| 1 |
<?php |
<?php |
| 2 |
// $Id: helptip.module,v 1.3.2.6 2006/11/04 18:48:14 yogadex Exp $ |
// $Id: helptip.module,v 1.3.2.7 2006/12/05 20:05:21 yogadex Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 40 |
*/ |
*/ |
| 41 |
function _helptip_get_block_settings($delta) { |
function _helptip_get_block_settings($delta) { |
| 42 |
$var_name = "helptip_block_".$delta."_settings"; |
$var_name = "helptip_block_".$delta."_settings"; |
| 43 |
$defaults = variable_get($var_name, |
$defaults = array('how_many' => 1, |
| 44 |
array('how_many' => 1, |
'title' => '%title', |
| 45 |
'title' => '%title') |
'min_weight' => -10, |
| 46 |
); |
'max_weight' => 10); |
| 47 |
return $defaults; |
|
| 48 |
|
$settings = variable_get($var_name, |
| 49 |
|
array()); |
| 50 |
|
// array_merge ensures default values will exist for all settings. |
| 51 |
|
return array_merge($defaults, $settings); |
| 52 |
} |
} |
| 53 |
|
|
| 54 |
/** |
/** |
| 58 |
if ($op == 'list') { |
if ($op == 'list') { |
| 59 |
$blocks[0]['info'] = t('Help tips'); |
$blocks[0]['info'] = t('Help tips'); |
| 60 |
for ($i = 1; $i < _helptip_num_blocks(); $i++) { |
for ($i = 1; $i < _helptip_num_blocks(); $i++) { |
| 61 |
$blocks[0]['info'] = t('Help tips %num', array('%num' => $i)); |
$blocks[$i]['info'] = t('Help tips %num', array('%num' => $i)); |
| 62 |
} |
} |
| 63 |
return $blocks; |
return $blocks; |
| 64 |
} |
} |
| 65 |
else if ($op == 'configure') { |
else if ($op == 'configure') { |
| 66 |
$var_name = "helptip_block_".$delta."_settings"; |
$defaults = _helptip_get_block_settings($delta); |
|
$defaults = _helptip_get_block_settings($var_name); |
|
|
$defaults = variable_get($var_name, |
|
|
array('how_many' => 1, |
|
|
'title' => '%title') |
|
|
); |
|
| 67 |
$form[$var_name] = array('#tree' => true); |
$form[$var_name] = array('#tree' => true); |
| 68 |
$form[$var_name]['title'] = |
$form[$var_name]['title'] = |
| 69 |
array('#type' => 'textfield', |
array('#type' => 'textfield', |
| 81 |
'#maxlength' => 2, |
'#maxlength' => 2, |
| 82 |
'#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.'), |
'#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.'), |
| 83 |
); |
); |
| 84 |
|
$form[$var_name]['min_weight'] = |
| 85 |
|
array('#type' => 'weight', |
| 86 |
|
'#title' => t('Minimum Weight'), |
| 87 |
|
'#default_value' => $defaults['min_weight'], |
| 88 |
|
'#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.'), |
| 89 |
|
); |
| 90 |
|
$form[$var_name]['max_weight'] = |
| 91 |
|
array('#type' => 'weight', |
| 92 |
|
'#title' => t('Maximum Weight'), |
| 93 |
|
'#default_value' => $defaults['max_weight'], |
| 94 |
|
'#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.'), |
| 95 |
|
); |
| 96 |
return $form; |
return $form; |
| 97 |
} |
} |
| 98 |
else if ($op == 'save') { |
else if ($op == 'save') { |
| 103 |
global $user; |
global $user; |
| 104 |
if (!user_access(HELPTIP_ACCESS_VIEW)) |
if (!user_access(HELPTIP_ACCESS_VIEW)) |
| 105 |
return; |
return; |
| 106 |
|
|
| 107 |
$settings = _helptip_get_block_settings($delta); |
$settings = _helptip_get_block_settings($delta); |
| 108 |
$paths = _helptip_get_current_paths(); |
$paths = _helptip_get_current_paths(); |
| 109 |
$path_clause = "('" . implode("' LIKE ht.path OR '", $paths) . "' LIKE ht.path)"; |
$path_clause = "('" . implode("' LIKE ht.path OR '", $paths) . "' LIKE ht.path)"; |
| 110 |
// use db_rewrite_sql for people with node_access modules |
// use db_rewrite_sql for people with node_access modules |
| 111 |
$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"), |
| 112 |
$settings['how_many']); |
$settings['how_many']); |
| 113 |
$block = array(); |
$block = array(); |
| 114 |
while ($data = db_fetch_object($result)) { |
while ($data = db_fetch_object($result)) { |
| 258 |
$form['helptip']['weight'] = array('#type' => 'weight', |
$form['helptip']['weight'] = array('#type' => 'weight', |
| 259 |
'#title' => t('Weight'), |
'#title' => t('Weight'), |
| 260 |
'#default_value' => $node->helptip->weight, |
'#default_value' => $node->helptip->weight, |
| 261 |
'#description' => t('When more than one help tip applies to a page, this controls the order in which they are displayed.'), |
'#description' => t('When more than one help tip applies to a page, this controls the order in which they are displayed. It may also determine in which block the helptip appears.'), |
| 262 |
'#required' => false); |
'#required' => false); |
| 263 |
|
|
| 264 |
$form['helptip']['settings'] = array('#tree' => true); |
$form['helptip']['settings'] = array('#tree' => true); |