public function reportBlog() { $app = JFactory::getApplication(); // Get the composite keys $log_user = $this->plugin->get('user')->id; $id = $app->input->get('id', 0, 'int'); $type = $app->input->get('type', '', 'POST'); $reason = $app->input->get('reason', '', 'STRING'); if (!$reason) { $message = "Reason is empty"; $final_result['message'] = $message; $final_result['status'] = false; return $final_result; } $report = EB::table('Report'); $report->obj_id = $id; $report->obj_type = $type; $report->reason = $reason; $report->created = EB::date()->toSql(); $report->created_by = $log_user; $state = $report->store(); if (!$state) { $message = "Cant store your report"; $final_result['message'] = $message; $final_result['status'] = false; return $final_result; } // Notify the site admin when there's a new report made $post = EB::post($id); $report->notify($post); $final_result['message'] = "Report logged successfully!"; $final_result['status'] = true; return $final_result; }
/** * Saves a new rating item * * @since 5.0 * @access public * @param string * @return */ public function store($updateNulls = false) { $config = EB::config(); $state = parent::store(); if ($this->type == 'entry' && $this->created_by) { // Load the post item $post = EB::post($this->uid); // Get the author of the post $author = $post->getAuthor(); // Get the link to the post $link = $post->getExternalPermalink(); // Notify EasySocial users that someone rated their post EB::easysocial()->notifySubscribers($post, 'ratings.add'); // Assign EasySocial points EB::easysocial()->assignPoints('blog.rate'); EB::easysocial()->assignPoints('blog.rated', $post->created_by); // Assign badge for users that report blog post. // Only give points if the viewer is viewing another person's blog post. EB::easysocial()->assignBadge('blog.rate', JText::_('COM_EASYBLOG_EASYSOCIAL_BADGE_RATED_BLOG')); // Assign points for AUP EB::aup()->assign('plgaup_easyblog_rate_blog', '', 'easyblog_rating', JText::_('COM_EASYBLOG_AUP_BLOG_RATED')); // Add notifications for EasyDiscuss // Add notifications // EB::jomsocial()->addNotification(JText::sprintf('COM_EASYBLOG_JOMSOCIAL_NOTIFICATIONS_NEW_RATING_FOR_YOUR_BLOG', str_replace("administrator/","", $author->getProfileLink()), $author->getName() , $link , $blog->title), 'easyblog_new_blog' , $target , $author , $link); // Add notifications for easydiscuss if ($config->get('integrations_jomsocial_notification_rating')) { $target = array($post->created_by); EB::easydiscuss()->addNotification($post, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_NOTIFICATIONS_NEW_RATING_FOR_YOUR_BLOG', $author->getName(), $post->title), EBLOG_NOTIFICATIONS_TYPE_RATING, array($post->created_by), $this->created_by, $link); } } return $state; }
public function reject() { // Check for request forgeries EB::checkToken(); // Ensure that user is logged in EB::requireLogin(); // Get any return url $return = EB::_('index.php?option=com_easyblog&view=dashboard&layout=moderate'); if ($this->getReturnURL()) { $return = $this->getReturnURL(); } // Check if the user is privileged enough if (!$this->acl->get('add_entry') && !$this->acl->get('manage_pending')) { return JError::raiseError(500, JText::_('COM_EASYBLOG_NO_PERMISSION_TO_MODERATE_BLOG')); } // Get a list of ids $ids = $this->input->get('ids', array(), 'array'); $message = $this->input->get('message', '', 'default'); foreach ($ids as $id) { $id = (int) $id; $post = EB::post($id); $post->reject($message); } $message = JText::_('COM_EASYBLOG_BLOGS_BLOG_SAVE_REJECTED'); $this->info->set($message, 'success'); return $this->app->redirect($return); }
public function load($cid) { static $instances = array(); if (!isset($instances[$cid])) { $this->_item = EB::post($cid); if (!$this->_item) { return $this->onLoadArticleError($cid); } $blogger = EB::user($this->_item->created_by); $this->_item->blogger = $blogger; $link = 'index.php?option=com_easyblog&view=entry&id=' . $this->getContentId(); // forcefully get item id if request is ajax $format = JRequest::getString('format', 'html'); if ($format === 'ajax') { $itemid = JRequest::getInt('pageItemId'); if (!empty($itemid)) { $link .= '&Itemid=' . $itemid; } } $link = EBR::_($link); $this->_item->permalink = $this->prepareLink($link); $instances[$cid] = $this->_item; } $this->_item = $instances[$cid]; return $this; }
public function display($tmpl = null) { // Ensure that the user is logged in. EB::requireLogin(); // null = new post // 63 = post 63 from post table // 63.2 = post 63, revision 2 from history table $uid = $this->input->getVar('uid', null); // If no id given, create a new post. $post = EB::post($uid); // Verify access (see function manager()) if (!$post->canCreate() && !$post->canEdit()) { // Do not allow user to access this page if he doesn't have access JError::raiseError(500, JText::_('COM_EASYBLOG_NOT_ALLOWED_ACCESS_IN_THIS_SECTION')); return; } // If there's no id provided, we will need to create the initial revision for the post. if (!$uid) { $post->create(); $uid = $post->uid; } // Determines if we should show the sidebars by default $templateId = $this->input->get('block_template', 0, 'int'); if (!$post->title) { $this->doc->setTitle(JText::_('COM_EASYBLOG_COMPOSER_POST_UNTITLED')); } $composer = EB::composer(); // Render default post templates $postTemplatesModel = EB::model('Templates'); $postTemplates = $postTemplatesModel->getPostTemplates($this->my->id); $this->set('postTemplates', $postTemplates); $this->set('composer', $composer); $this->set('post', $post); return parent::display('composer/default'); }
public function display($tmpl = null) { JPluginHelper::importPlugin('easyblog'); $dispatcher = JDispatcher::getInstance(); $mainframe = JFactory::getApplication(); $document = JFactory::getDocument(); $config = EasyBlogHelper::getConfig(); //for trigger $params = $mainframe->getParams('com_easyblog'); $joomlaVersion = EasyBlogHelper::getJoomlaVersion(); $blogId = $this->input->get('id', 0, 'int'); if (empty($blogId)) { return JError::raiseError(404, JText::_('COM_EASYBLOG_BLOG_NOT_FOUND')); } $my = JFactory::getUser(); $blog = EB::table('Blog'); $blog->load($blogId); $post = EB::post($blogId); // Check if blog is password protected. $protected = $this->isProtected($post); if ($protected !== false) { return; } // If the blog post is already deleted, we shouldn't let it to be accessible at all. if ($post->isTrashed()) { return JError::raiseError(404, JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); } // Check if the blog post is trashed if (!$post->isPublished() && $this->my->id != $post->created_by && !EB::isSiteAdmin()) { return JError::raiseError(404, JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); } // Check for team's privacy $allowed = $this->checkTeamPrivacy($post); if ($allowed === false) { return JError::raiseError(404, JText::_('COM_EASYBLOG_TEAMBLOG_MEMBERS_ONLY')); } // Check if the blog post is accessible. $accessible = $post->isAccessible(); if (!$accessible->allowed) { echo $accessible->error; return; } // Format the post $post = EB::formatter('entry', $post); $tags = $post->getTags(); $theme = EB::template(); $theme->set('post', $post); $theme->set('tags', $tags); $blogHtml = $theme->output('site/blogs/entry/pdf'); $pageTitle = EasyBlogHelper::getPageTitle($config->get('main_title')); $document->setTitle($post->title . $pageTitle); $document->setName($post->getPermalink()); // Fix phoca pdf plugin. if (method_exists($document, 'setArticleText')) { $document->setArticleText($blogHtml); } echo $blogHtml; return; }
public function execute() { if ($this->cache) { // Cache data and preload posts EB::cache()->insert($this->items); } // For list items we wouldn't want to process comments $comment = true; // For list items we do not want to load videos $video = false; // For list items we do not want to process gallery $gallery = false; // Result $result = array(); // Load up the tags model $tagsModel = EB::model('PostTag'); foreach ($this->items as $item) { $post = EB::post($item->id); $blog = new stdClass(); // Post details $blog->id = $post->id; $blog->title = $post->title; $blog->intro = $post->getIntro(); $blog->content = $post->getContent(); $blog->content_plain = $this->sanitize($blog->content); $blog->image = $post->getImage('thumbnail'); $blog->created = $post->created; $blog->hits = $post->hits; $blog->permalink = $post->getPermalink(true, true, 'json'); // Get the author details $author = $post->getAuthor(); $blog->author = new stdClass(); $blog->author->name = $author->getName(); $blog->author->avatar = $author->getAvatar(); // Get the tags for this post $tags = $post->getTags(); $blog->tags = array(); if ($tags) { foreach ($tags as $tag) { $item = new stdClass(); $item->title = $tag->getTitle(); $item->permalink = $tag->getExternalPermalink('json'); $blog->tags[] = $item; } } // Get the category details $category = $post->getPrimaryCategory(); $blog->category = new stdClass(); $blog->category->id = $category->id; $blog->category->title = $category->getTitle(); $blog->category->avatar = $category->getAvatar(); $blog->category->permalink = $category->getExternalPermalink('json'); $result[] = $blog; } return $result; }
public static function getPosts(&$params) { $config = EB::config(); $count = (int) $params->get('count', 0); // Retrieve the model from the component. $model = EB::model('Blog'); $categories = trim($params->get('catid')); $type = !empty($categories) ? 'category' : ''; if (!empty($categories)) { $categories = explode(',', $categories); } $sorting = array(); $sorting[] = $params->get('sorting', 'latest'); $sorting[] = $params->get('ordering', 'desc'); $rows = $model->getBlogsBy($type, $categories, $sorting, $count, EBLOG_FILTER_PUBLISHED, null, false); $posts = array(); // Retreive settings from params $maxWidth = $params->get('imagewidth', 300); $maxHeight = $params->get('imageheight', 200); foreach ($rows as $data) { $row = EB::post($data->id); $row->bind($data); $row->media = ''; //var_dump($row->image); if (!empty($row->image)) { $media = $row->getImage('thumbnail'); $imgHtml = $media; $row->media = $imgHtml; } else { $image = self::getImage($row->intro . $row->content); if ($image !== false) { // TODO: Here's where we need to crop the image based on the cropping ratio provided in the params. // Currently this is just a lame hack to fix the width and height $pattern = '/<\\s*img [^\\>]*src\\s*=\\s*[\\""\']?([^\\""\'>]*)/i'; preg_match($pattern, $image, $matches); $imageurl = ''; if ($matches) { $imageurl = isset($matches[1]) ? $matches[1] : ''; } if (!empty($imageurl)) { // $imgHtml = '<img title="'.$row->title.'" src="' . $imageurl . '" style="width: '. $maxWidth . 'px !important;height: '. $maxHeight . 'px !important;" />'; $imgHtml = $imageurl; $row->media = $imgHtml; } else { $row->media = $image; } } } if (!empty($row->media)) { $posts[] = $row; } } return $posts; }
/** * Default method to format normal posts * * @since 5.0 * @access public * @param string * @return */ public function execute() { // Result $result = array(); // Cache data and preload posts if ($this->cache) { EB::cache()->insert($this->items); } // Preload all featured posts for posts $featuredItems = array(); // Do a simple test to see if preload featured items is require or not if (!isset($this->items[0]->featured)) { $featuredItems = $this->preloadFeaturedItems(); } $i = 0; foreach ($this->items as $item) { // Load up the post library $post = EB::post(); $post->load($item->id); // Get the list of categories for this particular blog post $post->category = $post->getPrimaryCategory(); $post->categories = $post->getCategories(); // @Assign dynamic properties that must exist everytime formatBlog is called // We can't rely on ->author because CB plugins would mess things up. $post->author = $post->getAuthor(); // Determines if the blog post is featured if (isset($item->featured)) { $post->isFeatured = $item->featured; } else { if (isset($featuredItems[$post->id])) { $post->isFeatured = $featuredItems[$post->id]; } else { $post->isFeatured = 0; } } // Password verifications $this->password($post); // Get custom fields $post->fields = $post->getCustomFields(); // Format microblog postings if ($post->posttype) { $this->formatMicroblog($post); } else { $post->posttype = 'standard'; } // Assign tags to the custom properties. $post->tags = $post->getTags(); // Prepare nice date for the list $post->date = EB::date($post->created)->format(JText::_('DATE_FORMAT_LC')); $result[] = $post; $i++; } return $result; }
public function execute() { if ($this->cache) { //preload posts information EB::cache()->insert($this->items); } // For featured items we wouldn't want to process comments $comment = true; // For featured items we want to remove featured image $removeFeaturedImage = true; // For featured items we do not want to load videos $video = false; // For featured items we do not want to process gallery $gallery = false; // Ensure that the content does not exceed the introtext limit for featured items $contentLimit = $this->config->get('layout_featured_intro_limit'); $result = array(); foreach ($this->items as &$item) { $blog = EB::post($item->id); // Load the author's profile $author = EB::user($blog->created_by); // @Assign dynamic properties that must exist everytime formatBlog is called // We can't rely on ->author because CB plugins would mess things up. $blog->author = $author; $blog->blogger = $author; // Password verifications $this->password($blog); // Format microblog postings if ($blog->posttype) { $this->formatMicroblog($blog); } // Detect if content requires read more link $blog->readmore = $this->hasReadmore($blog); // // Truncate content // $this->truncate($blog); // EB::truncateContent($blog, $loadVideo, $frontpage, $loadGallery); // Format the content for the featured items if (empty($blog->intro)) { $blog->intro = $blog->content; } // We wouldn't want to display html codes in the content $blog->intro = strip_tags($blog->intro); // Get the content length $length = JString::strlen($blog->intro); if ($length > $contentLimit) { $blog->intro = JString::substr($blog->intro, 0, $contentLimit); } // Prepare nice date for the featured area $blog->date = EB::date($blog->created)->format(JText::_('DATE_FORMAT_LC')); $result[] = $blog; } return $result; }
public function execute() { if ($this->cache) { //preload posts information EB::cache()->insert($this->items); } // For featured items we wouldn't want to process comments $comment = true; // For featured items we want to remove featured image $removeFeaturedImage = true; // For featured items we do not want to load videos $video = false; // For featured items we do not want to process gallery $gallery = false; // Ensure that the content does not exceed the introtext limit for featured items $contentLimit = $this->config->get('layout_featured_intro_limit'); $result = array(); foreach ($this->items as &$item) { $blog = EB::post($item->id); // Load the author's profile $author = EB::user($blog->created_by); // @Assign dynamic properties that must exist everytime formatBlog is called // We can't rely on ->author because CB plugins would mess things up. $blog->author = $author; $blog->blogger = $author; // Password verifications $this->password($blog); // Format microblog postings if ($blog->posttype) { $this->formatMicroblog($blog); } // Get featured image if ($blog->hasImage()) { $blog->image = $blog->getImage($this->config->get('cover_featured_size', 'large')); } else { $tmp = $blog->getContentImage(); if ($tmp) { $blog->image = $tmp; } else { $blog->image = ''; } } // Detect if content requires read more link $blog->readmore = $this->hasReadmore($blog); // Prepare nice date for the featured area $blog->date = EB::date($blog->created)->format(JText::_('DATE_FORMAT_LC')); $result[] = $blog; } return $result; }
/** * Allows visitor to approve a comment * * @since 5.0 * @access public */ public function moderate() { // Get the hash key $key = $this->input->get('key', '', 'default'); // Default redirection url $redirect = EBR::_('index.php?option=com_easyblog', false); if (!$key) { $this->info->set('COM_EASYBLOG_NOT_ALLOWED', 'error'); return $this->app->redirect($redirect); } // Get the hashkey from the site $hashkey = EB::table('Hashkeys'); $state = $hashkey->loadByKey($key); // If the key doesn't exist, it may no longer be a valid request if (!$state || !$hashkey->id) { $this->info->set('COM_EASYBLOG_NOT_ALLOWED', 'error'); return $this->app->redirect($redirect); } // Load the comment now $comment = EB::table('Comment'); $comment->load($hashkey->uid); // Get the task to perform $task = $this->getTask(); // Load up the post library $post = EB::post($comment->post_id); if ($task == 'approve') { $comment->published = EBLOG_COMMENT_PUBLISHED; // Save the comment now $comment->store(true); // Process the mails for comments now $comment->processEmails(false, $post); // Update the sent flag for the comment $comment->updateSent(); } if ($task == 'reject') { $comment->published = EBLOG_COMMENT_UNPUBLISHED; $comment->store(true); } // Delete the unused hashkey now. $hashkey->delete(); $message = 'COM_EASYBLOG_MODERATE_COMMENT_PUBLISHED_SUCCESS'; if ($task == 'reject') { $message = 'COM_EASYBLOG_MODERATE_COMMENT_UNPUBLISHED_SUCCESS'; } $this->info->set($message, 'success'); // Get the permalink to the post $permalink = $post->getPermalink(false); return $this->app->redirect($permalink); }
/** * Displays the post selection form * * @since 5.0 * @access public * @param string * @return */ protected function getInput() { $title = JText::_('COM_EASYBLOG_MENU_SELECT_POST_TITLE'); if ($this->value) { $post = EB::post($this->value); $title = $post->title; } $theme = EB::template(); $theme->set('id', $this->id); $theme->set('name', $this->name); $theme->set('value', $this->value); $theme->set('title', $title); $output = $theme->output('admin/elements/post'); return $output; }
/** * Processes scheduled blog posts to be published * * @since 4.0 * @access public * @param string * @return */ public function publish() { // Retrieve a list of scheduled posts $model = EB::model('Blogs'); $items = $model->getScheduledPosts(); if (!$items) { return EB::exception('No scheduled posts to process currently.', EASYBLOG_MSG_INFO); } foreach ($items as $item) { $post = EB::post($item->id); // We know that all scheduled posts regardless if the author has access to publish or not should be published. // Since pending posts that are being scheduled needs to be approved by the admin first. $options = array('checkAcl' => false); $post->publish($options); } }
/** * Main display for the blog entry view * * @since 4.0 * @access public * @param string * @return */ public function display($tpl = null) { // Get the blog post id from the request $id = $this->input->get('id', 0, 'int'); // Load the blog post now $post = EB::post($id); // If blog id is not provided correctly, throw a 404 error page if (!$id || !$post->id) { return JError::raiseError(404, JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); } // If the settings requires the user to be logged in, do not allow guests here. if ($this->my->guest && $this->config->get('main_login_read')) { return EB::requireLogin(); } // Check if blog is password protected. $protected = $this->isProtected($post); if ($protected !== false) { return; } // If the blog post is already deleted, we shouldn't let it to be accessible at all. if ($post->isTrashed()) { return JError::raiseError(404, JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); } // Check if the blog post is trashed if (!$post->isPublished() && $this->my->id != $post->created_by && !EB::isSiteAdmin()) { return JError::raiseError(404, JText::_('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND')); } // Check for team's privacy $allowed = $this->checkTeamPrivacy($post); if ($allowed === false) { return JError::raiseError(404, JText::_('COM_EASYBLOG_TEAMBLOG_MEMBERS_ONLY')); } // Check if the blog post is accessible. $accessible = $post->isAccessible(); if (!$accessible->allowed) { echo $accessible->error; return; } // Increment the hit counter for the blog post. $post->hit(); // Format the post $post = EB::formatter('entry', $post); $theme = EB::template(); $theme->set('post', $post); $output = $theme->output('site/blogs/entry/default.print'); echo $output; }
public function display($tmpl = null) { // this is to handle the backend if (JFactory::getApplication()->isAdmin() && method_exists($this, $this->getLayout())) { $layoutName = $this->getLayout(); return $this->{$layoutName}(); } JHTML::_('behavior.modal'); // Ensure that the user is logged in. EB::requireLogin(); // null = new post // 63 = post 63 from post table // 63.2 = post 63, revision 2 from history table $uid = $this->input->getVar('uid', null); // If no id given, create a new post. $post = EB::post($uid); // Do not allow normal user to edit the existing post if there is already another revision that was submitted for approvals. if (!EB::isSiteAdmin() && !$this->acl->get('moderate_entry') && $post->hasRevisionWaitingForApproval()) { JError::raiseError(500, JText::_('COM_EASYBLOG_NOT_ALLOWED_TO_EDIT_ANOTHER_REVISION_PENDING_APPROVAL')); return; } // Verify access (see function manager()) if (!$post->canCreate() && !$post->canEdit()) { // Do not allow user to access this page if he doesn't have access JError::raiseError(500, JText::_('COM_EASYBLOG_NOT_ALLOWED_ACCESS_IN_THIS_SECTION')); return; } // If there's no id provided, we will need to create the initial revision for the post. if (!$uid) { $post->create(); $uid = $post->uid; } // Determines if we should show the sidebars by default $templateId = $this->input->get('block_template', 0, 'int'); if (!$post->title) { $this->doc->setTitle(JText::_('COM_EASYBLOG_COMPOSER_POST_UNTITLED')); } $composer = EB::composer(); // Render default post templates $postTemplatesModel = EB::model('Templates'); $postTemplates = $postTemplatesModel->getPostTemplates($this->my->id); $this->set('postTemplates', $postTemplates); $this->set('composer', $composer); $this->set('post', $post); return parent::display('composer/default'); }
/** * Processes scheduled blog posts to be published * * @since 4.0 * @access public * @param string * @return */ public function publish() { // Retrieve a list of scheduled posts $model = EB::model('Blogs'); $items = $model->getScheduledPosts(); if (!$items) { return EB::exception('No scheduled posts to process currently.', EASYBLOG_MSG_INFO); } // Get the current date $date = EB::date(); // Allowed autopost $autopost = array(EBLOG_OAUTH_LINKEDIN, EBLOG_OAUTH_FACEBOOK, EBLOG_OAUTH_TWITTER); foreach ($items as $item) { $post = EB::post($item->id); $post->publish(); } }
/** * Retrieves a list of subscribers for a particular blog post * * @since 5.0 * @access public * @param string * @return */ public function getBlogSubscriberEmails(&$emails = array(), $blogId) { $post = EB::post($blogId); // Get subscribers $subscribers = $post->getSubscribers(); if (!$subscribers) { return $emails; } foreach ($subscribers as $row) { $obj = new stdClass(); if (!isset($row->type)) { $row->type = 'subscription'; } $obj->unsubscribe = EB::getUnsubscribeLink($row, true); $obj->email = $row->email; $emails[$row->email] = $obj; } }
/** * Allows caller to vote on an imte * * @since 4.0 * @access public * @param string * @return */ public function vote() { // Get the type of the ratings $type = $this->input->get('type', '', 'cmd'); // Get the blog post object $id = $this->input->get('id', 0, 'int'); $post = EB::post($id); if (!$post->id || !$id) { return $this->ajax->reject(); } // If the blog post is password protected we shouldn't do anything if ($post->isPasswordProtected()) { return $this->ajax->reject(); } // Load up the rating table $rating = EB::table('Ratings'); // Get the user's session $session = JFactory::getSession(); // Do not allow guest to vote, or if the voter already voted. $exists = $rating->load(array('created_by' => $this->my->id, 'uid' => $post->id, 'type' => $type, 'sessionid' => $session->getId())); if ($exists || $this->my->guest && !$this->config->get('main_ratings_guests')) { return $this->ajax->reject(); } // Get the rating value $value = $this->input->get('value', 0, 'int'); // Set the ratings property $rating->created_by = $this->my->id; $rating->type = $type; $rating->uid = $post->id; $rating->ip = @$_SERVER['REMOTE_ADDR']; $rating->value = $value; $rating->sessionid = $session->getId(); $rating->created = EB::date()->toSql(); $rating->published = true; $rating->store(); // Get the final rating value $model = EB::model('Ratings'); $ratingValue = $model->getRatingValues($post->id, $type); $total = $ratingValue->total; $rating = $ratingValue->ratings; $message = JText::_('COM_EASYBLOG_RATINGS_RATED_THANK_YOU'); return $this->ajax->resolve($total, $message, $rating); }
/** * Retrieve custom fields based on the category * * @since 4.0 * @access public * @param string * @return */ public function getCustomFields() { // Get the category id $id = $this->input->get('id', 0, 'int'); $postId = $this->input->get('postId', 0, 'int'); $post = EB::post($postId); // @TODO: Check if the user can render the forms // Load up the model $model = EB::model('Categories'); // Retrieve the custom field group since each category can only have 1 group $group = $model->getCustomFieldGroup($id); // Retrieve the custom fields forms $fields = $model->getCustomFields($id); $theme = EB::template(); $theme->set('post', $post); $theme->set('id', $id); $theme->set('group', $group); $theme->set('fields', $fields); $output = $theme->output('site/composer/form/fields'); return $this->ajax->resolve($output); }
/** * Notifies the author when a post is rejected * * @since 5.0 * @access public * @param string * @return */ public function notify() { // $post = EB::table('Post'); $post = EB::post(); $post->load($this->post_id); // Get the author $author = $this->getAuthor(); $data = array(); $data['blogTitle'] = $post->title; $data['blogAuthor'] = $author->getName(); $data['blogAuthorAvatar'] = $author->getAvatar(); $data['blogEditLink'] = $post->getEditLink(false); $data['blogAuthorEmail'] = $author->user->email; $data['rejectMessage'] = $this->message; $subject = JText::_('COM_EASYBLOG_EMAIL_TITLE_NEW_BLOG_REJECTED'); $obj = new stdClass(); $obj->unsubscribe = false; $obj->email = $author->user->email; $emails = array($obj); $notification = EB::notification(); return $notification->send($emails, $subject, 'post.rejected', $data); }
/** * Allows caller to submit a report * * @since 4.0 * @access public * @param string * @return */ public function submit() { // Check for request forgeries EB::checkToken(); // Get the composite keys $id = $this->input->get('id', 0, 'int'); $type = $this->input->get('type', '', 'cmd'); // Initialize redirection link $redirect = EB::_('index.php?option=com_easyblog&view=entry&id=' . $id, false); // Check if guest is allowed to report or not. if ($this->my->guest && !$this->config->get('main_reporting_guests')) { $this->info->set('COM_EASYBLOG_CATEGORIES_FOR_REGISTERED_USERS_ONLY', 'error'); return $this->app->redirect($redirect); } // Ensure that the report reason is not empty. $reason = $this->input->get('reason', '', 'default'); if (!$reason) { EB::info()->set(JText::_('COM_EASYBLOG_REPORT_PLEASE_SPECIFY_REASON'), 'error'); return $this->app->redirect($redirect); } $report = EB::table('Report'); $report->obj_id = $id; $report->obj_type = $type; $report->reason = $reason; $report->created = EB::date()->toSql(); $report->created_by = $this->my->id; $report->ip = @$_SERVER['REMOTE_ADDR']; $state = $report->store(); if (!$state) { $this->info->set($report->getError()); return $this->app->redirect($redirect); } // Notify the site admin when there's a new report made $post = EB::post($id); $report->notify($post); $message = JText::_('COM_EASYBLOG_THANKS_FOR_REPORTING'); $this->info->set($message, 'success'); return $this->app->redirect($redirect); }
/** * Allows caller to search for posts * * @since 5.0 * @access public * @param string * @return */ public function search() { $query = $this->input->get('query', '', 'word'); $model = EB::model('Search'); $result = $model->searchText($query); if (!$result) { return $this->ajax->resolve($result); } $posts = array(); foreach ($result as $item) { $post = EB::post(); $post->bind($item, array('force' => true)); // Set a formatted date $post->formattedDate = EB::date($post->created)->format(JText::_('DATE_FORMAT_LC2')); $post->intro = $post->getIntro(true); $post->permalink = $post->getExternalPermalink(); $posts[] = $post; } $theme = EB::template(); $theme->set('posts', $posts); $output = $theme->output('site/composer/posts/post'); return $this->ajax->resolve($output); }
/** * Retrieves the place title * * @since 5.0 * @access public * @param string * @return */ public static function getPlaceName($placeId) { $placeName = $placeId; if (self::isUserPlace($placeId)) { $my = JFactory::getUser(); // Title should be dependent if the user is viewing their own media $id = explode(':', $placeId); $user = JFactory::getUser($id[1]); if ($my->id != $user->id) { return $user->name; } $placeName = 'user'; } // If this is an article place if (self::isPostPlace($placeId)) { // Get the post id $id = explode(':', $placeId); $post = EB::post($id[1]); if (!$post->title) { return JText::sprintf('COM_EASYBLOG_MM_PLACE_POST_UNTITLED', $id[1]); } return $post->title; } // If this is an album place if (self::isAlbumPlace($placeId)) { $parts = explode('/', $placeId); $placeName = $placeId; if ($parts > 1) { $placeName = $parts[0]; } } return JText::_('COM_EASYBLOG_MM_PLACE_' . strtoupper($placeName)); }
/** * Main method to import the feed items * * @since 4.0 * @access public * @param string * @return */ public function import(EasyBlogTableFeed &$feed, $limit = 0) { // Load site language file EB::loadLanguages(); // Import simplepie library jimport('simplepie.simplepie'); // We need DomDocument to exist if (!class_exists('DomDocument')) { return false; } // Set the maximum execution time to a higher value @ini_set('max_execution_time', 720); // Get the feed params $params = EB::registry($feed->params); // Determines the limit of items to fetch $limit = $limit ? $limit : $params->get('feedamount', 0); // Setup the outgoing connection to the feed source $connector = EB::connector(); $connector->addUrl($feed->url); $connector->execute(); // Get the contents $contents = $connector->getResult($feed->url); // If contents is empty, we know something failed if (!$contents) { return EB::exception(JText::sprintf('COM_EASYBLOG_FEEDS_UNABLE_TO_REACH_TARGET_URL', $feed->url), EASYBLOG_MSG_ERROR); } // Get the cleaner to clean things up $cleaner = $this->getAdapter('Cleaner'); $contents = $cleaner->cleanup($contents); // Load up the xml parser $parser = new SimplePie(); $parser->strip_htmltags(false); $parser->set_raw_data($contents); @$parser->init(); // Get a list of items // We need to supress errors here because simplepie will throw errors on STRICT mode. $items = @$parser->get_items(); if (!$items) { // TODO: Language string return EB::exception('COM_EASYBLOG_FEEDS_NOTHING_TO_BE_IMPORTED_CURRENTLY', EASYBLOG_MSG_ERROR); } // Get the feeds model $model = EB::model('Feeds'); // Determines the total number of items migrated $total = 0; foreach ($items as $item) { // If it reaches limit, skip processing if ($limit && $total == $limit) { break; } // Get the item's unique id $uid = @$item->get_id(); // If item already exists, skip this if ($model->isFeedItemImported($feed->id, $uid)) { continue; } // Log down a new history record to avoid fetching of the same item again $history = EB::table('FeedHistory'); $history->feed_id = $feed->id; $history->uid = $uid; $history->created = EB::date()->toSql(); $history->store(); // Get the item's link $link = @$item->get_link(); // Load up the post library $post = EB::post(); $createOption = array('overrideDoctType' => 'legacy', 'checkAcl' => false, 'overrideAuthorId' => $feed->item_creator); $post->create($createOption); // Pass this to the adapter to map the items $mapper = $this->getAdapter('Mapper'); $mapper->map($post, $item, $feed, $params); // Now we need to get the content of the blog post $mapper->mapContent($post, $item, $feed, $params); $saveOptions = array('applyDateOffset' => false, 'validateData' => false, 'useAuthorAsRevisionOwner' => true, 'checkAcl' => false, 'overrideAuthorId' => $feed->item_creator); // Try to save the blog post now try { $post->save($saveOptions); // Update the history table $history->post_id = $post->id; $history->store(); $total++; } catch (EasyBlogException $exception) { // do nothing. } } return EB::exception(JText::sprintf('COM_EASYBLOG_FEEDS_POSTS_MIGRATED_FROM_FEED', $total, $feed->url), EASYBLOG_MSG_SUCCESS); }
/** * Responsible to display the entire component output * * @since 4.0 * @access public * @param string * @return */ public function display($tpl = null) { if ($this->doc->getType() == 'html') { // Render headers on the site $this->renderHeaders(); // Get the contents from the view $namespace = 'site/' . $tpl; $contents = $this->theme->output($namespace); // Get menu suffix $suffix = $this->getMenuSuffix(); // Get the current view. $view = $this->getName(); // Get the current task $layout = $this->getLayout(); // If this is a dashboard theme, we need to let the theme object know $options = array(); if ($this->getName() == 'dashboard') { $options['dashboard'] = true; } // We need to append the contents back into the main structure $theme = EB::template(null, $options); // $theme = $this->theme; $tmpl = $this->input->get('tmpl'); // Get the toolbar $toolbar = ''; if ($tmpl != 'component' && $view == 'dashboard') { $toolbar = $this->getDashboardToolbar(); } if ($tmpl != 'component' && $view != 'dashboard') { $toolbar = $this->getToolbar(); } if ($view == 'entry' && $layout != 'preview') { $id = $this->input->get('id', 0, 'int'); $post = EB::post($id); if (!$post->isStandardSource()) { $contribution = $post->getBlogContribution(); $contributionHeader = $contribution->getHeader(); if ($contributionHeader) { $toolbar = ''; } } } // Get the theme name $themeName = $theme->getName(); // There is a possibility that the site uses a different font heading $headingFont = $this->getHeadingFont(); // We attach the script tags on the bottom of the page $scripts = EB::helper('Scripts')->getScripts(); // Jomsocial toolbar $jsToolbar = EB::jomsocial()->getToolbar(); $theme->set('jsToolbar', $jsToolbar); $lang = JFactory::getLanguage(); $rtl = $lang->isRTL(); if ($rtl) { $this->doc->addStyleSheet(JURI::root() . 'components/com_easyblog/themes/' . $themeName . '/styles/style-rtl.css'); } $theme->set('rtl', $rtl); $theme->set('bootstrap', ''); $theme->set('themeName', $themeName); $theme->set('headingFont', $headingFont); $theme->set('jscripts', $scripts); $theme->set('toolbar', $toolbar); $theme->set('contents', $contents); $theme->set('suffix', $suffix); $theme->set('layout', $layout); $theme->set('view', $view); $output = $theme->output('site/structure/default'); echo $output; return; } if ($this->doc->getType() == 'json') { // Determines if the json result should be wrapped with a callback. $callback = $this->input->get('callback', '', 'cmd'); $output = json_encode($this->props); if ($callback) { $output = $callback . '(' . $output . ')'; } header('Content-type: text/x-json; UTF-8'); echo $output; exit; } // dump($tpl); }
/** * Saves a blog post * * @since 5.0 * @access public * @param string * @return */ public function save() { try { $this->verifyAccess(); } catch (EasyBlogException $exception) { return $this->ajax->reject($exception); } // Get uid & data $uid = $this->input->get('uid'); $data = $this->input->getArray('post'); // Contents needs to be raw $data['content'] = $this->input->get('content', '', 'raw'); $data['document'] = $this->input->get('document', '', 'raw'); // Load up the post library $post = EB::post($uid); $post->bind($data, array()); // Default options $options = array(); // since this is a form submit and we knwo the date that submited already with the offset timezone. we need to reverse it. $options['applyDateOffset'] = true; // check if this is a 'Apply' action or not. $isApply = $this->input->get('isapply', false, 'bool'); // For autosave requests we do not want to run validation on it. $autosave = $this->input->get('autosave', false, 'bool'); if ($autosave) { $options['validateData'] = false; } // Notify that post is successfully $message = $isApply ? 'COM_EASYBLOG_POST_APPLIED_SUCCESS' : 'COM_EASYBLOG_POST_SAVED_SUCCESS'; $state = EASYBLOG_MSG_SUCCESS; if (!$post->isNew()) { $message = $isApply ? 'COM_EASYBLOG_POST_APPLIED_SUCCESS' : 'COM_EASYBLOG_POST_UPDATED_SUCCESS'; $state = EASYBLOG_MSG_INFO; } // Save post try { $post->save($options); } catch (EasyBlogException $exception) { // Reject if there is an error while saving post return $this->ajax->reject($exception); } // If this is being submitted for approval if ($post->isBeingSubmittedForApproval()) { $message = 'COM_EASYBLOG_POST_SUBMITTED_FOR_APPROVAL'; $state = EASYBLOG_MSG_WARNING; } // If this is a draft post. if ($post->isDraft()) { $message = 'COM_EASYBLOG_POST_SAVED_FOR_LATER_SUCCESS'; $state = EASYBLOG_MSG_INFO; } // For autosave if ($autosave) { $date = EB::date(); $date->setTimezone(); $message = JText::sprintf('COM_EASYBLOG_POST_AUTOMATICALLY_SAVED_AT', $date->format(JText::_('COM_EASYBLOG_COMPOSER_AUTOSAVE_TIME_FORMAT'), true)); $state = EASYBLOG_MSG_SUCCESS; } $exception = EB::exception($message, $state); // Resolve with post data $data = $post->toData(); // Reduces number of slashes. // TODO: Should this be part of toData(); $data->revision->content = json_decode($data->revision->content); // Determines if the current page load should be loading from block templates $postTemplate = EB::table('PostTemplate'); $postTemplate->load($this->input->get('block_template', 0, 'int')); if (!$postTemplate->id || $postTemplate->id == 1) { $postTemplate = false; } // Generate the revision status html codes $theme = EB::template(); $theme->set('post', $post); $theme->set('workingRevision', $post->getWorkingRevision()); $theme->set('revisions', $post->getRevisions()); $theme->set('postTemplate', $postTemplate); $revisionStatus = $theme->output('site/composer/panel/revisions/list'); // Get the post's edit url $editLink = $post->getEditLink(false); // Get the post's preview url $previewLink = $post->getPreviewLink(false); return $this->ajax->resolve($data, $exception, $revisionStatus, $editLink, $previewLink); }
public function migrate($wpBlogId) { $session = JFactory::getSession(); $migrateStat = $session->get('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG'); if (empty($migrateStat)) { $migrateStat = new stdClass(); $migrateStat->blog = 0; $migrateStat->category = 0; $migrateStat->user = array(); } // Get item based on $wpBlogId $items = $this->getItem($wpBlogId); // If no item to migrate, just return if (!$items) { return $this->ajax->resolve('noitem'); } foreach ($items as $item) { // step 1 : create categery if not exist in eblog_categories // step 2 : create user if not exists in eblog_users - create user through profile jtable load method. $date = EB::date(); $blogObj = new stdClass(); // Create category if this item's category does not exist on the site //$wpTableNamePrex = ($wpBlogId == '1') ? '' : $wpBlogId . '_'; // Get the easyblog category Id $categoryId = $this->getEasyblogCategory(); $blogObj->category_id = $categoryId; // this is needed because posy lib actually use this to create the post - category relations $blogObj->categories = array($categoryId); //load user profile $profile = EB::user($item->post_author); //assigning blog data $blogObj->created_by = $profile->id; $blogObj->created = !empty($item->post_date) ? $item->post_date : $date->toMySQL(); $blogObj->modified = $date->toMySQL(); $blogObj->title = $item->post_title; $blogObj->permalink = $item->post_title; // post lib will take care of the normalization of permalink /* replacing [caption] and [gallery] */ // Migrate caption $item = $this->migrateCaption($item); $blogObj->intro = $item->post_excerpt; $blogObj->content = $item->post_content; //translating the article state into easyblog publish status. $blogState = '0'; $isPrivate = '0'; if ($item->post_status == 'private') { $isPrivate = '1'; $blogState = '1'; } else { if ($item->post_status == 'publish') { $isPrivate = '0'; $blogState = '1'; } } $blogObj->blogpassword = $item->post_password; $blogObj->access = $isPrivate; $blogObj->published = $blogState; $blogObj->publish_up = !empty($item->post_date) ? $item->post_date : $date->toMySQL(); $blogObj->publish_down = '0000-00-00 00:00:00'; $blogObj->ordering = 0; $blogObj->hits = 0; $blogObj->frontpage = 1; $blogObj->allowcomment = $item->comment_status == 'open' ? 1 : 0; // lets create blank post which are legacy type. $post = EB::post(); $post->create(array('overrideDoctType' => 'legacy')); // now let get the uid $blogObj->uid = $post->uid; $blogObj->revision_id = $post->revision->id; // binding $post->bind($blogObj, array()); $saveOptions = array('applyDateOffset' => false, 'validateData' => false, 'useAuthorAsRevisionOwner' => true); $post->save($saveOptions); // add tags. $wpPostTag = $this->getWPTerms($item->id, 'post_tag'); // Migrate tag if (count($wpPostTag) > 0) { foreach ($wpPostTag as $tag) { $this->migrateTag($tag, $post); } } // Migrate comments $this->migrateComment($post, $item); //update session value $migrateStat->blog++; $statUser = $migrateStat->user; $statUserObj = null; if (!isset($statUser[$profile->id])) { $statUserObj = new stdClass(); $statUserObj->name = $profile->nickname; $statUserObj->blogcount = 0; } else { $statUserObj = $statUser[$profile->id]; } $statUserObj->blogcount++; $statUser[$profile->id] = $statUserObj; $migrateStat->user = $statUser; $session->set('EBLOG_MIGRATOR_JOOMLA_STAT', $migrateStat, 'EASYBLOG'); //log the entry into migrate table. $migratorTable = EB::table('Migrate'); $migratorTable->content_id = $item->id; $migratorTable->post_id = $post->id; $migratorTable->session_id = $session->getToken(); $migratorTable->component = 'com_wordpress'; $migratorTable->store(); $this->ajax->append('[data-progress-status]', JText::_('COM_EASYBLOG_MIGRATOR_MIGRATED_WORDPRESS_BLOG') . ': ' . $item->id . JText::_('COM_EASYBLOG_MIGRATOR_EASYBLOG') . ': ' . $post->id . '<br />'); } $stat = JText::_('COM_EASYBLOG_MIGRATOR_WORDPRESS_TOTAL_ARTICLE') . ' : ' . $migrateStat->blog . '<br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_WORDPRESS_TOTAL_CATEGORY') . ' : ' . $migrateStat->category . '<br />'; $this->ajax->append('[data-progress-status]', JText::_('COM_EASYBLOG_MIGRATOR_FINISHED')); $this->ajax->append('[data-progress-stat]', $stat); // we need to clear the stat variable that stored in session. $jSession = JFactory::getSession(); $jSession->set('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG'); return $this->ajax->resolve(); }
public function migrate($migrateComment, $migrateAll, $catId) { // Determine which category to import from $catId = $catId == 0 ? null : $catId; // Render Joomla's session $session = JFactory::getSession(); // Statistics $migrateStat = $session->get('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG'); if (empty($migrateStat)) { $migrateStat = new stdClass(); $migrateStat->blog = 0; $migrateStat->category = 0; $migrateStat->user = array(); } // Get the total number of items $total = $this->getTotalItems($catId); // Get the real items $items = $this->getItems($catId); // Determines if there is still items to be migrated $balance = $total - count($items); // If there's nothing to load just skip this if (!$items) { return $this->ajax->resolve('noitem'); } foreach ($items as $item) { // Create a new blog object $blogObj = new stdClass(); // Get today's date $date = EB::date(); // Create category if this item's category does not exist on the site $categoryId = $this->migrateCategory($item); // Assign the new category to the blog object $blogObj->category_id = $categoryId; // this is needed because post lib actually use this to create the post - category relations. $blogObj->categories = array($categoryId); // Create user if the user does not exist in `#__easyblog_users` $profile = EB::user($item->created_by); //assigning blog data $blogObj->created_by = $profile->id; $blogObj->created = !empty($item->created) ? $item->created : $date->toMySQL(); $blogObj->modified = $date->toMySQL(); $blogObj->title = $item->title; $blogObj->permalink = $item->alias; // post lib will take care of the normalization of permalink $blogObj->intro = $item->introtext; if (!empty($item->fulltext)) { $blogObj->content = $item->fulltext; } $blogState = $item->published == 2 || $item->published == -2 ? 0 : $item->published; $blogObj->published = $blogState; $blogObj->publish_up = !empty($item->publish_up) ? $item->publish_up : $date->toMySQL(); $blogObj->publish_down = !empty($item->publish_down) ? $item->publish_down : $date->toMySQL(); $blogObj->ordering = $item->ordering; $blogObj->hits = $item->hits; $blogObj->frontpage = 1; $blogObj->eb_language = $item->language; $blogObj->posttype = ''; $blogObj->source_id = '0'; $blogObj->source_type = EASYBLOG_POST_SOURCE_SITEWIDE; // lets create blank post which are legacy type. $post = EB::post(); $post->create(array('overrideDoctType' => 'legacy')); // now let get the uid $blogObj->uid = $post->uid; $blogObj->revision_id = $post->revision->id; // binding $post->bind($blogObj, array()); $saveOptions = array('applyDateOffset' => false, 'validateData' => false, 'useAuthorAsRevisionOwner' => true); $post->save($saveOptions); //Added video to blog content $this->migrateK2Videos($item, $post); //Migrate over the images $this->migrateK2Images($item, $post, $profile); //Get K2 Tags and map into Easyblog Tags $K2Tags = $this->getK2Tag($item->id); if ($K2Tags) { foreach ($K2Tags as $tag) { $this->mapK2Tag($tag, $item, $post); } } // if article was featured, lets mark this blog post as featured as well. if ($item->featured) { // just call the model file will do as we do not want to create stream on featured action at this migration. $modelFeatured = EB::model('Featured'); $modelFeatured->makeFeatured('post', $post->id); } //update session value $migrateStat->blog++; $statUser = $migrateStat->user; $statUserObj = null; if (!isset($statUser[$profile->id])) { $statUserObj = new stdClass(); $statUserObj->name = $profile->nickname; $statUserObj->blogcount = 0; } else { $statUserObj = $statUser[$profile->id]; } $statUserObj->blogcount++; $statUser[$profile->id] = $statUserObj; $migrateStat->user = $statUser; $session->set('EBLOG_MIGRATOR_JOOMLA_STAT', $migrateStat, 'EASYBLOG'); //log the entry into migrate table. $migratorTable = EB::table('Migrate'); $migratorTable->content_id = $item->id; $migratorTable->post_id = $post->id; $migratorTable->session_id = $session->getToken(); $migratorTable->component = 'com_k2'; $migratorTable->store(); $this->ajax->append('[data-progress-status]', JText::_('COM_EASYBLOG_MIGRATOR_MIGRATED_K2') . ': ' . $item->id . JText::_('COM_EASYBLOG_MIGRATOR_EASYBLOG') . ': ' . $post->id . '<br />'); if ($migrateComment) { $this->migrateK2Comments($item, $post); $return = array(); $return['migrate_k2_comments'] = 1; $return['k2category'] = $catId; $return = json_encode($return); } } $hasmore = false; if ($balance) { $hasmore = true; } if (!$hasmore) { $stat = JText::_('COM_EASYBLOG_MIGRATOR_K2_TOTAL_ARTICLE') . ' : ' . $migrateStat->blog . '<br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_K2_TOTAL_CATEGORY') . ' : ' . $migrateStat->category . '<br />'; $this->ajax->append('[data-progress-status]', JText::_('COM_EASYBLOG_MIGRATOR_FINISHED')); $this->ajax->append('[data-progress-stat]', $stat); // we need to clear the stat variable that stored in session. $jSession = JFactory::getSession(); $jSession->set('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG'); } return $this->ajax->resolve($hasmore); }
/** * Retrieves a list of most commented posts created by the author * * @since 4.0 * @access public * @param string * @return */ public function getMostCommentedPostByAuthor($authorId = null, $limit = 5) { $db = EB::db(); $user = JFactory::getUser($authorId); $query = array(); $query[] = 'SELECT a.*, COUNT(b.' . $db->qn('id') . ') AS ' . $db->qn('totalcomments') . ' FROM ' . $db->qn('#__easyblog_post') . ' AS a'; $query[] = 'INNER JOIN ' . $db->qn('#__easyblog_comment') . ' AS b'; $query[] = 'ON b.' . $db->qn('post_id') . ' = a.' . $db->qn('id'); $query[] = 'WHERE a.' . $db->qn('created_by') . '=' . $db->Quote($user->id); $query[] = 'AND a.' . $db->qn('published') . '=' . $db->Quote(EASYBLOG_POST_PUBLISHED); $query[] = 'AND a.' . $db->qn('state') . '=' . $db->Quote(EASYBLOG_POST_NORMAL); $query[] = 'AND b.' . $db->qn('published') . '=' . $db->Quote(1); $query[] = 'GROUP BY a.' . $db->qn('id'); $query[] = 'ORDER BY ' . $db->qn('totalcomments') . ' DESC'; $query[] = 'LIMIT 0,' . (int) $limit; $query = implode(' ', $query); $db->setQuery($query); $result = $db->loadObjectList(); if (!$result) { return $result; } $posts = array(); foreach ($result as $row) { $post = EB::post($row->id); $post->totalcomments = $row->totalcomments; $posts[] = $post; } return $posts; }