function blogapi_get_node_categories in Blog API 7.2
Service callback for metaWeblog.getCategories @TODO simplify this callback if possible
1 call to blogapi_get_node_categories()
- blogapi_movabletype_get_post_categories in modules/
blogapi_movabletype/ blogapi_movabletype.module - Service callback for mt.getPostCategories
File
- ./
blogapi.module, line 602 - Enable users to post using applications that support BlogAPIs.
Code
function blogapi_get_node_categories($postid, $username, $password) {
// Validate the user.
blogapi_validate_user($username, $password);
$node = node_load($postid);
if (!$node) {
return services_error(t('Node @nid not found', array(
'@nid' => $postid,
)), 404);
}
if (!node_access('view', $node, $user) || !user_access('administer nodes')) {
// User does not have permission to view the node.
return services_error(t('You are not authorized to view post @postid', array(
'@postid' => $postid,
)), 403);
}
$taxonomy_fields = blogapi_get_node_taxonomy_term_fields($node->nid);
$categories = array();
if (!empty($taxonomy_fields)) {
foreach ($taxonomy_fields as $field) {
$terms = field_get_items('node', $node, $field);
if (!empty($terms)) {
foreach ($terms as $term) {
$term = taxonomy_term_load($term['tid']);
$categories[] = array(
'categoryName' => $term->name,
'categoryId' => $term->tid,
'isPrimary' => TRUE,
);
}
}
}
}
return $categories;
}