diff --git a/lib/class.model.php b/lib/class.model.php index 6954f6e..5fc29ec 100644 --- a/lib/class.model.php +++ b/lib/class.model.php @@ -46,4 +46,49 @@ abstract class model { return new $model_class($this->db, $this->auth, $this->router, $this->view); } + + /* show ap[i output in json format + * + * INPUT: array + * OUTPUT: string + * ERROR: null + */ + protected function renderOutput($variables, $jsonout = false) { + + $contentt = 'Content-Type: text/plain'; + $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); + $httpcode = '412'; + $sucess = false; + $message = 'No message was specified, the server could not process the content or the page does not exist'; + $page = 1; + $pages = 1; + $per_page = 1; + $data = array($message); + + if(is_array($variables) ) { + foreach($variables as $key => $value) { + $$key = $value; + } + } + + $GLOBALS['http_response_code'] = $httpcode; + if( !is_null($jsonout) and !empty($jsonout)) { + $contentt = 'Content-Type: application/json; charset=utf-8'; + header($contentt); + $jsondata = array( + 'sucess' => $sucess, + 'message' => $message, + 'page' => $page, + 'pages' => $pages, + 'per_page' => $per_page, + 'data'=> $data + ); + print(json_encode($jsondata)); + } + else { + $contentt = 'Content-Type: text/html; charset=UTF-8'; + header($contentt); + include(DIR_VIEWS."notfoundview.php"); + } + } } diff --git a/models/index.php b/models/index.php index fed1b2d..d84f639 100644 --- a/models/index.php +++ b/models/index.php @@ -17,6 +17,7 @@ class index_model extends model { } public function show() { + $httpcode = 200; include(DIR_VIEWS."index.php"); } } diff --git a/models/notFound.php b/models/notFound.php index 7726d91..2c6bcd2 100644 --- a/models/notFound.php +++ b/models/notFound.php @@ -12,14 +12,9 @@ Copyright (c) 2018 Díaz Víctor aka (Máster Vitronic) class notFound_model extends model { - public function show() { - $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); - header($protocol . ' 404'); - $GLOBALS['http_response_code'] = '404'; - header('Content-Type: application/json; charset=utf-8'); - print(json_encode([ - 'msg'=>'Not Found' - ])); + public function show($errormessage = 'The page could not be found or was moved, or your request is not valid, please consult upstream') { + $variables = array('message'=>$errormessage,'httpcode'=>'404'); + $this->renderOutput($variables); } } diff --git a/public/views/index.php b/public/views/index.php index cb76608..c98b8b0 100644 --- a/public/views/index.php +++ b/public/views/index.php @@ -11,7 +11,7 @@ <body> <nav class="navbar" role="navigation" aria-label="main navigation"> <div class="navbar-brand"> - <a class="navbar-item" href="https://bulma.io"> + <a class="navbar-item"> </a> <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample"> <span aria-hidden="true"></span> @@ -28,14 +28,11 @@ <a href="about" class="navbar-item"> About </a> - <a href="api/use" class="navbar-item is-selected"> + <a href="api/api" class="navbar-item is-selected"> API </a> - <a href="help" class="navbar-item"> - Help - </a> <hr class="navbar-divider"> - <a href="about" class="navbar-item"> + <a href="https://codeberg.org/minenux/minenux-skindb-webdb/issues" class="navbar-item"> Report an issue </a> </div> @@ -65,9 +62,7 @@ <main class="contain"> <h1 class="title">Skins</h1> <hr> -<?php -echo 'Currently API database is on manteniance, please report any incident but first try to check if there any previous report at <a href="https://codeberg.org/minenux/minenux-skindb-webdb/issues">https://codeberg.org/minenux/minenux-skindb-webdb/issues</a> with code 412'; -?> + Wellcome! </main> <br> <footer class="footer"> diff --git a/public/views/notfoundview.php b/public/views/notfoundview.php new file mode 100644 index 0000000..c20e3a2 --- /dev/null +++ b/public/views/notfoundview.php @@ -0,0 +1,81 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta http-equiv="X-UA-Compatible" content="ie=edge"> + <title>SkinsDB</title> + <link rel="icon" href="icon.png" type="image/x-icon"> + <link rel="stylesheet" href="assets/css/bulma.min.css"> + </head> + <body> + <nav class="navbar" role="navigation" aria-label="main navigation"> + <div class="navbar-brand"> + <a class="navbar-item"> + </a> + <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample"> + <span aria-hidden="true"></span> + <span aria-hidden="true"></span> + </a> + </div> + <div id="navbarBasicExample" class="navbar-menu"> + <div class="navbar-start"> + <div class="navbar-item has-dropdown is-hoverable"> + <a href="lists" class="navbar-link"> + Start + </a> + <div class="navbar-dropdown"> + <a href="about" class="navbar-item"> + About + </a> + <a href="api/api" class="navbar-item is-selected"> + API + </a> + <hr class="navbar-divider"> + <a href="https://codeberg.org/minenux/minenux-skindb-webdb/issues" class="navbar-item"> + Report an issue + </a> + </div> + </div> + </div> + <div class="navbar-end"> + <div class="navbar-item"> + <a class="field is-grouped"> + <p class="control is-expanded"> + <input class="input" type="text" placeholder="type here to Search skin"> + </p> + <p class="control"> + <button class="button is-info is-selected"> + Search + </button> + </p> + </a> + <a href="about" class="button is-primary"> + About + </a> + </div> + </div> + </div> + </div> + </nav> + <br> + <main class="contain"> + <h1 class="title">Skins</h1> + <hr> +<p> +<?php +if(!isset($message)) $message = "System is currently in manteniance, just wait for a moment.."; +if(!isset($httpcode)) $httpcode = 412; +if(!isset($currentrequest)) $currentrequest = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; +echo $message.', please report any incident but first try to check if there any previous report at <a href="https://codeberg.org/minenux/minenux-skindb-webdb/issues">https://codeberg.org/minenux/minenux-skindb-webdb/issues</a> with code '.$httpcode.' and this link: '.$currentrequest; +?> +</p> + </main> + <br> + <footer class="footer"> + <div class="content has-text-centered"> + <p><strong>SkinsDdatabase</strong> by MinenuX</p> + </div> + </footer> + </body> +</html>