From 10d9b12b95f935f04859768de1d7f8e3667179f8 Mon Sep 17 00:00:00 2001 From: Said Achmiz Date: Tue, 11 Feb 2020 02:09:15 -0500 Subject: [PATCH] Added utility script deus.php --- .htaccess | 3 ++ deus.php | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 deus.php diff --git a/.htaccess b/.htaccess index a8226f7..c414742 100644 --- a/.htaccess +++ b/.htaccess @@ -12,4 +12,7 @@ DirectoryIndex index.shtml RewriteEngine On RewriteBase /deus/ + RewriteRule ^(.+?)index\.html$ $1index.shtml [QSA,L] + +RewriteRule \.php - [NC,F,L] diff --git a/deus.php b/deus.php new file mode 100644 index 0000000..efa3d45 --- /dev/null +++ b/deus.php @@ -0,0 +1,99 @@ + "pages", + "post" => "posts", + "gallery" => "pages", +]; + +$page_type_templates = [ + "page" => "templates/generic-page.shtml", + "post" => "templates/news-post.shtml", + "gallery" => "templates/image-gallery.shtml", +]; + +/**************************************************/ + +if ($argc < 2) + print_usage_and_exit(); + +$command = $argv[1]; + +switch ($command) { + case "new": { + if ($argc < 3) + print_usage_and_exit(); + + $page_type = $argv[2]; + $page_name = ($argc > 3) ? $argv[3] : ("new-".$page_type); + + new_page($page_type, $page_name); + + die; + } + default: { + print_usage_and_exit(); + } +} + +/**************************************************/ + +function new_page($page_type, $page_name) { + global $page_type_locations, $page_type_templates; + + if (!isset($page_type_locations[$page_type])) + print_error_and_exit("UNSPECIFIED_LOCATION"); + + if (!isset($page_type_templates[$page_type])) + print_error_and_exit("MISSING_TEMPLATE"); + + $page_directory = "{$page_type_locations[$page_type]}/{$page_name}"; + `mkdir {$page_directory}`; + `cp {$page_type_templates[$page_type]} {$page_directory}/index.shtml`; + echo "Created new {$page_type} at {$page_directory}/index.shtml.\n"; +} + +function print_usage_and_exit() { + global $page_type_templates; + + echo "Usage is:\n"; + echo " deus.php [ ]\n"; + echo "\n"; + echo "Available commands are:\n"; + echo " new Create a new page of the specified type and name\n"; + echo " Options:\n"; + echo " Page type (" . implode(", ", array_keys($page_type_templates)) . ") and optional page name\n"; + echo " Examples:\n"; + echo " deus.php new post\n"; + echo " (Creates new generic post called 'new-post')\n"; + echo " deus.php new gallery my-cool-gallery\n"; + die; +} + +function print_error_and_exit($error_code) { + switch ($error_code) { + case "UNSPECIFIED_LOCATION": { + echo "Target location not specified for pages of the specified type.\n"; + break; + } + case "MISSING_TEMPLATE": { + echo "No template provided for pages of the specified type.\n"; + break; + } + default: { + echo "NO!!!\n"; + break; + } + } + die; +} + +?> \ No newline at end of file