diff --git a/public/css/help.css b/public/css/help.css new file mode 100644 index 0000000..c663ec8 --- /dev/null +++ b/public/css/help.css @@ -0,0 +1,73 @@ +:root { + --font-size: 14px; +} + +html { + font-size: var(--font-size); + font-family: sans-serif; +} + +body { + background-image: url('/img/background.jpg'); + padding: 2rem; +} +table { + border-style: none; + padding: 0px; +} +tr:nth-child(even) { + background-color: white; +} +td { + border-style: none; + padding: 3px; + vertical-align: top; +} +td.top { + border-bottom: solid 2px black; +} +td.left { + width: 150px; + border-right: solid 2px black; +} +td.right { + width: 150px; + border-left: solid 2px black; +} +a { + color: #663300; + text-decoration: none; + font-weight: bold; +} +a:hover { + color: #330000; +} +.small { + font: 10px verdana; +} +.highlight { + color: red; +} +.light { + color: #999999; +} +.title { + border: solid 1px black; + background-color: #eeeeee; + font-weight: bold; + padding: 5px; + margin: 3px; +} +.copyright { + border: solid 1px black; + background-color: #eeeeee; + font: 10px verdana; +} + +footer { + display: flex; + justify-content: space-around; + font-size: 0.8rem; + padding: 0.5rem; + margin-top: 2rem; +} diff --git a/public/index.php b/public/index.php index 0f3ce99..36ac667 100644 --- a/public/index.php +++ b/public/index.php @@ -84,7 +84,7 @@ function dotown() if ($controlrow["shownews"] == 1) { $newsrow = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC); $townrow["news"] = '
Latest News
'; - $townrow["news"] .= "[".prettydate($newsrow["postdate"])."]
".nl2br($newsrow["content"]); + $townrow["news"] .= "[".pretty_date($newsrow["postdate"])."]
".nl2br($newsrow["content"]); } // Who's Online. Currently just members. Guests maybe later. diff --git a/src/actions/admin.php b/src/actions/admin.php index c0c30af..938884c 100644 --- a/src/actions/admin.php +++ b/src/actions/admin.php @@ -59,7 +59,7 @@ function donothing() because mistakes in the database content may result in script errors or your game breaking completely. HTML; - admindisplay($page, "Admin Home"); + display_admin($page, "Admin Home"); } function primary() @@ -86,10 +86,10 @@ function primary() $form['gamename'], $form['gamesize'], $form['class1name'], $form['class2name'], $form['class3name'], $form['gameopen'], $form['verifyemail'], $form['gameurl'], $form['adminemail'], $form['shownews'], $form['showonline'], $form['showbabble'] ]); - admindisplay("Settings updated.", "Main Settings"); + display_admin("Settings updated.", "Main Settings"); } else { $errorlist = ul_from_validate_errors($form['errors']); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Main Settings"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Main Settings"); } } @@ -128,7 +128,7 @@ function primary() if ($controlrow["gameopen"] == 1) { $controlrow["open1select"] = "selected=\"selected\" "; } else { $controlrow["open1select"] = ""; } if ($controlrow["gameopen"] == 0) { $controlrow["open0select"] = "selected=\"selected\" "; } else { $controlrow["open0select"] = ""; } - admindisplay(parsetemplate($page, $controlrow), "Main Settings"); + display_admin(parse($page, $controlrow), "Main Settings"); } function items() @@ -143,7 +143,7 @@ function items() } if (!$hasItems) $page .= "No items found.\n"; - admindisplay($page . "", "Edit Items"); + display_admin($page . "", "Edit Items"); } function edititem($id) @@ -163,10 +163,10 @@ function edititem($id) db()->query('UPDATE items SET name=?, type=?, buycost=?, attribute=?, special=? WHERE id=?;', [ $n, $_POST['type'] ?? 0, $bc, $a, $s, $id ]); - admindisplay("Item updated.","Edit Items"); + display_admin("Item updated.","Edit Items"); } else { $errorlist = implode('
', $errors); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Edit Items"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Edit Items"); } } @@ -203,7 +203,7 @@ function edititem($id) if ($item["type"] == 2) { $item["type2select"] = "selected=\"selected\" "; } else { $item["type2select"] = ""; } if ($item["type"] == 3) { $item["type3select"] = "selected=\"selected\" "; } else { $item["type3select"] = ""; } - admindisplay(parsetemplate($page, $item), "Edit Items"); + display_admin(parse($page, $item), "Edit Items"); } function drops() @@ -219,7 +219,7 @@ function drops() if (!$has_drops) { $page .= "No drops found.\n"; } - admindisplay($page . "", "Edit Drops"); + display_admin($page . "", "Edit Drops"); } function editdrop($id) @@ -241,10 +241,10 @@ function editdrop($id) db()->query('UPDATE drops SET name=?, mlevel=?, attribute1=?, attribute2=? WHERE id=?;', [ $n, $ml, $a, $a2, $id ]); - admindisplay("Item updated.","Edit Drops"); + display_admin("Item updated.","Edit Drops"); } else { $errorlist = implode('
', $errors); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Edit Drops"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Edit Drops"); } } @@ -276,7 +276,7 @@ function editdrop($id) defensepower - total defense power HTML; - admindisplay(parsetemplate($page, $drop), "Edit Drops"); + display_admin(parse($page, $drop), "Edit Drops"); } function towns() @@ -292,7 +292,7 @@ function towns() if (!$has_towns) $page .= "No towns found.\n"; - admindisplay($page . "", "Edit Towns"); + display_admin($page . "", "Edit Towns"); } function edittown($id) @@ -322,10 +322,10 @@ function edittown($id) db()->query('UPDATE towns SET name=?, latitude=?, longitude=?, innprice=?, mapprice=?, travelpoints=?, itemslist=? WHERE id=?;', [ $n, $la, $lo, $ip, $mp, $tp, $il, $id ]); - admindisplay("Town updated.", "Edit Towns"); + display_admin("Town updated.", "Edit Towns"); } else { $errorlist = implode('
', $errors); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Edit Towns"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Edit Towns"); } } @@ -348,7 +348,7 @@ function edittown($id) HTML; - admindisplay(parsetemplate($page, $row), "Edit Towns"); + display_admin(parse($page, $row), "Edit Towns"); } function monsters() @@ -376,7 +376,7 @@ function monsters() if (!$has_monsters) { $page .= "No monsters found.\n"; } - admindisplay($page."", "Edit Monster"); + display_admin($page."", "Edit Monster"); } function editmonster($id) @@ -403,10 +403,10 @@ function editmonster($id) db()->query('UPDATE monsters SET name=?, maxhp=?, maxdam=?, armor=?, level=?, maxexp=?, maxgold=?, immune=? WHERE id=?;', [ $n, $mh, $md, $a, $l, $me, $mg, $_POST['immune'] ?? 0, $id ]); - admindisplay("Monster updated.", "Edit monsters"); + display_admin("Monster updated.", "Edit monsters"); } else { $errorlist = implode('
', $errors); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Edit monsters"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Edit monsters"); } } @@ -434,7 +434,7 @@ function editmonster($id) if ($row["immune"] == 2) { $row["immune2select"] = "selected=\"selected\" "; } else { $row["immune2select"] = ""; } if ($row["immune"] == 3) { $row["immune3select"] = "selected=\"selected\" "; } else { $row["immune3select"] = ""; } - admindisplay(parsetemplate($page, $row), "Edit Monsters"); + display_admin(parse($page, $row), "Edit Monsters"); } function spells() @@ -451,7 +451,7 @@ function spells() if (!$has_spells) { $page .= "No spells found.\n"; } - admindisplay($page."", "Edit Spells"); + display_admin($page."", "Edit Spells"); } function editspell($id) @@ -470,10 +470,10 @@ function editspell($id) db()->query('UPDATE spells SET name=?, mp=?, attribute=?, type=? WHERE id=?;', [ $n, $mp, $a, $_POST['type'] ?? 0, $id ]); - admindisplay("Spell updated.", "Edit Spells"); + display_admin("Spell updated.", "Edit Spells"); } else { $errorlist = implode('
', $errors); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Edit Spells"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Edit Spells"); } } @@ -499,7 +499,7 @@ function editspell($id) if ($row["type"] == 4) { $row["type4select"] = "selected=\"selected\" "; } else { $row["type4select"] = ""; } if ($row["type"] == 5) { $row["type5select"] = "selected=\"selected\" "; } else { $row["type5select"] = ""; } - admindisplay(parsetemplate($page, $row), "Edit Spells"); + display_admin(parse($page, $row), "Edit Spells"); } function levels() @@ -522,12 +522,12 @@ function levels() HTML; - admindisplay($page, "Edit Levels"); + display_admin($page, "Edit Levels"); } function editlevel() { - if (!isset($_POST["level"])) admindisplay("No level to edit.", "Edit Levels"); + if (!isset($_POST["level"])) display_admin("No level to edit.", "Edit Levels"); $id = $_POST["level"]; if (isset($_POST["submit"])) { @@ -594,10 +594,10 @@ function editlevel() $three_exp, $three_hp, $three_mp, $three_tp, $three_strength, $three_dexterity, $three_spells, $id ]); - admindisplay("Level updated.", "Edit Levels"); + display_admin("Level updated.", "Edit Levels"); } else { $errorlist = implode('
', $errors); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Edit Spells"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Edit Spells"); } } @@ -652,7 +652,7 @@ function editlevel() HTML; - admindisplay(parsetemplate($page, $row), "Edit Levels"); + display_admin(parse($page, $row), "Edit Levels"); } function users() @@ -669,7 +669,7 @@ function users() if (!$has_users) { $page .= "No spells found.\n"; } - admindisplay($page."", "Edit Users"); + display_admin($page."", "Edit Users"); } function edituser($id) @@ -787,10 +787,10 @@ function edituser($id) $slot3name, $dropcode, $spells, $towns, $id ]); - admindisplay("User updated.", "Edit Users"); + display_admin("User updated.", "Edit Users"); } else { $errorlist = implode('
', $errors); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Edit Users"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Edit Users"); } } @@ -883,7 +883,7 @@ function edituser($id) if ($row["charclass"] == 2) { $row["class2select"] = "selected=\"selected\" "; } else { $row["class2select"] = ""; } if ($row["charclass"] == 3) { $row["class3select"] = "selected=\"selected\" "; } else { $row["class3select"] = ""; } - admindisplay(parsetemplate($page, $row), "Edit Users"); + display_admin(parse($page, $row), "Edit Users"); } function addnews() @@ -898,10 +898,10 @@ function addnews() if (count($errors) === 0) { db()->query('INSERT INTO news (author, content) VALUES (?, ?);', [$userrow['username'], $c]); - admindisplay("News post added.", "Add News"); + display_admin("News post added.", "Add News"); } else { $errorlist = implode('
', $errors); - admindisplay("Errors:
$errorlist

Please go back and try again.", "Add News"); + display_admin("Errors:
$errorlist

Please go back and try again.", "Add News"); } } @@ -914,5 +914,5 @@ function addnews() HTML; - admindisplay($page, "Add News"); + display_admin($page, "Add News"); } diff --git a/src/actions/forum.php b/src/actions/forum.php index e358455..c95b3fd 100644 --- a/src/actions/forum.php +++ b/src/actions/forum.php @@ -44,7 +44,7 @@ function showthread($id, $start) $page = "
\n"; while ($row = $posts->fetchArray(SQLITE3_ASSOC)) { - $page .= "\n"; + $page .= "\n"; } $page .= "
Forum :: ".$title['title']."
".$row["author"]."

".prettyforumdate($row["postdate"])."
".nl2br($row["content"])."
".$row["author"]."

".pretty_date($row["postdate"])."
".nl2br($row["content"])."

"; $page .= "
Reply To This Thread:

"; diff --git a/src/actions/help.php b/src/actions/help.php index 741c9e7..830fb69 100644 --- a/src/actions/help.php +++ b/src/actions/help.php @@ -246,7 +246,7 @@ function main() [ Top ] HTML; - display_help(parsetemplate($page, $controlrow)); + display_help(parse($page, $controlrow)); } function items() @@ -489,12 +489,16 @@ function levels() Experience points listed are total values up until that point. All other values are just the new amount that you gain for each level. HTML; - display_help(parsetemplate($page, $controlrow)); + display_help(parse($page, $controlrow)); } function display_help(string $content) { global $controlrow; - $template = parsetemplate(gettemplate('help'), $controlrow); - echo parsetemplate($template, ['content' => $content]); + echo render('help', [ + 'control' => $controlrow, + 'content' => $content, + 'version' => VERSION, + 'build' => BUILD + ]); } diff --git a/src/lib.php b/src/lib.php index 5355ec5..c714063 100644 --- a/src/lib.php +++ b/src/lib.php @@ -44,46 +44,30 @@ function render(string $path_to_base_view, array $data = []): string|false return ob_get_clean(); } -function gettemplate($templatename) { // SQL query for the template. - - $filename = __DIR__ . "/../templates/" . $templatename . ".php"; - include("$filename"); - return $template; - +/** + * Replace tags with given content. + */ +function parse(string $template, array $array): string +{ + return strtr($template, array_combine( + array_map(fn($key) => "{{{$key}}}", array_keys($array)), + array_values($array) + )); } -function parsetemplate($template, $array) { // Replace template with proper content. - - foreach($array as $a => $b) { - $template = str_replace("{{{$a}}}", $b, $template); - } - return $template; - -} - -function getmicrotime() { // Used for timing script operations. - - list($usec, $sec) = explode(" ",microtime()); - return ((float)$usec + (float)$sec); - -} - -function prettydate($uglydate) { // Change the MySQL date format (YYYY-MM-DD) into something friendlier. - - return date("F j, Y", mktime(0,0,0,substr($uglydate, 5, 2),substr($uglydate, 8, 2),substr($uglydate, 0, 4))); - -} - -function prettyforumdate($uglydate) { // Change the MySQL date format (YYYY-MM-DD) into something friendlier. - - return date("F j, Y", mktime(0,0,0,substr($uglydate, 5, 2),substr($uglydate, 8, 2),substr($uglydate, 0, 4))); - -} - -function is_email($email) { // Thanks to "mail(at)philipp-louis.de" from php.net! - - return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email)); - +/** + * Change the SQLite3 datetime format (YYYY-MM-DD HH:MM:SS) into something friendlier. + */ +function pretty_date(string $uglydate): string +{ + return date("l, F j, Y", mktime( + 0, + 0, + 0, + substr($uglydate, 5, 2), // Month + substr($uglydate, 8, 2), // Day + substr($uglydate, 0, 4) // Year + )); } /** @@ -97,14 +81,12 @@ function make_safe(string $content): string /** * Finalize admin page and output to browser. */ -function admindisplay($content, $title) +function display_admin($content, $title) { - global $controlrow; - echo render('admin', [ "title" => $title, "content" => $content, - "totaltime" => round(getmicrotime() - START, 4), + "totaltime" => round(microtime(true) - START, 4), "numqueries" => db()->count, "version" => VERSION, "build" => BUILD @@ -227,7 +209,7 @@ function display($content, $title, bool $topnav = true, bool $leftnav = true, bo 'rightnav' => $rightnav ? render('rightnav', ['user' => $userrow]) : '', "leftnav" => $leftnav ? render('leftnav', ['user' => $userrow]) : '', "topnav" => $topnav, - "totaltime" => round(getmicrotime() - START, 4), + "totaltime" => round(microtime(true) - START, 4), "numqueries" => db()->count, "version" => VERSION, "build" => BUILD, diff --git a/templates/help.php b/templates/help.php index 8d69293..285c75e 100644 --- a/templates/help.php +++ b/templates/help.php @@ -1,85 +1,27 @@ - - {{gamename}} Help - + + + <?= $control['gamename'] ?> Help + -

{{gamename}} Help

- [ Return to the game ] +

Help

+ [ Back to Help ]
+ [ Return to Game ]


- {{content}} +

- - - + -HTML;