aboutsummaryrefslogtreecommitdiff
path: root/lib/SimplePie
diff options
context:
space:
mode:
authorGravatar Alkarex <alexandre@alapetite.fr> 2013-12-23 13:22:50 +0100
committerGravatar Alkarex <alexandre@alapetite.fr> 2013-12-23 13:22:50 +0100
commit24d9d1628d673f68fa0cc7b98a3ef9a8d021b070 (patch)
tree2d794dc100d707e53b82a2de7d84b3d13103e461 /lib/SimplePie
parent75096e6a39fe5d34d3951991f296f616e62a9fd8 (diff)
parent9e46c1ee7fc7f9ad9e2c07f0cf826573dd4c9766 (diff)
Fusion 0.7-dev
Diffstat (limited to 'lib/SimplePie')
-rw-r--r--lib/SimplePie/SimplePie.php17
-rw-r--r--lib/SimplePie/SimplePie/Misc.php4
-rw-r--r--lib/SimplePie/SimplePie/Parser.php3
-rw-r--r--lib/SimplePie/SimplePie/Sanitize.php53
4 files changed, 68 insertions, 9 deletions
diff --git a/lib/SimplePie/SimplePie.php b/lib/SimplePie/SimplePie.php
index 9e532023a..d20ab5430 100644
--- a/lib/SimplePie/SimplePie.php
+++ b/lib/SimplePie/SimplePie.php
@@ -602,6 +602,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()
* @access private
@@ -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
*
diff --git a/lib/SimplePie/SimplePie/Misc.php b/lib/SimplePie/SimplePie/Misc.php
index 621f2c062..347520303 100644
--- a/lib/SimplePie/SimplePie/Misc.php
+++ b/lib/SimplePie/SimplePie/Misc.php
@@ -79,6 +79,10 @@ class SimplePie_Misc
public static function absolutize_url($relative, $base)
{
+ if (substr($relative, 0, 2) === '//') //FreshRSS: disable absolutize_url for "//www.example.net" which will pick HTTP or HTTPS automatically
+ {
+ return $relative;
+ }
$iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
if ($iri === false)
{
diff --git a/lib/SimplePie/SimplePie/Parser.php b/lib/SimplePie/SimplePie/Parser.php
index 72878c25a..c4c732787 100644
--- a/lib/SimplePie/SimplePie/Parser.php
+++ b/lib/SimplePie/SimplePie/Parser.php
@@ -132,7 +132,7 @@ class SimplePie_Parser
}
}
- try
+ try //FreshRSS
{
$dom = new DOMDocument();
$dom->recover = true;
@@ -140,7 +140,6 @@ class SimplePie_Parser
$dom->loadXML($data);
$this->encoding = $encoding = $dom->encoding = 'UTF-8';
$data = $dom->saveXML();
- //file_put_contents('/home/alex/public_html/alexandre.alapetite.fr/prive/FreshRSS/log/parser.log', date('c') . ' ' . 'OK' . "\n", FILE_APPEND);
}
catch (Exception $e)
{
diff --git a/lib/SimplePie/SimplePie/Sanitize.php b/lib/SimplePie/SimplePie/Sanitize.php
index 83a274ced..0974c150d 100644
--- a/lib/SimplePie/SimplePie/Sanitize.php
+++ b/lib/SimplePie/SimplePie/Sanitize.php
@@ -62,6 +62,7 @@ class SimplePie_Sanitize
var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
var $encode_instead_of_strip = false;
var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
+ var $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none')); //FreshRSS
var $strip_comments = false;
var $output_encoding = 'UTF-8';
var $enable_cache = true;
@@ -179,6 +180,25 @@ class SimplePie_Sanitize
}
}
+ public function add_attributes($attribs = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none')))
+ {
+ if ($attribs)
+ {
+ if (is_array($attribs))
+ {
+ $this->add_attributes = $attribs;
+ }
+ else
+ {
+ $this->add_attributes = explode(',', $attribs);
+ }
+ }
+ else
+ {
+ $this->add_attributes = false;
+ }
+ }
+
public function strip_comments($strip = false)
{
$this->strip_comments = (bool) $strip;
@@ -255,10 +275,11 @@ class SimplePie_Sanitize
$document->loadHTML($data);
restore_error_handler();
+ $xpath = new DOMXPath($document); //FreshRSS
+
// Strip comments
if ($this->strip_comments)
{
- $xpath = new DOMXPath($document);
$comments = $xpath->query('//comment()');
foreach ($comments as $comment)
@@ -274,7 +295,7 @@ class SimplePie_Sanitize
{
foreach ($this->strip_htmltags as $tag)
{
- $this->strip_tag($tag, $document, $type);
+ $this->strip_tag($tag, $document, $xpath, $type);
}
}
@@ -282,7 +303,15 @@ class SimplePie_Sanitize
{
foreach ($this->strip_attributes as $attrib)
{
- $this->strip_attr($attrib, $document);
+ $this->strip_attr($attrib, $xpath);
+ }
+ }
+
+ if ($this->add_attributes)
+ {
+ foreach ($this->add_attributes as $tag => $valuePairs)
+ {
+ $this->add_attr($tag, $valuePairs, $document);
}
}
@@ -452,9 +481,8 @@ class SimplePie_Sanitize
}
}
- protected function strip_tag($tag, $document, $type)
+ protected function strip_tag($tag, $document, $xpath, $type)
{
- $xpath = new DOMXPath($document);
$elements = $xpath->query('body//' . $tag);
if ($this->encode_instead_of_strip)
{
@@ -537,9 +565,8 @@ class SimplePie_Sanitize
}
}
- protected function strip_attr($attrib, $document)
+ protected function strip_attr($attrib, $xpath)
{
- $xpath = new DOMXPath($document);
$elements = $xpath->query('//*[@' . $attrib . ']');
foreach ($elements as $element)
@@ -547,4 +574,16 @@ class SimplePie_Sanitize
$element->removeAttribute($attrib);
}
}
+
+ protected function add_attr($tag, $valuePairs, $document)
+ {
+ $elements = $document->getElementsByTagName($tag);
+ foreach ($elements as $element)
+ {
+ foreach ($valuePairs as $attrib => $value)
+ {
+ $element->setAttribute($attrib, $value);
+ }
+ }
+ }
}