/**
  * normally returns TRUE, but returns FALSE when it, or its parent is in the list.
  * todo: add products in other product categories
  * @param SiteTree $page
  * @return Boolean
  */
 function canBeDiscounted(SiteTree $page)
 {
     if ($this->owner->PageIDs) {
         $allowedPageIDs = explode(',', $this->owner->PageIDs);
         $checkPages = new ArrayList(array($page));
         $alreadyCheckedPageIDs = array();
         while ($checkPages->Count()) {
             $page = $checkPages->First();
             if (array_search($page->ID, $allowedPageIDs) !== false) {
                 return true;
             }
             $alreadyCheckedPageIDs[] = $page->ID;
             $checkPages->remove($page);
             // Parents list update
             if ($page->hasMethod('AllParentGroups')) {
                 $parents = new ArrayList($page->AllParentGroups()->toArray());
             } else {
                 $parents = new ArrayList();
             }
             $parent = $page->Parent();
             if ($parent && $parent->exists()) {
                 $parents->unshift($parent);
             }
             foreach ($parents as $parent) {
                 if (array_search($parent->ID, $alreadyCheckedPageIDs) === false) {
                     $checkPages->push($parent);
                 }
             }
             $checkPages->removeDuplicates();
         }
         return false;
     }
     return true;
 }
 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;
             }
         }
     }
 }