ultimix
page_parts.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 
27 
38  var $Cache = false;
39  var $CachedMultyFS = false;
40  var $PageComposer = false;
41  var $PageMarkupUtilities = false;
42  var $Settings = false;
43  var $String = false;
44  var $Trace = false;
45 
56  function __construct()
57  {
58  try
59  {
60  $this->Cache = get_package( 'cache' , 'last' , __FILE__ );
61  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
62  $this->PageMarkupUtilities = get_package(
63  'page::page_markup::page_markup_utilities' , 'last' , __FILE__
64  );
65  $this->Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
66  $this->String = get_package( 'string' , 'last' , __FILE__ );
67  $this->Trace = get_package( 'trace' , 'last' , __FILE__ );
68  }
69  catch( Exception $e )
70  {
71  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
72  }
73  }
74 
97  function throw_method_was_not_found_exception( $p , $FunctionName )
98  {
99  $ClassName = $p[ 'fetched_package' ] !== false ? get_class( $p[ 'fetched_package' ] ) : 'false';
100 
101  $PackageFullName = $p[ 'package' ].'.'.$p[ 'package_version' ];
102 
103  throw(
104  new Exception(
105  'Function "'.$FunctionName.'" was not found in class "'.$ClassName.
106  '" from package '.$PackageFullName
107  )
108  );
109  }
110 
137  function get_settings_for_package( $PackageName , $PackageVersion )
138  {
139  try
140  {
141  $PackageDirectory = _get_package_relative_path_ex( $PackageName , $PackageVersion );
142 
143  if( $this->CachedMultyFS->file_exists( "$PackageDirectory/conf/cf_global_settings" ) )
144  {
145  return( $this->CachedMultyFS->file_get_contents( "$PackageDirectory/conf/cf_global_settings" ) );
146  }
147  else
148  {
149  return( '' );
150  }
151  }
152  catch( Exception $e )
153  {
154  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
155  }
156  }
157 
184  function get_controller( $PackageName , $PackageVersion )
185  {
186  try
187  {
188  $Package = get_package( $PackageName , $PackageVersion , __FILE__ );
189 
190  if( $Package === false )
191  {
192  $Package = get_package_object( 'page::auto_controller' , 'last' , __FILE__ );
193  $Package->set_path( _get_package_relative_path_ex(
194  $PackageName , $PackageVersion ).'/unexisting_controller.php'
195  );
196  }
197 
198  return( $Package );
199  }
200  catch( Exception $e )
201  {
202  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
203  }
204  }
205 
232  function get_view( $PackageName , $PackageVersion )
233  {
234  try
235  {
236  $Package = get_package( $PackageName , $PackageVersion , __FILE__ );
237  if( $Package === false )
238  {
239  $Package = get_package_object( 'page::auto_view' , 'last' , __FILE__ );
240  $Package->set_path(
241  _get_package_relative_path_ex( $PackageName , $PackageVersion ).'/unexisting_view.php'
242  );
243  }
244  return( $Package );
245  }
246  catch( Exception $e )
247  {
248  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
249  }
250  }
251 
282  private function get_predefined_packages( $PageOptions )
283  {
284  try
285  {
286  $this->Settings->load_settings( $PageOptions );
287  $PredefinedPackages = array();
288  if( $this->Settings->get_setting( 'predefined_packages' , false ) )
289  {
290  $Raw = $this->CachedMultyFS->file_get_contents(
291  dirname( __FILE__ ).'/conf/cf_predefined_packages' , 'exploded'
292  );
293  foreach( $Raw as $Value )
294  {
295  $Tmp = explode( '#' , $Value );
296  $PredefinedPackages [] = array(
297  'package' => $Tmp[ 0 ] , 'package_version' => $Tmp[ 1 ] ,
298  'options' => $Tmp[ 2 ] , 'placeholder' => $Tmp[ 3 ]
299  );
300  }
301  }
302  return( $PredefinedPackages );
303  }
304  catch( Exception $e )
305  {
306  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
307  }
308  }
309 
340  function get_package_appliance( $Page , $PageName , $PageOptions )
341  {
342  try
343  {
344  $PagePackages = $Page->get_package_appliance( $PageName );
345  $PredefinedPackages = $this->get_predefined_packages( $PageOptions );
346 
347  return( array_merge( $PredefinedPackages , $PagePackages ) );
348  }
349  catch( Exception $e )
350  {
351  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
352  }
353  }
354 
377  function load_settings_for_package( &$Package , &$Template )
378  {
379  try
380  {
381  $Package[ 'settings' ] = get_package_object( 'settings::settings' , 'last' , __FILE__ );
382 
383  $GlobalSettings = $this->get_settings_for_package(
384  $Package[ 'package' ] , $Package[ 'package_version' ]
385  );
386 
387  $Package[ 'settings' ]->load_settings( $GlobalSettings );
388  $Package[ 'settings' ]->append_settings( $Package[ 'options' ] );
389 
390  $PlaceHolderParameters = $Template->get_placeholder_parameters( $Package[ 'placeholder' ] );
391 
392  if( $PlaceHolderParameters !== false )
393  {
394  $Package[ 'settings' ]->append_settings( $PlaceHolderParameters );
395  }
396  }
397  catch( Exception $e )
398  {
399  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
400  }
401  }
402 
421  private function get_package_for_description( &$p )
422  {
423  try
424  {
425  if( $p[ 'settings' ]->get_setting( 'controller' , false ) == '1' )
426  {
427  $p[ 'fetched_package' ] = $this->get_controller( $p[ 'package' ] , $p[ 'package_version' ] );
428  }
429  elseif( $p[ 'settings' ]->get_setting( 'view' , false ) == '1' )
430  {
431  $p[ 'fetched_package' ] = $this->get_view( $p[ 'package' ] , $p[ 'package_version' ] );
432  }
433  else
434  {
435  $p[ 'fetched_package' ] = get_package( $p[ 'package' ] , $p[ 'package_version' ] , __FILE__ );
436  }
437  }
438  catch( Exception $e )
439  {
440  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
441  }
442  }
443 
466  function fetch_packages( &$Packages , &$Template )
467  {
468  try
469  {
470  foreach( $Packages as $i => $p )
471  {
472  $this->load_settings_for_package( $Packages[ $i ] , $Template );
473 
474  if( $Packages[ $i ][ 'settings' ]->get_setting( 'meta' , false ) !== false )
475  {
476  $PackagePath = _get_package_relative_path_ex( $p[ 'package' ] , $p[ 'package_version' ] );
477  $MetaFileName = $Packages[ $i ][ 'settings' ]->get_setting( 'meta' );
478  $MetaSettings = $this->CachedMultyFS->file_get_contents( "$PackagePath/meta/$MetaFileName" );
479  $Packages[ $i ][ 'settings' ]->append_settings( $MetaSettings );
480  }
481 
482  $this->get_package_for_description( $Packages[ $i ] );
483  }
484  }
485  catch( Exception $e )
486  {
487  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
488  }
489  }
490 
517  function execute_generators( &$Packages , $Type , &$Template )
518  {
519  try
520  {
521  $this->Trace->start_group( $Type );
522 
523  $Changed = false;
524  $Template->add_stylesheets();
525  $counter = 0;
526 
527  foreach( $Packages as $i => $p )
528  {
529  if( $p[ 'settings' ]->get_setting( $Type , false ) )
530  {
531  if( method_exists( $p[ 'fetched_package' ] , $Type ) )
532  {
533  $Caller = array( $p[ 'fetched_package' ] , $Type );
534  $Settings = $p[ 'settings' ];
535  call_user_func( $Caller , $Settings );
536  continue;
537  }
538  $this->throw_method_was_not_found_exception( $p , $Type );
539  }
540  }
541  $this->Trace->end_group();
542  }
543  catch( Exception $e )
544  {
545  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
546  }
547  }
548 
567  private function run_single_controller( &$p )
568  {
569  try
570  {
571  $ClassName = get_class( $p[ 'fetched_package' ] );
572 
573  $this->Trace->start_group( "controller : $ClassName" );
574 
575  $p[ 'fetched_package' ]->controller( $p[ 'settings' ] );
576 
577  $this->Trace->end_group();
578  }
579  catch( Exception $e )
580  {
581  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
582  }
583  }
584 
603  function compile_controllers( &$Packages )
604  {
605  try
606  {
607  $this->Trace->start_group( "controllers" );
608 
609  foreach( $Packages as $i => $p )
610  {
611  if( $p[ 'settings' ]->get_setting( 'controller' , false ) )
612  {
613  if( method_exists( $p[ 'fetched_package' ] , 'controller' ) )
614  {
615  $this->run_single_controller( $p );
616  }
617  else
618  {
619  $this->throw_method_was_not_found_exception( $p , 'controller' );
620  }
621  }
622  }
623 
624  $this->Trace->end_group();
625  }
626  catch( Exception $e )
627  {
628  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
629  }
630  }
631 
654  private function run_single_view( &$p , &$Template )
655  {
656  try
657  {
658  if( $p[ 'settings' ]->get_setting( 'cached' , false ) == 1 &&
659  $this->Cache->data_exists( $p[ 'options' ] ) )
660  {
661  $View = $this->Cache->get_data( $p[ 'options' ] );
662  }
663  else
664  {
665  $this->Trace->start_group( "view : ".get_class( $p[ 'fetched_package' ] ) );
666 
667  $View = $p[ 'fetched_package' ]->view( $p[ 'settings' ] );
668 
669  $View = $this->PageMarkupUtilities->wrap_control_view(
670  $p[ 'settings' ] , $View
671  );
672 
673  $this->Cache->add_data( $p[ 'options' ] , $View );
674 
675  $this->Trace->end_group();
676  }
677 
678  $Template->parse( $p[ 'placeholder' ] , $View );
679  }
680  catch( Exception $e )
681  {
682  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
683  }
684  }
685 
708  function compile_views( &$Packages , &$Template )
709  {
710  try
711  {
712  $this->Trace->start_group( "views" );
713 
714  foreach( $Packages as $i => $p )
715  {
716  if( $p[ 'placeholder' ] != '' )
717  {
718  if( $p[ 'settings' ]->get_setting( 'view' , false ) )
719  {
720  if( $p[ 'fetched_package' ] !== false && method_exists( $p[ 'fetched_package' ] , 'view' ) )
721  {
722  $this->run_single_view( $p , $Template );
723  }
724  else
725  {
726  $this->throw_method_was_not_found_exception( $p , 'view' );
727  }
728  }
729  }
730  }
731 
732  $this->Trace->end_group();
733  }
734  catch( Exception $e )
735  {
736  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
737  }
738  }
739  }
740 
741 ?>