-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathqueue.php
More file actions
943 lines (783 loc) · 27.6 KB
/
queue.php
File metadata and controls
943 lines (783 loc) · 27.6 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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
<?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.
*
*/
use phpbb\titania\access;
use phpbb\titania\ext;
use phpbb\titania\message\message;
/**
* Class to abstract titania queue
* @package Titania
*/
class titania_queue extends \phpbb\titania\entity\message_base
{
/**
* SQL Table
*
* @var string
*/
protected $sql_table = TITANIA_QUEUE_TABLE;
/**
* SQL identifier field
*
* @var string
*/
protected $sql_id_field = 'queue_id';
/**
* Object type (for message tool)
*
* @var string
*/
protected $object_type = ext::TITANIA_QUEUE;
/** @var \phpbb\titania\controller\helper */
protected $controller_helper;
/** @var \phpbb\user */
protected $user;
/** @var \phpbb\titania\subscriptions */
protected $subscriptions;
public function __construct()
{
// Configure object properties
$this->object_config = array_merge($this->object_config, array(
'queue_id' => array('default' => 0),
'revision_id' => array('default' => 0),
'contrib_id' => array('default' => 0),
'submitter_user_id' => array('default' => (int) phpbb::$user->data['user_id']),
'queue_topic_id' => array('default' => 0),
'queue_allow_repack' => array('default' => 1),
'queue_type' => array('default' => 0), // contrib type
'queue_status' => array('default' => ext::TITANIA_QUEUE_HIDE), // Uses either TITANIA_QUEUE_NEW or one of the tags for the queue status from the DB
'queue_submit_time' => array('default' => titania::$time),
'queue_close_time' => array('default' => 0),
'queue_close_user' => array('default' => 0),
'queue_progress' => array('default' => 0), // User_id of whoever marked this as in progress
'queue_progress_time' => array('default' => 0),
'queue_notes' => array('default' => '', 'message_field' => 'message'),
'queue_notes_bitfield' => array('default' => '', 'message_field' => 'message_bitfield'),
'queue_notes_uid' => array('default' => '', 'message_field' => 'message_uid'),
'queue_notes_options' => array('default' => 7, 'message_field' => 'message_options'),
'validation_notes' => array('default' => '', 'message_field' => 'message_validation'),
'validation_notes_bitfield' => array('default' => '', 'message_field' => 'message_validation_bitfield'),
'validation_notes_uid' => array('default' => '', 'message_field' => 'message_validation_uid'),
'validation_notes_options' => array('default' => 7, 'message_field' => 'message_validation_options'),
'mpv_results' => array('default' => ''),
'mpv_results_bitfield' => array('default' => ''),
'mpv_results_uid' => array('default' => ''),
'automod_results' => array('default' => ''),
'tv_results' => array('default' => ''),
'allow_author_repack' => array('default' => false),
'queue_tested' => array('default' => false),
));
$this->db = phpbb::$container->get('dbal.conn');
$this->controller_helper = phpbb::$container->get('phpbb.titania.controller.helper');
$this->user = phpbb::$container->get('user');
$this->subscriptions = phpbb::$container->get('phpbb.titania.subscriptions');
}
public function submit($update_first_post = true)
{
if (!$this->queue_id)
{
$this->user->add_lang_ext('phpbb/titania', 'manage');
$sql = 'SELECT c.contrib_id, c.contrib_name_clean, c.contrib_name, c.contrib_type, r.revision_version
FROM ' . TITANIA_CONTRIBS_TABLE . ' c, ' . TITANIA_REVISIONS_TABLE . ' r
WHERE r.revision_id = ' . (int) $this->revision_id . '
AND c.contrib_id = r.contrib_id';
$result = phpbb::$db->sql_query($sql);
$row = phpbb::$db->sql_fetchrow($result);
phpbb::$db->sql_freeresult($result);
if (!$row)
{
trigger_error('NO_CONTRIB');
}
$this->queue_type = $row['contrib_type'];
// Submit here first to make sure we have a queue_id for the topic url
parent::submit();
// Is there a queue discussion topic? If not we should create one
$this->get_queue_discussion_topic();
$this->update_first_queue_post(phpbb::$user->lang['VALIDATION'] . ' - ' . $row['contrib_name'] . ' - ' . $row['revision_version']);
}
else if ($update_first_post)
{
$this->update_first_queue_post();
}
parent::submit();
}
/**
* Rebuild (or create) the first post in the queue topic
*/
public function update_first_queue_post($post_subject = false)
{
$this->user->add_lang_ext('phpbb/titania', 'manage');
if (!$this->queue_topic_id)
{
$sql = 'SELECT contrib_type FROM ' . TITANIA_CONTRIBS_TABLE . '
WHERE contrib_id = ' . $this->contrib_id;
phpbb::$db->sql_query($sql);
$contrib_type = phpbb::$db->sql_fetchfield('contrib_type');
phpbb::$db->sql_freeresult();
// Create the topic
$post = new titania_post(ext::TITANIA_QUEUE);
$post->post_access = access::TEAM_LEVEL;
$post->topic->parent_id = $this->queue_id;
$post->topic->topic_category = $contrib_type;
$post->topic->topic_url = serialize(array('id' => $this->queue_id));
}
else
{
// Load the first post
$topic = new titania_topic;
$topic->topic_id = $this->queue_topic_id;
$topic->load();
$post = new titania_post($topic->topic_type, $topic, $topic->topic_first_post_id);
$post->load();
}
if ($post_subject)
{
$post->post_subject = $post_subject;
}
$post->post_user_id = $this->submitter_user_id;
$post->post_time = $this->queue_submit_time;
$revision = $this->get_revision();
// Reset the post text
$post->post_text = '';
// Queue Discussion Link
$queue_topic = $this->get_queue_discussion_topic();
$post->post_text .= '[url=' . $queue_topic->get_url() . ']' . phpbb::$user->lang['QUEUE_DISCUSSION_TOPIC'] . "[/url]\n\n";
if ($revision->revision_status == ext::TITANIA_REVISION_ON_HOLD)
{
$post->post_text .= '<strong>' . phpbb::$user->lang['REVISION_FOR_NEXT_PHPBB'] . "</strong>\n\n";
}
// Put text saying whether repacking is allowed or not
$post->post_text .= phpbb::$user->lang[(($this->queue_allow_repack) ? 'QUEUE_REPACK_ALLOWED' : 'QUEUE_REPACK_NOT_ALLOWED')] . "\n\n";
// Add the queue notes
if ($this->queue_notes)
{
$queue_notes = $this->queue_notes;
message::decode($queue_notes, $this->queue_notes_uid);
$post->post_text .= '[quote="' . users_overlord::get_user($this->submitter_user_id, 'username', true) . '"]' . $queue_notes . "[/quote]\n";
}
// Add the MPV results
if ($this->mpv_results)
{
$mpv_results = $this->mpv_results;
message::decode($mpv_results, $this->mpv_results_uid);
$post->post_text .= '[quote="' . phpbb::$user->lang['VALIDATION_PV'] . '"]' . $mpv_results . "[/quote]\n";
}
// Translation Validator
if ($this->tv_results)
{
$post->post_text .= '[quote="' . phpbb::$user->lang['VALIDATION_TV'] . '"][code]' . $this->tv_results . "[/code][/quote]\n";
}
// Prevent errors from different configurations
phpbb::$config['min_post_chars'] = 1;
phpbb::$config['max_post_chars'] = 0;
$this->forum_queue_update_first_queue_post($post);
// Store the post
$post->generate_text_for_storage(true, true, true);
$post->submit();
$this->queue_topic_id = $post->topic_id;
}
/**
* Reply to the queue topic with a message
*
* @param string $message
* @param bool $teams_only true to set to access level of teams
* @param int $post_user_id User ID to use for the post (defaults to current user)
* @return \titania_post Returns post object.
*/
public function topic_reply($message, $teams_only = true, $post_user_id = 0)
{
$this->user->add_lang_ext('phpbb/titania', 'manage');
$message = (isset(phpbb::$user->lang[$message])) ? phpbb::$user->lang[$message] : $message;
$post = new titania_post(ext::TITANIA_QUEUE, $this->queue_topic_id);
$post->__set_array(array(
'post_subject' => 'Re: ' . $post->topic->topic_subject,
'post_text' => $message,
));
if ($teams_only)
{
$post->post_access = access::TEAM_LEVEL;
}
if ($post_user_id)
{
$post->post_user_id = (int) $post_user_id;
}
$post->parent_contrib_type = $this->queue_type;
$post->generate_text_for_storage(true, true, true);
$post->submit();
return $post;
}
/**
* Reply to the discussion topic with a message
*
* @param string $message
* @param bool $teams_only true to set to access level of teams
* @param int $post_user_id
*/
public function discussion_reply($message, $teams_only = false, $post_user_id = 0)
{
$this->user->add_lang_ext('phpbb/titania', 'manage');
$message = (isset(phpbb::$user->lang[$message])) ? phpbb::$user->lang[$message] : $message;
$topic = $this->get_queue_discussion_topic();
$post = new titania_post(ext::TITANIA_QUEUE_DISCUSSION, $topic);
$post->__set_array(array(
'post_subject' => 'Re: ' . $post->topic->topic_subject,
'post_text' => $message,
));
if ($teams_only)
{
$post->post_access = access::TEAM_LEVEL;
}
if ($post_user_id)
{
$post->post_user_id = (int) $post_user_id;
}
$post->parent_contrib_type = $this->queue_type;
$post->generate_text_for_storage(true, true, true);
$post->submit();
}
public function delete()
{
$this->trash_queue_topic();
$post = new titania_post;
// Remove posts and topic
$sql = 'SELECT post_id FROM ' . TITANIA_POSTS_TABLE . '
WHERE topic_id = ' . (int) $this->queue_topic_id;
$result = phpbb::$db->sql_query($sql);
while ($row = phpbb::$db->sql_fetchrow($result))
{
$post->post_id = $row['post_id'];
$post->hard_delete();
}
phpbb::$db->sql_freeresult($result);
// Clear the revision queue id from the revisions table
$sql = 'UPDATE ' . TITANIA_REVISIONS_TABLE . '
SET revision_queue_id = 0
WHERE revision_id = ' . $this->revision_id;
phpbb::$db->sql_query($sql);
// Assplode
parent::delete();
}
public function move($new_status, \phpbb\titania\tags $tags)
{
$this->user->add_lang_ext('phpbb/titania', 'manage');
$from = $tags->get_tag_name($this->queue_status);
$to = $tags->get_tag_name($new_status);
$this->topic_reply(sprintf(phpbb::$user->lang['QUEUE_REPLY_MOVE'], $from, $to));
$this->queue_status = (int) $new_status;
$this->queue_progress = 0;
$this->queue_progress_time = 0;
$this->submit(false);
// Send notifications
$contrib = contribs_overlord::get_contrib_object($this->contrib_id, true);
$topic = new titania_topic();
$topic->load($this->queue_topic_id);
$path_helper = phpbb::$container->get('path_helper');
$u_view_queue = $topic->get_url(false, array('tag' => $new_status));
$vars = array(
'CONTRIB_NAME' => $contrib->contrib_name,
'CATEGORY_NAME' => $to,
'U_VIEW_QUEUE' => $path_helper->strip_url_params($u_view_queue, 'sid'),
);
$this->subscriptions->send_notifications(
ext::TITANIA_QUEUE_TAG,
$new_status,
'new_contrib_queue_cat',
$vars,
phpbb::$user->data['user_id']
);
}
public function in_progress()
{
$this->topic_reply('QUEUE_REPLY_IN_PROGRESS');
$this->queue_progress = phpbb::$user->data['user_id'];
$this->queue_progress_time = titania::$time;
$this->submit(false);
}
public function no_progress()
{
$this->topic_reply('QUEUE_REPLY_NO_PROGRESS');
$this->queue_progress = 0;
$this->queue_progress_time = 0;
$this->submit(false);
}
public function change_tested_mark($mark)
{
$this->queue_tested = (bool) $mark;
$this->submit(false);
}
/**
* Approve this revision
*
* @param mixed $public_notes
* @param int $robot_user_id User ID to use for posts/messages (defaults to current user)
*/
public function approve($public_notes, $robot_user_id = 0)
{
$this->user->add_lang_ext('phpbb/titania', array('manage', 'contributions'));
$revision = $this->get_revision();
$contrib = new titania_contribution;
if (!$contrib->load($this->contrib_id) || !$contrib->is_visible())
{
return false;
}
$revision->contrib = $contrib;
$revision->load_phpbb_versions();
$notes = $this->validation_notes;
message::decode($notes, $this->validation_notes_uid);
$message = sprintf(phpbb::$user->lang['QUEUE_REPLY_APPROVED'], $revision->revision_version, $notes);
// Replace empty quotes if there are no notes
if (!$notes)
{
$message = str_replace('[quote][/quote]', '', $message);
}
$this->topic_reply($message, false, $robot_user_id);
$this->discussion_reply($message, false, $robot_user_id);
// Get branch information first
$version_branches = array();
foreach ($revision->phpbb_versions as $phpbb_version)
{
$branch = (int) $phpbb_version['phpbb_version_branch'];
$version_branches[$branch] = $contrib->get_release_topic_id($branch);
}
// Update the revisions (this will create the release topics)
$revision->change_status(ext::TITANIA_REVISION_APPROVED);
$revision->submit();
// Go through each version branch in this revision and create the replies as needed
foreach ($version_branches as $branch => $contrib_release_topic_id)
{
// Reply to the release topic
if ($contrib_release_topic_id && $contrib->type->update_public)
{
// Replying to an already existing topic, use the update message
$post_public_notes = sprintf(phpbb::$user->lang[$contrib->type->update_public], $revision->revision_version) . (($public_notes) ? sprintf(phpbb::$user->lang[$contrib->type->update_public . '_NOTES'], $public_notes) : '');
$contrib->reply_release_topic($branch, $post_public_notes, array('poster_id' => $robot_user_id));
}
elseif (!$contrib_release_topic_id && $contrib->type->reply_public)
{
// Replying to a topic that was just made, use the reply message
$post_public_notes = phpbb::$user->lang[$contrib->type->reply_public] . (($public_notes) ? sprintf(phpbb::$user->lang[$contrib->type->reply_public . '_NOTES'], $public_notes) : '');
$contrib->reply_release_topic($branch, $post_public_notes, array('poster_id' => $robot_user_id));
}
}
// Self-updating
$this->queue_status = ext::TITANIA_QUEUE_APPROVED;
$this->queue_close_time = titania::$time;
$this->queue_close_user = phpbb::$user->data['user_id'];
$this->submit(false);
// Send notification message
$this->send_approve_deny_notification(true, $robot_user_id);
// Subscriptions
$email_vars = array(
'NAME' => $contrib->contrib_name,
'U_VIEW' => $contrib->get_url(),
);
$this->subscriptions->send_notifications(ext::TITANIA_CONTRIB, $this->contrib_id, 'subscribe_notify', $email_vars);
$this->trash_queue_topic();
}
public function close($revision_status)
{
// Update the revision
$revision = $this->get_revision();
$revision->change_status($revision_status);
// Self-updating
$this->queue_status = ext::TITANIA_QUEUE_CLOSED;
$this->queue_close_time = titania::$time;
$this->queue_close_user = phpbb::$user->data['user_id'];
$this->submit(false);
$this->trash_queue_topic();
}
public function deny($robot_user_id = 0)
{
// Reply to the queue topic and discussion with the message
$this->user->add_lang_ext('phpbb/titania', 'manage');
$revision = $this->get_revision();
$notes = $this->validation_notes;
message::decode($notes, $this->validation_notes_uid);
$message = sprintf(phpbb::$user->lang['QUEUE_REPLY_DENIED'], $revision->revision_version, $notes);
// Replace empty quotes if there are no notes
if (!$notes)
{
$message = str_replace('[quote][/quote]', '', $message);
}
$this->topic_reply($message, false, $robot_user_id);
$this->discussion_reply($message, false, $robot_user_id);
// Update the revision
$revision->change_status(ext::TITANIA_REVISION_DENIED);
// Self-updating
$this->queue_status = ext::TITANIA_QUEUE_DENIED;
$this->queue_close_time = titania::$time;
$this->queue_close_user = phpbb::$user->data['user_id'];
$this->submit(false);
// Send notification message
$this->send_approve_deny_notification(false, $robot_user_id);
$this->trash_queue_topic();
}
/**
* Send the approve/deny notification
* @param bool $approve
* @param int $robot_user_id User ID to use as sender (defaults to current user)
*/
private function send_approve_deny_notification($approve = true, $robot_user_id = 0)
{
$this->user->add_lang_ext('phpbb/titania', 'manage');
phpbb::_include('functions_privmsgs', 'submit_pm');
// Need some stuff
$contrib = new titania_contribution();
$contrib->load((int) $this->contrib_id);
$revision = new titania_revision($contrib, $this->revision_id);
$revision->load();
// Generate the authors list to send it to
$authors = array($contrib->contrib_user_id => 'to');
$sql = 'SELECT user_id FROM ' . TITANIA_CONTRIB_COAUTHORS_TABLE . '
WHERE contrib_id = ' . (int) $this->contrib_id . '
AND active = 1';
$result = phpbb::$db->sql_query($sql);
while ($row = phpbb::$db->sql_fetchrow($result))
{
$authors[$row['user_id']] = 'to';
}
phpbb::$db->sql_freeresult($result);
// Subject
$subject = sprintf(phpbb::$user->lang[$contrib->type->validation_subject], $contrib->contrib_name, $revision->revision_version);
// Message
$notes = $this->validation_notes;
message::decode($notes, $this->validation_notes_uid);
if ($approve)
{
$message = $contrib->type->validation_message_approve;
}
else
{
$message = $contrib->type->validation_message_deny;
}
$message = sprintf(phpbb::$user->lang[$message], $notes);
// Replace empty quotes if there are no notes
if (!$notes)
{
$message = str_replace('[quote][/quote]', phpbb::$user->lang['NO_NOTES'], $message);
}
// Parse the message
$message_uid = $message_bitfield = $message_options = false;
generate_text_for_storage($message, $message_uid, $message_bitfield, $message_options, true, true, true);
if ($robot_user_id)
{
$sender_id = $robot_user_id;
$sender_name = users_overlord::get_user($robot_user_id, 'username', true);
$sender_ip = '';
}
else
{
$sender_id = phpbb::$user->data['user_id'];
$sender_name = phpbb::$user->data['username'];
$sender_ip = phpbb::$user->ip;
}
$data = array(
'address_list' => array('u' => $authors),
'from_user_id' => $sender_id,
'from_username' => $sender_name,
'icon_id' => 0,
'from_user_ip' => $sender_ip,
'enable_bbcode' => true,
'enable_smilies' => true,
'enable_urls' => true,
'enable_sig' => true,
'message' => $message,
'bbcode_bitfield' => $message_bitfield,
'bbcode_uid' => $message_uid,
);
// Submit Plz
submit_pm('post', $subject, $data, true);
}
/**
* Get the revision object for this queue
*/
public function get_revision()
{
$sql = 'SELECT * FROM ' . TITANIA_REVISIONS_TABLE . '
WHERE contrib_id = ' . $this->contrib_id . '
AND revision_id = ' . $this->revision_id;
$result = phpbb::$db->sql_query($sql);
$row = phpbb::$db->sql_fetchrow($result);
phpbb::$db->sql_freeresult($result);
if ($row)
{
$revision = new titania_revision(contribs_overlord::get_contrib_object($this->contrib_id, true), $this->revision_id);
$revision->__set_array($row);
return $revision;
}
return false;
}
/**
* Get the queue discussion topic or create one if needed
*
* @param bool $check_only Return false if topic does not exist instead of creating it
*
* @return titania_topic object
*/
public function get_queue_discussion_topic($check_only = false)
{
$sql = 'SELECT * FROM ' . TITANIA_TOPICS_TABLE . '
WHERE parent_id = ' . $this->contrib_id . '
AND topic_type = ' . ext::TITANIA_QUEUE_DISCUSSION;
$result = phpbb::$db->sql_query($sql);
$row = phpbb::$db->sql_fetchrow($result);
phpbb::$db->sql_freeresult($result);
if ($row)
{
$topic = new titania_topic;
$topic->__set_array($row);
$this->queue_discussion_topic_id = $topic->topic_id;
return $topic;
}
else if ($check_only)
{
return false;
}
// No queue discussion topic...so we must create one
$this->user->add_lang_ext('phpbb/titania', 'posting');
$contrib = contribs_overlord::get_contrib_object($this->contrib_id, true);
$post = new titania_post(ext::TITANIA_QUEUE_DISCUSSION);
$post->topic->__set_array(array(
'parent_id' => $this->contrib_id,
'topic_category' => $contrib->contrib_type,
'topic_url' => serialize(array(
'contrib_type' => $contrib->type->url,
'contrib' => $contrib->contrib_name_clean,
)),
'topic_sticky' => true,
));
$post->__set_array(array(
'post_access' => access::AUTHOR_LEVEL,
'post_subject' => sprintf(phpbb::$user->lang['QUEUE_DISCUSSION_TOPIC_TITLE'], $contrib->contrib_name),
'post_text' => phpbb::$user->lang['QUEUE_DISCUSSION_TOPIC_MESSAGE'],
));
$post->generate_text_for_storage(true, true, true);
$post->submit();
$this->queue_discussion_topic_id = $post->topic->topic_id;
return $post->topic;
}
/**
* Get queue item URL.
*
* @param bool|string $action Optional action to link to.
* @param array $params Optional parameters to add to URL.
* @param array $tag Optional link to type if tags shown
*
* @return string Returns generated URL.
*/
public function get_url($action = false, $params = array(), $tag = false)
{
if (!$tag)
{
$controller = 'phpbb.titania.queue.item';
$params += array(
'id' => $this->queue_id,
);
if ($action)
{
$controller .= '.action';
$params['action'] = $action;
}
}
else
{
// Link back to the correct type if the tag is shown
$type_name = array_key_first($tag);
$controller = 'phpbb.titania.queue.type';
$params += [
'queue_type' => $tag[$type_name],
];
}
return $this->controller_helper->route($controller, $params);
}
/**
* Get URL to queue tool.
*
* @param string $tool Tool.
* @param int $revision_id Revision id.
* @param array $params Additional parameters to append to the URL.
*
* @return string
*/
public function get_tool_url($tool, $revision_id, array $params = array())
{
$params += array(
'tool' => $tool,
'id' => $revision_id,
);
return $this->controller_helper->route('phpbb.titania.queue.tools', $params);
}
/**
* Copy new posts for queue discussion, queue to the forum
*
* @param titania_post $post_object
*/
protected function forum_queue_update_first_queue_post(&$post_object)
{
if ($this->queue_status == ext::TITANIA_QUEUE_HIDE || !$this->queue_topic_id)
{
return;
}
$path_helper = phpbb::$container->get('path_helper');
// First we copy over the queue discussion topic if required
$sql = 'SELECT topic_id, phpbb_topic_id, topic_category FROM ' . TITANIA_TOPICS_TABLE . '
WHERE parent_id = ' . $this->contrib_id . '
AND topic_type = ' . ext::TITANIA_QUEUE_DISCUSSION;
$result = phpbb::$db->sql_query($sql);
$topic_row = phpbb::$db->sql_fetchrow($result);
phpbb::$db->sql_freeresult($result);
// Do we need to create the queue discussion topic or not?
if ($topic_row['topic_id'] && !$topic_row['phpbb_topic_id'])
{
$forum_id = titania_post::get_queue_forum_id($post_object->topic->topic_category, ext::TITANIA_QUEUE_DISCUSSION);
$temp_post = new titania_post;
// Go through any posts in the queue discussion topic and copy them
$topic_id = false;
$sql = 'SELECT * FROM ' . TITANIA_POSTS_TABLE . ' WHERE topic_id = ' . $topic_row['topic_id'];
$result = phpbb::$db->sql_query($sql);
while($row = phpbb::$db->sql_fetchrow($result))
{
titania::_include('functions_posting', 'phpbb_posting');
$temp_post->__set_array($row);
$post_text = $row['post_text'];
handle_queue_attachments($temp_post, $post_text);
message::decode($post_text, $row['post_text_uid']);
$post_text .= "\n\n" . $path_helper->strip_url_params($temp_post->get_url(), 'sid');
$options = array(
'poster_id' => $row['post_user_id'],
'forum_id' => $forum_id,
'topic_title' => $row['post_subject'],
'post_text' => $post_text,
);
if ($topic_id)
{
$options = array_merge($options, array(
'topic_id' => $topic_id,
));
phpbb_posting('reply', $options);
}
else
{
switch ($topic_row['topic_category'])
{
case ext::TITANIA_TYPE_EXTENSION:
$options['poster_id'] = titania::$config->forum_extension_robot;
break;
case ext::TITANIA_TYPE_MOD:
$options['poster_id'] = titania::$config->forum_mod_robot;
break;
case ext::TITANIA_TYPE_STYLE:
$options['poster_id'] = titania::$config->forum_style_robot;
break;
}
$topic_id = phpbb_posting('post', $options);
}
}
phpbb::$db->sql_freeresult($result);
if ($topic_id)
{
$sql = 'UPDATE ' . TITANIA_TOPICS_TABLE . '
SET phpbb_topic_id = ' . $topic_id . '
WHERE topic_id = ' . $topic_row['topic_id'];
phpbb::$db->sql_query($sql);
}
unset($temp_post);
}
// Does a queue topic already exist? If so, don't repost.
$sql = 'SELECT phpbb_topic_id FROM ' . TITANIA_TOPICS_TABLE . '
WHERE topic_id = ' . $this->queue_topic_id;
phpbb::$db->sql_query($sql);
$phpbb_topic_id = phpbb::$db->sql_fetchfield('phpbb_topic_id');
phpbb::$db->sql_freeresult();
if ($phpbb_topic_id)
{
return;
}
$forum_id = titania_post::get_queue_forum_id($post_object->topic->topic_category, $post_object->topic->topic_type);
if (!$forum_id)
{
return;
}
$post_object->submit();
titania::_include('functions_posting', 'phpbb_posting');
// Need some stuff
phpbb::$user->add_lang_ext('phpbb/titania', 'contributions');
$contrib = new titania_contribution;
$contrib->load((int) $this->contrib_id);
$revision = $this->get_revision();
$contrib->get_download($revision->revision_id);
switch ($post_object->topic->topic_category)
{
case ext::TITANIA_TYPE_EXTENSION:
$post_object->topic->topic_first_post_user_id = titania::$config->forum_extension_robot;
$lang_var = 'EXTENSION_QUEUE_TOPIC';
break;
case ext::TITANIA_TYPE_MOD:
$post_object->topic->topic_first_post_user_id = titania::$config->forum_mod_robot;
$lang_var = 'MOD_QUEUE_TOPIC';
break;
case ext::TITANIA_TYPE_STYLE:
$post_object->topic->topic_first_post_user_id = titania::$config->forum_style_robot;
$lang_var = 'STYLE_QUEUE_TOPIC';
break;
default:
return;
break;
}
$description = $contrib->contrib_desc;
message::decode($description, $contrib->contrib_desc_uid);
$download = current($contrib->download);
$post_text = sprintf(phpbb::$user->lang[$lang_var],
$contrib->contrib_name,
$path_helper->strip_url_params($contrib->author->get_url(), 'sid'),
users_overlord::get_user($contrib->author->user_id, '_username'),
$description,
$revision->revision_version,
$path_helper->strip_url_params($revision->get_url(), 'sid'),
$download['real_filename'],
get_formatted_filesize($download['filesize'])
);
$post_text .= "\n\n" . $post_object->post_text;
handle_queue_attachments($post_object, $post_text);
message::decode($post_text, $post_object->post_text_uid);
$post_text .= "\n\n" . $path_helper->strip_url_params($post_object->get_url(), 'sid');
$options = array(
'poster_id' => $post_object->topic->topic_first_post_user_id,
'forum_id' => $forum_id,
'topic_title' => $post_object->topic->topic_subject,
'post_text' => $post_text,
);
$topic_id = phpbb_posting('post', $options);
$post_object->topic->phpbb_topic_id = $topic_id;
$sql = 'UPDATE ' . TITANIA_TOPICS_TABLE . '
SET phpbb_topic_id = ' . (int) $topic_id . '
WHERE topic_id = ' . $post_object->topic->topic_id;
phpbb::$db->sql_query($sql);
}
/**
* Move queue topics to the trash can
*/
protected function trash_queue_topic()
{
$sql = 'SELECT phpbb_topic_id, topic_category FROM ' . TITANIA_TOPICS_TABLE . '
WHERE topic_id = ' . (int) $this->queue_topic_id;
$result = phpbb::$db->sql_query($sql);
$row = phpbb::$db->sql_fetchrow($result);
phpbb::$db->sql_freeresult($result);
if (!$row['phpbb_topic_id'])
{
return;
}
phpbb::_include('functions_admin', 'move_topics');
move_topics($row['phpbb_topic_id'], titania_post::get_queue_forum_id($row['topic_category'], 'trash'));
}
}