|
15 | 15 | if(!defined('DOKU_INC')) die(); |
16 | 16 |
|
17 | 17 | if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); |
18 | | -require_once(DOKU_PLUGIN.'syntax.php'); |
19 | 18 |
|
20 | 19 | class syntax_plugin_avatar extends DokuWiki_Syntax_Plugin { |
21 | 20 |
|
22 | | - function getType() { return 'substition'; } |
23 | | - function getSort() { return 315; } |
24 | | - |
25 | | - function connectTo($mode) { |
26 | | - $this->Lexer->addSpecialPattern("{{(?:gr|)avatar>.+?}}",$mode,'plugin_avatar'); |
27 | | - } |
28 | | - |
29 | | - function handle($match, $state, $pos, Doku_Handler $handler) { |
30 | | - list($syntax, $match) = explode('>', substr($match, 0, -2), 2); // strip markup |
31 | | - list($user, $title) = explode('|', $match, 2); // split title from mail / username |
32 | | - |
33 | | - // Check alignment |
34 | | - $ralign = (bool)preg_match('/^ /', $user); |
35 | | - $lalign = (bool)preg_match('/ $/', $user); |
36 | | - if ($lalign & $ralign) $align = 'center'; |
37 | | - else if ($ralign) $align = 'right'; |
38 | | - else if ($lalign) $align = 'left'; |
39 | | - else $align = NULL; |
40 | | - |
41 | | - //split into src and size parameter (using the very last questionmark) |
42 | | - list($user, $param) = explode('?', trim($user), 2); |
43 | | - if (preg_match('/^s/', $param)) $size = 20; |
44 | | - else if (preg_match('/^m/', $param)) $size = 40; |
45 | | - else if (preg_match('/^l/', $param)) $size = 80; |
46 | | - else if (preg_match('/^xl/', $param)) $size = 120; |
47 | | - else $size = NULL; |
48 | | - |
49 | | - return array($user, $title, $align, $size); |
50 | | - } |
51 | | - |
52 | | - function render($mode, Doku_Renderer $renderer, $data) { |
53 | | - if ($mode == 'xhtml') { |
54 | | - if ($my =& plugin_load('helper', 'avatar')) |
55 | | - $renderer->doc .= '<span class="vcard">'. |
56 | | - $my->getXHTML($data[0], $data[1], $data[2], $data[3]). |
57 | | - '</span>'; |
58 | | - return true; |
| 21 | + function getType() { return 'substition'; } |
| 22 | + function getSort() { return 315; } |
| 23 | + |
| 24 | + function connectTo($mode) { |
| 25 | + $this->Lexer->addSpecialPattern("{{(?:gr|)avatar>.+?}}",$mode,'plugin_avatar'); |
| 26 | + } |
| 27 | + |
| 28 | + function handle($match, $state, $pos, Doku_Handler $handler) { |
| 29 | + list($syntax, $match) = explode('>', substr($match, 0, -2), 2); // strip markup |
| 30 | + $one = explode('?', $match, 2); // [user|mail] ? [size]|[title] |
| 31 | + $two = explode('|', $one[0], 2); // [user] & [mail] |
| 32 | + $three = explode('|', $one[1], 2); // [size] & [title] |
| 33 | + $user = $two[0]; |
| 34 | + $title = $three[1]; |
| 35 | + $param = $three[0]; |
| 36 | + |
| 37 | + // Check alignment |
| 38 | + $ralign = (bool)preg_match('/^ /', $user); |
| 39 | + $lalign = (bool)preg_match('/ $/', $user); |
| 40 | + if ($lalign & $ralign) $align = 'center'; |
| 41 | + else if ($ralign) $align = 'right'; |
| 42 | + else if ($lalign) $align = 'left'; |
| 43 | + else $align = NULL; |
| 44 | + |
| 45 | + if (preg_match('/^s/', $param)) $size = 20; |
| 46 | + else if (preg_match('/^m/', $param)) $size = 40; |
| 47 | + else if (preg_match('/^l/', $param)) $size = 80; |
| 48 | + else if (preg_match('/^xl/', $param)) $size = 120; |
| 49 | + else $size = NULL; |
| 50 | + |
| 51 | + return array($user, $title, $align, $size); |
| 52 | + } |
| 53 | + |
| 54 | + function render($mode, Doku_Renderer $renderer, $data) { |
| 55 | + if ($mode == 'xhtml') { |
| 56 | + if ($my =& plugin_load('helper', 'avatar')) |
| 57 | + $renderer->doc .= '<span class="vcard">'. |
| 58 | + $my->getXHTML($data[0], $data[1], $data[2], $data[3]). |
| 59 | + '</span>'; |
| 60 | + return true; |
| 61 | + } |
| 62 | + return false; |
59 | 63 | } |
60 | | - return false; |
61 | | - } |
62 | 64 | } |
63 | 65 | // vim:ts=4:sw=4:et:enc=utf-8: |
0 commit comments