OSDN Git Service

changed to binary
[nucleus-jp/nucleus-jp-ancient.git] / euc / nucleus / plugins / skinfiles / index.php
1 <?php\r
2 \r
3 /*                                       */\r
4 /* Admin page for NP_SkinFiles           */\r
5 /* ------------------------------------  */\r
6 /* A simple skin files manager           */\r
7 /*                                       */\r
8 /* code by Jeff MacMichael               */\r
9 /* http://gednet.com/                    */\r
10 /*                                       */\r
11 /* version 1.01                          */\r
12  \r
13         $strRel = '../../../'; \r
14         include($strRel . 'config.php');\r
15         \r
16         include($DIR_LIBS . 'PLUGINADMIN.php');\r
17 \r
18         if (preg_match("/MD$/", $nucleus['version'])) {\r
19                 $isblogadmin = $member->isBlogAdmin(-1);\r
20         } else {\r
21                 $isblogadmin = $member->isBlogAdmin($blogid);\r
22         }\r
23         if (!($member->isAdmin() || $isblogadmin)) {\r
24                 $oPluginAdmin = new PluginAdmin('SkinFiles');\r
25                 $oPluginAdmin->start();\r
26                 echo "<p>"._ERROR_DISALLOWED."</p>";\r
27                 $oPluginAdmin->end();\r
28                 exit;\r
29         }\r
30 \r
31         // set to FALSE for normal operation, or TRUE if skins are stored\r
32         // under owner's member id i.e. /skins/1/grey/...   (MDNucleus)\r
33         $privateskins = FALSE;\r
34         if ($privateskins) { \r
35                 global $member;\r
36                 $SKINSUBDIR = $member->getID().'/'; \r
37                 $latestskins = 'latest-skins/';\r
38         } else {\r
39                 $SKINSUBDIR = '';\r
40         }\r
41         \r
42         global $pluginsskinfiles, $CONF;\r
43         $pluginsskinfiles=$CONF['PluginURL']."skinfiles";\r
44 \r
45         if (isset($_GET['action'])) {$action = $_GET['action'];}\r
46         if (isset($_POST['action'])) {$action = $_POST['action'];}\r
47 \r
48         if ($action == 'download') { \r
49                 download();\r
50                 return;\r
51                 break;\r
52         }\r
53 \r
54         // create the admin area page\r
55         $oPluginAdmin = new PluginAdmin('SkinFiles');\r
56         $oPluginAdmin->start();\r
57         \r
58         echo "<h2>Skin File Management</h2>";\r
59         \r
60         if (strstr('renfile delfile createdir rendir deldir deleteAllInDir'\r
61                 .' editfile uploadfile createfile getLatestSkins', $action)) { \r
62                 call_user_func($action);\r
63         } else {\r
64                 showdir();\r
65         }\r
66 \r
67         $oPluginAdmin->end();\r
68         return;\r
69         break;\r
70                 \r
71         function createfile() {\r
72                 global $oPluginAdmin, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
73                 $parent = $_POST["dir"];\r
74                 $filename = $_POST["filename"];\r
75                 $fullpath = $DIR_SKINS.$SKINSUBDIR.$parent.'/'.$filename;\r
76                 if (file_exists($fullpath)) {\r
77                         $msg = "Error: the file '$filename' already exists.";\r
78                         showdir($msg);\r
79                 }\r
80                 echo "<h3><b>Creating file \"/$parent/$filename\":</b></h3>";\r
81                 $errrep = error_reporting(E_ERROR);\r
82                 if (touch($fullpath)) { \r
83                         $msg = 'The file was created successfully.';\r
84                 } else {\r
85                         $msg = 'ERROR: The file was <i>not</i> created successfully.';\r
86                 }\r
87                 $oldumask = umask(0000);\r
88                 chmod($fullpath, 0755);\r
89                 umask($oldumask);\r
90                 error_reporting($errrep);\r
91                 showdir($msg);\r
92         }\r
93 \r
94         function createdir() {\r
95                 global $oPluginAdmin, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
96                 $parent = $_POST["dir"];\r
97                 $newdir = $_POST["newdir"];\r
98                 if (!$newdir) {\r
99                         echo 'You need to specify a directory name to create. <br /><br />';\r
100                         echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Go back</a><br />';              \r
101                         return;\r
102                 }\r
103                 $errrep = error_reporting(E_ERROR);\r
104                 $oldumask = umask(0000);\r
105                 if (mkdir ($DIR_SKINS.$SKINSUBDIR.$parent.'/'.$newdir, 0755)) {\r
106                         $msg = 'Directory created successfully.';\r
107                 } else {\r
108                         $msg = 'There was an error creating the directory (check to see if the directory already exists).';\r
109                 }\r
110                 umask($oldumask);\r
111                 error_reporting($errrep);\r
112                 showdir($msg);\r
113         }\r
114         \r
115         function download() {\r
116                 global $DIR_SKINS, $SKINSUBDIR;\r
117                 $file = $_GET["rfp"];\r
118                 $path = $DIR_SKINS.$SKINSUBDIR.$file;\r
119                 $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);\r
120                 $file = strrev($splitpath[0]);\r
121                 \r
122                 // download code taken from Paul Alger's PHP_Easy_Download. \r
123 \r
124                 // translate file name properly for Internet Explorer.\r
125                 if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){\r
126                         $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1);\r
127                 }\r
128                 // make sure the file exists before sending headers\r
129                 if(!$fdl=@fopen($path,'r')){\r
130                         die("Cannot Open File!");\r
131                 } else {\r
132                         header("Cache-Control: ");// leave blank to avoid IE errors\r
133                         header("Pragma: ");// leave blank to avoid IE errors\r
134                         header("Content-type: application/octet-stream");\r
135                         header('Content-Disposition: attachment; filename="'.$file.'"');\r
136                         header("Content-length: ".(string)(filesize($path)));\r
137                         sleep(1);\r
138                         \r
139                         fpassthru($fdl);\r
140                 }\r
141                 return;\r
142                 break;\r
143         }\r
144         \r
145         function uploadfile() {\r
146                 global $HTTP_POST_FILES, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles, $CONF;\r
147                 $filename = $HTTP_POST_FILES['filename']['name'];\r
148                 $filesize = $HTTP_POST_FILES['filename']['size'];\r
149                 $filetempname = $HTTP_POST_FILES['filename']['tmp_name'];\r
150                 $todir = $DIR_SKINS.$SKINSUBDIR.$_POST['dir'].'/';\r
151                 \r
152                 if ($filesize > $CONF['MaxUploadSize']) {\r
153                         showdir(_ERROR_FILE_TOO_BIG);\r
154                         return;\r
155                 }\r
156 \r
157                 // check file type against allowed types\r
158                 $ok = 0;\r
159                 $allowedtypes = explode (',', "css,html,htm,xml,inc,txt,".$CONF['AllowedTypes']);\r
160                 foreach ( $allowedtypes as $type ) \r
161                         if (eregi("\." .$type. "$",$filename)) $ok = 1;    \r
162                 if (!$ok) {\r
163                         showdir(_ERROR_BADFILETYPE);\r
164                         return;\r
165                 }\r
166                 if (!is_uploaded_file($filetempname)) {\r
167                         showdir(_ERROR_BADREQUEST);\r
168                         return;\r
169                 }\r
170                 if (file_exists($todir.$filename)) {\r
171                         showdir(_ERROR_UPLOADDUPLICATE);\r
172                         return;\r
173                 }\r
174 \r
175                 // move file to directory\r
176                 if (is_uploaded_file($filetempname)) {\r
177                         $errrep = error_reporting(E_ERROR);\r
178                         if (!@move_uploaded_file($filetempname, $todir . $filename)) {\r
179                                 showdir(_ERROR_UPLOADMOVE);\r
180                                 return;\r
181                         }\r
182                         error_reporting($errrep);\r
183                 }\r
184                 // chmod uploaded file\r
185                 $oldumask = umask(0000);\r
186                 @chmod($todir . $filename, 0755); \r
187                 umask($oldumask);               \r
188 \r
189                 showdir("File uploaded successfully.");\r
190         }\r
191 \r
192         function rendir() {\r
193                 global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
194                 if (isset($_POST['newname'])) {\r
195                         $splitpath =  preg_split( "/\//", strrev($_POST["oldname"]), 2);\r
196                         $newname = strrev($splitpath[1]) .'/'. $_POST["newname"];\r
197                         $newname = preg_replace("/^\//", "", $newname);\r
198                         $res = rename ( $DIR_SKINS.$SKINSUBDIR.$_POST["oldname"], \r
199                                 $DIR_SKINS.$SKINSUBDIR.$newname);\r
200                         if ($res) { \r
201                                 $msg = "Directory successfully renamed."; \r
202                         } else {\r
203                                 $msg = "Failed to rename directory - (check to see if another directory already exists with the new name).";\r
204                         }\r
205                         showdir($msg);\r
206                 } else { \r
207                         $oldname = preg_replace("/^\//", "", $_GET["oldname"]);\r
208                         echo '<h3><b>Rename directory "/'.$oldname.'":</b></h3>';\r
209                         $splitpath =  preg_split( "/\//", strrev($_GET["oldname"]), 2);\r
210                         $dir = strrev($splitpath[0]);\r
211                         $parent = strrev($splitpath[1]);\r
212                         echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Cancel rename</a><br />';                \r
213                         ?>\r
214                                 <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
215                                         <input type="hidden" name="action" value="rendir" />\r
216                                         <input type="hidden" name="dir" value="<?php echo "/$parent" ?>"/>\r
217                                         <input type="hidden" name="oldname" value="<?php echo $oldname?>"/>\r
218                                         <table><tr>\r
219                                                 <td><?php echo 'Rename to'?></td>\r
220                                                 <td><input name="newname" tabindex="90" value="<?php echo  htmlspecialchars($dir) ?>" maxlength="50" size="20" /></td>\r
221                                         </tr><tr>\r
222                                                 <td><?php echo "Rename"?></td>\r
223                                                 <td><input type="submit" tabindex="140" value="<?php echo "Rename this folder"?>" onclick="return checkSubmit();" /></td>\r
224                                         </tr></table>\r
225                                 </form>\r
226                         <?PHP\r
227                 }\r
228         }\r
229 \r
230         function editfile () {\r
231                 global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
232                 if (isset ($_POST['rfp']) && isset($_POST['content'])) {\r
233                         $file = $_POST['rfp'];\r
234                         $errrep = error_reporting(E_ERROR);\r
235                         $success = true;\r
236                         if ($fh = @fopen($DIR_SKINS.$SKINSUBDIR.$file, 'w')) { \r
237                                 if (fwrite ($fh, trim(stripslashes($_POST['content'])))) {\r
238                                         fclose($fh);\r
239                                 } else {\r
240                                         $success = false;\r
241                                 }\r
242                         } else {\r
243                                 $success = false;\r
244                         }\r
245                         error_reporting($errrep);\r
246                         if ($success) {\r
247                                 $msg = 'File was edited successfully.';\r
248                         } else {\r
249                                 $msg = 'ERROR: File was <i>not</i> saved successfully.';\r
250                         }\r
251                 }\r
252                 if (isset ($_GET['rfp'])) { $file = $_GET['rfp']; }\r
253                 if (isset ($_POST['rfp'])) { $file = $_POST['rfp']; }\r
254                 $splitpath =  preg_split( "/\//", strrev($file), 2);\r
255                 $parent = strrev($splitpath[1]);\r
256                 echo '<h3>Editing file "/'.$file.'":</h3>';\r
257                 if (isset($msg)) { echo "<p><b>$msg</b></p>"; }\r
258                 echo "> <a href=\"$pluginsskinfiles/?dir=$parent\"> Cancel/Return to /$parent</a><br /><br />";\r
259                 $fh = @fopen($DIR_SKINS.$SKINSUBDIR.$file, 'r');\r
260                 while (!feof($fh)) { \r
261                         $content .= fread($fh, 4096); \r
262                 }\r
263                 fclose ($fh);                   \r
264                 ?>\r
265                         <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
266                                 <input type="hidden" name="action" value="editfile" />\r
267                                 <input type="hidden" name="rfp" value="<?php echo $file ?>"/>\r
268                                 <input type="hidden" name="dir" value="<?php echo $parent ?>"/>\r
269                                 <input type="submit" tabindex="140" value="<?php echo "Save changes"?>" onclick="return checkSubmit();" />\r
270                                 <input type="reset" value="Reset Data" /><br />\r
271                                 <textarea class="skinedit" tabindex="8" rows="20" cols="80" name="content"><?PHP echo htmlspecialchars($content) ?></textarea>\r
272                                 <input type="submit" tabindex="140" value="<?php echo "Save changes"?>" onclick="return checkSubmit();" />\r
273                                 <input type="reset" value="Reset Data" /><br />\r
274                         </form>\r
275                 <?PHP\r
276         }\r
277 \r
278 \r
279         function renfile() {\r
280                 global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
281                 if (isset($_POST['newname'])) {\r
282                         $splitpath =  preg_split( "/\//", strrev($_POST["oldname"]), 2);\r
283                         $newname = strrev($splitpath[1]) .'/'. $_POST["newname"];\r
284                         $newname = preg_replace("/^\//", "", $newname);\r
285                         $res = rename ( $DIR_SKINS.$SKINSUBDIR.$_POST["oldname"], \r
286                                 $DIR_SKINS.$SKINSUBDIR.$newname);\r
287                         if ($res) { \r
288                                 $msg = "File successfully renamed."; \r
289                         } else {\r
290                                 $msg = "File could not be renamed - (check to see if another file already exists with the new name).";\r
291                         }\r
292                         showdir($msg);\r
293                 } else { \r
294                         echo '<h3><b>Rename file "/'.$_GET["rfp"].'":</b></h3>';\r
295                         $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);\r
296                         $file = strrev($splitpath[0]);\r
297                         $parent = strrev($splitpath[1]);\r
298                         echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Cancel rename</a><br />';                \r
299                         ?>\r
300                                 <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
301                                         <input type="hidden" name="action" value="renfile" />\r
302                                         <input type="hidden" name="oldname" value="<?php echo $_GET["rfp"] ?>"/>\r
303                                         <input type="hidden" name="dir" value="<?php echo "/$parent" ?>"/>\r
304                                         <table><tr>\r
305                                                 <td><?php echo 'Rename to'?></td>\r
306                                                 <td><input name="newname" tabindex="90" value="<?php echo  htmlspecialchars($file) ?>" maxlength="50" size="20" /></td>\r
307                                         </tr><tr>\r
308                                                 <td><?php echo "Rename"?></td>\r
309                                                 <td><input type="submit" tabindex="140" value="<?php echo "Rename this file"?>" onclick="return checkSubmit();" /></td>\r
310                                         </tr></table>\r
311                                 </form>\r
312                         <?PHP\r
313                 }\r
314         }\r
315 \r
316         function delfile() {\r
317                 global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
318                 if (isset($_GET['sure'])) { \r
319                         $file = $DIR_SKINS.$SKINSUBDIR.$_GET["rfp"];\r
320                         $errrep = error_reporting(E_ERROR);\r
321                         if (unlink ($file)) {\r
322                                 $msg = 'File "'.$_GET["rfp"].'" has been deleted.';\r
323                         } else {\r
324                                 $msg = 'ERROR: File "'.$_GET["rfp"].'" could not be deleted.';\r
325                         }\r
326                         error_reporting($errrep);\r
327                         showdir($msg);\r
328                 } else {\r
329                         $file = $DIR_SKINS.$SKINSUBDIR.$_GET["rfp"];\r
330                         $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);\r
331                         $parent = strrev($splitpath[1]);\r
332                         echo '<h3><b>Delete file "'.$_GET["rfp"].'": are you sure?</b></h3>';\r
333                         echo '<b>This action cannot be undone!</b><br /><br />';\r
334                         echo "> <a href=\"$pluginsskinfiles/?action=delfile&dir=$parent&sure=y&rfp=".$_GET["rfp"]."\">Yes, delete the file.</a><br />";         \r
335                         echo "> <a href=\"$pluginsskinfiles/?dir=".$parent.'">No, go back.</a><br />';          \r
336                 }\r
337         }\r
338 \r
339         function deldir() {\r
340                 global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
341                 if (isset($_GET['sure'])) { \r
342                         $dir = $DIR_SKINS.$SKINSUBDIR.$_GET["remdir"];\r
343                         $errrep = error_reporting(E_ERROR);\r
344                         if (rmdir ($dir)) {\r
345                                 $msg = 'Directory "'.$_GET["remdir"].'" has been deleted.';\r
346                         } else {\r
347                                 $msg = 'ERROR: directory "'.$_GET["remdir"].'" could not be deleted - (check to see if it contains files).';\r
348                         }\r
349                         error_reporting($errrep);\r
350                         showdir($msg);\r
351                 } else {\r
352                         $dir = preg_replace("/^\//", "",$_GET['remdir']);\r
353                         $parent = $_GET['dir'];\r
354                         echo '<h3><b>Delete directory "/'.$dir.'": are you sure?</b></h3>';\r
355                         echo '<b>This action cannot be undone!</b><br /><br />';\r
356                         echo "> <a href=\"$pluginsskinfiles/?action=deldir&sure=y&remdir=$dir&dir=$parent\">Yes, delete the directory (it must be empty to do this).</a><br /><br />";          \r
357                         echo "> <a href=\"$pluginsskinfiles/?dir=".$parent.'">No, go back.</a><br />';          \r
358                 }\r
359         }\r
360 \r
361         function deleteAllInDir() {\r
362                 global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
363                 $parent = $DIR_SKINS.$SKINSUBDIR.preg_replace("/^\//", "",$_GET['dir']);\r
364                 if ($dh = @opendir($parent)) { \r
365                         while (($file = readdir($dh)) !== false) { \r
366                                 if(!preg_match("/^\.{1,2}/", $file)){\r
367                                         if (!is_dir($parent.$file)) {\r
368                                                 $files[] = $file;\r
369                                         }\r
370                                 }\r
371                         }\r
372                         closedir($dh); \r
373                 } \r
374                 if (isset($_GET['sure'])) { \r
375                         $errrep = error_reporting(E_ERROR);\r
376                         echo '<h3>Deletion results</h3><table>';\r
377                         echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET["dir"]."\">Return to the /".$_GET["dir"]." directory.</a><br />";              \r
378                         foreach ($files as $file) {\r
379                                 if (unlink ("$parent/$file")) { \r
380                                         echo "<tr><td>File: $file was deleted.</td></tr>"; \r
381                                 } else {\r
382                                         echo "<tr><td>File: $file was <b>NOT</b> deleted.</td></tr>";\r
383                                 }\r
384                         }\r
385                         echo "</table>";\r
386                         error_reporting($errrep);\r
387                         echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET["dir"]."\">Return to the /".$_GET["dir"]." directory.</a><br />";              \r
388                 } else {\r
389                         echo '<h3><b>Delete all files in directory "/'.$_GET['dir'].'": are you sure?</b></h3>';\r
390                         echo '<b>This action cannot be undone!</b><br /><br />';\r
391                         echo "> <a href=\"$pluginsskinfiles/?action=deleteAllInDir&sure=y&dir=".$_GET["dir"]."\">Yes, delete <u>all files</u> in this directory.</a><br />";            \r
392                         echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET['dir'].'">No, go back.</a><br /><br />';               \r
393                         echo '<b>Files list:</b><table>';\r
394                         foreach ($files as $file) {     echo "<tr><td>$file</td></tr>"; }\r
395                         echo '</table>';\r
396                 }\r
397         }\r
398 \r
399         // function for MDNucleus; won't work unless $privateskins is set to true\r
400         function getLatestSkins() {\r
401                 global $DIR_SKINS, $pluginsskinfiles, $privateskins, $latestskins, $member;\r
402                 $confirmed = $_POST['overwrite'];\r
403                 if (!$confirmed) {\r
404                         showdir("Overwrite of default skin files not confirmed - no action taken.");\r
405                         return;\r
406                 }\r
407                 if ($dh = @opendir($DIR_SKINS.$latestskins)) { \r
408                         while (($file = readdir($dh)) !== false) { \r
409                                 if(!preg_match("/^\.{1,2}/", $file))\r
410                                         if (is_dir($DIR_SKINS.$latestskins.$file)) $skins[] = $file;\r
411                         }\r
412                         closedir($dh); \r
413                 } \r
414                 if ($skins) {\r
415                         $msg = "Refreshed skin folders:";\r
416                         sort ($skins);\r
417                         foreach ($skins as $skin) {\r
418                                 $memberskin = $DIR_SKINS.$member->getID().'/'.$skin;\r
419                                 if (is_file($memberskin)) unlink($memberskin);\r
420                                 if (!is_dir($memberskin)) {\r
421                                         $old_umask = umask(0);\r
422                                         mkdir($memberskin, 0755);\r
423                                         umask($old_umask);\r
424                                 }\r
425                                 exec("rsync -Wtr --delete ".$DIR_SKINS.$latestskins.$skin."/* ".$memberskin.'/');\r
426                                 $msg .= "  $skin";\r
427                         }\r
428                 } else {\r
429                         showdir("No default skin folders found.  No action taken.");\r
430                         return;\r
431                 }\r
432                 showdir($msg);\r
433         }\r
434 \r
435         function _isImageFile($file) {\r
436                 return preg_match ("/\.(gif|png|jpg|jpeg|bmp|ico)$/i", $file);\r
437         }\r
438 \r
439         function _isEditableFile($file) {\r
440                 return preg_match ("/\.(inc|txt|htm|html|xml)$/i", $file);\r
441         }\r
442 \r
443         function showdir($msg = '') {\r
444                 global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles, $CONF;\r
445                 global $privateskins, $latestskins;\r
446                 if (isset($_GET['dir'])) { \r
447                         $newdir = preg_replace("/^\//", "",$_GET['dir']);\r
448                         $currdir = $DIR_SKINS.$SKINSUBDIR."$newdir/";\r
449                         $in_subdir = 1;\r
450                 } elseif (isset($_POST['dir'])) { \r
451                         $newdir = preg_replace("/^\//", "",$_POST['dir']);\r
452                         $currdir = $DIR_SKINS.$SKINSUBDIR."$newdir/";\r
453                         $in_subdir = 1;\r
454                 } else {\r
455                         $newdir = '';\r
456                         $currdir = $DIR_SKINS.$SKINSUBDIR;\r
457                         $in_subdir = 0;\r
458                 }\r
459         \r
460                 if ($privateskins && (!is_dir($DIR_SKINS.$SKINSUBDIR))) {\r
461                         $oldumask = umask(0);\r
462                         mkdir($DIR_SKINS.$SKINSUBDIR, 0755);\r
463                         umask($oldmask);\r
464                 }\r
465 \r
466                 if (!is_dir($currdir)) {\r
467                         echo 'The specified location is not a directory or doesn\'t exist.';\r
468                         return;\r
469                 }\r
470                 \r
471                 if ($dh = @opendir($currdir)) { \r
472                         while (($file = readdir($dh)) !== false) { \r
473                                 if(!preg_match("/^\.{1,2}/", $file)){\r
474                                         if (is_dir($currdir.$file)) {\r
475                                                 $dirs[] = $file;\r
476                                         } else {\r
477                                                 $files[] = $file;\r
478                                         }\r
479                                 }\r
480                         }\r
481                         closedir($dh); \r
482                 } \r
483                 \r
484                 echo "<h3>Current Directory: <b>/$newdir</b></h3>";\r
485                 \r
486                 if ($msg) {\r
487                         echo '<p><b>'.htmlspecialchars($msg).'</b></p>';\r
488                 }\r
489                 \r
490                 if ($newdir != '') {\r
491                         echo "<u><a href=\"$pluginsskinfiles/\">> Return to / <</a></u><br />";\r
492                         if (strstr($newdir, '/')) {\r
493                                 $splitpath =  preg_split( "/\//", strrev($newdir), 2);\r
494                                 $updir = strrev($splitpath[1]);\r
495                                 echo "<u><a href=\"$pluginsskinfiles/?dir=/$updir\">> Return to /$updir <</a></u><br /><br />";\r
496                         }\r
497                 }\r
498                 echo "<u><a href=\"$pluginsskinfiles/?dir=$newdir\">> Refresh <</a></u><br />";\r
499 \r
500                 echo "<table>";\r
501                 if(is_array($dirs)){\r
502                         sort($dirs);\r
503                         foreach($dirs as $dir) {\r
504                                 echo "<tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'><td>";\r
505                                 echo "&nbsp;&nbsp;<a href=\"$pluginsskinfiles/?dir=$newdir/$dir\">";\r
506                                 echo "<img src=\"$pluginsskinfiles/dir.gif\"> $dir</a>&nbsp;</td>";\r
507                                 echo "<td>&nbsp;<a href=\"$pluginsskinfiles/?action=rendir&oldname=$newdir/$dir\" title=\"Rename directory\">(ren)</a></td>";\r
508                                 echo "<td>&nbsp;<a href=\"$pluginsskinfiles/?action=deldir&dir=$newdir&remdir=$newdir/$dir\" title=\"Delete directory\">(del)</a></td>";\r
509                                 echo "</td><td></td><td></td><td></td><td>";\r
510                                 echo "<td>".date('M d, Y  h:i:s a', filemtime($DIR_SKINS.$SKINSUBDIR.$newdir."/$dir"));\r
511                                 echo "</td></tr>";\r
512                         }\r
513                 }\r
514         \r
515                 if(is_array($files)){\r
516                         sort($files);\r
517                         foreach($files as $file) {\r
518                                 echo "<tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'><td>";\r
519                                 echo "&nbsp;&nbsp;";\r
520                                 if (preg_match("/\.css$/i", $file)) {\r
521                                         echo "<img src=\"$pluginsskinfiles/css.gif\"> ";\r
522                                 } elseif (preg_match("/\.php(3|4)?$/i", $file)) {\r
523                                         echo "<img src=\"$pluginsskinfiles/php.gif\"> ";\r
524                                 } elseif (_isEditableFile($file)) {\r
525                                         echo "<img src=\"$pluginsskinfiles/text.gif\"> ";\r
526                                 } elseif (_isImageFile($file)) {\r
527                                         echo "<img src=\"$pluginsskinfiles/image.gif\"> ";\r
528                                 } else {\r
529                                         echo "<img src=\"$pluginsskinfiles/generic.png\"> ";\r
530                                 }\r
531                                 if ($newdir == '') {$thisdir = '';} else {$thisdir = "$newdir/";}\r
532                                 echo "$file&nbsp;";\r
533                                 echo "</td><td>";\r
534                                 echo "&nbsp;<a href=\"$pluginsskinfiles/?action=renfile&rfp=$thisdir"."$file\" title=\"Rename file\">(ren)</a>";\r
535                                 echo "</td><td>";\r
536                                 echo "&nbsp;<a href=\"$pluginsskinfiles/?action=delfile&rfp=$thisdir"."$file\" title=\"Delete file\">(del)</a>";\r
537                                 echo "</td><td>";\r
538                                 if ((is_writable($DIR_SKINS.$SKINSUBDIR.$thisdir.$file)) && (!_isImageFile($file))) {\r
539                                         echo "&nbsp;<a href=\"$pluginsskinfiles/?action=editfile&rfp=$thisdir"."$file\" title=\"Edit file\">(edit)</a>";\r
540                                 }\r
541                                 echo "</td><td>";\r
542                                 if (_isImageFile($file)) {\r
543                                         echo '&nbsp;<a href="'.$CONF['SkinsURL'].$SKINSUBDIR.$thisdir."$file\" title=\"View graphic\">(view)</a>";\r
544                                 }\r
545                                 echo "</td><td>";\r
546                                 echo "&nbsp;<a href=\"$pluginsskinfiles/?action=download&rfp=$thisdir"."$file\" title=\"Download file\">(d/l)</a>";\r
547                                 echo "</td><td>";\r
548                                 echo number_format(filesize($DIR_SKINS.$SKINSUBDIR.$thisdir.$file)/1024, 2)." KB";\r
549                                 echo "</td><td>";\r
550                                 echo date('M d, Y  h:i:s a', filemtime($DIR_SKINS.$SKINSUBDIR.$thisdir.$file));\r
551                                 echo "</td></tr>";\r
552                         }\r
553                 }\r
554                 echo "</table>";\r
555         \r
556                 if(is_array($dirs) || is_array($files)) {\r
557                         if ($newdir != '') {\r
558                                 echo "<u><a href=\"$pluginsskinfiles/\">> Return to / <</a></u><br />";\r
559                                 if (strstr($newdir, '/')) {\r
560                                         $splitpath =  preg_split( "/\//", strrev($newdir), 2);\r
561                                         $updir = strrev($splitpath[1]);\r
562                                         echo "<u><a href=\"$pluginsskinfiles/?dir=/$updir\">> Return to /$updir <</a></u><br /><br />";\r
563                                 }\r
564                         }\r
565                         echo "<u><a href=\"$pluginsskinfiles/?dir=$newdir\">> Refresh <</a></u><br />";\r
566                 }\r
567 \r
568                 if ($newdir != '') {\r
569                         echo "<h3>Create new file in <b>/$newdir</b></h3>";\r
570                                 ?>\r
571                                 <form method="POST" enctype="multipart/form-data" action="<?php echo $pluginsskinfiles ?>/">\r
572                                                 <input type="hidden" name="action" value="createfile" />\r
573                                                 <input type="hidden" name="dir" value="<?php echo $newdir ?>">\r
574                                                 <input type="text" name="filename" size="40">\r
575                                                 <input type="submit" value="<?php echo 'Create file' ?>" />\r
576                                         </form>\r
577                                 <?PHP\r
578 \r
579                                 echo "<h3>Upload new file to <b>/$newdir</b></h3>";\r
580                                 ?>\r
581                                 <form method="POST" enctype="multipart/form-data" action="<?php echo $pluginsskinfiles ?>/">\r
582                                                 <input type="hidden" name="action" value="uploadfile" />\r
583                                                 <input type="hidden" name="dir" value="<?php echo $newdir ?>">\r
584                                                 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" />\r
585                                                 <input type="file" name="filename" size="40">\r
586                                                 <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" />\r
587                                         </form>\r
588                                 <?PHP\r
589         \r
590                         if (count($files)) {\r
591                                 echo "<h3>Delete all files in <b>/$newdir</b></h3>";\r
592                                         ?>\r
593                                                 <form method="get" action="<?php echo $pluginsskinfiles?>/">\r
594                                                         <input type="hidden" name="action" value="deleteAllInDir" />\r
595                                                         <input type="hidden" name="dir" value="<?php echo $newdir?>"/>\r
596                                                         <?php echo "Delete all Files? (will ask for confirmation)"?>\r
597                                                         <input type="submit" tabindex="140" value="<?php echo "Delete All"?>" onclick="return checkSubmit();" />\r
598                                                 </form>\r
599                                         <?PHP\r
600                         }\r
601                 }\r
602         \r
603                 echo "<h3>Create a new directory in <b>/$newdir</b></h3>"; \r
604                                 ?>\r
605                                         <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
606                                                 <input type="hidden" name="action" value="createdir" />\r
607                                                 <input type="hidden" name="dir" value="<?php echo $newdir?>"/>\r
608                                                 <input name="newdir" tabindex="90" value="<?php echo 'newdir' ?>" size="40" />\r
609                                                 <input type="submit" tabindex="140" value="<?php echo "Create"?>" onclick="return checkSubmit();" />\r
610                                         </form>\r
611                                 <?PHP\r
612 \r
613                 // for MDNucleus, ignored if on Win32 platform (for the moment)\r
614                 if (($newdir == '') && ($privateskins) && (!strtoupper(substr(PHP_OS, 0,3) == 'WIN'))) {\r
615                         if ($dh = @opendir($DIR_SKINS.$latestskins)) { \r
616                                 while (($file = readdir($dh)) !== false) { \r
617                                         if(!preg_match("/^\.{1,2}/", $file))\r
618                                                 if (is_dir($DIR_SKINS.$latestskins.$file)) $skins[] = $file;\r
619                                 }\r
620                                 closedir($dh); \r
621                         }\r
622                         if ($skins) {\r
623                                 echo "<h3>Refresh default skin files to standard versions</h3>";\r
624                                 ?>\r
625                                         <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
626                                                 <input type="hidden" name="action" value="getLatestSkins" />\r
627                                                 <?php\r
628                                                 sort ($skins);\r
629                                                 if (count($skins) > 1) {\r
630                                                         $lastskin = array_pop($skins);\r
631                                                         array_push($skins, "</b>and<b> $lastskin");\r
632                                                 }\r
633                                                 echo "This will overwrite or create files in the following skin file directories: <b>";\r
634                                                 echo implode(", ", $skins)."</b><br /><br />"; \r
635                                                 ?> \r
636                                                 Note that you may need to re-import skin definitions you wish to use (See Layout Import/Export).<br /><br />\r
637                                                 <input type="checkbox" name="overwrite" value="1" id="cb_overwrite" />\r
638                                                 <label for="cb_overwrite"><?php echo "Check this box to confirm overwrite of files<br />" ?></label>\r
639                                                 <input type="submit" tabindex="140" value="<?php echo "Overwrite Default Skin Files"?>" onclick="return checkSubmit();" />\r
640                                         </form>\r
641                                 <?PHP\r
642                         }\r
643                 }\r
644 \r
645         }\r
646 \r
647         \r
648         \r
649 ?>