1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Member Avatar & Status [MAS]. An extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2018-2020, Dark❶ [dark1] |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0-only) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace dark1\memberavatarstatus\core; |
12
|
|
|
|
13
|
|
|
use phpbb\config\config; |
14
|
|
|
use phpbb\language\language; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Member Avatar & Status Core Avatar Class. |
18
|
|
|
*/ |
19
|
|
|
class mas_avatar |
20
|
|
|
{ |
21
|
|
|
/** @var int No Avatar Size */ |
22
|
|
|
const NO_AVATAR_SIZE = 1000; |
23
|
|
|
|
24
|
|
|
/** @var int Avatar Minimum Size */ |
25
|
|
|
const AV_MIN_SZ = 9; |
26
|
|
|
|
27
|
|
|
/** @var int Avatar Default Size Small */ |
28
|
|
|
const AV_DEF_SZ_SML = 20; |
29
|
|
|
|
30
|
|
|
/** @var int Avatar Default Size Big */ |
31
|
|
|
const AV_DEF_SZ_BIG = 50; |
32
|
|
|
|
33
|
|
|
/** @var int Avatar Maximum Size Small */ |
34
|
|
|
const AV_MAX_SZ_SML = 99; |
35
|
|
|
|
36
|
|
|
/** @var int Avatar Maximum Size Big */ |
37
|
|
|
const AV_MAX_SZ_BIG = 999; |
38
|
|
|
|
39
|
|
|
/** @var \phpbb\config\config */ |
40
|
|
|
protected $config; |
41
|
|
|
|
42
|
|
|
/** @var \phpbb\language\language */ |
43
|
|
|
protected $language; |
44
|
|
|
|
45
|
|
|
/** @var string */ |
46
|
|
|
protected $phpbb_root_path; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Constructor for listener |
50
|
|
|
* |
51
|
|
|
* @param \phpbb\config\config $config phpBB config |
52
|
|
|
* @param \phpbb\language\language $language phpBB language |
53
|
|
|
* @param string $phpbb_root_path phpBB root_path |
54
|
|
|
* @access public |
55
|
|
|
*/ |
56
|
|
|
public function __construct(config $config, language $language, $phpbb_root_path) |
57
|
|
|
{ |
58
|
|
|
$this->config = $config; |
59
|
|
|
$this->language = $language; |
60
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* MAS Get No Avatar IMG |
67
|
|
|
* |
68
|
|
|
* @param void |
69
|
|
|
* @return string String with No Avatar IMG |
70
|
|
|
* @access public |
71
|
|
|
*/ |
72
|
|
|
public function mas_get_no_avatar_img() |
73
|
|
|
{ |
74
|
|
|
$avatar_row = array( |
75
|
|
|
'avatar' => append_sid($this->phpbb_root_path . 'ext/dark1/memberavatarstatus/image/avatar.png'), |
76
|
|
|
'avatar_type' => AVATAR_REMOTE, |
77
|
|
|
'avatar_width' => self::NO_AVATAR_SIZE, |
78
|
|
|
'avatar_height' => self::NO_AVATAR_SIZE, |
79
|
|
|
); |
80
|
|
|
return str_replace( |
81
|
|
|
'" />', |
82
|
|
|
'" title="' . $this->language->lang('MAS_NO_AVATAR_TEXT') . '" />', |
83
|
|
|
phpbb_get_user_avatar($avatar_row, $this->language->lang('MAS_NO_AVATAR_TEXT'), true) |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* MAS Get Config Avatar |
91
|
|
|
* |
92
|
|
|
* @param string $config_key takes Config Key String |
93
|
|
|
* @return bool Bool with Avatar Enable |
94
|
|
|
* @access public |
95
|
|
|
*/ |
96
|
|
|
public function mas_get_config_avatar($config_key) |
97
|
|
|
{ |
98
|
|
|
// Check if Avatar is Enabled. |
99
|
|
|
return (bool) ($this->config['allow_avatar'] && $this->config['dark1_mas_avatar'] && $this->config[$config_key]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* MAS Get Avatar SQL Query |
106
|
|
|
* |
107
|
|
|
* @param array $sql_ary takes SQL Array |
108
|
|
|
* @param string $config_key takes Config Key String |
109
|
|
|
* @param string $sql_uid Specifies User ID to be Matched with. |
110
|
|
|
* @param string $sql_obj Specifies SQL Object |
111
|
|
|
* @param string $prefix Specifies the prefix to be Set in SQL Select |
112
|
|
|
* @param string $lj_on_ex Specifies the Left Join On Extra SQL Query |
113
|
|
|
* @return array Array of data |
114
|
|
|
* @access public |
115
|
|
|
*/ |
116
|
|
|
public function mas_avatar_sql_query($sql_ary, $config_key, $sql_uid, $sql_obj, $prefix, $lj_on_ex) |
117
|
|
|
{ |
118
|
|
|
$config_key .= '_av'; |
119
|
|
|
$prefix .= ($prefix != '') ? '_' : ''; |
120
|
|
|
|
121
|
|
|
if ($this->mas_get_config_avatar($config_key)) |
122
|
|
|
{ |
123
|
|
|
$sql_ary['SELECT'] .= ', ' . $sql_obj . '.user_avatar as ' . $prefix . 'avatar, ' . $sql_obj . '.user_avatar_type as ' . $prefix . 'avatar_type, ' . $sql_obj . '.user_avatar_width as ' . $prefix . 'avatar_width, ' . $sql_obj . '.user_avatar_height as ' . $prefix . 'avatar_height'; |
124
|
|
|
$sql_ary['LEFT_JOIN'][] = array( |
125
|
|
|
'FROM' => array(USERS_TABLE => $sql_obj), |
126
|
|
|
'ON' => $sql_uid . ' = ' . $sql_obj . '.user_id' . $lj_on_ex, |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $sql_ary; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* MAS Get Avatar Size |
137
|
|
|
* |
138
|
|
|
* @param int $av_sz takes Avatar Size |
139
|
|
|
* @param int $av_default_sz Specifies Default Size in px |
140
|
|
|
* @param int $av_max_sz Specifies Avatar MAX Size in px |
141
|
|
|
* @return int Integer with Avatar Size in px |
142
|
|
|
* @access public |
143
|
|
|
*/ |
144
|
|
|
public function mas_get_avatar_size($av_sz, $av_default_sz = self::AV_DEF_SZ_SML, $av_max_sz = self::AV_MAX_SZ_SML) |
145
|
|
|
{ |
146
|
|
|
// $av_sz , Need to set this between self::AV_MIN_SZ to $av_max_sz Only , Default is $av_default_sz. |
147
|
|
|
if ($av_sz < self::AV_MIN_SZ || $av_sz > $av_max_sz) |
148
|
|
|
{ |
149
|
|
|
$av_sz = $av_default_sz; |
150
|
|
|
} |
151
|
|
|
return (int) $av_sz; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* MAS Get Config Avatar Size |
158
|
|
|
* |
159
|
|
|
* @param string $config_key takes Config Key String |
160
|
|
|
* @param int $av_default_sz Specifies Default Size in px |
161
|
|
|
* @param int $av_max_sz Specifies Avatar MAX Size in px |
162
|
|
|
* @return int Integer with Avatar Size in px |
163
|
|
|
* @access public |
164
|
|
|
*/ |
165
|
|
|
public function mas_get_config_avatar_size($config_key, $av_default_sz = self::AV_DEF_SZ_SML, $av_max_sz = self::AV_MAX_SZ_SML) |
166
|
|
|
{ |
167
|
|
|
// config -> dark1_mas_XX_sz , Need to get this between self::AV_MIN_SZ to $av_max_sz Only , Default is $av_default_sz. |
168
|
|
|
$av_sz = $this->mas_get_avatar_size((int) $this->config[$config_key], $av_default_sz, $av_max_sz); |
169
|
|
|
|
170
|
|
|
// Check if correction is required then set it. |
171
|
|
|
if ($av_sz != $this->config[$config_key]) |
172
|
|
|
{ |
173
|
|
|
$this->config->set($config_key, $av_sz); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
return (int) $this->config[$config_key]; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* MAS Get Avatar |
183
|
|
|
* |
184
|
|
|
* @param string $config_key takes Config Key String |
185
|
|
|
* @param string $prefix Specifies the prefix to be Searched in the $row |
186
|
|
|
* @param array $row is array of data |
187
|
|
|
* @return string String with Avatar Data |
188
|
|
|
* @access public |
189
|
|
|
*/ |
190
|
|
|
public function mas_get_avatar($config_key, $prefix, $row) |
191
|
|
|
{ |
192
|
|
|
$avatar = ''; |
193
|
|
|
$config_key .= '_av'; |
194
|
|
|
$prefix .= ($prefix != '') ? '_' : ''; |
195
|
|
|
|
196
|
|
|
if ($this->mas_get_config_avatar($config_key)) |
197
|
|
|
{ |
198
|
|
|
// $avatar_row |
199
|
|
|
$avatar_row = array( |
200
|
|
|
'avatar' => $row[$prefix . 'avatar'], |
201
|
|
|
'avatar_type' => $row[$prefix . 'avatar_type'], |
202
|
|
|
'avatar_width' => $row[$prefix . 'avatar_width'], |
203
|
|
|
'avatar_height' => $row[$prefix . 'avatar_height'], |
204
|
|
|
); |
205
|
|
|
$avatar = phpbb_get_user_avatar($avatar_row); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
return $avatar; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
} |
212
|
|
|
|