Changeset 464 for trunk


Ignore:
Timestamp:
02/20/08 16:42:41 (16 years ago)
Author:
bastiaans
Message:

libtoga.php:

  • fix: removed php4 stripos(), use strpos() in stead
  • add: check for upper or lowercase {x} and {y}
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/job_monarch/libtoga.php

    r463 r464  
    126126}
    127127
    128 /**
    129  * Replace stripos()
    130  *
    131  * @category    PHP
    132  * @package     PHP_Compat
    133  * @link        http://php.net/function.stripos
    134  * @author      Aidan Lister <aidan@php.net>
    135  * @version     $Revision: 1.1.1.1 $
    136  * @since       PHP 5
    137  * @require     PHP 4.0.1 (trigger_error)
    138  */
    139 if (!function_exists('stripos'))
    140 {
    141     function stripos ($haystack, $needle, $offset = null)
    142     {
    143         if (!is_scalar($haystack)) {
    144             trigger_error('stripos() expects parameter 1 to be string, ' . gettype($haystack) . ' given', E_USER_WARNING);
    145             return false;
    146         }
    147 
    148         if (!is_scalar($needle)) {
    149             trigger_error('stripos() needle is not a string or an integer.', E_USER_WARNING);
    150             return false;
    151         }
    152 
    153         if (!is_null($offset) && !is_numeric($offset)) {
    154             trigger_error('stripos() expects parameter 3 to be long, ' . gettype($offset) . ' given', E_USER_WARNING);
    155             return false;
    156         }
    157 
    158         // Manipulate the string if there is an offset                   
    159         $fix = 0;
    160         if (!is_null($offset))
    161         {
    162             if ($offset > 0)
    163             {
    164                 $haystack = substr($haystack, $offset, strlen($haystack) - $offset);
    165                 $fix = $offset;
    166             }
    167         }
    168 
    169         $segments = explode (strtolower($needle), strtolower($haystack), 2);
    170         $position = strlen($segments[0]) + $fix;
    171 
    172         return $position;
    173     }
    174 }
    175 
    176128class TarchDbase {
    177129
     
    12411193                        $y_present      = false;
    12421194
    1243                         if(stripos( $SORTBY_HOSTNAME, "{x}" ) != false )
    1244                         {
     1195                        // Should we scan by X, Y or both
     1196                        //
     1197                        if(strpos( $SORTBY_HOSTNAME, "{x}" ) != false )
     1198                        {
     1199                                $x_str          = "{x}";
    12451200                                $x_present      = true;
    12461201                        }
    1247                         if(stripos( $SORTBY_HOSTNAME, "{y}" ) != false )
    1248                         {
     1202                        else if(strpos( $SORTBY_HOSTNAME, "{X}" ) != false )
     1203                        {
     1204                                $x_str          = "{X}";
     1205                                $x_present      = true;
     1206                        }
     1207                        if(strpos( $SORTBY_HOSTNAME, "{y}" ) != false )
     1208                        {
     1209                                $y_str          = "{y}";
    12491210                                $y_present      = true;
    12501211                        }
    1251 
    1252                         if(( strpos( $SORTBY_HOSTNAME, "{x}" ) < strpos( $SORTBY_HOSTNAME, "{y}" ) ) && ( $x_present && $y_present ))
     1212                        else if(strpos( $SORTBY_HOSTNAME, "{Y}" ) != false )
     1213                        {
     1214                                $y_str          = "{Y}";
     1215                                $y_present      = true;
     1216                        }
     1217
     1218                        // If we should scan for both X and Y: see which one is first
     1219                        //
     1220                        if(( strpos( $SORTBY_HOSTNAME, $x_str ) < strpos( $SORTBY_HOSTNAME, $y_str ) ) && ( $x_present && $y_present ))
    12531221                        {
    12541222                       
    12551223                                $x_first        = 1;
    12561224                        }
    1257                         else if(( strpos( $SORTBY_HOSTNAME, "{x}" ) > strpos( $SORTBY_HOSTNAME, "{y}" ) ) && ( $x_present && $y_present ))
     1225                        else if(( strpos( $SORTBY_HOSTNAME, $x_str ) > strpos( $SORTBY_HOSTNAME, $y_str ) ) && ( $x_present && $y_present ))
    12581226                        {
    12591227                                $y_first        = 1;
     
    12691237                        }
    12701238
     1239                        // Now replace our {x} and {y} with %d for sscanf parsing
     1240                        //
    12711241                        if(( $x_first ) && ( $x_present && $y_present ) )
    12721242                        {
    1273                                 $skan_str       = str_replace( "{x}", "%d", $skan_str );
    1274                                 $skan_str       = str_replace( "{y}", "%d", $skan_str );
     1243                                $skan_str       = str_replace( $x_str, "%d", $skan_str );
     1244                                $skan_str       = str_replace( $y_str, "%d", $skan_str );
    12751245                        }
    12761246                        else if( $x_present)
    12771247                        {
    1278                                 $skan_str       = str_replace( "{x}", "%d", $skan_str );
     1248                                $skan_str       = str_replace( $x_str, "%d", $skan_str );
    12791249                        }
    12801250                        else if( $y_present)
    12811251                        {
    1282                                 $skan_str       = str_replace( "{y}", "%d", $skan_str );
     1252                                $skan_str       = str_replace( $y_str, "%d", $skan_str );
    12831253                        }
    12841254
     
    12881258                        $y_max          = null;
    12891259
     1260                        // Now let's walk through all our nodes and see which one are valid for our scan pattern
     1261                        //
    12901262                        foreach( $nodes as $hostname => $node )
    12911263                        {
Note: See TracChangeset for help on using the changeset viewer.