Index: helptip.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/helptip/helptip.module,v retrieving revision 1.3.2.7 diff -u -u -F^f -r1.3.2.7 helptip.module --- helptip.module 5 Dec 2006 20:05:21 -0000 1.3.2.7 +++ helptip.module 7 Dec 2006 00:19:57 -0000 @@ -40,11 +40,15 @@ function _helptip_num_blocks() { */ function _helptip_get_block_settings($delta) { $var_name = "helptip_block_".$delta."_settings"; - $defaults = variable_get($var_name, - array('how_many' => 1, - 'title' => '%title') - ); - return $defaults; + $defaults = array('how_many' => 1, + 'title' => '%title', + 'min_weight' => -10, + 'max_weight' => 10); + + $settings = variable_get($var_name, + array()); + // array_merge ensures default values will exist for all settings. + return array_merge($defaults, $settings); } /** @@ -54,17 +58,13 @@ function helptip_block($op = 'list', $de if ($op == 'list') { $blocks[0]['info'] = t('Help tips'); for ($i = 1; $i < _helptip_num_blocks(); $i++) { - $blocks[0]['info'] = t('Help tips %num', array('%num' => $i)); + $blocks[$i]['info'] = t('Help tips %num', array('%num' => $i)); } return $blocks; } else if ($op == 'configure') { $var_name = "helptip_block_".$delta."_settings"; $defaults = _helptip_get_block_settings($var_name); - $defaults = variable_get($var_name, - array('how_many' => 1, - 'title' => '%title') - ); $form[$var_name] = array('#tree' => true); $form[$var_name]['title'] = array('#type' => 'textfield', @@ -82,6 +82,18 @@ function helptip_block($op = 'list', $de '#maxlength' => 2, '#description' => t('How many tips to display? If more than one tip applies to the current page, more than one can be displayed. Order of tips is random.'), ); + $form[$var_name]['min_weight'] = + array('#type' => 'weight', + '#title' => t('Minimum Weight'), + '#default_value' => $defaults['min_weight'], + '#description' => t('Show only helptips with this weight or greater. This allows you to define multiple helptip blocks, and position helptips on the page by their weight.'), + ); + $form[$var_name]['max_weight'] = + array('#type' => 'weight', + '#title' => t('Maximum Weight'), + '#default_value' => $defaults['max_weight'], + '#description' => t('Show only helptips with this weight or less. This allows you to define multiple helptip blocks, and position helptips on the page by their weight.'), + ); return $form; } else if ($op == 'save') { @@ -97,7 +109,7 @@ function helptip_block($op = 'list', $de $paths = _helptip_get_current_paths(); $path_clause = "('" . implode("' LIKE ht.path OR '", $paths) . "' LIKE ht.path)"; // use db_rewrite_sql for people with node_access modules - $result = db_query(db_rewrite_sql("SELECT ht.* FROM {node} n LEFT JOIN {helptip} ht ON ht.nid = n.nid LEFT JOIN {helptip_user_data} ht_hidden ON ht_hidden.uid=$user->uid AND ht_hidden.nid=n.nid AND ht_hidden.relation='hidden' WHERE n.status = 1 AND ht_hidden.relation IS NULL AND $path_clause ORDER BY ht.weight, RAND() LIMIT %d"), + $result = db_query(db_rewrite_sql("SELECT ht.* FROM {node} n LEFT JOIN {helptip} ht ON ht.nid = n.nid LEFT JOIN {helptip_user_data} ht_hidden ON ht_hidden.uid=$user->uid AND ht_hidden.nid=n.nid AND ht_hidden.relation='hidden' WHERE n.status = 1 AND ht_hidden.relation IS NULL AND $path_clause AND weight >= $settings[min_weight] AND weight <= $settings[max_weight] ORDER BY ht.weight, RAND() LIMIT %d"), $settings['how_many']); $block = array(); while ($data = db_fetch_object($result)) {