Example #1
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('~"~', '', 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;
 }
Example #2
0
/**
 * 删除选中的数据
 * 支持单个删除 根据post数据来获取需要删除的数据的信息
 */
function m__del()
{
    global $l_obj;
    //判断操作权限
    check_level("E08");
    global $dbm;
    //print_r($_POST);
    foreach ($_POST as $k => $v) {
        if (!is_array($v)) {
            $_POST[$k] = helper::escape_stripslashes($v);
        }
    }
    //判断是否是单张图片的删除
    if (isset($_POST['info']) && !is_array($_POST['info'])) {
        $_POST['resource_info'] = array();
        $_POST['resource_info'][] = json_decode($_POST['info'], true);
    }
    //去反斜杠
    $arr = $_POST['resource_info'];
    //循环删除
    foreach ($arr as $v) {
        //拼接图片的路径
        $img_path = str_replace('\\', '/', dirname(__FILE__)) . '/..' . $v['resource_url'];
        //file_put_contents('log.php',$img_path);exit;
        //删除图片
        @unlink($img_path);
        //删除图片缩略图
        $x = strripos($img_path, '/');
        $thumb_img = substr($img_path, 0, $x + 1) . "thumb_" . substr($img_path, $x + 1);
        @unlink($thumb_img);
        //在删除网站配置的图片时会因为它们没有缩略图而报Warning
        //尝试删除文件所在目录,若为空,且有权限则删除。
        @rmdir(dirname($thumb_img));
        //删除图片资源记录
        $where = " id = '" . $v['resource_id'] . "'";
        if ($v['resource_id'] == 'undefined') {
            //是网站配置的图片
            $where = " resource_url like '%" . $v['resource_url'] . "%'";
            //将对应网站配置设置为空
            $config = $_SERVER['DOCUMENT_ROOT'] . SITE_PATH . '/core/config.php';
            $cf = file_get_contents($config);
            set_config($v['id_zhi'], '', $cf);
            file_put_contents($config, $cf);
        }
        $res = $dbm->single_del(TB_PREFIX . "resource_list", $where);
        if (!empty($res['error'])) {
            continue;
        }
        //print_r($v);
        //删除图片资源关联的数据 若是分类则不删除分类数据
        if ($v['table_name'] != 'undefined' && $v['table_name'] != 'category') {
            //图片关联到了其它表中的数据
            $where = " " . $v['id_name'] . " = '" . $v['id_zhi'] . "'";
            if ($v['id_name'] == 'area_html') {
                $where = " " . $v['id_name'] . " like '%" . $v['id_zhi'] . "%'";
            }
            $res = $dbm->single_del(TB_PREFIX . $v['table_name'], $where);
            if (!empty($res['error'])) {
                continue;
            }
        }
    }
    $l_obj->insert("删除资源成功");
    die('{"code":"0","msg":"删除成功"}');
}
Example #3
0
function m__cate_order()
{
    global $dbm, $c;
    //判断操作权限
    check_level("C0403");
    $_POST['params'] = helper::escape_stripslashes($_POST['params'], 1);
    $ids = json_decode($_POST['params'], 1);
    foreach ($ids as $a) {
        $dbm->single_update(TB_PREFIX . "category", array('corder' => $a['val']), "cate_id='" . $a['id'] . "'");
    }
    $c->update_cate();
    logs("修改分类排序成功");
    die('{"code":"0","msg":"分类排序修改成功"}');
}
Example #4
0
function m__save_attr()
{
    global $dbm;
    //判断操作权限
    check_level("E0403");
    $area_id = isset($_GET['area_id']) ? intval($_GET['area_id']) : 0;
    if ($area_id == 0) {
        die('{"code":1,"msg":"广告位不存在"}');
    }
    $a = $dbm->query("select * from " . TB_PREFIX . "recommend_area where area_id='{$area_id}'");
    if (count($a['list']) < 1) {
        die('{"code":1,"msg":"广告位不存在"}');
    }
    $area = $a['list'][0];
    //模型
    $attr = unserialize($area['area_html']);
    // 初始化数据
    foreach ($_POST as $a => $b) {
        $_POST[$a] = helper::sqlxss($b, 1);
        $_POST[$a] = preg_replace('~"~', '&#34;', $_POST[$a]);
        $_POST[$a] = helper::escape_stripslashes($_POST[$a]);
        if ($a == 'tag' && $b == '') {
            die('{"code":1,"msg":"标识不能为空,并且不可重复"}');
        }
        //if($a=='img' && $b=='') die('{"code":1,"msg":"图片不能为空"}');
    }
    unset($_POST['hashtoken']);
    //去掉不必要的参数
    if (isset($_POST['flash_file'])) {
        unset($_POST['flash_file']);
    }
    // 如果是代码广告
    if (isset($_POST['area_html'])) {
        $attr['list'] = $_POST['area_html'];
    } else {
        // 判断属性是否存在
        $attr_has = '-1';
        foreach ($attr['list'] as $k => $v) {
            if (!isset($attr['list'][$k]['tag'])) {
                $attr['list'][$k]['tag'] = $attr['list'][$k]['title'];
            }
            if ($attr['list'][$k]['tag'] == $_POST['tag']) {
                $attr_has = $k;
                break;
            }
        }
        if ($attr_has == '-1') {
            array_push($attr['list'], $_POST);
            //新增
        } else {
            $attr['list'][$attr_has] = $_POST;
            //修改
        }
    }
    $attr_content = serialize($attr);
    $attr_content = preg_replace("~'~", "\\'", $attr_content);
    // 写入数据库
    $res = $dbm->query_update("update " . TB_PREFIX . "recommend_area set area_html='{$attr_content}' where area_id='{$area_id}'");
    logs("修改管理广告位ID为:" . $area_id . "下面的广告成功" . $attr_content);
    die('{"code":0,"msg":"保存成功"}');
}