GetImagesByArticleNumber() public static method

Get all the images that belong to this article.
public static GetImagesByArticleNumber ( integer $p_articleNumber, boolean $p_countOnly = false ) : mixed
$p_articleNumber integer The specific article you want the images from.
$p_countOnly boolean Only return the number of images in the article.
return mixed Return either an array or an int.
コード例 #1
0
ファイル: MetaArticle.php プロジェクト: nistormihai/Newscoop
 protected function getImage() {
     $context = CampTemplate::singleton()->context();
     if ($context->image->defined) {
         return $context->image;
     }
     $images = ArticleImage::GetImagesByArticleNumber($this->m_dbObject->getArticleNumber());
     if (count($images) == 0) {
         return new MetaImage();
     }
     return new MetaImage($images[0]->getImageId());
 }
コード例 #2
0
 /**
  * Get all the files and directories of a relative path.
  *
  * @param string $path relative path to be base path.
  *
  * @return array of file and path information.
  * <code>
  *   array(0 => array('relative'=>'fullpath',...),
  *		   1 => array('filename'=>fileinfo array(),...)
  * </code>
  * fileinfo array:
  * <code>
  *   array('url'=>'full url',
  *         'relative'=>'relative to base',
  *         'fullpath'=>'full file path',
  *         'image'=>imageInfo array() false if not image,
  *         'stat' => filestat)
  * </code>
  */
 function getFiles($path, $articleId)
 {
     $files = array();
     $dirs = array();
     if ($this->isValidBase() == false) {
         return array($files, $dirs);
     }
     $path = Files::fixPath($path);
     $base = Files::fixPath($this->getBaseDir());
     $fullpath = Files::makePath($base, $path);
     $articleImages = ArticleImage::GetImagesByArticleNumber($articleId);
     foreach ($articleImages as $articleImage) {
         $image = $articleImage->getImage();
         $img = $this->getImageInfo($image->getImageStorageLocation());
         if (is_array($img) || !$this->config['validate_images']) {
             $file['template_id'] = $articleImage->getTemplateId();
             $file['url'] = $image->getImageUrl();
             $file['image'] = $img;
             $file['image_object'] = $image;
             $file['alt'] = htmlspecialchars($image->getDescription(), ENT_QUOTES);
             $files[$articleImage->getTemplateId()] = $file;
         }
     }
     ksort($dirs);
     ksort($files);
     return array($dirs, $files);
 }
コード例 #3
0
ファイル: Article.php プロジェクト: alvsgithub/Newscoop
 /**
  * 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;
 }
コード例 #4
0
 /**
  * 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;
         }
     }
 }
コード例 #5
0
ファイル: ArticleList.php プロジェクト: sourcefabric/newscoop
 /**
  * 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);
 }
コード例 #6
0
ファイル: edit.php プロジェクト: nidzix/Newscoop
// detect if blogger can edit
$userIsBlogger = false;
$blogService = \Zend_Registry::get('container')->getService('blog');
if ($blogService->isBlogger($g_user)) {
    $userIsBlogger = true;
    $userSection = $blogService->getSection($g_user);
    if (empty($userSection) || $userSection->getSectionId() != $articleObj->getSection()->getSectionId()) {
        camp_html_display_error(getGS("You're not allowed to edit article."));
        exit;
    }
}
$articleData = $articleObj->getArticleData();
// Get article type fields.
$dbColumns = $articleData->getUserDefinedColumns(FALSE, TRUE);
$articleType = new ArticleType($articleObj->getType());
$articleImages = ArticleImage::GetImagesByArticleNumber($f_article_number);
$lockUserObj = new User($articleObj->getLockedByUser());
$articleCreator = new User($articleObj->getCreatorId());
$articleEvents = ArticlePublish::GetArticleEvents($f_article_number, $f_language_selected, TRUE);
$articleTopics = ArticleTopic::GetArticleTopics($f_article_number);
$articleFiles = ArticleAttachment::GetAttachmentsByArticleNumber($f_article_number, $f_language_selected);
$articleLanguages = $articleObj->getLanguages();
// Create displayable "last modified" time.
$lastModified = strtotime($articleObj->getLastModified());
$today = getdate();
$savedOn = getdate($lastModified);
$savedToday = true;
if ($today['year'] != $savedOn['year'] || $today['mon'] != $savedOn['mon'] || $today['mday'] != $savedOn['mday']) {
    $savedToday = FALSE;
}
$sectionObj = null;
コード例 #7
0
 public function testPublishPackageMainWithSidebars()
 {
     $this->saveNewsItem(self::TEXT_XML);
     $picture = $this->saveNewsItem(self::PICTURE_XML);
     $xml = simplexml_load_file(APPLICATION_PATH . '/../tests/fixtures/' . self::PACKAGE_MAIN_SIDEBARS_XML);
     $item = PackageItem::createFromXml($xml->itemSet->packageItem);
     $feed = new TestFeed();
     $item->setFeed($feed);
     $picture->setFeed($feed);
     $this->service->publish($item);
     $this->assertTrue($item->isPublished());
     $articles = \Article::GetArticles();
     $this->assertEquals(1, count($articles));
     $main = array_pop($articles);
     $this->assertEquals('S&P piles pressure on Franco-German EU budget plan', $main->getTitle());
     $images = \ArticleImage::GetImagesByArticleNumber($main->getArticleNumber());
     $this->assertEquals(1, count($images));
 }
コード例 #8
0
ファイル: Article.php プロジェクト: nidzix/Newscoop
 /**
  * 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';
     $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);
         // 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;
     }
     CampCache::singleton()->clear('user');
     if (function_exists("camp_load_translation_strings")) {
         camp_load_translation_strings("api");
     }
     $logtext = getGS('Article status changed from $1 to $2.', $this->getWorkflowDisplayString($oldStatus), $this->getWorkflowDisplayString($p_value));
     Log::ArticleMessage($this, $logtext, null, 35);
     return true;
 }
コード例 #9
0
ファイル: ArticleList.php プロジェクト: nistormihai/Newscoop
	/**
	 * Process item
	 * @param Article $article
	 * @return array
	 */
	public function processItem(Article $article)
	{
		global $g_user, $Campsite;

		$articleLinkParams = '?f_publication_id=' . $article->getPublicationId()
		. '&amp;f_issue_number=' . $article->getIssueNumber() . '&amp;f_section_number=' . $article->getSectionNumber()
		. '&amp;f_article_number=' . $article->getArticleNumber() . '&amp;f_language_id=' . $article->getLanguageId()
		. '&amp;f_language_selected=' . $article->getLanguageId();
		$articleLink = $Campsite['WEBSITE_URL'].'/admin/articles/edit.php' . $articleLinkParams;
		$previewLink = $Campsite['WEBSITE_URL'].'/admin/articles/preview.php' . $articleLinkParams;

		$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 = getGS('The article has been locked by $1 ($2) $3 hour(s) and $4 minute(s) ago.',
				htmlspecialchars($lockUser->getRealName()),
				htmlspecialchars($lockUser->getUserName()),
				$timeDiff['hours'], $timeDiff['minutes']);
			} else {
				$lockInfo = getGS('The article has been locked by $1 ($2) $3 minute(s) ago.',
				htmlspecialchars($lockUser->getRealName()),
				htmlspecialchars($lockUser->getUserName()),
				$timeDiff['minutes']);
			}
			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() ? getGS('Yes') : getGS('No');
		$onSectionPage = $article->onSectionPage() ? getGS('Yes') : getGS('No');

		$imagesNo = (int) ArticleImage::GetImagesByArticleNumber($article->getArticleNumber(), true);
		$topicsNo = (int) ArticleTopic::GetArticleTopics($article->getArticleNumber(), true);
		$commentsNo = '';
		if ($article->commentsEnabled()) {
			$commentsNo = (int) ArticleComment::GetArticleComments($article->getArticleNumber(), $article->getLanguageId(), null, true);
		} 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,
		getGS('Edit'), $article->getName() . " ({$article->getLanguageName()})",
		$article->getName() . (empty($_REQUEST['language']) ? " ({$language->getCode()})" : '')),
		$tmpArticleType->getDisplayName(),
		$tmpUser->getRealName(),
		$tmpAuthor->getName(),
		$article->getWorkflowStatus(),
		$onFrontPage,
		$onSectionPage,
		$imagesNo,
		$topicsNo,
		$commentsNo,
		(int) $article->getReads(),
		Geo_Map::GetArticleMapId($article) != NULL ? getGS('Yes') : getGS('No'),
		(int) sizeof(Geo_Map::GetLocationsByArticle($article)),
		$article->getCreationDate(),
		$article->getPublishDate(),
		$article->getLastModified(),
		);
	}
コード例 #10
0
ファイル: PublisherService.php プロジェクト: nidzix/Newscoop
 /**
  * Set article images
  *
  * @param Article $article
  * @param array $images
  * @return void
  */
 private function setArticleImages(\Article $article, $images)
 {
     if (empty($images)) {
         return;
     }
     $oldImages = \ArticleImage::GetImagesByArticleNumber($article->getArticleNumber());
     foreach ($oldImages as $image) {
         $image->delete();
     }
     foreach ($images as $basename => $caption) {
         $file = $this->config['image_path'] . "/{$basename}";
         $realpath = realpath($file);
         if (!$realpath) {
             continue;
         }
         $imagesize = getimagesize($realpath);
         $info = array('name' => $basename, 'type' => $imagesize['mime'], 'tmp_name' => $realpath, 'size' => filesize($realpath), 'error' => 0);
         $attributes = array('Photographer' => 'sda', 'Description' => $caption, 'Source' => 'newsfeed');
         try {
             $image = \Image::OnImageUpload($info, $attributes, null, null, true);
             \ArticleImage::AddImageToArticle($image->getImageId(), $article->getArticleNumber(), null);
         } catch (\Exception $e) {
             var_dump($e);
             exit;
         }
     }
 }
コード例 #11
0
 /**
  * Test article images
  */
 private function checkImages($count, \Article $article)
 {
     $images = \ArticleImage::GetImagesByArticleNumber($article->getArticleNumber());
     $this->assertEquals($count, count($images));
 }