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/config/module.config.php b/module/VuFind/config/module.config.php index 48493d709d9b63e81dbbbc1ba8117d3a1e6acd53..58d150d96bd724355317504e02f0a0340ac2b595 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -129,6 +129,7 @@ $config = [ 'service_manager' => [ 'allow_override' => true, 'factories' => [ + 'VuFind\AccountCapabilities' => 'VuFind\Service\Factory::getAccountCapabilities', 'VuFind\AuthManager' => 'VuFind\Auth\Factory::getManager', 'VuFind\AuthPluginManager' => 'VuFind\Service\Factory::getAuthPluginManager', 'VuFind\AutocompletePluginManager' => 'VuFind\Service\Factory::getAutocompletePluginManager', diff --git a/module/VuFind/src/VuFind/Config/AccountCapabilities.php b/module/VuFind/src/VuFind/Config/AccountCapabilities.php new file mode 100644 index 0000000000000000000000000000000000000000..9efc100b9679e6b70b1ce63044d127f9987cb39c --- /dev/null +++ b/module/VuFind/src/VuFind/Config/AccountCapabilities.php @@ -0,0 +1,147 @@ +<?php +/** + * Class to determine which account capabilities are available, based on + * configuration and other factors. + * + * 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 Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +namespace VuFind\Config; +use VuFind\Auth\Manager as AuthManager; +use Zend\Config\Config; + +/** + * Class to determine which account capabilities are available, based on + * configuration and other factors. + * + * @category VuFind2 + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +class AccountCapabilities +{ + /** + * Auth manager + * + * @var AuthManager + */ + protected $auth; + + /** + * VuFind configuration + * + * @var Config + */ + protected $config; + + /** + * Constructor + * + * @param Config $config VuFind configuration + * @param AuthManager $auth Auth manager + */ + public function __construct(Config $config, AuthManager $auth) + { + $this->auth = $auth; + $this->config = $config; + } + + /** + * Get comment setting. + * + * @return string + */ + public function getCommentSetting() + { + if (!$this->isAccountAvailable()) { + return 'disabled'; + } + return isset($this->config->Social->comments) + && $this->config->Social->comments === 'disabled' + ? 'disabled' : 'enabled'; + } + + /** + * Get list setting. + * + * @return string + */ + public function getListSetting() + { + if (!$this->isAccountAvailable()) { + return 'disabled'; + } + $setting = isset($this->config->Social->lists) + ? trim(strtolower($this->config->Social->lists)) : 'enabled'; + if (!$setting) { + $setting = 'disabled'; + } + $whitelist = ['enabled', 'disabled', 'public_only', 'private_only']; + if (!in_array($setting, $whitelist)) { + $setting = 'enabled'; + } + return $setting; + } + + /** + * Get saved search setting. + * + * @return string + */ + public function getSavedSearchSetting() + { + if (!$this->isAccountAvailable()) { + return 'disabled'; + } + return isset($this->config->Site->allowSavedSearches) + && !$this->config->Site->allowSavedSearches + ? 'disabled' : 'enabled'; + } + + /** + * Get tag setting. + * + * @return string + */ + public function getTagSetting() + { + if (!$this->isAccountAvailable()) { + return 'disabled'; + } + return isset($this->config->Social->tags) + && $this->config->Social->tags === 'disabled' + ? 'disabled' : 'enabled'; + } + + /** + * Is a user account capable of saving data currently available? + * + * @return bool + */ + protected function isAccountAvailable() + { + return $this->auth->loginEnabled(); + } +} diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index f5afe675596423d645a8ff5430b862b2232bced3..932166061762d6ba1494051507dcde843731d394 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -624,9 +624,8 @@ class AbstractBase extends AbstractActionController */ protected function listsEnabled() { - $config = $this->getServiceLocator()->get('VuFind\Config')->get('config'); - $tagSetting = isset($config->Social->lists) ? $config->Social->lists : true; - return $tagSetting && $tagSetting !== 'disabled'; + $check = $this->getServiceLocator()->get('VuFind\AccountCapabilities'); + return $check->getListSetting() !== 'disabled'; } /** @@ -636,9 +635,8 @@ class AbstractBase extends AbstractActionController */ protected function tagsEnabled() { - $config = $this->getServiceLocator()->get('VuFind\Config')->get('config'); - $tagSetting = isset($config->Social->tags) ? $config->Social->tags : true; - return $tagSetting && $tagSetting !== 'disabled'; + $check = $this->getServiceLocator()->get('VuFind\AccountCapabilities'); + return $check->getTagSetting() !== 'disabled'; } /** 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/Recommend/Factory.php b/module/VuFind/src/VuFind/Recommend/Factory.php index 85a8c2580321de0377a78a4344f714917f8a7715..6f3d9bb934e2070e248af09da0cf5333c140b709 100644 --- a/module/VuFind/src/VuFind/Recommend/Factory.php +++ b/module/VuFind/src/VuFind/Recommend/Factory.php @@ -174,8 +174,11 @@ class Factory */ public static function getFavoriteFacets(ServiceManager $sm) { + $parentSm = $sm->getServiceLocator(); return new FavoriteFacets( - $sm->getServiceLocator()->get('VuFind\Config') + $parentSm->get('VuFind\Config'), + null, + $parentSm->get('VuFind\AccountCapabilities')->getTagSetting() ); } diff --git a/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php b/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php index 23b414e279edd3bf621b57df07e1a83f447bed01..29f0daf4e4aada6f5c0ca73e12d7611ae2aa06aa 100644 --- a/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php +++ b/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php @@ -26,6 +26,7 @@ * @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki */ namespace VuFind\Recommend; +use VuFind\Search\Solr\HierarchicalFacetHelper; /** * FavoriteFacets Recommendations Module @@ -40,6 +41,30 @@ namespace VuFind\Recommend; */ class FavoriteFacets extends SideFacets { + /** + * Tag capability setting + * + * @var string + */ + protected $tagSetting; + + /** + * Constructor + * + * @param \VuFind\Config\PluginManager $configLoader Configuration loader + * @param HierarchicalFacetHelper $facetHelper Helper for handling + * hierarchical facets + * @param string $tagSetting Tag capability setting + */ + public function __construct( + \VuFind\Config\PluginManager $configLoader, + HierarchicalFacetHelper $facetHelper = null, + $tagSetting = 'enabled' + ) { + parent::__construct($configLoader, $facetHelper); + $this->tagSetting = $tagSetting; + } + /** * Store the configuration of the recommendation module. * @@ -49,12 +74,8 @@ class FavoriteFacets extends SideFacets */ public function setConfig($settings) { - $config = $this->configLoader->get('config'); - $tagSetting = isset($config->Social->tags) - ? $config->Social->tags : true; - // Only display tags when enabled: - $this->mainFacets = ($tagSetting && $tagSetting !== 'disabled') + $this->mainFacets = ($this->tagSetting !== 'disabled') ? ['tags' => 'Your Tags'] : []; } } diff --git a/module/VuFind/src/VuFind/RecordTab/Factory.php b/module/VuFind/src/VuFind/RecordTab/Factory.php index f4cd5b27c38537d61a9d5170ca93938b99773e3b..793c4bff1ffa972f3b4155a9b5bcb17cf3e295ee 100644 --- a/module/VuFind/src/VuFind/RecordTab/Factory.php +++ b/module/VuFind/src/VuFind/RecordTab/Factory.php @@ -256,9 +256,7 @@ class Factory */ public static function getUserComments(ServiceManager $sm) { - $cfg = $sm->getServiceLocator()->get('VuFind\Config')->get('config'); - $enabled = !isset($cfg->Social->comments) - || ($cfg->Social->comments && $cfg->Social->comments !== 'disabled'); - return new UserComments($enabled); + $capabilities = $sm->getServiceLocator()->get('VuFind\AccountCapabilities'); + return new UserComments('enabled' === $capabilities->getCommentSetting()); } } diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index 4f20f5105a8bc8595d927d9b0c94042998e6ccf6..fec6f253c317a4956493f96ed3bce8f234542a81 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -41,6 +41,21 @@ use Zend\ServiceManager\ServiceManager; */ class Factory { + /** + * Construct the Account Capabilities helper. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Config\AccountCapabilities + */ + public static function getAccountCapabilities(ServiceManager $sm) + { + return new \VuFind\Config\AccountCapabilities( + $sm->get('VuFind\Config')->get('config'), + $sm->get('VuFind\AuthManager') + ); + } + /** * Construct the Auth Plugin Manager. * 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 c6d56cc5feaadbc09d935230588a24003ceb4a35..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. * @@ -514,17 +528,8 @@ class Factory */ public static function getUserList(ServiceManager $sm) { - $cfg = $sm->getServiceLocator()->get('VuFind\Config')->get('config'); - $setting = isset($cfg->Social->lists) - ? trim(strtolower($cfg->Social->lists)) : 'enabled'; - if (!$setting) { - $setting = 'disabled'; - } - $whitelist = ['enabled', 'disabled', 'public_only', 'private_only']; - if (!in_array($setting, $whitelist)) { - $setting = 'enabled'; - } - return new UserList($setting); + $capabilities = $sm->getServiceLocator()->get('VuFind\AccountCapabilities'); + return new UserList($capabilities->getListSetting()); } /** @@ -536,10 +541,7 @@ class Factory */ public static function getUserTags(ServiceManager $sm) { - $cfg = $sm->getServiceLocator()->get('VuFind\Config')->get('config'); - $mode = !isset($cfg->Social->tags) - || ($cfg->Social->tags && $cfg->Social->tags !== 'disabled') - ? 'enabled' : 'disabled'; - return new UserTags($mode); + $capabilities = $sm->getServiceLocator()->get('VuFind\AccountCapabilities'); + return new UserTags($capabilities->getTagSetting()); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/FavoriteFacetsTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/FavoriteFacetsTest.php index 7f677aeb85394197ea251e72c184c8e677a8963a..1643a714ba9f3f1fc2ee1fdf1962ff734aa6d542 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/FavoriteFacetsTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/FavoriteFacetsTest.php @@ -46,13 +46,10 @@ class FavoriteFacetsTest extends \VuFindTest\Unit\TestCase */ public function testFacetInitWithDisabledTags() { - $configLoader = $this->getMockConfigLoader( - ['Social' => ['tags' => false]] - ); $results = $this->getMockResults(); $params = $results->getParams(); $params->expects($this->exactly(0))->method('addFacet'); // no facets are expected in this case - $this->getFavoriteFacets($configLoader, $results); + $this->getFavoriteFacets($results, 'disabled'); } /** * Test facet initialization with enabled tags. @@ -64,21 +61,22 @@ class FavoriteFacetsTest extends \VuFindTest\Unit\TestCase $results = $this->getMockResults(); $params = $results->getParams(); $params->expects($this->once())->method('addFacet')->with($this->equalTo('tags'), $this->equalTo('Your Tags'), $this->equalTo(false)); - $this->getFavoriteFacets(null, $results); + $this->getFavoriteFacets($results); } /** * Get a fully configured module * - * @param \VuFind\Config\PluginManager $configLoader config loader * @param \VuFind\Search\Solr\Results $results results object + * @param string $tagSetting Are tags enabled? * @param string $settings settings * @param \Zend\StdLib\Parameters $request request * @param \VuFind\Search\Solr\HierarchicalFacetHelper $facetHelper hierarchical facet helper (true to build default, null to omit) + * @param \VuFind\Config\PluginManager $configLoader config loader * * @return FavoriteFacets */ - protected function getFavoriteFacets($configLoader = null, $results = null, $settings = '', $request = null, $facetHelper = null) + protected function getFavoriteFacets($results = null, $tagSetting = 'enabled', $settings = '', $request = null, $facetHelper = null, $configLoader = null) { if (null === $configLoader) { $configLoader = $this->getMockConfigLoader(); @@ -92,7 +90,7 @@ class FavoriteFacetsTest extends \VuFindTest\Unit\TestCase if (null === $request) { $request = new \Zend\StdLib\Parameters([]); } - $sf = new FavoriteFacets($configLoader, $facetHelper); + $sf = new FavoriteFacets($configLoader, $facetHelper, $tagSetting); $sf->setConfig($settings); $sf->init($results->getParams(), $request); $sf->process($results); @@ -111,7 +109,7 @@ class FavoriteFacetsTest extends \VuFindTest\Unit\TestCase { $loader = $this->getMockBuilder('VuFind\Config\PluginManager') ->disableOriginalConstructor()->getMock(); - $loader->expects($this->once())->method('get')->with($this->equalTo($key)) + $loader->expects($this->any())->method('get')->with($this->equalTo($key)) ->will($this->returnValue(new \Zend\Config\Config($config))); return $loader; } 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',