move formatting from JS to PHP
[mdref/mdref] / mdref / Action.php
index da3a4da871c5dd6c354af8990b8d66f879d9e1a0..0c48dd6b403c448d5d6f9538b141e448aadc01d1 100644 (file)
@@ -77,6 +77,10 @@ class Action {
                $pld->ref = $this->baseUrl->pathinfo(
                        $this->baseUrl->mod($this->request->getRequestUrl()));
 
+               $pld->markup = function($page) use($pld) {
+                       return $this->reference->getFormatter()->markup($page, $pld);
+               };
+
                $pld->refs = $this->reference;
                $pld->baseUrl = $this->baseUrl;
 
@@ -180,6 +184,9 @@ class Action {
                include ROOT."/views/layout.phtml";
                $this->response->addHeader("Link", "<" . $this->baseUrl->path . "index.css>; rel=preload; as=style");
                $this->response->addHeader("Link", "<" . $this->baseUrl->path . "index.js>; rel=preload; as=script");
+               if (isset($exception) && $exception->getCode()) {
+                       $this->response->setResponseCode($exception->getCode());
+               }
                if (is_resource($this->output)) {
                        $this->response->send($this->output);
                } else {
@@ -194,10 +201,10 @@ class Action {
                try {
                        $pld = $this->createPayload();
 
-                       if (strlen($pld->ref)) {
+                       if (isset($pld->ref) && strlen($pld->ref)) {
                                $cnn = null;
                                if (($repo = $this->reference->getRepoForEntry($pld->ref, $cnn))) {
-                                       if (strlen($cnn)) {
+                                       if (isset($cnn) && strlen($cnn)) {
                                                /* redirect */
                                                $this->serveCanonical($cnn);
                                                return;