Просмотр исходного кода

Resource-priorities

Prépare http://www.w3.org/TR/resource-priorities/
https://github.com/marienfressinaud/FreshRSS/issues/316
https://github.com/marienfressinaud/FreshRSS/issues/313
Continue https://github.com/marienfressinaud/FreshRSS/issues/188
https://github.com/marienfressinaud/FreshRSS/commit/e45357a91b9aa47d5b7ead14c174dc7c98ab9926
Alexandre Alapetite 12 лет назад
Родитель
Сommit
25fa654529
2 измененных файлов с 23 добавлено и 0 удалено
  1. 6 0
      app/models/Feed.php
  2. 17 0
      lib/SimplePie/SimplePie.php

+ 6 - 0
app/models/Feed.php

@@ -213,6 +213,12 @@ class Feed extends Model {
 					'autoplay', 'onload', 'onunload', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup',
 					'onmouseover', 'onmousemove', 'onmouseout', 'onfocus', 'onblur',
 					'onkeypress', 'onkeydown', 'onkeyup', 'onselect', 'onchange', 'seamless')));
+				$feed->add_attributes(array(
+					'img' => array('lazyload' => ''),	//http://www.w3.org/TR/resource-priorities/
+					'audio' => array('preload' => 'none'),
+					'iframe' => array('postpone' => '', 'sandbox' => 'allow-scripts allow-same-origin'),
+					'video' => array('postpone' => '', 'preload' => 'none'),
+				));
 				$feed->set_url_replacements(array(
 					'a' => 'href',
 					'area' => 'href',

+ 17 - 0
lib/SimplePie/SimplePie.php

@@ -601,6 +601,13 @@ class SimplePie
 	 */
 	public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
 
+	/**
+	 * @var array Stores the default attributes to add to differet tags by add_attributes().
+	 * @see SimplePie::add_attributes()
+	 * @access private
+	 */
+	public $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none'));	//FreshRSS
+
 	/**
 	 * @var array Stores the default tags to be stripped by strip_htmltags().
 	 * @see SimplePie::strip_htmltags()
@@ -1073,6 +1080,7 @@ class SimplePie
 			$this->strip_comments(false);
 			$this->strip_htmltags(false);
 			$this->strip_attributes(false);
+			$this->add_attributes(false);
 			$this->set_image_handler(false);
 		}
 	}
@@ -1119,6 +1127,15 @@ class SimplePie
 		$this->sanitize->strip_attributes($attribs);
 	}
 
+	public function add_attributes($attribs = '')
+	{
+		if ($attribs === '')
+		{
+			$attribs = $this->add_attributes;
+		}
+		$this->sanitize->add_attributes($attribs);
+	}
+
 	/**
 	 * Set the output encoding
 	 *