/** * Show user profile: data, wall posts, other features * @param int $userId * @return string * @throws \Ffcms\Core\Exception\SyntaxException * @throws \Ffcms\Core\Exception\NativeException * @throws NotFoundException * @throws ForbiddenException */ public function actionShow($userId) { $cfg = $this->application->configs; if ((int) $cfg['guestView'] !== 1 && !App::$User->isAuth()) { throw new ForbiddenException(__('You must login to view other profile')); } // check if target exists if (!App::$User->isExist($userId)) { throw new NotFoundException(__('This profile is not exist')); } $targetPersone = App::$User->identity($userId); // target user object instance of Apps\ActiveRecord\User $viewerPersone = App::$User->identity(); // current user object(viewer) instance of Apps\ActiveRecord\User $wallModel = null; // if current user is auth - allow to post messages on wall current user if (App::$User->isAuth() && $viewerPersone->getRole()->can('global/write')) { $wallModel = new FormWallPost(); // check if request post is done and rules validated if ($wallModel->send() && $wallModel->validate()) { // maybe in blacklist? if (!Blacklist::check($viewerPersone->getId(), $targetPersone->getId())) { App::$Session->getFlashBag()->add('error', __('This user are in your black list or you are in blacklist!')); } else { // check if message added if ($wallModel->makePost($targetPersone, $viewerPersone, (int) $cfg['delayBetweenPost'])) { App::$Session->getFlashBag()->add('success', __('The message was successful posted!')); } else { App::$Session->getFlashBag()->add('warning', __('Posting message was failed! Please, wait few seconds')); } } } } $query = $targetPersone->getWall(); // relation hasMany from users to walls // pagination and query params $wallPage = (int) $this->request->query->get('page'); $wallItems = (int) $cfg['wallPostOnPage']; $wallOffset = $wallPage * $wallItems; // build pagination $wallPagination = new SimplePagination(['url' => ['profile/show', $userId, null], 'page' => $wallPage, 'step' => $wallItems, 'total' => $query->count()]); // get wall messages $wallRecords = $query->orderBy('id', 'desc')->skip($wallOffset)->take($wallItems)->get(); return $this->view->render('show', ['user' => $targetPersone, 'viewer' => $viewerPersone, 'isSelf' => $viewerPersone !== null && $viewerPersone->id === $targetPersone->id, 'wall' => $wallModel, 'notify' => App::$Session->getFlashBag()->all(), 'wallRecords' => $wallRecords, 'pagination' => $wallPagination, 'ratingOn' => (int) $cfg['rating'] === 1]); }
/** * Send message via AJAX * @param $target_id * @return string * @throws ForbiddenException * @throws NativeException */ public function actionMessagesend($target_id) { // check if user is auth if (!App::$User->isAuth()) { throw new ForbiddenException('Auth required'); } // get current user object $user = App::$User->identity(); if (!Blacklist::check($user->id, $target_id)) { throw new ForbiddenException('In blacklist'); } // check input params $msg = App::$Security->strip_tags($this->request->get('message')); if (!Obj::isLikeInt($target_id) || $target_id < 1 || Str::length($msg) < 1) { throw new NativeException('Wrong input data'); } $this->setJsonHeader(); // try to save message $message = new Message(); $message->target_id = $target_id; $message->sender_id = $user->id; $message->message = $msg; $message->save(); return json_encode(['status' => 1]); }