This repository has been archived by the owner on May 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
template_functions.php
179 lines (152 loc) · 5.78 KB
/
template_functions.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
<?php
// Geo
function the_hnews_geo($before='', $after='', $echo=true, $lattxt='latitude ', $lngtxt='longitude ', $seperator=' and ') {
$geo = get_the_hnews_geo(0, $lattxt, $lngtxt, $seperator);
if (strlen($geo) > 0)
$geo = $before . $geo . $after;
if ($echo)
echo $geo;
else
return $geo;
}
function get_the_hnews_geo($id = 0, $lattxt, $lngtxt, $seperator) {
$post = &get_post($id);
$lat = $post->hnews_geo_latitude;
$lng = $post->hnews_geo_longitude;
$geo = '';
if( strlen($lat)>0 && strlen($lng)>0 ) {
$geo = "$lattxt<span class=\"latitude\">$lat</span>";
$geo .= $seperator;
$geo .= "$lngtxt<span class=\"longitude\">$lng</span>";
}
return apply_filters('the_hnews_geo', $geo, $post->ID);
}
// Source Organisation
function the_hnews_source_org($before='', $after='', $echo=true) {
$org = get_the_hnews_source_org();
if (strlen($org) == 0)
return;
$org = $before . $org . $after;
if ($echo)
echo $org;
else
return $org;
}
function get_the_hnews_source_org($id = 0, $seperator=', ') {
$post = &get_post($id);
$org_name = $post->hnews_org_name;
$org_unit = $post->hnews_org_unit;
$email = $post->hnews_email;
$url = $post->hnews_url;
$tel = $post->hnews_tel;
$post_office_box = $post->hnews_post_office_box;
$extended_address = $post->hnews_extended_address;
$street_address = $post->hnews_street_address;
$locality = $post->hnews_locality;
$region = $post->hnews_region;
$postal_code = $post->hnews_postal_code;
$country_name = $post->hnews_country_name;
$org = '';
if (empty($org_unit) && ! empty($org_name)) {
if ( ! empty($url)) {
$org = "<a href=\"$url\" class=\"fn org url\">$org_name</a>";
} else {
$org = "<span class=\"fn org\">$org_name</span>";
}
} elseif ( ! empty($org_unit)) {
$org .= '<span class="fn">';
$org .= "<span class=\"organization-name\">$org_name</span>";
$org .= $seperator;
$org .= "<span class=\"organization-unit\">$org_unit</span>";
$org .= '</span>';
}
$adr_bits = array();
if ( ! empty($post_office_box)) $adr_bits[] = "<span class=\"post-office-box\">PO Box $post_office_box</span>";
if ( ! empty($extended_address)) $adr_bits[] = "<span class=\"extended-address\">$extended_address</span>";
if ( ! empty($street_address)) $adr_bits[] = "<span class=\"street-address\">$street_address</span>";
if ( ! empty($locality)) $adr_bits[] = "<span class=\"locality\">$locality</span>";
if ( ! empty($region)) $adr_bits[] = "<span class=\"region\">$region</span>";
if ( ! empty($postal_code)) $adr_bits[] = "<span class=\"postal-code\">$postal_code</span>";
if ( ! empty($country_name)) $adr_bits[] = "<span class=\"country-name\">$country_name</span>";
if ( ! empty($adr_bits)) {
$adr = '<span class="adr">'.implode($seperator, $adr_bits).'</span>';
} else {
$adr = '';
}
$tel_bits = array();
if ( ! empty($tel)) $tel_bits[] = "<span class=\"tel\">$tel</span>";
if ( ! empty($email)) $tel_bits[] = "<a href=\"mailto:$email\" class=\"email\">$email</a>";
$tel = implode($seperator, $tel_bits);
$frags = array();
if( $org ) $frags[] = $org;
if( $adr ) $frags[] = $adr;
if( $tel ) $frags[] = $tel;
return apply_filters('the_hnews_source_org', implode( $seperator, $frags ), $post->ID);
}
// Principles
function the_hnews_principles_url($before='', $after='', $echo=true) {
$url = get_the_hnews_principles_url();
if (strlen($url) == 0)
return;
$url = $before . $url . $after;
if ($echo)
echo $url;
else
return $url;
}
function get_the_hnews_principles_url($id = 0) {
$post = &get_post($id);
if (empty($post->hnews_principles_url))
return '';
$name = strlen($post->hnews_principles_text) == 0 ? $post->hnews_principles_url : $post->hnews_principles_text;
$url = '<a href="' . $post->hnews_principles_url . '" rel="principles">' . $name . '</a>';
return apply_filters('the_hnews_principles_url', $url, $post->ID);
}
// License URL
function the_hnews_license_url($before='', $after='', $echo=true) {
$url = get_the_hnews_license_url();
if (strlen($url) == 0)
return;
$url = $before . $url . $after;
if ($echo)
echo $url;
else
return $url;
}
function get_the_hnews_license_url($id = 0) {
$post = &get_post($id);
if (empty($post->hnews_license_url))
return '';
$name = strlen($post->hnews_license_text) == 0 ? $post->hnews_license_url : $post->hnews_license_text;
$url = '<a href="' . $post->hnews_license_url . '" rel="item-license">' . $name . '</a>';
return apply_filters('the_hnews_license_url', $url, $post->ID);
}
/**
* Produces an example hNews meta block
*
* @return the hNews meta block in HTML
*/
function hnews_meta($format='l jS F Y \a\t Hi T') {
?>
<!-- hNews meta -->
<p class="postmetadata alt hnewsmeta">
<small>
<?php $geo = the_hnews_geo(' at <span class="geo">', '</span>', false);
if ( get_the_author_meta('url') ) {
$author = '<span class="vcard"><a href="' . get_the_author_meta('url') . '" title="' . esc_attr( sprintf(__("Visit %s’s website"), get_the_author()) ) . '" class="fn url" rel="external">' . get_the_author() . '</a></span>';
} else {
$author = get_the_author();
} ?>
Written by <?php echo $author; echo $geo; ?>.
<?php the_hnews_source_org('<span class="source-org vcard">Published by ', "</span>. "); ?>
<span class="published">Published on <span class="value-title" title="<?= get_the_time('c') ?> "><?= get_the_time($format) ?>.</span>
<?php if( get_the_time('c') != get_the_modified_date('c') ) { ?>
<span class="updated">Updated on <span class="value-title" title="<?= get_the_modified_date('c') ?> "><?= get_the_modified_date($format) ?>.</span>
<?php } ?>
<?php the_hnews_principles_url('Published under ', '. ' ); ?>
<?php the_hnews_license_url(' Licensed under ', '. ' ); ?>
</small>
</p>
<?php
}
?>