| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_SCRIPTS_AND_STYLES Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_SCRIPTS_AND_STYLES |
| 7 |
* @copyright Copyright (c) 2015, Oliver Bach |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 3.0 |
| 10 |
* |
| 11 |
*/ |
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/ |
| 13 |
|
| 14 |
|
| 15 |
/************************************************************************************************************************ |
| 16 |
* |
| 17 |
* |
| 18 |
* ALL WPPIZZA_SCRIPTS_AND_STYLES |
| 19 |
* |
| 20 |
* |
| 21 |
* |
| 22 |
************************************************************************************************************************/ |
| 23 |
class WPPIZZA_SCRIPTS_AND_STYLES{ |
| 24 |
function __construct() { |
| 25 |
|
| 26 |
/****************************** |
| 27 |
[runs only for frontend] |
| 28 |
but should also run on ajax |
| 29 |
******************************/ |
| 30 |
global $wppizza_options; |
| 31 |
|
| 32 |
|
| 33 |
/*** enqueue header scripts on checkout ***/ |
| 34 |
add_action( 'wp_head', array($this, 'wppizza_wp_head_on_checkout')); |
| 35 |
|
| 36 |
/***enqueue frontend styles - using some default if not yet set to avoid notices on install ***/ |
| 37 |
add_action('wp_enqueue_scripts', array( $this, 'wppizza_register_enqueue_scripts_and_styles'), (empty($wppizza_options['layout']['css_priority']) ? 11 : (int)$wppizza_options['layout']['css_priority'] )); |
| 38 |
|
| 39 |
|
| 40 |
} |
| 41 |
/****************************************************************** |
| 42 |
add any header script on checkout, if shop is open |
| 43 |
|
| 44 |
@param void |
| 45 |
@since 3.7 |
| 46 |
@return void |
| 47 |
******************************************************************/ |
| 48 |
function wppizza_wp_head_on_checkout(){ |
| 49 |
/* |
| 50 |
skip on all admin (including ajax )requests |
| 51 |
checkout only, shop open only, non-empty cart only |
| 52 |
*/ |
| 53 |
if(!wppizza_is_checkout() || !wppizza_is_shop_open() || wppizza_cart_is_empty()){return;} |
| 54 |
|
| 55 |
/* |
| 56 |
add script for gateways that allow inline payments |
| 57 |
when this particular gateway has been selected |
| 58 |
*/ |
| 59 |
$selected_gateway_ident = WPPIZZA()->session->get_selected_gateway(); |
| 60 |
do_action('wppizza_wp_head_on_checkout', $selected_gateway_ident); |
| 61 |
} |
| 62 |
/********************************************************************************************************************************************************************************** |
| 63 |
* |
| 64 |
* |
| 65 |
* |
| 66 |
* [register and enqueue css and js ] |
| 67 |
* |
| 68 |
* |
| 69 |
* |
| 70 |
**********************************************************************************************************************************************************************************/ |
| 71 |
function wppizza_register_enqueue_scripts_and_styles(){ |
| 72 |
global $wppizza_options, $wp_scripts, $blog_id, $post; |
| 73 |
$is_orderpage = wppizza_is_orderpage();/*are we on orderpage ? bool */ |
| 74 |
/** force "is_orderpage" if there is an orderpage widget on page */ |
| 75 |
$has_orderpage_widget = wppizza_has_orderpage_widget(); |
| 76 |
$is_orderpage = !empty($has_orderpage_widget) ? true : $is_orderpage ; |
| 77 |
/* load validation js on user order history page too **/ |
| 78 |
$is_orderhistory = !empty($is_orderpage) ? false : wppizza_is_orderhistory(); |
| 79 |
/* accordion css/js style */ |
| 80 |
$is_accordion = wppizza_as_accordion(); |
| 81 |
|
| 82 |
$force_script_style_inclusion = apply_filters('wppizza_filter_force_scripts_and_styles', false, $is_orderpage);/* allow to include script and styles on all pages, regardless of what page we are on if true */ |
| 83 |
|
| 84 |
$apply_gateway_localized_js_parameters = apply_filters('wppizza_apply_gateway_filter_localize_js', false);/* allow to filter (add) localised (gateway) parameters */ |
| 85 |
|
| 86 |
/***************************************************************************************************** |
| 87 |
* |
| 88 |
* |
| 89 |
* [register and enqueue css] |
| 90 |
* |
| 91 |
* |
| 92 |
******************************************************************************************************/ |
| 93 |
|
| 94 |
/*** |
| 95 |
skip all styles if not including |
| 96 |
***/ |
| 97 |
if(!empty($wppizza_options['layout']['include_css'])){ |
| 98 |
/** |
| 99 |
get available style and enqueue as required |
| 100 |
**/ |
| 101 |
$styles=wppizza_public_styles(); |
| 102 |
|
| 103 |
/* |
| 104 |
array of styles to enqueue |
| 105 |
*/ |
| 106 |
$enqueue_styles_ident=array(); |
| 107 |
/* |
| 108 |
last style enqueued to set custom css dependency |
| 109 |
*/ |
| 110 |
$dependency_last_style = null; |
| 111 |
|
| 112 |
/* |
| 113 |
load common global style beforee all others |
| 114 |
*/ |
| 115 |
$css_filename=''.WPPIZZA_SLUG.'.css'; |
| 116 |
$css_enqueue_ident= ''.WPPIZZA_SLUG.''; |
| 117 |
if (file_exists( WPPIZZA_TEMPLATE_DIR . '/css/'.$css_filename.'')){ |
| 118 |
/**stylesheet copied to template directory to keep settings**/ |
| 119 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_TEMPLATE_URI.'/css/'.$css_filename, array(), WPPIZZA_VERSION); |
| 120 |
}else{ |
| 121 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_URL . 'css/'.$css_filename, array(), WPPIZZA_VERSION); |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
/* |
| 126 |
loop through available styles, registering the ones that need to be registered |
| 127 |
*/ |
| 128 |
foreach($styles as $style_key=>$style){ |
| 129 |
|
| 130 |
/************************************** |
| 131 |
register selected only or all |
| 132 |
**************************************/ |
| 133 |
if( $style_key == $wppizza_options['layout']['style'] || !empty($wppizza_options['layout']['load_additional_styles'][$style_key])){ |
| 134 |
|
| 135 |
/************************************* |
| 136 |
[register any dependencies first] |
| 137 |
*************************************/ |
| 138 |
if(!empty($style['dependency'])){ |
| 139 |
$css_file_extension = !empty($styles[$style['dependency']]['ext']) ? $styles[$style['dependency']]['ext'] : 'css'; |
| 140 |
$css_filename=''.WPPIZZA_SLUG.'.'.$style['dependency'].'.'.$css_file_extension; |
| 141 |
$css_enqueue_ident= ''.WPPIZZA_SLUG.'-'.$style['dependency']; |
| 142 |
|
| 143 |
if (file_exists( WPPIZZA_TEMPLATE_DIR . '/css/'.$css_filename.'')){ |
| 144 |
/**stylesheet copied to template directory to keep settings**/ |
| 145 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_TEMPLATE_URI.'/css/'.$css_filename, array(), WPPIZZA_VERSION); |
| 146 |
}else{ |
| 147 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_URL . 'css/'.$css_filename, array(), WPPIZZA_VERSION); |
| 148 |
} |
| 149 |
} |
| 150 |
/************************************* |
| 151 |
[register (selected) stylesheet, adding dependency if set] |
| 152 |
*************************************/ |
| 153 |
$css_file_extension = !empty($style['ext']) ? $style['ext'] : 'css'; |
| 154 |
$css_filename=''.WPPIZZA_SLUG.'.'.$style['id'].'.'.$css_file_extension; |
| 155 |
$css_enqueue_ident=''.WPPIZZA_SLUG.'-'.$style['id']; |
| 156 |
$css_dependency=!empty($style['dependency']) ? array(''.WPPIZZA_SLUG.'-'.$style['dependency']) : array(WPPIZZA_SLUG); |
| 157 |
|
| 158 |
$gridParameters=($style['id']=='grid') ? '?grid='.$wppizza_options['layout']['style_grid_columns'].'-'.$wppizza_options['layout']['style_grid_margins'].'-'.$wppizza_options['layout']['style_grid_full_width'].'' : '' ; |
| 159 |
|
| 160 |
if (file_exists( WPPIZZA_TEMPLATE_DIR . '/css/'.$css_filename.'')){ |
| 161 |
/**stylesheet copied to template directory to keep settings**/ |
| 162 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_TEMPLATE_URI.'/css/'.$css_filename . $gridParameters, $css_dependency, WPPIZZA_VERSION); |
| 163 |
}else{ |
| 164 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_URL . 'css/'.$css_filename . $gridParameters , $css_dependency, WPPIZZA_VERSION); |
| 165 |
} |
| 166 |
|
| 167 |
/* |
| 168 |
set last style enqueued |
| 169 |
*/ |
| 170 |
$dependency_last_style = $css_enqueue_ident; |
| 171 |
|
| 172 |
} |
| 173 |
} |
| 174 |
/************************************** |
| 175 |
register rtl css if required |
| 176 |
**************************************/ |
| 177 |
if ( is_rtl() ) { |
| 178 |
$css_filename=''.WPPIZZA_SLUG.'.rtl.css'; |
| 179 |
$css_enqueue_ident=''.WPPIZZA_SLUG.'-rtl'; |
| 180 |
|
| 181 |
if (file_exists( WPPIZZA_TEMPLATE_DIR . '/css/'.$css_filename.'')){ |
| 182 |
/**stylesheet copied to template directory to keep settings**/ |
| 183 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_TEMPLATE_URI.'/css/'.$css_filename, $dependency_last_style, WPPIZZA_VERSION); |
| 184 |
}else{ |
| 185 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_URL . 'css/'.$css_filename , $dependency_last_style, WPPIZZA_VERSION); |
| 186 |
} |
| 187 |
|
| 188 |
/* |
| 189 |
set last style enqueued |
| 190 |
*/ |
| 191 |
$dependency_last_style = $css_enqueue_ident; |
| 192 |
} |
| 193 |
|
| 194 |
/* |
| 195 |
enqueue dashicons for cartimage under prices and empty image/photo placeholder |
| 196 |
*/ |
| 197 |
$css_enqueue_ident='dashicons'; |
| 198 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, get_stylesheet_uri(), array($dependency_last_style), $wp_scripts->default_version); |
| 199 |
$dependency_last_style = $css_enqueue_ident; |
| 200 |
|
| 201 |
|
| 202 |
/************************************ |
| 203 |
register custom css (CUSTOM FILE IN TEMPLATES) AFTER all other loaded css |
| 204 |
if we want to keep all the original css (including future changes) but only want to overwrite some lines , |
| 205 |
add wppizza-custom.css to your template directory |
| 206 |
*************************************/ |
| 207 |
$css_filename=''.WPPIZZA_SLUG.'.custom.css'; |
| 208 |
if (file_exists( WPPIZZA_TEMPLATE_DIR . '/css/'.$css_filename.'')){ |
| 209 |
$css_enqueue_ident=''.WPPIZZA_SLUG.'-custom'; |
| 210 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_TEMPLATE_URI.'/css/'.$css_filename, array($dependency_last_style), WPPIZZA_VERSION); |
| 211 |
$dependency_last_style = $css_enqueue_ident; |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
/************************************ |
| 216 |
register custom css (WPPIZZA->LAYOUT) OPTION set in layout page |
| 217 |
and either load file (if possible) |
| 218 |
or inline if necessary |
| 219 |
*************************************/ |
| 220 |
$css_filename=''.WPPIZZA_PREFIX.'.style.css'; |
| 221 |
$custom_css_file_path = WPPIZZA_PATH.'css/'.$css_filename.''; |
| 222 |
/* mke sure to regenerate file if it does not exists but should (on plugin update for example) */ |
| 223 |
if($wppizza_options['layout']['custom_css_type'] == 'file' && !file_exists($custom_css_file_path)){ |
| 224 |
$custom_css = get_option(WPPIZZA_SLUG.'_custom_css', ''); |
| 225 |
@file_put_contents($custom_css_file_path, $custom_css); |
| 226 |
} |
| 227 |
|
| 228 |
if($wppizza_options['layout']['custom_css_type'] == 'file' && file_exists($custom_css_file_path)){ |
| 229 |
$css_enqueue_ident=''.WPPIZZA_SLUG.'-style'; |
| 230 |
$enqueue_styles_ident[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_URL . 'css/'.$css_filename , $dependency_last_style, $wppizza_options['layout']['custom_css_version']); |
| 231 |
$dependency_last_style = $css_enqueue_ident; |
| 232 |
} |
| 233 |
/** add custom style inline if we need to ***/ |
| 234 |
if($wppizza_options['layout']['custom_css_type'] == 'inline'){ |
| 235 |
$custom_css = get_option(WPPIZZA_SLUG.'_custom_css', ''); |
| 236 |
if(!empty($custom_css)){ |
| 237 |
wp_add_inline_style( $dependency_last_style, $custom_css ); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
/*************************************** |
| 242 |
* |
| 243 |
* [enqueue all styles registered above] |
| 244 |
* [allow filtering to insert stylesheets somewhere in between - @since 3.10] |
| 245 |
***************************************/ |
| 246 |
$enqueue_styles_ident = apply_filters('wppizza_filter_enqueued_styles', $enqueue_styles_ident);// @since 3.10 |
| 247 |
foreach($enqueue_styles_ident as $enqueue_id => $enqueue){ |
| 248 |
wp_enqueue_style($enqueue_id); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
/* |
| 253 |
enqueue global styles |
| 254 |
*/ |
| 255 |
$enqueue_styles_global = array(); |
| 256 |
/** |
| 257 |
pretty photo css |
| 258 |
**/ |
| 259 |
if($wppizza_options['layout']['prettyPhoto']){ |
| 260 |
$css_filename=''.WPPIZZA_SLUG.'.prettyphoto.css'; |
| 261 |
$css_enqueue_ident=''.WPPIZZA_SLUG.'-prettyphoto'; |
| 262 |
$enqueue_styles_global[$css_enqueue_ident] = wp_register_style($css_enqueue_ident, WPPIZZA_URL.'css/'.$css_filename, array(), WPPIZZA_VERSION); |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
include spinner css/js on orderpage or globally (if cart increase) if enabled |
| 267 |
**/ |
| 268 |
if(($is_orderpage && !empty($wppizza_options['order_settings']['order_page_quantity_change'])) || !empty($wppizza_options['order_settings']['cart_increase']) || $force_script_style_inclusion ){ |
| 269 |
|
| 270 |
/* include spinner js */ |
| 271 |
$ui = $wp_scripts->query('jquery-ui-spinner'); |
| 272 |
|
| 273 |
/* make sure there's a style set */ |
| 274 |
if(!empty($wppizza_options['order_settings']['order_page_quantity_change_style'])){ |
| 275 |
$ui_style = $wppizza_options['order_settings']['order_page_quantity_change_style']; |
| 276 |
/* load a localised (gdpr) version (currently only smoothness supported) */ |
| 277 |
$isLocal = substr($ui_style, -5) == '.gdpr' ? true : false ; |
| 278 |
$cssPath = !$isLocal ? "https://code.jquery.com/ui/".$ui->ver."/themes/".$ui_style."/jquery-ui.min.css" : WPPIZZA_URL . 'css/ui/'.substr($ui_style, 0 , -5).'.css'; |
| 279 |
$cssVersion = !$isLocal ? null : WPPIZZA_VERSION; |
| 280 |
wp_enqueue_style('jquery-ui-'.$ui_style.'', $cssPath , false, $cssVersion); |
| 281 |
} |
| 282 |
|
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
include accordion css/js if enabled |
| 287 |
**/ |
| 288 |
if(!empty($wppizza_options['layout']['category_accordion']) || $is_accordion ){ |
| 289 |
/* include accordion js */ |
| 290 |
$ui = $wp_scripts->query('jquery-ui-accordion'); |
| 291 |
/* make sure there's a style set */ |
| 292 |
if(!empty($wppizza_options['layout']['category_accordion_style'])){ |
| 293 |
$ui_style = $wppizza_options['layout']['category_accordion_style']; |
| 294 |
/* load a localised (gdpr) version (currently only smoothness supported) */ |
| 295 |
$isLocal = substr($ui_style, -5) == '.gdpr' ? true : false ; |
| 296 |
$cssPath = !$isLocal ? "https://code.jquery.com/ui/".$ui->ver."/themes/".$ui_style."/jquery-ui.min.css" : WPPIZZA_URL . 'css/ui/'.substr($ui_style, 0 , -5).'.css'; |
| 297 |
$cssVersion = !$isLocal ? null : WPPIZZA_VERSION; |
| 298 |
wp_enqueue_style('jquery-ui-'.$ui_style.'', $cssPath, false, $cssVersion); |
| 299 |
} |
| 300 |
|
| 301 |
} |
| 302 |
|
| 303 |
/*************************************** |
| 304 |
* |
| 305 |
* [enqueue any global styles registered above] |
| 306 |
* |
| 307 |
***************************************/ |
| 308 |
foreach($enqueue_styles_global as $enqueue_id => $enqueue){ |
| 309 |
wp_enqueue_style($enqueue_id); |
| 310 |
} |
| 311 |
|
| 312 |
/***************************************************************************************************** |
| 313 |
* |
| 314 |
* |
| 315 |
* [register and enqueue js] |
| 316 |
* |
| 317 |
* |
| 318 |
******************************************************************************************************/ |
| 319 |
/*main js**/ |
| 320 |
$js_filename = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG === true ) ? 'scripts.source.js' : 'scripts.min.js' ; |
| 321 |
$js_enqueue_ident=''.WPPIZZA_SLUG.''; |
| 322 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/'.$js_filename , array('jquery'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 323 |
|
| 324 |
/*validation - order page , login form user order history, or if filter returns true*/ |
| 325 |
$enqueue_validation = apply_filters('wppizza_filter_enqueue_validation', false); |
| 326 |
if( $is_orderpage || $is_orderhistory || !empty($enqueue_validation) ){ |
| 327 |
|
| 328 |
/* |
| 329 |
validation |
| 330 |
*/ |
| 331 |
$js_filename = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG === true ) ? 'jquery.validate.js' : 'jquery.validate.min.js' ; |
| 332 |
$js_enqueue_ident=''.WPPIZZA_SLUG.'-validate'; |
| 333 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/validate/'.$js_filename , array(WPPIZZA_SLUG), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 334 |
|
| 335 |
|
| 336 |
/* |
| 337 |
validation methods |
| 338 |
*/ |
| 339 |
$js_filename = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG === true ) ? 'additional-methods.js' : 'additional-methods.min.js' ; |
| 340 |
$js_enqueue_ident=''.WPPIZZA_SLUG.'-validate-methods'; |
| 341 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/validate/'.$js_filename , array(WPPIZZA_SLUG.'-validate'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 342 |
|
| 343 |
|
| 344 |
/* |
| 345 |
validation lang/locale - if supported |
| 346 |
*/ |
| 347 |
$locale = get_locale(); |
| 348 |
$locale_short = substr($locale, 0, 2); |
| 349 |
|
| 350 |
// messages - full lang |
| 351 |
if(file_exists( WPPIZZA_PATH . '/js/validate/lng/messages_'.$locale.'.min.js')){ |
| 352 |
$js_filename = 'messages_'.$locale.'.min.js' ; |
| 353 |
$js_enqueue_ident=''.WPPIZZA_SLUG.'-validate-lng'; |
| 354 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/validate/lng/'.$js_filename , array(WPPIZZA_SLUG.'-validate'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 355 |
} |
| 356 |
// messages - main|short lang |
| 357 |
else if(file_exists( WPPIZZA_PATH . '/js/validate/lng/messages_'.$locale_short.'.min.js')){ |
| 358 |
$js_filename = 'messages_'.$locale_short.'.min.js' ; |
| 359 |
$js_enqueue_ident=''.WPPIZZA_SLUG.'-validate-lng'; |
| 360 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/validate/lng/'.$js_filename , array(WPPIZZA_SLUG.'-validate'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 361 |
} |
| 362 |
|
| 363 |
// methods - full lang |
| 364 |
if(file_exists( WPPIZZA_PATH . '/js/validate/lng/methods_'.$locale.'.min.js')){ |
| 365 |
$js_filename = 'methods_'.$locale.'.min.js' ; |
| 366 |
$js_enqueue_ident=''.WPPIZZA_SLUG.'-validate-methods-lng'; |
| 367 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/validate/lng/'.$js_filename , array(WPPIZZA_SLUG.'-validate-methods'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 368 |
} |
| 369 |
// methods - main|short lang |
| 370 |
else if(file_exists( WPPIZZA_PATH . '/js/validate/lng/methods_'.$locale_short.'.min.js')){ |
| 371 |
$js_filename = 'methods_'.$locale_short.'.min.js' ; |
| 372 |
$js_enqueue_ident=''.WPPIZZA_SLUG.'-validate-methods-lng'; |
| 373 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/validate/lng/'.$js_filename , array(WPPIZZA_SLUG.'-validate-methods'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
} |
| 378 |
|
| 379 |
/**include spinner js on orderpage if enabled**/ |
| 380 |
if($wppizza_options['order_settings']['order_page_quantity_change'] && ( $is_orderpage || $force_script_style_inclusion ) ){ |
| 381 |
$js_enqueue["jquery-ui-spinner"] = "jquery-ui-spinner"; |
| 382 |
} |
| 383 |
/**include spinner if cart increase by input is enabled **/ |
| 384 |
if(!empty($wppizza_options['order_settings']['cart_increase'])){ |
| 385 |
$js_enqueue["jquery-ui-spinner"] = "jquery-ui-spinner"; |
| 386 |
} |
| 387 |
|
| 388 |
/**include accordion if category as accordions is enabled **/ |
| 389 |
if(!empty($wppizza_options['layout']['category_accordion']) || $is_accordion ){ |
| 390 |
$js_enqueue["jquery-ui-accordion"] = "jquery-ui-accordion"; |
| 391 |
} |
| 392 |
|
| 393 |
/**pretty photo**/ |
| 394 |
if($wppizza_options['layout']['prettyPhoto']){ |
| 395 |
$js_filename='jquery.prettyPhoto.js'; |
| 396 |
$js_enqueue_ident=''.WPPIZZA_SLUG.'-prettyphoto'; |
| 397 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/'.$js_filename , array('jquery'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 398 |
|
| 399 |
/*custom pretty photo*/ |
| 400 |
$js_filename='jquery.prettyPhoto.custom.js'; |
| 401 |
$js_enqueue_ident=''.WPPIZZA_SLUG.'-ppCustom'; |
| 402 |
|
| 403 |
/**copy js to template directory to edit settings (theme etc)**/ |
| 404 |
if (file_exists( WPPIZZA_TEMPLATE_DIR . '/js/'.$js_filename.'')){ |
| 405 |
$js_enqueue[$js_enqueue_ident] = wp_register_style($js_enqueue_ident, WPPIZZA_TEMPLATE_URI.'/js/'.$js_filename, array('jquery'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 406 |
}else{ |
| 407 |
$js_enqueue[$js_enqueue_ident] = wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/'.$js_filename, array('jquery'), WPPIZZA_VERSION, apply_filters('wppizza_filter_js_in_footer', false)); |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
/*************************************** |
| 413 |
* |
| 414 |
* [enqueue any scripts registered above] |
| 415 |
* |
| 416 |
***************************************/ |
| 417 |
foreach($js_enqueue as $enqueue_id => $enqueue){ |
| 418 |
wp_enqueue_script($enqueue_id); |
| 419 |
} |
| 420 |
|
| 421 |
/***************************************************************************************************** |
| 422 |
* |
| 423 |
* |
| 424 |
* [localize js variables] |
| 425 |
* |
| 426 |
* |
| 427 |
******************************************************************************************************/ |
| 428 |
$localize = array(); |
| 429 |
|
| 430 |
/***************************** |
| 431 |
|
| 432 |
ajax url |
| 433 |
|
| 434 |
*****************************/ |
| 435 |
/**in case force_ssl_admin is set */ |
| 436 |
$ajaxUrl = admin_url('admin-ajax.php'); |
| 437 |
if ( force_ssl_admin() && !is_ssl() ) { |
| 438 |
$ajaxUrl = set_url_scheme($ajaxUrl, 'http'); |
| 439 |
} |
| 440 |
/* |
| 441 |
add to localized script |
| 442 |
*/ |
| 443 |
$localize['ajaxurl'] = $ajaxUrl; |
| 444 |
|
| 445 |
/***************************** |
| 446 |
add timestamp (let's us more easily verify |
| 447 |
if pages are cached, even if no identification |
| 448 |
of any caching is shown by some server setups |
| 449 |
and check timezones |
| 450 |
*****************************/ |
| 451 |
$localize['ts']['utc'] = WPPIZZA_UTC_TIME; |
| 452 |
$localize['ts']['loc'] = WPPIZZA_WP_TIME; |
| 453 |
$localize['ts']['os'] = ( WPPIZZA_UTC_OFFSET / 60 ) ; |
| 454 |
|
| 455 |
/***************************** |
| 456 |
set locale |
| 457 |
*****************************/ |
| 458 |
$localize['locale'] = array( |
| 459 |
WPPIZZA_LANGUAGE_CODE, |
| 460 |
WPPIZZA_LANGUAGE_CODE_2LTR, |
| 461 |
); |
| 462 |
|
| 463 |
/***************************** |
| 464 |
currency symbols/iso |
| 465 |
*****************************/ |
| 466 |
$localize['curr'] = array( |
| 467 |
's' => $wppizza_options['order_settings']['currency_symbol'], |
| 468 |
'iso' =>$wppizza_options['order_settings']['currency'], |
| 469 |
'pos' =>$wppizza_options['prices_format']['currency_symbol_position'], |
| 470 |
'spc' =>$wppizza_options['prices_format']['currency_symbol_spacing'], |
| 471 |
'dec' =>( defined('WPPIZZA_DECIMALS') ? (int)WPPIZZA_DECIMALS : (empty($wppizza_options['prices_format']['hide_decimals']) ? 2 : 0 )), |
| 472 |
); |
| 473 |
|
| 474 |
/***************************** |
| 475 |
set current blog id |
| 476 |
*****************************/ |
| 477 |
$localize['blog'] = $blog_id; |
| 478 |
|
| 479 |
/***************************** |
| 480 |
set current page/post id |
| 481 |
*****************************/ |
| 482 |
if(!empty($post->ID)){ |
| 483 |
$localize['pid'] = $post->ID; |
| 484 |
} |
| 485 |
//if $post->ID is empty (ajax calls) , lets try and take it from posted vars |
| 486 |
if(!isset($localize['pid']) && !empty($_POST['pid']) && is_numeric($_POST['pid'])){ |
| 487 |
$localize['pid'] = (int)$_POST['pid']; |
| 488 |
} |
| 489 |
/***************************** |
| 490 |
|
| 491 |
set flag to indicate we are on checkout page |
| 492 |
to not do any redirection for example |
| 493 |
*****************************/ |
| 494 |
if($is_orderpage){ |
| 495 |
|
| 496 |
/* |
| 497 |
flag we are on checkout page |
| 498 |
*/ |
| 499 |
|
| 500 |
$localize['isCheckout'] = 1; |
| 501 |
/* |
| 502 |
set flag to recalc on gateway change due to discounts or surcharges set |
| 503 |
- orderpage only |
| 504 |
*/ |
| 505 |
if(!empty(WPPIZZA()->gateways->must_recalculate)){ |
| 506 |
$localize['reCalc'] = 1; |
| 507 |
} |
| 508 |
|
| 509 |
} |
| 510 |
/***************************** |
| 511 |
set flag to indicate we are on thankyou page |
| 512 |
i.e an order was completed |
| 513 |
*****************************/ |
| 514 |
if(wppizza_is_thankyoupage()){ |
| 515 |
$localize['orderCompleted'] = 1; |
| 516 |
} |
| 517 |
|
| 518 |
/***************************** |
| 519 |
|
| 520 |
various alert messages |
| 521 |
|
| 522 |
*****************************/ |
| 523 |
$messages['closed']=''.$wppizza_options['localization']['alert_closed'].''; |
| 524 |
if($wppizza_options['layout']['add_to_cart_on_title_click']){ |
| 525 |
$messages['choosesize']=''.$wppizza_options['localization']['alert_choose_size'].''; |
| 526 |
} |
| 527 |
/* if delivery default */ |
| 528 |
if($wppizza_options['order_settings']['order_pickup'] && $wppizza_options['order_settings']['order_pickup_alert'] && empty($wppizza_options['order_settings']['order_pickup_as_default']) ){ |
| 529 |
$messages['pickup']=''.sprintf($wppizza_options['localization']['order_self_pickup_cartjs'], $wppizza_options['order_settings']['order_pickup_preparation_time']).''; |
| 530 |
} |
| 531 |
/* if pickup default (overrides above)*/ |
| 532 |
if($wppizza_options['order_settings']['order_pickup'] && $wppizza_options['order_settings']['order_pickup_alert'] && !empty($wppizza_options['order_settings']['order_pickup_as_default']) ){ |
| 533 |
$messages['pickup']=''.sprintf($wppizza_options['localization']['order_delivery_cartjs'], $wppizza_options['order_settings']['order_delivery_time']).''; |
| 534 |
} |
| 535 |
/* |
| 536 |
decode, escape, add messages |
| 537 |
to localized script |
| 538 |
*/ |
| 539 |
foreach($messages as $jsmKey => $jsMessage){ |
| 540 |
$messages[$jsmKey] = wppizza_decode_entities($jsMessage); |
| 541 |
} |
| 542 |
$localize['msg'] = $messages; |
| 543 |
|
| 544 |
/* |
| 545 |
localize cart |
| 546 |
*/ |
| 547 |
$localize['crt'] = array(); |
| 548 |
|
| 549 |
/***************************** |
| 550 |
before cart refresh function |
| 551 |
filterable individually! |
| 552 |
add functions (names) to run before cart is being updated |
| 553 |
*****************************/ |
| 554 |
$funcBeforeCartRefr = array(); |
| 555 |
$funcBeforeCartRefr[]='wppizzaTotalsBefore'; |
| 556 |
$funcBeforeCartRefr = apply_filters('wppizza_filter_js_before_cart_refresh_functions', $funcBeforeCartRefr); |
| 557 |
$funcBeforeCartRefr = array_keys(array_flip($funcBeforeCartRefr));/*flip to make unique, keys to just get the function name to sanitise things*/ |
| 558 |
/* |
| 559 |
add to localized script |
| 560 |
*/ |
| 561 |
$localize['funcBeforeCartRefr'] = $funcBeforeCartRefr; |
| 562 |
|
| 563 |
/***************************** |
| 564 |
filterable individually! |
| 565 |
add functions (names) to run |
| 566 |
on shop status init(pageload) and change |
| 567 |
*****************************/ |
| 568 |
$funcSetStatus = array(); |
| 569 |
$funcSetStatus = apply_filters('wppizza_filter_js_set_status_functions', $funcSetStatus); |
| 570 |
$funcSetStatus = array_keys(array_flip($funcSetStatus));/*flip to make unique, keys to just get the function name to sanitise things*/ |
| 571 |
/* |
| 572 |
add to localized script if not empty |
| 573 |
*/ |
| 574 |
if(!empty($funcSetStatus)){ |
| 575 |
$localize['funcSetSts'] = $funcSetStatus; |
| 576 |
} |
| 577 |
|
| 578 |
/***************************** |
| 579 |
cart refresh function |
| 580 |
filterable individually! |
| 581 |
add functions (names) to run when cart has been updated |
| 582 |
*****************************/ |
| 583 |
$funcCartRefr = array(); |
| 584 |
$funcCartRefr[]='wppizzaTotals'; |
| 585 |
$funcCartRefr = apply_filters('wppizza_filter_js_cart_refresh_functions', $funcCartRefr); |
| 586 |
$funcCartRefr = array_keys(array_flip($funcCartRefr));/*flip to make unique, keys to just get the function name to sanitise things*/ |
| 587 |
/* |
| 588 |
add to localized script |
| 589 |
*/ |
| 590 |
$localize['funcCartRefr'] = $funcCartRefr; |
| 591 |
|
| 592 |
/***************************** |
| 593 |
order status changed functions |
| 594 |
filterable individually! |
| 595 |
add functions (names) to run when an order status was updated |
| 596 |
(can be used when adding order history via shortcode ) |
| 597 |
*****************************/ |
| 598 |
$funcStatusChanged = array(); |
| 599 |
$funcStatusChanged = apply_filters('wppizza_filter_admin_js_status_changed_function', $funcStatusChanged); |
| 600 |
$funcStatusChanged = array_keys(array_flip($funcStatusChanged));/*flip to make unique, keys to just get the function name to sanitise things*/ |
| 601 |
/* |
| 602 |
add to localized script if not empty |
| 603 |
*/ |
| 604 |
if(!empty($funcStatusChanged)){ |
| 605 |
$localize['fnOrderStatusChange'] = $funcStatusChanged; |
| 606 |
} |
| 607 |
|
| 608 |
/***************************** |
| 609 |
before order submit |
| 610 |
add functions (names) to run just before an order gets submitted |
| 611 |
(i.e right after the "buy now" button was clicked but before anything else happens) |
| 612 |
*****************************/ |
| 613 |
$fnBeforeOrderSubmit = array(); |
| 614 |
$fnBeforeOrderSubmit = apply_filters('wppizza_filter_js_before_order_submit', $fnBeforeOrderSubmit); |
| 615 |
$fnBeforeOrderSubmit = array_keys(array_flip($fnBeforeOrderSubmit));/*flip to make unique, keys to just get the function name to sanitise things*/ |
| 616 |
/* |
| 617 |
add to localized script if not empty |
| 618 |
*/ |
| 619 |
if(!empty($fnBeforeOrderSubmit)){ |
| 620 |
$localize['fnBeforeOrderSubmit'] = $fnBeforeOrderSubmit; |
| 621 |
} |
| 622 |
|
| 623 |
/***************************** |
| 624 |
an (better) alternative to "fnBeforeOrderSubmit" above. |
| 625 |
sets a flag to run an one ajax request that calls |
| 626 |
"wppizza_verify_before_submit" we can hook into serverside |
| 627 |
instead of running multiple ajax request |
| 628 |
(i.e right after the "buy now" button was clicked but before anything else happens) |
| 629 |
*****************************/ |
| 630 |
$fnVerifyOnOrderSubmit = apply_filters('wppizza_filter_js_verify_on_order_submit', false); |
| 631 |
/* |
| 632 |
add to localized script if not empty |
| 633 |
*/ |
| 634 |
if(!empty($fnVerifyOnOrderSubmit)){ |
| 635 |
$localize['fnVerifyOnOrderSubmit'] = 1; |
| 636 |
} |
| 637 |
|
| 638 |
/***************************** |
| 639 |
|
| 640 |
various localized options |
| 641 |
alert or confirm when changing from pickup to delivery (or vice versa) |
| 642 |
*****************************/ |
| 643 |
if($wppizza_options['order_settings']['order_pickup'] && $wppizza_options['order_settings']['order_pickup_alert']){ |
| 644 |
$localized_options['puAlrt'] = empty($wppizza_options['order_settings']['order_pickup_alert_confirm']) ? 1 : 2 ; |
| 645 |
} |
| 646 |
/** default to pickup ? */ |
| 647 |
if(!empty($wppizza_options['order_settings']['order_pickup_as_default'])){ |
| 648 |
$localized_options['puDef'] = 1; |
| 649 |
} |
| 650 |
/* |
| 651 |
add to localized script |
| 652 |
*/ |
| 653 |
if(!empty($localized_options)){ |
| 654 |
$localize['opt']=$localized_options; |
| 655 |
} |
| 656 |
|
| 657 |
/***************************** |
| 658 |
|
| 659 |
other miscellaneous |
| 660 |
localized options |
| 661 |
|
| 662 |
*****************************/ |
| 663 |
$miscOptions = array(); |
| 664 |
|
| 665 |
/**are we using a cache plugin ?**/ |
| 666 |
if(apply_filters('wppizza_filter_using_cache_plugin', false)){ |
| 667 |
$miscOptions['usingCache']=1; |
| 668 |
} |
| 669 |
|
| 670 |
/**are we using a confirmation form too ?**/ |
| 671 |
if(!empty($wppizza_options['confirmation_form']['confirmation_form_enabled'])){ |
| 672 |
$miscOptions['cfrm']=1; |
| 673 |
} |
| 674 |
|
| 675 |
/** quantity change in cart or enabled **/ |
| 676 |
if(!empty($wppizza_options['order_settings']['cart_increase']) ){ |
| 677 |
$miscOptions['ofqc']=1; |
| 678 |
} |
| 679 |
/**do we want to be able to still change quantities on order page**/ |
| 680 |
if($wppizza_options['order_settings']['order_page_quantity_change'] && ( $is_orderpage || $force_script_style_inclusion ) ){ |
| 681 |
$miscOptions['ofqc']=1; |
| 682 |
} |
| 683 |
|
| 684 |
/** admin order polling time **/ |
| 685 |
$miscOptions['aopt'] = $wppizza_options['settings']['admin_order_history_polling_time'] ; |
| 686 |
|
| 687 |
/** forceing pickup toggle to be visible when closed should also bypass js isOpen check when toggeling**/ |
| 688 |
$force_pickup_toggle = apply_filters('wppizza_filter_force_pickup_toggle_display', false); |
| 689 |
if(!empty($force_pickup_toggle)){ |
| 690 |
$miscOptions['fpt'] = 1 ; |
| 691 |
} |
| 692 |
|
| 693 |
/** feedback add to cart**/ |
| 694 |
if($wppizza_options['layout']['jquery_fb_add_to_cart']!=''){ |
| 695 |
$miscOptions['itm']['fbatc'] = html_entity_decode($wppizza_options['localization']['jquery_fb_add_to_cart_info']); |
| 696 |
$miscOptions['itm']['fbatcms'] = $wppizza_options['layout']['jquery_fb_add_to_cart_ms']; |
| 697 |
} |
| 698 |
|
| 699 |
/**prettify js alerts localization strings**/ |
| 700 |
if(!empty($wppizza_options['layout']['prettify_js_alerts'])){ |
| 701 |
$miscOptions['pjsa'] = array(); |
| 702 |
$miscOptions['pjsa']['h1'] = get_bloginfo( 'name' ); |
| 703 |
$miscOptions['pjsa']['ok'] = __('OK', 'default' ); |
| 704 |
} |
| 705 |
|
| 706 |
/**pretty photo style - if enabled **/ |
| 707 |
if(!empty($wppizza_options['layout']['prettyPhoto'])){ |
| 708 |
$miscOptions['pp']['s'] = $wppizza_options['layout']['prettyPhotoStyle']; |
| 709 |
} |
| 710 |
|
| 711 |
/**accordion options - if enabled **/ |
| 712 |
if(!empty($wppizza_options['layout']['category_accordion']) || $is_accordion ){ |
| 713 |
$miscOptions['acc'] = array( |
| 714 |
'elm' => '.'.WPPIZZA_SLUG.'_accordion',//target element |
| 715 |
'opt' => array( |
| 716 |
'collapsible' => true, |
| 717 |
'active' => 0, |
| 718 |
'animate' => 200, |
| 719 |
'heightStyle'=> 'content', |
| 720 |
), |
| 721 |
); |
| 722 |
} |
| 723 |
|
| 724 |
/* |
| 725 |
add (merge) miscellaneous options to localized script |
| 726 |
*/ |
| 727 |
$localize = array_merge($localize, $miscOptions); |
| 728 |
|
| 729 |
/***************************** |
| 730 |
allow adding of veriables for |
| 731 |
extending plugins |
| 732 |
filterable individually! |
| 733 |
*****************************/ |
| 734 |
$jsExtend = array(); |
| 735 |
$jsExtend = apply_filters('wppizza_filter_js_extend', $jsExtend, $localize); |
| 736 |
/* |
| 737 |
add to localized script |
| 738 |
*/ |
| 739 |
$localize['extend'] = $jsExtend; |
| 740 |
|
| 741 |
|
| 742 |
/***************************** |
| 743 |
allow fitering |
| 744 |
of all |
| 745 |
localized js |
| 746 |
variables |
| 747 |
*****************************/ |
| 748 |
$localize = apply_filters('wppizza_filter_js_localize', $localize); |
| 749 |
|
| 750 |
|
| 751 |
/***************************** |
| 752 |
allow fitering of selected gateway |
| 753 |
localized js on checkout and if shop is open and cart is not empty anyway |
| 754 |
and not thankyou or cancel page |
| 755 |
@since 3.7 |
| 756 |
*****************************/ |
| 757 |
if(( wppizza_is_checkout() && wppizza_is_shop_open() && !wppizza_cart_is_empty() && !wppizza_is_cancelpage() && !wppizza_is_thankyoupage() ) || $apply_gateway_localized_js_parameters ){ |
| 758 |
$selected_gateway_ident = strtolower(wppizza_selected_gateway()); |
| 759 |
$localize = apply_filters('wppizza_gateways_inline_localize_'.$selected_gateway_ident.'', $localize, $selected_gateway_ident); |
| 760 |
} |
| 761 |
|
| 762 |
/* |
| 763 |
EXCLUSIONS |
| 764 |
remove all |
| 765 |
- funcCartRefr(esh), |
| 766 |
- funcBeforeCartRefr(esh) and |
| 767 |
- fnBeforeOrderSubmit |
| 768 |
on cancel or thank you page (as there's no cart that is going to be refreshed, submitted) |
| 769 |
*/ |
| 770 |
if(wppizza_is_cancelpage() || wppizza_is_thankyoupage()){ |
| 771 |
$localize['funcBeforeCartRefr'] = array(); |
| 772 |
$localize['funcCartRefr'] = array(); |
| 773 |
$localize['fnBeforeOrderSubmit'] = array(); |
| 774 |
} |
| 775 |
|
| 776 |
/***************************************************************************** |
| 777 |
|
| 778 |
|
| 779 |
localize it all |
| 780 |
|
| 781 |
|
| 782 |
*****************************************************************************/ |
| 783 |
wp_localize_script( WPPIZZA_SLUG, WPPIZZA_SLUG, $localize ); |
| 784 |
|
| 785 |
} |
| 786 |
|
| 787 |
} |
| 788 |
/*************************************************************** |
| 789 |
* |
| 790 |
* [ini] |
| 791 |
* |
| 792 |
***************************************************************/ |
| 793 |
$WPPIZZA_SCRIPTS_AND_STYLES = new WPPIZZA_SCRIPTS_AND_STYLES(); |
| 794 |
?> |