aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Helper/DownloadImages.php44
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;
6use Symfony\Component\DomCrawler\Crawler; 6use Symfony\Component\DomCrawler\Crawler;
7 7
8define('REGENERATE_PICTURES_QUALITY', 75); 8define('REGENERATE_PICTURES_QUALITY', 75);
9define('HTTP_PORT', 80);
10define('SSL_PORT', 443);
11define('BASE_URL','');
9 12
10class DownloadImages { 13class 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}