Created
April 30, 2012 17:54
-
-
Save mcrider/2560466 to your computer and use it in GitHub Desktop.
Testing OAK plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file plugins/generic/oak/OAKPlugin.inc.php | |
* | |
* Copyright (c) 2003-2010 John Willinsky | |
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING. | |
* | |
* @class OAK | |
* @ingroup plugins_generic_oak | |
* | |
* @brief OAK plugin class | |
*/ | |
import('lib.pkp.classes.plugins.GenericPlugin'); | |
class OAKPlugin extends GenericPlugin { | |
/** | |
* URL for oak server | |
* @var string | |
*/ | |
var $_host; | |
/** | |
* Publisher account for oak server | |
* @var string | |
*/ | |
var $_publisherId; | |
/** | |
* Password for oak server | |
* @var string | |
*/ | |
var $_password; | |
/** | |
* Secure ID for user on oak server | |
* @var string | |
*/ | |
var $_sid; | |
/** | |
* Set the host | |
* @param $host string | |
*/ | |
function setHost($host) { | |
$this->_host = $host; | |
} | |
/** | |
* Get the host | |
* @return string | |
*/ | |
function getHost() { | |
return $this->_host; | |
} | |
/** | |
* Set the publisherId | |
* @param $publisherId string | |
*/ | |
function setPublisherId($publisherId) { | |
$this->_publisherId = $publisherId; | |
} | |
/** | |
* Get the publisherId | |
* @return string | |
*/ | |
function getPublisherId() { | |
return $this->_publisherId; | |
} | |
/** | |
* Set the password | |
* @param $password string | |
*/ | |
function setPassword($password) { | |
$this->_password = $password; | |
} | |
/** | |
* Get the password | |
* @return string | |
*/ | |
function getPassword() { | |
return $this->_password; | |
} | |
/** | |
* Set the SID | |
* @param $sid string | |
*/ | |
function setSid($sid) { | |
$this->_sid = $sid; | |
} | |
/** | |
* Get the SID | |
* @return string | |
*/ | |
function getSid() { | |
return $this->_sid; | |
} | |
/** | |
* Called as a plugin is registered to the registry | |
* @param $category String Name of category plugin was registered to | |
* @return boolean True iff plugin initialized successfully; if false, | |
* the plugin will not be registered. | |
*/ | |
function register($category, $path) { | |
$success = parent::register($category, $path); | |
$this->addLocaleData(); | |
if ($success && $this->getEnabled()) { | |
HookRegistry::register('Templates::SectionEditor::SubmissionEditing::PreProofread', array($this, 'insertOak')); | |
} | |
return $success; | |
} | |
function getDisplayName() { | |
return Locale::translate('plugins.generic.oak.displayName'); | |
} | |
function getDescription() { | |
return Locale::translate('plugins.generic.oak.description'); | |
} | |
/** | |
* Allow author to specify book for review during article submission. | |
*/ | |
function insertOak($hookName, $params) { | |
if ($this->getEnabled()) { | |
$smarty =& $params[1]; | |
$output =& $params[2]; | |
$submission =& $smarty->get_template_vars('submission'); /* @var $submission Article */ | |
// Set access values | |
$this->setHost(Config::getVar('oak', 'host')); | |
$this->setPublisherId(Config::getVar('oak', 'publisherId')); | |
$this->setPassword(Config::getVar('oak', 'password')); | |
$smarty->assign_by_ref('submission', $submission); | |
// Get the primary author | |
$authors =& $submission->getAuthors(); | |
foreach ($authors as $author) { | |
if ($author->getPrimaryContact()) { | |
$primaryAuthor =& $author; | |
} | |
} | |
// Look up the author in OAK if possible | |
$authorExists = $this->_lookupAuthor($primaryAuthor->getEmail()); | |
// If the author is not found create an author | |
if(!$authorExists) $oakId = $this->_addAuthor($primaryAuthor); | |
$smarty->assign('oakId', $oakId); | |
$smarty->assign('authorEmail', $primaryAuthor->getEmail()); | |
$smarty->assign('authorFullName', $primaryAuthor->getFullName()); | |
$output .= $smarty->fetch($this->getTemplatePath() . '/oak.tpl'); | |
return false; | |
} | |
} | |
/** | |
* Search for an author by email. | |
* @return true if found | |
*/ | |
function _lookupAuthor($email) { | |
$params = array( | |
'FindAuthor' => array( | |
'PublisherId' => '50001', | |
'Password' => 'test', | |
'SearchTerm' => $email | |
) | |
); | |
$response = $this->_makeRequest('FindAuthor', $params); | |
var_dump($response); | |
$authorArray = array(); | |
$findAuthorResult = explode(chr(10), $response->FindAuthorResult); | |
foreach($findAuthorResult AS $sAuthor) { | |
if($sAuthor != "") { | |
$sAuthor_arr = explode(";", $sAuthor); | |
$nvcAuthors[] = array($sAuthor_arr[1], $sAuthor_arr[0]); | |
} | |
} | |
if(empty($authorArray)) return false; else return true; | |
} | |
/** | |
* Create a new author | |
* @return int OAK ID | |
*/ | |
function _addAuthor($author) { | |
$params = array( | |
'CreateAuthor' => array( | |
'PublisherId' => $this->getPublisherId(), | |
'Password' => $this->getPassword(), | |
'FirstName' => $author->getFirstName(), | |
'LastName' => $author->getLastName(), | |
'Email' => $author->getEmail(), | |
'University' => $author->getLocalizedAffiliation() | |
) | |
); | |
var_dump($params); | |
$response = $this->_makeRequest('CreateAuthor', $params); | |
var_dump($response); | |
$sReturnValue = $sReturnValue_temp->CreateAuthorResult; | |
$oakId = null; | |
if(substr($sReturnValue, 0, 3) == "OK|") { | |
$oakId = str_replace("OK|", "", $sReturnValue); | |
} | |
return $oakId; | |
} | |
function _makeRequest($request, $params) { | |
//Test mode | |
$url = "http://oaktest.e-supplies.dk/publisherservice/oakpublisherservice.asmx?WSDL"; | |
// Production mode | |
//$url = 'http://www.openaccesskey.com/publisherservice/oakpublisherservice.asmx?WSDL'; | |
$options = array( | |
'soap_version' => SOAP_1_2, | |
'cache_wsdl' => WSDL_CACHE_NONE, | |
'exceptions' => true, | |
'trace' => true | |
); | |
$client = new SoapClient($url, $options); | |
return $client->__soapCall($request, $params); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment