本文整理汇总了PHP中DiscussHelper::formatComments方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussHelper::formatComments方法的具体用法?PHP DiscussHelper::formatComments怎么用?PHP DiscussHelper::formatComments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiscussHelper
的用法示例。
在下文中一共展示了DiscussHelper::formatComments方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatReplies
public static function formatReplies($result, $category = null)
{
$config = DiscussHelper::getConfig();
if (!$result) {
return $result;
}
$my = JFactory::getUser();
$replies = array();
for ($i = 0; $i < count($result); $i++) {
$row =& $result[$i];
$reply = DiscussHelper::getTable('Post');
$reply->bind($row);
$response = new stdClass();
if ($row->user_id == 0 || $row->user_type == DISCUSS_POSTER_GUEST) {
$response->id = '0';
$response->name = 'Guest';
// TODO: user the poster_name
} else {
$replier = JFactory::getUser($row->user_id);
$response->id = $replier->id;
$response->name = $replier->name;
}
//load porfile info and auto save into table if user is not already exist in discuss's user table.
$creator = DiscussHelper::getTable('Profile');
$creator->load($response->id);
$reply->user = $creator;
$reply->content_raw = $row->content;
$reply->isVoted = $row->isVoted;
$reply->total_vote_cnt = $row->total_vote_cnt;
$reply->title = DiscussHelper::wordFilter($reply->title);
$reply->content = DiscussHelper::wordFilter($reply->content);
// Legacy fix when switching from WYSIWYG editor to bbcode.
$reply->content = EasyDiscussParser::html2bbcode($reply->content);
// Parse bbcodes.
$reply->content = self::parseContent($reply->content, true);
// Parse @username links.
$reply->content = DiscussHelper::getHelper('String')->nameToLink($reply->content);
// set for vote status
$reply->voted = $reply->hasVoted();
// get total vote for this reply
$reply->totalVote = $reply->sum_totalvote;
// get the 5 latest voters
$voters = DiscussHelper::getVoters($row->id);
$reply->voters = $voters->voters;
$reply->shownVoterCount = $voters->shownVoterCount;
$reply->minimize = DiscussHelper::getHelper('Post')->toMinimizePost($row->sum_totalvote);
$reply->likesAuthor = DiscussHelper::getHelper('Likes')->getLikesHTML($row->id, null, null, $reply->getLikeAuthorsObject($row->id));
$reply->isLike = DiscussHelper::getHelper('Post')->isLiked($row->id);
// get reply comments
$commentLimit = $config->get('main_comment_pagination') ? $config->get('main_comment_pagination_count') : null;
$comments = $reply->getComments($commentLimit);
$reply->comments = false;
if ($config->get('main_comment')) {
$reply->comments = DiscussHelper::formatComments($comments);
}
// get reply comments count
$reply->commentsCount = $reply->getTotalComments();
// @rule: Check for url references
$reply->references = $reply->getReferences();
$reply->content = DiscussHelper::formatContent($reply);
if ($config->get('main_content_trigger_replies')) {
// Move aside the original content_raw
$content_raw_temp = $reply->content_raw;
// Add the br tags in the content, we do it here so that the content triggers's javascript will not get added with br tags
// $reply->content_raw = DiscussHelper::bbcodeHtmlSwitcher( $reply, 'reply', false );
// process content plugins
DiscussEventsHelper::importPlugin('content');
DiscussEventsHelper::onContentPrepare('reply', $reply);
$reply->event = new stdClass();
$results = DiscussEventsHelper::onContentBeforeDisplay('reply', $reply);
$reply->event->beforeDisplayContent = trim(implode("\n", $results));
$results = DiscussEventsHelper::onContentAfterDisplay('reply', $reply);
$reply->event->afterDisplayContent = trim(implode("\n", $results));
// Assign the processed content back
// $reply->content = $reply->content_raw;
// Move back the original content_raw
$reply->content_raw = $content_raw_temp;
}
$reply->access = $reply->getAccess($category);
$replies[] = $reply;
}
return $replies;
}
示例2: saveReply
//.........这里部分代码省略.........
// Only allow users with proper access
$isModerator = DiscussHelper::getHelper('Moderator')->isModerator($post->category_id);
// Do not allow unauthorized access
if (!DiscussHelper::isSiteAdmin() && $post->user_id != $my->id && !$acl->allowed('edit_reply', 0) && !$isModerator) {
$ajax->reject('error', JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
$ajax->send();
}
// Get the new content from the post data
$post->content = $data['content'];
// Validate captcha
$this->checkCaptcha($data);
// @rule: Bind parameters
if ($config->get('reply_field_references')) {
$post->bindParams($data);
}
// Bind file attachments
if ($acl->allowed('add_attachment', '0')) {
$post->bindAttachments();
}
// Determines if this is a new post.
$isNew = false;
// @trigger: onBeforeSave
DiscussEventsHelper::importPlugin('content');
DiscussEventsHelper::onContentBeforeSave('post', $post, $isNew);
// Try to store the post now
if (!$post->store()) {
$ajax->reject('error', JText::_('COM_EASYDISCUSS_ERROR'));
$ajax->send();
}
// Process polls
$this->processPolls($post);
// Process custom fields
$this->saveCustomFieldsValue($post->id);
// @trigger: onAfterSave
DiscussEventsHelper::onContentAfterSave('post', $post, $isNew);
// Filter for badwords
$post->title = DiscussHelper::wordFilter($post->title);
$post->content = DiscussHelper::wordFilter($post->content);
// Determines if the user is allowed to delete this post
$canDelete = false;
if (DiscussHelper::isSiteAdmin() || $acl->allowed('delete_reply', '0') || $post->user_id == $my->id) {
$canDelete = true;
}
// URL References
$post->references = $post->getReferences();
// Get the voted state
$voteModel = DiscussHelper::getModel('Votes');
$post->voted = $voteModel->hasVoted($post->id);
// Get total votes for this post
$post->totalVote = $post->sum_totalvote;
// Load profile info
$creator = DiscussHelper::getTable('Profile');
$creator->load($post->user_id);
// Assign creator
$post->user = $creator;
// Format the content.
$tmp = $post->content;
$post->content_raw = $post->content;
$post->content = DiscussHelper::formatContent($post);
// Once the formatting is done, we need to escape the raw content
$post->content_raw = DiscussHelper::getHelper('String')->escape($tmp);
// Store the default values
//default value
$post->isVoted = 0;
$post->total_vote_cnt = 0;
$post->likesAuthor = '';
$post->minimize = 0;
// Trigger reply
$post->triggerReply();
// Load up parent's post
$question = DiscussHelper::getTable('Post');
$question->load($post->parent_id);
$recaptcha = '';
$enableRecaptcha = $config->get('antispam_recaptcha');
$publicKey = $config->get('antispam_recaptcha_public');
$skipRecaptcha = $config->get('antispam_skip_recaptcha');
$model = DiscussHelper::getModel('Posts');
$postCount = count($model->getPostsBy('user', $my->id));
if ($enableRecaptcha && !empty($publicKey) && $postCount < $skipRecaptcha) {
require_once DISCUSS_CLASSES . '/recaptcha.php';
$recaptcha = getRecaptchaData($publicKey, $config->get('antispam_recaptcha_theme'), $config->get('antispam_recaptcha_lang'), null, $config->get('antispam_recaptcha_ssl'), 'edit-reply-recaptcha' . $post->id);
}
// Get the post access object here.
$category = DiscussHelper::getTable('Category');
$category->load($post->category_id);
$access = $post->getAccess($category);
$post->access = $access;
// Get comments for the post
$commentLimit = $config->get('main_comment_pagination') ? $config->get('main_comment_pagination_count') : null;
$comments = $post->getComments($commentLimit);
$post->comments = DiscussHelper::formatComments($comments);
$theme = new DiscussThemes();
$theme->set('question', $question);
$theme->set('post', $post);
$theme->set('category', $category);
// Get theme file output
$contents = $theme->fetch('post.reply.item.php');
$ajax->resolve($contents);
return $ajax->send();
}
示例3: display
public function display($tpl = null)
{
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$config = DiscussHelper::getConfig();
// Sorting and filters.
$sort = JRequest::getString('sort', DiscussHelper::getDefaultRepliesSorting());
$filteractive = JRequest::getString('filter', 'allposts');
$id = JRequest::getInt('id');
$acl = DiscussHelper::getHelper('ACL');
// Add noindex for print view by default.
if (JRequest::getInt('print') == 1) {
$doc->setMetadata('robots', 'noindex,follow');
}
// Get current logged in user.
$my = JFactory::getUser();
// Determine if the logged in user is an admin.
$isAdmin = DiscussHelper::isSiteAdmin();
// Load the post table out.
$post = DiscussHelper::getTable('Post');
$state = $post->load($id);
// Need raw content for later use
$post->content_raw = $post->content;
// If id is not found, we need to redirect gracefully.
if (!$state || !$post->published || !$id) {
return JError::raiseError(404, JText::_('COM_EASYDISCUSS_SYSTEM_POST_NOT_FOUND'));
}
if ($post->private && $my->id != $post->user_id && !$isAdmin && !DiscussHelper::isModerator($post->category_id, $my->id)) {
return JError::raiseError(404, JText::_('COM_EASYDISCUSS_SYSTEM_POST_NOT_FOUND'));
}
// Check whether this is a valid discussion
if ($post->parent_id != 0 || $post->published == DISCUSS_ID_PENDING && (!$isAdmin && $post->user_id != $my->id)) {
return JError::raiseError(404, JText::_('COM_EASYDISCUSS_SYSTEM_POST_NOT_FOUND'));
}
// check the discussion is under moderation
if ($post->published == 4 && !DiscussHelper::isModerator($post->category_id, $my->id) && !$isAdmin) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOTICE_POST_SUBMITTED_UNDER_MODERATION'), 'error');
$app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
$app->close();
}
// Load the category.
$category = DiscussHelper::getTable('Category');
$category->load((int) $post->category_id);
if ($post->category_id && !$category->canAccess()) {
return JError::raiseError(404, JText::_('COM_EASYDISCUSS_SYSTEM_POST_NOT_FOUND'));
}
// Add pathway for category here.
DiscussHelper::getHelper('Pathway')->setCategoryPathway($category);
// Set breadcrumbs for this discussion.
$this->setPathway($this->escape($post->title));
// Mark as viewed for notifications.
$this->logView();
// Update hit count for this discussion.
$post->hit();
// Set page headers
$this->setPageHeaders($post);
// Before sending the title and content to be parsed, we need to store this temporarily in case it needs to be accessed.
$post->title_clear = $post->title;
// Filter badwords
$post->title = DiscussHelper::wordFilter($post->title);
$post->content = DiscussHelper::wordFilter($post->content);
// Get the tags for this discussion
$postsTagsModel = $this->getModel('PostsTags');
$tags = $postsTagsModel->getPostTags($id);
// Get adsense codes here.
$adsense = DiscussHelper::getAdsense();
$postsModel = DiscussHelper::getModel('Posts');
// Get the answer for this discussion.
$answer = $postsModel->getAcceptedReply($post->id);
// Format the answer object.
if ($answer) {
$answer = DiscussHelper::formatReplies($answer, $category);
$answer = $answer[0];
}
// Get a list of replies for this post.
$data = $this->getReplies($category, $post, $sort, $answer);
$replies = $data->replies;
$totalReplies = $data->total;
$hasMoreReplies = $data->more;
$readMoreURI = $data->readmore;
// Get comments for the post
$commentLimit = $config->get('main_comment_pagination') ? $config->get('main_comment_pagination_count') : null;
$post->comments = false;
if ($config->get('main_commentpost')) {
$comments = $post->getComments($commentLimit);
$post->comments = DiscussHelper::formatComments($comments);
}
// get reply comments count
$post->commentsCount = $post->getTotalComments();
// Get the post access object here.
$access = $post->getAccess($category);
$post->access = $access;
// Add custom values.
$postOwner = $post->getOwner();
$profileTable = DiscussHelper::getTable('Profile');
if ($postOwner->id) {
$profileTable->load($postOwner->id);
}
$post->user = $profileTable;
// update user's post read flag
//.........这里部分代码省略.........
示例4: saveReply
//.........这里部分代码省略.........
// Process custom fields.
$fieldIds = JRequest::getVar('customFields');
if (!empty($fieldIds)) {
foreach ($fieldIds as $fieldId) {
$fields = JRequest::getVar('customFieldValue_' . $fieldId);
if (!empty($fields)) {
// Cater for custom fields select list
// To detect if there is no value selected for the select list custom fields
if (in_array('defaultList', $fields)) {
$tempKey = array_search('defaultList', $fields);
$fields[$tempKey] = '';
}
}
$postTable->bindCustomFields($fields, $fieldId);
}
}
}
// @trigger: onAfterSave
DiscussEventsHelper::onContentAfterSave('post', $postTable, $isNew);
//get parent post
$parentId = $postTable->parent_id;
$parentTable = DiscussHelper::getTable('Post');
$parentTable->load($parentId);
// filtering badwords
$postTable->title = DiscussHelper::wordFilter($postTable->title);
$postTable->content = DiscussHelper::wordFilter($postTable->content);
//all access control goes here.
$canDelete = false;
if (DiscussHelper::isSiteAdmin() || $acl->allowed('delete_reply', '0') || $postTable->user_id == $user->id) {
$canDelete = true;
}
// @rule: URL References
$postTable->references = $postTable->getReferences();
// set for vote status
$voteModel = DiscussHelper::getModel('Votes');
$postTable->voted = $voteModel->hasVoted($postTable->id);
// get total vote for this reply
$postTable->totalVote = $postTable->sum_totalvote;
//load porfile info and auto save into table if user is not already exist in discuss's user table.
$creator = DiscussHelper::getTable('Profile');
$creator->load($postTable->user_id);
$postTable->user = $creator;
//default value
$postTable->isVoted = 0;
$postTable->total_vote_cnt = 0;
$postTable->likesAuthor = '';
$postTable->minimize = 0;
if ($config->get('main_content_trigger_replies')) {
// process content plugins
DiscussEventsHelper::importPlugin('content');
DiscussEventsHelper::onContentPrepare('reply', $postTable);
$postTable->event = new stdClass();
$results = DiscussEventsHelper::onContentBeforeDisplay('reply', $postTable);
$postTable->event->beforeDisplayContent = trim(implode("\n", $results));
$results = DiscussEventsHelper::onContentAfterDisplay('reply', $postTable);
$postTable->event->afterDisplayContent = trim(implode("\n", $results));
}
$theme = new DiscussThemes();
$question = DiscussHelper::getTable('Post');
$question->load($postTable->parent_id);
$recaptcha = '';
$enableRecaptcha = $config->get('antispam_recaptcha');
$publicKey = $config->get('antispam_recaptcha_public');
$skipRecaptcha = $config->get('antispam_skip_recaptcha');
$model = DiscussHelper::getModel('Posts');
$postCount = count($model->getPostsBy('user', $my->id));
if ($enableRecaptcha && !empty($publicKey) && $postCount < $skipRecaptcha) {
require_once DISCUSS_CLASSES . '/recaptcha.php';
$recaptcha = getRecaptchaData($publicKey, $config->get('antispam_recaptcha_theme'), $config->get('antispam_recaptcha_lang'), null, $config->get('antispam_recaptcha_ssl'), 'edit-reply-recaptcha' . $postTable->id);
}
// Get the post access object here.
$category = DiscussHelper::getTable('Category');
$category->load($postTable->category_id);
$access = $postTable->getAccess($category);
$postTable->access = $access;
// Get comments for the post
$commentLimit = $config->get('main_comment_pagination') ? $config->get('main_comment_pagination_count') : null;
$comments = $postTable->getComments($commentLimit);
$postTable->comments = DiscussHelper::formatComments($comments);
$theme->set('question', $question);
$theme->set('post', $postTable);
$theme->set('category', $category);
$html = $theme->fetch('post.reply.item.php');
if ($recaptcha && $public && $private) {
$output['type'] = 'success.captcha';
}
if (!$parentTable->islock) {
$output['type'] = 'locked';
}
$message = $isNew ? JText::_('COM_EASYDISCUSS_POST_STORED') : JText::_('COM_EASYDISCUSS_EDIT_SUCCESS');
$state = 'success';
// Let's set our custom message here.
DiscussHelper::setMessageQueue($message, $state);
$redirect = JRequest::getVar('redirect', '');
if (!empty($redirect)) {
$redirect = base64_decode($redirect);
return $this->setRedirect($redirect);
}
$this->setRedirect(DiscussRouter::getPostRoute($post['parent_id'], false));
}