| 1 |
<?php |
<?php |
| 2 |
// $Id: weight.module,v 1.23.2.2 2009/01/26 16:48:27 nancyw Exp $ |
// $Id: weight.module,v 1.23.2.3 2009/01/26 17:09:18 nancyw Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* This module uses the sticky column of the node table |
* This module uses the sticky column of the node table |
| 111 |
// the weight dropdown to the user. Also, to position my help text |
// the weight dropdown to the user. Also, to position my help text |
| 112 |
// appropriately, I'm using this '#suffix' hack rather than adding |
// appropriately, I'm using this '#suffix' hack rather than adding |
| 113 |
// a form property as i'd like to do. |
// a form property as i'd like to do. |
| 114 |
$form['options']['#suffix'] .= t('<strong>Weight:</strong> To change the weight of a node, select a value from the corresponding dropdown box under <i>@operations</i>. Node weights are submitted immediately. Selectors are only available for node types configured on the <a href="@weight_admin">weight admin page</a>.', |
$form['admin']['options']['#suffix'] .= t('<strong>Weight:</strong> To change the weight of a node, select a value from the corresponding dropdown box under <i>Operations</i>. Node weights are submitted immediately. Selectors are only available for node types configured on the <a href="@weight_admin">weight admin page</a>.', |
| 115 |
array( |
array('@weight_admin' => url('admin/settings/weight')) |
|
'@weight_admin' => url('admin/settings/weight'), |
|
|
'@operations' => t('Operations'), |
|
|
) |
|
| 116 |
); |
); |
| 117 |
|
|
| 118 |
// Add weight selector under the operations section of the admin node |
// Add weight selector under the operations section of the admin node |
| 121 |
foreach ($form['admin']['operations'] as $nid => $title) { |
foreach ($form['admin']['operations'] as $nid => $title) { |
| 122 |
// only add weight selector if weight is enabled for this node type |
// only add weight selector if weight is enabled for this node type |
| 123 |
if (in_array($form['admin']['name'][$nid]['#value'], $weight_node_type_names) ) { |
if (in_array($form['admin']['name'][$nid]['#value'], $weight_node_type_names) ) { |
| 124 |
$form['admin']['operations'][$nid]['weight_selector']['#value'] = weight_node_selector($nid); |
$selector = weight_node_selector($nid); |
| 125 |
|
$form['admin']['operations'][$nid]['weight_selector']['#value'] = $selector['selector']; |
| 126 |
|
$form['admin']['status'][$nid]['#value'] .= $selector['status']; |
| 127 |
} |
} |
| 128 |
} |
} |
| 129 |
} |
} |
| 178 |
'#type' => 'select', |
'#type' => 'select', |
| 179 |
'#title' => t('Node Weight Range'), |
'#title' => t('Node Weight Range'), |
| 180 |
'#default_value' => variable_get('weight_range', 20), |
'#default_value' => variable_get('weight_range', 20), |
| 181 |
'#options' => array(5 => 5, 10 => 10, 20 => 20, 30 => 30, 40 => 40), |
'#options' => array(5 => 5, 10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 60 => 60, 70=> 70, 80 => 80, 90 => 90, 99 => 99), |
| 182 |
'#description' => '<p>'. t('This will be the +/- range for node weight.') .'</p>', |
'#description' => '<p>'. t('This will be the +/- range for node weight.') .'</p>', |
| 183 |
); |
); |
| 184 |
|
|
| 306 |
$weight_selector = preg_replace("/(value='$weight')/", "$1 selected='selected'", $weight_selector); |
$weight_selector = preg_replace("/(value='$weight')/", "$1 selected='selected'", $weight_selector); |
| 307 |
$weight_selector = preg_replace("/\[NID\]/", $nid, $weight_selector); |
$weight_selector = preg_replace("/\[NID\]/", $nid, $weight_selector); |
| 308 |
$weight_selector = '<div class="weight_selector">'. $weight_selector .'</div>'; |
$weight_selector = '<div class="weight_selector">'. $weight_selector .'</div>'; |
| 309 |
return $weight_selector; |
$status = NULL; |
| 310 |
|
$status .= $node->sticky ? '<br />'. t('sticky') : NULL; |
| 311 |
|
$status .= $node->promote ? '<br />'. t('promoted') : NULL; |
| 312 |
|
$status .= $node->translate ? '<br />'. t('translate') : NULL; |
| 313 |
|
$status .= $node->moderate ? '<br />'. t('moderated') : NULL; |
| 314 |
|
return array('selector' => $weight_selector, 'status' => $status); |
| 315 |
} |
} |
| 316 |
|
|
| 317 |
/** |
/** |
| 321 |
// Doing it this way preserves the revision information. |
// Doing it this way preserves the revision information. |
| 322 |
$node = node_load($nid); |
$node = node_load($nid); |
| 323 |
$node->node_weight = $weight; |
$node->node_weight = $weight; |
|
_weight_encode($node); |
|
| 324 |
node_save($node); |
node_save($node); |
| 325 |
} |
} |
| 326 |
|
|
| 345 |
* Convert our weight back out of sticky. |
* Convert our weight back out of sticky. |
| 346 |
*/ |
*/ |
| 347 |
function _weight_decode(&$node) { |
function _weight_decode(&$node) { |
| 348 |
// $x = $node->sticky; |
if ($node->sticky == 0 || $node->sticky == 1) { |
| 349 |
|
$node->node_weight = 0; |
| 350 |
|
return; |
| 351 |
|
} |
| 352 |
|
|
| 353 |
if ($node->sticky > 0) { |
if ($node->sticky > 0) { |
| 354 |
$node->node_weight = $node->sticky == 1 ? 0 : (100 - $node->sticky); |
$node->node_weight = 100 - $node->sticky; |
| 355 |
$node->sticky = 1; |
$node->sticky = 1; |
| 356 |
} |
} |
| 357 |
else { |
else { |
| 358 |
$node->node_weight = $node->sticky == 0 ? 0 : -($node->sticky + 100); |
$node->node_weight = -($node->sticky + 100); |
| 359 |
$node->sticky = 0; |
$node->sticky = 0; |
| 360 |
} |
} |
|
// drupal_set_message("For node $node->nid, $x becomes sticky: $node->sticky and weight: $node->node_weight."); |
|
| 361 |
} |
} |
| 362 |
|
|
| 363 |
/** |
/** |