Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. if (isset($_SERVER['HTTP_HOST'])) {
  3. header ('Content-type: text/plain; charset=utf-8');
  4. http_response_code(403);
  5. die("NO!!!\n");
  6. }
  7. /**************************************************/
  8. $page_type_locations = [
  9. "page" => "pages",
  10. "post" => "posts",
  11. "gallery" => "pages",
  12. ];
  13. $page_type_templates = [
  14. "page" => "templates/generic-page.shtml",
  15. "post" => "templates/news-post.shtml",
  16. "gallery" => "templates/image-gallery.shtml",
  17. ];
  18. /**************************************************/
  19. if ($argc < 2)
  20. print_usage_and_exit();
  21. $command = $argv[1];
  22. switch ($command) {
  23. case "new": {
  24. if ($argc < 3)
  25. print_usage_and_exit();
  26. $page_type = $argv[2];
  27. $page_name = ($argc > 3) ? $argv[3] : ("new-".$page_type);
  28. new_page($page_type, $page_name);
  29. die;
  30. }
  31. default: {
  32. print_usage_and_exit();
  33. }
  34. }
  35. /**************************************************/
  36. function new_page($page_type, $page_name) {
  37. global $page_type_locations, $page_type_templates;
  38. if (!isset($page_type_locations[$page_type]))
  39. print_error_and_exit("UNSPECIFIED_LOCATION");
  40. if (!isset($page_type_templates[$page_type]))
  41. print_error_and_exit("MISSING_TEMPLATE");
  42. $page_directory = "{$page_type_locations[$page_type]}/{$page_name}";
  43. `mkdir {$page_directory}`;
  44. `cp {$page_type_templates[$page_type]} {$page_directory}/index.shtml`;
  45. echo "Created new {$page_type} at {$page_directory}/index.shtml.\n";
  46. }
  47. function print_usage_and_exit() {
  48. global $page_type_templates;
  49. echo "Usage is:\n";
  50. echo " deus.php <command> [ <options> ]\n";
  51. echo "\n";
  52. echo "Available commands are:\n";
  53. echo " new Create a new page of the specified type and name\n";
  54. echo " Options:\n";
  55. echo " Page type (" . implode(", ", array_keys($page_type_templates)) . ") and optional page name\n";
  56. echo " Examples:\n";
  57. echo " deus.php new post\n";
  58. echo " (Creates new generic post called 'new-post')\n";
  59. echo " deus.php new gallery my-cool-gallery\n";
  60. die;
  61. }
  62. function print_error_and_exit($error_code) {
  63. switch ($error_code) {
  64. case "UNSPECIFIED_LOCATION": {
  65. echo "Target location not specified for pages of the specified type.\n";
  66. break;
  67. }
  68. case "MISSING_TEMPLATE": {
  69. echo "No template provided for pages of the specified type.\n";
  70. break;
  71. }
  72. default: {
  73. echo "NO!!!\n";
  74. break;
  75. }
  76. }
  77. die;
  78. }
  79. ?>