Patching osticket for PHP 5.3

OSTicket is a decent piece of software for customer service. I upgraded to PHP 5.3 and had some problems because they are trying to keep it working all the way back to PHP 4. 🙁

Here is a patch to fix the eregi_replace deprecated errors.

diff --git a/osticket/include/class.format.php b/osticket/include/class.format.php
index 6cbb414..0380268 100644
--- a/osticket/include/class.format.php
+++ b/osticket/include/class.format.php
@@ -78,10 +78,10 @@ class Format {

     //make urls clickable. Mainly for display
     function clickableurls($text) {
-        $text=eregi_replace('(((f|ht){1}tp(s?)://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1', $text);
-        $text=eregi_replace("(^|[ \n\r\t])(www\.([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)(/[^/ \n\r]*)*)",
+        $text=preg_replace('#(((f|ht){1}tp(s?)://)[-a-zA-Z0-9@:%_\+.~\#?&//=]+)#','\\1', $text);
+        $text=preg_replace("#(^|[ \n\r\t])(www\.([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)(/[^/ \n\r]*)*)#",
                 '\\1\\2', $text);
-        $text=eregi_replace("(^|[ \n\r\t])([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})",'\\1\\2', $text);
+        $text=preg_replace("#(^|[ \n\r\t])([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})#",'\\1\\2', $text);

         return $text;
     }

diff --git a/osticket/include/class.validator.php b/osticket/include/class.validator.php
index 284d7c7..697d99c 100644
--- a/osticket/include/class.validator.php
+++ b/osticket/include/class.validator.php
@@ -126,15 +126,15 @@ class Validator {

     /* Functione below can be called directly without class instance. Validator::func(var..); */
     function is_email($email) {
-        return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",trim($email));
+        return preg_match("#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$#",trim($email));
     }
     function is_phone($phone) {
-        $stripped=eregi_replace("(\(|\)|\-|\+)","",ereg_replace("([  ]+)","",$phone));
+        $stripped=preg_replace("#(\(|\)|\-|\+)","",preg_replace("/([  ]+)#/","",$phone));
         return (!is_numeric($stripped) || ((strlen($stripped)<7) || (strlen($stripped)>13)))?false:true;
     }

     function is_url($url) { //Thanks to 4ice for the fix.
-        $urlregex = "^(https?)\:\/\/";
+        $urlregex = "#^(https?)\:\/\/";
         // USER AND PASS (optional)
         $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?";
         // HOSTNAME OR IP
@@ -149,9 +149,9 @@ class Validator {
         // GET Query (optional)
         $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?";
         // ANCHOR (optional)
-        $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
+        $urlregex .= "(\#[a-z_.-][a-z0-9+\$_.-]*)?\$#";

-        return eregi($urlregex, $url)?true:false;
+        return preg_match($urlregex, $url)?true:false;
     }


@@ -161,7 +161,7 @@ class Validator {
             return false;

         $ip=trim($ip);
-        if(ereg("^[0-9]{1,3}(.[0-9]{1,3}){3}$",$ip)) {
+        if(preg_match("#^[0-9]{1,3}(.[0-9]{1,3}){3}$#",$ip)) {
             foreach(explode(".", $ip) as $block)
                 if($block<0 || $block>255 )
                     return false;

 
TrackBack URI

4 Comments so far »

  1. exchangerates said

    am March 10 2011 @ 3:13 am

    Thanks John .
    Ive noticed PHP 5.3.0 tends to produce more deprecated warnings than earlier PHP 5.x releases. I don't think many production servers are running PHP 5.3.0 yet (quite possibly due to the new deprecated warnings). The bug report was from a development server.

    Tested with PHP 5.2.8 doesn't produce any warnings and seems to be the preferred production release of 5.x at the moment.

  2. John Congdon said

    am April 15 2011 @ 8:14 am

    Actually, according to PHP on 12/16/2010 posted on their site.

    The PHP development team would like to announce the immediate availability of PHP 5.2.16. This release marks the end of support for PHP 5.2. All users of PHP 5.2 are encouraged to upgrade to PHP 5.3.

  3. blank said

    am April 15 2011 @ 3:36 am

    Hi John,

    This looks interesting – how do I use it though?

  4. John Congdon said

    am April 15 2011 @ 8:17 am

    Do you mean, how do you use the patch? There are two ways. Copy/paste above into a text file and use the patch command, maybe overkill for the couple of lines that need changed.

    You can also just open the two files and change the lines. The lines starting with a (-) were removed and the ones with a (+) were added.
    include/class.format.php include/class.validator.php

    Example:
    @@ -161,7 +161,7 @@ class Validator {
    return false;

    $ip=trim($ip);
    – if(ereg("^[0-9]{1,3}(.[0-9]{1,3}){3}$",$ip)) {
    + if(preg_match("#^[0-9]{1,3}(.[0-9]{1,3}){3}$#",$ip)) {

    I simply changed the ereg function to use preg_match.

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: