forked from DBCDK/ting_search
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathting_search.module
808 lines (712 loc) · 23.1 KB
/
ting_search.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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
<?php
/**
* @file
* Enables search integration with Ting.
*/
/**
* Implements hook_ctools_plugin_directory().
*
* It simply tells panels where to find the .inc files that define various
* args, contexts, content_types.
*/
function ting_search_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' && !empty($plugin)) {
return "plugins/$plugin";
}
}
/**
* Implement hook_ctools_plugin_api().
*/
function ting_search_ctools_plugin_api($module, $api) {
if ($module == 'page_manager' && $api == 'pages_default') {
return array('version' => 1);
}
}
/**
* Implements hook_menu_alter().
*
* Temporary hack to alter titles.
*/
function ting_search_menu_alter(&$items) {
$items['search/node']['title'] = 'Website';
$items['search/node']['weight'] = 2;
$items['search/node/%menu_tail']['title'] = 'Website';
$items['search/node/%menu_tail']['weight'] = 2;
$items['search/node/%menu_tail']['load arguments'] = array('%map', '%index');
$items['search/ting']['title'] = 'Materials';
$items['search/ting']['weight'] = 1;
$items['search/ting/%menu_tail']['title'] = 'Materials';
$items['search/ting/%menu_tail']['weight'] = 1;
}
/**
* Implements hook_search_info().
*/
function ting_search_search_info() {
return array(
'title' => t('Materials'),
'path' => 'ting',
'conditions_callback' => 'ting_search_conditions_callback',
);
}
/**
* Implements hook_ding_facetbrowser().
*/
function ting_search_ding_facetbrowser() {
$results = new stdClass();
$results->show_empty = FALSE;
$search_result = drupal_static('ting_search_results');
if ($search_result) {
$results->facets = $search_result->getFacets();
$results->searchkey = $search_result->getKeyword();
return $results;
}
}
/**
* Implements hook_theme().
*/
function ting_search_theme() {
return array(
'ting_search_results' => array(
'variables' => array(
'results' => NULL,
'module' => NULL,
),
'file' => 'ting_search.pages.inc',
'template' => 'ting-search-results',
),
'ting_search_mini_pager' => array(
'variables' => array(
'tags' => array(),
'element' => 0,
'parameters' => array(),
'quantity' => 9,
),
),
'ting_search_pager' => array(
'variables' => array(
'tags' => array(),
'element' => 0,
'parameters' => array(),
'quantity' => 9,
),
),
'ting_search_display_extended_query' => array(
'variables' => array(
'query_label' => NULL,
'query_string' => NULL,
),
'template' => 'ting-search-display-extended-query',
),
'ting_search_extended_search' => array(
'template' => 'ting-search-extended-search',
),
);
}
function ting_search_get_extended_actions() {
return theme('ting_search_extended_search');
}
/**
* @brief Implementation of hook_form_FORM_ID_alter() for form search_block_form.
*/
function ting_search_form_search_block_form_alter(&$form, &$form_state, $form_id) {
drupal_add_js('misc/form.js');
drupal_add_js('misc/collapse.js');
$form['#attributes'] = array('class' => array('input-append'));
$form['#process'][] = '_search_block_form__assign_weight';
$advanced_fields = array(
'term.creator' => array(
'key' => 'creator',
'title' => t('Author'),
'description' => t('Enter the author name'),
),
'term.title' => array(
'key' => 'title',
'title' => t('Title'),
'description' => t('Enter title'),
),
'term.subject' => array(
'key' => 'subject',
'title' => t('Subject'),
'description' => t('Enter subject keywords'),
),
);
$advanced = TRUE;
// Parse extended search query parameters.
if (arg(0) == 'search') {
$parts = explode('/', $_GET['q']);
// Lose 'search' and the search type.
array_shift($parts);
$type = array_shift($parts);
$search_query = implode('/', $parts);
$indexes = ting_search_extract_keys($search_query, array_keys($advanced_fields));
$search_query = $indexes['q'];
unset($indexes['q']);
if ($type != 'ting' and !empty($indexes)) {
$search_query .= " " . implode(' ', $indexes);
$indexes = array();
$advanced = FALSE;
}
$form['search_block_form']['#default_value'] = $search_query;
}
$form['actions']['clear'] = array(
'#type' => 'markup',
'#prefix' => '<button type="button" class="btn clear btn-artesis-blue" type="button" disabled title="' . t('Clear search input') . '">',
'#suffix' => '</button>',
'#markup' => '<i class="icon-remove"></i>',
'#weigth' => 1,
'#html' => TRUE,
);
if ($advanced && module_exists('ting_search_extendform')) {
$form['actions']['advanced'] = array(
'#type' => 'markup',
'#prefix' => '<button type="button" class="btn advanced btn-artesis-blue" type="button" disabled title="' . t('Advanced search') . '">',
'#suffix' => '</button>',
'#markup' => '<i class="icon-right-open"></i>',
'#weigth' => 5,
'#html' => TRUE,
);
}
$form['actions']['submit']['#attributes'] = array('class' => array('btn', 'search', 'btn-artesis-turquoise'));
$form['actions']['submit']['#weight'] = 10;
$form['actions']['submit']['#value'] = '<i class="icon-search icon-white"></i> ' . $form['actions']['submit']['#value'];
$form['sort'] = array(
'#type' => 'hidden',
'#default_value' => isset($_GET['sort']) ? check_plain($_GET['sort']) : FALSE,
'#attributes' => array('id' => 'controls_search_sort'),
);
$form['size'] = array(
'#type' => 'hidden',
'#default_value' => isset($_GET['size']) ? (int) $_GET['size'] : FALSE,
'#attributes' => array('id' => 'controls_search_size'),
);
$form['#attached'] = array(
'css' => array(
drupal_get_path('module', 'ting_search') . '/ting_search_extendform.css',
),
'js' => array(
drupal_get_path('module', 'ting_search') . '/ting_search_extendform.js',
),
);
$form['#submit'] = array('ting_search_submit');
}
function _search_block_form__assign_weight($args) {
$args['search_block_form']['#weight'] = 10;
$args['actions']['#weight'] = 11;
$args['basic_search']['#weight'] = 12;
$args['advanced_search']['#weight'] = 13;
return $args;
}
/**
* Extract special field keys from search string.
*
* @param string $search_query The search query.
* @param array $keys Keys to extract.
*
* @return array Where the array keys are the search keys, and the remainder
* search string in 'q'.
*/
function ting_search_extract_keys($search_query, $keys) {
$indexes = &drupal_static('ting_search_extract_indexes', array());
ting_search_extract_indexes(NULL, $keys);
$regexpes = array(
'/(^|\s+and\s+)\(([^)]+)\)$/i',
);
foreach ($regexpes as $regexp) {
$search_query = preg_replace_callback($regexp, 'ting_search_extract_indexes', $search_query);
}
$indexes['q'] = $search_query;
return $indexes;
}
/**
* preg_replace_callback function.
*/
function ting_search_extract_indexes($matches, $set_keys = NULL) {
static $keys;
if ($set_keys) {
$keys = array_flip($set_keys);
}
$return = array();
$subexps = preg_split('/\s+and\s+/i', $matches[2] ?? $matches, NULL, PREG_SPLIT_NO_EMPTY);
$indexes = &drupal_static(__FUNCTION__, []);
foreach ($subexps as $subexp) {
if ((preg_match('/^([^=]+)\=([^"]*)$/', $subexp, $rx) || preg_match('/^([^=]+)\="(.*)"$/', $subexp, $rx)) && array_key_exists(trim($rx[1]), $keys)) {
$indexes[trim($rx[1])] = trim($rx[2]);
}
else {
$return[] = $subexp;
}
}
// Reappend unknown stuff.
if (count($return)) {
return " and (" . implode(' and ', $return) . ")";
}
return "";
}
/**
* Search conditions callback.
*/
function ting_search_conditions_callback($keys) {
$conditions = array();
if (!empty($_REQUEST['keys'])) {
$conditions['keys'] = check_plain($_REQUEST['keys']);
}
if (!empty($_REQUEST['size'])) {
$conditions['size'] = (int) $_REQUEST['size'];
}
if (!empty($_REQUEST['sort'])) {
$conditions['sort'] = check_plain($_REQUEST['sort']);
}
// If facets is set, check if we have to remove any, if so,
// reload the page.
if (!empty($_REQUEST['facets'])) {
$remove = array();
$redirect = FALSE;
foreach ($_REQUEST['facets'] as $key => $facet) {
if (preg_match('/^-facet/', $facet)) {
$remove[] = preg_replace('/^-/', '', $facet);
$redirect = TRUE;
unset($_REQUEST['facets'][$key]);
}
}
foreach ($_REQUEST['facets'] as $key => $facet) {
foreach ($remove as $rem) {
if ($facet == $rem) {
unset($_REQUEST['facets'][$key]);
continue;
}
}
}
$conditions['facets'] = $_REQUEST['facets'];
if ($redirect === TRUE) {
$facets = array();
foreach ($conditions['facets'] as $facet) {
$facets['facets'][] = $facet;
}
drupal_goto(rawurldecode($_GET['q']), array('query' => $facets));
}
}
return $conditions;
}
/**
* Implements hook_search_execute().
*/
function ting_search_search_execute($keys = NULL, $conditions = NULL) {
// TODO: Set sort options
$options = array();
$results = array();
$facet_array = array();
$query = '(' . _ting_search_quote($keys) . ')';
$options['numFacets'] = 25;
module_load_include('client.inc', 'ting');
//Extend query with selected facets
if (isset($conditions['facets']) && $conditions['facets'] != NULL) {
$facets = $conditions['facets'];
foreach ($facets as $facet) {
$facet = explode(':', $facet, 2);
if ($facet[0]) {
$facet_array[] = $facet[0] . '="' . rawurldecode($facet[1]) . '"';
}
}
$query .= ' AND ' . implode(' AND ', $facet_array);
}
try {
$page = pager_find_page();
$results_per_page = variable_get('ting_search_results_per_page', 10);
if (!empty($conditions['size'])) {
$results_per_page = $conditions['size'];
}
if (!empty($conditions['sort'])) {
$options['sort'] = $conditions['sort'];
}
if (module_exists('ting')) {
$search_result = ting_do_search($query, $page + 1, $results_per_page, $options);
if (!is_a($search_result, 'TingSearchResult')) {
throw new TingClientException('Not a TingSearchResult');
}
$search_result->setKeyword($keys);
}
else {
watchdog('ting_search', 'Enable ting-module to get searchresults', array(), WATCHDOG_CRITICAL);
$search_result = array();
}
$total_results = $search_result->getTotal();
pager_default_initialize($total_results, $results_per_page);
foreach ($search_result as $object) {
$build = ting_object_view($object, variable_get('ting_search_object_display', 'search_result'));
// Set proper link to result item.
$uri = entity_uri('ting_object', $object);
$results[] = array(
'type' => '',
'user' => '',
'date' => '',
'link' => url($uri['path']),
'title' => $object->getTitle(),
'snippet' => drupal_render($build)
);
}
}
catch (TingClientException $e) {
// TODO: Log the error.
$results = array();
}
drupal_static('ting_search_results', $search_result);
if (module_exists('bibdk_searchhistory')) {
module_invoke('bibdk_searchhistory', 'set_search_results', $keys, $search_result);
}
return $results;
}
/**
* Implements hook_search_page().
*/
function ting_search_search_page($results) {
return array(
'#theme' => 'ting_search_results',
'#results' => $results,
'#module' => 'ting_search',
);
}
/**
* Theme a mini pager with only first, previous and next links.
*/
function theme_ting_search_mini_pager($variables) {
$tags = $variables['tags'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$quantity = $variables['quantity'];
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
$li_previous = theme('pager_previous', array('text' => (isset($tags[1]) ? $tags[1] : t('‹ previous')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
if (empty($li_previous)) {
$li_previous = " ";
}
$li_first = theme('pager_first', array('text' => (isset($tags[0]) ? $tags[0] : t('« first')), 'element' => $element, 'parameters' => $parameters));
if (empty($li_first)) {
$li_first = " ";
}
$li_next = theme('pager_next', array('text' => (isset($tags[3]) ? $tags[3] : t('next ›')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
if (empty($li_next)) {
$li_next = " ";
}
if ($pager_total[$element] > 1) {
$items[] = array(
'class' => array('pager-first'),
'data' => $li_first,
);
$items[] = array(
'class' => array('pager-previous'),
'data' => $li_previous,
);
$items[] = array(
'class' => array('pager-next'),
'data' => $li_next,
);
return theme('item_list', array('items' => $items, 'type' => 'ul', 'attributes' => array('class' => array('pager'))));
}
}
/**
* Implements hook_block_info().
*/
function ting_search_block_info() {
$blocks['sort-form'] = array(
'info' => t('Ting search "sort by" form'),
'cache' => DRUPAL_CACHE_PER_PAGE,
);
$blocks['records-per-page'] = array(
'info' => t('Ting search "records per page"'),
'cache' => DRUPAL_CACHE_PER_PAGE,
);
$blocks['search-display-extended-query'] = array(
'info' => t('Ting search extended query display'),
'cache' => DRUPAL_CACHE_PER_PAGE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function ting_search_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'sort-form':
drupal_add_css(drupal_get_path('module', 'ting_search') . '/ting_search_extendform.css');
drupal_add_js(drupal_get_path('module', 'ting_search') . '/ting_search_extendform.js');
$block['subject'] = t('Ting search sort controls');
$block['content'] = drupal_get_form('ting_search_sort_form');
break;
case 'records-per-page':
drupal_add_css(drupal_get_path('module', 'ting_search') . '/ting_search_extendform.css');
drupal_add_js(drupal_get_path('module', 'ting_search') . '/ting_search_extendform.js');
$block['subject'] = t('Ting search records per page controls');
$block['content'] = records_per_page_controls_content();
break;
case 'search-display-extended-query':
drupal_add_css(drupal_get_path('module', 'ting_search') . '/ting_search_extendform.css');
drupal_add_js(drupal_get_path('module', 'ting_search') . '/ting_search_extendform.js');
$block['content'] = theme('ting_search_display_extended_query', array('query_label' => t('Your query:'), 'query_string' => NULL));
break;
}
return $block;
}
function search_extend_content() {
return drupal_get_form('search_extend_form');
}
/**
* Create form for sorting search result
*/
function ting_search_sort_form($form_state) {
$form['sort'] = array(
'#title' => t('Sort by:'),
'#type' => 'select',
'#default_value' => isset($_GET['sort']) ? check_plain($_GET['sort']) : '',
'#options' => array(
'' => t('Ranking'),
'title_ascending' => t('Title (Ascending)'),
'title_descending' => t('Title (Descending)'),
'creator_ascending' => t('Creator (Ascending)'),
'creator_descending' => t('Creator (Descending)'),
'date_ascending' => t('Date (Ascending)'),
'date_descending' => t('Date (Descending)'),
'acquisitionDate_ascending' => t('Acquisition date (Ascending)'),
'acquisitionDate_descending' => t('Acquisition date (Descending)'),
),
'#description' => t('Set sort order for search result'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Sort'),
'#states' => array(
'visible' => array(':input[name="op"]' => array('value' => '', ), ),
),
);
return $form;
}
/**
* Process submitted data for sorting order form
*/
function ting_search_sort_form_submit($form, &$form_state) {
$query = drupal_get_query_parameters();
if (isset($form_state['input']['sort'])) {
$query = array('sort' => $form_state['input']['sort']) + $query;
}
$form_state['redirect'] = array($_GET['q'], array('query' => $query, ), );
}
/**
* Create links for changing how many records per page
*/
function records_per_page_controls_content() {
$sizes = array(
'10' => t('10'),
'25' => t('25'),
'50' => t('50'),
);
$size = array();
$size['#type'] = 'markup';
$size['#prefix'] = '<div id="ting-search-records-per-page">' . t('Results on page:');
$size['#suffix'] = '</div>';
$size['#markup'] = '';
foreach ($sizes as $number => $text) {
$pg = array('page' => 0);
$sz = array('size' => $number);
$classes = array();
$keys = array_keys($sizes);
if (isset($_GET['size']) && $_GET['size'] == $number) {
$classes += array('selected');
}
elseif ((!isset($_GET['size']) || !in_array($_GET['size'], $sizes)) && $number == $keys[0]) {
$classes += array('selected');
}
$size['#markup'] .= l($text, $_GET['q'], array(
'query' => $sz + $pg + drupal_get_query_parameters(),
'attributes' => array('class' => $classes, ),
));
}
return $size;
}
/**
* Process a block search form submission.
*/
function ting_search_submit($form, &$form_state) {
$controls = array();
// The search form relies on control of the redirect destination for its
// functionality, so we override any static destination set in the request,
// for example by drupal_access_denied() or drupal_not_found()
// (see http://drupal.org/node/292565).
if (isset($_GET['destination'])) {
unset($_GET['destination']);
}
$form_id = $form['form_id']['#value']; // 'search_block_form'
$keys = $form_state['values'][$form_id];
$keys = str_replace(array('(', ')', '[', ']'), array('\(', '\)', '\[', '\]'), $keys);
$fields = array();
$extended_fields = array(
'creator' => 'term.creator',
'title' => 'term.title',
'subject' => 'term.subject',
);
foreach ($extended_fields as $name => $index) {
if (!empty($form_state['values'][$name])) {
$value = $form_state['values'][$name];
$fields[] = $index . '=' . (strpos($value, ' ') ? '"' . $value . '"' : $value);
}
}
$q = array();
if (!empty($keys)) {
$q[] = $keys;
}
if (!empty($fields)) {
$q[] = '(' . implode(' AND ', $fields) . ')';
}
$q = join(' AND ', $q);
$s = $form_state['values']['sort'];
if ($s != "") {
$controls['sort'] = $s;
}
$s = $form_state['values']['size'];
if ($s != "") {
$controls['size'] = $s;
}
// Check to see if the form was submitted empty.
// If it is empty, display an error message.
// (This method is used instead of setting #required to TRUE for this field
// because that results in a confusing error message. It would say a plain
// "field is required" because the search keywords field has no title.
// The error message would also complain about a missing #title field.)
if ($q == '') {
form_set_error('keys', t('Please enter some keywords.'));
}
$search_info = array();
$request_path = arg();
if ($request_path[0] != 'search' || !isset($request_path[1])) {
$search_info = search_get_default_module_info();
}
else {
foreach (search_get_info() as $search_engine) {
if ($search_engine['path'] == $request_path[1]) {
$search_info = $search_engine;
break;
}
}
}
if (!empty($search_info['path']) && in_array($search_info['module'], variable_get('search_active_modules', array()))) {
$form_state['redirect'] = FALSE;
$url = 'search/' . $search_info['path'] . '/' . trim($q);
drupal_goto($url, array('query' => $controls));
}
else {
form_set_error(NULL, t('Search is currently disabled.'), 'error');
}
}
/**
* Make a search query strict cql.
* check if string is valid cql. if not make it valid.
*
* examples,
* hest hund -> hest and hund (invalid cql. words are and'ed )
* "hest" or "hund" -> "hest" or "hund" (valid cql) nothing is done
* "hest or hund" -> "hest or hund". (valid cql) search for full phrase
*
* @see _ting_search_string_to_cql, _ting_search_convert_string_to_cql, _ting_search_string_is_cql
*/
function _ting_search_quote($string) {
$ret = _ting_search_string_to_cql($string);
return $ret;
}
/** Method to convert a string to strict cql (Basically by adding quotes when needed)
* @param $string
* @return string
*/
function _ting_search_string_to_cql($string) {
if (isset($string) && !_ting_search_string_is_cql($string)) {
$string = _ting_search_convert_string_to_cql($string);
}
return $string;
}
/** Add quotes to string and escapes existing quotes
* @param $string
* @return string
*/
function _ting_search_convert_string_to_cql($string) {
// Escape quotes
$string = str_replace('"', '\"', $string);
// remove multiple whitespaces
$string = preg_replace('/\s+/', ' ', $string);
// explode string by whitespace
$expressions = explode(' ', $string);
// join expressions with 'and' operator
return implode(' and ', $expressions);
}
/** Tests if a string is cql
* @param $string
* @return bool|int
*/
function _ting_search_string_is_cql($string) {
if (strpos($string, '"') !== FALSE && (!preg_match('@ and | or | not |=@', $string) && !(substr($string, 0, 1) === '"' && substr($string, -1) === '"'))) {
return FALSE;
}
return preg_match('@"|\(|\)|=@', $string);
}
/**
* Implements hook_ding_entity_buttons().
*
* Add "permalink" and "show info" buttons.
*/
function ting_search_ding_entity_buttons($type, $entity, $newsearch) {
if (!is_object($entity)) {
return array();
}
drupal_add_library('system', 'ui.dialog');
$options = array('absolute' => true);
$url = url('search/ting/' . $entity->getAcIdentifier(), $options);
$permalink_markup = array(
'#theme' => 'link',
'#text' => ' <i class="icon-white icon-flag"></i> ',
'#path' => $url,
'#options' => array(
'attributes' => array(
'class' => array(
'btn',
'permalink',
'btn-artesis-turquoise',
),
'title' => t('Permalink'),
'data-title' => $entity->getTitle(),
'data-creators' => implode(', ', $entity->getCreators()),
),
'html' => TRUE,
),
'#weight' => 101,
);
$show_markup = array(
'#theme' => 'link',
'#text' => '<i class="icon-plus"></i> ' . t('Show info'),
'#path' => $newsearch ? $url : current_path(),
'#options' => array(
'attributes' => array(
'class' => array(
'btn',
'show-info',
'btn-artesis-blue',
),
),
'html' => TRUE,
),
'#weight' => 100,
);
$hide_markup = $show_markup;
$hide_markup['#text'] = '<i class="icon-minus"></i> ' . t('Hide info');
$hide_markup['#options']['attributes']['class'] = array(
'btn',
'hide-info',
'btn-artesis-blue',
'hidden',
);
$hide_markup['#weight'] = 101;
return array($permalink_markup, $show_markup, $hide_markup);
}