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: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179:
<?php
/**
* Class used to determine if the core, or modules, need to be updated
*/
defined('ICMS_ROOT_PATH') or die("ImpressCMS root path not defined");
/**
* IcmsVersionChecker
*
* Class used to check if the ImpressCMS install is up to date
*
* @copyright The ImpressCMS Project http://www.impresscms.org/
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @category ICMS
* @package Core
* @subpackage VersionChecker
* @since 1.0
* @author marcan <marcan@impresscms.org>
* @version $Id: Versionchecker.php 11603 2012-02-26 08:45:50Z fiammy $
*/
class icms_core_Versionchecker {
/*
* errors
* @public $errors array
*/
public $errors = array();
/*
* URL of the XML containing version information
* @public $version_xml string
*/
public $version_xml = "http://www.impresscms.org/impresscms_version_branch13.xml";
/*
* Time before fetching the $version_xml again and store it in $cache_version_xml
* @public $cache_time integer
* @todo set this to a day at least or make it configurable in System Admin > Preferences
*/
public $cache_time=1;
/*
* Name of the latest version
* @public $latest_version_name string
*/
public $latest_version_name;
/*
* Name of installed version
* @private $installed_version_name string
*/
public $installed_version_name;
/*
* Number of the latest build
* @public $latest_build integer
*/
public $latest_build;
/*
* Status of the latest build
*
* 1 = Alpha
* 2 = Beta
* 3 = RC
* 10 = Final
*
* @public $latest_status integer
*/
public $latest_status;
/*
* URL of the latest release
* @public $latest_url string
*/
public $latest_url;
/*
* Changelog of the latest release
* @public $latest_changelog string
*/
public $latest_changelog;
/**
* Constructor
*
* @return void
*
*/
public function __construct() {
$this->installed_version_name = ICMS_VERSION_NAME;
}
/**
* Access the only instance of this class
*
* @static
* @staticvar object
*
* @return object
*
*/
static public function &getInstance() {
static $instance;
if (!isset($instance)) {
$instance = new self();
}
return $instance;
}
/**
* Check for a newer version of ImpressCMS
*
* @return TRUE if there is an update, FALSE if no update OR errors occured
*
*/
public function check() {
// Create a new instance of the SimplePie object
$feed = new icms_feeds_Simplerss();
$feed->set_feed_url($this->version_xml);
$feed->set_cache_duration(0);
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
$feed->init();
$feed->handle_content_type();
if (!$feed->error) {
$versionInfo['title'] = $feed->get_title();
$versionInfo['link'] = $feed->get_link();
$versionInfo['image_url'] = $feed->get_image_url();
$versionInfo['image_title'] = $feed->get_image_title();
$versionInfo['image_link'] = $feed->get_image_link();
$feed_item = $feed->get_item(0);
$versionInfo['description'] = $feed_item->get_description();
$versionInfo['permalink'] = $feed_item->get_permalink();
$versionInfo['title'] = $feed_item->get_title();
$versionInfo['content'] = $feed_item->get_content();
$guidArray = $feed_item->get_item_tags('', 'guid');
$versionInfo['guid'] = $guidArray[0]['data'];
} else {
$this->errors[] = _AM_VERSION_CHECK_RSSDATA_EMPTY;
return false;
}
$this->latest_version_name = $versionInfo['title'];
$this->latest_changelog = $versionInfo['description'];
$build_info = explode('|', $versionInfo['guid']);
$this->latest_build = $build_info[0];
$this->latest_status = $build_info[1];
if ($this->latest_build > ICMS_VERSION_BUILD) {
// There is an update available
$this->latest_url = $versionInfo['link'];
return true;
}
return false;
}
/**
* Gets all the error messages
*
* @param $ashtml bool return as html?
* @return mixed
*/
public function getErrors($ashtml=true) {
if (!$ashtml) {
return $this->errors;
} else {
$ret = '';
if (count($this->errors) > 0) {
foreach ($this->errors as $error) {
$ret .= $error.'<br />';
}
}
return $ret;
}
}
}