Skip to content

Commit

Permalink
MDL-31301 remove all uses of moodle_strtolower() and deprecated it
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Mar 3, 2012
1 parent f8311de commit 6f3451e
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 78 deletions.
2 changes: 1 addition & 1 deletion admin/mnet/access_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
$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') {
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ public function read_submitted_permissions() {
if (!is_null($shortname)) {
$this->role->shortname = $shortname;
$this->role->shortname = textlib::specialtoascii($this->role->shortname);
$this->role->shortname = moodle_strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT));
$this->role->shortname = textlib::strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT));
if (empty($this->role->shortname)) {
$this->errors['shortname'] = get_string('errorbadroleshortname', 'role');
}
Expand Down
8 changes: 4 additions & 4 deletions auth/cas/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function prevent_local_passwords() {
*/
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);
}

/**
Expand Down Expand Up @@ -336,15 +336,15 @@ function process_config($config) {
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);
Expand Down
22 changes: 11 additions & 11 deletions auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ function sync_users($do_updates=true) {
$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;
}
Expand Down Expand Up @@ -883,7 +883,7 @@ function update_user_record($username, $updatekeys = false) {
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));
Expand Down Expand Up @@ -928,7 +928,7 @@ function update_user_record($username, $updatekeys = false) {
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 '.';
Expand Down Expand Up @@ -1370,13 +1370,13 @@ function ldap_attributes () {
$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;
}

Expand Down Expand Up @@ -1580,7 +1580,7 @@ function ntlmsso_magic($sesskey) {
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;
}
Expand Down Expand Up @@ -1782,24 +1782,24 @@ function process_config($config) {
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);
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('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);
Expand Down
2 changes: 1 addition & 1 deletion backup/restorelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function restore_create_messages($restore,$xml_file) {
//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) {
Expand Down
6 changes: 3 additions & 3 deletions backup/util/dbops/backup_plan_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static function get_default_backup_filename($format, $type, $id, $users,
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 = '';
Expand All @@ -228,15 +228,15 @@ public static function get_default_backup_filename($format, $type, $id, $users,
break;
}
$shortname = str_replace(' ', '_', $shortname);
$shortname = moodle_strtolower(trim(clean_filename($shortname), '_'));
$shortname = textlib::strtolower(trim(clean_filename($shortname), '_'));
}

$name = empty($shortname) ? $id : $shortname;

// 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 = '';
Expand Down
2 changes: 1 addition & 1 deletion backup/util/helper/backup_cron_helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public static function remove_excess_backups($course) {
$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)) {
Expand Down
4 changes: 2 additions & 2 deletions enrol/ldap/settingslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function write_setting($data) {
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'));
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public function write_setting($data) {
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');
}
}
Expand Down
10 changes: 5 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -194,21 +194,21 @@

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'));
}
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);
Expand All @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4000,3 +4000,24 @@ 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);
}
4 changes: 2 additions & 2 deletions lib/filterlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1347,13 +1347,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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/formslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ function setShowAdvanced($showadvancedNow = null){
} 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
Expand Down
27 changes: 3 additions & 24 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,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.
Expand Down Expand Up @@ -3652,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);

Expand Down Expand Up @@ -3714,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();
Expand Down Expand Up @@ -8731,27 +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
return textlib::strtolower($string, $encoding);
}

/**
* Count words in a string.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1699,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;
Expand Down
2 changes: 1 addition & 1 deletion login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

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)) {
Expand Down
Loading

0 comments on commit 6f3451e

Please sign in to comment.