BuildTree(); } /** * Builds xml for tree in left frame in admin * * @param Array $params */ function BuildTree() { if (!isset($this->Application->Memcached) || !($data = $this->Application->Memcached->get('master:sections_parsed'))) { $data = $this->Conn->GetOne('SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "sections_parsed"'); } if ($data) { $this->Tree = unserialize($data); return ; } $this->Application->UnitConfigReader->ReReadConfigs(); $this->Tree = Array(); // 1. build base tree (don't update parent with children list yet) $prefixes = array_keys($this->Application->UnitConfigReader->configData); foreach ($prefixes as $prefix) { $config =& $this->Application->UnitConfigReader->configData[$prefix]; $sections = getArrayValue($config, 'Sections'); if (!$sections) continue; // echo 'Prefix: ['.$prefix.'] has ['.count($sections).'] sections
'; foreach ($sections as $section_name => $section_params) { // we could also skip not allowed sections here in future if ( isset($section_params['SectionPrefix']) ) { $section_prefix = $section_params['SectionPrefix']; } elseif ( $this->Application->getUnitOption($prefix, 'SectionPrefix') ) { $section_prefix = $this->Application->getUnitOption($prefix, 'SectionPrefix'); } else { $section_prefix = $prefix; } $section_params['SectionPrefix'] = $section_prefix; $section_params['url']['m_opener'] = 'r'; $section_params['url']['no_pass_through'] = 1; $pass_section = getArrayValue($section_params, 'url', 'pass_section'); if ($pass_section) { unset($section_params['url']['pass_section']); $section_params['url']['section'] = $section_name; if (!isset($section_params['url']['module'])) { $module_name = $this->Application->findModule('Path', $config['ModuleFolder'].'/', 'Name'); $section_params['url']['module'] = $module_name; } } if (!isset($section_params['url']['t'])) { $section_params['url']['t'] = 'index'; } if (!isset($section_params['onclick'])) { $section_params['onclick'] = 'checkEditMode()'; } if (!isset($section_params['container'])) { $section_params['container'] = 0; // for js tree printing to xml } $current_data = isset($this->Tree[$section_name]) ? $this->Tree[$section_name] : Array(); $this->Tree[$section_name] = array_merge_recursive2($current_data, $section_params); } } // 2. apply section ajustments foreach ($prefixes as $prefix) { $config =& $this->Application->UnitConfigReader->configData[$prefix]; $section_ajustments = getArrayValue($config, 'SectionAdjustments'); if (!$section_ajustments) continue; foreach ($section_ajustments as $section_name => $ajustment_params) { if (is_array($ajustment_params)) { $this->Tree[$section_name] = array_merge_recursive2($this->Tree[$section_name], $ajustment_params); } else { // then remove section unset($this->Tree[$section_name]); } } } // 3. foreach ($this->Tree as $section_name => $section_params) { // 3.1. update parent -> children references $this->Tree[ $section_params['parent'] ]['children'][ "{$section_params['priority']}" ] = $section_name; if ($section_params['type'] == stTAB) { // if this is tab, then mark parent section as TabOnly $this->Tree[ $section_params['parent'] ]['tabs_only'] = true; } // 3.2. process icons here, because they also can be ajusted if (isset($section_params['icon']) && preg_match('/([^:]+):(.*)/', $section_params['icon'], $regs)) { $this->Tree[$section_name]['icon'] = $regs[2]; $this->Tree[$section_name]['icon_module'] = $regs[1]; $module_folder = trim( $this->Application->findModule('Name', $regs[1], 'Path'), '/'); if ($module_folder == '') $module_folder = 'core'; } else { $module_folder = $this->Application->getUnitOption($section_params['SectionPrefix'], 'ModuleFolder'); } // this is to display HELP icon instead of missing one.. can be replaced with some other icon to draw attention $icon_file = $module_folder.'/admin_templates/img/icons/icon24_'.$this->Tree[$section_name]['icon']; if (!file_exists(FULL_PATH.'/'.$icon_file.'.gif')) { $this->Tree[$section_name]['icon'] = 'help'; $this->Tree[$section_name]['icon_module'] = 'core'; } } $this->Application->HandleEvent( new kEvent('adm:OnAfterBuildTree') ); if (isset($this->Application->Memcached)) { $this->Application->Memcached->set('master:sections_parsed',serialize($this->Tree), 0, 0); return; } $this->Conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("sections_parsed", '.$this->Conn->qstr(serialize($this->Tree)).', '.adodb_mktime().')'); } /** * Returns details information about section * * @param string $section_name * @return Array */ function &getSectionData($section_name) { if (isset($this->Tree[$section_name])) { $ret =& $this->Tree[$section_name]; } else { $ret = Array(); } return $ret; } /** * Returns first child, that is not a folder * * @param string $section_name * @param Array $tree * @return stirng */ function getFirstChild($section_name, $check_permission = false) { $section_data =& $this->getSectionData($section_name); $children = isset($section_data['children']) && $section_data['children'] ? $section_data['children'] : false; if ($children) { // get 1st child ksort($children, SORT_NUMERIC); foreach ($children as $child_priority => $child_section) { $section_data =& $this->getSectionData($child_section); $perm_section = $this->getPermSection($child_section); $perm_status = $check_permission ? $this->Application->CheckPermission($perm_section.'.view') : true; if ((isset($section_data['show_mode']) && $section_data['show_mode']) || !$perm_status) { continue; } break; } return $this->getFirstChild($child_section, $check_permission); } return $section_name; } /** * Returns section for permission checking based on given section * * @param string $section_name * @return string */ function getPermSection($section_name) { $ret = $section_name; $section_data =& $this->getSectionData($section_name); if ($section_data && isset($section_data['perm_prefix'])) { // this section uses other section permissions $ret = $this->Application->getUnitOption($section_data['perm_prefix'].'.main', 'PermSection'); } return $ret; } } ?>