", $out);
break;
case '/.*@csgen\.inline.*<HTML>\(.*"(.*)"\);/':
$htmlCode = htmlspecialchars_decode($matches[1]);
$out = str_replace($matches[0], "$htmlCode", $out);
break;
case '/.*@csgen\.inline.*<CSS>\(.*"(.*)"\);/':
$cssCode = htmlspecialchars_decode($matches[1]);
$out = str_replace($matches[0], "", $out);
break;
case '/.*@csgen\.inline.*<JAVASCRIPT>\(.*"(.*)"\);/':
$javascriptCode = htmlspecialchars_decode($matches[1]);
$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], "
", $out);
}
break;
case '/.*@csgen\.include.*<HTML>\(.*"(.*)"\);/':
if (file_exists($matches[1])) {
$out = str_replace($matches[0], file_get_contents($matches[1]), $out);
}
break;
case '/.*@csgen\.include.*<CSS>\(.*"(.*)"\);/':
if (file_exists($matches[1])) {
$out = str_replace($matches[0], "
", $out);
}
break;
case '/.*@csgen\.include.*<JAVASCRIPT>\(.*"(.*)"\);/':
if (file_exists($matches[1])) {
$out = str_replace($matches[0], "", $out);
}
break;
}
}
}
}
$ret->data = $out;
return $ret;
}
function printHeader($html, $printpage) {
include "config.php";
$pid = -1;
$id = -1;
if (isset($_REQUEST['id'])) {
$id = htmlspecialchars($_REQUEST['id']);
}
$Database = createTables($sqlDB);
$DatabaseQuery = $Database->query('SELECT * FROM pages');
$wasFound = 0;
$title = $instanceName;
$description = $instanceDescription;
$subdir = "";
if (isset($_GET['endpoint'])) {
$subdir = $_GET['endpoint'];
} else if (isset($_SERVER['REQUEST_URI'])) {
$subdir = '/' . trim(strtok($_SERVER['REQUEST_URI'], '?'), '/');
} else {
$subdir = '/';
}
while ($line = $DatabaseQuery->fetchArray()) {
$endpoint = $line['endpoint'];
if ((($endpoint == $subdir || "$endpoint/" == "$subdir") && $id == -1) || ($id != -1 && $printpage == 1)) {
$pid = $line['id'];
if ($pid != $id && $id != -1) {
$pid = -1;
continue;
}
$wasFound = 1;
$ret = convertMarkdownToHTML(file_get_contents($line['file']));
$title = $ret->title;
$description = $ret->description;
$favicon = $ret->favicon;
if ($title === "") {
$title = $instanceName;
}
if ($description === "") {
$description = $instanceDescription;
}
$html .= "\n";
$html .= "\n";
$html .= "\t\n";
$html .= "\t\t
\n";
if (file_exists($javaScript)) $html .= "\t\t\n";
$html .= "\t\t
\n";
$html .= "\t\t\n";
$html .= "\t\n";
$html .= "\t\n";
$html .= "\t\t
\n
\n";
if ($printpage == 1) {
if ($ret->redirectTo != '') {
$path = $ret->redirectTo;
header("Location: $path");
die();
}
$License = $ret->license;
$sourceFile = $line['file'];
if ($ret->isFeed == "true") {
printFeed($ret, $subdir);
}
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 (isset($_SESSION['type'])) {
$html .= "\t\t\t\tRequest changes\n";
}
if ($ret->displayLicense == "true" && $License != '') {
$html .= "\t\t\t\tThis page is licensed under the $License license.";
}
if ($ret->displayAuthors == "true" && $ret->authors) {
$html .= "\t\t\t\t
Authors
\n";
$html .= "\t\t\t\t
";
foreach ($ret->authors as $i => $it) {
$html .= "$it";
if (count($ret->authors) != $i + 1) {
$html .= ", ";
}
}
$html .= "\t\t\t\t
\n";
}
if ($ret->allowComments == "true") {
$html = printCommentField($html, $line['id'], $pid);
}
}
break;
}
}
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($requestLocation)) mkdir($requestLocation, 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 truncateText($text, $chars) {
if (strlen($text) <= $chars) {
return $text;
}
$text = $text." ";
$text = substr($text,0,$chars);
$text = substr($text,0,strrpos($text,' '));
$text = $text."...";
return $text;
}
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 (isset($_SESSION['username']) && isset($_SESSION['type'])) { if ($line['username'] == htmlspecialchars($_SESSION['username']) || htmlspecialchars($_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 (isset($_SESSION['username']) && isset($_SESSION['type'])) { if ($line['username'] == htmlspecialchars($_SESSION['username']) || htmlspecialchars($_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