public function url($id)
 {
     $page = $this->page($id);
     if (!$page) {
         return response::error(l('pages.error.missing'));
     }
     // avoid url changes for the home and error pages
     if ($page->isErrorPage() or $page->isHomePage()) {
         return response::error('This page type\'s url cannot be changed');
     }
     $changes = PageStore::fetch($page);
     PageStore::discard($page);
     try {
         if (site()->multilang() and site()->language()->code() != site()->defaultLanguage()->code()) {
             $page->update(array('URL-Key' => get('uid')));
         } else {
             $page->move(get('uid'));
         }
         PageStore::update($page, $changes);
         // hit the hook
         kirby()->trigger('panel.page.move', $page);
         return response::success('success', array('uid' => $page->uid(), 'uri' => $page->id()));
     } catch (Exception $e) {
         return response::error($e->getMessage());
     }
 }
Beispiel #2
0
 public function show($id)
 {
     try {
         $page = $this->page($id);
     } catch (Exception $e) {
         $page = $this->page(dirname($id));
         // dirty work around to move to the parent page
         die('<script>window.location.href = "#/pages/show/' . $page->id() . '"</script>');
     }
     $blueprint = blueprint::find($page);
     $fields = $blueprint->fields($page);
     $content = $page->content()->toArray();
     $files = null;
     $subpages = null;
     $preview = null;
     // create the preview link
     if ($previewSetting = $blueprint->preview()) {
         switch ($previewSetting) {
             case 'parent':
                 $preview = $page->parent() ? $page->parent()->url() : $page->url();
                 break;
             case 'first-child':
                 $preview = $page->children()->first() ? $page->children()->first()->url() : false;
                 break;
             case 'last-child':
                 $preview = $page->children()->last() ? $page->children()->last()->url() : false;
                 break;
             default:
                 $preview = $page->url();
                 break;
         }
     }
     // make sure the title is always there
     $content['title'] = $page->title();
     // merge with the kept snapshot
     $changes = PageStore::fetch($page);
     $content = array_merge($content, $changes);
     // create the form
     $form = new Form($fields->toArray(), $content);
     // check for untranslatable fields
     if (site()->language() != site()->defaultLanguage()) {
         foreach ($form->fields() as $field) {
             if ($field->translate() == false) {
                 $field->readonly = true;
                 $field->disabled = true;
             }
         }
     }
     // create the subpages if they exist
     if ($blueprint->pages()->max() !== 0 and $blueprint->pages()->hide() == false) {
         // fetch all subpages in the right order
         $children = api::subpages($page->children(), $blueprint);
         // add pagination to the subpages
         if ($limit = $blueprint->pages()->limit()) {
             $children = $children->paginate($limit, array('page' => get('page')));
         }
         // create the snippet and fill it with all data
         $subpages = new Snippet('pages/sidebar/subpages', array('title' => l('pages.show.subpages.title'), 'page' => $page, 'subpages' => $children, 'addbutton' => !api::maxPages($page, $blueprint->pages()->max()), 'pagination' => $children->pagination()));
     }
     // create the files
     if ($blueprint->files()->max() !== 0 and $blueprint->files()->hide() == false) {
         $files = new Snippet('pages/sidebar/files', array('page' => $page, 'files' => api::files($page, $blueprint)));
     }
     // create the monster sidebar
     $sidebar = new Snippet('pages/sidebar', array('page' => $page, 'preview' => $preview, 'deletable' => !$page->hasChildren() and $page->isDeletable() and $blueprint->deletable(), 'subpages' => $subpages, 'files' => $files));
     return view('pages/show', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('pages/breadcrumb', array('page' => $page)), 'search' => purl($page, 'search'))), 'sidebar' => $sidebar, 'form' => $form, 'changes' => $changes, 'page' => $page, 'notitle' => !$form->fields()->get('title')));
 }