* update item_images_url config to 1092

*  for backward support new require constants will be used for semantic
versioning: myaac_, php_, database_
* updated TODO
This commit is contained in:
slawkens1 2017-12-26 20:55:43 +01:00
parent 62443257fc
commit a95c93cd5b
3 changed files with 79 additions and 62 deletions

8
TODO
View File

@ -2,13 +2,14 @@
0.* 0.*
* support duplicated vocation names with different ids * support duplicated vocation names with different ids
* plugins: option to define custom requirements check in json file, to check if system meets the requirement
* cache Menus in templates * cache Menus in templates
* sandbox for plugins, don't install when requirements are not passed
* load items & weapons on install, preferably with ajax
* add changelog management interface
1.0: 1.0:
* i18n support (issue #1 on github) * i18n support (issue #1 on github)
* New Admin Panel layout and interface * New Admin Panel layout and interface
* add changelog management interface
* remove tibiacom template, and include it as a plugin * remove tibiacom template, and include it as a plugin
2.0 2.0
@ -29,4 +30,5 @@ At any time between (version not specified):
* new cache engine - plain php, is good with pure php 7.0+ and opcache * new cache engine - plain php, is good with pure php 7.0+ and opcache
* preferably configurable (enable/disable) forum TinyMCE editor * preferably configurable (enable/disable) forum TinyMCE editor
* OTAdmin support in Admin Panel * OTAdmin support in Admin Panel
* database towns table support for TFS 1.3 * database towns table support for TFS 1.3
* two factor authentication for TFS 1.x

View File

@ -75,7 +75,7 @@ $config = array(
// images // images
'outfit_images_url' => 'http://outfit-images.ots.me/outfit.php', // set to animoutfit.php for animated outfit 'outfit_images_url' => 'http://outfit-images.ots.me/outfit.php', // set to animoutfit.php for animated outfit
'item_images_url' => 'http://item-images.ots.me/960/', // set to images/items if you host your own items in images folder 'item_images_url' => 'http://item-images.ots.me/1092/', // set to images/items if you host your own items in images folder
// account // account
'account_management' => true, // disable if you're using other method to manage users (fe. tfs account manager) 'account_management' => true, // disable if you're using other method to manage users (fe. tfs account manager)

View File

@ -42,10 +42,10 @@ class Plugins {
private static $warnings = array(); private static $warnings = array();
private static $error = null; private static $error = null;
private static $pluginInfo = array(); private static $pluginInfo = array();
public static function install($file) { public static function install($file) {
global $db, $cache; global $db, $cache;
$zip = new ZipArchive(); $zip = new ZipArchive();
if($zip->open($file)) { if($zip->open($file)) {
for ($i = 0; $i < $zip->numFiles; $i++) { for ($i = 0; $i < $zip->numFiles; $i++) {
@ -53,12 +53,12 @@ class Plugins {
if(pathinfo($tmp, PATHINFO_DIRNAME) == 'plugins' && pathinfo($tmp, PATHINFO_EXTENSION) == 'json') if(pathinfo($tmp, PATHINFO_DIRNAME) == 'plugins' && pathinfo($tmp, PATHINFO_EXTENSION) == 'json')
$json_file = $tmp; $json_file = $tmp;
} }
if(!isset($json_file)) { if(!isset($json_file)) {
self::$error = 'Cannot find plugin info .json file. Installation is discontinued.'; self::$error = 'Cannot find plugin info .json file. Installation is discontinued.';
return false; return false;
} }
if($zip->extractTo(BASE)) { // place in the directory with same name if($zip->extractTo(BASE)) { // place in the directory with same name
$file_name = BASE . $json_file; $file_name = BASE . $json_file;
if(!file_exists($file_name)) { if(!file_exists($file_name)) {
@ -74,7 +74,7 @@ class Plugins {
} }
else { else {
$continue = true; $continue = true;
if(!isset($plugin['name'])) { if(!isset($plugin['name'])) {
self::$warnings[] = 'Plugin "name" tag is not set.'; self::$warnings[] = 'Plugin "name" tag is not set.';
} }
@ -90,38 +90,72 @@ class Plugins {
if(!isset($plugin['contact'])) { if(!isset($plugin['contact'])) {
self::$warnings[] = 'Plugin "contact" tag is not set.'; self::$warnings[] = 'Plugin "contact" tag is not set.';
} }
if(isset($plugin['require'])) { if(isset($plugin['require'])) {
$require = $plugin['require']; $require = $plugin['require'];
if(isset($require['myaac'])) {
$myaac_satified = true;
if(isset($require['myaac_'])) {
$require_myaac = $require['myaac_'];
if(!Composer\Semver\Semver::satisfies(MYAAC_VERSION, $require_myaac)) {
$myaac_satified = false;
}
}
else if(isset($require['myaac'])) {
$require_myaac = $require['myaac']; $require_myaac = $require['myaac'];
if(!self::satisfies(MYAAC_VERSION, $require_myaac)) { if(version_compare(MYAAC_VERSION, $require_myaac, '<')) {
self::$error = "Your AAC version doesn't meet the requirement of this plugin. Required version is: " . $require_myaac . ", and you're using version " . MYAAC_VERSION . "."; $myaac_satified = false;
$continue = false;
} }
} }
if(isset($require['php'])) { if(!$myaac_satified) {
self::$error = "Your AAC version doesn't meet the requirement of this plugin. Required version is: " . $require_myaac . ", and you're using version " . MYAAC_VERSION . ".";
$continue = false;
}
$php_satified = true;
if(isset($require['php_'])) {
$require_php = $require['php_'];
if(!Composer\Semver\Semver::satisfies(phpversion(), $require_php)) {
$php_satified = false;
}
}
else if(isset($require['php'])) {
$require_php = $require['php']; $require_php = $require['php'];
if(!self::satisfies(phpversion(), $require_php)) { if(version_compare(phpversion(), $require_php, '<')) {
self::$error = "Your PHP version doesn't meet the requirement of this plugin. Required version is: " . $require_php . ", and you're using version " . phpversion() . "."; $php_satified = false;
$continue = false;
} }
} }
if(isset($require['database'])) { if(!$php_satified) {
self::$error = "Your PHP version doesn't meet the requirement of this plugin. Required version is: " . $require_php . ", and you're using version " . phpversion() . ".";
$continue = false;
}
$database_satified = true;
if(isset($require['database_'])) {
$require_database = $require['database_'];
if(!Composer\Semver\Semver::satisfies(DATABASE_VERSION, $require_database)) {
$database_satified = false;
}
}
else if(isset($require['database'])) {
$require_database = $require['database']; $require_database = $require['database'];
if(!self::satisfies(DATABASE_VERSION, $require_database)) { if(version_compare(DATABASE_VERSION, $require_database, '<')) {
self::$error = "Your database version doesn't meet the requirement of this plugin. Required version is: " . $require_database . ", and you're using version " . DATABASE_VERSION . "."; $database_satified = false;
$continue = false;
} }
} }
if(!$database_satified) {
self::$error = "Your database version doesn't meet the requirement of this plugin. Required version is: " . $require_database . ", and you're using version " . DATABASE_VERSION . ".";
$continue = false;
}
foreach($require as $req => $version) { foreach($require as $req => $version) {
if(in_array($req, array('myaac', 'php', 'database'))) { if(in_array($req, array('myaac', 'myaac_', 'php', 'php_', 'database', 'database_'))) {
continue; continue;
} }
if(!self::is_installed($req, $version)) { if(!self::is_installed($req, $version)) {
self::$error = "This plugin requires another plugin to run correctly. The another plugin is: " . $req . ", with version " . $version . "."; self::$error = "This plugin requires another plugin to run correctly. The another plugin is: " . $req . ", with version " . $version . ".";
$continue = false; $continue = false;
@ -129,7 +163,7 @@ class Plugins {
} }
} }
} }
if($continue) { if($continue) {
if (isset($plugin['install'])) { if (isset($plugin['install'])) {
if (file_exists(BASE . $plugin['install'])) if (file_exists(BASE . $plugin['install']))
@ -137,7 +171,7 @@ class Plugins {
else else
self::$warnings[] = 'Cannot load install script. Your plugin might be not working correctly.'; self::$warnings[] = 'Cannot load install script. Your plugin might be not working correctly.';
} }
if (isset($plugin['hooks'])) { if (isset($plugin['hooks'])) {
foreach ($plugin['hooks'] as $_name => $info) { foreach ($plugin['hooks'] as $_name => $info) {
if (defined('HOOK_'. $info['type'])) { if (defined('HOOK_'. $info['type'])) {
@ -153,11 +187,11 @@ class Plugins {
self::$warnings[] = 'Unknown event type: ' . $info['type']; self::$warnings[] = 'Unknown event type: ' . $info['type'];
} }
} }
if($cache->enabled()) { if($cache->enabled()) {
$cache->delete('templates'); $cache->delete('templates');
} }
$zip->close(); $zip->close();
return true; return true;
} }
@ -167,19 +201,19 @@ class Plugins {
else { else {
self::$error = 'There was a problem with extracting zip archive.'; self::$error = 'There was a problem with extracting zip archive.';
} }
$zip->close(); $zip->close();
} }
else { else {
self::$error = 'There was a problem with opening zip archive.'; self::$error = 'There was a problem with opening zip archive.';
} }
return false; return false;
} }
public static function uninstall($plugin_name) { public static function uninstall($plugin_name) {
global $cache, $db; global $cache, $db;
$filename = BASE . 'plugins/' . $plugin_name . '.json'; $filename = BASE . 'plugins/' . $plugin_name . '.json';
if(!file_exists($filename)) { if(!file_exists($filename)) {
self::$error = 'Plugin ' . $plugin_name . ' does not exist.'; self::$error = 'Plugin ' . $plugin_name . ' does not exist.';
@ -205,7 +239,7 @@ class Plugins {
$success = false; $success = false;
} }
} }
if (isset($plugin_info['hooks'])) { if (isset($plugin_info['hooks'])) {
foreach ($plugin_info['hooks'] as $_name => $info) { foreach ($plugin_info['hooks'] as $_name => $info) {
if (defined('HOOK_'. $info['type'])) { if (defined('HOOK_'. $info['type'])) {
@ -219,12 +253,12 @@ class Plugins {
self::$warnings[] = 'Unknown event type: ' . $info['type']; self::$warnings[] = 'Unknown event type: ' . $info['type'];
} }
} }
if($success) { if($success) {
if($cache->enabled()) { if($cache->enabled()) {
$cache->delete('templates'); $cache->delete('templates');
} }
return true; return true;
} }
else { else {
@ -233,10 +267,10 @@ class Plugins {
} }
} }
} }
return false; return false;
} }
public static function is_installed($plugin_name, $version) { public static function is_installed($plugin_name, $version) {
$filename = BASE . 'plugins/' . $plugin_name . '.json'; $filename = BASE . 'plugins/' . $plugin_name . '.json';
if(!file_exists($filename)) { if(!file_exists($filename)) {
@ -253,36 +287,17 @@ class Plugins {
return false; return false;
} }
return self::satisfies($plugin_info['version'], $version); return Composer\Semver\Semver::satisfies($plugin_info['version'], $version);
}
public static function satisfies($version, $constraints) {
$is_semver = false;
$array = array(',', '>', '<', '=', '*', '|', '~');
foreach($array as $x) {
if(strpos($constraints, $x) !== false) {
$is_semver = true;
}
}
if($is_semver && !Composer\Semver\Semver::satisfies($version, $constraints)) {
return false;
}
else if(version_compare($version, $constraints, '<')) {
return false;
}
return true;
} }
public static function getWarnings() { public static function getWarnings() {
return self::$warnings; return self::$warnings;
} }
public static function getError() { public static function getError() {
return self::$error; return self::$error;
} }
public static function getPluginInfo() { public static function getPluginInfo() {
return self::$pluginInfo; return self::$pluginInfo;
} }