Index: branches/5.0.x/core/units/configuration/configuration_event_handler.php
===================================================================
diff -u -r12117 -r12233
--- branches/5.0.x/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 12117)
+++ branches/5.0.x/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 12233)
@@ -1,6 +1,6 @@
Application->GetVar($event->getPrefixSpecial(true));
- $state_country_hash = Array(
- 'Comm_State' => 'Comm_Country',
- 'Comm_Shipping_State' => 'Comm_Shipping_Country'
- );
+ $state_country_hash = Array (
+ 'Comm_State' => 'Comm_Country',
+ 'Comm_Shipping_State' => 'Comm_Shipping_Country'
+ );
$field_name = $object->GetDBField('VariableName');
- if (isset($state_country_hash[$field_name])) {
+ if (array_key_exists($field_name, $state_country_hash)) {
// if this is state field
$check_state = $object->GetDBField('VariableValue');
$check_country = $field_values[ $state_country_hash[$field_name] ]['VariableValue'];
@@ -93,8 +91,7 @@
if ($state_iso !== false) {
$object->SetDBField('VariableValue', $state_iso);
}
- else
- {
+ else {
$errormsgs = $this->Application->GetVar('errormsgs');
$errors = !$errormsgs || !isset($errormsgs[$event->Prefix_Special]) ? Array() : $errormsgs[$event->Prefix_Special];
@@ -105,7 +102,6 @@
$event->status = erFAIL;
}
}
-
}
/**
@@ -116,13 +112,50 @@
function OnAfterItemUpdate(&$event)
{
$object =& $event->getObject();
+ /* @var $object kDBItem */
+
if ($object->GetDBField('element_type') == 'password') {
if (trim($object->GetDBField('VariableValue')) == '') {
$field_options = $object->GetFieldOptions('VariableValue');
unset($field_options['skip_empty']);
$object->SetFieldOptions('VariableValue', $field_options);
}
}
+
+ // allows to check if variable's value was changed now
+ $variable_name = $object->GetDBField('VariableName');
+ $variable_value = $object->GetDBField('VariableValue');
+ $watch_variables = Array ('Require_AdminSSL', 'AdminSSL_URL', 'AdvancedUserManagement', 'Site_Name');
+
+ if (in_array($variable_name, $watch_variables)) {
+ $changed = $this->Application->GetVar($event->getPrefixSpecial() . '_changed', Array ());
+
+ if ($variable_value != $object->GetOriginalField('VariableValue')) {
+ $changed[$variable_name] = $variable_value;
+ $this->Application->SetVar($event->getPrefixSpecial() . '_changed', $changed);
+ }
+
+ switch ($variable_name) {
+ case 'Require_AdminSSL':
+ case 'AdminSSL_URL':
+ static $skin_deleted = false;
+
+ if (array_key_exists($variable_name, $changed) && !$skin_deleted) {
+ // when administrative console is moved to SSL mode, then delete skin
+ $skin_helper =& $this->Application->recallObject('SkinHelper');
+ /* @var $skin_helper SkinHelper */
+
+ $skin_file = $skin_helper->getSkinPath();
+ if (file_exists($skin_file)) {
+ unlink($skin_file);
+ }
+
+ $skin_deleted = true;
+ }
+ break;
+ }
+ }
+
}
/**
@@ -157,17 +190,9 @@
}
if ($event->status == erSUCCESS) { // reset cache
- $refresh_sections = false;
- if ($items_info) {
- $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
- $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $changed = $this->Application->GetVar($event->getPrefixSpecial() . '_changed', Array ());
+ $refresh_sections = array_key_exists('AdvancedUserManagement', $changed) || array_key_exists('Site_Name', $changed);
- $sql = 'SELECT ' . $id_field . '
- FROM ' . $table_name . '
- WHERE ' . $id_field . ' IN (' . implode(',', array_keys($items_info)) . ') AND (VariableName = "AdvancedUserManagement")';
- $refresh_sections = $this->Conn->GetCol($sql);
- }
-
if ($refresh_sections) {
// reset sections too, because of AdvancedUserManagement
$event->SetRedirectParam('refresh_tree', 1);
Index: branches/5.0.x/core/install/upgrades.php
===================================================================
diff -u -r12117 -r12233
--- branches/5.0.x/core/install/upgrades.php (.../upgrades.php) (revision 12117)
+++ branches/5.0.x/core/install/upgrades.php (.../upgrades.php) (revision 12233)
@@ -1,6 +1,6 @@
SetDBField('Options', serialize($skin_options));
$skin->Update();
- $skin_eh =& $this->Application->recallObject('skin_EventHandler');
- /* @var $skin_eh SkinEventHandler */
+ $skin_helper =& $this->Application->recallObject('SkinHelper');
+ /* @var $skin_helper SkinHelper */
- $skin_eh->Compile($skin);
+ $skin_file = $skin_helper->getSkinPath();
+ if (file_exists($skin_file)) {
+ unlink($skin_file);
+ }
}
}
}
Index: branches/5.0.x/core/units/general/helpers/helpers_config.php
===================================================================
diff -u -r12117 -r12233
--- branches/5.0.x/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 12117)
+++ branches/5.0.x/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 12233)
@@ -1,6 +1,6 @@
'MailingListHelper', 'class' => 'MailingListHelper', 'file' => 'mailing_list_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
Array ('pseudo' => 'JSONHelper', 'class' => 'JSONHelper', 'file' => 'json_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
Array ('pseudo' => 'LanguageImportHelper', 'class' => 'LanguageImportHelper', 'file' => 'language_import_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
+ Array ('pseudo' => 'SkinHelper', 'class' => 'SkinHelper', 'file' => 'skin_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
),
);
\ No newline at end of file
Index: branches/5.0.x/core/units/skins/skin_eh.php
===================================================================
diff -u -r12202 -r12233
--- branches/5.0.x/core/units/skins/skin_eh.php (.../skin_eh.php) (revision 12202)
+++ branches/5.0.x/core/units/skins/skin_eh.php (.../skin_eh.php) (revision 12233)
@@ -1,6 +1,6 @@
SwitchToLive();
$ids = $event->MasterEvent->getEventParam('ids');
- if (!is_array($ids)) $ids = explode(',', $ids);
-
- if(!$ids) return false;
- foreach($ids as $id)
- {
- $object->Load($id);
- $this->Compile($object);
+ if (!is_array($ids)) {
+ $ids = explode(',', $ids);
}
- }
- 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);
+ if (!$ids) {
+ return false;
}
- $compile_ts = adodb_mktime();
- $css_path = WRITEABLE . '/user_files/';
+ $skin_helper =& $this->Application->recallObject('SkinHelper');
+ /* @var $skin_helper SkinHelper */
- $css_file = $css_path.'admin-'.mb_strtolower($object->GetDBField('Name')).'-'.$compile_ts.'.css';
-
- $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
Index: branches/5.0.x/core/admin_templates/config/config_universal.tpl
===================================================================
diff -u -r12117 -r12233
--- branches/5.0.x/core/admin_templates/config/config_universal.tpl (.../config_universal.tpl) (revision 12117)
+++ branches/5.0.x/core/admin_templates/config/config_universal.tpl (.../config_universal.tpl) (revision 12233)
@@ -89,9 +89,15 @@
\ No newline at end of file
Index: branches/5.0.x/core/units/admin/admin_tag_processor.php
===================================================================
diff -u -r12202 -r12233
--- branches/5.0.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 12202)
+++ branches/5.0.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 12233)
@@ -1,6 +1,6 @@
Conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'Skins WHERE IsPrimary = 1');
- }
+ $skin_helper =& $this->Application->recallObject('SkinHelper');
+ /* @var $skin_helper SkinHelper */
- $css_path = WRITEABLE . DIRECTORY_SEPARATOR . 'user_files';
- $css_url = $this->Application->BaseURL( str_replace(DIRECTORY_SEPARATOR, '/', WRITEBALE_BASE) ) . 'user_files/';
-
- $type = array_key_exists('type', $params) ? $params['type'] : false;
- if ($type == 'logo') {
- $type = 'Logo';
- }
-
- if ($type == 'Logo' || $type == 'LogoBottom' || $type == 'LogoLogin') {
- return $style[$type] ? $css_url.$style[$type] : '';
- }
-
- $last_compiled = $style['LastCompiled'];
-
- $style_name = mb_strtolower( $style['Name'] );
-
- if( file_exists($css_path . '/' . 'admin-' . $style_name . '-' . $last_compiled . '.css') )
- {
- $ret = $css_url.'admin-'.$style_name.'-'.$last_compiled.'.css';
-
- }
- else
- {
- // search for previously compiled stylesheet
- $last_compiled = 0;
- if( $dh = opendir($css_path) )
- {
- while( ($file = readdir($dh)) !== false )
- {
- if( preg_match('/admin-(.*)-([\d]+).css/', $file, $rets) )
- {
- if( $rets[1] == $style_name && $rets[2] > $last_compiled ) $last_compiled = $rets[2];
- }
- }
- closedir($dh);
- }
- if ($last_compiled) {
- // found
- $ret = $css_url.'admin-'.$style_name.'-'.$last_compiled.'.css';
- }
- else {
- // not found (try to compile on the fly)
- $object =& $this->Application->recallObject('skin.-item', null, Array ('skip_autoload' => true));
- /* @var $object kDBItem */
-
- $skin_eh =& $this->Application->recallObject('skin_EventHandler');
- /* @var $skin_eh SkinEventHandler */
-
- $object->Load(1, 'IsPrimary');
- $skin_eh->Compile($object);
- $ret = $css_url.'admin-'.$style_name.'-'.adodb_mktime().'.css';
- }
- }
-
- if (isset($params['file_only'])) return $ret;
-
- return '';
+ return $skin_helper->AdminSkinTag($params);
}
function PrintCompileErrors($params)
Index: branches/5.0.x/core/units/general/helpers/skin_helper.php
===================================================================
diff -u
--- branches/5.0.x/core/units/general/helpers/skin_helper.php (revision 0)
+++ branches/5.0.x/core/units/general/helpers/skin_helper.php (revision 12233)
@@ -0,0 +1,194 @@
+_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 unknown_type $url
+ * @param unknown_type $compile_date
+ * @return unknown
+ */
+ 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;
+ }
+ }
\ No newline at end of file