Skip to content
Snippets Groups Projects
Commit f2598000 authored by Chris Hallberg's avatar Chris Hallberg Committed by Robert Lange
Browse files

Use GET instead of POST in header dropdown forms (#1318)

parent 7fa38374
Branches
Tags
No related merge requests found
<?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);
}
}
<?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;
}
}
...@@ -49,13 +49,14 @@ ...@@ -49,13 +49,14 @@
<?php if (isset($this->layout()->themeOptions) && count($this->layout()->themeOptions) > 1): ?> <?php if (isset($this->layout()->themeOptions) && count($this->layout()->themeOptions) > 1): ?>
<li class="theme dropdown"> <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> <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?=$this->transEsc("Theme")?> <b class="caret"></b></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<?php foreach ($this->layout()->themeOptions as $current): ?> <?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; ?> <?php endforeach; ?>
</ul> </ul>
</li> </li>
...@@ -63,13 +64,14 @@ ...@@ -63,13 +64,14 @@
<?php if (isset($this->layout()->allLangs) && count($this->layout()->allLangs) > 1): ?> <?php if (isset($this->layout()->allLangs) && count($this->layout()->allLangs) > 1): ?>
<li class="language dropdown"> <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> <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?=$this->transEsc("Language")?> <b class="caret"></b></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<?php foreach ($this->layout()->allLangs as $langCode => $langName): ?> <?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; ?> <?php endforeach; ?>
</ul> </ul>
</li> </li>
......
...@@ -62,6 +62,7 @@ return [ ...@@ -62,6 +62,7 @@ return [
'VuFind\View\Helper\Root\TransEsc' => 'Zend\ServiceManager\Factory\InvokableFactory', 'VuFind\View\Helper\Root\TransEsc' => 'Zend\ServiceManager\Factory\InvokableFactory',
'VuFind\View\Helper\Root\Translate' => '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\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\UserList' => 'VuFind\View\Helper\Root\UserListFactory',
'VuFind\View\Helper\Root\UserTags' => 'VuFind\View\Helper\Root\UserTagsFactory', 'VuFind\View\Helper\Root\UserTags' => 'VuFind\View\Helper\Root\UserTagsFactory',
], ],
...@@ -127,6 +128,7 @@ return [ ...@@ -127,6 +128,7 @@ return [
'truncate' => 'VuFind\View\Helper\Root\Truncate', 'truncate' => 'VuFind\View\Helper\Root\Truncate',
'userlist' => 'VuFind\View\Helper\Root\UserList', 'userlist' => 'VuFind\View\Helper\Root\UserList',
'usertags' => 'VuFind\View\Helper\Root\UserTags', 'usertags' => 'VuFind\View\Helper\Root\UserTags',
'Zend\View\Helper\Url' => 'VuFind\View\Helper\Root\Url',
] ]
], ],
]; ];
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment