/**
  * Does initial configuration for a given html editor.
  * @param string editor the name of desired html editor, system default will be used if none is passed
  * @param int courseid the courseid uploaded files should be linked to
  * @return bool true if an editor was configured, false otherwise.
  */
 public function configure($editor = NULL, $courseid = NULL)
 {
     global $CFG;
     static $configured = array();
     if (!isset($CFG->htmleditor) or !$CFG->htmleditor) {
         return;
     }
     if ($editor == '') {
         $editor = isset($CFG->defaulthtmleditor) ? $CFG->defaulthtmleditor : '';
     }
     if (isset($configured[$editor])) {
         return $configured[$editor];
     }
     $configuration = array();
     switch ($editor) {
         case 'tinymce':
             $editorlanguage = current_language();
             $configuration[] = $CFG->httpswwwroot . "/lib/editor/tinymce/jscripts/tiny_mce/tiny_mce.js";
             //$configuration[] = $CFG->httpswwwroot ."/lib/editor/tinymce/jscripts/tiny_mce/tiny_mce_src.js";
             $configuration[] = $CFG->httpswwwroot . "/lib/editor/tinymce/tinymce.js.php?course={$courseid}&editorlanguage={$editorlanguage}";
             $configured['tinymce'] = true;
             break;
         default:
             $configured[$editor] = false;
             break;
     }
     if (isset($CFG->editorsrc) && is_array($CFG->editorsrc)) {
         $CFG->editorsrc = $configuration + $CFG->editorsrc;
     } else {
         $CFG->editorsrc = $configuration;
     }
     return $configured[$editor];
 }
Example #2
0
 public function __construct()
 {
     parent::__construct();
     $this->authenticate->redirect_except();
     reset_language(current_language());
     $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
 }
Example #3
0
function check_language($cmd)
{
    /// return users current language if its
    /// dictionary is found installed in system
    /// and always return english if user's own
    /// language is not in the list. If english dictionary
    /// isn't found, then false is returned.
    global $CFG;
    clearstatcache();
    $current_lang = str_replace('_utf8', '', current_language());
    $output = '';
    if (!($handle = popen($cmd . ' dump dicts', 'r'))) {
        error_handler("Couldn't create handle!");
        exit;
    }
    while (!feof($handle)) {
        $output .= fread($handle, 1024);
    }
    @pclose($handle);
    $dicts = explode(chr(10), strtolower($output));
    if (is_array($dicts)) {
        if (in_array($current_lang, $dicts)) {
            return $current_lang;
        }
    }
    if (!empty($CFG->editordictionary)) {
        return $CFG->editordictionary;
    }
    return false;
}
Example #4
0
 public function __construct()
 {
     parent::__construct();
     $this->authenticate->redirect_except(array('register', 'register_submit', 'register_finish', 'forgot_password', 'forgot_password_submit', 'reset_password', 'reset_password_submit'));
     reset_language(current_language());
     $this->form_validation->set_error_delimiters('<label class="error">', '</label>');
 }
Example #5
0
 protected function render_custom_menu(custom_menu $menu)
 {
     global $CFG;
     // TODO: eliminate this duplicated logic, it belongs in core, not
     // here. See MDL-39565.
     $addlangmenu = true;
     $langs = get_string_manager()->get_list_of_translations();
     if (count($langs) < 2 or empty($CFG->langmenu) or $this->page->course != SITEID and !empty($this->page->course->lang)) {
         $addlangmenu = false;
     }
     if (!$menu->has_children() && $addlangmenu === false) {
         return '';
     }
     if ($addlangmenu) {
         $strlang = get_string('language');
         $currentlang = current_language();
         if (isset($langs[$currentlang])) {
             $currentlang = $langs[$currentlang];
         } else {
             $currentlang = $strlang;
         }
         $this->language = $menu->add($currentlang, new moodle_url('#'), $strlang, 10000);
         foreach ($langs as $langtype => $langname) {
             $this->language->add($langname, new moodle_url($this->page->url, array('lang' => $langtype)), $langname);
         }
     }
     $content = '<ul class="nav">';
     foreach ($menu->get_children() as $item) {
         $content .= $this->render_custom_menu_item($item, 1);
     }
     return $content . '</ul>';
 }
 public static function get_current_language()
 {
     $result = current_language();
     $result = explode('_', $result);
     $result = reset($result);
     return $result;
 }
Example #7
0
 protected function get_init_params($elementid, array $options = null)
 {
     global $CFG, $PAGE, $OUTPUT;
     //TODO: we need to implement user preferences that affect the editor setup too
     $directionality = get_string('thisdirection', 'langconfig');
     $strtime = get_string('strftimetime');
     $strdate = get_string('strftimedaydate');
     $lang = current_language();
     $contentcss = $PAGE->theme->editor_css_url()->out(false);
     $context = empty($options['context']) ? get_context_instance(CONTEXT_SYSTEM) : $options['context'];
     $xmedia = 'moodlemedia,';
     // HQ thinks it should be always on, so it is no matter if it will actually work or not
     /*
             if (!empty($options['legacy'])) {
                 $xmedia = 'moodlemedia,';
             } else {
                 if (!empty($options['noclean']) or !empty($options['trusted'])) {
                 }
             }*/
     $filters = filter_get_active_in_context($context);
     if (array_key_exists('filter/tex', $filters)) {
         $xdragmath = 'dragmath,';
     } else {
         $xdragmath = '';
     }
     if (array_key_exists('filter/emoticon', $filters)) {
         $xemoticon = 'moodleemoticon,';
     } else {
         $xemoticon = '';
     }
     $params = array('mode' => "exact", 'elements' => $elementid, 'relative_urls' => false, 'document_base_url' => $CFG->httpswwwroot, 'content_css' => $contentcss, 'language' => $lang, 'directionality' => $directionality, 'plugin_insertdate_dateFormat ' => $strdate, 'plugin_insertdate_timeFormat ' => $strtime, 'theme' => "advanced", 'skin' => "o2k7", 'skin_variant' => "silver", 'apply_source_formatting' => true, 'remove_script_host' => false, 'entity_encoding' => "raw", 'plugins' => "{$xmedia}advimage,safari,table,style,layer,advhr,advlink,emotions,inlinepopups,searchreplace,paste,directionality,fullscreen,moodlenolink,{$xemoticon}{$xdragmath}nonbreaking,contextmenu,insertdatetime,save,iespell,preview,print,noneditable,visualchars,xhtmlxtras,template,pagebreak,spellchecker", 'theme_advanced_font_sizes' => "1,2,3,4,5,6,7", 'theme_advanced_layout_manager' => "SimpleLayout", 'theme_advanced_toolbar_align' => "left", 'theme_advanced_buttons1' => "fontselect,fontsizeselect,formatselect", 'theme_advanced_buttons1_add' => "|,undo,redo,|,search,replace,|,fullscreen", 'theme_advanced_buttons2' => "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright", 'theme_advanced_buttons2_add' => "|,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl", 'theme_advanced_buttons3' => "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,|,image,{$xemoticon}{$xmedia}{$xdragmath}nonbreaking,charmap", 'theme_advanced_buttons3_add' => "table,|,code,spellchecker", 'theme_advanced_fonts' => "Trebuchet=Trebuchet MS,Verdana,Arial,Helvetica,sans-serif;Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;Wingdings=wingdings", 'theme_advanced_resize_horizontal' => true, 'theme_advanced_resizing' => true, 'theme_advanced_toolbar_location' => "top", 'theme_advanced_statusbar_location' => "bottom", 'spellchecker_rpc_url' => $CFG->wwwroot . "/lib/editor/tinymce/tiny_mce/{$this->version}/plugins/spellchecker/rpc.php");
     if ($xemoticon) {
         $manager = get_emoticon_manager();
         $emoticons = $manager->get_emoticons();
         $imgs = array();
         // see the TinyMCE plugin moodleemoticon for how the emoticon index is (ab)used :-S
         $index = 0;
         foreach ($emoticons as $emoticon) {
             $imgs[$emoticon->text] = $OUTPUT->render($manager->prepare_renderable_emoticon($emoticon, array('class' => 'emoticon emoticon-index-' . $index++)));
         }
         $params['moodleemoticon_emoticons'] = json_encode($imgs);
     }
     if (empty($CFG->xmlstrictheaders) and (!empty($options['legacy']) or !empty($options['noclean']) or !empty($options['trusted']))) {
         // now deal somehow with non-standard tags, people scream when we do not make moodle code xtml strict,
         // but they scream even more when we strip all tags that are not strict :-(
         $params['valid_elements'] = 'script[src|type],*[*]';
         // for some reason the *[*] does not inlcude javascript src attribute MDL-25836
         $params['invalid_elements'] = '';
     }
     if (empty($options['legacy'])) {
         if (isset($options['maxfiles']) and $options['maxfiles'] != 0) {
             $params['file_browser_callback'] = "M.editor_tinymce.filepicker";
         }
     }
     //Add onblur event for client side text validation
     if (!empty($options['required'])) {
         $params['init_instance_callback'] = 'M.editor_tinymce.onblur_event';
     }
     return $params;
 }
 protected function render_custom_menu(custom_menu $menu)
 {
     $langs = get_string_manager()->get_list_of_translations();
     $haslangmenu = $this->lang_menu() != '';
     if (!$menu->has_children() && !$haslangmenu) {
         return '';
     }
     if ($haslangmenu) {
         $strlang = get_string('language');
         $currentlang = current_language();
         if (isset($langs[$currentlang])) {
             $currentlang = $langs[$currentlang];
         } else {
             $currentlang = $strlang;
         }
         $this->language = $menu->add($currentlang, new moodle_url('#'), $strlang, 10000);
         foreach ($langs as $langtype => $langname) {
             $this->language->add($langname, new moodle_url($this->page->url, array('lang' => $langtype)), $langname);
         }
     }
     $children = $menu->get_children();
     if (count($children) == 0) {
         return false;
     }
     $content = '';
     foreach ($menu->get_children() as $item) {
         $content .= $this->render_custom_menu_item($item, 1);
     }
     return $content;
 }
 function definition()
 {
     global $COURSE;
     $mform =& $this->_form;
     $defaultcategory = $this->_customdata['defaultcategory'];
     $contexts = $this->_customdata['contexts'];
     //--------------------------------------------------------------------------------
     $mform->addElement('header', null, get_string("registrationinfotitle", 'qformat_wordtable'));
     $mform->addElement('hidden', 'lang', current_language());
     $mform->addElement('hidden', 'version', $CFG->version);
     $mform->addElement('hidden', 'release', $CFG->release);
     $mform->addElement('hidden', 'courseid', '');
     $mform->addElement('text', 'yolusername', get_string('username'));
     $mform->addRule('yolusername', get_string('required'), 'required', '', 'client');
     $mform->addRule('yolusername', get_string('invalidemail'), 'email', '', 'client');
     $mform->applyFilter('yolusername', 'trim');
     $mform->addElement('password', 'password', get_string("password"));
     $mform->addRule('password', get_string('required'), 'required', '', 'client');
     $mform->addElement('password', 'passwordconfirm', get_string("password"));
     $mform->addRule('passwordconfirm', get_string('required'), 'required', '', 'client');
     // This doesn't work, don't know why
     //$mform->addRule(array('password', 'passwordconfirm'), get_string('registrationpasswordsdonotmatch', 'qformat_wordtable'), 'compare', '', 'client');
     $mform->addElement('static', 'dummy2', '');
     $mform->addElement('text', 'sitename', get_string("fullsitename"));
     $mform->addRule('sitename', get_string('required'), 'required', '', 'client');
     $mform->applyFilter('sitename', 'trim');
     $mform->addElement('text', 'adminname', get_string("administrator"));
     $mform->addRule('adminname', get_string('required'), 'required', '', 'client');
     $mform->applyFilter('adminname', 'trim');
     $mform->addElement('text', 'adminemail', get_string("email"));
     $mform->addRule('adminemail', get_string('required'), 'required', '', 'client');
     $mform->addRule('adminemail', get_string('invalidemail'), 'email', '', 'client');
     $mform->applyFilter('adminemail', 'trim');
     $options[0] = get_string("publicdirectory0");
     $options[1] = get_string("publicdirectory1");
     $options[2] = get_string("publicdirectory2");
     $mform->addElement('select', 'public', get_string("publicdirectory"), $options);
     unset($options);
     /*
             $options[0] = get_string("subtype_free", "qformat_wordtable");
             $options[1] = get_string("subtype_unlimited", "qformat_wordtable");
             $mform->addElement('select', 'subscription', get_string("subscription_type", "qformat_wordtable"), $options );
             unset($options);
     */
     $options[0] = "<500";
     $options[1] = "501-5,000";
     $options[2] = ">5,001";
     $mform->addElement('select', 'sitesize', get_string("users"), $options);
     unset($options);
     $mform->addElement('select', 'country', get_string("selectacountry"), get_list_of_countries());
     $options[0] = get_string("registrationno");
     $options[1] = get_string("registrationyes");
     $mform->addElement('select', 'mailme', get_string("registrationemail"), $options);
     //--------------------------------------------------------------------------------
     $mform->addElement('submit', 'submitbutton', get_string('registrationsend', 'qformat_wordtable'));
     //--------------------------------------------------------------------------------
     $mform->addElement('static', 'dummy', '');
     $mform->closeHeaderBefore('dummy');
 }
 /** Specifies the contents of the default page. */
 public function add()
 {
     $data['page_title'] = lang('availability');
     $data['lang'] = current_language() == L::Dutch ? 'nl' : 'en';
     $data['preselect'] = AVAILABILITY_DEFAULT_TIMES;
     $this->load->view('templates/header');
     $this->authenticate->authenticate_redirect('availability_add_view', $data, UserRole::Leader);
     $this->load->view('templates/footer');
 }
Example #11
0
 public function custom_menu($custommenuitems = '')
 {
     global $CFG;
     if (!empty($CFG->custommenuitems)) {
         $custommenuitems .= $CFG->custommenuitems;
     }
     $custommenu = new custom_menu($custommenuitems, current_language());
     return $this->render_custom_menu($custommenu);
 }
Example #12
0
 /**
  * Test get_docs_url_standard in the normal case when we should link to Moodle docs.
  */
 public function test_get_docs_url_standard()
 {
     global $CFG;
     if (empty($CFG->docroot)) {
         $docroot = 'http://docs.moodle.org/';
     } else {
         $docroot = $CFG->docroot;
     }
     $this->assertRegExp('~^' . preg_quote($docroot, '') . '/2\\d/' . current_language() . '/course/editing$~', get_docs_url('course/editing'));
 }
 /**
  * Sets the parameters property of the extended class
  *
  * Sets the parameters property of the extended file resource class
  *
  * @param    USER  global object
  * @param    CFG   global object
  */
 function set_parameters()
 {
     global $USER, $CFG;
     $site = get_site();
     $this->parameters = array('label2' => array('langstr' => "", 'value' => '/optgroup'), 'label3' => array('langstr' => get_string('course'), 'value' => 'optgroup'), 'courseid' => array('langstr' => 'id', 'value' => $this->course->id), 'coursefullname' => array('langstr' => get_string('fullname'), 'value' => $this->course->fullname), 'courseshortname' => array('langstr' => get_string('shortname'), 'value' => $this->course->shortname), 'courseidnumber' => array('langstr' => get_string('idnumbercourse'), 'value' => $this->course->idnumber), 'coursesummary' => array('langstr' => get_string('summary'), 'value' => $this->course->summary), 'courseformat' => array('langstr' => get_string('format'), 'value' => $this->course->format), 'courseteacher' => array('langstr' => get_string('wordforteacher'), 'value' => $this->course->teacher), 'courseteachers' => array('langstr' => get_string('wordforteachers'), 'value' => $this->course->teachers), 'coursestudent' => array('langstr' => get_string('wordforstudent'), 'value' => $this->course->student), 'coursestudents' => array('langstr' => get_string('wordforstudents'), 'value' => $this->course->students), 'label4' => array('langstr' => "", 'value' => '/optgroup'), 'label5' => array('langstr' => get_string('miscellaneous'), 'value' => 'optgroup'), 'lang' => array('langstr' => get_string('preferredlanguage'), 'value' => current_language()), 'sitename' => array('langstr' => get_string('fullsitename'), 'value' => format_string($site->fullname)), 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $CFG), 'value' => $CFG->wwwroot), 'currenttime' => array('langstr' => get_string('time'), 'value' => time()), 'encryptedcode' => array('langstr' => get_string('encryptedcode'), 'value' => $this->set_encrypted_parameter()), 'label6' => array('langstr' => "", 'value' => '/optgroup'));
     if (!empty($USER->id)) {
         $userparameters = array('label1' => array('langstr' => get_string('user'), 'value' => 'optgroup'), 'userid' => array('langstr' => 'id', 'value' => $USER->id), 'userusername' => array('langstr' => get_string('username'), 'value' => $USER->username), 'useridnumber' => array('langstr' => get_string('idnumber'), 'value' => $USER->idnumber), 'userfirstname' => array('langstr' => get_string('firstname'), 'value' => $USER->firstname), 'userlastname' => array('langstr' => get_string('lastname'), 'value' => $USER->lastname), 'userfullname' => array('langstr' => get_string('fullname'), 'value' => fullname($USER)), 'useremail' => array('langstr' => get_string('email'), 'value' => $USER->email), 'usericq' => array('langstr' => get_string('icqnumber'), 'value' => $USER->icq), 'userphone1' => array('langstr' => get_string('phone') . ' 1', 'value' => $USER->phone1), 'userphone2' => array('langstr' => get_string('phone') . ' 2', 'value' => $USER->phone2), 'userinstitution' => array('langstr' => get_string('institution'), 'value' => $USER->institution), 'userdepartment' => array('langstr' => get_string('department'), 'value' => $USER->department), 'useraddress' => array('langstr' => get_string('address'), 'value' => $USER->address), 'usercity' => array('langstr' => get_string('city'), 'value' => $USER->city), 'usertimezone' => array('langstr' => get_string('timezone'), 'value' => get_user_timezone_offset()), 'userurl' => array('langstr' => get_string('webpage'), 'value' => $USER->url));
         $this->parameters = $userparameters + $this->parameters;
     }
 }
Example #14
0
 public function __construct()
 {
     parent::__construct();
     $this->authenticate->redirect_except();
     reset_language(current_language());
     $this->form_validation->set_error_delimiters('<label class="error">', '</label>');
     // Uploading experiment attachments
     $config['upload_path'] = './uploads/';
     $config['allowed_types'] = 'pdf';
     $this->load->library('upload', $config);
 }
 public function test_get_site_info()
 {
     global $DB, $USER, $CFG;
     $this->resetAfterTest(true);
     // This is the info we are going to check
     set_config('release', '2.4dev (Build: 20120823)');
     set_config('version', '2012083100.00');
     // Set current user
     $user = array();
     $user['username'] = '******';
     $user['firstname'] = 'John';
     $user['lastname'] = 'Doe';
     self::setUser(self::getDataGenerator()->create_user($user));
     // Add a web service and token.
     $webservice = new stdClass();
     $webservice->name = 'Test web service';
     $webservice->enabled = true;
     $webservice->restrictedusers = false;
     $webservice->component = 'moodle';
     $webservice->timecreated = time();
     $webservice->downloadfiles = true;
     $webservice->uploadfiles = true;
     $externalserviceid = $DB->insert_record('external_services', $webservice);
     // Add a function to the service
     $DB->insert_record('external_services_functions', array('externalserviceid' => $externalserviceid, 'functionname' => 'core_course_get_contents'));
     $_POST['wstoken'] = 'testtoken';
     $externaltoken = new stdClass();
     $externaltoken->token = 'testtoken';
     $externaltoken->tokentype = 0;
     $externaltoken->userid = $USER->id;
     $externaltoken->externalserviceid = $externalserviceid;
     $externaltoken->contextid = 1;
     $externaltoken->creatorid = $USER->id;
     $externaltoken->timecreated = time();
     $DB->insert_record('external_tokens', $externaltoken);
     $siteinfo = core_webservice_external::get_site_info();
     // We need to execute the return values cleaning process to simulate the web service server.
     $siteinfo = external_api::clean_returnvalue(core_webservice_external::get_site_info_returns(), $siteinfo);
     $this->assertEquals('johnd', $siteinfo['username']);
     $this->assertEquals('John', $siteinfo['firstname']);
     $this->assertEquals('Doe', $siteinfo['lastname']);
     $this->assertEquals(current_language(), $siteinfo['lang']);
     $this->assertEquals($USER->id, $siteinfo['userid']);
     $this->assertEquals(true, $siteinfo['downloadfiles']);
     $this->assertEquals($CFG->release, $siteinfo['release']);
     $this->assertEquals($CFG->version, $siteinfo['version']);
     $this->assertEquals($CFG->mobilecssurl, $siteinfo['mobilecssurl']);
     $this->assertEquals(count($siteinfo['functions']), 1);
     $function = array_pop($siteinfo['functions']);
     $this->assertEquals($function['name'], 'core_course_get_contents');
     $this->assertEquals($function['version'], $siteinfo['version']);
     $this->assertEquals(1, $siteinfo['downloadfiles']);
     $this->assertEquals(1, $siteinfo['uploadfiles']);
 }
Example #16
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $USER;
     require_once get_config('docroot') . 'lib/view.php';
     $configdata = $instance->get('configdata');
     // this will make sure to unserialize it for us
     $configdata['viewid'] = $instance->get('view');
     $view = new View($configdata['viewid']);
     $group = $view->get('group');
     $result = '';
     $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null;
     if ($artefactid) {
         $artefact = $instance->get_artefact_instance($configdata['artefactid']);
         if (!file_exists($artefact->get_path())) {
             return '';
         }
         $urlbase = get_config('wwwroot');
         // edit view doesn't use subdomains, neither do groups
         if (get_config('cleanurls') && get_config('cleanurlusersubdomains') && !$editing && empty($group)) {
             $viewauthor = new User();
             $viewauthor->find_by_id($view->get('owner'));
             $viewauthorurlid = $viewauthor->get('urlid');
             if ($urlallowed = !is_null($viewauthorurlid) && strlen($viewauthorurlid)) {
                 $urlbase = profile_url($viewauthor) . '/';
             }
         }
         // Send the current language to the pdf viewer
         $language = current_language();
         $language = str_replace('_', '-', substr($language, 0, substr_count($language, '_') > 0 ? 5 : 2));
         if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
             // In case the language file exists as a string with both lower and upper case, eg fr_FR we test for this
             $language = substr($language, 0, 2) . '-' . strtoupper(substr($language, 0, 2));
             if (!file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
                 // In case we fail to find a language of 5 chars, eg pt_BR (Portugese, Brazil) we try the 'parent' pt (Portugese)
                 $language = substr($language, 0, 2);
                 if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) {
                     $language = 'en-GB';
                 }
             }
         }
         $result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&lang=' . $language . '&view=' . $instance->get('view') . '" width="100%" height="500" frameborder="0"></iframe>';
         require_once get_config('docroot') . 'artefact/comment/lib.php';
         require_once get_config('docroot') . 'lib/view.php';
         $view = new View($configdata['viewid']);
         list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing);
     }
     $smarty = smarty_core();
     if ($artefactid) {
         $smarty->assign('commentcount', $commentcount);
         $smarty->assign('comments', $comments);
     }
     $smarty->assign('html', $result);
     return $smarty->fetch('blocktype:pdf:pdfrender.tpl');
 }
Example #17
0
 public function custom_menu($custommenuitems = '')
 {
     // The custom menu is always shown, even if no menu items
     // are configured in the global theme settings page.
     global $CFG;
     if (!empty($CFG->custommenuitems)) {
         $custommenuitems .= $CFG->custommenuitems;
     }
     $custommenu = new custom_menu($custommenuitems, current_language());
     return $this->render_custom_menu($custommenu);
 }
Example #18
0
function report_security_doc_link($issue, $name)
{
    global $CFG;
    if (empty($CFG->docroot)) {
        return $name;
    }
    $lang = str_replace('_utf8', '', current_language());
    $str = "<a onclick=\"this.target='docspopup'\" href=\"{$CFG->docroot}/{$lang}/report/security/{$issue}\">";
    $str .= "<img class=\"iconhelp\" src=\"{$CFG->httpswwwroot}/pix/docs.gif\" alt=\"\" />{$name}</a>";
    return $str;
}
Example #19
0
 /**
  * Test get_component_strings
  */
 public function test_get_component_strings()
 {
     global $USER;
     $this->resetAfterTest(true);
     $stringmanager = get_string_manager();
     $wsstrings = $stringmanager->load_component_strings('webservice', current_language());
     $componentstrings = core_external::get_component_strings('webservice');
     $this->assertEquals(count($componentstrings), count($wsstrings));
     foreach ($wsstrings as $name => $string) {
         $this->assertEquals($string, $componentstrings[$name]);
     }
 }
function wrs_getLanguagePath()
{
    $currentLanguage = substr(current_language(), 0, 2) . '_utf8';
    global $CFG;
    $currentPath = $CFG->dirroot . '/lang/' . $currentLanguage;
    if (file_exists($currentPath)) {
        return $currentPath;
    }
    $currentPath = $CFG->dataroot . '/lang/' . $currentLanguage;
    if (file_exists($currentPath)) {
        return $currentPath;
    }
    return $CFG->dirroot . '/lang/en_utf8';
}
Example #21
0
    public function test_get_site_info() {
        global $DB, $USER, $CFG;

        $this->resetAfterTest(true);

        // This is the info we are going to check
        set_config('release', '2.4dev (Build: 20120823)');
        set_config('version', '2012083100.00');

        // Set current user
        $user = array();
        $user['username'] = '******';
        $user['firstname'] = 'John';
        $user['lastname'] = 'Doe';
        self::setUser(self::getDataGenerator()->create_user($user));

        // Add a web service and token.
        $webservice = new stdClass();
        $webservice->name = 'Test web service';
        $webservice->enabled = true;
        $webservice->restrictedusers = false;
        $webservice->component = 'moodle';
        $webservice->timecreated = time();
        $webservice->downloadfiles = true;
        $externalserviceid = $DB->insert_record('external_services', $webservice);

        $_POST['wstoken'] = 'testtoken';
        $externaltoken = new stdClass();
        $externaltoken->token = 'testtoken';
        $externaltoken->tokentype = 0;
        $externaltoken->userid = $USER->id;
        $externaltoken->externalserviceid = $externalserviceid;
        $externaltoken->contextid = 1;
        $externaltoken->creatorid = $USER->id;
        $externaltoken->timecreated = time();
        $DB->insert_record('external_tokens', $externaltoken);

        $siteinfo = core_webservice_external::get_site_info();

        $this->assertEquals('johnd', $siteinfo['username']);
        $this->assertEquals('John', $siteinfo['firstname']);
        $this->assertEquals('Doe', $siteinfo['lastname']);
        $this->assertEquals(current_language(), $siteinfo['lang']);
        $this->assertEquals($USER->id, $siteinfo['userid']);
        $this->assertEquals(true, $siteinfo['downloadfiles']);
        $this->assertEquals($CFG->release, $siteinfo['release']);
        $this->assertEquals($CFG->version, $siteinfo['version']);
        $this->assertEquals(get_config('admin', 'mobilecssurl'), $siteinfo['mobilecssurl']);
    }
Example #22
0
 public function setup($page, $context)
 {
     // This only requires execution once per request.
     static $jsinitialised = false;
     if (empty($jsinitialised)) {
         $url = get_config('filter_mathjaxloader', 'httpsurl');
         $lang = $this->map_language_code(current_language());
         $url = new moodle_url($url, array('delayStartupUntil' => 'configured'));
         $moduleconfig = array('name' => 'mathjax', 'fullpath' => $url);
         $page->requires->js_module($moduleconfig);
         $config = get_config('filter_mathjaxloader', 'mathjaxconfig');
         $params = array('mathjaxconfig' => $config, 'lang' => $lang);
         $page->requires->yui_module('moodle-filter_mathjaxloader-loader', 'M.filter_mathjaxloader.configure', array($params));
         $jsinitialised = true;
     }
 }
Example #23
0
 public static function localize_text($text, $format, $qa, $component, $filearea, $itemid, $clean = false)
 {
     $language = current_language();
     $dom = new DOMDocument();
     $dom->strictErrorChecking = FALSE;
     $dom->loadHTML('<?xml version="1.0" encoding="UTF-8"?><html><body>' . $text . '</body></html>');
     $finder = new DomXPath($dom);
     $classname = "multilang";
     $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' {$classname} ')]");
     foreach ($nodes as $node) {
         if (strcmp($node->getAttribute("lang"), $language) == 0) {
             $text = self::DOMinnerHTML($node);
             break;
         }
     }
     return $text;
 }
 /** Specifies the contents of the default page. */
 public function index($header = TRUE)
 {
     // Prepare the data
     $data['page_title'] = lang('calendar');
     $data['legend'] = $this->generate_legend();
     $data['lang'] = current_language() == L::Dutch ? 'nl' : 'en';
     $data['experiments'] = $this->experimentModel->get_all_experiments();
     $data['participants'] = $this->participantModel->get_all_participants();
     $data['locations'] = $this->locationModel->get_all_locations();
     $data['leaders'] = array_merge($this->userModel->get_all_leaders(), $this->userModel->get_all_admins());
     // Load the view
     if ($header) {
         $this->load->view('templates/header', $data);
     } else {
         $this->load->view('templates/simple_header', $data);
     }
     $this->load->view('appointment_view');
     $this->load->view('templates/footer');
 }
Example #25
0
 /**
  * Renders the list of available steps according to the submitted filters.
  *
  * @param mixed $stepsdefinitions Available steps array.
  * @param moodleform $form
  * @return string HTML code
  */
 public function render_stepsdefinitions($stepsdefinitions, $form)
 {
     $html = $this->generic_info();
     // Form.
     ob_start();
     $form->display();
     $html .= ob_get_contents();
     ob_end_clean();
     if (empty($stepsdefinitions)) {
         $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
     } else {
         $stepsdefinitions = implode('', $stepsdefinitions);
         // Replace text selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace simple OR options.
         $regex = '#\\(\\?P<[^>]+>([^\\)|]+\\|[^\\)]+)\\)#';
         $stepsdefinitions = preg_replace_callback($regex, function ($matches) {
             return html_writer::select(explode('|', $matches[1]), uniqid());
         }, $stepsdefinitions);
         $stepsdefinitions = preg_replace_callback('/(FIELD_VALUE_STRING)/', function ($matches) {
             global $CFG;
             // Creating a link to a popup with the help.
             $url = new moodle_url('/help.php', array('component' => 'tool_behat', 'identifier' => 'fieldvalueargument', 'lang' => current_language()));
             // Note: this title is displayed only if JS is disabled,
             // otherwise the link will have the new ajax tooltip.
             $title = get_string('fieldvalueargument', 'tool_behat');
             $title = get_string('helpprefix2', '', trim($title, ". \t"));
             $attributes = array('href' => $url, 'title' => $title, 'aria-haspopup' => 'true', 'target' => '_blank');
             $output = html_writer::tag('a', 'FIELD_VALUE_STRING', $attributes);
             return html_writer::tag('span', $output, array('class' => 'helptooltip'));
         }, $stepsdefinitions);
     }
     // Steps definitions.
     $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
     $html .= $this->output->footer();
     return $html;
 }
Example #26
0
 /**
  * Replace emoticons found in the text with their images
  *
  * @param string $text to modify
  * @return void
  */
 protected function replace_emoticons(&$text)
 {
     global $CFG, $OUTPUT, $PAGE;
     static $emoticontexts = array();
     // internal cache used for replacing
     static $emoticonimgs = array();
     // internal cache used for replacing
     $lang = current_language();
     $theme = $PAGE->theme->name;
     if (!isset($emoticontexts[$lang][$theme]) or !isset($emoticonimgs[$lang][$theme])) {
         // prepare internal caches
         $manager = get_emoticon_manager();
         $emoticons = $manager->get_emoticons();
         $emoticontexts[$lang][$theme] = array();
         $emoticonimgs[$lang][$theme] = array();
         foreach ($emoticons as $emoticon) {
             $emoticontexts[$lang][$theme][] = $emoticon->text;
             $emoticonimgs[$lang][$theme][] = $OUTPUT->render($manager->prepare_renderable_emoticon($emoticon));
         }
         unset($emoticons);
     }
     if (empty($emoticontexts[$lang][$theme])) {
         // No emoticons defined, nothing to process here
         return;
     }
     // detect all the <script> zones to take out
     $excludes = array();
     preg_match_all('/<script language(.+?)<\\/script>/is', $text, $listofexcludes);
     // take out all the <script> zones from text
     foreach (array_unique($listofexcludes[0]) as $key => $value) {
         $excludes['<+' . $key . '+>'] = $value;
     }
     if ($excludes) {
         $text = str_replace($excludes, array_keys($excludes), $text);
     }
     // this is the meat of the code - this is run every time
     $text = str_replace($emoticontexts[$lang][$theme], $emoticonimgs[$lang][$theme], $text);
     // Recover all the <script> zones to text
     if ($excludes) {
         $text = str_replace(array_keys($excludes), $excludes, $text);
     }
 }
 protected static function replace_callback($langblock)
 {
     global $CFG;
     static $parentcache;
     if (!isset($parentcache)) {
         $parentcache = array();
     }
     $mylang = current_language();
     if (!array_key_exists($mylang, $parentcache)) {
         $parentlang = get_parent_language($mylang);
         $parentcache[$mylang] = $parentlang;
     } else {
         $parentlang = $parentcache[$mylang];
     }
     $blocklang = trim(core_text::strtolower($langblock[1]));
     $blocktext = $langblock[2];
     if ($mylang === $blocklang || $parentlang === $blocklang) {
         return $blocktext;
     }
     return '';
 }
Example #28
0
function wiki_ewiki_2_html($oldentry, $oldpage, $oldwiki)
{
    global $CFG, $wiki_entry, $moodle_disable_camel_case, $ewiki_plugins, $ewiki_config, $moodle_format;
    $wiki_entry = $oldentry;
    $moodle_disable_camel_case = $oldwiki->disablecamelcase == 1;
    // Block of dinamic ewiki defines
    wiki_set_define("EWIKI_NAME", $wiki_entry->pagename);
    wiki_set_define("EWIKI_DEFAULT_LANG", current_language());
    if ($moodle_disable_camel_case) {
        wiki_set_define("EWIKI_CHARS_L", "");
        wiki_set_define("EWIKI_CHARS_U", "");
    } else {
        wiki_set_define("EWIKI_CHARS_L", "a-z_µ¤\$ß-ÿ");
        wiki_set_define("EWIKI_CHARS_U", "A-Z0-9À-Þ");
    }
    wiki_set_define("EWIKI_CHARS", wiki_get_define('EWIKI_CHARS_L') . wiki_get_define('EWIKI_CHARS_U'));
    require_once $CFG->dirroot . '/mod/wiki/db/migration/wiki/ewikimoodlelib.php';
    require_once $CFG->dirroot . '/mod/wiki/db/migration/wiki/ewiki/ewiki.php';
    if ($oldwiki->htmlmode == 0) {
        # No HTML
        $ewiki_config["htmlentities"] = array();
        // HTML is managed by moodle
        $moodle_format = FORMAT_TEXT;
    }
    if ($oldwiki->htmlmode == 1) {
        # Safe HTML
        include_once $CFG->dirroot . "/mod/wiki/db/migration/wiki/ewiki/plugins/moodle/moodle_rescue_html.php";
        $moodle_format = FORMAT_HTML;
    }
    if ($oldwiki->htmlmode == 2) {
        # HTML Only
        $moodle_format = FORMAT_HTML;
        $ewiki_use_editor = 1;
        $ewiki_config["htmlentities"] = array();
        // HTML is allowed
        $ewiki_config["wiki_link_regex"] = " [!~]?(\n                    \\#?\\[[^<>\\[\\]\n]+\\] |\n                    \\^[-" . wiki_get_define('EWIKI_CHARS_U') . wiki_get_define('EWIKI_CHARS_L') . "]{3,} |\n                    \\b([\\w]{3,}:)*([" . wiki_get_define('EWIKI_CHARS_U') . "]+[" . wiki_get_define('EWIKI_CHARS_L') . "]+){2,}\\#?[\\w\\d]* |\n                    \\w[-_.+\\w]+@(\\w[-_\\w]+[.])+\\w{2,}   ) x";
    }
    $content = ewiki_format($oldpage->content);
    return format_text($content, $moodle_format);
}
 /**
  * Sets the parameters property of the extended class
  *
  * @param    USER  global object
  * @param    CFG   global object
  */
 function set_parameters()
 {
     global $USER, $CFG;
     $site = get_site();
     $littlecfg = new object();
     // to avoid some notices later
     $littlecfg->wwwroot = $CFG->wwwroot;
     $courseparameters = array('label3' => array('langstr' => get_string('course'), 'value' => 'optgroup'), 'courseid' => array('langstr' => 'id', 'value' => $this->course->id), 'coursefullname' => array('langstr' => get_string('fullnamecourse'), 'value' => $this->course->fullname), 'courseshortname' => array('langstr' => get_string('shortnamecourse'), 'value' => $this->course->shortname), 'courseidnumber' => array('langstr' => get_string('idnumbercourse'), 'value' => $this->course->idnumber), 'coursesummary' => array('langstr' => get_string('summary'), 'value' => $this->course->summary), 'courseformat' => array('langstr' => get_string('format'), 'value' => $this->course->format));
     $roles = get_all_roles();
     $coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id);
     $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS);
     foreach ($roles as $role) {
         $courseparameters['course' . $role->shortname] = array('langstr' => get_string('yourwordforx', '', $role->name), 'value' => $role->localname);
     }
     $courseparameters['label4'] = array('langstr' => '', 'value' => '/optgroup');
     $miscparameters = array('label5' => array('langstr' => get_string('miscellaneous'), 'value' => 'optgroup'), 'lang' => array('langstr' => get_string('preferredlanguage'), 'value' => current_language()), 'sitename' => array('langstr' => get_string('fullsitename'), 'value' => format_string($site->fullname)), 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $littlecfg), 'value' => $littlecfg->wwwroot), 'currenttime' => array('langstr' => get_string('time'), 'value' => time()), 'encryptedcode' => array('langstr' => get_string('encryptedcode'), 'value' => $this->set_encrypted_parameter()), 'label6' => array('langstr' => "", 'value' => '/optgroup'));
     $userparameters = array();
     if (!empty($USER->id)) {
         $userparameters = array('label1' => array('langstr' => get_string('user'), 'value' => 'optgroup'), 'userid' => array('langstr' => 'id', 'value' => $USER->id), 'userusername' => array('langstr' => get_string('username'), 'value' => $USER->username), 'useridnumber' => array('langstr' => get_string('idnumber'), 'value' => $USER->idnumber), 'userfirstname' => array('langstr' => get_string('firstname'), 'value' => $USER->firstname), 'userlastname' => array('langstr' => get_string('lastname'), 'value' => $USER->lastname), 'userfullname' => array('langstr' => get_string('fullnameuser'), 'value' => fullname($USER)), 'useremail' => array('langstr' => get_string('email'), 'value' => $USER->email), 'usericq' => array('langstr' => get_string('icqnumber'), 'value' => $USER->icq), 'userphone1' => array('langstr' => get_string('phone') . ' 1', 'value' => $USER->phone1), 'userphone2' => array('langstr' => get_string('phone2') . ' 2', 'value' => $USER->phone2), 'userinstitution' => array('langstr' => get_string('institution'), 'value' => $USER->institution), 'userdepartment' => array('langstr' => get_string('department'), 'value' => $USER->department), 'useraddress' => array('langstr' => get_string('address'), 'value' => $USER->address), 'usercity' => array('langstr' => get_string('city'), 'value' => $USER->city), 'usertimezone' => array('langstr' => get_string('timezone'), 'value' => get_user_timezone_offset()), 'userurl' => array('langstr' => get_string('webpage'), 'value' => $USER->url), 'label2' => array('langstr' => "", 'value' => '/optgroup'));
     }
     $this->parameters = array_merge($userparameters, $courseparameters, $miscparameters);
 }
Example #30
0
function populate($user, $context, $tool) {
    global $CFG;
    $user->firstname = optional_param('lis_person_name_given', '', PARAM_TEXT);
    $user->lastname = optional_param('lis_person_name_family', '', PARAM_TEXT);
    $user->email = clean_param($context->getUserEmail(), PARAM_EMAIL);
    $user->city = $tool->city;
    $user->country = $tool->country;
    $user->institution = $tool->institution;
    $user->timezone = $tool->timezone;
    $user->maildisplay = $tool->maildisplay;
    $user->mnethostid = $CFG->mnet_localhost_id;
    $user->confirmed = 1;

    $user->lang = $tool->lang;
    if (!$user->lang and isset($_POST['launch_presentation_locale'])) {
        $user->lang = optional_param('launch_presentation_locale', '', PARAM_LANG);
    }
    if (!$user->lang) {
        // TODO: This should be changed for detect the course lang
        $user->lang = current_language();
    }
}