Textpattern CMS support forum

You are not logged in. Register | Login | Help

#41 2011-12-21 23:00:31

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: rah_function // Every PHP function is a tag

Hi Jukka

Following on from your suggestion on the adi_wrap adi_join thread, could I trouble you for a bit more advice?

Removing a load of line breaks makes for an ugly mess in the template though. It would be great if there was plugin that I could wrap the code in that would remove the unwanted line breaks (and leave the desirable ones in tact) so I could keep my code semi-readable.

Could rah_function do that?

Last edited by pieman (2011-12-21 23:01:58)

Offline

#42 2011-12-21 23:56:40

Gocom
Plugin Author
Registered: 2006-07-14
Posts: 4,524
Website

Re: rah_function // Every PHP function is a tag

pieman wrote:

adi_join

For adi_join specifically, I would kindly ask Adi to add some extra improved functionality and options to the plugin’s toolset. Like for example an ability to select your own delimiter instead of using line breaks. To me it would also make sense to do the splitting before parsing, which prevents linebreaks carrying over from content. Title (<txp:title />) containing a linebreak wouldn’t effect adi_join’s results for instance.

Could rah_function do that?

Well, rah_function can do search-and-replace (str_replace, preg_replace) tasks for sure. Don’t know about keeping desirable ones intact. For that dedicated search-and-replace plugin, rah_replace, removing linefeeds is matter of:

<txp:rah_replace from="
" to="">
	<!--
		Something to modify
	-->
</txp:rah_replace>

Last edited by Gocom (2011-12-21 23:58:14)

Offline

#43 2012-03-30 03:52:14

WebKat
Member
Registered: 2007-01-16
Posts: 301

Re: rah_function // Every PHP function is a tag

I want to use this to put around an RSS feed so that it strips out images. How would I configure that?



WebKat

Offline

#44 2012-03-30 04:41:20

Gocom
Plugin Author
Registered: 2006-07-14
Posts: 4,524
Website

Re: rah_function // Every PHP function is a tag

Strip_tags perhaps?

<txp:rah_function call="strip_tags" allowed_tags="<p><a><em><strong><i><b><del><ins><u><table><td><tr><th><thead><tbody>">
	<p>Some HTML to filter.</p>
</txp:rah_function>

Offline

#45 2012-03-30 05:41:19

WebKat
Member
Registered: 2007-01-16
Posts: 301

Re: rah_function // Every PHP function is a tag

yeah! That worked great! Thanks for the help!!



WebKat

Offline

#46 2012-03-30 15:11:09

WebKat
Member
Registered: 2007-01-16
Posts: 301

Re: rah_function // Every PHP function is a tag

Ok, I have another question. <txp:rah_function> is doing something I don’t understand. Here is how I am calling it to display my LiveJournal rss feed (the one I needed the images stripped out of):

<txp:rah_function call="strip_tags" allowed_tags="<a><p><br><em><strong><i><b><u><form><input><span><div><table><td><tr><th><thead><tbody><blockquote>">
		<txp:bit_rss feed="http://opalcat.livejournal.com/data/atom" limit="4" form="rss" wraptag="p" />
</txp:rah_function>

So I have it allowed to show <a ...> tags, and it is, technically, if you look at the source code. What it ISN’T showing is what’s between the <a href="blah"> and </a>… it’s stripping that out, and I don’t want that. I want my links to work!

Whoa—hey—when I viewed the sourcecode I realized that it was stripping out my <h3> tags, so I added <h1><h2><h3> to my rah_function allowed tags, and for some reason, THAT allowed what was inside my link tags to show up!! I don’t see how they’re connected, but it works now. My new code looks like this:

<txp:rah_function call="strip_tags" allowed_tags="<a><p><br><em><strong><i><b><u><h1><h2><h3><form><input><span><div><table><td><tr><th><thead><tbody><blockquote>">
		<txp:bit_rss feed="http://opalcat.livejournal.com/data/atom" limit="4" form="rss" wraptag="p" />
</txp:rah_function>

and it’s outputting the proper code. The only problem is that there is lots of white space… it used to be that in my LiveJournal, after the images I had <br /> tags then the text link, but I added a style="clear:both;" to my image tags and removed the <br /> tags and in my journal it shows up looking exactly the same, except it won’t pull over a bunch of <br /> tags and make empty spaces… I think it might be that the reason I’m seeing the empty spaces anyway is that the rss feed is cached…? And I need to wait for it to pull the new one? Because I still see the <br /> tags when I view the sourcecode.

Anyway, I started this post out as a question as to why my links were empty and not showing up, and fixed it on my own in the process, but I decided to post it anyway in case anyone else ever has the same problem. Again, I have no idea why it worked. But it did.



WebKat

Offline

#47 2012-03-30 15:32:09

Gocom
Plugin Author
Registered: 2006-07-14
Posts: 4,524
Website

Re: rah_function // Every PHP function is a tag

The strip_tags function you are using to remove certain tags (rah_function is the wrapper), doesn’t care what you feed to it — it just removes nodes matching to a pattern. If it eats content with tags, that is the sign that the HTML you giving it is invalid. Most likely you have a broken tag, or stranded bracket somewhere (<, >). All brackets that are not part of a HTML tag, should be converted to entities, i.e. <3 should be &lt;3.

Offline

#48 2012-03-30 16:22:18

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 581
Website

Re: rah_function // Every PHP function is a tag

strip_tags is weird. I used it in a recent programming project and after about 30 minutes of annoyance decided to find a better way. So there are better tools for this job, but I don’t know of any that are as simple to set up as strip_tags.

Offline

#49 2012-03-30 17:41:51

WebKat
Member
Registered: 2007-01-16
Posts: 301

Re: rah_function // Every PHP function is a tag

Gocom wrote:

The strip_tags function you are using to remove certain tags (rah_function is the wrapper), doesn’t care what you feed to it — it just removes nodes matching to a pattern. If it eats content with tags, that is the sign that the HTML you giving it is invalid. Most likely you have a broken tag, or stranded bracket somewhere (<, >). All brackets that are not part of a HTML tag, should be converted to entities, i.e. <3 should be &lt;3.

Well as I said, it works now and I didn’t change the html that I was giving it, so the html is fine.. I just added <h1><h2><h3> to the allowed tags and somehow that made it work.



WebKat

Offline

#50 2012-07-19 12:43:31

Gocom
Plugin Author
Registered: 2006-07-14
Posts: 4,524
Website

Re: rah_function // Every PHP function is a tag

Rah_function v0.5 now out. This release is major and adds number of few features.

First and foremost is added support to class methods. Previously rah_function was able to call just functions, but now its support is extended to methods. Calling methods happens with a syntax familiar to PHP, e.g.

<txp:rah_function call="class->method" />
<txp:rah_function call="class::method" />

Rah_function’s new attribute _is allows using the tag as a conditional. When _is is defined the tag works as a conditional, similarly to any other if_ tag in Textpattern:

<txp:rah_function call="get_pref" name="production_status" _is="debug">
	Site is in debugging mode.
<txp:else />
	Either in Testing or Live.
</txp:rah_function>

Now the plugin also supports different types, casting and can pass different types to functions. For instance, arrays are now returned to as JSON and can be passed to the called function with simple JSON string. Any attribute can be converted to the different type using using attribute prefixes, as _int and _bool. These prefixes can also work as security feature. A attribute prefixed with _int will be converted to a integer no matter what the supplied value is.

Last of the new notable features is multi-function support. A single tag can call multiple functions and class methods. The tag’s call attribute can take a comma-separated list of functions. This allows to further process output returned by a function with a second or more functions.

Full list of changes:

  • Added: Ability to call class methods (call="Class->Method" and call="Class::StaticMethod").
  • Added: Multiple functions can be called with a single tag instance (call="func1, func2, func3"). Output is passed by reference from function to function. First function in the list is treated as the primary and given tag attributes only apply to it.
  • Added: Arrays are returned as JSON string and can be passed from one tag instance to other. JSON can be used as a value by prefixing used tag attribute name with _array.
  • Added: Converts returned booleans to uppercase strings, TRUE and FALSE. This makes it possible to identify integers from booleans (e.g. strpos).
  • Added: Function whitelisting option.
  • Improved: Prevent passing non-scalars to the template.
  • Improved: Moved away from sanitization and eval(). Now uses callbacks.
  • Improved: Show some error messages when needed.
  • Updated: Help file (readme). Thanks to Tye for help.

More info and downloads

Last edited by Gocom (2012-07-19 12:46:01)

Offline

Board footer

Powered by FluxBB