Example #1
0
 public function show($id)
 {
     $page = $this->page($id);
     $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();
     // 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, 'page' => $page, 'notitle' => !$form->fields()->get('title')));
 }
Example #2
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());
     }
 }
Example #3
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 {
         $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);
                 }
             }
         }
         history::visit($page->id());
         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());
     }
 }
Example #4
0
 /**
  * Close the form and destroy all
  * session resources by default.
  *
  * @param bool $destroyFieldsAndError
  * @return string
  */
 public static function close($destroyFieldsAndError = true)
 {
     self::$fields = [];
     if ($destroyFieldsAndError) {
         unset($_SESSION['__ERRORS__']);
         unset($_SESSION['__FIELDS__']);
     }
     return "</form>\n";
 }
Example #5
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());
     }
 }