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 __construct($kirby, $root) { // check requirements $this->requirements(); // store the instance as a singleton static::$instance = $this; $this->kirby = $kirby; $this->roots = new \Kirby\Panel\Roots($this, $root); $this->urls = new \Kirby\Panel\Urls($this, $root); // add the panel default options $this->kirby->options = array_merge($this->defaults(), $this->kirby->options); // setup the blueprints roots UserBlueprint::$root = $this->kirby->roots()->blueprints() . DS . 'users'; PageBlueprint::$root = $this->kirby->roots()->blueprints(); // load the site object $this->site = $this->site(); // setup the session $this->session(); // setup the multilang site stuff $this->multilang(); // load all Kirby extensions (methods, tags, smartypants) $this->kirby->extensions(); $this->kirby->plugins(); // setup the form plugin form::$root = array('default' => $this->roots->fields, 'custom' => $this->kirby->roots()->fields()); // force ssl if set in config if ($this->kirby->option('ssl') and !r::secure()) { // rebuild the current url with https go(url::build(array('scheme' => 'https'))); } // load all available routes $this->routes = array_merge($this->routes, require $this->roots->config . DS . 'routes.php'); // start the router $this->router = new Router($this->routes); // register router filters $this->router->filter('auth', function () use($kirby) { try { $user = panel()->user(); } catch (Exception $e) { panel()->redirect('login'); } }); // check for a completed installation $this->router->filter('isInstalled', function () use($kirby) { $installer = new Installer(); if (!$installer->isCompleted()) { panel()->redirect('install'); } }); // check for valid csrf tokens. Can be used for get requests // since all post requests are blocked anyway $this->router->filter('csrf', function () { panel()->csrfCheck(); }); // csrf protection for every post request if (r::is('post')) { $this->csrfCheck(); } }
public function blueprint() { if (isset($this->cache['blueprint'])) { return $this->cache['blueprint']; } $blueprint = $this->intendedTemplate(); if (!Blueprint::exists($blueprint)) { $blueprint = $this->template(); } return $this->cache['blueprint'] = new Blueprint($blueprint); }
public function prepareForNewTemplate($oldTemplate, $newTemplate, $language = null) { $data = array(); $incompatible = array(); $content = $this->content($language); $oldBlueprint = new Blueprint($oldTemplate); $oldFields = $oldBlueprint->fields($this); $newBlueprint = new Blueprint($newTemplate); $newFields = $newBlueprint->fields($this); // log $removed = array(); $replaced = array(); $added = array(); // first overwrite everything foreach ($oldFields as $oldField) { $data[$oldField->name()] = null; } // now go through all new fileds and compare them to the old field types foreach ($newFields as $newField) { $oldField = $oldFields->{$newField->name()}; // only take data from fields with matching names and types if ($oldField and $oldField->type() == $newField->type()) { $data[$newField->name()] = $content->get($newField->name())->value(); } else { $data[$newField->name()] = $newField->default(); if ($oldField) { $replaced[$newField->name()] = $newField->label(); } else { $added[$newField->name()] = $newField->label(); } } } foreach ($data as $name => $content) { if (is_null($content)) { $removed[$name] = $oldFields->{$name}->label(); } } return array('data' => $data, 'removed' => $removed, 'replaced' => $replaced, 'added' => $added); }