function multi_array_merge($array1, $array2) { if (is_array($array2) && count($array2)) { //不是空数组的话 foreach ($array2 as $k => $v) { if (is_array($v) && count($v)) { $array1[$k] = multi_array_merge($array1[$k], $v); } else { if (!empty($v)) { $array1[$k] = $v; } } } } else { $array1 = $array2; } return $array1; }
/** like array_merge only for multible arrays * returns merged array * * @param $array1 array * @param $array2 array * * @return $array1 array merged array */ function multi_array_merge($array1, $array2) { foreach ($array2 as $key => $value) { if (is_array($value)) { if (empty($array1[$key])) { $array1[$key] = $value; } else { $array1[$key] = multi_array_merge($array1[$key], $value); } } else { $array1[$key] = $value; } } return $array1; }
/** _loadMessages - INTERNAL * this methode loads ms_$rubric_$language.dat * * @param string $rubric to load (first word of message tag) * @param string $language to load (de,en,...), if is empty -> all languages will be loaded */ function _loadMessages($rubric, $language) { $message = array(); if (!empty($language)) { $entry = 'ms_' . $rubric . '_' . $language . '.dat'; if (file_exists($this->_file_path . $entry)) { include_once $this->_file_path . $entry; $this->_loaded_message_dats[] = $entry; if (!empty($message)) { $message = encode(FROM_FILE, $message); $this->_message_array = multi_array_merge($this->_message_array, $message); unset($message); } } else { foreach ($this->_dat_folder_array as $folder) { if (file_exists($folder . '/' . $entry)) { include_once $folder . '/' . $entry; $this->_loaded_message_dats[] = $entry; if (!empty($message)) { $message = encode(FROM_FILE, $message); $this->_message_array = multi_array_merge($this->_message_array, $message); unset($message); } break; } } } } else { $directory = dir($this->_file_path); while ($entry = $directory->read()) { if (mb_stristr($entry, $rubric)) { if (file_exists($this->_file_path . $entry)) { include_once $this->_file_path . $entry; $this->_loaded_message_dats[] = $entry; if (!empty($message)) { $message = encode(FROM_FILE, $message); $this->_message_array = multi_array_merge($this->_message_array, $message); unset($message); } } } } } }
public function rebuild_deploy($site_id, $page_id, $page_data_id, $site_detail = array()) { if (!$site_id && !$page_id) { return false; } if (!$site_detail) { //查出这个站点使用的套系 $site_detail = $this->pub_config->get_site_first('id,site_name,tem_style,support_client', $site_id); $support_client = explode(',', $site_detail['support_client']); if (!$support_client) { return false; } } else { $support_client = explode(',', $site_detail['support_client']); } $set_type_content = array(); //默认的模板类型 $set_type_default = $this->settings['site_col_template']; //有内容,查出内容类型 $content_type = $this->get_content_type(); include_once CUR_CONF_PATH . 'lib/cache.class.php'; $this->cache = new cache(); if ($site_id && !$page_id) { //先查出这个站点的部署信息 $site_deploy_tem = $this->obj->get_deploy_template($site_id, $this->settings['tem_style_default'], 0, 0); $this->cache->initialize(CUR_CONF_PATH . 'cache/deploy'); $this->cache->set($site_id, $site_deploy_tem[$site_id][0][0]); //取出站点下面的页面 $page_manage = common::get_page_manage($site_id); //取出所有页面类型的模板部署 $page_deploy_tems = $this->obj->get_deploy_template_all($site_id, "'" . $site_detail['tem_style'] . "'"); foreach ($page_manage as $k => $v) { $set_type_use = array(); //给页面类型部署(如果没有,则继承站点部署) $set_type_use = $v['has_content'] ? $set_type_default + $content_type : $set_type_default; foreach ($support_client as $k1 => $v1) { foreach ($set_type_use as $k2 => $v2) { //页面类型部署 if (empty($page_deploy_tems[$site_id][$v['id']][0][$v1][$k2])) { if (!empty($site_deploy_tem[$site_id][0][0][$v1][$k2])) { $page_deploy_tems[$site_id][$v['id']][0][$v1][$k2] = $site_deploy_tem[$site_id][0][0][$v1][$k2]; } else { $page_deploy_tems[$site_id][$v['id']][0][$v1][$k2] = array(); } } } } $this->cache->initialize(CUR_CONF_PATH . 'cache/deploy'); $this->cache->set($site_id . '_' . $v['id'], $page_deploy_tems[$site_id][$v['id']][0]); //给页面数据部署 $this->rebuild_page_data($support_client, $set_type_use, $site_id, $v, $page_deploy_tems, $page_deploy_tems[$site_id][$v['id']][0], $site_detail, 0, 0, 1000); } } else { if ($page_id && !$page_data_id) { $father_deploy_tem = array(); //查询出页面类型详情 $page_info = common::get_page_by_id($page_id); $set_type_use = $page_info['has_content'] ? $set_type_default + $content_type : $set_type_default; //取出所有页面类型的模板部署 $page_deploy_tems = $this->obj->get_deploy_template_all($site_id, "'" . $site_detail['tem_style'] . "'", $page_id); //当前页面类型的模板部署 $this->cache->initialize(CUR_CONF_PATH . 'cache/deploy'); $page_type_deploy_tem_cache = $this->cache->get($site_id . '_' . $page_id); $page_deploy_tems[$site_id][$page_id][0] = $page_deploy_tems[$site_id][$page_id][0] ? $page_deploy_tems[$site_id][$page_id][0] : array(); if (empty($page_type_deploy_tem_cache) && empty($page_deploy_tems[$site_id][$page_id][0])) { //取站点缓存部署 $this->cache->initialize(CUR_CONF_PATH . 'cache/deploy'); $site_deploy_tem_cache = $this->cache->get($site_id); if (!empty($site_deploy_tem_cache)) { $page_deploy_tems[$site_id][$page_id][0] = $site_deploy_tem_cache; } } $father_deploy_tem = multi_array_merge($page_type_deploy_tem_cache, $page_deploy_tems[$site_id][$page_id][0]); $this->cache->initialize(CUR_CONF_PATH . 'cache/deploy'); $this->cache->set($site_id . '_' . $page_id, $father_deploy_tem); //给页面数据部署 $this->rebuild_page_data($support_client, $set_type_use, $site_id, $page_info, $page_deploy_tems, $father_deploy_tem, $site_detail, 0, 0, 1000); } else { if ($page_data_id) { $father_deploy_tem = array(); //查询出页面类型详情 $page_info = common::get_page_by_id($page_id); $set_type_use = $page_info['has_content'] ? $set_type_default + $content_type : $set_type_default; //取出所有页面类型的模板部署 if (!is_numeric($page_data_id)) { return; } $page_deploy_tems = $this->obj->get_deploy_template_all($site_id, "'" . $site_detail['tem_style'] . "'", $page_id, $page_data_id); //当前页面类型的模板部署 $this->cache->initialize(CUR_CONF_PATH . 'cache/deploy'); $page_data_deploy_tem_cache = $this->cache->get($site_id . '_' . $page_id . '_' . $page_data_id); $page_data_deploy_tem_cache = empty($page_data_deploy_tem_cache) ? array() : $page_data_deploy_tem_cache; $page_deploy_tems[$site_id][$page_id][$page_data_id] = $page_deploy_tems[$site_id][$page_id][$page_data_id] ? $page_deploy_tems[$site_id][$page_id][$page_data_id] : array(); if (empty($page_data_deploy_tem_cache) && empty($page_deploy_tems[$site_id][$page_id][$page_data_id])) { $this->rebuild_deploy($site_id, $page_id, 0, $site_detail); $this->cache->initialize(CUR_CONF_PATH . 'cache/deploy'); $page_data_deploy_tem_cache = $this->cache->get($site_id . '_' . $page_id . '_' . $page_data_id); $page_data_deploy_tem_cache = empty($page_data_deploy_tem_cache) ? array() : $page_data_deploy_tem_cache; $page_deploy_tems[$site_id][$page_id][$page_data_id] = $page_deploy_tems[$site_id][$page_id][$page_data_id] ? $page_deploy_tems[$site_id][$page_id][$page_data_id] : array(); } $father_deploy_tem = multi_array_merge($page_data_deploy_tem_cache, $page_deploy_tems[$site_id][$page_id][$page_data_id]); $this->cache->initialize(CUR_CONF_PATH . 'cache/deploy'); $this->cache->set($site_id . '_' . $page_id . '_' . $page_data_id, $father_deploy_tem); //给页面数据部署 $this->rebuild_page_data($support_client, $set_type_use, $site_id, $page_info, $page_deploy_tems, $father_deploy_tem, $site_detail, $page_data_id, 0, 1000); } } } }