1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Topic Preview |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2013, 2016 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\cache\driver\driver_interface as cache_driver; |
|
|
|
|
14
|
|
|
use phpbb\config\config; |
|
|
|
|
15
|
|
|
use phpbb\db\driver\driver_interface as db_driver; |
|
|
|
|
16
|
|
|
use phpbb\extension\manager; |
|
|
|
|
17
|
|
|
use phpbb\request\request; |
|
|
|
|
18
|
|
|
|
19
|
|
|
class settings |
20
|
|
|
{ |
21
|
|
|
/** @var string Default no theme value */ |
22
|
|
|
const NO_THEME = 'no'; |
23
|
|
|
|
24
|
|
|
/** @var string Default theme value */ |
25
|
|
|
const DEFAULT_THEME = 'light'; |
26
|
|
|
|
27
|
|
|
/** @var cache_driver */ |
28
|
|
|
protected $cache; |
29
|
|
|
|
30
|
|
|
/** @var config */ |
31
|
|
|
protected $config; |
32
|
|
|
|
33
|
|
|
/** @var db_driver */ |
34
|
|
|
protected $db; |
35
|
|
|
|
36
|
|
|
/** @var manager */ |
37
|
|
|
protected $ext_manager; |
38
|
|
|
|
39
|
|
|
/** @var request */ |
40
|
|
|
protected $request; |
41
|
|
|
|
42
|
|
|
/** @var string */ |
43
|
|
|
protected $phpbb_root_path; |
44
|
|
|
|
45
|
|
|
/** @var string */ |
46
|
|
|
protected $u_action; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Constructor |
50
|
|
|
* |
51
|
|
|
* @param cache_driver $cache |
52
|
|
|
* @param config $config |
53
|
|
|
* @param db_driver $db |
54
|
|
|
* @param manager $phpbb_ext_manager |
55
|
|
|
* @param request $request |
56
|
|
|
* @param string $phpbb_root_path |
57
|
|
|
*/ |
58
|
3 |
|
public function __construct(cache_driver $cache, config $config, db_driver $db, manager $phpbb_ext_manager, request $request, $phpbb_root_path) |
59
|
|
|
{ |
60
|
3 |
|
$this->cache = $cache; |
61
|
3 |
|
$this->config = $config; |
62
|
3 |
|
$this->db = $db; |
63
|
3 |
|
$this->ext_manager = $phpbb_ext_manager; |
64
|
3 |
|
$this->request = $request; |
65
|
3 |
|
$this->phpbb_root_path = $phpbb_root_path; |
66
|
3 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Display the settings with the current config values |
70
|
|
|
* |
71
|
|
|
* @param string $u_action |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
1 |
|
public function display_settings($u_action) |
76
|
|
|
{ |
77
|
|
|
return array( |
78
|
1 |
|
'TOPIC_PREVIEW_LIMIT' => $this->config['topic_preview_limit'], |
79
|
1 |
|
'TOPIC_PREVIEW_WIDTH' => $this->config['topic_preview_width'], |
80
|
1 |
|
'TOPIC_PREVIEW_DELAY' => $this->config['topic_preview_delay'], |
81
|
1 |
|
'TOPIC_PREVIEW_DRIFT' => $this->config['topic_preview_drift'], |
82
|
1 |
|
'S_TOPIC_PREVIEW_AVATARS' => $this->config['topic_preview_avatars'], |
83
|
1 |
|
'S_TOPIC_PREVIEW_LAST_POST' => $this->config['topic_preview_last_post'], |
84
|
1 |
|
'TOPIC_PREVIEW_STRIP' => $this->config['topic_preview_strip_bbcodes'], |
85
|
1 |
|
'TOPIC_PREVIEW_STYLES' => $this->get_styles(), |
86
|
1 |
|
'TOPIC_PREVIEW_THEMES' => $this->get_themes(), |
87
|
1 |
|
'TOPIC_PREVIEW_DEFAULT' => self::DEFAULT_THEME, |
88
|
1 |
|
'TOPIC_PREVIEW_NO_THEME' => self::NO_THEME, |
89
|
1 |
|
'U_ACTION' => $u_action, |
90
|
1 |
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set the settings data from the form to the database |
95
|
|
|
*/ |
96
|
1 |
|
public function set_settings() |
97
|
|
|
{ |
98
|
1 |
|
$this->config->set('topic_preview_limit', abs($this->request->variable('topic_preview_limit', 0))); // abs() no negative values |
99
|
1 |
|
$this->config->set('topic_preview_width', abs($this->request->variable('topic_preview_width', 0))); // abs() no negative values |
100
|
1 |
|
$this->config->set('topic_preview_delay', abs($this->request->variable('topic_preview_delay', 0))); // abs() no negative values |
101
|
1 |
|
$this->config->set('topic_preview_drift', $this->request->variable('topic_preview_drift', 0)); |
102
|
1 |
|
$this->config->set('topic_preview_avatars', $this->request->variable('topic_preview_avatars', 0)); |
103
|
1 |
|
$this->config->set('topic_preview_last_post', $this->request->variable('topic_preview_last_post', 0)); |
104
|
1 |
|
$this->config->set('topic_preview_strip_bbcodes', $this->request->variable('topic_preview_strip_bbcodes', '')); |
105
|
|
|
|
106
|
1 |
|
$styles = $this->get_styles(); |
107
|
1 |
|
foreach ($styles as $row) |
108
|
|
|
{ |
109
|
1 |
|
$this->set_style_theme($row['style_id'], $this->request->variable('style_' . $row['style_id'], '')); |
110
|
1 |
|
} |
111
|
1 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Update topic_preview_theme setting in the styles table |
115
|
|
|
* |
116
|
|
|
* @param int $style_id Identifier of the board style |
117
|
|
|
* @param string $theme Name of the selected theme |
118
|
|
|
*/ |
119
|
1 |
|
protected function set_style_theme($style_id, $theme) |
120
|
|
|
{ |
121
|
1 |
|
$sql = 'UPDATE ' . STYLES_TABLE . " |
|
|
|
|
122
|
1 |
|
SET topic_preview_theme = '" . $this->db->sql_escape($theme) . "' |
123
|
1 |
|
WHERE style_id = " . (int) $style_id; |
124
|
|
|
|
125
|
1 |
|
$this->db->sql_query($sql); |
126
|
|
|
|
127
|
1 |
|
$this->cache->destroy('sql', STYLES_TABLE); |
128
|
1 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get style data from the styles table |
132
|
|
|
* |
133
|
|
|
* @return array Style data |
134
|
|
|
*/ |
135
|
2 |
|
protected function get_styles() |
136
|
|
|
{ |
137
|
|
|
$sql = 'SELECT style_id, style_name, topic_preview_theme |
138
|
2 |
|
FROM ' . STYLES_TABLE . ' |
|
|
|
|
139
|
2 |
|
WHERE style_active = 1'; |
140
|
2 |
|
$result = $this->db->sql_query($sql); |
141
|
|
|
|
142
|
2 |
|
$rows = $this->db->sql_fetchrowset($result); |
143
|
2 |
|
$this->db->sql_freeresult($result); |
144
|
|
|
|
145
|
2 |
|
return $rows; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Get file names from Topic Preview's CSS files |
150
|
|
|
* |
151
|
|
|
* @return array File name data |
152
|
|
|
*/ |
153
|
1 |
|
protected function get_themes() |
154
|
|
|
{ |
155
|
1 |
|
$finder = $this->ext_manager->get_finder(); |
156
|
|
|
|
157
|
|
|
// Find css files in ext/vse/topicpreview/styles/all/theme/ |
158
|
|
|
$themes = $finder |
159
|
1 |
|
->extension_suffix('.css') |
160
|
1 |
|
->extension_directory('/styles/all/theme') |
161
|
1 |
|
->find_from_extension('topicpreview', $this->phpbb_root_path . 'ext/vse/topicpreview/'); |
162
|
|
|
|
163
|
|
|
// Get just basenames of array keys |
164
|
1 |
|
$themes = array_map(function ($value) { |
165
|
1 |
|
return basename($value, '.css'); |
166
|
1 |
|
}, array_keys($themes)); |
167
|
|
|
|
168
|
|
|
// Add option for native browser tooltip (aka no theme) |
169
|
1 |
|
$themes[] = self::NO_THEME; |
170
|
|
|
|
171
|
1 |
|
return $themes; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
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