jigoshop /jigoshop.php

Language PHP Lines 1237
MD5 Hash 8145f424368d2368abebf7c1c98345c9
Repository https://github.com/scottpoulin/jigoshop.git View Raw File
   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
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
<?php
/**
 *   ./////////////////////////////.
 *  //////////////////////////////////
 *  ///////////    ///////////////////
 *  ////////     /////////////////////
 *  //////    ////////////////////////
 *  /////    /////////    ////////////
 *  //////     /////////     /////////
 *  /////////     /////////    ///////
 *  ///////////    //////////    /////
 *  ////////////////////////    //////
 *  /////////////////////    /////////
 *  ///////////////////    ///////////
 *  //////////////////////////////////
 *   `//////////////////////////////`
 *
 *
 * Plugin Name:         Jigoshop
 * Plugin URI:          http://jigoshop.com/
 * Description:         Jigoshop, a WordPress eCommerce plugin that works.
 * Author:              Jigoshop
 * Author URI:          http://jigoshop.com
 *
 * Version:             1.6.2
 * Requires at least:   3.4
 * Tested up to:        3.5.1
 *
 * Text Domain:         jigoshop
 * Domain Path:         /languages/
 *
 * DISCLAIMER
 *
 * Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
 * versions in the future. If you wish to customise Jigoshop core for your needs,
 * please use our GitHub repository to publish essential changes for consideration.
 *
 * @package             Jigoshop
 * @category            Core
 * @author              Jigoshop
 * @copyright           Copyright Š 2011-2013 Jigoshop.
 * @license             http://jigoshop.com/license/commercial-edition
 */

if ( !defined( "JIGOSHOP_VERSION" )) define( "JIGOSHOP_VERSION", 1303180) ;
if ( !defined( "JIGOSHOP_OPTIONS" )) define( "JIGOSHOP_OPTIONS", 'jigoshop_options' );
if ( !defined( 'JIGOSHOP_TEMPLATE_URL' ) ) define( 'JIGOSHOP_TEMPLATE_URL', 'jigoshop/' );
if ( !defined( "PHP_EOL" )) define( "PHP_EOL", "\r\n" );

/**
 * Include core files and classes
 **/
include_once( 'classes/abstract/jigoshop_base.class.php' );
include_once( 'classes/abstract/jigoshop_singleton.class.php' );
include_once( 'classes/jigoshop_options.class.php' );
include_once( 'classes/jigoshop_session.class.php' );

include_once( 'classes/jigoshop_sanitize.class.php' );
include_once( 'classes/jigoshop_validation.class.php' );
include_once( 'classes/jigoshop_forms.class.php' );
include_once( 'jigoshop_taxonomy.php' );

include_once( 'classes/jigoshop_countries.class.php' );
include_once( 'classes/jigoshop_customer.class.php' );
include_once( 'classes/jigoshop_product.class.php' );
include_once( 'classes/jigoshop_product_variation.class.php' );
include_once( 'classes/jigoshop_order.class.php' );
include_once( 'classes/jigoshop_orders.class.php' );
include_once( 'classes/jigoshop_tax.class.php' );
include_once( 'classes/jigoshop_shipping.class.php' );
include_once( 'classes/jigoshop_coupons.class.php' );

include_once( 'gateways/gateways.class.php' );
include_once( 'gateways/gateway.class.php' );
include_once( 'gateways/bank_transfer.php' );
include_once( 'gateways/cheque.php' );
include_once( 'gateways/cod.php' );
include_once( 'gateways/paypal.php' );
include_once( 'gateways/skrill.php' );

include_once( 'shipping/shipping_method.class.php' );
include_once( 'shipping/jigoshop_calculable_shipping.php' );
include_once( 'shipping/flat_rate.php' );
include_once( 'shipping/free_shipping.php' );
include_once( 'shipping/local_pickup.php' );

include_once( 'classes/jigoshop_query.class.php' );
include_once( 'classes/jigoshop.class.php' );
include_once( 'classes/jigoshop_cart.class.php' );
include_once( 'classes/jigoshop_checkout.class.php' );
include_once( 'classes/jigoshop_cron.class.php' );

include_once( 'shortcodes/init.php' );
include_once( 'widgets/init.php' );

include_once( 'jigoshop_templates.php' );
include_once( 'jigoshop_template_actions.php' );
include_once( 'jigoshop_emails.php' );
include_once( 'jigoshop_actions.php' );


/**
 * IIS compat fix/fallback
 **/
if ( ! isset( $_SERVER['REQUEST_URI'] )) {
	$_SERVER['REQUEST_URI'] = substr( $_SERVER['PHP_SELF'], 1 );
	if ( isset( $_SERVER['QUERY_STRING'] )) { $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; }
}


// Load administration & check if we need to install
if ( is_admin() ) {
	include_once( 'admin/jigoshop-admin.php' );
	register_activation_hook( __FILE__, 'install_jigoshop' );
}


/**
 * Jigoshop Inits
 **/
add_action( 'init', 'jigoshop_init', 0 );
function jigoshop_init() {

	/* ensure nothing is output to the browser prior to this (other than headers) */
	ob_start();
	
	// http://www.geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
	// this means that all Jigoshop extensions, shipping modules and gateways must load their text domains on the 'init' action hook
	// 
	// Override default translations with custom .mo's found in wp-content/languages/jigoshop first.
	load_textdomain( 'jigoshop', WP_LANG_DIR.'/jigoshop/jigoshop-'.get_locale().'.mo' );
	load_plugin_textdomain( 'jigoshop', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

	// instantiate options -after- loading text domains
    $jigoshop_options = Jigoshop_Base::get_options();

	jigoshop_post_type();                       // register taxonomies

	new jigoshop_cron();                        // -after- text domains and Options instantiation allows settings translations

	jigoshop_set_image_sizes();                 // called -after- our Options are loaded

	// add Singletons here so that the taxonomies are loaded before calling them.
	jigoshop_session::instance();               // Start sessions if they aren't already
	jigoshop::instance();                       // Utility functions, uses sessions
	jigoshop_customer::instance();              // Customer class, sorts session data such as location
	
	// Jigoshop will instantiate gateways and shipping methods on this same 'init' action hook
	// with a very low priority to ensure text domains are loaded first prior to installing any external options
	jigoshop_shipping::instance();              // Shipping class. loads shipping methods
	jigoshop_payment_gateways::instance();      // Payment gateways class. loads payment methods

	jigoshop_cart::instance();                  // Cart class, uses sessions

	if ( ! is_admin()) {

		/* Catalog Filters */
		add_filter( 'loop-shop-query', create_function( '', 'return array("orderby" => "' . $jigoshop_options->get_option('jigoshop_catalog_sort_orderby') . '","order" => "' . $jigoshop_options->get_option('jigoshop_catalog_sort_direction') . '");' ) );
		add_filter( 'loop_shop_columns' , create_function( '', 'return ' . $jigoshop_options->get_option('jigoshop_catalog_columns') . ';' ) );
		add_filter( 'loop_shop_per_page', create_function( '', 'return ' . $jigoshop_options->get_option('jigoshop_catalog_per_page') . ';' ) );

		jigoshop_catalog_query::instance();		// front end queries class

	}

	jigoshop_roles_init();

}

/**
 * Include template functions here with a low priority so they are pluggable by themes
 **/
add_action( 'init', 'jigoshop_load_template_functions', 999 );
function jigoshop_load_template_functions() {
	include_once( 'jigoshop_template_functions.php' );
}


function jigoshop_get_core_capabilities() {
	$capabilities = array();

	$capabilities['core'] = array(
		'manage_jigoshop',
		'view_jigoshop_reports',
		'manage_jigoshop_orders',
		'manage_jigoshop_coupons',
		'manage_jigoshop_products'
	);

	$capability_types = array( 'product', 'shop_order', 'shop_coupon' );

	foreach( $capability_types as $capability_type ) {

		$capabilities[ $capability_type ] = array(

			// Post type
			"edit_{$capability_type}",
			"read_{$capability_type}",
			"delete_{$capability_type}",
			"edit_{$capability_type}s",
			"edit_others_{$capability_type}s",
			"publish_{$capability_type}s",
			"read_private_{$capability_type}s",
			"delete_{$capability_type}s",
			"delete_private_{$capability_type}s",
			"delete_published_{$capability_type}s",
			"delete_others_{$capability_type}s",
			"edit_private_{$capability_type}s",
			"edit_published_{$capability_type}s",

			// Terms
			"manage_{$capability_type}_terms",
			"edit_{$capability_type}_terms",
			"delete_{$capability_type}_terms",
			"assign_{$capability_type}_terms"
		);
	}

	return $capabilities;
}

function jigoshop_roles_init() {
	global $wp_roles;

	if ( class_exists('WP_Roles') )
		if ( ! isset( $wp_roles ) )
			$wp_roles = new WP_Roles();

	if ( is_object( $wp_roles ) ) {

		// Customer role
		add_role( 'customer', __('Customer', 'jigoshop'), array(
			'read'						=> true,
			'edit_posts'				=> false,
			'delete_posts'				=> false
		) );

		// Shop manager role
		add_role( 'shop_manager', __('Shop Manager', 'jigoshop'), array(
			'read'						=> true,
			'read_private_pages'		=> true,
			'read_private_posts'		=> true,
			'edit_users'				=> true,
			'edit_posts' 				=> true,
			'edit_pages' 				=> true,
			'edit_published_posts'		=> true,
			'edit_published_pages'		=> true,
			'edit_private_pages'		=> true,
			'edit_private_posts'		=> true,
			'edit_others_posts' 		=> true,
			'edit_others_pages' 		=> true,
			'publish_posts' 			=> true,
			'publish_pages'				=> true,
			'delete_posts' 				=> true,
			'delete_pages' 				=> true,
			'delete_private_pages'		=> true,
			'delete_private_posts'		=> true,
			'delete_published_pages'	=> true,
			'delete_published_posts'	=> true,
			'delete_others_posts' 		=> true,
			'delete_others_pages' 		=> true,
			'manage_categories' 		=> true,
			'manage_links'				=> true,
			'moderate_comments'			=> true,
			'unfiltered_html'			=> true,
			'upload_files'				=> true,
			'export'					=> true,
			'import'					=> true,
		) );
		
		$capabilities = jigoshop_get_core_capabilities();

		foreach( $capabilities as $cap_group ) {
			foreach( $cap_group as $cap ) {
				$wp_roles->add_cap( 'administrator', $cap );
				$wp_roles->add_cap( 'shop_manager', $cap );
			}
		}
		
	}
}

/**
 * Jigoshop Frontend Styles and Scripts
 **/
add_action( 'template_redirect', 'jigoshop_frontend_scripts' );
function jigoshop_frontend_scripts() {

	if ( ! is_jigoshop() && is_admin() ) return false;

    $jigoshop_options = Jigoshop_Base::get_options();

	/**
	 * Frontend Styles
	 *
	 * For Jigoshop 1.3 or better there are 2 CSS related options
	 * The ususal 'jigoshop_disable_css' must be off to use -any- Jigoshop CSS
	 *      otherwise the theme is expected to provide -all- CSS located wherever it likes, loaded by the theme
	 * A user can also copy both frontend.less and frontend.css to a 'jigoshop' folder in the theme folder and
	 *      rename them to style.less and style.css and compile changes with SimpLESS
	 *      http://wearekiss.com/simpless
	 *      If Jigoshop finds this file, it will load -only- that file, or if not found will default to our frontend.css
	 * A user can also with the second option 'jigoshop_frontend_with_theme_css' enabled, load -both- the default frontend.css
	 *      -and- any extra bits found in the same 'theme/jigoshop/style.css'
	 *      This allows only a few modifications to be added in after the default frontend.css
	 *      It will also allow for easier additions to frontend.css that get missed if themers don't upgrade their version.
	 * With these 2 options, users should either provide the complete frontend.css (style.css in the theme jigoshop folder)
	 *      or just the few changes again in the style.css in the theme jigoshop folder and set the 2nd option accordingly
	 */
	$frontend_css = jigoshop::assets_url() . '/assets/css/frontend.css';
	$theme_css = file_exists( get_stylesheet_directory() . '/jigoshop/style.css')
		? get_stylesheet_directory_uri() . '/jigoshop/style.css'
		: jigoshop::assets_url() . '/assets/css/frontend.css';

	if ( $jigoshop_options->get_option( 'jigoshop_disable_css' ) == 'no' ) {
		if ( $jigoshop_options->get_option( 'jigoshop_frontend_with_theme_css' ) == 'yes' ) {
			wp_enqueue_style( 'jigoshop_frontend_styles', $frontend_css );
		}
		wp_enqueue_style( 'jigoshop_theme_styles', $theme_css );
	}

	 if ( $jigoshop_options->get_option( 'jigoshop_disable_fancybox' ) == 'no' ) {
		wp_enqueue_style( 'jigoshop_fancybox_styles', jigoshop::assets_url() . '/assets/css/fancybox.css' );
		wp_enqueue_script( 'fancybox', jigoshop::assets_url().'/assets/js/jquery.fancybox-1.3.4.pack.js', array('jquery'));
	}

	wp_enqueue_style( 'jqueryui_styles', jigoshop::assets_url().'/assets/css/ui.css' );
	wp_enqueue_script( 'jqueryui', jigoshop::assets_url().'/assets/js/jquery-ui-1.9.2.min.js', array('jquery'), '1.9.2' );

	wp_enqueue_script( 'jigoshop_blockui', jigoshop::assets_url().'/assets/js/blockui.js', array('jquery'));
	wp_enqueue_script( 'jigoshop_frontend', jigoshop::assets_url().'/assets/js/jigoshop_frontend.js', array('jquery'));
	wp_enqueue_script( 'jigoshop_script', jigoshop::assets_url().'/assets/js/script.js', array('jquery'));

	/* Script.js variables */
	$jigoshop_params = array(
		'ajax_url' 						=> admin_url('admin-ajax.php'),
		'assets_url' 					=> jigoshop::assets_url(),
		'checkout_url'					=> admin_url('admin-ajax.php?action=jigoshop-checkout'),
		'countries' 					=> json_encode(jigoshop_countries::$states),
		'currency_symbol' 				=> get_jigoshop_currency_symbol(),
		'get_variation_nonce' 			=> wp_create_nonce("get-variation"),
		'load_fancybox'					=> $jigoshop_options->get_option( 'jigoshop_disable_fancybox' )=='no'?true:false,
		'option_guest_checkout'			=> $jigoshop_options->get_option('jigoshop_enable_guest_checkout'),
		'select_state_text' 			=> __('Select a state&hellip;', 'jigoshop'),
		'state_text' 					=> __('state', 'jigoshop'),
		'update_order_review_nonce' 	=> wp_create_nonce("update-order-review"),
        'billing_state'                 => jigoshop_customer::get_state(),
        'shipping_state'                => jigoshop_customer::get_shipping_state()
	);

	if ( isset( jigoshop_session::instance()->min_price ))
		$jigoshop_params['min_price'] = $_GET['min_price'];

	if ( isset( jigoshop_session::instance()->max_price ))
		$jigoshop_params['max_price'] = $_GET['max_price'];

	$jigoshop_params['is_checkout'] = ( is_page( jigoshop_get_page_id( 'checkout' )) || is_page( jigoshop_get_page_id( 'pay' )) );

	$jigoshop_params = apply_filters('jigoshop_params', $jigoshop_params);

	wp_localize_script( 'jigoshop_script', 'jigoshop_params', $jigoshop_params );

}


/**
 * Add a "Settings" link to the plugins.php page for Jigoshop
 **/
add_filter( 'plugin_action_links', 'jigoshop_add_settings_link', 10, 2 );
function jigoshop_add_settings_link( $links, $file ) {
	$this_plugin = plugin_basename( __FILE__ );
	if ( $file == $this_plugin ) {
		$settings_link = '<a href="admin.php?page=jigoshop_settings">' . __( 'Settings', 'jigoshop' ) . '</a>';
		array_unshift( $links, $settings_link );
	}
	return $links;
}


/**
 * Add post thumbnail support to WordPress if needed
 **/
add_action( 'after_setup_theme', 'jigoshop_check_thumbnail_support', 99 );
function jigoshop_check_thumbnail_support() {
	if ( ! current_theme_supports( 'post-thumbnails' ) ) {
		add_theme_support( 'post-thumbnails' );
		remove_post_type_support( 'post', 'thumbnail' );
		remove_post_type_support( 'page', 'thumbnail' );
	} else {
		add_post_type_support( 'product', 'thumbnail' );
	}
}


add_action( 'admin_enqueue_scripts', 'jigoshop_admin_styles' );
function jigoshop_admin_styles() {

	/* Our setting icons */
	wp_enqueue_style( 'jigoshop_admin_icons_style', jigoshop::assets_url() . '/assets/css/admin-icons.css' );

	if ( ! jigoshop_is_admin_page() ) return false;
	wp_enqueue_style( 'jigoshop_admin_styles', jigoshop::assets_url() . '/assets/css/admin.css' );
	wp_enqueue_style( 'jigoshop-select2', jigoshop::assets_url() . '/assets/css/select2.css', '', '3.1', 'screen' );
	wp_enqueue_style( 'jquery-ui-jigoshop-styles', jigoshop::assets_url() . '/assets/css/jquery-ui-1.8.16.jigoshop.css' );
	wp_enqueue_style( 'thickbox' );

}


add_action( 'admin_print_scripts', 'jigoshop_admin_scripts' );
function jigoshop_admin_scripts() {

	if ( !jigoshop_is_admin_page() ) return false;

	$pagenow = jigoshop_is_admin_page();

	wp_enqueue_script( 'jigoshop-select2', jigoshop::assets_url().'/assets/js/select2.min.js', array( 'jquery' ), '3.1' );
	wp_enqueue_script( 'jquery-ui-datepicker', jigoshop::assets_url().'/assets/js/jquery-ui-datepicker-1.8.16.min.js', array( 'jquery' ), '1.8.16' );
	wp_enqueue_script( 'jigoshop_blockui', jigoshop::assets_url() . '/assets/js/blockui.js', array( 'jquery' ), '2.4.6' );
	wp_enqueue_script( 'jigoshop_backend', jigoshop::assets_url() . '/assets/js/jigoshop_backend.js', array( 'jquery' ), '1.0' );
	wp_enqueue_script( 'thickbox' );

	if ( $pagenow == 'jigoshop_page_jigoshop_reports' || $pagenow == 'toplevel_page_jigoshop' ) {
		wp_enqueue_script('jquery_flot', jigoshop::assets_url().'/assets/js/jquery.flot.min.js', array( 'jquery' ), '1.0' );
		wp_enqueue_script('jquery_flot_pie', jigoshop::assets_url().'/assets/js/jquery.flot.pie.min.js', array( 'jquery' ), '1.0' );
	}

	/**
	 * Disable autosaves on the order and coupon pages. Prevents the javascript alert when modifying.
	 * `wp_deregister_script( 'autosave' )` would produce errors, so we use a filter instead.
	 */
	if ( $pagenow == 'shop_order' || $pagenow == 'shop_coupon' )
		add_filter( 'script_loader_src', 'jigoshop_disable_autosave', 10, 2 );

}


//### Functions #########################################################

/**
 * Set Jigoshop Product Image Sizes for WordPress based on Admin->Jigoshop->Settings->Images
 **/
function jigoshop_set_image_sizes() {

    $jigoshop_options = Jigoshop_Base::get_options();

	$sizes = array(
		'shop_tiny'      => 'tiny',
		'shop_thumbnail' => 'thumbnail',
		'shop_small'     => 'catalog',
		'shop_large'     => 'featured'
	);

	foreach ( $sizes as $size => $altSize )
		add_image_size(
			$size,
			$jigoshop_options->get_option('jigoshop_' . $size . '_w'),
			$jigoshop_options->get_option('jigoshop_' . $size . '_h'),
			( $jigoshop_options->get_option( 'jigoshop_use_wordpress_' . $altSize . '_crop', 'no' ) == 'yes' )
		);

	/* The elephant in the room (._. ) */
	add_image_size( 'admin_product_list', 32, 32, $jigoshop_options->get_option( 'jigoshop_use_wordpress_tiny_crop', 'no' ) == 'yes' ? true : false );

}


/**
 * Get Jigoshop Product Image Size based on Admin->Jigoshop->Settings->Images
 * @param string $size - one of the 4 defined Jigoshop image sizes
 * @return array - an array containing the width and height of the required size
 * @since 0.9.9
 **/
function jigoshop_get_image_size( $size ) {

    $jigoshop_options = Jigoshop_Base::get_options();
	if ( is_array( $size ) )
		return $size;

	switch ( $size ) :
		case 'admin_product_list':
			$image_size = array( 32, 32 );
			break;
		case 'shop_tiny':
			$image_size = array( $jigoshop_options->get_option('jigoshop_shop_tiny_w'), $jigoshop_options->get_option('jigoshop_shop_tiny_h') );
			break;
		case 'shop_thumbnail':
			$image_size = array( $jigoshop_options->get_option('jigoshop_shop_thumbnail_w'), $jigoshop_options->get_option('jigoshop_shop_thumbnail_h') );
			break;
		case 'shop_small':
			$image_size = array( $jigoshop_options->get_option('jigoshop_shop_small_w'), $jigoshop_options->get_option('jigoshop_shop_small_h') );
			break;
		case 'shop_large':
			$image_size = array( $jigoshop_options->get_option('jigoshop_shop_large_w'), $jigoshop_options->get_option('jigoshop_shop_large_h') );
			break;
		default:
			$image_size = array( $jigoshop_options->get_option('jigoshop_shop_small_w'), $jigoshop_options->get_option('jigoshop_shop_small_h') );
			break;
	endswitch;

	return $image_size;
}


function jigoshop_is_admin_page() {

	global $current_screen;

	if ( $current_screen->post_type == 'product' || $current_screen->post_type == 'shop_order' || $current_screen->post_type == 'shop_coupon'  )
		return $current_screen->post_type;

	if ( strstr( $current_screen->id, 'jigoshop' ) )
		return $current_screen->id;

	return false;

}


function jigoshop_disable_autosave( $src, $handle ) {
    if ( 'autosave' != $handle ) return $src;
    return '';
}


/**
 * jigoshop_demo_store
 * Adds a demo store banner to the site
 */
add_action( 'wp_footer', 'jigoshop_demo_store' );
function jigoshop_demo_store() {

	if ( Jigoshop_Base::get_options()->get_option( 'jigoshop_demo_store' ) == 'yes' && is_jigoshop() ) :
		
		$bannner_text = apply_filters( 'jigoshop_demo_banner_text', __('This is a demo store for testing purposes &mdash; no orders shall be fulfilled.', 'jigoshop') );
		echo '<p class="demo_store">'.$bannner_text.'</p>';

	endif;
}


/**
 * jigoshop_sharethis
 * Adds social sharing code to footer
 */
add_action( 'wp_footer', 'jigoshop_sharethis' );
function jigoshop_sharethis() {

    $jigoshop_options = Jigoshop_Base::get_options();
	if (is_single() && $jigoshop_options->get_option('jigoshop_sharethis')) :

		if (is_ssl()) :
			$sharethis = 'https://ws.sharethis.com/button/buttons.js';
		else :
			$sharethis = 'http://w.sharethis.com/button/buttons.js';
		endif;

		echo '<script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="'.$sharethis.'"></script><script type="text/javascript">stLight.options({publisher:"'.$jigoshop_options->get_option('jigoshop_sharethis').'"});</script>';

	endif;
}


/**
 * Mail from name/email
 **/
add_filter( 'wp_mail_from_name', 'jigoshop_mail_from_name' );
function jigoshop_mail_from_name( $name ) {
	$name = get_bloginfo('name');
	$name = esc_attr($name);
	return $name;
}


/*
add_filter( 'wp_mail_from', 'jigoshop_mail_from' );
function jigoshop_mail_from( $email ) {
	$email = Jigoshop_Base::get_options()->get_option('jigoshop_email');
	return $email;
}
*/


/**
 * Allow product_cat in the permalinks for products.
 *
 * @param string $permalink The existing permalink URL.
 */
add_filter( 'post_type_link', 'jigoshop_product_cat_filter_post_link', 10, 4 );
function jigoshop_product_cat_filter_post_link( $permalink, $post, $leavename, $sample ) {

    if ($post->post_type!=='product') return $permalink;

    // Abort early if the placeholder rewrite tag isn't in the generated URL
    if ( false === strpos( $permalink, '%product_cat%' ) ) return $permalink;

    // Get the custom taxonomy terms in use by this post
    $terms = get_the_terms( $post->ID, 'product_cat' );

    if ( empty( $terms ) ) :
    	// If no terms are assigned to this post, use a string instead
        $permalink = str_replace( '%product_cat%', _x('product', 'slug', 'jigoshop'), $permalink );
    else :
    	// Replace the placeholder rewrite tag with the first term's slug
        $first_term = apply_filters( 'jigoshop_product_cat_permalink_terms', array_shift( $terms ), $terms);
        $permalink = str_replace( '%product_cat%', $first_term->slug, $permalink );
    endif;

    return $permalink;
}


/**
 * Evaluates to true only on the Shop page, not Product categories and tags
 * Note:is used to replace is_page( jigoshop_get_page_id( 'shop' ) )
 *
 * @return bool
 * @since 0.9.9
 */
function is_shop() {
	return is_post_type_archive( 'product' ) || is_page( jigoshop_get_page_id('shop') );
}

/**
 * Evaluates to true only on the Category Pages
 *
 * @return bool
 * @since 0.9.9
 */
function is_product_category() {
	return is_tax( 'product_cat' );
}

/**
 * Evaluates to true only on the Tag Pages
 *
 * @return bool
 * @since 0.9.9
 */
function is_product_tag() {
	return is_tax( 'product_tag' );
}

/**
 * Evaluates to true only on the Single Product Page
 *
 * @return bool
 * @since 0.9.9
 */
function is_product() {
	return is_singular( array('product') );
}

/**
 * Evaluates to true only on Shop, Product Category, and Product Tag pages
 *
 * @return bool
 * @since 0.9.9
 */
function is_product_list() {
	$is_list = false;
	$is_list |= is_shop();
	$is_list |= is_product_tag();
	$is_list |= is_product_category();
	return $is_list;
}

/**
 * Evaluates to true for all Jigoshop pages
 *
 * @return bool
 * @since 0.9.9
 */
function is_jigoshop() {
	$is_jigo = false;
	$is_jigo |= is_content_wrapped();
	$is_jigo |= is_account();
	$is_jigo |= is_cart();
	$is_jigo |= is_checkout();
	$is_jigo |= is_order_tracker();
	return $is_jigo;
}

/**
 * Evaluates to true only on the Shop, Category, Tag and Single Product Pages
 *
 * @return bool
 * @since 0.9.9.1
 */
function is_content_wrapped() {
	$is_wrapped = false;
	$is_wrapped |= is_product_list();
	$is_wrapped |= is_product();
	return $is_wrapped;
}

/**
 * Jigoshop page IDs
 *
 * returns -1 if no page is found
 **/
if (!function_exists('jigoshop_get_page_id')) {
	function jigoshop_get_page_id( $page ) {
        $jigoshop_options = Jigoshop_Base::get_options();
		$page = apply_filters('jigoshop_get_' . $page . '_page_id', $jigoshop_options->get_option('jigoshop_' . $page . '_page_id'));
		return ($page) ? $page : -1;
	}
}

/**
 * Evaluates to true only on the Order Tracking page
 *
 * @return bool
 * @since 0.9.9.1
 */
function is_order_tracker() {
	return is_page( jigoshop_get_page_id('track_order'));
}

/**
 * Evaluates to true only on the Cart page
 *
 * @return bool
 * @since 0.9.8
 */
function is_cart() {
	return is_page( jigoshop_get_page_id('cart'));
}

/**
 * Evaluates to true only on the Checkout or Pay pages
 *
 * @return bool
 * @since 0.9.8
 */
function is_checkout() {
	return is_page( jigoshop_get_page_id('checkout')) | is_page( jigoshop_get_page_id('pay'));
}

/**
 * Evaluates to true only on the main Account or any sub-account pages
 *
 * @return bool
 * @since 0.9.9.1
 */
function is_account() {
	$is_account = false;
	$is_account |= is_page( jigoshop_get_page_id('myaccount') );
	$is_account |= is_page( jigoshop_get_page_id('edit_address') );
	$is_account |= is_page( jigoshop_get_page_id('change_password') );
	$is_account |= is_page( jigoshop_get_page_id('view_order') );
	return $is_account;
}

if (!function_exists('is_ajax')) {
	function is_ajax() {
		if ( defined('DOING_AJAX') ) return true;
		return ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' );
	}
}

function jigoshop_force_ssl() {
	if (is_checkout() && !is_ssl()) :
		wp_safe_redirect( str_replace('http:', 'https:', get_permalink(jigoshop_get_page_id('checkout'))), 301 );
		exit;
	endif;
}
if (!is_admin() && Jigoshop_Base::get_options()->get_option('jigoshop_force_ssl_checkout')=='yes') add_action( 'wp', 'jigoshop_force_ssl');

function jigoshop_force_ssl_images( $content ) {
	if (is_ssl()) :
		if (is_array($content)) :
			$content = array_map('jigoshop_force_ssl_images', $content);
		else :
			$content = str_replace('http:', 'https:', $content);
		endif;
	endif;
	return $content;
}
add_filter('post_thumbnail_html', 'jigoshop_force_ssl_images');
add_filter('widget_text', 'jigoshop_force_ssl_images');
add_filter('wp_get_attachment_url', 'jigoshop_force_ssl_images');
add_filter('wp_get_attachment_image_attributes', 'jigoshop_force_ssl_images');
add_filter('wp_get_attachment_url', 'jigoshop_force_ssl_images');

function jigoshop_force_ssl_urls( $url ) {
	if (is_ssl()) :
		$url = str_replace('http:', 'https:', $url);
	endif;
	return $url;
}
add_filter('option_siteurl', 'jigoshop_force_ssl_urls');
add_filter('option_home', 'jigoshop_force_ssl_urls');
add_filter('option_url', 'jigoshop_force_ssl_urls');
add_filter('option_wpurl', 'jigoshop_force_ssl_urls');
add_filter('option_stylesheet_url', 'jigoshop_force_ssl_urls');
add_filter('option_template_url', 'jigoshop_force_ssl_urls');
add_filter('script_loader_src', 'jigoshop_force_ssl_urls');
add_filter('style_loader_src', 'jigoshop_force_ssl_urls');


function get_jigoshop_currency_symbol() {

    $jigoshop_options = Jigoshop_Base::get_options();
	$currency = $jigoshop_options->get_option('jigoshop_currency');
	$symbols = jigoshop::currency_symbols();
	$currency_symbol = $symbols[$currency];
	
	return apply_filters('jigoshop_currency_symbol', $currency_symbol, $currency);
	
}

function jigoshop_price( $price, $args = array() ) {

    $jigoshop_options = Jigoshop_Base::get_options();
	extract(shortcode_atts(array(
		'ex_tax_label' 	=> 0, // 0 for no label, 1 for ex. tax, 2 for inc. tax
        'with_currency' => true
	), $args));


    $tax_label = '';

    if ($ex_tax_label === 1) {
        $tax_label = __(' <small>(ex. tax)</small>', 'jigoshop');
    } else if ($ex_tax_label === 2) {
        $tax_label = __(' <small>(inc. tax)</small>', 'jigoshop');
    } else {
        $tax_label = '';
    }

	$return = '';
	$price = number_format(
		(double) $price,
		(int) $jigoshop_options->get_option('jigoshop_price_num_decimals'),
		$jigoshop_options->get_option('jigoshop_price_decimal_sep'),
		$jigoshop_options->get_option('jigoshop_price_thousand_sep')
	);

    $return = $price;

    if ($with_currency) :

        $currency_pos = $jigoshop_options->get_option('jigoshop_currency_pos');
        $currency_symbol = get_jigoshop_currency_symbol();
        $currency_code = $jigoshop_options->get_option('jigoshop_currency');

        switch ($currency_pos) :
            case 'left' :
                $return = $currency_symbol . $price;
            break;
            case 'left_space' :
                $return = $currency_symbol . ' ' . $price;
            break;
            case 'right' :
                $return = $price . $currency_symbol;
            break;
            case 'right_space' :
                $return = $price . ' ' . $currency_symbol;
            break;
            case 'left_code' :
                $return = $currency_code . $price;
            break;
            case 'left_code_space' :
                $return = $currency_code . ' ' . $price;
            break;
            case 'right_code' :
                $return = $price . $currency_code;
            break;
            case 'right_code_space' :
                $return = $price . ' ' . $currency_code;
            break;
            case 'code_symbol' :
                $return = $currency_code . $price . $currency_symbol;
            break;
            case 'code_symbol_space' :
                $return = $currency_code . ' ' . $price . ' ' . $currency_symbol;
            break;
            case 'symbol_code' :
                $return = $currency_symbol . $price . $currency_code;
            break;
            case 'symbol_code_space' :
                $return = $currency_symbol . ' ' . $price . ' ' . $currency_code;
            break;
        endswitch;

        // only show tax label (ex. tax) if we are going to show the price with currency as well. Otherwise we just want the formatted price
        if ($jigoshop_options->get_option('jigoshop_calc_taxes')=='yes') $return .= $tax_label;

    endif;

	return apply_filters( 'jigoshop_price_display_filter', $return);
}

/** Show variation info if set */
function jigoshop_get_formatted_variation( $variation = '', $flat = false ) {
	if ($variation && is_array($variation)) :

		$return = '';

		if (!$flat) :
			$return = '<dl class="variation">';
		endif;

		$varation_list = array();

		foreach ($variation as $name => $value) :

			$name = str_replace('tax_', '', $name);

			if ( taxonomy_exists( 'pa_'.$name )) :
				$terms = get_terms( 'pa_'.$name, array( 'orderby' => 'slug', 'hide_empty' => '0' ) );
				foreach ( $terms as $term ) :
					if ( $term->slug == $value ) $value = $term->name;
				endforeach;
				$name = get_taxonomy( 'pa_'.$name )->labels->name;
				$name = jigoshop_product::attribute_label('pa_'.$name);
			endif;

			if ($flat) :
				$varation_list[] = $name.': '.$value;
			else :
				$varation_list[] = '<dt>'.$name.':</dt><dd>'.$value.'</dd>';
			endif;

		endforeach;

		if ($flat) :
			$return .= implode(', ', $varation_list);
		else :
			$return .= implode('', $varation_list);
		endif;

		if (!$flat) :
			$return .= '</dl>';
		endif;

		return $return;

	endif;
}

// Remove pingbacks/trackbacks from Comments Feed
// betterwp.net/wordpress-tips/remove-pingbackstrackbacks-from-comments-feed/
add_filter('request', 'jigoshop_filter_request');
function jigoshop_filter_request($qv) {
	if (isset($qv['feed']) && !empty($qv['withcomments']))
	{
		add_filter('comment_feed_where', 'jigoshop_comment_feed_where');
	}
	return $qv;
}

function jigoshop_comment_feed_where($cwhere) {
	$cwhere .= " AND comment_type != 'jigoshop' ";
	return $cwhere;
}

function jigoshop_let_to_num($v) {
    $l = substr($v, -1);
    $ret = substr($v, 0, -1);
    switch(strtoupper($l)){
    case 'P':
        $ret *= 1024;
    case 'T':
        $ret *= 1024;
    case 'G':
        $ret *= 1024;
    case 'M':
        $ret *= 1024;
    case 'K':
        $ret *= 1024;
        break;
    }
    return $ret;
}

function jigowatt_clean( $var ) {
	return strip_tags(stripslashes(trim($var)));
}

// Returns a float value
function jigoshop_sanitize_num( $var ) {
	// TODO: as it stands, it doesn't allow negative values (-JAP-)
	// should be - preg_replace("/^[^[\-\+]0-9\.]/","",$var)
	// currently only used for prices in product-data-save.php
	return strip_tags(stripslashes(floatval(preg_replace("/^[^0-9\.]/","",$var))));
}

// Author: Sergey Biryukov
// Plugin URI: http://wordpress.org/extend/plugins/allow-cyrillic-usernames/
add_filter('sanitize_user', 'jigoshop_sanitize_user', 10, 3);
function jigoshop_sanitize_user($username, $raw_username, $strict) {
	$username = wp_strip_all_tags( $raw_username );
	$username = remove_accents( $username );
	$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
	$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities

	if ( $strict )
		$username = preg_replace( '|[^a-z?-?0-9 _.\-@]|iu', '', $username );

	$username = trim( $username );
	$username = preg_replace( '|\s+|', ' ', $username );

	return $username;
}

add_action( 'wp_head', 'jigoshop_head_version' );
function jigoshop_head_version() {
	echo "\n" . '<!-- Jigoshop Version: '.jigoshop::jigoshop_version().' -->' . "\n";
}

global $jigoshop_body_classes;

add_action('wp_head', 'jigoshop_page_body_classes');
function jigoshop_page_body_classes() {

	global $jigoshop_body_classes;

	$jigoshop_body_classes = (array) $jigoshop_body_classes;

	if ( is_order_tracker() ) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-tracker' ) );

	if ( is_checkout() ) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-checkout' ) );

	if ( is_cart() ) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-cart' ) );

	if ( is_page(jigoshop_get_page_id('thanks'))) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-thanks' ) );

	if ( is_page(jigoshop_get_page_id('pay'))) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-pay' ) );

	if ( is_account() ) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-myaccount' ) );

}

function jigoshop_add_body_class( $class = array() ) {

	global $jigoshop_body_classes;

	$jigoshop_body_classes = (array) $jigoshop_body_classes;

	$jigoshop_body_classes = array_unique( array_merge( $class, $jigoshop_body_classes ));
}

add_filter('body_class','jigoshop_body_class');
function jigoshop_body_class($classes) {

	global $jigoshop_body_classes;

	$jigoshop_body_classes = (array) $jigoshop_body_classes;

	$classes = array_unique( array_merge( $classes, $jigoshop_body_classes ));

	return $classes;
}

//### Extra Review Field in comments #########################################################

function jigoshop_add_comment_rating($comment_id) {
	if ( isset($_POST['rating']) ) :
		if (!$_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0) $_POST['rating'] = 5;
		add_comment_meta( $comment_id, 'rating', $_POST['rating'], true );
	endif;
}
add_action( 'comment_post', 'jigoshop_add_comment_rating', 1 );

function jigoshop_check_comment_rating($comment_data) {
	// If posting a comment (not trackback etc) and not logged in
	if ( isset($_POST['rating']) && !jigoshop::verify_nonce('comment_rating') )
		wp_die( __('You have taken too long. Please go back and refresh the page.', 'jigoshop') );

	elseif ( isset($_POST['rating']) && empty($_POST['rating']) && $comment_data['comment_type']== '' ) {
		wp_die( __('Please rate the product.',"jigoshop") );
		exit;
	}
	return $comment_data;
}
add_filter('preprocess_comment', 'jigoshop_check_comment_rating', 0);

//### Comments #########################################################

function jigoshop_comments($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment; global $post; ?>

	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
		<div id="comment-<?php comment_ID(); ?>" class="comment_container">

  			<?php echo get_avatar( $comment, $size='60' ); ?>

			<div class="comment-text">
				<?php if ( $rating = get_comment_meta( $comment->comment_ID, 'rating', true ) ): ?>
				<div class="star-rating" title="<?php echo esc_attr( $rating ); ?>">
					<span style="width:<?php echo $rating*16; ?>px"><?php echo $rating; ?> <?php _e('out of 5', 'jigoshop'); ?></span>
				</div>
				<?php endif; ?>
				<?php if ($comment->comment_approved == '0') : ?>
					<p class="meta"><em><?php _e('Your comment is awaiting approval','jigoshop'); ?></em></p>
				<?php else : ?>
					<p class="meta">
						<?php _e('Rating by','jigoshop'); ?> <strong class="reviewer vcard"><span class="fn"><?php comment_author(); ?></span></strong> <?php _e('on','jigoshop'); ?> <?php echo date_i18n(get_option('date_format'), strtotime(get_comment_date('Y-m-d'))); ?>:
					</p>
				<?php endif; ?>
  				<div class="description"><?php comment_text(); ?></div>
  				<div class="clear"></div>
  			</div>
			<div class="clear"></div>
		</div>
	<?php
}

//### Exclude order comments from front end #########################################################
add_filter( 'comments_clauses', 'jigoshop_exclude_order_admin_comments', 10, 1);
function jigoshop_exclude_order_admin_comments( $clauses ) {

	// NOTE: bit of a hack, tests if we're in the admin & its an ajax call
	// Don't hide when viewing orders in admin
	// TODO: removing the is_ajax() call for version 1.6, isn't working for some reason, order notes were not appearing in Admin
	if ( is_admin() ) {
		return $clauses;
	}

	// Hide all those comments which are of type jigoshop or order_note
	$clauses['where'] .= ' AND comment_type != "jigoshop"';
	$clauses['where'] .= ' AND comment_type != "order_note"'; // Removes order notes

	return $clauses;
}

/**
 * Support for Import/Export
 *
 * WordPress import should work - however, it fails to import custom product attribute taxonomies.
 * This code grabs the file before it is imported and ensures the taxonomies are created.
 **/
function jigoshop_import_start() {

	global $wpdb;
    $jigoshop_options = Jigoshop_Base::get_options();

	$id = (int) $_POST['import_id'];
	$file = get_attached_file( $id );

	$parser = new WXR_Parser();
	$import_data = $parser->parse( $file );

	if (isset($import_data['posts'])) :
		$posts = $import_data['posts'];

		if ($posts && sizeof($posts)>0) foreach ($posts as $post) :

			if ($post['post_type']=='product') :

				if ($post['terms'] && sizeof($post['terms'])>0) :

					foreach ($post['terms'] as $term) :

						$domain = $term['domain'];

						if (strstr($domain, 'pa_')) :

							// Make sure it exists!
							if (!taxonomy_exists( $domain )) :

								$nicename = sanitize_title(str_replace('pa_', '', $domain));

								$exists_in_db = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_id FROM ".$wpdb->prefix . "jigoshop_attribute_taxonomies WHERE attribute_name = %s;", $nicename ) );

								// Create the taxonomy
								if (!$exists_in_db) :
									$wpdb->insert( $wpdb->prefix . "jigoshop_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_type' => 'select' ), array( '%s', '%s' ) );
								endif;

								// Register the taxonomy now so that the import works!
								register_taxonomy( $domain,
							        array('product'),
							        array(
							            'hierarchical' => true,
							            'labels' => array(
												'name'             => $nicename,
												'singular_name'    => $nicename,
												'search_items'     =>  __( 'Search ', 'jigoshop') . $nicename,
												'all_items'        => __( 'All ', 'jigoshop') . $nicename,
												'parent_item'      => __( 'Parent ', 'jigoshop') . $nicename,
												'parent_item_colon'=> __( 'Parent ', 'jigoshop') . $nicename . ':',
												'edit_item'        => __( 'Edit ', 'jigoshop') . $nicename,
												'update_item'      => __( 'Update ', 'jigoshop') . $nicename,
												'add_new_item'     => __( 'Add New ', 'jigoshop') . $nicename,
												'new_item_name'    => __( 'New ', 'jigoshop') . $nicename
							            ),
										'show_ui'  => false,
										'query_var'=> true,
										'rewrite'  => array( 'slug'=> sanitize_title($nicename), 'with_front'=> false, 'hierarchical'=> true ),
							        )
							    );

								$jigoshop_options->set_option('jigowatt_update_rewrite_rules', '1');

							endif;

						endif;

					endforeach;

				endif;

			endif;

		endforeach;

	endif;

}
add_action('import_start', 'jigoshop_import_start');


if(!function_exists('jigoshop_log')){

    /**
     * Logs to the debug log when you enable wordpress debug mode.
     *
     * @param string $from_class is the name of the php file that you are logging from.
     * defaults to jigoshop if non is supplied.
     * @param mixed $message this can be a regular string, array or object
     */
    function jigoshop_log( $message, $from_class = 'jigoshop' ) {

        if( WP_DEBUG === true ) :
            if( is_array( $message ) || is_object( $message ) ) :
                error_log( $from_class . ': ' . print_r( $message, true ) );
            else :
                error_log( $from_class . ': ' . $message );
            endif;
        endif;

    }
}
Back to Top