"Varchar(255)", "Title" => "Varchar(255)", "MenuTitle" => "Varchar(100)", "Content" => "HTMLText", "MetaTitle" => "Varchar(255)", "MetaDescription" => "Varchar(255)", "MetaKeywords" => "Varchar(255)", "ExtraMeta" => "HTMLText", "ShowInMenus" => "Boolean", "ShowInSearch" => "Boolean", "HomepageForDomain" => "Varchar(100)", "ProvideComments" => "Boolean", "Sort" => "Int", "LegacyURL" => "Varchar(255)", "HasBrokenFile" => "Boolean", "HasBrokenLink" => "Boolean", "Status" => "Varchar", "ReportClass" => "Varchar", "Priority" => "Float", "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers, Inherit', 'Inherit')", "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers, Inherit', 'Inherit')", // Simple task tracking "ToDo" => "Text", ); static $indexes = array( "SearchFields" => "fulltext (Title, MenuTitle, Content, MetaTitle, MetaDescription, MetaKeywords)", "TitleSearchFields" => "fulltext (Title)", "URLSegment" => true, ); static $has_many = array( "Comments" => "PageComment" ); static $many_many = array( "LinkTracking" => "SiteTree", "ImageTracking" => "File", "ViewerGroups" => "Group", "EditorGroups" => "Group", ); static $belongs_many_many = array( "BackLinkTracking" => "SiteTree" ); static $many_many_extraFields = array( "LinkTracking" => array("FieldName" => "Varchar"), "ImageTracking" => array("FieldName" => "Varchar") ); static $casting = array( "Breadcrumbs" => "HTMLText", "LastEdited" => "SSDatetime", "Created" => "SSDatetime", ); static $defaults = array( "ShowInMenus" => 1, "ShowInSearch" => 1, "Status" => "New page", "CanViewType" => "Inherit", "CanEditType" => "Inherit" ); static $has_one = array( "Parent" => "SiteTree" ); static $versioning = array( "Stage", "Live" ); static $default_sort = "Sort"; /** * The text shown in the create page dropdown. If * this is not set, default to "Create a ClassName". * @var string */ static $add_action = null; /** * If this is false, the class cannot be created in the CMS. * @var boolean */ static $can_create = true; /** * Icon to use in the CMS * * This should be the base filename. The suffixes -file.gif, * -openfolder.gif and -closedfolder.gif will be appended to the base name * that you provide there. * If you prefer, you can pass an array: * array("jsparty\tree\images\page", $option). * $option can be either "file" or "folder" to force the icon to always * be a file or folder, regardless of whether the page has children or not * * @var string|array */ static $icon = array("jsparty/tree/images/page", "file"); static $extensions = array( "Hierarchy", "Translatable('Title', 'MenuTitle', 'Content', 'URLSegment', 'MetaTitle', 'MetaDescription', 'MetaKeywords', 'Status')", "Versioned('Stage', 'Live')" ); /** * Delimit breadcrumb-links generated by BreadCrumbs() * * @var string */ public static $breadcrumbs_delimiter = " » "; static $searchable_fields = array( 'Title', 'Content', ); /** * This controls whether of not extendCMSFields() is called by getCMSFields. */ private static $runCMSFieldsExtensions = true; /** * Get the URL for this page. * * @param string $action An action to include in the link * @return string The URL for this page */ public function Link($action = null) { if($action == "index") { $action = ""; } if($this->URLSegment == 'home' && !$action) return Director::baseURL(); else return Director::baseURL() . $this->URLSegment . "/$action"; } /** * Get the absolute URL for this page by stage */ public function AbsoluteLink() { if($this->hasMethod('alternateAbsoluteLink')) return $this->alternateAbsoluteLink(); else return Director::absoluteURL($this->Link()); } /** * Returns link/current, depending on whether you're on the current page. * This is useful for css styling of menus. * * @return string Either 'link' or 'current'. */ public function LinkOrCurrent() { return ($this->isCurrent()) ? "current" : "link"; } /** * Returns link/section, depending on whether you're on the current section. * This is useful for css styling of menus. * * @return string Either 'link' or 'section'. */ public function LinkOrSection() { return ($this->isSection()) ? "section" : "link"; } /** * Returns link/current/section, depending if you're not in the current * section, you're on the current page, or you're in the current section * but not on the current page. * * @return string Either 'link', 'current' or 'section'. */ public function LinkingMode() { $this->prepareCurrentAndSection(); if($this->ID == self::$currentPageID) { return "current"; } else if(in_array($this->ID, self::$currentSectionIDs)) { return "section"; } else { return "link"; } } /** * Get the URL segment for this page, eg 'home' * * @return string The URL segment */ public function ElementName() { return $this->URLSegment; } /** * 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::currentPage(); while($page) { if($sectionName == $page->URLSegment) return true; $page = $page->Parent; } return false; } /** * Returns comments on this page. This will only show comments that * have been marked as spam if "?showspam=1" is appended to the URL. * * @return DataObjectSet Comments on this page. */ public function Comments() { $spamfilter = isset($_GET['showspam']) ? '' : 'AND IsSpam=0'; $unmoderatedfilter = Permission::check('ADMIN') ? '' : 'AND NeedsModeration = 0'; $comments = DataObject::get("PageComment", "ParentID = '" . Convert::raw2sql($this->ID) . "' $spamfilter $unmoderatedfilter", "Created DESC"); return $comments ? $comments : new DataObjectSet(); } /** * Create a duplicate of this node. Doesn't affect joined data - create a * custom overloading of this if you need such behaviour. * * @return SiteTree The duplicated object. */ public function duplicate($doWrite = true) { $page = parent::duplicate($doWrite); $page->CheckedPublicationDifferences = $page->AddedToStage = true; return $page; } /** * Duplicates each child of this node recursively and returns the * duplicate node. * * @return SiteTree The duplicated object. */ public function duplicateWithChildren() { $clone = $this->duplicate(); $children = $this->AllChildren(); if($children) { foreach($children as $child) { $childClone = method_exists($child, 'duplicateWithChildren') ? $child->duplicateWithChildren() : $child->duplicate(); $childClone->ParentID = $clone->ID; $childClone->write(); } } return $clone; } /** * Duplicate this node and its children as a child of the node with the * given ID * * @param int $id ID of the new node's new parent */ public function duplicateAsChild($id) { $newSiteTree = $this->duplicate(); $newSiteTree->ParentID = $id; $newSiteTree->write(); } /** * An array of this pages URL segment and it's parents. * This is generated by prepareCurrentAndSection for use by * isCurrent() and isSection() * * @var array */ protected static $currentSectionIDs; /** * The current page ID. * This is generated by prepareCurrentAndSection for use by * isCurrent() and isSection() * * @var int */ private static $currentPageID; /** * Records the URL segment that was used to set the current page ID */ private static $currentPageIDSetFromURLSegment; /** * This function is used for isCurrent() and isSection() to prepare * the cached answers. */ protected function prepareCurrentAndSection() { if(!self::$currentPageID || Director::urlParam('URLSegment') != self::$currentPageIDSetFromURLSegment) { self::$currentPageID = Director::currentPage() ? Director::currentPage()->ID : null; self::$currentPageIDSetFromURLSegment = Director::urlParam('URLSegment'); if(!isset(self::$currentPageID)) { self::$currentPageID = -1; $nextID = (Director::currentPage() && isset(Director::currentPage()->Parent->ID)) ? Director::currentPage()->Parent->ID : null; } else { $nextID = SiteTree::$currentPageID; } $table = (Versioned::current_stage() == "Live") ? "SiteTree_Live" : "SiteTree"; SiteTree::$currentSectionIDs = array(); while($nextID) { self::$currentSectionIDs[] = $nextID; $nextID = DB::query("SELECT ParentID FROM SiteTree WHERE ID = $nextID")->value(); } } } /** * Check if this is the currently viewed page. * * @return boolean True if this is the current page. */ public function isCurrent() { $this->prepareCurrentAndSection(); return $this->ID == SiteTree::$currentPageID; } /** * Check if the currently viewed page is in this section. * * @return boolean True if the currently viewed page is in this section. */ public function isSection() { $this->prepareCurrentAndSection(); return in_array($this->ID, self::$currentSectionIDs); } /** * Return a breadcrumb trail to this page. Excludes "hidden" pages * (with ShowInMenus=0). * * @param int $maxDepth The maximum depth to traverse. * @param boolean $unlinked Do not make page names links * @param string $stopAtPageType ClassName of a page to stop the upwards traversal. * @param boolean $showHidden Include pages marked with the attribute ShowInMenus = 0 * @return string The breadcrumb trail. */ public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false) { $page = $this; $parts = array(); $i = 0; while( $page && (!$maxDepth || sizeof($parts) < $maxDepth) && (!$stopAtPageType || $page->ClassName != $stopAtPageType) ) { if($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) { if($page->URLSegment == 'home') $hasHome = true; if(($page->ID == $this->ID) || $unlinked) { $parts[] = Convert::raw2xml($page->Title); } else { $parts[] = ("Link() . "\">" . Convert::raw2xml($page->Title) . ""); } } $page = $page->Parent; } return implode(self::$breadcrumbs_delimiter, array_reverse($parts)); } /** * Make this page a child of another page. * * If the parent page does not exist, resolve it to a valid ID * before updating this page's reference. * * @param SiteTree|int $item Either the parent object, or the parent ID */ public function setParent($item) { if(is_object($item)) { if (!$item->exists()) $item->write(); $this->setField("ParentID", $item->ID); } else { $this->setField("ParentID", $item); } } /** * Get the parent of this page. * * @return SiteTree Parent of this page. */ public function getParent() { if ($this->getField("ParentID")) { return DataObject::get_one("SiteTree", "`SiteTree`.ID = " . $this->getField("ParentID")); } } /** * Return a string of the form "parent - page" or * "grandparent - parent - page". * * @param int $level The maximum amount of levels to traverse. * @param string $seperator Seperating string * @return string The resulting string */ function NestedTitle($level = 2, $separator = " - ") { $item = $this; while($item && $level > 0) { $parts[] = $item->Title; $item = $item->Parent; $level--; } return implode($separator, array_reverse($parts)); } /** * This function should return true if the current user can add children * to this page. It can be overloaded to customise the security model for an * application. * * Returns true if the member is allowed to do the given action. * * @uses DataObjectDecorator->can() * * @param string $perm The permission to be checked, such as 'View'. * @param Member $member The member whose permissions need checking. * Defaults to the currently logged in user. * * @return boolean True if the the member is allowed to do the given * action. * * @todo Check we get a endless recursion if we use parent::can() */ function can($perm, $member = null) { if(!isset($member)) $member = Member::currentUser(); if(Permission::checkMember($member, "ADMIN")) return true; if(method_exists($this, 'can' . ucfirst($perm))) { $method = 'can' . ucfirst($perm); return $this->$method($member); } // DEPRECATED 2.3: Use can() $results = $this->extend('alternateCan', $member); if($results && is_array($results)) if(!min($results)) return false; $results = $this->extend('can', $member); if($results && is_array($results)) if(!min($results)) return false; return true; } /** * This function should return true if the current user can add children * to this page. It can be overloaded to customise the security model for an * application. * * Denies permission if any of the following conditions is TRUE: * - alternateCanAddChildren() on a decorator returns FALSE * - canEdit() is not granted * - There are no classes defined in {@link $allowed_children} * * @uses DataObjectDecorator->canAddChildren() * @uses canEdit() * @uses $allowed_children * * @return boolean True if the current user can add children. */ public function canAddChildren($member = null) { if(!isset($member)) { $member = Member::currentUser(); } if(Permission::checkMember($member, "ADMIN")) return true; // DEPRECATED 2.3: use canAddChildren() instead $results = $this->extend('alternateCanAddChildren', $member); if($results && is_array($results)) if(!min($results)) return false; $results = $this->extend('canAddChildren', $member); if($results && is_array($results)) if(!min($results)) return false; return $this->canEdit() && $this->stat('allowed_children') != 'none'; } /** * This function should return true if the current user can view this * page. It can be overloaded to customise the security model for an * application. * * Denies permission if any of the following conditions is TRUE: * - canView() on any decorator returns FALSE * - "CanViewType" directive is set to "Inherit" and any parent page return false for canView() * - "CanViewType" directive is set to "LoggedInUsers" and no user is logged in * - "CanViewType" directive is set to "OnlyTheseUsers" and user is not in the given groups * * @uses DataObjectDecorator->canView() * @uses ViewerGroups() * * @return boolean True if the current user can view this page. */ public function canView($member = null) { if(!isset($member)) $member = Member::currentUser(); // admin override if(Permission::checkMember($member, "ADMIN")) return true; // DEPRECATED 2.3: use canView() instead $results = $this->extend('alternateCanView', $member); if($results && is_array($results)) if(!min($results)) return false; // decorated access checks $results = $this->extend('canView', $member); if($results && is_array($results)) if(!min($results)) return false; // check for empty spec if(!$this->CanViewType || $this->CanViewType == 'Anyone') return true; // check for inherit if($this->CanViewType == 'Inherit') { if($this->ParentID) return $this->Parent()->canView($member); else return true; } // check for any logged-in users if( $this->CanViewType == 'LoggedInUsers' && Member::currentUser() ) return true; // check for specific groups if( $this->CanViewType == 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups()) ) return true; return false; } /** * This function should return true if the current user can delete this * page. It can be overloaded to customise the security model for an * application. * * Denies permission if any of the following conditions is TRUE: * - canDelete() returns FALSE on any decorator * - canEdit() returns FALSE * - any descendant page returns FALSE for canDelete() * * @uses canDelete() * @uses canEdit() * * @param Member $member * @return boolean True if the current user can delete this page. */ public function canDelete($member = null) { if(!isset($member)) $member = Member::currentUser(); if(Permission::checkMember($member, "ADMIN")) return true; // DEPRECATED 2.3: use canDelete() instead $results = $this->extend('alternateCanDelete', $member); if($results && is_array($results)) if(!min($results)) return false; // decorated access checks $results = $this->extend('canDelete', $member); if($results && is_array($results)) if(!min($results)) return false; // if page can't be edited, don't grant delete permissions if(!$this->canEdit()) return false; $children = $this->AllChildren(); if($children) foreach($children as $child) { if(!$child->canDelete()) return false; } return $this->stat('can_create') != false; } /** * This function should return true if the current user can create new * pages of this class. It can be overloaded to customise the security model for an * application. * * Denies permission if any of the following conditions is TRUE: * - canCreate() returns FALSE on any decorator * - $can_create is set to FALSE and the site is not in "dev mode" * * Use {@link canAddChildren()} to control behaviour of creating children under this page. * * @uses $can_create * * @param Member $member * @return boolean True if the current user can create pages on this class. */ public function canCreate($member = null) { if(!isset($member)) $member = Member::currentUser(); if(Permission::checkMember($member, "ADMIN")) return true; // DEPRECATED 2.3: use canCreate() instead $results = $this->extend('alternateCanCreate', $member); if($results && is_array($results)) if(!min($results)) return false; // decorated permission checks $results = $this->extend('canCreate', $member); if($results && is_array($results)) if(!min($results)) return false; return $this->stat('can_create') != false || Director::isDev(); } /** * This function should return true if the current user can edit this * page. It can be overloaded to customise the security model for an * application. * * Denies permission if any of the following conditions is TRUE: * - canEdit() on any decorator returns FALSE * - canView() return false * - "CanEditType" directive is set to "Inherit" and any parent page return false for canEdit() * - "CanEditType" directive is set to "LoggedInUsers" and no user is logged in or doesn't have the CMS_Access_CMSMAIN permission code * - "CanEditType" directive is set to "OnlyTheseUsers" and user is not in the given groups * * @uses canView() * @uses EditorGroups() * * @param Member $member * @return boolean True if the current user can edit this page. */ public function canEdit($member = null) { if(!$member) $member = Member::currentUser(); if(Permission::checkMember($member, "ADMIN")) return true; // DEPRECATED 2.3: use canEdit() instead $results = $this->extend('alternateCanEdit', $member); if($results && is_array($results)) if(!min($results)) return false; // decorated access checks $results = $this->extend('canEdit', $member); if($results && is_array($results)) if(!min($results)) return false; // if page can't be viewed, don't grant edit permissions if(!$this->canView()) return false; // check for empty spec if(!$this->CanEditType || $this->CanEditType == 'Anyone') return true; // check for inherit if($this->CanEditType == 'Inherit') { if($this->ParentID) return $this->Parent()->canEdit($member); else return Permission::checkMember($member, 'CMS_ACCESS_CMSMain'); } // check for any logged-in users if($this->CanEditType == 'LoggedInUsers' && Permission::checkMember($member, 'CMS_ACCESS_CMSMain')) return true; // check for specific groups if($this->CanEditType == 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) return true; return false; } /** * This function should return true if the current user can publish this * page. It can be overloaded to customise the security model for an * application. * * Denies permission if any of the following conditions is TRUE: * - canPublish() on any decorator returns FALSE * - canEdit() returns FALSE * * @uses DataObjectDecorator->canPublish() * * @param Member $member * @return boolean True if the current user can publish this page. */ public function canPublish($member = null) { if(!$member) $member = Member::currentUser(); if(Permission::checkMember($member, "ADMIN")) return true; // DEPRECATED 2.3: use canPublish() instead $results = $this->extend('alternateCanPublish', $member); if($results && is_array($results)) if(!min($results)) return false; // If we have a result, then that means at least one decorator specified alternateCanPublish // Allow the permission check only if *all* voting decorators allow it. $results = $this->extend('canPublish', $member); if($results && is_array($results)) if(!min($results)) return false; // Normal case return $this->canEdit(); } /** * Collate selected descendants of this page. * * {@link $condition} will be evaluated on each descendant, and if it is * succeeds, that item will be added to the $collator array. * * @param string $condition The PHP condition to be evaluated. The page * will be called $item * @param array $collator An array, passed by reference, to collect all * of the matching descendants. */ public function collateDescendants($condition, &$collator) { if($children = $this->Children()) { foreach($children as $item) { if(eval("return $condition;")) $collator[] = $item; $item->collateDescendants($condition, $collator); } return true; } } /** * Return the title, description, keywords and language metatags. * * @todo Make generator tag dynamically determine version number (currently defaults to "2.0") * @todo Move
Welcome to SilverStripe! This is the default homepage. You can edit this page by opening the CMS. You can now access the developer documentation, or begin the tutorials.
'); $homepage->URLSegment = "home"; $homepage->Status = "Published"; $homepage->write(); $homepage->publish("Stage", "Live"); $homepage->flushCache(); Database::alteration_message("Home page created","created"); } if(DB::query("SELECT COUNT(*) FROM SiteTree")->value() == 1) { $aboutus = new Page(); $aboutus->Title = _t('SiteTree.DEFAULTABOUTTITLE', 'About Us'); $aboutus->Content = _t('SiteTree.DEFAULTABOUTCONTENT', 'You can fill this page out with your own content, or delete it and create your own pages.
You can fill this page out with your own content, or delete it and create your own pages.
" . _t('SiteTree.NOBACKLINKS', 'This page hasn\'t been linked to from any pages.') . "
"; } // Status / message // Create a status message for multiple parents if($this->ID && is_numeric($this->ID)) { $linkedPages = DataObject::get("VirtualPage", "CopyContentFromID = $this->ID"); } if(isset($linkedPages)) { foreach($linkedPages as $linkedPage) { $parentPage = $linkedPage->Parent; $parentPageTitle = $parentPage->Title; if($parentPage->ID) { $parentPageLinks[] = "ID\">{$parentPage->Title}"; } else { $parentPageLinks[] = "ID\">" . _t('SiteTree.TOPLEVEL', 'Site Content (Top Level)') . ""; } } $lastParent = array_pop($parentPageLinks); $parentList = "'$lastParent'"; if(count($parentPageLinks) > 0) { $parentList = "'" . implode("', '", $parentPageLinks) . "' and " . $parentList; } $statusMessage[] = sprintf( _t('SiteTree.APPEARSVIRTUALPAGES', "This content also appears on the virtual pages in the %s sections."), $parentList ); } if($this->HasBrokenLink || $this->HasBrokenFile) { $statusMessage[] = _t('SiteTree.HASBROKENLINKS', "This page has broken links."); } $message = "STATUS: $this->Status" . sprintf( _t( 'SiteTree.METANOTEPRIORITY', "Manually specify a Google Sitemaps priority for this page (%s)" ), '?' ) . "
" ), new DropdownField("Priority", $this->fieldLabel('Priority'), $pagePriorities) ), true ) ) ), $tabBehaviour = new Tab('Behaviour', new DropdownField( "ClassName", $this->fieldLabel('ClassName'), $this->getClassDropdown() ), new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')), new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch')), /*, new TreeMultiselectField("MultipleParents", "Page appears within", "SiteTree")*/ new CheckboxField("ProvideComments", $this->fieldLabel('ProvideComments')), new LiteralField( "", "" . _t('SiteTree.NOTEUSEASHOMEPAGE', "Use this page as the 'home page' for the following domains: (separate multiple domains with commas)") . "
" ), new TextField( "HomepageForDomain", _t('SiteTree.HOMEPAGEFORDOMAIN', "Domain(s)", PR_MEDIUM, 'Listing domains that should be used as homepage') ) ), $tabToDo = new Tab($this->ToDo ? 'To-do **' : 'To-do', new LiteralField("ToDoHelp", _t('SiteTree.TODOHELP', "You can use this to keep track of work that needs to be done to the content of your site. To see all your pages with to do information, open the 'Site Reports' window on the left and select 'To Do'
")), new TextareaField("ToDo", "") ), $tabReports = new TabSet('Reports', $tabBacklinks =new Tab('Backlinks', new LiteralField("Backlinks", $backlinks) ) ), $tabAccess = new Tab('Access', new HeaderField('WhoCanViewHeader',_t('SiteTree.ACCESSHEADER', "Who can view this page?"), 2), $viewersOptionsField = new OptionsetField( "CanViewType", "" ), new TreeMultiselectField("ViewerGroups", $this->fieldLabel('ViewerGroups')), new HeaderField('WhoCanEditHeader',_t('SiteTree.EDITHEADER', "Who can edit this page?"), 2), $editorsOptionsField = new OptionsetField( "CanEditType", "" ), new TreeMultiselectField("EditorGroups", $this->fieldLabel('EditorGroups')) ) ) //new NamedLabelField("Status", $message, "pageStatusMessage", true) ); $viewersOptionsSource = array(); if($this->Parent()->ID) $viewersOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page"); $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone"); $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users"); $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)"); $viewersOptionsField->setSource($viewersOptionsSource); $editorsOptionsSource = array(); if($this->Parent()->ID) $editorsOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page"); $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS"); $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)"); $editorsOptionsField->setSource($editorsOptionsSource); $tabContent->setTitle(_t('SiteTree.TABCONTENT', "Content")); $tabMain->setTitle(_t('SiteTree.TABMAIN', "Main")); $tabMeta->setTitle(_t('SiteTree.TABMETA', "Meta-data")); $tabBehaviour->setTitle(_t('SiteTree.TABBEHAVIOUR', "Behaviour")); $tabReports->setTitle(_t('SiteTree.TABREPORTS', "Reports")); $tabAccess->setTitle(_t('SiteTree.TABACCESS', "Access")); $tabBacklinks->setTitle(_t('SiteTree.TABBACKLINKS', "BackLinks")); if(self::$runCMSFieldsExtensions) { $this->extend('updateCMSFields', $fields); } return $fields; } function fieldLabels() { $labels = parent::fieldLabels(); $labels['Title'] = _t('SiteTree.PAGETITLE', "Page name"); $labels['MenuTitle'] = _t('SiteTree.MENUTITLE', "Navigation label"); $labels['MetaTagsHeader'] = _t('SiteTree.METAHEADER', "Search Engine Meta-tags"); $labels['MetaTitle'] = _t('SiteTree.METATITLE', "Title"); $labels['MetaDescription'] = _t('SiteTree.METADESC', "Description"); $labels['MetaKeywords'] = _t('SiteTree.METAKEYWORDS', "Keywords"); $labels['ExtraMeta'] = _t('SiteTree.METAEXTRA', "Custom Meta Tags"); $labels['Priority'] = _t('SiteTree.METAPAGEPRIO', "Page Priority"); $labels['ClassName'] = _t('SiteTree.PAGETYPE', "Page type", PR_MEDIUM, 'Classname of a page object'); $labels['ShowInMenus'] =_t('SiteTree.SHOWINMENUS', "Show in menus?"); $labels['ShowInSearch'] = _t('SiteTree.SHOWINSEARCH', "Show in search?"); $labels['ProvideComments'] = _t('SiteTree.ALLOWCOMMENTS', "Allow comments on this page?"); $labels['ViewersGroup'] = _t('SiteTree.GROUP', "Group"); $labels['EditorsGroup'] = _t('SiteTree.GROUP'); $labels['URLSegment'] = _t('SiteTree.URLSegment', 'URL Segment', PR_MEDIUM, 'URL for this page'); $labels['Content'] = _t('SiteTree.Content', 'Content', PR_MEDIUM, 'Main HTML Content for a page'); $labels['HomepageForDomain'] = _t('SiteTree.HomepageForDomain', 'Hompage for this domain'); $labels['CanViewType'] = _t('SiteTree.Viewers', 'Viewers Groups'); $labels['CanEditType'] = _t('SiteTree.Editors', 'Editors Groups'); $labels['ToDo'] = _t('SiteTree.ToDo', 'Todo Notes'); $labels['Parent'] = _t('SiteTree.has_one_Parent', 'Parent Page', PR_MEDIUM, 'The parent page in the site hierarchy'); $labels['Comments'] = _t('SiteTree.Comments', 'Comments'); $labels['LinkTracking'] = _t('SiteTree.many_many_LinkTracking', 'Link Tracking'); $labels['ImageTracking'] = _t('SiteTree.many_many_ImageTracking', 'Image Tracking'); $labels['BackLinkTracking'] = _t('SiteTree.many_many_BackLinkTracking', 'Backlink Tracking'); return $labels; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Get the actions available in the CMS for this page - eg Save, Publish. * * @return DataObjectSet The available actions for this page. */ function getCMSActions() { $actions = array(); if($this->isPublished() && $this->canPublish()) { $unpublish = FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete'); $unpublish->describe(_t('SiteTree.BUTTONUNPUBLISHDESC', "Remove this page from the published site")); $unpublish->addExtraClass('delete'); $actions[] = $unpublish; } if($this->stagesDiffer('Stage', 'Live')) { if($this->isPublished() && $this->canEdit()) { $rollback = FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'), 'delete'); $rollback->describe(_t('SiteTree.BUTTONCANCELDRAFTDESC', "Delete your draft and revert to the currently published page")); $rollback->addExtraClass('delete'); $actions[] = $rollback; } } if($this->canPublish()) { $actions[] = new FormAction('publish', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save and Publish')); } // getCMSActions() can be extended with updateCmsActions() on a decorator $this->extend('updateCMSActions', $actions); return new DataObjectSet($actions); } /** * Publish this page */ function doPublish() { $original = Versioned::get_one_by_stage("SiteTree", "Live", "`SiteTree`.`ID` = $this->ID"); if(!$original) $original = new SiteTree(); // Handle activities undertaken by decorators $this->extend('onBeforePublish', $original); $this->AssignedToID = 0; $this->RequestedByID = 0; $this->Status = "Published"; //$this->PublishedByID = Member::currentUser()->ID; $this->write(); $this->publish("Stage", "Live"); GoogleSitemap::ping(); // Fix the sort order for this page's siblings DB::query("UPDATE SiteTree_Live INNER JOIN SiteTree ON SiteTree_Live.ID = SiteTree.ID SET SiteTree_Live.Sort = SiteTree.Sort WHERE SiteTree_Live.ParentID = " . sprintf('%d', $this->ParentID)); // Handle activities undertaken by decorators $this->extend('onAfterPublish', $original); } /** * Unpublish this page - remove it from the live site */ function doUnpublish() { // Call delete on a cloned object so that this one doesn't lose its ID $this->flushCache(); $clone = DataObject::get_by_id("SiteTree", $this->ID); $clone->deleteFromStage('Live'); $this->Status = "Unpublished"; $this->write(); GoogleSitemap::ping(); } /** * Roll the draft version of this page to match the published page * @param $version Either the string 'Live' or a version number */ function doRollbackTo($version) { $this->publish($version, "Stage", true); $this->AssignedToID = 0; $this->RequestedByID = 0; $this->Status = "Saved (update)"; $this->writeWithoutVersion(); } /** * Revert the draft changes: replace the draft content with the content on live */ function doRevertToLive() { $this->publish("Live", "Stage", false); // Use a clone to get the updates made by $this->publish $clone = DataObject::get_by_id("SiteTree", $this->ID); $clone->AssignedToID = 0; $clone->RequestedByID = 0; $clone->Status = "Published"; $clone->writeWithoutVersion(); } /** * Check if this page is new - that is, if it has yet to have been written * to the database. * * @return boolean True if this page is new. */ function isNew() { /** * This check was a problem for a self-hosted site, and may indicate a * bug in the interpreter on their server, or a bug here * Changing the condition from empty($this->ID) to * !$this->ID && !$this->record['ID'] fixed this. */ if(empty($this->ID)) return true; if(is_numeric($this->ID)) return false; return stripos($this->ID, 'new') === 0; } /** * Check if this page has been published. * * @return boolean True if this page has been published. */ function isPublished() { if($this->isNew()) return false; return (DB::query("SELECT ID FROM `SiteTree_Live` WHERE ID = $this->ID")->value()) ? true : false; } /** * Look for ghost parents */ function MultipleParents() { $parents = new GhostPage_ComponentSet($this->Parent); $parents->setOwner($this); $ghostPages = DataObject::get("GhostPage", "LinkedPageID = '$this->ID'"); if($ghostPages) { foreach($ghostPages as $ghostPage) { // Ignore root ghost-pages if($p = $ghostPage->getParent()) $parents->push($p); } } return $parents; } /** * Get the class dropdown used in the CMS to change the class of a page. * This returns the list of options in the drop as a Map from class name * to text in dropdown. * * @return array */ protected function getClassDropdown() { $classes = ClassInfo::getValidSubClasses('SiteTree'); array_shift($classes); foreach($classes as $class) { $instance = singleton($class); if((($instance instanceof HiddenClass) || !$instance->canCreate()) && ($class != $this->class)) continue; /* $addAction = $instance->uninherited('add_action', true); if(!$addAction) { $addAction = $instance->singular_name(); } */ $addAction = $instance->i18n_singular_name(); if($class == $this->class) { $currentClass = $class; $currentAddAction = $addAction; } else { $result[$class] = ($class == $this->class) ? _t('SiteTree.CURRENTLY', 'Currently').' '.$addAction : _t('SiteTree.CHANGETO', 'Change to').' '.$addAction; $currentAddAction = null; $currentClass = null; } } // sort alphabetically, and put current on top asort($result); $result = array_reverse($result); $result[$currentClass] = $currentAddAction.' ('._t('SiteTree.CURRENT','current').')'; $result = array_reverse($result); return $result; } /** * Returns an array of the class names of classes that are allowed * to be children of this class. * * @return array */ function allowedChildren() { $candidates = $this->stat('allowed_children'); if($candidates && $candidates != "none" && $candidates != "SiteTree_root") { foreach($candidates as $candidate) { if(substr($candidate,0,1) == '*') { $allowedChildren[] = substr($candidate,1); } else { $subclasses = ClassInfo::subclassesFor($candidate); foreach($subclasses as $subclass) { if($subclass != "SiteTree_root") $allowedChildren[] = $subclass; } } } return $allowedChildren; } } /** * Returns the class name of the default class for children of this page. * * @return string */ function defaultChild() { $default = $this->stat('default_child'); $allowed = $this->allowedChildren(); if($allowed) { if(!$default || !in_array($default, $allowed)) $default = reset($allowed); return $default; } } /** * Returns the class name of the default class for the parent of this * page. * * @return string */ function defaultParent() { return $this->stat('default_parent'); } /** * Function to clean up the currently loaded page after a reorganise has * been called. It should return a piece of JavaScript to be executed on * the client side, to clean up the results of the reorganise. */ function cmsCleanup_parentChanged() { } /** * Get the title for use in menus for this page. If the MenuTitle * field is set it returns that, else it returns the Title field. * * @return string */ function getMenuTitle(){ if($value = $this->getField("MenuTitle")) { return $value; } else { return $this->getField("Title"); } } /** * Set the menu title for this page. * * @param string $value */ function setMenuTitle($value) { if($value == $this->getField("Title")) { $this->setField("MenuTitle", null); } else { $this->setField("MenuTitle", $value); } } /** * TitleWithStatus will return the title in an ,