Exemplo n.º 1
0
 public static function perform(Comment $comment)
 {
     if ($comment->comment_id) {
         return;
     }
     $article = $comment->article()->find_one();
     if ($article->user_id != $comment->user_id) {
         Notify::dispense()->create(array('user_id' => $article->user_id, 'from_user_id' => $comment->user_id, 'type' => Notify::REPLY, 'object_type' => $article->type(), 'object_id' => $article->id, 'message' => $comment->text))->save();
     }
     if (!preg_match_all('/@(\\w+)/', $comment->text, $match)) {
         return;
     }
     $users = array();
     foreach ($match[1] as $username) {
         if (isset($users[$username])) {
             continue;
         }
         if (!($user = User::dispense()->where('name', $username)->find_one())) {
             continue;
         }
         // If mention in reply, ignore mention notify
         if ($user->id == $article->user_id) {
             continue;
         }
         $users[$username] = $user->id;
     }
     foreach ($users as $user_id) {
         Notify::dispense()->create(array('user_id' => $user_id, 'from_user_id' => $comment->user_id, 'type' => Notify::MENTION, 'object_type' => $article->type(), 'object_id' => $article->id, 'message' => $comment->text))->save();
     }
 }
Exemplo n.º 2
0
Arquivo: User.php Projeto: angoz/pagon
 /**
  * GET /
  */
 public function get()
 {
     $id = $this->params['id'];
     $post = \Model\User::dispense()->find_one($id);
     if (!$post) {
         $this->error('Unknown User');
     }
     $this->data = $post->as_array();
 }
Exemplo n.º 3
0
 public function parserUser($text)
 {
     return preg_replace_callback('{
             (?<!(?:\\[|`))\\s?
                 @([\\w]{1,20})
             \\s(?!(?:\\]|`))
         }xs', function ($match) {
         if ($user = User::dispense()->where('name', $match[1])->find_one()) {
             return '[' . trim($match[0]) . '](' . Url::to('/u/' . $user->id) . ')';
         } else {
             return $match[0];
         }
     }, $text);
 }