[ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # Mantis - a php based bugtracking system 3 4 # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 5 # Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net 6 7 # Mantis is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Mantis is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Mantis. If not, see <http://www.gnu.org/licenses/>. 19 20 # -------------------------------------------------------- 21 # $Id: utility_api.php,v 1.22.2.1 2007-10-13 22:35:47 giallu Exp $ 22 # -------------------------------------------------------- 23 24 ### Utility API ### 25 26 # Utility functions are *small* functions that are used often and therefore 27 # have *no* prefix, to keep their names short. 28 # 29 # Utility functions have *no* dependencies on any other APIs, since they are 30 # included first in order to make them available to all the APIs. 31 # Miscellaneous functions that provide functionality on top of other APIS 32 # are found in the helper_api. 33 34 # -------------------- 35 # converts a 1 value to X 36 # converts a 0 value to a space 37 function trans_bool( $p_num ) { 38 if ( 0 == $p_num ) { 39 return ' '; 40 } else { 41 return 'X'; 42 } 43 } 44 45 # -------------------- 46 # Breaks up an enum string into num:value elements 47 function explode_enum_string( $p_enum_string ) { 48 return explode( ',', $p_enum_string ); 49 } 50 51 # -------------------- 52 # Given one num:value pair it will return both in an array 53 # num will be first (element 0) value second (element 1) 54 function explode_enum_arr( $p_enum_elem ) { 55 return explode( ':', $p_enum_elem ); 56 } 57 58 # -------------------- 59 # Get the string associated with the $p_enum value 60 function get_enum_to_array( $p_enum_string ) { 61 $t_arr = explode_enum_string( $p_enum_string ); 62 $enum_count = count( $t_arr ); 63 for ($i=0; $i < $enum_count;$i++) { 64 $t_s = explode_enum_arr( $t_arr[$i] ); 65 $t_index = (int) $t_s[0]; 66 $t_array[$t_index] = $t_s[1]; 67 } 68 return $t_array; 69 } 70 71 # -------------------- 72 # Get the string associated with the $p_enum value 73 function get_enum_to_string( $p_enum_string, $p_num ) { 74 $t_arr = explode_enum_string( $p_enum_string ); 75 $enum_count = count( $t_arr ); 76 for ($i=0; $i < $enum_count;$i++) { 77 $t_s = explode_enum_arr( $t_arr[$i] ); 78 if ( $t_s[0] == $p_num ) { 79 return $t_s[1]; 80 } 81 } 82 return '@' . $p_num . '@'; 83 } 84 85 # -------------------- 86 # Contributed by Peter Palmreuther 87 function mime_encode( $p_string = '' ) { 88 $output = ''; 89 $str_len = strlen( $p_string ); 90 for ( $i=0; $i < $str_len; $i++ ) { 91 if (( ord( $p_string[$i] ) < 33 ) || 92 ( ord( $p_string[$i] ) > 127 ) || 93 ( eregi( "[\%\[\]\{\}\(\)]", $p_string[$i] ) )) { 94 $output .= sprintf( '%%%02X', ord( $p_string[$i] ) ); 95 } else { 96 $output .= $p_string[$i]; 97 } 98 } 99 return( $output ); 100 } 101 102 # -------------------- 103 # This function checks to see if a variable is set 104 # if it is not then it assigns the default value 105 # otherwise it does nothing 106 function check_varset( &$p_var, $p_default_value ) { 107 if ( !isset( $p_var ) ) { 108 $p_var = $p_default_value; 109 } 110 } 111 112 # -------------------- 113 # Add a trailing DIRECTORY_SEPARATOR to a string if it isn't present 114 function terminate_directory_path( $p_path ) { 115 $str_len = strlen($p_path); 116 if ( $p_path && $p_path[$str_len-1] != DIRECTORY_SEPARATOR ) { 117 $p_path = $p_path.DIRECTORY_SEPARATOR; 118 } 119 120 return $p_path; 121 } 122 123 # -------------------- 124 # Print a debug string by generating a notice 125 function debug( $p_string ) { 126 trigger_error( $p_string, NOTICE ); 127 } 128 129 # -------------------- 130 # Return true if the parameter is an empty string or a string 131 # containing only whitespace, false otherwise 132 function is_blank( $p_var ) { 133 $p_var = trim( $p_var ); 134 $str_len = strlen( $p_var ); 135 if ( 0 == $str_len ) { 136 return true; 137 } 138 return false; 139 } 140 141 # -------------------- 142 # Get the named php ini variable but return it as a bool 143 function ini_get_bool( $p_name ) { 144 $result = ini_get( $p_name ); 145 146 if ( is_string( $result ) ) { 147 switch ( $result ) { 148 case 'off': 149 case 'false': 150 case 'no': 151 case 'none': 152 case '': 153 case '0': 154 return false; 155 break; 156 case 'on': 157 case 'true': 158 case 'yes': 159 case '1': 160 return true; 161 break; 162 } 163 } else { 164 return (bool)$result; 165 } 166 } 167 168 # -------------------- 169 # Get the named php ini variable but return it as a number after converting "K" and "M" 170 function ini_get_number( $p_name ) { 171 $t_result = ini_get( $p_name ); 172 $t_val = spliti( 'M', $t_result); 173 if ( $t_val[0] != $t_result ) { 174 return $t_val[0] * 1000000; 175 } 176 $t_val = spliti( 'K', $t_result); 177 if ( $t_val[0] != $t_result ) { 178 return $t_val[0] * 1000; 179 } 180 return $t_result; 181 } 182 183 184 185 # -------------------- 186 # Sort a multi-dimensional array by one of its keys 187 function multi_sort( $p_array, $p_key, $p_direction=ASCENDING ) { 188 if ( DESCENDING == $p_direction ) { 189 $t_factor = -1; 190 } else { 191 # might as well allow everything else to mean ASC rather than erroring 192 $t_factor = 1; 193 } 194 195 $t_function = create_function( '$a, $b', "return $t_factor * strnatcasecmp( \$a['$p_key'], \$b['$p_key'] );" ); 196 uasort( $p_array, $t_function ); 197 return $p_array; 198 } 199 200 # -------------------- 201 # Copies item with given key from source array to the destination, 202 # if the key exists in the source. If not - does nothing. 203 function copy_array_item_if_exist( &$p_arr_src, &$p_arr_dst, $key ) { 204 if( array_key_exists( $key, $p_arr_src ) ) { 205 $p_arr_dst[$key] = $p_arr_src[$key]; 206 } 207 } 208 209 # -------------------- 210 # Return GD version 211 # It doesn't use gd_info() so it works with PHP < 4.3.0 as well 212 function get_gd_version() 213 { 214 $t_GDfuncList = get_extension_funcs('gd'); 215 if( ! is_array( $t_GDfuncList ) ) { 216 return 0; 217 } else { 218 if( in_array('imagegd2',$t_GDfuncList) ) { 219 return 2; 220 } else { 221 return 1; 222 } 223 } 224 } 225 226 # --------------------- 227 # return true or false if string matches current page name 228 function is_page_name( $p_string ) { 229 return isset( $_SERVER['PHP_SELF'] ) && ( 0 < strpos( $_SERVER['PHP_SELF'], $p_string ) ); 230 } 231 232 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |