Skip to content

Commit

Permalink
Une bonne fois pour toutes : fix des XML qui sont merdiques !
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Jul 11, 2014
1 parent 5e054c9 commit 515cbf1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
15 changes: 15 additions & 0 deletions inc/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,21 @@ public static function look_for($value, $where = 'search')
return $res;
}

/**
* Retrieve data from XML file.
*/
public static function load_xml($link)
{
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML(Fct::load_url($link));
if ( is_null($doc) || !is_object($doc) ) {
//~ Fct::__($doc);
return false;
}
return $doc;
}

}

?>
42 changes: 16 additions & 26 deletions inc/Solver.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ public static function bonjourmadame($link)
if ( count($parts) < 4 ) {
return array('link' => null);
}
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML(Fct::load_url($link));
if ( !is_object($doc) ) {
$doc = Fct::load_xml($link);
if ( $doc === false ) {
return array('link' => null);
}
if ( $parts[3] == 'post' ) {
Expand Down Expand Up @@ -123,16 +121,15 @@ public static function cheezburger($link)
*/
public static function commitstrip($link)
{
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML(Fct::load_url($link));
if ( !is_object($doc) ) {
$doc = Fct::load_xml($link);
if ( $doc === false ) {
return array('link' => null);
}
$data = $doc
->getElementsByTagName('article')
>item(0)
->getElementsByTagName('img');
$data = $doc->getElementsByTagName('article')->item(0);
if ( is_null($data) ) {
return array('link' => null);
}
$data = $data->getElementsByTagName('img');
foreach ( $data as $img ) {
$src = $img->getAttribute('src');
if ( preg_match('/final/', $src) ) {
Expand Down Expand Up @@ -288,16 +285,13 @@ public static function kuvaton($link)
*/
public static function luc($link)
{
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML(Fct::load_url($link));
if ( !is_object($doc) ) {
$doc = Fct::load_xml($link);
if ( $doc === false ) {
return array('link' => null);
}
$image = $doc
->getElementById('content')
->getElementsByTagName('img')
->item(0);
->getElementsByTagName('img')->item(0);
$src = $image->getAttribute('src');
$ext = strtolower(pathinfo($src, 4));
return array(
Expand All @@ -316,10 +310,8 @@ public static function luc($link)
*/
public static function neufgag($link)
{
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML(Fct::load_url($link));
if ( !is_object($doc) ) {
$doc = Fct::load_xml($link);
if ( $doc === false ) {
return array('link' => null);
}
foreach ( $doc->getElementsByTagName('link') as $meta ) {
Expand Down Expand Up @@ -385,10 +377,8 @@ public static function twitter($link)
{
if ( preg_match('#/photo/#', $link) ) {
$url = $link.'/large';
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML(Fct::load_url($url));
if ( !is_object($doc) ) {
$doc = Fct::load_xml($url);
if ( $doc === false ) {
return array('link' => null);
}
foreach ( $doc->getElementsByTagName('img') as $image ) {
Expand Down

0 comments on commit 515cbf1

Please sign in to comment.