Location: PHPKode > scripts > GSM > gsm/GoogleSiteMapEntry.php
<?php
/*
GoogleSiteMapEntry.php

container for a single google site map entry
can handle both virtual and real files

Created by Isaac Scott <hide@address.com>

Last modified 15th September 2008
*/

class GoogleSiteMapEntry
{
	// definitions
	private
		$loc,
		$pri,
		$lmod,
		$freq;
	
	// constructor
	public function __construct($location)
	{
		$this->loc = $location;
		$pos = strpos($this->loc, '/', 7) + 1;
		$this->pri = 0.5;
		$this->freq = '';
		$this->lmod = time();
		if (file_exists(substr($this->loc, $pos)))
		{
			$stat = stat(substr($this->loc, $pos));
			$this->lmod = date ("Y-m-d", $stat['mtime']);
			$this->setFrequency($stat['mtime']);
		}
		
		return true;
	}
	
	// deconstructor
	public function __destruct()
	{}
	
	/*
	PUBLIC methods: accessible by anyone
	*/
	// takes a single arugument that is a float 
	// between 0 and 1 that is the priority 
	public function setPriority($priority)
	{
		$this->pri = $priority;
	}
	
	// takes a single argument that is a unix timestamp
	public function setLastMod($time)
	{
		$this->lmod = date("Y-m-d", $time);
		$this->setFrequency($time);
	}
	
	// returns the entry in xml format
	public function getXml()
	{
		$url = str_replace('&', '&amp;', $this->loc);
		$xml .= "\t<url>\n";
		$xml .= "\t\t<loc>$url</loc>\n";
		$xml .= "\t\t<lastmod>{$this->lmod}</lastmod>\n";
		$xml .= "\t\t<changefreq>{$this->freq}</changefreq>\n";
		$xml .= "\t\t<priority>{$this->pri}</priority>\n";
		$xml .= "\t</url>\n";
		
		return $xml;
	}
	/*
	PROTECTED methods: accessible by this class and its children
	*/
	
	/*
	PRIVATE methods: accessible by this class only
	*/
	// takes a single argument and sets the frequency
	private function setFrequency($time)
	{
		$days = (int) ((time() - $time) / 86400);
		$seconds = (time() - $time);
		if ($seconds < 60) {
			$this->freq = "always";
		} else if ($seconds >= 60 && $seconds < 120) {
			$this->freq = "hourly";
		} else if ($seconds > 120 && $days < 7) {
			$this->freq = "daily";
		} else if ($days >= 60 && $days <= 7) {
			$this->freq = "weekly";
		} else if ($days > 7 && $days <= 30) {
			$this->freq = "monthly";
		} else if ($days <= 365) {
			$this->freq = "yearly";
		} else {
#			$return = "unknown";
#			if ($this->stat['ctime'] == $this->stat['mtime'])
				$this->freq = "never";
		}
	}
}
?>
Return current item: GSM