You are here

function hashtags_node_get_terms in Hashtags 7.2

Same name and namespace in other branches
  1. 6.2 hashtags.module \hashtags_node_get_terms()
  2. 6 hashtags.module \hashtags_node_get_terms()
1 call to hashtags_node_get_terms()
hashtags_node_load in ./hashtags.module
Implementation of hook_node_load().

File

./hashtags.module, line 199

Code

function hashtags_node_get_terms($nid) {
  $terms = array();
  $output_type = variable_get('hashtags_output_type', 2);
  if ($output_type == HASHTAGS_ALL_TAGS_AS_LINKS || $output_type == HASHTAGS_ONLY_HASHTAGS_AS_LINKS) {
    $vid = variable_get('hashtags_vocabulary', '');
    $only_hashtags_condition = '';
    if ($output_type == HASHTAGS_ONLY_HASHTAGS_AS_LINKS) {
      $only_hashtags_condition = " AND LEFT(ttd.name,1) = '#'";
    }
    $sql = "SELECT ttd.tid, ttd.name FROM `taxonomy_term_data` ttd\n    INNER JOIN `taxonomy_index` ti ON ttd.tid = ti.tid\n    WHERE ttd.vid = :vid AND ti.nid = :nid {$only_hashtags_condition}";
    $result = db_query($sql, array(
      ':vid' => $vid,
      ':nid' => $nid,
    ));
    foreach ($result as $term) {
      $terms[$term->name] = $term->tid;
    }
  }
  return $terms;
}