示例#1
0
 public function addOpenGraph(DiscussPost $post)
 {
     // Use facebook developer tools to check the result
     // https://developers.facebook.com/tools/debug/og
     $doc = JFactory::getDocument();
     $config = DiscussHelper::getConfig();
     // Search for an image in the content
     $image = self::searchImage($post->content);
     if ($image) {
         $doc->addCustomTag('<meta property="og:image" content="' . $image . '" />');
     }
     if ($config->get('integration_facebook_like')) {
         $appId = $config->get('integration_facebook_like_appid');
         if ($appId) {
             $doc->addCustomTag('<meta property="fb:app_id" content="' . $appId . '" />');
         }
         $adminId = $config->get('integration_facebook_like_admin');
         if ($adminId) {
             $doc->addCustomTag('<meta property="fb:admins" content="' . $adminId . '" />');
         }
     }
     // Add post title info here.
     $doc->addCustomTag('<meta property="og:title" content="' . $post->title . '" />');
     // Add post content.
     $maxContent = 350;
     // Remove bbcode tags from the content.
     $content = EasyDiscussParser::removeCodes($post->content);
     $content = strip_tags($post->content);
     if (JString::strlen($content) > $maxContent) {
         $content = JString::substr($content, 0, $maxContent) . '...';
     }
     // Add content to description
     $doc->addCustomTag('<meta property="og:description" content="' . $content . '" />');
     // Add the type of the og tag.
     $doc->addCustomTag('<meta property="og:type" content="article" />');
     // Add the URL for this page.
     $url = DiscussRouter::getRoutedURL(DiscussRouter::getPostRoute($post->id, false, true));
     $doc->addCustomTag('<meta property="og:url" content="' . $url . '" />');
     $doc->setTitle($post->title);
     $doc->setDescription($content);
     return true;
 }
示例#2
0
 public static function formatPost($posts, $isSearch = false, $isFrontpage = false)
 {
     $config = DiscussHelper::getConfig();
     if (!$posts) {
         return $posts;
     }
     $model = DiscussHelper::getModel('Posts');
     $result = array();
     for ($i = 0; $i < count($posts); $i++) {
         $row = $posts[$i];
         $obj = DiscussHelper::getTable('Post');
         $obj->bind($row);
         // Set post owner
         $owner = DiscussHelper::getTable('Profile');
         $owner->load($row->user_id);
         if ($row->user_id == 0 || $row->user_type == DISCUSS_POSTER_GUEST) {
             $owner->id = 0;
             $owner->name = 'Guest';
         } else {
             $owner->id = $row->user_id;
             $owner->name = $owner->getName();
         }
         $obj->user = $owner;
         $obj->title = self::wordFilter($row->title);
         $obj->content = self::wordFilter($row->content);
         $obj->isFeatured = $row->featured;
         $obj->category = JText::_($row->category);
         // get total replies
         $totalReplies = isset($row->num_replies) ? $row->num_replies : '0';
         $obj->totalreplies = $totalReplies;
         if ($totalReplies > 0) {
             // get last reply
             $lastReply = $model->getLastReply($row->id);
             if (!empty($lastReply)) {
                 $replier = DiscussHelper::getTable('Profile');
                 $replier->load($lastReply->user_id);
                 $replier->poster_name = $lastReply->user_id ? $replier->getName() : $lastReply->poster_name;
                 $replier->poster_email = $lastReply->user_id ? $replier->user->email : $lastReply->poster_email;
                 $obj->reply = $replier;
             }
         }
         //check whether the post is still withing the 'new' duration.
         $obj->isnew = DiscussHelper::isNew($row->noofdays);
         //get post duration so far.
         $durationObj = new stdClass();
         $durationObj->daydiff = $row->daydiff;
         $durationObj->timediff = $row->timediff;
         $obj->duration = DiscussHelper::getDurationString($durationObj);
         // Some result set may already been optimized using the `totalFavourites` column.
         if (!isset($row->totalFavourites)) {
             $favouritesModel = DiscussHelper::getModel('Favourites');
             // Get total favourites based on post id
             $obj->totalFavourites = $favouritesModel->getFavouritesCount($row->id);
         } else {
             $obj->totalFavourites = $row->totalFavourites;
         }
         if (!$isSearch) {
             $postsTagsModel = DiscussHelper::getModel('PostsTags');
             $tags = $postsTagsModel->getPostTags($row->id);
             $obj->tags = $tags;
             // Some result set may already been optimized using the `polls_cnt` column
             if (isset($row->polls_cnt)) {
                 $obj->polls = $row->polls_cnt;
             } else {
                 $obj->polls = $model->hasPolls($row->id);
             }
             if (isset($row->attachments_cnt)) {
                 $obj->attachments = $row->attachments_cnt;
             } else {
                 $obj->attachments = $model->hasAttachments($row->id, DISCUSS_QUESTION_TYPE);
             }
         } else {
             $obj->tags = '';
             $obj->polls = '';
             $obj->attachments = '';
         }
         if ($config->get('main_password_protection') && !empty($row->password) && !DiscussHelper::hasPassword($row)) {
             $tpl = new DiscussThemes();
             $tpl->set('post', $obj);
             $obj->content = $tpl->fetch('entry.password.php');
             $obj->introtext = $obj->content;
         }
         // @since 3.0
         // Format introtext here.
         if (!empty($row->password) && !DiscussHelper::hasPassword($row)) {
             if (!$obj->isProtected()) {
                 $obj->introtext = $row->content;
                 //display password input form.
                 $obj->introtext = strip_tags($obj->introtext);
             }
         } else {
             $obj->content_raw = $row->content;
             // Remove codes block
             $obj->content = EasyDiscussParser::removeCodes($row->content);
             // bbcode translation if there are any.
             $obj->content = self::formatContent($obj);
             $obj->introtext = strip_tags($obj->content);
             // Truncate it now.
             $obj->introtext = JString::substr($obj->introtext, 0, $config->get('layout_introtextlength')) . JText::_('COM_EASYDISCUSS_ELLIPSES');
         }
         // Apply badword filters here
         $obj->introtext = DiscussHelper::wordFilter($obj->introtext);
         // Set the post type suffix and title
         $obj->post_type_suffix = $row->post_type_suffix;
         $obj->post_type_title = $row->post_type_title;
         // used in search.
         if (isset($row->itemtype)) {
             $obj->itemtype = $row->itemtype;
         }
         // Assigned user
         if (!$isFrontpage) {
             $assignment = DiscussHelper::getTable('PostAssignment');
             $assignment->load($row->id);
             $obj->assignment = $assignment;
         }
         $result[] = $obj;
     }
     return $result;
 }