From 5dcc3b283d7c678f409ce4ba2afa7866cf77cdf3 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 4 Jan 2013 12:35:47 -0500 Subject: [PATCH] Changed theme configuration to use PHP files instead of .ini files in order to allow more flexible helper configuration. --- .../VuFind/src/VuFind/Theme/Initializer.php | 38 +++++--------- module/VuFind/src/VuFind/Theme/Tools.php | 12 ++--- themes/blueprint/theme.config.php | 29 +++++++++++ themes/blueprint/theme.ini | 20 ------- themes/jquerymobile/theme.config.php | 24 +++++++++ themes/jquerymobile/theme.ini | 15 ------ themes/root/theme.config.php | 52 +++++++++++++++++++ themes/root/theme.ini | 47 ----------------- 8 files changed, 124 insertions(+), 113 deletions(-) create mode 100644 themes/blueprint/theme.config.php delete mode 100644 themes/blueprint/theme.ini create mode 100644 themes/jquerymobile/theme.config.php delete mode 100644 themes/jquerymobile/theme.ini create mode 100644 themes/root/theme.config.php delete mode 100644 themes/root/theme.ini diff --git a/module/VuFind/src/VuFind/Theme/Initializer.php b/module/VuFind/src/VuFind/Theme/Initializer.php index 52bdc0218e4..b06a737aa59 100644 --- a/module/VuFind/src/VuFind/Theme/Initializer.php +++ b/module/VuFind/src/VuFind/Theme/Initializer.php @@ -272,26 +272,18 @@ class Initializer /** * Support method for setUpThemes -- register view helpers. * - * @param string $theme Name of theme - * @param string $namespace Namespace for view helpers - * @param array $helpers Helpers to register + * @param array $helpers Helper settings * * @return void */ - protected function setUpThemeViewHelpers($theme, $namespace, $helpers) + protected function setUpThemeViewHelpers($helpers) { - // Ignore null helper array: - if (is_null($helpers)) { - return; - } - // Grab the helper loader from the view manager: $loader = $this->serviceManager->get('viewmanager')->getHelperManager(); // Register all the helpers: - foreach ($helpers as $helper) { - $loader->setInvokableClass(strtolower($helper), "$namespace\\$helper"); - } + $config = new \Zend\ServiceManager\Config($helpers); + $config->configureServiceManager($loader); } /** @@ -310,31 +302,29 @@ class Initializer // Apply the loaded theme settings in reverse for proper inheritance: foreach ($themes as $key=>$currentThemeInfo) { - if ($helperNS = $currentThemeInfo->get('helper_namespace')) { - $this->setUpThemeViewHelpers( - $key, $helperNS, $currentThemeInfo->get('helpers_to_register') - ); + if (isset($currentThemeInfo['helpers'])) { + $this->setUpThemeViewHelpers($currentThemeInfo['helpers']); } // Add template path: $templatePathStack[] = $this->baseDir . "/$key/templates"; // Add CSS and JS dependencies: - if ($css = $currentThemeInfo->get('css')) { - $resources->addCss($css); + if (isset($currentThemeInfo['css'])) { + $resources->addCss($currentThemeInfo['css']); } - if ($js = $currentThemeInfo->get('js')) { - $resources->addJs($js); + if (isset($currentThemeInfo['js'])) { + $resources->addJs($currentThemeInfo['js']); } // Select encoding: - if ($encoding = $currentThemeInfo->get('encoding')) { - $resources->setEncoding($encoding); + if (isset($currentThemeInfo['encoding'])) { + $resources->setEncoding($currentThemeInfo['encoding']); } // Select favicon: - if ($favicon = $currentThemeInfo->get('favicon')) { - $resources->setFavicon($favicon); + if (isset($currentThemeInfo['favicon'])) { + $resources->setFavicon($currentThemeInfo['favicon']); } } diff --git a/module/VuFind/src/VuFind/Theme/Tools.php b/module/VuFind/src/VuFind/Theme/Tools.php index 48aa978670b..f63592b8299 100644 --- a/module/VuFind/src/VuFind/Theme/Tools.php +++ b/module/VuFind/src/VuFind/Theme/Tools.php @@ -97,7 +97,7 @@ class Tools */ protected function getThemeConfig($theme) { - return $this->baseDir . "/$theme/theme.ini"; + return $this->baseDir . "/$theme/theme.config.php"; } /** @@ -145,11 +145,9 @@ class Tools $this->allThemeInfo = array(); $currentTheme = $this->getTheme(); do { - $iniReader = new \Zend\Config\Reader\Ini(); - $this->allThemeInfo[$currentTheme] = new \Zend\Config\Config( - $iniReader->fromFile($this->getThemeConfig($currentTheme)) - ); - $currentTheme = $this->allThemeInfo[$currentTheme]->extends; + $this->allThemeInfo[$currentTheme] + = include $this->getThemeConfig($currentTheme); + $currentTheme = $this->allThemeInfo[$currentTheme]['extends']; } while ($currentTheme); } @@ -183,7 +181,7 @@ class Tools return $returnFile ? $file : $currentTheme; } } - $currentTheme = $allThemeInfo[$currentTheme]->extends; + $currentTheme = $allThemeInfo[$currentTheme]['extends']; } return null; diff --git a/themes/blueprint/theme.config.php b/themes/blueprint/theme.config.php new file mode 100644 index 00000000000..979db456d4b --- /dev/null +++ b/themes/blueprint/theme.config.php @@ -0,0 +1,29 @@ +<?php +return array( + 'extends' => 'root', + 'css' => array( + 'blueprint/screen.css:screen, projection', + 'blueprint/print.css:print', + 'blueprint/ie.css:screen, projection:lt IE 8', + 'jquery-ui/css/smoothness/jquery-ui.css', + 'styles.css:screen, projection', + 'print.css:print', + 'ie.css:screen, projection:lt IE 8', + ), + 'js' => array( + 'jquery.min.js', + 'jquery.form.js', + 'jquery.metadata.js', + 'jquery.validate.min.js', + 'jquery-ui/js/jquery-ui.js', + 'lightbox.js', + 'common.js', + ), + 'favicon' => 'vufind-favicon.ico', + 'helpers' => array( + 'invokables' => array( + 'layoutclass' => 'VuFind\Theme\Blueprint\Helper\LayoutClass', + 'search' => 'VuFind\Theme\Blueprint\Helper\Search', + ) + ) +); \ No newline at end of file diff --git a/themes/blueprint/theme.ini b/themes/blueprint/theme.ini deleted file mode 100644 index 67c6e2a5f25..00000000000 --- a/themes/blueprint/theme.ini +++ /dev/null @@ -1,20 +0,0 @@ -extends = root -css[] = "blueprint/screen.css:screen, projection" -css[] = "blueprint/print.css:print" -css[] = "blueprint/ie.css:screen, projection:lt IE 8" -css[] = "jquery-ui/css/smoothness/jquery-ui.css" -css[] = "styles.css:screen, projection" -css[] = "print.css:print" -css[] = "ie.css:screen, projection:lt IE 8" -js[] = "jquery.min.js" -js[] = "jquery.form.js" -js[] = "jquery.metadata.js" -js[] = "jquery.validate.min.js" -js[] = "jquery-ui/js/jquery-ui.js" -js[] = "lightbox.js" -js[] = "common.js" -favicon = "vufind-favicon.ico" - -helper_namespace = "VuFind\Theme\Blueprint\Helper" -helpers_to_register[] = "LayoutClass" -helpers_to_register[] = "Search" \ No newline at end of file diff --git a/themes/jquerymobile/theme.config.php b/themes/jquerymobile/theme.config.php new file mode 100644 index 00000000000..8a2ccefd0db --- /dev/null +++ b/themes/jquerymobile/theme.config.php @@ -0,0 +1,24 @@ +<?php +return array( + 'extends' => 'root', + 'css' => array( + 'jquery.mobile-1.0rc2.min.css', + 'styles.css', + 'formats.css', + ), + 'js' => array( + 'jquery-1.6.4.min.js', + 'common.js', + 'jquery.mobile-1.0rc2.min.js', + 'jquery.cookie.js', + 'cart_cookie.js', + 'cart.js', + 'scripts.js', + ), + 'favicon' => 'vufind-favicon.ico', + 'helpers' => array( + 'invokables' => array( + 'mobilemenu' => 'VuFind\Theme\jQueryMobile\Helper\MobileMenu' + ) + ), +); \ No newline at end of file diff --git a/themes/jquerymobile/theme.ini b/themes/jquerymobile/theme.ini deleted file mode 100644 index 6d38d16cc4c..00000000000 --- a/themes/jquerymobile/theme.ini +++ /dev/null @@ -1,15 +0,0 @@ -extends = root -css[] = "jquery.mobile-1.0rc2.min.css" -css[] = "styles.css" -css[] = "formats.css" -js[] = "jquery-1.6.4.min.js" -js[] = "common.js" -js[] = "jquery.mobile-1.0rc2.min.js" -js[] = "jquery.cookie.js" -js[] = "cart_cookie.js" -js[] = "cart.js" -js[] = "scripts.js" -favicon = "vufind-favicon.ico" - -helper_namespace = "VuFind\Theme\jQueryMobile\Helper" -helpers_to_register[] = "MobileMenu" \ No newline at end of file diff --git a/themes/root/theme.config.php b/themes/root/theme.config.php new file mode 100644 index 00000000000..5a88177e3d5 --- /dev/null +++ b/themes/root/theme.config.php @@ -0,0 +1,52 @@ +<?php +return array( + 'extends' => false, + 'helpers' => array( + 'invokables' => array( + 'addellipsis' => 'VuFind\Theme\Root\Helper\AddEllipsis', + 'addthis' => 'VuFind\Theme\Root\Helper\AddThis', + 'auth' => 'VuFind\Theme\Root\Helper\Auth', + 'authornotes' => 'VuFind\Theme\Root\Helper\AuthorNotes', + 'browse' => 'VuFind\Theme\Root\Helper\Browse', + 'cart' => 'VuFind\Theme\Root\Helper\Cart', + 'citation' => 'VuFind\Theme\Root\Helper\Citation', + 'context' => 'VuFind\Theme\Root\Helper\Context', + 'currentpath' => 'VuFind\Theme\Root\Helper\CurrentPath', + 'datetime' => 'VuFind\Theme\Root\Helper\DateTime', + 'displaylanguageoption' => 'VuFind\Theme\Root\Helper\DisplayLanguageOption', + 'excerpt' => 'VuFind\Theme\Root\Helper\Excerpt', + 'flashmessages' => 'VuFind\Theme\Root\Helper\Flashmessages', + 'getlastsearchlink' => 'VuFind\Theme\Root\Helper\GetLastSearchLink', + 'headlink' => 'VuFind\Theme\Root\Helper\HeadLink', + 'headscript' => 'VuFind\Theme\Root\Helper\HeadScript', + 'headthemeresources' => 'VuFind\Theme\Root\Helper\HeadThemeResources', + 'highlight' => 'VuFind\Theme\Root\Helper\Highlight', + 'ils' => 'VuFind\Theme\Root\Helper\Ils', + 'imagelink' => 'VuFind\Theme\Root\Helper\ImageLink', + 'inlinescript' => 'VuFind\Theme\Root\Helper\InlineScript', + 'jqueryvalidation' => 'VuFind\Theme\Root\Helper\JqueryValidation', + 'mobileurl' => 'VuFind\Theme\Root\Helper\MobileUrl', + 'openurl' => 'VuFind\Theme\Root\Helper\OpenUrl', + 'printms' => 'VuFind\Theme\Root\Helper\Printms', + 'proxyurl' => 'VuFind\Theme\Root\Helper\ProxyUrl', + 'recommend' => 'VuFind\Theme\Root\Helper\Recommend', + 'record' => 'VuFind\Theme\Root\Helper\Record', + 'recordlink' => 'VuFind\Theme\Root\Helper\RecordLink', + 'related' => 'VuFind\Theme\Root\Helper\Related', + 'renderarray' => 'VuFind\Theme\Root\Helper\RenderArray', + 'resultfeed' => 'VuFind\Theme\Root\Helper\ResultFeed', + 'reviews' => 'VuFind\Theme\Root\Helper\Reviews', + 'searchoptions' => 'VuFind\Theme\Root\Helper\SearchOptions', + 'safemoneyformat' => 'VuFind\Theme\Root\Helper\SafeMoneyFormat', + 'sortfacetlist' => 'VuFind\Theme\Root\Helper\SortFacetList', + 'summon' => 'VuFind\Theme\Root\Helper\Summon', + 'syndeticsplus' => 'VuFind\Theme\Root\Helper\SyndeticsPlus', + 'systememail' => 'VuFind\Theme\Root\Helper\SystemEmail', + 'transesc' => 'VuFind\Theme\Root\Helper\TransEsc', + 'translate' => 'VuFind\Theme\Root\Helper\Translate', + 'truncate' => 'VuFind\Theme\Root\Helper\Truncate', + 'userlist' => 'VuFind\Theme\Root\Helper\UserList', + 'videoclips' => 'VuFind\Theme\Root\Helper\VideoClips', + ) + ), +); diff --git a/themes/root/theme.ini b/themes/root/theme.ini deleted file mode 100644 index 8a29b3c6633..00000000000 --- a/themes/root/theme.ini +++ /dev/null @@ -1,47 +0,0 @@ -extends = false - -helper_namespace = "VuFind\Theme\Root\Helper" -helpers_to_register[] = "AddEllipsis" -helpers_to_register[] = "AddThis" -helpers_to_register[] = "Auth" -helpers_to_register[] = "AuthorNotes" -helpers_to_register[] = "Browse" -helpers_to_register[] = "Cart" -helpers_to_register[] = "Citation" -helpers_to_register[] = "Context" -helpers_to_register[] = "CurrentPath" -helpers_to_register[] = "DateTime" -helpers_to_register[] = "DisplayLanguageOption" -helpers_to_register[] = "Excerpt" -helpers_to_register[] = "Flashmessages" -helpers_to_register[] = "GetLastSearchLink" -helpers_to_register[] = "HeadLink" -helpers_to_register[] = "HeadScript" -helpers_to_register[] = "HeadThemeResources" -helpers_to_register[] = "Highlight" -helpers_to_register[] = "Ils" -helpers_to_register[] = "ImageLink" -helpers_to_register[] = "InlineScript" -helpers_to_register[] = "JqueryValidation" -helpers_to_register[] = "MobileUrl" -helpers_to_register[] = "OpenUrl" -helpers_to_register[] = "Printms" -helpers_to_register[] = "ProxyUrl" -helpers_to_register[] = "Recommend" -helpers_to_register[] = "Record" -helpers_to_register[] = "RecordLink" -helpers_to_register[] = "Related" -helpers_to_register[] = "RenderArray" -helpers_to_register[] = "ResultFeed" -helpers_to_register[] = "Reviews" -helpers_to_register[] = "SearchOptions" -helpers_to_register[] = "SafeMoneyFormat" -helpers_to_register[] = "SortFacetList" -helpers_to_register[] = "Summon" -helpers_to_register[] = "SyndeticsPlus" -helpers_to_register[] = "SystemEmail" -helpers_to_register[] = "TransEsc" -helpers_to_register[] = "Translate" -helpers_to_register[] = "Truncate" -helpers_to_register[] = "UserList" -helpers_to_register[] = "VideoClips" -- GitLab