ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

core_utilities.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
16 global $CachedFiles;
17 $CachedFiles = array();
18
37 function _file_get_contents( $FilePath )
38 {
39 global $CachedFiles;
40
41 if( isset( $CachedFiles[ $FilePath ] ) === false )
42 {
43 $CachedFiles[ $FilePath ] = @file_get_contents( $FilePath );
44 }
45
46 return( $CachedFiles[ $FilePath ] );
47 }
48
63 function _rmdir_recurse( $Path )
64 {
65 $Handle = @opendir( $Path = rtrim( $Path , '/' ).'/' );
66 if( $Handle !== false )
67 {
68 for( ; false !== ( $File = readdir( $Handle ) ) ; )
69 {
70 if( $File != "." and $File != ".." )
71 {
72 $FullPath = $Path.$File;
73 if( is_dir( $FullPath ) )
74 {
75 _rmdir_recurse( $FullPath );
76 rmdir( $FullPath );
77 }
78 else
79 {
80 unlink( $FullPath );
81 }
82 }
83 }
84 closedir( $Handle );
85 }
86 }
87
88 global $LoadedPackagesPaths;
89 $LoadedPackagesPaths = array();
90
109 function _get_loaded_packages_paths()
110 {
111 try
112 {
113 global $LoadedPackagesPaths;
114
115 return( $LoadedPackagesPaths );
116 }
117 catch( Exception $e )
118 {
119 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
120 }
121 }
122
123 global $_parsed_objects;
124 $_parsed_objects = array();
125
148 function _compile_data( $k , $v )
149 {
150 if( is_object( $v ) || is_array( $v ) )
151 {
152 global $_parsed_objects;
153
154 if( in_array( $k , $_parsed_objects ) === false || is_numeric( $k ) )
155 {
156 $_parsed_objects[] = $k;
157 $Data = base64_encode( ' { '._collapse_params( $v ).' } ' );
158 }
159 else
160 {
161 $Data = base64_encode( ' {X} ' );
162 }
163 }
164 else
165 {
166 $Data = base64_encode( _collapse_params( $v ).' ' );
167 }
168
169 return( $Data );
170 }
171
190 function _return_params( $Params )
191 {
192 if( $Params === false )
193 {
194 return( 'false' );
195 }
196 elseif( $Params === true )
197 {
198 return( 'true' );
199 }
200 else
201 {
202 return( $Params );
203 }
204 }
205
206 global $_collapse_span_id;
207 $_collapse_span_id = 0;
208
227 function _compile_params( $Params )
228 {
229 global $_collapse_span_id;
230
231 $Str = ' ';
232
233 foreach( $Params as $k => $v )
234 {
235 $Data = _compile_data( $k , $v );
236
237 $_collapse_span_id += 1;
238 $id = $_collapse_span_id;
239
240 $PlaceHolders = array( '{id}' , '{data}' , '{k}' );
241
242 $Template = _file_get_contents( dirname( __FILE__ ).'/../../res/templates/func_link.tpl' );
243
244 $Str .= str_replace( $PlaceHolders , array( $id , $Data , $k ) , $Template );
245 }
246
247 return( $Str );
248 }
249
264 function _collapse_params( &$Params )
265 {
266 if( is_array( $Params ) && count( $Params ) == 0 )
267 {
268 return( '' );
269 }
270
271 if( is_array( $Params ) || is_object( $Params ) )
272 {
273 return( _compile_params( $Params ) );
274 }
275 else
276 {
277 return( _return_params( $Params ) );
278 }
279 }
280
307 function _get_exception_object( $Method , $Args , $ExceptionObject )
308 {
309 $ExceptionMessage = $ExceptionObject->getMessage();
310
311 return( new Exception( "$Method("._collapse_params( $Args ).")::$ExceptionMessage" ) );
312 }
313
336 function _throw_exception_object( $Method , $Args , $ExceptionObject )
337 {
338 throw( _get_exception_object( $Method , $Args , $ExceptionObject ) );
339 }
340
367 function str_replace_once( $Pattern , $Replacement , $Str )
368 {
369 if( strpos( $Str , $Pattern ) !== false )
370 {
371 return( substr_replace( $Str , $Replacement , strpos( $Str , $Pattern ) , strlen( $Pattern ) ) );
372 }
373
374 return( $Str );
375 }
376
377 ?>