ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

template_manager.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 template_manager_1_0_0{
27
50 function register_template( $TemplateName , $TemplateVersion )
51 {
52 try
53 {
54 $Security = get_package( 'security' , 'last' , __FILE__ );
55 $TemplateName = $Security->get( $TemplateName , 'string' );
56 $TemplateVersion = $Security->get( $TemplateVersion , 'string' );
57
58 $Handle = fopen( dirname( __FILE__ ).'/data/template_list' , 'a+' );
59
60 if( $Handle === false )
61 {
62 return( false );
63 }
64
65 $TemplateInfo = $TemplateName.'#'.$TemplateVersion."\r\n";
66
67 fwrite( $Handle , $TemplateInfo , strlen( $TemplateInfo ) );
68
69 fclose( $Handle );
70 }
71 catch( Exception $e )
72 {
73 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
74 }
75 }
76
95 function get_template_list()
96 {
97 try
98 {
99 $RawTemplateList = $this->CachedMultyFS->file_get_contents(
100 dirname( __FILE__ ).'/data/template_list' , 'exploded'
101 );
102
103 $TemplateList = array();
104
105 foreach( $RawTemplateList as $rtl )
106 {
107 $rtl = str_replace( "\r" , '' , $rtl );
108 $rtl = str_replace( "\n" , '' , $rtl );
109
110 $Trinity = explode( '#' , $rtl );
111
112 $TemplateList [] = array(
113 'name' => $Trinity[ 0 ] , 'version' => $Trinity[ 1 ] , 'default' => $Trinity[ 2 ]
114 );
115 }
116
117 return( $TemplateList );
118 }
119 catch( Exception $e )
120 {
121 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
122 }
123 }
124
147 private function compile_template_list( $Templates )
148 {
149 try
150 {
151 $List = $this->CachedMultyFS->get_template( __FILE__ , 'templates_list_header.tpl' );
152
153 foreach( $TemplateList as $tl )
154 {
155 $Template = $this->CachedMultyFS->get_template( __FILE__ , 'templates_list_item.tpl' );
156 $PlaceHolders = array( '{name}' , '{version}' );
157 $Data = array( $tl[ 'name' ] , $tl[ 'version' ] );
158 $Template = str_replace( $PlaceHolders , $Data , $Template );
159 $List .= $Template;
160 }
161
162 $List .= $this->CachedMultyFS->get_template( __FILE__ , 'templates_list_footer.tpl' );
163
164 return( $List );
165 }
166 catch( Exception $e )
167 {
168 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
169 }
170 }
171
190 function draw_template_list()
191 {
192 try
193 {
194 if( ( $TemplateList = $this->get_template_list() ) === false )
195 {
196 return( false );
197 }
198
199 return( $this->compile_template_list( $Templates ) );
200 }
201 catch( Exception $e )
202 {
203 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
204 }
205 }
206
225 function get_default_template_name()
226 {
227 try
228 {
229 $Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
230
231 $Settings->load_file( dirname( __FILE__ ).'/conf/cf_template_manager_settings' );
232
233 $Name = $Settings->get_setting( 'default_template_name' );
234 $Version = $Settings->get_setting( 'default_template_version' , 'last' );
235
236 return( array( 'name' => $Name , 'version' => $Version ) );
237 }
238 catch( Exception $e )
239 {
240 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
241 }
242 }
243
262 function get_default_admin_template_name()
263 {
264 try
265 {
266 $Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
267
268 $Settings->load_file( dirname( __FILE__ ).'/conf/cf_template_manager_settings' );
269
270 $Name = $Settings->get_setting( 'default_admin_template_name' );
271 $Version = $Settings->get_setting( 'default_admin_template_version' , 'last' );
272
273 return( array( 'name' => $Name , 'version' => $Version ) );
274 }
275 catch( Exception $e )
276 {
277 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
278 }
279 }
280
299 function get_default_template_version()
300 {
301 try
302 {
303 $TemplateList = $this->get_template_list();
304
305 foreach( $TemplateList as $tl )
306 {
307 if( $tl[ 'default' ] === 'default' )
308 {
309 return( $tl[ 'version' ] );
310 }
311 }
312 }
313 catch( Exception $e )
314 {
315 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
316 }
317 }
318
345 function get_template( $TemplateName , $TemplateVersion )
346 {
347 try
348 {
349 $Template = get_package( "$TemplateName" , "$TemplateVersion" , __FILE__ );
350
351 if( $Template === false )
352 {
353 $PackageDirectory = $this->get_template_path( $TemplateName , $TemplateVersion );
354
355 $Template = get_package_object( 'template_manager::default_template_script' , 'last' , __FILE__ );
356 $Template->set_template_path( $PackageDirectory."/unexisting_script.php" );
357
358 return( $Template );
359 }
360 else
361 {
362 return( $Template );
363 }
364 }
365 catch( Exception $e )
366 {
367 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
368 }
369 }
370
397 function get_template_path( $TemplateName , $TemplateVersion )
398 {
399 try
400 {
401 return( _get_package_relative_path_ex( $TemplateName , $TemplateVersion ) );
402 }
403 catch( Exception $e )
404 {
405 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
406 }
407 }
408 }
409
410 ?>