<commit_before><?php
/**
 * Initial implementation of Sitemap support.
 * GoogleSitemap should handle requests to 'sitemap.xml'
 * the other two classes are used to render the sitemap.
 * 
 * You can notify ("ping") Google about a changed sitemap
 * automatically whenever a new page is published or unpublished.
 * By default, Google is not notified, and will pick up your new
 * sitemap whenever the GoogleBot visits your website.
 * 
 * Enabling notification of Google after every publish (in your _config.php):
 * <example
 * GoogleSitemap::enable_google_notificaton();
 * </example>
 * 
 * @see http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=34609
 * 
 * @package sapphire
 * @subpackage misc
 */
class GoogleSitemap extends Controller {
	
	/**
	 * @var boolean
	 */
	protected static $enabled = true;
	
	/**
	 * @var DataObjectSet
	 */
	protected $Pages;
	
	/**
	 * @var boolean
	 */
	protected static $google_notification_enabled = false;
	
	public function Items() {
		$this->Pages = Versioned::get_by_stage('SiteTree', 'Live');

		$newPages = new DataObjectSet();
		
		foreach($this->Pages as $page) {
			// Only include pages from this host and pages which are not an instance of ErrorPage 
			if(parse_url($page->AbsoluteLink(), PHP_URL_HOST) == $_SERVER['HTTP_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 SSDatetime();
					$created->value = $properties['Created'];
					$now = new SSDatetime();
					$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';<commit_msg>MINOR: merged #3819. Allows the site map to work when site is on a non standard port<commit_after><?php
/**
 * Initial implementation of Sitemap support.
 * GoogleSitemap should handle requests to 'sitemap.xml'
 * the other two classes are used to render the sitemap.
 * 
 * You can notify ("ping") Google about a changed sitemap
 * automatically whenever a new page is published or unpublished.
 * By default, Google is not notified, and will pick up your new
 * sitemap whenever the GoogleBot visits your website.
 * 
 * Enabling notification of Google after every publish (in your _config.php):
 * <example
 * GoogleSitemap::enable_google_notificaton();
 * </example>
 * 
 * @see http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=34609
 * 
 * @package sapphire
 * @subpackage misc
 */
class GoogleSitemap extends Controller {
	
	/**
	 * @var boolean
	 */
	protected static $enabled = true;
	
	/**
	 * @var DataObjectSet
	 */
	protected $Pages;
	
	/**
	 * @var boolean
	 */
	protected static $google_notification_enabled = false;
	
	public function Items() {
		$this->Pages = Versioned::get_by_stage('SiteTree', 'Live');

		$newPages = new DataObjectSet();
		
		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 SSDatetime();
					$created->value = $properties['Created'];
					$now = new SSDatetime();
					$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';
{'fraction_non_alphanumeric': 0.13739853494357554, 'fraction_numerical': 0.014650564244704019, 'mean_word_length': 3.314261315115286, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4973488', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1502, 'n_words': 512}