1<?php 2 3// must be run within Dokuwiki 4if(!defined('DOKU_INC')) die(); 5 6require_once DOKU_PLUGIN . 'latexport/implementation/decorator.php'; 7require_once DOKU_PLUGIN . 'latexport/helpers/internal_media.php'; 8 9/** 10 * Can make groups of images if internal media are only separated by spaces. 11 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 12 * @author Jean-Michel Gonet <jmgonet@yahoo.com> 13 */ 14class DecoratorImages extends Decorator { 15 16 private $internalMediaGroup; 17 18 private $groupHasInternalMedia; 19 20 /** 21 * Class constructor. 22 * @param decorator The next decorator. 23 */ 24 function __construct($decorator) { 25 parent::__construct($decorator); 26 $this->internalMediaGroup = []; 27 $this->groupHasInternalMedia = FALSE; 28 } 29 30 /** 31 * Receives an internal media 32 * 33 * @param string $src media ID 34 * @param string $title descriptive text 35 * @param string $align left|center|right 36 * @param int $width width of media in pixel 37 * @param int $height height of media in pixel 38 * @param string $cache cache|recache|nocache 39 * @param string $linking linkonly|detail|nolink 40 */ 41 function internalmedia($src, $title = null, $align = null, $width = null, 42 $height = null, $cache = null, $linking = null, $positionInGroup = 0, $totalInGroup = 1) { 43 44 // New media are temporarily stored in the list. 45 $this->internalMediaGroup[] = new InternalMedia($src, $title, $align, $width, $height, $cache, $linking); 46 $this->groupHasInternalMedia = TRUE; 47 } 48 49 /** 50 * Any command different than white text closes the group of media. 51 */ 52 function any_command() { 53 $this->dumpInternalMediaGroup(); 54 } 55 56 /** 57 * Multiple images can be separated by spaces. 58 */ 59 function cdata($text) { 60 // If text contains only spaces, then we accept more 61 // media in the group. 62 if (!ctype_space($text)) { 63 // Otherwise, we dump the group. 64 $this->dumpInternalMediaGroup(); 65 } 66 67 // In any case, propagate the text: 68 $this->decorator->cdata($text); 69 } 70 71 /** 72 * Renders all images in the group. 73 * And empties the group. 74 */ 75 private function dumpInternalMediaGroup() { 76 if ($this->groupHasInternalMedia) { 77 $positionInGroup = 0; 78 $totalInGroup = count($this->internalMediaGroup); 79 foreach($this->internalMediaGroup as $internalMedia) { 80 $this->decorator->internalmedia( 81 $internalMedia->getSrc(), 82 $internalMedia->getTitle(), 83 $internalMedia->getAlign(), 84 $internalMedia->getWidth(), 85 $internalMedia->getHeight(), 86 $internalMedia->getCache(), 87 $internalMedia->getLinking(), 88 $positionInGroup ++, 89 $totalInGroup); 90 } 91 } 92 $this->internalMediaGroup = []; 93 $this->groupHasInternalMedia = FALSE; 94 } 95} 96