Example #1
0
 /**
  * The HTML version of the e-mail message.
  *
  * @param \stdClass $cm
  * @param \stdClass $post
  * @return string
  */
 public function format_message_text($cm, $post)
 {
     $message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', \context_module::instance($cm->id)->id, 'mod_forum', 'post', $post->id);
     $options = new \stdClass();
     $options->para = true;
     return format_text($message, $post->messageformat, $options);
 }
Example #2
0
 /**
  * Test ampersands.
  */
 public function test_ampersands()
 {
     global $CFG;
     $this->resetAfterTest(true);
     // Enable glossary filter at top level.
     filter_set_global_state('glossary', TEXTFILTER_ON);
     $CFG->glossary_linkentries = 1;
     // Create a test course.
     $course = $this->getDataGenerator()->create_course();
     $context = context_course::instance($course->id);
     // Create a glossary.
     $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course->id, 'mainglossary' => 1));
     // Create two entries with ampersands and one normal entry.
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
     $normal = $generator->create_content($glossary, array('concept' => 'normal'));
     $amp1 = $generator->create_content($glossary, array('concept' => 'A&B'));
     $amp2 = $generator->create_content($glossary, array('concept' => 'C&D'));
     // Format text with all three entries in HTML.
     $html = '<p>A&amp;B C&amp;D normal</p>';
     $filtered = format_text($html, FORMAT_HTML, array('context' => $context));
     // Find all the glossary links in the result.
     $matches = array();
     preg_match_all('~courseid=' . $course->id . '&amp;eid=([0-9]+).*?title="(.*?)"~', $filtered, $matches);
     // There should be 3 glossary links.
     $this->assertEquals(3, count($matches[1]));
     $this->assertEquals($amp1->id, $matches[1][0]);
     $this->assertEquals($amp2->id, $matches[1][1]);
     $this->assertEquals($normal->id, $matches[1][2]);
     // Check text and escaping of title attribute.
     $this->assertEquals($glossary->name . ': A&amp;B', $matches[2][0]);
     $this->assertEquals($glossary->name . ': C&amp;D', $matches[2][1]);
     $this->assertEquals($glossary->name . ': normal', $matches[2][2]);
 }
Example #3
0
 /**
  * Return comments by pages
  * @param int $page
  * @return mixed
  */
 function get_comments($page)
 {
     global $DB, $CFG, $USER;
     $params = array();
     if ($page == 0) {
         $start = 0;
     } else {
         $start = $page * $this->perpage;
     }
     $sql = "SELECT c.id, c.contextid, c.itemid, c.commentarea, c.userid, c.content, u.firstname, u.lastname, c.timecreated\n            FROM {comments} c, {user} u\n            WHERE u.id=c.userid ORDER BY c.timecreated ASC";
     $comments = array();
     $formatoptions = array('overflowdiv' => true);
     if ($records = $DB->get_records_sql($sql, array(), $start, $this->perpage)) {
         foreach ($records as $item) {
             $item->fullname = fullname($item);
             $item->time = userdate($item->timecreated);
             $item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions);
             $comments[] = $item;
             unset($item->firstname);
             unset($item->lastname);
             unset($item->timecreated);
         }
     }
     return $comments;
 }
 /**
  * If exists, this method can process local alternative values for
  * realizing the template, after all standard translations have been performed. 
  * Type information structure and application context dependant.
  */
 public function postprocess_data($course = null)
 {
     global $CFG, $COURSE, $DB;
     if (is_null($course)) {
         $course =& $COURSE;
     }
     // Get virtual fields from course title.
     $this->data->courseheading = format_string($course->fullname);
     $this->data->coursedesc = format_text($course->summary, $course->summaryformat);
     $this->data->idnumber = $course->idnumber;
     $this->data->shortname = $course->shortname;
     $storedimage = $this->get_file_url('image');
     $imageurl = !empty($storedimage) ? $storedimage : $this->fields['image']->default;
     if ($this->data->imagepositionoption == 'left') {
         $this->data->imageL = "<td width=\"100\" class=\"custombox-icon-left courseheading\" align=\"center\" style=\"background:url({$imageurl}) 50% 50% no-repeat transparent\">{$this->data->overimagetext}</td>";
         $this->data->imageR = '';
     } elseif ($this->data->imagepositionoption == 'right') {
         $this->data->imageL = '';
         $this->data->imageR = "<td width=\"100\" class=\"custombox-icon-right courseheading\" align=\"center\" style=\"background:url({$imageurl}) 50% 50% no-repeat transparent\">{$this->data->overimagetext}</td>";
     } else {
         $this->data->imageL = '';
         $this->data->imageR = '';
     }
     $cat = $DB->get_record('course_categories', array('id' => $course->category));
     $this->data->category = $cat->name;
 }
function block_exabis_eportfolio_print_extcomments($itemid)
{
    $stredit = get_string('edit');
    $strdelete = get_string('delete');
    $comments = get_records("block_exabeporitemcomm", "itemid", $itemid, 'timemodified DESC');
    if (!$comments) {
        return;
    }
    foreach ($comments as $comment) {
        $user = get_record('user', 'id', $comment->userid);
        echo '<table cellspacing="0" class="forumpost blogpost blog" width="100%">';
        echo '<tr class="header"><td class="picture left">';
        print_user_picture($comment->userid, SITEID, $user->picture);
        echo '</td>';
        echo '<td class="topic starter"><div class="author">';
        $fullname = fullname($user, $comment->userid);
        $by = new object();
        $by->name = $fullname;
        $by->date = userdate($comment->timemodified);
        print_string('bynameondate', 'forum', $by);
        echo '</div></td></tr>';
        echo '<tr><td class="left side">';
        echo '</td><td class="content">' . "\n";
        echo format_text($comment->entry);
        echo '</td></tr></table>' . "\n\n";
    }
}
 function get_content()
 {
     if ($this->content !== NULL) {
         return $this->content;
     }
     $search_string = $this->config->search_string;
     $search_string_enc = urlencode($search_string);
     $no_tweets = $this->config->no_tweets;
     $url = "http://search.twitter.com/search.atom?q={$search_string_enc}&rpp={$no_tweets}";
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $xml = curl_exec($ch);
     curl_close($ch);
     $dom = DOMDocument::loadXML($xml);
     $tweets = $dom->getElementsByTagName('entry');
     $output = "<ul class='list'>";
     foreach ($tweets as $tweet) {
         $output .= "<li style='border-top:1px dotted #aaa;padding:4px'>";
         $author = $tweet->getElementsByTagName('author')->item(0);
         $authorname = $author->getElementsByTagName('name')->item(0)->textContent;
         $authorlink = $author->getElementsByTagName('uri')->item(0)->textContent;
         $output .= "<a href='{$authorlink}'>{$authorname}</a>: ";
         $output .= format_text($tweet->getElementsByTagName('content')->item(0)->textContent, FORMAT_HTML);
         $output .= "</li>";
     }
     $output .= "</ul>";
     $this->title = $search_string . get_string('ontwitter', 'block_twitter_search');
     $this->content = new stdClass();
     $this->content->text = $output;
     $this->content->footer = '';
     return $this->content;
 }
 /**
  * Render a single contact.
  *
  * @param \stdClass $contact
  *
  * @return string
  */
 public function contact(stdClass $contact)
 {
     $url = new moodle_url('/user/profile.php', array('id' => $contact->id));
     $userpic = $this->output->user_picture($contact, array('size' => '100', 'class' => 'profilepicture'));
     $description = format_text($contact->description, $contact->descriptionformat);
     return html_writer::start_tag('li', array('class' => 'contact')) . html_writer::start_tag('div', array('class' => 'contactpic')) . $userpic . html_writer::end_tag('div') . html_writer::start_tag('a', array('href' => $url)) . fullname($contact) . html_writer::end_tag('a') . html_writer::start_tag('div', array('class' => 'contactdetails')) . $description . html_writer::end_tag('div') . html_writer::end_tag('li');
 }
 /**
  * Generates the message object for a give subscription and event.
  *
  * @param int $subscriptionid Subscription instance
  * @param \stdClass $eventobj Event data
  *
  * @return false|\stdClass message object
  */
 protected function generate_message($subscriptionid, \stdClass $eventobj)
 {
     try {
         $subscription = subscription_manager::get_subscription($subscriptionid);
     } catch (\dml_exception $e) {
         // Race condition, someone deleted the subscription.
         return false;
     }
     $user = \core_user::get_user($subscription->userid);
     $context = \context_user::instance($user->id, IGNORE_MISSING);
     if ($context === false) {
         // User context doesn't exist. Should never happen, nothing to do return.
         return false;
     }
     $template = $subscription->template;
     $template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
     $msgdata = new \stdClass();
     $msgdata->component = 'tool_monitor';
     // Your component name.
     $msgdata->name = 'notification';
     // This is the message name from messages.php.
     $msgdata->userfrom = \core_user::get_noreply_user();
     $msgdata->userto = $user;
     $msgdata->subject = $subscription->get_name($context);
     $msgdata->fullmessage = format_text($template, $subscription->templateformat, array('context' => $context));
     $msgdata->fullmessageformat = $subscription->templateformat;
     $msgdata->fullmessagehtml = format_text($template, $subscription->templateformat, array('context' => $context));
     $msgdata->smallmessage = '';
     $msgdata->notification = 1;
     // This is only set to 0 for personal messages between users.
     return $msgdata;
 }
Example #9
0
 public function display_reported_images(Page $page, $reports)
 {
     global $config;
     $h_reportedimages = "";
     $n = 0;
     foreach ($reports as $report) {
         $image = $report['image'];
         $h_reason = format_text($report['reason']);
         if ($config->get_bool('report_image_show_thumbs')) {
             $image_link = $this->build_thumb_html($image);
         } else {
             $image_link = "<a href=\"" . make_link("post/view/{$image->id}") . "\">{$image->id}</a>";
         }
         $reporter_name = html_escape($report['reporter_name']);
         $userlink = "<a href='" . make_link("user/{$reporter_name}") . "'>{$reporter_name}</a>";
         global $user;
         $iabbe = new ImageAdminBlockBuildingEvent($image, $user);
         send_event($iabbe);
         ksort($iabbe->parts);
         $actions = join("<br>", $iabbe->parts);
         $oe = $n++ % 2 == 0 ? "even" : "odd";
         $h_reportedimages .= "\n\t\t\t\t<tr class='{$oe}'>\n\t\t\t\t\t<td>{$image_link}</td>\n\t\t\t\t\t<td>Report by {$userlink}: {$h_reason}</td>\n\t\t\t\t\t<td class='formstretch'>\n\t\t\t\t\t\t<form action='" . make_link("image_report/remove") . "' method='POST'>\n\t\t\t\t\t\t\t<input type='hidden' name='id' value='{$report['id']}'>\n\t\t\t\t\t\t\t<input type='submit' value='Remove Report'>\n\t\t\t\t\t\t</form>\n\n\t\t\t\t\t\t<br>{$actions}\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t";
     }
     $thumb_width = $config->get_int("thumb_width");
     $html = "\n\t\t\t<table id='reportedimage' class='zebra'>\n\t\t\t\t<thead><td width='{$thumb_width}'>Image</td><td>Reason</td><td width='128'>Action</td></thead>\n\t\t\t\t{$h_reportedimages}\n\t\t\t</table>\n\t\t";
     $page->set_title("Reported Images");
     $page->set_heading("Reported Images");
     $page->add_block(new NavBlock());
     $page->add_block(new Block("Reported Images", $html));
 }
Example #10
0
 function get_content()
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     $filteropt = new stdClass();
     $filteropt->overflowdiv = true;
     if ($this->content_is_trusted()) {
         // fancy html allowed only on course, category and system blocks.
         $filteropt->noclean = true;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     if (isset($this->config->text)) {
         // rewrite url
         $this->config->text = file_rewrite_pluginfile_urls($this->config->text, 'pluginfile.php', $this->context->id, 'block_html', 'content', NULL);
         // Default to FORMAT_HTML which is what will have been used before the
         // editor was properly implemented for the block.
         $format = FORMAT_HTML;
         // Check to see if the format has been properly set on the config
         if (isset($this->config->format)) {
             $format = $this->config->format;
         }
         $this->content->text = format_text($this->config->text, $format, $filteropt);
     } else {
         $this->content->text = '';
     }
     unset($filteropt);
     // memory footprint
     return $this->content;
 }
    function definition() {
        $mform =& $this->_form;
        $contextid = $this->_customdata['contextid'];

        $export = $mform->addElement('hidden', 'export', ''); // Will be overwritten below

        $table = new html_table();
        /* Styling done using HTML table and CSS */
        $table->attributes['class'] = 'export_form_table';
        $table->align = array('left', 'left', 'left', 'center');
        $table->wrap = array('nowrap', '', 'nowrap', 'nowrap');
        $table->data = array();

        $table->head = array(get_string('name'),
                            get_string('description'),
                            get_string('shortname'),
                            get_string('export', 'report_rolesmigration'));

        $roles = get_all_roles();
        foreach ($roles as $role) {
            $row = array();
            $roleurl = new moodle_url('/admin/roles/define.php', array('roleid' => $role->id, 'action' => 'view'));
            $row[0] = '<a href="'.$roleurl.'">'.format_string($role->name).'</a>';
            $row[1] = format_text($role->description, FORMAT_HTML);
            $row[2] = ($role->shortname);
            /* Export values are added from role checkboxes */
            $row[3] = '<input type="checkbox" name="export[]" value="'.$role->shortname.'" />';

            $table->data[] = $row;
        }

        $mform->addElement('html', html_writer::table($table));
        $mform->addElement('hidden', 'contextid', $contextid);
        $this->add_action_buttons(false, get_string('submitexport', 'report_rolesmigration'));
    }
 function get_content()
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     $filteropt = new stdClass();
     $filteropt->overflowdiv = true;
     if ($this->content_is_trusted()) {
         // fancy html allowed only on course, category and system blocks.
         $filteropt->noclean = true;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     if (isset($this->config->text)) {
         // rewrite url
         $this->config->text = file_rewrite_pluginfile_urls($this->config->text, 'pluginfile.php', $this->context->id, 'block_html', 'content', NULL);
         $this->content->text = format_text($this->config->text, $this->config->format, $filteropt);
     } else {
         $this->content->text = '';
     }
     unset($filteropt);
     // memory footprint
     return $this->content;
 }
 function get_content()
 {
     global $CFG;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($this->instance)) {
         return '';
     }
     $this->content = new object();
     $options = new object();
     $options->noclean = true;
     // Don't clean Javascripts etc
     $this->content->text = format_text($this->page->course->summary, FORMAT_HTML, $options);
     if ($this->page->user_is_editing()) {
         if ($this->page->course->id == SITEID) {
             $editpage = $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=frontpagesettings';
         } else {
             $editpage = $CFG->wwwroot . '/course/edit.php?id=' . $this->page->course->id;
         }
         $this->content->text .= "<div class=\"editbutton\"><a href=\"{$editpage}\"><img src=\"{$CFG->pixpath}/t/edit.gif\" alt=\"" . get_string('edit') . "\" /></a></div>";
     }
     $this->content->footer = '';
     return $this->content;
 }
Example #14
0
 /**
  * Define the elements to be displayed at the form
  *
  * Called by the parent::definition()
  *
  * @return void
  */
 protected function definition_inner(&$mform)
 {
     $fields = $this->_customdata['fields'];
     $current = $this->_customdata['current'];
     $nodims = $this->_customdata['nodims'];
     // number of assessment dimensions
     $mform->addElement('hidden', 'nodims', $nodims);
     $mform->setType('nodims', PARAM_INT);
     for ($i = 0; $i < $nodims; $i++) {
         // dimension header
         $dimtitle = get_string('dimensionnumber', 'workshopform_comments', $i + 1);
         $mform->addElement('header', 'dimensionhdr__idx_' . $i, $dimtitle);
         // dimension id
         $mform->addElement('hidden', 'dimensionid__idx_' . $i, $fields->{'dimensionid__idx_' . $i});
         $mform->setType('dimensionid__idx_' . $i, PARAM_INT);
         // grade id
         $mform->addElement('hidden', 'gradeid__idx_' . $i);
         // value set by set_data() later
         $mform->setType('gradeid__idx_' . $i, PARAM_INT);
         // dimension description
         $desc = '<div id="id_dim_' . $fields->{'dimensionid__idx_' . $i} . '_desc" class="fitem description comments">' . "\n";
         $desc .= format_text($fields->{'description__idx_' . $i}, $fields->{'description__idx_' . $i . 'format'});
         $desc .= "\n</div>";
         $mform->addElement('html', $desc);
         // comment
         $label = get_string('dimensioncomment', 'workshopform_comments');
         //$mform->addElement('editor', 'peercomment__idx_' . $i, $label, null, array('maxfiles' => 0));
         $mform->addElement('textarea', 'peercomment__idx_' . $i, $label, array('cols' => 60, 'rows' => 10));
         $mform->addRule('peercomment__idx_' . $i, null, 'required', null, 'client');
     }
     $this->set_data($current);
 }
 function get_content()
 {
     global $CFG, $OUTPUT;
     require_once $CFG->libdir . '/filelib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($this->instance)) {
         return '';
     }
     $this->content = new stdClass();
     $options = new stdClass();
     $options->noclean = true;
     // Don't clean Javascripts etc
     $options->overflowdiv = true;
     $context = context_course::instance($this->page->course->id);
     $this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL);
     $this->content->text = format_text($this->page->course->summary, $this->page->course->summaryformat, $options);
     if ($this->page->user_is_editing()) {
         if ($this->page->course->id == SITEID) {
             $editpage = $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=frontpagesettings';
         } else {
             $editpage = $CFG->wwwroot . '/course/edit.php?id=' . $this->page->course->id;
         }
         $this->content->text .= "<div class=\"editbutton\"><a href=\"{$editpage}\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" alt=\"" . get_string('edit') . "\" /></a></div>";
     }
     $this->content->footer = '';
     return $this->content;
 }
Example #16
0
 private function get_body()
 {
     // returns just the contents of the body
     global $config;
     $base_href = get_base_href();
     $sitename = $config->get_string('title');
     $contact_link = $config->get_string('contact_link');
     $counter_dir = $config->get_string('home_counter', 'default');
     $total = Image::count_images();
     $strtotal = "{$total}";
     $num_comma = number_format($total);
     $counter_text = "";
     $length = strlen($strtotal);
     for ($n = 0; $n < $length; $n++) {
         $cur = $strtotal[$n];
         $counter_text .= " <img alt='{$cur}' src='{$base_href}/ext/home/counters/{$counter_dir}/{$cur}.gif' />  ";
     }
     // get the homelinks and process them
     if (strlen($config->get_string('home_links', '')) > 0) {
         $main_links = $config->get_string('home_links');
     } else {
         $main_links = '[url=site://post/list]Posts[/url] [url=site://comment/list]Comments[/url] [url=site://tags]Tags[/url]';
         if (class_exists("Pools")) {
             $main_links .= ' [url=site://pool]Pools[/url]';
         }
         if (class_exists("Wiki")) {
             $main_links .= ' [url=site://wiki]Wiki[/url]';
         }
         $main_links .= ' [url=site://ext_doc]Documentation[/url]';
     }
     $main_links = format_text($main_links);
     $main_text = $config->get_string('home_text');
     return $this->theme->build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text);
 }
Example #17
0
 /**
  * Add appropriate form elements to the criteria form
  *
  * @param stdClass $data details of overall criterion
  */
 public function config_form_criteria($data)
 {
     global $OUTPUT;
     $prefix = 'criteria-' . $this->id;
     if (count($data->criteria) > 2) {
         echo $OUTPUT->box_start();
         if (!empty($this->description)) {
             $badge = new badge($this->badgeid);
             echo $OUTPUT->box(format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())), 'criteria-description');
         }
         echo $OUTPUT->heading($this->get_title(), 2);
         $agg = $data->get_aggregation_methods();
         if (!$data->is_locked() && !$data->is_active()) {
             $editurl = new moodle_url('/badges/criteria_settings.php', array('badgeid' => $this->badgeid, 'edit' => true, 'type' => $this->criteriatype, 'crit' => $this->id));
             $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')), null, array('class' => 'criteria-action'));
             echo $OUTPUT->box($editaction, array('criteria-header'));
             $url = new moodle_url('criteria.php', array('id' => $data->id, 'sesskey' => sesskey()));
             echo $OUTPUT->single_select($url, 'update', $agg, $data->get_aggregation_method($this->criteriatype), null, null, array('aria-describedby' => 'overall'));
             echo html_writer::span(get_string('overallcrit', 'badges'), '', array('id' => 'overall'));
         } else {
             echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges', core_text::strtoupper($agg[$data->get_aggregation_method()])), 'clearfix');
         }
         echo $OUTPUT->box_end();
     }
 }
function getListOfTopics($course, $current)
{
    $section = 0;
    while ($section <= $course->numsections) {
        if (!($thissection = get_record('course_sections', 'course', $course->id, 'section', $section))) {
            notify('Error getting course_sections!');
        }
        $desc = format_text($thissection->summary, FORMAT_MOODLE, null, $course->id);
        $textByLines = explode("<br />", $desc);
        //we use <br /> to explode because the wysiwig editor add this element for line return
        $descTxt = strip_tags($textByLines[0]);
        $minidesc = substr($descTxt, 0, 20);
        if ($thissection->summary != null && strlen($descTxt) > 20) {
            $minidesc .= "...";
        } else {
            if ($thissection->summary == null) {
                $minidesc = "Topic";
            }
        }
        if ($current == $section) {
            echo '<OPTION selected value=' . $section . '>' . $section . ". " . $minidesc . '</OPTION>';
        } else {
            echo '<OPTION value=' . $section . '>' . $section . ". " . $minidesc . '</OPTION>';
        }
        $section++;
    }
}
Example #19
0
 /**
  * Format the text
  */
 public function format($value)
 {
     if (is_null($value)) {
         return $this->isnull;
     }
     return format_text($value, $this->format, $this->options);
 }
Example #20
0
 public static function get_setting($setting, $format = false, $theme = null)
 {
     if (empty($theme)) {
         if (empty(self::$theme)) {
             self::$theme = \theme_config::load('essential');
         }
         $theme = self::$theme;
     }
     global $CFG;
     require_once $CFG->dirroot . '/lib/weblib.php';
     if (empty($theme->settings->{$setting})) {
         return false;
     } else {
         if (!$format) {
             return $theme->settings->{$setting};
         } else {
             if ($format === 'format_text') {
                 return format_text($theme->settings->{$setting}, FORMAT_PLAIN);
             } else {
                 if ($format === 'format_html') {
                     return format_text($theme->settings->{$setting}, FORMAT_HTML, array('trusted' => true, 'noclean' => true));
                 } else {
                     return format_string($theme->settings->{$setting});
                 }
             }
         }
     }
 }
Example #21
0
 public function test_get_public_config()
 {
     global $CFG, $SITE, $OUTPUT;
     $this->resetAfterTest(true);
     $result = external::get_public_config();
     $result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
     // Test default values.
     $context = context_system::instance();
     $expected = array('wwwroot' => $CFG->wwwroot, 'httpswwwroot' => $CFG->httpswwwroot, 'sitename' => external_format_string($SITE->fullname, $context->id, true), 'guestlogin' => $CFG->guestloginbutton, 'rememberusername' => $CFG->rememberusername, 'authloginviaemail' => $CFG->authloginviaemail, 'registerauth' => $CFG->registerauth, 'forgottenpasswordurl' => $CFG->forgottenpasswordurl, 'authinstructions' => format_text($CFG->auth_instructions), 'authnoneenabled' => (int) is_enabled_auth('none'), 'enablewebservices' => $CFG->enablewebservices, 'enablemobilewebservice' => $CFG->enablemobilewebservice, 'maintenanceenabled' => $CFG->maintenance_enabled, 'maintenancemessage' => format_text($CFG->maintenance_message), 'typeoflogin' => api::LOGIN_VIA_APP, 'warnings' => array());
     $this->assertEquals($expected, $result);
     // Change some values.
     set_config('registerauth', 'email');
     $authinstructions = 'Something with <b>html tags</b>';
     set_config('auth_instructions', $authinstructions);
     set_config('typeoflogin', api::LOGIN_VIA_BROWSER, 'tool_mobile');
     set_config('logo', 'mock.png', 'core_admin');
     set_config('logocompact', 'mock.png', 'core_admin');
     $expected['registerauth'] = 'email';
     $expected['authinstructions'] = format_text($authinstructions);
     $expected['typeoflogin'] = api::LOGIN_VIA_BROWSER;
     $expected['launchurl'] = "{$CFG->wwwroot}/{$CFG->admin}/tool/mobile/launch.php";
     if ($logourl = $OUTPUT->get_logo_url()) {
         $expected['logourl'] = $logourl->out(false);
     }
     if ($compactlogourl = $OUTPUT->get_compact_logo_url()) {
         $expected['compactlogourl'] = $compactlogourl->out(false);
     }
     $result = external::get_public_config();
     $result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
     $this->assertEquals($expected, $result);
 }
function dialogue_backup_one_mod($bf, $preferences, $dialogue)
{
    if (is_numeric($dialogue)) {
        $dialogue = get_record('dialogue', 'id', $dialogue);
    }
    //Start mod
    fwrite($bf, start_tag("MOD", 3, true));
    //Print dialogue data
    fwrite($bf, full_tag("ID", 4, false, $dialogue->id));
    fwrite($bf, full_tag("MODTYPE", 4, false, "dialogue"));
    fwrite($bf, full_tag("NAME", 4, false, format_string($dialogue->name)));
    fwrite($bf, full_tag("INTRO", 4, false, format_text($dialogue->intro)));
    fwrite($bf, full_tag("DELETEAFTER", 4, false, $dialogue->deleteafter));
    fwrite($bf, full_tag("DIALOGUETYPE", 4, false, $dialogue->dialoguetype));
    fwrite($bf, full_tag("MULTIPLECONVERSATIONS", 4, false, $dialogue->multipleconversations));
    fwrite($bf, full_tag("MAILDEFAULT", 4, false, $dialogue->maildefault));
    fwrite($bf, full_tag("TIMEMODIFIED", 4, false, $dialogue->timemodified));
    fwrite($bf, full_tag("EDITTIME", 4, false, $dialogue->edittime));
    //if we've selected to backup users info, then execute backup_dialogue_conversations
    if ($preferences->mods["dialogue"]->userinfo) {
        $status = backup_dialogue_conversations($bf, $preferences, $dialogue->id);
    }
    //End mod
    $status = fwrite($bf, end_tag("MOD", 3, true));
    return $status;
}
Example #23
0
/**
 * Parent theme: Bootstrapbase by Bas Brands
 * Built on: Essential by Julian Ridden
 *
 * @package   theme_lambda
 * @copyright 2014 redPIthemes
 *
 */
function theme_lambda_get_setting($setting, $format = false)
{
    global $CFG;
    require_once $CFG->dirroot . '/lib/weblib.php';
    static $theme;
    if (empty($theme)) {
        $theme = theme_config::load('lambda');
    }
    if (empty($theme->settings->{$setting})) {
        return false;
    } else {
        if (!$format) {
            return $theme->settings->{$setting};
        } else {
            if ($format === 'format_text') {
                return format_text($theme->settings->{$setting}, FORMAT_PLAIN);
            } else {
                if ($format === 'format_html') {
                    return format_text($theme->settings->{$setting}, FORMAT_HTML, array('trusted' => true, 'noclean' => true));
                } else {
                    return format_string($theme->settings->{$setting});
                }
            }
        }
    }
}
Example #24
0
 /**
  * Return comments by pages
  *
  * @global moodle_database $DB
  * @param int $page
  * @return array An array of comments
  */
 function get_comments($page)
 {
     global $DB;
     if ($page == 0) {
         $start = 0;
     } else {
         $start = $page * $this->perpage;
     }
     $comments = array();
     $sql = "SELECT c.id, c.contextid, c.itemid, c.commentarea, c.userid, c.content, u.firstname, u.lastname, c.timecreated\n                  FROM {comments} c\n                  JOIN {user} u\n                       ON u.id=c.userid\n              ORDER BY c.timecreated ASC";
     $rs = $DB->get_recordset_sql($sql, null, $start, $this->perpage);
     $formatoptions = array('overflowdiv' => true);
     foreach ($rs as $item) {
         // Set calculated fields
         $item->fullname = fullname($item);
         $item->time = userdate($item->timecreated);
         $item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions);
         // Unset fields not related to the comment
         unset($item->firstname);
         unset($item->lastname);
         unset($item->timecreated);
         // Record the comment
         $comments[] = $item;
     }
     $rs->close();
     return $comments;
 }
Example #25
0
 /**
  * Define the elements to be displayed at the form
  *
  * Called by the parent::definition()
  *
  * @return void
  */
 protected function definition_inner(&$mform)
 {
     $fields = $this->_customdata['fields'];
     $current = $this->_customdata['current'];
     $nodims = $this->_customdata['nodims'];
     // number of assessment dimensions
     $mform->addElement('hidden', 'nodims', $nodims);
     $mform->setType('nodims', PARAM_INT);
     for ($i = 0; $i < $nodims; $i++) {
         // dimension header
         $dimtitle = get_string('dimensionnumber', 'teamworkform_numerrors', $i + 1);
         $mform->addElement('header', "dimensionhdr__idx_{$i}", $dimtitle);
         // dimension id
         $mform->addElement('hidden', 'dimensionid__idx_' . $i, $fields->{'dimensionid__idx_' . $i});
         $mform->setType('dimensionid__idx_' . $i, PARAM_INT);
         // grade id
         $mform->addElement('hidden', 'gradeid__idx_' . $i);
         // value set by set_data() later
         $mform->setType('gradeid__idx_' . $i, PARAM_INT);
         // dimension description
         $desc = '<div id="id_dim_' . $fields->{'dimensionid__idx_' . $i} . '_desc" class="fitem description numerrors">' . "\n";
         $desc .= format_text($fields->{'description__idx_' . $i}, $fields->{'description__idx_' . $i . 'format'});
         $desc .= "\n</div>";
         $mform->addElement('html', $desc);
         // evaluation of the assertion
         $label = get_string('dimensiongrade', 'teamworkform_numerrors');
         $mform->addGroup(array($mform->createElement('radio', 'grade__idx_' . $i, '', $fields->{'grade0__idx_' . $i}, -1), $mform->createElement('radio', 'grade__idx_' . $i, '', $fields->{'grade1__idx_' . $i}, 1)), 'group_grade__idx_' . $i, get_string('yourassessment', 'teamwork'), '<br />', false);
         $mform->addRule('group_grade__idx_' . $i, get_string('required'), 'required');
         // comment
         $label = get_string('dimensioncomment', 'teamworkform_numerrors');
         $mform->addElement('textarea', 'peercomment__idx_' . $i, $label, array('cols' => 60, 'rows' => 5));
     }
     $this->set_data($current);
 }
 function get_content()
 {
     global $USER;
     $isteacher = get_record('role_assignments', 'userid', $USER->id, 'roleid', '3');
     // Is the $USER assigned as Teacher, anywhere in the system?
     $iscoursecreator = get_record('role_assignments', 'userid', $USER->id, 'roleid', '2');
     // Is the $USER assigned as Course Creator, anywhere in the system?
     if ($this->content !== NULL) {
         return $this->content;
     }
     //echo "debug teacher=";print_r($isteacher);
     if (!isadmin($USER->id)) {
         if (empty($isteacher) and empty($iscoursecreator)) {
             return;
         }
     }
     if (!empty($this->instance->pinned) or $this->instance->pagetype === 'course-view') {
         // fancy html allowed only on course page and in pinned blocks for security reasons
         $filteropt = new stdClass();
         $filteropt->noclean = true;
     } else {
         $filteropt = null;
     }
     $this->content = new stdClass();
     $this->content->text = isset($this->config->text) ? format_text($this->config->text, FORMAT_HTML, $filteropt) : '';
     $this->content->footer = '';
     unset($filteropt);
     // memory footprint
     return $this->content;
 }
Example #27
0
 /**
  * Tests that the filter applies the required changes.
  *
  * @return void
  */
 public function test_filter()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     filter_manager::reset_caches();
     filter_set_global_state('data', TEXTFILTER_ON);
     $course1 = $this->getDataGenerator()->create_course();
     $coursecontext1 = context_course::instance($course1->id);
     $course2 = $this->getDataGenerator()->create_course();
     $coursecontext2 = context_course::instance($course2->id);
     $sitecontext = context_course::instance(SITEID);
     $site = get_site();
     $this->add_simple_database_instance($site, array('SiteEntry'));
     $this->add_simple_database_instance($course1, array('CourseEntry'));
     $html = '<p>I like CourseEntry and SiteEntry</p>';
     // Testing at course level (both site and course).
     $filtered = format_text($html, FORMAT_HTML, array('context' => $coursecontext1));
     $this->assertRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
     $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
     // Testing at site level (only site).
     $filtered = format_text($html, FORMAT_HTML, array('context' => $sitecontext));
     $this->assertNotRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
     $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
     // Changing to another course to test the caches invalidation (only site).
     $filtered = format_text($html, FORMAT_HTML, array('context' => $coursecontext2));
     $this->assertNotRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
     $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
 }
Example #28
0
 function print_file($filename, $filedata, $showln = true)
 {
     $ext = strtolower(vpl_fileExtension($filename));
     if (isset(self::$map[$ext])) {
         $lang = self::$map[$ext];
     } else {
         $lang = 'text';
     }
     $line = 0;
     $insert_link = function ($found) use($filename, &$line) {
         $ret = '<span class="vpl_ln">';
         $line++;
         $name = $filename . '.' . $line;
         $ret .= '<a name="' . $name . '"></a>';
         $ret .= sprintf('%5d', $line);
         $ret .= ' </span>';
         return $ret . '<span ';
     };
     $code = '<pre class="vpl_sh vpl_g">';
     $code .= '<span syntax="' . $lang . '"';
     $code .= $showln ? ' linenumbers="yes"' : '';
     $code .= '>' . htmlentities($filedata, ENT_NOQUOTES) . '</span>';
     $code .= '</pre>';
     $html = format_text($code, FORMAT_HTML, array('noclean' => true));
     if (preg_match('(<li )', $html) == 1) {
         $html = preg_replace_callback('(<li )', $insert_link, $html);
         $html = preg_replace('(</li>)', '</span>', $html);
         $html = preg_replace('(<div [^>]*><ol>)', '', $html);
         $html = preg_replace('(</ol></div>)', '', $html);
         echo $html;
     } else {
         $printer = vpl_sh_factory::get_object('text');
         $printer->print_file($filename, $filedata, $showln);
     }
 }
Example #29
0
 function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options)
 {
     global $CFG, $USER;
     static $htmleditorused = false;
     $answers =& $question->options->answers;
     $readonly = empty($options->readonly) ? '' : 'disabled="disabled"';
     // *RELIC of essay question type* Only use the rich text editor for the first poodllrecording question on a page.
     //  $usehtmleditor = can_use_html_editor() && !$htmleditorused;
     $formatoptions = new stdClass();
     $formatoptions->noclean = true;
     $formatoptions->para = false;
     $inputname = $question->name_prefix;
     $stranswer = get_string("answer", "quiz") . ': ';
     /// set question text and media
     $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course);
     $image = get_question_image($question);
     // feedback handling
     $feedback = '';
     if ($options->feedback && !empty($answers)) {
         foreach ($answers as $answer) {
             $feedback = format_text($answer->feedback, '', $formatoptions, $cmoptions->course);
         }
     }
     // get response value
     if (isset($state->responses[''])) {
         //relic of essay question type
         //$value = stripslashes_safe($state->responses['']);
         $value = $state->responses[''];
     } else {
         $value = "";
     }
     // answer
     if (empty($options->readonly)) {
         // *RELIC of essay question type* the student needs to record their voice  or video so lets give them their recorder.
         // $answer = print_textarea($usehtmleditor, 18, 80, 630, 400, $inputname, $value, $cmoptions->course, true);
         $answer = fetchSimpleAudioRecorder('question/' . $question->id, $USER->id, $inputname, '') . '<input type="hidden" value="" id="' . $inputname . '" name="' . $inputname . '" />';
     } else {
         // it is read only, so just format the students answer and output it
         // *RELIC of essay question type*
         /*
           $safeformatoptions = new stdClass;
           $safeformatoptions->para = false;
           $answer = format_text($value, FORMAT_MOODLE,
                                 $safeformatoptions, $cmoptions->course);
         			$answer = '<div class="answerreview">' . $answer . '</div>';					  
         */
         //$answer = $value ;
         //this will show an audio player both to the grading teacher and to the student reviewing
         $answer = fetchSimpleAudioPlayer($value, 'rtmp', 250, 30, false);
     }
     include "{$CFG->dirroot}/question/type/poodllrecording/display.html";
     // *RELIC of essay question type*
     /*
             if ($usehtmleditor && empty($options->readonly)) {
                 use_html_editor($inputname);
                 $htmleditorused = true;
             }
     */
 }
Example #30
0
 public function display_message(Page $page, User $from, User $to, PM $pm)
 {
     $this->display_composer($page, $to, $from, "Re: " . $pm->subject);
     $page->set_title("Private Message");
     $page->set_heading(html_escape($pm->subject));
     $page->add_block(new NavBlock());
     $page->add_block(new Block("Message from {$from->name}", format_text($pm->message), "main", 10));
 }