Skip to content

Commit

Permalink
MDL-29014 fix a few incorrect uses of strlen and substr
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 10, 2011
1 parent 5d2db8a commit 138c767
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions admin/registration/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public function definition() {
$options = array();
foreach ($hubs as $hub) {
//to not display a name longer than 100 character (too big)
if (strlen($hub['name']) > 100) {
$hubname = substr($hub['name'], 0, 100);
if (textlib::strlen($hub['name']) > 100) {
$hubname = textlib::substr($hub['name'], 0, 100);
$hubname = $hubname . "...";
} else {
$hubname = $hub['name'];
Expand Down
4 changes: 2 additions & 2 deletions blocks/navigation/block_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function trim(navigation_node $node, $mode=1, $long=50, $short=25, $recur
// Truncate the text to $long characters
$node->text = $this->trim_left($textlib, $node->text, $long);
}
if (is_string($node->shorttext) && 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);
}
Expand All @@ -262,7 +262,7 @@ public function trim(navigation_node $node, $mode=1, $long=50, $short=25, $recur
// Truncate the text to $long characters
$node->text = $this->trim_center($textlib, $node->text, $long);
}
if (is_string($node->shorttext) && 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);
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/rss_client/block_rss_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function get_item_html($item){

if(empty($title)){
// no title present, use portion of description
$title = substr(strip_tags($description), 0, 20) . '...';
$title = textlib::substr(strip_tags($description), 0, 20) . '...';
}else{
$title = break_up_long_words($title, 30);
}
Expand Down
4 changes: 2 additions & 2 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3255,11 +3255,11 @@ function make_editing_buttons(stdClass $mod, $absolute = true, $moveselect = tru
function course_format_name ($course,$max=100) {

$str = $course->shortname.': '. $course->fullname;
if (strlen($str) <= $max) {
if (textlib::strlen($str) <= $max) {
return $str;
}
else {
return substr($str,0,$max-3).'...';
return textlib::substr($str,0,$max-3).'...';
}
}

Expand Down
8 changes: 4 additions & 4 deletions course/report/log/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select
}
$section = $mod->section;
$mod->name = strip_tags(format_string($mod->name, true));
if (strlen($mod->name) > 55) {
$mod->name = substr($mod->name, 0, 50)."...";
if (textlib::strlen($mod->name) > 55) {
$mod->name = textlib::substr($mod->name, 0, 50)."...";
}
if (!$mod->visible) {
$mod->name = "(".$mod->name.")";
Expand Down Expand Up @@ -394,8 +394,8 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
}
$section = $mod->section;
$mod->name = strip_tags(format_string($mod->name, true));
if (strlen($mod->name) > 55) {
$mod->name = substr($mod->name, 0, 50)."...";
if (textlib::strlen($mod->name) > 55) {
$mod->name = textlib::substr($mod->name, 0, 50)."...";
}
if (!$mod->visible) {
$mod->name = "(".$mod->name.")";
Expand Down
8 changes: 4 additions & 4 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2233,10 +2233,10 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
if ($course->format == 'weeks' or empty($thissection->summary)) {
$item = $strsection ." ". $mod->sectionnum;
} else {
if (strlen($thissection->summary) < ($width-3)) {
if (textlib::strlen($thissection->summary) < ($width-3)) {
$item = $thissection->summary;
} else {
$item = substr($thissection->summary, 0, $width).'...';
$item = textlib::substr($thissection->summary, 0, $width).'...';
}
}
$menu[] = '<li class="section"><span>'.$item.'</span>';
Expand All @@ -2252,8 +2252,8 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid

$url = $mod->modname .'/view.php?id='. $mod->id;
$mod->name = strip_tags(format_string($mod->name ,true));
if (strlen($mod->name) > ($width+5)) {
$mod->name = substr($mod->name, 0, $width).'...';
if (textlib::strlen($mod->name) > ($width+5)) {
$mod->name = textlib::substr($mod->name, 0, $width).'...';
}
if (!$mod->visible) {
$mod->name = '('.$mod->name.')';
Expand Down
4 changes: 2 additions & 2 deletions mod/survey/download.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
/// Sending HTTP headers
$workbook->send($downloadfilename);
/// Creating the first worksheet
$myxls =& $workbook->add_worksheet(substr(strip_tags(format_string($survey->name,true)), 0, 31));
$myxls =& $workbook->add_worksheet(textlib::substr(strip_tags(format_string($survey->name,true)), 0, 31));

$header = array("surveyid","surveyname","userid","firstname","lastname","email","idnumber","time", "notes");
$col=0;
Expand Down Expand Up @@ -232,7 +232,7 @@
/// Sending HTTP headers
$workbook->send($downloadfilename);
/// Creating the first worksheet
$myxls =& $workbook->add_worksheet(substr(strip_tags(format_string($survey->name,true)), 0, 31));
$myxls =& $workbook->add_worksheet(textlib::substr(strip_tags(format_string($survey->name,true)), 0, 31));

$header = array("surveyid","surveyname","userid","firstname","lastname","email","idnumber","time", "notes");
$col=0;
Expand Down
4 changes: 2 additions & 2 deletions mod/wiki/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1300,8 +1300,8 @@ function wiki_print_page_content($page, $context, $subwikiid) {
*/
function wiki_trim_string($text, $limit = 25) {

if (strlen($text) > $limit) {
$text = substr($text, 0, $limit) . '...';
if (textlib::strlen($text) > $limit) {
$text = textlib::substr($text, 0, $limit) . '...';
}

return $text;
Expand Down
2 changes: 1 addition & 1 deletion mod/wiki/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ private function print_page_list_content() {
$strspecial = get_string('special', 'wiki');

foreach ($pages as $page) {
$letter = strtoupper(substr($page->title, 0, 1));
$letter = textlib::strtoupper(textlib::substr($page->title, 0, 1));
if (preg_match('/[A-Z]/', $letter)) {
$stdaux->{
$letter}
Expand Down
4 changes: 2 additions & 2 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1773,8 +1773,8 @@ public static function instance_form_validation($mform, $data, $errors) {
}

public function get_short_filename($str, $maxlength) {
if (strlen($str) >= $maxlength) {
return trim(substr($str, 0, $maxlength)).'...';
if (textlib::strlen($str) >= $maxlength) {
return trim(textlib::substr($str, 0, $maxlength)).'...';
} else {
return $str;
}
Expand Down

0 comments on commit 138c767

Please sign in to comment.