Index: og.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/Attic/og.module,v retrieving revision 1.298.2.199 diff -u -p -r1.298.2.199 og.module --- og.module 2 Oct 2008 03:16:07 -0000 1.298.2.199 +++ og.module 18 Jun 2009 19:49:42 -0000 @@ -607,7 +607,7 @@ function og_invite_page($gid) { } function og_invite_form($gid) { - $max = variable_get('og_email_max', 10); + $max = og_variable_get('email_max', 10); $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.')); @@ -620,7 +620,7 @@ function og_invite_form($gid) { 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); $mails = $form_values['mails']; $mails = str_replace("\n", ',', $mails); @@ -1108,7 +1108,7 @@ function og_view_group(&$node, $teaser = '#theme' => 'og_mission', ); - $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')); $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 @@ -1188,7 +1188,7 @@ function og_group_form($node) { // 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); // admin can always choose - get right default if (user_access('administer nodes')) { @@ -1213,7 +1213,7 @@ function og_group_form($node) { // directory checkbox - $visibility = variable_get('og_visibility_directory', OG_DIRECTORY_CHOOSE_TRUE); + $visibility = og_variable_get('visibility_directory', OG_DIRECTORY_CHOOSE_TRUE); // override for admins - get right default if (user_access('administer nodes')) { @@ -1365,7 +1365,7 @@ function og_nodeapi(&$node, $op, $teaser } 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 (og_is_group_post_type($node->type) && variable_get('og_audience_required', FALSE) && !user_access('administer nodes')) { + if (og_is_group_post_type($node->type) && og_variable_get('audience_required', FALSE) && !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')))); } @@ -1530,10 +1530,10 @@ function og_form_alter($form_id, &$form) if ($form_id == 'node_type_form') { // Built in content types do not alow changes to type machine name. if (isset($form['identity']['type']['#default_value'])) { - $usage = variable_get('og_content_type_usage_'. $form['identity']['type']['#default_value'], 'omitted'); + $usage = og_variable_get('content_type_usage_'. $form['identity']['type']['#default_value'], 'omitted'); } else { - $usage = variable_get('og_content_type_usage_'. $form['identity']['type']['#value'], 'omitted'); + $usage = og_variable_get('content_type_usage_'. $form['identity']['type']['#value'], 'omitted'); } // Persist $usage so that we can rebuild node access as needed. $form['old_og_content_type_usage'] = array( @@ -1708,7 +1708,7 @@ function og_form_add_og_audience($form_i } $node = $form['#node']; - $required = variable_get('og_audience_required', 0) && !user_access('administer nodes'); + $required = og_variable_get('audience_required', 0) && !user_access('administer nodes'); // Determine the list of groups that are shown. @@ -1763,7 +1763,7 @@ function og_form_add_og_audience($form_i } // 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('audience_checkboxes', TRUE) && count($gids); // determine value of audience multi-select if (count($options) == 1 && $required) { @@ -1934,7 +1934,7 @@ function og_mail($type, $obj) { '@site_mail' => variable_get("site_mail", ini_get("sendmail_from")), '@site_name' => mime_header_encode(variable_get("site_name", 'Drupal')), ); - $from_mail = strtr(variable_get("og_email_notification_pattern", '@user_name <@site_mail>'), $variables); + $from_mail = strtr(og_variable_get("email_notification_pattern", '@user_name <@site_mail>'), $variables); $headers = array('X-Mailer' => 'Drupal - og_mail', 'Precedence' => 'list', 'Message-Id' => "<$obj->msgid>"); if ($obj->in_reply_to) { @@ -2201,7 +2201,7 @@ function og_user($op, $edit, &$account, $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('notification', 2), '#description' => t('When posts are submitted into your groups, you may be notified via email.'), ); return $form; @@ -2218,7 +2218,7 @@ function og_user($op, $edit, &$account, } $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('notification', OG_NOTIFICATION_ALWAYS)); $account->og_email = NULL; break; case 'update': @@ -2281,9 +2281,9 @@ function og_node_type($op, $info) { variable_del('og_content_type_usage_'. $info->type); break; case 'update': - $usage = variable_get('og_content_type_usage_'. $info->type, 'omitted'); - variable_set('og_content_type_usage_'. $info->type, $usage); - variable_del('og_content_type_usage_'. $info->old_type); + $usage = og_variable_get('content_type_usage_'. $info->type, 'omitted'); + og_variable_set('content_type_usage_'. $info->type, $usage); + og_variable_del('content_type_usage_'. $info->old_type); } } @@ -2313,7 +2313,7 @@ function og_get_types($usage) { } } else { - $type_usage = variable_get('og_content_type_usage_'. $type->type, 'omitted'); + $type_usage = og_variable_get('content_type_usage_'. $type->type, 'omitted'); $return[$type_usage][] = $type->type; } } @@ -2322,24 +2322,24 @@ function og_get_types($usage) { // returns TRUE if node type should generate email notifications when posted to a group. function og_is_mail_type($type) { - $usage = variable_get('og_content_type_usage_'. $type, 'omitted'); + $usage = og_variable_get('content_type_usage_'. $type, 'omitted'); return strpos($usage, 'mail') && !strpos($usage, 'nomail') ? TRUE : FALSE; } // returns TRUE if node type lets all subscribers edit the node. function og_is_wiki_type($type) { - $usage = variable_get('og_content_type_usage_'. $type, 'omitted'); + $usage = og_variable_get('content_type_usage_'. $type, 'omitted'); return strpos($usage, 'wiki') ? TRUE : FALSE; } // returns TRUE if node type can be posted into a group. function og_is_group_post_type($type) { - $usage = variable_get('og_content_type_usage_'. $type, 'omitted'); + $usage = og_variable_get('content_type_usage_'. $type, 'omitted'); return strpos($usage, 'group_post') !== FALSE ? TRUE : FALSE; } function og_is_omitted_type($type) { - return variable_get('og_content_type_usage_'. $type, 'omitted') == 'omitted' ? TRUE : FALSE; + return og_variable_get('content_type_usage_'. $type, 'omitted') == 'omitted' ? TRUE : FALSE; } /** @@ -2350,7 +2350,7 @@ function og_is_omitted_type($type) { * @return boolean */ function og_is_group_type($type) { - return variable_get('og_content_type_usage_'. $type, 'omitted') == 'group' ? TRUE : FALSE; + return og_variable_get('content_type_usage_'. $type, 'omitted') == 'group' ? TRUE : FALSE; } /** @@ -2413,19 +2413,19 @@ function og_block($op = 'list', $delta = $items['og_block_cnt'] = array( '#type' => 'textfield', '#title' => t('Maximum number of members to show'), - '#default_value' => variable_get("og_block_cnt_$delta", 10), + '#default_value' => og_variable_get("block_cnt_$delta", 10), '#size' => 5, ); $items['og_block_subscribers_is_admin'] = array( '#type' => 'checkboxes', '#title' => t('Group roles'), - '#default_value' => variable_get("og_block_subscribers_is_admin", array('members', 'admins')), + '#default_value' => og_variable_get("block_subscribers_is_admin", array('members', 'admins')), '#options' => array('members' => t('Standard members'), 'admins' => t('Administrators')), '#description' => t('You may specify which types of group members appear in the listing.'), ); return $items; case 3: - return array('og_block_cnt' => array('#type' => 'textfield', '#title' => t('Maximum number of groups to show'), '#default_value' => variable_get("og_block_cnt_$delta", 10), '#size' => 5, '#maxlength' => 255)); + return array('og_block_cnt' => array('#type' => 'textfield', '#title' => t('Maximum number of groups to show'), '#default_value' => og_variable_get("block_cnt_$delta", 10), '#size' => 5, '#maxlength' => 255)); } } elseif ($op == 'save') { @@ -2493,7 +2493,7 @@ 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 $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 AND og.directory=1 ORDER BY nid DESC"; $result = db_query_range(db_rewrite_sql($sql), $types, 0, $max); $output = node_title_list($result); @@ -2509,7 +2509,7 @@ function og_block_new() { 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 u.name ASC"; $args = array_keys($user->og_groups); @@ -2527,9 +2527,9 @@ function og_block_subscribers() { $gid = $group_node->nid; // only members can see membership 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); // Should we show admins, standard users, or both. From block configuration. - $is_admin = variable_get("og_block_subscribers_is_admin", drupal_map_assoc(array('members', 'admins'))); + $is_admin = og_variable_get("block_subscribers_is_admin", drupal_map_assoc(array('members', 'admins'))); $block['subject'] = t('Recently joined'); $block['content'] = og_block_subscribers_list($gid, $max, $is_admin); return $block; @@ -2578,7 +2578,7 @@ function og_user_title_list($result, $gi } 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'); @@ -2741,7 +2741,7 @@ function og_admin_settings() { $map = og_types_map(); foreach (node_get_types() as $type) { $type_url_str = str_replace('_', '-', $type->type); - $usage = variable_get('og_content_type_usage_'. $type->type, 'omitted'); + $usage = og_variable_get('content_type_usage_'. $type->type, 'omitted'); $rows[] = array( $type->name, @@ -2759,7 +2759,7 @@ function og_admin_settings() { 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."), @@ -2767,20 +2767,20 @@ function og_admin_settings() { 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 members are not subscribed to group email notifications by default. A member may choose to enable this from her profile page or her My membership page.'), OG_NOTIFICATION_ALWAYS => t('New members are subscribed to group email notifications by default. A member 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 members automatically be notified via email when new content is posted to their group? Note that changing this setting has no effect on existing members.'), '#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 members automatically be notified via email when new content is posted to their group? Note that changing this setting has no effect on existing members.'), '#options' => $options); // audience checkboxes - $form['og_settings']['group_details']['og_audience_checkboxes'] = array('#type' => 'checkbox', '#title' => t('Audience checkboxes'), '#default_value' => variable_get('og_audience_checkboxes', TRUE), '#description' => t('Show each group that the user is a member of as a checkbox in the Audience section. This enables the member 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. This simplification only applies to new nodes, and not to edits of existing nodes. Group administrators always see checkboxes.')); + $form['og_settings']['group_details']['og_audience_checkboxes'] = array('#type' => 'checkbox', '#title' => t('Audience checkboxes'), '#default_value' => og_variable_get('audience_checkboxes', TRUE), '#description' => t('Show each group that the user is a member of as a checkbox in the Audience section. This enables the member 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. This simplification only applies to new nodes, and not to edits of existing nodes. Group administrators always see checkboxes.')); // audience required $options = array(t('optional'), t('required')); - $form['og_settings']['group_details']['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']['group_details']['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); // audience home page - Views @@ -2788,14 +2788,14 @@ function og_admin_settings() { $form['og_settings']['group_details']['og_home_page_view'] = array('#type' => 'radios', '#title' => t('Home page presentation'), '#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 group home page. You may alter the presentation using !theme. Also see the Theme section of the !README. Also note that group admins can override this presentation using the included Organic Groups Panels module.', array('!README' => og_readme(), '!theme' => l(t('typical Views themeing techniques'), 'http://drupal.org/node/42597')))); // member pictures - $form['og_settings']['group_details']['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 on the members page, the group members block, and group details block? You must also enable pictures in !user.', array('!user' => l(t('User configuration'), 'admin/user/settings')))); + $form['og_settings']['group_details']['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 on the members page, the group members block, and group details block? You must also enable pictures in !user.', array('!user' => l(t('User configuration'), 'admin/user/settings')))); $form['og_settings']['email'] = array('#type' => 'fieldset', '#title' => t('Email settings'), '#collapsible' => TRUE, '#collapsed' => TRUE); $form['og_settings']['email']['og_email_notification_pattern'] = array( '#type' => 'textfield', '#title' => t('Format of From: field'), - '#default_value' => variable_get("og_email_notification_pattern", '@user_name <@site_mail>'), + '#default_value' => og_variable_get("email_notification_pattern", '@user_name <@site_mail>'), '#description' => t('Specify the format of the "From:" field on outgoing notifications. Available variables: @user_mail, @user_name, @site_mail, @site_name. Note that the @user_mail token reveals the author\'s email address. If the admin email examples above appear blank, you need to set your site email in the Site Configuration panel.'), ); $form['og_settings']['email']['og_new_node_subject'] = array('#type' => 'textfield', '#title' => t('New content subject'), '#description' => t('Subject of email for new content. Available variables: @group, !group_url, @type, @site, !content_url, !reply_url, @title, @subject, @node_full, @node_teaser, @username. %subject contains the comment title in the case of a comment but the node title in the case of a new post. @title is always the node title.'), '#default_value' => _og_user_mail_text('og_new_node_subject')); @@ -2816,7 +2816,7 @@ function og_admin_settings() { } 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. @@ -3026,3 +3026,61 @@ function og_url_group($token, $argument, } return FALSE; } + +/** + * Replaces most calls to variable_get; if there is no current group context this function behaves as variable_get() would + * + * variable naming convention is as follows (in order of specificity); + * - og_GID_VARNAME // group instance specific settings + * - og_GROUPTYPENAME_VARNAME // group type specific settings + * - og_VARNAME // global group settings + * + * $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 + * + */ +function og_variable_get($variable, $default, $type = NULL, $gid = NULL) { + $prefix = 'og_'; + $dummy = 'ASDLKNVEWI@!)@!#$N#$V(@$N@$V'; // non-sense value used to detect non-retrieval of values + $return = $dummy; + + // get instance specific if possible + if ($gid != NULL) { + $return = variable_get($prefix.$gid.'_'.$variable, $dummy); + } + + // get type specific if possible + if ($type != NULL) { + $return = variable_get($prefix.$type.'_'.$variable, $dummy); + } + + // fallback to og_get_group_context() + if (($type == NULL && $gid == NULL) || $return == $dummy) { + $group_node = og_get_group_context(); + $type = $group_node->type; + $gid = $group_node->nid; + + // og_get_group_context(); should probably dummy a type on return here + if ($group_node == NULL && arg(0) == 'node' && arg(1) == 'add') { + $type = arg(2); + } + + // try instance specific first + $return = variable_get($prefix.$gid.'_'.$variable, $dummy); + if ($return == $dummy) { + $return = variable_get($prefix.$type.'_'.$variable, $dummy); + } + + // get type specific if possible + if ($type != NULL) { + $return = variable_get($prefix.$type.'_'.$variable, $dummy); + } + } + + if ($return == $dummy) { + $return = variable_get($prefix.$variable, $default); + } + + return $return; +} +