/**
  * Display full edit page for gallery
  * @return \Illuminate\Contracts\View\View|string
  */
 public function editPage()
 {
     $page = Page::preload($this->_block->getPageId());
     if ($page->exists) {
         $paths = Path::getById($page->id);
         return View::make('coaster::pages.gallery', ['paths' => $paths, '_block' => $this->_block, 'can_delete' => Auth::action('gallery.delete', ['page_id' => $page->id]), 'can_edit_caption' => Auth::action('gallery.caption', ['page_id' => $page->id])]);
     } else {
         return 'page not found';
     }
 }
Exemple #2
0
 /**
  * @param string $keyword
  * @param int $keywordAdditionalWeight
  */
 public function run($keyword, $keywordAdditionalWeight = 0)
 {
     $searchData = PageSearchData::with('block')->where('search_text', 'LIKE', '%' . $keyword . '%')->get();
     foreach ($searchData as $searchRow) {
         $page = Page::preload($searchRow->page_id);
         if (!$this->_onlyLive || $page->is_live()) {
             $this->_addWeight($page, (($b = $searchRow->block) ? $b->search_weight : 2) + $keywordAdditionalWeight);
         }
     }
 }
 /**
  * MenuItemDetails constructor.
  * @param MenuItem $item
  * @param bool $active
  * @param int $parentPageId
  * @param bool $canonicals
  */
 public function __construct(MenuItem $item, $active = false, $parentPageId = 0, $canonicals = false)
 {
     $pageId = Path::unParsePageId($item->page_id);
     if (!$item->id && !$canonicals) {
         $item->page_id = Path::parsePageId($pageId, $parentPageId);
     }
     $this->item = $item;
     $this->page = Page::preload($pageId);
     $this->parentPageId = $parentPageId;
     $this->active = $active;
     $this->name = $item->custom_name ?: PageLang::getName($pageId);
     $this->url = $this->page && $this->page->link ? PageLang::getUrl($pageId) : Path::getFullUrl($item->page_id);
 }
 /**
  * PageDetails constructor.
  * @param int $pageId
  * @param int $groupContainerPageId
  */
 public function __construct($pageId, $groupContainerPageId = 0)
 {
     $fullPaths = Path::getFullPath($pageId . ($groupContainerPageId ? ',' . $groupContainerPageId : ''));
     $page = Page::preload($pageId);
     $pageLang = PageLang::preload($pageId);
     $this->urlSegment = $pageLang->url;
     $this->url = $fullPaths->fullUrl;
     $this->name = $pageLang->name;
     $this->fullName = $fullPaths->fullName;
     $this->full_name = $this->fullName;
     $this->full_url = $this->url;
     $this->page = $page;
     $this->pageLang = $pageLang;
 }
 public function postSort()
 {
     $pages = Request::input('list');
     if (!empty($pages)) {
         $rootPages = Page::join('page_lang', 'page_lang.page_id', '=', 'pages.id')->where(function ($query) {
             $query->whereIn('page_lang.url', ['', '/']);
         })->where('page_lang.language_id', '=', Language::current())->where('link', '=', 0)->get(['pages.*'])->all();
         $rootPageIds = array_map(function ($rootPage) {
             return $rootPage->id;
         }, $rootPages);
         $order = [];
         $changeUnderParentIds = [];
         foreach ($pages as $pageId => $parent) {
             $currentPage = Page::preload($pageId);
             if ($currentPage->exists) {
                 $parent = empty($parent) || $parent == 'null' ? 0 : $parent;
                 if ($currentPage->parent != $parent && $parent != 0 && (in_array($currentPage->id, $rootPageIds) || in_array($parent, $rootPageIds))) {
                     return 0;
                     // don't allow root/home page to be moved under other pages or other pages to be moved under it
                 }
                 // get the order value for current page
                 $order[$parent] = isset($order[$parent]) ? $order[$parent] : 0;
                 $order[$parent]++;
                 if ($currentPage->parent != $parent || $currentPage->order != $order[$parent]) {
                     if (Auth::action('pages.sort', ['page_id' => $parent]) && Auth::action('pages.sort', ['page_id' => $currentPage->parent])) {
                         $parentPageName = $parent ? PageLang::preload($parent)->name : 'top level';
                         $pageName = PageLang::preload($pageId)->name;
                         if ($parent != $currentPage->parent) {
                             array_push($changeUnderParentIds, $parent, $currentPage->parent);
                             AdminLog::new_log('Moved page \'' . $pageName . '\' under \'' . $parentPageName . '\' (Page ID ' . $currentPage->id . ')');
                         }
                         if (!in_array($parent, $changeUnderParentIds)) {
                             $changeUnderParentIds[] = $parent;
                             AdminLog::new_log('Re-ordered pages in \'' . $parentPageName . '\' (Page ID ' . $currentPage->id . ')');
                         }
                         $changeUnderParentIds = array_unique($changeUnderParentIds);
                         $currentPage->parent = $parent;
                         $currentPage->order = $order[$parent];
                         $currentPage->save();
                     } else {
                         return 0;
                         // error, can't move page to new location
                     }
                 }
             } else {
                 return 0;
                 // error, moved page no longer exists
             }
         }
     }
     return 1;
 }
 /**
  * @param int $pageId
  * @param bool $checkLive
  * @param bool $sort
  * @return Collection
  */
 public function itemPageFiltered($pageId, $checkLive = false, $sort = false)
 {
     $pages = new Collection();
     if ($groupPageIds = $this->itemPageIdsFiltered($pageId, $checkLive, $sort)) {
         foreach ($groupPageIds as $groupPageId) {
             $pages->add(Page::preload($groupPageId));
         }
     }
     return $pages;
 }
 /**
  * @param Page[]|MenuItem[] $items
  * @param int $parentPageId
  * @param int $level
  * @param int $subLevels
  * @return string
  */
 protected static function _buildMenu($items, $parentPageId, $level = 1, $subLevels = 0)
 {
     // convert page models to menu items and remove non-live pages
     foreach ($items as $k => $item) {
         if (is_a($item, Page::class)) {
             $pageId = $item->id;
             $items[$k] = new MenuItem();
             $items[$k]->page_id = $item->id;
             $items[$k]->sub_levels = 0;
             $items[$k]->custom_name = '';
         } else {
             $pageId = $item->page_id;
         }
         $pageId = Path::unParsePageId($pageId);
         $page = Page::preload($pageId);
         if (!$page->exists || !$page->is_live()) {
             unset($items[$k]);
         }
     }
     $pageParents = [];
     $pageLevels = PageBuilder::getData('pageLevels') ?: [];
     foreach ($pageLevels as $k => $parentPage) {
         if ($k > 0) {
             $pageParents[] = $parentPage->page_id;
         }
     }
     $currentPage = PageBuilder::getData('page') ?: new Page();
     $total = count($items);
     $menuItems = '';
     $defaultSubLevels = $subLevels;
     if (is_a($items, Collection::class)) {
         $items = $items->all();
     }
     $items = array_values($items);
     foreach ($items as $count => $item) {
         $isFirst = $count == 0;
         $isLast = $count == $total - 1;
         $pageId = Path::unParsePageId($item->page_id);
         $active = $currentPage->id == $pageId || in_array($pageId, $pageParents);
         $itemData = new MenuItemDetails($item, $active, $parentPageId, self::$_canonicals);
         $subMenu = '';
         $subLevels = $item->sub_levels > 0 ? $item->sub_levels : $defaultSubLevels;
         if ($subLevels > 0) {
             if ($subPages = Page::category_pages($pageId)) {
                 $subMenu = self::_buildMenu($subPages, $pageId, $level + 1, $subLevels - 1);
             }
         }
         if (!empty($subMenu)) {
             $menuItems .= self::_getRenderedView('submenu_' . $level, ['item' => $itemData, 'items' => $subMenu, 'is_first' => $isFirst, 'is_last' => $isLast, 'count' => $count + 1, 'total' => $total, 'level' => $level, 'further_levels' => $subLevels]);
         } else {
             $menuItems .= self::_getRenderedView('item', ['item' => $itemData, 'is_first' => $isFirst, 'is_last' => $isLast, 'count' => $count, 'total' => $total, 'level' => $level]);
         }
     }
     if ($level == 1) {
         return self::_getRenderedView('menu', ['items' => $menuItems]);
     } else {
         return $menuItems;
     }
 }
 /**
  * @param int $categoryPageId
  * @param Page[]|Collection $pages
  * @param array $options
  * @return string
  */
 protected function _renderCategory($categoryPageId, $pages, $options)
 {
     if (array_key_exists('view', $options) && empty($options['view'])) {
         unset($options['view']);
     }
     $defaultOptions = ['render' => true, 'renderIfEmpty' => true, 'view' => 'default', 'type' => 'all', 'per_page' => 20, 'limit' => 0, 'content' => '', 'canonicals' => config('coaster::frontend.canonicals')];
     $options = array_merge($defaultOptions, $options);
     if (!$options['render']) {
         return $pages;
     }
     // select page of selected type
     $pagesOfSelectedType = [];
     if ($options['type'] == 'all') {
         $pagesOfSelectedType = is_a($pages, Collection::class) ? $pages->all() : $pages;
     } else {
         foreach ($pages as $page) {
             $children = count(Page::getChildPageIds($page->id));
             if ($options['type'] == 'pages' && $children == 0 || $options['type'] == 'categories' && $children > 0) {
                 $pagesOfSelectedType[] = $page;
             }
         }
     }
     // limit results
     if (!empty($options['limit']) && is_int($options['limit'])) {
         $pagesOfSelectedType = array_slice($pagesOfSelectedType, 0, $options['limit']);
     }
     // pagination
     if (!empty($options['per_page']) && (int) $options['per_page'] > 0) {
         $paginator = new LengthAwarePaginator($pagesOfSelectedType, count($pagesOfSelectedType), $options['per_page'], Request::input('page', 1));
         $paginator->setPath(Request::getPathInfo());
         $paginationLinks = PaginatorRender::run($paginator);
         $pages = array_slice($pagesOfSelectedType, ($paginator->currentPage() - 1) * $options['per_page'], $options['per_page']);
     } else {
         $pages = $pagesOfSelectedType;
         $paginationLinks = '';
     }
     $list = '';
     $total = count($pages);
     if (!$total && !$options['renderIfEmpty']) {
         return '';
     }
     $groupPageContainerId = 0;
     if ($categoryPageId && !$options['canonicals']) {
         $categoryPage = Page::preload($categoryPageId);
         $groupPageContainerId = $categoryPage->exists && $categoryPage->group_container > 0 ? $categoryPage->id : 0;
     }
     $pages = array_values($pages);
     foreach ($pages as $count => $page) {
         $isFirst = $count == 0;
         $isLast = $count == $total - 1;
         if (is_string($page->id)) {
             $tmpCustomBlockKey = $this->_customBlockDataKey;
             $this->_customBlockDataKey = 'customPage:' . $page->id;
             $pageDetails = new \stdClass();
             foreach ($page as $blockName => $content) {
                 if (in_array($blockName, ['fullUrl', 'fullName'])) {
                     $pageDetails->{$blockName} = $content;
                 } else {
                     $this->setCustomBlockData($blockName, $content, $this->_customBlockDataKey);
                 }
             }
             Path::addCustomPagePath($page->id, $pageDetails);
         }
         $fullPageInfo = new PageDetails($page->id, $groupPageContainerId);
         $this->pageOverride = $page;
         $list .= $this->_getRenderedView('categories.' . $options['view'] . '.page', ['page' => $fullPageInfo, 'category_id' => $categoryPageId, 'is_first' => $isFirst, 'is_last' => $isLast, 'count' => $count + 1, 'total' => $total]);
         if (isset($tmpCustomBlockKey)) {
             $this->_customBlockDataKey = $tmpCustomBlockKey;
             $tmpCustomBlockKey = null;
         }
         $this->pageOverride = null;
     }
     return $this->_getRenderedView('categories.' . $options['view'] . '.pages_wrap', ['pages' => $list, 'category_id' => $categoryPageId, 'pagination' => $paginationLinks, 'links' => $paginationLinks, 'total' => $total, 'content' => $options['content'], 'search_query' => $this->searchQuery]);
 }