public static function boot() { parent::boot(); static::deleted(function (MenuItem $menuItem) { $log = 'Menu Item \'' . Path::getFullName($menuItem->page_id) . '\' deleted from \'' . Menu::name($menuItem->menu_id) . '\''; $menuItem->addLogWithBackup($log, $menuItem); }); }
/** * Save link in search text (without the target attribute) * @param null|string $content * @return null|string */ public function generateSearchText($content) { $content = $this->_defaultData($content); $content['link'] = str_replace('internal://', '', $content['link'], $count); if ($count > 0) { $paths = Path::getById($content['link']); $content['link'] = $paths->exists ? $paths->name : ''; } return parent::generateSearchText($content['link']); }
/** * 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'; } }
/** * 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; }
/** * Display pages selected with view * Also reverse lookup option, find pages with the current page selected * @param string $content * @param array $options * @return string */ public function display($content, $options = []) { $pages = []; $page_ids = []; if (isset($options['reverse'])) { // get page_ids on which current page is selected in this block $currentPageId = PageBuilder::pageId(true); if ($currentPageId) { $same_blocks = PageBlock::where('block_id', '=', $this->_block->id)->get(); foreach ($same_blocks as $same_block) { $block_page_ids = @unserialize($same_block->content); if (!empty($block_page_ids)) { foreach ($block_page_ids as $k => $block_page_id) { $block_page_id = Path::unParsePageId($block_page_id); if ($currentPageId == $block_page_id) { $page_ids[] = $same_block->page_id; break; } } } } } } elseif (!empty($content)) { $page_ids = unserialize($content); } if (!empty($page_ids)) { foreach ($page_ids as $page_id) { $parsedPageId = Path::unParsePageId($page_id, false); $pages[$page_id] = new PageDetails($parsedPageId[0], !empty($parsedPageId[1]) ? $parsedPageId[1] : 0); } } $template = !empty($options['view']) ? $options['view'] : $this->_block->name; $selectPageViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.selectpages.'; if (View::exists($selectPageViews . $template)) { return View::make($selectPageViews . $template, array('pages' => $pages))->render(); } else { return 'Select pages template not found'; } }
public function tabInfo() { $contents = ''; $publishingOn = config('coaster::admin.publishing') > 0; $canPublish = $publishingOn && Auth::action('pages.version-publish', ['page_id' => $this->id]) || !$publishingOn; // page parent (only updated for new pages) if (!$this->id) { $parentPages = [-1 => '-- None --', 0 => '-- Top Level Page --'] + static::get_page_list(['links' => false, 'exclude_home' => true, 'group_pages' => false]); if (!array_key_exists($this->parent, $parentPages)) { $this->parent = -1; } } else { $parentPages = null; } // beacons selection (only updated for existing pages) if ($this->id && Auth::action('themes.beacons-update')) { $beaconSelect = BlockBeacon::getDropdownOptions($this->id); $beaconSelect = empty($beaconSelect->options) ? null : $beaconSelect; } else { $beaconSelect = null; } // page name, url $pageLang = $this->id ? PageLang::where('page_id', '=', $this->id)->where('language_id', '=', Language::current())->first() : new PageLang(); $fullUrls = [-1 => '?', 0 => '/']; foreach (Path::all() as $pageId => $details) { $fullUrls[$pageId] = rtrim($details->fullUrl, '/') . '/'; } $urlPrefixes = $this->parentPathIds(); foreach ($urlPrefixes as $pageId => $urlPrefix) { if (!key_exists($pageId, $fullUrls)) { $fullUrls[$pageId] = '?'; } } $contents .= View::make('coaster::partials.tabs.page_info.page_info', ['page' => $this, 'page_lang' => $pageLang, 'parentPages' => $parentPages, 'beacon_select' => $beaconSelect, 'urlArray' => $fullUrls, 'urlPrefixes' => $urlPrefixes, 'publishing_on' => $publishingOn, 'can_publish' => $canPublish])->render(); // groups $groups = PageGroup::all(); if (!$groups->isEmpty() || config('coaster::site.groups') !== '') { $contents .= View::make('coaster::partials.tabs.page_info.groups', ['page' => $this, 'groups' => $groups])->render(); } //template if (empty($this->template)) { $this->template = config('coaster::admin.default_template'); $parentPage = static::find($this->parent); if ($parentPage && ($parentTemplate = Template::find($parentPage->template))) { $this->template = $parentTemplate->child_template; } } $templateData = Template::find($this->template); $templates = Theme::get_template_list($this->template); $templateSelectHidden = !empty($templateData) ? $templateData->hidden : false; // menu selection $menus = Menu::all(); if (!$menus->isEmpty() && Auth::action('menus')) { $in_menus = $this->id ? MenuItem::get_page_menus($this->id) : []; foreach ($menus as $k => $menu) { $menus[$k]->in_menu = in_array($menu->id, $in_menus); } } else { $menus = []; } $contents .= View::make('coaster::partials.tabs.page_info.display_info', ['page' => $this, 'template' => $this->template, 'templates' => $templates, 'templateSelectHidden' => $templateSelectHidden, 'menus' => $menus, 'can_publish' => $canPublish])->render(); // live options, sitemap $liveOptions = [0 => 'Not Live (Hidden)', 1 => 'Live (Ignores Dates)', 2 => 'Live Between Specific Dates/Times']; $sitemapOptions = [0 => 'Excluded From Sitemap', 1 => 'Included in Sitemap (If Page Live)']; $contents .= View::make('coaster::partials.tabs.page_info.live_options', ['page' => $this, 'liveOptions' => $liveOptions, 'sitemapOptions' => $sitemapOptions, 'disabled' => !$canPublish])->render(); return ['Page Info', $contents]; }
/** * Get page name for search text instead of id * @param null|string $content * @return null */ public function generateSearchText($content) { return Path::getById($content)->name ?: null; }
/** * @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; } }
public function getCsv($pageId = 0, $blockId = 0) { $block_data = Block::getBlockOnPage($blockId, $pageId); if (empty($block_data) || $block_data->type != 'form') { \abort('404', 'Form not found on page'); } else { $csv = array(); $columns = array(); $column = 2; $row = 1; $submissions = FormSubmission::where('form_block_id', '=', $blockId)->orderBy('id', 'desc')->get(); if (!$submissions->isEmpty()) { foreach ($submissions as $submission) { $csv[$row] = array(); $csv[$row][0] = $submission->created_at; $csv[$row][1] = !empty($submission->from_page_id) ? Path::getFullName($submission->from_page_id) : '-'; $form_data = @unserialize($submission->content); if (!empty($form_data)) { foreach ($form_data as $k => $v) { if (!isset($columns[$k])) { $columns[$k] = $column; $column++; } if (is_array($v)) { $v = implode(", ", $v); } $csv[$row][$columns[$k]] = $v; } } else { preg_match_all('/\\"(.*?)\\";s:\\d*:\\"(.*?)\\";/si', $submission->content, $matches); foreach ($matches[1] as $k => $field_key) { if (!isset($columns[$field_key])) { $columns[$field_key] = $column; $column++; } $csv[$row][$columns[$field_key]] = $matches[2][$k]; } } $row++; } // add row titles $csv[0][0] = 'Date/Time'; $csv[0][1] = 'Page'; foreach ($columns as $name => $col) { $csv[0][$col] = ucwords($name); } $numb_columns = count($columns); foreach ($csv as $row_id => $csv_row) { for ($i = 0; $i < $numb_columns; $i++) { if (!isset($csv_row[$i])) { $csv[$row_id][$i] = ''; } } ksort($csv[$row_id]); } ksort($csv); $block_data = Block::find($blockId); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=" . $block_data->name . ".csv"); header("Pragma: no-cache"); header("Expires: 0"); $output = fopen("php://output", "w"); foreach ($csv as $csv_row) { fputcsv($output, $csv_row); // here you can change delimiter/enclosure } fclose($output); } exit; } }
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; }
public static function updateUrl($uniqueId, $pageId) { $beacon = self::where('unique_id', '=', $uniqueId)->first(); if (empty($beacon)) { FormMessage::add('page_info_other[beacons]', 'A selected beacon was not found'); } else { $beaconUrl = URL::to('/'); $beaconUrlParts = parse_url($beaconUrl); $beaconUrlEncoded = '02' . bin2hex($beaconUrlParts['host']); if ($pageId) { $pageUrl = Path::getFullUrl($pageId); $pageUrl = URL::to($pageUrl); try { $bitlyResponse = json_decode(self::_bitly()->request('GET', 'v3/shorten', ['query' => ['access_token' => config('coaster::key.bitly'), 'longUrl' => $pageUrl . '?beacon_id=' . $uniqueId]])->getBody()); if ($bitlyResponse->status_code == 200) { $beaconUrl = 'http://bit.ly/' . $bitlyResponse->data->hash; $beaconUrlEncoded = '02' . bin2hex('bit.ly/' . $bitlyResponse->data->hash); } else { FormMessage::add('page_info_other[beacons]', 'Error generating bit.ly url (response: ' . $bitlyResponse->status_txt . ')'); return 0; } } catch (RequestException $e) { FormMessage::add('page_info_other[beacons]', 'Error generating bit.ly url (response: ' . $e->getCode() . ')'); return 0; } } if ($beacon->url == $beaconUrl && $beacon->page_id == $pageId) { return 1; } try { self::_client()->request('POST', 'config/delete', ['query' => ['uniqueId' => $uniqueId]]); self::_client()->request('POST', 'config/create', ['query' => ['uniqueId' => $uniqueId, 'deviceType' => 'beacon', 'url' => $beaconUrlEncoded]])->getBody(); $beacon->page_id = $pageId; $beacon->url = $beaconUrl; $beacon->save(); return 1; } catch (RequestException $e) { $error = json_decode($e->getResponse()->getBody()); FormMessage::add('page_info_other[beacons]', 'Error updating device config with new URL (' . $error->status . ': ' . $error->message . ')'); } } return 0; }
/** * @param int|string $pageId * @param string $separator * @return Path */ public static function getFullPath($pageId, $separator = ' » ') { $pagePathData = Path::getById($pageId); $pagePathData->fullName = $pagePathData->fullName ? str_replace($pagePathData->separator, $separator, $pagePathData->fullName) : $pagePathData->fullName; return $pagePathData; }
public function getTinymcePageList() { $pages = array(); $all_pages = Page::all(); foreach ($all_pages as $page) { if (config('coaster::admin.advanced_permissions') && !Auth::action('pages', ['page_id' => $page->id])) { continue; } $pages[] = $page->id; } $page_details = Path::getFullPaths($pages, html_entity_decode(' » ')); $json_array = array(); foreach ($page_details as $page_detail) { $details = new \stdClass(); $details->title = $page_detail->fullName; $details->value = $page_detail->fullUrl; $json_array[] = $details; } usort($json_array, function ($a, $b) { return strcmp($a->title, $b->title); }); return json_encode($json_array); }
<th>Requested By</th> @endif @if ($show['status']) <th>Status</th> @endif <th>Actions</th> </tr> </thead> <tbody> @foreach($requests as $request) <tr> <td>{!! $request->page_version->version_id !!}</td> <td>{!! $request->page_version->getName() !!}</td> <?php $page_name = \CoasterCms\Helpers\Cms\Page\Path::getFullName($request->page_version->page_id); ?> @if ($show['page']) <td>{!! $page_name !!}</td> @endif <td>{!! $request->note !!}</td> @if ($show['requested_by']) <td>{!! $request->user?$request->user->email:'Undefined' !!}</td> @endif @if ($show['status']) <td>{!! $request->status !!}</td> @endif <td> <a href="{{ CoasterCms\Helpers\Cms\Page\Path::getFullUrl($request->page_version->page_id).'?preview='.$request->page_version->preview_key }}" target="_blank"><i class="glyphicon glyphicon-eye-open itemTooltip" title="Preview"></i></a> <a href="{{ route('coaster.admin.pages.edit', ['pageId' => $request->page_version->page_id, 'version' => $request->page_version->version_id]) }}"><i
public function postSaveLevels() { $itemId = substr(Request::input('id'), 5); $item = MenuItem::find($itemId); if (!empty($item)) { $menu = Menu::find($item->menu_id); $item->sub_levels = Request::input('sub_level') > $menu->max_sublevel ? $menu->max_sublevel : Request::input('sub_level'); $item->save(); // log action AdminLog::new_log('Change sub levels for menu item \'' . Path::getFullName($item->page_id) . '\' in \'' . Menu::name($item->menu_id) . '\' to ' . $item->sub_levels); return 1; } return null; }
/** * @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]); }