Public Member Functions | |
setStore ($store) | |
getStore () | |
setArea ($area) | |
getArea () | |
setPackageName ($name= '') | |
setAllGetOld ($storePackageArea) | |
getPackageName () | |
designPackageExists ($packageName, $area=self::DEFAULT_AREA) | |
setTheme () | |
getTheme ($type) | |
getDefaultTheme () | |
updateParamDefaults (array &$params) | |
getBaseDir (array $params) | |
getSkinBaseDir (array $params=array()) | |
getLocaleBaseDir (array $params=array()) | |
getSkinBaseUrl (array $params=array()) | |
validateFile ($file, array $params) | |
getFilename ($file, array $params) | |
getFallbackTheme () | |
getLayoutFilename ($file, array $params=array()) | |
getTemplateFilename ($file, array $params=array()) | |
getLocaleFileName ($file, array $params=array()) | |
getSkinUrl ($file=null, array $params=array()) | |
getPackageList () | |
getThemeList ($package=null) | |
Public Attributes | |
const | DEFAULT_AREA = 'frontend' |
const | DEFAULT_PACKAGE = 'default' |
const | DEFAULT_THEME = 'default' |
const | FALLBACK_THEME = 'default' |
Protected Member Functions | |
_checkUserAgentAgainstRegexps ($regexpsConfigPath) | |
Protected Attributes | |
$_store = null | |
$_area | |
$_name | |
$_theme | |
$_rootDir | |
$_config = null |
Definition at line 28 of file Package.php.
_checkUserAgentAgainstRegexps | ( | $ | regexpsConfigPath | ) | [protected] |
Get regex rules from config and check user-agent against them
Rules must be stored in config as a serialized array(['regexp']=>'...', ['value'] => '...') Will return false or found string.
string | $regexpsConfigPath |
Definition at line 500 of file Package.php.
00501 { 00502 if (!empty($_SERVER['HTTP_USER_AGENT'])) { 00503 if (!empty(self::$_customThemeTypeCache[$regexpsConfigPath])) { 00504 return self::$_customThemeTypeCache[$regexpsConfigPath]; 00505 } 00506 $configValueSerialized = Mage::getStoreConfig($regexpsConfigPath, $this->getStore()); 00507 if ($configValueSerialized) { 00508 $regexps = @unserialize($configValueSerialized); 00509 if (!empty($regexps)) { 00510 foreach ($regexps as $rule) { 00511 if (!empty(self::$_regexMatchCache[$rule['regexp']][$_SERVER['HTTP_USER_AGENT']])) { 00512 self::$_customThemeTypeCache[$regexpsConfigPath] = $rule['value']; 00513 return $rule['value']; 00514 } 00515 $regexp = $rule['regexp']; 00516 if (false === strpos($regexp, '/', 0)) { 00517 $regexp = '/' . $regexp . '/'; 00518 } 00519 if (@preg_match($regexp, $_SERVER['HTTP_USER_AGENT'])) { 00520 self::$_regexMatchCache[$rule['regexp']][$_SERVER['HTTP_USER_AGENT']] = true; 00521 self::$_customThemeTypeCache[$regexpsConfigPath] = $rule['value']; 00522 return $rule['value']; 00523 } 00524 } 00525 } 00526 } 00527 } 00528 return false; 00529 }
designPackageExists | ( | $ | packageName, | |
$ | area = self::DEFAULT_AREA | |||
) |
Definition at line 194 of file Package.php.
00195 { 00196 return is_dir(Mage::getBaseDir('design') . DS . $area . DS . $packageName); 00197 }
getArea | ( | ) |
Retrieve package area
Definition at line 117 of file Package.php.
00118 { 00119 if (is_null($this->_area)) { 00120 $this->_area = self::DEFAULT_AREA; 00121 } 00122 return $this->_area; 00123 }
getBaseDir | ( | array $ | params | ) |
Definition at line 273 of file Package.php.
00274 { 00275 $this->updateParamDefaults($params); 00276 $baseDir = (empty($params['_relative']) ? Mage::getBaseDir('design').DS : ''). 00277 $params['_area'].DS.$params['_package'].DS.$params['_theme'].DS.$params['_type']; 00278 return $baseDir; 00279 }
getDefaultTheme | ( | ) |
getFallbackTheme | ( | ) |
Definition at line 384 of file Package.php.
00385 { 00386 return Mage::getStoreConfig('design/theme/default', $this->getStore()); 00387 }
getFilename | ( | $ | file, | |
array $ | params | |||
) |
Use this one to get existing file name with fallback to default
$params['_type'] is required
string | $file | |
array | $params |
Definition at line 361 of file Package.php.
00362 { 00363 Varien_Profiler::start(__METHOD__); 00364 $this->updateParamDefaults($params); 00365 $filename = $this->validateFile($file, $params); 00366 if (false===$filename) { 00367 $params['_theme'] = $this->getFallbackTheme(); 00368 $filename = $this->validateFile($file, $params); 00369 if (false===$filename) { 00370 if ($this->getDefaultTheme()===$params['_theme']) { 00371 return $params['_default']; 00372 } 00373 $params['_theme'] = $this->getDefaultTheme(); 00374 $filename = $this->validateFile($file, $params); 00375 if (false===$filename) { 00376 return $params['_default']; 00377 } 00378 } 00379 } 00380 Varien_Profiler::stop(__METHOD__); 00381 return $filename; 00382 }
Definition at line 389 of file Package.php.
00390 { 00391 $params['_type'] = 'layout'; 00392 return $this->getFilename($file, $params); 00393 }
Definition at line 289 of file Package.php.
00290 { 00291 $this->updateParamDefaults($params); 00292 $baseDir = (empty($params['_relative']) ? Mage::getBaseDir('design').DS : ''). 00293 $params['_area'].DS.$params['_package'].DS.$params['_theme'] . DS . 'locale' . DS . 00294 Mage::app()->getLocale()->getLocaleCode(); 00295 return $baseDir; 00296 }
Definition at line 401 of file Package.php.
00402 { 00403 $params['_type'] = 'locale'; 00404 return $this->getFilename($file, $params); 00405 }
getPackageList | ( | ) |
Definition at line 449 of file Package.php.
00450 { 00451 $directory = Mage::getBaseDir('design') . DS . 'frontend'; 00452 return $this->_listDirectories($directory); 00453 }
getPackageName | ( | ) |
Retrieve package name
Definition at line 186 of file Package.php.
00187 { 00188 if (null === $this->_name) { 00189 $this->setPackageName(); 00190 } 00191 return $this->_name; 00192 }
Definition at line 281 of file Package.php.
00282 { 00283 $this->updateParamDefaults($params); 00284 $baseDir = (empty($params['_relative']) ? Mage::getBaseDir('skin').DS : ''). 00285 $params['_area'].DS.$params['_package'].DS.$params['_theme']; 00286 return $baseDir; 00287 }
Definition at line 298 of file Package.php.
00299 { 00300 $this->updateParamDefaults($params); 00301 $baseUrl = Mage::getBaseUrl('skin', isset($params['_secure'])?(bool)$params['_secure']:null) 00302 .$params['_area'].'/'.$params['_package'].'/'.$params['_theme'].'/'; 00303 return $baseUrl; 00304 }
Get skin file url
string | $file | |
array | $params |
Definition at line 414 of file Package.php.
00415 { 00416 Varien_Profiler::start(__METHOD__); 00417 if (empty($params['_type'])) { 00418 $params['_type'] = 'skin'; 00419 } 00420 if (empty($params['_default'])) { 00421 $params['_default'] = false; 00422 } 00423 $this->updateParamDefaults($params); 00424 if (!empty($file)) { 00425 $filename = $this->validateFile($file, $params); 00426 if (false===$filename) { 00427 00428 $params['_theme'] = $this->getFallbackTheme(); 00429 $filename = $this->validateFile($file, $params); 00430 if (false===$filename) { 00431 if ($this->getDefaultTheme()===$params['_theme']) { 00432 return $params['_default']; 00433 } 00434 $params['_theme'] = $this->getDefaultTheme(); 00435 $filename = $this->validateFile($file, $params); 00436 if (false===$filename) { 00437 return $params['_default']; 00438 } 00439 } 00440 00441 } 00442 } 00443 00444 $url = $this->getSkinBaseUrl($params).(!empty($file) ? $file : ''); 00445 Varien_Profiler::stop(__METHOD__); 00446 return $url; 00447 }
getStore | ( | ) |
Retrieve store
Definition at line 92 of file Package.php.
00093 { 00094 if ($this->_store === null) { 00095 return Mage::app()->getStore(); 00096 } 00097 return $this->_store; 00098 }
Definition at line 395 of file Package.php.
00396 { 00397 $params['_type'] = 'template'; 00398 return $this->getFilename($file, $params); 00399 }
getTheme | ( | $ | type | ) |
Definition at line 223 of file Package.php.
00224 { 00225 if (empty($this->_theme[$type])) { 00226 $this->_theme[$type] = Mage::getStoreConfig('design/theme/'.$type, $this->getStore()); 00227 if ($type!=='default' && empty($this->_theme[$type])) { 00228 $this->_theme[$type] = $this->getTheme('default'); 00229 if (empty($this->_theme[$type])) { 00230 $this->_theme[$type] = self::DEFAULT_THEME; 00231 } 00232 00233 // "locale", "layout", "template" 00234 } 00235 } 00236 00237 // + "default", "skin" 00238 00239 // set exception value for theme, if defined in config 00240 $customThemeType = $this->_checkUserAgentAgainstRegexps("design/theme/{$type}_ua_regexp"); 00241 if ($customThemeType) { 00242 $this->_theme[$type] = $customThemeType; 00243 } 00244 00245 return $this->_theme[$type]; 00246 }
getThemeList | ( | $ | package = null |
) |
Definition at line 455 of file Package.php.
00456 { 00457 $result = array(); 00458 00459 if (is_null($package)){ 00460 foreach ($this->getPackageList() as $package){ 00461 $result[$package] = $this->getThemeList($package); 00462 } 00463 } else { 00464 $directory = Mage::getBaseDir('design') . DS . 'frontend' . DS . $package; 00465 $result = $this->_listDirectories($directory); 00466 } 00467 00468 return $result; 00469 }
setAllGetOld | ( | $ | storePackageArea | ) |
Set store/package/area at once, and get respective values, that were before
$storePackageArea must be assoc array. The keys may be: 'store', 'package', 'area'
array | $storePackageArea |
Definition at line 163 of file Package.php.
00164 { 00165 $oldValues = array(); 00166 if (array_key_exists('store', $storePackageArea)) { 00167 $oldValues['store'] = $this->getStore(); 00168 $this->setStore($storePackageArea['store']); 00169 } 00170 if (array_key_exists('package', $storePackageArea)) { 00171 $oldValues['package'] = $this->getPackageName(); 00172 $this->setPackageName($storePackageArea['package']); 00173 } 00174 if (array_key_exists('area', $storePackageArea)) { 00175 $oldValues['area'] = $this->getArea(); 00176 $this->setArea($storePackageArea['area']); 00177 } 00178 return $oldValues; 00179 }
setArea | ( | $ | area | ) |
Set package area
string | $area |
Definition at line 106 of file Package.php.
setPackageName | ( | $ | name = '' |
) |
Set package name In case of any problem, the default will be set.
string | $name |
Definition at line 132 of file Package.php.
00133 { 00134 if (empty($name)) { 00135 // see, if exceptions for user-agents defined in config 00136 $customPackage = $this->_checkUserAgentAgainstRegexps('design/package/ua_regexp'); 00137 if ($customPackage) { 00138 $this->_name = $customPackage; 00139 } 00140 else { 00141 $this->_name = Mage::getStoreConfig('design/package/name', $this->getStore()); 00142 } 00143 } 00144 else { 00145 $this->_name = $name; 00146 } 00147 // make sure not to crash, if wrong package specified 00148 if (!$this->designPackageExists($this->_name, $this->getArea())) { 00149 $this->_name = self::DEFAULT_PACKAGE; 00150 } 00151 return $this; 00152 }
setStore | ( | $ | store | ) |
Set store
string|integer|Mage_Core_Model_Store | $store |
Definition at line 81 of file Package.php.
setTheme | ( | ) |
Declare design package theme params
Definition at line 204 of file Package.php.
00205 { 00206 switch (func_num_args()) { 00207 case 1: 00208 foreach (array('layout', 'template', 'skin', 'locale') as $type) { 00209 $this->_theme[$type] = func_get_arg(0); 00210 } 00211 break; 00212 00213 case 2: 00214 $this->_theme[func_get_arg(0)] = func_get_arg(1); 00215 break; 00216 00217 default: 00218 throw Mage::exception(Mage::helper('core')->__('Wrong number of arguments for %s', __METHOD__)); 00219 } 00220 return $this; 00221 }
updateParamDefaults | ( | array &$ | params | ) |
Definition at line 253 of file Package.php.
00254 { 00255 if ($this->getStore()) { 00256 $params['_store'] = $this->getStore(); 00257 } 00258 if (empty($params['_area'])) { 00259 $params['_area'] = $this->getArea(); 00260 } 00261 if (empty($params['_package'])) { 00262 $params['_package'] = $this->getPackageName(); 00263 } 00264 if (empty($params['_theme'])) { 00265 $params['_theme'] = $this->getTheme( (isset($params['_type'])) ? $params['_type'] : '' ); 00266 } 00267 if (empty($params['_default'])) { 00268 $params['_default'] = false; 00269 } 00270 return $this; 00271 }
validateFile | ( | $ | file, | |
array $ | params | |||
) |
Get absolute file path for requested file or false if doesn't exist
Possible params:
template
_package: design package, if not set = default
string | $file | |
array | $params |
Definition at line 325 of file Package.php.
00326 { 00327 Varien_Profiler::start(__METHOD__); 00328 switch ($params['_type']) { 00329 case 'skin': 00330 $fileName = $this->getSkinBaseDir($params); 00331 break; 00332 00333 case 'locale': 00334 $fileName = $this->getLocaleBasedir($params); 00335 break; 00336 00337 default: 00338 $fileName = $this->getBaseDir($params); 00339 break; 00340 } 00341 $fileName.= DS.$file; 00342 00343 $testFile = (empty($params['_relative']) ? '' : Mage::getBaseDir('design').DS) . $fileName; 00344 00345 if ($this->getDefaultTheme()!==$params['_theme'] && !file_exists($testFile)) { 00346 return false; 00347 } 00348 Varien_Profiler::stop(__METHOD__); 00349 return $fileName; 00350 }
$_area [protected] |
Definition at line 50 of file Package.php.
$_config = null [protected] |
Definition at line 73 of file Package.php.
$_name [protected] |
Definition at line 57 of file Package.php.
$_rootDir [protected] |
Definition at line 71 of file Package.php.
$_store = null [protected] |
Definition at line 43 of file Package.php.
$_theme [protected] |
Definition at line 64 of file Package.php.
const DEFAULT_AREA = 'frontend' |
Definition at line 30 of file Package.php.
const DEFAULT_PACKAGE = 'default' |
Definition at line 31 of file Package.php.
const DEFAULT_THEME = 'default' |
Definition at line 32 of file Package.php.
const FALLBACK_THEME = 'default' |
Definition at line 33 of file Package.php.