diff -ru ./.og-5.x-4.1/og.module ./og/og.module --- ./.og-5.x-4.1/og.module 2007-12-01 17:48:05.000000000 -0800 +++ ./og/og.module 2008-01-21 05:17:23.000000000 -0800 @@ -587,7 +587,7 @@ } function og_invite_form($gid) { - $max = variable_get('og_email_max', 10); + $max = og_variable_get('email_max', 10, '', $gid); $form['mails'] = array('#type' => 'textarea', '#title' => t('Email addresses or usernames'), '#description' => t('Enter up to %max email addresses or usernames. Separate multiple addresses by commas or new lines. Each person will receive an invitation message from you.', array('%max' => $max))); $form['pmessage'] = array('#type' => 'textarea', '#title' => t('Personal message'), '#description' => t('Optional. Enter a message which will become part of the invitation email.')); @@ -600,7 +600,7 @@ function og_invite_form_validate($form_id, $form_values, $form) { global $user; - $max = variable_get('og_email_max', 10); + $max = og_variable_get('email_max', 10, '', $form_values['gid']); $mails = $form_values['mails']; $mails = str_replace("\n", ',', $mails); @@ -1047,7 +1047,7 @@ unset($node->content['body']); $node->content['og_mission'] = array('#value' => theme('og_mission', $node), '#weight' => -3); - $view = views_get_view(variable_get('og_home_page_view', 'og_ghp_ron')); + $view = views_get_view(og_variable_get('home_page_view', 'og_ghp_ron', $node->type, $node->nid)); $views_available = variable_get('views_defaults', array()); if ($views_available[$view->name] == "disabled") { // do nothing. assume the group node type handles homepage, or theme layer - i.e. node-.tpl.php @@ -1123,7 +1123,7 @@ // registration checkbox // get the visibility for normal users - $visibility = variable_get('og_visibility_registration', OG_REGISTRATION_CHOOSE_FALSE); + $visibility = og_variable_get('visibility_registration', OG_REGISTRATION_CHOOSE_FALSE, $node->type, $node->nid); // admin can always choose - get right default if (user_access('administer nodes')) { @@ -1148,7 +1148,7 @@ // directory checkbox - $visibility = variable_get('og_visibility_directory', OG_DIRECTORY_CHOOSE_FALSE); + $visibility = og_variable_get('og_visibility_directory', OG_DIRECTORY_CHOOSE_FALSE, $node->type, $node->nid); // override for admins - get right default if (user_access('administer nodes')) { @@ -1247,7 +1247,7 @@ // returns TRUE if node type should generate email notifications when posted to a group. function og_node_type_notify($type) { - $omitted = variable_get('og_omitted_email_node_types', array()); + $omitted = og_variable_get('og_omitted_email_node_types', array(), $type); return in_array($type, $omitted) ? FALSE : TRUE; } @@ -1295,7 +1295,7 @@ } else { // Ensure that a group is selected if groups are required. needed when author has no groups. In other cases, fapi does the validation - if (!in_array($node->type, variable_get('og_omitted', array())) && variable_get('og_audience_required', FALSE) && !user_access('administer nodes')) { + if (!in_array($node->type, og_variable_get('og_omitted', array(), $node->type, $node->nid)) && og_variable_get('og_audience_required', FALSE, $node->type, $node->nid) && !user_access('administer nodes')) { if (!isset($node->og_groups)) { form_set_error('title', t('You must !join before posting on this web site.', array('!join' => l(t('join a group'), 'og')))); } @@ -1419,7 +1419,7 @@ $form['author']['name']['#title'] = t('Group manager'); $form['options']['sticky']['#title'] = t('Sticky at top of group home page and other lists'); } - elseif (!in_array($node->type, variable_get('og_omitted', array()))) { + elseif (!in_array($node->type, og_variable_get('og_omitted', array(), $node->type, $node->nid))) { if (!$node->nid) { if ($group_node = og_get_group_context()) { $bc[] = array('path' => 'og', 'title' => t('Groups')); @@ -1540,7 +1540,7 @@ } $node = $form['#node']; - $required = variable_get('og_audience_required', 0) && !user_access('administer nodes'); + $required = og_variable_get('og_audience_required', 0, $node->type, $node->nid) && !user_access('administer nodes'); // determine the list of groups that are shown. node admins see all of them if (user_access('administer nodes')) { $options = og_all_groups_options(); @@ -1555,7 +1555,7 @@ if (variable_get('og_enabled', FALSE)) { // get the visibility for normal users - $vis = variable_get('og_visibility', 0); + $vis = og_variable_get('og_visibility', 0, $node->type, $node->nid); // override visibility for og admins and when author only has 1 group if (user_access('administer organic groups') && $vis < 2) { @@ -1585,7 +1585,7 @@ } // show read only item if we are non-admin, and in simple mode (i.e. non-checkboxes) and at least one group is in querystring - $simple = !user_access('administer organic groups') && !variable_get('og_audience_checkboxes', TRUE) && count($gids); + $simple = !user_access('administer organic groups') && !og_variable_get('og_audience_checkboxes', TRUE, $node->type, $node->nid) && count($gids); // determine value of audience multi-select if (count($options) == 1 && $required) { @@ -1653,8 +1653,8 @@ } // used by og_book to determine the public state of an autocreated node -function og_get_visibility_default() { - $vis = variable_get('og_visibility', 0); +function og_get_visibility_default($type = '') { + $vis = og_variable_get('visibility', 0, $type); switch ($vis) { case OG_VISIBLE_GROUPONLY: case OG_VISIBLE_CHOOSE_PRIVATE: @@ -1990,7 +1990,7 @@ $form['og_settings']['og_email'] = array('#type' => 'radios', '#title' => t('Email notifications'), '#options' => $options, - '#default_value' => isset($account->og_email) ? $account->og_email : variable_get('og_notification', 2), + '#default_value' => isset($account->og_email) ? $account->og_email : og_variable_get('og_notification', 2), '#description' => t('When posts are submitted into your subscribed groups, you may be notified via email.'), ); return $form; @@ -2007,7 +2007,7 @@ } $sql = 'INSERT INTO {og_uid_global} (uid, og_email) VALUES (%d, %d)'; - db_query($sql, $account->uid, variable_get('og_notification', OG_NOTIFICATION_ALWAYS)); + db_query($sql, $account->uid, og_variable_get('og_notification', OG_NOTIFICATION_ALWAYS)); $account->og_email = NULL; break; case 'update': @@ -2110,7 +2110,7 @@ } function og_is_omitted_type($type) { - return in_array($type, variable_get('og_omitted', array())); + return in_array($type, og_variable_get('og_omitted', array(), $type)); } @@ -2224,7 +2224,7 @@ $sql = "SELECT COUNT(*) FROM {node} n INNER JOIN {og} og ON n.nid = og.nid WHERE og.directory=1 AND n.type IN ($in) AND n.status = 1"; $cnt = db_result(db_query(db_rewrite_sql($sql), $types)); if ($cnt > 0) { - $max = variable_get('og_block_cnt_3', 10); + $max = og_variable_get('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 IN ($in) AND og.directory=1 ORDER BY nid DESC"; $result = db_query_range(db_rewrite_sql($sql), $types, 0, $max); $output = node_title_list($result); @@ -2240,7 +2240,7 @@ function og_block_users_network() { global $user; if ($user->uid && count($user->og_groups)) { - $max = variable_get('og_block_cnt_2', 10); + $max = og_variable_get('block_cnt_2', 10); $placeholders = array_fill(0, count($user->og_groups), "'%s'"); $sql = "SELECT ogu.uid, u.name, u.picture FROM {og_uid} ogu INNER JOIN {users} u ON ogu.uid = u.uid WHERE ogu.uid != %d AND ogu.nid IN (". implode(", ", $placeholders) .") GROUP BY ogu.uid, u.name, u.picture ORDER BY ogu.created DESC"; $args = array_keys($user->og_groups); @@ -2258,7 +2258,7 @@ $gid = $group_node->nid; // only members can see subscriber list if (in_array($gid, array_keys($user->og_groups))) { - $max = variable_get('og_block_cnt_2', 10); + $max = og_variable_get('block_cnt_2', 10); $sql = "SELECT DISTINCT(u.uid), u.* FROM {og_uid} ogu INNER JOIN {users} u ON ogu.uid = u.uid WHERE ogu.nid = %d AND ogu.is_active = 1 AND u.status = 1 ORDER BY ogu.created DESC"; $result = db_query_range($sql, $gid, 0, $max); $block['content'] = og_user_title_list($result, $gid); @@ -2282,7 +2282,7 @@ } if ($links) { - $max = variable_get('og_block_cnt_2', 10); + $max = og_variable_get('block_cnt_2', 10); if (count($links) > $max-1) { array_pop($links); $txt = t('more'); @@ -2391,7 +2391,7 @@ // $group is an object containing the group node function og_og_create_links($group) { - $exempt = array_merge(variable_get('og_node_types', array('og')), variable_get('og_omitted', array())); + $exempt = array_merge(variable_get('og_node_types', array('og')), og_variable_get('og_omitted', array())); foreach (node_get_types() as $type) { // we used to check for node_access(create) but then node admins would get a false positive and see node types that they could not create if (!in_array($type->type, $exempt) && module_invoke(node_get_types('module', $type), 'access', 'create', $type)) { @@ -2457,7 +2457,7 @@ t('Group creator chooses whether her group appears in the directory. Defaults to %in.', array('%in' => t('in directory'))), t('Group creator chooses whether her group appears in the directory. Defaults to %out.', array('%out' => t('not in directory'))), ); - $form['og_settings']['group_details']['og_visibility_directory'] = array('#type' => 'radios', '#title' => t('Groups directory control'), '#default_value' => variable_get('og_visibility_directory', OG_DIRECTORY_CHOOSE_TRUE), '#description' =>t('OG admins always see the checkbox for adding a group to the %dir. Note that changing this setting has no effect on existing posts. Re-save those posts to acquire this new setting.', array('%dir' => t('groups directory'))), '#options' => $options); + $form['og_settings']['group_details']['og_visibility_directory'] = array('#type' => 'radios', '#title' => t('Groups directory control'), '#default_value' => og_variable_get('visibility_directory', OG_DIRECTORY_CHOOSE_TRUE), '#description' =>t('OG admins always see the checkbox for adding a group to the %dir. Note that changing this setting has no effect on existing posts. Re-save those posts to acquire this new setting.', array('%dir' => t('groups directory'))), '#options' => $options); // groups registration visibility $options = array(t('New groups don\'t appear on the registration form. Administrators control the form exclusively.'), @@ -2465,22 +2465,22 @@ t('Group creator chooses whether her group appears on the registration form. Defaults to %in.', array('%in' => t('on form'))), t('Group creator chooses whether her group appears on the registration form. Defaults to %out.', array('%out' => t('not on form'))), ); - $form['og_settings']['group_details']['og_visibility_registration'] = array('#type' => 'radios', '#title' => t('Registration form control'), '#default_value' => variable_get('og_visibility_registration', OG_REGISTRATION_CHOOSE_FALSE), '#description' =>t('OG admins always see the checkbox for adding a group to the %dir. Note that changing this setting has no effect on existing posts. Re-save those posts to acquire this new setting.', array('%dir' => t('registration form'))), '#options' => $options); + $form['og_settings']['group_details']['og_visibility_registration'] = array('#type' => 'radios', '#title' => t('Registration form control'), '#default_value' => og_variable_get('visibility_registration', OG_REGISTRATION_CHOOSE_FALSE), '#description' =>t('OG admins always see the checkbox for adding a group to the %dir. Note that changing this setting has no effect on existing posts. Re-save those posts to acquire this new setting.', array('%dir' => t('registration form'))), '#options' => $options); // email notifications default $options = array(OG_NOTIFICATION_SELECTIVE => t('New registrants are not subscribed to group email notifications by default. A user may choose to enable this from her profile page or her my subscriptions page.'), OG_NOTIFICATION_ALWAYS => t('New registrants are subscribed to group email notifications by default. A user may choose to disable this from her profile page.'), ); - $form['og_settings']['group_details']['og_notification'] = array('#type' => 'radios', '#title' => t('Group email notifications'), '#default_value' => variable_get('og_notification', OG_NOTIFICATION_ALWAYS), '#description' =>t('Should new registrants automatically be notified via email when new content is posted to their subscribed group? Note that changing this setting has no effect on existing subscriptions.'), '#options' => $options); + $form['og_settings']['group_details']['og_notification'] = array('#type' => 'radios', '#title' => t('Group email notifications'), '#default_value' => og_variable_get('notification', OG_NOTIFICATION_ALWAYS), '#description' =>t('Should new registrants automatically be notified via email when new content is posted to their subscribed group? Note that changing this setting has no effect on existing subscriptions.'), '#options' => $options); $form['og_settings']['node_form'] = array('#type' => 'fieldset', '#title' => t('Node authoring form'), '#collapsible' => TRUE, '#collapsed' => TRUE); - $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.')); - $form['og_settings']['node_form']['og_audience_checkboxes'] = array('#type' => 'checkbox', '#title' => t('Audience checkboxes'), '#default_value' => variable_get('og_audience_checkboxes', TRUE), '#description' => t('Show each subscribed group as a checkbox in the Audience section. This enables user to place her post into multiple groups. If unchecked, simplify the user interface by omitting the checkboxes and assuming user wants to post into the current group. Group administrators always see checkboxes.')); + $form['og_settings']['node_form']['og_help'] = array('#type' => 'textarea', '#default_value' => og_variable_get('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.')); + $form['og_settings']['node_form']['og_audience_checkboxes'] = array('#type' => 'checkbox', '#title' => t('Audience checkboxes'), '#default_value' => og_variable_get('audience_checkboxes', TRUE), '#description' => t('Show each subscribed group as a checkbox in the Audience section. This enables user to place her post into multiple groups. If unchecked, simplify the user interface by omitting the checkboxes and assuming user wants to post into the current group. Group administrators always see checkboxes.')); $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' => t('Public'))), t('Visibility chosen by author/editor using a checkbox on the posting form. '). t('Checkbox defaults to @pri.', array('@pri' => t('Private')))); - $form['og_settings']['node_form']['og_visibility'] = array('#type' => 'radios', '#title' => t('Visibility of posts'), '#default_value' => variable_get('og_visibility', 0), '#description' =>t('Determine how broadly available a given post should be when it is affiliated with a group. OG admins always see the checkbox for making a post @pub. Note that changing this setting has no effect on existing posts. Re-save those posts to acquire this new setting.', array('@pub' => t('Public'))), '#options' => $options); + $form['og_settings']['node_form']['og_visibility'] = array('#type' => 'radios', '#title' => t('Visibility of posts'), '#default_value' => og_variable_get('visibility', 0), '#description' =>t('Determine how broadly available a given post should be when it is affiliated with a group. OG admins always see the checkbox for making a post @pub. Note that changing this setting has no effect on existing posts. Re-save those posts to acquire this new setting.', array('@pub' => t('Public'))), '#options' => $options); $options = array(t('optional'), t('required')); - $form['og_settings']['node_form']['og_audience_required'] = array('#type' => 'radios', '#title' => t('Audience required'), '#default_value' => variable_get('og_audience_required', 0), '#options' => $options, '#description' => t('Do you require that all (non administrator) posts be affiliated with a group? Note that changing this setting will affect existing posts when they are edited.')); + $form['og_settings']['node_form']['og_audience_required'] = array('#type' => 'radios', '#title' => t('Audience required'), '#default_value' => og_variable_get('audience_required', 0), '#options' => $options, '#description' => t('Do you require that all (non administrator) posts be affiliated with a group? Note that changing this setting will affect existing posts when they are edited.')); unset($options); $types = node_get_types(); foreach ($types as $type) { @@ -2492,15 +2492,15 @@ unset($options[$val]); } $non_group_type_options = $options; // save this for og_node_types - $form['og_settings']['node_form']['og_omitted'] = array('#type' => 'select', '#title' => t('Omitted content types'), '#default_value' => variable_get('og_omitted', array()), '#options' => $non_group_type_options, '#description' => t('Select any node types which should not participate in the Audience targetting system. Node types which are designated as group home page node types (see below) will be automatically excluded.'), '#multiple' => TRUE); + $form['og_settings']['node_form']['og_omitted'] = array('#type' => 'select', '#title' => t('Omitted content types'), '#default_value' => og_variable_get('omitted', array()), '#options' => $non_group_type_options, '#description' => t('Select any node types which should not participate in the Audience targetting system. Node types which are designated as group home page node types (see below) will be automatically excluded.'), '#multiple' => TRUE); $form['og_settings']['home'] = array('#type' => 'fieldset', '#title' => t('Group home page'), '#collapsible' => TRUE, '#collapsed' => TRUE); $options = og_get_available_views(); - $form['og_settings']['home']['og_home_page_view'] = array('#type' => 'radios', '#title' => t('Presentation style'), '#options' => $options, '#default_value' => variable_get('og_home_page_view', 'og_ghp_ron'), '#description' => t('Pick a View for your group home page. Only Views whose names start with og_ghp_ are eligible. The View determines the layout of your home page. You may alter the presentation using usual the !theme. Also see the Theme section of the OG README file.', array('!theme' => l(t('usual Views themeing techniques'), 'http://drupal.org/node/42597')))); + $form['og_settings']['home']['og_home_page_view'] = array('#type' => 'radios', '#title' => t('Presentation style'), '#options' => $options, '#default_value' => og_variable_get('home_page_view', 'og_ghp_ron'), '#description' => t('Pick a View for your group home page. Only Views whose names start with og_ghp_ are eligible. The View determines the layout of your home page. You may alter the presentation using usual the !theme. Also see the Theme section of the OG README file.', array('!theme' => l(t('usual Views themeing techniques'), 'http://drupal.org/node/42597')))); $form['og_settings']['home']['og_node_types'] = array('#type' => 'select', '#title' => t('Group home page node types'), '#default_value' => variable_get('og_node_types', array('og')), '#options' => $all_node_type_options, '#required' => TRUE, '#description' => t("Required. Select the node types which act as group home pages. Usually, you will want to !create called group for this purpose.", array('!create' => l(t('create a simple node type'), 'admin/content/types'))), '#multiple' => TRUE); $form['og_settings']['email'] = array('#type' => 'fieldset', '#title' => t('Email settings'), '#collapsible' => TRUE, '#collapsed' => TRUE); - $form['og_settings']['email']['og_omitted_email_node_types'] = array('#type' => 'select', '#title' => t('Omitted node types for email notifications'), '#default_value' => variable_get('og_omitted_email_node_types', array()), '#options' => $non_group_type_options, '#description' => t("Select any node types which should not generate email notifications when they are posted into a group."), '#multiple' => TRUE); + $form['og_settings']['email']['og_omitted_email_node_types'] = array('#type' => 'select', '#title' => t('Omitted node types for email notifications'), '#default_value' => og_variable_get('omitted_email_node_types', array()), '#options' => $non_group_type_options, '#description' => t("Select any node types which should not generate email notifications when they are posted into a group."), '#multiple' => TRUE); $form['og_settings']['email']['og_email_notification_pattern'] = array( '#type' => 'textfield', @@ -2523,12 +2523,12 @@ $form['og_settings']['email']['og_new_admin_body'] = array('#type' => 'textarea', '#title' => t('New admin user email body'), '#rows' => 10, '#description' => 'The body of the email sent to a new admin for a group. Available variables: @group, @username, !group_url, !invite_url', '#default_value' => _og_user_mail_text('og_new_admin_body')); $form['og_settings']['pictures'] = array('#type' => 'fieldset', '#title' => t('Member pictures'), '#collapsible' => TRUE, '#collapsed' => TRUE); - $form['og_settings']['pictures']['og_member_pics'] = array('#type' => 'checkbox', '#title' => t('Member pictures'), '#default_value' => variable_get('og_member_pics', TRUE), '#description' => t('Should member pictures be shown in the group subscribers and group details blocks? You must also enable pictures in !user.', array('!user' => l(t('User configuration'), 'admin/user/settings')))); + $form['og_settings']['pictures']['og_member_pics'] = array('#type' => 'checkbox', '#title' => t('Member pictures'), '#default_value' => og_variable_get('member_pics', TRUE), '#description' => t('Should member pictures be shown in the group subscribers and group details blocks? You must also enable pictures in !user.', array('!user' => l(t('User configuration'), 'admin/user/settings')))); return system_settings_form($form); } function og_is_picture() { - return variable_get('user_pictures', 0) && variable_get('og_member_pics', TRUE); + return variable_get('user_pictures', 0) && og_variable_get('member_pics', TRUE); } // TODO: move this to new API function in Views where I can influence the WHERE clause. @@ -2772,3 +2772,72 @@ } return FALSE; } + + +/** + * Replaces most calls to variable_get; this should always be called with as much information as possible + * even though $type and $gid are optional the behavior will be the same as variable_get() unless they are + * specified + * + * $variable string The variable to retrieve with the 'og_' prefix removed + * $default mixed The value to return if there is not one set for the corresponding $variable + * $type string The group type (should be a member of og_node_types) + * $gid int The groupid of the current group if available. + * + ************************************ + * admin_email_body + * approve_user_body + * approve_user_subject + * audience_checkboxes + * audience_required + * deny_user_body + * deny_user_subject + * email_notification_pattern + * help + * home_page_view + * invite_user_body + * invite_user_subject + * member_pics + * new_admin_body + * new_admin_subject + * new_node_body + * new_node_subject + * notification + * omitted + * omitted_email_node_types + * request_user_body + * request_user_subject + * visibility + * visibility_directory + * visibility_registration + ************************************ + */ +function og_variable_get($variable, $default, $type = '', $gid = 0) { + $prefix = 'og_'; + + $return = ''; + + // see if we have node/group (instance) specific settings + if ($gid != 0) { + $prefix_gid = $prefix.$gid.'_'; + $return = variable_get($prefix_gid.$variable, ''); // default to empty string so we can detect and defer to group type + + if ($type == '' && $return == '') { // if we didn't get node specific recover the group type from the gid if necessary + $node = node_load($gid); + $type = $node->type; + } + } + + // see if we have group type specific settings + if ($type != '' && $return == '') { + $prefix_type = $prefix.$type.'_'; + $return = variable_get($prefix_type.$variable, ''); // default to empty string so we can detect and defer to global + } + + // fallback to global and then default if necessary + if ($return == '') { + $return = variable_get($prefix.$variable, $default); + } + + return $return; +}