- Added missing copyright to meneame
[haanga.git] / lib / Haanga / Extension / Tag.php
blob4b344fb7b7ae2dd305870085829184ad05fd485d
1 <?php
2 /*
3 +---------------------------------------------------------------------------------+
4 | Copyright (c) 2010 César Rodas and Menéame Comunicacions S.L. |
5 +---------------------------------------------------------------------------------+
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: |
8 | 1. Redistributions of source code must retain the above copyright |
9 | notice, this list of conditions and the following disclaimer. |
10 | |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | 3. All advertising materials mentioning features or use of this software |
16 | must display the following acknowledgement: |
17 | This product includes software developed by César D. Rodas. |
18 | |
19 | 4. Neither the name of the César D. Rodas nor the |
20 | names of its contributors may be used to endorse or promote products |
21 | derived from this software without specific prior written permission. |
22 | |
23 | THIS SOFTWARE IS PROVIDED BY CÉSAR D. RODAS ''AS IS'' AND ANY |
24 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
26 | DISCLAIMED. IN NO EVENT SHALL CÉSAR D. RODAS BE LIABLE FOR ANY |
27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE |
33 +---------------------------------------------------------------------------------+
34 | Authors: César Rodas <crodas@php.net> |
35 +---------------------------------------------------------------------------------+
39 class Haanga_Extension_Tag extends Haanga_Extension
41 /**
42 * isValid
44 * Check if the current $tag (string) is registered as a custom
45 * tag, if so, it check wether it is just a custom tag or a custom block.
47 * This method is called from the lexer for each alpha (within {% %}),
48 * to avoid parsing conflicts.
50 * @param string $tag Tag to check
52 * @return int|bool HG_Parser::T_CUSTOM_TAG, HG_Parser::T_CUSTOM_TAG or FALSE
54 final function isValid($tag)
56 static $cache = array();
57 $tag = strtolower($tag);
59 if (!isset($cache[$tag])) {
60 $class_name = $this->getClassName($tag);
61 if (class_exists($class_name)) {
62 $properties = get_class_vars($class_name);
63 $is_block = FALSE;
64 if (isset($properties['is_block'])) {
65 $is_block = (bool)$properties['is_block'];
67 $cache[$tag] = $is_block ? HG_Parser::T_CUSTOM_BLOCK : HG_Parser::T_CUSTOM_TAG;
69 if (!isset($cache[$tag])) {
70 $cache[$tag] = FALSE;
74 return $cache[$tag];
77 final function getClassName($tag)
79 $tag = str_replace("_", "", ucfirst($tag));
80 return "Haanga_Extension_Tag_{$tag}";
87 * Local variables:
88 * tab-width: 4
89 * c-basic-offset: 4
90 * End:
91 * vim600: sw=4 ts=4 fdm=marker
92 * vim<600: sw=4 ts=4