Completed
Push — master ( bf6f54...20dc95 )
by Andreas
03:16
created

Preview::tplContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Action;
4
5
/**
6
 * Class Preview
7
 *
8
 * preview during editing
9
 *
10
 * @package dokuwiki\Action
11
 */
12
class Preview extends Edit {
13
14
    /** @inheritdoc */
15
    public function preProcess() {
16
        header('X-XSS-Protection: 0');
17
        $this->savedraft();
18
        parent::preProcess();
19
    }
20
21
    /** @inheritdoc */
22
    public function tplContent() {
23
        global $TEXT;
24
        html_edit();
25
        html_show($TEXT);
26
    }
27
28
    /**
29
     * Saves a draft on preview
30
     */
31
    protected function savedraft() {
32
        global $INFO;
33
        global $ID;
34
        global $INPUT;
35
        global $conf;
36
37
        if(!$conf['usedraft']) return;
38
        if(!$INPUT->post->has('wikitext')) return;
39
40
        // ensure environment (safeguard when used via AJAX)
41
        assert(isset($INFO['client']), 'INFO.client should have been set');
42
        assert(isset($ID), 'ID should have been set');
43
44
        $draft = array(
45
            'id' => $ID,
46
            'prefix' => substr($INPUT->post->str('prefix'), 0, -1),
47
            'text' => $INPUT->post->str('wikitext'),
48
            'suffix' => $INPUT->post->str('suffix'),
49
            'date' => $INPUT->post->int('date'),
50
            'client' => $INFO['client'],
51
        );
52
        $cname = getCacheName($draft['client'] . $ID, '.draft');
53
        if(io_saveFile($cname, serialize($draft))) {
54
            $INFO['draft'] = $cname;
55
        }
56
    }
57
58
}
59