xref: /plugin/wrap/helper.php (revision fa67e7a80de989acd188fa6e714eba9b92d74a2b) !
1778ee21cSAnika Henke<?php
2778ee21cSAnika Henke/**
3778ee21cSAnika Henke * Helper Component for the Wrap Plugin
4778ee21cSAnika Henke *
5778ee21cSAnika Henke * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6778ee21cSAnika Henke * @author     Anika Henke <anika@selfthinker.org>
7778ee21cSAnika Henke */
8778ee21cSAnika Henke
9778ee21cSAnika Henkeclass helper_plugin_wrap extends DokuWiki_Plugin {
1029523ac3SLarsDW223    static protected $boxes = array ('wrap_box', 'wrap_danger', 'wrap_warning', 'wrap_caution', 'wrap_notice', 'wrap_safety',
1129523ac3SLarsDW223                                     'wrap_info', 'wrap_important', 'wrap_alert', 'wrap_tip', 'wrap_help', 'wrap_todo',
1229523ac3SLarsDW223                                     'wrap_download', 'wrap_hi', 'wrap_spoiler');
1329523ac3SLarsDW223    static protected $paragraphs = array ('wrap_leftalign', 'wrap_rightalign', 'wrap_centeralign', 'wrap_justify');
1463cb595fSSascha Leib
1563cb595fSSascha Leib	/* list of languages which normally use RTL scripts */
1663cb595fSSascha Leib	static protected $rtllangs = array('ar','dv','fa','ha','he','ks','ku','ps','ur','yi','arc');
1763cb595fSSascha Leib	/* list of right-to-left scripts (may override the language defaults to rtl) */
1863cb595fSSascha Leib	static protected $rtlscripts = array('arab','thaa','hebr','deva','shrd');
1963cb595fSSascha Leib	/* selection of left-to-right scripts (may override the language defaults to ltr) */
2063cb595fSSascha Leib	static protected $ltrscripts = array('latn','cyrl','grek','hebr','cyrs','armn');
2163cb595fSSascha Leib
221fdcb5a2SLarsDW223    static $box_left_pos = 0;
231fdcb5a2SLarsDW223    static $box_right_pos = 0;
241fdcb5a2SLarsDW223    static $box_first = true;
251fdcb5a2SLarsDW223    static $table_entr = 0;
26778ee21cSAnika Henke
2720cc304cSGerrit Uitslag    protected $column_count = 0;
2820cc304cSGerrit Uitslag
29778ee21cSAnika Henke    /**
30778ee21cSAnika Henke     * get attributes (pull apart the string between '<wrap' and '>')
31778ee21cSAnika Henke     *  and identify classes, width, lang and dir
32778ee21cSAnika Henke     *
33778ee21cSAnika Henke     * @author Anika Henke <anika@selfthinker.org>
34778ee21cSAnika Henke     * @author Christopher Smith <chris@jalakai.co.uk>
35778ee21cSAnika Henke     *   (parts taken from http://www.dokuwiki.org/plugin:box)
36778ee21cSAnika Henke     */
379e564057SAnika Henke    function getAttributes($data, $useNoPrefix=true) {
38778ee21cSAnika Henke
390b44a621SGerrit Uitslag        $attr = array(
400b44a621SGerrit Uitslag            'lang' => null,
410b44a621SGerrit Uitslag            'class' => null,
420b44a621SGerrit Uitslag            'width' => null,
430b44a621SGerrit Uitslag            'id' => null,
440b44a621SGerrit Uitslag            'dir' => null
450b44a621SGerrit Uitslag        );
46778ee21cSAnika Henke        $tokens = preg_split('/\s+/', $data, 9);
478666ad1eSSatoshi Sahara
488666ad1eSSatoshi Sahara        // anonymous function to convert inclusive comma separated items to regex pattern
498666ad1eSSatoshi Sahara        $pattern = function ($csv) {
508666ad1eSSatoshi Sahara            return '/^(?:'. str_replace(['?','*',' ',','],
518666ad1eSSatoshi Sahara                                        ['.','.*','','|'], $csv) .')$/';
528666ad1eSSatoshi Sahara        };
538666ad1eSSatoshi Sahara
548666ad1eSSatoshi Sahara        // noPrefix: comma separated class names that should be excluded from
558666ad1eSSatoshi Sahara        //   being prefixed with "wrap_",
568666ad1eSSatoshi Sahara        //   each item may contain wildcard (*, ?)
579e564057SAnika Henke        $noPrefix = ($this->getConf('noPrefix') && $useNoPrefix) ? $pattern($this->getConf('noPrefix')) : '';
588666ad1eSSatoshi Sahara
59f289ef65SSatoshi Sahara        // restrictedClasses : comma separated class names that should be checked
60f289ef65SSatoshi Sahara        //   based on restriction type (whitelist or blacklist),
61f289ef65SSatoshi Sahara        //   each item may contain wildcard (*, ?)
62f289ef65SSatoshi Sahara        $restrictedClasses = ($this->getConf('restrictedClasses')) ?
63f289ef65SSatoshi Sahara                            $pattern($this->getConf('restrictedClasses')) : '';
644d643b87SAnika Henke        $restrictionType = $this->getConf('restrictionType');
65778ee21cSAnika Henke
66778ee21cSAnika Henke        foreach ($tokens as $token) {
67778ee21cSAnika Henke
68778ee21cSAnika Henke            //get width
69943e64eeSAnika Henke            if (preg_match('/^\d*\.?\d+(%|px|em|rem|ex|ch|vw|vh|pt|pc|cm|mm|in)$/', $token)) {
70778ee21cSAnika Henke                $attr['width'] = $token;
71778ee21cSAnika Henke                continue;
72778ee21cSAnika Henke            }
73778ee21cSAnika Henke
74778ee21cSAnika Henke            //get lang
75*fa67e7a8SAndreas Gohr            if (preg_match('/^:([a-z\-]+)$/', $token, $matches)) {
76*fa67e7a8SAndreas Gohr                $attr['lang'] = $matches[1];
77778ee21cSAnika Henke                continue;
78778ee21cSAnika Henke            }
79778ee21cSAnika Henke
8010f30c3fSAnika Henke            //get id
81*fa67e7a8SAndreas Gohr            if (preg_match('/^#([A-Za-z0-9_-]+)$/', $token, $matches)) {
82*fa67e7a8SAndreas Gohr                $attr['id'] = $matches[1];
8310f30c3fSAnika Henke                continue;
8410f30c3fSAnika Henke            }
8510f30c3fSAnika Henke
86778ee21cSAnika Henke            //get classes
87778ee21cSAnika Henke            //restrict token (class names) characters to prevent any malicious data
88778ee21cSAnika Henke            if (preg_match('/[^A-Za-z0-9_-]/',$token)) continue;
894d643b87SAnika Henke            if ($restrictedClasses) {
90f289ef65SSatoshi Sahara                $classIsInList = preg_match($restrictedClasses, $token);
910f520867SSatoshi Sahara                // either allow only certain classes or disallow certain classes
920f520867SSatoshi Sahara                if ($restrictionType xor $classIsInList) continue;
934d643b87SAnika Henke            }
948666ad1eSSatoshi Sahara            // prefix adjustment of class name
953af97fceSEduardo Mozart de Oliveira            $prefix = (!empty($noPrefix) && preg_match($noPrefix, $token)) ? '' : 'wrap_';
96778ee21cSAnika Henke            $attr['class'] = (isset($attr['class']) ? $attr['class'].' ' : '').$prefix.$token;
97778ee21cSAnika Henke        }
988eb00ee4SAnika Henke        if ($this->getConf('darkTpl')) {
998eb00ee4SAnika Henke            $attr['class'] = (isset($attr['class']) ? $attr['class'].' ' : '').'wrap__dark';
1008eb00ee4SAnika Henke        }
101b2e512c8SAnika Henke        if ($this->getConf('emulatedHeadings')) {
102b2e512c8SAnika Henke            $attr['class'] = (isset($attr['class']) ? $attr['class'].' ' : '').'wrap__emuhead';
103b2e512c8SAnika Henke        }
104778ee21cSAnika Henke
10563cb595fSSascha Leib        /* improved RTL detection to make sure it covers more cases: */
10663cb595fSSascha Leib		if($attr['lang'] && $attr['lang'] !== '') {
10763cb595fSSascha Leib
10863cb595fSSascha Leib			// turn the language code into an array of components:
10963cb595fSSascha Leib			$arr = explode('-', $attr['lang']);
11063cb595fSSascha Leib
11163cb595fSSascha Leib			// is the language iso code (first field) in the list of RTL languages?
11263cb595fSSascha Leib			$rtl = in_array($arr[0], self::$rtllangs);
11363cb595fSSascha Leib
11463cb595fSSascha Leib			// is there a Script specified somewhere which overrides the text direction?
11563cb595fSSascha Leib			$rtl = ($rtl xor (bool) array_intersect( $rtl ? self::$ltrscripts : self::$rtlscripts, $arr));
11663cb595fSSascha Leib
11763cb595fSSascha Leib			$attr['dir'] = ( $rtl ? 'rtl' : 'ltr' );
118778ee21cSAnika Henke		}
119778ee21cSAnika Henke
120778ee21cSAnika Henke        return $attr;
121778ee21cSAnika Henke    }
122778ee21cSAnika Henke
123778ee21cSAnika Henke    /**
124778ee21cSAnika Henke     * build attributes (write out classes, width, lang and dir)
125778ee21cSAnika Henke     */
12606a639ecSAnika Henke    function buildAttributes($data, $addClass='', $mode='xhtml') {
127778ee21cSAnika Henke
128778ee21cSAnika Henke        $attr = $this->getAttributes($data);
129778ee21cSAnika Henke        $out = '';
130778ee21cSAnika Henke
13106a639ecSAnika Henke        if ($mode=='xhtml') {
1322e121deaSAnika Henke            if($attr['class']) $out .= ' class="'.hsc($attr['class']).' '.$addClass.'"';
1332e121deaSAnika Henke            // if used in other plugins, they might want to add their own class(es)
1342e121deaSAnika Henke            elseif($addClass)  $out .= ' class="'.$addClass.'"';
13510f30c3fSAnika Henke            if($attr['id'])    $out .= ' id="'.hsc($attr['id']).'"';
136778ee21cSAnika Henke            // width on spans normally doesn't make much sense, but in the case of floating elements it could be used
137da98b5a8SAnika Henke            if($attr['width']) {
138da98b5a8SAnika Henke                if (strpos($attr['width'],'%') !== false) {
139da98b5a8SAnika Henke                    $out .= ' style="width: '.hsc($attr['width']).';"';
140da98b5a8SAnika Henke                } else {
141da98b5a8SAnika Henke                    // anything but % should be 100% when the screen gets smaller
142da98b5a8SAnika Henke                    $out .= ' style="width: '.hsc($attr['width']).'; max-width: 100%;"';
143da98b5a8SAnika Henke                }
144da98b5a8SAnika Henke            }
145778ee21cSAnika Henke            // only write lang if it's a language in lang2dir.conf
146*fa67e7a8SAndreas Gohr            if($attr['dir'])   $out .= ' lang="'.hsc($attr['lang']).'" xml:lang="'.hsc($attr['lang']).'" dir="'.$attr['dir'].'"';
14706a639ecSAnika Henke        }
148778ee21cSAnika Henke
149778ee21cSAnika Henke        return $out;
150778ee21cSAnika Henke    }
151778ee21cSAnika Henke
15229523ac3SLarsDW223    /**
15329523ac3SLarsDW223     * render ODT element, Open
15429523ac3SLarsDW223     * (get Attributes, select ODT element that fits, render it, return element name)
15529523ac3SLarsDW223     */
15629523ac3SLarsDW223    function renderODTElementOpen($renderer, $HTMLelement, $data) {
1579e564057SAnika Henke        $attr = $this->getAttributes($data, false);
15803d18105SLarsDW223        $attr_string = $this->buildAttributes($data);
15929523ac3SLarsDW223        $classes = explode (' ', $attr['class']);
16029523ac3SLarsDW223
16129523ac3SLarsDW223        // Get language
16229523ac3SLarsDW223        $language = $attr['lang'];
16329523ac3SLarsDW223
16429523ac3SLarsDW223        $is_indent    = in_array ('wrap_indent', $classes);
16529523ac3SLarsDW223        $is_outdent   = in_array ('wrap_outdent', $classes);
16629523ac3SLarsDW223        $is_column    = in_array ('wrap_column', $classes);
167222a4effSLarsDW223        $is_group     = in_array ('wrap_group', $classes);
16829523ac3SLarsDW223        $is_pagebreak = in_array ('wrap_pagebreak', $classes);
16929523ac3SLarsDW223
17029523ac3SLarsDW223        // Check for multicolumns
17129523ac3SLarsDW223        $columns = 0;
17229523ac3SLarsDW223        preg_match ('/wrap_col\d/', $attr ['class'], $matches);
17329523ac3SLarsDW223        if ( empty ($matches [0]) === false ) {
17429523ac3SLarsDW223            $columns = $matches [0] [strlen($matches [0])-1];
17529523ac3SLarsDW223        }
17629523ac3SLarsDW223
17729523ac3SLarsDW223        // Check for boxes
17829523ac3SLarsDW223        $is_box = false;
17929523ac3SLarsDW223        foreach (self::$boxes as $box) {
18029523ac3SLarsDW223            if ( strpos ($attr ['class'], $box) !== false ) {
18129523ac3SLarsDW223                $is_box = true;
18229523ac3SLarsDW223                break;
18329523ac3SLarsDW223            }
18429523ac3SLarsDW223        }
18529523ac3SLarsDW223
18629523ac3SLarsDW223        // Check for paragraphs
18729523ac3SLarsDW223        $is_paragraph = false;
18829523ac3SLarsDW223        if ( empty($language) === false ) {
18929523ac3SLarsDW223            $is_paragraph = true;
19029523ac3SLarsDW223        } else {
19129523ac3SLarsDW223            foreach (self::$paragraphs as $paragraph) {
19229523ac3SLarsDW223                if ( strpos ($attr ['class'], $paragraph) !== false ) {
19329523ac3SLarsDW223                    $is_paragraph = true;
19429523ac3SLarsDW223                    break;
19529523ac3SLarsDW223                }
19629523ac3SLarsDW223            }
19729523ac3SLarsDW223        }
19829523ac3SLarsDW223
199ee387828SCodeLingoBot        $style = null;
20029523ac3SLarsDW223        if ( empty($attr['width']) === false ) {
20129523ac3SLarsDW223            $style = 'width: '.$attr['width'].';';
20229523ac3SLarsDW223        }
20329523ac3SLarsDW223        $attr ['class'] = 'dokuwiki '.$attr ['class'];
20429523ac3SLarsDW223
20529523ac3SLarsDW223        // Call corresponding functions for current wrap class
20629523ac3SLarsDW223        if ( $HTMLelement == 'span' ) {
20729523ac3SLarsDW223            if ( $is_indent === false && $is_outdent === false ) {
20803d18105SLarsDW223                $this->renderODTOpenSpan ($renderer, $attr ['class'], $style, $language, $attr_string);
20929523ac3SLarsDW223                return 'span';
21029523ac3SLarsDW223            } else {
21103d18105SLarsDW223                $this->renderODTOpenParagraph ($renderer, $attr ['class'], $style, $attr ['dir'], $language, $is_indent, $is_outdent, true, $attr_string);
21229523ac3SLarsDW223                return 'paragraph';
21329523ac3SLarsDW223            }
21429523ac3SLarsDW223        } else if ( $HTMLelement == 'div' ) {
21529523ac3SLarsDW223            if ( $is_box === true ) {
21603d18105SLarsDW223                $wrap = $this->loadHelper('wrap');
21703d18105SLarsDW223                $fullattr = $wrap->buildAttributes($data, 'plugin_wrap');
21803d18105SLarsDW223
21903d18105SLarsDW223                if ( method_exists ($renderer, 'getODTPropertiesFromElement') === false ) {
22003d18105SLarsDW223                    $this->renderODTOpenBox ($renderer, $attr ['class'], $style, $fullattr);
22103d18105SLarsDW223                } else {
22203d18105SLarsDW223                    $this->renderODTOpenTable ($renderer, $attr, $style,  $attr_string);
22303d18105SLarsDW223                }
22429523ac3SLarsDW223                return 'box';
22529523ac3SLarsDW223            } else if ( $columns > 0 ) {
22629523ac3SLarsDW223                $this->renderODTOpenColumns ($renderer, $attr ['class'], $style);
22729523ac3SLarsDW223                return 'multicolumn';
22829523ac3SLarsDW223            } else if ( $is_paragraph === true || $is_indent === true || $is_outdent === true ) {
22903d18105SLarsDW223                $this->renderODTOpenParagraph ($renderer, $attr ['class'], $style, $attr ['dir'], $language, $is_indent, $is_outdent, false, $attr_string);
23029523ac3SLarsDW223                return 'paragraph';
23129523ac3SLarsDW223            } else if ( $is_pagebreak === true ) {
23229523ac3SLarsDW223                $renderer->pagebreak ();
23329523ac3SLarsDW223                // Pagebreak hasn't got a closing stack so we return/push 'other' on the stack
23429523ac3SLarsDW223                return 'other';
23529523ac3SLarsDW223            } else if ( $is_column === true ) {
23603d18105SLarsDW223                $this->renderODTOpenColumn ($renderer, $attr ['class'], $style, $attr_string);
23729523ac3SLarsDW223                return 'column';
23829523ac3SLarsDW223            } else if ( $is_group === true ) {
23929523ac3SLarsDW223                $this->renderODTOpenGroup ($renderer, $attr ['class'], $style);
24029523ac3SLarsDW223                return 'group';
2411fdcb5a2SLarsDW223            } else if (strpos ($attr ['class'], 'wrap_clear') !== false ) {
2421fdcb5a2SLarsDW223                $renderer->linebreak();
2431fdcb5a2SLarsDW223                $renderer->p_close();
2441fdcb5a2SLarsDW223                $renderer->p_open();
2451fdcb5a2SLarsDW223
2461fdcb5a2SLarsDW223                self::$box_left_pos = 0;
2471fdcb5a2SLarsDW223                self::$box_right_pos = 0;
2481fdcb5a2SLarsDW223                self::$box_first = true;
24929523ac3SLarsDW223            }
25029523ac3SLarsDW223        }
25129523ac3SLarsDW223        return 'other';
25229523ac3SLarsDW223    }
25329523ac3SLarsDW223
25429523ac3SLarsDW223    /**
25529523ac3SLarsDW223     * render ODT element, Close
25629523ac3SLarsDW223     */
25729523ac3SLarsDW223    function renderODTElementClose($renderer, $element) {
25829523ac3SLarsDW223        switch ($element) {
25929523ac3SLarsDW223            case 'box':
26003d18105SLarsDW223                if ( method_exists ($renderer, 'getODTPropertiesFromElement') === false ) {
26129523ac3SLarsDW223                    $this->renderODTCloseBox ($renderer);
26203d18105SLarsDW223                } else {
26303d18105SLarsDW223                    $this->renderODTCloseTable ($renderer);
26403d18105SLarsDW223                }
26529523ac3SLarsDW223            break;
26629523ac3SLarsDW223            case 'multicolumn':
26729523ac3SLarsDW223                $this->renderODTCloseColumns($renderer);
26829523ac3SLarsDW223            break;
26929523ac3SLarsDW223            case 'paragraph':
27029523ac3SLarsDW223                $this->renderODTCloseParagraph($renderer);
27129523ac3SLarsDW223            break;
27229523ac3SLarsDW223            case 'column':
27329523ac3SLarsDW223                $this->renderODTCloseColumn($renderer);
27429523ac3SLarsDW223            break;
27529523ac3SLarsDW223            case 'group':
27629523ac3SLarsDW223                $this->renderODTCloseGroup($renderer);
27729523ac3SLarsDW223            break;
27829523ac3SLarsDW223            case 'span':
27929523ac3SLarsDW223                $this->renderODTCloseSpan($renderer);
28029523ac3SLarsDW223            break;
28129523ac3SLarsDW223            // No default by intention.
28229523ac3SLarsDW223        }
28329523ac3SLarsDW223    }
28429523ac3SLarsDW223
28503d18105SLarsDW223    function renderODTOpenBox ($renderer, $class, $style, $fullattr) {
28629523ac3SLarsDW223        $properties = array ();
28729523ac3SLarsDW223
28829523ac3SLarsDW223        if ( method_exists ($renderer, 'getODTProperties') === false ) {
28929523ac3SLarsDW223            // Function is not supported by installed ODT plugin version, return.
29029523ac3SLarsDW223            return;
29129523ac3SLarsDW223        }
29229523ac3SLarsDW223
29329523ac3SLarsDW223        // Get CSS properties for ODT export.
29429523ac3SLarsDW223        $renderer->getODTProperties ($properties, 'div', $class, $style);
29529523ac3SLarsDW223
29629523ac3SLarsDW223        if ( empty($properties ['background-image']) === false ) {
29729523ac3SLarsDW223            $properties ['background-image'] =
29829523ac3SLarsDW223                $renderer->replaceURLPrefix ($properties ['background-image'], DOKU_INC);
29929523ac3SLarsDW223        }
30029523ac3SLarsDW223
30129523ac3SLarsDW223        if ( empty($properties ['float']) === true ) {
30229523ac3SLarsDW223            // If the float property is not set, set it to 'left' becuase the ODT plugin
30329523ac3SLarsDW223            // would default to 'center' which is diffeent to the XHTML behaviour.
30429523ac3SLarsDW223            if ( strpos ($class, 'wrap_center') === false ) {
30529523ac3SLarsDW223                $properties ['float'] = 'left';
30629523ac3SLarsDW223            } else {
30729523ac3SLarsDW223                $properties ['float'] = 'center';
30829523ac3SLarsDW223            }
30929523ac3SLarsDW223        }
31029523ac3SLarsDW223
31129523ac3SLarsDW223        // The display property has differing usage in CSS. So we better overwrite it.
31229523ac3SLarsDW223        $properties ['display'] = 'always';
31329523ac3SLarsDW223        if ( stripos ($class, 'wrap_noprint') !== false ) {
31429523ac3SLarsDW223            $properties ['display'] = 'screen';
31529523ac3SLarsDW223        }
31629523ac3SLarsDW223        if ( stripos ($class, 'wrap_onlyprint') !== false ) {
31729523ac3SLarsDW223            $properties ['display'] = 'printer';
31829523ac3SLarsDW223        }
31929523ac3SLarsDW223
32029523ac3SLarsDW223        $renderer->_odtDivOpenAsFrameUseProperties ($properties);
32129523ac3SLarsDW223    }
32229523ac3SLarsDW223
32329523ac3SLarsDW223    function renderODTCloseBox ($renderer) {
32429523ac3SLarsDW223        if ( method_exists ($renderer, '_odtDivCloseAsFrame') === false ) {
32529523ac3SLarsDW223            // Function is not supported by installed ODT plugin version, return.
32629523ac3SLarsDW223            return;
32729523ac3SLarsDW223        }
32829523ac3SLarsDW223        $renderer->_odtDivCloseAsFrame ();
32929523ac3SLarsDW223    }
33029523ac3SLarsDW223
33129523ac3SLarsDW223    function renderODTOpenColumns ($renderer, $class, $style) {
33229523ac3SLarsDW223        $properties = array ();
33329523ac3SLarsDW223
33429523ac3SLarsDW223        if ( method_exists ($renderer, 'getODTProperties') === false ) {
33529523ac3SLarsDW223            // Function is not supported by installed ODT plugin version, return.
33629523ac3SLarsDW223            return;
33729523ac3SLarsDW223        }
33829523ac3SLarsDW223
33929523ac3SLarsDW223        // Get CSS properties for ODT export.
34029523ac3SLarsDW223        $renderer->getODTProperties ($properties, 'div', $class, $style);
34129523ac3SLarsDW223
34229523ac3SLarsDW223        $renderer->_odtOpenMultiColumnFrame($properties);
34329523ac3SLarsDW223    }
34429523ac3SLarsDW223
34529523ac3SLarsDW223    function renderODTCloseColumns ($renderer) {
34629523ac3SLarsDW223        if ( method_exists ($renderer, '_odtCloseMultiColumnFrame') === false ) {
34729523ac3SLarsDW223            // Function is not supported by installed ODT plugin version, return.
34829523ac3SLarsDW223            return;
34929523ac3SLarsDW223        }
35029523ac3SLarsDW223        $renderer->_odtCloseMultiColumnFrame();
35129523ac3SLarsDW223    }
35229523ac3SLarsDW223
353ee387828SCodeLingoBot    function renderODTOpenParagraph ($renderer, $class, $style, $dir, $language, $is_indent, $is_outdent, $indent_first, $attr=null) {
35429523ac3SLarsDW223        $properties = array ();
35529523ac3SLarsDW223
35603d18105SLarsDW223        if ( method_exists ($renderer, 'getODTPropertiesFromElement') === true ) {
35729523ac3SLarsDW223            // Get CSS properties for ODT export.
35803d18105SLarsDW223            // Set parameter $inherit=false to prevent changiung the font-size and family!
359ee387828SCodeLingoBot            $renderer->getODTPropertiesNew ($properties, 'p', $attr, null, false);
36003d18105SLarsDW223        } else if ( method_exists ($renderer, 'getODTProperties') === true ) {
36103d18105SLarsDW223            // Get CSS properties for ODT export (deprecated version).
36229523ac3SLarsDW223            $renderer->getODTProperties ($properties, 'p', $class, $style);
36329523ac3SLarsDW223
36429523ac3SLarsDW223            if ( empty($properties ['background-image']) === false ) {
36529523ac3SLarsDW223                $properties ['background-image'] =
36629523ac3SLarsDW223                    $renderer->replaceURLPrefix ($properties ['background-image'], DOKU_INC);
36729523ac3SLarsDW223            }
36803d18105SLarsDW223        } else {
36903d18105SLarsDW223            // To old ODT plugin version.
37003d18105SLarsDW223            return;
37103d18105SLarsDW223        }
37229523ac3SLarsDW223
37303d18105SLarsDW223        if ( empty($properties ['text-align']) )
37403d18105SLarsDW223        {
37503d18105SLarsDW223            if ($dir == 'ltr') {
37603d18105SLarsDW223                $properties ['text-align'] = 'left';
37703d18105SLarsDW223                $properties ['writing-mode'] = 'lr';
37803d18105SLarsDW223            }
37903d18105SLarsDW223            if ($dir == 'rtl') {
38003d18105SLarsDW223                $properties ['text-align'] = 'right';
38103d18105SLarsDW223                $properties ['writing-mode'] = 'rl';
38203d18105SLarsDW223            }
38303d18105SLarsDW223        }
38403d18105SLarsDW223
38503d18105SLarsDW223        $name = '';
38629523ac3SLarsDW223        if ( empty($language) === false ) {
38729523ac3SLarsDW223            $properties ['lang'] = $language;
38803d18105SLarsDW223            $name .= 'Language: '.$language;
38929523ac3SLarsDW223        }
39029523ac3SLarsDW223
39129523ac3SLarsDW223        if ( $indent_first === true ) {
39229523ac3SLarsDW223            // Eventually indent or outdent first line only...
39329523ac3SLarsDW223            if ( $is_indent === true ) {
39429523ac3SLarsDW223                // FIXME: Has to be adjusted if test direction will be supported.
39529523ac3SLarsDW223                // See all.css
39629523ac3SLarsDW223                $properties ['text-indent'] = $properties ['padding-left'];
39729523ac3SLarsDW223                $properties ['padding-left'] = 0;
39803d18105SLarsDW223                $name .= 'Indent first';
39929523ac3SLarsDW223            }
40029523ac3SLarsDW223            if ( $is_outdent === true ) {
40129523ac3SLarsDW223                // FIXME: Has to be adjusted if text (RTL, LTR) direction will be supported.
40229523ac3SLarsDW223                // See all.css
40329523ac3SLarsDW223                $properties ['text-indent'] = $properties ['margin-left'];
40429523ac3SLarsDW223                $properties ['margin-left'] = 0;
40503d18105SLarsDW223                $name .= 'Outdent first';
40629523ac3SLarsDW223            }
40729523ac3SLarsDW223        } else {
40829523ac3SLarsDW223            // Eventually indent or outdent the whole paragraph...
40929523ac3SLarsDW223            if ( $is_indent === true ) {
41029523ac3SLarsDW223                // FIXME: Has to be adjusted if test direction will be supported.
41129523ac3SLarsDW223                // See all.css
4124842a173Snerun                $properties ['margin-left'] = $properties ['padding-left'] ?? null;
41329523ac3SLarsDW223                $properties ['padding-left'] = 0;
41403d18105SLarsDW223                $name .= 'Indent';
41529523ac3SLarsDW223            }
41629523ac3SLarsDW223            if ( $is_outdent === true ) {
41729523ac3SLarsDW223                // Nothing to change: keep left margin property.
41829523ac3SLarsDW223                // FIXME: Has to be adjusted if text (RTL, LTR) direction will be supported.
41929523ac3SLarsDW223                // See all.css
42003d18105SLarsDW223                $name .= 'Outdent';
42129523ac3SLarsDW223            }
42229523ac3SLarsDW223        }
42329523ac3SLarsDW223
42429523ac3SLarsDW223        $renderer->p_close();
42503d18105SLarsDW223        if ( method_exists ($renderer, 'createParagraphStyle') === false ) {
42603d18105SLarsDW223            // Older ODT plugin version.
42729523ac3SLarsDW223            $renderer->_odtParagraphOpenUseProperties($properties);
42803d18105SLarsDW223        } else {
42903d18105SLarsDW223            // Newer version create our own common styles.
43003d18105SLarsDW223
43103d18105SLarsDW223            // Create parent style to group the others beneath it
43203d18105SLarsDW223            if (!$renderer->styleExists('Plugin_Wrap_Paragraphs')) {
43303d18105SLarsDW223                $parent_properties = array();
434ee387828SCodeLingoBot                $parent_properties ['style-parent'] = null;
43503d18105SLarsDW223                $parent_properties ['style-class'] = 'Plugin Wrap Paragraphs';
43603d18105SLarsDW223                $parent_properties ['style-name'] = 'Plugin_Wrap_Paragraphs';
43703d18105SLarsDW223                $parent_properties ['style-display-name'] = 'Plugin Wrap';
43803d18105SLarsDW223                $renderer->createParagraphStyle($parent_properties);
43903d18105SLarsDW223            }
44003d18105SLarsDW223
44103d18105SLarsDW223            $name .= $this->getODTCommonStyleName($class);
44203d18105SLarsDW223            $style_name = 'Plugin_Wrap_Paragraph_'.$name;
44303d18105SLarsDW223            if (!$renderer->styleExists($style_name)) {
44403d18105SLarsDW223                $properties ['style-parent'] = 'Plugin_Wrap_Paragraphs';
445ee387828SCodeLingoBot                $properties ['style-class'] = null;
44603d18105SLarsDW223                $properties ['style-name'] = $style_name;
44703d18105SLarsDW223                $properties ['style-display-name'] = $name;
44803d18105SLarsDW223                $renderer->createParagraphStyle($properties);
44903d18105SLarsDW223            }
45003d18105SLarsDW223
45103d18105SLarsDW223            $renderer->p_open($style_name);
45203d18105SLarsDW223        }
45329523ac3SLarsDW223    }
45429523ac3SLarsDW223
45529523ac3SLarsDW223    function renderODTCloseParagraph ($renderer) {
45629523ac3SLarsDW223        if ( method_exists ($renderer, 'p_close') === false ) {
45729523ac3SLarsDW223            // Function is not supported by installed ODT plugin version, return.
45829523ac3SLarsDW223            return;
45929523ac3SLarsDW223        }
46029523ac3SLarsDW223        $renderer->p_close();
46129523ac3SLarsDW223    }
46229523ac3SLarsDW223
46303d18105SLarsDW223    function renderODTOpenColumn ($renderer, $class, $style, $attr) {
46429523ac3SLarsDW223        $properties = array ();
46529523ac3SLarsDW223
46603d18105SLarsDW223        if ( method_exists ($renderer, 'getODTPropertiesFromElement') === true ) {
46703d18105SLarsDW223            // Get CSS properties for ODT export.
46803d18105SLarsDW223            $renderer->getODTPropertiesNew ($properties, 'div', $attr);
46903d18105SLarsDW223        } else if ( method_exists ($renderer, 'getODTProperties') === true ) {
47003d18105SLarsDW223            // Get CSS properties for ODT export (deprecated version).
471ee387828SCodeLingoBot            $renderer->getODTProperties ($properties, null, $class, $style);
47203d18105SLarsDW223        } else {
47303d18105SLarsDW223            // To old ODT plugin version.
47429523ac3SLarsDW223            return;
47529523ac3SLarsDW223        }
47629523ac3SLarsDW223
47729523ac3SLarsDW223        // Frames/Textboxes still have some issues with formatting (at least in LibreOffice)
47829523ac3SLarsDW223        // So as a workaround we implement columns as a table.
47929523ac3SLarsDW223        // This is why we now use the margin of the div as the padding for the ODT table.
4807d1f72d2Snerun        $properties ['padding-left'] = $properties ['margin-left'] ?? null;
4817d1f72d2Snerun        $properties ['padding-right'] = $properties ['margin-right'] ?? null;
4827d1f72d2Snerun        $properties ['padding-top'] = $properties ['margin-top'] ?? null;
4837d1f72d2Snerun        $properties ['padding-bottom'] = $properties ['margin-bottom'] ?? null;
484ee387828SCodeLingoBot        $properties ['margin-left'] = null;
485ee387828SCodeLingoBot        $properties ['margin-right'] = null;
486ee387828SCodeLingoBot        $properties ['margin-top'] = null;
487ee387828SCodeLingoBot        $properties ['margin-bottom'] = null;
48829523ac3SLarsDW223
48929523ac3SLarsDW223        // Percentage values are not supported for the padding. Convert to absolute values.
49029523ac3SLarsDW223        $length = strlen ($properties ['padding-left']);
49129523ac3SLarsDW223        if ( $length > 0 && $properties ['padding-left'] [$length-1] == '%' ) {
49229523ac3SLarsDW223            $properties ['padding-left'] = trim ($properties ['padding-left'], '%');
49329523ac3SLarsDW223            $properties ['padding-left'] = $renderer->_getAbsWidthMindMargins ($properties ['padding-left']).'cm';
49429523ac3SLarsDW223        }
49529523ac3SLarsDW223        $length = strlen ($properties ['padding-right']);
49629523ac3SLarsDW223        if ( $length > 0 && $properties ['padding-right'] [$length-1] == '%' ) {
49729523ac3SLarsDW223            $properties ['padding-right'] = trim ($properties ['padding-right'], '%');
49829523ac3SLarsDW223            $properties ['padding-right'] = $renderer->_getAbsWidthMindMargins ($properties ['padding-right']).'cm';
49929523ac3SLarsDW223        }
50029523ac3SLarsDW223        $length = strlen ($properties ['padding-top']);
50129523ac3SLarsDW223        if ( $length > 0 && $properties ['padding-top'] [$length-1] == '%' ) {
50229523ac3SLarsDW223            $properties ['padding-top'] = trim ($properties ['padding-top'], '%');
50329523ac3SLarsDW223            $properties ['padding-top'] = $renderer->_getAbsWidthMindMargins ($properties ['padding-top']).'cm';
50429523ac3SLarsDW223        }
50529523ac3SLarsDW223        $length = strlen ($properties ['padding-bottom']);
50629523ac3SLarsDW223        if ( $length > 0 && $properties ['padding-bottom'] [$length-1] == '%' ) {
50729523ac3SLarsDW223            $properties ['padding-bottom'] = trim ($properties ['padding-bottom'], '%');
50829523ac3SLarsDW223            $properties ['padding-bottom'] = $renderer->_getAbsWidthMindMargins ($properties ['padding-bottom']).'cm';
50929523ac3SLarsDW223        }
51029523ac3SLarsDW223
51129523ac3SLarsDW223        $this->column_count++;
51229523ac3SLarsDW223        if ( $this->column_count == 1 ) {
51329523ac3SLarsDW223            // If this is the first column opened since the group was opened
51429523ac3SLarsDW223            // then we have to open the table and a (single) row first.
51529523ac3SLarsDW223            $properties ['width'] = '100%';
51629523ac3SLarsDW223            $renderer->_odtTableOpenUseProperties($properties);
51729523ac3SLarsDW223            $renderer->_odtTableRowOpenUseProperties($properties);
51829523ac3SLarsDW223        }
51929523ac3SLarsDW223
52029523ac3SLarsDW223        // We did not specify any max column value when we opened the table.
52129523ac3SLarsDW223        // So we have to tell the renderer to add a column just now.
5228e550bd5SLarsDW223        unset($properties ['width']);
52329523ac3SLarsDW223        $renderer->_odtTableAddColumnUseProperties($properties);
52429523ac3SLarsDW223
52529523ac3SLarsDW223        // Open the cell.
52629523ac3SLarsDW223        $renderer->_odtTableCellOpenUseProperties($properties);
52729523ac3SLarsDW223    }
52829523ac3SLarsDW223
52929523ac3SLarsDW223    function renderODTCloseColumn ($renderer) {
53029523ac3SLarsDW223        if ( method_exists ($renderer, '_odtTableAddColumnUseProperties') === false ) {
53129523ac3SLarsDW223            // Function is not supported by installed ODT plugin version, return.
53229523ac3SLarsDW223            return;
53329523ac3SLarsDW223        }
53429523ac3SLarsDW223
53529523ac3SLarsDW223        $renderer->tablecell_close();
53629523ac3SLarsDW223    }
53729523ac3SLarsDW223
53829523ac3SLarsDW223    function renderODTOpenGroup ($renderer, $class, $style) {
53929523ac3SLarsDW223        // Nothing to do for now.
54029523ac3SLarsDW223    }
54129523ac3SLarsDW223
54229523ac3SLarsDW223    function renderODTCloseGroup ($renderer) {
54329523ac3SLarsDW223        // If a table has been opened in the group we close it now.
54429523ac3SLarsDW223        if ( $this->column_count > 0 ) {
54529523ac3SLarsDW223            // At last we need to close the row and the table!
54629523ac3SLarsDW223            $renderer->tablerow_close();
54729523ac3SLarsDW223            //$renderer->table_close();
54829523ac3SLarsDW223            $renderer->_odtTableClose();
54929523ac3SLarsDW223        }
55029523ac3SLarsDW223        $this->column_count = 0;
55129523ac3SLarsDW223    }
55229523ac3SLarsDW223
55303d18105SLarsDW223    function renderODTOpenSpan ($renderer, $class, $style, $language, $attr) {
55429523ac3SLarsDW223        $properties = array ();
55529523ac3SLarsDW223
55603d18105SLarsDW223        if ( method_exists ($renderer, 'getODTPropertiesFromElement') === true ) {
55729523ac3SLarsDW223            // Get CSS properties for ODT export.
55803d18105SLarsDW223            // Set parameter $inherit=false to prevent changiung the font-size and family!
559ee387828SCodeLingoBot            $renderer->getODTPropertiesNew ($properties, 'span', $attr, null, false);
56003d18105SLarsDW223        } else if ( method_exists ($renderer, 'getODTProperties') === true ) {
56103d18105SLarsDW223            // Get CSS properties for ODT export (deprecated version).
56229523ac3SLarsDW223            $renderer->getODTProperties ($properties, 'span', $class, $style);
56329523ac3SLarsDW223
56429523ac3SLarsDW223            if ( empty($properties ['background-image']) === false ) {
56529523ac3SLarsDW223                $properties ['background-image'] =
56629523ac3SLarsDW223                    $renderer->replaceURLPrefix ($properties ['background-image'], DOKU_INC);
56729523ac3SLarsDW223            }
56803d18105SLarsDW223        } else {
56903d18105SLarsDW223            // To old ODT plugin version.
57003d18105SLarsDW223            return;
57129523ac3SLarsDW223        }
57229523ac3SLarsDW223
57303d18105SLarsDW223        $name = '';
57403d18105SLarsDW223        if ( empty($language) === false ) {
57503d18105SLarsDW223            $properties ['lang'] = $language;
57603d18105SLarsDW223            $name .= 'Language: '.$language;
57703d18105SLarsDW223        }
57803d18105SLarsDW223
57903d18105SLarsDW223        if ( method_exists ($renderer, 'getODTPropertiesFromElement') === false ) {
58003d18105SLarsDW223            // Older ODT plugin version.
58129523ac3SLarsDW223            $renderer->_odtSpanOpenUseProperties($properties);
58203d18105SLarsDW223        } else {
58303d18105SLarsDW223            // Newer version create our own common styles.
584ee387828SCodeLingoBot            $properties ['font-size'] = null;
58503d18105SLarsDW223
58603d18105SLarsDW223            // Create parent style to group the others beneath it
58703d18105SLarsDW223            if (!$renderer->styleExists('Plugin_Wrap_Spans')) {
58803d18105SLarsDW223                $parent_properties = array();
589ee387828SCodeLingoBot                $parent_properties ['style-parent'] = null;
59003d18105SLarsDW223                $parent_properties ['style-class'] = 'Plugin Wrap Spans';
59103d18105SLarsDW223                $parent_properties ['style-name'] = 'Plugin_Wrap_Spans';
59203d18105SLarsDW223                $parent_properties ['style-display-name'] = 'Plugin Wrap';
59303d18105SLarsDW223                $renderer->createTextStyle($parent_properties);
59403d18105SLarsDW223            }
59503d18105SLarsDW223
59603d18105SLarsDW223            $name .= $this->getODTCommonStyleName($class);
59703d18105SLarsDW223            $style_name = 'Plugin_Wrap_Span_'.$name;
59803d18105SLarsDW223            if (!$renderer->styleExists($style_name)) {
59903d18105SLarsDW223                $properties ['style-parent'] = 'Plugin_Wrap_Spans';
600ee387828SCodeLingoBot                $properties ['style-class'] = null;
60103d18105SLarsDW223                $properties ['style-name'] = $style_name;
60203d18105SLarsDW223                $properties ['style-display-name'] = $name;
60303d18105SLarsDW223                $renderer->createTextStyle($properties);
60403d18105SLarsDW223            }
60503d18105SLarsDW223
60603d18105SLarsDW223            if (!empty($properties ['background-image'])) {
60703d18105SLarsDW223                if (method_exists ($renderer, '_odtAddImageUseProperties') === true) {
608ee387828SCodeLingoBot                    $size = null;
60903d18105SLarsDW223                    if (!empty($properties ['font-size'])) {
61003d18105SLarsDW223                        $size = $properties ['font-size'];
61103d18105SLarsDW223                        $size = $renderer->addToValue($size, '2pt');
61203d18105SLarsDW223                    }
61303d18105SLarsDW223                    $properties ['width'] = $size;
61403d18105SLarsDW223                    $properties ['height'] = $size;
615ee387828SCodeLingoBot                    $properties ['title'] = null;
61603d18105SLarsDW223                    $renderer->_odtAddImageUseProperties ($properties ['background-image'],$properties);
61703d18105SLarsDW223                } else {
618ee387828SCodeLingoBot                    $renderer->_odtAddImage ($properties ['background-image'],null,null,null,null,null);
61903d18105SLarsDW223                }
62003d18105SLarsDW223            }
62103d18105SLarsDW223            $renderer->_odtSpanOpen($style_name);
62203d18105SLarsDW223        }
62329523ac3SLarsDW223    }
62429523ac3SLarsDW223
62529523ac3SLarsDW223    function renderODTCloseSpan ($renderer) {
62629523ac3SLarsDW223        if ( method_exists ($renderer, '_odtSpanClose') === false ) {
62729523ac3SLarsDW223            // Function is not supported by installed ODT plugin version, return.
62829523ac3SLarsDW223            return;
62929523ac3SLarsDW223        }
63029523ac3SLarsDW223        $renderer->_odtSpanClose();
63129523ac3SLarsDW223    }
63203d18105SLarsDW223
63303d18105SLarsDW223    function renderODTOpenTable ($renderer, $attr, $style, $attr_string) {
6341fdcb5a2SLarsDW223        self::$table_entr += 1;
6351fdcb5a2SLarsDW223
63603d18105SLarsDW223        $class = $attr ['class'];
6371fdcb5a2SLarsDW223        $css_properties = array ();
63803d18105SLarsDW223
63903d18105SLarsDW223        if ( method_exists ($renderer, 'getODTPropertiesFromElement') === false ) {
64003d18105SLarsDW223            // Function is not supported by installed ODT plugin version, return.
64103d18105SLarsDW223            return;
64203d18105SLarsDW223        }
64303d18105SLarsDW223
64403d18105SLarsDW223        // Get CSS properties for ODT export.
645ee387828SCodeLingoBot        $renderer->getODTPropertiesNew ($css_properties, 'div', $attr_string, null, true);
64603d18105SLarsDW223
6471fdcb5a2SLarsDW223        if ( empty($css_properties ['float']) === true ) {
64803d18105SLarsDW223            // If the float property is not set, set it to 'left' becuase the ODT plugin
64903d18105SLarsDW223            // would default to 'center' which is diffeent to the XHTML behaviour.
6501fdcb5a2SLarsDW223            //$css_properties ['float'] = 'left';
6511fdcb5a2SLarsDW223            if (strpos ($class, 'wrap_left') !== false ) {
6521fdcb5a2SLarsDW223                $css_properties ['float'] = 'left';
6531fdcb5a2SLarsDW223            } else if (strpos ($class, 'wrap_center') !== false ) {
6541fdcb5a2SLarsDW223                $css_properties ['float'] = 'center';
6551fdcb5a2SLarsDW223            } else if (strpos ($class, 'wrap_right') !== false) {
6561fdcb5a2SLarsDW223                $css_properties ['float'] = 'right';
65703d18105SLarsDW223            }
65803d18105SLarsDW223        }
65903d18105SLarsDW223
66003d18105SLarsDW223        // The display property has differing usage in CSS. So we better overwrite it.
6611fdcb5a2SLarsDW223        $css_properties ['display'] = 'always';
66203d18105SLarsDW223        if ( stripos ($class, 'wrap_noprint') !== false ) {
6631fdcb5a2SLarsDW223            $css_properties ['display'] = 'screen';
66403d18105SLarsDW223        }
66503d18105SLarsDW223        if ( stripos ($class, 'wrap_onlyprint') !== false ) {
6661fdcb5a2SLarsDW223            $css_properties ['display'] = 'printer';
66703d18105SLarsDW223        }
66803d18105SLarsDW223
6691fdcb5a2SLarsDW223        $background_color = $css_properties ['background-color'];
670004a76e6SEduardo Mozart de Oliveira        $image = $css_properties ['background-image'] ?? null;
6711fdcb5a2SLarsDW223        $margin_top = $css_properties ['margin-top'];
6721fdcb5a2SLarsDW223        $margin_right = $css_properties ['margin-right'];
6731fdcb5a2SLarsDW223        $margin_bottom = $css_properties ['margin-bottom'];
6741fdcb5a2SLarsDW223        $margin_left = $css_properties ['margin-left'];
67503d18105SLarsDW223        $width = $attr ['width'];
67603d18105SLarsDW223
67703d18105SLarsDW223        // Open 2x1 table if image is present
67803d18105SLarsDW223        // otherwise only a 1x1 table
67903d18105SLarsDW223        $properties = array();
6801fdcb5a2SLarsDW223        $properties ['width'] = '100%';
68103d18105SLarsDW223        $properties ['align'] = 'center';
68203d18105SLarsDW223        $properties ['margin-top'] = $margin_top;
68303d18105SLarsDW223        $properties ['margin-right'] = $margin_right;
68403d18105SLarsDW223        $properties ['margin-bottom'] = $margin_bottom;
68503d18105SLarsDW223        $properties ['margin-left'] = $margin_left;
68603d18105SLarsDW223
6871fdcb5a2SLarsDW223        $frame_props = array();
6881fdcb5a2SLarsDW223        if (!empty($css_properties ['border'])) {
6891fdcb5a2SLarsDW223            $frame_props ['border'] = $css_properties ['border'];
6901fdcb5a2SLarsDW223        } else {
6911fdcb5a2SLarsDW223            $frame_props ['border'] = 'none';
6921fdcb5a2SLarsDW223        }
6931fdcb5a2SLarsDW223        $frame_props ['min-height'] = '1cm';
6941fdcb5a2SLarsDW223        $frame_props ['width'] = $attr ['width'];
6951fdcb5a2SLarsDW223        $frame_props ['float'] = $css_properties ['float'];
6961fdcb5a2SLarsDW223        if ( self::$table_entr > 1 ) {
6971fdcb5a2SLarsDW223            $frame_props ['anchor-type'] = 'as-char';
6981fdcb5a2SLarsDW223        } else {
6991fdcb5a2SLarsDW223            $frame_props ['anchor-type'] = 'paragraph';
7001fdcb5a2SLarsDW223        }
7011fdcb5a2SLarsDW223        $frame_props ['textarea-horizontal-align'] = 'left';
7021fdcb5a2SLarsDW223        $frame_props ['run-through'] = 'foreground';
7031fdcb5a2SLarsDW223        $frame_props ['vertical-pos'] = 'from-top';
7041fdcb5a2SLarsDW223        $frame_props ['vertical-rel'] = 'paragraph';
7051fdcb5a2SLarsDW223        $frame_props ['horizontal-pos'] = 'from-left';
7061fdcb5a2SLarsDW223        $frame_props ['horizontal-rel'] = 'paragraph';
7071fdcb5a2SLarsDW223        $frame_props ['wrap'] = 'parallel';
7081fdcb5a2SLarsDW223        $frame_props ['number-wrapped-paragraphs'] = 'no-limit';
7091fdcb5a2SLarsDW223        if (!empty($frame_props ['float']) &&
7101fdcb5a2SLarsDW223            $frame_props ['float'] != 'center') {
7111fdcb5a2SLarsDW223            $frame_props ['margin-top'] = '0cm';
7121fdcb5a2SLarsDW223            $frame_props ['margin-right'] = '0cm';
7131fdcb5a2SLarsDW223            $frame_props ['margin-bottom'] = '0cm';
7141fdcb5a2SLarsDW223            $frame_props ['margin-left'] = '0cm';
7151fdcb5a2SLarsDW223            $frame_props ['padding-top'] = '0cm';
7161fdcb5a2SLarsDW223            $frame_props ['padding-bottom'] = '0cm';
7171fdcb5a2SLarsDW223        } else {
7181fdcb5a2SLarsDW223            // No wrapping on not floating divs
7191fdcb5a2SLarsDW223            $frame_props ['wrap'] = 'none';
7201fdcb5a2SLarsDW223        }
7211fdcb5a2SLarsDW223
7221fdcb5a2SLarsDW223        switch ($frame_props ['float']) {
7231fdcb5a2SLarsDW223            case 'left':
7241fdcb5a2SLarsDW223                if ( self::$table_entr == 1 ) {
7251fdcb5a2SLarsDW223                    $frame_props ['y'] = '0cm';
7261fdcb5a2SLarsDW223                    $frame_props ['x'] = self::$box_left_pos.'cm';
7271fdcb5a2SLarsDW223                    self::$box_left_pos += trim($frame_props ['width'], 'cm');
7281fdcb5a2SLarsDW223                }
7291fdcb5a2SLarsDW223                $frame_props ['padding-left'] = '0cm';
7301fdcb5a2SLarsDW223            break;
7311fdcb5a2SLarsDW223            case 'right':
7321fdcb5a2SLarsDW223                $frame_props ['horizontal-rel'] = 'paragraph';
7331fdcb5a2SLarsDW223                $frame_props ['horizontal-pos'] = 'right';
7341fdcb5a2SLarsDW223                $frame_props ['padding-right'] = '0cm';
7351fdcb5a2SLarsDW223            break;
7361fdcb5a2SLarsDW223            case 'center':
7371fdcb5a2SLarsDW223                $frame_props ['horizontal-pos'] = 'center';
7381fdcb5a2SLarsDW223            break;
7391fdcb5a2SLarsDW223            default:
7401fdcb5a2SLarsDW223                $frame_props ['padding-left'] = '0cm';
7411fdcb5a2SLarsDW223            break;
7421fdcb5a2SLarsDW223        }
7431fdcb5a2SLarsDW223        $renderer->_odtOpenTextBoxUseProperties($frame_props);
7441fdcb5a2SLarsDW223
74503d18105SLarsDW223        $renderer->_odtTableOpenUseProperties($properties);
74603d18105SLarsDW223
74703d18105SLarsDW223        if (!empty($image)) {
74803d18105SLarsDW223            $properties = array();
74903d18105SLarsDW223            $properties ['width'] = '2cm';
75003d18105SLarsDW223            $renderer->_odtTableAddColumnUseProperties($properties);
75103d18105SLarsDW223        }
75203d18105SLarsDW223
75303d18105SLarsDW223        $properties = array();
75403d18105SLarsDW223        $renderer->_odtTableAddColumnUseProperties($properties);
75503d18105SLarsDW223
75603d18105SLarsDW223        $renderer->tablerow_open();
75703d18105SLarsDW223
75803d18105SLarsDW223        if (!empty($image)) {
75903d18105SLarsDW223            $properties = array();
76003d18105SLarsDW223            $properties ['vertical-align'] = 'middle';
76103d18105SLarsDW223            $properties ['text-align'] = 'center';
76203d18105SLarsDW223            $properties ['padding'] = '0.1cm';
76303d18105SLarsDW223            $properties ['background-color'] = $background_color;
76403d18105SLarsDW223
76503d18105SLarsDW223            $renderer->_odtTableCellOpenUseProperties($properties);
76603d18105SLarsDW223            $renderer->_odtAddImage($image);
76703d18105SLarsDW223            $renderer->tablecell_close();
76803d18105SLarsDW223        }
76903d18105SLarsDW223
77003d18105SLarsDW223        $properties = array();
77103d18105SLarsDW223        $properties ['vertical-align'] = 'middle';
77203d18105SLarsDW223        $properties ['padding'] = '0.3cm';
77303d18105SLarsDW223        $properties ['background-color'] = $background_color;
77403d18105SLarsDW223        $properties ['border'] = 'none';
77503d18105SLarsDW223        $renderer->_odtTableCellOpenUseProperties($properties);
77603d18105SLarsDW223    }
77703d18105SLarsDW223
77803d18105SLarsDW223    function renderODTCloseTable ($renderer) {
77903d18105SLarsDW223        $renderer->tablecell_close();
78003d18105SLarsDW223        $renderer->tablerow_close();
78103d18105SLarsDW223        $renderer->_odtTableClose();
7821fdcb5a2SLarsDW223        $renderer->_odtCloseTextBox ();
7833b240721SEduardo Mozart de Oliveira        $renderer->p_open();
7843b240721SEduardo Mozart de Oliveira        $renderer->p_close();
78503d18105SLarsDW223
7861fdcb5a2SLarsDW223        self::$table_entr -= 1;
78703d18105SLarsDW223    }
78803d18105SLarsDW223
78903d18105SLarsDW223    protected function getODTCommonStyleName ($class_string) {
79003d18105SLarsDW223        static $map = array (
79103d18105SLarsDW223            'wrap_box' => 'Box', 'wrap_danger' => 'Danger', 'wrap_warning' => 'Warning',
79203d18105SLarsDW223            'wrap_caution' => 'Caution', 'wrap_notice' => 'Notice', 'wrap_safety' => 'Safety',
79303d18105SLarsDW223            'wrap_info' => 'Info', 'wrap_important' => 'Important', 'wrap_alert' => 'Alert',
79403d18105SLarsDW223            'wrap_tip' => 'Tip', 'wrap_help' => 'Help', 'wrap_todo' => 'To do',
79503d18105SLarsDW223            'wrap_download' => 'Download', 'wrap_hi' => 'Highlighted', 'wrap_spoiler' => 'Spoiler',
79603d18105SLarsDW223            'wrap_leftalign' => 'Left aligned', 'wrap_rightalign' => 'Right aligned',
79703d18105SLarsDW223            'wrap_centeralign' => 'Centered', 'wrap_justify' => 'Justify', 'wrap_em' => 'Emphasised',
79803d18105SLarsDW223            'wrap_lo' => 'Less significant');
79903d18105SLarsDW223        $classes = explode(' ', $class_string);
80003d18105SLarsDW223        $name = '';
80103d18105SLarsDW223        foreach ($classes as $class) {
80203d18105SLarsDW223            if (array_key_exists($class, $map)) {
80303d18105SLarsDW223                $name .= $map [$class];
80403d18105SLarsDW223            }
80503d18105SLarsDW223        }
80603d18105SLarsDW223        return ($name);
80703d18105SLarsDW223    }
808778ee21cSAnika Henke}
809