[geeklog-hg] geeklog: Fixed [imageX] tag is not rendered correctly in Wiki-St...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Wed Dec 11 10:56:49 EST 2013


changeset 9345:175a95b33244
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/175a95b33244
user: dengen <taharaxp at gmail.com>
date: Thu Dec 12 00:56:26 2013 +0900
description:
Fixed [imageX] tag is not rendered correctly in Wiki-Style Format mode or Plain Old Text mode. (bug #0001727)
Now, [ImageX] tag is saved in the database as it is.

diffstat:

 public_html/admin/story.php    |    3 +-
 system/classes/story.class.php |  279 +++++++++++++++++++++-------------------
 system/lib-story.php           |   11 +-
 3 files changed, 150 insertions(+), 143 deletions(-)

diffs (truncated from 402 to 300 lines):

diff -r e4f733d4526b -r 175a95b33244 public_html/admin/story.php
--- a/public_html/admin/story.php	Sat Nov 30 09:13:07 2013 -0500
+++ b/public_html/admin/story.php	Thu Dec 12 00:56:26 2013 +0900
@@ -271,9 +271,8 @@
         }
         $result = $story->loadFromArgsArray($_POST);
 
-        // in preview mode, we now need to re-insert the images
         if ($_CONF['maximagesperarticle'] > 0) {
-            $errors = $story->insertImages();
+            $errors = $story->checkAttachedImages();
             if (count($errors) > 0) {
                 $msg = $LANG24[55] . LB . '<ul>' . LB;
                 foreach ($errors as $err) {
diff -r e4f733d4526b -r 175a95b33244 system/classes/story.class.php
--- a/system/classes/story.class.php	Sat Nov 30 09:13:07 2013 -0500
+++ b/system/classes/story.class.php	Thu Dec 12 00:56:26 2013 +0900
@@ -1194,20 +1194,15 @@
     }
 
     /**
-     * Inserts image HTML into the place of Image Placeholders for stories
-     * with images.
+     * Replaces all special syntax tags in intro and body with image HTML
      *
-     * @return array    containing errors, or empty.
+     * @param    string      $text  Intro or Body text
+     * @return   string      processed text
      */
-    function insertImages()
+    function renderImageTags($text)
     {
         global $_CONF, $_TABLES, $LANG24;
 
-        // Grab member vars into locals:
-        $intro = $this->_introtext;
-        $body = $this->_bodytext;
-        $fulltext = "$intro $body";
-
         // check if we have a (different) old sid - the article_images table
         // will only be updated later! cf. bug #0001256
         if (! empty($this->_originalSid) &&
@@ -1217,11 +1212,11 @@
             $ai_sid = $this->_sid;
         }
 
-        $result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} WHERE ai_sid = '{$ai_sid}' ORDER BY ai_img_num");
+        $result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} "
+                         . "WHERE ai_sid = '{$ai_sid}' ORDER BY ai_img_num");
         $nrows = DB_numRows($result);
-        $errors = array();
+
         $stdImageLoc = true;
-
         if (!strstr($_CONF['path_images'], $_CONF['path_html'])) {
             $stdImageLoc = false;
         }
@@ -1229,133 +1224,143 @@
         for ($i = 1; $i <= $nrows; $i++) {
             $A = DB_fetchArray($result);
 
+            $imgpath = '';
+
+            // If we are storing images on a "standard path" i.e. is
+            // available to the host web server, then the url to this
+            // image is based on the path to images, site url, articles
+            // folder and it's filename.
+            //
+            // Otherwise, we have to use the image handler to load the
+            // image from whereever else on the file system we're
+            // keeping them:
+            if ($stdImageLoc) {
+                $imgpath = substr($_CONF['path_images'], strlen($_CONF['path_html']));
+                $imgSrc = $_CONF['site_url'] . '/' . $imgpath . 'articles/' . $A['ai_filename'];
+            } else {
+                $imgSrc = $_CONF['site_url'] . '/getimage.php?mode=articles&image=' . $A['ai_filename'];
+            }
+
             $sizeattributes = COM_getImgSizeAttributes($_CONF['path_images'] . 'articles/' . $A['ai_filename']);
 
+            // Build image tags for each flavour of the image:
+            $img_noalign   = '<img ' . $sizeattributes . 'src="'                    . $imgSrc . '" alt=""' . XHTML . '>';
+            $img_leftalgn  = '<img ' . $sizeattributes . 'class="floatleft" src="'  . $imgSrc . '" alt=""' . XHTML . '>';
+            $img_rightalgn = '<img ' . $sizeattributes . 'class="floatright" src="' . $imgSrc . '" alt=""' . XHTML . '>';
+
+            // Are we keeping unscaled images?
+            if ($_CONF['keep_unscaled_image'] == 1) {
+                // Yes we are, so, we need to find out what the filename
+                // of the original, unscaled image is:
+                $lFilename_large = substr_replace($A['ai_filename'], '_original.',
+                                        strrpos($A['ai_filename'], '.'), 1);
+                $lFilename_large_complete = $_CONF['path_images'] . 'articles/' .
+                                                $lFilename_large;
+
+                // We need to map that filename to the right location
+                // or the fetch script:
+                if ($stdImageLoc) {
+                    $lFilename_large_URL = $_CONF['site_url'] . '/' . $imgpath .
+                                            'articles/' . $lFilename_large;
+                } else {
+                    $lFilename_large_URL = $_CONF['site_url'] .
+                                            '/getimage.php?mode=show&image=' .
+                                            $lFilename_large;
+                }
+
+                // And finally, replace the [imageX_mode] tags with the
+                // image and its hyperlink (only when the large image
+                // actually exists)
+                $lLink_url  = '';
+                $lLink_attr = '';
+                if (file_exists($lFilename_large_complete)) {
+                    $lLink_url = $lFilename_large_URL;
+                    $lLink_attr = array('title' => $LANG24[57]);
+                }
+            }
+
             $norm  = '[image' . $i . ']';
             $left  = '[image' . $i . '_left]';
             $right = '[image' . $i . '_right]';
 
-            $unscalednorm  = '[unscaled' . $i . ']';
-            $unscaledleft  = '[unscaled' . $i . '_left]';
-            $unscaledright = '[unscaled' . $i . '_right]';
+            if (!empty($lLink_url)) {
+                $text = str_replace($norm,  COM_createLink($img_noalign,   $lLink_url, $lLink_attr), $text);
+                $text = str_replace($left,  COM_createLink($img_leftalgn,  $lLink_url, $lLink_attr), $text);
+                $text = str_replace($right, COM_createLink($img_rightalgn, $lLink_url, $lLink_attr), $text);
+            } else {
+                // We aren't wrapping our image tags in hyperlinks, so
+                // just replace the [imagex_mode] tags with the image:
+                $text = str_replace($norm,  $img_noalign,   $text);
+                $text = str_replace($left,  $img_leftalgn,  $text);
+                $text = str_replace($right, $img_rightalgn, $text);
+            }
+
+            // And insert the unscaled mode images:
+            if (($_CONF['allow_user_scaling'] == 1) and ($_CONF['keep_unscaled_image'] == 1)) {
+                if (file_exists($lFilename_large_complete)) {
+                    $imgSrc = $lFilename_large_URL;
+                    $sizeattributes = COM_getImgSizeAttributes($lFilename_large_complete);
+                }
+
+                $unscalednorm  = '[unscaled' . $i . ']';
+                $unscaledleft  = '[unscaled' . $i . '_left]';
+                $unscaledright = '[unscaled' . $i . '_right]';
+
+                $text = str_replace($unscalednorm,
+                    '<img ' . $sizeattributes . 'src="'               . $imgSrc . '" alt=""' . XHTML . '>', $text);
+                $text = str_replace($unscaledleft,
+                    '<img ' . $sizeattributes . 'align="left" src="'  . $imgSrc . '" alt=""' . XHTML . '>', $text);
+                $text = str_replace($unscaledright,
+                    '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt=""' . XHTML . '>', $text);
+            }
+        }
+
+        return $text;
+    }
+
+    /**
+     * Check if using attached images
+     *
+     * @return array    containing errors, or empty.
+     */
+    function checkAttachedImages()
+    {
+        global $_TABLES, $LANG24;
+
+        $text = $this->_introtext . ' ' . $this->_bodytext;
+
+        // check if we have a (different) old sid - the article_images table
+        // will only be updated later! cf. bug #0001256
+        if (! empty($this->_originalSid) &&
+                ($this->_sid != $this->_originalSid)) {
+            $ai_sid = $this->_originalSid;
+        } else {
+            $ai_sid = $this->_sid;
+        }
+
+        $result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} "
+                         . "WHERE ai_sid = '{$ai_sid}' ORDER BY ai_img_num");
+        $nrows = DB_numRows($result);
+        $errors = array();
+        for ($i = 1; $i <= $nrows; $i++) {
+            $A = DB_fetchArray($result);
 
             // See how many times image $i is used in the fulltext of the article:
-            $icount = substr_count($fulltext, $norm) + substr_count($fulltext, $left) +
-                      substr_count($fulltext, $right);
-            // including unscaled.
-            $icount = $icount + substr_count($fulltext, $unscalednorm) +
-                      substr_count($fulltext, $unscaledleft)
-                      + substr_count($fulltext, $unscaledright);
+            $icount = substr_count($text, '[image'    . $i . ']')
+                    + substr_count($text, '[image'    . $i . '_left]')
+                    + substr_count($text, '[image'    . $i . '_right]')
+                    + substr_count($text, '[unscaled' . $i . ']')
+                    + substr_count($text, '[unscaled' . $i . '_left]')
+                    + substr_count($text, '[unscaled' . $i . '_right]');
 
             // If the image we are currently looking at wasn't used, we need
             // to log an error
             if ($icount == 0) {
                 // There is an image that wasn't used, create an error
                 $errors[] = $LANG24[48] . " #$i, {$A['ai_filename']}, " . $LANG24[53];
-            } else {
-                // We had no errors, so this image and all previous images
-                // are used, so we will then go and replace them
-                if (count($errors) == 0) {
-
-                    $imgpath = '';
-
-                    // If we are storing images on a "standard path" i.e. is
-                    // available to the host web server, then the url to this
-                    // image is based on the path to images, site url, articles
-                    // folder and it's filename.
-                    //
-                    // Otherwise, we have to use the image handler to load the
-                    // image from whereever else on the file system we're
-                    // keeping them:
-                    if ($stdImageLoc) {
-                        $imgpath = substr($_CONF['path_images'], strlen($_CONF['path_html']));
-                        $imgSrc = $_CONF['site_url'] . '/' . $imgpath . 'articles/' . $A['ai_filename'];
-                    } else {
-                        $imgSrc = $_CONF['site_url'] . '/getimage.php?mode=articles&image=' . $A['ai_filename'];
-                    }
-
-                    // Build image tags for each flavour of the image:
-                    $img_noalign   = '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt=""' . XHTML . '>';
-                    $img_leftalgn  = '<img ' . $sizeattributes . 'class="floatleft" src="'  . $imgSrc . '" alt=""' . XHTML . '>';
-                    $img_rightalgn = '<img ' . $sizeattributes . 'class="floatright" src="' . $imgSrc . '" alt=""' . XHTML . '>';
-
-
-                    // Are we keeping unscaled images?
-                    if ($_CONF['keep_unscaled_image'] == 1) {
-                        // Yes we are, so, we need to find out what the filename
-                        // of the original, unscaled image is:
-                        $lFilename_large = substr_replace($A['ai_filename'], '_original.',
-                                                strrpos($A['ai_filename'], '.'), 1);
-                        $lFilename_large_complete = $_CONF['path_images'] . 'articles/' .
-                                                        $lFilename_large;
-
-                        // We need to map that filename to the right location
-                        // or the fetch script:
-                        if ($stdImageLoc) {
-                            $lFilename_large_URL = $_CONF['site_url'] . '/' . $imgpath .
-                                                    'articles/' . $lFilename_large;
-                        } else {
-                            $lFilename_large_URL = $_CONF['site_url'] .
-                                                    '/getimage.php?mode=show&image=' .
-                                                    $lFilename_large;
-                        }
-
-                        // And finally, replace the [imageX_mode] tags with the
-                        // image and its hyperlink (only when the large image
-                        // actually exists)
-                        $lLink_url  = '';
-                        $lLink_attr = '';
-                        if (file_exists($lFilename_large_complete)) {
-                            $lLink_url = $lFilename_large_URL;
-                            $lLink_attr = array('title' => $LANG24[57]);
-                        }
-                    }
-
-                    if (!empty($lLink_url)) {
-                        $intro = str_replace($norm,  COM_createLink($img_noalign,   $lLink_url, $lLink_attr), $intro);
-                        $body  = str_replace($norm,  COM_createLink($img_noalign,   $lLink_url, $lLink_attr), $body);
-                        $intro = str_replace($left,  COM_createLink($img_leftalgn,  $lLink_url, $lLink_attr), $intro);
-                        $body  = str_replace($left,  COM_createLink($img_leftalgn,  $lLink_url, $lLink_attr), $body);
-                        $intro = str_replace($right, COM_createLink($img_rightalgn, $lLink_url, $lLink_attr), $intro);
-                        $body  = str_replace($right, COM_createLink($img_rightalgn, $lLink_url, $lLink_attr), $body);
-                    } else {
-                        // We aren't wrapping our image tags in hyperlinks, so
-                        // just replace the [imagex_mode] tags with the image:
-                        $intro = str_replace($norm,  $img_noalign,   $intro);
-                        $body  = str_replace($norm,  $img_noalign,   $body);
-                        $intro = str_replace($left,  $img_leftalgn,  $intro);
-                        $body  = str_replace($left,  $img_leftalgn,  $body);
-                        $intro = str_replace($right, $img_rightalgn, $intro);
-                        $body  = str_replace($right, $img_rightalgn, $body);
-                    }
-
-                    // And insert the unscaled mode images:
-                    if (($_CONF['allow_user_scaling'] == 1) and ($_CONF['keep_unscaled_image'] == 1)) {
-                        if (file_exists($lFilename_large_complete)) {
-                            $imgSrc = $lFilename_large_URL;
-                            $sizeattributes = COM_getImgSizeAttributes($lFilename_large_complete);
-                        }
-
-                        $intro = str_replace($unscalednorm, '<img ' . $sizeattributes . 'src="' .
-                                             $imgSrc . '" alt=""' . XHTML . '>', $intro);
-                        $body  = str_replace($unscalednorm, '<img ' . $sizeattributes . 'src="' .
-                                             $imgSrc . '" alt=""' . XHTML . '>', $body);
-                        $intro = str_replace($unscaledleft, '<img ' . $sizeattributes .
-                                             'align="left" src="' . $imgSrc . '" alt=""' . XHTML . '>', $intro);
-                        $body  = str_replace($unscaledleft, '<img ' . $sizeattributes .
-                                             'align="left" src="' . $imgSrc . '" alt=""' . XHTML . '>', $body);
-                        $intro = str_replace($unscaledright, '<img ' . $sizeattributes .
-                                             'align="right" src="' . $imgSrc. '" alt=""' . XHTML . '>', $intro);
-                        $body  = str_replace($unscaledright, '<img ' . $sizeattributes .
-                                             'align="right" src="' . $imgSrc . '" alt=""' . XHTML . '>', $body);



More information about the geeklog-cvs mailing list