]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
[add] atom feeds for unread / fav items 350/head
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Tue, 3 Dec 2013 09:40:27 +0000 (10:40 +0100)
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Tue, 3 Dec 2013 09:40:27 +0000 (10:40 +0100)
inc/poche/Poche.class.php
index.php
themes/default/config.twig

index 3ecaf084a7347c737e78e8e1fd3bf87615b8377d..ac66dfc9ccd4f51c447e3f11d58f6d6142ac4a70 100644 (file)
@@ -412,6 +412,7 @@ class Poche
                 $compare_prod = version_compare(POCHE, $prod);
                 $themes = $this->getInstalledThemes();
                 $languages = $this->getInstalledLanguages();
+                $token = $this->user->getConfigValue('token');
                 $http_auth = (isset($_SERVER['PHP_AUTH_USER']))?true:false;
                 $tpl_vars = array(
                     'themes' => $themes,
@@ -420,6 +421,8 @@ class Poche
                     'prod' => $prod,
                     'compare_dev' => $compare_dev,
                     'compare_prod' => $compare_prod,
+                    'token' => $token,
+                    'user_id' => $this->user->getId(),
                     'http_auth' => $http_auth,
                 );
                 Tools::logm('config view');
@@ -837,4 +840,52 @@ class Poche
         }
         return $version;
     }
+
+    public function generateToken()
+    {
+        if (ini_get('open_basedir') === '') {
+            $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
+        }
+        else {
+            $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
+        }
+
+        $this->store->updateUserConfig($this->user->getId(), 'token', $token);
+        $currentConfig = $_SESSION['poche_user']->config;
+        $currentConfig['token'] = $token;
+        $_SESSION['poche_user']->setConfig($currentConfig);
+    }
+
+    public function generateFeeds($token, $user_id, $type = 'home')
+    {
+        $allowed_types = array('home', 'fav');
+        $config = $this->store->getConfigUser($user_id);
+
+        if (!in_array($type, $allowed_types) ||
+            $token != $config['token']) {
+            die(_('Uh, there is a problem while generating feeds.'));
+        }
+        // Check the token
+
+        $feed = new FeedWriter(ATOM);
+        $feed->setTitle('poche - ' . $type . ' feed');
+        $feed->setLink(Tools::getPocheUrl());
+        $feed->setChannelElement('updated', date(DATE_ATOM , time()));
+        $feed->setChannelElement('author', 'poche');
+
+        $entries = $this->store->getEntriesByView($type, $user_id);
+        if (count($entries) > 0) {
+            foreach ($entries as $entry) {
+                $newItem = $feed->createNewItem();
+                $newItem->setTitle(htmlentities($entry['title']));
+                $newItem->setLink(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']);
+                $newItem->setDate(time());
+                $newItem->setDescription($entry['content']);
+                $feed->addItem($newItem);
+            }
+        }
+
+        $feed->genarateFeed();
+        exit;
+    }
 }
index ba146257a8e7905ed9dbc235a26de85c1064bc2f..7d462228e7d5be446d3b76f6014dbd97c41ae075 100644 (file)
--- a/index.php
+++ b/index.php
@@ -70,6 +70,13 @@ if (isset($_GET['login'])) {
     $poche->updateTheme();
 } elseif (isset($_GET['updatelanguage'])) {
     $poche->updateLanguage();
+} elseif (isset($_GET['feed'])) {
+    if ($_GET['action'] == 'generate') {
+        $poche->generateToken();
+    }
+    else {
+        $poche->generateFeeds($_GET['token'], $_GET['user_id'], $_GET['type']);
+    }
 }
 
 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
index a27836b4cfaf3928db6897c17f074fa4b9be860f..7cf3fe9c25779559c9efbdaa46c861633df560f0 100644 (file)
                 <li>{% trans "latest stable version" %} : {{ prod }}. {% if compare_prod == -1 %}<strong><a href="http://inthepoche.com/">{% trans "a more recent stable version is available." %}</a></strong>{% else %}{% trans "you are up to date." %}{% endif %}</li>
                 {% if constant('DEBUG_POCHE') == 1 %}<li>{% trans "latest dev version" %} : {{ dev }}. {% if compare_dev == -1 %}<strong><a href="http://inthepoche.com/">{% trans "a more recent development version is available." %}</a></strong>{% else %}{% trans "you are up to date." %}{% endif %}</li>{% endif %}
             </ul>
+
+            <h2>{% trans "Feeds" %}</h2>
+            {% if token == '' %}
+                <p>{% trans "The token is empty, you have to generate it to use feeds. Click <a href='?feed&amp;action=generate'>here to generate it</a>." %}</p>
+            {% else %}
+            <ul>
+                <li><a href="?feed&amp;type=home&amp;user_id={{ user_id }}&amp;token={{ token }}" target="_blank">{% trans "unread feed" %}</a></li>
+                <li><a href="?feed&amp;type=fav&amp;user_id={{ user_id }}&amp;token={{ token }}" target="_blank">{% trans "favorites feed" %}</a></li>
+            </ul>
+            {% endif %}
             
             <h2>{% trans "Change your theme" %}</h2>
             <form method="post" action="?updatetheme" name="changethemeform">