1<?php
2if(!defined('DOKU_INC')) die();
3if(!defined('DOKU_PLUGIN')) die();
4if(!defined('ABBR_CONF')) define('ABBR_CONF',DOKU_INC.'/conf/acronyms.local.conf');
5
6require_once(DOKU_PLUGIN.'admin.php');
7
8/**
9 * All DokuWiki plugins to extend the admin function
10 * need to inherit from this class
11 */
12class admin_plugin_acronymedit extends DokuWiki_Admin_Plugin {
13
14    /**
15     * Constructor
16     */
17    function admin_plugin_acronymedit() {
18        $this->setupLocale();
19    }
20
21    /**
22     * return some info
23     */
24    function getInfo() {
25        $parts = explode('_',get_class($this));
26        $file  = DOKU_PLUGIN.'/'.$parts[2].'/plugin.info.txt';
27        $info  = array();
28        if(!@file_exists($file)) {
29            trigger_error('getInfo() not implemented in '.get_class($this).' and '.$info.' not found', E_USER_WARNING);
30        }
31        else {
32            $info= confToHash($file);
33            $lang= explode(',', $info['lang']);
34            if (in_array('desc', $lang) && ''!==$this->getLang('plugininfo_desc')) $info['desc']= $this->getLang('plugininfo_desc');
35        }
36        return $info;
37    }
38
39    /**
40     * return prompt for admin menu
41     */
42    function getMenuText($language) {
43      if (!$this->disabled)
44        return parent::getMenuText($language);
45      return '';
46    }
47
48    /**
49     * return sort order for position in admin menu
50     */
51    function getMenuSort() {
52        return 4129;
53    }
54
55    /**
56     * handle user request
57     */
58    function handle() {
59    }
60
61    /**
62     * output appropriate html
63     */
64    function html() {
65      global $lang;
66      global $conf;
67
68      print "<h1>".$this->getLang('abbr_title')."</h1>";
69      print $this->getLang('abbr_text');
70      print "<br /><br />";
71
72      if (isset($_POST['saver']) && $_POST['saver']==1) {
73        $ok=true;
74        $ok = $ok & $this->writeFile(ABBR_CONF, $_POST['abbr']);
75
76        if ($ok) {
77          print "<form name=\"message_form\" method=\"POST\"><input type=\"hidden\" name=\"saver\" value=\"0\" /></form>";
78          print "<script>document.forms['message_form'].submit();</script>";
79        }
80        else {
81          msg("<b>".$this->getLang('abbr_error')."</b>",-1);
82          print "<br />";
83        }
84      }
85
86      print "<form method=\"POST\">";
87      print "<input type=\"hidden\" name=\"saver\" value=\"1\" />";
88
89      print "<h3>".$this->getLang('abbr_list')."</h3>";
90      print "<textarea name=\"abbr\" style=\"width:100%; height:20em;\">";
91      print @file_get_contents(ABBR_CONF);
92      print "</textarea>";
93      print "<br /><br />";
94
95      print "<input type=\"submit\" value=\"".$this->getLang('abbr_save')."\" title=\"".$this->getLang('abbr_save')." [S]\" accesskey=\"s\" />";
96      print "</form>";
97
98    }
99
100    function writeFile($filename,$chaine) {
101      //if (is_writable($filename)) {
102      if (is_writable( $filename ) || (is_writable(dirname( $filename ).'/.') && !file_exists( $filename ))) {
103        if (!$handle = fopen($filename, 'w')) {
104          msg($this->getLang('abbr_err_open')." ($filename).",-1);
105          return false;
106        }
107
108        if (fwrite($handle, $chaine) === FALSE) {
109          msg($this->getLang('abbr_err_write')." ($filename).",-1);
110          return false;
111        }
112
113        fclose($handle);
114        return true;
115
116    } else {
117      msg($this->getLang('abbr_err_secure')." ($filename).",-1);
118      return false;
119    }
120  }
121}
122// vim:ts=4:sw=4:et:enc=utf-8:
123