diff options
author | ArthurHoaro <arthur@hoa.ro> | 2018-05-02 18:28:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-02 18:28:09 +0200 |
commit | 3e35fc10e5f94ff7f49c416dfc4b77a0a15fbbfc (patch) | |
tree | 371cd38024846aa7f91c2a5d081219513c7d9a3c | |
parent | 3c0e27eec72f7bb00aea81540f978c4b4a1ac87f (diff) | |
parent | a1b727efb78b12566098a05073cb928198cf2797 (diff) | |
download | Shaarli-3e35fc10e5f94ff7f49c416dfc4b77a0a15fbbfc.tar.gz Shaarli-3e35fc10e5f94ff7f49c416dfc4b77a0a15fbbfc.tar.zst Shaarli-3e35fc10e5f94ff7f49c416dfc4b77a0a15fbbfc.zip |
Merge pull request #1133 from ArthurHoaro/hotfix/title-dl
Title retrieval fixes
-rw-r--r-- | application/LinkUtils.php | 17 | ||||
-rw-r--r-- | index.php | 2 |
2 files changed, 14 insertions, 5 deletions
diff --git a/application/LinkUtils.php b/application/LinkUtils.php index 3705f7e9..4df5c0ca 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | function get_curl_download_callback(&$charset, &$title, $curlGetInfo = 'curl_getinfo') | 12 | function get_curl_download_callback(&$charset, &$title, $curlGetInfo = 'curl_getinfo') |
13 | { | 13 | { |
14 | $isRedirected = false; | ||
14 | /** | 15 | /** |
15 | * cURL callback function for CURLOPT_WRITEFUNCTION (called during the download). | 16 | * cURL callback function for CURLOPT_WRITEFUNCTION (called during the download). |
16 | * | 17 | * |
@@ -22,16 +23,24 @@ function get_curl_download_callback(&$charset, &$title, $curlGetInfo = 'curl_get | |||
22 | * | 23 | * |
23 | * @return int|bool length of $data or false if we need to stop the download | 24 | * @return int|bool length of $data or false if we need to stop the download |
24 | */ | 25 | */ |
25 | return function(&$ch, $data) use ($curlGetInfo, &$charset, &$title) { | 26 | return function(&$ch, $data) use ($curlGetInfo, &$charset, &$title, &$isRedirected) { |
26 | $responseCode = $curlGetInfo($ch, CURLINFO_RESPONSE_CODE); | 27 | $responseCode = $curlGetInfo($ch, CURLINFO_RESPONSE_CODE); |
27 | if (!empty($responseCode) && $responseCode != 200) { | 28 | if (!empty($responseCode) && in_array($responseCode, [301, 302])) { |
29 | $isRedirected = true; | ||
30 | return strlen($data); | ||
31 | } | ||
32 | if (!empty($responseCode) && $responseCode !== 200) { | ||
28 | return false; | 33 | return false; |
29 | } | 34 | } |
30 | $contentType = $curlGetInfo($ch, CURLINFO_CONTENT_TYPE); | 35 | // After a redirection, the content type will keep the previous request value |
36 | // until it finds the next content-type header. | ||
37 | if (! $isRedirected || strpos(strtolower($data), 'content-type') !== false) { | ||
38 | $contentType = $curlGetInfo($ch, CURLINFO_CONTENT_TYPE); | ||
39 | } | ||
31 | if (!empty($contentType) && strpos($contentType, 'text/html') === false) { | 40 | if (!empty($contentType) && strpos($contentType, 'text/html') === false) { |
32 | return false; | 41 | return false; |
33 | } | 42 | } |
34 | if (empty($charset)) { | 43 | if (!empty($contentType) && empty($charset)) { |
35 | $charset = header_extract_charset($contentType); | 44 | $charset = header_extract_charset($contentType); |
36 | } | 45 | } |
37 | if (empty($charset)) { | 46 | if (empty($charset)) { |
@@ -1376,8 +1376,8 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
1376 | // The callback will fill $charset and $title with data from the downloaded page. | 1376 | // The callback will fill $charset and $title with data from the downloaded page. |
1377 | get_http_response( | 1377 | get_http_response( |
1378 | $url, | 1378 | $url, |
1379 | $conf->get('general.download_max_size', 4194304), | ||
1380 | $conf->get('general.download_timeout', 30), | 1379 | $conf->get('general.download_timeout', 30), |
1380 | $conf->get('general.download_max_size', 4194304), | ||
1381 | get_curl_download_callback($charset, $title) | 1381 | get_curl_download_callback($charset, $title) |
1382 | ); | 1382 | ); |
1383 | if (! empty($title) && strtolower($charset) != 'utf-8') { | 1383 | if (! empty($title) && strtolower($charset) != 'utf-8') { |