ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

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
26 class utilities_1_0_0{
27
66 function read_file( $Files , $Path , $File , $Mask = '/.+/' , $Recursive = true )
67 {
68 try
69 {
70 if( $File != "." && $File != ".." && $File != 'index.html' )
71 {
72 $FullPath = $Path.$File;
73
74 if( $Recursive && is_dir( $FullPath ) )
75 {
76 $Files = array_merge(
77 $Files ,
78 $this->get_files_from_directory( $FullPath , $Mask , $Recursive )
79 );
80 }
81 elseif( preg_match( $Mask , $FullPath ) )
82 {
83 $Files [] = $FullPath;
84 }
85 }
86
87 return( $Files );
88 }
89 catch( Exception $e )
90 {
91 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
92 }
93 }
94
125 function get_files_from_directory( $Path , $Mask = '/.+/' , $Recursive = true )
126 {
127 try
128 {
129 $Path = rtrim( $Path , '/' ).'/';
130
131 $Handle = @opendir( $Path );
132 $Files = array();
133
134 if( $Handle !== false )
135 {
136 for( ; false !== ( $File = readdir( $Handle ) ) ; )
137 {
138 $Files = $this->read_file( $Files , $Path , $File , $Mask , $Recursive );
139 }
140
141 closedir( $Handle );
142 }
143
144 return( $Files );
145 }
146 catch( Exception $e )
147 {
148 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
149 }
150 }
151
174 function zip_directory( $Directory , $ArchivePath )
175 {
176 try
177 {
178 $Files = $this->get_files_from_directory( $Directory );
179
180 $Text = get_package( 'string::text' , 'last' , __FILE__ );
181 $Files = $Text->trim_common_prefix( $Files );
182
183 $Zip = new ZipArchive;
184 $Zip->open( "$ArchivePath" , ZIPARCHIVE::CREATE );
185 foreach( $Files as $i => $File )
186 {
187 $Zip->addFile( "$Directory/$File" , $File );
188 }
189 $Zip->close();
190 }
191 catch( Exception $e )
192 {
193 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
194 }
195 }
196
223 function pack_into_url( $Params , $Exceptions )
224 {
225 try
226 {
227 $Tmp = array();
228
229 foreach( $Params as $k => $v )
230 {
231 if( in_array( $k , $Exceptions ) === false )
232 {
233 $Tmp [] = "$k=$v";
234 }
235 }
236
237 return( implode( '&' , $Tmp ) );
238 }
239 catch( Exception $e )
240 {
241 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
242 }
243 }
244
275 function get_package( &$Settings , $File , $Prefix = '' )
276 {
277 try
278 {
279 $PackageName = $Settings->get_setting( $Prefix.'package_name' );
280
281 $PackageVersion = $Settings->get_setting( $Prefix.'package_version' , 'last' );
282
283 return( get_package( $PackageName , $PackageVersion , $File ) );
284 }
285 catch( Exception $e )
286 {
287 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
288 }
289 }
290
313 function get_package_path( &$Settings )
314 {
315 try
316 {
317 $PackageName = $Settings->get_setting( 'package_name' );
318
319 $PackageVersion = $Settings->get_setting( 'package_version' , 'last' );
320
321 return( _get_package_relative_path_ex( $PackageName , $PackageVersion ) );
322 }
323 catch( Exception $e )
324 {
325 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
326 }
327 }
328
351 function get_records( &$Settings )
352 {
353 try
354 {
355 $Query = $this->Settings->get_setting( 'query' , false );
356 if( $Query )
357 {
358 $this->Database->query_as( DB_OBJECT );
359 $Records = $this->Database->query( $Query );
360 return( $this->Database->fetch_results( $Records ) );
361 }
362 else
363 {
364 $Package = $this->get_package( $Settings , __FILE__ );
365 $FunctionName = $Settings->get_setting( 'access_function_name' , 'simple_select' );
366 if( method_exists( $Package , $FunctionName ) )
367 {
368 return( call_user_func( array( $Package , $FunctionName ) ) );
369 }
370 }
371 throw( new Exception( "Can't get records" ) );
372 }
373 catch( Exception $e )
374 {
375 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
376 }
377 }
378
401 function detect_browser()
402 {
403 try
404 {
405 $UserAgent = $_SERVER['HTTP_USER_AGENT'];
406
407 if( stristr( $UserAgent , 'Firefox' ) !== false )
408 {
409 return( 'firefox' );
410 }
411 elseif( stristr( $UserAgent , 'Chrome' ) !== false )
412 {
413 return( 'chrome' );
414 }
415 elseif( stristr( $UserAgent , 'Safari' ) !== false )
416 {
417 return( 'safari' );
418 }
419 elseif( stristr( $UserAgent , 'Opera' ) !== false )
420 {
421 return( 'opera' );
422 }
423
424 return( 'ie' );
425 }
426 catch( Exception $e )
427 {
428 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
429 }
430 }
431 }
432
433 ?>