2024-01-02 03:55:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
define('BASE', str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']));
|
|
|
|
spl_autoload_register(function($class){ require str_replace('\\', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php'; });
|
|
|
|
use md\MarkdownExtra;
|
|
|
|
error_reporting(-1);
|
|
|
|
|
|
|
|
class parsedMarkdown {
|
|
|
|
public $title = '';
|
|
|
|
public $description = '';
|
2024-01-22 13:07:18 +01:00
|
|
|
public $favicon = '';
|
|
|
|
public $license = '';
|
2024-01-02 03:55:23 +01:00
|
|
|
public $date = '';
|
|
|
|
public $data = '';
|
2024-03-24 21:19:28 +01:00
|
|
|
public $authors = array();
|
2024-05-24 22:35:25 +02:00
|
|
|
public $tags = array();
|
2024-01-02 03:55:23 +01:00
|
|
|
public $allowComments = false;
|
2024-01-02 05:12:19 +01:00
|
|
|
public $displayTitle = false;
|
|
|
|
public $displayDate = false;
|
2024-01-10 07:58:37 +01:00
|
|
|
public $displaySource = true;
|
2024-03-24 21:19:28 +01:00
|
|
|
public $displayAuthors = false;
|
2024-01-22 13:07:18 +01:00
|
|
|
public $displayLicense = false;
|
2024-03-25 22:10:10 +01:00
|
|
|
public $redirectTo = '';
|
2024-03-24 22:12:51 +01:00
|
|
|
public $pages = array();
|
|
|
|
public $isFeed = false;
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function createTables($sqlDB) {
|
|
|
|
$Database = new SQLite3($sqlDB);
|
|
|
|
|
|
|
|
/* users table
|
|
|
|
* id (INTEGER PRIMARY KEY)
|
|
|
|
* username (TEXT)
|
|
|
|
* password (TEXT)
|
|
|
|
* usertype (INT)
|
|
|
|
* primaryadmin (INT)
|
|
|
|
* numberofcomments (INT)
|
|
|
|
* lastused (TEXT)
|
|
|
|
* created (TEXT)
|
|
|
|
* ip (TEXT)
|
|
|
|
* useragent (TEXT)
|
2024-02-05 22:27:22 +01:00
|
|
|
* key (TEXT)
|
2024-01-02 03:55:23 +01:00
|
|
|
*/
|
2024-02-05 22:27:22 +01:00
|
|
|
$Database->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, key TEXT)");
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
/* 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)");
|
|
|
|
|
2024-02-05 19:01:24 +01:00
|
|
|
/* requests table
|
2024-02-04 22:43:39 +01:00
|
|
|
* id (INTEGER PRIMARY KEY)
|
|
|
|
* pageid (INT)
|
2024-02-05 19:01:24 +01:00
|
|
|
* username (TEXT)
|
|
|
|
* date (TEXT)
|
|
|
|
* message (TEXT)
|
2024-02-04 22:43:39 +01:00
|
|
|
* endpoint (TEXT)
|
|
|
|
* file (TEXT)
|
|
|
|
*/
|
2024-02-05 19:01:24 +01:00
|
|
|
$Database->exec("CREATE TABLE IF NOT EXISTS requests(id INTEGER PRIMARY KEY, pageid INT, username TEXT, date TEXT, message TEXT, endpoint TEXT, file TEXT)");
|
2024-02-04 22:43:39 +01:00
|
|
|
|
|
|
|
/* 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)");
|
|
|
|
|
2024-01-02 03:55:23 +01:00
|
|
|
return $Database;
|
|
|
|
}
|
|
|
|
|
|
|
|
function removePrefix($prefix, $html) {
|
|
|
|
return preg_replace("/$prefix.*/", "", $html);
|
|
|
|
}
|
|
|
|
|
2024-03-24 22:12:51 +01:00
|
|
|
function printFeed($ret, $subdir) {
|
|
|
|
include "config.php";
|
|
|
|
|
|
|
|
$title = $ret->title;
|
|
|
|
$desc = $ret->description;
|
|
|
|
$pages = $ret->pages;
|
|
|
|
|
|
|
|
$rss = "";
|
|
|
|
$rss .= "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
|
|
|
|
$rss .= "<channel>\n";
|
|
|
|
$rss .= "\t<title>$title</title>\n";
|
|
|
|
$rss .= "\t<description>$desc</description>\n";
|
|
|
|
$rss .= "\t<atom:link href=\"$subdir\" rel=\"self\" type=\"application/rss+xml\"/>\n";
|
|
|
|
|
|
|
|
$rDatabase = createTables($sqlDB);
|
|
|
|
$rDatabaseQuery = $rDatabase->query('SELECT * FROM pages');
|
|
|
|
|
|
|
|
while ($rline = $rDatabaseQuery->fetchArray()) {
|
|
|
|
foreach ($pages as $i => $it) {
|
|
|
|
if ($rline['endpoint'] == $it) {
|
|
|
|
// is our page
|
|
|
|
$page = convertMarkdownToHTML(file_get_contents($rline['file']));
|
|
|
|
|
|
|
|
$ptitle = $page->title;
|
|
|
|
$pdesc = $page->description;
|
|
|
|
$pdata = $page->data;
|
|
|
|
$pdate = $page->date;
|
|
|
|
|
|
|
|
if ($pdate != "") {
|
|
|
|
$pdate = date('r', strtotime($pdate));
|
|
|
|
} else {
|
|
|
|
$pdate = "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
$rss .= "\t<item>\n";
|
|
|
|
$rss .= "\t\t<title>$ptitle</title>\n";
|
|
|
|
$rss .= "\t\t<link>$it</link>\n";
|
|
|
|
$rss .= "\t\t<guid>$it</guid>\n";
|
|
|
|
$rss .= "\t\t<pubDate>$pdate</pubDate>\n";
|
|
|
|
$rss .= "\t\t<description>\n";
|
|
|
|
$rss .= "\t\t\t<![CDATA[\n";
|
|
|
|
$rss .= "\t\t\t\t$pdata\n";
|
|
|
|
$rss .= "\t\t\t]]>\n";
|
|
|
|
$rss .= "\t\t</description>\n";
|
|
|
|
$rss .= "\t</item>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$rss .= "</channel>\n";
|
|
|
|
$rss .= "</rss>";
|
|
|
|
|
2024-03-25 22:02:10 +01:00
|
|
|
header('Content-type: application/xml');
|
|
|
|
|
2024-03-24 22:12:51 +01:00
|
|
|
print "$rss";
|
|
|
|
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2024-01-03 11:59:01 +01:00
|
|
|
function printCommentField($html, $id, $pageID) {
|
2024-01-02 03:55:23 +01:00
|
|
|
include "config.php";
|
|
|
|
|
|
|
|
$html .= "\t\t\t<div id=\"comment_section\" class=\"comment_section\">\n";
|
|
|
|
$html .= "\t\t\t\t<h2 id=\"comment_head\" class=\"comment_head\">Comment</h2>\n";
|
|
|
|
|
|
|
|
if (isset($_SESSION['username'])) {
|
|
|
|
$html .= "\t\t\t\t\t<p id=\"comment_p\" class=\"comment_p\">Have anything to say? Feel free to comment it below:</p>\n";
|
2024-02-27 17:39:43 +01:00
|
|
|
$html .= "\t\t\t\t\t<form method=\"POST\" class=\"commentWriteForm\" action=\"/comment.php?id=$id&retid=$pageID\" method=\"post\">\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
$html .= "\t\t\t\t\t\t<br><textarea id=\"commentWriteArea\" class=\"commentWriteArea\" name=\"body\" rows=\"8\" cols=\"50\"></textarea>\n";
|
|
|
|
$html .= "\t\t\t\t\t\t<br><br><input type=\"submit\" value=\"Comment\">\n";
|
|
|
|
$html .= "\t\t\t\t\t\t<br><br>\n";
|
|
|
|
$html .= "\t\t\t\t\t</form>\n";
|
|
|
|
} else {
|
|
|
|
$html .= "\t\t\t\t\t<p id=\"comment_p\" class=\"comment_p\">To post a comment, you must be logged in.</p>\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<div class=\"comment\">\n";
|
|
|
|
|
|
|
|
if ($line['usertype'] == 2) {
|
2024-01-03 11:20:47 +01:00
|
|
|
$html .= "\t\t\t\t\t\t<p style=\"text-align: left;\"><span class=\"commentAuthorMod\">$username</span> on <span class=\"commentDate\">$date:</span>\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
|
2024-03-31 01:54:11 +01:00
|
|
|
if (isset($_SESSION['username']) && isset($_SESSION['type'])) {
|
|
|
|
if ($line['username'] == htmlspecialchars($_SESSION['username']) || htmlspecialchars($_SESSION['type']) == 2) {
|
|
|
|
$html .= "<a id=\"commentRemove\" href=\"/remove-comment.php?id=$cid&retid=$pageID\">Remove</a></p>\n";
|
|
|
|
}
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t\t\t</p>\n";
|
|
|
|
} else {
|
2024-01-03 11:20:47 +01:00
|
|
|
$html .= "\t\t\t\t\t\t<p style=\"text-align: left;\"><span class=\"commentAuthor\">$username</span> on <span class=\"commentDate\">$date:</span>\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
|
2024-03-31 01:54:11 +01:00
|
|
|
if (isset($_SESSION['username']) && isset($_SESSION['type'])) {
|
|
|
|
if ($line['username'] == htmlspecialchars($_SESSION['username']) || htmlspecialchars($_SESSION['type']) == 2) {
|
|
|
|
$html .= "<a id=\"commentRemove\" href=\"/remove-comment.php?id=$cid&retid=$pageID\">Remove</a></p>\n";
|
|
|
|
}
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t\t\t</p>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t\t\t<p class=\"commentData\">$data</p>\n";
|
|
|
|
$html .= "\t\t\t\t\t</div>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t</div>\n";
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertMarkdownToHTML($contents) {
|
|
|
|
include "config.php";
|
|
|
|
|
|
|
|
$ret = new parsedMarkdown();
|
|
|
|
$parser = new MarkdownExtra;
|
2024-05-16 23:37:11 +02:00
|
|
|
$parser->no_markup = false;
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
$specialSyntax = array(
|
2024-01-03 10:06:10 +01:00
|
|
|
'/.*@csgen\.title.*=.*"(.*)(");/',
|
|
|
|
'/.*@csgen\.description.*=.*"(.*)(");/',
|
2024-01-22 13:07:18 +01:00
|
|
|
'/.*@csgen\.favicon.*=.*"(.*)(");/',
|
|
|
|
'/.*@csgen\.license.*=.*"(.*)(");/',
|
2024-01-03 10:06:10 +01:00
|
|
|
'/.*@csgen\.date.*=.*"(.*)(");/',
|
2024-05-24 22:35:25 +02:00
|
|
|
'/.*@csgen\.author.*=.*"(.*)(");/',
|
|
|
|
'/.*@csgen\.tags.*=.*"(.*)(");/',
|
2024-03-24 21:19:28 +01:00
|
|
|
'/.*@csgen\.addAuthor.*=.*"(.*)(");/',
|
2024-05-24 22:35:25 +02:00
|
|
|
'/.*@csgen\.addSummary.*=.*"(.*)(");/',
|
2024-01-03 10:06:10 +01:00
|
|
|
'/.*@csgen\.allowComments.*=.*"(.*)(");/',
|
|
|
|
'/.*@csgen\.displayTitle.*=.*"(.*)(");/',
|
|
|
|
'/.*@csgen\.displayDate.*=.*"(.*)(");/',
|
2024-01-10 07:58:37 +01:00
|
|
|
'/.*@csgen\.displaySource.*=.*"(.*)(");/',
|
2024-03-24 21:19:28 +01:00
|
|
|
'/.*@csgen\.displayAuthors.*=.*"(.*)(");/',
|
2024-01-22 13:07:18 +01:00
|
|
|
'/.*@csgen\.displayLicense.*=.*"(.*)(");/',
|
2024-03-24 22:12:51 +01:00
|
|
|
'/.*@csgen\.markAsFeed.*=.*"(.*)(");/',
|
|
|
|
'/.*@csgen\.includePage.*=.*"(.*)(");/',
|
2024-03-25 22:10:10 +01:00
|
|
|
'/.*@csgen\.redirectTo.*=.*"(.*)(");/',
|
2024-01-03 10:06:10 +01:00
|
|
|
'/.*@csgen\.span.*<STYLE.*,.*TEXT>\(.*"(.*)".*, "(.*)"\);/',
|
|
|
|
'/.*@csgen\.span.*<STYLE.*,.*HTML>\(.*"(.*)".*, "(.*)"\);/',
|
|
|
|
'/.*@csgen\.inline.*<HTML>\(.*"(.*)"\);/',
|
2024-01-03 10:40:51 +01:00
|
|
|
'/.*@csgen\.inline.*<CSS>\(.*"(.*)"\);/',
|
|
|
|
'/.*@csgen\.inline.*<JAVASCRIPT>\(.*"(.*)"\);/',
|
2024-01-03 10:06:10 +01:00
|
|
|
'/.*@csgen\.image.*<SIZE.*,.*PATH>\(.*"(.*)".*, "(.*)"\);/',
|
|
|
|
'/.*@csgen\.div.*<START.*,.*NAME>\(.*"(.*)"\);/',
|
|
|
|
'/.*@csgen\.div.*<END.*,.*NAME>\(.*"(.*)"\);/',
|
|
|
|
'/.*@csgen\.div.*<STYLE.*,.*NAME>\(.*"(.*)".*, "(.*)"\);/',
|
2024-01-03 10:40:51 +01:00
|
|
|
'/.*@csgen\.include.*<HTML>\(.*"(.*)"\);/',
|
|
|
|
'/.*@csgen\.include.*<CSS>\(.*"(.*)"\);/',
|
|
|
|
'/.*@csgen\.include.*<JAVASCRIPT>\(.*"(.*)"\);/',
|
2024-01-02 03:55:23 +01:00
|
|
|
);
|
|
|
|
|
2024-01-03 05:55:36 +01:00
|
|
|
$out = $parser->transform($contents);
|
2024-05-24 22:35:25 +02:00
|
|
|
$maxit = 1000;
|
2024-01-02 03:55:23 +01:00
|
|
|
|
2024-05-24 22:35:25 +02:00
|
|
|
while ((preg_match('/.*@csgen.*;/', $out)) && $maxit > 0) {
|
|
|
|
$maxit--;
|
2024-03-24 21:19:28 +01:00
|
|
|
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\.displayAuthors.*=.*"(.*)(");/':
|
|
|
|
$ret->displayAuthors = $matches[1];
|
|
|
|
$out = str_replace($matches[0], '', $out);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.displayLicense.*=.*"(.*)(");/':
|
|
|
|
$ret->displayLicense = $matches[1];
|
|
|
|
$out = str_replace($matches[0], '', $out);
|
|
|
|
|
2024-03-24 22:12:51 +01:00
|
|
|
break;
|
|
|
|
case '/.*@csgen\.markAsFeed.*=.*"(.*)(");/':
|
|
|
|
$ret->isFeed = $matches[1];
|
|
|
|
$out = str_replace($matches[0], '', $out);
|
|
|
|
|
2024-03-24 21:19:28 +01:00
|
|
|
break;
|
|
|
|
case '/.*@csgen\.addAuthor.*=.*"(.*)(");/':
|
|
|
|
$ret->authors[] = $matches[1];
|
|
|
|
$out = str_replace($matches[0], '', $out);
|
2024-05-24 22:35:25 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.addSummary.*=.*"(.*)(");/':
|
|
|
|
$page = $matches[1];
|
|
|
|
|
|
|
|
$Database = createTables($sqlDB);
|
|
|
|
$DatabaseQuery = $Database->query('SELECT * FROM pages');
|
|
|
|
|
|
|
|
while ($line = $DatabaseQuery->fetchArray()) {
|
|
|
|
if ($line['endpoint'] != $page) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$converted = convertMarkdownToHTML(file_get_contents($line['file']));
|
|
|
|
$title = $converted->title;
|
|
|
|
$description = $converted->description;
|
|
|
|
$author_a = $converted->authors;
|
|
|
|
$authors = "";
|
|
|
|
|
|
|
|
foreach ($author_a as $i => $it) {
|
|
|
|
$authors .= $it;
|
|
|
|
|
|
|
|
if (count($author_a) != $i + 1) {
|
|
|
|
$authors .= ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$tags_a = $converted->tags;
|
|
|
|
$tags = "";
|
|
|
|
|
|
|
|
foreach ($tags_a as $i => $it) {
|
|
|
|
$tags .= $it;
|
|
|
|
|
|
|
|
if (count($tags_a) != $i + 1) {
|
|
|
|
$tags .= ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$date = $converted->date;
|
|
|
|
$license = $converted->license;
|
|
|
|
|
2024-05-25 00:34:22 +02:00
|
|
|
$text = "<div class=\"summary\" id=\"summary-" . $line['id'] . "\" style=\"cursor: pointer;\" onclick=\"location.href='" . $line['endpoint'] . "';\">\n";
|
2024-05-24 22:35:25 +02:00
|
|
|
|
|
|
|
if ($title != "") {
|
|
|
|
$text .= "\t<h2 id=\"summary-title-" . $line['id'] . "\">$title</h2>\n";
|
|
|
|
} else {
|
|
|
|
$text .= "\t<h2 id=\"summary-title-" . $line['id'] . "\">" . $line['endpoint'] . "</h2>\n";
|
|
|
|
}
|
|
|
|
|
2024-05-24 23:39:56 +02:00
|
|
|
for ($i = 0; $i < 4; $i++) {
|
|
|
|
$sep = " • ";
|
|
|
|
|
|
|
|
if ($i == 0 && $authors != "") {
|
|
|
|
$text .= "\t<small id=\"summary-author-" . $line['id'] . "\">by $authors$sep</small>\n";
|
|
|
|
continue;
|
|
|
|
} else if ($i == 1 && $date != "") {
|
|
|
|
$text .= "\t<small id=\"summary-date-" . $line['id'] . "\">$date";
|
|
|
|
$sep = "";
|
|
|
|
} else if ($i == 2 && $tags != "") {
|
|
|
|
$text .= "$sep</small>\n";
|
|
|
|
$text .= "\t<small id=\"summary-tags-" . $line['id'] . "\">$tags";
|
|
|
|
$sep = "";
|
|
|
|
} else if ($i == 3 && $license != "") {
|
|
|
|
$text .= "$sep</small>\n";
|
|
|
|
$text .= "\t<small id=\"summary-license-" . $line['id'] . "\">$license";
|
2024-05-24 23:44:30 +02:00
|
|
|
$text .= "</small>\n";
|
|
|
|
} else if ($i == 3) {
|
|
|
|
$text .= "</small>\n";
|
2024-05-24 23:39:56 +02:00
|
|
|
}
|
2024-05-24 22:35:25 +02:00
|
|
|
}
|
|
|
|
|
2024-05-24 23:44:30 +02:00
|
|
|
if ($description != "") {
|
|
|
|
$text .= "\t<p id=\"summary-description-" . $line['id'] . "\">$description</p>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-24 22:35:25 +02:00
|
|
|
$text .= "</div>\n";
|
|
|
|
$out = str_replace($matches[0], $text, $out);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.author.*=.*"(.*)(");/':
|
|
|
|
$ret->authors[] = explode(',', $matches[1]);
|
|
|
|
|
|
|
|
if (count($ret->authors) == 1) {
|
|
|
|
$ret->authors = $ret->authors[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$out = str_replace($matches[0], '', $out);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.tags.*=.*"(.*)(");/':
|
|
|
|
$ret->tags[] = explode(',', $matches[1]);
|
|
|
|
|
|
|
|
if (count($ret->tags) == 1) {
|
|
|
|
$ret->tags = $ret->tags[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$out = str_replace($matches[0], '', $out);
|
2024-03-24 21:19:28 +01:00
|
|
|
|
2024-03-24 22:12:51 +01:00
|
|
|
break;
|
|
|
|
case '/.*@csgen\.includePage.*=.*"(.*)(");/':
|
|
|
|
$ret->pages[] = $matches[1];
|
|
|
|
$out = str_replace($matches[0], '', $out);
|
|
|
|
|
2024-03-25 22:10:10 +01:00
|
|
|
break;
|
|
|
|
case '/.*@csgen\.redirectTo.*=.*"(.*)(");/':
|
|
|
|
$ret->redirectTo = $matches[1];
|
|
|
|
$out = str_replace($matches[0], '', $out);
|
|
|
|
|
2024-03-24 21:19:28 +01:00
|
|
|
break;
|
|
|
|
case '/.*@csgen\.span.*<STYLE.*,.*TEXT>\(.*"(.*)".*, "(.*)"\);/':
|
|
|
|
$cssCode = htmlspecialchars_decode($matches[1]);
|
|
|
|
$out = str_replace($matches[0], "<span style=\"$cssCode\">$matches[2]</span>", $out);
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.span.*<STYLE.*,.*HTML>\(.*"(.*)".*, "(.*)"\);/':
|
|
|
|
$cssCode = htmlspecialchars_decode($matches[1]);
|
|
|
|
$htmlCode = htmlspecialchars_decode($matches[2]);
|
|
|
|
$out = str_replace($matches[0], "<span style=\"$cssCode\">$htmlCode</span>", $out);
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.div.*<START.*,.*NAME>\(.*"(.*)"\);/':
|
|
|
|
$out = str_replace($matches[0], "<div class=\"$matches[1]\">", $out);
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.div.*<END.*,.*NAME>\(.*"(.*)"\);/':
|
|
|
|
$out = str_replace($matches[0], "</div>", $out);
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.div.*<STYLE.*,.*NAME>\(.*"(.*)".*, "(.*)"\);/':
|
|
|
|
$cssCode = htmlspecialchars_decode($matches[1]);
|
|
|
|
$out = str_replace($matches[0], "<style>\n.$matches[2] {\n\t$cssCode\n}\n</style>\n<div class=\"$matches[2]\">", $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], "<style>$cssCode</style>", $out);
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.inline.*<JAVASCRIPT>\(.*"(.*)"\);/':
|
|
|
|
$javascriptCode = htmlspecialchars_decode($matches[1]);
|
|
|
|
$out = str_replace($matches[0], "<script>$javascriptCode</script>", $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], "<img width=\"$imgres[1]\" height=\"$imgres[2]\" src=\"$matches[2]\">", $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], "<link rel=\"stylesheet\" href=\"$matches[1]\">", $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case '/.*@csgen\.include.*<JAVASCRIPT>\(.*"(.*)"\);/':
|
|
|
|
if (file_exists($matches[1])) {
|
|
|
|
$out = str_replace($matches[0], "<script src=\"$matches[1]\"></script>", $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-16 23:47:24 +02:00
|
|
|
$ret->data = htmlspecialchars_decode($out);
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function printHeader($html, $printpage) {
|
|
|
|
include "config.php";
|
|
|
|
|
2024-03-23 22:34:24 +01:00
|
|
|
$pid = -1;
|
2024-01-03 11:32:22 +01:00
|
|
|
$id = -1;
|
|
|
|
|
|
|
|
if (isset($_REQUEST['id'])) {
|
2024-02-05 21:46:50 +01:00
|
|
|
$id = htmlspecialchars($_REQUEST['id']);
|
2024-01-03 11:32:22 +01:00
|
|
|
}
|
|
|
|
|
2024-01-02 03:55:23 +01:00
|
|
|
$Database = createTables($sqlDB);
|
|
|
|
$DatabaseQuery = $Database->query('SELECT * FROM pages');
|
|
|
|
|
|
|
|
$wasFound = 0;
|
2024-01-03 11:32:22 +01:00
|
|
|
|
2024-01-14 19:02:19 +01:00
|
|
|
$title = $instanceName;
|
|
|
|
$description = $instanceDescription;
|
|
|
|
|
2024-03-23 22:34:24 +01:00
|
|
|
$subdir = "";
|
|
|
|
if (isset($_GET['endpoint'])) {
|
|
|
|
$subdir = $_GET['endpoint'];
|
|
|
|
} else if (isset($_SERVER['REQUEST_URI'])) {
|
|
|
|
$subdir = '/' . trim(strtok($_SERVER['REQUEST_URI'], '?'), '/');
|
|
|
|
} else {
|
|
|
|
$subdir = '/';
|
|
|
|
}
|
|
|
|
|
2024-01-02 03:55:23 +01:00
|
|
|
while ($line = $DatabaseQuery->fetchArray()) {
|
|
|
|
$endpoint = $line['endpoint'];
|
2024-03-23 22:34:24 +01:00
|
|
|
if ((($endpoint == $subdir || "$endpoint/" == "$subdir") && $id == -1) || ($id != -1 && $printpage == 1)) {
|
|
|
|
$pid = $line['id'];
|
|
|
|
|
|
|
|
if ($pid != $id && $id != -1) {
|
|
|
|
$pid = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-01-02 03:55:23 +01:00
|
|
|
$wasFound = 1;
|
|
|
|
$ret = convertMarkdownToHTML(file_get_contents($line['file']));
|
|
|
|
|
2024-01-03 23:54:53 +01:00
|
|
|
$title = $ret->title;
|
|
|
|
$description = $ret->description;
|
2024-01-22 13:07:18 +01:00
|
|
|
$favicon = $ret->favicon;
|
2024-01-02 03:55:23 +01:00
|
|
|
|
2024-01-22 13:07:18 +01:00
|
|
|
if ($title === "") {
|
|
|
|
$title = $instanceName;
|
|
|
|
}
|
2024-01-03 23:54:53 +01:00
|
|
|
|
2024-01-22 13:07:18 +01:00
|
|
|
if ($description === "") {
|
|
|
|
$description = $instanceDescription;
|
|
|
|
}
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
$html .= "<!DOCTYPE html>\n";
|
|
|
|
$html .= "<html>\n";
|
2024-03-31 04:01:38 +02:00
|
|
|
$html .= "\t<head id=\"header\">\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
$html .= "\t\t<meta name=\"description\" content=\"$description\">\n";
|
|
|
|
$html .= "\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
|
|
|
|
2024-01-22 13:07:18 +01:00
|
|
|
if ($favicon != "") {
|
|
|
|
$html .= "\t\t<link rel=\"icon\" href=\"$favicon\"/>\n";
|
|
|
|
} else if (file_exists($Icon)) {
|
|
|
|
$html .= "\t\t<link rel=\"icon\" href=\"/$Icon\" />\n";
|
|
|
|
}
|
2024-01-22 16:22:50 +01:00
|
|
|
|
2024-01-02 03:55:23 +01:00
|
|
|
if (file_exists($Stylesheet)) $html .= "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"/$Stylesheet\"/>\n";
|
|
|
|
if (file_exists($javaScript)) $html .= "\t\t<script src=\"/$javaScript\"></script>\n";
|
|
|
|
|
|
|
|
$html .= "\t\t<title>$title</title>\n";
|
2024-03-31 04:01:38 +02:00
|
|
|
$html .= "\t\t<div id=\"bar_title\" class=\"bar_title\">\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
$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<small id='title'>$Header->data</small>\n";
|
2024-05-30 18:16:41 +02:00
|
|
|
}
|
|
|
|
if ($head['endpoint'] == "/_css") {
|
|
|
|
$html .= "<style>\n";
|
|
|
|
$html .= htmlspecialchars_decode(file_get_contents($head['file']));
|
|
|
|
$html .= "</style>\n";
|
|
|
|
}
|
|
|
|
if ($head['endpoint'] == "/_js") {
|
|
|
|
$html .= "<script>\n";
|
|
|
|
$html .= htmlspecialchars_decode(file_get_contents($head['file']));
|
|
|
|
$html .= "</script>\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($endpointFound == 0) {
|
|
|
|
if (file_exists($Logo)) $html .= "\t\t\t<img src=\"/$Logo\" id=\"titleLogo\" class=\"title\" width=\"$logoHeaderSize\">\n";
|
|
|
|
|
2024-01-03 23:59:33 +01:00
|
|
|
$html .= "\t\t\t<small id='title'><a id='title' href=\"/\">$instanceName</a></small>\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t</div>\n";
|
2024-03-31 04:01:38 +02:00
|
|
|
$html .= "\t\t<div id=\"bar_menu\" class=\"bar_menu\">\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
$html .= "\t\t\t<script>\n";
|
|
|
|
$html .= "\t\t\t\tfunction pelem() {\n";
|
|
|
|
$html .= "\t\t\t\t\tdocument.getElementById(\"dropdown\").classList.toggle(\"show\");\n";
|
|
|
|
$html .= "\t\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t\t\n";
|
|
|
|
$html .= "\t\t\t\twindow.onclick = function(event) {\n";
|
|
|
|
$html .= "\t\t\t\tif (!event.target.matches('.actionmenu')) {\n";
|
|
|
|
$html .= "\t\t\t\t\tvar dropdowns = document.getElementsByClassName(\"dropdown-content\");\n";
|
|
|
|
$html .= "\t\t\t\t\tvar i;\n";
|
|
|
|
$html .= "\t\t\t\t\tfor (i = 0; i < dropdowns.length; i++) {\n";
|
|
|
|
$html .= "\t\t\t\t\t\tvar openDropdown = dropdowns[i];\n";
|
|
|
|
$html .= "\t\t\t\t\t\tif (openDropdown.classList.contains('show')) {\n";
|
|
|
|
$html .= "\t\t\t\t\t\t\topenDropdown.classList.remove('show');\n";
|
|
|
|
$html .= "\t\t\t\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t</script>\n";
|
|
|
|
|
|
|
|
$html .= "\t\t\t<button onclick=\"pelem()\" class=\"actionmenu\">☰</button>\n";
|
|
|
|
$html .= "\t\t\t<div id=\"dropdown\" class=\"dropdown-content\">\n";
|
|
|
|
|
|
|
|
$ListDatabaseQuery = $Database->query('SELECT * FROM pages');
|
|
|
|
while ($list = $ListDatabaseQuery->fetchArray()) {
|
|
|
|
if ($list['endpoint'] == "/_list") {
|
|
|
|
$List = convertMarkdownToHTML(file_get_contents($list['file']));
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t$List->data\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_SESSION['type']) && $_SESSION['type'] == 2) {
|
2024-02-04 02:34:43 +01:00
|
|
|
$html .= "\t\t\t\t<a id='edit' href=\"/edit.php?id=$pid\">Edit</a>\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($_SESSION['type'])) {
|
|
|
|
if ($publicAccountCreation) {
|
|
|
|
$html .= "\t\t\t\t<a id='register' href=\"/register.php\">Register</a>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t<a id='login' href=\"/login.php\">Log in</a>\n";
|
|
|
|
} else {
|
2024-02-05 21:46:50 +01:00
|
|
|
$Username = htmlspecialchars($_SESSION['username']);
|
2024-01-02 03:55:23 +01:00
|
|
|
$html .= "\t\t\t\t<a id='username' href=\"/account.php\">$Username</a>\n";
|
|
|
|
$html .= "\t\t\t\t<a id='logout' href=\"/login.php?logout=true\">Log out</a>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_SESSION['type']) && $_SESSION['type'] == 2) {
|
|
|
|
$html .= "\t\t\t\t<a id='administration' href=\"/admin.php\">Administration</a>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t</div>\n";
|
|
|
|
|
|
|
|
$html .= "\t\t</div>\n";
|
|
|
|
$html .= "\t</head>\n";
|
|
|
|
$html .= "\t<body>\n";
|
2024-04-15 09:34:56 +02:00
|
|
|
$html .= "\t\t<div id=\"content\" class=\"content\">\n<br><br>\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
if ($printpage == 1) {
|
2024-03-25 22:10:10 +01:00
|
|
|
if ($ret->redirectTo != '') {
|
|
|
|
$path = $ret->redirectTo;
|
|
|
|
header("Location: $path");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2024-01-22 13:07:18 +01:00
|
|
|
$License = $ret->license;
|
2024-01-10 07:58:37 +01:00
|
|
|
$sourceFile = $line['file'];
|
|
|
|
|
2024-03-24 22:12:51 +01:00
|
|
|
if ($ret->isFeed == "true") {
|
|
|
|
printFeed($ret, $subdir);
|
|
|
|
}
|
|
|
|
|
2024-01-02 03:55:23 +01:00
|
|
|
if ($ret->displayTitle == "true" && $ret->title != "") {
|
|
|
|
$html .= "\t\t\t<h1 id=\"header\">$ret->title</h1>\n";
|
|
|
|
}
|
|
|
|
if ($ret->displayDate == "true" && $ret->date != "") {
|
|
|
|
$html .= "\t\t\t\t<p id=\"date\">$ret->date</h1>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t$ret->data\n";
|
|
|
|
|
2024-01-10 07:58:37 +01:00
|
|
|
if ($ret->displaySource == "true") {
|
2024-05-25 17:51:17 +02:00
|
|
|
$html .= "\t\t\t\t<button id=\"source\" onclick=\"window.location.href='/$sourceFile'\">Source</button>\n";
|
2024-01-10 07:58:37 +01:00
|
|
|
}
|
|
|
|
|
2024-02-05 19:05:00 +01:00
|
|
|
if (isset($_SESSION['type'])) {
|
2024-05-25 17:51:17 +02:00
|
|
|
$html .= "\t\t\t\t<button id=\"modify\" onclick=\"window.location.href='/edit-page.php?id=$pid'\">Request changes</button>\n";
|
2024-02-05 19:05:00 +01:00
|
|
|
}
|
2024-02-05 19:01:24 +01:00
|
|
|
|
2024-03-24 21:19:28 +01:00
|
|
|
if ($ret->displayLicense == "true" && $License != '') {
|
2024-01-22 13:07:18 +01:00
|
|
|
$html .= "\t\t\t\tThis page is licensed under the $License license.";
|
|
|
|
}
|
|
|
|
|
2024-03-24 21:19:28 +01:00
|
|
|
if ($ret->displayAuthors == "true" && $ret->authors) {
|
|
|
|
$html .= "\t\t\t\t<h2 id=\"authors\">Authors</h2>\n";
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t<p>";
|
|
|
|
|
|
|
|
foreach ($ret->authors as $i => $it) {
|
|
|
|
$html .= "$it";
|
|
|
|
|
|
|
|
if (count($ret->authors) != $i + 1) {
|
|
|
|
$html .= ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t</p>\n";
|
|
|
|
}
|
|
|
|
|
2024-01-02 03:55:23 +01:00
|
|
|
if ($ret->allowComments == "true") {
|
2024-03-23 22:34:24 +01:00
|
|
|
$html = printCommentField($html, $line['id'], $pid);
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
2024-01-03 11:59:01 +01:00
|
|
|
|
2024-03-23 22:34:24 +01:00
|
|
|
break;
|
2024-01-03 11:32:22 +01:00
|
|
|
|
2024-03-23 22:34:24 +01:00
|
|
|
}
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($wasFound != 1) {
|
|
|
|
$title = $instanceName;
|
|
|
|
$description = $instanceDescription;
|
|
|
|
|
|
|
|
$html .= "<!DOCTYPE html>\n";
|
|
|
|
$html .= "<html>\n";
|
|
|
|
$html .= "\t<head>\n";
|
|
|
|
$html .= "\t\t<meta name=\"description\" content=\"$description\">\n";
|
|
|
|
$html .= "\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
|
|
|
|
|
|
|
if (file_exists($Icon)) $html .= "\t\t<link rel=\"icon\" href=\"/$Icon\" />\n";
|
|
|
|
if (file_exists($Stylesheet)) $html .= "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"/$Stylesheet\"/>\n";
|
|
|
|
if (file_exists($javaScript)) $html .= "\t\t<script src=\"/$javaScript\"></script>\n";
|
|
|
|
|
|
|
|
$html .= "\t\t<title>$title</title>\n";
|
2024-03-31 04:01:38 +02:00
|
|
|
$html .= "\t\t<div id=\"bar_title\" class=\"bar_title\">\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
$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<small id='title'>$Header->data</small>\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($endpointFound == 0) {
|
|
|
|
if (file_exists($Logo)) $html .= "\t\t\t<img src=\"/$Logo\" id=\"titleLogo\" class=\"title\" width=\"$logoHeaderSize\">\n";
|
|
|
|
|
2024-01-03 23:59:33 +01:00
|
|
|
$html .= "\t\t\t<small id='title'><a id='title' href=\"/\">$instanceName</a></small>\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t</div>\n";
|
2024-03-31 04:01:38 +02:00
|
|
|
$html .= "\t\t<div id=\"bar_menu\" class=\"bar_menu\">\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
$html .= "\t\t\t<script>\n";
|
|
|
|
$html .= "\t\t\t\tfunction pelem() {\n";
|
|
|
|
$html .= "\t\t\t\t\tdocument.getElementById(\"dropdown\").classList.toggle(\"show\");\n";
|
|
|
|
$html .= "\t\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t\t\n";
|
|
|
|
$html .= "\t\t\t\twindow.onclick = function(event) {\n";
|
|
|
|
$html .= "\t\t\t\tif (!event.target.matches('.actionmenu')) {\n";
|
|
|
|
$html .= "\t\t\t\t\tvar dropdowns = document.getElementsByClassName(\"dropdown-content\");\n";
|
|
|
|
$html .= "\t\t\t\t\tvar i;\n";
|
|
|
|
$html .= "\t\t\t\t\tfor (i = 0; i < dropdowns.length; i++) {\n";
|
|
|
|
$html .= "\t\t\t\t\t\tvar openDropdown = dropdowns[i];\n";
|
|
|
|
$html .= "\t\t\t\t\t\tif (openDropdown.classList.contains('show')) {\n";
|
|
|
|
$html .= "\t\t\t\t\t\t\topenDropdown.classList.remove('show');\n";
|
|
|
|
$html .= "\t\t\t\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t}\n";
|
|
|
|
$html .= "\t\t\t</script>\n";
|
|
|
|
|
|
|
|
$html .= "\t\t\t<button onclick=\"pelem()\" class=\"actionmenu\">☰</button>\n";
|
|
|
|
$html .= "\t\t\t<div id=\"dropdown\" class=\"dropdown-content\">\n";
|
|
|
|
|
|
|
|
$ListDatabaseQuery = $Database->query('SELECT * FROM pages');
|
|
|
|
while ($list = $ListDatabaseQuery->fetchArray()) {
|
|
|
|
if ($list['endpoint'] == "/_list") {
|
|
|
|
$List = convertMarkdownToHTML(file_get_contents($list['file']));
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t$List->data\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_SESSION['type']) && $_SESSION['type'] == 2) {
|
|
|
|
$html .= "\t\t\t\t<a id='edit' href=\"/edit.php\">Edit</a>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($_SESSION['type'])) {
|
|
|
|
if ($publicAccountCreation) {
|
|
|
|
$html .= "\t\t\t\t<a id='register' href=\"/register.php\">Register</a>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t\t<a id='login' href=\"/login.php\">Log in</a>\n";
|
|
|
|
} else {
|
2024-02-05 21:46:50 +01:00
|
|
|
$Username = htmlspecialchars($_SESSION['username']);
|
2024-01-02 03:55:23 +01:00
|
|
|
$html .= "\t\t\t\t<a id='username' href=\"/account.php\">$Username</a>\n";
|
|
|
|
$html .= "\t\t\t\t<a id='logout' href=\"/login.php?logout=true\">Log out</a>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_SESSION['type']) && $_SESSION['type'] == 2) {
|
|
|
|
$html .= "\t\t\t\t<a id='administration' href=\"/admin.php\">Administration</a>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t\t</div>\n";
|
|
|
|
|
|
|
|
$html .= "\t\t</div>\n";
|
|
|
|
$html .= "\t</head>\n";
|
|
|
|
$html .= "\t<body>\n";
|
2024-03-31 04:01:38 +02:00
|
|
|
$html .= "\t\t<div id=\"content\" class=\"content\">\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
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";
|
2024-03-23 22:34:24 +01:00
|
|
|
|
|
|
|
break;
|
2024-01-02 03:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($foundErrorPage == 0) {
|
|
|
|
$html .= "\t\t\t<h1>404</h1>\n\t\t\t\t<p>404: The page you requested could not be found.</p>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function printFooter($html) {
|
|
|
|
include "config.php";
|
|
|
|
|
|
|
|
$html .= "\t\t</div>\n";
|
|
|
|
$html .= "\t</body>\n";
|
2024-03-31 04:01:38 +02:00
|
|
|
$html .= "\t<footer id='footer'>\n";
|
2024-01-02 03:55:23 +01:00
|
|
|
$html .= "\t\t<div class='footer'>\n";
|
|
|
|
|
|
|
|
$Database = createTables($sqlDB);
|
|
|
|
$DatabaseQuery = $Database->query('SELECT * FROM pages');
|
|
|
|
|
|
|
|
$wasFound = 0;
|
|
|
|
while ($line = $DatabaseQuery->fetchArray()) {
|
|
|
|
$endpoint = $line['endpoint'];
|
|
|
|
if ($endpoint == "/_foot") {
|
|
|
|
$wasFound = 1;
|
|
|
|
$ret = convertMarkdownToHTML(file_get_contents($line['file']));
|
|
|
|
$html .= "\t\t\t$ret->data\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($wasFound == 0) {
|
|
|
|
$html .= "\t\t\t<small class='footerText' id='footerText'>$footerText</p>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= "\t\t</div>\n";
|
|
|
|
$html .= "\t</footer>\n";
|
|
|
|
$html .= "</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);
|
2024-02-04 22:43:39 +01:00
|
|
|
if (!is_dir($historyLocation)) mkdir($historyLocation, 0777, true);
|
2024-02-05 19:01:24 +01:00
|
|
|
if (!is_dir($requestLocation)) mkdir($requestLocation, 0777, true);
|
2024-01-02 03:55:23 +01:00
|
|
|
|
|
|
|
$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'];
|
|
|
|
}
|
|
|
|
|
2024-02-05 19:01:24 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-02 03:55:23 +01:00
|
|
|
function generatePassword($pwd) {
|
|
|
|
return password_hash($pwd, PASSWORD_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|