diff --git a/admin/configuration.php b/admin/configuration.php index ded843d..35768aa 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -15,24 +15,26 @@ define('IN_ADMIN', 1); require_once('common.php'); +const CONFIG_FILE_PATH = '../config/site.php'; + + updateAdminHistory($conn); -$query = $conn->query('SELECT * FROM site_info'); +function updateConfiguration(string $path, array $new_config) { + $fp = fopen($path, 'w'); -if ($row = $query->fetch()) { - $title = Trim($row['title']); - $des = Trim($row['des']); - $baseurl = Trim($row['baseurl']); - $keyword = Trim($row['keyword']); - $site_name = Trim($row['site_name']); - $email = Trim($row['email']); - $twit = Trim($row['twit']); - $face = Trim($row['face']); - $gplus = Trim($row['gplus']); - $ga = Trim($row['ga']); - $additional_scripts = Trim($row['additional_scripts']); + $new_config_text = var_export($new_config, true); + $code = "query('SELECT * FROM captcha WHERE id = 1'); @@ -69,12 +71,33 @@ if ($row = $result->fetch()) { /* Update the configuration if necessary */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $action = $_POST['action']; + + if ($action === 'manage') { + $new_site_info = [ + 'title' => trim($_POST['title']), + 'description' => trim($_POST['description']), + 'baseurl' => trim($_POST['baseurl']), + 'keywords' => trim($_POST['keywords']), + 'site_name' => trim($_POST['site_name']), + 'email' => trim($_POST['email']), + 'google_analytics' => trim($_POST['ga']), + 'additional_scripts' => trim($_POST['additional_scripts']) + ]; + + $current_config['site_info'] = $new_site_info; + $current_site_info = $new_site_info; + + updateConfiguration(CONFIG_FILE_PATH, $current_config); + $msg = '
+ Configuration saved. +
'; + } if (isset($_POST['manage'])) { $query = $conn->prepare( 'UPDATE site_info SET title = ?, des = ?, baseurl = ?, keyword = ?, site_name = ?, email = ?, twit = ?, face = ?, gplus = ?, ga = ?, additional_scripts = ? WHERE id = 1' ); $query->execute([ - trim($_POST['title']), trim($_POST['des']), trim($_POST['baseurl']), trim($_POST['keyword']), @@ -218,7 +241,7 @@ if (isset($_POST['smtp_code'])) {
+ value="">
@@ -227,7 +250,7 @@ if (isset($_POST['smtp_code'])) {
+ value="">
@@ -245,25 +268,25 @@ if (isset($_POST['smtp_code'])) {
+ value="">
- + value="">
- + value="">
@@ -271,7 +294,7 @@ if (isset($_POST['smtp_code'])) {
+ value="">
@@ -279,31 +302,7 @@ if (isset($_POST['smtp_code'])) {
-
- - -
- -
- -
-
- -
- -
- -
-
- -
- -
- + value="">
@@ -313,11 +312,11 @@ if (isset($_POST['smtp_code'])) {
+ rows="8">
- +
diff --git a/config/.htaccess b/config/.htaccess new file mode 100644 index 0000000..3418e55 --- /dev/null +++ b/config/.htaccess @@ -0,0 +1 @@ +deny from all \ No newline at end of file diff --git a/config/site.php b/config/site.php new file mode 100644 index 0000000..3724124 --- /dev/null +++ b/config/site.php @@ -0,0 +1,19 @@ + + array ( + 'title' => 'PonePaste', + 'description' => 'PonePaste can store green', + 'baseurl' => 'ponepaste.local/', + 'keywords' => '', + 'site_name' => 'PonePaste', + 'email' => '', + 'google_analytics' => '', + 'additional_scripts' => 'PonePaste', + ), + 'interface' => + array ( + 'language' => 'en', + 'theme' => 'bulma', + ), +); \ No newline at end of file diff --git a/fav.php b/fav.php index a82de03..327cb3e 100644 --- a/fav.php +++ b/fav.php @@ -25,9 +25,6 @@ while ($row = mysqli_fetch_array($result)) { $keyword = Trim($row['keyword']); $site_name = Trim($row['site_name']); $email = Trim($row['email']); - $twit = Trim($row['twit']); - $face = Trim($row['face']); - $gplus = Trim($row['gplus']); $ga = Trim($row['ga']); $additional_scripts = Trim($row['additional_scripts']); } diff --git a/includes/common.php b/includes/common.php index c9c40ae..801cd8c 100644 --- a/includes/common.php +++ b/includes/common.php @@ -7,12 +7,8 @@ require_once('config.php'); require_once('includes/functions.php'); -function getSiteInfo(PDO $conn) : array { - return $conn->query('SELECT * FROM site_info LIMIT 1')->fetch(); -} - -function getSiteLangAndTheme(PDO $conn) : array { - return $conn->query('SELECT lang, theme FROM interface LIMIT 1')->fetch(); +function getSiteInfo() : array { + return require('config/site.php'); } function getSitePermissions(PDO $conn) : array { @@ -82,34 +78,25 @@ $conn = new PDO( ); // Setup site info -$row = getSiteInfo($conn); +$site_info = getSiteInfo(); +$row = $site_info['site_info']; $title = Trim($row['title']); -$des = Trim($row['des']); +$des = Trim($row['description']); $baseurl = Trim($row['baseurl']); -$keyword = Trim($row['keyword']); +$keyword = Trim($row['keywords']); $site_name = Trim($row['site_name']); $email = Trim($row['email']); -$twit = Trim($row['twit']); -$face = Trim($row['face']); -$gplus = Trim($row['gplus']); -$ga = Trim($row['ga']); +$ga = Trim($row['google_analytics']); $additional_scripts = Trim($row['additional_scripts']); // Setup theme and language - -$lang_and_theme = getSiteLangAndTheme($conn); - -if ($lang_and_theme) { - $default_lang = $lang_and_theme['lang']; - $default_theme = $lang_and_theme['theme']; -} else { - $default_lang = 'en.php'; - $default_theme = 'bulma'; -} +$lang_and_theme = $site_info['interface']; +$default_lang = $lang_and_theme['language']; +$default_theme = $lang_and_theme['theme']; // site permissions -$site_permissions = getSitePermissions($conn); +$site_permissions = $site_info['permissions']; if ($site_permissions) { $siteprivate = $site_permissions['siteprivate']; diff --git a/oauth.php b/oauth.php index 39de0d5..4528cbb 100644 --- a/oauth.php +++ b/oauth.php @@ -38,9 +38,6 @@ while ($row = mysqli_fetch_array($result)) { $keyword = Trim($row['keyword']); $site_name = Trim($row['site_name']); $email = Trim($row['email']); - $twit = Trim($row['twit']); - $face = Trim($row['face']); - $gplus = Trim($row['gplus']); $ga = Trim($row['ga']); $additional_scripts = Trim($row['additional_scripts']); } diff --git a/report.php b/report.php index 4fdd6b9..f601853 100644 --- a/report.php +++ b/report.php @@ -25,9 +25,6 @@ while ($row = mysqli_fetch_array($result)) { $keyword = Trim($row['keyword']); $site_name = Trim($row['site_name']); $email = Trim($row['email']); - $twit = Trim($row['twit']); - $face = Trim($row['face']); - $gplus = Trim($row['gplus']); $ga = Trim($row['ga']); $additional_scripts = Trim($row['additional_scripts']); }