/**
  * 
  */
 protected function _load()
 {
     $page = new Page();
     $page->id = 0;
     $page_lang = new PageLang();
     $page_lang->name = '';
     $page_lang->url = '';
     $page_lang->live_version = 0;
     $page->setRelation('pageCurrentLang', $page_lang);
     $this->pageLevels = [$page];
 }
 /**
  * Make changes to the database.
  *
  * @return void
  */
 public function up()
 {
     $date = new Carbon();
     $addRows = [];
     foreach (Page::all() as $page) {
         if ($page->in_group) {
             $addRows[] = ['page_id' => $page->id, 'group_id' => $page->in_group, 'created_at' => $date, 'updated_at' => $date];
         }
     }
     DB::table('page_group_pages')->insert($addRows);
     Schema::table('pages', function (Blueprint $table) {
         $table->dropColumn('in_group');
         $table->integer('group_container_url_priority')->default(0)->after('group_container');
         $table->integer('canonical_parent')->default(0)->after('group_container_url_priority');
     });
     Schema::table('page_group', function (Blueprint $table) {
         $table->dropColumn('default_parent');
         $table->dropColumn('order_by_attribute_id');
         $table->dropColumn('order_dir');
         $table->integer('url_priority')->default(50)->after('item_name');
     });
     Schema::table('page_group_attributes', function (Blueprint $table) {
         $table->integer('item_block_order_priority')->default(0)->after('item_block_id');
         $table->string('item_block_order_dir')->default('asc')->after('item_block_order_priority');
         $table->integer('filter_by_block_id')->default(0)->change();
     });
     $groupsController = DB::table('admin_controllers')->select('id')->where('controller', '=', 'groups')->first();
     DB::table('admin_actions')->insert(array(array('controller_id' => $groupsController->id, 'action' => 'edit', 'inherit' => 0, 'edit_based' => 0, 'name' => 'Edit Group Settings', 'about' => null, 'created_at' => $date, 'updated_at' => $date)));
     $lastInsertId = DB::getPdo()->lastInsertId();
     DB::table('user_roles_actions')->insert(array(array('role_id' => 2, 'action_id' => $lastInsertId, 'created_at' => $date, 'updated_at' => $date)));
 }
 public function getIndex()
 {
     $this->preload_menu_item_names();
     $menus = '';
     $menu_item_info = new \stdClass();
     $menu_item_info->permissions['delete'] = Auth::action('menus.delete');
     $menu_item_info->permissions['subpage'] = Auth::action('menus.save_levels');
     $menu_item_info->permissions['rename'] = Auth::action('menus.rename');
     foreach (Menu::all() as $menu) {
         $menu_items = $menu->items()->get();
         $menus_li = '';
         $menu_item_info->max_sublevel = $menu->max_sublevel;
         foreach ($menu_items as $menu_item) {
             if (isset($this->page_names[$menu_item->page_id])) {
                 $menu_item_info->custom_name = trim($menu_item->custom_name);
                 $menu_item_info->custom_name = !empty($menu_item_info->custom_name) ? ' (Custom Name: ' . $menu_item_info->custom_name . ')' : null;
                 $menu_item_info->name = $this->page_names[$menu_item->page_id];
                 $menu_item_info->id = $menu_item->id;
                 $menu_item_info->sub_levels = $menu_item->sub_levels;
                 $menus_li .= View::make('coaster::partials.menus.li', array('item' => $menu_item_info))->render();
             }
         }
         $menus .= View::make('coaster::partials.menus.ol', array('menus_li' => $menus_li, 'menu' => $menu, 'can_add_item' => Auth::action('menus.add')))->render();
     }
     $this->layoutData['content'] = View::make('coaster::pages.menus', array('menus' => $menus));
     $this->layoutData['modals'] = View::make('coaster::modals.menus.add_item', array('options' => Page::get_page_list()))->render() . View::make('coaster::modals.general.delete_item')->render() . View::make('coaster::modals.menus.edit_item')->render() . View::make('coaster::modals.menus.rename_item')->render();
 }
 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;
 }
示例#5
0
 /**
  * Populate select options with page names (also add no page option)
  * @param string $content
  * @return string
  */
 public function edit($content)
 {
     $parent = BlockSelectOption::where('block_id', '=', $this->_block->id)->where('option', '=', 'parent')->first();
     $parentPageId = !empty($parent) ? $parent->value : 0;
     $this->_editViewData['selectOptions'] = [0 => '-- No Page Selected --'] + Page::get_page_list(['parent' => $parentPageId]);
     return String_::edit($content);
 }
 function search(Request $request)
 {
     $q = $request->get('q');
     $searchEntity = $request->get('search_entity');
     $searchres = $searchEntity::adminSearch($q);
     if ($searchres->count() == 0) {
         return '<p>No items match your search.</p>';
     }
     return Page::getPageListView($searchres);
 }
示例#7
0
 /**
  * Edit link settings
  * @param string $content
  * @return string
  */
 public function edit($content)
 {
     $content = $this->_defaultData($content);
     $link = str_replace('internal://', '', $content['link'], $count);
     $content['link'] = $count > 0 ? '' : $content['link'];
     $this->_editViewData['targetOptions'] = [0 => 'Target: Same Tab', '_blank' => 'Target: New Tab'];
     $this->_editViewData['selectedPage'] = $count > 0 ? $link : 0;
     $this->_editViewData['pageList'] = [0 => 'Custom Link: '] + Page::get_page_list();
     return parent::edit($content);
 }
示例#8
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);
         }
     }
 }
示例#9
0
 /**
  * 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);
 }
示例#11
0
 /**
  * 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;
 }
示例#12
0
 /**
  * @param $blockId
  * @param $pageId
  * @return static|null
  */
 public static function getBlockOnPage($blockId, $pageId)
 {
     if ($page = Page::find($pageId)) {
         $blocksByCat = Template::template_blocks(config('coaster::frontend.theme'), $page->template);
     } else {
         $blocksByCat = Theme::theme_blocks(config('coaster::frontend.theme'));
     }
     foreach ($blocksByCat as $blocks) {
         foreach ($blocks as $block) {
             if ($block->id == $blockId) {
                 return static::find($blockId);
             }
         }
     }
     return null;
 }
示例#13
0
 public function publish($set_live = false, $ignore_auth = false)
 {
     $page_lang = PageLang::where('page_id', '=', $this->page_id)->where('language_id', '=', Language::current())->first();
     $page = Page::find($this->page_id);
     $publishingOn = config('coaster::admin.publishing') > 0 ? true : false;
     $haveAuth = $ignore_auth || ($publishingOn && Auth::action('pages.version-publish', ['page_id' => $this->page_id]) || !$publishingOn && Auth::action('pages.edit', ['page_id' => $this->page_id]));
     if (!empty($page_lang) && !empty($page) && $haveAuth) {
         $page_lang->live_version = $this->version_id;
         $page_lang->save();
         PageSearchData::updateText(strip_tags($page_lang->name), 0, $page->id);
         $page->template = $this->template;
         if ($set_live && $page->live == 0) {
             if (!empty($page->live_start) || !empty($page->live_end)) {
                 $page->live = 2;
             } else {
                 $page->live = 1;
             }
         }
         $page->save();
         return 1;
     }
     return 0;
 }
示例#14
0
 /**
  * Display form settings
  * Template selector should only should if custom template selected (otherwise deprecated)
  * @param string $postContent
  * @return string
  */
 public function edit($postContent)
 {
     $formData = $this->_defaultData($postContent);
     $formData->template = $formData->template == $this->_block->name ? 0 : $formData->template;
     $this->_editViewData['pageList'] = Page::get_page_list();
     $this->_editViewData['formTemplates'] = [0 => '-- Use view from template --'];
     $theme = Theme::find(config('coaster::frontend.theme'));
     if (!empty($theme)) {
         $forms = base_path('/resources/views/themes/' . $theme->theme . '/blocks/forms');
         if (is_dir($forms)) {
             foreach (scandir($forms) as $form) {
                 if (!is_dir($forms . DIRECTORY_SEPARATOR . $form)) {
                     $form_file = explode('.', $form);
                     if (!empty($form_file[0])) {
                         $this->_editViewData['formTemplates'][$form_file[0]] = $form_file[0] . (strpos(file_get_contents($forms . DIRECTORY_SEPARATOR . $form), 'captcha') ? ' (supports captcha)' : ' (does not support captcha)');
                     }
                 }
             }
         }
     }
     return parent::edit($formData);
 }
示例#15
0
 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 function postPages($role_id)
 {
     if (config('coaster::admin.advanced_permissions')) {
         $page_actions = AdminAction::where('controller_id', '=', 2)->where('inherit', '=', 0)->where('edit_based', '=', 0)->get();
         $actionIds = [];
         foreach ($page_actions as $action) {
             $actionIds[$action->action] = $action->id;
         }
         if (!config('coaster::admin.publishing')) {
             unset($actionIds['version-publish']);
         }
         $pages_permissions = Request::input('page');
         $this->_role_permissions = UserRole::find($role_id);
         // defaults
         $defaults = [];
         foreach ($actionIds as $action => $id) {
             $defaults[$id] = false;
         }
         foreach ($this->_role_permissions->actions as $action) {
             if (array_key_exists($action->id, $defaults)) {
                 $defaults[$action->id] = 1;
             }
         }
         // existing
         $existing = [];
         foreach ($this->_role_permissions->page_actions as $page_permission) {
             if (!isset($existing[$page_permission->pivot->page_id])) {
                 $existing[$page_permission->pivot->page_id] = [];
             }
             $existing[$page_permission->pivot->page_id][$page_permission->pivot->action_id] = $page_permission->pivot->access;
         }
         // save updates
         $pages = Page::where('parent', '>=', '0')->get();
         foreach ($pages as $page) {
             foreach ($actionIds as $action => $action_id) {
                 // get value entered
                 if (isset($pages_permissions[$page->id][$action])) {
                     $value = 'allow';
                 } else {
                     $value = 'deny';
                 }
                 // check if update is required
                 if (isset($existing[$page->id][$action_id])) {
                     if ($defaults[$action_id] && $value == 'allow' || !$defaults[$action_id] && $value == 'deny') {
                         // remove existing
                         $this->_role_permissions->page_actions()->newPivotStatementForId($page->id)->whereActionId($action_id)->delete();
                         if ($page->group_container > 0) {
                             $group = PageGroup::find($page->group_container);
                             foreach ($group->pages as $group_page) {
                                 $this->_role_permissions->page_actions()->newPivotStatementForId($group_page->id)->whereActionId($action_id)->delete();
                             }
                         }
                     } elseif ($existing[$page->id][$action_id] != $value) {
                         // update existing
                         $this->_role_permissions->page_actions()->newPivotStatementForId($page->id)->whereActionId($action_id)->update(['access' => $value]);
                         if ($page->group_container > 0) {
                             $group = PageGroup::find($page->group_container);
                             foreach ($group->pages as $group_page) {
                                 $this->_role_permissions->page_actions()->newPivotStatementForId($group_page->id)->whereActionId($action_id)->update(['access' => $value]);
                             }
                         }
                     }
                 } elseif (!$defaults[$action_id] && $value == 'allow' || $defaults[$action_id] && $value == 'deny') {
                     // add new page action
                     $this->_role_permissions->page_actions()->attach($page->id, ['action_id' => $action_id, 'access' => $value]);
                     if ($page->group_container > 0) {
                         $group = PageGroup::find($page->group_container);
                         foreach ($group->pages as $group_page) {
                             $this->_role_permissions->page_actions()->attach($group_page->id, ['action_id' => $action_id, 'access' => $value]);
                         }
                     }
                 }
             }
         }
         $this->addAlert('success', 'Page Permissions Updated');
     }
     $this->getPages($role_id);
 }
示例#17
0
 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();
     }
 }
示例#18
0
 /**
  * @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 getIndex()
 {
     $database_structure = $this->_db_messages();
     $search_data = PageSearchData::orderBy('updated_at', 'asc')->first();
     if (!empty($search_data)) {
         $last_indexed_search = DateTimeHelper::display($search_data->updated_at);
     } else {
         $last_indexed_search = false;
     }
     $update = Auth::action('system.update');
     if ($update) {
         $settings = Setting::where('hidden', '=', '0')->orWhere('editable', '=', 1)->get();
     } else {
         $settings = Setting::where('hidden', '=', '0')->get();
     }
     foreach ($settings as $k => $setting) {
         if (!$update) {
             $settings[$k]->editable = 0;
         }
         $note = '';
         switch ($setting->name) {
             case 'frontend.language':
                 $custom = new \stdClass();
                 $custom->selected = $setting->value;
                 $custom->options = Language::selectArray();
                 break;
             case 'frontend.theme':
                 $custom = new \stdClass();
                 $custom->selected = $setting->value;
                 $custom->options = Theme::selectArray();
                 break;
             case 'admin.default_template':
                 $custom = new \stdClass();
                 $custom->selected = $setting->value;
                 $custom->options = Theme::get_template_list($setting->value);
                 break;
             case 'frontend.language_fallback':
             case 'frontend.strong_tags':
             case 'admin.advanced_permissions':
             case 'admin.publishing':
                 $custom = new \stdClass();
                 $custom->selected = $setting->value;
                 $custom->options = [1 => 'On', 0 => 'Off'];
                 break;
             case 'admin.title_block':
                 $custom = new \stdClass();
                 $custom->selected = $setting->value;
                 $custom->options = Block::nameToNameArray();
                 break;
             case 'site.pages':
                 $total_pages = Page::get_total();
                 $note = 'set to 0 for no limit - currently ' . $total_pages . ' normal pages in use';
                 break;
             case 'site.groups':
                 $total_pages = Page::get_total(true);
                 $note = 'set to 0 for no limit on group pages - currently ' . $total_pages . ' pages in use';
                 break;
             case 'site.secure_folders':
                 $note = 'list of comma separated folders, will copy files to secure folders and vice versa on update';
                 break;
             default:
                 $custom = null;
         }
         if (empty($custom)) {
             $settings[$k]->value = $setting->value;
         } else {
             $settings[$k]->value = $custom;
         }
         $settings[$k]->note = !empty($note) ? $note : null;
         $settings[$k]->name = str_replace('.', $this->dot_replace, $setting->name);
     }
     $upgrade = new \stdClass();
     $upgrade->from = config('coaster::site.version');
     $upgrade->to = Setting::latestTag();
     $upgrade->required = version_compare(config('coaster::site.version'), Setting::latestTag(), '<');
     $this->layoutData['content'] = View::make('coaster::pages.system', array('database_structure' => $database_structure, 'last_indexed_search' => $last_indexed_search, 'site_details' => $settings, 'can_index_search' => Auth::action('system.search'), 'can_validate' => Auth::action('system.validate-db'), 'can_upgrade' => Auth::action('system.upgrade'), 'upgrade' => $upgrade));
 }
示例#20
0
 /**
  *
  */
 protected static function _preLoad()
 {
     if (!self::$_preLoaded) {
         $topLevelPages = Page::getChildPages(0);
         self::_loadSubPaths($topLevelPages);
         $loadedIds = [];
         foreach (self::$_preLoaded as $pageId => $pagePathData) {
             if ($pagePathData->groupContainers) {
                 uasort($pagePathData->groupContainers, function ($a, $b) {
                     if ($a['canonical']) {
                         return -1;
                     }
                     if ($b['canonical']) {
                         return 1;
                     }
                     if ($a['priority'] == $b['priority']) {
                         if ($a['url'] == $b['url']) {
                             return 0;
                         }
                         return $a['url'] < $b['url'] ? -1 : 1;
                     }
                     return $a['priority'] > $b['priority'] ? -1 : 1;
                 });
                 reset($pagePathData->groupContainers);
                 $groupPath = current($pagePathData->groupContainers);
                 if ($groupPath['canonical'] || $groupPath['priority'] > 100 || is_null($pagePathData->fullUrl)) {
                     $pagePathData->fullName = $groupPath['name'] . $pagePathData->separator . $pagePathData->name;
                     $pagePathData->fullUrl = rtrim($groupPath['url'], '/') . '/' . $pagePathData->url;
                 }
             }
             $loadedIds[] = $pageId;
         }
         foreach (Page::preloadArray() as $pageId => $page) {
             if (!in_array($pageId, $loadedIds)) {
                 self::_getById($pageId);
             }
         }
     }
 }
 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(' &raquo; '));
     $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);
 }
示例#22
0
 /**
  * @param string $path
  * @param Page $parentPage
  * @return bool
  */
 protected function _isSearchPage($path, Page $parentPage)
 {
     if ($path == 'search' || $parentPage->pageLang() && $parentPage->pageLang()->url == 'search') {
         return true;
     } else {
         return false;
     }
 }
示例#23
0
 /**
  * @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 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]);
 }