xref: /plugin/mikioplugin/syntax/placeholder.php (revision 1f71841cb8963211feaf5c6c8b5acf91a88f1d10)
1<?php
2/**
3 * Mikio Syntax Plugin: Placeholder
4 *
5 * Syntax:  <PLACEHOLDER [colour=] [text=] [text-colour=] [width=] [height=] [classes=]></PLACEHOLDER>
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     James Collins <james.collins@outlook.com.au>
9 */
10
11if (!defined('DOKU_INC')) die();
12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(dirname(__FILE__).'/core.php');
14
15class syntax_plugin_mikioplugin_placeholder extends syntax_plugin_mikioplugin_core {
16    public $tag                 = 'placeholder';
17    public $noEndTag            = true;
18    public $options             = array('width', 'height', 'text', 'colour', 'text-colour', 'classes');
19
20
21    public function render_lexer_special(Doku_Renderer $renderer, $data) {
22        $colour = '#868e96';
23        $textcolour = '#dee2e6';
24        $classes = '';
25
26        if(array_key_exists('colour', $data) && $data['colour'] != '') {
27            $colour = $data['colour'];
28        }
29
30        if(array_key_exists('text-colour', $data) && $data['text-colour'] != '') {
31            $colour = $data['text-colour'];
32        }
33
34        if(array_key_exists('classes', $data) && $data['classes'] != '') {
35            $classes = 'classes="' . $data['classes'] . '" ';
36        }
37
38        $renderer->doc .= '<svg ' . $classes . (array_key_exists('width', $data) && $data['width'] != '' ? ' width="' . $data['width'] . '" ' : '') . (array_key_exists('height', $data) && $data['height'] != '' ? ' height="' . $data['height'] . '" ' : '') . ' xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img">';
39        $renderer->doc .= '<rect width="100%" height="100%" fill="' . $colour . '"></rect>';
40
41        if(array_key_exists('text', $data) && $data['text'] != '') $renderer->doc .= '<text x="50%" y="50%" fill="' .$textcolour . '" dominant-baseline="middle" text-anchor="middle">' . $data['text'] . '</text>';
42
43        $renderer->doc .= '</svg>';
44    }
45}
46?>