Skip to content

Commit

Permalink
new features added
Browse files Browse the repository at this point in the history
  • Loading branch information
sametgirginer committed Aug 4, 2022
1 parent cb09067 commit 9ea57ea
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 51 deletions.
12 changes: 11 additions & 1 deletion Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ public static function threadPostSave(Entity $entity)

public static function templaterMacroPreRender(Templater $templater, &$type, &$template, &$name, array &$arguments, array &$globalVars)
{
$thread_id = ($globalVars['thread']) ? $globalVars['thread']->thread_id : null;
$thread_id = null;
$msc_title = false;

if ($name === "thread_list") {
$thread_id = ($globalVars['thread']) ? $globalVars['thread']->thread_id : null;
} else if ($name === "thread_view") {
$thread_id = ($globalVars['constraint']['c']['thread'] && !$globalVars['thread']) ? $globalVars['constraint']['c']['thread'] : null;
$msc_title = true;
}

if ($thread_id === null) return;

$db = \XF::Db();
Expand All @@ -68,6 +77,7 @@ public static function templaterMacroPreRender(Templater $templater, &$type, &$t
'msc_status' => $status,
'msc_online' => $server['online'],
'msc_max' => $server['max'],
'msc_title' => $msc_title,
]);
}
}
3 changes: 2 additions & 1 deletion _data/code_event_listeners.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<code_event_listeners>
<listener event_id="entity_post_save" execute_order="10" callback_class="MinecraftServerChecker\Listener" callback_method="threadPostSave" active="1" hint="XF\Entity\Thread" description="The event code will run when the custom thread field is saved."/>
<listener event_id="templater_macro_pre_render" execute_order="10" callback_class="MinecraftServerChecker\Listener" callback_method="templaterMacroPreRender" active="1" hint="public:msc_server_info:item" description="Macro variables"/>
<listener event_id="templater_macro_pre_render" execute_order="10" callback_class="MinecraftServerChecker\Listener" callback_method="templaterMacroPreRender" active="1" hint="public:msc_server_info:thread_list" description="Thread list event listener"/>
<listener event_id="templater_macro_pre_render" execute_order="10" callback_class="MinecraftServerChecker\Listener" callback_method="templaterMacroPreRender" active="1" hint="public:msc_server_info:thread_view" description="Thread view event listener"/>
</code_event_listeners>
55 changes: 25 additions & 30 deletions _data/template_modifications.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<template_modifications>
<modification type="public" template="PAGE_CONTAINER" modification_key="msc_thread_title" description="Adds server information to the thread title." execution_order="10" enabled="1" action="str_replace">
<find><![CDATA[<h1 class="p-title-value">]]></find>
<replace><![CDATA[$0
<xf:macro name="{{ $templateOverrides.msc_server_info ?: 'msc_server_info::thread_view' }}" />]]></replace>
</modification>
<modification type="public" template="core.less" modification_key="msc_structured_list" description="Adds style support for Minecraft Server information." execution_order="10" enabled="1" action="str_replace">
<find><![CDATA[{{ include('core_bbcode.less') }}]]></find>
<replace><![CDATA[$0
{{ include('msc.less') }}]]></replace>
</modification>
<modification type="public" template="forum_view" modification_key="msc_copy_js" description="Adds copy clipboard button for server ip address." execution_order="10" enabled="1" action="str_replace">
<find><![CDATA[<xf:extension name="thread_list">]]></find>
<replace><![CDATA[$0
Expand All @@ -18,40 +28,25 @@ function msc_copy_ip(ip) {
}
</script>]]></replace>
</modification>
<modification type="public" template="structured_list.less" modification_key="msc_structured_list" description="Adds style support for Minecraft Server information." execution_order="10" enabled="1" action="str_replace">
<find><![CDATA[.structItem-title
{]]></find>
<modification type="public" template="thread_list_macros" modification_key="msc_item_new_posts" description="Adds server information to the thread list for widgets." execution_order="10" enabled="1" action="str_replace">
<find><![CDATA[ <xf:if is="$thread.isUnread()">
<a href="{{ link('threads/unread', $thread) }}">{{ prefix('thread', $thread) }}{$thread.title}</a>
<xf:else />
<a href="{{ link('threads/post', $thread, {'post_id': $thread.last_post_id}) }}">{{ prefix('thread', $thread) }}{$thread.title}</a>
</xf:if>]]></find>
<replace><![CDATA[$0
.msc-status {
color: #efefef;
border-color: transparent;
border-radius: 5px;
}
.msc-online {
background: #249a24;
}
.msc-offline {
background: #9a2424;
}
.msc-copyip {
color: #185886;
border-color: #e5e5e5;
}
.msc-copyip:hover {
cursor: pointer;
}
.msc-ip {
display: none;
}]]></replace>
<br>
<xf:macro name="{{ $templateOverrides.msc_server_info ?: 'msc_server_info::thread_list' }}" />]]></replace>
</modification>
<modification type="public" template="thread_list_macros" modification_key="msc_item_new_threads" description="Adds server information to the thread list for widgets." execution_order="10" enabled="1" action="str_replace">
<find><![CDATA[<a href="{{ link('threads', $thread) }}">{{ prefix('thread', $thread) }}{$thread.title}</a>]]></find>
<replace><![CDATA[$0
<br>
<xf:macro name="{{ $templateOverrides.msc_server_info ?: 'msc_server_info::thread_list' }}" />]]></replace>
</modification>
<modification type="public" template="thread_list_macros" modification_key="msc_server_info_block" description="Adds server information to the thread list." execution_order="10" enabled="1" action="str_replace">
<find><![CDATA[<div class="structItem-title">]]></find>
<replace><![CDATA[$0
<xf:macro name="{{ $templateOverrides.msc_server_info ?: 'msc_server_info::item' }}" />]]></replace>
<xf:macro name="{{ $templateOverrides.msc_server_info ?: 'msc_server_info::thread_list' }}" />]]></replace>
</modification>
</template_modifications>
54 changes: 52 additions & 2 deletions _data/templates.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<templates>
<template type="public" title="msc_server_info" version_id="1000" version_string="1.0.0"><![CDATA[<xf:macro name="item" arg-thread="{$thread}">
<template type="public" title="msc.less" version_id="1020" version_string="1.0.2"><![CDATA[.msc-status {
color: #efefef;
border-color: transparent;
border-radius: 5px;
}
.msc-online {
background: #249a24;
}
.msc-offline {
background: #9a2424;
}
.msc-copyip {
color: #185886;
border-color: #e5e5e5;
}
.msc-copyip:hover {
cursor: pointer;
}
.msc-ip {
display: none;
}
.p-title-value .msc-status {
padding-right: 5px;
}]]></template>
<template type="public" title="msc_server_info" version_id="1020" version_string="1.0.2"><![CDATA[<xf:macro name="thread_list" arg-thread="{$thread}">
<xf:if is="$thread.custom_fields.msc_server_ip">
<span class="label msc-status msc-{$msc_status}">
<xf:if is="$msc_online">
<xf:if is="{$msc_status} === 'online'">
<span data-xf-init="tooltip" data-original-title="{{ phrase('msc_online_players') }}">{$msc_online}</span>/<span data-xf-init="tooltip" data-original-title="{{ phrase('msc_max_players') }}">{$msc_max}</span>
<xf:else />
<span>{{ phrase('msc_offline_server') }}</span>
</xf:if>
</span>
<a class="labelLink" onclick="msc_copy_ip('{$msc_ip}')"
data-xf-init="tooltip" data-original-title="{{ phrase('msc_copy_ip_address') }}" >
<span class="label msc-copyip"><i class="fas fa-copy"></i></span>
<span id="mscip-{$msc_ip}" class="msc-ip">{$msc_ip}</span>
</a>
</xf:if>
</xf:macro>
<xf:macro name="thread_view">
<xf:if is="$msc_title">
<span class="label msc-status msc-{$msc_status}">
<xf:if is="{$msc_status} === 'online'">
<span data-xf-init="tooltip" data-original-title="{{ phrase('msc_online_players') }}">{$msc_online}</span>/<span data-xf-init="tooltip" data-original-title="{{ phrase('msc_max_players') }}">{$msc_max}</span>
<xf:else />
<span>{{ phrase('msc_offline_server') }}</span>
Expand Down
7 changes: 5 additions & 2 deletions _output/code_event_listeners/_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"entity_post_save_38510f988e511bd8ddcbdd99d2a8a6df.json": {
"hash": "e46abd2f4015042969bbaaa4c5d27ce4"
},
"templater_macro_pre_render_b1b054a9c2fdb298921f5512c6f52fae.json": {
"hash": "92ea5b25bc24994f38d1d8138e926e82"
"templater_macro_pre_render_4a7728827b1c1f3e07b7b26b8a6a5880.json": {
"hash": "8908fb5ef24e63f2bfe26bd75fd63830"
},
"templater_macro_pre_render_83a31bba71a0824854aa9047105d2384.json": {
"hash": "7bc0f41533da798b94267f21fbbe6ab1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"callback_class": "MinecraftServerChecker\\Listener",
"callback_method": "templaterMacroPreRender",
"active": true,
"hint": "public:msc_server_info:item",
"description": "Macro variables"
"hint": "public:msc_server_info:thread_view",
"description": "Thread view event listener"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"event_id": "templater_macro_pre_render",
"execute_order": 10,
"callback_class": "MinecraftServerChecker\\Listener",
"callback_method": "templaterMacroPreRender",
"active": true,
"hint": "public:msc_server_info:thread_list",
"description": "Thread list event listener"
}
13 changes: 11 additions & 2 deletions _output/template_modifications/_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
"public/msc_copy_js.json": {
"hash": "4c9e9ca4b1ca9ffa50fff17263c633ec"
},
"public/msc_item_new_posts.json": {
"hash": "95b2fae1c433de3fc5154926f30fe92d"
},
"public/msc_item_new_threads.json": {
"hash": "a6485ab07461d6e97de89f5eee6acf2e"
},
"public/msc_server_info_block.json": {
"hash": "be91d8ad01128b34d860612837da87be"
"hash": "9e0aa74de1cf9aae6a23c50a57e97e7e"
},
"public/msc_structured_list.json": {
"hash": "f4704d8784a025fee46180e2a4405580"
"hash": "66aa3eed1aed3dcb3490c0c43efb518a"
},
"public/msc_thread_title.json": {
"hash": "b332f24a4181a035bc3c66f074a093a1"
}
}
9 changes: 9 additions & 0 deletions _output/template_modifications/public/msc_item_new_posts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"template": "thread_list_macros",
"description": "Adds server information to the thread list for widgets.",
"execution_order": 10,
"enabled": true,
"action": "str_replace",
"find": "\t\t\t<xf:if is=\"$thread.isUnread()\">\n\t\t\t\t<a href=\"{{ link('threads/unread', $thread) }}\">{{ prefix('thread', $thread) }}{$thread.title}</a>\n\t\t\t<xf:else />\n\t\t\t\t<a href=\"{{ link('threads/post', $thread, {'post_id': $thread.last_post_id}) }}\">{{ prefix('thread', $thread) }}{$thread.title}</a>\n\t\t\t</xf:if>",
"replace": "$0\n<br>\n<xf:macro name=\"{{ $templateOverrides.msc_server_info ?: 'msc_server_info::thread_list' }}\" />"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"template": "thread_list_macros",
"description": "Adds server information to the thread list for widgets.",
"execution_order": 10,
"enabled": true,
"action": "str_replace",
"find": "<a href=\"{{ link('threads', $thread) }}\">{{ prefix('thread', $thread) }}{$thread.title}</a>",
"replace": "$0\n<br>\n<xf:macro name=\"{{ $templateOverrides.msc_server_info ?: 'msc_server_info::thread_list' }}\" />"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"enabled": true,
"action": "str_replace",
"find": "<div class=\"structItem-title\">",
"replace": "$0\n<xf:macro name=\"{{ $templateOverrides.msc_server_info ?: 'msc_server_info::item' }}\" />"
"replace": "$0\n<xf:macro name=\"{{ $templateOverrides.msc_server_info ?: 'msc_server_info::thread_list' }}\" />"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"template": "structured_list.less",
"template": "core.less",
"description": "Adds style support for Minecraft Server information.",
"execution_order": 10,
"enabled": true,
"action": "str_replace",
"find": ".structItem-title\n{",
"replace": "$0\n.msc-status {\n\tcolor: #efefef;\n border-color: transparent;\n border-radius: 5px;\n}\n\n.msc-online {\n background: #249a24;\n}\n\n.msc-offline {\n background: #9a2424;\n}\n\n.msc-copyip {\n\tcolor: #185886;\n\tborder-color: #e5e5e5;\n}\n\n.msc-copyip:hover {\n\tcursor: pointer;\n}\n\n.msc-ip {\n\tdisplay: none;\n}"
"find": "{{ include('core_bbcode.less') }}",
"replace": "$0\n{{ include('msc.less') }}"
}
9 changes: 9 additions & 0 deletions _output/template_modifications/public/msc_thread_title.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"template": "PAGE_CONTAINER",
"description": "Adds server information to the thread title.",
"execution_order": 10,
"enabled": true,
"action": "str_replace",
"find": "<h1 class=\"p-title-value\">",
"replace": "$0\n<xf:macro name=\"{{ $templateOverrides.msc_server_info ?: 'msc_server_info::thread_view' }}\" />"
}
11 changes: 8 additions & 3 deletions _output/templates/_metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"public/msc.less": {
"version_id": 1020,
"version_string": "1.0.2",
"hash": "262ee085fef232ed4078c159ced2cd1b"
},
"public/msc_server_info.html": {
"version_id": 1000,
"version_string": "1.0.0",
"hash": "00904930c5e8e35ecff2784a76282c9c"
"version_id": 1020,
"version_string": "1.0.2",
"hash": "92dd856654890eb4756b6a1870e2a2aa"
}
}
30 changes: 30 additions & 0 deletions _output/templates/public/msc.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.msc-status {
color: #efefef;
border-color: transparent;
border-radius: 5px;
}

.msc-online {
background: #249a24;
}

.msc-offline {
background: #9a2424;
}

.msc-copyip {
color: #185886;
border-color: #e5e5e5;
}

.msc-copyip:hover {
cursor: pointer;
}

.msc-ip {
display: none;
}

.p-title-value .msc-status {
padding-right: 5px;
}
24 changes: 22 additions & 2 deletions _output/templates/public/msc_server_info.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
<xf:macro name="item" arg-thread="{$thread}">
<xf:macro name="thread_list" arg-thread="{$thread}">

<xf:if is="$thread.custom_fields.msc_server_ip">
<span class="label msc-status msc-{$msc_status}">
<xf:if is="$msc_online">
<xf:if is="{$msc_status} === 'online'">
<span data-xf-init="tooltip" data-original-title="{{ phrase('msc_online_players') }}">{$msc_online}</span>/<span data-xf-init="tooltip" data-original-title="{{ phrase('msc_max_players') }}">{$msc_max}</span>
<xf:else />
<span>{{ phrase('msc_offline_server') }}</span>
</xf:if>
</span>

<a class="labelLink" onclick="msc_copy_ip('{$msc_ip}')"
data-xf-init="tooltip" data-original-title="{{ phrase('msc_copy_ip_address') }}" >
<span class="label msc-copyip"><i class="fas fa-copy"></i></span>
<span id="mscip-{$msc_ip}" class="msc-ip">{$msc_ip}</span>
</a>
</xf:if>

</xf:macro>

<xf:macro name="thread_view">

<xf:if is="$msc_title">
<span class="label msc-status msc-{$msc_status}">
<xf:if is="{$msc_status} === 'online'">
<span data-xf-init="tooltip" data-original-title="{{ phrase('msc_online_players') }}">{$msc_online}</span>/<span data-xf-init="tooltip" data-original-title="{{ phrase('msc_max_players') }}">{$msc_max}</span>
<xf:else />
<span>{{ phrase('msc_offline_server') }}</span>
Expand Down
4 changes: 2 additions & 2 deletions addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"legacy_addon_id": "",
"title": "Minecraft Server Checker",
"description": "It pulls server data with custom thread fields and adds it to the thread list.",
"version_id": 1010,
"version_string": "1.0.1",
"version_id": 1020,
"version_string": "1.0.2",
"dev": "Samet Girginer",
"dev_url": "https://github.com/sametgirginer",
"faq_url": "",
Expand Down

0 comments on commit 9ea57ea

Please sign in to comment.