function tweet_feed_process_hashtags in Tweet Feed 7.2
Process hashtags in tweets
We need to store these in our taxonomy (do not save duplicates) and save a reference to them in our created tweet node
Parameters
array hashtag_entities: An array of entities to be saved to our hashtag taxonomy
array hashtags: An array of taxonomy objects to be saved to the node for this tweet
1 call to tweet_feed_process_hashtags()
- tweet_feed_save_tweet in ./
tweet_feed.module - Save The Tweet (and profile)
File
- ./
tweet_feed.module, line 529
Code
function tweet_feed_process_hashtags($hashtag_entities) {
$hashtags = array();
foreach ($hashtag_entities as $entity) {
// Check to see if this entity is in our hashtag taxonomy
$vocabulary = taxonomy_vocabulary_machine_name_load('hashtag_terms');
// if the taxonomy doesn't exist for some reason, then we need to fataly error
if ($vocabulary == FALSE) {
tweet_feed_set_message('The Hashtag Terms taxonomy vocabulary could not be found. Please uninstall and re-install Tweet Feed', 'fatal', $web_interface);
return FALSE;
}
// Now that we have the vocabulary information, see if this term/hashtag already
// exists and if it does, give us the tid
$result = db_select('taxonomy_term_data', 'td')
->fields('td', array(
'tid',
))
->condition('td.vid', $vocabulary->vid)
->condition('td.name', $entity->text)
->execute();
// If we have one, great! If we don't, nwe need to create one and then get the tid
// that way.
if ($result
->rowCount() > 0) {
$tid = $result
->fetchField();
}
else {
$term = new stdClass();
$term->vid = $vocabulary->vid;
$term->name = $entity->text;
taxonomy_term_save($term);
$tid = $term->tid;
}
$hashtags[] = $tid;
}
return $hashtags;
}