| 1 |
<?php
|
| 2 |
|
| 3 |
|
| 4 |
/**
|
| 5 |
* administrative functions for the SEMANTIC_SEARCH module
|
| 6 |
*
|
| 7 |
* @author Jonathan Hendler
|
| 8 |
* @package SEMANTIC_SEARCH
|
| 9 |
*
|
| 10 |
* */
|
| 11 |
|
| 12 |
|
| 13 |
/**
|
| 14 |
* replaces missing drupal 4.6 function
|
| 15 |
*/
|
| 16 |
function message_admin_access() {
|
| 17 |
return t('SEMANTIC_SEARCH admin access required.');
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* creates a simple list of the navigation elements for adminstering
|
| 22 |
* the SEMANTIC_SEARCH module's data
|
| 23 |
* */
|
| 24 |
function _NinaAdminMenu() {
|
| 25 |
if (!user_access("administer semantic_search")) {
|
| 26 |
return message_admin_access();
|
| 27 |
}
|
| 28 |
|
| 29 |
$output = '';
|
| 30 |
$menu_list[] = l('Export SEMANTIC_SEARCH Data', 'admin/semantic_search/export');
|
| 31 |
//$menu_list[] = l('Import SEMANTIC_SEARCH Data', 'semantic_search/admin/import');
|
| 32 |
$menu_list[] = l('Configure SEMANTIC_SEARCH', 'admin/semantic_search/settings');
|
| 33 |
//$menu_list[] = l('Admin Home', 'admin/semantic_search');
|
| 34 |
//$menu_list[] = l('Back to main Nina Application Admin Page', 'semantic_search');
|
| 35 |
$output .= theme_item_list($menu_list);
|
| 36 |
|
| 37 |
return t($output);
|
| 38 |
}
|
| 39 |
|
| 40 |
//function _SEMANTIC_SEARCHImport_validate($form_id, $form_values) {
|
| 41 |
// global $_semantic_search_search;
|
| 42 |
// //print_r($form_values);
|
| 43 |
//
|
| 44 |
//}
|
| 45 |
//
|
| 46 |
//function _SEMANTIC_SEARCHImport_submit($form_id, $form_values) {
|
| 47 |
// global $_semantic_search_search;
|
| 48 |
//
|
| 49 |
// if (!empty ($_FILES[SONIA_FORM_ARRAY_PREFIX]['name']['upload'])) {
|
| 50 |
// $uri = $_FILES[SONIA_FORM_ARRAY_PREFIX]['tmp_name']['upload'];
|
| 51 |
// } else
|
| 52 |
// if (!empty ($form_values['upload_remote'])) {
|
| 53 |
// //todo add filters and checks
|
| 54 |
// $uri = $form_values['upload_remote'];
|
| 55 |
// }
|
| 56 |
//
|
| 57 |
// $rdf = file_get_contents($uri);
|
| 58 |
//
|
| 59 |
// //get model URI
|
| 60 |
//
|
| 61 |
// //check RDF
|
| 62 |
//
|
| 63 |
// //chose sync method
|
| 64 |
//
|
| 65 |
//}
|
| 66 |
|
| 67 |
/**
|
| 68 |
* allowss standard SONIA RDF to be imported.
|
| 69 |
* @todo
|
| 70 |
* */
|
| 71 |
/*
|
| 72 |
function _SEMANTIC_SEARCHImport_form() {
|
| 73 |
if (!user_access("administer semantic_search")) {
|
| 74 |
return message_admin_access();
|
| 75 |
}
|
| 76 |
|
| 77 |
global $_semantic_search_search;
|
| 78 |
|
| 79 |
$output = '';
|
| 80 |
$form['title'] = array (
|
| 81 |
'#value' => 'SEMANTIC_SEARCH Administration<br/>'
|
| 82 |
);
|
| 83 |
|
| 84 |
$form['subtitle'] = array (
|
| 85 |
'#value' => 'Import RDF<br/>'
|
| 86 |
);
|
| 87 |
|
| 88 |
$form['#attributes'] = array (
|
| 89 |
'enctype' => 'multipart/form-data'
|
| 90 |
);
|
| 91 |
|
| 92 |
$form['new']['upload'] = array (
|
| 93 |
'#type' => 'file',
|
| 94 |
'#title' => t('Attach RDF[S] file'
|
| 95 |
), '#size' => 40, '#description' => SEMANTIC_SEARCH_ln('admin_import_file'),);
|
| 96 |
|
| 97 |
$form['new']['upload_remote'] = array (
|
| 98 |
'#type' => 'textfield',
|
| 99 |
'#title' => t('or Load a remote RDF[S] file'
|
| 100 |
), '#size' => 40, '#description' => SEMANTIC_SEARCH_ln('admin_import_remote_file'),);
|
| 101 |
|
| 102 |
//replace all old data - or simply add to the model
|
| 103 |
$form['new']['import_type'] = array (
|
| 104 |
'#type' => 'select',
|
| 105 |
'#options' => array (
|
| 106 |
SEMANTIC_SEARCH_IMPORT_SIGNAL_SYNC_DUP_OLD => 'add data (synchronize - allow duplicates - keep old data)',
|
| 107 |
SEMANTIC_SEARCH_IMPORT_SIGNAL_SYNC_NO_DUP_OLD => 'add data (synchronize - don\'t allow duplicates - keep old data)',
|
| 108 |
SEMANTIC_SEARCH_IMPORT_SIGNAL_SYNC_NO_DUP_NEW => 'add data (synchronize - don\'t allow duplicates - overwrite old data)',
|
| 109 |
SEMANTIC_SEARCH_IMPORT_SIGNAL_NO_OLD => 'add data (erase all old data, replacing with new data)',
|
| 110 |
|
| 111 |
|
| 112 |
),
|
| 113 |
'#values' => '',
|
| 114 |
'#title' => 'Import Type',
|
| 115 |
'#description' => SEMANTIC_SEARCH_ln('admin_import_synchronize'
|
| 116 |
),);
|
| 117 |
//<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
|
| 118 |
//TODO ARC can be optimized if it knows certain things about the model ahead of time
|
| 119 |
|
| 120 |
//TODO get max filesize from drupal settings
|
| 121 |
//TODO I do not want this pre-pended with drupal's edit prefix
|
| 122 |
$form['MAX_FILE_SIZE'] = array (
|
| 123 |
'#type' => 'hidden',
|
| 124 |
'#value' => 1000000
|
| 125 |
);
|
| 126 |
|
| 127 |
$form['submit'] = array (
|
| 128 |
'#type' => 'submit',
|
| 129 |
'#value' => t('Submit Data'
|
| 130 |
));
|
| 131 |
$output .= drupal_get_form('_SEMANTIC_SEARCHImport', $form);
|
| 132 |
|
| 133 |
return $output;
|
| 134 |
}
|
| 135 |
*/
|
| 136 |
|
| 137 |
/**
|
| 138 |
* Use Drupal function to trigger a download of a file
|
| 139 |
* @todo allow user to create filename
|
| 140 |
*
|
| 141 |
* */
|
| 142 |
function _semantic_search_export() {
|
| 143 |
if (!user_access("administer semantic_search")) {
|
| 144 |
return message_admin_access();
|
| 145 |
}
|
| 146 |
|
| 147 |
global $_semantic_search_search;
|
| 148 |
if (empty ($_semantic_search_search))
|
| 149 |
_SEMANTIC_SEARCH_INIT();
|
| 150 |
|
| 151 |
// link to set the downlowd
|
| 152 |
$download_link = SEMANTIC_SEARCH_ADMIN_EXPORT_HOME . '?&' . SEMANTIC_SEARCH_EXPORT_DOWNLOAD_SIGNAL . '=1'; //site plus export download signal
|
| 153 |
|
| 154 |
//link to print rdf to screen
|
| 155 |
$print_link = SEMANTIC_SEARCH_ADMIN_EXPORT_HOME . '?&' . SEMANTIC_SEARCH_EXPORT_PRINT_SIGNAL . '=1'; //site plus export download signal
|
| 156 |
|
| 157 |
//output
|
| 158 |
$output = '<a href="' . $download_link . '" > Download RDF File</a>';
|
| 159 |
$output .= '<br /><a href="' . $print_link . '" > Print to screen RDF File</a>';
|
| 160 |
|
| 161 |
if (isset ($_GET[SEMANTIC_SEARCH_EXPORT_DOWNLOAD_SIGNAL])) {
|
| 162 |
$rdf = $_semantic_search_search->sonia->exportRDF(null);
|
| 163 |
SONIA_H :: SendContent($rdf, 'sonia.rdf', 'text/xml+rdf');
|
| 164 |
} else
|
| 165 |
if (isset ($_GET[SEMANTIC_SEARCH_EXPORT_PRINT_SIGNAL])) {
|
| 166 |
$rdf = $_semantic_search_search->sonia->exportRDF(null);
|
| 167 |
return $output . '<br/>RDF:<br/><pre> <br/>' . nl2br(htmlentities($rdf)) . '</pre>';
|
| 168 |
}
|
| 169 |
|
| 170 |
return $output;
|
| 171 |
}
|