Index: branches/5.1.x/core/units/skins/skin_eh.php =================================================================== diff -u -N -r12127 -r12657 --- branches/5.1.x/core/units/skins/skin_eh.php (.../skin_eh.php) (revision 12127) +++ branches/5.1.x/core/units/skins/skin_eh.php (.../skin_eh.php) (revision 12657) @@ -1,6 +1,6 @@ Array ('self' => true), - ); + class SkinEventHandler extends kDBEventHandler { - $this->permMapping = array_merge($this->permMapping, $permissions); - } + function mapPermissions() + { + parent::mapPermissions(); + $permissions = Array ( + 'OnItemBuild' => Array ('self' => true), + ); - /** - * With "primary" special loads primary skin - * - * @param kEvent $event - * @return int - */ - function getPassedID(&$event) - { - if ($event->Special == 'primary') { - return Array ('IsPrimary' => 1); + $this->permMapping = array_merge($this->permMapping, $permissions); } - return parent::getPassedID($event); - } + /** + * With "primary" special loads primary skin + * + * @param kEvent $event + * @return int + */ + function getPassedID(&$event) + { + if ($event->Special == 'primary') { + return Array ('IsPrimary' => 1); + } - /** - * Allows to set selected theme as primary - * - * @param kEvent $event - */ - function OnSetPrimary(&$event) - { - if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { - return; + return parent::getPassedID($event); } - $ids = $this->StoreSelectedIDs($event); - if ($ids) { - $id = array_shift($ids); - $this->setPrimary($id); - } + /** + * Allows to set selected theme as primary + * + * @param kEvent $event + */ + function OnSetPrimary(&$event) + { + if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + return; + } - $this->clearSelectedIDs($event); - } + $ids = $this->StoreSelectedIDs($event); + if ($ids) { + $id = array_shift($ids); + $this->setPrimary($id); + } - function setPrimary($id) - { - $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + $this->clearSelectedIDs($event); + } - $sql = 'UPDATE '.$table_name.' - SET IsPrimary = 0'; - $this->Conn->Query($sql); + function setPrimary($id) + { + $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + $sql = 'UPDATE '.$table_name.' + SET IsPrimary = 0'; + $this->Conn->Query($sql); - $sql = 'UPDATE '.$table_name.' - SET IsPrimary = 1 - WHERE '.$id_field.' = '.$id; - $this->Conn->Query($sql); - } + $sql = 'UPDATE '.$table_name.' + SET IsPrimary = 1 + WHERE '.$id_field.' = '.$id; + $this->Conn->Query($sql); + } - /** - * [HOOK] Compile stylesheet file based on theme definitions - * - * @param kEvent $event - */ - function OnCompileStylesheet(&$event) - { - $object =& $event->getObject( Array('skip_autoload' => true) ); - $object->SwitchToLive(); - $ids = $event->MasterEvent->getEventParam('ids'); - if (!is_array($ids)) $ids = explode(',', $ids); - - if(!$ids) return false; - foreach($ids as $id) + /** + * [HOOK] Compile stylesheet file based on theme definitions + * + * @param kEvent $event + */ + function OnCompileStylesheet(&$event) { - $object->Load($id); - $this->Compile($object); - } - } + $object =& $event->getObject( Array('skip_autoload' => true) ); + $object->SwitchToLive(); - function Compile(&$object) - { - $ret = $object->GetDBField('CSS'); - $options = $object->GetDBField('Options'); - $options = unserialize($options); - $options['base_url'] = array('Value'=>rtrim($this->Application->BaseURL(), '/')); - foreach ($options as $key => $row) { - $ret = str_replace('@@'.$key.'@@', $row['Value'], $ret); - } + $ids = $event->MasterEvent->getEventParam('ids'); + if (!is_array($ids)) { + $ids = explode(',', $ids); + } - $compile_ts = adodb_mktime(); - $css_path = (defined('WRITEABLE') ? WRITEABLE : FULL_PATH.'/kernel').'/user_files/'; + if (!$ids) { + return false; + } - $css_file = $css_path.'admin-'.mb_strtolower($object->GetDBField('Name')).'-'.$compile_ts.'.css'; + $skin_helper =& $this->Application->recallObject('SkinHelper'); + /* @var $skin_helper SkinHelper */ - $fp = fopen($css_file,'w'); - if($fp) - { - $prev_css = $css_path.'admin-'.mb_strtolower($object->GetDBField('Name')).'-'.$object->GetDBField('LastCompiled').'.css'; - if( file_exists($prev_css) ) unlink($prev_css); - - fwrite($fp, $ret); - fclose($fp); - - $sql = 'UPDATE '.$object->TableName.' SET LastCompiled = '.$compile_ts.' WHERE '.$object->IDField.' = '.$object->GetID(); - $this->Conn->Query($sql); + foreach($ids as $id) { + $object->Load($id); + $skin_helper->compile($object); + } } - } -} \ No newline at end of file + + } \ No newline at end of file