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)"); return $Database; } function removePrefix($prefix, $html) { return preg_replace("/$prefix.*/", "", $html); } function printCommentField($html, $id, $pageID) { include "config.php"; $html .= "\t\t\t
\n"; $html .= "\t\t\t\t

Comment

\n"; if (isset($_SESSION['username'])) { $html .= "\t\t\t\t\t

Have anything to say? Feel free to comment it below:

\n"; $html .= "\t\t\t\t\t
\n"; $html .= "\t\t\t\t\t\t
\n"; $html .= "\t\t\t\t\t\t

\n"; $html .= "\t\t\t\t\t\t

\n"; $html .= "\t\t\t\t\t
\n"; } else { $html .= "\t\t\t\t\t

To 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
\n"; if ($line['usertype'] == 2) { $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"; } 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
\n"; } } $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\.date.*=.*"(.*)(");/', '/.*@csgen\.allowComments.*=.*"(.*)(");/', '/.*@csgen\.displayTitle.*=.*"(.*)(");/', '/.*@csgen\.displayDate.*=.*"(.*)(");/', '/.*@csgen\.displaySource.*=.*"(.*)(");/', '/.*@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\.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\.span.*<STYLE.*,.*TEXT>\(.*"(.*)".*, "(.*)"\);/': $out = str_replace($matches[0], "$matches[2]", $out); break; case '/.*@csgen\.span.*<STYLE.*,.*HTML>\(.*"(.*)".*, "(.*)"\);/': $out = str_replace($matches[0], "$matches[2]", $out); break; case '/.*@csgen\.div.*<START.*,.*NAME>\(.*"(.*)"\);/': $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], "", $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"; $id = -1; if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']; } $Database = createTables($sqlDB); $DatabaseQuery = $Database->query('SELECT * FROM pages'); $wasFound = 0; $i = 0; $subdir = isset($_GET['endpoint']) ? $_GET['endpoint'] : '/'; while ($line = $DatabaseQuery->fetchArray()) { $endpoint = $line['endpoint']; if ((($endpoint == $subdir || "$endpoint/" == "$subdir") && $id == -1) || ($id != -1 && $i == $id)) { $wasFound = 1; $ret = convertMarkdownToHTML(file_get_contents($line['file'])); $title = $ret->title; $description = $ret->description; if ($title === "") { $title = $instanceName; } if ($description === "") { $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\t\t\n"; $html .= "\t\t\t\n"; $html .= "\t\t\t
\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\tEdit\n"; } if (!isset($_SESSION['type'])) { if ($publicAccountCreation) { $html .= "\t\t\t\tRegister\n"; } $html .= "\t\t\t\tLog in\n"; } else { $Username = $_SESSION['username']; $html .= "\t\t\t\t$Username\n"; $html .= "\t\t\t\tLog out\n"; } if (isset($_SESSION['type']) && $_SESSION['type'] == 2) { $html .= "\t\t\t\tAdministration\n"; } $html .= "\t\t\t
\n"; $html .= "\t\t
\n"; $html .= "\t\n"; $html .= "\t\n"; $html .= "\t\t
\n"; if ($printpage == 1) { $sourceFile = $line['file']; if ($ret->displayTitle == "true" && $ret->title != "") { $html .= "\t\t\t

$ret->title

\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->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\t\t\n"; $html .= "\t\t\t\n"; $html .= "\t\t\t
\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\tEdit\n"; } if (!isset($_SESSION['type'])) { if ($publicAccountCreation) { $html .= "\t\t\t\tRegister\n"; } $html .= "\t\t\t\tLog in\n"; } else { $Username = $_SESSION['username']; $html .= "\t\t\t\t$Username\n"; $html .= "\t\t\t\tLog out\n"; } if (isset($_SESSION['type']) && $_SESSION['type'] == 2) { $html .= "\t\t\t\tAdministration\n"; } $html .= "\t\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); $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); } ?>