| 1 |
<?php
|
| 2 |
// $Id: weblinks.weight.inc,v 1.1.2.1 2009/05/24 20:04:48 nancyw Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Enable submission and display of categorized web links.
|
| 7 |
* This is an add-in that allows Web Links to act as though the Weight
|
| 8 |
* module is present. "Borrowed" from the Weight module.
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Convert our weight to 'encoded' sticky value for DB.
|
| 13 |
* Stickiness is the inverse of weight - stickiness is sorted DESC while
|
| 14 |
* weight is sorted ASC so we invert the weight before saving...
|
| 15 |
* If the sticky box is checked, subtract weight from 100;
|
| 16 |
* unweighted sticky nodes will have a value of 100.
|
| 17 |
*/
|
| 18 |
function weblinks_weight_encode(&$node) {
|
| 19 |
if ($node->sticky) {
|
| 20 |
$node->sticky = 100 - $node->node_weight;
|
| 21 |
}
|
| 22 |
// Unweighted non-sticky nodes will have a value of -100.
|
| 23 |
else {
|
| 24 |
$node->sticky = -($node->node_weight + 100);
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Convert our weight back out of sticky.
|
| 30 |
*/
|
| 31 |
function weblinks_weight_decode(&$node) {
|
| 32 |
if ($node->sticky == 0 || $node->sticky == 1) {
|
| 33 |
$node->node_weight = 0;
|
| 34 |
return;
|
| 35 |
}
|
| 36 |
|
| 37 |
if ($node->sticky > 0) {
|
| 38 |
$node->node_weight = 100 - $node->sticky;
|
| 39 |
$node->sticky = 1;
|
| 40 |
}
|
| 41 |
else {
|
| 42 |
$node->node_weight = -($node->sticky + 100);
|
| 43 |
$node->sticky = 0;
|
| 44 |
}
|
| 45 |
}
|