Main Page | Directories | File List | File Members

utils.php File Reference

Go to the source code of this file.

Functions

 utils_safeinput ($string)
 utils_get_content ($file)
 utils_check_path ($path)
 utils_makereal ($data, $string="%PROJECT", $replacement=0)
 utils_link ($url, $title, $defaultclass=0, $available=1, $help=0)
 utils_email ($address, $nohtml=0)
 utils_is_ascii ($string)
 utils_altrow ($i)
 utils_cutstring ($string, $lenght=35)
 format_date ($format="default", $timestamp, $default_value='-')
 utils_format_date ($timestamp, $format="default")
 utils_date_to_unixtime ($date)
 utils_read_file ($filename)
 utils_filesize ($filename, $file_size=0)
 utils_fileextension ($filename)
 utils_prep_string_for_sendmail ($body)
 utils_unconvert_htmlspecialchars ($string)
 utils_remove_htmlheader ($string)
 utils_result_column_to_array ($result, $col=0)
 result_column_to_array ($result, $col=0)
 utils_wrap_find_space ($string, $wrap)


Function Documentation

format_date format = "default",
timestamp,
default_value = '-'
 

Returns a formatted date for a unix timestamp with the given format

Alias of utils_format_date() with inverted parameters (look out!)

Definition at line 138 of file utils.php.

References utils_format_date().

Referenced by format_item_attached_files(), format_item_details(), forum_header(), forum_show_a_nested_message(), news_show_latest(), show_item_history(), show_item_list(), and show_item_list_sober().

00139 {
00140   return utils_format_date($timestamp, $format);
00141 }

result_column_to_array result,
col = 0
 

Definition at line 377 of file utils.php.

00378 {
00379   /*
00380                 backwards compatibility
00381   */
00382   return utils_result_column_to_array($result, $col);
00383 }

utils_altrow i  ) 
 

Definition at line 115 of file utils.php.

00116 {
00117   return html_get_alt_row_color ($i);
00118 }

utils_check_path path  ) 
 

Definition at line 52 of file utils.php.

References Error, and exit_error().

00053 {
00054   if (eregi(".*\.\.\/.*", $path))
00055     {
00056       exit_error('Error','Malformed url');
00057     }
00058 }

utils_cutstring string,
lenght = 35
 

Definition at line 120 of file utils.php.

Referenced by menu_thispage(), and trackers_data_handle_update().

00121 {
00122   $string = rtrim($string);
00123   if (strlen($string) > $lenght)
00124     {
00125       $string = substr($string, 0, $lenght);
00126       $string = substr($string, 0, strrpos($string, ' '));
00127       $string .= "...";
00128     }
00129   return $string;
00130 }

utils_date_to_unixtime date  ) 
 

Definition at line 213 of file utils.php.

References $res.

Referenced by trackers_data_handle_update().

00214 {
00215   $res = preg_match("/\s*(\d+)-(\d+)-(\d+)/",$date,$match);
00216   if ($res == 0)
00217     { return array(0,false); }
00218   list(,$year,$month,$day) = $match;
00219   $time = mktime(0, 0, 0, $month, $day, $year);
00220   dbg("DBG Matching date $date -> year $year, month $month,day $day -> time = $time<br />");
00221   return array($time,true);
00222 }

utils_email address,
nohtml = 0
 

Definition at line 86 of file utils.php.

References $address, and user_isloggedin().

Referenced by format_item_cc_list().

00087 {
00088   if (user_isloggedin())
00089     {
00090       if ($nohtml)
00091         { return $address; }
00092 
00093       return '<a href="mailto:'.$address.'">'.$address.'</a>';
00094 
00095     }
00096   else
00097     {
00098       if ($nohtml)
00099         { return _("-unavailable-"); }
00100 
00101       return utils_help(_("-unavailable-"),
00102                         _("This information is not provided to anonymous users"),
00103                         1);
00104     }
00105 
00106 }

utils_fileextension filename  ) 
 

Definition at line 258 of file utils.php.

00259 {
00260 
00261   $ext = substr(basename($filename), strrpos(basename($filename),".") + 1);
00262   if ($ext==gz || $ext==bz2)
00263     {
00264       $ext = substr(basename($filename), strrpos(basename($filename),".") - 3);
00265     }
00266   if ($ext==rpm)
00267     {
00268       $long_ext = _("rpm package");
00269     }
00270   if ($ext==deb)
00271     {
00272       $long_ext = _("debian package");
00273     }
00274   if ($ext==deb || $ext==rpm)
00275     {
00276       $arch_type = substr(basename($filename), strrpos(basename($filename),".") - 3);
00277       if ($arch_type == "src.".$ext)
00278         {
00279           $long_ext = sprintf(_("source %s"), $long_ext);
00280         }
00281       if ($arch_type == "rch.".$ext)
00282         {
00283           $long_ext = sprintf(_("arch independant %s"), $long_ext);
00284         }
00285       if ($arch_type == "386.".$ext)
00286         {
00287           $long_ext = sprintf(_("%s for i386 (ix86)"), $long_ext);
00288         }
00289       if ($arch_type == "586.".$ext)
00290         {
00291           $long_ext = sprintf(_("%s for i586"), $long_ext);
00292         }
00293       if ($arch_type == "686.".$ext)
00294         {
00295           $long_ext = sprintf(_("%s for i686"), $long_ext);
00296         }
00297       if ($arch_type == "a64.".$ext)
00298         {
00299           $long_ext = sprintf(_("%s for Itanium 64"), $long_ext);
00300         }
00301       if ($arch_type == "arc.".$ext)
00302         {
00303           $long_ext = sprintf(_("%s for Sparc"), $long_ext);
00304         }
00305       if ($arch_type == "pha.".$ext)
00306         {
00307           $long_ext = sprintf(_("%s for Alpha"), $long_ext);
00308         }
00309       if ($arch_type == "ppc.".$ext)
00310         {
00311           $long_ext = sprintf(_("%s for PowerPC"), $long_ext);
00312         }
00313       if ($arch_type == "390.".$ext)
00314         {
00315           $long_ext = sprintf(_("%s for s390"), $long_ext);
00316         }
00317       $ext = $long_ext;
00318     }
00319   return $ext;
00320 }

utils_filesize filename,
file_size = 0
 

Definition at line 236 of file utils.php.

Referenced by format_item_attached_files().

00237 {
00238   # If file size is defined, assume that we just want an unit conversion.
00239   if (!$file_size)
00240     {   $file_size = filesize($filename); }
00241 
00242   if ($file_size >= 1048576)
00243     {
00244       $file_size = round($file_size / 1048576 * 100) / 100 . _("MB");
00245     }
00246   elseif ($file_size >= 1024)
00247     {
00248       $file_size = round($file_size / 1024 * 100) / 100 . _("KB");
00249     }
00250   else
00251     {
00252       $file_size = $file_size . _("B");
00253     }
00254 
00255   return $file_size;
00256 }

utils_format_date timestamp,
format = "default"
 

Returns a formatted date for a unix timestamp

The given unix timestamp will be formatted according to the $format parameter. Note that this parameter is not one of the format strings supported by functions such as strftime(), but a description instead.

Currently, you can use the following values for $format:

  • default => localized Fri 18 November 2005 at 18:51
  • short => localized 18/11/2005, 18:51
  • minimal => localized 18/11/2005

See also:
utils_date_to_unixtime()

Definition at line 158 of file utils.php.

References user_isloggedin().

Referenced by format_date().

00159 {
00160   global $sys_datefmt;
00161   if ($timestamp == 0)
00162     {
00163       return '-';
00164     }
00165 
00166   # The installation configured a specific date format. This is not nice
00167   # this will prevent locales from being used
00168   if ($sys_datefmt)
00169     {
00170       return strftime($sys_datefmt, $timestamp);
00171     }
00172 
00173   ## Go at task #2614 to discuss about this
00174   # Used by default
00175   switch ($format)
00176     {
00177     case 'short':
00178       {
00179         # To be used in tables, nowhere else
00180         return strftime('%a %x, %R', $timestamp);
00181       }
00182     case 'minimal':
00183       {
00184         # To be used where place is really lacking, like in feature boxes.
00185         # (Nowhere else, it is too uninformative)
00186         return strftime('%x', $timestamp);
00187       }
00188     default:
00189       {
00190         # Used by default
00191         # Mention timezone to non-logged in users or in printer mode.
00192         # Logged-in users have this as account setting, so we can assume they
00193         # now and dont want time wasted by that
00194         if (user_isloggedin() && !defined(PRINTER))
00195           {
00196             return strftime('%A %x '._("at").' %R', $timestamp);
00197           }
00198         else
00199           {
00200             return strftime('%A %x '._("at").' %R %Z', $timestamp);
00201           }
00202       }
00203     }
00204 
00205   return false;
00206 }

utils_get_content file  ) 
 

Definition at line 34 of file utils.php.

Referenced by account_emailvalid(), account_groupnamevalid(), generic_footer(), generic_header_start(), menu_print_sidebar(), send_new_project_email(), theme_list(), and theme_rotate_jump().

00035 {
00036   if (is_file($GLOBALS['sys_incdir'].'/'.$file.'.'.$GLOBALS['locale']))
00037     {
00038       # there is localized version of the file :
00039       include($GLOBALS['sys_incdir'].'/'.$file.'.'.$GLOBALS['locale']);
00040     }
00041   elseif (is_file($GLOBALS['sys_incdir'].'/'.$file.'.txt'))
00042     {
00043       include($GLOBALS['sys_incdir'].'/'.$file.'.txt');
00044     }
00045   else
00046     {
00047       fb(sprintf(_("Warning: Savane was not able to read \"%s\" site-specific information, please contact administrators"), $file), 1);
00048     }
00049 }

utils_is_ascii string  ) 
 

Definition at line 109 of file utils.php.

Referenced by sendmail_encode_header_content().

00110 {
00111   return preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] )*$%xs', $string);
00112 }

utils_link url,
title,
defaultclass = 0,
available = 1,
help = 0
 

Definition at line 70 of file utils.php.

References $return.

Referenced by menu_thispage(), show_features_boxes(), and show_item_list_sober().

00071 {
00072   if (!$available)
00073     { $defaultclass = 'unavailable'; }
00074 
00075   $return = '<a href="'.$url.'"';
00076 
00077   if ($defaultclass)
00078     { $return .= ' class="'.$defaultclass.'"'; }
00079   if ($help)
00080     { $return .= ' title="'.$help.'"'; }
00081   $return .= '>'.$title.'</a>';
00082   return $return;
00083 }

utils_makereal data,
string = "%PROJECT",
replacement = 0
 

Definition at line 62 of file utils.php.

References $GLOBALS.

00063 {
00064   if (!$replacement)
00065     { $replacement = $GLOBALS[group_name]; }
00066   return ereg_replace($string, $replacement, $data);
00067 }

utils_prep_string_for_sendmail body  ) 
 

Definition at line 322 of file utils.php.

References $body.

00323 {
00324   $body=str_replace("\\","\\\\",$body);
00325   $body=str_replace("\"","\\\"",$body);
00326   $body=str_replace("\$","\\\$",$body);
00327   $body=str_replace("`","\\`",$body);
00328   return $body;
00329 }

utils_read_file filename  ) 
 

Definition at line 224 of file utils.php.

00225 {
00226   @$fp = fopen($filename, "r");
00227   if ($fp)
00228     {
00229       $val = fread($fp, filesize($filename));
00230       fclose ($fp);
00231       return $val;
00232     }
00233   return false;
00234 }

utils_remove_htmlheader string  ) 
 

Definition at line 348 of file utils.php.

00349 {
00350   $string = eregi_replace('(^.*<html[^>]*>.*<body[^>]*>)|(</body[^>]*>.*</html[^>]*>.*$)', '', $string);
00351   return $string;
00352 }

utils_result_column_to_array result,
col = 0
 

Definition at line 354 of file utils.php.

00355 {
00356   /*
00357                 Takes a result set and turns the optional column into
00358                 an array
00359   */
00360   $rows=db_numrows($result);
00361 
00362   if ($rows > 0)
00363     {
00364       $arr=array();
00365       for ($i=0; $i<$rows; $i++)
00366         {
00367           $arr[$i]=db_result($result,$i,$col);
00368         }
00369     }
00370   else
00371     {
00372       $arr=array();
00373     }
00374   return $arr;
00375 }

utils_safeinput string  ) 
 

Definition at line 27 of file utils.php.

References safeinput().

00028 {
00029   return safeinput($string);
00030 }

utils_unconvert_htmlspecialchars string  ) 
 

Definition at line 331 of file utils.php.

References nbsp.

Referenced by format_item_changes(), format_item_details(), and trackers_data_handle_update().

00332 {
00333   if (strlen($string) < 1)
00334     {
00335       return '';
00336     }
00337   else
00338     {
00339       $string=str_replace('&nbsp;',' ',$string);
00340       $string=str_replace('&quot;','"',$string);
00341       $string=str_replace('&gt;','>',$string);
00342       $string=str_replace('&lt;','<',$string);
00343       $string=str_replace('&amp;','&',$string);
00344       return $string;
00345     }
00346 }

utils_wrap_find_space string,
wrap
 

Internal function for recognizing and formatting headings

This function is a helper for _full_markup() and should not be used otherwise.

Internal function for recognizing and formatting lists

This function is a helper for _full_markup() and should not be used otherwise.

Definition at line 385 of file utils.php.


Generated on Sun Feb 26 13:23:05 2006 for Savane PHP Frontend Developer Reference by  doxygen 1.4.4