BLOG:CMS :: Support Forum

Support Forum for BLOG:CMS

You are not logged in.

#1 25.11.2006 04:25

abdon
BLOG:CMS Junior
Registered: 21.11.2006
Posts: 13

Passing a value to a plugin

Is there a way, to pass a value to a custom plugin from a blog entry?

I have a database that pulls information. From blog entries, I want to be able to access my database and inject the information into the blog entry. I figured out how to write a custom plugin, now I need to figure out how to pass a parameter to it from the blog entry itself, so the plugin knows what formated data to send back.

Any help would be appreciated. This is probably the last hard problem I need to figure out before I can continue with my project.

Offline

 

#2 27.11.2006 01:26

Radek Hulán
Site Admin
From: Prague, Czech Republic
Registered: 17.03.2004
Posts: 2509
Website

Re: Passing a value to a plugin

You can use e.g. event_PreItem, and parse it.

http://blogcms.com/admin/documentation/ … ugins.html


--= BLOG:CMS developer =--

Offline

 

#3 27.11.2006 10:44

abdon
BLOG:CMS Junior
Registered: 21.11.2006
Posts: 13

Re: Passing a value to a plugin

Radek Hulán wrote:

You can use e.g. event_PreItem, and parse it.

http://blogcms.com/admin/documentation/ … ugins.html

Yeah, I figured as much, but after several hours of hacking at it I could not make it work :'(

I was able to get the following to work for the comments:

function getEventList() { return array('PreAddComment'); }
  function event_PreAddComment(&$data) {
    // replace acronym HTML
    $data['comment']['body'] = str_replace('test','<strong>test<strong>',$data['comment']['body']);
  }

But I could not figure out how to modify a blog entry. I imagine it ought to look something like this:

getEventList() { return array('PreBlogContent'); }
  function event_PreBlogContent(&$data) {
    // replace acronym HTML
    $data['blog']['body'] = str_replace('test','<strong>test<strong>',$data['blog']['body']);
  }
}

But the parameters are wrong. Could you please help me figure out what's wrong?

By the way, on the example given on plugins.html there is a typo. strreplace should be str_replace.

Thanks a lot for all your help.

- Abdon

Offline

 

#4 27.11.2006 19:09

Radek Hulán
Site Admin
From: Prague, Czech Republic
Registered: 17.03.2004
Posts: 2509
Website

Re: Passing a value to a plugin

Look e.g. how admin/plugins/NP_Poll.php is written, it will become clear :-)


--= BLOG:CMS developer =--

Offline

 

#5 29.11.2006 13:02

abdon
BLOG:CMS Junior
Registered: 21.11.2006
Posts: 13

Re: Passing a value to a plugin

Radek Hulán wrote:

Look e.g. how admin/plugins/NP_Poll.php is written, it will become clear :-)

It seems our idea of clear is not the same. It took me a while to figure out what was going on :}

In case somebody else may need it, here is how the code goes. I created a marker inside of a blog entry, something in the form of MARKER_X where 'X' refers to a database record. The plugin searches for that instance, and if found, pull a record from the database, generates some HTML, and serves instead a database generated content.

This is how the code goes:

function getEventList() { return array('PreItem'); }
  function event_PreItem(&$data) {

    if (preg_match('/(MARKER_)(\d+)/', $data['item']->body,$match)){
      $query = sql_query("SELECT * FROM `TABLE` WHERE SOMEID=$match[2]");
      while ($msg = sql_fetch_array($query)) {
        // format your data, save it to $tempHTMLOut
      }
      $data['item']->body = $temphtmlout;
    }

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson

TOPlist