当前位置: 首页>>代码示例>>PHP>>正文


PHP SiteTree::get_by_link方法代码示例

本文整理汇总了PHP中SiteTree::get_by_link方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::get_by_link方法的具体用法?PHP SiteTree::get_by_link怎么用?PHP SiteTree::get_by_link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SiteTree的用法示例。


在下文中一共展示了SiteTree::get_by_link方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processRecord

 protected function processRecord($record, $columnMap, &$results, $preview = false)
 {
     $siteTreeID = null;
     if (!empty($record['NewURL'])) {
         //redirect to an existing page
         if ($page = SiteTree::get_by_link($record['NewURL'])) {
             $siteTreeID = $page->ID;
         } else {
             //custom url redirect
             $redirect = $this->createRedirect(array('OldURL' => $record['OldURL'], 'RedirectType' => 'Custom', 'RedirectTo' => $record['NewURL']));
             $results->addCreated($redirect);
             return $redirect->ID;
         }
     } else {
         if (!empty($record['PageID'])) {
             //pass in page id directly
             $siteTreeID = $record['PageID'];
         } else {
             return false;
         }
     }
     //check for an existing record
     $existing = OldURLRedirect::get()->filter(array('OldURL' => $record['OldURL'], 'PageID' => $siteTreeID))->first();
     if (!$existing) {
         $redirect = $this->createRedirect(array('OldURL' => $record['OldURL'], 'PageID' => $siteTreeID));
         $results->addCreated($redirect);
         return $redirect->ID;
     } else {
         $results->addUpdated($existing);
         return $existing->ID;
     }
 }
开发者ID:helpfulrobot,项目名称:webtorque7-old-urls,代码行数:32,代码来源:OldURLCsvBulkLoader.php

示例2: run

 function run($request)
 {
     increase_time_limit_to();
     $self = get_class($this);
     $verbose = isset($_GET['verbose']);
     if (isset($_GET['class']) && isset($_GET['id'])) {
         $item = DataObject::get($_GET['class'])->byID($_GET['id']);
         if (!$item || !$item->exists()) {
             die('not found: ' . $_GET['id']);
         }
         $item->rebuildVFI();
         echo "done";
         return;
     }
     if (isset($_GET['link'])) {
         $item = SiteTree::get_by_link($_GET['link']);
         if (!$item || !$item->exists()) {
             die('not found: ' . $_GET['link']);
         }
         $item->rebuildVFI();
         echo "done";
         return;
     }
     if (isset($_GET['start'])) {
         $this->runFrom($_GET['class'], $_GET['start'], $_GET['field']);
     } else {
         foreach (array('framework', 'sapphire') as $dirname) {
             $script = sprintf("%s%s{$dirname}%scli-script.php", BASE_PATH, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
             if (file_exists($script)) {
                 break;
             }
         }
         $classes = VirtualFieldIndex::get_classes_with_vfi();
         foreach ($classes as $class) {
             if (isset($_GET['class']) && $class != $_GET['class']) {
                 continue;
             }
             $singleton = singleton($class);
             $query = $singleton->get($class);
             $dtaQuery = $query->dataQuery();
             $sqlQuery = $dtaQuery->getFinalisedQuery();
             $singleton->extend('augmentSQL', $sqlQuery, $dtaQuery);
             $total = $query->count();
             $startFrom = isset($_GET['startfrom']) ? $_GET['startfrom'] : 0;
             $field = isset($_GET['field']) ? $_GET['field'] : '';
             echo "Class: {$class}, total: {$total}\n\n";
             for ($offset = $startFrom; $offset < $total; $offset += $this->stat('recordsPerRequest')) {
                 echo "{$offset}..";
                 $cmd = "php {$script} dev/tasks/{$self} class={$class} start={$offset} field={$field}";
                 if ($verbose) {
                     echo "\n  Running '{$cmd}'\n";
                 }
                 $res = $verbose ? passthru($cmd) : `{$cmd}`;
                 if ($verbose) {
                     echo "  " . preg_replace('/\\r\\n|\\n/', '$0  ', $res) . "\n";
                 }
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-shop-search,代码行数:60,代码来源:BuildVFI.php

示例3: get_navbar_html

 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;
 }
开发者ID:newleeland,项目名称:silverstripe-globaltoolbar,代码行数:25,代码来源:GlobalNavSiteTreeExtension.php

示例4: Languages

 /**
  * Get a set of content languages (for quick language navigation)
  * @example
  * <code>
  * <!-- in your template -->
  * <ul class="langNav">
  * 		<% loop Languages %>
  * 		<li><a href="$Link" class="$LinkingMode" title="$Title.ATT">$Language</a></li>
  * 		<% end_loop %>
  * </ul>
  * </code>
  *
  * @return ArrayList|null
  */
 public function Languages()
 {
     $locales = TranslatableUtility::get_content_languages();
     // there's no need to show a navigation when there's less than 2 languages. So return null
     if (count($locales) < 2) {
         return null;
     }
     $currentLocale = Translatable::get_current_locale();
     $homeTranslated = null;
     if ($home = SiteTree::get_by_link('home')) {
         /** @var SiteTree $homeTranslated */
         $homeTranslated = $home->getTranslation($currentLocale);
     }
     /** @var ArrayList $langSet */
     $langSet = ArrayList::create();
     foreach ($locales as $locale => $name) {
         Translatable::set_current_locale($locale);
         /** @var SiteTree $translation */
         $translation = $this->owner->hasTranslation($locale) ? $this->owner->getTranslation($locale) : null;
         $langSet->push(new ArrayData(array('Locale' => $locale, 'RFC1766' => i18n::convert_rfc1766($locale), 'Language' => DBField::create_field('Varchar', strtoupper(i18n::get_lang_from_locale($locale))), 'Title' => DBField::create_field('Varchar', html_entity_decode(i18n::get_language_name(i18n::get_lang_from_locale($locale), true), ENT_NOQUOTES, 'UTF-8')), 'LinkingMode' => $currentLocale == $locale ? 'current' : 'link', 'Link' => $translation ? $translation->AbsoluteLink() : ($homeTranslated ? $homeTranslated->Link() : ''))));
     }
     Translatable::set_current_locale($currentLocale);
     i18n::set_locale($currentLocale);
     return $langSet;
 }
开发者ID:bummzack,项目名称:translatable-dataobject,代码行数:39,代码来源:TranslatableUtility.php

示例5: requireDefaultRecords

 /**
  * Add default records to database.
  *
  * This function is called whenever the database is built, after the
  * database tables have all been created. Overload this to add default
  * records when the database is built, but make sure you call
  * parent::requireDefaultRecords().
  */
 public function requireDefaultRecords()
 {
     if (!SiteTree::get_by_link(Config::inst()->get('RootURLController', 'default_homepage_link'))) {
         $homepage = new HomePage();
         $homepage->Title = 'Home';
         $homepage->URLSegment = Config::inst()->get('RootURLController', 'default_homepage_link');
         $homepage->Sort = 1;
         $homepage->write();
         $homepage->publish('Stage', 'Live');
         $homepage->flushCache();
         DB::alteration_message('Home page created', 'created');
     }
     if (DB::query("SELECT COUNT(*) FROM \"SiteTree\"")->value() == 1) {
         $aboutus = new RootPage();
         $aboutus->Title = 'About Us';
         $aboutus->Sort = 2;
         $aboutus->write();
         $aboutus->publish('Stage', 'Live');
         $aboutus->flushCache();
         DB::alteration_message('Book 1 created', 'created');
         $contactus = new RootPage();
         $contactus->Title = 'Contact Us';
         $contactus->Sort = 3;
         $contactus->write();
         $contactus->publish('Stage', 'Live');
         $contactus->flushCache();
         DB::alteration_message('Book 2 created', 'created');
     }
     // call it on the parent
     parent::requireDefaultRecords();
 }
开发者ID:JamesWatling,项目名称:bonethug,代码行数:39,代码来源:Page.php

示例6: requireDefaultRecords

 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (Config::inst()->get('MailChimpController', 'redirect')) {
         if (!SiteTree::get_by_link(Config::inst()->get('MailChimpController', 'redirect_ok'))) {
             $regOk = new MailChimpLandingPage();
             $regOk->Title = _t('MailChimp.SUBSCIPTION_OK	', 'MailChimp Subscription OK');
             $regOk->Content = _t('MailChimp.SUBSCIPTION_OK_CONTENT', '<p>Thanks for subscribing</p>');
             $regOk->URLSegment = Config::inst()->get('MailChimpController', 'redirect_ok');
             $regOk->Sort = 9998;
             $regOk->ShowInMenus = FALSE;
             $regOk->ShowInSearch = FALSE;
             $regOk->write();
             $regOk->publish('Stage', 'Live');
             $regOk->flushCache();
             DB::alteration_message('MailChimp Subsciption OK created', 'created');
         }
         if (!SiteTree::get_by_link(Config::inst()->get('MailChimpController', 'redirect_ko'))) {
             $regOk = new MailChimpLandingPage();
             $regOk->Title = _t('MailChimp.SUBSCIPTION_KO	', 'MailChimp Subscription KO');
             $regOk->Content = _t('MailChimp.SUBSCIPTION_KO_CONTENT', '<p>Something goes wrong subscribing</p>');
             $regOk->URLSegment = Config::inst()->get('MailChimpController', 'redirect_ko');
             $regOk->Sort = 9999;
             $regOk->ShowInMenus = FALSE;
             $regOk->ShowInSearch = FALSE;
             $regOk->write();
             $regOk->publish('Stage', 'Live');
             $regOk->flushCache();
             DB::alteration_message('MailChimp Subsciption KO created', 'created');
         }
     }
 }
开发者ID:helpfulrobot,项目名称:zirak-silverstripe-mailchimp,代码行数:32,代码来源:MailChimpSubscribe.php

示例7: getParentPage

	public function getParentPage() {
		if($parent = $this->stat('parent')) {
			if(is_numeric($parent)) {
				return DataObject::get_by_id($this->modelClass(), $parent);
			}
			elseif(is_string($parent)) {
				return SiteTree::get_by_link($parent);
			}			
		}
		return false;	
	}
开发者ID:nathancox,项目名称:remodeladmin,代码行数:11,代码来源:RemodelAdmin.php

示例8: requireDefaultRecords

 /**
  * If no ProfiledPage exists and no Page exists called 'Profile' then creates one
  * titled 'Profile' and writes it to stage.
  *
  */
 public function requireDefaultRecords()
 {
     if ($this->config()->get('auto_build_models')) {
         if (!ProfiledPage::get()->count()) {
             if (!SiteTree::get_by_link('/profile')) {
                 /** @var ProfiledPage $page */
                 $page = ProfiledPage::create(array('Title' => CrackerjackModule::get_localised_config_string('ProfiledBuild', 'ProfiledPageTitle', 'Title')));
                 $page->writeToStage('Stage');
                 DB::alteration_message("Added ProfiledPage 'Page' at '/profile'", 'changed');
             }
         }
     }
 }
开发者ID:CrackerjackDigital,项目名称:silverstripe-profiled,代码行数:18,代码来源:Build.php

示例9: transform

 public function transform($item, $parentObject, $duplicateStrategy)
 {
     if (Director::is_cli()) {
         Debug::message("Parent: #{$parentObject->ID}, {$parentObject->Title}");
         Debug::message($item->AbsoluteURL);
     }
     // Sleep for 100ms to reduce load on the remote server
     usleep(100 * 1000);
     // Extract content from the page
     $contentFields = $this->getContentFieldsAndSelectors($item);
     // Default value for Title
     if (empty($contentFields['Title'])) {
         $contentFields['Title'] = array('content' => $item->Name);
     }
     // Default value for URL segment
     if (empty($contentFields['URLSegment'])) {
         $urlSegment = str_replace('/', '', $item->Name);
         $urlSegment = preg_replace('/\\.[^.]*$/', '', $urlSegment);
         $urlSegment = str_replace('.', '-', $item->Name);
         $contentFields['URLSegment'] = array('content' => $urlSegment);
     }
     $schema = $item->getSource()->getSchemaForURL($item->AbsoluteURL);
     $pageType = $schema->DataType;
     if (!$pageType) {
         throw new Exception('Pagetype for migration schema is empty!');
     }
     // Create a page with the appropriate fields
     $page = new $pageType(array());
     $existingPage = SiteTree::get_by_link($item->getExternalId());
     if ($existingPage && $duplicateStrategy === 'Overwrite') {
         if (get_class($existingPage) !== $pageType) {
             $existingPage->ClassName = $pageType;
             $existingPage->write();
         }
         if ($existingPage) {
             $page = $existingPage;
         }
     }
     $page->StaticSiteContentSourceID = $item->getSource()->ID;
     $page->StaticSiteURL = $item->AbsoluteURL;
     $page->ParentID = $parentObject ? $parentObject->ID : 0;
     foreach ($contentFields as $k => $v) {
         $page->{$k} = $v['content'];
     }
     $page->write();
     if (Director::is_cli()) {
         Debug::message("#{$page->Title}");
         Debug::message("#{$page->ID} child of #{$page->ID}");
     }
     return new TransformResult($page, $item->stageChildren());
 }
开发者ID:helpfulrobot,项目名称:silverstripe-staticsiteconnector,代码行数:51,代码来源:StaticSitePageTransformer.php

示例10: doAdd

 public function doAdd($data, $form)
 {
     $className = isset($data['PageType']) ? $data['PageType'] : "Page";
     $parentID = isset($data['ParentID']) ? (int) $data['ParentID'] : 0;
     $suffix = isset($data['Suffix']) ? "-" . $data['Suffix'] : null;
     if (!$parentID && isset($data['Parent'])) {
         $page = SiteTree::get_by_link($data['Parent']);
         if ($page) {
             $parentID = $page->ID;
         }
     }
     if (is_numeric($parentID) && $parentID > 0) {
         $parentObj = DataObject::get_by_id("SiteTree", $parentID);
     } else {
         $parentObj = null;
     }
     if (!$parentObj || !$parentObj->ID) {
         $parentID = 0;
     }
     if ($parentObj) {
         if (!$parentObj->canAddChildren()) {
             return Security::permissionFailure($this);
         }
         if (!singleton($className)->canCreate()) {
             return Security::permissionFailure($this);
         }
     } else {
         if (!SiteConfig::current_site_config()->canCreateTopLevel()) {
             return Security::permissionFailure($this);
         }
     }
     $record = $this->getNewItem("new-{$className}-{$parentID}" . $suffix, false);
     if (class_exists('Translatable') && $record->hasExtension('Translatable') && isset($data['Locale'])) {
         $record->Locale = $data['Locale'];
     }
     try {
         $record->write();
     } catch (ValidationException $ex) {
         $form->sessionMessage($ex->getResult()->message(), 'bad');
         return $this->getResponseNegotiator()->respond($this->request);
     }
     $editController = singleton('CMSPageEditController');
     $editController->setCurrentPageID($record->ID);
     Session::set("FormInfo.Form_EditForm.formError.message", _t('CMSMain.PageAdded', 'Successfully created page'));
     Session::set("FormInfo.Form_EditForm.formError.type", 'good');
     return $this->redirect(Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID));
 }
开发者ID:prostart,项目名称:erics-homes,代码行数:47,代码来源:CMSPageAddController.php

示例11: requireDefaultRecords

 function requireDefaultRecords()
 {
     if (self::$auto_include) {
         $className = $this->class;
         $page = $className::get()->First();
         if (!$page) {
             $page = new TypographyTestPage(self::$defaults);
             $parent = SiteTree::get_by_link(self::$parent_url_segment);
             if ($parent) {
                 $page->ParentID = $parent->ID;
             }
             $page->writeToStage('Stage');
             $page->publish('Stage', 'Live');
             $page->URLSegment = self::$defaults['URLSegment'];
             $page->writeToStage('Stage');
             $page->publish('Stage', 'Live');
             DB::alteration_message('TypographyTestPage', 'created');
         }
     }
 }
开发者ID:helpfulrobot,项目名称:xplore-typography,代码行数:20,代码来源:TypographyTestPage.php

示例12: requireDefaultRecords

 /**
  * Create a new Jobamatic page with defaults set.
  */
 public function requireDefaultRecords()
 {
     if (!SiteTree::get_by_link(self::DEFAULT_JOBPAGE_URLSEGMENT)) {
         $page = new JobamaticPage();
         $page->Title = self::DEFAULT_JOBPAGE_TITLE;
         $page->MenuTitle = self::DEFAULT_JOBPAGE_MENU_TITLE;
         $page->URLSegment = self::DEFAULT_JOBPAGE_URLSEGMENT;
         $page->Content = self::DEFAULT_JOBPAGE_CONTENT;
         $page->ShowInSearch = FALSE;
         $page->write();
         $page->publish('Stage', 'Live');
         $message = "Created default Jobamatic Page";
         $type = "created";
         $page->flushCache();
     } else {
         $message = "Failed to create default Jobamatic page &ndash; page with URLSegment &quot;jobs&quot; already exists.";
         $type = 'error';
     }
     DB::alteration_message($message, $type);
 }
开发者ID:r0nn1ef,项目名称:SilverStripe-Jobamatic-Module,代码行数:23,代码来源:JobamaticPage.php

示例13: requireDefaultRecords

 /**
  * Change the home page to HomePage type
  */
 public function requireDefaultRecords()
 {
     if (!SiteTree::get_by_link("home")) {
         $homepage = new HomePage();
         ${$homepage}->Title = "Home";
         $homepage->URLSegment = "home";
         $homepage->Sort = 1;
         $homepage->write();
         $homepage->publish('Stage', 'Live');
         $homepage->flushCache();
         DB::alteration_message('Home Page created', 'created');
     } else {
         $homepage = SiteTree::get_by_link("home");
         if ($homepage->ClassName != "HomePage") {
             $homepage = $homepage->newClassInstance("HomePage");
             $homepage->write();
             $homepage->publish('Stage', 'Live');
             $homepage->flushCache();
             DB::alteration_message('Home changed to HomePage', 'changed');
         }
     }
     parent::requireDefaultRecords();
 }
开发者ID:thezenmonkey,项目名称:quickstripe,代码行数:26,代码来源:HomePage.php

示例14: requireDefaultRecords

 /**
  * Change the contact-us page to ContactUsPage type
  */
 function requireDefaultRecords()
 {
     if (!SiteTree::get_by_link("contact-us")) {
         $contactpage = new HomePage();
         $contactpage->Title = "Contact Us";
         $contactpage->URLSegment = "contact-us";
         $contactpage->Sort = 3;
         $contactpage->write();
         $contactpage->publish('Stage', 'Live');
         $contactpage->flushCache();
         DB::alteration_message('Contact Us created', 'created');
     } else {
         $contactpage = SiteTree::get_by_link("contact-us");
         if ($contactpage->ClassName != "ContactUsPage") {
             $contactpage = $contactpage->newClassInstance("ContactUsPage");
             $contactpage->write();
             $contactpage->publish('Stage', 'Live');
             $contactpage->flushCache();
             DB::alteration_message('Contact Us changed to ContactUsPage', 'changed');
         }
     }
     parent::requireDefaultRecords();
 }
开发者ID:helpfulrobot,项目名称:thezenmonkey-quickstripe,代码行数:26,代码来源:ContactUsPage.php

示例15: SiteTreeHints

 /**
  * Create serialized JSON string with site tree hints data to be injected into
  * 'data-hints' attribute of root node of jsTree.
  * 
  * @return String Serialized JSON
  */
 public function SiteTreeHints()
 {
     $json = '';
     $classes = SiteTree::page_type_classes();
     $cacheCanCreate = array();
     foreach ($classes as $class) {
         $cacheCanCreate[$class] = singleton($class)->canCreate();
     }
     // Generate basic cache key. Too complex to encompass all variations
     $cache = SS_Cache::factory('CMSMain_SiteTreeHints');
     $cacheKey = md5(implode('_', array(Member::currentUserID(), implode(',', $cacheCanCreate), implode(',', $classes))));
     if ($this->request->getVar('flush')) {
         $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     }
     $json = $cache->load($cacheKey);
     if (!$json) {
         $def['Root'] = array();
         $def['Root']['disallowedChildren'] = array();
         // Contains all possible classes to support UI controls listing them all,
         // such as the "add page here" context menu.
         $def['All'] = array();
         // Identify disallows and set globals
         $globalDisallowed = array();
         foreach ($classes as $class) {
             $obj = singleton($class);
             $needsPerm = $obj->stat('need_permission');
             if (!$obj instanceof HiddenClass) {
                 $def['All'][$class] = array('title' => $obj->i18n_singular_name());
             }
             if (!$obj->stat('can_be_root')) {
                 $def['Root']['disallowedChildren'][] = $class;
             }
             if ($obj instanceof HiddenClass || (!array_key_exists($class, $cacheCanCreate) || !$cacheCanCreate[$class]) || $needsPerm && !$this->can($needsPerm)) {
                 $globalDisallowed[] = $class;
                 $def['Root']['disallowedChildren'][] = $class;
             }
         }
         // Set disallows by class
         foreach ($classes as $class) {
             $obj = singleton($class);
             if ($obj instanceof HiddenClass) {
                 continue;
             }
             $def[$class] = array();
             $allowed = $obj->allowedChildren();
             if ($pos = array_search('SiteTree', $allowed)) {
                 unset($allowed[$pos]);
             }
             // Start by disallowing all classes which aren't specifically allowed,
             // then add the ones which are globally disallowed.
             $disallowed = array_diff($classes, (array) $allowed);
             $disallowed = array_unique(array_merge($disallowed, $globalDisallowed));
             // Re-index the array for JSON non sequential key issue
             if ($disallowed) {
                 $def[$class]['disallowedChildren'] = array_values($disallowed);
             }
             $defaultChild = $obj->defaultChild();
             if ($defaultChild != 'Page' && $defaultChild != null) {
                 $def[$class]['defaultChild'] = $defaultChild;
             }
             $defaultParent = $obj->defaultParent();
             $parent = SiteTree::get_by_link($defaultParent);
             $id = $parent ? $parent->id : null;
             if ($defaultParent != 1 && $defaultParent != null) {
                 $def[$class]['defaultParent'] = $defaultParent;
             }
         }
         $this->extend('updateSiteTreeHints', $def);
         $json = Convert::raw2json($def);
         $cache->save($json, $cacheKey);
     }
     return $json;
 }
开发者ID:hemant-chakka,项目名称:awss,代码行数:79,代码来源:CMSMain.php


注:本文中的SiteTree::get_by_link方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。