Revision: 40068
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 25, 2011 21:57 by jurajsim
Initial Code
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.plugin.plugin');
class plgUserPap4 extends JPlugin
{
function plgUserPap4(& $subject, $config) {
parent::__construct($subject, $config);
}
/**
* Example store user method
* Method is called after user data is stored in the database
*/
function onAfterStoreUser($user, $isnew, $succes, $msg)
//function onBeforeStoreUser($user, $isnew)
{
global $mainframe;
// convert the user parameters passed to the event
// to a format the external application
$args = array();
$args['username'] = $user['username'];
$args['email'] = $user['email'];
$args['fullname'] = $user['name'];
$args['password'] = $user['password_clear'];
$args['parentuserid'] = $user['parentuserid'];
//foreach($user as $k=>$v) {
// echo "$k = $v<br>";
//}
if ($isnew)
{
// Call a function in the external app to create the user
// ThirdPartyApp::createUser($user['id'], $args);
require("PapApi.class.php");
// load plugin params info
$plugin =& JPluginHelper::getPlugin('user', 'pap4');
$pluginParams = new JParameter( $plugin->params );
$pap4Url = $pluginParams->get( 'pap4_url', 1 );
$pap4Username = $pluginParams->get( 'pap4_username', 1 );
$pap4Pwd = $pluginParams->get( 'pap4_password', 1 );
try {
// login to API
$session = new Gpf_Api_Session($pap4Url);
if(!$session->login($pap4Username, $pap4Pwd)) {
echo ("Cannot login. Message: ".$session->getMessage());
return;
}
$clickTracker = new Pap_Api_ClickTracker($session);
try {
$clickTracker->track();
} catch (Exception $e) {
}
if ($clickTracker->getAffiliate() != null) {
$args['parentuserid'] = $clickTracker->getAffiliate()->getValue('userid');
}
// create new affiliate
$affiliate = new Pap_Api_Affiliate($session);
$affiliate->setUsername($args['email']);
$affiliate->setPassword($args['password']);
$affiliate->setFirstname('Joomla');
$affiliate->setLastname($args['fullname']);
$affiliate->setParentUserId($args['parentuserid']);
if(!$affiliate->add()) {
echo("Cannot add record: ".$affiliate->getMessage());
return;
} else {
echo("Affiliate successfuly added");
}
} catch(Exception $e) {
echo("PAP4 API call error: ".$e->getMessage());
return;
}
}
}
}
Initial URL
Initial Description
Initial Title
Joomla affiliate register plugin
Initial Tags
php, plugin, joomla
Initial Language
PHP