public function getList($pageId = 0) { $page = Page::find($pageId); if (!empty($page)) { $block_cats = Template::template_blocks(config('coaster::frontend.theme'), $page->template); foreach ($block_cats as $block_cat) { foreach ($block_cat as $block) { if ($block->type == 'gallery') { $gallery_blocks[] = $block; } } } } if (isset($gallery_blocks)) { if (count($gallery_blocks) == 1) { return \redirect()->route('coaster.admin.gallery.edit', ['pageId' => $pageId, 'blockId' => $gallery_blocks[0]->id]); } $page_lang_data = PageLang::preload($pageId); if (!empty($page_lang_data)) { $name = $page_lang_data->name; if ($page->parent != 0) { $parent_lang_data = PageLang::preload($page->parent); $name = $parent_lang_data->name . " / " . $name; } } else { $name = ''; } $this->layoutData['content'] = View::make('coaster::pages.gallery.list', array('page_name' => $name, 'page_id' => $pageId, 'galleries' => $gallery_blocks)); } else { $this->layoutData['content'] = 'No Galleries Found'; } return null; }
/** * 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 getPages($groupId) { $group = PageGroup::preload($groupId); if ($group->exists) { $pageIds = $group->itemPageIds(false, true); $attributes = PageGroupAttribute::where('group_id', '=', $groupId)->get(); $attributeBlocks = []; foreach ($attributes as $attribute) { $block = Block::preload($attribute->item_block_id); if ($block->exists) { $attributeBlocks[$attribute->item_block_id] = $block; } } $pageRows = ''; if (!empty($pageIds)) { foreach ($pageIds as $pageId) { $pageLang = PageLang::preload($pageId); $showBlocks = []; $canEdit = Auth::action('pages.edit', ['page_id' => $pageId]); $canDelete = Auth::action('pages.delete', ['page_id' => $pageId]); foreach ($attributeBlocks as $attributeBlock) { $pageBlockContent = PageBlock::preloadPageBlockLanguage($pageId, $attributeBlock->id, -1, 'block_id')->content; if (strpos($attributeBlock->type, 'selectmultiple') === 0 && !empty($pageBlockContent)) { // selectmultiple $showBlocks[] = implode(', ', unserialize($pageBlockContent)); } elseif ($attributeBlock->type == 'datetime' && !empty($pageBlockContent)) { // datetime $showBlocks[] = (new Carbon($pageBlockContent))->format(config('coaster::date.format.long')); } else { // text/string/select $showBlocks[] = strip_tags(StringHelper::cutString($pageBlockContent, 50)); } } $pageRows .= View::make('coaster::partials.groups.page_row', array('page_lang' => $pageLang, 'item_name' => $group->item_name, 'showBlocks' => $showBlocks, 'can_edit' => $canEdit, 'can_delete' => $canDelete))->render(); } } $pagesTable = View::make('coaster::partials.groups.page_table', array('rows' => $pageRows, 'item_name' => $group->item_name, 'blocks' => $attributeBlocks))->render(); $this->layoutData['modals'] = View::make('coaster::modals.general.delete_item'); $this->layoutData['content'] = View::make('coaster::pages.groups', array('group' => $group, 'pages' => $pagesTable, 'can_add' => $group->canAddItems(), 'can_edit' => $group->canEditItems())); } }
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; }
private function _print_pages($parent) { $pages_li = ''; foreach ($this->_child_pages[$parent] as $child_page) { $page_lang = PageLang::preload($child_page->id); $sub_pages = ""; if ($child_page->group_container > 0) { } elseif (!empty($this->_child_pages[$child_page->id])) { $sub_pages = $this->_print_pages($child_page->id); } $page_actions = AdminAction::where('controller_id', '=', 2)->where('inherit', '=', 0)->where('edit_based', '=', 0)->get(); $edit_actions = []; foreach ($page_actions as $action) { if ($action->action == 'index') { $edit_actions['pages'] = false; } else { $edit_actions['pages.' . $action->action] = false; } } if (!config('coaster::admin.publishing')) { unset($edit_actions['pages.version-publish']); } $actions = $this->_role_permissions->processed_actions(['page_id' => $child_page->id]); $actions = array_merge($edit_actions, array_intersect_key($actions, $edit_actions)); $page_actions = []; foreach ($actions as $action => $value) { if ($action == 'pages') { $page_actions['index'] = $value; } else { $page_actions[str_replace('pages.', '', $action)] = $value; } } $pages_li .= View::make('coaster::partials.roles.pages.li', array('page_lang' => $page_lang, 'sub_pages' => $sub_pages, 'actions' => $page_actions))->render(); } return View::make('coaster::partials.roles.pages.ul', array('pages_li' => $pages_li)); }
public static function getPageListView($listPages, $tree = false, $level = 1, $cat_url = '') { $listPages = is_array($listPages) ? collect($listPages) : $listPages; if (!$listPages->isEmpty()) { $pages_li = ''; foreach ($listPages as $page) { if (config('coaster::admin.advanced_permissions') && !Auth::action('pages', ['page_id' => $page->id])) { continue; } $permissions = []; $permissions['add'] = Auth::action('pages.add', ['page_id' => $page->id]) && $page->parent != -1; $permissions['edit'] = Auth::action('pages.edit', ['page_id' => $page->id]); $permissions['delete'] = Auth::action('pages.delete', ['page_id' => $page->id]); $permissions['group'] = Auth::action('groups.pages', ['page_id' => $page->id]); $permissions['galleries'] = Auth::action('gallery.edit', ['page_id' => $page->id]); $permissions['forms'] = Auth::action('forms.submissions', ['page_id' => $page->id]); $permissions['blog'] = Auth::action('system.wp_login'); $page_lang = PageLang::preload($page->id); $li_info = new \stdClass(); $li_info->leaf = ''; $li_info->altName = ''; if ($tree) { $li_info->preview_link = $cat_url . '/' . $page_lang->url; $li_info->preview_link = $li_info->preview_link == '//' ? '/' : $li_info->preview_link; $childPages = self::getChildPages($page->id); $li_info->leaf = self::getPageListView($childPages, true, $level + 1, $li_info->preview_link); } else { $li_info->preview_link = Path::getFullUrl($page->id); $li_info->altName = Path::getFullName($page->id); } $li_info->number_of_forms = Template::preload_blocks_of_type('form', $page->template); $li_info->number_of_galleries = Template::preload_blocks_of_type('gallery', $page->template); if (trim($page_lang->url, '/') == '' && $page->parent == 0 && $page->link == 0) { $permissions['add'] = false; } if ($page->group_container > 0) { $li_info->type = 'type_group'; $li_info->group = PageGroup::preload($page->group_container); $li_info->group = $li_info->group->exists ? $li_info->group : ''; } else { if ($page->link == 1) { $li_info->preview_link = $page_lang->url; $li_info->type = 'type_link'; } else { $li_info->type = 'type_normal'; } $li_info->group = ''; } if (trim($li_info->preview_link, '/') != '' && trim($li_info->preview_link, '/') == trim(config('coaster::blog.url'), '/')) { $li_info->blog = route('coaster.admin.system.wp-login'); } else { $li_info->blog = ''; } if (!$page->is_live()) { $li_info->type = 'type_hidden'; if ($page->link == 0) { if ($liveVersion = PageVersion::getLiveVersion($page->id)) { $li_info->preview_link .= '?preview=' . $liveVersion->preview_key; } } } $pages_li .= View::make('coaster::partials.pages.li', array('page' => $page, 'page_lang' => $page_lang, 'li_info' => $li_info, 'permissions' => $permissions))->render(); } return View::make('coaster::partials.pages.ol', array('pages_li' => $pages_li, 'level' => $level))->render(); } return null; }
/** * @param string|int $pageId * @return Path */ protected static function _getById($pageId) { if (empty(self::$_preLoaded[$pageId])) { $pageLang = PageLang::preload($pageId); self::$_preLoaded[$pageId] = new self($pageLang->exists); self::$_preLoaded[$pageId]->pageId = $pageId; self::$_preLoaded[$pageId]->name = $pageLang->name; self::$_preLoaded[$pageId]->url = rtrim($pageLang->url, '/'); } return self::$_preLoaded[$pageId]; }
/** * @param int $pageId * @param bool $noOverride * @return int */ public function pageVersion($pageId = 0, $noOverride = false) { $pageId = $pageId ?: $this->pageId($noOverride); if ($this->previewVersion && $pageId == $this->pageId(true)) { return $this->previewVersion->version_id; } else { return PageLang::preload($pageId)->live_version; } }