From 1f02027b481507b4960360e9224a225674c40852 Mon Sep 17 00:00:00 2001 From: Tom Lake <tswsl1989@sucs.org> Date: Wed, 29 Jun 2011 11:06:05 +0000 Subject: [PATCH] Fix warnings related to ereg/eregi/ereg_match and split --- components/blogfeed.php | 4 ++-- components/contents.php | 2 +- components/email.php | 8 ++++---- components/events.php | 2 +- components/front.php | 3 ++- components/mw.php | 6 +++--- components/projects.php | 2 +- lib/blog/admin.lib.php | 2 +- lib/blog/blog.lib.php | 2 +- lib/blog/miscfunctions.lib.php | 4 ++-- lib/blog/validation.lib.php | 2 +- lib/sanitization.php | 2 +- lib/session.php | 2 +- lib/validation.php | 14 +++++++------- 14 files changed, 28 insertions(+), 27 deletions(-) diff --git a/components/blogfeed.php b/components/blogfeed.php index 70527c5..25c27f7 100644 --- a/components/blogfeed.php +++ b/components/blogfeed.php @@ -64,7 +64,7 @@ if (count($result) > 0) { } if($feedtype=='atom') { //this should be a date type c when we are on php5, untill then, this nasty hack should work. - $pubdate = ereg_replace(' ', 'T', $row['timestamp']).":00"; + $pubdate = preg_replace('/ /', 'T', $row['timestamp']).":00"; } $entries = ""; //output this entry @@ -85,7 +85,7 @@ if (count($result) > 0) { } if($feedtype=='atom') { do { - $entrydate = ereg_replace(' ', 'T', $row['timestamp']).":00"; + $entrydate = preg_replace('/ /', 'T', $row['timestamp']).":00"; $entries .= "\t<entry>\n"; $entries .= "\t\t<title>".htmlentities($row['subject'])."</title>\n"; $entries .= "\t\t<link rel=\"alternate\" type=\"text/html\" href=\"".$user['link']."entry/".$row['shortsubject']."\"/>\n"; diff --git a/components/contents.php b/components/contents.php index 451911e..8ef4da0 100644 --- a/components/contents.php +++ b/components/contents.php @@ -10,7 +10,7 @@ function listdir($mypath, $recurse, $summaries) { if ($file[0]!=".") { $element = array(); if (!is_dir($base."static".$mypath."/".$file)) { - $pagename = ereg_replace("\.txt", "", $file); + $pagename = preg_replace("/\.txt/", "", $file); if ($summaries) $element['summary'] = $DB->GetOne("select summary from static where path=?", array($mypath."/".$pagename)); if ($pagename!=@$lastdir) $output[$pagename]=str_replace("_", " ", $element); } else { diff --git a/components/email.php b/components/email.php index fa151b7..2d9c9a2 100644 --- a/components/email.php +++ b/components/email.php @@ -8,7 +8,7 @@ $subject = "Join request for user ".$_REQUEST['uname']; // Perform data integrity checks // Full name -if (ereg("[:/<>]", $_REQUEST['realname'])) { +if (preg_match("/[^\p{L}- ]/iu", $_REQUEST['realname'])) { $body .= "<p>That's a suspiciously unusual-looking name, <strong>" . htmlentities($_REQUEST['realname']) . "</strong>.</p>\n"; $body .= "<p>Please click <em>Back</em> and correct it.</p>\n"; } else { @@ -18,14 +18,14 @@ if (!is_numeric($_REQUEST['student_number']) || strlen($_REQUEST['student_number $body .= "<p>Please click <em>Back</em> and correct it.</p>\n"; } else { // Email address - list($username, $maildomain) = split("@", $_REQUEST['email']); + list($username, $maildomain) = preg_split("/@/", $_REQUEST['email']); if (!checkdnsrr($maildomain, "MX") && !checkdnsrr($maildomain)) { $body .= "<p>The email address <strong>" . htmlentities($_REQUEST['email']) . "</strong> appears not to be valid.</p>\n"; $body .= "<p>Please click <em>Back</em> and correct it.</p>\n"; } else { // Username // This test is rather inadequate. Needs improving - if (ereg("[:/<>]", $_REQUEST['uname'])) { + if (!preg_match("/^[a-z0-9_]*$/i", $_REQUEST['uname'])) { $body .= "<p>Usernames can only contain letters, numbers and underscores(_).</p>\n"; $body .= "<p>Please click <em>Back</em> and choose a different one.</p>\n"; } else { @@ -58,4 +58,4 @@ $smarty->assign("body", $body); $smarty->assign("title", "Joining"); $pathlist[2] = "Joining"; $smarty->assign("subselect", "Joining"); -?> \ No newline at end of file +?> diff --git a/components/events.php b/components/events.php index 830581f..64c30c4 100644 --- a/components/events.php +++ b/components/events.php @@ -13,7 +13,7 @@ $smarty->assign("event_categories", $eventcategories); $events_index = array_search("Events", $pathlist); if (isset($pathlist[$events_index + 1])) { - list($eventcat, $eventid) = split("_", $pathlist[$events_index + 1]); + list($eventcat, $eventid) = preg_split("/_/", $pathlist[$events_index + 1]); if (!in_array($eventcat, $eventcategories)) { trigger_error("Invalid category specified", E_USER_ERROR); unset($eventcat, $eventid); diff --git a/components/front.php b/components/front.php index 9e1034a..88fe8d8 100644 --- a/components/front.php +++ b/components/front.php @@ -8,7 +8,8 @@ $smarty->assign("body", $output); if (!$session->loggedin) { $output = file_get_contents("../static/fragments/Join.txt"); } else { - $output = "<div class=\"cbb\"><h3>You are logged in</h3><p>If you would like to contribute to the site or report a bug, please contact chckens or dez.</p></div>"; +// $output = "<div class=\"cbb\"><h3>You are logged in</h3><p>If you would like to contribute to the site or report a bug, please contact chckens or dez.</p></div>"; + $output = "<div class=\"cbb\"><h3>You are logged in</h3><p style=\"text-align: center;\">Why not join our <a href=\"#\" onclick=\"window.open('/mw/','Milliways','height=600,width=800,menubar=no,resizable=yes,location=no,directories=no,scrollbars=yes,status=no,toolbar=no')\" style=\"font-size: 150%; font-weight: bold; color: #ffc62b;\">Live Chat</a>?</p></div>"; //include('users.php'); //$output .= $result; include('electionreminder.php'); diff --git a/components/mw.php b/components/mw.php index e1aa3e1..cc6b754 100755 --- a/components/mw.php +++ b/components/mw.php @@ -94,9 +94,9 @@ function post_article($folder, $user, $replyto) $subject = strip_tags($_POST['subject']); $body = strip_tags( $_POST['body']); - $to = ereg_replace('[^[:alnum:][:punct:][:space:]]*','',trim($to)); - $subject = ereg_replace('[^[:alnum:][:punct:][:space:]]*','',trim($subject)); - $body = ereg_replace("\n\\.\n","\n .\n",$body); + $to = preg_replace('/[^[:alnum:][:punct:][:space:]]*/','',trim($to)); + $subject = preg_replace('/[^[:alnum:][:punct:][:space:]]*/','',trim($subject)); + $body = preg_replace("/\n\\.\n","\n .\n/",$body); $deb = fopen("/tmp/mwdebug.txt","w"); fwrite($deb, "folder: '$folder'\n"); diff --git a/components/projects.php b/components/projects.php index 66bcd43..401616d 100644 --- a/components/projects.php +++ b/components/projects.php @@ -20,7 +20,7 @@ foreach ($dirlist as $file) { } else if ($projectsection && (1 == preg_match("/^\[.*\]$/", trim($ini_line)))) { $projectsection = FALSE; } else if ($projectsection) { - list($key, $value) = split("=", $ini_line); + list($key, $value) = preg_split("/=/", $ini_line); $ini_array[trim($key)] = trim($value); } } diff --git a/lib/blog/admin.lib.php b/lib/blog/admin.lib.php index 11fae92..38fb2eb 100644 --- a/lib/blog/admin.lib.php +++ b/lib/blog/admin.lib.php @@ -774,7 +774,7 @@ class admin { } //if we have an add action elseif(isset($_POST['addnew'])) { - if(trim($_POST['name'])=="" or !eregi("^([a-z0-9]+([:space:][a-z0-9]*))$",trim($_POST['name']))) { + if(trim($_POST['name'])=="" or !preg_match("/^([a-z0-9]+([:space:][a-z0-9]*))$/i",trim($_POST['name']))) { $this->error = _("Check name"); } if(!validEmail($_POST['email'])) { diff --git a/lib/blog/blog.lib.php b/lib/blog/blog.lib.php index bbdc8a8..5eff1d9 100644 --- a/lib/blog/blog.lib.php +++ b/lib/blog/blog.lib.php @@ -621,7 +621,7 @@ class blogs { } //sanitse author if (isset($_POST['author']) && trim($_POST['author']) != "") { - if(eregi("^([a-z0-9]+ *)+$", $_POST['author'])) { + if(preg_match("/^([a-z0-9]+ *)+$/i", $_POST['author'])) { $author = addslashes(nl2br(trim(strip_tags($_POST['author'])))); } else { $this->commentError = _("Invalid name. We only allow alphanumeric names!"); diff --git a/lib/blog/miscfunctions.lib.php b/lib/blog/miscfunctions.lib.php index 0e932d9..96d87f1 100644 --- a/lib/blog/miscfunctions.lib.php +++ b/lib/blog/miscfunctions.lib.php @@ -75,9 +75,9 @@ function getSVNRevision() function checkSpamURLs($text) { $spam = false; //find urls, ugly but works - while (ereg("http://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}",$text,$match)) { + while (preg_match("/http://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/",$text,$match)) { $matches[] = $match[0]; - $text = ereg_replace($match[0],"",$text); + $text = preg_replace("/".$match[0]."/","",$text); //Can this be replaced with str_replace? } //pull in list of two level tlds, make an array from them. from http://spamcheck.freeapp.net/two-level-tlds $twoLevelTLD = file("/var/www/sucssite/lib/blog/two-level-tlds"); diff --git a/lib/blog/validation.lib.php b/lib/blog/validation.lib.php index 401a179..a8d149e 100644 --- a/lib/blog/validation.lib.php +++ b/lib/blog/validation.lib.php @@ -3,7 +3,7 @@ function safeuname($name) { if (strlen($name) < 2) return FALSE; - return ereg("^[a-z][a-z0-9_]*$", $name); + return preg_match("/^[a-z][a-z0-9_]*$/i", $name); } // Find out if a given user has a blog diff --git a/lib/sanitization.php b/lib/sanitization.php index 04c444c..0929059 100644 --- a/lib/sanitization.php +++ b/lib/sanitization.php @@ -1,6 +1,6 @@ <? function sanitizePhone($phone){ - return ereg_replace("[ ()]", "", $phone); + return preg_replace("/[ ()]/", "", $phone); } function sanitizeAddress($address){ return str_replace(array("\r\n","\r"),array("\n","\n"),$address); diff --git a/lib/session.php b/lib/session.php index da7c108..f462039 100644 --- a/lib/session.php +++ b/lib/session.php @@ -230,7 +230,7 @@ private $datahash=''; // hash of data field if (file_exists($info['homedirectory'][0]."/.forward")) { $forward = file($info['homedirectory'][0]."/.forward"); - $this->email_forward = ereg_replace("\n", "", $forward[0]); + $this->email_forward = preg_replace("/\n/", "", $forward[0]); } $this->fullname = $info['cn'][0]; diff --git a/lib/validation.php b/lib/validation.php index c4790aa..6561ba3 100644 --- a/lib/validation.php +++ b/lib/validation.php @@ -10,7 +10,7 @@ function validEmail ($email) //split user and domain list($user,$domain) = explode("@", $email); // check for bad characters, and check for zero length user & domain - if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email) or !$user or !$domain ) + if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",$email) or !$user or !$domain ) { $error = 'an invalid email address (syntax)'; return false; @@ -128,7 +128,7 @@ function sidUsed($sid){ function validUsername ($username){ global $error; // check if uname is sytactically valid - $syntax = ereg("^[a-z][a-z0-9_]*$", $username); + $syntax = preg_match("/^[a-z][a-z0-9_]*$/", $username); if(!$syntax || (strlen($username) < 2)){ $error = "Usernames must start with a letter, only contain lowercase letter, numbers 0-9 and underscores (_) and be at least 2 characters."; return false; @@ -196,7 +196,7 @@ function validRealName($realName,$override){ return false; } //check for a sane realname, see comment below - elseif (!ereg("^([A-Z]([.]+ +[A-Z])*([\']+[A-Z])*[a-z]+[ -]*)+$", $realName)) + elseif (!preg_match("/^([A-Z]([.]+ +[A-Z])*([\']+[A-Z])*[a-z]+[ -]*)+$/", $realName)) { $error = "Name incorrectly formated, email <a href=\"mailto:admin@sucs.org\">admin@sucs.org</a> if this is an error."; return false; @@ -241,7 +241,7 @@ function validSocName($socname,$override){ } } else{ - if(!ereg('^[A-Z1-9]',$socname) || strlen($socname) < 2){ + if(!preg_match('/^[A-Z1-9]/',$socname) || strlen($socname) < 2){ $error = "Must start with a capital letter or a number and be more than 1 character"; return false; } @@ -254,7 +254,7 @@ function validSocName($socname,$override){ function validAddress($address){ global $error; $address = sanitizeAddress($address); - if(!ereg("^([A-Z0-9]([[:alnum:]]|[ ./'-])*\n)+[A-Z0-9]([[:alnum:]]|[ ./'-])*$",$address)){ + if(!preg_match("/^([A-Z0-9]([[:alnum:]]|[ ./'-])*\n)+[A-Z0-9]([[:alnum:]]|[ ./'-])*$/",$address)){ $error = "Please supply at least two valid lines of address."; return false; } @@ -266,7 +266,7 @@ function validAddress($address){ function validPhone($phone){ global $error; $phone=sanitizePhone($phone); - if(!ereg("^\+?[0-9-]+$",$phone)){ + if(!preg_match("/^\+?[0-9-]+$/",$phone)){ $error = "Must be all numbers"; return false; } @@ -274,7 +274,7 @@ function validPhone($phone){ } function validSignupEmail($email){ global $error; - if(ereg('@sucs\.org$',$email)){ + if(preg_match('/@sucs\.org$/',$email)){ $error = "SUCS email addresses are not allowed"; return false; } -- GitLab