diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Url.php b/module/VuFind/src/VuFind/View/Helper/Root/Url.php new file mode 100644 index 0000000000000000000000000000000000000000..691aa6df74e594422ff23978b506acd2bbc72c75 --- /dev/null +++ b/module/VuFind/src/VuFind/View/Helper/Root/Url.php @@ -0,0 +1,102 @@ +<?php +/** + * Url view helper (extending core Zend helper with additional functionality) + * + * PHP version 7 + * + * Copyright (C) Villanova University 2019. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package View_Helpers + * @author Chris Hallberg <challber@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\View\Helper\Root; + +use Zend\Http\PhpEnvironment\Request; + +/** + * Url view helper (extending core Zend helper with additional functionality) + * + * @category VuFind + * @package View_Helpers + * @author Chris Hallberg <challber@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class Url extends \Zend\View\Helper\Url +{ + /** + * Request (or null if unavailable) + * + * @var Request + */ + protected $request = null; + + /** + * Constructor + * + * @param Request $request Request object for GET parameters + */ + public function __construct(Request $request) + { + $this->request = $request; + } + + /** + * Generates a url given the name of a route. + * + * @param string $name Name of the route + * @param array $params Parameters for the link + * @param array|Traversable $options Options for the route + * @param bool $reuseMatchedParams Whether to reuse matched + * parameters + * + * @see Zend\Mvc\Router\RouteInterface::assemble() + * @see Zend\Router\RouteInterface::assemble() + * + * @throws Exception\RuntimeException If no RouteStackInterface was + * provided + * @throws Exception\RuntimeException If no RouteMatch was provided + * @throws Exception\RuntimeException If RouteMatch didn't contain a + * matched route name + * @throws Exception\InvalidArgumentException If the params object was not + * an array or Traversable object. + * + * @return string Url For the link href attribute + */ + public function __invoke( + $name = null, $params = [], $options = [], $reuseMatchedParams = false + ) { + // If argument list is empty, return object for method access: + return func_num_args() == 0 ? $this : parent::__invoke(...func_get_args()); + } + + /** + * Get URL with current GET parameters and add one + * + * @param array $params Key-paired parameters + * + * @return string + */ + public function addQueryParameters($params) + { + $requestQuery = $this->request->getQuery()->toArray(); + $options = ['query' => array_merge($requestQuery, $params)]; + return $this->__invoke(null, [], $options); + } +} diff --git a/module/VuFind/src/VuFind/View/Helper/Root/UrlFactory.php b/module/VuFind/src/VuFind/View/Helper/Root/UrlFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..7ed0162d34e8f5402baa51e5f9f91fe2be25492b --- /dev/null +++ b/module/VuFind/src/VuFind/View/Helper/Root/UrlFactory.php @@ -0,0 +1,75 @@ +<?php +/** + * Url helper factory. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2019. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package View_Helpers + * @author Chris Hallberg <challber@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace VuFind\View\Helper\Root; + +use Interop\Container\ContainerInterface; +use Zend\Router\RouteMatch; +use Zend\ServiceManager\Factory\FactoryInterface; + +/** + * Url helper factory. + * + * @category VuFind + * @package View_Helpers + * @author Chris Hallberg <challber@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class UrlFactory implements FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + $helper = new $requestedName($container->get('Request')); + $helper->setRouter($container->get('HttpRouter')); + + $match = $container->get('Application') + ->getMvcEvent() + ->getRouteMatch(); + + if ($match instanceof RouteMatch) { + $helper->setRouteMatch($match); + } + + return $helper; + } +} diff --git a/themes/bootstrap3/templates/header.phtml b/themes/bootstrap3/templates/header.phtml index 838b40a33ac1560523f26e281e54d2bf1aeb52ca..fdb62ccc66767fe7524da7ef8fc38018a428885e 100644 --- a/themes/bootstrap3/templates/header.phtml +++ b/themes/bootstrap3/templates/header.phtml @@ -49,13 +49,14 @@ <?php if (isset($this->layout()->themeOptions) && count($this->layout()->themeOptions) > 1): ?> <li class="theme dropdown"> - <form method="post" name="themeForm" id="themeForm"> - <input type="hidden" name="ui"/> - </form> <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?=$this->transEsc("Theme")?> <b class="caret"></b></a> <ul class="dropdown-menu"> <?php foreach ($this->layout()->themeOptions as $current): ?> - <li<?=$current['selected'] ? ' class="active"' : ''?>><a href="#" onClick="document.themeForm.ui.value='<?=$this->escapeHtmlAttr($current['name'])?>';document.themeForm.submit()"><?=$this->transEsc($current['desc'])?></a></li> + <li<?=$current['selected'] ? ' class="active"' : ''?>> + <a href="<?=$this->escapeHtmlAttr($this->url()->addQueryParameters(['ui' => $current['name']])) ?>" rel="nofollow"> + <?=$this->transEsc($current['desc']) ?> + </a> + </li> <?php endforeach; ?> </ul> </li> @@ -63,13 +64,14 @@ <?php if (isset($this->layout()->allLangs) && count($this->layout()->allLangs) > 1): ?> <li class="language dropdown"> - <form method="post" name="langForm" id="langForm"> - <input type="hidden" name="mylang"/> - </form> <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?=$this->transEsc("Language")?> <b class="caret"></b></a> <ul class="dropdown-menu"> <?php foreach ($this->layout()->allLangs as $langCode => $langName): ?> - <li<?=$this->layout()->userLang == $langCode ? ' class="active"' : ''?>><a href="#" onClick="document.langForm.mylang.value='<?=$langCode?>';document.langForm.submit()"><?=$this->displayLanguageOption($langName)?></a></li> + <li<?=$this->layout()->userLang == $langCode ? ' class="active"' : ''?>> + <a href="<?=$this->escapeHtmlAttr($this->url()->addQueryParameters(['lng' => $langCode])) ?>" rel="nofollow"> + <?=$this->displayLanguageOption($langName) ?> + </a> + </li> <?php endforeach; ?> </ul> </li> diff --git a/themes/root/theme.config.php b/themes/root/theme.config.php index 09708f831c049f2a97426bd06df83e2578c4f0f0..6171c431d317ae9afd6f755694e2f534a797789e 100644 --- a/themes/root/theme.config.php +++ b/themes/root/theme.config.php @@ -62,6 +62,7 @@ return [ 'VuFind\View\Helper\Root\TransEsc' => 'Zend\ServiceManager\Factory\InvokableFactory', 'VuFind\View\Helper\Root\Translate' => 'Zend\ServiceManager\Factory\InvokableFactory', 'VuFind\View\Helper\Root\Truncate' => 'Zend\ServiceManager\Factory\InvokableFactory', + 'VuFind\View\Helper\Root\Url' => 'VuFind\View\Helper\Root\UrlFactory', 'VuFind\View\Helper\Root\UserList' => 'VuFind\View\Helper\Root\UserListFactory', 'VuFind\View\Helper\Root\UserTags' => 'VuFind\View\Helper\Root\UserTagsFactory', ], @@ -127,6 +128,7 @@ return [ 'truncate' => 'VuFind\View\Helper\Root\Truncate', 'userlist' => 'VuFind\View\Helper\Root\UserList', 'usertags' => 'VuFind\View\Helper\Root\UserTags', + 'Zend\View\Helper\Url' => 'VuFind\View\Helper\Root\Url', ] ], ];