AddImageToArticle() public static method

Link the given image with the given article. The template ID is the image's position in the template.
public static AddImageToArticle ( integer $p_imageId, integer $p_articleNumber, integer $p_templateId = null ) : void
$p_imageId integer
$p_articleNumber integer
$p_templateId integer Optional. If not specified, this will be the next highest number of the existing values.
return void
コード例 #1
0
ファイル: ImageController.php プロジェクト: nidzix/Newscoop
 public function setAttachAction()
 {
     $this->_helper->layout->disableLayout();
     try {
         $articleNumber = $this->_getParam('article_number');
         $imageId = $this->_getParam('image_id');
         //$image = $this->_helper->service('image')->find($imageId);
         //$articleImage = $this->_helper->service('image')->addArticleImage($articleNumber, $image);
         ArticleImage::AddImageToArticle($imageId, $articleNumber);
         $this->view->articleImages = $this->_helper->service('image')->findByArticle($this->_getParam('article_number'));
     } catch (\InvalidArgumentException $e) {
         $this->view->exception = $e->getMessage();
     }
 }
コード例 #2
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;
         }
     }
 }
コード例 #3
0
ファイル: do_link.php プロジェクト: nistormihai/Newscoop
$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>
コード例 #4
0
ファイル: ItemService.php プロジェクト: nidzix/Newscoop
 /**
  * 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);
         }
     }
 }
コード例 #5
0
ファイル: do_add.php プロジェクト: nistormihai/Newscoop
if (!empty($f_image_url)) {
	if (camp_is_valid_url($f_image_url)) {
		$image = Image::OnAddRemoteImage($f_image_url, $attributes, $g_user->getUserId());
	} else {
		camp_html_add_msg(getGS("The URL you entered is invalid: '$1'", htmlspecialchars($f_image_url)));
		camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'images/popup.php'));
	}
} elseif (!empty($_FILES['f_image_file']) && !empty($_FILES['f_image_file']['name'])) {
	$image = Image::OnImageUpload($_FILES['f_image_file'], $attributes, $g_user->getUserId());
} else {
	camp_html_add_msg(getGS("You must select an image file to upload."));
	camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'images/popup.php'));
}

// Check if image was added successfully
if (PEAR::isError($image)) {
	camp_html_add_msg($image->getMessage());
	camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'images/popup.php'));
}

ArticleImage::AddImageToArticle($image->getImageId(), $articleObj->getArticleNumber(), $f_image_template_id);

?>
<script type="text/javascript">
try {
    parent.$.fancybox.reload = true;
    parent.$.fancybox.message = "<?php putGS("Image '$1' added.", addslashes($image->getDescription())); ?>";
    parent.$.fancybox.close();
} catch (e) {}
</script>
コード例 #6
0
ファイル: do_upload.php プロジェクト: nidzix/Newscoop
        $images[] = $result;
    }
}
if (!empty($images)) {
    camp_html_add_msg(getGS('"$1" files uploaded.', count($images)), "ok");
    if ($f_article_edit) {
        require_once $GLOBALS['g_campsiteDir'] . '/classes/Article.php';
        require_once $GLOBALS['g_campsiteDir'] . '/classes/Image.php';
        require_once $GLOBALS['g_campsiteDir'] . '/classes/Issue.php';
        require_once $GLOBALS['g_campsiteDir'] . '/classes/Section.php';
        require_once $GLOBALS['g_campsiteDir'] . '/classes/Language.php';
        require_once $GLOBALS['g_campsiteDir'] . '/classes/Publication.php';
        //$imageIdList = array();
        foreach ($images as $image) {
            $ImageTemplateId = ArticleImage::GetUnusedTemplateId($f_article_number);
            ArticleImage::AddImageToArticle($image->getImageId(), $f_article_number, $ImageTemplateId);
            //$imageIdList[] = $image->getImageId();
        }
        //$imageIdList = implode(',',$imageIdList);
        //camp_html_goto_page('/'.$ADMIN.'/image/edit-image-data/images/'.$imageIdList);
        camp_html_goto_page('/' . $ADMIN . '/image/edit-image-data/article_number/' . $f_article_number . '/language_id/' . $f_language_id);
    } else {
        camp_html_goto_page("/{$ADMIN}/media-archive/multiedit.php");
    }
} else {
    if ($f_article_edit) {
        camp_html_goto_page('/' . $ADMIN . '/image/article-attach/article_number/' . $f_article_number . '/language_id/' . $f_language_id);
    } else {
        camp_html_add_msg($f_path . DIR_SEP . basename($newFilePath));
        camp_html_goto_page($backLink);
    }
コード例 #7
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;
         }
     }
 }