diff --git a/modules/content_profile_service.info b/modules/content_profile_service.info new file mode 100755 index 0000000..f1b6c3e --- /dev/null +++ b/modules/content_profile_service.info @@ -0,0 +1,8 @@ +; $Id: $ +name = Content Profile Service +description = Add Services integration for Content Profile +package = Services - services +dependencies[] = services +dependencies[] = content_profile +core = 6.x + diff --git a/modules/content_profile_service.module b/modules/content_profile_service.module new file mode 100755 index 0000000..bb475f3 --- /dev/null +++ b/modules/content_profile_service.module @@ -0,0 +1,104 @@ + 'content_profile.get', + '#callback' => 'content_profile_service_get', + '#access callback' => 'content_profile_service_get_access', + '#args' => array( + array( + '#name' => 'type', + '#type' => 'string', + '#description' => t('A valid content profile node type.'), + ), + array( + '#name' => 'uid', + '#type' => 'int', + '#description' => t('A user ID.'), + ), + array( + '#name' => 'lang', + '#type' => 'string', + '#description' => t('Try specific language'), + '#optional' => TRUE, + ), + array( + '#name' => 'fields', + '#type' => 'array', + '#optional' => TRUE, + '#description' => t('A list of fields to return.'), + ), + ), + '#return' => 'struct', + '#help' => t('Returns a profile node for a given user.'), + + ) + ); +} + +/** + * Check if the user has the permission to get the imagecache data. + * + * @param $presetname + * String. The preset name. + * @return + * Boolean. TRUE if the user has view access. + */ +function content_profile_service_get_access() { + return user_access("get content profiles of users"); +} + +/** + * Returns a content profile node for a given type/user. + * + * @param $type + * String. The content profile node type. + * @param $uid + * Number. The users ID + * @param $lang + * String (optinonal). The language the node shall be in + * @param $fields + * Array (optinonal). The node fields needed. If its empty, + * all fields will be returned + * @return + * Object. The node object. + */ +function content_profile_service_get($type, $uid, $lang = '', $fields = array()) { + global $user; + $node = content_profile_load($type, $uid, $lang); + + if ($node) { + // Apply field level content permissions + if (module_exists('content') && variable_get('services_use_content_permissions', FALSE)) { + $content_fields = content_fields(NULL, $node->type); + foreach ($content_fields as $field_name => $field_info) { + if (isset($node->$field_name)) { + $access = module_invoke_all('field_access', 'view', $field_info, $user, $node); + if (in_array(FALSE, $access)) { + unset($node->$field_name); + } + } + } + } + $result = services_node_load($node, $fields); + } + else { + $result = services_error(t('Could not find the node.'), 404); + } + + return $result; +}