Esempio n. 1
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;
 }
Esempio n. 2
0
"><?php 
        echo JString::strlen($post->title) > $params->get('max_title', 50) ? JString::substr($post->title, 0, $params->get('max_title', 50)) . '...' : $post->title;
        ?>
</a>
					<div class="small"><?php 
        echo JText::sprintf('MOD_RECENTDISCUSSIONS_STARTED_BY', '<a href="' . $post->profile->getLink() . '">' . $post->profile->getName() . '</a>');
        ?>
</div>
				</div>

				<?php 
        if ($params->get('show_content') && !$params->get('show_content_tooltips', false)) {
            ?>
				<div class="mod-story">
					<?php 
            if (empty($post->password) || isset($post->password) && DiscussHelper::hasPassword($post)) {
                ?>
					<?php 
                echo $post_content;
                ?>
					<?php 
            } else {
                ?>
						<i><?php 
                echo JText::_('MOD_RECENTDISCUSSIONS_PASSWORD_PROTECTED');
                ?>
</i>
					<?php 
            }
            ?>
				</div>