本文整理汇总了PHP中ThemeUtil::getIDFromName方法的典型用法代码示例。如果您正苦于以下问题:PHP ThemeUtil::getIDFromName方法的具体用法?PHP ThemeUtil::getIDFromName怎么用?PHP ThemeUtil::getIDFromName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThemeUtil
的用法示例。
在下文中一共展示了ThemeUtil::getIDFromName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_previewimage
/**
* Zikula_View function to display a preview image from a theme
*
* Available parameters:
* - name name of the theme to display the preview image for
* - name if set, the id assigned to the image
* - size if set, the size of the image to use from small, medium, large (optional: default 'medium')
* - assign if set, the title will be assigned to this variable
*
* Example
* {previewimage name=andreas08 size=large}
*
* @param array $params All attributes passed to this function from the template.
* @param Zikula_View $view Reference to the Zikula_View object.
*
* @see function.title.php::smarty_function_previewimage()
*
* @return string The markup to display the theme image.
*/
function smarty_function_previewimage($params, Zikula_View $view)
{
if (!isset($params['name'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('previewimage', 'name')));
return false;
}
if (!isset($params['size']) || !in_array($params['size'], array('large', 'medium', 'small'))) {
$params['size'] = 'medium';
}
$idstring = '';
if (isset($params['id'])) {
$idstring = " id=\"{$params['id']}\"";
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($params['name']));
$theme = ThemeUtil::getTheme($themeinfo['name']);
$themePath = null === $theme ? "themes/{$themeinfo['directory']}/images" : $theme->getRelativePath() . '/Resources/public/images';
if (file_exists("{$themePath}/preview_{$params['size']}.png")) {
$filesrc = "{$themePath}/preview_{$params['size']}.png";
} else {
$filesrc = "system/ThemeModule/Resources/public/images/preview_{$params['size']}.png";
}
$markup = "<img{$idstring} src=\"{$filesrc}\" alt=\"\" />";
if (isset($params['assign'])) {
$view->assign($params['assign'], $markup);
} else {
return $markup;
}
}
示例2: main
/**
* display theme changing user interface
*/
public function main()
{
// check if theme switching is allowed
if (!System::getVar('theme_change')) {
LogUtil::registerError($this->__('Notice: Theme switching is currently disabled.'));
$this->redirect(ModUtil::url('Users', 'user', 'main'));
}
if (!SecurityUtil::checkPermission('Theme::', '::', ACCESS_COMMENT)) {
return LogUtil::registerPermissionError();
}
// get our input
$startnum = FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : 1, 'GET');
// we need this value multiple times, so we keep it
$itemsperpage = $this->getVar('itemsperpage');
// get some use information about our environment
$currenttheme = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
// get all themes in our environment
$allthemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_USER);
$previewthemes = array();
$currentthemepic = null;
foreach ($allthemes as $key => $themeinfo) {
$themename = $themeinfo['name'];
if (file_exists($themepic = 'themes/'.DataUtil::formatForOS($themeinfo['directory']).'/images/preview_medium.png')) {
$themeinfo['previewImage'] = $themepic;
$themeinfo['largeImage'] = 'themes/'.DataUtil::formatForOS($themeinfo['directory']).'/images/preview_large.png';
} else {
$themeinfo['previewImage'] = 'system/Theme/images/preview_medium.png';
$themeinfo['largeImage'] = 'system/Theme/images/preview_large.png';
}
if ($themename == $currenttheme['name']) {
$currentthemepic = $themepic;
unset($allthemes[$key]);
} else {
$previewthemes[$themename] = $themeinfo;
}
}
$previewthemes = array_slice($previewthemes, $startnum-1, $itemsperpage);
$this->view->setCaching(Zikula_View::CACHE_DISABLED);
$this->view->assign('currentthemepic', $currentthemepic)
->assign('currenttheme', $currenttheme)
->assign('themes', $previewthemes)
->assign('defaulttheme', ThemeUtil::getInfo(ThemeUtil::getIDFromName(System::getVar('Default_Theme'))));
// assign the values for the pager plugin
$this->view->assign('pager', array('numitems' => sizeof($allthemes),
'itemsperpage' => $itemsperpage));
// Return the output that has been generated by this function
return $this->view->fetch('theme_user_main.tpl');
}
示例3: _getpurifierdefaultconfig
/**
* Retrieves default configuration array for HTML Purifier.
*
* @return array HTML Purifier default configuration settings.
*/
private static function _getpurifierdefaultconfig()
{
$purifierDefaultConfig = HTMLPurifier_Config::createDefault();
$purifierDefaultConfigValues = $purifierDefaultConfig->def->defaults;
$config = array();
foreach ($purifierDefaultConfigValues as $key => $val) {
$keys = explode(".", $key, 2);
$config[$keys[0]][$keys[1]] = $val;
}
$charset = ZLanguage::getEncoding();
if (strtolower($charset) != 'utf-8') {
// set a different character encoding with iconv
$config['Core']['Encoding'] = $charset;
// Note that HTML Purifier's support for non-Unicode encodings is crippled by the
// fact that any character not supported by that encoding will be silently
// dropped, EVEN if it is ampersand escaped. If you want to work around
// this, you are welcome to read docs/enduser-utf8.html in the full package for a fix,
// but please be cognizant of the issues the "solution" creates (for this
// reason, I do not include the solution in this document).
}
// determine doctype of current theme
// supported doctypes include:
//
// HTML 4.01 Strict
// HTML 4.01 Transitional
// XHTML 1.0 Strict
// XHTML 1.0 Transitional (default)
// XHTML 1.1
//
// TODO - we need a new theme field for doctype declaration
// for now we will use non-strict modes
$currentThemeID = ThemeUtil::getIDFromName(UserUtil::getTheme());
$themeInfo = ThemeUtil::getInfo($currentThemeID);
$useXHTML = (isset($themeInfo['xhtml']) && $themeInfo['xhtml']) ? true : false;
// as XHTML 1.0 Transitional is the default, we only set HTML (for now)
if (!$useXHTML) {
$config['HTML']['Doctype'] = 'HTML 4.01 Transitional';
}
// allow nofollow and imageviewer to be used as document relationships in the rel attribute
// see http://htmlpurifier.org/live/configdoc/plain.html#Attr.AllowedRel
$config['Attr']['AllowedRel'] = array('nofollow' => true, 'imageviewer' => true, 'lightbox' => true);
// allow Youtube by default
$config['Filter']['YouTube'] = false; // technically deprecated in favour of HTML.SafeEmbed and HTML.Object
// general enable for embeds and objects
$config['HTML']['SafeObject'] = true;
$config['Output']['FlashCompat'] = true;
$config['HTML']['SafeEmbed'] = true;
return $config;
}
示例4: smarty_function_themeinfo
/**
* Smarty function to display the theme info
*
* Example
* {themeinfo}
*
* @see function.themeinfo.php::smarty_function_themeinfo()
* @param array $params All attributes passed to this function from the template
* @param object $smarty Reference to the Smarty object
* @return string the themeinfo
*/
function smarty_function_themeinfo($params, $smarty)
{
LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('themeinfo', '$themeinfo')), E_USER_DEPRECATED);
$thistheme = UserUtil::getTheme();
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($thistheme));
$themecredits = '<!-- ' . __f('Theme: %1$s by %2$s - %3$s', array(DataUtil::formatForDisplay($themeinfo['display']), DataUtil::formatForDisplay($themeinfo['author']), DataUtil::formatForDisplay($themeinfo['contact']))) . ' -->';
return $themecredits;
}
示例5: __construct
/**
* Constructor.
*
* @param Zikula_ServiceManager $serviceManager ServiceManager.
* @param string $moduleName Module name ("zikula" for system plugins).
* @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
*/
public function __construct(Zikula_ServiceManager $serviceManager, $moduleName = '', $caching = null)
{
$this->serviceManager = $serviceManager;
$this->eventManager = $this->serviceManager->get('event_dispatcher');
$this->request = \ServiceUtil::get('request');
// set the error reporting level
$this->error_reporting = isset($GLOBALS['ZConfig']['Debug']['error_reporting']) ? $GLOBALS['ZConfig']['Debug']['error_reporting'] : E_ALL;
$this->error_reporting &= ~E_USER_DEPRECATED;
$this->allow_php_tag = true;
// get variables from input
$module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
$type = FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
$func = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING);
// set vars based on the module structures
$this->homepage = PageUtil::isHomepage();
$this->type = strtolower(!$this->homepage ? $type : System::getVar('starttype'));
$this->func = strtolower(!$this->homepage ? $func : System::getVar('startfunc'));
// Initialize the module property with the name of
// the topmost module. For Hooks, Blocks, API Functions and others
// you need to set this property to the name of the respective module!
$this->toplevelmodule = ModUtil::getName();
if (!$moduleName) {
$moduleName = $this->toplevelmodule;
}
$this->modinfo = ModUtil::getInfoFromName($moduleName);
$this->module = array($moduleName => $this->modinfo);
// initialise environment vars
$this->language = ZLanguage::getLanguageCode();
$this->baseurl = System::getBaseUrl();
$this->baseuri = System::getBaseUri();
// system info
$this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
$this->theme = $theme = $this->themeinfo['directory'];
$themeBundle = ThemeUtil::getTheme($this->themeinfo['name']);
//---- Plugins handling -----------------------------------------------
// add plugin paths
switch ($this->modinfo['type']) {
case ModUtil::TYPE_MODULE:
$mpluginPathNew = "modules/" . $this->modinfo['directory'] . "/Resources/views/plugins";
$mpluginPath = "modules/" . $this->modinfo['directory'] . "/templates/plugins";
break;
case ModUtil::TYPE_SYSTEM:
$mpluginPathNew = "system/" . $this->modinfo['directory'] . "/Resources/views/plugins";
$mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
break;
default:
$mpluginPathNew = "system/" . $this->modinfo['directory'] . "/Resources/views/plugins";
$mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
}
// add standard plugin search path
$this->plugins_dir = array();
$this->addPluginDir('config/plugins');
// Official override
$this->addPluginDir('lib/legacy/viewplugins');
// Core plugins
$this->addPluginDir(isset($themeBundle) ? $themeBundle->getRelativePath() . '/plugins' : "themes/{$theme}/plugins");
// Theme plugins
$this->addPluginDir('plugins');
// Smarty core plugins
$this->addPluginDir($mpluginPathNew);
// Plugins for current module
$this->addPluginDir($mpluginPath);
// Plugins for current module
// check if the 'type' parameter in the URL is admin or adminplugin
$legacyControllerType = FormUtil::getPassedValue('lct', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
if ($type === 'admin' || $type === 'adminplugin' || $legacyControllerType === 'admin') {
// include plugins of the Admin module to the plugins_dir array
if (!$this instanceof Zikula_View_Theme) {
$this->addPluginDir('system/AdminModule/Resources/views/plugins');
} else {
$this->load_filter('output', 'admintitle');
}
}
// theme plugins module overrides
$themePluginsPath = isset($themeBundle) ? $themeBundle->getRelativePath() . '/modules/$moduleName/plugins' : "themes/{$theme}/templates/modules/{$moduleName}/plugins";
$this->addPluginDir($themePluginsPath);
//---- Cache handling -------------------------------------------------
if ($caching && in_array((int) $caching, array(0, 1, 2))) {
$this->caching = (int) $caching;
} else {
$this->caching = (int) ModUtil::getVar('ZikulaThemeModule', 'render_cache');
}
$this->compile_id = '';
$this->cache_id = '';
// template compilation
$this->compile_dir = CacheUtil::getLocalDir('view_compiled');
$this->compile_check = ModUtil::getVar('ZikulaThemeModule', 'render_compile_check');
$this->force_compile = ModUtil::getVar('ZikulaThemeModule', 'render_force_compile');
// template caching
$this->cache_dir = CacheUtil::getLocalDir('view_cache');
$this->cache_lifetime = ModUtil::getVar('ZikulaThemeModule', 'render_lifetime');
$this->expose_template = ModUtil::getVar('ZikulaThemeModule', 'render_expose_template') == true ? true : false;
// register resource type 'z' this defines the way templates are searched
//.........这里部分代码省略.........
示例6: __construct
/**
* Constructor.
*
* @param Zikula_ServiceManager $serviceManager ServiceManager.
* @param string $themeName Theme name.
*/
public function __construct(Zikula_ServiceManager $serviceManager, $themeName)
{
// store our theme information
$this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themeName));
// prevents any case mismatch
$themeName = $this->themeinfo['name'];
foreach (array('name', 'directory', 'version', 'state', 'xhtml') as $key) {
$this->{$key} = $this->themeinfo[$key];
}
parent::__construct($serviceManager);
if ($this->themeinfo['i18n']) {
ZLanguage::bindThemeDomain($this->name);
// property for {gt} template plugin to detect language domain
$this->domain = ZLanguage::getThemeDomain($this->name);
} else {
$this->domain = null;
}
EventUtil::attachCustomHandlers("themes/{$themeName}/EventHandlers");
EventUtil::attachCustomHandlers("themes/{$themeName}/lib/{$themeName}/EventHandlers");
$event = new \Zikula\Core\Event\GenericEvent($this);
$this->eventManager->dispatch('theme.preinit', $event);
// change some base settings from our parent class
// template compilation
$this->compile_dir = CacheUtil::getLocalDir('Theme_compiled');
$this->compile_check = ModUtil::getVar('ZikulaThemeModule', 'compile_check');
$this->force_compile = ModUtil::getVar('ZikulaThemeModule', 'force_compile');
// template caching
$this->cache_dir = CacheUtil::getLocalDir('Theme_cache');
$this->caching = (int) ModUtil::getVar('ZikulaThemeModule', 'enablecache');
//if ($this->caching) {
// $this->cache_modified_check = true;
//}
// if caching and is not an admin controller
if ($this->caching && strpos($this->type, 'admin') !== 0) {
$modulesnocache = array_filter(explode(',', ModUtil::getVar('ZikulaThemeModule', 'modulesnocache')));
if (in_array($this->toplevelmodule, $modulesnocache)) {
$this->caching = Zikula_View::CACHE_DISABLED;
}
} else {
$this->caching = Zikula_View::CACHE_DISABLED;
}
// halt caching for write operations to prevent strange things happening
if (isset($_POST) && count($_POST) != 0) {
$this->caching = Zikula_View::CACHE_DISABLED;
}
// and also for GET operations with csrftoken/authkey
if (isset($_GET['csrftoken']) || isset($_GET['authkey'])) {
$this->caching = Zikula_View::CACHE_DISABLED;
}
$this->cache_lifetime = ModUtil::getVar('ZikulaThemeModule', 'cache_lifetime');
if (!$this->homepage) {
$this->cache_lifetime = ModUtil::getVar('ZikulaThemeModule', 'cache_lifetime_mods');
}
// assign all our base template variables
$this->_base_vars();
// define the plugin directories
$this->_plugin_dirs();
// load the theme configuration
$this->load_config();
// check for cached output
// turn on caching, check for cached output and then disable caching
// to prevent blocks from being cached
if ($this->caching && $this->is_cached($this->themeconfig['page'], $this->cache_id)) {
$this->display($this->themeconfig['page'], $this->cache_id);
System::shutdown();
}
// register page vars output filter
$this->load_filter('output', 'pagevars');
// register short urls output filter
if (System::getVar('shorturls')) {
$this->load_filter('output', 'shorturls');
}
// register trim whitespace output filter if requried
if (ModUtil::getVar('ZikulaThemeModule', 'trimwhitespace')) {
$this->load_filter('output', 'trimwhitespace');
}
$this->load_filter('output', 'asseturls');
$event = new \Zikula\Core\Event\GenericEvent($this);
$this->eventManager->dispatch('theme.init', $event);
$this->startOutputBuffering();
}
示例7: delete
/**
* delete a theme
*
*/
public function delete($args)
{
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'REQUEST');
$objectid = FormUtil::getPassedValue('objectid', isset($args['objectid']) ? $args['objectid'] : null, 'REQUEST');
$confirmation = FormUtil::getPassedValue('confirmation', null, 'POST');
if (!empty($objectid)) {
$mid = $objectid;
}
// Get the theme info
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if ($themeinfo == false) {
return LogUtil::registerError($this->__('Sorry! No such theme found.'), 404);
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::", ACCESS_DELETE)) {
return LogUtil::registerPermissionError();
}
// Check for confirmation.
if (empty($confirmation)) {
// No confirmation yet
// Add the message id
$this->view->assign($themeinfo);
// Return the output that has been generated by this function
return $this->view->fetch('theme_admin_delete.tpl');
}
// If we get here it means that the user has confirmed the action
$this->checkCsrfToken();
$deletefiles = FormUtil::getPassedValue('deletefiles', 0, 'POST');
// Delete the admin message
// The return value of the function is checked
if (ModUtil::apiFunc('Theme', 'admin', 'delete', array('themename' => $themename, 'deletefiles' => $deletefiles))) {
// Success
LogUtil::registerStatus($this->__('Done! Deleted it.'));
}
// This function generated no output, and so now it is complete we redirect
// the user to an appropriate page for them to carry on their work
$this->redirect(ModUtil::url('Theme', 'admin', 'view'));
}
示例8: queryStringDecode
//.........这里部分代码省略.........
// validation of the first parameter as language code
if (ZLanguage::isLangParam($args[0]) && in_array($args[0], ZLanguage::getInstalledLanguages())) {
// checks if the language is not enforced and this url is passing the default lang
if (!ZLanguage::getLangUrlRule() && $lang == $args[0]) {
// redirects the passed arguments without the default site language
array_shift($args);
foreach ($args as $k => $v) {
$args[$k] = urlencode($v);
}
self::redirect(self::getBaseUrl() . $frontController . ($args ? implode('/', $args) : ''), array(), 302, true);
self::shutDown();
}
self::queryStringSetVar('lang', $args[0], $request);
array_shift($args);
} elseif (ZLanguage::getLangUrlRule()) {
// if the lang is forced, redirects the passed arguments plus the lang
foreach ($args as $k => $v) {
$args[$k] = urlencode($v);
}
$langTheme = isset($_GET['theme']) ? "{$lang}/{$_GET['theme']}" : $lang;
self::redirect(self::getBaseUrl() . $frontController . $langTheme . '/' . implode('/', $args), array(), 302, true);
self::shutDown();
}
// check if there are remaining arguments
if ($args) {
// try the first argument as a module
$modinfo = ModUtil::getInfoFromName($args[0]);
if ($modinfo) {
array_shift($args);
}
}
// if that fails maybe it's a theme
if ($args && !$modinfo) {
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($args[0]));
if ($themeinfo) {
self::queryStringSetVar('theme', $themeinfo['name'], $request);
$request->attributes->set('_theme', $themeinfo['name']);
// now shift the vars and continue as before
array_shift($args);
if ($args) {
$modinfo = ModUtil::getInfoFromName($args[0]);
if ($modinfo) {
array_shift($args);
}
}
}
}
// if there are parameters (not homepage)
// try to see if there's a default shortURLs module
if ($args && !$modinfo) {
// add the default module handler into the code
$modinfo = ModUtil::getInfoFromName(self::getVar('shorturlsdefaultmodule'));
}
}
// check if there is a module and a custom url handler for it
// if not decode the url using the default handler
if ($modinfo && $modinfo['type'] != 0) {
// prepare the arguments to the module handler
array_unshift($args, '');
// support for 1.2- empty parameter due the initial explode
array_unshift($args, $modinfo['url']);
// set the REQUEST parameters
self::queryStringSetVar('module', $modinfo['name'], $request);
// the user.function name can be the second argument string, set a default
// later the custom module handler (if exists) must setup a new one if needed
self::queryStringSetVar('type', 'user', $request);
示例9: create
/**
* create theme
*/
public function create($args)
{
// Argument check
if (!isset($args['themeinfo']) || !isset($args['themeinfo']['name']) || empty($args['themeinfo']) || empty($args['themeinfo']['name'])) {
$url = ModUtil::url('Theme', 'admin', 'new');
return LogUtil::registerError(__("Error: You must enter at least the theme name."), null, $url);
}
$themeinfo = DataUtil::formatForOS($args['themeinfo']);
// check for some invalid input
if (!isset($themeinfo['displayname']) || empty($themeinfo['displayname'])) {
$themeinfo['displayname'] = $themeinfo['name'];
}
if (!isset($themeinfo['description']) || empty($themeinfo['description'])) {
$themeinfo['description'] = $themeinfo['name'];
}
// strip the theme name of any unwanted characters
$themeinfo['name'] = preg_replace('/[^a-z0-9_]/i', '_', $themeinfo['name']);
// check if theme already exists
if (ThemeUtil::getIDFromName($themeinfo['name'])) {
return LogUtil::registerError(__('Error! Could not create the new item.'));
}
// create the directory structure
$dirs = array(
'',
'/docs',
'/images',
'/plugins',
'/locale',
'/locale/en',
'/locale/en/LC_MESSAGES',
'/style',
'/templates',
'/templates/blocks',
'/templates/config',
'/templates/modules'
);
foreach ($dirs as $dir) {
if (!mkdir("themes/{$themeinfo['name']}/{$dir}") || !touch("themes/{$themeinfo['name']}/{$dir}/index.html")) {
return LogUtil::registerError(__('Error! Could not create the new item.'));
}
}
$versionfile = $args['versionfile'];
$potfile = $args['potfile'];
$palettesfile = $args['palettesfile'];
$variablesfile = $args['variablesfile'];
$pageconfigurationsfile = $args['pageconfigurationsfile'];
$pageconfigurationfile = $args['pageconfigurationfile'];
$pagetemplatefile = $args['pagetemplatefile'];
$cssfile = $args['cssfile'];
$blockfile = $args['blockfile'];
$files = array(
"themes/$themeinfo[name]/version.php" => 'versionfile',
"themes/$themeinfo[name]/locale/theme_".$themeinfo['name'].".pot" => 'potfile',
"themes/$themeinfo[name]/templates/config/themepalettes.ini" => 'palettesfile',
"themes/$themeinfo[name]/templates/config/themevariables.ini" => 'variablesfile',
"themes/$themeinfo[name]/templates/config/pageconfigurations.ini" => 'pageconfigurationsfile',
"themes/$themeinfo[name]/templates/config/master.ini" => 'pageconfigurationfile',
"themes/$themeinfo[name]/templates/master.tpl" => 'pagetemplatefile',
"themes/$themeinfo[name]/templates/blocks/block.tpl" => 'blockfile',
"themes/$themeinfo[name]/style/style.css" => 'cssfile'
);
// write the files
foreach ($files as $filename => $filevar) {
$handle = fopen($filename, 'w');
if (!$handle) {
return LogUtil::registerError(__f('Error! Could not open file so that it could be written to: %s', $filename));
}
if (!fwrite($handle, $$filevar)) {
fclose($handle);
return LogUtil::registerError(__f('Error! could not write to file: %s', $filename));
}
fclose($handle);
}
return true;
}
示例10: getTheme
/**
* Get the user's theme.
*
* This function will return the current theme for the user.
* Order of theme priority:
* - page-specific
* - category
* - user
* - system
*
* @param boolean $force True to ignore the cache.
*
* @return string the name of the user's theme
* @throws RuntimeException If this function was unable to calculate theme name.
*/
public static function getTheme($force = false)
{
static $pagetheme;
if (isset($pagetheme) && !$force) {
return $pagetheme;
}
/** @var $request Request */
$request = \ServiceUtil::get('request');
$theme = FormUtil::getPassedValue('theme', null, 'GETPOST');
if (!empty($theme) && SecurityUtil::checkPermission('ZikulaThemeModule::ThemeChange', '::', ACCESS_COMMENT)) {
// theme passed as parameter takes priority, can be RSS, Atom, Printer or other
$pagetheme = $theme;
} else {
// check for specified alternative site view domain and theme
$themedomain = ModUtil::getVar('ZikulaThemeModule', 'alt_theme_domain', '');
if ($themedomain && $_SERVER['SERVER_NAME'] == $themedomain && ModUtil::getVar('ZikulaThemeModule', 'alt_theme_name', '')) {
$pagetheme = ModUtil::getVar('ZikulaThemeModule', 'alt_theme_name');
}
}
// Retrieve required parameters
$type = FormUtil::getPassedValue('type', null, 'GETPOST');
$legacyType = FormUtil::getPassedValue('lct', null, 'GETPOST');
if ($type != $legacyType) {
// BC support (see #2051 for example)
$type = $legacyType;
}
if (null === $type) {
// routing preventing type from being set, get from request attributes
$type = $request->get('_zkType');
}
// Page-specific theme
$qstring = System::serverGetVar('QUERY_STRING');
if (!empty($pagetheme)) {
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($pagetheme));
if ($themeinfo['state'] == ThemeUtil::STATE_ACTIVE && ($themeinfo['user'] || $themeinfo['system'] || $themeinfo['admin'] && $type == 'admin') && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
$pagetheme = $themeinfo['name'];
$themeName = self::_getThemeFilterEvent($themeinfo['name'], 'page-specific');
$request->attributes->set('_theme', $themeName);
return $themeName;
}
}
// check for an admin theme
$adminSections = array('admin', 'adminplugin');
if (in_array($type, $adminSections) && SecurityUtil::checkPermission('::', '::', ACCESS_EDIT)) {
$admintheme = ModUtil::getVar('ZikulaAdminModule', 'admintheme');
if (!empty($admintheme)) {
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($admintheme));
if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
$pagetheme = $themeinfo['name'];
$themeName = self::_getThemeFilterEvent($themeinfo['name'], 'admin-theme');
$request->attributes->set('_theme', $themeName);
return $themeName;
}
}
}
// set a new theme for the user
$newtheme = FormUtil::getPassedValue('newtheme', null, 'GETPOST');
if (!empty($newtheme) && System::getVar('theme_change')) {
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($newtheme));
if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
if (self::isLoggedIn()) {
self::setVar('theme', $newtheme);
} else {
SessionUtil::setVar('theme', $newtheme);
}
$pagetheme = $themeinfo['name'];
$themeName = self::_getThemeFilterEvent($themeinfo['name'], 'new-theme');
$request->attributes->set('_theme', $themeName);
return $themeName;
}
}
// User theme
if (System::getVar('theme_change') || SecurityUtil::checkPermission('::', '::', ACCESS_ADMIN)) {
if (self::isLoggedIn()) {
$usertheme = self::getVar('theme');
} else {
$usertheme = SessionUtil::getVar('theme');
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($usertheme));
if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
$pagetheme = $themeinfo['name'];
$themeName = self::_getThemeFilterEvent($themeinfo['name'], 'user-theme');
$request->attributes->set('_theme', $themeName);
return $themeName;
}
//.........这里部分代码省略.........
示例11: display
public function display($blockinfo)
{
// check if the module is available
if (!ModUtil::available('Theme')) {
return;
}
// check if theme switching is allowed
if (!System::getVar('theme_change')) {
return;
}
// security check
if (!SecurityUtil::checkPermission( "Themeswitcherblock::", "$blockinfo[title]::", ACCESS_READ)) {
return;
}
// Get variables from content block
$vars = BlockUtil::varsFromContent($blockinfo['content']);
// Defaults
if (empty($vars['format'])) {
$vars['format'] = 1;
}
// get some use information about our environment
$currenttheme = UserUtil::getTheme();
// get all themes in our environment
$themes = ThemeUtil::getAllThemes();
// get some use information about our environment
$currenttheme = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
// get all themes in our environment
$themes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_USER);
$previewthemes = array();
$currentthemepic = null;
foreach ($themes as $themeinfo) {
$themename = $themeinfo['name'];
if (file_exists($themepic = 'themes/'.DataUtil::formatForOS($themeinfo['directory']).'/images/preview_small.png')) {
$themeinfo['previewImage'] = $themepic;
} else {
$themeinfo['previewImage'] = 'system/Theme/images/preview_small.png';
}
$previewthemes[$themename] = $themeinfo;
if ($themename == $currenttheme['name']) {
$currentthemepic = $themeinfo['previewImage'];
}
}
$this->view->assign($vars)
->assign('currentthemepic', $currentthemepic)
->assign('currenttheme', $currenttheme)
->assign('themes', $previewthemes);
$blockinfo['content'] = $this->view->fetch('theme_block_themeswitcher.tpl');
return BlockUtil::themeBlock($blockinfo);
}
示例12: themeBlock
/**
* Display a block based on the current theme.
*
* @param array $blockinfo Block info.
*
* @return string The rendered output.
*/
public static function themeBlock($blockinfo)
{
static $themeinfo, $themedir, $upb, $downb;
if (!isset($blockinfo['bid'])) {
$blockinfo['bid'] = '';
}
if (!isset($blockinfo['title'])) {
$blockinfo['title'] = '';
}
if (UserUtil::isLoggedIn() && ModUtil::getVar('Blocks', 'collapseable') == 1 && isset($blockinfo['collapsable']) && ($blockinfo['collapsable'] == '1')) {
if (!isset($themeinfo)) {
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
$themedir = DataUtil::formatForOS($themeinfo['directory']);
}
// check for collapsable menus being enabled, and setup the collapsable menu image.
if (!isset($upb)) {
if (file_exists('themes/' . $themedir . '/images/upb.png')) {
$upb = '<img src="themes/' . $themedir . '/images/upb.png" alt="-" />';
} elseif (file_exists('themes/' . $themedir . '/images/14_layer_raiselayer.png')) {
$upb = '<img src="themes/' . $themedir . '/images/14_layer_raiselayer.png" alt="-" />';
} else {
$upb = '<img src="images/icons/extrasmall/14_layer_raiselayer.png" alt="-" />';
}
}
if (!isset($downb)) {
if (file_exists('themes/' . $themedir . '/images/downb.png')) {
$downb = '<img src="themes/' . $themedir . '/images/downb.png" alt="+" />';
} elseif (file_exists('themes/' . $themedir . '/images/14_layer_lowerlayer.png')) {
$downb = '<img src="themes/' . $themedir . '/images/14_layer_lowerlayer.png" alt="+" />';
} else {
$downb = '<img src="images/icons/extrasmall/14_layer_lowerlayer.png" alt="+" />';
}
}
if (self::checkUserBlock($blockinfo) == '1') {
if (!empty($blockinfo['title'])) {
$blockinfo['minbox'] = '<a href="' . DataUtil::formatForDisplay(ModUtil::url('Blocks', 'user', 'changestatus', array('bid' => $blockinfo['bid']))) . '">' . $upb . '</a>';
}
} else {
$blockinfo['content'] = '';
if (!empty($blockinfo['title'])) {
$blockinfo['minbox'] = '<a href="' . DataUtil::formatForDisplay(ModUtil::url('Blocks', 'user', 'changestatus', array('bid' => $blockinfo['bid']))) . '">' . $downb . '</a>';
}
}
// end collapseable menu config
} else {
$blockinfo['minbox'] = '';
}
return Zikula_View_Theme::getInstance()->themesidebox($blockinfo);
}
示例13: __construct
/**
* Constructor.
*
* @param Zikula_ServiceManager $serviceManager ServiceManager.
* @param string $moduleName Module name ("zikula" for system plugins).
* @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
*/
public function __construct(Zikula_ServiceManager $serviceManager, $moduleName = '', $caching = null)
{
$this->serviceManager = $serviceManager;
$this->eventManager = $this->serviceManager->getService('zikula.eventmanager');
$this->request = $this->serviceManager->getService('request');
// set the error reporting level
$this->error_reporting = isset($GLOBALS['ZConfig']['Debug']['error_reporting']) ? $GLOBALS['ZConfig']['Debug']['error_reporting'] : E_ALL;
$this->allow_php_tag = true;
// get variables from input
$module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
$type = FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
$func = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING);
// set vars based on the module structures
$this->homepage = empty($module) ? true : false;
$this->type = strtolower(!$this->homepage ? $type : System::getVar('starttype'));
$this->func = strtolower(!$this->homepage ? $func : System::getVar('startfunc'));
// Initialize the module property with the name of
// the topmost module. For Hooks, Blocks, API Functions and others
// you need to set this property to the name of the respective module!
$this->toplevelmodule = ModUtil::getName();
if (!$moduleName) {
$moduleName = $this->toplevelmodule;
}
$this->modinfo = ModUtil::getInfoFromName($moduleName);
$this->module = array($moduleName => $this->modinfo);
// initialise environment vars
$this->language = ZLanguage::getLanguageCode();
$this->baseurl = System::getBaseUrl();
$this->baseuri = System::getBaseUri();
// system info
$this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
$this->theme = $theme = $this->themeinfo['directory'];
//---- Plugins handling -----------------------------------------------
// add plugin paths
switch ($this->modinfo['type'])
{
case ModUtil::TYPE_MODULE :
$mpluginPath = "modules/" . $this->modinfo['directory'] . "/templates/plugins";
$mpluginPathOld = "modules/" . $this->modinfo['directory'] . "/pntemplates/plugins";
break;
case ModUtil::TYPE_SYSTEM :
$mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
$mpluginPathOld = "system/" . $this->modinfo['directory'] . "/pntemplates/plugins";
break;
default:
$mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
$mpluginPathOld = "system/" . $this->modinfo['directory'] . "/pntemplates/plugins";
}
// add standard plugin search path
$this->plugins_dir = array();
$this->addPluginDir('config/plugins'); // Official override
$this->addPluginDir('lib/viewplugins'); // Core plugins
$this->addPluginDir("themes/$theme/plugins"); // Theme plugins
$this->addPluginDir('plugins'); // Smarty core plugins
$this->addPluginDir($mpluginPath); // Plugins for current module
// check if the 'type' parameter in the URL is admin and if yes,
// include system/Admin/templates/plugins to the plugins_dir array
if ($type === 'admin') {
if (!$this instanceof Zikula_View_Theme) {
$this->addPluginDir('system/Admin/templates/plugins');
} else {
$this->load_filter('output', 'admintitle');
}
}
// adds legacy plugin paths if needed
if (System::isLegacyMode()) {
$this->addPluginDir('lib/legacy/plugins'); // Core legacy plugins
$this->addPluginDir($mpluginPathOld); // Module plugins (legacy paths)
$this->addPluginDir("themes/$theme/templates/modules/$moduleName/plugins"); // Module override in themes
}
//---- Cache handling -------------------------------------------------
if ($caching && in_array((int)$caching, array(0, 1, 2))) {
$this->caching = (int)$caching;
} else {
$this->caching = (int)ModUtil::getVar('Theme', 'render_cache');
}
// write actions should not be cached or weird things happen
if (isset($_POST) && count($_POST) != 0) {
$this->caching = Zikula_View::CACHE_DISABLED;
}
//.........这里部分代码省略.........
示例14: themeBlock
/**
* Display a block based on the current theme.
*
* @param array $blockinfo Block info.
*
* @return string The rendered output.
*/
public static function themeBlock($blockinfo)
{
static $themeinfo, $themedir, $upb, $downb;
if (!isset($blockinfo['bid'])) {
$blockinfo['bid'] = '';
}
if (!isset($blockinfo['title'])) {
$blockinfo['title'] = '';
}
if (UserUtil::isLoggedIn() && ModUtil::getVar('ZikulaBlocksModule', 'collapseable') == 1 && isset($blockinfo['collapsable']) && $blockinfo['collapsable'] == '1') {
if (!isset($themeinfo)) {
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
$themedir = DataUtil::formatForOS($themeinfo['directory']);
}
// check for collapsable menus being enabled, and setup the collapsable menu image.
if (!isset($upb)) {
if (file_exists('themes/' . $themedir . '/images/upb.png')) {
$upb = '<img src="themes/' . $themedir . '/images/upb.png" alt="-" />';
} elseif (file_exists('themes/' . $themedir . '/images/14_layer_raiselayer.png')) {
$upb = '<img src="themes/' . $themedir . '/images/14_layer_raiselayer.png" alt="-" />';
} else {
$upb = '<img src="images/icons/extrasmall/14_layer_raiselayer.png" alt="-" />';
}
}
if (!isset($downb)) {
if (file_exists('themes/' . $themedir . '/images/downb.png')) {
$downb = '<img src="themes/' . $themedir . '/images/downb.png" alt="+" />';
} elseif (file_exists('themes/' . $themedir . '/images/14_layer_lowerlayer.png')) {
$downb = '<img src="themes/' . $themedir . '/images/14_layer_lowerlayer.png" alt="+" />';
} else {
$downb = '<img src="images/icons/extrasmall/14_layer_lowerlayer.png" alt="+" />';
}
}
$checkUserBlock = self::checkUserBlock($blockinfo);
if ($checkUserBlock) {
if (!empty($blockinfo['title'])) {
$blockinfo['minbox'] = '<a href="' . DataUtil::formatForDisplay(ModUtil::url('ZikulaBlocksModule', 'user', 'changestatus', array('bid' => $blockinfo['bid']))) . '">' . $upb . '</a>';
}
} else {
$blockinfo['content'] = '';
if (!empty($blockinfo['title'])) {
$blockinfo['minbox'] = '<a href="' . DataUtil::formatForDisplay(ModUtil::url('ZikulaBlocksModule', 'user', 'changestatus', array('bid' => $blockinfo['bid']))) . '">' . $downb . '</a>';
}
}
// end collapseable menu config
} else {
$blockinfo['minbox'] = '';
}
// try twig theme first (note: theme is already set by this point)
$container = ServiceUtil::getManager();
$twigBasedThemeBlock = $container->get('zikula_core.common.theme_engine')->wrapBcBlockInTheme($blockinfo);
if ($twigBasedThemeBlock) {
return $twigBasedThemeBlock;
}
// theme is not twig based revert to smarty
return Zikula_View_Theme::getInstance()->themesidebox($blockinfo);
}
示例15: pnThemeGetIDFromName
/**
* pnThemeGetIDFromName
*
* get themeID given its name
*
* @author Mark West
* @link http://www.markwest.me.uk
* @param 'theme' the name of the theme
* @return int theme ID
*/
function pnThemeGetIDFromName($theme)
{
LogUtil::log(__f('Warning! Function %1$s is deprecated. Please use %2$s instead.', array('pnThemeGetIDFromName()', 'ThemeUtil::getIDFromName()')), E_USER_DEPRECATED);
return ThemeUtil::getIDFromName($theme);
}