summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre.alapetite@alexandra.dk> 2015-07-23 14:28:44 +0200
committerGravatar Alexandre Alapetite <alexandre.alapetite@alexandra.dk> 2015-07-23 14:28:44 +0200
commit2f2facac300b95021406085d5d1701e001a0af65 (patch)
treee112184b03d01c5bcd2382d91f88505f48dd9f6d
parente8929e868bd84fda117a99ac7d744a60450aecb6 (diff)
parent7242806c309afdc38a0b5fa165a2a00f87292c9d (diff)
Merge branch 'FreshRSS/dev' into dev
-rwxr-xr-xapp/Controllers/feedController.php9
-rw-r--r--app/install.php4
-rw-r--r--data/config.default.php4
-rw-r--r--lib/lib_rss.php27
4 files changed, 41 insertions, 3 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 488d066a9..ec3dce777 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -295,14 +295,17 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
// Calculate date of oldest entries we accept in DB.
$nb_month_old = max(FreshRSS_Context::$user_conf->old_entries, 1);
$date_min = time() - (3600 * 24 * 30 * $nb_month_old);
- $pshbMinAge = time() - (3600 * 24); //TODO: Make a configuration.
+
+ // PubSubHubbub support
+ $pubsubhubbubEnabledGeneral = FreshRSS_Context::$system_conf->pubsubhubbub_enabled;
+ $pshbMinAge = time() - (3600 * 24); //TODO: Make a configuration.
$updated_feeds = 0;
$is_read = FreshRSS_Context::$user_conf->mark_when['reception'] ? 1 : 0;
foreach ($feeds as $feed) {
$url = $feed->url(); //For detection of HTTP 301
- $pubSubHubbubEnabled = $feed->pubSubHubbubEnabled();
+ $pubSubHubbubEnabled = $pubsubhubbubEnabledGeneral && $feed->pubSubHubbubEnabled();
if ((!$simplePiePush) && (!$id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) {
$text = 'Skip pull of feed using PubSubHubbub: ' . $url;
//Minz_Log::debug($text);
@@ -442,7 +445,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
$feed->faviconPrepare();
- if ($feed->pubSubHubbubPrepare()) {
+ if ($pubsubhubbubEnabledGeneral && $feed->pubSubHubbubPrepare()) {
Minz_Log::notice('PubSubHubbub subscribe ' . $feed->url());
if (!$feed->pubSubHubbubSubscribe(true)) { //Subscribe
Minz_Log::warning('Error while PubSubHubbub subscribing to ' . $feed->url());
diff --git a/app/install.php b/app/install.php
index d5455f17d..5a774d7c1 100644
--- a/app/install.php
+++ b/app/install.php
@@ -212,8 +212,11 @@ function saveStep3() {
$_SESSION['bd_prefix_user'] = $_SESSION['bd_prefix'] . (empty($_SESSION['default_user']) ? '' : ($_SESSION['default_user'] . '_'));
}
+ // We use dirname to remove the /i part
+ $base_url = dirname(Minz_Request::guessBaseUrl());
$config_array = array(
'salt' => $_SESSION['salt'],
+ 'base_url' => $base_url,
'title' => $_SESSION['title'],
'default_user' => $_SESSION['default_user'],
'auth_type' => $_SESSION['auth_type'],
@@ -226,6 +229,7 @@ function saveStep3() {
'prefix' => $_SESSION['bd_prefix'],
'pdo_options' => array(),
),
+ 'pubsubhubbub_enabled' => server_is_public($base_url),
);
@unlink(join_path(DATA_PATH, 'config.php')); //To avoid access-rights problems
diff --git a/data/config.default.php b/data/config.default.php
index 5db933ff8..a7a29b12c 100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@ -57,6 +57,10 @@ return array(
# SimplePie, which is retrieving RSS feeds via HTTP requests.
'simplepie_syslog_enabled' => true,
+ # Enable or not support of PubSubHubbub.
+ # /!\ It should NOT be enabled if base_url is not reachable by an external server.
+ 'pubsubhubbub_enabled' => false,
+
'limits' => array(
# Duration in seconds of the SimplePie cache,
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index c99e2c7e8..2a23fca45 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -83,6 +83,33 @@ function checkUrl($url) {
}
}
+
+/**
+ * Test if a given server address is publicly accessible.
+ *
+ * Note: for the moment it tests only if address is corresponding to a
+ * localhost address.
+ *
+ * @param $address the address to test, can be an IP or a URL.
+ * @return true if server is accessible, false else.
+ * @todo improve test with a more valid technique (e.g. test with an external server?)
+ */
+function server_is_public($address) {
+ $host = parse_url($address, PHP_URL_HOST);
+
+ $is_public = !in_array($host, array(
+ '127.0.0.1',
+ 'localhost',
+ 'localhost.localdomain',
+ '[::1]',
+ 'localhost6',
+ 'localhost6.localdomain6',
+ ));
+
+ return $is_public;
+}
+
+
function format_number($n, $precision = 0) {
// number_format does not seem to be Unicode-compatible
return str_replace(' ', ' ', //Espace fine insécable