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') . '目录不可写');
         }
     }
 }
Esempio n. 2
0
 public function create()
 {
     $m_type = intval($this->input['m_type']);
     $this->m_type = $m_type;
     $client_type = isset($this->input['client_type']) ? $this->input['client_type'] : 2;
     $content_mk_num = $this->input['content_mk_num'] ? intval($this->input['content_mk_num']) : 50;
     //每次取的条数
     $page_number = $this->input['page_number'] ? intval($this->input['page_number']) : 0;
     //最多生成多少条数
     $this->mk_count = $page_number;
     $content_mk_num = $page_number < $content_mk_num ? $page_number : $content_mk_num;
     //$min_weight   = ($this->input['min_weight']);
     //$max_weight   = ($this->input['max_weight']);
     $min_publish_time = $this->input['min_publish_time'];
     $max_publish_time = $this->input['max_publish_time'];
     $content_typearr = $this->input['content_typearr'];
     $is_contain_child = intval($this->input['is_contain_child']);
     //0不支持 1支持
     $this->max_page = intval($this->input['max_page']);
     if ($this->input['site_id']) {
         $site_id = intval(str_replace('site', '', $this->input['site_id']));
     }
     switch ($m_type) {
         case 1:
             $content_typestr = 0;
             $site_id = intval(str_replace('site', '', $this->input['siteid']));
             if (!$site_id) {
                 $this->errorOutput('NO_SITE_ID');
             }
             break;
             //生成首页
         //生成首页
         case 2:
             $site_id = intval(str_replace('site', '', $this->input['siteid']));
             if (!$site_id) {
                 $this->errorOutput('NO_SITE_ID');
             }
             include_once ROOT_PATH . 'lib/class/publishconfig.class.php';
             $this->pub_config = new publishconfig();
             $site = $this->pub_config->get_site_first('*', $site_id);
             if (!$site) {
                 $this->errorOutput('NO_SITE_DETAIL');
             }
             $md = get_site_temdir($site);
             $this->mk_material($site_id, $md);
             $this->mk_mode($site_id, $md);
             $this->mk_frame($site_id, $md, rtrim($site['site_dir'], '/') . '/');
             exit;
             //生成素材,基础框架
         //生成素材,基础框架
         case 3:
             $content_typestr = 0;
             $this->max_page = $this->max_page ? $this->max_page : 20;
             //这个地方需要查出这个栏目首页类型是index还是list,来决定content_type的值
             break;
             //生成栏目页,
         //生成栏目页,
         case 4:
             $content_typestr = -2;
             break;
             //生成内容页
         //生成内容页
         case 5:
             $site_id = intval(str_replace('site', '', $this->input['siteid']));
             if (!$site_id) {
                 $this->errorOutput('NO_SITE_ID');
             }
             deleteDir(ROOT_PATH . 'api/publishsys/cache/mkpublish/' . $site_id);
             echo json_encode('1');
             exit;
         case 6:
             //生成内容类型,获取内容类型
             $is_contain_child = 0;
             $this->max_page = 0;
             if (!$content_typearr) {
                 $all_content_type = $this->pub_content->get_all_content_type();
                 $content_typearr = array_keys($all_content_type);
             }
             if (!$content_typearr) {
                 $this->errorOutput('NO_CONTENT_TYPE');
             }
             $content_typestr = implode(',', $content_typearr);
             if ($min_publish_time) {
                 $this->content_param['starttime'] = $min_publish_time;
             }
             if ($max_publish_time) {
                 $this->content_param['endtime'] = $max_publish_time;
             }
             break;
     }
     if ($fid = $this->input['fid']) {
         $fidarr = explode(',', $fid);
         foreach ($fidarr as $k => $v) {
             if (strstr($v, "page_id") !== false) {
                 $page_idstr = str_replace('page_id', '', $v);
                 $get_page = explode($this->settings['separator'], $page_idstr);
             } else {
                 if (strstr($v, "page_data_id") !== false) {
                     $page_data_id = str_replace('page_data_id', '', $v);
                     $get_page = explode($this->settings['separator'], $page_data_id);
                 }
             }
             $page_id = $get_page[0];
             $page_data_id = $get_page[1];
             $mk_arr[$k]['site_id'] = $site_id;
             $mk_arr[$k]['page_id'] = $page_id;
             $mk_arr[$k]['page_data_id'] = intval($page_data_id);
             $mk_arr[$k]['content_type'] = $content_typestr;
             $mk_arr[$k]['client_type'] = $client_type;
         }
     } else {
         $mk_arr[0]['site_id'] = $site_id;
         $mk_arr[0]['page_id'] = 0;
         $mk_arr[0]['page_data_id'] = 0;
         $mk_arr[0]['content_type'] = $content_typestr;
         $mk_arr[0]['client_type'] = $client_type;
     }
     foreach ($mk_arr as $kk => $vv) {
         $this->set_content_mk_num($content_mk_num);
         $this->set_publish_user(trim($this->user['user_name']));
         $this->set_publish_time(TIMENOW);
         //内容参数
         $content_param = array();
         $site_id = $vv['site_id'];
         $page_id = $vv['page_id'];
         $page_data_id = $vv['page_data_id'];
         //			$content_type[] = $vv['content_type'];
         $content_type = explode(',', $vv['content_type']);
         $client_type = $vv['client_type'];
         $page_data_idarr = explode(',', $page_data_id);
         if ($site_id && !$page_id) {
             if ($is_contain_child) {
                 /*                     * 发布子级 */
                 //查出站点下的页面类型
                 $page_type = $this->pub_sys->get_page_manage($site_id);
                 if (is_array($page_type) && $page_type) {
                     $this->mk_plan_page_type($content_type, $page_type, $is_contain_child, $client_type);
                 }
             } else {
                 /*                     * 不发布子级 */
                 foreach ($content_type as $k => $v) {
                     $this->set_sqlarr($site_id, 0, 0, $v, $client_type, '站点首页');
                 }
             }
         }
         if ($page_id && (count($page_data_idarr) == 1 && !$page_data_idarr[0])) {
             //判断站点有没有,如有,是不是站点包含子级生成发布过了
             //				if($site_id && $is_contain_child)
             //				{
             //					break;
             //				}
             $page_type = $this->pub_sys->get_page_by_id($page_id, 1);
             if (is_array($page_type) && $page_type) {
                 $this->mk_plan_page_type($content_type, $page_type, $is_contain_child, $client_type);
             }
         }
         if ($page_data_idarr && (count($page_data_idarr) != 1 || $page_data_idarr[0])) {
             //判断站点有没有,如有,是不是站点包含子级生成发布过了
             //				if($site_id && $is_contain_child)
             //				{
             //					break;
             //				}
             $page_type = $this->pub_sys->get_page_by_id($page_id, 1, 'id');
             if ($page_type && is_array($page_type)) {
                 foreach ($page_data_idarr as $k => $v) {
                     //					$page_id;#!!!!!
                     $page_data_id = $v;
                     if ($this->m_type != 6) {
                         $page_data = $this->pub_sys->get_page_data($page_id, '', '', '', $page_type[$page_id], $page_data_id);
                         $page_data_detail = $page_data['page_data'][0];
                         $content_type = array();
                         if (is_array($page_data_detail)) {
                             if ($page_data_detail['column_file'] == 'list') {
                                 $content_type[] = -1;
                             } else {
                                 $content_type[] = 0;
                             }
                         } else {
                             $content_type[] = 0;
                         }
                     }
                     foreach ($content_type as $kk => $vv) {
                         $this->set_sqlarr($page_type[$page_id]['site_id'], $page_id, $page_data_id, $vv, $client_type, $page_data_detail['name']);
                     }
                     if ($is_contain_child) {
                         $this->mk_plan_page_data($content_type, $page_type[$page_id], $page_data_id, $is_contain_child, $client_type);
                     }
                 }
             }
         }
     }
     //入库
     if ($this->sqlarr) {
         $this->obj->insert_plan($this->sqlarr);
     }
 }