Skip to content

Commit

Permalink
update ojs3 publons plugin to 3.2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
huifeidepangzi committed Oct 21, 2019
1 parent 6173a8b commit 268f223
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 128 deletions.
3 changes: 2 additions & 1 deletion publons/PublonsHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function exportReview($args, $request) {
$reviewId = $reviewAssignment->getId();
$reviewFormResponseDao =& DAORegistry::getDAO('ReviewFormResponseDAO');
$reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
$reviewFormElements = $reviewFormElementDao->getReviewFormElements($reviewFormId);
$reviewFormElements = $reviewFormElementDao->getByReviewFormId($reviewFormId)->toArray();

foreach ($reviewFormElements as $reviewFormElement) if ($reviewFormElement->getIncluded()) {

Expand Down Expand Up @@ -243,6 +243,7 @@ function _curlPost($curlopt) {
$httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$httpError = curl_error($curl);
curl_close ($curl);

return array(
'status' => $httpStatus,
'result' => json_decode($httpResult, true),
Expand Down
94 changes: 71 additions & 23 deletions publons/PublonsPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
*/

import('lib.pkp.classes.plugins.GenericPlugin');
import('lib.pkp.classes.site.VersionCheck');

class PublonsPlugin extends GenericPlugin {

/**
* 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,
* @return boolean True if plugin initialized successfully; if false,
* the plugin will not be registered.
*/
function register($category, $path) {
function register($category, $path, $mainContextId = null) {

if (parent::register($category, $path)) {
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled()) {
$this->import('classes.PublonsReviews');
$this->import('classes.PublonsReviewsDAO');
Expand Down Expand Up @@ -52,7 +53,7 @@ function getName() {
/**
* Get the display name of this plugin
* @return string
* @see PKPPlugin::getDisplayName()
* @see Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.publons.displayName');
Expand All @@ -67,21 +68,53 @@ function getDescription() {
}

/**
* @see PKPPlugin::getTemplatePath()
* Get the version of OJS code
* @return string
*/
function getVersion() {
$codeVersion = VersionCheck::getCurrentCodeVersion();
return $codeVersion->getVersionString();
}

/**
* Compare the current ojs version is later than a specific version
* @return boolean
*/
function isCurrentVersionLaterThan($compareWith) {
$currentVersionNumbers = explode('.', $this->getVersion());
$compareWithVersionNumbers = explode('.', $compareWith);

foreach (range(0, sizeof($compareWithVersionNumbers)-1) as $index) {
if (intval($currentVersionNumbers[$index]) > intval($compareWithVersionNumbers[$index])) {
return true;
} elseif (intval($currentVersionNumbers[$index]) < intval($compareWithVersionNumbers[$index])) {
return false;
}
}
return false;
}

/**
* @see Plugin::getTemplatePath()
*/
function getTemplatePath($inCore = false) {
return parent::getTemplatePath() . 'templates' . DIRECTORY_SEPARATOR;
if ($this->isCurrentVersionLaterThan('3.1.1.4')) {
$bathPath = Core::getBaseDir();
return 'file:' . $bathPath . DIRECTORY_SEPARATOR . parent::getTemplatePath() . DIRECTORY_SEPARATOR;
} else {
return parent::getTemplatePath() . 'templates' . DIRECTORY_SEPARATOR;
}
}

/**
* @see PKPPlugin::getInstallSchemaFile()
* @see Plugin::getInstallSchemaFile()
* @return string
*/
function getInstallSchemaFile() {
return $this->getPluginPath() . DIRECTORY_SEPARATOR . 'schema.xml';
}

/**
/**
* Get the stylesheet for this plugin.
*/
function getStyleSheet() {
Expand Down Expand Up @@ -205,24 +238,27 @@ function handleTemplateFetch($hookName, $args) {
$templateMgr =& $args[0];
$template =& $args[1];

switch ($template) {
case 'reviewer/review/reviewCompleted.tpl':
$templateMgr->register_outputfilter(array(&$this, 'completedSubmissionOutputFilter'));
break;
case 'reviewer/review/step3.tpl':
$templateMgr->register_outputfilter(array(&$this, 'step3SubmissionOutputFilter'));
break;
default:
return false;
$filterName = '';
if ($template == 'reviewer/review/reviewCompleted.tpl'){
$filterName = 'completedSubmissionOutputFilter';
} elseif ($template == 'reviewer/review/step3.tpl') {
$filterName = 'step3SubmissionOutputFilter';
}

if ($filterName !== '') {
if ($this->isCurrentVersionLaterThan('3.1.1.4')) {
$templateMgr->registerFilter('output', array(&$this, $filterName));
} else {
$templateMgr->register_outputfilter(array(&$this, $filterName));
}
}
}

return false;
}


function step3SubmissionOutputFilter($output, &$templateMgr) {
function step3SubmissionOutputFilter($output, $templateMgr) {

$plugin =& PluginRegistry::getPlugin('generic', $this->getName());

Expand Down Expand Up @@ -257,7 +293,12 @@ function step3SubmissionOutputFilter($output, &$templateMgr) {

}

$templateMgr->unregister_outputfilter('step3SubmissionOutputFilter');
if ($this->isCurrentVersionLaterThan('3.1.1.4')) {
$templateMgr->unregisterFilter('output', 'step3SubmissionOutputFilter');
} else {
$templateMgr->unregister_outputfilter('step3SubmissionOutputFilter');
}

return $output;
}

Expand All @@ -267,7 +308,7 @@ function step3SubmissionOutputFilter($output, &$templateMgr) {
* @param $templateMgr TemplateManager
* @return $string
*/
function completedSubmissionOutputFilter($output, &$templateMgr) {
function completedSubmissionOutputFilter($output, $templateMgr) {
$plugin =& PluginRegistry::getPlugin('generic', $this->getName());

$reviewerSubmissionDao =& DAORegistry::getDAO('ReviewerSubmissionDAO');
Expand All @@ -284,7 +325,13 @@ function completedSubmissionOutputFilter($output, &$templateMgr) {
$info_url = $this->getSetting($journalId, 'info_url');

$templateMgr =& TemplateManager::getManager();
$templateMgr->unregister_outputfilter(array(&$this, 'completedSubmissionOutputFilter'));

if ($this->isCurrentVersionLaterThan('3.1.1.4')) {
$templateMgr->unregisterFilter('output', array(&$this, 'completedSubmissionOutputFilter'));
} else {
$templateMgr->unregister_outputfilter(array(&$this, 'completedSubmissionOutputFilter'));
}

$request = Application::getRequest();
$router = $request->getRouter();

Expand Down Expand Up @@ -326,10 +373,11 @@ function php5Installed() {
function curlInstalled() {
return function_exists('curl_version');
}

/**
* @see PKPPlugin::smartyPluginUrl()
* @see Plugin::smartyPluginUrl()
*/
function smartyPluginUrl($params, &$smarty) {
function smartyPluginUrl($params, $smarty) {
$path = array($this->getCategory(), $this->getName());
if (is_array($params['path'])) {
$params['path'] = array_merge($path, $params['path']);
Expand Down
51 changes: 6 additions & 45 deletions publons/classes/form/publonsSettingsForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ function PublonsSettingsForm(&$plugin, $journalId) {
$this->_journalId = $journalId;

parent::__construct($plugin->getTemplatePath() . 'publonsSettingsForm.tpl');
$this->addCheck(new FormValidator($this, 'username', FORM_VALIDATOR_REQUIRED_VALUE, 'plugins.generic.publons.settings.usernameRequired'));
$this->addCheck(new FormValidator($this, 'password', FORM_VALIDATOR_REQUIRED_VALUE, 'plugins.generic.publons.settings.passwordRequired'));
$this->addCheck(new FormValidator($this, 'auth_key', FORM_VALIDATOR_REQUIRED_VALUE, 'plugins.generic.publons.settings.authKeyRequired'));
$this->addCheck(new FormValidator($this, 'auth_token', FORM_VALIDATOR_REQUIRED_VALUE, 'plugins.generic.publons.settings.authTokenRequired'));
$this->addCheck(new FormValidator($this, 'auth_key', FORM_VALIDATOR_REQUIRED_VALUE, 'plugins.generic.publons.settings.journalTokenRequired'));
$this->addCheck(new FormValidator($this, 'info_url', FORM_VALIDATOR_OPTIONAL_VALUE, 'plugins.generic.publons.settings.invalidHelpUrl', new PublonsHelpURLFormValidator()));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
Expand All @@ -51,64 +49,26 @@ function initData() {
$journalId = $this->_journalId;

// Initialize from plugin settings
$this->setData('auth_token', $plugin->getSetting($journalId, 'auth_token'));
$this->setData('auth_key', $plugin->getSetting($journalId, 'auth_key'));
$this->setData('info_url', $plugin->getSetting($journalId, 'info_url'));
}

/**
* @see Form::readInputData()
* Reads the input data - uses the username and password to get the private
* access token for sending reviews to publons. The username and password
* are not saved.
*/
function readInputData() {
$this->readUserVars(array('auth_key', 'username', 'password', 'info_url'));
$request =& PKPApplication::getRequest();
$password = $request->getUserVar('password');

$this->setData('password', $password);

if (is_null($_SERVER["HTTP_PUBLONS_URL"])){
$url = "https://publons.com/api/v2/token/";
} else {
$url = $_SERVER["HTTP_PUBLONS_URL"]."/api/v2/token/";
}

$curlopt = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_POSTFIELDS => 'username='.$this->getData('username').'&password='.$this->getData('password')
);

$curl = curl_init();
curl_setopt_array($curl, $curlopt);

$httpResult = curl_exec($curl);
$httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$httpError = curl_error($curl);
curl_close ($curl);
$returned = array(
'status' => $httpStatus,
'result' => $httpResult,
'error' => $httpError
);

if($returned['status'] == 200) {
$token = json_decode($returned['result'], true)['token'];
$this->setData('auth_token', $token);
}
$this->readUserVars(array('auth_token', 'auth_key', 'info_url'));
}

/**
* Fetch the form.
* @copydoc Form::fetch()
*/
function fetch($request) {
function fetch($request, $template = null, $display = false) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->_plugin->getName());
return parent::fetch($request);
return parent::fetch($request, $template, $display);
}

/**
Expand All @@ -128,3 +88,4 @@ function execute() {


}
?>
18 changes: 8 additions & 10 deletions publons/locale/en_US/locale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

<locale name="en_US" full_name="U.S. English">

<message key="user.password">Password</message>
<message key="user.email">Email</message>

<message key="plugins.generic.publons.displayName">Publons Plugin</message>
Expand All @@ -34,17 +33,16 @@
<message key="plugins.generic.publons.settings.publishedTable.date.added">Date added</message>
<message key="plugins.generic.publons.settings.publishedTable.review">Review</message>
<message key="plugins.generic.publons.settings.publishedTable.noReviews">No reviews have been exported to Publons</message>
<message key="plugins.generic.publons.settings.usernameRequired">Please enter an email address which is associated with the integration token holder's account on Publons.</message>
<message key="plugins.generic.publons.settings.passwordRequired">Please enter the correct password.</message>
<message key="plugins.generic.publons.settings.authKeyRequired">Please enter the correct API key for your Publons integration.</message>
<message key="plugins.generic.publons.settings.journalTokenRequired">Please enter the correct journal token for your Publons integration.</message>
<message key="plugins.generic.publons.settings.invalidHelpUrl">Please start the url with https://publons.com</message>
<message key="plugins.generic.publons.settings.authTokenRequired">Please ensure that your email address and password are correct.</message>
<message key="plugins.generic.publons.settings.usernameDescription">The email address of the Publons account with an integration token.</message>
<message key="plugins.generic.publons.settings.passwordDescription">The password for the account specified above.</message>
<message key="plugins.generic.publons.settings.auth_tokenDescription">The Authorization token for the specified account (you can find that on https://publons.com/api/v2/ under Token).</message>
<message key="plugins.generic.publons.settings.authTokenRequired">Please ensure that your Authorization token is correct.</message>
<message key="plugins.generic.publons.settings.urlDescription">The URL of the journal landing page on Publons.</message>
<message key="plugins.generic.publons.settings.url">URL</message>
<message key="plugins.generic.publons.settings.auth_key">API Key</message>
<message key="plugins.generic.publons.settings.auth_keyDescription">The journal API key used to export reviews to Publons</message>
<message key="plugins.generic.publons.settings.journalToken">Journal Token</message>
<message key="plugins.generic.publons.settings.auth_token">Authorization Token</message>

<message key="plugins.generic.publons.settings.journalTokenDescription">The journal token used to export reviews to Publons</message>


<message key="plugins.generic.publons.confirmation.title">Send your review to Publons</message>
Expand All @@ -71,7 +69,7 @@
<message key="plugins.generic.publons.export.claimReview">Claim review</message>
<message key="plugins.generic.publons.export.next.autoClaimed">Your review has been auto-claimed on Publons.</message>
<message key="plugins.generic.publons.export.next.partnerEmailed">Your journal has emailed you with a link to claim this review or you can click on the button below.</message>
<message key="plugins.generic.publons.export.next.publonsEmailed">Publons has emailed you with a link to clain this review or you can click on the button below.</message>
<message key="plugins.generic.publons.export.next.publonsEmailed">Publons has emailed you with a link to claim this review or you can click on the button below.</message>
<message key="plugins.generic.publons.export.next.setAutoClaim">To skip this step in future please select "Automatically add reviews from partnered journals" in your Publons settings.</message>
<message key="plugins.generic.publons.export.next.linkClick">You have opted out of receiving Publons emails, to claim this review you must click the link below.</message>
<message key="plugins.generic.publons.export.backToReviewPage">Back to review page</message>
Expand Down
16 changes: 6 additions & 10 deletions publons/locale/fa_IR/locale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,19 @@
<message key="plugins.generic.publons.settings.publishedTable.review">داوری</message>
<message key="plugins.generic.publons.settings.publishedTable.noReviews">تاکنون داوری برای پابلون ارسال نشده است.
</message>
<message key="plugins.generic.publons.settings.usernameRequired">لطفا آدرس ایمیلی را وارد نمایید که در سیستم پابلون
به ثبت رسیده است.
</message>
<message key="plugins.generic.publons.settings.passwordRequired">لطفا رمز عبور خود را تصحیح نمایید.</message>
<message key="plugins.generic.publons.settings.authKeyRequired">لطفا کلید API صحیح را برای اتصال به سیستم پابلون
<message key="plugins.generic.publons.settings.auth_tokenDescription">The Authorization token for the specified account (you can find that on https://publons.com/api/v2/ under Token).</message>
<message key="plugins.generic.publons.settings.journalTokenRequired">لطفا کلید API صحیح را برای اتصال به سیستم پابلون
وارد نمایید.
</message>
<message key="plugins.generic.publons.settings.invalidHelpUrl">آدرس وارد شده می بایست با https://publons.com آغاز
گردد.
</message>
<message key="plugins.generic.publons.settings.authTokenRequired">از صحت آدرس ایمیل و رمز عبور مطمئن شوید.</message>
<message key="plugins.generic.publons.settings.usernameDescription">ایمیل حساب پابلون با توکن ادغام شد.</message>
<message key="plugins.generic.publons.settings.passwordDescription">رمز عبور برای حساب تعریف شده در بالا</message>
<message key="plugins.generic.publons.settings.authTokenRequired">Please ensure that your Authorization token is correct.</message>
<message key="plugins.generic.publons.settings.urlDescription">آدرس صفحه نشریه در سیستم پابلون</message>
<message key="plugins.generic.publons.settings.url">آدرس</message>
<message key="plugins.generic.publons.settings.auth_key">کلید API</message>
<message key="plugins.generic.publons.settings.auth_keyDescription">کلید API نشریه برای ارسال داوری ها به پابلون
<message key="plugins.generic.publons.settings.journalToken">کلید API</message>
<message key="plugins.generic.publons.settings.auth_token">Authorization Token</message>
<message key="plugins.generic.publons.settings.journalTokenDescription">کلید API نشریه برای ارسال داوری ها به پابلون
</message>
<message key="plugins.generic.publons.confirmation.title">ارسال داوری به پابلون</message>
<message key="plugins.generic.publons.confirmation.termsAndConditions">
Expand Down
Loading

0 comments on commit 268f223

Please sign in to comment.