Skip to content

Commit

Permalink
Add some per-feed options
Browse files Browse the repository at this point in the history
* Feed cURL timeout
* Mark updated articles as read
* Mark as read upon reception
FreshRSS#1702
* Ignore SSL (unsafe) FreshRSS#1811
  • Loading branch information
Alkarex committed Apr 29, 2018
1 parent 4ce4952 commit a5daab7
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 13 deletions.
12 changes: 7 additions & 5 deletions app/Controllers/feedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ public static function actualizeFeed($feed_id, $feed_url, $force, $simplePiePush

$updated_feeds = 0;
$nb_new_articles = 0;
$is_read = FreshRSS_Context::$user_conf->mark_when['reception'] ? 1 : 0;
foreach ($feeds as $feed) {
$url = $feed->url(); //For detection of HTTP 301

Expand Down Expand Up @@ -354,8 +353,9 @@ public static function actualizeFeed($feed_id, $feed_url, $force, $simplePiePush
} else { //This entry already exists but has been updated
//Minz_Log::debug('Entry with GUID `' . $entry->guid() . '` updated in feed ' . $feed->id() .
//', old hash ' . $existingHash . ', new hash ' . $entry->hash());
//TODO: Make an updated/is_read policy by feed, in addition to the global one.
$needFeedCacheRefresh = FreshRSS_Context::$user_conf->mark_updated_article_unread;
$mark_updated_article_unread = $feed->$attributes['mark_updated_article_unread'] !== null ? $feed->$attributes['mark_updated_article_unread'] :
FreshRSS_Context::$user_conf->mark_updated_article_unread;
$needFeedCacheRefresh = $mark_updated_article_unread;
$entry->_isRead(FreshRSS_Context::$user_conf->mark_updated_article_unread ? false : null); //Change is_read according to policy.
if (!$entryDAO->inTransaction()) {
$entryDAO->beginTransaction();
Expand All @@ -366,15 +366,17 @@ public static function actualizeFeed($feed_id, $feed_url, $force, $simplePiePush
// This entry should not be added considering configuration and date.
$oldGuids[] = $entry->guid();
} else {
$read_upon_reception = $feed->$attributes['read_upon_reception'] !== null ? $feed->$attributes['read_upon_reception'] :
FreshRSS_Context::$user_conf->mark_when['reception'];
if ($isNewFeed) {
$id = min(time(), $entry_date) . uSecString();
$entry->_isRead($is_read);
$entry->_isRead($read_upon_reception);
} elseif ($entry_date < $date_min) {
$id = min(time(), $entry_date) . uSecString();
$entry->_isRead(true); //Old article that was not in database. Probably an error, so mark as read
} else {
$id = uTimeString();
$entry->_isRead($is_read);
$entry->_isRead($read_upon_reception);
}
$entry->_id($id);

Expand Down
17 changes: 13 additions & 4 deletions app/Controllers/subscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ public function feedAction() {
return;
}

$this->view->feed = $this->view->feeds[$id];
$feed = $this->view->feeds[$id];
$this->view->feed = $feed;

Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $this->view->feed->name() . ' · ');
Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $feed->name() . ' · ');

if (Minz_Request::isPost()) {
$user = trim(Minz_Request::param('http_user_feed' . $id, ''));
Expand All @@ -95,6 +96,13 @@ public function feedAction() {
$ttl = FreshRSS_Context::$user_conf->ttl_default;
}

$feed->_attributes('mark_updated_article_unread', Minz_Request::paramTernary('mark_updated_article_unread'));
$feed->_attributes('read_upon_reception', Minz_Request::paramTernary('read_upon_reception'));
$feed->_attributes('ssl_verify', Minz_Request::paramTernary('ssl_verify'));

$timeout = intval(Minz_Request::param('timeout', 0));
$feed->_attributes('timeout', $timeout > 0 ? $timeout : null);

$values = array(
'name' => Minz_Request::param('name', ''),
'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
Expand All @@ -106,14 +114,15 @@ public function feedAction() {
'httpAuth' => $httpAuth,
'keep_history' => intval(Minz_Request::param('keep_history', FreshRSS_Feed::KEEP_HISTORY_DEFAULT)),
'ttl' => $ttl * ($mute ? -1 : 1),
'attributes' => $feed->attributes()
);

invalidateHttpCache();

$url_redirect = array('c' => 'subscription', 'params' => array('id' => $id));
if ($feedDAO->updateFeed($id, $values) !== false) {
$this->view->feed->_category($cat);
$this->view->feed->faviconPrepare();
$feed->_category($cat);
$feed->faviconPrepare();

Minz_Request::good(_t('feedback.sub.feed.updated'), $url_redirect);
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function load($loadDetails = false, $noCache = false) {
if ($this->httpAuth != '') {
$url = preg_replace('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $url);
}
$feed = customSimplePie();
$feed = customSimplePie($feed->attributes());
if (substr($url, -11) === '#force_feed') {
$feed->force_feed(true);
$url = substr($url, 0, -11);
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/cz/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'Zobrazit ve “Všechny kanály”',
'normal' => 'Show in its category', // TODO
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'Statistika',
'think_to_add' => 'Můžete přidat kanály.',
'timeout' => 'Timeout in seconds', //TODO
'title' => 'Název',
'title_add' => 'Přidat RSS kanál',
'ttl' => 'Neobnovovat častěji než',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/de/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'In Haupt-Feeds zeigen',
'normal' => 'Zeige in eigener Kategorie',
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'Statistiken',
'think_to_add' => 'Sie können Feeds hinzufügen.',
'timeout' => 'Timeout in seconds', //TODO
'title' => 'Titel',
'title_add' => 'Einen RSS-Feed hinzufügen',
'ttl' => 'Aktualisiere automatisch nicht öfter als',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/en/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'Show in main stream',
'normal' => 'Show in its category',
),
'ssl_verify' => 'Verify SSL security',
'stats' => 'Statistics',
'think_to_add' => 'You may add some feeds.',
'timeout' => 'Timeout in seconds',
'title' => 'Title',
'title_add' => 'Add a RSS feed',
'ttl' => 'Do not automatically refresh more often than',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/es/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
'main_stream' => 'Mostrar en salida principal',
'normal' => 'Show in its category', // TODO
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'Estadísticas',
'think_to_add' => 'Puedes añadir fuentes.',
'timeout' => 'Timeout in seconds', //TODO
'title' => 'Título',
'title_add' => 'Añadir fuente RSS',
'ttl' => 'No actualizar de forma automática con una frecuencia mayor a',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/fr/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'Afficher dans le flux principal',
'normal' => 'Afficher dans sa catégorie',
),
'ssl_verify' => 'Vérification sécurité SSL',
'stats' => 'Statistiques',
'think_to_add' => 'Vous pouvez ajouter des flux.',
'timeout' => 'Délai d’attente en secondes',
'title' => 'Titre',
'title_add' => 'Ajouter un flux RSS',
'ttl' => 'Ne pas automatiquement rafraîchir plus souvent que',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/he/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'הצגה בזרם המרכזי',
'normal' => 'Show in its category', // TODO
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'סטטיסטיקות',
'think_to_add' => 'ניתן להוסיף הזנות חדשות.',
'timeout' => 'Timeout in seconds', //TODO
'title' => 'כותרת',
'title_add' => 'הוספת הזנה',
'ttl' => 'אין לרענן אוטומטית יותר מ',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/it/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'Mostra in homepage', // TODO
'normal' => 'Show in its category', // TODO
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'Statistiche',
'think_to_add' => 'Aggiungi feed.',
'timeout' => 'Timeout in seconds', //TODO
'title' => 'Titolo',
'title_add' => 'Aggiungi RSS feed',
'ttl' => 'Non aggiornare automaticamente piu di',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/kr/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => '메인 스트림에 표시하기',
'normal' => '피드가 속한 카테고리에만 표시하기',
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => '통계',
'think_to_add' => '피드를 추가할 수 있습니다.',
'timeout' => 'Timeout in seconds', //TODO
'title' => '제목',
'title_add' => 'RSS 피드 추가',
'ttl' => '다음 시간이 지나기 전에 새로고침 금지',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/nl/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
'normal' => 'Show in its category', // TODO
),
'pubsubhubbub' => 'Directe notificaties met PubSubHubbub',
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'Statistieken',
'think_to_add' => 'Voeg wat feeds toe.',
'timeout' => 'Timeout in seconds', //TODO
'title' => 'Titel',
'title_add' => 'Voeg een RSS feed toe',
'ttl' => 'Vernieuw automatisch niet vaker dan',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/pt-br/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'Mostrar na tela principal',
'normal' => 'Show in its category', // TODO
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'Estatísticas',
'think_to_add' => 'Você deve adicionar alguns feeds.',
'timeout' => 'Timeout in seconds', //TODO
'title' => 'Título',
'title_add' => 'Adicionar o RSS feed',
'ttl' => 'Não atualize automáticamente mais que',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/ru/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'Show in main stream', // TODO
'normal' => 'Show in its category', // TODO
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'Statistics',// TODO
'think_to_add' => 'You may add some feeds.',// TODO
'timeout' => 'Timeout in seconds', //TODO
'title' => 'Title',// TODO
'title_add' => 'Add a RSS feed',// TODO
'ttl' => 'Do not automatically refresh more often than',// TODO
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/tr/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => 'Ana akışda göster',
'normal' => 'Show in its category', // TODO
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => 'İstatistikler',
'think_to_add' => 'Akış ekleyebilirsiniz.',
'timeout' => 'Timeout in seconds', //TODO
'title' => 'Başlık',
'title_add' => 'RSS akışı ekle',
'ttl' => 'Şu kadar süreden fazla otomatik yenileme yapma',
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/zh-cn/sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
'main_stream' => '在首页中显示',
'normal' => '在分类中显示',
),
'ssl_verify' => 'Verify SSL security', //TODO
'stats' => '统计',
'think_to_add' => '你可以添加一些 RSS 源。',
'timeout' => 'Timeout in seconds', //TODO
'title' => '标题',
'title_add' => '添加 RSS 源',
'ttl' => '最小自动更新时间',
Expand Down
47 changes: 47 additions & 0 deletions app/views/helpers/feed/update.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,53 @@
</div>
</div>

<div class="form-group">
<label class="group-name" for="mark_updated_article_unread"><?php echo _t('conf.reading.mark_updated_article_unread'); ?></label>
<div class="group-controls">
<label class="checkbox" for="mark_updated_article_unread">
<select name="mark_updated_article_unread" id="mark_updated_article_unread">
<option value=""<?php echo $this->feed->attributes('mark_updated_article_unread') === null ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.by_default'); ?></option>
<option value="0"<?php echo $this->feed->attributes('mark_updated_article_unread') === false ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.no'); ?></option>
<option value="1"<?php echo $this->feed->attributes('mark_updated_article_unread') === true ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.yes'); ?></option>
</select>
</label>
</div>
</div>

<div class="form-group">
<label class="group-name" for="read_upon_reception"><?php echo _t('conf.reading.read.when'); ?></label>
<div class="group-controls">
<label class="checkbox" for="read_upon_reception">
<select name="read_upon_reception" id="read_upon_reception">
<option value=""<?php echo $this->feed->attributes('read_upon_reception') === null ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.by_default'); ?></option>
<option value="0"<?php echo $this->feed->attributes('read_upon_reception') === false ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.no'); ?></option>
<option value="1"<?php echo $this->feed->attributes('read_upon_reception') === true ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.yes'); ?></option>
</select>
<?php echo _t('conf.reading.read.upon_reception'); ?>
</label>
</div>
</div>

<div class="form-group">
<label class="group-name" for="timeout"><?php echo _t('sub.feed.timeout'); ?></label>
<div class="group-controls">
<input type="number" name="timeout" id="timeout" min="3" max="120" value="<?php echo $this->feed->attributes('timeout'); ?>" placeholder="<?php echo _t('gen.short.blank_to_disable'); ?>" />
</div>
</div>

<div class="form-group">
<label class="group-name" for="ssl_verify"><?php echo _t('sub.feed.ssl_verify'); ?></label>
<div class="group-controls">
<label class="checkbox" for="ssl_verify">
<select name="ssl_verify" id="ssl_verify">
<option value=""<?php echo $this->feed->attributes('ssl_verify') === null ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.by_default'); ?></option>
<option value="0"<?php echo $this->feed->attributes('ssl_verify') === false ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.no'); ?></option>
<option value="1"<?php echo $this->feed->attributes('ssl_verify') === true ? ' selected="selected"' : ''; ?>><?php echo _t('gen.short.yes'); ?></option>
</select>
</label>
</div>
</div>

<div class="form-group form-actions">
<div class="group-controls">
<button type="submit" class="btn btn-important"><?php echo _t('gen.action.submit'); ?></button>
Expand Down
13 changes: 13 additions & 0 deletions lib/Minz/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ public static function param($key, $default = false, $specialchars = false) {
return $default;
}
}
public static function paramTernary($key) {
if (isset(self::$params[$key])) {
$p = self::$params[$key];
$tp = trim($p);
if ($p === null || $tp === '' || $tp === 'null') {
return null;
} elseif ($p == false || $tp == '0' || $tp === 'false' || $tp === 'no') {
return false;
}
return true;
}
return null;
}
public static function defaultControllerName() {
return self::$default_controller_name;
}
Expand Down
15 changes: 12 additions & 3 deletions lib/lib_rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,25 @@ function html_only_entity_decode($text) {
return strtr($text, $htmlEntitiesOnly);
}

function customSimplePie() {
function customSimplePie($attributes = array()) {
$system_conf = Minz_Configuration::get('system');
$limits = $system_conf->limits;
$simplePie = new SimplePie();
$simplePie->set_useragent(FRESHRSS_USERAGENT);
$simplePie->set_syslog($system_conf->simplepie_syslog_enabled);
$simplePie->set_cache_location(CACHE_PATH);
$simplePie->set_cache_duration($limits['cache_duration']);
$simplePie->set_timeout($limits['timeout']);
$simplePie->set_curl_options($system_conf->curl_options);

$feed_timeout = empty($attributes['timeout']) ? 0 : intval($attributes['timeout']);
$simplePie->set_timeout($feed_timeout > 0 ? $feed_timeout : $limits['timeout']);

$curl_options = $system_conf->curl_options;
if (isset($attributes['ssl_verify'])) {
$curl_options[CURLOPT_SSL_VERIFYHOST] = $attributes['ssl_verify'] ? 2 : 0;
$curl_options[CURLOPT_SSL_VERIFYPEER] = $attributes['ssl_verify'] ? true : false;
}
$simplePie->set_curl_options($curl_options);

$simplePie->strip_htmltags(array(
'base', 'blink', 'body', 'doctype', 'embed',
'font', 'form', 'frame', 'frameset', 'html',
Expand Down

0 comments on commit a5daab7

Please sign in to comment.