function xmldb_oublog_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; if ($result && $oldversion < 2008022600) { /// Define field views to be added to oublog_instances $table = new XMLDBTable('oublog_instances'); $field = new XMLDBField('views'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'accesstoken'); /// Launch add field views $result = $result && add_field($table, $field); $table = new XMLDBTable('oublog'); $field = new XMLDBField('views'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'global'); /// Launch add field views $result = $result && add_field($table, $field); } if ($result && $oldversion < 2008022700) { /// Define field oublogid to be added to oublog_links $table = new XMLDBTable('oublog_links'); $field = new XMLDBField('oublogid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id'); /// Launch add field oublogid $result = $result && add_field($table, $field); /// Define key oublog_links_oublog_fk (foreign) to be added to oublog_links $table = new XMLDBTable('oublog_links'); $key = new XMLDBKey('oublog_links_oublog_fk'); $key->setAttributes(XMLDB_KEY_FOREIGN, array('oublogid'), 'oublog', array('id')); /// Launch add key oublog_links_oublog_fk $result = $result && add_key($table, $key); /// Changing nullability of field oubloginstancesid on table oublog_links to null $table = new XMLDBTable('oublog_links'); $field = new XMLDBField('oubloginstancesid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'oublogid'); /// Launch change of nullability for field oubloginstancesid $result = $result && change_field_notnull($table, $field); } if ($result && $oldversion < 2008022701) { /// Define field sortorder to be added to oublog_links $table = new XMLDBTable('oublog_links'); $field = new XMLDBField('sortorder'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'url'); /// Launch add field sortorder $result = $result && add_field($table, $field); } if ($result && $oldversion < 2008030704) { /// Add search data require_once dirname(__FILE__) . '/../locallib.php'; require_once dirname(__FILE__) . '/../lib.php'; if (oublog_search_installed()) { global $db; $olddebug = $db->debug; $db->debug = false; print '<ul>'; oublog_ousearch_update_all(true); print '</ul>'; $db->debug = $olddebug; } } if ($result && $oldversion < 2008030707) { /// Define field lasteditedby to be added to oublog_posts $table = new XMLDBTable('oublog_posts'); $field = new XMLDBField('lasteditedby'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'visibility'); /// Launch add field lasteditedby $result = $result && add_field($table, $field); /// Transfer edit data to lasteditedby $result = $result && execute_sql("\r\nUPDATE {$CFG->prefix}oublog_posts SET lasteditedby=(\r\n SELECT userid FROM {$CFG->prefix}oublog_edits WHERE {$CFG->prefix}oublog_posts.id=postid ORDER BY id DESC LIMIT 1 \r\n) WHERE editsummary IS NOT NULL\r\n "); /// Define field editsummary to be dropped from oublog_posts $table = new XMLDBTable('oublog_posts'); $field = new XMLDBField('editsummary'); /// Launch drop field editsummary $result = $result && drop_field($table, $field); } if ($result && $oldversion < 2008073000) { /// Define field completionposts to be added to oublog $table = new XMLDBTable('oublog'); $field = new XMLDBField('completionposts'); $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'views'); /// Launch add field completionposts $result = $result && add_field($table, $field); /// Define field completioncomments to be added to oublog $field = new XMLDBField('completioncomments'); $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionposts'); /// Launch add field completioncomments $result = $result && add_field($table, $field); } if ($result && $oldversion < 2008121100) { // remove oublog:view from legacy:user roles $roles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW); foreach ($roles as $role) { $result = $result && unassign_capability('mod/oublog:view', $role->id); } } if ($result && $oldversion < 2009012600) { // Remove oublog:post and oublog:comment from legacy:user roles (if present) $roles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW); // Also from default user role if not already included if (!array_key_exists($CFG->defaultuserroleid, $roles)) { $roles[] = get_record('role', 'id', $CFG->defaultuserroleid); } print '<p><strong>Warning</strong>: The OU blog system capabilities have changed (again) in order to fix bugs and clarify access control. The system will automatically remove the capabilities <tt>mod/oublog:view</tt>, <tt>mod/oublog:post</tt>, and <tt>mod/oublog:comment</tt> from the following role(s):</p><ul>'; foreach ($roles as $role) { print '<li>' . htmlspecialchars($role->name) . '</li>'; $result = $result && unassign_capability('mod/oublog:view', $role->id); $result = $result && unassign_capability('mod/oublog:post', $role->id); $result = $result && unassign_capability('mod/oublog:comment', $role->id); } print '</ul><p>On a default Moodle installation this is the correct behaviour. Personal blog access is now controlled via the <tt>mod/oublog:viewpersonal</tt> and <tt>mod/oublog:contributepersonal</tt> capabilities. These capabilities have been added to the authenticated user role and any equivalent roles.</p> <p>If in doubt, please examine your role configuration with regard to these <tt>mod/oublog</tt> capabilities.</p>'; } if ($result && $oldversion < 2010031200) { /// Define field completionposts to be added to oublog $table = new XMLDBTable('oublog'); $field = new XMLDBField('individual'); $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completioncomments'); /// Launch add field completioncomments $result = $result && add_field($table, $field); } if ($result && $oldversion < 2010062400) { /// Define table oublog_comments_moderated to be created $table = new XMLDBTable('oublog_comments_moderated'); /// Adding fields to table oublog_comments_moderated $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); $table->addFieldInfo('postid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('message', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('timeposted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('authorname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('ipaddress', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('approval', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('timeset', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); $table->addFieldInfo('secretkey', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); /// Adding keys to table oublog_comments_moderated $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $table->addKeyInfo('postid', XMLDB_KEY_FOREIGN, array('postid'), 'oublog_posts', array('id')); /// Adding indexes to table oublog_comments_moderated $table->addIndexInfo('ipaddress', XMLDB_INDEX_NOTUNIQUE, array('ipaddress')); /// Launch create table for oublog_comments_moderated $result = $result && create_table($table); /// Changing nullability of field userid on table oublog_comments to null $table = new XMLDBTable('oublog_comments'); $field = new XMLDBField('userid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'postid'); /// Launch change of nullability for field userid $result = $result && change_field_notnull($table, $field); /// Define field authorname to be added to oublog_comments $field = new XMLDBField('authorname'); $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'timedeleted'); /// Launch add field authorname $result = $result && add_field($table, $field); /// Define field authorip to be added to oublog_comments $field = new XMLDBField('authorip'); $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'authorname'); /// Launch add field authorip $result = $result && add_field($table, $field); /// Define field timeapproved to be added to oublog_comments $field = new XMLDBField('timeapproved'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'authorip'); /// Launch add field timeapproved $result = $result && add_field($table, $field); } if ($result && $oldversion < 2010062500) { // Change the 'allow comments' value to 2 on global blog, if it is // currently set to 1 $result = $result && set_field('oublog', 'allowcomments', 2, 'global', 1, 'allowcomments', 1); } if ($result && $oldversion < 2010063000) { /// Define index ipaddress (not unique) to be dropped form oublog_comments_moderated $table = new XMLDBTable('oublog_comments_moderated'); $index = new XMLDBIndex('ipaddress'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('ipaddress')); /// Launch drop index authorip $result = $result && drop_index($table, $index); /// Rename field ipaddress on table oublog_comments_moderated to authorip $field = new XMLDBField('ipaddress'); $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'authorname'); /// Launch rename field ipaddress $result = $result && rename_field($table, $field, 'authorip'); /// Define index authorip (not unique) to be added to oublog_comments_moderated $table = new XMLDBTable('oublog_comments_moderated'); $index = new XMLDBIndex('authorip'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('authorip')); /// Launch add index authorip $result = $result && add_index($table, $index); } if ($result && $oldversion < 2010070101) { // Make cron start working - in some servers I found there was // 9999999999 in the lastcron field which caused it never to run; not // very helpful $result = $result && set_field('modules', 'lastcron', 1, 'name', 'oublog'); } return $result; }
function oublog_do_delete($course, $cm, $oublog, $post) { global $DB, $USER; $updatepost = (object) array('id' => $post->id, 'deletedby' => $USER->id, 'timedeleted' => time()); $transaction = $DB->start_delegated_transaction(); $DB->update_record('oublog_posts', $updatepost); if (!oublog_update_item_tags($post->oubloginstancesid, $post->id, array(), $post->visibility)) { print_error('tagupdatefailed', 'oublog'); } if (oublog_search_installed()) { $doc = oublog_get_search_document($updatepost, $cm); $doc->delete(); } // Inform completion system, if available. $completion = new completion_info($course); if ($completion->is_enabled($cm) && $oublog->completionposts) { $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid); } $transaction->allow_commit(); }
if ($offset) { $a = new stdClass(); $a->from = $offset + 1; $a->to = $recordcount - $offset > OUBLOG_POSTS_PER_PAGE ? $offset + OUBLOG_POSTS_PER_PAGE : $recordcount; $extranav = array('name' => get_string('extranavolderposts', 'oublog', $a), 'link' => '', 'type' => 'misc'); } if ($tag) { $extranav = array('name' => get_string('extranavtag', 'oublog', $tag), 'link' => '', 'type' => 'misc'); } /// Print the header $navlinks = array(); $navlinks[] = array('name' => format_string($oublog->name), 'link' => "allposts.php", 'type' => 'activityinstance'); if ($extranav) { $navlinks[] = $extranav; } if (oublog_search_installed()) { $buttontext = <<<EOF <form action="search.php" method="get"><div> <input type="text" name="query" value=""/> <input type="hidden" name="id" value="{$cm->id}"/> <input type="submit" value="{$strblogsearch}"/> </div></form> EOF; } else { $buttontext = ''; } $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));
/** * Returns html for a search form for the nav bar * @param string $name blog identifier field e.g. id * @param string $value blog identifier value e.g. 266 * @param string $strblogsearch search this blog text * @param string $querytext optional search term * @returns string html */ function oublog_get_search_form($name, $value, $strblogsearch, $querytext = '') { if (!oublog_search_installed()) { return ''; } global $OUTPUT; $out = html_writer::start_tag('form', array('action' => 'search.php', 'method' => 'get')); $out .= html_writer::start_tag('div'); $out .= html_writer::tag('label', $strblogsearch . ' ', array('for' => 'oublog_searchquery')); $out .= $OUTPUT->help_icon('searchblogs', 'oublog'); $out .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name, 'value' => $value)); $out .= html_writer::empty_tag('input', array('type' => 'text', 'name' => 'query', 'id' => 'oublog_searchquery', 'value' => $querytext)); $out .= html_writer::empty_tag('input', array('type' => 'image', 'id' => 'ousearch_searchbutton', 'alt' => get_string('search'), 'title' => get_string('search'), 'src' => $OUTPUT->pix_url('i/search'))); $out .= html_writer::end_tag('div'); $out .= html_writer::end_tag('form'); return $out; }
/** * Updates the fulltext search information for a post which is being added or * updated. * @param object $post Post data, including slashes for database. Must have * fields id,userid,groupid (if applicable), title, message * @param object $cm Course-module * @return True if search update was successful */ function oublog_search_update($post, $cm) { // Do nothing if OU search is not installed if (!oublog_search_installed()) { return true; } // Get search document $doc = oublog_get_search_document($post, $cm); // Sort out tags for use as extrastrings $taglist = oublog_get_post_tags($post, true); if (count($taglist) == 0) { $taglist = null; } // Update information about this post (works ok for add or edit) return $doc->update(stripslashes($post->title), stripslashes($post->message), null, null, $taglist); }
/** * Given an ID of an instance of this module, this function will * permanently delete the instance and any data that depends on it. * * @param int $id The ID of the module instance * @return boolena true on success, false on failure. */ function oublog_delete_instance($oublogid) { global $DB, $CFG; if (!($oublog = $DB->get_record('oublog', array('id' => $oublogid)))) { return false; } if ($oublog->global) { print_error('deleteglobalblog', 'oublog'); } if ($instances = $DB->get_records('oublog_instances', array('oublogid' => $oublog->id))) { foreach ($instances as $oubloginstancesid => $bloginstance) { // tags $DB->delete_records('oublog_taginstances', array('oubloginstancesid' => $oubloginstancesid)); if ($posts = $DB->get_records('oublog_posts', array('oubloginstancesid' => $oubloginstancesid))) { foreach ($posts as $postid => $post) { // comments $DB->delete_records('oublog_comments', array('postid' => $postid)); // edits $DB->delete_records('oublog_edits', array('postid' => $postid)); } // posts $DB->delete_records('oublog_posts', array('oubloginstancesid' => $oubloginstancesid)); } } } // links $DB->delete_records('oublog_links', array('oublogid' => $oublog->id)); // instances $DB->delete_records('oublog_instances', array('oublogid' => $oublog->id)); // Fulltext search data require_once dirname(__FILE__) . '/locallib.php'; if (oublog_search_installed()) { $moduleid = $DB->get_field('modules', 'id', array('name' => 'oublog')); $cm = $DB->get_record('course_modules', array('module' => $moduleid, 'instance' => $oublog->id)); if (!$cm) { print_error('invalidcoursemodule'); } local_ousearch_document::delete_module_instance_data($cm); } oublog_grade_item_delete($oublog); // oublog return $DB->delete_records('oublog', array('id' => $oublog->id)); }
/** * Given an ID of an instance of this module, this function will * permanently delete the instance and any data that depends on it. * * @param int $id The ID of the module instance * @return boolena true on success, false on failure. */ function oublog_delete_instance($oublogid) { if (!($oublog = get_record('oublog', 'id', $oublogid))) { return false; } if ($oublog->global) { error('You can\'t delete the global blog'); } if ($instances = get_records('oublog_instances', 'oublogid', $oublog->id)) { foreach ($instances as $oubloginstancesid => $bloginstance) { // tags delete_records('oublog_taginstances', 'oubloginstancesid', $oubloginstancesid); if ($posts = get_records('oublog_posts', 'oubloginstancesid', $oubloginstancesid)) { foreach ($posts as $postid => $post) { // comments delete_records('oublog_comments', 'postid', $postid); // edits delete_records('oublog_edits', 'postid', $postid); } // posts delete_records('oublog_posts', 'oubloginstancesid', $oubloginstancesid); } } } // links delete_records('oublog_links', 'oublogid', $oublog->id); // instances delete_records('oublog_instances', 'oublogid', $oublog->id); // Fulltext search data require_once dirname(__FILE__) . '/locallib.php'; if (oublog_search_installed()) { $moduleid = get_field('modules', 'id', 'name', 'oublog'); $cm = get_record('course_modules', 'module', $moduleid, 'instance', $oublog->id); if (!$cm) { error('Can\'t find coursemodule'); } ousearch_document::delete_module_instance_data($cm); } // oublog return delete_records('oublog', 'id', $oublog->id); }
function oublog_decode_content_links_caller($restore) { global $CFG; $status = true; //Process every blog $sql = "SELECT b.id, b.summary\r\n FROM {$CFG->prefix}oublog b\r\n WHERE b.course = {$restore->course_id}"; if ($blogs = get_records_sql($sql)) { //Iterate over each blog->summary $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($blogs as $blog) { //Increment counter $i++; $content = $blog->summary; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $blog->summary = addslashes($result); $status = update_record('oublog', $blog); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } //Process every blog instance $sql = "SELECT i.id, i.summary\r\n FROM {$CFG->prefix}oublog_instances i\r\n INNER JOIN {$CFG->prefix}oublog b ON i.oublogid = b.id\r\n WHERE b.course = {$restore->course_id}"; if ($instances = get_records_sql($sql)) { //Iterate over each blog->summary $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($instances as $instance) { //Increment counter $i++; $content = $instance->summary; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $instance->summary = addslashes($result); $status = update_record('oublog_instances', $instance); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } //Process every blog post in the course $sql = "SELECT p.id, p.message\r\n FROM {$CFG->prefix}oublog_posts p\r\n INNER JOIN {$CFG->prefix}oublog_instances i ON p.oubloginstancesid = i.id\r\n INNER JOIN {$CFG->prefix}oublog b ON i.oublogid = b.id\r\n WHERE b.course = {$restore->course_id}"; if ($posts = get_records_sql($sql)) { //Iterate over each post->message $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($posts as $post) { //Increment counter $i++; $content = $post->message; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $post->message = addslashes($result); $status = update_record('oublog_posts', $post); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } //Process every blog comment in the course $sql = "SELECT c.id, c.message\r\n FROM {$CFG->prefix}oublog_comments c\r\n INNER JOIN {$CFG->prefix}oublog_posts p ON c.postid = p.id\r\n INNER JOIN {$CFG->prefix}oublog_instances i ON p.oubloginstancesid = i.id\r\n INNER JOIN {$CFG->prefix}oublog b ON i.oublogid = b.id\r\n WHERE b.course = {$restore->course_id}"; if ($comments = get_records_sql($sql)) { //Iterate over each comment->message $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($comments as $comment) { //Increment counter $i++; $content = $comment->message; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $comment->message = addslashes($result); $status = update_record('oublog_comments', $comment); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } //Process every related link in this course $sql = "SELECT l.id, l.url\r\n FROM {$CFG->prefix}oublog_links l\r\n INNER JOIN {$CFG->prefix}oublog b ON l.oublogid = b.id\r\n WHERE b.course = {$restore->course_id}"; if ($links = get_records_sql($sql)) { //Iterate over each comment->message $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($links as $link) { //Increment counter $i++; $content = $link->url; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $link->url = addslashes($result); $status = update_record('oublog_links', $link); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } // Now fix up search for the course if (oublog_search_installed()) { oublog_ousearch_update_all(false, $restore->course_id); } return $status; }