Example #1
0
function m__list()
{
    global $dbm, $c;
    if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
        die('{"code":"200","msg":"ID号出错"}');
    }
    if (!isset($_GET['p']) || !is_numeric($_GET['p']) || $_GET['p'] < 1) {
        $_GET['p'] = 1;
    }
    $p = intval($_GET['p']);
    $id = intval($_GET['id']);
    echo get_comments($id, $p) . getcomment_form($id);
    die;
}
Example #2
0
 /**
  * 取文档
  *
  * @param  $id 文档ID
  * @param  $no_cache 1=强制读取最新数据
  * @param  $info_state
  * @param  $is_page 是否正文分页 1=是 0=不需要
  */
 public function get_content($id, $no_cache = 0, $info_state = false, $is_page = 1, $is_admin = 0)
 {
     $content = array();
     if (!is_numeric($id)) {
         return $content;
     }
     $sql = "select * from " . TB_PREFIX . "info_list where info_id='{$id}' ";
     if ($info_state) {
         $sql .= " and info_state=0 ";
     }
     $sql .= " limit 1";
     // 缓存开启,获取缓存内容
     if ($no_cache == 1) {
         $rs = $this->dbm->query($sql);
         //print_r($no_cache.'---111'.$rs);die();
     } else {
         if (defined('CACHE_TIME') && CACHE_TIME != '' && CACHE_TIME != 0) {
             $cache_file = md5($sql);
             $data_path = SITE_PATH . CACHE_NAME . '/content/' . substr($cache_file, 0, 2);
             //print_r($data_path);die();
             $rs = helper::file_cache($cache_file, '', CACHE_TIME, $data_path);
             if ($rs == 'timeout') {
                 $rs = $this->dbm->query($sql);
                 $rs = helper::file_cache($cache_file, $rs, CACHE_TIME, $data_path);
             }
         } else {
             // print_r($data_path);die();
             $rs = $this->dbm->query($sql);
         }
     }
     //print_r($rs);
     if (count($rs['list']) > 0) {
         $content = $rs['list'][0];
         if ($is_admin == 1) {
             $content['info_body'] = preg_replace('~&#34;~', '', htmlspecialchars_decode($content['info_body']));
             $content['info_body'] = preg_replace('~<p([^>]*)>\\n~', '<p$1>', $content['info_body']);
         }
         if (isset($_GET['preview']) && $_GET['preview'] == '1') {
             //预览方式不解码
         } else {
             $content['info_body'] = htmlspecialchars_decode($content['info_body']);
         }
         if (!get_magic_quotes_gpc()) {
             $content['info_body'] = stripslashes($content['info_body']);
         }
         $content['info_title_original'] = $content['info_title'];
         $content['publish_time_str'] = date('Y-m-d H:i:s', $content['publish_time']);
         // if (strlen($content['info_stitle']) <= 0) $content['info_stitle'] = $content['info_title']; // SEO别名
         if (isset($content['info_img'])) {
             $content['thumb'] = $this->thumb_url($content['info_img']);
             // 缩略图
         }
         // 资讯简介
         if ($content['info_desc'] == '') {
             $content['info_desc'] = helper::utf8_substr(preg_replace('~(<style[^>]*>[\\w\\W]*?</style>)|(<[^>]*>)|(\\r)|(\\n)|(\\t)~', '', $content['info_body']), 0, 220);
         }
         $content['resource'] = $this->get_resource($id);
         // 取外部资源
         //查询关系表中的关键字ID
         $sql = "select keyword_id from " . TB_PREFIX . "keyword_relation where info_id= '{$id}'";
         $r = $this->dbm->query($sql);
         $ids = array();
         for ($i = 0; $i < count($r['list']); $i++) {
             $ids[] = $r['list'][$i]['keyword_id'];
         }
         if (is_array($ids) && !empty($ids)) {
             $content['keword_ids'] = implode(',', $ids) . ',';
         }
         $sql = "select * from " . TB_PREFIX . "keyword where keyword_id in (" . implode(',', $ids) . ")";
         $ret = $this->dbm->query($sql);
         $content['tags_html'] = '';
         if (count($ret['list']) > 0) {
             $content['tags'] = array();
             foreach ($ret['list'] as $k => $v) {
                 $content['tags'][] = $v['keyword'];
                 $content['tags_html'] .= '<a href="' . $this->url->encode('tag_index', array('host' => SITE_PATH, 'extid' => $this->categories[$content['last_cate_id']]['extern_id'], 'id' => $v['keyword_id'])) . '" target="_blank">' . $v['keyword'] . '</a>&nbsp;&nbsp;';
             }
         }
         //如果文章图片为空,把资源的第一个图片放到文章图片上
         if (empty($content['info_img']) && count($content['resource']) > 0) {
             $content['info_img'] = isset($content['resource'][0]['resource_url']) ? $content['resource'][0]['resource_url'] : '';
         }
         // 取上下篇
         $rs_next = $this->get_list(array('type' => 0, 'cate_id' => $content['last_cate_id'], 'where' => " info_id>" . $id . " and info_url=''", 'pagesize' => 1, 'order' => 'order by info_id asc', 'no_cache' => $no_cache));
         $rs_prev = $this->get_list(array('type' => 0, 'cate_id' => $content['last_cate_id'], 'where' => " info_id<" . $id . " and info_url=''", 'pagesize' => 1, 'order' => 'order by info_id desc', 'no_cache' => $no_cache));
         $content['next']['surl'] = '';
         $content['next']['info_title'] = '';
         if (count($rs_next['list']) > 0) {
             $content['next']['surl'] = $rs_next['list'][0]['surl'];
             $content['next']['info_title'] = $rs_next['list'][0]['info_stitle'] == '' ? $rs_next['list'][0]['info_title'] : $rs_next['list'][0]['info_stitle'];
         }
         $content['prev']['surl'] = '';
         $content['prev']['info_title'] = '';
         if (count($rs_prev['list']) > 0) {
             $content['prev']['surl'] = $rs_prev['list'][0]['surl'];
             $content['prev']['info_title'] = $rs_prev['list'][0]['info_stitle'] == '' ? $rs_prev['list'][0]['info_title'] : $rs_prev['list'][0]['info_stitle'];
         }
         $surl_domain = $this->bind_domain($content['last_cate_id']);
         $content['surl'] = ($surl_domain == '' ? $this->url_recheck() : $surl_domain) . $this->url->encode('content_info', array('host' => SITE_PATH, 'id' => $id));
         // 是否生成正文内链
         if (CONTENT_NLINK == '1') {
             $content['info_body'] = $this->nlink($content['info_body']);
         }
         //资讯正文手工分页
         if ($is_page == 1) {
             $pattern = '~<div style="page-break-after: always;">(.*)</div>~isU';
             if (preg_match($pattern, $content['info_body'], $arr)) {
                 $content['info_body'] = helper::escape_stripslashes($content['info_body']);
                 $content_arr = preg_split($pattern, $content['info_body']);
                 $_html = '<div class="pagebar" style="margin:10px 0 0 0;padding:0;">';
                 $content_total = count($content_arr);
                 $pageno = isset($_GET['p']) ? intval($_GET['p']) : 1;
                 if (is_numeric($pageno) && $pageno < 1) {
                     $pageno = 1;
                 }
                 if ($pageno > $content_total) {
                     $pageno = $content_total;
                 }
                 for ($i = 1; $i <= $content_total; $i++) {
                     if ($pageno == $i) {
                         $_html .= '<span class="now_class">' . $i . '</span>';
                     } else {
                         //$_nurl = helper :: url_replace($i, 'pageno');
                         $_nurl = $this->url->encode('content_info_page', array('host' => SITE_PATH, 'id' => $id, 'p' => $i));
                         //$_nurl = $id.'_'.$i.'.html';
                         $_html .= '<a href="' . $_nurl . '">' . $i . '</a>';
                     }
                 }
                 $_html .= '</div><br /><br />';
                 $content['info_body'] = $content_arr[$pageno - 1] . $_html;
             }
         }
         // 取扩展表
         //$extern = $this -> get_extern_by_cate_id($content['last_cate_id']);
         /*$content['extern'] = array();
           if ($extern['extern_name'] != '') {
               $content['extern']  = $this -> get_extern($extern['extern_name'],$id);
           }*/
     }
     $p = isset($_GET['p']) ? $_GET['p'] : 1;
     // 取评论代码
     if (defined('COMMENT_CODE') && COMMENT_CODE != '') {
         $content['comment_code'] = COMMENT_CODE;
     } else {
         $content['comment_code'] = '';
         if (file_exists(dirname(__FILE__) . "/../plugins/gov.comment/comment_html.php")) {
             require_once dirname(__FILE__) . "/../plugins/gov.comment/comment_html.php";
             $content['comment_code'] = '<div id="comment_list">' . get_comments($id, $p) . getcomment_form($id, 'comment') . '</div>';
         }
     }
     return $content;
 }