From 9ea317039ddc766226fc7fcd479f8c513cae6111 Mon Sep 17 00:00:00 2001
From: garvinhicking
Date: Wed, 29 Mar 2006 13:31:02 +0000
Subject: [PATCH] Fix imagepng() for PHP 5.1.x
---
docs/NEWS | 9 +++-
include/functions_images.inc.php | 89 +++++++++++++++++---------------
2 files changed, 54 insertions(+), 44 deletions(-)
diff --git a/docs/NEWS b/docs/NEWS
index d0c173e..70fc452 100644
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -39,13 +39,20 @@ Version 1.1-alpha1()
* Removed config option "XHTML11 compliance" and enabled by default
now (garvinhicking)
-Version 1.0-beta2 (March 13th, 2006)
+Version 1.0 ()
------------------------------------------------------------------------
+ * Fix imagepng() function call for PHP 5.1.0 versions
+ (Sebastian Mordziol)
+
* Fix WYSIWYG javascript referencing so that plugins can access their
objects (like emoticonchooser). Also replace with and
with . (Jay Bertrandt)
+
+Version 1.0-beta2 (March 13th, 2006)
+------------------------------------------------------------------------
+
* Fixed chief-editor not being able to create editors (garvinhicking)
* Added turkish language by Ahmet Usal
diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php
index f997aee..37e9479 100644
--- a/include/functions_images.inc.php
+++ b/include/functions_images.inc.php
@@ -76,16 +76,16 @@ function serendipity_fetchImagesFromDatabase($start=0, $limit=0, &$total, $order
);
serendipity_ACL_SQL($cond, false, 'directory');
- $basequery = "FROM {$serendipity['dbPrefix']}images AS i
- LEFT OUTER JOIN {$serendipity['dbPrefix']}authors AS a
- ON i.authorid = a.authorid
+ $basequery = "FROM {$serendipity['dbPrefix']}images AS i
+ LEFT OUTER JOIN {$serendipity['dbPrefix']}authors AS a
+ ON i.authorid = a.authorid
{$cond['joins']}
-
+
{$cond['and']}";
-
- $query = "SELECT i.*,
- a.realname AS authorname
- $basequery
+
+ $query = "SELECT i.*,
+ a.realname AS authorname
+ $basequery
ORDER BY $order $ordermode $limitsql";
$rs = serendipity_db_query($query, false, 'assoc');
@@ -93,7 +93,7 @@ function serendipity_fetchImagesFromDatabase($start=0, $limit=0, &$total, $order
return array();
}
- $total_query = "SELECT count(i.id)
+ $total_query = "SELECT count(i.id)
$basequery";
$total_rs = serendipity_db_query($total_query, true, 'num');
if (is_array($total_rs)) {
@@ -112,13 +112,13 @@ function serendipity_fetchImagesFromDatabase($start=0, $limit=0, &$total, $order
*/
function serendipity_fetchImageFromDatabase($id) {
global $serendipity;
-
+
$cond = array(
'and' => "WHERE id = " . (int)$id
);
serendipity_ACL_SQL($cond, false, 'directory');
- $rs = serendipity_db_query("SELECT i.*
+ $rs = serendipity_db_query("SELECT i.*
FROM {$serendipity['dbPrefix']}images AS i
{$cond['joins']}
{$cond['and']}", true, 'assoc');
@@ -898,10 +898,10 @@ function serendipity_syncThumbs() {
);
serendipity_ACL_SQL($cond, false, 'directory');
- $rs = serendipity_db_query("SELECT *
+ $rs = serendipity_db_query("SELECT *
FROM {$serendipity['dbPrefix']}images AS i
{$cond['joins']}
-
+
{$cond['and']}", true, 'assoc');
if (is_array($rs)) {
$update = array();
@@ -955,6 +955,7 @@ function serendipity_functions_gd($infilename) {
case 'gif':
$func['load'] = 'imagecreatefromgif';
$func['save'] = 'imagegif';
+ $func['qual'] = 100;
break;
case 'jpeg':
@@ -962,11 +963,13 @@ function serendipity_functions_gd($infilename) {
case 'jfif':
$func['load'] = 'imagecreatefromjpeg';
$func['save'] = 'imagejpeg';
+ $func['qual'] = 100;
break;
case 'png':
$func['load'] = 'imagecreatefrompng';
$func['save'] = 'imagepng';
+ $func['qual'] = 9;
break;
default:
@@ -1009,7 +1012,7 @@ function serendipity_rotate_image_gd($infilename, $outfilename, $degrees)
$in = $func['load']($infilename);
$out = imagerotate($in, $degrees, 0);
- $func['save']($out, $outfilename);
+ $func['save']($out, $outfilename, $func['qual']);
$newwidth = imagesx($out);
$newheight = imagesy($out);
@@ -1057,7 +1060,7 @@ function serendipity_resize_image_gd($infilename, $outfilename, $newwidth, $newh
}
imagecopyresampled($out, $in, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
- $func['save']($out, $outfilename, 100);
+ $func['save']($out, $outfilename, $func['qual']);
$out = null;
$in = null;
@@ -1154,12 +1157,12 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
$aFilesOnDisk = array();
$aResultSet = serendipity_traversePath(
- $serendipity['serendipityPath'] . $serendipity['uploadPath']. $limit_path,
- '',
- false,
- NULL,
- 1,
- NULL,
+ $serendipity['serendipityPath'] . $serendipity['uploadPath']. $limit_path,
+ '',
+ false,
+ NULL,
+ 1,
+ NULL,
FALSE,
$aExclude
);
@@ -1183,14 +1186,14 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
// MTG 21/01/06: request all images from the database, delete any which don't exist
// on the filesystem, and mark off files from the file list which are already
// in the database
-
+
$nCount = 0;
if ($serendipity['onTheFlySynch'] && serendipity_checkPermission('adminImagesSync') && $serendipity['current_image_hash'] != $serendipity['last_image_hash']) {
- $aResultSet = serendipity_db_query("SELECT path, name, extension, thumbnail_name, id
+ $aResultSet = serendipity_db_query("SELECT path, name, extension, thumbnail_name, id
FROM {$serendipity['dbPrefix']}images", false, 'assoc');
if ($debug) echo "Got images:
" . print_r($aResultSet, true) . "
";
if (is_array($aResultSet)) {
- foreach ($aResultSet AS $sKey => $sFile) {
+ foreach ($aResultSet AS $sKey => $sFile) {
serendipity_plugin_api::hook_event('backend_thumbnail_filename_select', $sFile);
$sThumbNailFile = '';
if (isset($sFile['thumbnail_filename'])) {
@@ -1219,8 +1222,8 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
if ($debug) echo "Cleaned up ".$nCount." database entries
";
}
- serendipity_set_config_var('last_image_hash', $serendipity['current_image_hash'], 0);
- $aUnmatchedOnDisk = array_keys($aFilesOnDisk);
+ serendipity_set_config_var('last_image_hash', $serendipity['current_image_hash'], 0);
+ $aUnmatchedOnDisk = array_keys($aFilesOnDisk);
if ($debug) echo "Got unmatched files:
" . print_r($aUnmatchedOnDisk, true) . "
";
$nCount = 0;
foreach ($aUnmatchedOnDisk AS $sFile) {
@@ -1230,7 +1233,7 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
} else {
if ($debug) echo "Checking $sFile
";
}
-
+
// MTG: 21/01/06: put files which have just 'turned up' into the database
$aImageData = serendipity_getImageData($sFile);
if (serendipity_isImage($aImageData)) {
@@ -1267,7 +1270,7 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
## Aply ACL afterwards:
serendipity_directoryACL($paths, 'read');
-
+
$serendipity['imageList'] = serendipity_fetchImagesFromDatabase(
$start,
$perPage,
@@ -1611,7 +1614,7 @@ function serendipity_traversePath($basedir, $dir='', $onlyDirs = true, $pattern
while (($file = @readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
$bPatternMatch = (is_null($pattern) || preg_match($pattern, $file));
- $sFullPath = $odir . $file;
+ $sFullPath = $odir . $file;
$bIsDir = is_dir($sFullPath);
if ($onlyDirs === false || $bIsDir) {
if ($bPatternMatch &&
@@ -1635,7 +1638,7 @@ function serendipity_traversePath($basedir, $dir='', $onlyDirs = true, $pattern
}
@closedir($dh);
-
+
if ($depth == 1 && $apply_ACL !== FALSE) {
serendipity_directoryACL($files, $apply_ACL);
}
@@ -1802,7 +1805,7 @@ function serendipity_dirSlash($type, $dir) {
$dir .= '/';
}
}
-
+
return $dir;
}
@@ -1816,11 +1819,11 @@ function serendipity_dirSlash($type, $dir) {
function serendipity_directoryACL(&$paths, $type = 'read') {
global $serendipity;
static $debug = false;
-
+
if ($debug) {
echo "Applying ACL for mode '$type'.
\n";
}
-
+
if (!is_array($paths)) {
return true;
}
@@ -1833,7 +1836,7 @@ function serendipity_directoryACL(&$paths, $type = 'read') {
return true;
}
}
-
+
// Get list of all ACLs for directories.
$q = "SELECT a.artifact_index AS directory,
a.groupid
@@ -1844,27 +1847,27 @@ function serendipity_directoryACL(&$paths, $type = 'read') {
if (!is_array($allowed)) {
return true;
}
-
+
// Get a list of all the groups for this user. Pipe it into a usable array.
$my_groups =& serendipity_getGroups($serendipity['authorid']);
$acl_allowed_groups = array();
foreach($my_groups AS $my_group) {
$acl_allowed_groups[$my_group['id']] = true;
}
-
+
// Iterate every ACL and check if we are allowed to use it.
$acl_allowed = array();
foreach($allowed AS $row) {
$acl_allowed[$row['directory']][$row['groupid']] = true;
}
-
+
// Iterate the input path array and check it against ACL.
foreach($paths AS $idx => $info) {
if (!isset($acl_allowed[$info['relpath']])) {
// ACL for directory not set. Assume we are allowed to access.
continue;
}
-
+
$granted = false;
foreach($acl_allowed[$info['relpath']] AS $groupid => $set) {
if (isset($acl_allowed_groups[$groupid])) {
@@ -1873,7 +1876,7 @@ function serendipity_directoryACL(&$paths, $type = 'read') {
break;
}
}
-
+
if ($granted === false) {
// We are not allowed to access this element
if ($debug) {
@@ -1886,7 +1889,7 @@ function serendipity_directoryACL(&$paths, $type = 'read') {
}
}
}
-
+
if (count($paths) < $startCount) {
if ($debug) {
echo "ACL denied all.
\n";
@@ -1894,7 +1897,7 @@ function serendipity_directoryACL(&$paths, $type = 'read') {
return false;
}
}
-
+
return true;
}
@@ -1925,7 +1928,7 @@ function serendipity_getThumbNailPath($sRelativePath, $sName, $sExtension, $sThu
}
/**
- * Given a relative path to an image, construct an array containing all
+ * Given a relative path to an image, construct an array containing all
* relevant information about that image in the file structure.
*
* @author MTG
@@ -1969,7 +1972,7 @@ function serendipity_getImageData($sRelativePath) {
'hotlink' => 0,
'id' => $sRelativePath
);
-
+
return $array;
}
--
2.39.5