public function num() { $obj = new Obj(); $obj->mode = 'default'; $obj->field = null; $obj->format = null; if (is_array($this->num)) { foreach ($this->num as $k => $v) { $obj->{$k} = $v; } } else { if (!empty($this->num)) { $obj->mode = $this->num; } } switch ($obj->mode) { case 'date': // switch the default date format by configured handler $defaultDateFormat = kirby()->option('date.handler') == 'strftime' ? '%Y%m%d' : 'Ymd'; // set the defaults isset($obj->field) or $obj->field = 'date'; isset($obj->format) or $obj->format = $defaultDateFormat; break; } return $obj; }
private static function routes() { kirby()->routes(array(array('pattern' => self::$route, 'action' => function () { echo SplitviewTool::html(); }), array('pattern' => self::$route . '/assets/css/tool.css', 'action' => function () { $path = self::$assets . 'css' . DS . 'tool.css'; return new Response(f::read($path), 'css'); }), array('pattern' => self::$route . '/assets/css/tool.min.css', 'action' => function () { $path = self::$assets . 'css' . DS . 'tool.min.css'; return new Response(f::read($path), 'css'); }), array('pattern' => self::$route . '/assets/js/dist/tool.js', 'action' => function () { $path = self::$assets . 'js' . DS . 'dist/tool.js'; return new Response(f::read($path), 'js'); }), array('pattern' => self::$route . '/assets/js/dist/tool.min.js', 'action' => function () { $path = self::$assets . 'js' . DS . 'dist/tool.min.js'; return new Response(f::read($path), 'js'); }), array('pattern' => self::$route . '/assets/js/src/site.js', 'action' => function () { $path = self::$assets . 'js' . DS . 'src/site/site.js'; return new Response(f::read($path), 'js'); }), array('pattern' => self::$route . '/assets/js/dist/site.min.js', 'action' => function () { $path = self::$assets . 'js' . DS . 'dist/site.min.js'; return new Response(f::read($path), 'js'); }), array('pattern' => self::$route . '/assets/fonts/font-awesome.woff', 'action' => function () { $path = self::$assets . 'fonts' . DS . 'font-awesome-4.5.0' . DS . 'fontawesome-webfont.woff'; return new Response(f::read($path), 'woff'); }), array('pattern' => self::$route . '/assets/fonts/source-sans-pro.woff', 'action' => function () { $path = self::$assets . 'fonts' . DS . 'source-sans-pro' . DS . 'SourceSansPro-Regular.otf.woff'; return new Response(f::read($path), 'woff'); }))); }
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 create($uid, $template, $content = array()) { if (empty($template)) { throw new Exception(l('pages.add.error.template')); } $uid = empty($uid) ? str::random(32) : $uid; $blueprint = new Blueprint($template); $data = array(); foreach ($blueprint->fields(null) as $key => $field) { $data[$key] = $field->default(); } $data = array_merge($data, $content); // create the new page and convert it to a page model $page = new Page($this->page, parent::create($uid, $template, $data)->dirname()); if (!$page) { throw new Exception(l('pages.add.error.create')); } kirby()->trigger('panel.page.create', $page); // subpage builder foreach ((array) $page->blueprint()->pages()->build() as $build) { $missing = a::missing($build, array('title', 'template', 'uid')); if (!empty($missing)) { continue; } $subpage = $page->children()->create($build['uid'], $build['template'], array('title' => $build['title'])); if (isset($build['num'])) { $subpage->sort($build['num']); } } return $page; }
public function inspectPanelOptions() { $root = kirby()->roots()->index() . DS . '/panel'; require_once $root . DS . '/app/bootstrap.php'; $panel = new Kirby\Panel(kirby(), $root); $this->inspectOptions($panel->defaults()); }
/** * Instantiate the Manager Route Handler * * @return void */ public function __construct() { if (!site()->user() || !site()->user()->hasRole('admin', 'manager')) { flash('login.redirect', kirby()->request()->url()); go('login'); } }
public function index() { if (site()->users()->count() > 0) { go(panel()->urls()->login()); } if ($problems = installation::check()) { $content = view('installation/check', array('problems' => $problems)); } else { $form = panel()->form('installation', array('language' => kirby()->option('panel.language', 'en'))); $form->cancel = false; $form->save = l('installation.signup.button'); $form->centered = true; foreach (panel()->languages() as $lang) { $form->fields()->get('language')->options[$lang->code()] = $lang->title(); } $form->on('submit', function ($form) { try { // fetch all the form data $data = $form->serialize(); // make sure that the first user is an admin $data['role'] = 'admin'; // try to create the new user $user = panel()->site()->users()->create($data); // store the new username for the login screen s::set('username', $user->username()); // redirect to the login go(panel()->urls()->login() . '/welcome'); } catch (Exception $e) { $form->alert($e->getMessage()); } }); $content = view('installation/signup', array('form' => $form)); } return layout('installation', array('meta' => new Snippet('meta'), 'content' => $content)); }
/** * Create an instance of the view * * @param array $options * @return void */ public function __construct($options = array()) { $views = isset($options['views']) ? $options['views'] : Config::get('blade_views_dir', kirby()->roots()->templates()); $cache = isset($options['cache']) ? $options['cache'] : Config::get('blade_cache_dir', kirby()->roots()->cache() . DS . 'views'); $this->engine = new Blade($views, $cache); $this->setEchoFormat(); }
protected function checkAvatars() { $root = kirby()->roots()->avatars(); // try to create the avatars folder dir::make($root); return is_writable($root); }
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()); } }))); } }
protected function form($user = null) { $mode = $user ? 'edit' : 'add'; $fields = data::read(panel()->roots()->forms() . DS . 'user.' . $mode . '.php', 'yaml'); $content = $user ? $user->data() : array(); // add all languages $fields['language']['options'] = array(); $fields['language']['default'] = kirby()->option('panel.language', 'en'); foreach (panel()->languages() as $code => $lang) { $fields['language']['options'][$code] = $lang->title(); } // add all roles $fields['role']['options'] = array(); $fields['role']['default'] = site()->roles()->findDefault()->id(); foreach (site()->roles() as $role) { $fields['role']['options'][$role->id()] = $role->name(); } // make the role selector readonly when the user is not an admin if (!site()->user()->isAdmin()) { $fields['role']['readonly'] = true; } // make sure the password is never shown in the form unset($content['password']); return new Form($fields, $content); }
public function toHtml() { $snippet = kirby()->roots()->snippets() . DS . 'webmentions' . DS . 'author.php'; if (!file_exists($snippet)) { $snippet = dirname(__DIR__) . DS . 'snippets' . DS . 'author.php'; } return tpl::load($snippet, array('author' => $this, 'mention' => $this->mention)); }
public function __construct($user) { if ($user = kirby()->site()->user($user->username())) { $this->user = $user; } else { throw new Exception('The user could not be found'); } }
public function __construct($dir = null) { $this->dir = $dir ? $dir : kirby()->roots()->cache(); if (!file_exists($this->dir)) { mkdir($this->dir); } $this->Cache = cache::setup('file', array('root' => $this->dir)); }
/** * Create a new CrazyMailer * * @var array $config data, accepts same as Email::__construct() */ public function __construct($config) { $defaults = ['to' => KirbyConfig::get('mailer.to'), 'from' => KirbyConfig::get('mailer.from'), 'service' => 'mailgun', 'options' => ['key' => KirbyConfig::get('mailgun.key'), 'domain' => KirbyConfig::get('mailgun.domain')]]; $this->emailer = new KirbyEmailer(KirbyArray::merge($defaults, $config)); $this->enabled = env('MAILER_ENABLED', false); $handler = new StreamHandler(kirby()->roots()->site() . '/../logs/emailer.log', Logger::WARNING); $this->logger = new Logger('crazy'); $this->logger->pushHandler($handler); }
/** * Load Twig */ private function twig() { $loader = new Twig_Loader_Filesystem(kirby()->roots()->twig()); $twig = new Twig_Environment($loader, array('debug' => c::get('debug'))); if (c::get('debug')) { $twig->addExtension(new Twig_Extension_Debug()); } tpl::set('twig', $twig); }
/** * Load field dependencies. * * @return array */ public function load() { $loaded = array(); $dependencies = array('comments'); foreach ($dependencies as $d) { $loaded[] = kirby()->plugin($d); } return $loaded; }
/** * Render a template from the /site/templates/ directory * * @param string $file The filename of the template to render * @param array $data Data for the template * @param $return Default false, Set to true to return the output * @return void */ protected function render($file = 'index', $data = [], $return = false) { tpl::$data = array_merge(tpl::$data, ['kirby' => kirby(), 'site' => site(), 'pages' => pages()], $data); $output = tpl::load(kirby()->roots()->templates() . '/' . $file . '.php'); if ($return) { return $output; } die($output); }
function get_blueprint_path($blueprint) { $path = kirby()->roots->blueprints() . DS; $file = glob($path . $blueprint . '.php'); if (count($file) == 1) { return $file[0]; } else { return false; } }
public function create($data) { if ($data['password'] !== $data['passwordconfirmation']) { throw new Exception(l('users.form.error.password.confirm')); } unset($data['passwordconfirmation']); $user = parent::create($data); kirby()->trigger('panel.user.create', $user); return new User($user->username()); }
/** * Get formatted date fields * * @param string $format * @param string $field * @return string */ public function date($format = null, $field = 'date') { if ($timestamp = strtotime($this->get($field))) { if (is_null($format)) { return $timestamp; } else { return kirby()->options['date.handler']($format, $timestamp); } } }
public function __construct() { $this->type = 'text'; $this->icon = 'user'; $this->label = l::get('fields.user.label', 'User'); $this->options = array(); foreach (kirby()->site()->users() as $user) { $this->options[$user->username()] = $user->username(); } }
public function custom() { $root = kirby()->roots()->widgets(); foreach (dir::read($root) as $dir) { // add missing widgets to the order array if (!array_key_exists($dir, $this->order)) { $this->order[$dir] = true; } $this->load($dir, $root . DS . $dir . DS . $dir . '.php'); } }
public function _extend($params) { $extends = $params['extends']; $file = kirby()->get('blueprint', 'fields/' . $extends); if (empty($file) || !is_file($file)) { throw new Exception(l('fields.error.extended')); } $yaml = data::read($file, 'yaml'); $params = a::merge($yaml, $params); return $params; }
public function _extend($params) { $extends = $params['extends']; $files = glob(kirby()->roots()->blueprints() . DS . 'fields' . DS . $extends . '.{yml,yaml,php}', GLOB_BRACE); if (empty($files)) { throw new Exception(l('fields.error.extended')); } $yaml = data::read($files[0], 'yaml'); $params = a::merge($yaml, $params); return $params; }
public function _extend($params) { $extends = $params['extends']; $snippet = f::resolve(kirby()->roots()->blueprints() . DS . 'fields' . DS . $extends, array('yml', 'php', 'yaml')); if (empty($snippet)) { throw new Exception(l('fields.error.extended')); } $yaml = data::read($snippet, 'yaml'); $params = a::merge($yaml, $params); return $params; }
public function delete() { if (!panel()->user()->isAdmin() and !$this->isCurrent()) { throw new Exception(l('users.delete.error.permission')); } if ($this->isLastAdmin()) { // check the number of left admins to not delete the last one throw new Exception(l('users.delete.error.lastadmin')); } parent::delete(); kirby()->trigger('panel.user.delete', $this); }
public function __construct() { $this->kirby = kirby(); $this->path = $this->kirby->option('patterns.path', 'patterns'); $this->title = $this->kirby->option('patterns.title', 'Patterns'); $this->root = $this->kirby->option('patterns.directory', $this->kirby->roots()->site() . DS . 'patterns'); $lab = $this; // inject the patterns routes kirby()->routes([['pattern' => $this->path . '/(:all?)', 'action' => function ($path = null) use($lab) { return $lab->run($path); }]]); static::$instance = $this; }
public function index() { $widgets = array(); $wroot = kirby()->roots()->widgets(); $wdirs = dir::read($wroot); foreach ($wdirs as $dir) { $file = $wroot . DS . $dir . DS . $dir . '.php'; if (file_exists($file)) { $widgets[$dir] = (require $file); } } return view('dashboard/index', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('breadcrumb'), 'search' => purl('pages/search/'))), 'history' => history::get(), 'site' => site(), 'widgets' => $widgets, 'user' => site()->user())); }
protected function date() { foreach ($this->siblings as $sibling) { // get the date $date = $sibling->date($this->params->format(), $this->params->field()); // take the current date if the date is missing if (!$date) { $handler = kirby()->option('date.handler'); $date = $handler($this->params->format()); } $sibling->_sort($date); } }