Skip to content

Commit

Permalink
compatibility badges
Browse files Browse the repository at this point in the history
  • Loading branch information
tadhgboyle committed Mar 24, 2023
1 parent 7147e07 commit 21289a2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 28 deletions.
23 changes: 16 additions & 7 deletions core/classes/Events/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,28 @@ public static function executeEvent($event, array $params = []): ?array {
/**
* Get a list of events to display on the StaffCP webhooks page.
*
* @param bool $internal Whether to include internal events or not
* @return array List of all currently registered events
*/
public static function getEvents(bool $internal = false): array {
public static function getEvents(): array {
$return = [];

foreach (self::$_events as $name => $meta) {
if (!$meta['internal'] || $internal) {
if (is_callable($meta['description'])) {
$meta['description'] = $meta['description']();
}
$return[$name] = $meta['description'];
if ($meta['internal']) {
continue;
}

if (is_callable($meta['description'])) {
$description = $meta['description']();
} else {
$description = $meta['description'];
}

$class = $meta['class_name'];
$return[$name] = [
'description' => $description,
'supports_discord' => $class !== null && is_subclass_of($class, DiscordDispatchable::class),
'supports_normal' => $class !== null && is_subclass_of($class, HasWebhookParams::class),
];
}

return $return;
Expand Down
1 change: 1 addition & 0 deletions custom/languages/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"admin/details": "Details",
"admin/disable": "Disable",
"admin/disabled": "Disabled",
"admin/discord_hook": "Discord",
"admin/display_field_on_forum": "Display field on forum?",
"admin/download": "Download",
"admin/download_sitemap": "Download Sitemap",
Expand Down
25 changes: 17 additions & 8 deletions custom/panel_templates/Default/core/hooks_edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,27 @@
<div class="form-group">
<label for="link_location">{$HOOK_TYPE}</label>
<select class="form-control" id="hook_type" name="hook_type">
<option value="2" {if $HOOK_TYPE_VALUE eq 2} selected{/if}>Discord</option>
<option value="1" {if $HOOK_TYPE_VALUE eq 1} selected{/if}>{$NORMAL}</option>
<option value="2" {if $HOOK_TYPE_VALUE eq 2} selected{/if}>
{$DISCORD}
</option>
<option value="1" {if $HOOK_TYPE_VALUE eq 1} selected{/if}>
{$NORMAL}
</option>
</select>
</div>
<label for="InputName">{$HOOK_EVENTS}</label>
{foreach from=$ALL_EVENTS key=key item=item}
{foreach from=$ALL_EVENTS key=key item=meta}
<div class="form-group custom-control custom-switch">
<input type="checkbox" id="inputevents[{$key|escape}]" name="events[{$key|escape}]"
class="custom-control-input" value="1" {if in_array($key|escape,
$ENABLED_HOOKS)} checked{/if}>
<input type="checkbox" id="inputevents[{$key|escape}]" name="events[{$key|escape}]" class="custom-control-input" value="1" {if in_array($key|escape, $ENABLED_HOOKS)} checked{/if}>
<label class="custom-control-label" for="inputevents[{$key|escape}]">
{$item|escape}
{$meta.description|escape}
{if $meta.supports_discord}
<span class="badge badge-info">Supports Discord</span>
{/if}
{if $meta.supports_normal}
<span class="badge badge-info">Supports Normal</span>
{/if}

</label>
</div>
{/foreach}
Expand Down Expand Up @@ -109,4 +118,4 @@

</body>

</html>
</html>
25 changes: 15 additions & 10 deletions custom/panel_templates/Default/core/hooks_new.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,24 @@
<div class="form-group">
<label for="link_location">{$HOOK_TYPE}</label>
<select class="form-control" id="hook_type" name="hook_type">
<option value="2">Discord</option>
<option value="2">{$DISCORD}</option>
<option value="1">{$NORMAL}</option>
</select>
</div>
<label for="InputName">{$HOOK_EVENTS}</label>
{foreach from=$ALL_EVENTS key=key item=item}
<div class="form-group custom-control custom-switch">
<input type="checkbox" id="inputevents[{$key|escape}]" name="events[{$key|escape}]"
class="custom-control-input">
<label class="custom-control-label" for="inputevents[{$key|escape}]">
{$item|escape}
</label>
</div>
{foreach from=$ALL_EVENTS key=key item=meta}
<div class="form-group custom-control custom-switch">
<input type="checkbox" id="inputevents[{$key|escape}]" name="events[{$key|escape}]" class="custom-control-input">
<label class="custom-control-label" for="inputevents[{$key|escape}]">
{$meta.description|escape}
{if $meta.supports_discord}
<span class="badge badge-info">Supports Discord</span>
{/if}
{if $meta.supports_normal}
<span class="badge badge-info">Supports Normal</span>
{/if}
</label>
</div>
{/foreach}
<div class="form-group">
<input type="hidden" name="token" value="{$TOKEN}">
Expand Down Expand Up @@ -108,4 +113,4 @@

</body>

</html>
</html>
2 changes: 1 addition & 1 deletion modules/Core/classes/Events/AnnouncementCreatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function name(): string {
}

public static function description(): string {
return (new Language(ROOT_PATH . '/modules/Forum/language'))->get('forum', 'new_topic_hook_info');
return (new Language())->get('admin', 'announcement_hook_info');
}

public function toDiscordWebhook(): DiscordWebhookBuilder {
Expand Down
2 changes: 2 additions & 0 deletions modules/Core/pages/panel/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
'HOOK_EVENTS' => $language->get('admin', 'hook_events'),
'BACK' => $language->get('general', 'back'),
'BACK_LINK' => URL::build('/panel/core/hooks'),
'DISCORD' => $language->get('admin', 'discord_hook'),
'NORMAL' => $language->get('general', 'normal'),
'ALL_EVENTS' => EventHandler::getEvents(),
]);
Expand Down Expand Up @@ -200,6 +201,7 @@
'HOOK_EVENTS' => $language->get('admin', 'hook_events'),
'BACK' => $language->get('general', 'back'),
'BACK_LINK' => URL::build('/panel/core/hooks'),
'DISCORD' => $language->get('admin', 'discord_hook'),
'NORMAL' => $language->get('general', 'normal'),
'ALL_EVENTS' => EventHandler::getEvents(),
'ENABLED_HOOKS' => json_decode($hook->events, true)
Expand Down
8 changes: 6 additions & 2 deletions modules/Forum/classes/Events/TopicCreatedEvent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class TopicCreatedEvent extends AbstractEvent implements DiscordDispatchable {
class TopicCreatedEvent extends AbstractEvent implements DiscordDispatchable, HasWebhookParams {

public User $creator;
public string $forum_title;
Expand Down Expand Up @@ -30,7 +30,7 @@ public static function name(): string {
}

public static function description(): string {
return (new Language())->get('admin', 'announcement_hook_info');
return (new Language(ROOT_PATH . '/modules/Forum/language'))->get('forum', 'new_topic');
}

public function toDiscordWebhook(): DiscordWebhookBuilder {
Expand All @@ -51,4 +51,8 @@ public function toDiscordWebhook(): DiscordWebhookBuilder {
->setUrl(URL::getSelfURL() . ltrim(URL::build('/forum/topic/' . urlencode($this->topic_id) . '-' . $forum->titleToURL($this->topic_title)), '/'));
});
}

public function webhookParams(): array {
return [];
}
}

0 comments on commit 21289a2

Please sign in to comment.