/** * Get the wizard base uri from the current path. * * @return string */ public function uriFromPath() { $path = kirby::instance()->path(); // Check if the current path includes the progress indicator if (preg_match('#/\\d$#', $path)) { // Strip numeric value indicating the progress $parts = explode('/', $path); array_pop($parts); $path = implode('/', $parts); } return $this->uri = $path; }
public function parse() { if (!$this->field) { return ''; } $text = $this->field->value; // pre filters foreach (static::$pre as $filter) { $text = call_user_func_array($filter, array($this, $text)); } // tagsify $text = preg_replace_callback('!(?=[^\\]])\\([a-z0-9_-]+:.*?\\)!is', array($this, 'tag'), $text); // markdownify if (kirby()->option('markdown')) { $text = call(kirby::instance()->option('markdown.parser'), $text); } // smartypantsify if (kirby()->option('smartypants')) { $text = str_replace('"', '"', $text); $text = call(kirby::instance()->option('smartypants.parser'), $text); } // post filters foreach (static::$post as $filter) { $text = call_user_func_array($filter, array($this, $text)); } return $text; }
public function __construct($path) { $this->kirby = kirby::instance(); if (is_a($path, 'Media')) { parent::__construct($path->root(), $path->url()); } else { parent::__construct(url::isAbsolute($path) ? null : $this->kirby->roots()->index() . DS . ltrim($path, DS), url::makeAbsolute($path)); } }
protected function tearDown() { s::restart(); // clean all triggers kirby::$triggered = array(); kirby::$hooks = array(); $this->removeContent(); $this->removeAccounts(); }
public function __construct() { $root = kirby::instance()->roots()->accounts(); foreach (dir::read($root) as $file) { // skip invalid account files if (f::extension($file) != 'php') { continue; } $user = new User(f::name($file)); $this->append($user->username(), $user); } }
public static function configure() { if (is_null(static::$site)) { static::$site = kirby::panelsetup(); } // load all available routes static::$routes = array_merge(static::$routes, require root('panel.app.routes') . DS . 'api.php'); static::$routes = array_merge(static::$routes, require root('panel.app.routes') . DS . 'views.php'); // setup the blueprint root blueprint::$root = c::get('root.site') . DS . 'blueprints'; // start the router static::$router = new Router(); static::$router->register(static::$routes); // content language switcher variable if (static::$site->multilang()) { if ($language = server::get('http_language') or $language = s::get('lang')) { static::$site->visit('/', $language); } app::$language = static::$site->language()->code(); s::set('lang', app::$language); } // load the interface language file if (static::$site->user()) { $languageCode = static::$site->user()->language(); } else { $languageCode = c::get('panel.language', 'en'); } // validate the language code if (!in_array($languageCode, static::languages()->keys())) { $languageCode = 'en'; } // store the interface language app::$interfaceLanguage = $languageCode; $language = (require root('panel.app.languages') . DS . $languageCode . '.php'); // set all language variables l::$data = $language['data']; // register router filters static::$router->filter('auth', function () { if (!app::$site->user()) { go('panel/login'); } }); // check for a completed installation static::$router->filter('isInstalled', function () { if (app::$site->users()->count() == 0) { go('panel/install'); } }); // only use the fragments of the path without params static::$path = implode('/', (array) url::fragments(detect::path())); }
public function __construct(User $user) { // store the parent user object $this->user = $user; // this should rather be coming from the user object $this->kirby = kirby::instance(); // try to find the avatar if ($file = f::resolve($this->kirby->roots()->avatars() . DS . $user->username(), ['jpg', 'jpeg', 'gif', 'png'])) { $filename = f::filename($file); } else { $filename = $user->username() . '.jpg'; $file = $this->kirby->roots()->avatars() . DS . $filename; } parent::__construct($file, $this->kirby->urls()->avatars() . '/' . $filename); }
function jade($template) { $templates = kirby::instance()->roots()->templates(); // Closure to recursively get the modification time from jade templates and // their super templates (determeined by pre-parsing 'extends' statements). $getChangeTime = function ($template, $time) use(&$getChangeTime, $templates) { $file = "{$templates}/{$template}.jade"; $t = @filectime($file); if ($t === false) { die("Can't open jade file '{$file}'"); } if ($t > $time) { $time = $t; } $fp = fopen($file, 'r'); // Find all the lines of the template that contains an valid statements, // and see there are any 'extends' or 'include' statements to determine // dependencies. while (true) { $line = fgets($fp); if ($line === false) { break; } $line = trim($line); if (!$line || !strncmp($line, '//', 2)) { continue; } if (!strncmp($line, 'extends ', 8) || !strncmp($line, 'include ', 8)) { $time = $getChangeTime(substr($line, 8), $time); } } fclose($fp); return $time; }; $time = $getChangeTime($template, 0); static $jade = null; if (!isset($jade) || !$jade) { $jade = new Jade\Jade(true); } $cache = kirby::instance()->roots()->cache() . DS . "{$template}.jade.php"; $t = @filectime($cache); // Now get the modification time from the cached file, and regenerate if // the jade template or any of its dependencies have changed. if ($t === false || $t < $time) { file_put_contents($cache, $jade->render("{$templates}/{$template}.jade")); } return $cache; }
function snippet_detect($file, $data = array(), $return = false) { if (is_object($data)) { $data = array('item' => $data); } // If the session variable is not found, set the default value (e.g 'mobile') $device_class = s::get('device_class', 'mobile'); // Embed the device class specific snippet if ($device_class == 'mobile') { // Embed the mobile snippet (`mobile` is the default snippet, without the device specific `.postfix`, e.g. footer.php) return tpl::load(kirby::instance()->roots()->snippets() . DS . $file . '.php', $data, $return); } else { // Embed the device class specific snippet (e.g. `footer.desktop.php`) return tpl::load(kirby::instance()->roots()->snippets() . DS . $file . '.' . $device_class . '.php', $data, $return); } }
protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->isInstalled()) { throw new RuntimeException('Invalid Kirby installation'); } // bootstrap the core $this->bootstrap(); $output->writeln("<info>Core:\t\t" . kirby::version() . "</info>"); $output->writeln("<info>Toolkit:\t" . toolkit::version() . "</info>"); // also check for the panel version, if it is installed if (is_dir($this->dir() . '/panel')) { if (!is_file($this->dir() . '/panel/app/bootstrap.php')) { throw new RuntimeException('The panel does not seem to be correctly installed'); } // bootstrap the panel require $this->dir() . '/panel/app/bootstrap.php'; $output->writeln("<info>Panel:\t\t" . panel::version() . "</info>"); } }
/** * Constructor */ public function __construct() { $roles = kirby::instance()->option('roles'); // set the default set of roles, if roles are not configured if (empty($roles)) { $roles = array(array('id' => 'admin', 'name' => 'Admin', 'default' => true), array('id' => 'editor', 'name' => 'Editor', 'permissions' => array('panel.access' => true, 'panel.site.update' => false, 'panel.page.create' => true, 'panel.page.update' => true, 'panel.page.move' => true, 'panel.page.sort' => true, 'panel.page.hide' => true, 'panel.page.delete' => true, 'panel.file.upload' => true, 'panel.file.replace' => true, 'panel.file.update' => true, 'panel.file.delete' => true, 'panel.user.add' => false, 'panel.user.edit' => false, 'panel.user.role' => false, 'panel.user.delete' => false))); } foreach ($roles as $role) { $role = new Role($role); $this->data[$role->id()] = $role; } // check for a valid admin role if (!isset($this->data['admin'])) { throw new Exception('There must be an admin role'); } // check for a valid default role if (!$this->findDefault()) { $this->data['admin']->default = true; } }
/** * Constructor */ public function __construct() { $roles = kirby::instance()->option('roles'); // set the default set of roles, if roles are not configured if (empty($roles)) { $roles = array(array('id' => 'admin', 'name' => 'Admin', 'default' => true, 'panel' => true), array('id' => 'editor', 'name' => 'Editor', 'panel' => true)); } foreach ($roles as $role) { $role = new Role($role); $this->data[$role->id()] = $role; } // check for a valid admin role if (!isset($this->data['admin'])) { throw new Exception('There must be an admin role'); } // check for a valid default role if (!$this->findDefault()) { $this->data['admin']->default = true; } }
/** * Creates a new user * * @param array $user * @return User */ public static function create($data = array()) { // sanitize the given data for the new user $data = static::sanitize($data, 'insert'); // validate the dataset static::validate($data, 'insert'); // create the file root $file = kirby::instance()->roots()->accounts() . DS . $data['username'] . '.php'; // check for an existing username if (file_exists($file)) { throw new Exception('The username is taken'); } // create a new hash for the password if (!empty($data['password'])) { $data['password'] = password::hash($data['password']); } static::save($file, $data); // return the created user project return new static($data['username']); }
public function defaults() { $defaults = array('url' => false, 'timezone' => 'UTC', 'license' => null, 'rewrite' => true, 'error' => 'error', 'home' => 'home', 'locale' => 'en_US.UTF8', 'routes' => array(), 'headers' => array(), 'languages' => array(), 'roles' => array(), 'cache' => false, 'debug' => 'env', 'ssl' => false, 'cache.driver' => 'file', 'cache.options' => array(), 'cache.ignore' => array(), 'cache.autoupdate' => true, 'date.handler' => 'date', 'tinyurl.enabled' => true, 'tinyurl.folder' => 'x', 'markdown' => true, 'markdown.extra' => false, 'markdown.breaks' => true, 'smartypants' => false, 'smartypants.attr' => 1, 'smartypants.doublequote.open' => '“', 'smartypants.doublequote.close' => '”', 'smartypants.space.emdash' => ' ', 'smartypants.space.endash' => ' ', 'smartypants.space.colon' => ' ', 'smartypants.space.semicolon' => ' ', 'smartypants.space.marks' => ' ', 'smartypants.space.frenchquote' => ' ', 'smartypants.space.thousand' => ' ', 'smartypants.space.unit' => ' ', 'smartypants.skip' => 'pre|code|kbd|script|style|math', 'kirbytext.video.class' => 'video', 'kirbytext.video.width' => false, 'kirbytext.video.height' => false, 'kirbytext.image.figure' => true, 'content.file.extension' => 'txt', 'content.file.ignore' => array(), 'content.file.normalize' => false, 'thumbs.driver' => 'gd', 'thumbs.filename' => '{safeName}-{hash}.{extension}', 'thumbs.destination' => false); // default markdown parser callback $defaults['markdown.parser'] = function ($text) { // initialize the right markdown class $parsedown = kirby::instance()->option('markdown.extra') ? new ParsedownExtra() : new Parsedown(); // set markdown auto-breaks $parsedown->setBreaksEnabled(kirby::instance()->option('markdown.breaks')); // parse it! return $parsedown->text($text); }; // default smartypants parser callback $defaults['smartypants.parser'] = function ($text) { $parser = new SmartyPantsTypographer_Parser(kirby::instance()->option('smartypants.attr', 1)); return $parser->transform($text); }; // css handler $defaults['css.handler'] = function ($url, $media = null) { $kirby = kirby::instance(); if (is_array($url)) { $css = array(); foreach ($url as $u) { $css[] = call($kirby->option('css.handler'), array($u, $media)); } return implode(PHP_EOL, $css) . PHP_EOL; } // auto template css files if ($url == '@auto') { $file = $kirby->site()->page()->template() . '.css'; $root = $kirby->roots()->autocss() . DS . $file; $url = $kirby->urls()->autocss() . '/' . $file; if (!file_exists($root)) { return false; } } return html::tag('link', null, array('rel' => 'stylesheet', 'href' => url($url), 'media' => $media)); }; // js handler $defaults['js.handler'] = function ($src, $async = false) { $kirby = kirby::instance(); if (is_array($src)) { $js = array(); foreach ($src as $s) { $js[] = call($kirby->option('js.handler'), array($s, $async)); } return implode(PHP_EOL, $js) . PHP_EOL; } // auto template css files if ($src == '@auto') { $file = $kirby->site()->page()->template() . '.js'; $root = $kirby->roots()->autojs() . DS . $file; $src = $kirby->urls()->autojs() . '/' . $file; if (!file_exists($root)) { return false; } } return html::tag('script', '', array('src' => url($src), 'async' => $async)); }; return $defaults; }
/** * Get or set the user agent send with each request. * * @param string $name User agent to send. * @return string|self */ public function agent($name = null) { if (is_null($name)) { $kirby = 'Kirby/' . kirby::version(); $plugin = isset($this->agent) ? $this->agent : 'Kirby Comments/' . plugin('comments')->version(); return $kirby . ' | ' . $plugin; } $this->agent = $name; return $this; }
public function users() { return kirby::instance()->site()->users()->filterBy('role', $this->id); }
<?php define('DS', DIRECTORY_SEPARATOR); // load the cms bootstrapper include __DIR__ . DS . 'kirby' . DS . 'bootstrap.php'; // start the cms echo kirby::start();
/** * Returns either the current page or any page for a given uri * * @return Page */ function page() { return call_user_func_array(array(kirby::site(), 'page'), func_get_args()); }
public function requirements() { if (!version_compare(PHP_VERSION, static::$requires['php'], '>=')) { throw new Exception('Your PHP version is too old. Please upgrade to ' . static::$requires['php'] . ' or newer.'); } if (!detect::mbstring()) { throw new Exception('The mbstring extension must be installed'); } if (!version_compare(toolkit::version(), static::$requires['toolkit'], '>=')) { throw new Exception('Your Toolkit version is too old. Please upgrade to ' . static::$requires['toolkit'] . ' or newer.'); } if (!version_compare(kirby::version(), static::$requires['kirby'], '>=')) { throw new Exception('Your Kirby version is too old. Please upgrade to ' . static::$requires['kirby'] . ' or newer.'); } }
} ?> </div> <nav class="slider-nav"> <a class="slider-prev" href="#"><span>‹</span></a> <a class="slider-next" href="#"><span>›</span></a> </nav> </div> <section class="intro"> <h1 class="alpha with-beta">Kirby is a file‑based CMS</h1> <p class="beta">Easy to setup. Easy to use. Flexible as hell.</p> <a class="btn-white" href="<?php echo url('try'); ?> ">Download <?php echo kirby::version(); ?> </a> </section> </div> </header> <div class="site"> <?php } else { ?> <div class="site"> <header class="site-header" role="banner">
/** * Helper to create correct text file names for content files * * @param string $uri * @param string $template * @param string $lang * @return string */ function textfile($uri, $template = null, $lang = null) { if (is_null($template)) { $template = $this->intendedTemplate(); } $curi = ''; $parts = str::split($uri, '/'); $parent = site(); foreach ($parts as $p) { if ($parent and $child = $parent->children()->find($p)) { $curi .= '/' . $child->dirname(); $parent = $child; } else { $curi .= '/' . $p; $parent = null; } } $uri = ltrim($curi, '/'); $root = kirby::instance()->roots()->content(); $ext = kirby::instance()->option('content.file.extension', 'txt'); return $root . DS . r(!empty($uri), str_replace('/', DS, $uri) . DS) . $template . r($lang, '.' . $lang) . '.' . $ext; }
<?php ob_start(); $q = call(kirby::instance()->option('smartypants.parser'), get('q')); $words = implode('|', explode(' ', $q)); $pages = $site->search(get('q'), 'title|text')->filter(function ($page) { return $page->visible() || $page->intendedTemplate() == 'news' || $page->intendedTemplate() == 'event' || $page->intendedTemplate() == 'annual-report'; }); $url = function ($page) { return $page->article()->empty() ? $page->intendedTemplate() === 'external' ? $page->external() : $page->url() . '?' . http_build_query(['matches' => get('q')]) : $page->article()->toFile()->url(); }; $target = function ($page) { return !$page->article()->empty() || $page->intendedTemplate() === 'external' ? '_blank' : '_self'; }; foreach ($pages as $page) { ?> <article> <a class="link-list__link" href="<?php echo $url($page); ?> " target="<?php echo $target($page); ?> "> <?php if ($page->parents()->count() > 0) { ?> <header class="link-list__meta"> <?php echo implode(' > ', $page->parents()->flip()->map(function ($page) { return $page->title()->html();
<?php // load the bootstrapper include __DIR__ . DIRECTORY_SEPARATOR . 'bootstrap.php'; // start the cms echo kirby::start(array('root.content' => $rootContent, 'root.site' => $rootSite));
/** * Returns the absolute URL for the file * * @return string */ public function url() { return kirby::instance()->urls()->content() . '/' . $this->page->diruri() . '/' . $this->filename; }
public function testInstance() { $kirby = $this->kirbyInstance(); $this->assertEquals($kirby, kirby::instance()); }
/** * Creates a new page object * * @param string $uri * @param string $template * @param array $data */ public static function create($uri, $template, $data = array()) { if (!is_string($template) or empty($template)) { throw new Exception('Please pass a valid template name as second argument'); } // try to create the new directory $uri = static::createDirectory($uri); // create the path for the textfile $file = textfile($uri, $template); // try to store the data in the text file if (!data::write($file, $data, 'kd')) { throw new Exception('The page file could not be created'); } // get the new page object $page = page($uri); if (!is_a($page, 'Page')) { throw new Exception('The new page object could not be found'); } kirby::instance()->cache()->flush(); return $page; }
/** * Compile less to css and then call css.handler * * @param string $url * @param string $media * @return string */ function less() { return call(kirby::instance()->option('less.handler'), func_get_args()); }
/** * Returns the full path to the intended template file * This template file may not exist. * * @return string */ public function intendedTemplateFile() { return kirby::instance()->roots()->templates() . DS . $this->intendedTemplate() . '.php'; }