Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: [archived] sab_substr
The ‘& #160’ problem can probably be solved by disabling the ‘nowidow’ option in the TXP preferences.
Offline
Re: [archived] sab_substr
Hope I’m not treading on your toes here Ruud, but I needed a chop-tag-text plugin so I could output parts of the description field from zem_event, among others. None of the excerpt type plugins worked on non-txp tables :-(
Being a container tag, this was the closest I found that could do the job so I took it and made a slightly updated version, I hope fully backwards compatible with your rewrite.
Adds a few features like striptags, the ability to skip characters if you like, output chars from just the start or end of the string, and also the ability to split the output into two bits, each styled and classed separately (if required) to perhaps apply dropcap-type functionality. *shrug* I needed it and can’t rely on CSS2’s :first-letter
in IE6.
The only thing I couldn’t figure was why the regex wouldn’t work on large fields like the output of the <txp:body />
tag; just refused to limit the output. Weird. But since you run everything through utf8_decode() first, I figured it was probably safe to just use substr. I’m not great with this encoding entities lark, so let me know if I’ve screwed up.
EDIT: a small problem is that potentially the “excerpt” (for want of a better word) might cut-off in the middle of an entity and leave a strange half-entity on the page, which may cause problems. Probably a way round it one day…
EDIT2: My version of the plugin removed. Ruud’s version is official, mine isn’t, so I’ll keep it to myself.
Last edited by Bloke (2008-01-05 23:22:30)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: [archived] sab_substr
Arg! I’ve been toying with this all day and – alas – this wonderful little plug-in doesn’t seem to work. At least it doesn’t seem to work on <txp:body />
or <txp:excerpt />
. I can only get it to work with <txp:title />
. Is this so or am I just doing something wrong?
My code:
<h1><txp:permlink><txp:sab_substr limit="25" trail=""><txp:title /></txp:sab_substr></txp:permlink></h1>
<txp:sab_substr limit="230" trail="..."><txp:excerpt /></txp:sab_substr>
Offline
Re: [archived] sab_substr
How does it not work?
Offline
Re: [archived] sab_substr
It’s not limiting the <txp:excerpt />
output. I’m getting the complete <txp:excerpt />
without any limits. (which I just realized is a redundant sentence)
Last edited by bullseyeinteractive (2008-03-11 20:43:59)
Offline
Re: [archived] sab_substr
bullseyeinteractive wrote:
It’s not limiting the
<txp:excerpt />
output.
fwiw (for ruud), I think it’s something to do with the regular expression. For some reason it fails the match against anything other than a simple short tag like txp:title. I couldn’t fathom it, because it looks like it should work. Mind you, I’m pretty rubbish with regex, so I cheated and used substr() instead when I hacked it.
Last edited by Bloke (2008-03-11 20:50:13)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: [archived] sab_substr
Any idea why I’m not getting apostrophes, but instead getting: no '. I’ve dropped in $thing = strip_tags($thing);
but I don’t think that’s the issue here. I’ve also disabled ‘nowidow’ option in the TXP preferences. No luck. I don’t know enough PHP to get my head around this problem on my own.
Last edited by bullseyeinteractive (2008-03-12 18:37:36)
Offline
Re: [archived] sab_substr
Problem found. The preg_replace was missing the ‘s’ modifier, needed to treat the entire string as a single line. New version uploaded.
“substr” is not safe for use with UTF-8 strings, because it works on byte level instead of on character level, which for UTF-8 means a string can be split inside a multi-byte character and that results in invalid UTF-8.
Offline
Re: [archived] sab_substr
Ruud… uploaded the new version and I’m still seeing the ascii codes for “ and ‘. Is there something I haven’t set up correctly in Textpattern itself? I’ve gone through and replaced the “ and ‘ in the articles thinking that might have been a problem but no luck there either.
Offline
Re: [archived] sab_substr
sab_substr currently works only on normal text, not on HTML escaped text.
To make it work with HTML escaped text with markup, yet still make the limit attribute work accurately and have the resulting substring be valid HTML, that’s non-trivial and certainly a lot slower.
If you don’t mind tags getting stripped and risk of invalid HTML and inaccurate limits, you could add strip_tags and remove escape_output as a fast solution.
Offline
Re: [archived] sab_substr
The strip_tags
flip fixed it. And I don’t mind the tags getting stripped because I’m only using it for the title tag now. Thanks.
Offline
Re: [archived] sab_substr
ruud, just consider updating your help file sometime for the noobies, it did cause a problem earlier where someone copied it verbatim. Here’s what it says:
Example:
<sab_substr limit="10" trail="..."><txp:title /></sab_substr>
will output “long string…”, assuming the title is ‘long string title’.
Should be:
<txp:sab_substr limit="10" trail="..."><txp:title /></txp:sab_substr>
Also, when I use it as suggested in the help file, I get this crappy result. Is this the same limitation that has been discussed in this thread regarding escape characters?
EDIT: OK, I turned the no widow option off in Admin->Prefs (this option never worked to begin with, unfortunately, see here). Even with this option off, I still get this bad result. What’s the easiest way around this? I really don’t want to type in ascii codes for apostrophes and such. Is there a plugin to do this too? It would help, because I notice my RSS feed has these characters in it sometimes (depending on the reader).
Last edited by aswihart (2008-03-15 00:12:28)
Offline