From a517fb5bf1e5727e63717b2623799728c3bb07eb Mon Sep 17 00:00:00 2001 From: mgroeninger Date: Mon, 21 Aug 2006 18:09:20 +0000 Subject: [PATCH] Patched serendipity_displayImageList() to only sync images when $limit_path is NULL and $manage is false. Bumped version to beta3 for better version management on plugins. --- include/functions_images.inc.php | 226 +++++++++++++++---------------- serendipity_config.inc.php | 2 +- 2 files changed, 114 insertions(+), 114 deletions(-) diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php index 0ff1a51..23f1a6f 100644 --- a/include/functions_images.inc.php +++ b/include/functions_images.inc.php @@ -1356,125 +1356,125 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa } $start = ($page-1) * $perPage; - ## SYNCH START ## - $aExclude = array("CVS" => true, ".svn" => true); - serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude); - $paths = array(); - $aFilesOnDisk = array(); - - $aResultSet = serendipity_traversePath( - $serendipity['serendipityPath'] . $serendipity['uploadPath']. $limit_path, - '', - false, - NULL, - 1, - NULL, - FALSE, - $aExclude - ); + if ($manage && $limit_path == NULL) { + ## SYNCH START ## + $aExclude = array("CVS" => true, ".svn" => true); + serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude); + $paths = array(); + $aFilesOnDisk = array(); + + $aResultSet = serendipity_traversePath( + $serendipity['serendipityPath'] . $serendipity['uploadPath']. $limit_path, + '', + false, + NULL, + 1, + NULL, + FALSE, + $aExclude + ); + foreach ($aResultSet AS $sKey => $sFile) { + if ($sFile['directory']) { + if ($debug) echo "{$sFile['relpath']} is a directory.
"; + array_push($paths, $sFile); + } else { + if ($debug) echo "{$sFile['relpath']} is a file.
"; + // Store the file in our array, remove any ending slashes + $aFilesOnDisk[$sFile['relpath']] = 1; + } + unset($aResultSet[$sKey]); + } + + usort($paths, 'serendipity_sortPath'); + + if ($debug) echo "

Got files:

" . print_r($aFilesOnDisk, true) . "

"; + $serendipity['current_image_hash'] = md5(serialize($aFilesOnDisk)); + + $nTimeStart = microtime_float(); + // 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 + FROM {$serendipity['dbPrefix']}images", false, 'assoc'); + if ($debug) echo "

Got images:

" . print_r($aResultSet, true) . "

"; + if (is_array($aResultSet)) { + foreach ($aResultSet AS $sKey => $sFile) { + serendipity_plugin_api::hook_event('backend_thumbnail_filename_select', $sFile); + $sThumbNailFile = ''; + if (isset($sFile['thumbnail_filename'])) { + $sThumbNailFile = $sFile['thumbnail_filename']; + } else { + $sThumbNailFile = $sFile['path'] . $sFile['name'] . '.' . $sFile['thumbnail_name'] . '.' . $sFile['extension']; + } - foreach ($aResultSet AS $sKey => $sFile) { - if ($sFile['directory']) { - if ($debug) echo "{$sFile['relpath']} is a directory.
"; - array_push($paths, $sFile); - } else { - if ($debug) echo "{$sFile['relpath']} is a file.
"; - // Store the file in our array, remove any ending slashes - $aFilesOnDisk[$sFile['relpath']] = 1; - } - unset($aResultSet[$sKey]); - } + $sFileName = $sFile['path'] . $sFile['name'] . '.' . $sFile['extension']; + if ($debug) echo "

File name is $sFileName,
thumbnail is $sThumbNailFile

"; + unset($aResultSet[$sKey]); - usort($paths, 'serendipity_sortPath'); - - if ($debug) echo "

Got files:

" . print_r($aFilesOnDisk, true) . "

"; - $serendipity['current_image_hash'] = md5(serialize($aFilesOnDisk)); - - $nTimeStart = microtime_float(); - // 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 - FROM {$serendipity['dbPrefix']}images", false, 'assoc'); - if ($debug) echo "

Got images:

" . print_r($aResultSet, true) . "

"; - if (is_array($aResultSet)) { - foreach ($aResultSet AS $sKey => $sFile) { - serendipity_plugin_api::hook_event('backend_thumbnail_filename_select', $sFile); - $sThumbNailFile = ''; - if (isset($sFile['thumbnail_filename'])) { - $sThumbNailFile = $sFile['thumbnail_filename']; - } else { - $sThumbNailFile = $sFile['path'] . $sFile['name'] . '.' . $sFile['thumbnail_name'] . '.' . $sFile['extension']; - } - - $sFileName = $sFile['path'] . $sFile['name'] . '.' . $sFile['extension']; - if ($debug) echo "

File name is $sFileName,
thumbnail is $sThumbNailFile

"; - unset($aResultSet[$sKey]); - - if (isset($aFilesOnDisk[$sFileName])){ - unset($aFilesOnDisk[$sFileName]); - } else { - if ($debug) "Deleting Image {$sFile['id']}
\n"; - serendipity_deleteImage($sFile['id']); - ++$nCount; - } - - unset($aFilesOnDisk[$sThumbNailFile]); - } - } + if (isset($aFilesOnDisk[$sFileName])){ + unset($aFilesOnDisk[$sFileName]); + } else { + if ($debug) "Deleting Image {$sFile['id']}
\n"; + serendipity_deleteImage($sFile['id']); + ++$nCount; + } + unset($aFilesOnDisk[$sThumbNailFile]); + } + } - if ($nCount > 0){ - if ($debug) echo "

Cleaned up ".$nCount." database entries

"; - } + if ($nCount > 0){ + if ($debug) echo "

Cleaned up ".$nCount." database entries

"; + } - 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) { - if (preg_match('@\.' . $serendipity['thumbSuffix'] . '\.@', $sFile)) { - if ($debug) echo "

Skipping thumbnailed file $sFile

"; - continue; - } else { - if ($debug) echo "

Checking $sFile

"; - } + 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) { + if (preg_match('@\.' . $serendipity['thumbSuffix'] . '\.@', $sFile)) { + if ($debug) echo "

Skipping thumbnailed file $sFile

"; + continue; + } 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)) { - $nPos = strrpos($sFile, "/"); - if (is_bool($nPos) && !$nPos) { - $sFileName = $sFile; - $sDirectory = ""; - } else { - ++$nPos; - $sFileName = substr($sFile, $nPos); - $sDirectory = substr($sFile, 0, $nPos); - } - if ($debug) echo "

Inserting image $sFileName from $sDirectory

" . print_r($aImageData, true) . "
into database

"; - # TODO: Check if the thumbnail generation goes fine with Marty's code - serendipity_makeThumbnail($sFileName, $sDirectory); - serendipity_insertImageInDatabase($sFileName, $sDirectory); - ++$nCount; - } - } + // MTG: 21/01/06: put files which have just 'turned up' into the database + $aImageData = serendipity_getImageData($sFile); + if (serendipity_isImage($aImageData)) { + $nPos = strrpos($sFile, "/"); + if (is_bool($nPos) && !$nPos) { + $sFileName = $sFile; + $sDirectory = ""; + } else { + ++$nPos; + $sFileName = substr($sFile, $nPos); + $sDirectory = substr($sFile, 0, $nPos); + } + if ($debug) echo "

Inserting image $sFileName from $sDirectory

" . print_r($aImageData, true) . "
into database

"; + # TODO: Check if the thumbnail generation goes fine with Marty's code + serendipity_makeThumbnail($sFileName, $sDirectory); + serendipity_insertImageInDatabase($sFileName, $sDirectory); + ++$nCount; + } + } - if ($nCount > 0) { - if ($debug) echo "

Inserted ".$nCount." images into the database

"; - } - } else { - if ($debug) echo "

Media Gallery database is up to date

"; - } + if ($nCount > 0) { + if ($debug) echo "

Inserted ".$nCount." images into the database

"; + } + } else { + if ($debug) echo "

Media Gallery database is up to date

"; + } - /* - $nTimeEnd = microtime_float ( ); - $nDifference = $nTimeEnd - $nTimeStart; - echo "

total time taken was " . $nDifference . "

"; - */ - ## SYNCH FINISHED ## + /* + $nTimeEnd = microtime_float ( ); + $nDifference = $nTimeEnd - $nTimeStart; + echo "

total time taken was " . $nDifference . "

"; + */ + ## SYNCH FINISHED ## + } ## Aply ACL afterwards: serendipity_directoryACL($paths, 'read'); @@ -3294,4 +3294,4 @@ function &serendipity_getMediaPaths() { usort($paths, 'serendipity_sortPath'); return $paths; -} \ No newline at end of file +} diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php index 66ad451..233c76b 100644 --- a/serendipity_config.inc.php +++ b/serendipity_config.inc.php @@ -27,7 +27,7 @@ if (IS_installed === true && !defined('IN_serendipity')) { include(S9Y_INCLUDE_PATH . 'include/compat.inc.php'); // The version string -$serendipity['version'] = '1.1-beta2'; +$serendipity['version'] = '1.1-beta3'; // Setting this to 'false' will enable debugging output. All alpa/beta/cvs snapshot versions will emit debug information by default. To increase the debug level (to enable Smarty debugging), set this flag to 'debug'. $serendipity['production'] = (preg_match('@\-(alpha|beta|cvs)@', $serendipity['version']) ? false : true); -- 2.39.5