plugins + xajax

plugins + xajax

Postby chromos on Mon Jun 23, 2008 4:03 pm

Hello,
I want to register a function from a plugin with xajax. But I am not sure how to approach that problem.

A post from smarty forums looks like this:
Code: Select all
<?php
   require_once('/includes/header.php');
   
   $smarty = new Smarty;
   $smarty->config_dir = SMARTY_DIR;
   $smarty->template_dir = $_SERVER['DOCUMENT_ROOT'].'/templates';
   $smarty->compile_dir = $_SERVER['DOCUMENT_ROOT'].'/templates_c';
   $smarty->caching = FALSE;
   $smarty->compile_check = TRUE;
   $smarty->debugging = TRUE;
   
   
   $xajax = new xajax("/includes/boxes/login.php");
   $xajax->registerFunction('getPost', 'login.php');
   $xajax->processRequest();
   //$xajax->setFlags('debug',true);
   
       
   $smarty->assign("xajax_javascript",$xajax->getJavascript("/js/xajax/"));
   $smarty->display("index.tpl");
   
?>


1. Where would i place the
Code: Select all
new xajax
in lifetype's code? in template.class.php?

2. Where should i place
Code: Select all
processRequest()
, in template.class.php too?

The parameter of new xajax should then point to my plugin's class php file?
the
Code: Select all
getPost
function is a member Function of the plugin's class.

All i can think of is writing a function something like this:

Code: Select all
function RegisterMe() {
$a = new foo() /*the plugin class*/
return ($a->getPost());
}


But where would i have to place this function?

I am really confused atm.
I haven't ever thought that it'd be so hard to include xajax into lifetype :(
chromos
 
Posts: 274
Joined: Wed Mar 09, 2005 2:22 pm
LifeType Version: 1.2.9-devel

Re: plugins + xajax

Postby jondaley on Tue Jun 24, 2008 8:42 am

It might be easier if you tell us what you are actually trying to accomplish.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: plugins + xajax

Postby chromos on Tue Jun 24, 2008 12:54 pm

Well, basically I want to get the posts of a specific category with the help of a plugin. That's working right now

Furthermore, I want to register this function of the plugin with xajax to be able to asynchronously call the function via javascript wich returns the posts to the browser.

Hope it gets clearer ...
chromos
 
Posts: 274
Joined: Wed Mar 09, 2005 2:22 pm
LifeType Version: 1.2.9-devel

Re: plugins + xajax

Postby jondaley on Wed Jun 25, 2008 1:16 am

If you want to be able to run php from the template, you'll need to enable php (this is a security risk if you have other untrusted people who have blogs, and can write their own templates, otherwise it is safe) in the templates. Then you can put all your xajax php code in the template surrounded by {php} {/php} tags.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: plugins + xajax

Postby chromos on Wed Jun 25, 2008 4:22 am

Ok so you are saying, You'd just put all of this code into the template.

That's what I'd do to get this particular example working, but the function I want to register is a class method of a plugin.
And I am somehow stuck to make the transfer from this very simple example to the plugin's class method:

Questions:
1. I have to create the xajax object with a parameter pointing to the file the php function i want to register is in.
$xajax = new xajax("/plugins/foo/PluginFoo.class.php");
That won't ever work, will it?

2. the function I want to register with xajax->registerFunction() is a function of the class PluginFoo in the directory /plugins/foo. How am I able to register a class method?

BTW: I somehow managed to post in the wrong forum ...
chromos
 
Posts: 274
Joined: Wed Mar 09, 2005 2:22 pm
LifeType Version: 1.2.9-devel

Re: plugins + xajax

Postby jondaley on Wed Jun 25, 2008 9:15 am

Not knowing the code at all, I'd expect the xajax code to need a static function, and not a class member. So, as long as your class function can be called statically, ie. PluginName::FunctionName() you should be alright.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: plugins + xajax

Postby chromos on Tue Jul 01, 2008 1:51 pm

Ah I see I didn't know that i could use PluginName::FunctionName() to access the functions.

Unfortunately the include statement causes some trouble:
Code: Select all
include './xajax/xajax_core/xajax.inc.php';


failed to open stream: No such file or directory in /home/foo/public_html/lifetype/tmp/3/%%A6^A66^A6664C68%%header.template.php on line 6

Have been fiddling around for some days now, but i couldn't find a solution ...

BTW: Within the Function PluginName::FunctionName(), I call $this->blogInfo->getId().
This call is not valid when trying to call this class method with PluginName::FunctionName().

Do you have any suggestions how to solve this problem?
chromos
 
Posts: 274
Joined: Wed Mar 09, 2005 2:22 pm
LifeType Version: 1.2.9-devel

Re: plugins + xajax

Postby jondaley on Tue Jul 01, 2008 3:58 pm

Use the full path name when including - that is the best. You can use the PLOG_CLASS_PATH to get the root directory - see any of LT's include lines.

Right, you can use the Plugin::Function method, but you can't use $this inside that function, since it is being called statically, as opposed to part of the class.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: plugins + xajax

Postby chromos on Fri Jul 11, 2008 1:38 pm

luckily, I did not need xajax. I had a look at the crystalpoll plugin. I did not know that I am able to access plugin registered actions with ?op=pluginaction

But, maybe someone has an idea how to get the pager working?
chromos
 
Posts: 274
Joined: Wed Mar 09, 2005 2:22 pm
LifeType Version: 1.2.9-devel


Return to Plugin Development Team

cron