Permalink
Browse files

1)Corrected "../" link. It was only linking to first level, no matter…

… how deep the current folder.

2)Modified "path/to/current/folder" so that each level is click-able directly to that folder.
  • Loading branch information...
1 parent 4808a7d commit fc0ee1fb8d1f424ad3dd13e71914c06cb17f059e @Self-Evident committed Mar 17, 2012
Showing with 87 additions and 52 deletions.
  1. +87 −52 onefilecms.php
View
@@ -1,7 +1,7 @@
<?php
-
-// OneFileCMS - http://onefilecms.com/
-
+
+// OneFileCMS - http://onefilecms.com/
+
// CONFIGURATION INFO
$config_username = "username";
$config_password = "password";
@@ -25,9 +25,9 @@ function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return
$_SESSION['onefilecms_valid'] = "1";
} else {
$_SESSION['onefilecms_valid'] = "0";
- if ($_GET["p"] !== "login") {
- header("Location: ".$_SERVER["php_self"]."?p=login");
- exit("Invalid session. <a href='".$_SERVER["php_self"]."?p=login'>Please log in</a>.");
+ if ($_GET["p"] !== "login") {
+ header("Location: ".$_SERVER["php_self"]."?p=login");
+ exit("Invalid session. <a href='".$_SERVER["php_self"]."?p=login'>Please log in</a>.");
}
}
@@ -38,9 +38,9 @@ function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return
// redirect on invalid page attempts
if (!in_array(strtolower($_GET["p"]), array(
"copy","delete","error","deletefolder","edit","folder","index","login","logout","new","other","rename","renamefolder","upload"
- ))) {
- header("Location: /");
- exit("Invalid parameter. <a href='".$_SERVER["SCRIPT_NAME"]."'>Continue</a>.");
+ ))) {
+ header("Location: /");
+ exit("Invalid parameter. <a href='".$_SERVER["SCRIPT_NAME"]."'>Continue</a>.");
}
$page = $_GET["p"];
}
@@ -216,14 +216,14 @@ function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return
<p>Existing files with the same filename are automatically overwritten... Be careful!</p>
<form method="post" id="new" action="<?php echo $_SERVER["SCRIPT_NAME"].$varvar; ?>">
<input type="hidden" name="sessionid" value="<?php echo session_id(); ?>" />
- <p>
- <label>Old filename:</label>
- <input type="hidden" name="old_filename" value="<?php echo $filename; ?>" />
- <input type="text" name="dummy" value="<?php echo $filename; ?>" class="textinput" disabled="disabled" />
+ <p>
+ <label>Old filename:</label>
+ <input type="hidden" name="old_filename" value="<?php echo $filename; ?>" />
+ <input type="text" name="dummy" value="<?php echo $filename; ?>" class="textinput" disabled="disabled" />
</p>
- <p>
- <label for="copy_filename">New filename:</label>
- <input type="text" name="copy_filename" id="copy_filename" class="textinput" value="<?php echo $slug."_".date("mdyHi").$extension; ?>" />
+ <p>
+ <label for="copy_filename">New filename:</label>
+ <input type="text" name="copy_filename" id="copy_filename" class="textinput" value="<?php echo $slug."_".date("mdyHi").$extension; ?>" />
</p>
<p><input type="submit" class="button" value="Copy" /></p>
</form>
@@ -236,10 +236,10 @@ function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return
<p>Are you sure?</p>
<form method="post" action="<?php echo $_SERVER["SCRIPT_NAME"].$varvar; ?>">
<input type="hidden" name="sessionid" value="<?php echo session_id(); ?>" />
- <p>
- <input type="hidden" name="delete_filename" value="<?php echo $filename; ?>" />
- <input type="submit" class="button" name="delete_file" value="Yes" />
- <input type="button" class="button" name="cancel" value="No" onclick="parent.location='<?php echo $_SERVER["SCRIPT_NAME"]; ?>'" />
+ <p>
+ <input type="hidden" name="delete_filename" value="<?php echo $filename; ?>" />
+ <input type="submit" class="button" name="delete_file" value="Yes" />
+ <input type="button" class="button" name="cancel" value="No" onclick="parent.location='<?php echo $_SERVER["SCRIPT_NAME"]; ?>'" />
</p>
</form>
<?php };
@@ -251,10 +251,10 @@ function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return
<p>Folders have to be empty before they can be deleted.</p>
<form method="post" action="<?php echo $_SERVER["SCRIPT_NAME"].$varvar; ?>">
<input type="hidden" name="sessionid" value="<?php echo session_id(); ?>" />
- <p>
- <input type="hidden" name="delete_foldername" value="<?php echo $_GET["i"]; ?>" />
- <input type="submit" class="button" name="delete_folder" value="Yes" />
- <input type="button" class="button" name="cancel" value="No" onclick="parent.location='<?php echo $_SERVER["SCRIPT_NAME"]."?i=".substr_replace($_GET["i"],"",-1); ?>'" />
+ <p>
+ <input type="hidden" name="delete_foldername" value="<?php echo $_GET["i"]; ?>" />
+ <input type="submit" class="button" name="delete_folder" value="Yes" />
+ <input type="button" class="button" name="cancel" value="No" onclick="parent.location='<?php echo $_SERVER["SCRIPT_NAME"]."?i=".substr_replace($_GET["i"],"",-1); ?>'" />
</p>
</form>
<?php };
@@ -265,25 +265,25 @@ function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return
<a href="<?php echo $_SERVER["SCRIPT_NAME"]; ?>?i=<?php echo substr($_GET["f"],0,strrpos($_GET["f"],"/")); ?>" class="back">Back</a>
<form method="post" action="<?php echo $_SERVER["SCRIPT_NAME"]; ?>?f=<?php echo $filename; ?>">
<input type="hidden" name="sessionid" value="<?php echo session_id(); ?>" />
- <?php $lfile = strtolower($filename);
+ <?php $lfile = strtolower($filename);
if (strpos($config_disabled,end(explode(".", $lfile)))) { ?>
- <p>
- <textarea name="content" class="textinput disabled" cols="70" rows="25" disabled="disabled">Disabled.</textarea>
+ <p>
+ <textarea name="content" class="textinput disabled" cols="70" rows="25" disabled="disabled">Disabled.</textarea>
</p>
<p class="buttons_right">
<input type="submit" class="button" name="save_file" value="Save"
disabled="disabled" />
<?php } else { ?>
- <p>
- <input type="hidden" name="filename" id="filename" class="textinput" value="<?php echo $filename; ?>" />
- <textarea name="content" class="textinput" cols="70" rows="25"><?php echo $loadcontent; ?></textarea>
+ <p>
+ <input type="hidden" name="filename" id="filename" class="textinput" value="<?php echo $filename; ?>" />
+ <textarea name="content" class="textinput" cols="70" rows="25"><?php echo $loadcontent; ?></textarea>
</p>
<p class="buttons_right">
<input type="submit" class="button" name="save_file" id="save_file" value="Save" />
<?php } ?>
<input type="button" class="button" name="rename_file" value="Rename/Move" onclick="parent.location='<?php echo $_SERVER["SCRIPT_NAME"]; ?>?r=<?php echo $filename; ?>'" />
<input type="button" class="button" name="delete_file" value="Delete" onclick="parent.location='<?php echo $_SERVER["SCRIPT_NAME"]; ?>?d=<?php echo $filename; ?>'" />
- <input type="button" class="button" name="copy_file" value="Copy" onclick="parent.location='<?php echo $_SERVER["SCRIPT_NAME"]; ?>?c=<?php echo $filename; ?>'" />
+ <input type="button" class="button" name="copy_file" value="Copy" onclick="parent.location='<?php echo $_SERVER["SCRIPT_NAME"]; ?>?c=<?php echo $filename; ?>'" />
</p>
<div class="meta">
<p><i>File Size:</i> <?php echo round(filesize($filename)/1000,2); ?> kb -
@@ -296,13 +296,48 @@ function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return
// INDEX
if ($page == "index") { $varvar = "";
if (isset($_GET["i"])) { $varvar = $_GET["i"]."/"; } ?>
- <h2><?php echo basename(getcwd())."/".$varvar;?></h2>
+
+ <?php //*** Display current path & link each directory level **************
+
+ $full_path = basename(getcwd()).'/'.$_GET["i"];
+ $path_levels = explode("/",$full_path);
+ $levels = count($path_levels);
+
+ //First item is root of website.
+ if ($varvar == "") {
+ echo '<h2>', $path_levels[0]; //if at root, no need for link.
+ }else{
+ echo '<h2><a href="', $_SERVER["SCRIPT_NAME"], '" class="path">', $path_levels[0], ' </a>/';
+ }//end if
+
+ $current_path = "";
+ for ($x=1; $x < $levels-1; $x++){
+ if ($x != 1){$current_path .= '/';}
+ $current_path = $current_path.$path_levels[$x];
+ echo '<a href="', $_SERVER["SCRIPT_NAME"], '?i=', $current_path, '" class="path"> ';
+ echo $path_levels[$x], ' </a>/';
+ }//end for
+
+ //last item is current dir. No link needed.
+ echo ' '.$path_levels[$x].' /</h2>';
+ //******* End display current path ... ***********************************?>
+
<p class="index_folders">
- <?php if ((isset($_GET["i"])) and ($_GET["i"] !== "")) { ?>
- <a href="<?php echo $_SERVER["SCRIPT_NAME"]; ?>?i=<?php echo substr($_GET["i"],0,strpos($_GET["i"],"/")); ?>" class="folder">.. /</a>
- <?php }
- $files = glob($varvar."*",GLOB_ONLYDIR);
- sort($files);
+
+ <?php
+ // *** "../" link for parent directory *******
+ $newpath = dirname($varvar);
+ if ( $varvar == "") {
+ echo ''; //If $varvar is blank, already at base directory, so "../" is not needed.
+ }elseif ($newpath == ".") { // "." == base directory
+ echo '<a href="'.$_SERVER["SCRIPT_NAME"].'" class="folder"><b>.. /</b></a>';
+ }else{
+ echo '<a href="'.$_SERVER["SCRIPT_NAME"].'?i='.$newpath.'" class="folder"><b>.. /</b></a>';
+ }
+ // *** end "../" link for parent directory ***
+
+ $files = glob($varvar."*",GLOB_ONLYDIR);
+ sort($files);
foreach ($files as $file) { ?>
<a href="<?php echo $_SERVER["SCRIPT_NAME"]; ?>?i=<?php echo $file; ?>" class="folder"><?php echo basename($file); ?></a>
<?php } ?>
@@ -322,13 +357,13 @@ function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return
if (!is_dir($file) && $excludeme == 0) {
$file_class = "";
$lfile = strtolower($file);
- if (
- (strrpos(strtolower($lfile),".jpg")) ||
- (strrpos($lfile,".gif")) ||
+ if (
+ (strrpos(strtolower($lfile),".jpg")) ||
+ (strrpos($lfile,".gif")) ||
(strrpos($lfile,".png")) ||
- (strrpos($lfile,".ico"))
- ) {
- $file_class = "img";
+ (strrpos($lfile,".ico"))
+ ) {
+ $file_class = "img";
};
if (strrpos($lfile,".css")) { $file_class = "css"; };
if (strrpos($lfile,".php")) { $file_class = "php"; }; ?>
@@ -492,18 +527,18 @@ class="textinput" /></p>
</div>
-<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
+<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
-
+
$.fn.ready(function(){
-
- var $message = $("#message"),
- $save_file = $("#save_file");
+
+ var $message = $("#message"),
+ $save_file = $("#save_file");
if ( $message.length > 0 ) { $message.animate({opacity: 1.0}, 3000).fadeOut(); };
-
+
$(".button:visible:enabled:first").focus();
$(".textinput:visible:enabled:first").focus();
-
+
$(".page_edit .textinput").bind("change keyup", function (e) {
key = e.which+" ";
badkeys = "224 16 17 18 37 38 39 40 ";
@@ -513,7 +548,7 @@ class="textinput" /></p>
$(".page_edit h2").append(" *");
}
});
-
+
$(".page_edit form").submit(function() { $save_file.val("Save"); });
window.onbeforeunload = function () {
if ($save_file.val() == "Save!") {
@@ -522,7 +557,7 @@ class="textinput" /></p>
};
});
-
+
</script>
</body>

0 comments on commit fc0ee1f

Please sign in to comment.