Beispiel #1
0
 public function __construct($url)
 {
     $this->url = $url;
     $this->groupPage = $this->getBlogGroupPage();
     $this->group = PageGroup::where('id', '=', $this->groupPage->group_container)->first();
     $this->setUpCommentsBlocks();
 }
 public function getAdd($parentPageId = 0, $groupId = 0)
 {
     $publishingOn = config('coaster::admin.publishing') > 0;
     $cabPublish = $publishingOn && Auth::action('pages.version-publish', ['page_id' => $parentPageId]) || !$publishingOn && Auth::action('pages.edit', ['page_id' => $parentPageId]);
     // set page data
     $page = new Page();
     if ($parentPageId && ($parent = Page::find($parentPageId))) {
         $page->parent = $parent->id;
         $page->template = $parent->child_template;
     } else {
         $page->parent = 0;
     }
     if ($groupId && ($group = PageGroup::find($groupId))) {
         $page->groups->add($group);
         $page->template = $group->default_template;
         $page->parent = $parentPageId ? $page->parent : -1;
     }
     $page->group_container = 0;
     $page->link = 0;
     $page->live = $cabPublish ? 1 : 0;
     $page->sitemap = 1;
     // get item name, or default to page
     $item_name = $page->groupItemsNames() ?: 'Page';
     // get page info tab contents
     $tab_headers = [];
     $tab_contents = [];
     list($tab_headers[0], $tab_contents[0]) = $page->tabInfo();
     $tab_data = ['headers' => View::make('coaster::partials.tabs.header', ['tabs' => $tab_headers])->render(), 'contents' => View::make('coaster::partials.tabs.content', ['tabs' => $tab_contents, 'item' => $item_name, 'new_page' => true, 'publishing' => $publishingOn, 'can_publish' => $cabPublish, 'page' => $page])->render()];
     $this->layoutData['content'] = View::make('coaster::pages.pages.add', ['page' => $page, 'item_name' => $item_name, 'tab' => $tab_data]);
 }
 /**
  * Handle the event.
  *
  * @param  AuthRoute $event
  * @return void
  */
 public function handle(AuthRoute $event)
 {
     // specify page_id option for use in auth check
     switch ($event->controller) {
         case 'forms':
         case 'gallery':
         case 'pages':
             $event->returnOptions['page_id'] = isset($event->parameters['pageId']) ? $event->parameters['pageId'] : 0;
             // use parent page id when posting add page form
             if ($event->action == 'add') {
                 $event->returnOptions['page_id'] = Request::input('page_info.parent.select') ?: $event->returnOptions['page_id'];
                 if (isset($event->parameters['groupId'])) {
                     $pageGroup = PageGroup::preload($event->parameters['groupId']);
                     if (!$pageGroup->exists || !$pageGroup->canAddItems()) {
                         $event->override = false;
                     }
                 }
             }
             // let page sort function deal with permissions
             if ($event->action == 'sort') {
                 $event->override = true;
             }
             break;
         case 'groups':
             $page_group = PageGroup::preload(isset($event->parameters['groupId']) ? $event->parameters['groupId'] : 0);
             $event->override = $page_group->exists ? $page_group->canAddItems() : $event->override;
     }
 }
 public function postEdit($groupId)
 {
     $group = PageGroup::preload($groupId);
     if ($group->exists) {
         $groupInput = Request::input('group', []);
         foreach ($groupInput as $groupAttribute => $attributeValue) {
             if ($group->{$groupAttribute} !== null && $groupAttribute != 'id') {
                 if (is_array($attributeValue)) {
                     $attributeValue = isset($attributeValue['select']) ? $attributeValue['select'] : '';
                 }
                 $group->{$groupAttribute} = $attributeValue;
             }
         }
         $group->save();
         $currentAttributes = [];
         $newAttributes = [];
         foreach ($group->groupAttributes as $currentAttribute) {
             $currentAttributes[$currentAttribute->id] = $currentAttribute;
         }
         $groupPageAttributes = Request::input('groupAttribute', []);
         foreach ($groupPageAttributes as $attributeId => $groupPageAttribute) {
             if ($newAttribute = strpos($attributeId, 'new') === 0 ? new PageGroupAttribute() : (!empty($currentAttributes[$attributeId]) ? $currentAttributes[$attributeId] : null)) {
                 $newAttribute->group_id = $group->id;
                 $newAttribute->item_block_id = $groupPageAttribute['item_block_id'];
                 $newAttribute->item_block_order_priority = $groupPageAttribute['item_block_order_priority'];
                 $newAttribute->item_block_order_dir = $groupPageAttribute['item_block_order_dir'];
                 $newAttribute->save();
                 $newAttributes[$newAttribute->id] = $newAttribute;
             }
         }
         $deleteAttributeIds = array_diff(array_keys($currentAttributes), array_keys($newAttributes));
         PageGroupAttribute::whereIn('id', $deleteAttributeIds)->delete();
     }
     return redirect()->route('coaster.admin.groups.edit', ['groupId' => $groupId]);
 }
Beispiel #5
0
 /**
  * @param Page[] $pages
  * @param Path|null $parentPathData
  */
 protected static function _loadSubPaths($pages, $parentPathData = null)
 {
     foreach ($pages as $pageId => $pageData) {
         $pagePathData = self::_getById($pageId);
         $pagePathData->fullName = ($parentPathData ? $parentPathData->fullName . $pagePathData->separator : '') . $pagePathData->name;
         if ($pageData->link > 0) {
             $pagePathData->fullUrl = $pagePathData->url;
         } else {
             $pagePathData->fullUrl = ($parentPathData ? $parentPathData->fullUrl : '') . '/' . $pagePathData->url;
         }
         if ($childPages = Page::getChildPages($pageId)) {
             self::_loadSubPaths($childPages, $pagePathData);
         }
         if ($pageData->group_container > 0) {
             $group = PageGroup::preload($pageData->group_container);
             if ($group->exists) {
                 foreach ($group->itemPageFiltered($pageId) as $groupPage) {
                     $groupPagePathData = self::_getById($groupPage->id);
                     $groupPagePathData->groupContainers[$pageId] = ['name' => $pagePathData->fullName, 'url' => $pagePathData->fullUrl, 'priority' => $pageData->group_container_url_priority ?: $group->url_priority, 'canonical' => $groupPage->canonical_parent == $pageData->id];
                 }
             }
         }
     }
 }
 public function postPages($role_id)
 {
     if (config('coaster::admin.advanced_permissions')) {
         $page_actions = AdminAction::where('controller_id', '=', 2)->where('inherit', '=', 0)->where('edit_based', '=', 0)->get();
         $actionIds = [];
         foreach ($page_actions as $action) {
             $actionIds[$action->action] = $action->id;
         }
         if (!config('coaster::admin.publishing')) {
             unset($actionIds['version-publish']);
         }
         $pages_permissions = Request::input('page');
         $this->_role_permissions = UserRole::find($role_id);
         // defaults
         $defaults = [];
         foreach ($actionIds as $action => $id) {
             $defaults[$id] = false;
         }
         foreach ($this->_role_permissions->actions as $action) {
             if (array_key_exists($action->id, $defaults)) {
                 $defaults[$action->id] = 1;
             }
         }
         // existing
         $existing = [];
         foreach ($this->_role_permissions->page_actions as $page_permission) {
             if (!isset($existing[$page_permission->pivot->page_id])) {
                 $existing[$page_permission->pivot->page_id] = [];
             }
             $existing[$page_permission->pivot->page_id][$page_permission->pivot->action_id] = $page_permission->pivot->access;
         }
         // save updates
         $pages = Page::where('parent', '>=', '0')->get();
         foreach ($pages as $page) {
             foreach ($actionIds as $action => $action_id) {
                 // get value entered
                 if (isset($pages_permissions[$page->id][$action])) {
                     $value = 'allow';
                 } else {
                     $value = 'deny';
                 }
                 // check if update is required
                 if (isset($existing[$page->id][$action_id])) {
                     if ($defaults[$action_id] && $value == 'allow' || !$defaults[$action_id] && $value == 'deny') {
                         // remove existing
                         $this->_role_permissions->page_actions()->newPivotStatementForId($page->id)->whereActionId($action_id)->delete();
                         if ($page->group_container > 0) {
                             $group = PageGroup::find($page->group_container);
                             foreach ($group->pages as $group_page) {
                                 $this->_role_permissions->page_actions()->newPivotStatementForId($group_page->id)->whereActionId($action_id)->delete();
                             }
                         }
                     } elseif ($existing[$page->id][$action_id] != $value) {
                         // update existing
                         $this->_role_permissions->page_actions()->newPivotStatementForId($page->id)->whereActionId($action_id)->update(['access' => $value]);
                         if ($page->group_container > 0) {
                             $group = PageGroup::find($page->group_container);
                             foreach ($group->pages as $group_page) {
                                 $this->_role_permissions->page_actions()->newPivotStatementForId($group_page->id)->whereActionId($action_id)->update(['access' => $value]);
                             }
                         }
                     }
                 } elseif (!$defaults[$action_id] && $value == 'allow' || $defaults[$action_id] && $value == 'deny') {
                     // add new page action
                     $this->_role_permissions->page_actions()->attach($page->id, ['action_id' => $action_id, 'access' => $value]);
                     if ($page->group_container > 0) {
                         $group = PageGroup::find($page->group_container);
                         foreach ($group->pages as $group_page) {
                             $this->_role_permissions->page_actions()->attach($group_page->id, ['action_id' => $action_id, 'access' => $value]);
                         }
                     }
                 }
             }
         }
         $this->addAlert('success', 'Page Permissions Updated');
     }
     $this->getPages($role_id);
 }
Beispiel #7
0
 public static function _pageImportData($theme)
 {
     $importPath = $themePath = base_path() . '/resources/views/themes/' . $theme->theme . '/import/';
     if (is_dir($importPath)) {
         // wipe data
         DB::table((new Page())->getTable())->truncate();
         DB::table((new PageLang())->getTable())->truncate();
         DB::table((new PageVersion())->getTable())->truncate();
         DB::table((new PagePublishRequests())->getTable())->truncate();
         DB::table((new PageGroup())->getTable())->truncate();
         DB::table((new PageGroupAttribute())->getTable())->truncate();
         DB::table((new PageGroupPage())->getTable())->truncate();
         DB::table((new Menu())->getTable())->truncate();
         DB::table((new MenuItem())->getTable())->truncate();
         DB::table((new PageBlockDefault())->getTable())->truncate();
         DB::table((new PageBlock())->getTable())->truncate();
         DB::table((new PageBlockRepeaterData())->getTable())->truncate();
         DB::table((new PageBlockRepeaterRows())->getTable())->truncate();
         $templateIds = [];
         $templates = Template::where('theme_id', '=', $theme->id)->get();
         foreach ($templates as $template) {
             $templateIds[$template->template] = $template->id;
         }
         $blockIds = [];
         $blocks = Block::all();
         foreach ($blocks as $block) {
             $blockIds[$block->name] = $block->id;
         }
         $pagesCsv = $importPath . 'pages.csv';
         $groupsCsv = $importPath . 'pages/groups.csv';
         $groupAttributesCsv = $importPath . 'pages/group_attributes.csv';
         $menusCsv = $importPath . 'pages/menus.csv';
         $menuItemsCsv = $importPath . 'pages/menu_items.csv';
         $pageBlocksCsv = $importPath . 'pages/page_blocks.csv';
         $repeaterBlocksCsv = $importPath . 'pages/repeater_blocks.csv';
         // checks
         $error = 'pages data not imported, invalid columns in: ';
         if (!($pagesFileHandle = Csv::check($pagesCsv, 14))) {
             if (file_exists($pagesCsv)) {
                 throw new \Exception($error . $pagesCsv);
             }
         }
         if (!($groupsHandle = Csv::check($groupsCsv, 5))) {
             if (file_exists($groupsCsv)) {
                 throw new \Exception($error . $groupsCsv);
             }
         }
         if (!($groupAttributesHandle = Csv::check($groupAttributesCsv, 6))) {
             if (file_exists($groupAttributesCsv)) {
                 throw new \Exception($error . $groupAttributesCsv);
             }
         }
         if (!($menusHandle = Csv::check($menusCsv, 3))) {
             if (file_exists($menusCsv)) {
                 throw new \Exception($error . $menusCsv);
             }
         }
         if (!($menuItemsCsvHandle = Csv::check($menuItemsCsv, 5))) {
             if (file_exists($menuItemsCsv)) {
                 throw new \Exception($error . $menuItemsCsv);
             }
         }
         if (!($pageBlocksCsvHandle = Csv::check($pageBlocksCsv, 3))) {
             if (file_exists($pageBlocksCsv)) {
                 throw new \Exception($error . $pageBlocksCsv);
             }
         }
         if (!($repeaterBlocksCsvHandle = Csv::check($repeaterBlocksCsv, 4))) {
             if (file_exists($repeaterBlocksCsv)) {
                 throw new \Exception($error . $repeaterBlocksCsv);
             }
         }
         // add pages
         if ($pagesFileHandle) {
             $row = 0;
             while (($data = fgetcsv($pagesFileHandle)) !== false) {
                 if ($row++ == 0 && $data[0] == 'Page Id') {
                     continue;
                 }
                 list($pageId, $pageName, $pageUrl, $templateName, $parentId, $defaultChildTemplateName, $order, $link, $live, $sitemap, $groupContainer, $groupContainerUrlPriority, $canonicalParentPageId, $groupIds) = $data;
                 $newPage = new Page();
                 $newPage->id = $pageId;
                 $newPage->template = !empty($templateIds[$templateName]) ? $templateIds[$templateName] : 0;
                 $newPage->parent = $parentId ?: 0;
                 $newPage->child_template = !empty($templateIds[$defaultChildTemplateName]) ? $templateIds[$defaultChildTemplateName] : 0;
                 $newPage->order = $order;
                 $newPage->link = $link;
                 $newPage->live = $live;
                 $newPage->sitemap = $sitemap;
                 $newPage->group_container = $groupContainer ?: 0;
                 $newPage->group_container_url_priority = $groupContainerUrlPriority ?: 0;
                 $newPage->canonical_parent = $canonicalParentPageId ?: 0;
                 $newPage->save();
                 $newPageLang = new PageLang();
                 $newPageLang->page_id = $pageId;
                 $newPageLang->language_id = Language::current();
                 $newPageLang->name = $pageName;
                 $newPageLang->url = $pageUrl;
                 $newPageLang->live_version = 1;
                 $newPageLang->save();
                 PageVersion::add_new($pageId);
                 $groupIds = trim($groupIds);
                 $groupIds = $groupIds ? explode(',', $groupIds) : [];
                 foreach ($groupIds as $groupId) {
                     $newPageGroupPage = new PageGroupPage();
                     $newPageGroupPage->page_id = $pageId;
                     $newPageGroupPage->group_id = $groupId;
                     $newPageGroupPage->save();
                 }
             }
         }
         // add page groups
         if ($groupsHandle) {
             $row = 0;
             while (($data = fgetcsv($groupsHandle)) !== false) {
                 if ($row++ == 0 && $data[0] == 'Group Id') {
                     continue;
                 }
                 list($groupId, $groupName, $itemName, $defaultContainerPageId, $defaultTemplate) = $data;
                 $newGroup = new PageGroup();
                 $newGroup->id = $groupId;
                 $newGroup->name = $groupName;
                 $newGroup->item_name = $itemName;
                 $newGroup->url_priority = $defaultContainerPageId;
                 $newGroup->default_template = !empty($templateIds[$defaultTemplate]) ? $templateIds[$defaultTemplate] : 0;
                 $newGroup->save();
             }
         }
         if ($groupAttributesHandle) {
             $row = 0;
             while (($data = fgetcsv($groupAttributesHandle)) !== false) {
                 if ($row++ == 0 && $data[0] == 'Attribute Id') {
                     continue;
                 }
                 list($attributeId, $groupId, $blockName, $orderPriority, $orderDir, $filerByBlockName) = $data;
                 $newGroupAttribute = new PageGroupAttribute();
                 $newGroupAttribute->id = $attributeId;
                 $newGroupAttribute->group_id = $groupId;
                 $newGroupAttribute->item_block_id = !empty($blockIds[$blockName]) ? $blockIds[$blockName] : 0;
                 $newGroupAttribute->item_block_order_priority = $orderPriority;
                 $newGroupAttribute->item_block_order_dir = $orderDir == 'desc' ? $orderDir : 'asc';
                 $newGroupAttribute->filter_by_block_id = !empty($blockIds[$filerByBlockName]) ? $blockIds[$filerByBlockName] : 0;
                 $newGroupAttribute->save();
             }
         }
         // add menus
         if ($menusHandle) {
             $menuIds = [];
             $row = 0;
             while (($data = fgetcsv($menusHandle)) !== false) {
                 if ($row++ == 0 && $data[0] == 'Menu Identifier') {
                     continue;
                 }
                 list($name, $label, $maxSublevel) = $data;
                 $newMenu = new Menu();
                 $newMenu->label = $label;
                 $newMenu->name = $name;
                 $newMenu->max_sublevel = $maxSublevel;
                 $newMenu->save();
                 $menuIds[$name] = $newMenu->id;
             }
         }
         if ($menuItemsCsvHandle) {
             $row = 0;
             while (($data = fgetcsv($menuItemsCsvHandle)) !== false) {
                 if ($row++ == 0 && $data[0] == 'Menu Identifier') {
                     continue;
                 }
                 list($menuIdentifier, $pageId, $order, $subLevels, $customName) = $data;
                 if (!empty($menuIds[$menuIdentifier])) {
                     $newMenuItem = new MenuItem();
                     $newMenuItem->menu_id = $menuIds[$menuIdentifier];
                     $newMenuItem->page_id = $pageId;
                     $newMenuItem->order = $order;
                     $newMenuItem->sub_levels = $subLevels;
                     $newMenuItem->custom_name = $customName;
                     $newMenuItem->save();
                 }
             }
         }
         // add page content
         if ($pageBlocksCsvHandle) {
             $row = 0;
             while (($data = fgetcsv($pageBlocksCsvHandle)) !== false) {
                 if ($row++ == 0 && $data[0] == 'Page Id') {
                     continue;
                 }
                 list($pageId, $blockName, $content) = $data;
                 if (!empty($blockIds[$blockName])) {
                     if ($pageId) {
                         $newPageBlock = new PageBlock();
                         $newPageBlock->page_id = $pageId;
                     } else {
                         $newPageBlock = new PageBlockDefault();
                     }
                     $newPageBlock->block_id = $blockIds[$blockName];
                     $newPageBlock->version = 1;
                     $newPageBlock->content = $content;
                     $newPageBlock->save();
                 }
             }
         }
         if ($repeaterBlocksCsvHandle) {
             $row = 0;
             $existingRepeaterRowKeys = [];
             while (($data = fgetcsv($repeaterBlocksCsvHandle)) !== false) {
                 if ($row++ == 0 && $data[0] == 'Repeater Id') {
                     continue;
                 }
                 list($repeaterId, $repeaterRowId, $blockName, $content) = $data;
                 if (!empty($blockIds[$blockName])) {
                     if ($decodedContent = json_decode($content)) {
                         if (!is_string($decodedContent)) {
                             $content = serialize($decodedContent);
                         }
                     }
                     if (!isset($existingRepeaterRowKeys[$repeaterId . '-' . $repeaterRowId])) {
                         $newRepeaterRow = new PageBlockRepeaterRows();
                         $newRepeaterRow->repeater_id = $repeaterId;
                         $newRepeaterRow->row_id = $repeaterRowId;
                         $newRepeaterRow->save();
                         $existingRepeaterRowKeys[$repeaterId . '-' . $repeaterRowId] = $newRepeaterRow->id;
                         $newRepeaterData = new PageBlockRepeaterData();
                         $newRepeaterData->row_key = $existingRepeaterRowKeys[$repeaterId . '-' . $repeaterRowId];
                         $newRepeaterData->block_id = 0;
                         $newRepeaterData->version = 1;
                         $newRepeaterData->content = $repeaterRowId;
                         $newRepeaterData->save();
                     }
                     $newRepeaterData = new PageBlockRepeaterData();
                     $newRepeaterData->row_key = $existingRepeaterRowKeys[$repeaterId . '-' . $repeaterRowId];
                     $newRepeaterData->block_id = $blockIds[$blockName];
                     $newRepeaterData->version = 1;
                     $newRepeaterData->content = $content;
                     $newRepeaterData->save();
                 }
             }
         }
         PageSearchData::updateAllSearchData();
     }
 }
 /**
  * @param string $path
  * @param Page $parentPage
  * @return Page|null
  */
 protected function _loadSubPage($path, Page $parentPage)
 {
     $paths = [$path];
     $page = self::_pageQuery($paths, $parentPage->id);
     if (!$page && $parentPage->group_container > 0) {
         $page = self::_pageQuery($paths, false, $parentPage->group_container);
         if ($page) {
             $group = PageGroup::preload($parentPage->group_container);
             $page = in_array($page->id, $group->itemPageIdsFiltered($parentPage->id)) ? $page : null;
         }
     }
     return $page;
 }
Beispiel #9
0
 /**
  * Saves page data
  * @param PageVersion $pageVersion
  * @param array $pagePost
  * @param array $pageLangPost
  * @param array $pageGroupsPost
  * @param array $pageInfoOther
  * @return bool
  */
 public function savePostData($pageVersion, $pagePost, $pageLangPost, $pageGroupsPost, $pageInfoOther = [])
 {
     /*
      * Post data fixes
      */
     foreach ($pagePost as $k => $pagePostField) {
         if (is_array($pagePostField) && array_key_exists('exists', $pagePostField)) {
             $pagePost[$k] = array_key_exists('select', $pagePostField) ? $pagePostField['select'] : 0;
         }
     }
     if (array_key_exists('live_start', $pagePost)) {
         $pagePost['live_start'] = DateTimeHelper::jQueryToMysql($pagePost['live_start']) ?: null;
     }
     if (array_key_exists('live_end', $pagePost)) {
         $pagePost['live_end'] = DateTimeHelper::jQueryToMysql($pagePost['live_end']) ?: null;
     }
     foreach ($pageInfoOther as $k => $pageInfoOtherField) {
         if (is_array($pageInfoOtherField) && array_key_exists('exists', $pageInfoOtherField) && array_key_exists('select', $pageInfoOtherField)) {
             $pageInfoOther[$k] = $pageInfoOtherField['select'];
         }
     }
     /*
      * Overwrite default/existing data with posted data
      */
     $pageDefaults = array_merge(['template' => 0, 'parent' => 0, 'child_template' => 0, 'order' => 0, 'group_container' => 0, 'group_container_url_priority' => 0, 'canonical_parent' => 0, 'link' => 0, 'live' => 0, 'sitemap' => 1, 'live_start' => null, 'live_end' => null], $this->getAttributes());
     foreach ($pageDefaults as $pageAttribute => $pageDefault) {
         $this->{$pageAttribute} = $pageDefault;
         switch ($pageAttribute) {
             case 'template':
                 $pageVersion->{$pageAttribute} = $pagePost[$pageAttribute];
                 break;
             default:
                 $this->{$pageAttribute} = array_key_exists($pageAttribute, $pagePost) ? $pagePost[$pageAttribute] : $this->{$pageAttribute};
         }
     }
     if (!$this->pageCurrentLang) {
         $this->setRelation('pageCurrentLang', ($d = $this->pageDefaultLang) ? $d->replicate() : new PageLang());
         unset($this->pageCurrentLang->language_id);
     }
     $pageLang = $this->pageLang();
     $pageLangDefaults = array_merge(['language_id' => Language::current(), 'url' => '', 'name' => '', 'live_version' => 1], $pageLang->getAttributes());
     foreach ($pageLangDefaults as $pageLangAttribute => $pageLangDefault) {
         $pageLang->{$pageLangAttribute} = array_key_exists($pageLangAttribute, $pageLangPost) ? $pageLangPost[$pageLangAttribute] : $pageLangDefault;
     }
     /*
      * Check page parent exists if set and page limit is not hit
      */
     $parent = static::find($this->parent);
     if ($this->parent > 0 && !$parent) {
         return false;
     }
     if (!$this->id && !$this->link && static::at_limit($this->parent == -1)) {
         return false;
     }
     /*
      * Check page name/url set and does not conflict
      */
     $pageLang->url = trim($pageLang->url);
     if (!$this->link) {
         $pageLang->url = strtolower(str_replace(['/', ' '], '-', $pageLang->url));
         if (preg_match('#^[-]+$#', $pageLang->url)) {
             $pageLang->url = '';
         }
         if ($pageLang->url == '' && !$this->parent) {
             $pageLang->url = '/';
         }
         $siblings = [];
         foreach ($pageGroupsPost as $pageGroupId => $checkedVal) {
             $pageGroup = PageGroup::preload($pageGroupId);
             $siblings = array_merge($pageGroup->exists ? $pageGroup->itemPageIds() : [], $siblings);
         }
         if ($this->parent >= 0) {
             $siblings = array_merge(static::getChildPageIds($this->parent), $siblings);
         }
         $siblings = array_unique($siblings);
     }
     if (!$pageLang->name) {
         FormMessage::add('page_info_lang[name]', 'page name required');
     }
     if (!$pageLang->url) {
         FormMessage::add('page_info_lang[url]', 'page url required');
     }
     if (!empty($siblings)) {
         $same_level = PageLang::where('url', '=', $pageLang->url)->whereIn('page_id', $siblings);
         $same_level = $this->id ? $same_level->where('page_id', '!=', $this->id) : $same_level;
         if (!$same_level->get()->isEmpty()) {
             FormMessage::add('page_info_lang[url]', 'url in use by another page!');
             $pageLang->url = '';
         }
     }
     if (!$pageLang->name || !$pageLang->url) {
         return false;
     }
     /*
      * If adding a page as a group container, create container / check exists
      */
     if ($this->group_container == -1) {
         $groupContainer = new PageGroup();
         $groupContainer->name = $pageLang->name;
         $groupContainer->item_name = 'Page';
         $groupContainer->default_template = 0;
         $groupContainer->save();
         $this->group_container = $groupContainer->id;
     } elseif ($this->group_container) {
         $groupContainer = PageGroup::preload($this->group_container);
         if (!$groupContainer->exists || $pageDefaults['group_container'] != $this->group_container && !$groupContainer->canEditItems()) {
             $this->group_container = 0;
         }
     }
     /*
      * Check if page info can be updated (based on publishing auth action, or allowed if new page)
      */
     $authPageIdCheck = $this->id ?: ($this->parent > 0 ? $this->parent : 0);
     $canPublish = config('coaster::admin.publishing') > 0 && Auth::action('pages.version-publish', ['page_id' => $authPageIdCheck]) || config('coaster::admin.publishing') == 0 && Auth::action('pages.edit', ['page_id' => $authPageIdCheck]);
     $canPublish = $canPublish || isset($groupContainer) && (config('coaster::admin.publishing') > 0 && $groupContainer->canPublishItems() || config('coaster::admin.publishing') == 0 && $groupContainer->canEditItems());
     $willPublish = !$this->id || $canPublish;
     /*
      * Check and save page changes
      */
     if ($willPublish) {
         // if new page set as last ordered page
         if ($this->parent >= 0 && !$this->id) {
             $lastSibling = static::where('parent', '=', $this->parent)->orderBy('order', 'desc')->first();
             $this->order = $lastSibling ? $lastSibling->order + 1 : 1;
         }
         // if new page publish template
         $this->template = $this->id ? $this->template : $pageVersion->template;
         // if link remove live template
         $this->template = $this->link ? 0 : $this->template;
         // set page live between but no dates set set as hidden, or if can't publish set as hidden
         $this->live = $this->live == 2 && is_null($this->live_end) && is_null($this->live_start) ? 0 : $this->live;
         $this->live = $canPublish ? $this->live : 0;
         // save page data
         $this->save();
         $pageLang->page_id = $this->id;
         $pageLang->save();
     }
     $pageVersion->page_id = $this->id;
     $pageVersion->save();
     /*
      * Update title block to the page name is new page
      */
     if (!$this->id && ($titleBlock = Block::where('name', '=', config('coaster::admin.title_block'))->first())) {
         $titleBlock->setVersionId($pageVersion->version_id)->setPageId($this->id)->getTypeObject()->save($pageLang->name);
         PageSearchData::updateText(strip_tags($pageLang->name), 0, $this->id);
     }
     /*
      * Save Page Groups
      */
     $currentGroupIds = $this->groupIds();
     $newGroupIds = array_keys($pageGroupsPost);
     PageGroupPage::where('page_id', '=', $this->id)->whereIn('group_id', array_diff($currentGroupIds, $newGroupIds))->delete();
     foreach (array_diff($newGroupIds, $currentGroupIds) as $addGroupId) {
         $this->groups()->attach($addGroupId);
     }
     /*
      * Save other page info
      */
     if ($willPublish && Auth::action('menus')) {
         MenuItem::set_page_menus($this->id, array_key_exists('menus', $pageInfoOther) ? $pageInfoOther['menus'] : []);
     }
     if ($canPublish && array_key_exists('beacons', $pageInfoOther) && Auth::action('themes.beacons-update')) {
         BlockBeacon::updatePage($this->id, $pageInfoOther['beacons']);
     }
     return true;
 }