You are here

function similarterms_node_save in Similar By Terms 6

Same name and namespace in other branches
  1. 7 similarterms.module \similarterms_node_save()

Function to populate overrides table

1 call to similarterms_node_save()
similarterms_nodeapi in ./similarterms.module
Implementation of hook_nodeapi().

File

./similarterms.module, line 468
Similar By Terms module displays a block with similar content based on taxonomy terms.

Code

function similarterms_node_save($node) {
  if (!variable_get('similarterms_override_options', 0)) {
    return;
  }
  $result = array();
  $query = "INSERT INTO {similarterms_override} (nid, path, vid) VALUES(%d, %d, %d)";
  foreach (similarterms_taxonomy_get_vocabularies() as $v) {
    $vid = 'similarterms_vid_' . $v->vid;
    $alias =& $node->{$vid};
    similarterms_node_delete($node, $v->vid);
    if ($alias['similarterms_override_delete']) {
      continue;
    }
    foreach ($alias['similarterms_paths'] as $id => $path) {
      $pieces = explode('/', $path);
      if (sizeof($pieces) == 2 && $pieces[0] == "node" && is_numeric($pieces[1])) {
        $nid = $pieces[1];
      }
      else {
        $path = drupal_lookup_path('source', $path);
        $pieces = explode('/', $path);
        $nid = $pieces[1];
      }
      if ($nid) {
        $args = array(
          $node->nid,
          $nid,
          $v->vid,
        );
        $result[$id] = db_query($query, $args);
      }
    }
  }
}