123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- function tripal_ws_init() {
- global $base_url;
- $version = 'v0.1';
- $api_url = $base_url . '/ws/' . $version;
-
-
-
- $attributes = array(
- 'rel' => 'http://www.w3.org/ns/hydra/core#apiDocumentation',
- 'href' => $api_url . '/ws-doc/',
- );
- drupal_add_html_head_link($attributes, $header = FALSE);
- }
- function tripal_ws_menu() {
-
- $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,
- );
-
- $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;
- }
- function tripal_ws_services() {
- $ws_path = func_get_args();
- $params = $_GET;
- unset($params['q']);
-
- drupal_page_is_cacheable(FALSE);
-
-
- $version = array_shift($ws_path);
- if ($version and preg_match('/v\d+\.\d+/', $version)) {
- $api_url = 'ws/' . $version;
-
- 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 {
-
- }
- drupal_add_http_header('Content-Type', 'application/ld+json');
- print drupal_json_encode($response);
- }
- function tripal_ws_entity_load($entities, $type) {
- foreach ($entities as $entity) {
-
-
-
- }
- }
- function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) {
-
- $url = "https://dev.bioinfo.wsu.edu/~ccheng/tripal3/ws/v0.1/content/gene/12";
- $json = file_get_contents($url);
- $response = json_decode($json, TRUE);
-
-
- drupal_set_title($response['label']);
-
- $source_url = l($response['label'], $response['itemPage'], array('attributes' => array('target' => '_blank')));
- $content = '<div><strong>Source:</strong> Chun-huai\'s amazing test site: ' . $source_url . '</div>';
-
-
- $entity = new TripalEntity(array(), 'TripalEntity');
- $entity->id = 807;
- $entity->type = 'TripalEntity';
- $entity->bundle = 'bio_data_266';
- $entity->term_id = 266;
- $entity->title = $response['label'];
- $entity->uid = 1;
- $entity->status = 1;
-
- $fields = field_info_fields();
- $my_fields = array();
- foreach ($fields as $field) {
- if (isset($field['bundles']['TripalEntity'])) {
- foreach ($field['bundles']['TripalEntity'] as $bundle_name) {
- if ($bundle_name == 'bio_data_266') {
- $my_fields[] = $field;
- }
- }
- }
- }
-
-
-
- foreach ($my_fields as $field) {
-
- $field_name = $field['field_name'];
- $settings = $field['settings'];
-
- if (!isset($settings['semantic_web'])) {
- continue;
- }
-
-
- list($vocabulary, $accession) = explode(':', $settings['semantic_web']);
- $term = tripal_get_term_details($vocabulary, $accession);
-
-
- $term_name = strtolower(preg_replace('/ /', '_', $term['name']));
-
-
-
- if (isset($response[$term_name])) {
-
-
-
- if (isset($response['@context'][$term_name]['@type']) and
- $response['@context'][$term_name]['@type'] == '@id') {
- continue;
- }
-
-
- $f = array();
- $f['und'][0]['value'] = $response[$term_name];
- $entity->$field_name = $f;
- }
- }
-
- $entities = array();
- $entities[] = $entity;
- $view = entity_view('TripalEntity', $entities);
- $content .= drupal_render($view['TripalEntity'][807]);
- return $content;
- }
|