From 4058ff3ff4631bcc2c9cba534162c80db5cf2b65 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 7 Oct 2017 13:51:45 +0200 Subject: Remove SimplePie name from HTTP User-Agent string https://github.com/FreshRSS/FreshRSS/issues/1622#issuecomment-334928486 https://github.com/FreshRSS/FreshRSS/issues/1627 https://github.com/FreshRSS/FreshRSS/issues/1607 --- app/Models/Feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/Models') diff --git a/app/Models/Feed.php b/app/Models/Feed.php index d8fe03197..44d518a47 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -484,7 +484,7 @@ class FreshRSS_Feed extends Minz_Model { CURLOPT_URL => $hubJson['hub'], CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, - CURLOPT_USERAGENT => 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ')', + CURLOPT_USERAGENT => FRESHRSS_USERAGENT, CURLOPT_POSTFIELDS => http_build_query(array( 'hub.verify' => 'sync', 'hub.mode' => $state ? 'subscribe' : 'unsubscribe', -- cgit v1.2.3 From 1eb19409b5435546774425c00523b9f88d4fccf9 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 8 Oct 2017 17:26:43 +0200 Subject: CURLOPT_FOLLOWLOCATION open_basedir bug (#1657) CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set https://github.com/FreshRSS/FreshRSS/issues/1655#issuecomment-334999448 https://stackoverflow.com/questions/6918623/curlopt-followlocation-cannot-be-activated --- CHANGELOG.md | 2 ++ app/Models/Feed.php | 27 +++++++++++++++------------ lib/favicons.php | 4 ++-- 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'app/Models') diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a644478..4b24cd116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * SimplePie * Remove "SimplePie" name from HTTP User-Agent string [#1656](https://github.com/FreshRSS/FreshRSS/pull/1656) +* Bug fixing + * Work-around for `CURLOPT_FOLLOWLOCATION` `open_basedir` bug in favicons and PubSubHubbub [#1655](https://github.com/FreshRSS/FreshRSS/issues/1655) * Misc. * Travis translation validation tool [#1653](https://github.com/FreshRSS/FreshRSS/pull/1653) diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 44d518a47..85273d3f7 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -481,18 +481,21 @@ class FreshRSS_Feed extends Minz_Model { } $ch = curl_init(); curl_setopt_array($ch, array( - CURLOPT_URL => $hubJson['hub'], - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_USERAGENT => FRESHRSS_USERAGENT, - CURLOPT_POSTFIELDS => http_build_query(array( - 'hub.verify' => 'sync', - 'hub.mode' => $state ? 'subscribe' : 'unsubscribe', - 'hub.topic' => $url, - 'hub.callback' => $callbackUrl, - )) - ) - ); + CURLOPT_URL => $hubJson['hub'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POSTFIELDS => http_build_query(array( + 'hub.verify' => 'sync', + 'hub.mode' => $state ? 'subscribe' : 'unsubscribe', + 'hub.topic' => $url, + 'hub.callback' => $callbackUrl, + )), + CURLOPT_USERAGENT => FRESHRSS_USERAGENT, + CURLOPT_MAXREDIRS => 10, + )); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir bug + if (defined('CURLOPT_ENCODING')) { + curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings + } $response = curl_exec($ch); $info = curl_getinfo($ch); diff --git a/lib/favicons.php b/lib/favicons.php index 80246ee74..2d6f7aab7 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -31,12 +31,12 @@ function downloadHttp(&$url, $curlOptions = array()) { } $ch = curl_init($url); curl_setopt_array($ch, array( - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, CURLOPT_USERAGENT => FRESHRSS_USERAGENT, + CURLOPT_MAXREDIRS => 10, )); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir bug if (defined('CURLOPT_ENCODING')) { curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings } -- cgit v1.2.3 From f632a346269100d6a93bef318ffa66c97f16f6fa Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 12 Oct 2017 20:11:06 +0200 Subject: CLI optimize database (#1663) CLI optimize database https://github.com/FreshRSS/FreshRSS/issues/1583 And VACUUM in SQLite https://github.com/FreshRSS/FreshRSS/issues/918 Add VACUUM for PostgreSQL (Not tested yet) --- CHANGELOG.md | 4 ++++ app/Controllers/configureController.php | 6 +++-- app/Controllers/entryController.php | 4 ++-- app/Controllers/userController.php | 4 +++- app/Models/DatabaseDAO.php | 41 +++++++++++++++++++++++++++++++++ app/Models/DatabaseDAOPGSQL.php | 37 +++++++++++++++++++++++++++++ app/Models/DatabaseDAOSQLite.php | 13 +++++++++++ app/Models/EntryDAO.php | 22 ------------------ app/Models/EntryDAOPGSQL.php | 11 --------- app/Models/EntryDAOSQLite.php | 8 ------- cli/README.md | 3 +++ cli/db-optimize.php | 20 ++++++++++++++++ cli/user-info.php | 5 ++-- 13 files changed, 130 insertions(+), 48 deletions(-) create mode 100755 cli/db-optimize.php (limited to 'app/Models') diff --git a/CHANGELOG.md b/CHANGELOG.md index 051b04a3e..97fcdcbed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ * Remove "SimplePie" name from HTTP User-Agent string [#1656](https://github.com/FreshRSS/FreshRSS/pull/1656) * Bug fixing * Work-around for `CURLOPT_FOLLOWLOCATION` `open_basedir` bug in favicons and PubSubHubbub [#1655](https://github.com/FreshRSS/FreshRSS/issues/1655) +* CLI + * New command `./cli/db-optimize.php` for database optimisation [#1583](https://github.com/FreshRSS/FreshRSS/issues/1583) +* SQL + * Perform `VACUUM` on SQLite and PostgreSQL databases when optimisation is requested [#918](https://github.com/FreshRSS/FreshRSS/issues/918) * Misc. * Translation validation tool [#1653](https://github.com/FreshRSS/FreshRSS/pull/1653) * Translation manipulation tool [#1658](https://github.com/FreshRSS/FreshRSS/pull/1658) diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 155221d19..9d2ee450c 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -225,10 +225,12 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $entryDAO = FreshRSS_Factory::createEntryDao(); $this->view->nb_total = $entryDAO->count(); - $this->view->size_user = $entryDAO->size(); + + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); + $this->view->size_user = $databaseDAO->size(); if (FreshRSS_Auth::hasAccess('admin')) { - $this->view->size_total = $entryDAO->size(true); + $this->view->size_total = $databaseDAO->size(true); } } diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index c40588105..bd8b65b2b 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -147,8 +147,8 @@ class FreshRSS_entry_Controller extends Minz_ActionController { @set_time_limit(300); - $entryDAO = FreshRSS_Factory::createEntryDao(); - $entryDAO->optimizeTable(); + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); + $databaseDAO->optimize(); $feedDAO = FreshRSS_Factory::createFeedDao(); $feedDAO->updateCachedValues(); diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index a58501186..2a1d43d9e 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -120,7 +120,9 @@ class FreshRSS_user_Controller extends Minz_ActionController { // Get information about the current user. $entryDAO = FreshRSS_Factory::createEntryDao($this->view->current_user); $this->view->nb_articles = $entryDAO->count(); - $this->view->size_user = $entryDAO->size(); + + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); + $this->view->size_user = $databaseDAO->size(); } public static function createUser($new_user_name, $passwordPlain, $apiPasswordPlain, $userConfig = array(), $insertDefaultFeeds = true) { diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index 6ba5bca3e..f5469f2b7 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -80,4 +80,45 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { return $list; } + + public function size($all = false) { + $db = FreshRSS_Context::$system_conf->db; + $sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema=?'; //MySQL + $values = array($db['base']); + if (!$all) { + $sql .= ' AND table_name LIKE ?'; + $values[] = $this->prefix . '%'; + } + $stm = $this->bd->prepare($sql); + $stm->execute($values); + $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); + return $res[0]; + } + + public function optimize() { + $ok = true; + + $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'entry`'; //MySQL + $stm = $this->bd->prepare($sql); + $ok &= $stm != false; + if ($stm) { + $ok &= $stm->execute(); + } + + $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'feed`'; //MySQL + $stm = $this->bd->prepare($sql); + $ok &= $stm != false; + if ($stm) { + $ok &= $stm->execute(); + } + + $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'category`'; //MySQL + $stm = $this->bd->prepare($sql); + $ok &= $stm != false; + if ($stm) { + $ok &= $stm->execute(); + } + + return $ok; + } } diff --git a/app/Models/DatabaseDAOPGSQL.php b/app/Models/DatabaseDAOPGSQL.php index 2a18db970..1b3f7408d 100644 --- a/app/Models/DatabaseDAOPGSQL.php +++ b/app/Models/DatabaseDAOPGSQL.php @@ -40,4 +40,41 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAO { 'default' => $dao['default'], ); } + + public function size($all = true) { + $db = FreshRSS_Context::$system_conf->db; + $sql = 'SELECT pg_size_pretty(pg_database_size(?))'; + $values = array($db['base']); + $stm = $this->bd->prepare($sql); + $stm->execute($values); + $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); + return $res[0]; + } + + public function optimize() { + $ok = true; + + $sql = 'VACUUM `' . $this->prefix . 'entry`'; + $stm = $this->bd->prepare($sql); + $ok &= $stm != false; + if ($stm) { + $ok &= $stm->execute(); + } + + $sql = 'VACUUM `' . $this->prefix . 'feed`'; + $stm = $this->bd->prepare($sql); + $ok &= $stm != false; + if ($stm) { + $ok &= $stm->execute(); + } + + $sql = 'VACUUM `' . $this->prefix . 'category`'; + $stm = $this->bd->prepare($sql); + $ok &= $stm != false; + if ($stm) { + $ok &= $stm->execute(); + } + + return $ok; + } } diff --git a/app/Models/DatabaseDAOSQLite.php b/app/Models/DatabaseDAOSQLite.php index 2e1df132e..d3aedb3c0 100644 --- a/app/Models/DatabaseDAOSQLite.php +++ b/app/Models/DatabaseDAOSQLite.php @@ -45,4 +45,17 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { 'default' => $dao['dflt_value'], ); } + + public function size($all = false) { + return @filesize(join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite')); + } + + public function optimize() { + $sql = 'VACUUM'; + $stm = $this->bd->prepare($sql); + if ($stm) { + return $stm->execute(); + } + return false; + } } diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index bebafe500..e8b6dcdae 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -885,28 +885,6 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable { return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread); } - public function optimizeTable() { - $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'entry`'; //MySQL - $stm = $this->bd->prepare($sql); - if ($stm) { - return $stm->execute(); - } - } - - public function size($all = false) { - $db = FreshRSS_Context::$system_conf->db; - $sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema=?'; //MySQL - $values = array($db['base']); - if (!$all) { - $sql .= ' AND table_name LIKE ?'; - $values[] = $this->prefix . '%'; - } - $stm = $this->bd->prepare($sql); - $stm->execute($values); - $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); - return $res[0]; - } - public static function daoToEntry($dao) { $entry = new FreshRSS_Entry( $dao['id_feed'], diff --git a/app/Models/EntryDAOPGSQL.php b/app/Models/EntryDAOPGSQL.php index 405774abf..f09fe8e75 100644 --- a/app/Models/EntryDAOPGSQL.php +++ b/app/Models/EntryDAOPGSQL.php @@ -46,15 +46,4 @@ END $$;'; } return $result; } - - public function size($all = true) { - $db = FreshRSS_Context::$system_conf->db; - $sql = 'SELECT pg_size_pretty(pg_database_size(?))'; - $values = array($db['base']); - $stm = $this->bd->prepare($sql); - $stm->execute($values); - $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); - return $res[0]; - } - } diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php index 8dad54322..0f57dc1ba 100644 --- a/app/Models/EntryDAOSQLite.php +++ b/app/Models/EntryDAOSQLite.php @@ -261,12 +261,4 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO { } return $affected; } - - public function optimizeTable() { - //TODO: Search for an equivalent in SQLite - } - - public function size($all = false) { - return @filesize(join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite')); - } } diff --git a/cli/README.md b/cli/README.md index ce1be10a7..6f907566c 100644 --- a/cli/README.md +++ b/cli/README.md @@ -69,6 +69,9 @@ cd /usr/share/FreshRSS # Returns: 1) a * iff the user is admin, 2) the name of the user, # 3) the date/time of last user action, 4) the size occupied, # and the number of: 5) categories, 6) feeds, 7) read articles, 8) unread articles, and 9) favourites + +./cli/db-optimize.php --user username +# Optimize database (reduces the size) for a given user (perform `OPTIMIZE TABLE` in MySQL, `VACUUM` in SQLite) ``` diff --git a/cli/db-optimize.php b/cli/db-optimize.php new file mode 100755 index 000000000..83123a669 --- /dev/null +++ b/cli/db-optimize.php @@ -0,0 +1,20 @@ +#!/usr/bin/php +optimize(); + +done($ok); diff --git a/cli/user-info.php b/cli/user-info.php index aa3e239b8..41b95cbf3 100755 --- a/cli/user-info.php +++ b/cli/user-info.php @@ -19,6 +19,7 @@ foreach ($users as $username) { $catDAO = new FreshRSS_CategoryDAO(); $feedDAO = FreshRSS_Factory::createFeedDao($username); $entryDAO = FreshRSS_Factory::createEntryDao($username); + $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username); $nbEntries = $entryDAO->countUnreadRead(); $nbFavorites = $entryDAO->countUnreadReadFavorites(); @@ -27,7 +28,7 @@ foreach ($users as $username) { echo $username, "\t", date('c', FreshRSS_UserDAO::mtime($username)), "\t", - format_bytes($entryDAO->size()), "\t", + format_bytes($databaseDAO->size()), "\t", $catDAO->count(), " categories\t", count($feedDAO->listFeedsIds()), " feeds\t", $nbEntries['read'], " reads\t", @@ -38,7 +39,7 @@ foreach ($users as $username) { echo $username, "\t", FreshRSS_UserDAO::mtime($username), "\t", - $entryDAO->size(), "\t", + $databaseDAO->size(), "\t", $catDAO->count(), "\t", count($feedDAO->listFeedsIds()), "\t", $nbEntries['read'], "\t", -- cgit v1.2.3 From afffbfce0758391a52c8c0c5b9766643a49065e8 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sat, 4 Nov 2017 21:19:51 +0100 Subject: Add a Mastodon share (#1674) See #1521 --- app/FreshRSS.php | 8 +++++- app/Models/Share.php | 31 +++++++++++++++++++++-- app/i18n/cz/gen.php | 13 +++++----- app/i18n/de/gen.php | 10 ++++---- app/i18n/en/gen.php | 10 ++++---- app/i18n/es/gen.php | 11 ++++---- app/i18n/fr/gen.php | 11 ++++---- app/i18n/it/gen.php | 11 ++++---- app/i18n/kr/gen.php | 11 ++++---- app/i18n/nl/gen.php | 17 +++++++------ app/i18n/pt-br/gen.php | 11 ++++---- app/i18n/ru/gen.php | 9 ++++--- app/i18n/tr/gen.php | 11 ++++---- app/i18n/zh-cn/gen.php | 11 ++++---- app/views/configure/sharing.phtml | 6 ++++- app/views/helpers/index/normal/entry_bottom.phtml | 9 ++++++- data/shares.php | 25 ++++++++++++++++++ p/scripts/main.js | 11 ++++++++ 18 files changed, 158 insertions(+), 68 deletions(-) (limited to 'app/Models') diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 90d6fae06..8f4ee334c 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -111,7 +111,13 @@ class FreshRSS extends Minz_FrontController { public static function preLayout() { switch (Minz_Request::controllerName()) { case 'index': - header("Content-Security-Policy: default-src 'self'; child-src *; frame-src *; img-src * data:; media-src *"); + $urlToAuthorize = array_filter(array_map(function($a) { + if ('POST' === $a['method']) { + return $a['url']; + } + }, FreshRSS_Context::$user_conf->sharing)); + $connectSrc = count($urlToAuthorize) ? sprintf("; connect-src 'self' %s", implode(' ', $urlToAuthorize)) : ''; + header(sprintf("Content-Security-Policy: default-src 'self'; child-src *; frame-src *; img-src * data:; media-src *%s", $connectSrc)); break; case 'stats': header("Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline'"); diff --git a/app/Models/Share.php b/app/Models/Share.php index 86b1b9ed9..7378b30df 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -21,9 +21,11 @@ class FreshRSS_Share { } $help_url = isset($share_options['help']) ? $share_options['help'] : ''; + $field = isset($share_options['field']) ? $share_options['field'] : null; self::$list_sharing[$type] = new FreshRSS_Share( $type, $share_options['url'], $share_options['transform'], - $share_options['form'], $help_url + $share_options['form'], $help_url, $share_options['method'], + $field ); } @@ -76,6 +78,8 @@ class FreshRSS_Share { private $base_url = null; private $title = null; private $link = null; + private $method = 'GET'; + private $field; /** * Create a FreshRSS_Share object. @@ -86,9 +90,10 @@ class FreshRSS_Share { * is typically for a centralized service while "advanced" is for * decentralized ones. * @param $help_url is an optional url to give help on this option. + * @param $method defines the sharing method (GET or POST) */ private function __construct($type, $url_transform, $transform, - $form_type, $help_url = '') { + $form_type, $help_url, $method, $field) { $this->type = $type; $this->name = _t('gen.share.' . $type); $this->url_transform = $url_transform; @@ -103,6 +108,11 @@ class FreshRSS_Share { $form_type = 'simple'; } $this->form_type = $form_type; + if (!in_array($method, array('GET', 'POST'))) { + $method = 'GET'; + } + $this->method = $method; + $this->field = $field; } /** @@ -116,6 +126,8 @@ class FreshRSS_Share { 'url' => 'base_url', 'title' => 'title', 'link' => 'link', + 'method' => 'method', + 'field' => 'field', ); foreach ($options as $key => $value) { @@ -132,6 +144,21 @@ class FreshRSS_Share { return $this->type; } + /** + * Return the current method of the share option. + */ + public function method() { + return $this->method; + } + + /** + * Return the current field of the share option. It's null for shares + * using the GET method. + */ + public function field() { + return $this->field; + } + /** * Return the current form type of the share option. */ diff --git a/app/i18n/cz/gen.php b/app/i18n/cz/gen.php index a9c7dc875..e43355f64 100644 --- a/app/i18n/cz/gen.php +++ b/app/i18n/cz/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filtrovat', 'import' => 'Import', 'manage' => 'Spravovat', - 'mark_read' => 'Označit jako přečtené', 'mark_favorite' => 'Označit jako oblíbené', + 'mark_read' => 'Označit jako přečtené', 'remove' => 'Odstranit', 'see_website' => 'Navštívit WWW stránku', 'submit' => 'Odeslat', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Minulý rok', 'mar' => 'bře', 'march' => 'Bře', - 'may_' => 'Kvě', 'may' => 'Květen', + 'may_' => 'Kvě', 'mon' => 'Po', 'month' => 'měsíce', 'nov' => 'lis', @@ -143,7 +143,7 @@ return array( 'sharing' => 'Sdílení', 'shortcuts' => 'Zkratky', 'stats' => 'Statistika', - 'system' => 'System configuration',// @todo translate + 'system' => 'System configuration', // @todo translate 'update' => 'Aktualizace', 'user_management' => 'Správa uživatelů', 'user_profile' => 'Profil', @@ -158,20 +158,21 @@ return array( 'previous' => 'Předchozí', ), 'share' => array( + 'Known' => 'Known based sites', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Tisk', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Upozornění!', diff --git a/app/i18n/de/gen.php b/app/i18n/de/gen.php index 43d0a2c05..b42081324 100644 --- a/app/i18n/de/gen.php +++ b/app/i18n/de/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filtern', 'import' => 'Importieren', 'manage' => 'Verwalten', - 'mark_read' => 'Als gelesen markieren', 'mark_favorite' => 'Als Favorit markieren', + 'mark_read' => 'Als gelesen markieren', 'remove' => 'Entfernen', 'see_website' => 'Webseite ansehen', 'submit' => 'Abschicken', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Letztes Jahr', 'mar' => 'Mär', 'march' => 'März', - 'may_' => 'Mai', 'may' => 'Mai', + 'may_' => 'Mai', 'mon' => 'Mo', 'month' => 'Monat(en)', 'nov' => 'Nov', @@ -163,15 +163,15 @@ return array( 'email' => 'E-Mail', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Drucken', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Achtung!', diff --git a/app/i18n/en/gen.php b/app/i18n/en/gen.php index 095eb17d3..ef1993dbc 100644 --- a/app/i18n/en/gen.php +++ b/app/i18n/en/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filter', 'import' => 'Import', 'manage' => 'Manage', - 'mark_read' => 'Mark as read', 'mark_favorite' => 'Mark as favourite', + 'mark_read' => 'Mark as read', 'remove' => 'Remove', 'see_website' => 'See website', 'submit' => 'Submit', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Last year', 'mar' => 'Mar.', 'march' => 'March', - 'may_' => 'May', 'may' => 'May', + 'may_' => 'May', 'mon' => 'Mon', 'month' => 'months', 'nov' => 'Nov.', @@ -163,15 +163,15 @@ return array( 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Print', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Warning!', diff --git a/app/i18n/es/gen.php b/app/i18n/es/gen.php index 68fdaf429..0f113e073 100755 --- a/app/i18n/es/gen.php +++ b/app/i18n/es/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filtrar', 'import' => 'Importar', 'manage' => 'Administrar', - 'mark_read' => 'Marcar como leído', 'mark_favorite' => 'Marcar como favorita', + 'mark_read' => 'Marcar como leído', 'remove' => 'Borrar', 'see_website' => 'Ver web', 'submit' => 'Enviar', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Año pasado', 'mar' => 'mar', 'march' => 'marzo', - 'may_' => 'may', 'may' => 'mayo', + 'may_' => 'may', 'mon' => 'Lun', 'month' => 'meses', 'nov' => 'nov', @@ -158,20 +158,21 @@ return array( 'previous' => 'Anterior', ), 'share' => array( + 'Known' => 'Known based sites', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Print', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => '¡Aviso!', diff --git a/app/i18n/fr/gen.php b/app/i18n/fr/gen.php index 16935c3c4..29b7f8e4a 100644 --- a/app/i18n/fr/gen.php +++ b/app/i18n/fr/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filtrer', 'import' => 'Importer', 'manage' => 'Gérer', - 'mark_read' => 'Marquer comme lu', 'mark_favorite' => 'Mettre en favori', + 'mark_read' => 'Marquer comme lu', 'remove' => 'Supprimer', 'see_website' => 'Voir le site', 'submit' => 'Valider', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Depuis l’année dernière', 'mar' => 'mars', 'march' => 'mars', - 'may_' => 'mai', 'may' => 'mai', + 'may_' => 'mai', 'mon' => 'lun.', 'month' => 'mois', 'nov' => 'nov.', @@ -158,20 +158,21 @@ return array( 'previous' => 'Précédent', ), 'share' => array( + 'Known' => 'Sites basés sur Known', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Courriel', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Imprimer', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Sites basés sur Known', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Attention !', diff --git a/app/i18n/it/gen.php b/app/i18n/it/gen.php index ae39d7324..9eaabc2be 100644 --- a/app/i18n/it/gen.php +++ b/app/i18n/it/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filtra', 'import' => 'Importa', 'manage' => 'Gestisci', - 'mark_read' => 'Segna come letto', 'mark_favorite' => 'Segna come preferito', + 'mark_read' => 'Segna come letto', 'remove' => 'Rimuovi', 'see_website' => 'Vai al sito', 'submit' => 'Conferma', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Ultimo anno', 'mar' => 'mar.', 'march' => 'marzo', - 'may_' => 'May', 'may' => 'maggio', + 'may_' => 'May', 'mon' => 'Mon', 'month' => 'mesi', 'nov' => 'nov.', @@ -158,20 +158,21 @@ return array( 'previous' => 'Precedente', ), 'share' => array( + 'Known' => 'Siti basati su Known', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Stampa', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Siti basati su Known', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Attenzione!', diff --git a/app/i18n/kr/gen.php b/app/i18n/kr/gen.php index 35d5e8143..e9b6ea9b8 100644 --- a/app/i18n/kr/gen.php +++ b/app/i18n/kr/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => '해당하는 글 보기', 'import' => '불러오기', 'manage' => '관리', - 'mark_read' => '읽음으로 표시', 'mark_favorite' => '즐겨찾기에 등록', + 'mark_read' => '읽음으로 표시', 'remove' => '삭제', 'see_website' => '웹사이트 열기', 'submit' => '설정 저장', @@ -79,8 +79,8 @@ return array( 'last_year' => '최근 일 년', 'mar' => '3월', 'march' => '3월', - 'may_' => '5월', 'may' => '5월', + 'may_' => '5월', 'mon' => '월', 'month' => '개월', 'nov' => '11월', @@ -158,20 +158,21 @@ return array( 'previous' => 'Previous', ), 'share' => array( + 'Known' => 'Known based sites', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => '메일', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => '인쇄', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => '경고!', diff --git a/app/i18n/nl/gen.php b/app/i18n/nl/gen.php index 1617936ab..bccab8310 100644 --- a/app/i18n/nl/gen.php +++ b/app/i18n/nl/gen.php @@ -1,5 +1,5 @@ array( 'actualize' => 'Actualiseren', @@ -13,8 +13,8 @@ return array( 'filter' => 'Filteren', 'import' => 'Importeren', 'manage' => 'Beheren', - 'mark_read' => 'Markeer als gelezen', 'mark_favorite' => 'Markeer als favoriet', + 'mark_read' => 'Markeer als gelezen', 'remove' => 'Verwijder', 'see_website' => 'Bekijk website', 'submit' => 'Opslaan', @@ -63,8 +63,8 @@ return array( 'december' => 'Dec', 'feb' => 'feb', 'february' => 'Feb', - 'format_date' => 'j %s Y', //<-- European date format // 'format_date' => '%s j\\<\\s\\u\\p\\>S\\<\\/\\s\\u\\p\\> Y', - 'format_date_hour' => 'j %s Y \\o\\m H\\:i', //<-- European date format // 'format_date_hour' => '%s j\\<\\s\\u\\p\\>S\\<\\/\\s\\u\\p\\> Y \\a\\t H\\:i', + 'format_date' => 'j %s Y', + 'format_date_hour' => 'j %s Y \\o\\m H\\:i', 'fri' => 'Vr', 'jan' => 'jan', 'january' => 'Jan', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Vorig jaar', 'mar' => 'mrt', 'march' => 'Mrt', - 'may_' => 'Mei', 'may' => 'Mei', + 'may_' => 'Mei', 'mon' => 'Ma', 'month' => 'maanden', 'nov' => 'nov', @@ -158,20 +158,21 @@ return array( 'previous' => 'Vorige', ), 'share' => array( + 'Known' => 'Known based sites', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Print', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Attentie!', diff --git a/app/i18n/pt-br/gen.php b/app/i18n/pt-br/gen.php index 1a74e1437..e313b0d8b 100644 --- a/app/i18n/pt-br/gen.php +++ b/app/i18n/pt-br/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filtrar', 'import' => 'Importar', 'manage' => 'Gerenciar', - 'mark_read' => 'Marcar como lido', 'mark_favorite' => 'Marcar como favorito', + 'mark_read' => 'Marcar como lido', 'remove' => 'Remover', 'see_website' => 'Ver o site', 'submit' => 'Enviar', @@ -124,7 +124,7 @@ return array( 'pt-br' => 'Português (Brasil)', 'ru' => 'Русский', 'tr' => 'Türkçe', - 'zh-cn' => '简体中文' + 'zh-cn' => '简体中文', ), 'menu' => array( 'about' => 'Sobre', @@ -157,20 +157,21 @@ return array( 'previous' => 'Anterior', ), 'share' => array( + 'Known' => 'Known based sites', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Imprimir', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Atencão!', diff --git a/app/i18n/ru/gen.php b/app/i18n/ru/gen.php index 3a728016d..3283731df 100644 --- a/app/i18n/ru/gen.php +++ b/app/i18n/ru/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filter', 'import' => 'Import', 'manage' => 'Manage', - 'mark_read' => 'Mark as read', 'mark_favorite' => 'Mark as favourite', + 'mark_read' => 'Mark as read', 'remove' => 'Remove', 'see_website' => 'See website', 'submit' => 'Submit', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Last year', 'mar' => 'mar', 'march' => 'Mar', - 'may_' => 'May', 'may' => 'May', + 'may_' => 'May', 'mon' => 'Mon', 'month' => 'months', 'nov' => 'nov', @@ -158,20 +158,21 @@ return array( 'previous' => 'Previous', ), 'share' => array( + 'Known' => 'Known based sites', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Print', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Warning!', diff --git a/app/i18n/tr/gen.php b/app/i18n/tr/gen.php index 81f926840..535563542 100644 --- a/app/i18n/tr/gen.php +++ b/app/i18n/tr/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => 'Filtrele', 'import' => 'İçe Aktar', 'manage' => 'Yönet', - 'mark_read' => 'Okundu olarak işaretle', 'mark_favorite' => 'Favoriye ekle', + 'mark_read' => 'Okundu olarak işaretle', 'remove' => 'Sil', 'see_website' => 'Siteyi gör', 'submit' => 'Onayla', @@ -79,8 +79,8 @@ return array( 'last_year' => 'Geçen yıl', 'mar' => 'mar', 'march' => 'Mar', - 'may_' => 'May', 'may' => 'Mayıs', + 'may_' => 'May', 'mon' => 'Pzt', 'month' => 'ay', 'nov' => 'kas', @@ -158,20 +158,21 @@ return array( 'previous' => 'Önceki', ), 'share' => array( + 'Known' => 'Known based sites', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Print', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => 'Tehlike!', diff --git a/app/i18n/zh-cn/gen.php b/app/i18n/zh-cn/gen.php index 3fd2abef6..84be9f4ba 100644 --- a/app/i18n/zh-cn/gen.php +++ b/app/i18n/zh-cn/gen.php @@ -13,8 +13,8 @@ return array( 'filter' => '过滤器', 'import' => '导入', 'manage' => '管理', - 'mark_read' => '设为已读', 'mark_favorite' => '加入收藏', + 'mark_read' => '设为已读', 'remove' => '删除', 'see_website' => '查看网站', 'submit' => '提交', @@ -79,8 +79,8 @@ return array( 'last_year' => '去年', 'mar' => '三月', 'march' => '三月', - 'may_' => '五月', 'may' => '五月', + 'may_' => '五月', 'mon' => '周一', 'month' => '个月', 'nov' => '十一月', @@ -158,20 +158,21 @@ return array( 'previous' => '上一页', ), 'share' => array( + 'Known' => 'Known based sites', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', 'email' => 'Email', 'facebook' => 'Facebook', 'g+' => 'Google+', + 'gnusocial' => 'GNU social', + 'jdh' => 'Journal du hacker', + 'mastodon' => 'Mastodon', 'movim' => 'Movim', 'print' => 'Print', 'shaarli' => 'Shaarli', 'twitter' => 'Twitter', 'wallabag' => 'wallabag v1', 'wallabagv2' => 'wallabag v2', - 'jdh' => 'Journal du hacker', - 'Known' => 'Known based sites', - 'gnusocial' => 'GNU social', ), 'short' => array( 'attention' => '警告!', diff --git a/app/views/configure/sharing.phtml b/app/views/configure/sharing.phtml index ffcfb8b29..b0e6618fa 100644 --- a/app/views/configure/sharing.phtml +++ b/app/views/configure/sharing.phtml @@ -9,6 +9,8 @@ ' data-advanced='
+ +
@@ -28,6 +30,8 @@
+ +
formType() === 'advanced') { ?> @@ -48,7 +52,7 @@
+ + diff --git a/data/shares.php b/data/shares.php index d73ae3826..5403fd48c 100644 --- a/data/shares.php +++ b/data/shares.php @@ -14,6 +14,10 @@ * The ~TITLE~ placeholder represents the title of the shared article. * - transform is an array of transformation to apply on links and titles * - help is a URL to a help page + * - form is the type of form to display during configuration. It's either + * 'simple' or 'advanced'. 'simple' is used when only the name is configurable, + * 'advanced' is used when the name and the location are configurable. + * - method is the HTTP method (POST or GET) used to share a link. */ return array( @@ -22,12 +26,14 @@ return array( 'transform' => array('rawurlencode'), 'help' => 'http://sebsauvage.net/wiki/doku.php?id=php:shaarli', 'form' => 'advanced', + 'method' => 'GET', ), 'blogotext' => array( 'url' => '~URL~/admin/links.php?url=~LINK~', 'transform' => array(), 'help' => 'http://lehollandaisvolant.net/blogotext/fr/', 'form' => 'advanced', + 'method' => 'GET', ), 'wallabag' => array( 'url' => '~URL~?action=add&url=~LINK~', @@ -37,6 +43,7 @@ return array( ), 'help' => 'http://www.wallabag.org/', 'form' => 'advanced', + 'method' => 'GET', ), 'wallabagv2' => array( 'url' => '~URL~/bookmarklet?url=~LINK~', @@ -46,59 +53,77 @@ return array( ), 'help' => 'http://www.wallabag.org/', 'form' => 'advanced', + 'method' => 'GET', ), 'diaspora' => array( 'url' => '~URL~/bookmarklet?url=~LINK~&title=~TITLE~', 'transform' => array('rawurlencode'), 'help' => 'https://diasporafoundation.org/', 'form' => 'advanced', + 'method' => 'GET', ), 'movim' => array( 'url' => '~URL~/?share/~LINK~', 'transform' => array('rawurlencode', 'urlencode'), 'help' => 'https://github.com/edhelas/movim', 'form' => 'advanced', + 'method' => 'GET', ), 'twitter' => array( 'url' => 'https://twitter.com/share?url=~LINK~&text=~TITLE~', 'transform' => array('rawurlencode'), 'form' => 'simple', + 'method' => 'GET', ), 'g+' => array( 'url' => 'https://plus.google.com/share?url=~LINK~', 'transform' => array('rawurlencode'), 'form' => 'simple', + 'method' => 'GET', ), 'facebook' => array( 'url' => 'https://www.facebook.com/sharer.php?u=~LINK~&t=~TITLE~', 'transform' => array('rawurlencode'), 'form' => 'simple', + 'method' => 'GET', ), 'email' => array( 'url' => 'mailto:?subject=~TITLE~&body=~LINK~', 'transform' => array('rawurlencode'), 'form' => 'simple', + 'method' => 'GET', ), 'print' => array( 'url' => '#', 'transform' => array(), 'form' => 'simple', + 'method' => 'GET', ), 'jdh' => array( 'url' => 'https://www.journalduhacker.net/stories/new?url=~LINK~&title=~TITLE~', 'transform' => array('rawurlencode'), 'form' => 'simple', + 'method' => 'GET', ), 'Known' => array( 'url' => '~URL~/share?share_url=~LINK~&share_title=~TITLE~', 'transform' => array('rawurlencode'), 'help' => 'https://withknown.com/', 'form' => 'advanced', + 'method' => 'GET', ), 'gnusocial' => array( 'url' => '~URL~/notice/new?content=~TITLE~%20~LINK~', 'transform' => array('urlencode'), 'help' => 'https://gnu.io/social/', 'form' => 'advanced', + 'method' => 'GET', + ), + 'mastodon' => array( + 'url' => '~URL~/api/v1/statuses', + 'transform' => array(), + 'form' => 'advanced', + 'method' => 'POST', + 'field' => 'status', ), ); diff --git a/p/scripts/main.js b/p/scripts/main.js index 278ecfee9..ce8070008 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1172,6 +1172,14 @@ function init_print_action() { }); } +function init_post_action() { + $('.item.share > a[href="POST"]').click(function (event) { + event.preventDefault(); + var form = $(this).next('form'); + $.post(form.data('url'), form.serialize()); + }); +} + function init_share_observers() { shares = $('.group-share').length; @@ -1182,6 +1190,8 @@ function init_share_observers() { row = row.replace(/##type##/g, opt.val()); row = row.replace(/##help##/g, opt.data('help')); row = row.replace(/##key##/g, shares); + row = row.replace(/##method##/g, opt.data('method')); + row = row.replace(/##field##/g, opt.data('field')); $(this).parents('.form-group').before(row); shares++; @@ -1398,6 +1408,7 @@ function init_afterDOM() { init_posts(); init_nav_entries(); init_print_action(); + init_post_action(); init_notifs_html5(); window.setInterval(refreshUnreads, 120000); } else { -- cgit v1.2.3 From 4f06b17e005456515768f46b3cc3130428f579bf Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 3 Dec 2017 17:30:02 +0100 Subject: Extension function to override entry hash (#1707) Extension function to override entry hash https://github.com/FreshRSS/FreshRSS/issues/1706 --- CHANGELOG.md | 2 ++ app/Models/Entry.php | 8 ++++++++ 2 files changed, 10 insertions(+) (limited to 'app/Models') diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b3b06b4..c7fec5334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ * Perform `VACUUM` on SQLite and PostgreSQL databases when optimisation is requested [#918](https://github.com/FreshRSS/FreshRSS/issues/918) * I18n * Improved German [#1698](https://github.com/FreshRSS/FreshRSS/pull/1698) +* Extensions + * New function `$entry->_hash($hex)` for extensios that change the content of entries [#1707](https://github.com/FreshRSS/FreshRSS/pull/1707) * Misc. * Translation validation tool [#1653](https://github.com/FreshRSS/FreshRSS/pull/1653) * Translation manipulation tool [#1658](https://github.com/FreshRSS/FreshRSS/pull/1658) diff --git a/app/Models/Entry.php b/app/Models/Entry.php index df3d59bea..0ad3781e5 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -97,6 +97,14 @@ class FreshRSS_Entry extends Minz_Model { return $this->hash; } + public function _hash($value) { + $value = trim($value); + if (ctype_xdigit($value)) { + $this->hash = substr($value, 0, 32); + } + return $this->hash; + } + public function _id($value) { $this->id = $value; } -- cgit v1.2.3 From b1c317a253445a6458f1263c1b622a788cc7cd0e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 10 Dec 2017 21:31:41 +0100 Subject: Log rotation, use Minz_Log, new log constants ADMIN_LOG, API_LOG, PSHB_LOG --- app/Controllers/feedController.php | 4 ++-- app/Models/Feed.php | 14 +++++------- app/Models/LogDAO.php | 6 ++--- app/actualize_script.php | 13 ++++------- constants.php | 7 ++++-- lib/Minz/Log.php | 22 ++++++++++++++---- p/api/greader.php | 47 +++++++++----------------------------- p/api/pshb.php | 40 +++++++++++++++----------------- 8 files changed, 66 insertions(+), 87 deletions(-) (limited to 'app/Models') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 45cba9e98..883f7af05 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -263,7 +263,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if ((!$simplePiePush) && (!$feed_id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) { //$text = 'Skip pull of feed using PubSubHubbub: ' . $url; //Minz_Log::debug($text); - //file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + //Minz_Log::debug($text, PSHB_LOG); continue; //When PubSubHubbub is used, do not pull refresh so often } @@ -371,7 +371,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if ($pubSubHubbubEnabled && !$simplePiePush) { //We use push, but have discovered an article by pull! $text = 'An article was discovered by pull although we use PubSubHubbub!: Feed ' . $url . ' GUID ' . $entry->guid(); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); Minz_Log::warning($text); $pubSubHubbubEnabled = false; $feed->pubSubHubbubError(true); diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 85273d3f7..75d9f6d6f 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -403,8 +403,7 @@ class FreshRSS_Feed extends Minz_Model { if (!isset($hubJson['error']) || $hubJson['error'] !== (bool)$error) { $hubJson['error'] = (bool)$error; file_put_contents($hubFilename, json_encode($hubJson)); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" - . 'Set error to ' . ($error ? 1 : 0) . ' for ' . $url . "\n", FILE_APPEND); + Minz_Log::warning('Set error to ' . ($error ? 1 : 0) . ' for ' . $url, PSHB_LOG); } return false; } @@ -419,7 +418,7 @@ class FreshRSS_Feed extends Minz_Model { if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key'])) { $text = 'Invalid JSON for PubSubHubbub: ' . $this->url; Minz_Log::warning($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); return false; } if ((!empty($hubJson['lease_end'])) && ($hubJson['lease_end'] < (time() + (3600 * 23)))) { //TODO: Make a better policy @@ -427,7 +426,7 @@ class FreshRSS_Feed extends Minz_Model { . date('c', empty($hubJson['lease_end']) ? time() : $hubJson['lease_end']) . ' and needs renewal: ' . $this->url; Minz_Log::warning($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); $key = $hubJson['key']; //To renew our lease } elseif (((!empty($hubJson['error'])) || empty($hubJson['lease_end'])) && (empty($hubJson['lease_start']) || $hubJson['lease_start'] < time() - (3600 * 23))) { //Do not renew too often @@ -445,7 +444,7 @@ class FreshRSS_Feed extends Minz_Model { file_put_contents(PSHB_PATH . '/keys/' . $key . '.txt', base64url_encode($this->selfUrl)); $text = 'PubSubHubbub prepared for ' . $this->url; Minz_Log::debug($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::debug($text, PSHB_LOG); } $currentUser = Minz_Session::param('currentUser'); if (FreshRSS_user_Controller::checkUsername($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) { @@ -499,9 +498,8 @@ class FreshRSS_Feed extends Minz_Model { $response = curl_exec($ch); $info = curl_getinfo($ch); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . - 'PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url . - ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response . "\n", FILE_APPEND); + Minz_Log::warning('PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url . + ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response, PSHB_LOG); if (substr($info['http_code'], 0, 1) == '2') { return true; diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php index ab258cd58..5bce466d5 100644 --- a/app/Models/LogDAO.php +++ b/app/Models/LogDAO.php @@ -22,9 +22,9 @@ class FreshRSS_LogDAO { public static function truncate() { file_put_contents(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), ''); if (FreshRSS_Auth::hasAccess('admin')) { - file_put_contents(join_path(DATA_PATH, 'users', '_', 'log.txt'), ''); - file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_api.txt'), ''); - file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_pshb.txt'), ''); + file_put_contents(ADMIN_LOG, ''); + file_put_contents(API_LOG, ''); + file_put_contents(PSHB_LOG, ''); } } } diff --git a/app/actualize_script.php b/app/actualize_script.php index deaa1bf7c..d4908d3ea 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -20,10 +20,6 @@ $_GET['ajax'] = 1; $_GET['force'] = true; $_SERVER['HTTP_HOST'] = ''; - -$log_file = join_path(USERS_PATH, '_', 'log.txt'); - - $app = new FreshRSS(); $system_conf = Minz_Configuration::get('system'); @@ -45,13 +41,13 @@ $min_last_activity = time() - $limits['max_inactivity']; foreach ($users as $user) { if (($user !== $system_conf->default_user) && (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) { - Minz_Log::notice('FreshRSS skip inactive user ' . $user, $log_file); + Minz_Log::notice('FreshRSS skip inactive user ' . $user, ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'FreshRSS skip inactive user ' . $user . "\n"); //Unbuffered } continue; } - Minz_Log::notice('FreshRSS actualize ' . $user, $log_file); + Minz_Log::notice('FreshRSS actualize ' . $user, ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'Actualize ' . $user . "...\n"); //Unbuffered } @@ -66,8 +62,7 @@ foreach ($users as $user) { if (!invalidateHttpCache()) { - Minz_Log::notice('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), - $log_file); + Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG); if (defined('STDERR')) { fwrite(STDERR, 'Write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n"); } @@ -75,7 +70,7 @@ foreach ($users as $user) { } -Minz_Log::notice('FreshRSS actualize done.', $log_file); +Minz_Log::notice('FreshRSS actualize done.', ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'Done.' . "\n"); $end_date = date_create('now'); diff --git a/constants.php b/constants.php index b48c1be96..576be09b9 100644 --- a/constants.php +++ b/constants.php @@ -8,8 +8,8 @@ define('FRESHRSS_USERAGENT', 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; // PHP text output compression http://php.net/ob_gzhandler (better to do it at Web server level) define('PHP_COMPRESSION', false); -// maximum log file size, before it will be purged (defaults to 512000 = 500kB) -define('MAX_LOG_SIZE', 512000); +// Maximum log file size in Bytes, before it will be divided by two +define('MAX_LOG_SIZE', 1048576); // Constantes de chemins define('FRESHRSS_PATH', dirname(__FILE__)); @@ -22,7 +22,10 @@ define('FRESHRSS_PATH', dirname(__FILE__)); define('DATA_PATH', FRESHRSS_PATH . '/data'); define('UPDATE_FILENAME', DATA_PATH . '/update.php'); define('USERS_PATH', DATA_PATH . '/users'); + define('ADMIN_LOG', USERS_PATH . '/_/log.txt'); + define('API_LOG', USERS_PATH . '/_/log_api.txt'); define('CACHE_PATH', DATA_PATH . '/cache'); + define('PSHB_LOG', USERS_PATH . '/_/log_pshb.txt'); define('PSHB_PATH', DATA_PATH . '/PubSubHubbub'); define('LIB_PATH', FRESHRSS_PATH . '/lib'); diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index 6231754fa..5e7831cdb 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -71,7 +71,7 @@ class Minz_Log { . ' [' . $level_label . ']' . ' --- ' . $information . "\n"; - self::checkLogfileSize($file_name); + self::ensureMaxLogSize($file_name); if (file_put_contents($file_name, $log, FILE_APPEND | LOCK_EX) === false) { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); @@ -88,12 +88,24 @@ class Minz_Log { * @param $file_name * @throws Minz_PermissionDeniedException */ - protected static function checkLogfileSize($file_name) { - $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 512000; - if (@filesize($file_name) > $maxSize) { - if (file_put_contents($file_name, '') === false) { + protected static function ensureMaxLogSize($file_name) { + $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576; + if ($maxSize > 0 && @filesize($file_name) > $maxSize) { + $fp = fopen($file_name, 'c+'); + if ($fp && flock($fp, LOCK_EX)) { + fseek($fp, -intval($maxSize / 2), SEEK_END); + $content = fread($fp, $maxSize); + rewind($fp); + ftruncate($fp, 0); + fwrite($fp, $content ? $content : ''); + fflush($fp); + flock($fp, LOCK_UN); + } else { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); } + if ($fp) { + fclose($fp); + } } } diff --git a/p/api/greader.php b/p/api/greader.php index f086ee442..b27f5bd43 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -78,10 +78,6 @@ class MyPDO extends Minz_ModelPdo { } } -function logMe($text) { - file_put_contents(join_path(USERS_PATH, '_', 'log_api.txt'), date('c') . "\t" . $text . "\n", FILE_APPEND); -} - function debugInfo() { if (function_exists('getallheaders')) { $ALL_HEADERS = getallheaders(); @@ -107,16 +103,14 @@ function debugInfo() { } function badRequest() { - logMe("badRequest()"); - logMe(debugInfo()); + Minz_Log::warning('badRequest() ' . debugInfo(), API_LOG); header('HTTP/1.1 400 Bad Request'); header('Content-Type: text/plain; charset=UTF-8'); die('Bad Request!'); } function unauthorized() { - logMe("unauthorized()"); - logMe(debugInfo()); + Minz_Log::warning('unauthorized() ' . debugInfo(), API_LOG); header('HTTP/1.1 401 Unauthorized'); header('Content-Type: text/plain; charset=UTF-8'); header('Google-Bad-Token: true'); @@ -124,22 +118,21 @@ function unauthorized() { } function notImplemented() { - logMe("notImplemented()"); - logMe(debugInfo()); + Minz_Log::warning('notImplemented() ' . debugInfo(), API_LOG); header('HTTP/1.1 501 Not Implemented'); header('Content-Type: text/plain; charset=UTF-8'); die('Not Implemented!'); } function serviceUnavailable() { - logMe("serviceUnavailable()"); + Minz_Log::warning('serviceUnavailable() ' . debugInfo(), API_LOG); header('HTTP/1.1 503 Service Unavailable'); header('Content-Type: text/plain; charset=UTF-8'); die('Service Unavailable!'); } function checkCompatibility() { - logMe("checkCompatibility()"); + Minz_Log::warning('checkCompatibility() ' . debugInfo(), API_LOG); header('Content-Type: text/plain; charset=UTF-8'); if (PHP_INT_SIZE < 8 && !function_exists('gmp_init')) { die('FAIL 64-bit or GMP extension!'); @@ -170,7 +163,7 @@ function authorizationToUser() { if ($headerAuthX[1] === sha1(FreshRSS_Context::$system_conf->salt . $user . FreshRSS_Context::$user_conf->apiPasswordHash)) { return $user; } else { - logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); + Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1], API_LOG); Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); unauthorized(); } @@ -183,7 +176,6 @@ function authorizationToUser() { } function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html - //logMe('clientLogin(' . $email . ")"); if (ctype_alnum($email)) { if (!function_exists('password_verify')) { include_once(LIB_PATH . '/password_compat.php'); @@ -215,7 +207,7 @@ function token($conf) { //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php $user = Minz_Session::param('currentUser', '_'); - //logMe('token('. $user . ")"); //TODO: Implement real token that expires + //Minz_Log::debug('token('. $user . ')', API_LOG); //TODO: Implement real token that expires $token = str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; exit(); @@ -224,7 +216,6 @@ function token($conf) { function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken $user = Minz_Session::param('currentUser', '_'); - //logMe('checkToken(' . $token . ")"); if ($token === str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { return true; } @@ -232,7 +223,6 @@ function checkToken($conf, $token) { } function userInfo() { //https://github.com/theoldreader/api#user-info - //logMe("userInfo()"); $user = Minz_Session::param('currentUser', '_'); exit(json_encode(array( 'userId' => $user, @@ -243,7 +233,6 @@ function userInfo() { //https://github.com/theoldreader/api#user-info } function tagList() { - //logMe("tagList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -268,7 +257,6 @@ function tagList() { } function subscriptionList() { - //logMe("subscriptionList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -303,7 +291,6 @@ function subscriptionList() { } function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '') { - //logMe("subscriptionEdit()"); //https://github.com/mihaip/google-reader-api/blob/master/wiki/ApiSubscriptionEdit.wiki switch ($action) { case 'subscribe': @@ -360,7 +347,7 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' $feed = FreshRSS_feed_Controller::addFeed($streamName, $title, $addCatId, $c_name, $http_auth); continue; } catch (Exception $e) { - logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + Minz_Log::error('subscriptionEdit error subscribe: ' . $e->getMessage(), API_LOG); } } badRequest(); @@ -389,7 +376,6 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' } function quickadd($url) { - //logMe("quickadd($url)"); try { $feed = FreshRSS_feed_Controller::addFeed($url); exit(json_encode(array( @@ -397,7 +383,7 @@ function quickadd($url) { 'streamId' => $feed->id(), ))); } catch (Exception $e) { - logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + Minz_Log::error('quickadd error: ' . $e->getMessage(), API_LOG); die(json_encode(array( 'numResults' => 0, 'error' => $e->getMessage(), @@ -406,7 +392,6 @@ function quickadd($url) { } function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count - //logMe("unreadCount()"); header('Content-Type: application/json; charset=UTF-8'); $totalUnreads = 0; @@ -453,7 +438,6 @@ function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-googl function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation) { //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed - //logMe("streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation)"); header('Content-Type: application/json; charset=UTF-8'); $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -562,8 +546,6 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed - //logMe("streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)"); - $type = 'A'; $id = ''; if ($streamId === 'user/-/state/com.google/reading-list') { @@ -610,8 +592,6 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude } function editTag($e_ids, $a, $r) { - //logMe("editTag()"); - foreach ($e_ids as $i => $e_id) { $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/' } @@ -645,7 +625,6 @@ function editTag($e_ids, $a, $r) { } function renameTag($s, $dest) { - //logMe("renameTag()"); if ($s != '' && strpos($s, 'user/-/label/') === 0 && $dest != '' && strpos($dest, 'user/-/label/') === 0) { $s = substr($s, 13); @@ -661,7 +640,6 @@ function renameTag($s, $dest) { } function disableTag($s) { - //logMe("disableTag($s)"); if ($s != '' && strpos($s, 'user/-/label/') === 0) { $s = substr($s, 13); $categoryDAO = new FreshRSS_CategoryDAO(); @@ -679,7 +657,6 @@ function disableTag($s) { } function markAllAsRead($streamId, $olderThanId) { - //logMe("markAllAsRead($streamId, $olderThanId)"); $entryDAO = FreshRSS_Factory::createEntryDao(); if (strpos($streamId, 'feed/') === 0) { $f_id = basename($streamId); @@ -696,8 +673,8 @@ function markAllAsRead($streamId, $olderThanId) { exit('OK'); } -//logMe('----------------------------------------------------------------'); -//logMe(debugInfo()); +//Minz_Log::debug('----------------------------------------------------------------', API_LOG); +//Minz_Log::debug(debugInfo(), API_LOG); $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']); $pathInfos = explode('/', $pathInfo); @@ -718,8 +695,6 @@ if ($user !== '') { FreshRSS_Context::$user_conf = get_user_configuration($user); } -//logMe('User => ' . $user); - Minz_Session::_param('currentUser', $user); if (count($pathInfos) < 3) { diff --git a/p/api/pshb.php b/p/api/pshb.php index ed8326cf5..578681cc4 100644 --- a/p/api/pshb.php +++ b/p/api/pshb.php @@ -2,18 +2,18 @@ require('../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -define('MAX_PAYLOAD', 3145728); +const MAX_PAYLOAD = 3145728; header('Content-Type: text/plain; charset=UTF-8'); header('X-Content-Type-Options: nosniff'); -function logMe($text) { - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); -} - $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, MAX_PAYLOAD); -//logMe(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true)); +Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); +$system_conf = Minz_Configuration::get('system'); +$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) + +//Minz_Log::debug(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true), PSHB_LOG); $key = isset($_GET['k']) ? substr($_GET['k'], 0, 128) : ''; if (!ctype_xdigit($key)) { @@ -24,31 +24,31 @@ chdir(PSHB_PATH); $canonical64 = @file_get_contents('keys/' . $key . '.txt'); if ($canonical64 === false) { if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'unsubscribe') { - logMe('Warning: Accept unknown unsubscribe'); + Minz_Log::warning('Warning: Accept unknown unsubscribe', PSHB_LOG); header('Connection: close'); exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : ''); } header('HTTP/1.1 404 Not Found'); - logMe('Warning: Feed key not found!: ' . $key); + Minz_Log::warning('Warning: Feed key not found!: ' . $key, PSHB_LOG); die('Feed key not found!'); } $canonical64 = trim($canonical64); if (!preg_match('/^[A-Za-z0-9_-]+$/D', $canonical64)) { header('HTTP/1.1 500 Internal Server Error'); - logMe('Error: Invalid key reference!: ' . $canonical64); + Minz_Log::error('Error: Invalid key reference!: ' . $canonical64, PSHB_LOG); die('Invalid key reference!'); } $hubFile = @file_get_contents('feeds/' . $canonical64 . '/!hub.json'); if ($hubFile === false) { header('HTTP/1.1 404 Not Found'); unlink('keys/' . $key . '.txt'); - logMe('Error: Feed info not found!: ' . $canonical64); + Minz_Log::error('Error: Feed info not found!: ' . $canonical64, PSHB_LOG); die('Feed info not found!'); } $hubJson = json_decode($hubFile, true); if (!$hubJson || empty($hubJson['key']) || $hubJson['key'] !== $key) { header('HTTP/1.1 500 Internal Server Error'); - logMe('Error: Invalid key cross-check!: ' . $key); + Minz_Log::error('Error: Invalid key cross-check!: ' . $key, PSHB_LOG); die('Invalid key cross-check!'); } chdir('feeds/' . $canonical64); @@ -56,7 +56,7 @@ $users = glob('*.txt', GLOB_NOSORT); if (empty($users)) { header('HTTP/1.1 410 Gone'); $url = base64url_decode($canonical64); - logMe('Warning: Nobody subscribes to this feed anymore!: ' . $url); + Minz_Log::warning('Warning: Nobody subscribes to this feed anymore!: ' . $url, PSHB_LOG); unlink('../../keys/' . $key . '.txt'); Minz_Configuration::register('system', DATA_PATH . '/config.php', @@ -101,10 +101,6 @@ if ($ORIGINAL_INPUT == '') { die('Missing XML payload!'); } -Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); -$system_conf = Minz_Configuration::get('system'); -$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) - $simplePie = customSimplePie(); $simplePie->set_raw_data($ORIGINAL_INPUT); $simplePie->init(); @@ -115,7 +111,7 @@ $self = isset($links[0]) ? $links[0] : null; if ($self !== base64url_decode($canonical64)) { //header('HTTP/1.1 422 Unprocessable Entity'); - logMe('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64)); + Minz_Log::warning('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64), PSHB_LOG); //die('Self URL does not match registered canonical URL!'); $self = base64url_decode($canonical64); } @@ -124,7 +120,7 @@ $nb = 0; foreach ($users as $userFilename) { $username = basename($userFilename, '.txt'); if (!file_exists(USERS_PATH . '/' . $username . '/config.php')) { - logMe('Warning: Removing broken user link: ' . $username . ' for ' . $self); + Minz_Log::warning('Warning: Removing broken user link: ' . $username . ' for ' . $self, PSHB_LOG); unlink($userFilename); continue; } @@ -140,11 +136,11 @@ foreach ($users as $userFilename) { if ($updated_feeds > 0 || $feed != false) { $nb++; } else { - logMe('Warning: User ' . $username . ' does not subscribe anymore to ' . $self); + Minz_Log::warning('Warning: User ' . $username . ' does not subscribe anymore to ' . $self, PSHB_LOG); unlink($userFilename); } } catch (Exception $e) { - logMe('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self); + Minz_Log::error('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self, PSHB_LOG); } } @@ -153,12 +149,12 @@ unset($simplePie); if ($nb === 0) { header('HTTP/1.1 410 Gone'); - logMe('Warning: Nobody subscribes to this feed anymore after all!: ' . $self); + Minz_Log::warning('Warning: Nobody subscribes to this feed anymore after all!: ' . $self, PSHB_LOG); die('Nobody subscribes to this feed anymore after all!'); } elseif (!empty($hubJson['error'])) { $hubJson['error'] = false; file_put_contents('./!hub.json', json_encode($hubJson)); } -logMe('PubSubHubbub ' . $self . ' done: ' . $nb); +Minz_Log::notice('PubSubHubbub ' . $self . ' done: ' . $nb, PSHB_LOG); exit('Done: ' . $nb . "\n"); -- cgit v1.2.3 From e399bc4b929b660908e60f1928014ae6445327f5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 17 Dec 2017 20:14:20 +0100 Subject: Remove warning for CURLOPT_FOLLOWLOCATION with open_basedir (#1734) For PHP 5.6.0- http://www.php.net/ChangeLog-5.php#5.6.0 https://bugs.php.net/bug.php?id=65646 https://github.com/FreshRSS/FreshRSS/pull/1733 https://github.com/FreshRSS/FreshRSS/pull/1657 https://github.com/FreshRSS/FreshRSS/issues/1655 --- app/Models/Feed.php | 4 +++- lib/favicons.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'app/Models') diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 75d9f6d6f..560f7415d 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -491,7 +491,9 @@ class FreshRSS_Feed extends Minz_Model { CURLOPT_USERAGENT => FRESHRSS_USERAGENT, CURLOPT_MAXREDIRS => 10, )); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir bug + if (version_compare(PHP_VERSION, '5.6.0') >= 0 || ini_get('open_basedir') == '') { + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir PHP bug 65646 + } if (defined('CURLOPT_ENCODING')) { curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings } diff --git a/lib/favicons.php b/lib/favicons.php index 75e40900a..fe2e65f1f 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -36,8 +36,8 @@ function downloadHttp(&$url, $curlOptions = array()) { CURLOPT_USERAGENT => FRESHRSS_USERAGENT, CURLOPT_MAXREDIRS => 10, )); - if (ini_get('open_basedir') == '') { // see PHP bug 65646 - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + if (version_compare(PHP_VERSION, '5.6.0') >= 0 || ini_get('open_basedir') == '') { + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir PHP bug 65646 } if (defined('CURLOPT_ENCODING')) { curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings -- cgit v1.2.3