$mreturnurl = new moodle_url('/mod/oublog/view.php', array('user' => $user)); } else { $returnurl = $CFG->wwwroot . '/mod/oublog/view.php?id=' . $id; $mreturnurl = new moodle_url('/mod/oublog/view.php', array('id' => $id)); } // Set up groups $currentgroup = oublog_get_activity_group($cm, true); $groupmode = oublog_get_activity_groupmode($cm, $course); // Note I am not sure this check is necessary, maybe it is handled by // oublog_get_activity_group? Or maybe more checks are needed? Not sure. if ($currentgroup === 0 && $groupmode == SEPARATEGROUPS) { require_capability('moodle/site:accessallgroups', $context); } // Print the header $stroublog = get_string('modulename', 'oublog'); $strblogsearch = get_string('searchthisblog', 'oublog', oublog_get_displayname($oublog)); $strblogssearch = get_string('searchblogs', 'oublog'); if ($oublog->global) { if (!is_null($oubloginstance)) { $name = $oubloginstance->name; $buttontext = oublog_get_search_form('user', $oubloguser->id, $strblogsearch, $querytexthtml); } else { $buttontext = oublog_get_search_form('id', $cm->id, $strblogssearch, $querytexthtml); } if (isset($name)) { $PAGE->navbar->add(fullname($oubloguser), new moodle_url('/user/view.php', array('id' => $oubloguser->id))); $PAGE->navbar->add(format_string($oubloginstance->name), $mreturnurl); } else { $PAGE->navbar->add(format_string($oublog->name), new moodle_url('/mod/oublog/allposts.php')); } } else {
$subject = strtoupper(get_string('copy')) . ' - ' . $post->title; foreach ($emails as $email) { $fakeuser = (object) array('email' => $email, 'mailformat' => 1, 'id' => -1); if (!email_to_user($fakeuser, $from, $subject, '', $messagehtml)) { print_error(get_string('emailerror', 'oublog')); } } } redirect($viewurl); } else { if ($delete && $email) { // If subject is set in this post, use it. if (!isset($post->title) || empty($post->title)) { $post->title = get_string('deletedblogpost', 'oublog'); } $displayname = oublog_get_displayname($oublog, true); // Prepare the object for the emailcontenthtml get_string. $emailmessage = new stdClass(); $emailmessage->subject = $post->title; $emailmessage->blog = $oublog->name; $emailmessage->activityname = $displayname; $emailmessage->firstname = $USER->firstname; $emailmessage->lastname = $USER->lastname; $emailmessage->course = $COURSE->fullname; $emailmessage->deleteurl = $CFG->wwwroot . '/mod/oublog/viewpost.php?&post=' . $post->id; $formdata = new stdClass(); $messagetext = get_string('emailcontenthtml', 'oublog', $emailmessage); $formdata->message['text'] = $messagetext; // Display the form. echo $OUTPUT->header(); $mform->set_data($formdata);
print_error('invalidcoursemodule'); } if (!($oublog = $DB->get_record('oublog', array('id' => $cm->instance)))) { print_error('invalidcoursemodule'); } $context = context_module::instance($cm->id); $tempoublog = clone $oublog; if ($tempoublog->global) { $tempoublog->maxvisibility = OUBLOG_VISIBILITY_LOGGEDINUSER; // Force login regardless of setting. } else { $tempoublog->maxvisibility = OUBLOG_VISIBILITY_COURSEUSER; // Force login regardless of setting. } oublog_check_view_permissions($tempoublog, $context, $cm); $blogname = oublog_get_displayname($oublog); // Is able to import check for current blog. if (!$oublog->allowimport || !$oublog->global && $oublog->individual == OUBLOG_NO_INDIVIDUAL_BLOGS) { // Must have import enabled. Individual blog mode only. print_error('import_notallowed', 'oublog', null, $blogname); } // Check if group mode set - need to check user is in selected group etc. $groupmode = oublog_get_activity_groupmode($cm, $course); $currentgroup = 0; if ($groupmode != NOGROUPS) { $currentgroup = oublog_get_activity_group($cm); $ingroup = groups_is_member($currentgroup); if ($oublog->individual != OUBLOG_NO_INDIVIDUAL_BLOGS && ($currentgroup && !$ingroup)) { // Must be group memeber for individual blog with group mode on. print_error('import_notallowed', 'oublog', null, $blogname); }
print $OUTPUT->skip_link_target(); // Renderer hook so extra info can be added to global blog pages in theme. echo $oublogoutput->render_viewpage_prepost(); // Print blog posts. if ($posts) { echo "<div class='oublog-paging'>"; echo $OUTPUT->paging_bar($recordcount, $page, OUBLOG_POSTS_PER_PAGE, $returnurl); echo '</div>'; echo '<div id="oublog-posts">'; $rowcounter = 1; foreach ($posts as $post) { $post->row = $rowcounter; echo $oublogoutput->render_post($cm, $oublog, $post, $returnurl, $blogtype, $canmanageposts, $canaudit, true, false); $rowcounter++; } echo "<div class='oublog-paging'>"; echo $OUTPUT->paging_bar($recordcount, $page, OUBLOG_POSTS_PER_PAGE, $returnurl); echo '</div>'; } // Print information allowing the user to log in if necessary, or letting // them know if there are no posts in the blog. if (!isloggedin() || isguestuser()) { print '<p class="oublog_loginnote">' . get_string('maybehiddenposts', 'oublog', (object) array('link' => 'bloglogin.php', 'name' => oublog_get_displayname($oublog))) . '</p>'; } else { if (!$posts) { print '<p class="oublog_noposts">' . get_string('noposts', 'oublog', oublog_get_displayname($oublog)) . '</p>'; } } print '</div>'; // Finish the page. echo $OUTPUT->footer();
/** * Print a single blog post * * @param object $oublog Blog object * @param object $post Structure containing all post info and comments * @param string $baseurl Base URL of current page * @param string $blogtype Blog level ie course or above * @param bool $canmanageposts Has capability toggle * @param bool $canaudit Has capability toggle * @param bool $cancomment Has capability toggle * @param bool $forexport Export output rendering toggle * @param bool $email Email output rendering toggle * @return bool */ public function render_post($cm, $oublog, $post, $baseurl, $blogtype, $canmanageposts = false, $canaudit = false, $commentcount = true, $forexport = false, $format = false, $email = false) { global $CFG, $USER; $output = ''; $modcontext = context_module::instance($cm->id); // Get rid of any existing tag from the URL as we only support one at a time. $baseurl = preg_replace('~&tag=[^&]*~', '', $baseurl); $strcomment = get_string('comment', 'oublog'); $strtags = get_string('tags', 'oublog'); $stredit = get_string('edit', 'oublog'); $strdelete = get_string('delete', 'oublog'); $strpermalink = get_string('permalink', 'oublog'); $row = ''; if (isset($post->row)) { $row = $post->row % 2 ? 'oublog-odd' : 'oublog-even'; } $extraclasses = $post->deletedby ? ' oublog-deleted' : ''; $extraclasses .= ' oublog-hasuserpic'; $extraclasses .= ' ' . $row; $output .= html_writer::start_tag('div', array('class' => 'oublog-post' . $extraclasses)); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top')); $fs = get_file_storage(); if ($files = $fs->get_area_files($modcontext->id, 'mod_oublog', 'attachment', $post->id, "timemodified", false)) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-attachments')); $output .= get_string('attachments', 'mod_oublog') . ': '; foreach ($files as $file) { if (!$forexport && !$email) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = html_writer::empty_tag('img', array('src' => $this->output->pix_url(file_mimetype_icon($mimetype)), 'alt' => $mimetype, 'class' => 'icon')); if ($post->visibility == OUBLOG_VISIBILITY_PUBLIC) { $fileurlbase = '/mod/oublog/pluginfile.php'; } else { $fileurlbase = '/pluginfile.php'; } $filepath = '/' . $modcontext->id . '/mod_oublog/attachment/' . $post->id . '/' . $filename; $path = moodle_url::make_file_url($fileurlbase, $filepath, true); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-attachment')); $output .= html_writer::tag('a', $iconimage, array('href' => $path)); $output .= html_writer::tag('a', s($filename), array('href' => $path)); $output .= html_writer::end_tag('div'); } else { $filename = $file->get_filename(); if (is_object($format)) { $output .= $format->file_output($file) . ' '; } else { $output .= $filename . ' '; } } } $output .= html_writer::end_tag('div'); } $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top-content')); if (!$forexport) { $output .= html_writer::start_tag('div', array('class' => 'oublog-userpic')); $postuser = new object(); $postuser->id = $post->userid; $postuser->firstname = $post->firstname; $postuser->lastname = $post->lastname; $postuser->email = $post->email; $postuser->imagealt = $post->imagealt; $postuser->picture = $post->picture; $postuser->firstnamephonetic = $post->firstnamephonetic; $postuser->lastnamephonetic = $post->lastnamephonetic; $postuser->middlename = $post->middlename; $postuser->alternatename = $post->alternatename; $output .= $this->output->user_picture($postuser, array('courseid' => $oublog->course, 'size' => 70)); $output .= html_writer::end_tag('div'); } $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top-details')); $formattedtitle = format_string($post->title); if (trim($formattedtitle) !== '') { $output .= html_writer::tag('h2', format_string($post->title), array('class' => 'oublog-title')); } else { if (!$forexport) { $posttitle = get_accesshide(get_string('newpost', 'mod_oublog', oublog_get_displayname($oublog))); $output .= html_writer::tag('h2', $posttitle, array('class' => 'oublog-title')); } } if ($post->deletedby) { $deluser = new stdClass(); // Get user name fields. $delusernamefields = get_all_user_name_fields(false, null, 'del'); foreach ($delusernamefields as $namefield => $retnamefield) { $deluser->{$namefield} = $post->{$retnamefield}; } $a = new stdClass(); $a->fullname = html_writer::tag('a', fullname($deluser), array('href' => $CFG->wwwroot . '/user/view.php?id=' . $post->deletedby)); $a->timedeleted = oublog_date($post->timedeleted); $output .= html_writer::tag('div', get_string('deletedby', 'oublog', $a), array('class' => 'oublog-post-deletedby')); } $output .= html_writer::start_tag('div', array('class' => 'oublog-post-date')); $output .= oublog_date($post->timeposted); $output .= html_writer::empty_tag('br', array()); $output .= ' '; if ($blogtype == 'course' || strpos($_SERVER['REQUEST_URI'], 'allposts.php') != 0) { $output .= html_writer::start_tag('div', array('class' => 'oublog-postedby')); if (!$forexport) { $output .= get_string('postedby', 'oublog', '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->userid . '&course=' . $oublog->course . '">' . fullname($post) . '</a>'); } else { $output .= get_string('postedby', 'oublog', fullname($post)); } $output .= html_writer::end_tag('div'); } $output .= html_writer::end_tag('div'); if (!$oublog->individual) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-visibility')); $output .= oublog_get_visibility_string($post->visibility, $blogtype == 'personal'); $output .= html_writer::end_tag('div'); } if (isset($post->edits) && ($canaudit || $post->userid == $USER->id)) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-editsummary')); foreach ($post->edits as $edit) { $a = new stdClass(); $a->editby = fullname($edit); $a->editdate = oublog_date($edit->timeupdated); if (!$forexport && !$email) { if ($edit->userid == $post->userid) { $output .= '- ' . html_writer::tag('a', get_string('editsummary', 'oublog', $a), array('href' => $CFG->wwwroot . '/mod/oublog/viewedit.php?edit=' . $edit->id)); } else { $output .= '- ' . html_writer::tag('a', get_string('editonsummary', 'oublog', $a), array('href' => $CFG->wwwroot . '/mod/oublog/viewedit.php?edit=' . $edit->id)); } } else { if ($edit->userid == $post->userid) { $output .= '- ' . get_string('editsummary', 'oublog', $a); } else { $output .= '- ' . get_string('editonsummary', 'oublog', $a); } } $output .= html_writer::empty_tag('br', array()); } $output .= html_writer::end_tag('div'); } else { if ($post->lasteditedby) { $edit = new StdClass(); // Get user name fields. $editusernamefields = get_all_user_name_fields(false, null, 'ed'); foreach ($editusernamefields as $namefield => $retnamefield) { $edit->{$namefield} = $post->{$retnamefield}; } $a = new stdClass(); $a->editby = fullname($edit); $a->editdate = oublog_date($post->timeupdated); $output .= html_writer::tag('div', get_string('editsummary', 'oublog', $a), array('class' => 'oublog-post-editsummary')); } } $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-content')); if (!$forexport) { if ($post->visibility == OUBLOG_VISIBILITY_PUBLIC || $email) { $fileurlbase = 'mod/oublog/pluginfile.php'; } else { $fileurlbase = 'pluginfile.php'; } $post->message = file_rewrite_pluginfile_urls($post->message, $fileurlbase, $modcontext->id, 'mod_oublog', 'message', $post->id); } else { require_once $CFG->libdir . '/portfoliolib.php'; $post->message = portfolio_rewrite_pluginfile_urls($post->message, $modcontext->id, 'mod_oublog', 'message', $post->id, $format); } $posttextoptions = new stdClass(); if (trusttext_active() && has_capability('moodle/site:trustcontent', $modcontext, $post->userid)) { // Support trusted text when initial author is safe (post editors are not checked!). $posttextoptions->trusted = true; $posttextoptions->context = $modcontext; } $output .= format_text($post->message, FORMAT_HTML, $posttextoptions); $output .= html_writer::end_tag('div'); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-bottom')); if (isset($post->tags)) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-tags')) . $strtags . ': '; $tagcounter = 1; foreach ($post->tags as $taglink) { $taglinktext = $taglink; if ($tagcounter < count($post->tags)) { $taglinktext .= ','; } if (!$forexport && !$email) { $output .= html_writer::tag('a', $taglinktext, array('href' => $baseurl . '&tag=' . urlencode($taglink))) . ' '; } else { $output .= $taglinktext . ' '; } $tagcounter++; } $output .= html_writer::end_tag('div'); } $output .= html_writer::start_tag('div', array('class' => 'oublog-post-links')); if (!$forexport && !$email) { $output .= html_writer::tag('a', $strpermalink, array('href' => $CFG->wwwroot . '/mod/oublog/viewpost.php?post=' . $post->id)) . ' '; } if (!$post->deletedby) { if ($post->userid == $USER->id || $canmanageposts) { if (!$forexport && !$email) { $output .= html_writer::tag('a', $stredit, array('href' => $CFG->wwwroot . '/mod/oublog/editpost.php?blog=' . $post->oublogid . '&post=' . $post->id)) . ' '; if ($post->userid !== $USER->id) { // Add email and 'oublog_deleteandemail' to delete link. $output .= html_writer::tag('a', $strdelete, array('href' => $CFG->wwwroot . '/mod/oublog/deletepost.php?blog=' . $post->oublogid . '&post=' . $post->id . '&delete=1', 'class' => 'oublog_deleteandemail_' . $post->id)); self::render_oublog_print_delete_dialog($cm->id, $post->id); } else { $output .= html_writer::tag('a', $strdelete, array('href' => $CFG->wwwroot . '/mod/oublog/deletepost.php?blog=' . $post->oublogid . '&post=' . $post->id . '&delete=1')); } } } // Show portfolio export link. if (!empty($CFG->enableportfolios) && (has_capability('mod/oublog:exportpost', $modcontext) || $post->userid == $USER->id && has_capability('mod/oublog:exportownpost', $modcontext))) { if (!$forexport && !$email) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('oublog_portfolio_caller', array('postid' => $post->id), 'mod_oublog'); if (empty($files)) { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } $output .= $button->to_html(PORTFOLIO_ADD_TEXT_LINK) . ' '; } } // Show OU Alerts reporting link. if (isloggedin() && oublog_oualerts_enabled() && oublog_get_reportingemail($oublog) && !($post->userid == $USER->id) && !$post->deletedby) { $itemnurl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id)); $reportlink = oualerts_generate_alert_form_url('oublog', $modcontext->id, 'post', $post->id, $itemnurl, $itemnurl, '', false, true); if ($reportlink != '' && !$forexport && !$email) { $output .= html_writer::tag('a', get_string('postalert', 'oublog'), array('href' => $reportlink)); } } // Show comments. if ($post->allowcomments) { // If this is the current user's post, show pending comments too. $showpendingcomments = $post->userid == $USER->id && !empty($post->pendingcomments); if ((isset($post->comments) || $showpendingcomments) && $commentcount) { // Show number of comments. if (isset($post->comments)) { $linktext = get_string(count($post->comments) == 1 ? 'onecomment' : 'ncomments', 'oublog', count($post->comments)); } // Show number of pending comments. if (isset($post->pendingcomments)) { // Use different string if we already have normal comments too. if (isset($post->comments)) { $linktext .= get_string($post->pendingcomments == 1 ? 'onependingafter' : 'npendingafter', 'oublog', $post->pendingcomments); } else { $linktext = get_string($post->pendingcomments == 1 ? 'onepending' : 'npending', 'oublog', $post->pendingcomments); } } if (!$forexport) { // Display link. $output .= html_writer::tag('a', $linktext, array('href' => $CFG->wwwroot . '/mod/oublog/viewpost.php?post=' . $post->id . '#oublogcomments')); } else { $output .= $linktext; } // Display information about most recent comment. if (isset($post->comments)) { $last = array_pop($post->comments); array_push($post->comments, $last); $a = new stdClass(); if ($last->userid) { $a->fullname = fullname($last); } else { $a->fullname = s($last->authorname); } $a->timeposted = oublog_date($last->timeposted, true); $output .= ' ' . get_string('lastcomment', 'oublog', $a); } } else { if (oublog_can_comment($cm, $oublog, $post)) { if (!$forexport && !$email) { $output .= html_writer::tag('a', $strcomment, array('href' => $CFG->wwwroot . '/mod/oublog/editcomment.php?blog=' . $post->oublogid . '&post=' . $post->id)); } } } } } $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); return $output; }
/** * Returns blog info - cm, oublog * Also checks is a valid blog for import * (Throws exception on access error) * @param int $cmid * @param int $userid * @return array (cm id, oublog id, context id, blog name, course shortname) */ function oublog_import_getbloginfo($cmid, $userid = 0) { global $DB, $USER; if ($userid == 0) { $userid = $USER->id; } $bcourse = $DB->get_record_select('course', 'id = (SELECT course FROM {course_modules} WHERE id = ?)', array($cmid), '*', MUST_EXIST); $bmodinfo = get_fast_modinfo($bcourse, $userid); $bcm = $bmodinfo->get_cm($cmid); if ($bcm->modname !== 'oublog') { throw new moodle_exception('invalidcoursemodule', 'error'); } if (!($boublog = $DB->get_record('oublog', array('id' => $bcm->instance)))) { throw new moodle_exception('invalidcoursemodule', 'error'); } $bcontext = context_module::instance($bcm->id); $canview = $bcm->uservisible; if ($canview) { $canview = has_capability('mod/oublog:view', $bcontext, $userid); } if ($boublog->global) { // Ignore uservisible for global blog and only check cap. $canview = has_capability('mod/oublog:viewpersonal', context_system::instance(), $userid); } if (!$canview || !$boublog->global && $boublog->individual == OUBLOG_NO_INDIVIDUAL_BLOGS) { // Not allowed to get pages from selected blog. throw new moodle_exception('import_notallowed', 'oublog', '', oublog_get_displayname($boublog)); } if ($boublog->global) { $boublogname = $DB->get_field('oublog_instances', 'name', array('oublogid' => $boublog->id, 'userid' => $userid)); $shortname = ''; } else { $boublogname = $bcm->get_course()->shortname . ' ' . get_course_display_name_for_list($bcm->get_course()) . ' : ' . $bcm->get_formatted_name(); $shortname = $bcm->get_course()->shortname; } return array($bcm->id, $boublog->id, $bcontext->id, $boublogname, $shortname); }
} echo '</div>'; } // Print information allowing the user to log in if necessary, or letting // them know if there are no posts in the blog. if (isguestuser() && $USER->id == $user) { print '<p class="oublog_loginnote">' . get_string('guestblog', 'oublog', 'bloglogin.php?returnurl=' . urlencode($returnurl)) . '</p>'; } else { if (!isloggedin() || isguestuser()) { print '<p class="oublog_loginnote">' . get_string('maybehiddenposts', 'oublog', (object) array('link' => 'bloglogin.php?returnurl=' . urlencode($returnurl), 'name' => oublog_get_displayname($oublog))) . '</p>'; } else { if (!$posts) { if (!$tag) { $errormessage = get_string('noposts', 'oublog', oublog_get_displayname($oublog)); } else { $a = array('blog' => oublog_get_displayname($oublog), 'tag' => $tag); $errormessage = get_string('nopostsnotags', 'oublog', $a); } print '<p class="oublog_noposts">' . $errormessage . ' </p>'; } } } // Log oublog page view. $params = array('context' => $context, 'objectid' => $oublog->id); $event = \mod_oublog\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $course); $event->trigger(); $views = oublog_update_views($oublog, $oubloginstance); // Finish the page. echo "<div class=\"clearer\"></div><div class=\"oublog-views\">{$strviews} {$views}</div></div>";
/** * Print all user participation records for display * * @param object $cm current course module object * @param object $course current course object * @param object $oublog current oublog object * @param int $page html_table pagination page * @param array $participation mixed array of user participation values */ public function render_all_users_participation_table($cm, $course, $oublog, $page, $limitnum, $participation, $getposts, $getcomments, $start, $end, $pagingurl) { global $DB, $CFG, $OUTPUT, $USER; require_once $CFG->dirroot . '/mod/oublog/participation_table.php'; $groupmode = oublog_get_activity_groupmode($cm, $course); $thepagingbar = ""; if (!empty($participation->posts) && $participation->postscount > $limitnum) { $thepagingbar = $OUTPUT->paging_bar($participation->postscount, $page, $limitnum, $pagingurl); } else { if (!empty($participation->comments) && $participation->commentscount > $limitnum) { $thepagingbar = $OUTPUT->paging_bar($participation->commentscount, $page, $limitnum, $pagingurl); } } if ($getposts) { $output = ''; $output .= html_writer::tag('h2', $participation->postscount . ' ' . get_string('posts', 'oublog')); // Provide paging if postscount exceeds posts perpage. $output .= $thepagingbar; $poststable = new html_table(); $poststable->head = array(get_string('user'), get_string('title', 'oublog'), get_string('date'), oublog_get_displayname($oublog, true)); $poststable->size = array('25%', '25%', '25%', '25%'); $poststable->colclasses = array('oublog_usersinfo_col', '', '', ''); $poststable->attributes['class'] = 'oublog generaltable '; $poststable->data = array(); foreach ($participation->posts as $post) { // Post user object required for user_picture. $postuser = new object(); $postuser->id = $post->userid; $fields = explode(',', user_picture::fields('', null, '', 'poster')); foreach ($fields as $field) { if ($field != 'id') { $postuser->{$field} = $post->{$field}; } } $fullname = fullname($postuser); $row = array(); $row[] = $OUTPUT->user_picture($postuser, array('class' => 'userpicture')) . $fullname; $url = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id)); $postname = !empty($post->title) ? $post->title : get_string('untitledpost', 'oublog'); $row[] = html_writer::div(html_writer::link($url, $postname), ''); $row[] = html_writer::div(oublog_date($post->timeposted)); $bparams = array('id' => $cm->id); $linktext = $name = $grpname = $dispname = ''; if (oublog_get_displayname($oublog)) { $dispname = oublog_get_displayname($oublog); } if ($post->blogname != "") { $linktext = $post->blogname; } else { if ($oublog->name != "") { if ($groupmode > NOGROUPS && isset($post->groupid) && $post->groupid > 0) { $bparams['group'] = $post->groupid; $grpname = groups_get_group_name($post->groupid); } else { if ($oublog->individual != OUBLOG_NO_INDIVIDUAL_BLOGS) { $bparams['individual'] = $post->userid; $name = fullname($postuser); } } if ($post->groupid == 0 && $oublog->individual > OUBLOG_NO_INDIVIDUAL_BLOGS) { $name = fullname($postuser); } else { if (!$groupmode) { $name = $oublog->name; } } $a = (object) array('name' => $grpname . " " . $name, 'displayname' => $dispname); $linktext = get_string('defaultpersonalblogname', 'oublog', $a); } } if (!$groupmode && !$oublog->global && $oublog->individual == 0) { $a = (object) array('name' => $grpname . " " . $name, 'displayname' => $dispname); $linktext = get_string('defaultpersonalblogname', 'oublog', $a); } if (!$groupmode) { $linktext = $name; } $burl = new moodle_url('/mod/oublog/view.php', $bparams); $row[] = html_writer::link($burl, $linktext); $poststable->data[] = $row; } $output .= html_writer::table($poststable); $output .= $thepagingbar; return $output; } if ($getcomments) { $output = ''; // Do the comments stuff here. if (!$participation->comments) { $output .= html_writer::tag('h2', get_string('nousercomments', 'oublog')); } else { $output .= html_writer::tag('h2', $participation->commentscount . ' ' . get_string('comments', 'oublog')); // Provide paging if commentscount exceeds posts perpage. $output .= $thepagingbar; $commenttable = new html_table(); $commenttable->head = array(get_string('user'), get_string('title', 'oublog'), get_string('date'), get_string('post')); $commenttable->size = array('25%', '25%', '25%', '25%'); $commenttable->colclasses = array('oublog_usersinfo_col ', '', '', 'oublog_postsinfo_col'); $commenttable->attributes['class'] = 'oublog generaltable '; $commenttable->data = array(); unset($bparams); foreach ($participation->comments as $comment) { $row = array(); // Comment author object required for user_picture. $commentauthor = new stdClass(); $commentauthor->id = $comment->commenterid; $fields = explode(',', user_picture::fields('', null, '', 'commenter')); foreach ($fields as $field) { if ($field != 'id') { $cfield = "commenter" . $field; $commentauthor->{$field} = $comment->{$cfield}; } } $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $comment->postid)); $viewpostcommenturl = $viewposturl->out() . '#cid' . $comment->id; $commenttitle = !empty($comment->title) ? $comment->title : get_string('untitledcomment', 'oublog'); $posttitle = !empty($comment->posttitle) ? $comment->posttitle : get_string('untitledpost', 'oublog'); $viewcommentlink = html_writer::link($viewpostcommenturl, s($commenttitle)); // User cell. $usercell = $OUTPUT->user_picture($commentauthor, array('class' => 'userpicture')); $usercell .= html_writer::start_tag('div', array('class' => '')); $usercell .= fullname($commentauthor); $usercell .= html_writer::end_tag('div'); $row[] = $usercell; // Comments cell. $row[] = $viewcommentlink; // Comment date cell. $row[] = userdate($comment->timeposted); // Start of cell 4 code should resemble view page block code. $postauthor = new stdClass(); $postauthor->id = $comment->posterid; $postauthor->groupid = $comment->groupid; $fields = explode(',', user_picture::fields('', null, '', 'poster')); foreach ($fields as $field) { if ($field != 'id') { $pfield = "poster" . $field; $postauthor->{$field} = $comment->{$pfield}; } } $bparams = array('id' => $cm->id); $linktext = $name = $grpname = $dispname = ''; if (oublog_get_displayname($oublog)) { $dispname = oublog_get_displayname($oublog); } if ($comment->bloginstancename != '') { $bparams['individual'] = $comment->posterid; $bparams['group'] = $comment->groupid; $name = fullname($postauthor); } else { if ($oublog->name != "") { if ($groupmode > NOGROUPS && isset($comment->groupid) && $comment->groupid > 0) { $bparams['group'] = $comment->groupid; $grpname = groups_get_group_name($comment->groupid); } else { if ($oublog->individual != OUBLOG_NO_INDIVIDUAL_BLOGS) { $bparams['individual'] = $comment->posterid; $name = fullname($postauthor); } } if ($comment->groupid == 0 && $oublog->individual > OUBLOG_NO_INDIVIDUAL_BLOGS) { $name = fullname($postauthor); } else { if (!$groupmode) { $name = $oublog->name; } } $a = (object) array('name' => $grpname . $name, 'displayname' => $dispname); $linktext = get_string('defaultpersonalblogname', 'oublog', $a); } } if (!$groupmode && !$oublog->global && $oublog->individual == 0) { // Personal or course wide. $a = (object) array('name' => $grpname . $name, 'displayname' => $dispname); $linktext = get_string('defaultpersonalblogname', 'oublog', $a); } if (!$groupmode) { $linktext = $name; } $postauthorurl = new moodle_url('/mod/oublog/view.php', $bparams); $postauthorlink = html_writer::link($postauthorurl, $linktext); $viewpostlink = html_writer::link($viewposturl, s($posttitle)); // Posts cell. $postscell = html_writer::start_tag('div', array('class' => 'oublog_postsinfo')); $postscell .= $OUTPUT->user_picture($postauthor, array('courseid' => $oublog->course, 'class' => 'userpicture')); $postscell .= html_writer::start_tag('div', array('class' => 'oublog_postscell')); $postscell .= html_writer::start_tag('div', array('class' => 'oublog_postsinfo_label')); $postscell .= html_writer::start_tag('div', array('class' => 'oublog_postscell_posttitle')); $postscell .= html_writer::link($postauthorlink, $viewpostlink); $postscell .= html_writer::end_tag('div'); $postscell .= html_writer::start_tag('div', array('class' => 'oublogstats_commentposts_blogname')); $postscell .= html_writer::empty_tag('br', array()); $postscell .= oublog_date($comment->postdate); $postscell .= html_writer::empty_tag('br', array()); $postscell .= $postauthorlink; $postscell .= html_writer::end_tag('div'); $postscell .= html_writer::end_tag('div'); $postscell .= html_writer::end_tag('div'); $postscell .= html_writer::end_tag('div'); $postscell .= html_writer::end_tag('div'); $row[] = $postscell; $commenttable->data[] = $row; } $output .= html_writer::table($commenttable); $output .= $thepagingbar; return $output; } } }
// If editing a post, must be your post or you have manageposts $canmanage = has_capability('mod/oublog:manageposts', $context); if (isset($post) && $USER->id != $oubloginstance->userid && !$canmanage) { print_error('accessdenied', 'oublog'); } // Must be able to post in order to post OR edit a post. This is so that if // somebody is blocked from posting, they can't just edit an existing post. // Exception is that admin is allowed to edit posts even though they aren't // allowed to post to the blog. if (!(oublog_can_post($oublog, isset($oubloginstance) ? $oubloginstance->userid : 0, $cm) || isset($post) && $canmanage)) { print_error('accessdenied', 'oublog'); } // Get strings. $stroublogs = get_string('modulenameplural', 'oublog'); $stroublog = get_string('modulename', 'oublog'); $straddpost = get_string('newpost', 'oublog', oublog_get_displayname($oublog)); $streditpost = get_string('editpost', 'oublog'); // Set-up groups. $currentgroup = oublog_get_activity_group($cm, true); $groupmode = oublog_get_activity_groupmode($cm, $course); if ($groupmode == VISIBLEGROUPS && !groups_is_member($currentgroup) && !$oublog->individual) { require_capability('moodle/site:accessallgroups', $context); } $mform = new mod_oublog_post_form('editpost.php', array('individual' => $oublog->individual, 'maxvisibility' => $oublog->maxvisibility, 'allowcomments' => $oublog->allowcomments, 'edit' => !empty($postid), 'personal' => $oublog->global, 'maxbytes' => $oublog->maxbytes, 'maxattachments' => $oublog->maxattachments)); if ($mform->is_cancelled()) { redirect($viewurl); exit; } if (!($frmpost = $mform->get_data())) { if ($postid) { $post->post = $post->id;