Beispiel #1
0
 /**
  * Make post to user wall from $viewer to $target instance of iUser interface objects
  * @param iUser $target
  * @param iUser $viewer
  * @param int $delay
  * @return bool
  */
 public function makePost(iUser $target, iUser $viewer, $delay = 60)
 {
     if ($target === null || $viewer === null) {
         return false;
     }
     $find = WallRecords::where('sender_id', '=', $viewer->id)->orderBy('updated_at', 'desc')->first();
     if ($find !== null) {
         $lastPostTime = Date::convertToTimestamp($find->updated_at);
         if (time() - $lastPostTime < static::POST_GLOBAL_DELAY) {
             // past time was less then default delay
             return false;
         }
     }
     // save new post to db
     $record = new WallRecords();
     $record->target_id = $target->id;
     $record->sender_id = $viewer->id;
     $record->message = $this->message;
     $record->save();
     // add user notification
     if ($target->id !== $viewer->id) {
         $notify = new EntityAddNotification($target->id);
         $notify->add('profile/show/' . $target->id . '#wall-post-' . $record->id, EntityAddNotification::MSG_ADD_WALLPOST, ['snippet' => Text::snippet($this->message, 50)]);
     }
     // cleanup message
     $this->message = null;
     return true;
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function make()
 {
     // update readed marker
     $this->_post->readed = 1;
     $this->_post->save();
     // add new answer row in database
     $record = new FeedbackAnswer();
     $record->feedback_id = $this->_post->id;
     $record->name = $this->name;
     $record->email = $this->email;
     $record->message = $this->message;
     $record->user_id = $this->_userId;
     $record->is_admin = 1;
     $record->ip = $this->_ip;
     $record->save();
     // add user notification
     if ((int) $this->_post->user_id > 0 && $this->_userId !== (int) $this->_post->user_id) {
         $notify = new EntityAddNotification((int) $this->_post->user_id);
         $uri = '/feedback/read/' . $this->_post->id . '/' . $this->_post->hash . '#feedback-answer-' . $record->id;
         $notify->add($uri, EntityAddNotification::MSG_ADD_FEEDBACKANSWER, ['snippet' => Text::snippet($this->message, 50), 'post' => Text::snippet($this->_post->message, 50)]);
     }
     // send email notification
     $this->sendEmail($this->_post);
     // unset message data
     $this->message = null;
 }
Beispiel #3
0
 /**
  * Add new row to database and set post is unreaded
  */
 public function make()
 {
     // update readed marker
     $this->_post->readed = 0;
     $this->_post->save();
     // add new answer row in database
     $record = new FeedbackAnswer();
     $record->feedback_id = $this->_post->id;
     $record->name = $this->name;
     $record->email = $this->email;
     $record->message = $this->message;
     if ($this->_userId > 0) {
         $record->user_id = $this->_userId;
     }
     $record->ip = $this->_ip;
     $record->save();
     // add notification msg
     $targetId = $this->_post->user_id;
     if ($targetId !== null && (int) $targetId > 0 && $targetId !== $this->_userId) {
         $notify = new EntityAddNotification($targetId);
         $uri = '/feedback/read/' . $this->_post->id . '/' . $this->_post->hash . '#feedback-answer-' . $record->id;
         $notify->add($uri, EntityAddNotification::MSG_ADD_FEEDBACKANSWER, ['snippet' => Text::snippet($this->message, 50), 'post' => Text::snippet($this->_post->message, 50)]);
     }
 }
Beispiel #4
0
 /**
  * Add comment answer to database and return active record object
  * @return CommentAnswer
  */
 public function buildRecord()
 {
     $record = new CommentAnswer();
     $record->comment_id = $this->replayTo;
     $record->user_id = $this->_userId;
     $record->guest_name = $this->guestName;
     $record->message = $this->message;
     $record->lang = App::$Request->getLanguage();
     $record->ip = $this->ip;
     // check if premoderation is enabled and user is guest
     if ((bool) $this->_configs['guestModerate'] && $this->_userId < 1) {
         $record->moderate = 1;
     }
     $record->save();
     // add notification for comment post owner
     $commentPost = $record->getCommentPost();
     if ($commentPost !== null && (int) $commentPost->user_id !== 0 && (int) $commentPost->user_id !== $this->_userId) {
         $notify = new EntityAddNotification((int) $commentPost->user_id);
         $notify->add($commentPost->pathway, EntityAddNotification::MSG_ADD_COMMENTANSWER, ['snippet' => Text::snippet($this->message, 50), 'post' => Text::snippet($commentPost->message, 50)]);
     }
     return $record;
 }
Beispiel #5
0
 /**
  * Add new post answer from AJAX post
  * @param int $postId
  * @return string
  * @throws ForbiddenException
  * @throws NativeException
  */
 public function actionSendwallanswer($postId)
 {
     // not auth? what are you doing there? ;)
     if (!App::$User->isAuth()) {
         throw new ForbiddenException('Auth required');
     }
     // no post id? wtf you doing man!
     if (!Obj::isLikeInt($postId) || $postId < 1) {
         throw new NativeException('Wrong input data');
     }
     // get current(sender) user object
     $viewer = App::$User->identity();
     // get message from post and validate minlength
     $message = $this->request->get('message');
     $message = App::$Security->strip_tags($message);
     if (!Obj::isString($message) || Str::length($message) < 3) {
         throw new ForbiddenException('Wrong input data');
     }
     // try to find this post
     $wallPost = WallPost::where('id', '=', $postId);
     if ($wallPost->count() < 1) {
         throw new NativeException('Wrong input data');
     }
     $wallRow = $wallPost->first();
     $target_id = $wallRow->target_id;
     // check if in blacklist
     if (!Blacklist::check($viewer->id, $target_id)) {
         throw new ForbiddenException('User is blocked!');
     }
     // check delay between user last post and current
     $lastAnswer = WallAnswer::where('user_id', '=', App::$User->identity()->getId())->orderBy('created_at', 'DESC')->first();
     if (null !== $lastAnswer && false !== $lastAnswer) {
         $now = time();
         $answerTime = Date::convertToTimestamp($lastAnswer->created_at);
         $cfgs = \Apps\ActiveRecord\App::getConfigs('app', 'Profile');
         // hmm, maybe past less then delay required?
         if ($now - (int) $cfgs['delayBetweenPost'] < $answerTime) {
             throw new ForbiddenException('Delay between answers not pass');
         }
     }
     // make new row ;)
     $answers = new WallAnswer();
     $answers->post_id = $postId;
     $answers->user_id = $viewer->id;
     $answers->message = $message;
     $answers->save();
     // add notification for target user
     if ($viewer->id !== $target_id) {
         $notify = new EntityAddNotification($target_id);
         $notify->add('/profile/show/' . $target_id . '#wall-post-' . $wallRow->id, EntityAddNotification::MSG_ADD_WALLANSWER, ['snippet' => Text::snippet($message, 50), 'post' => $wallRow->message]);
     }
     // send "ok" response
     $this->setJsonHeader();
     return json_encode(['status' => 1, 'message' => 'ok']);
 }