Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-08-12 09:02:06

doogxela
Member
Registered: 2004-07-29
Posts: 14
Website

request: custom author signature

I would like a plugin that includes a file containing the article author’s signature. I am currently accomplishing the same effect using form overrides on my website (http://www.doogxela.net) but it was recently pointed out to me that this may not be a good use of the form override. I was thinking that I could create a separate file for each signature (or could I store these signatures in the database somehow, maybe in a custom field?) that would be called with a simple PHP include statement.

Offline

#2 2004-08-12 18:33:31

kennethlove666
Member
From: arkansas
Registered: 2004-04-27
Posts: 107
Website

Re: request: custom author signature

why not look into the if category and if section plugins and mod one so it’s if author?

have it check to see if the author name matches a given value, and if so, displays using xxxxx form. that way, that form could just contain the author’s signature, and it wouldn’t require any included files or form overrides.

if i have time, and you express an interest, i’ll try to rig this up.


Listen to Kenneth

Offline

#3 2004-08-12 20:04:36

doogxela
Member
Registered: 2004-07-29
Posts: 14
Website

Re: request: custom author signature

I’m afraid that I’m not much of a programmer, so I would very much appreciate it if you rigged something up for me. Would it be possible to have the plugin figure out the author and return that value to, perhaps, the txp:output_form tag? That way I wouldn’t need to create a conditional statement for every single author. It also wouldn’t need to be updated every time I add an author. If that’s not possible, then something like the if_section would be just fine.

Offline

#4 2004-08-12 20:47:15

doogxela
Member
Registered: 2004-07-29
Posts: 14
Website

Re: request: custom author signature

Well, I tried to do this myself, but I seem to be coming up empty. When I try to upload my plugin, I get this error:

Warning: base64_decode() expects parameter 1 to be string, array given in F:\doogxelanet\textpattern\textpattern\include\txp_plugin.php on line 127

Here is the code in my plugin:

<code> function dxm_siginsert($atts) { global $thisarticle; if (is_array($atts)) extract($atts); return '<txp:output_form form="'.$thisarticle['author'].'" />'; } </code>

So what am I missing? Yes, I am escaping the single quotes in the PHP file.

Offline

#5 2004-08-12 21:10:34

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

Re: request: custom author signature

Since this is partially my doing , here’s a simple proof of concept plugin for what I had in mind: chh_include.txt

Create a form for each signature and name it <code>signature:Name</code>, where Name is the Real Name value for that author (returned by <code><txp:author /></code>). Then add this to the end of your article form:

<pre><code><txp:chh_include formprefix=“signature:” param=“author” />
</code></pre>

So, for an author named John Doe, the tag will insert the contents of the form named <code>signature:John Doe</code>.

  • param — the txp tag/function to use as the form name
  • formprefix — added to the beginning of the form name (optional)
  • formsuffix — added to the end of the form name (optional)

Last edited by takshaka (2004-08-12 21:14:23)

Offline

#6 2004-08-13 02:08:12

doogxela
Member
Registered: 2004-07-29
Posts: 14
Website

Re: request: custom author signature

takshaka, your proof of concept does just what I needed, so I will most likely use it, since it can be used for any number of things, other than just custom sigs, and I appreciate it.

I would still like to know what is wrong with my code, though. I actually got my plugin uploaded by pretty much emptying it of code, then I tried to rebuild it. I finaly got it to work, and you know what? I ended up with exactly the same code as what I posted here. I really don’t understand that. I don’t understand why I was getting that error the first time I tried to upload it. Is my code reasonable?

takshaka, I have a few questions about yours. What is the $enc=’‘ in the function parameters? Are $prefix, $sufix, and $param arrays or just strings? In the line where you define $name, why do you have $param($atts)?

Sorry for those, but I’m trying to quickly learn PHP, and what programming I have done was quite some time ago.

Offline

#7 2004-08-13 02:32:35

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: request: custom author signature

Doog, regarding your PHP error: are you uploading the “compiled” plugin, or the human-readable source?


Alex

Offline

#8 2004-08-13 03:03:48

doogxela
Member
Registered: 2004-07-29
Posts: 14
Website

Re: request: custom author signature

> zem wrote:

> Doog, regarding your PHP error: are you uploading the “compiled” plugin, or the human-readable source?

The “compiled” plugin.

Offline

#9 2004-08-13 03:09:51

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: request: custom author signature

Odd. Can’t really say much more without seeing the plugin.


Alex

Offline

#10 2004-08-13 04:13:26

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

Re: request: custom author signature

> doogxela wrote:
> What is the $enc=’‘ in the function parameters?

Txp plugins are called with one or two arguments. The first is an array of attribute keys/values, which is always passed to the plugin. The second argument, a string containing the text enclosed by a double (long-form) tag, is not passed when a short-form tag is used.

<pre><code><txp:chh_example foo=“bar”>blah blah</txp:chh_example></code></pre>

The above long-form tag will result in a PHP function call that looks like <code>chh_example(array(‘foo’ => ‘bar’), ‘blah blah’)</code>

chh_include doesn’t actually do anything with $enc.

> Are $prefix, $sufix, and $param arrays or just strings?

They are strings.

> In the line where you define $name, why do you have $param($atts)?

That’s calling the function named by the string <code>$param</code>, in your case author(). This does actually make the plugin exploitable by authors if the tag is included in an article, since it allows the execution of an arbitrary PHP function, but I wanted something for more general use than your specific situation called for.

In your specific case, all the code you really need is what you tried yourself. But you should call output_form() directly or it probably won’t do anything:

<pre><code>
function dxm_siginsert($atts) { global $thisarticle; return output_form(array(‘form’ => $thisarticle[‘author’]));
}
</code></pre>

I would’ve just said this earlier, but —

  1. I wanted something more general, something I could use.
  2. I started writing my post before you posted your code. _;

Last edited by takshaka (2004-08-13 04:20:08)

Offline

#11 2004-08-13 04:29:04

doogxela
Member
Registered: 2004-07-29
Posts: 14
Website

Re: request: custom author signature

takshaka, thanks for answering all of my questions.

>> In the line where you define $name, why do you have $param($atts)?

>That’s calling the function named in $param, in your case author().

So I’m confused as to why you are calling the author() function. Isn’t the author name contained in the $atts array? Or is it the authorID?

Incidentally, my code does work:

<code>function dxm_siginsert($atts) {
global $thisarticle;
if (is_array($atts)) extract($atts);
return ‘<txp:output_form form=signature:”’.$thisarticle[‘author’].’” />’;
}</code>

That is the entirety of the plugin. Do I not actually need to extract $atts? (I’m not entirely sure I understand what that does anyway.)

Offline

#12 2004-08-13 16:36:03

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

Re: request: custom author signature

> doogxela wrote:

> So I’m confused as to why you are calling the author() function. Isn’t the author name contained in the $atts array? Or is it the authorID?

Txp tags correspond to PHP functions, so a <code><txp:article /></code> tag calls the article() function and <code><txp:author /></code> calls the author() function. All author() does is return the value of <code>$thisarticle[‘author’]</code> (the code is in textpattern/publish/taghandlers.php).

> Incidentally, my code does work:

Ah, cool. I wasn’t sure if the tag would be parsed.

> That is the entirety of the plugin. Do I not actually need to extract $atts? (I’m not entirely sure I understand what that does anyway.)

extract() creates variables based on the content of an array.

<pre><code>$stuff = array(‘one’ => 1, ‘two’ => 2);
extract($stuff);
// Now, $one = 1 and $two = 2
</code></pre>

I have an aversion to importing an arbitrary user-supplied list of variables. It’s one of the many things PHP encourages that grates on my nerves.

Your plugin doesn’t need to extract $atts because your tag doesn’t accept any attributes. But it doesn’t really matter. All of Dean’s tag handlers extract $atts whether it is used or not.

Last edited by takshaka (2004-08-13 16:36:35)

Offline

Board footer

Powered by FluxBB