ultimix
top.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 top_1_0_0{
27 
38  var $CachedMultyFS = false;
39  var $Database = false;
40  var $Security = false;
41  var $String = false;
42 
53  var $Output = false;
54 
65  function __construct()
66  {
67  try
68  {
69  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
70  $this->Database = get_package( 'database' , 'last' , __FILE__ );
71  $this->Security = get_package( 'security' , 'last' , __FILE__ );
72  $this->String = get_package( 'string' , 'last' , __FILE__ );
73  }
74  catch( Exception $e )
75  {
76  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
77  }
78  }
79 
102  private function get_templates( &$Options )
103  {
104  try
105  {
106  $DirPath = dirname( __FILE__ )."/res/templates/";
107 
108  $FileName = $Options->get_setting( 'header' , 'top_header' );
109  $Header = $this->CachedMultyFS->file_get_contents( "$DirPath$FileName.tpl" );
110 
111  $FileName = $Options->get_setting( 'item' , 'top_item' );
112  $Item = $this->CachedMultyFS->file_get_contents( "$DirPath$FileName.tpl" );
113 
114  $FileName = $Options->get_setting( 'footer' , 'top_footer' );
115  $Footer = $this->CachedMultyFS->file_get_contents( "$DirPath$FileName.tpl" );
116 
117  return( array( $Header , $Item , $Footer ) );
118  }
119  catch( Exception $e )
120  {
121  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
122  }
123  }
124 
147  private function compile_records( &$Options , $Item )
148  {
149  try
150  {
151  $Query = $Options->get_setting( 'query' );
152  $Records = $this->Database->query( $Query );
153  $Records = $this->Database->fetch_results( $Records );
154  foreach( $Records as $i => $Record )
155  {
156  set_field( $Record , 'row_number' , $i + 1 );
157  $this->Output .= $this->String->print_record( $Item , $Record );
158  }
159  }
160  catch( Exception $e )
161  {
162  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
163  }
164  }
165 
166  //TODO: filter 'literal' in the {lang:literal} macro for figure braces
167 
186  function draw_top( &$Options )
187  {
188  try
189  {
190  $this->Output = '';
191  $TopName = $this->Security->get_gp(
192  'top_name' , 'command' , $Options->get_setting( 'top_name' , false )
193  );
194  if( $TopName === false )
195  {
196  return;
197  }
198 
199  $Options->append_file( dirname( __FILE__ )."/conf/cf_$TopName" );
200 
201  $Title = $Options->get_setting( 'title' , false );
202  list( $Header , $Item , $Footer ) = $this->get_templates( $Options );
203 
204  $this->compile_records( $Options , $Item );
205 
206  $this->Output = $Header.$this->Output.$Footer;
207  if( $Title !== false )
208  {
209  $this->Output = "<h3>{lang:$Title}</h3>".$this->Output;
210  }
211  }
212  catch( Exception $e )
213  {
214  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
215  }
216  }
217 
240  function view( &$Options )
241  {
242  try
243  {
244  $ContextSet = get_package( 'gui::context_set' , 'last' , __FILE__ );
245 
246  $ContextSet->add_context( dirname( __FILE__ ).'/conf/cfcx_top' );
247 
248  if( $ContextSet->execute( $Options , $this , __FILE__ ) )
249  {
250  return( $this->Output );
251  }
252  }
253  catch( Exception $e )
254  {
255  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
256  }
257  }
258  }
259 ?>