/usr
/www
/users
/gmurgi
/kirby
/kirby
/vendor
/getkirby
/toolkit
/lib
/header.php
*/
public static function status($code, $send = true) {
$codes = static::$codes;
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
// allow full control over code and message
if(is_string($code) && preg_match('/^\d{3} \w.+$/', $code) === 1) {
$message = substr(rtrim($code), 4);
$code = substr($code, 0, 3);
} else {
$code = !array_key_exists('_' . $code, $codes) ? 500 : $code;
$message = isset($codes['_' . $code]) ? $codes['_' . $code] : 'Something went wrong';
}
$header = $protocol . ' ' . $code . ' ' . $message;
if(!$send) return $header;
// try to send the header
header($header);
}
/**
* Sends a 200 header
*
* @param boolean $send
* @return string|null
*/
public static function success($send = true) {
return static::status(200, $send);
}
/**
* Sends a 201 header
*
* @param boolean $send
* @return string|null
*/
public static function created($send = true) {
/usr
/www
/users
/gmurgi
/kirby
/kirby
/vendor
/getkirby
/toolkit
/lib
/header.php
*/
public static function status($code, $send = true) {
$codes = static::$codes;
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
// allow full control over code and message
if(is_string($code) && preg_match('/^\d{3} \w.+$/', $code) === 1) {
$message = substr(rtrim($code), 4);
$code = substr($code, 0, 3);
} else {
$code = !array_key_exists('_' . $code, $codes) ? 500 : $code;
$message = isset($codes['_' . $code]) ? $codes['_' . $code] : 'Something went wrong';
}
$header = $protocol . ' ' . $code . ' ' . $message;
if(!$send) return $header;
// try to send the header
header($header);
}
/**
* Sends a 200 header
*
* @param boolean $send
* @return string|null
*/
public static function success($send = true) {
return static::status(200, $send);
}
/**
* Sends a 201 header
*
* @param boolean $send
* @return string|null
*/
public static function created($send = true) {
/usr
/www
/users
/gmurgi
/kirby
/kirby
/vendor
/getkirby
/toolkit
/lib
/header.php
}
/**
* Sends a 403 header
*
* @param boolean $send
* @return string|null
*/
public static function forbidden($send = true) {
return static::status(403, $send);
}
/**
* Sends a 404 header
*
* @param boolean $send
* @return string|null
*/
public static function notfound($send = true) {
return static::status(404, $send);
}
/**
* Sends a 404 header
*
* @param boolean $send
* @return string|null
*/
public static function missing($send = true) {
return static::status(404, $send);
}
/**
* Sends a 410 header
*
* @param boolean $send
* @return string|null
*/
public static function gone($send = true) {
return static::status(410, $send);
/usr
/www
/users
/gmurgi
/kirby
/kirby
/core
/page.php
/**
* 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();
}
// send the header of the representation
if($representation = $this->representation()) {
if($mime = f::extensionToMime($representation)) header::type($mime);
}
}
/**
* Returns the root for the content file
*
* @return string
*/
public function textfile($template = null) {
if(is_null($template)) $template = $this->intendedTemplate();
return textfile($this->diruri(), $template);
}
/**
/usr
/www
/users
/gmurgi
/kirby
/kirby
/kirby.php
} else {
return $this->cache = cache::setup('mock');
}
}
/**
* Renders the HTML for the page or fetches it from the cache
*
* @param Page $page
* @param boolean $headers
* @return string
*/
public function render(Page $page, $data = array(), $headers = true) {
// register the currently rendered page
$this->page = $page;
// send all headers for the page
if($headers) $page->headers();
// configure pagination urls
$query = (string)$this->request()->query();
$params = (string)$this->request()->params() . r($query, '?') . $query;
pagination::$defaults['url'] = $page->url() . r($params, '/') . $params;
// cache the result if possible
if($this->options['cache'] && $page->isCachable() && in_array(r::method(), ['GET', 'HEAD'])) {
// try to read the cache by cid (cache id)
$detect = new Mobile_Detect();
if($detect->isMobile() && !$detect->isTablet()) {
$device = 'mobile';
}
elseif($detect->isTablet()) {
$device = 'tablet';
}
else {
$device = 'desktop';
/usr
/www
/users
/gmurgi
/kirby
/kirby
/kirby
/component
/response.php
* @link http://getkirby.com
* @copyright Bastian Allgeier
* @license http://getkirby.com/license
*/
class Response extends \Kirby\Component {
/**
* Builds and return the response by various input
*
* @param mixed $response
* @return mixed
*/
public function make($response) {
if(is_string($response)) {
return $this->kirby->render(page($response));
} else if(is_array($response)) {
return $this->kirby->render(page($response[0]), $response[1]);
} else if(is_a($response, 'Page')) {
return $this->kirby->render($response);
} else if(is_a($response, 'Response')) {
return $response;
} else {
return null;
}
}
}
/usr
/www
/users
/gmurgi
/kirby
/kirby
/kirby.php
// 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->option('language.detect') &&
$this->site()->multilang() &&
$this->site()->language()
) {
s::set('kirby_language', $this->site()->language()->code());
}
return $this->response;
}
/**
* Register a new hook
*
* @param string/array $hook The name of the hook
* @param closure $callback
*/
/usr
/www
/users
/gmurgi
/kirby
/index.php
<?php
define('DS', DIRECTORY_SEPARATOR);
// load kirby
require(__DIR__ . DS . 'kirby' . DS . 'bootstrap.php');
// check for a custom site.php
if(file_exists(__DIR__ . DS . 'site.php')) {
require(__DIR__ . DS . 'site.php');
} else {
$kirby = kirby();
}
// render
echo $kirby->launch();