Commit dc66098f authored by Colin Scott-Fleming's avatar Colin Scott-Fleming
Browse files

Initial copy of files from Drupal environment.

parent 648ab659
/* Form styling */
#field-irods-directory-values input {
}
#field-irods-directory-values input:focus {
background:#900;
}
; $Id$
name = "iRODS Directory"
description = "A textfield widget that allows the use of an iRODS filetree."
package = "iRODS Tools"
core = 7.x
version = 7.x-1.0
dependencies[] = irods_filetree
dependencies[] = field_ui
scripts[] = irods_directory.js
<?php
// $Id$
/**
* Implementation of hook_field_schema().
*/
function irods_directory_field_schema($field) {
$columns = array(
'irods_path' => array(
'type' => 'varchar', 'length' => 1024, 'not null' => TRUE
)
);
return array(
'columns' => $columns,
'indexes' => array()
);
}
// $Id$
// jQuery(document).ready(function() {
// input = jQuery('#field-irods-directory-values input');
// jQuery(input).focus(function() {
// this.attr('value', pick());
// });
// });
<?php
// $Id$
/**
* @file
* Provides a field for the path of an iRODS directory.
*/
/**
* Implementation of hook_field_info().
*/
function irods_directory_field_info() {
return array(
'irods_directory_field' => array(
'label' => t('iRODS Directory'),
'description' => t('iRODS Directory Path'),
'default_widget' => 'irods_directory_field_widget',
'default_formatter' => 'irods_directory_field_formatter'
)
);
}
/**
* Implementation of hook_field_widget_info().
*/
function irods_directory_field_widget_info() {
return array(
'irods_directory_field_widget' => array(
'label' => t('Default'),
'field types' => array('irods_directory_field')
)
);
}
/**
* Implementation of hook_field_widget_form().
*/
function irods_directory_field_widget_form(&$form, &$form_state, $field,
$instance, $langcode, $items, $delta, $element) {
$path = drupal_get_path('module', 'irods_directory');
drupal_add_css($path . '/irods_directory.css');
$path = drupal_get_path('module', 'irods_filetree');
drupal_add_js($path . '/irods_filetree.js');
$required = $element['#required'];
$item =& $items[$delta];
$element['irods_path'] = array(
'#title' => t('iRODS Data Path'),
'#type' => 'textfield',
'#required' => $required,
'#default_value' => isset($item['irods_path']) ? $item['irods_path'] : ''
);
return $element;
}
/**
* Implementation of hook_field_is_empty().
*/
function irods_directory_field_is_empty($item, $field) {
return !isset($item['irods_path']);
}
.block-irods-filetree .filetree_fetch_button {
display:inline;
background:#888;
padding:4px;
border: 1px solid #bbb;
border-radius:4px;
}
.block-irods-filetree .filetree {
display:none;
}
name = "iRODS Filetree"
description = "Retrieves the directory of an iRODS folder as JSON"
package = "iRODS Tools"
core = 7.x
version = "7.x-0.1"
// $Id$
// Wrap input on pageload.
jQuery(document).ready(function() {
var input = jQuery('#field-irods-directory-values input');
jQuery(input).focus(function() {
jQuery(this).attr('value', showPicker(this));
});
});
// Function that fetches the json
function ajaxFetch() {
var block = jQuery('.block-irods-filetree');
jqxhr = jQuery.ajax({
url : '/irods_filetree',
type : 'get',
dataType : 'json',
xhrFields: {
withCredentials: true
},
success : function(data, textStatus, xhr) {
var tree = data;
output = outputJSON(tree);
jQuery('.filetree', block).html(output);
jQuery('.filetree', block).css('display', 'block');
jQuery('.filetree_fetch_button', block).html('Refresh');
},
error : function(xhr, textStatus, errorThrown) {
output = "<p>An error occurred while connecting to iRODS:</p>";
output += "<p>The status was: <strong>" + xhr['status'] + "</strong> " +
errorThrown;
console.log(xhr);
jQuery('.filetree', block).html(output);
jQuery('.filetree', block).css('display', 'block');
}
});
}
// Helper function that converts JSON into a nested list structure
function outputJSON(obj) {
result = "<ul class=\"irods_parent\">";
for (var key in obj) {
result += "<li class=\"irods_node\" title=\"" + key + "\">"+ key;
if (Object.keys(obj).length) {
result += outputJSON(obj[key]);
};
result += "</li>";
}
result += "</ul>";
return result;
}
/**
* Shows the iRODS Filetree Picker.
*
* Uses element to attach the specific field to the picker so that the return
* value is assigned to the correct field.
*/
function showPicker(element) {
var content = buildPicker(element);
jQuery('body').append(content);
}
/**
* Climbs up the directory structure to return the file path of a nested
* element.
*/
function getDirectory(element) {
result = jQuery(element).attr('title');
while (jQuery(element).parent().hasClass('irods_parent')) {
element = jQuery(element).parent().parent();
result = jQuery(element).attr('title') + "/" + result;
}
return result;
}
/**
* Hides the iRODS Filetree Picker.
*/
function hidePicker() {
// For overlay module
if (location.href.indexOf('#overlay') >= 0) {
jQuery('.overlay-active')
.contents().find('.irods-filetree-picker-popup').remove();
};
// For no iFrames
jQuery('.irods-filetree-picker-popup').remove();
}
/**
* Builds the iRODS Filetree Picker
*/
function buildPicker(element) {
// The div that stores the picker content.
var result = jQuery('<div>').addClass('irods-filetree-picker-popup');
jQuery(result).append('<h2>iRODS File Picker®</h2>');
jQuery(result).append('<ul>');
jQuery('ul', result).addClass('irods-filetree-picker');
jQuery('ul', result).append('<li>');
jQuery('li', result).addClass('irods-filetree-picker options').html("/");
jQuery.ajax({
url : '/irods_filetree',
type : 'get',
dataType : 'json',
xhrFields: {
withCredentials: true
},
success : function(data, textStatus, xhr) {
var options = jQuery('.options', result);
var tree = data;
options.append(outputJSON(tree));
jQuery('li', options).dblclick(function() {
jQuery(element).attr('value', getDirectory(this));
hidePicker();
});
},
error : function(xhr, textStatus, errorThrown) {
output = "<p>An error occurred while connecting to iRODS:</p>";
output += "<p>The status was: <strong>" + xhr['status'] + "</strong> " +
errorThrown;
console.log(xhr);
}
});
return result;
}
<?php
/**
* @file
* iRODS File Tree
*/
/**
* Implements hook_menu()
*
* Creates an 'iRODS' section on the administration page for iRODS modules
* to use for their configuration and settings
*/
function irods_filetree_menu() {
// Admin config page
$items['admin/config/irods/filetree'] = array(
'title' => 'iRODS Server Configuration',
'description' => t('Configure iRODS server credentials.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('irods_filetree_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer site configuration')
);
// JSON return page
$items['irods_filetree'] = array(
'title' => 'Filetree',
'page callback' => 'irods_filetree_fetch',
'page arguments' => array(FALSE, FALSE),
'access callback' => 'user_access',
'access arguments' => array('administer site configuration')
);
return $items;
}
/**
* Implements hook_block_info()
*/
function irods_filetree_block_info() {
$blocks['irods filetree'] = array(
'info' => 'Filetree',
'cache' => DRUPAL_NO_CACHE
);
return $blocks;
}
/**
* Implements hook_block_view()
*/
function irods_filetree_block_view($delta = '') {
switch ($delta) {
case 'irods filetree':
$path = drupal_get_path('module', 'irods_filetree');
drupal_add_js($path . '/irods_filetree.js');
drupal_add_css($path . '/irods_filetree.css');
$block['subject'] = 'iRODS Filetree';
$block['content'] = '
<div class="filetree_fetch_button" onclick="ajaxFetch();">
Load
</div>
<div class="filetree"></div>';
break;
}
return $block;
}
/**
* This function returns a form for configuring the iRODS credentials used to
* retrieve the iRODS directory structure.
*
* @see irods_filetree_settings_validate
*/
function irods_filetree_settings($form, &$form_state) {
$form = array();
$form['description'] = array(
'#type' => 'item',
'#title' => t('iRODS Server Configuration'),
'#description' =>
t('Server credentials and important directory locations.')
);
$lib = 'sites/all/libraries/prods';
$form['irods_filetree_prods_dir'] = array(
'#type' => 'textfield',
'#title' => t('PRODS Location'),
'#required' => TRUE,
'#default_value' => variable_get('irods_filetree_prods_dir', $lib),
'#description' => t('Location of the PHP iRODS code on the webserver '.
'(no trailing slash).')
);
$form['irods_filetree_irods_root'] = array(
'#type' => 'textfield',
'#title' => t('Data root'),
'#required' => TRUE,
'#default_value' => variable_get('irods_filetree_irods_root', '/'),
'#description' => t('Location of the iRODS data directory to be used as'.
' the root (no trailing slash).</br><em>Note: this is the data root '.
'on the iRODS server.</em>')
);
$server = 'www.example.com';
$form['irods_filetree_irods_server'] = array(
'#type' => 'textfield',
'#title' => t('Server'),
'#required' => TRUE,
'#default_value' => variable_get('irods_filetree_irods_server', $server),
'#description' => t('Server address for iRODS server.')
);
$form['irods_filetree_irods_port'] = array(
'#type' => 'textfield',
'#title' => t('Port'),
'#required' => TRUE,
'#default_value' => variable_get('irods_filetree_irods_port', '1247'),
'#description' => t('Port for the iRODS connection.')
);
$form['irods_filetree_irods_user'] = array(
'#type' => 'textfield',
'#title' => t('Username.'),
'#required' => TRUE,
'#default_value' => variable_get('irods_filetree_irods_user', 'iroduser'),
'#description' => t('Username for the iRODS connection.')
);
$form['irods_filetree_irods_pass'] = array(
'#type' => 'textfield',
'#title' => t('iRODS server password'),
'#required' => TRUE,
'#default_value' => variable_get('irods_filetree_irods_pass', 'password'),
'#description' => t('Password for te iRODS connection.')
);
drupal_set_message("Form validation still in beta.", 'warning', FALSE);
return system_settings_form($form);
}
/**
* Form validation handler for iRODS File Tree Configuration form.
*/
function irods_filetree_settings_validate($form, &$form_state) {
// Validate PRODS directory path syntax
$prods_dir = $form_state['values']['irods_filetree_prods_dir'];
if (substr($prods_dir, 0, 1) != '/') {
$prods_dir = '/home/htdocs' . $GLOBALS['base_path'] . $prods_dir;
}
if (!file_exists($prods_dir)) {
form_set_error('irods_filetree_prods_dir', t('Directory @dir not found or inaccessible.', array('@dir' => $prods_dir)));
}
// Validate iRODS directory path syntax
$irods_root = $form_state['values']['irods_filetree_irods_root'];
// Validate server address
$irods_server = $form_state['values']['irods_filetree_irods_server'];
// Validate port
$port = intval($form_state['values']['irods_filetree_irods_port']);
if ($port < 1 || $port > 65535) {
form_set_error('irods_port', t('Enter a valid port value.'));
}
// Validate username
$irods_user = $form_state['values']['irods_filetree_irods_user'];
// Validate password
$irods_pass = $form_state['values']['irods_filetree_irods_pass'];
}
/**
* Function that retrieves the iRODS directory structure.
*
* @param $include_files - Boolean to store whether individual files will be
* listed, or just the directory structure.
* @param $debug - Boolean to return the json string or echo it for AJAX
* retrieval.
*/
function irods_filetree_fetch($include_files = FALSE, $debug = FALSE) {
$prods_dir = variable_get('irods_filetree_prods_dir', NULL);
if (!$prods_dir) {
$message = 'Undefined PHP iRODS installation directory. You may need to '.
'configure your iRODS setup '.
'<a href="admin/config/irods/filetree">here</a>.';
drupal_set_message($message, 'error', FALSE);
return;
}
if (!file_exists($prods_dir . '/Prods.inc.php')) {
$message = 'Could not locate Prods.inc.php in <em>' . $prods_dir .
'</em>. You may need to recopy PHP iRODS into <em>' . $prods_dir .
'</em>.';
drupal_set_message($message, 'error', FALSE);
return;
}
require_once($prods_dir . '/Prods.inc.php');
$irods_root = variable_get('irods_filetree_irods_root', NULL);
if (!$irods_root) {
$message = 'Undefined iRODS root. You may need to configure your iRODS '.
'setup <a href="admin/config/irods/filetree">here</a>.';
drupal_set_message($message, 'error', FALSE);
return;
}
$irods_server = variable_get('irods_filetree_irods_server', NULL);
if (!$irods_server) {
$message = 'Undefined iRODS server. You may need to configure your iRODS '.
'setup <a href="admin/config/irods/filetree">here</a>.';
drupal_set_message($message, 'error', FALSE);
return;
}
$irods_port = variable_get('irods_filetree_irods_port', 0);
if (!$irods_port) {
$message = 'Undefined iRODS port. You may need to configure your iRODS '.
'setup <a href="admin/config/irods/filetree">here</a>.';
drupal_set_message($message, 'error', FALSE);
return;
}
$irods_user = variable_get('irods_filetree_irods_user', NULL);
if (!$irods_user) {
$message = 'Undefined iRODS username. You may need to configure your '.
'iRODS setup <a href="admin/config/irods/filetree">here</a>.';
drupal_set_message($message, 'error', FALSE);
return;
}
$irods_pass = variable_get('irods_filetree_irods_pass', NULL);
if (!$irods_pass) {
$message = 'Undefined iRODS password. You may need to configure your '.
'iRODS setup <a href="admin/config/irods/filetree">here</a>.';
drupal_set_message($message, 'error', FALSE);
return;
}
$acct =
new RODSAccount($irods_server, $irods_port, $irods_user, $irods_pass);
if (!$acct) {
drupal_set_message('There was an error creating the iRODS account.',
'error', FALSE);
return;
}
$rootdir = new ProdsDir($acct, $irods_root);
if (!$rootdir) {
drupal_set_message('There was an error creating the iRODS directory.',
'error', FALSE);
return;
}
$json = fetch_contents($rootdir, $include_files);
if ($debug) {
return json_encode($json);
}
echo json_encode($json);
}
/**
* Recursive helper function for irods_filetree_fetch().
*
* @param $dir - Directory to list.
* @param $files - Boolean to dictate whether individual files will be listed,
* or if only directory tree will be listed.
*/
function fetch_contents($dir, $files) {
$contents = array();
if ($files)
foreach ($dir->getChildFiles() as $file)
array_push($contents, $file->getName());
foreach ($dir->getChildDirs() as $node)
$contents[$node->getName()] = fetch_contents($node, $files);
return $contents;
}
; $Id$
name = "iRODS Mailer"
description = "Notification Mailer for the iRODS Monitor"
package = "iRODS Tools"
core = 7.x
version = "7.x-0.1"
dependencies[] = messaging
<?php
// $Id
/*
* @file
* Handles notifying users of updates and scheduled notifications for their
* files via PHP mail.
*/
/*