public function test_create_content() { global $USER, $DB; $this->resetAfterTest(true); $this->setAdminUser(); $generator = $this->getDataGenerator()->get_plugin_generator('mod_oublog'); $options = new stdClass(); $options->course = $this->getDataGenerator()->create_course(); $oublog = $generator->create_instance($options); $postid = $generator->create_content($oublog); $post = oublog_get_post($postid); $this->assertInstanceOf('stdClass', $post); $this->assertEquals($USER->id, $post->userid); // Try making post with basic options. $postid = $generator->create_content($oublog, array('post' => (object) array('message' => 'testing'))); $post = $DB->get_record('oublog_posts', array('id' => $postid)); $this->assertInstanceOf('stdClass', $post); $this->assertEquals('testing', $post->message); // Test calling using oublog_test_lib inc attachments. $postid = $this->get_new_post($oublog); $post = $DB->get_record('oublog_posts', array('id' => $postid)); $this->assertInstanceOf('stdClass', $post); $postid = $this->get_new_post($oublog, (object) array('attachments' => array('tst.txt' => 'abcd'))); $fs = get_file_storage(); $file = $fs->get_file_by_id($DB->get_field('files', 'id', array('component' => 'mod_oublog', 'filename' => 'tst.txt'))); $this->assertInstanceOf('stored_file', $file); $this->assertEquals('tst.txt', $file->get_filename()); // Add an invalid comment and test exception. try { $commentid = $generator->create_content($oublog, array('comment' => (object) array())); $this->fail('Exception expected as no post id sent when adding comment'); } catch (coding_exception $e) { $this->assertEquals('Must pass postid when creating comment', $e->a); } // Add comment. $options = (object) array('postid' => $postid, 'message' => 'test'); $commentid = $generator->create_content($oublog, array('comment' => $options)); $comment = $DB->get_record('oublog_comments', array('id' => $commentid)); $this->assertInstanceOf('stdClass', $comment); $this->assertEquals('test', $comment->message); }
$blog = required_param('blog', PARAM_INT); // Blog ID $postid = required_param('post', PARAM_INT); // Post ID for editing $commentid = optional_param('comment', 0, PARAM_INT); // Comment ID for editing if (!($oublog = $DB->get_record("oublog", array("id" => $blog)))) { print_error('invalidblog', 'oublog'); } if (!($cm = get_coursemodule_from_instance('oublog', $blog))) { print_error('invalidcoursemodule'); } if (!($course = $DB->get_record("course", array("id" => $oublog->course)))) { print_error('coursemisconf'); } if (!($post = oublog_get_post($postid))) { print_error('invalidpost', 'oublog'); } if (!($oubloginstance = $DB->get_record('oublog_instances', array('id' => $post->oubloginstancesid)))) { print_error('invalidblog', 'oublog'); } $url = new moodle_url('/mod/oublog/editcomment.php', array('blog' => $blog, 'post' => $postid, 'comment' => $commentid)); $PAGE->set_url($url); // Check security. $context = context_module::instance($cm->id); oublog_check_view_permissions($oublog, $context, $cm); $post->userid = $oubloginstance->userid; // oublog_can_view_post needs this if (!oublog_can_view_post($post, $USER, $context, $oublog->global)) { print_error('accessdenied', 'oublog'); }
if (!($cm = get_coursemodule_from_instance('oublog', $oublog->id))) { print_error('invalidcoursemodule'); } if (!($course = $DB->get_record("course", array("id" => $cm->course)))) { print_error('coursemisconf'); } $url = new moodle_url('/mod/oublog/viewpost.php', array('post' => $postid)); $PAGE->set_url($url); $context = context_module::instance($cm->id); oublog_check_view_permissions($oublog, $context, $cm); $oublogoutput = $PAGE->get_renderer('mod_oublog'); // Check security. $canmanageposts = has_capability('mod/oublog:manageposts', $context); $canmanagecomments = has_capability('mod/oublog:managecomments', $context); $canaudit = has_capability('mod/oublog:audit', $context); if (!($post = oublog_get_post($postid, $canaudit))) { print_error('invalidpost', 'oublog'); } if (!($oubloginstance = $DB->get_record('oublog_instances', array('id' => $post->oubloginstancesid)))) { print_error('invalidblog', 'oublog'); } if (!oublog_can_view_post($post, $USER, $context, $oublog->global)) { print_error('accessdenied', 'oublog'); } // Get strings. $stroublogs = get_string('modulenameplural', 'oublog'); $stroublog = get_string('modulename', 'oublog'); $strdelete = get_string('delete', 'oublog'); $strtags = get_string('tags', 'oublog'); $strcomments = get_string('comments', 'oublog'); $strlinks = get_string('links', 'oublog');
public function test_oublog_add_comment() { global $SITE, $USER, $DB; $this->resetAfterTest(true); $this->setAdminUser(); // Test comment using Personal blog. $oublog = $this->get_new_oublog($SITE->id, array('global' => 1, 'visibility' => OUBLOG_VISIBILITY_PUBLIC)); $cm = get_coursemodule_from_id('oublog', $oublog->cmid); $post = $this->get_post_stub($oublog->id); $postid = oublog_add_post($post, $cm, $oublog, $SITE); $comment = new stdClass(); $comment->title = 'Test Comment'; $comment->messagecomment = array(); $comment->messagecomment['text'] = 'Message for test comment'; $comment->postid = $postid; $comment->userid = $USER->id; $commentid = oublog_add_comment($SITE, $cm, $oublog, $comment); $this->assertTrue(is_int($commentid)); // Get post with comments to check created correctly. $post = oublog_get_post($postid); $this->assertNotEmpty($post->comments); $this->assertTrue(array_key_exists($commentid, $post->comments)); $this->assertEquals($comment->message, $post->comments[$commentid]->message); $this->assertEquals($comment->title, $post->comments[$commentid]->title); $this->assertEquals(fullname($USER), fullname($post->comments[$commentid])); // Check $canaudit sees deleted comments (and other users don't). $DB->update_record('oublog_comments', (object) array('id' => $commentid, 'deletedby' => $USER->id)); $post = oublog_get_post($postid, true); $this->assertNotEmpty($post->comments); $post = oublog_get_post($postid); $this->assertFalse(isset($post->comments)); // Check moderated (not logged-in comments). $bloginstance = $DB->get_record('oublog_instances', array('id' => $post->oubloginstancesid)); $adminid = $USER->id; $this->setGuestUser(); $this->assertFalse(oublog_too_many_comments_from_ip()); $modcomment = new stdClass(); $modcomment->messagecomment = 'TEST'; $modcomment->title = 'TITLE'; $modcomment->postid = $postid; $modcomment->authorname = 'Unittest'; // Catch email sent. unset_config('noemailever'); $sink = $this->redirectEmails(); // Update our admin user email as default is blank. $DB->update_record('user', (object) array('id' => $adminid, 'email' => '*****@*****.**')); $result = oublog_add_comment_moderated($oublog, $bloginstance, $post, $modcomment); $messages = $sink->get_messages(); $this->assertTrue($result); $this->assertEquals(1, count($messages)); $modcomment = $DB->get_record('oublog_comments_moderated', array('postid' => $postid)); $this->assertInstanceOf('stdClass', $modcomment); $id = oublog_approve_comment($modcomment, true); $this->assertTrue(is_int($id)); $saved = $DB->get_record('oublog_comments', array('authorname' => $modcomment->authorname)); $this->assertInstanceOf('stdClass', $saved); // Check post without allowcomments returns no comments (even if added already). $DB->update_record('oublog_posts', (object) array('id' => $postid, 'allowcomments' => 0)); $post = oublog_get_post($postid); $this->assertFalse(isset($post->comments)); }
$approve = true; } else { required_param('breject', PARAM_TEXT); // Sanity check $approve = false; } $redirectlower = optional_param('last', 0, PARAM_INT) ? false : true; } // Load comment and check it if (!($mcomment = get_record('oublog_comments_moderated', 'id', $mcommentid))) { print_error('invalidrequest', 'error'); } // Use post page for continue on error messages $backlink = $CFG->wwwroot . '/mod/oublog/viewpost.php?post=' . $mcomment->postid; // Load post, blog, etc if (!($post = oublog_get_post($mcomment->postid, false))) { print_error('error_unspecified', 'oublog', $backlink, 'A1'); } if (!($oublog = oublog_get_blog_from_postid($post->id))) { print_error('error_unspecified', 'oublog', $backlink, 'A2'); } if (!($cm = get_coursemodule_from_instance('oublog', $oublog->id))) { print_error('error_unspecified', 'oublog', $backlink, 'A3'); } if (!($course = get_record("course", "id", $cm->course))) { print_error('error_unspecified', 'oublog', $backlink, 'A4'); } // Check state if ($mcomment->approval) { print_error('error_alreadyapproved', 'oublog', $backlink); }
require_once "../../config.php"; require_once $CFG->dirroot . '/mod/oublog/locallib.php'; require_once $CFG->libdir . '/completionlib.php'; $blog = required_param('blog', PARAM_INT); // Blog ID. $postid = required_param('post', PARAM_INT); // Post ID for editing. $confirm = optional_param('confirm', 0, PARAM_INT); // Confirm that it is ok to delete post. $delete = optional_param('delete', 0, PARAM_INT); $email = optional_param('email', 0, PARAM_INT); // Email author. if (!($oublog = $DB->get_record("oublog", array("id" => $blog)))) { print_error('invalidblog', 'oublog'); } if (!($post = oublog_get_post($postid, false))) { print_error('invalidpost', 'oublog'); } if (!($cm = get_coursemodule_from_instance('oublog', $blog))) { print_error('invalidcoursemodule'); } if (!($course = $DB->get_record("course", array("id" => $oublog->course)))) { print_error('coursemisconf'); } $url = new moodle_url('/mod/oublog/deletepost.php', array('blog' => $blog, 'post' => $postid, 'confirm' => $confirm)); $PAGE->set_url($url); // Check security. $context = context_module::instance($cm->id); oublog_check_view_permissions($oublog, $context, $cm); $postauthor = $DB->get_field_sql("\nSELECT\n i.userid\nFROM\n {oublog_posts} p\n INNER JOIN {oublog_instances} i on p.oubloginstancesid=i.id\nWHERE p.id = ?", array($postid)); if ($postauthor != $USER->id) {
/** * A whole blog from a single post, with or without attachments * * @global object * @uses PORTFOLIO_FORMAT_RICH * @return mixed */ public function prepare_package() { global $CFG; $plugin = $this->get('exporter')->get('instance')->get('plugin'); $posttitles = array(); $outputhtml = ''; // Exporting a set of posts from the view page. foreach ($this->posts as $post) { $post = oublog_get_post($post->id); if ($plugin != 'rtf') { $outputhtml = $this->prepare_post($post, true); // If post is titled use that as file name for export. if ($post->title) { $name = $post->title . '.html'; } else { $name = get_string('exportuntitledpost', 'oublog') . $post->id . '.html'; } // If post title already exists make it unique. if (in_array(strtolower($post->title), $posttitles) and $post->title != '') { $name = $post->title . ' ' . $post->id . '.html'; $post->title = $post->title . ' id ' . $post->id; } } else { // Ensure multiple posts and their comments // are included in the html for export. $outputhtml .= $this->prepare_post($post, false); } // Ensure multiple files contained within this post and it's comments // are included in the exported file. $manifest = $this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH; if (!empty($this->multifiles)) { foreach ($this->multifiles as $file) { $this->get('exporter')->copy_existing_file($file); } } if ($plugin != 'rtf') { $this->get('exporter')->write_new_file($outputhtml, $name, $manifest); $posttitles[] = strtolower($post->title); } } if ($plugin == 'rtf') { $name = $this->oublog->name . '.html'; $this->get('exporter')->write_new_file($outputhtml, $name, $manifest); } }
require_once "../../config.php"; require_once "locallib.php"; $commentid = required_param('comment', PARAM_INT); // Comment ID to delete $confirm = optional_param('confirm', 0, PARAM_INT); // Confirm that it is ok to delete comment if (class_exists('ouflags')) { require_once '../../local/mobile/ou_lib.php'; global $OUMOBILESUPPORT; $OUMOBILESUPPORT = true; ou_set_is_mobile(ou_get_is_mobile_from_cookies()); } if (!($comment = get_record('oublog_comments', 'id', $commentid))) { error('Comment ID was incorrect'); } if (!($post = oublog_get_post($comment->postid))) { error("Post ID was incorrect"); } if (!($cm = get_coursemodule_from_instance('oublog', $post->oublogid))) { error("Course module ID was incorrect"); } if (!($course = get_record("course", "id", $cm->course))) { error("Course is misconfigured"); } if (!($oublog = get_record("oublog", "id", $cm->instance))) { error("Course module is incorrect"); } /// Check security $context = get_context_instance(CONTEXT_MODULE, $cm->id); oublog_check_view_permissions($oublog, $context, $cm); // You can always delete your own comments, or any comment on your own
function oublog_oualerts_custom_info($item, $id) { global $CFG, $USER, $DB; require_once $CFG->dirroot . '/mod/oublog/locallib.php'; switch ($item) { case 'post': $data = oublog_get_post($id); $itemtitle = get_string('untitledpost', 'oublog'); break; case 'comment': $data = $DB->get_record('oublog_comments', array('id' => $id)); $itemtitle = get_string('untitledcomment', 'oublog'); break; default: $data = false; break; } if ($data != false && !empty($data->title)) { $itemtitle = $data->title; } // Return just the title string value of the post or comment. return $itemtitle; }
/** * This page prints information about edits to a blog post. * * @author Matt Clarkson <*****@*****.**> * @author Sam Marshall <*****@*****.**> * @package oublog */ require_once "../../config.php"; require_once "locallib.php"; $editid = required_param('edit', PARAM_INT); // Blog post edit ID if (!($edit = get_record('oublog_edits', 'id', $editid))) { error('Edit ID was incorrect'); } if (!($post = oublog_get_post($edit->postid))) { error("Post ID was incorrect"); } if (!($cm = get_coursemodule_from_instance('oublog', $post->oublogid))) { error("Course module ID was incorrect"); } if (!($course = get_record("course", "id", $cm->course))) { error("Course is misconfigured"); } if (!($oublog = get_record("oublog", "id", $cm->instance))) { error("Course module is incorrect"); } $context = get_context_instance(CONTEXT_MODULE, $cm->id); oublog_check_view_permissions($oublog, $context, $cm); /// Check security $canpost = oublog_can_post($oublog, $post->userid, $cm);
/** * Print a detailed representation of what a user has done with * a given particular instance of this module, for user activity reports. * * @param object $course * @param object $user * @param object $mod * @param object $oublog * @return object containing a time and info properties */ function oublog_user_complete($course, $user, $mod, $oublog) { global $CFG; include_once 'locallib.php'; $baseurl = $CFG->wwwroot . '/mod/oublog/view.php?id=' . $mod->id; $sql = "SELECT p.*\r\n FROM {$CFG->prefix}oublog_posts p\r\n INNER JOIN {$CFG->prefix}oublog_instances i ON p.oubloginstancesid = i.id\r\n WHERE p.deletedby IS NULL AND i.userid = {$user->id} AND oublogid = {$mod->instance} "; if ($posts = get_records_sql($sql)) { foreach ($posts as $post) { $postdata = oublog_get_post($post->id); oublog_print_post($mod, $oublog, $postdata, $baseurl, 'course'); } } else { echo get_string('noblogposts', 'oublog'); } return null; }