/** * Catch requests for the groups component and find the requested group */ function group_hierarchy_override_current_action($current_action) { global $bp; do_action('bp_group_hierarchy_route_requests'); /** Only process once - hopefully this won't have any side effects */ remove_action('bp_current_action', 'group_hierarchy_override_current_action'); /** Abort processing on dashboard pages and when not in groups component */ if (is_admin() && !strpos(admin_url('admin-ajax.php'), $_SERVER['REQUEST_URI'])) { return $current_action; } if (!bp_is_groups_component()) { return $current_action; } $groups_slug = bp_get_groups_root_slug(); bp_group_hierarchy_debug('Routing request'); bp_group_hierarchy_debug('Current component: ' . $bp->current_component); bp_group_hierarchy_debug('Current action: ' . $current_action); bp_group_hierarchy_debug('Groups slug: ' . $groups_slug); bp_group_hierarchy_debug('Are we on a user profile page?: ' . (empty($bp->displayed_user->id) ? 'N' : 'Y')); if ($current_action == '') { return $current_action; } if (!empty($bp->displayed_user->id) || in_array($current_action, apply_filters('groups_forbidden_names', array('my-groups', 'create', 'invites', 'send-invites', 'forum', 'delete', 'add', 'admin', 'request-membership', 'members', 'settings', 'avatar', $groups_slug, '')))) { bp_group_hierarchy_debug('Not rewriting current action.'); return $current_action; } $action_vars = $bp->action_variables; $group = new BP_Groups_Hierarchy($current_action); if (!$group->id && (!isset($bp->current_item) || !$bp->current_item)) { $current_action = ''; bp_group_hierarchy_debug('Group not found - returning 404.'); bp_do_404(); return; } if ($group->has_children()) { $parent_id = $group->id; foreach ($bp->action_variables as $action_var) { $subgroup_id = BP_Groups_Hierarchy::check_slug($action_var, $parent_id); if ($subgroup_id) { $action_var = array_shift($action_vars); $current_action .= '/' . $action_var; $parent_id = $subgroup_id; } else { // once we find something that isn't a group, we're done break; } } } bp_group_hierarchy_debug('Action changed to: ' . $current_action); $bp->action_variables = $action_vars; $bp->current_action = $current_action; return $current_action; }
/** * Try to DESCRIBE the groups table to see whether the column exists / was added * @param bool $debug_column Whether to report that the required column wasn't found - this is normal pre-install */ function bp_group_hierarchy_verify_install($debug_column = false) { global $wpdb, $bp; /** Manually confirm that parent_id column exists */ $parent_id_exists = true; $columns = $wpdb->get_results('DESCRIBE ' . $bp->groups->table_name); if ($columns) { $parent_id_exists = false; foreach ($columns as $column) { if ($column->Field == 'parent_id') { $parent_id_exists = true; break; } } if (!$parent_id_exists && $debug_column) { bp_group_hierarchy_debug('Required column was not found - last MySQL error was: ' . $wpdb->last_error); return $parent_id_exists; } } else { bp_group_hierarchy_debug('Could not DESCRIBE table - last MySQL error was: ' . $wpdb->last_error); return false; } return $parent_id_exists; }
function __get($varName) { if (isset($this->vars)) { if (array_key_exists($varName, $this->vars)) { return $this->vars[$varName]; } } bp_group_hierarchy_debug('Magic method: __get called for "' . $varName . '", but class is not ready.'); return false; }
/** * Enable loading template files from the plugin directory * This plugin only has template files for group pages, so pass on any requests for other components */ function bp_group_hierarchy_load_template_filter($found_template, $templates) { /** Starting in BP 1.6, group list page (or maybe AJAX requests from it) is not in the groups component */ if (!bp_is_groups_component() && !isset($_POST['object'])) { return $found_template; } $filtered_templates = array(); foreach ((array) $templates as $template) { if (file_exists(STYLESHEETPATH . '/' . $template)) { $filtered_templates[] = STYLESHEETPATH . '/' . $template; } else { if (file_exists(TEMPLATEPATH . '/' . $template)) { $filtered_templates[] = TEMPLATEPATH . '/' . $template; } else { if (file_exists(dirname(__FILE__) . '/templates/' . $template)) { $filtered_templates[] = dirname(__FILE__) . '/templates/' . $template; } else { bp_group_hierarchy_debug('Could not locate the requested template file: ' . $template); } } } } if (count($filtered_templates) == 0) { return $found_template; } $found_template = $filtered_templates[0]; return $found_template; }