Пример #1
0
 function __construct()
 {
     $this->dbm = new db_mysql();
     $this->table = TB_PREFIX . 'url_rewrite';
     $this->host = $_SERVER['HTTP_HOST'];
     // 伪静态对象初始化
     $a = helper::file_cache($this->host . '_' . CACHE_PREFIX . 'url_config', '', CACHE_TIME, SITE_PATH . CACHE_NAME);
     if ($a == 'timeout') {
         $a = helper::file_cache($this->host . '_' . CACHE_PREFIX . 'url_config', $this->url_config(), CACHE_TIME, SITE_PATH . CACHE_NAME);
     }
     $this->url_config = $a;
     $this->rewrite = SITE_REWRITEURL;
     $this->root_path = SITE_PATH;
 }
Пример #2
0
 /**
  * 更新分类缓存
  */
 public function update_cate()
 {
     $this->categories = helper::file_cache($this->host . '_' . CACHE_PREFIX . 'categories', $this->categories(), $this->cache_time, SITE_PATH . CACHE_NAME);
     //绑定域名的分类重写缓存
     foreach ($this->categories as $k => $v) {
         if (substr($v['go_url'], 0, 7) == 'http://') {
             $this->set_domain($k, $v['go_url']);
         }
     }
     $this->categories = helper::file_cache($this->host . '_' . CACHE_PREFIX . 'categories', $this->categories, $this->cache_time, SITE_PATH . CACHE_NAME);
 }
Пример #3
0
 /**
  * 把文档内容替换内链
  * @param $content 内容
  * @param  $n 内链个数 默认5个
  */
 public function nlink($content, $n = 5)
 {
     $file_path = SITE_PATH . CACHE_NAME;
     $rs = helper::file_cache(CACHE_PREFIX . 'nlink', '', CACHE_TIME, $file_path);
     //读取缓存
     if ($rs === 'timeout') {
         //缓存过期
         @unlink($file_path . '/' . CACHE_PREFIX . 'nlink');
         $sql = "SELECT * FROM " . TB_PREFIX . "nlink ORDER BY 'nlink_id' DESC LIMIT 0,2000";
         $rs = $this->dbm->query($sql);
         $rs = helper::file_cache(CACHE_PREFIX . 'nlink', $rs['list'], CACHE_TIME, $file_path);
     }
     $n = intval($n);
     $n = !empty($n) ? $n : 5;
     foreach ($rs as $v) {
         $content = preg_replace('~' . $v['nlink_txt'] . '~', '<a href="' . $v['nlink_url'] . '" target="_blank">' . $v['nlink_txt'] . '</a>', $content, 1, $count);
         $n -= $count;
         if ($n == 0) {
             break;
         }
     }
     unset($rs);
     return $content;
 }
Пример #4
0
 /**
  * 取精确标签资讯列表
  *
  * @param  $ 为数组格式
  * @param  $ =>where          更新的条件语句
  * @param  $ =>order          排序
  * @param  $ =>pagesize       分页大小
  * @param  $ =>p              当前页码
  * @param  $ =>rewrite        URL重写方式 0,1,2,默认为2
  * @param  $ =>count          是否计算总数 0 不计算 1 计算
  * @param  $ =>resource       是否同时取出资源 0 不取 1 取
  * @param  $ =>fields       查询的字段
  * @param  $ =>no_cache      1=强制读取最新数据
  * @param  $ =>extern  读取扩展表字段0=不读取,1=读取
  */
 public function get_list_tag($params)
 {
     $keyword_id = isset($params['keyword_id']) ? $params['keyword_id'] : '';
     $where = isset($params['where']) ? $params['where'] : '';
     $pagesize = isset($params['pagesize']) ? $params['pagesize'] : PAGESIZE_F;
     $p = isset($params['p']) ? $params['p'] : 1;
     $count = $params['count'] = isset($params['count']) ? $params['count'] : 0;
     $rewrite = isset($params['rewrite']) ? $params['rewrite'] : 2;
     $resource = isset($params['resource']) ? $params['resource'] : 0;
     $fields = isset($params['fields']) ? $params['fields'] : '';
     $node = isset($_GET['tpl']) ? $_GET['tpl'] : 'tag';
     $no_cache = isset($params['no_cache']) ? $params['no_cache'] : 0;
     $state = isset($params['state']) ? $params['state'] : 0;
     $show_extern = isset($params['extern']) ? $params['extern'] : 0;
     $show_tags = isset($params['show_tags']) ? $params['show_tags'] : 0;
     $order = 'order by b.info_id desc';
     $sql = "select * from " . TB_PREFIX . "keyword where keyword_id='" . $keyword_id . "' limit 1";
     $rs = $this->dbm->query($sql);
     $keyword = '';
     if (count($rs['list']) == 1) {
         $keyword = $rs['list'][0]['keyword'];
     }
     if ($fields == '') {
         $fields = '*';
     } else {
         $fields_arr = explode(',', $fields);
         $fields = '';
         for ($i = 0; $i < count($fields_arr); $i++) {
             $fields .= ',' . trim($fields_arr[$i]);
         }
         $fields = substr($fields, 1);
     }
     $total = 0;
     //总数
     // 拼接SQL语句
     $sql = "select * from " . TB_PREFIX . "keyword_relation as a left join " . TB_PREFIX . "info_list as b on a.info_id=b.info_id where a.keyword_id='{$keyword_id}' and b.info_state={$state} ";
     if (strlen($where) > 0) {
         $sql .= " and {$where} ";
     }
     //die($sql);
     // 拼接排序
     $suffix = $order;
     // 拼接分页数据
     $suffix .= " limit " . ($p - 1) * $pagesize . ",{$pagesize}";
     // 缓存开启,获取缓存内容
     if ($no_cache == 1) {
         $result = $this->dbm->query($sql, $suffix, $count);
     } else {
         if (defined('CACHE_TIME') && CACHE_TIME != '' && CACHE_TIME != 0) {
             // 缓存文件名
             $cache_file = md5($sql . $suffix);
             $data_path = SITE_PATH . CACHE_NAME . '/list/' . substr($cache_file, 0, 2);
             // 读取缓存
             $result = helper::file_cache($cache_file, '', CACHE_TIME, $data_path);
             if ($result == 'timeout') {
                 $result = $this->dbm->query($sql, $suffix, $count);
                 for ($i = 0; $i < count($result['list']); $i++) {
                     unset($result['list'][$i]['uid']);
                     unset($result['list'][$i]['uname']);
                 }
                 // 写入缓存
                 $result = helper::file_cache($cache_file, $result, CACHE_TIME, $data_path);
             }
         } else {
             $result = $this->dbm->query($sql, $suffix, $count);
         }
     }
     if ($count == 1) {
         $total = $result['total'];
     } else {
         $result['total'] = $total;
     }
     $result['keyword'] = $keyword;
     if (defined('INFO_IMG') && file_exists(INFO_IMG)) {
         $default_img = INFO_IMG;
     }
     // 重写返回数组
     for ($i = 0; $i < count($result['list']); $i++) {
         $result['list'][$i]['cate'] = $this->categories[$result['list'][$i]['last_cate_id']];
         if ($show_extern == '1') {
             // 取扩展表
             $extern = $this->get_extern_by_cate_id($result['list'][$i]['cate']['cate_id']);
             if ($extern['extern_name'] != '') {
                 $result['list'][$i]['extern'] = $this->get_extern($extern['extern_name'], $result['list'][$i]['info_id']);
             }
             // 取扩展字段结束
         }
         // 取资源列表
         if ($resource == 1) {
             $result['list'][$i]['resource'] = $this->get_resource($result['list'][$i]['info_id']);
             $result['list'][$i]['resource_total'] = count($result['list'][$i]['resource']);
         }
         // 缩略图
         if (isset($result['list'][$i]['info_img'])) {
             if ($result['list'][$i]['info_img'] == '') {
                 $result['list'][$i]['info_img'] = $default_img;
             }
             $result['list'][$i]['thumb'] = $this->thumb_url($result['list'][$i]['info_img']);
         }
         // URL
         $surl_domain = $this->bind_domain($result['list'][$i]['last_cate_id']);
         $result['list'][$i]['surl'] = ($surl_domain == '' ? $this->url_recheck() : $surl_domain) . $this->url->encode('content_info', array('host' => SITE_PATH, 'id' => $result['list'][$i]['info_id']));
         if ($result['list'][$i]['info_url'] != '') {
             $result['list'][$i]['surl'] = $result['list'][$i]['info_url'];
         }
         // 资讯标题
         // 标题加粗
         $result['list'][$i]['info_style_title'] = $result['list'][$i]['info_title'];
         if ($result['list'][$i]['fbold'] == 1) {
             $result['list'][$i]['info_style_title'] = "<b>" . $result['list'][$i]['info_title'] . "</b>";
         }
         // 标题加亮
         if (!empty($result['list'][$i]['fcolor'])) {
             $result['list'][$i]['info_style_title'] = "<font color='" . $result['list'][$i]['fcolor'] . "'>" . $result['list'][$i]['info_style_title'] . "</font>";
         }
         // 资讯简介
         if ($result['list'][$i]['info_desc'] == '') {
             $result['list'][$i]['info_desc'] = helper::utf8_substr(preg_replace('~(<style[^>]*>[\\w\\W]*?</style>)|(<[^>]*>)|(\\r)|(\\n)|(\\t)~', '', $result['list'][$i]['info_body']), 0, 220);
         }
         //精确标签输出
         //查询关系表中的关键字ID
         if ($show_tags == 1) {
             $sql = "select keyword_id from " . TB_PREFIX . "keyword_relation where info_id= '{$result['list'][$i]['info_id']}'";
             $r = $this->dbm->query($sql);
             $ids = array();
             foreach ($r['list'] as $k => $v) {
                 array_push($ids, $v['keyword_id']);
             }
             $sql = "select * from " . TB_PREFIX . "keyword where keyword_id in (" . implode(',', $ids) . ")";
             $ret = $this->dbm->query($sql);
             $result['tags_html'] = '';
             if (count($ret['list']) > 0) {
                 $result['list'][$i]['tags'] = array();
                 $result['list'][$i]['tags_html'] = '';
                 foreach ($ret['list'] as $k => $v) {
                     $result['list'][$i]['tags'][] = $v['keyword'];
                     $result['list'][$i]['tags_html'] .= '<a href="' . $this->url->encode('tag_index', array('host' => SITE_PATH, 'extid' => $this->categories[$result['list'][$i]['last_cate_id']]['extern_id'], 'id' => $v['keyword_id'])) . '" target="_blank">' . $v['keyword'] . '</a>&nbsp;&nbsp;';
                 }
             }
         }
     }
     // 分页码HTML
     if ($rewrite == 0 || $rewrite == 1) {
         // 前台使用动态地址或者伪静态地址
         if ($this->url != null && $params['count'] == 1) {
             $cpy = '';
             $result['pagebar'] = helper::pagebar(array('total' => $total, 'pagesize' => $pagesize, 'rewrite' => $rewrite, 'rule' => array('node' => $node, 'obj' => $this->url, 'params' => array('host' => SITE_PATH, 'id' => $keyword_id, 'p' => $p))));
         } else {
             $result['pagebar'] = array('pagecode' => '');
         }
     } else {
         $result['pagebar'] = helper::pagebar(array('total' => $total, 'pagesize' => $pagesize, 'rewrite' => $rewrite));
     }
     return $result;
 }
Пример #5
0
 /**
  * 更新模型缓存
  */
 public function update_models()
 {
     $this->models = helper::file_cache($this->host . '_' . CACHE_PREFIX . 'model', $this->get_model(), CACHE_TIME, SITE_PATH . CACHE_NAME);
 }
Пример #6
0
 function cache($params = array())
 {
     $params['cachekey'] = isset($params['cachekey']) ? $params['cachekey'] : '';
     $params['cachetime'] = isset($params['cachetime']) ? $params['cachetime'] : 3600 * 24;
     $params['type'] = isset($params['type']) ? $params['type'] : 'array';
     if ($params['cachekey'] == '') {
         return '未定义cachekey';
     }
     $cache = helper::file_cache($params['cachekey'], '', $params['cachetime']);
     if ($cache == 'timeout') {
         //echo $params['funcname']."(\$params)";
         if (preg_match('~\\(.*?\\)~', $params['funcname'])) {
             eval('$content=' . $params['funcname'] . ";");
         } else {
             eval('$content=' . $params['funcname'] . "(\$params);");
         }
         if ($params['type'] == 'array') {
             $ca = json_encode($content);
         } else {
             $ca = $content;
         }
         helper::file_cache($params['cachekey'], $ca);
         return $content;
     } else {
         if ($params['type'] == 'array') {
             $ca = json_decode($cache, 1);
         } else {
             $ca = $cache;
         }
         return $ca;
     }
 }