public function postIndex()
 {
     // update blocks
     AdminLog::new_log('Updated Site-wide Content');
     $versionId = PageVersion::add_new(0)->version_id;
     Block::submit(0, $versionId);
     $this->addAlert('success', 'Site-wide Content Updated');
     return \redirect()->route('coaster.admin.blocks');
 }
 public static function checkPageVersionIds()
 {
     $now = (new Carbon())->format('Y-m-d H:i:s');
     $pageVersionSchedules = self::where('live_from', '<=', $now)->orderBy('live_from')->get();
     $newVersions = [];
     if (!$pageVersionSchedules->isEmpty()) {
         $pageVersionSchedulesArr = [];
         foreach ($pageVersionSchedules as $pageVersionSchedule) {
             $pageVersionSchedulesArr[$pageVersionSchedule->page_version_id] = $pageVersionSchedule;
         }
         $pageVersionIdToPageVersion = [];
         $pageVersions = PageVersion::whereIn('id', array_keys($pageVersionSchedulesArr))->get();
         foreach ($pageVersions as $pageVersion) {
             $pageVersionIdToPageVersion[$pageVersion->id] = $pageVersion;
         }
         $pages = [];
         foreach ($pageVersionSchedulesArr as $pageVersionId => $pageVersionSchedule) {
             if (!isset($pageVersionIdToPageVersion[$pageVersionId])) {
                 continue;
             }
             if (!isset($pages[$pageVersionIdToPageVersion[$pageVersionId]->page_id])) {
                 $pages[$pageVersionIdToPageVersion[$pageVersionId]->page_id] = [];
             }
             $pages[$pageVersionIdToPageVersion[$pageVersionId]->page_id][$pageVersionId] = $pageVersionSchedule;
         }
         foreach ($pages as $page_id => $pageVersionSchedules) {
             self::$_latestPublish = ['time' => '', 'page_version_id' => ''];
             foreach ($pageVersionSchedules as $pageVersionSchedule) {
                 $pageVersionSchedule->delete(true);
             }
             if (self::$_latestPublish['page_version_id']) {
                 $pageVersionToPublish = $pageVersionIdToPageVersion[self::$_latestPublish['page_version_id']];
                 $pageVersionToPublish->publish(false, true);
                 $newVersions[$page_id] = $pageVersionToPublish->version_id;
             }
         }
     }
     return $newVersions;
 }
예제 #3
0
 /**
  * @param string $searchText
  * @return bool
  */
 public function publishContent($searchText)
 {
     if ($this->_pageId) {
         if (!$this->_repeaterId) {
             PageSearchData::updateText($searchText, $this->id, $this->_pageId);
         }
         $pageVersion = PageVersion::getLiveVersion($this->_pageId);
         if ($this->_versionId != $pageVersion->version_id) {
             return $pageVersion->publish();
         }
     }
     return false;
 }
예제 #4
0
 public function postVersionPublish($pageId)
 {
     $version_id = Request::input('version_id');
     if (!empty($pageId) && !empty($version_id)) {
         $page_version = PageVersion::where('page_id', '=', $pageId)->where('version_id', '=', $version_id)->first();
         if (!empty($page_version)) {
             return $page_version->publish();
         }
     }
     return 0;
 }
예제 #5
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();
     }
 }
예제 #6
0
 /**
  * Load current page status.
  * Is live, Is preview, External Template
  */
 protected function _loadPageStatus()
 {
     $lowestLevelPage = count($this->pageLevels) > 0 ? end($this->pageLevels) : null;
     if ($lowestLevelPage) {
         /** @var Page $lowestLevelPage */
         $this->isLive = $lowestLevelPage->is_live();
         if (!$this->is404) {
             if ($previewKey = Request::input('preview')) {
                 $this->previewVersion = PageVersion::where('page_id', '=', $lowestLevelPage->id)->where('preview_key', '=', $previewKey)->first() ?: null;
             }
         }
     }
     if ($externalTemplate = Request::get('external')) {
         $this->externalTemplate = $externalTemplate;
     }
 }
예제 #7
0
 /**
  * Saves page data as new page (will update page groups)
  * @param array $pagePost
  * @param array $pageLangPost
  * @param array $pageGroupsPost
  * @param array $pageInfoOther
  * @return Page|false
  */
 public function saveDuplicateFromPostData($pagePost, $pageLangPost, $pageGroupsPost, $pageInfoOther = [])
 {
     /** @var Page $duplicatePage */
     $duplicatePage = $this->replicate();
     $duplicatePage->setRelations([]);
     $pageLangPost['name'] = preg_replace('/\\s+Duplicate$/', '', $pageLangPost['name']) . ' Duplicate';
     $pageLangPost['url'] = preg_replace('/--v\\w+$/', '', $pageLangPost['url']) . '--v' . base_convert(microtime(true), 10, 36);
     $pageVersion = PageVersion::prepareNew();
     if ($duplicatePage->savePostData($pageVersion, $pagePost, $pageLangPost, $pageGroupsPost, $pageInfoOther)) {
         // duplicate role actions from original page
         foreach (UserRole::all() as $role) {
             /** @var \Illuminate\Database\Eloquent\Relations\BelongsToMany $pageActionsRelation */
             $pageActionsRelation = $role->page_actions();
             /** @var Collection $pageActions */
             $pageActions = $pageActionsRelation->where('page_id', '=', $duplicatePage->id)->get();
             if (!$pageActions->isEmpty()) {
                 foreach ($pageActions as $pageAction) {
                     $pageActionsRelation->attach($duplicatePage->id, ['action_id' => $pageAction->pivot->action_id, 'access' => $pageAction->pivot->access]);
                 }
             }
         }
         return $duplicatePage;
     } else {
         return false;
     }
 }
 public static function add($page_id, $version_id, $note = null)
 {
     $page_version = PageVersion::where('page_id', '=', $page_id)->where('version_id', '=', $version_id)->first();
     if ($page_version) {
         $page_requests = PagePublishRequests::where('status', '=', 'awaiting')->where('user_id', '=', Auth::user()->id)->get();
         if (!$page_requests->isEmpty()) {
             $page_version_ids = array();
             foreach ($page_requests as $page_request) {
                 $page_version_ids[] = $page_request->page_version_id;
             }
             $previous_requested_page_version = PageVersion::where('page_id', '=', $page_id)->whereIn('id', $page_version_ids)->first();
         }
         if (!empty($previous_requested_page_version)) {
             $page_request = PagePublishRequests::where('page_version_id', '=', $previous_requested_page_version->id)->where('user_id', '=', Auth::user()->id)->where('status', '=', 'awaiting')->first();
             if ($previous_requested_page_version->id == $page_version->id) {
                 $page_request->note = $note;
                 $page_request->save();
                 return 1;
             } else {
                 $page_request->status = 'cancelled';
                 $page_request->save();
             }
         }
         $new_request = new self();
         $new_request->page_version_id = $page_version->id;
         $new_request->status = 'awaiting';
         $new_request->user_id = Auth::user()->id;
         $new_request->mod_id = 0;
         $new_request->note = $note;
         $new_request->save();
         return 1;
     }
     return 0;
 }
예제 #9
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;
 }