Example #1
0
 /**
  * When this type of exception isn't caught this method is called by
  * Error::exception_handler() to deal with the problem.
  */
 public function handle()
 {
     $response = new \Response(\View::forge('404'), 404);
     \Event::shutdown();
     $response->send(true);
     return;
 }
Example #2
0
 /**
  * Redirects to another uri/url.  Sets the redirect header,
  * sends the headers and exits.  Can redirect via a Location header
  * or using a refresh header.
  *
  * The refresh header works better on certain servers like IIS.
  *
  * @access	public
  * @param	string	The url
  * @param	string	The redirect method
  * @param	int		The redirect status code
  * @return	void
  */
 public static function redirect($url = '', $method = 'location', $redirect_code = 302)
 {
     static::$status = $redirect_code;
     if (strpos($url, '://') === false) {
         $url = Uri::create($url);
     }
     if ($method == 'location') {
         static::set_header('Location', $url);
     } elseif ($method == 'refresh') {
         static::set_header('Refresh', '0;url=' . $url);
     } else {
         return;
     }
     Event::shutdown();
     static::send_headers();
     exit;
 }
Example #3
0
 /**
  * Redirects to another uri/url.  Sets the redirect header,
  * sends the headers and exits.  Can redirect via a Location header
  * or using a refresh header.
  *
  * The refresh header works better on certain servers like IIS.
  *
  * @param   string  $url     The url
  * @param   string  $method  The redirect method
  * @param   int     $code    The redirect status code
  * @return  void
  */
 public static function redirect($url = '', $method = 'location', $code = 302)
 {
     $response = new static();
     $response->set_status($code);
     if (strpos($url, '://') === false) {
         $url = $url !== '' ? \Uri::create($url) : \Uri::base();
     }
     if ($method == 'location') {
         $response->set_header('Location', $url);
     } elseif ($method == 'refresh') {
         $response->set_header('Refresh', '0;url=' . $url);
     } else {
         return;
     }
     \Event::shutdown();
     $response->send(true);
     exit;
 }
Example #4
0
File: index.php Project: hymns/fuel
// Use an anonymous function to keep the global namespace clean
call_user_func(function () {
    /**
     * Set all the paths here
     */
    $app_path = '../fuel/app/';
    $package_path = '../fuel/packages/';
    $core_path = '../fuel/core/';
    /**
     * Website docroot
     */
    define('DOCROOT', __DIR__ . DIRECTORY_SEPARATOR);
    !is_dir($app_path) and is_dir(DOCROOT . $app_path) and $app_path = DOCROOT . $app_path;
    !is_dir($core_path) and is_dir(DOCROOT . $core_path) and $core_path = DOCROOT . $core_path;
    !is_dir($package_path) and is_dir(DOCROOT . $package_path) and $package_path = DOCROOT . $package_path;
    define('APPPATH', realpath($app_path) . DIRECTORY_SEPARATOR);
    define('PKGPATH', realpath($package_path) . DIRECTORY_SEPARATOR);
    define('COREPATH', realpath($core_path) . DIRECTORY_SEPARATOR);
});
// Get the start time and memory for use later
defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());
// Boot the app
require_once APPPATH . 'bootstrap.php';
// Generate the request, execute it and send the output.
echo Request::factory()->execute()->send_headers()->output();
// Fire off the shutdown event
Event::shutdown();
// Do some final cleanup
Fuel::finish();
/* End of file index.php */
Example #5
0
 /**
  * Download a file
  *
  * @param  string       file path
  * @param  string|null  custom name for the file to be downloaded
  * @param  string|null  custom mime type or null for file mime type
  * @param  string|File_Area|null  file area name, object or null for base area
  * @param  bool        if false, return instead of exit
  */
 public static function download($path, $name = null, $mime = null, $area = null, $exit = true)
 {
     $info = static::file_info($path, $area);
     empty($mime) and $mime = $info['mimetype'];
     empty($name) and $name = $info['basename'];
     if (!($file = static::open_file(@fopen($info['realpath'], 'rb'), LOCK_SH, $area))) {
         throw new \FileAccessException('Filename given could not be opened for download.');
     }
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     ini_get('zlib.output_compression') and ini_set('zlib.output_compression', 0);
     !ini_get('safe_mode') and set_time_limit(0);
     header('Content-Type: ' . $mime);
     header('Content-Disposition: attachment; filename="' . $name . '"');
     header('Content-Description: File Transfer');
     header('Content-Length: ' . $info['size']);
     header('Content-Transfer-Encoding: binary');
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     while (!feof($file)) {
         echo fread($file, 2048);
     }
     static::close_file($file, $area);
     if ($exit) {
         \Event::shutdown();
         exit;
     }
 }
Example #6
0
 /**
  * Shows a 404.  Checks to see if a 404_override route is set, if not show
  * a default 404.
  *
  * Usage:
  *
  *     Request::show_404();
  *
  * @param   bool         Whether to return the 404 output or just output and exit
  * @return  void|string  Void if $return is false, the output if $return is true
  */
 public static function show_404($return = false)
 {
     logger(Fuel::L_INFO, 'Called', __METHOD__);
     // This ensures that show_404 doesn't recurse indefinately
     static $call_count = 0;
     $call_count++;
     if ($call_count == 1) {
         // first call, route the 404 route
         $route_request = true;
     } elseif ($call_count == 2) {
         // second call, try the 404 route without routing
         $route_request = false;
     } else {
         // third call, there's something seriously wrong now
         exit('It appears your _404_ route is incorrect.  Multiple Recursion has happened.');
     }
     if (\Config::get('routes._404_') === null) {
         $response = new \Response(\View::factory('404'), 404);
         if ($return) {
             return $response;
         }
         \Event::shutdown();
         $response->send(true);
     } else {
         $request = \Request::factory(\Config::get('routes._404_'), $route_request)->execute();
         if ($return) {
             return $request->response;
         }
         \Event::shutdown();
         $request->response->send(true);
     }
     \Fuel::finish();
     exit;
 }
Example #7
0
 /**
  * When this type of exception isn't caught this method is called by
  * Error::exception_handler() to deal with the problem.
  */
 public function handle()
 {
     $response = $this->response();
     \Event::shutdown();
     $response->send(true);
 }
Example #8
0
 /**
  * When this type of exception isn't caught this method is called by
  * Error::exception_handler() to deal with the problem.
  */
 public function handle()
 {
     $response = new \Response(\View::forge('500'), 500);
     \Event::shutdown();
     $response->send(true);
 }
Example #9
0
 /**
  * Build
  * 
  * Builds the grid and renders
  * it as a View object
  * 
  * @access	public
  * @return	View
  */
 public function build()
 {
     // Make sure we have columns
     if (!$this->get_columns()->count()) {
         throw new Exception('You must add a column to the grid before building it');
     }
     $this->_prepare_grid();
     // Build the grid
     $grid = \View::forge(\Config::get('grid.view.grid', 'grid'))->set('grid', $this, false);
     // If we can't display a container just return
     // the grid
     if (!$this->can_display_container()) {
         // If we're dealing with an
         // AJAX request, we want to
         // stream a new response
         if (\Input::is_ajax() and $this->should_override_response()) {
             // Create and send a response
             // with the grid as the contents
             $response = new \Response($grid);
             $response->send(true);
             // Close down fuel
             \Event::shutdown();
             \Fuel::finish();
             exit;
         }
         // Return the grid
         return $grid;
     }
     // If we can display a container, add it
     // and return both of them
     return $this->get_container()->build()->set('grid', $grid, false);
 }