function community_tags_node_view in Community Tags 6
Same name and namespace in other branches
- 5 community_tags.module \community_tags_node_view()
- 6.2 community_tags.module \community_tags_node_view()
- 7 community_tags.module \community_tags_node_view()
Community tags callback for node view.
chaps2 - implemented multiple vocabularies base on patch at #199936. @todo refactor to allow use of block cache
2 calls to community_tags_node_view()
- community_tags_block in ./
community_tags.module - Implementation of hook_block().
- community_tags_nodeapi in ./
community_tags.module - Implementation of hook_nodeapi(). Community tags hooks should be called after taxonomy module hooks - see system weight in community_tags.install.
1 string reference to 'community_tags_node_view'
- community_tags_menu in ./
community_tags.module - Implementation of hook_menu().
File
- ./
community_tags.module, line 485 - Implements community tagging of nodes using a specific vocabulary for Drupal v6.x
Code
function community_tags_node_view($node, $inline = TRUE) {
global $user;
if (is_numeric($node)) {
$node = node_load($node);
}
// Guard against duff nids and nodes. Added in response to http://drupal.org/node/331819.
if (!$node || !is_object($node)) {
return;
}
if (!$inline) {
drupal_set_title(check_plain($node->title));
}
module_load_include('inc', 'community_tags', 'community_tags.pages');
$output = '';
$vids = community_tags_vids_for_node($node);
foreach ($vids as $vid) {
$tags = community_tags_get_user_node_tags($user->uid, $node->nid, $vid);
$display_handler = _community_tags_get_display_handler($vid, $node->type, $inline);
$cloud = call_user_func($display_handler['fn'], 'node', NULL, $node->nid, $vid);
$names = array();
if (!count($tags)) {
// User has not yet added tags to this node yet. Show form.
$output .= drupal_get_form('community_tags_form', array(
'node' => $node,
'cloud' => $cloud,
'nid' => $node->nid,
'vid' => $vid,
'tags' => NULL,
'inline' => $inline,
'multiple' => count($vids),
));
}
elseif (user_access('edit own tags')) {
// User has already tagged this node, but can edit their tags. Show form
// with the user's tags pre-populated.
$names = community_tags_flatten($tags);
$tags = taxonomy_implode_tags($tags);
$output .= drupal_get_form('community_tags_form', array(
'node' => $node,
'cloud' => $cloud,
'nid' => $node->nid,
'vid' => $vid,
'tags' => $tags,
'inline' => $inline,
'multiple' => count($vids),
));
}
else {
// Sorry, no more adding tags for you!
$output .= '<p>' . t('You have already tagged this post. Your tags: ') . theme('community_tags', $tags) . '</p>';
}
// TODO might want to optimise this call
drupal_add_js(array(
'communityTags' => array(
'n_' . $node->nid => array(
'v_' . $vid => array(
'tags' => $names,
'url' => url('community-tags/js/' . $node->nid . '/' . $vid),
'add' => t('Add'),
'token' => drupal_get_token('community_tags_form'),
),
),
),
), 'setting');
}
return $output;
}