Ver código fonte

Add a content action parameter to work with CSS selector (#3453)

Before, when retrieving article contents with CSS selector, the content
of the RSS feed was replaced by the content of the CSS selector. It works
well in most of the cases but if there is a different content in the feed
and in the selector, the former is lost.
Now, there is a parameter to decide which action is performed after retrieving
the content. By default, the previous behavior is kept. But now, it is
possible to append or prepend the CSS selector content to the feed content.

See #3451
Alexis Degrugillier 5 anos atrás
pai
commit
fe1fba9828

+ 2 - 0
app/Controllers/subscriptionController.php

@@ -125,6 +125,8 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
 			}
 			$feed->_attributes('curl_params', empty($opts) ? null : $opts);
 
+			$feed->_attributes('content_action', Minz_Request::param('content_action', 'replace'));
+
 			if (FreshRSS_Auth::hasAccess('admin')) {
 				$feed->_attributes('ssl_verify', Minz_Request::paramTernary('ssl_verify'));
 				$timeout = intval(Minz_Request::param('timeout', 0));

+ 14 - 2
app/Models/Entry.php

@@ -446,8 +446,20 @@ class FreshRSS_Entry extends Minz_Model {
 						$feed->pathEntries(),
 						$feed->attributes()
 					);
-					if ($fullContent != '') {
-						$this->content = $fullContent;
+					if ('' !== $fullContent) {
+						switch ($feed->attributes('content_action')) {
+							case 'prepend':
+								$this->content = $fullContent . $this->content();
+								break;
+							case 'append':
+								$this->content = $this->content() . $fullContent;
+								break;
+							case 'replace':
+							default:
+								$this->content = $fullContent;
+								break;
+						}
+
 						return true;
 					}
 				} catch (Exception $e) {

+ 6 - 0
app/i18n/cz/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'Přihlašovací jméno',
 		),
 		'clear_cache' => 'Always clear cache',	// TODO - Translation
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Stáhne zkrácenou verzi RSS kanálů (pozor, náročnější na čas!)',

+ 6 - 0
app/i18n/de/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP-Nutzername',
 		),
 		'clear_cache' => 'Nicht cachen (für defekte Feeds)',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Verwende Cookies beim Herunterladen des Feed-Inhalts mit CSS-Filtern',
 		'css_cookie_help' => 'Beispiel: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',
 		'css_help' => 'Ruft bei gekürzten RSS-Feeds den vollständigen Artikelinhalt ab (Achtung, benötigt mehr Zeit!)',

+ 6 - 0
app/i18n/en-us/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP username',
 		),
 		'clear_cache' => 'Always clear cache',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',
+			'append' => 'Add after existing content',
+			'prepend' => 'Add before existing content',
+			'replace' => 'Replace existing content',
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',
 		'css_help' => 'Retrieves truncated RSS feeds (caution, requires more time!)',

+ 6 - 0
app/i18n/en/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP username',
 		),
 		'clear_cache' => 'Always clear cache',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',
+			'append' => 'Add after existing content',
+			'prepend' => 'Add before existing content',
+			'replace' => 'Replace existing content',
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',
 		'css_help' => 'Retrieves truncated RSS feeds (caution, requires more time!)',

+ 6 - 0
app/i18n/es/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'Nombre de usuario HTTP',
 		),
 		'clear_cache' => 'Always clear cache',	// TODO - Translation
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Recibir fuentes RSS truncadas (aviso, ¡necesita más tiempo!)',

+ 6 - 0
app/i18n/fr/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'Identifiant HTTP',
 		),
 		'clear_cache' => 'Toujours vider le cache',
+		'content_action' => array(
+			'_' => 'Action à effectuer pour la réception du contenu des articles',
+			'append' => 'Ajouter après le contenu existant',
+			'prepend' => 'Ajouter avant le contenu existant',
+			'replace' => 'Remplacer le contenu existant',
+		),
 		'css_cookie' => 'Utiliser des cookies pour la réception du contenu des articles',
 		'css_cookie_help' => 'Exemple : <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',
 		'css_help' => 'Permet de récupérer les flux tronqués (attention, demande plus de temps !)',

+ 6 - 0
app/i18n/he/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP שם משתמש',
 		),
 		'clear_cache' => 'Always clear cache',	// TODO - Translation
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'קבלת הזנות RSS קטומות	(זהירות, לוקח זמן רב יותר!)',

+ 6 - 0
app/i18n/it/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP username',	// TODO - Translation
 		),
 		'clear_cache' => 'Always clear cache',	// TODO - Translation
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'In caso di RSS feeds troncati (attenzione, richiede molto tempo!)',

+ 6 - 0
app/i18n/kr/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP 사용자 이름',
 		),
 		'clear_cache' => '항상 캐시 지우기',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => '글의 일부가 포함된 RSS 피드를 가져옵니다 (주의, 시간이 좀 더 걸립니다!)',

+ 6 - 0
app/i18n/nl/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP gebruikers naam',
 		),
 		'clear_cache' => 'Cache altijd leegmaken',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Haalt onvolledige RSS-feeds op (attentie, heeft meer tijd nodig!)',

+ 6 - 0
app/i18n/oc/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'Identificant HTTP',
 		),
 		'clear_cache' => 'Totjorn escafar lo cache',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Permet de recuperar los fluxes troncats (atencion, demanda mai de temps !)',

+ 6 - 0
app/i18n/pl/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'Użytkownik HTTP',
 		),
 		'clear_cache' => 'Zawsze czyść pamięć podręczną',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Pozwala na ograniczenie zawartości kanałów (uwaga, wymaga więcej czasu!)',

+ 6 - 0
app/i18n/pt-br/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'Usuário HTTP',
 		),
 		'clear_cache' => 'Sempre limpar o cache',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Retorna RSS feeds truncados (atenção, requer mais tempo!)',

+ 6 - 0
app/i18n/ru/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP username',	// TODO - Translation
 		),
 		'clear_cache' => 'Always clear cache',	// TODO - Translation
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Retrieves truncated RSS feeds (caution, requires more time!)',	// TODO - Translation

+ 6 - 0
app/i18n/sk/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'Používateľské meno pre HTTP',
 		),
 		'clear_cache' => 'Vždy vymazať vyrovnávaciu pamäť',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Stiahnuť skrátenú verziu RSS kanála (pozor, vyžaduje viac času!)',

+ 6 - 0
app/i18n/tr/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP kullanıcı adı',
 		),
 		'clear_cache' => 'Always clear cache',	// TODO - Translation
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => 'Dikkat, daha çok zaman gerekir!',

+ 6 - 0
app/i18n/zh-cn/sub.php

@@ -33,6 +33,12 @@ return array(
 			'username' => 'HTTP 用户名',
 		),
 		'clear_cache' => '总是清除缓存',
+		'content_action' => array(
+			'_' => 'Content action when fetching the article content',	// TODO - Translation
+			'append' => 'Add after existing content',	// TODO - Translation
+			'prepend' => 'Add before existing content',	// TODO - Translation
+			'replace' => 'Replace existing content',	// TODO - Translation
+		),
 		'css_cookie' => 'Use Cookies when fetching the article content',	// TODO - Translation
 		'css_cookie_help' => 'Example: <kbd>foo=bar; gdpr_consent=true; cookie=value</kbd>',	// TODO - Translation
 		'css_help' => '用于获取全文(注意,这将耗费更多时间!)',

+ 11 - 0
app/views/helpers/feed/update.phtml

@@ -299,6 +299,17 @@
 			</div>
 		</div>
 
+		<div class="form-group">
+			<label class="group-name" for="content_action"><?= _t('sub.feed.content_action') ?></label>
+			<div class="group-controls">
+				<select name="content_action" id="content_action">
+					<option value="replace"<?= 'replace' === $this->feed->attributes('content_action') ? ' selected="selected"' : '' ?>><?= _t('sub.feed.content_action.replace') ?></option>
+					<option value="prepend"<?= 'prepend' === $this->feed->attributes('content_action') ? ' selected="selected"' : '' ?>><?= _t('sub.feed.content_action.prepend') ?></option>
+					<option value="append"<?= 'append' === $this->feed->attributes('content_action') ? ' selected="selected"' : '' ?>><?= _t('sub.feed.content_action.append') ?></option>
+				</select>
+			</div>
+		</div>
+
 		<div class="form-group">
 			<label class="group-name" for="path_entries"><?= _t('sub.feed.proxy') ?></label>
 			<div class="group-controls">

+ 4 - 0
cli/i18n/ignore/en-us.php

@@ -712,6 +712,10 @@ return array(
 	'sub.feed.auth.password',
 	'sub.feed.auth.username',
 	'sub.feed.clear_cache',
+	'sub.feed.content_action._',
+	'sub.feed.content_action.append',
+	'sub.feed.content_action.prepend',
+	'sub.feed.content_action.replace',
 	'sub.feed.css_cookie',
 	'sub.feed.css_cookie_help',
 	'sub.feed.css_help',