1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Pierre Spring <pierre.spring@liip.ch>
5 */
6
7// must be run within Dokuwiki
8if (!defined('DOKU_INC')) die();
9
10class helper_plugin_npd extends DokuWiki_Plugin
11{
12
13    function getInfo()
14    {
15        return confToHash(dirname(__FILE__).'/plugin.info.txt');
16    }
17
18    function getMethods()
19    {
20        $result = array();
21        $result[] = array(
22            'name'   => 'html_new_page_button',
23            'desc'   => 'include a html button',
24            'params' => array(),
25            'return' => array()
26        );
27        return $result;
28    }
29
30    function html_new_page_button($return = false)
31    {
32        global $conf;
33        global $ID;
34
35        /* don't show the button if the user doesn't have edit permissions */
36        if(auth_quickaclcheck($ID) < AUTH_EDIT) {
37            return '';
38        }
39
40        $label = $this->getLang('btn_create_new_page');
41        if (!$label) {
42            // needs translation ;)
43            $label = 'Create New Page';
44        }
45
46        $tip = htmlspecialchars($label);
47
48        $ret = '';
49
50        //filter id (without urlencoding)
51        $id = idfilter($ID,false);
52
53
54        //make nice URLs even for buttons
55        if($conf['userewrite'] == 2){
56            $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id . "?";
57        }elseif($conf['userewrite']){
58            $script = DOKU_BASE.$id."?";
59        }else{
60            $script = DOKU_BASE.DOKU_SCRIPT . "?";
61            $params['id'] = $id;
62        }
63        $params['idx'] = ":" . getNS($ID);
64        $params['npd'] = 1;
65
66        $url = $script;
67
68        if(is_array($params)){
69            reset($params);
70            while (list($key, $val) = each($params)) {
71                $url .= $key.'=';
72                $url .= htmlspecialchars($val.'&');
73            }
74        }
75
76        $link_type = $this->getConf('link_type');
77
78        switch ($link_type) {
79        case 'link':
80            $ret .= '<a rel="nofollow" href="'.$url.'" style="display:none;" id="npd_create_button" class="action npd">'.$label.'</a>';
81            break;
82        default:
83            $ret .= '<form class="button" action="'.$url.'"><div class="no">';
84            $ret .= '<input id="npd_create_button" type="submit" value="'.htmlspecialchars($label).'" class="button" ';
85            $ret .= 'title="'.$tip.'" ';
86            // the button will be enabled by js, as it does not
87            // make any sense in a browser without js ;)
88            $ret .= 'style="display: none;" ';
89            $ret .= '/>';
90            $ret .= '</div>';
91            $ret .= '</form>';
92        }
93
94        if ($return) {
95            return $ret;
96        } else {
97            echo $ret;
98        }
99    }
100}
101
102