| 1 |
<?php |
| 2 |
add_action( 'wp_enqueue_scripts', function() { |
| 3 |
if( is_rtl() ) { |
| 4 |
wp_register_style( 'wpforo-bp-rtl', WPF()->tpl->template_url . '/integration/buddypress/style-rtl.css', false, WPFORO_VERSION ); |
| 5 |
wp_enqueue_style( 'wpforo-bp-rtl' ); |
| 6 |
} else { |
| 7 |
wp_register_style( 'wpforo-bp', WPF()->tpl->template_url . '/integration/buddypress/style.css', false, WPFORO_VERSION ); |
| 8 |
wp_enqueue_style( 'wpforo-bp' ); |
| 9 |
} |
| 10 |
if( ! is_wpforo_page() ) { |
| 11 |
wp_enqueue_style( 'dashicons' ); |
| 12 |
} |
| 13 |
} ); |
| 14 |
|
| 15 |
/** |
| 16 |
* Insert BuddyPress Activity |
| 17 |
* |
| 18 |
* @param array $args |
| 19 |
* |
| 20 |
* @return bool|int |
| 21 |
*/ |
| 22 |
function wpforo_bp_activity( $args = [] ) { |
| 23 |
if( ! function_exists( 'bp_activity_add' ) || ! is_user_logged_in() ) return false; |
| 24 |
$default = [ |
| 25 |
'action' => '', |
| 26 |
'title' => '', |
| 27 |
'content' => '', |
| 28 |
'component' => 'community', |
| 29 |
'type' => false, |
| 30 |
'primary_link' => '', |
| 31 |
'user_id' => '', |
| 32 |
'item_id' => false, |
| 33 |
'hide_sitewide' => false, |
| 34 |
'is_spam' => false, |
| 35 |
]; |
| 36 |
|
| 37 |
$args = wpforo_parse_args( $args, $default ); |
| 38 |
if( function_exists( 'bp_activity_add' ) ) { |
| 39 |
if( function_exists( 'bp_loggedin_user_domain' ) ) { |
| 40 |
$user_url = bp_loggedin_user_domain( $args['user_id'] ); |
| 41 |
if( function_exists( 'bp_core_get_user_displayname' ) ) { |
| 42 |
$user_name = bp_core_get_user_displayname( $args['user_id'] ); |
| 43 |
$activity_types = apply_filters( 'wpforo_buddypress_activity_types', ['wpforo_topic', 'wpforo_post', 'wpforo_like']); |
| 44 |
if( $user_url && $user_name ) { |
| 45 |
$user_link = '<a href="' . esc_url( (string) $user_url ) . '">' . esc_html( $user_name ) . '</a>'; |
| 46 |
$content_link = ( $args['primary_link'] && $args['title'] ) ? '<a href="' . esc_url( (string) $args['primary_link'] ) . '">' . esc_html( $args['title'] ) . '</a> - ' : $args['title'] . ' - '; |
| 47 |
if( $args['type'] == 'wpforo_topic' ) { |
| 48 |
$args['action'] = sprintf( wpforo_phrase( '%s posted a new topic %s', false ), $user_link, $content_link ); |
| 49 |
} elseif( $args['type'] == 'wpforo_post' ) { |
| 50 |
$args['action'] = sprintf( wpforo_phrase( '%s replied to the topic %s', false ), $user_link, $content_link ); |
| 51 |
} elseif( $args['type'] == 'wpforo_like' ) { |
| 52 |
$args['action'] = sprintf( wpforo_phrase( '%s liked forum post %s', false ), $user_link, $content_link ); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
if( in_array( $args['type'], $activity_types ) ){ |
| 59 |
return $activity_id = bp_activity_add( $args ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Delete BuddyPress Activity |
| 68 |
* |
| 69 |
* @param array $args |
| 70 |
*/ |
| 71 |
function wpforo_bp_activity_delete( $args = [] ) { |
| 72 |
if( ! function_exists( 'bp_activity_delete' ) || ! is_user_logged_in() ) return; |
| 73 |
$default = [ |
| 74 |
'action' => '', |
| 75 |
'title' => '', |
| 76 |
'content' => '', |
| 77 |
'component' => 'community', |
| 78 |
'type' => false, |
| 79 |
'primary_link' => '', |
| 80 |
'user_id' => '', |
| 81 |
'item_id' => false, |
| 82 |
'hide_sitewide' => false, |
| 83 |
'is_spam' => false, |
| 84 |
]; |
| 85 |
|
| 86 |
$args = wpforo_parse_args( $args, $default ); |
| 87 |
if( function_exists( 'bp_activity_delete' ) ) { |
| 88 |
bp_activity_delete( $args ); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Disable comment button for wpForo activity |
| 94 |
* |
| 95 |
* @param bool $can_comment |
| 96 |
* |
| 97 |
* @return bool |
| 98 |
*/ |
| 99 |
function wpforo_bp_activity_disable_comment( $can_comment = true ) { |
| 100 |
if( false === $can_comment ) return $can_comment; |
| 101 |
if( function_exists( 'bp_get_activity_action_name' ) ) { |
| 102 |
$action_name = bp_get_activity_type(); |
| 103 |
$disabled_actions = [ 'wpforo_topic', 'wpforo_post', 'wpforo_like' ]; |
| 104 |
$disabled_actions = apply_filters( 'wpforo_bp_activity_disable_comment', $disabled_actions ); |
| 105 |
if( in_array( $action_name, $disabled_actions ) ) { |
| 106 |
$can_comment = false; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
return $can_comment; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Register BuddyPress Activities |
| 115 |
*/ |
| 116 |
|
| 117 |
add_action( 'bp_register_activity_actions', function() { |
| 118 |
bp_activity_set_action( 'community', 'wpforo_topic', wpforo_phrase( 'Forum topic', false ), '', wpforo_phrase( 'Forum topic', false ), [ 'member' ] ); |
| 119 |
bp_activity_set_action( 'community', 'wpforo_post', wpforo_phrase( 'Forum post', false ), '', wpforo_phrase( 'Forum post', false ), [ 'member' ] ); |
| 120 |
bp_activity_set_action( 'community', 'wpforo_like', wpforo_phrase( 'Forum post like', false ), '', wpforo_phrase( 'Forum post like', false ), [ 'member' ] ); |
| 121 |
} ); |
| 122 |
add_filter( 'bp_activity_can_comment', 'wpforo_bp_activity_disable_comment' ); |
| 123 |
|
| 124 |
function wpforo_bp_forums_screen_topics() { |
| 125 |
add_action( 'bp_template_content', function() { |
| 126 |
if( isset( $_GET['wpfpaged'] ) && intval( $_GET['wpfpaged'] ) ) $paged = intval( $_GET['wpfpaged'] ); |
| 127 |
$paged = ( isset( $paged ) && $paged ) ? $paged : 1; |
| 128 |
$args = [ |
| 129 |
'offset' => ( $paged - 1 ) * WPF()->current_object['items_per_page'], |
| 130 |
'row_count' => WPF()->current_object['items_per_page'], |
| 131 |
'userid' => bp_displayed_user_id(), |
| 132 |
'orderby' => 'modified', |
| 133 |
'check_private' => true, |
| 134 |
]; |
| 135 |
$activities = WPF()->topic->get_topics( $args, $items_count ); |
| 136 |
?> |
| 137 |
<div id="wpforo-topics" class="wpforo-activity"> |
| 138 |
<h2 class="entry-title"><?php wpforo_phrase( 'Forum Topics Started' ); ?></h2> |
| 139 |
<?php if( empty( $activities ) ) : ?> |
| 140 |
<p class="wpf-p-error"> <?php wpforo_phrase( 'No activity found for this member.' ) ?> </p> |
| 141 |
<?php else: ?> |
| 142 |
<table> |
| 143 |
<?php $bg = false; |
| 144 |
foreach( $activities as $activity ) : ?> |
| 145 |
<tr> |
| 146 |
<td class="wpf-activity-title"> |
| 147 |
<span class="dashicons dashicons-admin-comments"></span> |
| 148 |
<?php |
| 149 |
$topic = wpforo_topic( $activity['topicid'] ); |
| 150 |
if( ! empty( $topic ) ) { |
| 151 |
$topic_url = $topic['url']; |
| 152 |
$topic_title = $topic['title']; |
| 153 |
if( ! $topic_url ) $topic_url = '#'; |
| 154 |
if( ! $topic_title ) $topic_title = wpforo_phrase( 'Topic link' ); |
| 155 |
?><a href="<?php echo esc_url( (string) $topic_url ) ?>" class="wpf-item-title"><?php echo $topic_title ?></a><?php |
| 156 |
} |
| 157 |
if( wpfval( $topic, 'forumid' ) ) { |
| 158 |
$forum = wpforo_forum( $topic['forumid'] ); |
| 159 |
$forum_url = $forum['url']; |
| 160 |
$forum_title = $forum['title']; |
| 161 |
if( ! $forum_url ) $forum_url = '#'; |
| 162 |
if( ! $forum_title ) $forum_url = wpforo_phrase( 'Forum link' ); |
| 163 |
?><p style="font-style: italic"><span><?php echo wpforo_phrase( 'in forum', false ) ?></span> <a href="<?php echo esc_url( (string) $forum_url ) ?>"><?php echo $forum_title ?></a></p><?php |
| 164 |
} |
| 165 |
?> |
| 166 |
</td> |
| 167 |
<td class="wpf-activity-users"> |
| 168 |
<?php $members = WPF()->topic->members( $topic['topicid'], 3 ); ?> |
| 169 |
<?php if( ! empty( $members ) ): foreach( $members as $member ): ?> |
| 170 |
<?php if( ! empty( $member ) ): ?> |
| 171 |
<a href="<?php echo bp_members_get_user_url( $member['userid'] ) ?>" title="<?php echo esc_attr( bp_core_get_user_displayname( $member['userid'] ) ); ?>"><?php echo wpforo_user_avatar( $member, 30 ) ?></a> |
| 172 |
<?php endif; ?> |
| 173 |
<?php endforeach; endif; ?> |
| 174 |
</td> |
| 175 |
<td class="wpf-activity-posts"> |
| 176 |
<?php echo $activity['posts']; ?><?php wpforo_phrase( 'posts' ); ?> |
| 177 |
</td> |
| 178 |
<td class="wpf-activity-date"><?php wpforo_date( $topic['created'] ); ?></td> |
| 179 |
</tr> |
| 180 |
<?php endforeach ?> |
| 181 |
</table> |
| 182 |
<div class="wpf-activity-foot"><?php WPF()->tpl->pagenavi( $paged, $items_count, null, false ); ?></div> |
| 183 |
<div style="clear: both"></div> |
| 184 |
<?php endif; ?> |
| 185 |
</div> |
| 186 |
<?php |
| 187 |
} ); |
| 188 |
bp_core_load_template( apply_filters( 'wpforo_bp_forums_screen_topics', 'members/single/plugins' ) ); |
| 189 |
} |
| 190 |
|
| 191 |
function wpforo_bp_forums_screen_replies() { |
| 192 |
add_action( 'bp_template_content', function() { |
| 193 |
if( isset( $_GET['wpfpaged'] ) && intval( $_GET['wpfpaged'] ) ) $paged = intval( $_GET['wpfpaged'] ); |
| 194 |
$paged = ( isset( $paged ) && $paged ) ? $paged : 1; |
| 195 |
$args = [ |
| 196 |
'offset' => ( $paged - 1 ) * WPF()->current_object['items_per_page'], |
| 197 |
'row_count' => WPF()->current_object['items_per_page'], |
| 198 |
'userid' => bp_displayed_user_id(), |
| 199 |
'orderby' => '`created` DESC', |
| 200 |
'check_private' => true, |
| 201 |
]; |
| 202 |
$activities = WPF()->post->get_posts( $args, $items_count ); |
| 203 |
?> |
| 204 |
<div id="wpforo-posts" class="wpforo-activity"> |
| 205 |
<h2 class="entry-title"><?php wpforo_phrase( 'Forum Replies Created' ); ?></h2> |
| 206 |
<?php if( empty( $activities ) ) : ?> |
| 207 |
<p class="wpf-p-error"> <?php wpforo_phrase( 'No activity found for this member.' ) ?> </p> |
| 208 |
<?php else: ?> |
| 209 |
<table> |
| 210 |
<?php foreach( $activities as $activity ) : ?> |
| 211 |
<tr> |
| 212 |
<td class="wpf-activity-title"> |
| 213 |
<span class="dashicons dashicons-format-chat"></span> |
| 214 |
<?php |
| 215 |
$post = wpforo_post( $activity['postid'] ); |
| 216 |
if( ! empty( $post ) ) { |
| 217 |
$post_url = $post['url']; |
| 218 |
$post_title = $post['title']; |
| 219 |
if( ! $post_url ) $post_url = '#'; |
| 220 |
if( ! $post_title ) $post_title = wpforo_phrase( 'Post link' ); |
| 221 |
?><a href="<?php echo esc_url( (string) $post_url ) ?>" class="wpf-item-title"><?php echo $post_title ?></a><?php |
| 222 |
} |
| 223 |
?> |
| 224 |
<?php if( wpfval( $post, 'body' ) ): ?> |
| 225 |
<p class="wpf-post-excerpt" style="font-style: italic"> |
| 226 |
<?php |
| 227 |
$body = wpforo_content_filter( $post['body'], $post ); |
| 228 |
$body = preg_replace( '#\[attach][^\[\]]*\[/attach]#i', '', strip_shortcodes( strip_tags( $body ) ) ); |
| 229 |
wpforo_text( $body, 200 ); |
| 230 |
?> |
| 231 |
</p> |
| 232 |
<?php endif; ?> |
| 233 |
</td> |
| 234 |
<td class="wpf-activity-forum"> |
| 235 |
<?php |
| 236 |
if( wpfval( $post, 'forumid' ) ) { |
| 237 |
$forum = wpforo_forum( $post['forumid'] ); |
| 238 |
$forum_url = $forum['url']; |
| 239 |
$forum_title = $forum['title']; |
| 240 |
if( ! $forum_url ) $forum_url = '#'; |
| 241 |
if( ! $forum_title ) $forum_url = wpforo_phrase( 'Forum link' ); |
| 242 |
?><p style="font-style: italic"><span><?php echo wpforo_phrase( 'in forum', false ) ?></span> <a href="<?php echo esc_url( (string) $forum_url ) ?>"><?php echo $forum_title ?></a></p><?php |
| 243 |
} |
| 244 |
?> |
| 245 |
</td> |
| 246 |
<td class="wpf-activity-date"><?php wpforo_date( $post['created'] ); ?></td> |
| 247 |
</tr> |
| 248 |
<?php endforeach ?> |
| 249 |
</table> |
| 250 |
<div class="wpf-activity-foot"><?php WPF()->tpl->pagenavi( $paged, $items_count, null, false ); ?></div> |
| 251 |
<div style="clear: both"></div> |
| 252 |
<?php endif; ?> |
| 253 |
</div> |
| 254 |
<?php |
| 255 |
} ); |
| 256 |
bp_core_load_template( apply_filters( 'wpforo_bp_forums_screen_replies', 'members/single/plugins' ) ); |
| 257 |
} |
| 258 |
|
| 259 |
function wpforo_bp_forums_screen_likes() { |
| 260 |
add_action( 'bp_template_content', function() { |
| 261 |
if( isset( $_GET['wpfpaged'] ) && intval( $_GET['wpfpaged'] ) ) $paged = intval( $_GET['wpfpaged'] ); |
| 262 |
$paged = ( isset( $paged ) && $paged ) ? $paged : 1; |
| 263 |
$args = [ |
| 264 |
'userid' => bp_displayed_user_id(), |
| 265 |
'offset' => ( $paged - 1 ) * WPF()->current_object['items_per_page'], |
| 266 |
'row_count' => WPF()->current_object['items_per_page'], |
| 267 |
'var' => 'postid', |
| 268 |
]; |
| 269 |
$activities = WPF()->post->get_liked_posts( $args, $items_count ); |
| 270 |
?> |
| 271 |
<div id="wpforo-liked-posts" class="wpforo-activity"> |
| 272 |
<h2 class="entry-title"><?php wpforo_phrase( 'Liked Forum Posts' ); ?></h2> |
| 273 |
<?php if( empty( $activities ) ) : ?> |
| 274 |
<p class="wpf-p-error"> <?php wpforo_phrase( 'No activity found for this member.' ) ?> </p> |
| 275 |
<?php else: ?> |
| 276 |
<table> |
| 277 |
<?php $bg = false; |
| 278 |
foreach( $activities as $postid ) : ?> |
| 279 |
<tr> |
| 280 |
<td class="wpf-activity-title"> |
| 281 |
<span class="dashicons dashicons-thumbs-up"></span> |
| 282 |
<?php |
| 283 |
$post = wpforo_post( $postid ); |
| 284 |
if( ! empty( $post ) ) { |
| 285 |
$post_url = $post['url']; |
| 286 |
$post_title = $post['title']; |
| 287 |
if( ! $post_url ) $post_url = '#'; |
| 288 |
if( ! $post_title ) $post_title = wpforo_phrase( 'Post link' ); |
| 289 |
?><a href="<?php echo esc_url( (string) $post_url ) ?>" class="wpf-item-title"><?php echo $post_title ?></a><?php |
| 290 |
} |
| 291 |
?> |
| 292 |
<?php if( wpfval( $post, 'body' ) ): ?> |
| 293 |
<p class="wpf-post-excerpt" style="font-style: italic"> |
| 294 |
<?php |
| 295 |
$body = wpforo_content_filter( $post['body'], $post ); |
| 296 |
$body = preg_replace( '#\[attach\][^\[\]]*\[\/attach\]#is', '', strip_shortcodes( strip_tags( $body ) ) ); |
| 297 |
wpforo_text( $body, 200 ); |
| 298 |
?> |
| 299 |
</p> |
| 300 |
<?php endif; ?> |
| 301 |
</td> |
| 302 |
<td class="wpf-activity-forum"> |
| 303 |
<?php |
| 304 |
if( wpfval( $post, 'forumid' ) ) { |
| 305 |
$forum = wpforo_forum( $post['forumid'] ); |
| 306 |
$forum_url = $forum['url']; |
| 307 |
$forum_title = $forum['title']; |
| 308 |
if( ! $forum_url ) $forum_url = '#'; |
| 309 |
if( ! $forum_title ) $forum_url = wpforo_phrase( 'Forum link' ); |
| 310 |
?><p style="font-style: italic"><span><?php echo wpforo_phrase( 'in forum', false ) ?></span> <a href="<?php echo esc_url( (string) $forum_url ) ?>"><?php echo $forum_title ?></a></p><?php |
| 311 |
} |
| 312 |
?> |
| 313 |
</td> |
| 314 |
<td class="wpf-activity-date"><?php wpforo_date( $post['created'] ); ?></td> |
| 315 |
</tr> |
| 316 |
<?php endforeach ?> |
| 317 |
</table> |
| 318 |
<div class="wpf-activity-foot"><?php WPF()->tpl->pagenavi( $paged, $items_count, null, false ); ?></div> |
| 319 |
<div style="clear: both"></div> |
| 320 |
<?php endif; ?> |
| 321 |
</div> |
| 322 |
<?php |
| 323 |
} ); |
| 324 |
bp_core_load_template( apply_filters( 'wpforo_bp_forums_screen_likes', 'members/single/plugins' ) ); |
| 325 |
} |
| 326 |
|
| 327 |
function wpforo_bp_forums_screen_subscriptions() { |
| 328 |
add_action( 'bp_template_content', 'wpforo_bp_member_forums_subscriptions_content' ); |
| 329 |
bp_core_load_template( apply_filters( 'wpforo_bp_forums_screen_subscriptions', 'members/single/plugins' ) ); |
| 330 |
} |
| 331 |
|
| 332 |
function wpforo_bp_member_forums_subscriptions_content() { |
| 333 |
if( !WPF()->sbscrb ) return; |
| 334 |
if( isset( $_GET['wpfpaged'] ) && intval( $_GET['wpfpaged'] ) ) $paged = intval( $_GET['wpfpaged'] ); |
| 335 |
$user_id = bp_displayed_user_id(); |
| 336 |
$paged = ( isset( $paged ) && $paged ) ? $paged : 1; |
| 337 |
$args = [ |
| 338 |
'offset' => ( $paged - 1 ) * WPF()->current_object['items_per_page'], |
| 339 |
'row_count' => WPF()->current_object['items_per_page'], |
| 340 |
'userid' => $user_id, |
| 341 |
'order' => 'DESC', |
| 342 |
]; |
| 343 |
$activities = WPF()->sbscrb->get_subscribes( $args, $items_count ); |
| 344 |
?> |
| 345 |
<div id="wpforo-subscriptions" class="wpforo-activity"> |
| 346 |
<h2 class="entry-title"><?php wpforo_phrase( 'Forum Subscriptions' ); ?></h2> |
| 347 |
<?php if( empty( $activities ) ) : ?> |
| 348 |
<p class="wpf-p-error"> <?php wpforo_phrase( 'No activity found for this member.' ) ?> </p> |
| 349 |
<?php else: ?> |
| 350 |
<table> |
| 351 |
<?php $bg = false; |
| 352 |
foreach( $activities as $activity ) : ?> |
| 353 |
<tr> |
| 354 |
<td class="wpf-activity-title"> |
| 355 |
<span class="dashicons <?php echo ( $activity['type'] == 'forum' ) ? 'dashicons-category' : 'dashicons-admin-comments'; ?>"></span> |
| 356 |
<?php |
| 357 |
$item_url = '#'; |
| 358 |
if( in_array( $activity['type'], [ 'forum', 'forum-topic' ] ) ) { |
| 359 |
$item = wpforo_forum( $activity['itemid'] ); |
| 360 |
$item_url = $item['url']; |
| 361 |
} elseif( $activity['type'] == 'topic' ) { |
| 362 |
$item = wpforo_topic( $activity['itemid'] ); |
| 363 |
$item_url = $item['url']; |
| 364 |
} elseif( in_array( $activity['type'], [ 'forums', 'forums-topics' ] ) ) { |
| 365 |
$item = [ 'title' => wpforo_phrase( 'All ' . $activity['type'], false ) ]; |
| 366 |
$item_url = '#'; |
| 367 |
} |
| 368 |
if( empty( $item ) ) continue; |
| 369 |
?> |
| 370 |
<a href="<?php echo esc_url( (string) $item_url ) ?>" class="wpf-item-title"><?php echo esc_html( $item['title'] ) ?></a> |
| 371 |
</td> |
| 372 |
<?php if( wpforo_is_owner( $user_id ) ) : ?> |
| 373 |
<td class="wpf-activity-unsb"><a href="<?php echo esc_url( (string) WPF()->sbscrb->get_unsubscribe_link( $activity['confirmkey'] ) ) ?>"><?php wpforo_phrase( 'Unsubscribe' ); ?></a></td> |
| 374 |
<?php else : ?> |
| 375 |
<td></td> |
| 376 |
<?php endif; ?> |
| 377 |
</tr> |
| 378 |
<?php endforeach ?> |
| 379 |
</table> |
| 380 |
<div class="wpf-activity-foot"><?php WPF()->tpl->pagenavi( $paged, $items_count, null, false ); ?></div> |
| 381 |
<div style="clear: both"></div> |
| 382 |
<?php endif; ?> |
| 383 |
</div> |
| 384 |
<?php |
| 385 |
} |
| 386 |
|
| 387 |
/** |
| 388 |
* Filter registered notifications components, and add 'community' to the queried 'component_name' array. |
| 389 |
* |
| 390 |
* @param array $component_names |
| 391 |
* |
| 392 |
* @return array |
| 393 |
* @since wpForo (1.4.8) |
| 394 |
* |
| 395 |
*/ |
| 396 |
add_filter( 'bp_notifications_get_registered_components', function( $component_names = [] ) { |
| 397 |
if( ! is_array( $component_names ) ) $component_names = []; |
| 398 |
array_push( $component_names, 'community' ); |
| 399 |
|
| 400 |
return $component_names; |
| 401 |
}, 11 ); |
| 402 |
|
| 403 |
/** |
| 404 |
* Format the BuddyBar/Toolbar notifications |
| 405 |
* |
| 406 |
* @param string $action The kind of notification being rendered |
| 407 |
* @param int $item_id The primary item id |
| 408 |
* @param int $secondary_item_id The secondary item id |
| 409 |
* @param int $total_items The total number of messaging-related notifications waiting for the user |
| 410 |
* @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar |
| 411 |
* |
| 412 |
* @since wpForo (1.4.8) |
| 413 |
* |
| 414 |
*/ |
| 415 |
function wpforo_bp_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { |
| 416 |
// New reply notifications |
| 417 |
|
| 418 |
if( 'wpforo_new_reply' === $action ) { |
| 419 |
|
| 420 |
$post = wpforo_post( $item_id ); |
| 421 |
if( ! wpfval( $post, 'postid' ) ) return false; |
| 422 |
$topic = wpforo_topic( $post['topicid'] ); |
| 423 |
if( ! wpfval( $topic, 'topicid' ) ) return false; |
| 424 |
|
| 425 |
$reply_id = $post['postid']; |
| 426 |
$reply_url = $post['url']; |
| 427 |
$topic_title = $topic['title']; |
| 428 |
$reply_link = wp_nonce_url( add_query_arg( [ 'action' => 'wpforo_mark_read', 'itemid' => $reply_id ], $reply_url ), 'wpforo_mark_topic_' . $reply_id ); |
| 429 |
$title_attr = __( 'Topic reply', 'wpforo' ); |
| 430 |
|
| 431 |
if( (int) $total_items > 1 ) { |
| 432 |
$text = sprintf( __( 'You have %d new replies', 'wpforo' ), (int) $total_items ); |
| 433 |
$filter = 'wpforo_bp_multiple_new_subscription_notification'; |
| 434 |
} else { |
| 435 |
if( ! empty( $secondary_item_id ) ) { |
| 436 |
$text = sprintf( __( 'You have %d new reply to %2$s from %3$s', 'wpforo' ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) ); |
| 437 |
} else { |
| 438 |
$text = sprintf( __( 'You have %d new reply to %s', 'wpforo' ), (int) $total_items, $topic_title ); |
| 439 |
} |
| 440 |
$filter = 'wpforo_bp_single_new_subscription_notification'; |
| 441 |
} |
| 442 |
// WordPress Toolbar |
| 443 |
if( 'string' === $format ) { |
| 444 |
$return = apply_filters( $filter, '<a href="' . esc_url( (string) $reply_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $reply_link ); |
| 445 |
} else { |
| 446 |
$return = apply_filters( $filter, [ 'text' => $text, 'link' => $reply_link ], $reply_link, (int) $total_items, $text, $topic_title ); |
| 447 |
} |
| 448 |
do_action( 'wpforo_bp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items ); |
| 449 |
|
| 450 |
return $return; |
| 451 |
} |
| 452 |
|
| 453 |
return $action; |
| 454 |
} |
| 455 |
|
| 456 |
add_filter( 'bp_notifications_get_notifications_for_user', 'wpforo_bp_format_buddypress_notifications', 11, 5 ); |
| 457 |
|
| 458 |
/** |
| 459 |
* Hooked into the new reply function, this notification action is responsible |
| 460 |
* for notifying topic and hierarchical reply authors of topic replies. |
| 461 |
* |
| 462 |
* @param array $post |
| 463 |
* @param array $topic |
| 464 |
* |
| 465 |
* @since wpForo (1.4.8) |
| 466 |
* |
| 467 |
*/ |
| 468 |
function wpforo_bp_add_notification( $post = [], $topic = [] ) { |
| 469 |
if( ! wpforo_setting( 'buddypress', 'notification' ) ) return; |
| 470 |
|
| 471 |
//Get reply data |
| 472 |
if( ! wpfval( $post, 'postid' ) ) return; |
| 473 |
if( ! wpfval( $topic, 'topicid' ) ) return; |
| 474 |
|
| 475 |
//Don't notify if a new reply is unapproved |
| 476 |
if( wpfval( $post, 'status' ) ) return; |
| 477 |
if( wpfval( $post, 'is_first_post' ) ) return; |
| 478 |
|
| 479 |
//Get author information |
| 480 |
$author_id = $post['userid']; |
| 481 |
$topic_author_id = $topic['userid']; |
| 482 |
|
| 483 |
// Hierarchical replies |
| 484 |
if( wpfval( $post, 'parentid' ) ) { |
| 485 |
$reply_to_item_author_id = wpforo_post( $post['parentid'], 'userid' ); |
| 486 |
} |
| 487 |
|
| 488 |
// Notify the topic author if not the current reply author |
| 489 |
if( $author_id != $topic_author_id ) { |
| 490 |
$args = [ |
| 491 |
'user_id' => $topic_author_id, |
| 492 |
'item_id' => $post['postid'], |
| 493 |
'component_name' => 'community', |
| 494 |
'component_action' => 'wpforo_new_reply', |
| 495 |
'date_notified' => $post['created'], |
| 496 |
'secondary_item_id' => $author_id, |
| 497 |
]; |
| 498 |
bp_notifications_add_notification( $args ); |
| 499 |
} |
| 500 |
|
| 501 |
// Notify the immediate reply author if not the current reply author |
| 502 |
if( isset( $reply_to_item_author_id ) && wpfval( $post, 'parentid' ) && $topic_author_id != $reply_to_item_author_id && $author_id != $reply_to_item_author_id ) { |
| 503 |
$args = [ |
| 504 |
'user_id' => $reply_to_item_author_id, |
| 505 |
'item_id' => $post['postid'], |
| 506 |
'component_name' => 'community', |
| 507 |
'component_action' => 'wpforo_new_reply', |
| 508 |
'date_notified' => $post['created'], |
| 509 |
'secondary_item_id' => $author_id, |
| 510 |
]; |
| 511 |
bp_notifications_add_notification( $args ); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
add_action( 'wpforo_after_add_post', 'wpforo_bp_add_notification', 10, 2 ); |
| 516 |
|
| 517 |
/** |
| 518 |
* Remove notification when reply is set unapproved |
| 519 |
* |
| 520 |
* @param array $post |
| 521 |
* @param array $topic |
| 522 |
* |
| 523 |
* @since wpForo (1.4.8) |
| 524 |
* |
| 525 |
*/ |
| 526 |
function wpforo_bp_delete_notification( $post = [], $topic = [] ) { |
| 527 |
|
| 528 |
if( ! wpforo_setting( 'buddypress', 'notification' ) ) return; |
| 529 |
|
| 530 |
//Get reply data |
| 531 |
if( ! wpfval( $post, 'postid' ) ) return; |
| 532 |
if( ! wpfval( $topic, 'topicid' ) && wpfval( $post, 'topicid' ) ) { |
| 533 |
$topic = wpforo_topic( $post['topicid'] ); |
| 534 |
} |
| 535 |
|
| 536 |
$reply_to_item_author_id = 0; |
| 537 |
if( wpfval( $post, 'parentid' ) ) { |
| 538 |
$reply_to_item_author_id = wpforo_post( $post['parentid'], 'userid' ); |
| 539 |
} |
| 540 |
|
| 541 |
if( wpfval( $topic, 'userid' ) ) { |
| 542 |
bp_notifications_delete_notifications_by_item_id( $topic['userid'], $post['postid'], 'community', 'wpforo_new_reply' ); |
| 543 |
} |
| 544 |
|
| 545 |
if( $reply_to_item_author_id && $topic['userid'] !== $reply_to_item_author_id ) { |
| 546 |
bp_notifications_delete_notifications_by_item_id( $reply_to_item_author_id, $post['postid'], 'community', 'wpforo_new_reply' ); |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
add_action( 'wpforo_after_delete_post', 'wpforo_bp_delete_notification', 10 ); |
| 551 |
|
| 552 |
/** |
| 553 |
* Add / Remove buddypress notification based on post status (approve/unapprove) |
| 554 |
* |
| 555 |
* @param int $reply_id |
| 556 |
* @param int $status | 0 is approved, 1 is unapproved |
| 557 |
* |
| 558 |
* @since wpForo (1.4.8) |
| 559 |
* |
| 560 |
*/ |
| 561 |
add_action( 'wpforo_post_status_update', |
| 562 |
function( $post, $status = 0 ) { |
| 563 |
if( !$post || ! wpforo_setting( 'buddypress', 'notification' ) ) return; |
| 564 |
$post['status'] = $status = intval( $status ); |
| 565 |
if( wpfval( $post, 'topicid' ) ) { |
| 566 |
$topic = WPF()->topic->get_topic( $post['topicid'] ); |
| 567 |
} else { |
| 568 |
return; |
| 569 |
} |
| 570 |
if( $status ) { |
| 571 |
wpforo_bp_delete_notification( $post, $topic ); |
| 572 |
} else { |
| 573 |
wpforo_bp_add_notification( $post, $topic ); |
| 574 |
} |
| 575 |
}, 10, 2 |
| 576 |
); |
| 577 |
|
| 578 |
/** |
| 579 |
* Mark notifications as read when reading a topic |
| 580 |
* |
| 581 |
* @since wpForo (1.4.8) |
| 582 |
* |
| 583 |
* If not trying to mark a notification as read |
| 584 |
*/ |
| 585 |
add_action( 'wpforo_actions_end', function( $action = '' ) { |
| 586 |
if( empty( $_GET['itemid'] ) || empty( $_GET['action'] ) ) return; |
| 587 |
if( 'wpforo_mark_read' !== $_GET['action'] ) return; |
| 588 |
|
| 589 |
// Get required data |
| 590 |
$action = $action ?: $_GET['action']; |
| 591 |
$user_id = bp_loggedin_user_id(); |
| 592 |
$reply_id = intval( $_GET['itemid'] ); |
| 593 |
|
| 594 |
// Check nonce |
| 595 |
$result = isset( $_REQUEST['_wpnonce'] ) ? wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpforo_mark_topic_' . $reply_id ) : false; |
| 596 |
|
| 597 |
if( ! $result ) { |
| 598 |
$wp_error = new WP_Error(); |
| 599 |
$wp_error->add( 'wpforo_bp_notification_error', __( 'Are you sure you wanted to do that?', 'wpforo' ) ); |
| 600 |
// Check current user's ability to edit the user |
| 601 |
} elseif( ! current_user_can( 'edit_user', $user_id ) ) { |
| 602 |
$wp_error = new WP_Error(); |
| 603 |
$wp_error->add( 'wpforo_bp_notification_permissions', __( 'You do not have permission to mark notifications for that user.', 'wpforo' ) ); |
| 604 |
} |
| 605 |
|
| 606 |
if( ! isset( $wp_error ) ) { |
| 607 |
$success = bp_notifications_mark_notifications_by_item_id( $user_id, $reply_id, 'community', 'wpforo_new_reply' ); |
| 608 |
do_action( 'wpforo_bp_notifications_handler', $success, $user_id, $reply_id, $action ); |
| 609 |
} |
| 610 |
|
| 611 |
// Redirect to the topic |
| 612 |
$redirect = wpforo_post( $reply_id, 'url' ); |
| 613 |
|
| 614 |
// Redirect |
| 615 |
wp_safe_redirect( $redirect ); |
| 616 |
|
| 617 |
// For good measure |
| 618 |
exit(); |
| 619 |
}, 9 ); |
| 620 |
|
| 621 |
function wpforo_bp_profile_url( $url = '', $member = [], $template = 'profile' ) { |
| 622 |
if( wpfval( $member, 'userid' ) ) { |
| 623 |
$user_domain = wpforo_bp_profile_domain( $member ); |
| 624 |
$tabs = wpforo_setting( 'buddypress', 'forum_tab' ); |
| 625 |
if( $user_domain && $tabs ) { |
| 626 |
if( $template === 'account' ) { |
| 627 |
$url = rtrim( $user_domain, '/' ) . '/profile/'; |
| 628 |
} elseif( $template === 'activity' ) { |
| 629 |
$url = rtrim( $user_domain, '/' ) . '/community/'; |
| 630 |
} elseif( $template === 'subscriptions' ) { |
| 631 |
$url = rtrim( $user_domain, '/' ) . '/community/subscriptions/'; |
| 632 |
} elseif( $template === 'profile' ) { |
| 633 |
$url = $user_domain; |
| 634 |
} |
| 635 |
} else { |
| 636 |
$url = $user_domain; |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
return apply_filters( 'wpforo_bp_member_profile_url', $url, $member, $template ); |
| 641 |
} |
| 642 |
|
| 643 |
function wpforo_bp_profile_domain( $member ) { |
| 644 |
$user_domain = trim( (string) bp_members_get_user_url( $member['userid'] ), '/' ); |
| 645 |
// Get profile root slug and build current login user url ////////////////// |
| 646 |
$root_slug = 'members'; |
| 647 |
if( strpos( (string) $user_domain, '//' ) !== false ) { |
| 648 |
if( $pages = bp_core_get_directory_page_ids() ) { |
| 649 |
if( wpfval( $pages, 'members' ) ) { |
| 650 |
$root = get_post_field( 'post_name', intval( $pages['members'] ) ); |
| 651 |
$root_slug = $root ?: $root_slug; |
| 652 |
} |
| 653 |
$username = bp_members_get_user_slug( $member['userid'] ); |
| 654 |
if( bp_is_username_compatibility_mode() ) $username = rawurlencode( $username ); |
| 655 |
$after_domain = bp_core_enable_root_profiles() ? $username : $root_slug . '/' . $username; |
| 656 |
$domain = trailingslashit( bp_get_root_url() . '/' . $after_domain ); |
| 657 |
$user_domain = apply_filters( 'bp_members_get_user_url', $domain, $member['userid'], $member['user_nicename'], $member['user_login'] ); |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
////////////////////////////////////////////////////////////////////////// |
| 662 |
return strtok( $user_domain, '?' ); |
| 663 |
} |
| 664 |
|
| 665 |
add_action( 'profile_update', function( $userid ) { |
| 666 |
WPF()->member->reset( $userid ); |
| 667 |
}); |
| 668 |
|
| 669 |
add_filter( 'bp_get_displayed_user_avatar', function( $avatar, $r ) { |
| 670 |
$replace_buddypress_avatar = apply_filters( 'wpforo_replace_buddypress_avatar', false ); |
| 671 |
if( $replace_buddypress_avatar ) { |
| 672 |
if( ! $r['width'] ) $r['width'] = 150; |
| 673 |
|
| 674 |
return wpforo_avatar( $avatar, $r['item_id'], $r['width'], '', $r['alt'] ); |
| 675 |
} |
| 676 |
|
| 677 |
return $avatar; |
| 678 |
}, 10, 2 ); |
| 679 |
|
| 680 |
add_filter( 'bp_get_activity_content_body', function( $body ) { return wpforo_strip_shortcodes( $body ); }, 4 ); |
| 681 |
|