* added faq management - add/edit/move/hide/delete from website

* moved install pages to twig
* load monsters and spells on installation of the AAC
This commit is contained in:
slawkens 2017-10-12 17:40:02 +02:00
parent 315e0400ff
commit f84ae88aa4
27 changed files with 683 additions and 361 deletions

View File

@ -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);

View File

@ -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'),

View File

@ -62,9 +62,9 @@ function next_buttons($previous = true, $next = true)
$ret .= '<input class="button" type="submit" onclick="document.getElementById(\'step\').value=\'' . $steps[$i + 1] . '\';" value="' . $locale['next'] . '" />';
*/
if($previous)
$ret .= '<input type="button" class="button" onclick="document.getElementById(\'step\').value=\'' . $steps[$i - 1] . '\'; this.form.submit();" value="' . $locale['previous'] . '" />';
$ret .= '<input type="button" class="button" onclick="document.getElementById(\'step\').value=\'' . $steps[$i - 1] . '\'; this.form.submit();" value="&laquo; ' . $locale['previous'] . '" />';
if($next)
$ret .= '<input type="button" class="button" onclick="document.getElementById(\'step\').value=\'' . $steps[$i + 1] . '\'; this.form.submit();" value="' . $locale['next'] . '" />';
$ret .= '<input type="button" class="button" onclick="document.getElementById(\'step\').value=\'' . $steps[$i + 1] . '\'; this.form.submit(); " value="' . $locale['next'] . ' &raquo;" />';
$ret .= '</div>';
return $ret;

View File

@ -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)

View File

@ -1,32 +1,14 @@
<?php
defined('MYAAC') or die('Direct access not allowed!');
?>
<form action="<?php echo BASE_URL; ?>install/" method="post" autocomplete="off">
<input type="hidden" name="step" id="step" value="finish" />
<table>
<?php
require(BASE . 'install/includes/config.php');
if(!$error) {
require(BASE . 'install/includes/database.php');
foreach(array(USE_ACCOUNT_NAME ? 'account' : 'account_id', 'password') as $value)
echo '
<tr>
<td>
<label for="vars_' . $value . '">
<span>' . $locale['step_admin_' . $value] . '</span>
</label>
<br>
<input type="text" name="vars[' . $value . ']" id="vars_' . $value . '"' . (isset($_SESSION['var_' . $value]) ? ' value="' . $_SESSION['var_' . $value] . '"' : '') . '/>
</td>
<td>
<em>' . $locale['step_admin_' . $value . '_desc'] . '</em>
</td>
</tr>';
echo $twig->render('install.admin.html.twig', array(
'locale' => $locale,
'session' => $_SESSION,
'buttons' => next_buttons(true, $error ? false : true)
));
}
?>
</table>
<?php echo next_buttons(true, $error ? false : true);
?>
</form>
?>

View File

@ -1,7 +1,7 @@
<?php
defined('MYAAC') or die('Direct access not allowed!');
$clients = array(
$clients_list = array(
710,
740,
750,
@ -65,51 +65,19 @@ $clients = array(
1098,
);
?>
<form action="<?php echo BASE_URL; ?>install/" method="post" autocomplete="off">
<input type="hidden" name="step" id="step" value="database" />
<table>
<?php
foreach(array('server_path', 'mail_admin', 'mail_address') as $value)
echo '
<tr>
<td>
<label for="vars_' . $value . '">
<span>' . $locale['step_config_' . $value] . '</span>
</label>
<br>
<input type="text" name="vars[' . $value . ']" id="vars_' . $value . '"' . (isset($_SESSION['var_' . $value]) ? ' value="' . $_SESSION['var_' . $value] . '"' : '') . '/>
</td>
<td>
<em>' . $locale['step_config_' . $value . '_desc'] . '</em>
</td>
</tr>';
$clients = array();
foreach($clients_list as $client) {
$client_version = (string)($client / 100);
if(strpos($client_version, '.') == false)
$client_version .= '.0';
echo '
<tr>
<td>
<label for="vars_client">
<span>' . $locale['step_config_client'] . '</span>
</label>
<br>
<select name="vars[client]" id="vars_client">';
//$i = 0;
foreach($clients as $client) {
$client_version = (string)($client / 100);
if(strpos($client_version, '.') == false)
$client_version .= '.0';
echo '<option value="' . $client . '">' . $client_version . '</option>';
}
$clients[$client] = $client_version;
}
echo '
</td>
<td>
<em>' . $locale['step_config_client_desc'] . '</em>
</td>
</tr>';
?>
</table>
<?php
echo next_buttons(true, true);
echo $twig->render('install.config.html.twig', array(
'clients' => $clients,
'locale' => $locale,
'session' => $_SESSION,
'buttons' => next_buttons()
));
?>
</form>

View File

@ -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);
@ -178,6 +175,14 @@ INSERT INTO `myaac_news` (`id`, `type`, `date`, `category`, `title`, `body`, `pl
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']);
$locale['step_finish_desc'] = str_replace('$LINK$', generateLink('http://my-aac.org', 'http://my-aac.org', true), $locale['step_finish_desc']);

View File

@ -1,10 +1,8 @@
<?php
defined('MYAAC') or die('Direct access not allowed!');
?>
<form action="<?php echo BASE_URL; ?>install/" method="post">
<input type="hidden" name="step" id="step" value="requirements" />
<textarea rows="10" cols="80" readonly="1"><?php echo file_get_contents(BASE . 'LICENSE'); ?></textarea>
<?php echo next_buttons();
?>
</form>
echo $twig->render('install.license.html.twig', array(
'license' => file_get_contents(BASE . 'LICENSE'),
'buttons' => next_buttons()
));
?>

View File

@ -5,29 +5,23 @@ if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['save
}
else {
unset($_SESSION['saved']);
?>
<form action="<?php echo BASE_URL; ?>install/" method="post">
<input type="hidden" name="step" id="step" value="license" />
<div class="input"><p><?php echo $locale['step_welcome_desc']; ?></p>
<select name="lang">
<?php
foreach(get_locales() as $tmp_locale)
{
$lang_file_main = LOCALE . $tmp_locale . '/main.php';
$lang_file_install = LOCALE . $tmp_locale . '/install.php';
if(@file_exists($lang_file_main)
&& @file_exists($lang_file_install))
{
require($lang_file_main);
echo '<option value="' . $tmp_locale . '">' . $locale['name'] . '</option>';
}
}
?>
</select>
</div>
<?php echo next_buttons(false, true); ?>
</form>
<?php
$locales = array();
foreach(get_locales() as $tmp_locale)
{
$lang_file_main = LOCALE . $tmp_locale . '/main.php';
$lang_file_install = LOCALE . $tmp_locale . '/install.php';
if(@file_exists($lang_file_main)
&& @file_exists($lang_file_install))
{
require($lang_file_main);
$locales[] = array('id' => $tmp_locale, 'name' => $locale['name']);
}
}
echo $twig->render('install.welcome.html.twig', array(
'locales' => $locales,
'locale' => $locale,
'buttons' => next_buttons(false, true)
));
}
?>

View File

@ -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;

View File

@ -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] != '/')

108
system/libs/creatures.php Normal file
View File

@ -0,0 +1,108 @@
<?php
class Creatures {
public static function loadFromXML($show = false) {
global $config, $db;
try { $db->query("DELETE FROM `myaac_monsters`;"); } catch(PDOException $error) {}
if($show) {
echo '<h2>Reload monsters.</h2>';
echo "<h2>All records deleted from table 'myaac_monsters' in database.</h2>";
}
$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."<br/>");
}
}
catch(PDOException $error) {
if($show) {
warning('Error while adding monster (' . $name . '): ' . $error->getMessage());
}
}
$names_added[] = $name;
}
}
return true;
}
}

143
system/libs/spells.php Normal file
View File

@ -0,0 +1,143 @@
<?php
class Spells {
public static function loadFromXML($show = false) {
global $config, $db;
try { $db->query('DELETE FROM `' . TABLE_PREFIX . 'spells`;'); } catch(PDOException $error) {}
if($show) {
echo '<h2>Reload spells.</h2>';
echo '<h2>All records deleted from table <b>' . TABLE_PREFIX . 'spells</b> in database.</h2>';
}
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 "<h3>Conjure:</h3>";
}
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 . "<br>");
}
}
catch(PDOException $error) {
if($show) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
}
}
}
//add instant spells
$instantlist = $allspells->getInstantsList();
if($show) {
echo "<h3>Instant:</h3>";
}
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."<br/>");
}
}
catch(PDOException $error) {
if($show) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
}
}
}
return true;
}
}

View File

@ -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 <i>admin@gmail.com</i>';
$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 <i>no-reply@your-server.org</i>';
$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...';

View File

@ -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 <i>admin@gmail.com</i>';
$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 <i>no-reply@twój-serwer.org</i>';
$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';

View File

@ -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 <i>admin@gmail.com</i>';
$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 <i>no-reply@your-server.org</i>';
$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';

View File

@ -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
));
?>

View File

@ -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

View File

@ -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 '<h2>Reload monsters.</h2>';
echo '<h2>All records deleted from table \'myaac_monsters\' in database.</h2>';
$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."<br/>");
}
catch(PDOException $error) {
warning('Error while adding monster (' . $name . '): ' . $error->getMessage());
}
$names_added[] = $name;
}
}
require LIBS . 'creatures.php';
Creatures::loadFromXML(true);
}
if($canEdit)

View File

@ -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.
<?php
if(admin())
echo ' You can add new faq questions in phpmyadmin under <b>' . TABLE_PREFIX . 'faq</b> table.';
<?php
}
$last = $faqs->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);
}
}
?>

View File

@ -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 '<h2>Reload spells.</h2>';
echo '<h2>All records deleted from table <b>' . TABLE_PREFIX . 'spells</b> in database.</h2>';
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 "<h3>Conjure:</h3>";
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 . "<br>");
}
catch(PDOException $error) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
}
}
//add instant spells
$instantlist = $allspells->getInstantsList();
echo "<h3>Instant:</h3>";
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."<br/>");
}
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 '<option value="' . $id . '" ';
if($id == $vocation_id && $vocation_id != "All" && $vocation_id != '')
@ -228,7 +114,7 @@ if(isset($vocation_id) && $vocation_id != 'All' && $vocation_id != '')
else
echo '<TD>Instant</TD>';
echo '<TD>' . $spell['mana'] . '</TD><TD>' . $spell['level'] . '</TD><TD>' . $spell['maglevel'] . '</TD><TD>' . $spell['soul'] . '</TD><TD>' . ($spell ['premium'] == 1 ? 'yes' : 'no') . '</TD><TD>' . $config_vocations[$vocation_id] . '</TD></TR>';
echo '<TD>' . $spell['mana'] . '</TD><TD>' . $spell['level'] . '</TD><TD>' . $spell['maglevel'] . '</TD><TD>' . $spell['soul'] . '</TD><TD>' . ($spell ['premium'] == 1 ? 'yes' : 'no') . '</TD><TD>' . $config['vocations'][$vocation_id] . '</TD></TR>';
}
}
}
@ -249,8 +135,8 @@ else
$showed_vocations = 0;
foreach($spell_vocations as $spell_vocation)
{
if(isset($config_vocations[$spell_vocation])) {
echo $config_vocations[$spell_vocation];
if(isset($config['vocations'][$spell_vocation])) {
echo $config['vocations'][$spell_vocation];
$showed_vocations++;
}
if($showed_vocations != count($spell_vocations))

View File

@ -0,0 +1,26 @@
<form method="post" action="{{ link }}">
{% if action == 'edit' %}
<input type="hidden" name="id" value="{{ id }}" />
{% endif %}
<table width="100%" border="0" cellspacing="1" cellpadding="4">
<tr>
<td bgcolor="{{ config.vdarkborder }}" class="white"><b>{% if action == 'edit' %}Edit{% else %}Add{% endif %} FAQ</b></td>
</tr>
<tr>
<td bgcolor="{{ config.darkborder }}">
<table border="0" cellpadding="1">
<tr>
<td>Question:</td>
<td><input name="question" value="{% if question is not null %}{{ question }}{% endif %}" size="29" maxlength="29"/></td>
<tr>
<td>Answer:</td>
<td><textarea name="answer" maxlength="300" cols="50" rows="5">{% if answer is not null %}{{ answer }}{% endif %}</textarea></td>
<tr/>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit"/>
</tr>
</table>
</td>
</tr>
</table>
</form>

View File

@ -1,11 +1,16 @@
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr bgcolor="{{ config.vdarkborder }}">
<td class="white">
<tr class="white" bgcolor="{{ config.vdarkborder }}">
<td>
<b>FAQ</b>
</td>
<td align="right">
<a href="#" onclick="toggleAll(); return false;">Toggle all</a>
</td>
{% if canEdit %}
<td style="width: 300px">
Options
</td>
{% endif %}
</tr>
{% set i = 0 %}
{% for faq in faqs %}
@ -13,8 +18,32 @@
<tr bgcolor="{{ getStyle(i) }}">
<td colspan="2" style="cursor: pointer;" onclick="toggleVisibility('faq_{{ i }}'); return false;">
<b>{{ faq.question }}</b>
<div id="faq_{{ i }}" style="display: none;">{{ faq.answer }}</div>
</td>
{% if canEdit %}
<td>
<a href="?subtopic=faq&action=edit&id={{ faq.id }}" title="Edit">
<img src="images/edit.png"/>Edit
</a>
<a id="delete" href="?subtopic=faq&action=delete&id={{ faq.id }}" onclick="return confirm('Are you sure?');" title="Delete">
<img src="images/del.png"/>Delete
</a>
<a href="?subtopic=faq&action=hide&id={{ faq.id }}" title="{% if faq.hidden != 1 %}Hide{% else %}Show{% endif %}">
<img src="images/{% if faq.hidden != 1 %}success{% else %}error{% endif %}.png"/>{% if faq.hidden != 1 %}Hide{% else %}Show{% endif %}
</a>
{% if i != 1 %}
<a href="?subtopic=faq&action=moveup&id={{ faq.id }}" title="Move up">
<img src="images/icons/arrow_up.gif"/>Move up
</a>
{% endif %}
{% if i != last %}
<a href="?subtopic=faq&action=movedown&id={{ faq.id }}" title="Move down">
<img src="images/icons/arrow_down.gif"/>Move down
</a>
{% endif %}
</td>
{% endif %}
</tr>
{% endfor %}
</table>

View File

@ -0,0 +1,27 @@
<form action="{{ constant('BASE_URL') }}install/" method="post" autocomplete="off">
<input type="hidden" name="step" id="step" value="finish" />
<table>
{% if constant('USE_ACCOUNT_NAME') %}
{% set type = 'account' %}
{% else %}
{% set type = 'account_id' %}
{% endif %}
{% for value in [type, 'password'] %}
<tr>
<td>
<label for="vars_{{ value }}">
<span>{{ locale['step_admin_' ~ value] }}</span>
</label>
<br/>
<input type="text" name="vars[{{ value }}]" id="vars_{{ value }}"{% if session['var_' ~ value] is not null %} value="{{ session['var_' ~ value] }}"{% endif %}/>
</td>
<td>
<em>{{ locale['step_admin_' ~ value ~ '_desc']|raw }}</em>
</td>
</tr>
{% endfor %}
</table>
{{ buttons|raw }}
</form>

View File

@ -0,0 +1,37 @@
<form action="{{ constant('BASE_URL') }}install/" method="post" autocomplete="off">
<input type="hidden" name="step" id="step" value="database" />
<table>
{% for value in ['server_path', 'mail_admin', 'mail_address'] %}
<tr>
<td>
<label for="vars_{{ value }}">
<span>{{ locale['step_config_' ~ value] }}</span>
</label>
<br>
<input type="text" name="vars[{{ value }}]" id="vars_{{ value }}"{% if session['var_' ~ value] is not null %} value="{{ session['var_' ~ value] }}"{% endif %}/>
</td>
<td>
<em>{{ locale['step_config_' ~ value ~ '_desc'] }}</em>
</td>
</tr>
{% endfor %}
<tr>
<td>
<label for="vars_client">
<span>{{ locale.step_config_client }}</span>
</label>
<br>
<select name="vars[client]" id="vars_client">
{% for id, version in clients %}
<option value="{{ id }}">{{ version }}</option>
{% endfor %}
</select>
</td>
<td>
<em>{{ locale.step_config_client_desc }}</em>
</td>
</tr>
</table>
{{ buttons|raw }}
</form>

View File

@ -0,0 +1,6 @@
<form action="{{ constant('BASE_URL') }}install/" method="post">
<input type="hidden" name="step" id="step" value="requirements" />
<textarea rows="10" cols="80" readonly="1">{{ license }}</textarea>
{{ buttons|raw }}
</form>

View File

@ -0,0 +1,12 @@
<form action="{{ constant('BASE_URL') }}install/" method="post">
<input type="hidden" name="step" id="step" value="license" />
<div class="input"><p>{{ locale.step_welcome_desc }}</p>
<select name="lang">
{% for locale_ in locales %}
<option value="{{ locale_.id }}">{{ locale_.name }}</option>
{% endfor %}
</select>
</div>
{{ buttons|raw }}
</form>