| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace features; |
| 3 | 3 | |
| 4 | -class BBP_Private_Replies { | |
| 4 | +class Forumax_Private_Replies { | |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * The capability required to view private posts. |
| 8 | 8 | * |
| @@ -25,9 +25,9 @@ | ||
| 25 | 25 | // Allow others to change the capability required to view private posts. |
| 26 | 26 | add_action( 'plugins_loaded', [ $this, 'filter_capability' ] ); |
| 27 | 27 | |
| 28 | 28 | // show the "Private Reply?" checkbox |
| 29 | - add_action( 'bbp_theme_before_reply_form_submit_wrapper', [ $this, 'checkbox' ] ); | |
| 29 | + add_action( 'frmx_reply_options', [ $this, 'checkbox' ] ); | |
| 30 | 30 | |
| 31 | 31 | // save the private reply state |
| 32 | 32 | add_action( 'bbp_new_reply', [ $this, 'update_reply' ], 0, 6 ); |
| 33 | 33 | add_action( 'bbp_edit_reply', [ $this, 'update_reply' ], 0, 6 ); |
| @@ -78,23 +78,26 @@ | ||
| 78 | 78 | */ |
| 79 | 79 | public function checkbox() { |
| 80 | 80 | |
| 81 | 81 | ?> |
| 82 | - <p> | |
| 83 | - | |
| 84 | - <input name="bbp_private_reply" id="bbp_private_reply" type="checkbox"<?php checked( '1', $this->is_private( bbp_get_reply_id() ) ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" /> | |
| 85 | - | |
| 86 | - <?php if ( bbp_is_reply_edit() && ( get_the_author_meta( 'ID' ) != bbp_get_current_user_id() ) ) : ?> | |
| 87 | - | |
| 88 | - <label for="bbp_private_reply"><?php esc_html_e( "Set author's post as private.", 'ama-core' ); ?></label> | |
| 89 | - | |
| 90 | - <?php else : ?> | |
| 91 | - | |
| 92 | - <label for="bbp_private_reply"><?php esc_html_e( 'Set as private reply', 'ama-core' ); ?></label> | |
| 93 | - | |
| 94 | - <?php endif; ?> | |
| 95 | - | |
| 96 | - </p> | |
| 82 | + <div class="frmx-option-row"> | |
| 83 | + <div class="frmx-option-icon frmx-option-icon--private"> | |
| 84 | + <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg> | |
| 85 | + </div> | |
| 86 | + <label for="bbp_private_reply" class="frmx-option-label"> | |
| 87 | + <?php if ( bbp_is_reply_edit() && ( get_the_author_meta( 'ID' ) != bbp_get_current_user_id() ) ) : ?> | |
| 88 | + <span class="frmx-option-title"><?php esc_html_e( 'Private reply', 'forumax' ); ?></span> | |
| 89 | + <span class="frmx-option-desc"><?php esc_html_e( "Set author's post as private", 'forumax' ); ?></span> | |
| 90 | + <?php else : ?> | |
| 91 | + <span class="frmx-option-title"><?php esc_html_e( 'Set as private reply', 'forumax' ); ?></span> | |
| 92 | + <span class="frmx-option-desc"><?php esc_html_e( 'Only visible to moderators and topic author', 'forumax' ); ?></span> | |
| 93 | + <?php endif; ?> | |
| 94 | + </label> | |
| 95 | + <label class="frmx-toggle" for="bbp_private_reply"> | |
| 96 | + <input name="bbp_private_reply" id="bbp_private_reply" type="checkbox"<?php checked( '1', $this->is_private( bbp_get_reply_id() ) ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" /> | |
| 97 | + <span class="frmx-toggle-slider"></span> | |
| 98 | + </label> | |
| 99 | + </div> | |
| 97 | 100 | <?php |
| 98 | 101 | |
| 99 | 102 | } |
| 100 | 103 | |
| @@ -159,8 +162,45 @@ | ||
| 159 | 162 | } |
| 160 | 163 | |
| 161 | 164 | |
| 162 | 165 | /** |
| 166 | + * Determines if the current user can view a private reply. | |
| 167 | + * | |
| 168 | + * @since 1.0 | |
| 169 | + * | |
| 170 | + * @param int $reply_id The ID of the reply. | |
| 171 | + * @return bool | |
| 172 | + */ | |
| 173 | + public function can_view_private_reply( $reply_id = 0 ) { | |
| 174 | + | |
| 175 | + if ( empty( $reply_id ) ) { | |
| 176 | + $reply_id = bbp_get_reply_id( $reply_id ); | |
| 177 | + } | |
| 178 | + | |
| 179 | + $current_user = is_user_logged_in() ? wp_get_current_user() : false; | |
| 180 | + $topic_author = bbp_get_topic_author_id( bbp_get_reply_topic_id( $reply_id ) ); | |
| 181 | + $reply_author = bbp_get_reply_author_id( $reply_id ); | |
| 182 | + | |
| 183 | + if ( ! empty( $current_user ) && $topic_author === $current_user->ID && user_can( $reply_author, $this->capability ) ) { | |
| 184 | + // Let the thread author view replies if the reply author is from a moderator. | |
| 185 | + return true; | |
| 186 | + } | |
| 187 | + | |
| 188 | + if ( ! empty( $current_user ) && $reply_author === $current_user->ID ) { | |
| 189 | + // Let the reply author view their own reply. | |
| 190 | + return true; | |
| 191 | + } | |
| 192 | + | |
| 193 | + if ( current_user_can( $this->capability ) ) { | |
| 194 | + // Let moderators view all replies. | |
| 195 | + return true; | |
| 196 | + } | |
| 197 | + | |
| 198 | + return false; | |
| 199 | + } | |
| 200 | + | |
| 201 | + | |
| 202 | + /** | |
| 163 | 203 | * Hides the reply content for users that do not have permission to view it |
| 164 | 204 | * |
| 165 | 205 | * @since 1.0 |
| 166 | 206 | * |
| @@ -170,39 +210,21 @@ | ||
| 170 | 210 | * @return string |
| 171 | 211 | */ |
| 172 | 212 | public function hide_reply( $content = '', $reply_id = 0 ) { |
| 173 | 213 | |
| 214 | + // if bbPress isn't active, bail | |
| 215 | + if ( ! function_exists( 'bbp_get_reply_id' ) ) { | |
| 216 | + return $content; | |
| 217 | + } | |
| 218 | + | |
| 174 | 219 | if ( empty( $reply_id ) ) { |
| 175 | 220 | $reply_id = bbp_get_reply_id( $reply_id ); |
| 176 | 221 | } |
| 177 | 222 | |
| 178 | 223 | if ( $this->is_private( $reply_id ) ) { |
| 179 | - | |
| 180 | - $can_view = false; | |
| 181 | - $current_user = is_user_logged_in() ? wp_get_current_user() : false; | |
| 182 | - $topic_author = bbp_get_topic_author_id(); | |
| 183 | - $reply_author = bbp_get_reply_author_id( $reply_id ); | |
| 184 | - | |
| 185 | - if ( ! empty( $current_user ) && $topic_author === $current_user->ID && user_can( $reply_author, $this->capability ) ) { | |
| 186 | - // Let the thread author view replies if the reply author is from a moderator | |
| 187 | - $can_view = true; | |
| 224 | + if ( ! $this->can_view_private_reply( $reply_id ) ) { | |
| 225 | + $content = '<div class="alert alert-danger">' . esc_html__( 'This reply has been marked as private.', 'forumax' ) . '</div>'; | |
| 188 | 226 | } |
| 189 | - | |
| 190 | - if ( ! empty( $current_user ) && $reply_author === $current_user->ID ) { | |
| 191 | - // Let the reply author view their own reply | |
| 192 | - $can_view = true; | |
| 193 | - } | |
| 194 | - | |
| 195 | - if ( current_user_can( $this->capability ) ) { | |
| 196 | - // Let moderators view all replies | |
| 197 | - $can_view = true; | |
| 198 | - } | |
| 199 | - | |
| 200 | - if ( ! $can_view ) { | |
| 201 | - $content = '<div class="alert alert-danger">' . esc_html__( 'This reply has been marked as private.', 'ama-core' ) . '</div>'; | |
| 202 | - } else { | |
| 203 | - $content = '<div class="alert alert-info">' . esc_html__( 'This is a private reply.', 'ama-core' ) . '</div>' . $content; | |
| 204 | - } | |
| 205 | 227 | } |
| 206 | 228 | |
| 207 | 229 | return $content; |
| 208 | 230 | } |
| @@ -253,20 +275,19 @@ | ||
| 253 | 275 | $reply_author = bbp_get_reply_author_id( $reply_id ); |
| 254 | 276 | $reply_author_name = bbp_get_reply_author_display_name( $reply_id ); |
| 255 | 277 | |
| 256 | 278 | // Strip tags from text and setup mail data |
| 257 | - $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); | |
| 258 | - $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) ); | |
| 279 | + $topic_title = wp_strip_all_tags( bbp_get_topic_title( $topic_id ) ); | |
| 280 | + $reply_content = wp_strip_all_tags( bbp_get_reply_content( $reply_id ) ); | |
| 259 | 281 | $reply_url = bbp_get_reply_url( $reply_id ); |
| 260 | 282 | $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
| 283 | + $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id ); | |
| 261 | 284 | |
| 262 | - $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id ); | |
| 263 | - | |
| 264 | 285 | // Array to hold BCC's |
| 265 | - $headers = []; | |
| 286 | + $headers = []; | |
| 266 | 287 | |
| 267 | 288 | // Setup the From header |
| 268 | - $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . $this->get_no_reply() . '>'; | |
| 289 | + $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . $this->get_no_reply() . '>'; | |
| 269 | 290 | |
| 270 | 291 | // Get topic subscribers and bail if empty |
| 271 | 292 | $user_ids = bbp_get_topic_subscribers( $topic_id, true ); |
| 272 | 293 | if ( empty( $user_ids ) ) { |
| @@ -304,8 +325,14 @@ | ||
| 304 | 325 | * |
| 305 | 326 | * @return bool |
| 306 | 327 | */ |
| 307 | 328 | public function reply_post_class( $classes ) { |
| 329 | + | |
| 330 | + // if bbPress isn't active, bail | |
| 331 | + if ( ! function_exists( 'bbp_get_reply_id' ) ) { | |
| 332 | + return $classes; | |
| 333 | + } | |
| 334 | + | |
| 308 | 335 | $reply_id = bbp_get_reply_id(); |
| 309 | 336 | |
| 310 | 337 | // only apply the class to replies |
| 311 | 338 | if ( bbp_get_reply_post_type() != get_post_type( $reply_id ) ) { |
| @@ -321,6 +348,6 @@ | ||
| 321 | 348 | |
| 322 | 349 | } // end class |
| 323 | 350 | |
| 324 | 351 | // instantiate our plugin's class. |
| 325 | -$GLOBALS['bbp_private_replies'] = new BBP_Private_Replies(); | |
| 352 | +$GLOBALS['bbp_private_replies'] = new Forumax_Private_Replies(); | |
| 326 | 353 | ?> |