Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/stylesheets/stylesheets_item.php
Show All 13 Lines | |||||
defined('FULL_PATH') or die('restricted access!'); | defined('FULL_PATH') or die('restricted access!'); | ||||
class StylesheetsItem extends kDBItem | class StylesheetsItem extends kDBItem | ||||
{ | { | ||||
function Compile() | function Compile() | ||||
{ | { | ||||
/** @var SelectorsItem $selector_item */ | |||||
$selector_item = $this->Application->recallObject('selectors.item', 'selectors', Array('live_table'=>true, 'skip_autoload' => true) ); | $selector_item = $this->Application->recallObject('selectors.item', 'selectors', Array('live_table'=>true, 'skip_autoload' => true) ); | ||||
/* @var $selector_item SelectorsItem */ | |||||
$parent_field = $this->Application->getUnitOption($selector_item->Prefix, 'ForeignKey'); | $parent_field = $this->Application->getUnitOption($selector_item->Prefix, 'ForeignKey'); | ||||
$sql_template = 'SELECT '.$selector_item->IDField.' FROM '.$selector_item->TableName.' WHERE '.$parent_field.' = %s ORDER BY SelectorName ASC'; | $sql_template = 'SELECT '.$selector_item->IDField.' FROM '.$selector_item->TableName.' WHERE '.$parent_field.' = %s ORDER BY SelectorName ASC'; | ||||
$selectors_ids = $this->Conn->GetCol( sprintf($sql_template, $this->GetID() ) ); | $selectors_ids = $this->Conn->GetCol( sprintf($sql_template, $this->GetID() ) ); | ||||
$ret = '/* This file is generated automatically. Don\'t edit it manually ! */'."\n\n"; | $ret = '/* This file is generated automatically. Don\'t edit it manually ! */'."\n\n"; | ||||
foreach($selectors_ids as $selector_id) | foreach($selectors_ids as $selector_id) | ||||
{ | { | ||||
$selector_item->Load($selector_id); | $selector_item->Load($selector_id); | ||||
$ret .= $selector_item->CompileStyle()."\n"; | $ret .= $selector_item->CompileStyle()."\n"; | ||||
} | } | ||||
$ret .= $this->GetDBField('AdvancedCSS'); | $ret .= $this->GetDBField('AdvancedCSS'); | ||||
$compile_ts = adodb_mktime(); | $compile_ts = adodb_mktime(); | ||||
$css_path = WRITEABLE . '/stylesheets/'; | $css_path = WRITEABLE . '/stylesheets/'; | ||||
/** @var FileHelper $file_helper */ | |||||
$file_helper = $this->Application->recallObject('FileHelper'); | $file_helper = $this->Application->recallObject('FileHelper'); | ||||
/* @var $file_helper FileHelper */ | |||||
$file_helper->CheckFolder($css_path); | $file_helper->CheckFolder($css_path); | ||||
$css_file = $css_path.mb_strtolower($this->GetDBField('Name')).'-'.$compile_ts.'.css'; | $css_file = $css_path.mb_strtolower($this->GetDBField('Name')).'-'.$compile_ts.'.css'; | ||||
$fp = fopen($css_file,'w'); | $fp = fopen($css_file,'w'); | ||||
if($fp) | if($fp) | ||||
{ | { | ||||
$prev_css = $css_path.mb_strtolower($this->GetDBField('Name')).'-'.$this->GetDBField('LastCompiled').'.css'; | $prev_css = $css_path.mb_strtolower($this->GetDBField('Name')).'-'.$this->GetDBField('LastCompiled').'.css'; | ||||
if( file_exists($prev_css) ) unlink($prev_css); | if( file_exists($prev_css) ) unlink($prev_css); | ||||
fwrite($fp, $ret); | fwrite($fp, $ret); | ||||
fclose($fp); | fclose($fp); | ||||
$sql = 'UPDATE '.$this->TableName.' SET LastCompiled = '.$compile_ts.' WHERE '.$this->IDField.' = '.$this->GetID(); | $sql = 'UPDATE '.$this->TableName.' SET LastCompiled = '.$compile_ts.' WHERE '.$this->IDField.' = '.$this->GetID(); | ||||
$this->Conn->Query($sql); | $this->Conn->Query($sql); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |