Added tt-rss-mobilize plugin for supporting Readability and other
mobilizer services out of the box.
This commit is contained in:
45
utils.php
Normal file
45
utils.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?
|
||||
|
||||
function env($name, $default = null)
|
||||
{
|
||||
$v = getenv($name) ?: $default;
|
||||
|
||||
if ($v === null) {
|
||||
error('The env ' . $name . ' does not exist');
|
||||
}
|
||||
|
||||
return $v;
|
||||
}
|
||||
|
||||
function error($text)
|
||||
{
|
||||
echo 'Error: ' . $text . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
function dbconnect($config)
|
||||
{
|
||||
$map = array('host' => 'HOST', 'port' => 'PORT', 'dbname' => 'NAME', 'user' => 'USER', 'password' => 'PASS');
|
||||
$dsn = $config['DB_TYPE'] . ':';
|
||||
foreach ($map as $d => $h) {
|
||||
if (isset($config['DB_' . $h])) {
|
||||
$dsn .= $d . '=' . $config['DB_' . $h] . ';';
|
||||
}
|
||||
}
|
||||
$pdo = new \PDO($dsn);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
function dbcheck($config)
|
||||
{
|
||||
try {
|
||||
dbconnect($config);
|
||||
return true;
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user