/[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.3 by joko, Wed Dec 11 01:00:22 2002 UTC revision 1.10 by jonen, Wed Nov 3 14:13:45 2004 UTC
# Line 3  Line 3 
3  //    $Id$  //    $Id$
4  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
5  //    $Log$  //    $Log$
6    //    Revision 1.10  2004/11/03 14:13:45  jonen
7    //    minor changes related to check mail-address
8    //
9    //    Revision 1.9  2004/09/07 18:52:01  jonen
10    //     added function 'format_amount'
11    //
12    //    Revision 1.8  2003/03/03 21:21:43  joko
13    //    refactored most reusable code to org.netfrag.glib/php_extensions.php
14    //
15    //    Revision 1.7  2003/03/01 05:05:55  joko
16    //    minor modification to 'Dumper'
17    //
18    //    Revision 1.6  2003/02/09 17:49:53  joko
19    //    - removed old code
20    //
21    //    Revision 1.5  2003/02/04 08:22:34  joko
22    //    + function is_hash
23    //    + function array_join_merge
24    //
25    //    Revision 1.4  2002/12/22 13:29:54  jonen
26    //    + added number format helper functions:
27    //      + number_format_locale()
28    //      + is_amount()
29    //
30  //    Revision 1.3  2002/12/11 01:00:22  joko  //    Revision 1.3  2002/12/11 01:00:22  joko
31  //    + renamed function 'sai' to 'array_init'  //    + renamed function 'sai' to 'array_init'
32  //  //
# Line 56  function get_date_forStorage($arg_date) Line 80  function get_date_forStorage($arg_date)
80    return $date_res;    return $date_res;
81  }  }
82    
 // -------------------------------------------------  
 // 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(); }  
 }  
83        
84    
85  // format functions  // format functions
86    // refactor to org.netfrag.glib::php???
87    // refactor to Data::Validator???
88  function isvalidemailaddress($mail) {  function isvalidemailaddress($mail) {
89      // TODO: review for regex process load
90    //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));
91    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) ) {
92          return "format";          return "format";
# Line 77  function isvalidemailaddress($mail) { Line 97  function isvalidemailaddress($mail) {
97    return "valid";    return "valid";
98  }  }
99    
 function dumpVar($var) {  
   return Dumper($var);  
 }  
   
 function Dumper($var) {  
   ob_start();  
   print_r($var);  
   $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;  
   }  
 }  
100    
101  //------------ getMonths ---------------------  //------------ getMonths ---------------------
102  // TODO: localize!  // TODO: localize!
# Line 109  function getMonthNames() { Line 109  function getMonthNames() {
109     return $months;     return $months;
110  }  }
111    
112    
113    // refactor to Data::Lift???
114  function null2nbsp_string($arg) {  function null2nbsp_string($arg) {
115    if ($arg == '') {    if ($arg == '') {
116      $arg = '&nbsp;';      $arg = '&nbsp;';
# Line 116  function null2nbsp_string($arg) { Line 118  function null2nbsp_string($arg) {
118    return $arg;    return $arg;
119  }  }
120    
121    // refactor to Data::Lift???
122  function null2nbsp_arraywalker(&$item, $key) {  function null2nbsp_arraywalker(&$item, $key) {
123      $item = null2nbsp_string($item);      $item = null2nbsp_string($item);
124  }  }
125    
126    // refactor to Data::Lift???
127  function null2nbsp($arg) {  function null2nbsp($arg) {
128    if (is_array($arg)) {    if (is_array($arg)) {
129      array_walk($arg, 'null2nbsp_arraywalker');      array_walk($arg, 'null2nbsp_arraywalker');
# Line 144  function getEncodedBirthdate($birthdate) Line 148  function getEncodedBirthdate($birthdate)
148    return $birthday;    return $birthday;
149  }  }
150    
151  /*  function number_format_storage($string) {
152  function dprint($message) {      $locale_info = localeconv();
153    print '<span style="font-family:Verdana,Helvetica;font-size:7pt;">';      $string =  str_replace($locale_info["decimal_point"], ".",  $string);
154    print $message;      return $string;
   print '</span><br>';  
155  }  }
156  */  
157    function number_format_locale1($string) {
158        $locale_info = localeconv();
159        $string =  str_replace(".", $locale_info["decimal_point"],  $string);
160        return $string;
161    }
162    
163    
164    function number_format_locale ($num, $decimals = null) {
165       $locale = localeconv();
166       //if(!isset($decimals)) $decimals = $locale['frac_digits'];
167       if(!isset($decimals)) $decimals = 2;
168       return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']);
169    }
170    
171    
172    // refactor to org.netfrag.glib::php???
173    // rename to 'check_amount'?
174    // move to Data::Validator???
175    function is_amount($amount) {
176      //if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) {
177      if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) {
178        return 1;
179      }
180    }
181    
182    function format_amount(&$amount) {
183      $amount = str_replace(array(".", ","), array("", "."), $amount);
184      //print "streplace amount: '$amount'<br>";
185      //return $amount;
186    }
187    
188    
189  ?>  ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.10

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