1<?php 2 3/** 4 * Mikio Syntax Plugin: Carousel 5 * 6 * @link http://github.com/nomadjimbob/mikioplugin 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author James Collins <james.collins@outlook.com.au> 9 */ 10if (!defined('DOKU_INC')) die(); 11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 12require_once(dirname(__FILE__) . '/core.php'); 13 14class syntax_plugin_mikioplugin_carousel extends syntax_plugin_mikioplugin_core 15{ 16 public $tag = 'carousel'; 17 public $hasEndTag = true; 18 public $options = array( 19 'transition' => array( 20 'type' => 'choice', 21 'data' => array('slide', 'fade'), 22 'default' => '' 23 ), 24 'indicators' => array( 25 'type' => 'choice', 26 'data' => array('true', 'false', 'circle'), 27 'default' => 'true' 28 ), 29 'controls' => array('type' => 'boolean', 'default' => 'true'), 30 'start' => array('type' => 'boolean', 'default' => 'false'), 31 'cover' => array('type' => 'boolean', 'default' => 'false'), 32 'control-color' => array('type' => 'color', 'default' => '#fff'), 33 'control-outline-color' => array('type' => 'color', 'default' => ''), 34 'control-outline-width' => array('type' => 'multisize', 'default' => ''), 35 'dynamic' => array('type' => 'text', 'default' => ''), 36 'dynamic-prefix' => array('type' => 'text', 'default' => ''), 37 ); 38 39 public function __construct() 40 { 41 $this->addCommonOptions('height'); 42 } 43 44 45 public function render_lexer_enter(Doku_Renderer $renderer, $data) 46 { 47 $classes = $this->buildClass($data, array('transition')); 48 $styles = $this->buildStyle(array('height' => $data['height']), TRUE); 49 50 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel' . ($data['cover'] ? ' ' . $this->classPrefix . 'image-cover' : '') . $classes . '" data-auto-start="' . ($data['start'] ? 'true' : 'false') . '"' . $styles . '>'; 51 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel-inner">'; 52 53 if (strlen($data['dynamic']) > 0) { 54 global $conf; 55 56 $namespace = $data['dynamic']; 57 if (substr($namespace, -1) == ':') { 58 $namespace = substr($namespace, 0, -1); 59 } 60 61 $path = str_replace(':', '/', $namespace); 62 63 $pages = array(); 64 search($pages, $conf['datadir'] . '/' . $path, 'search_allpages', array('depth' => 1, 'skipacl' => true)); 65 foreach ($pages as $page) { 66 $item_data = array(); 67 68 $page_id = $namespace . ':' . $page['id']; 69 preg_match('/{{([^>|}]+(\.jpg|\.gif|\.png))\|?.*}}/', rawWiki($page_id), $image_matches); 70 if (count($image_matches) > 1) { 71 $item_data['image'] = $image_matches[1]; 72 } 73 74 $item_data['title'] = (strlen($data['dynamic-prefix']) > 0 ? $data['dynamic-prefix'] . ' ' : '') . p_get_first_heading($page_id); 75 $item_data['url'] = $page_id; 76 77 $this->syntaxRender($renderer, 'carouselitem', '', $item_data, MIKIO_LEXER_SPECIAL); 78 } 79 } 80 } 81 82 83 public function render_lexer_exit(Doku_Renderer $renderer, $data) 84 { 85 $renderer->doc .= '</div>'; 86 87 if ($data['controls'] === TRUE) { 88 $svg_styles = $this->buildStyle(array('fill' => $data['control-color'], 'stroke' => $data['control-outline-color'], 'stroke-width' => $data['control-outline-width']), TRUE); 89 90 $renderer->doc .= '<a href="#" class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel-control ' . $this->classPrefix . 'carousel-control-prev" role="button"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 8 8"' . $svg_styles . '><path d="M5.25 0l-4 4 4 4 1.5-1.5L4.25 4l2.5-2.5L5.25 0z"/></svg></a>'; 91 $renderer->doc .= '<a href="#" class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel-control ' . $this->classPrefix . 'carousel-control-next" role="button"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 8 8"' . $svg_styles . '><path d="M2.75 0l-1.5 1.5L3.75 4l-2.5 2.5L2.75 8l4-4-4-4z"/></svg></a>'; 92 } 93 94 if (strcasecmp($data['indicators'], 'false') != 0) { 95 $renderer->doc .= '<ul class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel-indicators' . (strcasecmp($data['indicators'], 'circle') == 0 ? ' ' . $this->classPrefix . 'carousel-indicators-circle' : '') . '"></ul>'; 96 } 97 98 $renderer->doc .= '</div>'; 99 } 100} 101