1<?php
2/**
3 * Mailto plugin, mail the current page to several people
4 *
5 * @author     Cédric Villemain <cedric.villemain@dalibo.com>
6 */
7// must be run within Dokuwiki
8if(!defined('DOKU_INC')) die();
9
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'syntax.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_mailto extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * return some info
21     */
22    function getInfo(){
23        return confToHash(dirname(__FILE__).'/info.txt');
24    }
25
26    /**
27     * What kind of syntax are we?
28     */
29    function getType(){
30        return 'substition';
31    }
32
33    /**
34     * Where to sort in?
35     */
36    function getSort(){
37        return 155; /// Just before mantis actually TODO do we care of that, really ?
38    }
39
40    function connectTo($mode) {
41        $this->Lexer->addSpecialPattern('~~MAILTO:.*~~',$mode,'plugin_mailto');
42    }
43
44    function handle($match, $state, $pos, &$handler){
45        $match = substr( $match, 9, -2 ); // strip "~~MAILTO:" from start and "~~" from end
46        return explode( ',', $match );
47	}
48    /**
49     * Create output
50     */
51    function render($mode, &$renderer, $data) {
52        // store info in metadata
53        if($mode == 'metadata'){
54            $renderer->meta['plugin']['mailto']['to'] = $data[0];
55            $renderer->meta['plugin']['mailto']['cc'] = implode(',', array_slice($data,1));
56			return true;
57        }
58		elseif ($mode != 'metadata') {
59			$renderer->doc .= $this->getLang('mailto_attention_to')
60							  . implode (', ',$data);
61			global $ID;
62			$metas=p_get_metadata($ID);
63			if ($metas['plugin']['mailto']['sent'])
64			  $renderer->doc .= $this->getLang('mailto_attention_sent')
65							    . strftime($this->getConf('mailto_dformat'), $metas['plugin']['mailto']['sent']) . ' ) ';
66			return true;
67		}
68        return false;
69    }
70}
71
72