| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file community_tags.ajax.inc
|
| 6 |
*
|
| 7 |
* Handles the server side Ajax interactions of Community Tags.
|
| 8 |
*
|
| 9 |
* @defgroup community_tags_ajax Community Tags server side Ajax interactions.
|
| 10 |
* @{
|
| 11 |
*/
|
| 12 |
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Callback for the JS tagger.
|
| 16 |
*/
|
| 17 |
function community_tags_from_js($nid) {
|
| 18 |
global $user;
|
| 19 |
if (!is_numeric($nid) || !($node = node_load($nid))) {
|
| 20 |
return;
|
| 21 |
}
|
| 22 |
|
| 23 |
$tags = (isset($_POST['tags']) && is_array($_POST['tags'])) ? $_POST['tags'] : array();
|
| 24 |
|
| 25 |
// Merge in new tag and save
|
| 26 |
$tags = array_unique(array_merge($tags, taxonomy_explode_tags($_POST['add'])));
|
| 27 |
$vid = array_shift(community_tags_vids_for_node($node));
|
| 28 |
community_tags_taxonomy_node_save($node, array('tags' => array($vid => $tags)), FALSE, $user->uid);
|
| 29 |
|
| 30 |
// Fetch updated list
|
| 31 |
$tags = community_tags_flatten(community_tags_get_user_node_tags($user->uid, $node->nid));
|
| 32 |
|
| 33 |
// Output JSON
|
| 34 |
drupal_set_header('Content-Type: text/javascript; charset=utf-8');
|
| 35 |
print drupal_to_js(array('status' => TRUE, 'tags' => $tags, 'sequence' => $_POST['sequence']));
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* @}
|
| 40 |
*/
|