PluginProbe
WPPizza – A Restaurant Plugin / 3.20
WPPizza – A Restaurant Plugin v3.20
trunk 2.16.11.28 3.19 3.19.1 3.19.2 3.19.3 3.19.4 3.19.5 3.19.6 3.19.7 3.19.7.1 3.19.7.2 3.19.7.3 3.19.7.4 3.19.8 3.19.8.1 3.19.8.2 3.19.8.3 3.19.9 3.20 3.20.1
wppizza / classes / markup / loop.php

loop.php in WPPizza – A Restaurant Plugin 3.20, at classes/markup/loop.php

2,916 lines 95.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_TEMPLATES_MENU_ITEMS Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPizza display menu items (loop)
7 * @copyright Copyright (c) 2015, Oliver Bach
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 3.0
10 *
11 */
12 if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/
13
14 /* ================================================================================================================================= *
15 *
16 *
17 *
18 * CLASS - WPPIZZA_TEMPLATES_MENU_ITEMS
19 *
20 *
21 *
22 * ================================================================================================================================= */
23
24 class WPPIZZA_MARKUP_MENU_ITEMS{
25
26 private $wppizza_terms = array();/*as we might need to access t his in several places, just get it once for all*/
27 private $wppizza_terms_by_slug = array();
28 /***************************************************************************************************************
29 *
30 *
31 * [construct]
32 *
33 *
34 ****************************************************************************************************************/
35 function __construct() {
36 /* get sorted categories */
37 add_action('init', array($this,'get_wppizza_terms'));
38
39 /**
40 markup modules
41 **/
42 /*header before loop*/
43 add_filter('wppizza_filter_menu_header', array($this, 'wppizza_filter_menu_header'), 10, 6 );
44
45 /*
46 loop item elemens are added by doing
47 'wppizza_filter_menu_loop_'.$element.'
48 available elements are set by adding them to set_template_elements() -> $available_elements
49 then add required filter and create output like so (if element is xyz)
50 add_filter('wppizza_filter_menu_loop_xyz', array($this, 'wppizza_filter_menu_loop_xyz'), 10, 8 );
51 and create function as for the others
52 */
53
54 /*in loop - article element open*/
55 add_filter('wppizza_filter_menu_loop_article_open', array($this, 'wppizza_filter_menu_loop_article_open'), 10, 8 );
56 /*in loop - title*/
57 add_filter('wppizza_filter_menu_loop_title', array($this, 'wppizza_filter_menu_loop_title'), 10, 8 );
58 /*in loop - thumbnail*/
59 add_filter('wppizza_filter_menu_loop_thumbnail', array($this, 'wppizza_filter_menu_loop_thumbnail'), 10, 8 );
60 /*in loop - category*/
61 add_filter('wppizza_filter_menu_loop_category', array($this, 'wppizza_filter_menu_loop_category'), 10, 8 );
62 /*in loop - prices*/
63 add_filter('wppizza_filter_menu_loop_prices', array($this, 'wppizza_filter_menu_loop_prices'), 10, 8 );
64 /*in loop - content*/
65 add_filter('wppizza_filter_menu_loop_content', array($this, 'wppizza_filter_menu_loop_content'), 10, 8 );
66 /*in loop - additives*/
67 add_filter('wppizza_filter_menu_loop_additives', array($this, 'wppizza_filter_menu_loop_additives'), 10, 8 );
68 /*in loop - foodtype*/
69 add_filter('wppizza_filter_menu_loop_foodtype', array($this, 'wppizza_filter_menu_loop_foodtype'), 10, 8 );
70 /*in loop - permalink*/
71 add_filter('wppizza_filter_menu_loop_permalink', array($this, 'wppizza_filter_menu_loop_permalink'), 10, 8 );
72 // /*in loop - single post - comments*/
73 // add_filter('wppizza_filter_menu_loop_comments', array($this, 'wppizza_filter_menu_loop_comments'), 10, 8 );
74 /*in loop - article element close*/
75 add_filter('wppizza_filter_menu_loop_article_close', array($this, 'wppizza_filter_menu_loop_article_close'), 10, 8 );
76 /*no results - instead of loop*/
77 add_filter('wppizza_filter_menu_no_results', array($this, 'wppizza_filter_menu_no_results'), 10, 6 );
78 /*additives after loop*/
79 add_filter('wppizza_filter_menu_additives', array($this, 'wppizza_filter_menu_additives'), 10, 6 );
80 /*pagination after loop*/
81 add_filter('wppizza_filter_menu_pagination', array($this, 'wppizza_filter_menu_pagination'), 10, 6 );
82
83 }
84
85 /***********************************************************************************************************************************************************
86 *
87 *
88 *
89 *
90 * [ get / build queries and markup based on attributes and type set in shortcodes ]
91 *
92 *
93 *
94 * return array
95 ***********************************************************************************************************************************************************/
96 function markup($atts = null, $type = null){
97
98
99 $markup='';
100
101 /***********************************************
102 *
103 * regular loops
104 *
105 ***********************************************/
106 if(empty($type) && (!isset($atts['bestsellers']) && !isset($atts['single']) )){
107 global $wppizza_options;
108
109 /***********************************
110 set type to ident type of shortcode
111 ***********************************/
112 $type = 'category';
113
114 /***********************************
115 get all categories by slug
116 ***********************************/
117 $all_categories=$this->get_wppizza_terms_by_slug();
118
119 /***********************************
120 omit cats without menu items if set
121 ***********************************/
122 $omit_empty_categories = !empty($wppizza_options['layout']['omit_empty_categories']) ? true : false ;
123 if($omit_empty_categories){
124 if(!empty($all_categories)){
125 foreach($all_categories as $cat_key => $cat_array){
126 if(empty($cat_array['count'])){
127 unset($all_categories[$cat_key]);
128 }
129 }
130 }
131 }
132
133
134 /***********************************
135 get set categories
136 ***********************************/
137 if(!empty($atts['category'])){
138 $category_slugs = explode(',',$atts['category']);
139 }
140
141 /***********************************
142 get first category if not set
143 ***********************************/
144 if(empty($atts['category'])){
145 $first_category = reset($all_categories);
146 $category_slugs = array($first_category['slug']);
147 }
148 /***********************************
149 set slugs depending on exclusion and !all, sorted by category sort
150 ***********************************/
151 if(in_array('!all', $category_slugs)){
152
153 /**get all sorted ones first */
154 $set_categories=$all_categories;
155 /**check if we are excluding some categories**/
156 foreach($category_slugs as $sKey=>$slug){
157 if(substr($slug,0,1)=='-'){
158 $excl_slug = trim(substr($slug,1));
159 unset($set_categories[$excl_slug]);
160 }
161 }
162 /*set resulting**/
163 $category_slugs = array_keys($set_categories);
164 /**force posts per page to be -1 when using !all*/
165 $posts_per_page = -1;
166 }
167
168 /**
169 force navigation to be off
170 when displaying multiple categories
171 /*to check, should also be done by number of shortcodes on page i guess
172 **/
173 if(count($category_slugs)>1){
174 $atts['no_pagination'] = true;
175 }
176
177 /**********************************************
178 enable accordion ?
179 (shortcode attributes to override globals)
180 **********************************************/
181 if(isset($atts['accordion'])){
182 if(empty($atts['accordion'])){
183 unset($atts['accordion']);
184 }else{
185 $atts['accordion'] = true;
186 }
187 }
188 elseif(!empty($wppizza_options['layout']['category_accordion']) ){
189 $atts['accordion'] = true;
190 }
191 //only ever do accordion if more than one category
192 if(!empty($category_slugs) && count($category_slugs) <=1){
193 unset($atts['accordion']);
194 }
195
196 // if set to accordion remove any 'noheader' attribute (as the category header is required for the accordion to work
197 if(!empty($atts['accordion'])){
198 unset($atts['noheader']);
199 }
200
201 /***********************************
202 run the query for each category slug
203 provided it exists in the first place
204 ***********************************/
205 foreach($category_slugs as $slug){
206
207 if(!empty($all_categories[$slug])){
208 /**
209 set category id and slug to refer to later
210 **/
211 $category = array('id' => $all_categories[$slug]['id'], 'slug'=> $slug , 'name'=> $all_categories[$slug]['name'], 'description'=> $all_categories[$slug]['description'] );
212
213 /**
214 set arguments for query
215 **/
216 $query_args = array();
217 $query_args['posts_per_page'] = !empty($posts_per_page) ? $posts_per_page : $wppizza_options['layout']['items_per_loop'] ;
218 $query_args['exclude'] = (empty($atts['exclude']) || !empty($atts['include']) )? array() : array_unique(explode(',',$atts['exclude']));/*include, overrides exclude*/
219 $query_args['include'] = !empty($atts['include']) ? array_unique(explode(',',$atts['include'])) : array();
220 $query_args['tax_query']['field'] = 'slug';
221 $query_args['tax_query']['terms'] = strtolower(trim($slug));
222
223 /**
224 run the query
225 **/
226 $query_results = $this->get_query_results($query_args);
227
228 /**
229 set markup parameters
230 **/
231 $parameters = $this->set_markup_parameters($query_results, $atts, $type, $category);
232
233 /**
234 get markup by parameters set . looped, so MUST BE CONCAT
235 **/
236 $markup .= $this->get_markup_by_arguments($parameters);
237 }
238 }
239
240 /*
241 add accordion wrapper
242 (div) if enabled
243 */
244 if(!empty($atts['accordion'])){
245 $markup = PHP_EOL . '<div class="'.WPPIZZA_SLUG.'_accordion">' . PHP_EOL . $markup . PHP_EOL .'</div>';
246 }
247
248 return $markup;
249 }
250
251 /***********************************************
252 *
253 * single item
254 *
255 ***********************************************/
256 if(empty($type) && isset($atts['single']) ){
257 /***********************************
258 set type to ident type of shortcode
259 ***********************************/
260 $type = 'single';
261
262 /***********************************
263 get all categories by slug
264 ***********************************/
265 $all_categories=$this->get_wppizza_terms_by_slug();
266
267 /************************************
268 set arguments for query
269 ************************************/
270
271 /*allow to pass comma separated array*/
272 $selected_items = explode(',',$atts['single']);
273
274 /*if array, trim and cast to integer*/
275 $single_items_array = array();
276 foreach($selected_items as $selected_item){
277 $id=(int)trim($selected_item);
278 $single_items_array[$id]=$id;/*automatically remove duplicates*/
279 }
280
281 $query_args['include'] = $single_items_array;
282 $query_args['orderby'] = 'post__in';
283
284 /************************************
285 run the query
286 ************************************/
287 $query_results = $this->get_query_results($query_args);
288
289
290 /************************************
291 set markup parameters
292 ************************************/
293 $parameters = $this->set_markup_parameters($query_results, $atts, $type, false);
294
295
296 /************************************
297 allow to only show some/one price(s)
298 when using single items shortcode
299 by using $atts['price_id']
300 provided $atts[single] only refers to one single menu item
301 (at least one of the id's in $atts['price_id'] must exist for this item)
302 DONT USE !empty($atts['price_id']) as they can be 0 !!
303 ************************************/
304
305 if(isset($atts['price_id']) && $atts['price_id']!='' && count($selected_items) >= 1){
306
307 /*
308 create prices id (aka sizes) array
309 associated with each post id
310 */
311 $price_ids = explode(',' , $atts['price_id']);
312 $price_id_sizes = array();
313 foreach($selected_items as $k => $pid){
314 $price_id_sizes[$k][$pid] = explode(':',$price_ids[$k]);//allow multiple sizes for single item (using : )
315 }
316
317 /*
318 make returned zero indexed post ids to equate actual post id's to be able to map
319 sizes_ids to post ids
320 */
321 $sc_post_ids = array_map(function($val){return $val->ID;}, $parameters['posts']);
322 $parameters['posts'] = array_combine($sc_post_ids , $parameters['posts']);
323 $sc_posts = array_combine($sc_post_ids , $parameters['posts']);
324
325
326 $reset_post_data = array();
327 foreach($price_id_sizes as $k => $sizes_in_post){
328 foreach($sizes_in_post as $pid => $sizes){
329
330 $post_data = (array)$sc_posts[$pid];//sc_posts MUST be converted to array or it will all go horribly wrong
331
332 $reset_post_data[$k] = $post_data;
333 if(!empty($post_data['wppizza_data']['prices'])){//php8 to avoid fatals
334 $intersect = array_intersect_key($post_data['wppizza_data']['prices'], array_flip($sizes));
335 }
336 if(!empty($intersect)){
337 $reset_post_data[$k]['wppizza_data']['prices'] = $intersect;
338 }
339 }
340 }
341
342 /*
343 add (back) to parameters as object
344 */
345 $parameters['posts'] = array();
346 foreach($reset_post_data as $k => $data){
347 $parameters['posts'][$k] = (object)$reset_post_data[$k];
348 }
349 }
350
351 /***********************************
352 get markup by parameters set
353 ***********************************/
354 $markup = $this->get_markup_by_arguments($parameters);
355
356
357
358 return $markup;
359 }
360
361
362 /***********************************************
363 *
364 * bestsellers
365 *
366 ***********************************************/
367 if(empty($type) && isset($atts['bestsellers']) ){
368
369 /***********************************
370 set type to iden type of shortcode
371 ***********************************/
372 $type = 'bestsellers';
373
374 /***********************************
375 get bestsellers from options
376 and/or reindex new orders once a day
377 ***********************************/
378 $default_bestsellers_cache = array(
379 'last_update' => 0,
380 'next_update' => 0,
381 'orders_indexed' => 0,
382 'indexed_upto_id' => 0 ,
383 'bestsellers' => array(),
384 );
385 $bestsellers_cache = get_option(WPPIZZA_SLUG.'_bestsellers', $default_bestsellers_cache);
386
387 // current bestsellers as stored in options
388 $bestsellers = $bestsellers_cache['bestsellers'];
389
390 /*
391 update cache if next update timestamp has passed
392 or if it's the first time (as ts next_update is set to 0 )
393 */
394 $forceIndex = apply_filters('wppizza_force_bestseller_index', false);//dev only
395 if($bestsellers_cache['next_update'] < WPPIZZA_WP_TIME || $forceIndex){
396
397 /********************** set bestsellers *****************************/
398 global $wpdb;
399 /**wppizza posts to compare against, making sure posts still exists**/
400 $wppPostsQuery = $wpdb->prepare("SELECT ID FROM ".$wpdb->prefix ."posts where post_type='%s' AND post_status='publish' ", WPPIZZA_POST_TYPE );
401 $wppPostsRes = $wpdb->get_results($wppPostsQuery,OBJECT_K );
402
403 /**
404 run the query
405 limit to 10000 , should be plenty enough, but stops silly memory consumption on first index
406 (if anyone has more than 10000 orders per day, they probably want a different system)
407 **/
408 $bestsellersQuery=$wpdb->prepare("SELECT id, order_ini FROM ".$wpdb->prefix . WPPIZZA_TABLE_ORDERS." WHERE payment_status='COMPLETED' AND id > %d ORDER BY id desc LIMIT 0, 10000 ", $bestsellers_cache['indexed_upto_id']);
409 $bestsellersRes = $wpdb->get_results($bestsellersQuery);
410
411
412 //set the last indexed here to start off with
413 $bestsellersIndexed = array($bestsellers_cache['indexed_upto_id']);
414
415 /**
416 loop through items and get/add quantities
417 **/
418 foreach($bestsellersRes as $b=>$bs){
419
420 //indexed order id up to here
421 $bestsellersIndexed[$bs->id] = $bs->id;
422
423 $thisOrderDetails=maybe_unserialize($bs->order_ini);
424 if(isset($thisOrderDetails['items']) && is_array($thisOrderDetails['items'])){
425 foreach($thisOrderDetails['items'] as $item){
426 /**make sure this post still exists and has been sold more than 0 times**/
427 if(!empty($item['post_id']) && isset($wppPostsRes[$item['post_id']]) && $item['quantity']>0){
428 if(!isset($bestsellers[$item['post_id']])){
429 $bestsellers[$item['post_id']] = $item['quantity'];
430 }else{
431 $bestsellers[$item['post_id']] += $item['quantity'];
432 }
433 }
434 }
435 }
436
437 }
438
439 /*sort by quantity*/
440 arsort($bestsellers);
441
442
443 //update cache / option
444 $bestsellers_cache = array(
445 'last_update' => WPPIZZA_WP_TIME,
446 'next_update' => (WPPIZZA_WP_TIME + (24 * 60 * 60)),//once a day should do one would think
447 'orders_indexed' => (!empty($bestsellersRes) ? ($bestsellers_cache['orders_indexed'] + count($bestsellersRes) ) : $bestsellers_cache['orders_indexed'] ),
448 'indexed_upto_id' => !empty($bestsellersIndexed) ? max($bestsellersIndexed) : 0 ,
449 'bestsellers' => $bestsellers,
450 );
451 //update option
452 update_option(WPPIZZA_SLUG.'_bestsellers', $bestsellers_cache);
453 }
454
455
456 /**remove distinctly set excludes (if any)**/
457 if(!empty($atts['exclude'])){
458 $bestsellers_exclude = array_flip(array_unique(explode(',',$atts['exclude'])));
459 $bestsellers = array_diff_key($bestsellers, $bestsellers_exclude);
460 }
461
462 /*chunk to required bits*/
463 $chunks=(int)$atts['bestsellers'];
464 $bestsellers=array_chunk($bestsellers, $chunks, true);
465
466
467 /**get bestsellers**/
468 $set_bestsellers = array();
469 if(count($bestsellers)>0){
470 /**required bestsellers - first chunk**/
471 $set_bestsellers=array_keys($bestsellers[0]);
472 }
473 /**add distinctly set includes (if any)**/
474 if(isset($atts['include']) && $atts['include']!=''){
475 $set_bestsellers = array_merge($set_bestsellers, explode(',',$atts['include']));
476 }
477 //alternatives if empty*/
478 if(count($set_bestsellers)<=0 && isset($atts['ifempty'])){
479 $set_bestsellers = explode(',',$atts['ifempty']);
480 }
481 /* make them unique in case $atts['include'] duplicates id's */
482 $set_bestsellers = array_unique($set_bestsellers);
483
484
485 /************************************
486 set arguments for query
487 ************************************/
488 /*if array, trim and cast to integer*/
489 $single_items_array = array();
490 foreach($set_bestsellers as $selected_item){
491 $id=(int)trim($selected_item);
492 $single_items_array[$id]=$id;/*automatically remove duplicates*/
493 }
494
495 $query_args['include'] = $single_items_array;
496 $query_args['orderby'] = 'post__in';
497
498
499 /************************************
500 run the query
501 ************************************/
502 $query_results = $this->get_query_results($query_args);
503
504
505 /************************************
506 set markup parameters
507 ************************************/
508 $atts['noheader'] = 1 ; /**force omit header for bestsellers */
509 $parameters = $this->set_markup_parameters($query_results, $atts, $type, false);
510
511 /***********************************
512 get markup by parameters set
513 ***********************************/
514 $markup = $this->get_markup_by_arguments($parameters);
515
516 return $markup;
517 }
518
519
520 /***********************************************
521 *
522 * type = add_item_to_cart_button
523 *
524 ***********************************************/
525 if(!empty($type) && $type == 'add_item_to_cart_button'){
526 $markup = $this->add_item_to_cart_button($atts);
527 return $markup;
528 }
529
530 /*script should never get here, but just for the hell of it*/
531 return $markup;
532 }
533
534 /***********************************************************************************************************************************************************
535 *
536 *
537 *
538 *
539 * [ build and run the query ]
540 *
541 *
542 *
543 * return array
544 ***********************************************************************************************************************************************************/
545 function get_query_results($query_args){
546 global $wppizza_options;
547
548 /**
549 set query args
550 **/
551 $args = array();
552 $args['post_type'] = WPPIZZA_POST_TYPE ;
553 $args['posts_per_page'] = !empty($query_args['posts_per_page']) ? $query_args['posts_per_page'] : $wppizza_options['layout']['items_per_loop'] ;
554 $args['paged'] = $this->set_paged_var();
555 $args['post__not_in'] = !empty($query_args['exclude']) ? $query_args['exclude'] : '' ;
556 $args['post__in'] = !empty($query_args['include']) ? $query_args['include'] : '' ;
557
558 /**
559 omit tax query if not set (single items for example)
560 **/
561 if(!empty($query_args['tax_query'])){
562 $args['tax_query'] = array() ;
563 $args['tax_query'][0]['taxonomy'] = WPPIZZA_TAXONOMY ;
564 $args['tax_query'][0]['field'] = !empty($query_args['tax_query']['field']) ? $query_args['tax_query']['field'] : 'slug' ;
565 $args['tax_query'][0]['terms'] = !empty($query_args['tax_query']['terms']) ? $query_args['tax_query']['terms'] : array() ;
566 $args['tax_query'][0]['include_children'] = false ;
567 }
568
569 $args['orderby'] = !empty($query_args['orderby']) ? $query_args['orderby'] : 'menu_order' ;
570 $args['order'] = !empty($query_args['order']) ? $query_args['order'] : 'ASC' ;
571
572 /**
573 apply filters if required
574 **/
575 $args = apply_filters('wppizza_filter_loop_args', $args);
576
577 /**
578 execute query
579 **/
580 $the_query = new WP_Query( $args );
581
582 /**
583 return results
584 **/
585 return $the_query;
586 }
587
588 /***********************************************************************************************************************************************************
589 *
590 *
591 *
592 *
593 * [ set parameters to build markup ]
594 *
595 *
596 *
597 * return array
598 ***********************************************************************************************************************************************************/
599 function set_markup_parameters($query_results, $atts, $type, $category = false){
600 global $wppizza_options;
601
602 /*
603 set currency symbol
604 */
605 $currency_symbol = $wppizza_options['order_settings']['currency_symbol'];
606 /*
607 set blogid
608 */
609 global $blog_id;
610
611 /*
612 get wppizza categories
613 */
614 $get_wppizza_terms = get_terms(WPPIZZA_TAXONOMY);
615 /*
616 get templeta vars from
617 from helper function
618 */
619 $style = $this -> set_template_style($atts);
620 $accordion = !empty($atts['accordion']) ? true : false ;
621 $item_class = $this -> set_template_item_class($atts);
622 $elements = $this -> set_template_elements($atts, $style);
623 $attributes = $this -> set_template_attributes($atts);/*includes currency position next to prices*/
624
625
626 /*********************
627 ini return array
628 **********************/
629 $parameters = array();
630
631 /**********************************************
632 *
633 *
634 * add global parameters
635 *
636 *
637 **********************************************/
638 $parameters['global']['shortcode_type'] = $type;
639
640 $parameters['global']['rtl'] = is_rtl() ? true : false ;/*add right to left class if required*/
641 $parameters['global']['blog_id'] = $blog_id;
642 $parameters['global']['post_count'] = $query_results->post_count;
643 $parameters['global']['max_num_pages'] = $query_results->max_num_pages;
644
645 $parameters['global']['categoy'] = $category;
646
647 $parameters['global']['allergens'] = array(); /*holds all allergens for all posts returned by query */
648 $parameters['global']['additives'] = array(); /*holds all additives for all posts returned by query */
649 $parameters['global']['foodtype'] = array(); /*holds all foodtype for all posts returned by query */
650
651
652 /** include/exclude from display **/
653 $parameters['global']['include']['header'] = ( empty($category) || !empty($atts['noheader']) || !empty($wppizza_options['layout']['suppress_loop_headers'])) ? false : true; /* show header if we have a category and atts[noheader] is not defined*/
654 $parameters['global']['include']['loop'] = !empty($query_results->post_count) ? true : false; /* include loop, else include noresults */
655 $parameters['global']['include']['no_results'] = empty($query_results->post_count) ? true : false; /* include noresults */
656 $parameters['global']['include']['additives'] = isset($atts['showadditives']) ? wppizza_validate_boolean($atts['showadditives']) : 'auto' ;/*set bool if defined or 'auto' to override below as required*/
657 $parameters['global']['include']['pagination'] = (!empty($atts['no_pagination']) || $query_results->max_num_pages <= 1) ? false : true;
658 $parameters['global']['include']['viewonly'] = !empty($atts['viewonly']) ? true : false;
659
660
661 /** individual template overrides **/
662 $parameters['global']['template'] = array();
663 $parameters['global']['template']['style'] = $style;
664 $parameters['global']['template']['accordion'] = $accordion ;
665 $parameters['global']['template']['item_class'] = $item_class;
666 $parameters['global']['template']['elements'] = $elements;
667 $parameters['global']['template']['attributes'] = $attributes;
668 //$parameters['global']['template']['elements_exclude'] = $elements_exclude;
669 //$parameters['global']['template']['elements_include'] = $elements_include;
670
671
672
673
674 /**********************************************
675 *
676 *
677 * add posts parameters
678 *
679 *
680 **********************************************/
681 $parameters['posts'] = array();
682 /*****
683 *
684 * add wppizza meta data, category_id and showing additives (y/n) to post object
685 *
686 *****/
687
688 foreach($query_results -> posts as $key=>$post){
689
690
691 /*
692 add standard WP post object first of all
693 */
694 $parameters['posts'][$key] = $post;
695 /*
696 custom add - has thumbnail ?
697 */
698 $parameters['posts'][$key]->has_post_thumbnail = has_post_thumbnail( $post->ID );
699
700 /*
701 custom add - title stripped of html
702 */
703 $parameters['posts'][$key]->the_title_attribute = the_title_attribute(array('post'=>$post->ID, 'echo'=>0));
704
705 /*
706 custom add - permalink
707 */
708 $parameters['posts'][$key]->permalink = get_permalink( $post->ID );
709
710 /*
711 custom add - blogid
712 */
713 $parameters['posts'][$key]->blog_id = $blog_id;
714
715 /*
716 strip all tags of content if notags attribute set
717 */
718 $parameters['posts'][$key]->post_content = !empty($atts['notags']) ? wp_strip_all_tags( $post->post_content ) : $post->post_content ;
719
720 /*
721 custom add
722 get and add wppizza metadata - allow filtering
723 */
724 $wppizza_metadata = apply_filters('wppizza_filter_loop_meta',get_post_meta($post->ID, WPPIZZA_POST_TYPE, true ), $post->ID);
725 $parameters['posts'][$key]->wppizza_data = $wppizza_metadata;
726
727 /*
728 add sizes, prices (as 'value') / formatted prices (as 'price') , labels (as size)- overwriting original price meta
729 */
730 foreach($wppizza_metadata['prices'] as $price_key=>$price){
731 $parameters['posts'][$key]->wppizza_data['prices'][$price_key] = array(
732 'value' => $price,
733 'price' => wppizza_format_price($price, $currency_symbol, $attributes['currency_price']),
734 'size' => $wppizza_options['sizes'][$wppizza_metadata['sizes']][$price_key]['lbl']
735 ); //$wppizza_options['sizes']
736
737 }
738
739
740 /*
741 add allergens, overwriting original when done
742 */
743 if(!empty($wppizza_metadata['allergens']) && count($wppizza_metadata['allergens'])>0){
744
745 $post_allergens = array();
746
747 $post_has_allergens_icon = false;
748
749 foreach($wppizza_metadata['allergens'] as $allergen_id){
750
751 $allergen_icon = '' ;
752
753 if(!empty($wppizza_options['allergens'][$allergen_id]['icon']) && !empty($wppizza_options['allergens'][$allergen_id]['iconintitle']) ){
754 $allergen_icon = $wppizza_options['allergens'][$allergen_id]['icon'] ;
755 $post_has_allergens_icon = true;
756 }
757
758 $post_allergens[$allergen_id]= array(
759 'sort'=>$wppizza_options['allergens'][$allergen_id]['sort'],
760 'name'=>$wppizza_options['allergens'][$allergen_id]['name'],
761 'icon'=> $allergen_icon,
762 );
763
764 $parameters['global']['allergens'][$allergen_id] = $post_allergens[$allergen_id]; /*add to global array using key for uniqueness*/
765
766 }
767
768 /*
769 sort, keeping index
770 */
771 asort($post_allergens);
772
773 /*
774 overwrite original allergens key
775 */
776 $parameters['posts'][$key]->wppizza_data['allergens'] = $post_allergens;
777
778 /*
779 set flag that allergen icons are used (will add a distinct css class to set appropriate widths/heights)
780 */
781 if($post_has_allergens_icon){
782 $parameters['posts'][$key]->wppizza_data['allergens_icon'] = $post_has_allergens_icon;
783 }
784
785 }
786
787
788
789 /*
790 add additives, overwriting original when done
791 */
792 if(!empty($wppizza_metadata['additives']) && count($wppizza_metadata['additives'])>0){
793
794 $post_additives = array();;
795
796 foreach($wppizza_metadata['additives'] as $additive_id){
797
798 $post_additives[$additive_id] = array(
799 'sort'=>$wppizza_options['additives'][$additive_id]['sort'],
800 'name'=>$wppizza_options['additives'][$additive_id]['name'],
801 );
802
803 $parameters['global']['additives'][$additive_id] = $post_additives[$additive_id]; /*add to global array using key for uniqueness*/
804
805 }
806
807 /*
808 sort, keeping index
809 */
810 asort($post_additives);
811
812 /*
813 overwrite original additives key
814 */
815 $parameters['posts'][$key]->wppizza_data['additives'] = $post_additives;
816 }
817
818
819 /*
820 add foodtype, overwriting original when done
821 */
822 if(!empty($wppizza_metadata['foodtype']) && count($wppizza_metadata['foodtype'])>0){
823
824 $post_foodtype = array();
825
826 $post_has_foodtype_icon = false;
827
828 foreach($wppizza_metadata['foodtype'] as $foodtype_id){
829
830
831 $foodtype_icon = '' ;
832 if(!empty($wppizza_options['foodtype'][$foodtype_id]['icon'])){
833
834 $foodtype_icon = $wppizza_options['foodtype'][$foodtype_id]['icon'] ;
835
836 $post_has_foodtype_icon = true;
837 }
838
839 $post_foodtype[$foodtype_id]= array(
840 'sort'=>$wppizza_options['foodtype'][$foodtype_id]['sort'],
841 'name'=>$wppizza_options['foodtype'][$foodtype_id]['name'],
842 'icon'=> $foodtype_icon,
843 );
844
845 $parameters['global']['foodtype'][$foodtype_id] = $post_foodtype[$foodtype_id]; /*add to global array using key for uniqueness*/
846
847
848
849 }
850 asort($post_foodtype);/*sort, keeping index*/
851
852 /*
853 overwrite original foodtype key
854 */
855 $parameters['posts'][$key]->wppizza_data['foodtype'] = $post_foodtype;
856
857 /*
858 set flag that foodtype icons are used (will add a distinct css class to set appropriate widths/heights)
859 */
860 if($post_has_foodtype_icon){
861 $parameters['posts'][$key]->wppizza_data['foodtype_icon'] = $post_has_foodtype_icon;
862 }
863
864 }
865
866
867
868
869 /*
870 add global categories if query is for a category anyway
871 else get all this is assigned to (for atts[single] shortcode for example)
872 */
873 if(!empty($category)){
874 $parameters['posts'][$key]->wppizza_data['category'] = $category;
875 }
876 /** if we do not have a category (atts[single] for example), get all for this item and use first or set as false if uncategorised*/
877 if(empty($category)){
878 $get_post_terms = wp_get_post_terms( $post->ID, WPPIZZA_TAXONOMY);
879 /*get topmost that applies from sorted categories if there are any at all*/
880 if ($get_post_terms && !is_wp_error($get_post_terms)){
881 $plucked = wp_list_pluck( $get_post_terms, 'term_id');
882 $plucked = array_flip($plucked);// flip to get term_id as key
883 foreach($this->wppizza_terms as $term_id=>$term){
884 if(isset($plucked[$term_id])){
885 $term_key = $plucked[$term_id];
886 $post_category = array('id' => $get_post_terms[$term_key]->term_id, 'slug'=> $get_post_terms[$term_key]->slug , 'name'=> $get_post_terms[$term_key]->name, 'description'=> $get_post_terms[$term_key]->description );
887 $parameters['posts'][$key]->wppizza_data['category'] = $post_category;
888 break;
889 }
890 }
891 }else{
892 /*
893 force an uncategorised category if it was not assigned to any (possible if using [wppizza single=x] shortcode) - @since 3.6.1
894 */
895 $post_category = array('id' => 0, 'slug'=> sanitize_title_with_dashes($wppizza_options['localization']['uncategorised']) , 'name'=> $wppizza_options['localization']['uncategorised'], 'description'=> '' );
896 $parameters['posts'][$key]->wppizza_data['category'] = $post_category;
897 }
898 }
899
900 /*
901 get all the terms (categories) this item belongs to
902 */
903 $post_terms = wp_get_post_terms( $post->ID, WPPIZZA_TAXONOMY );
904
905 /* keeps things as arrays here */
906 $parameters['posts'][$key]->wppizza_data['terms'] = !empty($post_terms) ? json_decode(json_encode($post_terms), true) : array();
907
908 /*
909 get all the tags this item has set
910 */
911 $post_tags = wp_get_post_terms( $post->ID, WPPIZZA_TAGS);
912 /* keeps things as arrays here */
913 $parameters['posts'][$key]->wppizza_data['tags'] = !empty($post_tags) ? json_decode(json_encode($post_tags), true) : array();
914
915 }
916
917 /*
918 sort global allergens
919 */
920 asort($parameters['global']['allergens']);/*sort, keeping index*/
921
922 /*
923 sort global additives
924 */
925 asort($parameters['global']['additives']);/*sort, keeping index*/
926
927 /*
928 sort global foodtype
929 */
930 asort($parameters['global']['foodtype']);/*sort, keeping index*/
931
932
933
934 /*
935 overwrite global include_additives if set to auto
936 */
937 if($parameters['global']['include']['additives'] === 'auto'){
938
939 $parameters['global']['include']['additives'] = false;
940
941 if(!empty($parameters['global']['allergens']) || !empty($parameters['global']['additives'])){
942
943 $parameters['global']['include']['additives'] = true;
944
945 }
946 }
947
948
949
950 /*
951 allow filtering of all parameters we could/can in markup
952 */
953 $parameters = apply_filters('wppizza_filter_set_markup_parameters', $parameters, $style, $item_class, $elements, $attributes );
954
955
956 return $parameters;
957 }
958
959 /***********************************************************************************************************************************************************
960 *
961 *
962 *
963 *
964 * [ build markup - loop - using filters to put elements in right order (or indeed omit)]
965 *
966 *
967 *
968 * return string
969 ***********************************************************************************************************************************************************/
970 function get_markup_by_arguments($parameters){
971
972 /**
973 temp, enable permalinks
974 **/
975 //$parameters['global']['template']['elements']['permalink'] = 'permalink';
976
977
978 /*************************************
979
980 parameters to pass on to filters
981 somewhat split into distinct
982 variables for convenience
983
984 *************************************/
985
986 /**add options data to actions*/
987 global $wppizza_options;
988
989 /**add session data to actions perhaps ?*/
990 //$wppizza_session = array();
991 //$wppizza_session['user'] = 'todo';//$_SESSION[$this->session_key_userdata];
992 //$wppizza_session['cart'] = 'todo';//$_SESSION[$this->session_key_cart];
993
994 /**add style used */
995 $wppizza_style = $parameters['global']['template']['style'];
996
997 /*is rtl*/
998 $is_rtl = $parameters['global']['rtl'];
999
1000 /* localization - for ease of use */
1001 $txt = $wppizza_options['localization'];
1002
1003 /* all additives */
1004 $additives = wppizza_all_additives();
1005
1006 /* max num pages */
1007 $max_num_pages = $parameters['global']['max_num_pages'];
1008
1009 /*category id/slug/name/description - for ease of use */
1010 $category = $parameters['global']['categoy'];
1011
1012 /*number of posts*/
1013 $post_count = $parameters['global']['post_count'];
1014
1015 /*layout vars*/
1016 $layout = $parameters['global']['template'];
1017
1018 /* do we need to add an accordion wrapper ? */
1019 $accordion = !empty($parameters['global']['template']['accordion']) ? true : false;
1020
1021 /************************************************************************************************************************
1022 *
1023 *
1024 * creating loop markup
1025 *
1026 *
1027 * Note regarding filter hooks:
1028 * filter hooks are added for convenience, on could instead also the filters applied to each section such as
1029 * wppizza_filter_menu_header, wppizza_filter_menu_no_results, wppizza_filter_menu_additives,
1030 * wppizza_filter_menu_pagination etc etc , or indeed wppizza_filter_menu-markup
1031 *
1032 * if using the supplied filter hooks , they should add to the markup array like so :
1033 * $markup['unique_key'] = 'markup element - text - etc ';
1034 *
1035 ************************************************************************************************************************/
1036 $markup = array();/*ini markup string*/
1037
1038
1039 /*****************************
1040
1041 header
1042
1043 *****************************/
1044 /* convenience filter hook */
1045 $markup = apply_filters('wppizza_loop_before_header', $markup, $txt, $additives, $category, $max_num_pages, $post_count);
1046
1047 if(!empty($parameters['global']['include']['header'])){
1048
1049 $markup = apply_filters('wppizza_filter_menu_header', $markup, $txt, $additives, $parameters , $is_rtl , $category);
1050 }
1051
1052 /* convenience filter hook */
1053 $markup = apply_filters('wppizza_loop_after_header', $markup, $txt, $additives, $category, $max_num_pages, $post_count);
1054
1055
1056
1057 /*****************************
1058
1059 before loop / no results
1060
1061 *****************************/
1062 /* convenience filter hook */
1063 $markup = apply_filters('wppizza_loop_before_menu_items', $markup, $txt, $additives, $category, $max_num_pages, $post_count);
1064 /*****************************
1065
1066 loop
1067
1068 *****************************/
1069 if(!empty($parameters['global']['include']['loop'])){
1070
1071 $articlecount = 1;
1072 foreach($parameters['posts'] as $count=>$post_vars){
1073 $menu_item_markup = array();
1074
1075 /*
1076 if we do not have a category set (i.e when using [single=x] attribute in shortcode for example)
1077 lets see if we can get a category detail for this post itself
1078 */
1079 $post_category = ( empty($category) && !empty($post_vars->wppizza_data['category']) )? $post_vars->wppizza_data['category'] : $category ;
1080
1081 /*
1082 always open article element before - not settable via shortcode
1083 */
1084 $menu_item_markup = apply_filters('wppizza_filter_menu_loop_article_open', $menu_item_markup, $post_vars , $txt, $additives, $parameters , $is_rtl , $post_category, $articlecount);
1085
1086 /*
1087 add apply filter per module - in order of appearance in shortcode (or defaults)
1088 */
1089 foreach($layout['elements'] as $element){
1090
1091 $menu_item_markup = apply_filters('wppizza_filter_menu_loop_'.$element.'', $menu_item_markup, $post_vars , $txt, $additives, $parameters , $is_rtl, $post_category, $articlecount);
1092
1093 }
1094 /*
1095 always close article element after - not settable via shortcode
1096 */
1097 $menu_item_markup = apply_filters('wppizza_filter_menu_loop_article_close', $menu_item_markup, $post_vars , $txt, $additives, $parameters , $is_rtl , $post_category, $articlecount);
1098
1099
1100 $markup['menu_item_markup_'.$articlecount] = implode('',$menu_item_markup);
1101
1102 $articlecount++;
1103 }
1104 }
1105
1106 /***********************
1107
1108 no_results
1109
1110 ***********************/
1111 if(!empty($parameters['global']['include']['no_results'])){
1112
1113 $markup = apply_filters('wppizza_filter_menu_no_results', $markup, $txt, $additives, $parameters , $is_rtl , $category);//$articlecount $post_vars
1114
1115 }
1116
1117 /*****************************
1118
1119 after loop / no results
1120
1121 *****************************/
1122 /* convenience filter hook */
1123 $markup = apply_filters('wppizza_loop_after_menu_items', $markup, $txt, $additives, $category, $max_num_pages, $post_count);
1124
1125 /***********************
1126
1127 additives
1128
1129 ***********************/
1130 /* convenience filter hook */
1131 $markup = apply_filters('wppizza_loop_before_additives', $markup, $txt, $additives, $category, $max_num_pages, $post_count);
1132
1133 if(!empty($parameters['global']['include']['additives'])){
1134
1135 $markup = apply_filters('wppizza_filter_menu_additives', $markup, $txt, $additives, $parameters , $is_rtl , $category);//$articlecount $post_vars
1136
1137 }
1138
1139 /* convenience filter hook */
1140 $markup = apply_filters('wppizza_loop_after_additives', $markup, $txt, $additives, $category, $max_num_pages, $post_count);
1141
1142 /***********************
1143
1144 pagination -
1145 only if not single and more than 1 page
1146
1147 ***********************/
1148 /* convenience filter hook */
1149 $markup = apply_filters('wppizza_loop_before_pagination', $markup, $txt, $additives, $category, $max_num_pages, $post_count);
1150
1151 if(!empty($parameters['global']['include']['pagination'])){
1152
1153 $markup = apply_filters('wppizza_filter_menu_pagination', $markup, $txt, $additives, $parameters , $is_rtl , $category);//$articlecount $post_vars
1154
1155 }
1156
1157 /* convenience filter hook */
1158 $markup = apply_filters('wppizza_loop_after_pagination', $markup, $txt, $additives, $category, $max_num_pages, $post_count);
1159
1160 /************************
1161
1162 reset postdata and query
1163
1164 ************************/
1165 wp_reset_query();
1166
1167 /*
1168 add accordion divs
1169 */
1170 if($accordion && !empty($markup) ){
1171 //add before
1172 $accordion_content_ = array('accordion_content_' => '<div class="'.WPPIZZA_SLUG.'_accordion_content">');
1173 //add after
1174 $_accordion_content = array('_accordion_content' => '</div>');
1175 //add to array
1176 $markup = wppizza_array_splice($markup, $accordion_content_, '_header', false);
1177 $markup = $markup + $_accordion_content;
1178 }
1179
1180 /*markup - for more convenience when filtering - in an array , so implode for output*/
1181 $markup = apply_filters('wppizza_filter_menu-markup', $markup, $wppizza_style);
1182 $markup = implode('', $markup);
1183 return $markup;
1184 }
1185
1186 /***********************************************************************************************************************************************************
1187 *
1188 *
1189 *
1190 *
1191 * [ markup parts /modules- output as returned by filters]
1192 *
1193 *
1194 *
1195 *
1196 ***********************************************************************************************************************************************************/
1197
1198 /************************************************************************************************************
1199 *
1200 *
1201 *
1202 * [ markup parts - header markup]
1203 *
1204 *
1205 * return @array
1206 ************************************************************************************************************/
1207 function wppizza_filter_menu_header($markup, $txt, $additives, $parameters, $is_rtl, $category){
1208
1209 /********************
1210 parameters for convenience
1211 *********************/
1212 $style = $parameters['global']['template']['style'];
1213
1214 /********************
1215 set header id
1216 *********************/
1217 $header_id = ''. WPPIZZA_POST_TYPE .'-header-'.$category['slug'].'-'.$category['id'].'';
1218
1219 /*********************
1220 set header classes
1221 *********************/
1222 $header_class=array();
1223
1224 $header_class['header'][] = 'entry-header';
1225 $header_class['header'][] = 'page-header';//header only shown when there's a single ctaegory anyway, so we can add this everywhere one thinks
1226 $header_class['header'][] = ''.WPPIZZA_POST_TYPE.'-header';
1227 $header_class['header'][] = ''.WPPIZZA_POST_TYPE.'-header-'.$style.'';
1228 $header_class['header'][] = !empty($is_rtl) ? ''.WPPIZZA_POST_TYPE.'-header-rtl' : '';
1229 $header_class['header'][] = ''.WPPIZZA_POST_TYPE.'-header-'.$category['slug'].'';
1230
1231 $header_class['h1'][] ='entry-title';
1232 $header_class['h1'][] =''.WPPIZZA_POST_TYPE.'-entry-title ';
1233
1234 $header_class['description'][] = 'entry-meta';
1235 $header_class['description'][] = ''.WPPIZZA_POST_TYPE.'-header-meta';
1236
1237 /**
1238 allow filtering
1239 **/
1240 $header_class= apply_filters('wppizza_filter_menu_header_class', $header_class);
1241
1242 /*
1243 implode classes for output
1244 */
1245 $header_class['header']= implode(' ', $header_class['header']);
1246 $header_class['h1']= implode(' ', $header_class['h1']);
1247 $header_class['description']= implode(' ', $header_class['description']);
1248
1249
1250 /**
1251 allow filtering of h1 elemnt
1252 **/
1253 $header_element = apply_filters('wppizza_filter_menu_header_element', 'h1');
1254
1255 /*********************
1256
1257 get header markup from template - returns/ adds to $markup array
1258
1259 *********************/
1260 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/header.php')){
1261 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/header.php');
1262 }else{
1263 require(WPPIZZA_PATH.'templates/markup/loop/header.php');
1264 }
1265 /*********************
1266 apply filter if required
1267 *********************/
1268 $markup = apply_filters('wppizza_filter_menu_header_markup', $markup, $category, $style);
1269
1270
1271 return $markup;
1272 }
1273 /************************************************************************************************************
1274 *
1275 *
1276 *
1277 * [ markup parts - article open - does/should not exist as editable template]
1278 *
1279 *
1280 * return @array
1281 ************************************************************************************************************/
1282 function wppizza_filter_menu_loop_article_open($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
1283
1284 static $sectionid = 0;
1285 /********************
1286 parameters for convenience
1287 *********************/
1288 global $wppizza_options;
1289 $style = $parameters['global']['template']['style'];
1290 $item_class = $parameters['global']['template']['item_class'];
1291 $post_count = $parameters['global']['post_count'];
1292
1293 /********************
1294 set article id
1295 *********************/
1296 $post_article_id='post-'.$post->ID.'';
1297
1298 /*********************
1299 set article classes
1300 *********************/
1301 $post_article_class = array();
1302
1303 /*general class*/
1304 $post_article_class[] = ''.WPPIZZA_SLUG.'-article';
1305 /*selected style class*/
1306 $post_article_class[] = ''.WPPIZZA_SLUG.'-article-'.$style.'';
1307 /*custom classes added in shortcode */
1308 $post_article_class[] = !empty($item_class) ? $item_class : '';
1309 /*rtl*/
1310 $post_article_class[] = !empty($is_rtl) ? ''.WPPIZZA_POST_TYPE.'-article-rtl' : '';
1311
1312
1313 /*add - first*/
1314 if($articlecount==1){
1315 $post_article_class[]=''.WPPIZZA_SLUG.'-article-first';
1316 }
1317 /*add - last if more than one*/
1318 if($articlecount==$post_count && $post_count>1){
1319 $post_article_class[]=''.WPPIZZA_SLUG.'-article-last';
1320 }
1321 /*category*/
1322 $post_article_class[]=''.WPPIZZA_SLUG.'-article-'.$category['slug'].'';
1323 /*category with id*/
1324 $post_article_class[]=''.WPPIZZA_SLUG.'-article-'.$category['slug'].'-'.$category['id'].'';
1325 /*
1326 add all terms this belongs to using WPPIZZA_TAXONOMY here as WP > 4.2 adds some of these already and we
1327 can simply use array_unique below to get rid of superflous ones
1328 */
1329 foreach($post->wppizza_data['terms'] as $term){
1330 $post_article_class[]=''.WPPIZZA_TAXONOMY.'-'.$term['slug'].'';
1331 $post_article_class[]=''.WPPIZZA_TAXONOMY.'-term-'.$term['term_id'].'';
1332 }
1333 /*
1334 add all tags this belongs to using WPPIZZA_TAGS here as WP > 4.2 adds some of these already and we
1335 can simply use array_unique below to get rid of superflous ones
1336 */
1337 foreach($post->wppizza_data['tags'] as $tag){
1338 $post_article_class[]= isset($tag['slug']) ? ''.$tag['slug'].'' : '' ;
1339 }
1340 /*general*/
1341 $post_article_class[]='entry-content';
1342
1343 /**
1344 allow filtering
1345 **/
1346 $post_article_class = apply_filters('wppizza_filter_post_arcticle_class', $post_article_class, $style, $post->ID);
1347
1348 /**add standard*/
1349 $post_article_class = get_post_class($post_article_class, $post->ID);
1350
1351 /*
1352 implode classes for output
1353 */
1354 $post_article_class = array_unique($post_article_class);/* no need to have the same class multiple times */
1355 $post_article_class=implode(' ', $post_article_class);
1356
1357
1358 /*************************
1359
1360 markup
1361
1362 *************************/
1363 /*
1364 add sections for grid layout
1365 */
1366 if( !is_single() && $style == 'grid' ){
1367 $section_count = (($articlecount-1)/$wppizza_options['layout']['style_grid_columns']);
1368 $section_max = ceil($post_count/$wppizza_options['layout']['style_grid_columns'])-1;
1369 if(is_int($section_count)){
1370
1371 /**add first and last*/
1372 $first_section_class = $section_count==0 ? ' '.WPPIZZA_SLUG.'-grid-section-first' : '';
1373 $last_section_class = $section_count==$section_max ? ' '.WPPIZZA_SLUG.'-grid-section-last' : '';
1374
1375
1376 $markup['section_'] = '<section id="'.WPPIZZA_SLUG.'-grid-section-'.$sectionid.'" class="'.WPPIZZA_SLUG.'-grid-section '.WPPIZZA_SLUG.'-grid-section-'.$section_count.''.$first_section_class.''.$last_section_class.'">';
1377 /*advance counter*/
1378 $sectionid++;
1379 }
1380 }
1381 /*
1382 add article markup
1383 */
1384 $markup['article_'] = '<article id="' . $post_article_id . '" class="' . $post_article_class . '">';
1385 /**is this required/uesful actually as class added to article??*/
1386 //if(is_single()){/*to add to articleclasses*/
1387 //$markup .= "<div class='entry-content'>";
1388 //}
1389
1390 return $markup;
1391 }
1392 /************************************************************************************************************
1393 *
1394 *
1395 *
1396 * [ markup parts - post title]
1397 *
1398 *
1399 * return @array
1400 ************************************************************************************************************/
1401 function wppizza_filter_menu_loop_title($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
1402
1403 /********************
1404 parameters for convenience
1405 *********************/
1406 global $wppizza_options;
1407 /* classes filter parameters */
1408 $filter_parameters = $this->set_post_classes_filter_parameters($post, $parameters, $articlecount) ;
1409 /*single category, provided item does actually belong to one */
1410 if(!empty($post->wppizza_data['category'])){
1411 $category = $post->wppizza_data['category'];
1412 }else{
1413 /* we need a category, lets just get the first one else use first available */
1414 $category = wppizza_force_first_category();
1415 }
1416
1417
1418 /*********************
1419 get style
1420 *********************/
1421 $style = $filter_parameters['layout']['style'];
1422
1423 /*********************
1424 set title
1425 *********************/
1426 $post_title = apply_filters('wppizza_filter_post_title', $post->post_title , $post->ID);
1427
1428 /********************
1429 set id's
1430 *********************/
1431 /* title id: including postid, sizes id, +zero to trigger first if set */
1432 $post_title_id = ''.WPPIZZA_SLUG.'-article-'.$post->blog_id.'-'.$category['id'].'-'.$post->ID.'-'.$post->wppizza_data['sizes'].'-0';
1433 /* additives id */
1434 $post_additives_id = ''.WPPIZZA_SLUG.'-article-additives-'.$post->ID.'';
1435 /* foodtype id */
1436 $post_foodtype_id = ''.WPPIZZA_SLUG.'-article-ftypes-'.$post->ID.'';
1437
1438 /********************
1439 set h2 elemnt
1440 ********************/
1441 $post_title_element = apply_filters('wppizza_filter_post_title_element', 'h2');
1442
1443
1444 /*********************
1445 set title classes
1446 *********************/
1447 $post_title_class = array();
1448
1449 /*
1450 h2
1451 */
1452 $post_title_class['elm'] = array();
1453 $post_title_class['elm'][] = ''.WPPIZZA_POST_TYPE.'-article-'.$post_title_element.'';
1454 /**
1455 if selected in admin, make click on title add to cart or
1456 show alert when there are more than one size
1457 **/
1458 if(!empty($wppizza_options['layout']['add_to_cart_on_title_click'])){
1459 /*no of prices/sizes*/
1460 $numberOfPrices=count($post->wppizza_data['prices']);
1461
1462 /*trigger add to cart**/
1463 if($numberOfPrices==1){
1464 $post_title_class['elm'][]=' '.WPPIZZA_SLUG.'-trigger-click';
1465 }
1466 /*more than one size available, show alert**/
1467 if($numberOfPrices>1){
1468 $post_title_class['elm'][]=' '.WPPIZZA_SLUG.'-trigger-choose';
1469 }
1470 }
1471
1472 /*
1473 title
1474 */
1475 $post_title_class['title'] = array();
1476 $post_title_class['title'][] = ''.WPPIZZA_POST_TYPE.'-article-title';
1477
1478
1479 /*
1480 additives
1481 */
1482 $post_title_class['additives'] = array();
1483 $post_title_class['additives'][] = ''.WPPIZZA_POST_TYPE.'-article-additives';
1484
1485
1486 /*
1487 foodtype
1488 */
1489 $post_title_class['foodtype'] = array();
1490 $post_title_class['foodtype'][] = ''.WPPIZZA_POST_TYPE.'-article-ftypes';
1491
1492
1493 /*
1494 add "has_icons" class - although not used in the title by default - if icons are associated with any allergen or foodtype
1495 to allow for
1496 */
1497 if(!empty($post->wppizza_data['allergens_icon']) || !empty($post->wppizza_data['foodtype_icon'])){
1498 $post_title_class['additives'][] = ''.WPPIZZA_POST_TYPE.'-article-additives-icons';
1499 $post_title_class['foodtype'][] = ''.WPPIZZA_POST_TYPE.'-article-ftypes-icons';
1500 }
1501
1502
1503 /**
1504 allow filtering
1505 **/
1506 $post_title_class= apply_filters('wppizza_filter_post_title_class', $post_title_class, $filter_parameters['post_data'], $filter_parameters['layout'], $filter_parameters['parameters'], $filter_parameters['articlecount'], $filter_parameters['session']);
1507
1508 /*
1509 implode for output
1510 */
1511 $post_title_class['elm']= implode(' ', $post_title_class['elm']);
1512 $post_title_class['title']= implode(' ', $post_title_class['title']);
1513 $post_title_class['additives']= implode(' ', $post_title_class['additives']);
1514 $post_title_class['foodtype']= implode(' ', $post_title_class['foodtype']);
1515
1516
1517 /*
1518 food types
1519 $map to full food types vars
1520 */
1521 $post_foodtype = $this->get_post_aaf($post, 'foodtype', 'ftype');
1522
1523 /*
1524 allergens
1525 $map to full allergens vars
1526 */
1527 $post_allergens = $this->get_post_aaf($post, 'allergens', 'allergen');
1528
1529
1530 /*
1531 additives
1532 $map to full additives vars
1533 */
1534 $post_additives = $this->get_post_aaf($post, 'additives', 'article-additive');
1535
1536
1537 /*************************
1538
1539 markup
1540
1541 *************************/
1542 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/posts.title.php')){
1543 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/posts.title.php');
1544 }else{
1545 require(WPPIZZA_PATH.'templates/markup/loop/posts.title.php');
1546 }
1547
1548 /*********************
1549 apply filter if required
1550 *********************/
1551 $markup = apply_filters('wppizza_filter_post_title_markup', $markup, $style);
1552
1553 return $markup;
1554 }
1555
1556 /************************************************************************************************************
1557 *
1558 *
1559 *
1560 * [ markup parts - foodtype - only used when using elements='foodtype' attribute in shortcode]
1561 *
1562 *
1563 * return @array
1564 ************************************************************************************************************/
1565 function wppizza_filter_menu_loop_foodtype($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
1566
1567
1568 /********************
1569 parameters for convenience
1570 *********************/
1571 global $wppizza_options;
1572 /* classes filter parameters */
1573 $filter_parameters = $this->set_post_classes_filter_parameters($post, $parameters, $articlecount) ;
1574
1575
1576 /*********************
1577 get style
1578 *********************/
1579 $style = $filter_parameters['layout']['style'];
1580
1581
1582 /********************
1583 set id's
1584 *********************/
1585 /* foodtype id */
1586 $foodtype_loop_id = ''.WPPIZZA_SLUG.'-post-ftypes-'.$post->ID.'';
1587
1588 /********************
1589 set span elemnt
1590 ********************/
1591 $foodtype_loop_element = apply_filters('wppizza_filter_post_foodtype_element', 'span');
1592
1593
1594 /*********************
1595 set classes
1596 *********************/
1597 $foodtype_loop_class = array();
1598
1599 /*
1600 additives wrapper classes
1601 */
1602 $foodtype_loop_class['foodtype'] = array();
1603 $foodtype_loop_class['foodtype'][] = ''.WPPIZZA_POST_TYPE.'-post-ftypes';
1604 /*
1605 add "has_icons" class - although not used by default - if icons are associated with any allergen or foodtype
1606 to allow for
1607 */
1608 if(!empty($post->wppizza_data['foodtype_icon'])){
1609 $foodtype_loop_class['foodtype'][] = ''.WPPIZZA_POST_TYPE.'-post-ftypes-icons';
1610 }
1611
1612 /**
1613 allow filtering
1614 **/
1615 $foodtype_loop_class= apply_filters('wppizza_filter_post_foodtype_class', $foodtype_loop_class, $filter_parameters['post_data'], $filter_parameters['layout'], $filter_parameters['parameters'], $filter_parameters['articlecount'], $filter_parameters['session']);
1616
1617 /*
1618 implode for output
1619 */
1620 $foodtype_loop_class['additives']= implode(' ', $foodtype_loop_class['foodtype']);
1621
1622 /*
1623 foodtype
1624 $map to full allergens vars
1625 */
1626 $post_foodtype = $this->get_post_aaf($post, 'foodtype', 'ftype');
1627
1628
1629 /*************************
1630
1631 markup
1632
1633 *************************/
1634 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/posts.foodtype.php')){
1635 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/posts.foodtype.php');
1636 }else{
1637 require(WPPIZZA_PATH.'templates/markup/loop/posts.foodtype.php');
1638 }
1639
1640 /*********************
1641 apply filter if required
1642 *********************/
1643 $markup = apply_filters('wppizza_filter_post_foodtype_markup', $markup, $style);
1644
1645 return $markup;
1646 }
1647
1648 /************************************************************************************************************
1649 *
1650 *
1651 *
1652 * [ markup parts - additives - only used when using elements='additives' attribute in shortcode]
1653 *
1654 *
1655 * return @array
1656 ************************************************************************************************************/
1657 function wppizza_filter_menu_loop_additives($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
1658
1659
1660
1661 /********************
1662 parameters for convenience
1663 *********************/
1664 global $wppizza_options;
1665 /* classes filter parameters */
1666 $filter_parameters = $this->set_post_classes_filter_parameters($post, $parameters, $articlecount) ;
1667
1668
1669 /*********************
1670 get style
1671 *********************/
1672 $style = $filter_parameters['layout']['style'];
1673
1674
1675 /********************
1676 set id's
1677 *********************/
1678 /* additives id */
1679 $additives_loop_id = ''.WPPIZZA_SLUG.'-post-additives-'.$post->ID.'';
1680
1681 /********************
1682 set span elemnt
1683 ********************/
1684 $additive_loop_element = apply_filters('wppizza_filter_post_additives_element', 'span');
1685
1686
1687 /*********************
1688 set classes
1689 *********************/
1690 $additives_loop_class = array();
1691
1692 /*
1693 additives wrapper classes
1694 */
1695 $additives_loop_class['additives'] = array();
1696 $additives_loop_class['additives'][] = ''.WPPIZZA_POST_TYPE.'-post-additives';
1697 /*
1698 add "has_icons" class - although not used by default - if icons are associated with any allergen
1699 to allow for
1700 */
1701 if(!empty($post->wppizza_data['allergens_icon'])){
1702 $additives_loop_class['additives'][] = ''.WPPIZZA_POST_TYPE.'-post-additives-icons';
1703 }
1704
1705 /**
1706 allow filtering
1707 **/
1708 $additives_loop_class= apply_filters('wppizza_filter_post_additives_class', $additives_loop_class, $filter_parameters['post_data'], $filter_parameters['layout'], $filter_parameters['parameters'], $filter_parameters['articlecount'], $filter_parameters['session']);
1709
1710 /*
1711 implode for output
1712 */
1713 $additives_loop_class['additives']= implode(' ', $additives_loop_class['additives']);
1714
1715 /*
1716 allergens
1717 $map to full allergens vars
1718 */
1719 $post_allergens = $this->get_post_aaf($post, 'allergens', 'allergen');
1720
1721 /*
1722 additives
1723 $map to full additives vars
1724 */
1725 $post_additives = $this->get_post_aaf($post, 'additives', 'article-additive');
1726
1727
1728
1729 /*************************
1730
1731 markup
1732
1733 *************************/
1734 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/posts.additives.php')){
1735 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/posts.additives.php');
1736 }else{
1737 require(WPPIZZA_PATH.'templates/markup/loop/posts.additives.php');
1738 }
1739
1740 /*********************
1741 apply filter if required
1742 *********************/
1743 $markup = apply_filters('wppizza_filter_post_additives_markup', $markup, $style);
1744
1745 return $markup;
1746 }
1747
1748
1749 /************************************************************************************************************
1750 *
1751 *
1752 *
1753 * [ markup parts - thumbnail/placeholder]
1754 *
1755 *
1756 * return @array
1757 ************************************************************************************************************/
1758 function wppizza_filter_menu_loop_thumbnail($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
1759
1760 /********************
1761 parameters for convenience
1762 *********************/
1763 global $wppizza_options;
1764 /* classes filter parameters */
1765 $filter_parameters = $this->set_post_classes_filter_parameters($post, $parameters, $articlecount) ;
1766 $image_placeholder = $parameters['global']['template']['attributes']['image_placeholder'];
1767 $image_prettyphoto = $parameters['global']['template']['attributes']['image_prettyphoto'];
1768
1769 /* check if string or array of 2 int (w/h in pixels) */
1770 $xfImgSize = explode('x', $wppizza_options['layout']['featured_image_size']);
1771 if(count($xfImgSize) == 2 && is_int($xfImgSize[0]) && is_int($xfImgSize[1])){
1772 $featured_image_size = array($xfImgSize[0], $xfImgSize[1]);
1773 }else{
1774 $featured_image_size = $wppizza_options['layout']['featured_image_size'];
1775 }
1776
1777
1778 /*********************
1779 get style
1780 *********************/
1781 $style = $filter_parameters['layout']['style'];
1782
1783 /********************
1784 set id's
1785 *********************/
1786 $post_thumbnail_id = ''.WPPIZZA_SLUG.'-article-img-'.$post->ID.'';
1787
1788 /*********************
1789 set thumbmail classes
1790 *********************/
1791 $post_thumbnail_class = array();
1792
1793 $post_thumbnail_class['div'][] = ''.WPPIZZA_SLUG.'-article-image';
1794 $post_thumbnail_class['placeholder'][] = ''.WPPIZZA_SLUG.'-article-image-placeholder';
1795
1796 /*
1797 allow filtering
1798 */
1799 $post_thumbnail_class= apply_filters('wppizza_filter_post_thumbnail_class', $post_thumbnail_class, $filter_parameters['post_data'], $filter_parameters['layout'], $filter_parameters['parameters'], $filter_parameters['articlecount'], $filter_parameters['session']);
1800
1801 /*
1802 implode for output
1803 */
1804 $post_thumbnail_class['div']= implode(' ', $post_thumbnail_class['div']);
1805 $post_thumbnail_class['placeholder']= implode(' ', $post_thumbnail_class['placeholder']);
1806
1807
1808 /**********************
1809 create image/thumbnail elements for output
1810 **********************/
1811
1812 $has_thumbnail = !empty($post->has_post_thumbnail) ? true : false ;
1813 $has_placeholder = (empty($post->has_post_thumbnail) && !empty($image_placeholder) ) ? true : false ;
1814
1815 /**create the actual image markup */
1816 if(!empty($has_thumbnail)){
1817
1818 $featured_image = '';
1819
1820 if(!empty($image_prettyphoto)){
1821 $full_image_data = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full' );
1822 $featured_image .= '<a href="'.$full_image_data[0].'" rel="wpzpp-' . $post->post_name .'" title="' . $post->the_title_attribute .'">';
1823 }
1824
1825 $featured_image .= get_the_post_thumbnail($post->ID, apply_filters('wppizza_filter_featured_image_size', $featured_image_size), array('class' => ''.WPPIZZA_SLUG.'-article-image-thumb', 'title'=>$post->the_title_attribute));
1826
1827 if(!empty($image_prettyphoto)){
1828 $featured_image.= "</a>";
1829 }
1830 }
1831
1832 /*************************
1833
1834 markup
1835
1836 *************************/
1837 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/posts.thumbnail.php')){
1838 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/posts.thumbnail.php');
1839 }else{
1840 require(WPPIZZA_PATH.'templates/markup/loop/posts.thumbnail.php');
1841 }
1842
1843 /*********************
1844 apply filter if required
1845 *********************/
1846 $markup = apply_filters('wppizza_filter_post_thumbnail_markup', $markup, $style, $has_thumbnail, $has_placeholder);
1847
1848
1849 return $markup;
1850 }
1851 /************************************************************************************************************
1852 *
1853 *
1854 *
1855 * [ markup parts - category]
1856 *
1857 *
1858 * return @array
1859 ************************************************************************************************************/
1860 function wppizza_filter_menu_loop_category($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
1861
1862 /********************
1863 parameters for convenience
1864 *********************/
1865 /* classes filter parameters */
1866 $filter_parameters = $this->set_post_classes_filter_parameters($post, $parameters, $articlecount) ;
1867
1868
1869 $post_category = $category;
1870
1871 /*********************
1872 get style
1873 *********************/
1874 $style = $filter_parameters['layout']['style'];
1875
1876
1877 /*********************
1878 set category classes
1879 *********************/
1880 $post_category_class = array();
1881 /*general class*/
1882 $post_category_class[] = ''.WPPIZZA_SLUG.'-category';
1883 $post_category_class[] = ''.WPPIZZA_SLUG.'-category-'.$post_category['id'].'';
1884 $post_category_class[] = ''.WPPIZZA_SLUG.'-category-'.$post_category['slug'].'';
1885
1886 /*
1887 allow filtering
1888 */
1889 $post_category_class = apply_filters('wppizza_filter_post_category_class', $post_category_class, $filter_parameters['post_data'], $filter_parameters['layout'], $filter_parameters['parameters'], $filter_parameters['articlecount'], $filter_parameters['session']);
1890
1891 /*
1892 implode for output
1893 */
1894 $post_category_class = implode(' ', $post_category_class);
1895
1896
1897 /*************************
1898
1899 markup
1900
1901 *************************/
1902 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/posts.category.php')){
1903 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/posts.category.php');
1904 }else{
1905 require(WPPIZZA_PATH.'templates/markup/loop/posts.category.php');
1906 }
1907
1908 /*********************
1909 apply filter if required
1910 *********************/
1911 $markup = apply_filters('wppizza_filter_post_category_markup', $markup, $style);
1912
1913 return $markup;
1914 }
1915 /************************************************************************************************************
1916 *
1917 *
1918 *
1919 * [ markup parts - prices, sizes, currency symbols]
1920 *
1921 *
1922 * return @array
1923 ************************************************************************************************************/
1924
1925 function wppizza_filter_menu_loop_prices($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
1926
1927 /********************
1928 parameters for convenience
1929 *********************/
1930 global $wppizza_options;
1931 $prices = $post->wppizza_data['prices'];
1932 $sizes_id = $post->wppizza_data['sizes'];
1933 /* classes filter parameters */
1934 $filter_parameters = $this->set_post_classes_filter_parameters($post, $parameters, $articlecount) ;
1935 /*symbol*/
1936 $currency=$wppizza_options['order_settings']['currency_symbol'];
1937 /*position or omit main currency symbol*/
1938 $currency_display = $parameters['global']['template']['attributes']['currency_main'];
1939 /*single category, provided item does actually belong to one , else use first available*/
1940 if(!empty($post->wppizza_data['category'])){
1941 $category = $post->wppizza_data['category'];
1942 }else{
1943 /* we need a category, lets just get the first one else use first available */
1944 $category = wppizza_force_first_category();
1945 }
1946
1947 /* add to cart trigger class if set */
1948 $addtocarttriggerclass = 'add-to-cart';
1949
1950 /********************
1951 main, large currency symbol position
1952 ********************/
1953 $currency_left = ($currency_display==='left' ) ? true : false ;
1954 $currency_right = ($currency_display==='right' ) ? true : false ;
1955
1956
1957 /*********************
1958 get style
1959 *********************/
1960 $style = $filter_parameters['layout']['style'];
1961
1962 /********************
1963 set sizes/prices id's
1964 *********************/
1965 $post_sizes_id = ''.WPPIZZA_SLUG.'-article-sizes-'.$post->ID.'';
1966 $post_prices_id = ''.WPPIZZA_SLUG.'-article-prices-'.$post->ID.'';
1967
1968 /*********************
1969 set sizes/prices classes
1970 *********************/
1971 $post_prices_class = array();
1972
1973 /*wrapper outer class*/
1974 $post_prices_class['sizes'][] = ''.WPPIZZA_SLUG.'-article-sizes';
1975 $post_prices_class['sizes'][] = ''.WPPIZZA_SLUG.'-article-prices-'.$sizes_id.'';
1976
1977 /*wrapper inner class*/
1978 $post_prices_class['prices'][] = ''.WPPIZZA_SLUG.'-article-prices';
1979
1980 /*class currency*/
1981 $post_prices_class['currency'][] = ''.WPPIZZA_SLUG.'-article-price-currency';
1982 $post_prices_class['currency'][] = (!empty($currency_left)) ? ''.WPPIZZA_SLUG.'-article-price-right' : ''.WPPIZZA_SLUG.'-article-price-left';
1983
1984 /*
1985 allow filtering
1986 */
1987 $post_prices_class = apply_filters('wppizza_filter_post_prices_class', $post_prices_class, $filter_parameters['post_data'], $filter_parameters['layout'], $filter_parameters['parameters'], $filter_parameters['articlecount'], $filter_parameters['session']);
1988
1989 /*
1990 implode for output
1991 */
1992 $post_prices_class['sizes']= implode(' ', $post_prices_class['sizes']);
1993 $post_prices_class['prices']= implode(' ', $post_prices_class['prices']);
1994 $post_prices_class['currency']= implode(' ', $post_prices_class['currency']);
1995
1996
1997 /*
1998 individual prices
1999 add id's, classes, titels
2000 */
2001 foreach($prices as $key=>$price){
2002
2003 $idComponents = array($post->blog_id, $category['id'], $post->ID, $sizes_id, $key);
2004
2005 /*id consists of prefix - blogid - category id - post id - selected sizes - seleted size*/
2006 $prices[$key]['id'] = ''.WPPIZZA_SLUG.'-'.implode('-', $idComponents).'';
2007
2008
2009 /*class price, allow add to cart if enabled and not viewonly in shortcode*/
2010 $prices[$key]['class_price'] = ''.WPPIZZA_SLUG.'-article-price '.WPPIZZA_SLUG.'-article-price-'.$sizes_id.'-'.$key.' '.WPPIZZA_SLUG.'-price-'.$post->ID.'-'.$key.'';
2011 $prices[$key]['class_price'] .= ( empty($wppizza_options['layout']['disable_online_order']) && empty($parameters['global']['include']['viewonly']) ) ? ' '.WPPIZZA_SLUG.'-'.$addtocarttriggerclass.'' : '' ;
2012 $prices[$key]['class_price'] .= (!empty($wppizza_options['layout']['disable_online_order']) || !empty($parameters['global']['include']['viewonly'])) ? ' '.WPPIZZA_SLUG.'-article-price-viewonly' : '' ;
2013
2014 /* class for span surrounding price - empty by default,but filterable !*/
2015 $prices[$key]['class_price_span'] = '';
2016
2017 /*tile attribute - if applicable*/
2018 $prices[$key]['title'] = !empty($wppizza_options['layout']['disable_online_order']) || !empty($parameters['global']['include']['viewonly']) ? '' : ' title="'.$txt['add_to_cart'].'"' ;
2019
2020 /*class size, add nocart class if required*/
2021 $prices[$key]['class_size'] = ''.WPPIZZA_SLUG.'-article-size';
2022 $prices[$key]['class_size'] .= !empty($wppizza_options['layout']['hide_cart_icon']) || !empty($wppizza_options['layout']['disable_online_order']) || !empty($parameters['global']['include']['viewonly']) ? ' '.WPPIZZA_SLUG.'-no-cart' : '' ;
2023
2024 /**no label - hide pricetiers if only one and set to hide*/
2025 $prices[$key]['no_label'] = (!empty($wppizza_options['layout']['hide_single_pricetier']) && count($prices)<=1) ? true : false ;
2026
2027 /**set to "free" if zero */
2028 $prices[$key]['price'] = (empty($price['value']) && !empty($wppizza_options['prices_format']['localize_zero_price']) && !empty($wppizza_options['localization']['localize_zero_price']) ) ? $wppizza_options['localization']['localize_zero_price'] : $price['price'] ;
2029
2030
2031 /**
2032 data-attributes since v3.19.3
2033 currently id only, but can be expanded by adding to this array
2034 by filter here or with the wppizza_filter_post_prices if we need to in the future
2035 **/
2036 $data_attributes = apply_filters( 'wppizza_filter_loop_data_attributes', array(
2037 /* raw id without any prefixes, dot separated */
2038 'id' => implode('.', $idComponents),
2039 ), $idComponents );
2040 $attributes = array();
2041 foreach($data_attributes as $attKey => $attribute){
2042 $attributes[$attKey] = 'data-'.wppizza_alpha_only($attKey).'="'.esc_html($attribute).'"';
2043 }
2044 $prices[$key]['data'] = ' '.implode(' ', $attributes).' ';
2045
2046
2047 }
2048
2049 /* allow filtering */
2050 $prices = apply_filters('wppizza_filter_post_prices', $prices, $post, $style);
2051
2052 /*************************
2053
2054 markup
2055
2056 *************************/
2057 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/posts.prices.php')){
2058 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/posts.prices.php');
2059 }else{
2060 require(WPPIZZA_PATH.'templates/markup/loop/posts.prices.php');
2061 }
2062
2063
2064 /*********************
2065 apply filter if required
2066 *********************/
2067 $markup = apply_filters('wppizza_filter_post_prices_markup', $markup, $style, $post, $prices);
2068
2069
2070 return $markup;
2071 }
2072
2073 /************************************************************************************************************
2074 *
2075 *
2076 *
2077 * [ markup parts - post content]
2078 *
2079 *
2080 * return @array
2081 ************************************************************************************************************/
2082 function wppizza_filter_menu_loop_content($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
2083
2084 global $wppizza_options;
2085
2086 /********************
2087 parameters for convenience
2088 *********************/
2089 /* classes filter parameters */
2090 $filter_parameters = $this->set_post_classes_filter_parameters($post, $parameters, $articlecount) ;
2091
2092 /*********************
2093 get style
2094 *********************/
2095 $style = $filter_parameters['layout']['style'];
2096
2097 /********************
2098 set content id
2099 *********************/
2100 $post_content_id = ''.WPPIZZA_SLUG.'-article-content-'.$post->ID.'';
2101
2102 /*********************
2103 set content classes
2104 *********************/
2105 $post_content_class = array();
2106 /*general class*/
2107 $post_content_class[] = ''.WPPIZZA_SLUG.'-article-content';
2108
2109
2110 /*
2111 allow filtering
2112 */
2113 $post_content_class = apply_filters('wppizza_filter_post_content_class', $post_content_class, $filter_parameters['post_data'], $filter_parameters['layout'], $filter_parameters['parameters'], $filter_parameters['articlecount'], $filter_parameters['session']);
2114
2115 /*
2116 implode for output
2117 */
2118 $post_content_class = implode(' ', $post_content_class);
2119
2120 /*
2121 allow read more link
2122 */
2123 if(!empty($wppizza_options['layout']['allow_read_more_link'])){
2124 $post->post_content = get_the_content( null, false, $post);
2125 }
2126
2127 /*
2128 allow shortcodes and other filters
2129 */
2130 $post_content_element = 'p';
2131 if(!empty($wppizza_options['layout']['apply_menu_items_content_filter'])){
2132 $post_content_element = 'div';
2133 $post->post_content = apply_filters('the_content', $post->post_content);
2134 }
2135
2136 /*
2137 allow wppizza specific post content filter
2138 */
2139 $post->post_content = apply_filters('wppizza_filter_post_content', $post->post_content , $post->ID);
2140
2141
2142 /*************************
2143
2144 markup
2145
2146 *************************/
2147 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/posts.content.php')){
2148 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/posts.content.php');
2149 }else{
2150 require(WPPIZZA_PATH.'templates/markup/loop/posts.content.php');
2151 }
2152
2153 /*********************
2154 apply filter if required
2155 *********************/
2156 $markup = apply_filters('wppizza_filter_post_content_markup', $markup, $style, $post->ID);
2157
2158 return $markup;
2159 }
2160 /************************************************************************************************************
2161 *
2162 *
2163 *
2164 * [ markup parts - permalink]
2165 *
2166 *
2167 * return @array
2168 ************************************************************************************************************/
2169 function wppizza_filter_menu_loop_permalink($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
2170
2171 /********************
2172 parameters for convenience
2173 *********************/
2174 /* classes filter parameters */
2175 $filter_parameters = $this->set_post_classes_filter_parameters($post, $parameters, $articlecount) ;
2176
2177 /*********************
2178 get style
2179 *********************/
2180 $style = $filter_parameters['layout']['style'];
2181
2182 /********************
2183 set permalink id
2184 *********************/
2185 $post_permalink_id = ''.WPPIZZA_SLUG.'-permalink-'.$post->ID.'';
2186
2187 /*********************
2188 set permalink classes
2189 *********************/
2190 $post_permalink_class = array();
2191 /*general class*/
2192 $post_permalink_class[] = ''.WPPIZZA_SLUG.'-permalink';
2193
2194
2195 /*
2196 allow filtering
2197 */
2198 $post_permalink_class = apply_filters('wppizza_filter_post_permalink_class', $post_permalink_class, $filter_parameters['post_data'], $filter_parameters['layout'], $filter_parameters['parameters'], $filter_parameters['articlecount'], $filter_parameters['session']);
2199
2200 /*
2201 implode for output
2202 */
2203 $post_permalink_class = implode(' ', $post_permalink_class);
2204
2205
2206 /*************************
2207
2208 markup
2209
2210 *************************/
2211 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/posts.permalink.php')){
2212 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/posts.permalink.php');
2213 }else{
2214 require(WPPIZZA_PATH.'templates/markup/loop/posts.permalink.php');
2215 }
2216
2217 /*********************
2218 apply filter if required
2219 *********************/
2220 $markup = apply_filters('wppizza_filter_post_permalink_markup', $markup, $style);
2221
2222 return $markup;
2223 }
2224
2225 /************************************************************************************************************
2226 *
2227 *
2228 *
2229 * [ markup parts - comments todo perhaps one day when we are really bored]
2230 *
2231 *
2232 * return @array
2233 ************************************************************************************************************/
2234 function wppizza_filter_menu_loop_comments($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
2235 // if(is_single()){
2236 // comments_template( '', true );
2237 // }
2238 /***********TODO COMMENTS***********************************************************************/
2239 //Gather comments for a specific page/post
2240 // $comments = get_comments(array(
2241 // 'post_id' => $post->ID,
2242 // 'status' => 'approve' //Change this to the type of comments to be displayed
2243 // ));
2244 // ob_start();
2245 // //Display the list of comments
2246 // wp_list_comments(array(
2247 // 'per_page' => 10, //Allow comment pagination
2248 // 'reverse_top_level' => false //Show the latest comments at the top of the list
2249 // ), $comments);
2250 // $wppizza_loop_markup .= ob_get_clean();
2251
2252
2253
2254
2255 // /**should only disply on single posts*/
2256 // ob_start();
2257 // comments_template( '', true );
2258 // comment_form();
2259 // $wppizza_loop_markup .= ob_get_clean();
2260
2261 //ob_start();
2262 //$wppizza_loop_markup = wp_list_comments( array( 'post_id' => $post->ID ) ));
2263 //$wppizza_loop_markup .= ob_get_clean();
2264
2265
2266 // ob_start();
2267 // comments_template( '', true );
2268 // $wppizza_loop_markup .= ob_get_clean();
2269
2270 return $markup;
2271 }
2272 /************************************************************************************************************
2273 *
2274 *
2275 *
2276 * [ markup parts - article close - does/should not exist as editable template]
2277 *
2278 *
2279 * return @array
2280 ************************************************************************************************************/
2281 function wppizza_filter_menu_loop_article_close($markup, $post , $txt, $additives, $parameters, $is_rtl, $category, $articlecount){
2282 /********************
2283 parameters for convenience
2284 *********************/
2285 global $wppizza_options;
2286 $style = $parameters['global']['template']['style'];
2287 $post_count = $parameters['global']['post_count'];
2288
2289 /**is this required/uesful actually as class added to article??*/
2290 //if(is_single()){
2291 //$markup .= "</div>";
2292 //}
2293
2294 /*************************
2295
2296 markup
2297
2298 *************************/
2299 $markup['_article'] = '</article>';
2300
2301 /*
2302 end sections for grid layout
2303 */
2304 if(!is_single() && $style == 'grid' ){
2305 $section_count = (($articlecount)/$wppizza_options['layout']['style_grid_columns']);
2306 if(is_int($section_count) || $articlecount==$post_count){
2307 $markup['_section'] = '</section>';
2308 }
2309 }
2310
2311 return $markup;
2312 }
2313
2314 /************************************************************************************************************
2315 *
2316 *
2317 *
2318 * [ markup parts - no_results]
2319 *
2320 *
2321 * return @array
2322 ************************************************************************************************************/
2323 function wppizza_filter_menu_no_results($markup, $txt, $additives, $parameters, $is_rtl, $category){
2324 /********************
2325 parameters for convenience
2326 *********************/
2327 $style = $parameters['global']['template']['style'];
2328
2329 /*********************
2330 set classes
2331 *********************/
2332 $noresults_class = array();
2333 /*general class*/
2334 $noresults_class[] = ''.WPPIZZA_SLUG.'-no_results_found';
2335 /*selected style class*/
2336 $noresults_class[] = ''.WPPIZZA_SLUG.'-no_results_found-'.$style.'';
2337 /*rtl class*/
2338 $noresults_class[] = !empty($is_rtl) ? ''.WPPIZZA_SLUG.'-no_results_found-rtl' : '';
2339
2340 /*
2341 allow filtering
2342 */
2343 $noresults_class = apply_filters('wppizza_filter_noresults_class', $noresults_class);
2344
2345 /*
2346 implode for output
2347 */
2348 $noresults_class= implode(' ', $noresults_class);
2349
2350 /*************************
2351
2352 markup
2353
2354 *************************/
2355 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/no_results.php')){
2356 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/no_results.php');
2357 }else{
2358 require(WPPIZZA_PATH.'templates/markup/loop/no_results.php');
2359 }
2360
2361 /*********************
2362 apply filter if required
2363 *********************/
2364 $markup = apply_filters('wppizza_filter_menu_noresults_markup', $markup, $style);
2365
2366 return $markup;
2367 }
2368 /************************************************************************************************************
2369 *
2370 *
2371 *
2372 * [ markup parts - additives]
2373 *
2374 *
2375 * return @array
2376 ************************************************************************************************************/
2377 function wppizza_filter_menu_additives($markup, $txt, $additives, $parameters, $is_rtl, $category){
2378 /********************
2379 parameters for convenience
2380 *********************/
2381 $style = $parameters['global']['template']['style'];
2382
2383
2384 /*
2385 get all allergens defined
2386 */
2387 $allergens = wppizza_all_allergens();
2388 /* only return allergens that are in fact associated with the menu items displyed on that page */
2389 $allergens = array_intersect_key($allergens, $parameters['global']['allergens']);
2390
2391 /*
2392 get all additives defined
2393 */
2394 $additives = wppizza_all_additives();
2395 /* only actually return additives that are in fact associated with the menu items displyed on that page */
2396 $additives = array_intersect_key($additives, $parameters['global']['additives']);
2397
2398 /*********************
2399 set classes
2400 *********************/
2401 $class = array();
2402 /*general class*/
2403 $class[] = ''.WPPIZZA_SLUG.'-additives';
2404 /*selected style class*/
2405 $class[] = ''.WPPIZZA_SLUG.'-additives-'.$style.'';
2406
2407 //add icon class
2408 $has_icons = array_filter(wppizza_array_column($allergens, 'icon'));
2409 if(!empty($has_icons)){
2410 $class[] = WPPIZZA_SLUG.'-additives-icons';
2411 }
2412
2413
2414
2415 /*rtl class*/
2416 //$class[] = !empty($is_rtl) ? ''.WPPIZZA_SLUG.'-additives-rtl' : '';
2417
2418 /*
2419 allow filtering
2420 */
2421 $class = apply_filters('wppizza_filter_menu_additives_class', $class);
2422
2423 /*
2424 implode for output
2425 */
2426 $class= implode(' ', $class);
2427
2428
2429
2430 /*************************
2431
2432 markup
2433
2434 *************************/
2435 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/additives.php')){
2436 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/additives.php');
2437 }else{
2438 require(WPPIZZA_PATH.'templates/markup/loop/additives.php');
2439 }
2440
2441 /*********************
2442 apply filter if required
2443 *********************/
2444 $markup = apply_filters('wppizza_filter_menu_additives_markup', $markup, $style);
2445
2446 return $markup;
2447 }
2448
2449 /************************************************************************************************************
2450 *
2451 *
2452 *
2453 * [ markup parts - pagination]
2454 *
2455 * return @array
2456 *
2457 ************************************************************************************************************/
2458 function wppizza_filter_menu_pagination($markup, $txt, $additives, $parameters, $is_rtl, $category){
2459
2460 /********************
2461 parameters for convenience
2462 *********************/
2463 $max_num_pages = $parameters['global']['max_num_pages'];
2464 $force_get_the_posts_pagination = false;
2465 $style = $parameters['global']['template']['style'];
2466
2467 /*********************
2468 set classes
2469 *********************/
2470 $pagination_class = array();
2471 /*general class*/
2472 $pagination_class[] = 'navigation';
2473 $pagination_class[] = ''.WPPIZZA_SLUG.'-navigation';
2474 /*selected style class*/
2475 $pagination_class[] = ''.WPPIZZA_SLUG.'-navigation-'.$style.'';
2476 /*rtl class*/
2477 $pagination_class[] = !empty($is_rtl) ? ''.WPPIZZA_SLUG.'-navigation-rtl' : '';
2478 /*
2479 allow filtering
2480 */
2481 $pagination_class= apply_filters('wppizza_filter_menu_pagination_class', $pagination_class);
2482
2483 /*
2484 implode for output
2485 */
2486 $pagination_class= implode(' ', $pagination_class);
2487
2488 /*
2489 available since WP 4.1
2490 */
2491 if(function_exists('get_the_posts_pagination') && defined('WPPIZZA_WP41_POSTS_PAGINATION')){
2492 /*set flag*/
2493 $force_get_the_posts_pagination = true;
2494
2495 /*filterable args*/
2496 $args = array(
2497 'mid_size' => 1,
2498 'prev_text' => $txt['previous'],
2499 'next_text' => $txt['next'],
2500 'screen_reader_text' => __( 'Posts navigation', 'default' ),
2501 );
2502
2503 $args = apply_filters('wppizza_filter_menu_pagination_args', $args);
2504
2505 /*
2506 NOTE: get_the_posts_pagination does not seem to want to listen to
2507 the max_num_pages of the query, so we capture what it is, force it
2508 to be the max_num_pages we need for the pagination, and reset it again after
2509 */
2510 /*set $GLOBALS['wp_query']->max_num_pages to max num pages of this wppizza query*/
2511 global $wp_query;
2512 $get_max_num_pages = $wp_query->max_num_pages;/*allow to reset again*/
2513 $wp_query->max_num_pages = $max_num_pages;
2514 }
2515
2516 /*************************
2517
2518 markup
2519
2520 *************************/
2521 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/loop/pagination.php')){
2522 require(WPPIZZA_TEMPLATE_DIR.'/markup/loop/pagination.php');
2523 }else{
2524 require(WPPIZZA_PATH.'templates/markup/loop/pagination.php');
2525 }
2526
2527 /*********************
2528 apply filter if required
2529 *********************/
2530 $markup = apply_filters('wppizza_filter_menu_pagination_markup', $markup, $style);
2531
2532 /*
2533 get_the_posts_pagination available since WP 4.1 - reset wp_query (see notes above)
2534 */
2535 if(function_exists('get_the_posts_pagination') && defined('WPPIZZA_WP41_POSTS_PAGINATION')){
2536 $wp_query->max_num_pages = $get_max_num_pages;
2537 }
2538
2539 return $markup;
2540 }
2541 /************************************************************************************************************
2542 *
2543 *
2544 *
2545 * [ markup - add_item_to_cart_button ]
2546 *
2547 *
2548 *
2549 ************************************************************************************************************/
2550 function add_item_to_cart_button($atts){
2551 global $wppizza_options, $blog_id;
2552
2553 $markup = '';
2554
2555 /*missing or empty attributes**/
2556 if(!isset($atts['id']) || $atts['id']<=0 || $atts['id']=='' ){
2557 return $markup;
2558 }
2559 /**not the correct post type*/
2560 $posttype=get_post_type( $atts['id'] );
2561 if($posttype!=WPPIZZA_POST_TYPE){
2562 return $markup;
2563 }
2564
2565 /*
2566 get first category associated to item
2567 unless specifically set
2568 */
2569 if(empty($atts['category_id'])){
2570 $first_term = wp_get_post_terms($atts['id'], WPPIZZA_TAXONOMY);
2571 $first_term = reset($first_term);
2572 $category_id = $first_term->term_id;
2573 }else{
2574 $category_id = (int)$atts['category_id'];
2575 }
2576
2577 /* get sizes for this menu item*/
2578 $meta = get_post_meta($atts['id'], WPPIZZA_SLUG, true);//, WPPIZZA_SLUG, true
2579
2580 /*size id*/
2581 $size = $meta['sizes'];
2582
2583 /*price/tier id*/
2584 $selectedPrice=0;//default to first
2585
2586 /*check if size exists*/
2587 if(isset($atts['size']) && isset($meta['prices'][$atts['size']])){
2588 $selectedPrice = $atts['size'];
2589 }
2590
2591 $dropdown='';
2592 $hasdropdown=false;
2593 if(empty($atts['single'])){/*if not forced to single button*/
2594 if(count($meta['prices'])>1){
2595 $hasdropdown=true;
2596 $dropdown.='<select id="wppizza-add-to-cart-size-'.$atts['id'].'" class="wppizza-add-to-cart-size">';
2597 foreach($meta['prices'] as $selPrice=>$value){
2598 $dropdown.='<option value="'.$size.'-'.$selPrice.'" '.selected($selPrice,$selectedPrice,false).'>'.$wppizza_options['sizes'][$size][$selPrice]['lbl'].'</option>';
2599 }
2600 $dropdown.='</select>';
2601 }
2602 }
2603
2604 /****label - filterable****/
2605 $add_item_to_cart_button_label = apply_filters('wppizza_filter_add_item_to_cart_button_label', $wppizza_options['localization']['add_to_cart'], $atts);
2606
2607
2608 /****output****/
2609 $markup='<span id="wppizza-add-to-cart-btn-'.$atts['id'].'" class="wppizza-add-to-cart-btn-wrap">';
2610 if($hasdropdown){
2611 /**dropdown if multiple*/
2612 $markup.=$dropdown;
2613 /*size id and tier*/
2614 $markup.='<input type="button" id="'.WPPIZZA_SLUG.'-add-to-cart-select_'.$blog_id.'-'.$category_id.'-'.$atts['id'].'" class="'.WPPIZZA_SLUG.'-add-to-cart-select '.WPPIZZA_SLUG.'-add-to-cart-btn" value="'.$add_item_to_cart_button_label.'" />';
2615 }else{
2616 /*direct selection*/
2617 $markup.='<input type="button" id="'.WPPIZZA_SLUG.'-'.$blog_id.'-'.$category_id.'-'.$atts['id'].'-'.$size.'-'.$selectedPrice.'" class="'.WPPIZZA_SLUG.'-'.$addtocarttriggerclass.' '.WPPIZZA_SLUG.'-add-to-cart-btn" value="'.$add_item_to_cart_button_label.'" />';
2618 }
2619 $markup.='</span>';
2620
2621 return $markup;
2622 }
2623
2624
2625 /*************************************************************************************************************************************************************************
2626 *
2627 *
2628 *
2629 *
2630 * [helpers]
2631 *
2632 *
2633 *
2634 *
2635 *************************************************************************************************************************************************************************/
2636
2637 /********************************************************************************
2638 *
2639 * [get associated allergens/additives/foodtype
2640 * associated with a post]
2641 * @since 3.12.14
2642 *********************************************************************************/
2643 function get_post_aaf($post, $type, $class_ident){
2644
2645 $array = array();
2646
2647 $set_post_type = !empty($post->wppizza_data[$type]) ? $post->wppizza_data[$type] : array();
2648
2649 foreach($set_post_type as $key=>$value){
2650 $array[$key]['id'] = ''.WPPIZZA_SLUG.'-'.$class_ident.'-' . $post->ID . '-' .$key .'';
2651 $array[$key]['class'] = ''.WPPIZZA_SLUG.'-'.$class_ident.' '.WPPIZZA_SLUG.'-'.$class_ident.'-' .$key .'';
2652 if(!empty($value['icon'])){
2653 $array[$key]['class'] .= ' '.WPPIZZA_SLUG.'-'.$class_ident.'-icon '.WPPIZZA_SLUG.'-'.$class_ident.'-' .$value['icon'] .'';
2654 }
2655 $array[$key]['ident'] = $value['sort'];
2656 $array[$key]['name'] = $value['name'];
2657 }
2658
2659 return $array;
2660 }
2661
2662
2663
2664 /********************************************************************************
2665 *
2666 * [get all terms]
2667 *
2668 *********************************************************************************/
2669 function get_wppizza_terms(){
2670 global $wppizza_options;
2671 if($wppizza_options==0){return;}
2672 /* get sorted categories */
2673 $this->wppizza_terms = WPPIZZA()->categories->wppizza_get_cats_hierarchy($wppizza_options['layout']['category_sort_hierarchy']);
2674 return ;
2675 }
2676 /********************************************************************************
2677 *
2678 * [get all terms - with slugs as keys]
2679 *
2680 *********************************************************************************/
2681 function get_wppizza_terms_by_slug(){
2682
2683 static $terms = null;
2684
2685 if($terms === null){
2686
2687 $terms = array();
2688
2689 foreach($this->wppizza_terms as $term_id=>$term_sort){
2690 $get_term = get_term( $term_id, WPPIZZA_TAXONOMY );
2691 $terms[$get_term->slug]['id'] = $get_term->term_id;
2692 $terms[$get_term->slug]['slug'] = $get_term->slug;
2693 $terms[$get_term->slug]['name'] = $get_term->name;
2694 $terms[$get_term->slug]['description'] = apply_filters( 'term_description', $get_term->description);
2695 $terms[$get_term->slug]['parent'] = $get_term->parent;
2696 $terms[$get_term->slug]['count'] = $get_term->count;
2697 }
2698
2699 $this->wppizza_terms_by_slug = $terms;
2700 }
2701
2702
2703 return $this->wppizza_terms_by_slug;
2704 }
2705
2706 /********************************************************************************
2707 *
2708 * [set paged var]
2709 *
2710 *********************************************************************************/
2711 function set_paged_var(){
2712 global $paged;
2713
2714 /* home|frontpage uses "page" instead of "paged". no, dunno either*/
2715 if(is_home() || is_front_page()){
2716 $paged = (get_query_var('page')) ? get_query_var('page') : 1 ;
2717 }else{
2718 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1 ;
2719 }
2720
2721 return $paged;
2722 }
2723
2724 /*************************************************************
2725 *
2726 * custom class(es) to add for this template
2727 *
2728 *************************************************************/
2729 function set_template_item_class($atts){
2730 $item_class= !empty($atts['item_class']) ? wppizza_validate_alpha_only($atts['item_class'], true) : '';
2731 return $item_class;
2732 }
2733 /*************************************************************
2734 *
2735 * set style to use for this template if set and available
2736 * defaulting to what is set in wppizza->layout otherwise
2737 *
2738 *************************************************************/
2739 function set_template_style($atts){
2740 global $wppizza_options;
2741
2742 $set_style = isset($atts['style']) ? wppizza_validate_alpha_only($atts['style']) : '' ;
2743
2744 /*
2745 default to style set in wppizza->layout
2746 in case style set is invalid
2747 */
2748 $style = $wppizza_options['layout']['style'];
2749
2750 if(isset($set_style) && $set_style!=''){
2751 /*
2752 set as string
2753 */
2754 if(!is_numeric($set_style)){
2755
2756 /*
2757 styles registered in wppizza->layout
2758 */
2759 $styles_registered = wppizza_public_styles();
2760
2761 /*
2762 allow for filtering of allowed style attribute in shortcodes
2763 */
2764 $styles_registered = apply_filters('wppizza_filter_registered_shortcode_styles', $styles_registered);
2765
2766 if(isset($styles_registered[$set_style])){
2767 $style = $set_style;
2768 }
2769 }
2770 /**future use if using template id's*/
2771 if(is_numeric($set_style)){
2772 /*
2773 todo when it's available
2774 */
2775 }
2776 }
2777
2778 return $style;
2779 }
2780
2781 /*************************************************************
2782 *
2783 * which modules to display
2784 * defaulting to 'title, thumbnail, prices, content' (in that order)
2785 *
2786 * return array
2787 *************************************************************/
2788 function set_template_elements($atts, $style){
2789
2790 global $wppizza_options;
2791 /*available modules*/
2792 $available_elements = array('title', 'thumbnail', 'category', 'prices', 'content', 'permalink', 'comments', 'additives', 'foodtype');
2793
2794 /*
2795 default modules in modules order - as string
2796 depending on style used
2797 */
2798 $styles_registered = wppizza_public_styles();
2799 $styles_registered = apply_filters('wppizza_filter_registered_shortcode_styles', $styles_registered);
2800 $default_elements = $styles_registered[$style]['elements'];
2801
2802 /*
2803 set include modules
2804 */
2805 $set_include_elements = !empty($atts['elements']) ? $atts['elements'] : $default_elements ;
2806 $set_include_elements = explode(',', $set_include_elements);
2807
2808 /*
2809 set exclude modules - setting by shortcode attributes currently not implemented
2810 */
2811 $set_exclude_elements = array();
2812 //$set_exclude_elements = !empty($atts['elements_exclude']) ? $atts['elements_exclude'] : array() ;
2813 //$set_exclude_elements = explode(',', $set_exclude_elements);
2814 /*remove prices if specifically set in layout*/
2815 if(!empty($wppizza_options['prices_format']['hide_prices'])){
2816 $set_exclude_elements['prices'] = 'prices';
2817 }
2818
2819 /*
2820 loop and include/exclude
2821 */
2822 $elements = array();
2823 foreach($set_include_elements as $element){
2824 $element = strtolower(trim($element));/*cast to lowercase*/
2825 if(in_array($element, $available_elements) && !in_array($element, $set_exclude_elements)){
2826 $elements[$element] = $element;
2827 }
2828 }
2829
2830 return $elements;
2831 }
2832
2833 /*************************************************************
2834 *
2835 * which elements to use/show/hide, overriding whats set in layout
2836 * unless specifically set in wppizza->layout
2837 *
2838 * return array
2839 *************************************************************/
2840 function set_template_attributes($atts){
2841 global $wppizza_options;
2842
2843 /*
2844 for convenience. map 0|off/left/right
2845 */
2846 $map_position['off'] = 0;
2847 $map_position['0'] = 0;
2848 $map_position['left'] = 'left';
2849 $map_position['1'] = 'left';
2850 $map_position['right'] = 'right';
2851 $map_position['2'] = 'right';
2852 /*
2853 set main currency position
2854 0=off
2855 1 = left
2856 2 = right
2857 */
2858 /*default to off first of all*/
2859 $main_currency_position = 0;
2860 /**att not set, use globsl setting*/
2861 if(!isset($atts['currency_main'])){
2862 /*not hiding*/
2863 if(empty($wppizza_options['prices_format']['hide_item_currency_symbol'])){
2864 /*right, default*/
2865 if(empty($wppizza_options['prices_format']['currency_symbol_left'])){
2866 $main_currency_position = $map_position[2];
2867 }else{
2868 $main_currency_position = $map_position[1];
2869 }
2870 }
2871 }
2872 /**set in attribute**/
2873 if(isset($atts['currency_main'])){
2874 $main_currency_position = $map_position[$atts['currency_main']];
2875 }
2876
2877 /*main currency symbols*/
2878 $elements['currency_main'] = $main_currency_position ;/*main currency symbol*/
2879 $elements['currency_price'] = (isset($atts['currency_price']) && in_array($atts['currency_price'],array('0','left','right')))? $map_position[$atts['currency_price']] : $map_position[$wppizza_options['prices_format']['show_currency_with_price']];/*currency next to each price, 0-off, 1-left 2-right*/
2880
2881 /*images*/
2882 $elements['image_placeholder'] = isset($atts['image_placeholder']) ? wppizza_validate_boolean($atts['image_placeholder']) : $wppizza_options['layout']['placeholder_img'];
2883 $elements['image_prettyphoto'] = isset($atts['image_prettyphoto']) ? wppizza_validate_boolean($atts['image_prettyphoto']) : $wppizza_options['layout']['prettyPhoto'];
2884
2885 return $elements;
2886 }
2887
2888 /*************************************************************
2889 *
2890 * set parameters we can use when filtering classes
2891 * unless specifically set in wppizza->layout
2892 *
2893 * return array
2894 *************************************************************/
2895 function set_post_classes_filter_parameters($post, $parameters, $articlecount){
2896
2897 $filter_parameters = array();
2898
2899 $filter_parameters['post_data'] = $post;
2900
2901 $filter_parameters['layout'] = $parameters['global']['template'];
2902
2903 $filter_parameters['parameters'] = array();
2904 $filter_parameters['parameters']['shortcode_type'] = $parameters['global']['shortcode_type'];
2905 $filter_parameters['parameters']['post_count'] = $parameters['global']['post_count'];
2906 $filter_parameters['parameters']['max_num_pages'] = $parameters['global']['max_num_pages'];
2907 $filter_parameters['parameters']['categoy'] = $parameters['global']['categoy'];
2908
2909 $filter_parameters['articlecount'] = $articlecount;
2910
2911 $filter_parameters['session'] = '--- [#to add perhaps#] ---';
2912
2913 return $filter_parameters;
2914 }
2915 }
2916 ?>