Extracting text from / summarizing ezxmltext

Author Message

Stuart Herring

Sunday 09 January 2005 1:25:01 am

Hi,
I want to be able to provide the first few words of an ezxmltext field in a template, but I can't seem to find a safe way of doing so.

The closest I can come is using shorten(), but that's not safe, as it doesn't understand xhtml, and can leave tags un closed.

I think the best way to achieve what I want, would be to extract all the raw text from the field, and then apply shorten on that, but that leads me to my problem.

Is there any way of extracting the raw text from an ezxmltext field?

Jordan Hirsch

Wednesday 06 December 2006 11:37:51 am

Stuart, I don't suppose you ever found a way, did you? I'm looking for the same thing.

Me: http://jordan.teamhirsch.com
My blog: http://wiredformusic.blogspot.com
My other company: http://thinkimprov.com
eZ Certification: http://auth.ez.no/certification/verify/402488
eZ Award: http://ez.no/company/news/ez_awards_2007_prize_winners

Kristian Hole

Wednesday 06 December 2006 12:06:15 pm

Hi all,

To show only parts of xml, you have to strip the tags. (Otherwise you might end up cutting of inside a tag, or not have closed tags)

So, where you would normally use

{attribute_view_gui attribute=$node.data_map.attribute}

You need to use something like:

{$node.data_map.attribute.content.output.output_text|strip_tags|shorten(25)|wash}

To enable the striptags operator, you need to add the following in settings/override/template.ini.append.php

[PHP]
PHPOperatorList[strip_tags]=strip_tags

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

kracker (the)

Saturday 09 December 2006 10:20:39 am

I've done this once before ...

{strip_tags( $node.data_map.body.value.output.output_text ) | wash | shorten(135, '...', right)}

//kracker

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Xavier Dutoit

Sunday 10 December 2006 12:02:24 pm

Hi,

I wrote an extension that does a shorten on a xmltext. It's able to deal with tags. It's able to replace the <p> by <br>. it's able to keep some tags (eg <a> and <b> and stip the others). Best of all, it secures ez publish, even if you allow literal class="html".

Right now, I'm not sure about what API/template this extension should offer.

May be the best place to discuss that is the ezpedia.

Let me clarify what I have done, upload it to the pubsvn and launch a talk about it.

Take care.

X+

http://www.sydesy.com

kracker (the)

Monday 26 February 2007 11:19:53 pm

Hey Xavier,

I noticed this thread in passing today and wondered if you had any update on this subject?

Cheers,
//kracker

<i>Home Movies - The Ballad Of King Arthur & Robin Hood (Medley)</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Patrick Renaud

Thursday 01 March 2007 6:49:39 am

Thanks for this thread, I add this problem.
Added summarizing comment to the doc : http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_operators/strings/shorten

Ca, c'est fait !

Xavier Dutoit

Thursday 01 March 2007 12:15:31 pm

Hmm,

Update ? Yes, I went to myanmar (wonderful), got a few things running and might have found a band again.

Ooops sorry, you meant about the extension ?

I'll start a project about it and start discussion. It works fine on production for some sites, but not 100% sure of the templates I offer.

I'll keep you posted, probably this week-end. Don't hesitate to push me if I don't.

X+

http://www.sydesy.com

Kristian Hole

Thursday 01 March 2007 1:19:53 pm

I just got an idea here: You could do this with a special template operator "xmlshorten", which disregards tags when counting characters, and then automatically closes all open tags when desired length have been reached. Should not be too hard to implement...

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Kristian Hole

Thursday 01 March 2007 1:23:00 pm

Yes that was a very obvious solution.. Somebody just needs to implement it. Any takers?

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Xavier Dutoit

Saturday 10 March 2007 2:48:09 am

Well, since you mention offering a beer to the one doing it ;)

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

Xavier Dutoit

Saturday 10 March 2007 2:51:17 am

I do only part of your suggestion (closing properly the tags). As for the counting without including the tags, my svn is wide open to your patches ;)

X+

P.S. Claudia has some nice suggestions: http://projects.ez.no/xmlwash/forum/general/suggestions_for_shorten#msg295

http://www.sydesy.com

Nathan Kelly

Thursday 22 March 2007 9:40:41 pm

Hi all,

Xavier, your extension sounds like it will provide a good solution to this problem. Is it available to download anywhere yet, I looked at the project page but couldn't find a download?

I have just come up with a really stupid way to shorten the full message body of a blog post while retaining the format, say I have 2 paragraphs in the shortened text and I use striptags(), I lose the format of the paragraph tags, i.e. the 2 paragraphs become one.

I tried using the nl2br operator but found that it inserted 4 <br /> tags so I came up with a really convoluted solution that I really don't want to use if I don't have too:

{def $text=$blog.data_map.message.content.output.output_text|striptags|shorten(500, ' ...', right)}

<p>{$text|simplify('\n')|nl2br|nl2br} <a href={$blog.url_alias|ezurl}>More</a></p>

Nasty stuff, not what I would call an ideal solution, but it will do until I get my hands on xmlwash. ;)

Cheers.

Pardon me while I burst into flames...

Kristian Hole

Friday 23 March 2007 12:19:50 pm

@Nathan:

Here it is:
http://ez.no/community/contribs/template_plugins/xml_wash

:-)

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

kracker (the)

Friday 23 March 2007 9:32:20 pm

@Nathan:

The problem is that there is not a packaged binary (tar.gz,bzip2,zip) at,
http://projects.ez.no/xmlwash/downloads
http://ez.no/community/contribs/template_plugins/xml_wash

And while there are links all pointing to the project,
http://projects.ez.no/xmlwash

At this point the source code is not available from the individual project repository,
http://projects.ez.no:81/svn/projects/xmlwash/

I did however today find a copy of the source code at PubSVN,
http://pubsvn.ez.no/community/trunk/extension/xmlwash/

For clarity sake a number of locations above could make a clear direction to the source code for users who are not familiar with the popular location for community source code. <i>@X.. This is why the user feedback was mute. It was a release clarity mixup...</i>

<i>hth,
//kracker

KMK - Where's the **** At?</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Xavier Dutoit

Sunday 25 March 2007 1:04:55 am

Hi,

Since when not having access to the source code did stop someone to make comment about it ? ;)

That's on the projects svn, I will obsolete the one in pubsvn very soon.

What would be the best way to do that ? svn delete everything and add a README giving the new address ?

X+

http://www.sydesy.com

Nathan Kelly

Sunday 25 March 2007 8:19:30 pm

Got it, I looked at contribs the other day but must have overlooked it somehow. But I've got it now, thanks.

Cheers.

Pardon me while I burst into flames...

Xavier Dutoit

Monday 26 March 2007 12:41:05 am

Hi Nathan,

Don't worry, it wasn't on the project site and I didn't mention much of pubsvn ;)

For everyone, could you start discussing this extension in this forum ?

http://projects.ez.no/xmlwash/forum/general

X+

http://www.sydesy.com

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