diff --git a/common.php b/common.php index 39a4abfe..96748eee 100644 --- a/common.php +++ b/common.php @@ -28,7 +28,7 @@ session_start(); define('MYAAC', true); define('MYAAC_VERSION', '0.6.1'); -define('DATABASE_VERSION', 12); +define('DATABASE_VERSION', 13); define('TABLE_PREFIX', 'myaac_'); define('START_TIME', microtime(true)); define('MYAAC_OS', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'WINDOWS' : (strtoupper(PHP_OS) == 'DARWIN' ? 'MAC' : 'LINUX')); diff --git a/index.php b/index.php index a583fd95..1dc1b5a4 100644 --- a/index.php +++ b/index.php @@ -54,13 +54,21 @@ if(!empty($tmp)) else $uri = str_replace_first('/', '', $uri); -$uri = strtolower(str_replace(array('index.php/', '?'), '', $uri)); +$uri = str_replace(array('index.php/', '?'), '', $uri); $found = false; if(empty($uri) || isset($_REQUEST['template'])) { $_REQUEST['p'] = 'news'; $found = true; } +else if(preg_match("/^[A-Za-z0-9-_%\'+]+\.png$/i", $uri)) { + $tmp = explode('.', $uri); + $_REQUEST['name'] = urldecode($tmp[0]); + + chdir(TOOLS . 'signature'); + include(TOOLS . 'signature/index.php'); + exit(); +} else if(!preg_match('/[^A-z0-9_\-]/', $uri) && file_exists(SYSTEM . 'pages/' . $uri . '.php')) { $_REQUEST['p'] = $uri; $found = true; @@ -106,22 +114,15 @@ else { '/^news\/edit\/?$/' => array('subtopic' => 'news', 'action' => 'edit'), '/^news\/archive\/?$/' => array('subtopic' => 'newsarchive'), '/^news\/archive\/[0-9]+\/?$/' => array('subtopic' => 'newsarchive', 'id' => '$2'), - '/^polls\/[0-9]+\/?$/' => array('subtopic' => 'polls', 'id' => '$1') + '/^polls\/[0-9]+\/?$/' => array('subtopic' => 'polls', 'id' => '$1'), + '/^spells\/[A-Za-z0-9-_%]+\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'spells', 'vocation' => '$1', 'order' => '$2'), ); - if (preg_match("/^[A-Za-z0-9-_%\'+]+\.png$/i", $uri)) { - $tmp = explode('.', $uri); - $_REQUEST['name'] = urldecode($tmp[0]); - - chdir(TOOLS . 'signature'); - include(TOOLS . 'signature/index.php'); - exit(); - } - foreach($rules as $rule => $redirect) { if (preg_match($rule, $uri)) { $tmp = explode('/', $uri); foreach($redirect as $key => $value) { + if(strpos($value, '$') !== false) { $value = str_replace('$' . $value[1], $tmp[$value[1]], $value); } diff --git a/system/hooks.php b/system/hooks.php index c2571a89..9361026e 100644 --- a/system/hooks.php +++ b/system/hooks.php @@ -25,21 +25,6 @@ define('HOOK_CHARACTERS_AFTER_CHARACTERS', 12); define('HOOK_FIRST', HOOK_STARTUP); define('HOOK_LAST', HOOK_CHARACTERS_AFTER_CHARACTERS); -$hook_types = array( - 'STARTUP' => HOOK_STARTUP, - 'BEFORE_PAGE' => HOOK_BEFORE_PAGE, - 'AFTER_PAGE' => HOOK_AFTER_PAGE, - 'FINISH' => HOOK_FINISH, - 'TIBIACOM_ARTICLE' => HOOK_TIBIACOM_ARTICLE, - 'TIBIACOM_BORDER_3' => HOOK_TIBIACOM_BORDER_3, - 'CHARACTERS_BEFORE_INFORMATIONS' => HOOK_CHARACTERS_BEFORE_INFORMATIONS, - 'CHARACTERS_AFTER_INFORMATIONS' => HOOK_CHARACTERS_AFTER_INFORMATIONS, - 'CHARACTERS_BEFORE_SIGNATURE' => HOOK_CHARACTERS_BEFORE_SIGNATURE, - 'CHARACTERS_AFTER_SIGNATURE' => HOOK_CHARACTERS_AFTER_SIGNATURE, - 'CHARACTERS_AFTER_ACCOUNT' => HOOK_CHARACTERS_AFTER_ACCOUNT, - 'CHARACTERS_AFTER_CHARACTERS' => HOOK_CHARACTERS_AFTER_CHARACTERS -); - class Hook { private $_name, $_type, $_file; diff --git a/system/libs/plugins.php b/system/libs/plugins.php index 8ef65c9a..6dfefd94 100644 --- a/system/libs/plugins.php +++ b/system/libs/plugins.php @@ -101,13 +101,14 @@ class Plugins { if (isset($plugin['hooks'])) { foreach ($plugin['hooks'] as $_name => $info) { - if (isset($hook_types[$info['type']])) { + if (defined('HOOK_'. $info['type'])) { + $hook = constant('HOOK_'. $info['type']); $query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'hooks` WHERE `name` = ' . $db->quote($_name) . ';'); if ($query->rowCount() == 1) { // found something $query = $query->fetch(); - $db->query('UPDATE `' . TABLE_PREFIX . 'hooks` SET `type` = ' . $hook_types[$info['type']] . ', `file` = ' . $db->quote($info['file']) . ' WHERE `id` = ' . (int)$query['id'] . ';'); + $db->update(TABLE_PREFIX . 'hooks', array('type' => $hook, 'file' => $info['file']), array('id' => (int)$query['id'])); } else { - $db->query('INSERT INTO `' . TABLE_PREFIX . 'hooks` (`id`, `name`, `type`, `file`) VALUES (NULL, ' . $db->quote($_name) . ', ' . $hook_types[$info['type']] . ', ' . $db->quote($info['file']) . ');'); + $db->insert(TABLE_PREFIX . 'hooks', array('id' => 'NULL', 'name' => $_name, 'type' => $hook, 'file' => $info['file'])); } } else self::$warnings[] = 'Unknown event type: ' . $info['type']; diff --git a/system/libs/spells.php b/system/libs/spells.php index 4d1d3e2b..0fa2e447 100644 --- a/system/libs/spells.php +++ b/system/libs/spells.php @@ -25,10 +25,6 @@ class Spells { echo '

All records deleted from table ' . TABLE_PREFIX . 'spells in database.

'; } - foreach($config['vocations'] as $voc_id => $voc_name) { - $vocations_ids[$voc_name] = $voc_id; - } - try { self::$spellsList = new OTS_SpellsList($config['data_path'].'spells/spells.xml'); } @@ -36,6 +32,7 @@ class Spells { self::$lastError = $e->getMessage(); return false; } + //add conjure spells $conjurelist = self::$spellsList->getConjuresList(); if($show) { @@ -44,35 +41,29 @@ class Spells { foreach($conjurelist as $spellname) { $spell = self::$spellsList->getConjure($spellname); - $lvl = $spell->getLevel(); - $mlvl = $spell->getMagicLevel(); - $mana = $spell->getMana(); $name = $spell->getName(); - $soul = $spell->getSoul(); - $spell_txt = $spell->getWords(); - $vocations = $spell->getVocations(); + $words = $spell->getWords(); + if(strpos($words, '#') !== false) + continue; - $enabled = $spell->isEnabled(); - if($enabled) { - $hide_spell = 0; - } - else { - $hide_spell = 1; - } - $pacc = $spell->isPremium(); - if($pacc) { - $pacc = '1'; - } - else { - $pacc = '0'; - } - $type = 2; - $count = $spell->getConjureCount(); try { - $db->query('INSERT INTO myaac_spells (spell, name, words, type, mana, level, maglevel, soul, premium, vocations, conjure_count, hidden) VALUES (' . $db->quote($spell_txt) . ', ' . $db->quote($name) . ', ' . $db->quote($spell_txt) . ', ' . $db->quote($type) . ', ' . $db->quote($mana) . ', ' . $db->quote($lvl) . ', ' . $db->quote($mlvl) . ', ' . $db->quote($soul) . ', ' . $db->quote($pacc) . ', ' . $db->quote(json_encode($vocations)) . ', ' . $db->quote($count) . ', ' . $db->quote($hide_spell) . ')'); + $db->insert(TABLE_PREFIX . 'spells', array( + 'name' => $name, + 'words' => $words, + 'type' => 2, + 'mana' => $spell->getMana(), + 'level' => $spell->getLevel(), + 'maglevel' => $spell->getMagicLevel(), + 'soul' => $spell->getSoul(), + 'premium' => $spell->isPremium() ? 1 : 0, + 'vocations' => json_encode($spell->getVocations()), + 'conjure_count' => $spell->getConjureCount(), + 'hidden' => $spell->isEnabled() ? 0 : 1 + )); + if($show) { - success("Added: " . $name . "
"); + success('Added: ' . $name . '
'); } } catch(PDOException $error) { @@ -82,7 +73,7 @@ class Spells { } } - //add instant spells + // add instant spells $instantlist = self::$spellsList->getInstantsList(); if($show) { echo "

Instant:

"; @@ -90,39 +81,29 @@ class Spells { foreach($instantlist as $spellname) { $spell = self::$spellsList->getInstant($spellname); - $lvl = $spell->getLevel(); - $mlvl = $spell->getMagicLevel(); - $mana = $spell->getMana(); $name = $spell->getName(); - $soul = $spell->getSoul(); - $spell_txt = $spell->getWords(); - if(strpos($spell_txt, '###') !== false) + + $words = $spell->getWords(); + if(strpos($words, '#') !== false) continue; - $vocations = $spell->getVocations(); - - $enabled = $spell->isEnabled(); - if($enabled) { - $hide_spell = 0; - } - else { - $hide_spell = 1; - } - $pacc = $spell->isPremium(); - if($pacc) { - $pacc = '1'; - } - else { - $pacc = '0'; - } - $type = 1; - $count = 0; - - try { - $db->query("INSERT INTO myaac_spells (spell, name, words, type, mana, level, maglevel, soul, premium, vocations, conjure_count, hidden) VALUES (".$db->quote($spell_txt).", ".$db->quote($name).", ".$db->quote($spell_txt).", '".$type."', '".$mana."', '".$lvl."', '".$mlvl."', '".$soul."', '".$pacc."', ".$db->quote(json_encode($vocations)).", '".$count."', '".$hide_spell."')"); + $db->insert(TABLE_PREFIX . 'spells', array( + 'name' => $name, + 'words' => $words, + 'type' => 1, + 'mana' => $spell->getMana(), + 'level' => $spell->getLevel(), + 'maglevel' => $spell->getMagicLevel(), + 'soul' => $spell->getSoul(), + 'premium' => $spell->isPremium() ? 1 : 0, + 'vocations' => json_encode($spell->getVocations()), + 'conjure_count' => 0, + 'hidden' => $spell->isEnabled() ? 0 : 1 + )); + if($show) { - success("Added: ".$name."
"); + success('Added: ' . $name . '
'); } } catch(PDOException $error) { @@ -132,44 +113,35 @@ class Spells { } } - //add runes + // add runes $runeslist = self::$spellsList->getRunesList(); if($show) { echo "

Runes:

"; } - // runes + foreach($runeslist as $spellname) { $spell = self::$spellsList->getRune($spellname); - $lvl = $spell->getLevel(); - $mlvl = $spell->getMagicLevel(); - $mana = $spell->getMana(); - $name = $spell->getName() . ' (rune)'; - $soul = $spell->getSoul(); - $spell_txt = $spell->getWords(); - $vocations = $spell->getVocations(); - $id = $spell->getID(); - - $enabled = $spell->isEnabled(); - if($enabled) { - $hide_spell = 0; - } - else { - $hide_spell = 1; - } - $pacc = $spell->isPremium(); - if($pacc) { - $pacc = '1'; - } - else { - $pacc = '0'; - } - $type = 3; - $count = $spell->getConjureCount(); + $name = $spell->getName() . ' (rune)'; + try { - $db->query('INSERT INTO myaac_spells (spell, name, words, type, mana, level, maglevel, soul, premium, vocations, conjure_count, item_id, hidden) VALUES (' . $db->quote($spell_txt) . ', ' . $db->quote($name) . ', ' . $db->quote($spell_txt) . ', ' . $db->quote($type) . ', ' . $db->quote($mana) . ', ' . $db->quote($lvl) . ', ' . $db->quote($mlvl) . ', ' . $db->quote($soul) . ', ' . $db->quote($pacc) . ', ' . $db->quote(json_encode($vocations)) . ', ' . $db->quote($count) . ', ' . $db->quote($id) . ', ' . $db->quote($hide_spell) . ')'); + $db->insert(TABLE_PREFIX . 'spells', array( + 'name' => $name, + 'words' => $spell->getWords(), + 'type' => 3, + 'mana' => $spell->getMana(), + 'level' => $spell->getLevel(), + 'maglevel' => $spell->getMagicLevel(), + 'soul' => $spell->getSoul(), + 'premium' => $spell->isPremium() ? 1 : 0, + 'vocations' => json_encode($spell->getVocations()), + 'conjure_count' => 0, + 'item_id' => $spell->getID(), + 'hidden' => $spell->isEnabled() ? 0 : 1 + )); + if($show) { - success("Added: " . $name . "
"); + success('Added: ' . $name . '
'); } } catch(PDOException $error) { diff --git a/system/libs/usage_statistics.php b/system/libs/usage_statistics.php index 90bea622..119813f7 100644 --- a/system/libs/usage_statistics.php +++ b/system/libs/usage_statistics.php @@ -97,7 +97,16 @@ WHERE TABLE_SCHEMA = "forgottenserver";'); } $ret['locales'] = get_locales(); - $ret['plugins'] = get_plugins(); + $ret['plugins'] = array(); + foreach(get_plugins() as $plugin) { + $string = file_get_contents(BASE . 'plugins/' . $plugin . '.json'); + $plugin_info = json_decode($string, true); + if($plugin_info != false) { + if(isset($plugin_info['version'])) { + $ret['plugins'][$plugin] = $plugin_info['version']; + } + } + } $ret['templates'] = get_templates(); $ret['date_timezone'] = $config['date_timezone']; diff --git a/system/migrations/13.php b/system/migrations/13.php new file mode 100644 index 00000000..b709b843 --- /dev/null +++ b/system/migrations/13.php @@ -0,0 +1,4 @@ +query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP COLUMN `spell`;"); +?> \ No newline at end of file diff --git a/system/pages/spells.php b/system/pages/spells.php index bf5675a0..e40dcf26 100644 --- a/system/pages/spells.php +++ b/system/pages/spells.php @@ -21,145 +21,67 @@ if(isset($_POST['reload_spells']) && $canEdit) } } -if($canEdit) -{ -?> -
- - -
- -
- - - - - - - -
Spell Search
- - - - - -
Only for vocation: - - - render('buttons.submit.html.twig'); ?> -
-
-
+$spells = array(); +$spells_db = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'spells` WHERE `hidden` != 1 AND `type` < 3 ORDER BY ' . $order . ', level'); - - - - - - - - - - - - -query('SELECT * FROM `' . TABLE_PREFIX . 'spells` WHERE `hidden` != 1 AND `type` < 3 ORDER BY ' . $order . ', level'); -if(isset($vocation_id) && $vocation_id != 'All' && $vocation_id != '') -{ - foreach($spells as $spell) - { +if((string)$vocation_id != 'all') { + foreach($spells_db->fetchAll() as &$spell) { $spell_vocations = json_decode($spell['vocations'], true); - if(in_array($vocation_id, $spell_vocations) || count($spell_vocations) == 0) - { - echo ''; - if($spell['type'] == 1) - echo ''; - else if($spell['type'] == 2) - echo ''; + if(in_array($vocation_id, $spell_vocations) || count($spell_vocations) == 0) { + $spell['vocations'] = null; + $spells[] = $spell; + } + } +} +else { + foreach($spells_db->fetchAll() as &$spell) { + $vocations = json_decode($spell['vocations'], true); + + foreach($vocations as &$tmp_vocation) { + if(isset($config['vocations'][$tmp_vocation])) + $tmp_vocation = $config['vocations'][$tmp_vocation]; else - echo ''; - - echo ''; + $tmp_vocation = 'Unknown'; } + + $spell['vocations'] = implode('
', $vocations); + $spells[] = $spell; } } -else -{ - foreach($spells as $spell) - { - $spell_vocations = json_decode($spell['vocations'], true); - echo ''; - if($spell['type'] == 1) - echo ''; - else if($spell['type'] == 2) - echo ''; - else - echo ''; - - echo ''; - } -} +echo $twig->render('spells.html.twig', array( + 'canEdit' => $canEdit, + 'post_vocation_id' => $vocation_id, + 'post_vocation' => $vocation, + 'post_order' => $order, + 'spells' => $spells, +)); ?> -
- Name - - Words - - Type
(count)
-
- Mana - - Level - - Magic
Level
-
- Soul - - Premium - - Vocations: -
' . $spell['name'] . '' . $spell['words'] . 'InstantConjure ('.$spell['conjure_count'].')Rune' . $spell['mana'] . '' . $spell['level'] . '' . $spell['maglevel'] . '' . $spell['soul'] . '' . ($spell ['premium'] == 1 ? 'yes' : 'no') . '' . $config['vocations'][$vocation_id] . '
' .$spell['name'] . '' . $spell['words'] . 'InstantConjure ('.$spell['conjure_count'].')Rune' . $spell['mana'] . '' . $spell['level'] . '' . $spell['maglevel'] . '' . $spell['soul'] . ''. ($spell ['premium'] == 1 ? 'yes' : 'no') .''; - - $showed_vocations = 0; - foreach($spell_vocations as $spell_vocation) - { - if(isset($config['vocations'][$spell_vocation])) { - echo $config['vocations'][$spell_vocation]; - $showed_vocations++; - } - if($showed_vocations != count($spell_vocations)) - echo '
'; - } - - echo '
diff --git a/system/templates/spells.html.twig b/system/templates/spells.html.twig new file mode 100644 index 00000000..c0a29fd8 --- /dev/null +++ b/system/templates/spells.html.twig @@ -0,0 +1,96 @@ +{% if canEdit %} +
+ + +
+{% endif %} + +
+ + + + + + + +
Spell Search
+ + + + + +
Only for vocation: + + + {{ include('buttons.submit.html.twig') }} +
+
+
+
+ + + + + + + + + + + + + {% set i = 0 %} + {% for spell in spells %} + {% set i = i + 1 %} + + + + + + + + + + + + {% endfor %} +
+ Name + + Words + + Type
(count)
+
+ Mana + + Level + + Magic
Level
+
+ Soul + + Premium + + Vocations: +
{{ spell.name }}{{ spell.words }} + {% if spell.type == 1 %} + Instant + {% elseif spell.type == 2 %} + Conjure ({{ spell.conjure_count }}) + {% else %} + Rune + {% endif %} + {{ spell.mana }}{{ spell.level }}{{ spell.maglevel }}{{ spell.soul }}{% if spell.premium == 1 %}yes{% else %}no{% endif %} + {% if spell.vocations|length > 0 %} + + {{ spell.vocations|raw }} + + {% else %} + {{ config.vocations[post_vocation_id] }} + {% endif %} +
\ No newline at end of file