aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Database.class.php2
-rw-r--r--inc/poche/Poche.class.php51
2 files changed, 52 insertions, 1 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index bf67de2a..c233eda1 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -74,7 +74,7 @@ class Database {
74 return TRUE; 74 return TRUE;
75 } 75 }
76 76
77 private function getConfigUser($id) { 77 public function getConfigUser($id) {
78 $sql = "SELECT * FROM users_config WHERE user_id = ?"; 78 $sql = "SELECT * FROM users_config WHERE user_id = ?";
79 $query = $this->executeQuery($sql, array($id)); 79 $query = $this->executeQuery($sql, array($id));
80 $result = $query->fetchAll(); 80 $result = $query->fetchAll();
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&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}