forked from impleCode/ecommerce-product-catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates.php
633 lines (567 loc) · 33.1 KB
/
templates.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
<?php
if ( !defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* WP Product template manager
*
* Here all plugin templates are defined.
*
* @version 1.1.2
* @package ecommerce-product-catalog/
* @author Norbert Dreszer
*/
require_once(AL_BASE_PATH . '/templates/templates-functions.php');
if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
require_once(AL_BASE_PATH . '/templates/templates-woo-functions.php');
}
add_action( 'after_setup_theme', 'initialize_product_adder_template', 11 );
/**
* Includes correct template file
*
*/
function initialize_product_adder_template() {
$theme = get_option( 'template' );
$woothemes = array( "canvas", "woo", "al" );
$twentyeleven = array( "twentyeleven" );
$twentyten = array( "twentyten" );
$twentythirteen = array( "twentythirteen" );
$twentyfourteen = array( "twentyfourteen" );
$twentyfifteen = array( "twentyfifteen" );
$twentysixteen = array( "twentysixteen" );
$twentyseventeen = array( "twentyseventeen" );
$third_party = array( "storefront" );
$generic_content = array( "headway" );
if ( is_integraton_file_active() ) {
add_filter( 'template_include', 'al_product_adder_template' );
} else if ( in_array( $theme, $woothemes ) ) {
add_filter( 'template_include', 'al_product_adder_woo_template' );
} else if ( in_array( $theme, $third_party ) ) {
add_filter( 'template_include', 'al_product_adder_third_party_templates' );
} else if ( in_array( $theme, $twentyeleven ) ) {
add_filter( 'template_include', 'al_product_adder_twentyeleven_template' );
} else if ( in_array( $theme, $twentyten ) ) {
add_filter( 'template_include', 'al_product_adder_twentyten_template' );
} else if ( in_array( $theme, $twentythirteen ) ) {
add_filter( 'template_include', 'al_product_adder_twentythirteen_template' );
} else if ( in_array( $theme, $twentyfourteen ) ) {
add_filter( 'template_include', 'al_product_adder_twentyfourteen_template' );
} else if ( in_array( $theme, $twentyfifteen ) ) {
add_filter( 'template_include', 'al_product_adder_twentyfifteen_template' );
} else if ( in_array( $theme, $twentysixteen ) ) {
add_filter( 'template_include', 'al_product_adder_twentysixteen_template' );
} else if ( in_array( $theme, $twentyseventeen ) ) {
add_filter( 'template_include', 'al_product_adder_twentyseventeen_template' );
} else if ( in_array( $theme, $generic_content ) ) {
add_filter( 'template_include', 'al_product_enable_generic_content' );
} else if ( get_integration_type() == 'simple' && file_exists( get_page_php_path() ) ) {
add_filter( 'template_include', 'al_product_adder_page_template' );
} else if ( is_integraton_file_active( true ) && ic_is_woo_template_available() ) {
add_filter( 'template_include', 'al_product_auto_adder_template' );
} else if ( ic_is_woo_template_available() ) {
add_filter( 'template_include', 'al_product_woo_adder_template' );
} else {
add_filter( 'template_include', 'al_product_adder_custom_template' );
}
}
add_action( 'wp', 'ic_setup_postdata' );
/**
* Postdata setup for product pages
*
* @global type $post
*/
function ic_setup_postdata() {
if ( is_ic_catalog_page() ) {
global $post;
setup_postdata( $post );
}
}
function al_product_adder_template( $template ) {
if ( is_ic_catalog_page() ) {
return get_product_adder_path();
}
return $template;
}
function al_product_auto_adder_template( $template ) {
if ( is_ic_catalog_page() ) {
return get_product_adder_path( true );
}
return $template;
}
function al_product_adder_custom_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/product-adder.php';
}
return $template;
}
function al_product_woo_adder_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/product-woo-adder.php';
}
return $template;
}
// templates from woothemes
function al_product_adder_woo_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/third-party/product-woo-adder.php';
}
return $template;
}
function al_product_adder_third_party_templates( $template ) {
if ( is_ic_catalog_page() ) {
$theme = get_option( 'template' );
return dirname( __FILE__ ) . '/templates/third-party/' . $theme . '.php';
}
return $template;
}
// no sidebar on content page
function al_product_adder_twentyeleven_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/twenty/product-twentyeleven-adder.php';
}
return $template;
}
// twentyten - primary replaced by container id
function al_product_adder_twentyten_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/twenty/product-twentyten-adder.php';
}
return $template;
}
function al_product_adder_twentythirteen_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/twenty/product-twentythirteen-adder.php';
}
return $template;
}
function al_product_adder_twentyfourteen_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/twenty/product-twentyfourteen-adder.php';
}
return $template;
}
function al_product_adder_twentyfifteen_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/twenty/product-twentyfifteen-adder.php';
}
return $template;
}
function al_product_adder_twentysixteen_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/twenty/product-twentysixteen-adder.php';
}
return $template;
}
function al_product_adder_twentyseventeen_template( $template ) {
if ( is_ic_catalog_page() ) {
return dirname( __FILE__ ) . '/templates/twenty/product-twentyseventeen-adder.php';
}
return $template;
}
function al_product_enable_generic_content( $template ) {
if ( is_ic_catalog_page() ) {
add_action( 'generic_content', 'content_product_adder' );
}
return $template;
}
function al_product_adder_page_template( $template ) {
if ( is_ic_catalog_page() ) {
if ( is_archive() || is_search() || is_tax() ) {
$product_archive = get_product_listing_id();
if ( !empty( $product_archive ) && get_integration_type() != 'simple' ) {
wp_redirect( get_permalink( $product_archive ) );
exit;
}
} else {
return get_page_php_path();
}
}
return $template;
}
add_filter( "the_content", "product_page_content" );
function product_page_content( $content ) {
if ( is_main_query() && in_the_loop() && is_ic_product_page() && get_integration_type() == 'simple' ) {
remove_filter( "the_content", "product_page_content" );
ob_start();
content_product_adder();
$content = ob_get_contents();
ob_end_clean();
}
return $content;
}
add_shortcode( 'theme_integration', 'theme_integration_shortcode' );
function theme_integration_shortcode( $atts ) {
}
add_action( 'wp_footer', 'theme_integration_wizard' );
/**
* Shows theme intagration wizard
*
* @param type $atts
*/
function theme_integration_wizard( $atts ) {
$current_mode = get_real_integration_mode();
if ( is_ic_integration_wizard_page() ) {
$args = shortcode_atts( array(
'class' => 'fixed-box',
), $atts );
$class = esc_attr( $args[ 'class' ] );
$box_content = '<h4>' . __( 'Catalog Configuration', 'ecommerce-product-catalog' ) . '</h4>';
/* $box_content .= '<script>jQuery(window).scroll( function() { if (isScrolledIntoView(".relative-box")) {jQuery(".fixed-box").hide("slow");}
else {jQuery(".fixed-box").show("slow");}});
function isScrolledIntoView(elem)
{
var docViewTop = jQuery(window).scrollTop();
var docViewBottom = docViewTop + jQuery(window).height();
var elemTop = jQuery(elem).offset().top;
var elemBottom = elemTop + jQuery(elem).height();
return ((docViewTop < elemTop) && (docViewBottom > elemBottom));
// return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}</script>'; */
if ( !isset( $_GET[ 'test_advanced' ] ) ) {
$box_content .= '<p>' . sprintf( __( '%s is currently running in Simple Mode.', 'ecommerce-product-catalog' ), IC_CATALOG_PLUGIN_NAME ) . '</p>';
$box_content .= '<p>' . __( 'In Simple Mode the product listing, product search and category pages are disabled (please read this Sample Product Page to fully understand the difference).', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p>' . __( 'Please use the button below to check out how the product page looks in Automatic Advanced Mode.', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p class="wp-core-ui"><a href="' . esc_url( add_query_arg( 'test_advanced', '1' ) ) . '" class="button-primary">' . __( 'Start Advanced Mode Test', 'ecommerce-product-catalog' ) . '</a><a href="' . esc_url( add_query_arg( 'test_advanced', 'simple' ) ) . '" class="button-secondary">' . __( 'Use Simple Mode', 'ecommerce-product-catalog' ) . '</a></p>';
if ( $current_mode == 'simple' ) {
echo '<div id="integration_wizard" class="' . $class . '">' . implecode_info( $box_content, 0 ) . '</div>';
}
} else if ( isset( $_GET[ 'test_advanced' ] ) && $_GET[ 'test_advanced' ] == 1 ) {
//$box_content .= '<style>#integration_wizard.fixed-box.opacity {opacity: 0.8;}#integration_wizard.fixed-box:hover {opacity: 1;}</style>';
$box_content .= '<p class="initial-description">' . __( 'Advanced Mode is temporary enabled for this page now.', 'ecommerce-product-catalog' ) . ' <strong>' . __( "Don't worry if it looks messy.", 'ecommerce-product-catalog' ) . '</strong> ' . __( 'Make some adjustments if necessary (you can change it at any time later).', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p class="initial-description"><strong>' . __( 'Click start to proceed with layout adjustment.', 'ecommerce-product-catalog' ) . '</strong></p>';
//$box_content .= '<p>' . __( 'Please use the buttons below to let the script know if the Automatic Advanced Integration is done right.', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p class="wp-core-ui" style="margin-top: 20px;"><button class="button-primary start_section">' . __( 'Start', 'ecommerce-product-catalog' ) . '</button></p>';
$box_content .= '<table class="styling-adjustments">';
$integration_settings = get_integration_settings();
$box_content .= '<tbody class="section_1 integration-section" style="display: none">';
$box_content .= '<tr><td colspan="2"><p style="margin-bottom: 5px">' . sprintf( __( '%1$sDecrease width%2$s to change the product page horizontal size, %1$sincrease padding%2$s to generate space around the content and %1$sset background & text colors%2$s to match your theme style', 'ecommerce-product-catalog' ), '<strong>', '</strong>' ) . ':</p></td></tr>';
$box_content .= implecode_settings_number( __( 'Width', 'ecommerce-product-catalog' ), 'container_width', $integration_settings[ 'container_width' ], '%', 0, null, __( 'In most cases you should decrease this number to match your template container size.', 'ecommerce-product-catalog' ), 0 );
$box_content .= implecode_settings_text_color( __( 'Background', 'ecommerce-product-catalog' ), 'container_bg', $integration_settings[ 'container_bg' ], null, 0, null, '{change: function(event, ui){ var hexcolor = jQuery( this ).wpColorPicker( "color" ); jQuery("#container").css("background", hexcolor); jQuery("#container").css("overflow", "hidden"); jQuery("#container").css("width", jQuery("input[name=\"container_width\"]").val()+"%");}}' );
$box_content .= implecode_settings_text_color( __( 'Text Color', 'ecommerce-product-catalog' ), 'container_text', $integration_settings[ 'container_text' ], null, 0, null, '{change: function(event, ui){ var hexcolor = jQuery( this ).wpColorPicker( "color" ); jQuery("#container *").css("color", hexcolor); }}' );
$box_content .= implecode_settings_number( __( 'Padding', 'ecommerce-product-catalog' ), 'container_padding', $integration_settings[ 'container_padding' ], 'px', 0, null, __( 'Increase this number to make a space also on the top and bottom of the container. This is useful also if you are planning to enable the sidebar in next step.', 'ecommerce-product-catalog' ), 0 );
$box_content .= '</tbody>';
if ( !defined( 'AL_SIDEBAR_BASE_URL' ) ) {
$box_content .= '<tbody class="section_2 integration-section" style="display: none">';
$box_content .= '<tr><td colspan="2"><p style="margin-bottom: 5px">' . __( 'Select the sidebar side to enable it on your product pages.', 'ecommerce-product-catalog' ) . ':</p></td></tr>';
$box_content .= implecode_settings_radio( __( 'Default Sidebar', 'ecommerce-product-catalog' ), 'default_sidebar', $integration_settings[ 'default_sidebar' ], array( 'none' => __( 'Disabled', 'ecommerce-product-catalog' ), 'left' => __( 'Left', 'ecommerce-product-catalog' ), 'right' => __( 'Right', 'ecommerce-product-catalog' ) ), 0 );
$box_content .= '<tr><td colspan="2"><p style="margin-top: 5px; margin-bottom: 5px; display: none;" class="integration-sidebar-info">' . __( 'If the sidebar is to close to the content you can go back and adjust the padding.', 'ecommerce-product-catalog' ) . '</p></td></tr>';
if ( $integration_settings[ 'default_sidebar' ] == 'none' ) {
$box_content .= '<style>#catalog_sidebar {display: none;}</style>';
}
$box_content .= '</tbody>';
}
$box_content .= '<tbody class="section_3 integration-section" style="display: none">';
$box_content .= '<tr><td colspan="2"><p style="margin-bottom: 5px">' . __( 'Disable unnecessary product page elements', 'ecommerce-product-catalog' ) . ':</p></td></tr>';
$box_content .= implecode_settings_checkbox( __( 'Disable breadcrumbs', 'ecommerce-product-catalog' ), 'disable_breadcrumbs', $integration_settings[ 'disable_breadcrumbs' ], 0 );
$box_content .= implecode_settings_checkbox( __( 'Disable Name', 'ecommerce-product-catalog' ), 'disable_name', $integration_settings[ 'disable_name' ], 0 );
$box_content .= implecode_settings_checkbox( __( 'Disable Image', 'ecommerce-product-catalog' ), 'disable_image', $integration_settings[ 'disable_image' ], 0 );
if ( function_exists( 'get_currency_settings' ) ) {
$box_content .= implecode_settings_checkbox( __( 'Disable Price', 'ecommerce-product-catalog' ), 'disable_price', $integration_settings[ 'disable_price' ], 0 );
}
if ( function_exists( 'is_ic_sku_enabled' ) ) {
$box_content .= implecode_settings_checkbox( __( 'Disable SKU', 'ecommerce-product-catalog' ), 'disable_sku', $integration_settings[ 'disable_sku' ], 0 );
}
if ( function_exists( 'is_ic_shipping_enabled' ) ) {
$box_content .= implecode_settings_checkbox( __( 'Disable Shipping', 'ecommerce-product-catalog' ), 'disable_shipping', $integration_settings[ 'disable_shipping' ], 0 );
}
if ( function_exists( 'is_ic_attributes_enabled' ) ) {
$box_content .= implecode_settings_checkbox( __( 'Disable Attributes', 'ecommerce-product-catalog' ), 'disable_attributes', $integration_settings[ 'disable_attributes' ], 0 );
}
$box_content .= '</tbody>';
$box_content .= '</table>';
$box_content .= '<style>#integration_wizard .al-box table tbody, #integration_wizard .al-box table tr, #integration_wizard .al-box table td {border: 0; background: transparent;} #integration_wizard .al-box table.styling-adjustments td {vertical-align: middle;font-size: 14px; color: rgb(136, 136, 136); text-align: left;} #integration_wizard .wp-picker-container {padding-top: 5px;}html #integration_wizard.fixed-box .al-box table input.wp-picker-clear {background: #ededed; transition: none; padding: 1px 6px; border: 1px solid #000; color: #000; margin: 0; margin-left: 6px;}#integration_wizard .wp-picker-holder{position: absolute;z-index: 99;}</style>';
$box_content .= '<div class="section_last integration-section" style="display: none">';
$box_content .= '<p>' . __( 'Is everything looking fine now?', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<style>#integration_wizard .ic_spinner{background: url(' . admin_url() . '/images/spinner.gif) no-repeat;display: inline-block;
opacity: 0.7;
width: 20px;
height: 20px;
margin-left: 2px;
vertical-align: middle;
display: none;
margin-right:3px;
margin-left: -23px;}</style>';
$box_content .= '<p class="wp-core-ui"><span class="ic_spinner"></span><a href="' . esc_url( add_query_arg( 'test_advanced', 'ok' ) ) . '" class="button-primary integration-ok">' . __( 'It\'s Fine', 'ecommerce-product-catalog' ) . '</a><a href="' . esc_url( add_query_arg( 'test_advanced', 'bad' ) ) . '" class="button-secondary">' . __( 'It\'s Broken', 'ecommerce-product-catalog' ) . '</a> <button class="button-secondary show_third switch_section">' . __( 'Go Back', 'ecommerce-product-catalog' ) . '</button></p>';
$box_content .= '</div>';
$box_content .= '<p class="wp-core-ui" style="margin-top: 20px;"><button class="button-secondary show_prev_section switch_section" style="display: none">' . __( 'Go Back', 'ecommerce-product-catalog' ) . '</button><button class="button-primary show_next_section switch_section" style="display: none">' . __( 'Next', 'ecommerce-product-catalog' ) . '</button></p>';
echo '<div id="integration_wizard" class="integration_start ' . $class . '">' . implecode_info( $box_content, 0 ) . '</div>';
} else if ( isset( $_GET[ 'test_advanced' ] ) && $_GET[ 'test_advanced' ] == 'bad' ) {
$box_content .= '<p>' . __( 'It seems that Manual Theme Integration is needed in order to use Advanced Mode with your current theme.', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<h4>' . __( 'You Have 3 choices', 'ecommerce-product-catalog' ) . ':</h4>';
$box_content .= '<ol>';
$box_content .= '<li>' . __( 'Get the Manual Theme Integration done.', 'ecommerce-product-catalog' ) . '</li>';
$box_content .= '<li>' . __( 'Keep using Simple Mode which is still functional.', 'ecommerce-product-catalog' ) . '</li>';
$box_content .= '<li>' . __( 'Switch the theme.', 'ecommerce-product-catalog' ) . '</li>';
$box_content .= '</ol>';
$box_content .= '<p>' . __( 'Please make your choice below or switch the theme.', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p class="wp-core-ui"><a target="_blank" href="https://implecode.com/wordpress/product-catalog/theme-integration-guide/#cam=simple-mode&key=integration-advanced-fail" class="button-primary">' . __( 'Free Theme Integration Guide', 'ecommerce-product-catalog' ) . '</a><a href="' . esc_url( add_query_arg( 'test_advanced', 'simple' ) ) . '" class="button-secondary">' . __( 'Use Simple Mode', 'ecommerce-product-catalog' ) . '</a></p>';
enable_simple_mode();
echo '<div id="integration_wizard" class="' . $class . '">' . implecode_warning( $box_content, 0 ) . '</div>';
} else if ( isset( $_GET[ 'test_advanced' ] ) && $_GET[ 'test_advanced' ] == 'ok' ) {
$box_content .= '<p>' . sprintf( __( 'Congratulations! %s is working on Advanced Mode now. You can go to admin and add the products to the catalog.', 'ecommerce-product-catalog' ), IC_CATALOG_PLUGIN_NAME ) . '</p>';
$box_content .= '<p>' . sprintf( __( 'If you are a developer or would like to have full control on the product pages templates make sure to see the %stemplates docs%s.', 'ecommerce-product-catalog' ), '<a href="https://implecode.com/docs/ecommerce-product-catalog/product-page-template/">', '</a>' ) . '</p>';
//$box_content .= '<p>' . __( 'You can switch between modes at any time in Product Settings.', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p class="wp-core-ui"><a href="' . admin_url( 'edit.php?post_type=al_product' ) . '" class="button-primary">' . __( 'Go to Admin', 'ecommerce-product-catalog' ) . '</a>';
//$box_content .= '<a target="_blank" href="https://implecode.com/wordpress/product-catalog/theme-integration-guide/#cam=advanced-mode&key=integration-advanced-success" class="button-secondary">' . __( 'Free Theme Integration Guide', 'ecommerce-product-catalog' ) . '</a>';
$box_content .= '</p>';
enable_advanced_mode();
echo '<div id="integration_wizard" class="' . $class . '">' . implecode_success( $box_content, 0 ) . '</div>';
} else if ( isset( $_GET[ 'test_advanced' ] ) && $_GET[ 'test_advanced' ] == 'simple' ) {
$box_content .= '<p>' . __( 'You are using simple mode now.', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p>' . __( 'You can switch between modes at any time in Product Settings.', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p>' . __( 'Use the buttons below to try the advanced integration again or go to admin and start adding your products.', 'ecommerce-product-catalog' ) . '</p>';
$box_content .= '<p class="wp-core-ui"><a href="' . admin_url( 'edit.php?post_type=al_product' ) . '" class="button-primary">' . __( 'Go to Admin', 'ecommerce-product-catalog' ) . '</a><a href="' . esc_url( add_query_arg( 'test_advanced', '1' ) ) . '" class="button-secondary">' . __( 'Restart Advanced Mode Test', 'ecommerce-product-catalog' ) . '</a></p>';
enable_simple_mode();
echo '<div id="integration_wizard" class="' . $class . '">' . implecode_success( $box_content, 0 ) . '</div>';
}
}
}
/**
* Returns wizard advanced mode settings
* @return array
*/
function get_integration_settings() {
$archive_multiple_settings = get_multiple_settings();
$theme = get_option( 'template' );
$settings[ 'container_width' ] = isset( $archive_multiple_settings[ 'container_width' ][ $theme ] ) ? $archive_multiple_settings[ 'container_width' ][ $theme ] : 100;
$settings[ 'container_bg' ] = isset( $archive_multiple_settings[ 'container_bg' ][ $theme ] ) ? $archive_multiple_settings[ 'container_bg' ][ $theme ] : '';
$settings[ 'container_padding' ] = isset( $archive_multiple_settings[ 'container_padding' ][ $theme ] ) ? $archive_multiple_settings[ 'container_padding' ][ $theme ] : 0;
$settings[ 'container_text' ] = isset( $archive_multiple_settings[ 'container_text' ][ $theme ] ) ? $archive_multiple_settings[ 'container_text' ][ $theme ] : '';
$settings[ 'disable_breadcrumbs' ] = isset( $archive_multiple_settings[ 'enable_product_breadcrumbs' ] ) && $archive_multiple_settings[ 'enable_product_breadcrumbs' ] == 1 ? 0 : 1;
$settings[ 'disable_name' ] = isset( $archive_multiple_settings[ 'disable_name' ] ) ? $archive_multiple_settings[ 'disable_name' ] : 0;
$settings[ 'disable_image' ] = is_ic_product_gallery_enabled() ? 0 : 1;
$settings[ 'disable_price' ] = function_exists( 'is_ic_price_enabled' ) && is_ic_price_enabled() ? 0 : 1;
$settings[ 'disable_sku' ] = function_exists( 'is_ic_sku_enabled' ) && is_ic_sku_enabled() ? 0 : 1;
$settings[ 'disable_shipping' ] = function_exists( 'is_ic_shipping_enabled' ) && is_ic_shipping_enabled() ? 0 : 1;
$settings[ 'disable_attributes' ] = function_exists( 'is_ic_attributes_enabled' ) && is_ic_attributes_enabled() ? 0 : 1;
$settings[ 'default_sidebar' ] = isset( $archive_multiple_settings[ 'default_sidebar' ] ) ? $archive_multiple_settings[ 'default_sidebar' ] : 'none';
return $settings;
}
add_action( 'wp_ajax_save_wizard', 'save_wizard_advanced_mode_settings' );
/**
* Handles wizard avanced mode settings save
*/
function save_wizard_advanced_mode_settings() {
if ( current_user_can( 'manage_product_settings' ) ) {
$archive_multiple_settings = get_multiple_settings();
$product_page_settings = get_product_page_settings();
$theme = get_option( 'template' );
$archive_multiple_settings[ 'container_width' ][ $theme ] = intval( $_POST[ 'container_width' ] );
$archive_multiple_settings[ 'container_bg' ][ $theme ] = isset( $_POST[ 'container_bg' ] ) ? strval( $_POST[ 'container_bg' ] ) : '';
$archive_multiple_settings[ 'container_padding' ][ $theme ] = intval( $_POST[ 'container_padding' ] );
$archive_multiple_settings[ 'container_text' ][ $theme ] = isset( $_POST[ 'container_text' ] ) ? strval( $_POST[ 'container_text' ] ) : '';
$archive_multiple_settings[ 'disable_name' ] = intval( $_POST[ 'disable_name' ] );
$archive_multiple_settings[ 'disable_sku' ] = intval( $_POST[ 'disable_sku' ] );
$archive_multiple_settings[ 'default_sidebar' ] = strval( $_POST[ 'default_sidebar' ] );
$breadcrumbs = intval( $_POST[ 'disable_breadcrumbs' ] );
if ( $breadcrumbs == 1 ) {
$archive_multiple_settings[ 'enable_product_breadcrumbs' ] = 0;
} else {
$archive_multiple_settings[ 'enable_product_breadcrumbs' ] = 1;
}
update_option( 'archive_multiple_settings', $archive_multiple_settings );
if ( function_exists( 'get_currency_settings' ) ) {
$price = intval( $_POST[ 'disable_price' ] );
$product_currency_settings = get_currency_settings();
if ( $price == 1 ) {
$product_currency_settings[ 'price_enable' ] = 'off';
update_option( 'product_currency_settings', $product_currency_settings );
} else {
$product_currency_settings[ 'price_enable' ] = 'on';
update_option( 'product_currency_settings', $product_currency_settings );
}
}
$image = intval( $_POST[ 'disable_image' ] );
if ( $image == 1 ) {
$product_page_settings[ 'enable_product_gallery' ] = 0;
update_option( 'multi_single_options', $product_page_settings );
} else {
$product_page_settings[ 'enable_product_gallery' ] = 1;
update_option( 'multi_single_options', $product_page_settings );
}
if ( function_exists( 'is_ic_shipping_enabled' ) ) {
$shipping = intval( $_POST[ 'disable_shipping' ] );
if ( $shipping == 1 ) {
update_option( 'product_shipping_options_number', 0 );
} else if ( !is_ic_shipping_enabled() ) {
update_option( 'product_shipping_options_number', 2 );
}
}
if ( function_exists( 'is_ic_attributes_enabled' ) ) {
$attributes = intval( $_POST[ 'disable_attributes' ] );
if ( $attributes == 1 ) {
update_option( 'product_attributes_number', 0 );
} else if ( !is_ic_attributes_enabled() ) {
update_option( 'product_attributes_number', 3 );
}
}
}
echo 'done';
wp_die(); // this is required to terminate immediately and return a proper response
}
add_action( 'wp_enqueue_scripts', 'enqueue_sample_product_scripts', 100 );
function enqueue_sample_product_scripts() {
if ( isset( $_GET[ 'test_advanced' ] ) ) {
$product_id = sample_product_id();
if ( $product_id == get_the_ID() ) {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ) );
wp_enqueue_script( 'wp-color-picker', admin_url( 'js/color-picker.min.js' ), array( 'iris' ) );
$colorpicker_l10n = array(
'clear' => __( 'Clear' ),
'defaultString' => __( 'Default' ),
'pick' => __( 'Select Color' )
);
wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', $colorpicker_l10n );
}
}
}
function enable_advanced_mode( $hide_info = 0 ) {
$archive_multiple_settings = get_multiple_settings();
$theme = get_option( 'template' );
$archive_multiple_settings[ 'integration_type' ][ $theme ] = 'advanced';
update_option( 'archive_multiple_settings', $archive_multiple_settings );
if ( $hide_info == 1 ) {
$current_support_check = ic_get_theme_support_check();
$current_support_check[ $theme ] = $theme;
update_option( 'product_adder_theme_support_check', $current_support_check );
}
}
function enable_simple_mode() {
$archive_multiple_settings = get_multiple_settings();
$theme = get_option( 'template' );
$archive_multiple_settings[ 'integration_type' ][ $theme ] = 'simple';
update_option( 'archive_multiple_settings', $archive_multiple_settings );
$current_support_check = ic_get_theme_support_check();
$current_support_check[ $theme ] = '';
update_option( 'product_adder_theme_support_check', $current_support_check );
}
function get_real_integration_mode() {
$archive_multiple_settings = get_option( 'archive_multiple_settings', get_default_multiple_settings() );
$theme = get_option( 'template' );
$prev_int = (isset( $archive_multiple_settings[ 'integration_type' ] ) && !is_array( $archive_multiple_settings[ 'integration_type' ] )) ? $archive_multiple_settings[ 'integration_type' ] : 'simple';
if ( isset( $archive_multiple_settings[ 'integration_type' ] ) && !is_array( $archive_multiple_settings[ 'integration_type' ] ) ) {
$archive_multiple_settings[ 'integration_type' ] = array();
}
$archive_multiple_settings[ 'integration_type' ][ $theme ] = isset( $archive_multiple_settings[ 'integration_type' ][ $theme ] ) ? $archive_multiple_settings[ 'integration_type' ][ $theme ] : $prev_int;
return $archive_multiple_settings[ 'integration_type' ][ $theme ];
}
function is_integration_mode_selected() {
$return = false;
$archive_multiple_settings = get_option( 'archive_multiple_settings', get_default_multiple_settings() );
$theme = get_option( 'template' );
$prev_type = (isset( $archive_multiple_settings[ 'integration_type' ] ) && !is_array( $archive_multiple_settings[ 'integration_type' ] )) ? $archive_multiple_settings[ 'integration_type' ] : '';
if ( !isset( $archive_multiple_settings[ 'integration_type' ] ) || (isset( $archive_multiple_settings[ 'integration_type' ] ) && !is_array( $archive_multiple_settings[ 'integration_type' ] )) ) {
$archive_multiple_settings[ 'integration_type' ] = array();
}
$archive_multiple_settings[ 'integration_type' ][ $theme ] = isset( $archive_multiple_settings[ 'integration_type' ][ $theme ] ) ? $archive_multiple_settings[ 'integration_type' ][ $theme ] : $prev_type;
if ( $archive_multiple_settings[ 'integration_type' ][ $theme ] != '' || is_integraton_file_active() ) {
$return = true;
}
return $return;
}
function is_integraton_file_active( $auto = false ) {
if ( file_exists( get_product_adder_path( $auto ) ) ) {
return true;
} else {
return false;
}
}
add_action( 'switch_theme', 'erase_integration_type_select' );
function erase_integration_type_select() {
$archive_multiple_settings = get_option( 'archive_multiple_settings', get_default_multiple_settings() );
if ( isset( $archive_multiple_settings[ 'integration_type' ] ) && !is_array( $archive_multiple_settings[ 'integration_type' ] ) ) {
unset( $archive_multiple_settings[ 'integration_type' ] );
unset( $archive_multiple_settings[ 'container_width' ] );
unset( $archive_multiple_settings[ 'container_bg' ] );
unset( $archive_multiple_settings[ 'disable_name' ] );
unset( $archive_multiple_settings[ 'container_padding' ] );
unset( $archive_multiple_settings[ 'default_sidebar' ] );
update_option( 'archive_multiple_settings', $archive_multiple_settings );
delete_option( 'product_adder_theme_support_check' );
permalink_options_update();
}
}
add_action( 'admin_init', 'create_sample_product_with_redirect' );
function create_sample_product_with_redirect() {
if ( isset( $_GET[ 'create_sample_product_page' ] ) ) {
$sample_product_id = create_sample_product();
$url = get_permalink( $sample_product_id );
$url = esc_url_raw( add_query_arg( 'test_advanced', 1, $url ) );
wp_redirect( $url );
exit();
}
}
function implecode_supported_themes() {
return array( 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten', 'twentyfourteen', 'twentyfifteen', 'twentysixteen', 'twentyseventeen', 'pub/minileven',
'storefront', 'headway' );
}
function is_theme_implecode_supported() {
$template = get_option( 'template' );
$return = false;
if ( in_array( $template, implecode_supported_themes() ) || current_theme_supports( 'ecommerce-product-catalog' ) || ic_is_woo_template_available() ) {
$return = true;
}
return $return;
}
function is_advanced_mode_forced() {
// $template = get_option('template');
$return = false;
if ( is_theme_implecode_supported() || is_integraton_file_active() || ic_is_woo_template_available() ) {
$return = true;
}
return $return;
}
function get_product_adder_path( $auto = false ) {
if ( $auto ) {
return get_stylesheet_directory() . '/auto-product-adder.php';
} else {
return get_stylesheet_directory() . '/product-adder.php';
}
}
function get_custom_templates_folder() {
return get_stylesheet_directory() . '/implecode/';
}
function get_custom_product_page_path() {
$folder = get_custom_templates_folder();
return $folder . 'product-page.php';
}
function get_custom_product_listing_path() {
$folder = get_custom_templates_folder();
return $folder . 'product-listing.php';
}
function get_page_php_path() {
if ( file_exists( get_stylesheet_directory() . '/page.php' ) ) {
$path = get_stylesheet_directory() . '/page.php';
} else {
$path = get_theme_root() . '/' . get_template() . '/page.php';
}
return $path;
}
add_filter( 'template_include', 'home_product_listing_redirect', 5 );
/**
* Redirects the product listing page to homepage catalog if necessary
*
* @param type $template
* @return type
*/
function home_product_listing_redirect( $template ) {
if ( !is_paged() && !is_front_page() && is_ic_permalink_product_catalog() && is_product_listing_home_set() && is_post_type_archive( 'al_product' ) && !is_search() ) {
wp_redirect( get_site_url(), 301 );
exit;
}
return $template;
}
add_filter( 'redirect_canonical', 'ic_catalog_disable_redirect_canonical' );
/**
* Fixes wrong pagination redirect on home page catalog listing
*
* @param boolean $redirect_url
* @return boolean
*/
function ic_catalog_disable_redirect_canonical( $redirect_url ) {
if ( is_paged() && is_front_page() && is_ic_permalink_product_catalog() && is_product_listing_home_set() ) {
$redirect_url = false;
}
return $redirect_url;
}