ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

package_algorithms.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 package_algorithms_1_0_0{
27
38 var $Utilities = false;
39
50 function __construct()
51 {
52 try
53 {
54 $this->Utilities = get_package( 'utilities' , 'last' , __FILE__ );
55 }
56 catch( Exception $e )
57 {
58 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
59 }
60 }
61
80 function execute_script_line( $ScriptLine )
81 {
82 try
83 {
84 $Params = get_package_object( 'settings::settings' , 'last' , __FILE__ );
85 $Params->load_settings( $ScriptLine );
86
87 if( $Params->get_setting( 'command' , '' ) === 'install_package' )
88 {
89 $PackageFilePath = $Params->get_setting( 'package_file_path' , '' );
90 $MasterPackageName = $Params->get_setting( 'master_package_name' , '' );
91 $MasterPackageVersion = $Params->get_setting( 'master_package_version' , '' );
92
93 $this->install_package( $PackageFilePath , $MasterPackageName , $MasterPackageVersion );
94 return;
95 }
96
97 throw( new Exception( 'Command '.$ScriptLine.' was not executed' ) );
98 }
99 catch( Exception $e )
100 {
101 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
102 }
103 }
104
135 function get_master_package( $PackageFilePath , $MasterPackageName , $MasterPackageVersion )
136 {
137 try
138 {
139 if( $MasterPackageName === 'auto' )
140 {
141 $Zip = new ZipArchive;
142 if( $Zip->open( $FileSource ) === true )
143 {
144 $Conf = $Zip->getFromName( './install/cf_install' );
145 if( $Conf === false )
146 {
147 $Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
148 $Settings->load_setings( $Conf );
149 $MasterPackageName = $Settings->get_setting( 'master_package_name' , '/' );
150 $MasterPackageVersion = $Settings->get_setting( 'master_package_version' , 'last' );
151 }
152
153 $Zip->close();
154 }
155 }
156
157 return( array( $MasterPackageName , $MasterPackageVersion ) );
158 }
159 catch( Exception $e )
160 {
161 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
162 }
163 }
164
191 private function get_root_dir( $MasterPackageName , $MasterPackageVersion )
192 {
193 try
194 {
195 if( $MasterPackageName === '/' )
196 {
197 $ROOT_DIR = INSTALL_DIR;
198 }
199 else
200 {
201 $ROOT_DIR = _get_root_dir( $MasterPackageName , $MasterPackageVersion , INSTALL_DIR );
202 $ROOT_DIR = _get_package_path( $MasterPackageName , $MasterPackageVersion , $ROOT_DIR );
203 }
204
205 return( $ROOT_DIR );
206 }
207 catch( Exception $e )
208 {
209 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
210 }
211 }
212
239 function install_package( $PackageFilePath , $MasterPackageName , $MasterPackageVersion )
240 {
241 try
242 {
243 list( $MasterPackageName , $MasterPackageVersion ) = $this->get_master_package(
244 $PackageFilePath , $MasterPackageName , $MasterPackageVersion
245 );
246
247 $ROOT_DIR = $this->get_root_dir( $MasterPackageName , $MasterPackageVersion );
248
249 $PackageFolder = _install_package( $PackageFilePath , $ROOT_DIR );
250
251 $PageComposer = get_package( 'page::page_composer' , 'last' , __FILE__ );
252 $PageComposer->add_success_message( 'package_was_installed' );
253
254 _drop_core_cache();
255 }
256 catch( Exception $e )
257 {
258 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
259 }
260 }
261
288 function get_package_time( $Directory , $TimeFunc = '' )
289 {
290 try
291 {
292 $Utilities = get_package( 'utilities' , 'last' , __FILE__ );
293 $Files = $Utilities->get_files_from_directory( $Directory );
294
295 if( count( $Files ) )
296 {
297 $Time = $TimeFunc( $Files[ 0 ] );
298 foreach( $Files as $k => $v )
299 {
300 $Tmp = $TimeFunc( $v );
301 if( $Tmp > $Time )
302 {
303 $Time = $Tmp;
304 }
305 }
306
307 return( $Time );
308 }
309
310 return( false );
311 }
312 catch( Exception $e )
313 {
314 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
315 }
316 }
317
336 function get_packages_list()
337 {
338 try
339 {
340 $List = _get_packages_list();
341
342 foreach( $List as $i => $l )
343 {
344 $RootDir = _get_root_dir( $l[ 'package_name' ] , $l[ 'package_version' ] , INSTALL_DIR );
345 $PackagePath = _get_package_path( $l[ 'package_name' ] , $l[ 'package_version' ] , $RootDir );
346
347 $FileMTime = $this->get_package_time( $PackagePath , 'filemtime' );
348 $List[ $i ][ 'modify_date' ] = date( 'Y-m-d&\nb\sp;G:i:s' , $FileMTime );
349
350 $FileATime = $this->get_package_time( $PackagePath , 'fileatime' );
351 $List[ $i ][ 'access_date' ] = date( 'Y-m-d&\nb\sp;G:i:s' , $FileATime );
352 }
353
354 return( $List );
355 }
356 catch( Exception $e )
357 {
358 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
359 }
360 }
361
384 function get_meta_files( $PackageInfo )
385 {
386 try
387 {
388 $PackagePath = _get_package_relative_path_ex(
389 $PackageInfo[ 'full_package_name' ] , $PackageInfo[ 'full_package_version' ]
390 );
391
392 return( $this->Utilities->get_files_from_directory( "$PackagePath/meta" , '/meta_.+/' ) );
393 }
394 catch( Exception $e )
395 {
396 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
397 }
398 }
399
422 function get_config_files( $PackageInfo )
423 {
424 try
425 {
426 $PackagePath = _get_package_relative_path_ex(
427 $PackageInfo[ 'full_package_name' ] , $PackageInfo[ 'full_package_version' ]
428 );
429
430 return( $this->Utilities->get_files_from_directory( "$PackagePath/conf" , '/_.+/' ) );
431 }
432 catch( Exception $e )
433 {
434 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
435 }
436 }
437
460 function get_packages_tree( $List = false )
461 {
462 try
463 {
464 if( $List === false )
465 {
466 $List = _get_packages_tree();
467 }
468
469 foreach( $List as $i => $l )
470 {
471 $List[ $i ][ 'subpackages' ] = $this->get_packages_tree( $List[ $i ][ 'subpackages' ] );
472 $List[ $i ][ 'meta' ] = $this->get_meta_files( $List[ $i ] );
473 $List[ $i ][ 'conf' ] = $this->get_config_files( $List[ $i ] );
474 }
475
476 return( $List );
477 }
478 catch( Exception $e )
479 {
480 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
481 }
482 }
483
518 function select_packages( $Start , $Limit , $Field = false , $Order = false )
519 {
520 try
521 {
522 $List = $this->get_all_packages();
523 if( $Order !== false )
524 {
525 $SortSign = $Order === 'ascending' ? '<' : '>';
526 $SortFunc = create_function(
527 '$a , $b' ,
528 "if( \$a[ '$Field' ] == \$b[ '$Field' ] )return(0);".
529 "return( \$a[ '$Field' ] $SortSign \$b[ '$Field' ] ? -1 : 1 );"
530 );
531 usort( $List , $SortFunc );
532 }
533
534 $Ret = array();
535 foreach( $List as $i => $l )
536 {
537 if( $i >= $Start && $i < $Start + $Limit )
538 {
539 $Ret [] = $l;
540 }
541 }
542 return( $Ret );
543 }
544 catch( Exception $e )
545 {
546 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
547 }
548 }
549 }
550
551 ?>