Esempio n. 1
0
File: mk.php Progetto: h3len/Project
 public function build_mk_cache()
 {
     //获取站点信息
     $this->site = $this->pub_config->get_site_first('*', $this->site_id);
     $css_js_filein_tem = true;
     //获取客户端详细信息
     $this->client = $this->pub_config->get_client_first($this->client_type);
     //设置文件生成方式
     $this->page_info['file_mktype'] = $this->site['produce_format'];
     $this->page_info['filename'] = $this->site['indexname'] ? $this->site['indexname'] : 'index';
     $this->page_info['weburl'] = $this->site['site_info']['url'];
     $this->page_info['dir'] = $this->site['site_dir'];
     $this->page_info['custom_content_dir'] = $this->site['custom_content_dir'];
     $this->page_info['custom_content_dir'] = $this->site['custom_content_dir'];
     $this->page_info['tem_material_dir'] = get_site_temdir($this->site);
     $this->page_info['tem_material_url'] = get_site_temurl($this->site);
     //如果有页面id
     if ($this->page_id) {
         $page_type = common::get_page_manage($this->site_id, $this->page_id, 'id');
         $page_type_detail = $page_type[$this->page_id];
         if ($page_type_detail['sign'] == 'special') {
             //查询专题的生成目录
         } else {
             if ($page_type_detail['sign']) {
                 //设置文件生成方式
                 $this->page_info['file_mktype'] = isset($page_type_detail['maketype']) ? $page_type_detail['maketype'] : 1;
                 $this->page_info['filename'] = isset($page_type_detail['colindex']) ? $page_type_detail['colindex'] : 'index';
                 $this->page_info['weburl'] = $page_type_detail['column_domain'];
                 $this->page_info['dir'] .= $page_type_detail['column_dir'];
             }
         }
         //如果有页面数据id,
         if ($this->page_data_id && $page_type_detail['sign'] != 'special') {
             $page_data = common::get_page_data($this->page_id, '', '', '', $page_type_detail, $this->page_data_id);
             $page_data_detail = $page_data['page_data'][0];
             if (!$page_data_detail) {
                 $this->set_error('未取得page_data_id:' . $this->page_id . '_' . $this->page_data_id . var_export($page_data, true) . '详细信息');
             }
             $this->column = $page_data_detail;
             //设置文件生成方式
             if (in_array($this->content_type, $this->content_type_true)) {
                 $this->page_info['file_mktype'] = $page_data_detail['maketype'];
             } else {
                 $this->page_info['file_mktype'] = $page_data_detail['col_con_maketype'];
                 //表示内容正文(目前生成分页正文全文链接有作用)
                 $this->page_info['page_content_type'] = 1;
             }
             //设置文件生成方式
             $this->page_info['filename'] = $page_data_detail['colindex'];
             $this->page_info['weburl'] = $page_data_detail['column_domain'];
             $this->page_info['dir'] .= $page_data_detail['column_dir'];
             $this->page_info['column_dir'] .= $page_data_detail['column_dir'];
             $this->page_info['relate_dir'] .= $page_data_detail['relate_dir'];
         }
     }
     $this->page_info['suffix'] = $this->page_info['file_mktype'] == 1 ? '.html' : '.php';
     //内容页计算出内容的url
     if (in_array($this->content_type, $this->content_type_true)) {
         $this->is_page_content = false;
     }
     //取单元,设有缓存
     if ($this->page_id_c && $this->page_data_id_c) {
         //专题模块查询出该专题详细信息
         include_once ROOT_PATH . 'lib/class/special.class.php';
         $special_obj = new special();
         $this->special_detail = $special_obj->get_special_by_id($this->page_data_id_c);
         //$cell_ret             = common::get_special_cell_list($this->page_data_id_c, $this->template_sign, 0, $this->page_info['tem_material_url'] . '/' . $this->settings['template_name']);
         $cell_ret = common::getTemplateAndCell(0, 0, $this->page_data_id_c, 0, $this->page_info['tem_material_url'] . '/' . $this->settings['template_name'], $this->template_sign);
         if (is_array($this->special_detail) && $this->special_detail) {
             //$this->page_info['column_dir'] .= $this->special_detail['column_dir'];
             $this->page_info['file_mktype'] = $this->special_detail['maketype'];
             $this->page_info['suffix'] = $this->page_info['file_mktype'] == 1 ? '.html' : '.php';
         }
         //表示内容正文(目前生成分页正文全文链接有作用)
         $this->page_info['page_content_type'] = 0;
     } else {
         if ($page_type_detail['sign'] == 'special') {
             //专题模块查询出该专题详细信息
             include_once ROOT_PATH . 'lib/class/special.class.php';
             $special_obj = new special();
             //根据专题子栏目查询出专题
             $this->special_detail = $special_obj->get_mkspecial('', $this->page_data_id);
             //查询出这个专题的发布目录
             if ($this->special_detail && is_array($this->special_detail)) {
                 $this->special_column = $this->special_detail['special_column'];
                 $this->page_info['column_dir'] .= $this->special_detail['column_dir'];
                 $this->page_info['relate_dir'] = $this->special_detail['relate_dir'];
                 $this->page_info['special_dir'] = $this->special_detail['special_dir'];
                 $this->page_info['file_mktype'] = $this->special_detail['maketype'];
                 $this->page_info['filename'] = $this->special_detail['colindex'];
                 $this->page_info['dir'] .= $this->special_detail['column_dir'];
                 $this->page_info['suffix'] = $this->page_info['file_mktype'] == 1 ? '.html' : '.php';
                 $this->page_info['page_type'] = 'special';
                 $this->template_sign = $this->special_detail['template_sign'];
                 $this->column['name'] = $this->special_detail['title'];
                 $this->column['keywords'] = $this->special_detail['keywords'];
                 $this->column['content'] = $this->special_detail['brief'];
                 $this->page_data_id_s = $this->special_detail['id'];
                 $this->content_type_s = $this->page_data_id . 's';
             } else {
                 $this->set_error('未取到专题信息,专题的栏目id:' . $this->page_data_id . ';专题返回数据(get_mkspecial):' . var_export($this->special_detail, true));
             }
             //$cell_ret = common::get_special_cell_list($this->special_detail['id'], $this->template_sign, $this->page_data_id, $this->page_info['tem_material_url'] . '/' . $this->settings['template_name']);
             $cell_ret = common::getTemplateAndCell(0, 0, $this->special_detail['id'], $this->page_data_id, $this->page_info['tem_material_url'] . '/' . $this->settings['template_name'], $this->template_sign);
         } else {
             //$cell_ret = common::get_cell_list($this->site_id, $this->page_id, $this->page_data_id, $this->content_type, $this->template_sign);
             $cell_ret = common::getTemplateAndCell($this->site_id, $this->page_id, $this->page_data_id, $this->content_type, $this->page_info['tem_material_url'] . '/' . $this->settings['template_name']);
         }
     }
     /**
             foreach($cell_ret['default_cell'] as $k=>$v)
             {
        if($v['layout_id'])
        {
            $cell_ret['default_cell'][$k]['id']=$v['id'].'_'.$v['layout_id'];
        }
             }
     */
     //当前使用中的套系标识
     $template_style = $cell_ret['curr_style'] ? $cell_ret['curr_style'] : 'default';
     //当前模板标识
     $template_sign = $cell_ret['template_sign'];
     //获取模板,设有缓存
     if ($this->page_id_c && $this->page_data_id_c || $page_type_detail['sign'] == 'special') {
         foreach ($cell_ret['default_cell'] as $k => $v) {
             if ($v['layout_id']) {
                 $cell_ret['default_cell'][$k]['id'] = $v['id'] . '_' . $v['layout_id'];
             }
         }
         $this->template_set = $cell_ret['template'];
         //$this->template_set = common::get_template_cache($template_sign, $template_style, $this->settings['special_template']['site_id'], $this->page_info['tem_material_url'] . '/' . $this->settings['template_name']);
     } else {
         $this->template_set = $cell_ret['template'];
         //$this->template_set = common::get_template_cache($template_sign, $template_style, $this->site_id, $this->page_info['tem_material_url'] . '/' . $this->settings['template_name']);
     }
     //页面标题关键字描述的插入到模板中
     if (!$this->is_page_content) {
         $this->template_set = template_process($this->template_set, $this->site, $this->column);
     } else {
         $this->template_set = template_process($this->template_set, $this->site, $this->column, true);
     }
     //取出单元用到的数据源,样式
     $this->cell_process($cell_ret);
     //js加入栏目信息到源码中
     $column_detail_codearr = array('id' => $page_data_detail['id'], 'title' => $page_data_detail['name'], 'keywords' => $page_data_detail['keywords']);
     $column_detail_codestr = "\n" . "<script type=\"text/javascript\">var m2o_column=" . json_encode($column_detail_codearr) . ";";
     $m2o_content_detail_codearr = '<?php 
                     $m2o_content_detail_codearr = array(
                     \'id\' => $__info[\'content\'][\'content_id\'],
                     \'title\' => $__info[\'content\'][\'title\'],
                     \'keywords\' => $__info[\'content\'][\'keywords\'],
                     \'bundle_id\' => $__info[\'content\'][\'bundle_id\'],
                     \'module_id\' => $__info[\'content\'][\'module_id\'],
                     \'content_id\' => $__info[\'content\'][\'content_id\'],
                     \'content_fromid\' => $__info[\'content\'][\'content_fromid\'],
                     \'rid\' => $__info[\'content\'][\'rid\'],
                 );
                 echo json_encode($m2o_content_detail_codearr);
                 ?>';
     $column_detail_codestr .= "var m2o_content = '" . $m2o_content_detail_codearr . "';";
     $column_detail_codestr .= "</script>" . "\n";
     $this->template_set = str_ireplace('</head>', $column_detail_codestr . '</head>', $this->template_set);
     //css加载到模板中
     if (!$this->is_page_content) {
         $this->template_set = str_ireplace('</head>', $this->css . "\n" . '</head>', $this->template_set);
         $this->css = '';
     } else {
         //计算js,css路径,外链到模板head中去
         //页面素材域名
         if ($this->page_id_c && $this->page_data_id_c) {
             $mar_dir = $this->page_id_c . '/' . $this->page_data_id_c . '/' . $this->content_type . '/';
             $css_filename = $this->page_id_c . '_' . $this->page_data_id_c . '_' . $this->content_type . '_' . $this->client_type . '.css';
         } else {
             $mar_dir = $this->page_id . '/' . $this->page_data_id . '/' . $this->content_type . '/';
             $css_filename = $this->page_id . '_' . $this->page_data_id . '_' . $this->content_type . '_' . $this->client_type . '.css';
         }
         //计算css路径
         $this->mar_css['mar_css_dir'] = $this->page_info['tem_material_dir'] . '/' . $this->settings['template_name'] . '/' . $mar_dir;
         $this->mar_css['mar_css_filename'] = $css_filename;
         $css_link = '<link  rel="stylesheet" type="text/css" href="' . $this->page_info['tem_material_url'] . '/' . $this->settings['template_name'] . '/' . $mar_dir . $css_filename . '" />';
         $this->template_set = str_ireplace('</head>', $css_link . "\n" . '</head>', $this->template_set);
     }
     //js添加到</body>之前
     if ($this->js) {
         $this->template_set = str_ireplace('</body>', $this->js . "\n" . '</body>', $this->template_set);
         $this->js = '';
     }
     //生成头部文件
     $this->include_head($cell_ret);
     //生成缓存文件
     $this->set_cache();
     //复制数据源缓存到lib/m2o/include
     if (is_dir(CUR_CONF_PATH . 'cache/datasource')) {
         if (!file_copy(CUR_CONF_PATH . 'cache/datasource', CUR_CONF_PATH . 'lib/m2o/include', array())) {
             $this->set_error('模板服务器:' . realpath(CUR_CONF_PATH . 'lib/m2o/include') . '目录不可写');
         }
     }
 }