Skip to content

Commit

Permalink
Merge branch 'w10_MDL-31301_m23_textlibcleanup' of git://github.com/s…
Browse files Browse the repository at this point in the history
…kodak/moodle
  • Loading branch information
stronk7 committed Mar 6, 2012
2 parents 050bce5 + 3fed29a commit 2ed7cc2
Show file tree
Hide file tree
Showing 73 changed files with 291 additions and 420 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
4 changes: 2 additions & 2 deletions admin/roles/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ public function read_submitted_permissions() {
$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');
}
Expand Down
14 changes: 5 additions & 9 deletions admin/tool/uploaduser/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/uploaduser/user_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ function definition () {
$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');

Expand Down
11 changes: 5 additions & 6 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 All @@ -364,8 +364,7 @@ function iscreator($username) {
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)) {
Expand Down
74 changes: 31 additions & 43 deletions auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ function user_login($username, $password) {
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.
Expand Down Expand Up @@ -199,8 +198,7 @@ function user_login($username, $password) {
* @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))) {
Expand Down Expand Up @@ -245,9 +243,9 @@ function get_userinfo($username) {
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;
Expand Down Expand Up @@ -298,8 +296,7 @@ function get_userlist() {
* @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).')');
Expand All @@ -315,9 +312,8 @@ function user_exists($username) {
* @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':
Expand All @@ -342,7 +338,7 @@ function user_create($userobject, $plainpass) {
}
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);
}
}
}
Expand Down Expand Up @@ -570,8 +566,7 @@ function user_confirm($username, $confirmsecret) {
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);
Expand Down Expand Up @@ -616,7 +611,6 @@ function sync_users($do_updates=true) {
print_string('connectingldap', 'auth_ldap');
$ldapconnection = $this->ldap_connect();

$textlib = textlib_get_instance();
$dbman = $DB->get_manager();

/// Define table user to be created
Expand Down Expand Up @@ -667,7 +661,7 @@ function sync_users($do_updates=true) {
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));
}
Expand Down Expand Up @@ -845,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 @@ -889,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 @@ -934,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 All @@ -947,8 +941,7 @@ function ldap_bulk_insert($username) {
* @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();

Expand Down Expand Up @@ -998,8 +991,7 @@ function iscreator($username) {
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();

Expand Down Expand Up @@ -1057,8 +1049,7 @@ function user_update($olduser, $newuser) {
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();

Expand Down Expand Up @@ -1112,9 +1103,9 @@ function user_update($olduser, $newuser) {
$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;
Expand Down Expand Up @@ -1210,9 +1201,8 @@ function user_update_password($user, $newpassword) {
$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':
Expand Down Expand Up @@ -1380,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 @@ -1435,9 +1425,8 @@ function ldap_get_userlist($filter='*') {
$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);
}
Expand Down Expand Up @@ -1575,8 +1564,7 @@ function ntlmsso_magic($sesskey) {
// (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':
Expand All @@ -1592,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 @@ -1794,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
Loading

0 comments on commit 2ed7cc2

Please sign in to comment.