'http://www.w3.org/ns/hydra/core#apiDocumentation', 'href' => $api_url . '/ws-doc/', ); drupal_add_html_head_link($attributes, $header = FALSE); } /** * Implements hook_menu(). * Defines all menu items needed by Tripal Core * * @ingroup tripal_ws */ function tripal_ws_menu() { // Web Services API callbacks. $items['ws'] = array( 'title' => 'Tripal Web Services API', 'page callback' => 'tripal_ws_services', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); $items['remote/%/%/%/%'] = array( 'page callback' => 'tripal_ws_load_remote_entity', 'page arguments' => array(1, 2, 3, 4), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Tripal Web Services setting groups $items['admin/tripal/storage/ws'] = array( 'title' => 'Remote Tripal Sites', 'description' => t("Create mashups of content using data from this site and remote Tripal sites."), 'weight' => 20, 'page callback' => 'system_admin_menu_block_page', 'access arguments' => array('administer tripal'), 'file' => 'system.admin.inc', 'file path' => drupal_get_path('module', 'system'), ); $items['admin/tripal/storage/ws/tripal_sites'] = array( 'title' => 'Configuration', 'description' => t('Provides information about other Tripal sites. This allows data exchange and communication betwen Tripal enabled sites through the web services.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_ws_tripal_sites_form'), 'access arguments' => array('administer tripal'), 'type' => MENU_NORMAL_ITEM, 'weight' => 0, 'file' => 'includes/tripal_ws.admin.inc', 'file path' => drupal_get_path('module', 'tripal_ws'), ); $items['admin/tripal/storage/ws/tripal_sites/edit'] = array( 'title' => 'Add Tripal Site', 'description' => 'Add a Tripal site', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_ws_tripal_sites_edit_form'), 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_ws.admin.inc', 'file path' => drupal_get_path('module', 'tripal_ws'), 'type' => MENU_LOCAL_ACTION, 'weight' => 2 ); $items['admin/tripal/storage/ws/tripal_sites/remove/%'] = array( 'title' => 'Remove Tripal Site', 'description' => 'Remove a Tripal site', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_ws_tripal_sites_remove_form', 6), 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_ws.admin.inc', 'file path' => drupal_get_path('module', 'tripal_ws'), 'type' => MENU_CALLBACK, 'weight' => 2 ); return $items; } /** * The callback function for all RESTful web services. * */ function tripal_ws_services() { $ws_path = func_get_args(); $params = $_GET; unset($params['q']); // The web services should never be cached. drupal_page_is_cacheable(FALSE); // Using the provided version number, determine which web services // verion to call. $version = array_shift($ws_path); if ($version and preg_match('/v\d+\.\d+/', $version)) { $api_url = 'ws/' . $version; // Add the file with the appropriate web services. module_load_include('inc', 'tripal_ws', 'includes/tripal_ws.rest_' . $version); $version = preg_replace('/\./', '_', $version); $function = 'tripal_ws_services_' . $version; $response = array(); if (function_exists($function)) { $response = $function($api_url, $ws_path, $params); } } else { // TODO: What do we do if no version is provided? } drupal_add_http_header('Content-Type', 'application/json'); print drupal_json_encode($response); } /** * * @param $entities * @param $type */ function tripal_ws_entity_load($entities, $type) { foreach ($entities as $entity) { } } /** * * @param $site_id * @param $api_version * @param $ctype * @param $id * * @return */ function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) { // Get the content type on this site $bundle = tripal_load_bundle_entity(array('label' => $ctype)); $term = entity_load('TripalTerm', array('id' => $bundle->term_id)); $term = reset($term); $vocab = $term->vocab; $query = db_select('tripal_sites', 'ts'); $query->fields('ts'); $query->condition('id', $site_id); $site = $query->execute()->fetchObject(); if (!$site) { return 'Could not find specified site.'; } // Get the content from the web services of the remote site. $url = $site->url . "/ws/v0.1/content/" . $ctype . "/" . $id; $json = file_get_contents($url); $response = json_decode($json, TRUE); // Set the title for this page to match the title provided. drupal_set_title($response['label']); // Attribute this data to the proper source. $source_url = l($response['label'], $response['itemPage'], array('attributes' => array('target' => '_blank'))); $content = '