當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SiteTree類代碼示例

本文整理匯總了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;
 }
開發者ID:prostart,項目名稱:cobblestonepath,代碼行數:14,代碼來源:RootURLController.php

示例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');
 }
開發者ID:Cyber-Duck,項目名稱:Silverstripe-SEO,代碼行數:10,代碼來源:SEOPaginationTest.php

示例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);
	}
開發者ID:neopba,項目名稱:silverstripe-book,代碼行數:33,代碼來源:SecurityTest.php

示例4: canBeCached

 /**
  * 
  * @param SiteTree $page
  * @return boolean
  */
 protected function canBeCached(SiteTree $page)
 {
     if (!$page->canView()) {
         return false;
     }
     return true;
 }
開發者ID:helpfulrobot,項目名稱:stojg-dachshund,代碼行數:12,代碼來源:StaticCacheURLGatherer.php

示例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);
 }
開發者ID:helpfulrobot,項目名稱:jotham-silverstripe-dataobject-preview,代碼行數:8,代碼來源:PreviewPage.php

示例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");
		}
		
	}
開發者ID:neopba,項目名稱:silverstripe-book,代碼行數:54,代碼來源:ObjectTest.php

示例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;
 }
開發者ID:helpfulrobot,項目名稱:dnadesign-silverstripe-generatepdf,代碼行數:14,代碼來源:PublishRefreshPDF.php

示例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);
 }
開發者ID:helpfulrobot,項目名稱:kinglozzer-metatitle,代碼行數:13,代碼來源:MetaTitleExtensionTest.php

示例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();
     }
 }
開發者ID:helpfulrobot,項目名稱:i-lateral-silverstripe-middleman,代碼行數:36,代碼來源:Middleman_Controller.php

示例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');
             }
         }
     }
 }
開發者ID:helpfulrobot,項目名稱:comperio-silverstripe-cms,代碼行數:40,代碼來源:ErrorPage.php

示例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;
 }
開發者ID:helpfulrobot,項目名稱:themonkeys-laravel-silverstripe,代碼行數:26,代碼來源:Silverstripe.php

示例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;
 }
開發者ID:nttan,項目名稱:silverstripe-portfolio,代碼行數:26,代碼來源:BasicPage.php


注:本文中的SiteTree類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。