Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
    /**
     * Retrieves the comment count for the specific blog
     *
     * @param	int	$blogId	The blog id.
     **/
    public static function getCommentCount($blog)
    {
        $blogId = $blog->id;
        $config = EasyBlogHelper::getConfig();
        // If multiple comments, we output a common link
        if ($config->get('main_comment_multiple')) {
            return false;
        }
        if ($config->get('comment_komento')) {
            $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_komento' . DIRECTORY_SEPARATOR . 'bootstrap.php';
            if (JFile::exists($file)) {
                require_once $file;
                $commentsModel = Komento::getModel('comments');
                $commentCount = $commentsModel->getCount('com_easyblog', $blog->id);
                return $commentCount;
            }
        }
        $easysocial = EasyBlogHelper::getHelper('EasySocial');
        if ($config->get('comment_easysocial') && $easysocial->exists()) {
            return $easysocial->getCommentCount($blog);
        }
        if ($config->get('comment_compojoom')) {
            $file = JPATH_ROOT . '/administrator/components/com_comment/plugin/com_easyblog/josc_com_easyblog.php';
            if (JFile::exists($file)) {
                require_once $file;
                return CommentEasyBlog::output($blog, array(), true);
            }
            $file = JPATH_ROOT . '/components/com_comment/helpers/utils.php';
            if (JFile::exists($file)) {
                JLoader::discover('ccommentHelper', JPATH_ROOT . '/components/com_comment/helpers');
                return ccommentHelperUtils::commentInit('com_easyblog', $blog);
            }
        }
        if ($config->get('intensedebate')) {
            return false;
        }
        if ($config->get('comment_disqus')) {
            static $disqus = false;
            if (!$disqus) {
                ob_start();
                ?>
					var disqus_shortname = '<?php 
                echo $config->get('comment_disqus_code');
                ?>
';
					(function () {
					var s = document.createElement('script'); s.async = true;
					s.type = 'text/javascript';
					s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
					(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
					}());
				<?php 
                $contents = ob_get_contents();
                ob_end_clean();
                JFactory::getDocument()->addScriptDeclaration($contents);
                $disqus = true;
            }
            $string = '<!-- Disqus -->';
            $string .= '<span class="discus-comment">';
            $string .= '<a href="' . EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blogId) . '#disqus_thread"><span>' . JText::_('COM_EASYBLOG_COMMENTS') . '</span></a>';
            $string .= '</span>';
            return $string;
            // return false;
        }
        if ($config->get('comment_livefyre')) {
            return false;
        }
        if ($config->get('comment_jomcomment')) {
            $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jomcomment' . DIRECTORY_SEPARATOR . 'helper' . DIRECTORY_SEPARATOR . 'minimal.helper.php';
            jimport('joomla.filesystem.file');
            if (!JFile::exists($file)) {
                return false;
            }
            require_once $file;
            return jcCountComment($blogId, 'com_easyblog');
        }
        $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jcomments' . DIRECTORY_SEPARATOR . 'jcomments.php';
        if ($config->get('comment_jcomments') && JFile::exists($file)) {
            $db = EasyBlogHelper::db();
            $query = 'SELECT COUNT(1) FROM ' . $db->nameQuote('#__jcomments') . ' ' . 'WHERE ' . $db->nameQuote('object_id') . '=' . $db->Quote($blogId) . ' ' . 'AND ' . $db->nameQuote('object_group') . '=' . $db->Quote('com_easyblog') . ' ' . 'AND ' . $db->nameQuote('published') . '=' . $db->Quote(1);
            $db->setQuery($query);
            $total = $db->loadResult();
            return $total;
        }
        if ($config->get('comment_rscomments')) {
            return false;
        }
        if ($config->get('comment_facebook')) {
            return false;
        }
        // @task: Let's allow the plugin to also trigger the comment count.
        $params = EasyBlogHelper::getRegistry();
        $result = EasyBlogHelper::triggerEvent('easyblog.commentCount', $blog, $params, 0);
        $count = trim(implode(" ", $result));
        if (!empty($count)) {
            return $count;
        }
        $db = EasyBlogHelper::db();
        $query = 'SELECT COUNT(1) FROM ' . $db->nameQuote('#__easyblog_comment') . ' WHERE ' . $db->nameQuote('post_id') . '=' . $db->Quote($blogId) . ' AND `published` = ' . $db->Quote('1');
        $db->setQuery($query);
        $count = $db->loadResult();
        return $count;
    }
Ejemplo n.º 3
0
 function preview()
 {
     JPluginHelper::importPlugin('easyblog');
     $dispatcher = JDispatcher::getInstance();
     $mainframe = JFactory::getApplication();
     $acl = EasyBlogACLHelper::getRuleSet();
     $config = EasyBlogHelper::getConfig();
     $document = JFactory::getDocument();
     $my = JFactory::getUser();
     $params = $mainframe->getParams('com_easyblog');
     if (!EasyBlogHelper::isLoggedIn()) {
         EasyBlogHelper::showLogin();
         return;
     }
     $draftId = JRequest::getVar('draftid', '');
     $draft = EasyBlogHelper::getTable('Draft', 'Table');
     $draft->load($draftId);
     $blog = EasyBlogHelper::getTable('Blog', 'Table');
     $blog->bind($draft);
     $blogger = null;
     if ($blog->created_by != 0) {
         $blogger = EasyBlogHelper::getTable('Profile', 'Table');
         $blogger->load($blog->created_by);
     }
     // @rule: Set the author object into the table.
     $blog->author = $blogger;
     $blog->blogger = $blogger;
     $blogId = empty($draft->entry_id) ? $draft->id : $draft->entry_id;
     $limitstart = '0';
     $notice = '';
     $team = '';
     $blog->tags = empty($draft->tags) ? array() : $this->bindTags(explode(',', $draft->tags));
     // metas
     $meta = new stdClass();
     $meta->id = '';
     $meta->keywords = $draft->metakey;
     $meta->description = $draft->metadesc;
     $pageTitle = EasyBlogHelper::getPageTitle($config->get('main_title'));
     $document->setTitle($blog->title . $pageTitle);
     // process the video here if nessary
     $blog->intro = EasyBlogHelper::getHelper('Videos')->processVideos($blog->intro);
     $blog->content = EasyBlogHelper::getHelper('Videos')->processVideos($blog->content);
     // @rule: Process audio files.
     $blog->intro = EasyBlogHelper::getHelper('Audio')->process($blog->intro);
     $blog->content = EasyBlogHelper::getHelper('Audio')->process($blog->content);
     // @rule: Before any trigger happens, try to replace the gallery first and append it at the bottom.
     $blog->intro = EasyBlogHelper::getHelper('Gallery')->process($blog->intro, $blog->created_by);
     $blog->content = EasyBlogHelper::getHelper('Gallery')->process($blog->content, $blog->created_by);
     // Process jomsocial album's.
     $blog->intro = EasyBlogHelper::getHelper('Album')->process($blog->intro, $blog->created_by);
     $blog->content = EasyBlogHelper::getHelper('Album')->process($blog->content, $blog->created_by);
     // @trigger: onEasyBlogPrepareContent
     EasyBlogHelper::triggerEvent('easyblog.prepareContent', $blog, $params, $limitstart);
     //onPrepareContent trigger start
     $blog->introtext = $blog->intro;
     $blog->text = $blog->intro . $blog->content;
     // @trigger: onEasyBlogPrepareContent
     EasyBlogHelper::triggerEvent('prepareContent', $blog, $params, $limitstart);
     $blog->intro = $blog->introtext;
     $blog->content = $blog->text;
     $isFeatured = false;
     //page setup
     $blogHtml = '';
     $commentHtml = '';
     $blogHeader = '';
     $blogFooter = '';
     $adsenseHtml = '';
     $trackbackHtml = '';
     $blogger = null;
     if ($blog->created_by != 0) {
         $blogger = EasyBlogHelper::getTable('Profile', 'Table');
         $blogger->load($blog->created_by);
     }
     //onAfterDisplayTitle, onBeforeDisplayContent, onAfterDisplayContent trigger start
     $blog->event = new stdClass();
     // @trigger: onAfterDisplayTitle / onContentAfterTitle
     $results = EasyBlogHelper::triggerEvent('afterDisplayTitle', $blog, $params, $limitstart);
     $blog->event->afterDisplayTitle = JString::trim(implode("\n", $results));
     // @trigger: onBeforeDisplayContent / onContentBeforeDisplay
     $results = EasyBlogHelper::triggerEvent('beforeDisplayContent', $blog, $params, $limitstart);
     $blog->event->beforeDisplayContent = JString::trim(implode("\n", $results));
     // @trigger: onAfterDisplayContent / onContentAfterDisplay
     EasyBlogHelper::triggerEvent('afterDisplayContent', $blog, $params, $limitstart);
     $blog->event->afterDisplayContent = JString::trim(implode("\n", $results));
     if (!EasyBlogRouter::isCurrentActiveMenu('blogger', $blogger->id)) {
         $this->setPathway($blogger->getName(), $blogger->getLink());
     }
     if (!EasyBlogRouter::isCurrentActiveMenu('entry', $blog->id)) {
         $this->setPathway($blog->title, '');
     }
     $blog->totalComments = 0;
     // Facebook Like integrations
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'facebook.php';
     $facebookLike = EasyBlogFacebookLikes::getLikeHTML($blog);
     $url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true);
     //get blog navigation object
     $blogNav = EasyBlogHelper::getBlogNavigation($blog->id, $blog->created, $team, 'team');
     //$team
     $prevLink = array();
     if (!empty($blogNav['prev'])) {
         $prevLink['id'] = $blogNav['prev'][0]->id;
         $prevLink['title'] = JString::strlen($blogNav['prev'][0]->title) > 50 ? JString::substr($blogNav['prev'][0]->title, 0, 50) . '...' : $blogNav['prev'][0]->title;
     }
     $nextLink = array();
     if (!empty($blogNav['next'])) {
         $nextLink['id'] = $blogNav['next'][0]->id;
         $nextLink['title'] = JString::strlen($blogNav['next'][0]->title) > 50 ? JString::substr($blogNav['next'][0]->title, 0, 50) . '...' : $blogNav['next'][0]->title;
     }
     // @rule: Hide introtext if necessary
     if ($config->get('main_hideintro_entryview')) {
         $blog->intro = '';
     }
     //get social bookmark provider.
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'bookmark.php';
     $bookmark = EasyBlogBookmark::getHTML();
     $theme = new CodeThemes();
     $theme->set('facebookLike', $facebookLike);
     $theme->set('notice', $notice);
     $theme->set('blog', $blog);
     $theme->set('tags', $blog->tags);
     $theme->set('blogger', $blogger);
     $theme->set('prevLink', $prevLink);
     $theme->set('nextLink', $nextLink);
     $theme->set('blogRelatedPost', '');
     $theme->set('isFeatured', $isFeatured);
     $theme->set('isMineBlog', true);
     $theme->set('acl', $acl);
     $theme->set('url', $url);
     $theme->set('commentHTML', $commentHtml);
     $theme->set('bookmark', $bookmark);
     $theme->set('pdfLinkProperties', EasyBlogHelper::getPDFlinkProperties());
     $theme->set('ispreview', true);
     // @task: trackbacks
     $trackbacks = '';
     $theme->set('trackbackURL', EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=trackback&post_id=' . $blog->id, true, true));
     $theme->set('trackbacks', $trackbacks);
     //google adsense
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php';
     $adsense = EasyBlogGoogleAdsense::getHTML($blogger->id);
     $blogHeader = $adsense->header;
     $blogFooter = $adsense->footer;
     $theme->set('adsenseHTML', $adsense->beforecomments);
     $blogHtml = $theme->fetch('blog.read.php');
     echo $blogHeader;
     echo $blogHtml;
     echo $blogFooter;
 }