Ejemplo n.º 1
0
 public function run()
 {
     // Get screen names from positional arguments
     $screenNames = $this->getArgv();
     if (empty($screenNames)) {
         $this->error("Missing screen names");
     }
     $twitter = new Twitter();
     // Auth calls if given a token and secret as keyword arguments
     if ($authUserName = $this->arg('auth')) {
         $authUser = new Model\Person();
         if (!$authUser->loadByTwitter_Name($authUserName)) {
             $this->error("No user: {$authUserName}");
         }
         $twitter = $authUser->twitter();
     } else {
         $token = $this->arg('token');
         $secret = $this->arg('secret');
         if ($token && $secret) {
             $twitter->setCredentials($token, $secret);
         }
     }
     foreach ($screenNames as $name) {
         try {
             $userInfo = $twitter->getProfileInfoFromName($name);
         } catch (TwitterException $e) {
             $this->warn("Error fetching info for {$name}\n\n{$e->debugString()}");
         }
         $this->out("\n");
         $this->tabulate($userInfo, $userInfo->screen_name);
     }
     $this->end();
 }
Ejemplo n.º 2
0
 public function __construct(Request $request, &$session = null)
 {
     // Attempt to load a Person object from the session cookie
     if ($accessToken = $request->cookie(self::COOKIE)) {
         $person = new Model\Person();
         if ($person->loadByAccess_Token($accessToken)) {
             // Cache the logged in user object
             $this->user = $person;
         }
     }
     parent::__construct($request, $session);
     // Set backto from querystring
     if ($backto = $this->request->get('backto')) {
         $this->set('backto', $backto);
     }
 }
Ejemplo n.º 3
0
 public function persons()
 {
     $person_id = $this->person_id;
     $person_id = json_decode($person_id);
     $persons = Person::wherein('id', $person_id)->get();
     return $persons;
 }
Ejemplo n.º 4
0
 public function index()
 {
     $article_num = Article::count();
     $user_num = User::count();
     $person_num = Person::count();
     $project_num = Project::count();
     $users = User::sortByDesc('id')->take(5)->get();
     return Theme::view('admin.dash.index', compact('article_num', 'user_num', 'person_num', 'project_num', 'users'));
 }
Ejemplo n.º 5
0
 public function show($id = 0)
 {
     if (!preg_match("/^[1-9]\\d*\$/", $id)) {
         return Redirect::to('/');
     }
     $person = Person::find($id);
     if (empty($person)) {
         return Redirect::to('/');
     }
     $keywords = $person->keywords;
     $description = $person->description;
     if ($person->url != '') {
         return Redirect::to($person->url);
     }
     return Theme::view('person.show', compact('person', 'keywords', 'description'));
 }
Ejemplo n.º 6
0
 public function destroy($id)
 {
     Person::destroy($id);
     Cache::store('person')->flush();
     return ['error' => 0, 'message' => '删除成功!'];
 }
Ejemplo n.º 7
0
 public static function person_data($num, $order = null, $where = null, $type = 0, $offset = 0)
 {
     $num = intval($num);
     $offset = intval($offset);
     $key = 'person_' . $num . '_' . $order . '_' . $where . '_' . $type . '_' . $offset;
     if (Cache::store('person')->has($key)) {
         $date = Cache::store('person')->get($key);
         return $date;
     } else {
         switch ($order) {
             case byId:
                 $order_str = 'id';
                 break;
             case bySort:
                 $order_str = 'sort';
                 break;
             case byPoint:
                 $order_str = 'point';
                 break;
             default:
                 $order_str = 'id';
                 break;
         }
         switch ($where) {
             case findAll:
                 $date = Person::sortByDesc($order_str)->take($num)->Offset($offset)->get();
                 break;
             case findRecommend:
                 $date = Person::where('is_recommend', '>', 0)->sortByDesc($order_str)->take($num)->Offset($offset)->get();
                 break;
             default:
                 $date = Person::sortByDesc($order_str)->take($num)->Offset($offset)->get();
                 break;
         }
         $expiresAt = Carbon::now()->addMinutes(60);
         //设置缓存时间
         Cache::store('person')->put($key, $date, $expiresAt);
         return $date;
     }
 }
Ejemplo n.º 8
0
 public function callback()
 {
     // Abort if denied
     if ($this->request->get("denied")) {
         $this->session->message('twitterDenied');
         throw $this->session->finalRedirect();
     }
     // Retrieve request token and secret from the session
     $session_oauth_token = $this->session->delete('twitter_oauth_token');
     $session_oauth_token_secret = $this->session->delete('twitter_oauth_token_secret');
     if (!$session_oauth_token || !$session_oauth_token_secret) {
         throw new HttpStatus\BadRequest("Missing Twitter session credentials");
     }
     // Verify request token
     $authToken = $this->request->get("oauth_token");
     $authTokenVerifier = $this->request->get("oauth_verifier");
     if (!$authToken) {
         throw new HttpStatus\BadRequest('Missing oauth_token parameter in Twitter callback.');
     }
     if ($authToken !== $session_oauth_token) {
         throw new HttpStatus\BadRequest("Mismatched Twitter auth tokens: {$authToken} / {$session_oauth_token}");
     }
     // Step 3 - Exchange request token stored in the session for an oAuth token and secret.
     // http://oauth.net/core/1.0a/#auth_step3
     try {
         $twitter = new Twitter();
         $twitter->setCredentials($session_oauth_token, $session_oauth_token_secret);
         $accessTokenParams = $twitter->getAccessToken($authTokenVerifier);
     } catch (TwitterException $e) {
         throw HttpStatus\Base::mapAuthException($e);
     }
     // Store access token and secret in the session
     $finalToken = $accessTokenParams['oauth_token'];
     $finalSecret = $accessTokenParams['oauth_token_secret'];
     $authedTwitterUserId = $accessTokenParams['user_id'];
     $authedTwitterUserName = $accessTokenParams['screen_name'];
     // Now we decide what to do with our brand new token
     // a) Already logged in: done
     if ($this->session->isLoggedIn()) {
         throw $this->session->finalRedirect();
     }
     // b) Existing user linked to this Twitter account: Save Twitter account details and sign in
     $authedPerson = new Model\Person();
     if ($authedPerson->loadByTwitter_Id($authedTwitterUserId)) {
         $authedPerson->twitter_name = $authedTwitterUserName;
         $authedPerson->setTwitterCredentials($finalToken, $finalSecret);
         $authedPerson->save();
         throw $this->session->signIn($authedPerson);
     }
     // c) No account: Create and link
     $newPerson = new Model\Person();
     $newPerson->twitter_id = $authedTwitterUserId;
     $newPerson->twitter_name = $authedTwitterUserName;
     $newPerson->setTwitterCredentials($finalToken, $finalSecret);
     $newPerson->save();
     // Sign in and throw the final redirect
     throw $this->session->signIn($newPerson);
 }
Ejemplo n.º 9
0
 /**
  * Delete a person.
  */
 public function actionDelete()
 {
     $this->model->deletePerson((int) $_GET['id']);
     header('location: /');
 }