1<?php
2/**
3 * Colorbox Syntax Plugin
4 *
5 *  Provides the jquery colorbox plugin
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     Tom Cafferty <tcafferty@glocalfocal.com>
9 */
10if(!defined('DOKU_INC')) define('DOKU_INC',(dirname(__FILE__).'/../../').'/');
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_colorbox extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * What kind of syntax are we?
21     */
22    function getType(){
23        return 'substition';
24    }
25
26    function getPType(){
27        return 'block';
28    }
29
30    /**
31     * Where to sort in?
32     */
33    function getSort(){
34        return 160;
35    }
36
37    /**
38     * Connect pattern to lexer
39     */
40    function connectTo($mode) {
41      $this->Lexer->addSpecialPattern('<colorbox>.*?</colorbox>',$mode,'plugin_colorbox');
42    }
43
44    /**
45     * Handle the match
46     */
47    function handle($match, $state, $pos, &$handler){
48        parse_str($match, $return);
49        return $return;
50    }
51
52/**
53 *
54 * Create colorbox link output
55 *
56 * @author   Tom Cafferty <tcafferty@glocalfocal.com>
57 *
58 */
59    function render($mode, &$R, $data) {
60      global $conf;
61
62      // store meta info for this page
63      if($mode == 'metadata'){
64        $R->meta['plugin']['colorbox'] = true;
65        return true;
66      }
67
68      if($mode != 'xhtml') return false;
69
70      // Initialize settings from user input or conf file
71      if (isset($data['class']))
72        $class = $data['class'];
73      else
74        $class = $this->getConf('class');
75
76      if (isset($data['link']))
77        $link = $data['link'];
78
79      if (isset($data['name']))
80        $name = $data['name'];
81
82      // Set the colorbox link
83	  $R->doc .='<a class="'.$class.'" href="'.$link.'">'.$name.'</a>';
84
85	  return true;
86    }
87}