Hi there! A few colleagues and I have recently started a new journal, and we’re using the “Hypothesis” plugin to enable comments on papers, but we’re using the “Announcements” section as something of a blog to announce new things in the field, and post blogs from the editorial board. However, we can’t seem to find any way to add the possibility for comments on Announcements. Is there some way to add this functionality? Thank you all!
Hi again: does anyone know of a plugin to make this possible? Thanks! Or whether it would be possible to hire and pay someone to make it possible? We’re very new to this whole thing!
The current Hypothes.is
plugin uses one specific hook to load:
import('lib.pkp.classes.plugins.GenericPlugin');
class HypothesisPlugin extends GenericPlugin {
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null) {
if (parent::register($category, $path, $mainContextId)) {
HookRegistry::register('ArticleHandler::download',array(&$this, 'callback'));
return true;
}
return false;
}
/**
* Hook callback function for TemplateManager::display
* @param $hookName string
* @param $args array
* @return boolean
This hook is implemented here:
$fileId = $submissionFile->getFileId();
// The file manager expects the real article id. Extract it from the submission file.
$articleId = $submissionFile->getSubmissionId();
} else { // no proof files assigned to this galley!
header('HTTP/1.0 403 Forbidden');
echo '403 Forbidden<br>';
return;
}
}
if (!HookRegistry::call('ArticleHandler::download', array($this->article, &$this->galley, &$fileId))) {
import('lib.pkp.classes.file.SubmissionFileManager');
$submissionFileManager = new SubmissionFileManager($this->article->getContextId(), $this->article->getId());
$submissionFileManager->downloadById($fileId, null, $request->getUserVar('inline')?true:false);
}
} else {
header('HTTP/1.0 403 Forbidden');
echo '403 Forbidden<br>';
}
}
There is not a directly parallel hook in the AnnouncementsHandler
:
But, hook on the display of “frontend/pages/announcement.tpl” could be easily integrated via the TemplateManager::display
hook.
$this->setupTemplate($request);
$context = $request->getContext();
$announcementId = (int) array_shift($args);
$announcementDao = DAORegistry::getDAO('AnnouncementDAO');
$announcement = $announcementDao->getById($announcementId);
if ($announcement && $announcement->getAssocType() == Application::getContextAssocType() && $announcement->getAssocId() == $context->getId() && ($announcement->getDateExpire() == null || strtotime($announcement->getDateExpire()) > time())) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('announcement', $announcement);
$templateMgr->assign('announcementTitle', $announcement->getLocalizedTitleFull());
return $templateMgr->display('frontend/pages/announcement.tpl');
}
$request->redirect(null, 'announcement');
}
}
Currently the hypothes.is plugin also explicitly checks to ensure a galley is being viewed, which would not be the case with an announcement:
}
/**
* Hook callback function for TemplateManager::display
* @param $hookName string
* @param $args array
* @return boolean
*/
function callback($hookName, $args) {
$galley =& $args[1];
if (!$galley || $galley->getFileType() != 'text/html') return false;
ob_start(function($buffer) {
return str_replace('<head>', '<head><script async defer src="//hypothes.is/embed.js"></script>', $buffer);
});
return false;
}
/**
* Get the display name of this plugin
In all, if you have someone handy with PHP, I suspect it would not be a terribly complicated feature to implement.
This is so helpful, thank you! Now to find that person…