Пример #1
0
 * @package oublog
 */
require_once "../../config.php";
require_once "locallib.php";
$postid = required_param('post', PARAM_INT);
// Post id.
// Support redirects across systems - find post by username and time created.
$username = optional_param('u', '', PARAM_USERNAME);
$time = optional_param('time', 0, PARAM_INT);
if ($postid == 0 && !empty($username) && $time != 0) {
    // Search DB for an existing post (Personal blog only).
    $redirectto = new moodle_url('/mod/oublog/view.php', array('u' => $username));
    if (!($user = $DB->get_record('user', array('username' => $username), 'id'))) {
        print_error('invaliduser');
    }
    if (!(list($oublog, $oubloginstance) = oublog_get_personal_blog($user->id))) {
        // We redirect on error as system can create blog on access.
        redirect($redirectto);
    }
    // Get any posts matching user and time (If more than one just get first record).
    if (!($post = $DB->get_record('oublog_posts', array('oubloginstancesid' => $oubloginstance->id, 'timeposted' => $time), 'id', IGNORE_MULTIPLE))) {
        // Go to their blog home page if no post found.
        redirect($redirectto);
    }
    $postid = $post->id;
}
// This query based on the post id is so that we can get the blog etc to
// check permissions before calling oublog_get_post.
if (!($oublog = oublog_get_blog_from_postid($postid))) {
    print_error('invalidpost', 'oublog');
}
 public function test_oublog_tags()
 {
     global $USER, $DB, $SITE;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $course = $this->get_new_course();
     $stud1 = $this->get_new_user('student', $course->id);
     $group1 = $this->get_new_group($course->id);
     $group2 = $this->get_new_group($course->id);
     $this->get_new_group_member($group1->id, $stud1->id);
     // Whole course blog.
     $oublog = $this->get_new_oublog($course->id);
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $post = $this->get_post_stub($oublog->id);
     $post->tags = array('1', 'new', 'new', 'new2', 'a space');
     $postid = oublog_add_post($post, $cm, $oublog, $course);
     $this->assertEquals(21, strlen(oublog_get_tags_csv($postid)));
     $tags = oublog_get_tags($oublog, 0, $cm, null, -1);
     $this->assertCount(4, $tags);
     foreach ($tags as $tag) {
         $this->assertEquals(1, $tag->count);
         $this->assertContains($tag->tag, $post->tags);
     }
     // Individual blog.
     $oublog = $this->get_new_oublog($course->id, array('individual' => OUBLOG_VISIBLE_INDIVIDUAL_BLOGS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $post = $this->get_post_stub($oublog->id);
     $post->tags = array('1', 'new', 'new', 'new2', 'a space');
     $postid = oublog_add_post($post, $cm, $oublog, $course);
     $tags = oublog_get_tags($oublog, 0, $cm, null, $USER->id);
     $this->assertCount(4, $tags);
     $tags = oublog_get_tags($oublog, 0, $cm, null, $stud1->id);
     $this->assertEmpty($tags);
     // Group blog.
     $oublog = $this->get_new_oublog($course->id, array('groupmode' => VISIBLEGROUPS));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $post = $this->get_post_stub($oublog->id);
     $post->groupid = $group1->id;
     $post->tags = array('1', 'new', 'new', 'new2', 'a space');
     $postid = oublog_add_post($post, $cm, $oublog, $course);
     $tags = oublog_get_tags($oublog, $group1->id, $cm);
     $this->assertCount(4, $tags);
     $tags = oublog_get_tags($oublog, $group2->id, $cm);
     $this->assertEmpty($tags);
     // Personal blog.
     if (!($oublog = $DB->get_record('oublog', array('global' => 1)))) {
         $oublog = $this->get_new_oublog($SITE->id, array('global' => 1, 'maxvisibility' => OUBLOG_VISIBILITY_PUBLIC));
     }
     $cm = get_coursemodule_from_instance('oublog', $oublog->id);
     list($oublog, $bloginstance) = oublog_get_personal_blog($stud1->id);
     $post1stub = $this->get_post_stub($oublog->id);
     $post1stub->userid = $stud1->id;
     $post1stub->visibility = OUBLOG_VISIBILITY_COURSEUSER;
     // Private.
     $post1stub->tags = array('private');
     oublog_add_post($post1stub, $cm, $oublog, $SITE);
     $post2stub = $this->get_post_stub($oublog->id);
     $post2stub->userid = $stud1->id;
     $post2stub->visibility = OUBLOG_VISIBILITY_LOGGEDINUSER;
     // User must be logged in.
     $post2stub->tags = array('loggedin');
     oublog_add_post($post2stub, $cm, $oublog, $SITE);
     $post3stub = $this->get_post_stub($oublog->id);
     $post3stub->userid = $stud1->id;
     $post3stub->visibility = OUBLOG_VISIBILITY_PUBLIC;
     // Any user.
     $post3stub->tags = array('public');
     oublog_add_post($post3stub, $cm, $oublog, $SITE);
     $tags = oublog_get_tags($oublog, 0, $cm, $bloginstance->id);
     $this->assertCount(2, $tags);
     $this->setUser($stud1);
     $tags = oublog_get_tags($oublog, 0, $cm, $bloginstance->id);
     $this->assertCount(3, $tags);
     $this->setGuestUser();
     $tags = oublog_get_tags($oublog, 0, $cm, $bloginstance->id);
     $this->assertCount(1, $tags);
     $this->setUser($stud1);
     $post4stub = $this->get_post_stub($oublog->id);
     $post4stub->userid = $stud1->id;
     $post4stub->visibility = OUBLOG_VISIBILITY_PUBLIC;
     // Any user.
     // Add unordered alphabetic tags.
     $post4stub->tags = array('toad', 'newt', 'private', 'crock', 'loggedin', 'frog', 'public', 'dino');
     $postid = oublog_add_post($post4stub, $cm, $oublog, $course);
     $this->assertEquals(56, strlen(oublog_get_tags_csv($postid)));
     $post5stub = $this->get_post_stub($oublog->id);
     $post5stub->userid = $stud1->id;
     $post5stub->visibility = OUBLOG_VISIBILITY_PUBLIC;
     // Any user.
     // Add unordered alphabetic tags.
     $post5stub->tags = array('toad', 'private', 'crock', 'loggedin', 'frog', 'public', 'dino');
     $postid = oublog_add_post($post5stub, $cm, $oublog, $course);
     $this->assertEquals(50, strlen(oublog_get_tags_csv($postid)));
     // Recover tags with default ordering ie Alphabetic.
     $tags = oublog_get_tags($oublog, 0, $cm, null, -1);
     $this->assertCount(8, $tags);
     foreach ($tags as $tag) {
         $this->assertContains($tag->tag, $post4stub->tags);
     }
     $this->assertEquals('toad', $tag->tag);
     // Last in default, Alphabetical order.
     // Recover tags in Use order.
     $tags = oublog_get_tags($oublog, 0, $cm, null, -1, 'use');
     $this->assertCount(8, $tags);
     $lasttag = end($tags);
     $this->assertEquals('newt', $lasttag->tag);
     // Last when Use order specified.
     // Recover tags in Alphabetical order.
     $tags = oublog_get_tags($oublog, 0, $cm, null, -1, 'alpha');
     $this->assertCount(8, $tags);
     $lasttag = end($tags);
     $this->assertEquals('toad', $lasttag->tag);
     // Last when Alphabetic order specified.
     // Testing the create update of a blog instance with predefined tags.
     // set and also testing oublog_get_tag_list().
     // Whole course blog created with predefined tag set.
     $oublog = $this->get_new_oublog($course->id, array('tags' => 'blogtag01'));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     // Check that the predefined tag is inserted to the oublog_tags table.
     $blogtags = oublog_clarify_tags($oublog->tags);
     foreach ($blogtags as $tag) {
         $predefinedtags[] = $DB->get_record('oublog_tags', array('tag' => $tag));
     }
     // Confirm finding one predefined tag in the oublog_tags table.
     $this->assertCount(1, $predefinedtags);
     // Change the predefined tags on the blog.
     $oublog->tags = 'blogtag01, blogtag02';
     $oublog->instance = $oublog->id;
     oublog_update_instance($oublog);
     // Check that the changed tags are inserted to the oublog_tags table.
     $blogtags = oublog_clarify_tags($oublog->tags);
     foreach ($blogtags as $tag) {
         $changedtags[] = $DB->get_record('oublog_tags', array('tag' => $tag));
     }
     // Confirm finding predefined tags in the oublog_tags table.
     $this->assertCount(2, $changedtags);
     // Create post with 1 pre-defined and 1 user tag.
     $post = $this->get_post_stub($oublog->id);
     $post->tags = array('antelope', 'blogtag01');
     $postid = oublog_add_post($post, $cm, $oublog, $course);
     $this->assertEquals(19, strlen(oublog_get_tags_csv($postid)));
     // Recover post tags in default order.
     $tags = oublog_get_tags($oublog, 0, $cm, null, -1);
     foreach ($tags as $tag) {
         $this->assertEquals(1, $tag->count);
         $this->assertContains($tag->tag, $post->tags);
     }
     $this->assertNotEquals('antelope', $tag->tag);
     $this->assertEquals('blogtag01', $tag->tag);
     // Last in Alphabetical order.
     // Testing 'Set' tag only restrictions.
     // No restriction, recover full list of blog 'Set' and post tags.
     $oublog->restricttags = 0;
     $taglist = oublog_get_tag_list($oublog, 0, $cm, null, -1);
     $this->assertCount(3, $taglist);
     foreach ($taglist as $tag) {
         $fulltaglist[] = $tag->tag;
         if (isset($tag->label)) {
             // It should be an 'Official' ie. 'Set' predefined blog tag.
             $this->assertContains($tag->tag, $oublog->tags);
             $this->assertNotEmpty($tag->label);
             $this->assertGreaterThanOrEqual(0, $tag->count);
         }
         if (!isset($tag->label)) {
             // It should be the user post tag.
             $this->assertContains($tag->tag, $post->tags);
             $this->assertEquals('antelope', $tag->tag);
             $this->assertEquals(1, $tag->count);
         }
     }
     $this->assertContains('antelope', $fulltaglist);
     $this->assertContains('blogtag01', $fulltaglist);
     $this->assertContains('blogtag02', end($fulltaglist));
     // Last in full list.
     // Restriction applied, get restricted list of blog 'Set' tags.
     $oublog->restricttags = 1;
     $taglist = oublog_get_tag_list($oublog, 0, $cm, null, -1);
     $this->assertCount(2, $taglist);
     foreach ($taglist as $tag) {
         $restrictedtaglist[] = $tag->tag;
         if (isset($tag->label)) {
             // It should be an 'Official' ie. 'Set' predefined blog tag.
             $this->assertContains($tag->tag, $oublog->tags);
             $this->assertNotEmpty($tag->label);
             $this->assertGreaterThanOrEqual(0, $tag->count);
         }
         if (!isset($tag->label)) {
             $this->assertEmpty($tag->id);
             $this->assertEmpty($tag->weight);
             $this->assertEquals(0, $tag->count);
         }
     }
     $this->assertNotContains('antelope', $restrictedtaglist);
     $this->assertContains('blogtag01', $restrictedtaglist);
     $this->assertContains('blogtag02', end($restrictedtaglist));
     // Last in restricted list.
 }
$buttontext .= update_module_button($cm->id, $course->id, $stroublog);
$PAGEWILLCALLSKIPMAINDESTINATION = true;
// OU accessibility feature
$navigation = build_navigation($navlinks);
print_header_simple(format_string($oublog->name), "", $navigation, "", oublog_get_meta_tags($oublog, 'all', '', $cm), true, $buttontext, navmenu($course, $cm));
print '<div class="oublog-topofpage"></div>';
// The left column ...
if ($hasleft = !empty($CFG->showblocksonmodpages) && blocks_have_content($pageblocks, BLOCK_POS_LEFT)) {
    print '<div id="left-column">';
    blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
    print '</div>';
}
// The right column, BEFORE the middle-column.
print '<div id="right-column">';
if (isloggedin() and !isguestuser()) {
    list($oublog, $oubloginstance) = oublog_get_personal_blog($USER->id);
    $blogeditlink = "<br /><a href=\"view.php\" class=\"oublog-links\">{$oubloginstance->name}</a>";
    print_side_block(format_string($oublog->name), $blogeditlink, NULL, NULL, NULL, array('id' => 'oublog-summary'), get_string('bloginfo', 'oublog'));
}
if ($feeds = oublog_get_feedblock($oublog, 'all', '', false, $cm)) {
    print_side_block($strfeeds, $feeds, NULL, NULL, NULL, array('id' => 'oublog-feeds'), $strfeeds);
}
print '</div>';
// Start main column
$classes = '';
$classes .= $hasleft ? 'has-left-column ' : '';
$classes .= 'has-right-column ';
$classes = trim($classes);
if ($classes) {
    print '<div id="middle-column" class="' . $classes . '">';
} else {
Пример #4
0
 /**
  * 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;
     $output = '';
     $modcontext = context_module::instance($cm->id);
     $referurl = $baseurl;
     // Get rid of any existing tag from the URL as we only support one at a time.
     $baseurl = preg_replace('~&amp;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'));
     $output .= html_writer::start_tag('div', array('class' => 'oublog-social-container'));
     $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');
     }
     // Only show widgets if blog is global ect.
     if ($oublog->global && $oublog->maxvisibility == OUBLOG_VISIBILITY_PUBLIC) {
         if ($post->visibility == OUBLOG_VISIBILITY_PUBLIC && !$forexport && !$email) {
             list($oublog, $oubloginstance) = oublog_get_personal_blog($post->userid);
             $oubloginstancename = $oubloginstance->name;
             $linktext = get_string('tweet', 'oublog');
             $purl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id));
             $postname = !empty($post->title) ? $post->title : get_string('untitledpost', 'oublog');
             $output .= html_writer::start_tag('div', array('class' => 'oublog-post-socialshares'));
             $output .= get_string('share', 'oublog');
             $output .= html_writer::start_tag('div', array('class' => 'oublog-post-share'));
             // Show tweet link.
             $output .= html_writer::start_tag('div', array('class' => 'share-button'));
             $params = array('url' => $purl, 'dnt' => true, 'count' => 'none', 'text' => $postname . " " . $oubloginstance->name, 'class' => 'twitter-share-button');
             $turl = new moodle_url('https://twitter.com/share', $params);
             $output .= html_writer::link($turl, $linktext, $params);
             $output .= html_writer::end_tag('div');
             // Show facebook link.
             $output .= html_writer::start_tag('div', array('class' => 'share-button'));
             $output .= html_writer::start_tag('div', array('class' => 'fb-share-button', 'data-href' => $purl, 'data-colorscheme' => 'dark'));
             $output .= html_writer::end_tag('div');
             $output .= html_writer::end_tag('div');
             // Show googleplus link.
             $output .= html_writer::start_tag('div', array('class' => 'share-button'));
             $output .= html_writer::start_tag('div', array('class' => 'g-plus', 'data-href' => $purl, 'data-action' => 'share', 'data-height' => 20, 'data-annotation' => 'none'));
             $output .= html_writer::end_tag('div');
             $output .= html_writer::end_tag('div');
             $output .= html_writer::end_tag('div');
             $output .= html_writer::end_tag('div');
             // With JS enabled show social widget buttons.
             self::render_twitter_js();
             $output .= self::render_facebook_js();
             $output .= self::render_googleplus_js();
         }
     }
     $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 . '&amp;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;
         // Get rid of page from the URL we dont want it in tags.
         $pagelessurl = preg_replace('/&page=[^&]*/', '', $baseurl);
         foreach ($post->tags as $taglink) {
             $taglinktext = $taglink;
             if ($tagcounter < count($post->tags)) {
                 $taglinktext .= ',';
             }
             if (!$forexport && !$email) {
                 $output .= html_writer::tag('a', $taglinktext, array('href' => $pagelessurl . '&tag=' . urlencode($taglink))) . ' ';
             } else {
                 $output .= $taglinktext . ' ';
             }
             $tagcounter++;
         }
         $output .= html_writer::end_tag('div');
     }
     if (!$forexport && !$email) {
         // Output ratings.
         if (!empty($post->rating)) {
             $output .= html_writer::div($OUTPUT->render($post->rating), 'oublog-post-rating');
         }
     }
     $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 . '&referurl=' . urlencode($referurl))) . ' ';
                 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' . '&referurl=' . urlencode($referurl), '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' . '&referurl=' . urlencode($referurl)));
                 }
             }
         }
         // 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;
 }