Exemplo n.º 1
0
 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());
     }
 }
Exemplo n.º 2
0
 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)));
 }
Exemplo n.º 3
0
 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));
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
 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');
 }
Exemplo n.º 6
0
 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));
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 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()));
 }
Exemplo n.º 10
0
 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));
 }
Exemplo n.º 11
0
 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));
 }
Exemplo n.º 12
0
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;
                }
            }
        }
    }
}
Exemplo n.º 13
0
 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()));
 }
Exemplo n.º 14
0
 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());
     }
 }
Exemplo n.º 15
0
 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;
     }
 }
Exemplo n.º 16
0
 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));
 }
Exemplo n.º 17
0
 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));
 }
Exemplo n.º 18
0
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>';
}
Exemplo n.º 19
0
 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;
     }
 }
Exemplo n.º 20
0
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());
        }
    }
}
Exemplo n.º 21
0
 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));
 }
Exemplo n.º 22
0
<?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));
});