You are here

function fivestar_node_type in Fivestar 6.2

Same name and namespace in other branches
  1. 5 fivestar.module \fivestar_node_type()
  2. 6 fivestar.module \fivestar_node_type()

Implementation of hook_node_types().

File

./fivestar.module, line 193
A simple n-star voting widget, usable in other forms.

Code

function fivestar_node_type($op, $info) {
  $type = $info->type;
  $variables = array(
    'fivestar',
    'fivestar_unvote',
    'fivestar_style',
    'fivestar_stars',
    'fivestar_comment',
    'fivestar_position',
    'fivestar_position_teaser',
    'fivestar_labels_enable',
    'fivestar_labels',
    'fivestar_text',
    'fivestar_title',
    'fivestar_feedback',
  );

  // Be responsible and cleanup unneeded variables.
  if ($op == 'delete') {
    foreach ($variables as $variable) {
      foreach (fivestar_get_tags() as $tag) {
        $suffix = fivestar_get_suffix($type, $tag);
        variable_del($variable . '_' . $suffix);
      }
    }
  }
  elseif ($op == 'update' && !empty($info->old_type) && $info->old_type != $info->type) {
    foreach ($variables as $variable) {
      foreach (fivestar_get_tags() as $tag) {
        $oldvarname = $variable . '_' . fivestar_get_suffix($info->old_type, $tag);
        $newvarname = $variable . '_' . fivestar_get_suffix($info->type, $tag);
        $value = variable_get($oldvarname, -1);
        if ($value != -1) {
          variable_del($oldvarname);
          variable_set($newvarname, $value);
        }
      }
    }
  }
}