Compare commits

..

10 Commits

Author SHA1 Message Date
slawkens
11a2275115 Update Hooks.php 2025-05-08 19:55:31 +02:00
slawkens
50f73ba56c New filter: HOOK_FILTER_ROUTES 2025-05-08 18:35:03 +02:00
slawkens
7dcdc4f743 triggerFilter -> pass by reference (faster x5) 2025-05-08 18:34:36 +02:00
slawkens
8697809bbe Merge branch 'develop' into feature/twig-hooks-filters 2025-04-27 07:41:26 +02:00
slawkens
9af676a59e Merge branch 'develop' into feature/twig-hooks-filters 2025-03-09 21:24:47 +01:00
slawkens
3aaf71b9b5 Merge branch 'develop' into feature/twig-hooks-filters 2025-01-09 16:35:36 +01:00
slawkens
28d61ee12f Merge branch 'develop' into feature/twig-hooks-filters 2024-07-14 05:58:32 +02:00
slawkens
592bfaea70 Merge branch 'develop' into feature/twig-hooks-filters 2024-07-10 00:05:59 +02:00
slawkens
b471b1567a Cleanup 2024-06-29 21:30:12 +02:00
slawkens
44fe03c6ea feat: Hooks filters 2024-06-29 15:53:02 +02:00
16 changed files with 60 additions and 122 deletions

View File

@@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '8.1', '8.2', '8.3', '8.4' ]
php-versions: [ '8.1', '8.2', '8.3' ]
ots: ['tfs-1.4', 'canary-3.1.2'] # TODO: add 'tfs-master' (actually doesn't work cause AAC doesn't support reading .env configuration)
name: Cypress (PHP ${{ matrix.php-versions }}, ${{ matrix.ots }})
steps:
@@ -146,7 +146,6 @@ jobs:
with:
name: cypress-screenshots-${{ matrix.php-versions }}-${{ matrix.ots }}
path: cypress/screenshots
if-no-files-found: ignore
- name: Upload Cypress Videos
uses: actions/upload-artifact@v4
@@ -154,7 +153,6 @@ jobs:
with:
name: cypress-videos-${{ matrix.php-versions }}-${{ matrix.ots }}
path: cypress/videos
if-no-files-found: ignore
- name: Upload PHP Logs
uses: actions/upload-artifact@v4

View File

@@ -1,6 +1,6 @@
# [MyAAC](https://my-aac.org)
MyAAC is a free and open-source Automatic Account Creator (AAC) for Open Tibia Servers written in PHP. It is a fork of the [Gesior](https://github.com/gesior/Gesior2012) project. It supports only MySQL databases.
MyAAC is a free and open-source Automatic Account Creator (AAC) written in PHP. It is a fork of the [Gesior](https://github.com/gesior/Gesior2012) project. It supports only MySQL databases.
Official website: https://my-aac.org

View File

@@ -168,7 +168,6 @@ if ($logged && admin()) {
'username' => USE_ACCOUNT_NAME ? $account_logged->getName() : $account_logged->getId()
]);
}
$title_full = (isset($title) ? $title . ' - ' : '') . $config['lua']['serverName'];
require $template_path . '/' . $template_index;

View File

@@ -54,13 +54,12 @@ if ($db->hasTable('players')) {
}
}
Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php');
Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php');
DataLoader::setLocale($locale);
DataLoader::load();
// add menus entries
require_once SYSTEM . 'migrations/17.php';
$up();
// update config.highscores_ids_hidden
require_once SYSTEM . 'migrations/20.php';
$up();

View File

@@ -74,3 +74,7 @@ function fieldExist($field, $table)
global $db;
return $db->hasColumn($table, $field);
}
function getCreatureImgPath($creature): string {
return getMonsterImgPath($creature);
}

View File

@@ -1578,6 +1578,22 @@ function right($str, $length) {
return substr($str, -$length);
}
function getMonsterImgPath($monster): string
{
$monster_path = setting('core.monsters_images_url');
$monster_gfx_name = trim(strtolower($monster)) . setting('core.monsters_images_extension');
if (!file_exists($monster_path . $monster_gfx_name)) {
$monster_gfx_name = str_replace(" ", "", $monster_gfx_name);
if (file_exists($monster_path . $monster_gfx_name)) {
return $monster_path . $monster_gfx_name;
} else {
return $monster_path . 'nophoto.png';
}
} else {
return $monster_path . $monster_gfx_name;
}
}
function between($x, $lim1, $lim2) {
if ($lim1 < $lim2) {
$lower = $lim1; $upper = $lim2;

View File

@@ -97,7 +97,7 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
*
* @param IOTS_GuildAction $invites Invites driver (don't pass it to clear driver).
*/
public function setInvitesDriver(?IOTS_GuildAction $invites = null)
public function setInvitesDriver(IOTS_GuildAction $invites = null)
{
$this->invites = $invites;
}
@@ -107,7 +107,7 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
*
* @param IOTS_GuildAction $requests Membership requests driver (don't pass it to clear driver).
*/
public function setRequestsDriver(?IOTS_GuildAction $requests = null)
public function setRequestsDriver(IOTS_GuildAction $requests = null)
{
$this->requests = $requests;
}

View File

@@ -60,7 +60,7 @@ class OTS_GuildRank extends OTS_Row_DAO implements IteratorAggregate, Countable
* @throws PDOException On PDO operation error.
* @throws E_OTS_NotLoaded If given <var>$guild</var> object is not loaded.
*/
public function find($name, ?OTS_Guild $guild = null)
public function find($name, OTS_Guild $guild = null)
{
$where = '';

View File

@@ -284,7 +284,7 @@ class OTS_Monster extends DOMDocument
*/
public function getLook()
{
$look = [];
$look = array();
$element = $this->documentElement->getElementsByTagName('look')->item(0);
@@ -292,30 +292,14 @@ class OTS_Monster extends DOMDocument
return $look;
}
if ($element->hasAttribute('typeex')) {
$look['typeEx'] = (int) $element->getAttribute('typeex');
}
if ($element->hasAttribute('type')) {
$look['type'] = (int) $element->getAttribute('type');
}
if ($element->hasAttribute('head')) {
$look['head'] = (int) $element->getAttribute('head');
}
if ($element->hasAttribute('body')) {
$look['body'] = (int) $element->getAttribute('body');
}
if ($element->hasAttribute('legs')) {
$look['legs'] = (int) $element->getAttribute('legs');
}
if ($element->hasAttribute('feet')) {
$look['feet'] = (int) $element->getAttribute('feet');
}
if ($element->hasAttribute('addons')) {
$look['addons'] = (int) $element->getAttribute('addons');
}
if ($element->hasAttribute('corpse')) {
$look['corpse'] = (int) $element->getAttribute('corpse');
}
$look['type'] = $element->getAttribute('type');
$look['typeex'] = $element->getAttribute('typeex');
$look['head'] = $element->getAttribute('head');
$look['body'] = $element->getAttribute('body');
$look['legs'] = $element->getAttribute('legs');
$look['feet'] = $element->getAttribute('feet');
$look['addons'] = $element->getAttribute('addons');
$look['corpse'] = $element->getAttribute('corpse');
return $look;
}

View File

@@ -2026,7 +2026,7 @@ class OTS_Player extends OTS_Row_DAO
* @param OTS_GuildRank|null Guild rank (null to clear assign).
* @throws E_OTS_NotLoaded If passed <var>$guildRank</var> parameter is not loaded.
*/
public function setRank(?OTS_GuildRank $guildRank = null)
public function setRank(OTS_GuildRank $guildRank = null)
{
if(isset($guildRank))
$this->setRankId($guildRank->getId(), $guildRank->getGuild()->getId());
@@ -2632,7 +2632,7 @@ class OTS_Player extends OTS_Row_DAO
* @throws E_OTS_NotLoaded If player is not loaded.
* @throws PDOException On PDO operation error.
*/
public function setSlot($slot, ?OTS_Item $item = null, $pid = 0)
public function setSlot($slot, OTS_Item $item = null, $pid = 0)
{
static $sid;
@@ -2776,7 +2776,7 @@ class OTS_Player extends OTS_Row_DAO
* @throws E_OTS_NotLoaded If player is not loaded.
* @throws PDOException On PDO operation error.
*/
public function setDepot($depot, ?OTS_Item $item = null, $pid = 0, $depot_id = 0)
public function setDepot($depot, OTS_Item $item = null, $pid = 0, $depot_id = 0)
{
static $sid;

View File

@@ -10,13 +10,8 @@ $up = function () use ($db) {
$db->exec(file_get_contents(__DIR__ . '/17-menu.sql'));
}
$themes = ['kathrine', 'tibiacom',];
foreach ($themes as $theme) {
$file = TEMPLATES . $theme . '/menus.php';
if (is_file($file)) {
Plugins::installMenus($theme, require $file);
}
}
Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php');
Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php');
};
$down = function () use ($db) {

View File

@@ -16,22 +16,18 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Monsters';
if (empty($_REQUEST['name'])) {
$preview = setting('core.monsters_images_preview');
// display list of monsters
$monsters = MyAAC\Cache::remember('monsters', 30 * 60, function () use ($preview) {
$monsters = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) {
$query->where('rewardboss', 1);
})->get()->toArray();
$preview = setting('core.monsters_images_preview');
$monsters = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) {
$query->where('rewardboss', 1);
})->get()->toArray();
if ($preview) {
foreach($monsters as &$monster) {
$monster['img_link'] = getMonsterImage($monster);
}
if ($preview) {
foreach($monsters as $key => &$monster)
{
$monster['img_link'] = getMonsterImgPath($monster['name']);
}
return $monsters;
});
}
$twig->display('monsters.html.twig', array(
'monsters' => $monsters,
@@ -49,7 +45,7 @@ if ($monsterModel && isset($monsterModel->name)) {
/** @var array $monster */
$monster = $monsterModel->toArray();
function sort_by_chance($a, $b): int
function sort_by_chance($a, $b)
{
if ($a['chance'] == $b['chance']) {
return 0;
@@ -59,7 +55,7 @@ if ($monsterModel && isset($monsterModel->name)) {
$title = $monster['name'] . " - Monsters";
$monster['img_link']= getMonsterImage($monster);
$monster['img_link']= getMonsterImgPath($monster_name);
$voices = json_decode($monster['voices'], true);
$summons = json_decode($monster['summons'], true);
@@ -93,39 +89,3 @@ if ($monsterModel && isset($monsterModel->name)) {
// back button
$twig->display('monsters.back_button.html.twig');
function getMonsterImage($monster): string
{
$outfit = json_decode($monster['look'], true);
if (!empty($outfit['typeEx'])) {
return setting('core.item_images_url') . $outfit['typeEx'] . setting('core.item_images_extension');
}
if (isset($outfit['type'])) {
$getValue = function ($val) use ($outfit) {
return (!empty($outfit[$val])
? '&' . $val . '=' . $outfit[$val] : '');
};
return setting('core.outfit_images_url') . '?id=' . $outfit['type'] . $getValue('addons') . $getValue('head') . $getValue('body') . $getValue('legs') . $getValue('feet');
}
return getMonsterImgPath($monster['name']);
}
function getMonsterImgPath($name): string
{
$monster_path = setting('core.monsters_images_url');
$monster_gfx_name = trim(strtolower($name)) . setting('core.monsters_images_extension');
if (!file_exists($monster_path . $monster_gfx_name)) {
$monster_gfx_name = str_replace(" ", "", $monster_gfx_name);
if (file_exists($monster_path . $monster_gfx_name)) {
return $monster_path . $monster_gfx_name;
} else {
return $monster_path . 'nophoto.png';
}
} else {
return $monster_path . $monster_gfx_name;
}
}

View File

@@ -317,11 +317,6 @@ $content .= ob_get_contents();
ob_end_clean();
$hooks->trigger(HOOK_AFTER_PAGE);
if (isset($_REQUEST['_page_only'])) {
echo $content;
die;
}
if(!isset($title)) {
$title = str_replace('index.php/', '', $page);
$title = ucfirst($title);

View File

@@ -1473,7 +1473,7 @@ Sent by MyAAC,<br/>
],
'status_timeout' => [
'name' => 'Status Timeout',
'type' => 'double',
'type' => 'number',
'min' => 0,
'max' => 10, // more than 10 seconds waiting makes no sense
'step' => 0.1,

View File

@@ -219,7 +219,7 @@ class Settings implements \ArrayAccess
if ($setting['type'] === 'boolean') {
$value = ($setting['default'] ? 'true' : 'false');
}
else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password', 'textarea'])) {
else if (in_array($setting['type'], ['text', 'number', 'email', 'password', 'textarea'])) {
$value = $setting['default'];
}
else if ($setting['type'] === 'options') {
@@ -245,11 +245,7 @@ class Settings implements \ArrayAccess
$checkbox($key, false, $value);
}
else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password'])) {
if (in_array($setting['type'], ['float', 'double'])) {
$setting['type'] = 'number';
}
else if (in_array($setting['type'], ['text', 'number', 'email', 'password'])) {
if ($setting['type'] === 'number') {
$min = (isset($setting['min']) ? ' min="' . $setting['min'] . '"' : '');
$max = (isset($setting['max']) ? ' max="' . $setting['max'] . '"' : '');
@@ -355,7 +351,7 @@ class Settings implements \ArrayAccess
if ($setting['type'] === 'boolean') {
echo ($setting['default'] ? 'Yes' : 'No');
}
else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password', 'textarea'])) {
else if (in_array($setting['type'], ['text', 'number', 'email', 'password', 'textarea'])) {
echo $setting['default'];
}
else if ($setting['type'] === 'options') {
@@ -502,12 +498,9 @@ class Settings implements \ArrayAccess
break;
case 'number':
$ret['value'] = (int)$ret['value'];
break;
case 'double':
case 'float':
$ret['value'] = (double)($ret['value']);
if (!isset($ret['step']) || (int)$ret['step'] == 1) {
$ret['value'] = (int)$ret['value'];
}
break;
default:

View File

@@ -136,11 +136,6 @@ if($forumSetting != '')
$twig->addGlobal('template_name', $template_name);
$twig->addGlobal('template_path', $template_path);
if($twig_loader) {
$viewsPath = BASE . $template_path . '/views';
if (is_dir($viewsPath)) {
$twig_loader->prependPath($viewsPath);
}
$twig_loader->prependPath(BASE . $template_path);
}