forked from christiespeich/Mooberry-Book-Manager
/
single-book.php
1795 lines (1615 loc) · 51.6 KB
/
single-book.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
add_shortcode( 'book_title', 'mbdb_shortcode_title' );
add_shortcode( 'book_cover', 'mbdb_shortcode_cover' );
add_shortcode( 'book_subtitle', 'mbdb_shortcode_subtitle' );
add_shortcode( 'book_summary', 'mbdb_shortcode_summary' );
add_shortcode( 'book_publisher', 'mbdb_shortcode_publisher' );
add_shortcode( 'book_published', 'mbdb_shortcode_published' );
add_shortcode( 'book_goodreads', 'mbdb_shortcode_goodreads' );
add_shortcode( 'book_length', 'mbdb_shortcode_length' );
add_shortcode( 'book_excerpt', 'mbdb_shortcode_excerpt' );
add_shortcode( 'book_additional_info', 'mbdb_shortcode_additional_info' );
add_shortcode( 'book_genre', 'mbdb_shortcode_genre' );
add_shortcode( 'book_reviews', 'mbdb_shortcode_reviews' );
add_shortcode( 'book_buylinks', 'mbdb_shortcode_buylinks' );
add_shortcode( 'book_downloadlinks', 'mbdb_shortcode_downloadlinks' );
add_shortcode( 'book_serieslist', 'mbdb_shortcode_serieslist');
add_shortcode( 'book_series', 'mbdb_shortcode_series');
add_shortcode( 'book_tags', 'mbdb_shortcode_tags');
add_shortcode( 'book_illustrator', 'mbdb_shortcode_illustrator');
add_shortcode( 'book_editor', 'mbdb_shortcode_editor');
add_shortcode( 'book_cover_artist', 'mbdb_shortcode_cover_artist');
add_shortcode( 'book_links', 'mbdb_shortcode_links');
add_shortcode( 'book_editions', 'mbdb_shortcode_editions');
add_shortcode( 'mbdb_book', 'mbdb_shortcode_book');
/******************************************************************
*
* GENERIC FUNCTIONS
*
******************************************************************/
/**
* Get book ID based on slug or current post
*
*
*
* @since 1.0
* @since 3.0 use MBDB obj
*
* @param [string] $slug slug/post_name of book (optional)
*
* @return ID of book. 0 if book isn't found
*
*
*/
function mbdb_get_book_ID( $slug = '' ) {
global $post;
if ( $slug == '' ) {
if ($post) {
return $post->ID;
}
} else {
$book = MBDB()->books->get_by_slug($slug);
if ( $book ) {
return $book->book_id;
}
}
return 0;
}
/**
* Retrieves book data based on meta_data field ID
*
* Gets book by either ID or slug
*
* @since 2.0
* @since 3.0 use MBDB obj
*
* @param string $meta_data meta_data field ID of data to return
* @param string $book slug of book to retrieve data for (optional)
*
* @return mixed data or false if book couldn't be found or if data was blank
* ( make sure to test with === false when calling this function )
*
* @access public
*
*/
function mbdb_get_book_data( $meta_data, $book = '') {
$bookID = mbdb_get_book_ID( $book );
if ( $bookID != 0 ) {
$book_data = MBDB()->books->get_data( $meta_data, $bookID );
if ( $book_data != '' && $book_data != null ) {
return $book_data;
}
}
return false;
}
/**
* Return the output for a blank element
*
* Returns the html for when an element doesn't have any data
* including the proper css classes
*
* @since 2.0
* @param string $classname identifies the datafield in the class name
* @param string $blank_output what should be displayed if the data is blank
*
* @return string html output
*/
function mbdb_blank_output( $classname, $blank_output) {
return apply_filters('mbdb_shortcode_' . $classname, '<span class="mbm-book-' . $classname . '"><span class="mbm-book-' . $classname . '-blank">' . esc_html($blank_output) . '</span></span>');
}
/******************************
*
* SUMMARY
*
*****************************/
/**
* Output the summary including the proper css classes
*
* Includes the label & after text
* Adds auto <p> tags for newlines
*
* @since 1.0
* @param string $book_data data to output
* @param array $attr args passed in to shortcode
*
* @return html output
*
* @access public
*/
function mbdb_output_summary($book_data, $attr) {
return apply_filters('mbdb_shortcode_summary', '<div class="mbm-book-summary"><span class="mbm-book-summary-label">' . esc_html($attr['label']) . '</span><span class="mbm-book-summary-text">' . do_shortcode(wpautop(wp_kses_post($book_data))) . '</span><span class="mbm-book-summary-after">' . esc_html($attr['after']) . '</span></div>');
}
/**
*
* Get the book's summary
*
*
* @since 2.0
* @since 3.0 use custom table column name instead of post_meta
*
* @return mixed data or false if book couldn't be found or if data was blank
* ( make sure to test with === false when calling this function )
*
* @access public
*
*/
function mbdb_get_summary_data($book = '') {
return mbdb_get_book_data('summary', $book);
}
/**
*
* Shortcode function for book's summary
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_summary($attr, $content) {
$attr = shortcode_atts(array('label' => '',
'after' => '',
'blank' => '',
'book' => ''), $attr);
$book_data = mbdb_get_summary_data( $attr['book']);
if ($book_data === false) {
return mbdb_blank_output('summary', $attr['blank']);
} else {
return mbdb_output_summary($book_data, $attr);
}
}
/*******************************
PUBLICATION DATE
*****************************/
/**
*
* Get the book's published date
*
*
* @since 2.0
* @since 3.0 use custom table column name instead of post_meta
*
* @return mixed data or false if book couldn't be found or if data was blank
* ( make sure to test with === false when calling this function )
*
* @access public
*
*/
function mbdb_get_published_data($book = '' ) {
return mbdb_get_book_data('release_date', $book);
}
/**
*
* Shortcode function for book's published date
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_published($attr, $content) {
$attr = shortcode_atts(array('format' => 'short',
'label' => '',
'after' => '',
'blank' => '',
'book' => ''), $attr);
$mbdb_published = mbdb_get_published_data($attr['book']);
if ($mbdb_published === false) {
return mbdb_blank_output('published', $attr['blank']);
} else {
return mbdb_output_published($mbdb_published, $attr);
}
}
/**
* output the book's published date
*
*
*
* @since 2.0
* @since 3.0 use WP's default date format if one is not specified
*
* @param [string] $mbdb_published date to output
* @param [array] $attr Parameters
*
* @return Return_Description
*
* @access public
*/
function mbdb_output_published($mbdb_published, $attr) {
switch ($attr['format']) {
case 'short':
/* translators: short date format. see http://php.net/date */
$format = __('m/d/Y');
break;
case 'long':
/* translators: long date format. see http://php.net/date */
$format = __('F j, Y');
break;
case 'default':
$format = get_option('date_format');
break;
}
return apply_filters('mbdb_shortcode_published', '<span class="mbm-book-published"><span class="mbm-book-published-label">' . esc_html($attr['label']) . '</span><span class="mbm-book-published-text">' . date($format, strtotime($mbdb_published)) . '</span><span class="mbm-book-published-after">' . esc_html($attr['after']) . '</span></span>');
}
/*******************************
GOODREADS
*****************************/
/**
* Output Add to Goodreads button
* If can't find the Goodreads image, just use the text in the params
*
*
* @since 2.0
* @since 3.0 added alt text
*
* @param [string] $mbdb_goodreads goodreads url
* @param [array] $attr Parameters
*
* @return HTML output
*
* @access public
*/
function mbdb_output_goodreads($mbdb_goodreads, $attr) {
$mbdb_options = get_option('mbdb_options');
if (empty($mbdb_options['goodreads'])) {
return apply_filters('mbdb_shortcode_goodreads', '<div class="mbm-book-goodreads"><span class="mbm-book-goodreads-label">' . esc_html($attr['label']) . '</span><A class="mbm-book-goodreads-link" HREF="' . esc_url($mbdb_goodreads) . '" target="_new"><span class="mbm-book-goodreads-text">' . $attr['text'] . '</span></A><span class="mbm-book-goodreads-after">' . esc_html($attr['after']) . '</span></div>');
} else {
if (array_key_exists('goodreads-id', $mbdb_options)) {
$imageID = $mbdb_options['goodreads-id'];
} else {
$imageID = 0;
}
$alt = mbdb_get_alt_text( $imageID, __('Add to Goodreads', 'mooberry-book-manager') );
return apply_filters('mbdb_shortcode_goodreads', '<div class="mbm-book-goodreads"><span class="mbm-book-goodreads-label">' . esc_html($attr['label']) . '</span><A class="mbm-book-goodreads-link" HREF="' . esc_url($mbdb_goodreads) . '" target="_new"><img class="mbm-book-goodreads-image" src="' . esc_url($mbdb_options['goodreads']) . '"' . $alt . '/></A><span class="mbm-book-goodreads-after">' . esc_html($attr['after']) . '</span></div>');
}
}
/**
*
* Get the book's goodreads link
*
*
* @since 2.0
* @since 3.0 use custom table column name instead of post_meta
*
* @return mixed data or false if book couldn't be found or if data was blank
* ( make sure to test with === false when calling this function )
*
* @access public
*
*/
function mbdb_get_goodreads_data( $book = '') {
return mbdb_get_book_data('goodreads', $book);
}
/**
*
* Shortcode function for book's goodreads link
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_goodreads($attr, $content) {
$attr = shortcode_atts(array('text' => __('View on Goodreads', 'mooberry-book-manager'),
'label' => '',
'after' => '',
'blank' => '',
'book' => ''), $attr);
$mbdb_goodreads = mbdb_get_goodreads_data($attr['book']);
if ($mbdb_goodreads === false) {
return mbdb_blank_output('goodreads', $attr['blank']);
} else {
return mbdb_output_goodreads($mbdb_goodreads, $attr);
}
}
/******************************************
EXCERPT
**************************************/
/**
* Output the book's excerpt
* Truncate it around $attr['length'] characters after a paragraph
* behind a "show more" link
*
*
* @since 2.0
*
* @param [string] $mbdb_excerpt excerpt to output
* @param [array] $attr Parameters
*
* @return html output
*
* @access public
*/
function mbdb_output_excerpt($mbdb_excerpt, $attr) {
$mbdb_excerpt = wpautop($mbdb_excerpt);
$excerpt1 = '';
$excerpt2 = '';
if ($attr['length'] == 0) {
$excerpt1 = $mbdb_excerpt;
$excerpt2 = '';
} else {
if (preg_match('/^(.{1,' . $attr['length'] . '}<\/p>)(.*)/s', $mbdb_excerpt, $match)) {
$excerpt1 = $match[1];
$excerpt2 = $match[2];
} else {
// if no paragraphs in 1000 characters then take the first paragraph
if (preg_match('/^(.*<\/p>)(.*?)/sU', $mbdb_excerpt, $match)) {
$excerpt1 = $match[1];
$excerpt2 = $match[2];
}
}
}
$html_output = '<div class="mbm-book-excerpt">
<span class="mbm-book-excerpt-label">' . esc_html($attr['label']) . '</span>
<span class="mbm-book-excerpt-text">' . do_shortcode(wp_kses_post($excerpt1));
if (trim($excerpt2) != '' ) {
$html_output .= '<a name="more" class="mbm-book-excerpt-read-more">' . __('READ MORE', 'mooberry-book-manager') . '</a>
<span class="mbm-book-excerpt-text-hidden">' . do_shortcode(wp_kses_post($excerpt2)) . '<a class="mbm-book-excerpt-collapse" name="collapse">' . __('COLLAPSE', 'mooberry-book-manager') . '</a></span>';
}
$html_output .=' </span><span class="mbm-book-excerpt-after">' . esc_html($attr['after']) . '</span></div>';
return apply_filters('mbdb_shortcode_excerpt', $html_output);
}
/**
*
* Get the book's excerpt
*
*
* @since 2.0
* @since 3.0 use custom table column name instead of post_meta
*
* @return mixed data or false if book couldn't be found or if data was blank
* ( make sure to test with === false when calling this function )
*
* @access public
*
*/
function mbdb_get_excerpt_data($book = '') {
return mbdb_get_book_data('excerpt', $book);
}
/**
*
* Shortcode function for book's excerpt
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_excerpt($attr, $content) {
$attr = shortcode_atts(array('label' => '',
'after' => '',
'blank' => '',
'length' => '0',
'book' => ''), $attr);
$mbdb_excerpt = mbdb_get_excerpt_data( $attr['book']);
if ($mbdb_excerpt === false) {
return mbdb_blank_output('excerpt', $attr['blank']);
} else {
return mbdb_output_excerpt($mbdb_excerpt, $attr);
}
}
/*******************************************
ADDITIONAL INFO
*******************************************/
/**
* Output book's additional info
*
*
*
* @since 2.0
*
* @param [string] $mbdb_additional_info string to output
* @param [array] $attr Parameters
*
* @return HTML output
*
* @access public
*/
function mbdb_output_additional_info($mbdb_additional_info, $attr) {
$html_output = '<div class="mbm-book-additional-info">';
$html_output .= wpautop(wp_kses_post($mbdb_additional_info));
$html_output .= '</div>';
return apply_filters('mbdb_shortcode_additional_info', $html_output);
}
/**
*
* Get the book's additional info
*
*
* @since 2.0
* @since 3.0 use custom table column name instead of post_meta
*
* @return mixed data or false if book couldn't be found or if data was blank
* ( make sure to test with === false when calling this function )
*
* @access public
*
*/
function mbdb_get_additional_info_data($book = '') {
return mbdb_get_book_data('additional_info', $book);
}
/**
*
* Shortcode function for book's additioanl info
*
*
* @since
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_additional_info($attr, $content) {
$attr = shortcode_atts(array( 'blank' => '',
'book' => ''), $attr);
$mbdb_additional_info = mbdb_get_additional_info_data( $attr['book']);
if ($mbdb_additional_info === false) {
return mbdb_blank_output('additional_info', $attr['blank']);
} else {
return mbdb_output_additional_info($mbdb_additional_info, $attr);
}
}
/********************************************
TAXONOMIES
******************************************/
/**
* output one of the book's taxonomies in either a bulleted list
* or a comma-delimited list
*
*
*
* @since
*
* @param [string] $classname name for css class that identifies the taxonomy
* @param [array] $mbdb_terms list of terms
* @param [string] $permalink permalink for tax grid
* @param [string] $taxonomy name of taxonomy
* @param [array] $attr Parameters
*
* @return html output
*
* @access public
*/
function mbdb_output_taxonomy($classname, $mbdb_terms, $permalink, $taxonomy, $attr) {
if ($attr['delim'] == 'comma') {
$delim = ', ';
$after = '';
$before = '';
$begin = '';
$end = '';
} else {
$delim = '</li><li class="' . $classname . '-listitem">';
$before = '<li class="' . $classname . '-listitem">';
$after = '</li>';
$begin = '<ul class="' . $classname . '-list">';
$end = '</ul>';
}
$list = '';
$list .= $before;
foreach ($mbdb_terms as $term) {
$list .= '<a class="' . $classname . '-link" href="';
// check if using permalinks
if ( get_option('permalink_structure') !='' ) {
$list .= home_url($permalink . '/' . $term->slug);
} else {
$list .= home_url('?the-taxonomy=' . $taxonomy . '&the-term=' . $term->slug . '&post_type=mbdb_tax_grid');
}
$list .= '"><span class="' . $classname . '-text">' . $term->name . '</span></a>';
$list .= $delim;
}
// there's an extra $delim added to the string
if ($attr['delim']=='list') {
// trim off the last </li> by cutting the entire $delim off and then adding in the </li> back in
$list = substr($list, 0, strripos($list, $delim)) . '</li>';
} else {
// trim off the last space and comma
$list = substr($list, 0, -2);
}
return apply_filters('mbdb_shortcode_' . $permalink . '_taxonomy', '<div class="' . $classname . '" style="display:inline-block">' . $begin . $list . $end . '</div>');
}
/**
* Get terms for a book's taxonomy
*
* @since 2.0
*
* @param [string] $taxonomy taxonomy to retrieve
* @param [string] $book slug (optional)
*
* @return mixed list of terms or false if book couldn't be found
* or if data was blank
*
* @access public
*/
function mbdb_get_taxonomy_data($taxonomy, $book = '' ) {
$bookID = mbdb_get_book_ID($book);
if ($bookID != 0) {
$mbdb_terms = get_the_terms( $bookID, $taxonomy);
if (!$mbdb_terms) {
return false;
} else {
return $mbdb_terms;
}
} else {
return false;
}
}
/**
*
* Shortcode function for book's series
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_series( $attr, $content) {
return mbdb_shortcode_taxonomy($attr, 'mbdb_series', 'series');
}
/**
*
* Shortcode function for book's tags
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_tags( $attr, $content) {
return mbdb_shortcode_taxonomy($attr, 'mbdb_tag', 'book-tag');
}
/**
*
* Shortcode function for book's genres
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_genre($attr, $content) {
return mbdb_shortcode_taxonomy($attr, 'mbdb_genre', 'genre');
}
/**
*
* Shortcode function for book's editors
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_editor($attr, $content) {
return mbdb_shortcode_taxonomy($attr, 'mbdb_editor', 'editor');
}
/**
*
* Shortcode function for book's illustrators
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_illustrator($attr, $content) {
return mbdb_shortcode_taxonomy($attr, 'mbdb_illustrator', 'illustrator');
}
/**
*
* Shortcode function for book's cover artists
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_cover_artist($attr, $content) {
return mbdb_shortcode_taxonomy($attr, 'mbdb_cover_artist', 'cover-artist');
}
/**
*
* Get data for a book's taxonomy and output it
*
*
* @since 1.0
* @since 3.0 get permalink from options
*
* @param [array] parameters
* @param [string] taxonomy to get
* @param [string] default permalink and css class
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_taxonomy($attr, $taxonomy, $default_permalink) {
$attr = shortcode_atts(array('delim' => 'comma',
'blank' => '',
'book' => ''), $attr);
// v3.0 get permalink from options
$mbdb_options = get_option('mbdb_options');
$permalink = $mbdb_options['mbdb_book_grid_' . $taxonomy . '_slug'];
if ($permalink == '') {
$permalink = $default_permalink;
}
$mbdb_terms = mbdb_get_taxonomy_data( $taxonomy, $attr['book']);
if ($mbdb_terms === false) {
return mbdb_blank_output($permalink . '_taxonomy', $attr['blank']);
} else {
return mbdb_output_taxonomy('mbm-book-' . $default_permalink, $mbdb_terms, $permalink, $taxonomy, $attr);
}
}
/***********************************************
TITLE
*******************************************/
/**
*
* Shortcode function for book's title
* This function is different than the others because every book
* has a title. it's not an optional property. Also title comes
* from the post object not the custom table or post meta
*
* Title woudl only be blank if an invalid book is passed in
*
* @since 1.0
* @since 3.0 use MBDB object
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_get_title_data( $slug ) {
global $post;
if ($slug == '') {
$title = $post->post_title;
} else {
$book = MBDB()->books->get_by_slug($slug);
if ($book) {
$title = $book->post_title;
} else {
$title = '';
}
}
return $title;
}
function mbdb_shortcode_title( $attr, $content) {
$attr = shortcode_atts(array('book' => '',
'blank' => ''), $attr);
$title = mbdb_get_title_data( $attr['book'] );
if ($title != '') {
$html = '<span class="mbm-book-title"><span class="mbm-book-title-text">' . esc_html($title) . '</span></span>';
} else {
$html = '<span class="mbm-book-title"><span class="mbm-book-title-blank">' . esc_html($attr['blank']) . '</span></span>';
}
return apply_filters('mbdb_shortcode_title', $html);
}
/************************************************
SUBTITLE
*********************************************/
/**
*
* Get the book's subtitle
*
*
* @since 2.0
* @since 3.0 use custom table column name instead of post_meta
*
* @return mixed data or false if book couldn't be found or if data was blank
* ( make sure to test with === false when calling this function )
*
* @access public
*
*/
function mbdb_get_subtitle_data( $book = '') {
return mbdb_get_book_data('subtitle', $book);
}
/**
* Returns the output for subtitle
*
*
* @since 3.0
*
* @param string $classname identifies the data field in the css class
* @param string $data data to display
*
* @return string html output
*/
function mbdb_output_subtitle( $data, $attr ) {
return apply_filters('mbdb_shortcode_subtitle', '<span class="mbm-book-subtitle"><span class="mbm-book-subtitle-text">' . esc_html($data) . '</span></span>');
}
/**
*
* Shortcode function for book's subtitle
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_subtitle($attr, $content) {
$attr = shortcode_atts(array('book' => '',
'blank' => ''), $attr);
$book_data = mbdb_get_subtitle_data( $attr['book'] );
if ($book_data === false) {
return mbdb_blank_output('subtitle', $attr['blank']);
} else {
return mbdb_output_subtitle( $book_data, $attr);
}
}
/******************************
PUBLISHER
****************************/
/**
*
* Get the book's publisher
*
*
* @since 2.0
* @since 3.0 use custom table column name instead of post_meta
*
* @return mixed data or false if book couldn't be found or if data was blank
* ( make sure to test with === false when calling this function )
*
* @access public
*
*/
function mbdb_get_publisher_data($book = '') {
$publisherID = mbdb_get_book_data('publisher_id', $book);
if ($publisherID === false) {
return false;
}
$publisher = mbdb_get_publisher_info($publisherID);
if ($publisher == null) {
return false;
} else {
return $publisher;
}
}
/**
*
* Shortcode function for book's summary
*
*
* @since 1.0
*
* @param [array] parameters
* @param [string] content
*
* @return HTML output
*
* @access public
*
*/
function mbdb_shortcode_publisher($attr, $content) {
$attr = shortcode_atts(array('label' => '',
'after' => '',
'blank' => '',
'book' => ''), $attr);
$book_data = mbdb_get_publisher_data($attr['book']);
if ($book_data === false) {
return mbdb_blank_output('publisher', $attr['blank']);
} else {
return mbdb_output_publisher($book_data, $attr);
}
}
/**
*
* Outputs the book's publisher
*
*
* @since
*
* @param [array] $book_data Publisher array
* @param [array] $attr Parameters
*
* @return Return_Description
*
* @access public
*/
function mbdb_output_publisher($book_data, $attr) {
$mbdb_publisher = $book_data['name'];
$mbdb_publisherwebsite = $book_data['website'];
if (empty($mbdb_publisherwebsite)) {
$text = '<span class="mbm-book-publisher-text">' . esc_html($mbdb_publisher) . '</span>';
} else {
$text = '<A class="mbm-book-publisher-link" HREF="' . esc_url($mbdb_publisherwebsite) . '"><span class="mbm-book-publisher-text">' . esc_html($mbdb_publisher) . '</span></a>';
}
return apply_filters('mbdb_shortcode_publisher', '<span class="mbm-book-publisher"><span class="mbm-book-publisher-label">' . esc_html($attr['label']) . '</span>' . $text . '<span class="mbm-book-publisher-after">' . esc_html($attr['after']) . '</span></span>');
}
/*****************************************
SERIES LIST
***************************************/
/**
*
* Output series in a UL list with a heading
* (default Part of the ___ Series:)
*
*
* @since
*
* @param [array] $mbdb_series series
* @param [array] $attr Parameters
*
* @return Return_Description
*
* @access public
*/
function mbdb_output_serieslist($mbdb_series, $attr) {
$bookID = mbdb_get_book_ID($attr['book']);
$classname = 'mbm-book-serieslist';
$series_name = '';
foreach($mbdb_series as $series) {
$series_name .= '<div class="' . $classname . '-seriesblock"><span class="' . $classname . '-before">' . esc_html($attr['before']) . '</span>';