Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/skin_helper.php
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
// search for previously compiled skin | // search for previously compiled skin | ||||
$last_compiled = $this->_getLastCompiled( mb_strtolower($style_info['Name']) ); | $last_compiled = $this->_getLastCompiled( mb_strtolower($style_info['Name']) ); | ||||
if ($last_compiled) { | if ($last_compiled) { | ||||
// found | // found | ||||
$ret = $this->getSkinPath(true, $last_compiled); | $ret = $this->getSkinPath(true, $last_compiled); | ||||
} | } | ||||
else { | else { | ||||
// not found (try to compile on the fly) | // not found (try to compile on the fly) | ||||
/** @var kDBItem $skin */ | |||||
$skin = $this->Application->recallObject('skin.-item', null, Array ('skip_autoload' => true)); | $skin = $this->Application->recallObject('skin.-item', null, Array ('skip_autoload' => true)); | ||||
/* @var $skin kDBItem */ | |||||
$skin->Load(1, 'IsPrimary'); | $skin->Load(1, 'IsPrimary'); | ||||
$last_compiled = $this->compile($skin); | $last_compiled = $this->compile($skin); | ||||
$ret = $last_compiled ? $this->getSkinPath(true, $last_compiled) : ''; | $ret = $last_compiled ? $this->getSkinPath(true, $last_compiled) : ''; | ||||
} | } | ||||
} | } | ||||
if (array_key_exists('file_only', $params) && $params['file_only']) { | if (array_key_exists('file_only', $params) && $params['file_only']) { | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | |||||
* @param string $style_name | * @param string $style_name | ||||
* @return int | * @return int | ||||
*/ | */ | ||||
function _getLastCompiled($style_name) | function _getLastCompiled($style_name) | ||||
{ | { | ||||
$last_compiled = 0; | $last_compiled = 0; | ||||
$iterator = new DirectoryIterator( $this->_getStylesheetPath() . DIRECTORY_SEPARATOR ); | $iterator = new DirectoryIterator( $this->_getStylesheetPath() . DIRECTORY_SEPARATOR ); | ||||
/* @var $file_info DirectoryIterator */ | /** @var DirectoryIterator $file_info */ | ||||
foreach ($iterator as $file_info) { | foreach ($iterator as $file_info) { | ||||
if ( !$file_info->isFile() ) { | if ( !$file_info->isFile() ) { | ||||
continue; | continue; | ||||
} | } | ||||
$regs = $this->isSkinFile( $file_info->getFilename() ); | $regs = $this->isSkinFile( $file_info->getFilename() ); | ||||
if ( $regs && $regs[1] == $style_name && $regs[2] > $last_compiled ) { | if ( $regs && $regs[1] == $style_name && $regs[2] > $last_compiled ) { | ||||
$last_compiled = max($last_compiled, $regs[2]); | $last_compiled = max($last_compiled, $regs[2]); | ||||
} | } | ||||
} | } | ||||
return $last_compiled; | return $last_compiled; | ||||
} | } | ||||
/** | /** | ||||
* Deletes all compiled versions of all skins | * Deletes all compiled versions of all skins | ||||
* | * | ||||
*/ | */ | ||||
function deleteCompiled() | function deleteCompiled() | ||||
{ | { | ||||
$iterator = new DirectoryIterator( $this->_getStylesheetPath() . DIRECTORY_SEPARATOR ); | $iterator = new DirectoryIterator( $this->_getStylesheetPath() . DIRECTORY_SEPARATOR ); | ||||
/* @var $file_info DirectoryIterator */ | /** @var DirectoryIterator $file_info */ | ||||
foreach ($iterator as $file_info) { | foreach ($iterator as $file_info) { | ||||
if ( $file_info->isFile() && $this->isSkinFile( $file_info->getFilename() ) ) { | if ( $file_info->isFile() && $this->isSkinFile( $file_info->getFilename() ) ) { | ||||
unlink( $file_info->getPathname() ); | unlink( $file_info->getPathname() ); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Determines if given file is admin skin file | * Determines if given file is admin skin file | ||||
* | * | ||||
* @param string $filename | * @param string $filename | ||||
* @return array|bool | * @return array|bool | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function isSkinFile($filename) | protected function isSkinFile($filename) | ||||
{ | { | ||||
if ( preg_match(self::SKIN_REGEXP, $filename, $regs) ) { | if ( preg_match(self::SKIN_REGEXP, $filename, $regs) ) { | ||||
return $regs; | return $regs; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |