/home
/pourpieger
/public_html
/kirby
/branches
/multilang
/site.php
/**
* Sets the currently active page
* and returns its page object
*
* @param string $uri
* @return Page
*/
public function visit($uri = '', $lang = null) {
// if the language code is missing or the code is invalid (TODO)
if(!in_array($lang, $this->languages()->keys())) {
$lang = $this->defaultLanguage->code;
}
// set the current language
$this->language = $this->languages()->data[$lang];
// clean the uri
$uri = trim($uri, '/');
// alternate version without file extension
$baseUri = f::name($uri);
$parent = dirname($uri);
if($parent !== '.') $baseUri = $parent . '/' . $baseUri;
if(empty($uri)) {
return $this->page = $this->homePage();
} else {
if($lang == $this->defaultLanguage->code and $page = $this->children()->find($uri)) {
return $this->page = $page;
} else if($page = $this->children()->findByURI($uri)) {
return $this->page = $page;
}
// store the representation for $page->representation()
if($uri !== $baseUri) $this->representation = f::extension($uri);
if($baseUri === '') {
return $this->page = $this->homePage();
/home
/pourpieger
/public_html
/kirby
/branches
/multilang
/site.php
/**
* Sets the currently active page
* and returns its page object
*
* @param string $uri
* @return Page
*/
public function visit($uri = '', $lang = null) {
// if the language code is missing or the code is invalid (TODO)
if(!in_array($lang, $this->languages()->keys())) {
$lang = $this->defaultLanguage->code;
}
// set the current language
$this->language = $this->languages()->data[$lang];
// clean the uri
$uri = trim($uri, '/');
// alternate version without file extension
$baseUri = f::name($uri);
$parent = dirname($uri);
if($parent !== '.') $baseUri = $parent . '/' . $baseUri;
if(empty($uri)) {
return $this->page = $this->homePage();
} else {
if($lang == $this->defaultLanguage->code and $page = $this->children()->find($uri)) {
return $this->page = $page;
} else if($page = $this->children()->findByURI($uri)) {
return $this->page = $page;
}
// store the representation for $page->representation()
if($uri !== $baseUri) $this->representation = f::extension($uri);
if($baseUri === '') {
return $this->page = $this->homePage();
/home
/pourpieger
/public_html
/kirby
/kirby.php
$language = $site->detectedLanguage();
}
// build language homepage URL including params and/or query
$url = $language->url();
if($params = url::params()) $url .= '/' . url::paramsToString($params);
if($query = url::query()) $url .= '/?' . url::queryToString($query);
// redirect to the language homepage
if($language && rtrim(url::current(), '/') !== rtrim($url, '/')) {
return go($url);
}
}
// get the language code from the route
$lang = ($kirby->route->lang)? $kirby->route->lang->code() : false;
// visit the currently active page
$page = ($lang)? $site->visit($path, $lang) : $site->visit($path);
// redirections for files and invalid representations
if($site->representation !== null) {
// get the filename
$filename = rawurldecode(basename($path));
$pagepath = dirname($path);
// check if there's a page for the parent path
if($parent = $site->find($pagepath)) {
// check if there's a file for the last element of the path
if($file = $parent->file($filename)) {
return go($file->url());
}
}
// prevent invalid representation routes
if($site->representation === '' || $site->representation != $page->representation()) {
return $site->errorPage();
}
/home
/pourpieger
/public_html
/kirby
/vendor
/getkirby
/toolkit
/helpers.php
/**
* Facepalm typo alias
* @see csrf()
*/
function csfr() {
return call('csrf', func_get_args());
}
/**
* Shortcut for call_user_func_array with a better handling of arguments
*
* @param mixed $function
* @param mixed $arguments
* @return mixed
*/
function call($function, $arguments = array()) {
if(!is_callable($function)) return false;
if(!is_array($arguments)) $arguments = array($arguments);
return call_user_func_array($function, $arguments);
}
/**
* Parses yaml structured text
*
* @param $string
* @return array
*/
function yaml($string) {
return yaml::decode($string);
}
/**
* Simple email sender helper
*
* @param array $params
* @return Email
*/
function email($params = array()) {
return new Email($params);
/home
/pourpieger
/public_html
/kirby
/kirby.php
// load all plugins
$this->plugins();
// start the router
$this->router = new Router($this->routes());
$this->route = $this->router->run(trim($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->option('language.detect') &&
$this->site()->multilang() &&
$this->site()->language()
) {
s::set('kirby_language', $this->site()->language()->code());
}
return $this->response;
/home
/pourpieger
/public_html
/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();