* @license PHP License * @package WB * @subpackage datasource */ WBClass::load('WBObserver' , 'WBObserver_Observable' ); /** * Datasource Sitemap * * @version 0.3.0 * @package WB * @subpackage datasource */ abstract class WBDatasource_Sitemap extends WBStdClass implements WBObserver_Observable { /** * current priority * @var float */ private $priority = 1.0; /** * current path * @var float */ private $path = '/'; /** * sitemap snippet XML chunk, usually empty * @var string */ private $snippet = ''; /** * Date of modification * @var string */ private $modified = ''; /** * Change Frequency * @var string */ private $changeFreq = ''; const CHANGE_FREQ_ALWAYS = 'always'; const CHANGE_FREQ_DAILY = 'daily'; const CHANGE_FREQ_WEEKLY = 'weekly'; const CHANGE_FREQ_MONTHLY = 'monthly'; const CHANGE_FREQ_YEARLY = 'yeaarly'; const CHANGE_FREQ_NEVER = 'never'; /** * list of observers * @var array */ private $observers = array(); /** * datasource config * @var array */ protected $config = array(); /** * Configure datasource object * * Merge given config with default configuration * * @see $config * @param array $config */ final public function configure($config) { if (!is_array($config)) { $config = array(); } $this->config = array_merge($this->config, $config); } /** * attach observer * * @param WBObserver $observer */ final public function attach(WBObserver $observer) { $this->observers[$observer->getObjectId()] = $observer; } /** * detach observer * * @param WBObserver $observer */ final public function detach(WBObserver $observer) { unset($this->observers[$observer->getObjectId()]); } /** * notify observer * */ final public function notify() { foreach ($this->observers as $o) { $o->update($this); } } /** * Set current path * * @param string $path * @param string $snippet, usually empty */ final protected function setPath($path, $snippet = '') { $this->path = $path; $this->snippet = $snippet; } /** * Set current priority * * @param float $priority */ final protected function setPriority($priority) { $this->priority = $priority; } /** * Set Last Modifed Date * * @param string $timestamp */ final protected function setModified($timestamp = null) { if (empty($timestamp)) { $this->modified = ''; } if (10 < strlen($timestamp)) { $timestamp = substr($timestamp, 0, 10); } $this->modified = $timestamp; } /** * Set Current Change Frequency * * @see CHANGE_FREQ_DAILY * @param string $freq */ final protected function setChangeFreq($freq = null) { if (empty($freq)) { $this->changeFreq = ''; } $this->changeFreq = $freq; } /** * Get current path * * Usually called by observer * * @return string */ final public function getPath() { return $this->path; } /** * Get current priority * * Usually called by observer * * @return float */ final public function getPriority() { return $this->priority; } /** * Get current snippet * * Usually called by observer. Snippet is usually empty, still modification day and changefreq may be there * * @return float */ final public function getSnippet() { return $this->snippet; } /** * Get Current Modifed Date * * @return string */ final public function getModified() { return $this->modified; } /** * Get Current Change Frequency * * @return string */ final public function getChangedFreq() { return $this->changeFreq; } /** * Find all the URLs * * Walk through all the pages etc. to find all URLs to be added to the sitemap. */ abstract public function find(); }