Forums / Developer / getting "used images" in article

getting "used images" in article

Author Message

Georg Franz

Saturday 31 January 2004 9:43:23 am

Hi,

in ez 2.x it was possible to get the info which assigned images were used inside an article.

Example:
You assign 3 images to an article. Two of them should be shown inside the article-text and the third one should be displayed beside the article-text, e.g. in an extra column.

In ez3 this isn't possible in an easy way, because ez3 don't provide the info which "related objects" are used inside a xml-field.

But I found a (rather pervert) way to do this again. Maybe there is an easier / better solution?

I created an overide template for embedded images, "embed.tpl".

This template contains the lines

...
{let image_content=$object.data_map.image.content
     image=$object.data_map.image.content[$image_class]}
{section show=$image_content.is_valid}
{* marker which is used to get the object id of the image *}
<!-- image_id: {$object.id} -->
...
{/section}
...
{/let}

Then I created an template operator, which searches after the string

<!-- image_id: ... -->

and returns all found image object id's in an array.

snipplet of operator:

(...)
$gwf_find_image_name = "gwf_find_image"

(...)
$this->GwfFindImageName = $gwf_find_image_name;

(...)
$this->GwfFindImageName => array ( 'xml_text'  => array( "type" => "string",
                                   "required" => true,
                                   "default" => "") )
(...)

function modify( 
...
switch ( $operatorName )
{
 case $this->GwfFindImageName :
 {
   $input = $namedParameters['xml_text'];
   $return_array = array();
   $match = array();
   if (preg_match_all ("#<!-- image_id: (\d+) -->#",$input,$match))
   {
      $operatorValue = $match[1];
   }
 }
 break;
 (...)
}

Last step:

In the article-template I do something like this:

...
{let 
	used_images=array()
	related_array=$content_version.related_contentobject_array	
	related_class_id=array()
	show_images=true()
}
    {* send the generated html of the article-body to the template operator *}
	{set used_images=gwf_find_image($content_version.data_map.body.content.output.output_text)}

	{section show=$related_array}
		{section loop=$related_array}
			{* check, if there images attached *}
			{set related_class_id=$related_class_id|append($:item.contentclass_id)}
		{/section}
	{/section}
	{section show=$related_array}
		{* image class id = 5 *}
		{section show=and($related_class_id|contains(5),$show_images)}
			{section loop=$related_array}
				{section show=eq($:item.contentclass_id,5)}
					{section show=count($used_images)|gt(0)}
						{* show only images, which are not in the array $used_images *}
						{section show=eq($used_images|contains($:item.id),false())}
							{attribute_view_gui attribute=$:item.data_map.image}
						{/section}
						{* if there are no images inside the article body, show all related images *}
						{section-else}
							{attribute_view_gui attribute=$:item.data_map.image}
					{/section}
				{/section}
			{/section}
		{/section}
	{/section}
{/let}

Kind regars,
Emil.

Best wishes,
Georg.

--
http://www.schicksal.com Horoskop website which uses eZ Publish since 2004