ultimix
page_composer.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 
31 
42  var $TemplateName = '';
43 
54  var $TemplateVersion = '';
55 
66  var $Layout = 'default';
67 
78  var $Template = false;
79 
90  var $Packages = false;
91 
102  var $AutoMarkup = false;
103  var $Messages = false;
104  var $PageAccess = false;
106  var $PageCSS = false;
107  var $PageJS = false;
108  var $PageMarkup = false;
109  var $PageMeta = false;
110  var $PageParts = false;
111  var $Security = false;
112  var $String = false;
113  var $Trace = false;
114 
129  private function load_page_packages()
130  {
131  try
132  {
133  $this->AutoMarkup = get_package( 'page::auto_markup' , 'last' , __FILE__ );
134  $this->PageAccess = get_package( 'page::page_access' , 'last' , __FILE__ );
135  $this->PageComposerUtilities = get_package( 'page::page_composer_utilities' , 'last' , __FILE__ );
136  $this->PageCSS = get_package( 'page::page_css' , 'last' , __FILE__ );
137  $this->PageJS = get_package( 'page::page_js' , 'last' , __FILE__ );
138  $this->PageMarkup = get_package( 'page::page_markup' , 'last' , __FILE__ );
139  $this->PageMeta = get_package( 'page::page_meta' , 'last' , __FILE__ );
140  $this->PageParts = get_package( 'page::page_parts' , 'last' , __FILE__ );
141  }
142  catch( Exception $e )
143  {
144  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
145  }
146  }
147 
162  function __construct()
163  {
164  try
165  {
166  $this->Messages = get_package( 'page::messages' , 'last' , __FILE__ );
167  $this->load_page_packages();
168  $this->Security = get_package( 'security' , 'last' , __FILE__ );
169  $this->String = get_package( 'string' , 'last' , __FILE__ );
170  $this->Trace = get_package( 'trace' , 'last' , __FILE__ );
171  }
172  catch( Exception $e )
173  {
174  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
175  }
176  }
177 
196  function pre_generation( &$Options )
197  {
198  try
199  {
200  $PackagePath = _get_package_relative_path_ex( 'page::page_composer' , '1.0.0' );
201  $this->PageCSS->add_stylesheet( "{http_host}/$PackagePath/res/css/core.css" );
202 
203  $Lang = get_package( 'lang' , 'last' , __FILE__ );
204  $Lang->include_strings_js( 'page::page_composer' );
205 
206  $this->PageComposerUtilities->page_permit_validation( $Options );
207  }
208  catch( Exception $e )
209  {
210  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
211  }
212  }
213 
236  function prepare_page_generation( $PageName )
237  {
238  try
239  {
240  if( GZIP_TRAFFIC )
241  {
242  @ob_start( 'ob_gzhandler' , 9 );
243  }
244  $this->Messages->get_success_message_from_session();
245  $PageDescription = $this->PageAccess->get_page_description( $PageName );
246 
247  $this->PageComposerUtilities->translate_template_name( $this , $PageDescription );
248 
249  return( $PageDescription );
250  }
251  catch( Exception $e )
252  {
253  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
254  }
255  }
256 
275  private function set_page_meta_info( &$PageDescription )
276  {
277  try
278  {
279  $this->PageMeta->set_page_title( $PageDescription[ 'title' ] );
280  $this->PageMeta->add_page_keywords( $PageDescription[ 'keywords' ] );
281  $this->PageMeta->add_page_description( $PageDescription[ 'description' ] );
282  }
283  catch( Exception $e )
284  {
285  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
286  }
287  }
288 
307  private function load_layout( $PageDescription )
308  {
309  try
310  {
311  $Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
312  $Settings->load_settings( $PageDescription[ 'options' ] );
313  $this->Layout = $Settings->get_setting( 'layout' , 'default' );
314  }
315  catch( Exception $e )
316  {
317  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
318  }
319  }
320 
347  function fetch_page_data( &$Page , $PageName , $PageDescription )
348  {
349  try
350  {
351  $this->Trace->add_trace_string( "{lang:fetching_data} : $PageName" , COMMON );
352  $this->Template = $this->PageComposerUtilities->get_template_for_package( $PageDescription );
353 
354  $this->set_page_meta_info( $PageDescription );
355 
356  $Options = $PageDescription[ 'options' ];
357  $this->Packages = $this->PageParts->get_package_appliance( $Page , $PageName , $Options );
358 
359  $this->load_layout( $PageDescription );
360 
361  $this->PageParts->fetch_packages( $this->Packages , $this->Template );
362  }
363  catch( Exception $e )
364  {
365  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
366  }
367  }
368 
395  private function apply_options( $Str , $Options )
396  {
397  try
398  {
399  $Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
400 
401  $Settings->load_settings( $Options );
402 
403  return( $this->String->print_record( $Str , $Settings->get_raw_settings() ) );
404  }
405  catch( Exception $e )
406  {
407  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
408  }
409  }
410 
433  private function before_generation( &$Template , $PageDescription )
434  {
435  try
436  {
437  $this->PageParts->execute_generators( $this->Packages , 'pre_generation' , $Template );
438 
439  $Str = $Template->get_template();
440  if( $this->String->block_exists( $Str , 'layout' ) )
441  {
442  $Str = str_replace( '{layout}' , '{include:'.$this->Layout.'}' , $Str );
443  }
444 
445  $Str = $this->apply_options( $Str , $PageDescription[ 'options' ] );
446 
447  $Template->set_template( $Str );
448  }
449  catch( Exception $e )
450  {
451  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
452  }
453  }
454 
477  private function after_generation( &$Template , $PageDescription )
478  {
479  try
480  {
481  $Str = $Template->get_template();
482 
483  if( strpos( $PageDescription[ 'options' ] , 'process_macro=0' ) === false )
484  {
485  $Str = $this->AutoMarkup->compile_string( $Str );
486  }
487 
488  $Template->set_template( $Str );
489 
490  $this->PageComposerUtilities->output_trace_if_necessary( $this );
491  }
492  catch( Exception $e )
493  {
494  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
495  }
496  }
497 
520  function generation_loop( $PageName , $PageDescription )
521  {
522  try
523  {
524  $this->Trace->add_trace_string( "{lang:run_generation_loop} : $PageName" , COMMON );
525 
526  $this->before_generation( $this->Template , $PageDescription );
527 
528  $this->Template->process( $PageName );
529 
530  $this->PageParts->compile_controllers( $this->Packages );
531  $this->PageParts->compile_views( $this->Packages , $this->Template );
532 
533  $this->after_generation( $this->Template , $PageDescription );
534 
535  $this->Template->cleanup( $PageName , $PageDescription[ 'options' ] );
536  }
537  catch( Exception $e )
538  {
539  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
540  }
541  }
542 
565  function get_page( $PageName )
566  {
567  try
568  {
569  $PageDescription = $this->prepare_page_generation( $PageName );
570 
571  if( $PageDescription !== false )
572  {
573  $this->Trace->add_trace_string( "{lang:page_generation_start} : $PageName" , COMMON );
574  $this->fetch_page_data( $this->PageAccess , $PageName , $PageDescription );
575 
576  $this->generation_loop( $PageName , $PageDescription );
577 
578  return( $this->Template->get_template() );
579  }
580 
581  $this->Trace->add_trace_string( "{lang:requested_page_was_not_found} : $PageName" , ERROR );
582 
583  return( $this->get_page( '404' ) );
584  }
585  catch( Exception $e )
586  {
587  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
588  }
589  }
590 
613  function view( &$Options )
614  {
615  try
616  {
617  $PageMarkupUtilities = get_package(
618  'page::page_markup::page_markup_utilities' , 'last' , __FILE__
619  );
620 
621  if( $Options->get_setting( 'direct_view' , false ) )
622  {
623  $Options->load_from_http();
624 
625  return( $PageMarkupUtilities->direct_view( $Options ) );
626  }
627  if( $Options->get_setting( 'direct_controller' , false ) )
628  {
629  $Options->load_from_http();
630 
631  $PageMarkupUtilities->direct_controller( $Options );
632 
633  return;
634  }
635  }
636  catch( Exception $e )
637  {
638  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
639  }
640  }
641  }
642 
643 ?>