コード例 #1
0
/**
 * Update a blog comment
 *
 * @param object $comment
 * @return mixed commentid on success or false
 */
function oublog_update_comment($course, $cm, $oublog, $comment)
{
    global $CFG;
    if (!isset($comment->timeposted)) {
        $comment->timeposted = time();
    }
    if ($comment->id) {
        $ok = update_record('oublog_comments', $comment);
    }
    //$id=insert_record('oublog_comments', $comment);
    if ($ok) {
        // Inform completion system, if available
        if (class_exists('ouflags')) {
            if (completion_is_enabled($course, $cm) && $oublog->completioncomments) {
                completion_update_state($course, $cm, COMPLETION_COMPLETE);
            }
        }
    }
    return $ok;
}
コード例 #2
0
        $pageversions = ouwiki_get_page_history($pageversion->pageid, false, 0, 1);
        $currentpageversion = reset($pageversions);
        if (!$currentpageversion) {
            throw new Exception('Error deleting/undeleting ouwiki page version');
        }
        // Check if version that has been undeleted should be the new current version
        if ($pageversion->currentversionid != $currentpageversion->versionid) {
            // Set new current version id
            if (!set_field('ouwiki_pages', 'currentversionid', $currentpageversion->versionid, 'id', $pageversion->pageid)) {
                throw new Exception('Error deleting/undeleting ouwiki page version');
            }
        }
        // Update completion status for user
        if (class_exists('ouflags')) {
            if (completion_is_enabled($course, $cm) && ($ouwiki->completionedits || $ouwiki->completionpages)) {
                completion_update_state($course, $cm, COMPLETION_COMPLETE, $pageversion->userid);
            }
        }
    }
} catch (Exception $e) {
    // Unlock page
    ouwiki_release_lock($pageversion->pageid);
    print_error('deleteversionerror', 'ouwiki');
}
// Unlock page
ouwiki_release_lock($pageversion->pageid);
// Log delete or undelete action
$ouwikiparamsurl = ouwiki_display_wiki_parameters($pagename, $subwiki, $cm, OUWIKI_PARAMS_URL);
add_to_log($course->id, 'ouwiki', 'version' . $action, 'delete.php?' . $ouwikiparamsurl . '&version=' . $versionid, '', $cm->id);
// Redirect to view what is now the current version
redirect('history.php?' . $ouwikiparamsurl);
コード例 #3
0
if ($oublog->global) {
    $blogtype = 'personal';
    // Get blog user from the oublog_get_post result (to save making an
    // extra query); this is only used to display their name anyhow
    $oubloguser = (object) array('id' => $post->userid, 'firstname' => $post->firstname, 'lastname' => $post->lastname);
} else {
    $blogtype = 'course';
}
$viewurl = 'viewpost.php?post=' . $post->id;
if (!empty($commentid) && !empty($confirm)) {
    $updatecomment = (object) array('id' => $commentid, 'deletedby' => $USER->id, 'timedeleted' => time());
    update_record('oublog_comments', $updatecomment);
    // Inform completion system, if available
    if (class_exists('ouflags')) {
        if (completion_is_enabled($course, $cm) && $oublog->completioncomments) {
            completion_update_state($course, $cm, COMPLETION_INCOMPLETE, $comment->userid);
        }
    }
    redirect($viewurl);
    exit;
}
/// Get Strings
$stroublogs = get_string('modulenameplural', 'oublog');
$stroublog = get_string('modulename', 'oublog');
/// Print the header
if (class_exists('ouflags') && ou_get_is_mobile()) {
    ou_mobile_configure_theme();
}
if ($blogtype == 'personal') {
    $navlinks = array();
    $navlinks[] = array('name' => fullname($oubloguser), 'link' => "../../user/view.php?id={$oubloguser->id}", 'type' => 'misc');
コード例 #4
0
    $expost = get_record('oublog_posts', 'id', $postid);
    $updatepost = (object) array('id' => $postid, 'deletedby' => $USER->id, 'timedeleted' => time());
    $tw = new transaction_wrapper();
    update_record('oublog_posts', $updatepost);
    if (!oublog_update_item_tags($expost->oubloginstancesid, $expost->id, array(), $expost->visibility)) {
        $tw->rollback();
        error('Failed to update tags');
    }
    if (oublog_search_installed()) {
        $doc = oublog_get_search_document($updatepost, $cm);
        $doc->delete();
    }
    // Inform completion system, if available
    if (class_exists('ouflags')) {
        if (completion_is_enabled($course, $cm) && $oublog->completionposts) {
            completion_update_state($course, $cm, COMPLETION_INCOMPLETE, $postauthor);
        }
    }
    $tw->commit();
    redirect($viewurl);
    exit;
}
/// Get Strings
$stroublogs = get_string('modulenameplural', 'oublog');
$stroublog = get_string('modulename', 'oublog');
/// Print the header
if (class_exists('ouflags') && ou_get_is_mobile()) {
    ou_mobile_configure_theme();
}
if ($blogtype == 'personal') {
    $navlinks = array();
コード例 #5
0
 /**
  * Updates completion status based on changes made to entire discussion.
  * @param bool $positive True if the changes will make things complete
  *   that were previously incomplete; false if they will make things 
  *   incomplete that were previously complete
  */
 private function update_completion($positive)
 {
     // Get list of affected users (if any)
     $users = array();
     if ($this->forum->get_completion_replies() || $this->forum->get_completion_posts()) {
         // Affected users = everyone who posted
         $rootpost = $this->get_root_post();
         $posts = array();
         $rootpost->build_linear_children($posts);
         foreach ($posts as $post) {
             $users[$post->get_user()->id] = true;
         }
     } else {
         if ($this->forum->get_completion_discussions()) {
             // Affected users = discussion poster only
             $users[$this->get_poster()->id] = true;
         }
     }
     foreach ($users as $userid => $junk) {
         $course = $this->get_course();
         $cm = $this->get_course_module();
         completion_update_state($course, $cm, $positive ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE, $userid);
     }
 }
コード例 #6
0
/**
 * Saves a new version of the given named page within a subwiki. Can create
 * a new page or just add a new version to an existing one. In case of
 * failure, ends up calling error() rather than returning something.
 * @param object $course Course object
 * @param object $cm Course-module object
 * @param object $ouwiki OU wiki object
 * @param object $subwiki Subwiki object
 * @param string $pagename Name of page (NO SLASHES)
 * @param string $content XHTML Content (NO SLASHES)
 * @param int $changestart For section changes. Start position of change. (-1 if not section change)
 * @param int $changesize Size of changed section.
 * @param int $changeprevsize Previous size of changed section
 * @param bool $nouser If true, creates as system
 */
function ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename, $content, $changestart = -1, $changesize = -1, $changeprevsize = -1, $nouser = false)
{
    $tw = new transaction_wrapper();
    // Find page if it exists
    $pageversion = ouwiki_get_current_page($subwiki, $pagename, OUWIKI_GETPAGE_CREATE);
    // Analyse content for HTML headings that don't already have an ID.
    // These are all assigned unique, fairly short IDs.
    // Get number of version [guarantees in-page uniqueness of generated IDs]
    $versionnumber = count_records('ouwiki_versions', 'pageid', $pageversion->pageid);
    // Remove any spaces from annotation tags that were added for editing or by users
    // and remove any duplicate annotation tags
    $pattern = '~<span\\b.id=\\"annotation(.+?)\\">.*?</span>~';
    $replace = '<span id="annotation$1"></span>';
    $content = preg_replace($pattern, $replace, $content);
    unset($pattern, $replace, $used);
    // Get rid of any heading tags that only contain whitespace
    $emptypatterns = array();
    for ($i = 1; $i <= 6; $i++) {
        $emptypatterns[] = '~<h' . $i . '[^>]*>\\s*(<br[^>]*>\\s*)*</h' . $i . '>~';
    }
    $content = preg_replace($emptypatterns, '', $content);
    // List all headings that already have IDs, to check for duplicates
    $matches = array();
    preg_match_all('|<h[1-9] id="ouw_s(.*?)">(.*?)</h[1-9]>|', $content, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
    // Organise list by ID
    $byid = array();
    foreach ($matches as $index => $data) {
        $id = $data[1][0];
        if (!array_key_exists($id, $byid)) {
            $byid[$id] = array();
        }
        $byid[$id][] = $index;
    }
    // Handle any duplicates
    $deletebits = array();
    foreach ($byid as $id => $duplicates) {
        if (count($duplicates) > 1) {
            // We have a duplicate. By default, keep the first one
            $keep = $duplicates[0];
            // See if there is a title entry in the database for it
            $knowntitle = get_field('ouwiki_sections', 'title', 'xhtmlid', addslashes($id), 'pageid', $pageversion->pageid);
            if ($knowntitle) {
                foreach ($duplicates as $duplicate) {
                    $title = ouwiki_get_section_title(null, null, $matches[$duplicate][2][0]);
                    if ($title === $knowntitle) {
                        $keep = $duplicate;
                        break;
                    }
                }
            }
            foreach ($duplicates as $duplicate) {
                if ($duplicate !== $keep) {
                    $deletebits[] = (object) array('startbyte' => $matches[$duplicate][1][1] - 10, 'bytes' => strlen($matches[$duplicate][1][0]) + 11);
                }
            }
        }
    }
    // Were there any?
    if (count($deletebits) > 0) {
        // Sort in reverse order of starting position
        usort($deletebits, 'ouwiki_internal_sort_deletions');
        // Delete each bit
        foreach ($deletebits as $deletebit) {
            $content = substr($content, 0, $deletebit->startbyte) . substr($content, $deletebit->startbyte + $deletebit->bytes);
        }
    }
    // Replace existing empty headings with an ID including version count plus another index
    global $ouwiki_count;
    // Nasty but I can't think of a better way!
    $ouwiki_count = 0;
    global $ouwiki_internal_re;
    $ouwiki_internal_re->version = $versionnumber;
    $ouwiki_internal_re->count = 0;
    $sizebefore = strlen($content);
    $content = preg_replace_callback('/<h([1-9])>/', 'ouwiki_internal_re_headings', $content);
    $sizeafter = strlen($content);
    // Replace wiki links to [[Start page]] with the correct (non
    // language-specific) format [[]]
    $regex = str_replace('.*?', preg_quote(get_string('startpage', 'ouwiki')), OUWIKI_LINKS_SQUAREBRACKETS) . 'ui';
    $content = preg_replace($regex, '[[]]', $content);
    // Create version
    $version = new StdClass();
    $version->pageid = $pageversion->pageid;
    $version->xhtml = addslashes($content);
    $version->timecreated = time();
    if (!$nouser) {
        global $USER;
        $version->userid = $USER->id;
    }
    if ($changestart != -1) {
        $version->changestart = $changestart;
        // In tracking the new size, account for any added headings etc
        $version->changesize = $changesize + ($sizeafter - $sizebefore);
        $version->changeprevsize = $changeprevsize;
    }
    if (!($versionid = insert_record('ouwiki_versions', $version))) {
        $tw->rollback();
        ouwiki_dberror();
    }
    // Update latest version
    if (!set_field('ouwiki_pages', 'currentversionid', $versionid, 'id', $pageversion->pageid)) {
        $tw->rollback();
        ouwiki_dberror();
    }
    // Analyse for links
    $wikilinks = array();
    $externallinks = array();
    // Wiki links: ordinary [[links]]
    $matches = array();
    preg_match_all(OUWIKI_LINKS_SQUAREBRACKETS, $content, $matches, PREG_PATTERN_ORDER);
    foreach ($matches[1] as $match) {
        // Convert to page name (this also removes HTML tags etc)
        $wikilinks[] = ouwiki_get_wiki_link_details($match)->page;
    }
    // Note that we used to support CamelCase links but have removed support because:
    // 1. Confusing: students type JavaScript or MySpace and don't expect it to become a link
    // 2. Not accessible: screenreaders cannot cope with run-together words, and
    //    dyslexic students can have difficulty reading them
    // External links
    preg_match_all('/<a [^>]*href=(?:(?:\'(.*?)\')|(?:"(.*?))")/', $content, $matches, PREG_PATTERN_ORDER);
    foreach ($matches[1] as $match) {
        if ($match) {
            $externallinks[] = html_entity_decode($match);
        }
    }
    foreach ($matches[2] as $match) {
        if ($match) {
            $externallinks[] = html_entity_decode($match);
        }
    }
    // Add link records
    $link = new StdClass();
    $link->fromversionid = $versionid;
    foreach ($wikilinks as $targetpage) {
        if (!empty($targetpage)) {
            $pagerecord = get_record_select('ouwiki_pages', "subwikiid='{$subwiki->id}' AND UPPER(title)=UPPER('" . addslashes($targetpage) . "')");
            if ($pagerecord) {
                $pageid = $pagerecord->id;
            } else {
                $pageid = false;
            }
        } else {
            $pageid = get_field_select('ouwiki_pages', 'id', "subwikiid={$subwiki->id} AND title IS NULL");
        }
        if ($pageid) {
            $link->topageid = $pageid;
            $link->tomissingpage = null;
        } else {
            $link->topageid = null;
            $link->tomissingpage = addslashes(strtoupper($targetpage));
        }
        if (!($link->id = insert_record('ouwiki_links', $link))) {
            $tw->rollback();
            ouwiki_dberror();
        }
    }
    $link->topageid = null;
    $link->tomissingpage = null;
    $tl = textlib_get_instance();
    foreach ($externallinks as $url) {
        // Restrict length of URL
        if ($tl->strlen($url) > 255) {
            $url = $tl->substr($url, 0, 255);
        }
        $link->tourl = addslashes($url);
        if (!($link->id = insert_record('ouwiki_links', $link))) {
            $tw->rollback();
            ouwiki_dberror();
        }
    }
    // Inform search, if installed
    if (ouwiki_search_installed()) {
        $doc = new ousearch_document();
        $doc->init_module_instance('ouwiki', $cm);
        if ($subwiki->groupid) {
            $doc->set_group_id($subwiki->groupid);
        }
        $doc->set_string_ref($pageversion->title === '' ? null : $pageversion->title);
        if ($subwiki->userid) {
            $doc->set_user_id($subwiki->userid);
        }
        $title = is_null($pageversion->title) ? '' : $pageversion->title;
        if (!$doc->update($title, $content)) {
            $tw->rollback();
            ouwiki_dberror();
        }
    }
    // Inform completion system, if available
    if (class_exists('ouflags')) {
        if (completion_is_enabled($course, $cm) && ($ouwiki->completionedits || $ouwiki->completionpages)) {
            completion_update_state($course, $cm, COMPLETION_COMPLETE);
        }
    }
    $tw->commit();
}
コード例 #7
0
 public function update_completion($positive)
 {
     // Do nothing if completion isn't enabled
     if (!$this->get_forum()->is_auto_completion_enabled(true)) {
         return;
     }
     $course = $this->get_forum()->get_course();
     $cm = $this->get_forum()->get_course_module();
     completion_update_state($course, $cm, $positive ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE, $this->postfields->userid);
 }