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

eZ debug

Timing: Jan 18 2025 20:55:47
Script start
Timing: Jan 18 2025 20:55:47
Module start 'content'
Timing: Jan 18 2025 20:55:47
Module end 'content'
Timing: Jan 18 2025 20:55:47
Script end

Main resources:

Total runtime0.2273 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0118 588.8281180.8359
Module start 'content' 0.01180.0074 769.664194.0078
Module end 'content' 0.01930.2077 863.6719529.3281
Script end 0.2270  1,393.0000 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00341.5076200.0002
Check MTime0.00140.6216200.0001
Mysql Total
Database connection0.00462.038810.0046
Mysqli_queries0.171075.23261410.0012
Looping result0.00120.51391390.0000
Template Total0.207391.210.2073
Template load0.00090.384010.0009
Template processing0.206590.839210.2065
Override
Cache load0.00060.275510.0006
Sytem overhead
Fetch class attribute can translate value0.00080.361210.0008
XML
Image XML parsing0.00030.122710.0003
General
dbfile0.01134.9637200.0006
String conversion0.00000.003030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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