/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/plugins
/kirby-shortcode
/thunderer-shortcode
/vendor
/thunderer
/shortcode
/src
/Processor
/Processor.php
$length = mb_strlen($s->getText(), 'utf-8');
$textLength = mb_strlen($state, 'utf-8');
return mb_substr($state, 0, $offset, 'utf-8').$s->getReplacement().mb_substr($state, $offset + $length, $textLength, 'utf-8');
}, $text);
}
private function processHandler(ParsedShortcodeInterface $parsed, ProcessorContext $context, $handler)
{
$processed = ProcessedShortcode::createFromContext(clone $context);
$content = $this->processRecursion($processed, $context);
$processed = $processed->withContent($content);
if($handler) {
return call_user_func_array($handler, array($processed));
}
$state = $parsed->getText();
$length = mb_strlen($processed->getTextContent(), 'utf-8');
$offset = mb_strrpos($state, $processed->getTextContent(), 'utf-8');
return mb_substr($state, 0, $offset, 'utf-8').$processed->getContent().mb_substr($state, $offset + $length, mb_strlen($state, 'utf-8'), 'utf-8');
}
private function processRecursion(ParsedShortcodeInterface $shortcode, ProcessorContext $context)
{
if ($this->autoProcessContent && null !== $shortcode->getContent()) {
$context->recursionLevel++;
// this is safe from using max iterations value because it's manipulated in process() method
$content = $this->processIteration($shortcode->getContent(), clone $context, $shortcode);
$context->recursionLevel--;
return $content;
}
return $shortcode->getContent();
}
/**
* Container for event handlers used in this processor.
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/plugins
/kirby-shortcode
/thunderer-shortcode
/vendor
/thunderer
/shortcode
/src
/Processor
/Processor.php
$length = mb_strlen($s->getText(), 'utf-8');
$textLength = mb_strlen($state, 'utf-8');
return mb_substr($state, 0, $offset, 'utf-8').$s->getReplacement().mb_substr($state, $offset + $length, $textLength, 'utf-8');
}, $text);
}
private function processHandler(ParsedShortcodeInterface $parsed, ProcessorContext $context, $handler)
{
$processed = ProcessedShortcode::createFromContext(clone $context);
$content = $this->processRecursion($processed, $context);
$processed = $processed->withContent($content);
if($handler) {
return call_user_func_array($handler, array($processed));
}
$state = $parsed->getText();
$length = mb_strlen($processed->getTextContent(), 'utf-8');
$offset = mb_strrpos($state, $processed->getTextContent(), 'utf-8');
return mb_substr($state, 0, $offset, 'utf-8').$processed->getContent().mb_substr($state, $offset + $length, mb_strlen($state, 'utf-8'), 'utf-8');
}
private function processRecursion(ParsedShortcodeInterface $shortcode, ProcessorContext $context)
{
if ($this->autoProcessContent && null !== $shortcode->getContent()) {
$context->recursionLevel++;
// this is safe from using max iterations value because it's manipulated in process() method
$content = $this->processIteration($shortcode->getContent(), clone $context, $shortcode);
$context->recursionLevel--;
return $content;
}
return $shortcode->getContent();
}
/**
* Container for event handlers used in this processor.
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/plugins
/kirby-shortcode
/thunderer-shortcode
/vendor
/thunderer
/shortcode
/src
/Processor
/Processor.php
$filterEvent = new FilterShortcodesEvent($this->parser->parse($text), $parent);
$this->dispatchEvent(Events::FILTER_SHORTCODES, $filterEvent);
$shortcodes = $filterEvent->getShortcodes();
$replaces = array();
$baseOffset = $parent && $shortcodes
? mb_strpos($parent->getShortcodeText(), $shortcodes[0]->getText(), null, 'utf-8') - $shortcodes[0]->getOffset() + $parent->getOffset()
: 0;
foreach ($shortcodes as $shortcode) {
$hasNamePosition = array_key_exists($shortcode->getName(), $context->namePosition);
$context->baseOffset = $baseOffset + $shortcode->getOffset();
$context->position++;
$context->namePosition[$shortcode->getName()] = $hasNamePosition ? $context->namePosition[$shortcode->getName()] + 1 : 1;
$context->shortcodeText = $shortcode->getText();
$context->offset = $shortcode->getOffset();
$context->shortcode = $shortcode;
$context->textContent = $shortcode->getContent();
$handler = $this->handlers->get($shortcode->getName());
$replace = $this->processHandler($shortcode, $context, $handler);
$replaces[] = new ReplacedShortcode($shortcode, $replace);
}
$replaces = array_filter($replaces);
$applyEvent = new ReplaceShortcodesEvent($text, $replaces, $parent);
$this->dispatchEvent(Events::REPLACE_SHORTCODES, $applyEvent);
return $applyEvent->hasResult() ? $applyEvent->getResult() : $this->applyReplaces($text, $replaces);
}
private function applyReplaces($text, array $replaces)
{
return array_reduce(array_reverse($replaces), function($state, ReplacedShortcode $s) {
$offset = $s->getOffset();
$length = mb_strlen($s->getText(), 'utf-8');
$textLength = mb_strlen($state, 'utf-8');
return mb_substr($state, 0, $offset, 'utf-8').$s->getReplacement().mb_substr($state, $offset + $length, $textLength, 'utf-8');
}, $text);
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/plugins
/kirby-shortcode
/thunderer-shortcode
/vendor
/thunderer
/shortcode
/src
/Processor
/Processor.php
$this->handlers = $handlers;
}
/**
* Entry point for shortcode processing. Implements iterative algorithm for
* both limited and unlimited number of iterations.
*
* @param string $text Text to process
*
* @return string
*/
public function process($text)
{
$iterations = $this->maxIterations === null ? 1 : $this->maxIterations;
$context = new ProcessorContext();
$context->processor = $this;
while ($iterations--) {
$context->iterationNumber++;
$newText = $this->processIteration($text, $context, null);
if ($newText === $text) {
break;
}
$text = $newText;
$iterations += $this->maxIterations === null ? 1 : 0;
}
return $text;
}
private function dispatchEvent($name, $event)
{
if(null === $this->eventContainer) {
return $event;
}
$handlers = $this->eventContainer->getListeners($name);
foreach($handlers as $handler) {
call_user_func_array($handler, array($event));
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/plugins
/kirby-shortcode
/thunderer-shortcode
/vendor
/thunderer
/shortcode
/src
/ShortcodeFacade.php
public static function create(HandlerContainerInterface $handlers, SyntaxInterface $syntax)
{
$self = new self();
$self->handlers = $handlers;
$self->syntax = $syntax;
$self->rebuildProcessor();
return $self;
}
private function rebuildProcessor()
{
$this->processor = new Processor($this->parser, $this->handlers);
$this->processor = $this->processor->withEventContainer($this->events);
}
public function process($text)
{
return $this->processor->process($text);
}
public function parse($text)
{
return $this->parser->parse($text);
}
public function setParser(ParserInterface $parser)
{
$this->parser = $parser;
$this->rebuildProcessor();
return $this;
}
public function addHandler($name, $handler)
{
$this->handlers->add($name, $handler);
return $this;
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/plugins
/kirby-shortcode
/lib
/shortcode.php
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
class shortcode {
public static function parse($field) {
$facade = new ShortcodeFacade();
$data = c::get('plugin.shortcode.create');
$text = (string)$field;
if($data) {
foreach($data as $item) {
$key = $item['name'];
$callback = $item['text'];
if(is_callable($callback)) {
$facade->addHandler($key, function(ShortcodeInterface $shortcode) use ($callback, $field) {
return call_user_func_array($callback, [$shortcode, $field]);
});
}
}
return kirbytext($facade->process($text));
}
return kirbytext($text);
}
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/plugins
/kirby-shortcode
/lib
/field-methods.php
<?php
if(c::get('plugin.shortcode.field.method', true)) {
field::$methods['kirbytext'] = field::$methods['kt'] = function($field) {
$field->value = shortcode::parse($field);
return $field;
};
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/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);
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/kirby
/core
/field.php
/**
* Returns the field value
*
* @return string
*/
public function toString() {
return $this->value;
}
/**
* Applies registered Field methods
*
* @param string $method
* @param array $arguments
* @return mixed
*/
public function __call($method, $arguments = array()) {
if(isset(static::$methods[$method])) {
array_unshift($arguments, clone $this);
return call(static::$methods[$method], $arguments);
} else {
return $this;
}
}
/**
* Improved var_dump() output
*
* @return array
*/
public function __debuginfo() {
return [
'page' => $this->page()->id(),
'key' => $this->key(),
'value' => $this->value()
];
}
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/snippets
/sub_article.php
<?= $sub_page->text()->kirbytext() ?>
<div class="slider">
<?php foreach($sub_page->slideshow()->yaml() as $image): ?>
<?php if($image = $sub_page->image($image)): ?>
<figure><?= $image->html(); ?></figure>
<?php endif ?>
<?php endforeach; ?>
</div>
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/kirby
/vendor
/getkirby
/toolkit
/lib
/tpl.php
/**
* Tpl
*
* Super simple template engine
*
* @package Kirby Toolkit
* @author Bastian Allgeier <bastian@getkirby.com>
* @link http://getkirby.com
* @copyright Bastian Allgeier
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
class Tpl extends Silo {
public static $data = array();
public static function load($_file, $_data = array(), $_return = true) {
if(!file_exists($_file)) return false;
ob_start();
extract(array_merge(static::$data, (array)$_data));
require($_file);
$_content = ob_get_contents();
ob_end_clean();
if($_return) return $_content;
echo $_content;
}
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/kirby
/kirby
/component
/snippet.php
* Returns a snippet file path by name
*
* @param string $name
* @return string
*/
public function file($name) {
return $this->kirby->roots()->snippets() . DS . str_replace('/', DS, $name) . '.php';
}
/**
* Renders the snippet with the given data
*
* @param string $name
* @param array $data
* @param boolean $return
* @return string
*/
public function render($name, $data = [], $return = false) {
if(is_object($data)) $data = ['item' => $data];
return tpl::load($this->kirby->registry->get('snippet', $name), $data, $return);
}
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/kirby
/helpers.php
<?php
/**
* Embeds a snippet from the snippet folder
*
* @param string $file
* @param mixed $data array or object
* @param boolean $return
* @return string
*/
function snippet($file, $data = array(), $return = false) {
return kirby::instance()->component('snippet')->render($file, $data, $return);
}
/**
* Builds a css link tag for relative or absolute urls
*
* @param string $url
* @param string|array $media Either a media string or an array of attributes
* @return string
*/
function css() {
return call([kirby::instance()->component('css'), 'tag'], func_get_args());
}
/**
* Builds a script tag for relative or absolute links
*
* @param string $src
* @param boolean|array $async Either true for the async attribute or an array of attributes
* @return string
*/
function js() {
return call([kirby::instance()->component('js'), 'tag'], func_get_args());
}
/**
* Global markdown parser shortcut
*
* @param string $text
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/site
/templates
/default.php
<aside>
<?php snippet('menu') ?>
</aside>
<main>
<h1><?= $page->title()->html() ?></h1>
<?php $children = $page->children()->visible() ?>
<?php foreach($children as $child): ?>
<h2 id="<?=$child->slug()?>"><?= $child->title()->html() ?></h2>
<section>
<?php $sub_pages = $child->children()->visible() ?>
<?php foreach($sub_pages as $sub_page): ?>
<?php snippet($sub_page->intendedTemplate(), ['sub_page' => $sub_page]) ?>
<?php endforeach ?>
</section>
<?php endforeach ?>
</main>
<?php snippet('foot') ?>
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/kirby
/vendor
/getkirby
/toolkit
/lib
/tpl.php
/**
* Tpl
*
* Super simple template engine
*
* @package Kirby Toolkit
* @author Bastian Allgeier <bastian@getkirby.com>
* @link http://getkirby.com
* @copyright Bastian Allgeier
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
class Tpl extends Silo {
public static $data = array();
public static function load($_file, $_data = array(), $_return = true) {
if(!file_exists($_file)) return false;
ob_start();
extract(array_merge(static::$data, (array)$_data));
require($_file);
$_content = ob_get_contents();
ob_end_clean();
if($_return) return $_content;
echo $_content;
}
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/kirby
/kirby
/component
/template.php
if($template instanceof Page) {
$page = $template;
$file = $page->templateFile();
$data = $this->data($page, $data);
} else {
$file = $template;
$data = $this->data(null, $data);
}
// check for an existing template
if(!file_exists($file)) {
throw new Exception('The template could not be found');
}
// merge and register the template data globally
$tplData = tpl::$data;
tpl::$data = array_merge(tpl::$data, $data);
// load the template
$result = tpl::load($file, null, $return);
// reset the template data
tpl::$data = $tplData;
return $result;
}
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/kirby
/kirby.php
}
return $template;
}
// return a fresh template
return $this->template($page, $data);
}
/**
* Template configuration
*
* @param Page $page
* @param array $data
* @return string
*/
public function template(Page $page, $data = array()) {
return $this->component('template')->render($page, $data);
}
public function request() {
if(!is_null($this->request)) return $this->request;
return $this->request = new Request($this);
}
public function router() {
return $this->router;
}
public function route() {
return $this->route;
}
/**
* Starts the router, renders the page and returns the response
*
* @return mixed
*/
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/kirby
/kirby.php
}
}
// try to fetch the template from cache
$template = $this->cache()->get($cacheId);
// fetch fresh content if the cache is empty
if(empty($template)) {
$template = $this->template($page, $data);
// store the result for the next round
$this->cache()->set($cacheId, $template);
}
return $template;
}
// return a fresh template
return $this->template($page, $data);
}
/**
* Template configuration
*
* @param Page $page
* @param array $data
* @return string
*/
public function template(Page $page, $data = array()) {
return $this->component('template')->render($page, $data);
}
public function request() {
if(!is_null($this->request)) return $this->request;
return $this->request = new Request($this);
}
public function router() {
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/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;
}
}
}
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/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
*/
/srv
/data
/web
/vhosts
/vincent-maillard.fr
/htdocs
/projets
/eartsup
/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();