/**
  * Publikowanie komentarza na mikroblogu
  *
  * @param null|int $id
  * @return $this
  */
 public function save($id = null)
 {
     $this->validate(request(), ['text' => 'required|string', 'parent_id' => 'sometimes|integer|exists:microblogs,id']);
     $microblog = $this->microblog->findOrNew($id);
     if ($id === null) {
         $user = auth()->user();
         $data = request()->only(['text', 'parent_id']) + ['user_id' => $user->id];
     } else {
         $this->authorize('update', $microblog);
         $user = $this->user->find($microblog->user_id, ['id', 'name', 'is_blocked', 'is_active', 'photo']);
         $data = request()->only(['text']);
     }
     $microblog->fill($data);
     $parent = $this->microblog->find($microblog->parent_id);
     $object = new Stream_Comment();
     $target = (new Stream_Microblog())->map($parent);
     $actor = new Stream_Actor($user);
     $alert = new Alert_Watch($this->alert);
     $stream = new Stream_Activity($this->stream);
     if (!$id) {
         $activity = new Stream_Create($actor, $object, $target);
     } else {
         $activity = new Stream_Update($actor, $object, $target);
     }
     \DB::transaction(function () use($id, &$microblog, $activity, $alert, $stream, $object, $user, $parent) {
         $microblog->save();
         // we need to parse text first (and store it in cache)
         $parser = app()->make('Parser\\Comment');
         $microblog->text = $parser->parse($microblog->text);
         if (!$id) {
             $watchers = $this->microblog->getWatchers($microblog->parent_id);
             $alert = new Alerts();
             // we need to send alerts AFTER saving comment to database because we need ID of comment
             $alertData = ['microblog_id' => $microblog->id, 'content' => $microblog->text, 'excerpt' => excerpt($microblog->text), 'sender_id' => $user->id, 'sender_name' => $user->name, 'subject' => excerpt($parent->text, 48), 'url' => route('microblog.view', [$parent->id], false) . '#comment-' . $microblog->id];
             if ($watchers) {
                 // new comment. should we send a notification?
                 $alert->attach((new Alert_Watch($this->alert, $alertData))->setUsersId($watchers));
             }
             $ref = new Ref_Login();
             // get id of users that were mentioned in the text
             $usersId = $ref->grab($microblog->text);
             if ($usersId) {
                 $alert->attach((new Alert_Login($this->alert, $alertData))->setUsersId($usersId));
             }
             // send a notify
             $alert->notify();
         }
         $ref = new Ref_Hash();
         $this->microblog->setTags($microblog->id, $ref->grab($microblog->text));
         // map microblog object into stream activity object
         $object->map($microblog);
         // put item into stream activity
         $stream->add($activity);
     });
     foreach (['name', 'is_blocked', 'is_active', 'photo'] as $key) {
         $microblog->{$key} = $user->{$key};
     }
     return view('microblog._comment')->with('comment', $microblog)->with('microblog', ['id' => $microblog->parent_id]);
 }
Ejemplo n.º 2
0
 /**
  * @param $id
  * @param UserRepositoryInterface $user
  * @param SessionRepositoryInterface $session
  * @return mixed
  */
 public function index($id, UserRepositoryInterface $user, SessionRepositoryInterface $session)
 {
     $data = $user->find($id);
     if (!$data) {
         exit;
     }
     return view('components.vcard')->with('user', $data)->with(['session_at' => $session->userLastActivity($data->id), 'rank' => $user->rank($data->id), 'total_users' => $user->countUsersWithReputation()]);
 }
Ejemplo n.º 3
0
 /**
  * Submit a new message
  *
  * @param \Coyote\User $user
  * @param Request $request
  * @throws \Exception
  */
 public function submit(\Coyote\User $user, Request $request)
 {
     $rootId = $request->get('root_id', dechex(mt_rand(0, 0x7fffffff)));
     $author = $this->user->findByName($request->get('author'));
     if (!$author) {
         throw new \Exception('Can not get recipient ID.');
     }
     $text = Pm\Text::create(['text' => $request->get('text')]);
     $fill = ['root_id' => $rootId, 'text_id' => $text->id];
     // we need to create two records. one for recipient and one for message author
     $this->model->create($fill + ['user_id' => $author->id, 'author_id' => $user->id, 'folder' => Pm::INBOX]);
     $pm = $this->model->create($fill + ['user_id' => $user->id, 'author_id' => $author->id, 'folder' => Pm::SENTBOX]);
     return $pm;
 }
Ejemplo n.º 4
0
 /**
  * Parse users login
  *
  * @param array $excerpt
  * @return array
  */
 protected function inlineUserTag($excerpt)
 {
     $text =& $excerpt['text'];
     $start = strpos($text, '@');
     if (isset($text[$start + 1])) {
         $exitChar = $text[$start + 1] === '{' ? '}' : ' ';
         $end = strpos($text, $exitChar, $start);
         if ($end === false) {
             $end = mb_strlen($text) - $start;
         }
         $length = $end - $start;
         $start += 1;
         $end -= 1;
         if ($exitChar == '}') {
             $start += 1;
             $end -= 1;
             $length += 1;
         }
         $name = substr($text, $start, $end);
         $user = $this->user->findByName($name);
         if ($user) {
             return ['extent' => $length, 'element' => ['name' => 'a', 'text' => '@' . $name, 'attributes' => ['href' => route('profile', [$user->id]), 'data-user-id' => $user->id]]];
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Usuniecie zdjecia z serwera
  *
  * @param UserRepositoryInterface $user
  */
 public function delete(UserRepositoryInterface $user)
 {
     $user->update(['photo' => null], auth()->user()->id);
 }
 /**
  * Publikowanie wpisu na mikroblogu
  *
  * @param null|int $id
  * @return $this
  */
 public function save($id = null)
 {
     $this->validate(request(), ['text' => 'required|string']);
     $microblog = $this->microblog->findOrNew($id);
     $data = request()->only(['text']);
     if ($id === null) {
         $user = auth()->user();
         $data['user_id'] = $user->id;
         $media = ['image' => []];
     } else {
         $this->authorize('update', $microblog);
         $user = $this->user->find($microblog->user_id, ['id', 'name', 'is_blocked', 'is_active', 'photo']);
         $media = $microblog->media;
         if (empty($media['image'])) {
             $media = ['image' => []];
         }
     }
     if (request()->has('thumbnail') || count($media['image']) > 0) {
         $delete = array_diff($media['image'], (array) request()->get('thumbnail'));
         foreach ($delete as $name) {
             unlink(public_path('storage/microblog/' . $name));
             unset($media['image'][array_search($name, $media['image'])]);
         }
         $insert = array_diff((array) request()->get('thumbnail'), $media['image']);
         foreach ($insert as $name) {
             rename(public_path('storage/tmp/' . $name), public_path('storage/microblog/' . $name));
             $media['image'][] = $name;
         }
         $microblog->media = $media;
     }
     $microblog->fill($data);
     \DB::transaction(function () use(&$microblog, $id, $user) {
         $microblog->save();
         // parsing text and store it in cache
         $microblog->text = app()->make('Parser\\Microblog')->parse($microblog->text);
         $object = (new Stream_Microblog())->map($microblog);
         $actor = new Stream_Actor($user);
         $stream = new Stream_Activity($this->stream);
         if (!$id) {
             // increase reputation points
             (new Reputation_Create($this->reputation))->map($microblog)->save();
             // put this to activity stream
             $stream->add(new Stream_Create($actor, $object));
             $ref = new Ref_Login();
             // get id of users that were mentioned in the text
             $usersId = $ref->grab($microblog->text);
             if ($usersId) {
                 (new Alert_Login($this->alert))->with(['users_id' => $usersId, 'sender_id' => $user->id, 'sender_name' => $user->name, 'subject' => excerpt($microblog->text, 48), 'url' => route('microblog.view', [$microblog->id], false)])->notify();
             }
         } else {
             $stream->add(new Stream_Update($actor, $object));
         }
         $ref = new Ref_Hash();
         $this->microblog->setTags($microblog->id, $ref->grab($microblog->text));
     });
     // jezeli wpis zawiera jakies zdjecia, generujemy linki do miniatur
     // metoda thumbnails() przyjmuje w parametrze tablice tablic (wpisow, tj. mikroblogow)
     // stad takie zapis:
     $microblog = $this->microblog->thumbnails($microblog);
     // do przekazania do widoku...
     foreach (['name', 'is_blocked', 'is_active', 'photo'] as $key) {
         $microblog->{$key} = $user->{$key};
     }
     return view($id ? 'microblog._microblog_text' : 'microblog._microblog')->with('microblog', $microblog);
 }
 /**
  * @param Request $request
  * @param UserRepositoryInterface $user
  * @return $this
  */
 public function index(Request $request, UserRepositoryInterface $user)
 {
     $this->validate($request, ['q' => 'username']);
     return view('components.prompt')->with('users', $user->lookupName($request['q']));
 }