-
Notifications
You must be signed in to change notification settings - Fork 13
/
islandora_xquery.module
265 lines (252 loc) · 9.02 KB
/
islandora_xquery.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/**
* @file
* Defines all the hooks this module implements.
* @todo
* Handle "the i18n_string integration fun".
*/
define('ISLANDORA_XQUERY_ZORBA_REQUIRED_VERSION', '3.0.0');
define('ISLANDORA_XQUERY_ZORBA_DEFAULT_LOCATION', '/usr/bin/zorba');
define('ISLANDORA_XQUERY_BASEX_DEFAULT_LOCATION', '/usr/bin/basex');
define('ISLANDORA_XQUERY_STATUS_PENDING', 'PENDING');
define('ISLANDORA_XQUERY_STATUS_OBJECT_LOAD_FAIL', 'OBJECT LOAD FAIL');
define('ISLANDORA_XQUERY_STATUS_DATASTREAM_LOAD_FAIL', 'DATASTREAM LOAD FAIL');
define('ISLANDORA_XQUERY_STATUS_PATCH_FAIL', 'PATCH FAIL');
define('ISLANDORA_XQUERY_STATUS_DATSTREAM_UPDATE_FAIL', 'DATSTREAM UPDATE FAIL');
define('ISLANDORA_XQUERY_STATUS_APPLIED', 'APPLIED');
/**
* Implements hook_menu().
*/
function islandora_xquery_menu() {
$items = array();
$items['admin/islandora/tools/xquery/manage'] = array(
'title' => 'XQuery',
'description' => 'Configure Islandora XQuery',
'access arguments' => array('administer islandora_xquery'),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_xquery_admin_form'),
'file' => 'includes/admin.form.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/islandora/tools/xquery/manage/template'] = array(
'title' => 'Templates',
'description' => 'Configure templates for Islandora XQuery',
'access arguments' => array('administer islandora_xquery'),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_xquery_admin_form'),
'file' => 'includes/admin.form.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['admin/islandora/tools/xquery/manage/general'] = array(
'title' => 'General',
'description' => 'General configuration Islandora XQuery',
'access arguments' => array('administer islandora_xquery'),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_xquery_general_admin_form'),
'file' => 'includes/general_admin.form.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/islandora/tools/xquery/manage/processor'] = array(
'title' => 'Processors',
'description' => 'Configure Islandora XQuery processor',
'access arguments' => array('administer islandora_xquery'),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_xquery_processor_admin_form'),
'file' => 'includes/processor_admin.form.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/islandora/tools/xquery/manage/template/%'] = array(
'title' => 'Manage Template',
'description' => 'Manages a specific template for use in Islandora XQuery',
'access callback' => 'islandora_xquery_access',
'access arguments' => array(6),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_xquery_template_management_form', 6),
'file' => 'includes/manage.inc',
);
$items['admin/islandora/tools/xquery/manage/template/%/delete'] = array(
'title' => 'Delete Template',
'description' => 'Deletes a specific template from Islandora XQuery',
'access callback' => 'islandora_xquery_access',
'access arguments' => array(6),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_xquery_template_delete_confirm_form', 6),
'file' => 'includes/delete.inc',
);
$items['islandora/xquery/preview/%'] = array(
'title' => 'Query Preview',
'description' => "Provides a preview of xquery results before commiting them to Fedora.",
'access callback' => 'user_access',
'access arguments' => array('search and replace with xquery'),
'page callback' => 'islandora_xquery_preview_results',
'page arguments' => array(3),
'file' => 'includes/preview.inc',
);
$items['islandora/xquery/preview/%/apply'] = array(
'title' => 'Apply Query',
'description' => "Applies results of an xquery and commits them to Fedora.",
'access callback' => 'user_access',
'access arguments' => array('search and replace with xquery'),
'page callback' => 'islandora_xquery_apply_results',
'page arguments' => array(3),
'file' => 'includes/apply.inc',
);
$items['islandora/xquery/preview/%/cancel'] = array(
'title' => 'Apply Query',
'description' => "Cancels an xquery find/replace operation.",
'access callback' => 'user_access',
'access arguments' => array('search and replace with xquery'),
'page callback' => 'islandora_xquery_cancel_results',
'page arguments' => array(3),
'file' => 'includes/cancel.inc',
);
return $items;
}
/**
* Implements hook_theme().
*/
function islandora_xquery_theme($existing, $type, $theme, $path) {
$items = array();
$items['islandora_xquery_preview'] = array(
'path' => $path . '/theme',
'file' => 'theme.inc',
'template' => 'islandora-xquery-preview',
'variables' => array(
'results' => NULL,
'batch_id' => "",
'apply_link' => "",
'cancel_link' => "",
),
);
return $items;
}
/**
* Implements hook_libraries_info().
*/
function islandora_xquery_libraries_info() {
return array(
'geshi' => array(
'title' => 'GeSHi - Generic Syntax Highlighter for PHP',
'vendor url' => 'http://sourceforge.net/projects/geshi',
'download url' => 'http://sourceforge.net/projects/geshi/files/geshi',
'version arguments' => array(
'file' => 'geshi.php',
'pattern' => "/define\('GESHI_VERSION', '(.*)'\);/",
'lines' => 50,
),
'files' => array(
'php' => array(
'geshi.php',
),
),
),
);
}
/**
* Implements hook_permission().
*/
function islandora_xquery_permission() {
return array(
'administer islandora_xquery' => array(
'title' => 'Create and manage XQuery templates',
),
'search and replace with xquery' => array(
'title' => 'Search and replace with XQuery',
),
);
}
/**
* Access callback for accessing a association based upon ID.
*
* @param int $association_id
* The configuration ID of the list we are accessing.
*
* @return bool
* TRUE if the user has permission and the list exists, FALSE otherwise.
*/
function islandora_xquery_access($association_id) {
module_load_include('inc', 'islandora_xquery', 'includes/db');
return islandora_xquery_association_exists($association_id) && user_access('administer islandora_xquery');
}
/**
* Implements hook_islandora_solr_primary_display().
*/
function islandora_xquery_islandora_solr_primary_display() {
return array(
'xquery' => array(
'name' => t('XQuery'),
'module' => 'islandora_xquery',
'file' => 'includes/solr_results.inc',
'class' => 'IslandoraSolrResultsXquery',
'function' => 'displayResults',
'description' => t('Search results for performing an XQuery find/replace operation.'),
),
);
}
/**
* Implements hook_form_alter().
*/
function islandora_xquery_form_islandora_solr_advanced_search_form_alter(&$form, &$form_state, $form_id) {
// Filter out to just the enabled profile and see if XQuery is one of them.
if (user_access('search and replace with xquery')) {
$primary_display_array = variable_get('islandora_solr_primary_display_table', array());
if (!empty($primary_display_array)) {
$display = array_filter($primary_display_array['enabled']);
if (isset($display['xquery'])) {
$form['xquery'] = array(
'#type' => 'checkbox',
'#title' => t('XQuery search and replace?'),
);
$form['#submit'][] = 'islandora_xquery_solr_advanced_search_form_submit';
}
}
}
}
/**
* Implements hook_form_alter().
*/
function islandora_xquery_form_islandora_solr_simple_search_form_alter(&$form, &$form_state, $form_id) {
// Filter out to just the enabled profile and see if XQuery is one of them.
if (user_access('search and replace with xquery')) {
$primary_display_array = variable_get('islandora_solr_primary_display_table', array());
if (!empty($primary_display_array)) {
$display = array_filter($primary_display_array['enabled']);
if (isset($display['xquery'])) {
$form['xquery'] = array(
'#type' => 'checkbox',
'#title' => t('XQuery search and replace?'),
);
$form['#submit'][] = 'islandora_xquery_solr_search_form_submit';
}
}
}
}
/**
* Altered Islandora Solr advanced search form submit callback.
*
* @param array $form
* An associative array containing form structure.
* @param array $form_state
* An associative array containing form state.
*
* @see islandora_solr_advanced_search_form()
*/
function islandora_xquery_solr_advanced_search_form_submit($form, &$form_state) {
if ($form_state['values']['xquery']) {
$form_state['redirect'][1]['query']['display'] = 'xquery';
}
}
/**
* Islandora Solr simple search form submit callback.
*
* @param array $form
* An associative array containing form structure.
* @param array $form_state
* An associative array containing form state.
*/
function islandora_xquery_solr_search_form_submit($form, &$form_state) {
if ($form_state['values']['xquery']) {
$form_state['redirect'][1]['query']['display'] = 'xquery';
}
}