get('drupalXmlrpc', false); if ($drupalXmlrpc === false){ return PEAR::raiseError(_kt('No config for Drupal XMLRPC server')); } $oKTConfig = KTConfig::getSingleton(); $drupalURL = $oKTConfig->get('drupalURL', false); $client = new xmlrpc_client($drupalURL . $drupalXmlrpc); $client->return_type = 'phpvals'; return($client); } function authenticated() { //Get Drupal's seesion name to see if user is logged in $client = $this->setupdrupalxmlrpc(); if (PEAR::isError($client)) { return $client; } $message = new xmlrpcmsg("kt.getSessionName"); $r=&$client->send($message); $drupal_session_name = $r->val; if (!isset($_COOKIE[$drupal_session_name])) { return; } //Get the user from the Drupal Database $sid = $_COOKIE[$drupal_session_name]; $message = new xmlrpcmsg("kt.getUserBySession",array(php_xmlrpc_encode($sid))); $r=&$client->send($message); $duser = $r->val; IF (!($duser && $duser['uid'] > 0)) { setcookie($drupal_session_name, "", time() - 86400); unset($_COOKIE[$drupal_session_name]); return; } $oUser =& User::getByUsername($duser['name']); //If there is a profile field called profile_fullname use it in KnowledgeTree if (empty($duser['profile_fullname'])){ $userfullname = $duser['name']; } else { $userfullname = $duser['profile_fullname']; } if (PEAR::isError($oUser) || ($oUser === false)) { $oUser =& User::createFromArray(array( "Username" => $duser['name'], "Name" => $userfullname, "Email" => $duser['mail'], "EmailNotification" => true, "SmsNotification" => false, "MaxSessions" => 3, "password" => $duser['pass'], )); // This is a good place to do any additional tasks, // such as creating a home folder or adding the user to roles/groups. } else { // Update user with new info from Drupal $oUser->setName($userfullname); $oUser->setEmail($duser['mail']); $oUser->setPassword($duser['pass']); } if ($duser['kt_copyusersandroles']){ // Add user to same roles in KnowledgeTree as they have in Drupal foreach ($duser['roles'] as $key => $role){ $oGroup = Group::createFromArray(array('name'=>$role)); $oGroup = Group::getByName($role); $oGroup->addMember($oUser); } } //If the user has admin rights from Drupal's user tables - assumes KT system admins has a group id = 1 if ($duser['kt_admin']) { $oGroup = Group::get(1); $oGroup->addMember($oUser); } return $oUser; } function takeover() { //Get Drupal's seesion name to see if user is logged in $client = $this->setupdrupalxmlrpc(); if (PEAR::isError($client)) { return $client; } $message = new xmlrpcmsg("kt.getSessionName"); $r=&$client->send($message); $drupal_session_name = $r->val; // Need to strip out directories if drupal installation is not root // so that the drupal login redirector will forward user to the correct page $oKTConfig = KTConfig::getSingleton(); $rootUrl = $oKTConfig->get('rootUrl', '/'); preg_match('/(.*\/)(.*)$/', $rootUrl, $output); $basepath = $output[1]; // Re-encode url so that it can be passed through the redirectors of both Drupal and KnowledgeTree if (strpos($_SERVER["REQUEST_URI"], "redirect")>0){ $urlarray = split('redirect\=|\&errorMessage',urldecode($_SERVER["REQUEST_URI"])); $ref = urldecode($urlarray[1]); $rUrl = parse_url($ref); if (strpos($rUrl['query'], "qs=")>0){ $pvars = split('qs\=',$rUrl['query']); $pvars = split('\&',$pvars[1]); $pvars = $pvars[0]; $ref = str_replace($pvars,urlencode($pvars),$ref); } } else { $ref = $rootUrl . "/login.php"; } //Remove drupal directory if it exists $ref = substr($ref, strlen($basepath)); $oKTConfig = KTConfig::getSingleton(); $drupalURL = $oKTConfig->get('drupalURL', false); if (!isset($_COOKIE[$drupal_session_name])) { header($drupalURL.'user?destination='.urlencode($ref)); exit(); } } } class PortalPlugin extends KTPlugin { var $sNamespace = "drupal.drupal.plugin"; var $autoRegister = true; var $bAlwaysInclude = true; function PortalPlugin($sFilename = null) { $res = parent::KTPlugin($sFilename); $this->sFriendlyName = _kt("Drupal Plugin"); return $res; } function setup() { $this->registerInterceptor("DrupalInterceptor", "drupal.drupal.interceptor", __FILE__); $aOptions = array( 'sName' => 'Drupal Interceptor', 'sInterceptorNamespace' => 'drupal.drupal.interceptor', 'sConfig' => '' ); KTInterceptorInstance::createFromArray($aOptions); } } ?>