コード例 #1
0
 /**
  * 模板路径
  * @param type $templateFile
  * @return boolean|string 
  */
 public function parseTemplateFile($templateFile = '')
 {
     $status = parseTemplateFile($templateFile);
     if ($status == false) {
         echo str_replace(SITE_PATH, "", $templateFile) . "模板不存在!";
         exit;
     }
     return $status;
 }
コード例 #2
0
 public function index()
 {
     $page = isset($_GET[C("VAR_PAGE")]) ? $_GET[C("VAR_PAGE")] : 1;
     $page = max($page, 1);
     //模板处理
     $tp = explode(".", self::$Cache['Config']['indextp']);
     $template = parseTemplateFile("Index/{$tp[0]}");
     $SEO = seo('', '', self::$Cache['Config']['siteinfo'], self::$Cache['Config']['sitekeywords']);
     //生成路径
     $urls = $this->Url->index($page);
     $GLOBALS['URLRULE'] = $urls['page'];
     //seo分配到模板
     $this->assign("SEO", $SEO);
     //把分页分配到模板
     $this->assign(C("VAR_PAGE"), $page);
     $this->display("Index:" . $tp[0]);
 }
コード例 #3
0
ファイル: Html.class.php プロジェクト: sandom123/king400
 /**
  * 生成自定义列表页面
  * @param type $data
  * @return boolean
  */
 public function createListHtml($data = '')
 {
     if (empty($data)) {
         if (!empty($this->data)) {
             $data = $this->data;
             // 重置数据
             $this->data = array();
         } else {
             $this->error = '没有数据';
             return false;
         }
     } else {
         if (is_integer($data)) {
             $data = D('Template/Customlist')->where(array('id' => $data))->find();
             if (empty($data)) {
                 $this->error = '没有数据';
                 return false;
             }
         }
     }
     $model = D('Template/Customlist');
     //初始化一些模板分配变量
     $this->assignInitialize();
     //计算总数
     $countArray = $model->query($data['totalsql']);
     if (!empty($countArray)) {
         $count = $countArray[0]['total'];
     } else {
         return false;
     }
     //seo分配到模板
     $seo = seo(0, $data['title'], $data['description'], $data['keywords']);
     $this->assign("SEO", $seo);
     //分页总数
     $paging = ceil($count / $data['lencord']);
     $pagehao = 1;
     do {
         //生成路径
         $customlistUrl = $this->Url->createListUrl($data, $pagehao);
         if ($customlistUrl == false) {
             return false;
         }
         //取得URL规则
         $urls = $customlistUrl['page'];
         $page = page($count, $data['lencord'], $pagehao, array('isrule' => true, 'rule' => $urls));
         $listData = $model->query($data['listsql'] . " LIMIT {$page->firstRow},{$page->listRows}");
         //把分页分配到模板
         $this->assign(C("VAR_PAGE"), $pagehao);
         $this->assign('listData', $listData);
         $this->assign("pages", $page->show());
         if (empty($data['listpath'])) {
             //生成路径
             $htmlpath = SITE_PATH . $customlistUrl["path"];
             // 页面缓存
             ob_start();
             ob_implicit_flush(0);
             //渲染模板
             parent::show($data['template']);
             // 获取并清空缓存
             $content = ob_get_clean();
             //检查目录是否存在
             if (!is_dir(dirname($htmlpath))) {
                 // 如果静态目录不存在 则创建
                 mkdir(dirname($htmlpath), 0777, true);
             }
             //写入文件
             if (false === file_put_contents($htmlpath, $content)) {
                 throw_exception("自定义列表生成失败:" . $htmlpath);
             }
         } else {
             //去除完后缀的模板
             $template = TEMPLATE_PATH . (empty(self::$Cache["Config"]['theme']) ? "Default" : self::$Cache["Config"]['theme']) . "/Content/List/{$data['listpath']}";
             //模板检测
             $template = parseTemplateFile($template);
             //生成
             $this->buildHtml($customlistUrl['path'], SITE_PATH, $template);
         }
         $pagehao++;
     } while ($pagehao <= $paging);
     return true;
 }
コード例 #4
0
ファイル: Base.class.php プロジェクト: sandom123/king400
 /**
  * 模板显示 调用内置的模板引擎显示方法,
  * @access protected
  * @param string $templateFile 指定要调用的模板文件
  * 默认为空 由系统自动定位模板文件
  * @param string $charset 输出编码
  * @param string $contentType 输出类型
  * @param string $content 输出内容
  * @param string $prefix 模板缓存前缀
  * @return void
  */
 protected function display($templateFile = '', $charset = '', $contentType = '', $content = '', $prefix = '')
 {
     $this->view->display(parseTemplateFile($templateFile), $charset, $contentType, $content, $prefix);
 }
コード例 #5
0
ファイル: Html.class.php プロジェクト: NeilFee/vipxinbaigo
 /**
  * 更新首页
  * @param $page 页码,默认1
  */
 public function index($page = 1)
 {
     $page = max($page, 1);
     if (CONFIG_GENERATE == '0' || CONFIG_GENERATE < 1) {
         return false;
     }
     //初始化一些模板分配变量
     $this->assignInitialize();
     //模板处理
     $tp = explode(".", CONFIG_INDEXTP);
     $template = parseTemplateFile("Index:" . $tp[0]);
     if ($template == false && $tp[0] != "index") {
         //模板不存在,重新使用默认模板
         $template = "index";
         $template = parseTemplateFile("Index:" . $template);
         if ($template == false) {
             $this->error("首页模板不存在!");
         }
     } else {
         if ($template == false) {
             $this->error("首页模板不存在!");
         }
     }
     $SEO = seo("", "", AppframeAction::$Cache['Config']['siteinfo'], AppframeAction::$Cache['Config']['sitekeywords']);
     unset($GLOBALS["Total_Pages"]);
     $j = 1;
     //分页生成
     do {
         //把分页分配到模板
         $this->assign(C("VAR_PAGE"), $page);
         //seo分配到模板
         $this->assign("SEO", $SEO);
         //生成路径
         $urls = $this->url->index($page);
         $GLOBALS['URLRULE'] = $urls['page'];
         $filename = $urls['path'];
         //判断是否生成和入口文件同名,如果是,不生成!
         if ($filename != "/index.php") {
             $this->buildHtml($filename, SITE_PATH . "/", $template);
         }
         //如果GET有total_number参数则直接使用GET的,如果没有则根据$GLOBALS["Total_Pages"]获取分页总数
         $total_number = isset($_GET['total_number']) ? (int) $_GET['total_number'] : $GLOBALS["Total_Pages"];
         $page++;
         $j++;
     } while ($j <= $total_number);
 }
コード例 #6
0
 /**
  * 更新首页
  * @param $page 页码,默认1
  */
 public function index($page = 1)
 {
     $page = max($page, 1);
     if (CONFIG_GENERATE == '0' || CONFIG_GENERATE < 1) {
         return false;
     }
     //模板处理
     $tp = explode(".", CONFIG_INDEXTP);
     $template = parseTemplateFile("Index:" . $tp[0]);
     if ($template == false) {
         $this->error("首页模板不存在!");
     }
     //URL规则
     $urlrules = $this->url->index(0, "URLRULE");
     $urlrules = implode("~", $urlrules);
     define('URLRULE', $urlrules);
     $SEO = seo();
     $j = 1;
     //分页生成
     do {
         //生成路径
         $urls = $this->url->index($page);
         $filename = $urls[1];
         //把分页分配到模板
         $this->assign(C("VAR_PAGE"), $page);
         //seo分配到模板
         $this->assign("SEO", $SEO);
         //判断是否生成和入口文件同名,如果是,不生成!
         if ($filename != "/index.php") {
             $this->buildHtml($filename, SITE_PATH . "/", $template);
         }
         $page++;
         $j++;
         //如果GET有total_number参数则直接使用GET的,如果没有则根据常量 PAGES获取分页总数
         $total_number = isset($total_number) ? $total_number : PAGES;
     } while ($j <= $total_number);
 }
コード例 #7
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);
 }
コード例 #8
0
 public function public_preview()
 {
     $id = I('get.id', 0, 'intval');
     $catid = I('get.catid', 0, 'intval');
     $page = intval($_GET[C("VAR_PAGE")]);
     $page = max($page, 1);
     //获取当前栏目数据
     $category = getCategory($catid);
     if (empty($category)) {
         $this->error('该栏目不存在!');
     }
     //反序列化栏目配置
     $category['setting'] = $category['setting'];
     //模型ID
     $modelid = $category['modelid'];
     $data = ContentModel::getInstance($modelid)->relation(true)->where(array("id" => $id))->find();
     if (empty($data)) {
         $this->error('该信息不存在!');
     }
     ContentModel::getInstance($modelid)->dataMerger($data);
     //分页方式
     if (isset($data['paginationtype'])) {
         //分页方式
         $paginationtype = $data['paginationtype'];
         //自动分页字符数
         $maxcharperpage = (int) $data['maxcharperpage'];
     } else {
         //默认不分页
         $paginationtype = 0;
     }
     $content_output = new \content_output($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];
     //分页处理
     $pages = $titles = '';
     //分配解析后的文章数据到模板
     $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);
             $pages = page($pagenumber, 1, $page, array('isrule' => true, 'rule' => array('index' => 'index.php?m=Content&a=public_preview&catid=' . $catid . '&id=' . $id, 'list' => 'index.php?m=Content&a=public_preview&catid=' . $catid . '&id=' . $id . '&page={$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(parseTemplateFile("Show/{$template}"));
 }