summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/bureaucracy/helper/action.php
blob: 5c6dd08b375608b1ebaa78cb11f6fea1093b633e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
 * Base class for bureaucracy actions.
 *
 * All bureaucracy actions have to inherit from this class.
 *
 * ATM this class is pretty empty but, in the future it could be used to add
 * helper functions which can be utilized by the different actions.
 *
 * @author Michael Klier <chi@chimeric.de>
 */
class helper_plugin_bureaucracy_action extends syntax_plugin_bureaucracy {

    /**
     * Return false to prevent DokuWiki reusing instances of the plugin
     *
     * @return bool
     */
    public function isSingleton() {
        return false;
    }

    /**
     * Handle the user input [required]
     *
     * This function needs to be implemented to accept the user data collected
     * from the form. Data has to be grabbed from $_POST['bureaucracy'] using
     * the indicies in the 'idx' members of the $data items.
     *
     * @param helper_plugin_bureaucracy_field[] $fields the list of fields in the form
     * @param string                            $thanks the thank you message as defined in the form
     *                                                  or default one. Might be modified by the action
     *                                                  before returned
     * @param array                             $argv   additional arguments passed to the action
     * @return bool|string false on error, $thanks on success
     */
    public function run($fields, $thanks, $argv){
        msg('ERROR: called action %s did not implement a run() function');
        return false;
    }

    /**
     * Adds some language related replacement patterns
     */
    function prepareLanguagePlaceholder() {
        global $ID;
        global $conf;

        $this->patterns['__lang__'] = '/@LANG@/';
        $this->values['__lang__'] = $conf['lang'];

        $this->patterns['__trans__'] = '/@TRANS@/';
        $this->values['__trans__'] = '';

        /** @var helper_plugin_translation $trans */
        $trans = plugin_load('helper', 'translation');
        if (!$trans) return;

        $this->values['__trans__'] = $trans->getLangPart($ID);
        $this->values['__lang__'] = $trans->realLC('');
    }

    /**
     * Adds replacement pattern for fieldlabels (e.g @@Label@@)
     *
     * @param helper_plugin_bureaucracy_field $field
     */
    function prepareFieldReplacement($field) {
        $label = $field->getParam('label');

        if(!is_null($label)) {
            $this->patterns[$label] = $field->getReplacementPattern();
            $this->values[$label] = $field->getReplacementValue();
        }
    }

    /**
     * Adds <noinclude></noinclude> to replacement patterns
     */
    function prepareNoincludeReplacement() {
        $this->patterns['__noinclude__'] = '/<noinclude>(.*?)<\/noinclude>/is';
        $this->values['__noinclude__'] = '';
    }

    /**
     * Generate field replacements
     *
     * @param helper_plugin_bureaucracy_field[]  $fields  List of field objects
     * @return array
     */
    function prepareFieldReplacements($fields) {
        foreach ($fields as $field) {
            //field replacements
            $this->prepareFieldReplacement($field);
        }
    }

    /**
     * Returns ACL access level of the user or the (virtual) 'runas' user
     *
     * @param string $id pageid
     * @return int
     */
    protected function aclcheck($id) {
        $runas = $this->getConf('runas');

        if($runas) {
            $auth = auth_aclcheck($id, $runas, array());
        } else {
            $auth = auth_quickaclcheck($id);
        }
        return $auth;

    }

    /**
     * Available methods
     *
     * @return array
     */
    public function getMethods() {
        $result = array();
        $result[] = array(
            'name' => 'run',
            'desc' => 'Handle the user input',
            'params' => array(
                'fields' => 'helper_plugin_bureaucracy_field[]',
                'thanks' => 'string',
                'argv'   => 'array'
            ),
            'return' => array('false on error, thanks message on success' => 'bool|string')
        );
        return $result;
    }

}