]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/poche/Tools.class.php
Factorize
[github/wallabag/wallabag.git] / inc / poche / Tools.class.php
index 63137d765542a8724991c68b3314ceba8f574d0b..263034f07d3363e5df1b23781dae68a46d5736b3 100755 (executable)
@@ -40,6 +40,8 @@ final class Tools
      */
     public static function getPocheUrl()
     {
+       $baseUrl = "";
+
         $https = (!empty($_SERVER['HTTPS'])
                     && (strtolower($_SERVER['HTTPS']) == 'on'))
             || (isset($_SERVER["SERVER_PORT"])
@@ -51,9 +53,14 @@ final class Tools
 
         $serverport = (!isset($_SERVER["SERVER_PORT"])
             || $_SERVER["SERVER_PORT"] == '80'
+            || $_SERVER["SERVER_PORT"] == HTTP_PORT
             || ($https && $_SERVER["SERVER_PORT"] == '443')
             || ($https && $_SERVER["SERVER_PORT"]==SSL_PORT) //Custom HTTPS port detection
             ? '' : ':' . $_SERVER["SERVER_PORT"]);
+        
+        if (isset($_SERVER["HTTP_X_FORWARDED_PORT"])) {
+            $serverport = ':' . $_SERVER["HTTP_X_FORWARDED_PORT"];
+        }
 
         $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]);
 
@@ -67,8 +74,15 @@ final class Tools
             $serverport = '';
         }
 
-        return 'http' . ($https ? 's' : '') . '://'
-            . $host . $serverport . $scriptname;
+               // check if BASE_URL is configured
+               if(BASE_URL) {
+                       $baseUrl = BASE_URL;
+               } else {
+                       $baseUrl = 'http' . ($https ? 's' : '') . '://' . $host . $serverport;
+               }
+
+    return $baseUrl . $scriptname;
+    
     }
 
     /**
@@ -112,7 +126,7 @@ final class Tools
     {
         $views = array(
             'install', 'import', 'export', 'config', 'tags',
-            'edit-tags', 'view', 'login', 'error'
+            'edit-tags', 'view', 'login', 'error', 'about', 'register'
             );
 
         return (in_array($view, $views) ? $view . '.twig' : 'home.twig');
@@ -127,7 +141,7 @@ final class Tools
     public static function getFile($url)
     {
         $timeout = 15;
-        $useragent = "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0";
+        $useragent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0";
 
         if (in_array ('curl', get_loaded_extensions())) {
             # Fetch feed from URL
@@ -218,6 +232,27 @@ final class Tools
         exit();
     }
 
+    /**
+     * UTF-8 encode array of string
+     *
+     * @param $data
+     */
+    public static function utf8ize($data)
+    {
+        if (is_array($data))
+        {
+            foreach ($data as $k => $v)
+            {
+                $data[$k] = self::utf8ize($v);
+            }
+        }
+        else if (is_string ($data) && '' == mb_detect_encoding($data))
+        {
+            return utf8_encode($data);
+        }
+        return $data;
+    }
+
     /**
      * Create new line in log file
      *
@@ -294,21 +329,6 @@ final class Tools
         }
     }
 
-    /**
-     * Download the sqlite database
-     */
-    public static function downloadDb()
-    {
-        header('Content-Disposition: attachment; filename="poche.sqlite.gz"');
-        self::_status(200);
-
-        header('Content-Transfer-Encoding: binary');
-        header('Content-Type: application/octet-stream');
-        echo gzencode(file_get_contents(STORAGE_SQLITE));
-
-        exit;
-    }
-
     /**
      * Get the content for a given URL (by a call to FullTextFeed)
      *
@@ -352,7 +372,10 @@ final class Tools
             return $json;
         };
 
-        $json = $scope("inc/3rdparty/makefulltextfeed.php", array("url" => $url));
+       // Silence $scope function to avoid
+       // issues with FTRSS when error_reporting is to high
+       // FTRSS generates PHP warnings which break output
+        $json = @$scope("inc/3rdparty/makefulltextfeed.php", array("url" => $url));
 
         // Clearing and restoring context
         foreach ($GLOBALS as $key => $value) {
@@ -399,8 +422,11 @@ final class Tools
         );
 
         foreach ($files as $fileInfo) {
-            $todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink');
-            $todo($fileInfo->getRealPath());
+            $filename = $fileInfo->getFilename();
+            if (!$filename[0] == '.') {
+                $todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink');
+                $todo($fileInfo->getRealPath());
+            }
         }
 
         Tools::logm('empty cache');
@@ -424,4 +450,23 @@ final class Tools
         return str_replace('+', '', $token);
     }
 
+    /** 
+    *
+    * Returns the doctype for an HTML document (used for Mozilla Bookmarks)
+    * @param simple_html_dom $doc
+    * @return doctype $el
+    *
+    */
+
+    public static function get_doctype($doc)
+    {
+        $els = $doc->find('unknown');
+
+        foreach ($els as $e => $el) 
+            if ($el->parent()->tag == 'root') 
+                return $el;
+
+        return NULL;
+    }
+
 }