dokuwiki-indexmenu-plugin – Diff between revs 1 and 3

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 1 Rev 3
1 <?php 1 <?php
2 /** 2 /**
3 * Indexmenu Admin Plugin: Indexmenu Component. 3 * Indexmenu Admin Plugin: Indexmenu Component.
4 * 4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Samuele Tognini <samuele@samuele.netsons.org> 6 * @author Samuele Tognini <samuele@samuele.netsons.org>
7 */ 7 */
8   8  
9 if(!defined('DOKU_INC')) die(); 9 if(!defined('DOKU_INC')) die();
10   -  
11 require_once (DOKU_INC.'inc/HTTPClient.php'); 10  
12 require_once(DOKU_PLUGIN."indexmenu/inc/pclzip.lib.php"); 11 require_once(DOKU_PLUGIN."indexmenu/inc/pclzip.lib.php");
13   12  
14 if(!defined('INDEXMENU_IMG_ABSDIR')) define('INDEXMENU_IMG_ABSDIR', DOKU_PLUGIN."indexmenu/images"); 13 if(!defined('INDEXMENU_IMG_ABSDIR')) define('INDEXMENU_IMG_ABSDIR', DOKU_PLUGIN."indexmenu/images");
15 define('INDEXMENU_ICOS', 'base,folder,folderopen,folderh,folderhopen,page,plus,minus,nolines_plus,nolines_minus,minusbottom,plusbottom,join,joinbottom,line,empty'); 14 define('INDEXMENU_ICOS', 'base,folder,folderopen,folderh,folderhopen,page,plus,minus,nolines_plus,nolines_minus,minusbottom,plusbottom,join,joinbottom,line,empty');
16   15  
17 class admin_plugin_indexmenu extends DokuWiki_Admin_Plugin { 16 class admin_plugin_indexmenu extends DokuWiki_Admin_Plugin {
18 var $req = 'fetch'; 17 var $req = 'fetch';
19 var $repos = array( 18 var $repos = array(
20 "url" => array(DOKU_URL), 19 "url" => array(DOKU_URL),
21 "status" => array(""), 20 "status" => array(""),
22 ); 21 );
23   22  
24 var $selected = -1; 23 var $selected = -1;
25   24  
26 /** 25 /**
27 * return sort order for position in admin menu 26 * return sort order for position in admin menu
28 */ 27 */
29 function getMenuSort() { 28 function getMenuSort() {
30 return 999; 29 return 999;
31 } 30 }
32   31  
33 /** 32 /**
34 * handle user request 33 * handle user request
35 */ 34 */
36 function handle() { 35 function handle() {
37 $url = "http://samuele.netsons.org/dokuwiki"; 36 $url = "http://samuele.netsons.org/dokuwiki";
38 if(empty($url)) { 37 if(empty($url)) {
39 $this->repos['url'][] = $this->getLang('no_repos'); 38 $this->repos['url'][] = $this->getLang('no_repos');
40 $this->repos['status'][] = "disabled"; 39 $this->repos['status'][] = "disabled";
41 $this->repos['install'][] = -1; 40 $this->repos['install'][] = -1;
42 } else { 41 } else {
43 $this->repos['url'] = array_merge($this->repos['url'], explode(',', $url)); 42 $this->repos['url'] = array_merge($this->repos['url'], explode(',', $url));
44 } 43 }
45   44  
46 if(!isset($_REQUEST['req'])) return; // first time - nothing to do 45 if(!isset($_REQUEST['req'])) return; // first time - nothing to do
47 $this->req = $_REQUEST['req']; 46 $this->req = $_REQUEST['req'];
48   47  
49 if(is_numeric($_REQUEST['repo'])) $this->selected = $_REQUEST['repo']; 48 if(is_numeric($_REQUEST['repo'])) $this->selected = $_REQUEST['repo'];
50 } 49 }
51   50  
52 /** 51 /**
53 * output appropriate html 52 * output appropriate html
54 */ 53 */
55 function html() { 54 function html() {
56 global $conf; 55 global $conf;
57 ptln('<div id="config__manager">'); 56 ptln('<div id="config__manager">');
58 ptln(' <h1>'.$this->getLang('menu').'</h1>'); 57 ptln(' <h1>'.$this->getLang('menu').'</h1>');
59 ptln($this->_donate()); 58 ptln($this->_donate());
60 ptln(' <fieldset>'); 59 ptln(' <fieldset>');
61 ptln(' <legend>'.$this->getLang('checkupdates').'</legend>'); 60 ptln(' <legend>'.$this->getLang('checkupdates').'</legend>');
62 $this->_form_open("checkupdates"); 61 $this->_form_open("checkupdates");
63 $this->_form_close('check'); 62 $this->_form_close('check');
64 if($this->req == 'checkupdates') { 63 if($this->req == 'checkupdates') {
65 $this->_checkupdates(); 64 $this->_checkupdates();
66 } 65 }
67 ptln(' </fieldset>'); 66 ptln(' </fieldset>');
68 ptln(' <fieldset>'); 67 ptln(' <fieldset>');
69 ptln(' <legend>Themes</legend>'); 68 ptln(' <legend>Themes</legend>');
70 ptln(' <table class="inline">'); 69 ptln(' <table class="inline">');
71 ptln(' <tr class="default"><td class="label" colspan="2">'); 70 ptln(' <tr class="default"><td class="label" colspan="2">');
72 ptln(' <span class="outkey">'.$this->getLang('infos').'</span>'); 71 ptln(' <span class="outkey">'.$this->getLang('infos').'</span>');
73 ptln(' </td></tr>'); 72 ptln(' </td></tr>');
74 $n = 0; 73 $n = 0;
75 //cycles thru repositories urls 74 //cycles thru repositories urls
76 foreach($this->repos['url'] as $url) { 75 foreach($this->repos['url'] as $url) {
77 ptln(' <tr class="search_hit"><td>'); 76 ptln(' <tr class="search_hit"><td>');
78 $legend = ($n == 0) ? $conf['title'] : $this->repos['url'][$n]; 77 $legend = ($n == 0) ? $conf['title'] : $this->repos['url'][$n];
79 ptln(' <span><label><strong>'.$legend.'</strong></label></span>'); 78 ptln(' <span><label><strong>'.$legend.'</strong></label></span>');
80 ptln(' </td>'); 79 ptln(' </td>');
81 ptln(' <td class="value">'); 80 ptln(' <td class="value">');
82 $this->_form_open("fetch", $n); 81 $this->_form_open("fetch", $n);
83 $this->_form_close("fetch"); 82 $this->_form_close("fetch");
84 ptln(' </td></tr>'); 83 ptln(' </td></tr>');
85 //list requested theme 84 //list requested theme
86 if($n == $this->selected) { 85 if($n == $this->selected) {
87 ptln(' <tr class="default"><td colspan="2">'); 86 ptln(' <tr class="default"><td colspan="2">');
88 if($this->req == 'install') $this->install($this->selected, $_REQUEST['name']); 87 if($this->req == 'install') $this->install($this->selected, $_REQUEST['name']);
89 if($this->req == 'upload' && $_REQUEST['name']) { 88 if($this->req == 'upload' && $_REQUEST['name']) {
90 $info = ""; 89 $info = "";
91 if(isset($_REQUEST['author_info'])) { 90 if(isset($_REQUEST['author_info'])) {
92 $obfuscate = array('@' => ' [at] ', '.' => ' [dot] ', '-' => ' [dash] '); 91 $obfuscate = array('@' => ' [at] ', '.' => ' [dot] ', '-' => ' [dash] ');
93 $info .= "author=".strtr($_REQUEST['author_info'], $obfuscate)."\n"; 92 $info .= "author=".strtr($_REQUEST['author_info'], $obfuscate)."\n";
94 } 93 }
95 if(isset($_REQUEST['url_info'])) $info .= "url=".$_REQUEST['url_info']."\n"; 94 if(isset($_REQUEST['url_info'])) $info .= "url=".$_REQUEST['url_info']."\n";
96 if(isset($_REQUEST['author_info'])) $info .= "description=".$_REQUEST['author_info']; 95 if(isset($_REQUEST['author_info'])) $info .= "description=".$_REQUEST['author_info'];
97 if(!$this->upload($_REQUEST['name'], $info)) msg($this->getLang('install_no'), -1); 96 if(!$this->upload($_REQUEST['name'], $info)) msg($this->getLang('install_no'), -1);
98 } 97 }
99 if($this->req == 'delete' && $_REQUEST['name']) $this->_delete($_REQUEST['name']); 98 if($this->req == 'delete' && $_REQUEST['name']) $this->_delete($_REQUEST['name']);
100 ptln(' </td></tr><tr><td colspan="2">'); 99 ptln(' </td></tr><tr><td colspan="2">');
101 $this->dolist($n); 100 $this->dolist($n);
102 ptln(' </td></tr>'); 101 ptln(' </td></tr>');
103 } 102 }
104 $n++; 103 $n++;
105 } 104 }
106 ptln(' </table>'); 105 ptln(' </table>');
107 ptln(' </fieldset>'); 106 ptln(' </fieldset>');
108 ptln('</div>'); 107 ptln('</div>');
109 } 108 }
110   109  
111 /** 110 /**
112 * Connect to theme repository and list themes 111 * Connect to theme repository and list themes
113 * 112 *
114 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 113 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
115 * @author Samuele Tognini <samuele@samuele.netsons.org> 114 * @author Samuele Tognini <samuele@samuele.netsons.org>
116 */ 115 */
117 function dolist($n) { 116 function dolist($n) {
118 global $INFO; 117 global $INFO;
119 if($n === false) return; 118 if($n === false) return;
120 //info.txt keys to parse 119 //info.txt keys to parse
121 $keys = array('author', 'url', 'description'); 120 $keys = array('author', 'url', 'description');
122 $icos = explode(',', INDEXMENU_ICOS); 121 $icos = explode(',', INDEXMENU_ICOS);
123 $turl = ""; 122 $turl = "";
124 $info = ""; 123 $info = "";
125 //get list 124 //get list
126 $data = $this->_remotequery($this->repos['url'][$n]."/lib/plugins/indexmenu/ajax.php?req=local"); 125 $data = $this->_remotequery($this->repos['url'][$n]."/lib/plugins/indexmenu/ajax.php?req=local");
127 $data = explode(",", $data); 126 $data = explode(",", $data);
128 //print themes 127 //print themes
129 for($i = 3; $i < count($data); $i++) { 128 for($i = 3; $i < count($data); $i++) {
130 $theme = $data[$i]; 129 $theme = $data[$i];
131 $turl = $data[1].$data[2]."/".$theme; 130 $turl = $data[1].$data[2]."/".$theme;
132 ptln(' <em>'.$theme.'</em>'); 131 ptln(' <em>'.$theme.'</em>');
133 ptln(' <div class="indexmenu_list_themes">'); 132 ptln(' <div class="indexmenu_list_themes">');
134 ptln(' <div>'); 133 ptln(' <div>');
135 //print images 134 //print images
136 foreach(array_slice($icos, 0, 8) as $ico) { 135 foreach(array_slice($icos, 0, 8) as $ico) {
137 $ext = explode(".", $theme); 136 $ext = explode(".", $theme);
138 $ext = array_pop($ext); 137 $ext = array_pop($ext);
139 $ext = ($ext == $theme) ? '.gif' : ".$ext"; 138 $ext = ($ext == $theme) ? '.gif' : ".$ext";
140 ptln(' <img src="'.$turl."/".$ico.$ext.'" title="'.$ico.'" alt="'.$ico.'" />'); 139 ptln(' <img src="'.$turl."/".$ico.$ext.'" title="'.$ico.'" alt="'.$ico.'" />');
141 } 140 }
142 ptln(' </div>'); 141 ptln(' </div>');
143 //get theme info.txt 142 //get theme info.txt
144 if($info = $this->_remotequery($turl."/info.txt", false)) { 143 if($info = $this->_remotequery($turl."/info.txt", false)) {
145 foreach($keys as $key) { 144 foreach($keys as $key) {
146 if(!preg_match('/'.$key.'=(.*)/', $info, $out)) continue; 145 if(!preg_match('/'.$key.'=(.*)/', $info, $out)) continue;
147 ptln(" <div>"); 146 ptln(" <div>");
148 ptln(" <strong>".hsc($key).": </strong>".hsc($out[1])); 147 ptln(" <strong>".hsc($key).": </strong>".hsc($out[1]));
149 ptln(" </div>"); 148 ptln(" </div>");
150 } 149 }
151 } 150 }
152 if($n == 0) { 151 if($n == 0) {
153 $act = "upload"; 152 $act = "upload";
154 if($theme != "default") { 153 if($theme != "default") {
155 $this->_form_open("delete", $n); 154 $this->_form_open("delete", $n);
156 ptln(' <input type="hidden" name="name" value="'.$theme.'" />'); 155 ptln(' <input type="hidden" name="name" value="'.$theme.'" />');
157 $this->_form_close("delete"); 156 $this->_form_close("delete");
158 } 157 }
159 } else { 158 } else {
160 $act = "install"; 159 $act = "install";
161 ptln(' <a href="'.$this->repos['url'][$n]."/lib/plugins/indexmenu/ajax.php?req=send&amp;t=".$theme.'">Download</a>'); 160 ptln(' <a href="'.$this->repos['url'][$n]."/lib/plugins/indexmenu/ajax.php?req=send&amp;t=".$theme.'">Download</a>');
162 } 161 }
163 $this->_form_open($act, $n); 162 $this->_form_open($act, $n);
164 if($n == 0 && !is_file(INDEXMENU_IMG_ABSDIR."/".$theme."/info.txt")) { 163 if($n == 0 && !is_file(INDEXMENU_IMG_ABSDIR."/".$theme."/info.txt")) {
165 ptln(' <div><strong>author:</strong><input type="text" name="author_info" value="'.$INFO["userinfo"]["name"].hsc(" <".$INFO["userinfo"]["mail"].">").'" size="50" maxlength="100" /><br />'); 164 ptln(' <div><strong>author:</strong><input type="text" name="author_info" value="'.$INFO["userinfo"]["name"].hsc(" <".$INFO["userinfo"]["mail"].">").'" size="50" maxlength="100" /><br />');
166 ptln(' <strong>url:</strong><input type="text" name="url_info" value="'.$this->repos['url'][$n].'" size="50" maxlength="200" /><br />'); 165 ptln(' <strong>url:</strong><input type="text" name="url_info" value="'.$this->repos['url'][$n].'" size="50" maxlength="200" /><br />');
167 ptln(' <strong>description:</strong><input type="text" name="description_info" value="" size="50" maxlength="200" /></div>'); 166 ptln(' <strong>description:</strong><input type="text" name="description_info" value="" size="50" maxlength="200" /></div>');
168 } 167 }
169 ptln(' <input type="hidden" name="name" value="'.$theme.'" />'); 168 ptln(' <input type="hidden" name="name" value="'.$theme.'" />');
170 $this->_form_close($act); 169 $this->_form_close($act);
171 ptln(' <br /><br /></div>'); 170 ptln(' <br /><br /></div>');
172 } 171 }
173 } 172 }
174   173  
175 /** 174 /**
176 * Download and install themes 175 * Download and install themes
177 * 176 *
178 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 177 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
179 * @author Samuele Tognini <samuele@samuele.netsons.org> 178 * @author Samuele Tognini <samuele@samuele.netsons.org>
180 */ 179 */
181 function install($n, $name) { 180 function install($n, $name) {
182 $repo = $this->repos['url'][$n]; 181 $repo = $this->repos['url'][$n];
183 if(!isset($name)) return false; 182 if(!isset($name)) return false;
184 $return = true; 183 $return = true;
185 if(!$absdir = $this->checktmpsubdir()) return false; 184 if(!$absdir = $this->checktmpsubdir()) return false;
186 $tmp = $absdir."/tmp"; 185 $tmp = $absdir."/tmp";
187   186  
188 //send theme list request 187 //send theme list request
189 if(!$zipfile = io_download($repo."/lib/plugins/indexmenu/ajax.php?req=send&t=".$name, "$tmp/", true)) { 188 if(!$zipfile = io_download($repo."/lib/plugins/indexmenu/ajax.php?req=send&t=".$name, "$tmp/", true)) {
190 msg($this->getLang('down_err').": $name", -1); 189 msg($this->getLang('down_err').": $name", -1);
191 $return = false; 190 $return = false;
192 } else { 191 } else {
193 //create zip 192 //create zip
194 $zip = new PclZip("$tmp/$zipfile"); 193 $zip = new PclZip("$tmp/$zipfile");
195 $regexp = "/^".$name."\/(info.txt)|(style.css)|(".str_replace(",", "|", INDEXMENU_ICOS).")\.(gif|png|jpg)$/i"; 194 $regexp = "/^".$name."\/(info.txt)|(style.css)|(".str_replace(",", "|", INDEXMENU_ICOS).")\.(gif|png|jpg)$/i";
196 $status = $zip->extract(PCLZIP_OPT_PATH, $absdir."/", PCLZIP_OPT_BY_PREG, $regexp); 195 $status = $zip->extract(PCLZIP_OPT_PATH, $absdir."/", PCLZIP_OPT_BY_PREG, $regexp);
197 //error 196 //error
198 if($status == 0) { 197 if($status == 0) {
199 msg($this->getLang('zip_err')." $tmp/$zipfile: ".$zip->errorName(true), -1); 198 msg($this->getLang('zip_err')." $tmp/$zipfile: ".$zip->errorName(true), -1);
200 $return = false; 199 $return = false;
201 } else { 200 } else {
202 msg("<strong>$name</strong> ".$this->getLang('install_ok'), 1); 201 msg("<strong>$name</strong> ".$this->getLang('install_ok'), 1);
203 } 202 }
204 } 203 }
205 //clean tmp 204 //clean tmp
206 $this->_rm_dir($tmp); 205 $this->_rm_dir($tmp);
207 return $return; 206 return $return;
208 } 207 }
209   208  
210 /** 209 /**
211 * Remove a directory 210 * Remove a directory
212 * 211 *
213 */ 212 */
214 function _rm_dir($path) { 213 function _rm_dir($path) {
215 if(!is_string($path) || $path == "") return false; 214 if(!is_string($path) || $path == "") return false;
216   215  
217 if(is_dir($path)) { 216 if(is_dir($path)) {
218 if(!$dh = @opendir($path)) return false; 217 if(!$dh = @opendir($path)) return false;
219   218  
220 while($f = readdir($dh)) { 219 while($f = readdir($dh)) {
221 if($f == '..' || $f == '.') continue; 220 if($f == '..' || $f == '.') continue;
222 $this->_rm_dir("$path/$f"); 221 $this->_rm_dir("$path/$f");
223 } 222 }
224   223  
225 closedir($dh); 224 closedir($dh);
226 return @rmdir($path); 225 return @rmdir($path);
227 } else { 226 } else {
228 return @unlink($path); 227 return @unlink($path);
229 } 228 }
230 } 229 }
231   230  
232 /** 231 /**
233 * Retrive and create themes tmp directory 232 * Retrive and create themes tmp directory
234 * 233 *
235 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 234 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
236 * @author Samuele Tognini <samuele@samuele.netsons.org> 235 * @author Samuele Tognini <samuele@samuele.netsons.org>
237 */ 236 */
238 function checktmpsubdir() { 237 function checktmpsubdir() {
239 $tmp = INDEXMENU_IMG_ABSDIR."/tmp"; 238 $tmp = INDEXMENU_IMG_ABSDIR."/tmp";
240 if(!io_mkdir_p($tmp)) { 239 if(!io_mkdir_p($tmp)) {
241 msg($this->getLang('dir_err').": $tmp", -1); 240 msg($this->getLang('dir_err').": $tmp", -1);
242 return false; 241 return false;
243 } 242 }
244 return INDEXMENU_IMG_ABSDIR; 243 return INDEXMENU_IMG_ABSDIR;
245 } 244 }
246   245  
247 /** 246 /**
248 * Upload a theme into my site 247 * Upload a theme into my site
249 * 248 *
250 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 249 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
251 * @author Samuele Tognini <samuele@samuele.netsons.org> 250 * @author Samuele Tognini <samuele@samuele.netsons.org>
252 */ 251 */
253 function upload($theme, $info) { 252 function upload($theme, $info) {
254 $return = true; 253 $return = true;
255 $host = 'samuele.netsons.org'; 254 $host = 'samuele.netsons.org';
256 $path = '/dokuwiki/lib/plugins/indexmenu/upload/index.php'; 255 $path = '/dokuwiki/lib/plugins/indexmenu/upload/index.php';
257 //TODO: merge zip creation with that in ajax.php (create a class?) 256 //TODO: merge zip creation with that in ajax.php (create a class?)
258 if(!$absdir = $this->checktmpsubdir()) return false; 257 if(!$absdir = $this->checktmpsubdir()) return false;
259 $tmp = $absdir."/tmp"; 258 $tmp = $absdir."/tmp";
260 $zipfile = "$theme.zip"; 259 $zipfile = "$theme.zip";
261 $filelist = "$absdir/$theme"; 260 $filelist = "$absdir/$theme";
262 //create info 261 //create info
263 if(!empty($info)) { 262 if(!empty($info)) {
264 io_savefile("$tmp/$theme/info.txt", $info); 263 io_savefile("$tmp/$theme/info.txt", $info);
265 $filelist .= ",$tmp/$theme"; 264 $filelist .= ",$tmp/$theme";
266 } 265 }
267 //create zip 266 //create zip
268 $zip = new PclZip("$tmp/$zipfile"); 267 $zip = new PclZip("$tmp/$zipfile");
269 $status = $zip->create($filelist, PCLZIP_OPT_REMOVE_ALL_PATH); 268 $status = $zip->create($filelist, PCLZIP_OPT_REMOVE_ALL_PATH);
270 if($status == 0) { 269 if($status == 0) {
271 //error 270 //error
272 msg($this->getLang('zip_err').": ".$zip->errorName(true), -1); 271 msg($this->getLang('zip_err').": ".$zip->errorName(true), -1);
273 $return = false; 272 $return = false;
274 } else { 273 } else {
275 //prepare POST headers. 274 //prepare POST headers.
276 $boundary = "---------------------------".uniqid(""); 275 $boundary = "---------------------------".uniqid("");
277 $data = join("", file("$tmp/$zipfile")); 276 $data = join("", file("$tmp/$zipfile"));
278 $header = "POST $path HTTP/1.0\r\n"; 277 $header = "POST $path HTTP/1.0\r\n";
279 $header .= "Host: $host\r\n"; 278 $header .= "Host: $host\r\n";
280 $header .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Iceweasel/2.0 (Debian-2.0+dfsg-1)\r\n"; 279 $header .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Iceweasel/2.0 (Debian-2.0+dfsg-1)\r\n";
281 $header .= "Content-type: multipart/form-data, boundary=$boundary\r\n"; 280 $header .= "Content-type: multipart/form-data, boundary=$boundary\r\n";
282 $body = "--".$boundary."\r\n"; 281 $body = "--".$boundary."\r\n";
283 $body .= "Content-Disposition: form-data; name=\"userfile\"; filename=\"$zipfile\"\r\n"; 282 $body .= "Content-Disposition: form-data; name=\"userfile\"; filename=\"$zipfile\"\r\n";
284 $body .= "Content-Type: application/x-zip-compressed\r\n\r\n"; 283 $body .= "Content-Type: application/x-zip-compressed\r\n\r\n";
285 $body .= $data."\r\n"; 284 $body .= $data."\r\n";
286 $body .= "--".$boundary."\r\n"; 285 $body .= "--".$boundary."\r\n";
287 $body .= "Content-Disposition: form-data; name=\"upload\"\r\n\r\n"; 286 $body .= "Content-Disposition: form-data; name=\"upload\"\r\n\r\n";
288 $body .= "Upload\r\n"; 287 $body .= "Upload\r\n";
289 $body .= "--".$boundary."--\r\n"; 288 $body .= "--".$boundary."--\r\n";
290 $header .= "Content-Length: ".strlen($body)."\r\n\r\n"; 289 $header .= "Content-Length: ".strlen($body)."\r\n\r\n";
291   290  
292 //connect and send zip 291 //connect and send zip
293 if($fp = fsockopen($host, 80)) { 292 if($fp = fsockopen($host, 80)) {
294 fwrite($fp, $header.$body); 293 fwrite($fp, $header.$body);
295 //reply 294 //reply
296 $buf = ""; 295 $buf = "";
297 while(!feof($fp)) { 296 while(!feof($fp)) {
298 $buf .= fgets($fp, 3200); 297 $buf .= fgets($fp, 3200);
299 } 298 }
300 fclose($fp); 299 fclose($fp);
301 //parse resply 300 //parse resply
302 if(preg_match("/<!--indexmenu-->(.*)<!--\/indexmenu-->/s", $buf, $match)) { 301 if(preg_match("/<!--indexmenu-->(.*)<!--\/indexmenu-->/s", $buf, $match)) {
303 $str = substr($match[1], 4, 7); 302 $str = substr($match[1], 4, 7);
304 switch($str) { 303 switch($str) {
305 case "ERROR ": 304 case "ERROR ":
306 $mesg_type = -1; 305 $mesg_type = -1;
307 break; 306 break;
308 case "SUCCESS": 307 case "SUCCESS":
309 $mesg_type = 1; 308 $mesg_type = 1;
310 break; 309 break;
311 default: 310 default:
312 $mesg_type = 2; 311 $mesg_type = 2;
313 } 312 }
314 msg($match[1], $mesg_type); 313 msg($match[1], $mesg_type);
315 } else { 314 } else {
316 $return = false; 315 $return = false;
317 } 316 }
318 } else { 317 } else {
319 $return = false; 318 $return = false;
320 } 319 }
321 } 320 }
322   321  
323 $this->_rm_dir($tmp); 322 $this->_rm_dir($tmp);
324 return $return; 323 return $return;
325 } 324 }
326   325  
327 /** 326 /**
328 * Check for new messages from upstream 327 * Check for new messages from upstream
329 * 328 *
330 * @author Samuele Tognini <samuele@samuele.netsons.org> 329 * @author Samuele Tognini <samuele@samuele.netsons.org>
331 */ 330 */
332 function _checkupdates() { 331 function _checkupdates() {
333 require_once (DOKU_INC.'inc/HTTPClient.php'); 332 require_once (DOKU_INC.'inc/HTTPClient.php');
334 global $conf; 333 global $conf;
335 global $INFO; 334 global $INFO;
336 $w = -1; 335 $w = -1;
337 $date = $this->getInfo('date'); 336 $date = $this->getInfo('date');
338 $date = $date['date']; 337 $date = $date['date'];
339 $data = $this->_remotequery("http://samuele.netsons.org/dokuwiki/lib/plugins/indexmenu/remote.php?check=$date"); 338 $data = $this->_remotequery("http://samuele.netsons.org/dokuwiki/lib/plugins/indexmenu/remote.php?check=$date");
340 if($data === "") { 339 if($data === "") {
341 msg($this->getLang('noupdates'), 1); 340 msg($this->getLang('noupdates'), 1);
342 $data .= @preg_replace('/\n\n.*$/s', '', @io_readFile(DOKU_PLUGIN.'indexmenu/changelog'))."\n%\n"; 341 $data .= @preg_replace('/\n\n.*$/s', '', @io_readFile(DOKU_PLUGIN.'indexmenu/changelog'))."\n%\n";
343 $w = 1; 342 $w = 1;
344 } else { 343 } else {
345 $data = preg_replace('/\<br(\s*)?\/?\>/i', "", $data); 344 $data = preg_replace('/\<br(\s*)?\/?\>/i', "", $data);
346 $data = preg_replace('/\t/', " ", $data); 345 $data = preg_replace('/\t/', " ", $data);
347 } 346 }
348 $data = preg_replace('/\[\[(?!(http|https))(.:)(.*?)\]\]/s', "[[plugin:$3]]", $data); 347 $data = preg_replace('/\[\[(?!(http|https))(.:)(.*?)\]\]/s', "[[plugin:$3]]", $data);
349 $data = preg_replace('/\[\[(?!(http|https))(.*?)\]\]/s', "[[http://www.dokuwiki.org/$2]]", $data); 348 $data = preg_replace('/\[\[(?!(http|https))(.*?)\]\]/s', "[[http://www.dokuwiki.org/$2]]", $data);
350 $msgs = explode("\n%\n", $data); 349 $msgs = explode("\n%\n", $data);
351 foreach($msgs as $msg) { 350 foreach($msgs as $msg) {
352 if($msg) { 351 if($msg) {
353 $msg = p_render('xhtml', p_get_instructions($msg), $info); 352 $msg = p_render('xhtml', p_get_instructions($msg), $info);
354 msg($msg, $w); 353 msg($msg, $w);
355 } 354 }
356 } 355 }
357 } 356 }
358   357  
359 /** 358 /**
360 * Get url response and check it 359 * Get url response and check it
361 * 360 *
362 * @author Samuele Tognini <samuele@samuele.netsons.org> 361 * @author Samuele Tognini <samuele@samuele.netsons.org>
363 */ 362 */
364 function _remotequery($url, $tag = true) { 363 function _remotequery($url, $tag = true) {
365 require_once (DOKU_INC.'inc/HTTPClient.php'); 364 require_once (DOKU_INC.'inc/HTTPClient.php');
366 $http = new DokuHTTPClient(); 365 $http = new DokuHTTPClient();
367 $http->timeout = 8; 366 $http->timeout = 8;
368 $data = $http->get($url); 367 $data = $http->get($url);
369 if($tag) { 368 if($tag) {
370 if($data === false) { 369 if($data === false) {
371 msg($this->getLang('conn_err'), -1); 370 msg($this->getLang('conn_err'), -1);
372 } else { 371 } else {
373 (substr($data, 0, 9) === "indexmenu") ? $data = substr($data, 9) : $data = ""; 372 (substr($data, 0, 9) === "indexmenu") ? $data = substr($data, 9) : $data = "";
374 } 373 }
375 } 374 }
376 return $data; 375 return $data;
377 } 376 }
378   377  
379 /** 378 /**
380 * Open an html form 379 * Open an html form
381 * 380 *
382 * @author Samuele Tognini <samuele@samuele.netsons.org> 381 * @author Samuele Tognini <samuele@samuele.netsons.org>
383 */ 382 */
384 function _form_open($act, $n = -1) { 383 function _form_open($act, $n = -1) {
385 global $ID; 384 global $ID;
386 ptln(' <form action="'.wl($ID).'" method="post">'); 385 ptln(' <form action="'.wl($ID).'" method="post">');
387 ptln(' <input type="hidden" name="do" value="admin" />'); 386 ptln(' <input type="hidden" name="do" value="admin" />');
388 ptln(' <input type="hidden" name="page" value="'.$this->getPluginName().'" />'); 387 ptln(' <input type="hidden" name="page" value="'.$this->getPluginName().'" />');
389 ptln(' <input type="hidden" name="req" value="'.$act.'" />'); 388 ptln(' <input type="hidden" name="req" value="'.$act.'" />');
390 ptln(' <input type="hidden" name="repo" value="'.$n.'" />'); 389 ptln(' <input type="hidden" name="repo" value="'.$n.'" />');
391 } 390 }
392   391  
393 /** 392 /**
394 * Close the html form 393 * Close the html form
395 * 394 *
396 * @author Samuele Tognini <samuele@samuele.netsons.org> 395 * @author Samuele Tognini <samuele@samuele.netsons.org>
397 */ 396 */
398 function _form_close($act) { 397 function _form_close($act) {
399 ptln(' <input type="submit" name="btn" '.$this->repos['status'][$n].' value="'.$this->getLang($act).'" />'); 398 ptln(' <input type="submit" name="btn" '.$this->repos['status'][$n].' value="'.$this->getLang($act).'" />');
400 ptln(' </form>'); 399 ptln(' </form>');
401 } 400 }
402   401  
403 /** 402 /**
404 * Remove an installed theme 403 * Remove an installed theme
405 * 404 *
406 * @author Samuele Tognini <samuele@samuele.netsons.org> 405 * @author Samuele Tognini <samuele@samuele.netsons.org>
407 */ 406 */
408 function _delete($theme) { 407 function _delete($theme) {
409 if($theme == "default") return; 408 if($theme == "default") return;
410 if($this->_rm_dir(INDEXMENU_IMG_ABSDIR."/".utf8_encodeFN(basename($theme)))) { 409 if($this->_rm_dir(INDEXMENU_IMG_ABSDIR."/".utf8_encodeFN(basename($theme)))) {
411 msg($this->getLang('delete_ok').": $theme.", 1); 410 msg($this->getLang('delete_ok').": $theme.", 1);
412 } else { 411 } else {
413 msg($this->getLang('delete_no').": $theme.", -1); 412 msg($this->getLang('delete_no').": $theme.", -1);
414 } 413 }
415 } 414 }
416   415  
417 /** 416 /**
418 * Print the donate button. 417 * Print the donate button.
419 * 418 *
420 * @author Samuele Tognini <samuele@samuele.netsons.org> 419 * @author Samuele Tognini <samuele@samuele.netsons.org>
421 */ 420 */
422 function _donate() { 421 function _donate() {
423 $out = "<fieldset>\n"; 422 $out = "<fieldset>\n";
424 $out .= '<p>'.$this->getLang('donation_text').'</p>'; 423 $out .= '<p>'.$this->getLang('donation_text').'</p>';
425 $out .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">'."\n"; 424 $out .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">'."\n";
426 $out .= '<input type="hidden" name="cmd" value="_s-xclick" />'."\n"; 425 $out .= '<input type="hidden" name="cmd" value="_s-xclick" />'."\n";
427 $out .= '<input type="hidden" name="hosted_button_id" value="102873" />'."\n"; 426 $out .= '<input type="hidden" name="hosted_button_id" value="102873" />'."\n";
428 $out .= '<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" name="submit" alt="" />'."\n"; 427 $out .= '<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" name="submit" alt="" />'."\n";
429 $out .= '<img alt="" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1" />'."\n"; 428 $out .= '<img alt="" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1" />'."\n";
430 $out .= "</form></fieldset>\n"; 429 $out .= "</form></fieldset>\n";
431 return $out; 430 return $out;
432 } 431 }
433   432  
434 } 433 }
435   434