Fix redirect when a user leaves a hidden group from the group's page.

Usually when a user leaves a group from the group's page, it redirects
back to the group's homepage, however for hidden groups this creates
a 404.

This commit redirects the user back to their list of groups when
leaving a hidden group.

Commit also adds phpDoc and uses some API functions instead of the $bp
global.

Fixes #5077.  Props imath.

git-svn-id: https://buddypress.svn.wordpress.org/trunk@7384 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
Tweak JS when joining or leaving a group from the groups directory.

This commit does the following:

* When leaving a hidden group, it removes the hidden group from the group loop.
* Increases or decreases the "My Groups" count if you join or leave a group.

Props imath for the initial patch.

See #5077.

git-svn-id: https://buddypress.svn.wordpress.org/trunk@7385 cdf35c40-ae34-48e0-9cc9-0c9da1808c22