[755] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * Outputs a html <a> tag |
---|
| 5 | * <pre> |
---|
| 6 | * * href : the target URI where the link must point |
---|
| 7 | * * rest : any other attributes you want to add to the tag can be added as named parameters |
---|
| 8 | * </pre> |
---|
| 9 | * |
---|
| 10 | * Example : |
---|
| 11 | * |
---|
| 12 | * <code> |
---|
| 13 | * {* Create a simple link out of an url variable and add a special class attribute: *} |
---|
| 14 | * |
---|
| 15 | * {a $url class="external" /} |
---|
| 16 | * |
---|
| 17 | * {* Mark a link as active depending on some other variable : *} |
---|
| 18 | * |
---|
| 19 | * {a $link.url class=tif($link.active "active"); $link.title /} |
---|
| 20 | * |
---|
| 21 | * {* This is similar to: <a href="{$link.url}" class="{if $link.active}active{/if}">{$link.title}</a> *} |
---|
| 22 | * </code> |
---|
| 23 | * |
---|
| 24 | * This software is provided 'as-is', without any express or implied warranty. |
---|
| 25 | * In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 26 | * |
---|
| 27 | * @author Jordi Boggiano <j.boggiano@seld.be> |
---|
| 28 | * @copyright Copyright (c) 2008, Jordi Boggiano |
---|
| 29 | * @license http://dwoo.org/LICENSE Modified BSD License |
---|
| 30 | * @link http://dwoo.org/ |
---|
| 31 | * @version 1.0.0 |
---|
| 32 | * @date 2008-10-23 |
---|
| 33 | * @package Dwoo |
---|
| 34 | */ |
---|
| 35 | class Dwoo_Plugin_a extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block |
---|
| 36 | { |
---|
| 37 | public function init($href, array $rest=array()) |
---|
| 38 | { |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
---|
| 42 | { |
---|
| 43 | $p = $compiler->getCompiledParams($params); |
---|
| 44 | |
---|
| 45 | $out = Dwoo_Compiler::PHP_OPEN . 'echo \'<a '.self::paramsToAttributes($p); |
---|
| 46 | |
---|
| 47 | return $out.'>\';' . Dwoo_Compiler::PHP_CLOSE; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
---|
| 51 | { |
---|
| 52 | $p = $compiler->getCompiledParams($params); |
---|
| 53 | |
---|
| 54 | // no content was provided so use the url as display text |
---|
| 55 | if ($content == "") { |
---|
| 56 | // merge </a> into the href if href is a string |
---|
| 57 | if (substr($p['href'], -1) === '"' || substr($p['href'], -1) === '\'') { |
---|
| 58 | return Dwoo_Compiler::PHP_OPEN . 'echo '.substr($p['href'], 0, -1).'</a>'.substr($p['href'], -1).';'.Dwoo_Compiler::PHP_CLOSE; |
---|
| 59 | } |
---|
| 60 | // otherwise append |
---|
| 61 | return Dwoo_Compiler::PHP_OPEN . 'echo '.$p['href'].'.\'</a>\';'.Dwoo_Compiler::PHP_CLOSE; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | // return content |
---|
| 65 | return $content . '</a>'; |
---|
| 66 | } |
---|
| 67 | } |
---|