1 of 3
1
Plugin: Eexcerpt - Strip HTML and limit words
Posted: 25 June 2007 07:17 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2124
Joined  03-26-2006

To make decent excerpts, I needed something that stripped out all tags first and then limited the remaining words, all in one fell swoop, so I combined those functions into one plugin. Rick Ellis originally wrote Word Limit, then Vik Rubenfeld modified that into Word Limit Plus. I took Vik’s modification and added some HTML stripping for your eexcerpting pleasure.

For some background on this plugin, you can review these threads:

Autogenerating an excerpt when a summary doesn’t exist
Definitive answer on Filter_HTML status, update or alternative, please?


USAGE:
Wrap anything you want to be processed between the tag pairs. Works exactly like word_limit_plus, but strips tags.

{exp:eexcerpt if_exceeds="600" stop_after="500"
the_link="<a href='{title_permalink=news/item}'>MORE...</a>"}

text you want processed

{
/exp:eexcerpt}

REFERENCE: 

if_exceeds - Text will be truncated if it is greater than this number of words. This parameter must be included.

stop_after - Text greater than the number of words contained in the if_exceeds parameter, will be truncated to the word length stored in the stop_after parameter. This parameter must be included. Must be less than the number of words in the if_exceeds parameter.

the_link - Optional. A link back to the original article.

The download is now over at its designated page at masugadesign.com: http://www.masugadesign.com/the-lab/scripts/eexcerpt/

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 25 June 2007 03:48 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  814
Joined  03-16-2002

Great. Thank you! You can see it in action in the left “News” column at branchenwissen.info.

Mdesign, do you see any chance to add an parameter/function to handle line breaks/paragraph so that they are more or less preserved? On a fast glance, it seems the preg_replace() uses a clever regex to filter out all tags, so one would perhaps replace br and opening p tags with some marker, filter all remaining tags and then replace the marker with br / tags? But I don’t want to mess with your code, I just would like to see an option to have the layout of the excerpt somewhat preserved but tags stripped to guarantee consistent HTML coding.

-Markus

Profile
 
 
Posted: 25 June 2007 08:09 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2124
Joined  03-26-2006
ms - 25 June 2007 03:48 PM

Great. Thank you! You can see it in action in the left “News” column at branchenwissen.info.

Mdesign, do you see any chance to add an parameter/function to handle line breaks/paragraph so that they are more or less preserved?

Ausgezeichnet! Gesundheit!

I didn’t want to open a big can of worms with this plugin by introducing parameters. I had a pretty specific need - which I find repeating iteself on numerous sites I work on - which is real basic excerpts with no tags in them. I really only intended this to be used with a sentence, or maybe a few sentences. Heck, all I did was take an existing plugin and throw some HTML stripping in there first. I think it would be pretty easy to keep line breaks intact, though.

Hmm, you might be on to something there though. First go through and replace with [p] (or something), then go through and wipe out tags, then replace [p] with
. Is that what you were thinking?

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 26 June 2007 07:01 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  814
Joined  03-16-2002

Yes, something like this - just that I would perhaps use some either low or high ascii character as the “marker”/replacement for ,
and
that most likely in the text processed will not be used (perhaps bell, 0x07, or something like that). Reason is this would count one character, whereas [p] would count three (so, [p] could perhaps truncated to [p or [ afterwards). Then use the preg_replace, truncating and so on as your plugin already does - and in a last step, replace the marker with
or

.

Of course, it would need a parameter because for most cases the current usage is great, just to truncate longer news the line/paragraph breaks would be nice to have.

-Markus

Profile
 
 
Posted: 16 July 2007 02:49 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2124
Joined  03-26-2006

Markus - I just came upon the need to preserve line breaks myself. I think I’ll look at updating this plugin to preserve those if possible - when I get a spare moment grin .

As you can see, we were having a discussion about that over on this thread.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 07 August 2007 07:09 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  514
Joined  10-08-2005

mdesign,

great mod to the plugin. i like to ask for a feature to be considered: the ability to choose between “character unit” vs. “word unit”. sometimes, i need to truncate the post by the number of characters, regardless of the number of words.

thanks for your consideration.

Profile
 
 
Posted: 25 August 2007 10:00 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  161
Joined  03-19-2007

Looks like a very nice upgrade! I’ll try it out. I second the request for choosing characters or words. Using characters gives you a little more control over the space the excerpt will fill. (Some posts use more big words than others.) Why not eliminate the need for char_limit too, eh?

Thanks for the work and thanks for sharing.

 Signature 

—Kevin

Profile
 
 
Posted: 06 September 2007 02:55 PM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  218
Joined  02-10-2006

Masuga - is it possible to set the link manually in:

{exp:eexcerpt if_exceeds="600" stop_after="500"
the_link="<a href='{title_permalink=news/item}'>MORE...</a>"}

I tried to change it to read:

{exp:eexcerpt if_exceeds="600" stop_after="500"
the_link="<a href='/{segment_1}/{segment_2}/{segment_3}/category/{url_title}'>MORE...</a>"}

When I did this, it totally ignored the URL.

bjs

Profile
 
 
Posted: 07 September 2007 07:39 AM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2124
Joined  03-26-2006

Hmm, I thought segment variables were parsed very early on, so I’m assuming that link should work. When you say “totally ignored”, what does that mean, exactly? It returned nothing?

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 07 September 2007 08:04 AM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  218
Joined  02-10-2006

Yes…basically the link wouldn’t even appear, but the text wold be truncated as expected

bjs

Profile
 
 
Posted: 19 November 2007 04:11 PM   [ Ignore ]   [ # 10 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  921
Joined  07-18-2006

Could this be used for the following situation?

I’m showing weblog entries - and if an entry is shorter than X I want the whole thing to show.  If it is longer than X, I want to show X words, and then have a “show entire post” link, but instead of that link taking someone to a new page, I want to use javascript and “getElementById” to show the entire post on that same page without a reload.

Any thoughts on how I could get this extension to do that?  Or should I use this as a jumping point for a new extension?

Thanks!

Profile
 
 
Posted: 22 December 2007 11:39 AM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2124
Joined  03-26-2006

Sorry everyone, somehow I wasn’t getting messages from this thread. When I get a little time, I’ll re-read the last few posts and see what I can do (right in the middle of a project at the moment…)

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 03 June 2008 09:59 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  12
Joined  08-06-2007

great plugin but i get an error
Notice: Undefined offset: 70 in /plugins/pi.eexcerpt.php on line 80
any ideas? help?

Profile
 
 
Posted: 20 June 2008 03:02 AM   [ Ignore ]   [ # 13 ]  
Lab Assistant
RankRank
Total Posts:  103
Joined  02-19-2007

Thanks for this plugin. I’m using it to automatically generate my <description> tag with some 30 words. Great work!

Profile
 
 
Posted: 20 June 2008 08:26 AM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2124
Joined  03-26-2006

@alterracoffee: I didn’t see your post. Are you still getting this error?

@goodbytes: Glad you’re finding it useful!

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 20 June 2008 09:46 AM   [ Ignore ]   [ # 15 ]  
Grad Student
Rank
Total Posts:  45
Joined  04-24-2008
alterracoffee - 03 June 2008 09:59 AM

great plugin but i get an error
Notice: Undefined offset: 70 in /plugins/pi.eexcerpt.php on line 80
any ideas? help?

I’m getting the same error.  Well, similar in that the offset number is different.

Notice: Undefined offset: 16 in /plugins/pi.eexcerpt.php on line 80

I think the problem is when there are extra spaces at the end of the line.  For example, I have my short description line to cut off after 16 words.  My content manager put in a 14 word phrase, but during the copy and paste, he ended up putting 2 or 3 extra spaces at the end of the line.  This caused the error.  Once I removed the spaces, it works fine.

Is there some extra code you can add that will truncate any extra white space at the end of the line?

{exp:eexcerpt if_exceeds="16" stop_after="16"}
Profile
 
 
Posted: 20 June 2008 10:12 AM   [ Ignore ]   [ # 16 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  301
Joined  04-12-2008
<?php
$var
= 'with spaces   ';

$trimmed = trim($var);

echo(
$trimmed);
?>

should give ‘with spaces’ (without quotes), try adding the trim function where the plugin has troubles.

 Signature 

Designchuchi | Twitter

URL Field Extension
Required Category Extension
DC FreeForm GeoIP Extension
DC Template Manager

Profile
 
 
Posted: 20 June 2008 04:32 PM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2124
Joined  03-26-2006

If peschehimself’s fix works, I can put that in the Plugin and update the “official” version.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 06 August 2008 12:01 PM   [ Ignore ]   [ # 18 ]  
Research Assistant
RankRankRank
Total Posts:  495
Joined  02-22-2006

Cool plugin… Sorry to resurrect old thread…

Would be cool to have control over the “...”. Why did you choose to not make that an

&hellip;

?

Other than that, this plugin has saved me some headache!!! Many thanks.

 Signature 

EE Plugins: Keywordz, x2html, SizePlus, randimgplus & randPro

Profile
 
 
   
1 of 3
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120561 Total Logged-in Users: 60
Total Topics: 126605 Total Anonymous Users: 29
Total Replies: 665583 Total Guests: 328
Total Posts: 792188    
Members ( View Memberlist )