Added default 404 page
This commit is contained in:
parent
45c83c5025
commit
00a9d3a057
@ -120,17 +120,6 @@ Kohana::modules(array(
|
|||||||
// 'userguide' => SMDPATH.'userguide', // User guide and API documentation
|
// 'userguide' => SMDPATH.'userguide', // User guide and API documentation
|
||||||
));
|
));
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable specalised interfaces
|
|
||||||
*/
|
|
||||||
Route::set('sections', '<directory>/<controller>(/<action>(/<id>(/<sid>)))',
|
|
||||||
array(
|
|
||||||
'directory' => '('.implode('|',array_values(URL::$method_directory)).')'
|
|
||||||
))
|
|
||||||
->defaults(array(
|
|
||||||
'action' => 'index',
|
|
||||||
));
|
|
||||||
|
|
||||||
// Static file serving (CSS, JS, images)
|
// Static file serving (CSS, JS, images)
|
||||||
Route::set('default/media', 'media(/<file>)', array('file' => '.+'))
|
Route::set('default/media', 'media(/<file>)', array('file' => '.+'))
|
||||||
->defaults(array(
|
->defaults(array(
|
||||||
|
52
application/classes/Controller/Media.php
Normal file
52
application/classes/Controller/Media.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides access to rendering media items (javascript, images and css).
|
||||||
|
*
|
||||||
|
* @package Redir
|
||||||
|
* @category Controllers
|
||||||
|
* @author Deon George
|
||||||
|
* @copyright (c) 2009-2013 Deon George
|
||||||
|
* @license http://dev.leenooks.net/license.html
|
||||||
|
*/
|
||||||
|
class Controller_Media extends Controller {
|
||||||
|
/**
|
||||||
|
* This action will render all the media related files for a page
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
final public function action_get() {
|
||||||
|
// Get the file path from the request
|
||||||
|
$file = $this->request->param('file');
|
||||||
|
|
||||||
|
// Find the file extension
|
||||||
|
$ext = pathinfo($file,PATHINFO_EXTENSION);
|
||||||
|
|
||||||
|
// Remove the extension from the filename
|
||||||
|
$file = substr($file,0,-(strlen($ext)+1));
|
||||||
|
$f = '';
|
||||||
|
|
||||||
|
// If our file is pathed with session, our file is in our session.
|
||||||
|
if ($fd = Session::instance()->get_once($this->request->param('file'))) {
|
||||||
|
$this->response->body($fd);
|
||||||
|
|
||||||
|
// If not found try a default media file
|
||||||
|
} elseif ($f = Kohana::find_file('media',$file,$ext)) {
|
||||||
|
// Send the file content as the response
|
||||||
|
$this->response->body(file_get_contents($f));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Return a 404 status
|
||||||
|
$this->response->status(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate and check the ETag for this file
|
||||||
|
$this->check_cache(sha1($this->response->body()));
|
||||||
|
|
||||||
|
// Set the proper headers to allow caching
|
||||||
|
$this->response->headers('Content-Type',File::mime_by_ext($ext));
|
||||||
|
$this->response->headers('Content-Length',(string)$this->response->content_length());
|
||||||
|
$this->response->headers('Last-Modified',date('r',$f ? filemtime($f) : time()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -31,25 +31,27 @@ class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
|
|||||||
|
|
||||||
// Prepare the response object.
|
// Prepare the response object.
|
||||||
$response = Response::factory();
|
$response = Response::factory();
|
||||||
$redirect = $ro->redirect ? trim($ro->redirect) : Kohana::$config->load('config')->defaultfile;
|
|
||||||
|
|
||||||
// Process our redirection options
|
// Process our redirection options
|
||||||
if (is_null($redirect) OR ! trim($redirect)) {
|
if (preg_match('/^http[s]?:\/\//',$ro->redirect)) {
|
||||||
return parent::get_response();
|
|
||||||
|
|
||||||
} elseif (preg_match('/^http[s]?:\/\//',$redirect)) {
|
|
||||||
$response->status(302);
|
$response->status(302);
|
||||||
$response->headers('Location',$redirect);
|
$response->headers('Location',$ro->redirect);
|
||||||
|
|
||||||
} elseif (preg_match('/^file:\/\/(.*)$/',$redirect,$matches) AND file_exists($matches[1])) {
|
} elseif (preg_match('/^file:\/\/(.*)$/',$ro->redirect,$matches) AND file_exists($matches[1])) {
|
||||||
$response->status(200);
|
$response->status(200);
|
||||||
$response->body(file_get_contents($redirect));
|
$response->body(file_get_contents($matches[1]));
|
||||||
|
|
||||||
HTTP::check_cache($this->request(),$response,sha1($response->body()));
|
HTTP::check_cache($this->request(),$response,sha1($response->body()));
|
||||||
|
|
||||||
$response->headers('Content-Type',File::mime_by_ext(pathinfo($matches[1],PATHINFO_EXTENSION)));
|
$response->headers('Content-Type',File::mime_by_ext(pathinfo($matches[1],PATHINFO_EXTENSION)));
|
||||||
$response->headers('Content-Length',(string)$response->content_length());
|
$response->headers('Content-Length',(string)$response->content_length());
|
||||||
$response->headers('Last-Modified',date('r',$matches[1] ? filemtime($matches[1]) : time()));
|
$response->headers('Last-Modified',date('r',$matches[1] ? filemtime($matches[1]) : time()));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$response->status(404);
|
||||||
|
$response->body(View::factory('404'));
|
||||||
|
|
||||||
|
HTTP::check_cache($this->request(),$response,sha1($response->body()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class overrides Kohana's URL
|
|
||||||
*
|
|
||||||
* @package Redir
|
|
||||||
* @category Modifications
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Deon George
|
|
||||||
* @license http://dev.leenooks.net/license.html
|
|
||||||
*/
|
|
||||||
class URL extends Kohana_URL {
|
|
||||||
// Our method paths for different functions
|
|
||||||
public static $method_directory = array(
|
|
||||||
'admin'=>'a',
|
|
||||||
'affiliate'=>'affiliate', // @todo To retire
|
|
||||||
'reseller'=>'r',
|
|
||||||
'task'=>'task',
|
|
||||||
'user'=>'u',
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper to provide a URL::site() link based on function
|
|
||||||
*/
|
|
||||||
public static function link($dir,$src,$site=FALSE) {
|
|
||||||
if (! $dir)
|
|
||||||
return $src;
|
|
||||||
|
|
||||||
if (! array_key_exists($dir,URL::$method_directory))
|
|
||||||
throw new Kohana_Exception('Unknown directory :dir for :src',array(':dir'=>$dir,':src'=>$src));
|
|
||||||
|
|
||||||
$x = URL::$method_directory[$dir].'/'.$src;
|
|
||||||
|
|
||||||
return $site ? URL::site($x) : $x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to reveal the real directory for a URL
|
|
||||||
*/
|
|
||||||
public static function dir($dir) {
|
|
||||||
// Quick check if we can do something here
|
|
||||||
if (! in_array(strtolower($dir),URL::$method_directory))
|
|
||||||
return $dir;
|
|
||||||
|
|
||||||
// OK, we can, find it.
|
|
||||||
foreach (URL::$method_directory as $k=>$v)
|
|
||||||
if (strtolower($dir) == $v)
|
|
||||||
return ucfirst($k);
|
|
||||||
|
|
||||||
// If we get here, we didnt have anything.
|
|
||||||
return $dir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -9,8 +9,8 @@
|
|||||||
* @copyright (c) 2010-2013 Deon George
|
* @copyright (c) 2010-2013 Deon George
|
||||||
* @license http://dev.leenooks.net/license.html
|
* @license http://dev.leenooks.net/license.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'defaultfile' => 'file:///var/www/html/index.html',
|
|
||||||
'cache_type' => 'file',
|
'cache_type' => 'file',
|
||||||
'date_format' => 'd-M-Y',
|
'date_format' => 'd-M-Y',
|
||||||
);
|
);
|
||||||
|
BIN
application/media/img/404.jpg
Normal file
BIN
application/media/img/404.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
13
application/views/404.php
Normal file
13
application/views/404.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="auto" lang="auto">
|
||||||
|
<head>
|
||||||
|
<title>Not Found</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<style type="text/css">
|
||||||
|
body { width: 100%; background: #fff; text-align: center; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<img src="media/img/404.jpg" alt="Not Found">
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user