Merge branch 'w10_MDL-31301_m23_textlibcleanup' of git://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2012-03-06 16:06:53 +01:00
commit 2ed7cc2730
73 changed files with 291 additions and 420 deletions

View File

@ -103,7 +103,7 @@ if ($form = data_submitted() and confirm_sesskey()) {
$usernames = explode(',', $form->username);
foreach ($usernames as $username) {
$username = trim(moodle_strtolower($username));
$username = trim(textlib::strtolower($username));
if (!empty($username)) {
if (mnet_update_sso_access_control($username, $form->mnet_host_id, $form->accessctrl)) {
if ($form->accessctrl == 'allow') {

View File

@ -610,8 +610,8 @@ 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 = moodle_strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT));
$this->role->shortname = textlib::specialtoascii($this->role->shortname);
$this->role->shortname = textlib::strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT));
if (empty($this->role->shortname)) {
$this->errors['shortname'] = get_string('errorbadroleshortname', 'role');
}

View File

@ -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;

View File

@ -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');

View File

@ -51,7 +51,7 @@ class auth_plugin_cas extends auth_plugin_ldap {
*/
function user_login ($username, $password) {
$this->connectCAS();
return phpCAS::isAuthenticated() && (trim(moodle_strtolower(phpCAS::getUser())) == $username);
return phpCAS::isAuthenticated() && (trim(textlib::strtolower(phpCAS::getUser())) == $username);
}
/**
@ -336,15 +336,15 @@ class auth_plugin_cas extends auth_plugin_ldap {
set_config('host_url', trim($config->host_url), $this->pluginconfig);
set_config('ldapencoding', trim($config->ldapencoding), $this->pluginconfig);
set_config('contexts', trim($config->contexts), $this->pluginconfig);
set_config('user_type', moodle_strtolower(trim($config->user_type)), $this->pluginconfig);
set_config('user_attribute', moodle_strtolower(trim($config->user_attribute)), $this->pluginconfig);
set_config('user_type', textlib::strtolower(trim($config->user_type)), $this->pluginconfig);
set_config('user_attribute', textlib::strtolower(trim($config->user_attribute)), $this->pluginconfig);
set_config('search_sub', $config->search_sub, $this->pluginconfig);
set_config('opt_deref', $config->opt_deref, $this->pluginconfig);
set_config('bind_dn', trim($config->bind_dn), $this->pluginconfig);
set_config('bind_pw', $config->bind_pw, $this->pluginconfig);
set_config('ldap_version', $config->ldap_version, $this->pluginconfig);
set_config('objectclass', trim($config->objectclass), $this->pluginconfig);
set_config('memberattribute', moodle_strtolower(trim($config->memberattribute)), $this->pluginconfig);
set_config('memberattribute', textlib::strtolower(trim($config->memberattribute)), $this->pluginconfig);
set_config('memberattribute_isdn', $config->memberattribute_isdn, $this->pluginconfig);
set_config('attrcreators', trim($config->attrcreators), $this->pluginconfig);
set_config('groupecreators', trim($config->groupecreators), $this->pluginconfig);
@ -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)) {

View File

@ -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));
}
@ -845,7 +839,7 @@ class auth_plugin_ldap extends auth_plugin_base {
$user->mnethostid = $CFG->mnet_localhost_id;
// get_userinfo_asobj() might have replaced $user->username with the value
// from the LDAP server (which can be mixed-case). Make sure it's lowercase
$user->username = trim(moodle_strtolower($user->username));
$user->username = trim(textlib::strtolower($user->username));
if (empty($user->lang)) {
$user->lang = $CFG->lang;
}
@ -889,7 +883,7 @@ class auth_plugin_ldap extends auth_plugin_base {
global $CFG, $DB;
// Just in case check text case
$username = trim(moodle_strtolower($username));
$username = trim(textlib::strtolower($username));
// Get the current user record
$user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id));
@ -934,7 +928,7 @@ class auth_plugin_ldap extends auth_plugin_base {
function ldap_bulk_insert($username) {
global $DB, $CFG;
$username = moodle_strtolower($username); // usernames are __always__ lowercase.
$username = textlib::strtolower($username); // usernames are __always__ lowercase.
$DB->insert_record_raw('tmp_extuser', array('username'=>$username,
'mnethostid'=>$CFG->mnet_localhost_id), false, true);
echo '.';
@ -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':
@ -1380,13 +1370,13 @@ class auth_plugin_ldap extends auth_plugin_base {
$moodleattributes = array();
foreach ($this->userfields as $field) {
if (!empty($this->config->{"field_map_$field"})) {
$moodleattributes[$field] = moodle_strtolower(trim($this->config->{"field_map_$field"}));
$moodleattributes[$field] = textlib::strtolower(trim($this->config->{"field_map_$field"}));
if (preg_match('/,/', $moodleattributes[$field])) {
$moodleattributes[$field] = explode(',', $moodleattributes[$field]); // split ?
}
}
}
$moodleattributes['username'] = moodle_strtolower(trim($this->config->user_attribute));
$moodleattributes['username'] = textlib::strtolower(trim($this->config->user_attribute));
return $moodleattributes;
}
@ -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':
@ -1592,7 +1580,7 @@ class auth_plugin_ldap extends auth_plugin_base {
return false; // Should never happen!
}
$username = moodle_strtolower($username); // Compatibility hack
$username = textlib::strtolower($username); // Compatibility hack
set_cache_flag($this->pluginconfig.'/ntlmsess', $sesskey, $username, AUTH_NTLMTIMEOUT);
return true;
}
@ -1794,8 +1782,8 @@ class auth_plugin_ldap extends auth_plugin_base {
set_config('host_url', trim($config->host_url), $this->pluginconfig);
set_config('ldapencoding', trim($config->ldapencoding), $this->pluginconfig);
set_config('contexts', trim($config->contexts), $this->pluginconfig);
set_config('user_type', moodle_strtolower(trim($config->user_type)), $this->pluginconfig);
set_config('user_attribute', moodle_strtolower(trim($config->user_attribute)), $this->pluginconfig);
set_config('user_type', textlib::strtolower(trim($config->user_type)), $this->pluginconfig);
set_config('user_attribute', textlib::strtolower(trim($config->user_attribute)), $this->pluginconfig);
set_config('search_sub', $config->search_sub, $this->pluginconfig);
set_config('opt_deref', $config->opt_deref, $this->pluginconfig);
set_config('preventpassindb', $config->preventpassindb, $this->pluginconfig);
@ -1803,15 +1791,15 @@ class auth_plugin_ldap extends auth_plugin_base {
set_config('bind_pw', $config->bind_pw, $this->pluginconfig);
set_config('ldap_version', $config->ldap_version, $this->pluginconfig);
set_config('objectclass', trim($config->objectclass), $this->pluginconfig);
set_config('memberattribute', moodle_strtolower(trim($config->memberattribute)), $this->pluginconfig);
set_config('memberattribute', textlib::strtolower(trim($config->memberattribute)), $this->pluginconfig);
set_config('memberattribute_isdn', $config->memberattribute_isdn, $this->pluginconfig);
set_config('creators', trim($config->creators), $this->pluginconfig);
set_config('create_context', trim($config->create_context), $this->pluginconfig);
set_config('expiration', $config->expiration, $this->pluginconfig);
set_config('expiration_warning', trim($config->expiration_warning), $this->pluginconfig);
set_config('expireattr', moodle_strtolower(trim($config->expireattr)), $this->pluginconfig);
set_config('expireattr', textlib::strtolower(trim($config->expireattr)), $this->pluginconfig);
set_config('gracelogins', $config->gracelogins, $this->pluginconfig);
set_config('graceattr', moodle_strtolower(trim($config->graceattr)), $this->pluginconfig);
set_config('graceattr', textlib::strtolower(trim($config->graceattr)), $this->pluginconfig);
set_config('auth_user_create', $config->auth_user_create, $this->pluginconfig);
set_config('forcechangepassword', $config->forcechangepassword, $this->pluginconfig);
set_config('stdchangepassword', $config->stdchangepassword, $this->pluginconfig);

View File

@ -1189,8 +1189,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'] .= ' <img src="' . $data['image'] . '" />';

View File

@ -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');
}

View File

@ -226,7 +226,7 @@
//Process contacts
if ($contactcount) {
if (!defined('RESTORE_SILENTLY')) {
echo '<li>'.moodle_strtolower(get_string('contacts','message')).'</li>';
echo '<li>'.textlib::strtolower(get_string('contacts','message')).'</li>';
}
$counter = 0;
while ($counter < $contactcount) {

View File

@ -204,7 +204,7 @@ abstract class backup_plan_dbops extends backup_dbops {
global $DB;
// Calculate backup word
$backupword = str_replace(' ', '_', moodle_strtolower(get_string('backupfilename')));
$backupword = str_replace(' ', '_', textlib::strtolower(get_string('backupfilename')));
$backupword = trim(clean_filename($backupword), '_');
$shortname = '';
@ -228,7 +228,7 @@ abstract class backup_plan_dbops extends backup_dbops {
break;
}
$shortname = str_replace(' ', '_', $shortname);
$shortname = moodle_strtolower(trim(clean_filename($shortname), '_'));
$shortname = textlib::strtolower(trim(clean_filename($shortname), '_'));
}
$name = empty($shortname) ? $id : $shortname;
@ -236,7 +236,7 @@ abstract class backup_plan_dbops extends backup_dbops {
// Calculate date
$backupdateformat = str_replace(' ', '_', get_string('backupnameformat', 'langconfig'));
$date = userdate(time(), $backupdateformat, 99, false);
$date = moodle_strtolower(trim(clean_filename($date), '_'));
$date = textlib::strtolower(trim(clean_filename($date), '_'));
// Calculate info
$info = '';

View File

@ -459,7 +459,7 @@ abstract class backup_cron_automated_helper {
$storage = $config->backup_auto_storage;
$dir = $config->backup_auto_destination;
$backupword = str_replace(' ', '_', moodle_strtolower(get_string('backupfilename')));
$backupword = str_replace(' ', '_', textlib::strtolower(get_string('backupfilename')));
$backupword = trim(clean_filename($backupword), '_');
if (!file_exists($dir) || !is_dir($dir) || !is_writable($dir)) {

View File

@ -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;
}

View File

@ -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).'...');
}
}

View File

@ -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.

View File

@ -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).

View File

@ -818,7 +818,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);
}
}
@ -833,7 +833,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');
}
}
}

View File

@ -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');

View File

@ -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))) {

View File

@ -63,7 +63,7 @@ class admin_setting_configtext_trim_lower extends admin_setting_configtext {
return $validated;
}
if ($this->lowercase) {
$data = moodle_strtolower($data);
$data = textlib::strtolower($data);
}
return ($this->config_write($this->name, trim($data)) ? '' : get_string('errorsetting', 'admin'));
}
@ -118,7 +118,7 @@ class admin_setting_ldap_rolemapping extends admin_setting {
if (!$this->config_write('contexts_role'.$roleid, trim($data['contexts']))) {
$return = get_string('errorsetting', 'admin');
}
if (!$this->config_write('memberattribute_role'.$roleid, moodle_strtolower(trim($data['memberattribute'])))) {
if (!$this->config_write('memberattribute_role'.$roleid, textlib::strtolower(trim($data['memberattribute'])))) {
$return = get_string('errorsetting', 'admin');
}
}

View File

@ -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');

View File

@ -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) {

View File

@ -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");

View File

@ -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'])) {

View File

@ -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);
}

View File

@ -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);
}

View File

@ -168,7 +168,7 @@
$newsforumcontext = get_context_instance(CONTEXT_MODULE, $newsforumcm->id, MUST_EXIST);
$forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(strip_tags($forumname))), array('href'=>'#skipsitenews', 'class'=>'skip-block'));
echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(strip_tags($forumname))), array('href'=>'#skipsitenews', 'class'=>'skip-block'));
if (isloggedin()) {
$SESSION->fromdiscussion = $CFG->wwwroot;
@ -194,13 +194,13 @@
case FRONTPAGECOURSELIST:
if (isloggedin() and !$hassiteconfig and !isguestuser() and empty($CFG->disablemycourses)) {
echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block'));
echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block'));
echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
print_my_moodle();
echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipmycourses'));
} else if ((!$hassiteconfig and !isguestuser()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
// admin should not see list of courses when there are too many of them
echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('availablecourses'))), array('href'=>'#skipavailablecourses', 'class'=>'skip-block'));
echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('availablecourses'))), array('href'=>'#skipavailablecourses', 'class'=>'skip-block'));
echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
print_courses(0);
echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses'));
@ -208,7 +208,7 @@
break;
case FRONTPAGECATEGORYNAMES:
echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('categories'))), array('href'=>'#skipcategories', 'class'=>'skip-block'));
echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('categories'))), array('href'=>'#skipcategories', 'class'=>'skip-block'));
echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
echo $OUTPUT->box_start('generalbox categorybox');
print_whole_category_list(NULL, NULL, NULL, -1, false);
@ -218,7 +218,7 @@
break;
case FRONTPAGECATEGORYCOMBO:
echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block'));
echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block'));
echo $OUTPUT->heading(get_string('courses'), 2, 'headingblock header');
$renderer = $PAGE->get_renderer('core','course');
// if there are too many courses, budiling course category tree could be slow,

View File

@ -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'];
}

View File

@ -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;
}
}

View File

@ -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?

View File

@ -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);
}

View File

@ -4000,3 +4000,40 @@ function show_event($event) {
$event = new calendar_event($event);
return $event->toggle_visibility(true);
}
/**
* Converts string to lowercase using most compatible function available.
*
* @deprecated Use textlib::strtolower($text) instead.
*
* @param string $string The string to convert to all lowercase characters.
* @param string $encoding The encoding on the string.
* @return string
*/
function moodle_strtolower($string, $encoding='') {
debugging('moodle_strtolower() is deprecated. Please use textlib::strtolower() instead.', DEBUG_DEVELOPER);
//If not specified use utf8
if (empty($encoding)) {
$encoding = 'UTF-8';
}
//Use text services
return textlib::strtolower($string, $encoding);
}
/**
* Original singleton helper function, please use static methods instead,
* ex: textlib::convert()
*
* @deprecated since Moodle 2.1 use textlib::xxxx() instead
* @see textlib
* @return textlib instance
*/
function textlib_get_instance() {
debugging('textlib_get_instance() is deprecated. Please use static calling textlib::functioname() instead.', DEBUG_DEVELOPER);
return new textlib();
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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 *

View File

@ -1348,13 +1348,13 @@ function filter_remove_duplicates($linkarray) {
if ($filterobject->casesensitive) {
$exists = in_array($filterobject->phrase, $concepts);
} else {
$exists = in_array(moodle_strtolower($filterobject->phrase), $lconcepts);
$exists = in_array(textlib::strtolower($filterobject->phrase), $lconcepts);
}
if (!$exists) {
$cleanlinks[] = $filterobject;
$concepts[] = $filterobject->phrase;
$lconcepts[] = moodle_strtolower($filterobject->phrase);
$lconcepts[] = textlib::strtolower($filterobject->phrase);
}
}

View File

@ -1331,7 +1331,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
} else { //if setShowAdvanced is called without any preference
//make the default to not show advanced elements.
$showadvancedNow = get_user_preferences(
moodle_strtolower($this->_formName.'_showadvanced', 0));
textlib::strtolower($this->_formName.'_showadvanced', 0));
}
}
//value of hidden element

View File

@ -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);

View File

@ -599,7 +599,6 @@ class html2text
*/
function _strtoupper($str)
{
$tl = textlib_get_instance();
return $tl->strtoupper($str);
return textlib::strtoupper($str);
}
}

View File

@ -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);
}
}

View File

@ -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:
@ -1074,7 +1073,7 @@ function clean_param($param, $type) {
case PARAM_USERNAME:
$param = fix_utf8($param);
$param = str_replace(" " , "", $param);
$param = moodle_strtolower($param); // Convert uppercase to lowercase MDL-16919
$param = textlib::strtolower($param); // Convert uppercase to lowercase MDL-16919
if (empty($CFG->extendedusernamechars)) {
// regular expression, eliminate all chars EXCEPT:
// alphanum, dash (-), underscore (_), at sign (@) and period (.) characters.
@ -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');
}
}
@ -3654,7 +3652,7 @@ function create_user_record($username, $password, $auth = 'manual') {
global $CFG, $DB;
//just in case check text case
$username = trim(moodle_strtolower($username));
$username = trim(textlib::strtolower($username));
$authplugin = get_auth_plugin($auth);
@ -3716,7 +3714,7 @@ function create_user_record($username, $password, $auth = 'manual') {
function update_user_record($username) {
global $DB, $CFG;
$username = trim(moodle_strtolower($username)); /// just in case check text case
$username = trim(textlib::strtolower($username)); /// just in case check text case
$oldinfo = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
$newuser = array();
@ -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 .= '<div>'. get_string('errorminpasswordlength', 'auth', $CFG->minpasswordlength) .'</div>';
}
@ -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));
}
}
}
@ -8736,29 +8731,6 @@ function moodle_setlocale($locale='') {
}
}
/**
* Converts string to lowercase using most compatible function available.
*
* @deprecated since Moodle 2.0 use textlib::strtolower()
* @todo MDL-31250 Remove this function when no longer in use
* @see textlib::strtolower($text)
*
* @param string $string The string to convert to all lowercase characters.
* @param string $encoding The encoding on the string.
* @return string
*/
function moodle_strtolower ($string, $encoding='') {
//If not specified use utf8
if (empty($encoding)) {
$encoding = 'UTF-8';
}
//Use text services
$textlib = textlib_get_instance();
return $textlib->strtolower($string, $encoding);
}
/**
* Count words in a string.
*
@ -8783,12 +8755,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 +9867,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;
}

View File

@ -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);
}

View File

@ -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') {

View File

@ -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},

View File

@ -275,6 +275,11 @@ class textlib_test extends UnitTestCase {
}
public function test_deprecated_textlib_get_instance() {
global $CFG;
$debugging = $CFG->debug;
$CFG->debug = DEBUG_NORMAL;
$textlib = textlib_get_instance();
$this->assertIdentical($textlib->substr('abc', 1, 1), 'b');
$this->assertIdentical($textlib->strlen('abc'), 3);
@ -285,6 +290,8 @@ class textlib_test extends UnitTestCase {
$this->assertIdentical($textlib->strrpos('abcabc', 'a'), 3);
$this->assertIdentical($textlib->specialtoascii('ábc'), 'abc');
$this->assertIdentical($textlib->strtotitle('abc ABC'), 'Abc Abc');
$CFG->debug = $debugging;
}
}

View File

@ -68,10 +68,9 @@ class web_test extends UnitTestCase {
format_text_email('<p class="frogs">This is a <strong class=\'fishes\'>test</strong></p>',FORMAT_HTML));
$this->assertEqual('& so is this',
format_text_email('&amp; 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: &#x2022; &#8226;',FORMAT_HTML));
$this->assertEqual($tl->code2utf8(0x7fd2).$tl->code2utf8(0x7fd2),
$this->assertEqual(textlib::code2utf8(0x7fd2).textlib::code2utf8(0x7fd2),
format_text_email('&#x7fd2;&#x7FD2;',FORMAT_HTML));
}

View File

@ -24,20 +24,6 @@
defined('MOODLE_INTERNAL') || die();
/**
* Original singleton helper function, please use static methods instead,
* ex: textlib::convert()
*
* @deprecated since Moodle 2.1 MDL-29027 textlib contains static functions
* @todo MDL-31301 calling of textlib functions should be static.
* @see textlib
* @return textlib instance
*/
function textlib_get_instance() {
return new textlib();
}
/**
* defines string api's for manipulating strings
*

View File

@ -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);
}

View File

@ -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 {
@ -1702,7 +1699,7 @@ function highlightfast($needle, $haystack) {
return $haystack;
}
$parts = explode(moodle_strtolower($needle), moodle_strtolower($haystack));
$parts = explode(textlib::strtolower($needle), textlib::strtolower($haystack));
if (count($parts) === 1) {
return $haystack;

View File

@ -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 {

View File

@ -113,7 +113,7 @@ if ($user !== false or $frm !== false or $errormsg !== '') {
if ($frm and isset($frm->username)) { // Login WITH cookies
$frm->username = trim(moodle_strtolower($frm->username));
$frm->username = trim(textlib::strtolower($frm->username));
if (is_enabled_auth('none') ) {
if ($frm->username !== clean_param($frm->username, PARAM_USERNAME)) {

View File

@ -129,7 +129,7 @@ class login_signup_form extends moodleform {
$errors['username'] = get_string('usernameexists');
} else {
//check allowed characters
if ($data['username'] !== moodle_strtolower($data['username'])) {
if ($data['username'] !== textlib::strtolower($data['username'])) {
$errors['username'] = get_string('usernamelowercase');
} else {
if ($data['username'] !== clean_param($data['username'], PARAM_USERNAME)) {

View File

@ -35,7 +35,7 @@ echo $OUTPUT->header();
if (!$CFG->enablewebservices) {
throw new moodle_exception('enablewsdescription', 'webservice');
}
$username = trim(moodle_strtolower($username));
$username = trim(textlib::strtolower($username));
if (is_restored_user($username)) {
throw new moodle_exception('restoredaccountresetpassword', 'webservice');
}

View File

@ -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;
}

View File

@ -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');

View File

@ -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

View File

@ -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);
}
}

View File

@ -118,7 +118,7 @@ class mod_glossary_entry_form extends moodleform {
if ($DB->record_exists_select('glossary_entries',
'glossaryid = :glossaryid AND LOWER(concept) = :concept AND id != :id', array(
'glossaryid' => $glossary->id,
'concept' => moodle_strtolower($data['concept']),
'concept' => textlib::strtolower($data['concept']),
'id' => $id))) {
$errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
}
@ -129,7 +129,7 @@ class mod_glossary_entry_form extends moodleform {
if ($DB->record_exists_select('glossary_entries',
'glossaryid = :glossaryid AND LOWER(concept) = :concept', array(
'glossaryid' => $glossary->id,
'concept' => moodle_strtolower($data['concept'])))) {
'concept' => textlib::strtolower($data['concept'])))) {
$errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
}
}

View File

@ -72,7 +72,7 @@ $strglossary = get_string("modulename", "glossary");
$PAGE->navbar->add($strglossaries, new moodle_url('/mod/glossary/index.php', array('id'=>$course->id)));
$PAGE->navbar->add(get_string("categories","glossary"));
if (!empty($action)) {
$navaction = get_string($action). " " . moodle_strtolower(get_string("category","glossary"));
$navaction = get_string($action). " " . textlib::strtolower(get_string("category","glossary"));
$PAGE->navbar->add($navaction);
}
$PAGE->set_title(format_string($glossary->name));

View File

@ -72,7 +72,7 @@ if (!$mainglossary->allowduplicatedentries) {
if ($DB->record_exists_select('glossary_entries',
'glossaryid = :glossaryid AND LOWER(concept) = :concept', array(
'glossaryid' => $mainglossary->id,
'concept' => moodle_strtolower($entry->concept)))) {
'concept' => textlib::strtolower($entry->concept)))) {
$PAGE->set_title(format_string($glossary->name));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();

View File

@ -213,7 +213,7 @@ if ($xml = glossary_read_imported_file($result)) {
$dupentry = $DB->record_exists_select('glossary_entries',
'glossaryid = :glossaryid AND LOWER(concept) = :concept', array(
'glossaryid' => $glossary->id,
'concept' => moodle_strtolower($newentry->concept)));
'concept' => textlib::strtolower($newentry->concept)));
}
if ($dupentry) {
$permissiongranted = 0;

View File

@ -871,7 +871,7 @@ function glossary_get_entries_search($concept, $courseid) {
$bypassteacher = 0; //This means YES
}
$conceptlower = moodle_strtolower(trim($concept));
$conceptlower = textlib::strtolower(trim($concept));
$params = array('courseid1'=>$courseid, 'courseid2'=>$courseid, 'conceptlower'=>$conceptlower, 'concept'=>$concept);
@ -1947,9 +1947,9 @@ function glossary_print_sorting_links($cm, $mode, $sortkey = '',$sortorder = '')
*/
function glossary_sort_entries ( $entry0, $entry1 ) {
if ( moodle_strtolower(ltrim($entry0->concept)) < moodle_strtolower(ltrim($entry1->concept)) ) {
if ( textlib::strtolower(ltrim($entry0->concept)) < textlib::strtolower(ltrim($entry1->concept)) ) {
return -1;
} elseif ( moodle_strtolower(ltrim($entry0->concept)) > moodle_strtolower(ltrim($entry1->concept)) ) {
} elseif ( textlib::strtolower(ltrim($entry0->concept)) > textlib::strtolower(ltrim($entry1->concept)) ) {
return 1;
} else {
return 0;

View File

@ -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

View File

@ -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

View File

@ -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&amp;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

View File

@ -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)) {

View File

@ -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;

View File

@ -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');

View File

@ -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');

View File

@ -367,7 +367,7 @@ function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='officia
//add tag if does not exist
if (!$tagid = tag_get_id($tag)) {
$tag_id_array = tag_add(array($tag), $tagtype);
$tagid = $tag_id_array[moodle_strtolower($tag)];
$tagid = $tag_id_array[textlib::strtolower($tag)];
}
//ordering
$ordering = 0;
@ -691,8 +691,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;
}

View File

@ -286,7 +286,7 @@ function tag_get($field, $value, $returnfields='id, name, rawname') {
global $DB;
if ($field == 'name') {
$value = moodle_strtolower($value); // To cope with input that might just be wrong case
$value = textlib::strtolower($value); // To cope with input that might just be wrong case
}
return $DB->get_record('tag', array($field=>$value), $returnfields);
}
@ -446,7 +446,7 @@ function tag_get_id($tags, $return_value=null) {
//TODO MDL-31152 test this and see if it helps performance without breaking anything
//foreach($tags as $key => $tag) {
// $clean_tag = moodle_strtolower($tag);
// $clean_tag = textlib::strtolower($tag);
// if ( array_key_exists($clean_tag), $tag_id_cache) ) {
// $result[$clean_tag] = $tag_id_cache[$clean_tag];
// $tags[$key] = ''; // prevent further processing for this one.
@ -455,8 +455,8 @@ function tag_get_id($tags, $return_value=null) {
$tags = array_values(tag_normalize($tags));
foreach($tags as $key => $tag) {
$tags[$key] = moodle_strtolower($tag);
$result[moodle_strtolower($tag)] = null; // key must exists : no value for a key means the tag wasn't found.
$tags[$key] = textlib::strtolower($tag);
$result[textlib::strtolower($tag)] = null; // key must exists : no value for a key means the tag wasn't found.
}
if (empty($tags)) {
@ -562,7 +562,7 @@ function tag_rename($tagid, $newrawname) {
return false;
}
if (! $newname_clean = moodle_strtolower($newrawname_clean)) {
if (! $newname_clean = textlib::strtolower($newrawname_clean)) {
return false;
}
@ -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;
@ -760,7 +759,7 @@ function tag_add($tags, $type="default") {
// note that the difference between rawname and name is only
// capitalization : the rawname is NOT the same at the rawtag.
$tag_object->rawname = $tag;
$tag_name_lc = moodle_strtolower($tag);
$tag_name_lc = textlib::strtolower($tag);
$tag_object->name = $tag_name_lc;
//var_dump($tag_object);
$tags_ids[$tag_name_lc] = $DB->insert_record('tag', $tag_object);
@ -813,7 +812,7 @@ function tag_autocomplete($text) {
global $DB;
return $DB->get_records_sql("SELECT tg.id, tg.name, tg.rawname
FROM {tag} tg
WHERE tg.name LIKE ?", array(moodle_strtolower($text)."%"));
WHERE tg.name LIKE ?", array(textlib::strtolower($text)."%"));
}
/**
@ -1123,7 +1122,7 @@ function tag_normalize($rawtags, $case = TAG_CASE_LOWER) {
continue;
}
if ( !array_key_exists($rawtag, $cleaned_tags_lc) ) {
$cleaned_tags_lc[$rawtag] = moodle_strtolower( clean_param($rawtag, PARAM_TAG) );
$cleaned_tags_lc[$rawtag] = textlib::strtolower( clean_param($rawtag, PARAM_TAG) );
$cleaned_tags_mc[$rawtag] = clean_param($rawtag, PARAM_TAG);
}
if ( $case == TAG_CASE_LOWER ) {

View File

@ -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 .= '<strong>'. $fullname .'</strong>';

View File

@ -169,7 +169,7 @@ class user_editadvanced_form extends moodleform {
$err['username'] = get_string('usernameexists');
}
//check allowed characters
if ($usernew->username !== moodle_strtolower($usernew->username)) {
if ($usernew->username !== textlib::strtolower($usernew->username)) {
$err['username'] = get_string('usernamelowercase');
} else {
if ($usernew->username !== clean_param($usernew->username, PARAM_USERNAME)) {