1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Topic Preview |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2013 Matt Friedman |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace vse\topicpreview\core; |
12
|
|
|
|
13
|
|
|
use phpbb\config\config; |
|
|
|
|
14
|
|
|
use phpbb\event\dispatcher_interface; |
|
|
|
|
15
|
|
|
use phpbb\language\language; |
|
|
|
|
16
|
|
|
use phpbb\template\template; |
|
|
|
|
17
|
|
|
use phpbb\user; |
|
|
|
|
18
|
|
|
use vse\topicpreview\core\trim\trim; |
19
|
|
|
|
20
|
|
|
class display extends base |
21
|
|
|
{ |
22
|
|
|
/** @var int default width of topic preview */ |
23
|
|
|
const PREVIEW_SIZE = 360; |
24
|
|
|
|
25
|
|
|
/** @var int default height and width of topic preview avatars */ |
26
|
|
|
const AVATAR_SIZE = 60; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
const NO_AVATAR = 'no-avatar'; |
30
|
|
|
|
31
|
|
|
/** @var dispatcher_interface */ |
32
|
|
|
protected $dispatcher; |
33
|
|
|
|
34
|
|
|
/** @var language */ |
35
|
|
|
protected $language; |
36
|
|
|
|
37
|
|
|
/** @var template */ |
38
|
|
|
protected $template; |
39
|
|
|
|
40
|
|
|
/** @var string phpBB root path */ |
41
|
|
|
protected $root_path; |
42
|
|
|
|
43
|
|
|
/** @var trim */ |
44
|
|
|
protected $trim; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Constructor |
48
|
|
|
* |
49
|
|
|
* @param config $config Config object |
50
|
|
|
* @param dispatcher_interface $dispatcher Event dispatcher object |
51
|
|
|
* @param language $language Language object |
52
|
|
|
* @param template $template Template object |
53
|
|
|
* @param trim $trim Trim text object |
54
|
|
|
* @param user $user User object |
55
|
|
|
* @param string $root_path |
56
|
|
|
*/ |
57
|
9 |
|
public function __construct(config $config, dispatcher_interface $dispatcher, language $language, template $template, trim $trim, user $user, $root_path) |
58
|
|
|
{ |
59
|
9 |
|
$this->dispatcher = $dispatcher; |
60
|
9 |
|
$this->language = $language; |
61
|
9 |
|
$this->template = $template; |
62
|
9 |
|
$this->trim = $trim; |
63
|
9 |
|
$this->root_path = $root_path; |
64
|
9 |
|
parent::__construct($config, $user); |
65
|
|
|
|
66
|
9 |
|
$this->setup(); |
67
|
9 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Set up some common components |
71
|
|
|
*/ |
72
|
9 |
|
public function setup() |
73
|
|
|
{ |
74
|
|
|
// Load our language file (only needed if showing last post text) |
75
|
9 |
|
if ($this->last_post_enabled()) |
76
|
9 |
|
{ |
77
|
6 |
|
$this->language->add_lang('topic_preview', 'vse/topicpreview'); |
78
|
6 |
|
} |
79
|
|
|
|
80
|
9 |
|
$this->template->assign_vars(array( |
81
|
9 |
|
'S_TOPICPREVIEW' => $this->is_enabled(), |
82
|
9 |
|
'TOPICPREVIEW_THEME' => $this->get_theme(), |
83
|
9 |
|
'TOPICPREVIEW_DELAY' => $this->config['topic_preview_delay'], |
84
|
9 |
|
'TOPICPREVIEW_DRIFT' => $this->config['topic_preview_drift'], |
85
|
9 |
|
'TOPICPREVIEW_WIDTH' => !empty($this->config['topic_preview_width']) ? $this->config['topic_preview_width'] : self::PREVIEW_SIZE, |
86
|
9 |
|
)); |
87
|
9 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Inject topic preview text into the template |
91
|
|
|
* |
92
|
|
|
* @param array $row Row data |
93
|
|
|
* @param array $block Template vars array |
94
|
|
|
* |
95
|
|
|
* @return array Template vars array |
96
|
|
|
*/ |
97
|
6 |
|
public function display_topic_preview($row, $block) |
98
|
|
|
{ |
99
|
6 |
|
if (!$this->is_enabled()) |
100
|
6 |
|
{ |
101
|
1 |
|
return $block; |
102
|
|
|
} |
103
|
|
|
|
104
|
5 |
|
$block = array_merge($block, array( |
105
|
5 |
|
'TOPIC_PREVIEW_FIRST_POST' => $this->get_text_helper($row, 'first_post_text'), |
106
|
5 |
|
'TOPIC_PREVIEW_LAST_POST' => $this->get_text_helper($row, 'last_post_text'), |
107
|
5 |
|
'TOPIC_PREVIEW_FIRST_AVATAR' => $this->get_user_avatar_helper($row, 'fp'), |
108
|
5 |
|
'TOPIC_PREVIEW_LAST_AVATAR' => $this->get_user_avatar_helper($row, 'lp'), |
109
|
5 |
|
)); |
110
|
|
|
|
111
|
5 |
|
$tp_avatars = $this->avatars_enabled(); |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* EVENT to modify the topic preview display output before it gets inserted in the template block |
115
|
|
|
* |
116
|
|
|
* @event vse.topicpreview.display_topic_preview |
117
|
|
|
* @var array row Topic row data |
118
|
|
|
* @var array block Template vars array |
119
|
|
|
* @var bool tp_avatars Display avatars setting |
120
|
|
|
* @since 2.1.0 |
121
|
|
|
*/ |
122
|
5 |
|
$vars = array('row', 'block', 'tp_avatars'); |
123
|
5 |
|
extract($this->dispatcher->trigger_event('vse.topicpreview.display_topic_preview', compact($vars))); |
124
|
|
|
|
125
|
5 |
|
return $block; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get topic preview text helper function |
130
|
|
|
* This handles the trimming and censoring |
131
|
|
|
* |
132
|
|
|
* @param array $row User row data |
133
|
|
|
* @param string $post The first or last post text column key |
134
|
|
|
* |
135
|
|
|
* @return string The trimmed and censored topic preview text |
136
|
|
|
*/ |
137
|
5 |
|
protected function get_text_helper($row, $post) |
138
|
|
|
{ |
139
|
|
|
// Ignore empty/unset text or when the last post is also the first (and only) post |
140
|
5 |
|
if (empty($row[$post]) || ($post === 'last_post_text' && $row['topic_first_post_id'] === $row['topic_last_post_id'])) |
141
|
5 |
|
{ |
142
|
3 |
|
return ''; |
143
|
|
|
} |
144
|
|
|
|
145
|
4 |
|
return censor_text($this->trim->trim_text($row[$post], $this->config['topic_preview_limit'])); |
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Get user avatar helper function |
150
|
|
|
* |
151
|
|
|
* @param array $row User row data |
152
|
|
|
* @param string $poster Type of poster, fp or lp |
153
|
|
|
* |
154
|
|
|
* @return string Avatar image |
155
|
|
|
*/ |
156
|
5 |
|
protected function get_user_avatar_helper($row, $poster) |
157
|
|
|
{ |
158
|
5 |
|
if (!$this->avatars_enabled()) |
159
|
5 |
|
{ |
160
|
1 |
|
return ''; |
161
|
|
|
} |
162
|
|
|
|
163
|
4 |
|
$avatar = ''; |
164
|
4 |
|
if (!empty($row[$poster . '_avatar'])) |
165
|
4 |
|
{ |
166
|
|
|
$map = array( |
167
|
3 |
|
'avatar' => $row[$poster . '_avatar'], |
168
|
3 |
|
'avatar_type' => $row[$poster . '_avatar_type'], |
169
|
3 |
|
'avatar_width' => $row[$poster . '_avatar_width'], |
170
|
3 |
|
'avatar_height' => $row[$poster . '_avatar_height'], |
171
|
3 |
|
); |
172
|
3 |
|
$avatar = phpbb_get_user_avatar($map, 'USER_AVATAR', false, true); |
|
|
|
|
173
|
3 |
|
} |
174
|
|
|
|
175
|
|
|
// If avatar string is empty, fall back to no_avatar.gif |
176
|
4 |
|
return $avatar ?: self::NO_AVATAR; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Get user's style topic preview theme |
181
|
|
|
* Fall back to no theme if expected theme not found |
182
|
|
|
* |
183
|
|
|
* @return mixed Theme name if theme file found, false otherwise |
184
|
|
|
*/ |
185
|
9 |
|
protected function get_theme() |
186
|
|
|
{ |
187
|
9 |
|
if (!empty($this->user->style['topic_preview_theme']) && file_exists($this->root_path . 'ext/vse/topicpreview/styles/all/theme/' . $this->user->style['topic_preview_theme'] . '.css')) |
188
|
9 |
|
{ |
189
|
1 |
|
return $this->user->style['topic_preview_theme']; |
190
|
|
|
} |
191
|
|
|
|
192
|
8 |
|
return false; |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths