X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FUrl.class.php;h=aba236fa5b57f24bf8d6b479fa532730ffef7dea;hb=c95b78a8ceb918f033f3dd6c26aa7da4a8a527dc;hp=00b0b25758236ac03d4c3e6927e167aa7d3b7749;hpb=7ba37bd91a43321196e6d867caf9e298e82c6d6c;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php index 00b0b257..aba236fa 100644 --- a/inc/poche/Url.class.php +++ b/inc/poche/Url.class.php @@ -1,9 +1,9 @@ + * @category wallabag + * @author Nicolas Lœuillet * @copyright 2013 * @license http://www.wtfpl.net/ see COPYING file */ @@ -25,70 +25,7 @@ class Url $this->url = $url; } - public function isCorrect() - { - $pattern = '|^(.*:)//([a-z\-.]+)(:[0-9]+)?(.*)$|i'; - - return preg_match($pattern, $this->url); - } - - public function clean() - { - $url = html_entity_decode(trim($this->url)); - - $stuff = strpos($url,'&utm_source='); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - $stuff = strpos($url,'?utm_source='); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - $stuff = strpos($url,'#xtor=RSS-'); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - - $this->url = $url; - } - - public function fetchContent() - { - if ($this->isCorrect()) { - $this->clean(); - $html = Encoding::toUTF8(Tools::getFile($this->getUrl())); - - # if Tools::getFile() if not able to retrieve HTTPS content, try the same URL with HTTP protocol - if (!preg_match('!^https?://!i', $this->getUrl()) && (!isset($html) || strlen($html) <= 0)) { - $this->setUrl('http://' . $this->getUrl()); - $html = Encoding::toUTF8(Tools::getFile($this->getUrl())); - } - - if (function_exists('tidy_parse_string')) { - $tidy = tidy_parse_string($html, array(), 'UTF8'); - $tidy->cleanRepair(); - $html = $tidy->value; - } - - $parameters = array(); - if (isset($html) and strlen($html) > 0) - { - $readability = new Readability($html, $this->getUrl()); - $readability->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; - $readability->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS; - - if($readability->init()) - { - $content = $readability->articleContent->innerHTML; - $parameters['title'] = $readability->articleTitle->innerHTML; - $parameters['content'] = $content; - - return $parameters; - } - } - } - else { - #$msg->add('e', _('error during url preparation : the link is not valid')); - Tools::logm($this->getUrl() . ' is not a valid url'); - } - - return FALSE; + public function isCorrect() { + return filter_var($this->url, FILTER_VALIDATE_URL) !== FALSE; } } \ No newline at end of file