Index: og.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/og.module,v retrieving revision 1.147 diff -u -p -r1.147 og.module --- og.module 28 Mar 2006 03:36:21 -0000 1.147 +++ og.module 28 Mar 2006 18:55:11 -0000 @@ -37,7 +37,10 @@ function og_menu($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' => 'og/image', 'callback' => 'og_image', 'title' => t('group image (large)'), 'weight' => 4, 'access' => user_access('access content'), 'type' => MENU_CALLBACK); - $items[] = array('path' => 'node/add/og', 'title' => t('group'), 'access' => user_access('create groups')); + if (variable_get('og_node_type', 'og') == 'og') { + $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')); @@ -65,7 +68,7 @@ function og_menu($may_cache) { if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(arg(1)); - if ($node->type == 'og') { + if ($node->type == variable_get('og_node_type', '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); } } @@ -137,7 +140,7 @@ function og_set_group_context($group_nod function og_set_theme($nid) { global $custom_theme; $node = node_load(intval($nid)); - if ($node->type == 'og') { + if ($node->type == variable_get('og_node_type', 'og')) { $custom_theme = $node->og_theme; return $node; } @@ -665,7 +668,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)); @@ -691,7 +694,7 @@ function og_get_home_nodes_sql($str_type $where = " n.type IN ('$str_types')"; } else { - $where = "n.type NOT IN ('og')"; + $where = "n.type NOT IN ('" . variable_get('og_node_type', 'og') . "')"; } // we LEFT JOIN to node_comment_stats in case comment.module is disabled. @@ -913,7 +916,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 ($node->type != variable_get('og_node_type', '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)) { @@ -956,7 +959,9 @@ function og_validate(&$node) { } function og_node_info() { - return array('og' => array('name' => t('group'), 'base' => 'og')); + if (variable_get('og_node_type', 'og') == 'og') { + return array('og' => array('name' => t('group'), 'base' => 'og')); + } } function og_load(&$node) { @@ -1013,11 +1018,17 @@ function og_nodeapi(&$node, $op, $teaser array_unshift($bc, l(t('home'), '')); drupal_set_breadcrumb($bc); } + else if (variable_get('og_node_type', 'og') != 'og') { + og_view($node, FALSE, TRUE); + } break; case 'load': - if ($node->type != 'og') { + if ($node->type != variable_get('og_node_type', 'og')) { $node = og_node_load_public($node); } + else if (variable_get('og_node_type', 'og') != 'og') { + og_load($node); + } if ($grps = og_get_node_groups($node)) { // TODO: Refactor so we don't need 2 arrays. $node->og_groups = array_keys($grps); @@ -1025,13 +1036,17 @@ function og_nodeapi(&$node, $op, $teaser } break; case 'validate': - if ($node->type != 'og') { + if ($node->type != variable_get('og_node_type', 'og')) { + print_r(variable_get('og_omitted', array())); 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 if (variable_get('og_node_type', 'og') != 'og') { + og_validate($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 @@ -1050,10 +1065,16 @@ function og_nodeapi(&$node, $op, $teaser db_query($sql, $node->nid); break; case 'insert': + if (variable_get('og_node_type', 'og') != 'og' && $node->type == variable_get('og_node_type', 'og')) { + og_insert($node); + } og_save_permissions($node); og_mail($node); break; case 'update': + if (variable_get('og_node_type', 'og') != 'og' && $node->type == variable_get('og_node_type', 'og')) { + og_update($node); + } og_save_permissions($node); break; case 'search result': @@ -1071,8 +1092,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 ($node->type == variable_get('og_node_type', 'og') || in_array($node->type, variable_get('og_omitted', array()))) { $form['og_nodeapi']['og_public'] = array('#type' => 'value', '#value' => 1); + if ($node->type == variable_get('og_node_type', 'og') && $node->type != 'og') { + $form = array_merge($form, og_form($node)); + } } else { $required = variable_get('og_audience_required', 0); @@ -1226,7 +1250,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 = '%s' AND o.register = 1 ORDER BY n.title"), variable_get('og_node_type', '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; @@ -1241,12 +1265,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 = '%s' AND n.status = 1 AND o.register = 1"), variable_get('og_node_type', 'og')); + while ($group = db_fetch_object($result)) { + if ($edit['og_register'][$group->nid]) { + og_subscribe_user($group->nid, $account); } + } break; case 'load': @@ -1297,7 +1321,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 ($node->type != variable_get('og_node_type', '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 @@ -1379,7 +1403,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 != '%s' AND ISNULL(na.gid)", variable_get('og_node_type', '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); @@ -1475,12 +1499,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 = '%s' AND n.status = 1"; + $cnt = db_result(db_query(db_rewrite_sql($sql), variable_get('og_node_type', '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 = '%s' AND og.directory=1 ORDER BY nid DESC"; + $result = db_query_range(db_rewrite_sql($sql), variable_get('og_node_type', 'og'), 0, $max); $output = node_title_list($result); if ($cnt > $max) { $output .= ''; @@ -1618,7 +1642,7 @@ function og_settings_submit($form_id, $f } function og_settings() { - $form['#submit']['og_settings_submit'] = array(); // custom submit handler + $op = $_POST['op']; drupal_set_title(t('Organic groups configuration')); if (variable_get('og_enabled', 0)) { $status = t('enabled'); @@ -1631,9 +1655,20 @@ function og_settings() { $description = t('You usually want to enable access control with this module. The button below will delete one record in your node_access table and thus enable node permissions on your site. You may revert by clicking the same button again.'); } $form['og_settings']['og_module_status'] = array('#type' => 'fieldset', '#title' => t('Module status'), '#description' => $description); - $form['og_settings']['og_module_status']['module_action'] = array('#type' => 'submit', '#value' => $btn_text, '#prefix' => t('Organic groups access control is currently') . ' ' . theme('placeholder', $status). '.
'); - + $form['og_settings']['og_module_status']['module_status'] = array('#type' => 'button', '#value' => $btn_text, '#prefix' => t('Organic groups access control is currently') . ' ' . theme('placeholder', $status). '.
'); + // TODO: I attempted to move this into custom submit handler but then the regular system save halder was not getting called with proper args + if ($op == t('Enable')) { + _og_update_db(TRUE); + variable_set('og_enabled', 1); + drupal_goto('admin/settings/og'); + } + elseif ($op == t('Disable')) { + _og_update_db(FALSE); + variable_set('og_enabled', 0); + drupal_goto('admin/settings/og'); + } + $form['og_settings']['node_form'] = array('#type' => 'fieldset', '#title' => t('Node authoring form')); $form['og_settings']['node_form']['og_help'] = array('#type' => 'textarea', '#default_value' => variable_get('og_help', ''), '#cols' => 70, '#rows' =>5, '#title' => t('Explanation or submission guidelines'), '#description' => t('This text will be displayed at the top of the group submission form. It is useful for helping or instructing your users.')); $options = array(t('Visible only within the targeted groups'), t('Visible within the targeted groups and on other pages'), t('Visibility chosen by author/editor using a checkbox on the posting form. '). t('Checkbox defaults to %pub.', array('%pub' => theme('placeholder', t('Public')))), t('Visibility chosen by author/editor using a checkbox on the posting form. '). t('Checkbox defaults to %pri.', array('%pri' => theme('placeholder', t('Private'))))); @@ -1644,8 +1679,12 @@ function og_settings() { foreach (node_get_types() as $type => $name) { $options[$type] = t($name); } + + $form['og_settings']['node_form']['og_node_type'] = array('#type' => 'radios', '#title' => t('Organic Group content type'), '#default_value' => variable_get('og_node_type', 'og'), '#options' => $options, '#description' => t("Select the node type which should be used for Organic Groups. If you don't chose the default 'group', make sure to select it in 'Ommitted content type' below, too.")); + unset($options['og']); $form['og_settings']['node_form']['og_omitted'] = array('#type' => 'select', '#title' => t('Omitted content types'), '#default_value' => variable_get('og_omitted', array()), '#options' => $options, '#description' => t('Select any node types which should not participate in the Audience targetting system.'), '#multiple' => true); + $form['og_settings']['home'] = array('#type' => 'fieldset', '#title' => t('Group home page')); $options = array('ron' => t('River of News'), 'gbct' => t('Group by content type'));