backup de julho
[h2N7SspZmY.git] / lib / plugins / tag / syntax / tag.php
blob9b857c66340661005419926cc0558f71eb3ec52e
1 <?php
2 /**
3 * Tag Plugin: displays list of keywords with links to categories this page
4 * belongs to. The links are marked as tags for Technorati and other services
5 * using tagging.
7 * Usage: {{tag>category tags space separated}}
9 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
10 * @author Esther Brunner <wikidesign@gmail.com>
13 // must be run within Dokuwiki
14 if (!defined('DOKU_INC')) die();
16 if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
17 if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
18 if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
19 require_once(DOKU_PLUGIN.'syntax.php');
21 class syntax_plugin_tag_tag extends DokuWiki_Syntax_Plugin {
23 var $tags = array();
25 function getInfo() {
26 return array(
27 'author' => 'Gina Häußge, Michael Klier, Esther Brunner',
28 'email' => 'dokuwiki@chimeric.de',
29 'date' => @file_get_contents(DOKU_PLUGIN.'tag/VERSION'),
30 'name' => 'Tag Plugin (tag component)',
31 'desc' => 'Displays links to categories the page belongs to',
32 'url' => 'http://www.dokuwiki.org/plugin:tag',
36 function getType() { return 'substition'; }
37 function getSort() { return 305; }
38 function getPType() { return 'block';}
40 function connectTo($mode) {
41 $this->Lexer->addSpecialPattern('\{\{tag>.*?\}\}', $mode, 'plugin_tag_tag');
44 function handle($match, $state, $pos, &$handler) {
45 global $ID;
47 $tags = trim(substr($match, 6, -2)); // strip markup & whitespace
48 if (!$tags) return false;
49 if (!$my =& plugin_load('helper', 'tag')) return false;
50 $tags = $my->_parseTagList($tags); // split tags
51 $this->tags = array_merge($this->tags, $tags);
52 $my->_updateTagIndex($ID, $this->tags);
53 return $tags;
56 function render($mode, &$renderer, $data) {
57 if ($data === false) return false;
58 if (!$my =& plugin_load('helper', 'tag')) return false;
59 $tags = $my->tagLinks($data);
60 if (!$tags) return true;
62 // XHTML output
63 if ($mode == 'xhtml') {
64 $renderer->doc .= '<div class="tags"><span>'.DOKU_LF.
65 DOKU_TAB.$tags.DOKU_LF.
66 '</span></div>'.DOKU_LF;
67 return true;
69 // for metadata renderer
70 } elseif ($mode == 'metadata') {
71 if ($renderer->capture) $renderer->doc .= DOKU_LF.strip_tags($tags).DOKU_LF;
72 foreach ($my->references as $ref => $exists) {
73 $renderer->meta['relation']['references'][$ref] = $exists;
75 if (!is_array($renderer->meta['subject'])) $renderer->meta['subject'] = array();
76 $renderer->meta['subject'] = array_merge($renderer->meta['subject'], $data);
77 return true;
79 return false;
82 // vim:ts=4:sw=4:et:enc=utf-8: