| Server IP : 195.134.90.114 / Your IP : 216.73.216.86 Web Server : Apache/2.4.58 System : Linux nepub 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/public_html/plugins/generic/browseBySection/pages/ |
Upload File : |
<?php
/**
* @file plugins/generic/browseBySection/pages/BrowseBySectionHandler.inc.php
*
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
*
* @class BrowseBySectionHandler
* @ingroup plugins_generic_browsebysection
*
* @brief Handle reader-facing router requests for the browse by section plugin
*/
import('classes.handler.Handler');
class BrowseBySectionHandler extends Handler {
/**
* @copydoc PKPHandler::authorize()
*/
function authorize($request, &$args, $roleAssignments) {
import('lib.pkp.classes.security.authorization.ContextRequiredPolicy');
$this->addPolicy(new ContextRequiredPolicy($request));
import('classes.security.authorization.OjsJournalMustPublishPolicy');
$this->addPolicy(new OjsJournalMustPublishPolicy($request));
return parent::authorize($request, $args, $roleAssignments);
}
/**
* View a section
*
* @param $args array [
* @option string Section ID
* @option string page number
* ]
* @param $request PKPRequest
* @return null|JSONMessage
*/
public function view($args, $request) {
$sectionPath = $args[0] ?? null;
$page = isset($args[1]) && ctype_digit($args[1]) ? (int) $args[1] : 1;
$context = $request->getContext();
$contextId = $context ? $context->getId() : CONTEXT_ID_NONE;
// The page $arg can only contain an integer that's not 1. The first page
// URL does not include page $arg
if (isset($args[1]) && (!ctype_digit($args[1]) || $args[1] == 1)) {
$request->getDispatcher()->handle404();
exit;
}
if (!$sectionPath || !$contextId) {
$request->getDispatcher()->handle404();
exit;
}
$sectionDao = DAORegistry::getDAO('SectionDAO');
$sections = $sectionDao->getByContextId($contextId);
$sectionExists = false;
while ($section = $sections->next()) {
if ($section->getData('browseByEnabled') && $section->getData('browseByPath') === $sectionPath) {
$sectionExists = true;
break;
}
}
if (!$sectionExists) {
$request->getDispatcher()->handle404();
exit;
}
$browseByPerPage = $section->getData('browseByPerPage');
if (empty($browseByPerPage)) {
$browseByPerPage = BROWSEBYSECTION_DEFAULT_PER_PAGE;
}
$browseByOrder = $section->getData('browseByOrder');
// ordering defaults to datePublished DESC for backwards compatibility (if option is unset)
if (strpos($browseByOrder, 'title') !== false) {
$orderBy = 'title';
} else {
$orderBy = 'datePublished';
}
if (strpos($browseByOrder, 'Asc') !== false) {
$orderDir = 'ASC';
} else {
$orderDir = 'DESC';
}
import('classes.submission.Submission'); // Import status constants
$params = [
'contextId' => $contextId,
'count' => $browseByPerPage,
'offset' => $page ? ($page - 1) * $browseByPerPage : 0,
'orderBy' => $orderBy,
'orderDirection' => $orderDir,
'sectionIds' => [(int) $section->getId()],
'status' => STATUS_PUBLISHED,
];
$submissionsIterator = Services::get('submission')->getMany($params);
$total = Services::get('submission')->getMax($params);
if ($page > 1 && !count($submissionsIterator)) {
$request->getDispatcher()->handle404();
exit;
}
$articleGroups = [];
$submissions = [];
$issueIds = [];
foreach ($submissionsIterator as $submission) {
$submissions[] = $submission;
if ($submission->getCurrentPublication()->getData('issueId')) {
$issueIds[] = $submission->getCurrentPublication()->getData('issueId');
}
}
if ($orderBy === 'title') {
// segment groups alphabetically
$key = '';
$group = [];
foreach ($submissions as $article) {
$newkey = mb_substr($article->getLocalizedTitle(), 0, 1);
if ($newkey !== $key) {
if (count($group)) {
$articleGroups[] = ['key' => $key, 'articles' => $group];
}
$group = [];
$key = $newkey;
}
$group[] = $article;
}
if (count($group)) {
$articleGroups[] = ['key' => $key, 'articles' => $group];
}
} else {
// one continuous group
$articleGroups[] = ['key' => null, 'articles' => $submissions];
}
$issuesIterator = Services::get('issue')->getMany([
'contextId' => $contextId,
'isPublished' => true,
'issueIds' => array_unique($issueIds),
]);
$issues = iterator_to_array($issuesIterator);
$showingStart = $params['offset'] + 1;
$showingEnd = min($params['offset'] + $params['count'], $params['offset'] + count($submissions));
$nextPage = $total > $showingEnd ? $page + 1 : null;
$prevPage = $showingStart > 1 ? $page - 1 : null;
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign([
'section' => $section,
'sectionPath' => $sectionPath,
'sectionDescription' => $section->getLocalizedData('browseByDescription'),
'articleGroups' => $articleGroups,
'issues' => $issues,
'showingStart' => $showingStart,
'showingEnd' => $showingEnd,
'total' => $total,
'nextPage' => $nextPage,
'prevPage' => $prevPage,
]);
$plugin = PluginRegistry::getPlugin('generic', 'browsebysectionplugin');
return $templateMgr->display($plugin->getTemplateResource('frontend/pages/section.tpl'));
}
}