Example #1
0
 /**
  * This replaces all article image HTML in intro and body with
  * GL special syntax
  *
  * @param    string      $sid    ID for story to parse
  * @param    string      $intro  Intro text
  * @param    string      $body   Body text
  * @return   string      processed text
  *
  */
 function replaceImages($text)
 {
     global $_CONF, $_TABLES, $LANG24;
     $stdImageLoc = true;
     if (!strstr($_CONF['path_images'], $_CONF['path_html'])) {
         $stdImageLoc = false;
     }
     $count = 0;
     /* If we haven't already cached the images for this story, do so */
     if (!is_array($this->_storyImages)) {
         $result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} WHERE " . "ai_sid = '{$this->_sid}' ORDER BY ai_img_num");
         $nrows = DB_numRows($result);
         $this->_storyImages = array();
         for ($i = 1; $i <= $nrows; $i++) {
             $this->_storyImages[] = DB_fetchArray($result);
         }
         $count = $nrows;
     } else {
         $count = count($this->_storyImages);
     }
     // If the article has any images, remove them back to [image] tags.
     for ($i = 0; $i < $count; $i++) {
         $A = $this->_storyImages[$i];
         $imageX = '[image' . ($i + 1) . ']';
         $imageX_left = '[image' . ($i + 1) . '_left]';
         $imageX_right = '[image' . ($i + 1) . '_right]';
         $sizeattributes = COM_getImgSizeAttributes($_CONF['path_images'] . 'articles/' . $A['ai_filename']);
         $lLinkPrefix = '';
         $lLinkSuffix = '';
         if ($_CONF['keep_unscaled_image'] == 1) {
             $lFilename_large = substr_replace($A['ai_filename'], '_original.', strrpos($A['ai_filename'], '.'), 1);
             $lFilename_large_complete = $_CONF['path_images'] . 'articles/' . $lFilename_large;
             if ($stdImageLoc) {
                 $imgpath = substr($_CONF['path_images'], strlen($_CONF['path_html']));
                 $lFilename_large_URL = $_CONF['site_url'] . '/' . $imgpath . 'articles/' . $lFilename_large;
             } else {
                 $lFilename_large_URL = $_CONF['site_url'] . '/getimage.php?mode=show&amp;image=' . $lFilename_large;
             }
             if (file_exists($lFilename_large_complete)) {
                 $lLinkPrefix = '<a href="' . $lFilename_large_URL . '" title="' . $LANG24[57] . '">';
                 $lLinkSuffix = '</a>';
             }
         }
         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&amp;image=' . $A['ai_filename'];
         }
         $norm = $lLinkPrefix . '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix;
         $left = $lLinkPrefix . '<img ' . $sizeattributes . 'class="floatleft" src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix;
         $right = $lLinkPrefix . '<img ' . $sizeattributes . 'class="floatright" src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix;
         $text = str_replace($norm, $imageX, $text);
         $text = str_replace($left, $imageX_left, $text);
         $text = str_replace($right, $imageX_right, $text);
         if ($_CONF['allow_user_scaling'] == 1 and $_CONF['keep_unscaled_image'] == 1) {
             $unscaledX = '[unscaled' . ($i + 1) . ']';
             $unscaledX_left = '[unscaled' . ($i + 1) . '_left]';
             $unscaledX_right = '[unscaled' . ($i + 1) . '_right]';
             if (file_exists($lFilename_large_complete)) {
                 $sizeattributes = COM_getImgSizeAttributes($lFilename_large_complete);
                 $norm = '<img ' . $sizeattributes . 'src="' . $lFilename_large_URL . '" alt=""' . XHTML . '>';
                 $left = '<img ' . $sizeattributes . 'align="left" src="' . $lFilename_large_URL . '" alt=""' . XHTML . '>';
                 $right = '<img ' . $sizeattributes . 'align="right" src="' . $lFilename_large_URL . '" alt=""' . XHTML . '>';
             }
             $text = str_replace($norm, $unscaledX, $text);
             $text = str_replace($left, $unscaledX_left, $text);
             $text = str_replace($right, $unscaledX_right, $text);
         }
     }
     return $text;
 }
Example #2
0
/**
 * Inserts image HTML into the place of Image Placeholders
 *
 * @return string   Text with image placeholders removed
 */
function STORY_renderImages($sid, $text)
{
    global $_CONF, $_TABLES, $LANG24;
    $parsedText = $text;
    $ai_sid = $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();
    $stdImageLoc = true;
    if (!strstr($_CONF['path_images'], $_CONF['path_html'])) {
        $stdImageLoc = false;
    }
    for ($i = 1; $i <= $nrows; $i++) {
        $A = DB_fetchArray($result);
        $sizeattributes = COM_getImgSizeAttributes($_CONF['path_images'] . 'articles/' . $A['ai_filename']);
        $norm = '[image' . $i . ']';
        $left = '[image' . $i . '_left]';
        $right = '[image' . $i . '_right]';
        $unscalednorm = '[unscaled' . $i . ']';
        $unscaledleft = '[unscaled' . $i . '_left]';
        $unscaledright = '[unscaled' . $i . '_right]';
        $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&amp;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&amp;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)) {
            $parsedText = str_replace($norm, COM_createLink($img_noalign, $lLink_url, $lLink_attr), $parsedText);
            $parsedText = str_replace($left, COM_createLink($img_leftalgn, $lLink_url, $lLink_attr), $parsedText);
            $parsedText = str_replace($right, COM_createLink($img_rightalgn, $lLink_url, $lLink_attr), $parsedText);
        } else {
            // We aren't wrapping our image tags in hyperlinks, so
            // just replace the [imagex_mode] tags with the image:
            $parsedText = str_replace($norm, $img_noalign, $parsedText);
            $parsedText = str_replace($left, $img_leftalgn, $parsedText);
            $parsedText = str_replace($right, $img_rightalgn, $parsedText);
        }
        // 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);
            }
            $parsedText = str_replace($unscalednorm, '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt=""' . XHTML . '>', $parsedText);
            $parsedText = str_replace($unscaledleft, '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt=""' . XHTML . '>', $parsedText);
            $parsedText = str_replace($unscaledright, '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt=""' . XHTML . '>', $parsedText);
        }
    }
    return $parsedText;
}