Create and manage custom web pages.
Inheritance: extends Airship\Cabin\Hull\Blueprint\CustomPages, use trait Airship\Engine\Bolt\Cache
Beispiel #1
0
 /**
  * Create a new page in the current directory
  *
  * @param string $cabin
  * @param string $path
  * @param array $post
  * @return mixed
  */
 protected function processNewPage(string $cabin, string $path, array $post = []) : bool
 {
     $expected = ['url', 'format', 'page_body', 'save_btn', 'metadata'];
     if (!\Airship\all_keys_exist($expected, $post)) {
         return false;
     }
     $url = $path . '/' . \str_replace('/', '_', $post['url']);
     if (!empty($post['ignore_collisions']) && $this->detectCollisions($url, $cabin)) {
         $this->storeLensVar('post_response', ['message' => \__('The given filename might conflict with another route in this Airship.'), 'status' => 'error']);
         return false;
     }
     $raw = $this->isSuperUser() ? !empty($post['raw']) : false;
     if ($this->can('publish')) {
         $publish = $post['save_btn'] === 'publish';
     } elseif ($this->can('create')) {
         $publish = false;
     } else {
         $this->storeLensVar('post_response', ['message' => \__('You do not have permission to create new pages.'), 'status' => 'error']);
         return false;
     }
     if ($this->pg->createPage($cabin, $path, $post, $publish, $raw)) {
         \Airship\redirect($this->airship_cabin_prefix . '/pages/' . $cabin, ['dir' => $path]);
     }
     return true;
 }
Beispiel #2
0
 /**
  * Create a new redirect
  *
  * @param string $cabin
  * @route redirects/{string}/new
  */
 public function newRedirect(string $cabin)
 {
     $cabins = $this->getCabinNamespaces();
     if (!\in_array($cabin, $cabins) && !$this->can('create')) {
         \Airship\redirect($this->airship_cabin_prefix . '/redirects');
     }
     $this->setTemplateExtraData($cabin);
     $post = $this->post(new RedirectFilter());
     if ($post) {
         if (\Airship\all_keys_exist(['old_url', 'new_url'], $post)) {
             if (\preg_match('#^https?://#', $post['new_url'])) {
                 // Less restrictions:
                 $result = $this->pg->createDifferentCabinRedirect(\trim($post['old_url'], '/'), \trim($post['new_url'], '/'), $cabin);
             } else {
                 $result = $this->pg->createSameCabinRedirect(\trim($post['old_url'], '/'), \trim($post['new_url'], '/'), $cabin);
             }
             if ($result) {
                 \Airship\redirect($this->airship_cabin_prefix . '/redirects/' . $cabin);
             }
         }
     }
     $this->lens('redirect/new', ['cabin' => $cabin]);
 }