diff --git a/classes/services/NavigationMenuService.inc.php b/classes/services/NavigationMenuService.inc.php new file mode 100644 index 00000000000..086ac32ef3f --- /dev/null +++ b/classes/services/NavigationMenuService.inc.php @@ -0,0 +1,125 @@ + array( + 'title' => __('editor.issues.currentIssue'), + 'description' => __('manager.navigationMenus.current.description'), + ), + NMI_TYPE_ARCHIVES => array( + 'title' => __('navigation.archives'), + 'description' => __('manager.navigationMenus.archives.description'), + ), + ); + + $types = array_merge($types, $ojsTypes); + } + + /** + * Callback for display menu item functionallity + */ + function getDisplayStatusCallback($hookName, $args) { + $navigationMenuItem =& $args[0]; + + $request = \Application::getRequest(); + $dispatcher = $request->getDispatcher(); + + $isUserLoggedIn = \Validation::isLoggedIn(); + $isUserLoggedInAs = \Validation::isLoggedInAs(); + $context = $request->getContext(); + $currentUser = $request->getUser(); + + $contextId = $context ? $context->getId() : CONTEXT_ID_NONE; + + // Transform an item title if the title includes a {$variable} + $templateMgr = \TemplateManager::getManager(\Application::getRequest()); + $title = $navigationMenuItem->getLocalizedTitle(); + $prefix = '{$'; + $postfix = '}'; + + $titleRepl = $title; + + $prefixPos = strpos($title, $prefix); + $postfixPos = strpos($title, $postfix); + + if ($prefixPos !== false && $postfixPos !== false && ($postfixPos - $prefixPos) > 0){ + $titleRepl = substr($title, $prefixPos + strlen($prefix), $postfixPos - $prefixPos - strlen($prefix)); + + $templateReplaceTitle = $templateMgr->get_template_vars($titleRepl); + if ($templateReplaceTitle) { + $navigationMenuItem->setTitle($templateReplaceTitle, \AppLocale::getLocale()); + } + } + + $menuItemType = $navigationMenuItem->getType(); + + // Conditionally hide some items + switch ($menuItemType) { + case NMI_TYPE_CURRENT: + case NMI_TYPE_ARCHIVES: + $navigationMenuItem->setIsDisplayed($context && $context->getSetting('publishingMode') != PUBLISHING_MODE_NONE); + break; + } + + if ($navigationMenuItem->getIsDisplayed()) { + + // Set the URL + switch ($menuItemType) { + case NMI_TYPE_CURRENT: + $navigationMenuItem->setUrl($dispatcher->url( + $request, + ROUTE_PAGE, + null, + 'issue', + 'current', + null + )); + break; + case NMI_TYPE_ARCHIVES: + $navigationMenuItem->setUrl($dispatcher->url( + $request, + ROUTE_PAGE, + null, + 'issue', + 'archive', + null + )); + break; + } + } + } +} diff --git a/classes/services/OJSServiceProvider.inc.php b/classes/services/OJSServiceProvider.inc.php index 63d2d3d44f0..02b40d95c53 100644 --- a/classes/services/OJSServiceProvider.inc.php +++ b/classes/services/OJSServiceProvider.inc.php @@ -43,7 +43,7 @@ public function register(Container $pimple) { // NavigationMenus service $pimple['navigationMenu'] = function() { - return new \PKP\Services\NavigationMenuService(); + return new NavigationMenuService(); }; } }