/[cvs]/nfo/php/libs/org.netfrag.flib/utils/helper.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.flib/utils/helper.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by joko, Sun Feb 9 17:49:53 2003 UTC revision 1.9 by jonen, Tue Sep 7 18:52:01 2004 UTC
# Line 3  Line 3 
3  //    $Id$  //    $Id$
4  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
5  //    $Log$  //    $Log$
6    //    Revision 1.9  2004/09/07 18:52:01  jonen
7    //    added function 'format_amount'
8    //
9    //    Revision 1.8  2003/03/03 21:21:43  joko
10    //    refactored most reusable code to org.netfrag.glib/php_extensions.php
11    //
12    //    Revision 1.7  2003/03/01 05:05:55  joko
13    //    minor modification to 'Dumper'
14    //
15  //    Revision 1.6  2003/02/09 17:49:53  joko  //    Revision 1.6  2003/02/09 17:49:53  joko
16  //    - removed old code  //    - removed old code
17  //  //
# Line 68  function get_date_forStorage($arg_date) Line 77  function get_date_forStorage($arg_date)
77    return $date_res;    return $date_res;
78  }  }
79    
 // -------------------------------------------------  
 // array initializer  
 // initializes passed variable (taken by reference) with an empty array  
 // does this only if it doesn't exist yet or initialization is explicitely requested ($clear = 1)  
 function array_init(&$var, $clear = 0) {  
   if (!is_array($var) || $clear) { $var = array(); }  
 }  
80        
81    
82  // format functions  // format functions
83    // refactor to org.netfrag.glib::php???
84    // refactor to Data::Validator???
85  function isvalidemailaddress($mail) {  function isvalidemailaddress($mail) {
86    // TODO: review for regex process load    // TODO: review for regex process load
87    //return ((($string = trim($string)) != '') && (($atpos = strpos($string, '@' , 1)) > 1) && (($rdotpos = strrpos($string, '.')) > ($atpos + 2)) && (strlen($string) > $rdotpos + 2));    //return ((($string = trim($string)) != '') && (($atpos = strpos($string, '@' , 1)) > 1) && (($rdotpos = strrpos($string, '.')) > ($atpos + 2)) && (strlen($string) > $rdotpos + 2));
88    if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$mail, $regs) ) {    if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$mail, $regs) ) {
89          return "format";          return "format";
90    }    }
91    elseif( gethostbyname($regs[2]) == $regs[2] ) {    elseif( gethostbynamel($regs[2]) == $regs[2] ) {
92      return "host";      return "host";
93    }    }
94    return "valid";    return "valid";
95  }  }
96    
 function Dumper() {  
   ob_start();  
   $arg_list = func_get_args();  
   $count = 1;  
   foreach ($arg_list as $arg) {  
     print "<hr/>";  
     print_r($arg);  
     $count++;  
   }  
   $var_dump = ob_get_contents();  
   ob_end_clean();  
   $var_dump = str_replace("\n", "<br>", $var_dump);  
   $var_dump = str_replace(" ", "&nbsp;", $var_dump);  
   return $var_dump;  
 }  
   
 function session_register_safe($varname) {  
   if (!session_is_registered($varname)) {  
     session_register($varname);  
     return 1;  
   }  
 }  
97    
98  //------------ getMonths ---------------------  //------------ getMonths ---------------------
99  // TODO: localize!  // TODO: localize!
# Line 124  function getMonthNames() { Line 106  function getMonthNames() {
106     return $months;     return $months;
107  }  }
108    
109    
110    // refactor to Data::Lift???
111  function null2nbsp_string($arg) {  function null2nbsp_string($arg) {
112    if ($arg == '') {    if ($arg == '') {
113      $arg = '&nbsp;';      $arg = '&nbsp;';
# Line 131  function null2nbsp_string($arg) { Line 115  function null2nbsp_string($arg) {
115    return $arg;    return $arg;
116  }  }
117    
118    // refactor to Data::Lift???
119  function null2nbsp_arraywalker(&$item, $key) {  function null2nbsp_arraywalker(&$item, $key) {
120      $item = null2nbsp_string($item);      $item = null2nbsp_string($item);
121  }  }
122    
123    // refactor to Data::Lift???
124  function null2nbsp($arg) {  function null2nbsp($arg) {
125    if (is_array($arg)) {    if (is_array($arg)) {
126      array_walk($arg, 'null2nbsp_arraywalker');      array_walk($arg, 'null2nbsp_arraywalker');
# Line 174  function number_format_locale1($string) Line 160  function number_format_locale1($string)
160    
161  function number_format_locale ($num, $decimals = null) {  function number_format_locale ($num, $decimals = null) {
162     $locale = localeconv();     $locale = localeconv();
163     if(!isset($decimals)) $decimals = $locale['frac_digits'];     //if(!isset($decimals)) $decimals = $locale['frac_digits'];
164       if(!isset($decimals)) $decimals = 2;
165     return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']);     return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']);
166  }  }
167    
168    
169    // refactor to org.netfrag.glib::php???
170    // rename to 'check_amount'?
171    // move to Data::Validator???
172  function is_amount($amount) {  function is_amount($amount) {
173    //if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) {    //if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) {
174    if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) {    if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) {
# Line 186  function is_amount($amount) { Line 176  function is_amount($amount) {
176    }    }
177  }  }
178    
179    function format_amount(&$amount) {
180      $amount = str_replace(array(".", ","), array("", "."), $amount);
181      //print "streplace amount: '$amount'<br>";
182      //return $amount;
183    }
184    
 // from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php  
 function is_hash( $var ) {  
  if( is_array( $var ) ) {  
    $keys = array_keys( $var );  
    $all_num = true;  
    for( $i=0; $i<count($keys); $i++ )  
      if( is_string($keys[$i] ) ) return true;  
  }  
  return false;  
 }  
   
 // from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php  
 function array_join_merge( $arr1, $arr2 ) {  
  if( is_array( $arr1 ) and is_array( $arr2 ) ) {  
    // the same -> merge  
    $new_array = array();  
   
    if( is_hash( $arr1 ) and is_hash( $arr2 ) ) {  
     // hashes -> merge based on keys  
      $keys = array_merge( array_keys( $arr1 ), array_keys( $arr2 ) );  
      foreach( $keys as $key ) {  
 $new_array[$key] = array_join_merge( $arr1[$key], $arr2[$key] );  
      }  
    } else {  
      // two real arrays -> merge  
      $new_array =  
 array_reverse(array_unique(array_reverse(array_merge($arr1,$arr2))));  
   }  
       
    return $new_array;  
  } else {  
    // not the same ... take new one if defined, else the old one stays  
    return $arr2 ? $arr2 : $arr1;  
  }  
 }  
185    
186  ?>  ?>

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.9

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed