diff --git a/README.md b/README.md index b7224db..5ab39ba 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ You're welcome for contributing or testing though! :o)
### ToDo: +* archivate sent newsletters * admin UI: * protect admin dir with .htaccess/.htpasswd + add UI accordingly (not so sure this is practical, will be tied to Apache...) diff --git a/admin/index.php b/admin/index.php index 23344d7..efaec61 100755 --- a/admin/index.php +++ b/admin/index.php @@ -71,6 +71,14 @@ } + if (isset($error)) { + $logTimeFormat = date("Y-m-d"); + file_put_contents( + $cbNewsletter["basedir"] . "/admin/logs/debug_" . $logTimeFormat . ".log", + "\n\n=============================================================================================================================\n" . date("Y-m-d H:i:s") . "\n\n" . $Debugout->output(true), + FILE_APPEND | LOCK_EX + ); + } $cbNewsletter_endTime = microtime(); diff --git a/admin/lib/routes.php b/admin/lib/routes.php new file mode 100644 index 0000000..9d5b7e0 --- /dev/null +++ b/admin/lib/routes.php @@ -0,0 +1,13 @@ + "/admin/actions/subscriptions.action.php", + "subscriptions" => "/admin/actions/subscriptions.action.php", + "config" => "/admin/actions/config.action.php", + "create_newsletter" => "/admin/actions/create_newsletter.action.php", + "send_newsletter" => "/admin/actions/send_newsletter.action.php", + + ); + +?> diff --git a/admin/lib/routing.php b/admin/lib/routing.php index 2d4f372..c13c62d 100755 --- a/admin/lib/routing.php +++ b/admin/lib/routing.php @@ -57,19 +57,16 @@ -// ================ routing ================ +// =================== Routing =================== - if (isset($_GET["view"]) and strlen($_GET["view"]) > 1 and $_GET["view"] != "subscriptions") { - include_once(checkout("/admin/actions/" . $_GET["view"] . ".action.php")); + include_once(checkout( + Router::load("/admin/lib/routes.php") + ->direct($cbNewsletter["config"]["view"]) + )); - } else { - include_once(checkout("/admin/actions/subscriptions.action.php")); - - } - -// ================ routing ================ +// =================== Routing =================== diff --git a/index.php b/index.php index 5521c41..b0d3e9f 100755 --- a/index.php +++ b/index.php @@ -81,7 +81,7 @@ - if ($debug and isset($error)) { + if (isset($error)) { cbNewsletter_showErrors($error); } @@ -92,7 +92,7 @@ $logTimeFormat = date("Y-m-d"); file_put_contents( $cbNewsletter["basedir"] . "/admin/logs/debug_" . $logTimeFormat . ".log", - $Debugout->output(true), + "\n\n=============================================================================================================================\n" . date("Y-m-d H:i:s") . "\n\n" . $Debugout->output(true), FILE_APPEND | LOCK_EX ); } diff --git a/lib/bootstrap.common.php b/lib/bootstrap.common.php index cf40e87..3614475 100644 --- a/lib/bootstrap.common.php +++ b/lib/bootstrap.common.php @@ -10,6 +10,16 @@ + include_once(checkout("/lib/classes/Router.class.php")); + + include_once(checkout("/lib/classes/Request.class.php")); + + $cbNewsletter["config"]["view"] = Request::view(); + + $Debugout->add("\$cbNewsletter[\"config\"][\"view\"] set to", $cbNewsletter["config"]["view"]); + + + // General functions include_once(checkout("/lib/classes/HTML.class.php")); $HTML = new HTML; diff --git a/lib/bootstrap.php b/lib/bootstrap.php index 173d3e8..abcfdd2 100755 --- a/lib/bootstrap.php +++ b/lib/bootstrap.php @@ -2,9 +2,7 @@ $Debugout->add("
[ bootstrap ]");
 
-  if (isset($_GET["view"])) {
-    $cbNewsletter["config"]["view"] = $_GET["view"];
-  }
+
 
 
   // Other classes
@@ -15,6 +13,8 @@
 
 
 
+
+
   // common bootstrap
   include_once(checkout("/lib/bootstrap.common.php"));
 
diff --git a/lib/classes/Request.class.php b/lib/classes/Request.class.php
new file mode 100644
index 0000000..cbfb2ee
--- /dev/null
+++ b/lib/classes/Request.class.php
@@ -0,0 +1,25 @@
+
diff --git a/lib/classes/Router.class.php b/lib/classes/Router.class.php
new file mode 100644
index 0000000..2c27c58
--- /dev/null
+++ b/lib/classes/Router.class.php
@@ -0,0 +1,52 @@
+routes = include_once(checkout($file));
+
+    return $Router;
+
+  }
+
+  public function direct($view) {
+
+    global $Debugout, $error;
+
+    if (array_key_exists($view, $this->routes)) {
+
+      $route = $this->routes[$view];
+
+      $Debugout->add(
+        "directing known view '" . $view . "' to",
+        $route
+      );
+
+      return $route;
+
+    } else {
+
+      $route = $this->routes[""];
+
+      $error["routing"]["invalid_route"] = $view;
+
+      $Debugout->add(
+        "directing unknown view '" . $view . "' to error page"
+      );
+
+      return "/views/error.view.php";
+
+    }
+
+  }
+
+}
+
+?>
diff --git a/lib/routes.php b/lib/routes.php
new file mode 100644
index 0000000..6a2439b
--- /dev/null
+++ b/lib/routes.php
@@ -0,0 +1,15 @@
+ "/views/subscription.form.php",
+    "enter_subscription"    => "/actions/enter_subscription.action.php",
+    "manage_subscription"   => "/actions/manage_subscription.action.php",
+    "verify_subscription"   => "/actions/verify_subscription.action.php",
+    "verify_unsubscription" => "/action/verify_unsubscription.action.php",
+
+  );
+
+
+?>
diff --git a/lib/routing.php b/lib/routing.php
index a83d581..3daa0ae 100755
--- a/lib/routing.php
+++ b/lib/routing.php
@@ -2,7 +2,6 @@
 
   $Debugout->add("
[ routing ]");
 
-// =================== Routing ===================
 
 // ================  pre display  ================
 
@@ -52,17 +51,16 @@
 
 
 
+// =================== Routing ===================
 
-  if (isset($cbNewsletter["config"]["view"]) and strlen($cbNewsletter["config"]["view"]) > 1) {
-
-    include_once(checkout("/actions/" . $_GET["view"] . ".action.php"));
-
-  } else {
 
-    include_once(checkout("/views/subscription.form.php"));
+  include_once(checkout(
+    Router::load("/lib/routes.php")
+      ->direct($cbNewsletter["config"]["view"])
+  ));
 
-  }
 
+// =================== Routing ===================
 
 
 
@@ -76,7 +74,7 @@
 
 // ===============  post display  ================
 
-// =================== Routing ===================
+
 
   $Debugout->add("
"); diff --git a/views/error.view.php b/views/error.view.php new file mode 100644 index 0000000..c13585a --- /dev/null +++ b/views/error.view.php @@ -0,0 +1,4 @@ + +

+ +