mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
Corrected build
This commit is contained in:
parent
e86358a85a
commit
3d054a965b
1 changed files with 59 additions and 37 deletions
96
core.php
96
core.php
|
@ -5,7 +5,7 @@ $start_time = time(true);
|
||||||
* ================
|
* ================
|
||||||
* Inspired by Minty Wiki by am2064:
|
* Inspired by Minty Wiki by am2064:
|
||||||
* Link: https://github.com/am2064/Minty-Wiki
|
* Link: https://github.com/am2064/Minty-Wiki
|
||||||
*
|
*
|
||||||
* Credits:
|
* Credits:
|
||||||
* Slimdown - by Johnny Broadway from https://gist.github.com/jbroadway/2836900
|
* Slimdown - by Johnny Broadway from https://gist.github.com/jbroadway/2836900
|
||||||
*/
|
*/
|
||||||
|
@ -13,6 +13,14 @@ $start_time = time(true);
|
||||||
//the site's name
|
//the site's name
|
||||||
$sitename = "Pepperminty Wiki";
|
$sitename = "Pepperminty Wiki";
|
||||||
|
|
||||||
|
//the url from which to fetch updates. Defaults to the master (development) branch If there is sufficient demand, a separate stable branch will be created.
|
||||||
|
//currently not implemented (yet).
|
||||||
|
$updateurl = "https://raw.githubusercontent.com/sbrl/pepperminty-wiki/master/index.php";
|
||||||
|
|
||||||
|
//the secret key used to perform 'dangerous' actions, like updating the wiki, and deleting pages. It is strongly advised that you change this!
|
||||||
|
//note that neither of these features have been added yet.
|
||||||
|
$sitesecret = "ed420502615bac9037f8f12abd4c9f02";
|
||||||
|
|
||||||
//whether people can edit the site
|
//whether people can edit the site
|
||||||
$editing = true;
|
$editing = true;
|
||||||
|
|
||||||
|
@ -151,14 +159,14 @@ else
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* @summary makes a path safe
|
* @summary makes a path safe
|
||||||
*
|
*
|
||||||
* @details paths may only contain alphanumeric characters, spaces, underscores, and dashes
|
* @details paths may only contain alphanumeric characters, spaces, underscores, and dashes
|
||||||
*/
|
*/
|
||||||
function makepathsafe($string) { return preg_replace("/[^0-9a-zA-Z\_\-\ ]/i", "", $string); }
|
function makepathsafe($string) { return preg_replace("/[^0-9a-zA-Z\_\-\ ]/i", "", $string); }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @summary Hides an email address from bots by adding random html entities.
|
* @summary Hides an email address from bots by adding random html entities.
|
||||||
*
|
*
|
||||||
* @returns The mangled email address.
|
* @returns The mangled email address.
|
||||||
*/
|
*/
|
||||||
function hide_email($str)
|
function hide_email($str)
|
||||||
|
@ -176,7 +184,7 @@ function hide_email($str)
|
||||||
else
|
else
|
||||||
$hidden_email .= "&#" . ord($str[$i]) . ";";
|
$hidden_email .= "&#" . ord($str[$i]) . ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $hidden_email;
|
return $hidden_email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,18 +222,24 @@ if(makepathsafe($_GET["page"]) !== $_GET["page"])
|
||||||
function renderpage($title, $content, $minimal = false)
|
function renderpage($title, $content, $minimal = false)
|
||||||
{
|
{
|
||||||
global $sitename, $css, $favicon, $user, $isloggedin, $navlinks, $admindetails, $start_time, $pageindex;
|
global $sitename, $css, $favicon, $user, $isloggedin, $navlinks, $admindetails, $start_time, $pageindex;
|
||||||
|
|
||||||
$html = "<!DOCTYPE HTML>
|
$html = "<!DOCTYPE HTML>
|
||||||
<html><head>
|
<html><head>
|
||||||
<meta charset='utf-8' />
|
<meta charset='utf-8' />
|
||||||
<title>$title</title>
|
<title>$title</title>
|
||||||
<link rel='shortcut icon' href='$favicon' />
|
<link rel='shortcut icon' href='$favicon' />";
|
||||||
<style>$css</style>
|
if(preg_match("/^[^\/]*\/\/|^\//", $cs))
|
||||||
</head><body>
|
{
|
||||||
";
|
$html .= "\n\t\t<link rel='stylesheet' href='$css' />\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$html .= "\n\t\t<style>$css</style>\n";
|
||||||
|
}
|
||||||
|
$html .= "</head><body>\n";
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
|
|
||||||
if($minimal)
|
if($minimal)
|
||||||
{
|
{
|
||||||
$html .= "$content
|
$html .= "$content
|
||||||
|
@ -237,7 +251,7 @@ function renderpage($title, $content, $minimal = false)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$html .= "<nav>\n";
|
$html .= "<nav>\n";
|
||||||
|
|
||||||
if($isloggedin)
|
if($isloggedin)
|
||||||
$html .= "\t\tLogged in as $user. <a href='index.php?action=logout'>Logout</a>. | \n";
|
$html .= "\t\tLogged in as $user. <a href='index.php?action=logout'>Logout</a>. | \n";
|
||||||
else
|
else
|
||||||
|
@ -261,7 +275,7 @@ function renderpage($title, $content, $minimal = false)
|
||||||
$html .= "\t\t<a href='" . str_replace("{page}", $_GET["page"], $url) . "'>$display</a>\n";
|
$html .= "\t\t<a href='" . str_replace("{page}", $_GET["page"], $url) . "'>$display</a>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= " </nav>
|
$html .= " </nav>
|
||||||
<h1 class='sitename'>$sitename</h1>
|
<h1 class='sitename'>$sitename</h1>
|
||||||
$content
|
$content
|
||||||
|
@ -271,19 +285,19 @@ function renderpage($title, $content, $minimal = false)
|
||||||
<p>This wiki is managed by <a href='mailto:" . hide_email($admindetails["email"]) . "'>" . $admindetails["name"] . "</a>.</p>
|
<p>This wiki is managed by <a href='mailto:" . hide_email($admindetails["email"]) . "'>" . $admindetails["name"] . "</a>.</p>
|
||||||
</footer>
|
</footer>
|
||||||
<datalist id='allpages'>\n";
|
<datalist id='allpages'>\n";
|
||||||
|
|
||||||
foreach($pageindex as $pagename => $pagedetails)
|
foreach($pageindex as $pagename => $pagedetails)
|
||||||
{
|
{
|
||||||
$html .= "\t\t<option value='$pagename' />\n";
|
$html .= "\t\t<option value='$pagename' />\n";
|
||||||
}
|
}
|
||||||
$html .= "\t</datalist>";
|
$html .= "\t</datalist>";
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
$gentime = microtime(true) - $start_time;
|
$gentime = microtime(true) - $start_time;
|
||||||
$html .= "\n\t<!-- Took $gentime seconds to generate -->
|
$html .= "\n\t<!-- Took $gentime seconds to generate -->
|
||||||
</head></html>";
|
</head></html>";
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +328,7 @@ function renderpage($title, $content, $minimal = false)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modified by Starbeamrainbowlabs (starbeamrainbowlabs)
|
* Modified by Starbeamrainbowlabs (starbeamrainbowlabs)
|
||||||
*
|
*
|
||||||
* Changed bold to use single asterisks
|
* Changed bold to use single asterisks
|
||||||
* Changed italics to use single underscores
|
* Changed italics to use single underscores
|
||||||
* Added one to add the heading levels (no <h1> tags allowed)
|
* Added one to add the heading levels (no <h1> tags allowed)
|
||||||
|
@ -431,7 +445,7 @@ switch($_GET["action"])
|
||||||
http_response_code(203);
|
http_response_code(203);
|
||||||
header("location: index.php?page=" . $_GET["page"]);
|
header("location: index.php?page=" . $_GET["page"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$isloggedin and !$anonedits)
|
if(!$isloggedin and !$anonedits)
|
||||||
{
|
{
|
||||||
//future let the user view the page source instead
|
//future let the user view the page source instead
|
||||||
|
@ -450,14 +464,14 @@ switch($_GET["action"])
|
||||||
{
|
{
|
||||||
$title = "Editing " . $_GET["page"];
|
$title = "Editing " . $_GET["page"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$pagetext = "";
|
$pagetext = "";
|
||||||
if(isset($pageindex->$_GET["page"]))
|
if(isset($pageindex->$_GET["page"]))
|
||||||
{
|
{
|
||||||
$pagetext = file_get_contents($filename);
|
$pagetext = file_get_contents($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = "<h1>$title</h1>";
|
$content = "<h1>$title</h1>";
|
||||||
if(!$isloggedin and $anonedits)
|
if(!$isloggedin and $anonedits)
|
||||||
{
|
{
|
||||||
|
@ -469,7 +483,7 @@ switch($_GET["action"])
|
||||||
</form>";
|
</form>";
|
||||||
exit(renderpage("$title - $sitename", $content));
|
exit(renderpage("$title - $sitename", $content));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "save":
|
case "save":
|
||||||
if(!$editing)
|
if(!$editing)
|
||||||
{
|
{
|
||||||
|
@ -502,14 +516,14 @@ switch($_GET["action"])
|
||||||
$pageindex->$_GET["page"]->lasteditor = utf8_encode($user);
|
$pageindex->$_GET["page"]->lasteditor = utf8_encode($user);
|
||||||
else
|
else
|
||||||
$pageindex->$_GET["page"]->lasteditor = utf8_encode("anonymous");
|
$pageindex->$_GET["page"]->lasteditor = utf8_encode("anonymous");
|
||||||
|
|
||||||
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
|
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
if(isset($_GET["newpage"]))
|
if(isset($_GET["newpage"]))
|
||||||
http_response_code(201);
|
http_response_code(201);
|
||||||
else
|
else
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
|
|
||||||
header("location: index.php?page=" . $_GET["page"]);
|
header("location: index.php?page=" . $_GET["page"]);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -520,7 +534,7 @@ switch($_GET["action"])
|
||||||
<p>Please tell the administrator of this wiki (" . $admindetails["name"] . ") about this problem.</p>"));
|
<p>Please tell the administrator of this wiki (" . $admindetails["name"] . ") about this problem.</p>"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "list":
|
case "list":
|
||||||
$title = "All Pages";
|
$title = "All Pages";
|
||||||
$content = " <h1>$title on $sitename</h1>
|
$content = " <h1>$title on $sitename</h1>
|
||||||
|
@ -545,7 +559,15 @@ switch($_GET["action"])
|
||||||
$content .= " </table>";
|
$content .= " </table>";
|
||||||
exit(renderpage("$title - $sitename", $content));
|
exit(renderpage("$title - $sitename", $content));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "delete":
|
||||||
|
exit(renderpage("Deleting $pagename - $sitename", "Coming soon..."));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "dodelete":
|
||||||
|
exit("Coming soon...");
|
||||||
|
break;
|
||||||
|
|
||||||
case "help":
|
case "help":
|
||||||
$title = "Help - $sitename";
|
$title = "Help - $sitename";
|
||||||
$content = " <h1>$sitename Help</h1>
|
$content = " <h1>$sitename Help</h1>
|
||||||
|
@ -573,7 +595,7 @@ switch($_GET["action"])
|
||||||
</table>";
|
</table>";
|
||||||
exit(renderpage($title, $content));
|
exit(renderpage($title, $content));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "login":
|
case "login":
|
||||||
$title = "Login to $sitename";
|
$title = "Login to $sitename";
|
||||||
$content = "<h1>Login to $sitename</h1>\n";
|
$content = "<h1>Login to $sitename</h1>\n";
|
||||||
|
@ -588,7 +610,7 @@ switch($_GET["action"])
|
||||||
</form>";
|
</form>";
|
||||||
exit(renderpage($title, $content));
|
exit(renderpage($title, $content));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "checklogin":
|
case "checklogin":
|
||||||
if(isset($_POST["user"]) and isset($_POST["pass"]))
|
if(isset($_POST["user"]) and isset($_POST["pass"]))
|
||||||
{
|
{
|
||||||
|
@ -623,7 +645,7 @@ switch($_GET["action"])
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "logout":
|
case "logout":
|
||||||
$isloggedin = false;
|
$isloggedin = false;
|
||||||
unset($user);
|
unset($user);
|
||||||
|
@ -633,7 +655,7 @@ switch($_GET["action"])
|
||||||
exit(renderpage("Logout Successful", "<h1>Logout Successful</h1>
|
exit(renderpage("Logout Successful", "<h1>Logout Successful</h1>
|
||||||
<p>Logout Successful. You can login again <a href='index.php?action=login'>here</a>.</p>"));
|
<p>Logout Successful. You can login again <a href='index.php?action=login'>here</a>.</p>"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "credits":
|
case "credits":
|
||||||
$title = "Credits - $sitename";
|
$title = "Credits - $sitename";
|
||||||
$content = "<h1>$sitename credits</h1>
|
$content = "<h1>$sitename credits</h1>
|
||||||
|
@ -642,7 +664,7 @@ switch($_GET["action"])
|
||||||
<p>The default favicon is from <a href='//openclipart.org'>Open Clipart</a> by bluefrog23, and can be found <a href='https://openclipart.org/detail/19571/peppermint-candy-by-bluefrog23'>here</a>.</p>";
|
<p>The default favicon is from <a href='//openclipart.org'>Open Clipart</a> by bluefrog23, and can be found <a href='https://openclipart.org/detail/19571/peppermint-candy-by-bluefrog23'>here</a>.</p>";
|
||||||
exit(renderpage($title, $content));
|
exit(renderpage($title, $content));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "hash":
|
case "hash":
|
||||||
if(!isset($_GET["string"]))
|
if(!isset($_GET["string"]))
|
||||||
{
|
{
|
||||||
|
@ -655,7 +677,7 @@ switch($_GET["action"])
|
||||||
exit(renderpage("Hashed string", "<p><code>" . $_GET["string"] . "</code> → <code>" . hash("sha256", $_GET["string"] . "</code></p>")));
|
exit(renderpage("Hashed string", "<p><code>" . $_GET["string"] . "</code> → <code>" . hash("sha256", $_GET["string"] . "</code></p>")));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "view":
|
case "view":
|
||||||
default:
|
default:
|
||||||
//check to make sure that the page exists
|
//check to make sure that the page exists
|
||||||
|
@ -677,13 +699,13 @@ switch($_GET["action"])
|
||||||
}
|
}
|
||||||
$title = $_GET["page"] . " - $sitename";
|
$title = $_GET["page"] . " - $sitename";
|
||||||
$content = "<h1>" . $_GET["page"] . "</h1>";
|
$content = "<h1>" . $_GET["page"] . "</h1>";
|
||||||
|
|
||||||
$slimdown_start = microtime(true);
|
$slimdown_start = microtime(true);
|
||||||
|
|
||||||
$content .= Slimdown::render(file_get_contents($_GET["page"] . ".md"));
|
$content .= Slimdown::render(file_get_contents($_GET["page"] . ".md"));
|
||||||
|
|
||||||
$content .= "\n\t<!-- Took " . (microtime(true) - $slimdown_start) . " seconds to parse markdown -->\n";
|
$content .= "\n\t<!-- Took " . (microtime(true) - $slimdown_start) . " seconds to parse markdown -->\n";
|
||||||
|
|
||||||
if(isset($_GET["printable"]) and $_GET["printable"] === "yes")
|
if(isset($_GET["printable"]) and $_GET["printable"] === "yes")
|
||||||
$minimal = true;
|
$minimal = true;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue