Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#37 2011-11-10 18:35:54

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: rah_function // Every PHP function is a tag

Hey maruchan,

I did and those were pretty useful, however, they are all preg_replace examples. I’m trying to find a match only. I know it should probably be easier to figure out!

Offline

#38 2011-11-10 18:48:59

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: rah_function // Every PHP function is a tag

This worked:

<txp:rah_function call="preg_match" pattern="/^pdf/" subject="pdf" />

Wondering how one would use two functions (such as if and preg_match) in one rah tag. I’m a little confused over the attribute ‘thing’.

Offline

#39 2011-11-11 00:12:49

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_function // Every PHP function is a tag

lithium002 wrote:

This doesn’t generate any errors or warnings but does nothing.

The if you are calling isn’t a function, but a language construct. That’s the reason why it doesn’t return any errors or anything else either.

Wondering how one would use two functions (such as if and preg_match) in one rah tag.

Can’t. One tag can call one function. But you can use the tag to pass the results to other rah_function tag, or in the case of conditionals to variable and test the results with if_variable. Well, as long as the results can carry over to string land (you won’t be able to tell bool from integer for instance). As in:

<!--
	Create a variable called "math", and
	populate it with the results from rah_function
-->

<txp:variable name="match"><txp:rah_function call="preg_match" pattern="/^pdf/" subject="pdf" /></txp:variable>

<!--
	The variable should return either 1 or 0.
	Knowing that, one can do the conditional.
-->

<txp:if_variable name="match" value="1">
	Yes.
<txp:else />
	No.
</txp:if_variable>

I’m a little confused over the attribute ‘thing’.

That thing … thing sets to which parameter the wrapped content is passed to. The location thing attribute is placed in the parameter list, is where the wrapped content is passed. The attribute get’s it’s funky name, thing, from Textpattern. That’s what the parameter/functionality is called in Textpattern’s source code, and the name avoids collisions slightly better than potentially more commonly used names.

Last edited by Gocom (2011-11-11 00:17:06)

Offline

#40 2011-12-16 17:26:36

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_function // Every PHP function is a tag

Rah_function v0.4 released. Changes:

  • Improved: Do not use attributes’ real names in the function call, but use a temp array. Makes sure attributes get resolved as valid variables no matter what is passed to plugin tag by Textpattern’s parser.

More info and downloads

Last edited by Gocom (2011-12-16 17:27:21)

Offline

#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
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
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
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
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
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
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: 590
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

Board footer

Powered by FluxBB