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; }
/** * 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 static function updateAllSearchData() { self::truncate(); $pageLanguages = PageLang::all(); foreach ($pageLanguages as $pageLang) { static::updateText(strip_tags($pageLang->name), 0, $pageLang->page_id, $pageLang->language_id); $pageBlocks = Block::getDataForVersion(new PageBlock(), $pageLang->live_version, ['language_id' => $pageLang->language_id, 'page_id' => $pageLang->page_id]); foreach ($pageBlocks as $pageBlock) { $block = Block::preloadClone($pageBlock->block_id)->setPageId($pageBlock->page_id); $searchText = $block->search_weight > 0 ? $block->getTypeObject()->generateSearchText($pageBlock->content) : ''; static::updateText($searchText, $pageBlock->block_id, $pageBlock->page_id, $pageBlock->language_id); } } }
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; }
public static function version_table($page_id) { $versionsQuery = static::with(['user', 'scheduled_versions'])->where('page_id', '=', $page_id)->orderBy('version_id', 'desc'); $versions = $versionsQuery->paginate(15); $pagination = PaginatorRender::admin($versions); $page_lang = PageLang::where('page_id', '=', $page_id)->where('language_id', '=', Language::current())->first(); $live_version = static::where('page_id', '=', $page_id)->where('version_id', '=', $page_lang ? $page_lang->live_version : 0)->first(); $live_version = $live_version ?: new static(); $can_publish = Auth::action('pages.version-publish', ['page_id' => $page_id]); return View::make('coaster::partials.tabs.versions.table', ['versions' => $versions, 'pagination' => $pagination, 'live_version' => $live_version, 'can_publish' => $can_publish])->render(); }
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 _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(); } }
/** * 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; }
public function createPost($data) { $pageLang = PageLang::where('name', '=', $data->title->rendered)->first(); $uporc = 'updated'; if (empty($pageLang)) { $uporc = 'created'; $page = new Page(); $pageLang = new PageLang(); } else { $page = Page::find($pageLang->page_id); $comments = $this->getComments($data, $page); $latestVersion = PageVersion::latest_version($page->id, true); if (!empty($latestVersion)) { $latestVersion->publish(); } if (!empty($data->yoast)) { $this->getMetas($data->yoast, $data, $page->id); } $res = new \stdClass(); $res->message = 'Post ' . $uporc . ': ' . $pageLang->name; $res->oldLink = $data->link; $res->newLink = Path::getFullUrl($page->id); $res->categories = 'UPDATE RUN'; $res->tags = 'UPDATE RUN'; return $res; } $page->live = 2; $page->live_start = $this->carbonDate($data->date)->format("Y-m-d H:i:s"); $page->created_at = $this->carbonDate($data->date); $page->updated_at = $this->carbonDate($data->modified); $page->parent = $this->groupPage->id; $page->template = $this->group->default_template; $page->save(); $page->groups()->sync([$this->group->id]); $comments = $this->getComments($data, $page); $categories = $this->getCategory($data->_embedded->{"wp:term"}, $page->id); // Page Lang $pageLang->live_version = 0; $pageLang->page_id = $page->id; $pageLang->language_id = Language::current(); $pageLang->name = $data->title->rendered; $pageLang->url = str_slug($pageLang->name); $pageLang->save(); $tags = $this->syncTags($page, $data->_embedded->{"wp:term"}); $date_block = Block::where('name', '=', 'post_date')->first(); if (!empty($date_block)) { $date_block->setPageId($page->id)->getTypeObject()->save($this->carbonDate($data->date)->format("Y-m-d H:i:s")); } $title_block = Block::where('name', '=', config('coaster::admin.title_block'))->first(); if (!empty($title_block)) { $title_block->setPageId($page->id)->getTypeObject()->save($pageLang->name); } $content_block = Block::where('name', '=', 'content')->first(); if (!empty($content_block)) { $content_block->setPageId($page->id)->getTypeObject()->save($this->processContent($data->content->rendered)); } $leadText_block = Block::where('name', '=', 'lead_text')->first(); if (!empty($leadText_block)) { $leadText_block->setPageId($page->id)->getTypeObject()->save($data->excerpt->rendered); } $latestVersion = PageVersion::latest_version($page->id, true); if (!empty($latestVersion)) { $latestVersion->publish(); } if (!empty($data->yoast)) { $this->getMetas($data->yoast, $data, $page->id); } $res = new \stdClass(); $res->message = 'Post ' . $uporc . ': ' . $pageLang->name; $res->oldLink = $data->link; $res->newLink = Path::getFullUrl($page->id); $res->categories = $categories; $res->tags = $tags; return $res; }
/** * @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; } }