ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

trace.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
16 DEFINE( 'ERROR' , 'error' );
17 DEFINE( 'NOTIFICATION' , 'notification' );
18 DEFINE( 'COMMON' , 'common' );
19 DEFINE( 'QUERY' , 'query' );
20
31 class trace_1_0_0{
32
43 var $StoreTrace = true;
44
55 var $TraceStrings = array();
56
67 var $Templates = array();
68
79 var $CachedMultyFS = false;
80 var $String = false;
81
92 function __construct()
93 {
94 try
95 {
96 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
97 $this->String = get_package( 'string' , 'last' , __FILE__ );
98
99 $Data = array(
100 ERROR => 'trace_line_error.tpl' , COMMON => 'trace_line_common.tpl' ,
101 NOTIFICATION => 'trace_line_notification.tpl' , QUERY => 'trace_line_query.tpl' ,
102 'start_group' => 'trace_start_group.tpl' , 'end_group' => 'trace_end_group.tpl'
103 );
104
105 foreach( $Data as $Key => $Value )
106 {
107 $this->Templates[ $Key ] = $this->CachedMultyFS->get_template( __FILE__ , $Value );
108 }
109 }
110 catch( Exception $e )
111 {
112 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
113 }
114 }
115
138 function add_trace_string( $Str , $Type = COMMON )
139 {
140 try
141 {
142 if( $this->StoreTrace )
143 {
144 $Template = str_replace( '{string}' , $Str , $this->Templates[ $Type ] );
145
146 $this->TraceStrings [] = array( 'name' => 'string' , 'content' => $Template );
147 }
148 }
149 catch( Exception $e )
150 {
151 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
152 }
153 }
154
173 function start_group( $Str )
174 {
175 try
176 {
177 if( $this->StoreTrace )
178 {
179 $Template = str_replace( '{string}' , $Str , $this->Templates[ 'start_group' ] );
180 $Template = str_replace( '{i}' , count( $this->TraceStrings ) , $Template );
181
182 $this->TraceStrings [] = array( 'name' => 'start_group' , 'content' => $Template );
183 }
184 }
185 catch( Exception $e )
186 {
187 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
188 }
189 }
190
209 function end_group( $Count = 1 )
210 {
211 try
212 {
213 if( $this->StoreTrace )
214 {
215 for( $i = 0 ; $i < $Count ; $i++ )
216 {
217 $this->TraceStrings [] = array(
218 'name' => 'end_group' , 'content' => $this->Templates[ 'end_group' ]
219 );
220 }
221 }
222 }
223 catch( Exception $e )
224 {
225 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
226 }
227 }
228
247 function add_action( $ActionName , $ActionDescription )
248 {
249 try
250 {
251 if( $this->StoreTrace )
252 {
253 $Database = get_package( 'database' );
254 $Database->insert(
255 'umx_action' , "action_name , time , info" ,
256 "'".htmlspecialchars( $ActionName , ENT_QUOTES )."', NOW() ,'".
257 htmlspecialchars( $ActionDescription , ENT_QUOTES )."'"
258 );
259 }
260 }
261 catch( Exception $e )
262 {
263 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
264 }
265 }
266
285 private function remove_empty_leaves()
286 {
287 try
288 {
289 $Counter = 0;
290
291 for( $i = 0 ; $i < count( $this->TraceStrings ) ; )
292 {
293 if( get_field( $this->TraceStrings[ $i ] , 'name' ) == 'start_group' &&
294 get_field( $this->TraceStrings[ $i + 1 ] , 'name' ) == 'end_group' )
295 {
296 $Counter++;
297 array_splice( $this->TraceStrings , $i , 2 );
298 }
299 else
300 {
301 $i++;
302 }
303 }
304
305 return( $Counter );
306 }
307 catch( Exception $e )
308 {
309 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
310 }
311 }
312
327 private function remove_empty_tags()
328 {
329 try
330 {
331 for( ; $this->remove_empty_leaves() ; );
332 }
333 catch( Exception $e )
334 {
335 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
336 }
337 }
338
357 private function compile_trace_items()
358 {
359 try
360 {
361 $this->remove_empty_tags();
362
363 $Output = $this->CachedMultyFS->get_template( __FILE__ , 'trace_start.tpl' );
364 $Output .= implode_ex( '' , $this->TraceStrings , 'content' );
365 $Output .= $this->CachedMultyFS->get_template( __FILE__ , 'trace_end.tpl' );
366 $Output = str_replace(
367 '{output}' , $Output , $this->CachedMultyFS->get_template( __FILE__ , 'trace.tpl' )
368 );
369
370 return( $Output );
371 }
372 catch( Exception $e )
373 {
374 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
375 }
376 }
377
396 function compile_trace()
397 {
398 try
399 {
400 if( $this->StoreTrace )
401 {
402 $Output = $this->compile_trace_items();
403
404 $TraceBlock = $this->CachedMultyFS->get_template( __FILE__ , 'trace_block.tpl' );
405 $TraceBlock = str_replace( '{output}' , $Output , $TraceBlock );
406
407 return( $TraceBlock );
408 }
409 else
410 {
411 return( '{lang:trace_switched_off}' );
412 }
413 }
414 catch( Exception $e )
415 {
416 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
417 }
418 }
419
438 function __toString()
439 {
440 try
441 {
442 return( "" );
443 }
444 catch( Exception $e )
445 {
446 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
447 }
448 }
449 }
450
451 ?>