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: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341:
<?php
class Application
{
private $id = '';
private $name = '';
private $language = '';
private $localized_language = '';
private $type = '';
private $repository = '';
private $version = '';
private $compatibility_min = '';
private $compatibility_max = '';
private $pubdate = null;
private $priority = null;
private $security_update = false;
private $download_url = '';
private $update_url = '';
private $autoupdate_url = '';
private $authors = array();
private $description = '';
private $new_features = array();
private $improvements = array();
private $bug_corrections = array();
private $security_improvements = array();
private $warning_level = '';
private $warning = '';
const KERNEL_TYPE = 'kernel';
const MODULE_TYPE = 'module';
const TEMPLATE_TYPE = 'template';
public function __construct($id, $language, $type = self::MODULE_TYPE, $version = 0, $repository = '')
{
$this->id = $id;
$this->name = $id;
$this->language = $language;
$this->type = $type;
$this->repository = $repository;
$this->version = $version;
$this->pubdate = new Date();
}
public function load($xml_desc)
{
$attributes = $xml_desc->attributes();
$name = self::get_attribute($xml_desc, 'name');
$this->name = !empty($name) ? $name : $this->id;
$this->language = self::get_attribute($xml_desc, 'language');
$language = self::get_attribute($xml_desc, 'localized_language');
$this->localized_language = !empty($language) ? ($language) : $this->language;
$this->version = self::get_attribute($xml_desc, 'num');
$this->compatibility_min = self::get_attribute($xml_desc, 'min', 'compatibility');
$this->compatibility_max = self::get_attribute($xml_desc, 'max', 'compatibility');
$pubdate = self::get_attribute($xml_desc, 'pubdate');
if (!empty($pubdate))
{
$this->pubdate = new Date($pubdate);
}
else
{
$this->pubdate = new Date();
}
$this->security_update = self::get_attribute($xml_desc, 'security-update');
$this->security_update = TextHelper::strtolower($this->security_update) == 'true';
$this->priority = self::get_attribute($xml_desc, 'priority');
switch ($this->priority)
{
case 'high':
$this->priority = AdministratorAlert::ADMIN_ALERT_HIGH_PRIORITY;
break;
case 'medium':
$this->priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
break;
default:
$this->priority = AdministratorAlert::ADMIN_ALERT_LOW_PRIORITY;
break;
}
if ($this->security_update)
$this->priority++;
$this->download_url = self::get_attribute($xml_desc, 'url', 'download');
$this->update_url = self::get_attribute($xml_desc, 'url', 'update');
$this->autoupdate_url = self::get_attribute($xml_desc, 'url', 'autoupdate');
$this->authors = array();
$authors_elts = $xml_desc->xpath('authors/author');
foreach ($authors_elts as $author)
{
$this->authors[] = array(
'name' => self::get_attribute($author, 'name'),
'email' => self::get_attribute($author, 'email')
);
}
$this->description = $xml_desc->xpath('description');
$this->description = (string) $this->description[0];
$this->new_features = array();
$this->improvements = array();
$this->bug_corrections = array();
$this->security_improvements = array();
$novelties = $xml_desc->xpath('whatsnew/new');
foreach ($novelties as $novelty )
{
$attributes = $novelty->attributes();
$type = isset($attributes['type']) ? $attributes['type'] : 'feature';
switch ($type)
{
case 'improvement':
$this->improvements[] = (string) $novelty;
break;
case 'bug':
$this->bug_corrections[] = (string) $novelty;
break;
case 'security':
$this->security_improvements[] = (string) $novelty;
break;
default:
$this->new_features[] = (string) $novelty;
break;
}
}
$this->warning_level = self::get_attribute($xml_desc, 'level', 'warning');
if (!empty($this->warning_level))
{
$this->warning = $xml_desc->xpath('warning');
$this->warning = (string) $this->warning[0];
}
}
public function get_identifier()
{
return md5($this->type . '_' . $this->id . '_' . $this->version . '_' . $this->language);
}
public function check_compatibility()
{
$current_version = $this->get_installed_version();
if ($current_version == '0')
{
return false;
}
$phpboost_version = Environment::get_phpboost_version();
return version_compare($current_version, $this->get_version(), '<') > 0 &&
(($phpboost_version >= $this->compatibility_min) && ($this->compatibility_max == null ||
($phpboost_version <= $this->compatibility_max && $this->compatibility_max >= $this->compatibility_min)));
}
public function get_id() { return $this->id; }
public function get_name() { return $this->name; }
public function get_language() { return $this->language; }
public function get_localized_language() { return !empty($this->localized_language) ? $this->localized_language : $this->language; }
public function get_type() { return $this->type; }
public function get_repository() { return $this->repository; }
public function get_version() { return $this->version; }
public function get_compatibility_min() { return $this->compatibility_min; }
public function get_compatibility_max() { return $this->compatibility_max; }
public function get_pubdate() { return !empty($this->pubdate) && is_object($this->pubdate) ? $this->pubdate->format(Date::FORMAT_DAY_MONTH_YEAR, Timezone::USER_TIMEZONE) : ''; }
public function get_priority() { return $this->priority; }
public function get_security_update() { return $this->security_update; }
public function get_download_url() { return $this->download_url; }
public function get_update_url() { return $this->update_url; }
public function get_autoupdate_url() { return $this->autoupdate_url; }
public function get_authors() { return $this->authors; }
public function get_description() { return $this->description; }
public function get_new_features() { return $this->new_features; }
public function get_improvements() { return $this->improvements; }
public function get_bug_corrections() { return $this->bug_corrections; }
public function get_security_improvements() { return $this->security_improvements; }
public function get_warning_level() { return $this->warning_level; }
public function get_warning() { return $this->warning; }
private function get_attribute($xdoc, $attibute_name, $xpath_query = '.')
{
$elements = $xdoc->xpath($xpath_query);
if (count($elements) > 0)
{
$attributes = $elements[0]->attributes();
return isset($attributes[$attibute_name]) ? (string) $attributes[$attibute_name] : '';
}
return '';
}
private function get_installed_version()
{
switch ($this->type)
{
case self::KERNEL_TYPE:
return Environment::get_phpboost_version();
case self::MODULE_TYPE:
if (ModulesManager::is_module_installed($this->id))
{
return ModulesManager::get_module($this->id)->get_configuration()->get_version();
}
return '0';
case self::TEMPLATE_TYPE:
if (ThemesManager::get_theme_existed($this->id))
{
return ThemesManager::get_theme($this->id)->get_configuration()->get_version();
}
return '0';
default:
return '0';
}
}
}
?>