diff --git a/core.php b/core.php index b11342a..4f1f68b 100644 --- a/core.php +++ b/core.php @@ -553,7 +553,47 @@ switch($_GET["action"]) * %move% */ case "move": - exit(renderpage("Moving $page", "
Coming soon...
")); + if(!$isadmin) + exit(renderpage("Moving $page - Error", "You tried to move $page, but you do not have permission to do that.
+You should try logging in as an admin.
")); + + if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0) + exit(renderpage("Moving $page", "You tried to move $page to $new_name, but the page with the name $page does not exist in the first place.
+Nothing has been changed.
")); + + if($page == $new_name) + exit(renderpage("Moving $page - Error", "You tried to move $page, but the new name you gave is the same as it's current name.
+It is possible that you tried to use some characters in the new name that are not allowed and were removed.
+Page names may only contain alphanumeric characters, dashes, and underscores.
")); + + //move the page in the page index + $pageindex->$new_name = new stdClass(); + foreach($pageindex->$page as $key => $value) + { + $pageindex->$new_name->$key = $value; + } + unset($pageindex->$page); + file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); + + //move the page on the disk + rename("$page.md", "$new_name.md"); + + exit(renderpage("Moving $page", "$page has been moved to $new_name successfully.
")); break; /* diff --git a/index.php b/index.php index 7685844..76ea895 100755 --- a/index.php +++ b/index.php @@ -67,6 +67,7 @@ $navlinks = [ [ "Printable", "index.php?action=view&printable=yes&page={page}" ], " | ", [ $admindisplaychar . "Delete", "index.php?action=delete&page={page}" ], + [ $admindisplaychar . "Move", "index.php?action=move&page={page}" ], " | ", [ "All Pages", "index.php?action=list" ], " | ", @@ -77,8 +78,9 @@ $navlinks = [ //string of css to include //may be a url - urls will be referenced via a tag $css = "body { font-family: sans-serif; color: #333333; background: #f3f3f3; } +label { display: inline-block; min-width: 10rem; } textarea[name=content] { display: block; width: 100%; height: 35rem; } -input[name=page] { width: 16rem; } +/*input[name=page] { width: 16rem; }*/ nav { position: absolute; top: 5px; right: 5px; } th { text-align: left; } .sitename { text-align: center; font-size: 2.5rem; color: #222222; } @@ -666,7 +668,47 @@ switch($_GET["action"]) * %move% */ case "move": - exit(renderpage("Moving $page", "Coming soon...
")); + if(!$isadmin) + exit(renderpage("Moving $page - Error", "You tried to move $page, but you do not have permission to do that.
+You should try logging in as an admin.
")); + + if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0) + exit(renderpage("Moving $page", "You tried to move $page to $new_name, but the page with the name $page does not exist in the first place.
+Nothing has been changed.
")); + + if($page == $new_name) + exit(renderpage("Moving $page - Error", "You tried to move $page, but the new name you gave is the same as it's current name.
+It is possible that you tried to use some characters in the new name that are not allowed and were removed.
+Page names may only contain alphanumeric characters, dashes, and underscores.
")); + + //move the page in the page index + $pageindex->$new_name = new stdClass(); + foreach($pageindex->$page as $key => $value) + { + $pageindex->$new_name->$key = $value; + } + unset($pageindex->$page); + file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); + + //move the page on the disk + rename("$page.md", "$new_name.md"); + + exit(renderpage("Moving $page", "")); break; /* diff --git a/settings.fragment.php b/settings.fragment.php index 6cb15ef..4054d13 100644 --- a/settings.fragment.php +++ b/settings.fragment.php @@ -64,6 +64,7 @@ $navlinks = [ [ "Printable", "index.php?action=view&printable=yes&page={page}" ], " | ", [ $admindisplaychar . "Delete", "index.php?action=delete&page={page}" ], + [ $admindisplaychar . "Move", "index.php?action=move&page={page}" ], " | ", [ "All Pages", "index.php?action=list" ], " | ", @@ -74,8 +75,9 @@ $navlinks = [ //string of css to include //may be a url - urls will be referenced via a tag $css = "body { font-family: sans-serif; color: #333333; background: #f3f3f3; } +label { display: inline-block; min-width: 10rem; } textarea[name=content] { display: block; width: 100%; height: 35rem; } -input[name=page] { width: 16rem; } +/*input[name=page] { width: 16rem; }*/ nav { position: absolute; top: 5px; right: 5px; } th { text-align: left; } .sitename { text-align: center; font-size: 2.5rem; color: #222222; }