Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-13 18:55:11

freaky
Member
From: Austria
Registered: 2004-10-14
Posts: 55
Website

Article callbacks for save, publish

Hello!

I’m in the process of writing an plugin which changes the Body_html entry in the database after article save or publish. Why? I want to replace some keywords with small images. In my case these are flags. For example: (AUT) is after save or publish replaced by <img src="flags/aut.gif" /> only in the Body_html. The body should by untouched since it is textile.

For that reason I used the following callbacks:

register_callback("replace_with_flags", "article", "save");
register_callback("replace_with_flags", "article", "publish");

But the thing is, that in this context I have no article!? (global $thisarticle;) The other thing is that the save callback isn’t called after save? One other way would be the change Texile itself but I want to avoid this.

I thought of using a simple plugin for the texile body (e.g. <txp:xxx_flag c=“aut” />) but this is to long :( (And it should also work for older articles.)

Or is there another way to do that?

Thanks in advance :)

Offline

#2 2009-05-13 19:00:17

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Article callbacks for save, publish

freaky

Try this trick in your registered callback routine to get the ID…

if(!empty($GLOBALS['ID'])) // newly-saved article
    $ID = intval($GLOBALS['ID']);
else
    $ID = gps('ID');

Not sure if it’s exactly right for your context but I hope it helps.


Steve

Offline

#3 2009-05-13 19:47:14

freaky
Member
From: Austria
Registered: 2004-10-14
Posts: 55
Website

Re: Article callbacks for save, publish

Thanks! That helped my a little bit :)

I tried to play around with the register callback

register_callback("sta_replace_with_flags", "article", "create");
register_callback("sta_replace_with_flags", "article", "publish");
register_callback("sta_replace_with_flags", "article", "edit");
register_callback("sta_replace_with_flags", "article", "save");
register_callback("sta_replace_with_flags", "article", "post");

The thing is that some callbacks are note registered (I think). I also think that this what I want doesn’t work :(
Maybe somebody has an good idea? :)

Thanks :)

Offline

#4 2009-05-13 19:56:38

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Article callbacks for save, publish

freaky

Here’s what I did in one plugin that manipulated saved article data…

register_callback('sta_replace_with_flags', 'article' );

function sta_replace_with_flags($event, $step)
        {
        $save = gps('save');
        if ($save)
                $step = 'save';

        $publish = gps('publish');
        if ($publish)
                $step = 'publish';

        switch(strtolower($step))
                {
                case "":         break;
                case "list":     break;
                case "create":   
                case "publish":  
                case "edit":    
                case "save":     
                        sta_replace_flags_where_needed();
                        break;
                case "delete":   break;
                }
        }

Hope that helps (some more).


Steve

Offline

#5 2009-05-13 20:07:53

freaky
Member
From: Austria
Registered: 2004-10-14
Posts: 55
Website

Re: Article callbacks for save, publish

Thank you very much!

       $save = gps('save');
        if ($save)
                $step = 'save';
       $publish = gps('publish');
        if ($publish)
                $step = 'publish';

This does the trick! :)

Offline

#6 2009-05-13 20:09:13

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: Article callbacks for save, publish

freaky

Glad you got it working.


Steve

Offline

Board footer

Powered by FluxBB