PluginProbe
Private groups / trunk
Private groups vtrunk
trunk 1.5 1.6 1.7 1.8 1.8.1 1.9.1 1.9.2 2.0 2.0.1 2.2 2.3 2.4 2.5 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 116 releases
bbp-private-groups / includes / replies.php

replies.php in Private groups trunk, at includes/replies.php

155 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 //this is only used (as far as I can see) by the 'replies created' part of the user profile
4
5
6
7 add_filter ('bbp_get_user_replies_created', 'pg_get_user_replies_created') ;
8
9
10
11 function pg_get_user_replies_created( $user_id = 0 ) {
12
13
14
15 // Validate user
16
17 $user_id2 = bbp_get_user_id( $user_id );
18
19 $current_user= wp_get_current_user()->ID;
20
21 if ( empty( $user_id ) )
22
23 return false;
24
25
26
27 $limit='y' ;
28
29 if ( bbp_is_user_keymaster()) $limit='n' ;
30
31
32
33 if (user_can( $current_user, 'moderate' ) ) {
34
35 $check=get_user_meta( $current_user, 'private_group',true);
36
37 if ($check=='') $limit='n' ;
38
39 }
40
41 $allowed_posts = array();
42
43 //skip filtering unless needed
44
45 if ($limit != 'n') {
46
47 global $wpdb;
48
49 $reply=bbp_get_reply_post_type() ;
50
51 // $post_ids = $wpdb->get_col("select ID from $wpdb->posts where post_type = '$reply'");
52
53 $post_ids = $wpdb->get_col("select ID from $wpdb->posts where post_type = '$reply' and post_author = '$user_id2'");
54
55 //check this list against those the user is allowed to see, and create a list of valid ones for the wp_query in bbp_has_topics
56
57 $allowed_posts = check_private_groups_reply_ids($post_ids) ;
58
59 if (empty ($allowed_posts)) $allowed_posts[] = -1 ;
60
61
62
63 }
64
65
66
67 // The default reply query with allowed topic and reply ids array added
68
69
70
71
72
73
74
75 // Try to get the topics
76
77 $query = bbp_has_replies( array(
78
79 'post_type' => bbp_get_reply_post_type(),
80
81 'order' => 'DESC',
82
83 'author' => $user_id2,
84
85 'post__in' => $allowed_posts
86
87 ) );
88
89
90
91
92
93 return apply_filters( 'pg_get_user_replies_created', $query, $user_id );
94
95 }
96
97
98
99 //the function to check the above !
100
101 function check_private_groups_reply_ids($post_ids) {
102
103
104
105 //Init the Array which will hold our list of allowed posts
106
107 $allowed_posts = array();
108
109
110
111
112
113 //Loop through all the posts
114
115 foreach ( $post_ids as $post_id ) {
116
117 //Get the Forum ID based on Post Type Topic
118
119 $reply=bbp_get_reply_post_type() ;
120
121 $forum_id = private_groups_get_forum_id_from_post_id($post_id, $reply);
122
123 //Check if User has permissions to view this Post ID
124
125 //by calling the function that checks if the user can view this forum, and hence this post
126
127 if (private_groups_can_user_view_post_id($forum_id) && topic_permissions_check ($post_id)) {
128
129
130
131 //User can view this post - add it to the allowed array
132
133 array_push($allowed_posts, $post_id);
134
135 }
136
137 }
138
139
140
141 //Return the list
142
143 return $allowed_posts;
144
145 }
146
147
148
149
150
151
152
153
154
155