Exemplo n.º 1
0
 public function getList()
 {
     if (!extension_loaded('curl')) {
         $this->error('糗事百科插件需要开启PHP的CURL扩展');
     }
     $lists = S('QiuBai_content');
     if (!$lists) {
         $config = \Common\Controller\Addon::getConfig('QiuBai');
         $content = \Org\Net\Http::fsockopenDownload('http://www.qiushibaike.com');
         if ($content) {
             $regex = "/<div class=\"content\".*?>.*?--(.*?)--.*?<\\/div>/ism";
             preg_match_all($regex, $content, $match);
             $lists = array_map(function ($a, $b) {
                 return array('time' => time_format($a), 'content' => $b);
             }, $match[1], $match[0]);
             S('QiuBai_content', $lists, $config['cache_time']);
         }
     }
     if ($lists) {
         $this->success('成功', '', array('data' => $lists));
     } else {
         $this->error('获取糗事百科列表失败');
     }
     $this->assign('qiubai_list', $lists);
 }
Exemplo n.º 2
0
 /**
  * 检查新版本
  * @author jry <*****@*****.**>
  */
 public function checkVersion()
 {
     //远程更新地址
     $url = C('WEBSITE_DOMAIN') . C('UPDATE_URL') . '.html?action=check';
     //参数设置
     $params = array('product_name' => C('PRODUCT_NAME'), 'current_version' => C('CURRENT_VERSION'), 'company_name' => C('COMPANY_NAME'), 'develop_version' => C('DEVELOP_VERSION'), 'build_version' => C('BUILD_VERSION'), 'product_model' => C('PRODUCT_MODEL'), 'product_title' => C('PRODUCT_TITLE'), 'develop_team' => C('DEVELOP_TEAM'), 'data_auth_key' => sha1(C('DATA_AUTH_KEY')), 'website_domain' => $_SERVER['HTTP_HOST'], 'server_software' => php_uname() . '_' . $_SERVER['SERVER_SOFTWARE'], 'website_title' => C('WEB_SITE_TITLE'), 'auth_sn' => C('AUTH_SN'), 'autn_username' => C('AUTH_USERNAME'), 'autn_password' => C('AUTH_PASSWORD'));
     $vars = http_build_query($params);
     //获取版本数据
     $conf_arr = array('post' => $params);
     $result = json_decode(\Org\Net\Http::fsockopenDownload($url, $conf_arr), true);
     if ($result['status'] == 1) {
         $this->ajaxReturn($result);
     } else {
         $this->error('连接服务器失败');
     }
 }
 public function gather()
 {
     //保存请求时间
     //$data['create_time'] = NOW_TIME;
     //$result = M('post_log')->add($data);
     //取出需要更新文章
     $map_cron['next_cron_time'] = array('lt', NOW_TIME);
     //$map_cron['status']		//是否在连载
     $detail = D('Book')->where($map_cron)->order('next_cron_time')->find();
     $gid = $detail['gid'];
     $bookid = $detail['id'];
     //如果没有计划, 返回真
     if (!$detail) {
         exit('over');
     }
     //更新此次更新时间
     $data_cron['last_cron_time'] = NOW_TIME;
     $data_cron['next_cron_time'] = NOW_TIME + 3600;
     //下次时间 1小时
     $result = D('Book')->where('id=' . $bookid)->save($data_cron);
     if (!$gid) {
         exit('error');
     }
     $url = $this->getBookJs($gid);
     $content = json_decode(\Org\Net\Http::fsockopenDownload($url), true);
     if (!$content || $content['status'] != 1) {
         exit('error');
     }
     //判断是否采集过, 没有的话, 保存文章信息
     //判断最新章节
     //取出所有章节
     $group = $content['data']['group'];
     $map['bookid'] = $data['bookid'] = $bookid;
     //待优化: 查看已采集的章节数量,
     $count_chapter = D('BookChapter')->where('bookid=' . $bookid)->count();
     if ($count_chapter < count($group)) {
         foreach ($group as $k => $chapter) {
             if ($k < $count_chapter) {
                 continue;
             }
             //判断是否已经存在
             $map['chapterid'] = $chapter['index'];
             $exist_chapter = D('BookChapter')->where($map)->field('id, status')->find();
             if (!$exist_chapter) {
                 //保存
                 $data['chapterid'] = $chapter['index'];
                 $data['cid'] = $chapter['cid'];
                 $data['index'] = $chapter['index'];
                 $data['rank'] = $chapter['rank'];
                 $data['title'] = $chapter['text'];
                 $data['url'] = $chapter['href'];
                 D('BookChapter')->add($data);
             }
         }
         //更新最后一章信息到Book表
         $last_chapter['last_chapter_title'] = $data['title'];
         $last_chapter['last_chapter_index'] = $data['index'];
         $last_chapter['last_chapter_update_time'] = NOW_TIME;
         D('Book')->where('id=' . $bookid)->save($last_chapter);
         exit('success');
     } else {
         //更新下一个任务
         $this->gather();
     }
     //更新, 记录信息
 }
 public function gather()
 {
     $bookid = I('get.bookid');
     $gid = D('Book')->where('id=' . $bookid)->getField('gid');
     if (!$gid) {
         $this->ajaxReturn(array('statusCode' => 300, 'message' => '文章不存在'));
     }
     $url = $this->getBookJs($gid);
     $content = json_decode(\Org\Net\Http::fsockopenDownload($url), true);
     if (!$content || $content['status'] != 1) {
         $this->ajaxReturn(array('statusCode' => 300, 'message' => '采集失败'));
     }
     //判断是否采集过, 没有的话, 保存文章信息
     //判断最新章节
     //取出所有章节
     //dump($content);exit();
     $group = $content['data']['group'];
     //echo json_encode($group[199]);exit;
     $map['bookid'] = $data['bookid'] = $bookid;
     //待优化: 查看已采集的章节数量,
     $count_chapter = D('BookChapter')->where('bookid=' . $bookid)->count();
     if ($count_chapter < count($group)) {
         foreach ($group as $k => $chapter) {
             if ($k < $count_chapter) {
                 continue;
             }
             //判断是否已经存在
             $map['chapterid'] = $chapter['index'];
             $exist_chapter = D('BookChapter')->where($map)->field('id, status')->find();
             if (!$exist_chapter) {
                 //保存
                 $data['chapterid'] = $chapter['index'];
                 $data['cid'] = $chapter['cid'];
                 $data['index'] = $chapter['index'];
                 $data['rank'] = $chapter['rank'];
                 $data['title'] = $chapter['text'];
                 $data['url'] = $chapter['href'];
                 D('BookChapter')->add($data);
             }
         }
         //更新最后一章信息到Book表
         $last_chapter['last_chapter_title'] = $data['title'];
         $last_chapter['last_chapter_index'] = $data['index'];
         $last_chapter['last_chapter_update_time'] = NOW_TIME;
         D('Book')->where('id=' . $bookid)->save($last_chapter);
     }
     //取出地址中返回的章节
     $this->ajaxReturn(array('statusCode' => 200, 'message' => '采集成功', 'tabid' => 'Book_manage'));
 }