コード例 #1
0
ファイル: endpoint.php プロジェクト: aizlewood/2016
 public function __construct()
 {
     $endpoint = $this;
     if ($page = page('webmention') and kirby()->path() == $page->uri()) {
         if (r::is('post')) {
             try {
                 $endpoint->start();
                 header::status(202);
                 tpl::set('status', 'success');
                 tpl::set('alert', null);
             } catch (Exception $e) {
                 header::status(400);
                 tpl::set('status', 'error');
                 tpl::set('alert', $e->getMessage());
             }
         } else {
             tpl::set('status', 'idle');
         }
     } else {
         kirby()->routes(array(array('pattern' => 'webmention', 'method' => 'GET|POST', 'action' => function () use($endpoint) {
             try {
                 $endpoint->start();
                 echo response::success('Yay', 202);
             } catch (Exception $e) {
                 echo response::error($e->getMessage());
             }
         })));
     }
 }
コード例 #2
0
ファイル: response.php プロジェクト: LucasFyl/korakia
 /**
  * Sends the correct header for the response
  *
  * @param boolean $send If set to false, the header will be returned
  * @return mixed
  */
 public function header($send = true)
 {
     $status = header::status($this->code, false);
     $type = header::type($this->format, 'utf-8', false);
     if (!$send) {
         return $status . PHP_EOL . $type;
     }
     header($status);
     header($type);
 }
コード例 #3
0
ファイル: terror.php プロジェクト: chrishiam/LVSL
 public static function error($message, $type, $file, $line)
 {
     // remove everything that has been rendered so far
     if (ob_get_level()) {
         ob_end_clean();
     }
     if (class_exists('kirby') and !is_null(kirby::$instance)) {
         $kirby = kirby::$instance;
     } else {
         $kirby = null;
     }
     if (r::ajax()) {
         if (terror::debug()) {
             echo response::error($message, 400, array('type' => $type, 'file' => $file, 'line' => $line));
         } else {
             echo response::error('Unexpected error', 400);
         }
     } else {
         header::status(400);
         static::view($message, $type, $file, $line, $kirby);
     }
     die;
 }
コード例 #4
0
 /**
  * Starts the router, renders the page and returns the response
  *
  * @return mixed
  */
 public function launch()
 {
     // this will trigger the configuration
     $site = $this->site();
     // force secure connections if enabled
     if ($this->option('ssl') and !r::secure()) {
         // rebuild the current url with https
         go(url::build(array('scheme' => 'https')));
     }
     // set the timezone for all date functions
     date_default_timezone_set($this->options['timezone']);
     // load all extensions
     $this->extensions();
     // load all plugins
     $this->plugins();
     // load all models
     $this->models();
     // start the router
     $this->router = new Router($this->routes());
     $this->route = $this->router->run($this->path());
     // check for a valid route
     if (is_null($this->route)) {
         header::status('500');
         header::type('json');
         die(json_encode(array('status' => 'error', 'message' => 'Invalid route or request method')));
     }
     // call the router action with all arguments from the pattern
     $response = call($this->route->action(), $this->route->arguments());
     // load all language variables
     // this can only be loaded once the router action has been called
     // otherwise the current language is not yet available
     $this->localize();
     // build the response
     $this->response = $this->component('response')->make($response);
     // store the current language in the session
     if ($this->site()->multilang() && ($language = $this->site()->language())) {
         s::set('language', $language->code());
     }
     return $this->response;
 }
コード例 #5
0
ファイル: page.php プロジェクト: LucasFyl/korakia
 /**
  * Sends all appropriate headers for this page
  * Can be configured with the headers config array,
  * which should contain all header definitions for each template
  */
 public function headers()
 {
     $template = $this->template();
     if (isset($this->kirby->options['headers'][$template])) {
         $headers = $this->kirby->options['headers'][$template];
         if (is_numeric($headers)) {
             header::status($headers);
         } else {
             if (is_callable($headers)) {
                 call($headers, $this);
             }
         }
     } else {
         if ($this->isErrorPage()) {
             header::notfound();
         }
     }
 }
コード例 #6
0
ファイル: kirby.php プロジェクト: chrishiam/LVSL
 public function response()
 {
     // this will trigger the configuration
     $site = $this->site();
     $router = new Router($this->routes());
     $route = $router->run($this->path());
     // check for a valid route
     if (is_null($route)) {
         header::status('500');
         header::type('json');
         die(json_encode(array('status' => 'error', 'message' => 'Invalid route or request method')));
     }
     $response = call($route->action(), $route->arguments());
     if (is_string($response)) {
         $this->response = static::render(page($response));
     } else {
         if (is_array($response)) {
             $this->response = static::render(page($response[0]), $response[1]);
         } else {
             if (is_a($response, 'Response')) {
                 $this->response = $response;
             } else {
                 if (is_a($response, 'Page')) {
                     $this->response = static::render($response);
                 } else {
                     $this->response = null;
                 }
             }
         }
     }
     return $this->response;
 }