PluginProbe
Yatra – Travel Booking & Tour Operator Software / 2.1.16
Yatra – Travel Booking & Tour Operator Software v2.1.16
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / includes / yatra-misc-functions.php

yatra-misc-functions.php in Yatra – Travel Booking & Tour Operator Software 2.1.16, at includes/yatra-misc-functions.php

360 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!function_exists('yatra_get_discount_deals_lists')) {
3
4 function yatra_get_discount_deals_lists($atts = array())
5 {
6 $order = isset($atts['order']) ? sanitize_text_field($atts['order']) : 'DESC';
7
8 $order = in_array(strtolower($order), array('asc', 'desc')) ? $order : 'desc';
9
10 $posts_per_page = isset($atts['posts_per_page']) ? intval($atts['posts_per_page']) : 9;
11
12 $columns = isset($atts['columns']) ? absint($atts['columns']) : 3;
13
14 $current_page = isset($atts['current']) ? absint($atts['current']) : 1;
15
16 $current_page = $current_page < 1 ? 1 : $current_page;
17
18 $args = array(
19 'meta_query' => array(
20 array(
21 'key' => 'yatra_tour_meta_sales_price',
22 'value' => array('', 0),
23 'compare' => 'NOT IN'
24 )
25 ),
26
27 'post_type' => 'tour',
28
29 'order' => $order,
30
31 'posts_per_page' => -1,
32
33 'post_status' => 'publish'
34 );
35
36
37 $query = new WP_Query($args);
38
39 $post_count = is_wp_error($query) ? 0 : $query->post_count;
40
41 $total_page = $posts_per_page < 1 ? 0 : ceil($post_count / $posts_per_page);
42
43 $current_page = $total_page < $current_page ? 1 : $current_page;
44
45 if ($posts_per_page > 0) {
46
47 $args['posts_per_page'] = $posts_per_page;
48
49 }
50
51 $args['offset'] = ($current_page - 1) * $posts_per_page;
52
53 $posts = get_posts($args);
54
55 $grid_class = 'yatra-col-sm-6 ';
56
57 switch ($columns) {
58 case 2:
59 $grid_class .= 'yatra-col-md-6';
60 break;
61 case 3:
62 $grid_class .= 'yatra-col-md-4';
63 break;
64 case 4:
65 $grid_class .= 'yatra-col-md-3';
66 break;
67 default:
68 $grid_class .= 'yatra-col-md-4';
69 }
70
71 echo '<div class="yatra-discount-deals-list-container">';
72
73 echo '<div class="yatra-row yatra-discount-deals-wrap">';
74
75 foreach ($posts as $item) {
76
77 $data['data'] = array(
78 'id' => $item->ID,
79 'title' => $item->post_title,
80 'excerpt' => $item->post_excerpt,
81 'permalink' => get_permalink($item->ID),
82 'image' => '',
83 'class' => $grid_class
84 );
85
86 $attachment_id = (int)get_post_thumbnail_id($item);
87
88 if (($attachment_id) > 0) {
89
90 $attachment_link = wp_get_attachment_image_url($attachment_id, 'full');
91
92 $data['data']['image'] = $attachment_link;
93 }
94
95 yatra_get_template('tmpl-deals-item.php', $data);
96
97 }
98 echo '</div>';
99
100 yatra_get_template('parts/pagination.php', [
101 'total' => $total_page,
102 'current' => $current_page,
103 'base' => '',
104 'format' => '',
105 'class' => 'yatra-ajax-pagination',
106 'attributes' => $atts,
107 'type' => 'discount-deal'
108 ]);
109
110 echo '</div>';
111
112 }
113
114 }
115
116 if (!function_exists('yatra_get_tour_lists')) {
117
118 function yatra_get_tour_lists($atts = array())
119 {
120 $order = isset($atts['order']) ? sanitize_text_field($atts['order']) : 'DESC';
121
122 $order = in_array(strtolower($order), array('asc', 'desc')) ? $order : 'desc';
123
124 $featured = isset($atts['featured']) ? absint($atts['featured']) : 2;
125
126 $posts_per_page = isset($atts['posts_per_page']) ? intval($atts['posts_per_page']) : 9;
127
128 $columns = isset($atts['columns']) ? absint($atts['columns']) : 3;
129
130 $current_page = isset($atts['current']) ? absint($atts['current']) : 1;
131
132 $current_page = $current_page < 1 ? 1 : $current_page;
133
134 $meta_query = array();
135
136 switch ($featured) {
137
138 case 0:
139 $meta_query[] =
140
141 array(
142 'relation' => 'OR',
143 array(
144 'key' => 'yatra_tour_meta_tour_featured',
145 'value' => array(1, '1'),
146 'compare' => 'NOT IN'
147 ),
148 array(
149 'key' => 'yatra_tour_meta_tour_featured',
150 'compare' => 'NOT EXISTS',
151 'value' => 'null',
152 )
153 );
154 break;
155
156 case 1:
157 $meta_query[] =
158 array(
159 'key' => 'yatra_tour_meta_tour_featured',
160 'value' => array(1, '1'),
161 'compare' => 'IN'
162
163 );
164 break;
165 }
166
167 $args = array(
168 'post_type' => 'tour',
169 'order' => $order,
170 'posts_per_page' => -1,
171 'post_status' => 'publish'
172 );
173
174
175 if (count($meta_query) > 0) {
176
177 $args['meta_query'] = $meta_query;
178 }
179
180 $query = new WP_Query($args);
181
182 $post_count = is_wp_error($query) ? 0 : $query->post_count;
183
184 $total_page = $posts_per_page < 1 ? 0 : ceil($post_count / $posts_per_page);
185
186 $current_page = $total_page < $current_page ? 1 : $current_page;
187
188 if ($posts_per_page > 0) {
189
190 $args['posts_per_page'] = $posts_per_page;
191
192 }
193
194 $args['offset'] = ($current_page - 1) * $posts_per_page;
195
196 $post_items = get_posts($args);
197
198 $grid_class = 'yatra-col-sm-6 ';
199
200 switch ($columns) {
201 case 2:
202 $grid_class .= 'yatra-col-md-6';
203 break;
204 case 3:
205 $grid_class .= 'yatra-col-md-4';
206 break;
207 case 4:
208 $grid_class .= 'yatra-col-md-3';
209 break;
210 default:
211 $grid_class .= 'yatra-col-md-4';
212 }
213
214 echo '<div class="yatra-tour-list-container">';
215
216 echo '<div class="yatra-row yatra-tour-list-wrap">';
217
218 foreach ($post_items as $item) {
219
220 $data['data'] = array(
221 'id' => $item->ID,
222 'title' => $item->post_title,
223 'excerpt' => $item->post_excerpt,
224 'permalink' => get_permalink($item->ID),
225 'image' => '',
226 'class' => $grid_class,
227 );
228
229 $attachment_id = (int)get_post_thumbnail_id($item);
230
231 if (($attachment_id) > 0) {
232
233 $attachment_link = wp_get_attachment_image_url($attachment_id, 'full');
234
235 $data['data']['image'] = $attachment_link;
236 }
237
238 yatra_get_template('tmpl-tour-item.php', $data);
239
240 }
241
242 echo '</div>';
243
244
245 yatra_get_template('parts/pagination.php', [
246 'total' => $total_page,
247 'current' => $current_page,
248 'base' => '',
249 'format' => '',
250 'class' => 'yatra-ajax-pagination',
251 'attributes' => $atts,
252 'type' => 'tour'
253 ]);
254
255 echo '</div>';
256
257
258 }
259
260 }
261
262 function yatra_export($args = array())
263 {
264 $defaults = array(
265
266 'content' => array(),
267
268 );
269
270 $args = wp_parse_args($args, $defaults);
271
272 do_action('export_yatra', $args);
273
274 $sitename = strtolower(sanitize_key(get_bloginfo('name')));
275
276 if (!empty($sitename)) {
277
278 $sitename .= '.';
279 }
280
281 $content = $args['content'];
282
283 $content = is_string($content) ? $content : json_encode($content);
284
285 $date = gmdate('Y-m-d');
286
287 $wp_filename = $sitename . 'yatra.' . $date . '.json';
288
289 $filename = apply_filters('export_wp_filename', $wp_filename, $sitename, $date);
290
291 header('Content-Description: File Transfer');
292
293 header('Content-Disposition: attachment; filename=' . $filename);
294
295 header('Content-Type: text/json; charset=' . get_option('blog_charset'), true);
296
297 echo $content;
298
299 exit;
300
301 }
302
303 if (!function_exists('yatra_get_tour_view_details_button_text')) {
304 function yatra_get_tour_view_details_button_text()
305 {
306 return get_option('yatra_tour_view_details_button_text', __('View Details', 'yatra'));
307 }
308 }
309
310 if (!function_exists('yatra_is_tour_fixed_departure')) {
311 function yatra_is_tour_fixed_departure($tour_id)
312 {
313 $fixed_departure = (boolean)get_post_meta($tour_id, 'yatra_tour_meta_tour_fixed_departure', true);
314
315 $yatra_tour_availability = yatra_tour_meta_availability_date_ranges($tour_id);
316
317 if (!$fixed_departure || (count($yatra_tour_availability) < 1)) {
318
319 return false;
320
321 }
322 return true;
323 }
324 }
325
326
327 if (!function_exists('yatra_user_can_modify_booking')) {
328
329 function yatra_user_can_modify_booking($booking_id, $user_id = null)
330 {
331 $booking_id = absint($booking_id);
332
333 $user_id = $user_id === null ? get_current_user_id() : ($user_id);
334
335 $user_id = (int)($user_id);
336
337 if ($booking_id < 1 || $user_id < 1) {
338
339 return false;
340 }
341
342 $meta_user_id = (int)(get_post_meta($booking_id, 'yatra_user_id', true));
343
344 if ($meta_user_id < 1) {
345 return false;
346 }
347 if ($user_id === $meta_user_id) {
348
349 return true;
350 }
351 return false;
352 }
353 }
354 if (!function_exists('yatra_get_premium_addons')) {
355
356 function yatra_get_premium_addons()
357 {
358 return apply_filters('yatra_premium_addons', array());
359 }
360 }