public static function export()
 {
     // Set default handlers
     set_error_handler(array('Ai1wm_Error', 'error_handler'));
     set_exception_handler(array('Ai1wm_Error', 'exception_handler'));
     // Get options
     if (isset($_POST['options']) && ($options = $_POST['options'])) {
         // Log options
         Ai1wm_Logger::debug(AI1WM_EXPORT_OPTIONS, $options);
         // Export site
         $model = new Ai1wm_Export($options);
         $file = $model->export();
         // Send the file to the user
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename=' . self::filename());
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . $file->getSize());
         // Clear output buffering and read file content
         while (@ob_end_clean()) {
         }
         // Load file content
         $handle = fopen($file->getName(), 'rb');
         while (!feof($handle)) {
             echo fread($handle, 8192);
         }
         fclose($handle);
         // Flush storage
         StorageArea::getInstance()->flush();
         exit;
     }
 }
 /**
  * Custom Exception Handler
  *
  * @param  Exception $e Exception Object
  * @return void
  */
 public static function exception_handler($e)
 {
     $exceptions = get_site_option(AI1WM_EXCEPTION_HANDLER, array());
     // Limit errors
     if (count($exceptions) > self::EXCEPTION_LIMIT) {
         array_shift($exceptions);
     }
     // Add exception
     $exceptions[] = array('code' => $e->getCode(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'time' => time());
     Ai1wm_Logger::error(AI1WM_EXCEPTION_HANDLER, $exceptions);
 }