1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* User Notification Control [UNC]. An extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2020-2021, Dark❶, https://dark1.tech |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace dark1\usernotificationcontrol\core; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @ignore |
15
|
|
|
*/ |
16
|
|
|
use phpbb\user; |
17
|
|
|
use phpbb\extension\manager as ext_manager; |
18
|
|
|
use phpbb\notification\type\type_interface; |
19
|
|
|
use phpbb\notification\method\method_interface; |
20
|
|
|
use phpbb\finder; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* User Notification Control Core Helper Class. |
24
|
|
|
*/ |
25
|
|
|
class unc_helper |
26
|
|
|
{ |
27
|
|
|
/** @var user */ |
28
|
|
|
protected $user; |
29
|
|
|
|
30
|
|
|
/** @var ext_manager */ |
31
|
|
|
protected $ext_manager; |
32
|
|
|
|
33
|
|
|
/** @var array Notification Types */ |
34
|
|
|
protected $notification_types; |
35
|
|
|
|
36
|
|
|
/** @var array Notification Methods */ |
37
|
|
|
protected $notification_methods; |
38
|
|
|
|
39
|
|
|
/** @var string phpBB php ext */ |
40
|
|
|
protected $php_ext; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor for User Notification Control Core Table Class. |
44
|
|
|
* |
45
|
|
|
* @param user $user User object |
46
|
|
|
* @param ext_manager $ext_manager phpBB Extension Manager |
47
|
|
|
* @param array $notification_types phpBB Notification Types |
48
|
|
|
* @param array $notification_methods phpBB Notification Methods |
49
|
|
|
* @param string $php_ext phpBB php ext |
50
|
|
|
*/ |
51
|
|
|
public function __construct(user $user, ext_manager $ext_manager, $notification_types, $notification_methods, $php_ext) |
52
|
|
|
{ |
53
|
|
|
$this->user = $user; |
54
|
|
|
$this->ext_manager = $ext_manager; |
55
|
|
|
$this->notification_types = $notification_types; |
56
|
|
|
$this->notification_methods = $notification_methods; |
57
|
|
|
$this->php_ext = $php_ext; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get all of the subscription methods |
64
|
|
|
* |
65
|
|
|
* @return array Array of methods |
66
|
|
|
* @access public |
67
|
|
|
*/ |
68
|
|
|
public function get_subscription_methods() |
69
|
|
|
{ |
70
|
|
|
$subscription_methods = []; |
71
|
|
|
|
72
|
|
|
/** @var method_interface $method */ |
73
|
|
|
foreach ($this->notification_methods as $method_name => $method) |
74
|
|
|
{ |
75
|
|
|
$subscription_methods[$method_name] = [ |
76
|
|
|
'id' => $method->get_type(), |
77
|
|
|
'lang' => str_replace('.', '_', strtoupper($method->get_type())), |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $subscription_methods; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get all of the subscription types |
88
|
|
|
* |
89
|
|
|
* @return array Array of item types |
90
|
|
|
* @access public |
91
|
|
|
*/ |
92
|
|
|
public function get_subscription_types() |
93
|
|
|
{ |
94
|
|
|
$subscription_types = []; |
95
|
|
|
$prefix = 'NOTIFICATION_TYPE_'; |
96
|
|
|
|
97
|
|
|
/** @var type_interface $type */ |
98
|
|
|
foreach ($this->notification_types as $type_name => $type) |
99
|
|
|
{ |
100
|
|
|
$lang = str_replace('.', '_', strtoupper($type->get_type())); |
101
|
|
|
if (substr($lang, 0, strlen($prefix)) == $prefix) |
102
|
|
|
{ |
103
|
|
|
$lang = substr($lang, strlen($prefix)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$type_ary = [ |
107
|
|
|
'id' => $type->get_type(), |
108
|
|
|
'lang' => $prefix . $lang, |
109
|
|
|
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', |
110
|
|
|
]; |
111
|
|
|
|
112
|
|
|
if ($type::$notification_option !== false) |
113
|
|
|
{ |
114
|
|
|
$type_ary = array_merge($type_ary, $type::$notification_option); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$subscription_types[$type_ary['group']][$type_ary['id']] = $type_ary; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
// Move miscellaneous group to last section |
121
|
|
|
if (isset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'])) |
122
|
|
|
{ |
123
|
|
|
$miscellaneous = $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']; |
124
|
|
|
unset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); |
125
|
|
|
$subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $subscription_types; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get all of the subscription methods |
135
|
|
|
* |
136
|
|
|
* @return array Array of methods |
137
|
|
|
* @access public |
138
|
|
|
*/ |
139
|
|
|
public function get_lang_unc_custom() |
140
|
|
|
{ |
141
|
|
|
$lang_ary = []; |
142
|
|
|
$ext_name = 'dark1/usernotificationcontrol'; |
143
|
|
|
$ext_lang = 'lang_unc_custom'; |
144
|
|
|
|
145
|
|
|
/** @var finder $finder */ |
146
|
|
|
$finder = $this->ext_manager->get_finder(); |
147
|
|
|
$lang_file_path = $finder |
148
|
|
|
->set_extensions([$ext_name]) |
149
|
|
|
->prefix($ext_lang) |
150
|
|
|
->suffix('.'.$this->php_ext) |
151
|
|
|
->directory("language/".$this->user->lang_name) |
152
|
|
|
//->extension_directory("/language/".$this->user->lang_name) |
153
|
|
|
//->core_path("language/".$this->user->lang_name) |
154
|
|
|
->get_files(); |
155
|
|
|
|
156
|
|
|
// Check if exists |
157
|
|
|
if (current($lang_file_path)) |
158
|
|
|
{ |
159
|
|
|
$lang_ary = [$ext_name => $ext_lang]; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $lang_ary; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|