Get rid of deprecated API usage:
[grauphel.git] / controller / guicontroller.php
index 8ebea8c58f5b8900e4dfeb7a14cc97ed1e079f13..ef109a7fb787b9faeba03e3553ff079264966608 100644 (file)
@@ -122,11 +122,17 @@ class GuiController extends Controller
                 'note' => $note,
                 'note-content' => $contentHtml,
                 'links' => array(
+                    'html' => $this->urlGen->linkToRoute(
+                        'grauphel.notes.html', array('guid' => $guid)
+                    ),
                     'json' => $this->urlGen->linkToRoute(
                         'grauphel.api.note', array(
                             'guid' => $guid, 'username' => $this->user->getUid()
                         )
                     ),
+                    'text' => $this->urlGen->linkToRoute(
+                        'grauphel.notes.text', array('guid' => $guid)
+                    ),
                     'xml' => $this->urlGen->linkToRoute(
                         'grauphel.notes.xml', array('guid' => $guid)
                     ),
@@ -140,6 +146,7 @@ class GuiController extends Controller
         }
 
         $this->addNavigation($res, $selectedRawtag);
+        $this->addGlobalVars($res);
         return $res;
     }
 
@@ -162,6 +169,7 @@ class GuiController extends Controller
      */
     public function tag($rawtag)
     {
+        $rawtag = $this->unescapeTagFromUrl($rawtag);
         $notes = $this->getNotes()->loadNotesOverview(null, $rawtag, true);
         usort(
             $notes,
@@ -189,6 +197,7 @@ class GuiController extends Controller
                 'notes'  => $notes,
             )
         );
+        $this->addGlobalVars($res);
         $this->addNavigation($res, $rawtag);
 
         return $res;
@@ -213,6 +222,7 @@ class GuiController extends Controller
                 'username' => $this->user->getUid(),
             )
         );
+        $this->addGlobalVars($res);
         $this->addNavigation($res, null);
 
         return $res;
@@ -253,6 +263,19 @@ class GuiController extends Controller
         return $this->database($reset);
     }
 
+    /**
+     * Register some variables that templates will probably need.
+     *
+     * @return void
+     */
+    protected function addGlobalVars(TemplateResponse $res)
+    {
+        $params = $res->getParams();
+        $params['date']   = \OC::$server->getDateTimeFormatter();
+        $params['urlGen'] = \OC::$server->getURLGenerator();
+        $res->setParams($params);
+    }
+
     protected function addNavigation(TemplateResponse $res, $selectedRawtag = null)
     {
         $nav = new \OCP\Template('grauphel', 'appnavigation', '');
@@ -282,7 +305,8 @@ class GuiController extends Controller
                     'name' => $name,
                     'id'   => $rawtag,
                     'href' => $this->urlGen->linkToRoute(
-                        'grauphel.gui.tag', array('rawtag' => $rawtag)
+                        'grauphel.gui.tag',
+                        array('rawtag' => $this->escapeTagForUrl($rawtag))
                     ),
                     'selected' => $rawtag == $selectedRawtag,
                 );
@@ -346,5 +370,15 @@ class GuiController extends Controller
         }
         return false;
     }
+
+    protected function escapeTagForUrl($rawtag)
+    {
+        return str_replace('/', '%2F', $rawtag);
+    }
+
+    protected function unescapeTagFromUrl($rawtag)
+    {
+        return str_replace('%2F', '/', $rawtag);
+    }
 }
 ?>