1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-29 18:33:01 +00:00
Pepperminty-Wiki/settings.fragment.php

71 lines
2.1 KiB
PHP
Raw Permalink Normal View History

<?php
/*
* Pepperminty Wiki
* ================
* Inspired by Minty Wiki by am2064
* Link: https://github.com/am2064/Minty-Wiki
2016-05-29 19:34:34 +00:00
*
* Credits:
* Code by @Starbeamrainbowlabs
2016-03-12 18:55:47 +00:00
* Parsedown - by erusev and others on github from http://parsedown.org/
2016-04-03 17:01:12 +00:00
* Mathematical Expression rendering
* Code: @con-f-use <https://github.com/con-f-use>
* Rendering: MathJax (https://www.mathjax.org/)
2015-01-05 18:53:44 +00:00
* Bug reports:
* #2 - Incorrect closing tag - nibreh <https://github.com/nibreh/>
* #8 - Rogue <datalist /> tag - nibreh <https://github.com/nibreh/>
*/
2016-06-22 08:13:32 +00:00
$guiConfig = <<<'GUICONFIG'
2016-06-12 20:06:27 +00:00
{guiconfig}
GUICONFIG;
2016-06-22 08:13:32 +00:00
$settingsFilename = "peppermint.json";
2017-11-04 21:33:21 +00:00
if(file_exists("$settingsFilename.compromised")) {
http_response_code(500);
header("content-type: text/plain");
exit("Error: $settingsFilename.compromised exists on disk, so it's likely you need to block access to 'peppermint.json' from the internet. If you've done this already, please delete $settingsFilename.compromised and reload this page.");
}
2016-06-12 20:06:27 +00:00
$guiConfig = json_decode($guiConfig);
2015-04-09 14:13:07 +00:00
$settings = new stdClass();
if(!file_exists($settingsFilename))
2016-06-12 20:06:27 +00:00
{
// Copy the default settings over to the main settings array
foreach ($guiConfig as $key => $value)
$settings->$key = $value->default;
2016-06-12 20:06:27 +00:00
// Generate a random secret
2016-06-22 08:13:32 +00:00
$settings->secret = bin2hex(openssl_random_pseudo_bytes(16));
2016-06-12 20:06:27 +00:00
file_put_contents("peppermint.json", json_encode($settings, JSON_PRETTY_PRINT));
}
else
$settings = json_decode(file_get_contents("peppermint.json"));
if($settings === null)
{
header("content-type: text/plain");
exit("Error: Failed to decode the settings file! Does it contain a syntax error?");
}
// Fill in any missing properties
$settingsUpgraded = false;
foreach($guiConfig as $key => $propertyData)
{
if(!isset($settings->$key))
{
$settings->$key = $propertyData->default;
$settingsUpgraded = true;
}
}
if($settingsUpgraded)
file_put_contents("peppermint.json", json_encode($settings, JSON_PRETTY_PRINT));
// Insert the default CSS if requested
$defaultCSS = <<<THEMECSS
2016-06-22 08:13:32 +00:00
{default-css}
THEMECSS;
if($settings->css === "auto")
$settings->css = $defaultCSS;
?>