ultimix
template_content_access.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 $CachedMultyFS = false;
39  var $Security = false;
40  var $SecurityParser = false;
41 
52  function __construct()
53  {
54  try
55  {
56  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
57  $this->Security = get_package( 'security' , 'last' , __FILE__ );
58  $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
59  }
60  catch( Exception $e )
61  {
62  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
63  }
64  }
65 
76  var $AddCondition = false;
77 
96  function set_add_condition( $theAddCondition )
97  {
98  try
99  {
100  if( $this->AddCondition === false )
101  {
102  $this->AddCondition = $theAddCondition;
103  }
104  else
105  {
106  throw( new Exception( '"AddCondition" was already set' ) );
107  }
108  }
109  catch( Exception $e )
110  {
111  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
112  }
113  }
114 
137  function select_list( $id )
138  {
139  try
140  {
141  $id = $this->Security->get( $id , 'string' );
142 
143  $id = explode( ',' , $id );
144 
145  $Return = array();
146 
147  foreach( $id as $k => $v )
148  {
149  $Return [] = array( 'content' => $this->Security->get( $this->get_content( $v ) , 'string' ) );
150  }
151 
152  return( $Return );
153  }
154  catch( Exception $e )
155  {
156  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
157  }
158  }
159 
182  function update( $id , $Record )
183  {
184  try
185  {
186  $id = $this->Security->get( $id , 'string' );
187  $id = explode( ',' , $id );
188 
189  $Record = $this->SecurityParser->parse_parameters( $Record , 'content:string' , 'allow_not_set' );
190  $Template = get_field( $Record , 'content' );
191  $Template = $this->Security->get( $Template , 'unsafe_string' );
192 
193  foreach( $id as $k => $v )
194  {
195  $this->CachedMultyFS->file_put_contents( $this->get_content_path( $v ) , $Template );
196  }
197  }
198  catch( Exception $e )
199  {
200  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
201  }
202  }
203 
226  function try_virtual_path( $VirtualPath )
227  {
228  try
229  {
230  $Path = false;
231 
232  if( $this->AddCondition !== false )
233  {
234  $Path = $this->CachedMultyFS->get_file_path( $VirtualPath."_$this->AddCondition" , false );
235  }
236 
237  if( $Path === false )
238  {
239  $Path = $this->CachedMultyFS->get_file_path( $VirtualPath , false );
240  }
241 
242  return( $Path );
243  }
244  catch( Exception $e )
245  {
246  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
247  }
248  }
249 
272  function get_content_path( $Template )
273  {
274  try
275  {
276  $VirtualPath = dirname( __FILE__ )."/res/templates/$Template";
277 
278  if( ( $Path = $this->try_virtual_path( $VirtualPath ) ) !== false )
279  {
280  return( $Path );
281  }
282 
283  return( false );
284  }
285  catch( Exception $e )
286  {
287  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
288  }
289  }
290 
313  function get_content( $Template )
314  {
315  try
316  {
317  $Path = $this->get_content_path( $Template );
318 
319  if( $Path !== false && $this->CachedMultyFS->file_exists( $Path ) )
320  {
321  return( $this->CachedMultyFS->file_get_contents( $Path ) );
322  }
323  else
324  {
325  throw( new Exception( "The content \"$Template\" was not found. Path : $Path" ) );
326  }
327  }
328  catch( Exception $e )
329  {
330  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
331  }
332  }
333 
364  function get_package_template( $PackageName , $PackageVersion , $Template )
365  {
366  try
367  {
368  $PackageName = $this->Security->get( $PackageName , 'string' );
369  $PackageVersion = $this->Security->get( $PackageVersion , 'string' );
370  $Template = $this->Security->get( $Template , 'string' );
371 
372  $Path = _get_package_relative_path_ex( $PackageName , $PackageVersion )."/res/templates/$Template";
373 
374  return( $this->CachedMultyFS->file_get_contents( $Path ) );
375  }
376  catch( Exception $e )
377  {
378  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
379  }
380  }
381 
404  function get_package_file( &$Options )
405  {
406  try
407  {
408  $PackageName = $Options->get_setting( 'package_name' , false );
409  $PackageVersion = $Options->get_setting( 'package_version' , 'last' );
410  $FileName = $Options->get_setting( 'template' , false );
411 
412  return( $this->get_package_template( $PackageName , $PackageVersion , $FileName ) );
413  }
414  catch( Exception $e )
415  {
416  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
417  }
418  }
419 
442  function get_content_ex( $Options )
443  {
444  try
445  {
446  $PackageName = $Options->get_setting( 'package_name' , false );
447 
448  if( $PackageName === false )
449  {
450  return( $this->get_content( $Options->get_setting( 'template' ) ) );
451  }
452  else
453  {
454  return( $this->get_package_file( $Options ) );
455  }
456  }
457  catch( Exception $e )
458  {
459  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
460  }
461  }
462  }
463 
464 ?>