Compare commits

..

No commits in common. "b9d1865186ebc457f4d354c0c41f81f4cfceeeb0" and "f03651b83c203af54efe28496da39541128b5196" have entirely different histories.

16 changed files with 319 additions and 861 deletions

View File

@ -57,7 +57,7 @@
--color-deepblue: #000032; --color-deepblue: #000032;
--color-alliance: #f7941e; --color-alliance: #f7941e;
--color-background: var(--color-deepblue); --color-background: var(--color-deepblue);
--color-glass: color-mix(in lch, transparent 42%, var(--color-background)); --color-glass: color-mix(in lch, transparent 75%, var(--color-background));
} }
.p-auto { .p-auto {

View File

@ -9,7 +9,6 @@ use WoWPress\Database\CreateLogTable;
use WoWPress\Database\CreateNotificationTable; use WoWPress\Database\CreateNotificationTable;
use WoWPress\Database\CreateRaidTable; use WoWPress\Database\CreateRaidTable;
use WoWPress\Database\CreateSignupTable; use WoWPress\Database\CreateSignupTable;
use WoWPress\Database\CreateSKSHistoryTable;
use WoWPress\Database\CreateSKSTable; use WoWPress\Database\CreateSKSTable;
use WoWPress\Frontend\Widgets\Birthdays; use WoWPress\Frontend\Widgets\Birthdays;
use WoWPress\Frontend\Widgets\BossKills; use WoWPress\Frontend\Widgets\BossKills;
@ -168,8 +167,6 @@ if (!function_exists('wowpress_database')) :
CreateNotificationTable::sql(), CreateNotificationTable::sql(),
CreateCharListsTable::sql(), CreateCharListsTable::sql(),
CreateCharListItemTable::sql(), CreateCharListItemTable::sql(),
CreateSKSHistoryTable::sql(),
]); ]);
} }

View File

@ -5,7 +5,6 @@ use WoWPress\Models\CharacterList;
use WoWPress\Models\Log; use WoWPress\Models\Log;
use WoWPress\Models\Raid; use WoWPress\Models\Raid;
use WoWPress\Models\SKS; use WoWPress\Models\SKS;
use WoWPress\Models\SKSHistory;
use WoWPress\Models\User; use WoWPress\Models\User;
add_filter('generate_rewrite_rules', function ($wp_rewrite) { add_filter('generate_rewrite_rules', function ($wp_rewrite) {
@ -77,28 +76,39 @@ add_action('template_redirect', function () {
include plugin_dir_path(__FILE__) . '../pages/roster.php'; include plugin_dir_path(__FILE__) . '../pages/roster.php';
die; die;
break; break;
case 'import_sks':
isAllowed('wowpress_edit_site');
echo "<pre>";
foreach(SKS::getLists() as $list){
$list_there = SKSHistory::where('list_name',$list->list_name)->first();
if(empty($list_there)){
$export = $list->export();
$sks = SKSHistory::createList($list->list_name,$export);
$sks->save();
}
}
die;
break;
case 'sks': case 'sks':
isAllowed('wowpress_view_raids'); isAllowed('wowpress_view_raids');
$GLOBALS['wowpress']['page_title'] = "SKS-Liste"; $GLOBALS['wowpress']['page_title'] = "SKS-Liste";
$GLOBALS['wowpress']['liste'] = get_query_var('list_name', null); $GLOBALS['wowpress']['liste'] = get_query_var('list_name', null);
include plugin_dir_path(__FILE__) . '../pages/sks.php'; include plugin_dir_path(__FILE__) . '../pages/sks.php';
die; die;
break; break;
case 'logs': case 'logs':
# $cl = new CharacterList();
# $cl->list_name = "Strike-Liste TWW Season 1";
# $cl->border_color = "red";
# $cl->max_count = 6;
# $cl->notify = true;
# $cl->save();
#$cl = CharacterList::find(14);
#$char = Character::first();
#$char = Character::find(8);
#$cl->addItem($char,'Richtig Dumm','2024-09-26');
#dd($cl->characters);
#exit;
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
$GLOBALS['wowpress']['page_title'] = "Logs"; $GLOBALS['wowpress']['page_title'] = "Logs";
echo "<div style='display:flex;flex-direction:column;gap:2em;'>"; echo "<div style='display:flex;flex-direction:column;gap:2em;'>";

View File

@ -1,38 +0,0 @@
<?php
// Optionen-Seite erstellen
use WoWPress\Models\SKSHistory;
function wowpress_misc_options_page()
{
global $select_options, $radio_options;
if (! isset($_REQUEST['settings-updated']))
$_REQUEST['settings-updated'] = false; ?>
<div class="wrap">
<h2>Allgemeine Optionen für <?php bloginfo('name'); ?></h2>
<?php if (false !== $_REQUEST['settings-updated']) : ?>
<div class="updated fade">
<p><strong>Einstellungen gespeichert!</strong></p>
</div>
<?php endif; ?>
<h3>SKS-Liste neu Würfeln</h3>
<form method="post" action="/request" enctype="multipart/form-data">
<input type="hidden" name="action" value="rollSKS">
<?php wp_nonce_field('rollSKS', 'rollSKS_nonce'); ?>
<?php foreach (SKSHistory::groupBy('list_name')->get() as $list): ?>
<p class="submit"><input type="submit" name="list_name" class="button-primary" value="<?= $list->list_name ?>" /></p>
<?php endforeach; ?>
</form>
<h3>Neue SKS-Liste</h3>
<form method="post" action="/request" enctype="multipart/form-data">
<input type="hidden" name="action" value="createSKS">
<?php wp_nonce_field('createSKS', 'createSKS_nonce'); ?>
<input type="text" name="list_name" value="" placeholder="Listen-Name">
<p class="submit"><input type="submit" class="button-primary" value="Liste erstellen" /></p>
</form>
</div>
<?php }

View File

@ -2,7 +2,6 @@
require_once('api.php'); require_once('api.php');
require_once('style.php'); require_once('style.php');
require_once('misc.php');
add_action('admin_init', 'theme_options_init'); add_action('admin_init', 'theme_options_init');
add_action('admin_menu', 'theme_options_add_page'); add_action('admin_menu', 'theme_options_add_page');
@ -19,7 +18,6 @@ function theme_options_init()
{ {
register_setting('wowpress_options', 'wowpress_api', 'kb_validate_options'); register_setting('wowpress_options', 'wowpress_api', 'kb_validate_options');
register_setting('wowpress_options', 'wowpress_style', 'kb_validate_options'); register_setting('wowpress_options', 'wowpress_style', 'kb_validate_options');
register_setting('wowpress_options', 'wowpress_misc', 'kb_validate_options');
} }
@ -46,16 +44,6 @@ function theme_options_add_page()
'dashicons-format-image', 'dashicons-format-image',
26 26
); );
add_menu_page(
'Verschiedenes',
'Verschiedenes',
'wowpress_edit_site',
'wowpress_misc_options',
'wowpress_misc_options_page',
'dashicons-admin-customizer',
26
);
} }

View File

@ -10,7 +10,7 @@ use WoWPress\Models\User;
global $widget_area; global $widget_area;
set_sidebar_status('top', false); set_sidebar_status('top', false);
$characters = Character::orderBy('name')->get(); $characters = Character::orderBy('rank')->get();
get_header(); get_header();
?> ?>
@ -28,6 +28,7 @@ get_header();
<tr> <tr>
<td class="p-auto">Name</td> <td class="p-auto">Name</td>
<td class="p-auto hidden lg:table-cell">Klasse</td> <td class="p-auto hidden lg:table-cell">Klasse</td>
<td class="p-auto hidden lg:table-cell">Rang</td>
<td class="p-auto hidden lg:table-cell">Server</td> <td class="p-auto hidden lg:table-cell">Server</td>
<td class="p-auto hidden lg:table-cell">Gilde</td> <td class="p-auto hidden lg:table-cell">Gilde</td>
@ -58,21 +59,22 @@ get_header();
<?= translate_string($char->spec) ?></span> <?= translate_string($char->spec) ?></span>
</div> </div>
</td> </td>
<td class="p-auto hidden lg:table-cell"><?= $char->rank ?></td>
<td class="p-auto hidden lg:table-cell"><?= $char->realm ?></td> <td class="p-auto hidden lg:table-cell"><?= $char->realm ?></td>
<td class="p-auto hidden lg:table-cell"><?= $char->guild ?></td> <td class="p-auto hidden lg:table-cell"><?= $char->guild ?></td>
<?php if (current_user_can('wowpress_edit_characters')) : ?> <?php if (current_user_can('wowpress_edit_characters')) : ?>
<td class="p-auto hidden lg:table-cell"> <td class="p-auto hidden lg:table-cell">
<form action="/request" method="POST"> <form action="/request" method="POST">
<?php wp_nonce_field('toggleRaidchar', 'toggleRaidchar_nonce'); ?> <?php wp_nonce_field('toggleRaidchar', 'toggleRaidchar_nonce'); ?>
<input type="hidden" name="action" value="toggleRaidchar"> <input type="hidden" name="action" value="toggleRaidchar">
<input type="hidden" name="id" value="<?= $char->ID ?>"> <input type="hidden" name="id" value="<?= $char->ID ?>">
<?php if ($char->raidchar) : ?> <?php if ($char->raidchar) : ?>
<button type="submit" class="btn btn-<?= $char->color ?>"><?= Icon::get('o-check-circle') ?> Ja</button> <button type="submit" class="btn btn-<?=$char->color?>"><?=Icon::get('o-check-circle')?> Ja</button>
<?php else : ?> <?php else : ?>
<button type="submit" class="btn btn-gray"><?= Icon::get('o-no-symbol') ?> Nein</button> <button type="submit" class="btn btn-gray"><?=Icon::get('o-no-symbol')?> Nein</button>
<?php endif; ?> <?php endif; ?>
</form> </form>
</td> </td>
<td class="p-auto hidden lg:table-cell"> <td class="p-auto hidden lg:table-cell">

View File

@ -5,66 +5,52 @@ use Wenprise\Eloquent\Facades\DB;
use WoWPress\Frontend\Icon; use WoWPress\Frontend\Icon;
use WoWPress\Models\Log; use WoWPress\Models\Log;
use WoWPress\Models\SKS; use WoWPress\Models\SKS;
use WoWPress\Models\SKSHistory;
set_sidebar_status('top', false); set_sidebar_status('top', false);
get_header();
if (empty($GLOBALS['wowpress']['liste'])): $liste = $GLOBALS['wowpress']['liste'];
$listen = SKSHistory::groupBy('list_name')->get(); if (!empty($liste)) {
$liste = SKS::where('list_name', $liste)->first();
if (empty($liste->list_name)) {
$liste = SKS::first();
}
}
if (empty($liste->list_name)) {
$listen = SKS::getLists();
get_header();
?> ?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))"> <div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full"> <div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?> <?= $GLOBALS['wowpress']['page_title'] ?>n
</div> </div>
</div> </div>
<section id="primary"> <section id="primary">
<main id="main"> <main id="main">
<div class="bg-glass shadow p-auto flex flex-col gap-3"> <div class="bg-glass shadow p-auto">
<?php foreach ($listen as $list) : ?> <?php foreach ($listen as $list) : ?>
<a class="btn btn-outline" href="/sks/<?= $list->list_name ?>"><?= $list->list_name ?></a> <a class="btn btn-outline" href="/sks/<?= $list->list_name ?>"><?= $list->list_name ?></a>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</main> </main>
</section> </section>
<?php else: <?php
$liste = SKSHistory::getLatestList($GLOBALS['wowpress']['liste']); } else {
get_header();
?> ?>
<div class="top-title flex flex-col gap-2" style="margin-top:calc(-1 * var(--wowp-gap))"> <div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full"> <div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
SKS-Liste "<?= $liste->list_name ?>" <?= $GLOBALS['wowpress']['page_title'] ?> "<?= $liste->list_name ?>"
</div> </div>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<div class="flex flex-row justify-center gap-2">
<?php
if ($prevList = $liste->getPreviousList()):
?>
<form action="/request" method="POST" class="hidden" id="undoSKS">
<?php wp_nonce_field('undoSKS', 'undoSKS_nonce'); ?>
<input type="hidden" name="action" value="undoSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
</form>
<button type="submit" form="undoSKS" class="btn btn-outline btn-deepblue text-white hover:text-alliance">
Rückgängig (Stand vom <?= format_date($prevList->created_at, "dd.MM.yyyy HH:mm") ?>)
</button>
<?php endif;
if ($nextList = $liste->getNextList()):
?>
<form action="/request" method="POST" class="hidden" id="redoSKS">
<?php wp_nonce_field('redoSKS', 'redoSKS_nonce'); ?>
<input type="hidden" name="action" value="redoSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
</form>
<button type="submit" form="redoSKS" class="btn btn-outline btn-deepblue text-white hover:text-alliance">
Wiederherstellen (Stand vom <?= format_date($nextList->created_at, "dd.MM.yyyy HH:mm") ?>)
</button>
<?php endif; ?>
</div>
<? endif; ?>
</div> </div>
<section id="primary"> <section id="primary">
<main id="main"> <main id="main">
<div class="bg-glass shadow p-auto flex flex-col gap-2"> <div class="bg-glass shadow p-auto">
<table class="table-auto w-full"> <table class="table-auto w-full">
<thead> <thead>
<tr class="bg-glass"> <tr class="bg-glass">
@ -78,73 +64,83 @@ if (empty($GLOBALS['wowpress']['liste'])):
<?php endif; ?> <?php endif; ?>
</tr> </tr>
</thead> </thead>
<?php foreach ($liste->list_array as $list_item) : <tbody class="bg-black">
switch ($list_item['rank']) { <?php
case 1: foreach (SKS::getList($liste->list_name) as $sk) :
$rank_color = "text-[#bfac1d]"; ?>
break; <tr class="text-<?= $sk->active ? $sk->character->color : "slate-500" ?> odd:bg-slate-900">
case 2: <?php if (current_user_can('wowpress_edit_raids')) : ?>
$rank_color = "text-[#9c9b9a]"; <td class="p-auto text-center">
break; <form action="/request" method="POST">
case 3: <div class="flex flex-row">
$rank_color = "text-[#9e4f00]";
break;
default:
$rank_color = "text-white";
}
$char = $liste->getCharData($list_item['char']);
?>
<tr class="text-<?= $list_item['active'] ? $char->color : "slate-500" ?> odd:bg-slate-900"> <input type="text" class="bg-glass w-full text-center border-0 border-b border-<?= $sk->character->color ?>" name="rank" value="<?= $sk->rank ?>">
<button class="btn btn-outline btn-alliance" title="Manueller Eingriff">
<?= Icon::get('o-wrench') ?>
</button>
<td class="p-auto text-center <?= $rank_color ?>"><?= $list_item['rank'] ?></td> <?php wp_nonce_field('fixSKS', 'fixSKS_nonce'); ?>
<td class="p-auto text-center" style="font-size:1.3em"><?= $char->name ?></td> <input type="hidden" name="action" value="fixSKS">
<td class="p-auto text-center hidden lg:table-cell" style="font-size:1.3em"><?= $char->realm ?></td> <input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<?php if (current_user_can('wowpress_edit_raids')) : ?> </div>
<td class="p-auto text-center hidden lg:table-cell">
<form action="/request" method="POST">
<?php wp_nonce_field('toggleSKS', 'toggleSKS_nonce'); ?>
<input type="hidden" name="action" value="toggleSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="rank" value="<?= $list_item['rank'] ?>">
<button type="submit" class="btn w-full btn-outline btn-<?= $list_item['active'] ? $char->color : "slate" ?>"><?= $list_item['active'] ? "Aktiv" : "Inaktiv" ?></button>
</form>
</td>
<td class="p-auto">
<div class="flex gap-2 flex-col lg:flex-row justify-end">
<?php if ($list_item['active']) : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('lootSKS', 'lootSKS_nonce'); ?>
<input type="hidden" name="action" value="lootSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="char" value="<?= $list_item['char'] ?>">
<button type="submit" title="Looten" class="btn btn-outline btn-<?= $char->color ?>"><?= Icon::get('o-sparkles') ?></button>
</form>
<?php else : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('deleteSKS', 'deleteSKS_nonce'); ?>
<input type="hidden" name="action" value="deleteSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="char" value="<?= $list_item['char'] ?>">
<button type="submit" title="Löschen" class="btn btn-outline btn-red"><?= Icon::get('o-trash') ?></button>
</form>
<? endif; ?>
</div> </form>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?> </td>
</table> <?php else : ?>
<td class="p-auto text-center"><?= $sk->rank ?></td>
<?php endif; ?>
<td class="p-auto text-center" style="font-size:1.3em"><?= $sk->character->name ?></td>
<td class="p-auto text-center hidden lg:table-cell" style="font-size:1.3em"><?= $sk->character->realm ?></td>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center hidden lg:table-cell">
<form action="/request" method="POST">
<?php wp_nonce_field('toggleSKS', 'toggleSKS_nonce'); ?>
<input type="hidden" name="action" value="toggleSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" class="btn w-full btn-outline btn-<?= $sk->active ? $sk->character->color : "slate" ?>"><?= $sk->active ? "Aktiv" : "Inaktiv" ?></button>
</form>
</td>
<td class="p-auto">
<div class="flex gap-2 flex-col lg:flex-row justify-end">
<?php if ($sk->active) : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('lootSKS', 'lootSKS_nonce'); ?>
<input type="hidden" name="action" value="lootSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" title="Looten" class="btn btn-outline btn-<?= $sk->character->color ?>"><?= Icon::get('o-sparkles') ?></button>
</form>
<?php else : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('deleteSKS', 'deleteSKS_nonce'); ?>
<input type="hidden" name="action" value="deleteSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" title="Löschen" class="btn btn-outline btn-red"><?= Icon::get('o-trash') ?></button>
</form>
<? endif; ?>
</div>
</td>
<?php endif; ?>
</tr>
</div> </div>
<?php
endforeach;
?>
</tbody>
</table>
</div>
</main> </main>
</section> </section>
<?php <?php
if (current_user_can('wowpress_edit_raids')) : ?> }
if (current_user_can('wowpress_edit_raids')) : ?>
<div x-data> <div x-data>
<template x-teleport="#sidebar_right"> <template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1"> <div class="bg-glass shadow p-auto order-1">
@ -153,20 +149,38 @@ if (empty($GLOBALS['wowpress']['liste'])):
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<?php wp_nonce_field('addSKS', 'addSKS_nonce'); ?> <?php wp_nonce_field('addSKS', 'addSKS_nonce'); ?>
<input type="hidden" name="action" value="addSKS"> <input type="hidden" name="action" value="addSKS">
<input type="hidden" name="list_name" value="<?=$liste->list_name?>">
<input type="text" name="name" placeholder="Name" class="text-black"> <input type="text" name="name" placeholder="Name" class="text-black">
<input type="text" name="realm" placeholder="Server" class="text-black"> <input type="text" name="realm" placeholder="Server" class="text-black">
<input type="text" name="list_name" placeholder="Listenname" value="<?= !empty($liste->list_name) ? $liste->list_name : "" ?>" class="text-black">
<button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a> <button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a>
</div> </div>
</form> </form>
</div> </div>
</template> </template>
<?php if (!empty($liste->list_name)) : ?>
<template x-teleport="#sidebar_right">
<!--div class="bg-glass shadow p-auto order-1">
<h4 class="text-xl font-bold text-center mb-2">Liste neu Würfeln</h4>
<form action="/request" method="POST">
<div class="flex flex-col gap-2">
<?php wp_nonce_field('rollSKS', 'rollSKS_nonce'); ?>
<input type="hidden" name="action" value="rollSKS">
<input type="hidden" name="list_name" value="<?= $liste->list_name ?>">
<button type="submit" class="btn btn-outline btn-orange"><?= Icon::get('o-arrow-path') ?> Würfeln</a>
</div>
</form>
</div-->
</template>
<?php endif; ?>
</div> </div>
<?php <?php
endif; endif;
endif;
get_footer(); get_footer();
?>

View File

@ -1,186 +0,0 @@
<?php
use Wenprise\Eloquent\Database;
use Wenprise\Eloquent\Facades\DB;
use WoWPress\Frontend\Icon;
use WoWPress\Models\Log;
use WoWPress\Models\SKS;
set_sidebar_status('top', false);
$liste = $GLOBALS['wowpress']['liste'];
if (!empty($liste)) {
$liste = SKS::where('list_name', $liste)->first();
if (empty($liste->list_name)) {
$liste = SKS::first();
}
}
if (empty($liste->list_name)) {
$listen = SKS::getLists();
get_header();
?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?>n
</div>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto">
<?php foreach ($listen as $list) : ?>
<a class="btn btn-outline" href="/sks/<?= $list->list_name ?>"><?= $list->list_name ?></a>
<?php endforeach; ?>
</div>
</main>
</section>
<?php
} else {
get_header();
?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?> "<?= $liste->list_name ?>"
</div>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto">
<table class="table-auto w-full">
<thead>
<tr class="bg-glass">
<th class="p-auto w-40">Rang</th>
<th class="p-auto">Charakter</th>
<th class="p-auto hidden lg:table-cell">Server</th>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<th class="p-auto hidden lg:table-cell">Status</th>
<th class="p-auto w-0">Aktion</th>
<?php endif; ?>
</tr>
</thead>
<tbody class="bg-black">
<?php
foreach (SKS::getList($liste->list_name) as $sk) :
?>
<tr class="text-<?= $sk->active ? $sk->character->color : "slate-500" ?> odd:bg-slate-900">
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center">
<form action="/request" method="POST">
<div class="flex flex-row">
<input type="text" class="bg-glass w-full text-center border-0 border-b border-<?= $sk->character->color ?>" name="rank" value="<?= $sk->rank ?>">
<button class="btn btn-outline btn-alliance" title="Manueller Eingriff">
<?= Icon::get('o-wrench') ?>
</button>
<?php wp_nonce_field('fixSKS', 'fixSKS_nonce'); ?>
<input type="hidden" name="action" value="fixSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
</div>
</form>
</td>
<?php else : ?>
<td class="p-auto text-center"><?= $sk->rank ?></td>
<?php endif; ?>
<td class="p-auto text-center" style="font-size:1.3em"><?= $sk->character->name ?></td>
<td class="p-auto text-center hidden lg:table-cell" style="font-size:1.3em"><?= $sk->character->realm ?></td>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center hidden lg:table-cell">
<form action="/request" method="POST">
<?php wp_nonce_field('toggleSKS', 'toggleSKS_nonce'); ?>
<input type="hidden" name="action" value="toggleSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" class="btn w-full btn-outline btn-<?= $sk->active ? $sk->character->color : "slate" ?>"><?= $sk->active ? "Aktiv" : "Inaktiv" ?></button>
</form>
</td>
<td class="p-auto">
<div class="flex gap-2 flex-col lg:flex-row justify-end">
<?php if ($sk->active) : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('lootSKS', 'lootSKS_nonce'); ?>
<input type="hidden" name="action" value="lootSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" title="Looten" class="btn btn-outline btn-<?= $sk->character->color ?>"><?= Icon::get('o-sparkles') ?></button>
</form>
<?php else : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('deleteSKS', 'deleteSKS_nonce'); ?>
<input type="hidden" name="action" value="deleteSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" title="Löschen" class="btn btn-outline btn-red"><?= Icon::get('o-trash') ?></button>
</form>
<? endif; ?>
</div>
</td>
<?php endif; ?>
</tr>
</div>
<?php
endforeach;
?>
</tbody>
</table>
</div>
</main>
</section>
<?php
}
if (current_user_can('wowpress_edit_raids')) : ?>
<div x-data>
<template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1">
<h4 class="text-xl font-bold text-center mb-2">Charakter Hinzufügen</h4>
<form action="/request" method="POST">
<div class="flex flex-col gap-2">
<?php wp_nonce_field('addSKS', 'addSKS_nonce'); ?>
<input type="hidden" name="action" value="addSKS">
<input type="text" name="name" placeholder="Name" class="text-black">
<input type="text" name="realm" placeholder="Server" class="text-black">
<input type="text" name="list_name" placeholder="Listenname" value="<?= !empty($liste->list_name) ? $liste->list_name : "" ?>" class="text-black">
<button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a>
</div>
</form>
</div>
</template>
<?php if (!empty($liste->list_name)) : ?>
<template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1">
<h4 class="text-xl font-bold text-center mb-2">Liste neu Würfeln</h4>
<form action="/request" method="POST">
<div class="flex flex-col gap-2">
<?php wp_nonce_field('rollSKS', 'rollSKS_nonce'); ?>
<input type="hidden" name="action" value="rollSKS">
<input type="hidden" name="list_name" value="<?= $liste->list_name ?>">
<button type="submit" class="btn btn-outline btn-orange"><?= Icon::get('o-arrow-path') ?> Würfeln</a>
</div>
</form>
</div>
</template>
<?php endif; ?>
</div>
<?php
endif;
get_footer();
?>

View File

@ -14,7 +14,6 @@ use WoWPress\Models\Notification;
use WoWPress\Models\Raid; use WoWPress\Models\Raid;
use WoWPress\Models\Signup; use WoWPress\Models\Signup;
use WoWPress\Models\SKS; use WoWPress\Models\SKS;
use WoWPress\Models\SKSHistory;
use WoWPress\Models\User; use WoWPress\Models\User;
if (empty($_POST['action'])) { if (empty($_POST['action'])) {
@ -37,7 +36,6 @@ switch ($_POST['action']) {
$char = new Character(); $char = new Character();
$char->name = $_POST['name']; $char->name = $_POST['name'];
$char->realm = $_POST['realm']; $char->realm = $_POST['realm'];
$char->save();
$char->updateFromAPI(); $char->updateFromAPI();
$char->updateMedia(); $char->updateMedia();
} }
@ -153,37 +151,40 @@ switch ($_POST['action']) {
} }
} }
break; break;
case 'createSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['createSKS_nonce']) && wp_verify_nonce($_POST['createSKS_nonce'], 'createSKS')) {
if(isset($_POST['list_name'])){
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
break;
}
$list = new SKSHistory();
$list->list_name = $_POST['list_name'];
$list->active = true;
$list->fillWithRaiders();
$list->save();
}
}
break;
case 'addSKS': case 'addSKS':
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
if (isset($_POST['addSKS_nonce']) && wp_verify_nonce($_POST['addSKS_nonce'], 'addSKS')) { if (isset($_POST['addSKS_nonce']) && wp_verify_nonce($_POST['addSKS_nonce'], 'addSKS')) {
if (isset($_POST['name']) && isset($_POST['realm']) && isset($_POST['list_name'])) { if (isset($_POST['name']) && isset($_POST['realm']) && isset($_POST['list_name'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) { $char = Character::whereName($_POST['name'])->whereRealm($_POST['realm'])->first();
$list->addChar($_POST['name'],$_POST['realm']); if (empty($char->ID)) {
$char = new Character();
$char->name = $_POST['name'];
$char->realm = $_POST['realm'];
} }
$sks = new SKS();
$sks->char_name = $char->name;
$sks->realm_name = $char->realm;
$sks->list_name = $_POST['list_name'];
$sks->active = true;
$sks_last = SKS::where('list_name', $sks->list_name)->orderBy('rank', 'desc')->first();
$sks->rank = !empty($sks_last->rank) ? $sks_last->rank + 1 : 1;
$sks->save();
} }
} }
break; break;
case 'toggleSKS': case 'toggleSKS':
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
if (isset($_POST['toggleSKS_nonce']) && wp_verify_nonce($_POST['toggleSKS_nonce'], 'toggleSKS')) { if (isset($_POST['toggleSKS_nonce']) && wp_verify_nonce($_POST['toggleSKS_nonce'], 'toggleSKS')) {
if (isset($_POST['list_name']) && isset($_POST['rank'])) { if (isset($_POST['sks_id'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) { $sks = SKS::find($_POST['sks_id']);
$list->toggleActive($_POST['rank']); if ($sks->ID) {
$sks->active = !$sks->active;
$sks->save();
} }
} }
} }
@ -191,9 +192,16 @@ switch ($_POST['action']) {
case 'deleteSKS': case 'deleteSKS':
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
if (isset($_POST['deleteSKS_nonce']) && wp_verify_nonce($_POST['deleteSKS_nonce'], 'deleteSKS')) { if (isset($_POST['deleteSKS_nonce']) && wp_verify_nonce($_POST['deleteSKS_nonce'], 'deleteSKS')) {
if (isset($_POST['list_name']) && isset($_POST['char'])) { if (isset($_POST['sks_id'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) { $sks = SKS::find($_POST['sks_id']);
$list->removeChar($_POST['char']); if ($sks->ID) {
$after = $sks->getAfter(false);
foreach ($after as $sk) {
$sk->rank = $sk->rank - 1;
$sk->save();
}
$sks->delete();
} }
} }
} }
@ -201,29 +209,10 @@ switch ($_POST['action']) {
case 'lootSKS': case 'lootSKS':
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
if (isset($_POST['lootSKS_nonce']) && wp_verify_nonce($_POST['lootSKS_nonce'], 'lootSKS')) { if (isset($_POST['lootSKS_nonce']) && wp_verify_nonce($_POST['lootSKS_nonce'], 'lootSKS')) {
if (isset($_POST['list_name']) && isset($_POST['char'])) { if (isset($_POST['sks_id'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) { $sks = SKS::find($_POST['sks_id']);
$list->loot($_POST['char']); if ($sks->ID) {
} $sks->loot();
}
}
break;
case 'undoSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['undoSKS_nonce']) && wp_verify_nonce($_POST['undoSKS_nonce'], 'undoSKS')) {
if (isset($_POST['list_name'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->undo();
}
}
}
break;
case 'redoSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['redoSKS_nonce']) && wp_verify_nonce($_POST['redoSKS_nonce'], 'redoSKS')) {
if (isset($_POST['list_name'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->redo();
} }
} }
} }
@ -232,8 +221,22 @@ switch ($_POST['action']) {
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
if (isset($_POST['rollSKS_nonce']) && wp_verify_nonce($_POST['rollSKS_nonce'], 'rollSKS')) { if (isset($_POST['rollSKS_nonce']) && wp_verify_nonce($_POST['rollSKS_nonce'], 'rollSKS')) {
if (isset($_POST['list_name'])) { if (isset($_POST['list_name'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) { $sks = SKS::where('list_name', $_POST['list_name'])->first();
$list->shuffle(); if (!empty($sks->ID)) {
# $sks->roll();
}
}
}
break;
case 'fixSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['fixSKS_nonce']) && wp_verify_nonce($_POST['fixSKS_nonce'], 'fixSKS')) {
if (isset($_POST['sks_id']) && isset($_POST['rank'])) {
$sks = SKS::find($_POST['sks_id']);
if ($sks->ID) {
$sks->rank = intval($_POST['rank']);
$sks->save();
} }
} }
} }
@ -356,8 +359,8 @@ switch ($_POST['action']) {
} }
case 'addList': case 'addList':
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
if (checkNonce('addList')) { if(checkNonce('addList')){
if (isset($_POST['list_name'], $_POST['border_color'])) { if(isset($_POST['list_name'],$_POST['border_color'])){
$list = new CharacterList(); $list = new CharacterList();
$list->list_name = $_POST['list_name']; $list->list_name = $_POST['list_name'];
$list->border_color = $_POST['border_color']; $list->border_color = $_POST['border_color'];
@ -370,39 +373,40 @@ switch ($_POST['action']) {
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
if (isset($_POST['addCharToList_nonce']) && wp_verify_nonce($_POST['addCharToList_nonce'], 'addCharToList')) { if (isset($_POST['addCharToList_nonce']) && wp_verify_nonce($_POST['addCharToList_nonce'], 'addCharToList')) {
if (isset($_POST['character_ID']) && isset($_POST['list_id'])) { if(isset($_POST['character_ID']) && isset($_POST['list_id'])){
$list = CharacterList::find($_POST['list_id']); $list = CharacterList::find($_POST['list_id']);
$char = Character::find($_POST['character_ID']); $char = Character::find($_POST['character_ID']);
if ($char && $list) { if($char && $list){
$comment = ""; $comment = "";
$date = date('Y-m-d'); $date = date('Y-m-d');
if (!empty($_POST['comment'])) { if(!empty($_POST['comment'])){
$comment = $_POST['comment']; $comment = $_POST['comment'];
} }
if (!empty($_POST['date'])) { if(!empty($_POST['date'])){
$date = $_POST['date']; $date = $_POST['date'];
} }
$list->addItem($char, $comment, $date); $list->addItem($char,$comment,$date);
} }
} }
} }
break; break;
case 'removeListItem': case 'removeListItem':
isAllowed('wowpress_edit_raids'); isAllowed('wowpress_edit_raids');
if (checkNonce('removeListItem')) { if(checkNonce('removeListItem')){
if (isset($_POST['item_id'])) { if(isset($_POST['item_id'])){
$item_id = intval($_POST['item_id']); $item_id = intval($_POST['item_id']);
$item = CharacterListItem::find($item_id); $item = CharacterListItem::find($item_id);
if ($item) { if($item){
$item->delete(); $item->delete();
#CharacterListItem::deleteOrphans(); #CharacterListItem::deleteOrphans();
} }
} }
} }
break; break;
case 'cron': case 'cron':
if (isset($_POST['cron'])) { if(isset($_POST['cron'])){
switch ($_POST['cron']) { switch($_POST['cron']){
case 'update_applications': case 'update_applications':
break; break;

View File

@ -103,11 +103,7 @@ abstract class Api
$headers = array('Content-Type: application/json', 'Content-Length: ' . strlen($data_json)); $headers = array('Content-Type: application/json', 'Content-Length: ' . strlen($data_json));
$headers[] = 'Accept: application/json'; $headers[] = 'Accept: application/json';
if ($headerauth) { if ($headerauth) {
if (!is_bool($headerauth)) { $headers[] = 'Authorization: ' . $this->api_key;
$headers[] = 'Authorization: Bearer ' . $headerauth;
} else {
$headers[] = 'Authorization: ' . $this->api_key;
}
} }
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
@ -134,10 +130,10 @@ abstract class Api
$result = "{}"; $result = "{}";
if (!str_contains($url, "https:/")) { if (!str_contains($url, "https:/")) {
$url = $this->api_url . $url; $url = $this->api_url . $url;
} else { }else{
$parts = parse_url($url); $parts = parse_url($url);
parse_str($parts['query'], $query); parse_str($parts['query'], $query);
$parameter = array_merge($parameter, $query); $parameter = array_merge($parameter,$query);
$url = strtok($url, '?'); $url = strtok($url, '?');
} }
@ -150,44 +146,39 @@ abstract class Api
$cache = Cache::where('p_key', $cache_key)->get()->last(); $cache = Cache::where('p_key', $cache_key)->get()->last();
if (empty($cache->ID) || $cache->isExpired($expiration)) {
$ch = curl_init(); if(empty($cache->ID) || $cache->isExpired($expiration)){
if (!empty($parameter)) { $ch = curl_init();
$parameter = http_build_query($parameter); if (!empty($parameter)) {
curl_setopt($ch, CURLOPT_URL, $url . "?" . $parameter); $parameter = http_build_query($parameter);
} else { curl_setopt($ch, CURLOPT_URL, $url . "?" . $parameter);
curl_setopt($ch, CURLOPT_URL, $url); } else {
} curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); }
curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array(); $headers = array();
$headers[] = 'Accept: application/json'; $headers[] = 'Accept: application/json';
if ($headerauth) { if ($headerauth) {
if (!is_bool($headerauth)) { $headers[] = 'Authorization: ' . $this->api_key;
$headers[] = 'Authorization: Bearer ' . $headerauth; }
} else { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$headers[] = 'Authorization: ' . $this->api_key;
}
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch); $response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size); $header = substr($response, 0, $header_size);
$result = substr($response, $header_size); $result = substr($response, $header_size);
if (curl_errno($ch)) { if (curl_errno($ch)) {
error_log('Error:' . curl_error($ch)); error_log('Error:' . curl_error($ch));
return false; return false;
}
$cache = Cache::upsert($cache_key, $result);
$from_cache = false;
} }
$cache = Cache::upsert($cache_key, $result);
$from_cache = false;
}
if (!is_array($cache->value)) { if (!is_array($cache->value)) {
return ['error' => true]; return ['error' => true];

View File

@ -15,8 +15,8 @@ class BattleNet extends Api{
$data = $this->get("/profile/wow/character/$realm/$name", [ $data = $this->get("/profile/wow/character/$realm/$name", [
'namespace' => 'profile-eu', 'namespace' => 'profile-eu',
'locale' => 'en_US', 'locale' => 'en_US',
# 'access_token' => $this->bearer() 'access_token' => $this->bearer()
], $this->bearer(), $timeout); ], false, $timeout);
return $data; return $data;
} }
@ -35,13 +35,13 @@ class BattleNet extends Api{
$data = $this->get($guild, [ $data = $this->get($guild, [
'namespace' => 'profile-eu', 'namespace' => 'profile-eu',
'locale' => 'en_US', 'locale' => 'en_US',
#'access_token' => $this->bearer() 'access_token' => $this->bearer()
], $this->bearer(), -1); ], false, -1);
$data = $this->get($data['roster']['href'], [ $data = $this->get($data['roster']['href'], [
'namespace' => 'profile-eu', 'namespace' => 'profile-eu',
'locale' => 'en_US', 'locale' => 'en_US',
#'access_token' => $this->bearer() 'access_token' => $this->bearer()
], $this->bearer(), -1); ], false, -1);
foreach($data['members'] as $member){ foreach($data['members'] as $member){
if($member['character']['name'] == $name && $member['character']['realm']['slug'] == $char['realm']['slug']){ if($member['character']['name'] == $name && $member['character']['realm']['slug'] == $char['realm']['slug']){
$guild = $char['guild']['name']; $guild = $char['guild']['name'];
@ -62,8 +62,8 @@ class BattleNet extends Api{
$data = $this->get("/profile/wow/character/$realm/$name/character-media", [ $data = $this->get("/profile/wow/character/$realm/$name/character-media", [
'namespace' => 'profile-eu', 'namespace' => 'profile-eu',
'locale' => 'en_US', 'locale' => 'en_US',
# 'access_token' => $this->bearer() 'access_token' => $this->bearer()
], $this->bearer(), $timeout); ], false, $timeout);
if(!empty($data['code']) && $data['code'] == 403){ if(!empty($data['code']) && $data['code'] == 403){
# var_dump($data); # var_dump($data);

View File

@ -1,18 +0,0 @@
<?php
namespace WoWPress\Database;
class CreateSKSHistoryTable extends CreateTable
{
public static $table_name = "sks_history";
public static $fields = [
'list_name' => 'text NOT NULL',
'list_json' => 'json NOT NULL',
'active' => 'boolean',
'created_at' => 'timestamp NOT NULL',
'updated_at' => 'timestamp NOT NULL',
];
}

View File

@ -19,29 +19,26 @@ class Character extends Model
{ {
parent::__construct($attrs); parent::__construct($attrs);
$options = get_option('wowpress_api'); $options = get_option('wowpress_api');
if (isset($options['bnet'])) { if(isset($options['bnet'])){
$key = get_option('wowpress_api')['bnet']['key']; $key = get_option('wowpress_api')['bnet']['key'];
$id = get_option('wowpress_api')['bnet']['id']; $id = get_option('wowpress_api')['bnet']['id'];
} else { }else{
return false; return false;
} }
$this->api = new BattleNet($id, $key); $this->api = new BattleNet($id,$key);
} }
public function lists() public function lists(){
{ return $this->belongsToMany(CharacterList::class,'wowpress_charlists_item','list_id','character_id')->withPivot('comment','date','id');
return $this->belongsToMany(CharacterList::class, 'wowpress_charlists_item', 'list_id', 'character_id')->withPivot('comment', 'date', 'id');
} }
public function user() public function user(){
{
return $this->belongsTo(User::class); return $this->belongsTo(User::class);
} }
public function getCanEditAttribute() public function getCanEditAttribute(){
{ if(empty($this->user->ID)){
if (empty($this->user->ID)) {
return current_user_can('wowpress_edit_raids'); return current_user_can('wowpress_edit_raids');
} }
return current_user_can('wowpress_edit_raids') || (get_current_user_id() == $this->user->ID); return current_user_can('wowpress_edit_raids') || (get_current_user_id() == $this->user->ID);
@ -49,7 +46,7 @@ class Character extends Model
public function sanitize($string, $delimiter_space = "") public function sanitize($string,$delimiter_space="")
{ {
$string = strtolower(str_replace(" ", $delimiter_space, $string)); $string = strtolower(str_replace(" ", $delimiter_space, $string));
$string = strtolower(str_replace("'", "", $string)); $string = strtolower(str_replace("'", "", $string));
@ -57,41 +54,29 @@ class Character extends Model
return $string; return $string;
} }
public function getRankAttribute($rank) public function getRankAttribute($rank){
{ switch($rank){
switch ($rank) { case 0: return "Gildenmeister";
case 0: break;
return "Gildenmeister"; case 1: return "Offizier";
break; break;
case 1: case 2: return "Offi-Twink";
return "Offizier"; break;
break; case 3: return "Raidlead";
case 2: break;
return "Offi-Twink"; case 4: return "Ehrenmitglied";
break; break;
case 3: case 5: return "Raider";
return "Raidlead"; break;
break; case 6: return "Raider-Twink";
case 4: break;
return "Ehrenmitglied"; case 7: return "F&F";
break; break;
case 5: case 8: return "Novize";
return "Raider"; break;
break; case 9: return "Sleeper";
case 6: break;
return "Raider-Twink"; default: return "Gast";
break;
case 7:
return "F&F";
break;
case 8:
return "Novize";
break;
case 9:
return "Sleeper";
break;
default:
return "Gast";
} }
} }
@ -106,8 +91,7 @@ class Character extends Model
return get_template_directory_uri() . "/icons/class/$classname/$classname.png"; return get_template_directory_uri() . "/icons/class/$classname/$classname.png";
} }
public static function classIconLink($class) public static function classIconLink($class){
{
$classname = (new self())->sanitize($class); $classname = (new self())->sanitize($class);
return get_template_directory_uri() . "/icons/class/$classname/$classname.png"; return get_template_directory_uri() . "/icons/class/$classname/$classname.png";
} }
@ -119,8 +103,7 @@ class Character extends Model
return get_template_directory_uri() . "/icons/class/$classname/$specname.png"; return get_template_directory_uri() . "/icons/class/$classname/$specname.png";
} }
public static function specIconLink($class, $spec) public static function specIconLink($class,$spec){
{
$classname = (new self())->sanitize($class); $classname = (new self())->sanitize($class);
$specname = (new self())->sanitize($spec); $specname = (new self())->sanitize($spec);
return get_template_directory_uri() . "/icons/class/$classname/$specname.png"; return get_template_directory_uri() . "/icons/class/$classname/$specname.png";
@ -128,63 +111,54 @@ class Character extends Model
public function updateFromAPI() public function updateFromAPI()
{ {
$realm = $this->sanitize($this->realm, "-"); $realm = $this->sanitize($this->realm,"-");
$char_from_api = $this->api->getCharacter($this->name, $realm); $char_from_api = $this->api->getCharacter($this->name,$realm);
if (!array_key_exists('character_class', $char_from_api)) { if(!array_key_exists('character_class',$char_from_api)){
return false; return false;
} }
$this->class = $char_from_api['character_class']['name']; $this->class = $char_from_api['character_class']['name'];
$this->spec = $char_from_api['active_spec']['name']; $this->spec = $char_from_api['active_spec']['name'];
$this->id_blizz = $char_from_api['id']; $this->id_blizz = $char_from_api['id'];
$guild_data = $this->api->getGuildRank($this->name, $realm); $guild_data = $this->api->getGuildRank($this->name,$realm);
if (!empty($guild_data['rank'])) { if(!empty($guild_data['rank'])){
$this->guild = $guild_data['guild']; $this->guild = $guild_data['guild'];
$this->rank = $guild_data['rank']; $this->rank = $guild_data['rank'];
} else { }else{
$this->rank = 99; $this->rank = 99;
} }
$this->save(); $this->save();
return $char_from_api; return $char_from_api;
} }
public function updateMedia($force = false) public function updateMedia($force = false){
{ if(empty($this->id_blizz)){
if (empty($this->id_blizz)) {
return false; return false;
} }
$character_dir = wp_upload_dir()['basedir'] . "/characters/" . $this->ID . "/"; $character_dir = wp_upload_dir()['basedir']."/characters/".$this->ID."/";
if (!is_dir($character_dir)) { if(!is_dir($character_dir)){
mkdir($character_dir, 0777, true); mkdir($character_dir,0777,true);
} }
$id = $this->id_blizz; $id = $this->id_blizz;
$mod = $id % 256; $mod = $id % 256;
$realm = $this->sanitize($this->realm, '-'); $realm = $this->sanitize($this->realm,'-');
$data = $this->api->getMedia($this->name, $this->realm, 0); $img_url = "https://render.worldofwarcraft.com/eu/character/$realm/$mod/$id-avatar.jpg";
if (key_exists("assets", $data)) { file_put_contents($character_dir."avatar.jpg",file_get_contents($img_url));
foreach ($data['assets'] as $asset) {
if ($asset['key'] == 'avatar') {
file_put_contents($character_dir . "avatar.jpg", file_get_contents($asset['value']));
return true;
}
}
}
} }
public function getAvatarAttribute() public function getAvatarAttribute(){
{ $character_dir = wp_upload_dir()['basedir']."/characters/".$this->ID."/avatar.jpg";
$character_dir = wp_upload_dir()['basedir'] . "/characters/" . $this->ID . "/avatar.jpg"; $character_dir_uri = wp_upload_dir()['baseurl']."/characters/".$this->ID."/avatar.jpg";
$character_dir_uri = wp_upload_dir()['baseurl'] . "/characters/" . $this->ID . "/avatar.jpg"; if(file_exists($character_dir)){
if (file_exists($character_dir)) {
return $character_dir_uri; return $character_dir_uri;
} else { }else{
return ""; return "";
} }
} }
public function getClassButtonAttribute() public function getClassButtonAttribute(){
{ require(get_template_directory()."/template-parts/components/class-button.php");
require(get_template_directory() . "/template-parts/components/class-button.php");
} }
} }

View File

@ -27,7 +27,7 @@ class Raid extends Model
{ {
parent::__construct($attrs); parent::__construct($attrs);
$options = get_option('wowpress_api'); $options = get_option('wowpress_api');
if (isset($options['wowaudit'])) { if (isset($options['bnet'])) {
$key = get_option('wowpress_api')['wowaudit']['key']; $key = get_option('wowpress_api')['wowaudit']['key'];
} else { } else {
return false; return false;

View File

@ -126,19 +126,5 @@ class SKS extends Model
} }
} }
public function export(){
$list = $this->getList($this->list_name);
foreach($list as &$list_item){
$list_item['char'] = $list_item['char_name']."-".$list_item['realm_name'];
unset($list_item['list_name']);
unset($list_item['char_name']);
unset($list_item['realm_name']);
unset($list_item['ID']);
}
$list->sort(fn($a,$b) => $a['rank'] - $b['rank']);
return json_encode($list);
}
} }

View File

@ -1,266 +0,0 @@
<?php
namespace WoWPress\Models;
use Illuminate\Support\Collection;
use Wenprise\Eloquent\Model;
use WoWPress\Api\BattleNet;
use WoWPress\Api\WoWAudit;
class SKSHistory extends Model
{
protected $table = "wowpress_sks_history";
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
public function getLatest()
{
return self::where('list_name', $this->list_name)->where('active', true)->latest('created_at')->first();
}
public static function getLatestList($list_name)
{
return static::where('list_name', $list_name)->where('active', true)->latest('created_at')->first();
}
private function setList($list_array)
{
$this->list_json = json_encode($list_array);
}
public static function createList(string $list_name, $list_json)
{
$sks = new static();
$sks->list_name = $list_name;
if (is_array($list_json)) {
$list_json = json_encode($list_json);
}
$sks->list_json = $list_json;
$sks->active = true;
$sks->fixOrder();
return $sks;
}
public function fillWithRaiders()
{
$options = get_option('wowpress_api');
if (isset($options['wowaudit'])) {
$key = get_option('wowpress_api')['wowaudit']['key'];
} else {
return false;
}
$api = new WoWAudit(null, $key);
$roster = $api->getRoster();
$list = [];
foreach ($roster as $id => $character) {
if (!empty($character['name'])) {
$list[] = [
'char' => $character['name'] . "-" . $character['realm'],
'rank' => $id + 1,
'active' => true,
];
}
}
$this->list_json = json_encode($list);
}
public function getListArrayAttribute()
{
return json_decode($this->list_json, true);
}
public function shuffle()
{
$ranks = range(1, count($this->list_array));
shuffle($ranks);
$list = $this->list_array;
foreach ($list as $id => &$list_item) {
$list_item['rank'] = array_pop($ranks);
}
$this->saveList($list);
}
private function getChar($char)
{
foreach ($this->list_array as $list_item) {
if ($list_item['char'] == $char) {
return $list_item;
}
}
return false;
}
private function sort($list)
{
usort($list, fn($a, $b) => $a['rank'] - $b['rank']);
return $list;
}
public function fixOrder()
{
$data = $this->list_array;
// Separate active and inactive items
$activeItems = [];
$inactiveItems = [];
foreach ($data as $item) {
if ($item["active"]) {
$activeItems[] = $item;
} else {
$inactiveItems[] = $item;
}
}
// Sort the active items by rank
usort($activeItems, function ($a, $b) {
return $a["rank"] - $b["rank"];
});
// Reassign ranks starting from 1 for active items
$rankCounter = 0;
foreach ($activeItems as $key => $item) {
$rankCounter += 1;
foreach ($inactiveItems as $inactive_item) {
if ($inactive_item['rank'] == $rankCounter) {
$rankCounter += 1;
}
}
$item["rank"] = $rankCounter;
$activeItems[$key] = $item;
}
// Merge active and inactive items back
$data = array_merge($inactiveItems, $activeItems);
$data = $this->sort($data);
$this->setList($data);
}
public function loot($char)
{
if ($looter = $this->getChar($char)) {
if ($looter['active']) {
$list = $this->list_array;
foreach ($list as $id => &$list_item) {
if ($list_item['rank'] == $looter['rank']) {
$list[$id]['rank'] = PHP_INT_MAX; //Ans Ende der Liste mit dem Looter
break;
}
}
return $this->saveList($list);
}
}
return false;
}
public function saveList($list_array)
{
$this->active = false;
$this->save();
$new = self::createList($this->list_name, $list_array);
$new->save();
return $new;
}
public function toggleActive($rank)
{
$list = $this->list_array;
foreach ($list as &$list_item) {
if ($rank == $list_item['rank']) {
$list_item['active'] = !$list_item['active'];
return $this->saveList($list);
}
}
return false;
}
public function getList()
{
return $this->list_array;
}
public function getCharData($char)
{
list($name, $realm) = explode("-", $char);
$character = Character::whereName($name)->whereRealm($realm)->first();
if (empty($character)) {
$character = new Character();
$character->name = $name;
$character->realm = $realm;
$character->class = "priest";
}
return $character;
}
public function getPreviousList()
{
return SKSHistory::where('list_name', $this->list_name)->whereNot('active')->where('created_at', '<', $this->created_at)->latest()->first();
}
public function getNextList()
{
return SKSHistory::where('list_name', $this->list_name)->whereNot('active')->where('created_at', '>', $this->created_at)->first();
}
public function undo()
{
$lastItem = $this->getPreviousList();
$lastItem->active = true;
$lastItem->save();
$this->active = false;
$this->save();
}
public function redo()
{
$nextItem = $this->getNextList();
$nextItem->active = true;
$nextItem->save();
$this->active = false;
$this->save();
}
public function removeChar($char, $realm = "")
{
if ($realm) {
$char = $char . "-" . $realm;
}
$list = $this->list_array;
foreach ($list as $id => $list_item) {
if (!$list_item['active'] && $list_item['char'] == $char) {
unset($list[$id]);
}
}
$this->saveList($list);
}
public function addChar($char, $realm = "")
{
if ($realm) {
$char = $char . "-" . $realm;
}
$list = $this->list_array;
foreach ($list as $list_item) {
if ($list_item['char'] == $char) {
return false;
}
}
$list[] = [
'rank' => PHP_INT_MAX,
'active' => true,
'char' => $char
];
$this->saveList($list);
}
}