1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
<?php
define('SPOTWEB_FEATURE_VERSION', '0.06');
/*
* Spotweb version check needs to have as few dependencies on the
* rest of the Spotweb infrastructure as possible because that would
* create an interdependency
*/
class SpotWebVersionCheck {
const rss_url = 'https://raw.github.com/spotweb/spotweb/master/notifications.xml';
#const rss_url = './notifications.xml';
private $_xml = null;
function __construct() {
$this->retrieveRss();
}
/*
* Retrieves the RSS feed from Github
*/
private function retrieveRss() {
$rssFile = file_get_contents(SpotWebVersionCheck::rss_url);
# Supress the namespace warning
$this->_xml = @simplexml_load_string($rssFile);
} # retrieveRss
/*
* Returns the news items
*/
function getItems() {
$itemList = array();
/*
* Returning the array directly from simplexml doesn't work
*/
foreach($this->_xml->channel->item as $item) {
$itemArray = array(
'title' => $item->title,
'description' => $item->description,
'link' => $item->link,
'guid' => $item->guid,
'pubDate' => $item->pubDate,
'author' => $item->author,
'schema_version' => $item->schema_version,
'settings_version' => $item->settings_version,
'security_version' => $item->security_version,
'feature_version' => $item->feature_version);
$itemArray['is_newer_than_installed'] = !$this->isLatestVersion($itemArray);
$itemList[] = $itemArray;
} # foreach
return $itemList;
} # getItems
/*
* Returns whether the current system is up-to-date
*/
function isLatestVersion($item) {
return ($item['schema_version'] <= SPOTDB_SCHEMA_VERSION) &&
($item['settings_version'] <= SPOTWEB_SETTINGS_VERSION) &&
($item['security_version'] <= SPOTWEB_SECURITY_VERSION) &&
($item['feature_version'] <= SPOTWEB_FEATURE_VERSION);
} # isLatestVersion
} # class SpotWebVersionCheck.php
|