/** * 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 . '&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 . '&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; }
public function definition() { global $COURSE, $CFG; $mform = $this->_form; $mform->addElement('header', 'general', get_string('general', 'form')); // Adding the standard "name" field. $mform->addElement('text', 'name', get_string('blogname', 'oublog'), array('size' => '64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); if (!defined('OUBLOG_EDIT_INSTANCE')) { $this->add_intro_editor(false, get_string('oublogintro', 'oublog')); // Adding the "allowcomments" field. $options = array(OUBLOG_COMMENTS_ALLOW => get_string('logincomments', 'oublog'), OUBLOG_COMMENTS_ALLOWPUBLIC => get_string('publiccomments', 'oublog'), OUBLOG_COMMENTS_PREVENT => get_string('nocomments', 'oublog')); $mform->addElement('select', 'allowcomments', get_string('allowcommentsmax', 'oublog'), $options); $mform->setType('allowcomments', PARAM_INT); $mform->addHelpButton('allowcomments', 'allowcomments', 'oublog'); // Adding the "individual" field. $options = array(OUBLOG_NO_INDIVIDUAL_BLOGS => get_string('no_blogtogetheroringroups', 'oublog'), OUBLOG_SEPARATE_INDIVIDUAL_BLOGS => get_string('separateindividualblogs', 'oublog'), OUBLOG_VISIBLE_INDIVIDUAL_BLOGS => get_string('visibleindividualblogs', 'oublog')); $mform->addElement('select', 'individual', get_string('individualblogs', 'oublog'), $options); $mform->setType('individual', PARAM_INT); $mform->setDefault('individual', OUBLOG_NO_INDIVIDUAL_BLOGS); $mform->addHelpButton('individual', 'individualblogs', 'oublog'); // Disable "maxvisibility" field when "individual" field is set (not default). $mform->disabledIf('maxvisibility', 'individual', OUBLOG_NO_INDIVIDUAL_BLOGS, OUBLOG_NO_INDIVIDUAL_BLOGS); // Adding the "maxvisibility" field. $options = array(OUBLOG_VISIBILITY_COURSEUSER => get_string('visiblecourseusers', 'oublog'), OUBLOG_VISIBILITY_LOGGEDINUSER => get_string('visibleloggedinusers', 'oublog'), OUBLOG_VISIBILITY_PUBLIC => get_string('visiblepublic', 'oublog')); $mform->addElement('select', 'maxvisibility', get_string('maxvisibility', 'oublog'), $options); $mform->setType('maxvisibility', PARAM_INT); $mform->addHelpButton('maxvisibility', 'maxvisibility', 'oublog'); // Whether intro text shows on post form pages. $mform->addElement('checkbox', 'introonpost', get_string('introonpost', 'oublog'), '', 0); // Max size of attachments. $modulesettings = get_config('mod_oublog'); $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'oublog'), $choices); $mform->addHelpButton('maxbytes', 'maxattachmentsize', 'oublog'); $mform->setDefault('maxbytes', $modulesettings->maxbytes); // Max number of attachments. $choices = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 50, 100); $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'oublog'), $choices); $mform->addHelpButton('maxattachments', 'maxattachments', 'oublog'); $mform->setDefault('maxattachments', $modulesettings->maxattachments); // Enable the stats block. $mform->addElement('checkbox', 'statblockon', get_string('statblockon', 'oublog'), '', 0); $mform->addHelpButton('statblockon', 'statblockon', 'oublog'); // Show OU Alerts reporting link. if (oublog_oualerts_enabled()) { $mform->addElement('text', 'reportingemail', get_string('reportingemail', 'oublog'), array('size' => '48')); $mform->addHelpButton('reportingemail', 'reportingemail', 'oublog'); $mform->setType('reportingemail', PARAM_NOTAGS); $mform->addRule('reportingemail', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); } $mform->addElement('text', 'displayname', get_string('displayname', 'oublog'), array('size' => '48')); $mform->addHelpButton('displayname', 'displayname', 'oublog'); $mform->setType('displayname', PARAM_NOTAGS); $mform->addRule('displayname', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->addElement('checkbox', 'allowimport', get_string('allowimport', 'oublog'), '', 0); $mform->addHelpButton('allowimport', 'allowimport', 'oublog'); $this->standard_grading_coursemodule_elements(); $mform->setDefault('grade', 0); // Add standard elements, common to all modules. $features = new stdClass(); $features->groupings = true; $features->groupmembersonly = true; $this->standard_coursemodule_elements($features); } else { // Adding the "summary" field. $mform->addElement('editor', 'summary_editor', get_string('summary', 'oublog'), null, array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes)); $mform->setType('summary', PARAM_RAW); $mform->addElement('hidden', 'instance'); $mform->setType('instance', PARAM_INT); } // Add standard buttons, common to all modules. $this->add_action_buttons(); }
/** * 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); } } }