1<?php
2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4require_once(DOKU_PLUGIN.'syntax.php');
5
6class syntax_plugin_distribute_syntax extends DokuWiki_Syntax_Plugin {
7    var $options = array();
8    function getInfo(){
9        return array(
10            'author' => 'Ahmet Sacan',
11            'email'  => 'ahmet@ceng.metu.edu.tr',
12            'date'   => '2007-02-07',
13            'name'   => 'Distribute plugin',
14            'desc'   => 'helps distribute your plugins',
15            'url'    => 'http://www.ceng.metu.edu.tr/~ahmet',
16        );
17    }
18
19    function getType(){ return 'substition'; }
20    function getSort(){ return 158; }
21
22    function connectTo($mode) {
23	$this->Lexer->addSpecialPattern('\x5cdistribute\x7b[^\x7d]*\x7d',$mode,'plugin_distribute_syntax');
24    }
25    function handle($match, $state, $pos, &$handler){
26	$ret = (object) array('match'=>$match);
27	switch ($state) {
28         case DOKU_LEXER_SPECIAL:
29	 if(preg_match('/^\x5cdistribute\x7b([^\x7d]+)\x7d$/', $match, $ms)){
30	    $ret->command = 'distribute';
31            $ret->arg = $ms[1];
32	 }
33	}
34        return array($state,$ret);
35    }
36    ///////////////////////////////////////////////////////////////
37    function render($mode, &$renderer, $data) {
38        global $ID;
39	require_once dirname(__FILE__).'/../helper.funcs.util.php';
40        if($mode == 'xhtml'){
41            list($state, $match) = $data;
42	    $this->options['match'] .= $match->match;
43            switch ($state) {
44	      case DOKU_LEXER_SPECIAL:
45	          if(!in_array($match->arg, explode(',',$this->getConf('plugins'))))
46		    $renderer->doc .= "[[distribution of $match->arg plugin not allowed in configuration]]";
47		else{
48		    $lastupdate = my_filemtime(DOKU_PLUGIN.$match->arg, true);
49		    $renderer->doc .= "<a href='$_SERVER[PHP_SELF]?do=distribute&plugin=$match->arg&id=$ID' class='media mediafile mf_zip'>$match->arg".'_'.date('Ymd',$lastupdate).".zip</a>";
50		}
51            }
52            return true;
53        }//xhtml
54        return false;
55    }//render()
56}
57