getters * *********************************************************************************************/ /************************************************************* * * get/set array key/values for new templates or default on install * *************************************************************/ function admin_template_get_values($tplType, $tplId, $tplValues, $arrayIdent){ /* in case we add some other template types one day */ if($tplType=='print' || $tplType=='emails'){ /* section/template values */ $tpl_args = array( 'tpl_type' => $tplType, 'tpl_id' => $tplId, 'tpl_values'=> $tplValues, ); $tpl_values = WPPIZZA()->order->orders_formatted(array(), $tpl_args, 'template_values_'.$tplId.''); } return $tpl_values; } /************************************************************* * * create admin markup of email/print templates * *************************************************************/ function admin_template($msgKey, $templateKey, $templateSetValues = false, $arrayIdent = 'templates'){ global $wppizza_options; /* get default for new template or use set values */ $tplVals = $this->admin_template_get_values($templateKey, $msgKey, $templateSetValues, $arrayIdent); /* re-sort sections as set for display in admin */ if(!empty($templateSetValues['sort'])){ $tpl_section_sort = array(); foreach($templateSetValues['sort'] as $section_key => $section ){ $tpl_section_sort[$section_key] = $tplVals['sections'][$section_key]; } /* now overwrite old order */ $tplVals['sections'] = $tpl_section_sort; } /* create markup */ $markup = ''; /** template div wrapper **/ $markup.=''; $markup.='
'; /****************************** header/main options ******************************/ $markup.=''; $markup.=''; $markup.=''; /** print template , add "use" button/radio **/ if($templateKey=='print'){ $markup.=''; } /** title/label internal **/ $markup.=''; /** format **/ $markup.=''; /** email main recipients **/ if($templateKey=='emails'){ $markup.=''; } /** email additional recipients **/ if($templateKey=='emails'){ $markup.=''; } /** email attachments **/ if($templateKey=='emails'){ $markup.=''; } /** edit, preview, locked etc right **/ $markup.=''; $markup.=''; $markup.=''; $markup.='
'; $markup.=''; $markup.=''; $markup.=''; $markup.=''; /*mail type */ $markup.=''; $markup.=''; $markup.=''.__('email recipients','wppizza-admin').':'; foreach($tplVals['recipients'] as $recKey=>$recTitle){ $markup.=''; } $markup.=''; $markup.=''; $markup.=''; $markup.=''; $markup.=''; $markup.=''; $icons = array(); /*icon edit*/ $icons['edit'] = ""; /*icon code edit (show css/style)*/ $icons['css'] = ''; /*icon preview*/ $icons['preview'] = ""; /*icon delete - only for template id's >0 to always keep default, filterable in case other plugins use templates that are not used otherwise*/ $prevent_delete = apply_filters('wppizza_prevent_template_delete', array(0), $templateKey); if(!in_array($msgKey, $prevent_delete )){ $icons['delete'] = ""; } /* allow adding / splicing icons before imploding for markup */ $icons = apply_filters('wppizza_filter_template_icons_'.$templateKey.'', $icons, $templateKey, $msgKey, $arrayIdent); $markup .= implode('',$icons); $markup.='
'; /****************************** drag drop sections ******************************/ $markup.=''; $markup.=''; $markup.=''; /* * iterate through sections - in order of sort */ foreach($tplVals['sections'] as $section_key=>$section){ $markup.=''; } $markup.=''; $markup.=''; $markup.='
'; /* section on off and sort icon */ $markup.='
'; $markup.=''; $markup.=''; $markup.=''; $markup.=''; $markup.='';//'.$section_key.' $markup.=''; $markup.='
'; /* label enable wrap */ $markup.='
'; /* section header label on/off */ $markup.=''; $markup.='
'; /* drag/drop on/off variables */ $markup.='
'; foreach($section['parameters'] as $section_value_key=>$section_value){ $markup.='
'; /* drag/drop icon and hidden input to save selected order regardless of whether checkbox was selected */ $markup.=''; $markup.='';//'.$section_value_key.' $markup.=''; /* checkbox with label */ $markup.=''; $markup.='
'; } $markup.='
'; $markup.='
'; /****************************** global styles ******************************/ $markup.=''; $markup.=''; $markup.=''; $markup.=''; $markup.=''; $markup.=''; $markup.='
'; $markup.=''; if($templateKey=='emails'){ $markup.=''; $markup.=''; } $markup.='
'; /****************************** sections styles - emails only ******************************/ if($templateKey=='emails'){ $markup.=''; $markup.=''; $markup.=''; /* * iterate through sections */ foreach($tplVals['sections'] as $section_key=>$section){ $markup.=''; } $markup.=''; $markup.=''; $markup.='
'; /* label */ $markup.='
'; $markup.=''.__('Section Styles','wppizza-admin').' - '.$section['labels']['label'].''; $markup.='
'; /* style table */ $markup.='
'; $markup.=''; $markup.=''; $markup.='
'; /* style header */ $markup.='
'; $markup.=''; $markup.=''; $markup.='
'; /* style columns all */ $markup.='
'; /**labels**/ if($section_key=='order'){ $markup.=''; }else{ $markup.=''; } /**site vars have one td only**/ if($section_key=='site'){ $markup.=''.__('Column All','wppizza-admin').'
'; $markup.=''; }else{ $markup.='
'; $markup.=''.__('Left Column All','wppizza-admin').'
'; $markup.=''; $markup.='
'; /*order vars have 3 columns*/ if($section_key=='order'){ $markup.='
'; $markup.=''.__('Center Column All','wppizza-admin').'
'; $markup.=''; $markup.='
'; } $markup.='
'; $markup.=''.__('Right Column All','wppizza-admin').'
'; $markup.=''; $markup.='
'; } $markup.='
'; /* style rows */ $markup.='
'; /*skip for order items*/ if($section_key != 'order'){ $markup.=''; foreach($section['parameters'] as $section_value_key=>$section_value){ $markup.='
'; $markup.= $section_value['label'].'
'; $markup.='';//$tplVals['style'][$section_key][''.$section_value_key.'-tdall']//'.$section_value[''.$section_key.'-tdall'].' $markup.='
'; } } /* add styles for blogname and categories if displayed */ if($section_key=='order'){ $markup.=''; $markup.='
'; $markup.=''.__('Blogname','wppizza-admin').'
'; $markup.=''; $markup.='
'; $markup.='
'; $markup.=''.__('Category','wppizza-admin').'
'; $markup.=''; $markup.='
'; } $markup.='
'; $markup.='
'; } $markup.='
'; return $markup; } /*************************************************************************************************************************************************************************************************************************** * * * * plaintext template parts * * * ****************************************************************************************************************************************************************************************************************************/ function get_template_email_plaintext_sections_markup($order_formatted, $template_parameters, $template_type, $template_id = '', $template_contents = '' , $return_sections = false){ $tpl = array(); /* remove some potential notices for empty parameters */ if(empty($order_formatted['sections'])){ $order_formatted['sections'] = array() ; } /** loop through sections in the order they were set when saving the drag drop template **/ if(isset($template_parameters['sections'])){ foreach($template_parameters['sections'] as $section_key => $section_values){ if(!empty($section_values['section_enabled'])){ /* allow filtering to override whats saved in templates creating an empty array if it does not exist to avoid php warnings */ if(!isset($section_values['parameters'])){ $section_values['parameters'] = array(); } $section_values['parameters'] = apply_filters('wppizza_filter_template_section_parameters', $section_values['parameters'], $section_key, $template_parameters, $template_type); /************************************** * * * site vars * * **************************************/ if($section_key == 'site'){ $tpl[$section_key] = array(); /*************************************** label / legend ****************************************/ if(!empty($section_values['label_enabled'])){ $tpl[$section_key]['section_label'] = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); /* filter for even spacing **/ $tpl[$section_key]['section_label'] = apply_filters('wppizza_filter_plaintext_line', $tpl[$section_key]['section_label'], ' '); } /*************************************** rows ***************************************/ foreach($section_values['parameters'] as $value_key => $values){ if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ /* centered, without labels */ $row = array(); $row['ctr'] = $order_formatted['sections'][$section_key][$value_key]['value_formatted']; /** line **/ $tpl[$section_key][$value_key] = apply_filters('wppizza_filter_plaintext_line', $row, ' '); } } /**************************************** implode label and details for output ****************************************/ $tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /* allow filtering of whole section string (maybe using regexes) */ $tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); } /************************************** * * * general order parameters * * **************************************/ if($section_key == 'ordervars'){ $tpl[$section_key] = array(); /*************************************** label / legend ****************************************/ if(!empty($section_values['label_enabled'])){ $tpl[$section_key]['section_label'] = trim($order_formatted['localization']['templates_label_'.$section_key.'']); /* filter for even spacing **/ $tpl[$section_key]['section_label'] = apply_filters('wppizza_filter_plaintext_line', $tpl[$section_key]['section_label'], ' '); } /*************************************** rows ***************************************/ foreach($section_values['parameters'] as $value_key => $values){ if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ /* left label, right value using filter to space evenly*/ $row = array(); $row['lft'] = $order_formatted['sections'][$section_key][$value_key]['label']; $row['rgt'] = $order_formatted['sections'][$section_key][$value_key]['value_formatted']; /** line **/ $tpl[$section_key][$value_key] = apply_filters('wppizza_filter_plaintext_line', $row, ' '); } } /** implode for output */ $tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /* allow filtering of whole section string (maybe using regexes) */ $tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); } /************************************** * * * customer vars * * **************************************/ if($section_key == 'customer'){ $tpl[$section_key] = array(); /*************************************** label / legend ****************************************/ if(!empty($section_values['label_enabled'])){ $tpl[$section_key]['section_label'] = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); /* filter for even spacing **/ $tpl[$section_key]['section_label'] = apply_filters('wppizza_filter_plaintext_line', $tpl[$section_key]['section_label'], ' '); } /*************************************** rows ***************************************/ foreach($section_values['parameters'] as $value_key => $values){ if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ /* if omit_if_optional is set, omit formfield if field is not required to be filled in the 'required_attribute' willalready be set (or not as the case may be) depending on if it's pickup or delivery and required or not for those */ if(!empty($order_formatted['sections'][$section_key][$value_key]['omit_if_optional']) && empty($order_formatted['sections'][$section_key][$value_key]['required_attribute'])){ continue; } /* left label, right value using filter to space evenly */ $row = array(); /* label */ $row['lft'] = $order_formatted['sections'][$section_key][$value_key]['label']; // value /* radios and dropdowns need to be mapped back from numerical index to value */ //selects/dropdowns if($order_formatted['sections'][$section_key][$value_key]['type'] == 'select'){ //for backward compatibility, if using test as key as opposed to numeric indexes , decode entities $selIdx = wppizza_decode_entities($order_formatted['sections'][$section_key][$value_key]['value']); $value = isset($order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]['label']) ? $order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]['label'] : '' ; } //radios elseif($order_formatted['sections'][$section_key][$value_key]['type'] == 'radio'){ $selIdx = $order_formatted['sections'][$section_key][$value_key]['value']; $value = isset($order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]) ? $order_formatted['sections'][$section_key][$value_key]['options'][$selIdx] : '' ; } //multicheckboxes elseif($order_formatted['sections'][$section_key][$value_key]['type'] == 'multicheckbox'){ //selected indexes (comma seperated string) $selVals = $order_formatted['sections'][$section_key][$value_key]['value']; //available indexes (array) $optIdxs = $order_formatted['sections'][$section_key][$value_key]['options']; //init empty $output = ''; //map selected indexes back to values if($selVals != ''){ $selIdxs = array_flip(wppizza_strtoarray($selVals)); $intersect = array_intersect_key($optIdxs, $selIdxs); $output = implode(', ',$intersect); } $value = $output; } //all other else{ $value = $order_formatted['sections'][$section_key][$value_key]['value']; } /* right hand side (i.e the value selected/entered) */ $row['rgt'] = $value; /** line **/ $tpl[$section_key][$value_key] = apply_filters('wppizza_filter_plaintext_line', $row, ' '); } } /** implode for output */ $tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /* allow filtering of whole section string (maybe using regexes) */ $tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); } /************************************** * * * itemised order vars * * **************************************/ if($section_key == 'order'){ /*************************************** get order column data ***************************************/ $order_columns = WPPIZZA()->helpers->itemised_order_columns($order_formatted, $template_parameters, $template_type); /*************************************** ini array ***************************************/ $tpl[$section_key] = array(); /*************************************** label / legend - spaced by "-" ****************************************/ if(!empty($section_values['label_enabled'])){ $tpl[$section_key]['section_label'] = $order_columns['column_label']['plaintext']; } /**************************************** itemised order rows ****************************************/ $tpl[$section_key]['itemised'] = $order_columns['itemised']['plaintext']; /**************************************** implode label and details for output ****************************************/ $tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /* allow filtering of whole section string (maybe using regexes) */ $tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); } /************************************** * * * summary vars * - todo template vars need to match * **************************************/ if($section_key == 'summary'){ $tpl[$section_key] = array(); /*************************************** label / legend ****************************************/ if(!empty($section_values['label_enabled'])){ $tpl[$section_key]['section_label'] = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); /* filter for even spacing **/ $tpl[$section_key]['section_label'] = apply_filters('wppizza_filter_plaintext_line', $tpl[$section_key]['section_label'], ' '); } /*************************************** rows ***************************************/ foreach($section_values['parameters'] as $value_key => $values){ if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ foreach($order_formatted['sections'][$section_key][$value_key] as $vKey => $vals){ /* left label, right value using filter to space evenly*/ $row = array(); $row['lft'] = $vals['label']; $row['rgt'] = $vals['value_formatted']; /** line **/ $tpl[$section_key][$value_key.'_'.$vKey] = apply_filters('wppizza_filter_plaintext_line', $row, ' '); } } } /** implode for output */ $tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /* allow filtering of whole section string (maybe using regexes) */ $tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); } }}} /************************************** * * if using get_skeleton_template with content set * adding hardcoded divider **************************************/ if(!empty($template_contents)){ $section_key = 'contents'; $tpl[$section_key.'_divider'] = apply_filters('wppizza_filter_plaintext_line', '', '='); $tpl[$section_key] = apply_filters('wppizza_filter_plaintext_line', $template_contents, ' ', true); } /************************************** * * * add footer after everything else * emails only * **************************************/ if($template_type=='emails'){ $section_key = 'footer'; $tpl[$section_key] = array(); /** add centered note after **/ $tpl[$section_key]['divider'] = apply_filters('wppizza_filter_plaintext_line', '', '='); if(!empty($order_formatted['localization']['templates_footer_note'])){ $tpl[$section_key]['footer_note'] = apply_filters('wppizza_filter_plaintext_line', $order_formatted['localization']['templates_footer_note'], ' ', true); } /** implode for output */ $tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /* allow filtering of whole section string (maybe using regexes) */ $tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); } /************************************** * * * add footer after everything else * print only * **************************************/ if($template_type=='print'){ $section_key = 'footer'; $tpl[$section_key] = array(); /** add centered note after **/ $tpl[$section_key]['divider'] = apply_filters('wppizza_filter_plaintext_line', '', '='); if(!empty($order_formatted['localization']['templates_footer_note_print'])){ $tpl[$section_key]['footer_note'] = apply_filters('wppizza_filter_plaintext_line', $order_formatted['localization']['templates_footer_note_print'], ' ', true); } /** implode for output */ $tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /* allow filtering of whole section string (maybe using regexes) */ $tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); } /* allow filtering of each section (maybe using regexes - though using above filters in each section would probably be a better idea) */ $tpl = apply_filters('wppizza_filter_template_markup_plaintext', $tpl, $template_type, $template_id, $order_formatted); /** return just the sections as array before wrapping it into an html document **/ if($return_sections){ return $tpl; } /** output as string **/ $tpl['markup'] = implode(PHP_EOL.PHP_EOL,$tpl); return $tpl; } /********************************************************************************************************************************************************************************************************************************** * * * * html templates * * * ***********************************************************************************************************************************************************************************************************************************/ function get_template_email_html_sections_markup($order_formatted, $template_parameters, $template_type, $template_id, $template_contents = '', $return_sections = false){ $tpl = array(); /* remove some potential notices for empty parameters */ if(empty($order_formatted['sections'])){$order_formatted['sections'] = array() ;} /** loop through sections in the order they were set when saving the drag drop template **/ if(isset($template_parameters['sections'])){ foreach($template_parameters['sections'] as $section_key => $section_values){ /* allow filtering to override/add what's saved in templates creating an empty array if it does not exist to avoid php warnings */ if(!isset($section_values['parameters'])){ $section_values['parameters'] = array(); } $section_values['parameters'] = apply_filters('wppizza_filter_template_section_parameters', $section_values['parameters'], $section_key, $template_parameters, $template_type); /* allow filtering of html style to override/add what's saved in templates hook updated for 3.1.3 to only apply to this section adding template id and order_formatted[sections] to pass on all order parameters */ $section_values['style'] = empty($section_values['style']) ? array() : $section_values['style']; $section_values['style'] = apply_filters('wppizza_filter_template_section_'.$section_key.'_styles', $section_values['style'], $template_parameters['sections'][$section_key], $template_type, $template_id, $order_formatted['sections']); if(!empty($section_values['section_enabled'])){ /********************************************************** * * * site vars - typically labelled "Site Details" in Wppizza -> Templates * * **********************************************************/ if($section_key == 'site'){ $tpl[$section_key] = array(); /*************************************** label / legend ****************************************/ if(!empty($section_values['label_enabled'])){ $section_label = trim($order_formatted['localization']['templates_label_'.$section_key.'']); /***wrap in tr/th, omit style declarations on print **/ $thStyle=($template_type=='print') ? '' : ' style="'.$section_values['style']['th'].'"'; $tpl[$section_key]['section_label'] =''.PHP_EOL.''.PHP_EOL.''.PHP_EOL.''.$section_label.''.PHP_EOL.''.PHP_EOL.''.PHP_EOL.''.PHP_EOL; } /**************************************** wrap in tbody ****************************************/ $tpl[$section_key]['tbody_'] =''.PHP_EOL; /*************************************** rows ***************************************/ foreach($section_values['parameters'] as $value_key => $values){ if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ /* centered, without labels */ $row = array(); $row['ctr'] = $order_formatted['sections'][$section_key][$value_key]['value_formatted']; /***wrap in tr/td**/ if($template_type=='emails'){ $set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices $tpl[$section_key][$value_key] =''.$row['ctr'].''.PHP_EOL; } if($template_type=='print'){ $tpl[$section_key][$value_key] =''.$row['ctr'].''.PHP_EOL; } } } /**************************************** close tbody ****************************************/ $tpl[$section_key]['_tbody'] =''.PHP_EOL; /**************************************** implode for output ****************************************/ $tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /**************************************** wrap in table ****************************************/ if($template_type=='emails'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } if($template_type=='print'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].''.PHP_EOL.''; } } /********************************************************** * * * general order parameters - typically labelled "Overview" in Wppizza -> Templates * * **********************************************************/ if($section_key == 'ordervars'){ $tpl[$section_key] = array(); /*************************************** label / legend ****************************************/ if(!empty($section_values['label_enabled'])){ $section_label = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); /***wrap in tr/th, omit style declarations on print **/ $thStyle=($template_type=='print') ? '' : ' style="'.$section_values['style']['th'].'"'; $tpl[$section_key]['section_label'] =''.PHP_EOL.''.PHP_EOL.''.PHP_EOL.''.$section_label.''.PHP_EOL.''.PHP_EOL.''.PHP_EOL.''.PHP_EOL; } /**************************************** wrap in tbody ****************************************/ $tpl[$section_key]['tbody_'] =''.PHP_EOL; /*************************************** rows ***************************************/ foreach($section_values['parameters'] as $value_key => $values){ if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ /* left label, right value using filter to space evenly*/ $row = array(); $row['lft'] = $order_formatted['sections'][$section_key][$value_key]['label']; $row['rgt'] = $order_formatted['sections'][$section_key][$value_key]['value_formatted']; /**date, pickup/delivery note or admin notes need no label**/ if($value_key=='order_date' || $value_key=='pickup_delivery' || $value_key=='admin_notes'){ /***wrap in tr/td**/ if($template_type=='emails'){ $set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices $tpl[$section_key][$value_key] =''.$row['rgt'].''.PHP_EOL; } if($template_type=='print'){ if( $value_key=='admin_notes'){/* use nl2br for admin notes */ $tpl[$section_key][$value_key] =''.nl2br($row['rgt']).''.PHP_EOL; }else{ $tpl[$section_key][$value_key] =''.$row['rgt'].''.PHP_EOL; } } }else{ /***wrap in tr/td**/ if($template_type=='emails'){ $set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices $tpl[$section_key][$value_key] =''.$row['lft'].''.$row['rgt'].''.PHP_EOL; } if($template_type=='print'){ $tpl[$section_key][$value_key] =''.implode('',$row).''.PHP_EOL; } } } } /**************************************** close tbody ****************************************/ $tpl[$section_key]['_tbody'] =''.PHP_EOL; /**************************************** implode for output ****************************************/ $tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL, $tpl[$section_key]); /**************************************** wrap in table ****************************************/ if($template_type=='emails'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } if($template_type=='print'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } } /********************************************************** * * * customer vars - typically labelled "Customer Details" in Wppizza -> Templates * * **********************************************************/ if($section_key == 'customer'){ $tpl[$section_key] = array(); /*************************************** label / legend ****************************************/ if(!empty($section_values['label_enabled'])){ $section_label = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); /***wrap in tr/th, omit style declarations on print **/ $thStyle=($template_type=='print') ? '' : ' style="'.$section_values['style']['th'].'"'; $tpl[$section_key]['section_label'] =''.PHP_EOL.''.PHP_EOL.''.PHP_EOL.''.$section_label.''.PHP_EOL.''.PHP_EOL.''.PHP_EOL.''.PHP_EOL; } /**************************************** wrap in tbody ****************************************/ $tpl[$section_key]['tbody_'] =''.PHP_EOL; /*************************************** rows ***************************************/ foreach($section_values['parameters'] as $value_key => $values){ if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ /* if omit_if_optional is set, omit formfield if field is not required to be filled in the 'required_attribute' willalready be set (or not as the case may be) depending on if it's pickup or delivery and required or not for those */ if(!empty($order_formatted['sections'][$section_key][$value_key]['omit_if_optional']) && empty($order_formatted['sections'][$section_key][$value_key]['required_attribute'])){ continue; } /* left label, right value using filter to space evenly */ $row = array(); /* label */ $row['lft'] = $order_formatted['sections'][$section_key][$value_key]['label']; // value /* radios and dropdowns need to be mapped back from numerical index to value */ //selects/dropdowns if($order_formatted['sections'][$section_key][$value_key]['type'] == 'select'){ //for backward compatibility, if using test as key as opposed to numeric indexes , decode entities $selIdx = wppizza_decode_entities($order_formatted['sections'][$section_key][$value_key]['value']); $value = isset($order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]['label']) ? $order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]['label'] : '' ; } //radios elseif($order_formatted['sections'][$section_key][$value_key]['type'] == 'radio'){ $selIdx = $order_formatted['sections'][$section_key][$value_key]['value']; $value = isset($order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]) ? $order_formatted['sections'][$section_key][$value_key]['options'][$selIdx] : '' ; } //multicheckboxes elseif($order_formatted['sections'][$section_key][$value_key]['type'] == 'multicheckbox'){ //selected indexes (comma seperated string) $selVals = $order_formatted['sections'][$section_key][$value_key]['value']; //available indexes (array) $optIdxs = $order_formatted['sections'][$section_key][$value_key]['options']; //init empty $output = ''; //map selected indexes back to values if($selVals != ''){ $selIdxs = array_flip(wppizza_strtoarray($selVals)); $intersect = array_intersect_key($optIdxs, $selIdxs); $output = implode(', ',$intersect); } $value = $output; } //all other else{ $value = $order_formatted['sections'][$section_key][$value_key]['value']; } /* right hand side (i.e the value selected/entered) */ $row['rgt'] = $value; /***wrap in tr/td**/ if($template_type=='emails'){ $set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices $tpl[$section_key][$value_key] =''.$row['lft'].''.$row['rgt'].''.PHP_EOL; } if($template_type=='print'){ $tpl[$section_key][$value_key] =''.implode('',$row).''.PHP_EOL; } } } /**************************************** close tbody ****************************************/ $tpl[$section_key]['_tbody'] =''.PHP_EOL; /**************************************** implode for output ****************************************/ $tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /**************************************** wrap in table ****************************************/ if($template_type=='emails'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } if($template_type=='print'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } } /********************************************************** * * * itemised order vars - typically labelled "Order Details" in Wppizza -> Templates * * **********************************************************/ if($section_key == 'order'){ /*************************************** get order column data ***************************************/ $order_columns = WPPIZZA()->helpers->itemised_order_columns($order_formatted, $template_parameters, $template_type); /*************************************** ini array ***************************************/ $tpl[$section_key] = array(); /*************************************** label / legend - wrapped in ****************************************/ if(!empty($section_values['label_enabled'])){ $tpl[$section_key]['section_label'] = $order_columns['column_label']['html']; } /**************************************** itemised order rows - wrapped in ****************************************/ $tpl[$section_key]['itemised'] = $order_columns['itemised']['html']; /**************************************** implode for output ****************************************/ $tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /**************************************** wrap in ****************************************/ if($template_type=='emails'){ $tpl[$section_key]='
'.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } if($template_type=='print'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } } /********************************************************** * * * summary vars - typically labelled "Summary" in Wppizza -> Templates * * **********************************************************/ if($section_key == 'summary'){ $tpl[$section_key] = array(); /*************************************** label / legend ****************************************/ if(!empty($section_values['label_enabled'])){ $section_label = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); /***wrap in tr/th, omit style declarations on print **/ $thStyle=($template_type=='print') ? '' : ' style="'.$section_values['style']['th'].'"'; $tpl[$section_key]['section_label'] =''.PHP_EOL.''.PHP_EOL.''.PHP_EOL.''.$section_label.''.PHP_EOL.''.PHP_EOL.''.PHP_EOL.''.PHP_EOL; } /**************************************** wrap in tbody ****************************************/ $tpl[$section_key]['tbody_'] =''.PHP_EOL; /*************************************** rows ***************************************/ foreach($section_values['parameters'] as $value_key => $values){ if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ foreach($order_formatted['sections'][$section_key][$value_key] as $vKey => $vals){ /* left label, right value using filter to space evenly*/ $row = array(); $row['lft'] = $vals['label']; $row['rgt'] = $vals['value_formatted']; /***wrap in tr/td**/ if($template_type=='emails'){ $set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices $tpl[$section_key][$value_key.'_'.$vKey] =''.$row['lft'].''.$row['rgt'].''.PHP_EOL; } if($template_type=='print'){ $tpl[$section_key][$value_key.'_'.$vKey] =''.implode('',$row).''.PHP_EOL; } } } } /**************************************** close tbody ****************************************/ $tpl[$section_key]['_tbody'] =''.PHP_EOL; /**************************************** implode for output ****************************************/ $tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); $tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); /**************************************** wrap in table ****************************************/ if($template_type=='emails'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } if($template_type=='print'){ $tpl[$section_key]=''.PHP_EOL.''.$tpl[$section_key].'
'.PHP_EOL.''; } } } }} /************************************** * * if using get_skeleton_template with content set * with some hardcoded minimum padding **************************************/ if(!empty($template_contents)){ $section_key = 'contents'; $tpl[$section_key] = '
' . $template_contents . '
'.PHP_EOL.''; } /*********************************************************************** * * [add footer text in EMAIL templates after everything else] * ***********************************************************************/ if($template_type=='emails'){ $section_key = 'footer'; $tpl[$section_key] = array(); if(!empty($order_formatted['localization']['templates_footer_note'])){ $tpl[$section_key]['footer_note'] = $order_formatted['localization']['templates_footer_note']; } /* make it filterable just like all other sections */ $tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); if(count($tpl[$section_key])>0){ $tpl[$section_key]='
'.PHP_EOL.''.implode(PHP_EOL,$tpl[$section_key]).'
'.PHP_EOL.''; }else{ $tpl[$section_key]=''; } } /*********************************************************************** * * [add footer text in PRINT templates after everything else] * ***********************************************************************/ if($template_type=='print'){ $section_key = 'footer'; $tpl[$section_key] = array(); if(!empty($order_formatted['localization']['templates_footer_note_print'])){ $tpl[$section_key]['footer_note'] = $order_formatted['localization']['templates_footer_note_print']; } /* make it filterable just like all other sections */ $tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); if(count($tpl[$section_key])>0){ $tpl[$section_key]='
'.PHP_EOL.''.implode(PHP_EOL,$tpl[$section_key]).'
'.PHP_EOL.''; }else{ $tpl[$section_key]=''; } } /** filterable array sections **/ $tpl = apply_filters('wppizza_filter_template_markup', $tpl, $template_type, $order_formatted, $template_id); /** return just the sections as array before wrapping it into an html document **/ if($return_sections){ return $tpl; } /** output as string **/ $templateMarkup = implode(PHP_EOL.PHP_EOL, $tpl); /************************************************************************************************************************** * * * * [html elements wrapper to insert it into] * * * **************************************************************************************************************************/ $html=''; $html.=''.PHP_EOL; $html.=''.PHP_EOL; /* head */ $html.=''.PHP_EOL; /* title used as filename when using print / save as pdf for example. filterable let's be save and sanitize to a-zA-Z0-9\-_ for now */ $filter_args = array('order_formatted' => $order_formatted, 'tpl' => $tpl, 'template_type' => $template_type); $title_tag = __('Order','wppizza-admin'); $title_tag .= (isset($order_formatted['sections']['ordervars']['order_id']['value_formatted']) ? '-'.$order_formatted['sections']['ordervars']['order_id']['value_formatted'].'' : '' ); $title_tag = apply_filters('wppizza_filter_template_markup_title_tag', $title_tag , $filter_args); $html.=''.wppizza_validate_alpha_only($title_tag).''.PHP_EOL; /* meta */ $html.=''.PHP_EOL; if($template_type=='print'){ $html.=''; } $html.=''.PHP_EOL; /* body */ if($template_type=='emails'){ $body =''.PHP_EOL; } if($template_type=='print'){ //set to order-completed as default $bodyId = !empty($order_formatted['sections']['ordervars']['payment_status']['value_formatted']) ? 'order-'.$order_formatted['sections']['ordervars']['payment_status']['value_formatted'].'' : 'order-completed' ; $body =''.PHP_EOL; } /* make starting body tag filterable */ $html .= apply_filters('wppizza_filter_template_markup_html_body', $body, $template_type, $template_id, $order_formatted); /* content */ /*only wrap for emails*/ if($template_type=='emails'){ $html.=''.PHP_EOL; $html.=''.PHP_EOL; $html.=''.PHP_EOL; $html.=''.PHP_EOL; $html.='
'.PHP_EOL; $html.='
'.PHP_EOL; $html.=''.PHP_EOL; $html.=''.PHP_EOL; $html.=''.PHP_EOL; $html.=''.PHP_EOL; $html.=''.PHP_EOL; $html.=''.PHP_EOL; $html.='
'.PHP_EOL; } /** insert content into body **/ $html .= $templateMarkup.PHP_EOL; /** close tags **/ /*only wrap td/tr/table/center etc for emails*/ if($template_type=='emails'){ $html.='
'.PHP_EOL; $html.='
'.PHP_EOL; $html.='
'.PHP_EOL; } $html.=''.PHP_EOL; $html.=''.PHP_EOL; /* allow to filter the whole html */ $html = apply_filters('wppizza_filter_template_markup_html', $html, $template_type, $template_id, $order_formatted); return $html; } /********************************************************* * [get email/print skeleton template by id or shop/customer * inserting content between header and footer] * @since 3.9.2 * @param str. emails or print * @param mixed (id or id/shop/customer for email templates). omit to use default * @param str the content we want to use * @return array of message and message type (html/plaintext) *********************************************************/ function get_skeleton_template($type = 'emails' , $id = 0, $content = ''){ global $wppizza_options, $blog_id; /* skip if type is wrong */ if($type != 'emails' && $type != 'print' ){ return ''; } /**** distinguish between email and print templates ****/ /* get id/parameters - emails */ if($type == 'emails'){ /* get templates for this type */ $templates = get_option(WPPIZZA_SLUG.'_templates_'.$type); /* template used for shop emails */ if($id == 'shop' ){ $template_id = $wppizza_options['templates_apply']['emails']['recipients_default']['email_shop']; } /* template used for customer emails */ elseif($id == 'customer' ){ $template_id = $wppizza_options['templates_apply']['emails']['recipients_default']['email_customer']; } else{ $template_id = (int)$id; } /* if it does not exist, simply return the first one */ if(!isset($templates[$template_id])){ $template_id = 0; } /* set templates parameters */ $templates = $templates[$template_id]; } /* get id/parameters - print */ if($type == 'print'){ /* get templates for this type */ $templates = get_option(WPPIZZA_SLUG.'_templates_'.$type); /* default template */ if($id == 'default' ){ $template_id = $wppizza_options['templates_apply']['print']; }else{ $template_id = (int)$id; } /* if set id does not exist, return the default */ if(!isset($templates[$template_id])){ $template_id = 0; } /* set templates parameters */ $templates = $templates[$template_id]; } /**** end distinction between emails and print ****/ /* force disable of everything but header and footer */ $templates['sections']['ordervars']['section_enabled'] = false;//test if thsi should be disabled actually!!! $templates['sections']['customer']['section_enabled'] = false; $templates['sections']['order']['section_enabled'] = false; $templates['sections']['summary']['section_enabled'] = false; /* set order dummy parameters for header to pass on it really is only the site details blog info that gets passed on to the header as we are completely omitting any order parameters. Afer all, the point of this is to simply display a skeleton template including wrapper, and header / footer only with the main information that is normally the order details to be replaced as needed */ $dummy_order = array(); $dummy_order['blog_info'] = wppizza_get_blog_details($blog_id); $dummy_order['blog_options']['localization'] = $wppizza_options['localization']; /* skeleton param */ $skeleton_formatted = array(); $skeleton_formatted['sections'] = array(); $skeleton_formatted['sections']['site'] = WPPIZZA()->order->site_details_formatted($dummy_order, false); $skeleton_formatted['localization'] = $wppizza_options['localization']; $skeleton_formatted['blog_info'] = $dummy_order['blog_info']; $skeleton_formatted['date_format'] = wppizza_get_blog_dateformat(); /* get layout type html/plaintext */ $template_type = $templates['mail_type'] == 'wp_mail' ? 'text/plain' : 'text/html'; /* get output depending on format */ $message = ''; if($template_type == 'text/html'){ $message = WPPIZZA() -> templates_email_print -> get_template_email_html_sections_markup($skeleton_formatted, $templates, $type, $template_id, $content); }else{ $message = WPPIZZA() -> templates_email_print -> get_template_email_plaintext_sections_markup($skeleton_formatted, $templates, $type, $template_id, $content); $message = $message['markup']; } /* return message and message type (html/plaintext) */ $param = array(); $param['type'] = $template_type; $param['message'] = $message; return $param; } } ?>