コード例 #1
0
 /**
  * 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
0
 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;
     }
 }
 /**
  * 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" />';
 }
 /**
  * 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;
 }
コード例 #5
0
 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;
 }
 /**
  * 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
0
 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;
 }
 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
0
 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;
 }
 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));
 }
 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
0
 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
0
 /**
  * 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;
 }
 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
0
 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);
 }
コード例 #16
0
 function pagesAffectedByChanges()
 {
     $urls = $this->subPagesToCache();
     if ($parent = SiteTree::get()->byID($this->owner->ParentID)) {
         $urls = array_merge((array) $urls, (array) $parent->subPagesToCache());
     }
     return $urls;
 }
コード例 #17
0
 /**
  * A form action that takes the current page ID to populate it with mock data
  *
  * @param array $data The data passed in from the form
  * @param CMSForm $form The Form object that was used
  */
 public function addMockData($data, $form)
 {
     if ($page = SiteTree::get()->byID($data['ID'])) {
         $page->fill(array('only_empty' => true, 'include_relations' => false, 'download_images' => false));
         $this->owner->response->addHeader('X-Status', 'Added mock data');
     }
     return $this->owner->getResponseNegotiator()->respond($this->owner->request);
 }
 /**
  * Finds the controller for this page under the given parent id
  */
 public function getNestedController()
 {
     // Extract values stored in route
     $parentID = $this->request->param('ParentID');
     $URLSegment = $this->request->param('URLSegment');
     // get child page
     $sitetree = SiteTree::get()->filter(array("URLSegment" => $URLSegment, "ParentID" => $parentID))->first();
     return self::controller_for($sitetree, $this->request->param('Action'));
 }
コード例 #19
0
 public function getCMSFields()
 {
     $pageDropDown = new DropdownField('SiteTreeID', 'LinkedPage', SiteTree::get()->sort('Title')->map('ID', 'Title'));
     $pageDropDown->setEmptyString('(Select Page)');
     $fields = parent::getCMSFields();
     $fields->push($pageDropDown);
     $fields->push(new TextField('LinkLabel'));
     return $fields;
 }
コード例 #20
0
 /**
  * Gets the recent edited pages, limited to a user provided number of records
  *
  * @return ArrayList
  */
 public function RecentEdits()
 {
     $records = SiteTree::get()->sort("LastEdited DESC")->limit($this->Count);
     $set = ArrayList::create(array());
     foreach ($records as $r) {
         $set->push(ArrayData::create(array('EditLink' => Injector::inst()->get("CMSPagesController")->Link("edit/show/{$r->ID}"), 'Title' => $r->Title)));
     }
     return $set;
 }
コード例 #21
0
 public function up()
 {
     foreach (['Stage', 'Live'] as $stage) {
         Versioned::reading_stage($stage);
         $pages = SiteTree::get()->where("\n\t\t\t\tURLSegment LIKE '%-ja-jp' OR\n\t\t\t\tURLSegment LIKE '%-zh-cmn' OR\n\t\t\t\tURLSegment LIKE '%-de-DE' OR\n\t\t\t\tURLSegment LIKE '%-es-ES'\n\t\t\t");
         $count = $pages->count();
         $pages->removeAll();
         echo "Deleted {$count} pages from {$stage}.\n";
     }
 }
コード例 #22
0
ファイル: Lumberjack.php プロジェクト: namnn/installer
 /**
  * This is responsible for adding the child pages tab and gridfield.
  *
  * @param FieldList $fields
  */
 public function updateCMSFields(FieldList $fields)
 {
     $excluded = $this->owner->getExcludedSiteTreeClassNames();
     if (!empty($excluded)) {
         $pages = SiteTree::get()->filter(array('ParentID' => $this->owner->ID, 'ClassName' => $excluded));
         $gridField = new GridField("ChildPages", $this->getLumberjackTitle(), $pages, $this->getLumberjackGridFieldConfig());
         $tab = new Tab('ChildPages', $this->getLumberjackTitle(), $gridField);
         $fields->insertAfter($tab, 'Main');
     }
 }
 function Link()
 {
     if ($this->URL) {
         return $this->URL;
     } elseif ($this->InternalLinkID) {
         $page = SiteTree::get()->byID($this->InternalLinkID);
         if ($page->exists()) {
             return $page->Link();
         }
     }
 }
コード例 #24
0
 public function run($request)
 {
     $locale = Translatable::default_locale();
     $pages = SiteTree::get()->where("Locale='{$locale}'");
     foreach ($pages as $page) {
         $translated = $page->createTranslation("en_GB");
         $translated->doPublish();
         // $page->doUnpublish();
         // $page->delete();
     }
 }
 function removealladvertisements($request)
 {
     $id = intval($request->param("ID")) - 0;
     $page = SiteTree::get()->byID($id);
     if (!$page) {
         return "this page does not exist";
     }
     DB::query("DELETE FROM SiteTree_Advertisements WHERE SiteTreeID = " . $id);
     DB::query("UPDATE SiteTree SET AdvertisementsFolderID = 0 WHERE SiteTree.ID = " . $id);
     DB::query("UPDATE SiteTree_Live SET AdvertisementsFolderID = 0 WHERE SiteTree_Live.ID = " . $id);
     return sprintf(_t("AdvertisementController.REMOVEDALL", 'Removed all %1$s from this page, please reload page to see results.'), Config::inst()->get("Advertisement", "plural_name"));
 }
 /**
  * Deteremines whether this Blog Entry belongs to an Emergency Feed
  */
 function isEmergencyFeed()
 {
     $isEmergencyFeed = false;
     $parentID = $this->owner->ParentID;
     if ($parentID != 0) {
         $parent = SiteTree::get()->byID($parentID);
         if ($parent->ClassName == 'BlogHolder' && $parent->EmergencyFeed) {
             $isEmergencyFeed = true;
         }
     }
     return $isEmergencyFeed;
 }
 function __construct($page = null)
 {
     parent::__construct();
     switch (true) {
         case $page instanceof SiteTree:
             $this->page = $page;
             break;
         case is_numeric($page):
             $page = SiteTree::get()->byID((int) $page);
             break;
     }
 }
コード例 #28
0
 /**
  * @param array $params
  *
  * @return SS_List
  */
 public function sourceRecords($params = array())
 {
     Versioned::reading_stage("Stage");
     $records = SiteTree::get();
     $compatibility = ContentReviewCompatability::start();
     if (empty($params["ReviewDateBefore"]) && empty($params["ReviewDateAfter"])) {
         // If there's no review dates set, default to all pages due for review now
         $reviewDate = new Zend_Date(SS_Datetime::now()->Format("U"));
         $reviewDate->add(1, Zend_Date::DAY);
         $records = $records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString("YYYY-MM-dd")));
     } else {
         // Review date before
         if (!empty($params['ReviewDateBefore'])) {
             // TODO Get value from DateField->dataValue() once we have access to form elements here
             $reviewDate = new Zend_Date($params["ReviewDateBefore"], Config::inst()->get("i18n", "date_format"));
             $reviewDate->add(1, Zend_Date::DAY);
             $records = $records->where(sprintf("\"NextReviewDate\" < '%s'", $reviewDate->toString("YYYY-MM-dd")));
         }
         // Review date after
         if (!empty($params["ReviewDateAfter"])) {
             // TODO Get value from DateField->dataValue() once we have access to form elements here
             $reviewDate = new Zend_Date($params["ReviewDateAfter"], Config::inst()->get("i18n", "date_format"));
             $records = $records->where(sprintf("\"NextReviewDate\" >= '%s'", $reviewDate->toString("YYYY-MM-dd")));
         }
     }
     // Show virtual pages?
     if (empty($params["ShowVirtualPages"])) {
         $virtualPageClasses = ClassInfo::subclassesFor("VirtualPage");
         $records = $records->where(sprintf("\"SiteTree\".\"ClassName\" NOT IN ('%s')", implode("','", array_values($virtualPageClasses))));
     }
     // Owner dropdown
     if (!empty($params["ContentReviewOwner"])) {
         $ownerNames = Convert::raw2sql($params["ContentReviewOwner"]);
         $records = $records->filter("OwnerNames:PartialMatch", $ownerNames);
     }
     // Only show pages assigned to the current user?
     // This come last because it transforms $records to an ArrayList.
     if (!empty($params["OnlyMyPages"])) {
         $currentUser = Member::currentUser();
         $records = $records->filterByCallback(function ($page) use($currentUser) {
             $options = $page->getOptions();
             foreach ($options->ContentReviewOwners() as $owner) {
                 if ($currentUser->ID == $owner->ID) {
                     return true;
                 }
             }
             return false;
         });
     }
     ContentReviewCompatability::done($compatibility);
     return $records;
 }
コード例 #29
0
 public function onAfterInit()
 {
     if (!Director::isDev()) {
         // Only on live site
         $errorcode = $this->owner->failover->ErrorCode ? $this->owner->failover->ErrorCode : 404;
         $extract = preg_match('/^([a-z0-9\\.\\_\\-\\/]+)/i', $_SERVER['REQUEST_URI'], $rawString);
         if ($errorcode == 404 && $extract) {
             $uri = preg_replace('/\\.(aspx?|html?|php[34]?)$/i', '', $rawString[0]);
             $parts = preg_split('/\\//', $uri, -1, PREG_SPLIT_NO_EMPTY);
             $page_key = array_pop($parts);
             $sounds_like = soundex($page_key);
             // extend ignored classes with child classes
             $ignoreClassNames = array();
             if ($configClasses = Config::inst()->get('Intelligent404', 'intelligent_404_ignored_classes')) {
                 foreach ($configClasses as $class) {
                     $ignoreClassNames = array_merge($ignoreClassNames, array_values(ClassInfo::subclassesFor($class)));
                 }
             }
             // get all pages
             $SiteTree = SiteTree::get()->exclude('ClassName', $ignoreClassNames);
             // Translatable support
             if (class_exists('Translatable')) {
                 $SiteTree = $SiteTree->filter('Locale', Translatable::get_current_locale());
             }
             // Multisites support
             if (class_exists('Multisites')) {
                 $SiteTree = $SiteTree->filter('SiteID', Multisites::inst()->getCurrentSiteId());
             }
             $ExactMatches = new ArrayList();
             $PossibleMatches = new ArrayList();
             foreach ($SiteTree as $page) {
                 if ($page->URLSegment == $page_key) {
                     $ExactMatches->push($page);
                 } elseif ($sounds_like == soundex($page->URLSegment)) {
                     $PossibleMatches->push($page);
                 }
             }
             $ExactCount = $ExactMatches->Count();
             $PossibleCount = $PossibleMatches->Count();
             $redirectOnSingleMatch = Config::inst()->get('Intelligent404', 'redirect_on_single_match');
             if ($ExactCount == 1 && $redirectOnSingleMatch) {
                 return $this->RedirectToPage($ExactMatches->First()->Link());
             } elseif ($ExactCount == 0 && $PossibleCount == 1 && $redirectOnSingleMatch) {
                 return $this->RedirectToPage($PossibleMatches->First()->Link());
             } elseif ($ExactCount > 1 || $PossibleCount > 1 || !$redirectOnSingleMatch) {
                 $ExactMatches->merge($PossibleMatches);
                 $content = $this->owner->customise(array('Pages' => $ExactMatches))->renderWith(array('Intelligent404Options'));
                 $this->owner->Content .= $content;
             }
         }
     }
 }
コード例 #30
0
 /**
  * Returns a list of pages this BlockSet features on.
  *
  * @return DataList
  */
 public function Pages()
 {
     $pages = SiteTree::get();
     $types = $this->PageTypes->getValue();
     if (count($types)) {
         $pages = $pages->filter('ClassName', $types);
     }
     $parents = $this->PageParents()->column('ID');
     if (count($parents)) {
         $pages = $pages->filter('ParentID', $parents);
     }
     return $pages;
 }