miniflux-legacy/app/helpers/app.php
Frederic Guillot 82df35a59b Change the database structure to have a single database
This is a major change for the next release of Miniflux.

- There is now only one database that can supports multiple users
- There is no automated schema migration for this release
- A migration procedure is available in the ChangeLog file
2016-12-26 09:51:38 -05:00

68 lines
1.7 KiB
PHP

<?php
namespace Miniflux\Helper;
use PicoFeed\Logging\Logger;
function escape($value)
{
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false);
}
function generate_token()
{
if (function_exists('random_bytes')) {
return bin2hex(random_bytes(30));
} elseif (function_exists('openssl_random_pseudo_bytes')) {
return bin2hex(openssl_random_pseudo_bytes(30));
} elseif (ini_get('open_basedir') === '' && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
return hash('sha256', file_get_contents('/dev/urandom', false, null, 0, 30));
}
return hash('sha256', uniqid(mt_rand(), true));
}
function parse_app_version($refnames, $commithash)
{
$version = 'master';
if ($refnames !== '$Format:%d$') {
$tag = preg_replace('/\s*\(.*tag:\sv([^,]+).*\)/i', '\1', $refnames);
if ($tag !== null && $tag !== $refnames) {
return $tag;
}
}
if ($commithash !== '$Format:%H$') {
$version .= '.'.$commithash;
}
return $version;
}
function get_current_base_url()
{
$url = is_secure_connection() ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'];
if (strpos($_SERVER['HTTP_HOST'], ':') === false) {
$url .= $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 ? '' : ':'.$_SERVER['SERVER_PORT'];
}
$url .= str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])) !== '/' ? str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])).'/' : '/';
return $url;
}
function is_secure_connection()
{
return ! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
}
function write_debug_file() {
if (DEBUG_MODE) {
file_put_contents(DEBUG_FILENAME, implode(PHP_EOL, Logger::getMessages()), FILE_APPEND|LOCK_EX);
}
}