1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2016 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\content\model\entity; |
11
|
|
|
|
12
|
|
|
use blitze\sitemaker\model\base_entity; |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @method integer get_content_id() |
16
|
|
|
* @method object set_forum_id($forum_id) |
17
|
|
|
* @method integer get_forum_id() |
18
|
|
|
* @method string get_content_name() |
19
|
|
|
* @method string get_content_langname() |
20
|
|
|
* @method object set_content_enabled($enabled) |
21
|
|
|
* @method boolean get_content_enabled() |
22
|
|
|
* @method object set_content_colour($color) |
23
|
|
|
* @method string get_content_colour() |
24
|
|
|
* @method object set_content_desc_bitfield($bitfield) |
25
|
|
|
* @method string get_content_desc_bitfield() |
26
|
|
|
* @method object set_content_desc_options($options) |
27
|
|
|
* @method integer get_content_desc_options() |
28
|
|
|
* @method object set_content_desc_uid($uid) |
29
|
|
|
* @method string get_content_desc_uid() |
30
|
|
|
* @method object set_content_view($view) |
31
|
|
|
* @method string get_content_view() |
32
|
|
|
* @method object set_comments($comments) |
33
|
|
|
* @method string get_comments() |
34
|
|
|
* @method object set_req_approval($require_approval) |
35
|
|
|
* @method boolean get_req_approval() |
36
|
|
|
* @method object set_allow_views($allow_views) |
37
|
|
|
* @method boolean get_allow_views() |
38
|
|
|
* @method object set_show_pagination($show_pagination) |
39
|
|
|
* @method boolean get_show_pagination() |
40
|
|
|
* @method object set_index_show_desc($index_show_desc) |
41
|
|
|
* @method boolean get_index_show_desc() |
42
|
|
|
* @method integer get_items_per_page() |
43
|
|
|
* @method object set_summary_tpl($summary_tpl) |
44
|
|
|
* @method object set_detail_tpl($detail_tpl) |
45
|
|
|
* @method object set_last_modified($timestamp) |
46
|
|
|
* @method integer get_last_modified() |
47
|
|
|
* @method array get_content_fields() |
48
|
|
|
* @method object set_field_types($field_types) |
49
|
|
|
* @method array get_field_types() |
50
|
|
|
* @method object set_summary_fields($summary_fields) |
51
|
|
|
* @method array get_summary_fields() |
52
|
|
|
* @method object set_detail_fields($detail_fields) |
53
|
|
|
* @method array get_detail_fields() |
54
|
|
|
* |
55
|
|
|
*/ |
56
|
|
|
final class type extends base_entity |
57
|
|
|
{ |
58
|
|
|
/** @var integer */ |
59
|
|
|
protected $content_id; |
60
|
|
|
|
61
|
|
|
/** @var integer */ |
62
|
|
|
protected $forum_id; |
63
|
|
|
|
64
|
|
|
/** @var string */ |
65
|
|
|
protected $content_name; |
66
|
|
|
|
67
|
|
|
/** @var string */ |
68
|
|
|
protected $content_langname; |
69
|
|
|
|
70
|
|
|
/** @var boolean */ |
71
|
|
|
protected $content_enabled = true; |
72
|
|
|
|
73
|
|
|
/** @var string */ |
74
|
|
|
protected $content_colour = ''; |
75
|
|
|
|
76
|
|
|
/** @var string */ |
77
|
|
|
protected $content_desc = ''; |
78
|
|
|
|
79
|
|
|
/** @var string */ |
80
|
|
|
protected $content_desc_bitfield = ''; |
81
|
|
|
|
82
|
|
|
/** @var integer */ |
83
|
|
|
protected $content_desc_options = 7; |
84
|
|
|
|
85
|
|
|
/** @var string */ |
86
|
|
|
protected $content_desc_uid = ''; |
87
|
|
|
|
88
|
|
|
/** @var string */ |
89
|
|
|
protected $content_view; |
90
|
|
|
|
91
|
|
|
/** @var string */ |
92
|
|
|
protected $content_view_settings = ''; |
93
|
|
|
|
94
|
|
|
/** @var string */ |
95
|
|
|
protected $comments = ''; |
96
|
|
|
|
97
|
|
|
/** @var string */ |
98
|
|
|
protected $comments_settings = ''; |
99
|
|
|
|
100
|
|
|
/** @var boolean */ |
101
|
|
|
protected $req_approval = false; |
102
|
|
|
|
103
|
|
|
/** @var boolean */ |
104
|
|
|
protected $allow_views = true; |
105
|
|
|
|
106
|
|
|
/** @var boolean */ |
107
|
|
|
protected $show_pagination = true; |
108
|
|
|
|
109
|
|
|
/** @var boolean */ |
110
|
|
|
protected $index_show_desc = false; |
111
|
|
|
|
112
|
|
|
/** @var integer */ |
113
|
|
|
protected $items_per_page = 10; |
114
|
|
|
|
115
|
|
|
/** @var string */ |
116
|
|
|
protected $summary_tpl = ''; |
117
|
|
|
|
118
|
|
|
/** @var string */ |
119
|
|
|
protected $detail_tpl = ''; |
120
|
|
|
|
121
|
|
|
/** @var integer */ |
122
|
|
|
protected $last_modified = 0; |
123
|
|
|
|
124
|
|
|
/** @var string */ |
125
|
|
|
protected $topic_blocks = ''; |
126
|
|
|
|
127
|
|
|
/** @var array */ |
128
|
|
|
protected $content_fields = array(); |
129
|
|
|
|
130
|
|
|
/** @var array */ |
131
|
|
|
protected $field_types = array(); |
132
|
|
|
|
133
|
|
|
/** @var array */ |
134
|
|
|
protected $summary_fields = array(); |
135
|
|
|
|
136
|
|
|
/** @var array */ |
137
|
|
|
protected $detail_fields = array(); |
138
|
|
|
|
139
|
|
|
/** @var array */ |
140
|
|
|
protected $required_fields = array('forum_id', 'content_name', 'content_langname', 'content_view'); |
141
|
|
|
|
142
|
|
|
/** @var array */ |
143
|
|
|
protected $db_fields = array( |
144
|
|
|
'forum_id', |
145
|
|
|
'content_name', |
146
|
|
|
'content_langname', |
147
|
|
|
'content_enabled', |
148
|
|
|
'content_colour', |
149
|
|
|
'content_desc', |
150
|
|
|
'content_desc_bitfield', |
151
|
|
|
'content_desc_options', |
152
|
|
|
'content_desc_uid', |
153
|
|
|
'content_view', |
154
|
|
|
'content_view_settings', |
155
|
|
|
'comments', |
156
|
|
|
'comments_settings', |
157
|
|
|
'req_approval', |
158
|
|
|
'allow_views', |
159
|
|
|
'show_pagination', |
160
|
|
|
'index_show_desc', |
161
|
|
|
'items_per_page', |
162
|
|
|
'summary_tpl', |
163
|
|
|
'detail_tpl', |
164
|
|
|
'last_modified', |
165
|
|
|
'topic_blocks', |
166
|
|
|
); |
167
|
|
|
|
168
|
|
|
/** |
169
|
24 |
|
* Set content ID |
170
|
|
|
* @param int $content_id |
171
|
24 |
|
* @return $this |
172
|
24 |
|
*/ |
173
|
24 |
|
public function set_content_id($content_id) |
174
|
24 |
|
{ |
175
|
24 |
|
if (!$this->content_id) |
176
|
|
|
{ |
177
|
|
|
$this->content_id = (int) $content_id; |
178
|
|
|
} |
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
25 |
|
* Set content name |
184
|
|
|
* @param string $name |
185
|
25 |
|
* @return $this |
186
|
25 |
|
*/ |
187
|
25 |
|
public function set_content_name($name) |
188
|
|
|
{ |
189
|
|
|
$this->content_name = str_replace(' ', '_', strtolower(trim($name))); |
190
|
|
|
$this->content_colour = substr(md5($this->content_name), 0, 6); |
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
25 |
|
* Set content display name |
196
|
|
|
* @param string $langname |
197
|
25 |
|
* @return $this |
198
|
25 |
|
*/ |
199
|
|
|
public function set_content_langname($langname) |
200
|
|
|
{ |
201
|
|
|
$this->content_langname = ucwords($langname); |
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
23 |
|
* @param string $desc |
207
|
|
|
* @param string $mode |
208
|
23 |
|
* @return $this |
209
|
|
|
*/ |
210
|
23 |
|
public function set_content_desc($desc, $mode = '') |
211
|
23 |
|
{ |
212
|
|
|
$this->content_desc = $desc; |
213
|
|
|
|
214
|
23 |
|
if ($this->content_desc && $mode === 'storage') |
215
|
|
|
{ |
216
|
|
|
generate_text_for_storage($this->content_desc, $this->content_desc_uid, $this->content_desc_bitfield, $this->content_desc_options, true, true, true); |
217
|
|
|
} |
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
3 |
|
/** |
222
|
|
|
* @param string $mode |
223
|
3 |
|
* @return string |
224
|
3 |
|
*/ |
225
|
1 |
|
public function get_content_desc($mode = 'display') |
226
|
1 |
|
{ |
227
|
|
|
if ($mode === 'edit') |
228
|
|
|
{ |
229
|
|
|
$data = generate_text_for_edit($this->content_desc, $this->content_desc_uid, $this->content_desc_options); |
230
|
3 |
|
return $data['text']; |
231
|
3 |
|
} |
232
|
|
|
else |
233
|
|
|
{ |
234
|
|
|
$parse_flags = ($this->content_desc_bitfield ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES; |
235
|
|
|
return generate_text_for_display($this->content_desc, $this->content_desc_uid, $this->content_desc_bitfield, $parse_flags); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
23 |
|
* Set content view settings |
241
|
|
|
* @param array|string $settings |
242
|
23 |
|
* @return $this |
243
|
23 |
|
*/ |
244
|
23 |
|
public function set_content_view_settings($settings) |
245
|
23 |
|
{ |
246
|
23 |
|
$this->content_view_settings = ''; |
247
|
2 |
|
if (!is_array($settings)) |
248
|
2 |
|
{ |
249
|
2 |
|
$this->content_view_settings = $settings; |
250
|
2 |
|
} |
251
|
23 |
|
else if (sizeof($settings)) |
252
|
|
|
{ |
253
|
|
|
$this->content_view_settings = json_encode($settings); |
254
|
|
|
} |
255
|
|
|
return $this; |
256
|
|
|
} |
257
|
|
|
|
258
|
3 |
|
/** |
259
|
|
|
* Get content view settings |
260
|
3 |
|
* @return array |
261
|
|
|
*/ |
262
|
|
|
public function get_content_view_settings() |
263
|
|
|
{ |
264
|
|
|
return ($this->content_view_settings) ? json_decode($this->content_view_settings, true) : array(); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
23 |
|
* Set comment settings |
269
|
|
|
* @param array|string $settings |
270
|
23 |
|
* @return $this |
271
|
23 |
|
*/ |
272
|
|
|
public function set_comments_settings($settings) |
273
|
|
|
{ |
274
|
|
|
$this->comments_settings = ''; |
275
|
|
|
if (!is_array($settings)) |
276
|
|
|
{ |
277
|
3 |
|
$this->comments_settings = $settings; |
278
|
|
|
} |
279
|
3 |
|
else if (sizeof($settings)) |
280
|
|
|
{ |
281
|
|
|
$this->comments_settings = json_encode($settings); |
282
|
|
|
} |
283
|
|
|
return $this; |
284
|
|
|
} |
285
|
3 |
|
|
286
|
|
|
/** |
287
|
3 |
|
* Get comment type settings |
288
|
|
|
* @return array |
289
|
|
|
*/ |
290
|
|
|
public function get_comments_settings() |
291
|
|
|
{ |
292
|
|
|
return ($this->comments_settings) ? json_decode($this->comments_settings, true) : array(); |
293
|
23 |
|
} |
294
|
|
|
|
295
|
23 |
|
/** |
296
|
|
|
* Set Items per page. Must be greater than zero |
297
|
23 |
|
* @param int $items_per_page |
298
|
23 |
|
* @return $this |
299
|
|
|
*/ |
300
|
23 |
|
public function set_items_per_page($items_per_page) |
301
|
23 |
|
{ |
302
|
|
|
$this->items_per_page = ($items_per_page) ? $items_per_page : 1; |
303
|
23 |
|
return $this; |
304
|
23 |
|
} |
305
|
|
|
|
306
|
23 |
|
/** |
307
|
23 |
|
* @return string |
308
|
23 |
|
*/ |
309
|
|
|
public function get_summary_tpl() |
310
|
|
|
{ |
311
|
|
|
return htmlspecialchars_decode($this->summary_tpl); |
312
|
|
|
} |
313
|
|
|
|
314
|
24 |
|
/** |
315
|
|
|
* @return string |
316
|
24 |
|
*/ |
317
|
24 |
|
public function get_detail_tpl() |
318
|
|
|
{ |
319
|
|
|
return htmlspecialchars_decode($this->detail_tpl); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
3 |
|
* @param array $content_fields |
324
|
|
|
*/ |
325
|
3 |
|
public function set_content_fields(array $content_fields) |
326
|
|
|
{ |
327
|
|
|
$fields = strtoupper(join('|', array_keys($content_fields))); |
328
|
|
|
|
329
|
|
|
$field_types = $summary_fields = $detail_fields = array(); |
330
|
|
|
$this->parse_content_fields($content_fields, $field_types, $summary_fields, $detail_fields); |
331
|
|
|
|
332
|
|
|
$summary_fields = $this->get_template_fields($summary_fields, $this->summary_tpl, $fields); |
333
|
|
|
$detail_fields = $this->get_template_fields($detail_fields, $this->detail_tpl, $fields); |
334
|
|
|
|
335
|
23 |
|
$this->summary_fields = array_intersect_key($field_types, array_flip($summary_fields)); |
336
|
|
|
$this->detail_fields = array_intersect_key($field_types, array_flip($detail_fields)); |
337
|
23 |
|
|
338
|
|
|
$this->content_fields = $content_fields; |
339
|
23 |
|
$this->field_types = $field_types; |
340
|
|
|
} |
341
|
23 |
|
|
342
|
23 |
|
/** |
343
|
15 |
|
* @param array|string $topic_blocks |
344
|
15 |
|
* @return $this |
345
|
|
|
*/ |
346
|
23 |
|
public function set_topic_blocks($topic_blocks) |
347
|
23 |
|
{ |
348
|
15 |
|
$this->topic_blocks = is_array($topic_blocks) ? join(',', array_filter($topic_blocks)) : $topic_blocks; |
349
|
15 |
|
return $this; |
350
|
23 |
|
} |
351
|
23 |
|
|
352
|
|
|
/** |
353
|
|
|
* @return array |
354
|
|
|
*/ |
355
|
|
|
public function get_topic_blocks() |
356
|
|
|
{ |
357
|
|
|
return array_filter(explode(',', $this->topic_blocks)); |
358
|
|
|
} |
359
|
23 |
|
|
360
|
|
|
/** |
361
|
|
|
* @param array $content_fields |
362
|
23 |
|
* @param array $field_types |
363
|
|
|
* @param array $summary_fields |
364
|
|
|
* @param array $detail_fields |
365
|
|
|
* @return void |
366
|
|
|
*/ |
367
|
23 |
|
private function parse_content_fields(array $content_fields, array &$field_types, array &$summary_fields, array &$detail_fields) |
368
|
|
|
{ |
369
|
|
|
foreach ($content_fields as $field => $data) |
370
|
|
|
{ |
371
|
|
|
$field_types[$field] = $data['field_type']; |
372
|
|
|
|
373
|
|
|
if ($data['field_summary_show']) |
374
|
|
|
{ |
375
|
|
|
$summary_fields[] = $field; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
if ($data['field_detail_show']) |
379
|
|
|
{ |
380
|
|
|
$detail_fields[] = $field; |
381
|
|
|
} |
382
|
|
|
} |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* @param array $view_fields |
387
|
|
|
* @param string $template |
388
|
|
|
* @param string $fields |
389
|
|
|
* @return array |
390
|
|
|
*/ |
391
|
|
|
private function get_template_fields(array $view_fields, $template, $fields) |
392
|
|
|
{ |
393
|
|
|
if ($template) |
394
|
|
|
{ |
395
|
|
|
preg_match_all("/\{($fields)\}|\{\{\s($fields)\s\}\}/", $template, $view_fields); |
396
|
|
|
$view_fields = array_map('strtolower', array_pop($view_fields)); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
return $view_fields; |
400
|
|
|
} |
401
|
|
|
} |
402
|
|
|
|
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