Пример #1
0
 /**
  * Render the likes into a string.
  *
  * @param Collection $likesCollection  The likes to render.
  *
  * @param string     $viewAllLikesLink The link to view all of the likes for the content.
  *
  * @return string
  */
 public function render(Collection $likesCollection, $viewAllLikesLink)
 {
     $numLikesToList = $this->settings->get('posts.likes_to_show', 3);
     $numOtherLikes = $likesCollection->count() - $numLikesToList;
     $userId = $this->guard->user()->getAuthIdentifier();
     $likes = [];
     $likesCollection = $likesCollection->filter(function (Like $like) use(&$likes, &$numLikesToList, $userId) {
         if ($like->user->id === $userId) {
             $like->user->name = $this->lang->get('likes.current_user');
             $likes[] = $like;
             $numLikesToList--;
             return false;
         }
         return true;
     });
     $numLikesInCollection = $likesCollection->count();
     if ($numLikesInCollection > 0 && $numLikesToList > 0) {
         if ($numLikesInCollection < $numLikesToList) {
             $numLikesToList = $numLikesInCollection;
         }
         $randomLikes = $likesCollection->random($numLikesToList);
         if (!is_array($randomLikes)) {
             // random returns a single model if $numLikesToList is 1...
             $randomLikes = array($randomLikes);
         }
         foreach ($randomLikes as $key => $like) {
             $likes[] = $like;
         }
     }
     return $this->viewFactory->make('likes.list', compact('numOtherLikes', 'likes', 'viewAllLikesLink'))->render();
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function getForUser(User $user)
 {
     return $this->conversationModel->join('conversation_users', function ($join) use($user) {
         $join->on('conversation_users.conversation_id', '=', 'conversations.id');
         $join->where('conversation_users.user_id', '=', $user->id);
     })->where('conversation_users.has_left', false)->where('conversation_users.ignores', false)->orderBy('last_message_id', 'desc')->paginate($this->settings->get('user.topics_per_page', 20));
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function supported()
 {
     // NoCaptcha is supported when we have a public and private key
     if ($this->settings->get('captcha.nocaptcha_public_key', '') == '' || $this->settings->get('captcha.nocaptcha_private_key', '') == '') {
         return false;
     }
     return true;
 }
Пример #4
0
 /**
  * Shows the Index Page
  *
  * @param Store $settings
  *
  * @return \Illuminate\View\View
  */
 public function index(Store $settings)
 {
     // Forum permissions are checked in "getIndexTree" and "getNewest"
     $forums = $this->forumRepository->getIndexTree();
     $topics = $this->topicRepository->getNewest();
     $users = $this->userRepository->online($settings->get('wio.minutes', 15), 'name', 'asc', 0);
     return view('forum.index', compact('forums', 'topics', 'users'));
 }
Пример #5
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $this->app->setLocale($this->settings->get('user.language', 'en'));
     $langDir = ['left' => 'left', 'right' => 'right'];
     if (trans('general.direction') == 'rtl') {
         $langDir['left'] = 'right';
         $langDir['right'] = 'left';
     }
     $this->viewFactory->share('langDir', $langDir);
     return $next($request);
 }
Пример #6
0
 /**
  * @return bool
  */
 public function isOnline()
 {
     $minutes = $this->settings->get('wio.minutes', 15);
     // This user was logging out at last
     if ($this->wrappedObject->last_page == 'auth/logout') {
         return false;
     }
     // This user isn't online
     if (new \DateTime($this->wrappedObject->last_visit) < new \DateTime("{$minutes} minutes ago")) {
         return false;
     }
     // The user is online, now permissions
     // We're either testing our own account or have permissions to view everyone
     if ($this->permissionChecker->hasPermission('user', null, 'canViewAllOnline') || $this->guard->user()->id == $this->wrappedObject->id) {
         return true;
     }
     // Next we need to get the setting for this user
     // First get the id of our setting
     $settingId = Setting::where('name', 'user.showonline')->first()->id;
     // Now the value
     $settingValue = SettingValue::where('user_id', '=', $this->wrappedObject->id)->where('setting_id', '=', $settingId)->first();
     // Either the value isn't set (good) or true (better), let's show this user as online
     if ($settingValue == null || $settingValue->value == true) {
         return true;
     }
     // Still here? Then the viewing user doesn't have the permissions and we show him as offline
     return false;
 }
Пример #7
0
 /**
  * @param string $captchaName
  *
  * @return CaptchaInterface|null
  *
  * @throws CaptchaInvalidClassException
  */
 private function getCaptchaClass($captchaName)
 {
     if ($captchaName == false) {
         $captchaName = $this->settings->get('captcha.method', static::NONE);
     }
     if ($captchaName === static::NONE) {
         return null;
     }
     $captchaClass = 'MyBB\\Core\\Captcha\\Captcha' . ucfirst($captchaName);
     if (!class_exists($captchaClass)) {
         return null;
     }
     $captcha = $this->app->make($captchaClass);
     if (!$captcha || !$captcha instanceof CaptchaInterface || !$captcha->supported()) {
         throw new CaptchaInvalidClassException($captchaClass);
     }
     return $captcha;
 }
Пример #8
0
 /**
  * Get all posts for a thread.
  *
  * @param Topic $topic       The thread to fetch the posts for.
  * @param bool  $withTrashed Find trashed posts?
  *
  * @return mixed
  */
 public function allForTopic(Topic $topic, $withTrashed = false)
 {
     $postsPerPage = $this->settings->get('user.posts_per_page', 10);
     $baseQuery = $this->postModel->with(['author', 'likes'])->where('topic_id', '=', $topic->id);
     if ($withTrashed) {
         $baseQuery = $baseQuery->withTrashed();
     }
     return $baseQuery->paginate($postsPerPage);
 }
Пример #9
0
 /**
  * SHow all of the likes a post has received.
  *
  * @param int $postId The ID of the post to show the likes for.
  *
  * @return \Illuminate\View\View
  */
 public function getPostLikes($postId)
 {
     $post = $this->postsRepository->find($postId);
     if (!$post) {
         throw new PostNotFoundException();
     }
     $post->load('topic');
     $likes = $this->likesRepository->getAllLikesForContentPaginated($post, $this->settings->get('likes.per_page', 10));
     return view('post.likes', compact('post', 'likes'));
 }
Пример #10
0
 /**
  * Get all threads within a forum.
  *
  * @param Forum  $forum    The forum the threads belong to.
  * @param string $orderBy  The order by column
  * @param string $orderDir asc|desc
  *
  * @return mixed
  */
 public function allForForum(Forum $forum, $orderBy = 'posts.created_at', $orderDir = 'desc')
 {
     // Build the correct order_by column - nice versions may be submitted
     switch ($orderBy) {
         case 'replies':
             $orderBy = 'num_posts';
             break;
         case 'startdate':
             $orderBy = 'topics.created_at';
             break;
         case 'lastpost':
         default:
             $orderBy = 'posts.created_at';
             break;
     }
     $topicsPerPage = $this->settings->get('user.topics_per_page', 20);
     return $this->topicModel->withTrashed()->with(['author', 'lastPost', 'lastPost.author'])->leftJoin('posts', 'last_post_id', '=', 'posts.id')->where('forum_id', '=', $forum->id)->orderBy($orderBy, $orderDir)->paginate($topicsPerPage, ['topics.*']);
 }
Пример #11
0
 /**
  * @param int|string|\DateTime|TransDate $date
  *
  * @return TransDate
  *
  * @throws DateInvalidObjectException
  */
 private function getDateObject($date)
 {
     // We've already a valid date object. Don't set the timezone, it may get messy otherwise
     if ($date instanceof TransDate) {
         return $date;
     }
     // If it's a valid date format or a DateTime object we can simply call the constructor
     if (is_int($date) || @strtotime($date) !== false || $date == null || $date instanceof \DateTime) {
         $date = new TransDate($date);
     } else {
         throw new DateInvalidObjectException();
     }
     // Figure out our timezone
     $timezone = $this->settings->get('user.timezone', 'default');
     if ($timezone == 'default') {
         $timezone = trans('general.timezone');
     }
     return $date->setTimezone($timezone);
 }
Пример #12
0
 /**
  * @param Store  $settings
  * @param string $slug
  * @param int    $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function last(Store $settings, $slug = '', $id = 0)
 {
     // Forum permissions are checked in "find"
     $topic = $this->topicRepository->find($id);
     if (!$topic) {
         throw new TopicNotFoundException();
     }
     $postsPerPage = $settings->get('user.posts_per_page', 10);
     $numPost = $this->postRepository->getNumForPost($topic->lastPost, true);
     if (ceil($numPost / $postsPerPage) == 1) {
         return redirect()->route('topics.show', ['slug' => $topic->slug, 'id' => $topic->id, '#post-' . $topic->last_post_id]);
     } else {
         return redirect()->route('topics.show', ['slug' => $topic->slug, 'id' => $topic->id, 'page' => ceil($numPost / $postsPerPage), '#post-' . $topic->last_post_id]);
     }
 }
Пример #13
0
 /**
  *  Check Setting
  *
  * @param  \Illuminate\Http\Request $request
  *
  * @return Boolean True if setting is true
  */
 protected function checkSetting($request)
 {
     $action = $request->route()->getAction();
     $setting = $action['setting'];
     return $this->settings->get($setting, null, false);
 }
Пример #14
0
 /**
  * @param int          $id
  * @param ReplyRequest $request
  * @param Store        $settings
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postReply($id, ReplyRequest $request, Store $settings)
 {
     $this->failedValidationRedirect = route('conversations.read', ['id' => $id]);
     /** @var Conversation $conversation */
     $conversation = $this->conversationRepository->find($id);
     if (!$conversation || !$conversation->participants->contains($this->guard->user())) {
         throw new ConversationNotFoundException();
     }
     $message = $this->conversationMessageRepository->addMessageToConversation($conversation, ['author_id' => $this->guard->user()->id, 'message' => $request->input('message')]);
     if ($message) {
         $page = 1;
         if ($settings->get('conversations.message_order', 'desc') == 'asc') {
             $page = (int) ($conversation->messages->count() / $settings->get('user.posts_per_page', 10)) + 1;
         }
         return redirect()->route('conversations.read', ['id' => $conversation->id, 'page' => $page]);
     }
     return redirect()->route('conversations.read', ['id' => $conversation->id])->withInput()->withErrors(['content' => 'Error']);
 }
Пример #15
0
 /**
  * @param Store $settings
  *
  * @return \Illuminate\View\View
  */
 public function online(Store $settings)
 {
     $users = $this->userRepository->online($settings->get('wio.minutes', 15));
     return view('member.online', compact('users'));
 }
 /**
  * {@inheritdoc}
  */
 public function getAllForConversation(Conversation $conversation)
 {
     return $this->conversationMessageModel->where('conversation_id', $conversation->id)->orderBy('created_at', $this->settings->get('conversations.message_order', 'desc'))->paginate($this->settings->get('user.posts_per_page', 10));
 }
Пример #17
0
 /**
  * @param Request $request
  * @param Store   $settings
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postPrivacy(Request $request, Store $settings)
 {
     $this->validate($request, ['showonline' => 'boolean', 'receive_messages' => 'boolean', 'block_blocked_messages' => 'boolean', 'hide_blocked_posts' => 'boolean', 'only_buddy_messages' => 'boolean', 'receive_email' => 'boolean', 'dob_privacy' => 'required|in:0,1,2', 'dob_visibility' => 'required|in:0,1,2']);
     $input = $request->except(['_token']);
     $input['showonline'] = isset($input['showonline']);
     $input['receive_messages'] = isset($input['receive_messages']);
     $input['block_blocked_messages'] = isset($input['block_blocked_messages']);
     $input['hide_blocked_posts'] = isset($input['hide_blocked_posts']);
     $input['only_buddy_messages'] = isset($input['only_buddy_messages']);
     $input['receive_email'] = isset($input['receive_email']);
     // Prefix all settings with "user."
     $modifiedSettings = [];
     foreach ($input as $key => $value) {
         $modifiedSettings["user.{$key}"] = $value;
     }
     $settings->set($modifiedSettings, null, true);
     return redirect()->route('account.privacy')->withSuccess(trans('account.saved_privacy'));
 }