コード例 #1
0
ファイル: Html.class.php プロジェクト: NeilFee/vipxinbaigo
 /**
  * 生成内容页
  * @param  $data 数据
  * @param  $array_merge 是否合并
  * @param  $action 方法
  */
 public function show($data = '', $array_merge = 1, $action = 'add')
 {
     if (!$data['inputtime'] || !$data['id'] || !$data['catid']) {
         return false;
     }
     //初始化一些模板分配变量
     $this->assignInitialize();
     //取得信息ID
     $id = $data['id'];
     //栏目ID
     $catid = $data['catid'];
     //获取当前栏目数据
     $category = getCategory($catid);
     //模型ID
     $this->modelid = $category['modelid'];
     //分页方式
     if (isset($data['paginationtype'])) {
         //分页方式
         $paginationtype = $data['paginationtype'];
         //自动分页字符数
         $maxcharperpage = (int) $data['maxcharperpage'];
     } else {
         //默认不分页
         $paginationtype = 0;
     }
     //载入字段数据处理类
     if (false == require_cache(RUNTIME_PATH . 'content_output.class.php')) {
         D("Category")->category_cache();
         D("Content_cache")->model_content_cache();
         require RUNTIME_PATH . 'content_output.class.php';
     }
     $content_output = new content_output($this->modelid);
     //获取字段类型处理以后的数据
     $output_data = $content_output->get($data);
     $output_data['id'] = $id;
     $output_data['title'] = strip_tags($output_data['title']);
     //SEO
     $seo_keywords = '';
     if (!empty($output_data['keywords'])) {
         $seo_keywords = implode(',', $output_data['keywords']);
     }
     $seo = seo($catid, $output_data['title'], $output_data['description'], $seo_keywords);
     //内容页模板
     $template = $output_data['template'] ? $output_data['template'] : $category['setting']['show_template'];
     //去除模板文件后缀
     $newstempid = explode(".", $template);
     $template = $newstempid[0];
     unset($newstempid);
     //检测模板是否存在、不存在使用默认!
     $tempstatus = parseTemplateFile("Show:" . $template);
     if ($tempstatus == false && $template != "show") {
         //模板不存在,重新使用默认模板
         $template = "show";
         $tempstatus = parseTemplateFile("Show:" . $template);
         if ($tempstatus == false) {
             return false;
         }
     } else {
         if ($tempstatus == false) {
             return false;
         }
     }
     //分页处理
     $pages = $titles = '';
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] == 1) {
         //自动分页
         if ($maxcharperpage < 10) {
             $maxcharperpage = 500;
         }
         //按字数分割成几页处理开始
         import('Contentpage', APP_PATH . C("APP_GROUP_PATH") . '/Contents/ORG');
         $contentpage = new Contentpage();
         $contentfy = $contentpage->get_data($output_data['content'], $maxcharperpage);
         //自动分页有时会造成返回空,如果返回空,就不分页了
         if (!empty($contentfy)) {
             $output_data['content'] = $contentfy;
         }
     }
     //分配解析后的文章数据到模板
     $this->assign($output_data);
     //seo分配到模板
     $this->assign("SEO", $seo);
     //栏目ID
     $this->assign("catid", $catid);
     //分页生成处理
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] > 0) {
         //手动分页
         $CONTENT_POS = strpos($output_data['content'], '[page]');
         if ($CONTENT_POS !== false) {
             $contents = array_filter(explode('[page]', $output_data['content']));
             $pagenumber = count($contents);
             for ($i = 1; $i <= $pagenumber; $i++) {
                 //URL地址处理
                 $urlrules = $this->url->show($data, $i);
                 //用于分页导航
                 if (!isset($pageurl['index'])) {
                     $pageurl['index'] = $urlrules['page']['index'];
                     $pageurl['list'] = $urlrules['page']['list'];
                 }
                 $pageurls[$i] = $urlrules;
             }
             $pages = "";
             //生成分页
             foreach ($pageurls as $page => $urls) {
                 //$pagenumber 分页总数
                 $_GET[C("VAR_PAGE")] = $page;
                 $pages = page($pagenumber, 1, $page, array('isrule' => true, 'rule' => $pageurl))->show("default");
                 //判断[page]出现的位置是否在第一位
                 if ($CONTENT_POS < 7) {
                     $content = $contents[$page];
                 } else {
                     $content = $contents[$page - 1];
                 }
                 //分页
                 $this->assign("pages", $pages);
                 $this->assign("content", $content);
                 $this->buildHtml($urls['path'], SITE_PATH . "/", $tempstatus);
             }
             return true;
         }
     }
     //对pages进行赋值null,解决由于上一篇有分页下一篇无分页的时候,会把上一篇的分页带到下一篇!
     $this->assign("pages", null);
     $this->assign("content", $output_data['content']);
     //当没有启用内容页分页时候(如果内容字段有启用分页,不会执行到此步骤),判断其他支持分页的标签进行分页处理
     unset($GLOBALS["Total_Pages"]);
     $page = 1;
     $j = 1;
     //开始生成列表
     do {
         $this->assign(C("VAR_PAGE"), $page);
         //生成路径
         $category_url = $this->url->show($data, $page);
         $GLOBALS['URLRULE'] = implode("~", $category_url['page']);
         //生成
         $this->buildHtml($category_url["path"], SITE_PATH . "/", $tempstatus);
         $page++;
         $j++;
         $total_number = isset($_GET['total_number']) ? (int) $_GET['total_number'] : (int) $GLOBALS["Total_Pages"];
     } while ($j <= $total_number);
     return true;
 }
コード例 #2
0
 /**
  * 内容页 
  */
 public function shows()
 {
     $catid = $this->_get("catid");
     $id = $this->_get("id");
     $page = intval($_GET[C("VAR_PAGE")]);
     $page = max($page, 1);
     if (!$id || !$catid) {
         $this->error("缺少参数!");
     }
     $model = F("Model");
     $this->categorys = F("Category");
     //主表名称
     $tableName = ucwords($model[$this->categorys[$catid]['modelid']]['tablename']);
     if (empty($tableName)) {
         $this->error("模型不存在!");
     }
     $this->db = new ContentModel($tableName);
     $data = $this->db->relation(true)->where(array("id" => $id, 'status' => 99))->find();
     if (empty($data)) {
         $this->error("该信息不存在!");
     }
     $data = array_merge($data, $data[$tableName . "_data"]);
     unset($data[$tableName . "_data"]);
     if (isset($data['paginationtype'])) {
         $paginationtype = $data['paginationtype'];
         $maxcharperpage = $data['maxcharperpage'];
     } else {
         $paginationtype = 0;
     }
     $catid = $data['catid'];
     $CATEGORYS = $this->categorys;
     $CAT = $CATEGORYS[$catid];
     //取得栏目配置
     $CAT['setting'] = unserialize($CAT['setting']);
     //模型ID
     $this->modelid = $modelid = $CAT['modelid'];
     //载入字段数据处理类
     require_cache(RUNTIME_PATH . 'content_output.class.php');
     $content_output = new content_output($modelid, $catid, $CATEGORYS);
     $output_data = $content_output->get($data);
     $output_data['id'] = $id;
     extract($output_data);
     //上一页
     $where = array();
     $where['catid'] = $catid;
     $where['status'] = array("EQ", "99");
     $where['id'] = array("LT", $id);
     $previous_page = $this->db->where($where)->order(array("id" => "DESC"))->find();
     //下一页
     $where['id'] = array("GT", $id);
     $next_page = $this->db->where($where)->find();
     if (empty($previous_page)) {
         $previous_page = array('title' => "第一页", 'thumb' => CONFIG_SITEURL . 'statics/images/nopic_small.gif', 'url' => 'javascript:alert(\'第一页\');');
     }
     if (empty($next_page)) {
         $next_page = array('title' => "最后一页", 'thumb' => CONFIG_SITEURL . 'statics/images/nopic_small.gif', 'url' => 'javascript:alert(\'最后一页\');');
     }
     $output_data['title'] = $title = strip_tags($title);
     //SEO
     $seo_keywords = '';
     if (!empty($keywords)) {
         $seo_keywords = implode(',', $keywords);
     }
     $SEO = seo($catid, $title, $description, $seo_keywords);
     //模板处理开始
     $template = $template ? $template : $CAT['setting']['show_template'];
     //去除模板文件后缀
     $newstempid = explode(".", $template);
     $template = $newstempid[0];
     //检测模板是否存在、不存在使用默认!
     $tempstatus = parseTemplateFile("Show:" . $template);
     if ($tempstatus == false) {
         $template = "show";
         unset($tempstatus);
     }
     //分页处理
     $pages = $titles = '';
     if ($paginationtype == 1) {
         //自动分页
         if ($maxcharperpage < 10) {
             $maxcharperpage = 500;
         }
         import('@.ORG.Contentpage');
         $contentpage = new Contentpage();
         $contentfy = $contentpage->get_data($content, $maxcharperpage);
         //自动分页有时会造成返回空,如果返回空,就不分页了
         if (!empty($contentfy)) {
             $content = $contentfy;
         }
     }
     //分配变量到模板
     $this->assign($output_data);
     //seo分配到模板
     $this->assign("SEO", $SEO);
     //上一篇 下一篇
     $this->assign("previous_page", $previous_page);
     $this->assign("next_page", $next_page);
     //栏目ID
     $this->assign("catid", $catid);
     //模板地址
     $template = $tempstatus;
     //文章支持分页
     if ($paginationtype > 0) {
         $urlrules = $this->url->show($id, $page, $catid, $inputtime, $prefix, "", "", "URLRULE");
         $urlrules = implode("~", $urlrules);
         //print_r($urlrules);exit;
         define('URLRULE', $urlrules);
         //手动分页
         $CONTENT_POS = strpos($content, '[page]');
         if ($CONTENT_POS !== false) {
             $contents = array_filter(explode('[page]', $content));
             $pagenumber = count($contents);
             if (strpos($content, '[/page]') !== false && $CONTENT_POS < 7) {
                 $pagenumber--;
             }
             for ($i = 1; $i <= $pagenumber; $i++) {
                 $pageurls[$i] = $this->url->show($id, $i, $catid, $rs['inputtime']);
             }
             $END_POS = strpos($content, '[/page]');
             if ($END_POS !== false) {
                 if ($CONTENT_POS > 7) {
                     $content = '[page]' . $title . '[/page]' . $content;
                 }
                 if (preg_match_all("|\\[page\\](.*)\\[/page\\]|U", $content, $m, PREG_PATTERN_ORDER)) {
                     foreach ($m[1] as $k => $v) {
                         $p = $k + 1;
                         $titles[$p]['title'] = strip_tags($v);
                         $titles[$p]['url'] = $pageurls[$p][0];
                     }
                 }
             }
             //当不存在 [/page]时,则使用下面分页
             $pages = page($pagenumber, 1, $page, 6, C("VAR_PAGE"), '', true)->show("default");
             //判断[page]出现的位置是否在第一位
             if ($CONTENT_POS < 7) {
                 $content = $contents[$page];
             } else {
                 if ($page == 1 && !empty($titles)) {
                     $content = $title . '[/page]' . $contents[$page - 1];
                 } else {
                     $content = $contents[$page - 1];
                 }
             }
             if ($titles) {
                 list($title, $content) = explode('[/page]', $content);
                 $content = trim($content);
                 if (strpos($content, '</p>') === 0) {
                     $content = '<p>' . $content;
                 }
                 if (stripos($content, '<p>') === 0) {
                     $content = $content . '</p>';
                 }
             }
         }
     }
     $this->assign("pages", $pages);
     $this->assign("content", $content);
     $this->display($template);
 }
コード例 #3
0
 /**
  * 生成内容页
  * @param  $file 文件地址
  * @param  $data 数据
  * @param  $array_merge 是否合并
  * @param  $action 方法
  */
 public function show($file, $data = '', $array_merge = 1, $action = 'add')
 {
     //取得信息ID
     $id = $data['id'];
     //判断数据是否已经合并成一个数组,而不是分主表和附表
     if ($array_merge) {
         $data = new_stripslashes($data);
         $data = array_merge($data['system'], $data['model']);
         $data['id'] = $id;
     }
     //通过rs获取原始值
     $rs = $data;
     //栏目ID
     $catid = $data['catid'];
     //获取栏目缓存
     $Category = $this->categorys;
     //获取当前栏目数据
     $CAT = $Category[$catid];
     //反序列化栏目配置
     $CAT['setting'] = unserialize($CAT['setting']);
     //模型ID
     $this->modelid = $modelid = $CAT['modelid'];
     //获取主表名
     $this->table_name = $this->Model[$this->modelid]['tablename'];
     //处理由于通过关联模型获取数据,会把副表字段内容归入下标为 表名_data ,重新组合
     if (isset($data[ucwords($this->table_name) . "_data"])) {
         $data = array_merge($data, $data[ucwords($this->table_name) . "_data"]);
         unset($data[ucwords($this->table_name) . "_data"]);
     }
     //分页方式
     if (isset($data['paginationtype'])) {
         //分页方式
         $paginationtype = $data['paginationtype'];
         //自动分页字符数
         $maxcharperpage = (int) $data['maxcharperpage'];
     } else {
         //默认不分页
         $paginationtype = 0;
     }
     //载入字段数据处理类
     if (!file_exists(RUNTIME_PATH . 'content_output.class.php')) {
         $this->error("请更新缓存后再操作!");
     }
     require_cache(RUNTIME_PATH . 'content_output.class.php');
     $content_output = new content_output($modelid, $catid, $Category);
     //获取字段类型处理以后的数据
     $output_data = $content_output->get($data);
     $output_data['id'] = $id;
     extract($output_data);
     $this->table_name = $this->Model[$this->modelid]['tablename'];
     $this->db = M(ucwords($this->table_name));
     //上一篇
     $where = array();
     $where['catid'] = $catid;
     $where['status'] = array("EQ", "99");
     $where['id'] = array("LT", $id);
     $previous_page = $this->db->where($where)->order(array("id" => "DESC"))->find();
     //下一篇
     $where['id'] = array("GT", $id);
     $next_page = $this->db->where($where)->find();
     if (empty($previous_page)) {
         $previous_page = array('title' => "第一页", 'thumb' => CONFIG_SITEURL . 'statics/images/nopic_small.gif', 'url' => 'javascript:alert(\'第一页\');');
     }
     if (empty($next_page)) {
         $next_page = array('title' => "最后一页", 'thumb' => CONFIG_SITEURL . 'statics/images/nopic_small.gif', 'url' => 'javascript:alert(\'最后一页\');');
     }
     $output_data['title'] = $title = strip_tags($title);
     //SEO
     $seo_keywords = '';
     if (!empty($keywords)) {
         $seo_keywords = implode(',', $keywords);
     }
     $SEO = seo($catid, $title, $description, $seo_keywords);
     //模板处理开始
     $template = $template ? $template : $CAT['setting']['show_template'];
     //去除模板文件后缀
     $newstempid = explode(".", $template);
     $template = $newstempid[0];
     unset($newstempid);
     //检测模板是否存在、不存在使用默认!
     $tempstatus = parseTemplateFile("Show:" . $template);
     if ($tempstatus == false) {
         //模板不存在,重新使用默认模板
         $template = "show";
         $tempstatus = parseTemplateFile("Show:" . $template);
     }
     //分页处理
     $pages = $titles = '';
     if ($paginationtype == 1) {
         //自动分页
         if ($maxcharperpage < 10) {
             $maxcharperpage = 500;
         }
         //按字数分割成几页处理开始
         import('Contentpage', APP_PATH . C("APP_GROUP_PATH") . '/Contents/ORG');
         $contentpage = new Contentpage();
         $contentfy = $contentpage->get_data($content, $maxcharperpage);
         //自动分页有时会造成返回空,如果返回空,就不分页了
         if (!empty($contentfy)) {
             $content = $contentfy;
         }
     }
     //分配变量到模板
     $this->assign($output_data);
     //seo分配到模板
     $this->assign("SEO", $SEO);
     //上一篇 下一篇
     $this->assign("previous_page", $previous_page);
     $this->assign("next_page", $next_page);
     //栏目ID
     $this->assign("catid", $catid);
     //模板地址
     $template = $tempstatus;
     //分页生成处理
     if ($paginationtype > 0) {
         //手动分页
         $CONTENT_POS = strpos($content, '[page]');
         if ($CONTENT_POS !== false) {
             $contents = array_filter(explode('[page]', $content));
             $pagenumber = count($contents);
             if (strpos($content, '[/page]') !== false && $CONTENT_POS < 7) {
                 $pagenumber--;
             }
             for ($i = 1; $i <= $pagenumber; $i++) {
                 $pageurls[$i] = $this->url->show($id, $i, $catid, $data['inputtime'], $data['prefix'], '', 'edit');
             }
             $END_POS = strpos($content, '[/page]');
             if ($END_POS !== false) {
                 if ($CONTENT_POS > 7) {
                     $content = '[page]' . $title . '[/page]' . $content;
                 }
                 if (preg_match_all("|\\[page\\](.*)\\[/page\\]|U", $content, $m, PREG_PATTERN_ORDER)) {
                     foreach ($m[1] as $k => $v) {
                         $p = $k + 1;
                         $titles[$p]['title'] = strip_tags($v);
                         $titles[$p]['url'] = $pageurls[$p][0];
                     }
                 }
             }
             $urlrules = $this->url->show($id, $page, $catid, $data['inputtime'], $data['prefix'], "", "", "URLRULE");
             $urlrules = implode("~", $urlrules);
             define('URLRULE', $urlrules);
             $pages = "";
             //生成分页
             foreach ($pageurls as $page => $urls) {
                 //$pagenumber 分页总数
                 $_GET[C("VAR_PAGE")] = $page;
                 $pages = page($pagenumber, 1, $page, 6, C("VAR_PAGE"), '', true)->show("default");
                 //判断[page]出现的位置是否在第一位
                 if ($CONTENT_POS < 7) {
                     $content = $contents[$page];
                 } else {
                     if ($page == 1 && !empty($titles)) {
                         $content = $title . '[/page]' . $contents[$page - 1];
                     } else {
                         $content = $contents[$page - 1];
                     }
                 }
                 if ($titles) {
                     list($title, $content) = explode('[/page]', $content);
                     $content = trim($content);
                     if (strpos($content, '</p>') === 0) {
                         $content = '<p>' . $content;
                     }
                     if (stripos($content, '<p>') === 0) {
                         $content = $content . '</p>';
                     }
                 }
                 //分页
                 $this->assign("pages", $pages);
                 $this->assign("content", $content);
                 $pagefile = $urls[1];
                 //生成路径
                 $this->buildHtml($pagefile, SITE_PATH . "/", $template);
             }
             $this->assign("pages", "");
             return true;
         }
     }
     $this->assign("content", $content);
     //分页处理结束
     $filename = $file;
     //生成路径
     $this->buildHtml($filename, SITE_PATH . "/", $template);
     return true;
 }
コード例 #4
0
 public function shows()
 {
     $catid = I('get.catid', 0, 'intval');
     $id = I('get.id', 0, 'intval');
     $page = intval($_GET[C("VAR_PAGE")]);
     $page = max($page, 1);
     //获取当前栏目数据
     $category = getCategory($catid);
     if (empty($category)) {
         send_http_status(404);
         exit;
     }
     //反序列化栏目配置
     $category['setting'] = $category['setting'];
     //检查是否禁止访问动态页
     if ($category['setting']['showoffmoving']) {
         send_http_status(404);
         exit;
     }
     //模型ID
     $this->modelid = $category['modelid'];
     $this->db = ContentModel::getInstance($this->modelid);
     $data = $this->db->relation(true)->where(array("id" => $id, 'status' => 99))->find();
     if (empty($data)) {
         send_http_status(404);
         exit;
     }
     $this->db->dataMerger($data);
     //分页方式
     if (isset($data['paginationtype'])) {
         //分页方式
         $paginationtype = $data['paginationtype'];
         //自动分页字符数
         $maxcharperpage = (int) $data['maxcharperpage'];
     } else {
         //默认不分页
         $paginationtype = 0;
     }
     //载入字段数据处理类
     if (false == require_cache(RUNTIME_PATH . 'content_output.class.php')) {
         D("Category")->category_cache();
         D("Content_cache")->model_content_cache();
         require RUNTIME_PATH . 'content_output.class.php';
     }
     $content_output = new content_output($this->modelid);
     //获取字段类型处理以后的数据
     $output_data = $content_output->get($data);
     $output_data['id'] = $id;
     $output_data['title'] = strip_tags($output_data['title']);
     //SEO
     $seo_keywords = '';
     if (!empty($output_data['keywords'])) {
         $seo_keywords = implode(',', $output_data['keywords']);
     }
     $seo = seo($catid, $output_data['title'], $output_data['description'], $seo_keywords);
     //内容页模板
     $template = $output_data['template'] ? $output_data['template'] : $category['setting']['show_template'];
     //去除模板文件后缀
     $newstempid = explode(".", $template);
     $template = $newstempid[0];
     unset($newstempid);
     //分页处理
     $pages = $titles = '';
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] == 1) {
         //自动分页
         if ($maxcharperpage < 10) {
             $maxcharperpage = 500;
         }
         //按字数分割成几页处理开始
         import('Contentpage', APP_PATH . C("APP_GROUP_PATH") . '/Contents/ORG');
         $contentpage = new Contentpage();
         $contentfy = $contentpage->get_data($output_data['content'], $maxcharperpage);
         //自动分页有时会造成返回空,如果返回空,就不分页了
         if (!empty($contentfy)) {
             $output_data['content'] = $contentfy;
         }
     }
     //分配解析后的文章数据到模板
     $this->assign($output_data);
     //seo分配到模板
     $this->assign("SEO", $seo);
     //栏目ID
     $this->assign("catid", $catid);
     //分页生成处理
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] > 0) {
         $urlrules = $this->url->show($data, $page);
         //手动分页
         $CONTENT_POS = strpos($output_data['content'], '[page]');
         if ($CONTENT_POS !== false) {
             $contents = array_filter(explode('[page]', $output_data['content']));
             $pagenumber = count($contents);
             $pages = page($pagenumber, 1, $page, array('isrule' => true, 'rule' => $urlrules['page']))->show("default");
             //判断[page]出现的位置是否在第一位
             if ($CONTENT_POS < 7) {
                 $content = $contents[$page];
             } else {
                 $content = $contents[$page - 1];
             }
             //分页
             $this->assign("pages", $pages);
             $this->assign("content", $content);
         }
     } else {
         $this->assign("content", $output_data['content']);
     }
     $this->display("Show:" . $template);
 }