Page MenuHomeIn-Portal Phabricator

stylesheets_item.php
No OneTemporary

File Metadata

Created
Thu, Jul 3, 6:25 PM

stylesheets_item.php

<?php
class StylesheetsItem extends kDBItem
{
function Compile()
{
$this->Application->setUnitOption('selectors', 'AutoLoad', false);
$selector_item =& $this->Application->recallObject('selectors.item', 'selectors', Array('live_table'=>true) );
$parent_field = $this->Application->getUnitOption($selector_item->Prefix, 'ForeignKey');
$sql_template = 'SELECT '.$selector_item->IDField.' FROM '.$selector_item->TableName.' WHERE '.$parent_field.' = %s';
$selectors_ids = $this->Conn->GetCol( sprintf($sql_template, $this->GetID() ) );
$ret = '/* This file is generated automatically. Don\'t edit it manually ! */'."\n\n";
foreach($selectors_ids as $selector_id)
{
$selector_item->Load($selector_id);
$ret .= $selector_item->CompileStyle()."\n";
}
$ret .= $this->GetDBField('AdvancedCSS');
$compile_ts = adodb_mktime();
$css_path = FULL_PATH.'/kernel/stylesheets/';
$css_file = $css_path.strtolower($this->GetDBField('Name')).'-'.$compile_ts.'.css';
$fp = fopen($css_file,'w');
if($fp)
{
$prev_css = $css_path.strtolower($this->GetDBField('Name')).'-'.$this->GetDBField('LastCompiled').'.css';
if( file_exists($prev_css) ) unlink($prev_css);
fwrite($fp, $ret);
fclose($fp);
$sql = 'UPDATE '.$this->TableName.' SET LastCompiled = '.$compile_ts.' WHERE '.$this->IDField.' = '.$this->GetID();
$this->Conn->Query($sql);
}
}
}
?>

Event Timeline