Passed
Push — master ( 0fd3da...d47925 )
by Brian
05:32
created
vendor/ayecode/wp-ayecode-ui/includes/ayecode-ui-settings.php 1 patch
Indentation   +1099 added lines, -1099 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,236 +21,236 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'AyeCode_UI_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class AyeCode_UI_Settings
28
-	 * @ver 1.0.0
29
-	 * @todo decide how to implement textdomain
30
-	 */
31
-	class AyeCode_UI_Settings {
32
-
33
-		/**
34
-		 * Class version version.
35
-		 *
36
-		 * @var string
37
-		 */
38
-		public $version = '0.1.46';
39
-
40
-		/**
41
-		 * Class textdomain.
42
-		 *
43
-		 * @var string
44
-		 */
45
-		public $textdomain = 'aui';
46
-
47
-		/**
48
-		 * Latest version of Bootstrap at time of publish published.
49
-		 *
50
-		 * @var string
51
-		 */
52
-		public $latest = "4.5.3";
53
-
54
-		/**
55
-		 * Current version of select2 being used.
56
-		 *
57
-		 * @var string
58
-		 */
59
-		public $select2_version = "4.0.11";
60
-
61
-		/**
62
-		 * The title.
63
-		 *
64
-		 * @var string
65
-		 */
66
-		public $name = 'AyeCode UI';
67
-
68
-		/**
69
-		 * The relative url to the assets.
70
-		 *
71
-		 * @var string
72
-		 */
73
-		public $url = '';
74
-
75
-		/**
76
-		 * Holds the settings values.
77
-		 *
78
-		 * @var array
79
-		 */
80
-		private $settings;
81
-
82
-		/**
83
-		 * AyeCode_UI_Settings instance.
84
-		 *
85
-		 * @access private
86
-		 * @since  1.0.0
87
-		 * @var    AyeCode_UI_Settings There can be only one!
88
-		 */
89
-		private static $instance = null;
90
-
91
-		/**
92
-		 * Main AyeCode_UI_Settings Instance.
93
-		 *
94
-		 * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
-		 *
96
-		 * @since 1.0.0
97
-		 * @static
98
-		 * @return AyeCode_UI_Settings - Main instance.
99
-		 */
100
-		public static function instance() {
101
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
-
103
-				self::$instance = new AyeCode_UI_Settings;
104
-
105
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
106
-
107
-				if ( is_admin() ) {
108
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
110
-
111
-					// Maybe show example page
112
-					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
113
-				}
114
-
115
-				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
116
-
117
-				do_action( 'ayecode_ui_settings_loaded' );
118
-			}
119
-
120
-			return self::$instance;
121
-		}
122
-
123
-		/**
124
-		 * Setup some constants.
125
-		 */
126
-		public function constants(){
127
-			define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128
-			define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
-			if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
-			if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
131
-		}
132
-
133
-		/**
134
-		 * Initiate the settings and add the required action hooks.
135
-		 */
136
-		public function init() {
137
-			$this->constants();
138
-			$this->settings = $this->get_settings();
139
-			$this->url = $this->get_url();
140
-
141
-			/**
142
-			 * Maybe load CSS
143
-			 *
144
-			 * We load super early in case there is a theme version that might change the colors
145
-			 */
146
-			if ( $this->settings['css'] ) {
147
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
148
-			}
149
-			if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
151
-			}
152
-
153
-			// maybe load JS
154
-			if ( $this->settings['js'] ) {
155
-				$priority = $this->is_bs3_compat() ? 100 : 1;
156
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
157
-			}
158
-			if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
160
-			}
161
-
162
-			// Maybe set the HTML font size
163
-			if ( $this->settings['html_font_size'] ) {
164
-				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
165
-			}
166
-
167
-
168
-		}
169
-
170
-		/**
171
-		 * Check if we should load the admin scripts or not.
172
-		 *
173
-		 * @return bool
174
-		 */
175
-		public function load_admin_scripts(){
176
-			$result = true;
177
-
178
-			// check if specifically disabled
179
-			if(!empty($this->settings['disable_admin'])){
180
-				$url_parts = explode("\n",$this->settings['disable_admin']);
181
-				foreach($url_parts as $part){
182
-					if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
183
-						return false; // return early, no point checking further
184
-					}
185
-				}
186
-			}
187
-
188
-			return $result;
189
-		}
190
-
191
-		/**
192
-		 * Add a html font size to the footer.
193
-		 */
194
-		public function html_font_size(){
195
-			$this->settings = $this->get_settings();
196
-			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
197
-		}
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class AyeCode_UI_Settings
28
+     * @ver 1.0.0
29
+     * @todo decide how to implement textdomain
30
+     */
31
+    class AyeCode_UI_Settings {
32
+
33
+        /**
34
+         * Class version version.
35
+         *
36
+         * @var string
37
+         */
38
+        public $version = '0.1.46';
39
+
40
+        /**
41
+         * Class textdomain.
42
+         *
43
+         * @var string
44
+         */
45
+        public $textdomain = 'aui';
46
+
47
+        /**
48
+         * Latest version of Bootstrap at time of publish published.
49
+         *
50
+         * @var string
51
+         */
52
+        public $latest = "4.5.3";
53
+
54
+        /**
55
+         * Current version of select2 being used.
56
+         *
57
+         * @var string
58
+         */
59
+        public $select2_version = "4.0.11";
60
+
61
+        /**
62
+         * The title.
63
+         *
64
+         * @var string
65
+         */
66
+        public $name = 'AyeCode UI';
67
+
68
+        /**
69
+         * The relative url to the assets.
70
+         *
71
+         * @var string
72
+         */
73
+        public $url = '';
74
+
75
+        /**
76
+         * Holds the settings values.
77
+         *
78
+         * @var array
79
+         */
80
+        private $settings;
81
+
82
+        /**
83
+         * AyeCode_UI_Settings instance.
84
+         *
85
+         * @access private
86
+         * @since  1.0.0
87
+         * @var    AyeCode_UI_Settings There can be only one!
88
+         */
89
+        private static $instance = null;
90
+
91
+        /**
92
+         * Main AyeCode_UI_Settings Instance.
93
+         *
94
+         * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
+         *
96
+         * @since 1.0.0
97
+         * @static
98
+         * @return AyeCode_UI_Settings - Main instance.
99
+         */
100
+        public static function instance() {
101
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
+
103
+                self::$instance = new AyeCode_UI_Settings;
104
+
105
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
106
+
107
+                if ( is_admin() ) {
108
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
110
+
111
+                    // Maybe show example page
112
+                    add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
113
+                }
198 114
 
199
-		/**
200
-		 * Check if the current admin screen should load scripts.
201
-		 * 
202
-		 * @return bool
203
-		 */
204
-		public function is_aui_screen(){
205
-			$load = false;
206
-			// check if we should load or not
207
-			if ( is_admin() ) {
208
-				// Only enable on set pages
209
-				$aui_screens = array(
210
-					'page',
211
-					'post',
212
-					'settings_page_ayecode-ui-settings',
213
-					'appearance_page_gutenberg-widgets'
214
-				);
215
-				$screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
216
-
217
-				$screen = get_current_screen();
115
+                add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
116
+
117
+                do_action( 'ayecode_ui_settings_loaded' );
118
+            }
119
+
120
+            return self::$instance;
121
+        }
122
+
123
+        /**
124
+         * Setup some constants.
125
+         */
126
+        public function constants(){
127
+            define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128
+            define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
+            if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
+            if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
131
+        }
132
+
133
+        /**
134
+         * Initiate the settings and add the required action hooks.
135
+         */
136
+        public function init() {
137
+            $this->constants();
138
+            $this->settings = $this->get_settings();
139
+            $this->url = $this->get_url();
140
+
141
+            /**
142
+             * Maybe load CSS
143
+             *
144
+             * We load super early in case there is a theme version that might change the colors
145
+             */
146
+            if ( $this->settings['css'] ) {
147
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
148
+            }
149
+            if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
151
+            }
152
+
153
+            // maybe load JS
154
+            if ( $this->settings['js'] ) {
155
+                $priority = $this->is_bs3_compat() ? 100 : 1;
156
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
157
+            }
158
+            if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
160
+            }
161
+
162
+            // Maybe set the HTML font size
163
+            if ( $this->settings['html_font_size'] ) {
164
+                add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
165
+            }
166
+
167
+
168
+        }
169
+
170
+        /**
171
+         * Check if we should load the admin scripts or not.
172
+         *
173
+         * @return bool
174
+         */
175
+        public function load_admin_scripts(){
176
+            $result = true;
177
+
178
+            // check if specifically disabled
179
+            if(!empty($this->settings['disable_admin'])){
180
+                $url_parts = explode("\n",$this->settings['disable_admin']);
181
+                foreach($url_parts as $part){
182
+                    if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
183
+                        return false; // return early, no point checking further
184
+                    }
185
+                }
186
+            }
187
+
188
+            return $result;
189
+        }
190
+
191
+        /**
192
+         * Add a html font size to the footer.
193
+         */
194
+        public function html_font_size(){
195
+            $this->settings = $this->get_settings();
196
+            echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
197
+        }
198
+
199
+        /**
200
+         * Check if the current admin screen should load scripts.
201
+         * 
202
+         * @return bool
203
+         */
204
+        public function is_aui_screen(){
205
+            $load = false;
206
+            // check if we should load or not
207
+            if ( is_admin() ) {
208
+                // Only enable on set pages
209
+                $aui_screens = array(
210
+                    'page',
211
+                    'post',
212
+                    'settings_page_ayecode-ui-settings',
213
+                    'appearance_page_gutenberg-widgets'
214
+                );
215
+                $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
216
+
217
+                $screen = get_current_screen();
218 218
 
219 219
 //				echo '###'.$screen->id;
220 220
 				
221
-				if ( $screen && in_array( $screen->id, $screen_ids ) ) {
222
-					$load = true;
223
-				}
224
-			}
221
+                if ( $screen && in_array( $screen->id, $screen_ids ) ) {
222
+                    $load = true;
223
+                }
224
+            }
225 225
 
226
-			return $load;
227
-		}
226
+            return $load;
227
+        }
228 228
 
229
-		/**
230
-		 * Adds the styles.
231
-		 */
232
-		public function enqueue_style() {
229
+        /**
230
+         * Adds the styles.
231
+         */
232
+        public function enqueue_style() {
233 233
 
234
-			if( is_admin() && !$this->is_aui_screen()){
235
-				// don't add wp-admin scripts if not requested to
236
-			}else{
237
-				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
234
+            if( is_admin() && !$this->is_aui_screen()){
235
+                // don't add wp-admin scripts if not requested to
236
+            }else{
237
+                $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
238 238
 
239
-				$rtl = is_rtl() ? '-rtl' : '';
239
+                $rtl = is_rtl() ? '-rtl' : '';
240 240
 
241
-				if($this->settings[$css_setting]){
242
-					$compatibility = $this->settings[$css_setting]=='core' ? false : true;
243
-					$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
244
-					wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
245
-					wp_enqueue_style( 'ayecode-ui' );
241
+                if($this->settings[$css_setting]){
242
+                    $compatibility = $this->settings[$css_setting]=='core' ? false : true;
243
+                    $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
244
+                    wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
245
+                    wp_enqueue_style( 'ayecode-ui' );
246 246
 
247
-					// flatpickr
248
-					wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
247
+                    // flatpickr
248
+                    wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
249 249
 
250 250
 
251
-					// fix some wp-admin issues
252
-					if(is_admin()){
253
-						$custom_css = "
251
+                    // fix some wp-admin issues
252
+                    if(is_admin()){
253
+                        $custom_css = "
254 254
                 body{
255 255
                     background-color: #f1f1f1;
256 256
                     font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
@@ -289,35 +289,35 @@  discard block
 block discarded – undo
289 289
 				}
290 290
                 ";
291 291
 
292
-						// @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
293
-						$custom_css .= "
292
+                        // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
293
+                        $custom_css .= "
294 294
 						.edit-post-sidebar input[type=color].components-text-control__input{
295 295
 						    padding: 0;
296 296
 						}
297 297
 					";
298
-						wp_add_inline_style( 'ayecode-ui', $custom_css );
299
-					}
298
+                        wp_add_inline_style( 'ayecode-ui', $custom_css );
299
+                    }
300 300
 
301
-					// custom changes
302
-					wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
301
+                    // custom changes
302
+                    wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
303 303
 
304
-				}
305
-			}
304
+                }
305
+            }
306 306
 
307 307
 
308
-		}
308
+        }
309
+
310
+        /**
311
+         * Get inline script used if bootstrap enqueued
312
+         *
313
+         * If this remains small then its best to use this than to add another JS file.
314
+         */
315
+        public function inline_script() {
316
+            // Flatpickr calendar locale
317
+            $flatpickr_locale = self::flatpickr_locale();
309 318
 
310
-		/**
311
-		 * Get inline script used if bootstrap enqueued
312
-		 *
313
-		 * If this remains small then its best to use this than to add another JS file.
314
-		 */
315
-		public function inline_script() {
316
-			// Flatpickr calendar locale
317
-			$flatpickr_locale = self::flatpickr_locale();
318
-
319
-			ob_start();
320
-			?>
319
+            ob_start();
320
+            ?>
321 321
 			<script>
322 322
 				/**
323 323
 				 * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ).
@@ -981,27 +981,27 @@  discard block
 block discarded – undo
981 981
 
982 982
 			</script>
983 983
 			<?php
984
-			$output = ob_get_clean();
984
+            $output = ob_get_clean();
985 985
 
986
-			/*
986
+            /*
987 987
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
988 988
 			 */
989
-			return str_replace( array(
990
-				'<script>',
991
-				'</script>'
992
-			), '', $output );
993
-		}
994
-
995
-
996
-		/**
997
-		 * JS to help with conflict issues with other plugins and themes using bootstrap v3.
998
-		 *
999
-		 * @TODO we may need this when other conflicts arrise.
1000
-		 * @return mixed
1001
-		 */
1002
-		public static function bs3_compat_js() {
1003
-			ob_start();
1004
-			?>
989
+            return str_replace( array(
990
+                '<script>',
991
+                '</script>'
992
+            ), '', $output );
993
+        }
994
+
995
+
996
+        /**
997
+         * JS to help with conflict issues with other plugins and themes using bootstrap v3.
998
+         *
999
+         * @TODO we may need this when other conflicts arrise.
1000
+         * @return mixed
1001
+         */
1002
+        public static function bs3_compat_js() {
1003
+            ob_start();
1004
+            ?>
1005 1005
 			<script>
1006 1006
 				<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1007 1007
 				/* With Avada builder */
@@ -1009,20 +1009,20 @@  discard block
 block discarded – undo
1009 1009
 				<?php } ?>
1010 1010
 			</script>
1011 1011
 			<?php
1012
-			return str_replace( array(
1013
-				'<script>',
1014
-				'</script>'
1015
-			), '', ob_get_clean());
1016
-		}
1017
-
1018
-		/**
1019
-		 * Get inline script used if bootstrap file browser enqueued.
1020
-		 *
1021
-		 * If this remains small then its best to use this than to add another JS file.
1022
-		 */
1023
-		public function inline_script_file_browser(){
1024
-			ob_start();
1025
-			?>
1012
+            return str_replace( array(
1013
+                '<script>',
1014
+                '</script>'
1015
+            ), '', ob_get_clean());
1016
+        }
1017
+
1018
+        /**
1019
+         * Get inline script used if bootstrap file browser enqueued.
1020
+         *
1021
+         * If this remains small then its best to use this than to add another JS file.
1022
+         */
1023
+        public function inline_script_file_browser(){
1024
+            ob_start();
1025
+            ?>
1026 1026
 			<script>
1027 1027
 				// run on doc ready
1028 1028
 				jQuery(document).ready(function () {
@@ -1030,192 +1030,192 @@  discard block
 block discarded – undo
1030 1030
 				});
1031 1031
 			</script>
1032 1032
 			<?php
1033
-			$output = ob_get_clean();
1033
+            $output = ob_get_clean();
1034 1034
 
1035
-			/*
1035
+            /*
1036 1036
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1037 1037
 			 */
1038
-			return str_replace( array(
1039
-				'<script>',
1040
-				'</script>'
1041
-			), '', $output );
1042
-		}
1043
-
1044
-		/**
1045
-		 * Adds the Font Awesome JS.
1046
-		 */
1047
-		public function enqueue_scripts() {
1048
-
1049
-			if( is_admin() && !$this->is_aui_screen()){
1050
-				// don't add wp-admin scripts if not requested to
1051
-			}else {
1052
-
1053
-				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1054
-
1055
-				// select2
1056
-				wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
1057
-
1058
-				// flatpickr
1059
-				wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
1060
-
1061
-				// Bootstrap file browser
1062
-				wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
1063
-				wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
1064
-
1065
-				$load_inline = false;
1066
-
1067
-				if ( $this->settings[ $js_setting ] == 'core-popper' ) {
1068
-					// Bootstrap bundle
1069
-					$url = $this->url . 'assets/js/bootstrap.bundle.min.js';
1070
-					wp_register_script( 'bootstrap-js-bundle', $url, array(
1071
-						'select2',
1072
-						'jquery'
1073
-					), $this->latest, $this->is_bs3_compat() );
1074
-					// if in admin then add to footer for compatibility.
1075
-					is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
1076
-					$script = $this->inline_script();
1077
-					wp_add_inline_script( 'bootstrap-js-bundle', $script );
1078
-				} elseif ( $this->settings[ $js_setting ] == 'popper' ) {
1079
-					$url = $this->url . 'assets/js/popper.min.js';
1080
-					wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
1081
-					wp_enqueue_script( 'bootstrap-js-popper' );
1082
-					$load_inline = true;
1083
-				} else {
1084
-					$load_inline = true;
1085
-				}
1086
-
1087
-				// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
1088
-				if ( $load_inline ) {
1089
-					wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
1090
-					wp_enqueue_script( 'bootstrap-dummy' );
1091
-					$script = $this->inline_script();
1092
-					wp_add_inline_script( 'bootstrap-dummy', $script );
1093
-				}
1094
-			}
1095
-
1096
-		}
1097
-
1098
-		/**
1099
-		 * Enqueue flatpickr if called.
1100
-		 */
1101
-		public function enqueue_flatpickr(){
1102
-			wp_enqueue_style( 'flatpickr' );
1103
-			wp_enqueue_script( 'flatpickr' );
1104
-		}
1105
-
1106
-		/**
1107
-		 * Get the url path to the current folder.
1108
-		 *
1109
-		 * @return string
1110
-		 */
1111
-		public function get_url() {
1112
-
1113
-			$url = '';
1114
-			// check if we are inside a plugin
1115
-			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
1116
-
1117
-			// add check in-case user has changed wp-content dir name.
1118
-			$wp_content_folder_name = basename(WP_CONTENT_DIR);
1119
-			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
1120
-			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
1121
-
1122
-			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
1123
-				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
1124
-			}
1125
-
1126
-			return $url;
1127
-		}
1128
-
1129
-		/**
1130
-		 * Register the database settings with WordPress.
1131
-		 */
1132
-		public function register_settings() {
1133
-			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
1134
-		}
1135
-
1136
-		/**
1137
-		 * Add the WordPress settings menu item.
1138
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
1139
-		 */
1140
-		public function menu_item() {
1141
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
1142
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1143
-				$this,
1144
-				'settings_page'
1145
-			) );
1146
-		}
1147
-
1148
-		/**
1149
-		 * Get a list of themes and their default JS settings.
1150
-		 *
1151
-		 * @return array
1152
-		 */
1153
-		public function theme_js_settings(){
1154
-			return array(
1155
-				'ayetheme' => 'popper',
1156
-				'listimia' => 'required',
1157
-				'listimia_backend' => 'core-popper',
1158
-				//'avada'    => 'required', // removed as we now add compatibility
1159
-			);
1160
-		}
1161
-
1162
-		/**
1163
-		 * Get the current Font Awesome output settings.
1164
-		 *
1165
-		 * @return array The array of settings.
1166
-		 */
1167
-		public function get_settings() {
1168
-
1169
-			$db_settings = get_option( 'ayecode-ui-settings' );
1170
-			$js_default = 'core-popper';
1171
-			$js_default_backend = $js_default;
1172
-
1173
-			// maybe set defaults (if no settings set)
1174
-			if(empty($db_settings)){
1175
-				$active_theme = strtolower( get_template() ); // active parent theme.
1176
-				$theme_js_settings = self::theme_js_settings();
1177
-				if(isset($theme_js_settings[$active_theme])){
1178
-					$js_default = $theme_js_settings[$active_theme];
1179
-					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1180
-				}
1181
-			}
1182
-
1183
-			$defaults = array(
1184
-				'css'       => 'compatibility', // core, compatibility
1185
-				'js'        => $js_default, // js to load, core-popper, popper
1186
-				'html_font_size'        => '16', // js to load, core-popper, popper
1187
-				'css_backend'       => 'compatibility', // core, compatibility
1188
-				'js_backend'        => $js_default_backend, // js to load, core-popper, popper
1189
-				'disable_admin'     =>  '', // URL snippets to disable loading on admin
1190
-			);
1191
-
1192
-			$settings = wp_parse_args( $db_settings, $defaults );
1193
-
1194
-			/**
1195
-			 * Filter the Bootstrap settings.
1196
-			 *
1197
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1198
-			 */
1199
-			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1200
-		}
1201
-
1038
+            return str_replace( array(
1039
+                '<script>',
1040
+                '</script>'
1041
+            ), '', $output );
1042
+        }
1043
+
1044
+        /**
1045
+         * Adds the Font Awesome JS.
1046
+         */
1047
+        public function enqueue_scripts() {
1048
+
1049
+            if( is_admin() && !$this->is_aui_screen()){
1050
+                // don't add wp-admin scripts if not requested to
1051
+            }else {
1052
+
1053
+                $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1054
+
1055
+                // select2
1056
+                wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
1057
+
1058
+                // flatpickr
1059
+                wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
1060
+
1061
+                // Bootstrap file browser
1062
+                wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
1063
+                wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
1064
+
1065
+                $load_inline = false;
1066
+
1067
+                if ( $this->settings[ $js_setting ] == 'core-popper' ) {
1068
+                    // Bootstrap bundle
1069
+                    $url = $this->url . 'assets/js/bootstrap.bundle.min.js';
1070
+                    wp_register_script( 'bootstrap-js-bundle', $url, array(
1071
+                        'select2',
1072
+                        'jquery'
1073
+                    ), $this->latest, $this->is_bs3_compat() );
1074
+                    // if in admin then add to footer for compatibility.
1075
+                    is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
1076
+                    $script = $this->inline_script();
1077
+                    wp_add_inline_script( 'bootstrap-js-bundle', $script );
1078
+                } elseif ( $this->settings[ $js_setting ] == 'popper' ) {
1079
+                    $url = $this->url . 'assets/js/popper.min.js';
1080
+                    wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
1081
+                    wp_enqueue_script( 'bootstrap-js-popper' );
1082
+                    $load_inline = true;
1083
+                } else {
1084
+                    $load_inline = true;
1085
+                }
1202 1086
 
1203
-		/**
1204
-		 * The settings page html output.
1205
-		 */
1206
-		public function settings_page() {
1207
-			if ( ! current_user_can( 'manage_options' ) ) {
1208
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1209
-			}
1210
-			?>
1087
+                // Load needed inline scripts by faking the loading of a script if the main script is not being loaded
1088
+                if ( $load_inline ) {
1089
+                    wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
1090
+                    wp_enqueue_script( 'bootstrap-dummy' );
1091
+                    $script = $this->inline_script();
1092
+                    wp_add_inline_script( 'bootstrap-dummy', $script );
1093
+                }
1094
+            }
1095
+
1096
+        }
1097
+
1098
+        /**
1099
+         * Enqueue flatpickr if called.
1100
+         */
1101
+        public function enqueue_flatpickr(){
1102
+            wp_enqueue_style( 'flatpickr' );
1103
+            wp_enqueue_script( 'flatpickr' );
1104
+        }
1105
+
1106
+        /**
1107
+         * Get the url path to the current folder.
1108
+         *
1109
+         * @return string
1110
+         */
1111
+        public function get_url() {
1112
+
1113
+            $url = '';
1114
+            // check if we are inside a plugin
1115
+            $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
1116
+
1117
+            // add check in-case user has changed wp-content dir name.
1118
+            $wp_content_folder_name = basename(WP_CONTENT_DIR);
1119
+            $dir_parts = explode("/$wp_content_folder_name/",$file_dir);
1120
+            $url_parts = explode("/$wp_content_folder_name/",plugins_url());
1121
+
1122
+            if(!empty($url_parts[0]) && !empty($dir_parts[1])){
1123
+                $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
1124
+            }
1125
+
1126
+            return $url;
1127
+        }
1128
+
1129
+        /**
1130
+         * Register the database settings with WordPress.
1131
+         */
1132
+        public function register_settings() {
1133
+            register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
1134
+        }
1135
+
1136
+        /**
1137
+         * Add the WordPress settings menu item.
1138
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
1139
+         */
1140
+        public function menu_item() {
1141
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
1142
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1143
+                $this,
1144
+                'settings_page'
1145
+            ) );
1146
+        }
1147
+
1148
+        /**
1149
+         * Get a list of themes and their default JS settings.
1150
+         *
1151
+         * @return array
1152
+         */
1153
+        public function theme_js_settings(){
1154
+            return array(
1155
+                'ayetheme' => 'popper',
1156
+                'listimia' => 'required',
1157
+                'listimia_backend' => 'core-popper',
1158
+                //'avada'    => 'required', // removed as we now add compatibility
1159
+            );
1160
+        }
1161
+
1162
+        /**
1163
+         * Get the current Font Awesome output settings.
1164
+         *
1165
+         * @return array The array of settings.
1166
+         */
1167
+        public function get_settings() {
1168
+
1169
+            $db_settings = get_option( 'ayecode-ui-settings' );
1170
+            $js_default = 'core-popper';
1171
+            $js_default_backend = $js_default;
1172
+
1173
+            // maybe set defaults (if no settings set)
1174
+            if(empty($db_settings)){
1175
+                $active_theme = strtolower( get_template() ); // active parent theme.
1176
+                $theme_js_settings = self::theme_js_settings();
1177
+                if(isset($theme_js_settings[$active_theme])){
1178
+                    $js_default = $theme_js_settings[$active_theme];
1179
+                    $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1180
+                }
1181
+            }
1182
+
1183
+            $defaults = array(
1184
+                'css'       => 'compatibility', // core, compatibility
1185
+                'js'        => $js_default, // js to load, core-popper, popper
1186
+                'html_font_size'        => '16', // js to load, core-popper, popper
1187
+                'css_backend'       => 'compatibility', // core, compatibility
1188
+                'js_backend'        => $js_default_backend, // js to load, core-popper, popper
1189
+                'disable_admin'     =>  '', // URL snippets to disable loading on admin
1190
+            );
1191
+
1192
+            $settings = wp_parse_args( $db_settings, $defaults );
1193
+
1194
+            /**
1195
+             * Filter the Bootstrap settings.
1196
+             *
1197
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1198
+             */
1199
+            return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1200
+        }
1201
+
1202
+
1203
+        /**
1204
+         * The settings page html output.
1205
+         */
1206
+        public function settings_page() {
1207
+            if ( ! current_user_can( 'manage_options' ) ) {
1208
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1209
+            }
1210
+            ?>
1211 1211
 			<div class="wrap">
1212 1212
 				<h1><?php echo $this->name; ?></h1>
1213 1213
 				<p><?php _e("Here you can adjust settings if you are having compatibility issues.",'aui');?></p>
1214 1214
 				<form method="post" action="options.php">
1215 1215
 					<?php
1216
-					settings_fields( 'ayecode-ui-settings' );
1217
-					do_settings_sections( 'ayecode-ui-settings' );
1218
-					?>
1216
+                    settings_fields( 'ayecode-ui-settings' );
1217
+                    do_settings_sections( 'ayecode-ui-settings' );
1218
+                    ?>
1219 1219
 
1220 1220
 					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
1221 1221
 					<table class="form-table wpbs-table-settings">
@@ -1295,60 +1295,60 @@  discard block
 block discarded – undo
1295 1295
 					</table>
1296 1296
 
1297 1297
 					<?php
1298
-					submit_button();
1299
-					?>
1298
+                    submit_button();
1299
+                    ?>
1300 1300
 				</form>
1301 1301
 
1302 1302
 				<div id="wpbs-version"><?php echo $this->version; ?></div>
1303 1303
 			</div>
1304 1304
 
1305 1305
 			<?php
1306
-		}
1307
-
1308
-		public function customizer_settings($wp_customize){
1309
-			$wp_customize->add_section('aui_settings', array(
1310
-				'title'    => __('AyeCode UI','aui'),
1311
-				'priority' => 120,
1312
-			));
1313
-
1314
-			//  =============================
1315
-			//  = Color Picker              =
1316
-			//  =============================
1317
-			$wp_customize->add_setting('aui_options[color_primary]', array(
1318
-				'default'           => AUI_PRIMARY_COLOR,
1319
-				'sanitize_callback' => 'sanitize_hex_color',
1320
-				'capability'        => 'edit_theme_options',
1321
-				'type'              => 'option',
1322
-				'transport'         => 'refresh',
1323
-			));
1324
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1325
-				'label'    => __('Primary Color','aui'),
1326
-				'section'  => 'aui_settings',
1327
-				'settings' => 'aui_options[color_primary]',
1328
-			)));
1329
-
1330
-			$wp_customize->add_setting('aui_options[color_secondary]', array(
1331
-				'default'           => '#6c757d',
1332
-				'sanitize_callback' => 'sanitize_hex_color',
1333
-				'capability'        => 'edit_theme_options',
1334
-				'type'              => 'option',
1335
-				'transport'         => 'refresh',
1336
-			));
1337
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1338
-				'label'    => __('Secondary Color','aui'),
1339
-				'section'  => 'aui_settings',
1340
-				'settings' => 'aui_options[color_secondary]',
1341
-			)));
1342
-		}
1343
-
1344
-		/**
1345
-		 * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1346
-		 *
1347
-		 * @return mixed
1348
-		 */
1349
-		public static function bs3_compat_css() {
1350
-			ob_start();
1351
-			?>
1306
+        }
1307
+
1308
+        public function customizer_settings($wp_customize){
1309
+            $wp_customize->add_section('aui_settings', array(
1310
+                'title'    => __('AyeCode UI','aui'),
1311
+                'priority' => 120,
1312
+            ));
1313
+
1314
+            //  =============================
1315
+            //  = Color Picker              =
1316
+            //  =============================
1317
+            $wp_customize->add_setting('aui_options[color_primary]', array(
1318
+                'default'           => AUI_PRIMARY_COLOR,
1319
+                'sanitize_callback' => 'sanitize_hex_color',
1320
+                'capability'        => 'edit_theme_options',
1321
+                'type'              => 'option',
1322
+                'transport'         => 'refresh',
1323
+            ));
1324
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1325
+                'label'    => __('Primary Color','aui'),
1326
+                'section'  => 'aui_settings',
1327
+                'settings' => 'aui_options[color_primary]',
1328
+            )));
1329
+
1330
+            $wp_customize->add_setting('aui_options[color_secondary]', array(
1331
+                'default'           => '#6c757d',
1332
+                'sanitize_callback' => 'sanitize_hex_color',
1333
+                'capability'        => 'edit_theme_options',
1334
+                'type'              => 'option',
1335
+                'transport'         => 'refresh',
1336
+            ));
1337
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1338
+                'label'    => __('Secondary Color','aui'),
1339
+                'section'  => 'aui_settings',
1340
+                'settings' => 'aui_options[color_secondary]',
1341
+            )));
1342
+        }
1343
+
1344
+        /**
1345
+         * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1346
+         *
1347
+         * @return mixed
1348
+         */
1349
+        public static function bs3_compat_css() {
1350
+            ob_start();
1351
+            ?>
1352 1352
 			<style>
1353 1353
 			/* Bootstrap 3 compatibility */
1354 1354
 			body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;}
@@ -1374,579 +1374,579 @@  discard block
 block discarded – undo
1374 1374
 			<?php } ?>
1375 1375
 			</style>
1376 1376
 			<?php
1377
-			return str_replace( array(
1378
-				'<style>',
1379
-				'</style>'
1380
-			), '', ob_get_clean());
1381
-		}
1377
+            return str_replace( array(
1378
+                '<style>',
1379
+                '</style>'
1380
+            ), '', ob_get_clean());
1381
+        }
1382 1382
 
1383 1383
 
1384
-		public static function custom_css($compatibility = true) {
1385
-			$settings = get_option('aui_options');
1384
+        public static function custom_css($compatibility = true) {
1385
+            $settings = get_option('aui_options');
1386 1386
 
1387
-			ob_start();
1387
+            ob_start();
1388 1388
 
1389
-			$primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR;
1390
-			$secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR;
1391
-				//AUI_PRIMARY_COLOR_ORIGINAL
1392
-			?>
1389
+            $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR;
1390
+            $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR;
1391
+                //AUI_PRIMARY_COLOR_ORIGINAL
1392
+            ?>
1393 1393
 			<style>
1394 1394
 				<?php
1395 1395
 
1396
-					// BS v3 compat
1397
-					if( self::is_bs3_compat() ){
1398
-					    echo self::bs3_compat_css();
1399
-					}
1396
+                    // BS v3 compat
1397
+                    if( self::is_bs3_compat() ){
1398
+                        echo self::bs3_compat_css();
1399
+                    }
1400 1400
 
1401
-					if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1402
-						echo self::css_primary($primary_color,$compatibility);
1403
-					}
1401
+                    if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1402
+                        echo self::css_primary($primary_color,$compatibility);
1403
+                    }
1404 1404
 
1405
-					if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1406
-						echo self::css_secondary($settings['color_secondary'],$compatibility);
1407
-					}
1405
+                    if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1406
+                        echo self::css_secondary($settings['color_secondary'],$compatibility);
1407
+                    }
1408 1408
 
1409
-					// Set admin bar z-index lower when modal is open.
1410
-					echo ' body.modal-open #wpadminbar{z-index:999}';
1409
+                    // Set admin bar z-index lower when modal is open.
1410
+                    echo ' body.modal-open #wpadminbar{z-index:999}';
1411 1411
                 ?>
1412 1412
 			</style>
1413 1413
 			<?php
1414 1414
 
1415 1415
 
1416
-			/*
1416
+            /*
1417 1417
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1418 1418
 			 */
1419
-			return str_replace( array(
1420
-				'<style>',
1421
-				'</style>'
1422
-			), '', ob_get_clean());
1423
-		}
1424
-
1425
-		/**
1426
-		 * Check if we should add booststrap 3 compatibility changes.
1427
-		 *
1428
-		 * @return bool
1429
-		 */
1430
-		public static function is_bs3_compat(){
1431
-			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1432
-		}
1433
-
1434
-		public static function css_primary($color_code,$compatibility){;
1435
-			$color_code = sanitize_hex_color($color_code);
1436
-			if(!$color_code){return '';}
1437
-			/**
1438
-			 * c = color, b = background color, o = border-color, f = fill
1439
-			 */
1440
-			$selectors = array(
1441
-				'a' => array('c'),
1442
-				'.btn-primary' => array('b','o'),
1443
-				'.btn-primary.disabled' => array('b','o'),
1444
-				'.btn-primary:disabled' => array('b','o'),
1445
-				'.btn-outline-primary' => array('c','o'),
1446
-				'.btn-outline-primary:hover' => array('b','o'),
1447
-				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1448
-				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1449
-				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1450
-				'.btn-link' => array('c'),
1451
-				'.dropdown-item.active' => array('b'),
1452
-				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1453
-				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1419
+            return str_replace( array(
1420
+                '<style>',
1421
+                '</style>'
1422
+            ), '', ob_get_clean());
1423
+        }
1424
+
1425
+        /**
1426
+         * Check if we should add booststrap 3 compatibility changes.
1427
+         *
1428
+         * @return bool
1429
+         */
1430
+        public static function is_bs3_compat(){
1431
+            return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1432
+        }
1433
+
1434
+        public static function css_primary($color_code,$compatibility){;
1435
+            $color_code = sanitize_hex_color($color_code);
1436
+            if(!$color_code){return '';}
1437
+            /**
1438
+             * c = color, b = background color, o = border-color, f = fill
1439
+             */
1440
+            $selectors = array(
1441
+                'a' => array('c'),
1442
+                '.btn-primary' => array('b','o'),
1443
+                '.btn-primary.disabled' => array('b','o'),
1444
+                '.btn-primary:disabled' => array('b','o'),
1445
+                '.btn-outline-primary' => array('c','o'),
1446
+                '.btn-outline-primary:hover' => array('b','o'),
1447
+                '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1448
+                '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1449
+                '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1450
+                '.btn-link' => array('c'),
1451
+                '.dropdown-item.active' => array('b'),
1452
+                '.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1453
+                '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1454 1454
 //				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1455 1455
 //				'.custom-range::-moz-range-thumb' => array('b'),
1456 1456
 //				'.custom-range::-ms-thumb' => array('b'),
1457
-				'.nav-pills .nav-link.active' => array('b'),
1458
-				'.nav-pills .show>.nav-link' => array('b'),
1459
-				'.page-link' => array('c'),
1460
-				'.page-item.active .page-link' => array('b','o'),
1461
-				'.badge-primary' => array('b'),
1462
-				'.alert-primary' => array('b','o'),
1463
-				'.progress-bar' => array('b'),
1464
-				'.list-group-item.active' => array('b','o'),
1465
-				'.bg-primary' => array('b','f'),
1466
-				'.btn-link.btn-primary' => array('c'),
1467
-				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1468
-			);
1469
-
1470
-			$important_selectors = array(
1471
-				'.bg-primary' => array('b','f'),
1472
-				'.border-primary' => array('o'),
1473
-				'.text-primary' => array('c'),
1474
-			);
1475
-
1476
-			$color = array();
1477
-			$color_i = array();
1478
-			$background = array();
1479
-			$background_i = array();
1480
-			$border = array();
1481
-			$border_i = array();
1482
-			$fill = array();
1483
-			$fill_i = array();
1484
-
1485
-			$output = '';
1486
-
1487
-			// build rules into each type
1488
-			foreach($selectors as $selector => $types){
1489
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1490
-				$types = array_combine($types,$types);
1491
-				if(isset($types['c'])){$color[] = $selector;}
1492
-				if(isset($types['b'])){$background[] = $selector;}
1493
-				if(isset($types['o'])){$border[] = $selector;}
1494
-				if(isset($types['f'])){$fill[] = $selector;}
1495
-			}
1496
-
1497
-			// build rules into each type
1498
-			foreach($important_selectors as $selector => $types){
1499
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1500
-				$types = array_combine($types,$types);
1501
-				if(isset($types['c'])){$color_i[] = $selector;}
1502
-				if(isset($types['b'])){$background_i[] = $selector;}
1503
-				if(isset($types['o'])){$border_i[] = $selector;}
1504
-				if(isset($types['f'])){$fill_i[] = $selector;}
1505
-			}
1506
-
1507
-			// add any color rules
1508
-			if(!empty($color)){
1509
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1510
-			}
1511
-			if(!empty($color_i)){
1512
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1513
-			}
1514
-
1515
-			// add any background color rules
1516
-			if(!empty($background)){
1517
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1518
-			}
1519
-			if(!empty($background_i)){
1520
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1521
-			}
1522
-
1523
-			// add any border color rules
1524
-			if(!empty($border)){
1525
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1526
-			}
1527
-			if(!empty($border_i)){
1528
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1529
-			}
1530
-
1531
-			// add any fill color rules
1532
-			if(!empty($fill)){
1533
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1534
-			}
1535
-			if(!empty($fill_i)){
1536
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1537
-			}
1538
-
1539
-
1540
-			$prefix = $compatibility ? ".bsui " : "";
1541
-
1542
-			// darken
1543
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1544
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1545
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1546
-
1547
-			// lighten
1548
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1549
-
1550
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1551
-			$op_25 = $color_code."40"; // 25% opacity
1552
-
1553
-
1554
-			// button states
1555
-			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1556
-			$output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1557
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1558
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1559
-
1560
-
1561
-			// dropdown's
1562
-			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1563
-
1564
-
1565
-			// input states
1566
-			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1567
-
1568
-			// page link
1569
-			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1570
-
1571
-			return $output;
1572
-		}
1573
-
1574
-		public static function css_secondary($color_code,$compatibility){;
1575
-			$color_code = sanitize_hex_color($color_code);
1576
-			if(!$color_code){return '';}
1577
-			/**
1578
-			 * c = color, b = background color, o = border-color, f = fill
1579
-			 */
1580
-			$selectors = array(
1581
-				'.btn-secondary' => array('b','o'),
1582
-				'.btn-secondary.disabled' => array('b','o'),
1583
-				'.btn-secondary:disabled' => array('b','o'),
1584
-				'.btn-outline-secondary' => array('c','o'),
1585
-				'.btn-outline-secondary:hover' => array('b','o'),
1586
-				'.btn-outline-secondary.disabled' => array('c'),
1587
-				'.btn-outline-secondary:disabled' => array('c'),
1588
-				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1589
-				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1590
-				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1591
-				'.badge-secondary' => array('b'),
1592
-				'.alert-secondary' => array('b','o'),
1593
-				'.btn-link.btn-secondary' => array('c'),
1594
-			);
1595
-
1596
-			$important_selectors = array(
1597
-				'.bg-secondary' => array('b','f'),
1598
-				'.border-secondary' => array('o'),
1599
-				'.text-secondary' => array('c'),
1600
-			);
1601
-
1602
-			$color = array();
1603
-			$color_i = array();
1604
-			$background = array();
1605
-			$background_i = array();
1606
-			$border = array();
1607
-			$border_i = array();
1608
-			$fill = array();
1609
-			$fill_i = array();
1610
-
1611
-			$output = '';
1612
-
1613
-			// build rules into each type
1614
-			foreach($selectors as $selector => $types){
1615
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1616
-				$types = array_combine($types,$types);
1617
-				if(isset($types['c'])){$color[] = $selector;}
1618
-				if(isset($types['b'])){$background[] = $selector;}
1619
-				if(isset($types['o'])){$border[] = $selector;}
1620
-				if(isset($types['f'])){$fill[] = $selector;}
1621
-			}
1622
-
1623
-			// build rules into each type
1624
-			foreach($important_selectors as $selector => $types){
1625
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1626
-				$types = array_combine($types,$types);
1627
-				if(isset($types['c'])){$color_i[] = $selector;}
1628
-				if(isset($types['b'])){$background_i[] = $selector;}
1629
-				if(isset($types['o'])){$border_i[] = $selector;}
1630
-				if(isset($types['f'])){$fill_i[] = $selector;}
1631
-			}
1632
-
1633
-			// add any color rules
1634
-			if(!empty($color)){
1635
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1636
-			}
1637
-			if(!empty($color_i)){
1638
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1639
-			}
1640
-
1641
-			// add any background color rules
1642
-			if(!empty($background)){
1643
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1644
-			}
1645
-			if(!empty($background_i)){
1646
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1647
-			}
1648
-
1649
-			// add any border color rules
1650
-			if(!empty($border)){
1651
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1652
-			}
1653
-			if(!empty($border_i)){
1654
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1655
-			}
1656
-
1657
-			// add any fill color rules
1658
-			if(!empty($fill)){
1659
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1660
-			}
1661
-			if(!empty($fill_i)){
1662
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1663
-			}
1664
-
1665
-
1666
-			$prefix = $compatibility ? ".bsui " : "";
1667
-
1668
-			// darken
1669
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1670
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1671
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1672
-
1673
-			// lighten
1674
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1675
-
1676
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1677
-			$op_25 = $color_code."40"; // 25% opacity
1678
-
1679
-
1680
-			// button states
1681
-			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1682
-			$output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1683
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1684
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1685
-
1686
-
1687
-			return $output;
1688
-		}
1689
-
1690
-		/**
1691
-		 * Increases or decreases the brightness of a color by a percentage of the current brightness.
1692
-		 *
1693
-		 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1694
-		 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1695
-		 *
1696
-		 * @return  string
1697
-		 */
1698
-		public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1699
-			$hexCode = ltrim($hexCode, '#');
1700
-
1701
-			if (strlen($hexCode) == 3) {
1702
-				$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1703
-			}
1704
-
1705
-			$hexCode = array_map('hexdec', str_split($hexCode, 2));
1706
-
1707
-			foreach ($hexCode as & $color) {
1708
-				$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1709
-				$adjustAmount = ceil($adjustableLimit * $adjustPercent);
1710
-
1711
-				$color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1712
-			}
1713
-
1714
-			return '#' . implode($hexCode);
1715
-		}
1716
-
1717
-		/**
1718
-		 * Check if we should display examples.
1719
-		 */
1720
-		public function maybe_show_examples(){
1721
-			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1722
-				echo "<head>";
1723
-				wp_head();
1724
-				echo "</head>";
1725
-				echo "<body>";
1726
-				echo $this->get_examples();
1727
-				echo "</body>";
1728
-				exit;
1729
-			}
1730
-		}
1731
-
1732
-		/**
1733
-		 * Get developer examples.
1734
-		 *
1735
-		 * @return string
1736
-		 */
1737
-		public function get_examples(){
1738
-			$output = '';
1739
-
1740
-
1741
-			// open form
1742
-			$output .= "<form class='p-5 m-5 border rounded'>";
1743
-
1744
-			// input example
1745
-			$output .= aui()->input(array(
1746
-				'type'  =>  'text',
1747
-				'id'    =>  'text-example',
1748
-				'name'    =>  'text-example',
1749
-				'placeholder'   => 'text placeholder',
1750
-				'title'   => 'Text input example',
1751
-				'value' =>  '',
1752
-				'required'  => false,
1753
-				'help_text' => 'help text',
1754
-				'label' => 'Text input example label'
1755
-			));
1756
-
1757
-			// input example
1758
-			$output .= aui()->input(array(
1759
-				'type'  =>  'url',
1760
-				'id'    =>  'text-example2',
1761
-				'name'    =>  'text-example',
1762
-				'placeholder'   => 'url placeholder',
1763
-				'title'   => 'Text input example',
1764
-				'value' =>  '',
1765
-				'required'  => false,
1766
-				'help_text' => 'help text',
1767
-				'label' => 'Text input example label'
1768
-			));
1769
-
1770
-			// checkbox example
1771
-			$output .= aui()->input(array(
1772
-				'type'  =>  'checkbox',
1773
-				'id'    =>  'checkbox-example',
1774
-				'name'    =>  'checkbox-example',
1775
-				'placeholder'   => 'checkbox-example',
1776
-				'title'   => 'Checkbox example',
1777
-				'value' =>  '1',
1778
-				'checked'   => true,
1779
-				'required'  => false,
1780
-				'help_text' => 'help text',
1781
-				'label' => 'Checkbox checked'
1782
-			));
1783
-
1784
-			// checkbox example
1785
-			$output .= aui()->input(array(
1786
-				'type'  =>  'checkbox',
1787
-				'id'    =>  'checkbox-example2',
1788
-				'name'    =>  'checkbox-example2',
1789
-				'placeholder'   => 'checkbox-example',
1790
-				'title'   => 'Checkbox example',
1791
-				'value' =>  '1',
1792
-				'checked'   => false,
1793
-				'required'  => false,
1794
-				'help_text' => 'help text',
1795
-				'label' => 'Checkbox un-checked'
1796
-			));
1797
-
1798
-			// switch example
1799
-			$output .= aui()->input(array(
1800
-				'type'  =>  'checkbox',
1801
-				'id'    =>  'switch-example',
1802
-				'name'    =>  'switch-example',
1803
-				'placeholder'   => 'checkbox-example',
1804
-				'title'   => 'Switch example',
1805
-				'value' =>  '1',
1806
-				'checked'   => true,
1807
-				'switch'    => true,
1808
-				'required'  => false,
1809
-				'help_text' => 'help text',
1810
-				'label' => 'Switch on'
1811
-			));
1812
-
1813
-			// switch example
1814
-			$output .= aui()->input(array(
1815
-				'type'  =>  'checkbox',
1816
-				'id'    =>  'switch-example2',
1817
-				'name'    =>  'switch-example2',
1818
-				'placeholder'   => 'checkbox-example',
1819
-				'title'   => 'Switch example',
1820
-				'value' =>  '1',
1821
-				'checked'   => false,
1822
-				'switch'    => true,
1823
-				'required'  => false,
1824
-				'help_text' => 'help text',
1825
-				'label' => 'Switch off'
1826
-			));
1827
-
1828
-			// close form
1829
-			$output .= "</form>";
1830
-
1831
-			return $output;
1832
-		}
1833
-
1834
-		/**
1835
-		 * Calendar params.
1836
-		 *
1837
-		 * @since 0.1.44
1838
-		 *
1839
-		 * @return array Calendar params.
1840
-		 */
1841
-		public static function calendar_params() {
1842
-			$params = array(
1843
-				'month_long_1' => __( 'January', 'aui' ),
1844
-				'month_long_2' => __( 'February', 'aui' ),
1845
-				'month_long_3' => __( 'March', 'aui' ),
1846
-				'month_long_4' => __( 'April', 'aui' ),
1847
-				'month_long_5' => __( 'May', 'aui' ),
1848
-				'month_long_6' => __( 'June', 'aui' ),
1849
-				'month_long_7' => __( 'July', 'aui' ),
1850
-				'month_long_8' => __( 'August', 'aui' ),
1851
-				'month_long_9' => __( 'September', 'aui' ),
1852
-				'month_long_10' => __( 'October', 'aui' ),
1853
-				'month_long_11' => __( 'November', 'aui' ),
1854
-				'month_long_12' => __( 'December', 'aui' ),
1855
-				'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ),
1856
-				'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ),
1857
-				'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ),
1858
-				'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ),
1859
-				'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ),
1860
-				'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ),
1861
-				'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ),
1862
-				'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ),
1863
-				'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ),
1864
-				'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ),
1865
-				'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ),
1866
-				'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ),
1867
-				'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ),
1868
-				'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ),
1869
-				'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ),
1870
-				'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ),
1871
-				'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ),
1872
-				'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ),
1873
-				'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ),
1874
-				'day_s2_1' => __( 'Su', 'aui' ),
1875
-				'day_s2_2' => __( 'Mo', 'aui' ),
1876
-				'day_s2_3' => __( 'Tu', 'aui' ),
1877
-				'day_s2_4' => __( 'We', 'aui' ),
1878
-				'day_s2_5' => __( 'Th', 'aui' ),
1879
-				'day_s2_6' => __( 'Fr', 'aui' ),
1880
-				'day_s2_7' => __( 'Sa', 'aui' ),
1881
-				'day_s3_1' => __( 'Sun', 'aui' ),
1882
-				'day_s3_2' => __( 'Mon', 'aui' ),
1883
-				'day_s3_3' => __( 'Tue', 'aui' ),
1884
-				'day_s3_4' => __( 'Wed', 'aui' ),
1885
-				'day_s3_5' => __( 'Thu', 'aui' ),
1886
-				'day_s3_6' => __( 'Fri', 'aui' ),
1887
-				'day_s3_7' => __( 'Sat', 'aui' ),
1888
-				'day_s5_1' => __( 'Sunday', 'aui' ),
1889
-				'day_s5_2' => __( 'Monday', 'aui' ),
1890
-				'day_s5_3' => __( 'Tuesday', 'aui' ),
1891
-				'day_s5_4' => __( 'Wednesday', 'aui' ),
1892
-				'day_s5_5' => __( 'Thursday', 'aui' ),
1893
-				'day_s5_6' => __( 'Friday', 'aui' ),
1894
-				'day_s5_7' => __( 'Saturday', 'aui' ),
1895
-				'am_lower' => __( 'am', 'aui' ),
1896
-				'pm_lower' => __( 'pm', 'aui' ),
1897
-				'am_upper' => __( 'AM', 'aui' ),
1898
-				'pm_upper' => __( 'PM', 'aui' ),
1899
-				'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
1900
-				'time_24hr' => false,
1901
-				'year' => __( 'Year', 'aui' ),
1902
-				'hour' => __( 'Hour', 'aui' ),
1903
-				'minute' => __( 'Minute', 'aui' ),
1904
-				'weekAbbreviation' => __( 'Wk', 'aui' ),
1905
-				'rangeSeparator' => __( ' to ', 'aui' ),
1906
-				'scrollTitle' => __( 'Scroll to increment', 'aui' ),
1907
-				'toggleTitle' => __( 'Click to toggle', 'aui' )
1908
-			);
1909
-
1910
-			return apply_filters( 'ayecode_ui_calendar_params', $params );
1911
-		}
1912
-
1913
-		/**
1914
-		 * Flatpickr calendar localize.
1915
-		 *
1916
-		 * @since 0.1.44
1917
-		 *
1918
-		 * @return string Calendar locale.
1919
-		 */
1920
-		public static function flatpickr_locale() {
1921
-			$params = self::calendar_params();
1922
-
1923
-			if ( is_string( $params ) ) {
1924
-				$params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
1925
-			} else {
1926
-				foreach ( (array) $params as $key => $value ) {
1927
-					if ( ! is_scalar( $value ) ) {
1928
-						continue;
1929
-					}
1930
-
1931
-					$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
1932
-				}
1933
-			}
1457
+                '.nav-pills .nav-link.active' => array('b'),
1458
+                '.nav-pills .show>.nav-link' => array('b'),
1459
+                '.page-link' => array('c'),
1460
+                '.page-item.active .page-link' => array('b','o'),
1461
+                '.badge-primary' => array('b'),
1462
+                '.alert-primary' => array('b','o'),
1463
+                '.progress-bar' => array('b'),
1464
+                '.list-group-item.active' => array('b','o'),
1465
+                '.bg-primary' => array('b','f'),
1466
+                '.btn-link.btn-primary' => array('c'),
1467
+                '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1468
+            );
1469
+
1470
+            $important_selectors = array(
1471
+                '.bg-primary' => array('b','f'),
1472
+                '.border-primary' => array('o'),
1473
+                '.text-primary' => array('c'),
1474
+            );
1475
+
1476
+            $color = array();
1477
+            $color_i = array();
1478
+            $background = array();
1479
+            $background_i = array();
1480
+            $border = array();
1481
+            $border_i = array();
1482
+            $fill = array();
1483
+            $fill_i = array();
1484
+
1485
+            $output = '';
1486
+
1487
+            // build rules into each type
1488
+            foreach($selectors as $selector => $types){
1489
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1490
+                $types = array_combine($types,$types);
1491
+                if(isset($types['c'])){$color[] = $selector;}
1492
+                if(isset($types['b'])){$background[] = $selector;}
1493
+                if(isset($types['o'])){$border[] = $selector;}
1494
+                if(isset($types['f'])){$fill[] = $selector;}
1495
+            }
1496
+
1497
+            // build rules into each type
1498
+            foreach($important_selectors as $selector => $types){
1499
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1500
+                $types = array_combine($types,$types);
1501
+                if(isset($types['c'])){$color_i[] = $selector;}
1502
+                if(isset($types['b'])){$background_i[] = $selector;}
1503
+                if(isset($types['o'])){$border_i[] = $selector;}
1504
+                if(isset($types['f'])){$fill_i[] = $selector;}
1505
+            }
1506
+
1507
+            // add any color rules
1508
+            if(!empty($color)){
1509
+                $output .= implode(",",$color) . "{color: $color_code;} ";
1510
+            }
1511
+            if(!empty($color_i)){
1512
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1513
+            }
1514
+
1515
+            // add any background color rules
1516
+            if(!empty($background)){
1517
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1518
+            }
1519
+            if(!empty($background_i)){
1520
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1521
+            }
1522
+
1523
+            // add any border color rules
1524
+            if(!empty($border)){
1525
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1526
+            }
1527
+            if(!empty($border_i)){
1528
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1529
+            }
1530
+
1531
+            // add any fill color rules
1532
+            if(!empty($fill)){
1533
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1534
+            }
1535
+            if(!empty($fill_i)){
1536
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1537
+            }
1538
+
1539
+
1540
+            $prefix = $compatibility ? ".bsui " : "";
1541
+
1542
+            // darken
1543
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1544
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1545
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1546
+
1547
+            // lighten
1548
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1549
+
1550
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1551
+            $op_25 = $color_code."40"; // 25% opacity
1552
+
1553
+
1554
+            // button states
1555
+            $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1556
+            $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1557
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1558
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1559
+
1560
+
1561
+            // dropdown's
1562
+            $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1563
+
1564
+
1565
+            // input states
1566
+            $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1567
+
1568
+            // page link
1569
+            $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1570
+
1571
+            return $output;
1572
+        }
1573
+
1574
+        public static function css_secondary($color_code,$compatibility){;
1575
+            $color_code = sanitize_hex_color($color_code);
1576
+            if(!$color_code){return '';}
1577
+            /**
1578
+             * c = color, b = background color, o = border-color, f = fill
1579
+             */
1580
+            $selectors = array(
1581
+                '.btn-secondary' => array('b','o'),
1582
+                '.btn-secondary.disabled' => array('b','o'),
1583
+                '.btn-secondary:disabled' => array('b','o'),
1584
+                '.btn-outline-secondary' => array('c','o'),
1585
+                '.btn-outline-secondary:hover' => array('b','o'),
1586
+                '.btn-outline-secondary.disabled' => array('c'),
1587
+                '.btn-outline-secondary:disabled' => array('c'),
1588
+                '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1589
+                '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1590
+                '.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1591
+                '.badge-secondary' => array('b'),
1592
+                '.alert-secondary' => array('b','o'),
1593
+                '.btn-link.btn-secondary' => array('c'),
1594
+            );
1595
+
1596
+            $important_selectors = array(
1597
+                '.bg-secondary' => array('b','f'),
1598
+                '.border-secondary' => array('o'),
1599
+                '.text-secondary' => array('c'),
1600
+            );
1601
+
1602
+            $color = array();
1603
+            $color_i = array();
1604
+            $background = array();
1605
+            $background_i = array();
1606
+            $border = array();
1607
+            $border_i = array();
1608
+            $fill = array();
1609
+            $fill_i = array();
1610
+
1611
+            $output = '';
1612
+
1613
+            // build rules into each type
1614
+            foreach($selectors as $selector => $types){
1615
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1616
+                $types = array_combine($types,$types);
1617
+                if(isset($types['c'])){$color[] = $selector;}
1618
+                if(isset($types['b'])){$background[] = $selector;}
1619
+                if(isset($types['o'])){$border[] = $selector;}
1620
+                if(isset($types['f'])){$fill[] = $selector;}
1621
+            }
1622
+
1623
+            // build rules into each type
1624
+            foreach($important_selectors as $selector => $types){
1625
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1626
+                $types = array_combine($types,$types);
1627
+                if(isset($types['c'])){$color_i[] = $selector;}
1628
+                if(isset($types['b'])){$background_i[] = $selector;}
1629
+                if(isset($types['o'])){$border_i[] = $selector;}
1630
+                if(isset($types['f'])){$fill_i[] = $selector;}
1631
+            }
1632
+
1633
+            // add any color rules
1634
+            if(!empty($color)){
1635
+                $output .= implode(",",$color) . "{color: $color_code;} ";
1636
+            }
1637
+            if(!empty($color_i)){
1638
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1639
+            }
1640
+
1641
+            // add any background color rules
1642
+            if(!empty($background)){
1643
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1644
+            }
1645
+            if(!empty($background_i)){
1646
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1647
+            }
1648
+
1649
+            // add any border color rules
1650
+            if(!empty($border)){
1651
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1652
+            }
1653
+            if(!empty($border_i)){
1654
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1655
+            }
1656
+
1657
+            // add any fill color rules
1658
+            if(!empty($fill)){
1659
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1660
+            }
1661
+            if(!empty($fill_i)){
1662
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1663
+            }
1664
+
1665
+
1666
+            $prefix = $compatibility ? ".bsui " : "";
1667
+
1668
+            // darken
1669
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1670
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1671
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1672
+
1673
+            // lighten
1674
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1675
+
1676
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1677
+            $op_25 = $color_code."40"; // 25% opacity
1678
+
1679
+
1680
+            // button states
1681
+            $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1682
+            $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1683
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1684
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1685
+
1686
+
1687
+            return $output;
1688
+        }
1689
+
1690
+        /**
1691
+         * Increases or decreases the brightness of a color by a percentage of the current brightness.
1692
+         *
1693
+         * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1694
+         * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1695
+         *
1696
+         * @return  string
1697
+         */
1698
+        public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1699
+            $hexCode = ltrim($hexCode, '#');
1700
+
1701
+            if (strlen($hexCode) == 3) {
1702
+                $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1703
+            }
1704
+
1705
+            $hexCode = array_map('hexdec', str_split($hexCode, 2));
1706
+
1707
+            foreach ($hexCode as & $color) {
1708
+                $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1709
+                $adjustAmount = ceil($adjustableLimit * $adjustPercent);
1710
+
1711
+                $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1712
+            }
1713
+
1714
+            return '#' . implode($hexCode);
1715
+        }
1716
+
1717
+        /**
1718
+         * Check if we should display examples.
1719
+         */
1720
+        public function maybe_show_examples(){
1721
+            if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1722
+                echo "<head>";
1723
+                wp_head();
1724
+                echo "</head>";
1725
+                echo "<body>";
1726
+                echo $this->get_examples();
1727
+                echo "</body>";
1728
+                exit;
1729
+            }
1730
+        }
1731
+
1732
+        /**
1733
+         * Get developer examples.
1734
+         *
1735
+         * @return string
1736
+         */
1737
+        public function get_examples(){
1738
+            $output = '';
1739
+
1740
+
1741
+            // open form
1742
+            $output .= "<form class='p-5 m-5 border rounded'>";
1743
+
1744
+            // input example
1745
+            $output .= aui()->input(array(
1746
+                'type'  =>  'text',
1747
+                'id'    =>  'text-example',
1748
+                'name'    =>  'text-example',
1749
+                'placeholder'   => 'text placeholder',
1750
+                'title'   => 'Text input example',
1751
+                'value' =>  '',
1752
+                'required'  => false,
1753
+                'help_text' => 'help text',
1754
+                'label' => 'Text input example label'
1755
+            ));
1756
+
1757
+            // input example
1758
+            $output .= aui()->input(array(
1759
+                'type'  =>  'url',
1760
+                'id'    =>  'text-example2',
1761
+                'name'    =>  'text-example',
1762
+                'placeholder'   => 'url placeholder',
1763
+                'title'   => 'Text input example',
1764
+                'value' =>  '',
1765
+                'required'  => false,
1766
+                'help_text' => 'help text',
1767
+                'label' => 'Text input example label'
1768
+            ));
1769
+
1770
+            // checkbox example
1771
+            $output .= aui()->input(array(
1772
+                'type'  =>  'checkbox',
1773
+                'id'    =>  'checkbox-example',
1774
+                'name'    =>  'checkbox-example',
1775
+                'placeholder'   => 'checkbox-example',
1776
+                'title'   => 'Checkbox example',
1777
+                'value' =>  '1',
1778
+                'checked'   => true,
1779
+                'required'  => false,
1780
+                'help_text' => 'help text',
1781
+                'label' => 'Checkbox checked'
1782
+            ));
1783
+
1784
+            // checkbox example
1785
+            $output .= aui()->input(array(
1786
+                'type'  =>  'checkbox',
1787
+                'id'    =>  'checkbox-example2',
1788
+                'name'    =>  'checkbox-example2',
1789
+                'placeholder'   => 'checkbox-example',
1790
+                'title'   => 'Checkbox example',
1791
+                'value' =>  '1',
1792
+                'checked'   => false,
1793
+                'required'  => false,
1794
+                'help_text' => 'help text',
1795
+                'label' => 'Checkbox un-checked'
1796
+            ));
1797
+
1798
+            // switch example
1799
+            $output .= aui()->input(array(
1800
+                'type'  =>  'checkbox',
1801
+                'id'    =>  'switch-example',
1802
+                'name'    =>  'switch-example',
1803
+                'placeholder'   => 'checkbox-example',
1804
+                'title'   => 'Switch example',
1805
+                'value' =>  '1',
1806
+                'checked'   => true,
1807
+                'switch'    => true,
1808
+                'required'  => false,
1809
+                'help_text' => 'help text',
1810
+                'label' => 'Switch on'
1811
+            ));
1812
+
1813
+            // switch example
1814
+            $output .= aui()->input(array(
1815
+                'type'  =>  'checkbox',
1816
+                'id'    =>  'switch-example2',
1817
+                'name'    =>  'switch-example2',
1818
+                'placeholder'   => 'checkbox-example',
1819
+                'title'   => 'Switch example',
1820
+                'value' =>  '1',
1821
+                'checked'   => false,
1822
+                'switch'    => true,
1823
+                'required'  => false,
1824
+                'help_text' => 'help text',
1825
+                'label' => 'Switch off'
1826
+            ));
1827
+
1828
+            // close form
1829
+            $output .= "</form>";
1830
+
1831
+            return $output;
1832
+        }
1833
+
1834
+        /**
1835
+         * Calendar params.
1836
+         *
1837
+         * @since 0.1.44
1838
+         *
1839
+         * @return array Calendar params.
1840
+         */
1841
+        public static function calendar_params() {
1842
+            $params = array(
1843
+                'month_long_1' => __( 'January', 'aui' ),
1844
+                'month_long_2' => __( 'February', 'aui' ),
1845
+                'month_long_3' => __( 'March', 'aui' ),
1846
+                'month_long_4' => __( 'April', 'aui' ),
1847
+                'month_long_5' => __( 'May', 'aui' ),
1848
+                'month_long_6' => __( 'June', 'aui' ),
1849
+                'month_long_7' => __( 'July', 'aui' ),
1850
+                'month_long_8' => __( 'August', 'aui' ),
1851
+                'month_long_9' => __( 'September', 'aui' ),
1852
+                'month_long_10' => __( 'October', 'aui' ),
1853
+                'month_long_11' => __( 'November', 'aui' ),
1854
+                'month_long_12' => __( 'December', 'aui' ),
1855
+                'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ),
1856
+                'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ),
1857
+                'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ),
1858
+                'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ),
1859
+                'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ),
1860
+                'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ),
1861
+                'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ),
1862
+                'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ),
1863
+                'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ),
1864
+                'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ),
1865
+                'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ),
1866
+                'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ),
1867
+                'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ),
1868
+                'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ),
1869
+                'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ),
1870
+                'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ),
1871
+                'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ),
1872
+                'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ),
1873
+                'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ),
1874
+                'day_s2_1' => __( 'Su', 'aui' ),
1875
+                'day_s2_2' => __( 'Mo', 'aui' ),
1876
+                'day_s2_3' => __( 'Tu', 'aui' ),
1877
+                'day_s2_4' => __( 'We', 'aui' ),
1878
+                'day_s2_5' => __( 'Th', 'aui' ),
1879
+                'day_s2_6' => __( 'Fr', 'aui' ),
1880
+                'day_s2_7' => __( 'Sa', 'aui' ),
1881
+                'day_s3_1' => __( 'Sun', 'aui' ),
1882
+                'day_s3_2' => __( 'Mon', 'aui' ),
1883
+                'day_s3_3' => __( 'Tue', 'aui' ),
1884
+                'day_s3_4' => __( 'Wed', 'aui' ),
1885
+                'day_s3_5' => __( 'Thu', 'aui' ),
1886
+                'day_s3_6' => __( 'Fri', 'aui' ),
1887
+                'day_s3_7' => __( 'Sat', 'aui' ),
1888
+                'day_s5_1' => __( 'Sunday', 'aui' ),
1889
+                'day_s5_2' => __( 'Monday', 'aui' ),
1890
+                'day_s5_3' => __( 'Tuesday', 'aui' ),
1891
+                'day_s5_4' => __( 'Wednesday', 'aui' ),
1892
+                'day_s5_5' => __( 'Thursday', 'aui' ),
1893
+                'day_s5_6' => __( 'Friday', 'aui' ),
1894
+                'day_s5_7' => __( 'Saturday', 'aui' ),
1895
+                'am_lower' => __( 'am', 'aui' ),
1896
+                'pm_lower' => __( 'pm', 'aui' ),
1897
+                'am_upper' => __( 'AM', 'aui' ),
1898
+                'pm_upper' => __( 'PM', 'aui' ),
1899
+                'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
1900
+                'time_24hr' => false,
1901
+                'year' => __( 'Year', 'aui' ),
1902
+                'hour' => __( 'Hour', 'aui' ),
1903
+                'minute' => __( 'Minute', 'aui' ),
1904
+                'weekAbbreviation' => __( 'Wk', 'aui' ),
1905
+                'rangeSeparator' => __( ' to ', 'aui' ),
1906
+                'scrollTitle' => __( 'Scroll to increment', 'aui' ),
1907
+                'toggleTitle' => __( 'Click to toggle', 'aui' )
1908
+            );
1909
+
1910
+            return apply_filters( 'ayecode_ui_calendar_params', $params );
1911
+        }
1912
+
1913
+        /**
1914
+         * Flatpickr calendar localize.
1915
+         *
1916
+         * @since 0.1.44
1917
+         *
1918
+         * @return string Calendar locale.
1919
+         */
1920
+        public static function flatpickr_locale() {
1921
+            $params = self::calendar_params();
1922
+
1923
+            if ( is_string( $params ) ) {
1924
+                $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
1925
+            } else {
1926
+                foreach ( (array) $params as $key => $value ) {
1927
+                    if ( ! is_scalar( $value ) ) {
1928
+                        continue;
1929
+                    }
1930
+
1931
+                    $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
1932
+                }
1933
+            }
1934 1934
 
1935
-			$day_s3 = array();
1936
-			$day_s5 = array();
1935
+            $day_s3 = array();
1936
+            $day_s5 = array();
1937 1937
 
1938
-			for ( $i = 1; $i <= 7; $i ++ ) {
1939
-				$day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
1940
-				$day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
1941
-			}
1938
+            for ( $i = 1; $i <= 7; $i ++ ) {
1939
+                $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
1940
+                $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
1941
+            }
1942 1942
 
1943
-			$month_s = array();
1944
-			$month_long = array();
1943
+            $month_s = array();
1944
+            $month_long = array();
1945 1945
 
1946
-			for ( $i = 1; $i <= 12; $i ++ ) {
1947
-				$month_s[] = addslashes( $params[ 'month_s_' . $i ] );
1948
-				$month_long[] = addslashes( $params[ 'month_long_' . $i ] );
1949
-			}
1946
+            for ( $i = 1; $i <= 12; $i ++ ) {
1947
+                $month_s[] = addslashes( $params[ 'month_s_' . $i ] );
1948
+                $month_long[] = addslashes( $params[ 'month_long_' . $i ] );
1949
+            }
1950 1950
 
1951 1951
 ob_start();
1952 1952
 if ( 0 ) { ?><script><?php } ?>
@@ -1988,62 +1988,62 @@  discard block
 block discarded – undo
1988 1988
 }
1989 1989
 <?php if ( 0 ) { ?></script><?php } ?>
1990 1990
 <?php
1991
-			$locale = ob_get_clean();
1992
-
1993
-			return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
1994
-		}
1995
-
1996
-		/**
1997
-		 * Select2 JS params.
1998
-		 *
1999
-		 * @since 0.1.44
2000
-		 *
2001
-		 * @return array Select2 JS params.
2002
-		 */
2003
-		public static function select2_params() {
2004
-			$params = array(
2005
-				'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'aui' ),
2006
-				'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'aui' ),
2007
-				'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'aui' ),
2008
-				'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ),
2009
-				'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ),
2010
-				'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'aui' ),
2011
-				'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ),
2012
-				'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ),
2013
-				'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ),
2014
-				'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'aui' ),
2015
-				'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'aui' )
2016
-			);
2017
-
2018
-			return apply_filters( 'ayecode_ui_select2_params', $params );
2019
-		}
2020
-
2021
-		/**
2022
-		 * Select2 JS localize.
2023
-		 *
2024
-		 * @since 0.1.44
2025
-		 *
2026
-		 * @return string Select2 JS locale.
2027
-		 */
2028
-		public static function select2_locale() {
2029
-			$params = self::select2_params();
2030
-
2031
-			foreach ( (array) $params as $key => $value ) {
2032
-				if ( ! is_scalar( $value ) ) {
2033
-					continue;
2034
-				}
1991
+            $locale = ob_get_clean();
1992
+
1993
+            return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
1994
+        }
1995
+
1996
+        /**
1997
+         * Select2 JS params.
1998
+         *
1999
+         * @since 0.1.44
2000
+         *
2001
+         * @return array Select2 JS params.
2002
+         */
2003
+        public static function select2_params() {
2004
+            $params = array(
2005
+                'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'aui' ),
2006
+                'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'aui' ),
2007
+                'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'aui' ),
2008
+                'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ),
2009
+                'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ),
2010
+                'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'aui' ),
2011
+                'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ),
2012
+                'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ),
2013
+                'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ),
2014
+                'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'aui' ),
2015
+                'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'aui' )
2016
+            );
2017
+
2018
+            return apply_filters( 'ayecode_ui_select2_params', $params );
2019
+        }
2020
+
2021
+        /**
2022
+         * Select2 JS localize.
2023
+         *
2024
+         * @since 0.1.44
2025
+         *
2026
+         * @return string Select2 JS locale.
2027
+         */
2028
+        public static function select2_locale() {
2029
+            $params = self::select2_params();
2030
+
2031
+            foreach ( (array) $params as $key => $value ) {
2032
+                if ( ! is_scalar( $value ) ) {
2033
+                    continue;
2034
+                }
2035 2035
 
2036
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2037
-			}
2036
+                $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2037
+            }
2038 2038
 
2039
-			$locale = json_encode( $params );
2039
+            $locale = json_encode( $params );
2040 2040
 
2041
-			return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2042
-		}
2043
-	}
2041
+            return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2042
+        }
2043
+    }
2044 2044
 
2045
-	/**
2046
-	 * Run the class if found.
2047
-	 */
2048
-	AyeCode_UI_Settings::instance();
2045
+    /**
2046
+     * Run the class if found.
2047
+     */
2048
+    AyeCode_UI_Settings::instance();
2049 2049
 }
2050 2050
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway-ipn-handler.php 1 patch
Indentation   +386 added lines, -386 removed lines patch added patch discarded remove patch
@@ -12,461 +12,461 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Paypal_Gateway_IPN_Handler {
14 14
 
15
-	/**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	protected $id = 'paypal';
21
-
22
-	/**
23
-	 * Payment method object.
24
-	 *
25
-	 * @var GetPaid_Paypal_Gateway
26
-	 */
27
-	protected $gateway;
28
-
29
-	/**
30
-	 * Class constructor.
31
-	 *
32
-	 * @param GetPaid_Paypal_Gateway $gateway
33
-	 */
34
-	public function __construct( $gateway ) {
35
-		$this->gateway = $gateway;
36
-		$this->verify_ipn();
37
-	}
38
-
39
-	/**
40
-	 * Processes ipns and marks payments as complete.
41
-	 *
42
-	 * @return void
43
-	 */
44
-	public function verify_ipn() {
45
-
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
-
48
-		// Validate the IPN.
49
-		if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
-			wp_die( 'PayPal IPN Request Failure', 500 );
51
-		}
52
-
53
-		// Process the IPN.
54
-		$posted  = wp_unslash( $_POST );
55
-		$invoice = $this->get_ipn_invoice( $posted );
56
-
57
-		// Abort if it was not paid by our gateway.
58
-		if ( $this->id != $invoice->get_gateway() ) {
59
-			wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
-			wp_die( 'Invoice not paid via PayPal', 200 );
61
-		}
62
-
63
-		$posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
-		$posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
65
-
66
-		wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
68
-
69
-		if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
-			call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
-			wpinv_error_log( 'Done processing IPN', false );
72
-			wp_die( 'Processed', 200 );
73
-		}
74
-
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
77
-
78
-	}
79
-
80
-	/**
81
-	 * Retrieves IPN Invoice.
82
-	 *
83
-	 * @param array $posted
84
-	 * @return WPInv_Invoice
85
-	 */
86
-	protected function get_ipn_invoice( $posted ) {
87
-
88
-		wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
-
90
-		if ( ! empty( $posted['custom'] ) ) {
91
-			$invoice = new WPInv_Invoice( $posted['custom'] );
92
-
93
-			if ( $invoice->exists() ) {
94
-				wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
-				return $invoice;
96
-			}
97
-
98
-		}
99
-
100
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
102
-	}
103
-
104
-	/**
105
-	 * Check PayPal IPN validity.
106
-	 */
107
-	protected function validate_ipn() {
108
-
109
-		wpinv_error_log( 'Validating PayPal IPN response', false );
110
-
111
-		// Retrieve the associated invoice.
112
-		$posted  = wp_unslash( $_POST );
113
-		$invoice = $this->get_ipn_invoice( $posted );
114
-
115
-		if ( $this->gateway->is_sandbox( $invoice ) ) {
116
-			wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
117
-		}
118
-
119
-		// Validate the IPN.
120
-		$posted['cmd'] = '_notify-validate';
121
-
122
-		// Send back post vars to paypal.
123
-		$params = array(
124
-			'body'        => $posted,
125
-			'timeout'     => 60,
126
-			'httpversion' => '1.1',
127
-			'compress'    => false,
128
-			'decompress'  => false,
129
-			'user-agent'  => 'GetPaid/' . WPINV_VERSION,
130
-		);
131
-
132
-		// Post back to get a response.
133
-		$response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
134
-
135
-		// Check to see if the request was valid.
136
-		if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
137
-			wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
138
-			return true;
139
-		}
140
-
141
-		if ( is_wp_error( $response ) ) {
142
-			wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
143
-			return false;
144
-		}
15
+    /**
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20
+    protected $id = 'paypal';
21
+
22
+    /**
23
+     * Payment method object.
24
+     *
25
+     * @var GetPaid_Paypal_Gateway
26
+     */
27
+    protected $gateway;
28
+
29
+    /**
30
+     * Class constructor.
31
+     *
32
+     * @param GetPaid_Paypal_Gateway $gateway
33
+     */
34
+    public function __construct( $gateway ) {
35
+        $this->gateway = $gateway;
36
+        $this->verify_ipn();
37
+    }
38
+
39
+    /**
40
+     * Processes ipns and marks payments as complete.
41
+     *
42
+     * @return void
43
+     */
44
+    public function verify_ipn() {
45
+
46
+        wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
+
48
+        // Validate the IPN.
49
+        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
+            wp_die( 'PayPal IPN Request Failure', 500 );
51
+        }
52
+
53
+        // Process the IPN.
54
+        $posted  = wp_unslash( $_POST );
55
+        $invoice = $this->get_ipn_invoice( $posted );
56
+
57
+        // Abort if it was not paid by our gateway.
58
+        if ( $this->id != $invoice->get_gateway() ) {
59
+            wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
+            wp_die( 'Invoice not paid via PayPal', 200 );
61
+        }
62
+
63
+        $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
+        $posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
65
+
66
+        wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
+        wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
68
+
69
+        if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
+            call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
+            wpinv_error_log( 'Done processing IPN', false );
72
+            wp_die( 'Processed', 200 );
73
+        }
74
+
75
+        wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
+        wp_die( 'Unsupported IPN type', 200 );
77
+
78
+    }
79
+
80
+    /**
81
+     * Retrieves IPN Invoice.
82
+     *
83
+     * @param array $posted
84
+     * @return WPInv_Invoice
85
+     */
86
+    protected function get_ipn_invoice( $posted ) {
87
+
88
+        wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
+
90
+        if ( ! empty( $posted['custom'] ) ) {
91
+            $invoice = new WPInv_Invoice( $posted['custom'] );
92
+
93
+            if ( $invoice->exists() ) {
94
+                wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
+                return $invoice;
96
+            }
97
+
98
+        }
99
+
100
+        wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
+        wp_die( 'Could not retrieve the associated invoice.', 200 );
102
+    }
103
+
104
+    /**
105
+     * Check PayPal IPN validity.
106
+     */
107
+    protected function validate_ipn() {
108
+
109
+        wpinv_error_log( 'Validating PayPal IPN response', false );
110
+
111
+        // Retrieve the associated invoice.
112
+        $posted  = wp_unslash( $_POST );
113
+        $invoice = $this->get_ipn_invoice( $posted );
114
+
115
+        if ( $this->gateway->is_sandbox( $invoice ) ) {
116
+            wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
117
+        }
118
+
119
+        // Validate the IPN.
120
+        $posted['cmd'] = '_notify-validate';
121
+
122
+        // Send back post vars to paypal.
123
+        $params = array(
124
+            'body'        => $posted,
125
+            'timeout'     => 60,
126
+            'httpversion' => '1.1',
127
+            'compress'    => false,
128
+            'decompress'  => false,
129
+            'user-agent'  => 'GetPaid/' . WPINV_VERSION,
130
+        );
131
+
132
+        // Post back to get a response.
133
+        $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
134
+
135
+        // Check to see if the request was valid.
136
+        if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
137
+            wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
138
+            return true;
139
+        }
140
+
141
+        if ( is_wp_error( $response ) ) {
142
+            wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
143
+            return false;
144
+        }
145 145
 
146
-		wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
147
-		return false;
148
-
149
-	}
146
+        wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
147
+        return false;
148
+
149
+    }
150 150
 
151
-	/**
152
-	 * Check currency from IPN matches the invoice.
153
-	 *
154
-	 * @param WPInv_Invoice $invoice          Invoice object.
155
-	 * @param string   $currency currency to validate.
156
-	 */
157
-	protected function validate_ipn_currency( $invoice, $currency ) {
151
+    /**
152
+     * Check currency from IPN matches the invoice.
153
+     *
154
+     * @param WPInv_Invoice $invoice          Invoice object.
155
+     * @param string   $currency currency to validate.
156
+     */
157
+    protected function validate_ipn_currency( $invoice, $currency ) {
158 158
 
159
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
159
+        if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
160 160
 
161
-			/* translators: %s: currency code. */
162
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
161
+            /* translators: %s: currency code. */
162
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
163 163
 
164
-			wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
165
-		}
164
+            wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
165
+        }
166 166
 
167
-		wpinv_error_log( $currency, 'Validated IPN Currency', false );
168
-	}
167
+        wpinv_error_log( $currency, 'Validated IPN Currency', false );
168
+    }
169 169
 
170
-	/**
171
-	 * Check payment amount from IPN matches the invoice.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice          Invoice object.
174
-	 * @param float   $amount amount to validate.
175
-	 */
176
-	protected function validate_ipn_amount( $invoice, $amount ) {
177
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
170
+    /**
171
+     * Check payment amount from IPN matches the invoice.
172
+     *
173
+     * @param WPInv_Invoice $invoice          Invoice object.
174
+     * @param float   $amount amount to validate.
175
+     */
176
+    protected function validate_ipn_amount( $invoice, $amount ) {
177
+        if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
178 178
 
179
-			/* translators: %s: Amount. */
180
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
179
+            /* translators: %s: Amount. */
180
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
181 181
 
182
-			wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
183
-		}
182
+            wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
183
+        }
184 184
 
185
-		wpinv_error_log( $amount, 'Validated IPN Amount', false );
186
-	}
185
+        wpinv_error_log( $amount, 'Validated IPN Amount', false );
186
+    }
187 187
 
188
-	/**
189
-	 * Verify receiver email from PayPal.
190
-	 *
191
-	 * @param WPInv_Invoice $invoice          Invoice object.
192
-	 * @param string   $receiver_email Email to validate.
193
-	 */
194
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
-		$paypal_email = wpinv_get_option( 'paypal_email' );
188
+    /**
189
+     * Verify receiver email from PayPal.
190
+     *
191
+     * @param WPInv_Invoice $invoice          Invoice object.
192
+     * @param string   $receiver_email Email to validate.
193
+     */
194
+    protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
+        $paypal_email = wpinv_get_option( 'paypal_email' );
196 196
 
197
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
198
-			wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
197
+        if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
198
+            wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
199 199
 
200
-			/* translators: %s: email address . */
201
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
200
+            /* translators: %s: email address . */
201
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
202 202
 
203
-			return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
204
-		}
203
+            return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
204
+        }
205 205
 
206
-		wpinv_error_log( 'Validated PayPal Email', false );
207
-	}
206
+        wpinv_error_log( 'Validated PayPal Email', false );
207
+    }
208 208
 
209
-	/**
210
-	 * Handles one time payments.
211
-	 *
212
-	 * @param WPInv_Invoice $invoice  Invoice object.
213
-	 * @param array    $posted Posted data.
214
-	 */
215
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
209
+    /**
210
+     * Handles one time payments.
211
+     *
212
+     * @param WPInv_Invoice $invoice  Invoice object.
213
+     * @param array    $posted Posted data.
214
+     */
215
+    protected function ipn_txn_web_accept( $invoice, $posted ) {
216 216
 
217
-		// Collect payment details
218
-		$payment_status = strtolower( $posted['payment_status'] );
219
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
217
+        // Collect payment details
218
+        $payment_status = strtolower( $posted['payment_status'] );
219
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
220 220
 
221
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
222
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
223
-
224
-		// Update the transaction id.
225
-		if ( ! empty( $posted['txn_id'] ) ) {
226
-			$invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
227
-			$invoice->save();
228
-		}
221
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
222
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
223
+
224
+        // Update the transaction id.
225
+        if ( ! empty( $posted['txn_id'] ) ) {
226
+            $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
227
+            $invoice->save();
228
+        }
229 229
 
230
-		// Process a refund.
231
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
230
+        // Process a refund.
231
+        if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
232 232
 
233
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
233
+            update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
234 234
 
235
-			if ( ! $invoice->is_refunded() ) {
236
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
237
-			}
235
+            if ( ! $invoice->is_refunded() ) {
236
+                $invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
237
+            }
238 238
 
239
-			return wpinv_error_log( $posted['reason_code'], false );
240
-		}
239
+            return wpinv_error_log( $posted['reason_code'], false );
240
+        }
241 241
 
242
-		// Process payments.
243
-		if ( $payment_status == 'completed' ) {
242
+        // Process payments.
243
+        if ( $payment_status == 'completed' ) {
244 244
 
245
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
246
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
247
-			}
245
+            if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
246
+                return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
247
+            }
248 248
 
249
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
249
+            $this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
250 250
 
251
-			$note = '';
251
+            $note = '';
252 252
 
253
-			if ( ! empty( $posted['mc_fee'] ) ) {
254
-				$note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
255
-			}
253
+            if ( ! empty( $posted['mc_fee'] ) ) {
254
+                $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
255
+            }
256 256
 
257
-			if ( ! empty( $posted['payer_status'] ) ) {
258
-				$note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
259
-			}
257
+            if ( ! empty( $posted['payer_status'] ) ) {
258
+                $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
259
+            }
260 260
 
261
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
262
-			return wpinv_error_log( 'Invoice marked as paid.', false );
261
+            $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
262
+            return wpinv_error_log( 'Invoice marked as paid.', false );
263 263
 
264
-		}
264
+        }
265 265
 
266
-		// Pending payments.
267
-		if ( $payment_status == 'pending' ) {
266
+        // Pending payments.
267
+        if ( $payment_status == 'pending' ) {
268 268
 
269
-			/* translators: %s: pending reason. */
270
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
269
+            /* translators: %s: pending reason. */
270
+            $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
271 271
 
272
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
273
-		}
272
+            return wpinv_error_log( 'Invoice marked as "payment held".', false );
273
+        }
274 274
 
275
-		/* translators: %s: payment status. */
276
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
275
+        /* translators: %s: payment status. */
276
+        $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
277 277
 
278
-	}
278
+    }
279 279
 
280
-	/**
281
-	 * Handles one time payments.
282
-	 *
283
-	 * @param WPInv_Invoice $invoice  Invoice object.
284
-	 * @param array    $posted Posted data.
285
-	 */
286
-	protected function ipn_txn_cart( $invoice, $posted ) {
287
-		$this->ipn_txn_web_accept( $invoice, $posted );
288
-	}
280
+    /**
281
+     * Handles one time payments.
282
+     *
283
+     * @param WPInv_Invoice $invoice  Invoice object.
284
+     * @param array    $posted Posted data.
285
+     */
286
+    protected function ipn_txn_cart( $invoice, $posted ) {
287
+        $this->ipn_txn_web_accept( $invoice, $posted );
288
+    }
289 289
 
290
-	/**
291
-	 * Handles subscription sign ups.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice  Invoice object.
294
-	 * @param array    $posted Posted data.
295
-	 */
296
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
290
+    /**
291
+     * Handles subscription sign ups.
292
+     *
293
+     * @param WPInv_Invoice $invoice  Invoice object.
294
+     * @param array    $posted Posted data.
295
+     */
296
+    protected function ipn_txn_subscr_signup( $invoice, $posted ) {
297 297
 
298
-		wpinv_error_log( 'Processing subscription signup', false );
298
+        wpinv_error_log( 'Processing subscription signup', false );
299 299
 
300
-		// Make sure the invoice has a subscription.
301
-		$subscription = getpaid_get_invoice_subscription( $invoice );
300
+        // Make sure the invoice has a subscription.
301
+        $subscription = getpaid_get_invoice_subscription( $invoice );
302 302
 
303
-		if ( empty( $subscription ) ) {
304
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
305
-		}
303
+        if ( empty( $subscription ) ) {
304
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
305
+        }
306 306
 
307
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
307
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
308 308
 
309
-		// Validate the IPN.
310
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
311
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
312
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
309
+        // Validate the IPN.
310
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
311
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
312
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
313 313
 
314
-		// Activate the subscription.
315
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
316
-		$subscription->set_date_created( current_time( 'mysql' ) );
317
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
318
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
319
-		$subscription->activate();
314
+        // Activate the subscription.
315
+        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
316
+        $subscription->set_date_created( current_time( 'mysql' ) );
317
+        $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
318
+        $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
319
+        $subscription->activate();
320 320
 
321
-		// Set the transaction id.
322
-		if ( ! empty( $posted['txn_id'] ) ) {
323
-			$invoice->set_transaction_id( $posted['txn_id'] );
324
-		}
321
+        // Set the transaction id.
322
+        if ( ! empty( $posted['txn_id'] ) ) {
323
+            $invoice->set_transaction_id( $posted['txn_id'] );
324
+        }
325 325
 
326
-		// Update the payment status.
327
-		$invoice->mark_paid();
326
+        // Update the payment status.
327
+        $invoice->mark_paid();
328 328
 
329
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
329
+        $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
330 330
 
331
-		wpinv_error_log( 'Subscription started.', false );
332
-	}
331
+        wpinv_error_log( 'Subscription started.', false );
332
+    }
333 333
 
334
-	/**
335
-	 * Handles subscription renewals.
336
-	 *
337
-	 * @param WPInv_Invoice $invoice  Invoice object.
338
-	 * @param array    $posted Posted data.
339
-	 */
340
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
334
+    /**
335
+     * Handles subscription renewals.
336
+     *
337
+     * @param WPInv_Invoice $invoice  Invoice object.
338
+     * @param array    $posted Posted data.
339
+     */
340
+    protected function ipn_txn_subscr_payment( $invoice, $posted ) {
341 341
 
342
-		// Make sure the invoice has a subscription.
343
-		$subscription = wpinv_get_subscription( $invoice );
342
+        // Make sure the invoice has a subscription.
343
+        $subscription = wpinv_get_subscription( $invoice );
344 344
 
345
-		if ( empty( $subscription ) ) {
346
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
347
-		}
345
+        if ( empty( $subscription ) ) {
346
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
347
+        }
348 348
 
349
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
349
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
350 350
 
351
-		// Abort if this is the first payment.
352
-		$invoice_completed = date( 'Ynd', strtotime( $invoice->get_date_completed() ) );
353
-		$payment_date      = date( 'Ynd', strtotime( $posted['payment_date'] ) );
354
-		$subscription_date = date( 'Ynd', $subscription->get_time_created() );
355
-		if ( $invoice_completed == $payment_date || $subscription_date == $payment_date ) {
351
+        // Abort if this is the first payment.
352
+        $invoice_completed = date( 'Ynd', strtotime( $invoice->get_date_completed() ) );
353
+        $payment_date      = date( 'Ynd', strtotime( $posted['payment_date'] ) );
354
+        $subscription_date = date( 'Ynd', $subscription->get_time_created() );
355
+        if ( $invoice_completed == $payment_date || $subscription_date == $payment_date ) {
356 356
 
357
-			if ( ! empty( $posted['txn_id'] ) ) {
358
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
359
-			}
357
+            if ( ! empty( $posted['txn_id'] ) ) {
358
+                $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
359
+            }
360 360
 
361
-			return $invoice->mark_paid();
362
-		}
361
+            return $invoice->mark_paid();
362
+        }
363 363
 
364
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
364
+        wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
365 365
 
366
-		// Abort if the payment is already recorded.
367
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
368
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
369
-		}
370
-
371
-		$args = array(
372
-			'transaction_id' => $posted['txn_id'],
373
-			'gateway'        => $this->id,
374
-		);
375
-
376
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
377
-
378
-		if ( empty( $invoice ) ) {
379
-			return;
380
-		}
381
-
382
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
383
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
384
-
385
-		$subscription->renew();
386
-		wpinv_error_log( 'Subscription renewed.', false );
387
-
388
-	}
366
+        // Abort if the payment is already recorded.
367
+        if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
368
+            return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
369
+        }
370
+
371
+        $args = array(
372
+            'transaction_id' => $posted['txn_id'],
373
+            'gateway'        => $this->id,
374
+        );
375
+
376
+        $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
377
+
378
+        if ( empty( $invoice ) ) {
379
+            return;
380
+        }
381
+
382
+        $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
383
+        $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
384
+
385
+        $subscription->renew();
386
+        wpinv_error_log( 'Subscription renewed.', false );
387
+
388
+    }
389 389
 
390
-	/**
391
-	 * Handles subscription cancelations.
392
-	 *
393
-	 * @param WPInv_Invoice $invoice  Invoice object.
394
-	 */
395
-	protected function ipn_txn_subscr_cancel( $invoice ) {
390
+    /**
391
+     * Handles subscription cancelations.
392
+     *
393
+     * @param WPInv_Invoice $invoice  Invoice object.
394
+     */
395
+    protected function ipn_txn_subscr_cancel( $invoice ) {
396 396
 
397
-		// Make sure the invoice has a subscription.
398
-		$subscription = wpinv_get_subscription( $invoice );
397
+        // Make sure the invoice has a subscription.
398
+        $subscription = wpinv_get_subscription( $invoice );
399 399
 
400
-		if ( empty( $subscription ) ) {
401
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
402
-		}
403
-
404
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
405
-		$subscription->cancel();
406
-		wpinv_error_log( 'Subscription cancelled.', false );
407
-
408
-	}
409
-
410
-	/**
411
-	 * Handles subscription completions.
412
-	 *
413
-	 * @param WPInv_Invoice $invoice  Invoice object.
414
-	 * @param array    $posted Posted data.
415
-	 */
416
-	protected function ipn_txn_subscr_eot( $invoice ) {
400
+        if ( empty( $subscription ) ) {
401
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
402
+        }
403
+
404
+        wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
405
+        $subscription->cancel();
406
+        wpinv_error_log( 'Subscription cancelled.', false );
407
+
408
+    }
409
+
410
+    /**
411
+     * Handles subscription completions.
412
+     *
413
+     * @param WPInv_Invoice $invoice  Invoice object.
414
+     * @param array    $posted Posted data.
415
+     */
416
+    protected function ipn_txn_subscr_eot( $invoice ) {
417 417
 
418
-		// Make sure the invoice has a subscription.
419
-		$subscription = wpinv_get_subscription( $invoice );
418
+        // Make sure the invoice has a subscription.
419
+        $subscription = wpinv_get_subscription( $invoice );
420 420
 
421
-		if ( empty( $subscription ) ) {
422
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
423
-		}
421
+        if ( empty( $subscription ) ) {
422
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
423
+        }
424 424
 
425
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
426
-		$subscription->complete();
427
-		wpinv_error_log( 'Subscription completed.', false );
425
+        wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
426
+        $subscription->complete();
427
+        wpinv_error_log( 'Subscription completed.', false );
428 428
 
429
-	}
429
+    }
430 430
 
431
-	/**
432
-	 * Handles subscription fails.
433
-	 *
434
-	 * @param WPInv_Invoice $invoice  Invoice object.
435
-	 * @param array    $posted Posted data.
436
-	 */
437
-	protected function ipn_txn_subscr_failed( $invoice ) {
431
+    /**
432
+     * Handles subscription fails.
433
+     *
434
+     * @param WPInv_Invoice $invoice  Invoice object.
435
+     * @param array    $posted Posted data.
436
+     */
437
+    protected function ipn_txn_subscr_failed( $invoice ) {
438 438
 
439
-		// Make sure the invoice has a subscription.
440
-		$subscription = wpinv_get_subscription( $invoice );
439
+        // Make sure the invoice has a subscription.
440
+        $subscription = wpinv_get_subscription( $invoice );
441 441
 
442
-		if ( empty( $subscription ) ) {
443
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
444
-		}
442
+        if ( empty( $subscription ) ) {
443
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
444
+        }
445 445
 
446
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
447
-		$subscription->failing();
448
-		wpinv_error_log( 'Subscription marked as failing.', false );
446
+        wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
447
+        $subscription->failing();
448
+        wpinv_error_log( 'Subscription marked as failing.', false );
449 449
 
450
-	}
451
-
452
-	/**
453
-	 * Handles subscription suspensions.
454
-	 *
455
-	 * @param WPInv_Invoice $invoice  Invoice object.
456
-	 * @param array    $posted Posted data.
457
-	 */
458
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
450
+    }
451
+
452
+    /**
453
+     * Handles subscription suspensions.
454
+     *
455
+     * @param WPInv_Invoice $invoice  Invoice object.
456
+     * @param array    $posted Posted data.
457
+     */
458
+    protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
459 459
 
460
-		// Make sure the invoice has a subscription.
461
-		$subscription = wpinv_get_subscription( $invoice );
460
+        // Make sure the invoice has a subscription.
461
+        $subscription = wpinv_get_subscription( $invoice );
462 462
 
463
-		if ( empty( $subscription ) ) {
464
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
465
-		}
466
-
467
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
468
-		$subscription->cancel();
469
-		wpinv_error_log( 'Subscription cancelled.', false );
470
-	}
463
+        if ( empty( $subscription ) ) {
464
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
465
+        }
466
+
467
+        wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
468
+        $subscription->cancel();
469
+        wpinv_error_log( 'Subscription cancelled.', false );
470
+    }
471 471
 
472 472
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-exception.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,51 +14,51 @@
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Payment_Exception extends Exception {
16 16
 
17
-	/**
18
-	 * Sanitized error code.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	protected $error_code;
17
+    /**
18
+     * Sanitized error code.
19
+     *
20
+     * @var string
21
+     */
22
+    protected $error_code;
23 23
 
24
-	/**
25
-	 * Error extra data.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $error_data;
24
+    /**
25
+     * Error extra data.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $error_data;
30 30
 
31
-	/**
32
-	 * Setup exception.
33
-	 *
34
-	 * @param string $code             Machine-readable error code, e.g `getpaid-discount-error`.
35
-	 * @param string $message          User-friendly translated error message, e.g. 'Discount is invalid'.
36
-	 * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
37
-	 * @param array  $data             Extra error data.
38
-	 */
39
-	public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
40
-		$this->error_code = $code;
41
-		$this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
31
+    /**
32
+     * Setup exception.
33
+     *
34
+     * @param string $code             Machine-readable error code, e.g `getpaid-discount-error`.
35
+     * @param string $message          User-friendly translated error message, e.g. 'Discount is invalid'.
36
+     * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
37
+     * @param array  $data             Extra error data.
38
+     */
39
+    public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
40
+        $this->error_code = $code;
41
+        $this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
42 42
 
43
-		parent::__construct( $message, $http_status_code );
44
-	}
43
+        parent::__construct( $message, $http_status_code );
44
+    }
45 45
 
46
-	/**
47
-	 * Returns the error code.
48
-	 *
49
-	 * @return string
50
-	 */
51
-	public function getErrorCode() {
52
-		return $this->error_code;
53
-	}
46
+    /**
47
+     * Returns the error code.
48
+     *
49
+     * @return string
50
+     */
51
+    public function getErrorCode() {
52
+        return $this->error_code;
53
+    }
54 54
 
55
-	/**
56
-	 * Returns error data.
57
-	 *
58
-	 * @return array
59
-	 */
60
-	public function getErrorData() {
61
-		return $this->error_data;
62
-	}
55
+    /**
56
+     * Returns error data.
57
+     *
58
+     * @return array
59
+     */
60
+    public function getErrorData() {
61
+        return $this->error_data;
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-discount.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -12,162 +12,162 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Discount {
14 14
 
15
-	/**
16
-	 * Submission discounts.
17
-	 * @var array
18
-	 */
19
-	public $discounts = array();
15
+    /**
16
+     * Submission discounts.
17
+     * @var array
18
+     */
19
+    public $discounts = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     * @param float                           $initial_total
26
+     * @param float                           $recurring_total
27
+     */
28
+    public function __construct( $submission, $initial_total, $recurring_total ) {
29
+
30
+        // Process any existing invoice discounts.
31
+        if ( $submission->has_invoice() ) {
32
+            $this->discounts = $submission->get_invoice()->get_discounts();
33
+        }
34
+
35
+        // Do we have a discount?
36
+        $discount = $submission->get_field( 'discount' );
37
+
38
+        if ( empty( $discount ) ) {
39
+
40
+            if ( isset( $this->discounts['discount_code'] ) ) {
41
+                unset( $this->discounts['discount_code'] );
42
+            }
43
+
44
+            return;
45
+        }
46
+
47
+        // Processes the discount code.
48
+        $amount = max( $initial_total, $recurring_total );
49
+        $this->process_discount( $submission, $discount, $amount );
50
+
51
+    }
20 52
 
21 53
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 * @param float                           $initial_total
26
-	 * @param float                           $recurring_total
27
-	 */
28
-	public function __construct( $submission, $initial_total, $recurring_total ) {
29
-
30
-		// Process any existing invoice discounts.
31
-		if ( $submission->has_invoice() ) {
32
-			$this->discounts = $submission->get_invoice()->get_discounts();
33
-		}
34
-
35
-		// Do we have a discount?
36
-		$discount = $submission->get_field( 'discount' );
37
-
38
-		if ( empty( $discount ) ) {
39
-
40
-			if ( isset( $this->discounts['discount_code'] ) ) {
41
-				unset( $this->discounts['discount_code'] );
42
-			}
43
-
44
-			return;
45
-		}
46
-
47
-		// Processes the discount code.
48
-		$amount = max( $initial_total, $recurring_total );
49
-		$this->process_discount( $submission, $discount, $amount );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Processes a submission discount.
55
-	 *
56
-	 * @param GetPaid_Payment_Form_Submission $submission
57
-	 * @param string                          $discount
58
-	 * @param float                           $amount
59
-	 */
60
-	public function process_discount( $submission, $discount, $amount ) {
61
-
62
-		// Fetch the discount.
63
-		$discount = new WPInv_Discount( $discount );
64
-
65
-		// Ensure it is active.
54
+     * Processes a submission discount.
55
+     *
56
+     * @param GetPaid_Payment_Form_Submission $submission
57
+     * @param string                          $discount
58
+     * @param float                           $amount
59
+     */
60
+    public function process_discount( $submission, $discount, $amount ) {
61
+
62
+        // Fetch the discount.
63
+        $discount = new WPInv_Discount( $discount );
64
+
65
+        // Ensure it is active.
66 66
         if ( ! $this->is_discount_active( $discount ) ) {
67
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) );
68
-		}
69
-
70
-		// Exceeded limit.
71
-		if ( $discount->has_exceeded_limit() ) {
72
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) );
73
-		}
74
-
75
-		// Validate usages.
76
-		$this->validate_single_use_discount( $submission, $discount );
77
-
78
-		// Validate amount.
79
-		$this->validate_discount_amount( $submission, $discount, $amount );
80
-
81
-		// Save the discount.
82
-		$this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
-	}
84
-
85
-	/**
86
-	 * Validates a single use discount.
87
-	 *
88
-	 * @param WPInv_Discount                  $discount
89
-	 * @return bool
90
-	 */
91
-	public function is_discount_active(  $discount ) {
92
-		return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
-	}
94
-
95
-	/**
96
-	 * Returns a user's id or email.
97
-	 *
98
-	 * @param string $email
99
-	 * @return int|string|false
100
-	 */
101
-	public function get_user_id_or_email( $email ) {
102
-
103
-		if ( is_user_logged_in() ) {
104
-			return get_current_user_id();
105
-		}
106
-
107
-		return empty( $email ) ? false : sanitize_email( $email );
108
-	}
109
-
110
-	/**
111
-	 * Validates a single use discount.
112
-	 *
113
-	 * @param GetPaid_Payment_Form_Submission $submission
114
-	 * @param WPInv_Discount                  $discount
115
-	 */
116
-	public function validate_single_use_discount( $submission, $discount ) {
117
-
118
-		// Abort if it is not a single use discount.
119
-		if ( ! $discount->is_single_use() ) {
120
-			return;
121
-		}
122
-
123
-		// Ensure there is a valid billing email.
124
-		$user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
-
126
-		if ( empty( $user ) ) {
127
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
128
-		}
129
-
130
-		// Has the user used this discount code before?
131
-		if ( ! $discount->is_valid_for_user( $user ) ) {
132
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) );
133
-		}
134
-
135
-	}
136
-
137
-	/**
138
-	 * Validates the discount's amount.
139
-	 *
140
-	 * @param GetPaid_Payment_Form_Submission $submission
141
-	 * @param WPInv_Discount         $discount
142
-	 * @param float                  $amount
143
-	 */
144
-	public function validate_discount_amount( $submission, $discount, $amount ) {
145
-
146
-		// Validate minimum amount.
147
-		if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
-			$min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
150
-		}
151
-
152
-		// Validate the maximum amount.
153
-		if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
-			$max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
156
-		}
157
-
158
-	}
159
-
160
-	/**
161
-	 * Calculates the discount code's amount.
162
-	 *
163
-	 * Ensure that the discount exists and has been validated before calling this method.
164
-	 *
165
-	 * @param GetPaid_Payment_Form_Submission $submission
166
-	 * @param WPInv_Discount                  $discount
167
-	 * @return array
168
-	 */
169
-	public function calculate_discount( $submission, $discount ) {
170
-		return getpaid_calculate_invoice_discount( $submission, $discount );
171
-	}
67
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) );
68
+        }
69
+
70
+        // Exceeded limit.
71
+        if ( $discount->has_exceeded_limit() ) {
72
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) );
73
+        }
74
+
75
+        // Validate usages.
76
+        $this->validate_single_use_discount( $submission, $discount );
77
+
78
+        // Validate amount.
79
+        $this->validate_discount_amount( $submission, $discount, $amount );
80
+
81
+        // Save the discount.
82
+        $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
+    }
84
+
85
+    /**
86
+     * Validates a single use discount.
87
+     *
88
+     * @param WPInv_Discount                  $discount
89
+     * @return bool
90
+     */
91
+    public function is_discount_active(  $discount ) {
92
+        return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
+    }
94
+
95
+    /**
96
+     * Returns a user's id or email.
97
+     *
98
+     * @param string $email
99
+     * @return int|string|false
100
+     */
101
+    public function get_user_id_or_email( $email ) {
102
+
103
+        if ( is_user_logged_in() ) {
104
+            return get_current_user_id();
105
+        }
106
+
107
+        return empty( $email ) ? false : sanitize_email( $email );
108
+    }
109
+
110
+    /**
111
+     * Validates a single use discount.
112
+     *
113
+     * @param GetPaid_Payment_Form_Submission $submission
114
+     * @param WPInv_Discount                  $discount
115
+     */
116
+    public function validate_single_use_discount( $submission, $discount ) {
117
+
118
+        // Abort if it is not a single use discount.
119
+        if ( ! $discount->is_single_use() ) {
120
+            return;
121
+        }
122
+
123
+        // Ensure there is a valid billing email.
124
+        $user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
+
126
+        if ( empty( $user ) ) {
127
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
128
+        }
129
+
130
+        // Has the user used this discount code before?
131
+        if ( ! $discount->is_valid_for_user( $user ) ) {
132
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) );
133
+        }
134
+
135
+    }
136
+
137
+    /**
138
+     * Validates the discount's amount.
139
+     *
140
+     * @param GetPaid_Payment_Form_Submission $submission
141
+     * @param WPInv_Discount         $discount
142
+     * @param float                  $amount
143
+     */
144
+    public function validate_discount_amount( $submission, $discount, $amount ) {
145
+
146
+        // Validate minimum amount.
147
+        if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
+            $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
150
+        }
151
+
152
+        // Validate the maximum amount.
153
+        if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
+            $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
156
+        }
157
+
158
+    }
159
+
160
+    /**
161
+     * Calculates the discount code's amount.
162
+     *
163
+     * Ensure that the discount exists and has been validated before calling this method.
164
+     *
165
+     * @param GetPaid_Payment_Form_Submission $submission
166
+     * @param WPInv_Discount                  $discount
167
+     * @return array
168
+     */
169
+    public function calculate_discount( $submission, $discount ) {
170
+        return getpaid_calculate_invoice_discount( $submission, $discount );
171
+    }
172 172
 
173 173
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Indentation   +237 added lines, -237 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 4;
35 35
 
36 36
     /**
37
-	 * Endpoint for requests from Authorize.net.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	protected $notify_url;
42
-
43
-	/**
44
-	 * Endpoint for requests to Authorize.net.
45
-	 *
46
-	 * @var string
47
-	 */
37
+     * Endpoint for requests from Authorize.net.
38
+     *
39
+     * @var string
40
+     */
41
+    protected $notify_url;
42
+
43
+    /**
44
+     * Endpoint for requests to Authorize.net.
45
+     *
46
+     * @var string
47
+     */
48 48
     protected $endpoint;
49 49
 
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
63 63
 
64 64
     /**
65
-	 * Class constructor.
66
-	 */
67
-	public function __construct() {
65
+     * Class constructor.
66
+     */
67
+    public function __construct() {
68 68
 
69 69
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70 70
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
     }
77 77
 
78 78
     /**
79
-	 * Displays the payment method select field.
80
-	 *
81
-	 * @param int $invoice_id 0 or invoice id.
82
-	 * @param GetPaid_Payment_Form $form Current payment form.
83
-	 */
79
+     * Displays the payment method select field.
80
+     *
81
+     * @param int $invoice_id 0 or invoice id.
82
+     * @param GetPaid_Payment_Form $form Current payment form.
83
+     */
84 84
     public function payment_fields( $invoice_id, $form ) {
85 85
 
86 86
         // Let the user select a payment method.
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-	 * Creates a customer profile.
95
-	 *
96
-	 *
97
-	 * @param WPInv_Invoice $invoice Invoice.
94
+     * Creates a customer profile.
95
+     *
96
+     *
97
+     * @param WPInv_Invoice $invoice Invoice.
98 98
      * @param array $submission_data Posted checkout fields.
99 99
      * @param bool $save Whether or not to save the payment as a token.
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101
-	 * @return string|WP_Error Payment profile id.
102
-	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
101
+     * @return string|WP_Error Payment profile id.
102
+     */
103
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
104 104
 
105 105
         // Remove non-digits from the number
106 106
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
     }
168 168
 
169 169
     /**
170
-	 * Retrieves a customer profile.
171
-	 *
172
-	 *
173
-	 * @param string $profile_id profile id.
174
-	 * @return string|WP_Error Profile id.
170
+     * Retrieves a customer profile.
171
+     *
172
+     *
173
+     * @param string $profile_id profile id.
174
+     * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176
-	 */
177
-	public function get_customer_profile( $profile_id ) {
176
+     */
177
+    public function get_customer_profile( $profile_id ) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     }
190 190
 
191 191
     /**
192
-	 * Creates a customer profile.
193
-	 *
194
-	 *
192
+     * Creates a customer profile.
193
+     *
194
+     *
195 195
      * @param string $profile_id profile id.
196
-	 * @param WPInv_Invoice $invoice Invoice.
196
+     * @param WPInv_Invoice $invoice Invoice.
197 197
      * @param array $submission_data Posted checkout fields.
198 198
      * @param bool $save Whether or not to save the payment as a token.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200
-	 * @return string|WP_Error Profile id.
201
-	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
200
+     * @return string|WP_Error Profile id.
201
+     */
202
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
203 203
 
204 204
         // Remove non-digits from the number
205 205
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -272,13 +272,13 @@  discard block
 block discarded – undo
272 272
     }
273 273
 
274 274
     /**
275
-	 * Retrieves payment details from cache.
276
-	 *
277
-	 *
275
+     * Retrieves payment details from cache.
276
+     *
277
+     *
278 278
      * @param array $payment_details.
279
-	 * @return array|false Profile id.
280
-	 */
281
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
279
+     * @return array|false Profile id.
280
+     */
281
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
282 282
 
283 283
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
284 284
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -303,13 +303,13 @@  discard block
 block discarded – undo
303 303
     }
304 304
 
305 305
     /**
306
-	 * Securely adds payment details to cache.
307
-	 *
308
-	 *
306
+     * Securely adds payment details to cache.
307
+     *
308
+     *
309 309
      * @param array $payment_details.
310 310
      * @param string $payment_profile_id.
311
-	 */
312
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
311
+     */
312
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
313 313
 
314 314
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
315 315
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
     }
322 322
 
323 323
     /**
324
-	 * Retrieves a customer payment profile.
325
-	 *
326
-	 *
327
-	 * @param string $customer_profile_id customer profile id.
324
+     * Retrieves a customer payment profile.
325
+     *
326
+     *
327
+     * @param string $customer_profile_id customer profile id.
328 328
      * @param string $payment_profile_id payment profile id.
329
-	 * @return string|WP_Error Profile id.
329
+     * @return string|WP_Error Profile id.
330 330
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
331
-	 */
332
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
331
+     */
332
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
333 333
 
334 334
         // Generate args.
335 335
         $args = array(
@@ -345,15 +345,15 @@  discard block
 block discarded – undo
345 345
     }
346 346
 
347 347
     /**
348
-	 * Charges a customer payment profile.
349
-	 *
348
+     * Charges a customer payment profile.
349
+     *
350 350
      * @param string $customer_profile_id customer profile id.
351 351
      * @param string $payment_profile_id payment profile id.
352
-	 * @param WPInv_Invoice $invoice Invoice.
352
+     * @param WPInv_Invoice $invoice Invoice.
353 353
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
354
-	 * @return WP_Error|object
355
-	 */
356
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
354
+     * @return WP_Error|object
355
+     */
356
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
357 357
 
358 358
         // Generate args.
359 359
         $args = array(
@@ -399,41 +399,41 @@  discard block
 block discarded – undo
399 399
     }
400 400
 
401 401
     /**
402
-	 * Processes a customer charge.
403
-	 *
402
+     * Processes a customer charge.
403
+     *
404 404
      * @param stdClass $result Api response.
405
-	 * @param WPInv_Invoice $invoice Invoice.
406
-	 */
407
-	public function process_charge_response( $result, $invoice ) {
405
+     * @param WPInv_Invoice $invoice Invoice.
406
+     */
407
+    public function process_charge_response( $result, $invoice ) {
408 408
 
409 409
         wpinv_clear_errors();
410
-		$response_code = (int) $result->transactionResponse->responseCode;
410
+        $response_code = (int) $result->transactionResponse->responseCode;
411 411
 
412
-		// Succeeded.
413
-		if ( 1 == $response_code || 4 == $response_code ) {
412
+        // Succeeded.
413
+        if ( 1 == $response_code || 4 == $response_code ) {
414 414
 
415
-			// Maybe set a transaction id.
416
-			if ( ! empty( $result->transactionResponse->transId ) ) {
417
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
418
-			}
415
+            // Maybe set a transaction id.
416
+            if ( ! empty( $result->transactionResponse->transId ) ) {
417
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
418
+            }
419 419
 
420
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
420
+            $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
421 421
 
422
-			if ( 1 == $response_code ) {
423
-				return $invoice->mark_paid();
424
-			}
422
+            if ( 1 == $response_code ) {
423
+                return $invoice->mark_paid();
424
+            }
425 425
 
426
-			$invoice->set_status( 'wpi-onhold' );
427
-        	$invoice->add_note(
426
+            $invoice->set_status( 'wpi-onhold' );
427
+            $invoice->add_note(
428 428
                 sprintf(
429 429
                     __( 'Held for review: %s', 'invoicing' ),
430 430
                     $result->transactionResponse->messages->message[0]->description
431 431
                 )
432
-			);
432
+            );
433 433
 
434
-			return $invoice->save();
434
+            return $invoice->save();
435 435
 
436
-		}
436
+        }
437 437
 
438 438
         wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
439 439
 
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
     }
446 446
 
447 447
     /**
448
-	 * Returns payment information.
449
-	 *
450
-	 *
451
-	 * @param array $card Card details.
452
-	 * @return array
453
-	 */
454
-	public function get_payment_information( $card ) {
448
+     * Returns payment information.
449
+     *
450
+     *
451
+     * @param array $card Card details.
452
+     * @return array
453
+     */
454
+    public function get_payment_information( $card ) {
455 455
         return array(
456 456
 
457 457
             'creditCard'         => array (
@@ -464,25 +464,25 @@  discard block
 block discarded – undo
464 464
     }
465 465
 
466 466
     /**
467
-	 * Returns the customer profile meta name.
468
-	 *
469
-	 *
470
-	 * @param WPInv_Invoice $invoice Invoice.
471
-	 * @return string
472
-	 */
473
-	public function get_customer_profile_meta_name( $invoice ) {
467
+     * Returns the customer profile meta name.
468
+     *
469
+     *
470
+     * @param WPInv_Invoice $invoice Invoice.
471
+     * @return string
472
+     */
473
+    public function get_customer_profile_meta_name( $invoice ) {
474 474
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
475 475
     }
476 476
 
477 477
     /**
478
-	 * Validates the submitted data.
479
-	 *
480
-	 *
481
-	 * @param array $submission_data Posted checkout fields.
478
+     * Validates the submitted data.
479
+     *
480
+     *
481
+     * @param array $submission_data Posted checkout fields.
482 482
      * @param WPInv_Invoice $invoice
483
-	 * @return WP_Error|string The payment profile id
484
-	 */
485
-	public function validate_submission_data( $submission_data, $invoice ) {
483
+     * @return WP_Error|string The payment profile id
484
+     */
485
+    public function validate_submission_data( $submission_data, $invoice ) {
486 486
 
487 487
         // Validate authentication details.
488 488
         $auth = $this->get_auth_params();
@@ -514,13 +514,13 @@  discard block
 block discarded – undo
514 514
     }
515 515
 
516 516
     /**
517
-	 * Returns invoice line items.
518
-	 *
519
-	 *
520
-	 * @param WPInv_Invoice $invoice Invoice.
521
-	 * @return array
522
-	 */
523
-	public function get_line_items( $invoice ) {
517
+     * Returns invoice line items.
518
+     *
519
+     *
520
+     * @param WPInv_Invoice $invoice Invoice.
521
+     * @return array
522
+     */
523
+    public function get_line_items( $invoice ) {
524 524
         $items = array();
525 525
 
526 526
         foreach ( $invoice->get_items() as $item ) {
@@ -558,15 +558,15 @@  discard block
 block discarded – undo
558 558
     }
559 559
 
560 560
     /**
561
-	 * Process Payment.
562
-	 *
563
-	 *
564
-	 * @param WPInv_Invoice $invoice Invoice.
565
-	 * @param array $submission_data Posted checkout fields.
566
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
567
-	 * @return array
568
-	 */
569
-	public function process_payment( $invoice, $submission_data, $submission ) {
561
+     * Process Payment.
562
+     *
563
+     *
564
+     * @param WPInv_Invoice $invoice Invoice.
565
+     * @param array $submission_data Posted checkout fields.
566
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
567
+     * @return array
568
+     */
569
+    public function process_payment( $invoice, $submission_data, $submission ) {
570 570
 
571 571
         // Validate the submitted data.
572 572
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -599,69 +599,69 @@  discard block
 block discarded – undo
599 599
 
600 600
         exit;
601 601
 
602
-	}
602
+    }
603 603
 	
604
-	/**
605
-	 * Processes the initial payment.
606
-	 *
604
+    /**
605
+     * Processes the initial payment.
606
+     *
607 607
      * @param WPInv_Invoice $invoice Invoice.
608
-	 */
609
-	protected function process_initial_payment( $invoice ) {
608
+     */
609
+    protected function process_initial_payment( $invoice ) {
610 610
 
611
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
611
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
612 612
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
613
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
613
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
614 614
 
615
-		// Do we have an error?
616
-		if ( is_wp_error( $result ) ) {
617
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
618
-			wpinv_send_back_to_checkout( $invoice );
619
-		}
615
+        // Do we have an error?
616
+        if ( is_wp_error( $result ) ) {
617
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
618
+            wpinv_send_back_to_checkout( $invoice );
619
+        }
620 620
 
621
-		// Process the response.
622
-		$this->process_charge_response( $result, $invoice );
621
+        // Process the response.
622
+        $this->process_charge_response( $result, $invoice );
623 623
 
624
-		if ( wpinv_get_errors() ) {
625
-			wpinv_send_back_to_checkout( $invoice );
626
-		}
624
+        if ( wpinv_get_errors() ) {
625
+            wpinv_send_back_to_checkout( $invoice );
626
+        }
627 627
 
628
-	}
628
+    }
629 629
 
630 630
     /**
631
-	 * Processes recurring payments.
632
-	 *
631
+     * Processes recurring payments.
632
+     *
633 633
      * @param WPInv_Invoice $invoice Invoice.
634 634
      * @param WPInv_Subscription $subscription Subscription.
635
-	 */
636
-	public function process_subscription( $invoice, $subscription ) {
635
+     */
636
+    public function process_subscription( $invoice, $subscription ) {
637 637
 
638 638
         // Check if there is an initial amount to charge.
639 639
         if ( (float) $invoice->get_total() > 0 ) {
640
-			$this->process_initial_payment( $invoice );
640
+            $this->process_initial_payment( $invoice );
641 641
         }
642 642
 
643 643
         // Activate the subscription.
644 644
         $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
645 645
         $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
646 646
 
647
-		$subscription->set_next_renewal_date( $expiry );
648
-		$subscription->set_date_created( current_time( 'mysql' ) );
649
-		$subscription->set_profile_id( $invoice->generate_key() );
650
-		$subscription->activate();
647
+        $subscription->set_next_renewal_date( $expiry );
648
+        $subscription->set_date_created( current_time( 'mysql' ) );
649
+        $subscription->set_profile_id( $invoice->generate_key() );
650
+        $subscription->activate();
651 651
 
652
-		// Redirect to the success page.
652
+        // Redirect to the success page.
653 653
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
654 654
 
655 655
     }
656 656
 
657
-	/**
658
-	 * (Maybe) renews an authorize.net subscription profile.
659
-	 *
660
-	 *
661
-	 * @param bool $should_expire
657
+    /**
658
+     * (Maybe) renews an authorize.net subscription profile.
659
+     *
660
+     *
661
+     * @param bool $should_expire
662 662
      * @param WPInv_Subscription $subscription
663
-	 */
664
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
663
+     */
664
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
665 665
 
666 666
         // Ensure its our subscription && it's active.
667 667
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -678,18 +678,18 @@  discard block
 block discarded – undo
678 678
 
679 679
         return false;
680 680
 
681
-	}
681
+    }
682 682
 
683 683
     /**
684
-	 * Renews a subscription.
685
-	 *
684
+     * Renews a subscription.
685
+     *
686 686
      * @param WPInv_Subscription $subscription
687
-	 */
688
-	public function renew_subscription( $subscription ) {
687
+     */
688
+    public function renew_subscription( $subscription ) {
689 689
 
690
-		// Generate the renewal invoice.
691
-		$new_invoice = $subscription->create_payment();
692
-		$old_invoice = $subscription->get_parent_payment();
690
+        // Generate the renewal invoice.
691
+        $new_invoice = $subscription->create_payment();
692
+        $old_invoice = $subscription->get_parent_payment();
693 693
 
694 694
         if ( empty( $new_invoice ) ) {
695 695
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -698,37 +698,37 @@  discard block
 block discarded – undo
698 698
         }
699 699
 
700 700
         // Charge the payment method.
701
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
702
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
703
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
704
-
705
-		// Do we have an error?
706
-		if ( is_wp_error( $result ) ) {
707
-
708
-			$old_invoice->add_note(
709
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
710
-				true,
711
-				false,
712
-				true
713
-			);
714
-			$subscription->failing();
715
-			return;
716
-
717
-		}
718
-
719
-		// Process the response.
720
-		$this->process_charge_response( $result, $new_invoice );
721
-
722
-		if ( wpinv_get_errors() ) {
723
-
724
-			$old_invoice->add_note(
725
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
726
-				true,
727
-				false,
728
-				true
729
-			);
730
-			$subscription->failing();
731
-			return;
701
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
702
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
703
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
704
+
705
+        // Do we have an error?
706
+        if ( is_wp_error( $result ) ) {
707
+
708
+            $old_invoice->add_note(
709
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
710
+                true,
711
+                false,
712
+                true
713
+            );
714
+            $subscription->failing();
715
+            return;
716
+
717
+        }
718
+
719
+        // Process the response.
720
+        $this->process_charge_response( $result, $new_invoice );
721
+
722
+        if ( wpinv_get_errors() ) {
723
+
724
+            $old_invoice->add_note(
725
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
726
+                true,
727
+                false,
728
+                true
729
+            );
730
+            $subscription->failing();
731
+            return;
732 732
 
733 733
         }
734 734
 
@@ -737,13 +737,13 @@  discard block
 block discarded – undo
737 737
     }
738 738
 
739 739
     /**
740
-	 * Processes invoice addons.
741
-	 *
742
-	 * @param WPInv_Invoice $invoice
743
-	 * @param GetPaid_Form_Item[] $items
744
-	 * @return WPInv_Invoice
745
-	 */
746
-	public function process_addons( $invoice, $items ) {
740
+     * Processes invoice addons.
741
+     *
742
+     * @param WPInv_Invoice $invoice
743
+     * @param GetPaid_Form_Item[] $items
744
+     * @return WPInv_Invoice
745
+     */
746
+    public function process_addons( $invoice, $items ) {
747 747
 
748 748
         global $getpaid_authorize_addons;
749 749
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
         $invoice->recalculate_total();
764 764
 
765 765
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
766
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
766
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
767 767
 
768 768
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
769 769
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -778,11 +778,11 @@  discard block
 block discarded – undo
778 778
     }
779 779
 
780 780
     /**
781
-	 * Processes invoice addons.
782
-	 *
781
+     * Processes invoice addons.
782
+     *
783 783
      * @param array $args
784
-	 * @return array
785
-	 */
784
+     * @return array
785
+     */
786 786
     public function filter_addons_request( $args ) {
787 787
 
788 788
         global $getpaid_authorize_addons;
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
     }
817 817
 
818 818
     /**
819
-	 * Filters the gateway settings.
820
-	 *
821
-	 * @param array $admin_settings
822
-	 */
823
-	public function admin_settings( $admin_settings ) {
819
+     * Filters the gateway settings.
820
+     *
821
+     * @param array $admin_settings
822
+     */
823
+    public function admin_settings( $admin_settings ) {
824 824
 
825 825
         $currencies = sprintf(
826 826
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
             'readonly' => true,
861 861
         );
862 862
 
863
-		return $admin_settings;
864
-	}
863
+        return $admin_settings;
864
+    }
865 865
 
866 866
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-helper.php 1 patch
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -12,294 +12,294 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Helper {
14 14
 
15
-	/**
16
-	 * Get report totals such as invoice totals and discount amounts.
17
-	 *
18
-	 * Data example:
19
-	 *
20
-	 * 'subtotal' => array(
21
-	 *     'type'     => 'invoice_data',
22
-	 *     'function' => 'SUM',
23
-	 *     'name'     => 'subtotal'
24
-	 * )
25
-	 *
26
-	 * @param  array $args
27
-	 * @return mixed depending on query_type
28
-	 */
29
-	public static function get_invoice_report_data( $args = array() ) {
30
-		global $wpdb;
31
-
32
-		$default_args = array(
33
-			'data'                  => array(), // The data to retrieve.
34
-			'where'                 => array(), // An array of where queries.
35
-			'query_type'            => 'get_row', // wpdb query to run.
36
-			'group_by'              => '', // What to group results by.
37
-			'order_by'              => '', // What to order by.
38
-			'limit'                 => '', // Results limit.
39
-			'filter_range'          => array(), // An array of before and after dates to limit results by.
40
-			'invoice_types'         => array( 'wpi_invoice' ), // An array of post types to retrieve.
41
-			'invoice_status'        => array( 'publish', 'wpi-processing', 'wpi-onhold' ),
42
-			'parent_invoice_status' => false, // Optionally filter by parent invoice status.
43
-		);
44
-
45
-		$args         = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args );
46
-		$args         = wp_parse_args( $args, $default_args );
47
-
48
-		extract( $args );
49
-
50
-		if ( empty( $data ) ) {
51
-			return '';
52
-		}
53
-
54
-		$query           = array();
55
-		$query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) );
56
-		$query['from']   = "FROM {$wpdb->posts} AS posts";
57
-		$query['join']   = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) );
58
-
59
-		$query['where']  = "
15
+    /**
16
+     * Get report totals such as invoice totals and discount amounts.
17
+     *
18
+     * Data example:
19
+     *
20
+     * 'subtotal' => array(
21
+     *     'type'     => 'invoice_data',
22
+     *     'function' => 'SUM',
23
+     *     'name'     => 'subtotal'
24
+     * )
25
+     *
26
+     * @param  array $args
27
+     * @return mixed depending on query_type
28
+     */
29
+    public static function get_invoice_report_data( $args = array() ) {
30
+        global $wpdb;
31
+
32
+        $default_args = array(
33
+            'data'                  => array(), // The data to retrieve.
34
+            'where'                 => array(), // An array of where queries.
35
+            'query_type'            => 'get_row', // wpdb query to run.
36
+            'group_by'              => '', // What to group results by.
37
+            'order_by'              => '', // What to order by.
38
+            'limit'                 => '', // Results limit.
39
+            'filter_range'          => array(), // An array of before and after dates to limit results by.
40
+            'invoice_types'         => array( 'wpi_invoice' ), // An array of post types to retrieve.
41
+            'invoice_status'        => array( 'publish', 'wpi-processing', 'wpi-onhold' ),
42
+            'parent_invoice_status' => false, // Optionally filter by parent invoice status.
43
+        );
44
+
45
+        $args         = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args );
46
+        $args         = wp_parse_args( $args, $default_args );
47
+
48
+        extract( $args );
49
+
50
+        if ( empty( $data ) ) {
51
+            return '';
52
+        }
53
+
54
+        $query           = array();
55
+        $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) );
56
+        $query['from']   = "FROM {$wpdb->posts} AS posts";
57
+        $query['join']   = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) );
58
+
59
+        $query['where']  = "
60 60
 			WHERE 	posts.post_type 	IN ( '" . implode( "','", $invoice_types ) . "' )
61 61
 			";
62 62
 
63
-		if ( ! empty( $invoice_status ) ) {
64
-			$query['where'] .= "
63
+        if ( ! empty( $invoice_status ) ) {
64
+            $query['where'] .= "
65 65
 				AND 	posts.post_status 	IN ( '" . implode( "','", $invoice_status ) . "' )
66 66
 			";
67
-		}
68
-
69
-		if ( ! empty( $parent_invoice_status ) ) {
70
-			if ( ! empty( $invoice_status ) ) {
71
-				$query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) ";
72
-			} else {
73
-				$query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) ";
74
-			}
75
-		}
76
-
77
-		if ( ! empty( $filter_range['before'] ) ) {
78
-			$query['where'] .= "
67
+        }
68
+
69
+        if ( ! empty( $parent_invoice_status ) ) {
70
+            if ( ! empty( $invoice_status ) ) {
71
+                $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) ";
72
+            } else {
73
+                $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) ";
74
+            }
75
+        }
76
+
77
+        if ( ! empty( $filter_range['before'] ) ) {
78
+            $query['where'] .= "
79 79
 				AND 	posts.post_date < '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['before'] ) ) . "'
80 80
 			";
81
-		}
81
+        }
82 82
 
83
-		if ( ! empty( $filter_range['after'] ) ) {
84
-			$query['where'] .= "
83
+        if ( ! empty( $filter_range['after'] ) ) {
84
+            $query['where'] .= "
85 85
 				AND 	posts.post_date > '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['after'] ) ) . "'
86 86
 			";
87
-		}
87
+        }
88 88
 
89
-		if ( ! empty( $where ) ) {
89
+        if ( ! empty( $where ) ) {
90 90
 
91
-			foreach ( $where as $value ) {
91
+            foreach ( $where as $value ) {
92 92
 
93
-				if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
94
-
95
-					if ( is_array( $value['value'] ) ) {
96
-						$value['value'] = implode( "','", $value['value'] );
97
-					}
98
-
99
-					if ( ! empty( $value['value'] ) ) {
100
-						$where_value = "{$value['operator']} ('{$value['value']}')";
101
-					}
102
-				} else {
103
-					$where_value = "{$value['operator']} '{$value['value']}'";
104
-				}
105
-
106
-				if ( ! empty( $where_value ) ) {
107
-					$query['where'] .= " AND {$value['key']} {$where_value}";
108
-				}
109
-			}
110
-		}
111
-
112
-		if ( $group_by ) {
113
-			$query['group_by'] = "GROUP BY {$group_by}";
114
-		}
115
-
116
-		if ( $order_by ) {
117
-			$query['order_by'] = "ORDER BY {$order_by}";
118
-		}
119
-
120
-		if ( $limit ) {
121
-			$query['limit'] = "LIMIT {$limit}";
122
-		}
123
-
124
-		$query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data );
125
-		$query = implode( ' ', $query );
126
-
127
-		return self::execute( $query_type, $query );
128
-
129
-	}
130
-
131
-	/**
132
-	 * Prepares the data to select.
133
-	 *
134
-	 *
135
-	 * @param  array $data
136
-	 * @return array
137
-	 */
138
-	public static function prepare_invoice_data( $data ) {
139
-
140
-		$prepared = array();
141
-
142
-		foreach ( $data as $raw_key => $value ) {
143
-			$key      = sanitize_key( $raw_key );
144
-			$distinct = '';
145
-
146
-			if ( isset( $value['distinct'] ) ) {
147
-				$distinct = 'DISTINCT';
148
-			}
149
-
150
-			$get_key = self::get_invoice_table_key( $key, $value['type'] );
151
-
152
-			if ( false === $get_key ) {
153
-				// Skip to the next foreach iteration else the query will be invalid.
154
-				continue;
155
-			}
156
-
157
-			if ( ! empty( $value['function'] ) ) {
158
-				$get = "{$value['function']}({$distinct} {$get_key})";
159
-			} else {
160
-				$get = "{$distinct} {$get_key}";
161
-			}
162
-
163
-			$prepared[] = "{$get} as {$value['name']}";
164
-		}
165
-
166
-		return $prepared;
167
-
168
-	}
169
-
170
-	/**
171
-	 * Prepares the joins to use.
172
-	 *
173
-	 *
174
-	 * @param  array $data
175
-	 * @param  bool $with_parent
176
-	 * @return array
177
-	 */
178
-	public static function prepare_invoice_joins( $data, $with_parent ) {
179
-		global $wpdb;
180
-
181
-		$prepared = array();
182
-
183
-		foreach ( $data as $raw_key => $value ) {
184
-			$join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
185
-			$type      = isset( $value['type'] ) ? $value['type'] : false;
186
-			$key       = sanitize_key( $raw_key );
187
-
188
-			switch ( $type ) {
189
-				case 'meta':
190
-					$prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
191
-					break;
192
-				case 'parent_meta':
193
-					$prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
194
-					break;
195
-				case 'invoice_data':
196
-					$prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id";
197
-					break;
198
-				case 'invoice_item':
199
-					$prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id";
200
-					break;
201
-			}
202
-		}
203
-
204
-		if ( $with_parent ) {
205
-			$prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
206
-		}
207
-
208
-		return $prepared;
209
-
210
-	}
211
-
212
-	/**
213
-	 * Retrieves the appropriate table key to use.
214
-	 *
215
-	 *
216
-	 * @param  string $key
217
-	 * @param  string $table
218
-	 * @return string|false
219
-	 */
220
-	public static function get_invoice_table_key( $key, $table ) {
221
-
222
-		$keys = array(
223
-			'meta'         => "meta_{$key}.meta_value",
224
-			'parent_meta'  => "parent_meta_{$key}.meta_value",
225
-			'post_data'    => "posts.{$key}",
226
-			'invoice_data' => "invoices.{$key}",
227
-			'invoice_item' => "invoice_items.{$key}",
228
-		);
229
-
230
-		return isset( $keys[ $table ] ) ? $keys[ $table ] : false;
231
-
232
-	}
233
-
234
-	/**
235
-	 * Executes a query and caches the result for a minute.
236
-	 *
237
-	 *
238
-	 * @param  string $query_type
239
-	 * @param  string $query
240
-	 * @return mixed depending on query_type
241
-	 */
242
-	public static function execute( $query_type, $query ) {
243
-		global $wpdb;
244
-
245
-		$query_hash = md5( $query_type . $query );
246
-		$result     = self::get_cached_query( $query_hash );
247
-		if ( $result === false ) {
248
-			self::enable_big_selects();
249
-
250
-			$result = $wpdb->$query_type( $query );
251
-			self::set_cached_query( $query_hash, $result );
252
-		}
253
-
254
-		return $result;
255
-
256
-	}
257
-
258
-	/**
259
-	 * Enables big mysql selects for reports, just once for this session.
260
-	 */
261
-	protected static function enable_big_selects() {
262
-		static $big_selects = false;
263
-
264
-		global $wpdb;
265
-
266
-		if ( ! $big_selects ) {
267
-			$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
268
-			$big_selects = true;
269
-		}
270
-	}
271
-
272
-	/**
273
-	 * Get the cached query result or null if it's not in the cache.
274
-	 *
275
-	 * @param string $query_hash The query hash.
276
-	 *
277
-	 * @return mixed|false The cache contents on success, false on failure to retrieve contents.
278
-	 */
279
-	protected static function get_cached_query( $query_hash ) {
280
-
281
-		return wp_cache_get(
282
-			$query_hash,
283
-			strtolower( __CLASS__ )
284
-		);
285
-
286
-	}
287
-
288
-	/**
289
-	 * Set the cached query result.
290
-	 *
291
-	 * @param string $query_hash The query hash.
292
-	 * @param mixed  $data The data to cache.
293
-	 */
294
-	protected static function set_cached_query( $query_hash, $data ) {
295
-
296
-		wp_cache_set(
297
-			$query_hash,
298
-			$data,
299
-			strtolower( __CLASS__ ),
300
-			MINUTE_IN_SECONDS
301
-		);
302
-
303
-	}
93
+                if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
94
+
95
+                    if ( is_array( $value['value'] ) ) {
96
+                        $value['value'] = implode( "','", $value['value'] );
97
+                    }
98
+
99
+                    if ( ! empty( $value['value'] ) ) {
100
+                        $where_value = "{$value['operator']} ('{$value['value']}')";
101
+                    }
102
+                } else {
103
+                    $where_value = "{$value['operator']} '{$value['value']}'";
104
+                }
105
+
106
+                if ( ! empty( $where_value ) ) {
107
+                    $query['where'] .= " AND {$value['key']} {$where_value}";
108
+                }
109
+            }
110
+        }
111
+
112
+        if ( $group_by ) {
113
+            $query['group_by'] = "GROUP BY {$group_by}";
114
+        }
115
+
116
+        if ( $order_by ) {
117
+            $query['order_by'] = "ORDER BY {$order_by}";
118
+        }
119
+
120
+        if ( $limit ) {
121
+            $query['limit'] = "LIMIT {$limit}";
122
+        }
123
+
124
+        $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data );
125
+        $query = implode( ' ', $query );
126
+
127
+        return self::execute( $query_type, $query );
128
+
129
+    }
130
+
131
+    /**
132
+     * Prepares the data to select.
133
+     *
134
+     *
135
+     * @param  array $data
136
+     * @return array
137
+     */
138
+    public static function prepare_invoice_data( $data ) {
139
+
140
+        $prepared = array();
141
+
142
+        foreach ( $data as $raw_key => $value ) {
143
+            $key      = sanitize_key( $raw_key );
144
+            $distinct = '';
145
+
146
+            if ( isset( $value['distinct'] ) ) {
147
+                $distinct = 'DISTINCT';
148
+            }
149
+
150
+            $get_key = self::get_invoice_table_key( $key, $value['type'] );
151
+
152
+            if ( false === $get_key ) {
153
+                // Skip to the next foreach iteration else the query will be invalid.
154
+                continue;
155
+            }
156
+
157
+            if ( ! empty( $value['function'] ) ) {
158
+                $get = "{$value['function']}({$distinct} {$get_key})";
159
+            } else {
160
+                $get = "{$distinct} {$get_key}";
161
+            }
162
+
163
+            $prepared[] = "{$get} as {$value['name']}";
164
+        }
165
+
166
+        return $prepared;
167
+
168
+    }
169
+
170
+    /**
171
+     * Prepares the joins to use.
172
+     *
173
+     *
174
+     * @param  array $data
175
+     * @param  bool $with_parent
176
+     * @return array
177
+     */
178
+    public static function prepare_invoice_joins( $data, $with_parent ) {
179
+        global $wpdb;
180
+
181
+        $prepared = array();
182
+
183
+        foreach ( $data as $raw_key => $value ) {
184
+            $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
185
+            $type      = isset( $value['type'] ) ? $value['type'] : false;
186
+            $key       = sanitize_key( $raw_key );
187
+
188
+            switch ( $type ) {
189
+                case 'meta':
190
+                    $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
191
+                    break;
192
+                case 'parent_meta':
193
+                    $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
194
+                    break;
195
+                case 'invoice_data':
196
+                    $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id";
197
+                    break;
198
+                case 'invoice_item':
199
+                    $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id";
200
+                    break;
201
+            }
202
+        }
203
+
204
+        if ( $with_parent ) {
205
+            $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
206
+        }
207
+
208
+        return $prepared;
209
+
210
+    }
211
+
212
+    /**
213
+     * Retrieves the appropriate table key to use.
214
+     *
215
+     *
216
+     * @param  string $key
217
+     * @param  string $table
218
+     * @return string|false
219
+     */
220
+    public static function get_invoice_table_key( $key, $table ) {
221
+
222
+        $keys = array(
223
+            'meta'         => "meta_{$key}.meta_value",
224
+            'parent_meta'  => "parent_meta_{$key}.meta_value",
225
+            'post_data'    => "posts.{$key}",
226
+            'invoice_data' => "invoices.{$key}",
227
+            'invoice_item' => "invoice_items.{$key}",
228
+        );
229
+
230
+        return isset( $keys[ $table ] ) ? $keys[ $table ] : false;
231
+
232
+    }
233
+
234
+    /**
235
+     * Executes a query and caches the result for a minute.
236
+     *
237
+     *
238
+     * @param  string $query_type
239
+     * @param  string $query
240
+     * @return mixed depending on query_type
241
+     */
242
+    public static function execute( $query_type, $query ) {
243
+        global $wpdb;
244
+
245
+        $query_hash = md5( $query_type . $query );
246
+        $result     = self::get_cached_query( $query_hash );
247
+        if ( $result === false ) {
248
+            self::enable_big_selects();
249
+
250
+            $result = $wpdb->$query_type( $query );
251
+            self::set_cached_query( $query_hash, $result );
252
+        }
253
+
254
+        return $result;
255
+
256
+    }
257
+
258
+    /**
259
+     * Enables big mysql selects for reports, just once for this session.
260
+     */
261
+    protected static function enable_big_selects() {
262
+        static $big_selects = false;
263
+
264
+        global $wpdb;
265
+
266
+        if ( ! $big_selects ) {
267
+            $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
268
+            $big_selects = true;
269
+        }
270
+    }
271
+
272
+    /**
273
+     * Get the cached query result or null if it's not in the cache.
274
+     *
275
+     * @param string $query_hash The query hash.
276
+     *
277
+     * @return mixed|false The cache contents on success, false on failure to retrieve contents.
278
+     */
279
+    protected static function get_cached_query( $query_hash ) {
280
+
281
+        return wp_cache_get(
282
+            $query_hash,
283
+            strtolower( __CLASS__ )
284
+        );
285
+
286
+    }
287
+
288
+    /**
289
+     * Set the cached query result.
290
+     *
291
+     * @param string $query_hash The query hash.
292
+     * @param mixed  $data The data to cache.
293
+     */
294
+    protected static function set_cached_query( $query_hash, $data ) {
295
+
296
+        wp_cache_set(
297
+            $query_hash,
298
+            $data,
299
+            strtolower( __CLASS__ ),
300
+            MINUTE_IN_SECONDS
301
+        );
302
+
303
+    }
304 304
 
305 305
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -12,228 +12,228 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Validate VAT number.
35
+        $this->validate_vat( $submission );
36
+
37
+        if ( $this->skip_taxes ) {
38
+            return;
39
+        }
40
+
41
+        foreach ( $submission->get_items() as $item ) {
42
+            $this->process_item_tax( $item, $submission );
43
+        }
44
+
45
+        // Process any existing invoice taxes.
46
+        if ( $submission->has_invoice() ) {
47
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
+        }
49
+
50
+    }
51
+
52
+    /**
53
+     * Maybe process tax.
54
+     *
55
+     * @since 1.0.19
56
+     * @param GetPaid_Form_Item $item
57
+     * @param GetPaid_Payment_Form_Submission $submission
58
+     */
59
+    public function process_item_tax( $item, $submission ) {
60
+
61
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
+
66
+        foreach ( $taxes as $name => $amount ) {
67
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
+
70
+            if ( ! isset( $this->taxes[ $name ] ) ) {
71
+                $this->taxes[ $name ] = $tax;
72
+                continue;
73
+            }
74
+
75
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
76
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
+
78
+        }
79
+
80
+    }
81
+
82
+    /**
83
+     * Checks if the submission has a digital item.
84
+     *
85
+     * @param GetPaid_Payment_Form_Submission $submission
86
+     * @since 1.0.19
87
+     * @return bool
88
+     */
89
+    public function has_digital_item( $submission ) {
90
+
91
+        foreach ( $submission->get_items() as $item ) {
92
+
93
+            if ( 'digital' == $item->get_vat_rule() ) {
94
+                return true;
95
+            }
96
+
97
+        }
98
+
99
+        return false;
100
+    }
101
+
102
+    /**
103
+     * Checks if this is an eu store.
104
+     *
105
+     * @since 1.0.19
106
+     * @return bool
107
+     */
108
+    public static function is_eu_store() {
109
+        return self::is_eu_country( wpinv_get_default_country() );
110
+    }
26 111
 
27 112
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Validate VAT number.
35
-		$this->validate_vat( $submission );
36
-
37
-		if ( $this->skip_taxes ) {
38
-			return;
39
-		}
40
-
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
43
-		}
44
-
45
-		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
-		}
49
-
50
-	}
51
-
52
-	/**
53
-	 * Maybe process tax.
54
-	 *
55
-	 * @since 1.0.19
56
-	 * @param GetPaid_Form_Item $item
57
-	 * @param GetPaid_Payment_Form_Submission $submission
58
-	 */
59
-	public function process_item_tax( $item, $submission ) {
60
-
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
-
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
-
70
-			if ( ! isset( $this->taxes[ $name ] ) ) {
71
-				$this->taxes[ $name ] = $tax;
72
-				continue;
73
-			}
74
-
75
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
76
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
-
78
-		}
79
-
80
-	}
81
-
82
-	/**
83
-	 * Checks if the submission has a digital item.
84
-	 *
85
-	 * @param GetPaid_Payment_Form_Submission $submission
86
-	 * @since 1.0.19
87
-	 * @return bool
88
-	 */
89
-	public function has_digital_item( $submission ) {
90
-
91
-		foreach ( $submission->get_items() as $item ) {
92
-
93
-			if ( 'digital' == $item->get_vat_rule() ) {
94
-				return true;
95
-			}
96
-
97
-		}
98
-
99
-		return false;
100
-	}
101
-
102
-	/**
103
-	 * Checks if this is an eu store.
104
-	 *
105
-	 * @since 1.0.19
106
-	 * @return bool
107
-	 */
108
-	public static function is_eu_store() {
109
-		return self::is_eu_country( wpinv_get_default_country() );
110
-	}
111
-
112
-	/**
113
-	 * Checks if this is an eu country.
114
-	 *
115
-	 * @param string $country
116
-	 * @since 1.0.19
117
-	 * @return bool
118
-	 */
119
-	public static function is_eu_country( $country ) {
120
-		return getpaid_is_eu_state( $country );
121
-	}
122
-
123
-	/**
124
-	 * Checks if this is an eu purchase.
125
-	 *
126
-	 * @param string $customer_country
127
-	 * @since 1.0.19
128
-	 * @return bool
129
-	 */
130
-	public static function is_eu_transaction( $customer_country ) {
131
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
-	}
133
-
134
-	/**
135
-	 * Retrieves the vat number.
136
-	 *
137
-	 * @param GetPaid_Payment_Form_Submission $submission
138
-	 * @since 1.0.19
139
-	 * @return string
140
-	 */
141
-	public function get_vat_number( $submission ) {
142
-
143
-		// Retrieve from the posted number.
144
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
145
-		if ( ! is_null( $vat_number ) ) {
146
-			return wpinv_clean( $vat_number );
147
-		}
148
-
149
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
150
-	}
151
-
152
-	/**
153
-	 * Retrieves the company.
154
-	 *
155
-	 * @param GetPaid_Payment_Form_Submission $submission
156
-	 * @since 1.0.19
157
-	 * @return string
158
-	 */
159
-	public function get_company( $submission ) {
160
-
161
-		// Retrieve from the posted data.
162
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
163
-		if ( ! empty( $company ) ) {
164
-			return wpinv_clean( $company );
165
-		}
166
-
167
-		// Retrieve from the invoice.
168
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
169
-	}
170
-
171
-	/**
172
-	 * Checks if we require a VAT number.
173
-	 *
174
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
175
-	 * @param bool $country_in_eu Whether the customer country is from the EU
176
-	 * @since 1.0.19
177
-	 * @return string
178
-	 */
179
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
180
-
181
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
182
-		$prevent_b2c = ! empty( $prevent_b2c );
183
-		$is_eu       = $ip_in_eu || $country_in_eu;
184
-
185
-		return $prevent_b2c && $is_eu;
186
-	}
187
-
188
-	/**
189
-	 * Validate VAT data.
190
-	 *
191
-	 * @param GetPaid_Payment_Form_Submission $submission
192
-	 * @since 1.0.19
193
-	 */
194
-	public function validate_vat( $submission ) {
195
-
196
-		$in_eu = $this->is_eu_transaction( $submission->country );
197
-
198
-		// Abort if we are not validating vat numbers.
199
-		if ( ! $in_eu ) {
113
+     * Checks if this is an eu country.
114
+     *
115
+     * @param string $country
116
+     * @since 1.0.19
117
+     * @return bool
118
+     */
119
+    public static function is_eu_country( $country ) {
120
+        return getpaid_is_eu_state( $country );
121
+    }
122
+
123
+    /**
124
+     * Checks if this is an eu purchase.
125
+     *
126
+     * @param string $customer_country
127
+     * @since 1.0.19
128
+     * @return bool
129
+     */
130
+    public static function is_eu_transaction( $customer_country ) {
131
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
+    }
133
+
134
+    /**
135
+     * Retrieves the vat number.
136
+     *
137
+     * @param GetPaid_Payment_Form_Submission $submission
138
+     * @since 1.0.19
139
+     * @return string
140
+     */
141
+    public function get_vat_number( $submission ) {
142
+
143
+        // Retrieve from the posted number.
144
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
145
+        if ( ! is_null( $vat_number ) ) {
146
+            return wpinv_clean( $vat_number );
147
+        }
148
+
149
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
150
+    }
151
+
152
+    /**
153
+     * Retrieves the company.
154
+     *
155
+     * @param GetPaid_Payment_Form_Submission $submission
156
+     * @since 1.0.19
157
+     * @return string
158
+     */
159
+    public function get_company( $submission ) {
160
+
161
+        // Retrieve from the posted data.
162
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
163
+        if ( ! empty( $company ) ) {
164
+            return wpinv_clean( $company );
165
+        }
166
+
167
+        // Retrieve from the invoice.
168
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
169
+    }
170
+
171
+    /**
172
+     * Checks if we require a VAT number.
173
+     *
174
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
175
+     * @param bool $country_in_eu Whether the customer country is from the EU
176
+     * @since 1.0.19
177
+     * @return string
178
+     */
179
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
180
+
181
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
182
+        $prevent_b2c = ! empty( $prevent_b2c );
183
+        $is_eu       = $ip_in_eu || $country_in_eu;
184
+
185
+        return $prevent_b2c && $is_eu;
186
+    }
187
+
188
+    /**
189
+     * Validate VAT data.
190
+     *
191
+     * @param GetPaid_Payment_Form_Submission $submission
192
+     * @since 1.0.19
193
+     */
194
+    public function validate_vat( $submission ) {
195
+
196
+        $in_eu = $this->is_eu_transaction( $submission->country );
197
+
198
+        // Abort if we are not validating vat numbers.
199
+        if ( ! $in_eu ) {
200 200
             return;
201
-		}
201
+        }
202 202
 
203
-		// Prepare variables.
204
-		$vat_number  = $this->get_vat_number( $submission );
205
-		$ip_country  = getpaid_get_ip_country();
203
+        // Prepare variables.
204
+        $vat_number  = $this->get_vat_number( $submission );
205
+        $ip_country  = getpaid_get_ip_country();
206 206
         $is_eu       = $this->is_eu_country( $submission->country );
207 207
         $is_ip_eu    = $this->is_eu_country( $ip_country );
208 208
 
209
-		// Maybe abort early for initial fetches.
210
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
211
-			return;
212
-		}
209
+        // Maybe abort early for initial fetches.
210
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
211
+            return;
212
+        }
213 213
 
214
-		// If we're preventing business to consumer purchases,
215
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
214
+        // If we're preventing business to consumer purchases,
215
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216 216
 
217
-			// Ensure that a vat number has been specified.
218
-			throw new Exception(
219
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
220
-			);
217
+            // Ensure that a vat number has been specified.
218
+            throw new Exception(
219
+                __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
220
+            );
221 221
 
222
-		}
222
+        }
223 223
 
224
-		if ( empty( $vat_number ) ) {
225
-			return;
226
-		}
224
+        if ( empty( $vat_number ) ) {
225
+            return;
226
+        }
227 227
 
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
230
-		}
228
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
+            throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
230
+        }
231 231
 
232
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
-			return;
234
-		}
232
+        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
+            return;
234
+        }
235 235
 
236
-		$this->skip_taxes = true;
237
-	}
236
+        $this->skip_taxes = true;
237
+    }
238 238
 
239 239
 }
Please login to merge, or discard this patch.
vendor/composer/installed.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php return array (
2
-  'root' => 
3
-  array (
2
+    'root' => 
3
+    array (
4 4
     'pretty_version' => 'dev-master',
5 5
     'version' => 'dev-master',
6 6
     'aliases' => 
@@ -8,85 +8,85 @@  discard block
 block discarded – undo
8 8
     ),
9 9
     'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
10 10
     'name' => 'ayecode/invoicing',
11
-  ),
12
-  'versions' => 
13
-  array (
11
+    ),
12
+    'versions' => 
13
+    array (
14 14
     'ayecode/ayecode-connect-helper' => 
15 15
     array (
16
-      'pretty_version' => '1.0.3',
17
-      'version' => '1.0.3.0',
18
-      'aliases' => 
19
-      array (
20
-      ),
21
-      'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
16
+        'pretty_version' => '1.0.3',
17
+        'version' => '1.0.3.0',
18
+        'aliases' => 
19
+        array (
20
+        ),
21
+        'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
22 22
     ),
23 23
     'ayecode/invoicing' => 
24 24
     array (
25
-      'pretty_version' => 'dev-master',
26
-      'version' => 'dev-master',
27
-      'aliases' => 
28
-      array (
29
-      ),
30
-      'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
25
+        'pretty_version' => 'dev-master',
26
+        'version' => 'dev-master',
27
+        'aliases' => 
28
+        array (
29
+        ),
30
+        'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
31 31
     ),
32 32
     'ayecode/wp-ayecode-ui' => 
33 33
     array (
34
-      'pretty_version' => '0.1.46',
35
-      'version' => '0.1.46.0',
36
-      'aliases' => 
37
-      array (
38
-      ),
39
-      'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3',
34
+        'pretty_version' => '0.1.46',
35
+        'version' => '0.1.46.0',
36
+        'aliases' => 
37
+        array (
38
+        ),
39
+        'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3',
40 40
     ),
41 41
     'ayecode/wp-font-awesome-settings' => 
42 42
     array (
43
-      'pretty_version' => '1.0.12',
44
-      'version' => '1.0.12.0',
45
-      'aliases' => 
46
-      array (
47
-      ),
48
-      'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
43
+        'pretty_version' => '1.0.12',
44
+        'version' => '1.0.12.0',
45
+        'aliases' => 
46
+        array (
47
+        ),
48
+        'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
49 49
     ),
50 50
     'ayecode/wp-super-duper' => 
51 51
     array (
52
-      'pretty_version' => '1.0.24',
53
-      'version' => '1.0.24.0',
54
-      'aliases' => 
55
-      array (
56
-      ),
57
-      'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754',
52
+        'pretty_version' => '1.0.24',
53
+        'version' => '1.0.24.0',
54
+        'aliases' => 
55
+        array (
56
+        ),
57
+        'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754',
58 58
     ),
59 59
     'composer/installers' => 
60 60
     array (
61
-      'pretty_version' => 'v1.10.0',
62
-      'version' => '1.10.0.0',
63
-      'aliases' => 
64
-      array (
65
-      ),
66
-      'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d',
61
+        'pretty_version' => 'v1.10.0',
62
+        'version' => '1.10.0.0',
63
+        'aliases' => 
64
+        array (
65
+        ),
66
+        'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d',
67 67
     ),
68 68
     'maxmind-db/reader' => 
69 69
     array (
70
-      'pretty_version' => 'v1.6.0',
71
-      'version' => '1.6.0.0',
72
-      'aliases' => 
73
-      array (
74
-      ),
75
-      'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
70
+        'pretty_version' => 'v1.6.0',
71
+        'version' => '1.6.0.0',
72
+        'aliases' => 
73
+        array (
74
+        ),
75
+        'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
76 76
     ),
77 77
     'roundcube/plugin-installer' => 
78 78
     array (
79
-      'replaced' => 
80
-      array (
79
+        'replaced' => 
80
+        array (
81 81
         0 => '*',
82
-      ),
82
+        ),
83 83
     ),
84 84
     'shama/baton' => 
85 85
     array (
86
-      'replaced' => 
87
-      array (
86
+        'replaced' => 
87
+        array (
88 88
         0 => '*',
89
-      ),
89
+        ),
90
+    ),
90 91
     ),
91
-  ),
92 92
 );
Please login to merge, or discard this patch.
vendor/composer/InstalledVersions.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 class InstalledVersions
13 13
 {
14 14
 private static $installed = array (
15
-  'root' => 
16
-  array (
15
+    'root' => 
16
+    array (
17 17
     'pretty_version' => 'dev-master',
18 18
     'version' => 'dev-master',
19 19
     'aliases' => 
@@ -21,87 +21,87 @@  discard block
 block discarded – undo
21 21
     ),
22 22
     'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
23 23
     'name' => 'ayecode/invoicing',
24
-  ),
25
-  'versions' => 
26
-  array (
24
+    ),
25
+    'versions' => 
26
+    array (
27 27
     'ayecode/ayecode-connect-helper' => 
28 28
     array (
29
-      'pretty_version' => '1.0.3',
30
-      'version' => '1.0.3.0',
31
-      'aliases' => 
32
-      array (
33
-      ),
34
-      'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
29
+        'pretty_version' => '1.0.3',
30
+        'version' => '1.0.3.0',
31
+        'aliases' => 
32
+        array (
33
+        ),
34
+        'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
35 35
     ),
36 36
     'ayecode/invoicing' => 
37 37
     array (
38
-      'pretty_version' => 'dev-master',
39
-      'version' => 'dev-master',
40
-      'aliases' => 
41
-      array (
42
-      ),
43
-      'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
38
+        'pretty_version' => 'dev-master',
39
+        'version' => 'dev-master',
40
+        'aliases' => 
41
+        array (
42
+        ),
43
+        'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
44 44
     ),
45 45
     'ayecode/wp-ayecode-ui' => 
46 46
     array (
47
-      'pretty_version' => '0.1.46',
48
-      'version' => '0.1.46.0',
49
-      'aliases' => 
50
-      array (
51
-      ),
52
-      'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3',
47
+        'pretty_version' => '0.1.46',
48
+        'version' => '0.1.46.0',
49
+        'aliases' => 
50
+        array (
51
+        ),
52
+        'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3',
53 53
     ),
54 54
     'ayecode/wp-font-awesome-settings' => 
55 55
     array (
56
-      'pretty_version' => '1.0.12',
57
-      'version' => '1.0.12.0',
58
-      'aliases' => 
59
-      array (
60
-      ),
61
-      'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
56
+        'pretty_version' => '1.0.12',
57
+        'version' => '1.0.12.0',
58
+        'aliases' => 
59
+        array (
60
+        ),
61
+        'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
62 62
     ),
63 63
     'ayecode/wp-super-duper' => 
64 64
     array (
65
-      'pretty_version' => '1.0.24',
66
-      'version' => '1.0.24.0',
67
-      'aliases' => 
68
-      array (
69
-      ),
70
-      'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754',
65
+        'pretty_version' => '1.0.24',
66
+        'version' => '1.0.24.0',
67
+        'aliases' => 
68
+        array (
69
+        ),
70
+        'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754',
71 71
     ),
72 72
     'composer/installers' => 
73 73
     array (
74
-      'pretty_version' => 'v1.10.0',
75
-      'version' => '1.10.0.0',
76
-      'aliases' => 
77
-      array (
78
-      ),
79
-      'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d',
74
+        'pretty_version' => 'v1.10.0',
75
+        'version' => '1.10.0.0',
76
+        'aliases' => 
77
+        array (
78
+        ),
79
+        'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d',
80 80
     ),
81 81
     'maxmind-db/reader' => 
82 82
     array (
83
-      'pretty_version' => 'v1.6.0',
84
-      'version' => '1.6.0.0',
85
-      'aliases' => 
86
-      array (
87
-      ),
88
-      'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
83
+        'pretty_version' => 'v1.6.0',
84
+        'version' => '1.6.0.0',
85
+        'aliases' => 
86
+        array (
87
+        ),
88
+        'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
89 89
     ),
90 90
     'roundcube/plugin-installer' => 
91 91
     array (
92
-      'replaced' => 
93
-      array (
92
+        'replaced' => 
93
+        array (
94 94
         0 => '*',
95
-      ),
95
+        ),
96 96
     ),
97 97
     'shama/baton' => 
98 98
     array (
99
-      'replaced' => 
100
-      array (
99
+        'replaced' => 
100
+        array (
101 101
         0 => '*',
102
-      ),
102
+        ),
103
+    ),
103 104
     ),
104
-  ),
105 105
 );
106 106
 
107 107
 
Please login to merge, or discard this patch.