|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* Topic Image Preview. An extension for the phpBB Forum Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2017, 2020, Matt Friedman |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace vse\topicimagepreview\event; |
|
12
|
|
|
|
|
13
|
|
|
use phpbb\config\config; |
|
14
|
|
|
use phpbb\template\template; |
|
15
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Topic Image Preview Event listener. |
|
19
|
|
|
*/ |
|
20
|
|
|
class preview implements EventSubscriberInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var config */ |
|
23
|
|
|
protected $config; |
|
24
|
|
|
|
|
25
|
|
|
/** @var helper */ |
|
26
|
|
|
protected $helper; |
|
27
|
|
|
|
|
28
|
|
|
/** @var template */ |
|
29
|
|
|
protected $template; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function getSubscribedEvents() |
|
35
|
|
|
{ |
|
36
|
|
|
return [ |
|
37
|
|
|
'core.page_footer' => 'init_tpl_vars', |
|
38
|
|
|
// Viewforum events |
|
39
|
|
|
'core.viewforum_modify_topics_data' => 'viewforum_row', |
|
40
|
|
|
'core.viewforum_modify_topicrow' => 'viewforum_tpl', |
|
41
|
|
|
// Search events |
|
42
|
|
|
'core.search_modify_rowset' => 'searchresults_row', |
|
43
|
|
|
'core.search_modify_tpl_ary' => 'searchresults_tpl', |
|
44
|
|
|
// Precise Similar Topics events |
|
45
|
|
|
'vse.similartopics.modify_rowset' => 'similartopics_row', |
|
46
|
|
|
'vse.similartopics.modify_topicrow' => 'similartopics_tpl', |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Constructor |
|
52
|
|
|
* |
|
53
|
|
|
* @param config $config |
|
54
|
|
|
* @param helper $helper |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct(config $config, helper $helper, template $template) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->config = $config; |
|
59
|
|
|
$this->helper = $helper; |
|
60
|
|
|
$this->template = $template; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Set some template variables for T.I.P. |
|
65
|
|
|
*/ |
|
66
|
|
|
public function init_tpl_vars() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->template->assign_vars([ |
|
69
|
|
|
'S_TOPIC_IMAGE_PREVIEW' => $this->helper->is_preview(), |
|
70
|
|
|
'TOPIC_IMAGE_PREVIEW_DIM' => $this->config['vse_tip_dim'], |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Update viewforum row |
|
76
|
|
|
* |
|
77
|
|
|
* @param \phpbb\event\data $event The event object |
|
78
|
|
|
*/ |
|
79
|
|
|
public function viewforum_row($event) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->helper->update_row_data($event); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Update viewforum template |
|
86
|
|
|
* |
|
87
|
|
|
* @param \phpbb\event\data $event The event object |
|
88
|
|
|
*/ |
|
89
|
|
|
public function viewforum_tpl($event) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->helper->update_tpl_data($event); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Update search results topics row |
|
96
|
|
|
* |
|
97
|
|
|
* @param \phpbb\event\data $event The event object |
|
98
|
|
|
*/ |
|
99
|
|
|
public function searchresults_row($event) |
|
100
|
|
|
{ |
|
101
|
|
|
if ($event['show_results'] === 'topics' && $this->config->offsetGet('vse_tip_srt')) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->helper->update_row_data($event); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Update search results topics template |
|
109
|
|
|
* |
|
110
|
|
|
* @param \phpbb\event\data $event The event object |
|
111
|
|
|
*/ |
|
112
|
|
|
public function searchresults_tpl($event) |
|
113
|
|
|
{ |
|
114
|
|
|
if ($event['show_results'] === 'topics' && $this->config->offsetGet('vse_tip_srt')) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->helper->update_tpl_data($event); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Update similar topics row |
|
122
|
|
|
* |
|
123
|
|
|
* @param \phpbb\event\data $event The event object |
|
124
|
|
|
*/ |
|
125
|
|
|
public function similartopics_row($event) |
|
126
|
|
|
{ |
|
127
|
|
|
if ($this->config->offsetGet('vse_tip_pst')) |
|
128
|
|
|
{ |
|
129
|
|
|
$this->helper->update_row_data($event); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Update similar topics template |
|
135
|
|
|
* |
|
136
|
|
|
* @param \phpbb\event\data $event The event object |
|
137
|
|
|
*/ |
|
138
|
|
|
public function similartopics_tpl($event) |
|
139
|
|
|
{ |
|
140
|
|
|
if ($this->config->offsetGet('vse_tip_pst')) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->helper->update_tpl_data($event); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|