function submitFeedback(array $data, Form $form) { // TRUE if the submission contains a link. Crude spam mitigation. $ContainsLink = strpos($data['Content'], "http://") !== false; if ($data['Content'] != NULL && !$ContainsLink) { $FeedbackSubmission = new FeedbackSubmission(); $form->saveInto($FeedbackSubmission); // Tie the URL of the current page to the feedback submission $page = Director::get_current_page(); $FeedbackSubmission->Page = $page->Link(); //$FeedbackSubmission->write(); //Send email alert about submission $Subject = "New Website Feedback Submission"; $email = EmailFactory::getInstance()->buildEmail(FEEDBACK_FORM_FROM_EMAIL, FEEDBACK_FORM_TO_EMAIL, $Subject); $email->setTemplate("FeedbackSubmissionEmail"); $email->populateTemplate($FeedbackSubmission); $email->send(); // Redirect back to the page with a success message $form->controller->setMessage('Success', 'Thanks for providing feedback to improve the OpenStack website!'); $form->controller->redirectBack(); } else { $form->controller->setMessage('Error', "Oops! It doesn't look like you provided any feedback. Please check the form and try again."); $form->controller->redirectBack(); } }
public function Menu($level = 1) { if ($level == 1) { $root_elements = new ArrayList($this->get_root_elements()); $result = $root_elements->filter(array("ShowInMenus" => 1)); } else { $dataID = Director::get_current_page()->ID; $site_map = $this->get_site_map(); if (isset($site_map[$dataID])) { $parent = $site_map[$dataID]; $stack = array($parent); if ($parent) { while ($parent = $parent->getParent()) { array_unshift($stack, $parent); } } if (isset($stack[$level - 2])) { $elements = new ArrayList($stack[$level - 2]->getAllChildren()); $result = $elements->filter(array("ShowInMenus" => 1)); } } } $visible = array(); // Remove all entries the can not be viewed by the current user // We might need to create a show in menu permission if (isset($result)) { foreach ($result as $page) { if ($page->canView()) { $visible[] = $page; } } } return new ArrayList($visible); }
public static function get_navbar_html($page = null) { // remove the protocol from the URL, otherwise we run into https/http issues $url = self::remove_protocol_from_url(self::get_toolbar_hostname()); $static = true; if (!$page instanceof SiteTree) { $page = Director::get_current_page(); $static = false; } // In some cases, controllers are bound to "mock" pages, like Security. In that case, // throw the "default section" as the current controller. if (!$page instanceof SiteTree || !$page->isInDB()) { $controller = ModelAsController::controller_for($page = SiteTree::get_by_link(Config::inst()->get('GlobalNav', 'default_section'))); } else { // Use controller_for to negotiate sub controllers, e.g. /showcase/listing/slug // (Controller::curr() would return the nested RequestHandler) $controller = ModelAsController::controller_for($page); } // Ensure staging links are not exported to the nav $origStage = Versioned::current_stage(); Versioned::reading_stage('Live'); $html = ViewableData::create()->customise(array('ToolbarHostname' => $url, 'Scope' => $controller, 'ActivePage' => $page, 'ActiveParent' => $page instanceof SiteTree && $page->Parent()->exists() ? $page->Parent() : $page, 'StaticRender' => $static, 'GoogleCustomSearchId' => Config::inst()->get('GlobalNav', 'google_search_id')))->renderWith('GlobalNavbar'); Versioned::reading_stage($origStage); return $html; }
function __construct($controller, $name, $poll) { if (!$poll) { user_error("The poll doesn't exist.", E_USER_ERROR); } $this->poll = $poll; $data = array(); foreach ($poll->Choices() as $choice) { $data[$choice->ID] = $choice->Title; } if ($poll->MultiChoice) { $choiceField = new CheckboxSetField('PollChoices', '', $data); } else { $choiceField = new OptionsetField('PollChoices', '', $data); } $fields = new FieldList($choiceField); if (PollForm::$show_results_link) { $showResultsURL = Director::get_current_page()->Link() . '?poll_results'; $showResultsLink = new LiteralField('ShowPollLink', '<a class="show-results" href="' . $showResultsURL . '">Show results</a>'); $fields->push($showResultsLink); } $actions = new FieldList(new FormAction('submitPoll', 'Submit', null, null, 'button')); $validator = new PollForm_Validator('PollChoices'); parent::__construct($controller, $name, $fields, $actions, $validator); }
function Dates() { Requirements::themedCSS('archivewidget'); $results = new DataObjectSet(); $container = BlogTree::current(); $ids = $container->BlogHolderIDs(); $stage = Versioned::current_stage(); $suffix = !$stage || $stage == 'Stage' ? "" : "_{$stage}"; $monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")'; $yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")'; $sqlResults = DB::query("\n\t\t\tSELECT DISTINCT CAST({$monthclause} AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", {$yearclause} AS \"Year\"\n\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\tORDER BY \"Year\" DESC, \"Month\" DESC;"); if ($this->ShowLastYears == 0) { $cutOffYear = 0; } else { $cutOffYear = (int) date("Y") - $this->ShowLastYears; } $years = array(); if (Director::get_current_page()->ClassName == 'BlogHolder') { $urlParams = Director::urlParams(); $yearParam = $urlParams['ID']; $monthParam = $urlParams['OtherID']; } else { $date = new DateTime(Director::get_current_page()->Date); $yearParam = $date->format("Y"); $monthParam = $date->format("m"); } if ($sqlResults) { foreach ($sqlResults as $sqlResult) { $isMonthDisplay = true; $year = $sqlResult['Year'] ? (int) $sqlResult['Year'] : date('Y'); $isMonthDisplay = $year > $cutOffYear; // $dateFormat = 'Month'; else $dateFormat = 'Year'; $monthVal = isset($sqlResult['Month']) ? (int) $sqlResult['Month'] : 1; $month = $isMonthDisplay ? $monthVal : 1; $date = DBField::create('Date', array('Day' => 1, 'Month' => $month, 'Year' => $year)); if ($isMonthDisplay) { $link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal); } else { $link = $container->Link('date') . '/' . $sqlResult['Year']; } if ($isMonthDisplay || !$isMonthDisplay && !in_array($year, $years)) { $years[] = $year; $current = false; $children = new DataObjectSet(); $LinkingMode = "link"; if ($isMonthDisplay && $yearParam == $year && $monthParam == $month || !$isMonthDisplay && $yearParam == $year) { $LinkingMode = "current"; $current = true; if ($this->ShowChildren && $isMonthDisplay) { $filter = $yearclause . ' = ' . $year . ' AND ' . $monthclause . ' = ' . $month; $children = DataObject::get('BlogEntry', $filter, "Date DESC"); } } $results->push(new ArrayData(array('Date' => $date, 'Year' => $year, 'Link' => $link, 'NoMonth' => !$isMonthDisplay, 'LinkingMode' => $LinkingMode, 'Children' => $children))); unset($children); } } } return $results; }
/** * Return the current pages default filter * * @return array */ public function provideGridListFilters() { $page = \Director::get_current_page(); if ($page instanceof \CMSMain) { $page = $page->currentPage(); } return $page->DefaultFilter(); }
/** * Return children of the current page * @return \DataList */ public function provideGridListItems() { if ($this()->{static::SingleFieldName}) { if ($page = \Director::get_current_page()) { return $page->Children(); } } }
/** * @param string $action * @return string */ public function Link($action = null) { $id = $this->block ? $this->block->ID : null; $segment = Controller::join_links('block', $id, $action); if ($page = Director::get_current_page()) { return $page->Link($segment); } return Controller::curr()->Link($segment); }
public function Layout() { $page = Director::get_current_page(); $member = Member::currentUser(); $access = Permission::checkMember($member, 'CMS_ACCESS'); $sectionType = get_called_class(); if ($this->Public || $access) { return $page->renderWith($this->Render()); } }
public function InSectionID($sectionNameID) { $page = Director::get_current_page(); while ($page) { if ($sectionNameID == $page->ID) { return true; } $page = $page->Parent; } return false; }
public static function get_navbar_html($page = null) { // remove the protocol from the URL, otherwise we run into https/http issues $url = self::remove_protocol_from_url(self::get_toolbar_hostname()); $static = true; if (!$page instanceof SiteTree) { $page = Director::get_current_page(); $static = false; } return ViewableData::create()->customise(array('ToolbarHostname' => $url, 'Pages' => SiteTree::get()->filter(array('ParentID' => 0, 'ShowInGlobalNav' => true)), 'ActivePage' => $page, 'ActiveParent' => $page instanceof SiteTree && $page->Parent()->exists() ? $page->Parent() : $page, 'StaticRender' => $static, 'GoogleCustomSearchId' => Config::inst()->get('GlobalNav', 'google_search_id')))->renderWith('GlobalNavbar'); }
function LoginForm() { if (self::$BadLoginURL) { $page = self::$BadLoginURL; } else { $page = Director::get_current_page()->URLSegment; } Session::set("BadLoginURL", Director::absoluteURL($page, true)); $controller = new UsernameOrEmailLoginWidget_Controller($this); $form = $controller->LoginForm(); $this->extend('updateLoginForm', $form); return $form; }
/** * Return the current pages config.gridlist_custom_filters if set or empty array. * @return array */ public function provideGridListFilters() { $page = \Director::get_current_page(); if ($page instanceof \CMSMain) { $page = $page->currentPage(); } $filters = new \ArrayList(); if ($customFilters = $page->config()->get('gridlist_custom_filters') ?: []) { foreach ($customFilters as $filter => $title) { $filters->push(new GridListFilter([Title::SingleFieldName => $title, GridListFilter::TagFieldName => $filter])); } } return $filters; }
public function setobj() { $page = Director::get_current_page(); $fields = ['FirstName', 'LastName', 'Greeting']; foreach ($fields as $item) { $data = $_POST[$item]; if (!isset($data)) { continue; } $page->{$item} = $data; } $page->write(); return $this->getobj(); }
/** * Make sure only the custom filters are provided. This needs to go after other filter providers. * * @param $filters */ public function constrainGridListFilters(&$filters, &$parameters = []) { $page = \Director::get_current_page(); if ($page instanceof \CMSMain) { $page = $page->currentPage(); } if ($customFilters = $page->config()->get('gridlist_custom_filters') ?: []) { $filters = new \ArrayList(); foreach ($customFilters as $tag => $title) { if (!($filter = GridListFilter::get()->filter(['ModelTag' => $tag])->first())) { $filter = new GridListFilter([Title::SingleFieldName => $title, GridListFilter::TagFieldName => $tag]); } $filters->push($filter); } } }
public function Layout() { $page = Director::get_current_page(); $member = Member::currentUser(); $access = Permission::checkMember($member, 'CMS_ACCESS'); $sectionType = get_called_class(); if ($this->Public || $access) { // Added UserDefinedForm to section if (in_array('UserDefinedForm', ClassInfo::ancestry($page->ClassName))) { $result = new UserDefinedForm_Controller($page); $result->init(); $page->Form = $result->Form(); } return $page->renderWith($this->Render()); } }
function Blog() { if (empty($this->BlogID)) { $entry = Director::get_current_page(); if (is_a($entry, 'BlogPost')) { $this->BlogID = $entry->Parent()->ID; } else { if (is_a($entry, 'Blog')) { $this->BlogID = $entry->ID; } else { $this->BlogID = Blog::get()->First()->ID; } } } return Blog::get()->byId($this->BlogID); }
/** * Use the 'related' method to return related pages. * * @return mixed */ public function provideGridListItems() { if ($this()->{self::SingleFieldName}) { if ($page = \Director::get_current_page()) { $items = new \ArrayList(); // iterate through children of 'HasRelatedPages', eg 'BusinessPages', 'DivisionPages' etc foreach (HasRelatedPages::implementors() as $className => $title) { if ($page->hasExtension($className)) { // get all the related e.g. country pages to this page via the 'RelatedCountries' back relationship $items->merge($page->{$className::relationship_name()}()); } } return $items; } } }
public function RootPage() { if (!$this->currentRootPage) { $this->currentRootPage = Director::get_current_page(); if ($this->MenuRoot == 'Selected Page' && parent::RootPage()) { $this->currentRootPage = parent::RootPage(); } else { if ($this->MenuRoot == 'Root of Current Page' || $this->MenuRoot == 'Root') { while ($this->currentRootPage->exists() && (int) $this->currentRootPage->ParentID !== 0) { $this->currentRootPage = $this->currentRootPage->Parent(); } } } } return $this->currentRootPage; }
public function ListLinks() { switch ($this->LinkType) { case 'specify': return $this->LinkList(); break; case 'children': $currentPage = Director::get_current_page(); return $this->ParentPage()->Children()->Limit($this->LinkLimit)->Exclude(array("ID" => $currentPage->ID)); break; case 'currentchildren': default: $currentPage = Director::get_current_page(); return $currentPage->Children()->Limit($this->LinkLimit); break; } }
function LinkingMode() { $entry = Director::get_current_page(); if (is_a($entry, 'Blog')) { $currentCategory = Controller::curr()->getCurrentCategory(); if ($currentCategory) { if ($currentCategory->ID == $this->owner->ID) { return 'current'; } } else { if (!$this->owner->ID) { // this must be the allcat return 'current'; } } } }
public function getCMSFields() { $fields = parent::getCMSFields(); // Validate The Fact That an Actual E-mail Has Been Used $fields->replaceField("Email", new EmailField("Email", "Email")); $fields->removeByName('DoubleOptIn'); $fields->removeByName('MCMemberID'); $fields->removeByName('MCListID'); $fields->removeByName('MemberID'); if (empty($this->ID)) { $fields->removeByName('Subscribed'); } if (empty($this->UnsubscribeReason)) { $fields->removeByName('UnsubscribeReason'); } $lists = new DataList("MCList"); $lists->sort("\"MCList\".\"Name\" ASC"); $map = $lists->map("ID", "Name"); $mcListID = new DropdownField('MCListID', 'MailChimp List', $map); // Calculate What Parent Object We Are Adding This Subscription record Under (A Specific MCList or A Member) $params = Director::get_current_page()->getURLParams(); $FormParentObject = end($params); // If Already Set Don't Allow It To Be Modified if (!empty($this->MCListID)) { $mcListID = $mcListID->performReadonlyTransformation(); } // If Already Set And Read Only Or If Unset But Adding Subscription Record Under Member Object Show The MCListID Filed if (!empty($this->MCListID) || $FormParentObject == "Members") { $fields->addFieldToTab('Root.Main', $mcListID); } $MCMemberID = new TextField('MCMemberID', 'MailChimp Member ID'); $MCMemberID = $MCMemberID->performReadonlyTransformation(); $MCEmailID = new TextField('MCEmailID', 'MailChimp Email ID'); $MCEmailID = $MCEmailID->performReadonlyTransformation(); $fields->addFieldToTab('Root.Main', $MCMemberID, 'FirstName'); $fields->addFieldToTab('Root.Main', $MCEmailID, 'FirstName'); return $fields; }
/** * Try to get page from Director and if in CMS then get it from CMS page, fallback to * Controller url via page_for_path. * * @return \DataObject|\Page|\SiteTree */ public static function get_current_page() { $page = null; if (\Director::is_ajax()) { if ($path = self::path_for_request(\Controller::curr()->getRequest())) { $page = self::page_for_path($path); } } else { if ($page = \Director::get_current_page()) { if ($page instanceof \CMSMain) { $page = $page->currentPage(); } } if (!$page && ($controller = Controller::curr())) { if ($controller = Controller::curr()) { if ($request = $controller->getRequest()) { $page = Application::page_for_path($request->getURL()); } } } } return $page; }
public function init() { parent::init(); // Summit Landing Page Redirects // Looks to see if ?source is set and redirects to either English or Chinese landing page // based on the source if (isset($this->request)) { $getVars = $this->request->getVars(); } $chineseLangCampaigns = array("o2", "o4", "o6", "o8", "o17", "o18", "o22"); self::AddRequirements(); $use_shadow_box = Director::get_current_page()->IncludeShadowBox; $use_shadow_box = empty($use_shadow_box) || intval($use_shadow_box) == 0 ? 'false' : 'true'; $this->CustomScripts(); //this will be include inline on body after requirements Requirements::javascriptTemplate('themes/openstack/javascript/page.js', array('UseShadowBox' => $use_shadow_box)); }
/** * Checks if a user can view the page * * The user can view the current page if: * - They have the VIEW_DRAFT_CONTENT permission or * - The current time is after the Embargo time (if set) and before the Expiry time (if set) * * @param Member $member * @return boolean */ public function canView($member = null) { // if CMS user with sufficient rights: if (Permission::check("VIEW_DRAFT_CONTENT")) { //if(Permission::checkMember($member, 'VIEW_EMBARGOEXPIRY')) { return true; } // Debug::dump($this->owner->URLSegment." " // . $this->owner->Embargo . " " // . date('d-M-Y h:i', strtotime($this->owner->Embargo)) // . " - " . $this->owner->Expiry); // if on front, controller should be a subclass of ContentController (ties it to CMS, = ok...) $ctr = Controller::curr(); if (is_subclass_of($ctr, "ContentController")) { if ($this->owner->getScheduledStatus() || $this->owner->getExpiredStatus()) { // if $this->owner is the actual page being visited (Director::get_current_page()); $curpage = Director::get_current_page(); if ($curpage->ID == $this->owner->ID) { // we have to prevent visitors from actually visiting this page by redirecting to a 404 // This is a bit of a hack (redirect), but else visitors will be presented with a // 'login' screen in order to acquire sufficient privileges to view the page) $errorPage = ErrorPage::get()->filter('ErrorCode', 404)->first(); if ($errorPage) { $ctr->redirect($errorPage->Link(), 404); } else { // fallback (hack): redirect to anywhere, with a 404 $ctr->redirect(rtrim($this->owner->Link(), '/') . "-404", 404); //$ctr->redirect(Page::get()->first()->Link(), 404); } } return false; } else { return true; } } // else, allow return true; }
/** * Check if this page is in the given current section. * * @param string $sectionName Name of the section to check. * @return boolean True if we are in the given section. */ public function InSection($sectionName) { $page = Director::get_current_page(); while ($page) { if ($sectionName == $page->URLSegment) { return true; } $page = $page->Parent; } return false; }
public function SubmitLandPageUrl() { $url = $this->URL; $page = Director::get_current_page(); $res = $page->getManyManyComponents("Companies", "CompanyID={$this->ID}", "ID")->First(); $submit_url = $res->SubmitPageUrl; if (isset($submit_url) && $submit_url != '') { return $submit_url; } return $url; }
/** * Return array of mode strings in preference order from query string or configuration. * * @return mixed */ public function modes() { $options = [$this->getVar(static::ModeGetVar, self::PersistExact), \Director::get_current_page()->config()->get('gridlist_default_mode'), $this->config()->get('default_mode')]; return array_filter($options); }
public function MetaTags(&$tags) { if (is_a(Director::get_current_page(), 'Security')) { $tags = $tags . '<meta name="robots" content="noindex">'; } }
public function Link($action = null) { $segment = Controller::join_links('widget', $this->widget ? $this->widget->ID : null, $action); if (Director::get_current_page()) { return Director::get_current_page()->Link($segment); } else { return Controller::curr()->Link($segment); } }