Index: branches/5.0.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -r12299 -r12370 --- branches/5.0.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 12299) +++ branches/5.0.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 12370) @@ -1,6 +1,6 @@ Application->recallObject('SiteConfigHelper'); + /* @var $site_config_helper SiteConfigHelper */ + + $settings = $site_config_helper->getSettings(); + $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); // set root category @@ -1678,6 +1683,10 @@ 'onclick' => 'checkCatalog(' . $root_category . ')', ); + $section_ajustments['in-portal:browse_site'] = Array ( + 'url' => Array ('editing_mode' => $settings['default_editing_mode']), + ); + $this->Application->setUnitOption($event->Prefix, 'SectionAdjustments', $section_ajustments); // prepare structure dropdown Index: branches/5.0.x/core/units/helpers/site_config_helper.php =================================================================== diff -u --- branches/5.0.x/core/units/helpers/site_config_helper.php (revision 0) +++ branches/5.0.x/core/units/helpers/site_config_helper.php (revision 12370) @@ -0,0 +1,212 @@ +Application->ConfigValue('AdminConsoleInterface'); + define('SYSTEM_PRESET_PATH', FULL_PATH . ADMIN_DIRECTORY . DIRECTORY_SEPARATOR . 'system_presets' . DIRECTORY_SEPARATOR . $preset_name); + } + + /** + * Returns settings for current admin console preset + * + * @return Array + */ + function getSettings() + { + static $settings = null; + + if (isset($settings)) { + return $settings; + } + + $default_settings = $this->_getDefaultSettings(); + + $preset_name = $this->Application->ConfigValue('AdminConsoleInterface'); + $base_path = FULL_PATH . ADMIN_DIRECTORY . '/system_presets/' . $preset_name; + + if (file_exists($base_path . DIRECTORY_SEPARATOR . 'settings.php')) { + include_once $base_path . DIRECTORY_SEPARATOR . 'settings.php'; // will get $settings array + + foreach ($default_settings as $setting_name => $setting_value) { + if (!array_key_exists($setting_name, $settings)) { + $settings[$setting_name] = $setting_value; + } + } + + return $settings; + } + else { + $settings = $default_settings; + } + + return $settings; + } + + /** + * Returns default settings for admin console presets + * + * @return Array + */ + function _getDefaultSettings() + { + $settings = Array ( + 'default_editing_mode' => EDITING_MODE_BROWSE, + 'visible_editing_modes' => Array ( + EDITING_MODE_BROWSE, + EDITING_MODE_CONTENT, + EDITING_MODE_DESIGN, + ), + ); + + return $settings; + } + + /** + * Applies given changes to given prefix unit config + * + * @param string $prefix + * @param Array $changes + */ + function processConfigChanges($prefix, $changes) + { + extract($changes); + + $section_adjustments = $this->Application->getUnitOption('core-sections', 'SectionAdjustments', Array ()); + $title_presets = $this->Application->getUnitOption($prefix, 'TitlePresets', Array ()); + $fields = $this->Application->getUnitOption($prefix, 'Fields', Array ()); + $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields', Array ()); + $edit_tab_presets = $this->Application->getUnitOption($prefix, 'EditTabPresets', Array ()); + $grids = $this->Application->getUnitOption($prefix, 'Grids', Array ()); + + $field_names = array_keys($fields); + $virtual_field_names = array_keys($virtual_fields); + + if (isset($remove_sections)) { + // process sections + foreach ($remove_sections as $remove_section) { + $section_adjustments[$remove_section]['show_mode'] = smHIDE; + } + } + + if (isset($debug_only_sections)) { + // process sections + foreach ($debug_only_sections as $debug_only_section) { + $section_adjustments[$debug_only_section]['show_mode'] = smDEBUG; + } + } + + if (isset($remove_buttons)) { + // process toolbar buttons + foreach ($remove_buttons as $title_preset => $toolbar_buttons) { + $title_presets[$title_preset]['toolbar_buttons'] = array_diff($title_presets[$title_preset]['toolbar_buttons'], $toolbar_buttons); + } + } + + $reset_fields = true; + $reset_virtual_fields = true; + + // process hidden fields + if (isset($hidden_fields)) { + $fields = $this->_setFieldOption($fields, $hidden_fields, 'show_mode', false, $reset_fields); + $reset_fields = false; + } + + if (isset($virtual_hidden_fields)) { + $virtual_fields = $this->_setFieldOption($virtual_fields, $virtual_hidden_fields, 'show_mode', false, $reset_virtual_fields); + $reset_virtual_fields = false; + } + + // process debug only fields + if (isset($debug_only_fields)) { + $fields = $this->_setFieldOption($fields, $debug_only_fields, 'show_mode', smDEBUG, $reset_fields); + $reset_fields = false; + } + + if (isset($debug_only_virtual_fields)) { + $virtual_fields = $this->_setFieldOption($virtual_fields, $debug_only_virtual_fields, 'show_mode', smDEBUG, $reset_virtual_fields); + $reset_virtual_fields = false; + } + + // process required fields + if (isset($required_fields)) { + $fields = $this->_setFieldOption($fields, $required_fields, 'required', 1); + } + + if (isset($virtual_required_fields)) { + $virtual_fields = $this->_setFieldOption($virtual_fields, $virtual_required_fields, 'required', 1); + } + + if (isset($hide_edit_tabs)) { + // hide edit tabs + foreach ($hide_edit_tabs as $preset_name => $edit_tabs) { + foreach ($edit_tabs as $edit_tab) { + unset($edit_tab_presets[$preset_name][$edit_tab]); + } + } + } + + if (isset($hide_columns)) { + // hide columns in grids + foreach ($hide_columns as $grid_name => $columns) { + foreach ($columns as $column) { + unset($grids[$grid_name]['Fields'][$column]); + } + } + } + + // save changes + $this->Application->setUnitOption('core-sections', 'SectionAdjustments', $section_adjustments); + $this->Application->setUnitOption($prefix, 'TitlePresets', $title_presets); + $this->Application->setUnitOption($prefix, 'Fields', $fields); + $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields); + $this->Application->setUnitOption($prefix, 'EditTabPresets', $edit_tab_presets); + $this->Application->setUnitOption($prefix, 'Grids', $grids); + } + + /** + * Sets given option for given fields and unsets it for all other fields + * + * @param Array $fields + * @param Array $set_fields + * @param string $option_name + * @param mixed $option_value + * @param bool $reset + */ + function _setFieldOption($fields, $set_fields, $option_name, $option_value, $reset = true) + { + if ($reset) { + // unset given option for rest of fields (all except $set_fields) + $unset_fields = array_diff(array_keys($fields), $set_fields); + foreach ($unset_fields as $unset_field) { + if (array_key_exists($option_name, $fields[$unset_field])) { + unset($fields[$unset_field][$option_name]); + } + } + } + + // set given option to given fields + foreach ($set_fields as $set_field) { + $fields[$set_field][$option_name] = $option_value; + } + + return $fields; + } + } \ No newline at end of file Index: branches/5.0.x/core/units/sections/site_config_eh.php =================================================================== diff -u -r12299 -r12370 --- branches/5.0.x/core/units/sections/site_config_eh.php (.../site_config_eh.php) (revision 12299) +++ branches/5.0.x/core/units/sections/site_config_eh.php (.../site_config_eh.php) (revision 12370) @@ -1,6 +1,6 @@ Application->ConfigValue('AdminConsoleInterface'); - define('SYSTEM_PRESET_PATH', FULL_PATH . ADMIN_DIRECTORY . DIRECTORY_SEPARATOR . 'system_presets' . DIRECTORY_SEPARATOR . $preset_name); + if (!isset($this->_helper)) { + $this->_helper =& $this->Application->recallObject('SiteConfigHelper'); } $prefix_file = basename( $this->Application->UnitConfigReader->getPrefixFile($event->MasterEvent->Prefix) ); @@ -34,16 +40,9 @@ $prefix_file = substr($prefix_file, 0, $cut_pos) . '_' . $event->MasterEvent->Prefix . '.php'; if (file_exists(SYSTEM_PRESET_PATH . DIRECTORY_SEPARATOR . $prefix_file)) { - /*if ($this->Application->isDebugMode()) { - $this->Application->Debugger->appendHTML('Using site config: ' . $prefix_file); - }*/ require SYSTEM_PRESET_PATH . DIRECTORY_SEPARATOR . $prefix_file; } else { - /*if ($this->Application->isDebugMode()) { - $this->Application->Debugger->appendHTML('Site config missing: ' . $prefix_file); - }*/ - return ; } @@ -61,137 +60,6 @@ } // apply changes - $this->_processConfigChanges($event->MasterEvent->Prefix, $changes); + $this->_helper->processConfigChanges($event->MasterEvent->Prefix, $changes); } - - /** - * Applies given changes to given prefix unit config - * - * @param string $prefix - * @param Array $changes - */ - function _processConfigChanges($prefix, $changes) - { - extract($changes); - - $section_adjustments = $this->Application->getUnitOption($this->Prefix, 'SectionAdjustments', Array ()); - $title_presets = $this->Application->getUnitOption($prefix, 'TitlePresets', Array ()); - $fields = $this->Application->getUnitOption($prefix, 'Fields', Array ()); - $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields', Array ()); - $edit_tab_presets = $this->Application->getUnitOption($prefix, 'EditTabPresets', Array ()); - $grids = $this->Application->getUnitOption($prefix, 'Grids', Array ()); - - $field_names = array_keys($fields); - $virtual_field_names = array_keys($virtual_fields); - - if (isset($remove_sections)) { - // process sections - foreach ($remove_sections as $remove_section) { - $section_adjustments[$remove_section]['show_mode'] = smHIDE; - } - } - - if (isset($debug_only_sections)) { - // process sections - foreach ($debug_only_sections as $debug_only_section) { - $section_adjustments[$debug_only_section]['show_mode'] = smDEBUG; - } - } - - if (isset($remove_buttons)) { - // process toolbar buttons - foreach ($remove_buttons as $title_preset => $toolbar_buttons) { - $title_presets[$title_preset]['toolbar_buttons'] = array_diff($title_presets[$title_preset]['toolbar_buttons'], $toolbar_buttons); - } - } - - $reset_fields = true; - $reset_virtual_fields = true; - - // process hidden fields - if (isset($hidden_fields)) { - $fields = $this->_setFieldOption($fields, $hidden_fields, 'show_mode', false, $reset_fields); - $reset_fields = false; - } - - if (isset($virtual_hidden_fields)) { - $virtual_fields = $this->_setFieldOption($virtual_fields, $virtual_hidden_fields, 'show_mode', false, $reset_virtual_fields); - $reset_virtual_fields = false; - } - - // process debug only fields - if (isset($debug_only_fields)) { - $fields = $this->_setFieldOption($fields, $debug_only_fields, 'show_mode', smDEBUG, $reset_fields); - $reset_fields = false; - } - - if (isset($debug_only_virtual_fields)) { - $virtual_fields = $this->_setFieldOption($virtual_fields, $debug_only_virtual_fields, 'show_mode', smDEBUG, $reset_virtual_fields); - $reset_virtual_fields = false; - } - - // process required fields - if (isset($required_fields)) { - $fields = $this->_setFieldOption($fields, $required_fields, 'required', 1); - } - - if (isset($virtual_required_fields)) { - $virtual_fields = $this->_setFieldOption($virtual_fields, $virtual_required_fields, 'required', 1); - } - - if (isset($hide_edit_tabs)) { - // hide edit tabs - foreach ($hide_edit_tabs as $preset_name => $edit_tabs) { - foreach ($edit_tabs as $edit_tab) { - unset($edit_tab_presets[$preset_name][$edit_tab]); - } - } - } - - if (isset($hide_columns)) { - // hide columns in grids - foreach ($hide_columns as $grid_name => $columns) { - foreach ($columns as $column) { - unset($grids[$grid_name]['Fields'][$column]); - } - } - } - - // save changes - $this->Application->setUnitOption($this->Prefix, 'SectionAdjustments', $section_adjustments); - $this->Application->setUnitOption($prefix, 'TitlePresets', $title_presets); - $this->Application->setUnitOption($prefix, 'Fields', $fields); - $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields); - $this->Application->setUnitOption($prefix, 'EditTabPresets', $edit_tab_presets); - $this->Application->setUnitOption($prefix, 'Grids', $grids); - } - - /** - * Sets given option for given fields and unsets it for all other fields - * - * @param Array $fields - * @param Array $set_fields - * @param string $option_name - * @param mixed $option_value - * @param bool $reset - */ - function _setFieldOption($fields, $set_fields, $option_name, $option_value, $reset = true) - { - if ($reset) { - // unset given option for rest of fields (all except $set_fields) - $unset_fields = array_diff(array_keys($fields), $set_fields); - foreach ($unset_fields as $unset_field) { - if (array_key_exists($option_name, $fields[$unset_field])) { - unset($fields[$unset_field][$option_name]); - } - } - } - - // set given option to given fields - foreach ($set_fields as $set_field) { - $fields[$set_field][$option_name] = $option_value; - } - - return $fields; - } } \ No newline at end of file Index: branches/5.0.x/core/units/helpers/helpers_config.php =================================================================== diff -u -r12343 -r12370 --- branches/5.0.x/core/units/helpers/helpers_config.php (.../helpers_config.php) (revision 12343) +++ branches/5.0.x/core/units/helpers/helpers_config.php (.../helpers_config.php) (revision 12370) @@ -1,6 +1,6 @@ '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'), + Array ('class' => 'SiteConfigHelper', 'pseudo' => 'SiteConfigHelper', 'file' => 'site_config_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'), Array ('class' => 'InpCustomFieldsHelper', 'pseudo' => 'InpCustomFieldsHelper', 'file' => 'custom_fields_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'), Array ('class' => 'kCountryStatesHelper', 'pseudo' => 'CountryStatesHelper', 'file' => 'country_states_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'), Index: branches/5.0.x/core/units/sections/site_config_tp.php =================================================================== diff -u -r12343 -r12370 --- branches/5.0.x/core/units/sections/site_config_tp.php (.../site_config_tp.php) (revision 12343) +++ branches/5.0.x/core/units/sections/site_config_tp.php (.../site_config_tp.php) (revision 12370) @@ -1,6 +1,6 @@ Array ('image' => 'show_all', 'title' => 'Design Mode'), ); - $preset_name = $this->Application->ConfigValue('AdminConsoleInterface'); - $base_path = FULL_PATH . ADMIN_DIRECTORY . '/system_presets/' . $preset_name; + $site_config_helper =& $this->Application->recallObject('SiteConfigHelper'); + /* @var $site_config_helper SiteConfigHelper */ - if (file_exists($base_path . DIRECTORY_SEPARATOR . 'settings.php')) { - include_once $base_path . DIRECTORY_SEPARATOR . 'settings.php'; // will get $visible_editing_modes + $settings = $site_config_helper->getSettings(); - foreach ($editing_modes as $editing_mode => $data) { - if (!in_array($editing_mode, $visible_editing_modes)) { - unset($editing_modes[$editing_mode]); - } + foreach ($editing_modes as $editing_mode => $data) { + if (!in_array($editing_mode, $settings['visible_editing_modes'])) { + unset($editing_modes[$editing_mode]); } + } - if (count($editing_modes) == 1) { - // don't show buttons, when there only one left - return ''; - } + if (count($editing_modes) == 1) { + // don't show buttons, when there only one left + return ''; } $ret = '';