-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcodes.php
229 lines (183 loc) · 6.21 KB
/
shortcodes.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
<?php
/**
* Shortcode to display number of lernorte.
*/
function lfm_shortcode_number_lernorte() {
$params = array(
'limit' => -1
);
$lernorte = pods('lernort', $params);
return $lernorte->total_found();
}
add_shortcode('lfm_lernorte_count',
'lfm_shortcode_number_lernorte' );
/**
* Shortcode to display number of referent*n.
*/
function lfm_shortcode_number_referentn() {
$params = array(
'limit' => -1
);
$referentn = pods('referentn', $params);
return $referentn->total_found();
}
add_shortcode('lfm_referentn_count',
'lfm_shortcode_number_referentn' );
/**
* Shortcode to display number of veranstaltungen.
*/
function lfm_shortcode_number_veranstaltungen() {
$params = array(
'limit' => -1
);
$veranstaltungen = pods('veranstaltung', $params);
return $veranstaltungen->total_found();
}
add_shortcode('lfm_veranstaltungen_count',
'lfm_shortcode_number_veranstaltungen' );
/**
* Shortcode to display links to (upcoming) months
*/
function lfm_shortcode_upcoming_months_links() {
ob_start();
$num_month = 8;
$iter_date = new DateTime( strtotime( 'beginning of month') );
$i = -1;
while( $i++ < $num_month ) {
$month_date = mktime(0, 0, 0, date('n') + $i);
$month_name = date_i18n( 'F', $month_date, 1 );
echo "<a href=\"/veranstaltungen/".$iter_date->format('Y')."/" . date( 'm', $month_date ) . "\">" . $month_name . "</a> ";
if ( $i < $num_month ) {
echo "| ";
}
$iter_date->modify("+1 month");
}
//->modify( 'first day of next month' );
//$final = date("Y-m-d", strtotime("+1 month", $time));
return ob_get_clean();
}
add_shortcode('lfm_upcoming_months_links', 'lfm_shortcode_upcoming_months_links' );
/**
* Shortcode to display a list of events
*/
function lfm_shortcode_event_list_month() {
ob_start();
$calendar_month = get_query_var( 'calendar_month' );
$calendar_year = get_query_var( 'calendar_year' );
$zielgruppen = get_query_var( 'zielgruppe' );
$formate = get_query_var( 'format' );
$themenfelder = get_query_var( 'themenfelder' );
$spezials = get_query_var( 'spezials' );
if( !$calendar_month ) {
$today = strtotime('today');
$calendar_month = date( 'm', $today );
}
if( !$calendar_year ) {
$today = strtotime('today');
$calendar_year = date( 'y', $today );
}
$beginning_of_month_str = $calendar_year . '-' . str_pad($calendar_month, 2, "0", STR_PAD_LEFT) . '-' . '01';
$beginning_of_month = new DateTime($beginning_of_month_str);
$end_of_month = new DateTime($beginning_of_month_str);
$end_of_month->modify( 'last day of' );
$where_query = "CAST(start_datum.meta_value AS DATE) >= '" . $beginning_of_month->format('Y/m/d') . "'" . " AND CAST(start_datum.meta_value AS DATE) <= '" . $end_of_month->format('Y/m/d') . "'";
if ( !empty($zielgruppen) ) {
$zielgruppe_query = " AND zielgruppen.ID in (" . implode(', ', $zielgruppen) . ")";
$where_query .= $zielgruppe_query;
}
if ( !empty($formate) ) {
$formate_query = " AND veranstaltungsformate.ID in (" . implode(', ', $formate) . ")";
$where_query .= $formate_query;
}
if ( !empty($themenfelder) ) {
$themenfelder_query = " AND themenfelder.ID in (" . implode(', ', $themenfelder) . ")";
$where_query .= $themenfelder_query;
}
if ( !empty($spezials) ) {
$spezials_query = " AND spezials.ID in (" . implode(', ', $spezials) . ")";
$where_query .= $spezials_query;
}
$params = array(
'orderby' => 'start_datum ASC',
'limit' => 150,
'where' => $where_query
);
$pods = pods( 'veranstaltung', $params );
if ( $pods->total() <= 0 ) {
echo "In diesem Zeitraum mit diesem Filter keine Veranstaltungen";
}
if ( $pods->total() > 0 ) {
echo "<ul class=\"nodot divider\">";
}
while ( $pods->fetch() ) {
// reset id to use a single template
$pods->id = $pods->id();
echo $pods->template( 'Veranstaltung: Mini' );
//echo $pods->display( 'name' );
}
if ( $pods->total() > 0 ) {
echo "</ul>";
}
if ( $pods->total() == 150 ) {
echo "<b>Über 150 Veranstaltungen gefunden! Bitte die Auswahl über Filter weiter einschränken</b>";
}
return ob_get_clean();
}
add_shortcode('lfm_event_list_month', 'lfm_shortcode_event_list_month' );
/** Hop over all referentn and output their lastnames first letter. */
function lfm_shortcode_referentn_list() {
ob_start(); // Capture output in buffer, to return it later.
$params = array(
'orderby' => 'nachname',
'limit' => -1
);
$pods = pods( 'referentn', $params );
$current_first_letter = '';
if ( $pods->total() > 0 ) {
while( $pods->fetch() ) {
// reset id to use a single template
$pods->id = $pods->id();
$nachname = $pods->field( 'nachname' );
if (mb_substr($nachname, 0, 1, "UTF-8") != $current_first_letter) {
$current_first_letter = mb_substr( $nachname, 0, 1, "UTF-8" );
echo "<h2>" . $current_first_letter . "</h2>";
}
$temp = $pods->template( 'Referent: Mini' );
// Output rendered template if it exists
if ( isset( $temp ) ) {
//echo $pods->display( 'nachname' );
echo $temp;
//echo $pods->field('nachname');
}
}
// Pagination
echo $pods->pagination();
}
else {
echo 'No content found.';
}
$output = ob_get_clean();
return $output;
}
add_shortcode('lfm_referentn_list', 'lfm_shortcode_referentn_list' );
/**
* Shortcode to display the highlight Veranstaltung.
*/
function lfm_shortcode_highlight_veranstaltung($atts=[], $content=null, $tag='') {
// normalize attribute keys, lowercase
// allthough we otherwise ignore them.
$atts = array_change_key_case((array)$atts, CASE_LOWER);
// Array of ids of veranstaltung (shall be one only)
$highlight_veranstaltung = get_option( 'lernorte_hilfe-texte_highlight_veranstaltung' );
$params = array( 'limit' => -1 );
$pods = pods( 'veranstaltung', $params );
// Grab first id in the options array.
$pods->fetch( reset( $highlight_veranstaltung ) );
$pods->id = $pods->id();
/* Will have to guard this (and also empty option array above) */
$temp = $pods->template( 'Highlight-Veranstaltung' );
return $temp;
}
add_shortcode('lfm_highlight_veranstaltung',
'lfm_shortcode_highlight_veranstaltung' );
?>