]> git.mjollnir.org Git - s9y.git/commitdiff
1. Fix importer stuff for moveable Type
authorgarvinhicking <garvinhicking>
Tue, 13 Dec 2005 15:43:10 +0000 (15:43 +0000)
committergarvinhicking <garvinhicking>
Tue, 13 Dec 2005 15:43:10 +0000 (15:43 +0000)
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.

include/admin/category.inc.php
include/admin/entries.inc.php
include/admin/images.inc.php
include/admin/importers/movabletype.inc.php
include/functions_images.inc.php
serendipity_admin_image_selector.php

index 94066a0dd07fa0be41afd89fa78361d33f2b385d..1d15f8c9f970ddc17522c67ecf475cbfda5407cf 100644 (file)
@@ -184,7 +184,7 @@ if ($serendipity['GET']['adminAction'] == 'doDelete' && serendipity_checkFormTok
     <tr>
         <td><?php echo NAME; ?></td>
         <td><input type="text" name="serendipity[cat][name]" value="<?php echo isset($this_cat['category_name']) ? htmlspecialchars($this_cat['category_name']) : ''; ?>" /></td>
-        <td rowspan="5" align="center" valign="middle" width="200" style="border: 1px solid #ccc"><img src="<?php echo isset($this_cat['category_icon']) ? $this_cat['category_icon'] : '' ?>" id="imagepreview" <?php echo empty($this_cat['category_icon']) ? 'style="display: none"' : '' ?>></td>
+        <td rowspan="5" align="center" valign="middle" width="200" style="border: 1px solid #ccc"><img src="<?php echo isset($this_cat['category_icon']) ? $this_cat['category_icon'] : '' ?>" id="imagepreview" <?php echo empty($this_cat['category_icon']) ? 'style="display: none"' : '' ?> /></td>
     </tr>
 
     <tr>
index a15194f2df307aef150a283b56c3af8a0d3d2933..05b6669b79d52d2971555b6b5f03428126c0ad02 100644 (file)
@@ -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');
 
 
index 77fcbbf7e3450871cce877111bc1ec10ccf5ae1d..c7c8a7a8d935ce83eb812149a7ad67f3c2d17c87 100644 (file)
@@ -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 . '<br />', $serendipity['POST']['imageurl'], $tfile);
 
-                    // Create thumbnail
-                    if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$tindex]) ) {
-                        echo THUMB_CREATED_DONE . '<br />';
+                    $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 . '<br />';
+                        }
                     }
+
                     // 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 . '<br />';
+                    $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 . '<br />';
+                        }
                     }
+
                     // 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']) {
 
 
 <?php
+        if (!isset($serendipity['thumbPerPage'])) {
+            $serendipity['thumbPerPage'] = 2;
+        }
         serendipity_displayImageList(
           isset($serendipity['GET']['page'])   ? $serendipity['GET']['page']   : 1,
-          2,
+          $serendipity['thumbPerPage'],
           true
         );
 
index 5572bfed1330929e214881964a9600dd5b9b2e45..119c275464ca5888efd2ca8846edb03fd910464f 100644 (file)
@@ -91,6 +91,29 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
         return $this->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 '<div class="serendipityAdminMsgError">' . $r . '</div>';
                 } else {
+                    $this->debug('Saved entry ' . $r . ' (' . $entry['title'] . ')');
                     $entry['id'] = $r;
                     foreach((array)$comments AS $comment) {
                         $comment['entry_id'] = $r;
index 8d1f1439fa0ce4d23ea4cae348421ed8261e81e9..845c1f254885d84704b9f008c29c203f7f59e9c8 100644 (file)
@@ -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 . '<br />', $dFile);
             }
 
-            if (@unlink($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dThumb)) {
-                printf(DELETE_THUMBNAIL . '<br />', $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 . '<br />', $dfnThumb);
+                }
             }
         } else {
             printf(FILE_NOT_FOUND . '<br />', $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'])) {
index efd7726d03bfcb4b7e71ad4b2d2a979985a9dc26..386b40dcb44701d78e4b5db57dff0cc58826d96b 100644 (file)
@@ -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);
 ?>
     <img align="right" src="<?php echo $imgsrc; ?>">
@@ -161,6 +161,7 @@ switch ($serendipity['GET']['step']) {
                 <input type="hidden" name="imgThumbHeight" value="<?php echo $thumbHeight; ?>" />
                 <input type="hidden" name="imgWidth"  value="<?php echo $dimWidth; ?>" />
                 <input type="hidden" name="imgHeight" value="<?php echo $dimHeight; ?>" />
+                <input type="hidden" name="imgID" value="<?php echo (int)$serendipity['GET']['image']; ?>" />
                 <input type="hidden" name="imgName"   value="<?php echo $imgName; ?>" />
                 <input type="hidden" name="thumbName" value="<?php echo $thumbName; ?>" />
                 <input type="hidden" name="hotlink" value="<?php echo $file['hotlink']; ?>" />
@@ -259,9 +260,13 @@ switch ($serendipity['GET']['step']) {
     <br />
 
     <?php
+        if (!isset($serendipity['thumbPerPage2'])) {
+            $serendipity['thumbPerPage2'] = 3;
+        }
+
         serendipity_displayImageList(
           isset($serendipity['GET']['page'])   ? $serendipity['GET']['page']   : 1,
-          3,
+          $serendipity['thumbPerPage2'],
           false,
           '?serendipity[step]=1' . $add_url . '&amp;serendipity[textarea]='. $serendipity['GET']['textarea'],
           true