_module = 'Core'; $this->_name = 'Latest Profile Posts'; $this->_description = 'Display the latest profile posts on your site.'; $this->_engine = $engine; $this->_language = $language; $this->_cache = $cache; $this->_user = $user; $this->_timeago = $timeago; } public function initialise(): void { // Generate HTML code for widget if ($this->_user->isLoggedIn()) { $user_id = $this->_user->data()->id; } else { $user_id = 0; } $this->_cache->setCache('profile_posts_widget'); $posts_array = $this->_cache->fetch('profile_posts_' . $user_id, function () { if ($this->_user->isLoggedIn()) { if ($this->_user->hasPermission('profile.private.bypass')) { $posts = DB::getInstance()->query('SELECT * FROM nl2_user_profile_wall_posts ORDER BY `time` DESC LIMIT 5')->results(); } else { $posts = DB::getInstance()->query( <<results(); } } else { $posts = DB::getInstance()->query( <<results(); } $posts_array = []; foreach ($posts as $post) { $post_author = new User($post->author_id); $post_user = new User($post->user_id); $content = EventHandler::executeEvent(new RenderContentEvent($post->content))->content; $link = rtrim($post_user->getProfileURL(), '/'); $posts_array[] = [ 'avatar' => $post_author->getAvatar(), 'username' => $post_author->getDisplayname(), 'username_style' => $post_author->getGroupStyle(), 'content' => Text::truncate(strip_tags($content), 20), 'link' => $link . '/#post-' . $post->id . '/', 'date_ago' => date(DATE_FORMAT, $post->time), 'user_id' => $post->author_id, 'user_profile_link' => $post_author->getProfileURL(), 'ago' => $this->_timeago->inWords($post->time, $this->_language) ]; } return $posts_array; }, 120); if (count($posts_array) >= 1) { $this->_engine->addVariables([ 'PROFILE_POSTS_ARRAY' => $posts_array ]); } $this->_engine->addVariables([ 'LATEST_PROFILE_POSTS' => $this->_language->get('user', 'latest_profile_posts'), 'NO_PROFILE_POSTS' => $this->_language->get('user', 'no_profile_posts') ]); $this->_content = $this->_engine->fetch('widgets/profile_posts'); } }