ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

macro_parser.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 macro_parser_1_0_0{
27
54 function is_params_valid( &$Params , &$RegExValidators )
55 {
56 try
57 {
58 $Valid = true;
59 $Matches = array();
60 /* проверяем валидность параметров если надо */
61 if( count( $RegExValidators ) )
62 {
63 $ParamsList = explode( ';' , $Params );
64 foreach( $ParamsList as $key1 => $p )
65 {
66 $p = explode( '=' , $p );
67 foreach( $RegExValidators as $key2 => $rev )
68 {
69 if( $key2 == $p[ 0 ] )
70 {
71 $Result = preg_match( $rev , $p[ 1 ] , $Matches );
72 $Valid = count( $Matches ) == 0 ? false : $Valid;
73 break;
74 }
75 }
76 }
77 }
78 return( $Valid );
79 }
80 catch( Exception $e )
81 {
82 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
83 }
84 }
85
116 function handle_macro_start( $TmpStartPos , $TmpEndPos , &$StartPos , &$Counter )
117 {
118 try
119 {
120 if( $TmpStartPos !== false && $TmpEndPos !== false )
121 {
122 if( $TmpStartPos < $TmpEndPos )
123 {
124 $StartPos = $TmpEndPos;
125 }
126 if( $TmpEndPos < $TmpStartPos )
127 {
128 $Counter--;
129 if( $Counter )
130 {
131 $Counter++;
132 }
133 $StartPos = $TmpStartPos;
134 }
135 }
136 }
137 catch( Exception $e )
138 {
139 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
140 }
141 }
142
177 function handle_macro_end( $TmpStartPos , $TmpEndPos , &$StartPos , &$Counter , $MacroStartPos )
178 {
179 try
180 {
181 if( $TmpStartPos !== false && $TmpEndPos === false )
182 {
183 $Counter++;
184 $StartPos = $TmpStartPos;
185 }
186
187 if( $TmpStartPos === false && $TmpEndPos !== false )
188 {
189 $Counter--;
190 $StartPos = $TmpEndPos;
191 }
192
193 if( $TmpStartPos === false && $TmpEndPos === false )
194 {
195 /* ничего не найдено, поэтому внешний цикл закончен, да и внутренний тоже
196 $StartPos = strlen( $StringData ); */
197 $StartPos = $MacroStartPos;
198 }
199 }
200 catch( Exception $e )
201 {
202 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
203 }
204 }
205
244 function handle_macro_start_end( &$StringData , &$TmpStartPos , &$TmpEndPos ,
245 &$StartPos , &$Counter , $MacroStartPos )
246 {
247 try
248 {
249 $TmpStartPos = strpos( $StringData , chr( 123 ) , $StartPos + 1 );
250 $TmpEndPos = strpos( $StringData , chr( 125 ) , $StartPos + 1 );
251
252 $this->handle_macro_start( $TmpStartPos , $TmpEndPos , $StartPos , $Counter );
253
254 $this->handle_macro_end(
255 $TmpStartPos , $TmpEndPos , $StartPos , $Counter , $MacroStartPos
256 );
257 }
258 catch( Exception $e )
259 {
260 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
261 }
262 }
263
302 function find_macro( &$StringData , &$TmpStartPos , &$TmpEndPos ,
303 &$StartPos , &$Counter , $MacroStartPos , $ParamStartPos , $RegExValidators )
304 {
305 try
306 {
307 do
308 {
309 $this->handle_macro_start_end(
310 $StringData , $TmpStartPos , $TmpEndPos , $StartPos , $Counter , $MacroStartPos
311 );
312
313 if( $Counter == 0 )
314 {
315 $Params = substr( $StringData , $ParamStartPos , $TmpEndPos - $ParamStartPos );
316 if( $this->is_params_valid( $Params , $RegExValidators ) )
317 {
318 return( $Params );
319 }
320 $TmpStartPos = false;
321 $StartPos = $MacroStartPos;
322 }
323 }
324 while( $TmpStartPos );
325
326 return( false );
327 }
328 catch( Exception $e )
329 {
330 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
331 }
332 }
333 }
334 ?>