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