Example #1
0
    // Add context for editor.
    $editoroptions['context'] = $coursecontext;
    $editoroptions['subdirs'] = file_area_contains_subdirs($coursecontext, 'course', 'summary', 0);
    $course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course', 'summary', 0);
    if ($overviewfilesoptions) {
        file_prepare_standard_filemanager($course, 'overviewfiles', $overviewfilesoptions, $coursecontext, 'course', 'overviewfiles', 0);
    }
    // Inject current aliases.
    $aliases = $DB->get_records('role_names', array('contextid' => $coursecontext->id));
    foreach ($aliases as $alias) {
        $course->{'role_' . $alias->roleid} = $alias->name;
    }
    // Populate course tags.
    if (!empty($CFG->usetags)) {
        include_once $CFG->dirroot . '/tag/lib.php';
        $course->tags = tag_get_tags_array('course', $course->id);
    }
} else {
    // Editor should respect category context if course context is not set.
    $editoroptions['context'] = $catcontext;
    $editoroptions['subdirs'] = 0;
    $course = file_prepare_standard_editor($course, 'summary', $editoroptions, null, 'course', 'summary', null);
    if ($overviewfilesoptions) {
        file_prepare_standard_filemanager($course, 'overviewfiles', $overviewfilesoptions, null, 'course', 'overviewfiles', 0);
    }
}
// First create the form.
$args = array('course' => $course, 'category' => $category, 'editoroptions' => $editoroptions, 'returnto' => $returnto, 'returnurl' => $returnurl);
$editform = new course_edit_form(null, $args);
if ($editform->is_cancelled()) {
    // The form has been cancelled, take them back to what ever the return to is.
 /**
  * Get tags for this discussion.
  * @param $htmldecode bool Set true to decode html special chars (for form field)
  * @return array of sorted tags or false if no tags are found.
  */
 public function get_tags($htmldecode = false)
 {
     global $CFG;
     require_once $CFG->dirroot . '/tag/lib.php';
     $tags = null;
     $forum = $this->get_forum();
     if ($forum->get_tags_enabled()) {
         $tags = tag_get_tags_array('forumng_discussions', $this->get_id());
         $tags = array_map('strtolower', $tags);
         if ($htmldecode) {
             $tags = array_map('htmlspecialchars_decode', $tags);
         }
         // Sort tags keeping id.
         asort($tags);
         return $tags;
     } else {
         return false;
     }
 }
Example #3
0
    protected function print_edit($content = null) {
        global $CFG, $OUTPUT, $USER, $PAGE;

        if (!$this->check_locks()) {
            return;
        }

        //delete old locks (> 1 hour)
        wiki_delete_old_locks();

        $version = wiki_get_current_version($this->page->id);
        $format = $version->contentformat;

        if ($content == null) {
            if (empty($this->section)) {
                $content = $version->content;
            } else {
                $content = $this->sectioncontent;
            }
        }

        $versionnumber = $version->version;
        if ($this->versionnumber >= 0) {
            if ($version->version != $this->versionnumber) {
                print $OUTPUT->box(get_string('wrongversionlock', 'wiki'), 'errorbox');
                $versionnumber = $this->versionnumber;
            }
        }

        $url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
        if (!empty($this->section)) {
            $url .= "&section=" . urlencode($this->section);
        }

        $params = array(
            'attachmentoptions' => page_wiki_edit::$attachmentoptions,
            'format' => $version->contentformat,
            'version' => $versionnumber,
            'pagetitle' => $this->page->title,
            'contextid' => $this->modcontext->id
        );

        $data = new StdClass();
        $data->newcontent = $content;
        $data->version = $versionnumber;
        $data->format = $format;

        switch ($format) {
        case 'html':
            $data->newcontentformat = FORMAT_HTML;
            // Append editor context to editor options, giving preference to existing context.
            page_wiki_edit::$attachmentoptions = array_merge(array('context' => $this->modcontext), page_wiki_edit::$attachmentoptions);
            $data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id);
            break;
        default:
            break;
        }

        if ($version->contentformat != 'html') {
            $params['fileitemid'] = $this->subwiki->id;
            $params['component']  = 'mod_wiki';
            $params['filearea']   = 'attachments';
        }

        if (!empty($CFG->usetags)) {
            $params['tags'] = tag_get_tags_csv('wiki_pages', $this->page->id, TAG_RETURN_TEXT);
        }

        $form = new mod_wiki_edit_form($url, $params);

        if ($formdata = $form->get_data()) {
            if (!empty($CFG->usetags)) {
                $data->tags = $formdata->tags;
            }
        } else {
            if (!empty($CFG->usetags)) {
                $data->tags = tag_get_tags_array('wiki', $this->page->id);
            }
        }

        $form->set_data($data);
        $form->display();
    }
Example #4
0
/**
 * Generate any blog RSS feed via one function
 *
 * @param stdClass $context The context of the blog for which the feed it being generated
 * @param array    $args    An array of arguements needed to build the feed (contextid, token, componentname, type, id, tagid)
 */
function blog_rss_get_feed($context, $args)
{
    global $CFG, $SITE, $DB;
    if (empty($CFG->bloglevel)) {
        debugging('Blogging disabled on this site, RSS feeds are not available');
        return null;
    }
    if (empty($CFG->enablerssfeeds)) {
        debugging('Sorry, RSS feeds are disabled on this site');
        return '';
    }
    if ($CFG->bloglevel == BLOG_SITE_LEVEL) {
        if (isguestuser()) {
            debugging(get_string('nopermissiontoshow', 'error'));
            return '';
        }
    }
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    if (!has_capability('moodle/blog:view', $sitecontext)) {
        return null;
    }
    $type = clean_param($args[3], PARAM_ALPHA);
    $id = clean_param($args[4], PARAM_INT);
    // could be groupid / courseid  / userid  depending on $type
    $tagid = 0;
    if ($args[5] != 'rss.xml') {
        $tagid = clean_param($args[5], PARAM_INT);
    } else {
        $tagid = 0;
    }
    $filename = blog_rss_file_name($type, $id, $tagid);
    if (file_exists($filename)) {
        if (filemtime($filename) + 3600 > time()) {
            return $filename;
            // It's already done so we return cached version
        }
    }
    $courseid = $groupid = $userid = null;
    switch ($type) {
        case 'site':
            //$siteid = $id;
            break;
        case 'course':
            $courseid = $id;
            break;
        case 'group':
            $groupid = $id;
            break;
        case 'user':
            $userid = $id;
            break;
    }
    // Get all the entries from the database
    require_once $CFG->dirroot . '/blog/locallib.php';
    $blogheaders = blog_get_headers($courseid, $groupid, $userid, $tagid);
    $bloglisting = new blog_listing($blogheaders['filters']);
    $blogentries = $bloglisting->get_entries();
    // Now generate an array of RSS items
    if ($blogentries) {
        $items = array();
        foreach ($blogentries as $blog_entry) {
            $item = NULL;
            $item->author = fullname($DB->get_record('user', array('id' => $blog_entry->userid)));
            // TODO: this is slow
            $item->title = $blog_entry->subject;
            $item->pubdate = $blog_entry->lastmodified;
            $item->link = $CFG->wwwroot . '/blog/index.php?entryid=' . $blog_entry->id;
            $summary = file_rewrite_pluginfile_urls($blog_entry->summary, 'pluginfile.php', $sitecontext->id, 'blog', 'post', $blog_entry->id);
            $item->description = format_text($summary, $blog_entry->format);
            if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blog_entry->id))) {
                if ($blogtags) {
                    $item->tags = $blogtags;
                }
                $item->tagscheme = $CFG->wwwroot . '/tag';
            }
            $items[] = $item;
        }
        $articles = rss_add_items($items);
        /// Change structure to XML
    } else {
        $articles = '';
    }
    /// Get header and footer information
    switch ($type) {
        case 'user':
            $info = fullname($DB->get_record('user', array('id' => $id), 'firstname,lastname'));
            break;
        case 'course':
            $info = $DB->get_field('course', 'fullname', array('id' => $id));
            $info = format_string($info, true, array('context' => get_context_instance(CONTEXT_COURSE, $id)));
            break;
        case 'site':
            $info = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
            break;
        case 'group':
            $group = groups_get_group($id);
            $info = $group->name;
            //TODO: $DB->get_field('groups', 'name', array('id'=>$id))
            break;
        default:
            $info = '';
            break;
    }
    if ($tagid) {
        $info .= ': ' . $DB->get_field('tags', 'text', array('id' => $tagid));
    }
    $header = rss_standard_header(get_string($type . 'blog', 'blog', $info), $CFG->wwwroot . '/blog/index.php', get_string('intro', 'blog'));
    $footer = rss_standard_footer();
    // Save the XML contents to file.
    $rssdata = $header . $articles . $footer;
    if (blog_rss_save_file($type, $id, $tagid, $rssdata)) {
        return $filename;
    } else {
        return false;
        // Couldn't find it or make it
    }
}
Example #5
0
/**
 * Given a record in the {blog_external} table, checks the blog's URL
 * for new entries not yet copied into Moodle.
 * Also attempts to identify and remove deleted blog entries
 *
 * @param object $externalblog
 * @return boolean False if the Feed is invalid
 */
function blog_sync_external_entries($externalblog)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/simplepie/moodle_simplepie.php';
    $rssfile = new moodle_simplepie_file($externalblog->url);
    $filetest = new SimplePie_Locator($rssfile);
    if (!$filetest->is_feed($rssfile)) {
        $externalblog->failedlastsync = 1;
        $DB->update_record('blog_external', $externalblog);
        return false;
    } else {
        if (!empty($externalblog->failedlastsync)) {
            $externalblog->failedlastsync = 0;
            $DB->update_record('blog_external', $externalblog);
        }
    }
    $rss = new moodle_simplepie($externalblog->url);
    if (empty($rss->data)) {
        return null;
    }
    //used to identify blog posts that have been deleted from the source feed
    $oldesttimestamp = null;
    $uniquehashes = array();
    foreach ($rss->get_items() as $entry) {
        // If filtertags are defined, use them to filter the entries by RSS category
        if (!empty($externalblog->filtertags)) {
            $containsfiltertag = false;
            $categories = $entry->get_categories();
            $filtertags = explode(',', $externalblog->filtertags);
            $filtertags = array_map('trim', $filtertags);
            $filtertags = array_map('strtolower', $filtertags);
            foreach ($categories as $category) {
                if (in_array(trim(strtolower($category->term)), $filtertags)) {
                    $containsfiltertag = true;
                }
            }
            if (!$containsfiltertag) {
                continue;
            }
        }
        $uniquehashes[] = $entry->get_permalink();
        $newentry = new stdClass();
        $newentry->userid = $externalblog->userid;
        $newentry->module = 'blog_external';
        $newentry->content = $externalblog->id;
        $newentry->uniquehash = $entry->get_permalink();
        $newentry->publishstate = 'site';
        $newentry->format = FORMAT_HTML;
        // Clean subject of html, just in case
        $newentry->subject = clean_param($entry->get_title(), PARAM_TEXT);
        // Observe 128 max chars in DB
        // TODO: +1 to raise this to 255
        if (textlib::strlen($newentry->subject) > 128) {
            $newentry->subject = textlib::substr($newentry->subject, 0, 125) . '...';
        }
        $newentry->summary = $entry->get_description();
        //used to decide whether to insert or update
        //uses enty permalink plus creation date if available
        $existingpostconditions = array('uniquehash' => $entry->get_permalink());
        //our DB doesnt allow null creation or modified timestamps so check the external blog supplied one
        $entrydate = $entry->get_date('U');
        if (!empty($entrydate)) {
            $existingpostconditions['created'] = $entrydate;
        }
        //the post ID or false if post not found in DB
        $postid = $DB->get_field('post', 'id', $existingpostconditions);
        $timestamp = null;
        if (empty($entrydate)) {
            $timestamp = time();
        } else {
            $timestamp = $entrydate;
        }
        //only set created if its a new post so we retain the original creation timestamp if the post is edited
        if ($postid === false) {
            $newentry->created = $timestamp;
        }
        $newentry->lastmodified = $timestamp;
        if (empty($oldesttimestamp) || $timestamp < $oldesttimestamp) {
            //found an older post
            $oldesttimestamp = $timestamp;
        }
        if (textlib::strlen($newentry->uniquehash) > 255) {
            // The URL for this item is too long for the field. Rather than add
            // the entry without the link we will skip straight over it.
            // RSS spec says recommended length 500, we use 255.
            debugging('External blog entry skipped because of oversized URL', DEBUG_DEVELOPER);
            continue;
        }
        if ($postid === false) {
            $id = $DB->insert_record('post', $newentry);
            // Set tags
            if ($tags = tag_get_tags_array('blog_external', $externalblog->id)) {
                tag_set('post', $id, $tags);
            }
        } else {
            $newentry->id = $postid;
            $DB->update_record('post', $newentry);
        }
    }
    // Look at the posts we have in the database to check if any of them have been deleted from the feed.
    // Only checking posts within the time frame returned by the rss feed. Older items may have been deleted or
    // may just not be returned anymore. We can't tell the difference so we leave older posts alone.
    $sql = "SELECT id, uniquehash\n              FROM {post}\n             WHERE module = 'blog_external'\n                   AND " . $DB->sql_compare_text('content') . " = " . $DB->sql_compare_text(':blogid') . "\n                   AND created > :ts";
    $dbposts = $DB->get_records_sql($sql, array('blogid' => $externalblog->id, 'ts' => $oldesttimestamp));
    $todelete = array();
    foreach ($dbposts as $dbpost) {
        if (!in_array($dbpost->uniquehash, $uniquehashes)) {
            $todelete[] = $dbpost->id;
        }
    }
    $DB->delete_records_list('post', 'id', $todelete);
    $DB->update_record('blog_external', array('id' => $externalblog->id, 'timefetched' => time()));
}
Example #6
0
    print_error('guestnoeditprofileother');
}
if ($user->deleted) {
    echo $OUTPUT->header();
    echo $OUTPUT->heading(get_string('userdeleted'));
    echo $OUTPUT->footer();
    die;
}
// Load user preferences.
useredit_load_preferences($user);
// Load custom profile fields data.
profile_load_data($user);
// User interests.
if (!empty($CFG->usetags)) {
    require_once $CFG->dirroot . '/tag/lib.php';
    $user->interests = tag_get_tags_array('user', $id);
}
if ($user->id !== -1) {
    $usercontext = context_user::instance($user->id);
    $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => false, 'forcehttps' => false, 'context' => $usercontext);
    $user = file_prepare_standard_editor($user, 'description', $editoroptions, $usercontext, 'user', 'profile', 0);
} else {
    $usercontext = null;
    // This is a new user, we don't want to add files here.
    $editoroptions = array('maxfiles' => 0, 'maxbytes' => 0, 'trusttext' => false, 'forcehttps' => false, 'context' => $coursecontext);
}
// Prepare filemanager draft area.
$draftitemid = 0;
$filemanagercontext = $editoroptions['context'];
$filemanageroptions = array('maxbytes' => $CFG->maxbytes, 'subdirs' => 0, 'maxfiles' => 1, 'accepted_types' => 'web_image');
file_prepare_draft_area($draftitemid, $filemanagercontext->id, 'user', 'newicon', 0, $filemanageroptions);
Example #7
0
function wiki_reset_userdata($data)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/mod/wiki/pagelib.php';
    require_once $CFG->dirroot . '/tag/lib.php';
    require_once $CFG->dirroot . "/mod/wiki/locallib.php";
    $componentstr = get_string('modulenameplural', 'wiki');
    $status = array();
    //get the wiki(s) in this course.
    if (!($wikis = $DB->get_records('wiki', array('course' => $data->courseid)))) {
        return false;
    }
    $errors = false;
    foreach ($wikis as $wiki) {
        if (!($cm = get_coursemodule_from_instance('wiki', $wiki->id))) {
            continue;
        }
        $context = context_module::instance($cm->id);
        // Remove tags or all pages.
        if (!empty($data->reset_wiki_pages) || !empty($data->reset_wiki_tags)) {
            // Get subwiki information.
            $subwikis = wiki_get_subwikis($wiki->id);
            foreach ($subwikis as $subwiki) {
                // Get existing pages.
                if ($pages = wiki_get_page_list($subwiki->id)) {
                    // If the wiki page isn't selected then we are only removing tags.
                    if (empty($data->reset_wiki_pages)) {
                        // Go through each page and delete the tags.
                        foreach ($pages as $page) {
                            $tags = tag_get_tags_array('wiki_pages', $page->id);
                            foreach ($tags as $tagid => $tagname) {
                                // Delete the related tag_instances related to the wiki page.
                                $errors = tag_delete_instance('wiki_pages', $page->id, $tagid);
                                $status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'), 'error' => $errors);
                            }
                        }
                    } else {
                        // Otherwise we are removing pages and tags.
                        wiki_delete_pages($context, $pages, $subwiki->id);
                    }
                }
                if (!empty($data->reset_wiki_pages)) {
                    // Delete any subwikis.
                    $DB->delete_records('wiki_subwikis', array('id' => $subwiki->id), IGNORE_MISSING);
                    // Delete any attached files.
                    $fs = get_file_storage();
                    $fs->delete_area_files($context->id, 'mod_wiki', 'attachments');
                    $status[] = array('component' => $componentstr, 'item' => get_string('deleteallpages', 'wiki'), 'error' => $errors);
                }
            }
        }
        // Remove all comments.
        if (!empty($data->reset_wiki_comments) || !empty($data->reset_wiki_pages)) {
            $DB->delete_records_select('comments', "contextid = ? AND commentarea='wiki_page'", array($context->id));
            $status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
        }
    }
    return $status;
}
Example #8
0
function blog_generate_rss_feed($type, $id, $tagid = 0)
{
    global $CFG, $SITE;
    if (empty($CFG->enablerssfeeds)) {
        debugging('Sorry, RSS feeds are disabled on this site');
        return '';
    }
    $filename = blog_rss_file_name($type, $id, $tagid);
    if (file_exists($filename)) {
        if (filemtime($filename) + 3600 > time()) {
            return $filename;
            /// It's already done so we return cached version
        }
    }
    /// Get all the posts from the database
    $blogposts = blog_fetch_entries('', 20, '', $type, $id, $tagid);
    /// Now generate an array of RSS items
    if ($blogposts) {
        $items = array();
        foreach ($blogposts as $blogpost) {
            $item = NULL;
            $item->author = fullname(get_record('user', 'id', $blogpost->userid));
            $item->title = $blogpost->subject;
            $item->pubdate = $blogpost->lastmodified;
            $item->link = $CFG->wwwroot . '/blog/index.php?postid=' . $blogpost->id;
            $item->description = format_text($blogpost->summary, $blogpost->format);
            if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blogpost->id))) {
                if ($blogtags) {
                    $item->tags = $blogtags;
                }
                $item->tagscheme = $CFG->wwwroot . '/tag';
            }
            $items[] = $item;
        }
        $articles = rss_add_items($items);
        /// Change structure to XML
    } else {
        $articles = '';
    }
    /// Get header and footer information
    switch ($type) {
        case 'user':
            $info = fullname(get_record('user', 'id', $id, '', '', '', '', 'firstname,lastname'));
            break;
        case 'course':
            $info = get_field('course', 'fullname', 'id', $id);
            break;
        case 'site':
            $info = $SITE->fullname;
            break;
        case 'group':
            $group = groups_get_group($id, false);
            $info = $group->name;
            //TODO: get_field('groups', 'name', 'id', $id)
            break;
        default:
            $info = '';
            break;
    }
    if ($tagid) {
        $info .= ': ' . get_field('tags', 'text', 'id', $tagid);
    }
    $header = rss_standard_header(get_string($type . 'blog', 'blog', $info), $CFG->wwwroot . '/blog/index.php', get_string('intro', 'blog'));
    $footer = rss_standard_footer();
    /// Save the XML contents to file.
    $rssdata = $header . $articles . $footer;
    if (blog_rss_save_file($type, $id, $tagid, $rssdata)) {
        return $filename;
    } else {
        return false;
        // Couldn't find it or make it
    }
}
Example #9
0
    case 'add':
        // prepare new empty form
        $post->publishstate = 'site';
        $strformheading = get_string('addnewentry', 'blog');
        $post->action = $action;
        break;
    case 'edit':
        if (!$existing) {
            print_error('wrongpostid', 'blog');
        }
        $post->id = $existing->id;
        $post->subject = $existing->subject;
        $post->summary = $existing->summary;
        $post->publishstate = $existing->publishstate;
        $post->format = $existing->format;
        $post->tags = tag_get_tags_array('post', $post->id);
        $post->action = $action;
        $strformheading = get_string('updateentrywithid', 'blog');
        break;
    default:
        print_error('unknowaction');
}
// done here in order to allow deleting of posts with wrong user id above
if (!($user = $DB->get_record('user', array('id' => $userid)))) {
    print_error('invaliduserid');
}
$navlinks = array();
$navlinks[] = array('name' => fullname($user), 'link' => "{$CFG->wwwroot}/user/view.php?id={$userid}", 'type' => 'misc');
$navlinks[] = array('name' => $strblogs, 'link' => "{$CFG->wwwroot}/blog/index.php?userid={$userid}", 'type' => 'misc');
$navlinks[] = array('name' => $strformheading, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
Example #10
0
function wiki_print_page_content($page, $context, $subwikiid)
{
    global $OUTPUT, $CFG;
    if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
        $content = wiki_refresh_cachedcontent($page);
        $page = $content['page'];
    }
    if (isset($content)) {
        $box = '';
        foreach ($content['sections'] as $s) {
            $box .= '<p>' . get_string('repeatedsection', 'wiki', $s) . '</p>';
        }
        if (!empty($box)) {
            echo $OUTPUT->box($box);
        }
    }
    $html = file_rewrite_pluginfile_urls($page->cachedcontent, 'pluginfile.php', $context->id, 'mod_wiki', 'attachments', $subwikiid);
    $html = format_text($html, FORMAT_MOODLE, array('overflowdiv' => true));
    echo $OUTPUT->box($html);
    if (!empty($CFG->usetags)) {
        $tags = tag_get_tags_array('wiki_pages', $page->id);
        echo '<p class="wiki-tags"><span>Tags: </span>' . join($tags, ", ") . '</p>';
    }
    wiki_increment_pageviews($page);
}
Example #11
0
    protected function print_edit($content = null) {
        global $CFG, $OUTPUT, $USER, $PAGE;

        if (!$this->check_locks()) {
            return;
        }

        //delete old locks (> 1 hour)
        wiki_delete_old_locks();

        $version = wiki_get_current_version($this->page->id);
        $format = $version->contentformat;

        if ($content == null) {
            if (empty($this->section)) {
                $content = $version->content;
            } else {
                $content = $this->sectioncontent;
            }
        }

        $versionnumber = $version->version;
        if ($this->versionnumber >= 0) {
            if ($version->version != $this->versionnumber) {
                print $OUTPUT->box(get_string('wrongversionlock', 'wiki'), 'errorbox');
                $versionnumber = $this->versionnumber;
            }
        }

        $url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
        if (!empty($this->section)) {
            $url .= "&section=" . $this->section;
        }

        $params = array('attachmentoptions' => page_wiki_edit::$attachmentoptions, 'format' => $version->contentformat, 'version' => $versionnumber, 'pagetitle'=>$this->page->title);

        $data = new StdClass();
        $data->newcontent = $content;
        $data->version = $versionnumber;
        $data->format = $format;

        switch ($format) {
        case 'html':
            $data->newcontentformat = FORMAT_HTML;
            $data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id);
            break;
        default:
            //$draftitemid = file_get_submitted_draft_itemid('attachments');
            //file_prepare_draft_area($draftitemid, $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id);
            //$data->attachments = $draftitemid;
            }

        if ($version->contentformat != 'html') {
            $params['contextid'] = $this->modcontext->id;
            $params['component'] = 'mod_wiki';
            $params['filearea'] = 'attachments';
            $params['fileitemid'] = $this->subwiki->id;
        }

        if (!empty($CFG->usetags)) {
            $params['tags'] = tag_get_tags_csv('wiki_pages', $this->page->id, TAG_RETURN_TEXT);
        }

        $form = new mod_wiki_edit_form($url, $params);

        if ($formdata = $form->get_data()) {
            if ($format != 'html') {
                $errors = $this->process_uploads($this->modcontext);
                if (!empty($errors)) {
                    $contenterror = "";
                    foreach ($errors as $e) {
                        $contenterror .= "<p>" . get_string('filenotuploadederror', 'wiki', $e->get_filename()) . "</p>";
                    }
                    print $OUTPUT->box($contenterror, 'errorbox');
                }
            }
            if (!empty($CFG->usetags)) {
                $data->tags = $formdata->tags;
            }
        } else {
            if (!empty($CFG->usetags)) {
                $data->tags = tag_get_tags_array('wiki', $this->page->id);
            }
        }

        $form->set_data($data);
        $form->display();
    }
Example #12
0
require_login();
// Check capabilities but do not call require_login($course) - the user does not have to be enrolled.
$context = context_course::instance($course->id);
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
    print_error('coursehidden', '', $CFG->wwwroot . '/');
}
require_capability('moodle/course:tag', $context);
if (empty($CFG->usetags)) {
    print_error('tagsaredisabled', 'tag');
}
$PAGE->set_course($course);
$PAGE->set_pagelayout('incourse');
$PAGE->set_url('/course/tags.php', array('id' => $course->id));
$PAGE->set_title(get_string('coursetags', 'tag'));
$PAGE->set_heading($course->fullname);
$form = new coursetags_form();
$data = array('id' => $course->id, 'tags' => tag_get_tags_array('course', $course->id));
$form->set_data($data);
$redirecturl = $returnurl ? new moodle_url($returnurl) : course_get_url($course);
if ($form->is_cancelled()) {
    redirect($redirecturl);
} else {
    if ($data = $form->get_data()) {
        tag_set('course', $course->id, $data->tags, 'core', context_course::instance($course->id)->id);
        redirect($redirecturl);
    }
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('coursetags', 'tag'));
$form->display();
echo $OUTPUT->footer();
Example #13
0
 /**
  * Turns question into an xml segment
  * @param object question object
  * @param int context id
  * @return string xml segment
  */
 function writequestion($question)
 {
     global $CFG, $QTYPES, $OUTPUT;
     $fs = get_file_storage();
     $contextid = $question->contextid;
     // initial string;
     $expout = "";
     // add comment
     $expout .= "\n\n<!-- question: {$question->id}  -->\n";
     // check question type
     if (!($question_type = $this->get_qtype($question->qtype))) {
         // must be a plugin then, so just accept the name supplied
         $question_type = $question->qtype;
     }
     // add opening tag
     // generates specific header for Cloze and category type question
     if ($question->qtype == 'category') {
         $categorypath = $this->writetext($question->category);
         $expout .= "  <question type=\"category\">\n";
         $expout .= "    <category>\n";
         $expout .= "        {$categorypath}\n";
         $expout .= "    </category>\n";
         $expout .= "  </question>\n";
         return $expout;
     } elseif ($question->qtype != MULTIANSWER) {
         // for all question types except Close
         $name_text = $this->writetext($question->name);
         $qtformat = $this->get_format($question->questiontextformat);
         $generalfeedbackformat = $this->get_format($question->generalfeedbackformat);
         $question_text = $this->writetext($question->questiontext);
         $question_text_files = $this->write_files($question->questiontextfiles);
         $generalfeedback = $this->writetext($question->generalfeedback);
         $generalfeedback_files = $this->write_files($question->generalfeedbackfiles);
         $expout .= "  <question type=\"{$question_type}\">\n";
         $expout .= "    <name>{$name_text}</name>\n";
         $expout .= "    <questiontext format=\"{$qtformat}\">\n";
         $expout .= $question_text;
         $expout .= $question_text_files;
         $expout .= "    </questiontext>\n";
         $expout .= "    <generalfeedback format=\"{$generalfeedbackformat}\">\n";
         $expout .= $generalfeedback;
         $expout .= $generalfeedback_files;
         $expout .= "    </generalfeedback>\n";
         $expout .= "    <defaultgrade>{$question->defaultgrade}</defaultgrade>\n";
         $expout .= "    <penalty>{$question->penalty}</penalty>\n";
         $expout .= "    <hidden>{$question->hidden}</hidden>\n";
     } else {
         // for Cloze type only
         $name_text = $this->writetext($question->name);
         $question_text = $this->writetext($question->questiontext);
         $generalfeedback = $this->writetext($question->generalfeedback);
         $expout .= "  <question type=\"{$question_type}\">\n";
         $expout .= "    <name>{$name_text}</name>\n";
         $expout .= "    <questiontext>\n";
         $expout .= $question_text;
         $expout .= "    </questiontext>\n";
         $expout .= "    <generalfeedback>\n";
         $expout .= $generalfeedback;
         $expout .= "    </generalfeedback>\n";
     }
     if (!empty($question->options->shuffleanswers)) {
         $expout .= "    <shuffleanswers>{$question->options->shuffleanswers}</shuffleanswers>\n";
     } else {
         $expout .= "    <shuffleanswers>0</shuffleanswers>\n";
     }
     // output depends on question type
     switch ($question->qtype) {
         case 'category':
             // not a qtype really - dummy used for category switching
             break;
         case TRUEFALSE:
             foreach ($question->options->answers as $answer) {
                 $fraction_pc = round($answer->fraction * 100);
                 if ($answer->id == $question->options->trueanswer) {
                     $answertext = 'true';
                 } else {
                     $answertext = 'false';
                 }
                 $expout .= "    <answer fraction=\"{$fraction_pc}\">\n";
                 $expout .= $this->writetext($answertext, 3) . "\n";
                 $feedbackformat = $this->get_format($answer->feedbackformat);
                 $expout .= "      <feedback format=\"{$feedbackformat}\">\n";
                 $expout .= $this->writetext($answer->feedback, 4, false);
                 $expout .= $this->write_files($answer->feedbackfiles);
                 $expout .= "      </feedback>\n";
                 $expout .= "    </answer>\n";
             }
             break;
         case MULTICHOICE:
             $expout .= "    <single>" . $this->get_single($question->options->single) . "</single>\n";
             $expout .= "    <shuffleanswers>" . $this->get_single($question->options->shuffleanswers) . "</shuffleanswers>\n";
             $textformat = $this->get_format($question->options->correctfeedbackformat);
             $files = $fs->get_area_files($contextid, 'qtype_multichoice', 'correctfeedback', $question->id);
             $expout .= "    <correctfeedback format=\"{$textformat}\">\n";
             $expout .= $this->writetext($question->options->correctfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </correctfeedback>\n";
             $textformat = $this->get_format($question->options->partiallycorrectfeedbackformat);
             $files = $fs->get_area_files($contextid, 'qtype_multichoice', 'partiallycorrectfeedback', $question->id);
             $expout .= "    <partiallycorrectfeedback format=\"{$textformat}\">\n";
             $expout .= $this->writetext($question->options->partiallycorrectfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </partiallycorrectfeedback>\n";
             $textformat = $this->get_format($question->options->incorrectfeedbackformat);
             $files = $fs->get_area_files($contextid, 'qtype_multichoice', 'incorrectfeedback', $question->id);
             $expout .= "    <incorrectfeedback format=\"{$textformat}\">\n";
             $expout .= $this->writetext($question->options->incorrectfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </incorrectfeedback>\n";
             $expout .= "    <answernumbering>{$question->options->answernumbering}</answernumbering>\n";
             foreach ($question->options->answers as $answer) {
                 $percent = $answer->fraction * 100;
                 $expout .= "      <answer fraction=\"{$percent}\">\n";
                 $expout .= $this->writetext($answer->answer, 4, false);
                 $feedbackformat = $this->get_format($answer->feedbackformat);
                 $expout .= "      <feedback format=\"{$feedbackformat}\">\n";
                 $expout .= $this->writetext($answer->feedback, 5, false);
                 $expout .= $this->write_files($answer->feedbackfiles);
                 $expout .= "      </feedback>\n";
                 $expout .= "    </answer>\n";
             }
             break;
         case SHORTANSWER:
             $expout .= "    <usecase>{$question->options->usecase}</usecase>\n ";
             foreach ($question->options->answers as $answer) {
                 $percent = 100 * $answer->fraction;
                 $expout .= "    <answer fraction=\"{$percent}\">\n";
                 $expout .= $this->writetext($answer->answer, 3, false);
                 $feedbackformat = $this->get_format($answer->feedbackformat);
                 $expout .= "      <feedback format=\"{$feedbackformat}\">\n";
                 $expout .= $this->writetext($answer->feedback);
                 $expout .= $this->write_files($answer->feedbackfiles);
                 $expout .= "      </feedback>\n";
                 $expout .= "    </answer>\n";
             }
             break;
         case NUMERICAL:
             foreach ($question->options->answers as $answer) {
                 $tolerance = $answer->tolerance;
                 $percent = 100 * $answer->fraction;
                 $expout .= "<answer fraction=\"{$percent}\">\n";
                 // <text> tags are an added feature, old filed won't have them
                 $expout .= "    <text>{$answer->answer}</text>\n";
                 $expout .= "    <tolerance>{$tolerance}</tolerance>\n";
                 $feedbackformat = $this->get_format($answer->feedbackformat);
                 $expout .= "    <feedback format=\"{$feedbackformat}\">\n";
                 $expout .= $this->writetext($answer->feedback);
                 $expout .= $this->write_files($answer->feedbackfiles);
                 $expout .= "    </feedback>\n";
                 // fraction tag is deprecated
                 // $expout .= "    <fraction>{$answer->fraction}</fraction>\n";
                 $expout .= "</answer>\n";
             }
             $units = $question->options->units;
             if (count($units)) {
                 $expout .= "<units>\n";
                 foreach ($units as $unit) {
                     $expout .= "  <unit>\n";
                     $expout .= "    <multiplier>{$unit->multiplier}</multiplier>\n";
                     $expout .= "    <unit_name>{$unit->unit}</unit_name>\n";
                     $expout .= "  </unit>\n";
                 }
                 $expout .= "</units>\n";
             }
             if (isset($question->options->unitgradingtype)) {
                 $expout .= "    <unitgradingtype>{$question->options->unitgradingtype}</unitgradingtype>\n";
             }
             if (isset($question->options->unitpenalty)) {
                 $expout .= "    <unitpenalty>{$question->options->unitpenalty}</unitpenalty>\n";
             }
             if (isset($question->options->showunits)) {
                 $expout .= "    <showunits>{$question->options->showunits}</showunits>\n";
             }
             if (isset($question->options->unitsleft)) {
                 $expout .= "    <unitsleft>{$question->options->unitsleft}</unitsleft>\n";
             }
             if (!empty($question->options->instructionsformat)) {
                 $textformat = $this->get_format($question->options->instructionsformat);
                 $files = $fs->get_area_files($contextid, 'qtype_numerical', 'instruction', $question->id);
                 $expout .= "    <instructions format=\"{$textformat}\">\n";
                 $expout .= $this->writetext($question->options->instructions, 3);
                 $expout .= $this->write_files($files);
                 $expout .= "    </instructions>\n";
             }
             break;
         case MATCH:
             foreach ($question->options->subquestions as $subquestion) {
                 $files = $fs->get_area_files($contextid, 'qtype_match', 'subquestion', $subquestion->id);
                 $textformat = $this->get_format($subquestion->questiontextformat);
                 $expout .= "<subquestion format=\"{$textformat}\">\n";
                 $expout .= $this->writetext($subquestion->questiontext);
                 $expout .= $this->write_files($files);
                 $expout .= "<answer>";
                 $expout .= $this->writetext($subquestion->answertext);
                 $expout .= "</answer>\n";
                 $expout .= "</subquestion>\n";
             }
             break;
         case DESCRIPTION:
             // nothing more to do for this type
             break;
         case MULTIANSWER:
             $a_count = 1;
             foreach ($question->options->questions as $question) {
                 $thispattern = preg_quote("{#" . $a_count . "}");
                 //TODO: is this really necessary?
                 $thisreplace = $question->questiontext;
                 $expout = preg_replace("~{$thispattern}~", $thisreplace, $expout);
                 $a_count++;
             }
             break;
         case ESSAY:
             if (!empty($question->options->answers)) {
                 foreach ($question->options->answers as $answer) {
                     $percent = 100 * $answer->fraction;
                     $expout .= "<answer fraction=\"{$percent}\">\n";
                     $feedbackformat = $this->get_format($answer->feedbackformat);
                     $expout .= "    <feedback format=\"{$feedbackformat}\">\n";
                     $expout .= $this->writetext($answer->feedback);
                     $expout .= $this->write_files($answer->feedbackfiles);
                     $expout .= "    </feedback>\n";
                     // fraction tag is deprecated
                     // $expout .= "    <fraction>{$answer->fraction}</fraction>\n";
                     $expout .= "</answer>\n";
                 }
             }
             break;
         case CALCULATED:
         case CALCULATEDSIMPLE:
         case CALCULATEDMULTI:
             $expout .= "    <synchronize>{$question->options->synchronize}</synchronize>\n";
             $expout .= "    <single>{$question->options->single}</single>\n";
             $expout .= "    <answernumbering>{$question->options->answernumbering}</answernumbering>\n";
             $expout .= "    <shuffleanswers>" . $this->writetext($question->options->shuffleanswers, 3) . "</shuffleanswers>\n";
             $component = 'qtype_' . $question->qtype;
             $files = $fs->get_area_files($contextid, $component, 'correctfeedback', $question->id);
             $expout .= "    <correctfeedback>\n";
             $expout .= $this->writetext($question->options->correctfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </correctfeedback>\n";
             $files = $fs->get_area_files($contextid, $component, 'partiallycorrectfeedback', $question->id);
             $expout .= "    <partiallycorrectfeedback>\n";
             $expout .= $this->writetext($question->options->partiallycorrectfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </partiallycorrectfeedback>\n";
             $files = $fs->get_area_files($contextid, $component, 'incorrectfeedback', $question->id);
             $expout .= "    <incorrectfeedback>\n";
             $expout .= $this->writetext($question->options->incorrectfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </incorrectfeedback>\n";
             foreach ($question->options->answers as $answer) {
                 $tolerance = $answer->tolerance;
                 $tolerancetype = $answer->tolerancetype;
                 $correctanswerlength = $answer->correctanswerlength;
                 $correctanswerformat = $answer->correctanswerformat;
                 $percent = 100 * $answer->fraction;
                 $expout .= "<answer fraction=\"{$percent}\">\n";
                 // "<text/>" tags are an added feature, old files won't have them
                 $expout .= "    <text>{$answer->answer}</text>\n";
                 $expout .= "    <tolerance>{$tolerance}</tolerance>\n";
                 $expout .= "    <tolerancetype>{$tolerancetype}</tolerancetype>\n";
                 $expout .= "    <correctanswerformat>{$correctanswerformat}</correctanswerformat>\n";
                 $expout .= "    <correctanswerlength>{$correctanswerlength}</correctanswerlength>\n";
                 $feedbackformat = $this->get_format($answer->feedbackformat);
                 $expout .= "    <feedback format=\"{$feedbackformat}\">\n";
                 $expout .= $this->writetext($answer->feedback);
                 $expout .= $this->write_files($answer->feedbackfiles);
                 $expout .= "    </feedback>\n";
                 $expout .= "</answer>\n";
             }
             if (isset($question->options->unitgradingtype)) {
                 $expout .= "    <unitgradingtype>{$question->options->unitgradingtype}</unitgradingtype>\n";
             }
             if (isset($question->options->unitpenalty)) {
                 $expout .= "    <unitpenalty>{$question->options->unitpenalty}</unitpenalty>\n";
             }
             if (isset($question->options->showunits)) {
                 $expout .= "    <showunits>{$question->options->showunits}</showunits>\n";
             }
             if (isset($question->options->unitsleft)) {
                 $expout .= "    <unitsleft>{$question->options->unitsleft}</unitsleft>\n";
             }
             if (isset($question->options->instructionsformat)) {
                 $textformat = $this->get_format($question->options->instructionsformat);
                 $files = $fs->get_area_files($contextid, $component, 'instruction', $question->id);
                 $expout .= "    <instructions format=\"{$textformat}\">\n";
                 $expout .= $this->writetext($question->options->instructions, 3);
                 $expout .= $this->write_files($files);
                 $expout .= "    </instructions>\n";
             }
             if (isset($question->options->units)) {
                 $units = $question->options->units;
                 if (count($units)) {
                     $expout .= "<units>\n";
                     foreach ($units as $unit) {
                         $expout .= "  <unit>\n";
                         $expout .= "    <multiplier>{$unit->multiplier}</multiplier>\n";
                         $expout .= "    <unit_name>{$unit->unit}</unit_name>\n";
                         $expout .= "  </unit>\n";
                     }
                     $expout .= "</units>\n";
                 }
             }
             //The tag $question->export_process has been set so we get all the data items in the database
             //   from the function $QTYPES['calculated']->get_question_options(&$question);
             //  calculatedsimple defaults to calculated
             if (isset($question->options->datasets) && count($question->options->datasets)) {
                 // there should be
                 $expout .= "<dataset_definitions>\n";
                 foreach ($question->options->datasets as $def) {
                     $expout .= "<dataset_definition>\n";
                     $expout .= "    <status>" . $this->writetext($def->status) . "</status>\n";
                     $expout .= "    <name>" . $this->writetext($def->name) . "</name>\n";
                     if ($question->qtype == CALCULATED) {
                         $expout .= "    <type>calculated</type>\n";
                     } else {
                         $expout .= "    <type>calculatedsimple</type>\n";
                     }
                     $expout .= "    <distribution>" . $this->writetext($def->distribution) . "</distribution>\n";
                     $expout .= "    <minimum>" . $this->writetext($def->minimum) . "</minimum>\n";
                     $expout .= "    <maximum>" . $this->writetext($def->maximum) . "</maximum>\n";
                     $expout .= "    <decimals>" . $this->writetext($def->decimals) . "</decimals>\n";
                     $expout .= "    <itemcount>{$def->itemcount}</itemcount>\n";
                     if ($def->itemcount > 0) {
                         $expout .= "    <dataset_items>\n";
                         foreach ($def->items as $item) {
                             $expout .= "        <dataset_item>\n";
                             $expout .= "           <number>" . $item->itemnumber . "</number>\n";
                             $expout .= "           <value>" . $item->value . "</value>\n";
                             $expout .= "        </dataset_item>\n";
                         }
                         $expout .= "    </dataset_items>\n";
                         $expout .= "    <number_of_items>" . $def->number_of_items . "</number_of_items>\n";
                     }
                     $expout .= "</dataset_definition>\n";
                 }
                 $expout .= "</dataset_definitions>\n";
             }
             break;
         default:
             // try support by optional plugin
             if (!($data = $this->try_exporting_using_qtypes($question->qtype, $question))) {
                 echo $OUTPUT->notification(get_string('unsupportedexport', 'qformat_xml', $QTYPES[$question->qtype]->local_name()));
             }
             $expout .= $data;
     }
     // Write the question tags.
     if (!empty($CFG->usetags)) {
         require_once $CFG->dirroot . '/tag/lib.php';
         $tags = tag_get_tags_array('question', $question->id);
         if (!empty($tags)) {
             $expout .= "    <tags>\n";
             foreach ($tags as $tag) {
                 $expout .= "      <tag>" . $this->writetext($tag, 0, true) . "</tag>\n";
             }
             $expout .= "    </tags>\n";
         }
     }
     // close the question tag
     $expout .= "</question>\n";
     return $expout;
 }
 public function definition_after_data()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     $name = trim($mform->getElementValue('name'));
     $description = trim($mform->getElementValue('description'));
     $url = $mform->getElementValue('url');
     if (empty($name) || empty($description)) {
         $rss = new moodle_simplepie($url);
         if (empty($name) && $rss->get_title()) {
             $mform->setDefault('name', $rss->get_title());
         }
         if (empty($description) && $rss->get_description()) {
             $mform->setDefault('description', $rss->get_description());
         }
     }
     if ($id = $mform->getElementValue('id')) {
         $mform->setDefault('autotags', implode(',', tag_get_tags_array('blog_external', $id)));
         $mform->freeze('url');
         if ($mform->elementExists('filtertags')) {
             $mform->freeze('filtertags');
         }
         // TODO change the filtertags element to a multiple select, using the tags of the external blog
         // Use $rss->get_channel_tags()
     }
 }
Example #15
0
 public function definition()
 {
     $mform =& $this->_form;
     $this->user = $this->_customdata['user'];
     $mform->addElement('hidden', 'action', 'classify');
     $mform->addElement('hidden', 'id', $this->user->id);
     $selected = array();
     if ($itemptags = tag_get_tags_array('userclassify', $this->user->id)) {
         foreach ($itemptags as $itag) {
             $selected[strtolower($itag)] = 1;
         }
     }
     $types = get_records('classification_type');
     $allvalues = tao_get_classifications(false);
     $checkboxes = array();
     foreach ($allvalues as $value) {
         if (!array_key_exists($value->typeid, $checkboxes)) {
             $checkboxes[$value->typeid] = array();
         }
         $checkboxes[$value->typeid][] = $mform->createElement('checkbox', strtolower($value->value), $value->value, $value->value);
     }
     foreach ($types as $type) {
         $mform->addElement('header', $type->name);
         $mform->addGroup($checkboxes[$type->id], 'checkboxes' . $type->id, $type->name);
         $mform->setDefault('checkboxes' . $type->id, $selected);
     }
     $this->add_action_buttons(false);
 }
Example #16
0
/**
 * Private function to factor common code out of get_question_options().
 *
 * @param object $question the question to tidy.
 * @param boolean $loadtags load the question tags from the tags table. Optional, default false.
 * @return boolean true if successful, else false.
 */
function _tidy_question(&$question, $loadtags = false)
{
    global $CFG, $QTYPES;
    if (!array_key_exists($question->qtype, $QTYPES)) {
        $question->qtype = 'missingtype';
        $question->questiontext = '<p>' . get_string('warningmissingtype', 'quiz') . '</p>' . $question->questiontext;
    }
    $question->name_prefix = question_make_name_prefix($question->id);
    if ($success = $QTYPES[$question->qtype]->get_question_options($question)) {
        if (isset($question->_partiallyloaded)) {
            unset($question->_partiallyloaded);
        }
    }
    if ($loadtags && !empty($CFG->usetags)) {
        require_once $CFG->dirroot . '/tag/lib.php';
        $question->tags = tag_get_tags_array('question', $question->id);
    }
    return $success;
}
Example #17
0
$files = $fs->get_area_files($context->id, 'mod_booking', 'myfilemanager', $booking->booking->id);
if (count($files) > 0) {
    echo html_writer::start_tag('div');
    echo html_writer::tag('label', get_string("attachedfiles", "booking") . ': ', array('class' => 'bold'));
    foreach ($files as $file) {
        if ($file->get_filesize() > 0) {
            $filename = $file->get_filename();
            $furl = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . '/' . $file->get_itemid() . '/' . $file->get_filename());
            $out[] = html_writer::link($furl, $filename);
        }
    }
    echo html_writer::tag('span', implode(', ', $out));
    echo html_writer::end_tag('div');
}
if (!empty($CFG->usetags)) {
    $tags = tag_get_tags_array('booking', $booking->booking->id);
    $links = array();
    foreach ($tags as $tagid => $tag) {
        $turl = new moodle_url('tag.php', array('id' => $id, 'tag' => $tag));
        $links[] = html_writer::link($turl, $tag, array());
    }
    if (!empty($tags)) {
        echo html_writer::start_tag('div');
        echo html_writer::tag('label', get_string('tags') . ': ', array('class' => 'bold'));
        echo html_writer::tag('span', implode(', ', $links));
        echo html_writer::end_tag('div');
    }
}
if ($booking->booking->categoryid != '0' && $booking->booking->categoryid != '') {
    $categoryies = explode(',', $booking->booking->categoryid);
    if (count($categoryies) > 0) {
/**
 * Private function to factor common code out of get_question_options().
 *
 * @param object $question the question to tidy.
 * @param boolean $loadtags load the question tags from the tags table. Optional, default false.
 */
function _tidy_question($question, $loadtags = false)
{
    global $CFG;
    // Load question-type specific fields.
    if (!question_bank::is_qtype_installed($question->qtype)) {
        $question->questiontext = html_writer::tag('p', get_string('warningmissingtype', 'qtype_missingtype')) . $question->questiontext;
    }
    question_bank::get_qtype($question->qtype)->get_question_options($question);
    // Convert numeric fields to float. (Prevents these being displayed as 1.0000000.)
    $question->defaultmark += 0;
    $question->penalty += 0;
    if (isset($question->_partiallyloaded)) {
        unset($question->_partiallyloaded);
    }
    if ($loadtags && !empty($CFG->usetags)) {
        require_once $CFG->dirroot . '/tag/lib.php';
        $question->tags = tag_get_tags_array('question', $question->id);
    }
}
 function data_preprocessing(&$default_values)
 {
     $options = array('subdirs' => false, 'maxfiles' => 50, 'accepted_types' => array('*'), 'maxbytes' => 0);
     if ($this->current->instance) {
         $draftitemid = file_get_submitted_draft_itemid('myfilemanager');
         file_prepare_draft_area($draftitemid, $this->context->id, 'mod_booking', 'myfilemanager', $this->current->id, $options);
         $default_values['myfilemanager'] = $draftitemid;
         $default_values['tags'] = tag_get_tags_array('booking', $this->current->id);
     } else {
         $draftitemid = file_get_submitted_draft_itemid('myfilemanager');
         file_prepare_draft_area($draftitemid, null, 'mod_booking', 'myfilemanager', 0, $options);
         $default_values['myfilemanager'] = $draftitemid;
     }
     if (empty($default_values['timeopen'])) {
         $default_values['timerestrict'] = 0;
     } else {
         $default_values['timerestrict'] = 1;
     }
     if (!isset($default_values['bookingpolicyformat'])) {
         $default_values['bookingpolicyformat'] = FORMAT_HTML;
     }
     if (!isset($default_values['bookingpolicy'])) {
         $default_values['bookingpolicy'] = '';
     }
     if (!isset($default_values['showinapi'])) {
         $default_values['showinapi'] = 1;
     }
     $default_values['bookingpolicy'] = array('text' => $default_values['bookingpolicy'], 'format' => $default_values['bookingpolicyformat']);
     if (isset($default_values['bookedtext'])) {
         $default_values['bookedtext'] = array('text' => $default_values['bookedtext'], 'format' => FORMAT_HTML);
     }
     if (isset($default_values['waitingtext'])) {
         $default_values['waitingtext'] = array('text' => $default_values['waitingtext'], 'format' => FORMAT_HTML);
     }
     if (isset($default_values['statuschangetext'])) {
         $default_values['statuschangetext'] = array('text' => $default_values['statuschangetext'], 'format' => FORMAT_HTML);
     }
     if (isset($default_values['deletedtext'])) {
         $default_values['deletedtext'] = array('text' => $default_values['deletedtext'], 'format' => FORMAT_HTML);
     }
     if (isset($default_values['pollurltext'])) {
         $default_values['pollurltext'] = array('text' => $default_values['pollurltext'], 'format' => FORMAT_HTML);
     }
     if (isset($default_values['pollurlteacherstext'])) {
         $default_values['pollurlteacherstext'] = array('text' => $default_values['pollurlteacherstext'], 'format' => FORMAT_HTML);
     }
     if (isset($default_values['notificationtext'])) {
         $default_values['notificationtext'] = array('text' => $default_values['notificationtext'], 'format' => FORMAT_HTML);
     }
     if (isset($default_values['userleave'])) {
         $default_values['userleave'] = array('text' => $default_values['userleave'], 'format' => FORMAT_HTML);
     }
 }
Example #20
0
 /**
  * Turns question into an xml segment
  * @param object $question the question data.
  * @return string xml segment
  */
 public function writequestion($question)
 {
     global $CFG, $OUTPUT;
     $fs = get_file_storage();
     $contextid = $question->contextid;
     // Get files used by the questiontext.
     $question->questiontextfiles = $fs->get_area_files($contextid, 'question', 'questiontext', $question->id);
     // Get files used by the generalfeedback.
     $question->generalfeedbackfiles = $fs->get_area_files($contextid, 'question', 'generalfeedback', $question->id);
     if (!empty($question->options->answers)) {
         foreach ($question->options->answers as $answer) {
             $answer->answerfiles = $fs->get_area_files($contextid, 'question', 'answer', $answer->id);
             $answer->feedbackfiles = $fs->get_area_files($contextid, 'question', 'answerfeedback', $answer->id);
         }
     }
     $expout = '';
     // Add a comment linking this to the original question id.
     $expout .= "<!-- question: {$question->id}  -->\n";
     // Check question type
     $questiontype = $this->get_qtype($question->qtype);
     // Categories are a special case.
     if ($question->qtype == 'category') {
         $categorypath = $this->writetext($question->category);
         $expout .= "  <question type=\"category\">\n";
         $expout .= "    <category>\n";
         $expout .= "        {$categorypath}\n";
         $expout .= "    </category>\n";
         $expout .= "  </question>\n";
         return $expout;
     }
     // Now we know we are are handing a real question.
     // Output the generic information.
     $expout .= "  <question type=\"{$questiontype}\">\n";
     $expout .= "    <name>\n";
     $expout .= $this->writetext($question->name, 3);
     $expout .= "    </name>\n";
     $expout .= "    <questiontext {$this->format($question->questiontextformat)}>\n";
     $expout .= $this->writetext($question->questiontext, 3);
     $expout .= $this->write_files($question->questiontextfiles);
     $expout .= "    </questiontext>\n";
     $expout .= "    <generalfeedback {$this->format($question->generalfeedbackformat)}>\n";
     $expout .= $this->writetext($question->generalfeedback, 3);
     $expout .= $this->write_files($question->generalfeedbackfiles);
     $expout .= "    </generalfeedback>\n";
     if ($question->qtype != 'multianswer') {
         $expout .= "    <defaultgrade>{$question->defaultmark}</defaultgrade>\n";
     }
     $expout .= "    <penalty>{$question->penalty}</penalty>\n";
     $expout .= "    <hidden>{$question->hidden}</hidden>\n";
     // The rest of the output depends on question type.
     switch ($question->qtype) {
         case 'category':
             // not a qtype really - dummy used for category switching
             break;
         case 'truefalse':
             $trueanswer = $question->options->answers[$question->options->trueanswer];
             $trueanswer->answer = 'true';
             $expout .= $this->write_answer($trueanswer);
             $falseanswer = $question->options->answers[$question->options->falseanswer];
             $falseanswer->answer = 'false';
             $expout .= $this->write_answer($falseanswer);
             break;
         case 'multichoice':
             $expout .= "    <single>" . $this->get_single($question->options->single) . "</single>\n";
             $expout .= "    <shuffleanswers>" . $this->get_single($question->options->shuffleanswers) . "</shuffleanswers>\n";
             $expout .= "    <answernumbering>" . $question->options->answernumbering . "</answernumbering>\n";
             $expout .= $this->write_combined_feedback($question->options, $question->id, $question->contextid);
             $expout .= $this->write_answers($question->options->answers);
             break;
         case 'shortanswer':
             $expout .= "    <usecase>{$question->options->usecase}</usecase>\n";
             $expout .= $this->write_answers($question->options->answers);
             break;
         case 'numerical':
             foreach ($question->options->answers as $answer) {
                 $expout .= $this->write_answer($answer, "      <tolerance>{$answer->tolerance}</tolerance>\n");
             }
             $units = $question->options->units;
             if (count($units)) {
                 $expout .= "<units>\n";
                 foreach ($units as $unit) {
                     $expout .= "  <unit>\n";
                     $expout .= "    <multiplier>{$unit->multiplier}</multiplier>\n";
                     $expout .= "    <unit_name>{$unit->unit}</unit_name>\n";
                     $expout .= "  </unit>\n";
                 }
                 $expout .= "</units>\n";
             }
             if (isset($question->options->unitgradingtype)) {
                 $expout .= "    <unitgradingtype>" . $question->options->unitgradingtype . "</unitgradingtype>\n";
             }
             if (isset($question->options->unitpenalty)) {
                 $expout .= "    <unitpenalty>{$question->options->unitpenalty}</unitpenalty>\n";
             }
             if (isset($question->options->showunits)) {
                 $expout .= "    <showunits>{$question->options->showunits}</showunits>\n";
             }
             if (isset($question->options->unitsleft)) {
                 $expout .= "    <unitsleft>{$question->options->unitsleft}</unitsleft>\n";
             }
             if (!empty($question->options->instructionsformat)) {
                 $files = $fs->get_area_files($contextid, 'qtype_numerical', 'instruction', $question->id);
                 $expout .= "    <instructions " . $this->format($question->options->instructionsformat) . ">\n";
                 $expout .= $this->writetext($question->options->instructions, 3);
                 $expout .= $this->write_files($files);
                 $expout .= "    </instructions>\n";
             }
             break;
         case 'match':
             $expout .= "    <shuffleanswers>" . $this->get_single($question->options->shuffleanswers) . "</shuffleanswers>\n";
             $expout .= $this->write_combined_feedback($question->options, $question->id, $question->contextid);
             foreach ($question->options->subquestions as $subquestion) {
                 $files = $fs->get_area_files($contextid, 'qtype_match', 'subquestion', $subquestion->id);
                 $expout .= "    <subquestion " . $this->format($subquestion->questiontextformat) . ">\n";
                 $expout .= $this->writetext($subquestion->questiontext, 3);
                 $expout .= $this->write_files($files);
                 $expout .= "      <answer>\n";
                 $expout .= $this->writetext($subquestion->answertext, 4);
                 $expout .= "      </answer>\n";
                 $expout .= "    </subquestion>\n";
             }
             break;
         case 'description':
             // Nothing else to do.
             break;
         case 'multianswer':
             foreach ($question->options->questions as $index => $subq) {
                 $expout = preg_replace('~{#' . $index . '}~', $subq->questiontext, $expout);
             }
             break;
         case 'essay':
             $expout .= "    <responseformat>" . $question->options->responseformat . "</responseformat>\n";
             $expout .= "    <responsefieldlines>" . $question->options->responsefieldlines . "</responsefieldlines>\n";
             $expout .= "    <attachments>" . $question->options->attachments . "</attachments>\n";
             $expout .= "    <graderinfo " . $this->format($question->options->graderinfoformat) . ">\n";
             $expout .= $this->writetext($question->options->graderinfo, 3);
             $expout .= $this->write_files($fs->get_area_files($contextid, 'qtype_essay', 'graderinfo', $question->id));
             $expout .= "    </graderinfo>\n";
             break;
         case 'calculated':
         case 'calculatedsimple':
         case 'calculatedmulti':
             $expout .= "    <synchronize>{$question->options->synchronize}</synchronize>\n";
             $expout .= "    <single>{$question->options->single}</single>\n";
             $expout .= "    <answernumbering>" . $question->options->answernumbering . "</answernumbering>\n";
             $expout .= "    <shuffleanswers>" . $question->options->shuffleanswers . "</shuffleanswers>\n";
             $component = 'qtype_' . $question->qtype;
             $files = $fs->get_area_files($contextid, $component, 'correctfeedback', $question->id);
             $expout .= "    <correctfeedback>\n";
             $expout .= $this->writetext($question->options->correctfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </correctfeedback>\n";
             $files = $fs->get_area_files($contextid, $component, 'partiallycorrectfeedback', $question->id);
             $expout .= "    <partiallycorrectfeedback>\n";
             $expout .= $this->writetext($question->options->partiallycorrectfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </partiallycorrectfeedback>\n";
             $files = $fs->get_area_files($contextid, $component, 'incorrectfeedback', $question->id);
             $expout .= "    <incorrectfeedback>\n";
             $expout .= $this->writetext($question->options->incorrectfeedback, 3);
             $expout .= $this->write_files($files);
             $expout .= "    </incorrectfeedback>\n";
             foreach ($question->options->answers as $answer) {
                 $percent = 100 * $answer->fraction;
                 $expout .= "<answer fraction=\"{$percent}\">\n";
                 // "<text/>" tags are an added feature, old files won't have them
                 $expout .= "    <text>{$answer->answer}</text>\n";
                 $expout .= "    <tolerance>{$answer->tolerance}</tolerance>\n";
                 $expout .= "    <tolerancetype>{$answer->tolerancetype}</tolerancetype>\n";
                 $expout .= "    <correctanswerformat>" . $answer->correctanswerformat . "</correctanswerformat>\n";
                 $expout .= "    <correctanswerlength>" . $answer->correctanswerlength . "</correctanswerlength>\n";
                 $expout .= "    <feedback {$this->format($answer->feedbackformat)}>\n";
                 $files = $fs->get_area_files($contextid, $component, 'instruction', $question->id);
                 $expout .= $this->writetext($answer->feedback);
                 $expout .= $this->write_files($answer->feedbackfiles);
                 $expout .= "    </feedback>\n";
                 $expout .= "</answer>\n";
             }
             if (isset($question->options->unitgradingtype)) {
                 $expout .= "    <unitgradingtype>" . $question->options->unitgradingtype . "</unitgradingtype>\n";
             }
             if (isset($question->options->unitpenalty)) {
                 $expout .= "    <unitpenalty>" . $question->options->unitpenalty . "</unitpenalty>\n";
             }
             if (isset($question->options->showunits)) {
                 $expout .= "    <showunits>{$question->options->showunits}</showunits>\n";
             }
             if (isset($question->options->unitsleft)) {
                 $expout .= "    <unitsleft>{$question->options->unitsleft}</unitsleft>\n";
             }
             if (isset($question->options->instructionsformat)) {
                 $files = $fs->get_area_files($contextid, $component, 'instruction', $question->id);
                 $expout .= "    <instructions " . $this->format($question->options->instructionsformat) . ">\n";
                 $expout .= $this->writetext($question->options->instructions, 3);
                 $expout .= $this->write_files($files);
                 $expout .= "    </instructions>\n";
             }
             if (isset($question->options->units)) {
                 $units = $question->options->units;
                 if (count($units)) {
                     $expout .= "<units>\n";
                     foreach ($units as $unit) {
                         $expout .= "  <unit>\n";
                         $expout .= "    <multiplier>{$unit->multiplier}</multiplier>\n";
                         $expout .= "    <unit_name>{$unit->unit}</unit_name>\n";
                         $expout .= "  </unit>\n";
                     }
                     $expout .= "</units>\n";
                 }
             }
             // The tag $question->export_process has been set so we get all the
             // data items in the database from the function
             // qtype_calculated::get_question_options calculatedsimple defaults
             // to calculated
             if (isset($question->options->datasets) && count($question->options->datasets)) {
                 $expout .= "<dataset_definitions>\n";
                 foreach ($question->options->datasets as $def) {
                     $expout .= "<dataset_definition>\n";
                     $expout .= "    <status>" . $this->writetext($def->status) . "</status>\n";
                     $expout .= "    <name>" . $this->writetext($def->name) . "</name>\n";
                     if ($question->qtype == CALCULATED) {
                         $expout .= "    <type>calculated</type>\n";
                     } else {
                         $expout .= "    <type>calculatedsimple</type>\n";
                     }
                     $expout .= "    <distribution>" . $this->writetext($def->distribution) . "</distribution>\n";
                     $expout .= "    <minimum>" . $this->writetext($def->minimum) . "</minimum>\n";
                     $expout .= "    <maximum>" . $this->writetext($def->maximum) . "</maximum>\n";
                     $expout .= "    <decimals>" . $this->writetext($def->decimals) . "</decimals>\n";
                     $expout .= "    <itemcount>{$def->itemcount}</itemcount>\n";
                     if ($def->itemcount > 0) {
                         $expout .= "    <dataset_items>\n";
                         foreach ($def->items as $item) {
                             $expout .= "        <dataset_item>\n";
                             $expout .= "           <number>" . $item->itemnumber . "</number>\n";
                             $expout .= "           <value>" . $item->value . "</value>\n";
                             $expout .= "        </dataset_item>\n";
                         }
                         $expout .= "    </dataset_items>\n";
                         $expout .= "    <number_of_items>" . $def->number_of_items . "</number_of_items>\n";
                     }
                     $expout .= "</dataset_definition>\n";
                 }
                 $expout .= "</dataset_definitions>\n";
             }
             break;
         default:
             // try support by optional plugin
             if (!($data = $this->try_exporting_using_qtypes($question->qtype, $question))) {
                 notify(get_string('unsupportedexport', 'qformat_xml', $question->qtype));
             }
             $expout .= $data;
     }
     // Output any hints.
     $expout .= $this->write_hints($question);
     // Write the question tags.
     if (!empty($CFG->usetags)) {
         require_once $CFG->dirroot . '/tag/lib.php';
         $tags = tag_get_tags_array('question', $question->id);
         if (!empty($tags)) {
             $expout .= "    <tags>\n";
             foreach ($tags as $tag) {
                 $expout .= "      <tag>" . $this->writetext($tag, 0, true) . "</tag>\n";
             }
             $expout .= "    </tags>\n";
         }
     }
     // close the question tag
     $expout .= "  </question>\n";
     return $expout;
 }
Example #21
0
} else {
    if ($tag_id) {
        $tag = tag_get('id', $tag_id, '*');
    }
}
if (empty($tag)) {
    redirect($CFG->wwwroot . '/tag/search.php');
}
$PAGE->set_url('/tag/index.php', array('id' => $tag->id));
$PAGE->set_subpage($tag->id);
$PAGE->set_context($systemcontext);
$PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
$PAGE->set_pagelayout('standard');
$tagname = tag_display_name($tag);
// set the relatedtags field of the $tag object that will be passed to the form
$tag->relatedtags = tag_get_tags_array('tag', $tag->id);
$options = new stdClass();
$options->smiley = false;
$options->filter = false;
// convert and remove any XSS
$tag->description = format_text($tag->description, $tag->descriptionformat, $options);
$tag->descriptionformat = FORMAT_HTML;
$errorstring = '';
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => false, 'context' => $systemcontext, 'subdirs' => file_area_contains_subdirs($systemcontext, 'tag', 'description', $tag->id));
$tag = file_prepare_standard_editor($tag, 'description', $editoroptions, $systemcontext, 'tag', 'description', $tag->id);
$tagform = new tag_edit_form(null, compact('editoroptions'));
if ($tag->tagtype == 'official') {
    $tag->tagtype = '1';
} else {
    $tag->tagtype = '0';
}
Example #22
0
function wiki_reset_userdata($data)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/mod/wiki/pagelib.php';
    require_once $CFG->dirroot . '/tag/lib.php';
    $componentstr = get_string('modulenameplural', 'wiki');
    $status = array();
    //get the wiki(s) in this course.
    if (!($wikis = $DB->get_records('wiki', array('course' => $data->courseid)))) {
        return false;
    }
    $errors = false;
    foreach ($wikis as $wiki) {
        // remove all comments
        if (!empty($data->reset_wiki_comments)) {
            if (!($cm = get_coursemodule_from_instance('wiki', $wiki->id))) {
                continue;
            }
            $context = context_module::instance($cm->id);
            $DB->delete_records_select('comments', "contextid = ? AND commentarea='wiki_page'", array($context->id));
            $status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
        }
        if (!empty($data->reset_wiki_tags)) {
            # Get subwiki information #
            $subwikis = $DB->get_records('wiki_subwikis', array('wikiid' => $wiki->id));
            foreach ($subwikis as $subwiki) {
                if ($pages = $DB->get_records('wiki_pages', array('subwikiid' => $subwiki->id))) {
                    foreach ($pages as $page) {
                        $tags = tag_get_tags_array('wiki_pages', $page->id);
                        foreach ($tags as $tagid => $tagname) {
                            // Delete the related tag_instances related to the wiki page.
                            $errors = tag_delete_instance('wiki_pages', $page->id, $tagid);
                            $status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'), 'error' => $errors);
                        }
                    }
                }
            }
        }
    }
    return $status;
}
Example #23
0
        break;
    case 'edit':
        if (!$existing) {
            error('Incorrect blog post id');
        }
        $post->id = $existing->id;
        $post->subject = $existing->subject;
        $post->summary = $existing->summary;
        $post->publishstate = $existing->publishstate;
        $post->format = $existing->format;
        $post->action = $action;
        $strformheading = get_string('updateentrywithid', 'blog');
        if ($itemptags = tag_get_tags_csv('post', $post->id, TAG_RETURN_TEXT, 'default')) {
            $post->ptags = $itemptags;
        }
        if ($itemotags = tag_get_tags_array('post', $post->id, 'official')) {
            $post->otags = array_keys($itemotags);
        }
        break;
    default:
        error('Unknown action!');
}
// done here in order to allow deleting of posts with wrong user id above
if (!($user = get_record('user', 'id', $userid))) {
    error('Incorrect user id');
}
$navlinks = array();
$navlinks[] = array('name' => fullname($user), 'link' => "{$CFG->wwwroot}/user/view.php?id={$userid}", 'type' => 'misc');
$navlinks[] = array('name' => $strblogs, 'link' => "{$CFG->wwwroot}/blog/index.php?userid={$userid}", 'type' => 'misc');
$navlinks[] = array('name' => $strformheading, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
Example #24
0
        $strformheading = get_string('addnewentry', 'blog');
        $entry->action = $action;
        if ($CFG->useblogassociations) {
            //pre-select the course for associations
            if ($courseid) {
                $context = context_course::instance($courseid);
                $entry->courseassoc = $context->id;
            }
            //pre-select the mod for associations
            if ($modid) {
                $context = context_module::instance($modid);
                $entry->modassoc = $context->id;
            }
        }
        break;
    case 'edit':
        if (empty($entry->id)) {
            print_error('wrongentryid', 'blog');
        }
        $entry->tags = tag_get_tags_array('post', $entry->id);
        $strformheading = get_string('updateentrywithid', 'blog');
        break;
    default:
        print_error('unknowaction');
}
$entry->modid = $modid;
$entry->courseid = $courseid;
echo $OUTPUT->header();
$blogeditform->display();
echo $OUTPUT->footer();
die;
Example #25
0
/**
 * Private function to factor common code out of get_question_options().
 *
 * @param object $question the question to tidy.
 * @param boolean $loadtags load the question tags from the tags table. Optional, default false.
 */
function _tidy_question($question, $loadtags = false)
{
    global $CFG;
    if (!question_bank::is_qtype_installed($question->qtype)) {
        $question->questiontext = html_writer::tag('p', get_string('warningmissingtype', 'qtype_missingtype')) . $question->questiontext;
    }
    question_bank::get_qtype($question->qtype)->get_question_options($question);
    if (isset($question->_partiallyloaded)) {
        unset($question->_partiallyloaded);
    }
    if ($loadtags && !empty($CFG->usetags)) {
        require_once $CFG->dirroot . '/tag/lib.php';
        $question->tags = tag_get_tags_array('question', $question->id);
    }
}
Example #26
0
function wiki_print_page_content($page, $context, $subwikiid)
{
    global $OUTPUT, $CFG;
    if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
        $content = wiki_refresh_cachedcontent($page);
        $page = $content['page'];
    }
    if (isset($content)) {
        $box = '';
        foreach ($content['sections'] as $s) {
            $box .= '<p>' . get_string('repeatedsection', 'wiki', $s) . '</p>';
        }
        if (!empty($box)) {
            echo $OUTPUT->box($box);
        }
    }
    $html = file_rewrite_pluginfile_urls($page->cachedcontent, 'pluginfile.php', $context->id, 'mod_wiki', 'attachments', $subwikiid);
    $html = format_text($html, FORMAT_MOODLE, array('overflowdiv' => true));
    echo $OUTPUT->box($html);
    if (!empty($CFG->usetags)) {
        $tags = tag_get_tags_array('wiki_pages', $page->id);
        echo $OUTPUT->container_start('wiki-tags');
        echo '<span class="wiki-tags-title">' . get_string('tags') . ': </span>';
        $links = array();
        foreach ($tags as $tagid => $tag) {
            $url = new moodle_url('/tag/index.php', array('tag' => $tag));
            $links[] = html_writer::link($url, $tag, array('title' => get_string('tagtitle', 'wiki', $tag)));
        }
        echo join($links, ", ");
        echo $OUTPUT->container_end();
    }
    wiki_increment_pageviews($page);
}
Example #27
0
/**
 * Given a record in the {blog_external} table, checks the blog's URL
 * for new entries not yet copied into Moodle.
 *
 * @param object $externalblog
 * @return boolean False if the Feed is invalid
 */
function blog_sync_external_entries($externalblog)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/simplepie/moodle_simplepie.php';
    $rssfile = new moodle_simplepie_file($externalblog->url);
    $filetest = new SimplePie_Locator($rssfile);
    if (!$filetest->is_feed($rssfile)) {
        $externalblog->failedlastsync = 1;
        $DB->update_record('blog_external', $externalblog);
        return false;
    } else {
        if (!empty($externalblog->failedlastsync)) {
            $externalblog->failedlastsync = 0;
            $DB->update_record('blog_external', $externalblog);
        }
    }
    // Delete all blog entries associated with this external blog
    blog_delete_external_entries($externalblog);
    $rss = new moodle_simplepie($externalblog->url);
    if (empty($rss->data)) {
        return null;
    }
    foreach ($rss->get_items() as $entry) {
        // If filtertags are defined, use them to filter the entries by RSS category
        if (!empty($externalblog->filtertags)) {
            $containsfiltertag = false;
            $categories = $entry->get_categories();
            $filtertags = explode(',', $externalblog->filtertags);
            $filtertags = array_map('trim', $filtertags);
            $filtertags = array_map('strtolower', $filtertags);
            foreach ($categories as $category) {
                if (in_array(trim(strtolower($category->term)), $filtertags)) {
                    $containsfiltertag = true;
                }
            }
            if (!$containsfiltertag) {
                continue;
            }
        }
        $newentry = new stdClass();
        $newentry->userid = $externalblog->userid;
        $newentry->module = 'blog_external';
        $newentry->content = $externalblog->id;
        $newentry->uniquehash = $entry->get_permalink();
        $newentry->publishstate = 'site';
        $newentry->format = FORMAT_HTML;
        $newentry->subject = $entry->get_title();
        $newentry->summary = $entry->get_description();
        //our DB doesnt allow null creation or modified timestamps so check the external blog didnt supply one
        $entrydate = $entry->get_date('U');
        if (empty($entrydate)) {
            $newentry->created = time();
            $newentry->lastmodified = time();
        } else {
            $newentry->created = $entrydate;
            $newentry->lastmodified = $entrydate;
        }
        $textlib = textlib_get_instance();
        if ($textlib->strlen($newentry->uniquehash) > 255) {
            // The URL for this item is too long for the field. Rather than add
            // the entry without the link we will skip straight over it.
            // RSS spec says recommended length 500, we use 255.
            debugging('External blog entry skipped because of oversized URL', DEBUG_DEVELOPER);
            continue;
        }
        $id = $DB->insert_record('post', $newentry);
        // Set tags
        if ($tags = tag_get_tags_array('blog_external', $externalblog->id)) {
            tag_set('post', $id, $tags);
        }
    }
    $DB->update_record('blog_external', array('id' => $externalblog->id, 'timefetched' => mktime()));
}