final class Tools
{
- private function __construct()
- {
-
- }
-
/**
* Initialize PHP environment
*/
$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"]);
{
$views = array(
'install', 'import', 'export', 'config', 'tags',
- 'edit-tags', 'view', 'login', 'error'
+ 'edit-tags', 'view', 'login', 'error', 'about'
);
return (in_array($view, $views) ? $view . '.twig' : 'home.twig');
}
}
- /**
- * 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)
*
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) {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';
}
+ /*
+ * Empty cache folder
+ */
+ public static function emptyCache()
+ {
+ $files = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator(CACHE, RecursiveDirectoryIterator::SKIP_DOTS),
+ RecursiveIteratorIterator::CHILD_FIRST
+ );
+
+ foreach ($files as $fileInfo) {
+ $todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink');
+ $todo($fileInfo->getRealPath());
+ }
+
+ Tools::logm('empty cache');
+ Tools::redirect();
+ }
+
+ public static function generateToken()
+ {
+ if (ini_get('open_basedir') === '') {
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+ // alternative to /dev/urandom for Windows
+ $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
+ } else {
+ $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
+ }
+ }
+ else {
+ $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
+ }
+
+ return str_replace('+', '', $token);
+ }
+
}