-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathitem.php
More file actions
581 lines (491 loc) · 14.7 KB
/
item.php
File metadata and controls
581 lines (491 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
<?php
/**
*
* This file is part of the phpBB Customisation Database package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\titania\controller\manage\queue;
use phpbb\titania\contribution\type\collection as type_collection;
use phpbb\titania\ext;
class item extends \phpbb\titania\controller\manage\base
{
/** @var \phpbb\titania\tags */
protected $tags;
/** @var \phpbb\titania\message\message */
protected $message;
/** @var \phpbb\titania\posting */
protected $posting;
/** @var int */
protected $id;
/** @var \titania_queue */
protected $queue;
/** @var \titania_contribution */
protected $contrib;
/** @var \titania_revision */
protected $revision;
/** @var bool */
protected $is_author;
/**
* Constructor
*
* @param \phpbb\auth\auth $auth
* @param \phpbb\config\config $config
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\template\template $template
* @param \phpbb\user $user
* @param \phpbb\titania\cache\service $cache
* @param \phpbb\titania\controller\helper $helper
* @param type_collection $types
* @param \phpbb\request\request $request
* @param \phpbb\titania\config\config $ext_config
* @param \phpbb\titania\display $display
* @param \phpbb\titania\tags $tags
* @param \phpbb\titania\message\message $message
* @param \phpbb\titania\posting $posting
*/
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\titania\cache\service $cache, \phpbb\titania\controller\helper $helper, type_collection $types, \phpbb\request\request $request, \phpbb\titania\config\config $ext_config, \phpbb\titania\display $display, \phpbb\titania\tags $tags, \phpbb\titania\message\message $message, \phpbb\titania\posting $posting)
{
parent::__construct($auth, $config, $db, $template, $user, $cache, $helper, $types, $request, $ext_config, $display);
$this->tags = $tags;
$this->message = $message;
$this->posting = $posting;
}
/**
* Display queue item.
*
* @param int $id Queue item id.
* @return \Symfony\Component\HttpFoundation\Response
*/
public function display_item($id)
{
$this->load_item($id);
// Check auth
if (!$this->check_auth())
{
return $this->helper->needs_auth();
}
// Create type link information for tags (e.g., make sure the tag hyperlinks back to the type)
$queue_type = $this->types->get($this->queue->queue_type);
$queue_type_name = $queue_type->name;
$queue_type_url = $queue_type->url;
// Display the main queue item
$data = \queue_overlord::display_queue_item($this->id);
// Display the posts in the queue (after the posting helper acts)
\posts_overlord::display_topic_complete($data['topic']);
$this->display->assign_global_vars();
$this->generate_navigation('queue');
$tag = $this->request->variable('tag', 0);
// Make sure the item category is added to the breadcrumb.
// If the user clicks on a tag (e.g., a tag like "New" or "All")
// then this part ensures it gets added to the navigation breadcrumbs
if ($tag)
{
// Add tag to Breadcrumbs
$this->display->generate_breadcrumbs(array(
$this->tags->get_tag_name($tag) => $this->queue->get_url(false, array('tag' => $tag), [$queue_type_name => $queue_type_url]),
));
}
return $this->helper->render('manage/queue.html', \queue_overlord::$queue[$this->id]['topic_subject']);
}
/**
* Delegates requested action to appropriate method.
*
* @param int $id Queue item id.
* @param string $action Requested action.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function item_action($id, $action)
{
$this->load_item($id);
if (!$this->check_auth($action))
{
return $this->helper->needs_auth();
}
$this->display->assign_global_vars();
$this->generate_navigation('queue');
$valid_action = false;
$check_actions = array(
'in_progress',
'no_progress',
'tested',
'not_tested',
'rebuild',
);
if (in_array($action, $check_actions) && !check_link_hash($this->request->variable('hash', ''), 'queue_action'))
{
return $this->helper->error('PAGE_REQUEST_INVALID');
}
// Only allow these actions to run if the queue item is still open.
if ($this->queue->queue_status > 0)
{
$valid_action = true;
switch ($action)
{
case 'in_progress':
$this->queue->in_progress();
break;
case 'no_progress':
$this->queue->no_progress();
break;
case 'tested':
$this->queue->change_tested_mark(true);
break;
case 'not_tested':
$this->queue->change_tested_mark(false);
break;
case 'move':
$this->move();
break;
case 'allow_author_repack' :
return $this->allow_author_repack();
break;
case 'approve':
return $this->approve();
break;
case 'deny':
return $this->deny();
break;
default:
$valid_action = false;
}
}
switch ($action)
{
case 'rebuild':
$this->queue->update_first_queue_post();
break;
case 'reply':
case 'quote':
case 'edit':
case 'quick_edit':
case 'delete':
case 'undelete':
return $this->posting($action);
break;
default:
if (!$valid_action)
{
return $this->helper->error('INVALID_ACTION', 404);
}
}
redirect($this->queue->get_url());
}
/**
* Load queue item.
*
* @param int $id Queue item id.
* @throws \Exception Throws exception if no item found.
* @return null
*/
protected function load_item($id)
{
$this->id = (int) $id;
$this->queue = \queue_overlord::get_queue_object($this->id, true);
if (!$this->queue)
{
throw new \Exception($this->user->lang['NO_QUEUE_ITEM']);
}
$this->contrib = \contribs_overlord::get_contrib_object($this->queue->contrib_id, true);
$this->revision = $this->queue->get_revision();
$this->is_author = $this->contrib->is_author || $this->contrib->is_active_coauthor || $this->contrib->is_coauthor;
}
/**
* Check user's authorization.
*
* @param bool|string Optional action to check auth for.
* @return bool Returns true if user is authorized, false otherwise.
*/
protected function check_auth($action = false)
{
if (!$this->contrib->type->acl_get('view'))
{
return false;
}
switch ($action)
{
case 'approve':
// Do not allow to approve your own contributions, except for founders...
if (!$this->ext_config->allow_self_validation && $this->user->data['user_type'] != USER_FOUNDER && $this->is_author)
{
return false;
}
case 'allow_author_repack':
case 'deny' :
return $this->contrib->type->acl_get('validate');
break;
default:
return true;
}
}
/**
* Posting action.
*
* @param string $action
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
protected function posting($action)
{
$this->posting->parent_type = $this->queue->queue_type;
return $this->posting->act(
$this->contrib,
$action,
$this->queue->queue_topic_id,
'manage/queue_post.html',
$this->id,
false,
ext::TITANIA_QUEUE,
$this->helper->get_current_url()
);
}
/**
* Allow author to repack revision action.
*
* @return null
*/
protected function allow_author_repack()
{
$topic = $this->queue->get_queue_discussion_topic();
$post = new \titania_post(ext::TITANIA_QUEUE_DISCUSSION, $topic);
$post->__set_array(array(
'post_subject' => 'Re: ' . $post->topic->topic_subject,
));
// Load the message object
$message_object = $this->get_message($post);
// Submit check...handles running $post->post_data() if required
$submit = $message_object->submit_check();
if ($submit)
{
$this->queue->allow_author_repack = true;
$repack_url = $this->contrib->get_url('revision', array(
'page' => 'repack',
'id' => $this->queue->revision_id,
));
$for_edit = $post->generate_text_for_edit();
$post->post_text = $for_edit['message'] . "\n\n
[url=" . $repack_url . ']' .
$this->user->lang['AUTHOR_REPACK_LINK'] . '[/url]';
$post->generate_text_for_storage($for_edit['allow_bbcode'], $for_edit['allow_smilies'], $for_edit['allow_urls']);
$post->submit();
$this->queue->submit();
$this->queue->topic_reply('QUEUE_REPLY_ALLOW_REPACK');
$this->queue->submit();
redirect($this->queue->get_url());
}
$message_object->display();
// Common stuff
$this->template->assign_vars(array(
'S_POST_ACTION' => $this->helper->get_current_url(),
'L_POST_A' => $this->user->lang['DISCUSSION_REPLY_MESSAGE'],
));
return $this->helper->render('manage/queue_post.html', 'DISCUSSION_REPLY_MESSAGE');
}
/**
* Move action.
*
* @return null
*/
protected function move()
{
$tags = $this->cache->get_tags(ext::TITANIA_QUEUE);
if (check_link_hash($this->request->variable('hash', ''), 'quick_actions') || confirm_box(true))
{
$new_tag = $this->request->variable('id', 0);
if (!isset($tags[$new_tag]))
{
return $this->helper->error('NO_TAG');
}
$this->queue->move($new_tag, $this->tags);
}
else
{
// Generate the list of tags we can move it to
$extra = '<select name="id">';
foreach ($tags as $tag_id => $row)
{
$extra .= '<option value="' . $tag_id . '">' . $this->user->lang($row['tag_field_name']) . '</option>';
}
$extra .= '</select>';
$this->template->assign_var('CONFIRM_EXTRA', $extra);
confirm_box(false, 'MOVE_QUEUE');
}
}
/**
* Approve action.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function approve()
{
$public_notes = $this->request->variable('public_notes', '', true);
$post_as_robot = $this->request->variable('post_as_robot', 1);
if ($this->validate('approve'))
{
$robot_user = $post_as_robot ? $this->get_robot_user() : false;
$robot_user_id = $robot_user ? (int) $robot_user['user_id'] : 0;
$this->queue->approve($public_notes, $robot_user_id);
// Reload contribution with new data.
$this->contrib->load();
$this->contrib->type->approve($this->contrib, $this->queue, $this->request);
$this->cache->destroy('sql', TITANIA_CONTRIBS_TABLE);
redirect($this->queue->get_url());
}
if ($this->contrib->type->update_public)
{
$this->template->assign_vars(array(
'PUBLIC_MESSAGE' => $public_notes,
'S_PUBLIC_NOTES' => true,
));
if ($this->request->is_set_post('preview'))
{
$this->template->assign_vars(array(
'PUBLIC_PREVIEW_SUBJECT' => 'Re: ' . $this->contrib->contrib_name,
'PUBLIC_PREVIEW_MESSAGE' => $this->get_public_notes_preview($public_notes),
));
}
}
return $this->helper->render(
'manage/queue_validate.html',
$this->user->lang['APPROVE_QUEUE'] . ' - ' . $this->contrib->contrib_name
);
}
/**
* Deny action.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function deny()
{
$post_as_robot = $this->request->variable('post_as_robot', 1);
if ($this->validate('deny'))
{
$robot_user = $post_as_robot ? $this->get_robot_user() : false;
$robot_user_id = $robot_user ? (int) $robot_user['user_id'] : 0;
$this->queue->deny($robot_user_id);
$this->contrib->type->deny($this->contrib, $this->queue, $this->request);
redirect($this->queue->get_url());
}
return $this->helper->render(
'manage/queue_validate.html',
$this->user->lang['DENY_QUEUE'] . ' - ' . $this->contrib->contrib_name
);
}
/**
* Common approval/denial message handler.
*
* @param string $action Action: approve|deny
* @return bool Returns true if message was submmited properly.
*/
protected function validate($action)
{
$this->queue->message_fields_prefix = 'message_validation';
$message = $this->get_message($this->queue);
$error = array();
if ($message->submit_check())
{
// Check form key
if (($form_key_error = $message->validate_form_key()) !== false)
{
$error[] = $form_key_error;
}
if (empty($error))
{
return true;
}
}
$message->display();
$this->contrib->type->display_validation_options($action, $this->request, $this->template);
$this->display_topic_review();
$post_as_robot = $this->request->variable('post_as_robot', 1);
$robot_user = $this->get_robot_user();
$robot_name = $robot_user ? $robot_user['username'] : '';
$this->template->assign_vars(array(
'ERROR' => implode('<br />', $error),
'L_TOPIC_REVIEW' => $this->user->lang['QUEUE_REVIEW'],
'TOPIC_TITLE' => $this->contrib->contrib_name,
'PAGE_TITLE_EXPLAIN' => $this->user->lang[strtoupper($action) . '_QUEUE_CONFIRM'],
'S_CONFIRM_ACTION' => $this->queue->get_url($action),
'S_SHOW_POST_AS_OPTION' => (bool) $robot_name,
'POST_AS_ROBOT' => $post_as_robot,
'ROBOT_NAME' => $robot_name,
'POST_AS_LABEL' => $this->user->lang['POST_AS_' . strtoupper($action)],
));
return false;
}
/**
* Get the validated robot user row, or false if forum_robot is unset or resolves to the anonymous user.
*
* @return array|false
*/
protected function get_robot_user()
{
if (empty($this->contrib->type->forum_robot))
{
return false;
}
$robot_user = \users_overlord::get_user($this->contrib->type->forum_robot, false, true);
return ($robot_user && $robot_user['user_id'] != ANONYMOUS) ? $robot_user : false;
}
/**
* Get public notes preview.
*
* @param string $notes
* @return string
*/
protected function get_public_notes_preview($notes)
{
$preview = $this->user->lang(
$this->contrib->type->update_public,
$this->revision->revision_version
);
if ($notes)
{
$preview .= $this->user->lang($this->contrib->type->update_public . '_NOTES', $notes);
}
$uid = $bitfield = $options = false;
generate_text_for_storage($preview, $uid, $bitfield, $options, true, true, true);
return generate_text_for_display($preview, $uid, $bitfield, $options);
}
/**
* Get message object.
*
* @param mixed $object Parent object receiving the message.
* @return \phpbb\titania\message\message
*/
protected function get_message($object)
{
$this->message
->set_parent($object)
->set_auth(array(
'bbcode' => $this->auth->acl_get('u_titania_bbcode'),
'smilies' => $this->auth->acl_get('u_titania_smilies'),
))
->set_settings(array(
'display_subject' => false,
))
;
return $this->message;
}
/**
* Display queue topic review.
*
* @return null
*/
protected function display_topic_review()
{
// Setup the sort tool
$topic_sort = \posts_overlord::build_sort();
$topic_sort->set_defaults(false, false, 'd');
// Load the topic
$topic = new \titania_topic;
$topic->load($this->queue->queue_topic_id);
// Display the posts for review
\posts_overlord::display_topic($topic, $topic_sort);
}
}