Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.project
.buildpath
.settings
.DS_Store
.DS_Store
276 changes: 191 additions & 85 deletions DatesPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,207 @@
/**
* @file plugins/generic/dates/DatesPlugin.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2014-2026 Simon Fraser University
* Copyright (c) 2003-2026 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class dates
* @ingroup plugins_generic_dates
* Dates Plugin for OJS 3.5
*
* @brief dates plugin class
* Adds publication and editorial workflow dates
* to the public article page.
*/

use APP\core\Application;
use APP\decision\Decision;
use APP\facades\Repo;

use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;

class DatesPlugin extends GenericPlugin
{
/**
* Register the plugin
*/
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);

if ($success && $this->getEnabled($mainContextId)) {
Hook::add(
'Templates::Article::Details',
[$this, 'addDates']
);
}

return $success;
}

/**
* Plugin display name
*/
public function getDisplayName()
{
return __('plugins.generic.dates.displayName');
}

/**
* Plugin description
*/
public function getDescription()
{
return __('plugins.generic.dates.description');
}

/**
* Safe PHP 8.1+ date formatting
*/
protected function formatDate($dateString, $locale = 'en_US')
{
if (!$dateString) {
return null;
}

$timestamp = strtotime($dateString);

if (!$timestamp) {
return null;
}

$formatter = new \IntlDateFormatter(
$locale,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::NONE
);

return $formatter->format($timestamp);
}

/**
* Add article dates to template output
*/
public function addDates($hookName, $args)
{
error_log('DATES PLUGIN HOOK FIRED');

/**
* VERY IMPORTANT:
* For frontend template hooks:
*
* $args[1] = TemplateManager
* $args[2] = output (by reference)
*/
$templateMgr = $args[1];
$output =& $args[2];

$article = $templateMgr->getTemplateVars('article');
$publication = $templateMgr->getTemplateVars('publication');

class DatesPlugin extends GenericPlugin {
/**
* Called as a plugin is registered to the registry
* @param $category String Name of category plugin was registered to
* @return boolean True if plugin initialized successfully; if false,
* the plugin will not be registered.
*/
function register($category, $path, $mainContextId = NULL) {
$success = parent::register($category, $path, $mainContextId);
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return true;
if ($success && $this->getEnabled()) {
HookRegistry::register('Templates::Article::Details', array($this, 'addDates'));
}
return $success;
}

/**
* Get the plugin display name.
* @return string
*/
function getDisplayName() {
return __('plugins.generic.dates.displayName');
}

/**
* Get the plugin description.
* @return string
*/
function getDescription() {
return __('plugins.generic.dates.description');
}

/**
* Add dates to article landing page
* @param $hookName string
* @param $params array
*/
function addDates($hookName, $params) {
$request = $this->getRequest();
$context = $request->getContext();

$smarty = $params[1];
$output =& $params[2];

$article = $smarty->getTemplateVars('article');

$dates = "";
$submitdate = $article->getDateSubmitted();
$publishdate = $article->getDatePublished();
$reviewdate = "";

$decisions = Repo::decision()->getCollector()
if (!$article || !$publication) {
error_log('DATES PLUGIN: article or publication missing');
return false;
}

$request = Application::get()->getRequest();
if (!$request) {
return false;
}

$context = $request->getContext();
if (!$context) {
return false;
}

$dates = [];

/**
* Better locale handling for OJS
*/
$locale = $context->getPrimaryLocale();
if (!$locale) {
$locale = 'en_US';
}

/**
* Submitted date
*/
$dateSubmitted = $article->getData('dateSubmitted');

if ($dateSubmitted) {
$dates['submitted'] = $this->formatDate(
$dateSubmitted,
$locale
);
}

/**
* Published date
* IMPORTANT:
* This comes from publication, not article
*/
$datePublished = $publication->getData('datePublished');

if ($datePublished) {
$dates['published'] = $this->formatDate(
$datePublished,
$locale
);
}

/**
* Accepted date via editorial decisions
*/
try {
$decisions = Repo::decision()
->getCollector()
->filterBySubmissionIds([$article->getId()])
->getMany();

// Loop through the decisions
foreach ($decisions as $decision) {
// If we have a review stage decision and it was a submission accepted decision, get to date for the decision
// Note that since version 3.4 the decision value has changed from '1' to '2' for accepted
if ($decision->getData('stageId') == '3' && $decision->getData('decision') == '2'){
$reviewdate = $decision->getData('dateDecided');
}
}

$dates = array();
$dateFormatShort = PKPString::convertStrftimeFormat($context->getLocalizedDateFormatShort($locale));

if ($submitdate)
$dates['received'] = date($dateFormatShort,strtotime($submitdate));
if ($reviewdate)
$dates['accepted'] = date($dateFormatShort,strtotime($reviewdate));
if ($publishdate)
$dates['published'] = date($dateFormatShort,strtotime($publishdate));

// Only show dates if there was a review
if ($reviewdate){
$smarty->assign('dates', $dates);
$output .= $smarty->fetch($this->getTemplateResource('dates.tpl'));
}
return false;
}
}
foreach ($decisions as $decision) {
if (
(int) $decision->getData('decision')
=== (int) Decision::ACCEPT
) {
$dates['accepted'] = $this->formatDate(
$decision->getData('dateDecided'),
$locale
);
break;
}
}
} catch (\Throwable $e) {
/**
* Never break article rendering because of plugin issues
*/
error_log(
'DatesPlugin decision lookup failed: '
. $e->getMessage()
);
}

/**
* Debug log
*/
error_log(
'DATES PLUGIN DATA: ' . print_r($dates, true)
);

?>
/**
* Assign to Smarty
*/
$templateMgr->assign(
'datesPluginDates',
$dates
);

/**
* THIS is the crucial part:
* append rendered template output
*/
$output .= $templateMgr->fetch(
$this->getTemplateResource('dates.tpl')
);

return false;
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Dates plugin for OJS 3.4
# Dates plugin for OJS 3.5.0.4 / PHP 8.4

Display Received, Accepted and Published dates on the article landing page.

Once enabled the plugin will show the dates automatically for all published articles if a Review Accepted decision can be found for the submission.

***
Plugin created by The Federation of Finnish Learned Societies (https://tsv.fi/en/).
Updated by SOAP | Stichting OpenAccess platforms
***
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/**
* @file plugins/generic/dates/index.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2014-2026 Simon Fraser University
* Copyright (c) 2003-2026 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @ingroup plugins_generic_dates
Expand Down
4 changes: 2 additions & 2 deletions locale/en/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ msgid ""
msgstr ""

"plugins/generic/dates/locale/en_US/locale.po
"Copyright (c) 2014-2021 Simon Fraser University
"Copyright (c) 2003-2021 John Willinsky
"Copyright (c) 2014-2026 Simon Fraser University
"Copyright (c) 2003-2026 John Willinsky
"Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
"dates plugin localization strings

Expand Down
4 changes: 2 additions & 2 deletions locale/es/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ msgid ""
msgstr ""

"plugins/generic/dates/locale/es_ES/locale.po
"Copyright (c) 2014-2021 Simon Fraser University
"Copyright (c) 2003-2021 John Willinsky
"Copyright (c) 2014-2026 Simon Fraser University
"Copyright (c) 2003-2026 John Willinsky
"Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
"dates plugin localization strings

Expand Down
4 changes: 2 additions & 2 deletions locale/fi/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ msgid ""
msgstr ""

"plugins/generic/dates/locale/fi/locale.po
"Copyright (c) 2014-2021 Simon Fraser University
"Copyright (c) 2003-2021 John Willinsky
"Copyright (c) 2014-2026 Simon Fraser University
"Copyright (c) 2003-2026 John Willinsky
"Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
"dates plugin localization strings

Expand Down
4 changes: 2 additions & 2 deletions locale/it/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ msgid ""
msgstr ""

"plugins/generic/dates/locale/it_IT/locale.po
"Copyright (c) 2014-2021 Simon Fraser University
"Copyright (c) 2003-2021 John Willinsky
"Copyright (c) 2014-2026 Simon Fraser University
"Copyright (c) 2003-2026 John Willinsky
"Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
"dates plugin localization strings

Expand Down
Loading