From: garvinhicking Date: Tue, 13 Dec 2005 15:43:10 +0000 (+0000) Subject: 1. Fix importer stuff for moveable Type X-Git-Tag: 1.0~233 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=28d94e0b7e9ba9d7e6e6cd2bc2ea4c1e42e6fa2b;p=s9y.git 1. Fix importer stuff for moveable Type 2. Fix XHTML compliance for category image selector 3. Abstract image media database a bit for better plugin hooks and foreign interaction. Can now create multiple thumbnail sizes per file. --- diff --git a/include/admin/category.inc.php b/include/admin/category.inc.php index 94066a0..1d15f8c 100644 --- a/include/admin/category.inc.php +++ b/include/admin/category.inc.php @@ -184,7 +184,7 @@ if ($serendipity['GET']['adminAction'] == 'doDelete' && serendipity_checkFormTok - > + /> diff --git a/include/admin/entries.inc.php b/include/admin/entries.inc.php index a15194f..05b6669 100644 --- a/include/admin/entries.inc.php +++ b/include/admin/entries.inc.php @@ -15,7 +15,8 @@ $sort_order = array('timestamp' => DATE, 'a.realname' => AUTHOR, 'category_name' => CATEGORY, 'last_modified' => LAST_UPDATED, - 'title' => TITLE); + 'title' => TITLE, + 'id' => 'ID'); $per_page = array('12', '16', '50', '100'); diff --git a/include/admin/images.inc.php b/include/admin/images.inc.php index 77fcbbf..c7c8a7a 100644 --- a/include/admin/images.inc.php +++ b/include/admin/images.inc.php @@ -48,7 +48,10 @@ switch ($serendipity['GET']['adminAction']) { return; } - $abortLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[adminModule]=images'; + if (!isset($serendipity['adminFile'])) { + $serendipity['adminFile'] = 'serendipity_admin.php'; + } + $abortLoc = $serendipity['serendipityHTTPPath'] . $serendipity['adminFile'] . '?serendipity[adminModule]=images'; $newLoc = $abortLoc . '&serendipity[adminAction]=DoDelete&serendipity[fid]=' . $serendipity['GET']['fid'] . '&' . serendipity_setFormToken('url'); printf(ABOUT_TO_DELETE_FILE, $file['name'] .'.'. $file['extension']); @@ -82,14 +85,26 @@ switch ($serendipity['GET']['adminAction']) { $newfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $serendipity['GET']['newname'] . '.' . $file['extension']; $oldfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . '.'. $file['extension']; if ($serendipity['GET']['newname'] != '' && file_exists($oldfile) && !file_exists($newfile)) { + $renameValues = array(array( + 'from' => $oldfile, + 'to' => $newfile, + 'thumb' => $serendipity['thumbSuffix'], + 'fthumb' => $file['thumbnail_name'] + )); + + serendipity_plugin_api::hook_event('backend_media_rename', $renameValues); + // Rename file - rename($oldfile, $newfile); + rename($renameValues[0]['from'], $renameValues[0]['to']); + + foreach($renameValues as $renameData) { + // Rename thumbnail + rename($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . (!empty($renameData['fthumb']) ? '.' . $renameData['fthumb'] : '') . '.' . $file['extension'], + $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $serendipity['GET']['newname'] . '.' . $renameData['thumb'] . '.' . $file['extension']); + } - // Rename thumbnail - rename($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . '.' . $file['extension'], - $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $serendipity['GET']['newname'] . '.' . $serendipity['thumbSuffix'] . '.' . $file['extension']); + serendipity_updateImageInDatabase(array('thumbnail_name' => $renameValues[0]['thumb'], 'name' => $serendipity['GET']['newname']), $serendipity['GET']['fid']); - 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) } else { if (!file_exists($oldfile)) { @@ -184,10 +199,19 @@ switch ($serendipity['GET']['adminAction']) { printf(FILE_FETCHED . '
', $serendipity['POST']['imageurl'], $tfile); - // Create thumbnail - if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$tindex]) ) { - echo THUMB_CREATED_DONE . '
'; + $thumbs = array(array( + 'thumbSize' => $serendipity['thumbSize'], + 'thumb' => $serendipity['thumbSuffix'] + )); + serendipity_plugin_api::hook_event('backend_media_makethumb', $thumbs); + + foreach($thumbs as $thumb) { + // Create thumbnail + if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$tindex], $thumb['thumbSize'], $thumb['thumb']) ) { + echo THUMB_CREATED_DONE . '
'; + } } + // Insert into database $image_id = serendipity_insertImageInDatabase($tfile, $serendipity['POST']['target_directory'][$tindex], $authorid); serendipity_plugin_api::hook_event('backend_image_add', $target); @@ -232,10 +256,19 @@ switch ($serendipity['GET']['adminAction']) { @umask(0000); @chmod($target, 0664); - // Create thumbnail - if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$idx]) ) { - echo THUMB_CREATED_DONE . '
'; + $thumbs = array(array( + 'thumbSize' => $serendipity['thumbSize'], + 'thumb' => $serendipity['thumbSuffix'] + )); + serendipity_plugin_api::hook_event('backend_media_makethumb', $thumbs); + + foreach($thumbs as $thumb) { + // Create thumbnail + if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$idx], $thumb['thumbSize'], $thumb['thumb']) ) { + echo THUMB_CREATED_DONE . '
'; + } } + // Insert into database $image_id = serendipity_insertImageInDatabase($tfile, $serendipity['POST']['target_directory'][$idx], $authorid); serendipity_plugin_api::hook_event('backend_image_add', $target); @@ -785,9 +818,12 @@ switch ($serendipity['GET']['adminAction']) { inputFields; } + function toTime($string) { + $ts = strtotime($string); + $this->debug('Calling strtotime(' . $string . ') = ' . $ts); + if ($ts <= 1) { + // Match strings like: "11/16/2005 00:14:53 PM" + if (preg_match('@([01][0-9])/([0-3][0-9])/([0-9]{4}) ([0-2][0-9]):([0-5][0-9]):([0-5][0-9]) (P|A)M@i', $string, $match)) { + if ($match[7] == 'P') { + // Post mediam, add 12 hours. + $match[4] = $match[4] + 12; + } + + $ts = mktime($match[4], $match[5], $match[6], $match[1], $match[2], $match[3]); + $this->debug('Matched string date format: ' . $ts); + } + } + + if ($ts <= 1) { + $ts = time(); + } + + return $ts; + } + function doEntryWork(&$mt_entry, &$tasks){ global $serendipity; @@ -134,10 +157,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import { $entry['allow_comments'] = ($data == '1') ? 'true' : 'false'; break; case 'DATE': - $entry['timestamp'] = strtotime($data); - if ($entry['timestamp'] == 0) { - $entry['timestamp'] = time(); - } + $entry['timestamp'] = $this->totime($data); break; case 's9y_body': @@ -223,10 +243,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import { break; case 'DATE': - $comment['timestamp'] = strtotime($data); - if ($comment['timestamp'] == 0) { - $comment['timestamp'] = time(); - } + $comment['timestamp'] = $this->toTime($data); break; case 'REPLY': @@ -328,7 +345,16 @@ class Serendipity_Import_MovableType extends Serendipity_Import { $tline = trim($line); $this->debug("Continuing inspecting next line: $line"); } - if (preg_match('/^([A-Z\s]+):/', $line, $matches)) { + if (preg_match('/^--------/', $line)) { + $this->debug('Next line is new element. End marker found. Parsing full entry.'); + $entries[] = $this->doEntryWork($entry, $tasks); + $entry = array(); + $el = ""; + $c_el = ""; + $skip = false; + $is_comment = false; + $is_trackback = false; + } elseif (preg_match('/^([A-Z\s]+):/', $line, $matches)) { $this->debug("Match result: $matches[1]"); if ($matches[1] == 'COMMENT') { $this->debug("Marking COMMENT."); @@ -410,6 +436,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import { if ( !is_int($r = serendipity_updertEntry($entry)) ) { echo '
' . $r . '
'; } else { + $this->debug('Saved entry ' . $r . ' (' . $entry['title'] . ')'); $entry['id'] = $r; foreach((array)$comments AS $comment) { $comment['entry_id'] = $r; diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php index 8d1f143..845c1f2 100644 --- a/include/functions_images.inc.php +++ b/include/functions_images.inc.php @@ -135,9 +135,14 @@ function serendipity_updateImageInDatabase($updates, $id) { */ function serendipity_deleteImage($id) { global $serendipity; + $dThumb = array(); + $file = serendipity_fetchImageFromDatabase($id); $dFile = $file['path'] . $file['name'] . '.' . $file['extension']; - $dThumb = $file['path'] . $file['name'] . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . '.' . $file['extension']; + + $dThumb = array(array( + 'fthumb' => $file['thumbnail_name'] + )); if (!serendipity_checkPermission('adminImagesDelete')) { return; @@ -156,8 +161,14 @@ function serendipity_deleteImage($id) { printf(DELETE_FILE_FAIL . '
', $dFile); } - if (@unlink($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dThumb)) { - printf(DELETE_THUMBNAIL . '
', $dThumb); + serendipity_plugin_api::hook_event('backend_media_delete', $dThumb); + foreach($dThumb as $thumb) { + $dfnThumb = $file['path'] . $file['name'] . (!empty($dThumb['fthumb']) ? '.' . $dThumb['fthumb'] : '') . '.' . $file['extension']; + $dfThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dfnThumb; + + if (@unlink($dfThumb)) { + printf(DELETE_THUMBNAIL . '
', $dfnThumb); + } } } else { printf(FILE_NOT_FOUND . '
', $dFile); @@ -379,15 +390,20 @@ function serendipity_insertImageInDatabase($filename, $directory, $authorid = 0, * @access public * @param string The input image filename * @param string The directory to the image file - * @param array The target size of the thumbnail (2-dimensional array width,height) + * @param string The target size of the thumbnail (2-dimensional array width,height) + * @param string Name of the thumbnail * @return array The result size of the thumbnail */ -function serendipity_makeThumbnail($file, $directory = '', $size = false) { +function serendipity_makeThumbnail($file, $directory = '', $size = false, $thumbname = false) { global $serendipity; if ($size === false) { $size = $serendipity['thumbSize']; } + + if ($thumbname === false) { + $thumbname = $serendipity['thumbSuffix']; + } $t = serendipity_parseFileName($file); $f = $t[0]; @@ -395,7 +411,7 @@ function serendipity_makeThumbnail($file, $directory = '', $size = false) { $infile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $file; - $outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $f . '.' . $serendipity['thumbSuffix'] . '.' . $suf; + $outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $f . '.' . $thumbname . '.' . $suf; $fdim = @serendipity_getimagesize($infile, '', $suf); if (isset($fdim['noimage'])) { diff --git a/serendipity_admin_image_selector.php b/serendipity_admin_image_selector.php index efd7726..386b40d 100644 --- a/serendipity_admin_image_selector.php +++ b/serendipity_admin_image_selector.php @@ -148,7 +148,7 @@ switch ($serendipity['GET']['step']) { $thumbHeight = $thumbsize[1]; $imgsrc = $file['imgsrc']; } - $file['finishJSFunction'] = 'serendipity_imageSelector_done(\'' . $serendipity['GET']['textarea'] . '\')'; + $file['finishJSFunction'] = 'serendipity_imageSelector_done(\'' . htmlspecialchars($serendipity['GET']['textarea']) . '\')'; serendipity_plugin_api::hook_event('frontend_image_selector', $file); ?> @@ -161,6 +161,7 @@ switch ($serendipity['GET']['step']) { + @@ -259,9 +260,13 @@ switch ($serendipity['GET']['step']) {