リビジョン | 246 (tree) |
---|---|
日時 | 2010-08-16 10:50:23 |
作者 | kmorimatsu |
<%using%> tag implementation.
@@ -35,7 +35,9 @@ | ||
35 | 35 | self::echo_html('<!--\'"-->'.$text,$data); |
36 | 36 | $db=debug_backtrace(); |
37 | 37 | self::echo_html('<!--'); |
38 | + ob_start(); | |
38 | 39 | print_r($db); |
40 | + self::p(ob_get_clean()); | |
39 | 41 | self::echo_html('-->'); |
40 | 42 | for ($i=0;$i<count($db);$i++) { |
41 | 43 | if ($db[$i]['class']=='error') continue; |
@@ -571,7 +571,7 @@ | ||
571 | 571 | static public function log($desc,$by,$type='general'){ |
572 | 572 | $row=array( |
573 | 573 | 'ip'=>$_SERVER['REMOTE_ADDR'], |
574 | - 'referer'=>$_SERVER['HTTP_REFERER'], | |
574 | + 'referer'=>@$_SERVER['HTTP_REFERER'], | |
575 | 575 | 'mid'=>(int)member::setting('id'), |
576 | 576 | 'time'=>_NOW, |
577 | 577 | 'uri'=>$_SERVER['REQUEST_URI'], |
@@ -136,6 +136,7 @@ | ||
136 | 136 | $replace=array('self','compile_cb'); |
137 | 137 | } |
138 | 138 | // Actually, JIT compiler is just a preg_replace_callback. |
139 | + self::$compile_using=array(); | |
139 | 140 | $compiled=preg_replace_callback($search,$replace,$source); |
140 | 141 | if (!$lambda) return $compiled; |
141 | 142 | // Create lambda |
@@ -143,6 +144,7 @@ | ||
143 | 144 | if (!is_callable($code)) return error::compile_error($source,$compiled); |
144 | 145 | return $code; |
145 | 146 | } |
147 | + static private $compile_using; | |
146 | 148 | static private function compile_cb($matches){ |
147 | 149 | // Simple replacements |
148 | 150 | if (count($matches)<=2) { |
@@ -165,10 +167,11 @@ | ||
165 | 167 | // First argument for skin-var is always $data. |
166 | 168 | array_unshift($args,'$data'); |
167 | 169 | $args=implode(',',$args); |
168 | - if (preg_match('/^(if|ifnot|elseif|elseifnot)\.([a-zA-Z0-9\.]+)$/',$matches[2],$if)) { | |
170 | + if (preg_match('/^(if|ifnot|elseif|elseifnot)(\.[a-zA-Z0-9\.]+)?$/',$matches[2],$if)) { | |
169 | 171 | // If-skinvars. |
170 | - $method=self::compile_cb_method($if[2],'if_'); | |
171 | - if ($method===false) error::quit('If-var not found: <%0%>',$if[2]); | |
172 | + $iftag=isset($if[2]) ? substr($if[2],1):''; | |
173 | + $method=self::compile_cb_method($iftag,'if_'); | |
174 | + if ($method===false) error::quit('If-var not found: <%0%>',$iftag); | |
172 | 175 | switch($if[1]){ |
173 | 176 | case 'ifnot': |
174 | 177 | return "<?php $cr if (!( $method($args) )) { ?>"; |
@@ -183,6 +186,11 @@ | ||
183 | 186 | } else switch($matches[2]){ |
184 | 187 | // The other skinvars. |
185 | 188 | // Note that the position of $cr is important. This makes the template (if/select) description simple. |
189 | + case 'using': | |
190 | + foreach(explode(',',$matches[3]) as $namespace){ | |
191 | + self::$compile_using[]=$namespace; | |
192 | + } | |
193 | + return $cr; | |
186 | 194 | case 'return': |
187 | 195 | return "$cr<?php return true; ?>"; |
188 | 196 | case 'exit': |
@@ -226,7 +234,14 @@ | ||
226 | 234 | } |
227 | 235 | |
228 | 236 | } |
229 | - static private function compile_cb_method($text,$prefix='tag_'){ | |
237 | + static private function compile_cb_method($text,$prefix='tag_',$using=true){ | |
238 | + if (count(self::$compile_using) && $using) { | |
239 | + foreach(self::$compile_using as $namespace){ | |
240 | + $tag=$text=='' ? $namespace:$namespace.'.'.$text; | |
241 | + $method=self::compile_cb_method($tag,$prefix,false); | |
242 | + if ($method) return $method; | |
243 | + } | |
244 | + } | |
230 | 245 | if (preg_match('/^jp\.([a-z0-9]+)$/i',$text,$m)) { |
231 | 246 | $class='jp_'.$m[1]; |
232 | 247 | $method=$prefix.$m[1]; |