]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/poche/Poche.class.php
Merge branch 'extraction-with-basic-auth' of git://github.com/aaa2000/poche into...
[github/wallabag/wallabag.git] / inc / poche / Poche.class.php
index 4a5a954bfe6e6fdd917a40574974d73015ede13e..0be1668d08f1649401cdcb89a606b1fdc20cfcb4 100644 (file)
@@ -111,7 +111,7 @@ class Poche
         $passTheme = TRUE;
         # Twig is an absolute requirement for Poche to function. Abort immediately if the Composer installer hasn't been run yet
         if (! self::$canRenderTemplates) {
-            $this->notInstalledMessage[] = 'Twig does not seem to be installed. Please initialize the Composer installation to automatically fetch dependencies. Have a look at <a href="http://doc.inthepoche.com/doku.php?id=users:begin:install">the documentation.</a>';
+            $this->notInstalledMessage[] = 'Twig does not seem to be installed. Please initialize the Composer installation to automatically fetch dependencies. Have a look at <a href="http://doc.wallabag.org/doku.php?id=users:begin:install">the documentation.</a>';
             $passTheme = FALSE;
         }
 
@@ -326,6 +326,22 @@ class Poche
         );
     }
 
+    protected function getPageContent(Url $url)
+    {
+        $options = array('http' => array('user_agent' => 'poche'));
+        if (isset($_SERVER['AUTH_TYPE']) && "basic" === strtolower($_SERVER['AUTH_TYPE'])) {
+            $options['http']['header'] = sprintf(
+                "Authorization: Basic %s", 
+                base64_encode(
+                    sprintf('%s:%s', $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
+                )
+            );
+        }
+        $context = stream_context_create($options);
+        $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);
+        return json_decode($json, true);
+    }
+
     /**
      * Call action (mark as fav, archive, delete, etc.)
      */
@@ -334,10 +350,7 @@ class Poche
         switch ($action)
         {
             case 'add':
-                $options = array('http' => array('user_agent' => 'poche'));
-                $context = stream_context_create($options);
-                $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);
-                $content = json_decode($json, true);
+                $content = $this->getPageContent($url);
                 $title = $content['rss']['channel']['item']['title'];
                 $body = $content['rss']['channel']['item']['description'];
 
@@ -956,7 +969,7 @@ class Poche
         if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) {
            $version = file_get_contents($cache_file);
         } else {
-           $version = file_get_contents('http://static.inthepoche.com/versions/' . $which);
+           $version = file_get_contents('http://static.wallabag.org/versions/' . $which);
            file_put_contents($cache_file, $version, LOCK_EX);
         }
         return $version;