From f43bbda83e9328832915f017f7a8cf83fcb2f50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Fri, 8 Jul 2016 19:05:01 +0200 Subject: [PATCH] core: split and rename BridgeAbstract::file_get_html MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to have one method to get the data, potentially using the proxy if defined, and one method to get the Simple DOM HTML object from these data, with a more informative name Signed-off-by: Pierre Mazière --- lib/Bridge.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Bridge.php b/lib/Bridge.php index 664fc93..2daca2a 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -105,7 +105,7 @@ abstract class BridgeAbstract implements BridgeInterface{ return $this; } - protected function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT){ + protected function getContents($url,$use_include_path=false,$context=null,$offset=0,$maxlen=null){ $contextOptions = array( 'http' => array( 'user_agent'=>ini_get('user_agent') @@ -125,9 +125,22 @@ abstract class BridgeAbstract implements BridgeInterface{ }; } } - return file_get_html($url,$use_include_path,$context,$offset,$maxLen, - $lowercase,$forceTagsClosed,$target_charset,$stripRN,$defaultBRText, - $defaultSpanText); + + if(is_null($maxlen)){ + $content=@file_get_contents($url, $use_include_path, $context, $offset); + }else{ + $content=@file_get_contents($url, $use_include_path, $context, $offset,$maxlen); + } + + if($content===false){ + $this->message('Cant\'t download '.$url ); + } + return $content; + } + + protected function getSimpleHTMLDOM($url, $use_include_path = false, $context=null, $offset = 0, $maxLen=null, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT){ + $content=$this->getContents($url,$use_include_path,$context,$offset,$maxLen); + return str_get_html($content,$lowercase,$forceTagsClosed,$target_charset,$stripRN,$defaultBRText,$defaultSpanText); } }