From f8311defeb8c102dd7eeabef341464383feef259 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 21 Jan 2012 13:28:20 +0100 Subject: [PATCH] MDL-31301 use static textlib methods --- admin/roles/lib.php | 2 +- admin/tool/uploaduser/locallib.php | 14 ++-- admin/tool/uploaduser/user_form.php | 3 +- auth/cas/auth.php | 3 +- auth/ldap/auth.php | 52 ++++++--------- backup/converter/moodle1/handlerlib.php | 3 +- backup/converter/moodle1/lib.php | 6 +- blocks/navigation/block_navigation.php | 49 ++++++-------- blocks/rss_client/block_rss_client.php | 7 +- blog/lib.php | 9 +-- course/lib.php | 9 +-- enrol/database/lib.php | 4 +- enrol/guest/locallib.php | 3 +- enrol/ldap/lib.php | 3 +- enrol/self/locallib.php | 3 +- grade/edit/scale/edit_form.php | 3 +- grade/import/csv/index.php | 5 +- grade/import/grade_import_form.php | 3 +- group/group_form.php | 4 +- group/grouping_form.php | 4 +- iplookup/lib.php | 4 +- lib/adminlib.php | 79 ++++++++--------------- lib/csvlib.class.php | 6 +- lib/datalib.php | 9 ++- lib/dml/mysqli_native_moodle_database.php | 3 +- lib/excellib.class.php | 9 +-- lib/filestorage/file_archive.php | 13 ++-- lib/filestorage/file_storage.php | 4 +- lib/graphlib.php | 6 +- lib/html2text.php | 3 +- lib/html2text_readme.txt | 3 +- lib/moodlelib.php | 38 ++++------- lib/navigationlib.php | 10 ++- lib/phpmailer/moodle_phpmailer.php | 3 +- lib/simpletest/testmoodlelib.php | 12 ++-- lib/simpletest/testweblib.php | 5 +- lib/tokeniserlib.php | 21 ++---- lib/weblib.php | 7 +- login/forgot_password.php | 2 +- message/lib.php | 5 +- mod/data/import_form.php | 3 +- mod/data/view.php | 3 +- mod/feedback/import.php | 3 +- mod/glossary/print.php | 11 ++-- mod/glossary/sql.php | 19 +++--- mod/glossary/view.php | 11 ++-- mod/label/lib.php | 6 +- mod/lti/locallib.php | 10 +-- report/completion/index.php | 6 +- report/progress/index.php | 6 +- tag/coursetagslib.php | 3 +- tag/lib.php | 3 +- tag/locallib.php | 5 +- 53 files changed, 191 insertions(+), 329 deletions(-) diff --git a/admin/roles/lib.php b/admin/roles/lib.php index d2dbaba6563..65ad776ec72 100644 --- a/admin/roles/lib.php +++ b/admin/roles/lib.php @@ -610,7 +610,7 @@ class define_role_table_advanced extends capability_table_with_risks { $shortname = optional_param('shortname', null, PARAM_RAW); if (!is_null($shortname)) { $this->role->shortname = $shortname; - $this->role->shortname = textlib_get_instance()->specialtoascii($this->role->shortname); + $this->role->shortname = textlib::specialtoascii($this->role->shortname); $this->role->shortname = moodle_strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT)); if (empty($this->role->shortname)) { $this->errors['shortname'] = get_string('errorbadroleshortname', 'role'); diff --git a/admin/tool/uploaduser/locallib.php b/admin/tool/uploaduser/locallib.php index 83b648c9b32..b46f97291a6 100644 --- a/admin/tool/uploaduser/locallib.php +++ b/admin/tool/uploaduser/locallib.php @@ -179,13 +179,11 @@ function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $pr print_error('csvfewcolumns', 'error', $returnurl); } - $textlib = textlib_get_instance(); // profile fields may contain unicode chars - // test columns $processed = array(); foreach ($columns as $key=>$unused) { $field = $columns[$key]; - $lcfield = $textlib->strtolower($field); + $lcfield = textlib::strtolower($field); if (in_array($field, $stdfields) or in_array($lcfield, $stdfields)) { // standard fields are only lowercase $newfield = $lcfield; @@ -281,8 +279,6 @@ function uu_process_template($template, $user) { * Internal callback function. */ function uu_process_template_callback($username, $firstname, $lastname, $block) { - $textlib = textlib_get_instance(); - switch ($block[3]) { case 'u': $repl = $username; @@ -299,18 +295,18 @@ function uu_process_template_callback($username, $firstname, $lastname, $block) switch ($block[1]) { case '+': - $repl = $textlib->strtoupper($repl); + $repl = textlib::strtoupper($repl); break; case '-': - $repl = $textlib->strtolower($repl); + $repl = textlib::strtolower($repl); break; case '~': - $repl = $textlib->strtotitle($repl); + $repl = textlib::strtotitle($repl); break; } if (!empty($block[2])) { - $repl = $textlib->substr($repl, 0 , $block[2]); + $repl = textlib::substr($repl, 0 , $block[2]); } return $repl; diff --git a/admin/tool/uploaduser/user_form.php b/admin/tool/uploaduser/user_form.php index 33b11193508..7fb74b0641b 100644 --- a/admin/tool/uploaduser/user_form.php +++ b/admin/tool/uploaduser/user_form.php @@ -53,8 +53,7 @@ class admin_uploaduser_form1 extends moodleform { $mform->setDefault('delimiter_name', 'comma'); } - $textlib = textlib_get_instance(); - $choices = $textlib->get_encodings(); + $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); diff --git a/auth/cas/auth.php b/auth/cas/auth.php index d66bdb80297..41d4dcc2785 100644 --- a/auth/cas/auth.php +++ b/auth/cas/auth.php @@ -364,8 +364,7 @@ class auth_plugin_cas extends auth_plugin_ldap { return false; } - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($username, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding); // Test for group creator if (!empty($this->config->groupecreators)) { diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index 9f88bbd43bd..07a1b18c29a 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -133,9 +133,8 @@ class auth_plugin_ldap extends auth_plugin_base { return false; } - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($username, 'utf-8', $this->config->ldapencoding); - $extpassword = $textlib->convert($password, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding); + $extpassword = textlib::convert($password, 'utf-8', $this->config->ldapencoding); // Before we connect to LDAP, check if this is an AD SSO login // if we succeed in this block, we'll return success early. @@ -199,8 +198,7 @@ class auth_plugin_ldap extends auth_plugin_base { * @return mixed array with no magic quotes or false on error */ function get_userinfo($username) { - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($username, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding); $ldapconnection = $this->ldap_connect(); if(!($user_dn = $this->ldap_find_userdn($ldapconnection, $extusername))) { @@ -245,9 +243,9 @@ class auth_plugin_ldap extends auth_plugin_base { continue; // wrong data mapping! } if (is_array($entry[$value])) { - $newval = $textlib->convert($entry[$value][0], $this->config->ldapencoding, 'utf-8'); + $newval = textlib::convert($entry[$value][0], $this->config->ldapencoding, 'utf-8'); } else { - $newval = $textlib->convert($entry[$value], $this->config->ldapencoding, 'utf-8'); + $newval = textlib::convert($entry[$value], $this->config->ldapencoding, 'utf-8'); } if (!empty($newval)) { // favour ldap entries that are set $ldapval = $newval; @@ -298,8 +296,7 @@ class auth_plugin_ldap extends auth_plugin_base { * @param string $username */ function user_exists($username) { - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($username, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding); // Returns true if given username exists on ldap $users = $this->ldap_get_userlist('('.$this->config->user_attribute.'='.ldap_filter_addslashes($extusername).')'); @@ -315,9 +312,8 @@ class auth_plugin_ldap extends auth_plugin_base { * @param mixed $plainpass Plaintext password */ function user_create($userobject, $plainpass) { - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($userobject->username, 'utf-8', $this->config->ldapencoding); - $extpassword = $textlib->convert($plainpass, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($userobject->username, 'utf-8', $this->config->ldapencoding); + $extpassword = textlib::convert($plainpass, 'utf-8', $this->config->ldapencoding); switch ($this->config->passtype) { case 'md5': @@ -342,7 +338,7 @@ class auth_plugin_ldap extends auth_plugin_base { } foreach ($values as $value) { if (!empty($userobject->$key) ) { - $newuser[$value] = $textlib->convert($userobject->$key, 'utf-8', $this->config->ldapencoding); + $newuser[$value] = textlib::convert($userobject->$key, 'utf-8', $this->config->ldapencoding); } } } @@ -570,8 +566,7 @@ class auth_plugin_ldap extends auth_plugin_base { function password_expire($username) { $result = 0; - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($username, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding); $ldapconnection = $this->ldap_connect(); $user_dn = $this->ldap_find_userdn($ldapconnection, $extusername); @@ -616,7 +611,6 @@ class auth_plugin_ldap extends auth_plugin_base { print_string('connectingldap', 'auth_ldap'); $ldapconnection = $this->ldap_connect(); - $textlib = textlib_get_instance(); $dbman = $DB->get_manager(); /// Define table user to be created @@ -667,7 +661,7 @@ class auth_plugin_ldap extends auth_plugin_base { if ($entry = @ldap_first_entry($ldapconnection, $ldap_result)) { do { $value = ldap_get_values_len($ldapconnection, $entry, $this->config->user_attribute); - $value = $textlib->convert($value[0], $this->config->ldapencoding, 'utf-8'); + $value = textlib::convert($value[0], $this->config->ldapencoding, 'utf-8'); $this->ldap_bulk_insert($value); } while ($entry = ldap_next_entry($ldapconnection, $entry)); } @@ -947,8 +941,7 @@ class auth_plugin_ldap extends auth_plugin_base { * @return boolean result */ function user_activate($username) { - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($username, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding); $ldapconnection = $this->ldap_connect(); @@ -998,8 +991,7 @@ class auth_plugin_ldap extends auth_plugin_base { return null; } - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($username, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding); $ldapconnection = $this->ldap_connect(); @@ -1057,8 +1049,7 @@ class auth_plugin_ldap extends auth_plugin_base { return true; } - $textlib = textlib_get_instance(); - $extoldusername = $textlib->convert($olduser->username, 'utf-8', $this->config->ldapencoding); + $extoldusername = textlib::convert($olduser->username, 'utf-8', $this->config->ldapencoding); $ldapconnection = $this->ldap_connect(); @@ -1112,9 +1103,9 @@ class auth_plugin_ldap extends auth_plugin_base { $ambiguous = false; } - $nuvalue = $textlib->convert($newuser->$key, 'utf-8', $this->config->ldapencoding); + $nuvalue = textlib::convert($newuser->$key, 'utf-8', $this->config->ldapencoding); empty($nuvalue) ? $nuvalue = array() : $nuvalue; - $ouvalue = $textlib->convert($olduser->$key, 'utf-8', $this->config->ldapencoding); + $ouvalue = textlib::convert($olduser->$key, 'utf-8', $this->config->ldapencoding); foreach ($ldapkeys as $ldapkey) { $ldapkey = $ldapkey; @@ -1210,9 +1201,8 @@ class auth_plugin_ldap extends auth_plugin_base { $result = false; $username = $user->username; - $textlib = textlib_get_instance(); - $extusername = $textlib->convert($username, 'utf-8', $this->config->ldapencoding); - $extpassword = $textlib->convert($newpassword, 'utf-8', $this->config->ldapencoding); + $extusername = textlib::convert($username, 'utf-8', $this->config->ldapencoding); + $extpassword = textlib::convert($newpassword, 'utf-8', $this->config->ldapencoding); switch ($this->config->passtype) { case 'md5': @@ -1435,9 +1425,8 @@ class auth_plugin_ldap extends auth_plugin_base { $users = ldap_get_entries_moodle($ldapconnection, $ldap_result); // Add found users to list - $textlib = textlib_get_instance(); for ($i = 0; $i < count($users); $i++) { - $extuser = $textlib->convert($users[$i][$this->config->user_attribute][0], + $extuser = textlib::convert($users[$i][$this->config->user_attribute][0], $this->config->ldapencoding, 'utf-8'); array_push($fresult, $extuser); } @@ -1575,8 +1564,7 @@ class auth_plugin_ldap extends auth_plugin_base { // (according to my reading of RFC-1945, RFC-2616 and RFC-2617 and // my local tests), so we need to convert the REMOTE_USER value // (i.e., what we got from the HTTP WWW-Authenticate header) into UTF-8 - $textlib = textlib_get_instance(); - $username = $textlib->convert($_SERVER['REMOTE_USER'], 'iso-8859-1', 'utf-8'); + $username = textlib::convert($_SERVER['REMOTE_USER'], 'iso-8859-1', 'utf-8'); switch ($this->config->ntlmsso_type) { case 'ntlm': diff --git a/backup/converter/moodle1/handlerlib.php b/backup/converter/moodle1/handlerlib.php index f0c97541ca9..3faa5571b7a 100644 --- a/backup/converter/moodle1/handlerlib.php +++ b/backup/converter/moodle1/handlerlib.php @@ -1190,8 +1190,7 @@ class moodle1_question_bank_handler extends moodle1_xml_handler { // replay the upgrade step 2010080901 - updating question image if (!empty($data['image'])) { - $textlib = textlib_get_instance(); - if ($textlib->substr($textlib->strtolower($data['image']), 0, 7) == 'http://') { + if (textlib::substr(textlib::strtolower($data['image']), 0, 7) == 'http://') { // it is a link, appending to existing question text $data['questiontext'] .= ' '; diff --git a/backup/converter/moodle1/lib.php b/backup/converter/moodle1/lib.php index 86e2026b579..e79dbfea350 100644 --- a/backup/converter/moodle1/lib.php +++ b/backup/converter/moodle1/lib.php @@ -1161,9 +1161,6 @@ class moodle1_file_manager implements loggable { /** @var string the root of the converter temp directory */ protected $basepath; - /** @var textlib instance used during the migration */ - protected $textlib; - /** @var array of file ids that were migrated by this instance */ protected $fileids = array(); @@ -1187,7 +1184,6 @@ class moodle1_file_manager implements loggable { $this->userid = $userid; // set other useful bits $this->basepath = $converter->get_tempdir_path(); - $this->textlib = textlib_get_instance(); } /** @@ -1218,7 +1214,7 @@ class moodle1_file_manager implements loggable { } $filepath = clean_param($filepath, PARAM_PATH); - if ($this->textlib->strlen($filepath) > 255) { + if (textlib::strlen($filepath) > 255) { throw new moodle1_convert_exception('file_path_longer_than_255_chars'); } diff --git a/blocks/navigation/block_navigation.php b/blocks/navigation/block_navigation.php index 2d035182651..d5610c06199 100644 --- a/blocks/navigation/block_navigation.php +++ b/blocks/navigation/block_navigation.php @@ -242,81 +242,74 @@ class block_navigation extends block_base { * @param int $long The length to trim text to * @param int $short The length to trim shorttext to * @param bool $recurse Recurse all children - * @param textlib|null $textlib */ - public function trim(navigation_node $node, $mode=1, $long=50, $short=25, $recurse=true, $textlib=null) { - if ($textlib == null) { - $textlib = textlib_get_instance(); - } + public function trim(navigation_node $node, $mode=1, $long=50, $short=25, $recurse=true) { switch ($mode) { case self::TRIM_RIGHT : - if ($textlib->strlen($node->text)>($long+3)) { + if (textlib::strlen($node->text)>($long+3)) { // Truncate the text to $long characters - $node->text = $this->trim_right($textlib, $node->text, $long); + $node->text = $this->trim_right($node->text, $long); } - if (is_string($node->shorttext) && $textlib->strlen($node->shorttext)>($short+3)) { + if (is_string($node->shorttext) && textlib::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext - $node->shorttext = $this->trim_right($textlib, $node->shorttext, $short); + $node->shorttext = $this->trim_right($node->shorttext, $short); } break; case self::TRIM_LEFT : - if ($textlib->strlen($node->text)>($long+3)) { + if (textlib::strlen($node->text)>($long+3)) { // Truncate the text to $long characters - $node->text = $this->trim_left($textlib, $node->text, $long); + $node->text = $this->trim_left($node->text, $long); } - if (is_string($node->shorttext) && $textlib->strlen($node->shorttext)>($short+3)) { + if (is_string($node->shorttext) && textlib::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext - $node->shorttext = $this->trim_left($textlib, $node->shorttext, $short); + $node->shorttext = $this->trim_left($node->shorttext, $short); } break; case self::TRIM_CENTER : - if ($textlib->strlen($node->text)>($long+3)) { + if (textlib::strlen($node->text)>($long+3)) { // Truncate the text to $long characters - $node->text = $this->trim_center($textlib, $node->text, $long); + $node->text = $this->trim_center($node->text, $long); } - if (is_string($node->shorttext) && $textlib->strlen($node->shorttext)>($short+3)) { + if (is_string($node->shorttext) && textlib::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext - $node->shorttext = $this->trim_center($textlib, $node->shorttext, $short); + $node->shorttext = $this->trim_center($node->shorttext, $short); } break; } if ($recurse && $node->children->count()) { foreach ($node->children as &$child) { - $this->trim($child, $mode, $long, $short, true, $textlib); + $this->trim($child, $mode, $long, $short, true); } } } /** * Truncate a string from the left - * @param textlib $textlib * @param string $string The string to truncate * @param int $length The length to truncate to * @return string The truncated string */ - protected function trim_left($textlib, $string, $length) { - return '...'.$textlib->substr($string, $textlib->strlen($string)-$length, $length); + protected function trim_left($string, $length) { + return '...'.textlib::substr($string, textlib::strlen($string)-$length, $length); } /** * Truncate a string from the right - * @param textlib $textlib * @param string $string The string to truncate * @param int $length The length to truncate to * @return string The truncated string */ - protected function trim_right($textlib, $string, $length) { - return $textlib->substr($string, 0, $length).'...'; + protected function trim_right($string, $length) { + return textlib::substr($string, 0, $length).'...'; } /** * Truncate a string in the center - * @param textlib $textlib * @param string $string The string to truncate * @param int $length The length to truncate to * @return string The truncated string */ - protected function trim_center($textlib, $string, $length) { + protected function trim_center($string, $length) { $trimlength = ceil($length/2); - $start = $textlib->substr($string, 0, $trimlength); - $end = $textlib->substr($string, $textlib->strlen($string)-$trimlength); + $start = textlib::substr($string, 0, $trimlength); + $end = textlib::substr($string, textlib::strlen($string)-$trimlength); $string = $start.'...'.$end; return $string; } diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index a3aa5114f7b..086983d1792 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -267,13 +267,10 @@ */ function format_title($title,$max=64) { - // Loading the textlib singleton instance. We are going to need it. - $textlib = textlib_get_instance(); - - if ($textlib->strlen($title) <= $max) { + if (textlib::strlen($title) <= $max) { return s($title); } else { - return s($textlib->substr($title,0,$max-3).'...'); + return s(textlib::substr($title,0,$max-3).'...'); } } diff --git a/blog/lib.php b/blog/lib.php index 080df708c88..ab9fd52fb85 100644 --- a/blog/lib.php +++ b/blog/lib.php @@ -150,8 +150,6 @@ function blog_sync_external_entries($externalblog) { $rssfile = new moodle_simplepie_file($externalblog->url); $filetest = new SimplePie_Locator($rssfile); - $textlib = textlib_get_instance(); // Going to use textlib services - if (!$filetest->is_feed($rssfile)) { $externalblog->failedlastsync = 1; $DB->update_record('blog_external', $externalblog); @@ -203,8 +201,8 @@ function blog_sync_external_entries($externalblog) { $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) . '...'; + if (textlib::strlen($newentry->subject) > 128) { + $newentry->subject = textlib::substr($newentry->subject, 0, 125) . '...'; } $newentry->summary = $entry->get_description(); @@ -239,8 +237,7 @@ function blog_sync_external_entries($externalblog) { $oldesttimestamp = $timestamp; } - $textlib = textlib_get_instance(); - if ($textlib->strlen($newentry->uniquehash) > 255) { + 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. diff --git a/course/lib.php b/course/lib.php index d34d9ecbeb2..91f6e9681e3 100644 --- a/course/lib.php +++ b/course/lib.php @@ -389,8 +389,7 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per // If $log->url has been trimmed short by the db size restriction // code in add_to_log, keep a note so we don't add a link to a broken url - $tl=textlib_get_instance(); - $brokenurl=($tl->strlen($log->url)==100 && $tl->substr($log->url,97)=='...'); + $brokenurl=(textlib::strlen($log->url)==100 && textlib::substr($log->url,97)=='...'); $row = array(); if ($course->id == SITEID) { @@ -1435,8 +1434,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, $initialised = true; } - $tl = textlib_get_instance(); - $modinfo = get_fast_modinfo($course); $completioninfo = new completion_info($course); @@ -1561,8 +1558,8 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, // Avoid unnecessary duplication: if e.g. a forum name already // includes the word forum (or Forum, etc) then it is unhelpful // to include that in the accessible description that is added. - if (false !== strpos($tl->strtolower($instancename), - $tl->strtolower($altname))) { + if (false !== strpos(textlib::strtolower($instancename), + textlib::strtolower($altname))) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). diff --git a/enrol/database/lib.php b/enrol/database/lib.php index 08b86f9beae..c47d54787d3 100644 --- a/enrol/database/lib.php +++ b/enrol/database/lib.php @@ -781,7 +781,7 @@ class enrol_database_plugin extends enrol_plugin { } return $text; } else { - return textlib_get_instance()->convert($text, 'utf-8', $dbenc); + return textlib::convert($text, 'utf-8', $dbenc); } } @@ -796,7 +796,7 @@ class enrol_database_plugin extends enrol_plugin { } return $text; } else { - return textlib_get_instance()->convert($text, $dbenc, 'utf-8'); + return textlib::convert($text, $dbenc, 'utf-8'); } } } diff --git a/enrol/guest/locallib.php b/enrol/guest/locallib.php index 27e1ede9be7..6182070dccc 100644 --- a/enrol/guest/locallib.php +++ b/enrol/guest/locallib.php @@ -62,8 +62,7 @@ class enrol_guest_enrol_form extends moodleform { if ($data['guestpassword'] !== $instance->password) { $plugin = enrol_get_plugin('guest'); if ($plugin->get_config('showhint')) { - $textlib = textlib_get_instance(); - $hint = $textlib->substr($instance->password, 0, 1); + $hint = textlib::substr($instance->password, 0, 1); $errors['guestpassword'] = get_string('passwordinvalidhint', 'enrol_guest', $hint); } else { $errors['guestpassword'] = get_string('passwordinvalid', 'enrol_guest'); diff --git a/enrol/ldap/lib.php b/enrol/ldap/lib.php index 730ec5a8ac2..f3678bc07fe 100644 --- a/enrol/ldap/lib.php +++ b/enrol/ldap/lib.php @@ -648,8 +648,7 @@ class enrol_ldap_plugin extends enrol_plugin { return array(); } - $textlib = textlib_get_instance(); - $extmemberuid = $textlib->convert($memberuid, 'utf-8', $this->get_config('ldapencoding')); + $extmemberuid = textlib::convert($memberuid, 'utf-8', $this->get_config('ldapencoding')); if($this->get_config('memberattribute_isdn')) { if (!($extmemberuid = $this->ldap_find_userdn ($ldapconnection, $extmemberuid))) { diff --git a/enrol/self/locallib.php b/enrol/self/locallib.php index 17423397e99..86adfbf819d 100644 --- a/enrol/self/locallib.php +++ b/enrol/self/locallib.php @@ -116,8 +116,7 @@ class enrol_self_enrol_form extends moodleform { } else { $plugin = enrol_get_plugin('self'); if ($plugin->get_config('showhint')) { - $textlib = textlib_get_instance(); - $hint = $textlib->substr($instance->password, 0, 1); + $hint = textlib::substr($instance->password, 0, 1); $errors['enrolpassword'] = get_string('passwordinvalidhint', 'enrol_self', $hint); } else { $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self'); diff --git a/grade/edit/scale/edit_form.php b/grade/edit/scale/edit_form.php index c6091b564c6..ccb7ab1d352 100644 --- a/grade/edit/scale/edit_form.php +++ b/grade/edit/scale/edit_form.php @@ -140,9 +140,8 @@ class edit_scale_form extends moodleform { } else { $thescale = implode(',',$scalearray); - $textlib = textlib_get_instance(); //this check strips out whitespace from the scale we're validating but not from those already in the DB - $count = $DB->count_records_select('scale', "courseid=:courseid AND ".$DB->sql_compare_text('scale', $textlib->strlen($thescale)).'=:scale', + $count = $DB->count_records_select('scale', "courseid=:courseid AND ".$DB->sql_compare_text('scale', textlib::strlen($thescale)).'=:scale', array('courseid'=>$courseid, 'scale'=>$thescale)); if ($count) { diff --git a/grade/import/csv/index.php b/grade/import/csv/index.php index 886bf4303d0..11ae292f7c4 100644 --- a/grade/import/csv/index.php +++ b/grade/import/csv/index.php @@ -116,10 +116,9 @@ if ($formdata = $mform->get_data()) { $text = $mform->get_file_content('userfile'); // trim utf-8 bom - $textlib = textlib_get_instance(); /// normalize line endings and do the encoding conversion - $text = $textlib->convert($text, $formdata->encoding); - $text = $textlib->trim_utf8_bom($text); + $text = textlib::convert($text, $formdata->encoding); + $text = textlib::trim_utf8_bom($text); // Fix mac/dos newlines $text = preg_replace('!\r\n?!',"\n",$text); $fp = fopen($filename, "w"); diff --git a/grade/import/grade_import_form.php b/grade/import/grade_import_form.php index 84629f86788..6021f60a297 100644 --- a/grade/import/grade_import_form.php +++ b/grade/import/grade_import_form.php @@ -41,8 +41,7 @@ class grade_import_form extends moodleform { // file upload $mform->addElement('filepicker', 'userfile', get_string('file')); $mform->addRule('userfile', null, 'required'); - $textlib = textlib_get_instance(); - $encodings = $textlib->get_encodings(); + $encodings = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings); if (!empty($features['includeseparator'])) { diff --git a/group/group_form.php b/group/group_form.php index 15639491787..37044effcb3 100644 --- a/group/group_form.php +++ b/group/group_form.php @@ -85,11 +85,9 @@ class group_form extends moodleform { $errors = parent::validation($data, $files); - $textlib = textlib_get_instance(); - $name = trim($data['name']); if ($data['id'] and $group = $DB->get_record('groups', array('id'=>$data['id']))) { - if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) { + if (textlib::strtolower($group->name) != textlib::strtolower($name)) { if (groups_get_group_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupnameexists', 'group', $name); } diff --git a/group/grouping_form.php b/group/grouping_form.php index f438882dc34..258234e7ffb 100644 --- a/group/grouping_form.php +++ b/group/grouping_form.php @@ -75,11 +75,9 @@ class grouping_form extends moodleform { $errors = parent::validation($data, $files); - $textlib = textlib_get_instance(); - $name = trim($data['name']); if ($data['id'] and $grouping = $DB->get_record('groupings', array('id'=>$data['id']))) { - if ($textlib->strtolower($grouping->name) != $textlib->strtolower($name)) { + if (textlib::strtolower($grouping->name) != textlib::strtolower($name)) { if (groups_get_grouping_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupingnameexists', 'group', $name); } diff --git a/iplookup/lib.php b/iplookup/lib.php index 920f55551f0..44a2c80c52e 100644 --- a/iplookup/lib.php +++ b/iplookup/lib.php @@ -39,8 +39,6 @@ function iplookup_find_location($ip) { if (!empty($CFG->geoipfile) and file_exists($CFG->geoipfile)) { require_once('Net/GeoIP.php'); - $textlib = textlib_get_instance(); - $geoip = Net_GeoIP::getInstance($CFG->geoipfile, Net_GeoIP::STANDARD); $location = $geoip->lookupLocation($ip); $geoip->close(); @@ -50,7 +48,7 @@ function iplookup_find_location($ip) { return $info; } if (!empty($location->city)) { - $info['city'] = $textlib->convert($location->city, 'iso-8859-1', 'utf-8'); + $info['city'] = textlib::convert($location->city, 'iso-8859-1', 'utf-8'); $info['title'][] = $info['city']; } diff --git a/lib/adminlib.php b/lib/adminlib.php index 4025f91700f..ce5af0d7df0 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1137,12 +1137,10 @@ class admin_externalpage implements part_of_admin_tree { * @return mixed array-object structure of found settings and pages */ public function search($query) { - $textlib = textlib_get_instance(); - $found = false; if (strpos(strtolower($this->name), $query) !== false) { $found = true; - } else if (strpos($textlib->strtolower($this->visiblename), $query) !== false) { + } else if (strpos(textlib::strtolower($this->visiblename), $query) !== false) { $found = true; } if ($found) { @@ -1286,12 +1284,10 @@ class admin_settingpage implements part_of_admin_tree { return array($this->name => $result); } - $textlib = textlib_get_instance(); - $found = false; if (strpos(strtolower($this->name), $query) !== false) { $found = true; - } else if (strpos($textlib->strtolower($this->visiblename), $query) !== false) { + } else if (strpos(textlib::strtolower($this->visiblename), $query) !== false) { $found = true; } if ($found) { @@ -1613,17 +1609,16 @@ abstract class admin_setting { if (strpos(strtolower($this->name), $query) !== false) { return true; } - $textlib = textlib_get_instance(); - if (strpos($textlib->strtolower($this->visiblename), $query) !== false) { + if (strpos(textlib::strtolower($this->visiblename), $query) !== false) { return true; } - if (strpos($textlib->strtolower($this->description), $query) !== false) { + if (strpos(textlib::strtolower($this->description), $query) !== false) { return true; } $current = $this->get_setting(); if (!is_null($current)) { if (is_string($current)) { - if (strpos($textlib->strtolower($current), $query) !== false) { + if (strpos(textlib::strtolower($current), $query) !== false) { return true; } } @@ -1631,7 +1626,7 @@ abstract class admin_setting { $default = $this->get_defaultsetting(); if (!is_null($default)) { if (is_string($default)) { - if (strpos($textlib->strtolower($default), $query) !== false) { + if (strpos(textlib::strtolower($default), $query) !== false) { return true; } } @@ -2210,9 +2205,8 @@ class admin_setting_configmulticheckbox extends admin_setting { return true; } - $textlib = textlib_get_instance(); foreach ($this->choices as $desc) { - if (strpos($textlib->strtolower($desc), $query) !== false) { + if (strpos(textlib::strtolower($desc), $query) !== false) { return true; } } @@ -2440,12 +2434,11 @@ class admin_setting_configselect extends admin_setting { if (!$this->load_choices()) { return false; } - $textlib = textlib_get_instance(); foreach ($this->choices as $key=>$value) { - if (strpos($textlib->strtolower($key), $query) !== false) { + if (strpos(textlib::strtolower($key), $query) !== false) { return true; } - if (strpos($textlib->strtolower($value), $query) !== false) { + if (strpos(textlib::strtolower($value), $query) !== false) { return true; } } @@ -2624,9 +2617,8 @@ class admin_setting_configmultiselect extends admin_setting_configselect { return true; } - $textlib = textlib_get_instance(); foreach ($this->choices as $desc) { - if (strpos($textlib->strtolower($desc), $query) !== false) { + if (strpos(textlib::strtolower($desc), $query) !== false) { return true; } } @@ -4716,7 +4708,6 @@ class admin_page_managemods extends admin_externalpage { $found = false; if ($modules = $DB->get_records('modules')) { - $textlib = textlib_get_instance(); foreach ($modules as $module) { if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) { continue; @@ -4726,7 +4717,7 @@ class admin_page_managemods extends admin_externalpage { break; } $strmodulename = get_string('modulename', $module->name); - if (strpos($textlib->strtolower($strmodulename), $query) !== false) { + if (strpos(textlib::strtolower($strmodulename), $query) !== false) { $found = true; break; } @@ -4798,15 +4789,14 @@ class admin_setting_manageenrols extends admin_setting { return true; } - $textlib = textlib_get_instance(); - $query = $textlib->strtolower($query); + $query = textlib::strtolower($query); $enrols = enrol_get_plugins(false); foreach ($enrols as $name=>$enrol) { $localised = get_string('pluginname', 'enrol_'.$name); - if (strpos($textlib->strtolower($name), $query) !== false) { + if (strpos(textlib::strtolower($name), $query) !== false) { return true; } - if (strpos($textlib->strtolower($localised), $query) !== false) { + if (strpos(textlib::strtolower($localised), $query) !== false) { return true; } } @@ -4969,7 +4959,6 @@ class admin_page_manageblocks extends admin_externalpage { $found = false; if ($blocks = $DB->get_records('block')) { - $textlib = textlib_get_instance(); foreach ($blocks as $block) { if (!file_exists("$CFG->dirroot/blocks/$block->name/")) { continue; @@ -4979,7 +4968,7 @@ class admin_page_manageblocks extends admin_externalpage { break; } $strblockname = get_string('pluginname', 'block_'.$block->name); - if (strpos($textlib->strtolower($strblockname), $query) !== false) { + if (strpos(textlib::strtolower($strblockname), $query) !== false) { $found = true; break; } @@ -5024,7 +5013,6 @@ class admin_page_managemessageoutputs extends admin_externalpage { $found = false; if ($processors = get_message_processors()) { - $textlib = textlib_get_instance(); foreach ($processors as $processor) { if (!$processor->available) { continue; @@ -5034,7 +5022,7 @@ class admin_page_managemessageoutputs extends admin_externalpage { break; } $strprocessorname = get_string('pluginname', 'message_'.$processor->name); - if (strpos($textlib->strtolower($strprocessorname), $query) !== false) { + if (strpos(textlib::strtolower($strprocessorname), $query) !== false) { $found = true; break; } @@ -5096,10 +5084,9 @@ class admin_page_manageqbehaviours extends admin_externalpage { } $found = false; - $textlib = textlib_get_instance(); require_once($CFG->dirroot . '/question/engine/lib.php'); foreach (get_plugin_list('qbehaviour') as $behaviour => $notused) { - if (strpos($textlib->strtolower(question_engine::get_behaviour_name($behaviour)), + if (strpos(textlib::strtolower(question_engine::get_behaviour_name($behaviour)), $query) !== false) { $found = true; break; @@ -5144,10 +5131,9 @@ class admin_page_manageqtypes extends admin_externalpage { } $found = false; - $textlib = textlib_get_instance(); require_once($CFG->dirroot . '/question/engine/bank.php'); foreach (question_bank::get_all_qtypes() as $qtype) { - if (strpos($textlib->strtolower($qtype->local_name()), $query) !== false) { + if (strpos(textlib::strtolower($qtype->local_name()), $query) !== false) { $found = true; break; } @@ -5186,7 +5172,6 @@ class admin_page_manageportfolios extends admin_externalpage { } $found = false; - $textlib = textlib_get_instance(); $portfolios = get_plugin_list('portfolio'); foreach ($portfolios as $p => $dir) { if (strpos($p, $query) !== false) { @@ -5197,7 +5182,7 @@ class admin_page_manageportfolios extends admin_externalpage { if (!$found) { foreach (portfolio_instances(false, false) as $instance) { $title = $instance->get('name'); - if (strpos($textlib->strtolower($title), $query) !== false) { + if (strpos(textlib::strtolower($title), $query) !== false) { $found = true; break; } @@ -5238,7 +5223,6 @@ class admin_page_managerepositories extends admin_externalpage { } $found = false; - $textlib = textlib_get_instance(); $repositories= get_plugin_list('repository'); foreach ($repositories as $p => $dir) { if (strpos($p, $query) !== false) { @@ -5249,7 +5233,7 @@ class admin_page_managerepositories extends admin_externalpage { if (!$found) { foreach (repository::get_types() as $instance) { $title = $instance->get_typename(); - if (strpos($textlib->strtolower($title), $query) !== false) { + if (strpos(textlib::strtolower($title), $query) !== false) { $found = true; break; } @@ -5321,7 +5305,6 @@ class admin_setting_manageauths extends admin_setting { return true; } - $textlib = textlib_get_instance(); $authsavailable = get_plugin_list('auth'); foreach ($authsavailable as $auth => $dir) { if (strpos($auth, $query) !== false) { @@ -5329,7 +5312,7 @@ class admin_setting_manageauths extends admin_setting { } $authplugin = get_auth_plugin($auth); $authtitle = $authplugin->get_title(); - if (strpos($textlib->strtolower($authtitle), $query) !== false) { + if (strpos(textlib::strtolower($authtitle), $query) !== false) { return true; } } @@ -5524,13 +5507,12 @@ class admin_setting_manageeditors extends admin_setting { return true; } - $textlib = textlib_get_instance(); $editors_available = editors_get_available(); foreach ($editors_available as $editor=>$editorstr) { if (strpos($editor, $query) !== false) { return true; } - if (strpos($textlib->strtolower($editorstr), $query) !== false) { + if (strpos(textlib::strtolower($editorstr), $query) !== false) { return true; } } @@ -5761,9 +5743,8 @@ class admin_page_managefilters extends admin_externalpage { $found = false; $filternames = filter_get_all_installed(); - $textlib = textlib_get_instance(); foreach ($filternames as $path => $strfiltername) { - if (strpos($textlib->strtolower($strfiltername), $query) !== false) { + if (strpos(textlib::strtolower($strfiltername), $query) !== false) { $found = true; break; } @@ -6071,11 +6052,10 @@ function admin_find_write_settings($node, $data) { function admin_search_settings_html($query) { global $CFG, $OUTPUT; - $textlib = textlib_get_instance(); - if ($textlib->strlen($query) < 2) { + if (textlib::strlen($query) < 2) { return ''; } - $query = $textlib->strtolower($query); + $query = textlib::strtolower($query); $adminroot = admin_get_root(); $findings = $adminroot->search($query); @@ -6406,7 +6386,6 @@ class admin_setting_managerepository extends admin_setting { return true; } - $textlib = textlib_get_instance(); $repositories= get_plugin_list('repository'); foreach ($repositories as $p => $dir) { if (strpos($p, $query) !== false) { @@ -6415,7 +6394,7 @@ class admin_setting_managerepository extends admin_setting { } foreach (repository::get_types() as $instance) { $title = $instance->get_typename(); - if (strpos($textlib->strtolower($title), $query) !== false) { + if (strpos(textlib::strtolower($title), $query) !== false) { return true; } } @@ -6811,10 +6790,9 @@ class admin_setting_manageexternalservices extends admin_setting { return true; } - $textlib = textlib_get_instance(); $services = $DB->get_records('external_services', array(), 'id, name'); foreach ($services as $service) { - if (strpos($textlib->strtolower($service->name), $query) !== false) { + if (strpos(textlib::strtolower($service->name), $query) !== false) { return true; } } @@ -7369,14 +7347,13 @@ class admin_setting_managewebserviceprotocols extends admin_setting { return true; } - $textlib = textlib_get_instance(); $protocols = get_plugin_list('webservice'); foreach ($protocols as $protocol=>$location) { if (strpos($protocol, $query) !== false) { return true; } $protocolstr = get_string('pluginname', 'webservice_'.$protocol); - if (strpos($textlib->strtolower($protocolstr), $query) !== false) { + if (strpos(textlib::strtolower($protocolstr), $query) !== false) { return true; } } diff --git a/lib/csvlib.class.php b/lib/csvlib.class.php index 2eb9df30bf6..d88716e3953 100644 --- a/lib/csvlib.class.php +++ b/lib/csvlib.class.php @@ -84,11 +84,9 @@ class csv_import_reader { $this->close(); $this->_error = null; - $textlib = textlib_get_instance(); - - $content = $textlib->convert($content, $encoding, 'utf-8'); + $content = textlib::convert($content, $encoding, 'utf-8'); // remove Unicode BOM from first line - $content = $textlib->trim_utf8_bom($content); + $content = textlib::trim_utf8_bom($content); // Fix mac/dos newlines $content = preg_replace('!\r\n?!', "\n", $content); // is there anyting in file? diff --git a/lib/datalib.php b/lib/datalib.php index 9a8d62fc191..1eaaa546308 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1703,15 +1703,14 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user // database so that it doesn't cause a DB error. Log a warning so that // developers can avoid doing things which are likely to cause this on a // routine basis. - $tl = textlib_get_instance(); - if(!empty($info) && $tl->strlen($info)>255) { - $info = $tl->substr($info,0,252).'...'; + if(!empty($info) && textlib::strlen($info)>255) { + $info = textlib::substr($info,0,252).'...'; debugging('Warning: logged very long info',DEBUG_DEVELOPER); } // If the 100 field size is changed, also need to alter print_log in course/lib.php - if(!empty($url) && $tl->strlen($url)>100) { - $url=$tl->substr($url,0,97).'...'; + if(!empty($url) && textlib::strlen($url)>100) { + $url = textlib::substr($url,0,97).'...'; debugging('Warning: logged very long URL',DEBUG_DEVELOPER); } diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index 3f70beff41e..572e2e7c8ca 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -559,10 +559,9 @@ class mysqli_native_moodle_database extends moodle_database { $info->max_length = 0; $values = $matches[1]; $values = explode(',', $values); - $textlib = textlib_get_instance(); foreach ($values as $val) { $val = trim($val, "'"); - $length = $textlib->strlen($val); + $length = textlib::strlen($val); $info->enums[] = $val; $info->max_length = ($info->max_length < $length) ? $length : $info->max_length; } diff --git a/lib/excellib.class.php b/lib/excellib.class.php index 8b1262daa35..44315ca08d9 100644 --- a/lib/excellib.class.php +++ b/lib/excellib.class.php @@ -143,8 +143,7 @@ class MoodleExcelWorksheet { // With $latin_output = false, it does not cope at all. // With $latin_output = true it is supposed to work, but in our experience, // it doesn't. Therefore, truncate in all circumstances. - $textlib = textlib_get_instance(); - $name = $textlib->substr($name, 0, 31); + $name = textlib::substr($name, 0, 31); } /// Internally, add one sheet to the workbook @@ -167,13 +166,11 @@ class MoodleExcelWorksheet { function write_string($row, $col, $str, $format=null) { /// Calculate the internal PEAR format $format = $this->MoodleExcelFormat2PearExcelFormat($format); - /// Loading the textlib singleton instance. We are going to need it. - $textlib = textlib_get_instance(); /// Convert the text from its original encoding to UTF-16LE if (!$this->latin_output) { /// Only if don't want to use latin (win1252) stronger output - $str = $textlib->convert($str, 'utf-8', 'utf-16le'); + $str = textlib::convert($str, 'utf-8', 'utf-16le'); } else { /// else, convert to latin (win1252) - $str = $textlib->convert($str, 'utf-8', 'windows-1252'); + $str = textlib::convert($str, 'utf-8', 'windows-1252'); } /// Add the string safely to the PEAR Worksheet $this->pear_excel_worksheet->writeString($row, $col, $str, $format); diff --git a/lib/filestorage/file_archive.php b/lib/filestorage/file_archive.php index 96879680ebd..d27d2c6a6da 100644 --- a/lib/filestorage/file_archive.php +++ b/lib/filestorage/file_archive.php @@ -130,19 +130,18 @@ abstract class file_archive implements Iterator { if ($this->encoding === 'utf-8') { return $localname; } - $textlib = textlib_get_instance(); - $converted = $textlib->convert($localname, 'utf-8', $this->encoding); - $original = $textlib->convert($converted, $this->encoding, 'utf-8'); + $converted = textlib::convert($localname, 'utf-8', $this->encoding); + $original = textlib::convert($converted, $this->encoding, 'utf-8'); if ($original === $localname) { $result = $converted; } else { // try ascii conversion - $converted2 = $textlib->specialtoascii($localname); - $converted2 = $textlib->convert($converted2, 'utf-8', $this->encoding); - $original2 = $textlib->convert($converted, $this->encoding, 'utf-8'); + $converted2 = textlib::specialtoascii($localname); + $converted2 = textlib::convert($converted2, 'utf-8', $this->encoding); + $original2 = textlib::convert($converted, $this->encoding, 'utf-8'); if ($original2 === $localname) { //this looks much better @@ -176,7 +175,7 @@ abstract class file_archive implements Iterator { $result = ltrim($result, '/'); // no leading / if ($this->encoding !== 'utf-8') { - $result = textlib_get_instance()->convert($result, $this->encoding, 'utf-8'); + $result = textlib::convert($result, $this->encoding, 'utf-8'); } return clean_param($result, PARAM_PATH); diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index 502cbc4da02..a60b7c2944e 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -348,7 +348,7 @@ class file_storage { if ($recursive) { $dirs = $includedirs ? "" : "AND filename <> '.'"; - $length = textlib_get_instance()->strlen($filepath); + $length = textlib::strlen($filepath); $sql = "SELECT * FROM {files} @@ -375,7 +375,7 @@ class file_storage { $result = array(); $params = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'dirid'=>$directory->get_id()); - $length = textlib_get_instance()->strlen($filepath); + $length = textlib::strlen($filepath); if ($includedirs) { $sql = "SELECT * diff --git a/lib/graphlib.php b/lib/graphlib.php index d801378a317..c712fad514b 100644 --- a/lib/graphlib.php +++ b/lib/graphlib.php @@ -1247,8 +1247,7 @@ class graph { break; } // start of Moodle addition - $textlib = textlib_get_instance(); - $text = $textlib->utf8_to_entities($text, true, true); //does not work with hex entities! + $text = textlib::utf8_to_entities($text, true, true); //does not work with hex entities! // end of Moodle addition ImageTTFText($this->image, $points, $angle, $x, $y, $colour, $font, $text); } @@ -1353,8 +1352,7 @@ class graph { // get boundary box and offsets for printing at an angle // start of Moodle addition - $textlib = textlib_get_instance(); - $text = $textlib->utf8_to_entities($text, true, true); //gd does not work with hex entities! + $text = textlib::utf8_to_entities($text, true, true); //gd does not work with hex entities! // end of Moodle addition $bounds = ImageTTFBBox($points, $angle, $font, $text); diff --git a/lib/html2text.php b/lib/html2text.php index 0320433362a..8337f98f97d 100644 --- a/lib/html2text.php +++ b/lib/html2text.php @@ -599,7 +599,6 @@ class html2text */ function _strtoupper($str) { - $tl = textlib_get_instance(); - return $tl->strtoupper($str); + return textlib::strtoupper($str); } } diff --git a/lib/html2text_readme.txt b/lib/html2text_readme.txt index 7058045e5fc..65b5f32d5a9 100644 --- a/lib/html2text_readme.txt +++ b/lib/html2text_readme.txt @@ -47,8 +47,7 @@ Index: lib/html2text.php - return mb_strtoupper($str); - else - return strtoupper($str); -+ $tl = textlib_get_instance(); -+ return $tl->strtoupper($str); ++ return textlib::strtoupper($str); } } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 71d98685aac..57b08fe067f 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1006,8 +1006,7 @@ function clean_param($param, $type) { $param = preg_replace('~[[:cntrl:]]|[<>`]~u', '', $param); //convert many whitespace chars into one $param = preg_replace('/\s+/', ' ', $param); - $textlib = textlib_get_instance(); - $param = $textlib->substr(trim($param), 0, TAG_MAX_LENGTH); + $param = textlib::substr(trim($param), 0, TAG_MAX_LENGTH); return $param; case PARAM_TAGLIST: @@ -2032,8 +2031,7 @@ function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour if ($CFG->ostype == 'WINDOWS') { if ($localewincharset = get_string('localewincharset', 'langconfig')) { - $textlib = textlib_get_instance(); - $datestring = $textlib->convert($datestring, $localewincharset, 'utf-8'); + $datestring = textlib::convert($datestring, $localewincharset, 'utf-8'); } } @@ -3791,11 +3789,10 @@ function truncate_userinfo($info) { 'url' => 255, ); - $textlib = textlib_get_instance(); // apply where needed foreach (array_keys($info) as $key) { if (!empty($limit[$key])) { - $info[$key] = trim($textlib->substr($info[$key],0, $limit[$key])); + $info[$key] = trim(textlib::substr($info[$key],0, $limit[$key])); } } @@ -4285,9 +4282,8 @@ function check_password_policy($password, &$errmsg) { return true; } - $textlib = textlib_get_instance(); $errmsg = ''; - if ($textlib->strlen($password) < $CFG->minpasswordlength) { + if (textlib::strlen($password) < $CFG->minpasswordlength) { $errmsg .= '
'. get_string('errorminpasswordlength', 'auth', $CFG->minpasswordlength) .'
'; } @@ -5250,18 +5246,17 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a $charsets = get_list_of_charsets(); unset($charsets['UTF-8']); if (in_array($charset, $charsets)) { - $textlib = textlib_get_instance(); $mail->CharSet = $charset; - $mail->FromName = $textlib->convert($mail->FromName, 'utf-8', strtolower($charset)); - $mail->Subject = $textlib->convert($mail->Subject, 'utf-8', strtolower($charset)); - $mail->Body = $textlib->convert($mail->Body, 'utf-8', strtolower($charset)); - $mail->AltBody = $textlib->convert($mail->AltBody, 'utf-8', strtolower($charset)); + $mail->FromName = textlib::convert($mail->FromName, 'utf-8', strtolower($charset)); + $mail->Subject = textlib::convert($mail->Subject, 'utf-8', strtolower($charset)); + $mail->Body = textlib::convert($mail->Body, 'utf-8', strtolower($charset)); + $mail->AltBody = textlib::convert($mail->AltBody, 'utf-8', strtolower($charset)); foreach ($temprecipients as $key => $values) { - $temprecipients[$key][1] = $textlib->convert($values[1], 'utf-8', strtolower($charset)); + $temprecipients[$key][1] = textlib::convert($values[1], 'utf-8', strtolower($charset)); } foreach ($tempreplyto as $key => $values) { - $tempreplyto[$key][1] = $textlib->convert($values[1], 'utf-8', strtolower($charset)); + $tempreplyto[$key][1] = textlib::convert($values[1], 'utf-8', strtolower($charset)); } } } @@ -8754,9 +8749,7 @@ function moodle_strtolower ($string, $encoding='') { $encoding = 'UTF-8'; } //Use text services - $textlib = textlib_get_instance(); - - return $textlib->strtolower($string, $encoding); + return textlib::strtolower($string, $encoding); } /** @@ -8783,12 +8776,10 @@ function count_words($string) { */ function count_letters($string) { /// Loading the textlib singleton instance. We are going to need it. - $textlib = textlib_get_instance(); - $string = strip_tags($string); // Tags are out now $string = preg_replace('/[[:space:]]*/','',$string); //Whitespace are out now - return $textlib->strlen($string); + return textlib::strlen($string); } /** @@ -9897,10 +9888,9 @@ function message_popup_window() { $smallmessage = null; if (!empty($message_users->smallmessage)) { //display the first 200 chars of the message in the popup - $textlib = textlib_get_instance(); $smallmessage = null; - if ($textlib->strlen($message_users->smallmessage) > 200) { - $smallmessage = $textlib->substr($message_users->smallmessage,0,200).'...'; + if (textlib::strlen($message_users->smallmessage) > 200) { + $smallmessage = textlib::substr($message_users->smallmessage,0,200).'...'; } else { $smallmessage = $message_users->smallmessage; } diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 9a565545c83..19ef2f5951a 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -3369,8 +3369,6 @@ class settings_navigation extends navigation_node { $this->get_course_modules($course); - $textlib = textlib_get_instance(); - foreach ($sections as $section) { if ($formatidentifier !== 0 && $section->section != $formatidentifier) { continue; @@ -3388,8 +3386,8 @@ class settings_navigation extends navigation_node { $url = new moodle_url('/course/mod.php', array('id'=>$course->id, 'sesskey'=>sesskey(), 'section'=>$section->section)); $pos = strpos($value, '&type='); if ($pos!==false) { - $url->param('add', $textlib->substr($value, 0,$pos)); - $url->param('type', $textlib->substr($value, $pos+6)); + $url->param('add', textlib::substr($value, 0,$pos)); + $url->param('type', textlib::substr($value, $pos+6)); } else { $url->param('add', $value); } @@ -3408,8 +3406,8 @@ class settings_navigation extends navigation_node { $url = new moodle_url('/course/mod.php', array('id'=>$course->id, 'sesskey'=>sesskey(), 'section'=>$section->section)); $pos = strpos($activityname, '&type='); if ($pos!==false) { - $url->param('add', $textlib->substr($activityname, 0,$pos)); - $url->param('type', $textlib->substr($activityname, $pos+6)); + $url->param('add', textlib::substr($activityname, 0,$pos)); + $url->param('type', textlib::substr($activityname, $pos+6)); } else { $url->param('add', $activityname); } diff --git a/lib/phpmailer/moodle_phpmailer.php b/lib/phpmailer/moodle_phpmailer.php index ff38155df83..debfb6b7676 100644 --- a/lib/phpmailer/moodle_phpmailer.php +++ b/lib/phpmailer/moodle_phpmailer.php @@ -74,8 +74,7 @@ class moodle_phpmailer extends PHPMailer { * Fall back to phpmailers inbuilt functions if not */ public function EncodeHeader ($str, $position = 'text') { - $textlib = textlib_get_instance(); - $encoded = $textlib->encode_mimeheader($str, $this->CharSet); + $encoded = textlib::encode_mimeheader($str, $this->CharSet); if ($encoded !== false) { $encoded = str_replace("\n", $this->LE, $encoded); if ($position == 'phrase') { diff --git a/lib/simpletest/testmoodlelib.php b/lib/simpletest/testmoodlelib.php index 254b87093c3..575238fb94c 100644 --- a/lib/simpletest/testmoodlelib.php +++ b/lib/simpletest/testmoodlelib.php @@ -1400,15 +1400,13 @@ class moodlelib_test extends UnitTestCase { $systemdefaulttimezone = date_default_timezone_get(); date_default_timezone_set('Australia/Perth'); - //get instance of textlib for strtolower - $textlib = textlib_get_instance(); foreach ($testvalues as $vals) { $USER->timezone = $vals['usertimezone']; $actualoutput = userdate($vals['time'], '%A, %d %B %Y, %I:%M %p', $vals['timezone']); //On different systems case of AM PM changes so compare case insenitive - $vals['expectedoutput'] = $textlib->strtolower($vals['expectedoutput']); - $actualoutput = $textlib->strtolower($actualoutput); + $vals['expectedoutput'] = textlib::strtolower($vals['expectedoutput']); + $actualoutput = textlib::strtolower($actualoutput); $this->assertEqual($vals['expectedoutput'], $actualoutput, "Expected: {$vals['expectedoutput']} => Actual: {$actualoutput}, @@ -1574,8 +1572,6 @@ class moodlelib_test extends UnitTestCase { $systemdefaulttimezone = date_default_timezone_get(); date_default_timezone_set('Australia/Perth'); - //get instance of textlib for strtolower - $textlib = textlib_get_instance(); //Test make_timestamp with all testvals and assert if anything wrong. foreach ($testvalues as $vals) { $USER->timezone = $vals['usertimezone']; @@ -1591,8 +1587,8 @@ class moodlelib_test extends UnitTestCase { ); //On different systems case of AM PM changes so compare case insenitive - $vals['expectedoutput'] = $textlib->strtolower($vals['expectedoutput']); - $actualoutput = $textlib->strtolower($actualoutput); + $vals['expectedoutput'] = textlib::strtolower($vals['expectedoutput']); + $actualoutput = textlib::strtolower($actualoutput); $this->assertEqual($vals['expectedoutput'], $actualoutput, "Expected: {$vals['expectedoutput']} => Actual: {$actualoutput}, diff --git a/lib/simpletest/testweblib.php b/lib/simpletest/testweblib.php index d4ead8f6030..c1a313d02c5 100644 --- a/lib/simpletest/testweblib.php +++ b/lib/simpletest/testweblib.php @@ -68,10 +68,9 @@ class web_test extends UnitTestCase { format_text_email('

This is a test

',FORMAT_HTML)); $this->assertEqual('& so is this', format_text_email('& so is this',FORMAT_HTML)); - $tl = textlib_get_instance(); - $this->assertEqual('Two bullets: '.$tl->code2utf8(8226).' *', + $this->assertEqual('Two bullets: '.textlib::code2utf8(8226).' *', format_text_email('Two bullets: • •',FORMAT_HTML)); - $this->assertEqual($tl->code2utf8(0x7fd2).$tl->code2utf8(0x7fd2), + $this->assertEqual(textlib::code2utf8(0x7fd2).textlib::code2utf8(0x7fd2), format_text_email('習習',FORMAT_HTML)); } diff --git a/lib/tokeniserlib.php b/lib/tokeniserlib.php index a903cfe5179..b57c44ad515 100644 --- a/lib/tokeniserlib.php +++ b/lib/tokeniserlib.php @@ -164,8 +164,6 @@ define('PREG_CLASS_CJK', '\x{3041}-\x{30ff}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}'. */ function tokenise_text($text, $stop_words = array(), $overlap_cjk = false, $join_numbers = false) { - $textlib = textlib_get_instance(); - // Multipliers for scores of words inside certain HTML tags. // Note: 'a' must be included for link ranking to work. $tags = array('h1' => 25, @@ -204,7 +202,7 @@ function tokenise_text($text, $stop_words = array(), $overlap_cjk = false, $join if ($tag) { // Increase or decrease score per word based on tag list($tagname) = explode(' ', $value, 2); - $tagname = $textlib->strtolower($tagname); + $tagname = textlib::strtolower($tagname); // Closing or opening tag? if ($tagname[0] == '/') { $tagname = substr($tagname, 1); @@ -243,7 +241,7 @@ function tokenise_text($text, $stop_words = array(), $overlap_cjk = false, $join $accum .= $word .' '; $num = is_numeric($word); // Check word length - if ($num || $textlib->strlen($word) >= MINIMUM_WORD_SIZE) { + if ($num || textlib::strlen($word) >= MINIMUM_WORD_SIZE) { // Normalize numbers if ($num && $join_numbers) { $word = (int)ltrim($word, '-0'); @@ -319,13 +317,11 @@ function tokenise_split($text, $stop_words, $overlap_cjk, $join_numbers) { */ function tokenise_simplify($text, $overlap_cjk, $join_numbers) { - $textlib = textlib_get_instance(); - // Decode entities to UTF-8 - $text = $textlib->entities_to_utf8($text, true); + $text = textlib::entities_to_utf8($text, true); // Lowercase - $text = $textlib->strtolower($text); + $text = textlib::strtolower($text); // Simple CJK handling if ($overlap_cjk) { @@ -377,10 +373,8 @@ function tokenise_simplify($text, $overlap_cjk, $join_numbers) { */ function tokenise_expand_cjk($matches) { - $textlib = textlib_get_instance(); - $str = $matches[0]; - $l = $textlib->strlen($str); + $l = textlib::strlen($str); // Passthrough short words if ($l <= MINIMUM_WORD_SIZE) { return ' '. $str .' '; @@ -391,7 +385,7 @@ function tokenise_expand_cjk($matches) { // Begin loop for ($i = 0; $i < $l; ++$i) { // Grab next character - $current = $textlib->substr($str, 0, 1); + $current = textlib::substr($str, 0, 1); $str = substr($str, strlen($current)); $chars[] = $current; if ($i >= MINIMUM_WORD_SIZE - 1) { @@ -408,6 +402,5 @@ function tokenise_expand_cjk($matches) { */ function tokenise_truncate_word(&$text) { - $textlib = textlib_get_instance(); - $text = $textlib->substr($text, 0, MAXIMUM_WORD_SIZE); + $text = textlib::substr($text, 0, MAXIMUM_WORD_SIZE); } diff --git a/lib/weblib.php b/lib/weblib.php index 9c2d4a35485..c666aa2b067 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -782,20 +782,17 @@ function data_submitted() { */ function break_up_long_words($string, $maxsize=20, $cutchar=' ') { -/// Loading the textlib singleton instance. We are going to need it. - $textlib = textlib_get_instance(); - /// First of all, save all the tags inside the text to skip them $tags = array(); filter_save_tags($string,$tags); /// Process the string adding the cut when necessary $output = ''; - $length = $textlib->strlen($string); + $length = textlib::strlen($string); $wordlength = 0; for ($i=0; $i<$length; $i++) { - $char = $textlib->substr($string, $i, 1); + $char = textlib::substr($string, $i, 1); if ($char == ' ' or $char == "\t" or $char == "\n" or $char == "\r" or $char == "<" or $char == ">") { $wordlength = 0; } else { diff --git a/login/forgot_password.php b/login/forgot_password.php index f5fc673d1c7..807cbc3ed57 100644 --- a/login/forgot_password.php +++ b/login/forgot_password.php @@ -126,7 +126,7 @@ if ($mform->is_cancelled()) { // first try the username if (!empty($data->username)) { - $username = textlib_get_instance()->strtolower($data->username); // mimic the login page process, if they forget username they need to use email for reset + $username = textlib::strtolower($data->username); // mimic the login page process, if they forget username they need to use email for reset $user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0, 'suspended'=>0)); } else { diff --git a/message/lib.php b/message/lib.php index 7eb339ea653..c71f62cd8b0 100644 --- a/message/lib.php +++ b/message/lib.php @@ -470,7 +470,6 @@ function message_print_contacts($onlinecontacts, $offlinecontacts, $strangers, $ */ function message_print_usergroup_selector($viewing, $courses, $coursecontexts, $countunreadtotal, $countblocked, $strunreadmessages) { $options = array(); - $textlib = textlib_get_instance(); // going to use textlib services if ($countunreadtotal>0) { //if there are unread messages $options[MESSAGE_VIEW_UNREAD_MESSAGES] = $strunreadmessages; @@ -489,8 +488,8 @@ function message_print_usergroup_selector($viewing, $courses, $coursecontexts, $ if (has_capability('moodle/course:viewparticipants', $coursecontexts[$course->id])) { //Not using short_text() as we want the end of the course name. Not the beginning. $shortname = format_string($course->shortname, true, array('context' => $coursecontexts[$course->id])); - if ($textlib->strlen($shortname) > MESSAGE_MAX_COURSE_NAME_LENGTH) { - $courses_options[MESSAGE_VIEW_COURSE.$course->id] = '...'.$textlib->substr($shortname, -MESSAGE_MAX_COURSE_NAME_LENGTH); + if (textlib::strlen($shortname) > MESSAGE_MAX_COURSE_NAME_LENGTH) { + $courses_options[MESSAGE_VIEW_COURSE.$course->id] = '...'.textlib::substr($shortname, -MESSAGE_MAX_COURSE_NAME_LENGTH); } else { $courses_options[MESSAGE_VIEW_COURSE.$course->id] = $shortname; } diff --git a/mod/data/import_form.php b/mod/data/import_form.php index 7da41db8994..ce0bbeeec93 100644 --- a/mod/data/import_form.php +++ b/mod/data/import_form.php @@ -21,8 +21,7 @@ class mod_data_import_form extends moodleform { $mform->addElement('text', 'fieldenclosure', get_string('fieldenclosure', 'data')); - $textlib = textlib_get_instance(); - $choices = $textlib->get_encodings(); + $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'admin'), $choices); $mform->setDefault('encoding', 'UTF-8'); diff --git a/mod/data/view.php b/mod/data/view.php index 0a2290c07ab..439722e835a 100644 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -230,8 +230,7 @@ $search = ''; } - $textlib = textlib_get_instance(); - if ($textlib->strlen($search) < 2) { + if (textlib::strlen($search) < 2) { $search = ''; } $SESSION->dataprefs[$data->id]['search'] = $search; // Make it sticky diff --git a/mod/feedback/import.php b/mod/feedback/import.php index e8a1c205a98..896ccd86e50 100644 --- a/mod/feedback/import.php +++ b/mod/feedback/import.php @@ -286,7 +286,6 @@ function feedback_check_xml_utf8($text) { //encoding is given in $match[2] if (isset($match[0]) AND isset($match[1]) AND isset($match[2])) { $enc = $match[2]; - $textlib = textlib_get_instance(); - return $textlib->convert($text, $enc); + return textlib::convert($text, $enc); } } diff --git a/mod/glossary/print.php b/mod/glossary/print.php index 013c70e5583..2d53a42ede6 100644 --- a/mod/glossary/print.php +++ b/mod/glossary/print.php @@ -63,9 +63,6 @@ $PAGE->set_title(get_string("modulenameplural", "glossary")); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); -/// Loading the textlib singleton instance. We are going to need it. -$textlib = textlib_get_instance(); - if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) { notice(get_string('printviewnotallowed', 'glossary')); } @@ -181,12 +178,12 @@ if ( $allentries ) { // Setting the pivot for the current entry $pivot = $entry->glossarypivot; - $upperpivot = $textlib->strtoupper($pivot); - $pivottoshow = $textlib->strtoupper(format_string($pivot, true, $fmtoptions)); + $upperpivot = textlib::strtoupper($pivot); + $pivottoshow = textlib::strtoupper(format_string($pivot, true, $fmtoptions)); // Reduce pivot to 1cc if necessary if ( !$fullpivot ) { - $upperpivot = $textlib->substr($upperpivot, 0, 1); - $pivottoshow = $textlib->substr($pivottoshow, 0, 1); + $upperpivot = textlib::substr($upperpivot, 0, 1); + $pivottoshow = textlib::substr($pivottoshow, 0, 1); } // If there's group break diff --git a/mod/glossary/sql.php b/mod/glossary/sql.php index 43b7904e3a3..a2cb2c1f97d 100644 --- a/mod/glossary/sql.php +++ b/mod/glossary/sql.php @@ -11,7 +11,6 @@ /// Initialise some variables $sqlorderby = ''; $sqlsortkey = NULL; - $textlib = textlib_get_instance(); // For cases needing inner view $sqlwrapheader = ''; @@ -89,14 +88,14 @@ case GLOSSARY_AUTHOR_VIEW: $where = ''; - $params['hookup'] = $textlib->strtoupper($hook); + $params['hookup'] = textlib::strtoupper($hook); if ( $sqlsortkey == 'firstname' ) { $usernamefield = $DB->sql_fullname('u.firstname' , 'u.lastname'); } else { $usernamefield = $DB->sql_fullname('u.lastname' , 'u.firstname'); } - $where = "AND " . $DB->sql_substr("upper($usernamefield)", 1, $textlib->strlen($hook)) . " = :hookup"; + $where = "AND " . $DB->sql_substr("upper($usernamefield)", 1, textlib::strlen($hook)) . " = :hookup"; if ( $hook == 'ALL' ) { $where = ''; @@ -115,10 +114,10 @@ $printpivot = 0; $where = ''; - $params['hookup'] = $textlib->strtoupper($hook); + $params['hookup'] = textlib::strtoupper($hook); if ($hook != 'ALL' and $hook != 'SPECIAL') { - $where = "AND " . $DB->sql_substr("upper(concept)", 1, $textlib->strlen($hook)) . " = :hookup"; + $where = "AND " . $DB->sql_substr("upper(concept)", 1, textlib::strlen($hook)) . " = :hookup"; } $sqlselect = "SELECT ge.*, ge.concept AS glossarypivot"; @@ -176,7 +175,7 @@ if (substr($searchterm,0,1) == '+') { $searchterm = trim($searchterm, '+-'); - if ($textlib->strlen($searchterm) < 2) { + if (textlib::strlen($searchterm) < 2) { continue; } $searchterm = preg_quote($searchterm, '|'); @@ -185,7 +184,7 @@ } else if (substr($searchterm,0,1) == "-") { $searchterm = trim($searchterm, '+-'); - if ($textlib->strlen($searchterm) < 2) { + if (textlib::strlen($searchterm) < 2) { continue; } $searchterm = preg_quote($searchterm, '|'); @@ -193,7 +192,7 @@ $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)"; } else { - if ($textlib->strlen($searchterm) < 2) { + if (textlib::strlen($searchterm) < 2) { continue; } $searchcond[] = $DB->sql_like($concat, ":ss$i", false, true, $NOT); @@ -235,8 +234,8 @@ case 'letter': if ($hook != 'ALL' and $hook != 'SPECIAL') { - $params['hookup'] = $textlib->strtoupper($hook); - $where = "AND " . $DB->sql_substr("upper(concept)", 1, $textlib->strlen($hook)) . " = :hookup"; + $params['hookup'] = textlib::strtoupper($hook); + $where = "AND " . $DB->sql_substr("upper(concept)", 1, textlib::strlen($hook)) . " = :hookup"; } if ($hook == 'SPECIAL') { //Create appropiate IN contents diff --git a/mod/glossary/view.php b/mod/glossary/view.php index b57cec68464..cd5a306d0a6 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -57,9 +57,6 @@ $fmtoptions = array( require_once($CFG->dirroot . '/comment/lib.php'); comment::init(); -/// Loading the textlib singleton instance. We are going to need it. -$textlib = textlib_get_instance(); - /// redirecting if adding a new entry if ($tab == GLOSSARY_ADDENTRY_VIEW ) { redirect("edit.php?cmid=$cm->id&mode=$mode"); @@ -425,12 +422,12 @@ if ($allentries) { // Setting the pivot for the current entry $pivot = $entry->glossarypivot; - $upperpivot = $textlib->strtoupper($pivot); - $pivottoshow = $textlib->strtoupper(format_string($pivot, true, $fmtoptions)); + $upperpivot = textlib::strtoupper($pivot); + $pivottoshow = textlib::strtoupper(format_string($pivot, true, $fmtoptions)); // Reduce pivot to 1cc if necessary if ( !$fullpivot ) { - $upperpivot = $textlib->substr($upperpivot, 0, 1); - $pivottoshow = $textlib->substr($pivottoshow, 0, 1); + $upperpivot = textlib::substr($upperpivot, 0, 1); + $pivottoshow = textlib::substr($pivottoshow, 0, 1); } // if there's a group break diff --git a/mod/label/lib.php b/mod/label/lib.php index d11ba19c542..2430d176a36 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -35,11 +35,9 @@ define("LABEL_MAX_NAME_LENGTH", 50); * @return string */ function get_label_name($label) { - $textlib = textlib_get_instance(); - $name = strip_tags(format_string($label->intro,true)); - if ($textlib->strlen($name) > LABEL_MAX_NAME_LENGTH) { - $name = $textlib->substr($name, 0, LABEL_MAX_NAME_LENGTH)."..."; + if (textlib::strlen($name) > LABEL_MAX_NAME_LENGTH) { + $name = textlib::substr($name, 0, LABEL_MAX_NAME_LENGTH)."..."; } if (empty($name)) { diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 74f0276046f..0bbe06b85ba 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -413,8 +413,6 @@ function lti_get_tool_table($tools, $id) { * @return Array of custom parameters */ function lti_split_custom_parameters($customstr) { - $textlib = textlib_get_instance(); - $lines = preg_split("/[\n;]/", $customstr); $retval = array(); foreach ($lines as $line) { @@ -422,8 +420,8 @@ function lti_split_custom_parameters($customstr) { if ( $pos === false || $pos < 1 ) { continue; } - $key = trim($textlib->substr($line, 0, $pos)); - $val = trim($textlib->substr($line, $pos+1, strlen($line))); + $key = trim(textlib::substr($line, 0, $pos)); + $val = trim(textlib::substr($line, $pos+1, strlen($line))); $key = lti_map_keyname($key); $retval['custom_'.$key] = $val; } @@ -438,10 +436,8 @@ function lti_split_custom_parameters($customstr) { * @return string Processed name */ function lti_map_keyname($key) { - $textlib = textlib_get_instance(); - $newkey = ""; - $key = $textlib->strtolower(trim($key)); + $key = textlib::strtolower(trim($key)); foreach (str_split($key) as $ch) { if ( ($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9') ) { $newkey .= $ch; diff --git a/report/completion/index.php b/report/completion/index.php index dcd81a98b01..2d2b83df7fb 100644 --- a/report/completion/index.php +++ b/report/completion/index.php @@ -68,8 +68,7 @@ $leftcols = 1 + count($extrafields); function csv_quote($value) { global $excel; if ($excel) { - $tl = textlib_get_instance(); - return $tl->convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE'); + return textlib::convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE'); } else { return '"'.str_replace('"',"'",$value).'"'; } @@ -145,9 +144,8 @@ if (!$csv) { */ if ($csv) { $shortname = format_string($course->shortname, true, array('context' => $context)); - $textlib = textlib_get_instance(); header('Content-Disposition: attachment; filename=progress.'. - preg_replace('/[^a-z0-9-]/','_',$textlib->strtolower(strip_tags($shortname))).'.csv'); + preg_replace('/[^a-z0-9-]/','_',textlib::strtolower(strip_tags($shortname))).'.csv'); // Unicode byte-order mark for Excel if ($excel) { header('Content-Type: text/csv; charset=UTF-16LE'); diff --git a/report/progress/index.php b/report/progress/index.php index 644d8c3f0e9..5c3f531dda5 100644 --- a/report/progress/index.php +++ b/report/progress/index.php @@ -58,8 +58,7 @@ $leftcols = 1 + count($extrafields); function csv_quote($value) { global $excel; if ($excel) { - $tl = textlib_get_instance(); - return $tl->convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE'); + return textlib::convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE'); } else { return '"'.str_replace('"',"'",$value).'"'; } @@ -133,9 +132,8 @@ if ($total) { if ($csv && $grandtotal && count($activities)>0) { // Only show CSV if there are some users/actvs $shortname = format_string($course->shortname, true, array('context' => $context)); - $textlib = textlib_get_instance(); header('Content-Disposition: attachment; filename=progress.'. - preg_replace('/[^a-z0-9-]/','_',$textlib->strtolower(strip_tags($shortname))).'.csv'); + preg_replace('/[^a-z0-9-]/','_',textlib::strtolower(strip_tags($shortname))).'.csv'); // Unicode byte-order mark for Excel if ($excel) { header('Content-Type: text/csv; charset=UTF-16LE'); diff --git a/tag/coursetagslib.php b/tag/coursetagslib.php index c83b9543084..02d20b60aec 100644 --- a/tag/coursetagslib.php +++ b/tag/coursetagslib.php @@ -695,8 +695,7 @@ function coursetag_get_official_keywords($courseid, $asarray=false) { } foreach ($tags as $tag) { if( empty($CFG->keeptagnamecase) ) { - $textlib = textlib_get_instance(); - $name = $textlib->strtotitle($tag->name); + $name = textlib::strtotitle($tag->name); } else { $name = $tag->rawname; } diff --git a/tag/lib.php b/tag/lib.php index 2859162b61d..4f15fadecdc 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -673,8 +673,7 @@ function tag_display_name($tagobject, $html=TAG_RETURN_HTML) { if (empty($CFG->keeptagnamecase)) { //this is the normalized tag name - $textlib = textlib_get_instance(); - $tagname = $textlib->strtotitle($tagobject->name); + $tagname = textlib::strtotitle($tagobject->name); } else { //original casing of the tag name $tagname = $tagobject->rawname; diff --git a/tag/locallib.php b/tag/locallib.php index 6c750b069b6..fb7f9a9f730 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -356,7 +356,6 @@ function tag_print_tagged_users_table($tag_object, $limitfrom='', $limitnum='', function tag_print_user_box($user, $return=false) { global $CFG, $OUTPUT; - $textlib = textlib_get_instance(); $usercontext = get_context_instance(CONTEXT_USER, $user->id); $profilelink = ''; @@ -381,8 +380,8 @@ function tag_print_user_box($user, $return=false) { } //truncate name if it's too big - if ($textlib->strlen($fullname) > 26) { - $fullname = $textlib->substr($fullname, 0, 26) .'...'; + if (textlib::strlen($fullname) > 26) { + $fullname = textlib::substr($fullname, 0, 26) .'...'; } $output .= ''. $fullname .'';