/** * This is called when an image is deleted. * It will disassociate the image from all articles. * * @param int $p_imageId * @return void */ public static function OnImageDelete($p_imageId) { global $g_ado_db; // Get the articles that use this image. $queryStr = "SELECT * FROM ArticleImages WHERE IdImage={$p_imageId}"; $rows = $g_ado_db->GetAll($queryStr); if (is_array($rows)) { foreach ($rows as $row) { ArticleImage::RemoveImageTagsFromArticleText($row['NrArticle'], $row['Number']); } $queryStr = "DELETE FROM ArticleImages WHERE IdImage={$p_imageId}"; $g_ado_db->Execute($queryStr); $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $cacheService->clearNamespace('article_image'); } }
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; }
/** * This is called when an image is deleted. * It will disassociate the image from all articles. * * @param int $p_imageId * @return void */ public static function OnImageDelete($p_imageId) { global $g_ado_db; // Get the articles that use this image. $queryStr = "SELECT * FROM ArticleImages WHERE IdImage={$p_imageId}"; $rows = $g_ado_db->GetAll($queryStr); if (is_array($rows)) { foreach ($rows as $row) { ArticleImage::RemoveImageTagsFromArticleText($row['NrArticle'], $row['Number']); } $queryStr = "DELETE FROM ArticleImages WHERE IdImage={$p_imageId}"; $g_ado_db->Execute($queryStr); } }
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; }