/**
  * 内容详细页
  */
 public function showAction()
 {
     $id = (int) $this->get('id');
     $page = $this->get('page') ? (int) $this->get('page') : 1;
     $data = $this->content->find($id);
     //查询当前文档数据
     $model = $this->get_model();
     //获取模型缓存
     $catid = $data['catid'];
     //赋值栏目id
     $cat = $this->cats[$catid];
     //获取当前文档的栏目数据
     if (empty($data) || $data['status'] == 0) {
         //判断数据是否存在或文档状态是否通过
         header('HTTP/1.1 404 Not Found');
         $this->msg(lang('con-1', array('1' => $id)));
     } elseif (!isset($model[$data['modelid']]) || empty($model[$data['modelid']])) {
         //判断模型是否存在
         header('HTTP/1.1 404 Not Found');
         $this->msg(lang('con-3', array('1' => $id)));
     } elseif (empty($cat)) {
         //判断栏目是否存在
         header('HTTP/1.1 404 Not Found');
         $this->msg(lang('con-0', array('1' => $catdir && empty($catid) ? $catdir : $catid)));
     }
     $table = $model[$data['modelid']]['tablename'];
     $_data = $this->db->where('id', $id)->get($table)->row_array();
     //附表数据查询
     $data = array_merge($data, $_data);
     //合并主表和附表
     $data = $this->getFieldData($model[$cat['modelid']], $data);
     //格式化部分数据类型
     $data = $this->get_content_page($data, 1, $page);
     //内容分页和子标题
     $data['content'] = relatedlink($data['content']);
     //关联链接
     $prev_page = $this->db->where("catid = {$catid} AND id < {$id} AND status = 1")->order_by('id DESC')->get('content_' . SITE_ID)->row_array();
     //上一篇文章
     $next_page = $this->db->where("catid = {$catid} AND id > {$id} AND status = 1")->order_by('id DESC')->get('content_' . SITE_ID)->row_array();
     //下一篇文章
     $this->view->assign(array('cat' => $cat, 'page' => $page, 'pageurl' => urlencode(getUrl($data, '{page}')), 'prev_page' => $prev_page, 'next_page' => $next_page));
     $this->view->assign($data);
     $this->view->assign(showSeo($data, $page));
     $this->view->display(substr($cat['showtpl'], 0, -5));
 }
Example #2
0
 /**
  * 生成内容html
  */
 protected function createShow($data, $page = 1)
 {
     if (empty($data)) {
         return false;
     }
     ob_start();
     $id = $data['id'];
     $catid = $data['catid'];
     $cat = $this->cats[$catid];
     if ($cat['setting']['url']['use'] == 0 || $cat['setting']['url']['tohtml'] == 0 || $cat['setting']['url']['show'] == '') {
         return false;
     }
     $table = $this->model($cat['tablename']);
     $_data = $table->find($id);
     $data = array_merge($data, $_data);
     $model = $this->get_model();
     $data = $this->getFieldData($model[$cat['modelid']], $data);
     $data = $this->get_content_page($data, 1, $page);
     $url = substr($this->getUrl($data, $page), strlen(Controller::get_base_url()));
     //去掉域名部分
     if (substr($url, -5) != '.html') {
         $file = 'index.html';
         //文件名
         $dir = $url;
         //目录
     } else {
         $file = basename($url);
         $dir = str_replace($file, '', $url);
     }
     $this->mkdirs($dir);
     $dir = substr($dir, -1) == '/' ? substr($dir, 0, -1) : $dir;
     $htmlfile = $dir ? $dir . '/' . $file : $file;
     if ($data['status'] == 0) {
         @unlink($htmlfile);
         if (isset($pagelist) && is_array($pagelist)) {
             foreach ($pagelist as $p => $u) {
                 $file = str_replace(Controller::get_base_url(), '', $u);
                 @unlink($file);
             }
         }
         return false;
     }
     $prev_page = $this->content->getOne("`catid`={$catid} AND `id`<{$id} AND `status`<>0 ORDER BY `id` DESC", null, 'title,url,hits');
     $next_page = $this->content->getOne("`catid`={$catid} AND `id`>{$id} AND `status`<>0", null, 'title,url,hits');
     $data['content'] = relatedlink($data['content']);
     $this->view->assign(array('cat' => $cat, 'cats' => $this->cats, 'page' => $page, 'pageurl' => urlencode(getUrl($data, '{page}')), 'prev_page' => $prev_page, 'next_page' => $next_page));
     $this->view->assign($data);
     $this->view->assign(showSeo($data, $page));
     if ($this->namespace == 'admin') {
         $this->view->setTheme(true);
     }
     $this->view->display(substr($cat['showtpl'], 0, -5));
     if ($this->namespace == 'admin') {
         $this->view->setTheme(false);
     }
     if (!file_put_contents($htmlfile, ob_get_clean(), LOCK_EX)) {
         $this->adminMsg(lang('a-com-11', array('1' => $htmlfile)));
     }
     $htmlfiles = $this->cache->get('html_files');
     $htmlfiles[] = $htmlfile;
     $this->cache->set('html_files', $htmlfiles);
     if (isset($_data['content']) && strpos($_data['content'], '{-page-}') !== false) {
         $content = explode('{-page-}', $_data['content']);
         $pageid = $page <= 0 ? 1 : $page;
         $nextpage = $pageid + 1;
         if ($nextpage <= count($content)) {
             $this->createShow($data, $nextpage);
         }
     }
     return true;
 }
Example #3
0
 /**
  * 生成栏目html
  */
 protected function createCat($cat, $page = 1)
 {
     if ($cat['typeid'] == 3) {
         return false;
     }
     if ($cat['setting']['url']['use'] == 0 || $cat['setting']['url']['tohtml'] == 0 || $cat['setting']['url']['list'] == '') {
         return false;
     }
     $url = substr($this->getCaturl($cat, $page), strlen(self::get_base_url()));
     //去掉域名部分
     if (substr($url, -5) != '.html') {
         $file = 'index.html';
         //文件名
         $dir = $url;
         //目录
     } else {
         $file = basename($url);
         $dir = str_replace($file, '', $url);
     }
     $this->mkdirs($dir);
     $dir = substr($dir, -1) == '/' ? substr($dir, 0, -1) : $dir;
     $htmlfile = $dir ? $dir . '/' . $file : $file;
     ob_start();
     $catid = $cat['catid'];
     $cat = $this->cats[$catid];
     if (empty($cat)) {
         return;
     }
     $this->view->setTheme(true);
     if ($cat['typeid'] == 1) {
         //内部栏目
         $this->view->assign($cat);
         $this->view->assign(listSeo($cat, $page));
         $this->view->assign(array('page' => $page, 'catid' => $catid, 'pageurl' => urlencode($this->getCaturl($cat, '{page}'))));
         $this->view->display(substr($cat['child'] == 1 ? $cat['categorytpl'] : $cat['listtpl'], 0, -5));
     } elseif ($cat['typeid'] == 2) {
         //单网页
         $cat = $this->get_content_page($cat, 0, $page);
         $cat['content'] = relatedlink($cat['content']);
         $this->view->assign($cat);
         $this->view->assign(listSeo($cat, $page));
         $this->view->display(substr($cat['showtpl'], 0, -5));
     }
     $this->view->setTheme(false);
     if (!file_put_contents($htmlfile, ob_get_clean(), LOCK_EX)) {
         $this->adminMsg(lang('a-com-11', array('1' => $htmlfile)));
     }
     $htmlfiles = $this->cache->get('html_files');
     $htmlfiles[] = $htmlfile;
     if (empty($page) || $page == 1) {
         $onefile = str_replace('{page}', 1, substr($this->getCaturl($cat, '{page}'), strlen(self::get_base_url())));
         @copy($htmlfile, $onefile);
         $htmlfiles[] = $onefile;
     }
     $this->cache->set('html_files', $htmlfiles);
     if (strpos($cat['content'], '{-page-}') !== false) {
         $content = explode('{-page-}', $cat['content']);
         $pageid = count($content) >= $page ? $page - 1 : count($content) - 1;
         $page_id = 1;
         $pagelist = array();
         $cat['content'] = $content[$pageid];
         foreach ($content as $t) {
             $pagelist[$page_id] = getCaturl($cat, $page_id);
             $page_id++;
         }
         if (isset($pagelist[$page + 1])) {
             $this->createCat($cat, $page + 1);
         }
     }
     return true;
 }
Example #4
0
 /**
  * 内容详细页
  */
 public function showAction()
 {
     $id = (int) $this->get('id');
     $page = $this->get('page') ? (int) $this->get('page') : 1;
     $data = $this->content->where('status=>1')->find($id);
     //查询当前文档数据
     $model = $this->get_model();
     //获取模型缓存
     $catid = $data['catid'];
     //赋值栏目id
     $cat = $this->cats[$catid];
     //获取当前文档的栏目数据
     if (empty($data) || $data['status'] == 0) {
         //判断数据是否存在或文档状态是否通过
         header('HTTP/1.1 404 Not Found');
         $this->msg(lang('con-1', array('1' => $id)));
     } elseif (!isset($model[$data['modelid']]) || empty($model[$data['modelid']])) {
         //判断模型是否存在
         header('HTTP/1.1 404 Not Found');
         $this->msg(lang('con-3', array('1' => $id)));
     } elseif (empty($cat)) {
         //判断栏目是否存在
         header('HTTP/1.1 404 Not Found');
         $this->msg(lang('con-0', array('1' => $catdir && empty($catid) ? $catdir : $catid)));
     } elseif ($data['status'] != 1) {
         header('HTTP/1.1 404 Not Found');
         $this->msg(lang('con-3', array('1' => $id)));
     }
     $table = $model[$data['modelid']]['tablename'];
     //Found "content_1_news"
     $_data = $this->db->where('id', $id)->get($table)->row_array();
     //附表数据查询
     $data = array_merge($data, $_data);
     //合并主表和附表
     $field = $model[$cat['modelid']]['fields']['data'];
     if ($field) {
         foreach ($field as $t) {
             if ($t['formtype'] == 'wurl') {
                 if (isset($data[$t['field']])) {
                     // 跳转外链
                     $this->redirect($data[$t['field']]);
                     exit;
                 }
             }
         }
     }
     $data = $this->getFieldData($model[$cat['modelid']], $data);
     //格式化部分数据类型
     $data = $this->get_content_page($data, 1, $page);
     //内容分页和子标题
     $data['content'] = relatedlink($data['content']);
     //关联链接
     $mainTable = 'content_' . SITE_ID;
     //print_R( $data);exit;
     //print_r($data);exit;
     if (isset($data['jiamengmoban']) && !empty($data['jiamengmoban'])) {
         $proxyVal = $data['jiamengmoban'];
         $values = explode("#", $proxyVal);
         $domain = $values[0];
         $view = $values[1];
         if (!strstr($_SERVER['HTTP_HOST'], $domain)) {
             header('HTTP/1.1 404 Not Found');
             $this->msg(lang('con-1', array('1' => $id)));
         }
     }
     // 代理模板
     if (!$this->session->is_set($_SERVER['HTTP_HOST'] . '_' . SITE_ID)) {
         if (strstr($_SERVER['HTTP_HOST'], $domain)) {
             define('PROXY_THEME_DIR', $view . '/');
             $this->session->set($_SERVER['HTTP_HOST'] . '_' . SITE_ID, $view . '/');
             $this->session->set($_SERVER['HTTP_HOST'] . '_' . SITE_ID . '_domain', $domain);
         }
     }
     //var_dump($this->session->is_set($_SERVER['HTTP_HOST'].'_'.SITE_ID));
     //var_dump($this->session->get($_SERVER['HTTP_HOST'].'_'.SITE_ID));
     //print_R($this->session);
     //echo PROXY_THEME_DIR;
     //exit;
     //if ($this->session->is_set('user_id') && $this->session->get('user_id')) return true;
     /*
     print_r($cat);
     print_r($data);
     print_r(substr($cat['showtpl'], 0, -5));exit;
     */
     if (defined('PROXY_DOMAIN') && isset($data['jiamengmoban'])) {
         $prev_page = $this->db->join($table, $table . '.id = ' . $mainTable . '.id')->where($mainTable . ".catid = {$catid} AND " . $this->db->dbprefix . "content_" . SITE_ID . ".id < {$id} AND status = 1 AND jiamengmoban like '" . PROXY_DOMAIN . "%'")->order_by($mainTable . '.id DESC')->get($mainTable)->row_array();
     } else {
         $prev_page = $this->db->join($table, $table . '.id = ' . $mainTable . '.id')->where($mainTable . ".catid = {$catid} AND " . $this->db->dbprefix . "content_" . SITE_ID . ".id < {$id} AND status = 1")->order_by($mainTable . '.id DESC')->get($mainTable)->row_array();
     }
     //print_r($prev_page);exit;
     if (defined('PROXY_DOMAIN') && isset($data['jiamengmoban'])) {
         $next_page = $this->db->join($table, $table . '.id = ' . $mainTable . '.id')->where($mainTable . ".catid = {$catid} AND " . $this->db->dbprefix . "content_" . SITE_ID . ".id > {$id} AND status = 1 AND jiamengmoban like '" . PROXY_DOMAIN . "%'")->order_by($mainTable . '.id DESC')->get($mainTable)->row_array();
     } else {
         $next_page = $this->db->join($table, $table . '.id = ' . $mainTable . '.id')->where($mainTable . ".catid = {$catid} AND " . $this->db->dbprefix . "content_" . SITE_ID . ".id > {$id} AND status = 1")->order_by($mainTable . '.id DESC')->get($mainTable)->row_array();
     }
     $config = self::load_config('config');
     $commentCfg = $config['SITE_COMMENT'];
     $this->view->assign(array('commentCfg' => $commentCfg, 'cat' => $cat, 'page' => $page, 'pageurl' => urlencode(getUrl($data, '{page}')), 'prev_page' => $prev_page, 'next_page' => $next_page));
     $this->view->assign($data);
     $this->view->assign(showSeo($data, $page));
     $this->view->display(substr($cat['showtpl'], 0, -5));
 }