Index: og.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/og.module,v retrieving revision 1.158 diff -u -p -r1.158 og.module --- og.module 9 Apr 2006 03:38:24 -0000 1.158 +++ og.module 9 Apr 2006 17:13:11 -0000 @@ -19,8 +19,6 @@ function og_help($section) { break; case 'admin/modules#description': return t("Organic groups"); - case 'node/add#og': - return t("A group provides a home page for like minded users. There they post articles about their shared interest."); case strstr($section, 'admin/block/configure/og'): return t('Group specific blocks are only visible on group pages and not on systemwide pages like the home page or admin pages.'); case 'admin/settings/og': @@ -36,7 +34,6 @@ function og_menu($may_cache) { if ($may_cache) { // anon users should be able to get to the subscribe page $items[] = array('path' => 'og/subscribe', 'type' => MENU_CALLBACK, 'callback' => 'og_subscribe', 'access' => TRUE, 'title' => t('subscribe to group')); - $items[] = array('path' => 'node/add/og', 'title' => t('group'), 'access' => user_access('create groups')); $items[] = array('path' => 'og', 'callback' => 'og_list_groups_page', 'title' => t('groups'), 'weight' => 3, 'access' => user_access('access content')); $access = $user->uid; // login is required $items[] = array('path' => 'og/unsubscribe', 'type' => MENU_CALLBACK, 'callback' => 'og_unsubscribe', 'access' => $access, 'title' => t('unsubscribe from group')); @@ -64,7 +61,7 @@ function og_menu($may_cache) { if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(arg(1)); - if ($node->type == 'og') { + if (in_array($node->type, variable_get('og_node_types', array('og')))) { $items[] = array('path' => 'node/'. arg(1). '/email', 'title' => t('email'), 'callback' => 'og_email', 'callback arguments' => array(arg(1)), 'access' => node_access('update', $node), 'type' => MENU_LOCAL_TASK, 'weight' => 7); } } @@ -74,8 +71,11 @@ function og_menu($may_cache) { return $items; } +/** + * Implementation of hook_perm(). + */ function og_perm() { - return array('create groups', 'administer organic groups'); + return array('administer organic groups'); } /** @@ -136,7 +136,7 @@ function og_set_group_context($group_nod function og_set_theme($nid) { global $custom_theme, $user; $node = node_load(intval($nid)); - if ($node->type == 'og') { + if (in_array($node->type, variable_get('og_node_types', array('og')))) { $custom_theme = $node->og_theme; return $node; } @@ -559,20 +559,6 @@ function og_get_subscriptions($uid) { return $subscriptions[$uid]; } -/** - * Implementation of hook_access(). - */ -function og_access($op, $node) { - global $user; - if ($op == 'create') { - return user_access('create groups') && $user->uid; - } - - if ($user->uid && $node->uid == $user->uid && ($op == 'update' || $op == 'delete')) { - return TRUE; - } -} - function og_list_users_sql($min_is_active = 1, $min_is_admin = 0) { return "SELECT u.uid, u.name, u.mail, u.picture, ou.* FROM {og_uid} ou INNER JOIN {users} u ON ou.uid = u.uid WHERE ou.nid = %d AND u.status > 0 AND is_active >= $min_is_active AND is_admin >= $min_is_admin ORDER BY u.name ASC"; } @@ -681,7 +667,7 @@ function og_list_groups_page() { global $user; $result = pager_query(db_rewrite_sql("SELECT og.nid, n.title, r.body, n.uid, u.name, og.description FROM {og} og INNER JOIN {node} n ON og.nid = n.nid INNER JOIN {node_revisions} r ON r.vid = n.vid INNER JOIN {users} u ON n.uid = u.uid WHERE og.directory=1 AND n.status=1 ORDER BY n.nid DESC", 'og', 'nid'), 50); - $header = array(t("Title"), t('Subscribers'), t("Manager"), t('Description')); + $header = array(t('Title'), t('Subscribers'), t('Manager'), t('Description')); while ($node = db_fetch_object($result)) { $cnt = db_num_rows(db_query(og_list_users_sql(), $node->nid)); @@ -715,7 +701,7 @@ function og_get_home_nodes_sql($str_type } } else { - $where = "n.type != 'og'"; + $where = "n.type NOT IN ('" . implode("','", variable_get('og_node_types', array('og'))) . "')"; } // we LEFT JOIN to node_comment_stats in case comment.module is disabled. @@ -744,7 +730,7 @@ function og_db_rewrite_sql($sql, $primar // when you view a group, you really see some facts about the group in a block and then lists of nodes affiliated with that group. // each of these lists is presented by default in a table, although that can be changed by the theme -function og_view(&$node, $teaser = FALSE, $page = FALSE) { +function og_view_group(&$node, $teaser = FALSE, $page = FALSE) { $node = theme('og_view', $node, $teaser, $page); return $node; } @@ -814,13 +800,10 @@ function theme_og_view(&$node, $teaser = * * @param object $node */ -function og_form(&$node) {//, &$param) { - $form['title'] = array('#type' => 'textfield', '#title' => t('Name'), '#weight' => 0, '#default_value' => $node->title, '#size' => 60, '#maxlength' => 128, '#required' => true); +function og_node_form(&$node) { $edit = $_POST['edit']; $form['og_description'] = array('#type' => 'textfield', '#title' => t('Description'), '#default_value' => $node->og_description, '#size' => 70, '#maxlength' => 150, '#required' => true, '#description' => t('A brief description for the group details block and the group directory.')); - $form['body'] = array('#type' => 'textarea', '#title' => t('Welcome message'), '#default_value' => $node->body, '#rows' => 10, '#required' => FALSE, '#description' => t('This message is shown by default at the top of the group home page.')); - $form['format'] = filter_form($node->format); $form['og_website'] = array('#type' => 'textfield', '#title' => t('Group website'), '#default_value' => $node->og_website, '#description' => t('If your group has its own website, enter the address here.')); if (isset($edit['og_selective'])) { @@ -916,7 +899,7 @@ function og_node_load_public($node) { // returns all the group affiliations for a given node. function og_get_node_groups($node) { - if ($node->type != 'og') { + if (in_array($node->type, variable_get('og_node_types', array('og')))) { $sql = "SELECT na.gid, n.title FROM {node_access} na INNER JOIN {node} n ON na.gid = n.nid WHERE na.nid = %d AND na.realm='og_subscriber' AND na.gid != 0"; $result = db_query($sql, $node->nid); while ($row = db_fetch_object($result)) { @@ -929,7 +912,7 @@ function og_get_node_groups($node) { /** * Implementation of hook_validate */ -function og_validate(&$node) { +function og_validate_group(&$node) { // comments are not allowed on group nodes, since we don't have any nice way to present them $node->comment = 0; @@ -948,23 +931,19 @@ function og_validate(&$node) { } -function og_node_info() { - return array('og' => array('name' => t('group'), 'base' => 'og')); -} - -function og_load(&$node) { +function og_load_group(&$node) { $sql = 'SELECT selective AS og_selective, description AS og_description, theme AS og_theme, website AS og_website, register AS og_register, directory AS og_directory FROM {og} WHERE nid = %d'; $result = db_query($sql, $node->nid); $node = (object) array_merge((array)$node, db_fetch_array($result)); $node->comment=0; // we don't use comments on og nodes } -function og_insert($node) { +function og_insert_group($node) { $sql = "INSERT INTO {og} (nid, theme, selective, description, website, register, directory) VALUES (%d, '%s', %d, '%s', '%s', %d, %d)"; db_query($sql, $node->nid, $node->og_theme, $node->og_selective, $node->og_description, $node->og_website, $node->og_register, $node->og_directory); } -function og_update($node) { +function og_update_group($node) { $sql = "UPDATE {og} SET theme = '%s', selective = %d, register = %d, description = '%s', website = '%s', directory = %d WHERE nid = %d"; db_query($sql, $node->og_theme, $node->og_selective, $node->og_register, $node->og_description, $node->og_website, $node->og_directory, $node->nid); } @@ -990,11 +969,17 @@ function og_nodeapi(&$node, $op, $teaser array_unshift($bc, l(t('home'), '')); drupal_set_breadcrumb($bc); } + if (in_array($node->type, variable_get('og_node_types', array('og')))) { + og_view_group($node, FALSE, TRUE); + } break; case 'load': - if ($node->type != 'og') { + if (in_array($node->type, variable_get('og_node_types', array('og')))) { $node = og_node_load_public($node); } + else { + og_load_group($node); + } if ($grps = og_get_node_groups($node)) { // TODO: Refactor so we don't need 2 arrays. $node->og_groups = array_keys($grps); @@ -1002,13 +987,16 @@ function og_nodeapi(&$node, $op, $teaser } break; case 'validate': - if ($node->type != 'og') { + if (in_array($node->type, variable_get('og_node_types', array('og')))) { if (!in_array($node->type, variable_get('og_omitted', array()))) { if (variable_get('og_audience_required', 0) && empty($node->og_groups) && $_POST) { form_set_error('og_groups', t('You must select an audience in order to post.')); } } } + else { + og_validate_group($node); + } break; case 'submit': // if a post isn't in any groups. it must be public. this assumption is the heart of the problem with @@ -1027,10 +1015,16 @@ function og_nodeapi(&$node, $op, $teaser db_query($sql, $node->nid); break; case 'insert': + if (in_array($node->type, variable_get('og_node_types', array('og')))) { + og_insert_group($node); + } og_save_permissions($node); og_mail($node); break; case 'update': + if (in_array($node->type, variable_get('og_node_types', array('og')))) { + og_update_group($node); + } og_save_permissions($node); break; case 'search result': @@ -1048,8 +1042,11 @@ function og_form_alter($form_id, &$form) $node = $form['#node']; $edit = $_REQUEST['edit']; - if ($node->type == 'og' || in_array($node->type, variable_get('og_omitted', array()))) { + if (in_array($node->type, variable_get('og_node_types', array('og'))) || in_array($node->type, variable_get('og_omitted', array()))) { $form['og_nodeapi']['og_public'] = array('#type' => 'value', '#value' => 1); + if (in_array($node->type, variable_get('og_node_types', array('og')))) { + $form = array_merge($form, og_node_form($node)); + } } else { $required = variable_get('og_audience_required', 0); @@ -1203,7 +1200,7 @@ function og_user($op, &$edit, &$account, case 'register': $options = array(); $values = array(); - $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type = 'og' AND o.register = 1 ORDER BY n.title")); + $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND o.register = 1 ORDER BY n.title'), variable_get('og_node_types', array('og'))); while ($group = db_fetch_object($result)) { $options[$group->nid] = t('Subscribe to %name', array('%name' => theme('placeholder', $group->title))); $values[$group->nid] = in_array($group->nid, (array) $edit['og_register']) ? $group->nid : 0; @@ -1218,13 +1215,12 @@ function og_user($op, &$edit, &$account, } break; case 'insert': - $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type = 'og' AND n.status = 1 AND o.register = 1")); - while ($group = db_fetch_object($result)) { - if ($edit['og_register'][$group->nid]) { - og_subscribe_user($group->nid, $account); - } + $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND n.status = 1 AND o.register = 1'), variable_get('og_node_types', array('og'))); + while ($group = db_fetch_object($result)) { + if ($edit['og_register'][$group->nid]) { + og_subscribe_user($group->nid, $account); } - + } break; case 'load': $account->og_groups = og_get_subscriptions($account->uid); @@ -1274,7 +1270,7 @@ function og_save_permissions(&$node) { $sql = "DELETE FROM {node_access} WHERE realm LIKE '%s' AND nid = %d"; db_query($sql, 'og_%', $node->nid); - if ($node->type != 'og') { + if (in_array($node->type, variable_get('og_node_types', array('og')))) { // put the post into each selected group. we need a separate row for public and private nodes. // for public nodes, the grant_view column indicates which group the node belongs to. The gid=0 always. Needed to get // public nodes to display on the home page for non subscribers @@ -1356,7 +1352,7 @@ function _og_update_db($enable) { db_query('DELETE from {node_access} WHERE nid=0 AND gid=0 AND realm=\'all\' AND grant_view=1 AND grant_update=0 AND grant_delete=0'); // Assign universal grant to all non-group nodes which don't already have any grants from this module - $result = db_query("SELECT n.nid FROM {node} n LEFT JOIN {node_access} na ON n.nid = na.nid AND realm LIKE '%og%' WHERE n.type != 'og' AND ISNULL(na.gid)"); + $result = db_query("SELECT n.nid FROM {node} n LEFT JOIN {node_access} na ON n.nid = na.nid AND realm LIKE '%og%' WHERE n.type NOT IN (". str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND ISNULL(na.gid)', variable_get('og_node_types', array('og'))); while ($row = db_fetch_object($result)) { $sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view) VALUES (%d, 0, 'og_all', 1)"; db_query($sql, $row->nid); @@ -1451,12 +1447,12 @@ function og_block_my() { } function og_block_new() { - $sql = "SELECT COUNT(*) FROM {node} n INNER JOIN {og} og ON n.nid = og.nid WHERE og.directory=1 AND n.type = 'og' AND n.status = 1"; - $cnt = db_result(db_query(db_rewrite_sql($sql))); + $sql = 'SELECT COUNT(*) FROM {node} n INNER JOIN {og} og ON n.nid = og.nid WHERE og.directory=1 AND n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND n.status = 1'; + $cnt = db_result(db_query(db_rewrite_sql($sql), variable_get('og_node_types', array('og')))); if ($cnt > 0) { $max = variable_get('og_block_cnt_3', 10); - $sql = "SELECT n.nid, n.title FROM {node} n INNER JOIN {og} og ON n.nid = og.nid WHERE n.status = 1 AND n.type = 'og' AND og.directory=1 ORDER BY nid DESC"; - $result = db_query_range(db_rewrite_sql($sql), 0, $max); + $sql = 'SELECT n.nid, n.title FROM {node} n INNER JOIN {og} og ON n.nid = og.nid WHERE n.status = 1 AND n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND og.directory=1 ORDER BY nid DESC'; + $result = db_query_range(db_rewrite_sql($sql), variable_get('og_node_types', array('og')), 0, $max); $output = node_title_list($result); if ($cnt > $max) { $output .= '