1<?php
2/**
3 * DokuWiki Plugin vamr (Syntax Component)
4 * version 1.3 (2018-08-29)
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michal Rubeš <michal@termiter.cz>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15
16require_once DOKU_PLUGIN.'syntax.php';
17
18class syntax_plugin_vamr extends DokuWiki_Syntax_Plugin {
19    function getType() {
20        return 'container';
21    }
22
23    function getPType() {
24        return 'normal';
25    }
26
27    function getSort() {
28        return 190;
29    }
30
31
32    function connectTo($mode) {
33        $this->Lexer->addSpecialPattern('{vamr.*?}',$mode,'plugin_vamr');
34    }
35
36    function handle($match, $state, $pos, &$handler){
37    		$handle = trim(substr($match,5,-1));
38				$param = explode(' ', $handle);
39				if (!is_numeric($param[0])) $param[0] = 0;
40				if (!isset($param[1])) $param[1] = '';
41				if (!isset($param[2])) $param[2] = '';
42
43				$data[0] = $param[0];
44
45        if ($data[0] == 'x') {
46        $num = 5500; //number of photos
47        $r = rand(1, $num);
48        if (!$fp = curl_init('https://www.darwiniana.cz/vamr/?page=obrazek&amp;id='.$r)) $r = 1;
49        $data[0] = $r;
50        }
51
52				$data[1] = 2;
53				if ($param[1] == 'small' or $param[2] == 'small') $data[1] = 1;
54//				if ($param[1] == 'normal' or $param[2] == 'normal') $data[1] = 2;
55				if ($param[1] == 'big' or $param[2] == 'big') $data[1] = 3;
56				$data[2] = '';
57				if ($param[1] == 'left' or $param[2] == 'left') $data[2] = ' class="medialeft"';
58				if ($param[1] == 'right' or $param[2] == 'right') $data[2] = ' class="mediaright"';
59				if ($param[1] == 'center' or $param[2] == 'center') $data[2] = ' class="mediacenter"';
60
61				$data[3] = 'VAMR - Velký Atlas Masožravých Rostlin';
62        return $data;
63    }
64
65    function render($mode, &$renderer, $data) {
66        if($mode != 'xhtml' or $data[0]==0) return false;
67$renderer->doc .= '<a href="https://www.darwiniana.cz/vamr/?page=obrazek&amp;id='.$data[0].'"><img src="https://www.darwiniana.cz/vamr/galerie/'.str_pad($data[0], 5, '0', STR_PAD_LEFT).'-t'.$data[1].'.jpg" alt="'.$data[3].'"'.$data[2].'/></a>';
68        return true;
69    }
70}
71
72// vim:ts=4:sw=4:et:enc=utf-8:
73