OSDN Git Service

merged 3.3 beta1
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / plugins / skinfiles / index.php
index a23e3ee..a102c35 100644 (file)
-<?php\r
-\r
-/*                                       */\r
-/* Admin page for NP_SkinFiles           */\r
-/* ------------------------------------  */\r
-/* A simple skin files manager           */\r
-/*                                       */\r
-/* code by Jeff MacMichael               */\r
-/* http://gednet.com/                    */\r
-/*                                       */\r
-/* version 1.01                          */\r
\r
-       $strRel = '../../../'; \r
-       include($strRel . 'config.php');\r
-       \r
-       include($DIR_LIBS . 'PLUGINADMIN.php');\r
-\r
-       if (preg_match("/MD$/", $nucleus['version'])) {\r
-               $isblogadmin = $member->isBlogAdmin(-1);\r
-       } else {\r
-               $isblogadmin = $member->isBlogAdmin($blogid);\r
-       }\r
-       if (!($member->isAdmin() || $isblogadmin)) {\r
-               $oPluginAdmin = new PluginAdmin('SkinFiles');\r
-               $oPluginAdmin->start();\r
-               echo "<p>"._ERROR_DISALLOWED."</p>";\r
-               $oPluginAdmin->end();\r
-               exit;\r
-       }\r
-\r
-       // set to FALSE for normal operation, or TRUE if skins are stored\r
-       // under owner's member id i.e. /skins/1/grey/...   (MDNucleus)\r
-       $privateskins = FALSE;\r
-       if ($privateskins) { \r
-               global $member;\r
-               $SKINSUBDIR = $member->getID().'/'; \r
-               $latestskins = 'latest-skins/';\r
-       } else {\r
-               $SKINSUBDIR = '';\r
-       }\r
-       \r
-       global $pluginsskinfiles, $CONF;\r
-       $pluginsskinfiles=$CONF['PluginURL']."skinfiles";\r
-\r
-       if (isset($_GET['action'])) {$action = $_GET['action'];}\r
-       if (isset($_POST['action'])) {$action = $_POST['action'];}\r
-\r
-       if ($action == 'download') { \r
-               download();\r
-               return;\r
-               break;\r
-       }\r
-\r
-       // create the admin area page\r
-       $oPluginAdmin = new PluginAdmin('SkinFiles');\r
-       $oPluginAdmin->start();\r
-       \r
-       echo "<h2>Skin File Management</h2>";\r
-       \r
-       if (strstr('renfile delfile createdir rendir deldir deleteAllInDir'\r
-               .' editfile uploadfile createfile getLatestSkins', $action)) { \r
-               call_user_func($action);\r
-       } else {\r
-               showdir();\r
-       }\r
-\r
-       $oPluginAdmin->end();\r
-       return;\r
-       break;\r
-               \r
-       function createfile() {\r
-               global $oPluginAdmin, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
-               $parent = $_POST["dir"];\r
-               $filename = $_POST["filename"];\r
-               $fullpath = $DIR_SKINS.$SKINSUBDIR.$parent.'/'.$filename;\r
-               if (file_exists($fullpath)) {\r
-                       $msg = "Error: the file '$filename' already exists.";\r
-                       showdir($msg);\r
-               }\r
-               echo "<h3><b>Creating file \"/$parent/$filename\":</b></h3>";\r
-               $errrep = error_reporting(E_ERROR);\r
-               if (touch($fullpath)) { \r
-                       $msg = 'The file was created successfully.';\r
-               } else {\r
-                       $msg = 'ERROR: The file was <i>not</i> created successfully.';\r
-               }\r
-               $oldumask = umask(0000);\r
-               chmod($fullpath, 0755);\r
-               umask($oldumask);\r
-               error_reporting($errrep);\r
-               showdir($msg);\r
-       }\r
-\r
-       function createdir() {\r
-               global $oPluginAdmin, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
-               $parent = $_POST["dir"];\r
-               $newdir = $_POST["newdir"];\r
-               if (!$newdir) {\r
-                       echo 'You need to specify a directory name to create. <br /><br />';\r
-                       echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Go back</a><br />';              \r
-                       return;\r
-               }\r
-               $errrep = error_reporting(E_ERROR);\r
-               $oldumask = umask(0000);\r
-               if (mkdir ($DIR_SKINS.$SKINSUBDIR.$parent.'/'.$newdir, 0755)) {\r
-                       $msg = 'Directory created successfully.';\r
-               } else {\r
-                       $msg = 'There was an error creating the directory (check to see if the directory already exists).';\r
-               }\r
-               umask($oldumask);\r
-               error_reporting($errrep);\r
-               showdir($msg);\r
-       }\r
-       \r
-       function download() {\r
-               global $DIR_SKINS, $SKINSUBDIR;\r
-               $file = $_GET["rfp"];\r
-               $path = $DIR_SKINS.$SKINSUBDIR.$file;\r
-               $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);\r
-               $file = strrev($splitpath[0]);\r
-               \r
-               // download code taken from Paul Alger's PHP_Easy_Download. \r
-\r
-               // translate file name properly for Internet Explorer.\r
-               if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){\r
-                       $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1);\r
-               }\r
-               // make sure the file exists before sending headers\r
-               if(!$fdl=@fopen($path,'r')){\r
-                       die("Cannot Open File!");\r
-               } else {\r
-                       header("Cache-Control: ");// leave blank to avoid IE errors\r
-                       header("Pragma: ");// leave blank to avoid IE errors\r
-                       header("Content-type: application/octet-stream");\r
-                       header('Content-Disposition: attachment; filename="'.$file.'"');\r
-                       header("Content-length: ".(string)(filesize($path)));\r
-                       sleep(1);\r
-                       \r
-                       fpassthru($fdl);\r
-               }\r
-               return;\r
-               break;\r
-       }\r
-       \r
-       function uploadfile() {\r
-               global $HTTP_POST_FILES, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles, $CONF;\r
-               $filename = $HTTP_POST_FILES['filename']['name'];\r
-               $filesize = $HTTP_POST_FILES['filename']['size'];\r
-               $filetempname = $HTTP_POST_FILES['filename']['tmp_name'];\r
-               $todir = $DIR_SKINS.$SKINSUBDIR.$_POST['dir'].'/';\r
-               \r
-               if ($filesize > $CONF['MaxUploadSize']) {\r
-                       showdir(_ERROR_FILE_TOO_BIG);\r
-                       return;\r
-               }\r
-\r
-               // check file type against allowed types\r
-               $ok = 0;\r
-               $allowedtypes = explode (',', "css,html,htm,xml,inc,txt,".$CONF['AllowedTypes']);\r
-               foreach ( $allowedtypes as $type ) \r
-                       if (eregi("\." .$type. "$",$filename)) $ok = 1;    \r
-               if (!$ok) {\r
-                       showdir(_ERROR_BADFILETYPE);\r
-                       return;\r
-               }\r
-               if (!is_uploaded_file($filetempname)) {\r
-                       showdir(_ERROR_BADREQUEST);\r
-                       return;\r
-               }\r
-               if (file_exists($todir.$filename)) {\r
-                       showdir(_ERROR_UPLOADDUPLICATE);\r
-                       return;\r
-               }\r
-\r
-               // move file to directory\r
-               if (is_uploaded_file($filetempname)) {\r
-                       $errrep = error_reporting(E_ERROR);\r
-                       if (!@move_uploaded_file($filetempname, $todir . $filename)) {\r
-                               showdir(_ERROR_UPLOADMOVE);\r
-                               return;\r
-                       }\r
-                       error_reporting($errrep);\r
-               }\r
-               // chmod uploaded file\r
-               $oldumask = umask(0000);\r
-               @chmod($todir . $filename, 0755); \r
-               umask($oldumask);               \r
-\r
-               showdir("File uploaded successfully.");\r
-       }\r
-\r
-       function rendir() {\r
-               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
-               if (isset($_POST['newname'])) {\r
-                       $splitpath =  preg_split( "/\//", strrev($_POST["oldname"]), 2);\r
-                       $newname = strrev($splitpath[1]) .'/'. $_POST["newname"];\r
-                       $newname = preg_replace("/^\//", "", $newname);\r
-                       $res = rename ( $DIR_SKINS.$SKINSUBDIR.$_POST["oldname"], \r
-                               $DIR_SKINS.$SKINSUBDIR.$newname);\r
-                       if ($res) { \r
-                               $msg = "Directory successfully renamed."; \r
-                       } else {\r
-                               $msg = "Failed to rename directory - (check to see if another directory already exists with the new name).";\r
-                       }\r
-                       showdir($msg);\r
-               } else { \r
-                       $oldname = preg_replace("/^\//", "", $_GET["oldname"]);\r
-                       echo '<h3><b>Rename directory "/'.$oldname.'":</b></h3>';\r
-                       $splitpath =  preg_split( "/\//", strrev($_GET["oldname"]), 2);\r
-                       $dir = strrev($splitpath[0]);\r
-                       $parent = strrev($splitpath[1]);\r
-                       echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Cancel rename</a><br />';                \r
-                       ?>\r
-                               <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
-                                       <input type="hidden" name="action" value="rendir" />\r
-                                       <input type="hidden" name="dir" value="<?php echo "/$parent" ?>"/>\r
-                                       <input type="hidden" name="oldname" value="<?php echo $oldname?>"/>\r
-                                       <table><tr>\r
-                                               <td><?php echo 'Rename to'?></td>\r
-                                               <td><input name="newname" tabindex="90" value="<?php echo  htmlspecialchars($dir) ?>" maxlength="50" size="20" /></td>\r
-                                       </tr><tr>\r
-                                               <td><?php echo "Rename"?></td>\r
-                                               <td><input type="submit" tabindex="140" value="<?php echo "Rename this folder"?>" onclick="return checkSubmit();" /></td>\r
-                                       </tr></table>\r
-                               </form>\r
-                       <?PHP\r
-               }\r
-       }\r
-\r
-       function editfile () {\r
-               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
-               if (isset ($_POST['rfp']) && isset($_POST['content'])) {\r
-                       $file = $_POST['rfp'];\r
-                       $errrep = error_reporting(E_ERROR);\r
-                       $success = true;\r
-                       if ($fh = @fopen($DIR_SKINS.$SKINSUBDIR.$file, 'w')) { \r
-                               if (fwrite ($fh, trim(stripslashes($_POST['content'])))) {\r
-                                       fclose($fh);\r
-                               } else {\r
-                                       $success = false;\r
-                               }\r
-                       } else {\r
-                               $success = false;\r
-                       }\r
-                       error_reporting($errrep);\r
-                       if ($success) {\r
-                               $msg = 'File was edited successfully.';\r
-                       } else {\r
-                               $msg = 'ERROR: File was <i>not</i> saved successfully.';\r
-                       }\r
-               }\r
-               if (isset ($_GET['rfp'])) { $file = $_GET['rfp']; }\r
-               if (isset ($_POST['rfp'])) { $file = $_POST['rfp']; }\r
-               $splitpath =  preg_split( "/\//", strrev($file), 2);\r
-               $parent = strrev($splitpath[1]);\r
-               echo '<h3>Editing file "/'.$file.'":</h3>';\r
-               if (isset($msg)) { echo "<p><b>$msg</b></p>"; }\r
-               echo "> <a href=\"$pluginsskinfiles/?dir=$parent\"> Cancel/Return to /$parent</a><br /><br />";\r
-               $fh = @fopen($DIR_SKINS.$SKINSUBDIR.$file, 'r');\r
-               while (!feof($fh)) { \r
-                       $content .= fread($fh, 4096); \r
-               }\r
-               fclose ($fh);                   \r
-               ?>\r
-                       <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
-                               <input type="hidden" name="action" value="editfile" />\r
-                               <input type="hidden" name="rfp" value="<?php echo $file ?>"/>\r
-                               <input type="hidden" name="dir" value="<?php echo $parent ?>"/>\r
-                               <input type="submit" tabindex="140" value="<?php echo "Save changes"?>" onclick="return checkSubmit();" />\r
-                               <input type="reset" value="Reset Data" /><br />\r
-                               <textarea class="skinedit" tabindex="8" rows="20" cols="80" name="content"><?PHP echo htmlspecialchars($content) ?></textarea>\r
-                               <input type="submit" tabindex="140" value="<?php echo "Save changes"?>" onclick="return checkSubmit();" />\r
-                               <input type="reset" value="Reset Data" /><br />\r
-                       </form>\r
-               <?PHP\r
-       }\r
-\r
-\r
-       function renfile() {\r
-               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
-               if (isset($_POST['newname'])) {\r
-                       $splitpath =  preg_split( "/\//", strrev($_POST["oldname"]), 2);\r
-                       $newname = strrev($splitpath[1]) .'/'. $_POST["newname"];\r
-                       $newname = preg_replace("/^\//", "", $newname);\r
-                       $res = rename ( $DIR_SKINS.$SKINSUBDIR.$_POST["oldname"], \r
-                               $DIR_SKINS.$SKINSUBDIR.$newname);\r
-                       if ($res) { \r
-                               $msg = "File successfully renamed."; \r
-                       } else {\r
-                               $msg = "File could not be renamed - (check to see if another file already exists with the new name).";\r
-                       }\r
-                       showdir($msg);\r
-               } else { \r
-                       echo '<h3><b>Rename file "/'.$_GET["rfp"].'":</b></h3>';\r
-                       $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);\r
-                       $file = strrev($splitpath[0]);\r
-                       $parent = strrev($splitpath[1]);\r
-                       echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Cancel rename</a><br />';                \r
-                       ?>\r
-                               <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
-                                       <input type="hidden" name="action" value="renfile" />\r
-                                       <input type="hidden" name="oldname" value="<?php echo $_GET["rfp"] ?>"/>\r
-                                       <input type="hidden" name="dir" value="<?php echo "/$parent" ?>"/>\r
-                                       <table><tr>\r
-                                               <td><?php echo 'Rename to'?></td>\r
-                                               <td><input name="newname" tabindex="90" value="<?php echo  htmlspecialchars($file) ?>" maxlength="50" size="20" /></td>\r
-                                       </tr><tr>\r
-                                               <td><?php echo "Rename"?></td>\r
-                                               <td><input type="submit" tabindex="140" value="<?php echo "Rename this file"?>" onclick="return checkSubmit();" /></td>\r
-                                       </tr></table>\r
-                               </form>\r
-                       <?PHP\r
-               }\r
-       }\r
-\r
-       function delfile() {\r
-               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
-               if (isset($_GET['sure'])) { \r
-                       $file = $DIR_SKINS.$SKINSUBDIR.$_GET["rfp"];\r
-                       $errrep = error_reporting(E_ERROR);\r
-                       if (unlink ($file)) {\r
-                               $msg = 'File "'.$_GET["rfp"].'" has been deleted.';\r
-                       } else {\r
-                               $msg = 'ERROR: File "'.$_GET["rfp"].'" could not be deleted.';\r
-                       }\r
-                       error_reporting($errrep);\r
-                       showdir($msg);\r
-               } else {\r
-                       $file = $DIR_SKINS.$SKINSUBDIR.$_GET["rfp"];\r
-                       $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);\r
-                       $parent = strrev($splitpath[1]);\r
-                       echo '<h3><b>Delete file "'.$_GET["rfp"].'": are you sure?</b></h3>';\r
-                       echo '<b>This action cannot be undone!</b><br /><br />';\r
-                       echo "> <a href=\"$pluginsskinfiles/?action=delfile&dir=$parent&sure=y&rfp=".$_GET["rfp"]."\">Yes, delete the file.</a><br />";         \r
-                       echo "> <a href=\"$pluginsskinfiles/?dir=".$parent.'">No, go back.</a><br />';          \r
-               }\r
-       }\r
-\r
-       function deldir() {\r
-               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
-               if (isset($_GET['sure'])) { \r
-                       $dir = $DIR_SKINS.$SKINSUBDIR.$_GET["remdir"];\r
-                       $errrep = error_reporting(E_ERROR);\r
-                       if (rmdir ($dir)) {\r
-                               $msg = 'Directory "'.$_GET["remdir"].'" has been deleted.';\r
-                       } else {\r
-                               $msg = 'ERROR: directory "'.$_GET["remdir"].'" could not be deleted - (check to see if it contains files).';\r
-                       }\r
-                       error_reporting($errrep);\r
-                       showdir($msg);\r
-               } else {\r
-                       $dir = preg_replace("/^\//", "",$_GET['remdir']);\r
-                       $parent = $_GET['dir'];\r
-                       echo '<h3><b>Delete directory "/'.$dir.'": are you sure?</b></h3>';\r
-                       echo '<b>This action cannot be undone!</b><br /><br />';\r
-                       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
-                       echo "> <a href=\"$pluginsskinfiles/?dir=".$parent.'">No, go back.</a><br />';          \r
-               }\r
-       }\r
-\r
-       function deleteAllInDir() {\r
-               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;\r
-               $parent = $DIR_SKINS.$SKINSUBDIR.preg_replace("/^\//", "",$_GET['dir']);\r
-               if ($dh = @opendir($parent)) { \r
-                       while (($file = readdir($dh)) !== false) { \r
-                               if(!preg_match("/^\.{1,2}/", $file)){\r
-                                       if (!is_dir($parent.$file)) {\r
-                                               $files[] = $file;\r
-                                       }\r
-                               }\r
-                       }\r
-                       closedir($dh); \r
-               } \r
-               if (isset($_GET['sure'])) { \r
-                       $errrep = error_reporting(E_ERROR);\r
-                       echo '<h3>Deletion results</h3><table>';\r
-                       echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET["dir"]."\">Return to the /".$_GET["dir"]." directory.</a><br />";              \r
-                       foreach ($files as $file) {\r
-                               if (unlink ("$parent/$file")) { \r
-                                       echo "<tr><td>File: $file was deleted.</td></tr>"; \r
-                               } else {\r
-                                       echo "<tr><td>File: $file was <b>NOT</b> deleted.</td></tr>";\r
-                               }\r
-                       }\r
-                       echo "</table>";\r
-                       error_reporting($errrep);\r
-                       echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET["dir"]."\">Return to the /".$_GET["dir"]." directory.</a><br />";              \r
-               } else {\r
-                       echo '<h3><b>Delete all files in directory "/'.$_GET['dir'].'": are you sure?</b></h3>';\r
-                       echo '<b>This action cannot be undone!</b><br /><br />';\r
-                       echo "> <a href=\"$pluginsskinfiles/?action=deleteAllInDir&sure=y&dir=".$_GET["dir"]."\">Yes, delete <u>all files</u> in this directory.</a><br />";            \r
-                       echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET['dir'].'">No, go back.</a><br /><br />';               \r
-                       echo '<b>Files list:</b><table>';\r
-                       foreach ($files as $file) {     echo "<tr><td>$file</td></tr>"; }\r
-                       echo '</table>';\r
-               }\r
-       }\r
-\r
-       // function for MDNucleus; won't work unless $privateskins is set to true\r
-       function getLatestSkins() {\r
-               global $DIR_SKINS, $pluginsskinfiles, $privateskins, $latestskins, $member;\r
-               $confirmed = $_POST['overwrite'];\r
-               if (!$confirmed) {\r
-                       showdir("Overwrite of default skin files not confirmed - no action taken.");\r
-                       return;\r
-               }\r
-               if ($dh = @opendir($DIR_SKINS.$latestskins)) { \r
-                       while (($file = readdir($dh)) !== false) { \r
-                               if(!preg_match("/^\.{1,2}/", $file))\r
-                                       if (is_dir($DIR_SKINS.$latestskins.$file)) $skins[] = $file;\r
-                       }\r
-                       closedir($dh); \r
-               } \r
-               if ($skins) {\r
-                       $msg = "Refreshed skin folders:";\r
-                       sort ($skins);\r
-                       foreach ($skins as $skin) {\r
-                               $memberskin = $DIR_SKINS.$member->getID().'/'.$skin;\r
-                               if (is_file($memberskin)) unlink($memberskin);\r
-                               if (!is_dir($memberskin)) {\r
-                                       $old_umask = umask(0);\r
-                                       mkdir($memberskin, 0755);\r
-                                       umask($old_umask);\r
-                               }\r
-                               exec("rsync -Wtr --delete ".$DIR_SKINS.$latestskins.$skin."/* ".$memberskin.'/');\r
-                               $msg .= "  $skin";\r
-                       }\r
-               } else {\r
-                       showdir("No default skin folders found.  No action taken.");\r
-                       return;\r
-               }\r
-               showdir($msg);\r
-       }\r
-\r
-       function _isImageFile($file) {\r
-               return preg_match ("/\.(gif|png|jpg|jpeg|bmp|ico)$/i", $file);\r
-       }\r
-\r
-       function _isEditableFile($file) {\r
-               return preg_match ("/\.(inc|txt|htm|html|xml)$/i", $file);\r
-       }\r
-\r
-       function showdir($msg = '') {\r
-               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles, $CONF;\r
-               global $privateskins, $latestskins;\r
-               if (isset($_GET['dir'])) { \r
-                       $newdir = preg_replace("/^\//", "",$_GET['dir']);\r
-                       $currdir = $DIR_SKINS.$SKINSUBDIR."$newdir/";\r
-                       $in_subdir = 1;\r
-               } elseif (isset($_POST['dir'])) { \r
-                       $newdir = preg_replace("/^\//", "",$_POST['dir']);\r
-                       $currdir = $DIR_SKINS.$SKINSUBDIR."$newdir/";\r
-                       $in_subdir = 1;\r
-               } else {\r
-                       $newdir = '';\r
-                       $currdir = $DIR_SKINS.$SKINSUBDIR;\r
-                       $in_subdir = 0;\r
-               }\r
-       \r
-               if ($privateskins && (!is_dir($DIR_SKINS.$SKINSUBDIR))) {\r
-                       $oldumask = umask(0);\r
-                       mkdir($DIR_SKINS.$SKINSUBDIR, 0755);\r
-                       umask($oldmask);\r
-               }\r
-\r
-               if (!is_dir($currdir)) {\r
-                       echo 'The specified location is not a directory or doesn\'t exist.';\r
-                       return;\r
-               }\r
-               \r
-               if ($dh = @opendir($currdir)) { \r
-                       while (($file = readdir($dh)) !== false) { \r
-                               if(!preg_match("/^\.{1,2}/", $file)){\r
-                                       if (is_dir($currdir.$file)) {\r
-                                               $dirs[] = $file;\r
-                                       } else {\r
-                                               $files[] = $file;\r
-                                       }\r
-                               }\r
-                       }\r
-                       closedir($dh); \r
-               } \r
-               \r
-               echo "<h3>Current Directory: <b>/$newdir</b></h3>";\r
-               \r
-               if ($msg) {\r
-                       echo '<p><b>'.htmlspecialchars($msg).'</b></p>';\r
-               }\r
-               \r
-               if ($newdir != '') {\r
-                       echo "<u><a href=\"$pluginsskinfiles/\">> Return to / <</a></u><br />";\r
-                       if (strstr($newdir, '/')) {\r
-                               $splitpath =  preg_split( "/\//", strrev($newdir), 2);\r
-                               $updir = strrev($splitpath[1]);\r
-                               echo "<u><a href=\"$pluginsskinfiles/?dir=/$updir\">> Return to /$updir <</a></u><br /><br />";\r
-                       }\r
-               }\r
-               echo "<u><a href=\"$pluginsskinfiles/?dir=$newdir\">> Refresh <</a></u><br />";\r
-\r
-               echo "<table>";\r
-               if(is_array($dirs)){\r
-                       sort($dirs);\r
-                       foreach($dirs as $dir) {\r
-                               echo "<tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'><td>";\r
-                               echo "&nbsp;&nbsp;<a href=\"$pluginsskinfiles/?dir=$newdir/$dir\">";\r
-                               echo "<img src=\"$pluginsskinfiles/dir.gif\"> $dir</a>&nbsp;</td>";\r
-                               echo "<td>&nbsp;<a href=\"$pluginsskinfiles/?action=rendir&oldname=$newdir/$dir\" title=\"Rename directory\">(ren)</a></td>";\r
-                               echo "<td>&nbsp;<a href=\"$pluginsskinfiles/?action=deldir&dir=$newdir&remdir=$newdir/$dir\" title=\"Delete directory\">(del)</a></td>";\r
-                               echo "</td><td></td><td></td><td></td><td>";\r
-                               echo "<td>".date('M d, Y  h:i:s a', filemtime($DIR_SKINS.$SKINSUBDIR.$newdir."/$dir"));\r
-                               echo "</td></tr>";\r
-                       }\r
-               }\r
-       \r
-               if(is_array($files)){\r
-                       sort($files);\r
-                       foreach($files as $file) {\r
-                               echo "<tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'><td>";\r
-                               echo "&nbsp;&nbsp;";\r
-                               if (preg_match("/\.css$/i", $file)) {\r
-                                       echo "<img src=\"$pluginsskinfiles/css.gif\"> ";\r
-                               } elseif (preg_match("/\.php(3|4)?$/i", $file)) {\r
-                                       echo "<img src=\"$pluginsskinfiles/php.gif\"> ";\r
-                               } elseif (_isEditableFile($file)) {\r
-                                       echo "<img src=\"$pluginsskinfiles/text.gif\"> ";\r
-                               } elseif (_isImageFile($file)) {\r
-                                       echo "<img src=\"$pluginsskinfiles/image.gif\"> ";\r
-                               } else {\r
-                                       echo "<img src=\"$pluginsskinfiles/generic.png\"> ";\r
-                               }\r
-                               if ($newdir == '') {$thisdir = '';} else {$thisdir = "$newdir/";}\r
-                               echo "$file&nbsp;";\r
-                               echo "</td><td>";\r
-                               echo "&nbsp;<a href=\"$pluginsskinfiles/?action=renfile&rfp=$thisdir"."$file\" title=\"Rename file\">(ren)</a>";\r
-                               echo "</td><td>";\r
-                               echo "&nbsp;<a href=\"$pluginsskinfiles/?action=delfile&rfp=$thisdir"."$file\" title=\"Delete file\">(del)</a>";\r
-                               echo "</td><td>";\r
-                               if ((is_writable($DIR_SKINS.$SKINSUBDIR.$thisdir.$file)) && (!_isImageFile($file))) {\r
-                                       echo "&nbsp;<a href=\"$pluginsskinfiles/?action=editfile&rfp=$thisdir"."$file\" title=\"Edit file\">(edit)</a>";\r
-                               }\r
-                               echo "</td><td>";\r
-                               if (_isImageFile($file)) {\r
-                                       echo '&nbsp;<a href="'.$CONF['SkinsURL'].$SKINSUBDIR.$thisdir."$file\" title=\"View graphic\">(view)</a>";\r
-                               }\r
-                               echo "</td><td>";\r
-                               echo "&nbsp;<a href=\"$pluginsskinfiles/?action=download&rfp=$thisdir"."$file\" title=\"Download file\">(d/l)</a>";\r
-                               echo "</td><td>";\r
-                               echo number_format(filesize($DIR_SKINS.$SKINSUBDIR.$thisdir.$file)/1024, 2)." KB";\r
-                               echo "</td><td>";\r
-                               echo date('M d, Y  h:i:s a', filemtime($DIR_SKINS.$SKINSUBDIR.$thisdir.$file));\r
-                               echo "</td></tr>";\r
-                       }\r
-               }\r
-               echo "</table>";\r
-       \r
-               if(is_array($dirs) || is_array($files)) {\r
-                       if ($newdir != '') {\r
-                               echo "<u><a href=\"$pluginsskinfiles/\">> Return to / <</a></u><br />";\r
-                               if (strstr($newdir, '/')) {\r
-                                       $splitpath =  preg_split( "/\//", strrev($newdir), 2);\r
-                                       $updir = strrev($splitpath[1]);\r
-                                       echo "<u><a href=\"$pluginsskinfiles/?dir=/$updir\">> Return to /$updir <</a></u><br /><br />";\r
-                               }\r
-                       }\r
-                       echo "<u><a href=\"$pluginsskinfiles/?dir=$newdir\">> Refresh <</a></u><br />";\r
-               }\r
-\r
-               if ($newdir != '') {\r
-                       echo "<h3>Create new file in <b>/$newdir</b></h3>";\r
-                               ?>\r
-                               <form method="POST" enctype="multipart/form-data" action="<?php echo $pluginsskinfiles ?>/">\r
-                                               <input type="hidden" name="action" value="createfile" />\r
-                                               <input type="hidden" name="dir" value="<?php echo $newdir ?>">\r
-                                               <input type="text" name="filename" size="40">\r
-                                               <input type="submit" value="<?php echo 'Create file' ?>" />\r
-                                       </form>\r
-                               <?PHP\r
-\r
-                               echo "<h3>Upload new file to <b>/$newdir</b></h3>";\r
-                               ?>\r
-                               <form method="POST" enctype="multipart/form-data" action="<?php echo $pluginsskinfiles ?>/">\r
-                                               <input type="hidden" name="action" value="uploadfile" />\r
-                                               <input type="hidden" name="dir" value="<?php echo $newdir ?>">\r
-                                               <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" />\r
-                                               <input type="file" name="filename" size="40">\r
-                                               <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" />\r
-                                       </form>\r
-                               <?PHP\r
-       \r
-                       if (count($files)) {\r
-                               echo "<h3>Delete all files in <b>/$newdir</b></h3>";\r
-                                       ?>\r
-                                               <form method="get" action="<?php echo $pluginsskinfiles?>/">\r
-                                                       <input type="hidden" name="action" value="deleteAllInDir" />\r
-                                                       <input type="hidden" name="dir" value="<?php echo $newdir?>"/>\r
-                                                       <?php echo "Delete all Files? (will ask for confirmation)"?>\r
-                                                       <input type="submit" tabindex="140" value="<?php echo "Delete All"?>" onclick="return checkSubmit();" />\r
-                                               </form>\r
-                                       <?PHP\r
-                       }\r
-               }\r
-       \r
-               echo "<h3>Create a new directory in <b>/$newdir</b></h3>"; \r
-                               ?>\r
-                                       <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
-                                               <input type="hidden" name="action" value="createdir" />\r
-                                               <input type="hidden" name="dir" value="<?php echo $newdir?>"/>\r
-                                               <input name="newdir" tabindex="90" value="<?php echo 'newdir' ?>" size="40" />\r
-                                               <input type="submit" tabindex="140" value="<?php echo "Create"?>" onclick="return checkSubmit();" />\r
-                                       </form>\r
-                               <?PHP\r
-\r
-               // for MDNucleus, ignored if on Win32 platform (for the moment)\r
-               if (($newdir == '') && ($privateskins) && (!strtoupper(substr(PHP_OS, 0,3) == 'WIN'))) {\r
-                       if ($dh = @opendir($DIR_SKINS.$latestskins)) { \r
-                               while (($file = readdir($dh)) !== false) { \r
-                                       if(!preg_match("/^\.{1,2}/", $file))\r
-                                               if (is_dir($DIR_SKINS.$latestskins.$file)) $skins[] = $file;\r
-                               }\r
-                               closedir($dh); \r
-                       }\r
-                       if ($skins) {\r
-                               echo "<h3>Refresh default skin files to standard versions</h3>";\r
-                               ?>\r
-                                       <form method="post" action="<?php echo $pluginsskinfiles?>/">\r
-                                               <input type="hidden" name="action" value="getLatestSkins" />\r
-                                               <?php\r
-                                               sort ($skins);\r
-                                               if (count($skins) > 1) {\r
-                                                       $lastskin = array_pop($skins);\r
-                                                       array_push($skins, "</b>and<b> $lastskin");\r
-                                               }\r
-                                               echo "This will overwrite or create files in the following skin file directories: <b>";\r
-                                               echo implode(", ", $skins)."</b><br /><br />"; \r
-                                               ?> \r
-                                               Note that you may need to re-import skin definitions you wish to use (See Layout Import/Export).<br /><br />\r
-                                               <input type="checkbox" name="overwrite" value="1" id="cb_overwrite" />\r
-                                               <label for="cb_overwrite"><?php echo "Check this box to confirm overwrite of files<br />" ?></label>\r
-                                               <input type="submit" tabindex="140" value="<?php echo "Overwrite Default Skin Files"?>" onclick="return checkSubmit();" />\r
-                                       </form>\r
-                               <?PHP\r
-                       }\r
-               }\r
-\r
-       }\r
-\r
-       \r
-       \r
+<?php
+
+/*                                       */
+/* Admin page for NP_SkinFiles           */
+/* ------------------------------------  */
+/* A simple skin files manager           */
+/*                                       */
+/* code by Jeff MacMichael               */
+/* http://gednet.com/                    */
+/*                                       */
+/* version 1.01                          */
+       $strRel = '../../../'; 
+       include($strRel . 'config.php');
+       
+       include($DIR_LIBS . 'PLUGINADMIN.php');
+
+       if (preg_match("/MD$/", $nucleus['version'])) {
+               $isblogadmin = $member->isBlogAdmin(-1);
+       } else {
+               $isblogadmin = $member->isBlogAdmin($blogid);
+       }
+       if (!($member->isAdmin() || $isblogadmin)) {
+               $oPluginAdmin = new PluginAdmin('SkinFiles');
+               $oPluginAdmin->start();
+               echo "<p>"._ERROR_DISALLOWED."</p>";
+               $oPluginAdmin->end();
+               exit;
+       }
+
+       // set to FALSE for normal operation, or TRUE if skins are stored
+       // under owner's member id i.e. /skins/1/grey/...   (MDNucleus)
+       $privateskins = FALSE;
+       if ($privateskins) { 
+               global $member;
+               $SKINSUBDIR = $member->getID().'/'; 
+               $latestskins = 'latest-skins/';
+       } else {
+               $SKINSUBDIR = '';
+       }
+       
+       global $pluginsskinfiles, $CONF;
+       $pluginsskinfiles=$CONF['PluginURL']."skinfiles";
+
+       if (isset($_GET['action'])) {$action = $_GET['action'];}
+       if (isset($_POST['action'])) {$action = $_POST['action'];}
+
+       if ($action == 'download') { 
+               download();
+               return;
+               break;
+       }
+
+       // create the admin area page
+       $oPluginAdmin = new PluginAdmin('SkinFiles');
+       $oPluginAdmin->start();
+       
+       echo "<h2>Skin File Management</h2>";
+       
+       if (strstr('renfile delfile createdir rendir deldir deleteAllInDir'
+               .' editfile uploadfile createfile getLatestSkins', $action)) { 
+               call_user_func($action);
+       } else {
+               showdir();
+       }
+
+       $oPluginAdmin->end();
+       return;
+       break;
+               
+       function createfile() {
+               global $oPluginAdmin, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;
+               $parent = $_POST["dir"];
+               $filename = $_POST["filename"];
+               $fullpath = $DIR_SKINS.$SKINSUBDIR.$parent.'/'.$filename;
+               if (file_exists($fullpath)) {
+                       $msg = "Error: the file '$filename' already exists.";
+                       showdir($msg);
+               }
+               echo "<h3><b>Creating file \"/$parent/$filename\":</b></h3>";
+               $errrep = error_reporting(E_ERROR);
+               if (touch($fullpath)) { 
+                       $msg = 'The file was created successfully.';
+               } else {
+                       $msg = 'ERROR: The file was <i>not</i> created successfully.';
+               }
+               $oldumask = umask(0000);
+               chmod($fullpath, 0755);
+               umask($oldumask);
+               error_reporting($errrep);
+               showdir($msg);
+       }
+
+       function createdir() {
+               global $oPluginAdmin, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;
+               $parent = $_POST["dir"];
+               $newdir = $_POST["newdir"];
+               if (!$newdir) {
+                       echo 'You need to specify a directory name to create. <br /><br />';
+                       echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Go back</a><br />';              
+                       return;
+               }
+               $errrep = error_reporting(E_ERROR);
+               $oldumask = umask(0000);
+               if (mkdir ($DIR_SKINS.$SKINSUBDIR.$parent.'/'.$newdir, 0755)) {
+                       $msg = 'Directory created successfully.';
+               } else {
+                       $msg = 'There was an error creating the directory (check to see if the directory already exists).';
+               }
+               umask($oldumask);
+               error_reporting($errrep);
+               showdir($msg);
+       }
+       
+       function download() {
+               global $DIR_SKINS, $SKINSUBDIR;
+               $file = $_GET["rfp"];
+               $path = $DIR_SKINS.$SKINSUBDIR.$file;
+               $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);
+               $file = strrev($splitpath[0]);
+               
+               // download code taken from Paul Alger's PHP_Easy_Download. 
+
+               // translate file name properly for Internet Explorer.
+               if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){
+                       $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1);
+               }
+               // make sure the file exists before sending headers
+               if(!$fdl=@fopen($path,'r')){
+                       die("Cannot Open File!");
+               } else {
+                       header("Cache-Control: ");// leave blank to avoid IE errors
+                       header("Pragma: ");// leave blank to avoid IE errors
+                       header("Content-type: application/octet-stream");
+                       header('Content-Disposition: attachment; filename="'.$file.'"');
+                       header("Content-length: ".(string)(filesize($path)));
+                       sleep(1);
+                       
+                       fpassthru($fdl);
+               }
+               return;
+               break;
+       }
+       
+       function uploadfile() {
+               global $HTTP_POST_FILES, $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles, $CONF;
+               $filename = $HTTP_POST_FILES['filename']['name'];
+               $filesize = $HTTP_POST_FILES['filename']['size'];
+               $filetempname = $HTTP_POST_FILES['filename']['tmp_name'];
+               $todir = $DIR_SKINS.$SKINSUBDIR.$_POST['dir'].'/';
+               
+               if ($filesize > $CONF['MaxUploadSize']) {
+                       showdir(_ERROR_FILE_TOO_BIG);
+                       return;
+               }
+
+               // check file type against allowed types
+               $ok = 0;
+               $allowedtypes = explode (',', "css,html,htm,xml,inc,txt,".$CONF['AllowedTypes']);
+               foreach ( $allowedtypes as $type ) 
+                       if (eregi("\." .$type. "$",$filename)) $ok = 1;    
+               if (!$ok) {
+                       showdir(_ERROR_BADFILETYPE);
+                       return;
+               }
+               if (!is_uploaded_file($filetempname)) {
+                       showdir(_ERROR_BADREQUEST);
+                       return;
+               }
+               if (file_exists($todir.$filename)) {
+                       showdir(_ERROR_UPLOADDUPLICATE);
+                       return;
+               }
+
+               // move file to directory
+               if (is_uploaded_file($filetempname)) {
+                       $errrep = error_reporting(E_ERROR);
+                       if (!@move_uploaded_file($filetempname, $todir . $filename)) {
+                               showdir(_ERROR_UPLOADMOVE);
+                               return;
+                       }
+                       error_reporting($errrep);
+               }
+               // chmod uploaded file
+               $oldumask = umask(0000);
+               @chmod($todir . $filename, 0755); 
+               umask($oldumask);               
+
+               showdir("File uploaded successfully.");
+       }
+
+       function rendir() {
+               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;
+               if (isset($_POST['newname'])) {
+                       $splitpath =  preg_split( "/\//", strrev($_POST["oldname"]), 2);
+                       $newname = strrev($splitpath[1]) .'/'. $_POST["newname"];
+                       $newname = preg_replace("/^\//", "", $newname);
+                       $res = rename ( $DIR_SKINS.$SKINSUBDIR.$_POST["oldname"], 
+                               $DIR_SKINS.$SKINSUBDIR.$newname);
+                       if ($res) { 
+                               $msg = "Directory successfully renamed."; 
+                       } else {
+                               $msg = "Failed to rename directory - (check to see if another directory already exists with the new name).";
+                       }
+                       showdir($msg);
+               } else { 
+                       $oldname = preg_replace("/^\//", "", $_GET["oldname"]);
+                       echo '<h3><b>Rename directory "/'.$oldname.'":</b></h3>';
+                       $splitpath =  preg_split( "/\//", strrev($_GET["oldname"]), 2);
+                       $dir = strrev($splitpath[0]);
+                       $parent = strrev($splitpath[1]);
+                       echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Cancel rename</a><br />';                
+                       ?>
+                               <form method="post" action="<?php echo $pluginsskinfiles?>/">
+                                       <input type="hidden" name="action" value="rendir" />
+                                       <input type="hidden" name="dir" value="<?php echo "/$parent" ?>"/>
+                                       <input type="hidden" name="oldname" value="<?php echo $oldname?>"/>
+                                       <table><tr>
+                                               <td><?php echo 'Rename to'?></td>
+                                               <td><input name="newname" tabindex="90" value="<?php echo  htmlspecialchars($dir) ?>" maxlength="50" size="20" /></td>
+                                       </tr><tr>
+                                               <td><?php echo "Rename"?></td>
+                                               <td><input type="submit" tabindex="140" value="<?php echo "Rename this folder"?>" onclick="return checkSubmit();" /></td>
+                                       </tr></table>
+                               </form>
+                       <?PHP
+               }
+       }
+
+       function editfile () {
+               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;
+               if (isset ($_POST['rfp']) && isset($_POST['content'])) {
+                       $file = $_POST['rfp'];
+                       $errrep = error_reporting(E_ERROR);
+                       $success = true;
+                       if ($fh = @fopen($DIR_SKINS.$SKINSUBDIR.$file, 'w')) { 
+                               if (fwrite ($fh, trim(stripslashes($_POST['content'])))) {
+                                       fclose($fh);
+                               } else {
+                                       $success = false;
+                               }
+                       } else {
+                               $success = false;
+                       }
+                       error_reporting($errrep);
+                       if ($success) {
+                               $msg = 'File was edited successfully.';
+                       } else {
+                               $msg = 'ERROR: File was <i>not</i> saved successfully.';
+                       }
+               }
+               if (isset ($_GET['rfp'])) { $file = $_GET['rfp']; }
+               if (isset ($_POST['rfp'])) { $file = $_POST['rfp']; }
+               $splitpath =  preg_split( "/\//", strrev($file), 2);
+               $parent = strrev($splitpath[1]);
+               echo '<h3>Editing file "/'.$file.'":</h3>';
+               if (isset($msg)) { echo "<p><b>$msg</b></p>"; }
+               echo "> <a href=\"$pluginsskinfiles/?dir=$parent\"> Cancel/Return to /$parent</a><br /><br />";
+               $fh = @fopen($DIR_SKINS.$SKINSUBDIR.$file, 'r');
+               while (!feof($fh)) { 
+                       $content .= fread($fh, 4096); 
+               }
+               fclose ($fh);                   
+               ?>
+                       <form method="post" action="<?php echo $pluginsskinfiles?>/">
+                               <input type="hidden" name="action" value="editfile" />
+                               <input type="hidden" name="rfp" value="<?php echo $file ?>"/>
+                               <input type="hidden" name="dir" value="<?php echo $parent ?>"/>
+                               <input type="submit" tabindex="140" value="<?php echo "Save changes"?>" onclick="return checkSubmit();" />
+                               <input type="reset" value="Reset Data" /><br />
+                               <textarea class="skinedit" tabindex="8" rows="20" cols="80" name="content"><?PHP echo htmlspecialchars($content) ?></textarea>
+                               <input type="submit" tabindex="140" value="<?php echo "Save changes"?>" onclick="return checkSubmit();" />
+                               <input type="reset" value="Reset Data" /><br />
+                       </form>
+               <?PHP
+       }
+
+
+       function renfile() {
+               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;
+               if (isset($_POST['newname'])) {
+                       $splitpath =  preg_split( "/\//", strrev($_POST["oldname"]), 2);
+                       $newname = strrev($splitpath[1]) .'/'. $_POST["newname"];
+                       $newname = preg_replace("/^\//", "", $newname);
+                       $res = rename ( $DIR_SKINS.$SKINSUBDIR.$_POST["oldname"], 
+                               $DIR_SKINS.$SKINSUBDIR.$newname);
+                       if ($res) { 
+                               $msg = "File successfully renamed."; 
+                       } else {
+                               $msg = "File could not be renamed - (check to see if another file already exists with the new name).";
+                       }
+                       showdir($msg);
+               } else { 
+                       echo '<h3><b>Rename file "/'.$_GET["rfp"].'":</b></h3>';
+                       $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);
+                       $file = strrev($splitpath[0]);
+                       $parent = strrev($splitpath[1]);
+                       echo '> <a href="'.$_SERVER['HTTP_REFERER'].'">Cancel rename</a><br />';                
+                       ?>
+                               <form method="post" action="<?php echo $pluginsskinfiles?>/">
+                                       <input type="hidden" name="action" value="renfile" />
+                                       <input type="hidden" name="oldname" value="<?php echo $_GET["rfp"] ?>"/>
+                                       <input type="hidden" name="dir" value="<?php echo "/$parent" ?>"/>
+                                       <table><tr>
+                                               <td><?php echo 'Rename to'?></td>
+                                               <td><input name="newname" tabindex="90" value="<?php echo  htmlspecialchars($file) ?>" maxlength="50" size="20" /></td>
+                                       </tr><tr>
+                                               <td><?php echo "Rename"?></td>
+                                               <td><input type="submit" tabindex="140" value="<?php echo "Rename this file"?>" onclick="return checkSubmit();" /></td>
+                                       </tr></table>
+                               </form>
+                       <?PHP
+               }
+       }
+
+       function delfile() {
+               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;
+               if (isset($_GET['sure'])) { 
+                       $file = $DIR_SKINS.$SKINSUBDIR.$_GET["rfp"];
+                       $errrep = error_reporting(E_ERROR);
+                       if (unlink ($file)) {
+                               $msg = 'File "'.$_GET["rfp"].'" has been deleted.';
+                       } else {
+                               $msg = 'ERROR: File "'.$_GET["rfp"].'" could not be deleted.';
+                       }
+                       error_reporting($errrep);
+                       showdir($msg);
+               } else {
+                       $file = $DIR_SKINS.$SKINSUBDIR.$_GET["rfp"];
+                       $splitpath =  preg_split( "/\//", strrev($_GET["rfp"]), 2);
+                       $parent = strrev($splitpath[1]);
+                       echo '<h3><b>Delete file "'.$_GET["rfp"].'": are you sure?</b></h3>';
+                       echo '<b>This action cannot be undone!</b><br /><br />';
+                       echo "> <a href=\"$pluginsskinfiles/?action=delfile&dir=$parent&sure=y&rfp=".$_GET["rfp"]."\">Yes, delete the file.</a><br />";         
+                       echo "> <a href=\"$pluginsskinfiles/?dir=".$parent.'">No, go back.</a><br />';          
+               }
+       }
+
+       function deldir() {
+               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;
+               if (isset($_GET['sure'])) { 
+                       $dir = $DIR_SKINS.$SKINSUBDIR.$_GET["remdir"];
+                       $errrep = error_reporting(E_ERROR);
+                       if (rmdir ($dir)) {
+                               $msg = 'Directory "'.$_GET["remdir"].'" has been deleted.';
+                       } else {
+                               $msg = 'ERROR: directory "'.$_GET["remdir"].'" could not be deleted - (check to see if it contains files).';
+                       }
+                       error_reporting($errrep);
+                       showdir($msg);
+               } else {
+                       $dir = preg_replace("/^\//", "",$_GET['remdir']);
+                       $parent = $_GET['dir'];
+                       echo '<h3><b>Delete directory "/'.$dir.'": are you sure?</b></h3>';
+                       echo '<b>This action cannot be undone!</b><br /><br />';
+                       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 />";          
+                       echo "> <a href=\"$pluginsskinfiles/?dir=".$parent.'">No, go back.</a><br />';          
+               }
+       }
+
+       function deleteAllInDir() {
+               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles;
+               $parent = $DIR_SKINS.$SKINSUBDIR.preg_replace("/^\//", "",$_GET['dir']);
+               if ($dh = @opendir($parent)) { 
+                       while (($file = readdir($dh)) !== false) { 
+                               if(!preg_match("/^\.{1,2}/", $file)){
+                                       if (!is_dir($parent.$file)) {
+                                               $files[] = $file;
+                                       }
+                               }
+                       }
+                       closedir($dh); 
+               } 
+               if (isset($_GET['sure'])) { 
+                       $errrep = error_reporting(E_ERROR);
+                       echo '<h3>Deletion results</h3><table>';
+                       echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET["dir"]."\">Return to the /".$_GET["dir"]." directory.</a><br />";              
+                       foreach ($files as $file) {
+                               if (unlink ("$parent/$file")) { 
+                                       echo "<tr><td>File: $file was deleted.</td></tr>"; 
+                               } else {
+                                       echo "<tr><td>File: $file was <b>NOT</b> deleted.</td></tr>";
+                               }
+                       }
+                       echo "</table>";
+                       error_reporting($errrep);
+                       echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET["dir"]."\">Return to the /".$_GET["dir"]." directory.</a><br />";              
+               } else {
+                       echo '<h3><b>Delete all files in directory "/'.$_GET['dir'].'": are you sure?</b></h3>';
+                       echo '<b>This action cannot be undone!</b><br /><br />';
+                       echo "> <a href=\"$pluginsskinfiles/?action=deleteAllInDir&sure=y&dir=".$_GET["dir"]."\">Yes, delete <u>all files</u> in this directory.</a><br />";            
+                       echo "> <a href=\"$pluginsskinfiles/?dir=".$_GET['dir'].'">No, go back.</a><br /><br />';               
+                       echo '<b>Files list:</b><table>';
+                       foreach ($files as $file) {     echo "<tr><td>$file</td></tr>"; }
+                       echo '</table>';
+               }
+       }
+
+       // function for MDNucleus; won't work unless $privateskins is set to true
+       function getLatestSkins() {
+               global $DIR_SKINS, $pluginsskinfiles, $privateskins, $latestskins, $member;
+               $confirmed = $_POST['overwrite'];
+               if (!$confirmed) {
+                       showdir("Overwrite of default skin files not confirmed - no action taken.");
+                       return;
+               }
+               if ($dh = @opendir($DIR_SKINS.$latestskins)) { 
+                       while (($file = readdir($dh)) !== false) { 
+                               if(!preg_match("/^\.{1,2}/", $file))
+                                       if (is_dir($DIR_SKINS.$latestskins.$file)) $skins[] = $file;
+                       }
+                       closedir($dh); 
+               } 
+               if ($skins) {
+                       $msg = "Refreshed skin folders:";
+                       sort ($skins);
+                       foreach ($skins as $skin) {
+                               $memberskin = $DIR_SKINS.$member->getID().'/'.$skin;
+                               if (is_file($memberskin)) unlink($memberskin);
+                               if (!is_dir($memberskin)) {
+                                       $old_umask = umask(0);
+                                       mkdir($memberskin, 0755);
+                                       umask($old_umask);
+                               }
+                               exec("rsync -Wtr --delete ".$DIR_SKINS.$latestskins.$skin."/* ".$memberskin.'/');
+                               $msg .= "  $skin";
+                       }
+               } else {
+                       showdir("No default skin folders found.  No action taken.");
+                       return;
+               }
+               showdir($msg);
+       }
+
+       function _isImageFile($file) {
+               return preg_match ("/\.(gif|png|jpg|jpeg|bmp|ico)$/i", $file);
+       }
+
+       function _isEditableFile($file) {
+               return preg_match ("/\.(inc|txt|htm|html|xml)$/i", $file);
+       }
+
+       function showdir($msg = '') {
+               global $DIR_SKINS, $SKINSUBDIR, $pluginsskinfiles, $CONF;
+               global $privateskins, $latestskins;
+               if (isset($_GET['dir'])) { 
+                       $newdir = preg_replace("/^\//", "",$_GET['dir']);
+                       $currdir = $DIR_SKINS.$SKINSUBDIR."$newdir/";
+                       $in_subdir = 1;
+               } elseif (isset($_POST['dir'])) { 
+                       $newdir = preg_replace("/^\//", "",$_POST['dir']);
+                       $currdir = $DIR_SKINS.$SKINSUBDIR."$newdir/";
+                       $in_subdir = 1;
+               } else {
+                       $newdir = '';
+                       $currdir = $DIR_SKINS.$SKINSUBDIR;
+                       $in_subdir = 0;
+               }
+       
+               if ($privateskins && (!is_dir($DIR_SKINS.$SKINSUBDIR))) {
+                       $oldumask = umask(0);
+                       mkdir($DIR_SKINS.$SKINSUBDIR, 0755);
+                       umask($oldmask);
+               }
+
+               if (!is_dir($currdir)) {
+                       echo 'The specified location is not a directory or doesn\'t exist.';
+                       return;
+               }
+               
+               if ($dh = @opendir($currdir)) { 
+                       while (($file = readdir($dh)) !== false) { 
+                               if(!preg_match("/^\.{1,2}/", $file)){
+                                       if (is_dir($currdir.$file)) {
+                                               $dirs[] = $file;
+                                       } else {
+                                               $files[] = $file;
+                                       }
+                               }
+                       }
+                       closedir($dh); 
+               } 
+               
+               echo "<h3>Current Directory: <b>/$newdir</b></h3>";
+               
+               if ($msg) {
+                       echo '<p><b>'.htmlspecialchars($msg).'</b></p>';
+               }
+               
+               if ($newdir != '') {
+                       echo "<u><a href=\"$pluginsskinfiles/\">> Return to / <</a></u><br />";
+                       if (strstr($newdir, '/')) {
+                               $splitpath =  preg_split( "/\//", strrev($newdir), 2);
+                               $updir = strrev($splitpath[1]);
+                               echo "<u><a href=\"$pluginsskinfiles/?dir=/$updir\">> Return to /$updir <</a></u><br /><br />";
+                       }
+               }
+               echo "<u><a href=\"$pluginsskinfiles/?dir=$newdir\">> Refresh <</a></u><br />";
+
+               echo "<table>";
+               if(is_array($dirs)){
+                       sort($dirs);
+                       foreach($dirs as $dir) {
+                               echo "<tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'><td>";
+                               echo "&nbsp;&nbsp;<a href=\"$pluginsskinfiles/?dir=$newdir/$dir\">";
+                               echo "<img src=\"$pluginsskinfiles/dir.gif\"> $dir</a>&nbsp;</td>";
+                               echo "<td>&nbsp;<a href=\"$pluginsskinfiles/?action=rendir&oldname=$newdir/$dir\" title=\"Rename directory\">(ren)</a></td>";
+                               echo "<td>&nbsp;<a href=\"$pluginsskinfiles/?action=deldir&dir=$newdir&remdir=$newdir/$dir\" title=\"Delete directory\">(del)</a></td>";
+                               echo "</td><td></td><td></td><td></td><td>";
+                               echo "<td>".date('M d, Y  h:i:s a', filemtime($DIR_SKINS.$SKINSUBDIR.$newdir."/$dir"));
+                               echo "</td></tr>";
+                       }
+               }
+       
+               if(is_array($files)){
+                       sort($files);
+                       foreach($files as $file) {
+                               echo "<tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'><td>";
+                               echo "&nbsp;&nbsp;";
+                               if (preg_match("/\.css$/i", $file)) {
+                                       echo "<img src=\"$pluginsskinfiles/css.gif\"> ";
+                               } elseif (preg_match("/\.php(3|4)?$/i", $file)) {
+                                       echo "<img src=\"$pluginsskinfiles/php.gif\"> ";
+                               } elseif (_isEditableFile($file)) {
+                                       echo "<img src=\"$pluginsskinfiles/text.gif\"> ";
+                               } elseif (_isImageFile($file)) {
+                                       echo "<img src=\"$pluginsskinfiles/image.gif\"> ";
+                               } else {
+                                       echo "<img src=\"$pluginsskinfiles/generic.png\"> ";
+                               }
+                               if ($newdir == '') {$thisdir = '';} else {$thisdir = "$newdir/";}
+                               echo "$file&nbsp;";
+                               echo "</td><td>";
+                               echo "&nbsp;<a href=\"$pluginsskinfiles/?action=renfile&rfp=$thisdir"."$file\" title=\"Rename file\">(ren)</a>";
+                               echo "</td><td>";
+                               echo "&nbsp;<a href=\"$pluginsskinfiles/?action=delfile&rfp=$thisdir"."$file\" title=\"Delete file\">(del)</a>";
+                               echo "</td><td>";
+                               if ((is_writable($DIR_SKINS.$SKINSUBDIR.$thisdir.$file)) && (!_isImageFile($file))) {
+                                       echo "&nbsp;<a href=\"$pluginsskinfiles/?action=editfile&rfp=$thisdir"."$file\" title=\"Edit file\">(edit)</a>";
+                               }
+                               echo "</td><td>";
+                               if (_isImageFile($file)) {
+                                       echo '&nbsp;<a href="'.$CONF['SkinsURL'].$SKINSUBDIR.$thisdir."$file\" title=\"View graphic\">(view)</a>";
+                               }
+                               echo "</td><td>";
+                               echo "&nbsp;<a href=\"$pluginsskinfiles/?action=download&rfp=$thisdir"."$file\" title=\"Download file\">(d/l)</a>";
+                               echo "</td><td>";
+                               echo number_format(filesize($DIR_SKINS.$SKINSUBDIR.$thisdir.$file)/1024, 2)." KB";
+                               echo "</td><td>";
+                               echo date('M d, Y  h:i:s a', filemtime($DIR_SKINS.$SKINSUBDIR.$thisdir.$file));
+                               echo "</td></tr>";
+                       }
+               }
+               echo "</table>";
+       
+               if(is_array($dirs) || is_array($files)) {
+                       if ($newdir != '') {
+                               echo "<u><a href=\"$pluginsskinfiles/\">> Return to / <</a></u><br />";
+                               if (strstr($newdir, '/')) {
+                                       $splitpath =  preg_split( "/\//", strrev($newdir), 2);
+                                       $updir = strrev($splitpath[1]);
+                                       echo "<u><a href=\"$pluginsskinfiles/?dir=/$updir\">> Return to /$updir <</a></u><br /><br />";
+                               }
+                       }
+                       echo "<u><a href=\"$pluginsskinfiles/?dir=$newdir\">> Refresh <</a></u><br />";
+               }
+
+               if ($newdir != '') {
+                       echo "<h3>Create new file in <b>/$newdir</b></h3>";
+                               ?>
+                               <form method="POST" enctype="multipart/form-data" action="<?php echo $pluginsskinfiles ?>/">
+                                               <input type="hidden" name="action" value="createfile" />
+                                               <input type="hidden" name="dir" value="<?php echo $newdir ?>">
+                                               <input type="text" name="filename" size="40">
+                                               <input type="submit" value="<?php echo 'Create file' ?>" />
+                                       </form>
+                               <?PHP
+
+                               echo "<h3>Upload new file to <b>/$newdir</b></h3>";
+                               ?>
+                               <form method="POST" enctype="multipart/form-data" action="<?php echo $pluginsskinfiles ?>/">
+                                               <input type="hidden" name="action" value="uploadfile" />
+                                               <input type="hidden" name="dir" value="<?php echo $newdir ?>">
+                                               <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" />
+                                               <input type="file" name="filename" size="40">
+                                               <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" />
+                                       </form>
+                               <?PHP
+       
+                       if (count($files)) {
+                               echo "<h3>Delete all files in <b>/$newdir</b></h3>";
+                                       ?>
+                                               <form method="get" action="<?php echo $pluginsskinfiles?>/">
+                                                       <input type="hidden" name="action" value="deleteAllInDir" />
+                                                       <input type="hidden" name="dir" value="<?php echo $newdir?>"/>
+                                                       <?php echo "Delete all Files? (will ask for confirmation)"?>
+                                                       <input type="submit" tabindex="140" value="<?php echo "Delete All"?>" onclick="return checkSubmit();" />
+                                               </form>
+                                       <?PHP
+                       }
+               }
+       
+               echo "<h3>Create a new directory in <b>/$newdir</b></h3>"; 
+                               ?>
+                                       <form method="post" action="<?php echo $pluginsskinfiles?>/">
+                                               <input type="hidden" name="action" value="createdir" />
+                                               <input type="hidden" name="dir" value="<?php echo $newdir?>"/>
+                                               <input name="newdir" tabindex="90" value="<?php echo 'newdir' ?>" size="40" />
+                                               <input type="submit" tabindex="140" value="<?php echo "Create"?>" onclick="return checkSubmit();" />
+                                       </form>
+                               <?PHP
+
+               // for MDNucleus, ignored if on Win32 platform (for the moment)
+               if (($newdir == '') && ($privateskins) && (!strtoupper(substr(PHP_OS, 0,3) == 'WIN'))) {
+                       if ($dh = @opendir($DIR_SKINS.$latestskins)) { 
+                               while (($file = readdir($dh)) !== false) { 
+                                       if(!preg_match("/^\.{1,2}/", $file))
+                                               if (is_dir($DIR_SKINS.$latestskins.$file)) $skins[] = $file;
+                               }
+                               closedir($dh); 
+                       }
+                       if ($skins) {
+                               echo "<h3>Refresh default skin files to standard versions</h3>";
+                               ?>
+                                       <form method="post" action="<?php echo $pluginsskinfiles?>/">
+                                               <input type="hidden" name="action" value="getLatestSkins" />
+                                               <?php
+                                               sort ($skins);
+                                               if (count($skins) > 1) {
+                                                       $lastskin = array_pop($skins);
+                                                       array_push($skins, "</b>and<b> $lastskin");
+                                               }
+                                               echo "This will overwrite or create files in the following skin file directories: <b>";
+                                               echo implode(", ", $skins)."</b><br /><br />"; 
+                                               ?> 
+                                               Note that you may need to re-import skin definitions you wish to use (See Layout Import/Export).<br /><br />
+                                               <input type="checkbox" name="overwrite" value="1" id="cb_overwrite" />
+                                               <label for="cb_overwrite"><?php echo "Check this box to confirm overwrite of files<br />" ?></label>
+                                               <input type="submit" tabindex="140" value="<?php echo "Overwrite Default Skin Files"?>" onclick="return checkSubmit();" />
+                                       </form>
+                               <?PHP
+                       }
+               }
+
+       }
+
+       
+       
 ?>
\ No newline at end of file