diff --git a/application/bootstrap.php b/application/bootstrap.php index 143e83e..6dc6352 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -120,17 +120,6 @@ Kohana::modules(array( // 'userguide' => SMDPATH.'userguide', // User guide and API documentation )); -/** - * Enable specalised interfaces - */ -Route::set('sections', '/(/(/(/)))', - array( - 'directory' => '('.implode('|',array_values(URL::$method_directory)).')' - )) - ->defaults(array( - 'action' => 'index', - )); - // Static file serving (CSS, JS, images) Route::set('default/media', 'media(/)', array('file' => '.+')) ->defaults(array( diff --git a/application/classes/Controller/Media.php b/application/classes/Controller/Media.php new file mode 100644 index 0000000..416be47 --- /dev/null +++ b/application/classes/Controller/Media.php @@ -0,0 +1,52 @@ +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())); + } +} +?> diff --git a/application/classes/HTTP/Exception/404.php b/application/classes/HTTP/Exception/404.php index 9651d3d..88279de 100644 --- a/application/classes/HTTP/Exception/404.php +++ b/application/classes/HTTP/Exception/404.php @@ -31,25 +31,27 @@ class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 { // Prepare the response object. $response = Response::factory(); - $redirect = $ro->redirect ? trim($ro->redirect) : Kohana::$config->load('config')->defaultfile; // Process our redirection options - if (is_null($redirect) OR ! trim($redirect)) { - return parent::get_response(); - - } elseif (preg_match('/^http[s]?:\/\//',$redirect)) { + if (preg_match('/^http[s]?:\/\//',$ro->redirect)) { $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->body(file_get_contents($redirect)); + $response->body(file_get_contents($matches[1])); 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-Length',(string)$response->content_length()); $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; diff --git a/application/classes/URL.php b/application/classes/URL.php deleted file mode 100644 index 56f0f60..0000000 --- a/application/classes/URL.php +++ /dev/null @@ -1,54 +0,0 @@ -'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; - } -} -?> diff --git a/application/config/config.php b/application/config/config.php index a02f1bb..fe247cd 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -9,8 +9,8 @@ * @copyright (c) 2010-2013 Deon George * @license http://dev.leenooks.net/license.html */ + return array( - 'defaultfile' => 'file:///var/www/html/index.html', 'cache_type' => 'file', 'date_format' => 'd-M-Y', ); diff --git a/application/media/img/404.jpg b/application/media/img/404.jpg new file mode 100644 index 0000000..091f185 Binary files /dev/null and b/application/media/img/404.jpg differ diff --git a/application/views/404.php b/application/views/404.php new file mode 100644 index 0000000..94adc7d --- /dev/null +++ b/application/views/404.php @@ -0,0 +1,13 @@ + + + + Not Found + + + + + Not Found + +