function bpgr_render_review() { global $bp; // Don't show for groups that have reviews turned off if (!BP_Group_Reviews::current_group_is_available()) { return; } // Rendering the full span so you can avoid editing your group-header.php template // If you don't like it you can call bpgr_review_html() yourself and unhook this function ;) ?> <span class="rating"><?php echo bpgr_review_html(); ?> </span> <?php }
function bp_group_reviews_extension() { global $bp; $this->group_id = BP_Groups_Group::group_exists($bp->current_item); $this->name = __('Reviews', 'bpgr'); $this->slug = $bp->group_reviews->slug; $this->nav_item_position = 22; $this->enable_create_step = false; $this->enable_nav_item = BP_Group_Reviews::current_group_is_available(); $this->enable_edit_item = false; if (isset($_POST['review_submit'])) { check_admin_referer('review_submit'); $has_posted = ''; if (empty($_POST['review_content']) || !(int) $_POST['rating']) { // Something has gone wrong. Save the user's submitted data to reinsert into the post box after redirect $cookie_data = array('review_content' => $_POST['review_content'], 'rating' => $_POST['rating']); $cookie = json_encode($cookie_data); setcookie('bpgr-data', $cookie, time() + 60 * 60 * 24, COOKIEPATH); bp_core_add_message(__("Please make sure you fill in the review, and don't forget to provide a rating!", 'bpgr'), 'error'); } else { /* Auto join this user if they are not yet a member of this group */ if (!is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member($bp->loggedin_user->id, $bp->groups->current_group->id)) { groups_join_group($bp->groups->current_group->id, $bp->loggedin_user->id); } if ($rating_id = $this->post_review(array('content' => $_POST['review_content'], 'rating' => (int) $_POST['rating']))) { bp_core_add_message("Your review was posted successfully!"); $has_posted = groups_get_groupmeta($bp->groups->current_group->id, 'posted_review'); if (!in_array((int) $bp->loggedin_user->id, (array) $has_posted)) { $has_posted[] = (int) $bp->loggedin_user->id; } groups_update_groupmeta($bp->groups->current_group->id, 'posted_review', $has_posted); if ((int) $_POST['rating'] < 0) { $_POST['rating'] = 1; } if ((int) $_POST['rating'] > 5) { $_POST['rating'] = 5; } } else { bp_core_add_message("There was a problem posting your review, please try again.", 'error'); } } bp_core_redirect(apply_filters('bpgr_after_post_redirect', trailingslashit(bp_get_group_permalink($bp->groups->current_group) . $this->slug, $has_posted))); } }
function toggle_markup() { $is_reviewable = BP_Group_Reviews::current_group_is_available(); ?> <div class="checkbox"> <label for="bpgr_toggle"><input type="checkbox" id="bpgr_toggle" name="bpgr_toggle" value="yes" <?php if ($is_reviewable) { ?> checked="checked"<?php } ?> /> <?php _e('Enable group reviews', 'bpgr'); ?> </label> </div> <?php }
/** * Check whether the group reviews tab is available for the current group * * A member specific check is done first. This should probably be moved out in the future * * @package BP Group Reviews * @since 1.0.3 * * @return bool $is_available True if the reviews tab is available for the group */ function current_group_is_available() { global $bp; // Check to see whether it's already in the global if (isset($bp->groups->current_group->is_reviewable)) { $is_available = $bp->groups->current_group->is_reviewable ? true : false; } else { // If the current user doesn't have access to the group, don't bother // checking whether reviews are turned on if (empty($bp->groups->current_group->user_has_access)) { $is_available = false; } else { $is_available = BP_Group_Reviews::group_is_reviewable($bp->groups->current_group->id); } } return apply_filters('bpgr_current_group_is_available', $is_available); }