diff options
author | adev <adev2000@gmail.com> | 2014-01-12 17:08:52 +0100 |
---|---|---|
committer | adev <adev2000@gmail.com> | 2014-01-12 17:08:52 +0100 |
commit | f878daeb8bc9245a294677e4ac141f8bd37c2b4f (patch) | |
tree | 478609f121f57ef25bbe7d786fde89b082968f58 | |
parent | 9ba98a0abe4ac5efed5213812f0f26821417b47d (diff) | |
download | wallabag-f878daeb8bc9245a294677e4ac141f8bd37c2b4f.tar.gz wallabag-f878daeb8bc9245a294677e4ac141f8bd37c2b4f.tar.zst wallabag-f878daeb8bc9245a294677e4ac141f8bd37c2b4f.zip |
add basic auth in file_get_contents for content extraction when user use basic auth
-rw-r--r-- | inc/poche/Poche.class.php | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index e033ad74..004cca8e 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -325,6 +325,22 @@ class Poche | |||
325 | ); | 325 | ); |
326 | } | 326 | } |
327 | 327 | ||
328 | protected function getPageContent(Url $url) | ||
329 | { | ||
330 | $options = array('http' => array('user_agent' => 'poche')); | ||
331 | if (isset($_SERVER['AUTH_TYPE']) && "basic" === strtolower($_SERVER['AUTH_TYPE'])) { | ||
332 | $options['http']['header'] = sprintf( | ||
333 | "Authorization: Basic %s", | ||
334 | base64_encode( | ||
335 | sprintf('%s:%s', $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) | ||
336 | ) | ||
337 | ); | ||
338 | } | ||
339 | $context = stream_context_create($options); | ||
340 | $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed', false, $context); | ||
341 | return json_decode($json, true); | ||
342 | } | ||
343 | |||
328 | /** | 344 | /** |
329 | * Call action (mark as fav, archive, delete, etc.) | 345 | * Call action (mark as fav, archive, delete, etc.) |
330 | */ | 346 | */ |
@@ -333,10 +349,7 @@ class Poche | |||
333 | switch ($action) | 349 | switch ($action) |
334 | { | 350 | { |
335 | case 'add': | 351 | case 'add': |
336 | $options = array('http' => array('user_agent' => 'poche')); | 352 | $content = $this->getPageContent($url); |
337 | $context = stream_context_create($options); | ||
338 | $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed', false, $context); | ||
339 | $content = json_decode($json, true); | ||
340 | $title = $content['rss']['channel']['item']['title']; | 353 | $title = $content['rss']['channel']['item']['title']; |
341 | $body = $content['rss']['channel']['item']['description']; | 354 | $body = $content['rss']['channel']['item']['description']; |
342 | 355 | ||