added ini-file support for application settings

This commit is contained in:
eleksir
2017-03-18 12:18:48 +03:00
parent 5b1653ca11
commit 6f3789bfdc
2 changed files with 29 additions and 12 deletions

View File

@@ -1,11 +1,13 @@
<?php
define ('BASEURL', "/"); # must end with '/'
define ('KEY_MIN', 3);
define ('KEY_MAX', 9);
define ('DBPATH', 'paste/paste.sqlite');
define ('SITE_ADDRESS', 'http://127.0.0.1/');
define ('CDN_ADDRESS', 'http://127.0.0.1/');
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
$config = parse_ini_file("app.ini");
define ('SITE_ADDRESS', $config["siteaddress"]);
define ('BASEURL', $config["baseurl"]);
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
define ('CDN_ADDRESS', $config["cdnaddress"]);
define ('DBPATH', $config["dbpath"]);
define ('KEY_MIN', 3);
define ('KEY_MAX', 9);
unset ($config);
function showindex($text) {
header('Content-Language: en, ru');
@@ -25,10 +27,10 @@ function showindex($text) {
height: 70vh;
}
</style>
<title>Paste.</title>
<title>Slack paste.</title>
</head>
<body>
<h3>Paste</h3>
<h3>Slack Paste</h3>
<form method="post" action="<?php print APP_ADDRESS; ?>" enctype="multipart/form-data">
<textarea name="exs" id="textbox" autofocus></textarea><br />
<input type="submit" value="Post it!" style="font-size:115%;" /> for
@@ -76,7 +78,7 @@ description() {
cat << HERE
DESCRIPTION
Upload data and fetch URL from the pastebin <?php print SITE_ADDRESS; ?>
Upload data and fetch URL from the pastebin http://p.dafuq.ru/
USAGE
$0 filename.txt
@@ -188,14 +190,14 @@ function init_db() {
$dbh = null;
}
function query_db($id) {
function query_db($q) {
if (! file_exists(DBPATH)) {
init_db();
return false;
}
$dbh = new PDO("sqlite:" . DBPATH);
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$id'");
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$q'");
if ($sth === false) {
$e = $r->errorInfo();