forked from dingproject/ting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathting.module
441 lines (402 loc) · 12.1 KB
/
ting.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<?php
/**
* @file
* Module to integrate the Ting search engine with a Drupal site.
*/
/**
* Implementation of hook_menu().
*/
function ting_menu() {
$path = drupal_get_path('module', 'ting') . '/includes';
$items = array();
$items['ting/object/redirect'] = array(
'title' => 'Redirect to object based on local ID (links from bibliotek.dk).',
'page callback' => 'ting_search_pages_object_redirect',
'access arguments' => array('search content'),
'type' => MENU_CALLBACK,
'file' => 'ting.pages.inc',
'file path' => $path,
);
$items['admin/settings/ting'] = array(
'title' => 'Ting search',
'page callback' => 'drupal_get_form',
'page arguments' => array('ting_admin_settings_form'),
'access arguments' => array('administer site configuration'),
'file' => 'ting.admin.inc',
'file path' => $path,
);
$items['admin/settings/ting/access'] = array(
'title' => 'Ting access',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/settings/ting/ranking'] = array(
'title' => 'Ranking',
'page callback' => 'drupal_get_form',
'page arguments' => array('ting_admin_ranking_form'),
'access arguments' => array('administer site configuration'),
'file' => 'ting.admin.inc',
'file path' => $path,
'type' => MENU_LOCAL_TASK,
);
$items['admin/settings/ting/boost'] = array(
'title' => 'Boost',
'description' => 'Enable the user to boost specific values for specific fields in search results.',
'page callback' => 'drupal_get_form',
'page arguments' => array('ting_admin_boost_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'ting.admin.inc',
'file path' => $path,
'type' => MENU_LOCAL_TASK,
);
$items['ting/ranking_field/ahah'] = array(
'title' => 'Ting ranking field AHAH callback',
'title callback' => FALSE,
'page callback' => 'ting_admin_ranking_add_field_ahah',
'access arguments' => array('administer site configuration'),
'file' => 'ting.admin.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
);
$items['ting/boost_field/ahah'] = array(
'title' => 'Ting boost field AHAH callback',
'title callback' => FALSE,
'page callback' => 'ting_admin_boost_add_field_ahah',
'access arguments' => array('administer site configuration'),
'file' => 'ting.admin.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_elements().
*
* Define a new form element named ting_ranking_field.
*
* It calls the theme function theme_ting_ranking_field, if not defined
* no elements will be displayed.
*/
function ting_elements() {
return array(
'ting_boost_field' => array(
'#input' => TRUE,
'#process' => array('ting_boost_field_element_process'),
),
'ting_ranking_field' => array(
'#input' => TRUE,
'#process' => array('ting_ranking_field_element_process'),
),
);
}
/**
* Implementation of hook_theme().
*/
function ting_theme() {
return array(
'ting_thing' => array(
'arguments' => array('type' => 'object', 'object' => NULL, 'query_args' => NULL),
'file' => 'ting.theme.inc',
),
'ting_list' => array(
'arguments' => array('ting_list' => NULL, 'sorted' => FALSE),
'template' => 'ting-list',
'file' => 'ting.theme.inc',
),
'ting_list_item' => array(
'arguments' => array('object' => NULL),
'template' => 'ting-list-item',
'file' => 'ting.theme.inc',
),
'ting_tabs' => array(
'arguments' => array('tabs' => NULL, 'wrapper_id' => NULL),
'template' => 'ting-tabs',
'file' => 'ting.theme.inc',
),
'ting_collection' => array(
'arguments' => array('collection' => NULL, 'query_args' => NULL),
'template' => 'ting_collection',
'file' => 'ting.theme.inc',
),
'ting_object' => array(
'arguments' => array('object' => NULL),
'template' => 'ting_object',
'file' => 'ting.theme.inc',
),
'ting_object_title' => array(
'arguments' => array('object' => NULL, 'display_image' => NULL),
'template' => 'ting-object-title',
'file' => 'ting.theme.inc',
),
'ting_ranking_field' => array(
'arguments' => array('element' => NULL),
),
'ting_boost_field' => array(
'arguments' => array('element' => NULL),
'file' => 'ting.theme.inc',
),
'ting_details' => array(
'arguments' => array('details' => NULL),
'file' => 'ting.theme.inc',
),
'ting_details_group' => array(
'arguments' => array('title' => NULL, 'group' => NULL),
'file' => 'ting.theme.inc',
),
);
}
/**
* Implementation of hook_ctools_plugin_api().
*/
function ting_ctools_plugin_api($module, $api) {
if ($module == 'page_manager' && $api == 'pages_default') {
return array('version' => 1);
}
}
/**
* Implementation of hook_ctools_plugin_directory().
*
* Tells CTools (and thus Panels) where to look for plugin code.
*/
function ting_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' || $module == 'panels') {
return 'plugins/' . $plugin;
}
}
/**
* Implementation of hook_imagecache_default_presets()
*/
function ting_imagecache_default_presets() {
$presets = array();
$presets['180_x'] = array (
'presetname' => '180_x',
'actions' =>
array (
0 =>
array (
'weight' => '0',
'module' => 'imagecache',
'action' => 'imagecache_scale',
'data' =>
array (
'width' => '180',
'height' => '',
'upscale' => 0,
),
),
),
);
$presets['80_x'] = array (
'presetname' => '80_x',
'actions' =>
array (
0 =>
array (
'weight' => '0',
'module' => 'imagecache',
'action' => 'imagecache_scale',
'data' =>
array (
'width' => '80',
'height' => '',
'upscale' => 1,
),
),
)
);
return $presets;
}
/**
* Implementation of hook_ting_add_js().
*/
function ting_ting_add_js($type) {
// Add button helper on collection and object views if the required jQuery UI modules are loaded
// These are not requirements to avoid unecessary dependencies in ting module
if (in_array($type, array('ting_collection_view', 'ting_object_view'))) {
if (module_exists('jquery_ui') && module_exists('jquery_ui_theme')) {
jquery_ui_add('ui.dialog');
jquery_ui_theme_load();
drupal_add_js(drupal_get_path('module', 'ting') . '/js/ting.buttons.js');
}
}
}
/**
* Implementation of hook_ting_object_buttons().
*/
function ting_ting_object_buttons($object) {
if (!empty($object->localId)) {
if (!empty($object->online_url) &&
ting_object_is($object, 'online')) {
// TODO: Consider new ting object class: audible
if (in_array(drupal_strtolower($object->type), array('lydbog (net)', 'musik (net)',
'lydbog (online)', 'netmusik (album)' /* Included to ensure backwards compatability with DKABM 1.x */
))) {
$text = t('Hear online');
}
else {
$text = t('See online');
}
return array(
array(
'data' => l($text, $object->online_url),
'class' => 'view-online',
)
);
}
}
}
/**
* Implementation of hook_trampoline_variables().
*/
function ting_trampoline_variables() {
return array(
'ting_agency',
'ting_search_url',
'ting_scan_url',
'ting_spell_url',
'ting_recommendation_server',
);
}
/**
* Menu loader function.
*/
function ting_id_load($id) {
module_load_include('client.inc', 'ting');
return ting_get_object_by_id($id);
}
/**
* Menu loader function.
*/
function ting_local_id_load($id) {
module_load_include('client.inc', 'ting');
return ting_get_object_by_local_id($id);
}
/**
* Add additional information to a ting object.
*/
function ting_enrich_object(&$object) {
$object = array_shift(ting_add_additional_info(array($object)));
}
/**
* Parse a string containing search query arguments into an array
* @return array Array of search query arguments
*/
function _ting_search_parse_query_args($query_string) {
$query_args = array();
$query_elements = explode(';', $query_string);
foreach ($query_elements as &$e) {
$e = explode(':', $e, 2);
if (strpos($e[1], ':') !== FALSE) {
$query_args[$e[0]] = array();
$e_args = explode(':', $e[1], 2);
$query_args[$e[0]][$e_args[0]] = $e_args[1];
} else {
$query_args[$e[0]] = $e[1];
}
}
return $query_args;
}
/**
* Return whether an object is of a given pseudo-class.
*
* Modules can add their own pseudo-classes by implementing
* hook_ting_object_is(). This function will call all implementations and
* return the overall result.
*
* Modules may return TRUE, FALSE or NULL from the hook. If any modules
* returned FALSE, the result is FALSE, else the result is TRUE if anyone
* returned TRUE, FALSE otherwise.
*/
function ting_object_is($object, $class) {
$result = module_invoke_all('ting_object_is', $object, $class);
// Return true if anyone returned true, and nobody returned false.
if (!in_array(FALSE, $result) && in_array(TRUE, $result)) {
return TRUE;
}
return FALSE;
}
/**
* Implementation of hook_ting_object_is().
*/
function ting_ting_object_is($object, $class) {
// Known online types.
if ($class == 'online') {
$online_types = array('avis (net)', 'film (net)', 'lydbog (net)', 'musik (net)', 'ebog', 'periodikum (net)', 'pc-spil (net)', 'tidsskrift (net)', 'netdokument',
'lydbog (online)', 'netmusik (album)' /* Included to ensure backwards compatability with DKABM 1.x */);
if (in_array(drupal_strtolower($object->type), $online_types)) {
return TRUE;
}
}
}
/**
* Processor for the ting_ranking_field form element.
*/
function ting_ranking_field_element_process($element, $form_state) {
$element['#tree'] = TRUE;
$element['field_type'] = array(
'#title' => t('Type'),
'#type' => 'select',
'#options' => array(
'phrase' => t('Phrase'),
'word' => t('Word'),
),
'#default_value' => $element['#value']['field_type'],
);
$element['field_name'] = array(
'#title' => t('Field name'),
'#type' => 'select',
'#options' => array(
'' => '- ' . t('Choose') . ' -',
'ac.source' => t('Source'),
'dc.title' => t('Title'),
'dc.creator' => t('Author'),
'dc.subject' => t('Subject'),
'dc.date' => t('Year of publish'),
'dc.type' => t('Material type'),
),
'#default_value' => $element['#value']['field_name'],
'#attributes' => array('class' => 'field-name'),
);
$element['weight'] = array(
'#title' => t('Weight'),
'#type' => 'select',
'#options' => drupal_map_assoc(range(1, 10)),
'#default_value' => $element['#value']['weight'],
);
return $element;
}
/**
* Processor for the ting_boost_field form element.
*/
function ting_boost_field_element_process($element, $form_state) {
$element['#tree'] = TRUE;
$element['#prefix'] = '<div class="ting-boost-field-element clearfix">';
$element['#suffix'] = '</div>';
$element['field_name'] = array(
'#title' => t('Field name'),
'#type' => 'select',
'#options' => array(
'' => '- ' . t('Choose') . ' -',
'ac.source' => t('Source'),
'dc.creator' => t('Author'),
'dc.date' => t('Year of publish'),
'dc.language' => t('Language'),
'dc.type' => t('Material type'),
'dc.identifier' => t('ISBN number'),
),
'#default_value' => (isset($element['#value']['field_name'])) ? $element['#value']['field_name'] : NULL,
'#attributes' => array('class' => array('field-name')),
);
$element['field_value'] = array(
'#title' => t('Value'),
'#type' => 'textfield',
'#default_value' => (isset($element['#value']['field_value'])) ? $element['#value']['field_value'] : NULL,
);
$element['weight'] = array(
'#title' => t('Weight'),
'#type' => 'select',
'#options' => drupal_map_assoc(range(1, 10)),
'#default_value' => (isset($element['#value']['weight'])) ? $element['#value']['weight'] : NULL,
);
return $element;
}