/** * Display image link (target attribute appended to end or link if exists) * @param string $content * @param array $options * @return string */ public function display($content, $options = []) { $content = $this->_defaultData($content); $target = $content['target'] ? ' target=\\"' . $content['target'] . '"' : ''; $link = str_replace('internal://', '', $content['link'], $count); return ($count > 0 ? Path::getFullUrl($link) : $link) . $target; }
/** * 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); }
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; }
public static function getPageListView($listPages, $tree = false, $level = 1, $cat_url = '') { $listPages = is_array($listPages) ? collect($listPages) : $listPages; if (!$listPages->isEmpty()) { $pages_li = ''; foreach ($listPages as $page) { if (config('coaster::admin.advanced_permissions') && !Auth::action('pages', ['page_id' => $page->id])) { continue; } $permissions = []; $permissions['add'] = Auth::action('pages.add', ['page_id' => $page->id]) && $page->parent != -1; $permissions['edit'] = Auth::action('pages.edit', ['page_id' => $page->id]); $permissions['delete'] = Auth::action('pages.delete', ['page_id' => $page->id]); $permissions['group'] = Auth::action('groups.pages', ['page_id' => $page->id]); $permissions['galleries'] = Auth::action('gallery.edit', ['page_id' => $page->id]); $permissions['forms'] = Auth::action('forms.submissions', ['page_id' => $page->id]); $permissions['blog'] = Auth::action('system.wp_login'); $page_lang = PageLang::preload($page->id); $li_info = new \stdClass(); $li_info->leaf = ''; $li_info->altName = ''; if ($tree) { $li_info->preview_link = $cat_url . '/' . $page_lang->url; $li_info->preview_link = $li_info->preview_link == '//' ? '/' : $li_info->preview_link; $childPages = self::getChildPages($page->id); $li_info->leaf = self::getPageListView($childPages, true, $level + 1, $li_info->preview_link); } else { $li_info->preview_link = Path::getFullUrl($page->id); $li_info->altName = Path::getFullName($page->id); } $li_info->number_of_forms = Template::preload_blocks_of_type('form', $page->template); $li_info->number_of_galleries = Template::preload_blocks_of_type('gallery', $page->template); if (trim($page_lang->url, '/') == '' && $page->parent == 0 && $page->link == 0) { $permissions['add'] = false; } if ($page->group_container > 0) { $li_info->type = 'type_group'; $li_info->group = PageGroup::preload($page->group_container); $li_info->group = $li_info->group->exists ? $li_info->group : ''; } else { if ($page->link == 1) { $li_info->preview_link = $page_lang->url; $li_info->type = 'type_link'; } else { $li_info->type = 'type_normal'; } $li_info->group = ''; } if (trim($li_info->preview_link, '/') != '' && trim($li_info->preview_link, '/') == trim(config('coaster::blog.url'), '/')) { $li_info->blog = route('coaster.admin.system.wp-login'); } else { $li_info->blog = ''; } if (!$page->is_live()) { $li_info->type = 'type_hidden'; if ($page->link == 0) { if ($liveVersion = PageVersion::getLiveVersion($page->id)) { $li_info->preview_link .= '?preview=' . $liveVersion->preview_key; } } } $pages_li .= View::make('coaster::partials.pages.li', array('page' => $page, 'page_lang' => $page_lang, 'li_info' => $li_info, 'permissions' => $permissions))->render(); } return View::make('coaster::partials.pages.ol', array('pages_li' => $pages_li, 'level' => $level))->render(); } return null; }
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 string $direction * @return string */ public function categoryLink($direction = 'next') { if (!isset($this->_pageCategoryLinks)) { $this->_pageCategoryLinks = ['next' => '', 'prev' => '']; $parentPageId = $this->parentPageId(); if ($parentPageId) { $pages = Page::category_pages($parentPageId, true); if (count($pages) > 1) { foreach ($pages as $k => $page) { if ($page->id == $this->page->id) { $key = $k; break; } } if (isset($key)) { if (!empty($pages[$key + 1])) { $this->_pageCategoryLinks['next'] = Path::getFullUrl($pages[$key + 1]->id); } if (!empty($pages[$key - 1])) { $this->_pageCategoryLinks['prev'] = Path::getFullUrl($pages[$key - 1]->id); } } } } } return $this->_pageCategoryLinks[$direction]; }