Forums / Developer / $item...|shorten(100) is not working

$item...|shorten(100) is not working

Author Message

kavi kavi

Tuesday 23 January 2007 6:32:11 am

Hi everybody !
What's wrong with my code ?!
$item.object.data_map.intro.content.output.output_text is working without |shorten(100).
Is shorten is incompatible with $item ?!

{let nodes=fetch( 'content', 'list', hash( 'parent_node_id', 100,
'limit', 3,
'sort_by', array( 'published', false() )
))}

{foreach $nodes as $item}
<li class="article_atg">
<h1><a href="{$item.url}" title="titre">{$item.name}</a></h1>
<a href="{$item.url}" title="titre"><img src=""></img></a>
<p>
{def $mon_intro=$item.object.data_map.intro.content.output.output_text|shorten(100)}
<a href={$item.url} title="Lien vers : {$item.name}">{$mon_intro}</a>
</p>
</li>
{/foreach}
{/let}

kavi

Betsy Gamrat

Tuesday 23 January 2007 4:24:23 pm

kavi,

I would try


{def $mon_intro=$item.object.data_map.intro.content.output|shorten(100)}

and

{def $mon_intro=$item.object.data_map.intro.content|shorten(100)}

Xavier Dutoit

Tuesday 23 January 2007 11:56:19 pm

Hi,

You will have problem if your attribute is a xml block (or if it contains any html code), as it can cut it between the open and close tag.

I wrote an extension to take care of that problem, not 100% sure about the api, but will put it soon in the svn if you're interested.

X+

http://www.sydesy.com

kavi kavi

Wednesday 24 January 2007 1:20:33 am

Hi xavier!

I'm interested on your code. I'll see it...

I've find a solution but not the best i think...

Here is my code :
{let nodes=fetch( 'content', 'list', hash( 'parent_node_id', 100,
'limit', 3,
'sort_by', array( 'published', false() )))}
{foreach $nodes as $item}
<li class="article">
<h1><a href="{$item.url}" title="Lien vers : {$item.name}">{$item.name}</a></h1>
<p>
{def $mon_intro=$item.object.data_map.intro.content.output.output_text
$tab=$mon_intro|explode(' ')
$nb=$tab|count()
$tab1=$tab|extract(0,20 )}
<a href={$item.url} title="Lien vers : {$item.name}">{$tab1|implode(' ')}...</a>
</p>
</li>
{/foreach}

Thanks
kavi

Xavier Dutoit

Wednesday 24 January 2007 2:36:29 am

Hi,

Funny solution, wouldn't have tought about it. Bravo !

My extension let you keep some tags (eg, a b i) and truncate it.

Moreover, it secures ez publish, by cleaning properly all the XSS that you might got in if you have literal class=html activated (in my case, mandatory if I want to be able to have a ok looking RSS import).

X+

http://www.sydesy.com

kavi kavi

Thursday 25 January 2007 7:12:12 am

Salut xavier !

merci pour tes compliments qui me touchent beaucoup. cela fait 4 mois que j'ai découvert eZPublish et PHP...
Tu veux dire que ma solution est plus crédible que la tienne...?! ou c'est le contraire ? Je n'ai pas tout pigé...

kavi

Xavier Dutoit

Thursday 25 January 2007 8:02:21 am

Salut,

My solution is an extension that contains php code that does the work. It's more advanced than your solution (and likely to be faster too). I provides the ability to keep some tags (eg keep the bold and italic and links) and get rid of the others.

It also allows to protect your site against attack if you let your users to publish html code in your content (ie if you have the literal tag with "html" class).

X+

http://www.sydesy.com

Xavier Dutoit

Saturday 10 March 2007 2:52:43 am

This extension allows to shorten the xml result, even while keeping all (or a selection of) xml tags.

http://projects.ez.no/xmlwash

as an added bonus, it offers a bigger security, no matter your ez config, even while using the html class for the literal tag.

X+

http://www.sydesy.com

eZ debug

Timing: Jan 31 2025 01:33:09
Script start
Timing: Jan 31 2025 01:33:09
Module start 'content'
Timing: Jan 31 2025 01:33:09
Module end 'content'
Timing: Jan 31 2025 01:33:09
Script end

Main resources:

Total runtime0.2041 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0075 587.9297370.2969
Module start 'content' 0.00750.0138 958.22661,009.6563
Module end 'content' 0.02130.1827 1,967.88283,899.9609
Script end 0.2040  5,867.8438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00492.4180200.0002
Check MTime0.00150.7416200.0001
Mysql Total
Database connection0.00060.310210.0006
Mysqli_queries0.107452.64871410.0008
Looping result0.00140.70701390.0000
Template Total0.182289.310.1822
Template load0.00100.488210.0010
Template processing0.181288.796210.1812
Override
Cache load0.00070.325910.0007
Sytem overhead
Fetch class attribute can translate value0.00211.005110.0021
XML
Image XML parsing0.00030.127910.0003
General
dbfile0.00361.7597200.0002
String conversion0.00000.002930.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