Skip to content

Commit a90fa74

Browse files
authored
Merge pull request #33 from iMattPro/updates
Modernize code and future proof
2 parents 825158a + be95712 commit a90fa74

File tree

9 files changed

+48
-27
lines changed

9 files changed

+48
-27
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ This is the repository for the development of the Topic Prefixes phpBB extension
44

55
[![Build Status](https://github.com/phpbb-extensions/topicprefixes/actions/workflows/tests.yml/badge.svg)](https://github.com/phpbb-extensions/topicprefixes/actions)
66
[![codecov](https://codecov.io/gh/phpbb-extensions/topicprefixes/branch/master/graph/badge.svg?token=Dc0GWOeQWj)](https://codecov.io/gh/phpbb-extensions/topicprefixes)
7-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phpbb-extensions/topicprefixes/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phpbb-extensions/topicprefixes/?branch=master)
87

98
The phpBB Topic Prefixes extension allows phpBB board administrators to create topic prefix tags that users can easily add to their topic titles. Features include:
109

adm/style/acp_topic_prefixes.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.tp-toggle-on,
2+
.tp-toggle-off {
3+
font-weight: 900;
4+
}
5+
6+
.tp-toggle-on:before {
7+
content: "\f205";
8+
}
9+
10+
.tp-toggle-off:before {
11+
content: "\f204";
12+
}

adm/style/acp_topic_prefixes.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1>{{ lang('TOPIC_PREFIXES') }}</h1>
3434
<td><strong>{{ prefix.PREFIX_TAG }}</strong></td>
3535
<td>
3636
<a href="{{ prefix.U_EDIT }}" style="text-decoration: none" title="{{ lang('TOPIC_PREFIX_TOGGLE_STATE') }}" data-ajax="tp_toggle">
37-
<i class="icon acp-icon fa-toggle-{{ prefix.PREFIX_ENABLED ? 'on' : 'off' }} fa-fw"></i>
37+
<i class="fa fa-fw tp-toggle-{{ prefix.PREFIX_ENABLED ? 'on' : 'off' }} acp-icon"></i>
3838
</a>
3939
</td>
4040
<td class="actions">
@@ -56,10 +56,10 @@ <h1>{{ lang('TOPIC_PREFIXES') }}</h1>
5656
<form id="acp_add_topic_prefix" method="post" action="{{ U_ACTION }}">
5757
<fieldset class="quick">
5858
{{ lang('CREATE_TOPIC_PREFIX') ~ lang('COLON') }}
59-
<input type="text" name="prefix_tag" value="" maxlength="200" placeholder="{{ lang('TOPIC_PREFIX_PLACEHOLDER') }}" />
60-
<input class="button2" name="submit" type="submit" value="{{ lang('SUBMIT') }}" />
61-
<input type="hidden" name="action" value="add" />
62-
<input type="hidden" name="forum_id" value="{{ FORUM_ID }}" />
59+
<input type="text" name="prefix_tag" value="" maxlength="200" placeholder="{{ lang('TOPIC_PREFIX_PLACEHOLDER') }}">
60+
<input class="button2" name="submit" type="submit" value="{{ lang('SUBMIT') }}">
61+
<input type="hidden" name="action" value="add">
62+
<input type="hidden" name="forum_id" value="{{ FORUM_ID }}">
6363
{{ S_FORM_TOKEN }}
6464
{{ S_HIDDEN_FIELDS }}
6565
</fieldset>
@@ -68,4 +68,5 @@ <h1>{{ lang('TOPIC_PREFIXES') }}</h1>
6868
{% endif %}
6969

7070
{% INCLUDEJS '@phpbb_topicprefixes/acp_topic_prefixes.js' %}
71+
{% INCLUDECSS '@phpbb_topicprefixes/acp_topic_prefixes.css' %}
7172
{% include 'overall_footer.html' %}

adm/style/acp_topic_prefixes.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
(function($) {
2-
1+
(function() {
32
'use strict';
43

5-
$('#select_forum').on('change', function() {
6-
$(this).closest('form').trigger('submit');
4+
document.getElementById('select_forum').addEventListener('change', function() {
5+
this.closest('form').submit();
76
});
87

98
phpbb.addAjaxCallback('tp_toggle', function(res) {
@@ -12,8 +11,7 @@
1211
}
1312

1413
const icon = this.querySelector('i');
15-
icon.classList.toggle('fa-toggle-on');
16-
icon.classList.toggle('fa-toggle-off');
14+
icon.classList.toggle('tp-toggle-on');
15+
icon.classList.toggle('tp-toggle-off');
1716
});
18-
19-
})(jQuery);
17+
})();

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "phpbb-extension",
44
"description": "An official phpBB extension for topic prefixes.",
55
"homepage": "https://www.phpbb.com/customise/db/extension/topicprefixes/",
6-
"version": "1.0.1",
6+
"version": "1.0.2-dev",
77
"license": "GPL-2.0-only",
88
"authors": [
99
{
@@ -27,7 +27,7 @@
2727
"extra": {
2828
"display-name": "phpBB Topic Prefixes",
2929
"soft-require": {
30-
"phpbb/phpbb": ">=3.2.0,<4.0.0@dev"
30+
"phpbb/phpbb": ">=3.2.0"
3131
},
3232
"version-check": {
3333
"host": "www.phpbb.com",

controller/admin_controller.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace phpbb\topicprefixes\controller;
1212

13+
use phpbb\json_response;
1314
use phpbb\language\language;
1415
use phpbb\log\log;
1516
use phpbb\request\request;
@@ -188,8 +189,7 @@ public function edit_prefix($prefix_id)
188189

189190
if ($this->request->is_ajax())
190191
{
191-
$json_response = new \phpbb\json_response;
192-
$json_response->send(['success' => true]);
192+
$this->send_json_response(true);
193193
}
194194
}
195195

@@ -251,8 +251,7 @@ public function move_prefix($prefix_id, $direction, $amount = 1)
251251

252252
if ($this->request->is_ajax())
253253
{
254-
$json_response = new \phpbb\json_response;
255-
$json_response->send(['success' => true]);
254+
$this->send_json_response(true);
256255
}
257256
}
258257

@@ -334,4 +333,18 @@ protected function get_forum_info($forum_id)
334333

335334
return $acp_forums->get_forum_info($forum_id);
336335
}
336+
337+
/**
338+
* Send a JSON response
339+
*
340+
* @param bool $content The content of the JSON response (true|false)
341+
* @access protected
342+
*/
343+
protected function send_json_response($content)
344+
{
345+
$json_response = new json_response;
346+
$json_response->send([
347+
'success' => (bool) $content,
348+
]);
349+
}
337350
}

ext.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class ext extends \phpbb\extension\base
3131
*/
3232
public function is_enableable()
3333
{
34-
return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=')
35-
&& phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '<')
36-
&& PHP_VERSION_ID >= 50400;
34+
return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=') && PHP_VERSION_ID >= 50400;
3735
}
3836
}

language/en/info_acp_topic_prefixes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
'ACP_MANAGE_PREFIXES' => 'Manage prefixes',
2727

2828
// ACP Log messages
29-
'ACP_LOG_PREFIX_ADDED' => '<strong>Created new topic prefix</strong><br />» %1$s in forum: %2$s',
30-
'ACP_LOG_PREFIX_DELETED' => '<strong>Deleted topic prefix</strong><br />» %1$s in forum: %2$s',
29+
'ACP_LOG_PREFIX_ADDED' => '<strong>Created new topic prefix</strong><br>» %1$s in forum: %2$s',
30+
'ACP_LOG_PREFIX_DELETED' => '<strong>Deleted topic prefix</strong><br>» %1$s in forum: %2$s',
3131
));

tests/functional/functional_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ public function test_acp_disable_prefix()
7979

8080
// Disable the prefix
8181
$crawler = self::request('GET', 'adm/index.php?i=\phpbb\topicprefixes\acp\topic_prefixes_module&mode=manage&action=edit&forum_id=' . self::FORUM_ID . "&prefix_id={$prefix}&hash={$hash}&sid={$this->sid}");
82-
self::assertCount(1, $crawler->filter('tr')->eq(2)->filter('.fa-toggle-off'));
82+
self::assertCount(1, $crawler->filter('tr')->eq(2)->filter('.tp-toggle-off'));
8383

8484
// Enable the prefix
8585
$crawler = self::request('GET', 'adm/index.php?i=\phpbb\topicprefixes\acp\topic_prefixes_module&mode=manage&action=edit&forum_id=' . self::FORUM_ID . "&prefix_id={$prefix}&hash={$hash}&sid={$this->sid}");
86-
self::assertCount(1, $crawler->filter('tr')->eq(2)->filter('.fa-toggle-on'));
86+
self::assertCount(1, $crawler->filter('tr')->eq(2)->filter('.tp-toggle-on'));
8787
}
8888

8989
public function test_acp_delete_prefix()

0 commit comments

Comments
 (0)