aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-12-03 10:40:27 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-12-03 10:40:27 +0100
commit72c20a52978f31b84ffc817894f9f85f4a8506ee (patch)
tree78b133d6c397cf44d711f15a8f1785cd76c9d6ea
parent5846b0f1b32f7f9b99a3c20acfeeaee9781eebea (diff)
downloadwallabag-72c20a52978f31b84ffc817894f9f85f4a8506ee.tar.gz
wallabag-72c20a52978f31b84ffc817894f9f85f4a8506ee.tar.zst
wallabag-72c20a52978f31b84ffc817894f9f85f4a8506ee.zip
[add] atom feeds for unread / fav items
-rw-r--r--inc/poche/Poche.class.php51
-rw-r--r--index.php7
-rw-r--r--themes/default/config.twig10
3 files changed, 68 insertions, 0 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 3ecaf084..ac66dfc9 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -412,6 +412,7 @@ class Poche
412 $compare_prod = version_compare(POCHE, $prod); 412 $compare_prod = version_compare(POCHE, $prod);
413 $themes = $this->getInstalledThemes(); 413 $themes = $this->getInstalledThemes();
414 $languages = $this->getInstalledLanguages(); 414 $languages = $this->getInstalledLanguages();
415 $token = $this->user->getConfigValue('token');
415 $http_auth = (isset($_SERVER['PHP_AUTH_USER']))?true:false; 416 $http_auth = (isset($_SERVER['PHP_AUTH_USER']))?true:false;
416 $tpl_vars = array( 417 $tpl_vars = array(
417 'themes' => $themes, 418 'themes' => $themes,
@@ -420,6 +421,8 @@ class Poche
420 'prod' => $prod, 421 'prod' => $prod,
421 'compare_dev' => $compare_dev, 422 'compare_dev' => $compare_dev,
422 'compare_prod' => $compare_prod, 423 'compare_prod' => $compare_prod,
424 'token' => $token,
425 'user_id' => $this->user->getId(),
423 'http_auth' => $http_auth, 426 'http_auth' => $http_auth,
424 ); 427 );
425 Tools::logm('config view'); 428 Tools::logm('config view');
@@ -837,4 +840,52 @@ class Poche
837 } 840 }
838 return $version; 841 return $version;
839 } 842 }
843
844 public function generateToken()
845 {
846 if (ini_get('open_basedir') === '') {
847 $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
848 }
849 else {
850 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
851 }
852
853 $this->store->updateUserConfig($this->user->getId(), 'token', $token);
854 $currentConfig = $_SESSION['poche_user']->config;
855 $currentConfig['token'] = $token;
856 $_SESSION['poche_user']->setConfig($currentConfig);
857 }
858
859 public function generateFeeds($token, $user_id, $type = 'home')
860 {
861 $allowed_types = array('home', 'fav');
862 $config = $this->store->getConfigUser($user_id);
863
864 if (!in_array($type, $allowed_types) ||
865 $token != $config['token']) {
866 die(_('Uh, there is a problem while generating feeds.'));
867 }
868 // Check the token
869
870 $feed = new FeedWriter(ATOM);
871 $feed->setTitle('poche - ' . $type . ' feed');
872 $feed->setLink(Tools::getPocheUrl());
873 $feed->setChannelElement('updated', date(DATE_ATOM , time()));
874 $feed->setChannelElement('author', 'poche');
875
876 $entries = $this->store->getEntriesByView($type, $user_id);
877 if (count($entries) > 0) {
878 foreach ($entries as $entry) {
879 $newItem = $feed->createNewItem();
880 $newItem->setTitle(htmlentities($entry['title']));
881 $newItem->setLink(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']);
882 $newItem->setDate(time());
883 $newItem->setDescription($entry['content']);
884 $feed->addItem($newItem);
885 }
886 }
887
888 $feed->genarateFeed();
889 exit;
890 }
840} 891}
diff --git a/index.php b/index.php
index ba146257..7d462228 100644
--- a/index.php
+++ b/index.php
@@ -70,6 +70,13 @@ if (isset($_GET['login'])) {
70 $poche->updateTheme(); 70 $poche->updateTheme();
71} elseif (isset($_GET['updatelanguage'])) { 71} elseif (isset($_GET['updatelanguage'])) {
72 $poche->updateLanguage(); 72 $poche->updateLanguage();
73} elseif (isset($_GET['feed'])) {
74 if ($_GET['action'] == 'generate') {
75 $poche->generateToken();
76 }
77 else {
78 $poche->generateFeeds($_GET['token'], $_GET['user_id'], $_GET['type']);
79 }
73} 80}
74 81
75elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { 82elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
diff --git a/themes/default/config.twig b/themes/default/config.twig
index a27836b4..7cf3fe9c 100644
--- a/themes/default/config.twig
+++ b/themes/default/config.twig
@@ -28,6 +28,16 @@
28 <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> 28 <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>
29 {% 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 %} 29 {% 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 %}
30 </ul> 30 </ul>
31
32 <h2>{% trans "Feeds" %}</h2>
33 {% if token == '' %}
34 <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>
35 {% else %}
36 <ul>
37 <li><a href="?feed&amp;type=home&amp;user_id={{ user_id }}&amp;token={{ token }}" target="_blank">{% trans "unread feed" %}</a></li>
38 <li><a href="?feed&amp;type=fav&amp;user_id={{ user_id }}&amp;token={{ token }}" target="_blank">{% trans "favorites feed" %}</a></li>
39 </ul>
40 {% endif %}
31 41
32 <h2>{% trans "Change your theme" %}</h2> 42 <h2>{% trans "Change your theme" %}</h2>
33 <form method="post" action="?updatetheme" name="changethemeform"> 43 <form method="post" action="?updatetheme" name="changethemeform">