Get rid of deprecated API usage:
authorChristian Weiske <cweiske@cweiske.de>
Sun, 7 Oct 2018 09:44:54 +0000 (11:44 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 7 Oct 2018 09:44:54 +0000 (11:44 +0200)
- \OC_User
- \OCP\User
- \OCP\Util::formatDate

Resolves: https://github.com/cweiske/grauphel/issues/69

controller/guicontroller.php
lib/search/provider.php
templates/appnavigation.php
templates/gui-note.php
templates/tag.php
templates/tokens.php

index d48296d49af8b50343b8e3e51c03d195560dc06a..ef109a7fb787b9faeba03e3553ff079264966608 100644 (file)
@@ -146,6 +146,7 @@ class GuiController extends Controller
         }
 
         $this->addNavigation($res, $selectedRawtag);
+        $this->addGlobalVars($res);
         return $res;
     }
 
@@ -196,6 +197,7 @@ class GuiController extends Controller
                 'notes'  => $notes,
             )
         );
+        $this->addGlobalVars($res);
         $this->addNavigation($res, $rawtag);
 
         return $res;
@@ -220,6 +222,7 @@ class GuiController extends Controller
                 'username' => $this->user->getUid(),
             )
         );
+        $this->addGlobalVars($res);
         $this->addNavigation($res, null);
 
         return $res;
@@ -260,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', '');
index b3957781cb2c6ec66654f0eb73d2b6a340a1f415..816209ef8d609ce32994bc42c3cde91fbd896253 100644 (file)
@@ -39,7 +39,9 @@ class Provider extends \OCP\Search\Provider
     {
         $urlGen = \OC::$server->getURLGenerator();
         $notes  = new NoteStorage($urlGen);
-        $notes->setUsername(\OC_User::getUser());
+        $notes->setUsername(
+            \OC::$server->getUserSession()->getUser()->getUID()
+        );
 
         $qp = new QueryParser();
         $rows = $notes->search($qp->parse($query));
index 7d51049829f736300ccde2e7f21f406840c28e7a..72e30b6cefff27d360b5268afa6af6fcd85cda09 100644 (file)
@@ -12,7 +12,7 @@
     <div id="app-settings-content" style="display: none;">
       <ul>
         <li><a href="<?php p(OC::$server->getURLGenerator()->linkToRoute('grauphel.gui.index')); ?>">Info and stats</a></li>
-      <?php if (OCP\User::isLoggedIn()) { ?>
+      <?php if (\OC::$server->getUserSession()->isLoggedIn()) { ?>
         <li><a href="<?php p(OC::$server->getURLGenerator()->linkToRoute('grauphel.gui.tokens')); ?>">Manage access tokens</a></li>
         <li><a href="<?php p(OC::$server->getURLGenerator()->linkToRoute('grauphel.gui.database')); ?>">Manage database</a></li>
       <?php } ?>
index 2aa5a209a9a19f0171ac668aeaebd6b4b5fc31f6..bb8d03e282bdd910670dd3d47b6b6e4871169877 100644 (file)
@@ -14,7 +14,7 @@
  <h1><?php echo ($_['note']->title); ?></h1>
  <p class="muted">
   Last modified:
-  <?php p(\OCP\Util::formatDate(strtotime($_['note']->{'last-change-date'}))); ?>
+  <?php p($_['date']->formatDate(strtotime($_['note']->{'last-change-date'}))); ?>
  </p>
  <div class="note-content">
   <?php echo $_['note-content']; ?>
index ee5f592da8ed906decf5cf90be4ab39d3ada6bff..e8e092efd058de847a2f6dc8f16e3f4c287d827b 100644 (file)
     <?php foreach ($_['notes'] as $note) { ?>
      <tr id="note-<?php p($note['guid']); ?>">
       <td>
-       <a class="cellclick" href="<?php p(OC::$server->getURLGenerator()->linkToRoute('grauphel.gui.note', array('guid' => $note['guid']))); ?>"><?php echo ($note['title']); ?></a>
+       <a class="cellclick" href="<?php p($_['urlGen']->linkToRoute('grauphel.gui.note', array('guid' => $note['guid']))); ?>"><?php echo ($note['title']); ?></a>
       </td>
       <td style="color: <?php echo p($note['dateColor']); ?>">
-       <?php p(\OCP\Util::formatDate(strtotime($note['last-change-date']))); ?>
+       <?php p($_['date']->formatDate(strtotime($note['last-change-date']))); ?>
       </td>
      </tr>
     <?php } ?>
index 9fe7dd68d4bcb18b2f7d5fbcf3f2e9349a44933c..9d812ebe52e7a8e1c7d5636c589eb7c56db9e455 100644 (file)
@@ -26,7 +26,7 @@
        <td><?php p($token->tokenKey); ?></td>
        <td title="<?php p($token->client); ?>"><?php p($_['client']->getNiceName($token->client)); ?></td>
        <td>
-        <?php p(\OCP\Util::formatDate($token->lastuse)); ?>
+        <?php p($_['date']->formatDate($token->lastuse)); ?>
         <form method="POST" action="<?php p(OC::$server->getURLGenerator()->linkToRoute('grauphel.token.delete', array('username' => $_['username'], 'tokenKey' => $token->tokenKey))); ?>">
            <input type="hidden" name="delete" value="1" />
            <button type="submit" class="icon-delete delete action"