exec("CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, username TEXT, password TEXT, usertype INT, primaryadmin INT, numberofcomments INT, lastused TEXT, created TEXT, ip TEXT, useragent TEXT)");
/* comments table
* id (INTEGER PRIMARY KEY)
* date (TEXT)
* data (TEXT)
* username (TEXT)
* usertype (INT)
* page (INT)
*/
$Database->exec("CREATE TABLE IF NOT EXISTS comments(id INTEGER PRIMARY KEY, date TEXT, data TEXT, username TEXT, usertype INT, page INT)");
/* pages table
* id (INTEGER PRIMARY KEY)
* username (TEXT)
* date (TEXT)
* endpoint (TEXT)
* file (TEXT)
*/
$Database->exec("CREATE TABLE IF NOT EXISTS pages(id INTEGER PRIMARY KEY, username TEXT, date TEXT, endpoint TEXT, file TEXT)");
/* modified table
* id (INTEGER PRIMARY KEY)
* pageid (INT)
* author (TEXT)
* endpoint (TEXT)
* file (TEXT)
*/
$Database->exec("CREATE TABLE IF NOT EXISTS modified(id INTEGER PRIMARY KEY, pageid INT, author TEXT, endpoint TEXT, file TEXT)");
/* history table
* id (INTEGER PRIMARY KEY)
* pageid (INT)
* username (TEXT)
* date (TEXT)
* endpoint (TEXT)
* file (TEXT)
*/
$Database->exec("CREATE TABLE IF NOT EXISTS history(id INTEGER PRIMARY KEY, pageid INT, username TEXT, date TEXT, endpoint TEXT, file TEXT)");
return $Database;
}
function removePrefix($prefix, $html) {
return preg_replace("/$prefix.*/", "", $html);
}
function printCommentField($html, $id, $pageID) {
include "config.php";
$html .= "\t\t\t
\n";
return $html;
}
function convertMarkdownToHTML($contents) {
include "config.php";
$ret = new parsedMarkdown();
$parser = new MarkdownExtra;
$parser->no_markup = true;
$specialSyntax = array(
'/.*@csgen\.title.*=.*"(.*)(");/',
'/.*@csgen\.description.*=.*"(.*)(");/',
'/.*@csgen\.favicon.*=.*"(.*)(");/',
'/.*@csgen\.license.*=.*"(.*)(");/',
'/.*@csgen\.date.*=.*"(.*)(");/',
'/.*@csgen\.allowComments.*=.*"(.*)(");/',
'/.*@csgen\.displayTitle.*=.*"(.*)(");/',
'/.*@csgen\.displayDate.*=.*"(.*)(");/',
'/.*@csgen\.displaySource.*=.*"(.*)(");/',
'/.*@csgen\.displayLicense.*=.*"(.*)(");/',
'/.*@csgen\.span.*<STYLE.*,.*TEXT>\(.*"(.*)".*, "(.*)"\);/',
'/.*@csgen\.span.*<STYLE.*,.*HTML>\(.*"(.*)".*, "(.*)"\);/',
'/.*@csgen\.inline.*<HTML>\(.*"(.*)"\);/',
'/.*@csgen\.inline.*<CSS>\(.*"(.*)"\);/',
'/.*@csgen\.inline.*<JAVASCRIPT>\(.*"(.*)"\);/',
'/.*@csgen\.image.*<SIZE.*,.*PATH>\(.*"(.*)".*, "(.*)"\);/',
'/.*@csgen\.div.*<START.*,.*NAME>\(.*"(.*)"\);/',
'/.*@csgen\.div.*<END.*,.*NAME>\(.*"(.*)"\);/',
'/.*@csgen\.div.*<STYLE.*,.*NAME>\(.*"(.*)".*, "(.*)"\);/',
'/.*@csgen\.include.*<HTML>\(.*"(.*)"\);/',
'/.*@csgen\.include.*<CSS>\(.*"(.*)"\);/',
'/.*@csgen\.include.*<JAVASCRIPT>\(.*"(.*)"\);/',
);
$out = $parser->transform($contents);
foreach ($specialSyntax as $pattern) {
$matches = array();
if (preg_match($pattern, $out, $matches)) {
switch ($pattern) {
case '/.*@csgen\.title.*=.*"(.*)(");/':
$ret->title = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.description.*=.*"(.*)(");/':
$ret->description = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.favicon.*=.*"(.*)(");/':
$ret->favicon = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.license.*=.*"(.*)(");/':
$ret->license = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.date.*=.*"(.*)(");/':
$ret->date = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.allowComments.*=.*"(.*)(");/':
$ret->allowComments = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.displayTitle.*=.*"(.*)(");/':
$ret->displayTitle = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.displayDate.*=.*"(.*)(");/':
$ret->displayDate = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.displaySource.*=.*"(.*)(");/':
$ret->displaySource = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.displayLicense.*=.*"(.*)(");/':
$ret->displayLicense = $matches[1];
$out = str_replace($matches[0], '', $out);
break;
case '/.*@csgen\.span.*<STYLE.*,.*TEXT>\(.*"(.*)".*, "(.*)"\);/':
$out = str_replace($matches[0], "", $out);
break;
case '/.*@csgen\.div.*<END.*,.*NAME>\(.*"(.*)"\);/':
$out = str_replace($matches[0], "
", $out);
break;
case '/.*@csgen\.div.*<STYLE.*,.*NAME>\(.*"(.*)".*, "(.*)"\);/':
$out = str_replace($matches[0], "", $out);
break;
case '/.*@csgen\.inline.*<HTML>\(.*"(.*)"\);/':
$out = str_replace($matches[0], "$matches[1]", $out);
break;
case '/.*@csgen\.inline.*<CSS>\(.*"(.*)"\);/':
$out = str_replace($matches[0], "", $out);
break;
case '/.*@csgen\.inline.*<JAVASCRIPT>\(.*"(.*)"\);/':
$out = str_replace($matches[0], "", $out);
break;
case '/.*@csgen\.image.*<SIZE.*,.*PATH>\(.*"(.*)".*, "(.*)"\);/':
$imgres = array();
if (preg_match('/([0-9]*)x([0-9]*)/', $matches[1], $imgres)) {
$out = str_replace($matches[0], "\n";
if ($printpage == 1) {
$License = $ret->license;
$sourceFile = $line['file'];
if ($ret->displayTitle == "true" && $ret->title != "") {
$html .= "\t\t\t\n";
}
if ($ret->displayDate == "true" && $ret->date != "") {
$html .= "\t\t\t\t
$ret->date\n";
}
$html .= "\t\t\t\t$ret->data\n";
if ($ret->displaySource == "true") {
$html .= "\t\t\t\tSource\n";
}
if ($ret->displayLicense == "true") {
$html .= "\t\t\t\tThis page is licensed under the $License license.";
}
if ($ret->allowComments == "true") {
$html = printCommentField($html, $line['id'], $i);
}
}
break;
}
$i++;
}
if ($wasFound != 1) {
$title = $instanceName;
$description = $instanceDescription;
$html .= "\n";
$html .= "\n";
$html .= "\t
\n";
$html .= "\t\t
\n";
$html .= "\t\t
\n";
if (file_exists($Icon)) $html .= "\t\t
\n";
if (file_exists($Stylesheet)) $html .= "\t\t
\n";
if (file_exists($javaScript)) $html .= "\t\t\n";
$html .= "\t\t
$title\n";
$html .= "\t\t
\n";
$endpointFound = 0;
$HeaderDatabaseQuery = $Database->query('SELECT * FROM pages');
while ($head = $HeaderDatabaseQuery->fetchArray()) {
if ($head['endpoint'] == "/_head") {
$Header = convertMarkdownToHTML(file_get_contents($head['file']));
$endpointFound = 1;
$html .= "\t\t
$Header->data\n";
break;
}
}
if ($endpointFound == 0) {
if (file_exists($Logo)) $html .= "\t\t\t
\n";
$html .= "\t\t\t
$instanceName\n";
}
$html .= "\t\t
\n";
$html .= "\t\t\n";
$html .= "\t\n";
$html .= "\t\n";
$html .= "\t\t
\n";
if ($printpage == 1) {
$ErrDatabaseQuery = $Database->query('SELECT * FROM pages');
$foundErrorPage = 0;
while ($err = $ErrDatabaseQuery->fetchArray()) {
if ($err['endpoint'] == "/_404") {
$foundErrorPage = 1;
$Err = convertMarkdownToHTML(file_get_contents($err['file']));
$html .= "\t\t\t$Err->data\n";
break;
}
}
if ($foundErrorPage == 0) {
$html .= "\t\t\t
404
\n\t\t\t\t
404: The page you requested could not be found.
\n";
}
}
}
return $html;
}
function printFooter($html) {
include "config.php";
$html .= "\t\t
\n";
$html .= "\t\n";
$html .= "\t
\n";
$html .= "\n";
return "$html";
}
function checkIfAdminExists() {
include "config.php";
$adminExists = 0;
$Database = createTables($sqlDB);
$DatabaseQuery = $Database->query('SELECT * FROM users');
if (!is_dir($documentLocation)) mkdir($documentLocation, 0777, true);
if (!is_dir($attachmentLocation)) mkdir($attachmentLocation, 0777, true);
if (!is_dir($historyLocation)) mkdir($historyLocation, 0777, true);
if (!is_dir($modifiedLocation)) mkdir($modifiedLocation, 0777, true);
$adminExists = 0;
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['usertype'] == 2) {
$adminExists = 1;
break;
}
}
return $adminExists;
}
function getIPAddress() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
return $_SERVER['REMOTE_ADDR'];
}
}
function getUserAgent() {
return $_SERVER['HTTP_USER_AGENT'];
}
function generatePassword($pwd) {
return password_hash($pwd, PASSWORD_DEFAULT);
}
?>
Comment
\n"; if (isset($_SESSION['username'])) { $html .= "\t\t\t\t\tHave anything to say? Feel free to comment it below:
\n"; $html .= "\t\t\t\t\t\n"; } else { $html .= "\t\t\t\t\tTo post a comment, you must be logged in.
\n"; } // print the actual list $Database = createTables($sqlDB); $DatabaseQuery = $Database->query('SELECT * FROM comments'); while ($line = $DatabaseQuery->fetchArray()) { if ($line['page'] == $id) { $username = $line['username']; $date = $line['date']; $data = $line['data']; $cid = $line['id']; $html .= "\t\t\t\t\t$username on $date:\n"; if ($line['username'] == $_SESSION['username'] || $_SESSION['type'] == 2) { $html .= "Remove
\n"; } $html .= "\t\t\t\t\t\t\n"; } else { $html .= "\t\t\t\t\t\t$username on $date:\n"; if ($line['username'] == $_SESSION['username'] || $_SESSION['type'] == 2) { $html .= "Remove
\n"; } $html .= "\t\t\t\t\t\t\n"; } $html .= "\t\t\t\t\t\t$data
\n"; $html .= "\t\t\t\t\t