Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3071
Modified Files:
NEWS serendipity_admin_image_selector.php
serendipity_admin_images.inc.php serendipity_entries.php
serendipity_functions.inc.php
Added Files:
db_update-0.5-0.5.1.sql serendipity_functions_images.inc.php
Log Message:
Image-Sync functions.
Move image records into database for better handling
Clean up image functions, move them to a new functions file
Please test and remember to run db_update-0.5-0.5.1.sql
--- NEW FILE: db_update-0.5-0.5.1.sql ---
CREATE TABLE `serendipity_images` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
`extension` varchar(5) NOT NULL default '',
`mime` varchar(15) NOT NULL default '',
`size` int(11) NOT NULL default '0',
`dimensions_width` int(11) NOT NULL default '0',
`dimensions_height` int(11) NOT NULL default '0',
`thumbnail_name` varchar(255) NOT NULL default '',
`date` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM;
--- NEW FILE: serendipity_functions_images.inc.php ---
<?php
/**
* Get a list of images
**/
function serendipity_fetchImagesFromDatabase($start = 0, $limit=0, &$total) {
global $serendipity;
$rs = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}images ORDER BY date DESC", false, 'assoc');
if ( !is_array($rs) ) {
return array();
}
$total = sizeof($rs)+1;
if ( $limit > 0 ) {
$rs = @array_slice($rs, $start, $limit);
}
return $rs;
}
function serendipity_fetchImageFromDatabase($id) {
global $serendipity;
$rs = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}images WHERE id = ". $id, true, 'assoc');
return $rs;
}
function serendipity_updateImageInDatabase($updates, $id) {
global $serendipity;
$i=0;
if ( sizeof($updates) > 0 ) {
foreach ( $updates as $k => $v ) {
$q[] = $k ." = '". $v ."'";
}
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}images SET ". implode($q, ',') ." WHERE id = ". $id);
$i++;
}
return $i;
}
function serendipity_deleteImage($id) {
global $serendipity;
$file = serendipity_fetchImageFromDatabase($id);
$dFile = $file['name'] .'.'. $file['extension'];
$dThumb = $file['name'] .'.'. $file['thumbnail_name'] .'.'. $file['extension'];
if ( file_exists($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dFile) ) {
if ( @unlink($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dFile) ) {
printf(DELETE_IMAGE . '<br />', $dFile);
} else {
printf(DELETE_IMAGE_FAIL . '<br />', $dFile);
}
if ( @unlink($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dThumb) ) {
printf(DELETE_THUMBNAIL . '<br />', $dThumb);
}
} else {
printf(FILE_NOT_FOUND, $dFile);
}
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}images WHERE id = ". $id);
}
/**
* Get a list of images
**/
function serendipity_fetchImages($group = false, $start = 0, $end = 20) {
global $serendipity;
// Open directory
$images = array();
if ($dir = @opendir($serendipity['serendipityPath'] . $serendipity['uploadPath'])) {
while(false !== ($f = readdir($dir))) {
if ($f != '.' && $f != '..' && strpos($f, $serendipity['thumbSuffix']) === false) {
array_push($images, $f);
}
}
}
natsort($images);
/* BC */
$serendipity['imageList'] = $images;
return $images;
}
function serendipity_insertImageInDatabase($filename, $extension, $mimetype, $filesize, $width, $height, $thumbnail, $date) {
global $serendipity;
$sql = serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}images
(name, extension, mime, size, dimensions_width, dimensions_height, thumbnail_name, date)
VALUES('". $filename ."', '". $extension ."', '". $mimetype ."', ". $filesize .", ". $width.", ". $height .", '". $thumbnail ."', ". $date .")");
return true;
}
/**
* Generate a thumbnail
**/
function serendipity_makeThumbnail($file, $size=false) {
global $serendipity;
if ($size===false) {
$size = $serendipity['thumbSize'];
}
// Calculate name of thumbnail
$t = serendipity_parseFileName($file);
$f = $t[0];
$suf = $t[1];
$infile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file;
$outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $f . '.' . $serendipity['thumbSuffix'] . '.' . $suf;
$fdim = getimagesize($infile);
if ( !isset($fdim['mime']) ) {
$fdim['mime'] = serendipity_guessMime($infile);
}
if ($serendipity['magick'] !== true) {
$r = serendipity_resize_image_gd($infile, $outfile, $size);
} else {
/*if ($serendipity["dim"] == "height") $newSize = "*x".$serendipity["thumbSize"];
else $newSize = $serendipity["thumbSize"]."x*"; */
$newSize = $size . 'x' . $size;
$r = array($size, $size);
$cmd = $serendipity['convert'] . " -antialias -scale $newSize $infile $outfile 2>&1";
$res = `$cmd`;
}
/* Lets assume we are all done, now we add the image to the image database */
serendipity_insertImageInDatabase($f, $suf, $fdim['mime'], filesize($infile), $fdim[0], $fdim[1], $serendipity['thumbSuffix'], time());
return $res;
}
/**
* Scale an image (ignoring proportions)
**/
function serendipity_scaleImg($id, $width, $height) {
global $serendipity;
$file = serendipity_fetchImageFromDatabase($id);
$infile = $outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['name'] .'.'. $file['extension'];
if($serendipity['magick'] !== true) {
serendipity_resize_image_gd($infile, $outfile, $width, $height);
}
$cmd = $serendipity['convert'] . ' -scale ' . $width . 'x' . $height . ' ' . $infile . ' ' . $outfile;
$res = `$cmd`;
serendipity_updateImageInDatabase(array('dimensions_width' => $width, 'dimensions_height' => $height), $id);
return;
}
/**
* Creates thumbnails for all images in the upload dir
**/
function serendipity_generateThumbs() {
global $serendipity;
$i=0;
$serendipity['imageList'] = serendipity_fetchImagesFromDatabase(0, 0, $total);
foreach ( $serendipity['imageList'] as $k => $file ) {
$filename = $file['name'] .'.'. $file['extension'];
$ffull = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $filename;
$fdim = @getimagesize($ffull);
$oldThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['name'] .'.'. $file['thumbnail_name'] .'.'. $file['extension'];
$newThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['name'] .'.'. $serendipity['thumbSuffix'] .'.'. $file['extension'];
if (!file_exists($oldThumb) && !file_exists($newThumb) && ($fdim[0] > $serendipity['thumbSize'] || $fdim[1] > $serendipity['thumbSize'])) {
printf(RESIZE_BLAHBLAH, $filename . ': ' . serendipity_makeThumbnail($filename));
$i++;
} elseif (!file_exists($oldThumb) && !file_exists($newThumb) && $fdim[0] < $serendipity['thumbSize'] && $fdim[1] < $serendipity['thumbSize']) {
$res = copy ($ffull, $newThumb);
if (@$res === true) {
printf(THUMBNAIL_USING_OWN . '<br />', $filename);
} else {
printf('<span style="color: #ff0000">' . THUMBNAIL_FAILED_COPY . '</span><br />', $filename);
}
}
}
return $i;
}
function serendipity_guessMIME($extension) {
switch ( $extension ) {
}
return $mime;
}
/**
* Creates thumbnails for all images in the upload dir
**/
function serendipity_syncThumbs() {
global $serendipity;
$i=0;
$files = serendipity_fetchImages();
for($x=0; $x<count($files); $x++) {
$update = $q = array();
$f = serendipity_parseFileName($files[$x]);
$ffull = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $files[$x];
$fthumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $f[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f[1];
$fdim = getimagesize($ffull);
if ( !isset($fdim['mime']) ) {
$fdim['mime'] = serendipity_guessMime($f[1]);
}
$rs = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}images
WHERE name = '$f[0]'
AND mime = '$fdim[mime]'", true, 'assoc');
if ( is_array($rs) ) {
$checkfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $rs['name'] . '.' . $rs['thumbnail_name'] . '.' . $rs['extension'];
if ( $rs['dimensions_width'] != $fdim[0] ) {
$update['dimensions_width'] = $fdim[0];
}
if ( $rs['dimensions_height'] != $fdim[1] ) {
$update['dimensions_height'] = $fdim[1];
}
if ( $rs['size'] != filesize($ffull) ) {
$update['size'] = filesize($ffull);
}
if ( !file_exists($checkfile) && file_exists($fthumb) ) {
$update['thumbnail_name'] = $serendipity['thumbSuffix'];
}
/* Do the database update, if needed */
serendipity_updateImageInDatabase($update, $rs['id']);
if ( sizeof($update) != 0 ) { $i++; }
} else {
if ( file_exists($fthumb) ) {
$thumbnail = $serendipity['thumbSuffix'];
}
serendipity_insertImageInDatabase($f[0], $f[1], $fdim['mime'], filesize($ffull), $fdim[0], $fdim[1], $thumbnail, filemtime($ffull));
$i++;
}
}
return $i;
}
function serendipity_resize_image_gd($infilename, $outfilename, $newwidth, $newheight=null)
{
if (!function_exists('imagecopyresampled')) {
return false;
}
$inf = pathinfo(strtolower($infilename));
switch ($inf['extension']) {
case 'gif':
$loadfn = 'imagecreatefromgif';
$savefn = 'imagegif';
break;
case 'jpeg':
case 'jpg':
case 'jfif':
$loadfn = 'imagecreatefromjpeg';
$savefn = 'imagejpeg';
break;
case 'png':
$loadfn = 'imagecreatefrompng';
$savefn = 'imagepng';
break;
default:
return false;
}
/* If our loader does not exist, we are doomed */
if ( !function_exists($loadfn) ) {
return false;
}
/* If the save function does not exist (i.e. read-only GIF), we want to output it as PNG */
if ( !function_exists($savefn) ) {
if ( function_exists('imagepng') ) {
$savefn = 'imagepng';
} else {
return false;
}
}
$in = $loadfn($infilename);
/* todo: Never - ever - enlarge an original image */
if (is_null($newheight)) {
$newheight = (imagesy($in) / imagesx($in)) * $newwidth;
}
$out = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($out, $in, 0, 0, 0, 0, $newwidth, $newheight, imagesx($in), imagesy($in));
$savefn($out, $outfilename);
$out = null;
$in = null;
return array($newwidth, $newheight);
}
function serendipity_displayImageList($start = 0, $end = 10, $lineBreak=NULL, $manage=false, $url=NULL) {
global $serendipity;
$serendipity['imageList'] = serendipity_fetchImagesFromDatabase($start, $end, $totalImages);
$inc = $end - $start;
if ( isset($serendipity['GET']['adminModule']) ) {
$extraParems = 'serendipity[adminModule]='. $serendipity['GET']['adminModule'] .'&';
}
$left = '<input type="button" value="<<<" onclick="location.href=\'?'. $extraParems .'serendipity[start]=' . ($start-$end) . '\';" '. (($start <= 0) ? 'disabled' : '') .'>' . "\n";
$right = '<input type="button" value=">>>" onclick="location.href=\'?'. $extraParems .'serendipity[start]=' . ($start+$end) . '\';" '. (($totalImages < $start+$end) ? 'disabled' : '') .'>' . "\n";
if ( is_null($lineBreak) ) {
$lineBreak = floor(750 / ($serendipity['thumbSize'] + 20));
}
?>
<table border="0" width="100%">
<tr>
<td align="left" colspan="<?php echo floor($lineBreak/2); ?>">
<?php echo $left; ?>
</td>
<td align="right" colspan="<?php echo ceil($lineBreak/2); ?>">
<?php echo $right; ?>
</td>
</tr>
<tr>
<?php
foreach ( $serendipity['imageList'] as $k => $file ) {
++$x; $preview = '';
$i = getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . '/' . $file['name'] .'.'. $file['thumbnail_name'] .'.'. $file['extension']);
$imgsrc = $serendipity['uploadHTTPPath'] . $file['name'] . '.' . $file['thumbnail_name'] . '.' . $file['extension'];
if (file_exists($imgsrc)) {
$preview .= '<img src="' . $imgsrc . '" border="0"'. (( $manage) ? '' : '') .' alt="'. $file['name'] . '" />';
if ( $url ) { $preview = '<a href="'.$url.'&serendipity[image]='. $file['id'] .'">'. $preview .'</a>'; }
}
?>
<td class="serendipity_admin_list_item" nowrap="nowrap" align="center" valign="bottom">
<?php echo $preview; ?>
<?php if ( $manage ) { ?>
<table border="0" width="100%" style="border-bottom: 1px solid #000000">
<tr>
<td valign="middle"><font size="1">Org: <?php echo $file['dimensions_width'] . 'x' . $file['dimensions_height']; ?><br>Thumb: <?php echo $i[0] . 'x' . $i[1]; ?></font></td>
<td valign="middle" align="center"><img class="serendipityImageButton" title="<?php echo IMAGE_FULLSIZE; ?>" alt="<?php echo IMAGE_FULLSIZE; ?>" src="<?php echo $serendipity['serendipityHTTPPath']; ?>pixel/zoom.png" border="0" onclick="F1 = window.open('<?php echo $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['name'] . '.'. $file['extension']; ?>','Zoom','height=<?php echo ($file['dimensions_height'] + 20); ?>,width=<?php echo ($file['dimensions_width'] + 20); ?>,toolbar=no,menubar=no,location=no');" /></td>
<td valign="middle" align="center"><img class="serendipityImageButton" title="<?php echo IMAGE_RENAME; ?>" alt="<?php echo IMAGE_RENAME; ?>" src="<?php echo $serendipity['serendipityHTTPPath']; ?>pixel/rename.png" border="0" onclick="rename('<?php echo $file['id']; ?>', '<?php echo addslashes($file['name']); ?>')" /></td>
<td valign="middle" align="center"><img class="serendipityImageButton" title="<?php echo IMAGE_RESIZE; ?>" alt="<?php echo IMAGE_RESIZE; ?>" src="<?php echo $serendipity['serendipityHTTPPath']; ?>pixel/scale.png" border="0" onclick="location.href='?serendipity[adminModule]=images&serendipity[adminAction]=scaleSelect&serendipity[fid]=<?php echo $file['id']; ?>';" /></td>
<td valign="middle" align="center"><img class="serendipityImageButton" title="<?php echo IMAGE_DELETE; ?>" alt="<?php echo IMAGE_DELETE; ?>" src="<?php echo $serendipity['serendipityHTTPPath']; ?>pixel/delete.png" border="0" onclick="location.href='?serendipity[adminModule]=images&serendipity[adminAction]=delete&serendipity[fid]=<?php echo $file['id']; ?>';" /></td>
</tr>
</table>
<?php } ?>
</td>
<?php
// Newline?
if ($x%$lineBreak == 0) {
?>
</tr>
<tr>
<?php
}
}
?>
</tr>
<tr>
<td align="left" colspan="<?php echo floor($lineBreak/2); ?>">
<?php echo $left; ?>
</td>
<td align="right" colspan="<?php echo ceil($lineBreak/2); ?>">
<?php echo $right; ?>
</td>
</tr>
</table>
<?php
}
?>
Index: NEWS
===================================================================
RCS file: /cvsroot/php-blog/serendipity/NEWS,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- NEWS 8 Feb 2004 12:06:05 -0000 1.62
+++ NEWS 8 Feb 2004 17:56:27 -0000 1.63
@@ -2,6 +2,8 @@
Version 0.5.1 ()
------------------------------------
+ * Redesigned image manager (tomsommer)
+ * Added image syncronization with database (tomsommer)
* Fix leaking draft entries by directly entering URL or using quicksearch (garvinhicking)
* Now able to use CommentAPI to post entries to an RSS/Atom feed, like from RSS Bandit (garvinhicking)
Index: serendipity_admin_image_selector.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_image_selector.php,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- serendipity_admin_image_selector.php 11 Nov 2003 16:17:04 -0000 1.14
+++ serendipity_admin_image_selector.php 8 Feb 2004 17:56:27 -0000 1.15
@@ -20,72 +20,6 @@
die(HAVE_TO_BE_LOGGED_ON);
}
-function serendipity_displayImageList($start = 0, $end = 20) {
- global $serendipity;
-
- serendipity_fetchImages(true);
- $inc = $end - $start;
- $files = array_slice($serendipity['imageList'], $start, $inc);
-
- if ($start > 0) {
- $left = '<input type="button" value="<<<" onclick="location.href=\'?serendipity[start]=' . max(0, $start - $inc) . '&serendipity[end]=' . $start . '\';">' . "\n";
- }
-
- if (count($serendipity["imageList"]) > $end) {
- $right = '<input type="button" value=">>>" onclick="location.href=\'?serendipity[start]=' . $end . '&serendipity[end]=' . ($end + $inc) . '\';">' . "\n";
- }
-
- $lineBreak = floor(750 / ($serendipity['thumbSize'] + 20));
-?>
-<table border="0">
- <tr>
- <td align="left" colspan="<?php echo floor($linebreak/2); ?>">
- <?php echo $left; ?>
- </td>
-
- <td align="right" colspan="<?php echo ceil($linebreak/2); ?>">
- <?php echo $right; ?>
- </td>
- </tr>
-
- <tr>
-<?php
- for ($x=0; $x<count($files); $x++) {
- // Parse filename and image info
- $f = serendipity_parseFileName($files[$x]);
- $i = getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . '/' . $files[$x]);
- $imgsrc = $serendipity['uploadHTTPPath'] . $f[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f[1];
- // Display thumbnails
-?>
- <td height="<?php echo $serendipity['thumbSize']; ?>" align="center" valign="middle">
- <a href="?serendipity[step]=1&serendipity[image]=<?php echo $files[$x]; ?>">
- <img src="<?php echo $imgsrc; ?>" hspace="15" border="0" />
- </a>
- </td>
-<?php
- // Newline?
- if (($x+1)%$lineBreak == 0) {
-?>
- </tr>
- <tr>
-<?php
- }
- }
-?>
- </tr>
- <tr>
- <td align="left" colspan="<?php echo floor($linebreak/2); ?>">
- <?php echo $left; ?>
- </td>
-
- <td align="right" colspan="<?php echo ceil($linebreak/2); ?>">
- <?php echo $right; ?>
- </td>
- </tr>
-</table>
-<?php
-}
-
?>
<html>
<head>
@@ -97,17 +31,17 @@
<?php
switch ($serendipity['GET']['step']) {
case '1':
- $f = serendipity_parseFileName($serendipity["GET"]["image"]);
- $imgsrc = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $f[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f[1];
- $imgName = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $serendipity['GET']['image'];
- $thumbName = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $f[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f[1];
+ $file = serendipity_fetchImageFromDatabase($serendipity['GET']['image']);
+ $imgsrc = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $file['name'] . '.' . $file['thumbnail_name'] . '.' . $file['extension'];
+ $imgName = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['name'] .'.'. $file['extension'];
+ $thumbName = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['name'] . '.' . $file['thumbnail_name'] . '.' . $file['extension'];
?>
<script type="text/javascript" language="JavaScript" src="<?php echo $serendipity['serendipityHTTPPath']; ?>serendipity_define.js.php"></script>
<script type="text/javascript" language="Javascript" src="<?php echo $serendipity['serendipityHTTPPath']; ?>serendipity_editor.js"></script>
<div>
<img align="right" src="<?php echo $imgsrc; ?>">
- <h1><?php printf(YOU_CHOSE, $serendipity['GET']['image']); ?></h1>
+ <h1><?php printf(YOU_CHOSE, $file['name']); ?></h1>
<p>
<form action="#" method="GET" name="serendipity[selForm]" onSubmit="serendipity_imageSelector_done()">
<div>
@@ -131,7 +65,7 @@
<br />
<input id="radio_islink_yes" type="radio" name="serendipity[isLink]" checked="checked" /><label for="radio_islink_yes"> <?php echo I_WANT_NO_LINK; ?><br />
<input id="radio_islink_no" type="radio" name="serendipity[isLink]" /><label for="radio_islink_no"> <?php echo I_WANT_IT_TO_LINK; ?></label>
- <input type="text" name="serendipity[url]" size="30" value="<?php echo $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $serendipity['GET']['image']; ?>" onfocus="value='';" /><br />
+ <input type="text" name="serendipity[url]" size="30" value="<?php echo $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $file['name'] .'.'. $file['extension']; ?>" onfocus="value='';" /><br />
<br />
<input type="button" value="<?php echo BACK; ?>" onclick="history.go(-1);" />
@@ -148,7 +82,7 @@
}
if (!is_numeric($serendipity['GET']['end'])) {
- $serendipity['GET']['end'] = $serendipity['GET']['start']+ floor(750/($serendipity['thumbSize']+20))*floor(580/($serendipity['thumbSize']+20));
+ $serendipity['GET']['end'] = 15;
}
?>
<b><?php echo SELECT_IMAGE; ?></b>
@@ -157,7 +91,7 @@
<?php echo CLICK_IMAGE_TO_INSERT; ?>
<br />
- <?php serendipity_displayImageList($serendipity['GET']['start'], $serendipity['GET']['end']);
+ <?php serendipity_displayImageList($serendipity['GET']['start'], 8, 4, false, '?serendipity[step]=1');
}
?>
Index: serendipity_admin_images.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_images.inc.php,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- serendipity_admin_images.inc.php 11 Nov 2003 16:17:04 -0000 1.13
+++ serendipity_admin_images.inc.php 8 Feb 2004 17:56:27 -0000 1.14
@@ -13,136 +13,37 @@
die ("Don't hack!");
}
-function serendipity_displayImageList($start = 0, $end = 20) {
- global $serendipity;
-
- serendipity_fetchImages(true);
- $inc = $end - $start;
- $files = @array_slice($serendipity['imageList'], $start, $inc);
-
- if ($start > 0) {
- $left = '<input type="button" value="<<<" onclick="location.href=\'' . $_SERVER['REQUEST_URI'] . '&start=' . max(0, $start - $inc) . '&end=' . $start . '\';" />' . "\n";
- }
-
- if (count($serendipity["imageList"]) > $end) {
- $right = '<input type="button" value=">>>" onclick="location.href=\'' . $_SERVER['REQUEST_URI'] . '&start=' . $end . '&end=' . ($end + $inc) . '\';" />' . "\n";
- }
-?>
- <script type="text/javascript" language="javascript">
- <!--
- function rename(fname) {
- if(newname = prompt('<?php echo ENTER_NEW_NAME; ?>' + fname, fname)) {
- location.href='?serendipity[adminModule]=images&serendipity[adminAction]=rename&serendipity[oldname]='+ escape(fname) + '&serendipity[newname]='+ escape(newname);
- }
- }
- //-->
- </script>
-
- <div class="serendipity_admin_list">
- <div class="serendipity_admin_list_title"><?php echo IMAGE_MANAGER; ?></div>
-
- <table class="serendipity_admin_list">
- <tr>
- <td align="left" colspan="2">
- <?php echo $left; ?>
- </td>
-
- <td align="right" colspan="2">
- <?php echo $right; ?>
- </td>
- </tr>
-
- <tr>
-<?php
- for ($x=0; $x<count($files); $x++) {
- // Parse filename and image info
- $f = serendipity_parseFileName($files[$x]);
- $i = @getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . '/' . $files[$x]);
- $_imgsrc = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $f[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f[1];
- $imgsrc = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $f[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f[1];
- if (file_exists($_imgsrc)) {
- $preview = '<img align="left" src="' . $imgsrc . '" hspace="15" alt="" />';
- } else {
- $preview = '';
- }
-?>
- <td class="serendipity_admin_list_item" width="50%" nowrap="nowrap">
- <b><?php echo $files[$x]; ?></b>
- <br />
-
- <?php echo $preview; ?>
- <br />
- <?php echo $i[0] . 'x' . $i[1]; ?>
- <br />
+switch ($serendipity['GET']['adminAction']) {
+ case 'sync':
+ set_time_limit(0);
+ ignore_user_abort();
- <img class="serendipityImageButton" alt="<?php echo IMAGE_FULLSIZE; ?>" src="<?php echo $serendipity['serendipityHTTPPath']; ?>pixel/zoom.png" border="0" onclick="F1 = window.open('<?php echo $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $files[$x]; ?>','Zoom','height=<?php echo ($i[1] + 20); ?>,width=<?php echo ($i[0] + 20); ?>,toolbar=no,menubar=no,location=no');" />
- <img class="serendipityImageButton" alt="<?php echo IMAGE_RENAME; ?>" src="<?php echo $serendipity['serendipityHTTPPath']; ?>pixel/rename.png" border="0" onclick="rename('<?php echo addslashes($files[$x]); ?>')" />
- <br>
- <img class="serendipityImageButton" alt="<?php echo IMAGE_RESIZE; ?>" src="<?php echo $serendipity['serendipityHTTPPath']; ?>pixel/scale.png" border="0" onclick="location.href='?serendipity[adminModule]=images&serendipity[adminAction]=scaleSelect&serendipity[fname]=<?php echo rawurlencode($files[$x]); ?>';" />
- <img class="serendipityImageButton" alt="<?php echo IMAGE_DELETE; ?>" src="<?php echo $serendipity['serendipityHTTPPath']; ?>pixel/delete.png" border="0" onclick="location.href='?serendipity[adminModule]=images&serendipity[adminAction]=delete&serendipity[fname]=<?php echo rawurlencode($files[$x]); ?>';" />
- </td>
-<?php
- // Linebreak?
- if (($x+1)%2 == 0) {
-?>
- </tr>
- <tr>
-<?php
- }
- }
-?>
- </tr>
+ echo '<p><b>' . SYNCING . '</b><br /><br />';
+ flush();
- <tr>
- <td align="left" colspan="2">
- <?php echo $left; ?>
- </td>
+ $i = serendipity_syncThumbs();
+ printf(SYNC_DONE, $i);
- <td align="right" colspan="2">
- <?php echo $right; ?>
- </td>
- </tr>
- </table>
- </div>
-<?php
-}
-switch ($serendipity['GET']['adminAction']) {
- case 'genThumbs':
- set_time_limit(0);
- ignore_user_abort();
- echo '<b>' . RESIZING . '</b><br /><br />';
+ echo '<p><b>' . RESIZING . '</b><br /><br />';
flush();
$i = serendipity_generateThumbs();
printf(RESIZE_DONE, $i);
+
break;
case 'DoDelete':
$file = $serendipity['GET']['fname'];
- $fThumb = serendipity_parseFileName($file);
- $fThumb = $fThumb[0] . '.' . $serendipity['thumbSuffix'] . '.' . $fThumb[1];
- if ( file_exists($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file) ) {
- if ( @unlink($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file) ) {
- printf(DELETE_IMAGE . '<br />', $file);
- } else {
- printf(DELETE_IMAGE_FAIL . '<br />', $file);
- }
-
- if ( @unlink($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $fThumb) ) {
- printf(DELETE_THUMBNAIL . '<br />', $fThumb);
- }
- } else {
- printf(FILE_NOT_FOUND, $file);
- }
+ serendipity_deleteImage($serendipity['GET']['fid']);
break;
case 'delete':
- $file = $serendipity['GET']['fname'];
+ $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']);
$abortLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_entries.php?serendipity[adminModule]=images';
- $newLoc = $abortLoc . '&serendipity[adminAction]=DoDelete&serendipity[fname]=' . $file;
+ $newLoc = $abortLoc . '&serendipity[adminAction]=DoDelete&serendipity[fid]=' . $serendipity['GET']['fid'];
- printf(ABOUT_TO_DELETE_FILE, $file);
+ printf(ABOUT_TO_DELETE_FILE, $file['name'] .'.'. $file['extension']);
?>
<form method="get" name="delete_image">
<div>
@@ -155,22 +56,18 @@
break;
case 'rename':
- $oldfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['GET']['oldname'];
- $newfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['GET']['newname'];
-
- if ($serendipity['GET']['oldname'] != '' && $serendipity['GET']['newname']!= '' &&
- file_exists($oldfile) &&
- !file_exists($newfile)) {
-
+ $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']);
+ $newfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['GET']['newname'] . '.' . $file['extension'];
+ $oldfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['name'] . '.'. $file['extension'];
+ if ( $serendipity['GET']['newname']!= '' && file_exists($oldfile) && !file_exists($newfile) ) {
// Rename file
rename($oldfile, $newfile);
// Rename thumbnail
- $f = serendipity_parseFileName($serendipity['GET']['oldname']);
- $f2= serendipity_parseFileName($serendipity['GET']['newname']);
- rename( $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $f[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f[1],
- $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $f2[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f2[1]);
+ rename( $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['name'] . '.' . $file['thumbnail_name'] . '.' . $file['extension'],
+ $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['GET']['newname'] . '.' . $serendipity['thumbSuffix'] . '.' . $file['extension']);
+ serendipity_updateImageInDatabase(array('thumbnail_name' => $serendipity['thumbSuffix'], 'name' => $serendipity['GET']['newname']), $serendipity['GET']['fid']);
// Forward user to overview (we don't want the user's back button to rename things again)
?>
<script language="javascript" type="text/javascript">
@@ -273,28 +170,28 @@
break;
case 'scale':
+ $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']);
printf(
SCALING_IMAGE . '<br />',
- $serendipity['GET']['fname'],
+ $file['name'] .'.'. $file['extension'],
$serendipity['GET']['width'],
$serendipity['GET']['height']
);
- echo serendipity_scaleImg($serendipity['GET']['fname'], $serendipity['GET']['width'], $serendipity['GET']['height']) . '<br />';
+ echo serendipity_scaleImg($serendipity['GET']['fid'], $serendipity['GET']['width'], $serendipity['GET']['height']) . '<br />';
echo DONE . '<br />';
-
// Forward user to overview (we don't want the user's back button to rename things again)
?>
<script language="javascript" type="text/javascript">
- location.href="?serendipity[adminModule]=images";
+ // location.href="?serendipity[adminModule]=images";
</script>
<?php
break;
case 'scaleSelect':
- $f = serendipity_parseFileName($serendipity['GET']['fname']);
- $s = getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . '/' . $serendipity['GET']['fname']);
+ $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']);
+ $s = getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . '/' . $file['name'] .'.'. $file['extension']);
?>
<script type="text/javascript" language="javascript">
<!--
@@ -330,7 +227,7 @@
<input type="hidden" name="serendipity[adminModule]" value="images" />
<input type="hidden" name="serendipity[adminAction]" value="scale" />
- <input type="hidden" name="serendipity[fname]" value="<?php echo $serendipity["GET"]["fname"]; ?>" />
+ <input type="hidden" name="serendipity[fid]" value="<?php echo $serendipity["GET"]["fid"]; ?>" />
<input type="text" size="4" name="serendipity[width]" onchange="rescale('width' , value);" value="<?php echo $s[0]; ?>" />x
<input type="text" size="4" name="serendipity[height]" onchange="rescale('height', value);" value="<?php echo $s[1]; ?>" />
@@ -343,15 +240,28 @@
</div>
</form>
- <img src="<?php echo $serendipity['uploadHTTPPath'] . $serendipity['GET']['fname']; ?>" name="serendipityScaleImg" style="width: <?php echo $s[0]; ?>px; height: <?php echo $s[1]; ?>px;" alt="" />
+ <img src="<?php echo $serendipity['uploadHTTPPath'] . $file['name'] .'.'. $file['extension'] ; ?>" name="serendipityScaleImg" style="width: <?php echo $s[0]; ?>px; height: <?php echo $s[1]; ?>px;" alt="" />
<?php
break;
default:
- if (isset($_GET['start'])) {
- serendipity_displayImageList($_GET['start'], $_GET['end'] ? $_GET['end'] : NULL);
+?>
+<script type="text/javascript" language="javascript">
+ <!--
+ function rename(id, fname) {
+ if(newname = prompt('<?php echo ENTER_NEW_NAME; ?>' + fname, fname)) {
+ location.href='?serendipity[adminModule]=images&serendipity[adminAction]=rename&serendipity[fid]='+ escape(id) + '&serendipity[newname]='+ escape(newname);
+ }
+ }
+ //-->
+ </script>
+
+
+<?php
+ if (isset($serendipity['GET']['start'])) {
+ serendipity_displayImageList($serendipity['GET']['start'], 8, 2, true);
} else {
- serendipity_displayImageList();
+ serendipity_displayImageList(0, 8, 2, true);
}
break;
Index: serendipity_entries.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_entries.php,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- serendipity_entries.php 23 Jan 2004 05:50:21 -0000 1.21
+++ serendipity_entries.php 8 Feb 2004 17:56:27 -0000 1.22
@@ -73,7 +73,7 @@
<div class="serendipitySideBarContent">
• <a href="?serendipity[adminModule]=images&serendipity[adminAction]=addSelect"><?php echo ADD_IMAGES; ?></a><br />
• <a href="?serendipity[adminModule]=images"><?php echo MANAGE_IMAGES; ?></a><br />
- • <a href="?serendipity[adminModule]=images&serendipity[adminAction]=genThumbs" onclick="return confirm('<?php echo WARNING_THIS_BLAHBLAH; ?>');"><?php echo CREATE_THUMBS; ?></a><br />
+ • <a href="?serendipity[adminModule]=images&serendipity[adminAction]=sync" onclick="return confirm('<?php echo WARNING_THIS_BLAHBLAH; ?>');"><?php echo CREATE_THUMBS; ?></a><br />
</div>
</div>
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- serendipity_functions.inc.php 8 Feb 2004 12:06:05 -0000 1.199
+++ serendipity_functions.inc.php 8 Feb 2004 17:56:27 -0000 1.200
@@ -2,11 +2,13 @@
# Copyright (c) 2003-2004, Jannis Hermanns
# All rights reserved. See LICENSE file for licensing details
+$serendipity['imageList'] = array();
include_once("${serendipity['serendipityPath']}serendipity_db.inc.php");
include_once("${serendipity['serendipityPath']}compat.php");
include_once("${serendipity['serendipityPath']}serendipity_functions_config.inc.php");
include_once("${serendipity['serendipityPath']}bundled-libs/XML/RPC.php");
-$serendipity['imageList'] = array();
+include_once("${serendipity['serendipityPath']}serendipity_functions_images.inc.php");
+
function serendipity_logout() {
$_SESSION['serendipityAuthedUser'] = false;
@@ -1933,28 +1935,6 @@
/**
-* Get a list of images
-**/
-function serendipity_fetchImages($group = false, $start = 0, $end = 20) {
- global $serendipity;
-
- if (count($serendipity['imageList'])) {
- return;
- }
-
- // Open directory
- if ($dir = @opendir($serendipity['serendipityPath'] . $serendipity['uploadPath'])) {
- while(false !== ($f = readdir($dir))) {
- if ($f != '.' && $f != '..' && strpos($f, $serendipity['thumbSuffix']) === false) {
- array_push($serendipity['imageList'], $f);
- }
- }
- }
-
- natsort($serendipity['imageList']);
-}
-
-/**
* Split up a filename
**/
function serendipity_parseFileName($file) {
@@ -1964,142 +1944,6 @@
return array($f, $suf);
}
-function serendipity_resize_image_gd($infilename, $outfilename, $newwidth, $newheight=null)
-{
- if (!function_exists('imagecopyresampled')) {
- return false;
- }
-
- $inf = pathinfo(strtolower($infilename));
- switch ($inf['extension']) {
- case 'gif':
- $loadfn = 'imagecreatefromgif';
- $savefn = 'imagegif';
- break;
-
- case 'jpeg':
- case 'jpg':
- case 'jfif':
- $loadfn = 'imagecreatefromjpeg';
- $savefn = 'imagejpeg';
- break;
-
- case 'png':
- $loadfn = 'imagecreatefrompng';
- $savefn = 'imagepng';
- break;
-
- default:
- return false;
- }
-
- /* If our loader does not exist, we are doomed */
- if ( !function_exists($loadfn) ) {
- return false;
- }
-
- /* If the save function does not exist (i.e. read-only GIF), we want to output it as PNG */
- if ( !function_exists($savefn) ) {
- if ( function_exists('imagepng') ) {
- $savefn = 'imagepng';
- } else {
- return false;
- }
- }
-
- $in = $loadfn($infilename);
- if (is_null($newheight)) {
- $newheight = (imagesy($in) / imagesx($in)) * $newwidth;
- }
- $out = imagecreatetruecolor($newwidth, $newheight);
- imagecopyresampled($out, $in, 0, 0, 0, 0, $newwidth, $newheight, imagesx($in), imagesy($in));
- $savefn($out, $outfilename);
- $out = null;
- $in = null;
-
- return 'OK!';
-}
-
-/**
-* Generate a thumbnail
-**/
-function serendipity_makeThumbnail($file, $size=false) {
- global $serendipity;
-
- if ($size===false) {
- $size = $serendipity['thumbSize'];
- }
-
- // Calculate name of thumbnail
- $t = serendipity_parseFileName($file);
- $f = $t[0];
- $suf = $t[1];
-
- $infile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file;
- $outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $f . '.' . $serendipity['thumbSuffix'] . '.' . $suf;
-
- if ($serendipity['magick'] !== true) {
- return serendipity_resize_image_gd($infile, $outfile, $size);
- }
-
- /*if ($serendipity["dim"] == "height") $newSize = "*x".$serendipity["thumbSize"];
- else $newSize = $serendipity["thumbSize"]."x*"; */
- $newSize = $size . 'x' . $size;
- $cmd = $serendipity['convert'] . " -antialias -scale $newSize $infile $outfile 2>&1";
- $res = `$cmd`;
-
- return $res;
-}
-
-/**
-* Scale an image (ignoring proportions)
-**/
-function serendipity_scaleImg($file, $width, $height) {
- global $serendipity;
-
- $infile = $outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file;
-
- if($serendipity['magick'] !== true) {
- return serendipity_resize_image_gd($infile, $outfile, $width, $height);
- }
-
- $cmd = $serendipity['convert'] . ' -scale ' . $width . 'x' . $height . ' ' . $infile . ' ' . $outfile;
- $res = `$cmd`;
- return $res;
-}
-
-/**
-* Creates thumbnails for all images in the upload dir
-**/
-function serendipity_generateThumbs() {
- global $serendipity;
-
- $i=0;
- serendipity_fetchImages();
-
- $files = $serendipity['imageList'];
- for($x=0; $x<count($files); $x++) {
- $f = serendipity_parseFileName($files[$x]);
- $fdim = getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $files[$x]);
-
- $checkfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $f[0] . '.' . $serendipity['thumbSuffix'] . '.' . $f[1];
-
- if (!file_exists($checkfile) && ($fdim[0] > $serendipity['thumbSize'] || $fdim[1] > $serendipity['thumbSize'])) {
- printf(RESIZE_BLAHBLAH, $files[$x] . ': ' . serendipity_makeThumbnail($files[$x]));
- $i++;
- } elseif (!file_exists($checkfile) && $fdim[0] < $serendipity['thumbSize'] && $fdim[1] < $serendipity['thumbSize']) {
- $res = copy ($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $files[$x], $checkfile);
- if ($res === true) {
- printf(THUMBNAIL_USING_OWN . '<br />', $files[$x]);
- } else {
- printf('<span style="color: #ff0000">' . THUMBNAIL_FAILED_COPY . '</span><br />', $files[$x]);
- }
- }
- }
-
- return $i;
-}
-
/**
* Prints a form to enter new diary entries
**/
@@ -2758,6 +2602,7 @@
return $ver;
}
+
define("serendipity_FUNCTIONS_LOADED", true);
/* vim: set sts=4 ts=4 expandtab : */
?>
|