Add 404 page, add meta description

This commit is contained in:
speedie 2023-06-28 18:04:36 +02:00
parent 2ed2cd0d82
commit 77fccc4277
2 changed files with 47 additions and 61 deletions

21
404.php Normal file
View file

@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Page not found.">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="/index.css"/>
<link rel="icon" href="/icons/fav.svg"/>
<title>Page not found</title>
</head>
<body>
<div class="main">
<p>The page you requested was not found. It's possible that it was deleted, moved, or never existed in the first place. If you're unsure, you might want to check the wiki commit history.</p>
<ul>
<li><a href="/index.php">Home</a></li>
<li><a href="https://git.speedie.site/speedie/spmenu">spmenu Git repository</a></li>
<li><a href="https://git.speedie.site/speedie/spmenu-wiki">spmenu wiki Git repository</a></li>
</ul>
</div>
</body>
</html>

View file

@ -44,12 +44,33 @@ function __( $label, $alt_word = null )
return htmlspecialchars($w2_word_set[$label], ENT_QUOTES);
}
function printHeader($title, $action, $bodyclass="")
function truncate($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 printHeader($title, $action, $html, $bodyclass="")
{
// TODO: Improve this garbage, I suck at PHP and this is just stuff I found on the internet.
$nhtml = $html;
$nhtml = preg_replace( '@<p\b[^>]*>(?=.*?<a\b[^>]*>).*?<\@p>@si', '', $nhtml);
$nhtml = preg_replace( '@<(li)[^>]*?>.*?</\\1>@si', '', $nhtml);
$nhtml = preg_replace( '@<(ul)[^>]*?>.*?</\\1>@si', '', $nhtml);
$nhtml = strip_tags($nhtml);
$nhtml = preg_replace('/\s*$^\s*/m', "\n", $nhtml);
$nhtml = truncate($nhtml, 512);
print "<!doctype html>\n";
print "<html lang=\"" . W2_LOCALE . "\">\n";
print " <head>\n";
print " <meta charset=\"" . W2_CHARSET . "\">\n";
print " <meta name=\"description\" content=\"$nhtml\">\n";
print " <link rel=\"icon\" href=\"/icons/fav.svg\"/>\n";
print " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
print " <link type=\"text/css\" rel=\"stylesheet\" href=\"" . BASE_URI . "/" . CSS_FILE ."\" />\n";
@ -65,46 +86,6 @@ function printFooter()
print "</html>";
}
function printDrawer()
{
print " <div id=\"drawer\" class=\"inactive\">\n".
" <a href=\"\" onclick=\"toggleDrawer(); return false;\"><img src=\"/icons/close.svg\" alt=\"".__('Close')."\" title=\"".__('Close')."\" class=\"icon rightaligned\"/></a>\n".
" <div>\n".
"# ".__('Header')." 1<br/>".
"## ".__('Header')." 2<br/>".
"### ".__('Header')." 3<br/>".
"#### ".__('Header')." 4<br/>".
"##### ".__('Header')." 5<br/>".
"###### ".__('Header')." 6<br/>".
"<br/>".
"*".__('Emphasize')."* - <em>".__('Emphasize')."</em><br/>".
"_".__('Emphasize')."* - <em>".__('Emphasize')."</em><br/>".
"**".__('Bold')."** - <strong>".__('Bold')."</strong><br/>".
"__".__('Bold')."__ - <strong>".__('Bold')."</strong><br/>".
"<br/>".
"[[Link to page]]<br/>".
"&lt;http://example.com/&gt;<br/>".
"[link text](http://url)<br/><br/>".
"{{image.jpg}}<br/>".
"![Alt text](/images/image.jpg)<br/>".
"![Alt text](/images/image.jpg \"Optional title\")<br/>".
"<br/>".
"- Unordered list<br/>".
"+ Unordered list<br/>".
"* Unordered list<br/>".
"1. Ordered list<br/>".
"<br/>".
"> Blockquote<br/>".// <blockquote>Blockquotes</blockquote>\n".
"```Code```<br/>". //<pre>Code</pre>\n\n".
"`inline-code`<br/><br/>".
"*** Horizontal rule<br/>".
"--- Horizontal rule<br/>\n".
" </div>\n".
" </div>\n".
" <a id=\"drawer-control\" href=\"\" onclick=\"toggleDrawer(); return false;\">\n".
" </a>\n";
}
// Support functions
function descLengthSort($val_1, $val_2)
@ -164,16 +145,6 @@ function pageURL($page)
function pageLink($page, $title, $attributes="")
{
return "<a href=\"" . pageURL($page) ."\"$attributes>$title</a>";
/* wip
$link_page = $match[1];
$link_filename = PAGES_PATH . "/$link_page.txt";
$link_page_exists = file_exists($link_filename);
if ($link_page_exists)
return "<a href=\"" . pageURL($page) ."\"$attributes>$title</a>";
else
//return "<a href=\"" . SELF . VIEW . "/" . htmlentities($link_page) . "\" class=\"missing-link\">" . htmlentities($link_page) . "</a>";
return "<a href=\"" . pageURL($page) ."\" class=\"missing-link\" . $attributes>$title</a>";
*/
}
function redirectWithMessage($page, $msg)
@ -291,8 +262,9 @@ if ($action === 'view')
}
else
{
$newPage = $page;
$action = 'new';
$newPage = NULL;
include('404.php');
die();
}
}
$oldgitmsg = "";
@ -415,12 +387,9 @@ if ( $action === 'all' )
$title = __($action);
}
// Disable caching on the client (the iPhone is pretty agressive about this
// and it can cause problems with the editing function)
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
printHeader($title, $action);
printHeader($title, $action, $html);
print " <div class=\"titlebar\"><span class=\"title\">$title</span>$datetime";
print " </div>\n";
print " <div class=\"toolbar\">\n";
@ -428,10 +397,6 @@ if ( $action === 'all' )
print " <a href=\"" . SELF . "?action=all\"><img src=\"/icons/list.svg\" alt=\"". __('All') . "\" title=\"". __('All') . "\" class=\"icon\"></a>\n";
print " <form method=\"post\" action=\"" . SELF . "?action=search\">\n";
print " <input class=\"search\" placeholder=\"". __('Search') ."\" size=\"20\" id=\"search\" type=\"text\" name=\"q\" />\n </form>\n";
if ($action === 'edit')
{
printDrawer();
}
print " </div>\n";
if (SIDEBAR_PAGE != '')
{