本文整理汇总了PHP中SiteTree::get方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::get方法的具体用法?PHP SiteTree::get怎么用?PHP SiteTree::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteTree
的用法示例。
在下文中一共展示了SiteTree::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upClass
/**
* Migrate records of a single class
*
* @param string $class
* @param null|string $stage
*/
protected function upClass($class)
{
if (!class_exists($class)) {
return;
}
if (is_subclass_of($class, 'SiteTree')) {
$items = SiteTree::get()->filter('ClassName', $class);
} else {
$items = $class::get();
}
if ($count = $items->count()) {
$this->message(sprintf('Migrating %s legacy %s records.', $count, $class));
foreach ($items as $item) {
$cancel = $item->extend('onBeforeUp');
if ($cancel && min($cancel) === false) {
continue;
}
/**
* @var MigratableObject $item
*/
$result = $item->up();
$this->message($result);
$item->extend('onAfterUp');
}
}
}
示例2: init
function init()
{
parent::init();
$id = 0;
if ($this->request->param("OwnerID")) {
$id = intval($this->request->param("OwnerID"));
} elseif (isset($_GET["i"])) {
$i = intval($_GET["i"]);
$point = GoogleMapLocationsObject::get()->byID($i);
if (!$point) {
//New POINT
} else {
$id = $point->ParentID;
}
}
if ($id) {
$this->owner = SiteTree::get()->byID($id);
} elseif (!$this->owner) {
$this->owner = SiteTree::get()->filter(array("Title" => Convert::raw2sql($this->request->param("Title"))))->First();
}
if (!$this->owner & !in_array($this->request->param("Action"), self::$actions_without_owner)) {
//user_error("no owner has been identified for GoogleMapDataResponse", E_USER_NOTICE);
$this->owner = SiteTree::get()->First();
}
//END HACK
$this->title = urldecode($this->request->param("Title"));
$this->sessionTitle = $sessionTitle = preg_replace('/[^a-zA-Z0-9]/', '', $this->title);
$this->lng = floatval($this->request->param("Longitude"));
$this->lat = floatval($this->request->param("Latitude"));
$this->filter = urldecode($this->request->param("Filter"));
if (!$this->title && $this->owner) {
$this->title = $this->owner->Title;
}
}
示例3: 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
示例4: getSiteMenu
/**
* This method should be used to built navigation menus in templates,
* instead of ContentController->getMenu()
* @return ArrayList
**/
public function getSiteMenu($level = 1)
{
$site = Multisites::inst()->getCurrentSite();
$page = $this->owner->data();
$result = new ArrayList();
if ($level == 1) {
$pages = SiteTree::get()->filter(array('ParentID' => $site ? $site->ID : 0, 'ShowInMenus' => true));
} else {
$parent = $page;
$stack = array($page);
while (($parent = $parent->Parent()) && $parent->ID > 0 && !$parent instanceof Site) {
array_unshift($stack, $parent);
}
if (!isset($stack[$level - 2])) {
return;
}
$pages = $stack[$level - 2]->Children();
}
foreach ($pages as $page) {
if ($page->canView()) {
$result->push($page);
}
}
return $result;
}
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-multisites,代码行数:30,代码来源:MultisitesContentControllerExtension.php
示例5: 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;
}
示例6: 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();
}
}
示例7: flushSiteTree
public static function flushSiteTree($sitetreeID)
{
$sitetree = SiteTree::get()->byID($sitetreeID);
if ($sitetree && $sitetree->exists()) {
$strategy = Config::inst()->get('SectionIO', 'sitetree_flush_strategy');
switch ($strategy) {
case 'single':
$exp = 'obj.http.content-type ~ "' . preg_quote('text/html') . '"';
$exp .= ' && obj.http.x-url ~ "^' . preg_quote($sitetree->Link()) . '$"';
break;
case 'parents':
$exp = 'obj.http.content-type ~ "' . preg_quote('text/html') . '"';
$exp .= ' && (obj.http.x-url ~ "^' . preg_quote($sitetree->Link()) . '$"';
$parent = $sitetree->getParent();
while ($parent && $parent->exists()) {
$exp .= ' || obj.http.x-url ~ "^' . preg_quote($parent->Link()) . '$"';
$parent = $parent->getParent();
}
$exp .= ')';
break;
case 'all':
$exp = 'obj.http.content-type ~ "' . preg_quote('text/html') . '"';
break;
case 'everyting':
default:
$exp = 'obj.http.x-url ~ /';
break;
}
return static::performFlush($exp);
}
return false;
}
示例8: handleAction
public function handleAction(\GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName != $this->urlSegment) {
return;
}
$record = $gridField->Form && $gridField->Form->Record ? $gridField->Form->Record : null;
if (!$record || !$record->SiteTreeID) {
throw new \ValidationException(_t('Link.NO_CURRENT_PAGE', 'No current page to draw from'), 0);
}
$root = \SiteTree::get()->filter('ParentID', $record->SiteTreeID);
if (!$root->exists()) {
throw new \ValidationException(_t('Link.NO_PAGES', 'No pages available'), 0);
}
$item = singleton($gridField->getModelClass());
if (!$item->canCreate()) {
throw new \ValidationException(_t('Link.CANNOT_CREATE', 'You cannot create a Link'), 0);
}
foreach ($root as $page) {
$link = $item->create();
$link->Type = 'SiteTree';
$link->SiteTreeID = $page->ID;
$link->write();
$gridField->getList()->add($link);
}
}
示例9: 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;
}
示例10: performance
function performance($request)
{
$markers = array();
$q = substr(GoogleAnalyzer::get_sapphire_version(), 0, 3) == '2.3' ? '`' : '"';
$metrics = $request->requestVar('metrics');
$filters = null;
$eventfiltersql = "{$q}GoogleLogEvent{$q}.{$q}PageID{$q} = 0";
$page = SiteTree::get()->byID((int) $request->param('ID'));
if ($page) {
$url = trim($page->Link(), '/');
if (!empty($url)) {
$url .= '/';
}
$filters = 'ga:pagePath==/' . $url;
$eventfiltersql .= " OR {$q}GoogleLogEvent{$q}.{$q}PageID{$q} = " . (int) $page->ID;
$allversions = $q == '"' ? '"WasPublished" = 1 AND ' . DB::getConn()->datetimeDifferenceClause('"LastEdited"', date('Y-m-d 23:59:59', strtotime('-1 Year'))) . ' > 0' : "{$q}WasPublished{$q} = 1 AND {$q}LastEdited{$q} > '" . date('Y-m-d 23:59:59', strtotime('-1 Year')) . "'";
foreach ($page->allVersions() as $version) {
$markers[] = array(strtotime($version->LastEdited) * 1000, 'Updated', 'Long descr.');
}
}
$events = DataObject::get('GoogleLogEvent', $eventfiltersql);
if ($events) {
foreach ($events as $event) {
$markers[] = array(strtotime($event->Created) * 1000, $event->Title, 'Long descr.');
}
}
$store = new GoogleDataStore(GoogleConfig::get_google_config('profile'), GoogleConfig::get_google_config('email'), GoogleConfig::get_google_config('password'));
$data = $store->fetchPerformance(array('dimensions' => 'ga:date', 'metrics' => 'ga:visits,ga:pageviews', 'sort' => '-ga:date', 'filters' => $filters));
return json_encode(array('series' => $data, 'markers' => $markers));
}
开发者ID:helpfulrobot,项目名称:jelicanin-silverstripe-googleanalytics,代码行数:30,代码来源:GoogleDataController.php
示例11: publishPageAndBlocks
public function publishPageAndBlocks($data, $form)
{
// regular save
$this->owner->save($data, $form);
// Now publish the whole bunch
if ($page = SiteTree::get()->byID($data['ID'])) {
if (!$page->canPublish()) {
throw new SS_HTTPResponse_Exception("Publish page not allowed", 403);
}
// else: publish page (also triggers editable columns/rows write())
$page->doPublish();
// and publish any blocks which the user's allowed to publish (have already been written)
if (is_callable(array($page, 'Blocks'))) {
foreach ($page->Blocks() as $block) {
// skip any blocks that we cannot publish
if (!$block->canPublish()) {
continue;
}
// publish
$block->invokeWithExtensions('onBeforePublish', $block);
$block->publish('Stage', 'Live');
$block->invokeWithExtensions('onAfterPublish', $block);
}
}
} else {
throw new SS_HTTPResponse_Exception("Bad page ID #" . (int) $data['ID'], 404);
}
// this generates a message that will show up in the CMS
$this->owner->response->addHeader('X-Status', rawurlencode("Page + blocks published"));
return $this->owner->getResponseNegotiator()->respond($this->owner->request);
}
示例12: requireDefaultRecords
function requireDefaultRecords()
{
if ($this->class == 'TestPage') {
return;
}
$class = $this->class;
if (!DataObject::get_one($class)) {
// Try to create common parent
$parent = SiteTree::get()->filter('URLSegment', 'feature-test-pages')->First();
if (!$parent) {
$parent = new Page(array('Title' => 'Feature Test Pages', 'Content' => 'A collection of pages for testing various features in the SilverStripe CMS', 'ShowInMenus' => 0));
$parent->write();
$parent->doPublish();
}
// Create actual page
$page = new $class();
$page->Title = str_replace("TestPage", "", $class);
$page->ShowInMenus = 0;
if ($parent) {
$page->ParentID = $parent->ID;
}
$page->write();
$page->publish('Stage', 'Live');
}
}
示例13: get_homepage_link
/**
* Get the full form (e.g. /home/) relative link to the home page for the current HTTP_HOST value. Note that the
* link is trimmed of leading and trailing slashes before returning to ensure consistency.
*
* @return string
*/
public static function get_homepage_link()
{
if (!self::$cached_homepage_link) {
// @todo Move to 'homepagefordomain' module
if (class_exists('HomepageForDomainExtension')) {
$host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
$candidates = SiteTree::get()->where(array('"SiteTree"."HomepageForDomain" LIKE ?' => "%{$host}%"));
if ($candidates) {
foreach ($candidates as $candidate) {
if (preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
}
}
}
}
if (!self::$cached_homepage_link) {
// TODO Move to 'translatable' module
if (class_exists('Translatable') && SiteTree::has_extension('Translatable') && ($link = Translatable::get_homepage_link_by_locale(Translatable::get_current_locale()))) {
self::$cached_homepage_link = $link;
} else {
self::$cached_homepage_link = Config::inst()->get('RootURLController', 'default_homepage_link');
}
}
}
return self::$cached_homepage_link;
}
示例14: process
public function process()
{
$classes = array();
$types = $this->types;
foreach ($types as $t) {
if (class_exists($t)) {
$pages = SiteTree::get()->filter(array('ClassName' => $t));
$urls = array();
// only used for later context
$object = null;
foreach ($pages as $object) {
if (singleton('SimpleCachePublisher')->dontCache($object)) {
continue;
}
if ($object->hasMethod('pagesAffectedByChanges')) {
$pageUrls = $object->pagesAffectedByChanges();
foreach ($pageUrls as $url) {
$urls[] = $url;
}
} else {
$urls[] = $object->AbsoluteLink();
}
}
if ($object) {
$job = new SimpleCachePublishingJob($object, $urls);
singleton('QueuedJobService')->queueJob($job);
}
}
$this->currentStep++;
}
$this->isComplete = 1;
$nextRun = date('Y-m-d H:i:s', time() + $this->schedule);
$job = new ScheduledRepublishJob($this->types, $this->schedule);
singleton('QueuedJobService')->queueJob($job, $nextRun);
}
示例15: create_nav
public static function create_nav()
{
// remove the protocol from the URL, otherwise we run into https/http issues
$url = self::remove_protocol_from_url(self::get_toolbar_hostname());
$html = ViewableData::create()->customise(array('ToolbarHostname' => $url, 'Pages' => SiteTree::get()->filter(array('ParentID' => 0, 'ShowInGlobalNav' => true)), 'GoogleCustomSearchId' => Config::inst()->get('GlobalNav', 'google_search_id')))->renderWith('GlobalNavbar');
$path = Config::inst()->get('GlobalNav', 'snippet_path');
file_put_contents(BASE_PATH . $path, $html);
}