From df6afaf0909506a334ef2b8c6f69770cd9890e0d Mon Sep 17 00:00:00 2001 From: Denis Sacchet Date: Sun, 20 Oct 2013 16:53:54 +0200 Subject: Added support for http_auth --- inc/poche/Poche.class.php | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 806da54b..0766cd51 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -408,6 +408,7 @@ class Poche $compare_prod = version_compare(POCHE, $prod); $themes = $this->getInstalledThemes(); $languages = $this->getInstalledLanguages(); + $http_auth = (isset($_SERVER['PHP_AUTH_USER']))?true:false; $tpl_vars = array( 'themes' => $themes, 'languages' => $languages, @@ -415,6 +416,7 @@ class Poche 'prod' => $prod, 'compare_dev' => $compare_dev, 'compare_prod' => $compare_prod, + 'http_auth' => $http_auth, ); Tools::logm('config view'); break; @@ -573,6 +575,21 @@ class Poche Tools::redirect('?view=config'); } + /** + * get credentials from differents sources + * it redirects the user to the $referer link + * @return array + */ + private function credentials() { + if(isset($_SERVER['PHP_AUTH_USER'])) { + return array($_SERVER['PHP_AUTH_USER'],'php_auth'); + } + if(!empty($_POST['login']) && !empty($_POST['password'])) { + return array($_POST['login'],$_POST['password']); + } + return array(false,false); + } + /** * checks if login & password are correct and save the user in session. * it redirects the user to the $referer link @@ -582,11 +599,17 @@ class Poche */ public function login($referer) { - if (!empty($_POST['login']) && !empty($_POST['password'])) { - $user = $this->store->login($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])); + list($login,$password)=$this->credentials(); + if($login === false || $password === false) { + $this->messages->add('e', _('login failed: you have to fill all fields')); + Tools::logm('login failed'); + Tools::redirect(); + } + if (!empty($login) && !empty($password)) { + $user = $this->store->login($login, Tools::encodeString($password . $login)); if ($user != array()) { # Save login into Session - Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user))); + Session::login($user['username'], $user['password'], $login, Tools::encodeString($password . $login), array('poche_user' => new User($user))); $this->messages->add('s', _('welcome to your poche')); Tools::logm('login successful'); Tools::redirect($referer); @@ -594,10 +617,6 @@ class Poche $this->messages->add('e', _('login failed: bad login or password')); Tools::logm('login failed'); Tools::redirect(); - } else { - $this->messages->add('e', _('login failed: you have to fill all fields')); - Tools::logm('login failed'); - Tools::redirect(); } } @@ -814,4 +833,4 @@ class Poche } return $version; } -} \ No newline at end of file +} -- cgit v1.2.3 From 027b4e156853b4d5e358e19e83506ec4446de7ab Mon Sep 17 00:00:00 2001 From: Denis Sacchet Date: Sun, 20 Oct 2013 23:28:45 +0200 Subject: Adding support for http_auth --- inc/poche/Database.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 5c40b026..1d3ff0c2 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -87,6 +87,17 @@ class Database { return $user_config; } + public function userExists($username) { + $sql = "SELECT * FROM users WHERE username=?"; + $query = $this->executeQuery($sql, array($username)); + $login = $query->fetchAll(); + if (isset($login[0])) { + return true; + } else { + return false; + } + } + public function login($username, $password) { $sql = "SELECT * FROM users WHERE username=? AND password=?"; $query = $this->executeQuery($sql, array($username, $password)); -- cgit v1.2.3 From 985ce3ec53a71174b30b1872813cb69cab8d7081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 25 Oct 2013 14:25:37 +0200 Subject: bug fix #259: Deleting article doesn't redirect --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 0766cd51..39d43761 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -374,7 +374,7 @@ class Poche $msg = 'error : can\'t delete link #' . $id; } Tools::logm($msg); - Tools::redirect(); + Tools::redirect('?'); break; case 'toggle_fav' : $this->store->favoriteById($id, $this->user->getId()); -- cgit v1.2.3 From 363bc4eb8642d464cc0c099f7ab72a425b56b463 Mon Sep 17 00:00:00 2001 From: banux Date: Sun, 27 Oct 2013 07:37:05 +0100 Subject: Add a autoclose parameters. When we use sharing method in plugins like the tiny tiny rss one or the firefox plugins we can passe the autoclose=true parameters that close the popup. --- inc/poche/Poche.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 39d43761..5d807268 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -327,7 +327,7 @@ class Poche /** * Call action (mark as fav, archive, delete, etc.) */ - public function action($action, Url $url, $id = 0, $import = FALSE) + public function action($action, Url $url, $id = 0, $import = FALSE, $autoclose = FALSE) { switch ($action) { @@ -358,7 +358,11 @@ class Poche } if (!$import) { - Tools::redirect('?view=home'); + if ($autoclose == TRUE) { + Tools::redirect('?view=home'); + } else { + Tools::redirect('?view=home&autoclose=true'); + } } break; case 'delete': -- cgit v1.2.3 From f616ab60efc502b919b9b72f81aee2975b2e8465 Mon Sep 17 00:00:00 2001 From: banux Date: Sun, 27 Oct 2013 07:47:14 +0100 Subject: use 2 seprate variable for autoclosing windows to avoid to quick closing when sharing, the popup can be close before the link is save --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5d807268..3ecaf084 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -361,7 +361,7 @@ class Poche if ($autoclose == TRUE) { Tools::redirect('?view=home'); } else { - Tools::redirect('?view=home&autoclose=true'); + Tools::redirect('?view=home&closewin=true'); } } break; -- cgit v1.2.3 From 45e9e0f5653993d5f463209691953e7a41527267 Mon Sep 17 00:00:00 2001 From: Dmitry Sandalov Date: Tue, 5 Nov 2013 12:13:55 +0300 Subject: fix #270 access from remote machine Replacing SERVER_NAME with HTTP_HOST allows me to use Poche on remote machines --- inc/poche/Tools.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 1d092823..030d75ba 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -53,12 +53,12 @@ class Tools $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); - if (!isset($_SERVER["SERVER_NAME"])) { + if (!isset($_SERVER["HTTP_HOST"])) { return $scriptname; } return 'http' . ($https ? 's' : '') . '://' - . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; + . $_SERVER["HTTP_HOST"] . $serverport . $scriptname; } public static function redirect($url = '') -- cgit v1.2.3 From f2d3ee98a6a3137f8c3edd62294d34a8ff4700b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 13 Nov 2013 15:17:34 +0100 Subject: [fix] bug fix #287: test if open_basedir & safe_mode are active to use CURLOPT_FOLLOWLOCATION --- inc/poche/Tools.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 1d092823..7a872e7d 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -133,7 +133,9 @@ class Tools $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + if (!ini_get('open_basedir') && !ini_get('safe_mode')) { + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + } curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); -- cgit v1.2.3 From 0c2f453750b742fde21ec2a8fdcf3beb9eff2faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 20 Nov 2013 10:22:21 +0100 Subject: Fix Undefined offset Notice (thx @vjousse) --- inc/poche/Database.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 1d3ff0c2..bf67de2a 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -166,7 +166,7 @@ class Database { $query = $this->executeQuery($sql, $params); $entry = $query->fetchAll(); - return $entry[0]; + return isset($entry[0]) ? $entry[0] : null; } public function getEntriesByView($view, $user_id, $limit = '') { -- cgit v1.2.3 From 5846b0f1b32f7f9b99a3c20acfeeaee9781eebea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 3 Dec 2013 10:39:45 +0100 Subject: [change] getConfigUser is now a public function --- inc/poche/Database.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') 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 { return TRUE; } - private function getConfigUser($id) { + public function getConfigUser($id) { $sql = "SELECT * FROM users_config WHERE user_id = ?"; $query = $this->executeQuery($sql, array($id)); $result = $query->fetchAll(); -- cgit v1.2.3 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') 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 From 59cc585271a5f253b15617d97e26a29403a929dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 5 Dec 2013 15:13:32 +0100 Subject: [add] add RSS feed for archive --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index ac66dfc9..a8a54ff0 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -858,7 +858,7 @@ class Poche public function generateFeeds($token, $user_id, $type = 'home') { - $allowed_types = array('home', 'fav'); + $allowed_types = array('home', 'fav', 'archive'); $config = $this->store->getConfigUser($user_id); if (!in_array($type, $allowed_types) || -- cgit v1.2.3 From 42c80841c846610be280218d53fcde06b0f0063b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 09:45:27 +0100 Subject: [change] we now use Full-Text RSS 3.1, thank you so much @fivefilters --- inc/poche/Poche.class.php | 9 +- inc/poche/PocheReadability.php | 46 ------ inc/poche/Url.class.php | 364 ----------------------------------------- inc/poche/global.inc.php | 16 +- 4 files changed, 8 insertions(+), 427 deletions(-) delete mode 100644 inc/poche/PocheReadability.php (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a8a54ff0..5862befb 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -332,9 +332,12 @@ class Poche switch ($action) { case 'add': - $content = $url->extract(); + $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed'); + $content = json_decode($json, true); + $title = $content['rss']['channel']['item']['title']; + $body = $content['rss']['channel']['item']['description']; - if ($this->store->add($url->getUrl(), $content['title'], $content['body'], $this->user->getId())) { + if ($this->store->add($url->getUrl(), $title, $body, $this->user->getId())) { Tools::logm('add link ' . $url->getUrl()); $sequence = ''; if (STORAGE == 'postgres') { @@ -342,7 +345,7 @@ class Poche } $last_id = $this->store->getLastId($sequence); if (DOWNLOAD_PICTURES) { - $content = filtre_picture($content['body'], $url->getUrl(), $last_id); + $content = filtre_picture($body, $url->getUrl(), $last_id); Tools::logm('updating content article'); $this->store->updateContent($last_id, $content, $this->user->getId()); } diff --git a/inc/poche/PocheReadability.php b/inc/poche/PocheReadability.php deleted file mode 100644 index 48ae90d0..00000000 --- a/inc/poche/PocheReadability.php +++ /dev/null @@ -1,46 +0,0 @@ -getInnerText($this->dom->getElementsByTagName('title')->item(0)); - } catch(Exception $e) {} - - if (preg_match('/ [\|\-] /', $curTitle)) - { - $curTitle = preg_replace('/(.*)[\|\-] .*/i', '$1', $origTitle); - - if (count(explode(' ', $curTitle)) < 3) { - $curTitle = preg_replace('/[^\|\-]*[\|\-](.*)/i', '$1', $origTitle); - } - } - else if(strlen($curTitle) > 150 || strlen($curTitle) < 15) - { - $hOnes = $this->dom->getElementsByTagName('h1'); - if($hOnes->length == 1) - { - $curTitle = $this->getInnerText($hOnes->item(0)); - } - } - - $curTitle = trim($curTitle); - - if (count(explode(' ', $curTitle)) <= 4) { - $curTitle = $origTitle; - } - - $articleTitle = $this->dom->createElement('h1'); - $articleTitle->innerHTML = $curTitle; - - return $articleTitle; - } -} \ No newline at end of file diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index 600a2166..8b3468c3 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -12,45 +12,6 @@ class Url { public $url; - private $fingerprints = array( - // Posterous - ' array('hostname'=>'fingerprint.posterous.com', 'head'=>true), - // Blogger - ' array('hostname'=>'fingerprint.blogspot.com', 'head'=>true), - ' array('hostname'=>'fingerprint.blogspot.com', 'head'=>true), - // WordPress (self-hosted and hosted) - '\"$_name\""; - } else { - $html = "Download $_name"; - } - $title = $_name; - $do_content_extraction = false; - break; - } - } - } - unset($_mime, $_act, $_name, $match); - } - if ($do_content_extraction) { - $html = $response['body']; - // remove strange things - $html = str_replace('', '', $html); - $html = $this->convert_to_utf8($html, $response['headers']); - - // check site config for single page URL - fetch it if found - if ($single_page_response = $this->getSinglePage($item, $html, $effective_url)) { - $html = $single_page_response['body']; - // remove strange things - $html = str_replace('', '', $html); - $html = $this->convert_to_utf8($html, $single_page_response['headers']); - $effective_url = $single_page_response['effective_url']; - unset($single_page_response); - } - $extract_result = $extractor->process($html, $effective_url); - $readability = $extractor->readability; - $content_block = ($extract_result) ? $extractor->getContent() : null; - } - } - if ($do_content_extraction) { - // if we failed to extract content... - if (!$extract_result) { - $html = $this->error_message; - // keep the original item description - $html .= $item->get_description(); - } else { - $readability->clean($content_block, 'select'); - if ($this->rewrite_relative_urls) $this->makeAbsolute($effective_url, $content_block); - if ($content_block->childNodes->length == 1 && $content_block->firstChild->nodeType === XML_ELEMENT_NODE) { - $html = $content_block->firstChild->innerHTML; - } else { - $html = $content_block->innerHTML; - } - // post-processing cleanup - $html = preg_replace('!

[\s\h\v]*

!u', '', $html); - } - } - } - - $title = ($extractor->getTitle() != '' ? $extractor->getTitle() : _('Untitled')); - $content = array ('title' => $title, 'body' => $html); - - return $content; - } - - private function convert_to_utf8($html, $header=null) - { - $encoding = null; - if ($html || $header) { - if (is_array($header)) $header = implode("\n", $header); - if (!$header || !preg_match_all('/^Content-Type:\s+([^;]+)(?:;\s*charset=["\']?([^;"\'\n]*))?/im', $header, $match, PREG_SET_ORDER)) { - // error parsing the response - } else { - $match = end($match); // get last matched element (in case of redirects) - if (isset($match[2])) $encoding = trim($match[2], "\"' \r\n\0\x0B\t"); - } - // TODO: check to see if encoding is supported (can we convert it?) - // If it's not, result will be empty string. - // For now we'll check for invalid encoding types returned by some sites, e.g. 'none' - // Problem URL: http://facta.co.jp/blog/archives/20111026001026.html - if (!$encoding || $encoding == 'none') { - // search for encoding in HTML - only look at the first 35000 characters - $html_head = substr($html, 0, 40000); - if (preg_match('/^<\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html_head, $match)) { - $encoding = trim($match[1], '"\''); - } elseif (preg_match('/]+)/i', $html_head, $match)) { - $encoding = trim($match[1]); - } elseif (preg_match_all('/]+)>/i', $html_head, $match)) { - foreach ($match[1] as $_test) { - if (preg_match('/charset=["\']?([^"\']+)/i', $_test, $_m)) { - $encoding = trim($_m[1]); - break; - } - } - } - } - if (isset($encoding)) $encoding = trim($encoding); - // trim is important here! - if (!$encoding || (strtolower($encoding) == 'iso-8859-1')) { - // replace MS Word smart qutoes - $trans = array(); - $trans[chr(130)] = '‚'; // Single Low-9 Quotation Mark - $trans[chr(131)] = 'ƒ'; // Latin Small Letter F With Hook - $trans[chr(132)] = '„'; // Double Low-9 Quotation Mark - $trans[chr(133)] = '…'; // Horizontal Ellipsis - $trans[chr(134)] = '†'; // Dagger - $trans[chr(135)] = '‡'; // Double Dagger - $trans[chr(136)] = 'ˆ'; // Modifier Letter Circumflex Accent - $trans[chr(137)] = '‰'; // Per Mille Sign - $trans[chr(138)] = 'Š'; // Latin Capital Letter S With Caron - $trans[chr(139)] = '‹'; // Single Left-Pointing Angle Quotation Mark - $trans[chr(140)] = 'Œ'; // Latin Capital Ligature OE - $trans[chr(145)] = '‘'; // Left Single Quotation Mark - $trans[chr(146)] = '’'; // Right Single Quotation Mark - $trans[chr(147)] = '“'; // Left Double Quotation Mark - $trans[chr(148)] = '”'; // Right Double Quotation Mark - $trans[chr(149)] = '•'; // Bullet - $trans[chr(150)] = '–'; // En Dash - $trans[chr(151)] = '—'; // Em Dash - $trans[chr(152)] = '˜'; // Small Tilde - $trans[chr(153)] = '™'; // Trade Mark Sign - $trans[chr(154)] = 'š'; // Latin Small Letter S With Caron - $trans[chr(155)] = '›'; // Single Right-Pointing Angle Quotation Mark - $trans[chr(156)] = 'œ'; // Latin Small Ligature OE - $trans[chr(159)] = 'Ÿ'; // Latin Capital Letter Y With Diaeresis - $html = strtr($html, $trans); - } - if (!$encoding) { - $encoding = 'utf-8'; - } else { - if (strtolower($encoding) != 'utf-8') { - $html = SimplePie_Misc::change_encoding($html, $encoding, 'utf-8'); - /* - if (function_exists('iconv')) { - // iconv appears to handle certain character encodings better than mb_convert_encoding - $html = iconv($encoding, 'utf-8', $html); - } else { - $html = mb_convert_encoding($html, 'utf-8', $encoding); - } - */ - } - } - } - return $html; - } - - private function makeAbsolute($base, $elem) { - $base = new SimplePie_IRI($base); - // remove '//' in URL path (used to prevent URLs from resolving properly) - // TODO: check if this is still the case - if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path); - foreach(array('a'=>'href', 'img'=>'src') as $tag => $attr) { - $elems = $elem->getElementsByTagName($tag); - for ($i = $elems->length-1; $i >= 0; $i--) { - $e = $elems->item($i); - //$e->parentNode->replaceChild($articleContent->ownerDocument->createTextNode($e->textContent), $e); - $this->makeAbsoluteAttr($base, $e, $attr); - } - if (strtolower($elem->tagName) == $tag) $this->makeAbsoluteAttr($base, $elem, $attr); - } - } - - private function makeAbsoluteAttr($base, $e, $attr) { - if ($e->hasAttribute($attr)) { - // Trim leading and trailing white space. I don't really like this but - // unfortunately it does appear on some sites. e.g. - $url = trim(str_replace('%20', ' ', $e->getAttribute($attr))); - $url = str_replace(' ', '%20', $url); - if (!preg_match('!https?://!i', $url)) { - if ($absolute = SimplePie_IRI::absolutize($base, $url)) { - $e->setAttribute($attr, $absolute); - } - } - } - } - - private function makeAbsoluteStr($base, $url) { - $base = new SimplePie_IRI($base); - // remove '//' in URL path (causes URLs not to resolve properly) - if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path); - if (preg_match('!^https?://!i', $url)) { - // already absolute - return $url; - } else { - if ($absolute = SimplePie_IRI::absolutize($base, $url)) { - return $absolute; - } - return false; - } - } - - // returns single page response, or false if not found - private function getSinglePage($item, $html, $url) { - global $http, $extractor; - $host = @parse_url($url, PHP_URL_HOST); - $site_config = SiteConfig::build($host); - if ($site_config === false) { - // check for fingerprints - if (!empty($extractor->fingerprints) && ($_fphost = $extractor->findHostUsingFingerprints($html))) { - $site_config = SiteConfig::build($_fphost); - } - if ($site_config === false) $site_config = new SiteConfig(); - SiteConfig::add_to_cache($host, $site_config); - return false; - } else { - SiteConfig::add_to_cache($host, $site_config); - } - $splink = null; - if (!empty($site_config->single_page_link)) { - $splink = $site_config->single_page_link; - } elseif (!empty($site_config->single_page_link_in_feed)) { - // single page link xpath is targeted at feed - $splink = $site_config->single_page_link_in_feed; - // so let's replace HTML with feed item description - $html = $item->get_description(); - } - if (isset($splink)) { - // Build DOM tree from HTML - $readability = new PocheReadability($html, $url); - $xpath = new DOMXPath($readability->dom); - // Loop through single_page_link xpath expressions - $single_page_url = null; - foreach ($splink as $pattern) { - $elems = @$xpath->evaluate($pattern, $readability->dom); - if (is_string($elems)) { - $single_page_url = trim($elems); - break; - } elseif ($elems instanceof DOMNodeList && $elems->length > 0) { - foreach ($elems as $item) { - if ($item instanceof DOMElement && $item->hasAttribute('href')) { - $single_page_url = $item->getAttribute('href'); - break; - } elseif ($item instanceof DOMAttr && $item->value) { - $single_page_url = $item->value; - break; - } - } - } - } - // If we've got URL, resolve against $url - if (isset($single_page_url) && ($single_page_url = $this->makeAbsoluteStr($url, $single_page_url))) { - // check it's not what we have already! - if ($single_page_url != $url) { - // it's not, so let's try to fetch it... - $_prev_ref = $http->referer; - $http->referer = $single_page_url; - if (($response = $http->get($single_page_url, true)) && $response['status_code'] < 300) { - $http->referer = $_prev_ref; - return $response; - } - $http->referer = $_prev_ref; - } - } - } - return false; - } } \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 65a026a7..846699d3 100644 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -20,25 +20,13 @@ require_once INCLUDES . '/poche/Url.class.php'; require_once INCLUDES . '/3rdparty/class.messages.php'; require_once INCLUDES . '/poche/Poche.class.php'; -require_once INCLUDES . '/3rdparty/Readability.php'; -require_once INCLUDES . '/poche/PocheReadability.php'; - -require_once INCLUDES . '/3rdparty/Encoding.php'; require_once INCLUDES . '/poche/Database.class.php'; require_once INCLUDES . '/3rdparty/simple_html_dom.php'; require_once INCLUDES . '/3rdparty/paginator.php'; require_once INCLUDES . '/3rdparty/Session.class.php'; -require_once INCLUDES . '/3rdparty/simplepie/SimplePieAutoloader.php'; -require_once INCLUDES . '/3rdparty/simplepie/SimplePie/Core.php'; -require_once INCLUDES . '/3rdparty/content-extractor/ContentExtractor.php'; -require_once INCLUDES . '/3rdparty/content-extractor/SiteConfig.php'; -require_once INCLUDES . '/3rdparty/humble-http-agent/HumbleHttpAgent.php'; -require_once INCLUDES . '/3rdparty/humble-http-agent/SimplePie_HumbleHttpAgent.php'; -require_once INCLUDES . '/3rdparty/humble-http-agent/CookieJar.php'; -require_once INCLUDES . '/3rdparty/feedwriter/FeedItem.php'; -require_once INCLUDES . '/3rdparty/feedwriter/FeedWriter.php'; -require_once INCLUDES . '/3rdparty/feedwriter/DummySingleItemFeed.php'; +require_once INCLUDES . '/3rdparty/libraries/feedwriter/FeedItem.php'; +require_once INCLUDES . '/3rdparty/libraries/feedwriter/FeedWriter.php'; require_once INCLUDES . '/3rdparty/FlattrItem.class.php'; # Composer its autoloader for automatically loading Twig -- cgit v1.2.3 From 9e7c840b186fb4ad2cd3768cec49ee348facf3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 10:14:59 +0100 Subject: [fix] RSS feeds were buggy when I update full-text RSS --- inc/poche/Poche.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5862befb..d45d0c40 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -870,10 +870,10 @@ class Poche } // Check the token - $feed = new FeedWriter(ATOM); + $feed = new FeedWriter(RSS2); $feed->setTitle('poche - ' . $type . ' feed'); $feed->setLink(Tools::getPocheUrl()); - $feed->setChannelElement('updated', date(DATE_ATOM , time())); + $feed->setChannelElement('updated', date(DATE_RSS , time())); $feed->setChannelElement('author', 'poche'); $entries = $this->store->getEntriesByView($type, $user_id); -- cgit v1.2.3 From 5bea1a4d310e468d6ea1b71de36bdb4a53b8c57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 13:02:15 +0100 Subject: [add] function to get tags by entry --- inc/poche/Database.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index c233eda1..86907e52 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -249,4 +249,15 @@ class Database { public function getLastId($column = '') { return $this->getHandle()->lastInsertId($column); } + + public function retrieveTagsByEntry($entry_id) { + $sql = + "SELECT * FROM tags + LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id + WHERE tags_entries.entry_id = ?"; + $query = $this->executeQuery($sql, array($entry_id)); + $tags = $query->fetchAll(); + + return $tags; + } } -- cgit v1.2.3 From 7b171c73400ff2c0b8f3634e35d186b22176759b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 13:02:38 +0100 Subject: [add] send tags to article view --- inc/poche/Poche.class.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index d45d0c40..c9fb6382 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -443,12 +443,16 @@ class Poche # flattr checking $flattr = new FlattrItem(); - $flattr->checkItem($entry['url'],$entry['id']); + $flattr->checkItem($entry['url'], $entry['id']); + + # tags + $tags = $this->store->retrieveTagsByEntry($entry['id']); $tpl_vars = array( - 'entry' => $entry, - 'content' => $content, - 'flattr' => $flattr + 'entry' => $entry, + 'content' => $content, + 'flattr' => $flattr, + 'tags' => $tags ); } else { -- cgit v1.2.3 From 2e2ebe5ec767dcbee90394d12b03298592c87805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 13:15:06 +0100 Subject: [add] create tags page --- inc/poche/Database.class.php | 14 +++++++++++--- inc/poche/Poche.class.php | 6 ++++++ inc/poche/Tools.class.php | 5 +++-- 3 files changed, 20 insertions(+), 5 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 86907e52..8e9ee0b7 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -250,13 +250,21 @@ class Database { return $this->getHandle()->lastInsertId($column); } + public function retrieveAllTags() { + $sql = "SELECT * FROM tags"; + $query = $this->executeQuery($sql, array()); + $tags = $query->fetchAll(); + + return $tags; + } + public function retrieveTagsByEntry($entry_id) { - $sql = + $sql = "SELECT * FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags_entries.entry_id = ?"; - $query = $this->executeQuery($sql, array($entry_id)); - $tags = $query->fetchAll(); + $query = $this->executeQuery($sql, array($entry_id)); + $tags = $query->fetchAll(); return $tags; } diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index c9fb6382..802ec542 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -430,6 +430,12 @@ class Poche ); Tools::logm('config view'); break; + case 'tags': + $tags = $this->store->retrieveAllTags(); + $tpl_vars = array( + 'tags' => $tags, + ); + break; case 'view': $entry = $this->store->retrieveOneById($id, $this->user->getId()); if ($entry != NULL) { diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 750553f1..5bb65fe9 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -103,14 +103,15 @@ class Tools case 'config': $tpl_file = 'config.twig'; break; + case 'tags': + $tpl_file = 'tags.twig'; + break; case 'view': $tpl_file = 'view.twig'; break; - case 'login': $tpl_file = 'login.twig'; break; - case 'error': $tpl_file = 'error.twig'; break; -- cgit v1.2.3 From 6cab59c3409f4edc9b309b76295cb4061bff3fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 14:03:14 +0100 Subject: [add] edit tags page --- inc/poche/Poche.class.php | 7 +++++++ inc/poche/Tools.class.php | 3 +++ 2 files changed, 10 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 802ec542..5d368842 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -430,6 +430,13 @@ class Poche ); Tools::logm('config view'); break; + case 'edit-tags': + # tags + $tags = $this->store->retrieveTagsByEntry($id); + $tpl_vars = array( + 'tags' => $tags, + ); + break; case 'tags': $tags = $this->store->retrieveAllTags(); $tpl_vars = array( diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 5bb65fe9..9d911699 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -106,6 +106,9 @@ class Tools case 'tags': $tpl_file = 'tags.twig'; break; + case 'edit-tags': + $tpl_file = 'edit-tags.twig'; + break; case 'view': $tpl_file = 'view.twig'; break; -- cgit v1.2.3 From 74ec445a662aa31f713bc50e74c9366da336538a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 14:07:00 +0100 Subject: [change] simplify Tools::getTplFile --- inc/poche/Tools.class.php | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 9d911699..b0ef55f5 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -88,43 +88,16 @@ class Tools public static function getTplFile($view) { - $default_tpl = 'home.twig'; - - switch ($view) { - case 'install': - $tpl_file = 'install.twig'; - break; - case 'import'; - $tpl_file = 'import.twig'; - break; - case 'export': - $tpl_file = 'export.twig'; - break; - case 'config': - $tpl_file = 'config.twig'; - break; - case 'tags': - $tpl_file = 'tags.twig'; - break; - case 'edit-tags': - $tpl_file = 'edit-tags.twig'; - break; - case 'view': - $tpl_file = 'view.twig'; - break; - case 'login': - $tpl_file = 'login.twig'; - break; - case 'error': - $tpl_file = 'error.twig'; - break; - - default: - $tpl_file = $default_tpl; - break; + $views = array( + 'install', 'import', 'export', 'config', 'tags', + 'edit-tags', 'view', 'login', 'error' + ); + + if (in_array($view, $views)) { + return $view . '.twig'; } - - return $tpl_file; + + return 'home.twig'; } public static function getFile($url) -- cgit v1.2.3 From 4886ed6d3637df0b3e16e672d58d4ef8f17dc432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 14:22:29 +0100 Subject: [add] page which lists entries for a tag --- inc/poche/Database.class.php | 21 +++++++++++++++++++++ inc/poche/Poche.class.php | 8 ++++++++ inc/poche/Tools.class.php | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 8e9ee0b7..a89bce41 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -258,6 +258,27 @@ class Database { return $tags; } + public function retrieveTag($id) { + $tag = NULL; + $sql = "SELECT * FROM tags WHERE id=?"; + $params = array(intval($id)); + $query = $this->executeQuery($sql, $params); + $tag = $query->fetchAll(); + + return isset($tag[0]) ? $tag[0] : null; + } + + public function retrieveEntriesByTag($tag_id) { + $sql = + "SELECT * FROM entries + LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id + WHERE tags_entries.tag_id = ?"; + $query = $this->executeQuery($sql, array($tag_id)); + $entries = $query->fetchAll(); + + return $entries; + } + public function retrieveTagsByEntry($entry_id) { $sql = "SELECT * FROM tags diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5d368842..fefbb02d 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -437,6 +437,14 @@ class Poche 'tags' => $tags, ); break; + case 'tag': + $entries = $this->store->retrieveEntriesByTag($id); + $tag = $this->store->retrieveTag($id); + $tpl_vars = array( + 'tag' => $tag, + 'entries' => $entries, + ); + break; case 'tags': $tags = $this->store->retrieveAllTags(); $tpl_vars = array( diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index b0ef55f5..6da53023 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -90,7 +90,7 @@ class Tools { $views = array( 'install', 'import', 'export', 'config', 'tags', - 'edit-tags', 'view', 'login', 'error' + 'edit-tags', 'view', 'login', 'error', 'tag' ); if (in_array($view, $views)) { -- cgit v1.2.3 From f778e47283c9691d2992045e0fbcdfc6685f157f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 14:37:42 +0100 Subject: [add] rss for tag --- inc/poche/Poche.class.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index fefbb02d..68f56d62 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -446,8 +446,11 @@ class Poche ); break; case 'tags': + $token = $this->user->getConfigValue('token'); $tags = $this->store->retrieveAllTags(); $tpl_vars = array( + 'token' => $token, + 'user_id' => $this->user->getId(), 'tags' => $tags, ); break; @@ -884,9 +887,9 @@ class Poche $_SESSION['poche_user']->setConfig($currentConfig); } - public function generateFeeds($token, $user_id, $type = 'home') + public function generateFeeds($token, $user_id, $tag_id, $type = 'home') { - $allowed_types = array('home', 'fav', 'archive'); + $allowed_types = array('home', 'fav', 'archive', 'tag'); $config = $this->store->getConfigUser($user_id); if (!in_array($type, $allowed_types) || @@ -901,7 +904,13 @@ class Poche $feed->setChannelElement('updated', date(DATE_RSS , time())); $feed->setChannelElement('author', 'poche'); - $entries = $this->store->getEntriesByView($type, $user_id); + if ($type == 'tag') { + $entries = $this->store->retrieveEntriesByTag($tag_id); + } + else { + $entries = $this->store->getEntriesByView($type, $user_id); + } + if (count($entries) > 0) { foreach ($entries as $entry) { $newItem = $feed->createNewItem(); -- cgit v1.2.3 From c432fa1674fbe2b190cf0d0bab2e90302a61e98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 15:07:51 +0100 Subject: [add] assign and remove a tag to an entry --- inc/poche/Database.class.php | 31 +++++++++++++++++++++++++++++++ inc/poche/Poche.class.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index a89bce41..d95b9b81 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -289,4 +289,35 @@ class Database { return $tags; } + + public function removeTagForEntry($entry_id, $tag_id) { + $sql_action = "DELETE FROM tags_entries WHERE tag_id=? AND entry_id=?"; + $params_action = array($tag_id, $entry_id); + $query = $this->executeQuery($sql_action, $params_action); + return $query; + } + + public function retrieveTagByValue($value) { + $tag = NULL; + $sql = "SELECT * FROM tags WHERE value=?"; + $params = array($value); + $query = $this->executeQuery($sql, $params); + $tag = $query->fetchAll(); + + return isset($tag[0]) ? $tag[0] : null; + } + + public function createTag($value) { + $sql_action = 'INSERT INTO tags ( value ) VALUES (?)'; + $params_action = array($value); + $query = $this->executeQuery($sql_action, $params_action); + return $query; + } + + public function setTagToEntry($tag_id, $entry_id) { + $sql_action = 'INSERT INTO tags_entries ( tag_id, entry_id ) VALUES (?, ?)'; + $params_action = array($tag_id, $entry_id); + $query = $this->executeQuery($sql_action, $params_action); + return $query; + } } diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 68f56d62..d415dd03 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -397,6 +397,36 @@ class Poche Tools::redirect(); } break; + case 'add_tag' : + $tags = explode(',', $_POST['value']); + $entry_id = $_POST['entry_id']; + foreach($tags as $key => $tag_value) { + $value = trim($tag_value); + $tag = $this->store->retrieveTagByValue($value); + + if (is_null($tag)) { + # we create the tag + $tag = $this->store->createTag($value); + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'tags_id_seq'; + } + $tag_id = $this->store->getLastId($sequence); + } + else { + $tag_id = $tag['id']; + } + + # we assign the tag to the article + $this->store->setTagToEntry($tag_id, $entry_id); + } + Tools::redirect(); + break; + case 'remove_tag' : + $tag_id = $_GET['tag_id']; + $this->store->removeTagForEntry($id, $tag_id); + Tools::redirect(); + break; default: break; } @@ -434,6 +464,7 @@ class Poche # tags $tags = $this->store->retrieveTagsByEntry($id); $tpl_vars = array( + 'entry_id' => $id, 'tags' => $tags, ); break; -- cgit v1.2.3 From d460914f65254d201911a8346792d680218c8dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 12 Dec 2013 09:42:19 +0100 Subject: [add] download database if sqlite is on --- inc/poche/Tools.class.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 750553f1..9d8e1fd6 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -249,4 +249,28 @@ class Tools $lang = explode('.', $userlanguage); return str_replace('_', '-', $lang[0]); } + + public static function status($status_code) + { + if (strpos(php_sapi_name(), 'apache') !== false) { + + header('HTTP/1.0 '.$status_code); + } + else { + + header('Status: '.$status_code); + } + } + + + public static function download_db() { + header('Content-Disposition: attachment; filename="poche.sqlite.gz"'); + self::status(200); + + header('Content-Transfer-Encoding: binary'); + header('Content-Type: application/octet-stream'); + echo gzencode(file_get_contents(STORAGE_SQLITE)); + + exit; + } } -- cgit v1.2.3 From a0aa150418b628b32b18c70436d6be495129ee38 Mon Sep 17 00:00:00 2001 From: Dmitry Sandalov Date: Sat, 21 Dec 2013 23:39:45 +0400 Subject: fix for long lasting session --- inc/poche/Poche.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index d415dd03..adec9b28 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -678,7 +678,8 @@ class Poche $user = $this->store->login($login, Tools::encodeString($password . $login)); if ($user != array()) { # Save login into Session - Session::login($user['username'], $user['password'], $login, Tools::encodeString($password . $login), array('poche_user' => new User($user))); + $longlastingsession = isset($_POST['longlastingsession']); + Session::login($user['username'], $user['password'], $login, Tools::encodeString($password . $login), $longlastingsession, array('poche_user' => new User($user))); $this->messages->add('s', _('welcome to your poche')); Tools::logm('login successful'); Tools::redirect($referer); -- cgit v1.2.3 From 1810c13b55b01043620fd81a65ce6e84cccc429c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 23 Dec 2013 09:09:10 +0100 Subject: PHP_AUTH_USER isn't available when using php as cgi --- inc/poche/Poche.class.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index adec9b28..4b26574d 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -446,7 +446,7 @@ class Poche $themes = $this->getInstalledThemes(); $languages = $this->getInstalledLanguages(); $token = $this->user->getConfigValue('token'); - $http_auth = (isset($_SERVER['PHP_AUTH_USER']))?true:false; + $http_auth = (isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['REMOTE_USER'])) ? true : false; $tpl_vars = array( 'themes' => $themes, 'languages' => $languages, @@ -649,14 +649,18 @@ class Poche * it redirects the user to the $referer link * @return array */ - private function credentials() { - if(isset($_SERVER['PHP_AUTH_USER'])) { - return array($_SERVER['PHP_AUTH_USER'],'php_auth'); - } - if(!empty($_POST['login']) && !empty($_POST['password'])) { - return array($_POST['login'],$_POST['password']); - } - return array(false,false); + private function credentials() { + if(isset($_SERVER['PHP_AUTH_USER'])) { + return array($_SERVER['PHP_AUTH_USER'],'php_auth'); + } + if(!empty($_POST['login']) && !empty($_POST['password'])) { + return array($_POST['login'],$_POST['password']); + } + if(isset($_SERVER['REMOTE_USER'])) { + return array($_SERVER['REMOTE_USER'],'http_auth'); + } + + return array(false,false); } /** -- cgit v1.2.3 From 5cfafc6110985236d9f212533faee79e460bf20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 23 Dec 2013 10:35:09 +0100 Subject: [add] check tags tables --- inc/poche/Database.class.php | 71 ++++++++++++++++++++++++++++++++++++++++++-- inc/poche/Poche.class.php | 3 +- 2 files changed, 71 insertions(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index d95b9b81..d7e9fc11 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -39,12 +39,79 @@ class Database { public function isInstalled() { $sql = "SELECT username FROM users"; $query = $this->executeQuery($sql, array()); + if ($query == false) { + die(STORAGE . ' database looks empty. You have to create it (you can find database structure in install folder).'); + } $hasAdmin = count($query->fetchAll()); if ($hasAdmin == 0) - return FALSE; + return false; - return TRUE; + return true; + } + + public function checkTags() { + + if (STORAGE == 'sqlite') { + $sql = ' + CREATE TABLE IF NOT EXISTS tags ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, + value TEXT + )'; + } + elseif(STORAGE == 'mysql') { + $sql = ' + CREATE TABLE IF NOT EXISTS `tags` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `value` varchar(255) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + '; + } + else { + $sql = ' + CREATE TABLE tags ( + id bigserial primary key, + value varchar(255) NOT NULL + ); + '; + } + + $query = $this->executeQuery($sql, array()); + + if (STORAGE == 'sqlite') { + $sql = ' + CREATE TABLE tags_entries ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, + entry_id INTEGER, + tag_id INTEGER, + FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE, + FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE + )'; + } + elseif(STORAGE == 'mysql') { + $sql = ' + CREATE TABLE IF NOT EXISTS `tags_entries` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `entry_id` int(11) NOT NULL, + `tag_id` int(11) NOT NULL, + FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE, + FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + '; + } + else { + $sql = ' + CREATE TABLE tags_entries ( + id bigserial primary key, + entry_id integer NOT NULL, + tag_id integer NOT NULL + ) + '; + } + + $query = $this->executeQuery($sql, array()); } public function install($login, $password) { diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4b26574d..4f70afb7 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -49,6 +49,7 @@ class Poche if (! $this->store->isInstalled()) { $this->install(); } + $this->store->checkTags(); } } @@ -659,7 +660,7 @@ class Poche if(isset($_SERVER['REMOTE_USER'])) { return array($_SERVER['REMOTE_USER'],'http_auth'); } - + return array(false,false); } -- cgit v1.2.3 From da5fc42f615eeb45a702604970f94967507fb432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 23 Dec 2013 11:23:12 +0100 Subject: [fix] bug with queries when postgresql is used --- inc/poche/Database.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index d7e9fc11..afe02a41 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -194,10 +194,10 @@ class Database { $config = $this->getConfigUser($userId); if (!isset ($user_config[$key])) { - $sql = "INSERT INTO users_config (`value`, `user_id`, `name`) VALUES (?, ?, ?)"; + $sql = "INSERT INTO users_config (value, user_id, name) VALUES (?, ?, ?)"; } else { - $sql = "UPDATE users_config SET `value`=? WHERE `user_id`=? AND `name`=?"; + $sql = "UPDATE users_config SET value=? WHERE user_id=? AND name=?"; } $params = array($value, $userId, $key); -- cgit v1.2.3 From 9de34d4e8430b8b2d994aa9b681ec9f11dabf0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 3 Jan 2014 10:06:26 +0100 Subject: [fix] error in query to get entries and tags --- inc/poche/Database.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index afe02a41..d8b63859 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -337,7 +337,7 @@ class Database { public function retrieveEntriesByTag($tag_id) { $sql = - "SELECT * FROM entries + "SELECT entries.* FROM entries LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id WHERE tags_entries.tag_id = ?"; $query = $this->executeQuery($sql, array($tag_id)); @@ -348,7 +348,7 @@ class Database { public function retrieveTagsByEntry($entry_id) { $sql = - "SELECT * FROM tags + "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags_entries.entry_id = ?"; $query = $this->executeQuery($sql, array($entry_id)); -- cgit v1.2.3 From 0b57c6825aa0bf88d10a2c420875f6cf9afe17c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 3 Jan 2014 10:15:05 +0100 Subject: [fix] bugs #374 and #376 - encoding in rss --- inc/poche/Poche.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4f70afb7..d3eb71d2 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -951,7 +951,7 @@ class Poche if (count($entries) > 0) { foreach ($entries as $entry) { $newItem = $feed->createNewItem(); - $newItem->setTitle(htmlentities($entry['title'])); + $newItem->setTitle($entry['title']); $newItem->setLink(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); $newItem->setDate(time()); $newItem->setDescription($entry['content']); -- cgit v1.2.3 From b5c1ed12273d72888b443e801123252d92f8c8ec Mon Sep 17 00:00:00 2001 From: FireFox Date: Fri, 3 Jan 2014 11:17:15 +0100 Subject: Change Permissions in pochePictures.php Stored Pictures are not accessible (on my server), when permission is set to 0705, but instead, when using 0755 (or for example to 0715) all is working as expected. So maybe it would be good, considering in changing the permission of created directories in the assets directory --- inc/poche/pochePictures.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/pochePictures.php b/inc/poche/pochePictures.php index 4e4a0b08..b0cfb9df 100644 --- a/inc/poche/pochePictures.php +++ b/inc/poche/pochePictures.php @@ -84,12 +84,12 @@ function create_assets_directory($id) { $assets_path = ABS_PATH; if(!is_dir($assets_path)) { - mkdir($assets_path, 0705); + mkdir($assets_path, 0715); } $article_directory = $assets_path . $id; if(!is_dir($article_directory)) { - mkdir($article_directory, 0705); + mkdir($article_directory, 0715); } return $article_directory; @@ -107,4 +107,4 @@ function remove_directory($directory) } return rmdir($directory); } -} \ No newline at end of file +} -- cgit v1.2.3 From 9bc32632af80130ca6aff968b800ceb43aa86576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 3 Jan 2014 15:18:13 +0100 Subject: [fix] #375 Readability.com changed its export format --- inc/poche/Poche.class.php | 53 +++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index d3eb71d2..e9ff7b46 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -806,34 +806,37 @@ class Poche $url = NULL; $favorite = FALSE; $archive = FALSE; - foreach ($value as $attr => $attr_value) { - if ($attr == 'article__url') { - $url = new Url(base64_encode($attr_value)); - } - $sequence = ''; - if (STORAGE == 'postgres') { - $sequence = 'entries_id_seq'; - } - if ($attr_value == 'true') { - if ($attr == 'favorite') { - $favorite = TRUE; + foreach ($value as $item) { + foreach ($item as $attr => $value) { + if ($attr == 'article__url') { + $url = new Url(base64_encode($value)); } - if ($attr == 'archive') { - $archive = TRUE; + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'entries_id_seq'; + } + if ($value == 'true') { + if ($attr == 'favorite') { + $favorite = TRUE; + } + if ($attr == 'archive') { + $archive = TRUE; + } } } - } - # we can add the url - if (!is_null($url) && $url->isCorrect()) { - $this->action('add', $url, 0, TRUE); - $count++; - if ($favorite) { - $last_id = $this->store->getLastId($sequence); - $this->action('toggle_fav', $url, $last_id, TRUE); - } - if ($archive) { - $last_id = $this->store->getLastId($sequence); - $this->action('toggle_archive', $url, $last_id, TRUE); + + # we can add the url + if (!is_null($url) && $url->isCorrect()) { + $this->action('add', $url, 0, TRUE); + $count++; + if ($favorite) { + $last_id = $this->store->getLastId($sequence); + $this->action('toggle_fav', $url, $last_id, TRUE); + } + if ($archive) { + $last_id = $this->store->getLastId($sequence); + $this->action('toggle_archive', $url, $last_id, TRUE); + } } } } -- cgit v1.2.3