1<?php
2/**
3 * piclens : create a piclens link with feedurl
4 * Syntax  : [[piclens>url|texte]] (comme un lien normal...)
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Etienne Mauvais <emauvaisfr@yahoo.fr>
8 */
9
10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13
14/**
15 * All DokuWiki plugins to extend the parser/rendering mechanism
16 * need to inherit from this class
17 */
18class syntax_plugin_piclens extends DokuWiki_Syntax_Plugin {
19
20    /**
21     * return some info
22     */
23    function getInfo(){
24        return array(
25          'author' => 'Etienne M.',
26          'email'  => 'emauvaisfr@yahoo.fr',
27          'date'   => '2008-10-07',
28          'name'   => 'piclens Plugin',
29          'desc'   => html_entity_decode($this->getLang('pic_description')),
30          'url'    => 'http://www.dokuwiki.org/plugin:piclens',
31        );
32    }
33
34    /**
35     * What kind of syntax are we?
36     */
37    function getType(){
38        return 'disabled';
39    }
40
41    /**
42     * What kind of syntax do we allow (optional)
43     */
44    function getAllowedTypes() {
45        return array('disabled');
46    }
47
48    /**
49     * What about paragraphs? (optional)
50     */
51   function getPType(){
52       return 'normal';
53   }
54
55    /**
56     * Where to sort in?
57     */
58    function getSort(){
59        return 30;
60    }
61
62
63    /**
64     * Connect pattern to lexer
65     */
66    function connectTo($mode) {
67        //$this->Lexer->addEntryPattern('\x3Cpiclens (?=.*/\x3E)',$mode,'plugin_piclens');
68        $this->Lexer->addEntryPattern('\x5B\x5Bpiclens>(?=.*\x5D\x5D)',$mode,'plugin_piclens');
69    }
70
71    function postConnect() {
72        $this->Lexer->addExitPattern('\x5D\x5D', 'plugin_piclens');
73    }
74
75
76    /**
77     * Handle the match
78     */
79    function handle($match, $state, $pos, &$handler){
80        switch ($state) {
81          case DOKU_LEXER_ENTER :
82            break;
83          case DOKU_LEXER_MATCHED :
84            break;
85          case DOKU_LEXER_UNMATCHED :
86            break;
87          case DOKU_LEXER_EXIT :
88            break;
89          case DOKU_LEXER_SPECIAL :
90            break;
91        }
92        return array($match, $state);
93    }
94
95    /**
96     * Create output
97     */
98    function render($mode, &$renderer, $data) {
99        if($mode == 'xhtml'){
100            if ($data[1] == DOKU_LEXER_ENTER){
101                //Inclusion des scripts piclens
102                $renderer->doc .= '<script type="text/javascript" src="http://lite.piclens.com/current/piclens.js"></script>';
103            } else if ($data[1] == DOKU_LEXER_UNMATCHED){
104                //Cr�ation du lien
105                //R�cup�ration du feedUrl et du texte
106                $val=split("\|", $data[0]);
107                if ($val[0]) {
108                  if ($val[1]=="") $val[1]=$val[0];
109                  $val[1]=preg_replace("/ *?$/","",$val[1]);
110                  $renderer->doc .= '<a href="javascript:PicLensLite.start({feedUrl:\''.$val[0].'\'});" title="'.$this->getLang('pic_via').'" class="piclens">'.$val[1].'</a>';
111                }
112            } else if ($data[1] == DOKU_LEXER_EXIT){
113                //Si le client piclens n'est pas install�, on ajoute un lien qui renvoie vers la page de tlchargement
114                $renderer->doc .= '<script>if (!PicLensLite.hasClient()) document.writeln(\' (<a href="http://www.cooliris.com/site/support/download-all-products.php" target="_new" title="'.$this->getLang('pic_telecharger').'">?</a>)\');</script>';
115            }
116            return true;
117        }
118        return false;
119    }
120}
121