-
Notifications
You must be signed in to change notification settings - Fork 0
/
eagle-search.php
1507 lines (1301 loc) · 78.1 KB
/
eagle-search.php
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
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Eagle Search Inscriptions
Plugin URI: http://www.googate.it/eagle-search-inscriptions
Description: This plugin implements a search inscription engine from CNR Solr database
Author: Michele Del Giudice
Author URI: http://www.googate.it
Version: 1.0
License: GPL2
Text Domain: eagle-search
Copyright 2014 Michele Del Giudice (email : michele@fedece.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'settings.php';
global $esi_db_version;
global $esi_script_onload;
$esi_db_version = "1.0";
function esi_database_install() {
global $wpdb;
global $esi_db_version;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "esi_query";
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
query_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
user_id INT NOT NULL ,
query_type VARCHAR( 6 ) NOT NULL ,
query TEXT NOT NULL ,
page_number SMALLINT UNSIGNED NOT NULL ,
tot_page_saved TINYINT UNSIGNED NOT NULL ,
title VARCHAR( 80 ) NOT NULL ,
comment TEXT NOT NULL,
resource VARCHAR( 256 ) NOT NULL ,
data DATETIME NOT NULL
) ENGINE = INNODB;";
dbDelta($sql);
$table_name = $wpdb->prefix . "esi_eagle_instance";
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
eagle_instance_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
user_id INT NOT NULL ,
col TINYINT UNSIGNED NOT NULL ,
row TINYINT UNSIGNED NOT NULL ,
resource VARCHAR( 256 ) NOT NULL ,
data DATETIME NOT NULL ,
comment TEXT NOT NULL ,
title VARCHAR( 80 ) NOT NULL
) ENGINE = INNODB";
dbDelta($sql);
//
// $sql = "ALTER TABLE $table_name ADD INDEX (eagle_object_id)";
// dbDelta($sql);
// $sql = "ALTER TABLE $table_name ADD FOREIGN KEY (eagle_object_id) REFERENCES wp_esi_eagle_object (eagle_object_id) ON DELETE CASCADE ON UPDATE NO ACTION ;";
// dbDelta($sql);
add_option("esi_db_version", $esi_db_version);
flush_rewrite_rules(true);
}
register_activation_hook(__FILE__, 'esi_database_install');
function esi_database_uninstall() {
// global $wpdb;
// global $esi_db_version;
//
// $table_name = $wpdb->prefix . "esi_eagle_object";
// $sql = "DROP TABLE $table_name";
// $wpdb->query($sql);
//
// $table_name = $wpdb->prefix . "esi_query_result_page";
// $sql = "DROP TABLE $table_name";
// $wpdb->query($sql);
// $table_name = $wpdb->prefix . "esi_eagle_instance";
// $sql = "DROP TABLE $table_name";
// $wpdb->query($sql);
//
// $table_name = $wpdb->prefix . "esi_query";
// $sql = "DROP TABLE $table_name";
// $wpdb->query($sql);
//
// delete_option($esi_db_version);
flush_rewrite_rules(true);
}
register_uninstall_hook(__FILE__, 'esi_database_uninstall');
function esi_process_shortcode($atts = null) {
global $languages;
$defaultAttrVal = array("page_name" => "basic search", "preload" => "undefined");
extract(shortcode_atts($defaultAttrVal, $atts, 'esi_shortcode'));
if ($page_name === "basic search") {
require_once __DIR__ . '/class/localVocabularyParser.php';
wp_enqueue_script('jquery', '/wp-content/plugins/eagle-search/js/jquery-1.10.1.min.js');
wp_enqueue_script('lightbox', '/wp-content/plugins/eagle-search/js/lightbox.min.js');
wp_enqueue_script('eagle-search', '/wp-content/plugins/eagle-search/js/search.js');
wp_enqueue_style('lightboxstyle', '/wp-content/plugins/eagle-search/css/lightbox.css');
/* keyboard required */
wp_enqueue_style('jqueryuistyle', '/wp-content/plugins/eagle-search/css/jquery-ui.min.css');
wp_enqueue_style('mykeyboard', '/wp-content/plugins/eagle-search/css/mykeyboard.css');
wp_enqueue_script('jqueryui', '/wp-content/plugins/eagle-search/js/jquery-ui.js', array('jquery'));
wp_enqueue_script('mykeyboard', '/wp-content/plugins/eagle-search/js/mykeyboard.js', array('jqueryui'));
/* Preset */
wp_enqueue_script('preset', '/wp-content/plugins/eagle-search/js/preset.js');
wp_enqueue_style('esi-style', '/wp-content/plugins/eagle-search/css/simple-search.css');
$menu = '<ul class="menu-search"><li class="left selected"><a class="selected" href="/basic-search">basic search</a></li><li class="left"><a href="/advanced-search">advanced search</a></li><li class="left"><a href="/image-search">image search</a></li><li class="left"><a href="/archives">archives</a></li></ul>';
//$datingCriteria = new localVocabularyParser("datingvoc");
$objectType = new localVocabularyParser("objecttypevoc");
$typeOfInscription = new localVocabularyParser("inscriptiontypevoc");
$material = new localVocabularyParser("materialvoc");
$decoration = new localVocabularyParser("decorationvoc");
$state = new localVocabularyParser("stateofpreservationvoc");
$writing = new localVocabularyParser("writingtypevoc");
$js = '<script type="text/javascript">jQuery(document).ready(function() {';
// $js.='Search.advFacetCache["datingvoc"]=' . json_encode($datingCriteria->getVocabolaryAssocWithName()) . ';';
$js.='Search.advFacetCache["objecttypevoc"]=' . json_encode($objectType->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["inscriptiontypevoc"]=' . json_encode($typeOfInscription->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["materialvoc"]=' . json_encode($material->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["decorationvoc"]=' . json_encode($decoration->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["stateofpreservationvoc"]=' . json_encode($state->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["writingtypevoc"]=' . json_encode($writing->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$generic_true_false_voc_choice = array();
$generic_true_false_voc_choice[] = array("vocLabel" => "No", "vocValue" => "false");
$generic_true_false_voc_choice[] = array("vocLabel" => 'Yes', "vocValue" => "true");
$js.='Search.advFacetCache["hasimage"]=' . json_encode(array_merge(array("vocName" => "hasimage"), $generic_true_false_voc_choice)) . ';';
$js.='Search.advFacetCache["hastranslation"]=' . json_encode(array_merge(array("vocName" => "hastranslation"), $generic_true_false_voc_choice)) . ';';
$js.='});</script>';
$jsOnLoad = '<script type="text/javascript">jQuery(window).load(function() {';
if ($preload != 'undefined' && $preload != '') {
$decoded = urldecode($preload);
parse_str($decoded, $parsed_request);
if (!array_key_exists('fields', $parsed_request)) {
$jsOnLoad.='Search.bookmarkSimple("' . $parsed_request['query'] . '","' . $parsed_request['page'] . '","' . $parsed_request['entity'] . '","' . urlencode($parsed_request['facet']) . '","' . $parsed_request['artifactSelectedRow'] . '","' . $parsed_request['artifactSelectedCol'] . '");';
} else {
$jsOnLoad.='Search.bookmarkSimple("' . $parsed_request['query'] . '","' . $parsed_request['page'] . '","' . $parsed_request['entity'] . '","' . urlencode($parsed_request['facet']) . '","' . $parsed_request['artifactSelectedRow'] . '","' . $parsed_request['artifactSelectedCol'] . '","' . urlencode($parsed_request['fields']) . '");';
}
}
$jsOnLoad.='});</script>';
$languageHtml = '<select id="lang" onchange="Search.advFacetCacheRefresh();" class="search-element select">';
$languageHtml.='<option selected="selected" value="null" >Default Language</option>';
foreach ($languages as $language) {
$languageHtml.='<option value="' . $language['iso'] . '" >' . $language['name'] . '</option>';
}
// $imgUploadSearch = '<div class="img_search_cont"><label>Search by Image</label><br/><input type="file" name="img_search" id="img_search" /><button onclick="Search.searchByImage()" >Image Search</button></div>';
// $polytonic = '<table class="policont"><tr><td class="label">Greek keyboard</td><td><input type="checkbox" class="search-element checkbox" id="politonic_enable" /></td><td whidth="300"><button class="action-button" type="button" onclick="Search.simpleSearchAll();">Browse All</button></td><td>' . $languageHtml . '</td></tr></table>';
// $polytonic = '<table class="policont"><tr><td><input type="checkbox" class="search-element checkbox" id="politonic_enable" /></td><td class="label">Greek keyboard</td><td class="label">Include substrings (search might take more time)</td><td><input type="checkbox" class="search-element checkbox" id="ckstring" /></td></tr><tr><td><input type="checkbox" class="search-element checkbox" id="hebrew_enable" disabled /></td><td class="label">Hebrew keyboard</td><td whidth="300"><button class="action-button" type="button" onclick="Search.simpleSearchAll();">Browse All</button></td></tr></table>';
$polytonic = '<table class="policont"><tr><td><input type="checkbox" class="search-element checkbox" id="ckstring" /></td><td colspan="3" class="label">Include substrings (search might take more time)</td></tr><tr><td ><input data-keylanguage="greek" type="checkbox" class="search-element checkbox keySwitcher" id="politonic_enable" /></td><td class="label">Greek keyboard</td><td><input data-keylanguage="hebrew" type="checkbox" class="search-element checkbox keySwitcher" id="hebrew_enable" /></td><td class="label">Hebrew keyboard</td></tr></table>';
$browseAll = '<h5 class="resultCount">Type a keyword and press ENTER, or <a onclick="Search.simpleSearchAll();" class="" href="#">browse all the EAGLE collections</a></h5>';
$buttonHelp ='<button onclick="Search.showHelp();" class="help-button" id="send">?</button>';
$research = '<div class="search-padder">' . $browseAll . '<div class="search-box"><img onclick="Search.simpleSearch(event,\'artifact\');" class="lente" src="' . plugins_url('img/lente.png', __FILE__) . '" /><input class="politonic" onkeydown="Search.simpleSearch(event,\'artifact\');" type="text" placeholder="Search free text" value="" name="mysearch" id="mysearch" />'.$buttonHelp .'</div>' . $polytonic . $imgUploadSearch .'</div>' . $js.$jsOnLoad;
} else if ($page_name === "advanced search") {
require_once __DIR__ . '/class/localVocabularyParser.php';
/* Make instance of each required vocabolary */
//$datingCriteria = new localVocabularyParser("datingvoc");
$objectType = new localVocabularyParser("objecttypevoc");
$typeOfInscription = new localVocabularyParser("inscriptiontypevoc");
$material = new localVocabularyParser("materialvoc");
$decoration = new localVocabularyParser("decorationvoc");
$state = new localVocabularyParser("stateofpreservationvoc");
$writing = new localVocabularyParser("writingtypevoc");
/* Enqueue required script */
wp_enqueue_script('jquery', '/wp-content/plugins/eagle-search/js/jquery-1.10.1.min.js');
wp_enqueue_script('lightbox', '/wp-content/plugins/eagle-search/js/lightbox.min.js');
wp_enqueue_script('eagle-search', '/wp-content/plugins/eagle-search/js/search.js');
wp_enqueue_style('lightboxstyle', '/wp-content/plugins/eagle-search/css/lightbox.css');
wp_enqueue_script('preset', '/wp-content/plugins/eagle-search/js/preset.js');
wp_enqueue_style('esi-style', '/wp-content/plugins/eagle-search/css/adv-search.css');
/* keyboard required */
wp_enqueue_style('jqueryuistyle', '/wp-content/plugins/eagle-search/css/jquery-ui.min.css');
wp_enqueue_style('mykeyboard', '/wp-content/plugins/eagle-search/css/mykeyboard.css');
wp_enqueue_script('jqueryui', '/wp-content/plugins/eagle-search/js/jquery-ui.js', array('jquery'));
wp_enqueue_script('mykeyboard', '/wp-content/plugins/eagle-search/js/mykeyboard.js', array('jqueryui'));
/* JS caching advFields */
$js = '<script type="text/javascript">jQuery(document).ready(function() {';
// $js.='Search.advFacetCache["notbefore"]=' . json_encode($datingCriteria->getVocabolaryAssocWithName()) . ';';
$js.='Search.advFacetCache["objecttypevoc"]=' . json_encode($objectType->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["inscriptiontypevoc"]=' . json_encode($typeOfInscription->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["materialvoc"]=' . json_encode($material->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["decorationvoc"]=' . json_encode($decoration->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["stateofpreservationvoc"]=' . json_encode($state->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$js.='Search.advFacetCache["writingtypevoc"]=' . json_encode($writing->getVocabolaryAssocWithName(SORT_STRING)) . ';';
$generic_true_false_voc_choice = array();
$generic_true_false_voc_choice[] = array("vocLabel" => "No", "vocValue" => "false");
$generic_true_false_voc_choice[] = array("vocLabel" => 'Yes', "vocValue" => "true");
$js.='Search.advFacetCache["hasimage"]=' . json_encode(array_merge(array("vocName" => "hasimage"), $generic_true_false_voc_choice)) . ';';
$js.='Search.advFacetCache["hastranslation"]=' . json_encode(array_merge(array("vocName" => "hastranslation"), $generic_true_false_voc_choice)) . ';';
// $js.='});</script>';
/* Make internal menu */
//$menu = '<ul class="menu-search"><li class="left"><a href="/basic-search">basic search</a></li><li class="left selected"><a class="selected" href="/advanced-search">advanced search</a></li><li class="left"><a href="/image-search">image search</a></li><li class="left"><a href="/archives">archives</a></li></ul>';
/* Append research box */
$research = '<div class="search-padder">';
$research.='<textarea placeholder="Text of the inscription" onkeydown="Search.advKeySearch(event);" onclick="Search.resetAdvTextarea(this);" class="search-element textareat" name="inscriptiontext" ></textarea> <button onclick="Search.showHelp();" class="help-button" valign="top" id="send">?</button><br/>';
$research.='<select onkeydown="Search.advKeySearch(event);" class="search-element select" name="objecttypevoc" >';
$research.='<option selected="selected" value="" >Object type</option>';
$data = $objectType->getVocabolaryData(SORT_REGULAR);
$js.='Search.advFieldCache["objecttypevoc"]=' . json_encode($data) . ';';
foreach ($data as $objT) {
$research.='<option value="' . $objT['vocValue'] . '" >' . $objT['vocLabel'] . '</option>';
}
$research.='</select><br/>';
$research.='<input type="text" placeholder="Ancient findspot" onkeydown="Search.advKeySearch(event);" onclick="Search.resetAdvText(this);" class="search-element input" name="ancientfindspot" value="" /><br/>';
$research.='<select onkeydown="Search.advKeySearch(event);" class="search-element select" name="inscriptiontypevoc" >';
$research.='<option selected="selected" value="" >Type of inscription</option>';
$data = $typeOfInscription->getVocabolaryData(SORT_REGULAR);
$js.='Search.advFieldCache["inscriptiontypevoc"]=' . json_encode($data) . ';';
foreach ($data as $objT) {
$research.='<option value="' . $objT['vocValue'] . '" >' . $objT['vocLabel'] . '</option>';
}
$research.='</select><br/>';
// $research.='<select class="search-element select" name="notbefore" >';
// $research.='<option selected="selected" value="" >Not Before</option>';
// $data = $datingCriteria->getVocabolaryData(SORT_REGULAR);
// //var_dump($data); die();
// $js.='Search.advFieldCache["notbefore"]=' . json_encode($data) . ';';
// foreach ($data as $objT) {
// $research.='<option value="' . $objT['vocValue'] . '" >' . $objT['vocLabel'] . '</option>';
// }
// $research.='</select><br/>';
$research.='<textarea placeholder="Bibliography" onkeydown="Search.advKeySearch(event);" onclick="Search.resetAdvTextarea(this);" class="search-element textareab" name="bibliography" ></textarea><br/>';
$research.='<table><tr><td><input type="checkbox" class="search-element checkbox" name="hasimage" value="" /></td><td class="label">Only with image</td></tr></table>';
$research.='<table><tr><td><input type="checkbox" class="search-element checkbox" name="hastranslation" value="" /></td><td class="label">Only with translation</td></tr></table>';
$research.='<input type="text" placeholder="Not Before - Year" onkeydown="Search.advKeySearch(event);" onclick="Search.resetAdvTextarea(this);" type="text" class="search-element input date" name="notbefore" value="" /><br/>';
$research.='<input type="text" placeholder="Not After - Year" onkeydown="Search.advKeySearch(event);" onclick="Search.resetAdvTextarea(this);" type="text" class="search-element input date" name="notafter" value="" /><br/>';
$research.='<div id="fieldsAppender"></div>';
$research.='<table class="policont"><tr><td><input type="checkbox" class="search-element checkbox" name="ckstringadv" /></td><td colspan="3" class="label">Include substrings (search might take more time)</td></tr></table>';
$research.='<button onclick="Search.advSearch(\'documental\');" class="action-button" id="send">Search</button>';
$research.='</div>';
$js.='});</script>';
$jsOnLoad = '<script type="text/javascript">jQuery(window).load(function() {';
if ($preload != 'undefined' && $preload != '') {
$decoded = urldecode($preload);
parse_str($decoded, $parsed_request);
// var_dump($parsed_request['fields']); die();
$jsOnLoad.='Search.bookmarkAdvanced("' . $parsed_request['query'] . '","' . urlencode($parsed_request['fields']) . '","' . $parsed_request['page'] . '","' . $parsed_request['entity'] . '","' . $parsed_request['artifactSelectedRow'] . '","' . $parsed_request['artifactSelectedCol'] . '","' . urlencode($parsed_request['facet']) . '");';
}
$jsOnLoad.='});</script>';
$research.=$js.$jsOnLoad;
} else if ($page_name === "archives") {
wp_enqueue_script('jquery', '/wp-content/plugins/eagle-search/js/jquery-1.10.1.min.js');
wp_enqueue_script('lightbox', '/wp-content/plugins/eagle-search/js/lightbox.min.js');
wp_enqueue_script('eagle-search', '/wp-content/plugins/eagle-search/js/search.js');
wp_enqueue_style('lightboxstyle', '/wp-content/plugins/eagle-search/css/lightbox.css');
wp_enqueue_script('preset', '/wp-content/plugins/eagle-search/js/preset.js');
wp_enqueue_style('esi-style', '/wp-content/plugins/eagle-search/css/archives.css');
wp_enqueue_style('esi-style', '/wp-content/plugins/eagle-search/css/simple-search.css');
/* keyboard required */
wp_enqueue_style('jqueryuistyle', '/wp-content/plugins/eagle-search/css/jquery-ui.min.css');
wp_enqueue_style('mykeyboard', '/wp-content/plugins/eagle-search/css/mykeyboard.css');
wp_enqueue_script('jqueryui', '/wp-content/plugins/eagle-search/js/jquery-ui.js', array('jquery'));
wp_enqueue_script('mykeyboard', '/wp-content/plugins/eagle-search/js/mykeyboard.js', array('jqueryui'));
$research = '';
$menu = '<ul class="menu-search arcmenu"><li class="left selected" onclick="Search.archivesRelist(\'results\',0);">Search results</li><li class="left" onclick="Search.archivesRelist(\'items\',0);">Single items</li></ul>';
$submenu = '';
$table = '<div id="archivesCont"><table class="tableArchives"><tr><td>You must be logged in to access this section</td></tr>';
if (is_user_logged_in()) {
require_once __DIR__ . '/class/EagleSaveSystem.php';
$dbRow = EagleSaveSystem::getLastResearchSaved(get_current_user_id());
$submenu = '<ul class="archivesSubMenu"><li onclick="Search.archiveSelectAll();" class="left">Check All</li><li onclick="Search.archiveDeselectAll();" class="left">Uncheck All</li><li class="left selected"><button class="action-button" type="button" onclick="Search.deleteAllArchives();">Delete</button></li></ul>';
$table = '<div id="archivesCont"><table class="tableArchives"><thead><tr><th>Checked</th><th>Title</th><th>Date</th><th>Actions</th></tr></thead>';
$index = 0;
if (count($dbRow) > 0) {
foreach ($dbRow as $row) {
$onclick = ($row->query_type == "string:similarity" || $row->query_type == "string:recognize") ? 'Search.archivesSimilarityView(\'results\',' . $row->query_id . ',event);' : 'Search.archivesView(\'results\',' . $row->query_id . ',event);';
$table.='<tr id="row' . $index . '" class="row' . ($index % 2) . '"><td><input tableid="' . $row->query_id . '" mytype="results" type="checkbox" value="' . $row->query_id . '" /></td><td>' . $row->title . '</td><td class="date">' . $row->data . '</td><td><button class="action-button" type="button" onclick="Search.archivesDelete(\'results\',' . $row->query_id . ',' . $index . ');">Delete</button><button class="action-button" type="button" onclick="Search.archivesModify(\'results\',' . $row->query_id . ',' . $index . ');">Edit</button><button class="action-button" type="button" onclick="' . $onclick . '">View</button></td></tr>';
$index++;
}
} else {
$table = '<div id="archivesCont"><table class="tableArchives"><tr><td>No result Found</td></tr>';
}
}
$table.='</table></div>';
$research = $table . $submenu;
} elseif ($page_name === "image-search") {
require_once __DIR__ . '/class/localVocabularyParser.php';
wp_enqueue_script('jquery', '/wp-content/plugins/eagle-search/js/jquery-1.10.1.min.js');
wp_enqueue_script('lightbox', '/wp-content/plugins/eagle-search/js/lightbox.min.js');
wp_enqueue_script('eagle-search', '/wp-content/plugins/eagle-search/js/search.js');
wp_enqueue_style('lightboxstyle', '/wp-content/plugins/eagle-search/css/lightbox.css');
/* keyboard required */
wp_enqueue_style('jqueryuistyle', '/wp-content/plugins/eagle-search/css/jquery-ui.min.css');
wp_enqueue_style('mykeyboard', '/wp-content/plugins/eagle-search/css/mykeyboard.css');
wp_enqueue_script('jqueryui', '/wp-content/plugins/eagle-search/js/jquery-ui.js', array('jquery'));
wp_enqueue_script('mykeyboard', '/wp-content/plugins/eagle-search/js/mykeyboard.js', array('jqueryui'));
/* Preset */
wp_enqueue_script('preset', '/wp-content/plugins/eagle-search/js/preset.js');
wp_enqueue_style('esi-style', '/wp-content/plugins/eagle-search/css/simple-search.css');
$menu = '<ul class="menu-search"><li class="left"><a class="selected" href="/basic-search">basic search</a></li><li class="left"><a href="/advanced-search">advanced search</a></li><li class="left selected"><a href="/image-search">image search</a></li><li class="left"><a href="/archives">archives</a></li></ul>';
$js = '';
// $objectType = new localVocabularyParser("objecttypevoc");
// $typeOfInscription = new localVocabularyParser("inscriptiontypevoc");
// $material = new localVocabularyParser("materialvoc");
// $decoration = new localVocabularyParser("decorationvoc");
// $state = new localVocabularyParser("stateofpreservationvoc");
// $writing = new localVocabularyParser("writingtypevoc");
//$js = '<script type="text/javascript">jQuery(document).ready(function() {';
// // $js.='Search.advFacetCache["datingvoc"]=' . json_encode($datingCriteria->getVocabolaryAssocWithName()) . ';';
// $js.='Search.advFacetCache["objecttypevoc"]=' . json_encode($objectType->getVocabolaryAssocWithName()) . ';';
// $js.='Search.advFacetCache["inscriptiontypevoc"]=' . json_encode($typeOfInscription->getVocabolaryAssocWithName()) . ';';
// $js.='Search.advFacetCache["materialvoc"]=' . json_encode($material->getVocabolaryAssocWithName()) . ';';
// $js.='Search.advFacetCache["decorationvoc"]=' . json_encode($decoration->getVocabolaryAssocWithName()) . ';';
// $js.='Search.advFacetCache["stateofpreservationvoc"]=' . json_encode($state->getVocabolaryAssocWithName()) . ';';
// $js.='Search.advFacetCache["writingtypevoc"]=' . json_encode($writing->getVocabolaryAssocWithName()) . ';';
// $generic_true_false_voc_choice = array();
// $generic_true_false_voc_choice[] = array("vocLabel" => "No", "vocValue" => "false");
// $generic_true_false_voc_choice[] = array("vocLabel" => 'Yes', "vocValue" => "true");
// $js.='Search.advFacetCache["hasimage"]=' . json_encode(array_merge(array("vocName" => "hasimage"), $generic_true_false_voc_choice)) . ';';
// $js.='Search.advFacetCache["hastranslation"]=' . json_encode(array_merge(array("vocName" => "hastranslation"), $generic_true_false_voc_choice)) . ';';
// $js.='});</script>';
$imgUploadSearch = '<div class="img_search_cont"><h4>Search by Image</h4><br/><input type="file" name="img_search" id="img_search" /><button class="action-button" onclick="Search.searchByImage()" >Search</button></div>';
//$polytonic = '<table class="policont"><tr><td class="label">Greek keyboard</td><td><input type="checkbox" class="search-element checkbox" id="politonic_enable" /></td></tr></table>';
$research = '<div class="search-padder">' . $imgUploadSearch . '</div>' . $js;
}
return $menu . $research;
}
add_shortcode('esi_shortcode', 'esi_process_shortcode');
/* This function make a proxy ajax advanced search request from client interface */
function esi_process_ajax_research($return = false) {
require_once __DIR__ . '/class/EagleSearch.php';
require_once __DIR__ . '/class/localVocabularyParser.php';
$eagle = new EagleSearch();
try {
/* Enable Facet */
//$eagle->addFacetField("datingvoc");
//$eagle->addFacetField("dating");
$eagle->addFacetField("decorationvoc");
$eagle->addFacetField("materialvoc");
$eagle->addFacetField("objecttypevoc");
$eagle->addFacetField("stateofpreservationvoc");
$eagle->addFacetField("inscriptiontypevoc");
$eagle->addFacetField("writingtypevoc");
$eagle->addFacetField("ancientfindspotforbrowsing");
$eagle->addFacetField("modernfindspotforbrowsing");
$eagle->addFacetField("hasimage");
$eagle->addFacetField("hastranslation");
$eagle->addFacetField("repositorynameforbrowsing");
$eagle->setFacetEnabled();
//if (isset($_POST['ckstringadv']))
if ($_POST['ckstringadv'] == 'true')
{
$CkSubStr=1;
}
if (isset($_POST['fields'])) {
$fields = json_decode(stripcslashes($_POST['fields']), true);
$adv = "";
$advq = "";
$dating = array();
if (count($fields)) {
foreach ($fields as $key => $value) {
if ($key === "modernfindspot") {
$advq .= ($advq === "") ? "((modernfindspot:(" . getSubStr($value,$CkSubStr) . "))OR(moderncountry:(" . getSubStr($value,$CkSubStr) . "))OR(modernregion:(" . getSubStr($value,$CkSubStr) . "))OR(modernprovince:(" . getSubStr($value,$CkSubStr) . ")))" : "AND((modernfindspot:(" . getSubStr($value,$CkSubStr) . "))OR(moderncountry:(" . getSubStr($value,$CkSubStr) . "))OR(modernregion:(" . getSubStr($value,$CkSubStr) . "))OR(modernprovince:(" . getSubStr($value,$CkSubStr) . ")))";
} else if ($key === "ancientfindspot") {
$advq .= ($advq === "") ? "((romanprovinceitalicregion:(" . getSubStr($value,$CkSubStr) . "))OR(ancientfindspot:(" . getSubStr($value,$CkSubStr) . ")))" : "AND((romanprovinceitalicregion:(" . getSubStr($value,$CkSubStr) . "))OR(ancientfindspot:(" . getSubStr($value,$CkSubStr) . ")))";
} else if ($key === "location") {
$adv .= ($adv === "") ? "((conservationcountry:(" . getSubStr($value,$CkSubStr) . "))OR(conservationregion:(" . getSubStr($value,$CkSubStr) . "))OR(conservationcity:(" . getSubStr($value,$CkSubStr) . "))OR(museum:(" . getSubStr($value,$CkSubStr) . ")))" : "AND((conservationcountry:(" . getSubStr($value,$CkSubStr) . "))OR(conservationregion:(" . getSubStr($value,$CkSubStr) . "))OR(conservationcity:(" . getSubStr($value,$CkSubStr) . "))OR(museum:(" . getSubStr($value,$CkSubStr) . ")))";
} else if ($key === "inscriptiontext") {
$advq .= ($advq === "") ? "(inscriptiontext:(" . getSubStr($value,$CkSubStr) . "))" : "AND(inscriptiontext:(" . getSubStr($value,$CkSubStr) . "))";
} else if ($key === "bibliography") {
$advq .= ($advq === "") ? "(bibliography:(" . getSubStr($value,$CkSubStr) . "))" : "AND(bibliography:(" . getSubStr($value,$CkSubStr) . "))";
} else if ($key === 'notafter' || $key === 'notbefore') {
$dating[$key] = $value;
} else {
$adv .= ($adv === "") ? "(" . $key . ":" . "\"" . $value . "\"" . ")" : "AND(" . $key . ":" . "\"" . $value . "\"" . ")";
}
}
if (array_key_exists('notbefore', $dating) && array_key_exists('notafter', $dating)) {
// $adv .= ($adv === "") ? "(((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[* TO " . $dating["notafter"] . "]))AND((notbefore:[* TO " . $dating["notbefore"] . "])OR(notafter:[" . $dating["notafter"] . " TO *])))" : "AND(((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[* TO " . $dating["notafter"] . "]))AND((notbefore:[* TO " . $dating["notbefore"] . "])OR(notafter:[" . $dating["notafter"] . " TO *])))";
$adv .= ($adv === "") ? "(((notbefore:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "])OR(notafter:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "])))": "AND(((notbefore:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "])OR(notafter:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "])))";
//nicola ha sostituito or con and $adv .= ($adv === "") ? "(((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[* TO " . $dating["notafter"] . "]))OR((notbefore:[* TO " . $dating["notbefore"] . "])OR(notafter:[" . $dating["notafter"] . " TO *])))" : "AND(((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[* TO " . $dating["notafter"] . "]))OR((notbefore:[* TO " . $dating["notbefore"] . "])OR(notafter:[" . $dating["notafter"] . " TO *])))";
} else if (array_key_exists('notbefore', $dating)) {
$adv .= ($adv === "") ? "((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[" . $dating["notbefore"] . " TO *]))" : "AND((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[" . $dating["notbefore"] . " TO *]))";
} else if (array_key_exists('notafter', $dating)) {
// $adv .= ($adv === "") ? "(((notbefore:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "]))OR((notafter:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "])))" : "AND(((notbefore:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "]))OR((notafter:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "])))";
$adv .= ($adv === "") ? "((notbefore:[* TO " . $dating["notafter"] . "])OR(notafter:[* TO " . $dating["notafter"] . "]))" : "AND((notbefore:[* TO " . $dating["notafter"] . "])OR(notafter:[* TO " . $dating["notafter"] . "]))";
}
}
if (isset($_POST['facet']) && !empty($_POST['facet']))
$result = $eagle->advancedSearch($advq, $adv, $_POST['page'], $_POST['entity'], preg_replace('/^\s*AND\s*/', '', stripcslashes($_POST['facet'])));
else
$result = $eagle->advancedSearch($advq, $adv, $_POST['page'], $_POST['entity']);
} else {
$result = $eagle->simpleSearch($_POST['query'], $_POST['page'], $_POST['entity'], preg_replace('/^\s*AND\s*/', '', stripcslashes($_POST['facet'])));
}
} catch (EagleSearchException $ex) {
$result = json_encode(array("error" => $ex->getMessage()));
}
if ($return)
return $result;
echo $result;
exit();
}
add_action('wp_ajax_esi_process_ajax_research', 'esi_process_ajax_research');
add_action('wp_ajax_nopriv_esi_process_ajax_research', 'esi_process_ajax_research');
add_shortcode('esi_do_proxyimage', 'esi_proxyimage');
function esi_proxyimage() {
$url = $_GET['url'];
// $url="http://laststatues.classics.ox.ac.uk/database/detail-base.php?image=Image_3_Large&recid=545";
// var_dump($url);
// var_dump($_GET['url']);
// die();
$upload_dir = wp_upload_dir();
$upload_dir = $upload_dir['basedir'] . '/proxyimg/';
$imgname = md5($url);
if (!file_exists($upload_dir . $imgname)) {
error_log("File not exists");
/* Request File */
$ch = curl_init();
$timeout = 0;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// Getting binary data
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip,deflate'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$image = curl_exec($ch);
$savefile = fopen($upload_dir . $imgname, 'w');
fwrite($savefile, $image);
fclose($savefile);
curl_close($ch);
}
$size = getimagesize($upload_dir . $imgname);
$fp = fopen($upload_dir . $imgname, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
echo 'An error occurred.';
}
// die();
//
// $ch = curl_init($_GET['url']);
// curl_setopt($ch, CURLOPT_HEADER, 0);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
// $rawdata = curl_exec($ch);
// curl_close($ch);
//
// echo $rawdata;
// die();
//
// $im = imagecreatefromstring(file_get_contents(($_GET['url'])));
// $data = file_get_contents();
// var_dump(urldecode($_GET['url']));
// var_dump($data); die();
// $imgString = base64_decode($data);
//
// $im = imagecreatefromstring($imgString);
// if ($im !== false) {
// header('Content-Type: image/png');
// imagepng($im);
// imagedestroy($im);
// } else {
// echo 'An error occurred.';
// }
// $resource = file_get_contents(urldecode($_GET['url']));
// //$image= imagecreatefromstring ( $resource );
// header('Content-Type: image/jpeg');
// echo $resource;
exit;
}
add_action('wp_ajax_esi_similar_from_dnetresourceid', 'esi_similar_from_dnetresourceid');
add_action('wp_ajax_nopriv_esi_similar_from_dnetresourceid', 'esi_similar_from_dnetresourceid');
function esi_similar_from_dnetresourceid() {
}
add_action('wp_ajax_esi_object_from_dnetresourceid', 'esi_object_from_dnetresourceid');
add_action('wp_ajax_nopriv_esi_object_from_dnetresourceid', 'esi_object_from_dnetresourceid');
function esi_object_from_dnetresourceid() {
require_once __DIR__ . '/class/EagleSearch.php';
$eagle = new EagleSearch();
try {
// var_dump(json_decode(stripslashes($_POST['dnetresourceidentifierList'])));
echo $eagle->getObjectFromDnetResourceIdentifier(json_decode(stripslashes($_POST['dnetresourceidentifierList'])), $_POST['entity']);
} catch (EagleSearchException $ex) {
echo json_encode(array("error" => $ex->getMessage()));
}
exit();
}
add_action('wp_ajax_esi_image_search', 'esi_image_search');
add_action('wp_ajax_nopriv_esi_image_search', 'esi_image_search');
function getCurlValue($filename, $contentType, $postname) {
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
// See: https://wiki.php.net/rfc/curl-file-upload
if (function_exists('curl_file_create')) {
return curl_file_create($filename, $contentType, $postname);
}
// Use the old style if using an older version of PHP
$value = "@$filename;filename=" . $postname;
if ($contentType) {
$value .= ';type=' . $contentType;
}
return $value;
}
function getSubStr($AllStr,$CkSubStr) {
// Nicola Ricevo tutta la stringa e la elaboro
$countquote= substr_count($AllStr, '"');
$retstr="";
$strret="";
if ($CkSubStr===1)
{
//if ($countquote % 2 == 0)
//{
$arr = explode(" ", rtrim(ltrim($AllStr)));
$quoted=0;
for ($i=0 ; $i < count($arr); $i++)
{
$strret = $arr[$i];
switch ($arr[$i])
{
case "OR":
$retstr .= $arr[$i]." ";
break;
case "AND":
$retstr .= $arr[$i]." ";
break;
default:
if (substr($strret, 0, 1)==='"')
{
$retstr.= $arr[$i]." ";
$quoted +=1;
}
else
{
if (strrpos($arr[$i], '"'))
{
$quoted +=1;
$retstr .= $arr[$i]." ";
}
else
{
if ($quoted % 2 === 0)
{
$retstr .= "*".$arr[$i]."*"." ";
}
else
{
$retstr .= $arr[$i]." ";
}
}
}
}
}
//}
$retstr=rtrim(ltrim($retstr));
}
else
{
$retstr=$AllStr;
}
$match = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '~', '?', ':',';');
$replace = array('\\\\', '\\+', '\\-', '\\&&', '\\||', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\?', '\\:','\\;');
$retstr = str_replace($match, $replace, $retstr);
// var_dump($retstr); die();
return $retstr;
}
function esi_image_search() {
$ret = new stdClass();
$ret->error = false;
if (isset($_FILES['image'])) {
require_once __DIR__ . '/class/EagleSearch.php';
$image = $_FILES['image']['tmp_name'];
$imageType = $_FILES['image']['type'];
$imageName = basename($_FILES['image']['name']);
$maxImageNumber = 30;
$cfile = getCurlValue($image, $imageType, $imageName);
// $cfile = curl_file_create($image, $imageType, $imageName);
$postData = array('img' => $cfile, 'nResults' => $maxImageNumber);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, EagleSearch::CNR_SIMILARITY_SEARCH_URL);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
$r = curl_exec($curl);
if (curl_errno($curl)) {
$ret->error = false;
$ret->msg = 'SimilarityAPI_Erros: ' . curl_error($curl);
curl_close($curl);
} else {
curl_close($curl);
$xml = new SimpleXMLElement($r);
$response = array();
foreach ($xml->results->result as $result) {
//$response[]=array("id"=>addslashes($result->id),"thumbnail"=>addslashes($result->thumbnail),"title"=>addslashes($result->title));
$response[] = array("id" => $result->id, "thumbnail" => $result->thumbnail, "title" => $result->title);
}
$ret->results = $response;
}
} else if (isset($_POST['dnetResurceIdentifier'])) {
require_once __DIR__ . '/class/EagleSearch.php';
$request = file_get_contents(EagleSearch::CNR_GET_METADATA_URL . '?id=' . $_POST['dnetResurceIdentifier']);
$xml = new SimpleXMLElement($request);
$response = "";
foreach ($xml->result->doc->children() as $arr) {
if ($arr['name'] == '__result') {
$response = $arr->str;
break;
}
}
$ret->results = $response;
} else if (isset($_POST['dnetResurceIdentifierById'])) {
require_once __DIR__ . '/class/EagleSearch.php';
$request = file_get_contents(EagleSearch::CNR_SIMILARITY_SEARCH_BYID_URL . '?docID=' . $_POST['dnetResurceIdentifierById']);
//file_put_contents(__DIR__.'/logger/'.$_POST['dnetResurceIdentifierById'].'.xml', $request);
try {
$xml = new SimpleXMLElement($request);
$response = array();
foreach ($xml->results->result as $result) {
$response[] = array("id" => $result->id, "thumbnail" => $result->thumbnail, "title" => $result->title);
}
if (count($response))
$ret->results = $response;
else {
$ret->error = true;
$ret->msg = 'No similar image found!';
}
} catch (Exception $e) {
$ret->error = true;
$ret->msg = 'This request : ' . EagleSearch::CNR_SIMILARITY_SEARCH_BYID_URL . '?docID=' . $_POST['dnetResurceIdentifierById'] . ' could not be parsed as XML!';
}
//$ret->results = $request;
} else {
$ret->error = true;
$ret->msg = 'No image uploaded!';
}
echo json_encode($ret);
exit();
}
add_action('wp_ajax_esi_ajax_registration', 'esi_ajax_registration');
add_action('wp_ajax_nopriv_esi_ajax_registration', 'esi_ajax_registration');
function esi_ajax_registration() {
$result = new stdClass();
$result->error = false;
if (isset($_POST['registerFields'])) {
$registration = json_decode(stripcslashes($_POST['registerFields']));
if (!is_null($registration)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "secret=" . urlencode("6LcwsAcTAAAAAAOgXymMrsUMROYbDN8rJcuNSs4p") . "&response=" . urlencode($registration->grecaptcharesponse));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
$server_output = json_decode($server_output);
//var_dump($server_output);
if ($server_output->success === false) {
$result->msg = 'Captcha code error!';
$result->error = true;
echo json_encode($result);
exit;
}
$user_id = username_exists($registration->username);
if ($user_id) {
$result->msg = 'Username already present';
}
$emailCheck = email_exists($registration->email);
if ($emailCheck) {
$result->msg = 'Email already present';
}
if (!$user_id and $emailCheck == false) {
$random_password = wp_generate_password(12, false);
$userdata = array(
'user_login' => $registration->username,
'user_email' => $registration->email,
'user_pass' => $random_password,
'display_name' => $registration->first_name . ' ' . $registration->last_name,
'first_name' => $registration->first_name,
'last_name' => $registration->last_name,
);
$user_id = wp_insert_user($userdata);
if (is_wp_error($user_id)) {
$result->error = true;
$result->msg = 'Register fields failed ';
} else {
$result->msg = 'Thank you for your registration, your request has been forwarded to the site administrator. As soon as he approves it, an email containing your password will be sent to the email address that you have specified in the registration request.';
}
} else {
$result->error = true;
}
} else {
$result->error = true;
$result->msg = 'Parameters format mismatch';
}
} else {
$result->error = true;
$result->msg = 'Register fields empty';
}
echo json_encode($result);
exit;
}
add_action('wp_ajax_esi_mk_keyboard', 'esi_mk_keyboard');
add_action('wp_ajax_nopriv_esi_mk_keyboard', 'esi_mk_keyboard');
/*
* AJAX Callback
* Manage KeyBoard Action
*/
function esi_mk_keyboard() {
global $wbcllogger;
$result = new stdClass();
$result->error = false;
switch ($_REQUEST['type']) {
case "greek": {
ob_start();
echo file_get_contents(ESI_LAYOUTS . 'greek.html');
$result->html = ob_get_clean();
break;
}
case "hebrew": {
ob_start();
echo file_get_contents(ESI_LAYOUTS . 'hebrew.html');
$result->html = ob_get_clean();
break;
}
default: {
$result->error = true;
$result->msg = __('Unknow KeyBoard type or empty!', 'eagle');
}
}
echo json_encode($result);
die();
}
add_action('wp_ajax_esi_generate_csv', 'esi_generate_csv');
add_action('wp_ajax_nopriv_esi_generate_csv', 'esi_generate_csv');
function esi_generate_csv() {
$result = new stdClass();
$result->error = false;
$research = esi_process_ajax_research(true);
try {
$result->redirect = \Eagle\EagleHelper::eagleResearchList2CSV($research, $_POST['entity']);
} catch (\Eagle\EagleHelperException $eee) {
$result->error = true;
$result->msg = $eee->getMessage();
}
echo json_encode($result);
exit;
}
add_action('wp_ajax_esi_generate_pdf', 'esi_generate_pdf');
add_action('wp_ajax_nopriv_esi_generate_pdf', 'esi_generate_pdf');
function esi_generate_pdf() {
$result = new stdClass();
$result->error = false;
if (isset($_POST['dom_string'])) {
try {
$result->redirect = \Eagle\EagleHelper::dom2PDF($_POST['dom_string']);
} catch (\Eagle\EagleHelperException $e) {
$result->error = true;
$result->msg = $e->getMessage();
}
} else {
$result->error = true;
$result->msg = 'DOM String missing!';
}
echo json_encode($result);
exit;
}
add_shortcode('esi_do_getepidoc', 'esi_getepidoc');
function esi_getepidoc() {
//error_log("ddddd");
if (isset($_GET['objectid'])) {
// error_log($_GET['objectid']);
require_once __DIR__ . '/class/EagleSearch.php';
// $eagle = new EagleSearch();
try {
list($provider, $resourceID, $contentType) = explode('::', $_GET['objectid']);
$epidoc = file_get_contents(EagleSearch::SORL_EPIDOC_API_URL . $provider . '::' . $resourceID);
if ($epidoc == "EpiDoc representation not available for this record") {
header("Content-Type:text/html");
echo $epidoc;
} else {
// $xml = new SimpleXMLElement($eagle->epidocEagleObj($_GET['objectid']));
$filename = (str_replace(":", '_', $_GET['objectid']));
header("Content-disposition: attachment; filename=$filename.xml");
header("Content-Type:text/xml");
echo $epidoc;
// $epidoc = new SimpleXMLElement($xml->result->doc->arr->str);
// echo ($epidoc->metadata->eagleObject->asXML());
header("Expires: 0");
}
} catch (EagleSearchException $ex) {
echo json_encode(array("error" => $ex->getMessage()));
}
}
}
function esi_login_check() {
if (is_user_logged_in())
echo json_encode(array("logged" => true));
else
echo json_encode(array("logged" => false, "msg" => "<p>You must to be logged to save your research!</p>"));
exit();
}
add_action('wp_ajax_esi_login_check', 'esi_login_check');
add_action('wp_ajax_nopriv_esi_login_check', 'esi_login_check');
/* Save function */
function esi_save_ajax_research() {
$result = array();
if (is_user_logged_in()) {
require_once __DIR__ . '/class/EagleSearch.php';
require_once __DIR__ . '/class/EagleSaveSystem.php';
$eagle = new EagleSearch();
$adv = "";
$dating = array();
$fq = null;
try {
if (isset($_POST['fields'])) {
if (isset($_POST['searchType']) && $_POST['searchType'] === 0) {
$adv = preg_replace('/^\s*AND\s*/', '', stripcslashes($_POST['fields']));
} else if (isset($_POST['searchType']) && $_POST['searchType'] === 1) {
$fields = json_decode(stripcslashes($_POST['fields']), true);
if (count($fields)) {
foreach ($fields as $key => $value) {
if ($key === "detailedspot") {
//error_log($key);
//$eagle->addVirtualField(array('detailedspot' => array('modernfindspot', 'moderncountry', 'modernregion', 'modernprovince')));
// $eagle->setVirtualEnabled();
//$adv .= ($adv === "") ? "(" . $key . ":" . "\"" . $value . "\"" . ")" : "AND(" . $key . ":" . "\"" . $value . "\"" . ")";
$adv .= ($adv === "") ? "((modernfindspot:" . "\"" . $value . "\"" . ")OR(moderncountry:" . "\"" . $value . "\"" . ")OR(modernregion:" . "\"" . $value . "\"" . ")OR(modernprovince:" . "\"" . $value . "\"" . "))" : "AND((modernfindspot:" . "\"" . $value . "\"" . ")OR(moderncountry:" . "\"" . $value . "\"" . ")OR(modernregion:" . "\"" . $value . "\"" . ")OR(modernprovince:" . "\"" . $value . "\"" . "))";
} else if ($key === "location") {
//error_log($key);
//$eagle->addVirtualField(array('location' => array('conservationcountry', 'conservationregion', 'conservationcity', 'museum')));
//$eagle->setVirtualEnabled();
// $adv .= ($adv === "") ? "(" . $key . ":" . "\"" . $value . "\"" . ")" : "AND(" . $key . ":" . "\"" . $value . "\"" . ")";
$adv .= ($adv === "") ? "((conservationcountry:" . "\"" . $value . "\"" . ")OR(conservationregion:" . "\"" . $value . "\"" . ")OR(conservationcity:" . "\"" . $value . "\"" . ")OR(museum:" . "\"" . $value . "\"" . "))" : "AND((conservationcountry:" . "\"" . $value . "\"" . ")OR(conservationregion:" . "\"" . $value . "\"" . ")OR(conservationcity:" . "\"" . $value . "\"" . ")OR(museum:" . "\"" . $value . "\"" . "))";
} else if ($key === 'notafter' || $key === 'notbefore') {
//error_log($key);
$dating[$key] = $value;
//$adv .= ($adv === "") ? "(($key:\"[$value TO *]\")OR(notafter:\"[$value TO *]\"))" : "OR(notafter:\"[$value TO *]\"))";
} else {
//error_log($key);
$adv .= ($adv === "") ? "(" . $key . ":" . "\"" . $value . "\"" . ")" : "AND(" . $key . ":" . "\"" . $value . "\"" . ")";
}
}
if (array_key_exists('notbefore', $dating) && array_key_exists('notafter', $dating)) {
$adv .= ($adv === "") ? "(((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[* TO " . $dating["notafter"] . "]))OR((notbefore:[* TO " . $dating["notbefore"] . "])OR(notafter:[" . $dating["notafter"] . " TO *])))" : "AND(((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[* TO " . $dating["notafter"] . "]))OR((notbefore:[* TO " . $dating["notbefore"] . "])OR(notafter:[" . $dating["notafter"] . " TO *])))";
} else if (array_key_exists('notbefore', $dating)) {
$adv .= ($adv === "") ? "((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[" . $dating["notbefore"] . " TO *]))" : "AND((notbefore:[" . $dating["notbefore"] . " TO *])OR(notafter:[" . $dating["notbefore"] . " TO *]))";
} else if (array_key_exists('notafter', $dating)) {
//$adv .= ($adv === "") ? "(((notbefore:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "]))OR((notafter:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "])))" : "AND(((notbefore:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "]))OR((notafter:[" . $dating["notbefore"] . " TO " . $dating["notafter"] . "])))";
$adv .= ($adv === "") ? "((notbefore:[* TO " . $dating["notafter"] . "])OR(notafter:[* TO " . $dating["notafter"] . "]))" : "AND((notbefore:[* TO " . $dating["notafter"] . "])OR(notafter:[* TO " . $dating["notafter"] . "]))";
}
}
}
if (isset($_POST['facetOnAdvanced']) && !empty($_POST['facetOnAdvanced']) && !is_null($_POST['facetOnAdvanced'])) {
// error_log("valuto i facet on advanced");
$fq = preg_replace('/^\s*AND\s*/', '', stripcslashes($_POST['facetOnAdvanced']));
}
// $fields = json_decode(stripcslashes($_POST['fields']), true);
// $adv = "";
// if (count($fields)) {
// foreach ($fields as $key => $value) {
// $adv .= "AND(" . $key . ":" . "\"" . $value . "\"" . ")";
// }
// }
}
$eagle->setSavePath(WP_CONTENT_DIR . '/');
$filename = $eagle->saveAdvancedSearch($_POST['query'], $adv, $_POST['entity'], intval($_POST['page']), $_POST['searchType'], $fq);
if (is_null($filename)) {
$result["error"] = true;