示例#1
0
文件: upgrade.php 项目: h3len/Project
 function sync_data()
 {
     hg_flushMsg('开始同步数据');
     $sql = "SELECT COUNT(*) as total FROM " . DB_PREFIX . "nums";
     $total = $this->db->query_first($sql);
     $total = $total['total'];
     $offset = 0;
     $count = 10000;
     //查询存在的分表
     include_once CUR_CONF_PATH . 'lib/cache.class.php';
     $cache = new CacheFile();
     while ($offset < $total) {
         hg_flushMsg('开始同步第' . $offset . '到' . ($offset + $count) . '条');
         $table = $cache->get_cache('access_table_name');
         $table = convert_table_name($table);
         $table_str = '';
         if ($table) {
             $table_str = implode(',', $table);
         }
         $sql = "ALTER TABLE " . DB_PREFIX . "merge UNION(" . $table_str . ")";
         $this->db->query($sql);
         //查询存在的分表
         $sql = "SELECT app_bundle, module_bundle, cid, title FROM " . DB_PREFIX . "nums WHERE 1 ORDER BY id ASC LIMIT " . $offset . ", " . $count;
         $q = $this->db->query($sql);
         while (($row = $this->db->fetch_array($q)) != false) {
             $sql = "UPDATE " . DB_PREFIX . "merge SET title = '" . $row['title'] . "'\n                        WHERE app_bundle='" . $row['app_bundle'] . "' AND module_bundle = '" . $row['module_bundle'] . "' AND cid='" . $row['cid'] . "'";
             //                hg_flushMsg($sql);
             $this->db->query($sql);
         }
         $offset += $count;
     }
     hg_flushMsg('数据同步完成');
 }
示例#2
0
 function show()
 {
     $cid = urldecode($this->input['cid']);
     if (!$cid) {
         $this->errorOutput('no cid');
     }
     $sql = "UPDATE " . DB_PREFIX . "nums SET del = 1 WHERE cid IN(" . $cid . ")";
     $this->db->query($sql);
     include_once CUR_CONF_PATH . 'lib/cache.class.php';
     $cache = new CacheFile();
     $table = $cache->get_cache('access_table_name');
     $table = convert_table_name($table);
     if ($table) {
         $table_str = implode(',', $table);
     }
     $sql = "ALTER TABLE " . DB_PREFIX . "merge UNION(" . $table_str . ")";
     $this->db->query($sql);
     $sql = "UPDATE " . DB_PREFIX . "merge SET del = 1 WHERE cid IN(" . $cid . ")";
     $this->db->query($sql);
     exit('sucess');
 }
示例#3
0
文件: access.php 项目: h3len/Project
 function get_content()
 {
     if ($this->settings['cache_expire_time']) {
         /**先从缓存读取数据 缓存不存在或过期时再从表中查询*/
         include_once ROOT_PATH . 'lib/class/cache/cache.class.php';
         $cache_factory = cache_factory::get_instance();
         $cache_type = $this->settings['cache_type'] ? $this->settings['cache_type'] : 'file';
         $cache_driver = $cache_factory->get_cache_driver($cache_type);
         $input = $this->input;
         unset($input['access_token'], $input['lpip']);
         $cache_id = md5(serialize($input));
         $data = $cache_driver->get($cache_id);
         if ($data) {
             $this->addItem($data);
             $this->output();
         }
         /**先从缓存读取数据 缓存不存在或过期时再从表中查询*/
     }
     //$condition = $this->get_condition();
     $offset = $this->input['page'] ? $this->input['page_num'] * ($this->input['page'] - 1) : 0;
     $count = $this->input['page_num'] ? intval($this->input['page_num']) : 20;
     $con = $con_count = $this->con_process();
     $con['offset'] = $offset;
     $con['count'] = $count;
     $content = $this->obj->get_content($con);
     include_once ROOT_PATH . 'lib/class/publishcontent.class.php';
     $this->publishcontent = new publishcontent();
     $content_type = $this->publishcontent->get_all_content_type();
     $pub_content_bundle = array();
     foreach ((array) $content_type as $k => $v) {
         $pub_content_bundle[] = $v['bundle_id'];
     }
     include_once ROOT_PATH . 'lib/class/auth.class.php';
     $this->auth = new Auth();
     $app_info = $this->auth->get_app();
     $module = array();
     foreach ((array) $app_info as $k => $v) {
         if (!empty($v)) {
             $module[$v['bundle']] = $v['name'];
         }
     }
     $cidArr = array();
     $conArr = array();
     $other_content = array();
     foreach ((array) $content as $row) {
         if (!in_array($row['app_bundle'], $pub_content_bundle)) {
             $row['bundle_name'] = $module[$row['app_bundle']];
             if (!$row['bundle_name']) {
                 $row['bundle_name'] = $this->settings["App_{$row['app_bundle']}"]['name'];
             }
             if (!$row['bundle_name']) {
                 $row['bundle_name'] = $row['app_bundle'];
             }
             $row['content_url'] = $row['url'];
             $row['access_nums'] = $row['num'];
             $other_content[] = $row;
         } else {
             $cidArr[] = $row['cid'];
             $conArr[$row['cid']] = array('access_nums' => $row['num']);
         }
     }
     $cidStr = implode(',', $cidArr);
     $ret = $this->publishcontent->get_content_by_cid($cidStr);
     if (!is_array($ret)) {
         //return array();
     }
     $ret = (array) $ret;
     $arExistIds = array();
     foreach ($ret as $k => $v) {
         $arExistIds[] = $v['cid'];
         $ret[$k]['bundle_name'] = $module[$v['bundle_id']];
         if (!$ret[$k]['bundle_name']) {
             $ret[$k]['bundle_name'] = $this->settings["App_{$v['bundle_id']}"]['name'];
         }
         if (!$ret[$k]['bundle_name']) {
             $ret[$k]['bundle_name'] = $v['bundle_id'];
         }
         $ret[$k] = array_merge($ret[$k], $conArr[$k]);
     }
     $ret = array_merge($ret, $other_content);
     //发布库删除没有更新统计时条数不准确 下面代码为解决此bug
     //对比cid差集
     $delCid = array_diff($cidArr, $arExistIds);
     //更新已经不存在的内容
     if (!empty($delCid)) {
         $cid = implode(',', $delCid);
         $sql = "UPDATE " . DB_PREFIX . "nums SET del = 1 WHERE cid IN(" . $cid . ")";
         $this->db->query($sql);
         include_once CUR_CONF_PATH . 'lib/cache.class.php';
         $cache = new CacheFile();
         $table = $cache->get_cache('access_table_name');
         $table = convert_table_name($table);
         if ($table) {
             $table_str = implode(',', $table);
         }
         $sql = "ALTER TABLE " . DB_PREFIX . "merge UNION(" . $table_str . ")";
         $this->db->query($sql);
         $sql = "UPDATE " . DB_PREFIX . "merge SET del = 1 WHERE cid IN(" . $cid . ")";
         $this->db->query($sql);
     }
     $ret = hg_array_sort($ret, 'access_nums', 'DESC');
     $pagearr = $this->obj->get_content($con_count, 1);
     $pagearr['page_num'] = $count;
     $pagearr['total_num'] = $pagearr['total'];
     $pagearr['total_page'] = ceil($pagearr['total'] / $count);
     $pagearr['current_page'] = floor($offset / $count) + 1;
     $ret = array('content' => array_values($ret), 'page' => $pagearr);
     if ($this->settings['cache_expire_time']) {
         /*将数据写入缓存*/
         $cache_driver->set($cache_id, $ret, $this->settings['cache_expire_time']);
         /*将数据写入缓存*/
     }
     $this->addItem($ret);
     $this->output();
 }
示例#4
0
 public function show($condition, $offset, $count)
 {
     include_once ROOT_PATH . 'lib/class/publishcontent.class.php';
     $this->publishcontent = new publishcontent();
     $content_type = $this->publishcontent->get_all_content_type();
     $pub_content_bundle = array();
     foreach ((array) $content_type as $k => $v) {
         $pub_content_bundle[] = $v['bundle_id'];
     }
     include_once ROOT_PATH . 'lib/class/auth.class.php';
     $this->auth = new Auth();
     $app_info = $this->auth->get_app();
     $module = array();
     foreach ((array) $app_info as $k => $v) {
         if (!empty($v)) {
             $module[$v['bundle']] = $v['name'];
         }
     }
     $limit = " LIMIT " . $offset . " , " . $count;
     $sql = "SELECT * FROM " . DB_PREFIX . "nums WHERE 1 " . $condition . $limit;
     $q = $this->db->query($sql);
     $cidArr = array();
     $conArr = array();
     $other_content = array();
     while ($row = $this->db->fetch_array($q)) {
         if (!in_array($row['app_bundle'], $pub_content_bundle)) {
             $row['bundle_name'] = $module[$row['app_bundle']];
             if (!$row['bundle_name']) {
                 $row['bundle_name'] = $this->settings["App_{$row['app_bundle']}"]['name'];
             }
             if (!$row['bundle_name']) {
                 $row['bundle_name'] = $row['app_bundle'];
             }
             $row['update_time'] = date('Y-m-d H:i:s', $row['update_time']);
             $row['content_url'] = $row['url'];
             $other_content[] = $row;
         } else {
             $cidArr[] = $row['cid'];
             $conArr[$row['cid']] = array('access_nums' => $row['access_nums'], 'update_time' => date('Y-m-d H:i:s', $row['update_time']));
         }
     }
     $cidStr = implode(',', $cidArr);
     //		include_once(ROOT_PATH . 'lib/class/publishcontent.class.php');
     //		$this->publishcontent = new publishcontent();
     $ret = $this->publishcontent->get_content_by_cid($cidStr);
     if (!is_array($ret)) {
         //return array();
     }
     $ret = (array) $ret;
     $arExistIds = array();
     foreach ($ret as $k => $v) {
         $arExistIds[] = $v['cid'];
         $ret[$k]['bundle_name'] = $module[$v['bundle_id']];
         if (!$ret[$k]['bundle_name']) {
             $ret[$k]['bundle_name'] = $this->settings["App_{$v['bundle_id']}"]['name'];
         }
         if (!$ret[$k]['bundle_name']) {
             $ret[$k]['bundle_name'] = $v['bundle_id'];
         }
         $ret[$k] = array_merge($ret[$k], $conArr[$k]);
     }
     $ret = array_merge($ret, $other_content);
     //发布库删除没有更新统计时条数不准确 下面代码为解决此bug
     //对比cid差集
     $delCid = array_diff($cidArr, $arExistIds);
     //更新已经不存在的内容
     if (!empty($delCid)) {
         $cid = implode(',', $delCid);
         $sql = "UPDATE " . DB_PREFIX . "nums SET del = 1 WHERE cid IN(" . $cid . ")";
         $this->db->query($sql);
         include_once CUR_CONF_PATH . 'lib/cache.class.php';
         $cache = new CacheFile();
         $table = $cache->get_cache('access_table_name');
         $table = convert_table_name($table);
         if ($table) {
             $table_str = implode(',', $table);
         }
         $sql = "ALTER TABLE " . DB_PREFIX . "merge UNION(" . $table_str . ")";
         $this->db->query($sql);
         $sql = "UPDATE " . DB_PREFIX . "merge SET del = 1 WHERE cid IN(" . $cid . ")";
         $this->db->query($sql);
     }
     //		switch($this->input['access_nums'])
     //		{
     //			case 1:
     //				$info = hg_array_sort($ret,'access_nums','DESC');
     //				break;
     //			case 2:
     //				$info = hg_array_sort($ret,'access_nums','ASC');
     //				break;
     //			default:
     //				$info = hg_array_sort($ret,'update_time','DESC');
     //		}
     $info = hg_array_sort($ret, 'access_nums', 'DESC');
     return $info;
 }
示例#5
0
文件: ranking.php 项目: h3len/Project
 function show()
 {
     $id = intval($this->input['sort_id']);
     $column_id = $this->input['column_id'];
     $exclude_column_id = $this->input['exclude_column_id'];
     if ($id) {
         $sql = "SELECT status,output_type,column_id FROM " . DB_PREFIX . "ranking_sort WHERE id = " . $id;
         $sort = $this->db->query_first($sql);
         if (empty($sort) || $sort['status'] != 1) {
             $this->errorOutput("unexist or unaudited");
         }
         include_once ROOT_PATH . 'lib/class/publishcontent.class.php';
         $this->publishcontent = new publishcontent();
         $content_type = $this->publishcontent->get_all_content_type();
         $pub_content_bundle = array();
         foreach ((array) $content_type as $k => $v) {
             $pub_content_bundle[] = $v['bundle_id'];
         }
         $offset = intval($this->input['offset']) ? intval($this->input['offset']) : 0;
         $count = intval($this->input['count']) ? intval($this->input['count']) : 30;
         $data_limit = " LIMIT " . $offset . ", " . $count;
         $sql = "SELECT * FROM " . DB_PREFIX . "ranking_cont WHERE sort_id = " . $id . " ORDER BY count DESC " . $data_limit;
         $q = $this->db->query($sql);
         $cidArr = array();
         $conArr = array();
         $other_content = array();
         while ($row = $this->db->fetch_array($q)) {
             if ($row['app_bundle'] && !in_array($row['app_bundle'], $pub_content_bundle)) {
                 $row['update_time'] = date('Y-m-d H:i:s', $row['update_time']);
                 $row['content_url'] = $row['url'];
                 $other_content[] = $row;
             } else {
                 $cidArr[] = $row['cid'];
                 $conArr[$row['cid']] = $row['count'];
             }
         }
         $cidStr = implode(',', $cidArr);
         $blDirectReturn = $this->input['direct_return'] && $this->input['direct_return'] != 'false' ? 1 : 0;
         if ($blDirectReturn) {
             $this->addItem($cidStr);
         } else {
             if ($cidStr) {
                 if ($sort['output_type'] == 1) {
                     include_once ROOT_PATH . 'lib/class/publishconfig.class.php';
                     $this->publishconfig = new publishconfig();
                     $ret = $this->publishconfig->get_column_info_by_ids($cidStr);
                 } else {
                     include_once ROOT_PATH . 'lib/class/publishcontent.class.php';
                     $this->publishtcontent = new publishcontent();
                     $useColumn = array();
                     if ($column_id) {
                         $sort['column_id'] = $column_id;
                     }
                     if ($exclude_column_id) {
                         $exclude_column_id = explode(',', $exclude_column_id);
                         $sort['column_id'] = explode(',', $sort['column_id']);
                         $sort['column_id'] = array_diff($sort['column_id'], $exclude_column_id);
                         $sort['column_id'] = implode(',', $sort['column_id']);
                     }
                     foreach ($cidArr as $cv) {
                         $useColumn[$cv] = $sort['column_id'];
                     }
                     $ret = $this->publishtcontent->get_content_by_cid($cidStr, $useColumn);
                 }
                 $arExistIds = array();
                 if (is_array($ret) && count($ret) > 0) {
                     foreach ($ret as $k => $v) {
                         $arExistIds[] = $sort['output_type'] == 1 ? $v['id'] : $v['cid'];
                         //栏目时统计记录的是id  内容统计记录的是cid
                         $ret[$k]['count'] = $sort['output_type'] == 1 ? $conArr[$v['id']] : $conArr[$v['cid']];
                     }
                 }
                 //发布库删除没有更新统计时条数不准确 下面代码为解决此bug
                 //对比cid差集
                 $cidStr = explode(',', $cidStr);
                 $delCid = array_diff($cidStr, $arExistIds);
                 //更新已经不存在的内容
                 if (0 && !empty($delCid)) {
                     $cid = implode(',', $delCid);
                     $sql = "UPDATE " . DB_PREFIX . "nums SET del = 1 WHERE cid IN(" . $cid . ")";
                     $this->db->query($sql);
                     include_once CUR_CONF_PATH . 'lib/cache.class.php';
                     $cache = new CacheFile();
                     $table = $cache->get_cache('access_table_name');
                     $table = convert_table_name($table);
                     if ($table) {
                         $table_str = implode(',', $table);
                     }
                     $sql = "ALTER TABLE " . DB_PREFIX . "merge UNION(" . $table_str . ")";
                     $this->db->query($sql);
                     $sql = "UPDATE " . DB_PREFIX . "merge SET del = 1 WHERE cid IN(" . $cid . ")";
                     $this->db->query($sql);
                     $sql = "DELETE FROM " . DB_PREFIX . "ranking_cont WHERE sort_id=" . $id . " AND cid IN(" . $cid . ")";
                     $this->db->query($sql);
                 }
                 //
                 $ret = (array) $ret;
                 $ret = array_merge($other_content, $ret);
                 if (is_array($ret) && count($ret)) {
                     $ret = hg_array_sort($ret, 'count', 'DESC');
                     foreach ($ret as $k => $v) {
                         if ($sort['output_type'] == 1) {
                             $v['title'] = $v['name'];
                         }
                         $this->addItem($v);
                     }
                 }
             }
         }
     } else {
         $sql = "SELECT * FROM " . DB_PREFIX . "ranking_sort WHERE status = 1 ";
         $q = $this->db->query($sql);
         $ret = array();
         while ($row = $this->db->fetch_array($q)) {
             $ret[] = $row;
         }
         if ($ret) {
             foreach ($ret as $k => $v) {
                 $this->addItem($v);
             }
         }
     }
     $this->output();
 }