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.
This commit is contained in:
@ -1356,125 +1356,125 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
|
|||||||
}
|
}
|
||||||
$start = ($page-1) * $perPage;
|
$start = ($page-1) * $perPage;
|
||||||
|
|
||||||
## SYNCH START ##
|
if ($manage && $limit_path == NULL) {
|
||||||
$aExclude = array("CVS" => true, ".svn" => true);
|
## SYNCH START ##
|
||||||
serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude);
|
$aExclude = array("CVS" => true, ".svn" => true);
|
||||||
$paths = array();
|
serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude);
|
||||||
$aFilesOnDisk = array();
|
$paths = array();
|
||||||
|
$aFilesOnDisk = array();
|
||||||
|
|
||||||
$aResultSet = serendipity_traversePath(
|
$aResultSet = serendipity_traversePath(
|
||||||
$serendipity['serendipityPath'] . $serendipity['uploadPath']. $limit_path,
|
$serendipity['serendipityPath'] . $serendipity['uploadPath']. $limit_path,
|
||||||
'',
|
'',
|
||||||
false,
|
false,
|
||||||
NULL,
|
NULL,
|
||||||
1,
|
1,
|
||||||
NULL,
|
NULL,
|
||||||
FALSE,
|
FALSE,
|
||||||
$aExclude
|
$aExclude
|
||||||
);
|
);
|
||||||
|
foreach ($aResultSet AS $sKey => $sFile) {
|
||||||
|
if ($sFile['directory']) {
|
||||||
|
if ($debug) echo "{$sFile['relpath']} is a directory.<br />";
|
||||||
|
array_push($paths, $sFile);
|
||||||
|
} else {
|
||||||
|
if ($debug) echo "{$sFile['relpath']} is a file.<br />";
|
||||||
|
// Store the file in our array, remove any ending slashes
|
||||||
|
$aFilesOnDisk[$sFile['relpath']] = 1;
|
||||||
|
}
|
||||||
|
unset($aResultSet[$sKey]);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($aResultSet AS $sKey => $sFile) {
|
usort($paths, 'serendipity_sortPath');
|
||||||
if ($sFile['directory']) {
|
|
||||||
if ($debug) echo "{$sFile['relpath']} is a directory.<br />";
|
|
||||||
array_push($paths, $sFile);
|
|
||||||
} else {
|
|
||||||
if ($debug) echo "{$sFile['relpath']} is a file.<br />";
|
|
||||||
// Store the file in our array, remove any ending slashes
|
|
||||||
$aFilesOnDisk[$sFile['relpath']] = 1;
|
|
||||||
}
|
|
||||||
unset($aResultSet[$sKey]);
|
|
||||||
}
|
|
||||||
|
|
||||||
usort($paths, 'serendipity_sortPath');
|
if ($debug) echo "<p>Got files: <pre>" . print_r($aFilesOnDisk, true) . "</pre></p>";
|
||||||
|
$serendipity['current_image_hash'] = md5(serialize($aFilesOnDisk));
|
||||||
|
|
||||||
if ($debug) echo "<p>Got files: <pre>" . print_r($aFilesOnDisk, true) . "</pre></p>";
|
$nTimeStart = microtime_float();
|
||||||
$serendipity['current_image_hash'] = md5(serialize($aFilesOnDisk));
|
// 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
|
||||||
|
|
||||||
$nTimeStart = microtime_float();
|
$nCount = 0;
|
||||||
// MTG 21/01/06: request all images from the database, delete any which don't exist
|
if ($serendipity['onTheFlySynch'] && serendipity_checkPermission('adminImagesSync') && $serendipity['current_image_hash'] != $serendipity['last_image_hash']) {
|
||||||
// on the filesystem, and mark off files from the file list which are already
|
$aResultSet = serendipity_db_query("SELECT path, name, extension, thumbnail_name, id
|
||||||
// in the database
|
FROM {$serendipity['dbPrefix']}images", false, 'assoc');
|
||||||
|
if ($debug) echo "<p>Got images: <pre>" . print_r($aResultSet, true) . "</pre></p>";
|
||||||
|
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'];
|
||||||
|
}
|
||||||
|
|
||||||
$nCount = 0;
|
$sFileName = $sFile['path'] . $sFile['name'] . '.' . $sFile['extension'];
|
||||||
if ($serendipity['onTheFlySynch'] && serendipity_checkPermission('adminImagesSync') && $serendipity['current_image_hash'] != $serendipity['last_image_hash']) {
|
if ($debug) echo "<p>File name is $sFileName,<br />thumbnail is $sThumbNailFile</p>";
|
||||||
$aResultSet = serendipity_db_query("SELECT path, name, extension, thumbnail_name, id
|
unset($aResultSet[$sKey]);
|
||||||
FROM {$serendipity['dbPrefix']}images", false, 'assoc');
|
|
||||||
if ($debug) echo "<p>Got images: <pre>" . print_r($aResultSet, true) . "</pre></p>";
|
|
||||||
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 (isset($aFilesOnDisk[$sFileName])){
|
||||||
if ($debug) echo "<p>File name is $sFileName,<br />thumbnail is $sThumbNailFile</p>";
|
unset($aFilesOnDisk[$sFileName]);
|
||||||
unset($aResultSet[$sKey]);
|
} else {
|
||||||
|
if ($debug) "Deleting Image {$sFile['id']}<br />\n";
|
||||||
|
serendipity_deleteImage($sFile['id']);
|
||||||
|
++$nCount;
|
||||||
|
}
|
||||||
|
unset($aFilesOnDisk[$sThumbNailFile]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($aFilesOnDisk[$sFileName])){
|
if ($nCount > 0){
|
||||||
unset($aFilesOnDisk[$sFileName]);
|
if ($debug) echo "<p>Cleaned up ".$nCount." database entries</p>";
|
||||||
} else {
|
}
|
||||||
if ($debug) "Deleting Image {$sFile['id']}<br />\n";
|
|
||||||
serendipity_deleteImage($sFile['id']);
|
|
||||||
++$nCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($aFilesOnDisk[$sThumbNailFile]);
|
serendipity_set_config_var('last_image_hash', $serendipity['current_image_hash'], 0);
|
||||||
}
|
$aUnmatchedOnDisk = array_keys($aFilesOnDisk);
|
||||||
}
|
if ($debug) echo "<p>Got unmatched files: <pre>" . print_r($aUnmatchedOnDisk, true) . "</pre></p>";
|
||||||
|
$nCount = 0;
|
||||||
|
foreach ($aUnmatchedOnDisk AS $sFile) {
|
||||||
|
if (preg_match('@\.' . $serendipity['thumbSuffix'] . '\.@', $sFile)) {
|
||||||
|
if ($debug) echo "<p>Skipping thumbnailed file $sFile</p>";
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if ($debug) echo "<p>Checking $sFile</p>";
|
||||||
|
}
|
||||||
|
|
||||||
if ($nCount > 0){
|
// MTG: 21/01/06: put files which have just 'turned up' into the database
|
||||||
if ($debug) echo "<p>Cleaned up ".$nCount." database entries</p>";
|
$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 "<p>Inserting image $sFileName from $sDirectory <pre>" . print_r($aImageData, true) . "</pre> into database</p>";
|
||||||
|
# TODO: Check if the thumbnail generation goes fine with Marty's code
|
||||||
|
serendipity_makeThumbnail($sFileName, $sDirectory);
|
||||||
|
serendipity_insertImageInDatabase($sFileName, $sDirectory);
|
||||||
|
++$nCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
serendipity_set_config_var('last_image_hash', $serendipity['current_image_hash'], 0);
|
if ($nCount > 0) {
|
||||||
$aUnmatchedOnDisk = array_keys($aFilesOnDisk);
|
if ($debug) echo "<p>Inserted ".$nCount." images into the database</p>";
|
||||||
if ($debug) echo "<p>Got unmatched files: <pre>" . print_r($aUnmatchedOnDisk, true) . "</pre></p>";
|
}
|
||||||
$nCount = 0;
|
} else {
|
||||||
foreach ($aUnmatchedOnDisk AS $sFile) {
|
if ($debug) echo "<p>Media Gallery database is up to date</p>";
|
||||||
if (preg_match('@\.' . $serendipity['thumbSuffix'] . '\.@', $sFile)) {
|
}
|
||||||
if ($debug) echo "<p>Skipping thumbnailed file $sFile</p>";
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
if ($debug) echo "<p>Checking $sFile</p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
// MTG: 21/01/06: put files which have just 'turned up' into the database
|
/*
|
||||||
$aImageData = serendipity_getImageData($sFile);
|
$nTimeEnd = microtime_float ( );
|
||||||
if (serendipity_isImage($aImageData)) {
|
$nDifference = $nTimeEnd - $nTimeStart;
|
||||||
$nPos = strrpos($sFile, "/");
|
echo "<p> total time taken was " . $nDifference . "</p>";
|
||||||
if (is_bool($nPos) && !$nPos) {
|
*/
|
||||||
$sFileName = $sFile;
|
## SYNCH FINISHED ##
|
||||||
$sDirectory = "";
|
}
|
||||||
} else {
|
|
||||||
++$nPos;
|
|
||||||
$sFileName = substr($sFile, $nPos);
|
|
||||||
$sDirectory = substr($sFile, 0, $nPos);
|
|
||||||
}
|
|
||||||
if ($debug) echo "<p>Inserting image $sFileName from $sDirectory <pre>" . print_r($aImageData, true) . "</pre> into database</p>";
|
|
||||||
# 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 "<p>Inserted ".$nCount." images into the database</p>";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($debug) echo "<p>Media Gallery database is up to date</p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
$nTimeEnd = microtime_float ( );
|
|
||||||
$nDifference = $nTimeEnd - $nTimeStart;
|
|
||||||
echo "<p> total time taken was " . $nDifference . "</p>";
|
|
||||||
*/
|
|
||||||
## SYNCH FINISHED ##
|
|
||||||
|
|
||||||
## Aply ACL afterwards:
|
## Aply ACL afterwards:
|
||||||
serendipity_directoryACL($paths, 'read');
|
serendipity_directoryACL($paths, 'read');
|
||||||
@ -3294,4 +3294,4 @@ function &serendipity_getMediaPaths() {
|
|||||||
usort($paths, 'serendipity_sortPath');
|
usort($paths, 'serendipity_sortPath');
|
||||||
|
|
||||||
return $paths;
|
return $paths;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ if (IS_installed === true && !defined('IN_serendipity')) {
|
|||||||
include(S9Y_INCLUDE_PATH . 'include/compat.inc.php');
|
include(S9Y_INCLUDE_PATH . 'include/compat.inc.php');
|
||||||
|
|
||||||
// The version string
|
// 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'.
|
// 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);
|
$serendipity['production'] = (preg_match('@\-(alpha|beta|cvs)@', $serendipity['version']) ? false : true);
|
||||||
|
Reference in New Issue
Block a user