Skip to content

Commit

Permalink
MDL-31301 use static textlib methods
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Mar 3, 2012
1 parent 5bbf3cb commit f8311de
Show file tree
Hide file tree
Showing 53 changed files with 191 additions and 329 deletions.
2 changes: 1 addition & 1 deletion admin/roles/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ 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 = textlib::specialtoascii($this->role->shortname);
$this->role->shortname = moodle_strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT));
if (empty($this->role->shortname)) {
$this->errors['shortname'] = get_string('errorbadroleshortname', 'role');
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
3 changes: 1 addition & 2 deletions auth/cas/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 20 additions & 32 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 @@ -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 @@ -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 Down
3 changes: 1 addition & 2 deletions backup/converter/moodle1/handlerlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,7 @@ public function process_question(array $data, array $raw) {

// 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'] . '" />';

Expand Down
6 changes: 1 addition & 5 deletions backup/converter/moodle1/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -1187,7 +1184,6 @@ public function __construct(moodle1_converter $converter, $contextid = null, $co
$this->userid = $userid;
// set other useful bits
$this->basepath = $converter->get_tempdir_path();
$this->textlib = textlib_get_instance();
}

/**
Expand Down Expand Up @@ -1218,7 +1214,7 @@ public function migrate_file($sourcepath, $filepath = '/', $filename = null, $so
}
$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');
}

Expand Down
49 changes: 21 additions & 28 deletions blocks/navigation/block_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,81 +242,74 @@ public function html_attributes() {
* @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;
}
Expand Down
7 changes: 2 additions & 5 deletions blocks/rss_client/block_rss_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,10 @@ function get_item_html($item){
*/
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).'...');
}
}

Expand Down
Loading

0 comments on commit f8311de

Please sign in to comment.