Copyright (C) 2005-2012 Leo Feyer
Author: Tim Gatzky (info@tim-gatzky.de)
Inheritance: extends Frontend
Example #1
0
 public function testImageInterface()
 {
     $image = new ArticleImage(self::ARTICLE_NUMBER, new LocalImage(self::PICTURE_LANDSCAPE));
     $this->assertEquals(self::PICTURE_LANDSCAPE, $image->getPath());
     $this->assertEquals(500, $image->getWidth());
     $this->assertEquals(333, $image->getHeight());
     $this->assertFalse($image->isDefault());
 }
	/**
	 * Creates the list of objects. Sets the parameter $p_hasNextElements to
	 * true if this list is limited and elements still exist in the original
	 * list (from which this was truncated) after the last element of this
	 * list.
	 *
	 * @param int $p_start
	 * @param int $p_limit
	 * @param array $p_parameters
	 * @param int &$p_count
	 * @return array
	 */
	protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count)
	{
	    $articleImagesList = ArticleImage::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
	    $metaImagesList = array();
	    foreach ($articleImagesList as $image) {
	        $metaImagesList[] = new MetaImage($image->getImageId());
	    }
	    return $metaImagesList;
	}
 /**
  * @Route("get_img", name="newscoop_get_img")
  */
 public function indexAction(Request $request)
 {
     // reads parameters from image link URI
     $imageId = $request->get('ImageId', null);
     $articleNr = $request->get('NrArticle', null);
     $imageNr = $request->get('NrImage', null);
     $imageRatio = $request->get('ImageRatio', null);
     $imageResizeWidth = $request->get('ImageWidth', null);
     $imageResizeHeight = $request->get('ImageHeight', null);
     $imageCrop = $request->get('ImageForcecrop', null);
     $resizeCrop = $request->get('ImageCrop', null);
     if (empty($imageId) && !empty($imageNr) && !empty($articleNr)) {
         $articleImage = new \ArticleImage($articleNr, null, $imageNr);
         $imageId = $articleImage->getImageId();
     }
     $showImage = new \CampGetImage($imageId, $imageRatio, $imageResizeWidth, $imageResizeHeight, $imageCrop, $resizeCrop);
     die;
 }
 public static function boot()
 {
     parent::boot();
     ArticleImage::creating(function ($image) {
         $image->order = ArticleImage::where('blog_article_id', '=', $image->blog_article_id)->count() + 1;
     });
     ArticleImage::deleted(function ($image) {
         $images = ArticleImage::where('blog_article_id', '=', $image->blog_article_id)->orderBy('order', 'asc')->get();
         $i = 1;
         foreach ($images as $image) {
             $image->order = $i;
             $i++;
             $image->save();
         }
     });
 }
 /**
  * Creates the list of objects. Sets the parameter $p_hasNextElements to
  * true if this list is limited and elements still exist in the original
  * list (from which this was truncated) after the last element of this
  * list.
  *
  * @param int $p_start
  * @param int $p_limit
  * @param array $p_parameters
  * @param int &$p_count
  * @return array
  */
 protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count)
 {
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKey = $cacheService->getCacheKey(array('ArticleImagesList', implode('-', $this->m_constraints), implode('-', $this->m_order), $p_start, $p_limit, implode('-', $p_parameters), $p_count), 'article_image');
     if ($cacheService->contains($cacheKey)) {
         $metaImagesList = $cacheService->fetch($cacheKey);
     } else {
         $articleImagesList = ArticleImage::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
         $metaImagesList = array();
         foreach ($articleImagesList as $image) {
             $metaImagesList[] = new MetaImage($image->getImageId());
         }
         $cacheService->save($cacheKey, $metaImagesList);
     }
     return $metaImagesList;
 }
 public function order($id)
 {
     $image = ArticleImage::findOrFail($id);
     $order = $image->order;
     $image->order = \Input::get('order');
     $image->save();
     if ($order > $image->order) {
         $images = ArticleImage::where('blog_article_id', '=', $image->blog_article_id)->orderBy('order', 'asc')->orderBy('updated_at', 'desc')->get();
     } else {
         $images = ArticleImage::where('blog_article_id', '=', $image->blog_article_id)->orderBy('order', 'asc')->orderBy('updated_at', 'asc')->get();
     }
     $i = 1;
     foreach ($images as $image) {
         $image->order = $i;
         $i++;
         $image->save();
     }
     \Session::flash('message', 'Article Image order successfully updated!');
     return \Redirect::back();
 }
Example #7
0
 /**
  * Delete the row from the database, all article references to this image,
  * and the file(s) on disk.
  *
  * @return mixed
  *		TRUE if the record was deleted,
  * 		return a PEAR_Error on failure.
  */
 public function delete()
 {
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleImage.php';
     if (function_exists("camp_load_translation_strings")) {
         camp_load_translation_strings("api");
     }
     $imageStorageService = Zend_Registry::get('container')->getService('image.update_storage');
     if ($imageStorageService->isDeletable($this->getImageFileName())) {
         // Deleting the images from disk is the most common place for
         // something to go wrong, so we do that first.
         $thumb = $this->getThumbnailStorageLocation();
         $imageFile = $this->getImageStorageLocation();
         if (file_exists($thumb) && !is_writable($thumb)) {
             return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $thumb), CAMP_ERROR_DELETE_FILE);
         }
         if (file_exists($imageFile) && !is_writable($imageFile)) {
             return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $imageFile), CAMP_ERROR_DELETE_FILE);
         }
         if (file_exists($imageFile) && !unlink($imageFile)) {
             return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $imageFile), CAMP_ERROR_DELETE_FILE);
         }
         if (file_exists($thumb) && !unlink($thumb)) {
             return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $thumb), CAMP_ERROR_DELETE_FILE);
         }
     }
     // Delete all the references to this image.
     ArticleImage::OnImageDelete($this->getImageId());
     $imageId = $this->getImageId();
     $imageDescription = $this->getDescription();
     // @ticket CS-4225
     $em = \Zend_Registry::get('container')->getService('em');
     $entity = $em->find('Newscoop\\Image\\LocalImage', $imageId);
     $em->remove($entity);
     $em->flush();
     // Delete the record in the database
     if (!parent::delete()) {
         return new PEAR_Error(getGS("Could not delete record from the database."));
     }
     return true;
 }
 /**
  * Set images for the article
  *
  * @param \Article                                  $article
  * @param \Newscoop\IngestPluginBundle\Entity\Entry $entry
  */
 protected function setArticleImagesLegacy(\Article $article, \Newscoop\IngestPluginBundle\Entity\Feed\Entry $entry)
 {
     $images = $entry->getImages();
     if (!is_array($images) || empty($images)) {
         return;
     }
     $oldImages = \ArticleImage::GetImagesByArticleNumber($article->getArticleNumber());
     if (is_array($oldImages)) {
         foreach ($oldImages as $image) {
             $image->delete();
         }
     }
     $filesystem = new Filesystem();
     foreach ($images as $image) {
         if (!array_key_exists('location', $image) || !$image['location']) {
             continue;
         }
         $imagePath = '';
         if ($filesystem->exists($image['location'])) {
             $basename = basename($image['location']);
             $imagePath = $image['location'];
         } else {
             $tmpPath = tempnam(sys_get_temp_dir(), 'NWSIMG');
             try {
                 $filesystem->copy($image['location'], $tmpPath, true);
             } catch (IOExceptionInterface $e) {
                 continue;
             }
             $imagePath = $tmpPath;
             $basename = basename($image['location']);
         }
         $imagesize = getimagesize($imagePath);
         $info = array('name' => $basename, 'type' => $imagesize['mime'], 'tmp_name' => $imagePath, 'size' => filesize($imagePath), 'error' => 0);
         $attributes = array('Photographer' => array_key_exists('photographer', $image) ? $image['photographer'] : '', 'Description' => array_key_exists('description', $image) ? $image['description'] : '', 'Source' => 'newsfeed', 'Status' => 'approved');
         try {
             $image = \Image::OnImageUpload($info, $attributes, null, null, true);
             \ArticleImage::AddImageToArticle($image->getImageId(), $article->getArticleNumber(), null);
         } catch (\Exception $e) {
             var_dump($e);
             exit;
         }
     }
 }
Example #9
0
$articleObj = new Article($f_language_selected, $f_article_number);
if (!$articleObj->exists()) {
	camp_html_display_error(getGS('Article does not exist.'), null, true);
	exit;
}

$imageObj = new Image($f_image_id);
if (!$imageObj->exists()) {
	camp_html_display_error(getGS('Image does not exist.'), null, true);
	exit;
}

// This file can only be accessed if the user has the right to change articles
// or the user created this article and it hasnt been published yet.
if (!$g_user->hasPermission('AttachImageToArticle')) {
	camp_html_display_error(getGS("You do not have the right to attach images to articles."), null, true);
	exit;
}

ArticleImage::AddImageToArticle($f_image_id, $f_article_number);

?>
<script>
try {
    parent.$.fancybox.reload = true;
    parent.$.fancybox.message = "<?php putGS("Image '$1' added.", addslashes($imageObj->getDescription())); ?>";
    parent.$.fancybox.close();
} catch (e) {}
</script>
Example #10
0
 /**
  * Process item
  * @param  Article $article
  * @return array
  */
 public function processItem($article)
 {
     global $g_user, $Campsite;
     $translator = \Zend_Registry::get('container')->getService('translator');
     $editorService = \Zend_Registry::get('container')->getService('newscoop.editor');
     $articleLink = $editorService->getLink($article);
     $articleLinkParams = $editorService->getLinkParameters($article);
     $articleLinkParamsTranslate = $articleLinkParams . '&amp;f_action=translate&amp;f_action_workflow=' . $article->getWorkflowStatus() . '&amp;f_article_code=' . $article->getArticleNumber() . '_' . $article->getLanguageId();
     $previewLink = $Campsite['WEBSITE_URL'] . '/admin/articles/preview.php' . $editorService->getLinkParameters($article);
     $htmlPreviewLink = '<a href="' . $previewLink . '" target="_blank" title="' . $translator->trans('Preview') . '">' . $translator->trans('Preview') . '</a>';
     $translateLink = $Campsite['WEBSITE_URL'] . '/admin/articles/translate.php' . $articleLinkParamsTranslate;
     $htmlTranslateLink = '<a href="' . $translateLink . '" target="_blank" title="' . $translator->trans('Translate') . '">' . $translator->trans('Translate') . '</a>';
     $lockInfo = '';
     $lockHighlight = false;
     $timeDiff = camp_time_diff_str($article->getLockTime());
     if ($article->isLocked() && $timeDiff['days'] <= 0) {
         $lockUser = new User($article->getLockedByUser());
         if ($timeDiff['hours'] > 0) {
             $lockInfo = $translator->trans('The article has been locked by $1 ($2) $3 hour(s) and $4 minute(s) ago.', array('$1' => htmlspecialchars($lockUser->getRealName()), '$2' => htmlspecialchars($lockUser->getUserName()), '$3' => $timeDiff['hours'], '$4' => $timeDiff['minutes']), 'articles');
         } else {
             $lockInfo = $translator->trans('The article has been locked by $1 ($2) $3 minute(s) ago.', array('$1' => htmlspecialchars($lockUser->getRealName()), '$2' => htmlspecialchars($lockUser->getUserName()), '$3' => $timeDiff['minutes']), 'articles');
         }
         if ($article->getLockedByUser() != $g_user->getUserId()) {
             $lockHighlight = true;
         }
     }
     $tmpUser = new User($article->getCreatorId());
     $tmpArticleType = new ArticleType($article->getType());
     $tmpAuthor = new Author();
     $articleAuthors = ArticleAuthor::GetAuthorsByArticle($article->getArticleNumber(), $article->getLanguageId());
     foreach ((array) $articleAuthors as $author) {
         if (strtolower($author->getAuthorType()->getName()) == 'author') {
             $tmpAuthor = $author;
             break;
         }
     }
     if (!$tmpAuthor->exists() && isset($articleAuthors[0])) {
         $tmpAuthor = $articleAuthors[0];
     }
     $onFrontPage = $article->onFrontPage() ? $translator->trans('Yes') : $translator->trans('No');
     $onSectionPage = $article->onSectionPage() ? $translator->trans('Yes') : $translator->trans('No');
     $imagesNo = (int) ArticleImage::GetImagesByArticleNumber($article->getArticleNumber(), true);
     $topicsNo = (int) ArticleTopic::GetArticleTopics($article->getArticleNumber(), true);
     $commentsNo = '';
     if ($article->commentsEnabled()) {
         global $controller;
         $repositoryComments = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment');
         $filter = array('thread' => $article->getArticleNumber(), 'language' => $article->getLanguageId());
         $params = array('sFilter' => $filter);
         $commentsNo = $repositoryComments->getCount($params);
     } else {
         $commentsNo = 'No';
     }
     // get language code
     $language = new Language($article->getLanguageId());
     return array($article->getArticleNumber(), $article->getLanguageId(), $article->getOrder(), sprintf('%s <a href="%s" title="%s %s">%s</a>', $article->isLocked() ? '<span class="ui-icon ui-icon-locked' . (!$lockHighlight ? ' current-user' : '') . '" title="' . $lockInfo . '"></span>' : '', $articleLink, $translator->trans('Edit'), htmlspecialchars($article->getName() . " ({$article->getLanguageName()})"), htmlspecialchars($article->getName() . (empty($_REQUEST['language']) ? " ({$language->getCode()})" : ''))), htmlspecialchars($article->getSection()->getName()), $article->getWebcode(), htmlspecialchars($tmpArticleType->getDisplayName()), htmlspecialchars($tmpUser->getRealName()), htmlspecialchars($tmpAuthor->getName()), $article->getWorkflowStatus(), $onFrontPage, $onSectionPage, $imagesNo, $topicsNo, $commentsNo, (int) $article->getReads(), Geo_Map::GetArticleMapId($article) != null ? $translator->trans('Yes') : $translator->trans('No'), (int) sizeof(Geo_Map::GetLocationsByArticle($article)), $article->getCreationDate(), $article->getPublishDate(), $article->getLastModified(), $htmlPreviewLink, $htmlTranslateLink);
 }
Example #11
0
 function getImageByNumber($articleId, $imageNumber)
 {
     $articleImage = new ArticleImage($articleId, null, $imageNumber);
     $image = $articleImage->getImage();
     return $image;
 }
Example #12
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());
 }
Example #13
0
 /**
  * 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');
     }
 }
Example #14
0
 /**
  * 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);
     }
 }
Example #15
0
 /**
  * Set default article image
  *
  * @param int $articleNumber
  * @param ImageInterface $image
  * @return void
  */
 public function setDefaultArticleImage($articleNumber, ArticleImage $image)
 {
     $query = $this->orm->createQuery('UPDATE Newscoop\\Image\\ArticleImage i SET i.isDefault = 0 WHERE i.articleNumber = :articleNumber');
     $query->setParameter('articleNumber', $articleNumber)->execute();
     $image->setIsDefault(true);
     $this->orm->flush($image);
     $this->orm->clear();
 }
Example #16
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
Example #17
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;
}
Example #18
0
    /**
     * Sets the URI path and query values based on given parameters.
     *
     * @param array $p_params
     *      An array of valid URL parameters
     * @param boolean $p_preview
     *      If true, will keep the preview parameters in the URL
     *
     * @return void
     */
    protected function buildURI(array &$p_params = array(), $p_preview = false) {
        if ($this->isValidCache()) {
            return;
        }

        if (count($p_params) == 0) {
            return;
        }
        $parameter = strtolower(array_shift($p_params));

        switch ($parameter) {
            case 'root_level':
                $this->m_buildPath = $this->m_config->getSetting('SUBDIR').'/';
                if ($p_preview) {
                    $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters);
                } else {
                    $this->m_buildQueryArray = array();
                }
                $p_params = array();
                break;
            case 'articleattachment':
                $context = CampTemplate::singleton()->context();
                $attachment = new Attachment($context->attachment->identifier);
                $this->m_buildPath = $attachment->getAttachmentUri();
                $this->m_buildQueryArray = array();
                $p_params = array();
                break;
            case 'articlecomment':
                $context = CampTemplate::singleton()->context();
                if ($context->comment->defined) {
                    $this->m_buildQueryArray['acid'] = $context->comment->identifier;
                }
                break;
            case 'image':
                $this->m_buildQueryArray = array();
                if (isset($p_params[0]) && is_numeric($p_params[0])) {
                    $this->processOldImageOptions($imageNo, $p_params);
                } else {
                    $this->processImageOptions($imageNo, $p_params);
                }

                $context = CampTemplate::singleton()->context();
                if (!is_null($imageNo)) {
                    $oldImage = $context->image;
                    $articleImage = new ArticleImage($context->article->number, null, $imageNo);
                    $context->image = new MetaImage($articleImage->getImageId());
                }
                $this->m_buildPath = $this->m_config->getSetting('SUBDIR').'/get_img';
                $this->m_validURI = $context->image->defined();
                $this->m_buildQueryArray['ImageId'] = $context->image->number;
                if (!is_null($imageNo)) {
                    $context->image = $oldImage;
                }
                $p_params = array();
                break;
            case 'previous_subtitle':
            case 'next_subtitle':
            case 'all_subtitles':
                $option = isset($p_params[0]) ? array_shift($p_params) : null;
                $article = CampTemplate::singleton()->context()->article;
                $subtitleNo = $article->current_subtitle_no($option);
                if (!$article->defined || (!is_null($subtitleNo) && !is_numeric($subtitleNo))) {
                    return;
                }
                $fieldObj = $article->$option;
                if (($parameter == 'previous_subtitle' && !$fieldObj->has_previous_subtitles)
                || ($parameter == 'next_subtitle' && !$fieldObj->has_next_subtitles)) {
                    return;
                }
                $subtitleURLId = $article->subtitle_url_id($option);
                if ($parameter == 'all_subtitles') {
                    $newSubtitleNo = 'all';
                } else {
                    $newSubtitleNo = $subtitleNo + ($parameter == 'previous_subtitle' ? -1 : 1);
                }
                $this->m_buildQueryArray[$subtitleURLId] = $newSubtitleNo;
                break;
            case 'previous_items':
            case 'next_items':
                $context = CampTemplate::singleton()->context();
                if ($context->current_list == null) {
                    return;
                }
                $listId = $context->current_list->id;
                $this->m_buildQueryArray[$listId] = ($parameter == 'previous_items' ?
                $context->current_list->previous_start : $context->current_list->next_start);
                if ($this->m_buildQueryArray[$listId] == 0) {
                    unset($this->m_buildQueryArray[$listId]);
                }
                break;
            case 'reset_issue_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('IssuesList');
                $this->resetList($listIdPrefix);
                break;
            case 'reset_section_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('SectionsList');
                $this->resetList($listIdPrefix);
                break;
            case 'reset_article_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('ArticlesList');
                $this->resetList($listIdPrefix);
                break;
            case 'reset_searchresult_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('SearchResultsList');
                $this->resetList($listIdPrefix);
                break;
            case 'reset_subtitle_list':
                $context = CampTemplate::singleton()->context();
                $listIdPrefix = $context->list_id_prefix('SubtitlesList');
                $this->resetList($listIdPrefix);
                break;
            default:
                ;
        }
    }
Example #19
0
 * @author Holman Romero <*****@*****.**>
 * @copyright 2007 MDLF, Inc.
 * @license http://www.gnu.org/licenses/gpl.txt
 * @version $Revision$
 * @link http://www.sourcefabric.org
 */

/**
 * Includes
 */
$GLOBALS['g_campsiteDir'] = dirname(__FILE__);
require_once($GLOBALS['g_campsiteDir'].'/template_engine/classes/CampRequest.php');
require_once($GLOBALS['g_campsiteDir'].'/template_engine/classes/CampGetImage.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleImage.php');

// reads parameters from image link URI
$imageId = (int) CampRequest::GetVar('ImageId', null, 'get');
$articleNr = (int) CampRequest::GetVar('NrArticle', null, 'get');
$imageNr = (int) CampRequest::GetVar('NrImage', null, 'get');
$imageRatio = (int) CampRequest::GetVar('ImageRatio', null, 'get');
$imageResizeWidth = (int) CampRequest::GetVar('ImageWidth', null, 'get');
$imageResizeHeight = (int) CampRequest::GetVar('ImageHeight', null, 'get');

if (empty($imageId) && !empty($imageNr) && !empty($articleNr)) {
	$articleImage = new ArticleImage($articleNr, null, $imageNr);
	$imageId = $articleImage->getImageId();
}

$showImage = new CampGetImage($imageId, $imageRatio, $imageResizeWidth, $imageResizeHeight);

?>
Example #20
0
	/**
	 * Delete the row from the database, all article references to this image,
	 * and the file(s) on disk.
	 *
	 * @return mixed
	 *		TRUE if the record was deleted,
	 * 		return a PEAR_Error on failure.
	 */
	public function delete()
	{
		require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleImage.php');

		if (function_exists("camp_load_translation_strings")) {
			camp_load_translation_strings("api");
		}

		// Deleting the images from disk is the most common place for
		// something to go wrong, so we do that first.
		$thumb = $this->getThumbnailStorageLocation();
		$imageFile = $this->getImageStorageLocation();

		if (file_exists($thumb) && !is_writable($thumb)) {
			return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $thumb), CAMP_ERROR_DELETE_FILE);
		}
		if (file_exists($imageFile) && !is_writable($imageFile)) {
			return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $imageFile), CAMP_ERROR_DELETE_FILE);
		}
		if (file_exists($imageFile) && !unlink($imageFile)) {
			return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $imageFile), CAMP_ERROR_DELETE_FILE);
		}
		if (file_exists($thumb) && !unlink($thumb)) {
			return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $thumb), CAMP_ERROR_DELETE_FILE);
		}

		// Delete all the references to this image.
		ArticleImage::OnImageDelete($this->getImageId());

		$imageId = $this->getImageId();
		$imageDescription = $this->getDescription();
		// Delete the record in the database
		if (!parent::delete()) {
			return new PEAR_Error(getGS("Could not delete record from the database."));
		}

		$logtext = getGS('Image "$1" ($2) deleted', $imageDescription, $imageId);
		Log::Message($logtext, null, 42);
		return true;
	} // fn delete
Example #21
0
 /**
  * Process the image statement given in Campsite internal formatting.
  * Returns a standard image URL.
  *
  * @param  array  $p_matches
  * @return string
  */
 public static function ProcessImageLink(array $p_matches)
 {
     $context = CampTemplate::singleton()->context();
     $oldImage = $context->image;
     $uri = $context->url;
     if ($uri->article->number == 0) {
         return '';
     }
     $imageNumber = $p_matches[1];
     $detailsString = $p_matches[2];
     $detailsArray = array();
     if (trim($detailsString) != '') {
         $imageAttributes = 'align|alt|sub|width|height|ratio|\\w+';
         preg_match_all("/[\\s]+({$imageAttributes})=\"([^\"]+)\"/i", $detailsString, $detailsArray1);
         $detailsArray1[1] = array_map('strtolower', $detailsArray1[1]);
         if (count($detailsArray1[1]) > 0) {
             $detailsArray1 = array_combine($detailsArray1[1], $detailsArray1[2]);
         } else {
             $detailsArray1 = array();
         }
         preg_match_all("/[\\s]+({$imageAttributes})=([^\"\\s]+)/i", $detailsString, $detailsArray2);
         $detailsArray2[1] = array_map('strtolower', $detailsArray2[1]);
         if (count($detailsArray2[1]) > 0) {
             $detailsArray2 = array_combine($detailsArray2[1], $detailsArray2[2]);
         } else {
             $detailsArray2 = array();
         }
         $detailsArray = array_merge($detailsArray1, $detailsArray2);
     }
     $articleImage = new ArticleImage($uri->article->number, null, $imageNumber);
     $imageObj = $articleImage->getImage();
     $image = new MetaImage($articleImage->getImageId());
     $context->image = $image;
     $imageSize = @getimagesize($imageObj->getImageStorageLocation());
     unset($imageObj);
     $imageOptions = '';
     $preferencesService = \Zend_Registry::get('container')->getService('system_preferences_service');
     if (array_key_exists('sub', $detailsArray)) {
         if ($preferencesService->MediaRichTextCaptions == 'Y') {
             $detailsArray['sub'] = html_entity_decode($detailsArray['sub'], ENT_QUOTES, 'UTF-8');
         } else {
             $detailsArray['sub'] = strip_tags(html_entity_decode($detailsArray['sub'], ENT_QUOTES, 'UTF-8'));
         }
     }
     $defaultOptions = array('ratio' => 'EditorImageRatio', 'width' => 'EditorImageResizeWidth', 'height' => 'EditorImageResizeHeight');
     foreach (array('ratio', 'width', 'height') as $imageOption) {
         $defaultOption = (int) $preferencesService->get($defaultOptions[$imageOption]);
         if (isset($detailsArray[$imageOption]) && $detailsArray[$imageOption] > 0) {
             if (strpos($detailsArray[$imageOption], '%') === false) {
                 $imageOptions .= " {$imageOption} " . (int) $detailsArray[$imageOption];
                 $detailsArray[$imageOption] = $detailsArray[$imageOption] . "px";
             }
         } elseif ($imageOption != 'ratio' && $defaultOption > 0) {
             $imageOptions .= " {$imageOption} {$defaultOption}";
         } elseif ($imageOption == 'ratio' && $defaultOption != 100) {
             $imageOptions .= " {$imageOption} {$defaultOption}";
         }
     }
     $imageOptions = trim($imageOptions);
     $imgZoomLink = '';
     if ($preferencesService->EditorImageZoom == 'Y' && strlen($imageOptions) > 0) {
         $imgZoomLink = '/' . $image->filerpath;
     }
     try {
         $templatesService = \Zend_Registry::get('container')->getService('newscoop.templates.service');
         $smarty = $templatesService->getSmarty();
         $uri->uri_parameter = "image {$imageOptions}";
         $smarty->assign('imageDetails', $detailsArray);
         $smarty->assign('MediaRichTextCaptions', $preferencesService->MediaRichTextCaptions);
         $smarty->assign('uri', $uri);
         $smarty->assign('imgZoomLink', $imgZoomLink);
         return $templatesService->fetchTemplate("editor_image.tpl");
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }
Example #22
0
 /**
  * Set the workflow state of the article.
  * 	   'Y' = 'Published'
  *     'S' = 'Submitted'
  *     'N' = 'New'
  *
  * @param  string  $p_value
  * @return boolean
  */
 public function setWorkflowStatus($p_value)
 {
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleIndex.php';
     $translator = \Zend_Registry::get('container')->getService('translator');
     $em = \Zend_Registry::get('container')->getService('em');
     $p_value = strtoupper($p_value);
     if ($p_value != 'Y' && $p_value != 'S' && $p_value != 'N' && $p_value != 'M') {
         return false;
     }
     // If the article is being published
     if ($this->getWorkflowStatus() != 'Y' && $p_value == 'Y') {
         $this->setProperty('PublishDate', 'NOW()', true, true);
         // send out an article.published event
         self::dispatchEvent("article.published", $this);
         self::dispatchEvent("article.publish", $this, array('number' => $this->getArticleNumber(), 'language' => $this->getLanguageId()));
         // dispatch blog.published
         $blogConfig = \Zend_Registry::get('container')->getParameter('blog');
         if ($this->getType() == $blogConfig['article_type']) {
             self::dispatchEvent('blog.published', $this, array('number' => $this->getArticleNumber(), 'language' => $this->getLanguageId()));
         }
         $article_images = ArticleImage::GetImagesByArticleNumber($this->getArticleNumber());
         foreach ($article_images as $article_image) {
             $image = $article_image->getImage();
             $user_id = (int) $image->getUploadingUserId();
             //send out an image.published event
             self::dispatchEvent("image.published", $this, array("user" => $user_id));
         }
     }
     // Unlock the article if it changes status.
     if ($this->getWorkflowStatus() != $p_value) {
         $this->setIsLocked(false);
     }
     if ($p_value == 'Y' || $p_value == 'M') {
         $issueObj = new Issue($this->getPublicationId(), $this->getLanguageId(), $this->getIssueNumber());
         if (!$issueObj->exists()) {
             return false;
         }
         $p_value = $issueObj->isPublished() ? 'Y' : 'M';
     }
     $oldStatus = $this->getWorkflowStatus();
     if (!parent::setProperty('Published', $p_value)) {
         return false;
     }
     $language = $em->getRepository('Newscoop\\Entity\\Language')->findOneById($this->getLanguageId());
     $authors = $em->getRepository('Newscoop\\Entity\\ArticleAuthor')->getArticleAuthors($this->getArticleNumber(), $language->getCode())->getArrayResult();
     foreach ($authors as $author) {
         self::dispatchEvent("user.set_points", $this, array('authorId' => $author['fk_author_id']));
     }
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheService->clearNamespace('article');
     $logtext = $translator->trans('Article status changed from $1 to $2.', array('$1' => $this->getWorkflowDisplayString($oldStatus), '$2' => $this->getWorkflowDisplayString($p_value)), 'api');
     Log::ArticleMessage($this, $logtext, null, 35);
     return true;
 }
Example #23
0
}

$imageObj = new Image($f_image_id);

if (!is_null($f_image_description) && $g_user->hasPermission('ChangeImage')) {
	$attributes = array();
	$attributes['Description'] = $f_image_description;
	$attributes['Photographer'] = $f_image_photographer;
	$attributes['Place'] = $f_image_place;
	$attributes['Date'] = $f_image_date;
	$imageObj->update($attributes);
}

if ($g_user->hasPermission('AttachImageToArticle')) {
	if (is_numeric($f_image_template_id) && ($f_image_template_id > 0)) {
		$articleImageObj = new ArticleImage($f_article_number, $f_image_id);
		$updated = $articleImageObj->setTemplateId($f_image_template_id);
		if ($updated == false) {
			camp_html_add_msg(getGS("Image number '$1' already exists", $f_image_template_id));
			camp_html_goto_page($backLink);
		}
	}
}

camp_html_add_msg(getGS("Image '$1' updated.", $imageObj->getDescription()), "ok");

?>

<script type="text/javascript">
	window.location.href='<?php echo "/$ADMIN/articles/edit.php?f_language_id=$f_language_id&f_article_number=$f_article_number"; ?>'
</script>
Example #24
0
require_once $GLOBALS['g_campsiteDir'] . '/classes/User.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
$translator = \Zend_Registry::get('container')->getService('translator');
if (!SecurityToken::isValid()) {
    camp_html_display_error($translator->trans('Invalid security token!'));
    exit;
}
$f_language_id = Input::Get('f_language_id', 'int', 0);
$f_language_selected = Input::Get('f_language_selected', 'int', 0);
$f_article_number = Input::Get('f_article_number', 'int', 0);
$f_image_id = Input::Get('f_image_id', 'int', 0);
$f_image_template_id = Input::Get('f_image_template_id', 'int', 0);
// Check input
if (!Input::IsValid()) {
    camp_html_display_error($translator->trans('Invalid input: $1', array('$1' => Input::GetErrorString())), null, true);
    exit;
}
// This file can only be accessed if the user has the right to change articles
// or the user created this article and it hasnt been published yet.
if (!$g_user->hasPermission('AttachImageToArticle')) {
    camp_html_display_error($translator->trans("You do not have the right to attach images to articles.", array(), 'article_images'), null, true);
    exit;
}
$articleObj = new Article($f_language_selected, $f_article_number);
$imageObj = new Image($f_image_id);
$articleImage = new ArticleImage($f_article_number, $f_image_id, $f_image_template_id);
$articleImage->delete();
Zend_Registry::get('container')->getService('image.rendition')->unsetArticleImageRenditions($f_article_number, $f_image_id);
camp_html_add_msg($translator->trans('The image has been removed from the article.', array(), 'article_images'), "ok");
camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'edit.php'));
Example #25
0
        				// 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/campsite1_internal_link?$1" target="$2">', $text);
        				// Internal Links without targets
        				$text = preg_replace("/<!\*\*\s*Link\s*Internal\s*([\w=&]*)\s*>/i", '<a href="/campsite/campsite1_internal_link?$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);
        				if (isset($imageMatches[1][0])) {
        					foreach ($imageMatches[1] as $templateId) {
        						// Get the image URL
        						$articleImage = new ArticleImage($srcArticleData->getProperty('NrArticle'), null, $templateId);
        						$image = new Image($articleImage->getImageId());
        						$imageUrl = $image->getImageUrl();
        						$text = preg_replace("/<!\*\*\s*Image\s*".$templateId."\s*/i", '<img src="'.$imageUrl.'" id="'.$templateId.'" ', $text);
        					}
        				}
        			?>
        			<TR>
        			<TD ALIGN="RIGHT" VALIGN="TOP" style="padding-top: 8px; padding-right: 5px;">
        			</td>
        			<td align="right" valign="top" style="padding-top: 8px;">
        				<?php echo htmlspecialchars($dbColumn->getDisplayName()); ?>:
        			</td>
        			<TD align="left" valign="top">
        				<table cellpadding="0" cellspacing="0" width="100%">
        				<tr>
Example #26
0
<?php
camp_load_translation_strings("media_archive");
require_once($GLOBALS['g_campsiteDir'].'/classes/Input.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/Article.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/Image.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/ImageSearch.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/Log.php');

$f_image_id = Input::Get('f_image_id', 'int', 0);

if (!Input::IsValid()) {
	camp_html_goto_page("/$ADMIN/media-archive/index.php");
}
$imageObj = new Image($f_image_id);
$articles = ArticleImage::GetArticlesThatUseImage($f_image_id);

$crumbs = array();
$crumbs[] = array(getGS("Content"), "");
$crumbs[] = array(getGS("Media Archive"), "/$ADMIN/media-archive/index.php");
if ($g_user->hasPermission('ChangeImage')) {
	$crumbs[] = array(getGS('Change image information'), "");
}
else {
	$crumbs[] = array(getGS('View image'), "");
}
$breadcrumbs = camp_html_breadcrumbs($crumbs);

include_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/javascript_common.php");

echo $breadcrumbs;
Example #27
0
    /**
     * Delete article from database.  This will
     * only delete one specific translation of the article.
     *
     * @return boolean
     */
    public function delete()
    {
        // It is an optimization to put these here because in most cases
        // you dont need these files.
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleImage.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleTopic.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleIndex.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleAttachment.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleComment.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticlePublish.php');

        // Delete scheduled publishing
        ArticlePublish::OnArticleDelete($this->m_data['Number'], $this->m_data['IdLanguage']);

        // Delete Article Comments
        ArticleComment::OnArticleDelete($this->m_data['Number'], $this->m_data['IdLanguage']);

        // is this the last translation?
        if (count($this->getLanguages()) <= 1) {
            // Delete image pointers
            ArticleImage::OnArticleDelete($this->m_data['Number']);

            // Delete topics pointers
            ArticleTopic::OnArticleDelete($this->m_data['Number']);

            // Delete file pointers
            ArticleAttachment::OnArticleDelete($this->m_data['Number']);

            // Delete indexes
            ArticleIndex::OnArticleDelete($this->getPublicationId(), $this->getIssueNumber(),
                $this->getSectionNumber(), $this->getLanguageId(), $this->getArticleNumber());
        }

        // geo-map processing
        // is this the last translation?
        if (count($this->getLanguages()) <= 1) {
            // unlink the article-map pointers
            Geo_Map::OnArticleDelete($this->m_data['Number']);
        }
        else {
            // removing non-last translation of the map poi contents
            Geo_Map::OnLanguageDelete($this->m_data['Number'], $this->m_data['IdLanguage']);
        }

        // Delete row from article type table.
        $articleData = new ArticleData($this->m_data['Type'],
            $this->m_data['Number'],
            $this->m_data['IdLanguage']);
        $articleData->delete();

        $tmpObj = clone $this; // for log
        $tmpData = $this->m_data;
        $tmpData['languageName'] = $this->getLanguageName();
        // Delete row from Articles table.
        $deleted = parent::delete();

        if ($deleted) {
            if (function_exists("camp_load_translation_strings")) {
                camp_load_translation_strings("api");
            }
            Log::ArticleMessage($tmpObj, getGS('Article deleted.'), null, 32);
        }
        $this->m_cacheUpdate = true;
        return $deleted;
    } // fn delete
Example #28
0
$f_language_id = Input::Get('f_language_id', 'int', 0);
$f_language_selected = Input::Get('f_language_selected', 'int', 0);
$f_article_number = Input::Get('f_article_number', 'int', 0);
if (!Input::IsValid()) {
    camp_html_display_error($translator->trans('Invalid input: $1', array('$1' => Input::GetErrorString())), $_SERVER['REQUEST_URI'], true);
    exit;
}
if (!is_writable($Campsite['IMAGE_DIRECTORY'])) {
    camp_html_add_msg($translator->trans("Unable to add new image.", array(), 'media_archive'));
    camp_html_add_msg(camp_get_error_message(CAMP_ERROR_WRITE_DIR, $Campsite['IMAGE_DIRECTORY']));
}
$articleObj = new Article($f_language_selected, $f_article_number);
$publicationObj = new Publication($f_publication_id);
$issueObj = new Issue($f_publication_id, $f_language_id, $f_issue_number);
$sectionObj = new Section($f_publication_id, $f_issue_number, $f_language_id, $f_section_number);
$ImageTemplateId = ArticleImage::GetUnusedTemplateId($f_article_number);
$q_now = $g_ado_db->GetOne("SELECT LEFT(NOW(), 10)");
include_once $GLOBALS['g_campsiteDir'] . "/{$ADMIN_DIR}/javascript_common.php";
camp_html_display_msgs();
?>

<form method="POST" action="/<?php 
echo $ADMIN;
?>
/media-archive/do_upload.php" enctype="multipart/form-data">
<?php 
echo SecurityToken::FormParameter();
?>
<input type="hidden" name="f_article_edit" value="1">
<input type="hidden" name="f_publication_id" value="<?php 
echo $f_publication_id;
Example #29
0
    /**
     * Process the image statement given in Campsite internal formatting.
     * Returns a standard image URL.
     *
     * @param array $p_matches
     * @return string
     */
    public static function ProcessImageLink(array $p_matches) {
    	$context = CampTemplate::singleton()->context();
    	$oldImage = $context->image;
        $uri = $context->url;
        if ($uri->article->number == 0) {
            return '';
        }

        $imageNumber = $p_matches[1];
        $detailsString = $p_matches[2];
        $detailsArray = array();
        if (trim($detailsString) != '') {
        	$imageAttributes = 'align|alt|sub|width|height|ratio|\w+';
        	preg_match_all("/[\s]+($imageAttributes)=\"([^\"]+)\"/i", $detailsString, $detailsArray1);
        	$detailsArray1[1] = array_map('strtolower', $detailsArray1[1]);
        	if (count($detailsArray1[1]) > 0) {
        		$detailsArray1 = array_combine($detailsArray1[1], $detailsArray1[2]);
        	} else {
        		$detailsArray1 = array();
        	}
        	preg_match_all("/[\s]+($imageAttributes)=([^\"\s]+)/i", $detailsString, $detailsArray2);
        	$detailsArray2[1] = array_map('strtolower', $detailsArray2[1]);
        	if (count($detailsArray2[1]) > 0) {
        		$detailsArray2 = array_combine($detailsArray2[1], $detailsArray2[2]);
        	} else {
        		$detailsArray2 = array();
        	}
        	$detailsArray = array_merge($detailsArray1, $detailsArray2);
        }

        $articleImage = new ArticleImage($uri->article->number, null, $imageNumber);
        $imageObj = $articleImage->getImage();
        $image = new MetaImage($articleImage->getImageId());
        $context->image = $image;
        $imageSize = @getimagesize($imageObj->getImageStorageLocation());
        unset($imageObj);

        $imageOptions = '';
        $defaultOptions = array('ratio'=>'EditorImageRatio', 'width'=>'EditorImageResizeWidth',
        'height'=>'EditorImageResizeHeight');
        foreach (array('ratio', 'width', 'height') as $imageOption) {
        	$defaultOption = (int)SystemPref::Get($defaultOptions[$imageOption]);
        	if (isset($detailsArray[$imageOption]) && $detailsArray[$imageOption] > 0) {
        		$imageOptions .= " $imageOption " . (int)$detailsArray[$imageOption];
        	} elseif ($imageOption != 'ratio' && $defaultOption > 0) {
        		$imageOptions .= " $imageOption $defaultOption";
        	} elseif ($imageOption == 'ratio' && $defaultOption != 100) {
        		$imageOptions .= " $imageOption $defaultOption";
        	}
        }
        $imageOptions = trim($imageOptions);

        $imgZoomLink = '';
        if (SystemPref::Get("EditorImageZoom") == 'Y' && strlen($imageOptions) > 0) {
        	$uri->uri_parameter = "image";
            $imgZoomLink = '<a href="' . $uri->uri . '" class="photoViewer" ';
            if (isset($detailsArray['sub']) && !empty($detailsArray['sub'])) {
                $imgZoomLink .= 'title="' . $detailsArray['sub'] . '">';
            } else {
                $imgZoomLink .= 'title="">';
            }
        }

        $isCentered = false;
        $imgString = '</p><div class="cs_img"';
        if (isset($detailsArray['align']) && !empty($detailsArray['align'])) {
            if ($detailsArray['align'] == 'middle') {
                $imgString = '</p><div align="center"><div class="cs_img"';
                $isCentered = true;
            } else {
                $imgString .= ' style="float:' . $detailsArray['align'] . ';"';
            }
        }
        $imgString .= '>';
        $imgString .= (strlen($imgZoomLink) > 0) ? '<p>'.$imgZoomLink : '<p>';
        $uri->uri_parameter = "image $imageOptions";
        $imgString .= '<img src="' . $uri->uri . '"';
        if (isset($detailsArray['alt']) && !empty($detailsArray['alt'])) {
            $imgString .= ' alt="' . $detailsArray['alt'] . '"';
        }
        if (isset($detailsArray['sub']) && !empty($detailsArray['sub'])) {
            $imgString .= ' title="' . $detailsArray['sub'] . '"';
        }
        $imgString .= ' border="0"/>';
        $imgString .= (strlen($imgZoomLink) > 0) ? '</a></p>' : '</p>';
        if (isset($detailsArray['sub']) && !empty($detailsArray['sub'])) {
            $imgString .= '<p class="cs_img_caption">';
            $imgString .= $detailsArray['sub'] . '</p>';
        }
        if ($isCentered) {
            $imgString .= '</div></div><p>';
        } else {
            $imgString .= '</div><p>';
        }
        $context->image = $oldImage;

        return $imgString;
    }
Example #30
0
 /**
  * Publish group
  *
  * @param Newscoop\News\GroupRef $groupRef
  * @param Newscoop\News\Item $item
  * @return void
  */
 private function publishGroup(GroupRef $groupRef, Item $item)
 {
     $group = $item->getGroupSet()->getGroup($groupRef);
     $items = array();
     foreach ($group->getRefs() as $ref) {
         if ($ref instanceof ItemRef) {
             $groupItem = $this->findByItemRef($ref, $item->getFeed());
             if ($groupItem === null) {
                 continue;
             }
             $groupItem->setPublished(new \DateTime());
             switch ($groupItem->getItemMeta()->getItemClass()) {
                 case ItemMeta::CLASS_PICTURE:
                     $image = $this->publishPicture($groupItem);
                     \ArticleImage::AddImageToArticle($image->getImageId(), $items[0]->getArticleNumber());
                     break;
                 case ItemMeta::CLASS_TEXT:
                     $article = $this->publishText($groupItem);
                     $items[] = $article;
                     break;
             }
         } else {
             $this->publishGroup($ref, $item);
         }
     }
 }