_getStyleField( $params['type'] ); } $style_info = $this->_getStyleInfo(); if (file_exists( $this->getSkinPath() )) { // returns last compiled skin $ret = $this->getSkinPath(true); } else { // search for previously compiled skin $last_compiled = $this->_getLastCompiled( mb_strtolower($style_info['Name']) ); if ($last_compiled) { // found $ret = $this->getSkinPath(true, $last_compiled); } else { // not found (try to compile on the fly) $skin =& $this->Application->recallObject('skin.-item', null, Array ('skip_autoload' => true)); /* @var $skin kDBItem */ $skin->Load(1, 'IsPrimary'); $last_compiled = $this->compile($skin); $ret = $last_compiled ? $this->getSkinPath(true, $last_compiled) : ''; } } if (array_key_exists('file_only', $params) && $params['file_only']) { return $ret; } return ''; } /** * Compiles given skin object * * @param kDBItem $object */ 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); } $compile_ts = adodb_mktime(); $css_file = $this->_getStylesheetPath() . DIRECTORY_SEPARATOR . 'admin-' . mb_strtolower($object->GetDBField('Name')) . '-' . $compile_ts . '.css'; $fp = fopen($css_file, 'w'); if (!$fp) { return false; } $prev_css = $this->_getStylesheetPath() . '/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); return $compile_ts; } /** * Returns fields of primary admin skin * * @return Array */ function _getStyleInfo() { static $style = null; if (!isset($style)) { $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'Skins WHERE IsPrimary = 1'; $style = $this->Conn->GetRow($sql); } return $style; } /** * Returns requested field value of primary admin skin * * @param string $field * @return string */ function _getStyleField($field) { if ($field == 'logo') { // old style method of calling $field = 'Logo'; } $style_info = $this->_getStyleInfo(); if (!$style_info[$field]) { return ''; } $image_fields = Array ('Logo', 'LogoBottom', 'LogoLogin'); if (in_array($field, $image_fields)) { return $this->_getStylesheetPath(true) . '/' . $style_info[$field]; } return $style_info[$field]; } /** * Returns path, where compiled skin and it's image files are stored * * @param bool $url * @return string */ function _getStylesheetPath($url = false) { if ($url) { return $this->Application->BaseURL( str_replace(DIRECTORY_SEPARATOR, '/', WRITEBALE_BASE) ) . 'user_files'; } return WRITEABLE . DIRECTORY_SEPARATOR . 'user_files'; } /** * Returns full path to primary admin skin using given or last compiled date * * @param string $url * @param int $compile_date * @return string */ function getSkinPath($url = false, $compile_date = null) { $style_info = $this->_getStyleInfo(); if (!isset($compile_date)) { $compile_date = $style_info['LastCompiled']; } $style_name = 'admin-' . mb_strtolower($style_info['Name']) . '-' . $compile_date . '.css'; return $this->_getStylesheetPath($url) . ($url ? '/' : DIRECTORY_SEPARATOR) . $style_name; } /** * Returns maximal compilation date for given skin name * * @param string $style_name * @return int */ function _getLastCompiled($style_name) { $last_compiled = 0; $dh = dir($this->_getStylesheetPath() . DIRECTORY_SEPARATOR); while (false !== ($file = $dh->read())) { if ( preg_match('/admin-(.*)-([\d]+).css/', $file, $rets) ) { if ($rets[1] == $style_name && $rets[2] > $last_compiled) { $last_compiled = $rets[2]; } } } $dh->close(); return $last_compiled; } /** * Deletes all compiled versions of all skins * */ function deleteCompiled() { $dh = dir($this->_getStylesheetPath() . DIRECTORY_SEPARATOR); while (false !== ($file = $dh->read())) { if ( preg_match('/admin-(.*)-([\d]+).css/', $file, $rets) ) { unlink($dh->path . $file); } } $dh->close(); } }