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; }
/** * Responsible to format the blog posts and append neccessary data. * * @access public * @param Array $data An array of blog posts. * @param boolean $loadComments Determines whether or not to load the comments into the object. * @param boolean $removeFeaturedImage Determines whether or not to remove featured image from the content. * @param boolean $loadVideo If true, video codes will be processed. * @param boolean $frontpage Determines whether this is for the front page or not. * @return Array An array of formatted blog posts. */ public static function formatBlog($data, $loadComments = false, $removeFeaturedImage = true, $loadVideo = true, $frontpage = false, $loadGallery = true) { $app = JFactory::getApplication(); $params = $app->getParams('com_easyblog'); $model = EasyBlogHelper::getModel('Blog'); $config = EasyBlogHelper::getConfig(); // @rule: If nothing is supplied, just return the empty data. if (empty($data)) { return $data; } // @task: Get the tags relations model. $modelPT = EasyBlogHelper::getModel('PostTag'); // @task : Resultset data $result = array(); for ($i = 0; $i < count($data); $i++) { $row =& $data[$i]; $blog = EasyBlogHelper::getTable('Blog'); $blog->bind($row); // @task: Since the $blog object does not contain 'team_id', we need to set this here. if (isset($row->team_id)) { $blog->team_id = $row->team_id; } // @task: 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 : ''; $profile = EasyBlogHelper::getTable('Profile', 'Table'); $profile->load($blog->created_by); // @legacy The following variables are no longer used in 3.5 // @since 3.5 $blog->avatar = $profile->getAvatar(); $blog->avatarLink = $profile->getProfileLink(); $blog->displayName = $profile->getName(); // @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 = $profile; $blog->blogger = $profile; $blog->isFeatured = EasyBlogHelper::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 && EasyBlogHelper::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->source)) { 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 = EasyBlogGoogleAdsense::stripAdsenseCode($blog->intro); $blog->content = EasyBlogGoogleAdsense::stripAdsenseCode($blog->content); // @rule: Content truncations. EasyBlogHelper::truncateContent($blog, $loadVideo, $frontpage, $loadGallery); // @task: Legacy fix for blog posts prior to 3.5 // Remove first image from featured post if ($removeFeaturedImage && $blog->isFeatured) { $blog->text = EasyBlogHelper::removeFeaturedImage($blog->text); } // @rule: Add nofollow tags if necessary if ($config->get('main_anchor_nofollow')) { $blog->text = self::addNoFollow($blog->text); } // @rule: $limitstart variable is required by content plugins. $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); // @trigger: onEasyBlogPrepareContent JPluginHelper::importPlugin('easyblog'); EasyBlogHelper::triggerEvent('easyblog.prepareContent', $blog, $params, $limitstart); $blog->introtext = $blog->intro; // @trigger: onPrepareContent / onContentPrepare EasyBlogHelper::triggerEvent('prepareContent', $blog, $params, $limitstart); $blog->excerpt = $blog->introtext; $blog->content = $blog->text; //onPrepareContent trigger end // @rule: Assign tags to the custom properties. $blog->tags = $modelPT->getBlogTags($blog->id); // @rule: Assign total comments in this blog post. $blog->totalComments = EasyBlogHelper::getHelper('Comment')->getCommentCount($blog); $blog->comments = array(); if ($loadComments) { $blog->comments = EasyBlogHelper::getHelper('Comment')->getBlogComment($blog->id, $config->get('layout_showcommentcount', 3), 'desc', true); } $blog->event = new stdClass(); // @trigger: onContentAfterTitle / onAfterDisplayTitle $results = EasyBlogHelper::triggerEvent('afterDisplayTitle', $blog, $params, $limitstart); $blog->event->afterDisplayTitle = JString::trim(implode("\n", $results)); // @trigger: onContentAfterTitle / onAfterDisplayTitle $results = EasyBlogHelper::triggerEvent('beforeDisplayContent', $blog, $params, $limitstart); $blog->event->beforeDisplayContent = JString::trim(implode("\n", $results)); // @trigger: onContentAfterTitle / onAfterDisplayTitle $results = EasyBlogHelper::triggerEvent('afterDisplayContent', $blog, $params, $limitstart); $blog->event->afterDisplayContent = JString::trim(implode("\n", $results)); // Facebook Like integrations require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'facebook.php'; $facebookLike = EasyBlogFacebookLikes::getLikeHTML($blog); $blog->facebookLike = $facebookLike; $result[] = $blog; } return $result; }
public function notify($underApproval = false) { if (empty($this->send_notification_emails)) { return; } // @rule: Send email notifications out to subscribers. $author = EasyBlogHelper::getTable('Profile'); $author->load($this->created_by); $data['blogTitle'] = $this->title; $data['blogAuthor'] = $author->getName(); $data['blogAuthorAvatar'] = $author->getAvatar(); $data['blogAuthorLink'] = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $author->id, false, true); $data['blogAuthorEmail'] = $author->user->email; $data['blogIntro'] = $this->intro; $data['blogContent'] = $this->content; // Try to truncate introtext based on the configured settings because content is empty. if (empty($this->content)) { $obj = clone $this; $obj->readmore = EasyBlogHelper::requireReadmore($obj); EasyBlogHelper::truncateContent($obj, false, true); $data['blogIntro'] = $obj->text; } $data['blogLink'] = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $this->id, false, true); $date = EasyBlogDateHelper::dateWithOffSet($this->created); $data['blogDate'] = EasyBlogDateHelper::toFormat($date, '%A, %B %e, %Y'); // If blog post is being posted from the back end and SH404 is installed, we should just use the raw urls. $sh404exists = EasyBlogRouter::isSh404Enabled(); if (JFactory::getApplication()->isAdmin() && $sh404exists) { $data['blogLink'] = JURI::root() . 'index.php?option=com_easyblog&view=entry&id=' . $this->id; $data['blogAuthorLink'] = JURI::root() . 'index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $author->id; } $config = EasyBlogHelper::getConfig(); $emailBlogTitle = JString::substr($this->title, 0, $config->get('main_mailtitle_length')); $emailTitle = JText::sprintf('COM_EASYBLOG_EMAIL_TITLE_NEW_BLOG_ADDED_WITH_TITLE', $emailBlogTitle) . ' ...'; $notification = EasyBlogHelper::getHelper('Notification'); $emails = array(); // @rule: Fetch custom emails defined at the back end. if ($config->get('notification_blogadmin')) { if ($config->get('custom_email_as_admin')) { $notification->getCustomEmails($emails); } else { $notification->getAdminEmails($emails); } } // @task: If this blog post is a team posting, we shouldn't send notification to everyone. $model = JModel::getInstance('TeamBlogs', 'EasyBlogModel'); $contribution = $model->getBlogContributed($this->id); if ($contribution) { $team = EasyBlogHelper::getTable('TeamBlog'); $team->load($contribution->team_id); $contribution->access = $team->access; } else { $contribution = new stdClass(); $contribution->access = EBLOG_TEAMBLOG_ACCESS_EVERYONE; } // @task: This is when this blog post is posted into a team. if ($contribution && $config->get('notification_teamsubscriber') && isset($contribution->team_id)) { // @task: Send emails to users who is a member of the team $notification->getTeamUserEmails($emails, $contribution->team_id); // @task: Send emails to users who have subscribed to the team $notification->getTeamSubscriberEmails($emails, $this); } // @task: Only send emails to these group of users provided that, it is not a team posting or private team posting. if (!$contribution || $contribution->access != EBLOG_TEAMBLOG_ACCESS_MEMBER) { // @rule: Get all email addresses for the whole site. if ($config->get('notification_allmembers')) { $notification->getAllEmails($emails); } else { // @rule: Send to subscribers that subscribe to the bloggers if ($config->get('notification_blogsubscriber')) { $notification->getBloggerSubscriberEmails($emails, $this); } // @rule: Send to subscribers that subscribed to the category if ($config->get('notification_categorysubscriber')) { $notification->getCategorySubscriberEmails($emails, $this); } // @rule: Send notification to all site's subscribers if ($config->get('notification_sitesubscriber')) { $notification->getSiteSubscriberEmails($emails, $this); } } } // @rule: We need to remove the email of the creator since the creator of this blog post should not receive the email. if (isset($emails[$author->user->email])) { unset($emails[$author->user->email]); } // @task: Add the emails into the mail queue now. if (!empty($emails)) { $notification->send($emails, $emailTitle, 'email.blog.new', $data); } // @task: If this blog post is under approval, we need to send email to the site admin if ($underApproval) { // We know that this blog post requires moderation. Send notification to the author and let them know, that it is being moderated. $authorEmail = array(); $obj = new stdClass(); $obj->unsubscribe = false; $obj->email = $author->user->email; $authorEmail[$author->user->email] = $obj; $notification->send($authorEmail, JText::_('COM_EASYBLOG_EMAIL_TITLE_NEW_BLOG_APPROVED'), 'email.blog.approved', $data); } }