init_hooks(); } private function init_hooks() { add_action( 'wpforo_template_profile_subscriptions_head_bar', function(){ $this->manager_form(); } ); add_action( 'wpforo_template_forum_head_bar_action_links', function(){ echo $this->forum_subscribe_link(); } ); add_action( 'wpforo_template_topic_head_bar_action_links', function(){ echo $this->forum_subscribe_link(); } ); add_action( 'wpforo_template_post_head_bar_action_links', function(){ echo $this->topic_subscribe_link(); } ); add_action( 'wpforo_editor_topic_submit_before', function( $forum, $values ){ if( !$values ) echo $this->topic_form_checkbox( $forum ); }, 10, 2 ); add_action( 'wpforo_editor_post_submit_before', function( $topic, $values, $forum ){ if( !$values ){ $layout = $topic['layout'] = WPF()->forum->get_layout( $forum ); echo $this->post_form_checkbox( $topic, $layout ); } }, 10, 3 ); add_action( 'wpforo_portable_editor_post_submit_before', function( $topic, $values, $forum ){ if( !$values ){ $layout = $topic['layout'] = WPF()->forum->get_layout( $forum ); echo $this->post_form_checkbox( $topic, $layout ); } }, 10, 3); } public function manager_form( $userid = 0 ) { $userid = intval( $userid ); if( ! $userid ) { $userid = WPF()->current_object['userid']; if( ! $userid ) $userid = WPF()->current_userid; } if( ( WPF()->current_userid !== $userid && ! wpforo_current_user_is( 'admin' ) ) || ( wpforo_setting( 'subscriptions', 'subscribe_confirmation' ) && ! wpforo_current_user_is( 'admin' ) && ! WPF()->sbscrb->is_email_confirmed() ) ) return; $sbs = []; $allposts_checked = ''; $alltopics_checked = ''; if( WPF()->sbscrb->get_subscribes( [ 'type' => 'forums-topics', 'userid' => $userid, 'active' => null ] ) ) { $allposts_checked = ' checked'; } if( WPF()->sbscrb->get_subscribes( [ 'type' => 'forums', 'userid' => $userid, 'active' => null ] ) ) { $alltopics_checked = ' checked'; } if( ! $allposts_checked && ! $alltopics_checked ) { if( $sbs_forum = WPF()->sbscrb->get_subscribes( [ 'type' => 'forum', 'userid' => $userid, 'active' => null ] ) ) { foreach( $sbs_forum as $s ) $sbs[ $s['itemid'] ] = $s['type']; } if( $sbs_forum_topic = WPF()->sbscrb->get_subscribes( [ 'type' => 'forum-topic', 'userid' => $userid, 'active' => null ] ) ) { foreach( $sbs_forum_topic as $s ) $sbs[ $s['itemid'] ] = $s['type']; } } ?>

>
>
    forum->tree( 'subscribe_manager_form', false, $sbs ); ?>
current_userid || WPF()->current_user_email ) { if( WPF()->current_object['forumid'] && WPF()->perm->forum_can( 'sb', WPF()->current_object['forumid'] ) ) { if( WPF()->sbscrb->get_subscribe( [ "userid" => WPF()->current_userid, "itemid" => 0, "type" => ['forums','forums-topics'], 'user_email' => WPF()->current_user_email, ] ) ) return ''; $args = [ "userid" => WPF()->current_userid, "itemid" => WPF()->current_object['forumid'], "type" => ['forum','forum-topic'], 'user_email' => WPF()->current_user_email, ]; if( WPF()->sbscrb->get_subscribe( $args ) ) { return sprintf( '%2$s', WPF()->current_object['forumid'], wpforo_phrase( 'Unsubscribe', false ) ); } return sprintf( ' %2$s', WPF()->current_object['forumid'], wpforo_phrase( 'Subscribe for new topics', false ) ); } } return ''; } public function topic_subscribe_link() { if( WPF()->current_userid || WPF()->current_user_email ) { if( WPF()->current_object['forumid'] && WPF()->perm->forum_can( 'sb', WPF()->current_object['forumid'] ) ) { if( WPF()->sbscrb->get_subscribe( [ "userid" => WPF()->current_userid, "itemid" => 0, "type" => ['forums','forums-topics'], 'user_email' => WPF()->current_user_email, ] ) ) return ' '; $args = [ "userid" => WPF()->current_userid, "itemid" => WPF()->current_object['topicid'], "type" => "topic", 'user_email' => WPF()->current_user_email, ]; if( WPF()->sbscrb->get_subscribe( $args ) ) { return sprintf( '%2$s', WPF()->current_object['topicid'], wpforo_phrase( 'Unsubscribe', false ) ); } return sprintf( ' %2$s', WPF()->current_object['topicid'], wpforo_phrase( 'Subscribe for new replies', false ) ); } } return ' '; } public function topic_form_checkbox( $forum ) { if( wpforo_setting( 'subscriptions', 'subscribe_checkbox_on_post_editor' ) && WPF()->perm->forum_can( 'sb', $forum['forumid'] ) ) { if( WPF()->sbscrb->get_subscribe( [ "userid" => WPF()->current_userid, "itemid" => 0, "type" => ['forums-topics'], 'user_email' => WPF()->current_user_email, ] ) ) return ''; if( WPF()->sbscrb->get_subscribe( [ "userid" => WPF()->current_userid, "itemid" => $forum['forumid'], "type" => ['forum-topic'], 'user_email' => WPF()->current_user_email, ] ) ) return ''; return sprintf( '
 
', uniqid(), wpforo_setting( 'subscriptions', 'subscribe_checkbox_default_status' ) ? 'checked' : '', WPF()->forum->get_layout( $forum ) === 3 ? wpforo_phrase( 'Subscribe to this question', false ) : wpforo_phrase( 'Subscribe to this topic', false ) ); } return ''; } public function post_form_checkbox( $topic, $layout = 1 ) { if( wpforo_setting( 'subscriptions', 'subscribe_checkbox_on_post_editor' ) && WPF()->perm->forum_can( 'sb', $topic['forumid'] ) ) { if( WPF()->sbscrb->get_subscribe( [ "userid" => WPF()->current_userid, "itemid" => 0, "type" => ['forums-topics'], 'user_email' => WPF()->current_user_email, ] ) ) return ''; if( WPF()->sbscrb->get_subscribe( [ "userid" => WPF()->current_userid, "itemid" => $topic['forumid'], "type" => ['forum-topic'], 'user_email' => WPF()->current_user_email, ] ) ) return ''; $topic = [ "userid" => WPF()->current_userid, "itemid" => intval( $topic['topicid'] ), "type" => "topic" ]; $subscribe = WPF()->sbscrb->get_subscribe( $topic ); if( ! isset( $subscribe['subid'] ) ) { return sprintf( '
 
', uniqid(), wpforo_setting( 'subscriptions', 'subscribe_checkbox_default_status' ) ? 'checked' : '', $layout === 3 ? wpforo_phrase( 'Subscribe to this question', false ) : wpforo_phrase( 'Subscribe to this topic', false ) ); } } return ''; } }