| @@ -1,89 +1,22 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -global $rpg_settingsf ; | |
| 4 | - | |
| 5 | 3 | add_action('bbp_template_redirect', 'private_group_enforce_permissions', 1); |
| 6 | 4 | add_filter('protected_title_format', 'pg_remove_protected_title'); |
| 7 | 5 | add_filter('private_title_format', 'pg_remove_private_title'); |
| 8 | -//handle favorites | |
| 9 | -add_filter( 'bbp_get_user_favorites', 'rpg_get_user_favorites' ); | |
| 10 | - | |
| 11 | -//links and topic counts | |
| 12 | -add_filter('bbp_get_forum_freshness_link', 'pg_get_forum_freshness_link', 10, 2 ); | |
| 13 | -add_filter ('bbp_get_single_forum_description' , 'rpg_get_single_forum_description' , 10 , 2) ; | |
| 14 | -add_filter ('bbp_get_forum_topic_count' , 'rpg_get_forum_topic_count', 10 , 2 ) ; | |
| 15 | -add_filter ('bbp_get_forum_reply_count' , 'rpg_get_forum_reply_count', 10 , 2 ) ; | |
| 16 | -add_filter ('bbp_get_forum_post_count' , 'rpg_get_forum_post_count', 10 , 2 ) ; | |
| 17 | - | |
| 18 | -add_filter ('bbp_get_forum_last_active_id' , 'rpg_get_forum_last_active_id', 10 , 2 ) ; | |
| 19 | -add_filter( 'bbp_user_can_view_forum', 'rpg_user_can_view_forum', 10, 3 ); | |
| 20 | - | |
| 21 | -//filter back end access to topics and replies to ensure that moderators can only see their forums they have access to | |
| 22 | -add_filter( 'bbp_request', 'rpg_filter_bbp_request', 10, 1 ); | |
| 23 | - | |
| 24 | -add_action( 'admin_notices', 'rpg_warning' ); | |
| 25 | - | |
| 26 | - | |
| 27 | -global $rpg_settingsf ; | |
| 28 | - | |
| 29 | -//hide forum menu items if visibilty switched off | |
| 30 | -if (empty($rpg_settingsf['set_forum_visibility'])) add_filter( 'wp_get_nav_menu_items', 'rpg_exclude_menu_items', null, 3 ); | |
| 31 | - | |
| 32 | - | |
| 33 | -//This code hides the author link if needed - we only potentially need to get this link if forum visibility is active, otherwise it is not needed. | |
| 34 | -//and user can't see the post - but then function will test that ! | |
| 35 | - | |
| 36 | -if (!empty ($rpg_settingsf['set_forum_visibility']) ) { | |
| 37 | -remove_filter( 'bbp_get_author_link', 'bbp_suppress_private_author_link', 10, 2 ); | |
| 38 | - remove_filter( 'bbp_get_topic_author_link', 'bbp_suppress_private_author_link', 10, 2 ); | |
| 39 | - remove_filter( 'bbp_get_reply_author_link', 'bbp_suppress_private_author_link', 10, 2 ); | |
| 40 | - add_filter( 'bbp_get_author_link', 'pg_check_profile', 10, 2 ) ; | |
| 41 | - add_filter( 'bbp_get_topic_author_link', 'pg_check_profile', 10, 2 ) ; | |
| 42 | - add_filter( 'bbp_get_reply_author_link', 'pg_check_profile', 10, 2 ) ; | |
| 43 | -} | |
| 44 | - | |
| 45 | -//add assign role to register, | |
| 6 | +add_filter('bbp_get_forum_freshness_link', 'custom_freshness_link' ); | |
| 7 | +add_filter('bbp_get_author_link', 'pg_get_author_link' ) ; | |
| 46 | 8 | add_action ('bbp_user_register', 'pg_role_group') ; |
| 47 | 9 | |
| 48 | -//and to wp-login | |
| 49 | -global $rpg_roles ; | |
| 50 | -if (!empty ($rpg_roles['login'])) { | |
| 51 | - add_action('wp_login', 'pg_assign_role_on_login', 10, 2); | |
| 52 | -} | |
| 53 | -//and on every visit | |
| 54 | -if (!empty ($rpg_roles['change_on_visit'] )) { | |
| 55 | - add_action('init', 'pg_assign_role_on_init'); | |
| 56 | -} | |
| 57 | 10 | |
| 58 | -// ADD FORUM ID column to admin | |
| 59 | -add_action("manage_edit-forum_columns", 'rpg_ID_column_add'); | |
| 60 | -add_filter("manage_forum_posts_custom_column", 'rpg_ID_column_value', 10, 3); | |
| 61 | 11 | |
| 62 | -//add groups to forum lists | |
| 63 | -add_action("manage_edit-forum_columns", 'rpg_groups_column_add') ; | |
| 64 | -add_filter("manage_forum_posts_custom_column", 'rpg_groups_column_value', 10, 3); | |
| 65 | - | |
| 66 | - | |
| 67 | -// add filters for bbp-style-pack if stylepack is running | |
| 68 | - add_filter('bsp_get_freshness_display_title', 'pg_get_forum_freshness_title' ); | |
| 69 | - add_filter('bsp_display_topic_index_query', 'pg_display_topic_index_query_filter'); | |
| 70 | - add_filter('bsp_display_forum_query', 'pg_display_forum_query_filter'); | |
| 71 | - add_filter('bsp_activity_widget', 'pg_latest_activity_forum_query_filter') ; | |
| 72 | - | |
| 73 | -// add filters for bbp-shortcodes plugin shortcodes if plugin is running | |
| 74 | - add_filter('asc_display_topic_index_query', 'pg_display_topic_index_query_filter'); | |
| 75 | - add_filter('asc_display_forum_query', 'pg_display_forum_query_filter'); | |
| 76 | - | |
| 77 | - | |
| 78 | - | |
| 79 | - | |
| 80 | 12 | /* |
| 81 | 13 | * Check if the current user has rights to view the given Post ID |
| 82 | - * Some of this core code is from the work of Aleksandar Adamovic in his Tehnik BBPress Permissions - thanks ! | |
| 14 | + * Much of this code is from the work of Aleksandar Adamovic in his Tehnik BBPress Permissions - thanks ! | |
| 83 | 15 | * |
| 84 | 16 | */ |
| 85 | - | |
| 17 | + | |
| 18 | + | |
| 86 | 19 | function private_groups_check_can_user_view_post() { |
| 87 | 20 | //uses $post_id and $post_type to get the forum ($forum_id) that the post belongs to |
| 88 | 21 | global $wp_query; |
| 89 | 22 | |
| @@ -94,12 +27,11 @@ | ||
| 94 | 27 | if (bbp_is_topic_super_sticky($post_id)) return true; |
| 95 | 28 | |
| 96 | 29 | |
| 97 | 30 | $forum_id = private_groups_get_forum_id_from_post_id($post_id, $post_type); |
| 98 | - //then call the function that checks if the user can view this forum, and hence this post | |
| 99 | - if (private_groups_can_user_view_post_id($forum_id) && topic_permissions_check ($post_id)) { | |
| 100 | - return true ; | |
| 101 | - } | |
| 31 | +//then call the function that checks if the user can view this forum, and hence this post | |
| 32 | + if (private_groups_can_user_view_post_id($forum_id)) | |
| 33 | + return true; | |
| 102 | 34 | } |
| 103 | 35 | |
| 104 | 36 | |
| 105 | 37 | |
| @@ -123,29 +55,30 @@ | ||
| 123 | 55 | //Get the Forum ID based on Post Type (Reply, Topic, Forum) |
| 124 | 56 | $forum_id = private_groups_get_forum_id_from_post_id($post_id, $post_type); |
| 125 | 57 | //Check if User has permissions to view this Post ID |
| 126 | 58 | //by calling the function that checks if the user can view this forum, and hence this post |
| 127 | - if (private_groups_can_user_view_post_id($forum_id) && topic_permissions_check ($post_id)) { | |
| 59 | + if (private_groups_can_user_view_post_id($forum_id)) { | |
| 128 | 60 | |
| 129 | - //User can view this post - add it to the allowed array | |
| 61 | + //User can view this post - add it to the allowed array | |
| 130 | 62 | array_push($allowed_posts, $post_id); |
| 131 | 63 | } |
| 132 | 64 | |
| 133 | 65 | endwhile; |
| 134 | 66 | |
| 135 | - //Return the list | |
| 67 | + //Return the list | |
| 136 | 68 | return $allowed_posts; |
| 137 | 69 | } |
| 138 | 70 | |
| 139 | 71 | |
| 72 | + | |
| 73 | + | |
| 140 | 74 | /* |
| 141 | 75 | * Returns the bbPress Forum ID from given Post ID and Post Type |
| 142 | 76 | * |
| 143 | 77 | * returns: bbPRess Forum ID |
| 144 | 78 | */ |
| 145 | -function private_groups_get_forum_id_from_post_id($post_id, $post_type = 0) { | |
| 146 | - if (empty ($post_type )) $post_type = get_post_type ($post_id) ; | |
| 147 | - $forum_id = 0; | |
| 79 | +function private_groups_get_forum_id_from_post_id($post_id, $post_type) { | |
| 80 | + $forum_id = 0; | |
| 148 | 81 | |
| 149 | 82 | // Check post type |
| 150 | 83 | switch ($post_type) { |
| 151 | 84 | // Forum |
| @@ -174,18 +107,16 @@ | ||
| 174 | 107 | if (!is_bbpress()) |
| 175 | 108 | return; |
| 176 | 109 | |
| 177 | 110 | // Bail if not viewing a single item or if user has caps |
| 178 | - if (!is_singular() || bbp_is_user_keymaster() ) | |
| 179 | - | |
| 180 | - return; | |
| 111 | + if (!is_singular() || bbp_is_user_keymaster() || current_user_can('read_hidden_forums')) | |
| 112 | + return; | |
| 181 | 113 | |
| 182 | - if (!private_groups_check_can_user_view_post() ) { | |
| 114 | + if (!private_groups_check_can_user_view_post()) { | |
| 183 | 115 | if (!is_user_logged_in()) { |
| 184 | - if(!empty($rpg_settingsf['redirect_page2'])) { | |
| 185 | - $link= apply_filters('rpg_forum_visibility_2' , $rpg_settingsf['redirect_page2']) ; | |
| 186 | - wp_redirect($link); | |
| 187 | - exit; | |
| 116 | + if($rpg_settingsf['redirect_page2']) { | |
| 117 | + $link=$rpg_settingsf['redirect_page2'] ; | |
| 118 | + header( "Location: $link" ); | |
| 188 | 119 | } |
| 189 | 120 | else { |
| 190 | 121 | auth_redirect(); |
| 191 | 122 | } |
| @@ -190,12 +121,11 @@ | ||
| 190 | 121 | auth_redirect(); |
| 191 | 122 | } |
| 192 | 123 | } |
| 193 | 124 | else { |
| 194 | - if(!empty($rpg_settingsf['redirect_page1'])) { | |
| 125 | + if($rpg_settingsf['redirect_page1']) { | |
| 195 | 126 | $link=$rpg_settingsf['redirect_page1'] ; |
| 196 | - wp_redirect($link); | |
| 197 | - exit; | |
| 127 | + header( "Location: $link" ); | |
| 198 | 128 | } |
| 199 | 129 | else { |
| 200 | 130 | bbp_set_404(); |
| 201 | 131 | } |
| @@ -203,14 +133,12 @@ | ||
| 203 | 133 | } |
| 204 | 134 | } |
| 205 | 135 | } |
| 206 | 136 | |
| 207 | - | |
| 208 | - | |
| 209 | - | |
| 137 | +//removes 'private' and protected prefix for forums | |
| 210 | 138 | function pg_remove_private_title($title) { |
| 211 | 139 | global $rpg_settingsg ; |
| 212 | - if (isset( $rpg_settingsg['activate_remove_private_prefix']) ) { | |
| 140 | + if( $rpg_settingsg['activate_remove_private_prefix']) { | |
| 213 | 141 | return '%s'; |
| 214 | 142 | } |
| 215 | 143 | else { |
| 216 | 144 | Return $title ; |
| @@ -218,9 +146,9 @@ | ||
| 218 | 146 | } |
| 219 | 147 | |
| 220 | 148 | function pg_remove_protected_title($title) { |
| 221 | 149 | global $rpg_settingsg ; |
| 222 | - if (isset ($rpg_settingsg['activate_remove_private_prefix']) ) { | |
| 150 | + if( $rpg_settingsg['activate_remove_private_prefix']) { | |
| 223 | 151 | return '%s'; |
| 224 | 152 | } |
| 225 | 153 | else { |
| 226 | 154 | Return $title ; |
| @@ -226,837 +154,154 @@ | ||
| 226 | 154 | Return $title ; |
| 227 | 155 | } |
| 228 | 156 | } |
| 229 | 157 | |
| 230 | -function pg_get_forum_freshness_link ($anchor, $forum_id) { | |
| 231 | - $anchor = pg_get_forum_freshness_link_anchor($forum_id) ; | |
| 232 | - if ($anchor ['title'] == 'no_topics' ) { | |
| 233 | - $anchor = esc_html__( 'No Topics', 'bbpress' ); | |
| 234 | - } | |
| 235 | - else { | |
| 236 | - $link_url = $anchor ['link_url'] ; | |
| 237 | - $title = $anchor ['title'] ; | |
| 238 | - $display = $anchor ['display'] ; | |
| 239 | - $anchor = '<a href="' .esc_url( $link_url) . '" title="' . esc_attr( $title ) . '">' .esc_html( $display ) .'</a>'; | |
| 240 | - } | |
| 241 | - return $anchor ; | |
| 242 | -} | |
| 158 | +function custom_freshness_link( $forum_id = 0 ) { | |
| 159 | +global $rpg_settingsf ; | |
| 160 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 161 | + $active_id = bbp_get_forum_last_active_id( $forum_id ); | |
| 162 | + $link_url = $title = ''; | |
| 163 | + $forum_title= bbp_get_forum_title ($forum_id) ; | |
| 243 | 164 | |
| 244 | -function pg_get_forum_freshness_title () { | |
| 245 | - $anchor = pg_get_forum_freshness_link_anchor() ; | |
| 246 | - if ($anchor ['title'] == 'no_topics' ) { | |
| 247 | - $anchor = esc_html__( 'No Topics', 'bbpress' ); | |
| 248 | - } | |
| 249 | - else { | |
| 250 | - $link_url = $anchor ['link_url'] ; | |
| 251 | - $title = $anchor ['title'] ; | |
| 252 | - $display = $anchor ['display'] ; | |
| 253 | - $anchor = $anchor = '<a href="' .esc_url( $link_url) . '" title="' . esc_attr( $title ) . '">' .esc_html( $title ) .'</a><p/>'; | |
| 254 | - } | |
| 255 | - return $anchor ; | |
| 256 | -} | |
| 257 | - | |
| 258 | -function rpg_get_forum_last_active_id ($active_id, $forum_id) { | |
| 259 | - //amended to allow for case where a forum has topics in the forum, and sub forums as well - previosuly only allowed for subforums | |
| 260 | - //so first check if the last active is in this forum itself (rather than a sub forum) if so then we can just retirn $active)id | |
| 261 | - $parent = get_post_meta( $active_id, '_bbp_forum_id', true ); | |
| 262 | - if ($parent == $forum_id ) return $active_id ; | |
| 263 | - //else we need to check which sub forums this user can see. | |
| 264 | - $sub_forums = private_groups_get_permitted_subforums($forum_id) ; | |
| 265 | - if ( !empty( $sub_forums ) ) { | |
| 266 | - $active_id = 0; | |
| 267 | - $show = array(); | |
| 268 | - //find the latest permissible | |
| 269 | - foreach ( $sub_forums as $sub_forum ) { | |
| 270 | - $sub_forum_id = $sub_forum->ID ; | |
| 271 | - $active_id = get_post_meta( $sub_forum_id , '_bbp_last_active_id', true ); | |
| 272 | - $last_active = get_post_meta( $sub_forum_id, '_bbp_last_active_time', true ); | |
| 273 | - if ( empty( $active_id ) ) { // not replies, maybe topics ? | |
| 274 | - $active_id = bbp_get_forum_last_topic_id( $sub_forum_id ); | |
| 275 | - if ( !empty( $active_id ) ) { | |
| 276 | - $last_active = bbp_get_topic_last_active_time( $active_id ); | |
| 277 | - } | |
| 278 | - } | |
| 279 | - if ( !empty( $active_id ) ) { | |
| 280 | - $curdate = strtotime($last_active); | |
| 281 | - $show[$curdate] = $active_id ; | |
| 282 | - } | |
| 283 | - } | |
| 284 | - $mostRecent= 0; | |
| 285 | - foreach($show as $date=>$value){ | |
| 286 | - if ($date > $mostRecent) { | |
| 287 | - $mostRecent = $date; | |
| 288 | - } | |
| 289 | - } | |
| 290 | - if ($mostRecent != 0) { | |
| 291 | - $active_id = $show[$mostRecent] ; | |
| 292 | - } else { | |
| 293 | - $active_id = 0; | |
| 294 | - } | |
| 295 | - } | |
| 296 | - | |
| 297 | - | |
| 298 | - | |
| 299 | - return apply_filters( 'pg_get_forum_last_active_id', $active_id, $forum_id ); | |
| 300 | -} | |
| 301 | - | |
| 302 | - | |
| 303 | - | |
| 304 | -function pg_get_forum_freshness_link_anchor( $forum_id = 0 ) { | |
| 305 | - global $rpg_settingsf ; | |
| 306 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 307 | - | |
| 308 | - //this returns the wrong answer - I suspect because there is another filter acting | |
| 309 | - //$active_id = bbp_get_forum_last_active_id( $forum_id ); | |
| 310 | - $active_id = (int) get_post_meta( $forum_id, '_bbp_last_active_id', true ); | |
| 311 | - | |
| 312 | - | |
| 313 | 165 | if ( empty( $active_id ) ) |
| 314 | 166 | $active_id = bbp_get_forum_last_reply_id( $forum_id ); |
| 315 | 167 | |
| 316 | 168 | if ( empty( $active_id ) ) |
| 317 | 169 | $active_id = bbp_get_forum_last_topic_id( $forum_id ); |
| 318 | - | |
| 319 | - //then reset forum_id to the forum of the active topic in case it is a sub forum | |
| 320 | - $forum_id = private_groups_get_forum_id_from_post_id($active_id) ; | |
| 321 | - | |
| 322 | - $link_url = $title = ''; | |
| 323 | 170 | |
| 324 | 171 | if ( bbp_is_topic( $active_id ) ) { |
| 325 | 172 | $link_url = bbp_get_forum_last_topic_permalink( $forum_id ); |
| 173 | + //$link_id added to get post_id and type to allow for later check | |
| 174 | + $link_id= bbp_get_forum_last_topic_id ($forum_id) ; | |
| 175 | + $check="topic" ; | |
| 326 | 176 | $title = bbp_get_forum_last_topic_title( $forum_id ); |
| 327 | - | |
| 328 | - | |
| 177 | + $forum_id_last_active = bbp_get_topic_forum_id($active_id); | |
| 329 | 178 | } elseif ( bbp_is_reply( $active_id ) ) { |
| 330 | 179 | $link_url = bbp_get_forum_last_reply_url( $forum_id ); |
| 180 | + //$link-id added to get post-id and type to allow for later check | |
| 181 | + $link_id = bbp_get_forum_last_reply_id ( $forum_id ); | |
| 182 | + $check="reply" ; | |
| 331 | 183 | $title = bbp_get_forum_last_reply_title( $forum_id ); |
| 332 | - | |
| 333 | - | |
| 184 | + $forum_id_last_active = bbp_get_reply_forum_id($active_id); | |
| 334 | 185 | } |
| 335 | 186 | |
| 336 | 187 | $time_since = bbp_get_forum_last_active_time( $forum_id ); |
| 337 | - | |
| 188 | + | |
| 338 | 189 | |
| 339 | - if ( !empty( $time_since ) && !empty( $link_url ) ) { | |
| 190 | + if ( !empty( $time_since ) && !empty( $link_url ) ) { | |
| 191 | + //ADDITIONAL CODE to original bbp_get_forum_freshness_link function | |
| 340 | 192 | //test if user can see this post, and post link if they can |
| 341 | 193 | $user_id = wp_get_current_user()->ID; |
| 194 | + //get the forum id for the post - that's the forum ID against which we check to see if it is in a group - no idea what forum group the stuff above produces, suspect post id of when last changed. | |
| 195 | + $forum_id_check = private_groups_get_forum_id_from_post_id($link_id, $check); | |
| 342 | 196 | //now we can check if the user can view this, and if it's not private |
| 343 | - if (private_groups_can_user_view_post($user_id,$forum_id) && !bbp_is_forum_private($forum_id) && topic_permissions_check ($active_id)) { | |
| 344 | - $anchor ['link_url'] = $link_url ; | |
| 345 | - $anchor ['title'] = $title; | |
| 346 | - $anchor ['display'] = $time_since; | |
| 347 | - //$anchor ['display'] = $forum_id ; | |
| 348 | - | |
| 197 | + if (private_groups_can_user_view_post($user_id,$forum_id_check) && !bbp_is_forum_private($forum_id_last_active)) { | |
| 198 | + $anchor = '<a href="' .esc_url( $link_url) . '" title="' . esc_attr( $title ) . '">' .esc_html( $time_since ) .'</a>'; | |
| 349 | 199 | } |
| 350 | 200 | //if it is private, then check user can view |
| 351 | - elseif (private_groups_can_user_view_post($user_id,$forum_id) && bbp_is_forum_private($forum_id) && current_user_can( 'read_private_forums' ) && topic_permissions_check ($active_id) ) { | |
| 352 | - $anchor ['link_url'] = $link_url ; | |
| 353 | - $anchor ['title'] = $title; | |
| 354 | - $anchor ['display'] = $time_since; | |
| 201 | + elseif (private_groups_can_user_view_post($user_id,$forum_id_check) && bbp_is_forum_private($forum_id_last_active) && current_user_can( 'read_private_forums' ) ) { | |
| 202 | + $anchor = '<a href="' .esc_url( $link_url) . '" title="' . esc_attr( $title ) . '">' .esc_html( $time_since ) .'</a>'; | |
| 355 | 203 | } |
| 356 | - //else we need to work out what to show so | |
| 357 | - | |
| 358 | - elseif (private_groups_can_user_view_post($user_id,$forum_id) && !topic_permissions_check ($active_id)) { | |
| 359 | - //now we check if it was only that user wasn't allowed to view the topic, and then find the last active topic for this user ('own topics' active) | |
| 360 | - $last_active_topic = rpg_own_topic_freshness ($forum_id); | |
| 361 | - //if user has no topics then we return with 0 | |
| 362 | - if (empty($last_active_topic)) $anchor ['title'] = 'no_topics'; | |
| 363 | - else { | |
| 364 | - $last_active_id = get_post_meta ($last_active_topic, '_bbp_last_active_id', true) ; | |
| 365 | - $anchor ['link_url'] = bbp_get_topic_permalink( $last_active_id); | |
| 366 | - $anchor ['title'] = bbp_get_topic_title($last_active_id ); | |
| 367 | - $anchor ['display'] = bbp_get_topic_last_active_time($last_active_topic ) ; | |
| 368 | - } | |
| 204 | + //else user cannot see post so... | |
| 205 | + else { | |
| 206 | + //set up which link to send them to | |
| 207 | + if (!is_user_logged_in()) { | |
| 208 | + if($rpg_settingsf['redirect_page2']) { | |
| 209 | + $link=$rpg_settingsf['redirect_page2'] ; | |
| 369 | 210 | } |
| 370 | - //so no access unless... if visibility is set... | |
| 371 | - | |
| 372 | - elseif (!empty ($rpg_settingsf['set_forum_visibility'])) { | |
| 373 | - | |
| 374 | - //so we need to set up a $link that will determine where they go, and change the date to a freshness message if set | |
| 375 | - //so set up for not logged in and logged in | |
| 376 | - if (!is_user_logged_in()) { | |
| 377 | - if($rpg_settingsf['redirect_page2']) { | |
| 378 | - $link_url= apply_filters('rpg_forum_freshness_visibility_2' , $rpg_settingsf['redirect_page2']) ; | |
| 379 | - } | |
| 380 | - else { | |
| 381 | - $link_url="/wp-login"; | |
| 382 | - } | |
| 211 | + else { | |
| 212 | + $link="/wp-login"; | |
| 383 | 213 | } |
| 384 | - //so if logged in, | |
| 214 | + } | |
| 385 | 215 | else { |
| 386 | - if($rpg_settingsf['redirect_page1']) { | |
| 387 | - $link_url=$rpg_settingsf['redirect_page1'] ; | |
| 388 | - } | |
| 389 | - else { | |
| 390 | - $link_url='/404'; | |
| 391 | - } | |
| 392 | - } | |
| 216 | + if($rpg_settingsf['redirect_page1']) { | |
| 217 | + $link=$rpg_settingsf['redirect_page1'] ; | |
| 218 | + } | |
| 219 | + else { | |
| 220 | + $link='/404'; | |
| 221 | + } | |
| 222 | + | |
| 223 | + } | |
| 393 | 224 | //now see if there is a freshness message |
| 394 | - if (!empty ($rpg_settingsf['set_freshness_message']) ) { | |
| 225 | + if ($rpg_settingsf['set_freshness_message']) { | |
| 395 | 226 | $title=$rpg_settingsf['freshness_message'] ; |
| 227 | + //and set up anchor | |
| 228 | + $anchor = '<a href="' . esc_url($link) . '">' .$title. '</a>'; | |
| 229 | + } | |
| 230 | + else{ | |
| 231 | + $anchor = '<a href="' . esc_url($link) . '">' .esc_html( $time_since ) .'</a>'; | |
| 396 | 232 | } |
| 397 | - else { | |
| 398 | - $title = esc_html( $time_since ) ; | |
| 399 | - } | |
| 400 | - | |
| 401 | - | |
| 402 | - //so we have a link and a title, so create the anchor | |
| 403 | - $anchor ['link_url'] = $link_url ; | |
| 404 | - $anchor ['title'] = $title; | |
| 405 | - $anchor ['display'] = $title; | |
| 406 | - | |
| 407 | - | |
| 408 | - } | |
| 409 | - | |
| 410 | - else { | |
| 411 | - //visibility is not set, and we have no topics to show the user so | |
| 412 | - $anchor ['title'] = 'no_topics'; | |
| 413 | - } | |
| 414 | - | |
| 415 | 233 | |
| 416 | - } | |
| 417 | - else { | |
| 418 | - // we have no topics, or something else has gone wrong ! | |
| 419 | - $anchor ['title'] = 'no_topics'; | |
| 420 | - } | |
| 421 | - | |
| 422 | - return $anchor; | |
| 423 | -} | |
| 424 | - | |
| 425 | -//not currently used - put in whilst testing time since - can be removed if this line still shows ! | |
| 426 | -function rpg_get_forum_last_active_time( $forum_id = 0 ) { | |
| 427 | - | |
| 428 | - // Verify forum and get last active meta | |
| 429 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 430 | - $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true ); | |
| 431 | - | |
| 432 | - if ( empty( $last_active ) ) { | |
| 433 | - $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 434 | - if ( ! empty( $reply_id ) ) { | |
| 435 | - $last_active = get_post_field( 'post_date', $reply_id ); | |
| 436 | - } else { | |
| 437 | - $topic_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 438 | - if ( ! empty( $topic_id ) ) { | |
| 439 | - $last_active = bbp_get_topic_last_active_time( $topic_id ); | |
| 440 | - } | |
| 441 | 234 | } |
| 442 | 235 | } |
| 236 | + | |
| 237 | + else | |
| 238 | + $anchor = esc_html__( 'No Topics', 'bbpress' ); | |
| 443 | 239 | |
| 444 | - $active_time = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; | |
| 445 | - | |
| 446 | - // Filter & return | |
| 447 | - return apply_filters( 'rpg_get_forum_last_active', $active_time, $forum_id ); | |
| 240 | + return $anchor; | |
| 448 | 241 | } |
| 449 | 242 | |
| 450 | -//I can't see where I use this function !! | |
| 451 | -//this function is only used if we have a user with 'access own topics' only to forum | |
| 452 | -//basically it just changes the post_id called to the correct one | |
| 453 | -function rpg_get_last_active_author ($args) { | |
| 454 | - $user_id = wp_get_current_user()->ID; | |
| 455 | - $forum_id = 0 ; | |
| 456 | - $active_id = $args['post_id'] ; | |
| 457 | - if (private_groups_can_user_view_post($user_id,$forum_id) && !topic_permissions_check ($active_id)){ | |
| 458 | - $last_active_topic = rpg_own_topic_freshness ($forum_id); | |
| 459 | - //if user has no topics then we return with 0 | |
| 460 | - if (!empty($last_active_topic)) { | |
| 461 | - $post_id = get_post_meta ($last_active_topic, '_bbp_last_active_id', true) ; | |
| 462 | - $args['post_id'] = $post_id ; | |
| 463 | - } | |
| 464 | - } | |
| 465 | -return $args ; | |
| 466 | 243 | |
| 467 | -} | |
| 468 | - | |
| 469 | - | |
| 470 | -//we only need to get this link if forum visibility is active, otherwise it is not needed. | |
| 471 | -//and if user can't see the freshness link | |
| 472 | -function pg_check_profile($author_link, $args ) { | |
| 473 | - //so we start with the code from the original suppress function | |
| 474 | - // Assume the author link is the return value | |
| 475 | - $retval = $author_link; | |
| 476 | - | |
| 477 | - // Show the normal author link | |
| 478 | - if ( !empty( $args['post_id'] ) && !current_user_can( 'read_private_forums' ) ) { | |
| 479 | - | |
| 480 | - // What post type are we looking at? | |
| 481 | - $post_type = get_post_field( 'post_type', $args['post_id'] ); | |
| 482 | - | |
| 483 | - switch ( $post_type ) { | |
| 484 | - | |
| 485 | - // Topic | |
| 486 | - case bbp_get_topic_post_type() : | |
| 487 | - if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) ) | |
| 488 | - $retval = ''; | |
| 489 | - | |
| 490 | - break; | |
| 491 | - | |
| 492 | - // Reply | |
| 493 | - case bbp_get_reply_post_type() : | |
| 494 | - if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) ) | |
| 495 | - $retval = ''; | |
| 496 | - | |
| 497 | - break; | |
| 498 | - | |
| 499 | - // Post | |
| 500 | - default : | |
| 501 | - if ( bbp_is_forum_private( $args['post_id'] ) ) | |
| 502 | - $retval = ''; | |
| 503 | - | |
| 504 | - break; | |
| 505 | - } | |
| 506 | - } | |
| 507 | - //so now to code for private groups | |
| 508 | - //so if retval isn't already blank, lets see if we should blank the author as the user isn't allowed to see this post | |
| 509 | - //we also check whether $args['post_id'] is blank as for a new forum with no topics AND any super sticky topics in other forums, then post_id is blank | |
| 510 | - if (!empty( $args['post_id'] ) && $retval !='') { | |
| 511 | - $forum_id_check = private_groups_get_forum_id_from_post_id($args['post_id']); | |
| 512 | - $current_user = wp_get_current_user()->ID; | |
| 513 | - //now we can check if the user can view this | |
| 514 | - if (!private_groups_can_user_view_post($current_user,$forum_id_check)) | |
| 515 | - $retval = '' ; | |
| 516 | - } | |
| 517 | 244 | |
| 518 | - return apply_filters( 'pg_no_profile', $retval ); | |
| 245 | +function pg_get_author_link( ) { | |
| 246 | +$user_id2 = wp_get_current_user()->ID; | |
| 519 | 247 | |
| 520 | -} | |
| 248 | + // Parse arguments against default values | |
| 249 | + $r = bbp_parse_args( $args, array( | |
| 250 | + 'post_id' => $post_id, | |
| 251 | + 'link_title' => '', | |
| 252 | + 'type' => 'both', | |
| 253 | + 'size' => 14 | |
| 254 | + ), 'pg_get_author_link' ); | |
| 521 | 255 | |
| 522 | 256 | |
| 523 | - | |
| 524 | - | |
| 525 | -//This function is added to bbp_user_register which in turn hooks to wordpress user_register. It checks if the user role has a group set against it, and if so assigns that to the user | |
| 526 | - | |
| 527 | -function pg_role_group ($user_id) { | |
| 528 | - if ($user_id == 0) return ; // bail if no user ID | |
| 529 | - global $rpg_roles ; | |
| 530 | - if (empty ($rpg_roles)) return ; //bail if not set in $rpg_roles | |
| 531 | - pg_set_user_group ($user_id) ; | |
| 532 | -} | |
| 533 | - | |
| 534 | -//this function assigns user to roles on login | |
| 535 | -function pg_assign_role_on_login($user_login, $user) { | |
| 536 | - $user_id = $user->ID ; | |
| 537 | - //bail if user groups are set for this user | |
| 538 | - $blank_test = get_user_meta ($user_id , 'private_group', true) ; | |
| 539 | - if (!empty ($blank_test)) return ; //has an entry in the database | |
| 540 | - //bail if login option not set in $rpg_roles | |
| 541 | - global $rpg_roles ; | |
| 542 | - if (empty ($rpg_roles)) return ; //bail if not set in $rpg_roles | |
| 543 | - pg_set_user_group ($user_id) ; | |
| 544 | -} | |
| 545 | - | |
| 546 | -//this function assigns user to roles on every visit (and every page refresh!) | |
| 547 | -function pg_assign_role_on_init() { | |
| 548 | - global $rpg_roles ; | |
| 549 | - $user = wp_get_current_user(); | |
| 550 | - $user_id = $user->ID ; | |
| 551 | - if (empty ($rpg_roles)) return ; //bail if not set in $rpg_roles | |
| 552 | - pg_set_user_group ($user_id) ; | |
| 553 | -} | |
| 554 | - | |
| 555 | -//this function has been superseded by the one below to allow for multiple wordpress roles | |
| 556 | -function pg_set_user_group_old ($user_id) { | |
| 557 | - global $rpg_roles ; | |
| 558 | - $user_info = get_userdata($user_id); | |
| 559 | - if (empty ($user_info)) return ; | |
| 560 | - $user_roles = $user_info->roles ; | |
| 561 | - foreach ((array)$user_roles as $list=>$role) { | |
| 562 | - if (!empty ($rpg_roles[$role] ) ) { | |
| 563 | - $group = $rpg_roles[$role] ; | |
| 564 | - if ($group != 'no-group' && (!empty($group)) ) { | |
| 565 | - update_user_meta( $user_id, 'private_group', $group); | |
| 566 | - } | |
| 567 | - } | |
| 568 | - } | |
| 569 | - | |
| 570 | -} | |
| 571 | - | |
| 572 | -function pg_set_user_group ($user_id) { | |
| 573 | - global $rpg_roles ; | |
| 574 | - $string='' ; | |
| 575 | - $user_info = get_userdata($user_id); | |
| 576 | - if (empty ($user_info)) return ; | |
| 577 | - $user_roles = $user_info->roles ; | |
| 578 | - foreach ((array)$user_roles as $list=>$role) { | |
| 579 | - if (!empty ($rpg_roles[$role] ) ) { | |
| 580 | - $group = $rpg_roles[$role] ; | |
| 581 | - if ($group != 'no-group' && (!empty($group)) ) { | |
| 582 | - $string.= $group.'*' ; | |
| 583 | - } | |
| 584 | - } | |
| 585 | - } | |
| 586 | - if (!empty ($string)) update_user_meta( $user_id, 'private_group', '*'.$string); | |
| 587 | -} | |
| 588 | - | |
| 589 | - | |
| 590 | - | |
| 591 | -//function for style pack topic index query | |
| 592 | -function pg_display_topic_index_query_filter ($args) { | |
| 593 | - // if we have no forums to select against then do nothing as this function has nothing to do. has_topics will do the filter | |
| 594 | - if (!empty ($args['post_parent__in'])) { | |
| 595 | - //get forums this user is allowed to see | |
| 596 | - $allowed_posts = pg_get_user_forums () ; | |
| 597 | - if (empty ($allowed_posts)) $allowed_posts[] = -1 ; | |
| 598 | - // now we have $allowed forums, so then we need to only have forums that are common to both (intersect) | |
| 599 | - if (!empty($args['post_parent__in'])) { | |
| 600 | - $allowed_posts = array_intersect( $allowed_posts, $args['post_parent__in']); | |
| 601 | - } | |
| 602 | - | |
| 603 | - //if there are no allowed forums set post_type to rubbish to ensure a nil return (otherwise it shows all allowed as post__in is blank) | |
| 604 | - if (empty ($allowed_posts)) $args['post_type'] = 'qvyzzvxx' ; | |
| 605 | - | |
| 606 | - //then we can create the post__in data | |
| 607 | - $args['post_parent__in'] = $allowed_posts; | |
| 608 | - } | |
| 609 | - | |
| 610 | - | |
| 611 | - return apply_filters( 'pg_display_topic_index_query_filter', $args ); | |
| 612 | -} | |
| 613 | - | |
| 614 | - | |
| 615 | -//function for style pack topic index query | |
| 616 | -function pg_display_forum_query_filter ($args) { | |
| 617 | - global $rpg_settingsf ; | |
| 618 | - //if forums are visible to everyone, then skip filtering, so if set_forum_visibility is empty then we need to filter, otherwise don't | |
| 619 | - if (empty($rpg_settingsf['set_forum_visibility'])) { | |
| 620 | - //get forums this user is allowed to see | |
| 621 | - $allowed_posts = pg_get_user_forums () ; | |
| 622 | - if (empty ($allowed_posts)) $allowed_posts[] = -1 ; | |
| 623 | - // now we have $allowed forums, so then we need to only have forums that are common to both (intersect) | |
| 624 | - if (!empty($args['post__in'])) { | |
| 625 | - $allowed_posts = array_intersect( $allowed_posts, $args['post__in']); | |
| 626 | - } | |
| 627 | - //if there are no allowed forums set post_type to rubbish to ensure a nil return (otherwise it shows all allowed as post__in is blank) | |
| 628 | - if (empty ($allowed_posts)) $args['post_type'] = 'qvyzzvxx' ; | |
| 629 | - //then we can create the post__in data | |
| 630 | - $args['post__in'] = $allowed_posts; | |
| 631 | - } | |
| 632 | - | |
| 633 | -return apply_filters( 'pg_display_topic_index_query_filter', $args ); | |
| 634 | -} | |
| 635 | - | |
| 636 | - | |
| 637 | -//function to create array used by above two functions | |
| 638 | -function pg_get_user_forums () { | |
| 639 | -//create an array of current forums this user can view | |
| 640 | - $query_data = array( | |
| 641 | - 'post_type' => bbp_get_forum_post_type(), | |
| 642 | - 'post_status' => bbp_get_public_status_id(), | |
| 643 | - 'posts_per_page' => get_option('_bbp_forums_per_page', 50), | |
| 644 | - 'orderby' => 'menu_order', | |
| 645 | - 'order' => 'ASC' | |
| 646 | - ); | |
| 647 | - //PRIVATE GROUPS Get an array of forums which the current user has permissions to view | |
| 648 | - $allowed_posts = private_groups_get_permitted_post_ids(new WP_Query($query_data)); | |
| 649 | - return $allowed_posts ; | |
| 650 | -} | |
| 651 | - | |
| 652 | -//function for style pack latest activity widget | |
| 653 | -function pg_latest_activity_forum_query_filter ($topics_query) { | |
| 654 | - $topics_query['posts_per_page'] = 200; | |
| 655 | - $allowed_posts = private_groups_get_permitted_post_ids(new WP_Query($topics_query)); | |
| 656 | - $topics_query['post__in'] = $allowed_posts ; | |
| 657 | - return apply_filters( 'pg_latest_activity_forum_query_filter', $topics_query ) ; | |
| 658 | -} | |
| 659 | - | |
| 660 | - | |
| 661 | - | |
| 662 | - | |
| 663 | - | |
| 664 | -function rpg_get_user_favorites( $user_id = 0 ) { | |
| 665 | - $user_id = bbp_get_user_id( $user_id ); | |
| 666 | - if ( empty( $user_id ) ) | |
| 667 | - return false; | |
| 668 | - | |
| 669 | - // If user has favorites, load them | |
| 670 | - $favorites = bbp_get_user_favorites_topic_ids( $user_id ); | |
| 671 | - //create a filtered list | |
| 672 | - if ( !empty( $favorites ) ) { | |
| 673 | - $filtered_favorites = array(); | |
| 674 | - foreach ($favorites as $list=>$fav) { | |
| 675 | - $post_type = get_post_type ($fav) ; | |
| 676 | - $forum_id = private_groups_get_forum_id_from_post_id($fav, $post_type); | |
| 677 | - //then call the function that checks if the user can view this forum, and hence this post | |
| 678 | - if ( private_groups_can_user_view_post_id($forum_id, $post_type) && topic_permissions_check ($fav) ) array_push($filtered_favorites, $fav); | |
| 679 | - } | |
| 680 | - } | |
| 681 | - //then show if any.. | |
| 682 | - if ( !empty( $filtered_favorites ) ) { | |
| 683 | - $query = bbp_has_topics( array( 'post__in' => $filtered_favorites ) ); | |
| 684 | - } else { | |
| 685 | - $query = false; | |
| 686 | - } | |
| 687 | - return apply_filters( 'rpg_get_user_favorites', $query, $user_id, $favorites ); | |
| 688 | -} | |
| 689 | - | |
| 690 | -//amended single forum description | |
| 691 | -function rpg_get_single_forum_description( $retstr, $r ) { | |
| 692 | - $forum_id = bbp_get_forum_id( $r['forum_id'] ); | |
| 693 | - // check if this forum has sub-forums and if it hasn't then just return | |
| 694 | - $children = bbp_forum_query_subforum_ids( $forum_id ); | |
| 695 | - if ( empty( $children ) ) { | |
| 696 | - return apply_filters( 'rpg_get_single_forum_description1', $retstr, $r ); | |
| 697 | - } | |
| 698 | - | |
| 699 | - // Unhook the 'view all' query var adder | |
| 700 | - remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' ); | |
| 701 | - | |
| 702 | - // Get some forum data | |
| 703 | - $tc_int = bbp_get_forum_topic_count( $forum_id, false ); | |
| 704 | - $rc_int = bbp_get_forum_reply_count( $forum_id, false ); | |
| 705 | - $topic_count = bbp_get_forum_topic_count( $forum_id ); | |
| 706 | - $reply_count = bbp_get_forum_reply_count( $forum_id ); | |
| 707 | - // this taken out as it seems to get a faulty answer, possibly due to something alreday filtering the bbp_get_forum_last_active_id function ! so now go direct ! | |
| 708 | - //$last_active = bbp_get_forum_last_active_id( $forum_id ); | |
| 709 | - $last_active = (int) get_post_meta( $forum_id, '_bbp_last_active_id', true ); | |
| 710 | - | |
| 711 | - // Has replies | |
| 712 | - if ( !empty( $reply_count ) ) { | |
| 713 | - $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count ); | |
| 714 | - } | |
| 715 | - | |
| 716 | - $topic_text = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count ); | |
| 717 | - $check=false ; | |
| 718 | - | |
| 719 | - // Forum has active data | |
| 720 | - if ( !empty( $last_active ) ) { | |
| 721 | - $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_active, 'size' => $r['size'] ) ); | |
| 722 | - //$last_updated_by = $forum_id.' '.$last_active ; | |
| 723 | - //now get the forum the LAST ACTIVE topic/reply comes from | |
| 724 | - $last_active_forum_id = private_groups_get_forum_id_from_post_id($last_active) ; | |
| 725 | - //and see if our user is allowed to see this post, if so display the lastest | |
| 726 | - if (private_groups_can_user_view_post_id($last_active_forum_id )) { | |
| 727 | - $check = true ; //set check as we're outputing in this section | |
| 728 | - $time_since = bbp_get_forum_last_active_time( $forum_id ); | |
| 729 | - //$time_since = bbp_get_forum_freshness_link( $forum_id ); | |
| 730 | - | |
| 257 | + //confirmed topic | |
| 258 | + if( bbp_is_topic( $post_id) ) { | |
| 259 | + $topic=bbp_get_topic_post_type() ; | |
| 260 | + $forum_id_check = private_groups_get_forum_id_from_post_id($post_id, $topic); | |
| 261 | + //now we can check if the user can view this | |
| 262 | + if (!private_groups_can_user_view_post($user_id2,$forum_id_check)) | |
| 263 | + return; | |
| 264 | + return bbp_get_topic_author_link( $r ); | |
| 731 | 265 | |
| 732 | - // Has replies | |
| 733 | - if ( ! empty( $reply_count ) ) { | |
| 734 | - $retstr = bbp_is_forum_category( $forum_id ) | |
| 735 | - ? sprintf( esc_html__( 'This category has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by ) | |
| 736 | - : sprintf( esc_html__( 'This forum has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by ); | |
| 737 | 266 | |
| 738 | - // Only has topics | |
| 739 | - } else { | |
| 740 | - $retstr = bbp_is_forum_category( $forum_id ) | |
| 741 | - ? sprintf( esc_html__( 'This category has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by ) | |
| 742 | - : sprintf( esc_html__( 'This forum has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by ); | |
| 743 | - } | |
| 744 | - | |
| 745 | - | |
| 746 | - } //end of if user can view | |
| 747 | - | |
| 748 | - // Forum has no last active data | |
| 749 | - //OR user is not allowed to see this data | |
| 267 | + // Confirmed reply | |
| 268 | + } elseif ( bbp_is_reply( $post_id ) ) { | |
| 269 | + $reply=bbp_get_reply_post_type() ; | |
| 270 | + $forum_id_check = private_groups_get_forum_id_from_post_id($post_id, $reply); | |
| 271 | + //now we can check if the user can view this | |
| 272 | + if (!private_groups_can_user_view_post($user_id2,$forum_id_check)) | |
| 273 | + return ; | |
| 274 | + return bbp_get_reply_author_link( $r ); | |
| 750 | 275 | } |
| 751 | - if ($check == false) { | |
| 276 | + // Neither a reply nor a topic, so could be a revision | |
| 277 | + //if it isn't a topic or reply, not sure so better to just not display the author in this case | |
| 278 | + //could be revised to look up the post_parent of this post and then churn that round the code above if required return ; | |
| 279 | + return ; | |
| 752 | 280 | |
| 753 | - if ( !empty( $reply_count ) ) { | |
| 754 | - | |
| 755 | - if ( bbp_is_forum_category( $forum_id ) ) { | |
| 756 | - $retstr = sprintf( esc_html__( 'This category contains %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text ); | |
| 757 | - } else { | |
| 758 | - $retstr = sprintf( esc_html__( 'This forum contains %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text ); | |
| 759 | - } | |
| 760 | - | |
| 761 | - } else { | |
| 762 | - | |
| 763 | - if ( !empty( $topic_count ) ) { | |
| 764 | - | |
| 765 | - if ( bbp_is_forum_category( $forum_id ) ) { | |
| 766 | - $retstr = sprintf( esc_html__( 'This category contains %1$s.', 'bbpress' ), $topic_text ); | |
| 767 | - } else { | |
| 768 | - $retstr = sprintf( esc_html__( 'This forum contains %1$s.', 'bbpress' ), $topic_text ); | |
| 769 | - } | |
| 770 | - | |
| 771 | - } else { | |
| 772 | - $retstr = esc_html__( 'This forum is empty.', 'bbpress' ); | |
| 773 | - } | |
| 774 | - } | |
| 775 | - } | |
| 776 | - | |
| 777 | - // Add the 'view all' filter back | |
| 778 | - add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' ); | |
| 779 | - | |
| 780 | - // Combine the elements together | |
| 781 | - $retstr = $r['before'] . $retstr . $r['after']; | |
| 782 | - | |
| 783 | - // Return filtered result | |
| 784 | - return apply_filters( 'rpg_get_single_forum_description', $retstr, $r ); | |
| 785 | - | |
| 786 | 281 | } |
| 787 | 282 | |
| 788 | 283 | |
| 789 | -//function to deal with cases where a forum/category has sub forums, but the user might not be able to see all these sub forums, and gather data | |
| 790 | -function rpg_check_subforums ($forum_id) { | |
| 791 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 792 | - $sub_forums = private_groups_get_permitted_subforums($forum_id) ; | |
| 793 | - if ( !empty( $sub_forums ) ) { | |
| 794 | - //set up an array $show with dates for each forum set to last active topic ID | |
| 795 | - foreach ( $sub_forums as $sub_forum ) { | |
| 796 | - $sub_forum_id = $sub_forum->ID ; | |
| 797 | - $active_id = bbp_get_forum_last_active_id( $sub_forum_id ); | |
| 798 | - $last_active = get_post_meta( $active_id, '_bbp_last_active_time', true ); | |
| 799 | - $curdate = strtotime($last_active); | |
| 800 | - $show[$curdate] = $active_id ; | |
| 801 | - } | |
| 802 | - //then loop thorugh this array to find the most recent date | |
| 803 | - $mostRecent= 0; | |
| 804 | - foreach($show as $date=>$value){ | |
| 805 | - if ($date > $mostRecent) { | |
| 806 | - $mostRecent = $date; | |
| 807 | - } | |
| 808 | - } | |
| 809 | - //then assemble the anchor for latest topic | |
| 810 | - $latest_topic = $show[$mostRecent] ; | |
| 811 | - $link_url = bbp_get_topic_permalink( $latest_topic ); | |
| 812 | - $title = bbp_get_topic_title( $latest_topic ); | |
| 813 | - $time_since = bbp_get_topic_last_active_time( $latest_topic ); | |
| 814 | - $anchor ['latest_topic'] = $latest_topic ; | |
| 815 | - $anchor ['link_url'] = $link_url ; | |
| 816 | - $anchor ['title'] = $title; | |
| 817 | - $anchor ['display'] = $time_since; | |
| 818 | - } | |
| 819 | - else { | |
| 820 | - //pass back a title which we can use to say none | |
| 821 | - $anchor ['title'] = 'no_topics'; | |
| 822 | - } | |
| 823 | -return $anchor ; | |
| 824 | -} | |
| 284 | +//This function is added to bbp_user_register which in turn hooks to wordpress user_register. It checks if the user role has a group set against it, and if so assigns that to the user | |
| 825 | 285 | |
| 826 | - | |
| 827 | -function rpg_get_forum_topic_count ($topics, $forum_id) { | |
| 828 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 829 | - //do a check to ensure that user can see all items in this forum and if not calculate topics by author - for 'access own' forums | |
| 830 | - if (!rpg_access_own_topics_check ($forum_id)) { | |
| 831 | - $topics = rpg_calaculate_own_topics ($forum_id) ; | |
| 832 | - return apply_filters('rpg_get_forum_topic_count3' , $topics, $forum_id ); | |
| 833 | - } | |
| 834 | - $sub_forums = private_groups_get_permitted_subforums($forum_id) ; | |
| 835 | - | |
| 836 | - if ( !empty( $sub_forums ) ) { | |
| 837 | - $topics = 0 ; | |
| 838 | - foreach ( $sub_forums as $sub_forum ) { | |
| 839 | - $sub_forum_id = $sub_forum->ID ; | |
| 840 | - //and increment topic totals | |
| 841 | - $topics = $topics + get_post_meta( $sub_forum_id, '_bbp_total_topic_count', true ); | |
| 842 | - } | |
| 843 | - //if main forum is also a forum not a category, then add this in | |
| 844 | - if (bbp_get_forum_type($forum_id) == 'forum') { | |
| 845 | - $topics = $topics + get_post_meta( $forum_id, '_bbp_topic_count', true ); | |
| 286 | +function pg_role_group ($user_id) { | |
| 287 | +$test=get_option ('rpg_roles') ; | |
| 288 | +//if no roles set, then exit | |
| 289 | +if (empty ($test)) return ; | |
| 290 | +//we have roles set, so now cycle through the roles for this user | |
| 291 | +//$user_id = get_current_user_id(); | |
| 292 | +//if ($user_id == 0) return ; // bail if no user ID | |
| 293 | + $roles = get_usermeta( $user_id, 'wp_capabilities',false ) ; | |
| 294 | + foreach ($roles as $role=>$value) { | |
| 295 | + foreach ($test as $check=>$group){ | |
| 296 | + if ($role == $check ) { | |
| 297 | + if ($group != 'no-group') update_user_meta( $user_id, 'private_group', $group); | |
| 846 | 298 | } |
| 847 | - return apply_filters('rpg_get_forum_topic_count1' , $topics, $forum_id ); | |
| 299 | + } | |
| 848 | 300 | } |
| 849 | - else { | |
| 850 | - return apply_filters('rpg_get_forum_topic_count2', $topics, $forum_id ); | |
| 851 | - } | |
| 852 | 301 | } |
| 853 | 302 | |
| 854 | -function rpg_calaculate_own_topics ($forum_id) { | |
| 855 | - $count=0 ; | |
| 856 | - $user_id = wp_get_current_user()->ID; | |
| 857 | - //Get an array of topics | |
| 858 | - global $wpdb; | |
| 859 | - $post=bbp_get_topic_post_type() ; | |
| 860 | - $post_ids=$wpdb->get_col("select ID from $wpdb->posts where post_type = '$post' and post_parent = '$forum_id' and post_status <> 'trash'") ; | |
| 861 | - foreach ($post_ids as $post_id) { | |
| 862 | - $author_id = bbp_get_topic_author_id( $post_id); | |
| 863 | - if ($user_id == $author_id) | |
| 864 | - $count++ ; | |
| 865 | - } | |
| 866 | - return $count; | |
| 867 | -} | |
| 868 | 303 | |
| 869 | -function rpg_calaculate_own_replies ($forum_id) { | |
| 870 | - $count=0 ; | |
| 871 | - $topics = array(); | |
| 872 | - $user_id = wp_get_current_user()->ID; | |
| 873 | - //Get an array of topics first | |
| 874 | - global $wpdb; | |
| 875 | - $post=bbp_get_topic_post_type() ; | |
| 876 | - $post_ids=$wpdb->get_col("select ID from $wpdb->posts where post_type = '$post' and post_parent = '$forum_id' and post_status <> 'trash'") ; | |
| 877 | - foreach ($post_ids as $post_id) { | |
| 878 | - $author_id = bbp_get_topic_author_id( $post_id); | |
| 879 | - if ($user_id == $author_id) { | |
| 880 | - //get the reply count | |
| 881 | - $count= $count + get_post_meta ($post_id, '_bbp_reply_count', true) ; | |
| 882 | - } | |
| 883 | - } | |
| 884 | - return $count; | |
| 885 | -} | |
| 886 | - | |
| 887 | - | |
| 888 | 304 | |
| 889 | -function rpg_get_forum_reply_count ($replies, $forum_id) { | |
| 890 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 891 | - if (!rpg_access_own_topics_check ($forum_id)) { | |
| 892 | - $replies = rpg_calaculate_own_replies ($forum_id) ; | |
| 893 | - return apply_filters('rpg_get_forum_reply_count3' , $replies, $forum_id ); | |
| 894 | - } | |
| 895 | - $sub_forums = private_groups_get_permitted_subforums($forum_id) ; | |
| 896 | - if ( !empty( $sub_forums ) ) { | |
| 897 | - $replies = 0 ; | |
| 898 | - foreach ( $sub_forums as $sub_forum ) { | |
| 899 | - $sub_forum_id = $sub_forum->ID ; | |
| 900 | - //and increment reply totals | |
| 901 | - $replies = $replies + get_post_meta( $sub_forum_id, '_bbp_total_reply_count', true ); | |
| 902 | - } | |
| 903 | - //if main forum is also a forum not a category, then add this in | |
| 904 | - if (bbp_get_forum_type($forum_id) == 'forum') { | |
| 905 | - $replies = $replies + get_post_meta( $forum_id, '_bbp_reply_count', true ); | |
| 906 | - } | |
| 907 | - return apply_filters('rpg_get_forum_reply_count1' , $replies, $forum_id ); | |
| 908 | - } | |
| 909 | - else { | |
| 910 | - return apply_filters('rpg_get_forum_reply_count2', $replies, $forum_id ); | |
| 911 | - } | |
| 912 | -} | |
| 913 | 305 | |
| 914 | -function rpg_get_forum_post_count ($retval, $forum_id) { | |
| 915 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 916 | - if (!rpg_access_own_topics_check ($forum_id)) { | |
| 917 | - $retval = rpg_calaculate_own_replies ($forum_id) ; | |
| 918 | - return apply_filters('rpg_get_forum_reply_count3' , $retval, $forum_id ); | |
| 919 | - } | |
| 920 | - $sub_forums = private_groups_get_permitted_subforums($forum_id) ; | |
| 921 | - if ( !empty( $sub_forums ) ) { | |
| 922 | - $replies = $topics = $retval = 0 ; | |
| 923 | - foreach ( $sub_forums as $sub_forum ) { | |
| 924 | - $sub_forum_id = $sub_forum->ID ; | |
| 925 | - //and increment reply totals | |
| 926 | - $replies = $replies + get_post_meta( $sub_forum_id, '_bbp_total_reply_count', true ); | |
| 927 | - $topics = $topics + get_post_meta( $sub_forum_id, '_bbp_total_topic_count', true ); | |
| 928 | - } | |
| 929 | - //if main forum is also a forum not a category, then add this in | |
| 930 | - /*if (bbp_get_forum_type($forum_id) == 'forum') { | |
| 931 | - $replies = $replies + get_post_meta( $sub_forum_id, '_bbp_reply_count', true ); | |
| 932 | - $topics = $topics + get_post_meta( $sub_forum_id, '_bbp_topic_count', true ); | |
| 933 | - }*/ | |
| 934 | - $retval = $replies + $topics ; | |
| 935 | - return apply_filters('rpg_get_forum_post_count1' , $retval, $forum_id ); | |
| 936 | - } | |
| 937 | - else { | |
| 938 | - return apply_filters('rpg_get_forum_post_count2', $retval, $forum_id ); | |
| 939 | - } | |
| 940 | -} | |
| 941 | 306 | |
| 942 | - | |
| 943 | - | |
| 944 | - | |
| 945 | -//add private groups to forum lists | |
| 946 | - | |
| 947 | -////////////////////////////// ADD FORUM ID column to admin if not added by style pack | |
| 948 | - | |
| 949 | -function rpg_ID_column_add($columns) { | |
| 950 | - $new = array(); | |
| 951 | - foreach($columns as $key => $title) { | |
| 952 | - if ($key=='bbp_reply_topic') // Put the forum ID column before the Topics column | |
| 953 | - $new['rpg_id'] = 'Forum ID'; | |
| 954 | - $new[$key] = $title; | |
| 955 | - } | |
| 956 | - return $new; | |
| 957 | -} | |
| 958 | - | |
| 959 | -function rpg_ID_column_value($column_name, $id) { | |
| 960 | - if ($column_name == 'rpg_id') echo $id; | |
| 961 | -} | |
| 962 | - | |
| 963 | - | |
| 964 | -function rpg_groups_column_add($columns) { | |
| 965 | - $new = array(); | |
| 966 | - foreach($columns as $key => $title) { | |
| 967 | - if ($key=='bbp_forum_topic_count') // Put the forum ID column before the Topics column | |
| 968 | - $new['rpg_pg'] = 'Private Groups'; | |
| 969 | - $new[$key] = $title; | |
| 970 | - } | |
| 971 | - return $new; | |
| 972 | -} | |
| 973 | - | |
| 974 | -function rpg_groups_column_value($column_name, $id) { | |
| 975 | - if ($column_name == 'rpg_pg') { | |
| 976 | - global $rpg_groups ; | |
| 977 | - $meta = get_post_meta( $id, '_private_group', false ); | |
| 978 | - echo '<ul>' ; | |
| 979 | - foreach ($meta as $group) { | |
| 980 | - $groupname=__('Group','bbp-private-groups').substr($group,5,strlen($group)) ; | |
| 981 | - $details = $rpg_groups[$group] ; | |
| 982 | - echo '<li>'.$groupname.' '.$details.'</li>' ; | |
| 983 | - } | |
| 984 | - echo '</ul>' ; | |
| 985 | - } | |
| 986 | - | |
| 987 | -} | |
| 988 | - | |
| 989 | -function rpg_user_can_view_forum ($retval, $forum_id, $user_id ){ | |
| 990 | - //if it's already false then just return it, otherwise... | |
| 991 | - if ($retval == true) { | |
| 992 | - $retval = private_groups_can_user_view_post( $user_id, $forum_id ) ; | |
| 993 | - } | |
| 994 | - return $retval ; | |
| 995 | -} | |
| 996 | - | |
| 997 | - | |
| 998 | -//filter back end topics and replies to ensure that moderators can only see their own forums | |
| 999 | -function rpg_filter_bbp_request( $array ) { | |
| 1000 | - //only apply if we are in backend admin (otherwise all forum displays go to 404 !) | |
| 1001 | - $link = $_SERVER['REQUEST_URI']; | |
| 1002 | - $topic_admin = '/wp-admin/edit.php?post_type='.bbp_get_topic_post_type() ; | |
| 1003 | - $reply_admin = '/wp-admin/edit.php?post_type='.bbp_get_reply_post_type() ; | |
| 1004 | - $topic_date_filter = '/wp-admin/edit.php?s&post_status=all&post_type='.bbp_get_topic_post_type() ; | |
| 1005 | - $reply_date_filter = '/wp-admin/edit.php?s&post_status=all&post_type='.bbp_get_reply_post_type() ; | |
| 1006 | - if ( strpos($link, $topic_admin) !== false || strpos($link, $reply_admin) !== false || strpos($link, $topic_date_filter) !== false || strpos($link, $reply_date_filter) !== false ) { | |
| 1007 | - global $wpdb; | |
| 1008 | - $forum=bbp_get_forum_post_type() ; | |
| 1009 | - $forum_ids=$wpdb->get_col("select ID from $wpdb->posts where post_type = '$forum'") ; | |
| 1010 | - //check this list against those the user is allowed to see, and create a list of valid ones for the wp_query | |
| 1011 | - $allowed_forums = private_groups_check_permitted_forums($forum_ids) ; | |
| 1012 | - $array['meta_key'] = '_bbp_forum_id'; | |
| 1013 | - $array['meta_value'] = $allowed_forums; | |
| 1014 | - $array['compare']= 'IN' ; | |
| 1015 | - } | |
| 1016 | - return $array ; | |
| 1017 | -} | |
| 1018 | - | |
| 1019 | -function rpg_warning(){ | |
| 1020 | - | |
| 1021 | -// bbpress version | |
| 1022 | - if (function_exists('bbPress')) { | |
| 1023 | - $bbp = bbpress(); | |
| 1024 | - } else { | |
| 1025 | - global $bbp; | |
| 1026 | - } | |
| 1027 | - if (isset($bbp->version)) { | |
| 1028 | - $bbpversion = $bbp->version; | |
| 1029 | - $bbpversion = (substr($bbpversion, 0, 3)) ; | |
| 1030 | - } else { | |
| 1031 | - $bbpversion = '???'; | |
| 1032 | - } | |
| 1033 | - | |
| 1034 | -// this is a success message | |
| 1035 | -if($bbpversion =='2.6' ): | |
| 1036 | - $n = get_option ('rpg_warning', 0) ; | |
| 1037 | - $n++ ; | |
| 1038 | - if ($n<11) { | |
| 1039 | -?> | |
| 1040 | -<div class='notice notice-success is-dismissible'> | |
| 1041 | -<?php | |
| 1042 | -_e('WARNING : You have bbp-Private-Groups plugin working with bbPress 2.6. If you have forums that are set to \'hidden\' or \'private\' PLEASE CHECK that they display correctly - 2.6 has changed the way these forums are excluded. If in doubt, set these forums to a group that is not being used to ensure they do not display by mistake. ', 'bbp-private-groups'); ?> | |
| 1043 | -</div> | |
| 1044 | -<?php | |
| 1045 | -update_option ('rpg_warning' , $n) ; | |
| 1046 | - } | |
| 1047 | - | |
| 1048 | -endif; | |
| 1049 | -} | |
| 1050 | - | |
| 1051 | -function rpg_exclude_menu_items( $items, $menu, $args ) { | |
| 1052 | - // Iterate over the items to search and remove | |
| 1053 | - foreach ( $items as $key => $item ) { | |
| 1054 | - if ( $item->object == 'forum' ) { | |
| 1055 | - if (!private_groups_can_user_view_post_id($item->object_id)) unset( $items[$key] ); | |
| 1056 | - } | |
| 1057 | - } | |
| 1058 | -return $items; | |
| 1059 | -} | |
| 1060 | - | |
| 1061 | - | |
| 1062 | - | |
| 307 | +?> | |