Exemple #1
0
 /**
  * Returns an image meta object corresponding to the given index
  * of the image attachment inside the article. Returns an empty
  * meta image object if the image did not exist.
  *
  * @param int $p_imageIndex - the index of the image attachment in the article
  * @return MetaImage
  */
 public function image($p_imageIndex) {
     $articleImage = new ArticleImage($this->m_dbObject->getArticleNumber(),
     null, $p_imageIndex);
     if (!$articleImage->exists()) {
         return new MetaImage();
     }
     return new MetaImage($articleImage->getImageId());
 }
Exemple #2
0
	/**
	 * This function is a callback for preg_replace_callback().
	 * It will replace <img src="http://[hostname]/[image_dir]/cms-image-000000001.jpg" align="center" alt="alternate text" sub="caption text" id="5">
	 * with <!** Image [image_template_id] align=CENTER alt="alternate text" sub="caption text">
	 * @param array p_match
	 * @return string
	 */
	public function transformImageTags($p_match) {
		array_shift($p_match);
		$attrs = array();
		foreach ($p_match as $attr) {
			$attr = explode('=', $attr);
			if (isset($attr[0]) && !empty($attr[0])) {
				$attrName = trim(strtolower($attr[0]));
				$attrValue = isset($attr[1]) ? $attr[1] : '';
				// Strip out the quotes
				$attrValue = str_replace('"', '', $attrValue);
				$attrs[$attrName] = $attrValue;
			}
		}

		if (!isset($attrs['id'])) {
			return '';
		} else {
			if (strpos($attrs['id'], '_')) {
				list($templateId, $imageRatio) = explode('_', $attrs['id']);
			} else {
				$templateId = $attrs['id'];
			}
			$articleImage = new ArticleImage($this->m_data['NrArticle'], null, $templateId);
			if (!$articleImage->exists()) {
				return '';
			}
		}
		$alignTag = '';
		if (isset($attrs['align'])) {
			$alignTag = 'align="'.$attrs['align'].'"';
		}
		$altTag = '';
		if (isset($attrs['alt']) && strlen($attrs['alt']) > 0) {
			$altTag = 'alt="'.$attrs['alt'].'"';
		}
		$captionTag = '';
		if (isset($attrs['title']) && strlen($attrs['title']) > 0) {
			$captionTag = 'sub="'.$attrs['title'].'"';
		}
		if (isset($attrs['width']) && strlen($attrs['width']) > 0) {
			$widthTag = 'width="'.$attrs['width'].'"';
		}
		if (isset($attrs['height']) && strlen($attrs['height']) > 0) {
			$heightTag = 'height="'.$attrs['height'].'"';
		}
		$ratioTag = '';
		if (isset($imageRatio) && ($imageRatio > 0 && $imageRatio < 100)) {
			$ratioTag = 'ratio="'.$imageRatio.'"';
		}
		$imageTag = "<!** Image $templateId $alignTag $altTag $captionTag $widthTag $heightTag $ratioTag>";
		return $imageTag;
	} // fn TransformImageTags
Exemple #3
0
function parseTextBody($text, $articleNumber)
{
    // Subheads
    $text = preg_replace("/<!\\*\\*\\s*Title\\s*>/i", "<span class=\"campsite_subhead\">", $text);
    $text = preg_replace("/<!\\*\\*\\s*EndTitle\\s*>/i", "</span>", $text);
    // Internal Links with targets
    $text = preg_replace("/<!\\*\\*\\s*Link\\s*Internal\\s*([\\w=&]*)\\s*target[\\s\"]*([\\w_]*)[\\s\"]*>/i", '<a href="/campsite/campsite_internal_link?$1" target="$2">', $text);
    // Internal Links without targets
    $text = preg_replace("/<!\\*\\*\\s*Link\\s*Internal\\s*([\\w=&]*)\\s*>/i", '<a href="/campsite/campsite_internal_link?$1">', $text);
    // External Links (old style 2.1) with targets
    $text = preg_replace("/<!\\*\\*\\s*Link\\s*External[\\s\"]*([^\\s\"]*)[\\s\"]*target[\\s\"]*([\\w_]*)[\\s\"]*>/i", '<a href="$1" target="$2">', $text);
    // External Links (old style 2.1) without targets
    $text = preg_replace("/<!\\*\\*\\s*Link\\s*External[\\s\"]*([^\\s\"]*)[\\s\"]*>/i", '<a href="$1">', $text);
    // End link
    $text = preg_replace("/<!\\*\\*\\s*EndLink\\s*>/i", "</a>", $text);
    // Images
    preg_match_all("/<!\\*\\*\\s*Image\\s*([\\d]*)\\s*/i", $text, $imageMatches);
    preg_match_all("/\\s*sub=\"(.*?)\"/", $text, $titles);
    preg_match_all("/<!\\*\\*\\s*Image\\s*([\\d]*)\\s*(.*?)\\s*ratio=\"(.*?)\"/", $text, $ratios);
    if (isset($imageMatches[1][0])) {
        if (isset($titles) && sizeof($titles) > 0) {
            for ($x = 0; $x < sizeof($titles[0]); $x++) {
                $text = preg_replace("/\\s*" . preg_replace('~\\/~', '\\/', preg_quote($titles[0][$x])) . "/", ' title="' . $titles[1][$x] . '"', $text);
            }
        }
        $formattingErrors = FALSE;
        foreach ($imageMatches[1] as $templateId) {
            // Get the image URL
            $articleImage = new ArticleImage($articleNumber, NULL, $templateId);
            if (!$articleImage->exists()) {
                ArticleImage::RemoveImageTagsFromArticleText($articleNumber, $templateId);
                $formattingErrors = TRUE;
                continue;
            }
            $image = new Image($articleImage->getImageId());
            $imageUrl = $image->getImageUrl();
            unset($fakeTemplateId);
            if (isset($ratios) && sizeof($ratios) > 0) {
                $n = 0;
                foreach ($ratios[3] as $ratio) {
                    if ($ratios[1][$n++] == $templateId) {
                        $fakeTemplateId = $templateId . '_' . $ratio;
                    }
                }
            }
            if (!isset($fakeTemplateId)) {
                $fakeTemplateId = $templateId;
            }
            $text = preg_replace("/<!\\*\\*\\s*Image\\s*" . $templateId . "\\s+/i", '<img src="' . $imageUrl . '" id="' . $fakeTemplateId . '" ', $text);
        }
        if ($formattingErrors) {
            print '<script type="text/javascript">window.location.reload();</script>';
        }
    }
    return $text;
}
 /**
  * Returns an image meta object corresponding to the given index
  * of the image attachment inside the article. Returns an empty
  * meta image object if the image did not exist.
  *
  * @param  int       $p_imageIndex - the index of the image attachment in the article
  * @return MetaImage
  */
 public function image($p_imageIndex)
 {
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $imageCacheKey = $cacheService->getCacheKey(array('MetaImage', $this->m_dbObject->getArticleNumber(), $p_imageIndex), 'article');
     if ($cacheService->contains($imageCacheKey)) {
         return $cacheService->fetch($imageCacheKey);
     }
     $articleImage = new ArticleImage($this->m_dbObject->getArticleNumber(), null, $p_imageIndex);
     if (!$articleImage->exists()) {
         $metaImage = new MetaImage();
     } else {
         $metaImage = new MetaImage($articleImage->getImageId());
     }
     $cacheService->save($imageCacheKey, $metaImage);
     return $metaImage;
 }
Exemple #5
0
function parseTextBody($text, $articleNumber)
{
    $translator = \Zend_Registry::get('container')->getService('translator');
    // Subheads
    $text = preg_replace("/<!\\*\\*\\s*Title\\s*>/i", "<span class=\"campsite_subhead\">", $text);
    $text = preg_replace("/<!\\*\\*\\s*EndTitle\\s*>/i", "</span>", $text);
    // Internal Links with targets
    $text = preg_replace("/<!\\*\\*\\s*Link\\s*Internal\\s*([\\w=&]*)\\s*target[\\s\"]*([\\w_]*)[\\s\"]*>/i", '<a href="/campsite/campsite_internal_link?$1" target="$2">', $text);
    // Internal Links without targets
    $text = preg_replace("/<!\\*\\*\\s*Link\\s*Internal\\s*([\\w=&]*)\\s*>/i", '<a href="/campsite/campsite_internal_link?$1">', $text);
    // External Links (old style 2.1) with targets
    $text = preg_replace("/<!\\*\\*\\s*Link\\s*External[\\s\"]*([^\\s\"]*)[\\s\"]*target[\\s\"]*([\\w_]*)[\\s\"]*>/i", '<a href="$1" target="$2">', $text);
    // External Links (old style 2.1) without targets
    $text = preg_replace("/<!\\*\\*\\s*Link\\s*External[\\s\"]*([^\\s\"]*)[\\s\"]*>/i", '<a href="$1">', $text);
    // End link
    $text = preg_replace("/<!\\*\\*\\s*EndLink\\s*>/i", "</a>", $text);
    // Images
    preg_match_all("/<!\\*\\*\\s*Image\\s*([\\d]*)\\s*/i", $text, $imageMatches);
    preg_match_all("/\\s*sub=\"(.*?)\"/", $text, $titles);
    preg_match_all("/<!\\*\\*\\s*Image\\s*([\\d]*)\\s*(.*?)\\s*ratio=\"(.*?)\"/", $text, $ratios);
    // snippet tag format: <-- Snippet 1 -->
    $snippetPattern = '<\\-\\-\\sSnippet\\s([\\d]+)\\s\\-\\->';
    $text = preg_replace("/{$snippetPattern}/i", '<div data-snippet-id="$1" class="camp_snippet">' . $translator->trans('Snippet', array(), 'articles') . ' $1</div>', $text);
    if (isset($imageMatches[1][0])) {
        if (isset($titles) && sizeof($titles) > 0) {
            for ($x = 0; $x < sizeof($titles[0]); $x++) {
                $text = preg_replace("/\\s*" . preg_replace('~\\/~', '\\/', preg_quote($titles[0][$x])) . "/", ' title="' . htmlspecialchars($titles[1][$x], ENT_QUOTES, 'UTF-8') . '"', $text);
            }
        }
        $formattingErrors = FALSE;
        foreach ($imageMatches[1] as $templateId) {
            // Get the image URL
            $articleImage = new ArticleImage($articleNumber, NULL, $templateId);
            if (!$articleImage->exists()) {
                ArticleImage::RemoveImageTagsFromArticleText($articleNumber, $templateId);
                $formattingErrors = TRUE;
                continue;
            }
            $image = new Image($articleImage->getImageId());
            $imageUrl = $image->getImageUrl();
            unset($fakeTemplateId);
            if (isset($ratios) && sizeof($ratios) > 0) {
                $n = 0;
                foreach ($ratios[3] as $ratio) {
                    if ($ratios[1][$n++] == $templateId) {
                        $fakeTemplateId = $templateId . '_' . $ratio;
                    }
                }
            }
            if (!isset($fakeTemplateId)) {
                $fakeTemplateId = $templateId;
            }
            $text = preg_replace("/<!\\*\\*\\s*Image\\s*" . $templateId . "\\s+/i", '<img src="' . $imageUrl . '" id="' . $fakeTemplateId . '" ', $text);
        }
        if ($formattingErrors) {
            print '<script type="text/javascript">window.location.reload();</script>';
        }
    }
    return $text;
}
Exemple #6
0
 /**
  * Returns true if the article had an attached image identified
  * by the given article internal index.
  *
  * @param  int  $p_imageIndex - the index of the image attachment in the article
  * @return bool
  */
 public function has_image($p_imageIndex)
 {
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKey = $cacheService->getCacheKey(array('has_article_image', $this->m_dbObject->getArticleNumber(), $p_imageIndex), 'article_image');
     if ($cacheService->contains($cacheKey)) {
         $exists = $cacheService->fetch($cacheKey);
     } else {
         $articleImage = new ArticleImage($this->m_dbObject->getArticleNumber(), null, $p_imageIndex);
         $exists = (int) $articleImage->exists();
         $cacheService->save($cacheKey, $exists);
     }
     return $exists;
 }