Esempio n. 1
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;
 }
Esempio n. 2
0
/**
 * If OU alerts is enabled, and the blog has reporting email setup,
 * if the user has the report/oualerts:managealerts capability for the context then
 * the link to the alerts report should be added.
 *
 * @global object
 * @global object
 */
function oublog_extend_settings_navigation(settings_navigation $settings, navigation_node $node)
{
    global $DB, $CFG, $PAGE;
    if (!($oublog = $DB->get_record("oublog", array("id" => $PAGE->cm->instance)))) {
        return;
    }
    include_once $CFG->dirroot . '/mod/oublog/locallib.php';
    if (oublog_oualerts_enabled() && oublog_get_reportingemail($oublog)) {
        if (has_capability('report/oualerts:managealerts', context_module::instance($PAGE->cm->id))) {
            $node->add(get_string('oublog_managealerts', 'oublog'), new moodle_url('/report/oualerts/manage.php', array('cmid' => $PAGE->cm->id, 'coursename' => $PAGE->course->id, 'contextcourseid' => $PAGE->course->id)), settings_navigation::TYPE_CUSTOM);
        }
    }
}