|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* |
|
6
|
|
|
* @package ElkArte Forum |
|
7
|
|
|
* @copyright ElkArte Forum contributors |
|
8
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
|
9
|
|
|
* |
|
10
|
|
|
* @version 2.0 dev |
|
11
|
|
|
* |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace ElkArte\Modules\Random; |
|
15
|
|
|
|
|
16
|
|
|
use ElkArte\EventManager; |
|
17
|
|
|
use ElkArte\Modules\AbstractModule; |
|
18
|
|
|
use ElkArte\Languages\Txt; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class \ElkArte\Modules\Random\Display |
|
22
|
|
|
*/ |
|
23
|
|
|
class Display extends AbstractModule |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var bool |
|
27
|
|
|
*/ |
|
28
|
|
|
protected static $includeUnapproved = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc } |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function hooks(EventManager $eventsManager) |
|
34
|
|
|
{ |
|
35
|
|
|
global $modSettings; |
|
36
|
|
|
|
|
37
|
|
|
$return = array(); |
|
38
|
|
|
|
|
39
|
|
|
if (!empty($modSettings['enableFollowup'])) |
|
40
|
|
|
{ |
|
41
|
|
|
$return = array( |
|
42
|
|
|
array('topicinfo', array('\\ElkArte\\Modules\\Random\\Display', 'topicinfo'), array('topicinfo', 'topic', 'includeUnapproved')), |
|
43
|
|
|
array('prepare_context', array('\\ElkArte\\Modules\\Random\\Display', 'prepare_context'), array()) |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
add_integration_function('integrate_topic_query', '\\ElkArte\\Modules\\Random\\Display::followup_topic_query', '', false); |
|
47
|
|
|
add_integration_function('integrate_display_message_list', '\\ElkArte\\Modules\\Random\\Display::followup_message_list', '', false); |
|
48
|
|
|
add_integration_function('integrate_display_message_list', '\\ElkArte\\Modules\\Random\\Display::load_likes', '', false); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Adds to the display query to fetch the id of the original topic. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string[] $topic_selects |
|
58
|
|
|
* @param string[] $topic_tables |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function followup_topic_query(&$topic_selects, &$topic_tables) |
|
61
|
|
|
{ |
|
62
|
|
|
$topic_selects[] = 'fu.derived_from'; |
|
63
|
|
|
$topic_tables[] = 'LEFT JOIN {db_prefix}follow_ups AS fu ON (fu.follow_up = t.id_topic)'; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Show topics originated from the messages. |
|
68
|
|
|
* |
|
69
|
|
|
* @param int[] $messages |
|
70
|
|
|
*/ |
|
71
|
|
|
public static function followup_message_list($messages) |
|
72
|
|
|
{ |
|
73
|
|
|
global $context; |
|
74
|
|
|
|
|
75
|
|
|
require_once(SUBSDIR . '/FollowUps.subs.php'); |
|
76
|
|
|
$context['follow_ups'] = followupTopics($messages, self::$includeUnapproved); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Show likes. |
|
81
|
|
|
* |
|
82
|
|
|
* @param int[] $messages |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function load_likes($messages) |
|
85
|
|
|
{ |
|
86
|
|
|
global $modSettings, $context, $txt; |
|
87
|
|
|
|
|
88
|
|
|
if (!empty($modSettings['likes_enabled']) && !empty($messages)) |
|
89
|
|
|
{ |
|
90
|
|
|
require_once(SUBSDIR . '/Likes.subs.php'); |
|
91
|
|
|
$context['likes'] = loadLikes($messages, true); |
|
92
|
|
|
theme()->getLayers()->addBefore('load_likes_button', 'body'); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Prepares the data for the droppy with "child topics". |
|
98
|
|
|
* |
|
99
|
|
|
* @param mixed[] $topicinfo |
|
100
|
|
|
* @param int $topic |
|
101
|
|
|
* @param bool $includeUnapproved |
|
102
|
|
|
*/ |
|
103
|
|
|
public function topicinfo($topicinfo, $topic, $includeUnapproved) |
|
104
|
|
|
{ |
|
105
|
|
|
global $context, $scripturl; |
|
106
|
|
|
|
|
107
|
|
|
self::$includeUnapproved = $includeUnapproved; |
|
108
|
|
|
|
|
109
|
|
|
// If this topic was derived from another, set the followup details |
|
110
|
|
|
if (!empty($topicinfo['derived_from'])) |
|
111
|
|
|
{ |
|
112
|
|
|
require_once(SUBSDIR . '/FollowUps.subs.php'); |
|
113
|
|
|
$context['topic_derived_from'] = topicStartedHere($topic, $includeUnapproved); |
|
114
|
|
|
|
|
115
|
|
|
// Derived from, set the link back |
|
116
|
|
|
if (!empty($context['topic_derived_from'])) |
|
117
|
|
|
{ |
|
118
|
|
|
$context['links']['derived_from'] = $scripturl . '?msg=' . $context['topic_derived_from']['derived_from']; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Can we show the button? |
|
125
|
|
|
*/ |
|
126
|
|
|
public function prepare_context() |
|
127
|
|
|
{ |
|
128
|
|
|
global $context; |
|
129
|
|
|
|
|
130
|
|
|
$context['can_follow_up'] = boardsAllowedTo('post_new') !== array(); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|