You are here

function weight_nodeapi in Weight 6

Same name and namespace in other branches
  1. 5 weight.module \weight_nodeapi()

File

./weight.module, line 81
This module uses the sticky column of the node table to add weighting to nodes.

Code

function weight_nodeapi(&$node, $op) {
  $weight_node_types = variable_get('weight_node_types', array_flip(node_get_types('names')));
  if (in_array($node->type, $weight_node_types)) {
    switch ($op) {
      case 'presave':

        // Non-weighted nodes have a weight of zero.
        if (is_null($node->node_weight)) {
          $node->node_weight = variable_get('weight_default', 0);
        }

        // If the admin wants to use the menu weight, see if there is one.
        if (variable_get('weight_use_menu', FALSE)) {
          $node->node_weight = isset($node->menu['link_title']) && !empty($node->menu['link_title']) ? $node->menu['weight'] : $node->node_weight;
        }

        // Encode weight into the sticky value for the database.
        _weight_encode($node);
        break;
      case 'load':
        _weight_decode($node);
        break;
    }
  }
}