Skip to Content Skip to Menu

eventhandler doesn't call function

  • onzinnet
  • onzinnet
  • OFFLINE
  • Posts: 1
  • Thanks: 0
  • Karma: 0
17 years 11 months ago #24659 by onzinnet
eventhandler doesn't call function was created by onzinnet
Hi,

I've been developing a plugin to bridge Listmessenger with CB. The problem is that my custom class(LEbridge) is not instantiated and none of the functions is called.

My sourcecode(adapted version of the mailman plugin)
[code:1]<?php
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');

$_PLUGINS->registerFunction('onAfterUserApproval', 'afterApproveUser', 'LEbridge');
$_PLUGINS->registerFunction('onAfterNewUser', 'afterNewUser', 'LEbridge');

$_PLUGINS->registerFunction('onAfterDeleteUser', 'afterDeleteUser', 'LEbridge');

$_PLUGINS->registerFunction('onBeforeUserUpdate', 'beforeUpdateUser', 'LEbridge');
$_PLUGINS->registerFunction('onBeforeUpdateUser', 'beforeUpdateUser', 'LEbridge');

print_r($_PLUGINS);
include 'Snoopy.class.php';
echo("Plugins geregged, aanroepen van snoopy voltooid."«»);
//install function, does nothing, just returns a successtext.
function plug_cb_LEbridge_install() {
$html = ' Thank you for downloading and installing this CB plugin!';

return $html;
}

//uninstall function, just returns a successtext.
function plug_cb_LEbridge_uninstall() {
return '<p> Thank you for trying this plugin!</p>';
}

//bridge listemessenger and comunitybuilder
class LEbridge extends cbEventHandler
{
var $snoopy_instance;
var $login_cookies_instance;

//construct super class.
function LEbridge()
{
parent::cbEventHandler();
echo("class instantiated."«»);
}

//when approve is marked the user will be subscribed, if not the user will be unsubscribed.
function afterApproveUser($user, $approved, $succes) {
echo("Debug: AfterApprove"«»);
$this->_printArray($user);
if ($approved) {
$this->Subscribe($user->email);
} else {
$this->unSubscribe($user->id);
}
return true;
}

//after a new user is submitted, he will be subscribed.
function afterNewUser($user, $cbUser, $stored = false, $smth = true) {
echo("Debug: afterNewUser"«»);
$this->_printArray($user);
$this->Subscribe($user->email);
return true;
}

//on change of email address
function beforeUpdateUser(& $user, & $cbUser) {
global $database;

echo("Debug: beforeUpdate"«»);
$this->_printArray($user);
$query = "SELECT email, block FROM #__users WHERE id = $user->id";
$database->setQuery($query);
$old_row = $database->LoadRow();

$old_email = $old_row[0];
$old_block = $old_row[1];
//unsubscribe the old one and subscribe the new email
if ($old_email != $user->email) {
$this->unSubscribe($id);

if (! $user->block ) {
$this->Subscribe($user->email);
}
} else if ($user->block != $old_block) {
if (! $user->block ) {
$this->Subscribe($user->email);
} else {
$this->unSubscribe($user->id);
}
}

return true;
}

//When a user is deleted, he will be unsubscribed.
function afterDeleteUser($user, $store = true) {
echo("Debug: afterdelete"«»);
$this->_printArray($user);
$this->unSubscribe($user->id);
return true;
}

//loginprocedure for the admin pannel
function admin_login() {
echo("Admin login"«»);
global $login_cookies_instance;

if (!isSet ($login_cookies)) {
$params = $this->params;
$submit = $params->get('admin_password', '');
$url = $params->get('admin_url', '');

$s = $this->_getSnoopy();
$s->submit($url, $submit);

while (list ($key, $val) = each($s->headers)) {
list ($title, $value) = split(":", $val);
if ($title == 'Set-Cookie') {
$cookieList = split(';', $value);
while (list ($k, $v) = each($cookieList)) {
list ($cookieKey, $cookieVal) = split('=', trim($v));
$login_cookies_instance[trim($cookieKey)] = trim($cookieVal);
}
}
}
}
return $login_cookies_instance;
}

function Subscribe($email) {
echo("Debug: Subscribe has been called"«»);
$login_cookies = $this->admin_login();

$params = $this->params;
$url = './administrator/index2.php?option=com_lm&section=subscribers&action=add';

//first and lastname also from postdata?
$postdata = $params->get('firstname');
$postdata = $params->get('lastname');
$postdata = $email;

echo("Submitting: ".$postdata.$postdata.$postdata."@ $url"«»);

$s = $this->_getSnoopy();
$s->cookies = $login_cookies;
$s->submittext($url, $postdata);
}

function unSubscribe($id) {
echo("Debug: unsubscribe has been called."«»);
$login_cookies = $this->admin_login();

$url = './administrator/index2.php?option=com_lm&section=subscribers&action=delete';

$postdata'] = array($id);
echo("Unsubscribing user: ".$id);
$s = $this->_getSnoopy();
$s->cookies = $login_cookies;
$s->submittext($url, $postdata);
}

//@access: private, instantiates the snoopy class.
function _getSnoopy() {
echo("Debug: snoopy has been called"«»);
global $snoopy_instance;
if (!isSet ($snoopy_instance))
$snoopy_instance = new Snoopy;
return $snoopy_instance;
}

function _printArray($userInfo)
{
echo("Print van de user array is aangevraagd..."«»);
foreach($userInfo as $info)
{
echo("Key:".key($info)." & value:".$info);
}
}
}
?>
[/code:1]
As you can see I've put some debug messages in my function to notify me when a function has been called. None of these show. This is my output:

cbPluginHandler Object ( [_events] => Array ( [onBeforeUserProfileDisplay] => Array ( [0] => Array ( [0] => getMenuTab [1] => prepareMenu [2] => 14 ) [1] => Array ( [0] => getStatusTab [1] => prepareStatus [2] => 14 ) ) [onAfterDeleteUser] => Array ( [0] => Array ( [0] => getConnectionTab [1] => userDeleted [2] => 2 ) [1] => Array ( [0] => LEbridge [1] => afterDeleteUser [2] => 505 ) ) [onAfterUserApproval] => Array ( [0] => Array ( [0] => LEbridge [1] => afterApproveUser [2] => 505 ) ) [onAfterNewUser] => Array ( [0] => Array ( [0] => LEbridge [1] => afterNewUser [2] => 505 ) ) [onBeforeUserUpdate] => Array ( [0] => Array ( [0] => LEbridge [1] => beforeUpdateUser [2] => 505 ) ) [onBeforeUpdateUser] => Array ( [0] => Array ( [0] => LEbridge [1] => beforeUpdateUser [2] => 505 ) ) ) [_menus] => [_lists] => [_plugins] => Array ( [1] => stdClass Object ( [id] => 1 [folder] => plug_cbcore [element] => cb.core [published] => 1 [type] => user [params] => [lookup] => plug_cbcore/cb.core ) [14] => stdClass Object ( [id] => 14 [folder] => plug_cbmenu [element] => cb.menu [published] => 1 [type] => user [params] => [lookup] => plug_cbmenu/cb.menu ) [2] => stdClass Object ( [id] => 2 [folder] => plug_cbconnections [element] => cb.connections [published] => 1 [type] => user [params] => [lookup] => plug_cbconnections/cb.connections ) [3] => stdClass Object ( [id] => 3 [folder] => plug_cbmamboauthortab [element] => cb.authortab [published] => 1 [type] => user [params] => [lookup] => plug_cbmamboauthortab/cb.authortab ) [5] => stdClass Object ( [id] => 5 [folder] => plug_cbmamblogtab [element] => cb.mamblogtab [published] => 1 [type] => user [params] => [lookup] => plug_cbmamblogtab/cb.mamblogtab ) [505] => stdClass Object ( [id] => 505 [folder] => plug_cb_lebridge [element] => cb.LEbridge [published] => 1 [type] => user [params] => [lookup] => plug_cb_lebridge/cb.LEbridge ) ) [_pluginGroups] => Array ( [user] => Array ( [1] => 1 [14] => 14 [2] => 2 [3] => 3 [5] => 5 ) ) [_loading] => 505 [debugMSG] => Array ( ) [errorMSG] => Array ( ) [_iserror] => [params] => ) Plugins geregged, aanroepen van snoopy voltooid. Registration Complete!
You may now login.

I think the problem is in the $_PLUGINS->registerfunction part. Can anybody point out the problem?

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum