public function execute() { if (!$this->items) { return $this->items; } // cache teamblogs EB::cache()->insertTeams($this->items); $teams = array(); // Load up the blogs model $model = EB::model('TeamBlogs'); // Get the current user's group id's $gid = EB::getUserGids(); foreach ($this->items as $item) { $team = EB::table('TeamBlog'); $team->load($item->id); // Check if the logged in user is a member of the group $team->isMember = $team->isMember($this->my->id, $gid); $team->isActualMember = $team->isMember($this->my->id, $gid, false); $team->members = $model->getAllMembers($team->id, 5); // total member count ( including actual members and users from asociated joomla group.) $team->memberCount = $team->getAllMembersCount(); // post count associated with this teamblog. $team->postCount = $team->getPostCount(); // Get the list of blog posts form this team $blogs = array(); if ($team->access != EBLOG_TEAMBLOG_ACCESS_MEMBER || $team->isMember || EB::isSiteAdmin()) { $blogs = $model->getPosts($team->id, EASYBLOG_TEAMBLOG_LISTING_NO_POST); $blogs = EB::formatter('list', $blogs); } $team->blogs = $blogs; // Get the list of tags // $team->tags = $team->getTags(); // Get categories used in this team // $team->categories = $team->getCategories(); // Determines if the team is featured if (isset($item->isfeatured)) { $team->isFeatured = $item->isfeatured; } else { $team->isFeatured = EB::isFeatured('teamblog', $team->id); } // check if team description is emtpy or not. if yes, show default message. if (empty($team->description)) { $team->description = JText::_('COM_EASYBLOG_TEAMBLOG_NO_DESCRIPTION'); } // Determines if the viewer is subscribed to this team $team->isTeamSubscribed = $model->isTeamSubscribedEmail($team->id, $this->my->email); // If the user is subscribed, we need to get his subscription id $team->subscription_id = $team->isTeamSubscribed; $teams[] = $team; } return $teams; }
/** * Displays a list of blog posts from a specific team * * @since 4.0 * @access public * @param string * @return */ public function listings() { // Get the team id that is being accessed now $id = $this->input->get('id', 0, 'int'); $team = EB::table('TeamBlog'); $team->load($id); if (!$id || !$team->id) { return JError::raiseError(404, JText::_('COM_EASYBLOG_TEAMBLOG_INVALID_ID')); } // set meta tags for teamblog view EB::setMeta($id, META_TYPE_TEAM); $gid = EB::getUserGids(); $isMember = $team->isMember($this->my->id, $gid); $team->isMember = $isMember; $team->isActualMember = $team->isMember($this->my->id, $gid, false); // Add rss feed link if ($team->access == EBLOG_TEAMBLOG_ACCESS_EVERYONE || $team->isMember) { $this->doc->addHeadLink($team->getRSS(), 'alternate', 'rel', array('type' => 'application/rss+xml', 'title' => 'RSS 2.0')); $this->doc->addHeadLink($team->getAtom(), 'alternate', 'rel', array('type' => 'application/atom+xml', 'title' => 'Atom 1.0')); } // check if team description is emtpy or not. if yes, show default message. if (empty($team->description)) { $team->description = JText::_('COM_EASYBLOG_TEAMBLOG_NO_DESCRIPTION'); } // Set the breadcrumbs for this view $this->setViewBreadcrumb('teamblog'); $this->setPathway($team->getTitle()); // Retrieve the model $model = EB::model('TeamBlogs'); $posts = $model->getPosts($team->id); $posts = EB::formatter('list', $posts); // Get the pagination $pagination = $model->getPagination(); // Retrieve team's information $members = $model->getTeamMembers($team->id); // Determines if the team blog is featured $team->isFeatured = EB::isFeatured('teamblog', $team->id); // Set the page title $title = EB::getPageTitle($team->title); $this->setPageTitle($title, $pagination, $this->config->get('main_pagetitle_autoappend')); // Check if subscribed $isTeamSubscribed = $model->isTeamSubscribedEmail($team->id, $this->my->email); // Get the current url $return = $team->getPermalink(); $this->set('return', $return); $this->set('team', $team); $this->set('members', $members); $this->set('pagination', $pagination->getPagesLinks()); $this->set('posts', $posts); $this->set('isTeamSubscribed', $isTeamSubscribed); parent::display('teamblogs/item'); }
public static function formatBlog($data, $loadComments = false, $removeFeaturedImage = true, $loadVideo = true, $frontpage = false, $loadGallery = true) { // Ensures that we only proceed to format items if there's real data. if (!$data) { return $data; } $app = JFactory::getApplication(); $params = $app->getParams('com_easyblog'); $model = EB::model('Blog'); $config = EB::config(); // Get the tags relation model $modelPT = EB::model('PostTag'); // Initialize a default array set $result = array(); // Some benchmark says that counting it here would be faster $total = count($data); for ($i = 0; $i < $total; $i++) { $row = $data[$i]; $blog = EB::table('Blog'); $blog->bind($row); // Since the $blog object does not contain 'team_id', we need to set this here. if ($raw->source_type == EASYBLOG_POST_SOURCE_TEAM) { $blog->team_id = $row->source_id; } // Since the $blog object does not contain 'category', we need to set this here. $blog->category = $row->category; $blog->featuredImage = isset($row->featuredImage) ? $row->featuredImage : ''; // 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; $blog->isFeatured = EB::isFeatured('post', $blog->id); $blog->category = empty($blog->category) ? JText::_('COM_EASYBLOG_UNCATEGORIZED') : JText::_($blog->category); // @task: Detect password protections. $requireVerification = false; $tmpTitle = $blog->title; if ($config->get('main_password_protect', true) && !empty($blog->blogpassword)) { $blog->title = JText::sprintf('COM_EASYBLOG_PASSWORD_PROTECTED_BLOG_TITLE', $blog->title); $requireVerification = true; } // @rule: If user already authenticated with the correct password, we will hide the password if ($requireVerification && EB::verifyBlogPassword($blog->blogpassword, $blog->id)) { $blog->title = $tmpTitle; $blog->blogpassword = ''; } // @rule: Initialize all variables $blog->videos = array(); $blog->galleries = array(); $blog->albums = array(); $blog->audios = array(); // @rule: Before anything get's processed we need to format all the microblog posts first. if (!empty($blog->posttype)) { self::formatMicroblog($blog); } // @rule: Detect if the content requires a read more link. $blog->readmore = EasyBlogHelper::requireReadmore($blog); // @rule: Remove any adsense codes from the content. $blog->intro = EB::adsense()->strip($blog->intro); $blog->content = EB::adsense()->strip($blog->content); // Truncate content EB::truncateContent($blog, $loadVideo, $frontpage, $loadGallery); // Assign tags to the custom properties. $blog->tags = $modelPT->getBlogTags($blog->id); // Facebook Like integrations $facebookLike = EB::facebook()->getLikeHTML($blog); $blog->facebookLike = $facebookLike; $result[] = $blog; } return $result; }
/** * Post processing when a blog post is saved * * @since 5.0 * @access public * @param string * @return */ public function postSave() { // do not do anything if the post is a blank post. if ($this->isBlank()) { return; } // Whenever the blog post is stored, we need to clear the cache. $this->clearCache(); // Triggers plugins after the post is stored $this->triggerAfterSave(); // When this post is being submitted for approval we want to notify site administrator's if ($this->isBeingSubmittedForApproval()) { $this->notify(true, false); } // Add activity stream for Jomsocial, regardless if it is being published or not, we should let the client check this. if (!$this->isDraft() && !$this->isPending() && !$this->isScheduled()) { EB::jomsocial()->insertActivity($this); } // When this post is saved and published we need to perform the auto posting for the system if ($this->isPublished()) { EB::autoposting()->shareSystem($this); } // When this post is saved, we might need to perform the auto posting if ($this->autoposting && $this->isPublished()) { EB::autoposting()->shareUser($this, $this->autoposting); } // When this post is being published, we should add post actions here. if ($this->isBeingPublished()) { // Send notifications to subscribers if (!$this->isPasswordProtected() && !$this->saveOptions['skipNotifications']) { $this->notify(); } // EasySocial Integrations // If $this->isBeingPublished, it will be always a new post. if (!isset($this->saveOptions['saveFromEasysocialStory'])) { EB::easysocial()->createBlogStream($this, true); } EB::easysocial()->updateBlogPrivacy($this->post); EB::easysocial()->assignPoints('blog.create', $this->created_by); EB::easysocial()->notifySubscribers($this, 'new.post'); EB::easysocial()->addIndexerNewBlog($this); EB::easysocial()->assignBadge('blog.create', JText::_('COM_EASYBLOG_EASYSOCIAL_BADGE_CREATE_BLOG_POST')); // EasyDiscuss Integrations EB::easydiscuss()->log('easyblog.new.blog', $this->created_by, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_HISTORY_NEW_BLOG', $this->title)); EB::easydiscuss()->addPoint('easyblog.new.blog', $this->created_by); EB::easydiscuss()->addBadge('easyblog.new.blog', $this->created_by); EB::easydiscuss()->insertNotification('new.blog', $this); // Alpha User Points EB::aup()->assignPoints('plgaup_easyblog_add_blog', $this->created_by, JText::sprintf('COM_EASYBLOG_AUP_NEW_BLOG_CREATED', $this->getPermalink(), $this->title)); // Points should only be rewarded when the post is being published EB::jomsocial()->assignPoints('com_easyblog.blog.add', $this->created_by); // Ping to Pingomatic args: $post, $debug. EB::pingomatic()->ping($this, false); // Automatically feature the blog post if required $isFeaturedAuthor = EB::isFeatured('blogger', $this->created_by); $isFeaturedPost = EB::isFeatured('post', $this->id); if ($this->config->get('main_autofeatured', 0) && $isFeaturedAuthor && !$isFeaturedPost) { $this->setFeatured('post', $this->id); } } else { if ($this->isPublished()) { // This action is an edit post EB::easysocial()->createBlogStream($this, false); } } // When the post is approved, we want to notify the author if ($this->isBeingApproved()) { // We do not need to notify the world that the post is published because it's already handled above under $this->notify(false, '1', false, true); } // When this post is being unpublished, we should add triggers here. if ($this->isBeingUnpublished()) { // If the post is being unpublished, remove them from the stream EB::jomsocial()->removePostStream($this); } // When this post is rejected by the moderator, we should add triggers here if ($this->isBeingRejected()) { // When a post is rejected, add the necessary data on the reject table so we can determine why it's being rejected $reject = EB::table('PostReject'); $reject->post_id = $this->id; $reject->created_by = $this->created_by; $reject->created = EB::date()->toSql(); // @TODO: How should we get the reject message from the composer? $reject->message = $this->input->get('message', '', 'default'); $reject->store(); // Send notify $reject->notify(); } }
/** * Stores the blog post * * @since 5.0 * @access public * @param string * @return */ public function store($log = true) { // Load language file from the front end. EB::loadLanguages(); // Whenever the blog post is stored, we need to clear the cache. $cache = EB::getCache(); $cache->clean('com_easyblog'); $cache->clean('_system'); $cache->clean('page'); // Get easyblog's config $config = EB::config(); // Get the current logged in user. $my = JFactory::getUser(); // @rule: no guest allowed to create blog post. if (JRequest::getVar('task', '') != 'cron' && JRequest::getVar('task', '') != 'cronfeed' && empty($my->id)) { $this->setError(JText::_('COM_EASYBLOG_YOU_ARE_NOT_LOGIN')); return false; } $under_approval = false; if (isset($this->under_approval)) { $under_approval = true; // now we need to reset this variable from the blog object. unset($this->under_approval); } // @trigger: onBeforeSave $this->triggerBeforeSave(); // @rule: Determine if this record is new or not. if (empty($this->isnew)) { $isNew = empty($this->id) ? true : false; } else { $isNew = true; } // @rule: Get the rulesets for this user. $acl = EB::acl(); // @rule: Process badword filters for title here. $blockedWord = EasyBlogHelper::getHelper('String')->hasBlockedWords($this->title); if ($blockedWord !== false) { $this->setError(JText::sprintf('COM_EASYBLOG_BLOG_TITLE_CONTAIN_BLOCKED_WORDS', $blockedWord)); return false; } // @rule: Check for minimum words in the content if required. if ($config->get('main_post_min') && $this->_checkLength) { $minimum = $config->get('main_post_length'); $total = JString::strlen(strip_tags($this->intro . $this->content)); if ($total < $minimum) { $this->setError(JText::sprintf('COM_EASYBLOG_CONTENT_LESS_THAN_MIN_LENGTH', $minimum)); return false; } } // @rule: Check for invalid title if (empty($this->title) || $this->title == JText::_('COM_EASYBLOG_DASHBOARD_WRITE_DEFAULT_TITLE')) { $this->setError(JText::_('COM_EASYBLOG_DASHBOARD_SAVE_EMPTY_TITLE_ERROR')); return false; } // @rule: For edited blogs, ensure that they have permissions to edit it. if (!$isNew && $this->created_by != JFactory::getUser()->id && !EasyBlogHelper::isSiteAdmin() && !$acl->get('moderate_entry')) { // @task: Only throw error when this blog post is not a team blog post and it's not owned by the current logged in user. $model = EB::model('TeamBlogs'); $contribution = $model->getBlogContributed($this->id); if (!$contribution || !$model->checkIsTeamAdmin(JFactory::getUser()->id, $contribution->team_id)) { $this->setError(JText::_('COM_EASYBLOG_NO_PERMISSION_TO_EDIT_BLOG')); return false; } } // Filter / strip contents that are not allowed $filterTags = EasyBlogHelper::getHelper('Acl')->getFilterTags(); $filterAttributes = EasyBlogHelper::getHelper('Acl')->getFilterAttributes(); // @rule: Apply filtering on contents jimport('joomla.filter.filterinput'); $inputFilter = JFilterInput::getInstance($filterTags, $filterAttributes, 1, 1, 0); $inputFilter->tagBlacklist = $filterTags; $inputFilter->attrBlacklist = $filterAttributes; $filterTpe = EasyBlogHelper::getJoomlaVersion() >= '1.6' ? 'html' : 'string'; if (count($filterTags) > 0 && !empty($filterTags[0]) || count($filterAttributes) > 0 && !empty($filterAttributes[0])) { $this->intro = $inputFilter->clean($this->intro, $filterTpe); $this->content = $inputFilter->clean($this->content, $filterTpe); } // @rule: Process badword filters for content here. $blockedWord = EasyBlogHelper::getHelper('String')->hasBlockedWords($this->intro . $this->content); if ($blockedWord !== false) { $this->setError(JText::sprintf('COM_EASYBLOG_BLOG_POST_CONTAIN_BLOCKED_WORDS', $blockedWord)); return false; } // @rule: Test for the empty-ness if (empty($this->intro) && empty($this->content)) { $this->setError(JText::_('COM_EASYBLOG_DASHBOARD_SAVE_CONTENT_ERROR')); } $state = parent::store(); $source = JRequest::getVar('blog_contribute_source', 'easyblog'); // if this is blog edit, then we should see the column isnew to determine // whether the post is really new or not. if (!$isNew) { $isNew = $this->isnew; } // this one is needed for the trigger to work properly. $this->isnew = $isNew; // @trigger: onAfterSave $this->triggerAfterSave(); // @task: If auto featured is enabled, we need to feature the blog post automatically since the blogger is featured. if ($config->get('main_autofeatured', 0) && EB::isFeatured('blogger', $this->created_by) && !EB::isFeatured('post', $this->id)) { // just call the model file will do as we do not want to create stream on featured action at this migration. $modelF = EB::model('Featured'); $modelF->makeFeatured('post', $this->id); } // @task: This is when the blog is either created or updated. if ($source == 'easyblog' && $state && $this->published == EASYBLOG_POST_PUBLISHED && $log) { $category = EB::table('Category'); $category->load($this->category_id); $easysocial = EasyBlogHelper::getHelper('EasySocial'); if ($category->private == 0) { // @rule: Add new stream item in jomsocial EB::jomsocial()->addBlogActivity($this, $isNew); } // @rule: Add stream for easysocial if ($config->get('integrations_easysocial_stream_newpost') && $easysocial->exists() && $isNew) { $easysocial->createBlogStream($this, $isNew); } // update privacy in easysocial. if ($config->get('integrations_easysocial_privacy') && $easysocial->exists()) { $easysocial->updateBlogPrivacy($this); } } if ($source == 'easyblog' && $state && $this->published == EASYBLOG_POST_PUBLISHED && $isNew && $log) { // @rule: Send email notifications out to subscribers. $author = EB::user($this->created_by); // Ping pingomatic EB::pingomatic()->ping($this); // Assign EasySocial points $easysocial = EasyBlogHelper::getHelper('EasySocial'); if ($easysocial->exists()) { $easysocial->assignPoints('blog.create', $this->created_by); } // @rule: Add userpoints for jomsocial if ($config->get('main_jomsocial_userpoint')) { $path = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'userpoints.php'; if (JFile::exists($path)) { require_once $path; CUserPoints::assignPoint('com_easyblog.blog.add', $this->created_by); } } $link = $this->getExternalBlogLink('index.php?option=com_easyblog&view=entry&id=' . $this->id); // @rule: Add notifications for jomsocial 2.6 if ($config->get('integrations_jomsocial_notification_blog')) { // Get list of users who subscribed to this blog. $target = $this->getRegisteredSubscribers('new', array($this->created_by)); EasyBlogHelper::getHelper('JomSocial')->addNotification(JText::sprintf('COM_EASYBLOG_JOMSOCIAL_NOTIFICATIONS_NEW_BLOG', str_replace("administrator/", "", $author->getProfileLink()), $author->getName(), $link, $this->title), 'easyblog_new_blog', $target, $author, $link); } // Get list of users who subscribed to this blog. // @rule: Add notifications for easysocial if ($config->get('integrations_easysocial_notifications_newpost') && $easysocial->exists()) { $easysocial->notifySubscribers($this, 'new.post'); } // @rule: Add indexer for easysocial if ($config->get('integrations_easysocial_indexer_newpost') && $easysocial->exists()) { $easysocial->addIndexerNewBlog($this); } // @rule: Integrations with EasyDiscuss EasyBlogHelper::getHelper('EasyDiscuss')->log('easyblog.new.blog', $this->created_by, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_HISTORY_NEW_BLOG', $this->title)); EasyBlogHelper::getHelper('EasyDiscuss')->addPoint('easyblog.new.blog', $this->created_by); EasyBlogHelper::getHelper('EasyDiscuss')->addBadge('easyblog.new.blog', $this->created_by); // Assign badge for users that report blog post. // Only give points if the viewer is viewing another person's blog post. EasyBlogHelper::getHelper('EasySocial')->assignBadge('blog.create', JText::_('COM_EASYBLOG_EASYSOCIAL_BADGE_CREATE_BLOG_POST')); if ($config->get('integrations_easydiscuss_notification_blog')) { // Get list of users who subscribed to this blog. $target = $this->getRegisteredSubscribers('new', array($this->created_by)); EasyBlogHelper::getHelper('EasyDiscuss')->addNotification($this, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_NOTIFICATIONS_NEW_BLOG', $author->getName(), $this->title), EBLOG_NOTIFICATIONS_TYPE_BLOG, $target, $this->created_by, $link); } // AUP EB::aup()->assignPoints('plgaup_easyblog_add_blog', $this->created_by, JText::sprintf('COM_EASYBLOG_AUP_NEW_BLOG_CREATED', $this->getPermalink(), $this->title)); // Update the isnew column so that if user edits this entry again, it doesn't send any notifications the second time. $this->isnew = $this->published && $this->isnew ? 0 : 1; $this->store(false); } return $state; }
/** * Determines if the team is featured * * @since 4.0 * @access public * @param string * @return */ public function isFeatured() { $featured = EB::isFeatured('teamblog', $this->id); return $featured; }