Ejemplo n.º 1
0
 /**
  * Display a post. This method is used for:
  * - The normal HTML display of a post
  * - HTML email of a post
  * - Text-only email of a post
  * These are all combined in one method since ordinarily they change at
  * the same time (i.e. if adding/hiding information it is usually added to
  * or hidden from all views).
  *
  * $options is an associative array from a mod_forumng_post::OPTION_xx constant.
  * All available options are always set - if they were not set by
  * the user, they will have been set to false before this call happens,
  * so there is no need to use empty() or isset().
  *
  * Options are as follows. These are available in email mode:
  *
  * OPTION_TIME_ZONE (int) - Moodle time zone
  * OPTION_VIEW_FULL_NAMES (bool) - If user is allowed to see full names
  * OPTION_EMAIL (bool) - True if this is an email (false = standard view)
  * OPTION_DIGEST (bool) - True if this is part of an email digest
  * OPTION_COMMAND_REPLY (bool) - True if 'Reply' link should be displayed
  *   (available in email too)
  *
  * These options only apply in non-email usage:
  *
  * OPTION_SUMMARY (bool) - True if the entire post should not be displayed,
  *   only a short summary
  * OPTION_NO_COMMANDS (bool) - True if this post is being printed on its own
  * OPTION_COMMAND_EDIT (bool) - Display 'Edit' command
  * OPTION_COMMAND_DELETE (bool) - Display 'Edit' command
  * OPTION_COMMAND_SPLIT (bool) - Display 'Split' command
  * OPTION_RATINGS_VIEW (bool) - True to display current ratings
  * OPTION_RATINGS_EDIT (bool) - True to display ratings edit combo
  * OPTION_LEAVE_DIV_OPEN (bool) - True to not close post div (means that
  *   child posts can be added within).
  * OPTION_EXPANDED (bool) - True to show full post, otherwise abbreviate
  * OPTION_DISCUSSION_SUBJECT (bool) - If true, and only IF post is a
  *   discussion root, includes subject (HTML, shortened as it would be for
  *   header display) as a hidden field.
  *
  * @param mod_forumng_post $post Post object
  * @param bool $html True if using HTML, false to output in plain text
  * @param array $options Associative array of name=>option, as above
  * @return string HTML or text of post
  */
 public function render_post($post, $html, $options)
 {
     global $CFG, $USER, $THEME, $OUTPUT;
     $discussion = $post->get_discussion();
     $expanded = $options[mod_forumng_post::OPTION_EXPANDED];
     $export = $options[mod_forumng_post::OPTION_EXPORT];
     $email = $options[mod_forumng_post::OPTION_EMAIL];
     // When posts are deleted we hide a lot of info - except when the person
     // viewing it has the ability to view deleted posts.
     $deletedhide = $post->get_deleted() && !$options[mod_forumng_post::OPTION_VIEW_DELETED_INFO];
     // Hide deleted messages if they have no replies
     if ($deletedhide && ($export || !$email) && !$post->has_children()) {
         // note: !email check is to deal with posts that are deleted
         // between when the mail list finds them, and when it sends out
         // mail. It would be confusing to send out a blank email so let's
         // not do that. Also, ->has_children() is not safe to call during
         // email processing because it doesn't load the whole discussion.
         return '';
     }
     // Save some bandwidth by not sending link full paths except in emails
     if ($options[mod_forumng_post::OPTION_FULL_ADDRESSES]) {
         $linkprefix = $CFG->wwwroot . '/mod/forumng/';
     } else {
         $linkprefix = '';
     }
     $postnumber = ($options[mod_forumng_post::OPTION_NO_COMMANDS] || $email) && !$options[mod_forumng_post::OPTION_VISIBLE_POST_NUMBERS] ? '' : $post->get_number();
     $lf = "\n";
     // Initialise result
     $out = '';
     if ($html) {
         if ($export) {
             $out .= '<hr />';
         }
         // Basic intro
         $classes = $expanded ? ' forumng-full' : ' forumng-short';
         $classes .= $post->is_important() ? ' forumng-important' : '';
         $classes .= !$email && !$options[mod_forumng_post::OPTION_UNREAD_NOT_HIGHLIGHTED] && $post->is_unread() ? ' forumng-unread' : ' forumng-read';
         $classes .= $post->get_deleted() ? ' forumng-deleted' : '';
         $classes .= ' forumng-p' . $postnumber;
         if ($options[mod_forumng_post::OPTION_INDICATE_MODERATOR] == true) {
             $classes .= ' forumng-imoderator';
         }
         $out .= $lf . '<div class="forumng-post' . $classes . '">' . '<div class="post-deco"><div class="post-deco-bar"></div></div><a id="p' . $post->get_id() . '"></a>';
         if ($options[mod_forumng_post::OPTION_FIRST_UNREAD]) {
             $out .= '<a id="firstunread"></a>';
         }
         // Theme hooks
         if (!empty($THEME->forumng_post_hooks)) {
             for ($i = 1; $i <= $THEME->forumng_post_hooks; $i++) {
                 $out .= '<div class="forumng-' . $i . '"></div>';
             }
         }
     }
     if ($html || $options[mod_forumng_post::OPTION_VISIBLE_POST_NUMBERS]) {
         // Accessible text giving post a number so we can make links unique
         // etc.
         if ($postnumber) {
             $data = new stdClass();
             $data->num = $postnumber;
             if ($post->get_parent()) {
                 if ($html) {
                     $data->parent = '<a class="forumng-parentlink" href="#p' . $post->get_parent()->get_id() . '">' . $post->get_parent()->get_number() . '</a>';
                 } else {
                     $data->parent = $post->get_parent()->get_number();
                 }
                 $data->info = '';
                 if ($post->is_unread()) {
                     $data->info = get_string('postinfo_unread', 'forumng');
                 }
                 if (!$expanded) {
                     $data->info .= ' ' . get_string('postinfo_short', 'forumng');
                 }
                 if ($post->get_deleted()) {
                     $data->info .= ' ' . get_string('postinfo_deleted', 'forumng');
                 }
                 $data->info = trim($data->info);
                 if ($data->info) {
                     $data->info = ' (' . $data->info . ')';
                 }
                 $info = get_string('postnumreply', 'forumng', $data);
             } else {
                 $info = get_string('postnum', 'forumng', $data);
             }
             if ($options[mod_forumng_post::OPTION_VISIBLE_POST_NUMBERS]) {
                 if (!$html) {
                     $out .= "## " . $info . "\n";
                 }
             }
         }
     }
     // Discussion subject (root only)
     if ($options[mod_forumng_post::OPTION_DISCUSSION_SUBJECT] && $post->is_root_post()) {
         $out .= '<input type="hidden" name="discussion_subject" value="' . shorten_text(htmlspecialchars($post->get_subject())) . '" />';
     }
     // Pictures (HTML version only)
     if ($html) {
         $out .= $lf . html_writer::start_tag('div', array('class' => 'forumng-pic-info'));
     }
     if ($html && !$export && $options[mod_forumng_post::OPTION_USER_IMAGE]) {
         $out .= $lf . html_writer::start_tag('div', array('class' => 'forumng-pic'));
         // User picture.
         if (!$options[mod_forumng_post::OPTION_IS_ANON]) {
             $out .= $deletedhide ? '' : $post->display_user_picture();
         } else {
             if ($options[mod_forumng_post::OPTION_VIEW_ANON_INFO]) {
                 $out .= $deletedhide ? '' : $post->display_user_picture();
             }
         }
         // Group pictures if any - only for expanded version
         if ($expanded) {
             $grouppics = $post->display_group_pictures();
             if ($grouppics) {
                 $out .= '<div class="forumng-grouppicss">' . $grouppics . '</div>';
             }
         }
         $out .= html_writer::end_tag('div');
     }
     // Link used to expand post
     $expandlink = '';
     if (!$expanded && !$deletedhide) {
         $expandlink = $this->render_expand_link($linkprefix, $discussion, $post);
     }
     // Byline
     $by = new stdClass();
     $by->name = $deletedhide ? '' : fullname($post->get_user(), $options[mod_forumng_post::OPTION_VIEW_FULL_NAMES]);
     $by->date = $deletedhide ? '' : userdate($post->get_created(), get_string('strftimedatetime', 'langconfig'), $options[mod_forumng_post::OPTION_TIME_ZONE]);
     if ($html) {
         $out .= $lf . '<div class="forumng-info"><h2 class="forumng-author">';
         $out .= $post->is_important() ? '<img src="' . $this->pix_url('exclamation_mark', 'mod_forumng') . '" alt="' . get_string('important', 'forumng') . '" ' . 'title = "' . get_string('important', 'forumng') . '"/>' : '';
         if ($export) {
             if (!$options[mod_forumng_post::OPTION_IS_ANON]) {
                 $out .= $by->name . ' ';
             }
         } else {
             if (!$options[mod_forumng_post::OPTION_IS_ANON]) {
                 $out .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->get_user()->id . ($post->get_forum()->is_shared() ? '' : '&amp;course=' . $post->get_forum()->get_course_id()) . '">' . $by->name . '</a>';
             }
         }
         if ($options[mod_forumng_post::OPTION_IS_ANON] || $options[mod_forumng_post::OPTION_INDICATE_MODERATOR]) {
             $moderator = get_string('moderator', 'forumng');
             $out .= html_writer::tag('div', get_string('moderator', 'forumng'), array('class' => 'forumng-moderator-flag'));
         }
         if ($postnumber) {
             if ($options[mod_forumng_post::OPTION_VISIBLE_POST_NUMBERS]) {
                 $out .= html_writer::tag('small', ' ' . $info, array('class' => 'accesshide', 'style' => 'position:static'));
             } else {
                 $out .= '<span class="accesshide"> ' . $info . ' </span>';
             }
         }
         $out .= $deletedhide ? '' : '</h2> <span class="forumng-separator">&#x2022;</span> ';
         $out .= '<span class="forumng-date">' . $by->date . '</span>';
         // Should not show editing user info, if poster is anonymous and
         // current user can�t view anonymous info .
         if ($options[mod_forumng_post::OPTION_IS_ANON] && $discussion->get_forum()->can_post_anonymously() || $options[mod_forumng_post::OPTION_INDICATE_MODERATOR] || !$options[mod_forumng_post::OPTION_IS_ANON] && !$email) {
             if ($edituser = $post->get_edit_user()) {
                 $out .= ' <span class="forumng-separator">&#x2022;</span> ' . '<span class="forumng-edit">';
                 $edit = new stdClass();
                 $edit->date = userdate($post->get_modified(), get_string('strftimedatetime', 'langconfig'), $options[mod_forumng_post::OPTION_TIME_ZONE]);
                 $edit->name = fullname($edituser, $options[mod_forumng_post::OPTION_VIEW_FULL_NAMES]);
                 if ($edituser->id == $post->get_user()->id) {
                     $out .= get_string('editbyself', 'forumng', $edit->date);
                 } else {
                     $out .= get_string('editbyother', 'forumng', $edit);
                 }
                 if ($options[mod_forumng_post::OPTION_COMMAND_HISTORY]) {
                     $out .= ' (<a href="history.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . '">' . get_string('history', 'forumng') . '</a>)';
                 }
                 $out .= '</span>';
             }
         }
         if ($options[mod_forumng_post::OPTION_SELECTABLE]) {
             $out .= '<span class="forumng-separator"> &#x2022; </span>' . '<input type="checkbox" name="selectp' . $post->get_id() . '" id="id_selectp' . $post->get_id() . '" /><label class="accesshide" for="id_selectp' . $post->get_id() . '">' . get_string('selectlabel', 'forumng', $postnumber) . '</label>';
         }
         // End: forumng-info.
         $out .= html_writer::end_tag('div');
         // End: forumng-pic-info.
         $out .= html_writer::end_tag('div');
     } else {
         require_once dirname(__FILE__) . '/mod_forumng_cron.php';
         $out .= $by->name . ' - ' . $by->date . $lf;
         $out .= mod_forumng_cron::EMAIL_DIVIDER;
     }
     // Add a outer div to main contents
     if ($html) {
         $out .= '<div class="forumng-post-outerbox">';
     }
     if ($html && $post->get_deleted()) {
         $out .= '<p class="forumng-deleted-info"><strong>' . get_string('deletedpost', 'forumng') . '</strong> ';
         if ($deletedhide) {
             $out .= get_string($post->get_delete_user()->id == $post->get_user()->id ? 'deletedbyauthor' : 'deletedbymoderator', 'forumng', userdate($post->get_deleted()));
         } else {
             $a = new stdClass();
             $a->date = userdate($post->get_deleted());
             $a->user = '******' . $CFG->wwwroot . '/user/view.php?id=' . $post->get_delete_user()->id . '&amp;course=' . $post->get_forum()->get_course_id() . '">' . fullname($post->get_delete_user(), $options[mod_forumng_post::OPTION_VIEW_FULL_NAMES]) . '</a>';
             $out .= get_string('deletedbyuser', 'forumng', $a);
         }
         $out .= '</p>';
     }
     if ($options[mod_forumng_post::OPTION_IS_ANON] && $options[mod_forumng_post::OPTION_VIEW_ANON_INFO] && !$email) {
         $a = html_writer::link(new moodle_url('/user/view.php', array('id' => $post->get_user()->id, 'course' => $post->get_forum()->get_course_id())), fullname($post->get_user(), $options[mod_forumng_post::OPTION_VIEW_FULL_NAMES]));
         $out .= get_string('createdbymoderator', 'forumng', $a);
     }
     // Get subject. This may make a db query when showing a single post
     // (which includes parent subject).
     if ($options[mod_forumng_post::OPTION_EMAIL] || $options[mod_forumng_post::OPTION_NO_COMMANDS]) {
         $subject = $post->get_effective_subject(true);
     } else {
         $subject = $post->get_subject();
     }
     // Otherwise, subject is only displayed if it has changed
     if ($subject !== null && $expanded && !$deletedhide) {
         if ($html) {
             $out .= $lf . '<h3 class="forumng-subject">';
             if ($options[mod_forumng_post::OPTION_DIGEST]) {
                 // Digest contains link to original post
                 $out .= '<a href="' . $linkprefix . 'discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_HTML) . '#p' . $post->get_id() . '">' . format_string($subject) . '</a>';
             } else {
                 $out .= format_string($subject);
             }
             $out .= '</h3>';
         } else {
             $out .= format_string($subject, true);
             if ($options[mod_forumng_post::OPTION_DIGEST]) {
                 // Link to original post
                 $out .= " <{$linkprefix}discuss.php?" . $discussion->get_link_params(mod_forumng::PARAM_HTML) . $discussion->get_id() . '#p' . $post->get_id() . '>';
             }
             $out .= $lf;
         }
     }
     // Get content of actual message in HTML
     if ($html) {
         $message = $post->get_formatted_message();
         if (!$expanded && !$deletedhide) {
             // When not expanded and no subject, we include a summary of the
             // message
             $stripped = strip_tags(preg_replace('~<script.*?</script>~s', '', $message));
             $messagetosummarise = $subject !== null ? '<h3>' . $subject . '</h3>&nbsp;' . $stripped : $stripped;
             $summary = self::nice_shorten_text($messagetosummarise, 50);
             $out .= $lf . '<div class="forumng-summary"><div class="forumng-text">' . $summary . '</div> ' . $expandlink . '</div>';
         }
     }
     // Start of post main section
     if ($expanded && !$deletedhide) {
         if ($html) {
             $out .= '<div class="forumng-postmain">';
         }
         // Attachments
         $attachments = $post->get_attachment_names();
         if (count($attachments)) {
             if ($html) {
                 $out .= $lf;
                 if (count($attachments) == 1) {
                     $attachmentlabel = get_string('attachment', 'forumng');
                 } else {
                     $attachmentlabel = get_string('attachments', 'forumng');
                 }
                 $out .= '<span class="accesshide">' . $attachmentlabel . '</span><ul class="forumng-attachments">';
             }
             foreach ($attachments as $attachment) {
                 if ($html) {
                     require_once $CFG->libdir . '/filelib.php';
                     $iconsrc = $this->pix_url('/f/' . mimeinfo('icon', $attachment));
                     $alt = get_mimetype_description(mimeinfo('type', $attachment));
                     $out .= '<li><a href="' . $post->get_attachment_url($attachment) . '">' . '<img src="' . $iconsrc . '" alt="' . $alt . '" /> <span>' . htmlspecialchars($attachment) . '</span></a> </li>';
                 } else {
                     // Right-align the entry to 70 characters
                     $padding = 70 - strlen($attachment);
                     if ($padding > 0) {
                         $out .= str_repeat(' ', $padding);
                     }
                     // Add filename
                     $out .= $attachment . $lf;
                 }
             }
             if ($html) {
                 $out .= '</ul>' . $lf;
             } else {
                 $out .= $lf;
                 // Extra line break after attachments
             }
         }
         // Display actual content
         if ($html) {
             if ($options[mod_forumng_post::OPTION_PRINTABLE_VERSION]) {
                 $message = preg_replace('~<a[^>]*\\shref\\s*=\\s*[\'"](http:.*?)[\'"][^>]*>' . '(?!(http:|www\\.)).*?</a>~', "\$0 [\$1]", $message);
             }
             $out .= $lf . '<div class="forumng-message">' . $message . '</div>';
         } else {
             $out .= $post->get_email_message();
             $out .= "\n\n";
         }
         if ($html) {
             $out .= $lf . '<div class="clear forumng-postfooter">';
         }
         // Ratings.
         $ratings = '';
         $ratingclasses = '';
         if ($options[mod_forumng_post::OPTION_RATINGS_VIEW]) {
             $ratingclasses .= ' forumng-canview';
             if ($post->get_num_ratings() >= $post->get_forum()->get_rating_threshold()) {
                 if ($html) {
                     $ratings .= '<div class="forumng-rating">';
                     $a = new stdClass();
                     $a->avg = '<strong id="rating_for_' . $post->get_id() . '">' . $post->get_average_rating(true) . '</strong>';
                     $a->num = '<span class="forumng-count">' . $post->get_num_ratings() . '</span>';
                     $ratings .= get_string('averagerating', 'forumng', $a);
                     $ratings .= '</div>';
                 } else {
                     $ratings .= strip_tags($post->get_average_rating(true));
                 }
             }
         }
         if ($options[mod_forumng_post::OPTION_RATINGS_EDIT] && $html) {
             $ratingclasses .= ' forumng-canedit';
             $ratings .= '<div class="forumng-editrating">' . get_string('yourrating', 'forumng') . ' ';
             $ratings .= html_writer::select($post->get_forum()->get_rating_options(), 'rating' . $post->get_id(), $post->get_own_rating(), array(mod_forumng_post::NO_RATING => '-'));
             $ratings .= '</div>';
         }
         if ($post->get_forum()->get_enableratings() == mod_forumng::FORUMNG_STANDARD_RATING && $post->get_ratings()) {
             $out .= html_writer::div($OUTPUT->render($post->get_ratings()), 'forumng-ratings-standard');
         } else {
             if ($ratings) {
                 $out .= '<div class="forumng-ratings' . $ratingclasses . '">' . $ratings . '</div>';
             }
         }
         // Commands at bottom of mail
         $mobileclass = '';
         if ($html) {
             $commandsarray = array();
             $expires = $post->can_ignore_edit_time_limit() ? '' : '&amp;expires=' . ($post->get_edit_time_limit() - time());
             $expandparam = !empty($options[mod_forumng_post::OPTION_CHILDREN_EXPANDED]) ? '&amp;expand=1' : '';
             // Jump box
             if ($options[mod_forumng_post::OPTION_JUMP_PREVIOUS] || $options[mod_forumng_post::OPTION_JUMP_NEXT] || $options[mod_forumng_post::OPTION_JUMP_PARENT]) {
                 $nextid = $options[mod_forumng_post::OPTION_JUMP_NEXT];
                 $pid = $options[mod_forumng_post::OPTION_JUMP_PREVIOUS];
                 $parentid = $options[mod_forumng_post::OPTION_JUMP_PARENT];
                 if ($jumptotext = $this->render_commands_jumpto($nextid, $pid, $parentid)) {
                     $thiscommand = '<span class="forumng-jumpto-label">' . get_string('jumpto', 'forumng') . '</span>' . $jumptotext;
                     $commandsarray['forumng-jumpto'] = $thiscommand;
                 }
             }
             // Mark post read.
             if ($CFG->forumng_trackreadposts && !isguestuser() && $post->is_unread() && !mod_forumng::mark_read_automatically()) {
                 $commandsarray['forumng-markread'] = html_writer::link(new moodle_url('/mod/forumng/markread.php', array('p' => $post->get_id())), get_string('markpostread', 'forumng'));
             }
             // Flag link.
             if ($options[mod_forumng_post::OPTION_FLAG_CONTROL]) {
                 $flagurl = new moodle_url('flagpost.php?', array('p' => $post->get_id(), 'timeread' => $options[mod_forumng_post::OPTION_READ_TIME], 'flag' => $post->is_flagged() ? 0 : 1));
                 $icon = "flag." . ($post->is_flagged() ? 'on' : 'off');
                 $iconalt = get_string($post->is_flagged() ? 'clearflag' : 'setflag', 'forumng');
                 $bnstr = get_string($post->is_flagged() ? 'clearflag' : 'flagpost', 'forumng');
                 $iconhtml = $OUTPUT->pix_icon($icon, '', 'forumng');
                 $iconhtml .= html_writer::span($bnstr, 'flagtext');
                 $link = html_writer::link($flagurl, $iconhtml, array('title' => $iconalt));
                 $commandsarray['forumng-flagpost'] = html_writer::div($link, 'forumng-flagpost');
             }
             // Direct link.
             if ($options[mod_forumng_post::OPTION_COMMAND_DIRECTLINK]) {
                 $commandsarray['forumng-permalink'] = '<a href="discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_HTML) . '#p' . $post->get_id() . '" title="' . get_string('directlinktitle', 'forumng') . '">' . get_string('directlink', 'forumng', $postnumber) . '</a>';
             }
             // Alert link.
             $forum = $discussion->get_forum();
             if ($options[mod_forumng_post::OPTION_COMMAND_REPORT] && !($options[mod_forumng_post::OPTION_IS_ANON] || $options[mod_forumng_post::OPTION_INDICATE_MODERATOR])) {
                 $reportabuselink = '';
                 if ($forum->oualerts_enabled()) {
                     $itmurl = $CFG->wwwroot . '/mod/forumng/discuss.php';
                     $itmurl .= '?' . $discussion->get_link_params(mod_forumng::PARAM_PLAIN);
                     $itemurl = $itmurl . '#p' . $post->get_id();
                     $context = $post->get_forum()->get_context(false);
                     $reportabuselink = oualerts_generate_alert_form_url('forumng', $context->id, 'post', $post->get_id(), $itemurl, $itemurl, $USER->id, false, true);
                 } else {
                     $reportabuselink = $linkprefix . 'alert.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . $expandparam;
                 }
                 $commandsarray['forumng-alert'] = '<a href="' . $reportabuselink . '" title="' . get_string('alert_linktitle', 'forumng') . '">' . get_string('alert_link', 'forumng', $postnumber) . '</a>';
             }
             // Split link
             if ($options[mod_forumng_post::OPTION_COMMAND_SPLIT]) {
                 $commandsarray['forumng-split'] = '<a href="' . $linkprefix . 'splitpost.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . $expandparam . '">' . get_string('split', 'forumng', $postnumber) . '</a>';
             }
             // Delete link
             if ($options[mod_forumng_post::OPTION_COMMAND_DELETE]) {
                 $commandsarray['forumng-delete'] = '<a' . $mobileclass . ' href="' . $linkprefix . 'deletepost.php?' . $post->get_link_params(mod_forumng::PARAM_HTML, true) . $expandparam . $expires . '">' . get_string('delete', 'forumng', $postnumber) . '</a>';
             }
             // Undelete link
             if ($options[mod_forumng_post::OPTION_COMMAND_UNDELETE]) {
                 $commandsarray['forumng-undelete'] = '<a href="' . $linkprefix . 'deletepost.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . $expandparam . '&amp;delete=0">' . get_string('undelete', 'forumng', $postnumber) . '</a>';
             }
             // Edit link
             if ($options[mod_forumng_post::OPTION_COMMAND_EDIT]) {
                 $commandsarray['forumng-edit'] = '<a' . $mobileclass . ' href="' . $linkprefix . 'editpost.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . $expandparam . $expires . '">' . get_string('edit', 'forumng', $postnumber) . '</a>';
             }
             // Reply link
             if ($options[mod_forumng_post::OPTION_COMMAND_REPLY]) {
                 $commandsarray['forumng-replylink'] = '<a' . $mobileclass . ' href="' . $linkprefix . 'editpost.php?replyto=' . $post->get_id() . $post->get_forum()->get_clone_param(mod_forumng::PARAM_HTML) . $expandparam . '">' . get_string('reply', 'forumng', $postnumber) . '</a>';
             }
             if (count($commandsarray)) {
                 $out .= $lf . $this->render_commands($commandsarray);
             }
         } else {
             // Reply link
             if ($options[mod_forumng_post::OPTION_COMMAND_REPLY]) {
                 $out .= mod_forumng_cron::EMAIL_DIVIDER;
                 if ($options[mod_forumng_post::OPTION_EMAIL]) {
                     $course = $post->get_forum()->get_course();
                     $out .= get_string("postmailinfo", "forumng", $course->shortname) . $lf;
                 }
                 $out .= "{$linkprefix}editpost.php?replyto=" . $post->get_id() . $post->get_forum()->get_clone_param(mod_forumng::PARAM_PLAIN) . $lf;
             }
             // Only the reply command is available in text mode
         }
         // End: forumng-postfooter and forumng-postmain.
         if ($html) {
             $out .= html_writer::end_tag('div') . html_writer::end_tag('div');
         }
     }
     // End of post div
     if ($html) {
         // Useful empty div at end of post.
         $out .= html_writer::tag('div', '', array('class' => 'forumng-endpost'));
         // End: forumng-post-outerbox.
         $out .= html_writer::end_tag('div');
         // Export has a couple blank lines after post (but within div, for validity).
         if ($export) {
             $out .= '<br /><br />';
         }
         // End: forumng-post.
         $out .= html_writer::end_tag('div');
     }
     return $out;
 }
Ejemplo n.º 2
0
 /**
  * Print comments which relate to a single blog post
  *
  * @param object $post Structure containing all post info and comments
  * @param object $oublog Blog object
  * @param bool $canmanagecomments Has capability toggle
  * @param bool $canaudit Has capability toggle
  * @param bool $forexport Export output rendering toggle
  * @param object $cm Current course module object
  * @return html
  */
 public function render_comments($post, $oublog, $canaudit, $canmanagecomments, $forexport, $cm, $format = false)
 {
     global $DB, $CFG, $USER, $OUTPUT;
     $viewfullnames = true;
     $strdelete = get_string('delete', 'oublog');
     $strcomments = get_string('comments', 'oublog');
     $output = '';
     $modcontext = context_module::instance($cm->id);
     if (!$canmanagecomments) {
         $context = context_module::instance($cm->id);
         $canmanagecomments = has_capability('mod/oublog:managecomments', $context);
     }
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-comments', 'id' => 'oublogcomments'));
     $counter = 0;
     foreach ($post->comments as $comment) {
         $extraclasses = $comment->deletedby ? ' oublog-deleted' : '';
         $extraclasses .= ' oublog-hasuserpic';
         $output .= html_writer::start_tag('div', array('class' => 'oublog-comment' . $extraclasses, 'id' => 'cid' . $comment->id));
         if ($counter == 0) {
             $output .= html_writer::tag('h2', format_string($strcomments), array('class' => 'oublog-commentstitle'));
         }
         if ($comment->deletedby) {
             $deluser = new stdClass();
             $fields = get_all_user_name_fields(false, null, 'del');
             foreach ($fields as $field => $dfield) {
                 $deluser->{$field} = $comment->{$dfield};
             }
             $a = new stdClass();
             $a->fullname = '<a href="../../user/view.php?id=' . $comment->deletedby . '">' . fullname($deluser) . '</a>';
             $a->timedeleted = oublog_date($comment->timedeleted);
             $output .= html_writer::tag('div', get_string('deletedby', 'oublog', $a), array('class' => 'oublog-comment-deletedby'));
         }
         if ($comment->userid && !$forexport) {
             $output .= html_writer::start_tag('div', array('class' => 'oublog-userpic'));
             $commentuser = new object();
             $fields = explode(',', user_picture::fields());
             foreach ($fields as $field) {
                 if ($field != 'id') {
                     $commentuser->{$field} = $comment->{$field};
                 }
             }
             $commentuser->id = $comment->userid;
             $output .= $OUTPUT->user_picture($commentuser, array('courseid' => $oublog->course, 'size' => 70));
             $output .= html_writer::end_tag('div');
         }
         if (trim(format_string($comment->title)) !== '') {
             $output .= html_writer::tag('h2', format_string($comment->title), array('class' => 'oublog-title'));
         } else {
             if (!$forexport) {
                 $commenttitle = get_accesshide(get_string('newcomment', 'mod_oublog'));
                 $output .= html_writer::tag('h2', $commenttitle, array('class' => 'oublog-title'));
             }
         }
         $output .= html_writer::start_tag('div', array('class' => 'oublog-post-date'));
         $output .= oublog_date($comment->timeposted);
         $output .= html_writer::start_tag('div', array('class' => 'oublog-postedby'));
         if ($comment->userid) {
             if (!$forexport) {
                 $output .= get_string('postedby', 'oublog', '<a href="../../user/view.php?id=' . $comment->userid . '&amp;course=' . $oublog->course . '">' . fullname($comment) . '</a>');
             } else {
                 $output .= get_string('postedby', 'oublog', fullname($comment));
             }
         } else {
             $output .= get_string($canaudit ? 'postedbymoderatedaudit' : 'postedbymoderated', 'oublog', (object) array('commenter' => s($comment->authorname), 'approver' => '<a href="../../user/view.php?id=' . $comment->userid . '&amp;course=' . $oublog->course . '">' . fullname($post) . '</a>', 'approvedate' => oublog_date($comment->timeapproved), 'ip' => s($comment->authorip)));
         }
         $output .= html_writer::end_tag('div');
         $output .= html_writer::end_tag('div');
         $output .= html_writer::start_tag('div', array('class' => 'oublog-comment-content'));
         if (!$forexport) {
             if ($post->visibility == OUBLOG_VISIBILITY_PUBLIC) {
                 $fileurlbase = 'mod/oublog/pluginfile.php';
             } else {
                 $fileurlbase = 'pluginfile.php';
             }
             $comment->message = file_rewrite_pluginfile_urls($comment->message, $fileurlbase, $modcontext->id, 'mod_oublog', 'messagecomment', $comment->id);
         } else {
             $comment->message = portfolio_rewrite_pluginfile_urls($comment->message, $modcontext->id, 'mod_oublog', 'messagecomment', $comment->id, $format);
         }
         $output .= format_text($comment->message, FORMAT_HTML);
         $output .= html_writer::end_tag('div');
         $output .= html_writer::start_tag('div', array('class' => 'oublog-post-links'));
         if (!$comment->deletedby) {
             // You can delete your own comments, or comments on your own
             // personal blog, or if you can manage comments.
             if ($comment->userid && $comment->userid == $USER->id || $oublog->global && $post->userid == $USER->id || $canmanagecomments) {
                 if (!$forexport) {
                     $output .= '<a href="deletecomment.php?comment=' . $comment->id . '">' . $strdelete . '</a>';
                 } else {
                     $output .= $strdelete;
                 }
             }
         }
         // Show OU Alerts reporting link.
         if (isloggedin() && oublog_oualerts_enabled() && oublog_get_reportingemail($oublog) && !($comment->userid == $USER->id) && !$comment->deletedby) {
             $itmurl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id));
             $itemurl = $itmurl->out() . '#cid' . $comment->id;
             $retnurl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id));
             $returnurl = $retnurl->out() . '#cid' . $comment->id;
             $reportlink = oualerts_generate_alert_form_url('oublog', $modcontext->id, 'comment', $comment->id, $itemurl, $returnurl, '', false, true);
             if ($reportlink != '') {
                 $output .= html_writer::tag('a', get_string('commentalert', 'oublog'), array('href' => $reportlink));
             }
         }
         $output .= html_writer::end_tag('div');
         $output .= html_writer::end_tag('div');
         $counter++;
     }
     $output .= html_writer::end_tag('div');
     return $output;
 }