PluginProbe
wpForo Forum / 3.0.7
wpForo Forum v3.0.7
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / modules / subscriptions / classes / Template.php

Template.php in wpForo Forum 3.0.7, at modules/subscriptions/classes/Template.php

305 lines 12.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\modules\subscriptions\classes;
4
5 class Template {
6 public function __construct() {
7 $this->init_hooks();
8 }
9
10 private function init_hooks() {
11 add_action( 'wpforo_template_profile_subscriptions_head_bar', function(){ $this->manager_form(); } );
12 add_action( 'wpforo_template_forum_head_bar_action_links', function(){ echo $this->forum_subscribe_link(); } );
13 add_action( 'wpforo_template_topic_head_bar_action_links', function(){ echo $this->forum_subscribe_link(); } );
14 add_action( 'wpforo_template_post_head_bar_action_links', function(){ echo $this->topic_subscribe_link(); } );
15 add_action( 'wpforo_editor_topic_submit_before', function( $forum, $values ){
16 if( !$values ) echo $this->topic_form_checkbox( $forum );
17 }, 10, 2 );
18 add_action( 'wpforo_editor_post_submit_before', function( $topic, $values, $forum ){
19 if( !$values ){
20 $layout = $topic['layout'] = WPF()->forum->get_layout( $forum );
21 echo $this->post_form_checkbox( $topic, $layout );
22 }
23 }, 10, 3 );
24 add_action( 'wpforo_portable_editor_post_submit_before', function( $topic, $values, $forum ){
25 if( !$values ){
26 $layout = $topic['layout'] = WPF()->forum->get_layout( $forum );
27 echo $this->post_form_checkbox( $topic, $layout );
28 }
29 }, 10, 3);
30 }
31
32 public function manager_form( $userid = 0 ) {
33 $userid = intval( $userid );
34 if( ! $userid ) {
35 $userid = WPF()->current_object['userid'];
36 if( ! $userid ) $userid = WPF()->current_userid;
37 }
38 if(
39 (
40 WPF()->current_userid !== $userid
41 && ! wpforo_current_user_is( 'admin' )
42 ) || (
43 wpforo_setting( 'subscriptions', 'subscribe_confirmation' )
44 && ! wpforo_current_user_is( 'admin' )
45 && ! WPF()->sbscrb->is_email_confirmed()
46 )
47 ) return;
48 $sbs = [];
49 $allposts_checked = '';
50 $alltopics_checked = '';
51
52 if( WPF()->sbscrb->get_subscribes( [ 'type' => 'forums-topics', 'userid' => $userid, 'active' => null ] ) ) {
53 $allposts_checked = ' checked';
54 }
55 if( WPF()->sbscrb->get_subscribes( [ 'type' => 'forums', 'userid' => $userid, 'active' => null ] ) ) {
56 $alltopics_checked = ' checked';
57 }
58
59 if( ! $allposts_checked && ! $alltopics_checked ) {
60 if( $sbs_forum = WPF()->sbscrb->get_subscribes( [ 'type' => 'forum', 'userid' => $userid, 'active' => null ] ) ) {
61 foreach( $sbs_forum as $s ) $sbs[ $s['itemid'] ] = $s['type'];
62 }
63 if( $sbs_forum_topic = WPF()->sbscrb->get_subscribes( [ 'type' => 'forum-topic', 'userid' => $userid, 'active' => null ] ) ) {
64 foreach( $sbs_forum_topic as $s ) $sbs[ $s['itemid'] ] = $s['type'];
65 }
66 }
67 ?>
68 <script type="text/javascript">
69 jQuery(document).ready(function ($) {
70 if ($('#wpf_subscription_tools input[id^="wpf_sbs_allposts_"]').length === $('#wpf_subscription_tools input[id^="wpf_sbs_allposts_"]:checked').length) {
71 $('#wpf_sbs_allposts').prop('checked', true)
72 }
73 if ($('#wpf_subscription_tools input[id^="wpf_sbs_alltopics_"]').length === $('#wpf_subscription_tools input[id^="wpf_sbs_alltopics_"]:checked').length) {
74 $('#wpf_sbs_alltopics').prop('checked', true)
75 }
76 if ($('#wpf_sbs_allposts').is(':checked')) {
77 $('#wpf_subscription_tools input[id^="wpf_sbs_allposts_"]').prop('checked', true)
78 }
79 if ($('#wpf_sbs_alltopics').is(':checked')) {
80 $('#wpf_subscription_tools input[id^="wpf_sbs_alltopics_"]').prop('checked', true)
81 }
82 var wpforo_wrap = $('#wpforo-wrap')
83 wpforo_wrap.on('change', '#wpf_sbs_allposts', function () {
84 var stat = $(this).is(':checked')
85 $('#wpf_sbs_alltopics').prop('checked', false)
86 $('#wpf_subscription_tools input[id^="wpf_sbs_allposts_"]').prop('checked', stat)
87 if (stat) $('#wpf_subscription_tools input[id^="wpf_sbs_alltopics_"]').prop('checked', !stat)
88 })
89 wpforo_wrap.on('change', '#wpf_sbs_alltopics', function () {
90 var stat = $(this).is(':checked')
91 $('#wpf_sbs_allposts').prop('checked', false)
92 $('#wpf_subscription_tools input[id^="wpf_sbs_alltopics_"]').prop('checked', stat)
93 if (stat) $('#wpf_subscription_tools input[id^="wpf_sbs_allposts_"]').prop('checked', !stat)
94 })
95 wpforo_wrap.on('change', '#wpf_subscription_tools input[id^="wpf_sbs_allposts_"]', function () {
96 var stat = $(this).is(':checked')
97 $('#wpf_sbs_allposts,#wpf_sbs_alltopics').prop('checked', false)
98 if (stat) {
99 if ($('#wpf_subscription_tools input[id^="wpf_sbs_allposts_"]').length === $('#wpf_subscription_tools input[id^="wpf_sbs_allposts_"]:checked').length) {
100 $('#wpf_sbs_allposts').prop('checked', true)
101 }
102 $(this).siblings('input[id^="wpf_sbs_alltopics_"]').prop('checked', false)
103 }
104 })
105 wpforo_wrap.on('change', '#wpf_subscription_tools input[id^="wpf_sbs_alltopics_"]', function () {
106 var stat = $(this).is(':checked')
107 $('#wpf_sbs_allposts,#wpf_sbs_alltopics').prop('checked', false)
108 if (stat) {
109 if ($('#wpf_subscription_tools input[id^="wpf_sbs_alltopics_"]').length === $('#wpf_subscription_tools input[id^="wpf_sbs_alltopics_"]:checked').length) {
110 $('#wpf_sbs_alltopics').prop('checked', true)
111 }
112 $(this).siblings('input[id^="wpf_sbs_allposts_"]').prop('checked', false)
113 }
114 })
115 })
116 </script>
117 <div id="wpf_subscription_tools" class="wpf-tools">
118 <p class="wpf-sbs-head"><?php wpforo_phrase( 'Subscription Manager' ) ?></p>
119 <form id="wpf_sbs_form" method="post" enctype="multipart/form-data" action="">
120 <input type="hidden" name="wpfaction" value="subscribe_manager">
121 <input type="hidden" name="wpforo[boardid]" value="<?php echo WPF()->board->get_current( 'boardid' ) ?>">
122 <input type="hidden" name="wpforo[userid]" value="<?php echo $userid ?>">
123 <?php wp_nonce_field( 'wpforo_verify_form_' . $userid, '_wpfnonce' ); ?>
124 <div class="wpf-sbs-bulk">
125 <div class="wpf-sbs-bulk-posts">
126 <input id="wpf_sbs_allposts" type="checkbox" name="wpforo[check_all]" value="forums-topics" <?php echo $allposts_checked ?>>
127 <label for="wpf_sbs_allposts"><?php wpforo_phrase( 'Subscribe to all new topics and posts' ) ?></label>
128 </div>
129 <div class="wpf-sbs-bulk-topics">
130 <input id="wpf_sbs_alltopics" type="checkbox" name="wpforo[check_all]" value="forums" <?php echo $alltopics_checked ?>>
131 <label for="wpf_sbs_alltopics"><?php wpforo_phrase( 'Subscribe to all new topics' ) ?></label>
132 </div>
133 </div>
134 <div class="wpf-sbs-bulk-options">
135 <ul>
136 <?php WPF()->forum->tree( 'subscribe_manager_form', false, $sbs ); ?>
137 </ul>
138 </div>
139 <div class="wpf-sbs-tool-foot">
140 <input type="submit" value="<?php wpforo_phrase( 'Update Subscriptions' ) ?>">
141 </div>
142 </form>
143 </div>
144 <?php
145 }
146
147 public function forum_subscribe_link() {
148 if( WPF()->current_userid || WPF()->current_user_email ) {
149 if( WPF()->current_object['forumid'] && WPF()->perm->forum_can( 'sb', WPF()->current_object['forumid'] ) ) {
150 if(
151 WPF()->sbscrb->get_subscribe(
152 [
153 "userid" => WPF()->current_userid,
154 "itemid" => 0,
155 "type" => ['forums','forums-topics'],
156 'user_email' => WPF()->current_user_email,
157 ]
158 )
159 ) return '';
160
161 $args = [
162 "userid" => WPF()->current_userid,
163 "itemid" => WPF()->current_object['forumid'],
164 "type" => ['forum','forum-topic'],
165 'user_email' => WPF()->current_user_email,
166 ];
167 if( WPF()->sbscrb->get_subscribe( $args ) ) {
168 return sprintf(
169 '<span class="wpf-unsubscribe-forum wpf-button-outlined" data-type="forum" data-itemid="%1$d">%2$s</span>',
170 WPF()->current_object['forumid'],
171 wpforo_phrase( 'Unsubscribe', false )
172 );
173 }
174
175 return sprintf(
176 '<span class="wpf-subscribe-forum wpf-button-outlined wpfcl-5" data-type="forum" data-itemid="%1$d"><i class="far fa-envelope wpfcl-5"></i> %2$s</span>',
177 WPF()->current_object['forumid'],
178 wpforo_phrase( 'Subscribe for new topics', false )
179 );
180 }
181 }
182
183 return '';
184 }
185
186 public function topic_subscribe_link() {
187 if( WPF()->current_userid || WPF()->current_user_email ) {
188 if( WPF()->current_object['forumid'] && WPF()->perm->forum_can( 'sb', WPF()->current_object['forumid'] ) ) {
189 if(
190 WPF()->sbscrb->get_subscribe(
191 [
192 "userid" => WPF()->current_userid,
193 "itemid" => 0,
194 "type" => ['forums','forums-topics'],
195 'user_email' => WPF()->current_user_email,
196 ]
197 )
198 ) return '<span class="wpf-subscribe-topic">&nbsp;</span>';
199
200 $args = [
201 "userid" => WPF()->current_userid,
202 "itemid" => WPF()->current_object['topicid'],
203 "type" => "topic",
204 'user_email' => WPF()->current_user_email,
205 ];
206 if( WPF()->sbscrb->get_subscribe( $args ) ) {
207 return sprintf(
208 '<span class="wpf-unsubscribe-topic wpf-button-outlined" data-type="topic" data-itemid="%1$d">%2$s</span>',
209 WPF()->current_object['topicid'],
210 wpforo_phrase( 'Unsubscribe', false )
211 );
212 }
213
214 return sprintf(
215 '<span class="wpf-subscribe-topic wpf-button-outlined wpfcl-5" data-type="topic" data-itemid="%1$d"><i class="far fa-envelope"></i> %2$s</span>',
216 WPF()->current_object['topicid'],
217 wpforo_phrase( 'Subscribe for new replies', false )
218 );
219 }
220 }
221
222 return '<span class="wpf-subscribe-topic">&nbsp;</span>';
223 }
224
225 public function topic_form_checkbox( $forum ) {
226 if( wpforo_setting( 'subscriptions', 'subscribe_checkbox_on_post_editor' ) && WPF()->perm->forum_can( 'sb', $forum['forumid'] ) ) {
227 if(
228 WPF()->sbscrb->get_subscribe(
229 [
230 "userid" => WPF()->current_userid,
231 "itemid" => 0,
232 "type" => ['forums-topics'],
233 'user_email' => WPF()->current_user_email,
234 ]
235 )
236 ) return '';
237
238 if(
239 WPF()->sbscrb->get_subscribe(
240 [
241 "userid" => WPF()->current_userid,
242 "itemid" => $forum['forumid'],
243 "type" => ['forum-topic'],
244 'user_email' => WPF()->current_user_email,
245 ]
246 )
247 ) return '';
248
249 return sprintf(
250 '<div class="wpf-topic-sbs">
251 <input id="wpf-topic-sbs-%1$s" type="checkbox" name="wpforo_topic_subs" value="1" %2$s>&nbsp;
252 <label for="wpf-topic-sbs-%1$s">%3$s</label>
253 </div>',
254 uniqid(),
255 wpforo_setting( 'subscriptions', 'subscribe_checkbox_default_status' ) ? 'checked' : '',
256 WPF()->forum->get_layout( $forum ) === 3 ? wpforo_phrase( 'Subscribe to this question', false ) : wpforo_phrase( 'Subscribe to this topic', false )
257 );
258 }
259
260 return '';
261 }
262
263 public function post_form_checkbox( $topic, $layout = 1 ) {
264 if( wpforo_setting( 'subscriptions', 'subscribe_checkbox_on_post_editor' ) && WPF()->perm->forum_can( 'sb', $topic['forumid'] ) ) {
265 if(
266 WPF()->sbscrb->get_subscribe(
267 [
268 "userid" => WPF()->current_userid,
269 "itemid" => 0,
270 "type" => ['forums-topics'],
271 'user_email' => WPF()->current_user_email,
272 ]
273 )
274 ) return '';
275
276 if(
277 WPF()->sbscrb->get_subscribe(
278 [
279 "userid" => WPF()->current_userid,
280 "itemid" => $topic['forumid'],
281 "type" => ['forum-topic'],
282 'user_email' => WPF()->current_user_email,
283 ]
284 )
285 ) return '';
286
287 $topic = [ "userid" => WPF()->current_userid, "itemid" => intval( $topic['topicid'] ), "type" => "topic" ];
288 $subscribe = WPF()->sbscrb->get_subscribe( $topic );
289 if( ! isset( $subscribe['subid'] ) ) {
290 return sprintf(
291 '<div class="wpf-topic-sbs">
292 <input id="wpf-topic-sbs-%1$s" type="checkbox" name="wpforo_topic_subs" value="1" %2$s>&nbsp;
293 <label for="wpf-topic-sbs-%1$s">%3$s</label>
294 </div>',
295 uniqid(),
296 wpforo_setting( 'subscriptions', 'subscribe_checkbox_default_status' ) ? 'checked' : '',
297 $layout === 3 ? wpforo_phrase( 'Subscribe to this question', false ) : wpforo_phrase( 'Subscribe to this topic', false )
298 );
299 }
300 }
301
302 return '';
303 }
304 }
305