Browse Source

Changed regexps
Altered function names to make them possibly collide with other functions
less frequently
Altered code for sorting to hopefully improve speed

Tyler Akins 24 years ago
parent
commit
47505bdd6d
2 changed files with 14 additions and 12 deletions
  1. 5 5
      functions/addressbook.php
  2. 9 7
      functions/array.php

+ 5 - 5
functions/addressbook.php

@@ -58,7 +58,7 @@
    
    
    // Had to move this function outside of the Addressbook Class
    // Had to move this function outside of the Addressbook Class
    // PHP 4.0.4 Seemed to be having problems with inline functions.
    // PHP 4.0.4 Seemed to be having problems with inline functions.
-   function cmp($a,$b) {   
+   function addressbook_cmp($a,$b) {   
       if($a['backend'] > $b['backend']) 
       if($a['backend'] > $b['backend']) 
 	     return 1;
 	     return 1;
 	  else if($a['backend'] < $b['backend']) 
 	  else if($a['backend'] < $b['backend']) 
@@ -106,7 +106,7 @@
       // See each of the backend classes for valid parameters.
       // See each of the backend classes for valid parameters.
       function add_backend($backend, $param = '') {
       function add_backend($backend, $param = '') {
 	 $backend_name = 'abook_' . $backend;
 	 $backend_name = 'abook_' . $backend;
-	 eval("\$newback = new $backend_name(\$param);");
+	 eval('$newback = new ' . $backend_name . '($param);');
 	 if(!empty($newback->error)) {
 	 if(!empty($newback->error)) {
 	    $this->error = $newback->error;
 	    $this->error = $newback->error;
 	    return false;
 	    return false;
@@ -174,7 +174,7 @@
     	 $ret = $this->search($expression, $bnum);
     	 $ret = $this->search($expression, $bnum);
     	 if(!is_array($ret))
     	 if(!is_array($ret))
     	    return $ret;
     	    return $ret;
-	     usort($ret, 'cmp');
+	     usort($ret, 'addressbook_cmp');
 	     return $ret;
 	     return $ret;
       }
       }
 
 
@@ -260,7 +260,7 @@
 	    $userdata['nickname'] = $userdata['email'];
 	    $userdata['nickname'] = $userdata['email'];
 	 }
 	 }
 
 
-	 if(eregi("[\: \|\#\"\!]", $userdata['nickname'])) {
+	 if(eregi('[\\: \\|\\#\"\\!]', $userdata['nickname'])) {
 	    $this->error = _("Nickname contain illegal characters");
 	    $this->error = _("Nickname contain illegal characters");
 	    return false;
 	    return false;
 	 }
 	 }
@@ -338,7 +338,7 @@
 	    return false;
 	    return false;
 	 }
 	 }
 
 
-	 if(eregi("[\: \|\#\"\!]", $userdata['nickname'])) {
+	 if(eregi('[\\: \\|\\#"\\!]', $userdata['nickname'])) {
 	    $this->error = _("Nickname contain illegal characters");
 	    $this->error = _("Nickname contain illegal characters");
 	    return false;
 	    return false;
 	 }
 	 }

+ 9 - 7
functions/array.php

@@ -18,13 +18,17 @@
          $col = array($col);
          $col = array($col);
       }
       }
       $GLOBALS['col'] = $col;  // Column or Columns as an array
       $GLOBALS['col'] = $col;  // Column or Columns as an array
+      if ($dir > 0)
+          $dir = 1;
+      else
+          $dir = -1;
       $GLOBALS['dir'] = $dir;  // Direction, a positive number for ascending a negative for descending
       $GLOBALS['dir'] = $dir;  // Direction, a positive number for ascending a negative for descending
 
 
-      usort($ary,'comp2');
+      usort($ary,'array_comp2');
       return $ary;
       return $ary;
   }
   }
 
 
-  function comp2($a,$b,$i = 0) {
+  function array_comp2($a,$b,$i = 0) {
          global $col;
          global $col;
          global $dir;
          global $dir;
          $c = count($col) -1;
          $c = count($col) -1;
@@ -35,11 +39,9 @@
                $r = comp2($a,$b,$i);
                $r = comp2($a,$b,$i);
             }
             }
          } elseif($a[$col[$i]] < $b[$col[$i]]){
          } elseif($a[$col[$i]] < $b[$col[$i]]){
-            $r = -1 * $dir; // Im not sure why you must * dir here, but it wont work just before the return...
-         } else {
-            $r = 1 * $dir;
-         }
-         return $r;
+            return (- $dir);
+         } 
+	 return $dir;
       }
       }
 
 
    function removeElement($array, $element) {
    function removeElement($array, $element) {