public function update($id) { $filename = get('filename'); $page = $this->page($id); if (!$page) { return response::error(l('files.error.missing.page')); } $file = $page->file($filename); if (!$file) { return response::error(l('files.error.missing.file')); } $blueprint = blueprint::find($page); $fields = $blueprint->files()->fields($page); // trigger the validation $form = new Form($fields->toArray()); $form->validate(); // fetch the form data $data = filedata::createByInput($file, $form->serialize()); // stop at invalid fields if (!$form->isValid()) { return response::error(l('files.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name'))); } try { $file->update($data, app::$language); return response::success('success', array('data' => $data)); } catch (Exception $e) { return response::error($e->getMessage()); } }
public function show($id = null) { $filename = get('filename'); $page = $this->page($id); $file = $this->file($page, $filename); $blueprint = blueprint::find($page); $fields = $blueprint->files()->fields($page); $meta = $file->meta()->toArray(); $files = api::files($page, $blueprint); $index = $files->indexOf($file); $next = $files->nth($index + 1); $prev = $files->nth($index - 1); // breadcrumb items if ($page->isSite()) { $items = array(array('url' => purl('metatags'), 'title' => l('metatags')), array('url' => purl('files/index'), 'title' => l('metatags.files')), array('url' => purl($file, 'show'), 'title' => $file->filename())); } else { $items = array(array('url' => purl('files/index/' . $page->id()), 'title' => l('files')), array('url' => purl($file, 'show'), 'title' => $file->filename())); } // file info display $info = array(); $info[] = $file->type(); $info[] = $file->niceSize(); if ((string) $file->dimensions() != '0 x 0') { $info[] = $file->dimensions(); } return view('files/show', array('topbar' => new Snippet('pages/topbar', array('menu' => new Snippet('menu'), 'breadcrumb' => new Snippet('pages/breadcrumb', array('page' => $page, 'items' => $items)), 'search' => purl($page, 'search'))), 'form' => new Form($fields->toArray(), $meta), 'p' => $page, 'f' => $file, 'next' => $next, 'prev' => $prev, 'info' => implode(' / ', $info))); }
public function sort($id = '') { $page = $this->page($id); $blueprint = blueprint::find($page); $uids = get('uids'); $flip = $blueprint->pages()->sort() == 'flip'; $children = $page->children(); if ($flip) { $index = get('index', 1); $uids = array_reverse($uids); $n = $page->children()->visible()->count() - ($index * $blueprint->pages()->limit() - 1); if ($n <= 0) { $n = 1; } } else { $index = get('index', 1) - 1; $n = $blueprint->pages()->limit() * $index + 1; } foreach ($uids as $uid) { try { $child = $children->find($uid); $x = api::createPageNum($child, $blueprint); if ($x !== false and $x >= 0) { $child->sort($x); } else { $child->sort($n); } $n++; } catch (Exception $e) { } } return response::success('success'); }
public function structure($id, $fieldName, $context) { $page = empty($id) ? site() : page($id); if (!$page) { throw new Exception('The page could not be found'); } $blueprint = blueprint::find($page); $field = null; $fields = $context == 'file' ? $blueprint->files()->fields() : $blueprint->fields(); // make sure to get fields by case insensitive field names foreach ($fields as $f) { if (strtolower($f->name) == strtolower($fieldName)) { $field = $f; } } if (!$field) { throw new Exception('The field could not be found'); } $fields = new Blueprint\Fields($field->fields(), $page); $fields = $fields->toArray(); foreach ($fields as $key => $field) { if ($field['type'] == 'textarea') { $fields[$key]['buttons'] = false; } } $form = new Form($fields, null, $fieldName); $form->save = get('_id') ? l('fields.structure.save') : l('fields.structure.add'); return view('editor/structure', array('page' => $page, 'form' => $form)); }
public function __construct($kirby, $dir) { static::$instance = $this; $this->kirby = $kirby; $this->site = $kirby->site(); $this->roots = new Panel\Roots($dir); $this->urls = new Panel\Urls($kirby->urls()->index() . '/' . basename($dir)); $this->load(); // load all available routes $this->routes = array_merge($this->routes, require $this->roots->routes . DS . 'api.php'); $this->routes = array_merge($this->routes, require $this->roots->routes . DS . 'views.php'); // setup the blueprint root blueprint::$root = $this->kirby->roots()->blueprints(); // setup the form plugin form::setup($this->roots->fields, $this->kirby->roots()->fields()); // start the router $this->router = new Router($this->routes); // register router filters $this->router->filter('auth', function () use($kirby) { $user = $kirby->site()->user(); if (!$user or !$user->hasPanelAccess()) { if ($user) { $user->logout(); } go('panel/login'); } }); // check for a completed installation $this->router->filter('isInstalled', function () use($kirby) { if ($kirby->site()->users()->count() == 0) { go('panel/install'); } }); }
public function headline() { if (!$this->readonly) { $fieldName = $this->name; $blueprint = blueprint::find($this->page()); $fieldsets = $blueprint->fields()->{$fieldName}->fieldsets; $addDropdownHtml = '<div class="drop-down">'; $addDropdownHtml .= '<a class="drop-down-toggle label-option"><i class="icon icon-left fa fa-chevron-circle-down"></i>' . l('fields.structure.add') . '</a>'; $addDropdownHtml .= '<ul>'; foreach ($fieldsets as $fieldsetName => $fieldsetFields) { $addDropdownHtml .= '<li>'; $addDropdownHtml .= '<a href="#0" class="builder-add-button" data-fieldset="' . $fieldsetName . '"><i class="icon icon-left fa fa-plus-circle"></i>' . $fieldsetFields['label'] . '</a>'; $addDropdownHtml .= '</li>'; } $addDropdownHtml .= '</ul>'; $addDropdownHtml .= '</div>'; } else { $addButtons[] = null; } $label = parent::label(); $label->addClass('builder-label'); // foreach ($addButtons as $key => $value) { // $label->append($add[$key]); // } $label->append($addDropdownHtml); return $label; }
public function index() { $site = site(); $blueprint = blueprint::find($site); $fields = $blueprint->fields()->toArray(); $content = $site->content()->toArray(); return view('metatags/index', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('breadcrumb', array('items' => array(array('title' => l('metatags'), 'url' => purl('metatags/'))))), 'search' => purl('pages/search/'))), 'form' => new Form($fields, $content), 's' => $site)); }
public static function keep($page) { $blueprint = blueprint::find($page); $fields = $blueprint->fields($page); // trigger the validation $form = new Form($fields->toArray()); // fetch the data for the form $data = pagedata::createByInput($page, $form->serialize()); static::update($page, $data); }
public static function createByBlueprint($blueprint, $input = array()) { $bp = blueprint::find($blueprint); if (!$bp) { return $input; } $data = array(); foreach ($bp->fields() as $key => $field) { $data[$key] = $field->default(); } return array_merge($data, $input); }
public function index() { $site = site(); $blueprint = blueprint::find($site); $fields = $blueprint->fields($site)->toArray(); $content = $site->content()->toArray(); $files = null; // create the files if ($blueprint->files()->max() !== 0 and $blueprint->files()->hide() == false) { $files = new Snippet('pages/sidebar/files', array('page' => $site, 'files' => api::files($site, $blueprint))); } return view('metatags/index', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('breadcrumb', array('items' => array(array('title' => l('metatags'), 'url' => purl('metatags/'))))), 'search' => purl('pages/search/'))), 'form' => new Form($fields, $content), 's' => $site, 'files' => $files, 'license' => panel()->license())); }
public function structure($id, $field) { $page = empty($id) ? site() : page($id); if (!$page) { throw new Exception('The page could not be found'); } $blueprint = blueprint::find($page); $field = $blueprint->fields()->get($field); $fields = new Blueprint\Fields($field->fields(), $page); $form = new Form($fields->toArray()); $form->save = get('_id') ? l('fields.structure.save') : l('fields.structure.add'); return view('editor/structure', array('page' => $page, 'form' => $form)); }
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 show($id) { $filename = get('filename'); $page = $this->page($id); $file = $this->file($page, $filename); $blueprint = blueprint::find($page); $fields = $blueprint->files()->fields($page); $meta = $file->meta()->toArray(); $files = api::files($page, $blueprint); $index = $files->indexOf($file); $next = $files->nth($index + 1); $prev = $files->nth($index - 1); return view('files/show', array('topbar' => new Snippet('pages/topbar', array('menu' => new Snippet('menu'), 'breadcrumb' => new Snippet('pages/breadcrumb', array('page' => $page, 'items' => array(array('url' => purl('files/index/' . $page->id()), 'title' => l('files')), array('url' => purl($file, 'show'), 'title' => $file->filename())))), 'search' => purl($page, 'search'))), 'form' => new Form($fields->toArray(), $meta), 'p' => $page, 'f' => $file, 'next' => $next, 'prev' => $prev)); }
function i($icon, $position = null) { if (is_string($icon)) { echo '<i class="icon' . r($position, ' icon-' . $position) . ' fa fa-' . $icon . '"></i>'; } else { if (is_a($icon, 'Page')) { $icon = blueprint::find($icon)->icon(); i($icon, 'left'); } else { if (is_a($icon, 'File')) { switch ($icon->type()) { case 'image': i('file-image-o', 'left'); break; case 'document': switch ($icon->extension()) { case 'pdf': i('file-pdf-o', 'left'); break; case 'doc': case 'docx': i('file-word-o', 'left'); break; case 'xls': i('file-excel-o', 'left'); break; default: i('file-text-o', 'left'); break; } break; case 'code': i('file-code-o', 'left'); break; case 'audio': i('file-audio-o', 'left'); break; case 'video': i('file-video-o', 'left'); break; default: i('file-archive-o', 'left'); break; } } } } }
public function index() { $site = site(); $widgets = array(); $wroot = kirby()->roots()->widgets(); $wdirs = dir::read($wroot); // fetch all top-level pages in the right order $blueprint = blueprint::find($site); $pages = api::subpages($site->children(), $blueprint); 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, 'pages' => $pages, 'addbutton' => !api::maxPages($site, $blueprint->pages()->max()), 'widgets' => $widgets, 'user' => site()->user(), 'license' => panel()->license())); }
public function update($id = '') { $page = $this->page($id); if (!$page) { return response::error(l('pages.error.missing')); } $blueprint = blueprint::find($page); $fields = $blueprint->fields($page); $oldTitle = (string) $page->title(); // trigger the validation $form = new Form($fields->toArray()); $form->validate(); // fetch the data for the form $data = pagedata::createByInput($page, $form->serialize()); // stop at invalid fields if (!$form->isValid()) { return response::error(l('pages.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name'))); } try { PageStore::discard($page); $page->update($data); // make sure that the sorting number is correct if ($page->isVisible()) { $num = api::createPageNum($page); if ($num !== $page->num()) { if ($num > 0) { $page->sort($num); } } } // get the blueprint of the parent page to find the // correct sorting mode for this page $parentBlueprint = blueprint::find($page->parent()); // auto-update the uid if the sorting mode is set to zero if ($parentBlueprint->pages()->num()->mode() == 'zero') { $uid = str::slug($page->title()); $page->move($uid); } history::visit($page->id()); kirby()->trigger('panel.page.update', $page); return response::success('success', array('file' => $page->content()->root(), 'data' => $data, 'uid' => $page->uid(), 'uri' => $page->id())); } catch (Exception $e) { return response::error($e->getMessage()); } }
public static function createPageNum($page, $blueprint = null) { if (is_null($blueprint)) { $parent = $page->parent() ? $page->parent() : site(); $blueprint = blueprint::find($parent); } $num = $blueprint->pages()->num(); switch ($num->mode()) { case 'zero': return 0; break; case 'date': return $page->date($num->format(), $num->field()); break; default: return false; } }
public function index($id = null) { $page = $this->page($id); $blueprint = blueprint::find($page); $visible = api::subpages($page->children()->visible(), $blueprint); $invisible = api::subpages($page->children()->invisible(), $blueprint); $baseUrl = rtrim(purl('subpages/index/' . $page->id()), '/'); // don't create the view if the page is not allowed to have subpages if ($blueprint->pages()->max() === 0) { goToErrorView(); } if ($limit = $blueprint->pages()->limit()) { $visible = $visible->paginate($limit, array('page' => get('visible'))); $invisible = $invisible->paginate($limit, array('page' => get('invisible'))); $visiblePagination = new Snippet('subpages/pagination', array('pagination' => $visible->pagination(), 'nextUrl' => $baseUrl . '/visible:' . $visible->pagination()->nextPage() . '/invisible:' . $invisible->pagination()->page(), 'prevUrl' => $baseUrl . '/visible:' . $visible->pagination()->prevPage() . '/invisible:' . $invisible->pagination()->page())); $invisiblePagination = new Snippet('subpages/pagination', array('pagination' => $invisible->pagination(), 'nextUrl' => $baseUrl . '/visible:' . $visible->pagination()->page() . '/invisible:' . $invisible->pagination()->nextPage(), 'prevUrl' => $baseUrl . '/visible:' . $visible->pagination()->page() . '/invisible:' . $invisible->pagination()->prevPage())); } return view('subpages/index', array('page' => $page, 'topbar' => new Snippet('pages/topbar', array('menu' => new Snippet('menu'), 'breadcrumb' => new Snippet('pages/breadcrumb', array('page' => $page, 'items' => array(array('url' => purl('subpages/index/' . $id), 'title' => l('subpages'))))), 'search' => purl($page, 'search'))), 'baseurl' => $baseUrl, 'addbutton' => !api::maxPages($page, $blueprint->pages()->max()) and $page->hasChildren(), 'sortable' => $blueprint->pages()->sortable(), 'visible' => $visible, 'flip' => $blueprint->pages()->sort() == 'flip', 'visiblePagination' => $visiblePagination, 'invisible' => $invisible, 'invisiblePagination' => $invisiblePagination)); }
public function structure($id, $field) { $page = empty($id) ? site() : page($id); if (!$page) { throw new Exception('The page could not be found'); } $blueprint = blueprint::find($page); $field = $blueprint->fields()->get($field); $fields = new Blueprint\Fields($field->fields(), $page); $fields = $fields->toArray(); foreach ($fields as $key => $field) { if ($field['type'] == 'textarea') { $fields[$key]['buttons'] = false; } } $form = new Form($fields); $form->save = get('_id') ? l('fields.structure.save') : l('fields.structure.add'); return view('editor/structure', array('page' => $page, 'form' => $form)); }
function builderForm($id, $fieldName, $fieldsetName, $context) { $kirby = kirby(); $kirby->extensions(); $kirby->plugins(); $root = $kirby->roots->index . DS . 'panel'; $panel = new Panel($kirby, $root); $panel->i18n(); $roots = new Panel\Roots($panel, $root); $site = $kirby->site(); $page = empty($id) ? site() : page($id); if (!$page) { throw new Exception('The page could not be found'); } $blueprint = blueprint::find($page); $field = null; $fields = $context == 'file' ? $blueprint->files()->fields() : $blueprint->fields(); // make sure to get fields by case insensitive field names foreach ($fields as $f) { if (strtolower($f->name) == strtolower($fieldName)) { $field = $f; } } if (!$field) { throw new Exception('The field could not be found'); } $fieldsets = $field->fieldsets(); $fields = new Blueprint\Fields($fieldsets[$fieldsetName]['fields'], $page); $fields = $fields->toArray(); foreach ($fields as $key => $field) { if ($field['type'] == 'textarea') { $fields[$key]['buttons'] = false; } } $form = new Form($fields, null, $fieldName); $form->save = get('_id') ? l('fields.structure.save') : l('fields.structure.add'); echo '<div class="modal-content modal-content-large">'; echo $form; echo '</div>'; }
public function num($uid, $to = null) { $page = $this->find($uid); $blueprint = blueprint::find($this->parent); $params = $blueprint->pages()->num(); if ($to == 'last') { $to = $this->visible()->count() + 1; } switch ($params->mode()) { case 'zero': return 0; break; case 'date': if ($to = $page->date($params->format(), $params->field())) { return $to; } else { return date($params->format()); } break; default: if (v::num($to)) { if ($to <= 0) { $to = 1; } else { if ($page->isInvisible()) { $limit = $this->visible()->count() + 1; } else { $limit = $this->visible()->count(); } if ($limit < $to) { $to = $limit; } } return intval($to); } else { return false; } break; } }
function n($page) { if ($page->isInvisible()) { return '—'; } else { if ($page->parent() and $blueprint = blueprint::find($page->parent())) { switch ($blueprint->pages()->num()->mode()) { case 'zero': return str::substr($page->title(), 0, 1); break; case 'date': return date('Y/m/d', strtotime($page->num())); break; default: return intval($page->num()); break; } } else { return intval($page->num()); } } }
public function __construct($params = array()) { if ($params === true) { $this->template = blueprint::all(); } else { if ($params === false) { $this->limit = 0; $this->max = 0; $this->sortable = false; $this->hide = true; } else { if (is_array($params)) { $template = a::get($params, 'template'); if ($template == false) { $this->template = blueprint::all(); } else { if (is_array($template)) { $this->template = $template; } else { $this->template = array($template); } } $this->sort = a::get($params, 'sort', $this->sort); $this->sortable = a::get($params, 'sortable', $this->sortable); $this->limit = a::get($params, 'limit', $this->limit); $this->num = a::get($params, 'num', $this->num); $this->max = a::get($params, 'max', $this->max); $this->hide = a::get($params, 'hide', $this->hide); $this->build = a::get($params, 'build', $this->build); } else { if (is_string($params)) { $this->template = array($params); } } } } }
public function delete($id) { $page = $this->page($id); $error = null; $blueprint = blueprint::find($page); $back = array('subpages' => purl('subpages/index/' . $page->parent()->id()), 'page' => purl($page, 'show')); if ($page->isHomePage()) { $errortype = 'home'; } else { if ($page->isErrorPage()) { $errortype = 'error'; } else { if ($page->hasChildren()) { $errortype = 'children'; } else { if (!$blueprint->deletable()) { $errortype = 'blocked'; } else { $errortype = null; } } } } if ($errortype) { $error = array('headline' => l::get('pages.delete.error.' . $errortype . '.headline'), 'text' => l::get('pages.delete.error.' . $errortype . '.text')); } else { $error = null; } return view('pages/delete', array('page' => $this->page($id), 'back' => a::get($back, get('to')), 'error' => $error)); }
<?php $site = site(); $blueprint = blueprint::find($site); $pages = api::subpages($site->children(), $blueprint); $addbutton = !api::maxPages($site, $blueprint->pages()->max()); $options = array(array('text' => l('dashboard.index.pages.edit'), 'icon' => 'pencil', 'link' => '#/subpages/index/')); if ($addbutton) { $options[] = array('text' => l('dashboard.index.pages.add'), 'icon' => 'plus-circle', 'link' => '#/pages/add/', 'key' => '+'); } return array('title' => array('text' => l('dashboard.index.pages.title'), 'link' => '#/subpages/index/', 'compressed' => true), 'options' => $options, 'html' => function () use($pages) { return tpl::load(__DIR__ . DS . 'pages.html.php', array('pages' => $pages)); });