Skip to content
Snippets Groups Projects
Commit 0c34784f authored by Demian Katz's avatar Demian Katz
Browse files

Moved theme-related code into a separate module.

parent 22e25ed7
No related merge requests found
Showing
with 181 additions and 43 deletions
<?php <?php
$config = array( $config = array(
'modules' => array( 'modules' => array(
'VuFindHttp', 'VuFind', 'VuFindHttp', 'VuFindTheme', 'VuFind',
), ),
'module_listener_options' => array( 'module_listener_options' => array(
'config_glob_paths' => array( 'config_glob_paths' => array(
......
...@@ -480,11 +480,6 @@ $config = array( ...@@ -480,11 +480,6 @@ $config = array(
$sm->get('VuFind\Http')->createClient() $sm->get('VuFind\Http')->createClient()
); );
}, },
'VuFindTheme\ThemeInfo' => function ($sm) {
return new \VuFind\Theme\ThemeInfo(
realpath(__DIR__ . '/../../../themes'), 'blueprint'
);
}
), ),
'invokables' => array( 'invokables' => array(
'VuFind\AuthManager' => 'VuFind\Auth\Manager', 'VuFind\AuthManager' => 'VuFind\Auth\Manager',
...@@ -494,7 +489,6 @@ $config = array( ...@@ -494,7 +489,6 @@ $config = array(
'VuFind\SearchSpecsReader' => 'VuFind\Config\SearchSpecsReader', 'VuFind\SearchSpecsReader' => 'VuFind\Config\SearchSpecsReader',
'VuFind\SessionManager' => 'Zend\Session\SessionManager', 'VuFind\SessionManager' => 'Zend\Session\SessionManager',
'VuFind\WorldCatUtils' => 'VuFind\Connection\WorldCatUtils', 'VuFind\WorldCatUtils' => 'VuFind\Connection\WorldCatUtils',
'VuFindTheme\ResourceContainer' => 'VuFind\Theme\ResourceContainer',
), ),
'initializers' => array( 'initializers' => array(
array('VuFind\ServiceManager\Initializer', 'initInstance'), array('VuFind\ServiceManager\Initializer', 'initInstance'),
......
...@@ -301,14 +301,14 @@ class Bootstrap ...@@ -301,14 +301,14 @@ class Bootstrap
// Attach template injection configuration to the route event: // Attach template injection configuration to the route event:
$this->events->attach( $this->events->attach(
'route', array('VuFind\Theme\Initializer', 'configureTemplateInjection') 'route', array('VuFindTheme\Initializer', 'configureTemplateInjection')
); );
// Attach remaining theme configuration to the dispatch event at high // Attach remaining theme configuration to the dispatch event at high
// priority (TODO: use priority constant once defined by framework): // priority (TODO: use priority constant once defined by framework):
$config = $this->config->Site; $config = $this->config->Site;
$callback = function ($event) use ($config) { $callback = function ($event) use ($config) {
$theme = new \VuFind\Theme\Initializer($config, $event); $theme = new \VuFindTheme\Initializer($config, $event);
$theme->init(); $theme->init();
}; };
$this->events->attach('dispatch.error', $callback, 10000); $this->events->attach('dispatch.error', $callback, 10000);
......
...@@ -121,20 +121,20 @@ class Loader implements \Zend\Log\LoggerAwareInterface ...@@ -121,20 +121,20 @@ class Loader implements \Zend\Log\LoggerAwareInterface
/** /**
* Theme tools * Theme tools
* *
* @var \VuFind\Theme\ThemeInfo * @var \VuFindTheme\ThemeInfo
*/ */
protected $themeTools; protected $themeTools;
/** /**
* Constructor * Constructor
* *
* @param \Zend\Config\Config $config VuFind configuration * @param \Zend\Config\Config $config VuFind configuration
* @param \VuFind\Theme\ThemeInfo $theme VuFind theme tools * @param \VuFindTheme\ThemeInfo $theme VuFind theme tools
* @param \Zend\Http\Client $client HTTP client * @param \Zend\Http\Client $client HTTP client
* @param string $baseDir Directory to store downloaded images * @param string $baseDir Directory to store downloaded images
* (set to system temp dir if not otherwise specified) * (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 \Zend\Http\Client $client, $baseDir = null
) { ) {
$this->config = $config; $this->config = $config;
......
...@@ -76,7 +76,7 @@ class HeadLink extends \Zend\View\Helper\HeadLink ...@@ -76,7 +76,7 @@ class HeadLink extends \Zend\View\Helper\HeadLink
/** /**
* Get the theme tools. * Get the theme tools.
* *
* @return \VuFind\Theme\ThemeInfo * @return \VuFindTheme\ThemeInfo
*/ */
public function getThemeInfo() public function getThemeInfo()
{ {
......
...@@ -76,7 +76,7 @@ class HeadScript extends \Zend\View\Helper\HeadScript ...@@ -76,7 +76,7 @@ class HeadScript extends \Zend\View\Helper\HeadScript
/** /**
* Get the theme tools. * Get the theme tools.
* *
* @return \VuFind\Theme\ThemeInfo * @return \VuFindTheme\ThemeInfo
*/ */
public function getThemeInfo() public function getThemeInfo()
{ {
......
...@@ -42,7 +42,7 @@ class HeadThemeResources extends AbstractServiceLocator ...@@ -42,7 +42,7 @@ class HeadThemeResources extends AbstractServiceLocator
/** /**
* Get the theme resource container. * Get the theme resource container.
* *
* @return \VuFind\Theme\ResourceContainer * @return \VuFindTheme\ResourceContainer
*/ */
public function getThemeResourceContainer() public function getThemeResourceContainer()
{ {
......
...@@ -42,7 +42,7 @@ class ImageLink extends AbstractServiceLocator ...@@ -42,7 +42,7 @@ class ImageLink extends AbstractServiceLocator
/** /**
* Get the theme tools. * Get the theme tools.
* *
* @return \VuFind\Theme\ThemeInfo * @return \VuFindTheme\ThemeInfo
*/ */
public function getThemeInfo() public function getThemeInfo()
{ {
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
* @link http://vufind.org/wiki/building_a_recommendations_module Wiki * @link http://vufind.org/wiki/building_a_recommendations_module Wiki
*/ */
namespace VuFind\Theme\Root\Helper; namespace VuFind\Theme\Root\Helper;
use VuFind\Mobile,
Zend\View\Helper\AbstractHelper;
/** /**
* Mobile URL view helper * Mobile URL view helper
...@@ -38,7 +36,7 @@ use VuFind\Mobile, ...@@ -38,7 +36,7 @@ use VuFind\Mobile,
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/building_a_recommendations_module Wiki * @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 * Return the mobile version of the current URL if the user is on a mobile device
...@@ -48,9 +46,11 @@ class MobileUrl extends AbstractHelper ...@@ -48,9 +46,11 @@ class MobileUrl extends AbstractHelper
*/ */
public function __invoke() 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 // Do nothing special if we're not on a mobile device or no mobile theme is
// enabled: // enabled:
if (!Mobile::enabled() || !Mobile::detect()) { if (!$mobile->enabled() || !$mobile->detect()) {
return false; return false;
} }
......
<?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()
{
}
}
...@@ -25,10 +25,8 @@ ...@@ -25,10 +25,8 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org Main Site * @link http://vufind.org Main Site
*/ */
namespace VuFind\Theme; namespace VuFindTheme;
use VuFind\Mobile, use Zend\Config\Config,
VuFind\Mvc\View\Http\InjectTemplateListener,
Zend\Config\Config,
Zend\Mvc\MvcEvent, Zend\Mvc\MvcEvent,
Zend\Stdlib\RequestInterface as Request; Zend\Stdlib\RequestInterface as Request;
...@@ -67,10 +65,17 @@ class Initializer ...@@ -67,10 +65,17 @@ class Initializer
/** /**
* Theme tools object * Theme tools object
* *
* @var \VuFind\Theme\ThemeInfo * @var \VuFindTheme\ThemeInfo
*/ */
protected $tools; protected $tools;
/**
* Mobile interface detector
*
* @var \VuFindTheme\Mobile
*/
protected $mobile;
/** /**
* Constructor * Constructor
* *
...@@ -100,6 +105,10 @@ class Initializer ...@@ -100,6 +105,10 @@ class Initializer
// Get base directory from tools object: // Get base directory from tools object:
$this->tools = $this->serviceManager->get('VuFindTheme\ThemeInfo'); $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 ...@@ -193,7 +202,7 @@ class Initializer
{ {
// Load standard configuration options: // Load standard configuration options:
$standardTheme = $this->config->theme; $standardTheme = $this->config->theme;
$mobileTheme = isset($this->config->mobile_theme) $mobileTheme = $this->mobile->enabled()
? $this->config->mobile_theme : false; ? $this->config->mobile_theme : false;
// Find out if the user has a saved preference in the POST, URL or cookies: // Find out if the user has a saved preference in the POST, URL or cookies:
...@@ -204,7 +213,7 @@ class Initializer ...@@ -204,7 +213,7 @@ class Initializer
) )
); );
if (empty($selectedUI)) { if (empty($selectedUI)) {
$selectedUI = ($mobileTheme && Mobile::detect()) $selectedUI = ($mobileTheme && $this->mobile->detect())
? 'mobile' : 'standard'; ? 'mobile' : 'standard';
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org Main Site * @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 * VuFind "Inject Template" Listener -- this extends the core ZF2 class to adjust
......
...@@ -26,31 +26,37 @@ ...@@ -26,31 +26,37 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
* @category VuFind2 * @category VuFind2
* @package Mobile * @package Theme
* @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net> * @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://code.google.com/p/mobileesp/ MobileESP Project * @link http://code.google.com/p/mobileesp/ MobileESP Project
*/ */
namespace VuFind; namespace VuFindTheme;
use VuFind\Config\Reader as ConfigReader;
/** /**
* Mobile Device Detection Wrapper * Mobile Device Detection Wrapper
* *
* @category VuFind2 * @category VuFind2
* @package Mobile * @package Theme
* @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net> * @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://code.google.com/p/mobileesp/ MobileESP Project * @link http://code.google.com/p/mobileesp/ MobileESP Project
*/ */
class Mobile class Mobile
{ {
/**
* Are mobile themes enabled?
*
* @var bool
*/
protected $enabled = false;
/** /**
* Function to detect if a mobile device is being used. * Function to detect if a mobile device is being used.
* *
* @return bool * @return bool
*/ */
public static function detect() public function detect()
{ {
// Do the most exhaustive device detection possible; other method calls // Do the most exhaustive device detection possible; other method calls
// may be used instead of DetectMobileLong if you want to target a narrower // may be used instead of DetectMobileLong if you want to target a narrower
...@@ -59,14 +65,23 @@ class Mobile ...@@ -59,14 +65,23 @@ class Mobile
return $mobile->DetectMobileLong(); 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. * Function to check whether mobile theme is configured.
* *
* @return bool * @return bool
*/ */
public static function enabled() public function enabled()
{ {
$config = ConfigReader::getConfig(); return $this->enabled;
return isset($config->Site->mobile_theme);
} }
} }
\ No newline at end of file
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org Main Site * @link http://vufind.org Main Site
*/ */
namespace VuFind\Theme; namespace VuFindTheme;
/** /**
* VuFind Theme Public Resource Handler (for CSS, JS, etc.) * VuFind Theme Public Resource Handler (for CSS, JS, etc.)
...@@ -38,9 +38,32 @@ namespace VuFind\Theme; ...@@ -38,9 +38,32 @@ namespace VuFind\Theme;
*/ */
class ResourceContainer class ResourceContainer
{ {
/**
* CSS files
*
* @var array
*/
protected $css = array(); protected $css = array();
/**
* Javascript files
*
* @var array
*/
protected $js = array(); protected $js = array();
/**
* Favicon
*
* @var string
*/
protected $favicon = null; protected $favicon = null;
/**
* Encoding type
*
* @var string
*/
protected $encoding = 'UTF-8'; protected $encoding = 'UTF-8';
/** /**
...@@ -53,7 +76,7 @@ class ResourceContainer ...@@ -53,7 +76,7 @@ class ResourceContainer
*/ */
public function addCss($css) public function addCss($css)
{ {
if (!is_array($css) && !is_a($css, '\Traversable')) { if (!is_array($css) && !is_a($css, 'Traversable')) {
$css = array($css); $css = array($css);
} }
foreach ($css as $current) { foreach ($css as $current) {
...@@ -71,7 +94,7 @@ class ResourceContainer ...@@ -71,7 +94,7 @@ class ResourceContainer
*/ */
public function addJs($js) public function addJs($js)
{ {
if (!is_array($js) && !is_a($js, '\Traversable')) { if (!is_array($js) && !is_a($js, 'Traversable')) {
$js = array($js); $js = array($js);
} }
foreach ($js as $current) { foreach ($js as $current) {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org Main Site * @link http://vufind.org Main Site
*/ */
namespace VuFind\Theme; namespace VuFindTheme;
/** /**
* Class to represent currently-selected theme and related information. * Class to represent currently-selected theme and related information.
......
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