function update_tem() { /*if($this->user['group_type'] > MAX_ADMIN_TYPE) { $action = $this->user['prms']['app_prms'][APP_UNIQUEID]['nodes']; if(!in_array('deploy_tem',$action)) { $this->errorOutput("NO_PRIVILEGE"); } }*/ /*模板 权限验证预处理 start*/ $need_auth = 0; //$auth_page_self存储授权页面本身、$auth_page_parents存储授权栏目父级页面 $auth_site = $auth_site_self = $auth_page = $auth_column = $auth_page_self = $auth_page_parents = array(); if ($this->user['group_type'] > MAX_ADMIN_TYPE) { $need_auth = 1; $auth_node = $this->user['prms']['app_prms'][APP_UNIQUEID]['nodes']; if ((is_array($auth_node) ? implode(',', $auth_node) : $auth_node) == 1) { $need_auth = 0; //1表示全选 不需要验证权限 } $auth_node = is_array($auth_node) ? $auth_node : explode(',', $auth_node); if ($need_auth) { foreach ((array) $auth_node as $k => $v) { switch ($v) { case strstr($v, "site") !== false: $v = str_replace("site", "", $v); $v = explode($this->settings['separator'], $v); $auth_site[] = $auth_site_self[] = $v[0]; break; case strstr($v, "page_id") !== false: $v = str_replace("page_id", "", $v); $v = explode($this->settings['separator'], $v); $auth_site[] = $v[0]; $auth_page[] = $auth_page_self[] = $v[1]; break; case strstr($v, "page_data_id") !== false: $v = str_replace("page_data_id", "", $v); $v = explode($this->settings['separator'], $v); $auth_site[] = $v[0]; $auth_page[] = $auth_page_parents[] = $v[1]; $auth_column[$v[1]][] = $v[2]; break; default: break; } } } } /*模板 权限验证预处理 end*/ $data = json_decode(html_entity_decode($this->input['data']), true); if ($data['title'] && is_array($data['title'])) { include_once CUR_CONF_PATH . "lib/rebuild_deploy.class.php"; $rebuild_deploy = new rebuilddeploy(); $group_id = intval($this->input['group_id']); if (!$group_id) { $sql = "select group_id from " . DB_PREFIX . "deploy_template order by group_id DESC limit 1"; $groupdetail = $this->db->query_first($sql); $group_id = intval($groupdetail['group_id']) + 1; } else { $sql = "delete from " . DB_PREFIX . "deploy_template where group_id={$group_id}"; $this->db->query($sql); } foreach ($data['title'] as $k => $v) { $fid = $v['id']; $page_id = 0; $page_data_id = 0; if (strstr($fid, "site") !== false) { $site_id = str_replace('site', '', $fid); } else { if (strstr($fid, "page_id") !== false) { $page_id = intval(str_replace('page_id', '', $fid)); $page_detail = common::get_page_by_id($page_id); $site_id = $page_detail['site_id']; } else { if (strstr($fid, "page_data_id") !== false) { $page_data_id = str_replace('page_data_id', '', $fid); $get_page = explode($this->settings['separator'], $page_data_id); $page_id = $get_page[0]; $page_data_id = $get_page[1]; $page_detail = common::get_page_by_id($page_id); $site_id = $page_detail['site_id']; } else { continue; } } } $sql = "delete from " . DB_PREFIX . "deploy_template where site_id={$site_id} and page_id={$page_id} and page_data_id={$page_data_id}"; $this->db->query($sql); if ($data['page'] && is_array($data['page'])) { foreach ($data['page'] as $kk => $vv) { $this->update($site_id, $page_id, $page_data_id, $vv['content_type'], $vv['sign'], $v['title'], $v['full_title'], $group_id); } } $rebuild_deploy->rebuild_deploy($site_id, $page_id, $page_data_id); } } $content_type = $this->pub_content->get_all_content_type(); $ret['site'] = common::get_deploy_templates($site_id, 0, 0); if ($need_auth) { if (!in_array($site_id, $auth_site_self)) { $ret['no_auth_site'] = 1; //是否已经授权站点 } } $page_info = array(); $sql = "select * from " . DB_PREFIX . "deploy_template where site_id=" . $site_id . " and page_id!=0 order by group_id DESC,content_type,id"; $info = $this->db->query($sql); while ($row = $this->db->fetch_array($info)) { if ($need_auth) { //只显示授权节点和授权节点孩子节点 if ($row['site_id'] && !$row['page_id'] && !$row['page_data_id']) { //授权节点本身 显示 if (!in_array($row['site_id'], $auth_site_self)) { continue; } } if ($row['site_id'] && $row['page_id'] && !$row['page_data_id']) { //授权节点本身或者孩子节点 显示 if (!in_array($row['page_id'], $auth_page_self) && !in_array($row['site_id'], $auth_site_self)) { continue; } } if ($row['site_id'] && $row['page_id'] && $row['page_data_id']) { $cur_page_auth_column = isset($auth_column[$row['page_id']]) ? $auth_column[$row['page_id']] : array(); //授权节点本身或者孩子节点 显示 if (!in_array($row['page_data_id'], $cur_page_auth_column) && !in_array($row['page_id'], $auth_page_self) && !in_array($row['site_id'], $auth_site_self)) { $page_data = common::get_page_data($row['page_id'], 0, 1, 0, $page_info[$row['page_id']], $row['page_data_id']); $page_info[$row['page_id']] = $page_data['page_info']; //记录page信息 下次调用common::get_page_data方法时使用 foreach ((array) $page_data['page_data'] as $k => $v) { $auth_column_parents[$v['id']] = $v['parents']; } //栏目孩子节点显示 if (!array_intersect(explode(',', $auth_column_parents[$row['page_data_id']]), $cur_page_auth_column)) { continue; } } } } $use_content_type[$row['content_type']] = $row['content_type']; if ($row['site_id'] && !$row['page_id'] && !$row['page_data_id']) { continue; $page_title_id = 'site' . $row['site_id']; } else { if ($row['page_id'] && !$row['page_data_id']) { $page_title_id = 'page_id' . $row['page_id']; } else { $page_title_id = 'page_data_id' . $row['page_id'] . '_' . $row['page_data_id']; } } if (!isset($page_title_c[$row['group_id']][$row['site_id']][$row['page_id']][$row['page_data_id']])) { $page_title[$row['group_id']][] = array('id' => $page_title_id, 'title' => $row['title'], 'full_title' => $row['full_title']); $page_title_c[$row['group_id']][$row['site_id']][$row['page_id']][$row['page_data_id']] = $row['id']; } if ($row['content_type'] > 0) { $page[$row['group_id']][$row['content_type']] = array('content_type' => $content_type[$row['content_type']], 'dep' => $row); } else { $page[$row['group_id']][$row['content_type']] = array('content_type' => array('content_type' => !$row['content_type'] ? '首页' : '列表页'), 'dep' => $row); } } $ret['content_type'] = $content_type; $ret['page_title'] = $page_title; $ret['page'] = $page; $this->addItem($ret); $this->output(); }
/** * 合并当前页面模板 * * * */ private function mergeCell() { if (!class_exists('publishconfig')) { include_once ROOT_PATH . 'lib/class/publishconfig.class.php'; } $this->objPub = new publishconfig(); if (!$this->arSiteInfo) { $this->arSiteInfo = $this->objPub->get_site_first('*', $this->intSiteId); } if ($this->intLayoutId) { if (!class_exists('layout')) { include CUR_CONF_PATH . 'lib/layout.class.php'; } $objLayout = new layout(); $this->arCellList = $objLayout->getLayoutCell($this->intLayoutId); return ''; } if ($this->blPreset && $this->blPreset != 'false') { $deploy = common::get_template_cell($this->intSiteId, $this->intTemplateId, $this->strTemplateSign); $this->arCellList = $deploy['default_cell']; return; } if ($this->strTemplateSign && (!$this->blPreset || $this->blPreset === 'false')) { //快速专题 取出此专题的布局信息 内容类型存在时是列表页 列表页暂不支持布局 if (!$this->intContentType) { $sql = "SELECT * FROM " . DB_PREFIX . "template_layout WHERE special_id = " . $this->intPageDataId; $templateLayout = $this->db->query_first($sql); $layoutIds = $templateLayout['layout_ids']; if ($layoutIds) { $this->strLayoutIds = $layoutIds; if (!class_exists('layout')) { include CUR_CONF_PATH . 'lib/layout.class.php'; } $objLayout = new layout(); $sql = "SELECT id, content, css, is_header, header_text, is_more, more_href,original_id \r\n FROM " . DB_PREFIX . "layout WHERE id IN(" . $layoutIds . ")"; $q = $this->db->query($sql); $layoutInfo = array(); while ($row = $this->db->fetch_array($q)) { $row = $objLayout->layout_namespace_and_header_process($row); $layoutInfo[$row['id']] = $row; } $layoutIds = explode(',', $layoutIds); $layouts = array(); if (is_array($layoutIds) && count($layoutIds) > 0) { $layoutIds = array_reverse($layoutIds); foreach ($layoutIds as $k => $v) { $cells = array(); $cells = $objLayout->getLayoutCell($v); $layoutInfo[$v]['cells'] = $cells; $layouts[] = $layoutInfo[$v]; } } $this->arLayoutInfo = $layouts; } } } else { include_once CUR_CONF_PATH . 'lib/rebuild_deploy.class.php'; $deploy = new rebuilddeploy(); $deployTemplate = $deploy->get_deploy_templates($this->intSiteId, $this->intPageId, $this->intPageDataId); //赛选此客户端类型下该内容类型下部署的模板 $this->strTemplateSign = $deployTemplate[$this->intClientType][$this->intContentType]['template_sign']; //没有部署模板时使用全局类型模板 if (!$this->strTemplateSign) { $sql = "SELECT id, sign FROM " . DB_PREFIX . "templates WHERE site_id = 0 AND content_type = " . $this->intContentType; $arInfo = $this->db->query_first($sql); if (!$arInfo) { return array('errmsg' => '该内容类型全局模板不存在'); } $this->strTemplateSign = $arInfo['sign']; $this->intUseGlobalTemplate = 1; } } //模板合并机制更改 老机制多套系切换时有bug 20140831 if (!$this->arSiteInfo) { $this->arSiteInfo = $this->objPub->get_site_first('tem_style', $this->intSiteId); } $this->strCurrStyle = $this->arSiteInfo['tem_style']; //使用默认套系 if ($this->strDefaultStyle == $this->arSiteInfo['tem_style']) { //默认套系中该模板预设单元 $condition = " AND c.template_style='" . $this->strDefaultStyle . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id = 0"; $arDefaultCell = common::get_cell($condition); //默认套系中页面单元 $condition = " AND c.site_id = " . $this->intSiteId . " AND c.page_id=" . $this->intPageId . " AND c.page_data_id=" . $this->intPageDataId . " AND c.content_type = " . $this->intContentType . "\r\n AND c.template_style='" . $this->strDefaultStyle . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id != 0"; $defaultSetCell = common::get_cell($condition); //合并模板单元和页面单元 优先使用页面单元 if (is_array($defaultSetCell) && count($defaultSetCell)) { foreach ($defaultSetCell as $k => $v) { if (array_key_exists($k, $arDefaultCell)) { $arDefaultCell[$k] = $defaultSetCell[$k]; } } } } else { $sql = "SELECT id FROM " . DB_PREFIX . "templates WHERE template_style = '" . $this->arSiteInfo['tem_style'] . "' AND sign = '" . $this->strTemplateSign . "'"; $info = $this->db->query_first($sql); if (!$info['id']) { //默认套系中该模板预设单元 $condition = " AND c.template_style='" . $this->strDefaultStyle . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id = 0"; $arDefaultCell = common::get_cell($condition); //默认套系中页面单元 $condition = " AND c.site_id = " . $this->intSiteId . " AND c.page_id=" . $this->intPageId . " AND c.page_data_id=" . $this->intPageDataId . " AND c.content_type = " . $this->intContentType . "\r\n AND c.template_style='" . $this->strDefaultStyle . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id != 0"; $defaultSetCell = common::get_cell($condition); //合并模板单元和页面单元 优先使用页面单元 if (is_array($defaultSetCell) && count($defaultSetCell)) { foreach ($defaultSetCell as $k => $v) { if (array_key_exists($k, $arDefaultCell)) { $arDefaultCell[$k] = $defaultSetCell[$k]; } } } } else { //当前使用套系模板预设单元 $condition = " AND c.template_style='" . $this->arSiteInfo['tem_style'] . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id = 0"; $arDefaultCell = common::get_cell($condition); //当前使用套系页面单元 $condition = " AND c.site_id=" . $this->intSiteId . " AND c.page_id=" . $this->intPageId . " AND c.page_data_id=" . $this->intPageDataId . " AND c.content_type = " . $this->intContentType . "\r\n AND c.template_style='" . $this->arSiteInfo['tem_style'] . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id != 0 "; $defaultSetCell = common::get_cell($condition); //合并模板预设单元和页面单元 优先使用页面单元 if (is_array($defaultSetCell) && count($defaultSetCell) > 0) { foreach ($defaultSetCell as $k => $v) { if (array_key_exists($k, $arDefaultCell)) { $arDefaultCell[$k] = $defaultSetCell[$k]; } } } } } //模板合并机制更改 老机制多套系切换时bug 20140831 // //默认套系中该模板单元 // $condition = " AND c.template_style='" . $this->strDefaultStyle . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id = 0"; // $arDefaultCell = common::get_cell($condition); // //默认套系中页面单元 // $condition = " AND c.site_id = " . $this->intSiteId . " AND c.page_id=" . $this->intPageId . " AND c.page_data_id=" . $this->intPageDataId . " AND c.content_type = " . $this->intContentType . " // AND c.template_style='" . $this->strDefaultStyle . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id != 0"; // $defaultSetCell = common::get_cell($condition); // //第一次合并 默认套系中的模板单元和默认套系中的页面单元 // if (is_array($defaultSetCell) && count($defaultSetCell)) // { // foreach ($defaultSetCell as $k => $v) // { // if (array_key_exists($k, $arDefaultCell)) // { // $arDefaultCell[$k] = $defaultSetCell[$k]; // } // } // } // //当前使用套系该模板单元 // if (!$this->arSiteInfo) // { // $this->arSiteInfo = $this->objPub->get_site_first('tem_style', $this->intSiteId); // } // $this->strCurrStyle = $this->arSiteInfo['tem_style']; // $condition = " AND c.template_style='" . $this->arSiteInfo['tem_style'] . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id = 0"; // $arUsingCell = common::get_cell($condition); // //第二次合并 第一次合并后的单元和当前使用套系模板单元 // if (is_array($arUsingCell) && count($arUsingCell) > 0) // { // foreach ($arUsingCell as $k => $v) // { // if (array_key_exists($k, $arDefaultCell)) // { // if ($arUsingCell[$k]['cell_mode'] || $arUsingCell[$k]['data_source']) // { // $arDefaultCell[$k] = $arUsingCell[$k]; // } // } // } // } // //当前使用套系页面单元 // $condition = " AND c.site_id=" . $this->intSiteId . " AND c.page_id=" . $this->intPageId . " AND c.page_data_id=" . $this->intPageDataId . " AND c.content_type = " . $this->intContentType . " // AND c.template_style='" . $this->arSiteInfo['tem_style'] . "' AND c.template_sign IN('" . $this->strTemplateSign . "') AND c.original_id != 0 "; // $arUsingSetCell = common::get_cell($condition); // //第三次合并 第二次合并后的单元和当前使用套系页面单元 // if (is_array($arUsingSetCell) && count($arUsingSetCell) > 0) // { // foreach ($arUsingSetCell as $k => $v) // { // if (array_key_exists($k, $arDefaultCell)) // { // $arDefaultCell[$k] = $arUsingSetCell[$k]; // } // } // } $this->arCellList = $arDefaultCell; return; }
public function test() { include_once CUR_CONF_PATH . "lib/rebuild_deploy.class.php"; $rebuild_deploy = new rebuilddeploy(); $data = $rebuild_deploy->get_deploy_templates(1, 8, 1); print_r($data); exit; }
public function merge_cell($site_id, $page_id = '', $page_data_id = '', $content_type = '', $site = array(), $template_sign = '') { $default_style = $this->settings['tem_style_default']; //当前部署的模板名 if (!$template_sign) { include_once CUR_CONF_PATH . 'lib/rebuild_deploy.class.php'; $deploy = new rebuilddeploy(); $deploy_template = $deploy->get_deploy_templates($site_id, $page_id, $page_data_id); //赛选此客户端类型下该内容类型下部署的模板 $client_type = $this->input['client_type'] ? $this->input['client_type'] : 2; $template = $deploy_template[$client_type][$content_type]['template_sign']; } else { $template = $template_sign; } //默认套系中该模板单元 $condition = " AND c.template_style='" . $default_style . "' AND c.template_sign IN('" . $template . "') AND c.original_id = 0"; $default_cell = self::get_cell($condition); //默认套系中页面单元 $condition = " AND c.template_style='" . $default_style . "' AND c.template_sign IN('" . $template . "') AND c.site_id = " . $site_id . " AND c.page_id=" . $page_id . " AND c.page_data_id=" . $page_data_id . " AND c.content_type = " . $content_type . " AND c.original_id != 0"; $default_set_cell = self::get_cell($condition); //第一次合并 默认套系中的模板单元和默认套系中的页面单元 if (is_array($default_set_cell) && count($default_set_cell)) { foreach ($default_set_cell as $k => $v) { if (array_key_exists($k, $default_cell)) { $default_cell[$k] = $default_set_cell[$k]; } } } //当前使用套系该模板单元 if (!$site) { include_once ROOT_PATH . 'lib/class/publishconfig.class.php'; $this->pub = new publishconfig(); $site = $this->pub->get_site_first('tem_style', $site_id); } $condition = " AND c.template_style='" . $site['tem_style'] . "' AND c.template_sign IN('" . $template . "') AND c.content_type = " . $content_type . " AND c.original_id = 0"; $using_cell = self::get_cell($condition); //第二次合并 第一次合并后的单元和当前使用套系模板单元 if (is_array($using_cell) && count($using_cell) > 0) { foreach ($using_cell as $k => $v) { if (array_key_exists($k, $default_cell)) { if ($using_cell[$k]['cell_mode'] || $using_cell[$k]['data_source']) { $default_cell[$k] = $using_cell[$k]; } } } } //当前使用套系页面单元 $condition = " AND c.template_style='" . $site['tem_style'] . "' AND c.template_sign IN('" . $template . "') AND c.site_id=" . $site_id . " AND c.page_id=" . $page_id . " AND c.page_data_id=" . $page_data_id . " AND c.content_type = " . $content_type . " AND c.original_id != 0 "; $using_set_cell = self::get_cell($condition); //第三次合并 第二次合并后的单元和当前使用套系页面单元 if (is_array($using_set_cell) && count($using_set_cell) > 0) { foreach ($using_set_cell as $k => $v) { if (array_key_exists($k, $default_cell)) { $default_cell[$k] = $using_set_cell[$k]; } } } $ret = array('default_style' => $default_style, 'curr_style' => $site['tem_style'], 'template_sign' => $template, 'default_cell' => $default_cell); return $ret; }