Skip to content

Commit e40a712

Browse files
committed
feat: add permission data
1 parent 9090ccd commit e40a712

File tree

6 files changed

+172
-101
lines changed

6 files changed

+172
-101
lines changed

Diff for: event/main_listener.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
*
4-
* Topic Color. An extension for the phpBB Forum Software package.
4+
* Topic Title Color. An extension for the phpBB Forum Software package.
55
*
66
* @copyright (c) 2017, David Colón, https://www.davidiq.com
77
* @license GNU General Public License, version 2 (GPL-2.0)
@@ -60,15 +60,15 @@ public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface
6060

6161
static public function getSubscribedEvents()
6262
{
63-
return array(
63+
return [
6464
'core.modify_posting_auth' => 'modify_posting_auth',
6565
'core.posting_modify_submit_post_after' => 'posting_modify_submit_post_after',
6666
'core.viewtopic_modify_page_title' => 'viewtopic_modify_page_title',
6767
'core.viewforum_modify_topics_data' => 'viewforum_modify_topics_data',
6868
'core.viewforum_modify_topicrow' => 'viewforum_modify_topicrow',
6969
'core.display_forums_before' => 'display_forums_before',
7070
'core.display_forums_modify_template_vars' => 'display_forums_modify_template_vars',
71-
);
71+
];
7272
}
7373

7474
/**
@@ -104,11 +104,11 @@ public function modify_posting_auth($event)
104104
{
105105
$this->user->add_lang_ext('davidiq/topictitlecolor', 'topictitlecolor');
106106
$title_color = strtoupper($this->request->variable('title_color', ''));
107-
$this->template->assign_vars(array(
107+
$this->template->assign_vars([
108108
'S_TOPIC_TITLE_COLOR' => true,
109109
'TITLE_COLOR' => $title_color,
110110
'S_TOPIC_PREVIEW' => true,
111-
));
111+
]);
112112
}
113113

114114
$this->get_topic_color($topic_id);
@@ -142,10 +142,10 @@ public function posting_modify_submit_post_after($event)
142142

143143
if (is_array($color_matches) && !empty($color_matches[0]))
144144
{
145-
$sql = "INSERT INTO {$this->table_prefix}topic_title_colors " . $this->db->sql_build_array('INSERT', array(
145+
$sql = "INSERT INTO {$this->table_prefix}topic_title_colors " . $this->db->sql_build_array('INSERT', [
146146
'topic_id' => $topic_id,
147147
'title_color' => $color_matches[0],
148-
));
148+
]);
149149
$this->db->sql_query($sql);
150150
}
151151
}
@@ -194,7 +194,7 @@ public function viewforum_modify_topicrow($event)
194194
public function display_forums_before($event)
195195
{
196196
$forum_rows = $event['forum_rows'];
197-
$forum_last_post_ids = array();
197+
$forum_last_post_ids = [];
198198

199199
if (!$forum_rows || !count($forum_rows))
200200
{
@@ -214,14 +214,14 @@ public function display_forums_before($event)
214214
return;
215215
}
216216

217-
$sql_array = array(
217+
$sql_array = [
218218
'SELECT' => 'sc.topic_id, sc.title_color, p.post_id',
219-
'FROM' => array(
219+
'FROM' => [
220220
$this->table_prefix . 'posts' => 'p',
221221
$this->table_prefix . 'topic_title_colors' => 'sc',
222-
),
222+
],
223223
'WHERE' => 'p.topic_id = sc.topic_id AND ' . $this->db->sql_in_set('p.post_id', $forum_last_post_ids),
224-
);
224+
];
225225

226226
$result = $this->db->sql_query($this->db->sql_build_query('SELECT', $sql_array));
227227
$title_color_rows = $this->db->sql_fetchrowset($result);
@@ -265,14 +265,14 @@ private function get_topic_color($topic_ids, &$topic_rowset = false)
265265
{
266266
if (!is_array($topic_ids))
267267
{
268-
$topic_ids = array($topic_ids);
268+
$topic_ids = [$topic_ids];
269269
}
270270

271-
$sql_array = array(
271+
$sql_array = [
272272
'SELECT' => 'sc.topic_id, sc.title_color',
273-
'FROM' => array($this->table_prefix . 'topic_title_colors' => 'sc'),
273+
'FROM' => [$this->table_prefix . 'topic_title_colors' => 'sc'],
274274
'WHERE' => $this->db->sql_in_set('sc.topic_id', $topic_ids),
275-
);
275+
];
276276
$result = $this->db->sql_query($this->db->sql_build_query('SELECT', $sql_array));
277277
$title_color_rows = $this->db->sql_fetchrowset($result);
278278
$this->db->sql_freeresult($result);

Diff for: language/en/permissions_topictitlecolor.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
*
4+
* Topic Title Color. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2022, David Colón, https://www.davidiq.com/
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
if (!defined('IN_PHPBB'))
12+
{
13+
exit;
14+
}
15+
16+
if (empty($lang) || !is_array($lang))
17+
{
18+
$lang = [];
19+
}
20+
21+
// DEVELOPERS PLEASE NOTE
22+
//
23+
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
24+
//
25+
// Placeholders can now contain order information, e.g. instead of
26+
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
27+
// translators to re-order the output of data while ensuring it remains correct
28+
//
29+
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
30+
// equally where a string contains only two placeholders which are used to wrap text
31+
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
32+
//
33+
// Some characters you may want to copy&paste:
34+
// ’ » “ ” …
35+
//
36+
37+
$lang = array_merge($lang, [
38+
'ACL_F_SETTOPICTITLECOLOR' => 'Can set topic title color',
39+
]);

Diff for: language/en/topictitlecolor.php

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
<?php
2-
/**
3-
*
4-
* titlecolor [English]
5-
*
6-
* @package language
7-
* @copyright (c) 2017 DavidIQ.com
8-
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
9-
*
10-
*/
11-
12-
/**
13-
* DO NOT CHANGE
14-
*/
15-
if (!defined('IN_PHPBB'))
16-
{
17-
exit;
18-
}
19-
20-
if (empty($lang) || !is_array($lang))
21-
{
22-
$lang = array();
23-
}
24-
25-
// DEVELOPERS PLEASE NOTE
26-
//
27-
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
28-
//
29-
// Placeholders can now contain order information, e.g. instead of
30-
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
31-
// translators to re-order the output of data while ensuring it remains correct
32-
//
33-
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
34-
// equally where a string contains only two placeholders which are used to wrap text
35-
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
36-
//
37-
38-
$lang = array_merge($lang, array(
39-
'TITLE_COLOUR' => 'Title colour',
40-
'NO_TITLE_COLOR' => 'NONE',
41-
));
42-
1+
<?php
2+
/**
3+
*
4+
* titlecolor [English]
5+
*
6+
* @package language
7+
* @copyright (c) 2017 DavidIQ.com
8+
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
9+
*
10+
*/
11+
12+
/**
13+
* DO NOT CHANGE
14+
*/
15+
if (!defined('IN_PHPBB'))
16+
{
17+
exit;
18+
}
19+
20+
if (empty($lang) || !is_array($lang))
21+
{
22+
$lang = [];
23+
}
24+
25+
// DEVELOPERS PLEASE NOTE
26+
//
27+
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
28+
//
29+
// Placeholders can now contain order information, e.g. instead of
30+
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
31+
// translators to re-order the output of data while ensuring it remains correct
32+
//
33+
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
34+
// equally where a string contains only two placeholders which are used to wrap text
35+
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
36+
//
37+
38+
$lang = array_merge($lang, [
39+
'TITLE_COLOUR' => 'Title colour',
40+
'NO_TITLE_COLOR' => 'NONE',
41+
]);
42+

Diff for: migrations/initial_schema.php

+43-43
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
<?php
2-
/**
3-
*
4-
* Subject Color. An extension for the phpBB Forum Software package.
5-
*
6-
* @copyright (c) 2017, David Colón, https://www.davidiq.com
7-
* @license GNU General Public License, version 2 (GPL-2.0)
8-
*
9-
*/
10-
11-
namespace davidiq\topictitlecolor\migrations;
12-
13-
class initial_schema extends \phpbb\db\migration\migration
14-
{
15-
public function effectively_installed()
16-
{
17-
return $this->db_tools->sql_table_exists($this->table_prefix . 'topic_title_colors');
18-
}
19-
20-
public function update_schema()
21-
{
22-
return array(
23-
'add_tables' => array(
24-
$this->table_prefix . 'topic_title_colors' => array(
25-
'COLUMNS' => array(
26-
'topic_id' => array('UINT', 0),
27-
'title_color' => array('VCHAR:6', ''),
28-
),
29-
'PRIMARY_KEY' => 'topic_id',
30-
),
31-
),
32-
);
33-
}
34-
35-
public function revert_schema()
36-
{
37-
return array(
38-
'drop_tables' => array(
39-
$this->table_prefix . 'topic_title_colors',
40-
),
41-
);
42-
}
43-
}
1+
<?php
2+
/**
3+
*
4+
* Subject Color. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2017, David Colón, https://www.davidiq.com
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace davidiq\topictitlecolor\migrations;
12+
13+
class initial_schema extends \phpbb\db\migration\migration
14+
{
15+
public function effectively_installed()
16+
{
17+
return $this->db_tools->sql_table_exists($this->table_prefix . 'topic_title_colors');
18+
}
19+
20+
public function update_schema()
21+
{
22+
return [
23+
'add_tables' => [
24+
$this->table_prefix . 'topic_title_colors' => [
25+
'COLUMNS' => [
26+
'topic_id' => ['UINT', 0],
27+
'title_color' => ['VCHAR:6', ''],
28+
],
29+
'PRIMARY_KEY' => 'topic_id',
30+
],
31+
],
32+
];
33+
}
34+
35+
public function revert_schema()
36+
{
37+
return [
38+
'drop_tables' => [
39+
$this->table_prefix . 'topic_title_colors',
40+
],
41+
];
42+
}
43+
}

Diff for: migrations/install_permission.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
*
4+
* Topic Title Color. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2020, David Colón, https://www.davidiq.com/
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace davidiq\topictitlecolor\migrations;
12+
13+
class install_permission extends \phpbb\db\migration\migration
14+
{
15+
public static function depends_on()
16+
{
17+
return ['\davidiq\topictitlecolor\migrations\install_schema'];
18+
}
19+
20+
/**
21+
* Add permissions data to the database during extension installation.
22+
*
23+
* @return array Array of data update instructions
24+
*/
25+
public function update_data()
26+
{
27+
return [
28+
// Add new permissions
29+
['permission.add', ['f_settopictitlecolor', false, 'f_noapprove']], // Copy settings from "Can post without approval"
30+
];
31+
}
32+
}
File renamed without changes.

0 commit comments

Comments
 (0)