ultimix
system_structure_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 $Cache = false;
51  var $CachedMultyFS = false;
52  var $Security = false;
53  var $Settings = false;
54  var $PageAccess = false;
55  var $String = false;
56 
67  function __construct()
68  {
69  try
70  {
71  $this->Cache = get_package( 'cache' , 'last' , __FILE__ );
72  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
73  $this->Security = get_package( 'security' , 'last' , __FILE__ );
74  $this->Settings = get_package( 'settings::package_settings' , 'last' , __FILE__ );
75  $this->PageAccess = get_package( 'page::page_access' , 'last' , __FILE__ );
76  $this->String = get_package( 'string' , 'last' , __FILE__ );
77  }
78  catch( Exception $e )
79  {
80  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
81  }
82  }
83 
106  function get_root_item( $Items )
107  {
108  try
109  {
110  foreach( $Items as $i => $v )
111  {
112  if( $v->page == $v->root_page )
113  {
114  return( $v );
115  }
116  }
117 
118  return( false );
119  }
120  catch( Exception $e )
121  {
122  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
123  }
124  }
125 
152  function get_prev_item( $MainItem , $Items )
153  {
154  try
155  {
156  foreach( $Items as $i => $v )
157  {
158  if( $v->page == $MainItem->root_page )
159  {
160  return( $v );
161  }
162  }
163 
164  return( false );
165  }
166  catch( Exception $e )
167  {
168  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
169  }
170  }
171 
198  function get_item( $Page , $Items )
199  {
200  try
201  {
202  foreach( $Items as $i => $v )
203  {
204  if( $v->page == $Page )
205  {
206  return( $v );
207  }
208  }
209 
210  return( false );
211  }
212  catch( Exception $e )
213  {
214  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
215  }
216  }
217 
248  function compile_map_items( $Map , $RootItem , $Items )
249  {
250  try
251  {
252  $MapPart = '';
253 
254  foreach( $Items as $i )
255  {
256  if( $i->root_page == $RootItem->page && $i->root_page != $i->page )
257  {
258  if( $MapPart === '' )
259  {
260  $MapPart .= $this->CachedMultyFS->get_template( __FILE__ , 'map_start.tpl' );
261  }
262  $MapPart .= $this->compile_map( $i , $Items );
263  }
264  }
265 
266  if( $MapPart !== '' )
267  {
268  $MapPart .= $this->CachedMultyFS->get_template( __FILE__ , 'map_end.tpl' );
269  }
270 
271  return( $MapPart );
272  }
273  catch( Exception $e )
274  {
275  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
276  }
277  }
278 
305  function compile_map( $RootItem , $Items )
306  {
307  try
308  {
309  $Map = '';
310 
311  $PageDescription = $this->PageAccess->get_page_description( $RootItem->page );
312 
313  $Map .= $this->CachedMultyFS->get_template( __FILE__ , 'map_item_start.tpl' ).
314  ( strlen( $RootItem->navigation ) ? $RootItem->navigation :
315  '{href:tpl=std;page=./'.$RootItem->page.'.html;raw_text='.$PageDescription[ 'title' ].'}' );
316 
317  $Map .= $this->compile_map_items( $Map , $RootItem , $Items );
318 
319  $Map .= $this->CachedMultyFS->get_template( __FILE__ , 'map_item_end.tpl' );
320 
321  return( $Map );
322  }
323  catch( Exception $e )
324  {
325  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
326  }
327  }
328 
351  function draw_map( $Options )
352  {
353  try
354  {
355  $Data = $this->Cache->get_data( 'full_map' );
356  if( $Data === false )
357  {
358  $Access = get_package( 'system_structure::system_structure_access' , 'last' , __FILE__ );
359 
360  $Items = $Access->unsafe_select();
361  $RootItem = $this->get_root_item( $Items );
362 
363  $Map = $this->CachedMultyFS->get_template( __FILE__ , 'map_start.tpl' );
364  $Map .= $this->compile_map( $RootItem , $Items );
365  $Map .= $this->CachedMultyFS->get_template( __FILE__ , 'map_end.tpl' );
366 
367  $this->Cache->add_data( 'full_map' , $Map );
368 
369  $this->Output = $Map;
370  }
371  else
372  {
373  $this->Output = $Data;
374  }
375  }
376  catch( Exception $e )
377  {
378  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
379  }
380  }
381 
400  private function get_separator()
401  {
402  try
403  {
404  $Separator = $this->Settings->get_package_setting(
405  'system_structure::system_structure_view' , 'last' , 'cf_system_structure' ,
406  'bread_crumbs_separator' , '&nbsp;&gt;&nbsp;'
407  );
408 
409  return( $Separator );
410  }
411  catch( Exception $e )
412  {
413  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
414  }
415  }
416 
447  private function compile_item_loop( $Str , $MainItem , $Items )
448  {
449  try
450  {
451  $Counter = 1;
452  $Separator = $this->get_separator();
453 
454  while( $MainItem !== false && $MainItem->page != $MainItem->root_page )
455  {
456  $Str = $Separator.$Str;
457  $MainItem = $this->get_item( $MainItem->root_page , $Items );
458  $PageDescription = $this->PageAccess->get_page_description( $MainItem->page );
459  $Str = (
460  strlen( $MainItem->navigation ) != 0 ? $MainItem->navigation : '{href:tpl=std;page=./'.
461  $MainItem->page.'.html;raw_text='.$PageDescription[ 'title' ].'}'
462  ).$Str;
463  $Counter++;
464  }
465 
466  return( array( $Str , $Counter ) );
467  }
468  catch( Exception $e )
469  {
470  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
471  }
472  }
473 
504  private function compile_items( &$Options , $MainItem , $Items )
505  {
506  try
507  {
508  $PageDescription = $this->PageAccess->get_page_description( $MainItem->page );
509  $Str = strlen( $MainItem->navigation ) != 0 ? $MainItem->navigation : '{href:tpl=std;page=./'.
510  $MainItem->page.'.html;raw_text='.$PageDescription[ 'title' ].'}';
511 
512  list( $Str , $Counter ) = $this->compile_item_loop( $Str , $MainItem , $Items );
513 
514  if( $Options->get_setting( 'show_on_root_page' , false ) == false )
515  {
516  if( $Counter == 1 )
517  {
518  $Str = '';
519  }
520  }
521 
522  return( $Str );
523  }
524  catch( Exception $e )
525  {
526  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
527  }
528  }
529 
552  private function compile_bread_crumbs( &$Options )
553  {
554  try
555  {
556  $PageName = $this->Security->get_g( 'page_name' , 'command' );
557  $Access = get_package( 'system_structure::system_structure_access' , 'last' , __FILE__ );
558  $Items = $Access->unsafe_select();
559  $MainItem = $this->get_item( $PageName , $Items );
560 
561  if( $MainItem !== false )
562  {
563  $Str = $this->compile_items( $Options , $MainItem , $Items );
564  }
565  else
566  {
567  $Str = '';
568  }
569 
570  return( $Str );
571  }
572  catch( Exception $e )
573  {
574  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
575  }
576  }
577 
600  function draw_bread_crumbs( &$Options )
601  {
602  try
603  {
604  $PageName = $this->Security->get_g( 'page_name' , 'command' );
605  $Data = $this->Cache->get_data( "bread_crumbs_for_$PageName" );
606 
607  if( $Data === false )
608  {
609  $Str = $this->compile_bread_crumbs( $Options );
610 
611  $this->Cache->add_data( "bread_crumbs_for_$PageName" , $Str );
612 
613  $this->Output = $Str;
614  }
615  else
616  {
617  $this->Output = $Data;
618  }
619  }
620  catch( Exception $e )
621  {
622  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
623  }
624  }
625 
648  function view( &$Options )
649  {
650  try
651  {
652  $ContextSet = get_package_object( 'gui::context_set' , 'last' , __FILE__ );
653 
654  $ContextSet->add_context( dirname( __FILE__ ).'/conf/cfcx_map' );
655 
656  $ContextSet->add_context( dirname( __FILE__ ).'/conf/cfcx_bread_crumbs' );
657 
658  $ContextSet->execute( $Options , $this , __FILE__ );
659 
660  return( $this->Output );
661  }
662  catch( Exception $e )
663  {
664  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
665  }
666  }
667  }
668 
669 ?>