diff --git a/.gitignore b/.gitignore index 2abed7e..aec2e3e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ cache/* vendor composer.phar db/poche.sqlite -inc/poche/config.inc.php \ No newline at end of file +inc/poche/config.inc.php +inc/3rdparty/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer/ \ No newline at end of file diff --git a/TRANSLATION.md b/TRANSLATION.md index 2ea9279..2e38d5c 100755 --- a/TRANSLATION.md +++ b/TRANSLATION.md @@ -62,6 +62,6 @@ So, you are almost done. This step may be required if your web server runs php scripts in name of, say, www user (i.e. Apache with mod_php, not cgi). -##To create new tanslation +##To create new translation Please simple create appropriate directories in locale folder and perform all steps, described above. Instead of opening an existing file just create new one. diff --git a/check_setup.php b/check_setup.php index 96dd0f7..2b84a74 100644 --- a/check_setup.php +++ b/check_setup.php @@ -13,16 +13,6 @@ if (version_compare(PHP_VERSION, '5.4.0', '<')) { } } -// Check PDO Sqlite -if (! extension_loaded('pdo_sqlite')) { - die('PHP extension required: pdo_sqlite'); -} - -// Check ZIP -if (! extension_loaded('zip')) { - die('PHP extension required: zip'); -} - // Check if /cache is writeable if (! is_writable('cache')) { die('The directory "cache" must be writeable by your web server user'); diff --git a/cron.php b/cron.php new file mode 100644 index 0000000..8fbf421 --- /dev/null +++ b/cron.php @@ -0,0 +1,53 @@ +getConfigUser($user_id); + +if ($token != $config['token']) { + die(_('Uh, there is a problem with the cron.')); +} + +$items = $store->retrieveUnfetchedEntries($user_id, $limit); + +foreach ($items as $item) { + $url = new Url(base64_encode($item['url'])); + $content = Tools::getPageContent($url); + + $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); + $body = $content['rss']['channel']['item']['description']; + + // // clean content from prevent xss attack + $config = HTMLPurifier_Config::createDefault(); + $purifier = new HTMLPurifier($config); + $title = $purifier->purify($title); + $body = $purifier->purify($body); + + + $store->updateContentAndTitle($item['id'], $title, $body, $user_id); +} \ No newline at end of file diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index b30a31f..599b68c 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php @@ -33,7 +33,7 @@ class Session // his/her session is considered expired (3600 sec. = 1 hour) public static $inactivityTimeout = 86400; // Extra timeout for long sessions (if enabled) (82800 sec. = 23 hours) - public static $longSessionTimeout = 31536000; + public static $longSessionTimeout = 604800; // 604800 = a week // If you get disconnected often or if your IP address changes often. // Let you disable session cookie hijacking protection public static $disableSessionProtection = false; @@ -61,7 +61,7 @@ class Session if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { $ssl = true; } - session_set_cookie_params($cookie['lifetime'], $cookiedir, $_SERVER['HTTP_HOST'], $ssl); + session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl); // Use cookies to store session. ini_set('session.use_cookies', 1); // Force cookies for session (phpsessionID forbidden in URL) @@ -143,7 +143,14 @@ class Session */ public static function logout() { - unset($_SESSION['uid'],$_SESSION['ip'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['longlastingsession'], $_SESSION['poche_user']); + // unset($_SESSION['uid'],$_SESSION['ip'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['longlastingsession'], $_SESSION['poche_user']); + + // Destruction du cookie (le code peut paraître complexe mais c'est pour être certain de reprendre les mêmes paramètres) + $args = array_merge(array(session_name(), ''), array_values(session_get_cookie_params())); + $args[2] = time() - 3600; + call_user_func_array('setcookie', $args); + // Suppression physique de la session + session_destroy(); } /** diff --git a/inc/3rdparty/libraries/feedwriter/FeedItem.php b/inc/3rdparty/libraries/feedwriter/FeedItem.php index 9373dee..0eae5e0 100644 --- a/inc/3rdparty/libraries/feedwriter/FeedItem.php +++ b/inc/3rdparty/libraries/feedwriter/FeedItem.php @@ -156,6 +156,7 @@ if($this->version == RSS2 || $this->version == RSS1) { $this->setElement('link', $link); + $this->setElement('guid', $link); } else { diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index c998fe1..5b51b50 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -230,8 +230,30 @@ class Database { } } + public function updateContentAndTitle($id, $title, $body, $user_id) { + $sql_action = 'UPDATE entries SET content = ?, title = ? WHERE id=? AND user_id=?'; + $params_action = array($body, $title, $id, $user_id); + $query = $this->executeQuery($sql_action, $params_action); + + return $query; + } + + public function retrieveUnfetchedEntries($user_id, $limit) { + + $sql_limit = "LIMIT 0,".$limit; + if (STORAGE == 'postgres') { + $sql_limit = "LIMIT ".$limit." OFFSET 0"; + } + + $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND user_id=? ORDER BY id " . $sql_limit; + $query = $this->executeQuery($sql, array($user_id)); + $entries = $query->fetchAll(); + + return $entries; + } + public function retrieveAll($user_id) { - $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id"; + $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? ORDER BY id"; $query = $this->executeQuery($sql, array($user_id)); $entries = $query->fetchAll(); @@ -250,7 +272,7 @@ class Database { public function retrieveOneByURL($url, $user_id) { $entry = NULL; - $sql = "SELECT * FROM entries WHERE url=? AND user_id=?"; + $sql = "SELECT * FROM entries WHERE content <> '' AND url=? AND user_id=?"; $params = array($url, $user_id); $query = $this->executeQuery($sql, $params); $entry = $query->fetchAll(); @@ -267,21 +289,22 @@ class Database { public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { switch ($view) { case 'archive': - $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; + $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; $params = array($user_id, 1); break; case 'fav' : - $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? "; + $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_fav=? "; $params = array($user_id, 1); break; case 'tag' : $sql = "SELECT entries.* FROM entries LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id - WHERE entries.user_id=? AND tags_entries.tag_id = ? "; + WHERE entries.content <> '' AND + entries.user_id=? AND tags_entries.tag_id = ? "; $params = array($user_id, $tag_id); break; default: - $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; + $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; $params = array($user_id, 0); break; } @@ -294,24 +317,25 @@ class Database { return $entries; } - public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { - switch ($view) { + public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { + switch ($view) { case 'archive': - $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; + $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; $params = array($user_id, 1); break; case 'fav' : - $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? "; + $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_fav=? "; $params = array($user_id, 1); break; - case 'tag' : - $sql = "SELECT count(*) FROM entries - LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id - WHERE entries.user_id=? AND tags_entries.tag_id = ? "; - $params = array($user_id, $tag_id); - break; + case 'tag' : + $sql = "SELECT count(*) FROM entries + LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id + WHERE entries.content <> '' AND + entries.user_id=? AND tags_entries.tag_id = ? "; + $params = array($user_id, $tag_id); + break; default: - $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; + $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; $params = array($user_id, 0); break; } @@ -319,7 +343,7 @@ class Database { $query = $this->executeQuery($sql, $params); list($count) = $query->fetch(); - return $count; + return $count; } public function updateContent($id, $content, $user_id) { @@ -365,12 +389,15 @@ class Database { return $this->getHandle()->lastInsertId($column); } - public function retrieveAllTags($user_id) { - $sql = "SELECT DISTINCT tags.* FROM tags + public function retrieveAllTags($user_id, $term = null) { + $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id LEFT JOIN entries ON tags_entries.entry_id=entries.id - WHERE entries.user_id=?"; - $query = $this->executeQuery($sql, array($user_id)); + WHERE entries.content <> '' AND entries.user_id=? + ". (($term) ? "AND lower(tags.value) LIKE ?" : '') ." + GROUP BY tags.id, tags.value + ORDER BY tags.value"; + $query = $this->executeQuery($sql, (($term)? array($user_id, strtolower('%'.$term.'%')) : array($user_id) )); $tags = $query->fetchAll(); return $tags; @@ -381,7 +408,7 @@ class Database { $sql = "SELECT DISTINCT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id LEFT JOIN entries ON tags_entries.entry_id=entries.id - WHERE tags.id=? AND entries.user_id=?"; + WHERE entries.content <> '' AND tags.id=? AND entries.user_id=?"; $params = array(intval($id), $user_id); $query = $this->executeQuery($sql, $params); $tag = $query->fetchAll(); @@ -393,7 +420,8 @@ class Database { $sql = "SELECT entries.* FROM entries LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id - WHERE tags_entries.tag_id = ? AND entries.user_id=?"; + WHERE entries.content <> '' AND + tags_entries.tag_id = ? AND entries.user_id=?"; $query = $this->executeQuery($sql, array($tag_id, $user_id)); $entries = $query->fetchAll(); diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 87c00b7..7bf3330 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -35,6 +35,7 @@ class Poche 'ru_RU.utf8' => 'Pусский', 'sl_SI.utf8' => 'Slovenščina', 'uk_UA.utf8' => 'Українська', + 'pt_BR.utf8' => 'Brasileiro', ); public function __construct() { @@ -361,60 +362,6 @@ class Poche ); } - protected function getPageContent(Url $url) - { - // Saving and clearing context - $REAL = array(); - foreach( $GLOBALS as $key => $value ) { - if( $key != "GLOBALS" && $key != "_SESSION" ) { - $GLOBALS[$key] = array(); - $REAL[$key] = $value; - } - } - // Saving and clearing session - $REAL_SESSION = array(); - foreach( $_SESSION as $key => $value ) { - $REAL_SESSION[$key] = $value; - unset($_SESSION[$key]); - } - - // Running code in different context - $scope = function() { - extract( func_get_arg(1) ); - $_GET = $_REQUEST = array( - "url" => $url->getUrl(), - "max" => 5, - "links" => "preserve", - "exc" => "", - "format" => "json", - "submit" => "Create Feed" - ); - ob_start(); - require func_get_arg(0); - $json = ob_get_flush(); - return $json; - }; - $json = $scope( "inc/3rdparty/makefulltextfeed.php", array("url" => $url) ); - - // Clearing and restoring context - foreach( $GLOBALS as $key => $value ) { - if( $key != "GLOBALS" && $key != "_SESSION" ) { - unset($GLOBALS[$key]); - } - } - foreach( $REAL as $key => $value ) { - $GLOBALS[$key] = $value; - } - // Clearing and restoring session - foreach( $_SESSION as $key => $value ) { - unset($_SESSION[$key]); - } - foreach( $REAL_SESSION as $key => $value ) { - $_SESSION[$key] = $value; - } - return json_decode($json, true); - } - /** * Call action (mark as fav, archive, delete, etc.) */ @@ -423,17 +370,25 @@ class Poche switch ($action) { case 'add': - $content = $this->getPageContent($url); - $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); - $body = $content['rss']['channel']['item']['description']; + if (!$import) { + $content = Tools::getPageContent($url); + $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); + $body = $content['rss']['channel']['item']['description']; - // clean content from prevent xss attack - $config = HTMLPurifier_Config::createDefault(); - $purifier = new HTMLPurifier($config); - $title = $purifier->purify($title); - $body = $purifier->purify($body); + // clean content from prevent xss attack + $config = HTMLPurifier_Config::createDefault(); + $config->set('Cache.SerializerPath', CACHE); + $purifier = new HTMLPurifier($config); + $title = $purifier->purify($title); + $body = $purifier->purify($body); + } + else { + $title = ''; + $body = ''; + } //search for possible duplicate if not in import mode + $duplicate = NULL; if (!$import) { $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); } @@ -534,25 +489,33 @@ class Poche Tools::logm('error : article not found'); Tools::redirect(); } + //get all already set tags to preven duplicates + $already_set_tags = array(); + $entry_tags = $this->store->retrieveTagsByEntry($entry_id); + foreach ($entry_tags as $tag) { + $already_set_tags[] = $tag['value']; + } foreach($tags as $key => $tag_value) { $value = trim($tag_value); - $tag = $this->store->retrieveTagByValue($value); + if ($value && !in_array($value, $already_set_tags)) { + $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']; - } + 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); + # we assign the tag to the article + $this->store->setTagToEntry($tag_id, $entry_id); + } } if(!$import) { Tools::redirect(); @@ -581,8 +544,12 @@ class Poche switch ($view) { case 'config': - $dev = trim($this->getPocheVersion('dev')); - $prod = trim($this->getPocheVersion('prod')); + $dev_infos = $this->getPocheVersion('dev'); + $dev = trim($dev_infos[0]); + $check_time_dev = date('d-M-Y H:i', $dev_infos[1]); + $prod_infos = $this->getPocheVersion('prod'); + $prod = trim($prod_infos[0]); + $check_time_prod = date('d-M-Y H:i', $prod_infos[1]); $compare_dev = version_compare(POCHE, $dev); $compare_prod = version_compare(POCHE, $prod); $themes = $this->getInstalledThemes(); @@ -594,6 +561,8 @@ class Poche 'languages' => $languages, 'dev' => $dev, 'prod' => $prod, + 'check_time_dev' => $check_time_dev, + 'check_time_prod' => $check_time_prod, 'compare_dev' => $compare_dev, 'compare_prod' => $compare_prod, 'token' => $token, @@ -619,7 +588,17 @@ class Poche break; case 'tags': $token = $this->user->getConfigValue('token'); - $tags = $this->store->retrieveAllTags($this->user->getId()); + //if term is set - search tags for this term + $term = Tools::checkVar('term'); + $tags = $this->store->retrieveAllTags($this->user->getId(), $term); + if (Tools::isAjaxRequest()) { + $result = array(); + foreach ($tags as $tag) { + $result[] = $tag['value']; + } + echo json_encode($result); + exit; + } $tpl_vars = array( 'token' => $token, 'user_id' => $this->user->getId(), @@ -660,6 +639,7 @@ class Poche 'entries' => '', 'page_links' => '', 'nb_results' => '', + 'listmode' => (isset($_COOKIE['listmode']) ? true : false), ); //if id is given - we retrive entries by tag: id is tag id @@ -895,7 +875,9 @@ class Poche # the second
    is for read links $read = 1; } - $this->messages->add('s', _('import from instapaper completed')); + + $unlink = unlink($targetFile); + $this->messages->add('s', _('import from instapaper completed. You have to execute the cron to fetch content.')); Tools::logm('import from instapaper completed'); Tools::redirect(); } @@ -939,7 +921,9 @@ class Poche # the second