| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/ |
| 3 |
/************************************************************************************************************************************** |
| 4 |
|
| 5 |
CLASS - WPPIZZA_TEMPLATES_EMAIL_PRINT |
| 6 |
|
| 7 |
|
| 8 |
**************************************************************************************************************************************/ |
| 9 |
class WPPIZZA_MARKUP_EMAIL_PRINT{ |
| 10 |
|
| 11 |
/********************************************************************************************** |
| 12 |
* |
| 13 |
* |
| 14 |
* [construct] |
| 15 |
* |
| 16 |
* |
| 17 |
*********************************************************************************************/ |
| 18 |
function __construct() { |
| 19 |
} |
| 20 |
|
| 21 |
/********************************************************************************************** |
| 22 |
* |
| 23 |
* |
| 24 |
* [public methods] |
| 25 |
* -> getters |
| 26 |
* |
| 27 |
*********************************************************************************************/ |
| 28 |
|
| 29 |
/************************************************************* |
| 30 |
* |
| 31 |
* get/set array key/values for new templates or default on install |
| 32 |
* |
| 33 |
*************************************************************/ |
| 34 |
function admin_template_get_values($tplType, $tplId, $tplValues, $arrayIdent){ |
| 35 |
|
| 36 |
/* in case we add some other template types one day */ |
| 37 |
if($tplType=='print' || $tplType=='emails'){ |
| 38 |
/* |
| 39 |
section/template values |
| 40 |
*/ |
| 41 |
$tpl_args = array( |
| 42 |
'tpl_type' => $tplType, |
| 43 |
'tpl_id' => $tplId, |
| 44 |
'tpl_values'=> $tplValues, |
| 45 |
); |
| 46 |
$tpl_values = WPPIZZA()->order->orders_formatted(array(), $tpl_args, 'template_values_'.$tplId.''); |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
return $tpl_values; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
/************************************************************* |
| 55 |
* |
| 56 |
* create admin markup of email/print templates |
| 57 |
* |
| 58 |
*************************************************************/ |
| 59 |
function admin_template($msgKey, $templateKey, $templateSetValues = false, $arrayIdent = 'templates'){ |
| 60 |
global $wppizza_options; |
| 61 |
|
| 62 |
/* |
| 63 |
get default for new template or use set values |
| 64 |
*/ |
| 65 |
$tplVals = $this->admin_template_get_values($templateKey, $msgKey, $templateSetValues, $arrayIdent); |
| 66 |
|
| 67 |
/* |
| 68 |
re-sort sections as set for display in admin |
| 69 |
*/ |
| 70 |
if(!empty($templateSetValues['sort'])){ |
| 71 |
$tpl_section_sort = array(); |
| 72 |
foreach($templateSetValues['sort'] as $section_key => $section ){ |
| 73 |
$tpl_section_sort[$section_key] = $tplVals['sections'][$section_key]; |
| 74 |
} |
| 75 |
/* now overwrite old order */ |
| 76 |
$tplVals['sections'] = $tpl_section_sort; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
/* |
| 81 |
create markup |
| 82 |
*/ |
| 83 |
$markup = ''; |
| 84 |
/** |
| 85 |
template div wrapper |
| 86 |
**/ |
| 87 |
$markup.='<!-- template type:'.$templateKey.' key:'.$msgKey.' -->'; |
| 88 |
|
| 89 |
|
| 90 |
$markup.='<div id="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-'.$msgKey.'" class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-template '.WPPIZZA_SLUG.'-'.$arrayIdent.'-'.$templateKey.' '.$tplVals['new_class'].'">'; |
| 91 |
|
| 92 |
/****************************** |
| 93 |
|
| 94 |
header/main options |
| 95 |
|
| 96 |
******************************/ |
| 97 |
$markup.='<table id="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-'.$templateKey.'-'.$msgKey.'" class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main '.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-'.$templateKey.' widefat">'; |
| 98 |
$markup.='<tbody>'; |
| 99 |
$markup.='<tr>'; |
| 100 |
|
| 101 |
/** |
| 102 |
print template , add "use" button/radio |
| 103 |
**/ |
| 104 |
if($templateKey=='print'){ |
| 105 |
$markup.='<td class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-use">'; |
| 106 |
$markup.='<label class="wppizza-dashicons wppizza-dashicons-radio">'.__('use','wppizza-admin').'<input type="radio" id="'.WPPIZZA_SLUG.'_'.$arrayIdent.'_'.$templateKey.'_print_id_'.$msgKey.'" name="'.WPPIZZA_SLUG.'[templates_apply]['.$templateKey.'][print_id]" '.checked($wppizza_options['templates_apply'][$templateKey],$msgKey,false).' value="'.$msgKey.'" /></label>'; |
| 107 |
$markup.='</td>'; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
/** |
| 112 |
title/label internal |
| 113 |
**/ |
| 114 |
$markup.='<td class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-label">'; |
| 115 |
$markup.='<label><input name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][title]" type="text" size="10" value="'.$tplVals['title'].'" /></label>'; |
| 116 |
$markup.='</td>'; |
| 117 |
|
| 118 |
|
| 119 |
/** |
| 120 |
format |
| 121 |
**/ |
| 122 |
$markup.='<td class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-mail_type">'; |
| 123 |
/*mail type */ |
| 124 |
$markup.='<label>'; |
| 125 |
$markup.='<span>'.__('format', 'wppizza-admin').'</span>'; |
| 126 |
/*set values*/ |
| 127 |
$mailFieldName=''.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][mail_type]'; |
| 128 |
$mailFieldSelected=$tplVals['mail_type']; |
| 129 |
$mailID=''.WPPIZZA_SLUG.'_'.$arrayIdent.'_mail_type_'.$templateKey.'_'.$msgKey.''; |
| 130 |
$mailClass=''.WPPIZZA_SLUG.'_'.$arrayIdent.'_mail_type'; |
| 131 |
|
| 132 |
$markup .= wppizza_admin_mail_delivery_options($mailFieldName, $mailFieldSelected, $mailID, $mailClass); |
| 133 |
|
| 134 |
$markup.='</label>'; |
| 135 |
$markup.='</td>'; |
| 136 |
|
| 137 |
|
| 138 |
/** |
| 139 |
email main recipients |
| 140 |
**/ |
| 141 |
if($templateKey=='emails'){ |
| 142 |
$markup.='<td class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-recipients">'; |
| 143 |
$markup.='<span>'.__('email recipients','wppizza-admin').':</span>'; |
| 144 |
foreach($tplVals['recipients'] as $recKey=>$recTitle){ |
| 145 |
$markup.='<label><input type="radio" id="'.WPPIZZA_SLUG.'_'.$arrayIdent.'_'.$templateKey.'_recipients_'.$recKey.'_'.$msgKey.'" name="'.WPPIZZA_SLUG.'[templates_apply]['.$templateKey.'][recipients_default]['.$recKey.']" '.checked($tplVals['recipients_default_selected'][$recKey],$msgKey,false).' value="'.$msgKey.'" />'.$recTitle.'</label>'; |
| 146 |
} |
| 147 |
$markup.=''; |
| 148 |
$markup.='</td>'; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
email additional recipients |
| 153 |
**/ |
| 154 |
if($templateKey=='emails'){ |
| 155 |
$markup.='<td class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-additional-recipients">'; |
| 156 |
$markup.='<label><span>'.__('additional recipients','wppizza-admin').'</span><input type="text" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][recipients_additional]" placeholder="'.__('comma separated emails','wppizza-admin').'" value="'.$tplVals['recipients_additional'].'" /></label>'; |
| 157 |
$markup.='</td>'; |
| 158 |
} |
| 159 |
/** |
| 160 |
email attachments |
| 161 |
**/ |
| 162 |
if($templateKey=='emails'){ |
| 163 |
$markup.='<td class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-attachments">'; |
| 164 |
$markup.='<label><span>'.__('omit attachments','wppizza-admin').'</span><input type="checkbox" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][omit_attachments]" '.checked($tplVals['omit_attachments'],true,false).' value="1" />'.__('(if any)','wppizza-admin').'</label>'; |
| 165 |
$markup.='</td>'; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
/** |
| 171 |
edit, preview, locked etc right |
| 172 |
**/ |
| 173 |
$markup.='<td class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-main-buttons">'; |
| 174 |
|
| 175 |
$icons = array(); |
| 176 |
|
| 177 |
/*icon edit*/ |
| 178 |
$icons['edit'] = "<span id='".WPPIZZA_SLUG."_".$arrayIdent."_toggle_".$templateKey."_".$msgKey."' class='".WPPIZZA_SLUG."_".$arrayIdent."_details_toggle wppizza-dashicons dashicons-edit' title='".__('edit', 'wppizza-admin')."'></span>"; |
| 179 |
|
| 180 |
/*icon code edit (show css/style)*/ |
| 181 |
$icons['css'] = '<span id="'.WPPIZZA_SLUG.'-dashicons-'.$arrayIdent.'-'.$templateKey.'-media-code-'.$msgKey.'" class="wppizza-dashicons dashicons-media-code '.$tplVals['htmlactiveclass'].'" title="'.$tplVals['htmlactivetitle'].'"></span>'; |
| 182 |
|
| 183 |
/*icon preview*/ |
| 184 |
$icons['preview'] = "<span id='".WPPIZZA_SLUG."_".$arrayIdent."_".$templateKey."_preview-".$msgKey."' class='".WPPIZZA_SLUG."_".$arrayIdent."_preview wppizza-dashicons dashicons-visibility' title='".__('preview', 'wppizza-admin')."'></span>"; |
| 185 |
|
| 186 |
/*icon delete - only for template id's >0 to always keep default, filterable in case other plugins use templates that are not used otherwise*/ |
| 187 |
$prevent_delete = apply_filters('wppizza_prevent_template_delete', array(0), $templateKey); |
| 188 |
if(!in_array($msgKey, $prevent_delete )){ |
| 189 |
$icons['delete'] = "<span id='".WPPIZZA_SLUG."_".$arrayIdent."_".$templateKey."_delete-".$msgKey."' class='".WPPIZZA_SLUG."_".$arrayIdent."_delete wppizza-dashicons dashicons-trash' title='".__('delete', 'wppizza-admin')."'></span>"; |
| 190 |
} |
| 191 |
/* |
| 192 |
allow adding / splicing icons before imploding for markup |
| 193 |
*/ |
| 194 |
$icons = apply_filters('wppizza_filter_template_icons_'.$templateKey.'', $icons, $templateKey, $msgKey, $arrayIdent); |
| 195 |
$markup .= implode('',$icons); |
| 196 |
|
| 197 |
|
| 198 |
$markup.='</td>'; |
| 199 |
$markup.='</tr>'; |
| 200 |
$markup.='</tbody>'; |
| 201 |
$markup.='</table>'; |
| 202 |
|
| 203 |
|
| 204 |
/****************************** |
| 205 |
|
| 206 |
drag drop sections |
| 207 |
|
| 208 |
******************************/ |
| 209 |
$markup.='<table id="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-sections-'.$templateKey.'-'.$msgKey.'" class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-sections '.WPPIZZA_SLUG.'-'.$arrayIdent.'-sections-'.$templateKey.' widefat">'; |
| 210 |
$markup.='<tbody>'; |
| 211 |
$markup.='<tr class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts">'; |
| 212 |
/* |
| 213 |
* iterate through sections - in order of sort |
| 214 |
*/ |
| 215 |
foreach($tplVals['sections'] as $section_key=>$section){ |
| 216 |
|
| 217 |
$markup.='<td class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-'.$section_key.' '.WPPIZZA_SLUG.'-'.$arrayIdent.'-'.$templateKey.'-section-'.$section_key.'">'; |
| 218 |
|
| 219 |
/* |
| 220 |
section on off and sort icon |
| 221 |
*/ |
| 222 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-part-enable '.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-'.$section_key.'-part-enable">'; |
| 223 |
$markup.='<span>'; |
| 224 |
$markup.='<label class="button">'; |
| 225 |
$markup.='<input id="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-part-'.$msgKey.'-'.$section_key.'" class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-part" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][section_enabled]" type="checkbox" value="1" '.checked(!empty($section['section_enabled']),true,false).' />';//'.$section_key.' |
| 226 |
$markup.= $section['labels']['label'] ; |
| 227 |
$markup.='</label>'; |
| 228 |
$markup.='</span>'; |
| 229 |
|
| 230 |
$markup.='<span class="wppizza-dashicons-leftright dashicons-leftright wppizza-'.$arrayIdent.'-sort-part" title="'.__('drag and drop to sort','wppizza-admin').'">'; |
| 231 |
$markup.='<input name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sort]['.$section_key.']" type="hidden" value="1" />';//'.$section_key.' |
| 232 |
$markup.='</span>'; |
| 233 |
|
| 234 |
$markup.='</div>'; |
| 235 |
|
| 236 |
|
| 237 |
/* |
| 238 |
label enable wrap |
| 239 |
*/ |
| 240 |
|
| 241 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-part-header '.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-'.$section_key.'-part-header">'; |
| 242 |
/* |
| 243 |
section header label on/off |
| 244 |
*/ |
| 245 |
$markup.='<label>'; |
| 246 |
$markup.='<input name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][label_enabled]" type="checkbox" '.checked(!empty($section['label_enabled']),true,false).' value="1" />'; |
| 247 |
/*label for order is made up of 3 labels*/ |
| 248 |
if($section_key=='order'){ |
| 249 |
$orderlbl=implode(' | ',$section['labels']['parameters']); |
| 250 |
/* Translators: 1: Section titles such as 'Site Details', 'Overview', 'Customer Details'... */ |
| 251 |
$markup.=''.sprintf( __( 'Show "%1$s"', 'wppizza-admin'), $orderlbl ).''; |
| 252 |
}else{ |
| 253 |
/* Translators: 1: Section labels such as 'Site Details', 'Overview', 'Customer Details'... */ |
| 254 |
$markup.=''.sprintf( __( 'Show "%1$s" label', 'wppizza-admin'), $section['labels']['label'] ).''; |
| 255 |
} |
| 256 |
$markup.='</label>'; |
| 257 |
|
| 258 |
$markup.='</div>'; |
| 259 |
|
| 260 |
/* |
| 261 |
drag/drop on/off variables |
| 262 |
*/ |
| 263 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-parts '.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-parts-'.$section_key.' '.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-parts-'.$section_key.'-'.$msgKey.'">'; |
| 264 |
|
| 265 |
foreach($section['parameters'] as $section_value_key=>$section_value){ |
| 266 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-sort-var-'.$section_value_key.' '.WPPIZZA_SLUG.'-'.$arrayIdent.'-'.$templateKey.'-sort-var-'.$section_value_key.'">'; |
| 267 |
|
| 268 |
/* |
| 269 |
drag/drop icon and hidden input to save selected order |
| 270 |
regardless of whether checkbox was selected |
| 271 |
*/ |
| 272 |
$markup.='<span class="'.WPPIZZA_SLUG.'-dashicons-small dashicons-editor-ol '.WPPIZZA_SLUG.'-'.$arrayIdent.'-sort-var" title="'.__('drag and drop to sort','wppizza-admin').'">'; |
| 273 |
$markup.='<input id="'.WPPIZZA_SLUG.'-values-order.'.$templateKey.'-'.$msgKey.'.'.$section_key.'.'.$section_value_key.'" class="'.WPPIZZA_SLUG.'-values-order" class="'.WPPIZZA_SLUG.'-values-order" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sort]['.$section_key.']['.$section_value_key.']" type="hidden" value="1" />';//'.$section_value_key.' |
| 274 |
$markup.='</span>'; |
| 275 |
|
| 276 |
/* |
| 277 |
checkbox with label |
| 278 |
*/ |
| 279 |
$markup.='<label title="'.__('show in template','wppizza-admin').'">'; |
| 280 |
$markup.='<input id="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-input-var-'.$msgKey.'-'.$section_key.'-'.$section_value_key.'" class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-input-var" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][parameters]['.$section_value_key.'][enabled]" type="checkbox" value="1" '.checked(!empty($section_value['enabled']),true,false).' />';//'.$section_value_key.' |
| 281 |
$markup.= $section_value['label'] ; |
| 282 |
$markup.='</label>'; |
| 283 |
|
| 284 |
$markup.='</div>'; |
| 285 |
} |
| 286 |
$markup.='</div>'; |
| 287 |
$markup.='</td>'; |
| 288 |
} |
| 289 |
$markup.='</tr>'; |
| 290 |
$markup.='</tbody>'; |
| 291 |
$markup.='</table>'; |
| 292 |
|
| 293 |
/****************************** |
| 294 |
|
| 295 |
global styles |
| 296 |
|
| 297 |
******************************/ |
| 298 |
$markup.='<table id="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles-'.$templateKey.'-'.$msgKey.'" class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles '.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles-'.$templateKey.' widefat">'; |
| 299 |
$markup.='<tbody>'; |
| 300 |
$markup.='<tr>'; |
| 301 |
$markup.='<td>'; |
| 302 |
|
| 303 |
$markup.='<label class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles-body '.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles-body-'.$templateKey.'">'; |
| 304 |
if($templateKey=='emails'){ |
| 305 |
$markup.=''.__('Body - element style','wppizza-admin').''; |
| 306 |
} |
| 307 |
if($templateKey=='print'){ |
| 308 |
$markup.=''.__('Print Order CSS','wppizza-admin').''; |
| 309 |
} |
| 310 |
$markup.='<textarea name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][global_styles][body]">'.$tplVals['global_styles']['body'].'</textarea>'; |
| 311 |
$markup.='</label>'; |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
if($templateKey=='emails'){ |
| 316 |
|
| 317 |
$markup.='<label class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles-wrapper '.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles-wrapper-'.$templateKey.'">'; |
| 318 |
$markup.=''.__('Wrapper - element style','wppizza-admin').''; |
| 319 |
$markup.='<textarea name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][global_styles][wrapper]">'.$tplVals['global_styles']['wrapper'].'</textarea>'; |
| 320 |
$markup.='</label>'; |
| 321 |
|
| 322 |
$markup.='<label class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles-table '.WPPIZZA_SLUG.'-'.$arrayIdent.'-global-styles-table-'.$templateKey.'">'; |
| 323 |
$markup.=''.__('Main Table - element style','wppizza-admin').''; |
| 324 |
$markup.='<textarea name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][global_styles][table]">'.$tplVals['global_styles']['table'].'</textarea>'; |
| 325 |
$markup.='</label>'; |
| 326 |
} |
| 327 |
|
| 328 |
$markup.='</td>'; |
| 329 |
$markup.='</tr>'; |
| 330 |
$markup.='</tbody>'; |
| 331 |
$markup.='</table>'; |
| 332 |
|
| 333 |
|
| 334 |
/****************************** |
| 335 |
|
| 336 |
sections styles - emails only |
| 337 |
|
| 338 |
******************************/ |
| 339 |
if($templateKey=='emails'){ |
| 340 |
$markup.='<table id="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-sections-styles-'.$templateKey.'-'.$msgKey.'" class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-sections-styles '.WPPIZZA_SLUG.'-'.$arrayIdent.'-sections-styles-'.$templateKey.' widefat">'; |
| 341 |
$markup.='<tbody>'; |
| 342 |
$markup.='<tr>'; |
| 343 |
/* |
| 344 |
* iterate through sections |
| 345 |
*/ |
| 346 |
foreach($tplVals['sections'] as $section_key=>$section){ |
| 347 |
$markup.='<td>'; |
| 348 |
|
| 349 |
/* |
| 350 |
label |
| 351 |
*/ |
| 352 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-styles-label">'; |
| 353 |
$markup.=''.__('Section Styles','wppizza-admin').' - '.$section['labels']['label'].''; |
| 354 |
$markup.='</div>'; |
| 355 |
|
| 356 |
/* |
| 357 |
style table |
| 358 |
*/ |
| 359 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-styles-table">'; |
| 360 |
$markup.='<label>'.__('Table','wppizza-admin').'</label>'; |
| 361 |
$markup.='<textarea name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style][table]">'.$section['style']['table'].'</textarea>'; |
| 362 |
$markup.='</div>'; |
| 363 |
|
| 364 |
/* |
| 365 |
style header |
| 366 |
*/ |
| 367 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-styles-header">'; |
| 368 |
$markup.='<label>'.__('Headers / Labels','wppizza-admin').'</label>'; |
| 369 |
$markup.='<textarea name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style][th]">'.$section['style']['th'].'</textarea>'; |
| 370 |
$markup.='</div>'; |
| 371 |
|
| 372 |
/* |
| 373 |
style columns all |
| 374 |
*/ |
| 375 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-styles-columns '.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-styles-columns-'.$section_key.'">'; |
| 376 |
|
| 377 |
/**labels**/ |
| 378 |
if($section_key=='order'){ |
| 379 |
$markup.='<label>'.__('Order Details','wppizza-admin').'</label>'; |
| 380 |
}else{ |
| 381 |
$markup.='<label>'.__('Columns','wppizza-admin').'</label>'; |
| 382 |
} |
| 383 |
|
| 384 |
/**site vars have one td only**/ |
| 385 |
if($section_key=='site'){ |
| 386 |
|
| 387 |
$markup.=''.__('Column All','wppizza-admin').'<br />'; |
| 388 |
$markup.='<textarea class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style '.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style-ctr" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style][td-ctr]">'.$section['style']['td-ctr'].'</textarea>'; |
| 389 |
|
| 390 |
}else{ |
| 391 |
|
| 392 |
$markup.='<div>'; |
| 393 |
$markup.=''.__('Left Column All','wppizza-admin').'<br />'; |
| 394 |
$markup.='<textarea class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style '.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style-lft" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style][td-lft]">'.$section['style']['td-lft'].'</textarea>'; |
| 395 |
$markup.='</div>'; |
| 396 |
|
| 397 |
/*order vars have 3 columns*/ |
| 398 |
if($section_key=='order'){ |
| 399 |
$markup.='<div>'; |
| 400 |
$markup.=''.__('Center Column All','wppizza-admin').'<br />'; |
| 401 |
$markup.='<textarea class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style '.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style-ctr" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style][td-ctr]">'.$section['style']['td-ctr'].'</textarea>'; |
| 402 |
$markup.='</div>'; |
| 403 |
} |
| 404 |
|
| 405 |
$markup.='<div>'; |
| 406 |
$markup.=''.__('Right Column All','wppizza-admin').'<br />'; |
| 407 |
$markup.='<textarea class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style '.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style-rgt" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style][td-rgt]">'.$section['style']['td-rgt'].'</textarea>'; |
| 408 |
$markup.='</div>'; |
| 409 |
|
| 410 |
} |
| 411 |
|
| 412 |
$markup.='</div>'; |
| 413 |
|
| 414 |
/* |
| 415 |
style rows |
| 416 |
*/ |
| 417 |
$markup.='<div class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-styles-rows '.WPPIZZA_SLUG.'-'.$arrayIdent.'-section-styles-rows-'.$section_key.'">'; |
| 418 |
|
| 419 |
/*skip for order items*/ |
| 420 |
if($section_key != 'order'){ |
| 421 |
|
| 422 |
$markup.='<label>'.__('Details','wppizza-admin').'</label>'; |
| 423 |
|
| 424 |
foreach($section['parameters'] as $section_value_key=>$section_value){ |
| 425 |
$markup.='<div>'; |
| 426 |
$markup.= $section_value['label'].'<br />'; |
| 427 |
$markup.='<textarea name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style]['.$section_value_key.'-tdall]" >'.$section['style'][''.$section_value_key.'-tdall'].'</textarea>';//$tplVals['style'][$section_key][''.$section_value_key.'-tdall']//'.$section_value[''.$section_key.'-tdall'].' |
| 428 |
$markup.='</div>'; |
| 429 |
} |
| 430 |
|
| 431 |
} |
| 432 |
|
| 433 |
/* add styles for blogname and categories if displayed */ |
| 434 |
if($section_key=='order'){ |
| 435 |
|
| 436 |
$markup.='<label>'.__('Category / Blogname (if enabled)','wppizza-admin').'</label>'; |
| 437 |
|
| 438 |
$markup.='<div>'; |
| 439 |
$markup.=''.__('Blogname','wppizza-admin').'<br />'; |
| 440 |
$markup.='<textarea class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style '.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style-blogname" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style][td-blogname]">'.$section['style']['td-blogname'].'</textarea>'; |
| 441 |
$markup.='</div>'; |
| 442 |
|
| 443 |
$markup.='<div>'; |
| 444 |
$markup.=''.__('Category','wppizza-admin').'<br />'; |
| 445 |
$markup.='<textarea class="'.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style '.WPPIZZA_SLUG.'-'.$arrayIdent.'-parts-style-catname" name="'.WPPIZZA_SLUG.'['.$arrayIdent.']['.$templateKey.']['.$msgKey.'][sections]['.$section_key.'][style][td-catname]">'.$section['style']['td-catname'].'</textarea>'; |
| 446 |
$markup.='</div>'; |
| 447 |
} |
| 448 |
|
| 449 |
$markup.='</div>'; |
| 450 |
|
| 451 |
$markup.='</td>'; |
| 452 |
} |
| 453 |
$markup.='</tr>'; |
| 454 |
$markup.='</tbody>'; |
| 455 |
$markup.='</table>'; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
$markup.='</div>'; |
| 460 |
|
| 461 |
return $markup; |
| 462 |
} |
| 463 |
|
| 464 |
/*************************************************************************************************************************************************************************************************************************** |
| 465 |
* |
| 466 |
* |
| 467 |
* |
| 468 |
* plaintext template parts |
| 469 |
* |
| 470 |
* |
| 471 |
* |
| 472 |
****************************************************************************************************************************************************************************************************************************/ |
| 473 |
function get_template_email_plaintext_sections_markup($order_formatted, $template_parameters, $template_type, $template_id = '', $template_contents = '' , $return_sections = false){ |
| 474 |
|
| 475 |
$tpl = array(); |
| 476 |
|
| 477 |
/* |
| 478 |
remove some potential notices for empty parameters |
| 479 |
*/ |
| 480 |
if(empty($order_formatted['sections'])){ |
| 481 |
$order_formatted['sections'] = array() ; |
| 482 |
} |
| 483 |
|
| 484 |
/** |
| 485 |
loop through sections in the order they were set |
| 486 |
when saving the drag drop template |
| 487 |
**/ |
| 488 |
|
| 489 |
if(isset($template_parameters['sections'])){ |
| 490 |
foreach($template_parameters['sections'] as $section_key => $section_values){ |
| 491 |
if(!empty($section_values['section_enabled'])){ |
| 492 |
|
| 493 |
|
| 494 |
/* |
| 495 |
allow filtering to override whats saved in templates |
| 496 |
creating an empty array if it does not exist to avoid php warnings |
| 497 |
*/ |
| 498 |
if(!isset($section_values['parameters'])){ |
| 499 |
$section_values['parameters'] = array(); |
| 500 |
} |
| 501 |
$section_values['parameters'] = apply_filters('wppizza_filter_template_section_parameters', $section_values['parameters'], $section_key, $template_parameters, $template_type); |
| 502 |
|
| 503 |
|
| 504 |
/************************************** |
| 505 |
* |
| 506 |
* |
| 507 |
* site vars |
| 508 |
* |
| 509 |
* |
| 510 |
**************************************/ |
| 511 |
if($section_key == 'site'){ |
| 512 |
$tpl[$section_key] = array(); |
| 513 |
|
| 514 |
/*************************************** |
| 515 |
label / legend |
| 516 |
****************************************/ |
| 517 |
if(!empty($section_values['label_enabled'])){ |
| 518 |
$tpl[$section_key]['section_label'] = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); |
| 519 |
/* filter for even spacing **/ |
| 520 |
$tpl[$section_key]['section_label'] = apply_filters('wppizza_filter_plaintext_line', $tpl[$section_key]['section_label'], ' '); |
| 521 |
} |
| 522 |
|
| 523 |
/*************************************** |
| 524 |
rows |
| 525 |
***************************************/ |
| 526 |
foreach($section_values['parameters'] as $value_key => $values){ |
| 527 |
|
| 528 |
if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ |
| 529 |
|
| 530 |
/* centered, without labels */ |
| 531 |
$row = array(); |
| 532 |
$row['ctr'] = $order_formatted['sections'][$section_key][$value_key]['value_formatted']; |
| 533 |
|
| 534 |
/** line **/ |
| 535 |
$tpl[$section_key][$value_key] = apply_filters('wppizza_filter_plaintext_line', $row, ' '); |
| 536 |
|
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
/**************************************** |
| 541 |
implode label and details for output |
| 542 |
****************************************/ |
| 543 |
$tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 544 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 545 |
/* allow filtering of whole section string (maybe using regexes) */ |
| 546 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
/************************************** |
| 551 |
* |
| 552 |
* |
| 553 |
* general order parameters |
| 554 |
* |
| 555 |
* |
| 556 |
**************************************/ |
| 557 |
if($section_key == 'ordervars'){ |
| 558 |
|
| 559 |
$tpl[$section_key] = array(); |
| 560 |
|
| 561 |
/*************************************** |
| 562 |
label / legend |
| 563 |
****************************************/ |
| 564 |
if(!empty($section_values['label_enabled'])){ |
| 565 |
|
| 566 |
$tpl[$section_key]['section_label'] = trim($order_formatted['localization']['templates_label_'.$section_key.'']); |
| 567 |
/* filter for even spacing **/ |
| 568 |
$tpl[$section_key]['section_label'] = apply_filters('wppizza_filter_plaintext_line', $tpl[$section_key]['section_label'], ' '); |
| 569 |
} |
| 570 |
|
| 571 |
/*************************************** |
| 572 |
rows |
| 573 |
***************************************/ |
| 574 |
foreach($section_values['parameters'] as $value_key => $values){ |
| 575 |
|
| 576 |
if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ |
| 577 |
|
| 578 |
/* left label, right value using filter to space evenly*/ |
| 579 |
$row = array(); |
| 580 |
$row['lft'] = $order_formatted['sections'][$section_key][$value_key]['label']; |
| 581 |
$row['rgt'] = $order_formatted['sections'][$section_key][$value_key]['value_formatted']; |
| 582 |
|
| 583 |
/** line **/ |
| 584 |
$tpl[$section_key][$value_key] = apply_filters('wppizza_filter_plaintext_line', $row, ' '); |
| 585 |
|
| 586 |
} |
| 587 |
|
| 588 |
} |
| 589 |
|
| 590 |
/** implode for output */ |
| 591 |
$tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 592 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 593 |
/* allow filtering of whole section string (maybe using regexes) */ |
| 594 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
/************************************** |
| 599 |
* |
| 600 |
* |
| 601 |
* customer vars |
| 602 |
* |
| 603 |
* |
| 604 |
**************************************/ |
| 605 |
if($section_key == 'customer'){ |
| 606 |
$tpl[$section_key] = array(); |
| 607 |
|
| 608 |
|
| 609 |
/*************************************** |
| 610 |
label / legend |
| 611 |
****************************************/ |
| 612 |
if(!empty($section_values['label_enabled'])){ |
| 613 |
$tpl[$section_key]['section_label'] = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); |
| 614 |
/* filter for even spacing **/ |
| 615 |
$tpl[$section_key]['section_label'] = apply_filters('wppizza_filter_plaintext_line', $tpl[$section_key]['section_label'], ' '); |
| 616 |
} |
| 617 |
|
| 618 |
/*************************************** |
| 619 |
rows |
| 620 |
***************************************/ |
| 621 |
foreach($section_values['parameters'] as $value_key => $values){ |
| 622 |
|
| 623 |
if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ |
| 624 |
|
| 625 |
/* |
| 626 |
if omit_if_optional is set, |
| 627 |
omit formfield if field is not required to be filled in |
| 628 |
the 'required_attribute' willalready be set (or not as the case may be) |
| 629 |
depending on if it's pickup or delivery and required or not for those |
| 630 |
*/ |
| 631 |
if(!empty($order_formatted['sections'][$section_key][$value_key]['omit_if_optional']) && empty($order_formatted['sections'][$section_key][$value_key]['required_attribute'])){ |
| 632 |
continue; |
| 633 |
} |
| 634 |
|
| 635 |
/* |
| 636 |
left label, right value using filter to space evenly |
| 637 |
*/ |
| 638 |
$row = array(); |
| 639 |
|
| 640 |
/* |
| 641 |
label |
| 642 |
*/ |
| 643 |
$row['lft'] = $order_formatted['sections'][$section_key][$value_key]['label']; |
| 644 |
|
| 645 |
// value |
| 646 |
/* |
| 647 |
radios and dropdowns need to be mapped back from numerical index to value |
| 648 |
*/ |
| 649 |
//selects/dropdowns |
| 650 |
if($order_formatted['sections'][$section_key][$value_key]['type'] == 'select'){ |
| 651 |
//for backward compatibility, if using test as key as opposed to numeric indexes , decode entities |
| 652 |
$selIdx = wppizza_decode_entities($order_formatted['sections'][$section_key][$value_key]['value']); |
| 653 |
$value = isset($order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]['label']) ? $order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]['label'] : '' ; |
| 654 |
} |
| 655 |
//radios |
| 656 |
elseif($order_formatted['sections'][$section_key][$value_key]['type'] == 'radio'){ |
| 657 |
$selIdx = $order_formatted['sections'][$section_key][$value_key]['value']; |
| 658 |
$value = isset($order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]) ? $order_formatted['sections'][$section_key][$value_key]['options'][$selIdx] : '' ; |
| 659 |
} |
| 660 |
//multicheckboxes |
| 661 |
elseif($order_formatted['sections'][$section_key][$value_key]['type'] == 'multicheckbox'){ |
| 662 |
//selected indexes (comma seperated string) |
| 663 |
$selVals = $order_formatted['sections'][$section_key][$value_key]['value']; |
| 664 |
//available indexes (array) |
| 665 |
$optIdxs = $order_formatted['sections'][$section_key][$value_key]['options']; |
| 666 |
//init empty |
| 667 |
$output = ''; |
| 668 |
//map selected indexes back to values |
| 669 |
if($selVals != ''){ |
| 670 |
$selIdxs = array_flip(wppizza_strtoarray($selVals)); |
| 671 |
$intersect = array_intersect_key($optIdxs, $selIdxs); |
| 672 |
$output = implode(', ',$intersect); |
| 673 |
} |
| 674 |
$value = $output; |
| 675 |
} |
| 676 |
//all other |
| 677 |
else{ |
| 678 |
$value = $order_formatted['sections'][$section_key][$value_key]['value']; |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
/* |
| 683 |
right hand side (i.e the value selected/entered) |
| 684 |
*/ |
| 685 |
$row['rgt'] = $value; |
| 686 |
|
| 687 |
/** line **/ |
| 688 |
$tpl[$section_key][$value_key] = apply_filters('wppizza_filter_plaintext_line', $row, ' '); |
| 689 |
|
| 690 |
} |
| 691 |
|
| 692 |
} |
| 693 |
|
| 694 |
/** implode for output */ |
| 695 |
$tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 696 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 697 |
/* allow filtering of whole section string (maybe using regexes) */ |
| 698 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
/************************************** |
| 703 |
* |
| 704 |
* |
| 705 |
* itemised order vars |
| 706 |
* |
| 707 |
* |
| 708 |
**************************************/ |
| 709 |
if($section_key == 'order'){ |
| 710 |
|
| 711 |
/*************************************** |
| 712 |
get order column data |
| 713 |
***************************************/ |
| 714 |
$order_columns = WPPIZZA()->helpers->itemised_order_columns($order_formatted, $template_parameters, $template_type); |
| 715 |
|
| 716 |
/*************************************** |
| 717 |
ini array |
| 718 |
***************************************/ |
| 719 |
$tpl[$section_key] = array(); |
| 720 |
|
| 721 |
/*************************************** |
| 722 |
label / legend - spaced by "-" |
| 723 |
****************************************/ |
| 724 |
if(!empty($section_values['label_enabled'])){ |
| 725 |
$tpl[$section_key]['section_label'] = $order_columns['column_label']['plaintext']; |
| 726 |
} |
| 727 |
|
| 728 |
/**************************************** |
| 729 |
itemised order rows |
| 730 |
****************************************/ |
| 731 |
$tpl[$section_key]['itemised'] = $order_columns['itemised']['plaintext']; |
| 732 |
|
| 733 |
|
| 734 |
/**************************************** |
| 735 |
implode label and details for output |
| 736 |
****************************************/ |
| 737 |
$tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 738 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 739 |
/* allow filtering of whole section string (maybe using regexes) */ |
| 740 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
/************************************** |
| 746 |
* |
| 747 |
* |
| 748 |
* summary vars |
| 749 |
* - todo template vars need to match |
| 750 |
* |
| 751 |
**************************************/ |
| 752 |
if($section_key == 'summary'){ |
| 753 |
$tpl[$section_key] = array(); |
| 754 |
|
| 755 |
/*************************************** |
| 756 |
label / legend |
| 757 |
****************************************/ |
| 758 |
if(!empty($section_values['label_enabled'])){ |
| 759 |
$tpl[$section_key]['section_label'] = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); |
| 760 |
/* filter for even spacing **/ |
| 761 |
$tpl[$section_key]['section_label'] = apply_filters('wppizza_filter_plaintext_line', $tpl[$section_key]['section_label'], ' '); |
| 762 |
} |
| 763 |
|
| 764 |
/*************************************** |
| 765 |
rows |
| 766 |
***************************************/ |
| 767 |
foreach($section_values['parameters'] as $value_key => $values){ |
| 768 |
|
| 769 |
if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ |
| 770 |
foreach($order_formatted['sections'][$section_key][$value_key] as $vKey => $vals){ |
| 771 |
/* left label, right value using filter to space evenly*/ |
| 772 |
$row = array(); |
| 773 |
$row['lft'] = $vals['label']; |
| 774 |
$row['rgt'] = $vals['value_formatted']; |
| 775 |
|
| 776 |
/** line **/ |
| 777 |
$tpl[$section_key][$value_key.'_'.$vKey] = apply_filters('wppizza_filter_plaintext_line', $row, ' '); |
| 778 |
} |
| 779 |
} |
| 780 |
|
| 781 |
} |
| 782 |
|
| 783 |
/** implode for output */ |
| 784 |
$tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 785 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 786 |
/* allow filtering of whole section string (maybe using regexes) */ |
| 787 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); |
| 788 |
} |
| 789 |
}}} |
| 790 |
|
| 791 |
/************************************** |
| 792 |
* |
| 793 |
* if using get_skeleton_template with content set |
| 794 |
* adding hardcoded divider |
| 795 |
**************************************/ |
| 796 |
if(!empty($template_contents)){ |
| 797 |
|
| 798 |
$section_key = 'contents'; |
| 799 |
$tpl[$section_key.'_divider'] = apply_filters('wppizza_filter_plaintext_line', '', '='); |
| 800 |
$tpl[$section_key] = apply_filters('wppizza_filter_plaintext_line', $template_contents, ' ', true); |
| 801 |
|
| 802 |
} |
| 803 |
/************************************** |
| 804 |
* |
| 805 |
* |
| 806 |
* add footer after everything else |
| 807 |
* emails only |
| 808 |
* |
| 809 |
**************************************/ |
| 810 |
if($template_type=='emails'){ |
| 811 |
$section_key = 'footer'; |
| 812 |
$tpl[$section_key] = array(); |
| 813 |
/** add centered note after **/ |
| 814 |
$tpl[$section_key]['divider'] = apply_filters('wppizza_filter_plaintext_line', '', '='); |
| 815 |
if(!empty($order_formatted['localization']['templates_footer_note'])){ |
| 816 |
$tpl[$section_key]['footer_note'] = apply_filters('wppizza_filter_plaintext_line', $order_formatted['localization']['templates_footer_note'], ' ', true); |
| 817 |
} |
| 818 |
/** implode for output */ |
| 819 |
$tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 820 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 821 |
/* allow filtering of whole section string (maybe using regexes) */ |
| 822 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); |
| 823 |
} |
| 824 |
|
| 825 |
/************************************** |
| 826 |
* |
| 827 |
* |
| 828 |
* add footer after everything else |
| 829 |
* print only |
| 830 |
* |
| 831 |
**************************************/ |
| 832 |
if($template_type=='print'){ |
| 833 |
$section_key = 'footer'; |
| 834 |
$tpl[$section_key] = array(); |
| 835 |
/** add centered note after **/ |
| 836 |
$tpl[$section_key]['divider'] = apply_filters('wppizza_filter_plaintext_line', '', '='); |
| 837 |
if(!empty($order_formatted['localization']['templates_footer_note_print'])){ |
| 838 |
$tpl[$section_key]['footer_note'] = apply_filters('wppizza_filter_plaintext_line', $order_formatted['localization']['templates_footer_note_print'], ' ', true); |
| 839 |
} |
| 840 |
/** implode for output */ |
| 841 |
$tpl[$section_key] = apply_filters('wppizza_filter_plaintext_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 842 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 843 |
/* allow filtering of whole section string (maybe using regexes) */ |
| 844 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_markup_plaintext_'.$section_key.'', $tpl[$section_key], $template_type); |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
/* |
| 850 |
allow filtering of each section (maybe using regexes - though using above filters in each section would probably be a better idea) |
| 851 |
*/ |
| 852 |
$tpl = apply_filters('wppizza_filter_template_markup_plaintext', $tpl, $template_type, $template_id, $order_formatted); |
| 853 |
|
| 854 |
/** |
| 855 |
return just the sections as array |
| 856 |
before wrapping it into an html document |
| 857 |
**/ |
| 858 |
if($return_sections){ |
| 859 |
return $tpl; |
| 860 |
} |
| 861 |
|
| 862 |
/** |
| 863 |
output as string |
| 864 |
**/ |
| 865 |
$tpl['markup'] = implode(PHP_EOL.PHP_EOL,$tpl); |
| 866 |
|
| 867 |
return $tpl; |
| 868 |
} |
| 869 |
/********************************************************************************************************************************************************************************************************************************** |
| 870 |
* |
| 871 |
* |
| 872 |
* |
| 873 |
* html templates |
| 874 |
* |
| 875 |
* |
| 876 |
* |
| 877 |
***********************************************************************************************************************************************************************************************************************************/ |
| 878 |
function get_template_email_html_sections_markup($order_formatted, $template_parameters, $template_type, $template_id, $template_contents = '', $return_sections = false){ |
| 879 |
|
| 880 |
$tpl = array(); |
| 881 |
|
| 882 |
/* |
| 883 |
remove some potential notices for empty parameters |
| 884 |
*/ |
| 885 |
if(empty($order_formatted['sections'])){$order_formatted['sections'] = array() ;} |
| 886 |
|
| 887 |
/** |
| 888 |
loop through sections in the order they were set |
| 889 |
when saving the drag drop template |
| 890 |
**/ |
| 891 |
if(isset($template_parameters['sections'])){ |
| 892 |
foreach($template_parameters['sections'] as $section_key => $section_values){ |
| 893 |
|
| 894 |
|
| 895 |
/* |
| 896 |
allow filtering to override/add what's saved in templates |
| 897 |
creating an empty array if it does not exist to avoid php warnings |
| 898 |
*/ |
| 899 |
if(!isset($section_values['parameters'])){ |
| 900 |
$section_values['parameters'] = array(); |
| 901 |
} |
| 902 |
$section_values['parameters'] = apply_filters('wppizza_filter_template_section_parameters', $section_values['parameters'], $section_key, $template_parameters, $template_type); |
| 903 |
|
| 904 |
/* |
| 905 |
allow filtering of html style to override/add what's saved in templates |
| 906 |
hook updated for 3.1.3 to only apply to this section |
| 907 |
adding template id and order_formatted[sections] to pass on all order parameters |
| 908 |
*/ |
| 909 |
$section_values['style'] = empty($section_values['style']) ? array() : $section_values['style']; |
| 910 |
$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']); |
| 911 |
|
| 912 |
if(!empty($section_values['section_enabled'])){ |
| 913 |
|
| 914 |
/********************************************************** |
| 915 |
* |
| 916 |
* |
| 917 |
* site vars - typically labelled "Site Details" in Wppizza -> Templates |
| 918 |
* |
| 919 |
* |
| 920 |
**********************************************************/ |
| 921 |
if($section_key == 'site'){ |
| 922 |
$tpl[$section_key] = array(); |
| 923 |
|
| 924 |
/*************************************** |
| 925 |
label / legend |
| 926 |
****************************************/ |
| 927 |
if(!empty($section_values['label_enabled'])){ |
| 928 |
|
| 929 |
$section_label = trim($order_formatted['localization']['templates_label_'.$section_key.'']); |
| 930 |
|
| 931 |
/***wrap in tr/th, omit style declarations on print **/ |
| 932 |
$thStyle=($template_type=='print') ? '' : ' style="'.$section_values['style']['th'].'"'; |
| 933 |
$tpl[$section_key]['section_label'] ='<thead>'.PHP_EOL.'<tr>'.PHP_EOL.'<th '.$thStyle.'>'.PHP_EOL.''.$section_label.''.PHP_EOL.'</th>'.PHP_EOL.'</tr>'.PHP_EOL.'</thead>'.PHP_EOL; |
| 934 |
|
| 935 |
} |
| 936 |
/**************************************** |
| 937 |
wrap in tbody |
| 938 |
****************************************/ |
| 939 |
$tpl[$section_key]['tbody_'] ='<tbody>'.PHP_EOL; |
| 940 |
|
| 941 |
/*************************************** |
| 942 |
rows |
| 943 |
***************************************/ |
| 944 |
foreach($section_values['parameters'] as $value_key => $values){ |
| 945 |
|
| 946 |
if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ |
| 947 |
/* centered, without labels */ |
| 948 |
$row = array(); |
| 949 |
$row['ctr'] = $order_formatted['sections'][$section_key][$value_key]['value_formatted']; |
| 950 |
|
| 951 |
/***wrap in tr/td**/ |
| 952 |
if($template_type=='emails'){ |
| 953 |
$set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices |
| 954 |
$tpl[$section_key][$value_key] ='<tr><td style="'.$section_values['style']['td-ctr'].';'.$set_email_td_all.'">'.$row['ctr'].'</td></tr>'.PHP_EOL; |
| 955 |
} |
| 956 |
if($template_type=='print'){ |
| 957 |
$tpl[$section_key][$value_key] ='<tr id="'.$value_key.'"><td>'.$row['ctr'].'</td></tr>'.PHP_EOL; |
| 958 |
} |
| 959 |
|
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
/**************************************** |
| 964 |
close tbody |
| 965 |
****************************************/ |
| 966 |
$tpl[$section_key]['_tbody'] ='</tbody>'.PHP_EOL; |
| 967 |
|
| 968 |
/**************************************** |
| 969 |
implode for output |
| 970 |
****************************************/ |
| 971 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 972 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 973 |
|
| 974 |
/**************************************** |
| 975 |
wrap in table |
| 976 |
****************************************/ |
| 977 |
if($template_type=='emails'){ |
| 978 |
$tpl[$section_key]='<table id="'.$section_key.'" style="position:relative;width:100%;'.$section_values['style']['table'].'">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 979 |
} |
| 980 |
if($template_type=='print'){ |
| 981 |
$tpl[$section_key]='<table id="header">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
/********************************************************** |
| 986 |
* |
| 987 |
* |
| 988 |
* general order parameters - typically labelled "Overview" in Wppizza -> Templates |
| 989 |
* |
| 990 |
* |
| 991 |
**********************************************************/ |
| 992 |
if($section_key == 'ordervars'){ |
| 993 |
|
| 994 |
$tpl[$section_key] = array(); |
| 995 |
|
| 996 |
/*************************************** |
| 997 |
label / legend |
| 998 |
****************************************/ |
| 999 |
if(!empty($section_values['label_enabled'])){ |
| 1000 |
|
| 1001 |
$section_label = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); |
| 1002 |
|
| 1003 |
/***wrap in tr/th, omit style declarations on print **/ |
| 1004 |
$thStyle=($template_type=='print') ? '' : ' style="'.$section_values['style']['th'].'"'; |
| 1005 |
$tpl[$section_key]['section_label'] ='<thead>'.PHP_EOL.'<tr>'.PHP_EOL.'<th colspan="2" '.$thStyle.'>'.PHP_EOL.''.$section_label.''.PHP_EOL.'</th>'.PHP_EOL.'</tr>'.PHP_EOL.'</thead>'.PHP_EOL; |
| 1006 |
} |
| 1007 |
|
| 1008 |
/**************************************** |
| 1009 |
wrap in tbody |
| 1010 |
****************************************/ |
| 1011 |
$tpl[$section_key]['tbody_'] ='<tbody>'.PHP_EOL; |
| 1012 |
|
| 1013 |
/*************************************** |
| 1014 |
rows |
| 1015 |
***************************************/ |
| 1016 |
|
| 1017 |
|
| 1018 |
foreach($section_values['parameters'] as $value_key => $values){ |
| 1019 |
|
| 1020 |
if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ |
| 1021 |
|
| 1022 |
/* left label, right value using filter to space evenly*/ |
| 1023 |
$row = array(); |
| 1024 |
$row['lft'] = $order_formatted['sections'][$section_key][$value_key]['label']; |
| 1025 |
$row['rgt'] = $order_formatted['sections'][$section_key][$value_key]['value_formatted']; |
| 1026 |
|
| 1027 |
/**date, pickup/delivery note or admin notes need no label**/ |
| 1028 |
if($value_key=='order_date' || $value_key=='pickup_delivery' || $value_key=='admin_notes'){ |
| 1029 |
/***wrap in tr/td**/ |
| 1030 |
if($template_type=='emails'){ |
| 1031 |
$set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices |
| 1032 |
$tpl[$section_key][$value_key] ='<tr><td colspan="2" style="'.$set_email_td_all.'">'.$row['rgt'].'</td></tr>'.PHP_EOL; |
| 1033 |
} |
| 1034 |
if($template_type=='print'){ |
| 1035 |
if( $value_key=='admin_notes'){/* use nl2br for admin notes */ |
| 1036 |
$tpl[$section_key][$value_key] ='<tr id="'.$value_key.'"><td colspan="2">'.nl2br($row['rgt']).'</td></tr>'.PHP_EOL; |
| 1037 |
}else{ |
| 1038 |
$tpl[$section_key][$value_key] ='<tr id="'.$value_key.'"><td colspan="2">'.$row['rgt'].'</td></tr>'.PHP_EOL; |
| 1039 |
} |
| 1040 |
} |
| 1041 |
}else{ |
| 1042 |
/***wrap in tr/td**/ |
| 1043 |
if($template_type=='emails'){ |
| 1044 |
$set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices |
| 1045 |
$tpl[$section_key][$value_key] ='<tr><td style="'.$section_values['style']['td-lft'].';'.$set_email_td_all.'">'.$row['lft'].'</td><td style="'.$section_values['style']['td-rgt'].';'.$set_email_td_all.'">'.$row['rgt'].'</td></tr>'.PHP_EOL; |
| 1046 |
} |
| 1047 |
if($template_type=='print'){ |
| 1048 |
$tpl[$section_key][$value_key] ='<tr id="'.$value_key.'"><td>'.implode('</td><td>',$row).'</td></tr>'.PHP_EOL; |
| 1049 |
} |
| 1050 |
|
| 1051 |
} |
| 1052 |
} |
| 1053 |
} |
| 1054 |
|
| 1055 |
/**************************************** |
| 1056 |
close tbody |
| 1057 |
****************************************/ |
| 1058 |
$tpl[$section_key]['_tbody'] ='</tbody>'.PHP_EOL; |
| 1059 |
|
| 1060 |
/**************************************** |
| 1061 |
implode for output |
| 1062 |
****************************************/ |
| 1063 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 1064 |
$tpl[$section_key] = implode(PHP_EOL, $tpl[$section_key]); |
| 1065 |
|
| 1066 |
/**************************************** |
| 1067 |
wrap in table |
| 1068 |
****************************************/ |
| 1069 |
if($template_type=='emails'){ |
| 1070 |
$tpl[$section_key]='<table id="'.$section_key.'" style="position:relative;width:100%;'.$section_values['style']['table'].'">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 1071 |
} |
| 1072 |
if($template_type=='print'){ |
| 1073 |
$tpl[$section_key]='<table id="overview">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
/********************************************************** |
| 1078 |
* |
| 1079 |
* |
| 1080 |
* customer vars - typically labelled "Customer Details" in Wppizza -> Templates |
| 1081 |
* |
| 1082 |
* |
| 1083 |
**********************************************************/ |
| 1084 |
if($section_key == 'customer'){ |
| 1085 |
|
| 1086 |
$tpl[$section_key] = array(); |
| 1087 |
|
| 1088 |
/*************************************** |
| 1089 |
label / legend |
| 1090 |
****************************************/ |
| 1091 |
if(!empty($section_values['label_enabled'])){ |
| 1092 |
|
| 1093 |
$section_label = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); |
| 1094 |
|
| 1095 |
/***wrap in tr/th, omit style declarations on print **/ |
| 1096 |
$thStyle=($template_type=='print') ? '' : ' style="'.$section_values['style']['th'].'"'; |
| 1097 |
$tpl[$section_key]['section_label'] ='<thead>'.PHP_EOL.'<tr>'.PHP_EOL.'<th colspan="2" '.$thStyle.'>'.PHP_EOL.''.$section_label.''.PHP_EOL.'</th>'.PHP_EOL.'</tr>'.PHP_EOL.'</thead>'.PHP_EOL; |
| 1098 |
} |
| 1099 |
|
| 1100 |
/**************************************** |
| 1101 |
wrap in tbody |
| 1102 |
****************************************/ |
| 1103 |
$tpl[$section_key]['tbody_'] ='<tbody>'.PHP_EOL; |
| 1104 |
|
| 1105 |
/*************************************** |
| 1106 |
rows |
| 1107 |
***************************************/ |
| 1108 |
foreach($section_values['parameters'] as $value_key => $values){ |
| 1109 |
|
| 1110 |
if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ |
| 1111 |
|
| 1112 |
/* |
| 1113 |
if omit_if_optional is set, |
| 1114 |
omit formfield if field is not required to be filled in |
| 1115 |
the 'required_attribute' willalready be set (or not as the case may be) |
| 1116 |
depending on if it's pickup or delivery and required or not for those |
| 1117 |
*/ |
| 1118 |
if(!empty($order_formatted['sections'][$section_key][$value_key]['omit_if_optional']) && empty($order_formatted['sections'][$section_key][$value_key]['required_attribute'])){ |
| 1119 |
continue; |
| 1120 |
} |
| 1121 |
|
| 1122 |
/* |
| 1123 |
left label, right value using filter to space evenly |
| 1124 |
*/ |
| 1125 |
$row = array(); |
| 1126 |
|
| 1127 |
/* |
| 1128 |
label |
| 1129 |
*/ |
| 1130 |
$row['lft'] = $order_formatted['sections'][$section_key][$value_key]['label']; |
| 1131 |
|
| 1132 |
|
| 1133 |
// value |
| 1134 |
/* |
| 1135 |
radios and dropdowns need to be mapped back from numerical index to value |
| 1136 |
*/ |
| 1137 |
//selects/dropdowns |
| 1138 |
if($order_formatted['sections'][$section_key][$value_key]['type'] == 'select'){ |
| 1139 |
//for backward compatibility, if using test as key as opposed to numeric indexes , decode entities |
| 1140 |
$selIdx = wppizza_decode_entities($order_formatted['sections'][$section_key][$value_key]['value']); |
| 1141 |
$value = isset($order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]['label']) ? $order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]['label'] : '' ; |
| 1142 |
} |
| 1143 |
//radios |
| 1144 |
elseif($order_formatted['sections'][$section_key][$value_key]['type'] == 'radio'){ |
| 1145 |
$selIdx = $order_formatted['sections'][$section_key][$value_key]['value']; |
| 1146 |
$value = isset($order_formatted['sections'][$section_key][$value_key]['options'][$selIdx]) ? $order_formatted['sections'][$section_key][$value_key]['options'][$selIdx] : '' ; |
| 1147 |
} |
| 1148 |
//multicheckboxes |
| 1149 |
elseif($order_formatted['sections'][$section_key][$value_key]['type'] == 'multicheckbox'){ |
| 1150 |
//selected indexes (comma seperated string) |
| 1151 |
$selVals = $order_formatted['sections'][$section_key][$value_key]['value']; |
| 1152 |
//available indexes (array) |
| 1153 |
$optIdxs = $order_formatted['sections'][$section_key][$value_key]['options']; |
| 1154 |
//init empty |
| 1155 |
$output = ''; |
| 1156 |
//map selected indexes back to values |
| 1157 |
if($selVals != ''){ |
| 1158 |
$selIdxs = array_flip(wppizza_strtoarray($selVals)); |
| 1159 |
$intersect = array_intersect_key($optIdxs, $selIdxs); |
| 1160 |
$output = implode(', ',$intersect); |
| 1161 |
} |
| 1162 |
$value = $output; |
| 1163 |
} |
| 1164 |
//all other |
| 1165 |
else{ |
| 1166 |
$value = $order_formatted['sections'][$section_key][$value_key]['value']; |
| 1167 |
} |
| 1168 |
|
| 1169 |
/* |
| 1170 |
right hand side (i.e the value selected/entered) |
| 1171 |
*/ |
| 1172 |
$row['rgt'] = $value; |
| 1173 |
|
| 1174 |
/***wrap in tr/td**/ |
| 1175 |
if($template_type=='emails'){ |
| 1176 |
$set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices |
| 1177 |
$tpl[$section_key][$value_key] ='<tr><td style="'.$section_values['style']['td-lft'].';'.$set_email_td_all.'">'.$row['lft'].'</td><td style="'.$section_values['style']['td-rgt'].';'.$set_email_td_all.'">'.$row['rgt'].'</td></tr>'.PHP_EOL; |
| 1178 |
} |
| 1179 |
if($template_type=='print'){ |
| 1180 |
$tpl[$section_key][$value_key] ='<tr id="'.$value_key.'"><td>'.implode('</td><td>',$row).'</td></tr>'.PHP_EOL; |
| 1181 |
} |
| 1182 |
} |
| 1183 |
} |
| 1184 |
|
| 1185 |
/**************************************** |
| 1186 |
close tbody |
| 1187 |
****************************************/ |
| 1188 |
$tpl[$section_key]['_tbody'] ='</tbody>'.PHP_EOL; |
| 1189 |
|
| 1190 |
/**************************************** |
| 1191 |
implode for output |
| 1192 |
****************************************/ |
| 1193 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 1194 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 1195 |
|
| 1196 |
/**************************************** |
| 1197 |
wrap in table |
| 1198 |
****************************************/ |
| 1199 |
if($template_type=='emails'){ |
| 1200 |
$tpl[$section_key]='<table id="'.$section_key.'" style="position:relative;width:100%;'.$section_values['style']['table'].'">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 1201 |
} |
| 1202 |
if($template_type=='print'){ |
| 1203 |
$tpl[$section_key]='<table id="'.$section_key.'">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 1204 |
} |
| 1205 |
} |
| 1206 |
/********************************************************** |
| 1207 |
* |
| 1208 |
* |
| 1209 |
* itemised order vars - typically labelled "Order Details" in Wppizza -> Templates |
| 1210 |
* |
| 1211 |
* |
| 1212 |
**********************************************************/ |
| 1213 |
if($section_key == 'order'){ |
| 1214 |
|
| 1215 |
/*************************************** |
| 1216 |
get order column data |
| 1217 |
***************************************/ |
| 1218 |
$order_columns = WPPIZZA()->helpers->itemised_order_columns($order_formatted, $template_parameters, $template_type); |
| 1219 |
|
| 1220 |
/*************************************** |
| 1221 |
ini array |
| 1222 |
***************************************/ |
| 1223 |
$tpl[$section_key] = array(); |
| 1224 |
|
| 1225 |
/*************************************** |
| 1226 |
label / legend - wrapped in <thead> |
| 1227 |
****************************************/ |
| 1228 |
if(!empty($section_values['label_enabled'])){ |
| 1229 |
$tpl[$section_key]['section_label'] = $order_columns['column_label']['html']; |
| 1230 |
} |
| 1231 |
|
| 1232 |
/**************************************** |
| 1233 |
itemised order rows - wrapped in <tbody> |
| 1234 |
****************************************/ |
| 1235 |
$tpl[$section_key]['itemised'] = $order_columns['itemised']['html']; |
| 1236 |
|
| 1237 |
/**************************************** |
| 1238 |
implode for output |
| 1239 |
****************************************/ |
| 1240 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 1241 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 1242 |
|
| 1243 |
/**************************************** |
| 1244 |
wrap in <table> |
| 1245 |
****************************************/ |
| 1246 |
if($template_type=='emails'){ |
| 1247 |
$tpl[$section_key]='<table id="'.$section_key.'" style="position:relative;width:100%;'.$section_values['style']['table'].'">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 1248 |
} |
| 1249 |
if($template_type=='print'){ |
| 1250 |
$tpl[$section_key]='<table id="'.$section_key.'">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 1251 |
} |
| 1252 |
} |
| 1253 |
/********************************************************** |
| 1254 |
* |
| 1255 |
* |
| 1256 |
* summary vars - typically labelled "Summary" in Wppizza -> Templates |
| 1257 |
* |
| 1258 |
* |
| 1259 |
**********************************************************/ |
| 1260 |
if($section_key == 'summary'){ |
| 1261 |
|
| 1262 |
$tpl[$section_key] = array(); |
| 1263 |
|
| 1264 |
/*************************************** |
| 1265 |
label / legend |
| 1266 |
****************************************/ |
| 1267 |
if(!empty($section_values['label_enabled'])){ |
| 1268 |
|
| 1269 |
$section_label = empty($order_formatted['localization']['templates_label_'.$section_key.'']) ? '' : trim($order_formatted['localization']['templates_label_'.$section_key.'']); |
| 1270 |
|
| 1271 |
/***wrap in tr/th, omit style declarations on print **/ |
| 1272 |
$thStyle=($template_type=='print') ? '' : ' style="'.$section_values['style']['th'].'"'; |
| 1273 |
$tpl[$section_key]['section_label'] ='<thead>'.PHP_EOL.'<tr>'.PHP_EOL.'<th colspan="2" '.$thStyle.'>'.PHP_EOL.''.$section_label.''.PHP_EOL.'</th>'.PHP_EOL.'</tr>'.PHP_EOL.'</thead>'.PHP_EOL; |
| 1274 |
} |
| 1275 |
|
| 1276 |
/**************************************** |
| 1277 |
wrap in tbody |
| 1278 |
****************************************/ |
| 1279 |
$tpl[$section_key]['tbody_'] ='<tbody>'.PHP_EOL; |
| 1280 |
|
| 1281 |
/*************************************** |
| 1282 |
rows |
| 1283 |
***************************************/ |
| 1284 |
foreach($section_values['parameters'] as $value_key => $values){ |
| 1285 |
|
| 1286 |
if(!empty($values['enabled']) && !empty($order_formatted['sections'][$section_key][$value_key])){ |
| 1287 |
foreach($order_formatted['sections'][$section_key][$value_key] as $vKey => $vals){ |
| 1288 |
/* left label, right value using filter to space evenly*/ |
| 1289 |
$row = array(); |
| 1290 |
$row['lft'] = $vals['label']; |
| 1291 |
$row['rgt'] = $vals['value_formatted']; |
| 1292 |
|
| 1293 |
/***wrap in tr/td**/ |
| 1294 |
if($template_type=='emails'){ |
| 1295 |
$set_email_td_all = !empty($section_values['style'][$value_key.'-tdall']) ? $section_values['style'][$value_key.'-tdall'] : '' ;//remove potential php notices |
| 1296 |
$tpl[$section_key][$value_key.'_'.$vKey] ='<tr><td style="'.$section_values['style']['td-lft'].';'.$set_email_td_all.'">'.$row['lft'].'</td><td style="'.$section_values['style']['td-rgt'].';'.$set_email_td_all.'">'.$row['rgt'].'</td></tr>'.PHP_EOL; |
| 1297 |
} |
| 1298 |
if($template_type=='print'){ |
| 1299 |
$tpl[$section_key][$value_key.'_'.$vKey] ='<tr id="'.$value_key.'"><td>'.implode('</td><td>',$row).'</td></tr>'.PHP_EOL; |
| 1300 |
} |
| 1301 |
} |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
/**************************************** |
| 1306 |
close tbody |
| 1307 |
****************************************/ |
| 1308 |
$tpl[$section_key]['_tbody'] ='</tbody>'.PHP_EOL; |
| 1309 |
|
| 1310 |
/**************************************** |
| 1311 |
implode for output |
| 1312 |
****************************************/ |
| 1313 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 1314 |
$tpl[$section_key] = implode(PHP_EOL,$tpl[$section_key]); |
| 1315 |
|
| 1316 |
/**************************************** |
| 1317 |
wrap in table |
| 1318 |
****************************************/ |
| 1319 |
if($template_type=='emails'){ |
| 1320 |
$tpl[$section_key]='<table id="'.$section_key.'" style="position:relative;width:100%;'.$section_values['style']['table'].'">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 1321 |
} |
| 1322 |
if($template_type=='print'){ |
| 1323 |
$tpl[$section_key]='<table id="'.$section_key.'">'.PHP_EOL.''.$tpl[$section_key].'</table>'.PHP_EOL.''; |
| 1324 |
} |
| 1325 |
} |
| 1326 |
|
| 1327 |
} |
| 1328 |
}} |
| 1329 |
|
| 1330 |
/************************************** |
| 1331 |
* |
| 1332 |
* if using get_skeleton_template with content set |
| 1333 |
* with some hardcoded minimum padding |
| 1334 |
**************************************/ |
| 1335 |
if(!empty($template_contents)){ |
| 1336 |
|
| 1337 |
$section_key = 'contents'; |
| 1338 |
|
| 1339 |
$tpl[$section_key] = '<table id="'.$section_key.'"><tbody><tr><td style="padding:30px 10px">' . $template_contents . '</td></tr></tbody></table>'.PHP_EOL.''; |
| 1340 |
} |
| 1341 |
|
| 1342 |
/*********************************************************************** |
| 1343 |
* |
| 1344 |
* [add footer text in EMAIL templates after everything else] |
| 1345 |
* |
| 1346 |
***********************************************************************/ |
| 1347 |
if($template_type=='emails'){ |
| 1348 |
$section_key = 'footer'; |
| 1349 |
$tpl[$section_key] = array(); |
| 1350 |
|
| 1351 |
if(!empty($order_formatted['localization']['templates_footer_note'])){ |
| 1352 |
$tpl[$section_key]['footer_note'] = $order_formatted['localization']['templates_footer_note']; |
| 1353 |
} |
| 1354 |
|
| 1355 |
/* make it filterable just like all other sections */ |
| 1356 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 1357 |
|
| 1358 |
|
| 1359 |
if(count($tpl[$section_key])>0){ |
| 1360 |
$tpl[$section_key]='<table id="'.$section_key.'" style="position:relative;width:100%;text-align:center;font-size:90%"><tr><td>'.PHP_EOL.''.implode(PHP_EOL,$tpl[$section_key]).'</td></tr></table>'.PHP_EOL.''; |
| 1361 |
}else{ |
| 1362 |
$tpl[$section_key]=''; |
| 1363 |
} |
| 1364 |
|
| 1365 |
} |
| 1366 |
|
| 1367 |
/*********************************************************************** |
| 1368 |
* |
| 1369 |
* [add footer text in PRINT templates after everything else] |
| 1370 |
* |
| 1371 |
***********************************************************************/ |
| 1372 |
if($template_type=='print'){ |
| 1373 |
$section_key = 'footer'; |
| 1374 |
$tpl[$section_key] = array(); |
| 1375 |
|
| 1376 |
if(!empty($order_formatted['localization']['templates_footer_note_print'])){ |
| 1377 |
$tpl[$section_key]['footer_note'] = $order_formatted['localization']['templates_footer_note_print']; |
| 1378 |
} |
| 1379 |
|
| 1380 |
/* make it filterable just like all other sections */ |
| 1381 |
$tpl[$section_key] = apply_filters('wppizza_filter_template_'.$section_key.'_section', $tpl[$section_key], $template_type, $template_id, $order_formatted['sections']); |
| 1382 |
|
| 1383 |
|
| 1384 |
if(count($tpl[$section_key])>0){ |
| 1385 |
$tpl[$section_key]='<table id="'.$section_key.'"><tr><td>'.PHP_EOL.''.implode(PHP_EOL,$tpl[$section_key]).'</td></tr></table>'.PHP_EOL.''; |
| 1386 |
}else{ |
| 1387 |
$tpl[$section_key]=''; |
| 1388 |
} |
| 1389 |
|
| 1390 |
} |
| 1391 |
|
| 1392 |
|
| 1393 |
/** |
| 1394 |
filterable array sections |
| 1395 |
**/ |
| 1396 |
$tpl = apply_filters('wppizza_filter_template_markup', $tpl, $template_type, $order_formatted, $template_id); |
| 1397 |
|
| 1398 |
/** |
| 1399 |
return just the sections as array |
| 1400 |
before wrapping it into an html document |
| 1401 |
**/ |
| 1402 |
if($return_sections){ |
| 1403 |
return $tpl; |
| 1404 |
} |
| 1405 |
|
| 1406 |
/** |
| 1407 |
output as string |
| 1408 |
**/ |
| 1409 |
$templateMarkup = implode(PHP_EOL.PHP_EOL, $tpl); |
| 1410 |
|
| 1411 |
/************************************************************************************************************************** |
| 1412 |
* |
| 1413 |
* |
| 1414 |
* |
| 1415 |
* [html elements wrapper to insert it into] |
| 1416 |
* |
| 1417 |
* |
| 1418 |
* |
| 1419 |
**************************************************************************************************************************/ |
| 1420 |
|
| 1421 |
$html=''; |
| 1422 |
$html.='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.PHP_EOL; |
| 1423 |
|
| 1424 |
$html.='<html xmlns="http://www.w3.org/1999/xhtml">'.PHP_EOL; |
| 1425 |
|
| 1426 |
|
| 1427 |
/* |
| 1428 |
head |
| 1429 |
*/ |
| 1430 |
$html.='<head>'.PHP_EOL; |
| 1431 |
|
| 1432 |
|
| 1433 |
/* |
| 1434 |
title |
| 1435 |
used as filename when using print / save as pdf for example. |
| 1436 |
filterable let's be save and sanitize to a-zA-Z0-9\-_ for now |
| 1437 |
*/ |
| 1438 |
$filter_args = array('order_formatted' => $order_formatted, 'tpl' => $tpl, 'template_type' => $template_type); |
| 1439 |
$title_tag = __('Order','wppizza-admin'); |
| 1440 |
$title_tag .= (isset($order_formatted['sections']['ordervars']['order_id']['value_formatted']) ? '-'.$order_formatted['sections']['ordervars']['order_id']['value_formatted'].'' : '' ); |
| 1441 |
$title_tag = apply_filters('wppizza_filter_template_markup_title_tag', $title_tag , $filter_args); |
| 1442 |
$html.='<title>'.wppizza_validate_alpha_only($title_tag).'</title>'.PHP_EOL; |
| 1443 |
|
| 1444 |
/* |
| 1445 |
meta |
| 1446 |
*/ |
| 1447 |
$html.='<meta http-equiv="Content-Type" content="text/html;charset='.get_option('blog_charset').'" />'.PHP_EOL; |
| 1448 |
|
| 1449 |
if($template_type=='print'){ |
| 1450 |
$html.='<style type="text/css">'.apply_filters('wppizza_filter_templates_html_print_css',$template_parameters['global_styles']['body'], $order_formatted).'</style>'; |
| 1451 |
} |
| 1452 |
|
| 1453 |
$html.='</head>'.PHP_EOL; |
| 1454 |
|
| 1455 |
/* |
| 1456 |
body |
| 1457 |
*/ |
| 1458 |
if($template_type=='emails'){ |
| 1459 |
$body ='<body style="'.$template_parameters['global_styles']['body'].'">'.PHP_EOL; |
| 1460 |
} |
| 1461 |
if($template_type=='print'){ |
| 1462 |
//set to order-completed as default |
| 1463 |
$bodyId = !empty($order_formatted['sections']['ordervars']['payment_status']['value_formatted']) ? 'order-'.$order_formatted['sections']['ordervars']['payment_status']['value_formatted'].'' : 'order-completed' ; |
| 1464 |
$body ='<body id="'.$bodyId.'">'.PHP_EOL; |
| 1465 |
} |
| 1466 |
/* make starting body tag filterable */ |
| 1467 |
$html .= apply_filters('wppizza_filter_template_markup_html_body', $body, $template_type, $template_id, $order_formatted); |
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
/* |
| 1472 |
content |
| 1473 |
*/ |
| 1474 |
/*only wrap for emails*/ |
| 1475 |
if($template_type=='emails'){ |
| 1476 |
$html.='<table style="border-collapse:collapse;'.$template_parameters['global_styles']['wrapper'].'">'.PHP_EOL; |
| 1477 |
$html.='<tr>'.PHP_EOL; |
| 1478 |
$html.='<td>'.PHP_EOL; |
| 1479 |
$html.='<center>'.PHP_EOL; |
| 1480 |
$html.='<table style="border-collapse:collapse;'.$template_parameters['global_styles']['table'].'">'.PHP_EOL; |
| 1481 |
$html.='<tbody>'.PHP_EOL; |
| 1482 |
$html.='<tr>'.PHP_EOL; |
| 1483 |
$html.='<td>'.PHP_EOL; |
| 1484 |
} |
| 1485 |
|
| 1486 |
/** |
| 1487 |
insert content into body |
| 1488 |
**/ |
| 1489 |
$html .= $templateMarkup.PHP_EOL; |
| 1490 |
|
| 1491 |
/** |
| 1492 |
close tags |
| 1493 |
**/ |
| 1494 |
/*only wrap td/tr/table/center etc for emails*/ |
| 1495 |
if($template_type=='emails'){ |
| 1496 |
$html.='</td>'.PHP_EOL; |
| 1497 |
$html.='</tr>'.PHP_EOL; |
| 1498 |
$html.='</tbody>'.PHP_EOL; |
| 1499 |
$html.='</table>'.PHP_EOL; |
| 1500 |
$html.='</center>'.PHP_EOL; |
| 1501 |
$html.='</td>'.PHP_EOL; |
| 1502 |
$html.='</tr>'.PHP_EOL; |
| 1503 |
$html.='</table>'.PHP_EOL; |
| 1504 |
} |
| 1505 |
$html.='</body>'.PHP_EOL; |
| 1506 |
$html.='</html>'.PHP_EOL; |
| 1507 |
|
| 1508 |
/* |
| 1509 |
allow to filter the whole html |
| 1510 |
*/ |
| 1511 |
$html = apply_filters('wppizza_filter_template_markup_html', $html, $template_type, $template_id, $order_formatted); |
| 1512 |
|
| 1513 |
return $html; |
| 1514 |
} |
| 1515 |
|
| 1516 |
/********************************************************* |
| 1517 |
* [get email/print skeleton template by id or shop/customer |
| 1518 |
* inserting content between header and footer] |
| 1519 |
* @since 3.9.2 |
| 1520 |
* @param str. emails or print |
| 1521 |
* @param mixed (id or id/shop/customer for email templates). omit to use default |
| 1522 |
* @param str the content we want to use |
| 1523 |
* @return array of message and message type (html/plaintext) |
| 1524 |
*********************************************************/ |
| 1525 |
function get_skeleton_template($type = 'emails' , $id = 0, $content = ''){ |
| 1526 |
global $wppizza_options, $blog_id; |
| 1527 |
|
| 1528 |
/* skip if type is wrong */ |
| 1529 |
if($type != 'emails' && $type != 'print' ){ |
| 1530 |
return ''; |
| 1531 |
} |
| 1532 |
|
| 1533 |
|
| 1534 |
/**** distinguish between email and print templates ****/ |
| 1535 |
/* |
| 1536 |
get id/parameters - emails |
| 1537 |
*/ |
| 1538 |
if($type == 'emails'){ |
| 1539 |
|
| 1540 |
/* |
| 1541 |
get templates for this type |
| 1542 |
*/ |
| 1543 |
$templates = get_option(WPPIZZA_SLUG.'_templates_'.$type); |
| 1544 |
|
| 1545 |
|
| 1546 |
/* template used for shop emails */ |
| 1547 |
if($id == 'shop' ){ |
| 1548 |
$template_id = $wppizza_options['templates_apply']['emails']['recipients_default']['email_shop']; |
| 1549 |
} |
| 1550 |
/* template used for customer emails */ |
| 1551 |
elseif($id == 'customer' ){ |
| 1552 |
$template_id = $wppizza_options['templates_apply']['emails']['recipients_default']['email_customer']; |
| 1553 |
} |
| 1554 |
else{ |
| 1555 |
$template_id = (int)$id; |
| 1556 |
} |
| 1557 |
|
| 1558 |
/* if it does not exist, simply return the first one */ |
| 1559 |
if(!isset($templates[$template_id])){ |
| 1560 |
$template_id = 0; |
| 1561 |
} |
| 1562 |
|
| 1563 |
/* |
| 1564 |
set templates parameters |
| 1565 |
*/ |
| 1566 |
$templates = $templates[$template_id]; |
| 1567 |
|
| 1568 |
} |
| 1569 |
/* |
| 1570 |
get id/parameters - print |
| 1571 |
*/ |
| 1572 |
if($type == 'print'){ |
| 1573 |
/* |
| 1574 |
get templates for this type |
| 1575 |
*/ |
| 1576 |
$templates = get_option(WPPIZZA_SLUG.'_templates_'.$type); |
| 1577 |
|
| 1578 |
/* default template */ |
| 1579 |
if($id == 'default' ){ |
| 1580 |
$template_id = $wppizza_options['templates_apply']['print']; |
| 1581 |
}else{ |
| 1582 |
$template_id = (int)$id; |
| 1583 |
} |
| 1584 |
|
| 1585 |
/* if set id does not exist, return the default */ |
| 1586 |
if(!isset($templates[$template_id])){ |
| 1587 |
$template_id = 0; |
| 1588 |
} |
| 1589 |
|
| 1590 |
/* |
| 1591 |
set templates parameters |
| 1592 |
*/ |
| 1593 |
$templates = $templates[$template_id]; |
| 1594 |
} |
| 1595 |
/**** end distinction between emails and print ****/ |
| 1596 |
|
| 1597 |
|
| 1598 |
/* |
| 1599 |
force disable of everything but header and footer |
| 1600 |
*/ |
| 1601 |
$templates['sections']['ordervars']['section_enabled'] = false;//test if thsi should be disabled actually!!! |
| 1602 |
$templates['sections']['customer']['section_enabled'] = false; |
| 1603 |
$templates['sections']['order']['section_enabled'] = false; |
| 1604 |
$templates['sections']['summary']['section_enabled'] = false; |
| 1605 |
|
| 1606 |
|
| 1607 |
/* |
| 1608 |
set order dummy parameters for header to pass on |
| 1609 |
it really is only the site details blog info |
| 1610 |
that gets passed on to the header as we are completely |
| 1611 |
omitting any order parameters. |
| 1612 |
Afer all, the point of this is to simply display a skeleton |
| 1613 |
template including wrapper, and header / footer only |
| 1614 |
with the main information that is normally the order details |
| 1615 |
to be replaced as needed |
| 1616 |
*/ |
| 1617 |
$dummy_order = array(); |
| 1618 |
$dummy_order['blog_info'] = wppizza_get_blog_details($blog_id); |
| 1619 |
$dummy_order['blog_options']['localization'] = $wppizza_options['localization']; |
| 1620 |
|
| 1621 |
|
| 1622 |
/* skeleton param */ |
| 1623 |
$skeleton_formatted = array(); |
| 1624 |
$skeleton_formatted['sections'] = array(); |
| 1625 |
$skeleton_formatted['sections']['site'] = WPPIZZA()->order->site_details_formatted($dummy_order, false); |
| 1626 |
$skeleton_formatted['localization'] = $wppizza_options['localization']; |
| 1627 |
$skeleton_formatted['blog_info'] = $dummy_order['blog_info']; |
| 1628 |
$skeleton_formatted['date_format'] = wppizza_get_blog_dateformat(); |
| 1629 |
|
| 1630 |
|
| 1631 |
/* |
| 1632 |
get layout type |
| 1633 |
html/plaintext |
| 1634 |
*/ |
| 1635 |
$template_type = $templates['mail_type'] == 'wp_mail' ? 'text/plain' : 'text/html'; |
| 1636 |
|
| 1637 |
|
| 1638 |
/* |
| 1639 |
get output depending on format |
| 1640 |
*/ |
| 1641 |
$message = ''; |
| 1642 |
|
| 1643 |
if($template_type == 'text/html'){ |
| 1644 |
$message = WPPIZZA() -> templates_email_print -> get_template_email_html_sections_markup($skeleton_formatted, $templates, $type, $template_id, $content); |
| 1645 |
}else{ |
| 1646 |
$message = WPPIZZA() -> templates_email_print -> get_template_email_plaintext_sections_markup($skeleton_formatted, $templates, $type, $template_id, $content); |
| 1647 |
$message = $message['markup']; |
| 1648 |
} |
| 1649 |
|
| 1650 |
/* |
| 1651 |
return message and message type (html/plaintext) |
| 1652 |
*/ |
| 1653 |
$param = array(); |
| 1654 |
$param['type'] = $template_type; |
| 1655 |
$param['message'] = $message; |
| 1656 |
|
| 1657 |
return $param; |
| 1658 |
} |
| 1659 |
} |
| 1660 |
?> |