/** * Returns a pages change frequency calculated by pages age and number of * versions. Google expects always, hourly, daily, weekly, monthly, yearly * or never as values. * * @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic * * @return SS_Datetime */ public function getChangeFrequency() { if ($freq = GoogleSitemap::get_frequency_for_class($this->owner->class)) { return $freq; } $date = date('Y-m-d H:i:s'); $created = new SS_Datetime(); $created->value = $this->owner->Created ? $this->owner->Created : $date; $now = new SS_Datetime(); $now->value = $date; $versions = $this->owner->Version ? $this->owner->Version : 1; $timediff = $now->format('U') - $created->format('U'); // Check how many revisions have been made over the lifetime of the // Page for a rough estimate of it's changing frequency. $period = $timediff / ($versions + 1); if ($period > 60 * 60 * 24 * 365) { $freq = 'yearly'; } elseif ($period > 60 * 60 * 24 * 30) { $freq = 'monthly'; } elseif ($period > 60 * 60 * 24 * 7) { $freq = 'weekly'; } elseif ($period > 60 * 60 * 24) { $freq = 'daily'; } elseif ($period > 60 * 60) { $freq = 'hourly'; } else { $freq = 'always'; } return $freq; }
public function getChangeFrequency() { $date = date('Y-m-d H:i:s'); $created = new SS_Datetime(); $created->value = $this->owner->Created ? $this->owner->Created : $date; $now = new SS_Datetime(); $now->value = $date; $versions = $this->owner->Version ? $this->owner->Version : 1; $timediff = $now->format('U') - $created->format('U'); // Check how many revisions have been made over the lifetime of the // Page for a rough estimate of it's changing frequency. $period = $timediff / ($versions + 1); if ($period > 60 * 60 * 24 * 365) { $freq = GoogleSiteMapGenerator::CHANGE_FREQ_YEARLY; } elseif ($period > 60 * 60 * 24 * 30) { $freq = GoogleSiteMapGenerator::CHANGE_FREQ_MONTHLY; } elseif ($period > 60 * 60 * 24 * 7) { $freq = GoogleSiteMapGenerator::CHANGE_FREQ_WEEKLY; } elseif ($period > 60 * 60 * 24) { $freq = GoogleSiteMapGenerator::CHANGE_FREQ_DAILY; } elseif ($period > 60 * 60) { $freq = GoogleSiteMapGenerator::CHANGE_FREQ_HOURLY; } else { $freq = GoogleSiteMapGenerator::CHANGE_FREQ_ALWAYS; } return $freq; }
public function Items() { $filter = ''; $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; if (self::$use_show_in_search) { $filter = "{$bt}ShowInSearch{$bt} = 1"; } $this->Pages = Versioned::get_by_stage('SiteTree', 'Live', $filter); $newPages = new DataObjectSet(); if ($this->Pages) { foreach ($this->Pages as $page) { // Only include pages from this host and pages which are not an instance of ErrorPage // We prefix $_SERVER['HTTP_HOST'] with 'http://' so that parse_url to help parse_url identify the host name component; we could use another protocol (like // 'ftp://' as the prefix and the code would work the same. if (parse_url($page->AbsoluteLink(), PHP_URL_HOST) == parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST) && !$page instanceof ErrorPage) { // If the page has been set to 0 priority, we set a flag so it won't be included if ($page->canView() && (!isset($page->Priority) || $page->Priority > 0)) { // The one field that isn't easy to deal with in the template is // Change frequency, so we set that here. $properties = $page->toMap(); $created = new SS_Datetime(); $created->value = $properties['Created']; $now = new SS_Datetime(); $now->value = date('Y-m-d H:i:s'); $versions = $properties['Version']; $timediff = $now->format('U') - $created->format('U'); // Check how many revisions have been made over the lifetime of the // Page for a rough estimate of it's changing frequency. $period = $timediff / ($versions + 1); if ($period > 60 * 60 * 24 * 365) { // > 1 year $page->ChangeFreq = 'yearly'; } elseif ($period > 60 * 60 * 24 * 30) { // > ~1 month $page->ChangeFreq = 'monthly'; } elseif ($period > 60 * 60 * 24 * 7) { // > 1 week $page->ChangeFreq = 'weekly'; } elseif ($period > 60 * 60 * 24) { // > 1 day $page->ChangeFreq = 'daily'; } elseif ($period > 60 * 60) { // > 1 hour $page->ChangeFreq = 'hourly'; } else { // < 1 hour $page->ChangeFreq = 'always'; } $newPages->push($page); } } } return $newPages; } }
public function process() { if (!$this->tempFile) { throw new Exception("Temporary sitemap file has not been set"); } if (!file_exists($this->tempFile)) { throw new Exception("Temporary file {$this->tempFile} has been deleted!"); } $remainingChildren = $this->pagesToProcess; // if there's no more, we're done! if (!count($remainingChildren)) { $this->completeJob(); $this->isComplete = true; return; } // lets process our first item - note that we take it off the list of things left to do $ID = array_shift($remainingChildren); // get the page $page = Versioned::get_by_stage('Page', 'Live', '"SiteTree_Live"."ID" = ' . $ID); if (!$page || !$page->Count()) { $this->addMessage("Page ID #{$ID} could not be found, skipping"); } else { $page = $page->First(); } if ($page && $page instanceof Page && !$page instanceof ErrorPage) { if ($page->canView() && (!isset($page->Priority) || $page->Priority > 0)) { $created = $page->dbObject('Created'); $now = new SS_Datetime(); $now->value = date('Y-m-d H:i:s'); $versions = $page->Version; $timediff = $now->format('U') - $created->format('U'); // Check how many revisions have been made over the lifetime of the // Page for a rough estimate of it's changing frequency. $period = $timediff / ($versions + 1); if ($period > 60 * 60 * 24 * 365) { // > 1 year $page->ChangeFreq = 'yearly'; } elseif ($period > 60 * 60 * 24 * 30) { // > ~1 month $page->ChangeFreq = 'monthly'; } elseif ($period > 60 * 60 * 24 * 7) { // > 1 week $page->ChangeFreq = 'weekly'; } elseif ($period > 60 * 60 * 24) { // > 1 day $page->ChangeFreq = 'daily'; } elseif ($period > 60 * 60) { // > 1 hour $page->ChangeFreq = 'hourly'; } else { // < 1 hour $page->ChangeFreq = 'always'; } // do the generation of the file in a temporary location $content = $page->renderWith('SitemapEntry'); $fp = fopen($this->tempFile, "a"); if (!$fp) { throw new Exception("Could not open {$this->tempFile} for writing"); } fputs($fp, $content, strlen($content)); fclose($fp); } } // and now we store the new list of remaining children $this->pagesToProcess = $remainingChildren; $this->currentStep++; if (!count($remainingChildren)) { $this->completeJob(); $this->isComplete = true; return; } }
public function process() { if (!$this->tempFile) { throw new Exception("Temporary sitemap file has not been set"); } if (!file_exists($this->tempFile)) { throw new Exception("Temporary file {$this->tempFile} has been deleted!"); } $remainingChildren = $this->toProcess; // if there's no more, we're done! if (!count($remainingChildren)) { $this->completeJob(); $this->isComplete = true; return; } // lets process our first item - note that we take it off the list of things left to do $ID = array_shift($remainingChildren); $post = DataList::create('MicroPost')->byID($ID); if (!$post || !$post->exists()) { $this->addMessage("Post ID #{$ID} could not be found, skipping"); } if ($post) { $created = $post->dbObject('Created'); $now = new SS_Datetime(); $now->value = date('Y-m-d H:i:s'); $timediff = $now->format('U') - $created->format('U'); $period = $timediff; if ($period > 60 * 60 * 24 * 7) { // > 1 week $post->ChangeFreq = 'weekly'; } else { $post->ChangeFreq = 'daily'; } // do the generation of the file in a temporary location $content = $post->renderWith('SitemapEntry'); $fp = fopen($this->tempFile, "a"); if (!$fp) { throw new Exception("Could not open {$this->tempFile} for writing"); } fputs($fp, $content, strlen($content)); fclose($fp); } // and now we store the new list of remaining children $this->toProcess = $remainingChildren; $this->currentStep++; if (!count($remainingChildren)) { $this->completeJob(); $this->isComplete = true; return; } }