diff --git a/module/VuFindTheme/Module.php b/module/VuFindTheme/Module.php index 05c3f22b868578b745e8d2e92cb70333f312632c..9ca7617035b427e073f83bc75a4ea54751aaccb3 100644 --- a/module/VuFindTheme/Module.php +++ b/module/VuFindTheme/Module.php @@ -83,7 +83,40 @@ class Module */ public function getViewHelperConfig() { - return array(); + return array( + 'factories' => array( + 'headlink' => function ($sm) { + return new \VuFindTheme\View\Helper\HeadLink( + $sm->getServiceLocator()->get('VuFindTheme\ThemeInfo') + ); + }, + 'headscript' => function ($sm) { + return new \VuFindTheme\View\Helper\HeadScript( + $sm->getServiceLocator()->get('VuFindTheme\ThemeInfo') + ); + }, + 'headthemeresources' => function ($sm) { + return new \VuFindTheme\View\Helper\HeadThemeResources( + $sm->getServiceLocator()->get('VuFindTheme\ResourceContainer') + ); + }, + 'imagelink' => function ($sm) { + return new \VuFindTheme\View\Helper\ImageLink( + $sm->getServiceLocator()->get('VuFindTheme\ThemeInfo') + ); + }, + 'inlinescript' => function ($sm) { + return new \VuFindTheme\View\Helper\InlineScript( + $sm->getServiceLocator()->get('VuFindTheme\ThemeInfo') + ); + }, + 'mobileurl' => function ($sm) { + return new \VuFindTheme\View\Helper\MobileUrl( + $sm->getServiceLocator()->get('VuFindTheme\Mobile') + ); + }, + ), + ); } /** diff --git a/module/VuFind/src/VuFind/View/Helper/Root/HeadLink.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadLink.php similarity index 62% rename from module/VuFind/src/VuFind/View/Helper/Root/HeadLink.php rename to module/VuFindTheme/src/VuFindTheme/View/Helper/HeadLink.php index eeb4a25bdc37ee04083536f150ad7258ce0b2e58..50e9f7c17ca2713df457c1d7f4a79907a91db53a 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/HeadLink.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadLink.php @@ -25,9 +25,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -namespace VuFind\View\Helper\Root; -use Zend\ServiceManager\ServiceLocatorInterface, - Zend\ServiceManager\ServiceLocatorAwareInterface; +namespace VuFindTheme\View\Helper; /** * Head link view helper (extended for VuFind's theme system) @@ -39,48 +37,23 @@ use Zend\ServiceManager\ServiceLocatorInterface, * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ class HeadLink extends \Zend\View\Helper\HeadLink - implements ServiceLocatorAwareInterface { /** - * Service locator + * Theme information service * - * @var ServiceLocatorInterface + * @var \VuFindTheme\ThemeInfo */ - protected $serviceLocator; + protected $themeInfo; /** - * Set the service locator. + * Constructor * - * @param ServiceLocatorInterface $serviceLocator Locator to register - * - * @return AbstractServiceLocator - */ - public function setServiceLocator(ServiceLocatorInterface $serviceLocator) - { - // The service locator passed in here is a Zend\View\HelperPluginManager; - // we want to pull out the main Zend\ServiceManager\ServiceManager. - $this->serviceLocator = $serviceLocator->getServiceLocator(); - return $this; - } - - /** - * Get the service locator. - * - * @return \Zend\ServiceManager\ServiceLocatorInterface - */ - public function getServiceLocator() - { - return $this->serviceLocator; - } - - /** - * Get the theme tools. - * - * @return \VuFindTheme\ThemeInfo + * @param \VuFindTheme\ThemeInfo $themeInfo Theme information service */ - public function getThemeInfo() + public function __construct(\VuFindTheme\ThemeInfo $themeInfo) { - return $this->getServiceLocator()->get('VuFindTheme\ThemeInfo'); + parent::__construct(); + $this->themeInfo = $themeInfo; } /** @@ -94,7 +67,7 @@ class HeadLink extends \Zend\View\Helper\HeadLink { // Normalize href to account for themes, then call the parent class: $relPath = 'css/' . $item->href; - $currentTheme = $this->getThemeInfo()->findContainingTheme($relPath); + $currentTheme = $this->themeInfo->findContainingTheme($relPath); if (!empty($currentTheme)) { $urlHelper = $this->getView()->plugin('url'); diff --git a/module/VuFind/src/VuFind/View/Helper/Root/HeadScript.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadScript.php similarity index 65% rename from module/VuFind/src/VuFind/View/Helper/Root/HeadScript.php rename to module/VuFindTheme/src/VuFindTheme/View/Helper/HeadScript.php index 1929204bd4a3e6c68df4a597c7374a77f783dfab..5686af579894bcd66b1cd0c4e5ed7b67f4b448ea 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/HeadScript.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadScript.php @@ -25,9 +25,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -namespace VuFind\View\Helper\Root; -use Zend\ServiceManager\ServiceLocatorInterface, - Zend\ServiceManager\ServiceLocatorAwareInterface; +namespace VuFindTheme\View\Helper; /** * Head script view helper (extended for VuFind's theme system) @@ -39,48 +37,23 @@ use Zend\ServiceManager\ServiceLocatorInterface, * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ class HeadScript extends \Zend\View\Helper\HeadScript - implements ServiceLocatorAwareInterface { /** - * Service locator + * Theme information service * - * @var ServiceLocatorInterface + * @var \VuFindTheme\ThemeInfo */ - protected $serviceLocator; + protected $themeInfo; /** - * Set the service locator. + * Constructor * - * @param ServiceLocatorInterface $serviceLocator Locator to register - * - * @return AbstractServiceLocator - */ - public function setServiceLocator(ServiceLocatorInterface $serviceLocator) - { - // The service locator passed in here is a Zend\View\HelperPluginManager; - // we want to pull out the main Zend\ServiceManager\ServiceManager. - $this->serviceLocator = $serviceLocator->getServiceLocator(); - return $this; - } - - /** - * Get the service locator. - * - * @return \Zend\ServiceManager\ServiceLocatorInterface - */ - public function getServiceLocator() - { - return $this->serviceLocator; - } - - /** - * Get the theme tools. - * - * @return \VuFindTheme\ThemeInfo + * @param \VuFindTheme\ThemeInfo $themeInfo Theme information service */ - public function getThemeInfo() + public function __construct(\VuFindTheme\ThemeInfo $themeInfo) { - return $this->getServiceLocator()->get('VuFindTheme\ThemeInfo'); + parent::__construct(); + $this->themeInfo = $themeInfo; } /** @@ -98,7 +71,7 @@ class HeadScript extends \Zend\View\Helper\HeadScript // Normalize href to account for themes: if (!empty($item->attributes['src'])) { $relPath = 'js/' . $item->attributes['src']; - $currentTheme = $this->getThemeInfo()->findContainingTheme($relPath); + $currentTheme = $this->themeInfo->findContainingTheme($relPath); if (!empty($currentTheme)) { $urlHelper = $this->getView()->plugin('url'); diff --git a/module/VuFind/src/VuFind/View/Helper/Root/HeadThemeResources.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadThemeResources.php similarity index 80% rename from module/VuFind/src/VuFind/View/Helper/Root/HeadThemeResources.php rename to module/VuFindTheme/src/VuFindTheme/View/Helper/HeadThemeResources.php index 6c0069334786f335856c0044f5ca1d6e94466e09..76210ee577b1c3aa87e2b5b9964917093d029dc2 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/HeadThemeResources.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadThemeResources.php @@ -25,8 +25,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -namespace VuFind\View\Helper\Root; -use Zend\View\Helper\AbstractHelper; +namespace VuFindTheme\View\Helper; /** * View helper for loading theme-related resources in the header. @@ -37,16 +36,23 @@ use Zend\View\Helper\AbstractHelper; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -class HeadThemeResources extends AbstractServiceLocator +class HeadThemeResources extends \Zend\View\Helper\AbstractHelper { /** - * Get the theme resource container. + * Theme resource container * - * @return \VuFindTheme\ResourceContainer + * @var \VuFindTheme\ResourceContainer */ - public function getThemeResourceContainer() + protected $container; + + /** + * Constructor + * + * @param \VuFindTheme\ResourceContainer $container Theme resource container + */ + public function __construct(\VuFindTheme\ResourceContainer $container) { - return $this->getServiceLocator()->get('VuFindTheme\ResourceContainer'); + $this->container = $container; } /** @@ -56,18 +62,16 @@ class HeadThemeResources extends AbstractServiceLocator */ public function __invoke() { - $resourceContainer = $this->getThemeResourceContainer(); - // Set up encoding: $headMeta = $this->getView()->plugin('headmeta'); $headMeta()->appendHttpEquiv( - 'Content-Type', 'text/html; charset=' . $resourceContainer->getEncoding() + 'Content-Type', 'text/html; charset=' . $this->container->getEncoding() ); // Load CSS (make sure we prepend them in the appropriate order; theme // resources should load before extras added by individual templates): $headLink = $this->getView()->plugin('headlink'); - foreach (array_reverse($resourceContainer->getCss()) as $current) { + foreach (array_reverse($this->container->getCss()) as $current) { $parts = explode(':', $current); $headLink()->prependStylesheet( trim($parts[0]), @@ -78,7 +82,7 @@ class HeadThemeResources extends AbstractServiceLocator // Load Javascript (same ordering considerations as CSS, above): $headScript = $this->getView()->plugin('headscript'); - foreach (array_reverse($resourceContainer->getJs()) as $current) { + foreach (array_reverse($this->container->getJs()) as $current) { $parts = explode(':', $current); $headScript()->prependFile( trim($parts[0]), @@ -89,7 +93,7 @@ class HeadThemeResources extends AbstractServiceLocator } // If we have a favicon, load it now: - $favicon = $resourceContainer->getFavicon(); + $favicon = $this->container->getFavicon(); if (!empty($favicon)) { $imageLink = $this->getView()->plugin('imagelink'); $headLink(array( diff --git a/module/VuFind/src/VuFind/View/Helper/Root/ImageLink.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/ImageLink.php similarity index 79% rename from module/VuFind/src/VuFind/View/Helper/Root/ImageLink.php rename to module/VuFindTheme/src/VuFindTheme/View/Helper/ImageLink.php index 23183d68af11ae3e8e2ba474ab967482f47ce6e6..eeacb3e2c2fdc4f456da6f3759c6d406da08d26e 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/ImageLink.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/ImageLink.php @@ -25,8 +25,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://www.vufind.org Main Page */ -namespace VuFind\View\Helper\Root; -use Zend\View\Helper\AbstractHelper; +namespace VuFindTheme\View\Helper; /** * Image link view helper (extended for VuFind's theme system) @@ -37,16 +36,23 @@ use Zend\View\Helper\AbstractHelper; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://www.vufind.org Main Page */ -class ImageLink extends AbstractServiceLocator +class ImageLink extends \Zend\View\Helper\AbstractHelper { /** - * Get the theme tools. + * Theme information service * - * @return \VuFindTheme\ThemeInfo + * @var \VuFindTheme\ThemeInfo */ - public function getThemeInfo() + protected $themeInfo; + + /** + * Constructor + * + * @param \VuFindTheme\ThemeInfo $themeInfo Theme information service + */ + public function __construct(\VuFindTheme\ThemeInfo $themeInfo) { - return $this->getServiceLocator()->get('VuFindTheme\ThemeInfo'); + $this->themeInfo = $themeInfo; } /** @@ -60,7 +66,7 @@ class ImageLink extends AbstractServiceLocator { // Normalize href to account for themes: $relPath = 'images/' . $image; - $currentTheme = $this->getThemeInfo()->findContainingTheme($relPath); + $currentTheme = $this->themeInfo->findContainingTheme($relPath); if (is_null($currentTheme)) { return null; diff --git a/module/VuFind/src/VuFind/View/Helper/Root/InlineScript.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/InlineScript.php similarity index 98% rename from module/VuFind/src/VuFind/View/Helper/Root/InlineScript.php rename to module/VuFindTheme/src/VuFindTheme/View/Helper/InlineScript.php index dfd865e25d6751ff02ecab95143b4ec3d8f5e9c1..33def48402243ec7565bc9e756f375891c5b0e8b 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/InlineScript.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/InlineScript.php @@ -25,7 +25,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org Main Site */ -namespace VuFind\View\Helper\Root; +namespace VuFindTheme\View\Helper; /** * Inline script view helper (extended for VuFind's theme system) diff --git a/module/VuFind/src/VuFind/View/Helper/Root/MobileUrl.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/MobileUrl.php similarity index 73% rename from module/VuFind/src/VuFind/View/Helper/Root/MobileUrl.php rename to module/VuFindTheme/src/VuFindTheme/View/Helper/MobileUrl.php index 6217748e22bfb6bf6f1484915a40ab354472b092..884f64fec94e195ba4f1c2b7f72b5c80e33430f7 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/MobileUrl.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/MobileUrl.php @@ -25,7 +25,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -namespace VuFind\View\Helper\Root; +namespace VuFindTheme\View\Helper; /** * Mobile URL view helper @@ -36,8 +36,25 @@ namespace VuFind\View\Helper\Root; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -class MobileUrl extends AbstractServiceLocator +class MobileUrl extends \Zend\View\Helper\AbstractHelper { + /** + * Mobile service + * + * @var \VuFindTheme\Mobile + */ + protected $mobile; + + /** + * Constructor + * + * @param \VuFindTheme\Mobile $mobile Mobile service + */ + public function __construct(\VuFindTheme\Mobile $mobile) + { + $this->mobile = $mobile; + } + /** * Return the mobile version of the current URL if the user is on a mobile device * and might want to switch over. Return false when not on a mobile device. @@ -46,16 +63,18 @@ class MobileUrl extends AbstractServiceLocator */ public function __invoke() { - $mobile = $this->getServiceLocator()->get('VuFindTheme\Mobile'); - // Do nothing special if we're not on a mobile device or no mobile theme is // enabled: - if (!$mobile->enabled() || !$mobile->detect()) { + if (!$this->mobile->enabled() || !$this->mobile->detect()) { return false; } $urlHelper = $this->getView()->plugin('serverurl'); - $currentUrl = rtrim($urlHelper(true), '?'); + $currentUrl = $urlHelper(true); + $currentUrl = preg_replace( + array('/\&ui=[^&]*/', '/\?ui=[^&]*\&?/'), array('', '?'), $currentUrl + ); + $currentUrl = rtrim($currentUrl, '?'); $currentUrl .= strstr($currentUrl, '?') ? '&' : '?'; return $currentUrl .= 'ui=mobile'; } diff --git a/themes/root/theme.config.php b/themes/root/theme.config.php index 380594b4f2fcd687850aef929b823a43ce15365f..3adaa6c4a684a287deb5b743b0f9c17bb0ea8212 100644 --- a/themes/root/theme.config.php +++ b/themes/root/theme.config.php @@ -17,15 +17,9 @@ return array( 'excerpt' => 'VuFind\View\Helper\Root\Excerpt', 'flashmessages' => 'VuFind\View\Helper\Root\Flashmessages', 'getlastsearchlink' => 'VuFind\View\Helper\Root\GetLastSearchLink', - 'headlink' => 'VuFind\View\Helper\Root\HeadLink', - 'headscript' => 'VuFind\View\Helper\Root\HeadScript', - 'headthemeresources' => 'VuFind\View\Helper\Root\HeadThemeResources', 'highlight' => 'VuFind\View\Helper\Root\Highlight', 'ils' => 'VuFind\View\Helper\Root\Ils', - 'imagelink' => 'VuFind\View\Helper\Root\ImageLink', - 'inlinescript' => 'VuFind\View\Helper\Root\InlineScript', 'jqueryvalidation' => 'VuFind\View\Helper\Root\JqueryValidation', - 'mobileurl' => 'VuFind\View\Helper\Root\MobileUrl', 'openurl' => 'VuFind\View\Helper\Root\OpenUrl', 'printms' => 'VuFind\View\Helper\Root\Printms', 'proxyurl' => 'VuFind\View\Helper\Root\ProxyUrl',