ultimix
content_view.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 $Output;
39 
50  var $CachedMultyFS = false;
51  var $ContentAccess = false;
52  var $ContentAlgorithms = false;
53  var $PageMeta = false;
54  var $Security = false;
55  var $Settings = false;
56  var $String = false;
57 
68  function __construct()
69  {
70  try
71  {
72  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
73  $this->ContentAccess = get_package( 'content::content_access' , 'last' , __FILE__ );
74  $this->ContentAlgorithms = get_package( 'content::content_algorithms' , 'last' , __FILE__ );
75  $this->PageMeta = get_package( 'page::page_meta' , 'last' , __FILE__ );
76  $this->Security = get_package( 'security' , 'last' , __FILE__ );
77  $this->Settings = get_package( 'settings::package_settings' , 'last' , __FILE__ );
78  $this->String = get_package( 'string' , 'last' , __FILE__ );
79  }
80  catch( Exception $e )
81  {
82  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
83  }
84  }
85 
104  function pre_generation( &$Options )
105  {
106  try
107  {
108  $PackagePath = _get_package_relative_path_ex( 'content::content_view' , '1.0.0' );
109  $PageCSS = get_package( 'page::page_css' , 'last' , __FILE__ );
110  $PageCSS->add_stylesheet( "{http_host}/$PackagePath/res/css/content.css" );
111  }
112  catch( Exception $e )
113  {
114  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
115  }
116  }
117 
140  private function get_category_names( &$Options )
141  {
142  try
143  {
144  if( $Options->get_setting( 'category_name' , false ) )
145  {
146  $CategoryNames = $Options->get_setting( 'category_name' );
147  }
148  else
149  {
150  $CategoryNames = $this->Settings->get_package_setting( 'content::content_view' , 'last' ,
151  'cf_content_view_conf' , 'content_line_categories' , 'news,article' );
152  }
153 
154  return( $CategoryNames );
155  }
156  catch( Exception $e )
157  {
158  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
159  }
160  }
161 
204  function select_content_line_items( $Start , $Limit , $Field , $Order , $Condition , &$Options )
205  {
206  try
207  {
208  $Category = get_package( 'category::category_algorithms' , 'last' , __FILE__ );
209 
210  $CategoryNames = $this->get_category_names( $Options );
211 
212  $CategoryIds = $Category->get_category_ids( $CategoryNames );
213 
214  return(
215  $this->ContentAccess->select(
216  $Start , $Options->get_setting( 'display_limit' , $Limit ) , $Field , $Order ,
217  "( $Condition ) AND category IN ( ".implode( ' , ' , $CategoryIds ).' )'
218  )
219  );
220  }
221  catch( Exception $e )
222  {
223  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
224  }
225  }
226 
253  private function get_months( &$PublicationStructure , $Year )
254  {
255  try
256  {
257  return(
258  array_unique(
259  get_field_ex(
260  array_filter(
261  $PublicationStructure ,
262  create_function( "\$d" , "return( \$d->publication_year == $Year );" )
263  ) ,
264  'publication_month'
265  )
266  )
267  );
268  }
269  catch( Exception $e )
270  {
271  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
272  }
273  }
274 
305  private function get_month_template( &$PublicationStructure , $Year , $Month )
306  {
307  try
308  {
309  $MonthTemplate = $this->CachedMultyFS->get_template( __FILE__ , 'archive_month.tpl' );
310 
311  $MonthTemplate = $this->String->print_record(
312  $MonthTemplate ,
313  array_filter(
314  $PublicationStructure ,
315  create_function(
316  "\$d" , "return( \$d->publication_year == $Year && \$d->publication_month == $Month );"
317  )
318  )
319  );
320 
321  return( $MonthTemplate );
322  }
323  catch( Exception $e )
324  {
325  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
326  }
327  }
328 
363  private function compile_month_content( $Year , $Month , $MonthTemplate , $CategoryIds )
364  {
365  try
366  {
367  if( $this->Security->get_gp( 'month' , 'integer' , date( 'm' ) ) == $Month )
368  {
369  $Content = $this->ContentAccess->get_content_for_date( $Year , $Month , $CategoryIds );
370 
371  foreach( $Content as $c )
372  {
373  $ContentTemplate = $this->CachedMultyFS->get_template(
374  __FILE__ , 'archive_content.tpl'
375  );
376  $ContentTemplate = $this->String->print_record( $ContentTemplate , $c );
377  $MonthTemplate = str_replace(
378  '{content_data}' , $ContentTemplate.'{content_data}' , $MonthTemplate
379  );
380  }
381  }
382 
383  return( $MonthTemplate );
384  }
385  catch( Exception $e )
386  {
387  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
388  }
389  }
390 
425  private function compile_year_content( $Year , $YearTemplate , $CategoryIds , $PublicationStructure )
426  {
427  try
428  {
429  if( $this->Security->get_gp( 'year' , 'integer' , date( 'Y' ) ) == $Year )
430  {
431  $Months = $this->get_months( $PublicationStructure , $Year );
432 
433  foreach( $Months as $Month )
434  {
435  $MonthTemplate = $this->get_month_template( $PublicationStructure , $Year , $Month );
436 
437  $MonthTemplate = $this->compile_month_content( $Year , $Month , $MonthTemplate , $CategoryIds );
438 
439  $MonthTemplate = str_replace( '{content_data}' , '' , $MonthTemplate );
440  $YearTemplate = str_replace(
441  '{month_data}' , $MonthTemplate.'{month_data}' , $YearTemplate
442  );
443  }
444  }
445 
446  return( $YearTemplate );
447  }
448  catch( Exception $e )
449  {
450  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
451  }
452  }
453 
480  private function compile_years( $PublicationStructure , $Years , $CategoryIds )
481  {
482  try
483  {
484  foreach( $Years as $Year )
485  {
486  $YearTemplate = $this->CachedMultyFS->get_template( __FILE__ , 'archive_year.tpl' );
487  $YearTemplate = str_replace( '{publication_year}' , $Year , $YearTemplate );
488 
489  $YearTemplate = $this->compile_year_content(
490  $Year , $YearTemplate , $CategoryIds , $PublicationStructure
491  );
492 
493  $YearTemplate = str_replace( '{month_data}' , '' , $YearTemplate );
494 
495  $this->Output .= $YearTemplate;
496  }
497  }
498  catch( Exception $e )
499  {
500  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
501  }
502  }
503 
522  function content_archive( &$Options )
523  {
524  try
525  {
526  $CategoryAccess = get_package( 'category::category_algorithms' , 'last' , __FILE__ );
527  $CategoryIds = $CategoryAccess->get_category_ids(
528  $Options->get_setting( 'category' , 'news,article,faq,blog' )
529  );
530 
531  $PublicationStructure = $this->ContentAccess->get_publication_structure( $CategoryIds );
532 
533  $Years = array_unique( get_field_ex( $PublicationStructure , 'publication_year' ) );
534 
535  $this->compile_years( $PublicationStructure , $Years , $CategoryIds );
536  }
537  catch( Exception $e )
538  {
539  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
540  }
541  }
542 
565  function compile_view_content( $ContentId )
566  {
567  try
568  {
569  $Content = $this->ContentAlgorithms->get_by_id( $ContentId );
570  $Template = $this->CachedMultyFS->get_template( __FILE__ , 'content_view_template.tpl' );
571  $Output = $this->String->print_record( $Template , $Content );
572 
573  $this->PageMeta->set_page_title( get_field( $Content , 'title' ) );
574  $this->PageMeta->add_page_keywords( get_field( $Content , 'keywords' ) );
575  $this->PageMeta->add_page_description( get_field( $Content , 'description' ) );
576 
577  return( $Output );
578  }
579  catch( Exception $e )
580  {
581  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
582  }
583  }
584 
603  function view_content( $Options )
604  {
605  try
606  {
607  if( ( $ContentId = $this->Security->get_gp( 'content_id' , 'integer' , false ) ) === false )
608  {
609  $this->Output = '{lang:exact_content_was_not_found}';
610  return;
611  }
612 
613  $this->Output = $this->compile_view_content( $ContentId );
614  }
615  catch( Exception $e )
616  {
617  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
618  }
619  }
620 
643  function view( $Options )
644  {
645  try
646  {
647  $ContextSet = get_package_object( 'gui::context_set' , 'last' , __FILE__ );
648 
649  $Path = dirname( __FILE__ );
650 
651  $ContextSet->add_context( "$Path/conf/cfcxs_content_line" );
652 
653  $ContextSet->add_context( "$Path/conf/cfcxs_content_view" );
654 
655  $ContextSet->add_context( "$Path/conf/cfcxs_content_archive" );
656 
657  $ContextSet->execute( $Options , $this , __FILE__ );
658 
659  return( $this->Output );
660  }
661  catch( Exception $e )
662  {
663  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
664  }
665  }
666  }
667 
668 ?>