From f4c84ad7fc981643d952a4fb4abfcdb85fccf621 Mon Sep 17 00:00:00 2001 From: Dimtion Date: Wed, 20 Jan 2016 10:57:07 +0100 Subject: Create 404 template Solve #430 for links --- inc/shaarli.css | 15 ++++++++++++++- index.php | 19 ++++++++++++++----- tpl/404.html | 17 +++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 tpl/404.html diff --git a/inc/shaarli.css b/inc/shaarli.css index d6bbdbc1..96e2cae1 100644 --- a/inc/shaarli.css +++ b/inc/shaarli.css @@ -1101,4 +1101,17 @@ div.dailyNoEntry { ul.errors { color: red; float: left; -} \ No newline at end of file +} + +/* 404 page */ +.error-container { + + margin: 50px; + margin-top: 20px; +} + +.error-container h1 { + text-decoration: none; + font-style: normal; + color: #80AD48; +} diff --git a/index.php b/index.php index 553f65e4..beba9c32 100644 --- a/index.php +++ b/index.php @@ -472,7 +472,7 @@ if (isset($_POST['login'])) session_set_cookie_params(0,$cookiedir,$_SERVER['SERVER_NAME']); // 0 means "When browser closes" session_regenerate_id(true); } - + // Optional redirect after login: if (isset($_GET['post'])) { $uri = '?post='. urlencode($_GET['post']); @@ -681,6 +681,18 @@ class pageBuilder if ($this->tpl===false) $this->initialize(); // Lazy initialization $this->tpl->draw($page); } + + /** + * Render a 404 page (uses the template : tpl/404.tpl) + * + * usage : $PAGE->render404('The link was deleted') + * @param string $message A messate to display what is not found + */ + public function render404($message='The page you are trying to reach does not exist or has been deleted.') { + header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); + $this->tpl->assign('error_message', $message); + $this->renderPage('404'); + } } // ------------------------------------------------------------------------------------------ @@ -1883,10 +1895,7 @@ function buildLinkList($PAGE,$LINKSDB) $linksToDisplay = $LINKSDB->filter($search_type, $search_crits); if (count($linksToDisplay) == 0) { - header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); - echo '

404 Not found.

Oh crap. - The link you are trying to reach does not exist or has been deleted.'; - echo '
Would you mind clicking here?'; + $PAGE->render404('The link you are trying to reach does not exist or has been deleted.'); exit; } } diff --git a/tpl/404.html b/tpl/404.html new file mode 100644 index 00000000..a45be801 --- /dev/null +++ b/tpl/404.html @@ -0,0 +1,17 @@ + + + + {include="includes"} + + + +
+

404 Not found Oh crap!

+

{$error_message}

+

Would you mind clicking here ?

+
+{include="page.footer"} + + -- cgit v1.2.3