Exemplo n.º 1
0
 /**
  * 获取全部列表
  * @param int $uid
  * @return FeedInterface[]
  */
 public function getList($uid)
 {
     $uid = (int) $uid;
     if (!$this->getCountInfo($uid)) {
         return [];
     }
     $data = $this->db->select("feed", ['id', 'time', 'action', 'content'], ['users_id' => $uid, 'LIMIT' => [$this->count['number'] * ($this->count['page'] - 1), $this->count['number']], 'ORDER' => 'id DESC']);
     if ($data === false) {
         Log::write(_("Get feed list error."), Log::SQL);
         return [];
     }
     return Feed::getInstance()->parseList($data);
 }
Exemplo n.º 2
0
 /**
  * 添加钩子,并初始化部分信息
  */
 public function add()
 {
     $hook = hook();
     if (!db()->status()) {
         $hook->add('UriInfo_process', function () {
             return ['Home', 'sql_error'];
         });
     } else {
         $lib = lib();
         c_lib()->load('cookie')->add('cookie', new Cookie(cfg()->get('cookie', 'encode')));
         $lib->load('AppException', 'UserLogin', 'Option', 'Router', 'User', 'NoticeApply', 'Feed')->add('option', new Option());
         if (count(cfg()->get('option')) <= 0) {
             //系统初始化失败,要求进行系统安装
             define('INIT_ERROR', true);
             $hook->add('UriInfo_process', function () {
                 return ['Home', 'init_error'];
             });
             return;
         }
         if (!cfg()->get('mail_queue')) {
             $hook->add('MailTemplate_mailSend_noQueue', function () {
                 return true;
             });
         }
         option()->register_hook();
         //添加动态钩子
         Feed::getInstance()->addHook();
         $hook->add("Router_createRouter", function ($list) {
             $list['/^avatar\\/([1-9]{1}[0-9]*)\\/([1-9]{1}[0-9]*\\.[a-z]{2,5})$/'] = "/Tool/avatar/[1]/[2]";
             $list['/^avatar\\/([1-9]{1}[0-9]*)\\/default.jpg/'] = "/Tool/avatar/[1]/default.jpg";
             return $list;
         });
         //读取配置文件之后加载路由类
         $r = new Router();
         //生成路由信息
         $r->createRouter();
         $lib->add("router", $r);
         //添加提醒服务
         $lib->add("notice_apply", new NoticeApply());
         $lib->add("login_user", UserLogin::CookieLogin());
         //添加头像处理钩子
         //开始根据路由信息处理
         $hook->add('UriInfo_process', function ($list) {
             return lib()->using('router')->process($list);
         });
         $hook->add('Markdown_encodeUrlAttribute', function ($url) {
             return get_url(['Tool', 'redirect'], "?go=" . urlencode($url));
         });
         $hook->add("header_hook", function () {
             echo "<script>var SITE_URL='" . get_url() . "';var IS_LOGIN="******"true" : "false") . ";</script>\n";
         });
         $this->publish_cdn();
         if (!cfg()->get('cache', 'status')) {
             //启用页面缓存设置
             hook()->add("Cache_set", function () {
                 //关闭缓存输出
                 return false;
             });
         } else {
             pcache();
             //允许缓存时初始化信息,并加载钩子机制
         }
         $hook->add('footer_hook', function () {
             //输出数据库中的设置
             echo cfg()->get('option', 'footer');
         });
     }
 }
Exemplo n.º 3
0
 public function time_line()
 {
     try {
         $this->throwMsgCheck('is_get', 'is_ajax', 'is_login');
         $id = (int) req()->get('id');
         $list = Feed::getInstance()->getList(login_user()->getId(), $id);
         $u = [];
         $c = [];
         foreach ($list as $fid => &$v) {
             $id = $v->getUserId();
             $oid = $v->getObjUserId();
             if (!isset($u[$id])) {
                 $u[$id] = User::getUser($id)->getSimpleInfo();
                 $u[$id]['link'] = user_link($u[$id]['name']);
             }
             if (!isset($u[$oid])) {
                 $u[$oid] = User::getUser($oid)->getSimpleInfo();
                 $u[$oid]['link'] = user_link($u[$oid]['name']);
             }
             $c[$fid] = $v->getInfo();
         }
         $this->rt_msg['content'] = ['list' => $c, 'user' => $u, 'count' => count($list)];
         $this->rt_msg['status'] = true;
     } catch (\Exception $ex) {
         $this->rt_msg['msg'] = $ex->getMessage();
         $this->rt_msg['code'] = $ex->getCode();
     }
 }