Ejemplo n.º 1
0
 public function getIndex()
 {
     // load theme global blocks
     $blocks = array();
     $theme = Theme::find(config('coaster::frontend.theme'));
     if (!empty($theme)) {
         $blocks = Theme::theme_blocks($theme->id);
     }
     // load tab contents from categories & blocks (with default block contents)
     $default_blocks = PageBlockDefault::preloadArray();
     list($tab_headers, $tab_contents) = Block::getTabs($blocks, $default_blocks);
     $tab_headers = array_filter($tab_headers);
     ksort($tab_headers);
     $tab_data = ['headers' => View::make('coaster::partials.tabs.header', ['tabs' => $tab_headers])->render(), 'contents' => View::make('coaster::partials.tabs.content', ['tabs' => $tab_contents, 'item' => 'Site-wide Content', 'new_page' => false, 'publishing' => false, 'can_publish' => true])->render()];
     $this->layoutData['title'] = 'Site-wide Content';
     $this->layoutData['content'] = View::make('coaster::pages.blocks', ['tab' => $tab_data]);
 }
Ejemplo n.º 2
0
 public function getEdit($pageId, $versionId = 0)
 {
     // get page data
     if (!($page = Page::find($pageId))) {
         return 'Page Not Found';
     }
     PageVersionSchedule::checkPageVersionIds();
     $publishingOn = config('coaster::admin.publishing') > 0;
     $auth = ['can_publish' => $publishingOn && Auth::action('pages.version-publish', ['page_id' => $pageId]) || !$publishingOn && Auth::action('pages.edit', ['page_id' => $pageId]), 'can_duplicate' => $page->canDuplicate()];
     // get page lang data
     if (!($page_lang = $page->pageCurrentLang)) {
         if (!($page_lang = $page->pageDefaultLang)) {
             return 'Page Lang Data Not Found';
         }
         $page_lang = $page_lang->replicate();
         $page_lang->language_id = Language::current();
         $page_lang->save();
     }
     $page_lang->url = ltrim($page_lang->url, '/');
     // get version data
     $versionData = [];
     $versionData['latest'] = PageVersion::latest_version($pageId);
     $versionData['editing'] = $versionId == 0 || $versionId > $versionData['latest'] ? $versionData['latest'] : $versionId;
     $versionData['live'] = $page_lang->live_version;
     // get frontend link (preview or direct link if document)
     $frontendLink = Path::getFullUrl($pageId);
     if (!$page->is_live() && $page->link == 0) {
         $live_page_version = PageVersion::where('page_id', '=', $pageId)->where('version_id', '=', $versionData['live'])->first();
         if (!empty($live_page_version)) {
             $frontendLink .= '?preview=' . $live_page_version->preview_key;
         }
     }
     // if loading a non live version get version template rather than current page template
     if ($versionData['live'] != $versionData['editing']) {
         if ($page_version = PageVersion::where('version_id', '=', $versionData['editing'])->where('page_id', '=', $pageId)->first()) {
             $page->template = $page_version->template;
         } else {
             return 'Page Version Data Not Found';
         }
     }
     // load blocks content
     if ($page->link == 0) {
         $blocks = Template::template_blocks(config('coaster::frontend.theme'), $page->template);
         $blocks_content = PageBlock::preloadPage($pageId, $versionData['editing']);
         list($tab_headers, $tab_contents) = Block::getTabs($blocks, $blocks_content, $page->id);
     } else {
         $tab_headers = [];
         $tab_contents = [];
     }
     // load page info and order so page info is first and block categories are in order
     list($tab_headers[0], $tab_contents[0]) = $page->tabInfo();
     ksort($tab_headers);
     // load version / publish requests
     if ($publishingOn && count($tab_headers) > 1) {
         $tab_headers[-1] = 'Versions';
         $tab_contents[-1] = View::make('coaster::partials.tabs.versions.main', ['content' => PageVersion::version_table($page->id)])->render();
         list($tab_headers[-2], $tab_contents[-2]) = $page->tabRequests();
     }
     // remove empty tabs
     $tab_headers = array_filter($tab_headers);
     // get item name, or default to page
     $item_name = $page->groupItemsNames() ?: 'Page';
     $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' => false, 'publishing' => $publishingOn, 'can_publish' => $auth['can_publish'], 'page' => $page])->render()];
     // add required modals
     if ($publishingOn) {
         $intervals = PageVersionSchedule::selectOptions();
         $this->layoutData['modals'] = View::make('coaster::modals.pages.publish')->render() . View::make('coaster::modals.pages.publish_schedule', ['intervals' => $intervals, 'live_version' => $versionData['live']])->render() . View::make('coaster::modals.pages.request_publish')->render() . View::make('coaster::modals.pages.rename_version')->render();
     }
     $this->layoutData['content'] = View::make('coaster::pages.pages.edit', ['page' => $page, 'page_lang' => $page_lang, 'item_name' => $item_name, 'publishingOn' => $publishingOn, 'tab' => $tab_data, 'frontendLink' => $frontendLink, 'version' => $versionData, 'auth' => $auth]);
     return null;
 }