From f84ae88aa42d079998a94818ec94b419a14b368d Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 12 Oct 2017 17:40:02 +0200 Subject: [PATCH] * added faq management - add/edit/move/hide/delete from website * moved install pages to twig * load monsters and spells on installation of the AAC --- common.php | 1 + index.php | 2 + install/includes/functions.php | 4 +- install/index.php | 10 ++ install/steps/admin.php | 32 +--- install/steps/config.php | 64 ++------ install/steps/finish.php | 21 ++- install/steps/license.php | 12 +- install/steps/welcome.php | 42 +++-- system/functions.php | 20 +++ system/init.php | 4 + system/libs/creatures.php | 108 +++++++++++++ system/libs/spells.php | 143 +++++++++++++++++ system/locale/en/install.php | 6 +- system/locale/pl/install.php | 4 +- system/locale/sv/install.php | 4 +- system/pages/admin/plugins.php | 33 ++-- system/pages/commands.php | 3 +- system/pages/creatures.php | 90 +---------- system/pages/faq.php | 174 ++++++++++++++++++++- system/pages/spells.php | 126 +-------------- system/templates/faq.form.html.twig | 26 +++ system/templates/faq.html.twig | 33 +++- system/templates/install.admin.html.twig | 27 ++++ system/templates/install.config.html.twig | 37 +++++ system/templates/install.license.html.twig | 6 + system/templates/install.welcome.html.twig | 12 ++ 27 files changed, 683 insertions(+), 361 deletions(-) create mode 100644 system/libs/creatures.php create mode 100644 system/libs/spells.php create mode 100644 system/templates/faq.form.html.twig create mode 100644 system/templates/install.admin.html.twig create mode 100644 system/templates/install.config.html.twig create mode 100644 system/templates/install.license.html.twig create mode 100644 system/templates/install.welcome.html.twig diff --git a/common.php b/common.php index c8a4c46c..0bc60e76 100644 --- a/common.php +++ b/common.php @@ -45,6 +45,7 @@ define('FLAG_CONTENT_SPELLS', 128); define('FLAG_CONTENT_MONSTERS', 256); define('FLAG_CONTENT_SCREENSHOTS', 512); define('FLAG_CONTENT_MOVIES', 1024); +define('FLAG_CONTENT_FAQ', 2048); // news define('NEWS', 1); diff --git a/index.php b/index.php index af6e3dd6..c3b87ed1 100644 --- a/index.php +++ b/index.php @@ -84,6 +84,8 @@ else { '/^news\/archive\/?$/' => array('subtopic' => 'newsarchive'), '/^news\/archive\/[0-9]+\/?$/' => array('subtopic' => 'newsarchive', 'id' => '$2'), '/^guilds\/[A-Za-z0-9-_%+\']+$/' => array('subtopic' => 'guilds', 'action' => 'show', 'guild' => '$1'), + '/^faq\/add\/?$/' => array('subtopic' => 'faq', 'action' => 'add'), + '/^faq\/edit\/?$/' => array('subtopic' => 'faq', 'action' => 'edit'), '/^forum\/add_board\/?$/' => array('subtopic' => 'forum', 'action' => 'add_board'),# '/^forum\/edit_board\/?$/' => array('subtopic' => 'forum', 'action' => 'edit_board'), '/^forum\/board\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_board', 'id' => '$2'), diff --git a/install/includes/functions.php b/install/includes/functions.php index 75cd7cf4..4c138c55 100644 --- a/install/includes/functions.php +++ b/install/includes/functions.php @@ -62,9 +62,9 @@ function next_buttons($previous = true, $next = true) $ret .= ''; */ if($previous) - $ret .= ''; + $ret .= ''; if($next) - $ret .= ''; + $ret .= ''; $ret .= ''; return $ret; diff --git a/install/index.php b/install/index.php index 617301f0..05bd2a12 100644 --- a/install/index.php +++ b/install/index.php @@ -10,6 +10,16 @@ require(BASE . 'install/includes/functions.php'); require(BASE . 'install/includes/locale.php'); require(BASE . 'config.local.php'); +// twig +require_once LIBS . 'Twig/Autoloader.php'; +Twig_Autoloader::register(); + +$twig_loader = new Twig_Loader_Filesystem(SYSTEM . 'templates'); +$twig = new Twig_Environment($twig_loader, array( + 'cache' => CACHE . 'twig/', + 'auto_reload' => true +)); + if(isset($_POST['vars'])) { foreach($_POST['vars'] as $key => $value) diff --git a/install/steps/admin.php b/install/steps/admin.php index ccb02539..7be88fc9 100644 --- a/install/steps/admin.php +++ b/install/steps/admin.php @@ -1,32 +1,14 @@ -
- - - - - - '; + + echo $twig->render('install.admin.html.twig', array( + 'locale' => $locale, + 'session' => $_SESSION, + 'buttons' => next_buttons(true, $error ? false : true) + )); } - ?> -
- -
- -
- ' . $locale['step_admin_' . $value . '_desc'] . ' -
- -
\ No newline at end of file +?> \ No newline at end of file diff --git a/install/steps/config.php b/install/steps/config.php index d2519348..5e2d3439 100644 --- a/install/steps/config.php +++ b/install/steps/config.php @@ -1,7 +1,7 @@ -
- - - - - - '; +$clients = array(); +foreach($clients_list as $client) { + $client_version = (string)($client / 100); + if(strpos($client_version, '.') == false) + $client_version .= '.0'; + + $clients[$client] = $client_version; +} -echo ' - - - - '; - ?> -
- -
- -
- ' . $locale['step_config_' . $value . '_desc'] . ' -
- -
-
- ' . $locale['step_config_client_desc'] . ' -
- -
\ No newline at end of file +echo $twig->render('install.config.html.twig', array( + 'clients' => $clients, + 'locale' => $locale, + 'session' => $_SESSION, + 'buttons' => next_buttons() +)); +?> \ No newline at end of file diff --git a/install/steps/finish.php b/install/steps/finish.php index ab4e7c94..9bd696cd 100644 --- a/install/steps/finish.php +++ b/install/steps/finish.php @@ -6,14 +6,11 @@ if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['save } else { require(SYSTEM . 'init.php'); - //require(BASE . 'install/includes/config.php'); if(!$error) { - //require(BASE . 'install/includes/database.php'); - if(USE_ACCOUNT_NAME) - $account = isset($_SESSION['var_account']) ? $_SESSION['var_account'] : NULL; + $account = isset($_SESSION['var_account']) ? $_SESSION['var_account'] : null; else - $account_id = isset($_SESSION['var_account_id']) ? $_SESSION['var_account_id'] : NULL; + $account_id = isset($_SESSION['var_account_id']) ? $_SESSION['var_account_id'] : null; $password = $_SESSION['var_password']; @@ -23,7 +20,7 @@ else { $salt = generateRandomString(10, false, true, true); $password = $salt . $password; } - +/* $account_db = new OTS_Account(); $account_db->load(1); if($account_db->isLoaded()) { @@ -38,12 +35,12 @@ else { if(USE_ACCOUNT_NAME) $new_account->create('dummy_account', 1); else - $new_account->create(NULL, 1); + $new_account->create(null, 1); $new_account->setPassword('for sample characters. ' . generateRandomString(10)); $new_account->save(); } - +*/ $account_db = new OTS_Account(); if(isset($account)) $account_db->find($account); @@ -177,6 +174,14 @@ INSERT INTO `myaac_news` (`id`, `type`, `date`, `category`, `title`, `body`, `pl if($success) { success($locale['step_database_imported_players']); } + + require LIBS . 'creatures.php'; + if(Creatures::loadFromXML()) + success($locale['step_database_loaded_creatures']); + + require LIBS . 'spells.php'; + if(Spells::loadFromXML()) + success($locale['step_database_loaded_spells']); $locale['step_finish_desc'] = str_replace('$ADMIN_PANEL$', generateLink(ADMIN_URL, $locale['step_finish_admin_panel'], true), $locale['step_finish_desc']); $locale['step_finish_desc'] = str_replace('$HOMEPAGE$', generateLink(BASE_URL, $locale['step_finish_homepage'], true), $locale['step_finish_desc']); diff --git a/install/steps/license.php b/install/steps/license.php index 0874b89a..3181f866 100644 --- a/install/steps/license.php +++ b/install/steps/license.php @@ -1,10 +1,8 @@ -
- - - -
+echo $twig->render('install.license.html.twig', array( + 'license' => file_get_contents(BASE . 'LICENSE'), + 'buttons' => next_buttons() +)); +?> diff --git a/install/steps/welcome.php b/install/steps/welcome.php index b170f606..8a38e8ce 100644 --- a/install/steps/welcome.php +++ b/install/steps/welcome.php @@ -5,29 +5,23 @@ if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['save } else { unset($_SESSION['saved']); -?> -
- -

- -
- - -
- $tmp_locale, 'name' => $locale['name']); + } + } + echo $twig->render('install.welcome.html.twig', array( + 'locales' => $locales, + 'locale' => $locale, + 'buttons' => next_buttons(false, true) + )); } ?> \ No newline at end of file diff --git a/system/functions.php b/system/functions.php index c0d1363b..b6d42500 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1057,6 +1057,26 @@ function get_templates() return $ret; } +/** + * Generates list of installed plugins + * @return array $plugins + */ +function get_plugins() +{ + $ret = array(); + + $path = PLUGINS; + foreach(scandir($path) as $file) { + $file_ext = pathinfo($file, PATHINFO_EXTENSION); + $file_name = pathinfo($file, PATHINFO_FILENAME); + if ($file == '.' || $file == '..' || $file == 'disabled' || $file == 'example.json' || is_dir($path . $file) || $file_ext != 'json') + continue; + + $ret[] = str_replace('.json', '', $file_name); + } + + return $ret; +} function getWorldName($id) { global $config; diff --git a/system/init.php b/system/init.php index 110c9957..82e319ca 100644 --- a/system/init.php +++ b/system/init.php @@ -14,6 +14,10 @@ require_once(BASE . 'config.php'); if(file_exists(BASE . 'config.local.php')) // user customizations require(BASE . 'config.local.php'); +if(!isset($config['installed']) || !$config['installed']) { + die('AAC has not been installed yet or there was error during installation. Please install again.'); +} + date_default_timezone_set($config['date_timezone']); // take care of trailing slash at the end if($config['server_path'][strlen($config['server_path']) - 1] != '/') diff --git a/system/libs/creatures.php b/system/libs/creatures.php new file mode 100644 index 00000000..d26cfcdf --- /dev/null +++ b/system/libs/creatures.php @@ -0,0 +1,108 @@ +query("DELETE FROM `myaac_monsters`;"); } catch(PDOException $error) {} + + if($show) { + echo '

Reload monsters.

'; + echo "

All records deleted from table 'myaac_monsters' in database.

"; + } + + $allmonsters = new OTS_MonstersList($config['data_path'].'monster/'); + //$names_added must be an array + $names_added[] = ''; + //add monsters + foreach($allmonsters as $lol) { + $monster = $allmonsters->current(); + if(!$monster->loaded()) { + if($show) { + warning('Error while adding monster: ' . $allmonsters->currentFile()); + } + continue; + } + //load monster mana needed to summon/convince + $mana = $monster->getManaCost(); + //load monster experience + $exp = $monster->getExperience(); + //load monster name + $name = $monster->getName(); + //load monster health + $health = $monster->getHealth(); + //load monster speed and calculate "speed level" + $speed_ini = $monster->getSpeed(); + if($speed_ini <= 220) { + $speed_lvl = 1; + } else { + $speed_lvl = ($speed_ini - 220) / 2; + } + //check "is monster use haste spell" + $defenses = $monster->getDefenses(); + $use_haste = 0; + foreach($defenses as $defense) { + if($defense == 'speed') { + $use_haste = 1; + } + } + //load monster flags + $flags = $monster->getFlags(); + //create string with immunities + $immunities = $monster->getImmunities(); + $imu_nr = 0; + $imu_count = count($immunities); + $immunities_string = ''; + foreach($immunities as $immunitie) { + $immunities_string .= $immunitie; + $imu_nr++; + if($imu_count != $imu_nr) { + $immunities_string .= ", "; + } + } + + //create string with voices + $voices = $monster->getVoices(); + $voice_nr = 0; + $voice_count = count($voices); + $voices_string = ''; + foreach($voices as $voice) { + $voices_string .= '"'.$voice.'"'; + $voice_nr++; + if($voice_count != $voice_nr) { + $voices_string .= ", "; + } + } + //load race + $race = $monster->getRace(); + //create monster gfx name + //$gfx_name = str_replace(" ", "", trim(mb_strtolower($name))).".gif"; + $gfx_name = trim(mb_strtolower($name)).".gif"; + //don't add 2 monsters with same name, like Butterfly + + if(!isset($flags['summonable'])) + $flags['summonable'] = '0'; + if(!isset($flags['convinceable'])) + $flags['convinceable'] = '0'; + + if(!in_array($name, $names_added)) { + try { + $db->query("INSERT INTO `myaac_monsters` (`hide_creature`, `name`, `mana`, `exp`, `health`, `speed_lvl`, `use_haste`, `voices`, `immunities`, `summonable`, `convinceable`, `race`, `gfx_name`, `file_path`) VALUES (0, " . $db->quote($name) . ", " . $db->quote(empty($mana) ? 0 : $mana) . ", " . $db->quote($exp) . ", " . $db->quote($health) . ", " . $db->quote($speed_lvl) . ", " . $db->quote($use_haste) . ", " . $db->quote($voices_string) . ", " . $db->quote($immunities_string) . ", " . $db->quote($flags['summonable'] > 0 ? 1 : 0) . ", " . $db->quote($flags['convinceable'] > 0 ? 1 : 0) . ", ".$db->quote($race).", ".$db->quote($gfx_name).", " . $db->quote($allmonsters->currentFile()) . ")"); + + if($show) { + success("Added: ".$name."
"); + } + } + catch(PDOException $error) { + if($show) { + warning('Error while adding monster (' . $name . '): ' . $error->getMessage()); + } + } + + $names_added[] = $name; + } + } + + return true; + } +} \ No newline at end of file diff --git a/system/libs/spells.php b/system/libs/spells.php new file mode 100644 index 00000000..8c671b4c --- /dev/null +++ b/system/libs/spells.php @@ -0,0 +1,143 @@ +query('DELETE FROM `' . TABLE_PREFIX . 'spells`;'); } catch(PDOException $error) {} + + if($show) { + echo '

Reload 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; + } + + $allspells = new OTS_SpellsList($config['data_path'].'spells/spells.xml'); + //add conjure spells + $conjurelist = $allspells->getConjuresList(); + if($show) { + echo "

Conjure:

"; + } + + foreach($conjurelist as $spellname) { + $spell = $allspells->getConjure($spellname); + $lvl = $spell->getLevel(); + $mlvl = $spell->getMagicLevel(); + $mana = $spell->getMana(); + $name = $spell->getName(); + $soul = $spell->getSoul(); + $spell_txt = $spell->getWords(); + $vocations = $spell->getVocations(); + $nr_of_vocations = count($vocations); + $vocations_to_db = ""; + $voc_nr = 0; + foreach($vocations as $vocation_to_add) { + if(check_number($vocation_to_add)) { + $vocations_to_db .= $vocation_to_add; + } + else + $vocations_to_db .= $vocations_ids[$vocation_to_add]; + $voc_nr++; + + if($voc_nr != $nr_of_vocations) { + $vocations_to_db .= ','; + } + } + + $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($vocations_to_db) . ', ' . $db->quote($count) . ', ' . $db->quote($hide_spell) . ')'); + if($show) { + success("Added: " . $name . "
"); + } + } + catch(PDOException $error) { + if($show) { + warning('Error while adding spell (' . $name . '): ' . $error->getMessage()); + } + } + } + + //add instant spells + $instantlist = $allspells->getInstantsList(); + if($show) { + echo "

Instant:

"; + } + + foreach($instantlist as $spellname) { + $spell = $allspells->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) + continue; + + $vocations = $spell->getVocations(); + $nr_of_vocations = count($vocations); + $vocations_to_db = ""; + $voc_nr = 0; + foreach($vocations as $vocation_to_add) { + if(check_number($vocation_to_add)) { + $vocations_to_db .= $vocation_to_add; + } + else + $vocations_to_db .= $vocations_ids[$vocation_to_add]; + $voc_nr++; + + if($voc_nr != $nr_of_vocations) { + $vocations_to_db .= ','; + } + } + $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."', '".$vocations_to_db."', '".$count."', '".$hide_spell."')"); + if($show) { + success("Added: ".$name."
"); + } + } + catch(PDOException $error) { + if($show) { + warning('Error while adding spell (' . $name . '): ' . $error->getMessage()); + } + } + } + + return true; + } +} \ No newline at end of file diff --git a/system/locale/en/install.php b/system/locale/en/install.php index b851d345..d12bae8f 100644 --- a/system/locale/en/install.php +++ b/system/locale/en/install.php @@ -44,10 +44,10 @@ $locale['step_config_server_path'] = 'Server path'; $locale['step_config_server_path_desc'] = 'Path to your TFS main directory, where you have config.lua located.'; $locale['step_config_mail_admin'] = 'Admin E-Mail'; -$locale['step_config_mail_admin_desc'] = 'Address where emails from contact form will be delivered, for example admin@gmail.com'; +$locale['step_config_mail_admin_desc'] = 'Address where emails from contact form will be delivered, for example admin@gmail.com'; $locale['step_config_mail_admin_error'] = 'Admin E-Mail is not correct.'; $locale['step_config_mail_address'] = 'Server E-Mail'; -$locale['step_config_mail_address_desc'] = 'Address which will be used for outgoing emails (from:), for example no-reply@your-server.org'; +$locale['step_config_mail_address_desc'] = 'Address which will be used for outgoing emails (from:), for example no-reply@your-server.org'; $locale['step_config_mail_address_error'] = 'Server E-Mail is not correct.'; $locale['step_config_client'] = 'Client version'; $locale['step_config_client_desc'] = 'Used for download page and some templates'; @@ -69,6 +69,8 @@ $locale['step_database_adding_field'] = 'Adding field'; $locale['step_database_modifying_field'] = 'Modifying field'; $locale['step_database_changing_field'] = 'Changing $FIELD$ to $FIELD_NEW$...'; $locale['step_database_imported_players'] = 'Imported player samples...'; +$locale['step_database_loaded_creatures'] = 'Loaded creatures...'; +$locale['step_database_loaded_spells'] = 'Loaded spells...'; $locale['step_database_created_account'] = 'Created admin account...'; $locale['step_database_created_news'] = 'Created newses...'; diff --git a/system/locale/pl/install.php b/system/locale/pl/install.php index d166436d..a1be3ab9 100644 --- a/system/locale/pl/install.php +++ b/system/locale/pl/install.php @@ -48,10 +48,10 @@ $locale['step_config_password'] = 'Hasło do konta admina'; $locale['step_config_password_desc'] = 'Hasło do Twojego konta administratora.'; $locale['step_config_mail_admin'] = 'E-Mail admina'; -$locale['step_config_mail_admin_desc'] = 'Na ten adres będą dostarczane E-Maile z formularza kontaktowego , przykładowo admin@gmail.com'; +$locale['step_config_mail_admin_desc'] = 'Na ten adres będą dostarczane E-Maile z formularza kontaktowego , przykładowo admin@gmail.com'; $locale['step_config_mail_admin_error'] = 'E-Mail admina jest niepoprawny.'; $locale['step_config_mail_address'] = 'E-Mail serwera'; -$locale['step_config_mail_address_desc'] = 'Ten adres będzie używany do wysyłanych wiadomości z serwera (from:), przykładowo no-reply@twój-serwer.org'; +$locale['step_config_mail_address_desc'] = 'Ten adres będzie używany do wysyłanych wiadomości z serwera (from:), przykładowo no-reply@twój-serwer.org'; $locale['step_config_mail_address_error'] = 'E-Mail serwera jest niepoprawny.'; $locale['step_config_client'] = 'Wersja klienta'; $locale['step_config_client_desc'] = 'Używana do strony pobieranie klienta oraz kilku szablonów'; diff --git a/system/locale/sv/install.php b/system/locale/sv/install.php index 16868dcf..a0c7b911 100644 --- a/system/locale/sv/install.php +++ b/system/locale/sv/install.php @@ -43,11 +43,11 @@ $locale['step_config_title'] = 'Grundläggande konfiguration'; $locale['step_config_server_path'] = 'Server mapp'; $locale['step_config_server_path_desc'] = 'Mappen som innhåller exe filen till The Forgotten Server, där du har din config.lua.'; $locale['step_config_mail_admin'] = 'Admin E-Post'; -$locale['step_config_mail_admin_desc'] = 'Adress där E-Post från kontaktförmolär kommer att leveraras, till exempel admin@gmail.com'; +$locale['step_config_mail_admin_desc'] = 'Adress där E-Post från kontaktförmolär kommer att leveraras, till exempel admin@gmail.com'; $locale['step_config_mail_admin_error'] = 'Admin E-Post är inte korrekt.'; $locale['step_config_mail_address'] = 'Server E-Post'; -$locale['step_config_mail_address_desc'] = 'Adress som kommer att användas för utgående email (från:), till exempel no-reply@your-server.org'; +$locale['step_config_mail_address_desc'] = 'Adress som kommer att användas för utgående email (från:), till exempel no-reply@your-server.org'; $locale['step_config_mail_address_error'] = 'Server E-Post är inte korrekt.'; $locale['step_config_client'] = 'Klientversion'; diff --git a/system/pages/admin/plugins.php b/system/pages/admin/plugins.php index 16deb280..8d862957 100644 --- a/system/pages/admin/plugins.php +++ b/system/pages/admin/plugins.php @@ -13,8 +13,6 @@ $title = 'Plugin manager'; require(SYSTEM . 'hooks.php'); -echo $twig->render('admin.plugins.form.html.twig'); - function deleteDirectory($dir) { if(!file_exists($dir)) { return true; @@ -37,6 +35,8 @@ function deleteDirectory($dir) { return rmdir($dir); } +echo $twig->render('admin.plugins.form.html.twig'); + if(isset($_REQUEST['uninstall'])){ $uninstall = $_REQUEST['uninstall']; @@ -112,13 +112,11 @@ else if(isset($_FILES["plugin"]["name"])) if($filetype == 'zip') // check if it is zipped/compressed file { $tmp_filename = pathinfo($filename, PATHINFO_FILENAME); - $targetdir = BASE; - $targetzip = BASE . 'plugins/' . $tmp_filename; + $targetzip = BASE . 'plugins/' . $tmp_filename . '.zip'; if(move_uploaded_file($tmp_name, $targetzip)) { // move uploaded file $zip = new ZipArchive(); - $x = $zip->open($targetzip); // open the zip file to extract - if ($x === true) { + if ($zip->open($targetzip)) { for ($i = 0; $i < $zip->numFiles; $i++) { $tmp = $zip->getNameIndex($i); if(pathinfo($tmp, PATHINFO_DIRNAME) == 'plugins' && pathinfo($tmp, PATHINFO_EXTENSION) == 'json') @@ -128,7 +126,7 @@ else if(isset($_FILES["plugin"]["name"])) if(!isset($json_file)) { error('Cannot find plugin info .json file. Installation is discontinued.'); } - else if($zip->extractTo($targetdir)) { // place in the directory with same name + else if($zip->extractTo(BASE)) { // place in the directory with same name $file_name = BASE . $json_file; if(!file_exists($file_name)) warning("Cannot load " . $file_name . ". File doesn't exist."); @@ -224,36 +222,27 @@ else if(isset($_FILES["plugin"]["name"])) } $plugins = array(); -$rows = array(); - -$path = PLUGINS; -foreach(scandir($path) as $file) +foreach(get_plugins() as $plugin) { - $file_ext = pathinfo($file, PATHINFO_EXTENSION); - $file_name = pathinfo($file, PATHINFO_FILENAME); - if($file == '.' || $file == '..' || $file == 'disabled' || $file == 'example.json' || is_dir($path . $file) || $file_ext != 'json') - continue; - - $file_info = str_replace('.json', '', $file_name); - $string = file_get_contents(BASE . 'plugins/' . $file_info . '.json'); + $string = file_get_contents(BASE . 'plugins/' . $plugin . '.json'); $plugin_info = json_decode($string, true); if($plugin_info == false) { - warning('Cannot load plugin info ' . $file); + warning('Cannot load plugin info ' . $plugin . '.json'); } else { - $rows[] = array( + $plugins[] = array( 'name' => $plugin_info['name'], 'description' => $plugin_info['description'], 'version' => $plugin_info['version'], 'author' => $plugin_info['author'], 'contact' => $plugin_info['contact'], - 'file' => $file_info, + 'file' => $plugin, 'uninstall' => isset($plugin_info['uninstall']) ); } } echo $twig->render('admin.plugins.html.twig', array( - 'plugins' => $rows + 'plugins' => $plugins )); ?> \ No newline at end of file diff --git a/system/pages/commands.php b/system/pages/commands.php index 2a3e8fe6..d6f5af7d 100644 --- a/system/pages/commands.php +++ b/system/pages/commands.php @@ -92,8 +92,7 @@ $last = $commands->rowCount(); echo $twig->render('commands.html.twig', array( 'commands' => $commands, 'last' => $last, - 'canEdit' => $canEdit, - 'vdarkborder' => $config['vdarkborder'] + 'canEdit' => $canEdit )); class Commands diff --git a/system/pages/creatures.php b/system/pages/creatures.php index c311b50a..9f9ea57f 100644 --- a/system/pages/creatures.php +++ b/system/pages/creatures.php @@ -64,94 +64,8 @@ function printLoot($level, $itemid, $count, $chance) $canEdit = hasFlag(FLAG_CONTENT_MONSTERS) || admin(); if(isset($_POST['reload_monsters']) && $canEdit) { - try { $db->query("DELETE FROM myaac_monsters WHERE 1 = 1"); } catch(PDOException $error) {} - echo '

Reload monsters.

'; - echo '

All records deleted from table \'myaac_monsters\' in database.

'; - $allmonsters = new OTS_MonstersList($config['data_path'].'monster/'); - //$names_added must be an array - $names_added[] = ''; - //add monsters - foreach($allmonsters as $lol) { - $monster = $allmonsters->current(); - if(!$monster->loaded()) { - warning('Error while adding monster: ' . $allmonsters->currentFile()); - continue; - } - //load monster mana needed to summon/convince - $mana = $monster->getManaCost(); - //load monster experience - $exp = $monster->getExperience(); - //load monster name - $name = $monster->getName(); - //load monster health - $health = $monster->getHealth(); - //load monster speed and calculate "speed level" - $speed_ini = $monster->getSpeed(); - if($speed_ini <= 220) { - $speed_lvl = 1; - } else { - $speed_lvl = ($speed_ini - 220) / 2; - } - //check "is monster use haste spell" - $defenses = $monster->getDefenses(); - $use_haste = 0; - foreach($defenses as $defense) { - if($defense == 'speed') { - $use_haste = 1; - } - } - //load monster flags - $flags = $monster->getFlags(); - //create string with immunities - $immunities = $monster->getImmunities(); - $imu_nr = 0; - $imu_count = count($immunities); - $immunities_string = ''; - foreach($immunities as $immunitie) { - $immunities_string .= $immunitie; - $imu_nr++; - if($imu_count != $imu_nr) { - $immunities_string .= ", "; - } - } - - //create string with voices - $voices = $monster->getVoices(); - $voice_nr = 0; - $voice_count = count($voices); - $voices_string = ''; - foreach($voices as $voice) { - $voices_string .= '"'.$voice.'"'; - $voice_nr++; - if($voice_count != $voice_nr) { - $voices_string .= ", "; - } - } - //load race - $race = $monster->getRace(); - //create monster gfx name - //$gfx_name = str_replace(" ", "", trim(mb_strtolower($name))).".gif"; - $gfx_name = trim(mb_strtolower($name)).".gif"; - //don't add 2 monsters with same name, like Butterfly - - if(!isset($flags['summonable'])) - $flags['summonable'] = '0'; - if(!isset($flags['convinceable'])) - $flags['convinceable'] = '0'; - - if(!in_array($name, $names_added)) { - try { - $db->query("INSERT INTO `myaac_monsters` (`hide_creature`, `name`, `mana`, `exp`, `health`, `speed_lvl`, `use_haste`, `voices`, `immunities`, `summonable`, `convinceable`, `race`, `gfx_name`, `file_path`) VALUES (0, " . $db->quote($name) . ", " . $db->quote(empty($mana) ? 0 : $mana) . ", " . $db->quote($exp) . ", " . $db->quote($health) . ", " . $db->quote($speed_lvl) . ", " . $db->quote($use_haste) . ", " . $db->quote($voices_string) . ", " . $db->quote($immunities_string) . ", " . $db->quote($flags['summonable'] > 0 ? 1 : 0) . ", " . $db->quote($flags['convinceable'] > 0 ? 1 : 0) . ", ".$db->quote($race).", ".$db->quote($gfx_name).", " . $db->quote($allmonsters->currentFile()) . ")"); - - success("Added: ".$name."
"); - } - catch(PDOException $error) { - warning('Error while adding monster (' . $name . '): ' . $error->getMessage()); - } - - $names_added[] = $name; - } - } + require LIBS . 'creatures.php'; + Creatures::loadFromXML(true); } if($canEdit) diff --git a/system/pages/faq.php b/system/pages/faq.php index 5c6e802e..185f8414 100644 --- a/system/pages/faq.php +++ b/system/pages/faq.php @@ -11,19 +11,179 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Frequently Asked Questions'; -$faqs = $db->query('SELECT ' . $db->fieldName('question') . ', ' . $db->fieldName('answer') . - ' FROM ' . $db->tableName(TABLE_PREFIX . 'faq') . ' ORDER BY ' . $db->fieldName('ordering')); +$canEdit = hasFlag(FLAG_CONTENT_FAQ) || superAdmin(); +if($canEdit) +{ + if(!empty($action)) + { + if($action == 'delete' || $action == 'edit' || $action == 'hide' || $action == 'moveup' || $action == 'movedown') + $id = $_REQUEST['id']; + + if(isset($_REQUEST['question'])) + $question = $_REQUEST['question']; + + if(isset($_REQUEST['answer'])) + $answer = stripslashes($_REQUEST['answer']); + + $errors = array(); + + if($action == 'add') { + if(FAQ::add($question, $answer, $errors)) + $question = $answer = ''; + } + else if($action == 'delete') { + FAQ::delete($id, $errors); + } + else if($action == 'edit') + { + if(isset($id) && !isset($question)) { + $faq = FAQ::get($id); + $question = $faq['question']; + $answer = $faq['answer']; + } + else { + FAQ::update($id, $question, $answer); + $action = $question = $answer = ''; + } + } + else if($action == 'hide') { + FAQ::toggleHidden($id, $errors); + } + else if($action == 'moveup') { + FAQ::move($id, -1, $errors); + } + else if($action == 'movedown') { + FAQ::move($id, 1, $errors); + } + + if(!empty($errors)) + echo $twig->render('error_box.html.twig', array('errors' => $errors)); + } + + echo $twig->render('faq.form.html.twig', array( + 'link' => getLink('faq/' . ($action == 'edit' ? 'edit' : 'add')), + 'action' => $action, + 'id' => isset($id) ? $id : null, + 'question' => isset($question) ? $question : null, + 'answer' => isset($answer) ? $answer : null + )); +} + +$faqs = + $db->query('SELECT `id`, `question`, `answer`' . + ($canEdit ? ', `hidden`, `ordering`' : '') . + ' FROM `' . TABLE_PREFIX . 'faq`' . + (!$canEdit ? ' WHERE `hidden` != 1' : '') . + ' ORDER BY `ordering`;'); if(!$faqs->rowCount()) { -?> + ?> There are no questions added yet. -' . TABLE_PREFIX . 'faq table.'; + rowCount(); echo $twig->render('faq.html.twig', array( - 'faqs' => $faqs + 'faqs' => $faqs, + 'last' => $last, + 'canEdit' => $canEdit )); + +class FAQ +{ + static public function add($question, $answer, &$errors) + { + global $db; + if(isset($question[0]) && isset($answer[0])) + { + $query = $db->select(TABLE_PREFIX . 'faq', array('question' => $question)); + + if($query === false) + { + $query = + $db->query( + 'SELECT ' . $db->fieldName('ordering') . + ' FROM ' . $db->tableName(TABLE_PREFIX . 'faq') . + ' ORDER BY ' . $db->fieldName('ordering') . ' DESC LIMIT 1' + ); + + $ordering = 0; + if($query->rowCount() > 0) { + $query = $query->fetch(); + $ordering = $query['ordering'] + 1; + } + $db->insert(TABLE_PREFIX . 'faq', array('question' => $question, 'answer' => $answer, 'ordering' => $ordering)); + } + else + $errors[] = 'FAQ with this question already exists.'; + } + else + $errors[] = 'Please fill all inputs.'; + + return !count($errors); + } + + static public function get($id) { + global $db; + return $db->select(TABLE_PREFIX . 'faq', array('id' => $id)); + } + + static public function update($id, $question, $answer) { + global $db; + $db->update(TABLE_PREFIX . 'faq', array('question' => $question, 'answer' => $answer), array('id' => $id)); + } + + static public function delete($id, &$errors) + { + global $db; + if(isset($id)) + { + if(self::get($id) !== false) + $db->delete(TABLE_PREFIX . 'faq', array('id' => $id)); + else + $errors[] = 'FAQ with id ' . $id . ' does not exists.'; + } + else + $errors[] = 'id not set'; + + return !count($errors); + } + + static public function toggleHidden($id, &$errors) + { + global $db; + if(isset($id)) + { + $query = self::get($id); + if($query !== false) + $db->update(TABLE_PREFIX . 'faq', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id)); + else + $errors[] = 'FAQ with id ' . $id . ' does not exists.'; + } + else + $errors[] = 'id not set'; + + return !count($errors); + } + + static public function move($id, $i, &$errors) + { + global $db; + $query = self::get($id); + if($query !== false) + { + $ordering = $query['ordering'] + $i; + $old_record = $db->select(TABLE_PREFIX . 'faq', array('ordering' => $ordering)); + if($old_record !== false) + $db->update(TABLE_PREFIX . 'faq', array('ordering' => $query['ordering']), array('ordering' => $ordering)); + + $db->update(TABLE_PREFIX . 'faq', array('ordering' => $ordering), array('id' => $id)); + } + else + $errors[] = 'FAQ with id ' . $id . ' does not exists.'; + + return !count($errors); + } +} ?> diff --git a/system/pages/spells.php b/system/pages/spells.php index 9e006730..b4324a75 100644 --- a/system/pages/spells.php +++ b/system/pages/spells.php @@ -12,125 +12,11 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Spells'; -$config_vocations = $config['vocations']; $canEdit = hasFlag(FLAG_CONTENT_SPELLS) || admin(); if(isset($_POST['reload_spells']) && $canEdit) { - try { $db->query('DELETE FROM ' . TABLE_PREFIX . 'spells WHERE 1 = 1'); } catch(PDOException $error) {} - echo '

Reload 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; - } - - $allspells = new OTS_SpellsList($config['data_path'].'spells/spells.xml'); - //add conjure spells - $conjurelist = $allspells->getConjuresList(); - echo "

Conjure:

"; - foreach($conjurelist as $spellname) { - $spell = $allspells->getConjure($spellname); - $lvl = $spell->getLevel(); - $mlvl = $spell->getMagicLevel(); - $mana = $spell->getMana(); - $name = $spell->getName(); - $soul = $spell->getSoul(); - $spell_txt = $spell->getWords(); - $vocations = $spell->getVocations(); - $nr_of_vocations = count($vocations); - $vocations_to_db = ""; - $voc_nr = 0; - foreach($vocations as $vocation_to_add) { - if(check_number($vocation_to_add)) { - $vocations_to_db .= $vocation_to_add; - } - else - $vocations_to_db .= $vocations_ids[$vocation_to_add]; - $voc_nr++; - - if($voc_nr != $nr_of_vocations) { - $vocations_to_db .= ','; - } - } - - $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($vocations_to_db) . ', ' . $db->quote($count) . ', ' . $db->quote($hide_spell) . ')'); - success("Added: " . $name . "
"); - } - catch(PDOException $error) { - warning('Error while adding spell (' . $name . '): ' . $error->getMessage()); - } - } - - //add instant spells - $instantlist = $allspells->getInstantsList(); - echo "

Instant:

"; - foreach($instantlist as $spellname) { - $spell = $allspells->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) - continue; - - $vocations = $spell->getVocations(); - $nr_of_vocations = count($vocations); - $vocations_to_db = ""; - $voc_nr = 0; - foreach($vocations as $vocation_to_add) { - if(check_number($vocation_to_add)) { - $vocations_to_db .= $vocation_to_add; - } - else - $vocations_to_db .= $vocations_ids[$vocation_to_add]; - $voc_nr++; - - if($voc_nr != $nr_of_vocations) { - $vocations_to_db .= ','; - } - } - $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."', '".$vocations_to_db."', '".$count."', '".$hide_spell."')"); - success("Added: ".$name."
"); - } - catch(PDOException $error) { - warning('Error while adding spell (' . $name . '): ' . $error->getMessage()); - } - } + require LIBS . 'spells.php'; + Spells::loadFromXML(true); } if($canEdit) @@ -165,7 +51,7 @@ if(!in_array($order, array('spell', 'words', 'type', 'mana', 'level', 'maglevel' echo '>All'; - foreach($config_vocations as $id => $vocation) + foreach($config['vocations'] as $id => $vocation) { echo '