createSameCabinRedirect() public method

Create a redirect
public createSameCabinRedirect ( string $oldURL, string $newURL, string $cabin ) : boolean
$oldURL string
$newURL string
$cabin string
return boolean
Esempio n. 1
0
 /**
  * Confirm deletion
  *
  * @param int $pageId
  * @param array $post
  * @param string $cabin
  * @param string $dir
  * @return mixed
  */
 protected function processDeletePage(int $pageId, array $post = [], string $cabin = '', string $dir = '') : bool
 {
     $this->log('Attempting to delete a page', LogLevel::ALERT, ['pageId' => $pageId, 'cabin' => $cabin, 'dir' => $dir]);
     list($oldCabin, $oldPath, $oldURL) = $this->pg->getPathByPageId((int) $pageId, $cabin);
     if ($this->pg->deletePage($pageId)) {
         if (!empty($post['create_redirect']) && !empty($post['redirect_to'])) {
             $this->pg->createSameCabinRedirect($oldPath . '/' . $oldURL, $post['redirect_to'], $oldCabin);
         }
         \Airship\redirect($this->airship_cabin_prefix . '/pages/' . $cabin, ['dir' => $dir]);
     }
     return false;
 }
Esempio n. 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]);
 }