? .DS_Store
? MY_NOTES.txt
? og_forum-651672-67.patch
? og_forum.patch
? og_forum_2.patch
Index: og_forum.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_forum/Attic/og_forum.module,v
retrieving revision 1.11.2.11.2.18.2.17.2.20
diff -r1.11.2.11.2.18.2.17.2.20 og_forum.module
15a16,20
> 
> /**
>  * Hook Implementations.
>  */
> 
25c30
< } // function og_forum_help()
---
> }
30,31d34
<  * Valid permissions for this module
<  * @return array An array of valid permissions for the accounttypes module
35c38
< } // function og_forum_perm()
---
> } 
50c53
<     'page callback' => 'og_forum_public',
---
>     'page callback' => '_og_forum_public',
52c55
<     'access callback' =>  'og_forum_access_privileges_1',
---
>     'access callback' =>  'og_forum_manage_public_private_reset_access',
58c61
<     'page callback' => 'og_forum_private',
---
>     'page callback' => '_og_forum_private',
60c63
<     'access callback' =>  'og_forum_access_privileges_1',
---
>     'access callback' =>  'og_forum_manage_public_private_reset_access',
66c69
<     'page callback' => 'og_forum_reset',
---
>     'page callback' => '_og_forum_reset',
68c71
<     'access callback' =>  'og_forum_access_privileges_1',
---
>     'access callback' =>  'og_forum_manage_public_private_reset_access',
75c78
<     'page callback' => 'og_forum_manage',
---
>     'page callback' => '_og_forum_manage',
77c80
<     'access callback' =>  'og_forum_access_privileges_2',
---
>     'access callback' =>  '_og_forum_manage_add_edit_access',
79a83,90
>   );
>   $items['og_forum/manage/edit/%/%'] = array(
>     'title' => t('Edit forum'),
>     'page callback' => '_og_forum_form_main',
>     'page arguments' => array(2,3,4),
>     'access callback' =>  '_og_forum_manage_add_edit_access',
>     'access arguments' => array(3),
>     'type' => MENU_CALLBACK
83c94
<     'page callback' => 'og_forum_form_main',
---
>     'page callback' => '_og_forum_form_main',
85c96
<     'access callback' =>  'og_forum_access_privileges_3',
---
>     'access callback' =>  '_og_forum_manage_add_edit_access',
89,96d99
<   $items['og_forum/manage/edit/%/%'] = array(
<     'title' => t('Edit forum'),
<     'page callback' => 'og_forum_form_main',
<     'page arguments' => array(2,3,4),
<     'access callback' =>  'og_forum_access_privileges_2',
<     'access arguments' => array(3),
<     'type' => MENU_CALLBACK
<   );
122c125
<   $callbacks['forum']['access callback'] = 'og_forum_access_forum_page';
---
>   $callbacks['forum']['access callback'] = '_og_forum_access_forum_page';
124,165c127
<   $callbacks['forum']['page callback'] = 'og_forum_topic_redirect';
< }
< 
< function og_forum_topic_redirect($tid=0) {
<   if ($tid) {	 
<     $gid = og_forum_gid_from_tid($tid);
<     if ($gid)
<       drupal_goto("node/$gid/og/forum/$tid");  
<   }
<   return forum_page($tid);
< }
< 
< function og_forum_access_privileges_1 ($gid) {
<   $group = node_load($gid);
<   $allow_public = variable_get('forum_allow_public', 0);	
<   return ((og_forum_is_admin($group) && user_access('admin own group forums') && $allow_public) || user_access('make forums public'));	
< }	
< 
< function og_forum_access_privileges_2 ($gid) {
<   $group = node_load($gid);
<   return ((og_forum_is_admin($group) && user_access('admin own group forums')) || user_access('administer forums'));
< }
< 
< function og_forum_access_privileges_3 ($gid, $tid) {
<   $group = node_load($gid);
<   return ((og_forum_is_admin($group) && user_access('admin own group forums') && !og_forum_forum_limit_reached($tid)) || user_access('administer forums'));
< } // took off a ) bracket after the end of user_access('admin own group forums') , is this right ?? 
< 
< function og_forum_group_type_load($arg) {
<   $node = node_load($arg);
<   if (og_is_group_type($node->type)) {
<      global $user;
<      if (!isset($user->og_groups)) {
<        $user->og_groups = og_get_subscriptions($user->uid);
<      }
<      $tid = og_forum_get_forum_container($arg);
<      if (og_forum_is_public($tid) || (!empty($user->og_groups) && array_key_exists($arg, $user->og_groups)) || user_access('administer forums'))
<        return $tid;
<      else
<        return FALSE;
<   }
<   return FALSE;
---
>   $callbacks['forum']['page callback'] = '_og_forum_topic_redirect';
169,171c131
<  * Implimentation of hook_block()
<  *
<  * Creates a block to display forum information for a group.
---
>  * Implementation of hook_block()
177a138
> 	
218c179
<           $forum  = og_forum_get_forum_container($nid);
---
>           $forum  = _og_forum_get_forum_container($nid);
228c189
< } //og_forum_block
---
> }
231c192
<  * Implementation of hook_settings().
---
>  * Implementation of hook_admin_settings().
234c195
<   $form['#submit'][] = 'og_forum_settings_submit'; // custom submit handler
---
>   $form['#submit'][] = '_og_forum_settings_submit'; // custom submit handler
246c207
<   $current_default_name = variable_get('forum_default_name', 'General discussion');
---
>   $current_default_name = variable_get('og_forum_default_name', 'General discussion');
250c211
<     '#description' => t('When this module creates a container and default forum for a new group, this will be the name given to that group.'),
---
>     '#description' => t('When this module creates a container and default forum for a new group, this will be the name given to that forum.'),
258c219
<   $default_container_yn = variable_get('forum_default_container_yn', FALSE);
---
>   $default_container_yn = variable_get('og_forum_default_container_yn', FALSE);
265c226
<   $default_container = variable_get('forum_default_container', 0);
---
>   $default_container = variable_get('og_forum_default_container', 0);
287c248
<   $auto_public = variable_get('forum_auto_public', 0);
---
>   $auto_public = variable_get('og_forum_auto_public', 0);
295c256
<   $allow_public = variable_get('forum_allow_public', 0);
---
>   $allow_public = variable_get('og_forum_allow_public', 0);
299c260
<     '#description' => t('If you would like to allow group owners the ability to decide which, if any, of their forums are publicly viewable, check the box.
---
>     '#description' => t('If you would like to allow group managers the ability to decide which, if any, of their forums are publicly viewable, check the box.
301c262
<     allow group owners to override auto settings on a case by case basis. The auto mode respects group owner-set values.'),
---
>     allow group owners to override auto settings on a case by case basis to make forums private. The auto public option respects group manager set values.'),
304c265
<   $all_public = variable_get('forum_all_public', 0);
---
>   $all_public = variable_get('og_forum_all_public', 0);
339c300
<   $forum_limit = variable_get('forum_limit', 0);
---
>   $og_forum_limit_forums = variable_get('og_forum_limit_forums', 0);
346c307
<     '#default_value' => $forum_limit,
---
>     '#default_value' => $og_forum_limit_forums,
349,415c310
< } // function og_forum_admin_settings()
< 
< /**
<  * Custom submit handler for group update
<  */
< function og_forum_settings_submit($form, &$form_state) {
<   $form_values = $form_state['values'];
<   if ($form_values['op'] == t('Update old groups')) {
<     og_forum_retroactively_apply();
<   }
<   elseif ($form_values['op'] == t('Publicize old groups')) {
<     $auto_public = variable_get('forum_auto_public', 0);
<     if ($auto_public) {
<       //go through all existing forums and where a node has been made public, set the forum's publicity to PUBLIC_AUTO
<       $sql = "SELECT DISTINCT tn.tid, oa.group_nid FROM {node} n INNER JOIN {og_ancestry} oa ON oa.nid = n.nid INNER JOIN {og_access_post} oap ON oap.nid = oa.nid INNER JOIN {term_node} tn ON tn.nid = oa.nid  WHERE n.type = 'forum' AND oap.og_public = 1";
<       $results = db_query($sql);
<       while ($result = db_fetch_object($results)) {
<         $gid = $result->group_nid;
<         $container = og_forum_get_forum_container($gid);
<         $sql2 = "UPDATE {og_term} SET public = %d WHERE tid = %d and nid = %d";
<         db_query($sql2, PUBLIC_AUTO, $result->tid, $gid);
<         db_query($sql2, PUBLIC_AUTO, $container, $gid);
<       }
<     }
<     else {
<       drupal_set_message(t('You need to select "Automatic forum publicity" for this to work.'), 'error');
<     }
<   }
<   elseif ($form_values['op'] == t('Switch to auto mode')) {
<     $sql = "UPDATE {og_term} SET public = %d WHERE public = %d";
<     db_query($sql, PUBLIC_AUTO, PUBLIC_BY_GROUP_OWNER);
<     db_query($sql, PRIVATE_DEFAULT, PRIVATE_BY_GROUP_OWNER);
<   }
<   if ($form_values['op'] == t('Save configuration')) {
<     variable_set('forum_default_name', $form_values['default_forum_name']);
<     variable_set('forum_default_container_yn', $form_values['default_container_yn']);
<     variable_set('forum_default_container', $form_values['default_container']);
<     variable_set('forum_allow_public', $form_values['allow_public']);
<     variable_set('forum_auto_public', $form_values['auto_public']);
<     variable_set('forum_all_public', $form_values['all_public']);
<     variable_set('forum_limit', $form_values['limit_forums']);
<   }
< } // function og_forum_settings_submit()
< 
< /**
<  * using the tid, set the group context
<  */
< function og_forum_set_og_group_context_from_tid($tid=0) {
<   $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
<   if ($gid = db_result(db_query($sql, $tid))) {
<   $group_node = node_load($gid);
<   og_set_group_context($group_node);
<   }
< } // function og_forum_set_og_group_context_from_tid()
< 
< /**
<  * using the tid, get the group id
<  */
< function og_forum_gid_from_tid($tid=0) {
<   $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
<   if ($gid = db_result(db_query($sql, $tid))) {
<     return $gid;
<   }
<   else {
<     return 0;
<   }
< } // function og_forum_gid_from_tid()
---
> }
422d316
< 
425c319
<       if (user_access('administer forums') || (!module_exists('og_access') || variable_get('forum_all_public', 0))) {  
---
>       if (user_access('administer forums') || (!module_exists('og_access') || variable_get('og_forum_all_public', 0))) {  
429c323
<         return og_forum_get_sql();
---
>         return _og_forum_db_rewrite_sql();
432c326
<     elseif (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'forum') {
---
>     elseif (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'forum') { //print $query;
434d327
<         // if a &gids is present in the URL
438c331
< 	    }
---
> 	    } 
440c333
<       return og_forum_get_sql();
---
>       return _og_forum_db_rewrite_sql();
446,467d338
<  * Filter terms by: og_forum_is_public(), user's group subscription and group forum term {og_term}
<  */
< function og_forum_get_sql() { 
<   global $user;
<   $return = array();
<   $return['distinct'] = TRUE;
<   $return['join'] = "LEFT JOIN {og_term} ogt ON ogt.tid = t.tid";
<   // Either the forum is unconfigured or public or public
<   $return['where'] = "ogt.public > " . PRIVATE_BY_GROUP_OWNER;
<   
<   if (!empty($user->og_groups)) { 
<     // Add own user groups into accessible forums/TIDs
<     $return['where'] .= " OR ogt.nid IN (" . implode(',', array_keys($user->og_groups)) . ")";
<   }
<   
<   if ($og_forum_container = variable_get('forum_default_container', FALSE)) {
<     $return['where'] .= " AND t.tid != $og_forum_container"; 
<   }
<   return $return;
< }
< 
< /**
475,476c346,347
<       if ($node->type == 'forum' && $og_forum_nid = db_result(db_query('SELECT nid FROM {og_term} WHERE tid = %d', $node->tid))) {
<         $node->og_forum_nid = $og_forum_nid;
---
>       if ($node->type == 'forum' && $gid = _og_forum_gid_from_tid($node->tid)) {
>         $node->og_forum_gid = $gid;
481,483c352,353
<         if (!og_get_group_context()) {
<           og_forum_set_og_group_context_from_tid(arg(3));
<           //return FALSE;
---
>         if (!og_get_group_context()) { //TODO check if arg(3) is numeric
>           _og_forum_set_og_group_context_from_tid(arg(3));
489,496c359,369
<         $default_container_yn = variable_get('forum_default_container_yn', FALSE);
<         if ($default_container_yn) {
<           $edit = array('name' => $node->title, 'vid' => og_forum_get_vid());
<           $default_container = variable_get('forum_default_container', 0);
<           $edit['parent'] = array($default_container);
<           unset($edit['tid']);
<           $status = taxonomy_save_term($edit);
<           db_query('INSERT INTO {og_term} (tid, nid) VALUES (%d, %d)', $edit['tid'], $node->nid);
---
>         $default_container_yn = variable_get('og_forum_default_container_yn', FALSE);
>      	if ($default_container_yn) {
>           $tid = variable_get('og_forum_default_container', 0);
>           $vid = _og_forum_get_vid();
>           $term = array(
> 		    'vid' => $vid, 
> 		    'name' => $node->title,		
> 		    'parent' => array($tid), 
> 		  );
> 		  taxonomy_save_term($term);
>           db_query('INSERT INTO {og_term} (nid) VALUES (%d)', $node->nid);
498,516c371
<         else {
<           //Added Functionality to allow for the creation of multiple forums/containers
<           //when a new group is created. To use, change the default forum name
<           //in OG_Forum administation to a semicolon seperated list
<           //e.g. Forum1;Forum2;Forum
<           //Use C for new container, P for the previous container, R to return to the root container
<           //e.g. Forum1;C;Container2;Forum2;C;Container3;Forum3;R;Forum4 would give the structure
<           //  Group Container
<           //  Forum1
<           //  Container2
<           //  ..Forum2
<           //  ..Container3
<           //  ....Forum3
<           //  Forum4
<           // NOTE: Weights are used to keep the ordering correct
<           // 2-19-2008 Josh Cohen
<           // Updated 3-13-2008 - Added ability to use descriptions. Follow the container or 
<           // forum number by a comma, then decription. e.g. Forum3, This is a description;Forum4
<           //
---
>         else { //TODO Multiple forum & containers should be implemented as a satellite module
518,602c373,379
<           $edit = array('name' => $node->title, 'vid' => og_forum_get_vid());
<           $status = taxonomy_save_term($edit);
<           $containers = variable_get('forum_containers', array());
<           $containers[] = $edit['tid'];
<           variable_set('forum_containers', $containers);
<           db_query('INSERT INTO {og_term} (tid, nid) VALUES (%d, %d)', $edit['tid'], $node->nid);
<           ///Start Multiple Forum Code Change 
<           // 2-19-2008 Josh Cohen
<           $curr_container = $edit['tid'];
<           $root_container = $curr_container;
<           unset($edit['tid']); //taxonomy_save_term will give us new tids
<           $default_forum_names = variable_get('forum_default_name', 'General discussion');
<           $forum_names = explode(";",$default_forum_names); //return default forum names as an array
<           $is_container = 0;
<           $c_order = array($root_container); //To keep track of the container sequence
<           $weight_indx = -10;
<           foreach ($forum_names as $fvalue){
<             switch(strtoupper($fvalue)){
<             case('C'): //Create New Container
<               $is_container = 1;
<               break;
<             case('P'): //Go to previous container
<               //Delete current container
<               if (end($c_order) != $root_container){
<                 array_pop($c_order);
<               }
<               //Set current container
<               $curr_container = end($c_order);
<               $is_container = 0;
<               break;
<             case('R'): //Go to the root container
<               unset($c_order);
<               $c_order = array($root_container);
<               $curr_container = $root_container;
<               $is_container = 0;
<               break;
<             default:
<               if ($is_container == '1'){
<                 //Add New Container
<                 $forum_names = explode(",",$fvalue); //Break out Name and Description
<                 if (count($forum_names) == 2){
<                   $fname = $forum_names[0];
<                   $fdesc = $forum_names[1];
<                 }else{
<                   $fname = $forum_names[0];
<                   unset($fdesc);
<                 }                
<                 $edit = array('name' => $fname, 'vid' => og_forum_get_vid(), 'parent' => $curr_container, 'weight' => $weight_indx, 'description' => $fdesc);
<                 $status = taxonomy_save_term($edit);
<                 $containers = variable_get('forum_containers', array());
<                 $containers[] = $edit['tid'];
<                 variable_set('forum_containers', $containers);
<                 $curr_container = $edit['tid'];
<                 $c_order[] = $edit['tid']; //Add the new container to our index
<                 unset($edit['tid']);
<                 unset($edit['parent']);
<                 $is_container = 0;                
<                 $weight_indx = $weight_indx + 1;                
<               }
<               else {
<                //Add New Forum
<                $forum_names = explode(",",$fvalue); //Break out Name and Description
<                 if (count($forum_names) == 2){
<                   $fname = $forum_names[0];
<                   $fdesc = $forum_names[1];
<                 }else{
<                   $fname = $forum_names[0];
<                   unset($fdesc);
<                 }       
<                $edit['name'] = $fname;
<                $edit['description'] = $fdesc;
<                $edit['parent'] = $curr_container;
<                $edit['weight'] = $weight_indx;               
<                $status = taxonomy_save_term($edit);
<                unset($edit['tid']); //Clear term so Taxonomy_save_term will generate a new term on next iteration
<                $is_container = 0;
<                $weight_indx = $weight_indx + 1;
<               }
<               break;
<             } //End Switch
<           }            
<           unset($forum_names); //clean up variables
<           unset($c_order);
<           //End Multiple Forum Code Change 
<           //2-19-2008 Josh Cohen         
---
>           $vid = _og_forum_get_vid();
>           $term = array(
> 		    'vid' => $vid, 
> 		    'name' => $node->title,		 
> 		  );
>           taxonomy_save_term($term); //TODO Should we checking if term was inserted or updated.
>           db_query('INSERT INTO {og_term} (nid) VALUES (%d)', $node->nid);       
605,606c382,384
<       elseif ($node->type == 'forum') {//if the node is marked public, check the 'puclicity' settings and act accordingly
<         //setup variables for common operations
---
>       elseif ($node->type == 'forum') {//if the node is marked public, check the 'publicity' settings and act accordingly
>         $container = _og_forum_get_forum_container(current($node->og_groups)); //??
>         $gid = _og_forum_gid_from_tid($node->tid);
608,612c386,388
<         $container = og_forum_get_forum_container(current($node->og_groups));
<         $gid = og_forum_gid_from_tid($node->tid);
<         $results = db_query($sql, $gid);
<         while ($result = db_fetch_object($results)) {
<           $forums[$result->tid] = $result->public;
---
>         $result = db_query($sql, $gid);
>         while ($data = db_fetch_object($result)) {
>           $forums[$data->tid] = $data->public;
661,662c437,438
<         $container = og_forum_get_forum_container(current($node->og_groups));
<         $gid = og_forum_gid_from_tid($node->tid);
---
>         $container = _og_forum_get_forum_container(current($node->og_groups));
>         $gid = _og_forum_gid_from_tid($node->tid);
702,703c478,479
<         while ($term = db_fetch_object($result)) {
<           taxonomy_del_term($term->tid);
---
>         while ($data = db_fetch_object($result)) {
>           taxonomy_del_term($data->tid);
711,712c487,488
<       if (!empty($page) && isset($node->og_forum_nid)) {
< 	    $group = node_load($node->og_forum_nid);
---
>       if (!empty($page) && isset($node->og_forum_gid)) {
> 	    $group = node_load($node->og_forum_gid);
718c494
<        $gid = og_forum_gid_from_tid($node->tid);
---
>        $gid = _og_forum_gid_from_tid($node->tid);
735,736c511,512
<     og_forum_set_og_group_context_from_tid($tid);
<     $gid = og_forum_gid_from_tid($tid);
---
>     _og_forum_set_og_group_context_from_tid($tid);
>     $gid = _og_forum_gid_from_tid($tid);
746,805d521
< function _og_forum_set_breadcrumb($tid, $is_forum_post = FALSE) {
<   $vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', ''));
<   $parents = array_reverse(taxonomy_get_parents_all($tid));
<   $title = $vocabulary->name;
<   // Breadcrumb navigation:
<   $gid = og_forum_gid_from_tid($tid);
<   $breadcrumb[] = l(t('Home'), NULL);
<   if ($gid != NULL) {
<     $node = node_load($gid);
< 	$breadcrumb[] = l(t('Groups'), 'og'); 
< 	$breadcrumb[] = l($node->title, 'node/'. $node->nid);
<   }
<   if ($parents && count($parents) != 1) {
<     $p = array_shift($parents);
<     $title = t('Forums');
< 	$breadcrumb[] = l($title, 'forum/' . $p->tid);
<     foreach ($parents as $p) {
<       if ($p->tid == $tid) {
<         $title = $p->name;
<         if ($is_forum_post)
<           	$breadcrumb[] = l(t($p->name), 'forum/' .$p->tid);
<       }
<       else {
<         $breadcrumb[] = l(t($p->name), 'forum/' .$p->tid);
<       }
<     }
<   }
<   if (!$is_forum_post)
<     drupal_set_title(check_plain($title));
<   drupal_set_breadcrumb($breadcrumb);	
< }
< 
< /**
<  * Retrieve container for given group
<  *
<  * @param $group_id
<  *   Organic group ID
<  * @return
<  *   Forum container's term ID
<  */
< function og_forum_get_forum_container($group_id) {
<   // If it exists, grab the first term created for group; this will be the forum container; if not, it is a forum inside a generic container; find it
<   return db_result(db_query_range('SELECT tid FROM {og_term} WHERE nid = %d ORDER BY tid ASC', $group_id, 0, 1));
< } // function og_forum_get_forum_container()
< 
< /**
<  * Check if a user is a group manager of the given group
<  */
< function og_forum_is_admin($group) {
<   global $user;
<   $result = db_query(og_list_users_sql(0), $group->nid);
<   while ($row = db_fetch_object($result)) {
<     if ($user->uid == 1 && user_access('administer forums')) return TRUE;
<     if ($row->uid == $user->uid) { 
<       if ($row->is_admin > 0) return TRUE;
<     }
<   }
<   return FALSE;
< } // function og_forum_is_admin()
< 
813c529
<   $forum  = og_forum_get_forum_container($group->nid);
---
>   $forum  = _og_forum_get_forum_container($group->nid);
816,818c532,533
<   // Add forum creation link for the group managers
<     if ((og_forum_is_admin($group) && user_access('admin own group forums')) || user_access('administer forums')) { 
<       $links['manage_forums'] = l(t('Manage group forums'), 'og_forum/manage/' . $group->nid, array('attributes' => array('title' => t('Let you create, edit, delete group\'s forums.'))));
---
>     if ((_og_forum_is_admin($group) && user_access('admin own group forums')) || user_access('administer forums')) { 
>       $links['manage_forums'] = l(t('Manage group forums'), 'og_forum/manage/' . $group->nid, array('attributes' => array('title' => t('Let\'s you create, edit and delete group forums.'))));
822,841c537
< } // function og_forum_og_create_links()
< 
< /**
<  * Creates forums for all groups that don't have any yet.
<  */
< function og_forum_retroactively_apply() {
<   $counter = 0;
<   // Obtain list of all groups
<   $result = db_query('SELECT og.nid, n.title, n.type FROM {og} og INNER JOIN {node} n on og.nid = n.nid');
<   while ($group = db_fetch_object($result)) {
<     // See if terms are found for this group
<     if (!db_result(db_query('SELECT * FROM {og_term} ogt WHERE ogt.nid = %d', $group->nid))) {
<       // If not, fake a nodeapi insert
<       og_forum_nodeapi($group, 'insert');
<       $counter++;
<     }
<   }
<   drupal_set_message(t('%num groups had forums created', array('%num' => $counter)));
< } // function og_forum_retroactively_apply()
< 
---
> }
854,855c550,551
<         $result = db_fetch_object(db_query($sql, arg(1)));
<         og_forum_set_og_group_context_from_tid($result->tid);
---
>         $data = db_fetch_object(db_query($sql, arg(1)));
>         _og_forum_set_og_group_context_from_tid($data->tid);
861,864c557,560
<       $results = db_query('SELECT ot.tid, th.parent FROM {og_term} ot LEFT JOIN {term_hierarchy} th ON ot.tid = th.tid WHERE nid = %d ORDER BY tid ASC', $gid);
<       $all_results = array();
<       while ($result = db_fetch_object($results)) {
<         $all_results[$result->tid] = $result->parent;
---
>       $result = db_query('SELECT ot.tid, th.parent FROM {og_term} ot LEFT JOIN {term_hierarchy} th ON ot.tid = th.tid WHERE nid = %d ORDER BY tid ASC', $gid);
>       $term_hierarchies = array();
>       while ($data = db_fetch_object($result)) {
>         $term_hierarchies[$data->tid] = $data->parent;
866c562
<       $vid =  og_forum_get_vid(); 
---
>       $vid =  _og_forum_get_vid(); 
876c572
<         $first = reset($all_results);
---
>         $first = reset($term_hierarchies);
878c574
<           next($all_results);
---
>           next($term_hierarchies);
880c576
<         $term = key($all_results);
---
>         $term = key($term_hierarchies);
889c585
<         if (is_array($all_results) && !array_key_exists($option_key, $all_results)) {
---
>         if (is_array($term_hierarchies) && !array_key_exists($option_key, $term_hierarchies)) {
908,910c604,606
<       $results = db_query('SELECT ot.tid, th.parent FROM {og_term} ot LEFT JOIN {term_hierarchy} th ON ot.tid = th.tid ORDER BY tid ASC');
<       while ($result = db_fetch_object($results)) {
<         $all_results[$result->tid] = $result->parent;
---
>       $result = db_query('SELECT ot.tid, th.parent FROM {og_term} ot LEFT JOIN {term_hierarchy} th ON ot.tid = th.tid ORDER BY tid ASC');
>       while ($data = db_fetch_object($result)) {
>         $term_hierarchies[$data->tid] = $data->parent;
912c608
<       $vid =  og_forum_get_vid(); 
---
>       $vid =  _og_forum_get_vid(); 
930c626
<           if (is_array($all_results) && array_key_exists($option_key, $all_results)) {
---
>           if (is_array($term_hierarchies) && array_key_exists($option_key, $term_hierarchies)) {
940c636
<     $allow_public = variable_get('forum_allow_public', 0);
---
>     $allow_public = variable_get('og_forum_allow_public', 0);
953c649
<     $allow_public = variable_get('forum_allow_public', 0);
---
>     $allow_public = variable_get('og_forum_allow_public', 0);
965c661,902
< } // function og_forum_form_alter()
---
> }
> 
> /**
>  * hook_taxonomy implementation
>  * 
>  * This should replace og_forum's own management of terms which bypasses regular taxonomy. Using this function allows group
>  * forums to be managed both from within the group and at the site-wide forum admin pages.
>  *
>  * @param string $op
>  * @param string $type
>  * @param array $obj
>  */
> function og_forum_taxonomy($op, $type, $obj) {
>   switch ($op) {
>     case 'insert':
>     case 'update':
>       if (isset($obj['parent'])) {
>         $parent = (is_array ($obj['parent'])) ? $obj['parent'][0] : $obj['parent'];
>         $nid = db_result(db_query("SELECT nid FROM {og_term} WHERE tid = %d", $parent));
>         if ($nid) {
>           if (!db_result(db_query('SELECT tid FROM {og_term} WHERE tid = %d', $obj['tid']))) {
>             db_query('INSERT INTO {og_term} (tid, nid) VALUES (%d, %d)', $obj['tid'], $nid);
>           }
>         }
>       }
>       break;
>     case 'delete':
>       if (isset($obj['tid'])) {
>         db_query("DELETE FROM {og_term} WHERE tid = %d", $obj['tid']);
>       }
>       break;
>   }
> }
> 
> function og_forum_preprocess_node(&$variables) {
>   	if (!empty($variables['page']) && $variables['type'] == 'forum') {
>     _og_forum_set_breadcrumb($variables['tid'], TRUE); 
>   }
> }
> 
> function og_forum_preprocess_forums(&$variables) {
>   if(isset($variables['tid']) && $variables['tid'] != 0) {
>     $gid = _og_forum_gid_from_tid($variables['tid']);
>     if (!empty($gid)) {
>       _og_forum_set_group_context(node_load($gid));
>       _og_forum_set_breadcrumb($variables['tid']);
>       if (isset($variables['links']['forum'])) {
>         $variables['links']['forum']['query'] = array('gids[]' => $gid);
>       }
>     }
>   }
> }
> 
> 
> 
> /**
>  * Helper functions.
>  */
> 
> 
> function _og_forum_topic_redirect($tid=0) {
>   if ($tid) {	 
>     $gid = _og_forum_gid_from_tid($tid);
>     if ($gid)
>       drupal_goto("node/$gid/og/forum/$tid");  
>   }
>   return forum_page($tid);
> }
> 
> function _og_forum_manage_public_private_reset_access ($gid) {
>   $group = node_load($gid);
>   $allow_public = variable_get('og_forum_allow_public', 0);	
>   return ((_og_forum_is_admin($group) && user_access('admin own group forums') && $allow_public) || user_access('make forums public'));	
> }	
> 
> function _og_forum_manage_add_edit_access ($gid, $tid) {
>   $group = node_load($gid);
>   return ((_og_forum_is_admin($group) && user_access('admin own group forums'))  || user_access('administer forums'));
> } // took off !_og_forum_forum_limit_reached($tid)
> 
> /**
>  * Custom submit handler for group update
>  */
> function _og_forum_settings_submit($form, &$form_state) {
>   $form_values = $form_state['values'];
>   if ($form_values['op'] == t('Update old groups')) {
>     _og_forum_retroactively_apply();
>   }
>   elseif ($form_values['op'] == t('Publicize old groups')) {
>     $auto_public = variable_get('og_forum_auto_public', 0);
>     if ($auto_public) {
>       //go through all existing forums and where a node has been made public, set the forum's publicity to PUBLIC_AUTO
>       $sql = "SELECT DISTINCT tn.tid, oa.group_nid FROM {node} n INNER JOIN {og_ancestry} oa ON oa.nid = n.nid INNER JOIN {og_access_post} oap ON oap.nid = oa.nid INNER JOIN {term_node} tn ON tn.nid = oa.nid  WHERE n.type = 'forum' AND oap.og_public = 1";
>       $result = db_query($sql);
>       while ($data = db_fetch_object($result)) {
>         $gid = $data->group_nid;
>         $tid = _og_forum_get_forum_container($gid);
>         $sql = "UPDATE {og_term} SET public = %d WHERE tid = %d and nid = %d";  //TODO change og_term field nid to gid?
>         db_query($sql, PUBLIC_AUTO, $data->tid, $gid);
>         db_query($sql, PUBLIC_AUTO, $tid, $gid);
>       }
>     }
>     else {
>       drupal_set_message(t('You need to select "Automatic forum publicity" for this to work.'), 'error');
>     }
>   }
>   elseif ($form_values['op'] == t('Switch to auto mode')) {
>     $sql = "UPDATE {og_term} SET public = %d WHERE public = %d";
>     db_query($sql, PUBLIC_AUTO, PUBLIC_BY_GROUP_OWNER);
>     db_query($sql, PRIVATE_DEFAULT, PRIVATE_BY_GROUP_OWNER);
>   }
>   if ($form_values['op'] == t('Save configuration')) {
>     variable_set('og_forum_default_name', $form_values['default_forum_name']);
>     variable_set('og_forum_default_container_yn', $form_values['default_container_yn']);
>     variable_set('og_forum_default_container', $form_values['default_container']);
>     variable_set('og_forum_allow_public', $form_values['allow_public']);
>     variable_set('og_forum_auto_public', $form_values['auto_public']);
>     variable_set('og_forum_all_public', $form_values['all_public']);
>     variable_set('og_forum_limit_forums', $form_values['limit_forums']);
>   }
> }
> 
> /**
>  * using the tid, set the group context
>  */
> function _og_forum_set_og_group_context_from_tid($tid=0) {
>   $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
>   if ($gid = db_result(db_query($sql, $tid))) {
>     $group_node = node_load($gid);
>     og_set_group_context($group_node);
>   }
> } 
> 
> /**
>  * using the tid, get the group id
>  */
> function _og_forum_gid_from_tid($tid=0) { //TODO change og_term field nid to gid?
>   $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
>   if ($gid = db_result(db_query($sql, $tid))) {
>     return $gid;
>   }
>   else {
>     return FALSE;
>   }
> }
> 
> /**
>  * Filter terms by: _og_forum_is_public(), user's group subscription and group forum term {og_term}
>  */
> function _og_forum_db_rewrite_sql() { 
>   global $user;
>   $return = array();
>   $return['distinct'] = TRUE;
>   $return['join'] = "LEFT JOIN {og_term} ogt ON ogt.tid = t.tid";  //TODO Does it matter that the query that were modifying uses INNER JOINS?
>   //TODO Is this correct?
>   $return['where'] = "ogt.public IS NULL OR ogt.public > " . PRIVATE_BY_GROUP_OWNER;
>   if (!empty($user->og_groups)) { 
>     // Add own user groups into accessible forums/TIDs
>     $return['where'] .= " OR ogt.nid IN (" . implode(',', array_keys($user->og_groups)) . ")";
>   }
>   if ($og_forum_container = variable_get('og_forum_default_container', FALSE)) {
>     $return['where'] .= " AND t.tid != $og_forum_container"; 
>   }
>   return $return;
> }
> 
> function _og_forum_set_breadcrumb($tid, $is_forum_post = FALSE) {
>   $vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', ''));
>   $parents = array_reverse(taxonomy_get_parents_all($tid));
>   $title = $vocabulary->name;
>   // Breadcrumb navigation:
>   $gid = _og_forum_gid_from_tid($tid);
>   $breadcrumb[] = l(t('Home'), NULL);
>   if ($gid != NULL) {
>     $node = node_load($gid);
> 	$breadcrumb[] = l(t('Groups'), 'og'); 
> 	$breadcrumb[] = l($node->title, 'node/'. $node->nid);
>   }
>   if ($parents && count($parents) != 1) {
>     $p = array_shift($parents);
>     $title = t('Forums');
> 	$breadcrumb[] = l($title, 'forum/' . $p->tid);
>     foreach ($parents as $p) {
>       if ($p->tid == $tid) {
>         $title = $p->name;
>         if ($is_forum_post)
>           	$breadcrumb[] = l(t($p->name), 'forum/' . $p->tid);
>       }
>       else {
>         $breadcrumb[] = l(t($p->name), 'forum/' . $p->tid);
>       }
>     }
>   }
>   if (!$is_forum_post)
>     drupal_set_title(check_plain($title));
>   drupal_set_breadcrumb($breadcrumb);	
> }
> 
> /**
>  * Retrieve container for given group
>  *
>  * @param $group_id
>  *   Organic group ID
>  * @return
>  *   Forum container's term ID
>  */
> function _og_forum_get_forum_container($group_id) {
>   // If it exists, grab the first term created for group; this will be the forum container; if not, it is a forum inside a generic container; find it
>   return db_result(db_query_range('SELECT tid FROM {og_term} WHERE nid = %d ORDER BY tid ASC', $group_id, 0, 1));
> }
> 
> /**
>  * Check if a user is a group manager of the given group
>  */
> function _og_forum_is_admin($group) { //TODO taken out user_access('administer forums')
>   global $user;
>   $result = db_query(og_list_users_sql(0), $group->nid);
>   while ($data = db_fetch_object($result)) {
>     if (($data->uid == $user->uid) && $data->is_admin) { 
>       return TRUE;
>     }
>   }
>   return FALSE;
> }
> 
> /**
>  * Creates forums for all groups that don't have any yet.
>  */
> function _og_forum_retroactively_apply() {
>   $counter = 0;
>   // Obtain list of all groups
>   $result = db_query('SELECT og.nid, n.title, n.type FROM {og} og INNER JOIN {node} n on og.nid = n.nid');
>   while ($data = db_fetch_object($result)) {
>     // See if terms are found for this group
>     if (!db_result(db_query('SELECT * FROM {og_term} ogt WHERE ogt.nid = %d', $data->nid))) {
>       // If not, fake a nodeapi insert
>       og_forum_nodeapi($data, 'insert');
>       $counter++;
>     }
>   }
>   drupal_set_message(t('%num groups had forums created', array('%num' => $counter)));
> }
970c907
< function og_forum_manage($gid) { 
---
> function _og_forum_manage($gid) { 
973c910,911
<   $allow_public = variable_get('forum_allow_public', 0);
---
>   $vid = _og_forum_get_vid();
>   $allow_public = variable_get('og_forum_allow_public', 0);
977d914
<   // set a nice breadcrumb
979,981c916,918
<   $content = '<p>' .t('This page shows the forums associated with the %group group.', array('%group' => $group->title)). '</p>';
<   $og_terms = _og_forum_ogterms($group);
<   $forum_limit_reached = og_forum_forum_limit_reached($group->nid);
---
>   $content = '<p>' . t('This page shows the forums associated with the %group group.', array('%group' => $group->title)) . '</p>';
>   $og_terms = _og_forum_og_terms($group);
>   $forum_limit_reached = _og_forum_forum_limit_reached($group->nid);
984,991c921,928
<   $results = db_query($sql, $group->nid);
<   $all_tids = array();
<   while ($result = db_fetch_object($results)) {
<     $all_tids[$result->tid] = $result->public;
<   }
<   $tree = taxonomy_get_tree(og_forum_get_vid());
<   if ($tree) {
<     foreach ($tree as $term) {
---
>   $result = db_query($sql, $group->nid);
>   $publicity = array();
>   while ($data = db_fetch_object($result)) {
>     $publicity[$data->tid] = $data->public;
>   }
>   $terms = taxonomy_get_tree();
>   if ($terms) {
>     foreach ($terms as $term) {
993,994c930,931
<         if (in_array($term->tid, variable_get('forum_containers', array()))) {//we're looking at a container
<           if ($forum_limit_reached && !(user_access('administer forums'))) {//the limit for the number of forums allowed was reached
---
>         if (in_array($term->tid, variable_get('forum_containers', array()))) {
>           if ($forum_limit_reached && !(user_access('administer forums'))) {
996c933
<             $rows[] = array(str_repeat('-', $term->depth). ' ' .check_plain($term->name), array('data' => '', 'colspan' => '3'));
---
>             $rows[] = array(str_repeat('-', $term->depth). ' ' . check_plain($term->name), array('data' => '', 'colspan' => '3'));
999c936
<             $rows[] = array(str_repeat('-', $term->depth). ' ' .check_plain($term->name), array('data' => l(t('add forum'), "og_forum/manage/add/$group->nid/$term->tid"), 'colspan' => '3'));
---
>             $rows[] = array(str_repeat('-', $term->depth). ' ' . check_plain($term->name), array('data' => l(t('add forum'), "og_forum/manage/add/$group->nid/$term->tid"), 'colspan' => '3'));
1003,1004c940,941
<           if ((user_access('make forums public') || $allow_public) && $all_tids[$term->tid] < PUBLIC_AUTO) {//it's presently private
<             $rows[] = array(str_repeat('-', $term->depth). ' ' .check_plain($term->name), l(t('edit forum'), "og_forum/manage/edit/$group->nid/$term->tid"), l(t('make public'), "og_forum/manage/public/$group->nid/$term->tid"), l(t('reset publicity'), "og_forum/manage/reset/$group->nid/$term->tid"));
---
>           if ((user_access('make forums public') || $allow_public) && $publicity[$term->tid] < PUBLIC_AUTO) {//it's presently private
>             $rows[] = array(str_repeat('-', $term->depth). ' ' . check_plain($term->name), l(t('edit forum'), "og_forum/manage/edit/$group->nid/$term->tid"), l(t('make public'), "og_forum/manage/public/$group->nid/$term->tid"), l(t('reset publicity'), "og_forum/manage/reset/$group->nid/$term->tid"));
1006,1007c943,944
<           elseif ((user_access('make forums public') || $allow_public) && $all_tids[$term->tid] > PRIVATE_BY_GROUP_OWNER) {//it's presently public
<             $rows[] = array(str_repeat('-', $term->depth). ' ' .check_plain($term->name), l(t('edit forum'), "og_forum/manage/edit/$group->nid/$term->tid"), l(t('make private'), "og_forum/manage/private/$group->nid/$term->tid"), l(t('reset publicity'), "og_forum/manage/reset/$group->nid/$term->tid"));
---
>           elseif ((user_access('make forums public') || $allow_public) && $publicity[$term->tid] > PRIVATE_BY_GROUP_OWNER) {//it's presently public
>             $rows[] = array(str_repeat('-', $term->depth). ' ' . check_plain($term->name), l(t('edit forum'), "og_forum/manage/edit/$group->nid/$term->tid"), l(t('make private'), "og_forum/manage/private/$group->nid/$term->tid"), l(t('reset publicity'), "og_forum/manage/reset/$group->nid/$term->tid"));
1010c947
<             $rows[] = array(str_repeat('-', $term->depth). ' ' .check_plain($term->name), l(t('edit forum'), "og_forum/manage/edit/$group->nid/$term->tid"));
---
>             $rows[] = array(str_repeat('-', $term->depth). ' ' . check_plain($term->name), l(t('edit forum'), "og_forum/manage/edit/$group->nid/$term->tid"));
1017c954
< } // function og_forum_manage()
---
> } 
1023c960
< function og_forum_form_main($type, $group_id, $tid) {
---
> function _og_forum_form_main($type, $group_id, $tid) { //TODO some redundancy
1026c963
<     return drupal_get_form('og_forum_confirm_delete', $tid, $group_id);
---
>     return drupal_get_form('_og_forum_confirm_delete', $tid, $group_id);
1031c968
<       return drupal_get_form('og_forum_form_forum', $edit, $group_id, $edit['tid']);
---
>       return drupal_get_form('_og_forum_form_forum', $edit, $group_id, $edit['tid']);
1041c978
<       return drupal_get_form('og_forum_form_forum', $edit, $group_id);
---
>       return drupal_get_form('_og_forum_form_forum', $edit, $group_id);
1043c980
< } // function og_forum_form_main(
---
> }
1049,1051c986,989
< function og_forum_form_forum(&$form_state, $edit, $group_id = 0, $tid = 0) { 
<   $node = node_load($group_id);
<   og_set_language($node);
---
> function _og_forum_form_forum(&$form_state, $edit, $group_id = 0, $tid = 0) { 
>   $group = node_load($group_id);
>   $vid = _og_forum_get_vid();
>   og_set_language($group);
1069c1007
<     _og_forum_manage_breadcrumb(node_load($group_id), 'add');
---
>     _og_forum_manage_breadcrumb($group, 'add');
1076c1014
<     _og_forum_manage_breadcrumb(node_load($group_id), 'edit');
---
>     _og_forum_manage_breadcrumb($group, 'edit');
1091c1029
<   $allow_public = variable_get('forum_allow_public', 0);
---
>   $allow_public = variable_get('og_forum_allow_public', 0);
1101c1039
<   $form['vid'] = array('#type' => 'hidden', '#value' => og_forum_get_vid());
---
>   $form['vid'] = array('#type' => 'hidden', '#value' => $vid);
1107,1108c1045,1046
<   $form['#submit'][] = 'og_forum_form_submit';
<   $form['#validate'][] = 'og_forum_form_validate';
---
>   $form['#submit'][] = '_og_forum_form_submit';
>   $form['#validate'][] = '_og_forum_form_validate';
1110c1048
< } // function og_forum_form_forum()
---
> }
1115c1053
< function og_forum_form_validate($form, &$form_state) {
---
> function _og_forum_form_validate($form, &$form_state) {
1122c1060
<     if ($group && og_forum_is_admin($group) && (in_array($form_values['parent'], _og_forum_ogterms($group)) || $form_values['tid'])) {
---
>     if ($group && _og_forum_is_admin($group) && (in_array($form_values['parent'], _og_forum_og_terms($group)) || $form_values['tid'])) {
1130c1068
< } // function og_forum_form_validate()
---
> }
1135c1073
< function og_forum_form_submit($form, &$form_state) {
---
> function _og_forum_form_submit($form, &$form_state) {
1142c1080
<       if ($container) {
---
>       if ($container) { //TODO is this always false?
1153,1186c1091,1092
<   $form_state['redirect'] = 'og_forum/manage/' .$form_values['group_id'];
< } // function og_forum_form_submit()
< 
< /**
<  * hook_taxonomy implementation
<  * 
<  * This should replace og_forum's own management of terms which bypasses regular taxonomy. Using this function allows group
<  * forums to be managed both from within the group and at the site-wide forum admin pages.
<  *
<  * @param string $op
<  * @param string $type
<  * @param array $obj
<  */
< function og_forum_taxonomy($op, $type, $obj) {
<   switch ($op) {
<     case 'insert':
<     case 'update':
<       if (isset($obj['parent'])) {
<         $parent = (is_array ($obj['parent'])) ? $obj['parent'][0] : $obj['parent'];
<         $result = db_result(db_query("SELECT nid FROM {og_term} WHERE tid = %d", $parent));
<         if ($result) {
<           if (!db_result(db_query('SELECT tid FROM {og_term} WHERE tid = %d', $obj['tid']))) {
<             db_query('INSERT INTO {og_term} (tid, nid) VALUES (%d, %d)', $obj['tid'], $result);
<           }
<         }
<       }
<       break;
<     case 'delete':
<       if (isset($obj['tid'])) {
<         db_query("DELETE FROM {og_term} WHERE tid = %d", $obj['tid']);
<       }
<       break;
<   }
< } // function og_forum_taxonomy()
---
>   $form_state['redirect'] = 'og_forum/manage/' . $form_values['group_id'];
> }
1193c1099
< function og_forum_confirm_delete($form_state, $tid, $group_id) {
---
> function _og_forum_confirm_delete($form_state, $tid, $group_id) {
1198c1104
<   $return_address = 'og_forum/manage/' .arg(3);
---
>   $return_address = 'og_forum/manage/' . arg(3);
1202c1108
< } // function og_forum_confirm_delete()
---
> }
1207c1113
< function og_forum_confirm_delete_submit($form, &$form_state) {
---
> function _og_forum_confirm_delete_submit($form, &$form_state) {
1210c1116
<   $group_id = og_forum_gid_from_tid($form_values['tid']);
---
>   $group_id = _og_forum_gid_from_tid($form_values['tid']);
1215c1121
< } // function og_forum_confirm_delete_submit()
---
> }
1240c1146
< } // function _og_forum_manage_breadcrumb()
---
> } 
1245c1151
< function _og_forum_ogterms($group) {
---
> function _og_forum_og_terms($group) {
1252c1158
< } // function _og_forum_ogterms()
---
> } 
1260,1262c1166,1168
< function og_forum_forum_limit_reached($nid) {
<   $forum_limit = variable_get('forum_limit', 0);
<   if ($forum_limit == 0) return FALSE;
---
> function _og_forum_forum_limit_reached($nid) {
>   $forum_limit_forums = variable_get('forum_limit_forums', 0);
>   if ($forum_limit_forums == 0) return FALSE;
1267c1173
<   if ($num_forums >= $forum_limit) {
---
>   if ($num_forums >= $forum_limit_forums) {
1273c1179
< } // function og_forum_forum_limit_reached()
---
> }
1281,1282c1187,1188
< function og_forum_public($gid, $tid) {
<   $container = og_forum_get_forum_container($gid);
---
> function _og_forum_public($gid, $tid) {
>   $container = _og_forum_get_forum_container($gid);
1286,1287c1192,1193
<   return drupal_goto('og_forum/manage/'. $gid);
< } // function og_forum_public()
---
>   return drupal_goto('og_forum/manage/' . $gid);
> }
1295,1296c1201,1202
< function og_forum_private($gid, $tid) {
<   $container = og_forum_get_forum_container($gid);
---
> function _og_forum_private($gid, $tid) {
>   $container = _og_forum_get_forum_container($gid);
1299,1302c1205,1208
<   $sql2 = "SELECT COUNT(tid) FROM {og_term} WHERE nid = %d AND tid <> %d AND public > 1";
<   $results = db_query($sql2, $gid, $container);//find out if any other forums are public
<   $result = db_result($results);
<   if (!$result) {//if no other forums in the group are public, go ahead and make the container private
---
>   $sql2 = "SELECT COUNT(tid) FROM {og_term} WHERE nid = %d AND tid <> %d AND public > %d";
>   $result = db_query($sql2, $gid, $container, PRIVATE_BY_GROUP_OWNER); //find out if any other forums are public
>   $count = db_result($result);
>   if (!$count) {//if no other forums in the group are public, go ahead and make the container private
1305,1306c1211,1212
<   return drupal_goto('og_forum/manage/'. $gid);
< } // function og_forum_private()
---
>   return drupal_goto('og_forum/manage/' . $gid);
> }
1314,1315c1220,1221
< function og_forum_reset($gid, $tid) {
<   $container = og_forum_get_forum_container($gid);
---
> function _og_forum_reset($gid, $tid) {
>   $container = _og_forum_get_forum_container($gid);
1318,1321c1224,1227
<   $sql2 = "SELECT COUNT(tid) FROM {og_term} WHERE nid = %d AND tid <> %d AND public > 1";
<   $results = db_query($sql2, $gid, $container);//find out if any other forums are public
<   $result = db_result($results);
<   if (!$result) {//if no other forums in the group are public, go ahead and make the container private
---
>   $sql2 = "SELECT COUNT(tid) FROM {og_term} WHERE nid = %d AND tid <> %d AND public > %d";
>   $result = db_query($sql2, $gid, $container, PRIVATE_BY_GROUP_OWNER);//find out if any other forums are public
>   $count = db_result($result);
>   if (!$count) {//if no other forums in the group are public, go ahead and make the container private
1325c1231
< } // function og_forum_reset()
---
> }
1330c1236
< function og_forum_is_public($tid) {
---
> function _og_forum_is_public($tid) {
1332,1333c1238,1239
<   $results = db_fetch_object(db_query($sql, $tid));
<   if (!empty($results) && ($results->public <= PRIVATE_BY_GROUP_OWNER)) {
---
>   $result = db_fetch_object(db_query($sql, $tid));
>   if (!empty($result) && ($result->public <= PRIVATE_BY_GROUP_OWNER)) {
1341c1247
< function og_forum_get_vid() {
---
> function _og_forum_get_vid() {
1346,1364d1251
< function og_forum_preprocess_node(&$variables) {
<   	if (!empty($variables['page']) && $variables['type'] == 'forum') {
<     _og_forum_set_breadcrumb($variables['tid'], TRUE); 
<   }
< }
< 
< function og_forum_preprocess_forums(&$variables) {
<   if(isset($variables['tid']) && $variables['tid'] != 0) {
<     $gid = og_forum_gid_from_tid($variables['tid']);
<     if (!empty($gid)) {
<       _og_forum_set_group_context(node_load($gid));
<       _og_forum_set_breadcrumb($variables['tid']);
<       if (isset($variables['links']['forum'])) {
<         $variables['links']['forum']['query'] = array('gids[]' => $gid);
<       }
<     }
<   }
< }
< 
1371c1258
< function og_forum_access_forum_page($tid = 0) {
---
> function _og_forum_access_forum_page($tid = 0) {
1380,1381c1267,1268
<     og_forum_set_og_group_context_from_tid($tid);
<     $gid = og_forum_gid_from_tid($tid); 
---
>     _og_forum_set_og_group_context_from_tid($tid);
>     $gid = _og_forum_gid_from_tid($tid); 
1383c1270
<       	if (!(!empty($user->og_groups) && array_key_exists($gid, $user->og_groups)) && ($user->uid != 1) && !(user_access('administer forums')) && !og_forum_is_public($tid)) {	
---
>       	if (!(!empty($user->og_groups) && array_key_exists($gid, $user->og_groups)) && ($user->uid != 1) && !(user_access('administer forums')) && !_og_forum_is_public($tid)) {	
