diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-06-28 22:06:00 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-29 16:25:45 +0200 |
commit | 94654765cca6771c2f54eeaa056b7e65f3353105 (patch) | |
tree | ea2fbf8c171801f748e35b10a2f258db77e07af2 /src/Wallabag | |
parent | 419214d7221e0821ef2b73eb2b3db816ed0cf173 (diff) | |
download | wallabag-94654765cca6771c2f54eeaa056b7e65f3353105.tar.gz wallabag-94654765cca6771c2f54eeaa056b7e65f3353105.tar.zst wallabag-94654765cca6771c2f54eeaa056b7e65f3353105.zip |
Working
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/DownloadImages.php | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php index 32a9dbb2..14f0aa1b 100644 --- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php +++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php | |||
@@ -6,6 +6,9 @@ use Psr\Log\LoggerInterface as Logger; | |||
6 | use Symfony\Component\DomCrawler\Crawler; | 6 | use Symfony\Component\DomCrawler\Crawler; |
7 | 7 | ||
8 | define('REGENERATE_PICTURES_QUALITY', 75); | 8 | define('REGENERATE_PICTURES_QUALITY', 75); |
9 | define('HTTP_PORT', 80); | ||
10 | define('SSL_PORT', 443); | ||
11 | define('BASE_URL',''); | ||
9 | 12 | ||
10 | class DownloadImages { | 13 | class DownloadImages { |
11 | private $folder; | 14 | private $folder; |
@@ -47,7 +50,7 @@ class DownloadImages { | |||
47 | $filename = basename(parse_url($absolute_path, PHP_URL_PATH)); | 50 | $filename = basename(parse_url($absolute_path, PHP_URL_PATH)); |
48 | $fullpath = $this->folder."/".$filename; | 51 | $fullpath = $this->folder."/".$filename; |
49 | self::checks($file, $fullpath, $absolute_path); | 52 | self::checks($file, $fullpath, $absolute_path); |
50 | $this->html = str_replace($image, $fullpath, $this->html); | 53 | $this->html = str_replace($image, self::getPocheUrl() . '/' . $fullpath, $this->html); |
51 | } | 54 | } |
52 | 55 | ||
53 | return $this->html; | 56 | return $this->html; |
@@ -144,4 +147,43 @@ class DownloadImages { | |||
144 | /* absolute URL is ready! */ | 147 | /* absolute URL is ready! */ |
145 | return $scheme.'://'.$abs; | 148 | return $scheme.'://'.$abs; |
146 | } | 149 | } |
150 | |||
151 | public static function getPocheUrl() | ||
152 | { | ||
153 | $baseUrl = ""; | ||
154 | $https = (!empty($_SERVER['HTTPS']) | ||
155 | && (strtolower($_SERVER['HTTPS']) == 'on')) | ||
156 | || (isset($_SERVER["SERVER_PORT"]) | ||
157 | && $_SERVER["SERVER_PORT"] == '443') // HTTPS detection. | ||
158 | || (isset($_SERVER["SERVER_PORT"]) //Custom HTTPS port detection | ||
159 | && $_SERVER["SERVER_PORT"] == SSL_PORT) | ||
160 | || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) | ||
161 | && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'); | ||
162 | $serverport = (!isset($_SERVER["SERVER_PORT"]) | ||
163 | || $_SERVER["SERVER_PORT"] == '80' | ||
164 | || $_SERVER["SERVER_PORT"] == HTTP_PORT | ||
165 | || ($https && $_SERVER["SERVER_PORT"] == '443') | ||
166 | || ($https && $_SERVER["SERVER_PORT"]==SSL_PORT) //Custom HTTPS port detection | ||
167 | ? '' : ':' . $_SERVER["SERVER_PORT"]); | ||
168 | |||
169 | if (isset($_SERVER["HTTP_X_FORWARDED_PORT"])) { | ||
170 | $serverport = ':' . $_SERVER["HTTP_X_FORWARDED_PORT"]; | ||
171 | } | ||
172 | // $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); | ||
173 | // if (!isset($_SERVER["HTTP_HOST"])) { | ||
174 | // return $scriptname; | ||
175 | // } | ||
176 | $host = (isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'])); | ||
177 | if (strpos($host, ':') !== false) { | ||
178 | $serverport = ''; | ||
179 | } | ||
180 | // check if BASE_URL is configured | ||
181 | if(BASE_URL) { | ||
182 | $baseUrl = BASE_URL; | ||
183 | } else { | ||
184 | $baseUrl = 'http' . ($https ? 's' : '') . '://' . $host . $serverport; | ||
185 | } | ||
186 | return $baseUrl; | ||
187 | |||
188 | } | ||
147 | } | 189 | } |