| 1 |
<?php |
| 2 |
|
| 3 |
namespace wpforo\modules\subscriptions\classes; |
| 4 |
|
| 5 |
class Actions { |
| 6 |
public function __construct() { |
| 7 |
$this->init_hooks(); |
| 8 |
} |
| 9 |
|
| 10 |
public function init_hooks( ) { |
| 11 |
add_action( 'wpforo_action_subscriptions_settings_save', [ $this, 'settings_save' ] ); |
| 12 |
|
| 13 |
add_action( 'wpforo_core_inited', [ $this, 'confirmation' ] ); |
| 14 |
add_action( 'wpforo_action_unsbscrb', [ $this, 'delete' ] ); |
| 15 |
add_action( 'wpforo_action_subscribe_manager', [ $this, 'manager' ] ); |
| 16 |
|
| 17 |
add_action( 'wpforo_after_add_topic', [ $this, 'topic_auto_subscribe' ] ); |
| 18 |
add_action( 'wpforo_after_add_post', [ $this, 'topic_auto_subscribe' ] ); |
| 19 |
add_action( 'wpforo_post_approve', [ $this, 'after_post_approve' ] ); |
| 20 |
add_action( 'wpforo_after_delete_topic', [ $this, 'after_delete_topic' ] ); |
| 21 |
add_action( 'wpforo_after_delete_user', [ $this, 'after_delete_user' ] ); |
| 22 |
|
| 23 |
add_action( 'wpforo_after_add_topic', [ $this, 'after_add_topic' ], 10, 2 ); |
| 24 |
add_action( 'wpforo_after_add_post', [ $this, 'after_add_post' ], 10, 2 ); |
| 25 |
|
| 26 |
### AJAX ACTIONS ### |
| 27 |
add_action( 'wp_ajax_wpforo_subscribe_ajax', [ $this, 'subscribe' ] ); |
| 28 |
add_action( 'wp_ajax_nopriv_wpforo_subscribe_ajax', [ $this, 'subscribe' ] ); |
| 29 |
add_action( 'wp_ajax_wpforo_unsubscribe', [ $this, 'unsubscribe' ] ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* subscriptions_settings_save after submit action |
| 34 |
* |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
public function settings_save() { |
| 38 |
check_admin_referer( 'wpforo_settings_save_subscriptions' ); |
| 39 |
|
| 40 |
if( wpfkey( $_POST, 'reset' ) ) { |
| 41 |
wpforo_delete_option( 'subscriptions' ); |
| 42 |
} else { |
| 43 |
$subscriptions = wpforo_array_args_cast_and_merge( wp_unslash( $_POST['subscriptions'] ), WPF()->settings->_subscriptions ); |
| 44 |
$subscriptions['confirmation_email_subject'] = sanitize_text_field( $subscriptions['confirmation_email_subject'] ); |
| 45 |
$subscriptions['confirmation_email_message'] = wpforo_kses( $subscriptions['confirmation_email_message'], 'email' ); |
| 46 |
$subscriptions['new_topic_notification_email_subject'] = sanitize_text_field( $subscriptions['new_topic_notification_email_subject'] ); |
| 47 |
$subscriptions['new_topic_notification_email_message'] = wpforo_kses( $subscriptions['new_topic_notification_email_message'], 'email' ); |
| 48 |
$subscriptions['new_post_notification_email_subject'] = sanitize_text_field( $subscriptions['new_post_notification_email_subject'] ); |
| 49 |
$subscriptions['new_post_notification_email_message'] = wpforo_kses( $subscriptions['new_post_notification_email_message'], 'email' ); |
| 50 |
$subscriptions['user_mention_email_subject'] = sanitize_text_field( $subscriptions['user_mention_email_subject'] ); |
| 51 |
$subscriptions['user_mention_email_message'] = wpforo_kses( $subscriptions['user_mention_email_message'], 'email' ); |
| 52 |
$subscriptions['user_following_email_subject'] = sanitize_text_field( $subscriptions['user_following_email_subject'] ); |
| 53 |
$subscriptions['user_following_email_message'] = wpforo_kses( $subscriptions['user_following_email_message'], 'email' ); |
| 54 |
foreach( WPF()->action->generate_option_names( 'subscriptions' ) as $option_name ) { |
| 55 |
wpforo_update_option( $option_name, $subscriptions ); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
WPF()->notice->add( 'Successfully Done', 'success' ); |
| 60 |
wp_safe_redirect( wp_get_raw_referer() ); |
| 61 |
exit(); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* subscription_confirmation form submit action |
| 66 |
*/ |
| 67 |
public function confirmation(): void { |
| 68 |
if( wpfval( WPF()->GET, 'wpfaction' ) === 'sbscrbconfirm' && ($sbs_key = wpfval( WPF()->GET, 'key' )) ) { |
| 69 |
$sbs_key = sanitize_text_field( $sbs_key ); |
| 70 |
WPF()->sbscrb->edit( $sbs_key ); |
| 71 |
wp_safe_redirect( wpforo_setting( 'authorization', 'redirect_url_after_confirm_sbscrb' ) ?: wpforo_home_url( preg_replace( '#\?.*$#is', '', (string) WPF()->current_url ) ) ); |
| 72 |
exit(); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* subscription_delete form submit action |
| 78 |
*/ |
| 79 |
public function delete() { |
| 80 |
if( $sbs_key = wpfval( WPF()->GET, 'key' ) ) { |
| 81 |
$sbs_key = sanitize_text_field( $sbs_key ); |
| 82 |
WPF()->sbscrb->delete( $sbs_key ); |
| 83 |
wp_safe_redirect( wpforo_setting( 'authorization', 'redirect_url_after_confirm_sbscrb' ) ?: wpforo_home_url( preg_replace( '#\?.*$#is', '', (string) WPF()->current_url ) ) ); |
| 84 |
exit(); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* subscribe_manager form submit action |
| 90 |
*/ |
| 91 |
public function manager() { |
| 92 |
$userid = (int) wpfval( $_POST, 'wpforo', 'userid' ); |
| 93 |
wpforo_verify_form( 'wpforo_verify_form_' . $userid ); |
| 94 |
|
| 95 |
WPF()->change_board( (int) wpfval( $_POST, 'wpforo', 'boardid' ) ); |
| 96 |
|
| 97 |
$data = ( ! empty( $_POST['wpforo']['forums'] ) ? array_map( 'sanitize_title', $_POST['wpforo']['forums'] ) : [] ); |
| 98 |
$all = ( ! empty( $_POST['wpforo']['check_all'] ) ? sanitize_title( $_POST['wpforo']['check_all'] ) : '' ); |
| 99 |
|
| 100 |
WPF()->sbscrb->reset( $data, $all, $userid ); |
| 101 |
wp_safe_redirect( wpforo_get_request_uri() ); |
| 102 |
exit(); |
| 103 |
} |
| 104 |
|
| 105 |
function topic_auto_subscribe( $item ) { |
| 106 |
if( ! isset( $_POST['wpforo_topic_subs'] ) || ! $_POST['wpforo_topic_subs'] ) return false; |
| 107 |
|
| 108 |
if( isset( $item['forumid'] ) && $item['forumid'] ) { |
| 109 |
if( isset( $item['private'] ) && $item['private'] && ! wpforo_is_owner( $item['userid'] ) ) { |
| 110 |
if( ! WPF()->perm->forum_can( 'vp', $item['forumid'] ) ) { |
| 111 |
WPF()->notice->add( 'You are not permitted to subscribe here', 'error' ); |
| 112 |
return false; |
| 113 |
} |
| 114 |
} |
| 115 |
} else { |
| 116 |
WPF()->notice->add( 'Forum ID is not detected', 'error' ); |
| 117 |
return false; |
| 118 |
} |
| 119 |
|
| 120 |
$args = [ |
| 121 |
'itemid' => wpforo_bigintval( $item['topicid'] ), |
| 122 |
'type' => 'topic', |
| 123 |
'userid' => WPF()->current_userid, |
| 124 |
'user_name' => '', |
| 125 |
'user_email' => '', |
| 126 |
]; |
| 127 |
|
| 128 |
if( ! WPF()->current_userid ) { |
| 129 |
if( WPF()->current_user_email ) $args['user_email'] = WPF()->current_user_email; |
| 130 |
if( WPF()->current_user_display_name ) $args['user_name'] = WPF()->current_user_display_name; |
| 131 |
} |
| 132 |
if( ! $args['userid'] && ! $args['user_email'] ) return false; |
| 133 |
|
| 134 |
$args['confirmkey'] = WPF()->sbscrb->get_confirm_key(); |
| 135 |
|
| 136 |
if( wpforo_setting( 'subscriptions', 'subscribe_confirmation' ) ) { |
| 137 |
############### Sending Email ################## |
| 138 |
$confirmlink = WPF()->sbscrb->get_confirm_link( $args ); |
| 139 |
$member_name = ( WPF()->current_userid ? wpforo_user_dname( WPF()->current_user ) : ( $args['user_name'] ?: $args['user_email'] ) ); |
| 140 |
$subject = wpforo_setting( 'subscriptions', 'confirmation_email_subject' ); |
| 141 |
$message = wpforo_setting( 'subscriptions', 'confirmation_email_message' ); |
| 142 |
$topic = WPF()->topic->get_topic( $item['topicid'], false ); |
| 143 |
$from_tags = [ "[user_display_name]", "[entry_title]", "[confirm_link]" ]; |
| 144 |
$to_words = [ |
| 145 |
sanitize_text_field( $member_name ), |
| 146 |
'<strong>' . sanitize_text_field( $topic['title'] ) . '</strong>', |
| 147 |
'<br><br><a target="_blank" href="' . esc_url( (string) $confirmlink ) . '"> ' . wpforo_phrase( 'Confirm my subscription', false ) . ' </a>', |
| 148 |
]; |
| 149 |
$subject = stripslashes( str_replace( $from_tags, $to_words, (string) $subject ) ); |
| 150 |
$message = stripslashes( str_replace( $from_tags, $to_words, (string) $message ) ); |
| 151 |
$message = wpforo_kses( $message, 'email' ); |
| 152 |
|
| 153 |
add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type', 999 ); |
| 154 |
$headers = wpforo_mail_headers(); |
| 155 |
|
| 156 |
if( wp_mail( WPF()->current_user_email, sanitize_text_field( $subject ), $message, $headers ) ) { |
| 157 |
if( $response = WPF()->sbscrb->add( $args ) ) return $response; |
| 158 |
} else { |
| 159 |
WPF()->notice->add( 'Can\'t send confirmation email', 'error' ); |
| 160 |
return false; |
| 161 |
} |
| 162 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 163 |
############### Sending Email end ############## |
| 164 |
} else { |
| 165 |
$args['active'] = 1; |
| 166 |
if( $response = WPF()->sbscrb->add( $args ) ) return $response; |
| 167 |
} |
| 168 |
|
| 169 |
return false; |
| 170 |
} |
| 171 |
|
| 172 |
public function after_post_approve( $post ) { |
| 173 |
if( (int) wpfval($post, 'is_first_post') ){ |
| 174 |
if( ($topicid = wpforo_bigintval(wpfval($post, 'topicid'))) |
| 175 |
&& ($topic = WPF()->topic->get_topic( $topicid )) |
| 176 |
&& ($forumid = (int) wpfval($post, 'forumid')) |
| 177 |
&& ($forum = WPF()->forum->get_forum( $forumid )) |
| 178 |
) { |
| 179 |
$topic['body'] = $post['body']; |
| 180 |
WPF()->sbscrb->Mentioning->Actions->send_mail_to_mentioned_users( $topic, $forum ); |
| 181 |
$this->after_add_topic( $topic, $forum ); |
| 182 |
} |
| 183 |
}else{ |
| 184 |
if( ($topicid = wpforo_bigintval(wpfval($post, 'topicid'))) |
| 185 |
&& ($topic = WPF()->topic->get_topic( $topicid )) |
| 186 |
) { |
| 187 |
WPF()->sbscrb->Mentioning->Actions->send_mail_to_mentioned_users( $post, $topic ); |
| 188 |
$this->after_add_post( $post, $topic ); |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
public function after_delete_topic( $topic ) { |
| 194 |
if( wpfval( $topic, 'topicid' ) ) WPF()->sbscrb->delete( [ 'type' => 'topic', 'itemid' => $topic['topicid'] ] ); |
| 195 |
} |
| 196 |
|
| 197 |
public function after_delete_user( $userid ) { |
| 198 |
WPF()->sbscrb->delete_for_all_active_boards( [ 'userid' => $userid ] ); |
| 199 |
} |
| 200 |
|
| 201 |
public function after_add_topic( $topic, $forum ) { |
| 202 |
if( ! wpfval( $topic, 'url' ) ) $topic['url'] = wpforo_topic( $topic['topicid'], 'url' ); |
| 203 |
if( ! wpfkey( $topic, 'body' ) ) $topic['body'] = wpforo_post( $topic['first_postid'], 'body' ); |
| 204 |
|
| 205 |
$topic = apply_filters( 'wpforo_sbscrb_after_add_topic__topic_filter', $topic ); |
| 206 |
$forum = apply_filters( 'wpforo_sbscrb_after_add_topic__forum_filter', $forum ); |
| 207 |
|
| 208 |
$owner = wpforo_member( $topic ); |
| 209 |
|
| 210 |
$forums_sbs = WPF()->sbscrb->get_subscribes( [ 'itemid' => 0, 'type' => [ 'forums', 'forums-topics' ] ] ); |
| 211 |
$forum_sbs = WPF()->sbscrb->get_subscribes( [ 'itemid' => $topic['forumid'], 'type' => [ 'forum' , 'forum-topic' ] ] ); |
| 212 |
$subscribers = array_merge( $forums_sbs, $forum_sbs ); |
| 213 |
if( wpforo_setting( 'email', 'new_topic_notify' ) ) { |
| 214 |
foreach( wpforo_setting( 'email', 'admin_emails' ) as $admin_email ) $subscribers[] = $admin_email; |
| 215 |
} |
| 216 |
$subscribers = apply_filters( 'wpforo_forum_subscribers', $subscribers, $topic, $forum ); |
| 217 |
|
| 218 |
foreach( $subscribers as $subscriber ) { |
| 219 |
if( is_array( $subscriber ) ) { |
| 220 |
if( $subscriber['userid'] ) { |
| 221 |
$user = WPF()->member->get_member( $subscriber['userid'] ); |
| 222 |
} elseif( $subscriber['user_email'] ) { |
| 223 |
$user = [ 'groupid' => 4, 'groupids' => [4], 'display_name' => ( $subscriber['user_name'] ?: $subscriber['user_email'] ), 'user_email' => $subscriber['user_email'] ]; |
| 224 |
} else { |
| 225 |
continue; |
| 226 |
} |
| 227 |
|
| 228 |
if( ! WPF()->topic->view_access( $topic, $user ) ) continue; |
| 229 |
|
| 230 |
$unsubscribe_link = WPF()->sbscrb->get_unsubscribe_link( $subscriber['confirmkey'] ); |
| 231 |
} else { |
| 232 |
$user = [ 'display_name' => $subscriber, 'user_email' => $subscriber ]; |
| 233 |
$unsubscribe_link = ''; |
| 234 |
} |
| 235 |
|
| 236 |
if( ! wpfval( $user, 'user_email' ) ) continue; |
| 237 |
|
| 238 |
if( wpfval($user, 'user_email') ){ |
| 239 |
$key = 'topicid_' . $topic['topicid'] . '_user_email_' . $user['user_email']; |
| 240 |
if( ! WPF()->ram_cache->exists( $key ) ){ |
| 241 |
|
| 242 |
if( apply_filters( 'break_wpforo_subscriber_send_email_after_add_topic', false, $user, $owner, $topic, $forum ) ) continue; |
| 243 |
|
| 244 |
if( in_array( wpfval($user, 'status'), ['banned', 'inactive'], true ) ) continue; |
| 245 |
if( wpforo_is_users_same( $owner, $user ) ) continue; |
| 246 |
if( wpforo_is_users_same( $user ) ) continue; |
| 247 |
|
| 248 |
$sbj_msg = WPF()->sbscrb->get_sbj_msg( 'new_topic', $forum, $topic, $owner, $user, $unsubscribe_link ); |
| 249 |
wpforo_send_email( $user['user_email'], $sbj_msg['sbj'], $sbj_msg['msg'] ); |
| 250 |
|
| 251 |
WPF()->ram_cache->set( $key, true ); |
| 252 |
} |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
public function after_add_post( $post, $topic ) { |
| 258 |
$post = apply_filters( 'wpforo_sbscrb_after_add_post__post_filter', $post ); |
| 259 |
$topic = apply_filters( 'wpforo_sbscrb_after_add_post__topic_filter', $topic ); |
| 260 |
|
| 261 |
$owner = wpforo_member( $post ); |
| 262 |
$forums_sbs = WPF()->sbscrb->get_subscribes( [ 'itemid' => 0, 'type' => 'forums-topics' ] ); |
| 263 |
$forum_sbs = WPF()->sbscrb->get_subscribes( [ 'itemid' => $post['forumid'], 'type' => 'forum-topic' ] ); |
| 264 |
$topic_sbs = WPF()->sbscrb->get_subscribes( [ 'itemid' => $post['topicid'], 'type' => 'topic' ] ); |
| 265 |
$subscribers = array_merge( $forums_sbs, $forum_sbs, $topic_sbs ); |
| 266 |
if( wpforo_setting( 'email', 'new_reply_notify' ) ) { |
| 267 |
foreach( wpforo_setting( 'email', 'admin_emails' ) as $admin_email ) $subscribers[] = $admin_email; |
| 268 |
} |
| 269 |
$subscribers = apply_filters( 'wpforo_topic_subscribers', $subscribers, $post, $topic ); |
| 270 |
|
| 271 |
foreach( $subscribers as $subscriber ) { |
| 272 |
if( is_array( $subscriber ) ) { |
| 273 |
if( $subscriber['userid'] ) { |
| 274 |
$user = WPF()->member->get_member( $subscriber['userid'] ); |
| 275 |
} elseif( $subscriber['user_email'] ) { |
| 276 |
$user = [ 'groupid' => 4, 'groupids' => [4], 'display_name' => ( $subscriber['user_name'] ?: $subscriber['user_email'] ), 'user_email' => $subscriber['user_email'] ]; |
| 277 |
} else { |
| 278 |
continue; |
| 279 |
} |
| 280 |
|
| 281 |
if( ! WPF()->post->view_access( $post, $user ) ) continue; |
| 282 |
|
| 283 |
$unsubscribe_link = WPF()->sbscrb->get_unsubscribe_link( $subscriber['confirmkey'] ); |
| 284 |
} else { |
| 285 |
$user = [ 'display_name' => $subscriber, 'user_email' => $subscriber ]; |
| 286 |
$unsubscribe_link = ''; |
| 287 |
} |
| 288 |
|
| 289 |
if( ! wpfval( $user, 'user_email' ) ) continue; |
| 290 |
|
| 291 |
$key = 'postid_' . $post['postid'] . '_user_email_' . $user['user_email']; |
| 292 |
if( ! WPF()->ram_cache->exists( $key ) ){ |
| 293 |
|
| 294 |
if( apply_filters( 'break_wpforo_subscriber_send_email_after_add_post', false, $user, $owner, $post, $topic ) ) continue; |
| 295 |
|
| 296 |
if( in_array( wpfval($user, 'status'), ['banned', 'inactive'], true ) ) continue; |
| 297 |
if( wpforo_is_users_same( $owner, $user ) ) continue; |
| 298 |
if( wpforo_is_users_same( $user ) ) continue; |
| 299 |
|
| 300 |
$sbj_msg = WPF()->sbscrb->get_sbj_msg( 'new_post', $topic, $post, $owner, $user, $unsubscribe_link ); |
| 301 |
wpforo_send_email( $user['user_email'], $sbj_msg['sbj'], $sbj_msg['msg'] ); |
| 302 |
|
| 303 |
WPF()->ram_cache->set( $key, true ); |
| 304 |
} |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
############### -- AJAX ACTIONS -- ############### |
| 309 |
|
| 310 |
public function subscribe() { |
| 311 |
wpforo_verify_nonce( 'wpforo_subscribe_ajax' ); |
| 312 |
$return = 0; |
| 313 |
$resp = [ 'notice' => WPF()->notice->get_notices() ]; |
| 314 |
$args = [ |
| 315 |
'itemid' => wpforo_bigintval( wpfval( $_POST, 'itemid' ) ), |
| 316 |
'type' => sanitize_text_field( wpfval( $_POST, 'type' ) ), |
| 317 |
'userid' => WPF()->current_userid, |
| 318 |
'active' => null, |
| 319 |
'user_name' => '', |
| 320 |
'user_email' => '', |
| 321 |
]; |
| 322 |
|
| 323 |
if( ! WPF()->current_userid ) { |
| 324 |
if( WPF()->current_user_email ) $args['user_email'] = WPF()->current_user_email; |
| 325 |
if( WPF()->current_user_display_name ) $args['user_name'] = WPF()->current_user_display_name; |
| 326 |
} |
| 327 |
if( ! $args['userid'] && ! $args['user_email'] ) wp_send_json_error( $resp ); |
| 328 |
|
| 329 |
if( wpfval( $_POST, 'status' ) === 'subscribe' ) { |
| 330 |
$item_title = ''; |
| 331 |
if( $args['type'] === 'forum' ) { |
| 332 |
$forum = WPF()->forum->get_forum( $args['itemid'] ); |
| 333 |
$item_title = wpfval( $forum, 'title' ); |
| 334 |
if( wpfval( $forum, 'forumid' ) && ! WPF()->perm->forum_can( 'vf', $forum['forumid'] ) ) { |
| 335 |
WPF()->notice->add( 'You are not permitted to subscribe here', 'error' ); |
| 336 |
$resp['notice'] = WPF()->notice->get_notices(); |
| 337 |
wp_send_json_error( $resp ); |
| 338 |
} |
| 339 |
} elseif( $args['type'] === 'topic' ) { |
| 340 |
$topic = WPF()->topic->get_topic( $args['itemid'], false ); |
| 341 |
$item_title = wpfval( $topic, 'title' ); |
| 342 |
if( wpfval( $topic, 'forumid' ) ) { |
| 343 |
if( wpfval( $topic, 'private' ) && ! wpforo_is_owner( $topic['userid'], $topic['email'] ) && ! WPF()->perm->forum_can( 'vp', $topic['forumid'] ) ) { |
| 344 |
WPF()->notice->add( 'You are not permitted to subscribe here', 'error' ); |
| 345 |
$resp['notice'] = WPF()->notice->get_notices(); |
| 346 |
wp_send_json_error( $resp ); |
| 347 |
} |
| 348 |
} |
| 349 |
} elseif( $args['type'] === 'user' ) { |
| 350 |
$member = WPF()->member->get_member( $args['itemid'] ); |
| 351 |
$item_title = wpforo_user_dname( $member ); |
| 352 |
if( $args['itemid'] === WPF()->current_userid ) { |
| 353 |
WPF()->notice->add( 'You are not permitted to subscribe with you', 'error' ); |
| 354 |
$resp['notice'] = WPF()->notice->get_notices(); |
| 355 |
wp_send_json_error( $resp ); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
$args['confirmkey'] = WPF()->sbscrb->get_confirm_key(); |
| 360 |
|
| 361 |
if( wpforo_setting( 'subscriptions', 'subscribe_confirmation' ) ) { |
| 362 |
$args['active'] = 0; |
| 363 |
############### Sending Email ################## |
| 364 |
$confirmlink = WPF()->sbscrb->get_confirm_link( $args ); |
| 365 |
$member_name = ( WPF()->current_userid ? wpforo_user_dname( WPF()->current_user ) : ( $args['user_name'] ?: $args['user_email'] ) ); |
| 366 |
$subject = wpforo_setting( 'subscriptions', 'confirmation_email_subject' ); |
| 367 |
$message = wpforo_setting( 'subscriptions', 'confirmation_email_message' ); |
| 368 |
$from_tags = [ "[user_display_name]", "[entry_title]", "[confirm_link]" ]; |
| 369 |
$to_words = [ |
| 370 |
sanitize_text_field( $member_name ), |
| 371 |
sprintf( '<strong>%1$s</strong>', sanitize_text_field( $item_title ) ), |
| 372 |
sprintf( '<br><br><a target="_blank" href="%1$s"> %2$s </a>', esc_url( (string) $confirmlink ), wpforo_phrase( 'Confirm my subscription', false ) ), |
| 373 |
]; |
| 374 |
$subject = stripslashes( strip_tags( str_replace( $from_tags, $to_words, (string) $subject ) ) ); |
| 375 |
$message = stripslashes( str_replace( $from_tags, $to_words, (string) $message ) ); |
| 376 |
$message = wpforo_kses( $message, 'email' ); |
| 377 |
|
| 378 |
add_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type', 999 ); |
| 379 |
$headers = wpforo_mail_headers(); |
| 380 |
|
| 381 |
if( wp_mail( WPF()->current_user_email, sanitize_text_field( $subject ), $message, $headers ) ) { |
| 382 |
if( WPF()->sbscrb->add( $args ) ) $return = 1; |
| 383 |
} else { |
| 384 |
WPF()->notice->add( 'Can\'t send confirmation email', 'error' ); |
| 385 |
} |
| 386 |
remove_filter( 'wp_mail_content_type', 'wpforo_set_html_content_type' ); |
| 387 |
############### Sending Email end ############## |
| 388 |
} else { |
| 389 |
$args['active'] = 1; |
| 390 |
if( WPF()->sbscrb->add( $args ) ) $return = 1; |
| 391 |
} |
| 392 |
} elseif( wpfval( $_POST, 'status' ) === 'unsubscribe' ) { |
| 393 |
if( ( $type = wpfval( $args, 'type' ) ) && is_scalar( $type ) && in_array( $type, ['forum','forum-topic'], true ) ) $args['type'] = ['forum','forum-topic']; |
| 394 |
if( $subscribe = WPF()->sbscrb->get_subscribe( $args ) ){ |
| 395 |
$return = (int) WPF()->sbscrb->delete( $subscribe['confirmkey'] ); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
$resp['notice'] = WPF()->notice->get_notices(); |
| 400 |
if( $return ) { |
| 401 |
wp_send_json_success( $resp ); |
| 402 |
} else { |
| 403 |
wp_send_json_error( $resp ); |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
public function unsubscribe() { |
| 408 |
wpforo_verify_nonce( 'wpforo_unsubscribe' ); |
| 409 |
$r = false; |
| 410 |
|
| 411 |
$boardid = wpfkey( $_POST, 'boardid' ) ? (int) $_POST['boardid'] : WPF()->board->get_current( 'boardid' ); |
| 412 |
WPF()->change_board( $boardid ); |
| 413 |
|
| 414 |
if( $key = sanitize_text_field( wpfval( $_POST, 'key' ) ) ) $r = WPF()->sbscrb->delete( $key ); |
| 415 |
|
| 416 |
$data = [ 'notice' => WPF()->notice->get_notices() ]; |
| 417 |
if( $r ){ |
| 418 |
wp_send_json_success( $data ); |
| 419 |
}else{ |
| 420 |
wp_send_json_error( $data ); |
| 421 |
} |
| 422 |
} |
| 423 |
} |
| 424 |
|