summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-08 15:24:19 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-08 15:24:19 +0200
commit483d2551eaea6ffc3f7e13c8ea9c3ea215fadff0 (patch)
treedbc064b807becd290f772d383789beb24b943701
parent331b832fc0f48015ee49743352f654fcceea781b (diff)
get rid of simplepie absolute url function and use Net url2
-rw-r--r--appinfo/application.php16
-rw-r--r--articleenhancer/xpatharticleenhancer.php4
-rw-r--r--tests/classloader.php27
-rw-r--r--utility/faviconfetcher.php30
4 files changed, 28 insertions, 49 deletions
diff --git a/appinfo/application.php b/appinfo/application.php
index 6028d7c1c..ad15dac84 100644
--- a/appinfo/application.php
+++ b/appinfo/application.php
@@ -54,16 +54,20 @@ use \OCA\News\ArticleEnhancer\XPathArticleEnhancer;
use \OCA\News\ArticleEnhancer\RegexArticleEnhancer;
-require_once __DIR__ . '/../3rdparty/htmlpurifier/library/HTMLPurifier.auto.php';
+$thirdPartyLibs = [
+ '\HTMLPurifier' => 'htmlpurifier/library/HTMLPurifier.auto.php',
+ '\SimplePie' => 'simplepie/autoloader.php',
+ '\ZendXML\Security' => 'ZendXml/vendor/autoload.php',
+ '\Net_URL2' => 'Net_URL2/Net/URL2.php'
+];
// to prevent clashes with installed app framework versions
-if (!class_exists('\SimplePie')) {
- require_once __DIR__ . '/../3rdparty/simplepie/autoloader.php';
+foreach ($thirdPartyLibs as $class => $path) {
+ if (!class_exists($class)) {
+ require_once __DIR__ . '/../3rdparty/' . $path;
+ }
}
-if (!class_exists('\ZendXML\Security')) {
- require_once __DIR__ . '/../3rdparty/ZendXml/vendor/autoload.php';
-}
class Application extends App {
diff --git a/articleenhancer/xpatharticleenhancer.php b/articleenhancer/xpatharticleenhancer.php
index ec3b61525..fa704e301 100644
--- a/articleenhancer/xpatharticleenhancer.php
+++ b/articleenhancer/xpatharticleenhancer.php
@@ -161,10 +161,6 @@ class XPathArticleEnhancer implements ArticleEnhancer {
* @return string the resulting absolute URL
*/
protected function relativeToAbsoluteUrl($relativeUrl, $absoluteUrl) {
- if (!class_exists('\Net_URL2')) {
- require_once __DIR__ . '/../3rdparty/Net_URL2/Net/URL2.php';
- }
-
$base = new \Net_URL2($absoluteUrl);
return $base->resolve($relativeUrl);
}
diff --git a/tests/classloader.php b/tests/classloader.php
index ef3849849..c7a8b9f4d 100644
--- a/tests/classloader.php
+++ b/tests/classloader.php
@@ -13,24 +13,25 @@
require_once __DIR__ . '/../3rdparty/ZendXml/vendor/autoload.php';
require_once __DIR__ . '/../3rdparty/simplepie/autoloader.php';
+require_once __DIR__ . '/../3rdparty/Net_URL2/Net/URL2.php';
require_once __DIR__ . '/../../../tests/lib/appframework/db/mappertestutility.php';
// to execute without owncloud, we need to create our own classloader
spl_autoload_register(function ($className){
- if (strpos($className, 'OCA\\') === 0) {
+ if (strpos($className, 'OCA\\') === 0) {
- $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
- $relPath = __DIR__ . '/../..' . $path;
+ $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
+ $relPath = __DIR__ . '/../..' . $path;
- if(file_exists($relPath)){
- require_once $relPath;
- }
- } else if(strpos($className, 'OCP\\') === 0) {
- $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
- $relPath = __DIR__ . '/../../../lib/public' . $path;
+ if(file_exists($relPath)){
+ require_once $relPath;
+ }
+ } else if(strpos($className, 'OCP\\') === 0) {
+ $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
+ $relPath = __DIR__ . '/../../../lib/public' . $path;
- if(file_exists($relPath)){
- require_once $relPath;
- }
- }
+ if(file_exists($relPath)){
+ require_once $relPath;
+ }
+ }
}); \ No newline at end of file
diff --git a/utility/faviconfetcher.php b/utility/faviconfetcher.php
index 8a285a47b..850a7f576 100644
--- a/utility/faviconfetcher.php
+++ b/utility/faviconfetcher.php
@@ -49,25 +49,8 @@ class FaviconFetcher {
if($faviconUrl && $this->isImage($faviconUrl)) {
return $faviconUrl;
} elseif ($url) {
- // try /favicon.ico as fallback
- $parts = parse_url($url);
-
- // malformed url
- if ($parts === false || !array_key_exists('host', $parts)) {
- return null;
- }
-
- $port = '';
- if (array_key_exists("port", $parts)) {
- $port = $parts['port'];
- }
-
- $scheme = 'http';
- if (array_key_exists("scheme", $parts)) {
- $scheme = $parts['scheme'];
- }
-
- $faviconUrl = $scheme . "://" . $parts['host'] . $port . "/favicon.ico";
+ $base = new \Net_URL2($url);
+ $faviconUrl = (string) $base->resolve('/favicon.ico');
if($this->isImage($faviconUrl)) {
return $faviconUrl;
@@ -117,7 +100,8 @@ class FaviconFetcher {
if ($elements->length > 0) {
/** @noinspection PhpUndefinedMethodInspection */
$iconPath = $this->getAttribute($elements->item(0), 'href');
- $absPath = \SimplePie_Misc::absolutize_url($iconPath, $url);
+ $base = new \Net_URL2($url);
+ $absPath = (string) $base->resolve($iconPath, $url);
return $absPath;
}
}
@@ -178,9 +162,3 @@ class FaviconFetcher {
}
}
-
-/**
- * Thrown when no valid url was found by faviconfetcher
- */
-class NoValidUrlException extends \Exception {
-}