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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 06:17:07
Script start
Timing: Jan 31 2025 06:17:07
Module start 'layout'
Timing: Jan 31 2025 06:17:07
Module start 'content'
Timing: Jan 31 2025 06:17:07
Module end 'content'
Timing: Jan 31 2025 06:17:07
Script end

Main resources:

Total runtime0.0138 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0051 588.1328151.2109
Module start 'layout' 0.00510.0024 739.343836.6484
Module start 'content' 0.00750.0048 775.992290.2813
Module end 'content' 0.01230.0015 866.273433.9922
Script end 0.0137  900.2656 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002316.8194140.0002
Check MTime0.00107.2335140.0001
Mysql Total
Database connection0.00085.726610.0008
Mysqli_queries0.002316.594230.0008
Looping result0.00000.102210.0000
Template Total0.00107.610.0010
Template load0.00085.906710.0008
Template processing0.00021.621310.0002
Override
Cache load0.00053.843710.0005
General
dbfile0.00021.765180.0000
String conversion0.00000.050240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs