diff --git a/config/application.config.php b/config/application.config.php index c7800de4654f8c8a5d1bedea77991ee09e96828a..bd737f1eb2b3612e81e8b49e69b714f540d9021b 100644 --- a/config/application.config.php +++ b/config/application.config.php @@ -1,7 +1,7 @@ <?php $config = array( 'modules' => array( - 'VuFindHttp', 'VuFind', + 'VuFindHttp', 'VuFindTheme', 'VuFind', ), 'module_listener_options' => array( 'config_glob_paths' => array( diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 60c3c7cb84a4b562acae677357985abb653cc7be..73685d986aca65d1e5eeadb4067be76ea0f04feb 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -480,11 +480,6 @@ $config = array( $sm->get('VuFind\Http')->createClient() ); }, - 'VuFindTheme\ThemeInfo' => function ($sm) { - return new \VuFind\Theme\ThemeInfo( - realpath(__DIR__ . '/../../../themes'), 'blueprint' - ); - } ), 'invokables' => array( 'VuFind\AuthManager' => 'VuFind\Auth\Manager', @@ -494,7 +489,6 @@ $config = array( 'VuFind\SearchSpecsReader' => 'VuFind\Config\SearchSpecsReader', 'VuFind\SessionManager' => 'Zend\Session\SessionManager', 'VuFind\WorldCatUtils' => 'VuFind\Connection\WorldCatUtils', - 'VuFindTheme\ResourceContainer' => 'VuFind\Theme\ResourceContainer', ), 'initializers' => array( array('VuFind\ServiceManager\Initializer', 'initInstance'), diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index 63b21e44c91568910f45a7b949826f7e36dd5644..3f0d23c815504482bb553d63137bd235ebb0b806 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -301,14 +301,14 @@ class Bootstrap // Attach template injection configuration to the route event: $this->events->attach( - 'route', array('VuFind\Theme\Initializer', 'configureTemplateInjection') + 'route', array('VuFindTheme\Initializer', 'configureTemplateInjection') ); // Attach remaining theme configuration to the dispatch event at high // priority (TODO: use priority constant once defined by framework): $config = $this->config->Site; $callback = function ($event) use ($config) { - $theme = new \VuFind\Theme\Initializer($config, $event); + $theme = new \VuFindTheme\Initializer($config, $event); $theme->init(); }; $this->events->attach('dispatch.error', $callback, 10000); diff --git a/module/VuFind/src/VuFind/Cover/Loader.php b/module/VuFind/src/VuFind/Cover/Loader.php index 74fed7a328388ed60f620ae50a1e5f99911632ec..3f03e9cc237e76117f89e0b0ea328ab588e7e599 100644 --- a/module/VuFind/src/VuFind/Cover/Loader.php +++ b/module/VuFind/src/VuFind/Cover/Loader.php @@ -121,20 +121,20 @@ class Loader implements \Zend\Log\LoggerAwareInterface /** * Theme tools * - * @var \VuFind\Theme\ThemeInfo + * @var \VuFindTheme\ThemeInfo */ protected $themeTools; /** * Constructor * - * @param \Zend\Config\Config $config VuFind configuration - * @param \VuFind\Theme\ThemeInfo $theme VuFind theme tools - * @param \Zend\Http\Client $client HTTP client - * @param string $baseDir Directory to store downloaded images + * @param \Zend\Config\Config $config VuFind configuration + * @param \VuFindTheme\ThemeInfo $theme VuFind theme tools + * @param \Zend\Http\Client $client HTTP client + * @param string $baseDir Directory to store downloaded images * (set to system temp dir if not otherwise specified) */ - public function __construct($config, \VuFind\Theme\ThemeInfo $theme, + public function __construct($config, \VuFindTheme\ThemeInfo $theme, \Zend\Http\Client $client, $baseDir = null ) { $this->config = $config; diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/HeadLink.php b/module/VuFind/src/VuFind/Theme/Root/Helper/HeadLink.php index 5beeac2f1dff3f2a9fd5183c7948ccc2ebdcd81a..ad7910271b7d41de8b37e7ad5f8df5f027d97e11 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/HeadLink.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/HeadLink.php @@ -76,7 +76,7 @@ class HeadLink extends \Zend\View\Helper\HeadLink /** * Get the theme tools. * - * @return \VuFind\Theme\ThemeInfo + * @return \VuFindTheme\ThemeInfo */ public function getThemeInfo() { diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/HeadScript.php b/module/VuFind/src/VuFind/Theme/Root/Helper/HeadScript.php index ba7994c6468c9a93f5c6f104bf4dc10b5e233961..830240c55614f195b0e4f5b05e8d121593f87e9e 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/HeadScript.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/HeadScript.php @@ -76,7 +76,7 @@ class HeadScript extends \Zend\View\Helper\HeadScript /** * Get the theme tools. * - * @return \VuFind\Theme\ThemeInfo + * @return \VuFindTheme\ThemeInfo */ public function getThemeInfo() { diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/HeadThemeResources.php b/module/VuFind/src/VuFind/Theme/Root/Helper/HeadThemeResources.php index fa8fb9229a285c0fc9db70420bcd6fae46b35212..31abed9e5dbe7b9ba87a712e7e7ef1cad2087668 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/HeadThemeResources.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/HeadThemeResources.php @@ -42,7 +42,7 @@ class HeadThemeResources extends AbstractServiceLocator /** * Get the theme resource container. * - * @return \VuFind\Theme\ResourceContainer + * @return \VuFindTheme\ResourceContainer */ public function getThemeResourceContainer() { diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/ImageLink.php b/module/VuFind/src/VuFind/Theme/Root/Helper/ImageLink.php index 1c05d7fa6d2797ef8e9649d96f191d15528747af..a73ad8836f9de961d8be035bf6339bfe950fbda3 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/ImageLink.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/ImageLink.php @@ -42,7 +42,7 @@ class ImageLink extends AbstractServiceLocator /** * Get the theme tools. * - * @return \VuFind\Theme\ThemeInfo + * @return \VuFindTheme\ThemeInfo */ public function getThemeInfo() { diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/MobileUrl.php b/module/VuFind/src/VuFind/Theme/Root/Helper/MobileUrl.php index 68652496a5f8ae1048a74bcd3d710da7341ab2d5..546b54943a5117e351c0af20696b9beaf966faef 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/MobileUrl.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/MobileUrl.php @@ -26,8 +26,6 @@ * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ namespace VuFind\Theme\Root\Helper; -use VuFind\Mobile, - Zend\View\Helper\AbstractHelper; /** * Mobile URL view helper @@ -38,7 +36,7 @@ use VuFind\Mobile, * @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 AbstractHelper +class MobileUrl extends AbstractServiceLocator { /** * Return the mobile version of the current URL if the user is on a mobile device @@ -48,9 +46,11 @@ class MobileUrl extends AbstractHelper */ 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 (!$mobile->enabled() || !$mobile->detect()) { return false; } diff --git a/module/VuFindTheme/Module.php b/module/VuFindTheme/Module.php new file mode 100644 index 0000000000000000000000000000000000000000..05c3f22b868578b745e8d2e92cb70333f312632c --- /dev/null +++ b/module/VuFindTheme/Module.php @@ -0,0 +1,97 @@ +<?php +/** + * ZF2 module definition for the VuFind theme system. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2013. + * + * 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 Theme + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://github.com/dmj/vf2-proxy + */ +namespace VuFindTheme; + +/** + * ZF2 module definition for the VuFind theme system. + * + * @category VuFind2 + * @package Theme + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://github.com/dmj/vf2-proxy + */ +class Module +{ + /** + * Get autoloader configuration + * + * @return void + */ + public function getAutoloaderConfig() + { + return array( + 'Zend\Loader\StandardAutoloader' => array( + 'namespaces' => array( + __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, + ), + ), + ); + } + + /** + * Return service configuration. + * + * @return array + */ + public function getServiceConfig() + { + return array( + 'factories' => array( + 'VuFindTheme\ThemeInfo' => function ($sm) { + return new \VuFindTheme\ThemeInfo( + realpath(__DIR__ . '/../../themes'), 'blueprint' + ); + } + ), + 'invokables' => array( + 'VuFindTheme\Mobile' => 'VuFindTheme\Mobile', + 'VuFindTheme\ResourceContainer' => 'VuFindTheme\ResourceContainer', + ), + ); + } + + /** + * Get view helper configuration. + * + * @return array + */ + public function getViewHelperConfig() + { + return array(); + } + + /** + * Perform initialization + * + * @return void + */ + public function init() + { + } +} diff --git a/module/VuFind/src/VuFind/Theme/Initializer.php b/module/VuFindTheme/src/VuFindTheme/Initializer.php similarity index 96% rename from module/VuFind/src/VuFind/Theme/Initializer.php rename to module/VuFindTheme/src/VuFindTheme/Initializer.php index 9688b240dae87dc7a62bf67d98156a2c9cd4b87a..0e3a1de337c977f38c34233d8a9a09b52fa8d455 100644 --- a/module/VuFind/src/VuFind/Theme/Initializer.php +++ b/module/VuFindTheme/src/VuFindTheme/Initializer.php @@ -25,10 +25,8 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org Main Site */ -namespace VuFind\Theme; -use VuFind\Mobile, - VuFind\Mvc\View\Http\InjectTemplateListener, - Zend\Config\Config, +namespace VuFindTheme; +use Zend\Config\Config, Zend\Mvc\MvcEvent, Zend\Stdlib\RequestInterface as Request; @@ -67,10 +65,17 @@ class Initializer /** * Theme tools object * - * @var \VuFind\Theme\ThemeInfo + * @var \VuFindTheme\ThemeInfo */ protected $tools; + /** + * Mobile interface detector + * + * @var \VuFindTheme\Mobile + */ + protected $mobile; + /** * Constructor * @@ -100,6 +105,10 @@ class Initializer // Get base directory from tools object: $this->tools = $this->serviceManager->get('VuFindTheme\ThemeInfo'); + + // Set up mobile device detector: + $this->mobile = $this->serviceManager->get('VuFindTheme\Mobile'); + $this->mobile->enable(isset($this->config->mobile_theme)); } /** @@ -193,7 +202,7 @@ class Initializer { // Load standard configuration options: $standardTheme = $this->config->theme; - $mobileTheme = isset($this->config->mobile_theme) + $mobileTheme = $this->mobile->enabled() ? $this->config->mobile_theme : false; // Find out if the user has a saved preference in the POST, URL or cookies: @@ -204,7 +213,7 @@ class Initializer ) ); if (empty($selectedUI)) { - $selectedUI = ($mobileTheme && Mobile::detect()) + $selectedUI = ($mobileTheme && $this->mobile->detect()) ? 'mobile' : 'standard'; } diff --git a/module/VuFind/src/VuFind/Mvc/View/Http/InjectTemplateListener.php b/module/VuFindTheme/src/VuFindTheme/InjectTemplateListener.php similarity index 98% rename from module/VuFind/src/VuFind/Mvc/View/Http/InjectTemplateListener.php rename to module/VuFindTheme/src/VuFindTheme/InjectTemplateListener.php index 53dce0861284d6dd664d4a2da3c742f260ee3486..d8a6e60c9bb284e0ddcd31438229af1884c236e2 100644 --- a/module/VuFind/src/VuFind/Mvc/View/Http/InjectTemplateListener.php +++ b/module/VuFindTheme/src/VuFindTheme/InjectTemplateListener.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\Mvc\View\Http; +namespace VuFindTheme; /** * VuFind "Inject Template" Listener -- this extends the core ZF2 class to adjust diff --git a/module/VuFind/src/VuFind/Mobile.php b/module/VuFindTheme/src/VuFindTheme/Mobile.php similarity index 81% rename from module/VuFind/src/VuFind/Mobile.php rename to module/VuFindTheme/src/VuFindTheme/Mobile.php index d8869fe901593302df6ce3ca72c25329385e9ad2..8433c90ef10151f9b6e2bd732dcab19f1bfcf532 100644 --- a/module/VuFind/src/VuFind/Mobile.php +++ b/module/VuFindTheme/src/VuFindTheme/Mobile.php @@ -26,31 +26,37 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @category VuFind2 - * @package Mobile + * @package Theme * @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net> * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://code.google.com/p/mobileesp/ MobileESP Project */ -namespace VuFind; -use VuFind\Config\Reader as ConfigReader; +namespace VuFindTheme; /** * Mobile Device Detection Wrapper * * @category VuFind2 - * @package Mobile + * @package Theme * @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net> * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://code.google.com/p/mobileesp/ MobileESP Project */ class Mobile { + /** + * Are mobile themes enabled? + * + * @var bool + */ + protected $enabled = false; + /** * Function to detect if a mobile device is being used. * * @return bool */ - public static function detect() + public function detect() { // Do the most exhaustive device detection possible; other method calls // may be used instead of DetectMobileLong if you want to target a narrower @@ -59,14 +65,23 @@ class Mobile return $mobile->DetectMobileLong(); } + /** + * Function to set enabled status of mobile themes. + * + * @param bool $enabled Are mobile themes enabled? + */ + public function enable($enabled = true) + { + $this->enabled = $enabled; + } + /** * Function to check whether mobile theme is configured. * * @return bool */ - public static function enabled() + public function enabled() { - $config = ConfigReader::getConfig(); - return isset($config->Site->mobile_theme); + return $this->enabled; } } \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Theme/ResourceContainer.php b/module/VuFindTheme/src/VuFindTheme/ResourceContainer.php similarity index 89% rename from module/VuFind/src/VuFind/Theme/ResourceContainer.php rename to module/VuFindTheme/src/VuFindTheme/ResourceContainer.php index 82a63aa11e512405e8349c5e31007d1861292a17..2fcef78e932fe35fd075fafb4f07f17054546ca3 100644 --- a/module/VuFind/src/VuFind/Theme/ResourceContainer.php +++ b/module/VuFindTheme/src/VuFindTheme/ResourceContainer.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\Theme; +namespace VuFindTheme; /** * VuFind Theme Public Resource Handler (for CSS, JS, etc.) @@ -38,9 +38,32 @@ namespace VuFind\Theme; */ class ResourceContainer { + /** + * CSS files + * + * @var array + */ protected $css = array(); + + /** + * Javascript files + * + * @var array + */ protected $js = array(); + + /** + * Favicon + * + * @var string + */ protected $favicon = null; + + /** + * Encoding type + * + * @var string + */ protected $encoding = 'UTF-8'; /** @@ -53,7 +76,7 @@ class ResourceContainer */ public function addCss($css) { - if (!is_array($css) && !is_a($css, '\Traversable')) { + if (!is_array($css) && !is_a($css, 'Traversable')) { $css = array($css); } foreach ($css as $current) { @@ -71,7 +94,7 @@ class ResourceContainer */ public function addJs($js) { - if (!is_array($js) && !is_a($js, '\Traversable')) { + if (!is_array($js) && !is_a($js, 'Traversable')) { $js = array($js); } foreach ($js as $current) { diff --git a/module/VuFind/src/VuFind/Theme/ThemeInfo.php b/module/VuFindTheme/src/VuFindTheme/ThemeInfo.php similarity index 99% rename from module/VuFind/src/VuFind/Theme/ThemeInfo.php rename to module/VuFindTheme/src/VuFindTheme/ThemeInfo.php index aff13d6fb81923448a478cb21fee89b55aa7777f..254c25f1a5189d9937d0a241bb797522ca19e36a 100644 --- a/module/VuFind/src/VuFind/Theme/ThemeInfo.php +++ b/module/VuFindTheme/src/VuFindTheme/ThemeInfo.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\Theme; +namespace VuFindTheme; /** * Class to represent currently-selected theme and related information.