-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
271 lines (240 loc) · 8.31 KB
/
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
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
<?php
$treaty_header_mode = '';
$organization = NULL;
$treaty = NULL;
require_once(dirname(__FILE__) . '/functions_informea.php');
require_once(dirname(__FILE__) . '/functions_informea_ajax.php');
require_once(dirname(__FILE__) . '/functions_informea_template.php');
function i3_setup() {
register_nav_menus(array(
'primary' =>__('Primary Navigation', 'informea'),
'footer' => __('Footer Menu', 'informea'),
));
}
add_action('after_setup_theme', 'i3_setup');
add_filter('nav_menu_css_class' , 'about_page_menu');
function about_page_menu($classes){
if( in_array('current-menu-item', $classes) ){
$classes[] = 'active ';
}
return $classes;
}
function i3_enqueue_styles() {
global $wp_styles;
//jQuery and migrate are always loaded in the header
//http://blog.cloudfour.com/getting-all-javascript-into-the-footer-in-wordpress-not-so-fast-buster/
wp_register_script('bootstrap', get_stylesheet_directory_uri() . '/scripts/bootstrap.js', array('jquery'), FALSE, TRUE);
wp_register_script('informea-common', get_stylesheet_directory_uri() . '/scripts/common.js', array('jquery'), FALSE, TRUE);
wp_register_script('informea-treaties', get_stylesheet_directory_uri() . '/scripts/treaties.js', array('jquery'), FALSE, TRUE);
wp_register_script('informea-about', get_template_directory_uri() . '/scripts/about.js', array('jquery'), FALSE, TRUE);
wp_register_script('jquery-scrollto', get_template_directory_uri() . '/scripts/jquery.scrollto.min.js', array('jquery'), FALSE, TRUE);
wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.css');
wp_register_style('bootstrap-responsive', get_template_directory_uri() . '/css/bootstrap-responsive.css');
wp_register_style('font-awesome', get_template_directory_uri() . '/font-awesome/css/font-awesome.min.css');
wp_register_style('font-awesome-ie7', get_template_directory_uri() . '/font-awesome/css/font-awesome-ie7.min.css');
wp_register_style('informea-style', get_bloginfo('stylesheet_url'));
wp_register_style('informea-style-responsive', get_template_directory_uri() . '/css/style-responsive.css');
wp_register_style('informea-logos', get_template_directory_uri() . '/css/logos.css');
wp_register_style('informea-print', get_template_directory_uri() . '/css/print.css');
// Add this to all the front-end pages
wp_enqueue_script('informea-common');
wp_enqueue_script('bootstrap');
wp_enqueue_script('jquery-scrollto');
wp_enqueue_style('bootstrap');
wp_enqueue_style('bootstrap-responsive');
wp_enqueue_style('informea-style');
wp_enqueue_style('informea-style-responsive');
wp_enqueue_style('informea-logos');
wp_enqueue_style('font-awesome');
wp_enqueue_style('font-awesome-ie7');
$wp_styles->add_data('font-awesome-ie7', 'conditional', 'IE 7');
}
add_action('wp_enqueue_scripts', 'i3_enqueue_styles');
/**
* Echo the formatted region of a treaty (empty regions are treated as global)
* @param $treaty stdClass object
* @return string
*/
function i3_treaty_format_coverage($treaty) {
return !empty($treaty->region) ? $treaty->region : __('Global', 'informea');
}
/**
* Echo the formatted topic of a treaty (printing primary and secondary topics)
* @param $treaty stdClass Treaty object
* @return string Formatted topic
*/
function i3_treaty_format_topic($treaty) {
$ret = '';
if(!empty($treaty->theme)) {
$ret = sprintf('<strong>%s</strong>', $treaty->theme);
}
if(!empty($treaty->theme_secondary) && $treaty->theme_secondary != $treaty->theme) {
if(!empty($treaty->theme)) {
$ret .= ', ';
}
$ret .= sprintf('%s', $treaty->theme_secondary);
}
return $ret;
}
/**
* Build the treaty URL (use this instead of hard-coding the URL inside pages)
* @param $treaty stdClass Treaty object
* @param $suffix string Add suffix at the end of the URL
* @param bool $echo (Optional) echo the URL instead of returning it
* @return string The treaty URL
*/
function i3_treaty_url($treaty, $suffix = '', $echo = TRUE) {
if(!is_string($treaty)) {
$treaty = $treaty->odata_name;
}
$url = sprintf('%s/treaties/%s%s', get_bloginfo('url'), $treaty, $suffix);
if($echo) {
echo $url;
}
return $url;
}
/**
* Echo the trety primary topics, in treaty index page
* @param $treaty stdClass Treaty object
* @return string Treaty topics
*/
function i3_treaty_format_topics($treaty) {
$ret = '';
if(!empty($treaty->theme) || !empty($treaty->theme_secondary)) {
if(!empty($treaty->theme)) {
$ret = sprintf('<strong>%s</strong>', $treaty->theme);
}
if(!empty($treaty->theme_secondary)) {
if(!empty($treaty->theme)) {
$ret .= ', ';
}
$ret .= $treaty->theme_secondary;
}
}
return $ret;
}
/**
* Echo the year when treaty was created
* @param $treaty stdClass Treaty object
*/
function i3_treaty_format_year($treaty) {
$ret = '';
if(!empty($treaty->start)) {
$date = i3_format_mysql_date($treaty->start, 'Y');
if(!empty($date)) {
$ret = $date;
}
}
return $ret;
}
/**
* Format MySQL datetime or timestamp field
* @param $mysql_date string date/timestamp
* @param string $format Output format
* @param string $empty Add this character when date is invalid. Default
* @return string formatted date
*/
function i3_format_mysql_date($mysql_date, $format = 'd F Y', $empty = ' ') {
$ret = $empty;
if(!empty($mysql_date)) {
$date = strtotime($mysql_date);
if(!empty($date)) {
$ret = date($format, $date);
}
}
return $ret;
}
function i3_format_article_title($article) {
$number = '';
if(!empty($article->official_order)) {
$number = $article->official_order;
if(substr($number, -1) !== '.') {
$number .= '. ';
}
}
return sprintf('%s %s', $number, $article->title);
}
/**
* Print the caption table for the decision listing inside treaty page
*
* @param stdClass $cop COP meeting
* @param integer $c Number of decisions
*/
function i3_treaty_decision_caption($cop, $c) {
$ret = sprintf('%d decisions.', $c);
$ret .= sprintf(' Meeting was held on %s, ', i3_format_mysql_date($cop->start));
if(!empty($cop->location)) {
$ret .= sprintf(' %s', $cop->location);
}
if(!empty($cop->city)) {
$ret .= sprintf(' in %s', $cop->city);
}
$countries = InforMEA::get_countries();
if(!empty($countries[$cop->id_country])) {
$c = $countries[$cop->id_country];
$ret .= sprintf(', %s', $c->name);
}
return $ret;
}
/**
* Build the website breadcrumbtrail
*/
function informea_the_breadcrumb() {
$items = array();
if(!is_front_page()) {
$items[] = sprintf('<li><a href="%s">Home</a> <span class="divider">/</span></li>', get_bloginfo('url'));
}
$items = apply_filters('the_breadcrumb', $items);
if(!empty($items)) {
echo '<ul class="breadcrumb hidden-phone">';
foreach($items as $item) {
echo $item;
}
echo '</ul>';
}
}
/**
* Retrieve the country flag URL.
*
* @param $country stdClass Country object
* @param $version string Size. Supported values: 'medium' (default) or 'large'
* @return string URL to the country flag image
*/
function i3_country_flag($country, $version = 'medium') {
$ret = 'http://placehold.it/60x60';
$field = 'icon_' . $version;
if(!empty($country->$field)) {
$ret = sprintf('%s/%s', get_template_directory_uri(), $country->$field);
}
return $ret;
}
/**
* Build URLs to the glossary pages.
*
* @param stdClass $ob Entity object
* @param string $suffix Additional suffix
* @return string URL
*/
function i3_url_glossary($ob = NULL, $suffix = '') {
if($ob) {
$url = sprintf('%s/glossary', get_bloginfo('url'));
} else {
$url = sprintf('%s/glossary/%d', get_bloginfo('url'), $ob->id);
}
return $url . $suffix;
}
/**
* Build URLs to the treaty pages.
*
* @param stdClass $ob Entity object
* @param string $suffix Additional suffix
* @return string URL
*/
function i3_url_treaty($ob = NULL, $suffix = '') {
if(!$ob) {
$url = sprintf('%s/treaties', get_bloginfo('url'));
} else {
$url = sprintf('%s/treaties/%s', get_bloginfo('url'), $ob->odata_name);
}
return $url . $suffix;
}