Update vendor

This commit is contained in:
Frederic Guillot 2013-02-24 14:03:14 -05:00
parent f943bdddf2
commit a6324c47a0
3 changed files with 54 additions and 16 deletions

View File

@ -13,6 +13,16 @@ class Filter
public $ignored_tags = array(); public $ignored_tags = array();
public $allowed_tags = array( public $allowed_tags = array(
'dt' => array(),
'dd' => array(),
'dl' => array(),
'table' => array(),
'caption' => array(),
'tr' => array(),
'th' => array(),
'td' => array(),
'tbody' => array(),
'thead' => array(),
'h2' => array(), 'h2' => array(),
'h3' => array(), 'h3' => array(),
'h4' => array(), 'h4' => array(),
@ -63,6 +73,10 @@ class Filter
'img' => array('src') 'img' => array('src')
); );
public $add_attributes = array(
'a' => 'rel="noreferrer" target="_blank"'
);
public function __construct($data, $url) public function __construct($data, $url)
{ {
@ -150,6 +164,11 @@ class Filter
$this->data .= '<'.$name.$attr_data; $this->data .= '<'.$name.$attr_data;
if (isset($this->add_attributes[$name])) {
$this->data .= ' '.$this->add_attributes[$name].' ';
}
if ($name !== 'img' && $name !== 'br') $this->data .= '>'; if ($name !== 'img' && $name !== 'br') $this->data .= '>';
} }
} }

View File

@ -42,34 +42,42 @@ class Reader
} }
public function getParser() public function getFirstTag($data)
{ {
$first_lines = substr($this->content, 0, 1024); if (strpos($data, '<?xml') !== false) {
if (stripos($first_lines, 'html') !== false) { $data = substr($data, strrpos($data, '?>') + 2);
if ($this->discover()) { $open_tag = strpos($data, '<');
$close_tag = strpos($data, '>');
$first_lines = substr($this->content, 0, 1024); return substr($data, $open_tag, $close_tag);
}
else {
return false;
}
} }
if (strpos($first_lines, '<feed ') !== false) { return $data;
}
public function getParser($discover = false)
{
$first_tag = $this->getFirstTag($this->content);
if (strpos($first_tag, '<feed ') !== false) {
return new Atom($this->content); return new Atom($this->content);
} }
else if (strpos($first_lines, '<rss ') !== false && strpos($first_lines, 'version="2.0"') !== false) { else if (strpos($first_tag, '<rss ') !== false && strpos($first_tag, 'version="2.0"') !== false) {
return new Rss20($this->content); return new Rss20($this->content);
}/* }
else if (strpos($first_lines, '<rdf') !== false && strpos($first_lines, 'xmlns="http://purl.org/rss/1.0/"') !== false) { else if ($discover === true) {
return new Rss10($this->content); return false;
}*/ }
else if ($this->discover()) {
return $this->getParser(true);
}
return false; return false;
} }
@ -77,6 +85,11 @@ class Reader
public function discover() public function discover()
{ {
if (! $this->content) {
return false;
}
\libxml_use_internal_errors(true); \libxml_use_internal_errors(true);
$dom = new \DOMDocument; $dom = new \DOMDocument;

View File

@ -49,6 +49,12 @@ function flash_error($html)
} }
function get_host_from_url($url)
{
return escape(parse_url($url, PHP_URL_HOST));
}
function in_list($id, array $listing) function in_list($id, array $listing)
{ {
if (isset($listing[$id])) { if (isset($listing[$id])) {