4 /*! @defgroup ConStructModule conStruct Drupal Module */
7 /*! @file conStruct.module
8 @brief Main conStruct module file.
9 @details This file includes all the other PHP files needed to run this Drupal module.
11 @author Frederick Giasson, Structured Dynamics LLC.
17 // Include the utilities function used by the hooks and tools
18 include_once("framework/utilities.php");
20 // Loading needed global variables
23 ini_set("memory_limit","64M");
25 // Enable global WSF debug information
26 //$_GET['wsf_debug'] = 1;
32 ini_set("display_errors", "On");
33 $_GET['wsf_debug'] = 1;
34 error_reporting(E_ALL);
37 // cache_clear_all('variables', 'cache');
39 /*!@brief Main Drupal hook procedure
40 @details This hook is the first one called by Drupal when one of the module's page is accessed.
42 \li Get the URI that has been accessed by the user
43 \li Trigger the conStruct tool related to this URI by calling its main procedure.
47 @return A string containing the HTML page description generated by the conStruct tool
49 @author Frederick Giasson, Structured Dynamics LLC.
54 function conStruct_main()
58 cache_clear_all('variables', 'cache');
60 drupal_set_html_head("<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"/drupal/"
61 .
drupal_get_path('module', "conStruct") .
"/css/style.css\" />");
64 // Get the extension of the URI requested to Drupal.
67 if (stripos($uri, "conStruct/settings/cache") !== FALSE
)
69 return conStruct_cache();
72 return (t("Check conStruct tools in the right sidebar"));
76 /*! @brief Define menu items and page callbacks.
77 @details This hook enables modules to register paths, which determines whose requests are to be handled.
78 Depending on the type of registration requested by each path, a link is placed in the the navigation
79 block and/or an item appears in the menu administration page (q=admin/menu).
84 @return An array of menu items. Each menu item has a key corresponding to the Drupal path being registered.
85 The item is an associative array.
87 @author Frederick Giasson, Structured Dynamics LLC.
89 @see http://api.drupal.org/api/function/hook_block
93 function conStruct_menu()
97 // Registration of the conStruct module settings page path
98 $items['admin/settings/conStruct'] = array(
99 'title' => t('conStruct Settings'),
100 'description' => t('Basic settings for a conStruct instance'),
101 'page callback' => 'drupal_get_form',
102 'page arguments' => array('conStruct_admin'),
103 'access arguments' => array('access administration pages'),
104 'type' => MENU_NORMAL_ITEM
107 // Access settings menu
108 $items['admin/settings/conStruct/access'] = array(
109 'title' => t('Access Settings'),
110 'description' => t('Access settings for node functions'),
111 'page callback' => 'drupal_get_form',
112 'page arguments' => array('conStruct_access_settings'),
113 'access arguments' => array('access administration pages'),
114 'type' => MENU_NORMAL_ITEM
117 // Registration of the main conStruct module page path
118 $items['conStruct'] = array(
119 'page callback' => 'conStruct_main',
120 'access callback' => 'conStruct_access_callback',
121 'type' => MENU_CALLBACK
127 function conStruct_form_alter(&$form, $form_state, $form_id)
129 if ($form_id == "dataset_node_form")
131 $form['#after_build'] = array('_conStruct_form_afterbuild');
135 function _conStruct_form_afterbuild($form, &$form_state)
137 // Change the field_wsf field of the Dataset type to add all the possible, registered, structWSF network addresses.
138 if(isset($form["field_wsf"]))
140 $wsfAddresses = array();
141 $wsfRegistry = variable_get("WSF-Registry", array());
143 foreach($wsfRegistry as
$s => $wsfs)
146 preg_match("/^(http:\/\/)?([^\/]+)/i", $wsfs, $domain_only);
147 $host = $domain_only[2];
149 $wsfAddresses[$host] = $host;
152 $form['field_wsf']['value']['#options'] = $wsfAddresses;
158 /*! @brief Declare a block or set of blocks.
159 @details Any module can export a block (or blocks) to be displayed by defining the _block hook. This hook
160 is called by theme.inc to display a block, and also by block.module to procure the list of available blocks.
162 The functions mymodule_display_block_1 and 2, as used in the example, should of course be defined
163 somewhere in your module and return the content you want to display to your users. If the "content"
164 element is empty, no block will be displayed even if "subject" is present.
166 After completing your blocks, do not forget to enable them in the block admin menu.
170 @param[in] $op What kind of information to retrieve about the block or blocks. Possible values:
171 @li 'list': A list of all blocks defined by the module.
172 @li 'configure': Configuration form for the block.
173 @li 'save': Save the configuration options.
174 @li 'view': Process the block when enabled in a region in order to view its contents.
176 @param[in] $delta Which block to return (not applicable if $op is 'list'). Although it is most commonly an integer starting at 0, this is not mandatory. For instance, aggregator.module uses string values for $delta.
178 @param[in] $edit If $op is 'save', the submitted form data from the configuration form.
180 @return If $op is 'list': An array of block descriptions. Each block description is an associative array.
182 @author Frederick Giasson, Structured Dynamics LLC.
184 @see http://api.drupal.org/api/function/hook_block
188 function conStruct_block($op = 'list', $delta = 0, $edit = array())
192 // The $op parameter determines what piece of information is being requested.
197 // If $op is "list", we just need to return a list of block descriptions.
198 // This is used to provide a list of possible blocks to the administrator,
199 // end users will not see these descriptions.
200 $blocks[0]['info'] = t('conStruct Settings');
204 // If $op is "configure", we need to provide the administrator with a
205 // configuration form. The $delta parameter tells us which block is being
206 // configured. In this example, we'll allow the administrator to customize
207 // the text of the first block.
211 // All we need to provide is a text field, Drupal will take care of
212 // the other block configuration options and the save button.
213 $form['block_example_string'] = array(
214 '#type' => 'textfield',
215 '#title' => t('Block contents'),
217 '#description' => t('This string will appear in the conStruct Tools menu'),
218 '#default_value' => variable_get('conStruct_string', t(''))
226 // If $op is "save", we need to save settings from the configuration form.
227 // Since the first block is the only one that allows configuration, we
228 // need to check $delta to make sure we only save it.
231 // Have Drupal save the string to the database.
232 variable_set('conStruct_string', $edit['conStruct_string']);
240 // If $op is "view", then we need to generate the block for display
241 // purposes. The $delta parameter tells us which block is being requested.
245 // The subject is displayed at the top of the block. Note that it
246 // should be passed through t() for translation.
247 $block['subject'] = t('conStruct Tools');
248 // The content of the block is typically generated by calling a custom
250 $block['content'] = conStruct_contents(1);
257 /*! @brief Display the conStruct side-bar menu items
258 @details This function is called to generate the HTML of the tool lists being displayed in the side-bar.
262 @return A string where the HTML menus have been defined.
264 @author Frederick Giasson, Structured Dynamics LLC.
268 function conStruct_contents($which_block)
273 if ($which_block == 1)
275 // Modules would typically perform some database queries to fetch the
276 // content for their blocks. Here, we'll just use the variable set in the
277 // block configuration or, if none has set, a default value.
279 $localPath = $base_url .
"/" .
drupal_get_path("module", "conStruct") .
"/imgs/";
283 // For a specific user
284 if (user_access('administer conStruct'))
286 $menuItems .
= "<img src=\"" .
$localPath .
"kcontrol.png\" style=\"padding-right:5px;\" alt=\"\" /><a href=\"" .
$base_url
287 .
"/admin/settings/conStruct/\">" .
t("Settings") .
"</a><br />";
290 if (user_access('access conStruct') && $user->uid
)
292 /*! note: this procedure can have performence issue with big structWSF instances (big datasets). */
293 $menuItems .
= "<img src=\"" .
$localPath .
"kcontrol.png\" style=\"padding-right:5px;\" alt=\"\" /><a href=\"" .
$base_url
294 .
"/admin/settings/conStruct/access/\">Access Settings</a><br />";
297 if (user_access('access conStruct') && $user->uid
&& module_exists("structOntology"))
299 /*! note: this procedure can have performence issue with big structWSF instances (big datasets). */
300 $menuItems .
= "<img src=\"" .
$localPath .
"kcontrol.png\" style=\"padding-right:5px;\" alt=\"\" /><a href=\"" .
$base_url
301 .
"/admin/settings/conStruct/structOntology/\">Ontology Settings</a><br />";
304 if (user_access('access conStruct') && $user->uid
&& module_exists("structScones"))
306 /*! note: this procedure can have performence issue with big structWSF instances (big datasets). */
307 $menuItems .
= "<img src=\"" .
$localPath .
"kcontrol.png\" style=\"padding-right:5px;\" alt=\"\" /><a href=\"" .
$base_url
308 .
"/admin/settings/conStruct/scones/\">Scones Settings</a><br />";
311 return variable_get('conStruct_string', t($menuItems));
316 /*! @brief Define user permissions.
317 @details This hook can supply permissions that the module defines, so that they can be selected on the user
318 permissions page and used to restrict access to actions the module performs.
320 The permissions in the array do not need to be wrapped with the function t(), since the string extractor
321 takes care of extracting permission names defined in the perm hook for translation.
323 Permissions are checked using user_access().
327 @note Currently only two kind of users exist: (1) "access" and (2) "administer". However, we expect to have more
328 kind of users in the future for different node maintenance purposes
330 @note Once new permissions are created, the node administrator has to set their permissions in the setting panel
333 @return An array of permissions strings.
335 @author Frederick Giasson, Structured Dynamics LLC.
337 @see http://api.drupal.org/api/function/hook_perm
341 function conStruct_perm()
345 'administer conStruct'
350 /*! @brief Define access restrictions.
351 @details This hook allows node modules to limit access to the node types they define.
352 The administrative account (user ID #1) always passes any access check, so this hook is not called in that case. If this
353 hook is not defined for a node type, all access checks will fail, so only the administrator will be able to see content of that
354 type. However, users with the "administer nodes" permission may always view and edit content through the
355 administrative interface.
359 @warning The access hook is not yet implemented
361 @param[in] $op The operation to be performed. Possible values:
366 @param[in] $node The node on which the operation is to be performed, or, if it does not yet exist, the type of node to be created.
368 @param[in] $account A user object representing the user for whom the operation is to be performed.
370 @return TRUE if the operation is to be allowed; FALSE if the operation is to be denied; NULL to not override the settings in the node_access table, or access control modules.
372 @author Frederick Giasson, Structured Dynamics LLC.
374 @todo Implementing the access hook properly
376 @see http://api.drupal.org/api/function/hook_access
381 function conStruct_access($op, $node, $account)
386 /*! @brief Access callback for the conStruct_main() page
390 @warning The access hook callback function is not yet implemented
392 @return TRUE if the operation is to be allowed; FALSE if the operation is to be denied; NULL to not override the settings in the node_access table, or access control modules.
394 @author Frederick Giasson, Structured Dynamics LLC.
396 @todo Implementing the callback function for the access hook
398 @see http://api.drupal.org/api/function/hook_access
403 function conStruct_access_callback()
408 /*! @brief Create the settings form
409 @details This procedure is called to create the settings form displayed to the administrator
410 when the settings page of the conStruct module is accessed
414 @note This procedure has been registered to Drupal in the conStruct_menu() procedure.
416 @return A form object where all the settings have been defined.
418 @author Frederick Giasson, Structured Dynamics LLC.
420 @see http://drupal.org/node/206761
421 @see http://drupal.org/node/37775
425 function conStruct_admin()
429 // Nomalization of the URL of the node. Here we remove the "www" to normalize it.
430 $normalized_base_url = str_replace("www.", "", $base_url);
432 $graph = variable_get('conStruct_UrisDomain', str_replace("http://", "", get_domain($normalized_base_url)));
434 // Creation of the settings form
435 $form['conStruct_UrisDomain'] = array(
436 '#type' => 'textfield',
437 '#title' => t('Domain name used to resolve resources URIs'),
438 '#default_value' => $graph,
440 '#maxlength' => 1024,
442 "Each resource create, imported and updated on this system can be resolved on the Web. A conStruct website can have one or multiple domain names that can be used to access the resources indexed in the system. To make sure everything resolves to the same URIs, we have to set the canonical domain name used to create, and resolve, the resources identifiers."),
446 $form['conStruct_enableAutomaticIpChangeOnLogin'] = array(
447 '#type' => 'checkbox',
448 '#title' => t('Automatic users IP Change on login'),
450 "This option let you turn on/off the feature that automatically update the IP of the users if they change
451 computer. This option is turned off by default. In that case, users have to change it manually using the
452 'access settings' page."),
453 '#default_value' => variable_get('conStruct_enableAutomaticIpChangeOnLogin', 0),
456 return system_settings_form($form);
460 /*! @brief Validate the settings form
461 @details This procedure validate the fields filled by the administrator
465 @note This procedure is called by Drupal Core each time a setting is saved.
467 @param[in] $form is the form ID of the passed form
468 @param[out] $form_state are the form values which you may perform validation on
470 @return Nothing is successful. Returns a form error with the error message if the validation failed.
472 @author Frederick Giasson, Structured Dynamics LLC.
474 @see http://drupal.org/node/206761
475 @see http://drupal.org/node/37775
479 function conStruct_admin_validate($form, &$form_state)
481 // Get the current graph URI parameter
482 $uri = $form_state['values']['conStruct_UrisDomain'];
484 // If the URI is lesser tan 16 characters, return an error
485 if (strlen($uri) <= 8)
487 form_set_error('conStruct_UrisDomain', t('The URI of the base graph should have at least 8 characters'));
490 // Perform special handling of that URI
495 /*! @brief Access settings
498 @note This procedure has been registered to Drupal in the conStruct_menu() procedure.
500 @return A form object where all the settings have been defined.
503 @author Frederick Giasson, Structured Dynamics LLC.
505 @see http://drupal.org/node/206761
506 @see http://drupal.org/node/37775
510 function conStruct_access_settings()
515 // Creation of the settings form
516 $form["conStruct_AccessUser" .
$user->uid
] = array(
517 '#type' => 'textfield',
518 '#title' => t('The IP address you will use to query the web services related to this node. (you current IP: '
519 .
$_SERVER['REMOTE_ADDR'] .
')'),
520 '#default_value' => variable_get("conStruct_AccessUser" .
$user->uid
, ""),
522 '#maxlength' => 1024,
524 "Each node user can be bound with a IP address. This IP address is the address that can be used to query any web services, and datasets, available to that user."),
528 return system_settings_form($form);
532 /*! @brief Validate access settings
535 @param[in] $form Form to validate
536 @param[out] $form_state
538 @author Frederick Giasson, Structured Dynamics LLC.
540 @see http://drupal.org/node/206761
541 @see http://drupal.org/node/37775
545 function conStruct_access_settings_validate($form, &$form_state)
549 updateUserIpOnNetworks($form_state['values']["conStruct_AccessUser" .
$user->uid
]);
552 /*! @brief Update the IP of a user on linked structWSF instances.
555 @param[in] $newIP The new IP of the user to update.
557 @return Returns final (it could have been changed from the input variable) the new IP assigned by the procedure.
559 @author Frederick Giasson, Structured Dynamics LLC.
563 function updateUserIpOnNetworks($newIP)
567 // Check if the IP is being changed.
568 $oldIP = variable_get("conStruct_AccessUser" .
$user->uid
, "");
572 $newIP = "self::$user->uid";
577 $oldIP = "self::$user->uid";
580 include_once('./' .
drupal_get_path('module', 'conStruct') .
'/framework/WebServiceQuerier.php');
581 include_once('./' .
drupal_get_path('module', 'conStruct') .
'/framework/ProcessorXML.php');
583 // If it changed, we have to fix the access accordingly.
584 if ($oldIP != $newIP)
586 // Fix for each linked WSF
587 $wsfRegistry = variable_get("WSF-Registry", array());
589 if(count($wsfRegistry) > 0)
591 $includedWsfAddresses = array();
593 $sidRegistry = variable_get("SID-Registry", "");
595 foreach ($wsfRegistry as
$wsfAddress)
599 // Make sure that we don't query the same server twice
600 foreach ($sidRegistry as
$s => $wsfs)
602 if (array_search($wsfAddress, $wsfs) !== FALSE
)
608 if ($sid !== FALSE
&& array_search($sid, $includedWsfAddresses) === FALSE
)
610 array_push($includedWsfAddresses, $sid);
617 // Get all access descriptions for the old IP
618 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/lister/", "get", "text/xml",
619 "registered_ip=" .
urlencode($oldIP) .
"&mode=access_user");
621 if ($wsq->getStatus() == 200)
623 $xml = new
ProcessorXML();
624 $xml->loadXML($wsq->getResultset());
626 $accesses = $xml->getSubjectsByType("wsf:Access");
628 foreach ($accesses as
$access)
630 $webServiceAccesses = "";
634 $access_uri = $xml->getURI($access);
637 $predicates = $xml->getPredicatesByType($access, "wsf:registeredIP");
638 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal");
639 $registeredIP = $xml->getContent($objects->item(0));
642 $predicates = $xml->getPredicatesByType($access, "wsf:datasetAccess");
643 $objects = $xml->getObjectsByType($predicates->item(0), "void:Dataset");
644 $datasetAccess = $xml->getURI($objects->item(0));
647 $predicates = $xml->getPredicatesByType($access, "wsf:create");
648 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal");
649 $crud = $xml->getContent($objects->item(0)) .
";";
651 $predicates = $xml->getPredicatesByType($access, "wsf:read");
652 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal");
653 $crud .
= $xml->getContent($objects->item(0)) .
";";
655 $predicates = $xml->getPredicatesByType($access, "wsf:update");
656 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal");
657 $crud .
= $xml->getContent($objects->item(0)) .
";";
659 $predicates = $xml->getPredicatesByType($access, "wsf:delete");
660 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal");
661 $crud .
= $xml->getContent($objects->item(0));
663 // Get webServiceAccess(es)
664 $webservicesType = $xml->getPredicatesByType($access, "wsf:webServiceAccess");
666 foreach ($webservicesType as
$webserviceElement)
668 $webservicesTypeObj = $xml->getObjects($webserviceElement);
670 foreach ($webservicesTypeObj as
$wto)
672 $webServiceAccesses .
= $xml->getURI($wto) .
";";
676 $webServiceAccesses = substr($webServiceAccesses, 0, strlen($webServiceAccesses) - 1);
678 // Make sure we don't change the permissions of the World Readable default IP (0.0.0.0)
679 if ($registeredIP != "0.0.0.0")
681 // Update the access for this new IP for this Access.
682 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
683 "registered_ip=" .
urlencode($newIP) .
"&crud=$crud&ws_uris=" .
urlencode($webServiceAccesses) .
684 "&dataset=" .
urlencode($datasetAccess) .
"&action=update&target_access_uri=" .
urlencode($access_uri));
686 if ($wsq->getStatus() != 200)
689 $wsq->displayError();
697 $wsq->displayError();
707 /*! @brief Handle user action (implementation of the hook_user Drupal hook)
708 @details This hook allows modules to react when operations are performed on user accounts. This
709 hook is implemented to change the IP address of a user each time he log in. If its IP address
710 changed, then it will be updated on some related structWSF instances.
712 @param[in] $op What kind of action is being performed. Possible values (in alphabetical order)
713 @param[in] $edit The array of form values submitted by the user.
714 @param[in] $account The user object on which the operation is being performed.
715 @param[in] $category The active category of user information being edited.
719 @author Frederick Giasson, Structured Dynamics LLC.
721 @see http://api.drupal.org/api/function/hook_user
725 function conStruct_user($op, &$edit, &$account, $category = NULL
)
732 $enabled = variable_get("conStruct_enableAutomaticIpChangeOnLogin", 0);
739 Each time a user login, or view its user page, we have to check if its his IP address
740 changed. If it did, then we will change it on the different structWSF instances where
741 he has accesses defined for him.
743 We do exactly the same procedure for a "view", because some users can still be logged
744 in with their laptop computer, and changed their location (from home to internet coffee
749 A special case. If the operation is "view", then we have to make sure that the
750 user that view the page, is the one that is logged in. Otherwise, it would
753 if($op == "view" && ($account->uid
!= $user->uid
))
758 /* Get the current IP of the user and process the IP change */
759 if(isset($_SERVER['REMOTE_ADDR']))
761 $newIP = updateUserIpOnNetworks($_SERVER['REMOTE_ADDR']);
763 /* Assign the newIP into Drupal's variable registry. */
765 /* If the new IP is a "self" IP, then we simply assign an empty string to it. We have
766 to proceed that way because it is what the software is expecting. We are only
767 mimicing what the "settings save" behavior of Drupal. */
768 if(strtolower(substr($newIP, 0, 4)) == "self")
773 variable_set("conStruct_AccessUser" .
$user->uid
, $newIP);
783 /*! @brief Handle Organic Groups changes
784 @details Hook Organic Groups to handle user subscription / unsubscription
786 @param[in] $op Operation done by OG
787 @param[in] $gid Group ID
788 @param[in] $uid User ID
789 @param[in] $args Arguments of the hook
793 @author Frederick Giasson, Structured Dynamics LLC.
795 @see http://api.drupal-contrib.org/api/function/hook_og
796 @see http://api.freestylesystems.co.uk/api/function/og_og/6
800 function conStruct_og($op, $gid, $uid, $args)
802 include_once('./' .
drupal_get_path('module', 'conStruct') .
'/framework/WebServiceQuerier.php');
803 include_once('./' .
drupal_get_path('module', 'conStruct') .
'/framework/ProcessorXML.php');
811 // We have to check if a "dataset" is already created for that group. If it is not, this means that
812 // this user is the owner of this dataset. The problem here is the execution order of hooks in drupal.
813 // "hook_og" which manage the subscription of users is executed BEFORE hook_nodeapi which manage the
814 // creation of groups (datasets).
815 $wsfAddress = variable_get("Dataset-" .
$gid .
"-WSF", "");
816 $wsfAddressCreated = variable_get("Dataset-" .
$gid .
"-WSF-Created", "");
818 // Make sure we don't recreate the admin of this dataset twice
819 if ($wsfAddressCreated != "")
821 variable_del("Dataset-" .
$gid .
"-WSF-Created");
824 if ($wsfAddress != "")
826 // If we are in face of a linked dataset, we have to use the linked dataset URI as the
827 // target URI for this WSF query.
828 $linkedDatasetRegistry = variable_get("Linked-Dataset-Registry", "");
830 $targetDataset = variable_get("Dataset-" .
$gid .
"-ID", get_domain($base_url) .
"/wsf/datasets/" .
$gid .
"/");
832 if ($linkedDatasetRegistry != "")
834 if (isset($linkedDatasetRegistry[$gid]))
836 $targetDataset = $linkedDatasetRegistry[$gid];
841 new
WebServiceQuerier($wsfAddress .
"dataset/read/", "get", "text/xml", "uri=" .
urlencode($targetDataset));
843 $datasetCreated = TRUE
;
845 if ($wsq->getStatus() != 200)
848 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
850 $wsq->displayError();
855 // If a new user get subscribed to a group, we have to check if an access IP is defined for him.
856 // If there is one, we have to create an access for it.
857 $userIP = variable_get("conStruct_AccessUser" .
$uid, "");
861 // If there is no IP for that user, we overload the IP of the node with "::"
862 $userIP = "self::$uid";
865 $wsfAddress = variable_get("Dataset-" .
$gid .
"-WSF", "");
867 if ($wsfAddress != "")
869 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/lister/", "get", "text/xml", "mode=ws");
871 if ($wsq->getStatus() == 200)
873 // Get all web services
876 $xml = new
ProcessorXML();
877 $xml->loadXML($wsq->getResultset());
879 $webServiceElements = $xml->getXPath('//predicate/object[attribute::type="wsf:WebService"]');
881 foreach ($webServiceElements as
$element)
883 $webservices .
= $xml->getURI($element) .
";";
886 $webservices = substr($webservices, 0, strlen($webservices) - 1);
893 // By default CRUD is to "False;True;False;False". It is the duty of the dataset administrator
894 // to setup the proper CUD permissions for each user that have access to the dataset.
896 $wsq = new WebServiceQuerier($wsfAddress."auth/registrar/access/", "post", "text/xml",
897 "registered_ip=$userIP&crud=False;True;False;False&ws_uris".
898 "=$webservices&dataset=$targetDataset&action=create");
900 // If the user is an administrator, we give him full CRU. Otherwiser we give only R
904 'SELECT {role}.name FROM {users_roles} INNER JOIN {role} ON {role}.rid = {users_roles}.rid WHERE uid=%d ',
907 $roleNames = array();
909 // Get all WSF address still in use
910 while ($roleName = db_result($resultset))
912 array_push($roleNames, $roleName);
915 if (array_search("owner/curator", $roleNames) !== FALSE
)
917 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
918 "registered_ip=" .
urlencode($userIP) .
"&crud=True;True;True;True&ws_uris" .
919 "=" .
urlencode($webservices) .
"&dataset=" .
urlencode($targetDataset) .
"&action=create");
921 elseif (array_search("admin", $roleNames) !== FALSE
)
923 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
924 "registered_ip=" .
urlencode($userIP) .
"&crud=True;True;True;True&ws_uris" .
925 "=" .
urlencode($webservices) .
"&dataset=" .
urlencode($targetDataset) .
"&action=create");
929 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
930 "registered_ip=" .
urlencode($userIP) .
"&crud=False;True;False;False&ws_uris" .
931 "=" .
urlencode($webservices) .
"&dataset=" .
urlencode($targetDataset) .
"&action=create");
934 if ($wsq->getStatus() != 200)
937 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
939 $wsq->displayError();
945 // We have to add a reference, as a contributor of the dataset, in the description of the dataset.
946 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/read/", "get", "text/xml",
947 "uri=" .
urlencode($targetDataset));
951 if ($wsq->getStatus() != 200)
954 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
956 $wsq->displayError();
961 $xml = new
ProcessorXML();
962 $xml->loadXML($wsq->getResultset());
964 $datasets = $xml->getSubjectsByType("void:Dataset");
966 $predicates = $xml->getPredicatesByType($datasets->item(0), "dcterms:contributor");
968 foreach ($predicates as
$predicate)
970 $objects = $xml->getObjectsByType($predicate, "sioc:User");
972 $contributors .
= $xml->getURI($objects->item(0)) .
";";
976 $contributors .
= $base_url .
"/user/" .
$uid .
"/;";
978 $contributors = substr($contributors, 0, strlen($contributors) - 1);
982 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/update/", "post", "text/xml",
983 "uri=" .
urlencode($targetDataset) .
"&contributors=" .
urlencode($contributors));
985 if ($wsq->getStatus() != 200)
988 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
990 $wsq->displayError();
996 $wsq->displayError();
1001 drupal_set_message(t("No WSF address linked to this dataset"), "error", TRUE
);
1008 // Trigged at dataset creation.
1009 // Trigged when the manager of a group is changed.
1015 // Delete the Access for that user since he has been unsubscribed from that group.
1016 $userIP = variable_get("conStruct_AccessUser" .
$uid, "");
1019 // If there is no IP for that user, we overload the IP of the node with "::"
1020 $userIP = "self::$uid";
1023 // If we are in face of a linked dataset, we have to use the linked dataset URI as the target URI for this
1025 $linkedDatasetRegistry = variable_get("Linked-Dataset-Registry", "");
1027 $targetDataset = variable_get("Dataset-" .
$gid .
"-ID", get_domain($base_url) .
"/wsf/datasets/" .
$gid .
"/");
1028 if ($linkedDatasetRegistry != "")
1030 if (isset($linkedDatasetRegistry[$gid]))
1032 $targetDataset = $linkedDatasetRegistry[$gid];
1036 $wsfAddress = variable_get("Dataset-" .
$gid .
"-WSF", "");
1037 if ($wsfAddress != "")
1039 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1040 "registered_ip=" .
urlencode($userIP) .
"&dataset=" .
urlencode($targetDataset) .
"&action=delete_target");
1042 if ($wsq->getStatus() != 200)
1044 $wsq->displayError();
1049 // Delete the contributor reference in the dataset description
1051 new
WebServiceQuerier($wsfAddress .
"dataset/read/", "get", "text/xml", "uri=" .
urlencode($targetDataset));
1055 if ($wsq->getStatus() != 200)
1057 $wsq->displayError();
1061 $xml = new
ProcessorXML();
1062 $xml->loadXML($wsq->getResultset());
1064 $datasets = $xml->getSubjectsByType("void:Dataset");
1066 $predicates = $xml->getPredicatesByType($datasets->item(0), "dcterms:contributor");
1068 foreach ($predicates as
$predicate)
1070 $objects = $xml->getObjectsByType($predicate, "sioc:User");
1072 if ($xml->getURI($objects->item(0)) != $base_url .
"/user/" .
$uid .
"/")
1074 $contributors .
= $xml->getURI($objects->item(0)) .
";";
1079 $contributors = substr($contributors, 0, strlen($contributors) - 1);
1083 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/update/", "post", "text/xml",
1084 "uri=" .
urlencode($targetDataset) .
"&contributors=" .
urlencode($contributors));
1086 if ($wsq->getStatus() != 200)
1088 $wsq->displayError();
1093 drupal_set_message(t("No WSF address linked to this dataset"), "error", TRUE
);
1102 case "admin create":
1109 /*! @brief Monitor everything tha happens on Drupal
1113 @author Frederick Giasson, Structured Dynamics LLC.
1117 function conStruct_nodeapi(&$node, $op, $teaser = NULL
, $page = NULL
)
1119 include_once('./' .
drupal_get_path('module', 'conStruct') .
'/framework/WebServiceQuerier.php');
1120 include_once('./' .
drupal_get_path('module', 'conStruct') .
'/framework/ProcessorXML.php');
1126 if (strtolower($node->op
) != "delete") // Don't validate on a delete operation
1128 if (og_is_group_type($node->type
) && $node->type
== "dataset")
1130 // Make sure the WSF is registered to that node
1131 $wsfn = variable_get("WSF-Registry", array());
1133 if(array_search("http://".
$node->field_wsf
[0]["value"].
"/ws/", $wsfn) === FALSE
)
1135 form_set_error($node->field_wsf
[0]["_error_element"],
1136 t("This WSF is not registered in this conStruct node. Please register it using the Networks module."));
1140 if(isset($node->field_custom_dataset_uri
[0]["value"]) && $node->field_custom_dataset_uri
[0]["value"] != "")
1142 // Make sure that if a custom dataset has been defined that we don't duplicate it.
1143 $resultset = db_query('SELECT nid FROM {og}');
1145 while($datasetId = db_result($resultset))
1147 if(variable_get("Dataset-" .
$datasetId .
"-ID", "") == $node->field_custom_dataset_uri
[0]["value"])
1149 if($node->body
== "Import")
1151 form_set_error($node->field_custom_dataset_uri
[0]["_error_element"],
1152 t("The dataset file you imported has been appended to the existing dataset referenced by the custom URI you provided."));
1156 form_set_error($node->field_custom_dataset_uri
[0]["_error_element"],
1157 t("This custom dataset URI is already used by another dataset. Please choose another one and create it again."));
1165 if ($node->field_existing_dataset_uri
[0]["value"] != "")
1167 // Make sure that the linked dataset is not already linked by another group
1168 $linkedDatasetRegistry = variable_get("Linked-Dataset-Registry", "");
1170 if ($linkedDatasetRegistry != "")
1172 $id = array_search($node->field_existing_dataset_uri
[0]["value"], $linkedDatasetRegistry);
1173 if($id !== FALSE
&& $id != $node->nid
)
1175 form_set_error($node->field_existing_dataset_uri
[0]["_error_element"],
1176 t("A group of this Drupal node is already linked to this dataset URI"));
1181 // Make sure the WSF is existing & that the dataset is existing
1182 $wsq = new
WebServiceQuerier("http://" .
$node->field_wsf
[0]["value"] .
"/ws/" .
"dataset/read/", "get",
1183 "text/xml", "uri=" .
urlencode($node->field_existing_dataset_uri
[0]["value"]));
1185 if ($wsq->getStatus() != 200)
1187 if ($wsq->getStatus() == 503)
1189 form_set_error($node->field_wsf
[0]["_error_element"],
1190 t("This WSF address is not existing or unreachable"));
1194 form_set_error($node->field_existing_dataset_uri
[0]["_error_element"],
1195 t("Web service error: (status: @status) @status_message - @status_message_description", array(
1196 "status_message" => strip_tags($wsq->getStatusMessage()),
1197 "status_message_description" => strip_tags($wsq->getStatusMessageDescription())
1209 // Handling OG group creation
1210 if (og_is_group_type($node->type
) && $node->type
== "dataset")
1215 // Save the WSF IP for this newly created dataset
1216 variable_set("Dataset-" .
$node->nid .
"-WSF", "http://" .
$node->field_wsf
[0]["value"] .
"/ws/");
1217 variable_set("Dataset-" .
$node->nid .
"-WSF-Created", "true");
1219 if(isset($node->field_custom_dataset_uri
[0]["value"]) && $node->field_custom_dataset_uri
[0]["value"] != "")
1221 variable_set("Dataset-" .
$node->nid .
"-ID", $node->field_custom_dataset_uri
[0]["value"]);
1225 variable_set("Dataset-" .
$node->nid .
"-ID", "");
1228 $wsfAddress = variable_get("Dataset-" .
$node->nid .
"-WSF", "");
1230 // Save this new WSF address into the WSF registery
1231 $wsfRegistry = variable_get("WSF-Registry", array());
1233 if (array_search($wsfAddress, $wsfRegistry) === FALSE
)
1235 array_push($wsfRegistry, $wsfAddress);
1236 variable_set("WSF-Registry", $wsfRegistry);
1239 // Now, lets recreate the SID-Registry structure
1240 $sidRegistry = array();
1242 foreach ($wsfRegistry as
$wsfa)
1246 curl_setopt($ch, CURLOPT_HEADER
, 0);
1247 curl_setopt($ch, CURLOPT_URL
, $wsfa .
"index.php");
1248 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
1249 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 1);
1251 $data = curl_exec($ch);
1253 if (curl_errno($ch))
1259 $data = trim($data);
1261 if (!isset($sidRegistry[$data]))
1263 $sidRegistry[$data] = array($wsfa);
1267 array_push($sidRegistry[$data], $wsfa);
1273 // Save the SID-Registry
1274 variable_set("SID-Registry", $sidRegistry);
1276 // Check if a remote dataset URI as been defined
1277 if(isset($node->field_existing_dataset_uri
[0]["value"]) && $node->field_existing_dataset_uri
[0]["value"] != "")
1279 // Save the local group ID and the remote group ID in the Remote WSF registry
1280 $linkedDatasetRegistry = variable_get("Linked-Dataset-Registry", "");
1282 if ($linkedDatasetRegistry == "")
1284 $linkedDatasetRegistry = array();
1287 $linkedDatasetRegistry[$node->nid
] = $node->field_existing_dataset_uri
[0]["value"];
1289 $targetDataset = $linkedDatasetRegistry[$node->nid
];
1291 variable_set("Dataset-" .
$node->nid .
"-ID", $targetDataset);
1293 variable_set("Linked-Dataset-Registry", $linkedDatasetRegistry);
1295 // If we link to an existing dataset, we register the user with full crud if he is an admin, or the
1296 // owner/curator of the conStruct node instance (CRUD == True;True;True;True.) Otherwise, he will get the
1297 // collaborator (CRUD == False;True;False;False) permissions.
1298 // it is up to the creator of the remote dataset to change these permissions to this user.
1300 // Note: we can't create this permission in hook_og.php for the only reason that this hook get executed
1301 // BEFORE this one. So the linkage is not yet done at that time.
1303 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/read/", "get", "text/xml",
1304 "uri=" .
urlencode($targetDataset));
1306 if($wsq->getStatus() == 200)
1308 // If a new user get subscribed to a group, we have to check if an access IP is defined for him. If there
1309 // is one, we have to create an access for it.
1310 $userIP = variable_get("conStruct_AccessUser" .
$user->uid
, "");
1314 // If there is no IP for that user, we overload the IP of the node with "::"
1315 $userIP = "self::$user->uid";
1318 $wsfAddress = variable_get("Dataset-" .
$node->nid .
"-WSF", "");
1320 if ($wsfAddress != "")
1322 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/lister/", "get", "text/xml", "mode=ws");
1324 if ($wsq->getStatus() == 200)
1326 // Get all web services
1329 $xml = new
ProcessorXML();
1330 $xml->loadXML($wsq->getResultset());
1332 $webServiceElements = $xml->getXPath('//predicate/object[attribute::type="wsf:WebService"]');
1334 foreach ($webServiceElements as
$element)
1336 $webservices .
= $xml->getURI($element) .
";";
1339 $webservices = substr($webservices, 0, strlen($webservices) - 1);
1346 // Check to see what role the user has on the node, and then specify the proper permissions for him.
1349 'SELECT {role}.name FROM {users_roles} INNER JOIN {role} ON {role}.rid = {users_roles}.rid WHERE uid=%d ',
1352 $roleNames = array();
1354 // Get all WSF address still in use
1355 while ($roleName = db_result($resultset))
1357 array_push($roleNames, $roleName);
1360 if (array_search("owner/curator", $roleNames) !== FALSE
)
1362 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1363 "registered_ip=" .
urlencode($userIP) .
"&crud=True;True;True;True&ws_uris" .
1364 "=" .
urlencode($webservices) .
"&dataset=" .
urlencode($targetDataset) .
"&action=create");
1366 elseif (array_search("admin", $roleNames) !== FALSE
)
1368 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1369 "registered_ip=" .
urlencode($userIP) .
"&crud=True;True;True;True&ws_uris" .
1370 "=" .
urlencode($webservices) .
"&dataset=" .
urlencode($targetDataset) .
"&action=create");
1374 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1375 "registered_ip=" .
urlencode($userIP) .
"&crud=False;True;False;False&ws_uris" .
1376 "=" .
urlencode($webservices) .
"&dataset=" .
urlencode($targetDataset) .
"&action=create");
1379 if ($wsq->getStatus() != 200)
1382 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
1384 $wsq->displayError();
1390 // We have to register the VO node with all permission to properly manage this dataset
1391 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1392 "registered_ip=self&crud=True;True;True;True&ws_uris=" .
urlencode($webservices) .
"&dataset="
1393 .
urlencode($targetDataset) .
"&action=create");
1395 if ($wsq->getStatus() != 200)
1398 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
1400 $wsq->displayError();
1407 // We have to add a reference, as a contributor of the dataset, in the description of the dataset.
1408 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/read/", "get", "text/xml",
1409 "uri=" .
urlencode($targetDataset));
1413 if ($wsq->getStatus() != 200)
1416 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
1418 $wsq->displayError();
1423 $xml = new
ProcessorXML();
1424 $xml->loadXML($wsq->getResultset());
1426 $datasets = $xml->getSubjectsByType("void:Dataset");
1428 $predicates = $xml->getPredicatesByType($datasets->item(0), "dcterms:contributor");
1430 foreach ($predicates as
$predicate)
1432 $objects = $xml->getObjectsByType($predicate, "sioc:User");
1434 $contributors .
= $xml->getURI($objects->item(0)) .
";";
1438 $contributors .
= $base_url .
"/user/" .
$user->uid .
"/;";
1440 $contributors = substr($contributors, 0, strlen($contributors) - 1);
1444 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/update/", "post", "text/xml",
1445 "uri=" .
urlencode($targetDataset) .
"&contributors=" .
urlencode($contributors));
1447 if ($wsq->getStatus() != 200)
1450 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
1452 $wsq->displayError();
1458 $wsq->displayError();
1463 drupal_set_message(t("No WSF address linked to this dataset"), "error", TRUE
);
1468 $wsq->displayError();
1473 // If we are not linking the group to an existing dataset, we have to create it on the WSF
1475 // Creating new Dataset
1476 $title = db_result(db_query('SELECT title FROM {node} WHERE nid=%d LIMIT 1', $node->nid
));
1477 $description = db_result(db_query('SELECT og_description FROM {og} WHERE nid=%d LIMIT 1', $node->nid
));
1479 $baseDomain = variable_get("conStruct_UrisDomain", get_domain($base_url));
1481 $newDatasetUri = variable_get("Dataset-" .
$node->nid .
"-ID", "");
1483 if($newDatasetUri == "")
1485 // If no custom datasets have been defined, we use a generic one composed of its organic groups ID.
1486 $newDatasetUri = (strpos($baseDomain, "http://") === FALSE ?
"http://" .
$baseDomain : $baseDomain)
1487 .
"/wsf/datasets/" .
$node->nid .
"/";
1489 variable_set("Dataset-" .
$node->nid .
"-ID", $newDatasetUri);
1492 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/create/", "post", "text/xml", "uri="
1493 .
urlencode($newDatasetUri)
1494 .
"&title=" .
urlencode($title) .
"&description=" .
urlencode($description) .
"&creator="
1495 .
urlencode($base_url .
"/user/" .
$user->uid .
"/"));
1497 if ($wsq->getStatus() != 200)
1499 $wsq->displayError();
1505 // Creation of a full access for this VO node. Once it is done, it is the node that will manage interaction
1506 // between users and the dataset.
1508 // create a new cURL resource
1509 if (isset($_SERVER['REMOTE_ADDR']))
1511 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/lister/", "get", "text/xml", "mode=ws");
1513 if ($wsq->getStatus() == 200)
1515 // Get all web services
1518 $xml = new
ProcessorXML();
1519 $xml->loadXML($wsq->getResultset());
1521 $webServiceElements = $xml->getXPath('//predicate/object[attribute::type="wsf:WebService"]');
1523 foreach ($webServiceElements as
$element)
1525 $webservices .
= $xml->getURI($element) .
";";
1528 $webservices = substr($webservices, 0, strlen($webservices) - 1);
1532 if ($webservices == "")
1534 $wsq->displayError();
1540 // Create the access, of this VO node, to all registered web services of the WSF
1543 // Take care with PHP's $_SERVER['SERVER_ADDR'] and EC2 instances. This variable is the private DNS IP
1544 // of the instance, AND NOT its IP accessible on the web.
1546 $baseDomain = variable_get("conStruct_UrisDomain", get_domain($base_url));
1548 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1549 "registered_ip=self&crud=true;true;true;true&ws_uris=" .
urlencode($webservices) .
"&dataset="
1550 .
urlencode($newDatasetUri) .
"&action=create");
1552 if ($wsq->getStatus() != 200)
1554 $wsq->displayError();
1559 $wsq->displayError();
1563 // We have to register the "public" user that has the "0.0.0.0" IP address
1564 // By default this public user has no permissions
1566 $baseDomain = variable_get("conStruct_UrisDomain", get_domain($base_url));
1568 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1569 "registered_ip=0.0.0.0&crud=False;False;False;False&ws_uris=" .
urlencode($webservices) .
"&dataset="
1570 .
urlencode($newDatasetUri) .
"&action=create");
1572 if ($wsq->getStatus() != 200)
1575 if ($wsq->getStatusMessageDescription() != "This dataset doesn't exist in this WSF")
1577 $wsq->displayError();
1584 // Registration of the administrator of this node
1587 $userIP = variable_get("conStruct_AccessUser" .
$user->uid
, "");
1591 // If there is no IP for that user, we overload the IP of the node with "::"
1592 $userIP = "self::$user->uid";
1595 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/lister/", "get", "text/xml", "mode=ws");
1597 if ($wsq->getStatus() == 200)
1599 // Get all web services
1602 $xml = new
ProcessorXML();
1603 $xml->loadXML($wsq->getResultset());
1605 $webServiceElements = $xml->getXPath('//predicate/object[attribute::type="wsf:WebService"]');
1607 foreach ($webServiceElements as
$element)
1609 $webservices .
= $xml->getURI($element) .
";";
1612 $webservices = substr($webservices, 0, strlen($webservices) - 1);
1617 $baseDomain = variable_get("conStruct_UrisDomain", get_domain($base_url));
1619 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1620 "registered_ip=" .
urlencode($userIP) .
"&crud=True;True;True;True&ws_uris=$webservices&dataset="
1621 .
urlencode($newDatasetUri) .
"&action=create");
1623 if ($wsq->getStatus() != 200)
1625 $wsq->displayError();
1632 $wsq->displayError();
1640 // Handling OG group deletation
1641 if (og_is_group_type($node->type
) && $node->type
== "dataset")
1643 $wsfAddress = variable_get("Dataset-" .
$node->nid .
"-WSF", "");
1645 variable_del("Dataset-" .
$node->nid .
"-WSF");
1647 $datasetUri = variable_get("Dataset-" .
$node->nid .
"-ID", get_domain($base_url) .
"/wsf/datasets/" .
$node->nid .
"/");
1649 variable_del("Dataset-" .
$node->nid .
"-ID");
1651 // Clean up the WSF-Registry
1654 Not necessary anymore since we are now using structNetwork to manage the WSF-Registry.
1657 $resultset = db_query('SELECT nid FROM {og}');
1661 // Get all WSF address still in use
1662 while ($nid = db_result($resultset))
1664 $wsf = variable_get("Dataset-" . $nid . "-WSF", "");
1666 if (array_search($wsf, $usedWsf) === FALSE && $wsf != "")
1668 array_push($usedWsf, $wsf);
1672 // Recreate the WSF-Registry according to this list
1673 variable_set("WSF-Registry", $usedWsf);
1676 // Check if it was a linked dataset. If it was, we only remove it from the linked dataset registry of this
1678 $linkedDatasetRegistry = variable_get("Linked-Dataset-Registry", "");
1680 if ($linkedDatasetRegistry != "")
1682 if (isset($linkedDatasetRegistry[$node->nid
]))
1684 // Lets remove the remove accesses to this dataset for each user of this group
1686 $resultset = db_query('SELECT uid FROM {og_uid} WHERE nid=%d', $node->nid
);
1688 while ($uid = db_result($resultset))
1690 $userIP = variable_get("conStruct_AccessUser" .
$uid, "");
1694 // If there is no IP for that user, we overload the IP of the node with "::"
1695 $userIP = "self::$uid";
1698 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1699 "registered_ip=" .
urlencode($userIP) .
"&dataset=" .
urlencode($linkedDatasetRegistry[$node->nid
])
1700 .
"&action=delete_target");
1702 if ($wsq->getStatus() != 200)
1704 $wsq->displayError();
1710 // Then remove the access of this VO node
1711 $wsq = new
WebServiceQuerier($wsfAddress .
"auth/registrar/access/", "post", "text/xml",
1712 "registered_ip=self&dataset=" .
urlencode($linkedDatasetRegistry[$node->nid
])
1713 .
"&action=delete_target");
1715 // Finally, lets drop the linkage to this dataset and this group
1717 unset($linkedDatasetRegistry[$node->nid
]);
1719 variable_set("Linked-Dataset-Registry", $linkedDatasetRegistry);
1725 // Otherwise, we delete the dataset that has been previously created
1728 if ($wsfAddress != "")
1730 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/delete/", "get", "text/xml",
1731 "uri=" .
urlencode($datasetUri));
1733 if ($wsq->getStatus() != 200)
1735 $wsq->displayError();
1742 drupal_set_message(t("No WSF address linked to this dataset"), "error", TRUE
);
1750 // Handling OG group update
1751 if (og_is_group_type($node->type
) && $node->type
== "dataset")
1755 $wsfAddress = variable_get("Dataset-" .
$node->nid .
"-WSF", "");
1757 if ($wsfAddress != "")
1760 // if the WSF address changed, we first have to change it here.
1761 if ($wsfAddress != "http://" .
$node->field_wsf
[0]["value"] .
"/ws/")
1763 // Save the WSF IP for this newly created dataset
1764 variable_set("Dataset-" .
$node->nid .
"-WSF", "http://" .
$node->field_wsf
[0]["value"] .
"/ws/");
1766 $wsfAddress = variable_get("Dataset-" .
$node->nid .
"-WSF", "");
1768 // Save this new WSF address into the WSF registery
1769 $wsfRegistry = variable_get("WSF-Registry", array());
1771 if (array_search($wsfAddress, $wsfRegistry) === FALSE
)
1773 array_push($wsfRegistry, $wsfAddress);
1774 variable_set("WSF-Registry", $wsfRegistry);
1777 // Now, lets recreate the SID-Registry structure
1778 $sidRegistry = array();
1780 foreach ($wsfRegistry as
$wsfAddress)
1784 curl_setopt($ch, CURLOPT_HEADER
, 0);
1785 curl_setopt($ch, CURLOPT_URL
, $wsfAddress .
"index.php");
1786 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
1787 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 1);
1789 $data = curl_exec($ch);
1791 if (curl_errno($ch))
1797 $data = trim($data);
1799 if (!isset($sidRegistry[$data]))
1801 $sidRegistry[$data] = array($wsfAddress);
1805 array_push($sidRegistry[$data], $wsfAddress);
1811 // Save the SID-Registry
1812 variable_set("SID-Registry", $sidRegistry);
1815 // Then we check if the address of the linked dataset changed
1816 $linkedDatasetRegistry = variable_get("Linked-Dataset-Registry", "");
1818 if ($linkedDatasetRegistry == "")
1820 if (isset($linkedDatasetRegistry[$node->nid
]))
1822 $linkedDatasetRegistry[$node->nid
] = $node->field_existing_dataset_uri
[0]["value"];
1824 variable_set("Linked-Dataset-Registry", $linkedDatasetRegistry);
1830 // If not, we update the description of the dataset
1831 $wsq = new
WebServiceQuerier($wsfAddress .
"dataset/update/", "post", "text/xml",
1832 "uri=" .
urlencode(variable_get("Dataset-" .
$node->nid .
"-ID", get_domain($base_url) .
1833 "/wsf/datasets/" .
$node->nid .
"/")) .
"&title="
1834 .
urlencode($node->title
) .
"&description=" .
urlencode($node->og_description
));
1836 if ($wsq->getStatus() != 200)
1838 $wsq->displayError();
1843 drupal_set_message(t("No WSF address linked to this dataset"), "error", TRUE
);