-
Notifications
You must be signed in to change notification settings - Fork 3
/
bbpvotes-buddypress.php
142 lines (103 loc) · 4.83 KB
/
bbpvotes-buddypress.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
class bbP_Votes_BuddyPress {
function __construct(){
add_action( 'bp_register_activity_actions',array(&$this,'register_activity_actions'));
add_action( 'bbpvotes_do_post_vote',array(&$this,'voted_activity'),10,3);
add_action( 'bp_setup_nav', array(&$this,'register_karma_nav') );
add_action( 'bbp_template_before_user_replies', array(&$this,'before_karma_replies') );
}
function register_karma_nav(){
global $bp;
$karma = 10;
$parent_slug = BP_FORUMS_SLUG;
$karma = bbpvotes_get_author_score( bp_displayed_user_id() );
$karma_text = bbpvotes_get_score_text($karma);
bp_core_new_subnav_item(
array(
'name' => sprintf( __( 'Karma <span>%d</span>', 'bbpvotes' ), $karma_text ),
'slug' => 'bbpvotes_karma',
'parent_url' => trailingslashit( bp_displayed_user_domain() . $parent_slug ),
'parent_slug' => $parent_slug,
'screen_function' => array(&$this,'karma_screen'),
'item_css_id' => 'bbpvotes-karma'
)
);
}
function karma_screen(){
add_action( 'bp_template_content', array(&$this,'karma_replies_content') );
bp_core_load_template( apply_filters( 'bbp_member_forums_screen_favorites', 'members/single/plugins' ) );
}
function karma_replies_content() {
?>
<div id="bbpress-forums">
<?php bbp_get_template_part( 'user', 'replies-created' ); ?>
</div>
<?php
}
function before_karma_replies(){
add_filter( 'bbp_has_replies_query', array(&$this,'filter_karma_replies') );
}
function filter_karma_replies($args){
$args[bbpvotes()->var_sort_by_vote] = 'score_desc';
return $args;
}
function register_activity_actions() {
// Sitewide activity stream items
bp_activity_set_action( 'bbpress', 'bbpvotes_voted_up', esc_html__( 'New vote up', 'bbpvotes' ) );
bp_activity_set_action( 'bbpress', 'bbpvotes_voted_down', esc_html__( 'New vote down', 'bbpvotes' ) );
}
function voted_activity($post_id,$user_id,$vote){
//check vote value
if (is_bool($vote) === false) return new WP_Error( 'vote_is_not_bool', __( 'Vote is not a boolean', 'bbpvotes' ));
$voteplus = ($vote === true);
$voteminus = ($vote === false);
$post = get_post($post_id);
$user_link = bbp_get_user_profile_link( $user_id );
//build item link
if ($post->post_type == bbp_get_topic_post_type()){
$topic_id = $post->ID;
$post_permalink = get_permalink( $post->ID );
}elseif ($post->post_type == bbp_get_reply_post_type()){
$topic_id = bbp_get_reply_topic_id( $post->ID );
$post_permalink = bbp_get_reply_url( $post->ID );
}
//topic infos
$topic = get_post($topic_id);
$topic_author_link = bbp_get_user_profile_link( $topic->post_author );
$topic_title = $topic->post_title;
$post_link = '<a href="' . $post_permalink . '">' . $topic_title . '</a>';
if ($voteplus){
$type = 'bbpvotes_voted_up';
if ($post->post_type == bbp_get_topic_post_type()){
$action = sprintf( esc_html__( '%1$s voted up to the topic %2$s by %3$s', 'bbpress' ), $user_link, $post_link, $topic_author_link );
}elseif ($post->post_type == bbp_get_reply_post_type()){
$action = sprintf( esc_html__( '%1$s voted up to a reply by %3$s in the topic %2$s', 'bbpress' ), $user_link, $post_link, $topic_author_link );
}
}else{
$type = 'bbpvotes_voted_down';
if ($post->post_type == bbp_get_topic_post_type()){
$action = sprintf( esc_html__( '%1$s voted down to the topic %2$s by %3$s', 'bbpress' ), $user_link, $post_link, $topic_author_link );
}elseif ($post->post_type == bbp_get_reply_post_type()){
$action = sprintf( esc_html__( '%1$s voted down to a reply by %3$s in the topic %2$s', 'bbpress' ), $user_link, $post_link, $topic_author_link );
}
}
$args = array(
'action' => $action,
//'content' => bp_create_excerpt($post->post_content),
'component' => 'bbpress',
'type' => $type,
'item_id' => $topic->ID,
);
if ($post->post_type == bbp_get_reply_post_type()){
$args['secondary_item_id'] = $post->ID;
}
/*
if ($is_update){
$previous_activity_id =
$args['id'] = $previous_activity_id;
}
*/
bp_activity_add( $args );
}
}
new bbP_Votes_BuddyPress;