From 72c20a52978f31b84ffc817894f9f85f4a8506ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 3 Dec 2013 10:40:27 +0100 Subject: [add] atom feeds for unread / fav items --- inc/poche/Poche.class.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'inc/poche/Poche.class.php') 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 $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&id=' . $entry['id']); + $newItem->setDate(time()); + $newItem->setDescription($entry['content']); + $feed->addItem($newItem); + } + } + + $feed->genarateFeed(); + exit; + } } -- cgit v1.2.3