/** * Return number of children, optionally with conditions * * Use this over $page->numChildren property when you want to specify a selector or when you want the result to * include only visible children. See the options for the $selector argument. * * @param Page $page * @param bool|string|int $selector * When not specified, result includes all children without conditions, same as $page->numChildren property. * When a string, a selector string is assumed and quantity will be counted based on selector. * When boolean true, number includes only visible children (excludes unpublished, hidden, no-access, etc.) * When boolean false, number includes all children without conditions, including unpublished, hidden, no-access, etc. * When integer 1 number includes viewable children (as opposed to visible, viewable includes hidden pages + it also includes unpublished pages if user has page-edit permission). * @return int Number of children * */ public function numChildren(Page $page, $selector = null) { if (is_bool($selector)) { // onlyVisible takes the place of selector $onlyVisible = $selector; if (!$onlyVisible) { return $page->get('numChildren'); } return $page->wire('pages')->count("parent_id={$page->id}"); } else { if ($selector === 1) { // viewable pages only $numChildren = $page->get('numChildren'); if (!$numChildren) { return 0; } if ($page->wire('user')->isSuperuser()) { return $numChildren; } if ($page->wire('user')->hasPermission('page-edit')) { return $page->wire('pages')->count("parent_id={$page->id}, include=unpublished"); } return $page->wire('pages')->count("parent_id={$page->id}, include=hidden"); } else { if (empty($selector) || !is_string($selector)) { return $page->get('numChildren'); } else { return $page->wire('pages')->count("parent_id={$page->id}, {$selector}"); } } } }
function getPage() { $data = array(); // if there is no path, load the index if (empty($this->data['path'])) { $page = new Page(1); } else { $page = new Page(); $page->get_page_from_path($this->data['path']); } // see if we have found a page if ($page->get('id')) { // store the information of the page /* $data['id'] = $this->data['id'] = $page->get('id'); $data['title'] = stripslashes( $page->get('title') ); $data['content'] = stripslashes( $page->get('content') ); $data['tags'] = stripslashes( $page->get('tags') ); $data['date'] = strtotime( stripslashes( $page->get('date') ) ); */ $data = $page->getAll(); // check if the page has been classified as a category $this->category = strpos($data['tags'], "category") > -1 ? true : false; $data['path'] = $this->data['path']; //$data['view'] = getPath('views/main/body.php'); $this->data['body'][] = $data; // FIX #38: copy data of "static" pages in a separate array for easy access $this->data['_page'] = $data; $this->data['template'] = stripslashes($page->get('template')); return true; } else { return false; } }
/** * Ensure that every user loaded has at least the 'guest' role * */ protected function loaded(Page $page) { static $guestID = null; if (is_null($guestID)) { $guestID = $this->wire('config')->guestUserRolePageID; } $roles = $page->get('roles'); if (!$roles->has("id={$guestID}")) { $page->get('roles')->add($this->wire('roles')->getGuestRole()); } }
/** * @test */ public function testGet() { $page = Page::get("hello"); $page2 = Page::get(2); $this->assertEquals(2, $page2->identifier()); $this->assertEquals("hello", $page->title); }
public function removeInitialPages() { if ($aboutus = Page::get()->filter(['Title' => "About us"])->first()) { $contactus = Page::get()->filter(['Title' => "Contact us"])->first(); $this->deleteAll([$aboutus, $contactus]); } }
public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeFieldFromTab('Root', 'Pages'); $fields->removeFieldsFromTab('Root.Main', array('SortOrder', 'showBlockbyClass', 'shownInClass', 'MemberVisibility')); $fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title'); $memberGroups = Group::get(); $sourcemap = $memberGroups->map('Code', 'Title'); $source = array('anonymous' => 'Anonymous visitors'); foreach ($sourcemap as $mapping => $key) { $source[$mapping] = $key; } $memberVisibility = new CheckboxSetField($name = "MemberVisibility", $title = "Show block for specific groups", $source); $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.'); $availabelClasses = $this->availableClasses(); $inClass = new CheckboxSetField($name = "shownInClass", $title = "Show block for specific content types", $availabelClasses); $filterSelector = OptionsetField::create('showBlockbyClass', 'Choose filter set', array('0' => 'by page', '1' => 'by page/data type'))->setDescription('<p><br /><strong>by page</strong>: block will be displayed in the selected page(s)<br /><strong>by page/data type</strong>: block will be displayed on the pages created with the particular page/data type. e.g. is <strong>"InternalPage"</strong> is picked, the block will be displayed, and will ONLY be displayed on all <strong>Internal Pages</strong></p>'); $availablePages = Page::get()->exclude('ClassName', array('ErrorPage', 'RedirectorPage', 'VirtualPage')); $pageSelector = new CheckboxSetField($name = "Pages", $title = "Show on Page(s)", $availablePages->map('ID', 'Title')); if ($this->canConfigPageAndType(Member::currentUser())) { $fields->addFieldsToTab('Root.VisibilitySettings', array($filterSelector, $pageSelector, $inClass)); } if ($this->canConfigMemberVisibility(Member::currentUser())) { $fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility); } if (!$fields->fieldByName('Options')) { $fields->insertBefore($right = RightSidebar::create('Options'), 'Root'); } $fields->addFieldsToTab('Options', array(CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'), CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper'))); return $fields; }
public function setUp() { parent::setUp(); Translatable::disable_locale_filter(); //Publish all english pages $pages = Page::get()->filter('Locale', 'en_US'); foreach ($pages as $page) { $page->publish('Stage', 'Live'); } //Rewrite the french translation groups and publish french pages $pagesFR = Page::get()->filter('Locale', 'fr_FR'); foreach ($pagesFR as $index => $page) { $page->addTranslationGroup($pages->offsetGet($index)->ID, true); $page->publish('Stage', 'Live'); } Translatable::enable_locale_filter(); $this->origLocaleRoutingEnabled = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL'); Config::inst()->update('MultilingualRootURLController', 'UseLocaleURL', false); $this->origDashLocaleEnabled = Config::inst()->get('MultilingualRootURLController', 'UseDashLocale'); Config::inst()->update('MultilingualRootURLController', 'UseDashLocale', false); $this->origAcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE']; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.5'; $this->origCookieLocale = Cookie::get('language'); Cookie::force_expiry('language'); Cookie::set('language', 'en'); $this->origCurrentLocale = Translatable::get_current_locale(); Translatable::set_current_locale('en_US'); $this->origLocale = Translatable::default_locale(); Translatable::set_default_locale('en_US'); $this->origi18nLocale = i18n::get_locale(); i18n::set_locale('en_US'); $this->origAllowedLocales = Translatable::get_allowed_locales(); Translatable::set_allowed_locales(array('en_US', 'fr_FR')); MultilingualRootURLController::reset(); }
public function requireDefaultRecords() { parent::requireDefaultRecords(); if ($this->config()->get("auto_include")) { $check = TemplateOverviewPage::get()->First(); if (!$check) { $page = new TemplateOverviewPage(); $page->ShowInMenus = 0; $page->ShowInSearch = 0; $page->Title = "Templates overview"; $page->PageTitle = "Templates overview"; $page->Sort = 99998; $page->URLSegment = "templates"; $parent = Page::get()->filter(array("URLSegment" => $this->config()->get("parent_url_segment")))->First(); if ($parent) { $page->ParentID = $parent->ID; } $page->writeToStage('Stage'); $page->publish('Stage', 'Live'); $page->URLSegment = "templates"; $page->writeToStage('Stage'); $page->publish('Stage', 'Live'); DB::alteration_message("TemplateOverviewPage", "created"); } } }
/** * @param SS_HTTPRequest $request */ public function run($request) { /** ========================================= * @var Page $page ===========================================*/ if (class_exists('Page')) { if (Page::has_extension('TwitterCardMeta')) { // Should we overwrite? $overwrite = $request->getVar('overwrite') ? true : false; echo sprintf('Overwrite is %s', $overwrite ? 'enabled' : 'disabled') . $this->eol . $this->eol; $pages = Page::get(); foreach ($pages as $page) { $id = $page->ID; echo $this->hr; echo 'Updating page: ' . $page->Title . $this->eol; foreach ($this->fields_to_update as $fieldName) { $oldData = DB::query("SELECT {$fieldName} FROM Page WHERE ID = {$id}")->column($fieldName); $newData = DB::query("SELECT {$fieldName} FROM SiteTree WHERE ID = {$id}")->column($fieldName); if (!empty($oldData)) { // If new data has been saved and we don't want to overwrite, exit the loop if (!empty($newData) && $overwrite === false) { continue; } DB::query("UPDATE SiteTree SET {$fieldName} = '{$oldData[0]}' WHERE ID = {$id}"); } else { echo 'Field "' . $fieldName . '" empty.' . $this->eol; } } } } } }
function Siblings() { if (!$this->ParentID) { $this->ParentID = 0; } return Page::get()->filter(array("ShowInMenus" => 1, "ParentID" => $this->ParentID)); }
public function __construct($name, $title = null, $value = null, $form = null) { // Create a callable function that returns an array of options for the DependentDropdownField. // When the value of the field it depends on changes, this function is called passing the // updated value as the first parameter ($val) $getanchors = function ($page_id) { // Copied from HtmlEditorField_Toolbar::getanchors() if (($page = Page::get()->byID($page_id)) && !empty($page)) { // if (!$page->canView()) { /* ERROR? */ } // Similar to the regex found in HtmlEditorField.js / getAnchors method. if (preg_match_all("/\\s(name|id)=\"([^\"]+?)\"|\\s(name|id)='([^']+?)'/im", $page->Content, $matches)) { // var_dump(array_filter(array_merge($matches[2], $matches[4]))); $anchors = array_filter(array_merge($matches[2], $matches[4])); return array_combine($anchors, $anchors); } } }; // naming with underscores to prevent values from actually being saved somewhere $this->fieldCustomURL = new TextField("{$name}[CustomURL]", '', '', 300, $form); $this->fieldShortcode = new TextField("{$name}[Shortcode]", '', '', 300, $form); $this->fieldPageID = new TreeDropdownField("{$name}[PageID]", '', 'SiteTree', 'ID', 'MenuTitle'); $this->fieldPageID->setForm($form); // $this->fieldPageAnchor = new DropdownField("{$name}[PageAnchor]", 'Anchor:',array(), '', $form); // The DependentDropdownField, setting the source as the callable function // and setting the field it depends on to the appropriate field $this->fieldPageAnchor = DependentDropdownField::create("{$name}[PageAnchor]", 'Text-anchor:', $getanchors, $form)->setEmptyString('Page anchor: (none)')->setDepends($this->fieldPageID); $this->fieldFileID = new TreeDropdownField("{$name}[FileID]", '', 'File', 'ID', 'Name'); $this->fieldFileID->addExtraClass('filetree'); $this->fieldFileID->setForm($form); $this->fieldTitle = new TextField("{$name}[Title]", 'Title: ', '', 300, $form); $this->fieldLinkmode = new DropdownField("{$name}[Linkmode]", 'Type: ', array('Page' => 'Page', 'URL' => 'URL', 'File' => 'File', 'Email' => 'Email', 'Shortcode' => 'Shortcode'), '', $form); $this->fieldLinkmode->addExtraClass('LinkModePicker'); parent::__construct($name, $title, $value, $form); }
function run($request) { $data = (require_once __DIR__ . '/../../../BlockFiller.php'); if ($data) { foreach (Block::get() as $block) { $block->delete(); } } //Loop through all blocks, defined in root/BlockFiller.php foreach ($data as $key => $blockData) { $block = Block::create($blockData); //Find page by classname, so it can link block to page $page = Page::get()->filter(['ClassName' => $blockData['ClassName']])->first(); //If page is found, write block if (isset($page->ID)) { $block->PageID = $page->ID; $block->write(); //Loop through all blocks translations, which are defined in block section under 'trans' foreach ($blockData['trans'] as $key => $translation) { $blockTrans = BlockTranslation::create($translation); $blockTrans->BlockID = $block->ID; $blockTrans->write(); } var_dump($block->Title); } } }
/** * Return number of children, optionally with conditions * * Use this over $page->numChildren property when you want to specify a selector or when you want the result to * include only visible children. See the options for the $selector argument. * * @param Page $page * @param bool|string $selector * When not specified, result includes all children without conditions, same as $page->numChildren property. * When a string, a selector string is assumed and quantity will be counted based on selector. * When boolean true, number includes only visible children (excludes unpublished, hidden, no-access, etc.) * When boolean false, number includes all children without conditions, including unpublished, hidden, no-access, etc. * @return int Number of children * */ public function numChildren(Page $page, $selector = null) { if (is_bool($selector)) { // onlyVisible takes the place of selector $onlyVisible = $selector; if (!$onlyVisible) { return $page->get('numChildren'); } return $page->children('limit=2')->getTotal(); } else { if (empty($selector) || !is_string($selector)) { return $page->get('numChildren'); } else { return wire('pages')->count("parent_id={$page->id}, {$selector}"); } } }
protected function initFormField() { if ($this->getSetting('PageTypeName')) { $pages = Page::get($this->getSetting('PageTypeName'))->map('ID', 'Title'); return new DropdownField($this->Name, $this->Title, $pages); } return false; }
function syncCommentsAction() { $id = (int) $_REQUEST['ID']; $page = Page::get()->byID($id); DisqusSync::sync($page->disqusIdentifier()); $this->owner->response->addHeader('X-Status', sprintf('Synced successfuly')); return; }
public function test_calc_base_directory_for_object() { //Page should be "pages" $page = Page::get()->first(); $this->assertEquals('pages', UploadDirRules::calc_base_directory_for_object($page)); //SiteConfig should be "site" $sc = SiteConfig::current_site_config(); $this->assertEquals('site', UploadDirRules::calc_base_directory_for_object($sc)); }
public function GetRootPages() { $controllers = new ArrayList(); $pageModels = Page::get()->filter(array("ParentId" => 0, "ID:not" => AllInOneHelper::excludedPageIds())); foreach ($pageModels as $model) { $controllers->push(ModelAsController::controller_for($model)); } return $controllers; }
/** * Runs the permissiion checks, and setup of the controller view. */ public function index() { if (!Director::isDev() && !Permission::check('ADMIN')) { return Security::permissionFailure(); } $page = Page::get()->first(); $controller = ModelAsController::controller_for($page); $controller->init(); return $controller->customise($this->getStyleGuideData())->renderWith(array('SimpleStyleguideController', 'Page')); }
/** * Get a value from the language page (intercepting translator and isDefault) * */ public function get($key) { if ($key == 'translator') { return $this->translator(); } if ($key == 'isDefault' || $key == 'isDefaultLanguage') { return $this->isDefaultLanguage; } return parent::get($key); }
public static function build($object_family_name) { switch ($object_family_name) { case "page": if (func_num_args() == 2) { return Page::get(func_get_arg(1)); } else { return new Page("", ""); } } }
/** * Check to show or hide block builder menu * * @return true */ public function ShowBlockBuilder() { $id = $this->owner->currentPageID(); if ($id) { $page = Page::get()->byID($id); if ($page) { if (!$page->canShowBlockBuilder() || in_array($page->ClassName, self::$disallow_modules)) { return false; } } } return true; }
/** * Provide pages which have * * @return \DataList */ public function provideGridListItems($parameters = []) { if ($this()->{self::SingleFieldName}) { if ($this()->hasExtension(HasGridListFilters::class_name())) { $filterIDs = $this->filterIDs(); // name of the field on Pages $filterField = HasGridListFilters::relationship_name('ID'); $pages = \Page::get()->filter([$filterField => $filterIDs]); // debug help $count = $pages->count(); return $pages; } } }
/** * @param SS_HTTPRequest $request */ public function run($request) { $compatibility = ContentReviewCompatability::start(); $now = class_exists("SS_Datetime") ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate(); // First grab all the pages with a custom setting $pages = Page::get("Page")->where("\"SiteTree\".\"NextReviewDate\" <= '{$now}'"); $overduePages = $this->getOverduePagesForOwners($pages); // Lets send one email to one owner with all the pages in there instead of no of pages // of emails. foreach ($overduePages as $memberID => $pages) { $this->notifyOwner($memberID, $pages); } ContentReviewCompatability::done($compatibility); }
public function tearDown() { parent::tearDown(); if (file_exists(ASSETS_PATH . "/{$this->sitemap}")) { unlink(ASSETS_PATH . "/{$this->sitemap}"); } $pages = Page::get(); foreach ($pages as $page) { $page->delete(); } $pages = SiteMapPage::get(); foreach ($pages as $page) { $page->delete(); } }
public function getanchors() { $id = (int) $this->getRequest()->getVar('PageID'); $anchors = array(); if (($page = Page::get()->byID($id)) && !empty($page)) { if (!$page->canView()) { throw new SS_HTTPResponse_Exception(_t('HtmlEditorField.ANCHORSCANNOTACCESSPAGE', 'You are not permitted to access the content of the target page.'), 403); } // Chris Bolt $anchors = self::getPageAnchors($page); // End Chris Bolt } else { throw new SS_HTTPResponse_Exception(_t('HtmlEditorField.ANCHORSPAGENOTFOUND', 'Target page not found.'), 404); } return json_encode($anchors); }
/** * @param string $direction * @return ArrayData|bool */ public function DirectionLink($direction = 'next') { switch ($direction) { case 'previous': $sortDirection = 'Sort:LessThan'; $sort = 'Sort DESC'; break; default: $sortDirection = 'Sort:GreaterThan'; $sort = 'Sort ASC'; } /** @var Page $page */ $page = Page::get()->filter(array('ParentID' => $this->owner->ParentID, $sortDirection => $this->owner->Sort))->sort($sort)->first(); if (isset($page)) { return new ArrayData(array('Title' => $page->Title, 'MenuTitle' => $page->MenuTitle, 'Link' => $page->Link())); } return false; }
public function blocks(\SS_HTTPRequest $request) { $page = null; /** @var \Page|HasBlocks $page */ if ($pageID = $request->param('PageID')) { $page = \Page::get()->byID($pageID); } else { if ($path = Application::path_for_request($request)) { $page = Application::page_for_path($path); } } if ($page) { if ($page->hasExtension(\Modular\Relationships\HasBlocks::class_name())) { \Director::set_current_page($page); /** @var \GridListBlock $gridList */ if ($gridListBlock = $page->Blocks()->find('ClassName', 'GridListBlock')) { return $gridListBlock->renderWith("GridListItems"); } } } }
/** * ModuleHolder Page Link. * * @return string $modulePageLink */ public function Link() { $extensionPageLink = ""; $id = $this->ID; if ($this->URLSegment) { $id = $this->URLSegment; } if ($this->Type == 'Module') { $page = Page::get()->filter('ClassName', 'ModuleHolderPage')->first(); $extensionPageLink = $page ? $page->Link("show/{$id}") : ""; } if ($this->Type == 'Theme') { $page = Page::get()->filter('ClassName', 'ThemeHolderPage')->first(); $extensionPageLink = $page ? $page->Link("show/{$id}") : ""; } if ($this->Type == 'Widget') { $page = Page::get()->filter('ClassName', 'WidgetHolderPage')->first(); $extensionPageLink = $page ? $page->Link("show/{$id}") : ""; } return $extensionPageLink; }
public function run($request) { // Clean up $task = new CleanupGeneratedPDF(); $task->run(null); // Generate $pages = Page::get()->filterByCallback(function ($page) { return $page->hasExtension('AutoGeneratePDF'); }); if ($pages) { foreach ($pages as $page) { $controller = singleton($page->ClassName . '_Controller'); if ($controller && $controller->hasExtension('GeneratePDF_Controller')) { $success = $controller->generatePDF($page); if ($success) { echo 'Generating PDF for ' . $page->Title . PHP_EOL; } } } } }
public function show($id, $language = null) { if ($language == null) { $language = CoOrg::getLanguage(); } else { $this->viewingTranslation = true; } $page = Page::get($id, $language); if ($page != null) { $this->page = $page; $this->render('show'); } else { $this->error(t('Page not found')); $this->notFound(); } }