-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_tags.php
More file actions
117 lines (83 loc) · 2.25 KB
/
template_tags.php
File metadata and controls
117 lines (83 loc) · 2.25 KB
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
<?php
function dt_get_bookbox_item($item, $post_id = 0) {
$deadtree = DeadTrees::get_dt();
$postmeta = $deadtree->get_bookbox_info($post_id);
if(isset($postmeta[$item])) {
return $postmeta[$item];
} else {
return;
}
}
function dt_get_isbn($post_id = 0) {
return dt_get_bookbox_item('isbn', $post_id);
}
function dt_get_asin_com($post_id = 0) {
return dt_get_bookbox_item('asin_amazon.com', $post_id);
}
function dt_get_asin_ca($post_id = 0) {
return dt_get_bookbox_item('asin_amazon.ca', $post_id);
}
function dt_get_asin_uk($post_id = 0) {
return dt_get_bookbox_item('asin_amazon.co.uk', $post_id);
}
function dt_get_bookbox_comment($post_id = 0) {
return dt_get_bookbox_item('comment', $post_id);
}
function dt_get_bookbox_image($post_id = 0) {
$attachment_id = dt_get_bookbox_item('cover_image_attachment_id', $post_id);
if(!empty($attachment_id)) {
return wp_get_attachment_image($attachment_id, 'dt_book_cover_thumb');
}
}
// requires the loop
function dt_bookbox() {
if('dt_book' == get_post_type(get_the_ID())) {
$file = locate_template(array('deadtree-bookbox.php'), true, false);
if(empty($file)) {
$deadtree = DeadTrees::get_dt();
require($deadtree->get_basedir() . '/template/deadtree-bookbox.php');
}
}
}
// requires loop, will be used in filters
// dt_bookbox() is more efficient, since it doesn't use output buffering.
function dt_get_bookbox() {
ob_start();
dt_bookbox();
$bookbox = ob_get_clean();
return $bookbox;
}
function dt_get_amazon_url($domain = 'amazon.com', $post_id = 0) {
$url = '';
if(empty($post_id)) {
$post_id = get_the_ID();
}
if(!empty($post_id)) {
$domain = strtolower($domain);
$asin = '';
switch($domain) {
case 'amazon.ca':
$asin = dt_get_asin_ca($post_id);
break;
case 'amazon.co.uk':
$asin = dt_get_asin_uk($post_id);
break;
}
// amazon.com is handled here
if(empty($asin)) {
$asin = dt_get_asin_com($post_id);
}
if(!empty($asin)) {
$deadtree = DeadTrees::get_dt();
$affiliate_id = $deadtree->get_amazon_affiliate_id($domain);
if(!empty($affiliate_id)) {
$affiliate_url = '/?tag=' . $affiliate_id;
} else {
$affiliate_url = '';
}
$url .= 'http://www.' . $domain . '/dp/' . $asin . $affiliate_url;
}
}
return $url;
}
?>