--- sites/all/modules/headerimage/headerimage.module 2007-12-21 06:34:41.000000000 -0600 +++ sites/all/modules/headerimage/headerimageNew.module 2009-03-10 16:55:38.000000000 -0500 @@ -343,6 +343,9 @@ function headerimage_select_node($block) case 'php': $match = drupal_eval($condition); break; + case 'og': + $match = headerimage_eval_og($condition); + break; } } if ($match) break; @@ -473,6 +476,27 @@ function headerimage_eval_nodetype($cond } /** + * Evaluate og condition + * + * Return true if current node is a page of the group selected in the condition + * + * @param $condition + * array of organic group nids + * + * @return + * true: current node is a page in $condition's groups + * false: if not + * null: current page is not a node + */ +function headerimage_eval_og($condition) { + if (arg(0) == 'node' && is_numeric(arg(1))) { + // check if current node is one of the condition groups + $match = in_array(arg(1), $condition); + } + return $match; +} + +/** * Implementation of hook_form_alter */ function headerimage_form_alter($form_id, &$form) { @@ -614,6 +638,33 @@ function headerimage_form_alter($form_id '#rows' => 4, ); break; + case 'og': + if (module_exists('og')) { + $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {og} g INNER JOIN {node} n ON g.nid = n.nid WHERE n.status = 1 ORDER BY n.title ASC')); + while ($data = db_fetch_object($result)) { + $groups[$data->nid] = $data->title; + } + + if (isset($groups)) { + $description = t("One or more groups may be selected."); + } + else { + $description = t("No groups defined. Please create a group before using it as a condition."); + } + $form['headerimage'][$name] = array( + '#type' => 'select', + '#title' => $title, + '#description' => $description, + '#default_value' => $form['#node']->$name, + '#options' => $groups, + '#multiple' => true, + ); + + } + else { + drupal_set_message(t("The og module is not enabled. Please enable the module or remove it from the !settings.", + array('!settings' => l(t('Header Image settings'), 'admin/settings/headerimage/settings')))); + } } } } @@ -737,6 +788,7 @@ function headerimage_get_condition_types 'book' => t('Book'), 'nodetype' => t('Node type'), 'php' => t('PHP'), + 'og' => t('Organic Groups'), ); }