Update of /cvsroot/php-blog/serendipity/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10197/include
Modified Files:
functions_images.inc.php
Log Message:
- Clean up serendipity_makeThumbnail() and don't insert image into database from it. Instead serendipity_insertImageInDatabase has to be called "manually" after an image is done being processed.
- serendipity_insertImageInDatabase() now requires far less arguments, as it can calculate them on its own
- Fix E_NOTICE for non-string array element when mime is application/pdf
- Let serendipity_getImageSize do mime calc, so we don't need to clutter the rest of the code with serendipity_guessMime
The latter might need a little tweaking
Index: functions_images.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_images.inc.php,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- functions_images.inc.php 9 Feb 2005 17:33:43 -0000 1.30
+++ functions_images.inc.php 9 Feb 2005 19:46:09 -0000 1.31
@@ -124,16 +124,26 @@
return $images;
}
-function serendipity_insertImageInDatabase($filename, $extension, $mimetype, $filesize, $width, $height, $thumbnail, $date, $authorid, $directory) {
+function serendipity_insertImageInDatabase($filename, $directory, $authorid = 0, $time = NULL) {
global $serendipity;
- if (empty($width)) {
- $width = 0;
+ if ( is_null($time) ) {
+ $time = time();
}
- if (empty($height)) {
- $height = 0;
- }
+ $filepath = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $filename;
+ $filesize = @filesize($filepath);
+
+ list($filebase, $extension) = serendipity_parseFileName($filename);
+
+ $thumbpath = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $filebase . '.'. $serendipity['thumbSuffix'] . '.'. $extension;
+ $thumbnail = (file_exists($thumbpath) ? $serendipity['thumbSuffix'] : '');
+
+ $fdim = @serendipity_getimagesize($filepath, '', $extension);
+ $width = $fdim[0];
+ $height = $fdim[1];
+ $mime = $fdim['mime'];
+
$query = sprintf(
"INSERT INTO {$serendipity['dbPrefix']}images (
@@ -159,14 +169,14 @@
%s,
'%s'
)",
- serendipity_db_escape_string($filename),
+ serendipity_db_escape_string($filebase),
serendipity_db_escape_string($extension),
- serendipity_db_escape_string($mimetype),
+ serendipity_db_escape_string($mime),
(int)$filesize,
(int)$width,
(int)$height,
serendipity_db_escape_string($thumbnail),
- (int)$date,
+ (int)$time,
(int)$authorid,
serendipity_db_escape_string($directory)
);
@@ -182,30 +192,29 @@
return $image_id;
}
- return true;
+ return 0;
}
/**
* Generate a thumbnail
**/
-function serendipity_makeThumbnail($file, $size = false, $authorid = '0', $directory = '', $insertMode = true) {
+function serendipity_makeThumbnail($file, $directory = '', $size = false) {
global $serendipity;
if ($size === false) {
$size = $serendipity['thumbSize'];
}
- // Calculate name of thumbnail
$t = serendipity_parseFileName($file);
$f = $t[0];
$suf = $t[1];
- $ft_mime = serendipity_guessMime($suf);
+
$infile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $file;
$outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $f . '.' . $serendipity['thumbSuffix'] . '.' . $suf;
- $fdim = @serendipity_getimagesize($infile, $ft_mime);
+ $fdim = @serendipity_getimagesize($infile, '', $suf);
if (isset($fdim['noimage'])) {
$r = array(0, 0);
} else {
@@ -228,11 +237,6 @@
}
}
- /* Lets assume we are all done, now we add the image to the image database */
- if ($insertMode) {
- serendipity_insertImageInDatabase($f, $suf, $fdim['mime'], filesize($infile), $fdim[0], $fdim[1], $serendipity['thumbSuffix'], time(), $authorid, $directory);
- }
-
return $r;
}
@@ -347,12 +351,13 @@
$fdim = @getimagesize($ffull);
if (!file_exists($oldThumb) && !file_exists($newThumb) && ($fdim[0] > $serendipity['thumbSize'] || $fdim[1] > $serendipity['thumbSize'])) {
- $returnsize = serendipity_makeThumbnail($filename, false, $file['authorid'], '', false);
- printf(RESIZE_BLAHBLAH, $filename . ': ' . $returnsize[0] . 'x' . $returnsize[1]);
- if (!file_exists($newThumb)) {
- printf('<span class="serendipityAdminMsgError">' . THUMBNAIL_FAILED_COPY . '</span><br />', $filename);
- } else {
- $update = true;
+ if ( $returnsize = serendipity_makeThumbnail($filename, $file['path']) !== false ) {
+ printf(RESIZE_BLAHBLAH, $filename . ': ' . $returnsize[0] . 'x' . $returnsize[1]);
+ if (!file_exists($newThumb)) {
+ printf('<span class="serendipityAdminMsgError">' . THUMBNAIL_FAILED_COPY . '</span><br />', $filename);
+ } else {
+ $update = true;
+ }
}
} elseif (!file_exists($oldThumb) && !file_exists($newThumb) && $fdim[0] <= $serendipity['thumbSize'] && $fdim[1] <= $serendipity['thumbSize']) {
$res = @copy($ffull, $newThumb);
@@ -637,12 +642,8 @@
$i++;
}
} else {
- if (file_exists($fthumb)) {
- $thumbnail = $serendipity['thumbSuffix'];
- }
-
printf(FOUND_FILE . '<br />', $files[$x]);
- serendipity_insertImageInDatabase($fbase, $f[1], $fdim['mime'], filesize($ffull), $fdim[0], $fdim[1], $thumbnail, filemtime($ffull), '0', $fdir);
+ serendipity_insertImageInDatabase($files[$x], $fdir, 0, filemtime($ffull));
$i++;
}
}
@@ -1122,12 +1123,12 @@
$ft_mime = serendipity_guessMime($suf);
}
- $fdim = @getimagesize($file);
-
if ($ft_mime == 'application/pdf') {
- $fdim = array(1000,1000,24, '', 'bits'=> 24, channels => '3', 'mime' => 'application/pdf');
+ $fdim = array(1000,1000,24, '', 'bits'=> 24, 'channels' => '3', 'mime' => 'application/pdf');
}
+ $fdim = @getimagesize($file);
+
if (is_array($fdim)) {
if (empty($fdim['mime'])) {
$fdim['mime'] = $ft_mime;
|