forked from aadl/sopac
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sopac.module
1191 lines (1083 loc) · 38.1 KB
/
sopac.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
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
/**
* SOPAC is The Social OPAC: a Drupal module that serves as a wholly integrated web OPAC for the Drupal CMS
*
* @package SOPAC
* @version 2.1
* @author John Blyberg
*/
/**
* Initialize the SOPAC module. Load dependencies, etc...
*/
function sopac_init() {
global $user, $base_url;
// Handle SSL redirection if it is enabled.
if (variable_get('sopac_ssl_enable', 0)) {
$protected_uri = preg_match('/^(\/user|\/myaccount|\/login|\/donate)/', request_uri(), $debug_match);
$lists = preg_match('/.*list.*/', request_uri(), $debug_match);
if (($_SERVER['HTTPS'] && !$protected_uri) || ($_SERVER['HTTPS'] && $lists)) {
$new_link = 'http://' . $_SERVER['HTTP_HOST'] . request_uri();
}
elseif (!$_SERVER['HTTPS'] && $protected_uri && !$lists) {
if (variable_get('sopac_ssl_port', 443) != '443') {
$nonstd_port = ':' . variable_get('sopac_ssl_port', 443);
}
$new_link = 'https://' . $_SERVER['HTTP_HOST'] . request_uri();
}
if ($new_link) {
header("Location: $new_link");
}
}
// Grab the Locum path from config and load it
$locum_path = trim(variable_get('sopac_locum_path', '/usr/local/lib/locum'));
if ($locum_path[0] != '/') { $locum_path = '/' . $locum_path; }
if (substr($locum_path, -1) != '/') { $locum_path .= '/'; }
if (@file_exists($locum_path . 'locum-client.php')) {
@require_once($locum_path . 'locum-client.php');
}
// Grab the Insurge path from config and load it
$insurge_path = trim(variable_get('sopac_insurge_path', '/usr/local/lib/insurge'));
if ($insurge_path[0] != '/') { $insurge_path = '/' . $insurge_path; }
if (substr($insurge_path, -1) != '/') { $insurge_path .= '/'; }
if (@file_exists($insurge_path . 'insurge-client.php')) {
require_once($insurge_path . 'insurge-client.php');
}
// Set up some user-specific values
if ($user->uid) {
$user->locum_pass = substr($user->pass, 0, 7);
profile_load_profile($user);
$user->bcode_verified = sopac_bcode_isverified(&$user);
}
// Assign the various CSS Files
drupal_add_css(drupal_get_path('module', 'sopac') .'/sopac.css');
}
/**
* Display help and module information
*
* @param string $path Which path of the site we're displaying help
* @param array $arg Array that holds the current path as would be returned from arg() function
* @return string help text for the path
*/
function sopac_help($path, $arg) {
$output = '';
switch ($path) {
case "admin/help#sopac":
$output = '<p>'. t("The Social OPAC™ for Drupal") .'</p>';
break;
}
return $output;
}
/**
* Valid permissions for this module
*
* @return array An array of valid permissions for the sopac module
*/
function sopac_perm() {
return array('access user pages', 'administer sopac', 'show suppressed records', 'staff request');
}
/**
* Generate HTML for the sopac block.
* Uses the following templates: sopac_facet_block.tpl.php
*
* @param string $op the operation from the URL
* @param int $delta offset
* @return string block HTML
*/
function sopac_block($op = 'list', $delta = 0) {
global $locum_results_all, $locum_cfg;
$sopac_prefix = variable_get('sopac_url_prefix', 'cat/seek');
// listing of blocks, such as on the admin/block page
switch ($op) {
case 'list':
$block[0] = array(
'info' => t('Catalog Facets'),
'pages' => $sopac_prefix . '/search/*',
'cache' => BLOCK_CACHE_PER_PAGE,
);
$block[1] = array(
'info' => t('Search Tracker'),
'pages' => $sopac_prefix . '/search/*',
'cache' => BLOCK_CACHE_PER_PAGE,
);
$block[2] = array(
'info' => t('Catalog Tags'),
'pages' => $sopac_prefix . '/*',
'cache' => BLOCK_CACHE_PER_PAGE,
);
$block[3] = array(
'info' => t('Catalog Reviews'),
'pages' => $sopac_prefix . '/*',
'weight' => 1,
'cache' => BLOCK_CACHE_PER_PAGE,
);
$block[4] = array(
'info' => t('Item Tags'),
'pages' => $sopac_prefix . '/record/*',
'cache' => BLOCK_CACHE_PER_PAGE,
);
$block[5] = array(
'info' => t('Item Reviews'),
'pages' => $sopac_prefix . '/record/*',
'weight' => 1,
'cache' => BLOCK_CACHE_PER_PAGE,
);
$block[6] = array(
'info' => t('Personal Tags'),
'pages' => 'user/*',
'cache' => BLOCK_CACHE_PER_PAGE,
);
$block[7] = array(
'info' => t('Personal Reviews'),
'pages' => 'user/*',
'weight' => 1,
'cache' => BLOCK_CACHE_PER_PAGE,
);
$block[8] = array(
'info' => t('Public Lists'),
'pages' => $sopac_prefix . '/*',
'weight' => 1,
'cache' => BLOCK_CACHE_PER_PAGE,
);
return $block;
case 'view':
switch ($delta) {
case 0:
if ($locum_results_all['num_hits']) {
$block_content = theme('sopac_facet_block', $facet_menu, $locum_results_all, $locum_cfg);
$block['subject'] = t('Facets');
$block['content'] = $block_content;
}
break;
case 1:
require_once('sopac_catalog.php');
$block['subject'] = t('Your Search');
$block_content = sopac_search_block($locum_results_all, $locum_cfg);
$block['content'] = $block_content;
break;
case 2:
// SOPAC overview block for patron tags
require_once('sopac_social.php');
$block['subject'] = t('Popular Tags');
$block['content'] = theme('sopac_tag_block', 'overview');
break;
case 3:
// SOPAC overview block for patron reviews
require_once('sopac_social.php');
$block['subject'] = t('New Reviews');
$block['content'] = theme('sopac_review_block', 'overview');
break;
case 4:
// SOPAC item record block for patron tags
require_once('sopac_social.php');
$block['subject'] = t('Record Tags');
$block['content'] = theme('sopac_tag_block', 'record');
break;
case 5:
// SOPAC item record block for patron reviews
require_once('sopac_social.php');
$block['subject'] = t('Reviews');
$block['content'] = theme('sopac_review_block', 'record');
break;
case 6:
// SOPAC personal record block for patron's own tags
require_once('sopac_social.php');
$block['subject'] = t('My Top Tags');
$block['content'] = theme('sopac_tag_block', 'personal');
break;
case 7:
// SOPAC personal record block for patron's own reviews
require_once('sopac_social.php');
$block['subject'] = t('My Reviews');
$block['content'] = theme('sopac_review_block', 'personal');
break;
case 8:
require_once('sopac_user.php');
$block['subject'] = t('Public Lists');
$block['content'] = theme('sopac_list_block', 'public');
break;
}
return $block;
}
}
/**
* Implementation of hook_menu()
* Determines what the callback is for SOPAC and returns the appropriate Drupal menu array
*
* @return array Drupal menu array
*/
function sopac_menu() {
global $user;
$sopac_prefix = variable_get('sopac_url_prefix', 'cat/seek');
$items = array();
$items['admin/settings/sopac'] = array(
'title' => 'SOPAC settings',
'description' => 'SOPAC configuration options',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_admin'),
'access arguments' => array('access administration pages'),
'file' => 'sopac_admin.php',
'type' => MENU_NORMAL_ITEM,
);
$items['search_handler'] = array(
'title' => 'Search Handler',
'page callback' => 'theme_sopac_search_handler',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['admin/settings/sopac/moderate'] = array(
'title' => 'Moderate SOPAC Reviews',
'description' => 'SOPAC Moderation Page',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_admin_moderate_form'),
'access arguments' => array('access administration pages'),
'file' => 'sopac_admin.php',
'type' => MENU_NORMAL_ITEM,
);
$items[$sopac_prefix . '/search'] = array(
'title' => 'Catalog Search',
'page callback' => 'sopac_catalog_search',
'access arguments' => array('access content'),
'file' => 'sopac_catalog.php',
'type' => MENU_CALLBACK,
);
$items[$sopac_prefix . '/savesearch'] = array(
'title' => 'Save Search',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_savesearch_form'),
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
$items[$sopac_prefix . '/record/%'] = array(
'title' => 'Item Record',
'page callback' => 'sopac_bib_record',
'access arguments' => array('access content'),
'file' => 'sopac_catalog.php',
'type' => MENU_CALLBACK,
);
$items[variable_get('sopac_url_prefix', 'cat/seek') . '/record/%/reharvest'] = array(
'title' => 'Item Record',
'page callback' => 'sopac_bib_record_reharvest',
'access arguments' => array('access content'),
'file' => 'sopac_catalog.php',
'type' => MENU_CALLBACK,
);
// url to help handle selecting from multiple pickup locations
$items['hold/location'] = array(
'title' => 'Select Pickup Location',
'page callback' => 'sopac_hold_location_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_catalog.php',
'type' => MENU_CALLBACK,
);
$items[$sopac_prefix . '/request'] = array(
'title' => 'Request an Item',
'page callback' => 'sopac_request_item',
'access arguments' => array('access content'),
'file' => 'sopac_catalog.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/checkouts'] = array(
'title' => 'My Checkouts',
'page callback' => 'sopac_checkouts_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_NORMAL_ITEM,
);
if (variable_get('sopac_checkout_history_enable', 0)) {
$items['user/%user/checkouts/history'] = array(
'title' => 'My Checkout History',
'page callback' => 'sopac_checkout_history_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_NORMAL_ITEM,
);
$items['user/%user/checkouts/history/opt/%'] = array(
'title' => 'Change Checkout History Status',
'page callback' => 'sopac_checkout_history_toggle',
'page arguments' => array(4),
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
}
$items['user/%user/requests'] = array(
'title' => 'My Requests',
'page callback' => 'sopac_holds_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_NORMAL_ITEM,
);
if (variable_get('sopac_fines_enable', 1)) {
$items['user/%user/fines'] = array(
'title' => 'My Fines',
'page callback' => 'sopac_fines_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_NORMAL_ITEM,
);
$items['user/%user/fines/list'] = array(
'title' => 'List Fines',
'access arguments' => array('access user pages'),
'weight' => -10,
'file' => 'sopac_user.php',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
if (variable_get('sopac_payments_enable', 1)) {
$items['user/%user/fines/payments'] = array(
'title' => 'List Payments',
'page callback' => 'sopac_finespaid_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_LOCAL_TASK,
);
$items['user/%user/fines/pay'] = array(
'title' => 'Fines Payment',
'page callback' => 'sopac_makepayment_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
}
}
$items['user/%user/library'] = array(
'title' => 'My Library',
'page callback' => 'sopac_personal_overview_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_NORMAL_ITEM,
);
$items['user/%user/library/tags'] = array(
'title' => 'My Tags',
'page callback' => 'sopac_tags_page_cloud',
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_NORMAL_ITEM,
);
$items['user/%user/library/tags/cloud'] = array(
'title' => 'Tag Cloud',
'access arguments' => array('access user pages'),
'weight' => -10,
'file' => 'sopac_social.php',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['user/%user/library/tags/list'] = array(
'title' => 'Tag List',
'page callback' => 'sopac_tags_page_list',
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_LOCAL_TASK,
);
$items['user/%user/tag/edit'] = array(
'title' => 'Edit Tag',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_user_tag_edit'),
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/tag/delete'] = array(
'title' => 'Delete Tag',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_user_tag_delete'),
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/tag/show'] = array(
'title' => 'Tagged Items',
'page callback' => 'sopac_user_tag_hitlist',
'page arguments' => array(3),
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/library/ratings'] = array(
'title' => 'My Ratings',
'page callback' => 'sopac_ratings_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_NORMAL_ITEM,
);
$items['user/%user/library/reviews'] = array(
'title' => 'My Reviews',
'page callback' => 'sopac_review_page',
'access arguments' => array('access user pages'),
'page arguments' => array('personal'),
'file' => 'sopac_social.php',
'type' => MENU_NORMAL_ITEM,
);
$items['user/%user/library/searches'] = array(
'title' => 'My Searches',
'page callback' => 'sopac_saved_searches_page',
'access arguments' => array('access user pages'),
'file' => 'sopac_user.php',
'type' => MENU_NORMAL_ITEM,
);
$items['user/%user/lists'] = array(
'title' => 'My Lists',
'page callback' => 'sopac_lists_page',
'access arguments' => array('access content'),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/lists/edit'] = array(
'title' => 'Modify List',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_list_edit_form', 3),
'access callback' => 'sopac_lists_access',
'access arguments' => array(3),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/lists/delete/%'] = array(
'title' => 'Delete List',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_list_confirm_delete', 3),
'access callback' => 'sopac_lists_access',
'access arguments' => array(3),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/listadd/%/%'] = array(
'title' => 'Add To List',
'page callback' => 'sopac_list_add',
'page arguments' => array(2, 3),
'access callback' => 'sopac_lists_access',
'access arguments' => array(3),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/listmovetop/%/%'] = array(
'title' => 'Add To List',
'page callback' => 'sopac_list_move_top',
'page arguments' => array(2, 3),
'access callback' => 'sopac_lists_access',
'access arguments' => array(2),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
$items['user/%user/listdelete/%/%'] = array(
'title' => 'Add To List',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_list_confirm_item_delete', 2, 3),
'access callback' => 'sopac_lists_access',
'access arguments' => array(2),
'file' => 'sopac_user.php',
'type' => MENU_CALLBACK,
);
$items['review/delete'] = array(
'title' => 'Delete Review',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_delete_review_form'),
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_CALLBACK,
);
$items['review/edit'] = array(
'title' => 'Edit Review',
'page callback' => 'drupal_get_form',
'page arguments' => array('sopac_review_form'),
'access arguments' => array('access user pages'),
'file' => 'sopac_social.php',
'type' => MENU_CALLBACK,
);
$items['review/view'] = array(
'title' => 'Read Review',
'page callback' => 'sopac_review_page',
'access arguments' => array('access content'),
'page arguments' => array('single'),
'file' => 'sopac_social.php',
'type' => MENU_CALLBACK,
);
$items['review/user'] = array(
'title' => 'User Reviews',
'page callback' => 'sopac_review_page',
'access arguments' => array('access content'),
'page arguments' => array('user'),
'file' => 'sopac_social.php',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_theme()
*/
function sopac_theme() {
return array(
'sopac_results' => array(
'template' => 'sopac-results',
'arguments' => array('result_info' => NULL, 'hitlist_pager' => NULL, 'hitlist_content' => NULL, 'locum_result' => NULL, 'locum_config' => NULL),
),
'sopac_results_rss' => array(
'template' => 'sopac-results-rss',
'arguments' => array('result_info' => NULL, 'search_term' => NULL, 'search_type' => NULL, 'hitlist_content' => NULL, 'locum_result' => NULL, 'locum_config' => NULL),
),
'sopac_results_xml' => array(
'template' => 'sopac-results-xml',
'arguments' => array('result_info' => NULL, 'hitlist_pager' => NULL, 'hitlist_content' => NULL, 'locum_result' => NULL, 'locum_config' => NULL),
),
'sopac_results_hitlist' => array(
'template' => 'sopac-results-hitlist',
'arguments' => array('result_num' => NULL, 'cover_img_url' => NULL, 'locum_result' => NULL, 'locum_config' => NULL, 'no_circ' => NULL, 'minimal' => NULL),
),
'sopac_results_hitlist_rss' => array(
'template' => 'sopac-results-hitlist-rss',
'arguments' => array('result_num' => NULL, 'cover_img_url' => NULL, 'locum_result' => NULL, 'locum_config' => NULL, 'no_circ' => NULL),
),
'sopac_results_hitlist_xml' => array(
'template' => 'sopac-results-hitlist-xml',
'arguments' => array('result_num' => NULL, 'cover_img_url' => NULL, 'locum_result' => NULL, 'locum_config' => NULL, 'no_circ' => NULL),
),
'sopac_results_nohits' => array(
'template' => 'sopac-results-nohits',
'arguments' => array('locum_result' => NULL, 'locum_config' => NULL),
),
'sopac_record' => array(
'template' => 'sopac-record',
'arguments' => array('item' => NULL, 'item_status' => NULL, 'locum_config' => NULL, 'no_circ' => NULL, 'locum' => NULL, 'rev_arr' => NULL, 'rev_form' => NULL),
),
'sopac_record_musicdownload' => array(
'template' => 'sopac-record-musicdownload',
'arguments' => array('item' => NULL, 'locum_config' => NULL, 'rev_arr' => NULL, 'rev_form' => NULL),
),
'sopac_review' => array(
'template' => 'sopac-review',
'arguments' => array('user' => NULL, 'title' => NULL, 'rev_arr' => NULL, 'page_type' => NULL, 'rev_form' => NULL, 'ratings' => NULL, 'no_rev_msg' => NULL, 'bib_info' => NULL),
),
'sopac_facet_block' => array(
'template' => 'sopac-facet-block',
'arguments' => array('facet_menu' => NULL, 'locum_result' => NULL, 'locum_config' => NULL),
),
'sopac_search_block' => array(
'template' => 'sopac-search-block',
'arguments' => array('search' => NULL, 'locum_result' => NULL, 'locum_config' => NULL, 'user' => NULL),
),
'sopac_request' => array(
'template' => 'sopac-request',
'arguments' => array('request_result_msg' => NULL, 'request_error_msg' => NULL, 'item_form' => NULL, 'bnum' => NULL),
),
'sopac_fines' => array(
'template' => 'sopac-fines',
'arguments' => array('notice' => NULL, 'fine_table' => NULL, 'user' => NULL, 'payment_form' => NULL),
),
'sopac_pat_overview' => array(
'template' => 'sopac-pat-overview',
'arguments' => array('review_display' => NULL, 'ratings_chunk' => NULL, 'tag_cloud' => NULL),
),
'sopac_patron_profile' => array(
'arguments' => array('element' => NULL),
'template' => 'sopac-patroninfo-profile',
),
'sopac_ratings_page' => array(
'template' => 'sopac-ratings-page',
'arguments' => array('ratings_arr' => NULL),
),
'sopac_tags_page' => array(
'template' => 'sopac-tags-page',
'arguments' => array('tags_arr' => NULL),
),
'sopac_user_tag_hitlist' => array(
'template' => 'sopac-user-tag-hitlist',
'arguments' => array('tag' => NULL, 'pager_body' => NULL, 'result_body' => NULL),
),
'sopac_tag_block' => array(
'arguments' => array('block_type' => NULL),
),
'sopac_review_block' => array(
'arguments' => array('block_type' => NULL),
),
'sopac_tag_cloud' => array(
'arguments' => array('tags' => NULL, 'cloud_type' => 'catalog', 'min_size' => 10, 'max_size' => 24, 'wraplength' => 19),
),
'sopac_get_rating_stars' => array(
'arguments' => array('bnum' => NULL, 'rating' => NULL, 'show_label' => TRUE, 'post_redirect' => FALSE, 'id' => 'default'),
),
'sopac_user_holds_list' => array(
'template' => 'sopac-user-holds-list',
'arguments' => array('data' => array()),
),
'sopac_user_holds_list_multirow' => array(
'template' => 'sopac-user-holds-list-multirow',
'arguments' => array('data' => array()),
),
'sopac_list' => array(
'arguments' => array('list' => NULL),
),
'sopac_list_form' => array(
'arguments' => array('form' => NULL),
),
'sopac_list_block' => array(
'arguments' => array('block_type' => NULL),
),
'sopac_admin_moderate_reviews' => array(
'arguments' => array('form' => NULL),
),
);
}
/**
* Preprocess function (apparently needs to be in module page so found by theme register)
*
* @param array $variables
*/
function sopac_preprocess_sopac_user_holds_list(&$variables) {
$variables['freezes_enabled'] = variable_get('sopac_hold_freezes_enable', 1);
form_theme_bridge_parse_data_for_layout($variables);
}
/**
* Preprocess function (apparently needs to be in module page so found by theme register)
*
* @param array $variables
*/
function sopac_preprocess_sopac_user_holds_list_multirow(&$variables) {
form_theme_bridge_parse_data_for_layout($variables);
}
/**
* Implementation of hook_user()
*/
function sopac_user($op, &$edit, &$account, $category = NULL) {
require_once('sopac_user.php');
switch ($op) {
case 'submit':
sopac_update_locum_acct($op, $edit, $account, $category);
break;
case 'view':
sopac_user_view($op, $edit, $account, $category);
break;
case 'delete':
// TODO : Clean-up
break;
}
}
/**
* Checks to see if $cardnum has been verified
*
* @param string $cardnum Library patron barcode/card number
* @return boolean True if patron has verified the barcode, False if not.
*/
function sopac_bcode_isverified(&$user_obj) {
if (!$user_obj->profile_pref_cardnum) {
profile_load_profile($user_obj);
}
if (!$user_obj->profile_pref_cardnum) {
return FALSE;
}
$db_obj = db_fetch_object(db_query("SELECT COUNT(*) AS vfy FROM {sopac_card_verify} WHERE uid = %d AND cardnum = '%s' AND verified > 0", $user_obj->uid, $user_obj->profile_pref_cardnum));
if ($db_obj->vfy > 0) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* Creates an external function to formulate a search form by doing the neccesary includes.
* An example for using this might be calling this function from within a node.
*
* @param string $form_type Can be "basic", "advanced", or "both" (default)
* @return string Drupal-themed and generated search form
*/
function sopac_search_form($form_type = 'both') {
require_once('sopac_catalog.php');
switch (strtolower(trim($form_type))) {
case 'basic':
$search_form = drupal_get_form('sopac_search_form_basic');
break;
case 'advanced':
$search_form = drupal_get_form('sopac_search_form_adv');
break;
case 'both':
default:
$search_form = drupal_get_form('sopac_search_form_basic') . drupal_get_form('sopac_search_form_adv');
break;
}
return $search_form;
}
/**
* Handles the search queries & sets the the RESTful URIs.
* It very well may be that this function needs to be overridden due to themeing
* considerations, so it takes advantage of Drupal's hook_theme and may be defined
* in template.php.
*/
function theme_sopac_search_handler() {
$locum = new locum();
$locum_cfg = $locum->locum_config;
$search_query = trim($_POST['search_query']);
if (!$search_query) { $search_query = '*'; }
// enforce encoding of user-entered data
else {$search_query = drupal_urlencode($search_query);}
$search_type = $_POST['search_type'];
$search_type_arr = explode('_', $search_type);
if ($search_type_arr[0] == 'cat') {
$search_type = $search_type_arr[1];
$search_fmt = $search_type_arr[2];
$search_url = '/' . variable_get('sopac_url_prefix', 'cat/seek') . '/search/' . $search_type . '/' . $search_query;
// Material / Format types
if ($search_fmt) {
if ($search_fmt != 'all') {
$uris['search_format'] = $locum->csv_parser($locum_cfg['format_groups'][$search_fmt], '|');
}
} else if ($_POST['search_format']) {
if (is_array($_POST['search_format'])) {
$uris['search_format'] = trim(implode('|', $_POST['search_format']));
} else {
$uris['search_format'] = $_POST['search_format'];
}
}
// Location selections overrule collection selections and act as
// a filter if they are in a selection collection.
if ($_POST['collection']) {
$locations = array();
$uris['collection'] = trim(implode('|', $_POST['collection']));
foreach ($_POST['collection'] as $collection) {
$collection_arr = $locum->csv_parser($locum_cfg['collections'][$collection]);
if ($_POST['location']) {
$valid_locs = array_intersect($_POST['location'], $collection_arr);
if (count($valid_locs)) {
$locations = array_merge($locations, $valid_locs);
} else {
$locations = array_merge($locations, $collection_arr);
}
} else {
$locations = array_merge($locations, $collection_arr);
}
}
if ($_POST['location']) {
$locations = array_merge($locations, array_diff($_POST['location'], $locations));
}
} else if ($_POST['location']) {
$locations = $_POST['location'];
}
if (count($locations)) { $uris['location'] = trim(implode('|', $locations)); }
// Sort variable
if ($_POST['sort']) { $uris['sort'] = $_POST['sort']; }
// Age Group variable
if ($_POST['age']) { $uris['age'] = $_POST['age']; }
// Limit to Available
if ($_POST['limit_avail'] || $_POST['limit']) {
if (variable_get('sopac_multi_branch_enable', 0)) {
if ($_POST['limit_avail'] && $_POST['limit']) {
$uris['limit_avail'] = $_POST['limit_avail'];
}
} else {
$uris['limit_avail'] = 'any';
}
}
// Publisher Search
if ($_POST['publisher']) {
$uris['pub'] = trim($_POST['publisher']);
}
// Publication date ranges
if ($_POST['pub_year_start'] || $_POST['pub_year_end']) {
$uris['pub_year'] = trim($_POST['pub_year_start']) . '|' .
trim($_POST['pub_year_end']);
}
// Convert all our URI variables to GETs
if (count($uris)) {
$delimiter = '?';
foreach ($uris as $uri_key => $uri_vals) {
$search_url .= $delimiter . $uri_key . '=' . $uri_vals;
$delimiter = '&';
}
}
} else if ($search_type_arr[0] == 'web') {
switch ($search_type_arr[1]) {
case 'local':
$search_url = '/search/node/' . utf8_urldecode($search_query);
break;
case 'google':
$search_url = 'http://www.google.com/search?hl=en&q=' . utf8_urldecode($search_query);
break;
}
}
header('Location: ' . $search_url);
}
/**
* A little function that strips out all the random crapola that people's browsers sometimes throw in.
*
* @return string cleaned-up URI.
*/
function utf8_urldecode($str) {
$str = preg_replace("/%u([0-9a-f]{3,4})/i", "&#x\\1;", urldecode($str));
return html_entity_decode($str, NULL, 'UTF-8');
}
/*
* Exceptions in lower case are words you don't want converted
* Exceptions all in upper case are any words you don't want converted to title case
* but should be converted to upper case, e.g.:
* king henry viii or king henry Viii should be King Henry VIII
* From: http://www.php.net/manual/en/function.mb-convert-case.php#92317
*/
function title_case($string) {
$delimiters = array(" ", "-", ".", "O'", "Mc");
$exceptions = array("út", "u", "s", "és", "utca", "tér", "krt", "körút", "sétány", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXIII", "XXIV", "XXV", "XXVI", "XXVII", "XXVIII", "XXIX", "XXX", "3rd", "2nd" );
$string = mb_convert_case($string, MB_CASE_TITLE, "UTF-8");
foreach ($delimiters as $dlnr => $delimiter){
$words = explode($delimiter, $string);
$newwords = array();
foreach ($words as $wordnr => $word){
if (in_array(mb_strtoupper($word, "UTF-8"), $exceptions)){
// check exceptions list for any words that should be in upper case
$word = mb_strtoupper($word, "UTF-8");
}
elseif (in_array(mb_strtolower($word, "UTF-8"), $exceptions)){
// check exceptions list for any words that should be in upper case
$word = mb_strtolower($word, "UTF-8");
}
elseif (!in_array($word, $exceptions) ){
// convert to uppercase (non-utf8 only)
$word = mb_convert_case($word, MB_CASE_TITLE, "UTF-8");
}
array_push($newwords, $word);
}
$string = join($delimiter, $newwords);
}
return $string;
}
/**
* This function parses the URI to grab the elements upon which SOPAC acts. This is an
* attempt at pseudo-RESTful URIs within the catalog. We'll still use some GET vars but
* the major functionality if represented RESTfully.
*
* @return array Array of URI elements
*/
function sopac_parse_uri($strip_prefix = TRUE) {
// Strip out everything in the URI up through SOPAC's prefix
if ($strip_prefix) {
$args_raw = substr($_GET['q'], strlen(variable_get('sopac_url_prefix', 'cat/seek')));
}
else {
$args_raw = $_GET['q'];
}
$uri_array = explode('/', $args_raw);
if ($uri_array[0] == '') {
array_shift($uri_array);
}
foreach ($uri_array as $uri_elem) {
$result[] = utf8_urldecode(trim($uri_elem));
}
return $result;
}
/**
* Returns an array of GET variables, allowing for the ability to override them
* It also parses getvars with multiple values delimited by |
*
* @param array $override Optional override option that will override actual GET variables
* @return boolean|array If there are GET vars, an array of GET vars is returned, or else FALSE
*/
function sopac_parse_get_vars($override = array()) {
// TODO - Hard-coding this is not the best way to do it, but for now it is what it is... Revisit for 2.2?
$implode = array('search_format', 'pub_year', 'location', 'collection', 'facet_series', 'facet_lang', 'facet_year', 'facet_decade', 'age');
$getvars_raw = explode('?', $_SERVER['REQUEST_URI']);
if (count($getvars_raw) > 1) {
$getvars = urldecode($getvars_raw[1]);
} else {
if (count($override)) { return $override; } else { return FALSE; }
}
$getvars = explode('&', trim($getvars));
foreach ($getvars as $get) {
$get_arr = explode('=', $get);
if (count($get_arr) > 1) {
if (in_array($get_arr[0], $implode)) {
$vars[$get_arr[0]] = explode('|', trim($get_arr[1]));
} else {
$vars[$get_arr[0]] = trim($get_arr[1]);
}
}
}
foreach ($override as $okey => $ovar) {
if ($ovar) {
$vars[$okey] = $ovar;
}
else {
unset($vars[$okey]);
}
}
return count($vars) ? $vars : FALSE;
}
/**
* Takes an array and creates page variable. It's basically the reverse of sopac_parse_get_vars()
*
* @param array Array of variables to formulate
* @return string GET variable string
*/
function sopac_make_pagevars($getvars) {
$pagevars = '';
if (is_array($getvars) && count($getvars)) {
foreach ($getvars as $key => $var) {
if (is_array($var)) {
$var = implode('|', $var);