diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 0622661cee521d38e27988954a47083e58a0fdbb..3f9b3c490cb643d07a57e277c66b9ff435e7be0f 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -97,6 +97,8 @@ showBookBag = false bookBagMaxSize = 100 ; Display bulk items (export, save, etc.) and checkboxes on search result screens? showBulkOptions = false +; Should users be allowed to save searches in their accounts? +allowSavedSearches = true ; Generator value to display in an HTML header <meta> tag: generator = "VuFind 2.5" diff --git a/module/VuFind/src/VuFind/Config/AccountCapabilities.php b/module/VuFind/src/VuFind/Config/AccountCapabilities.php index 50108eee7a2044bfee0af29b0263683674891eeb..74b9cadee8c82c19be281b467f55fedbb4979ce9 100644 --- a/module/VuFind/src/VuFind/Config/AccountCapabilities.php +++ b/module/VuFind/src/VuFind/Config/AccountCapabilities.php @@ -89,6 +89,18 @@ class AccountCapabilities return $setting; } + /** + * Get saved search setting. + * + * @return string + */ + public function getSavedSearchSetting() + { + return isset($this->config->Site->allowSavedSearches) + && !$this->config->Site->allowSavedSearches + ? 'disabled' : 'enabled'; + } + /** * Get tag setting. * diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index d69baad7771154b61d1a883ac8a9a46ca25111b4..0ab2057c642727285a6ab1724f90ce0f89dab7dc 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -284,6 +284,12 @@ class MyResearchController extends AbstractBase */ public function savesearchAction() { + // Fail if saved searches are disabled. + $check = $this->getServiceLocator()->get('VuFind\AccountCapabilities'); + if ($check->getSavedSearchSetting() === 'disabled') { + throw new \Exception('Saved searches disabled.'); + } + $user = $this->getUser(); if ($user == false) { return $this->forceLogin(); diff --git a/module/VuFind/src/VuFind/View/Helper/Root/AccountCapabilities.php b/module/VuFind/src/VuFind/View/Helper/Root/AccountCapabilities.php new file mode 100644 index 0000000000000000000000000000000000000000..8e86605c31643373429f4d8f07f12eedc23153b9 --- /dev/null +++ b/module/VuFind/src/VuFind/View/Helper/Root/AccountCapabilities.php @@ -0,0 +1,68 @@ +<?php +/** + * AccountCapabilities view helper + * + * PHP version 5 + * + * Copyright (C) Villanova University 2015. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package View_Helpers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +namespace VuFind\View\Helper\Root; +use VuFind\Config\AccountCapabilities as Helper; + +/** + * AccountCapabilities view helper + * + * @category VuFind2 + * @package View_Helpers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +class AccountCapabilities extends \Zend\View\Helper\AbstractHelper +{ + /** + * Capabilities helper + * + * @var Helper + */ + protected $helper; + + /** + * Constructor + * + * @param Helper $connection Capabilities helper + */ + public function __construct(Helper $helper) + { + $this->helper = $helper; + } + + /** + * Get the capabilities helper. + * + * @return Helper + */ + public function __invoke() + { + return $this->helper; + } +} \ No newline at end of file diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php index b59993d75a57fb125546ba6cdad13941d7b648dc..12769c3fe1259eaf1c3c9147222b92f8bee7308a 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php @@ -56,6 +56,20 @@ class Factory ); } + /** + * Construct the AccountCapabilities helper. + * + * @param ServiceManager $sm Service manager. + * + * @return AccountCapabilities + */ + public static function getAccountCapabilities(ServiceManager $sm) + { + return new AccountCapabilities( + $sm->getServiceLocator()->get('VuFind\AccountCapabilities') + ); + } + /** * Construct the AlphaBrowse helper. * diff --git a/themes/bootstrap3/templates/myresearch/menu.phtml b/themes/bootstrap3/templates/myresearch/menu.phtml index d56da0d5d197ae45279b4b2c319eba3c1ad163af..14ebab3eb0f7449170c55946ecb18fe73f8cdb16 100644 --- a/themes/bootstrap3/templates/myresearch/menu.phtml +++ b/themes/bootstrap3/templates/myresearch/menu.phtml @@ -50,10 +50,12 @@ </a> <? endif; ?> <? endif; ?> - <a href="<?=$this->url('search-history')?>?require_login" class="list-group-item<?=$this->active == 'history' ? ' active' : ''?>"> - <?=$this->transEsc('history_saved_searches')?> - <span class="pull-right flip"><i class="fa fa-fw fa-search"></i></span> - </a> + <? if ($this->accountCapabilities()->getSavedSearchSetting() === 'enabled'): ?> + <a href="<?=$this->url('search-history')?>?require_login" class="list-group-item<?=$this->active == 'history' ? ' active' : ''?>"> + <?=$this->transEsc('history_saved_searches')?> + <span class="pull-right flip"><i class="fa fa-fw fa-search"></i></span> + </a> + <? endif; ?> <? if ($user = $this->auth()->isLoggedIn()): ?> <a href="<?=$this->url('myresearch-logout')?>" class="list-group-item"> <?=$this->transEsc("Log Out")?> diff --git a/themes/bootstrap3/templates/search/history-table.phtml b/themes/bootstrap3/templates/search/history-table.phtml index 9a3fa5f18369342eb523f9abf9d7faffdd38388b..9daf184a3e2e8ae507d709d41cd5a6cb75077df2 100644 --- a/themes/bootstrap3/templates/search/history-table.phtml +++ b/themes/bootstrap3/templates/search/history-table.phtml @@ -1,10 +1,11 @@ +<? $saveSupported = $this->accountCapabilities()->getSavedSearchSetting() === 'enabled'; ?> <table class="table table-striped"> <tr> <th width="20%"><?=$this->transEsc("history_time")?></th> <th><?=$this->transEsc("history_search")?></th> <th><?=$this->transEsc("history_limits")?></th> <th><?=$this->transEsc("history_results")?></th> - <th><?=$this->transEsc($this->showSaved ? "history_delete" : "history_save")?></th> + <? if ($saveSupported): ?><th><?=$this->transEsc($this->showSaved ? "history_delete" : "history_save")?></th><? endif; ?> </tr> <? foreach (($this->showSaved ? array_reverse($this->saved) : array_reverse($this->unsaved)) as $iteration => $info): ?> <tr class="<?=$iteration % 2 == 1 ? 'even' : 'odd'?>row"> @@ -25,13 +26,15 @@ <? endforeach; ?> </td> <td><?=$this->escapeHtml($this->localizedNumber($info->getResultTotal()))?></td> - <td> - <? if ($this->showSaved): ?> - <a href="<?=$this->url('myresearch-savesearch')?>?delete=<?=urlencode($info->getSearchId())?>&mode=history"><i class="fa fa-remove"></i> <?=$this->transEsc("history_delete_link")?></a> - <? else: ?> - <a href="<?=$this->url('myresearch-savesearch')?>?save=<?=urlencode($info->getSearchId())?>&mode=history"><i class="fa fa-save"></i> <?=$this->transEsc("history_save_link")?></a> - <? endif; ?> - </td> + <? if ($saveSupported): ?> + <td> + <? if ($this->showSaved): ?> + <a href="<?=$this->url('myresearch-savesearch')?>?delete=<?=urlencode($info->getSearchId())?>&mode=history"><i class="fa fa-remove"></i> <?=$this->transEsc("history_delete_link")?></a> + <? else: ?> + <a href="<?=$this->url('myresearch-savesearch')?>?save=<?=urlencode($info->getSearchId())?>&mode=history"><i class="fa fa-save"></i> <?=$this->transEsc("history_save_link")?></a> + <? endif; ?> + </td> + <? endif; ?> </tr> <? endforeach; ?> </table> diff --git a/themes/bootstrap3/templates/search/history.phtml b/themes/bootstrap3/templates/search/history.phtml index efec1177841711b2ac190dab5c52e034e135243a..39f4e36a2090408ed2968cd14f2ca7e1d07e0614 100644 --- a/themes/bootstrap3/templates/search/history.phtml +++ b/themes/bootstrap3/templates/search/history.phtml @@ -5,11 +5,13 @@ // Set up breadcrumbs: $this->layout()->breadcrumbs = '<li><a href="' . $this->url('myresearch-home') . '">' . $this->transEsc('Your Account') . '</a></li>' . '<li class="active">' . $this->transEsc('History') . '</li>'; + + $saveSupported = $this->accountCapabilities()->getSavedSearchSetting() === 'enabled'; ?> <div class="row"> <div class="<?=$this->layoutClass('mainbody')?>"> - <? if (!empty($this->saved)): ?> + <? if ($saveSupported && !empty($this->saved)): ?> <h2><?=$this->transEsc("history_saved_searches")?></h2> <?=$this->context()->renderInContext('search/history-table.phtml', array('showSaved' => true));?> <? endif; ?> @@ -23,12 +25,14 @@ <? endif; ?> </div> - <div class="<?=$this->layoutClass('sidebar')?>"> - <?=$this->context($this)->renderInContext( - "myresearch/menu.phtml", - // Only activate search history in account menu if user is logged in. - $this->auth()->isLoggedIn() ? array('active' => 'history') : array() - ); - ?> - </div> + <? if ($saveSupported): ?> + <div class="<?=$this->layoutClass('sidebar')?>"> + <?=$this->context($this)->renderInContext( + "myresearch/menu.phtml", + // Only activate search history in account menu if user is logged in. + $this->auth()->isLoggedIn() ? array('active' => 'history') : array() + ); + ?> + </div> + <? endif; ?> </div> \ No newline at end of file diff --git a/themes/bootstrap3/templates/search/results.phtml b/themes/bootstrap3/templates/search/results.phtml index 1ed0fdced7d384e5620f1b5222bcddb5b996a6d8..97930e8618d8c6ea8752a20a8f09fe7550a11a82 100644 --- a/themes/bootstrap3/templates/search/results.phtml +++ b/themes/bootstrap3/templates/search/results.phtml @@ -111,7 +111,7 @@ <a href="<?=$this->results->getUrlQuery()->setViewParam('rss')?>"><i class="fa fa-bell"></i> <?=$this->transEsc('Get RSS Feed')?></a> — <a href="<?=$this->url('search-email')?>" class="mailSearch modal-link" id="mailSearch<?=$this->escapeHtmlAttr($this->results->getSearchId())?>" title="<?=$this->transEsc('Email this Search')?>"><i class="fa fa-envelope"></i> <?=$this->transEsc('Email this Search')?></a> - <? if (($account = $this->auth()->getManager()) && $account->loginEnabled()): // hide save option if login disabled ?> + <? if ($this->accountCapabilities()->getSavedSearchSetting() === 'enabled'): ?> — <? if (is_numeric($this->results->getSearchId())): ?> <? if ($this->results->isSavedSearch()): ?> diff --git a/themes/jquerymobile/templates/search/header-navbar.phtml b/themes/jquerymobile/templates/search/header-navbar.phtml index eb7daaad86cae7d632ce6264996102865101a52f..6bb71b162e2d3a2078a283ea10b23f5ec95614a6 100644 --- a/themes/jquerymobile/templates/search/header-navbar.phtml +++ b/themes/jquerymobile/templates/search/header-navbar.phtml @@ -4,7 +4,7 @@ <div data-role="navbar"> <ul> <li><a href="#Search-narrow" data-rel="dialog" data-transition="flip"><?=$this->transEsc('Narrow Search')?></a></li> - <? if (($account = $this->auth()->getManager()) && $account->loginEnabled()): // hide save option if login disabled ?> + <? if ($this->accountCapabilities()->getSavedSearchSetting() === 'enabled'): ?> <li> <? if (isset($this->results) && is_numeric($this->results->getSearchId())): ?> <? if ($this->results->isSavedSearch()): ?> diff --git a/themes/jquerymobile/templates/search/history-table.phtml b/themes/jquerymobile/templates/search/history-table.phtml index 24b1f3925602d17d99fa16f95addae8960355f52..c43cabf5643df5824d5ef8f76311318a7e319e56 100644 --- a/themes/jquerymobile/templates/search/history-table.phtml +++ b/themes/jquerymobile/templates/search/history-table.phtml @@ -1,3 +1,4 @@ +<? $saveSupported = $this->accountCapabilities()->getSavedSearchSetting() === 'enabled'; ?> <? foreach (($this->showSaved ? array_reverse($this->saved) : array_reverse($this->unsaved)) as $iteration => $info): ?> <li> <a rel="external" href="<?=$this->url($info->getOptions()->getSearchAction()) . $info->getUrlQuery()->getParams()?>"> @@ -16,10 +17,12 @@ <? endforeach; ?> </div> </a> - <? if ($this->showSaved): ?> - <a rel="external" href="<?=$this->url('myresearch-savesearch')?>?delete=<?=urlencode($info->getSearchId())?>&mode=history" class="delete"><?=$this->transEsc("history_delete_link")?></a> - <? else: ?> - <a rel="external" href="<?=$this->url('myresearch-savesearch')?>?save=<?=urlencode($info->getSearchId())?>&mode=history" class="add"><?=$this->transEsc("history_save_link")?></a> + <? if ($saveSupported): ?> + <? if ($this->showSaved): ?> + <a rel="external" href="<?=$this->url('myresearch-savesearch')?>?delete=<?=urlencode($info->getSearchId())?>&mode=history" class="delete"><?=$this->transEsc("history_delete_link")?></a> + <? else: ?> + <a rel="external" href="<?=$this->url('myresearch-savesearch')?>?save=<?=urlencode($info->getSearchId())?>&mode=history" class="add"><?=$this->transEsc("history_save_link")?></a> + <? endif; ?> <? endif; ?> </li> <? endforeach; ?> \ No newline at end of file diff --git a/themes/jquerymobile/templates/search/history.phtml b/themes/jquerymobile/templates/search/history.phtml index e9e9ea37a3f165940428e4be0c3fb779f6e64839..66d3f206bbbabbe676dba43103fb329131007110 100644 --- a/themes/jquerymobile/templates/search/history.phtml +++ b/themes/jquerymobile/templates/search/history.phtml @@ -1,6 +1,11 @@ <? // Set page title. $this->headTitle($this->translate('Search History')); + + $saveSupported = $this->accountCapabilities()->getSavedSearchSetting() === 'enabled'; + if (!$saveSupported) { + $this->saved = []; + } ?> <div data-role="page" id="Search-history"> <?=$this->mobileMenu()->header()?> diff --git a/themes/root/theme.config.php b/themes/root/theme.config.php index 16488fec1f1871deeb6a10a61e7e5b7ddf118a58..41041b6f7f4c31f33f6c5577a0c277846f58a9c3 100644 --- a/themes/root/theme.config.php +++ b/themes/root/theme.config.php @@ -3,6 +3,7 @@ return array( 'extends' => false, 'helpers' => array( 'factories' => array( + 'accountcapabilities' => 'VuFind\View\Helper\Root\Factory::getAccountCapabilities', 'addthis' => 'VuFind\View\Helper\Root\Factory::getAddThis', 'alphabrowse' => 'VuFind\View\Helper\Root\Factory::getAlphaBrowse', 'auth' => 'VuFind\View\Helper\Root\Factory::getAuth',