本文整理汇总了PHP中SiteTree类的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree类的具体用法?PHP SiteTree怎么用?PHP SiteTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SiteTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: should_be_on_root
/**
* Returns TRUE if a request to a certain page should be redirected to the site root (i.e. if the page acts as the
* home page).
*
* @param SiteTree $page
* @return bool
*/
public static function should_be_on_root(SiteTree $page)
{
if (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true), '/')) {
return !(class_exists('Translatable') && $page->hasExtension('Translatable') && $page->Locale && $page->Locale != Translatable::default_locale());
}
return false;
}
示例2: setUp
/**
* Test setting pagination properties and returning the object
*/
public function setUp()
{
parent::setUp();
$page = new SiteTree(['Title' => "Test Page", 'URLSegment' => 'test']);
$page->write();
$page->publish('Stage', 'Live');
}
示例3: testExternalBackUrlRedirectionDisallowed
function testExternalBackUrlRedirectionDisallowed() {
$page = new SiteTree();
$page->URLSegment = 'testpage';
$page->Title = 'Testpage';
$page->write();
$page->publish('Stage','Live');
// Test internal relative redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', 'testpage');
$this->assertEquals(302, $response->getStatusCode());
$this->assertRegExp('/testpage/', $response->getHeader('Location'),
"Internal relative BackURLs work when passed through to login form"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
// Test internal absolute redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', Director::absoluteBaseURL() . 'testpage');
// for some reason the redirect happens to a relative URL
$this->assertRegExp('/^' . preg_quote(Director::absoluteBaseURL(), '/') . 'testpage/', $response->getHeader('Location'),
"Internal absolute BackURLs work when passed through to login form"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
// Test external redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', 'http://myspoofedhost.com');
$this->assertNotRegExp('/^' . preg_quote('http://myspoofedhost.com', '/') . '/', $response->getHeader('Location'),
"Redirection to external links in login form BackURL gets prevented as a measure against spoofing attacks"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
}
示例4: canBeCached
/**
*
* @param SiteTree $page
* @return boolean
*/
protected function canBeCached(SiteTree $page)
{
if (!$page->canView()) {
return false;
}
return true;
}
示例5: getPreviewAction
public function getPreviewAction(SiteTree $page, PreviewableDataObject $obj)
{
/*
* $obj is an instance of ExampleObject in this case.
* 'show' can be what ever action you wish the controller to use
*/
return $page->Link('show/' . $obj->ID);
}
示例6: testHasmethodBehaviour
function testHasmethodBehaviour() {
/* SiteTree should have all of the methods that Versioned has, because Versioned is listed in SiteTree's
* extensions */
$st = new SiteTree();
$cc = new ContentController($st);
$this->assertTrue($st->hasMethod('publish'), "Test SiteTree has publish");
$this->assertTrue($st->hasMethod('migrateVersion'), "Test SiteTree has migrateVersion");
/* This relationship should be case-insensitive, too */
$this->assertTrue($st->hasMethod('PuBliSh'), "Test SiteTree has PuBliSh");
$this->assertTrue($st->hasMethod('MiGratEVersIOn'), "Test SiteTree has MiGratEVersIOn");
/* In a similar manner, all of SiteTree's methods should be available on ContentController, because $failover is set */
$this->assertTrue($cc->hasMethod('canView'), "Test ContentController has canView");
$this->assertTrue($cc->hasMethod('linkorcurrent'), "Test ContentController has linkorcurrent");
/* This 'method copying' is transitive, so all of Versioned's methods should be available on ContentControler.
* Once again, this is case-insensitive */
$this->assertTrue($cc->hasMethod('MiGratEVersIOn'), "Test ContentController has MiGratEVersIOn");
/* The above examples make use of SiteTree, Versioned and ContentController. Let's test defineMethods() more
* directly, with some sample objects */
$objs = array();
$objs[] = new ObjectTest_T2();
$objs[] = new ObjectTest_T2();
$objs[] = new ObjectTest_T2();
// All these methods should exist and return true
$trueMethods = array('testMethod','otherMethod','someMethod','t1cMethod','normalMethod');
foreach($objs as $i => $obj) {
foreach($trueMethods as $method) {
$methodU = strtoupper($method);
$methodL = strtoupper($method);
$this->assertTrue($obj->hasMethod($method), "Test that obj#$i has method $method");
$this->assertTrue($obj->hasMethod($methodU), "Test that obj#$i has method $methodU");
$this->assertTrue($obj->hasMethod($methodL), "Test that obj#$i has method $methodL");
$this->assertTrue($obj->$method(), "Test that obj#$i can call method $method");
$this->assertTrue($obj->$methodU(), "Test that obj#$i can call method $methodU");
$this->assertTrue($obj->$methodL(), "Test that obj#$i can call method $methodL");
}
$this->assertTrue($obj->hasMethod('Wrapping'), "Test that obj#$i has method Wrapping");
$this->assertTrue($obj->hasMethod('WRAPPING'), "Test that obj#$i has method WRAPPING");
$this->assertTrue($obj->hasMethod('wrapping'), "Test that obj#$i has method wrapping");
$this->assertEquals("Wrapping", $obj->Wrapping(), "Test that obj#$i can call method Wrapping");
$this->assertEquals("Wrapping", $obj->WRAPPING(), "Test that obj#$i can call method WRAPPIGN");
$this->assertEquals("Wrapping", $obj->wrapping(), "Test that obj#$i can call method wrapping");
}
}
示例7: getParents
/**
* Go throught tree upward to find all parents
*/
private static function getParents(SiteTree $page)
{
$parents = array();
$parent = $page->parent();
while ($parent && $parent->exists()) {
array_push($parents, $parent);
// Keep looping
$parent = $parent->parent();
}
return $parents;
}
示例8: testDataIntegrity
public function testDataIntegrity()
{
$siteTree = new SiteTree();
$siteTree->MetaTitle = 'Custom meta title';
$siteTree->write();
$siteTreeTest = SiteTree::get()->byID($siteTree->ID);
$this->assertEquals('Custom meta title', $siteTreeTest->MetaTitle);
$obj = new MetaTitleExtensionTest_DataObject();
$obj->MetaTitle = 'Custom DO meta title';
$obj->write();
$objTest = MetaTitleExtensionTest_DataObject::get()->byID($obj->ID);
$this->assertEquals('Custom DO meta title', $objTest->MetaTitle);
}
示例9: updateMetadata
/**
* @param SiteConfig $config
* @param SiteTree $owner
* @param string $metadata
*
* @return void
*
*/
public function updateMetadata(SiteConfig $config, SiteTree $owner, &$metadata)
{
// Facebook App ID
if ($config->FacebookAppID) {
$metadata .= $owner->MarkupComment('Facebook Insights');
$metadata .= $owner->MarkupFacebook('fb:app_id', $config->FacebookAppID, false);
// Admins (if App ID)
foreach ($config->FacebookAdmins() as $admin) {
if ($admin->FacebookProfileID) {
$metadata .= $owner->MarkupFacebook('fb:admins', $admin->FacebookProfileID, false);
}
}
}
}
开发者ID:graphiques-digitale,项目名称:silverstripe-seo-facebook-domain-insights,代码行数:22,代码来源:SEO_FacebookDomainInsights_SiteTree_DataExtension.php
示例10: getMenu
/**
* Returns a fixed navigation menu of the given level.
* @return SS_List
*/
public function getMenu($level = 1)
{
if (ClassInfo::exists("SiteTree")) {
if ($level == 1) {
$result = SiteTree::get()->filter(array("ShowInMenus" => 1, "ParentID" => 0));
} else {
$parent = $this->owner->data();
$stack = array($parent);
if ($parent) {
while ($parent = $parent->Parent) {
array_unshift($stack, $parent);
}
}
if (isset($stack[$level - 2]) && !$stack[$level - 2] instanceof Product) {
$result = $stack[$level - 2]->Children();
}
}
$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);
} else {
return new ArrayList();
}
}
示例11: requireDefaultRecords
/**
* Ensures that there is always a 404 page by checking if there's an
* instance of ErrorPage with a 404 and 500 error code. If there is not,
* one is created when the DB is built.
*/
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
if ($this->class === 'ErrorPage' && SiteTree::config()->create_default_pages) {
$defaultPages = $this->getDefaultRecords();
foreach ($defaultPages as $defaultData) {
$code = $defaultData['ErrorCode'];
$page = ErrorPage::get()->filter('ErrorCode', $code)->first();
$pageExists = !empty($page);
if (!$pageExists) {
$page = new ErrorPage($defaultData);
$page->write();
$page->publish('Stage', 'Live');
}
// Check if static files are enabled
if (!self::config()->enable_static_file) {
continue;
}
// Ensure this page has cached error content
$success = true;
if (!$page->hasStaticPage()) {
// Update static content
$success = $page->writeStaticPage();
} elseif ($pageExists) {
// If page exists and already has content, no alteration_message is displayed
continue;
}
if ($success) {
DB::alteration_message(sprintf('%s error page created', $code), 'created');
} else {
DB::alteration_message(sprintf('%s error page could not be created. Please check permissions', $code), 'error');
}
}
}
}
示例12: onAfterWrite
/**
* Update link mappings when replacing the default automated URL handling.
*/
public function onAfterWrite()
{
parent::onAfterWrite();
// Determine whether the default automated URL handling has been replaced.
if (Config::inst()->get('MisdirectionRequestFilter', 'replace_default')) {
// Determine whether the URL segment or parent ID has been updated.
$changed = $this->owner->getChangedFields();
if (isset($changed['URLSegment']['before']) && isset($changed['URLSegment']['after']) && $changed['URLSegment']['before'] != $changed['URLSegment']['after'] || isset($changed['ParentID']['before']) && isset($changed['ParentID']['after']) && $changed['ParentID']['before'] != $changed['ParentID']['after']) {
// The link mappings should only be created for existing pages.
$URL = isset($changed['URLSegment']['before']) ? $changed['URLSegment']['before'] : $this->owner->URLSegment;
if (strpos($URL, 'new-') !== 0) {
// Determine the page URL.
$parentID = isset($changed['ParentID']['before']) ? $changed['ParentID']['before'] : $this->owner->ParentID;
$parent = SiteTree::get_one('SiteTree', "SiteTree.ID = {$parentID}");
while ($parent) {
$URL = Controller::join_links($parent->URLSegment, $URL);
$parent = SiteTree::get_one('SiteTree', "SiteTree.ID = {$parent->ParentID}");
}
// Instantiate a link mapping for this page.
singleton('MisdirectionService')->createPageMapping($URL, $this->owner->ID);
// Purge any link mappings that point back to the same page.
$this->owner->regulateMappings($this->owner->Link() === Director::baseURL() ? Controller::join_links(Director::baseURL(), 'home/') : $this->owner->Link(), $this->owner->ID);
// Recursively create link mappings for any children.
$children = $this->owner->AllChildrenIncludingDeleted();
if ($children->count()) {
$this->owner->recursiveMapping($URL, $children);
}
}
}
}
}
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-misdirection,代码行数:34,代码来源:SiteTreeMisdirectionExtension.php
示例13: doTranslatePages
/**
* Handles the translation of pages and its relations
*
* @param array $data , Form $form
* @return boolean | index function
**/
public function doTranslatePages($data, $form)
{
$language = $data['NewTransLang'];
$pages = explode(',', $data['PageIDs']);
$status = array('translated' => array(), 'error' => array());
foreach ($pages as $p) {
$page = SiteTree::get()->byID($p);
$id = $page->ID;
if (!$page->hasTranslation($language)) {
try {
$translation = $page->createTranslation($language);
$successMessage = $this->duplicateRelations($page, $translation);
$status['translated'][$translation->ID] = array('TreeTitle' => $translation->TreeTitle);
$translation->destroy();
unset($translation);
} catch (Exception $e) {
// no permission - fail gracefully
$status['error'][$page->ID] = true;
}
}
$page->destroy();
unset($page);
}
return '<input type="hidden" class="close-dialog" />';
}
开发者ID:helpfulrobot,项目名称:mspacemedia-batchtranslate,代码行数:31,代码来源:CMSBatchAction_TranslateController.php
示例14: model
public static function model($url = null)
{
static::start();
$stage = static::getRequestedStage();
$key = $url . '|' . $stage;
if (isset(static::$models[$key])) {
return static::$models[$key];
}
$segments = !is_null($url) ? static::segments($url) : Request::segments();
$segment = array_shift($segments);
if ($segment) {
$parentID = 0;
do {
$model = \SiteTree::get()->filter(array('URLSegment' => $segment, 'ParentID' => $parentID))->First();
if ($model) {
$parentID = $model->ID;
} else {
break;
}
} while ($segment = array_shift($segments));
} else {
// special case - home page
$model = \SiteTree::get()->filter(array('URLSegment' => 'home', 'ParentID' => 0))->First();
}
return static::$models[$url] = $model;
}
示例15: allPagesToCache
public function allPagesToCache()
{
// Get each page type to define its sub-urls
$urls = array();
// memory intensive depending on number of pages
$pages = SiteTree::get()->where("ClassName != 'BlogEntry'");
//remove Blog pages from cache due to Form SecurityID issue
foreach ($pages as $page) {
array_push($urls, $page->Link());
if ($page->ClassName == 'ProjectPage') {
//add ajax pages for each projectpage
array_push($urls, $page->Link() . 'ajax');
}
}
//add tag pages
$tags = Tag::get()->filter(array('HasTagPage' => 1));
foreach ($tags as $tag) {
array_push($urls, '/tag/' . $tag->Slug);
}
//add location pages
$locations = Location::get();
foreach ($locations as $location) {
array_push($urls, '/location/' . $location->Slug);
}
return $urls;
}