PHP 8.1.33
Preview: CThemeManager.php Size: 3.68 KB
/home/jambtst2015/www/framework/web/CThemeManager.php

<?php
/**
 * CThemeManager class file.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright 2008-2013 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

/**
 * CThemeManager manages the themes for the Web application.
 *
 * A theme is a collection of view/layout files and resource files
 * (e.g. css, image, js files). When a theme is active, {@link CController}
 * will look for the specified view/layout under the theme folder first.
 * The corresponding view/layout files will be used if the theme provides them.
 * Otherwise, the default view/layout files will be used.
 *
 * By default, each theme is organized as a directory whose name is the theme name.
 * All themes are located under the "WebRootPath/themes" directory.
 *
 * To activate a theme, set the {@link CWebApplication::setTheme theme} property
 * to be the name of that theme.
 *
 * Since a self-contained theme often contains resource files that are made
 * Web accessible, please make sure the view/layout files are protected from Web access.
 *
 * @property array $themeNames List of available theme names.
 * @property string $basePath The base path for all themes. Defaults to "WebRootPath/themes".
 * @property string $baseUrl The base URL for all themes. Defaults to "/WebRoot/themes".
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @package system.web
 * @since 1.0
 */
class CThemeManager extends CApplicationComponent
{
	/**
	 * default themes base path
	 */
	const DEFAULT_BASEPATH='themes';

	/**
	 * @var string the name of the theme class for representing a theme.
	 * Defaults to {@link CTheme}. This can also be a class name in dot syntax.
	 */
	public $themeClass='CTheme';

	private $_basePath=null;
	private $_baseUrl=null;


	/**
	 * @param string $name name of the theme to be retrieved
	 * @return CTheme the theme retrieved. Null if the theme does not exist.
	 */
	public function getTheme($name)
	{
		$themePath=$this->getBasePath().DIRECTORY_SEPARATOR.$name;
		if(is_dir($themePath))
		{
			$class=Yii::import($this->themeClass, true);
			return new $class($name,$themePath,$this->getBaseUrl().'/'.$name);
		}
		else
			return null;
	}

	/**
	 * @return array list of available theme names
	 */
	public function getThemeNames()
	{
		static $themes;
		if($themes===null)
		{
			$themes=array();
			$basePath=$this->getBasePath();
			$folder=@opendir($basePath);
			while(($file=@readdir($folder))!==false)
			{
				if($file!=='.' && $file!=='..' && $file!=='.svn' && $file!=='.gitignore' && is_dir($basePath.DIRECTORY_SEPARATOR.$file))
					$themes[]=$file;
			}
			closedir($folder);
			sort($themes);
		}
		return $themes;
	}

	/**
	 * @return string the base path for all themes. Defaults to "WebRootPath/themes".
	 */
	public function getBasePath()
	{
		if($this->_basePath===null)
			$this->setBasePath(dirname(Yii::app()->getRequest()->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH);
		return $this->_basePath;
	}

	/**
	 * @param string $value the base path for all themes.
	 * @throws CException if the base path does not exist
	 */
	public function setBasePath($value)
	{
		$this->_basePath=realpath($value);
		if($this->_basePath===false || !is_dir($this->_basePath))
			throw new CException(Yii::t('yii','Theme directory "{directory}" does not exist.',array('{directory}'=>$value)));
	}

	/**
	 * @return string the base URL for all themes. Defaults to "/WebRoot/themes".
	 */
	public function getBaseUrl()
	{
		if($this->_baseUrl===null)
			$this->_baseUrl=Yii::app()->getBaseUrl().'/'.self::DEFAULT_BASEPATH;
		return $this->_baseUrl;
	}

	/**
	 * @param string $value the base URL for all themes.
	 */
	public function setBaseUrl($value)
	{
		$this->_baseUrl=rtrim($value,'/');
	}
}

Directory Contents

Dirs: 9 × Files: 28

Name Size Perms Modified Actions
actions DIR
- drwxr-xr-x 2025-10-08 19:22:44
Edit Download
auth DIR
- drwxr-xr-x 2025-10-08 19:45:04
Edit Download
filters DIR
- drwxr-xr-x 2025-10-11 10:02:11
Edit Download
form DIR
- drwxr-xr-x 2025-10-09 05:45:59
Edit Download
helpers DIR
- drwxr-xr-x 2025-10-11 04:35:21
Edit Download
js DIR
- drwxr-xr-x 2025-10-15 09:54:12
Edit Download
renderers DIR
- drwxr-xr-x 2025-10-11 01:32:19
Edit Download
services DIR
- drwxr-xr-x 2025-10-12 12:01:04
Edit Download
widgets DIR
- drwxr-xr-x 2025-10-08 17:42:55
Edit Download
6.45 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
5.93 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
13.46 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
9.99 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.20 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
27.88 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
46.39 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
7.01 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
4.21 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
8.63 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
1.45 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
2.12 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
2.67 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
47.44 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
16.31 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
1.87 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
883 B lrw-r--r-- 2024-11-22 17:53:15
Edit Download
7.14 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
17.31 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
4.18 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.58 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.68 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
9.13 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
27.42 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
16.96 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
6.53 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
7.38 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
192.84 KB lrw-r--r-- 2025-11-04 15:12:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).