Completed
Push — master ( 90f9c7...f3a861 )
by Mark
11s
created

syntax_plugin_yalist::render_xhtml_item()   C

Complexity

Conditions 21
Paths 21

Size

Total Lines 66
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 66
rs 5.781
cc 21
eloc 64
nc 21
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This plugin extends DokuWiki's list markup syntax to allow definition lists
4
 * and list items with multiple paragraphs. The complete syntax is as follows:
5
 *
6
 *
7
 *   - ordered list item            [<ol><li>]  <!-- as standard syntax -->
8
 *   * unordered list item          [<ul><li>]  <!-- as standard syntax -->
9
 *   ? definition list term         [<dl><dt>]
10
 *   : definition list definition   [<dl><dd>]
11
 *
12
 *   -- ordered list item w/ multiple paragraphs
13
 *   ** unordered list item w/ multiple paragraphs
14
 *   :: definition list definition w/multiple paragraphs
15
 *   .. new paragraph in --, **, or ::
16
 *
17
 *
18
 * Lists can be nested within lists, just as in the standard DokuWiki syntax.
19
 *
20
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
21
 * @author     Ben Slusky <[email protected]>
22
 *
23
 */
24
if (!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
25
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
26
require_once(DOKU_PLUGIN.'syntax.php');
27
class syntax_plugin_yalist extends DokuWiki_Syntax_Plugin {
28
    var $stack = array();
29
    static $odt_table_stack = array();
30
    static $odt_table_stack_index = 0;
31
32
    function getType() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
        return 'container';
34
    }
35
    function getSort() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
        // just before listblock (10)
37
        return 9;
38
    }
39
    function getPType() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
40
        return 'block';
41
    }
42
    function getAllowedTypes() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
43
        return array('substition', 'protected', 'disabled', 'formatting');
44
    }
45
    function connectTo($mode) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
       $this->Lexer->addEntryPattern('\n {2,}(?:--?|\*\*?|\?|::?)', $mode, 'plugin_yalist');
47
       $this->Lexer->addEntryPattern('\n\t{1,}(?:--?|\*\*?|\?|::?)', $mode, 'plugin_yalist');
48
       $this->Lexer->addPattern('\n {2,}(?:--?|\*\*?|\?|::?|\.\.)', 'plugin_yalist');
49
       $this->Lexer->addPattern('\n\t{1,}(?:--?|\*\*?|\?|::?|\.\.)', 'plugin_yalist');
50
    }
51
    function postConnect() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
52
        $this->Lexer->addExitPattern('\n', 'plugin_yalist');
53
    }
54
    function handle($match, $state, $pos, Doku_Handler $handler) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
        $output = array();
56
        $level = 0;
57
        switch ($state) {
58
        case DOKU_LEXER_ENTER:
59
            $frame = $this->_interpret_match($match);
60
            $level = $frame['level'] = 1;
61
            array_push($output,
62
                       "${frame['list']}_open",
63
                       "${frame['item']}_open",
64
                       "${frame['item']}_content_open");
65
            if ($frame['paras'])
66
                array_push($output, 'p_open');
67
            array_push($this->stack, $frame);
68
            break;
69
        case DOKU_LEXER_EXIT:
70
            $close_content = true;
71
            while ($frame = array_pop($this->stack)) {
72
                // for the first frame we pop off the stack, we'll need to
73
                // close the content tag; for the rest it will have been
74
                // closed already
75
                if ($close_content) {
76
                    if ($frame['paras'])
77
                        array_push($output, 'p_close');
78
                    array_push($output, "${frame['item']}_content_close");
79
                    $close_content = false;
80
                }
81
                array_push($output,
82
                           "${frame['item']}_close",
83
                           "${frame['list']}_close");
84
            }
85
            break;
86
        case DOKU_LEXER_MATCHED:
87
            $last_frame = end($this->stack);
88
            if (substr($match, -2) == '..') {
89
                // new paragraphs cannot be deeper than the current depth,
90
                // but they may be shallower
91
                $para_depth = count(explode('  ', str_replace("\t", '  ', $match)));
92
                $close_content = true;
93 View Code Duplication
                while ($para_depth < $last_frame['depth'] && count($this->stack) > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
                    if ($close_content) {
95
                        if ($last_frame['paras'])
96
                            array_push($output, 'p_close');
97
                        array_push($output, "${last_frame['item']}_content_close");
98
                        $close_content = false;
99
                    }
100
                    array_push($output,
101
                               "${last_frame['item']}_close",
102
                               "${last_frame['list']}_close");
103
                    array_pop($this->stack);
104
                    $last_frame = end($this->stack);
105
                }
106
                if ($last_frame['paras']) {
107
                    if ($close_content)
108
                        // depth did not change
109
                        array_push($output, 'p_close', 'p_open');
110
                    else
111
                        array_push($output,
112
                                   "${last_frame['item']}_content_open",
113
                                   'p_open');
114
                } else {
115
                    // let's just pretend we didn't match...
116
                    $state = DOKU_LEXER_UNMATCHED;
117
                    $output = $match;
118
                }
119
                break;
120
            }
121
            $curr_frame = $this->_interpret_match($match);
122
            if ($curr_frame['depth'] > $last_frame['depth']) {
123
                // going one level deeper
124
                $level = $last_frame['level'] + 1;
125
                if ($last_frame['paras'])
126
                    array_push($output, 'p_close');
127
                array_push($output,
128
                           "${last_frame['item']}_content_close",
129
                           "${curr_frame['list']}_open");
130
            } else {
131
                // same depth, or getting shallower
132
                $close_content = true;
133
                // keep popping frames off the stack until we find a frame
134
                // that's at least as deep as this one, or until only the
135
                // bottom frame (i.e. the initial list markup) remains
136 View Code Duplication
                while ($curr_frame['depth'] < $last_frame['depth'] &&
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
                       count($this->stack) > 1)
138
                {
139
                    // again, we need to close the content tag only for
140
                    // the first frame popped off the stack
141
                    if ($close_content) {
142
                        if ($last_frame['paras'])
143
                            array_push($output, 'p_close');
144
                        array_push($output, "${last_frame['item']}_content_close");
145
                        $close_content = false;
146
                    }
147
                    array_push($output,
148
                               "${last_frame['item']}_close",
149
                               "${last_frame['list']}_close");
150
                    array_pop($this->stack);
151
                    $last_frame = end($this->stack);
152
                }
153
                // pull the last frame off the stack;
154
                // it will be replaced by the current frame
155
                array_pop($this->stack);
156
                $level = $last_frame['level'];
157
                if ($close_content) {
158
                    if ($last_frame['paras'])
159
                        array_push($output, 'p_close');
160
                    array_push($output, "${last_frame['item']}_content_close");
161
                    $close_content = false;
0 ignored issues
show
Unused Code introduced by
$close_content is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
162
                }
163
                array_push($output, "${last_frame['item']}_close");
164
                if ($curr_frame['list'] != $last_frame['list']) {
165
                    // change list types
166
                    array_push($output,
167
                               "${last_frame['list']}_close",
168
                               "${curr_frame['list']}_open");
169
                }
170
            }
171
            // and finally, open tags for the new list item
172
            array_push($output,
173
                       "${curr_frame['item']}_open",
174
                       "${curr_frame['item']}_content_open");
175
            if ($curr_frame['paras'])
176
                array_push($output, 'p_open');
177
            $curr_frame['level'] = $level;
178
            array_push($this->stack, $curr_frame);
179
            break;
180
        case DOKU_LEXER_UNMATCHED:
181
            $output = $match;
182
            break;
183
        }
184
        return array('state' => $state, 'output' => $output, 'level' => $level);
185
    }
186
    function _interpret_match($match) {
187
        $tag_table = array(
188
            '*' => 'u_li',
189
            '-' => 'o_li',
190
            '?' => 'dt',
191
            ':' => 'dd',
192
        );
193
        $tag = $tag_table[substr($match, -1)];
194
        return array(
195
            'depth' => count(explode('  ', str_replace("\t", '  ', $match))),
196
            'list' => substr($tag, 0, 1) . 'l',
197
            'item' => substr($tag, -2),
198
            'paras' => (substr($match, -1) == substr($match, -2, 1)),
199
        );
200
    }
201
202
    function render($mode, Doku_Renderer $renderer, $data) {
203
        if ($mode != 'xhtml' && $mode != 'latex' && $mode != 'odt')
204
            return false;
205
        if ($data['state'] == DOKU_LEXER_UNMATCHED) {
206
            if ($mode != 'odt') {
207
                $renderer->doc .= $renderer->_xmlEntities($data['output']);
208
            } else {
209
                $renderer->cdata($data['output']);
210
            }
211
            return true;
212
        }
213
        foreach ($data['output'] as $i) {
214
            switch ($mode) {
215
                case 'xhtml':
216
                    $this->render_xhtml_item($renderer, $i, $data);
217
                break;
218
                case 'latex':
219
                    $this->render_latex_item($renderer, $i, $data);
220
                break;
221
                case 'odt':
222
                    $this->render_odt_item($renderer, $i, $data);
223
                break;
224
            }
225
        }
226
        if ($data['state'] == DOKU_LEXER_EXIT) {
227
            if ($mode != 'odt') {
228
                $renderer->doc .= "\n";
229
            } else {
230
                $renderer->linebreak();
231
            }
232
        }
233
        return true;
234
    }
235
236
    function render_xhtml_item(Doku_Renderer $renderer, $item) {
237
        $markup = '';
238
        switch ($item) {
239
        case 'ol_open':
240
            $markup = "<ol>\n";
241
            break;
242
        case 'ol_close':
243
            $markup = "</ol>\n";
244
            break;
245
        case 'ul_open':
246
            $markup = "<ul>\n";
247
            break;
248
        case 'ul_close':
249
            $markup = "</ul>\n";
250
            break;
251
        case 'dl_open':
252
            $markup = "<dl>\n";
253
            break;
254
        case 'dl_close':
255
            $markup = "</dl>\n";
256
            break;
257
        case 'li_open':
258
            $markup = "<li class=\"level${data['level']}\">";
0 ignored issues
show
Bug introduced by
The variable $data does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
259
            break;
260
        case 'li_content_open':
261
            $markup = "<div class=\"li\">\n";
262
            break;
263
        case 'li_content_close':
264
            $markup = "\n</div>";
265
            break;
266
        case 'li_close':
267
            $markup = "</li>\n";
268
            break;
269
        case 'dt_open':
270
            $markup = "<dt class=\"level${data['level']}\">";
271
            break;
272
        case 'dt_content_open':
273
            $markup = "<span class=\"dt\">";
274
            break;
275
        case 'dt_content_close':
276
            $markup = "</span>";
277
            break;
278
        case 'dt_close':
279
            $markup = "</dt>\n";
280
            break;
281
        case 'dd_open':
282
            $markup = "<dd class=\"level${data['level']}\">";
283
            break;
284
        case 'dd_content_open':
285
            $markup = "<div class=\"dd\">\n";
286
            break;
287
        case 'dd_content_close':
288
            $markup = "\n</div>";
289
            break;
290
        case 'dd_close':
291
            $markup = "</dd>\n";
292
            break;
293
        case 'p_open':
294
            $markup = "<p>\n";
295
            break;
296
        case 'p_close':
297
            $markup = "\n</p>";
298
            break;
299
        }
300
        $renderer->doc .= $markup;
301
    }
302
303
    function render_latex_item(Doku_Renderer $renderer, $item) {
304
        $markup = '';
305
        switch ($i) {
0 ignored issues
show
Bug introduced by
The variable $i does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
306
        case 'ol_open':
307
            $markup = "\\begin{enumerate}\n";
308
            break;
309
        case 'ol_close':
310
            $markup = "\\end{enumerate}\n";
311
            break;
312
        case 'ul_open':
313
            $markup = "\\begin{itemize}\n";
314
            break;
315
        case 'ul_close':
316
            $markup = "\\end{itemize}\n";
317
            break;
318
        case 'dl_open':
319
            $markup = "\\begin{description}\n";
320
            break;
321
        case 'dl_close':
322
            $markup = "\\end{description}\n";
323
            break;
324
        case 'li_open':
325
            $markup = "\item ";
326
            break;
327
        case 'li_content_open':
328
            break;
329
        case 'li_content_close':
330
            break;
331
        case 'li_close':
332
            $markup = "\n";
333
            break;
334
        case 'dt_open':
335
            $markup = "\item[";
336
            break;
337
        case 'dt_content_open':
338
            break;
339
        case 'dt_content_close':
340
            break;
341
        case 'dt_close':
342
            $markup = "] ";
343
            break;
344
        case 'dd_open':
345
            break;
346
        case 'dd_content_open':
347
            break;
348
        case 'dd_content_close':
349
            break;
350
        case 'dd_close':
351
            $markup = "\n";
352
            break;
353
        case 'p_open':
354
            $markup = "\n";
355
            break;
356
        case 'p_close':
357
            $markup = "\n";
358
            break;
359
        }
360
        $renderer->doc .= $markup;
361
    }
362
363
    /**
364
     * Render yalist items for ODT format
365
     *
366
     * @param Doku_Renderer $renderer  The current renderer object
367
     * @param string        $item      The item to render
368
     *
369
     * @author LarsDW223
370
     */
371
    function render_odt_item(Doku_Renderer $renderer, $item) {
372
        switch ($item) {
373
        case 'ol_open':
374
            $renderer->listo_open();
375
            break;
376
        case 'ul_open':
377
            $renderer->listu_open();
378
            break;
379
        case 'dl_open':
380
            if ($this->getConf('def_list_odt_export') != 'table') {
381
                $renderer->listu_open();
382
            } else {
383
                $renderer->table_open(2);
384
            }
385
            self::$odt_table_stack [self::$odt_table_stack_index] = array();
386
            self::$odt_table_stack [self::$odt_table_stack_index]['itemOpen'] = false;
387
            self::$odt_table_stack [self::$odt_table_stack_index]['dtState'] = 0;
388
            self::$odt_table_stack [self::$odt_table_stack_index]['ddState'] = 0;
389
            self::$odt_table_stack_index++;
390
            break;
391
        case 'ol_close':
392
        case 'ul_close':
393
            $renderer->list_close();
394
            break;
395
        case 'dl_close':
396
            $config = $this->getConf('def_list_odt_export');
397
            if ($config != 'table') {
398
                if (self::$odt_table_stack [self::$odt_table_stack_index-1]['ddState'] != 2) {
399
                    if ($config == 'listheader' && method_exists ($renderer, 'listheader_close')) {
400
                        $renderer->listheader_close();
401
                    } else {
402
                        $renderer->listitem_close();
403
                    }
404
                }
405
                self::$odt_table_stack [self::$odt_table_stack_index-1]['ddState'] = 0;
406
                $renderer->list_close();
407
            } else {
408 View Code Duplication
                if (self::$odt_table_stack [self::$odt_table_stack_index-1]['ddState'] == 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
409
                    $properties = array();
410
                    $properties ['border'] = 'none';
411
                    $renderer->_odtTableCellOpenUseProperties($properties);
412
                    $renderer->tablecell_close();
413
                }
414
                self::$odt_table_stack [self::$odt_table_stack_index-1]['ddState'] = 0;
415
                if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === true) {
416
                    $renderer->tablerow_close(1);
417
                    self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = false;
418
                }
419
                $renderer->table_close();
420
            }
421
            if (self::$odt_table_stack_index > 0) {
422
                self::$odt_table_stack_index--;
423
                unset(self::$odt_table_stack [self::$odt_table_stack_index]);
424
            }
425
            break;
426
427
        case 'li_open':             
428
            $renderer->listitem_open(1);
429
            break;
430
        case 'li_content_open':
431
            $renderer->listcontent_open();
432
            break;
433
        case 'li_content_close':    
434
            $renderer->listcontent_close();
435
            break;
436
        case 'li_close':
437
            $renderer->listitem_close();
438
            break;
439
440
        case 'dt_open': // unconditional: DT tags can't contain paragraphs. That would not be legal XHTML.
441
            switch ($this->getConf('def_list_odt_export')) {
442
                case 'listheader':
443
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === true) {
444
                        if (method_exists ($renderer, 'listheader_close')) {
445
                            $renderer->listheader_close();
446
                        } else {
447
                            $renderer->listitem_close();
448
                        }
449
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = false;
450
                    }
451
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === false) {
452
                        if (method_exists ($renderer, 'listheader_open')) {
453
                            $renderer->listheader_open(1);
454
                        } else {
455
                            $renderer->listitem_open(1);
456
                        }
457
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = true;
458
                    }
459
                break;
460
                case 'table':
461 View Code Duplication
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['ddState'] == 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
462
                        $properties = array();
463
                        $properties ['border'] = 'none';
464
                        $renderer->_odtTableCellOpenUseProperties($properties);
465
                        $renderer->tablecell_close();
466
                    }
467
468
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === true) {
469
                        $renderer->tablerow_close();
470
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = false;
471
                    }
472
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === false) {
473
                        $renderer->tablerow_open(1);
474
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = true;
475
                    }
476
                    $properties = array();
477
                    $properties ['border'] = 'none';
478
                    $renderer->_odtTableCellOpenUseProperties($properties);
479
                break;
480
                default:
481
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === true) {
482
                        $renderer->listitem_close();
483
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = false;
484
                    }
485
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === false) {
486
                        $renderer->listitem_open(1);
487
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = true;
488
                    }
489
                break;
490
            }
491
            self::$odt_table_stack [self::$odt_table_stack_index-1]['dtState'] = 1;
492
            self::$odt_table_stack [self::$odt_table_stack_index-1]['ddState'] = 0;
493
            break;
494
        case 'dd_open':
495
            switch ($this->getConf('def_list_odt_export')) {
496 View Code Duplication
                case 'listheader':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
497
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === false) {
498
                        if (method_exists ($renderer, 'listheader_open')) {
499
                            $renderer->listheader_open(1);
500
                        } else {
501
                            $renderer->listitem_open(1);
502
                        }
503
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = true;
504
                    }
505
                break;
506
                case 'table':
507
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === false) {
508
                        $renderer->tablerow_open(1);
509
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = true;
510
                    }
511
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['dtState'] == 1) {
512
                        $renderer->tablecell_close();
513
                    }
514 View Code Duplication
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['dtState'] == 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
515
                        $properties = array();
516
                        $properties ['border'] = 'none';
517
                        $renderer->_odtTableCellOpenUseProperties($properties);
518
                        $renderer->tablecell_close();
519
                    }
520
521
                    $properties = array();
522
                    $properties ['border'] = 'none';
523
                    $renderer->_odtTableCellOpenUseProperties($properties);
524
                break;
525 View Code Duplication
                default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
526
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === false) {
527
                        $renderer->listitem_open(1);
528
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = true;
529
                    }
530
                break;
531
            }
532
            self::$odt_table_stack [self::$odt_table_stack_index-1]['dtState'] = 0;
533
            self::$odt_table_stack [self::$odt_table_stack_index-1]['ddState'] = 1;
534
            break;
535
        case 'dt_content_open':
536
            switch ($this->getConf('def_list_odt_export')) {
537
                case 'table':
538
                    $renderer->p_open();
539
                break;
540
                default:
541
                    $renderer->listcontent_open();
542
                break;
543
            }
544
            $this->renderODTOpenSpan($renderer);
545
            break;
546
        case 'dd_content_open':
547
            switch ($this->getConf('def_list_odt_export')) {
548
                case 'table':
549
                    $renderer->p_open();
550
                break;
551
                default:
552
                    $renderer->listcontent_open();
553
                break;
554
            }
555
            break;
556
        case 'dt_content_close':
557
            $this->renderODTCloseSpan($renderer);
558
            switch ($this->getConf('def_list_odt_export')) {
559
                case 'table':
560
                    $renderer->p_close();
561
                break;
562
                default:
563
                    $renderer->listcontent_close();
564
                break;
565
            }
566
            break;
567
        case 'dd_content_close':
568
            switch ($this->getConf('def_list_odt_export')) {
569
                case 'table':
570
                    $renderer->p_close();
571
                break;
572
                default:
573
                    $renderer->listcontent_close();
574
                break;
575
            }
576
            break;
577
        case 'dt_close':
578
            switch ($this->getConf('def_list_odt_export')) {
579
                case 'listheader':
580
                    $renderer->linebreak();
581
                    break;
582
                case 'table':
583
                    $renderer->tablecell_close();
584
                    self::$odt_table_stack [self::$odt_table_stack_index-1]['dtState'] = 2;
585
                    break;
586
                default:
587
                    $renderer->linebreak();
588
                    break;
589
            }
590
            break;
591
592
        case 'dd_close':
593
            switch ($this->getConf('def_list_odt_export')) {
594 View Code Duplication
                case 'listheader':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
595
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === true) {
596
                        if (method_exists ($renderer, 'listheader_close')) {
597
                            $renderer->listheader_close();
598
                        } else {
599
                            $renderer->listitem_close();
600
                        }
601
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = false;
602
                    }
603
                    break;
604
                case 'table':
605
                    $renderer->tablecell_close();
606
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === true) {
607
                        $renderer->tablerow_close(1);
608
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = false;
609
                    }
610
                    break;
611 View Code Duplication
                default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
612
                    if (self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] === true) {
613
                        $renderer->listitem_close(1);
614
                        self::$odt_table_stack [self::$odt_table_stack_index-1]['itemOpen'] = false;
615
                    }
616
                    break;
617
            }
618
            self::$odt_table_stack [self::$odt_table_stack_index-1]['dtState'] = 0;
619
            self::$odt_table_stack [self::$odt_table_stack_index-1]['ddState'] = 2;
620
            break;
621
622
        case 'p_open':
623
            $renderer->p_open();
624
            break;
625
        case 'p_close':
626
            $renderer->p_close();
627
            break;
628
        }
629
    }
630
631
    /**
632
     * Open ODT span for rendering of dt-content
633
     *
634
     * @param Doku_Renderer $renderer  The current renderer object
635
     *
636
     * @author LarsDW223
637
     */
638
    function renderODTOpenSpan ($renderer) {
639
        $properties = array ();
640
641
        // Get CSS properties for ODT export.
642
        $renderer->getODTProperties ($properties, 'div', 'dokuwiki dt', NULL);
643
644
        $renderer->_odtSpanOpenUseProperties($properties);
645
    }
646
647
    /**
648
     * Close ODT span for rendering of dt-content
649
     *
650
     * @param Doku_Renderer $renderer  The current renderer object
651
     *
652
     * @author LarsDW223
653
     */
654
    function renderODTCloseSpan ($renderer) {
655
        if ( method_exists ($renderer, '_odtSpanClose') === false ) {
656
            // Function is not supported by installed ODT plugin version, return.
657
            return;
658
        }
659
        $renderer->_odtSpanClose();
660
    }
661
}
662