Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-02-05 10:56:53

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Developing plugins: finding a tag within the plugin

I’m not sure if this is the right forum to post this question, but here goes …

I’m looking at extending the functionality of zem_contact_reborn. One of the things I need to be able to do is find out if a certain tag is used within the plugin; I need this as part of some basic validation before the plugin actually displays anything.

Let’s try to make this simpler. Say I have a plugin called “my_plugin”, which contains a specific tag called “needed”, which are used as follows:
<code>
<txp:my_plugin>
<txp:my_plugin_needed />
<txp:my_plugin />
</code>

So, in this case I want the plugin to test for the presence of <code><txp:my_plugin_needed></code> before the tag is parsed and modify the functionality depending on whether that tag is present or not.

The closest I have got is to allow the tag to be parsed and then test the HTML returned for some specific strings – but this is really too late to actually stop the plugin from running if the tag is not present.

Can someone drop me some pointers on how to do this? I can be more specific if necessary.

Thanks,

Anura

PS I’m really not a PHP coder. I’ve had some success with modifying the work of others (ie. standing on the shoulders of giants!).

Offline

#2 2006-02-06 09:14:54

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

Re: Developing plugins: finding a tag within the plugin

Why not just pass a default to the my_plugin() routine, where, if it finds that false/missing/etc, it will halt – or (less portable), hard code what you’re trying to set into the function itself?

Offline

#3 2006-02-06 20:52:03

igner
Plugin Author
Registered: 2004-06-03
Posts: 337

Re: Developing plugins: finding a tag within the plugin

this topic’s come up before, see this thread

Not sure what came of it – I’ve been occupied with other things of late.


And then my dog ate my badger, and the love was lost.

Offline

#4 2006-02-08 10:40:14

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Developing plugins: finding a tag within the plugin

neptho, Are you suggesting having a default overridden by the plugin tag? If so, I’m afraid I’m still in the dark over how to get the main plugin to check for the presence of the tag before the tag itself is processed; otherwise, it would mean having to parse the tag and then see what happens.

igner, Thanks, I read that thread but it seem to be about storing plugin settings. My issue isn’t a setting as such, but more a once only check that a plugin tag exists that has to be repeated each time the plugin is used.

Any more suggestions? I know I’m a bit thick, but I’ll persist with trying to find a solution. Thanks again.

Offline

#5 2006-02-08 16:56:14

takshaka
Archived Plugin Author
From: Below the Manson-Nixon line
Registered: 2004-06-02
Posts: 97
Website

Re: Developing plugins: finding a tag within the plugin

I’m not sure I understand what you actually need.

If you want to know whether the foo_tag tag of foo_plugin is defined, do —

<pre>include_plugin(‘foo_plugin’);
if (function_exists(‘foo_tag’)) // foo_tag exists
else // no foo_tag</pre>

If you want to know whether a pair of enclosing tags contains another tag —

<code><txp:enclosing_tag>
<txp:foo_tag />
</txp:enclosing_tag></code>

— then you’ll have to search for it:

<pre>
function enclosing_tag ($atts, $content) { if (substr_count($content, ‘&lt;txp:foo_tag ‘)) // tag exists else // it doesn’t
}
</pre>

Offline

#6 2006-02-08 22:35:37

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Developing plugins: finding a tag within the plugin

takshaka, Thank you – the second one will do the trick I think. It’s not whether the plugin tag has been defined, but whether or not someone has used it within any instance of the plugin.

If I’m allowed near a computer tonight, I’ll go home and try it out.

Thanks again for your help. My knowledge of PHP and TXP slowly expands.

Offline

Board footer

Powered by FluxBB