Passed
Push — master ( 6086f2...9dee83 )
by Kiran
09:50 queued 20s
created
wp-ayecode-ui/includes/components/class-aui-component-pagination.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,112 +11,112 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Pagination {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function get( $args = array() ) {
22
-		global $wp_query, $aui_bs5;
23
-
24
-		$defaults = array(
25
-			'class'              => '',
26
-			'mid_size'           => 2,
27
-			'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28
-			'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
-			'screen_reader_text' => __( 'Posts navigation', 'ayecode-connect' ),
30
-			'before_paging'      => '',
31
-			'after_paging'       => '',
32
-			'type'               => 'array',
33
-			'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
34
-			'links'              => array(), // an array of links if using custom links, this includes the a tag.
35
-			'rounded_style'      => false,
36
-			'custom_next_text'   => '', // Custom next page text
37
-			'custom_prev_text'   => '', // Custom prev page text
38
-		);
39
-
40
-		/**
41
-		 * Parse incoming $args into an array and merge it with $defaults
42
-		 */
43
-		$args = wp_parse_args( $args, $defaults );
44
-
45
-		$output = '';
46
-
47
-		// Don't print empty markup if there's only one page.
48
-		if ( $args['total'] > 1 ) {
49
-			// Set up paginated links.
50
-			$links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
51
-
52
-			$class = !empty($args['class']) ? $args['class'] : '';
53
-
54
-			$custom_prev_link = '';
55
-			$custom_next_link = '';
56
-
57
-			// make the output bootstrap ready
58
-			$links_html = "<ul class='pagination m-0 p-0 $class'>";
59
-			if ( ! empty( $links ) ) {
60
-				foreach ( $links as $link ) {
61
-					$_link = $link;
62
-
63
-					if ( $aui_bs5 ) {
64
-						$link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link';
65
-						$link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active';
66
-						$links_html .= "<li class='page-item mx-0'>";
67
-						$link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link );
68
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
69
-						$links_html .=  $link;
70
-						$links_html .= "</li>";
71
-					} else {
72
-						$active = strpos( $link, 'current' ) !== false ? 'active' : '';
73
-						$links_html .= "<li class='page-item $active'>";
74
-						$links_html .= str_replace( "page-numbers", "page-link", $link );
75
-						$links_html .= "</li>";
76
-					}
77
-
78
-					if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) {
79
-						$link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link );
80
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
81
-
82
-						if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) {
83
-							$custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link );
84
-						} else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) {
85
-							$custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link );
86
-						}
87
-					}
88
-				}
89
-			}
90
-			$links_html .= "</ul>";
91
-
92
-			if ( $links ) {
93
-				$output .= '<section class="px-0 py-2 w-100">';
94
-				$output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
95
-				$output .= '</section>';
96
-			}
97
-
98
-			$output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output );
99
-			$output = str_replace( "nav-links", "aui-nav-links", $output );
100
-		}
101
-
102
-		if ( $output ) {
103
-			if ( $custom_next_link || $custom_prev_link ) {
104
-				$total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
105
-				$current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
106
-
107
-				$output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>';
108
-			}
109
-
110
-			if ( ! empty( $args['before_paging'] ) ) {
111
-				$output = $args['before_paging'] . $output;
112
-			}
113
-
114
-			if ( ! empty( $args['after_paging'] ) ) {
115
-				$output = $output . $args['after_paging'];
116
-			}
117
-		}
118
-
119
-		return $output;
120
-	}
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function get( $args = array() ) {
22
+        global $wp_query, $aui_bs5;
23
+
24
+        $defaults = array(
25
+            'class'              => '',
26
+            'mid_size'           => 2,
27
+            'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28
+            'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
+            'screen_reader_text' => __( 'Posts navigation', 'ayecode-connect' ),
30
+            'before_paging'      => '',
31
+            'after_paging'       => '',
32
+            'type'               => 'array',
33
+            'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
34
+            'links'              => array(), // an array of links if using custom links, this includes the a tag.
35
+            'rounded_style'      => false,
36
+            'custom_next_text'   => '', // Custom next page text
37
+            'custom_prev_text'   => '', // Custom prev page text
38
+        );
39
+
40
+        /**
41
+         * Parse incoming $args into an array and merge it with $defaults
42
+         */
43
+        $args = wp_parse_args( $args, $defaults );
44
+
45
+        $output = '';
46
+
47
+        // Don't print empty markup if there's only one page.
48
+        if ( $args['total'] > 1 ) {
49
+            // Set up paginated links.
50
+            $links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
51
+
52
+            $class = !empty($args['class']) ? $args['class'] : '';
53
+
54
+            $custom_prev_link = '';
55
+            $custom_next_link = '';
56
+
57
+            // make the output bootstrap ready
58
+            $links_html = "<ul class='pagination m-0 p-0 $class'>";
59
+            if ( ! empty( $links ) ) {
60
+                foreach ( $links as $link ) {
61
+                    $_link = $link;
62
+
63
+                    if ( $aui_bs5 ) {
64
+                        $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link';
65
+                        $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active';
66
+                        $links_html .= "<li class='page-item mx-0'>";
67
+                        $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link );
68
+                        $link = str_replace( 'text-dark link-primary current', 'current', $link );
69
+                        $links_html .=  $link;
70
+                        $links_html .= "</li>";
71
+                    } else {
72
+                        $active = strpos( $link, 'current' ) !== false ? 'active' : '';
73
+                        $links_html .= "<li class='page-item $active'>";
74
+                        $links_html .= str_replace( "page-numbers", "page-link", $link );
75
+                        $links_html .= "</li>";
76
+                    }
77
+
78
+                    if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) {
79
+                        $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link );
80
+                        $link = str_replace( 'text-dark link-primary current', 'current', $link );
81
+
82
+                        if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) {
83
+                            $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link );
84
+                        } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) {
85
+                            $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link );
86
+                        }
87
+                    }
88
+                }
89
+            }
90
+            $links_html .= "</ul>";
91
+
92
+            if ( $links ) {
93
+                $output .= '<section class="px-0 py-2 w-100">';
94
+                $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
95
+                $output .= '</section>';
96
+            }
97
+
98
+            $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output );
99
+            $output = str_replace( "nav-links", "aui-nav-links", $output );
100
+        }
101
+
102
+        if ( $output ) {
103
+            if ( $custom_next_link || $custom_prev_link ) {
104
+                $total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
105
+                $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
106
+
107
+                $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>';
108
+            }
109
+
110
+            if ( ! empty( $args['before_paging'] ) ) {
111
+                $output = $args['before_paging'] . $output;
112
+            }
113
+
114
+            if ( ! empty( $args['after_paging'] ) ) {
115
+                $output = $output . $args['after_paging'];
116
+            }
117
+        }
118
+
119
+        return $output;
120
+    }
121 121
 
122 122
 }
123 123
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/inc/bs5-js.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1001,8 +1001,8 @@
 block discarded – undo
1001 1001
     aui_flip_color_scheme_on_scroll();
1002 1002
 
1003 1003
 	<?php
1004
-	// FSE tweaks.
1005
-	if(!empty($_REQUEST['postType'])){ ?>
1004
+    // FSE tweaks.
1005
+    if(!empty($_REQUEST['postType'])){ ?>
1006 1006
     function aui_fse_set_data_scroll() {
1007 1007
         console.log('init scroll');
1008 1008
         let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas");
Please login to merge, or discard this patch.
vendor/ayecode/ayecode-connect-helper/ayecode-connect-helper.php 1 patch
Indentation   +302 added lines, -302 removed lines patch added patch discarded remove patch
@@ -1,264 +1,264 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 if ( ! class_exists( "AyeCode_Connect_Helper" ) ) {
7
-	/**
8
-	 * Allow the quick setup and connection of our AyeCode Connect plugin.
9
-	 *
10
-	 * Class AyeCode_Connect_Helper
11
-	 */
12
-	class AyeCode_Connect_Helper {
13
-
14
-		// Hold the version number
15
-		var $version = "1.0.4";
16
-
17
-		// Hold the default strings.
18
-		var $strings = array();
19
-
20
-		// Hold the default pages.
21
-		var $pages = array();
22
-
23
-		/**
24
-		 * The constructor.
25
-		 *
26
-		 * AyeCode_Connect_Helper constructor.
27
-		 *
28
-		 * @param array $strings
29
-		 * @param array $pages
30
-		 */
31
-		public function __construct( $strings = array(), $pages = array() ) {
32
-			// Only fire if not localhost and the current user has the right permissions.
33
-			if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) {
34
-				// set default strings
35
-				$default_strings = array(
36
-					'connect_title'     => __( "Thanks for choosing an AyeCode Product!", 'ayecode-connect' ),
37
-					'connect_external'  => __( "Please confirm you wish to connect your site?", 'ayecode-connect' ),
38
-					'connect'           => wp_sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", 'ayecode-connect' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ),
39
-					'connect_button'    => __( "Connect Site", 'ayecode-connect' ),
40
-					'connecting_button' => __( "Connecting...", 'ayecode-connect' ),
41
-					'error_localhost'   => __( "This service will only work with a live domain, not a localhost.", 'ayecode-connect' ),
42
-					'error'             => __( "Something went wrong, please refresh and try again.", 'ayecode-connect' ),
43
-				);
44
-				$this->strings   = array_merge( $default_strings, $strings );
45
-
46
-				// set default pages
47
-				$default_pages = array();
48
-				$this->pages   = array_merge( $default_pages, $pages );
49
-
50
-				// maybe show connect site notice
51
-				add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) );
52
-
53
-				// add ajax action if not already added
54
-				if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) {
55
-					add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) );
56
-				}
57
-			}
58
-
59
-			// add ajax action if not already added
60
-			if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) {
61
-				add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) );
62
-			}
63
-		}
64
-
65
-		/**
66
-		 * Give a way to check we can connect via a external redirect.
67
-		 */
68
-		public function ayecode_connect_helper_installed(){
69
-			$active = array(
70
-				'gd'    =>  defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0,
71
-				'uwp'    =>  defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0,
72
-				'wpi'    =>  defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0,
73
-			);
74
-			wp_send_json_success( $active );
75
-			wp_die();
76
-		}
77
-
78
-		/**
79
-		 * Get slug from path
80
-		 *
81
-		 * @param  string $key
82
-		 *
83
-		 * @return string
84
-		 */
85
-		private function format_plugin_slug( $key ) {
86
-			$slug = explode( '/', $key );
87
-			$slug = explode( '.', end( $slug ) );
88
-
89
-			return $slug[0];
90
-		}
91
-
92
-		/**
93
-		 * Install and activate the AyeCode Connect Plugin
94
-		 */
95
-		public function ayecode_connect_install() {
96
-			// bail if localhost
97
-			if ( $this->is_localhost() ) {
98
-				wp_send_json_error( $this->strings['error_localhost'] );
99
-			}
100
-
101
-			// Explicitly clear the event.
102
-			wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() );
103
-
104
-			$success     = true;
105
-			$plugin_slug = "ayecode-connect";
106
-			if ( ! empty( $plugin_slug ) ) {
107
-				require_once( ABSPATH . 'wp-admin/includes/file.php' );
108
-				require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
109
-				require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
110
-				require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
111
-
112
-				WP_Filesystem();
113
-
114
-				$skin              = new Automatic_Upgrader_Skin;
115
-				$upgrader          = new WP_Upgrader( $skin );
116
-				$installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) );
117
-				$plugin_slug       = $plugin_slug;
118
-				$plugin            = $plugin_slug . '/' . $plugin_slug . '.php';
119
-				$installed         = false;
120
-				$activate          = false;
121
-
122
-				// See if the plugin is installed already
123
-				if ( in_array( $plugin_slug, $installed_plugins ) ) {
124
-					$installed = true;
125
-					$activate  = ! is_plugin_active( $plugin );
126
-				}
127
-
128
-				// Install this thing!
129
-				if ( ! $installed ) {
130
-
131
-					// Suppress feedback
132
-					ob_start();
133
-
134
-					try {
135
-						$plugin_information = plugins_api( 'plugin_information', array(
136
-							'slug'   => $plugin_slug,
137
-							'fields' => array(
138
-								'short_description' => false,
139
-								'sections'          => false,
140
-								'requires'          => false,
141
-								'rating'            => false,
142
-								'ratings'           => false,
143
-								'downloaded'        => false,
144
-								'last_updated'      => false,
145
-								'added'             => false,
146
-								'tags'              => false,
147
-								'homepage'          => false,
148
-								'donate_link'       => false,
149
-								'author_profile'    => false,
150
-								'author'            => false,
151
-							),
152
-						) );
153
-
154
-						if ( is_wp_error( $plugin_information ) ) {
155
-							throw new Exception( $plugin_information->get_error_message() );
156
-						}
157
-
158
-						$package  = $plugin_information->download_link;
159
-						$download = $upgrader->download_package( $package );
160
-
161
-						if ( is_wp_error( $download ) ) {
162
-							throw new Exception( $download->get_error_message() );
163
-						}
164
-
165
-						$working_dir = $upgrader->unpack_package( $download, true );
166
-
167
-						if ( is_wp_error( $working_dir ) ) {
168
-							throw new Exception( $working_dir->get_error_message() );
169
-						}
170
-
171
-						$result = $upgrader->install_package( array(
172
-							'source'                      => $working_dir,
173
-							'destination'                 => WP_PLUGIN_DIR,
174
-							'clear_destination'           => false,
175
-							'abort_if_destination_exists' => false,
176
-							'clear_working'               => true,
177
-							'hook_extra'                  => array(
178
-								'type'   => 'plugin',
179
-								'action' => 'install',
180
-							),
181
-						) );
182
-
183
-						if ( is_wp_error( $result ) ) {
184
-							throw new Exception( $result->get_error_message() );
185
-						}
186
-
187
-						$activate = true;
188
-
189
-					} catch ( Exception $e ) {
190
-						$success = false;
191
-					}
192
-
193
-					// Discard feedback
194
-					ob_end_clean();
195
-				}
196
-
197
-				wp_clean_plugins_cache();
198
-
199
-				// Activate this thing
200
-				if ( $activate ) {
201
-					try {
202
-						$result = activate_plugin( $plugin );
203
-
204
-						if ( is_wp_error( $result ) ) {
205
-							$success = false;
206
-						} else {
207
-							$success = true;
208
-						}
209
-					} catch ( Exception $e ) {
210
-						$success = false;
211
-					}
212
-				}
213
-			}
214
-
215
-			if ( $success && function_exists( 'ayecode_connect_args' ) ) {
216
-				ayecode_connect();// init
217
-				$args        = ayecode_connect_args();
218
-				$client      = new AyeCode_Connect( $args );
219
-				$redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : '';
220
-				$redirect    = $client->build_connect_url( $redirect_to );
221
-				wp_send_json_success( array( 'connect_url' => $redirect ) );
222
-			} else {
223
-				wp_send_json_error( $this->strings['error_localhost'] );
224
-			}
225
-			wp_die();
226
-		}
227
-
228
-		/**
229
-		 * Check if maybe localhost.
230
-		 *
231
-		 * @return bool
232
-		 */
233
-		public function is_localhost() {
234
-			$localhost = false;
235
-
236
-			$host              = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '';
237
-			$localhost_domains = array(
238
-				'localhost',
239
-				'localhost.localdomain',
240
-				'127.0.0.1',
241
-				'::1'
242
-			);
243
-
244
-			if ( in_array( $host, $localhost_domains ) ) {
245
-				$localhost = true;
246
-			}
247
-
248
-			return $localhost;
249
-		}
250
-
251
-		/**
252
-		 * Show notice to connect site.
253
-		 */
254
-		public function ayecode_connect_install_notice() {
255
-			if ( $this->maybe_show() ) {
256
-				$connect_title_string     = $this->strings['connect_title'];
257
-				$connect_external_string  = $this->strings['connect_external'];
258
-				$connect_string           = $this->strings['connect'];
259
-				$connect_button_string    = $this->strings['connect_button'];
260
-				$connecting_button_string = $this->strings['connecting_button'];
261
-				?>
7
+    /**
8
+     * Allow the quick setup and connection of our AyeCode Connect plugin.
9
+     *
10
+     * Class AyeCode_Connect_Helper
11
+     */
12
+    class AyeCode_Connect_Helper {
13
+
14
+        // Hold the version number
15
+        var $version = "1.0.4";
16
+
17
+        // Hold the default strings.
18
+        var $strings = array();
19
+
20
+        // Hold the default pages.
21
+        var $pages = array();
22
+
23
+        /**
24
+         * The constructor.
25
+         *
26
+         * AyeCode_Connect_Helper constructor.
27
+         *
28
+         * @param array $strings
29
+         * @param array $pages
30
+         */
31
+        public function __construct( $strings = array(), $pages = array() ) {
32
+            // Only fire if not localhost and the current user has the right permissions.
33
+            if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) {
34
+                // set default strings
35
+                $default_strings = array(
36
+                    'connect_title'     => __( "Thanks for choosing an AyeCode Product!", 'ayecode-connect' ),
37
+                    'connect_external'  => __( "Please confirm you wish to connect your site?", 'ayecode-connect' ),
38
+                    'connect'           => wp_sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", 'ayecode-connect' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ),
39
+                    'connect_button'    => __( "Connect Site", 'ayecode-connect' ),
40
+                    'connecting_button' => __( "Connecting...", 'ayecode-connect' ),
41
+                    'error_localhost'   => __( "This service will only work with a live domain, not a localhost.", 'ayecode-connect' ),
42
+                    'error'             => __( "Something went wrong, please refresh and try again.", 'ayecode-connect' ),
43
+                );
44
+                $this->strings   = array_merge( $default_strings, $strings );
45
+
46
+                // set default pages
47
+                $default_pages = array();
48
+                $this->pages   = array_merge( $default_pages, $pages );
49
+
50
+                // maybe show connect site notice
51
+                add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) );
52
+
53
+                // add ajax action if not already added
54
+                if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) {
55
+                    add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) );
56
+                }
57
+            }
58
+
59
+            // add ajax action if not already added
60
+            if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) {
61
+                add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) );
62
+            }
63
+        }
64
+
65
+        /**
66
+         * Give a way to check we can connect via a external redirect.
67
+         */
68
+        public function ayecode_connect_helper_installed(){
69
+            $active = array(
70
+                'gd'    =>  defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0,
71
+                'uwp'    =>  defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0,
72
+                'wpi'    =>  defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0,
73
+            );
74
+            wp_send_json_success( $active );
75
+            wp_die();
76
+        }
77
+
78
+        /**
79
+         * Get slug from path
80
+         *
81
+         * @param  string $key
82
+         *
83
+         * @return string
84
+         */
85
+        private function format_plugin_slug( $key ) {
86
+            $slug = explode( '/', $key );
87
+            $slug = explode( '.', end( $slug ) );
88
+
89
+            return $slug[0];
90
+        }
91
+
92
+        /**
93
+         * Install and activate the AyeCode Connect Plugin
94
+         */
95
+        public function ayecode_connect_install() {
96
+            // bail if localhost
97
+            if ( $this->is_localhost() ) {
98
+                wp_send_json_error( $this->strings['error_localhost'] );
99
+            }
100
+
101
+            // Explicitly clear the event.
102
+            wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() );
103
+
104
+            $success     = true;
105
+            $plugin_slug = "ayecode-connect";
106
+            if ( ! empty( $plugin_slug ) ) {
107
+                require_once( ABSPATH . 'wp-admin/includes/file.php' );
108
+                require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
109
+                require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
110
+                require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
111
+
112
+                WP_Filesystem();
113
+
114
+                $skin              = new Automatic_Upgrader_Skin;
115
+                $upgrader          = new WP_Upgrader( $skin );
116
+                $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) );
117
+                $plugin_slug       = $plugin_slug;
118
+                $plugin            = $plugin_slug . '/' . $plugin_slug . '.php';
119
+                $installed         = false;
120
+                $activate          = false;
121
+
122
+                // See if the plugin is installed already
123
+                if ( in_array( $plugin_slug, $installed_plugins ) ) {
124
+                    $installed = true;
125
+                    $activate  = ! is_plugin_active( $plugin );
126
+                }
127
+
128
+                // Install this thing!
129
+                if ( ! $installed ) {
130
+
131
+                    // Suppress feedback
132
+                    ob_start();
133
+
134
+                    try {
135
+                        $plugin_information = plugins_api( 'plugin_information', array(
136
+                            'slug'   => $plugin_slug,
137
+                            'fields' => array(
138
+                                'short_description' => false,
139
+                                'sections'          => false,
140
+                                'requires'          => false,
141
+                                'rating'            => false,
142
+                                'ratings'           => false,
143
+                                'downloaded'        => false,
144
+                                'last_updated'      => false,
145
+                                'added'             => false,
146
+                                'tags'              => false,
147
+                                'homepage'          => false,
148
+                                'donate_link'       => false,
149
+                                'author_profile'    => false,
150
+                                'author'            => false,
151
+                            ),
152
+                        ) );
153
+
154
+                        if ( is_wp_error( $plugin_information ) ) {
155
+                            throw new Exception( $plugin_information->get_error_message() );
156
+                        }
157
+
158
+                        $package  = $plugin_information->download_link;
159
+                        $download = $upgrader->download_package( $package );
160
+
161
+                        if ( is_wp_error( $download ) ) {
162
+                            throw new Exception( $download->get_error_message() );
163
+                        }
164
+
165
+                        $working_dir = $upgrader->unpack_package( $download, true );
166
+
167
+                        if ( is_wp_error( $working_dir ) ) {
168
+                            throw new Exception( $working_dir->get_error_message() );
169
+                        }
170
+
171
+                        $result = $upgrader->install_package( array(
172
+                            'source'                      => $working_dir,
173
+                            'destination'                 => WP_PLUGIN_DIR,
174
+                            'clear_destination'           => false,
175
+                            'abort_if_destination_exists' => false,
176
+                            'clear_working'               => true,
177
+                            'hook_extra'                  => array(
178
+                                'type'   => 'plugin',
179
+                                'action' => 'install',
180
+                            ),
181
+                        ) );
182
+
183
+                        if ( is_wp_error( $result ) ) {
184
+                            throw new Exception( $result->get_error_message() );
185
+                        }
186
+
187
+                        $activate = true;
188
+
189
+                    } catch ( Exception $e ) {
190
+                        $success = false;
191
+                    }
192
+
193
+                    // Discard feedback
194
+                    ob_end_clean();
195
+                }
196
+
197
+                wp_clean_plugins_cache();
198
+
199
+                // Activate this thing
200
+                if ( $activate ) {
201
+                    try {
202
+                        $result = activate_plugin( $plugin );
203
+
204
+                        if ( is_wp_error( $result ) ) {
205
+                            $success = false;
206
+                        } else {
207
+                            $success = true;
208
+                        }
209
+                    } catch ( Exception $e ) {
210
+                        $success = false;
211
+                    }
212
+                }
213
+            }
214
+
215
+            if ( $success && function_exists( 'ayecode_connect_args' ) ) {
216
+                ayecode_connect();// init
217
+                $args        = ayecode_connect_args();
218
+                $client      = new AyeCode_Connect( $args );
219
+                $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : '';
220
+                $redirect    = $client->build_connect_url( $redirect_to );
221
+                wp_send_json_success( array( 'connect_url' => $redirect ) );
222
+            } else {
223
+                wp_send_json_error( $this->strings['error_localhost'] );
224
+            }
225
+            wp_die();
226
+        }
227
+
228
+        /**
229
+         * Check if maybe localhost.
230
+         *
231
+         * @return bool
232
+         */
233
+        public function is_localhost() {
234
+            $localhost = false;
235
+
236
+            $host              = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '';
237
+            $localhost_domains = array(
238
+                'localhost',
239
+                'localhost.localdomain',
240
+                '127.0.0.1',
241
+                '::1'
242
+            );
243
+
244
+            if ( in_array( $host, $localhost_domains ) ) {
245
+                $localhost = true;
246
+            }
247
+
248
+            return $localhost;
249
+        }
250
+
251
+        /**
252
+         * Show notice to connect site.
253
+         */
254
+        public function ayecode_connect_install_notice() {
255
+            if ( $this->maybe_show() ) {
256
+                $connect_title_string     = $this->strings['connect_title'];
257
+                $connect_external_string  = $this->strings['connect_external'];
258
+                $connect_string           = $this->strings['connect'];
259
+                $connect_button_string    = $this->strings['connect_button'];
260
+                $connecting_button_string = $this->strings['connecting_button'];
261
+                ?>
262 262
 				<div class="notice notice-info acch-notice">
263 263
 					<span class="acch-float-left">
264 264
 						<svg width="61px" height="61px" viewBox="0 0 61 61" version="1.1"
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
 				</div>
306 306
 
307 307
 				<?php
308
-				// only include the popup HTML if needed.
309
-				if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
310
-					?>
308
+                // only include the popup HTML if needed.
309
+                if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
310
+                    ?>
311 311
 					<div id="ayecode-connect-helper-external-confirm" style="display:none;">
312 312
 						<div class="noticex notice-info acch-notice" style="border: none;">
313 313
 					<span class="acch-float-left">
@@ -353,23 +353,23 @@  discard block
 block discarded – undo
353 353
 						</div>
354 354
 					</div>
355 355
 					<?php
356
-				}
357
-
358
-				// add required scripts
359
-				$this->script();
360
-			}
361
-		}
362
-
363
-		/**
364
-		 * Get the JS Script.
365
-		 */
366
-		public function script() {
367
-
368
-			// add thickbox if external request is requested
369
-			if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
370
-				add_thickbox();
371
-			}
372
-			?>
356
+                }
357
+
358
+                // add required scripts
359
+                $this->script();
360
+            }
361
+        }
362
+
363
+        /**
364
+         * Get the JS Script.
365
+         */
366
+        public function script() {
367
+
368
+            // add thickbox if external request is requested
369
+            if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
370
+                add_thickbox();
371
+            }
372
+            ?>
373 373
 			<style>
374 374
 				.acch-title {
375 375
 					margin: 0;
@@ -435,38 +435,38 @@  discard block
 block discarded – undo
435 435
 					});
436 436
 				} 
437 437
 				<?php
438
-				// add thickbox if external request is requested
439
-				if(! empty( $_REQUEST['external-connect-request'] )) {
440
-				?>
438
+                // add thickbox if external request is requested
439
+                if(! empty( $_REQUEST['external-connect-request'] )) {
440
+                ?>
441 441
 				jQuery(function () {
442 442
 					setTimeout(function () {
443 443
 						tb_show("AyeCode Connect", "?TB_inline?width=300&height=80&inlineId=ayecode-connect-helper-external-confirm");
444 444
 					}, 200);
445 445
 				});
446 446
 				<?php
447
-				}
448
-				?>
447
+                }
448
+                ?>
449 449
 			</script>
450 450
 			<?php
451
-		}
452
-
453
-		/**
454
-		 * Decide what pages to show on.
455
-		 *
456
-		 * @return bool
457
-		 */
458
-		public function maybe_show() {
459
-			$show = false;
460
-
461
-			// check if on a page set to show
462
-			if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) {
463
-				// check if not active and connected
464
-				if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) {
465
-					$show = true;
466
-				}
467
-			}
468
-
469
-			return $show;
470
-		}
471
-	}
451
+        }
452
+
453
+        /**
454
+         * Decide what pages to show on.
455
+         *
456
+         * @return bool
457
+         */
458
+        public function maybe_show() {
459
+            $show = false;
460
+
461
+            // check if on a page set to show
462
+            if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) {
463
+                // check if not active and connected
464
+                if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) {
465
+                    $show = true;
466
+                }
467
+            }
468
+
469
+            return $show;
470
+        }
471
+    }
472 472
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 1 patch
Indentation   +821 added lines, -821 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,406 +21,406 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 */
29
-	class WP_Font_Awesome_Settings {
30
-
31
-		/**
32
-		 * Class version version.
33
-		 *
34
-		 * @var string
35
-		 */
36
-		public $version = '1.1.7';
37
-
38
-		/**
39
-		 * Class textdomain.
40
-		 *
41
-		 * @var string
42
-		 */
43
-		public $textdomain = 'font-awesome-settings';
44
-
45
-		/**
46
-		 * Latest version of Font Awesome at time of publish published.
47
-		 *
48
-		 * @var string
49
-		 */
50
-		public $latest = "6.4.2";
51
-
52
-		/**
53
-		 * The title.
54
-		 *
55
-		 * @var string
56
-		 */
57
-		public $name = 'Font Awesome';
58
-
59
-		/**
60
-		 * Holds the settings values.
61
-		 *
62
-		 * @var array
63
-		 */
64
-		private $settings;
65
-
66
-		/**
67
-		 * WP_Font_Awesome_Settings instance.
68
-		 *
69
-		 * @access private
70
-		 * @since  1.0.0
71
-		 * @var    WP_Font_Awesome_Settings There can be only one!
72
-		 */
73
-		private static $instance = null;
74
-
75
-		/**
76
-		 * Main WP_Font_Awesome_Settings Instance.
77
-		 *
78
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
79
-		 *
80
-		 * @since 1.0.0
81
-		 * @static
82
-		 * @return WP_Font_Awesome_Settings - Main instance.
83
-		 */
84
-		public static function instance() {
85
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
86
-				self::$instance = new WP_Font_Awesome_Settings;
87
-
88
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
89
-
90
-				if ( is_admin() ) {
91
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
92
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
93
-					add_action( 'admin_init', array( self::$instance, 'constants' ) );
94
-					add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
95
-				}
96
-
97
-				do_action( 'wp_font_awesome_settings_loaded' );
98
-			}
99
-
100
-			return self::$instance;
101
-		}
102
-
103
-		/**
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     */
29
+    class WP_Font_Awesome_Settings {
30
+
31
+        /**
32
+         * Class version version.
33
+         *
34
+         * @var string
35
+         */
36
+        public $version = '1.1.7';
37
+
38
+        /**
39
+         * Class textdomain.
40
+         *
41
+         * @var string
42
+         */
43
+        public $textdomain = 'font-awesome-settings';
44
+
45
+        /**
46
+         * Latest version of Font Awesome at time of publish published.
47
+         *
48
+         * @var string
49
+         */
50
+        public $latest = "6.4.2";
51
+
52
+        /**
53
+         * The title.
54
+         *
55
+         * @var string
56
+         */
57
+        public $name = 'Font Awesome';
58
+
59
+        /**
60
+         * Holds the settings values.
61
+         *
62
+         * @var array
63
+         */
64
+        private $settings;
65
+
66
+        /**
67
+         * WP_Font_Awesome_Settings instance.
68
+         *
69
+         * @access private
70
+         * @since  1.0.0
71
+         * @var    WP_Font_Awesome_Settings There can be only one!
72
+         */
73
+        private static $instance = null;
74
+
75
+        /**
76
+         * Main WP_Font_Awesome_Settings Instance.
77
+         *
78
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
79
+         *
80
+         * @since 1.0.0
81
+         * @static
82
+         * @return WP_Font_Awesome_Settings - Main instance.
83
+         */
84
+        public static function instance() {
85
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
86
+                self::$instance = new WP_Font_Awesome_Settings;
87
+
88
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
89
+
90
+                if ( is_admin() ) {
91
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
92
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
93
+                    add_action( 'admin_init', array( self::$instance, 'constants' ) );
94
+                    add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
95
+                }
96
+
97
+                do_action( 'wp_font_awesome_settings_loaded' );
98
+            }
99
+
100
+            return self::$instance;
101
+        }
102
+
103
+        /**
104 104
          * Define any constants that may be needed by other packages.
105 105
          *
106
-		 * @return void
107
-		 */
108
-		public function constants(){
106
+         * @return void
107
+         */
108
+        public function constants(){
109 109
 
110
-			// register iconpicker constant
111
-			if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) {
112
-				$url = $this->get_path_url();
113
-				$version = $this->settings['version'];
110
+            // register iconpicker constant
111
+            if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) {
112
+                $url = $this->get_path_url();
113
+                $version = $this->settings['version'];
114 114
 
115
-				if( !$version || version_compare($version,'5.999','>')){
116
-					$url .= 'assets/js/fa-iconpicker-v6.min.js';
117
-				}else{
118
-					$url .= 'assets/js/fa-iconpicker-v5.min.js';
119
-				}
115
+                if( !$version || version_compare($version,'5.999','>')){
116
+                    $url .= 'assets/js/fa-iconpicker-v6.min.js';
117
+                }else{
118
+                    $url .= 'assets/js/fa-iconpicker-v5.min.js';
119
+                }
120 120
 
121
-				define( 'FAS_ICONPICKER_JS_URL', $url );
121
+                define( 'FAS_ICONPICKER_JS_URL', $url );
122 122
 
123
-			}
123
+            }
124 124
 
125 125
             // Set a constant if pro enbaled
126
-			if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) {
127
-				define( 'FAS_PRO', true );
128
-			}
129
-		}
130
-
131
-		/**
132
-		 * Get the url path to the current folder.
133
-		 *
134
-		 * @return string
135
-		 */
136
-		public function get_path_url() {
137
-			$content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
138
-			$content_url = untrailingslashit( WP_CONTENT_URL );
139
-
140
-			// Replace http:// to https://.
141
-			if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
142
-				$content_url = str_replace( 'http://', 'https://', $content_url );
143
-			}
144
-
145
-			// Check if we are inside a plugin
146
-			$file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
147
-			$url = str_replace( $content_dir, $content_url, $file_dir );
148
-
149
-			return trailingslashit( $url );
150
-		}
151
-
152
-		/**
153
-		 * Initiate the settings and add the required action hooks.
154
-		 *
155
-		 * @since 1.0.8 Settings name wrong - FIXED
156
-		 */
157
-		public function init() {
158
-			// Download fontawesome locally.
159
-			add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
160
-			add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
161
-
162
-			$this->settings = $this->get_settings();
163
-
164
-			// Check if the official plugin is active and use that instead if so.
165
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
166
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
167
-					add_action( 'admin_head', array( $this, 'add_generator' ), 99 );
168
-				}
169
-
170
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
171
-					add_action( 'wp_head', array( $this, 'add_generator' ), 99 );
172
-				}
173
-
174
-				if ( $this->settings['type'] == 'CSS' ) {
175
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
176
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
177
-						//add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend
178
-					}
179
-
180
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
181
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
182
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
183
-					}
184
-				} else {
185
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
186
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
187
-					}
188
-
189
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
190
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
191
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
192
-					}
193
-				}
194
-
195
-				// remove font awesome if set to do so
196
-				if ( $this->settings['dequeue'] == '1' ) {
197
-					add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
198
-				}
199
-			}
200
-
201
-		}
202
-
203
-		/**
204
-		 * Add FA to the FSE.
205
-		 *
206
-		 * @param $editor_settings
207
-		 * @param $block_editor_context
208
-		 *
209
-		 * @return array
210
-		 */
211
-		public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
212
-
213
-			if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
214
-				$url = $this->get_url();
215
-				$editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
216
-			}
217
-
218
-			return $editor_settings;
219
-		}
220
-
221
-		/**
222
-		 * Add FA to the FSE.
223
-		 *
224
-		 * @param $editor_settings
225
-		 * @param $block_editor_context
226
-		 *
227
-		 * @return array
228
-		 */
229
-		public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
230
-
231
-			$url = $this->get_url();
232
-			$editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
233
-
234
-			return $editor_settings;
235
-		}
236
-
237
-		/**
238
-		 * Adds the Font Awesome styles.
239
-		 */
240
-		public function enqueue_style() {
241
-			// build url
242
-			$url = $this->get_url();
243
-			$version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
244
-
245
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
246
-			wp_register_style( 'font-awesome', $url, array(), $version );
247
-			wp_enqueue_style( 'font-awesome' );
248
-
249
-			// RTL language support CSS.
250
-			if ( is_rtl() ) {
251
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
252
-			}
253
-
254
-			if ( $this->settings['shims'] ) {
255
-				$url = $this->get_url( true );
256
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
257
-				wp_register_style( 'font-awesome-shims', $url, array(), $version );
258
-				wp_enqueue_style( 'font-awesome-shims' );
259
-			}
260
-		}
261
-
262
-		/**
263
-		 * Adds the Font Awesome JS.
264
-		 */
265
-		public function enqueue_scripts() {
266
-			// build url
267
-			$url = $this->get_url();
268
-
269
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
270
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
271
-			wp_register_script( 'font-awesome', $url, array(), null );
272
-			wp_enqueue_script( 'font-awesome' );
273
-
274
-			if ( $this->settings['shims'] ) {
275
-				$url = $this->get_url( true );
276
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
277
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
278
-				wp_enqueue_script( 'font-awesome-shims' );
279
-			}
280
-		}
281
-
282
-		/**
283
-		 * Get the url of the Font Awesome files.
284
-		 *
285
-		 * @param bool $shims If this is a shim file or not.
286
-		 * @param bool $local Load locally if allowed.
287
-		 *
288
-		 * @return string The url to the file.
289
-		 */
290
-		public function get_url( $shims = false, $local = true ) {
291
-			$script  = $shims ? 'v4-shims' : 'all';
292
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
293
-			$type    = $this->settings['type'];
294
-			$version = $this->settings['version'];
295
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
296
-			$url     = '';
297
-
298
-			if ( $type == 'KIT' && $kit_url ) {
299
-				if ( $shims ) {
300
-					// if its a kit then we don't add shims here
301
-					return '';
302
-				}
303
-				$url .= $kit_url; // CDN
304
-				$url .= "?wpfas=true"; // set our var so our version is not removed
305
-			} else {
306
-				$v = '';
307
-				// Check and load locally.
308
-				if ( $local && $this->has_local() ) {
309
-					$script .= ".min";
310
-					$v .= '&ver=' . strip_tags( $this->settings['local_version'] );
311
-					$url .= $this->get_fonts_url(); // Local fonts url.
312
-				} else {
313
-					$url .= "https://$sub.fontawesome.com/releases/"; // CDN
314
-					$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
315
-				}
316
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
317
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
318
-				$url .= "?wpfas=true" . $v; // set our var so our version is not removed
319
-			}
320
-
321
-			return $url;
322
-		}
323
-
324
-		/**
325
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
326
-		 *
327
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
328
-		 *
329
-		 * @param $url
330
-		 * @param $original_url
331
-		 * @param $_context
332
-		 *
333
-		 * @return string The filtered url.
334
-		 */
335
-		public function remove_font_awesome( $url, $original_url, $_context ) {
336
-
337
-			if ( $_context == 'display'
338
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
339
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
340
-			) {// it's a font-awesome-url (probably)
341
-
342
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
343
-					if ( $this->settings['type'] == 'JS' ) {
344
-						if ( $this->settings['js-pseudo'] ) {
345
-							$url .= "' data-search-pseudo-elements defer='defer";
346
-						} else {
347
-							$url .= "' defer='defer";
348
-						}
349
-					}
350
-				} else {
351
-					$url = ''; // removing the url removes the file
352
-				}
353
-
354
-			}
355
-
356
-			return $url;
357
-		}
358
-
359
-		/**
360
-		 * Register the database settings with WordPress.
361
-		 */
362
-		public function register_settings() {
363
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
364
-		}
365
-
366
-		/**
367
-		 * Add the WordPress settings menu item.
368
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
369
-		 */
370
-		public function menu_item() {
371
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
372
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
373
-				$this,
374
-				'settings_page'
375
-			) );
376
-		}
377
-
378
-		/**
379
-		 * Get the current Font Awesome output settings.
380
-		 *
381
-		 * @return array The array of settings.
382
-		 */
383
-		public function get_settings() {
384
-			$db_settings = get_option( 'wp-font-awesome-settings' );
385
-
386
-			$defaults = array(
387
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
388
-				'version'   => '', // latest
389
-				'enqueue'   => '', // front and backend
390
-				'shims'     => '0', // default OFF now in 2020
391
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
392
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
393
-				'pro'       => '0', // if pro CDN url should be used
394
-				'local'     => '0', // Store fonts locally.
395
-				'local_version' => '', // Local fonts version.
396
-				'kit-url'   => '', // the kit url
397
-			);
398
-
399
-			$settings = wp_parse_args( $db_settings, $defaults );
400
-
401
-			/**
402
-			 * Filter the Font Awesome settings.
403
-			 *
404
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
405
-			 */
406
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
407
-		}
408
-
409
-		/**
410
-		 * The settings page html output.
411
-		 */
412
-		public function settings_page() {
413
-			if ( ! current_user_can( 'manage_options' ) ) {
414
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) );
415
-			}
416
-
417
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
418
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
419
-				$this->get_latest_version( $force_api = true );
420
-			}
421
-
422
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
423
-				?>
126
+            if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) {
127
+                define( 'FAS_PRO', true );
128
+            }
129
+        }
130
+
131
+        /**
132
+         * Get the url path to the current folder.
133
+         *
134
+         * @return string
135
+         */
136
+        public function get_path_url() {
137
+            $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
138
+            $content_url = untrailingslashit( WP_CONTENT_URL );
139
+
140
+            // Replace http:// to https://.
141
+            if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
142
+                $content_url = str_replace( 'http://', 'https://', $content_url );
143
+            }
144
+
145
+            // Check if we are inside a plugin
146
+            $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
147
+            $url = str_replace( $content_dir, $content_url, $file_dir );
148
+
149
+            return trailingslashit( $url );
150
+        }
151
+
152
+        /**
153
+         * Initiate the settings and add the required action hooks.
154
+         *
155
+         * @since 1.0.8 Settings name wrong - FIXED
156
+         */
157
+        public function init() {
158
+            // Download fontawesome locally.
159
+            add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
160
+            add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
161
+
162
+            $this->settings = $this->get_settings();
163
+
164
+            // Check if the official plugin is active and use that instead if so.
165
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
166
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
167
+                    add_action( 'admin_head', array( $this, 'add_generator' ), 99 );
168
+                }
169
+
170
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
171
+                    add_action( 'wp_head', array( $this, 'add_generator' ), 99 );
172
+                }
173
+
174
+                if ( $this->settings['type'] == 'CSS' ) {
175
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
176
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
177
+                        //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend
178
+                    }
179
+
180
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
181
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
182
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
183
+                    }
184
+                } else {
185
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
186
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
187
+                    }
188
+
189
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
190
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
191
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
192
+                    }
193
+                }
194
+
195
+                // remove font awesome if set to do so
196
+                if ( $this->settings['dequeue'] == '1' ) {
197
+                    add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
198
+                }
199
+            }
200
+
201
+        }
202
+
203
+        /**
204
+         * Add FA to the FSE.
205
+         *
206
+         * @param $editor_settings
207
+         * @param $block_editor_context
208
+         *
209
+         * @return array
210
+         */
211
+        public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
212
+
213
+            if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
214
+                $url = $this->get_url();
215
+                $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
216
+            }
217
+
218
+            return $editor_settings;
219
+        }
220
+
221
+        /**
222
+         * Add FA to the FSE.
223
+         *
224
+         * @param $editor_settings
225
+         * @param $block_editor_context
226
+         *
227
+         * @return array
228
+         */
229
+        public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
230
+
231
+            $url = $this->get_url();
232
+            $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
233
+
234
+            return $editor_settings;
235
+        }
236
+
237
+        /**
238
+         * Adds the Font Awesome styles.
239
+         */
240
+        public function enqueue_style() {
241
+            // build url
242
+            $url = $this->get_url();
243
+            $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
244
+
245
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
246
+            wp_register_style( 'font-awesome', $url, array(), $version );
247
+            wp_enqueue_style( 'font-awesome' );
248
+
249
+            // RTL language support CSS.
250
+            if ( is_rtl() ) {
251
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
252
+            }
253
+
254
+            if ( $this->settings['shims'] ) {
255
+                $url = $this->get_url( true );
256
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
257
+                wp_register_style( 'font-awesome-shims', $url, array(), $version );
258
+                wp_enqueue_style( 'font-awesome-shims' );
259
+            }
260
+        }
261
+
262
+        /**
263
+         * Adds the Font Awesome JS.
264
+         */
265
+        public function enqueue_scripts() {
266
+            // build url
267
+            $url = $this->get_url();
268
+
269
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
270
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
271
+            wp_register_script( 'font-awesome', $url, array(), null );
272
+            wp_enqueue_script( 'font-awesome' );
273
+
274
+            if ( $this->settings['shims'] ) {
275
+                $url = $this->get_url( true );
276
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
277
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
278
+                wp_enqueue_script( 'font-awesome-shims' );
279
+            }
280
+        }
281
+
282
+        /**
283
+         * Get the url of the Font Awesome files.
284
+         *
285
+         * @param bool $shims If this is a shim file or not.
286
+         * @param bool $local Load locally if allowed.
287
+         *
288
+         * @return string The url to the file.
289
+         */
290
+        public function get_url( $shims = false, $local = true ) {
291
+            $script  = $shims ? 'v4-shims' : 'all';
292
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
293
+            $type    = $this->settings['type'];
294
+            $version = $this->settings['version'];
295
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
296
+            $url     = '';
297
+
298
+            if ( $type == 'KIT' && $kit_url ) {
299
+                if ( $shims ) {
300
+                    // if its a kit then we don't add shims here
301
+                    return '';
302
+                }
303
+                $url .= $kit_url; // CDN
304
+                $url .= "?wpfas=true"; // set our var so our version is not removed
305
+            } else {
306
+                $v = '';
307
+                // Check and load locally.
308
+                if ( $local && $this->has_local() ) {
309
+                    $script .= ".min";
310
+                    $v .= '&ver=' . strip_tags( $this->settings['local_version'] );
311
+                    $url .= $this->get_fonts_url(); // Local fonts url.
312
+                } else {
313
+                    $url .= "https://$sub.fontawesome.com/releases/"; // CDN
314
+                    $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
315
+                }
316
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
317
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
318
+                $url .= "?wpfas=true" . $v; // set our var so our version is not removed
319
+            }
320
+
321
+            return $url;
322
+        }
323
+
324
+        /**
325
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
326
+         *
327
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
328
+         *
329
+         * @param $url
330
+         * @param $original_url
331
+         * @param $_context
332
+         *
333
+         * @return string The filtered url.
334
+         */
335
+        public function remove_font_awesome( $url, $original_url, $_context ) {
336
+
337
+            if ( $_context == 'display'
338
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
339
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
340
+            ) {// it's a font-awesome-url (probably)
341
+
342
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
343
+                    if ( $this->settings['type'] == 'JS' ) {
344
+                        if ( $this->settings['js-pseudo'] ) {
345
+                            $url .= "' data-search-pseudo-elements defer='defer";
346
+                        } else {
347
+                            $url .= "' defer='defer";
348
+                        }
349
+                    }
350
+                } else {
351
+                    $url = ''; // removing the url removes the file
352
+                }
353
+
354
+            }
355
+
356
+            return $url;
357
+        }
358
+
359
+        /**
360
+         * Register the database settings with WordPress.
361
+         */
362
+        public function register_settings() {
363
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
364
+        }
365
+
366
+        /**
367
+         * Add the WordPress settings menu item.
368
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
369
+         */
370
+        public function menu_item() {
371
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
372
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
373
+                $this,
374
+                'settings_page'
375
+            ) );
376
+        }
377
+
378
+        /**
379
+         * Get the current Font Awesome output settings.
380
+         *
381
+         * @return array The array of settings.
382
+         */
383
+        public function get_settings() {
384
+            $db_settings = get_option( 'wp-font-awesome-settings' );
385
+
386
+            $defaults = array(
387
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
388
+                'version'   => '', // latest
389
+                'enqueue'   => '', // front and backend
390
+                'shims'     => '0', // default OFF now in 2020
391
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
392
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
393
+                'pro'       => '0', // if pro CDN url should be used
394
+                'local'     => '0', // Store fonts locally.
395
+                'local_version' => '', // Local fonts version.
396
+                'kit-url'   => '', // the kit url
397
+            );
398
+
399
+            $settings = wp_parse_args( $db_settings, $defaults );
400
+
401
+            /**
402
+             * Filter the Font Awesome settings.
403
+             *
404
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
405
+             */
406
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
407
+        }
408
+
409
+        /**
410
+         * The settings page html output.
411
+         */
412
+        public function settings_page() {
413
+            if ( ! current_user_can( 'manage_options' ) ) {
414
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) );
415
+            }
416
+
417
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
418
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
419
+                $this->get_latest_version( $force_api = true );
420
+            }
421
+
422
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
423
+                ?>
424 424
                 <style>
425 425
                     .wpfas-kit-show {
426 426
                         display: none;
@@ -446,16 +446,16 @@  discard block
 block discarded – undo
446 446
                     <h1><?php echo $this->name; ?></h1>
447 447
                     <form method="post" action="options.php" class="fas-settings-form">
448 448
 						<?php
449
-						settings_fields( 'wp-font-awesome-settings' );
450
-						do_settings_sections( 'wp-font-awesome-settings' );
451
-						$table_class = '';
452
-						if ( $this->settings['type'] ) {
453
-							$table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
454
-						}
455
-						if ( ! empty( $this->settings['pro'] ) ) {
456
-							$table_class .= ' wpfas-has-pro';
457
-						}
458
-						?>
449
+                        settings_fields( 'wp-font-awesome-settings' );
450
+                        do_settings_sections( 'wp-font-awesome-settings' );
451
+                        $table_class = '';
452
+                        if ( $this->settings['type'] ) {
453
+                            $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
454
+                        }
455
+                        if ( ! empty( $this->settings['pro'] ) ) {
456
+                            $table_class .= ' wpfas-has-pro';
457
+                        }
458
+                        ?>
459 459
 						<?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?>
460 460
 							<?php if ( $this->has_local() ) { ?>
461 461
                                 <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div>
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
                                 <td>
481 481
                                     <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
482 482
                                     <span><?php
483
-										echo wp_sprintf(
484
-											__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ),
485
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
486
-											'</a>'
487
-										);
488
-										?></span>
483
+                                        echo wp_sprintf(
484
+                                            __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ),
485
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
486
+                                            '</a>'
487
+                                        );
488
+                                        ?></span>
489 489
                                 </td>
490 490
                             </tr>
491 491
 
@@ -526,14 +526,14 @@  discard block
 block discarded – undo
526 526
                                     <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/>
527 527
                                     <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/>
528 528
                                     <span><?php
529
-										echo wp_sprintf(
530
-											__( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'ayecode-connect' ),
531
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
532
-											' <i class="fas fa-external-link-alt"></i></a>',
533
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
534
-											' <i class="fas fa-external-link-alt"></i></a>'
535
-										);
536
-										?></span>
529
+                                        echo wp_sprintf(
530
+                                            __( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'ayecode-connect' ),
531
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
532
+                                            ' <i class="fas fa-external-link-alt"></i></a>',
533
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
534
+                                            ' <i class="fas fa-external-link-alt"></i></a>'
535
+                                        );
536
+                                        ?></span>
537 537
                                 </td>
538 538
                             </tr>
539 539
 
@@ -587,8 +587,8 @@  discard block
 block discarded – undo
587 587
                         </table>
588 588
                         <div class="fas-buttons">
589 589
 							<?php
590
-							submit_button();
591
-							?>
590
+                            submit_button();
591
+                            ?>
592 592
                             <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p>
593 593
 
594 594
                         </div>
@@ -597,414 +597,414 @@  discard block
 block discarded – undo
597 597
                     <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div>
598 598
                 </div>
599 599
 				<?php
600
-			}
601
-		}
602
-
603
-		/**
604
-		 * Check a version number is valid and if so return it or else return an empty string.
605
-		 *
606
-		 * @param $version string The version number to check.
607
-		 *
608
-		 * @since 1.0.6
609
-		 *
610
-		 * @return string Either a valid version number or an empty string.
611
-		 */
612
-		public function validate_version_number( $version ) {
613
-
614
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
615
-				// valid
616
-			} else {
617
-				$version = '';// not validated
618
-			}
619
-
620
-			return $version;
621
-		}
622
-
623
-
624
-		/**
625
-		 * Get the latest version of Font Awesome.
626
-		 *
627
-		 * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
628
-		 *
629
-		 * @since 1.0.7
630
-		 * @return mixed|string The latest version number found.
631
-		 */
632
-		public function get_latest_version( $force_api = false ) {
633
-			$latest_version = $this->latest;
634
-
635
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
636
-
637
-			if ( $cache === false || $force_api ) { // its not set
638
-				$api_ver = $this->get_latest_version_from_api();
639
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
640
-					$latest_version = $api_ver;
641
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
642
-				}
643
-			} elseif ( $this->validate_version_number( $cache ) ) {
644
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
645
-					$latest_version = $cache;
646
-				}
647
-			}
648
-
649
-			// Check and auto download fonts locally.
650
-			if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
651
-				if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
652
-					$this->download_package( $latest_version );
653
-				}
654
-			}
655
-
656
-			return $latest_version;
657
-		}
658
-
659
-		/**
660
-		 * Get the latest Font Awesome version from the github API.
661
-		 *
662
-		 * @since 1.0.7
663
-		 * @return string The latest version number or `0` on API fail.
664
-		 */
665
-		public function get_latest_version_from_api() {
666
-			$version  = "0";
667
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
668
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
669
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
670
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
671
-					$version = $api_response['tag_name'];
672
-				}
673
-			}
674
-
675
-			return $version;
676
-		}
677
-
678
-		/**
679
-		 * Inline CSS for RTL language support.
680
-		 *
681
-		 * @since 1.0.13
682
-		 * @return string Inline CSS.
683
-		 */
684
-		public function rtl_inline_css() {
685
-			$inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
686
-
687
-			return $inline_css;
688
-		}
689
-
690
-		/**
691
-		 * Show any warnings as an admin notice.
692
-		 *
693
-		 * @return void
694
-		 */
695
-		public function admin_notices() {
696
-			$settings = $this->settings;
697
-
698
-			if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
699
-				if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
700
-					?>
600
+            }
601
+        }
602
+
603
+        /**
604
+         * Check a version number is valid and if so return it or else return an empty string.
605
+         *
606
+         * @param $version string The version number to check.
607
+         *
608
+         * @since 1.0.6
609
+         *
610
+         * @return string Either a valid version number or an empty string.
611
+         */
612
+        public function validate_version_number( $version ) {
613
+
614
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
615
+                // valid
616
+            } else {
617
+                $version = '';// not validated
618
+            }
619
+
620
+            return $version;
621
+        }
622
+
623
+
624
+        /**
625
+         * Get the latest version of Font Awesome.
626
+         *
627
+         * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
628
+         *
629
+         * @since 1.0.7
630
+         * @return mixed|string The latest version number found.
631
+         */
632
+        public function get_latest_version( $force_api = false ) {
633
+            $latest_version = $this->latest;
634
+
635
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
636
+
637
+            if ( $cache === false || $force_api ) { // its not set
638
+                $api_ver = $this->get_latest_version_from_api();
639
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
640
+                    $latest_version = $api_ver;
641
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
642
+                }
643
+            } elseif ( $this->validate_version_number( $cache ) ) {
644
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
645
+                    $latest_version = $cache;
646
+                }
647
+            }
648
+
649
+            // Check and auto download fonts locally.
650
+            if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
651
+                if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
652
+                    $this->download_package( $latest_version );
653
+                }
654
+            }
655
+
656
+            return $latest_version;
657
+        }
658
+
659
+        /**
660
+         * Get the latest Font Awesome version from the github API.
661
+         *
662
+         * @since 1.0.7
663
+         * @return string The latest version number or `0` on API fail.
664
+         */
665
+        public function get_latest_version_from_api() {
666
+            $version  = "0";
667
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
668
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
669
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
670
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
671
+                    $version = $api_response['tag_name'];
672
+                }
673
+            }
674
+
675
+            return $version;
676
+        }
677
+
678
+        /**
679
+         * Inline CSS for RTL language support.
680
+         *
681
+         * @since 1.0.13
682
+         * @return string Inline CSS.
683
+         */
684
+        public function rtl_inline_css() {
685
+            $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
686
+
687
+            return $inline_css;
688
+        }
689
+
690
+        /**
691
+         * Show any warnings as an admin notice.
692
+         *
693
+         * @return void
694
+         */
695
+        public function admin_notices() {
696
+            $settings = $this->settings;
697
+
698
+            if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
699
+                if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
700
+                    ?>
701 701
                     <div class="notice  notice-error is-dismissible">
702 702
                         <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p>
703 703
                     </div>
704 704
 					<?php
705
-				}
706
-			} else {
707
-				if ( ! empty( $settings ) ) {
708
-					if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
709
-						$link = admin_url('options-general.php?page=wp-font-awesome-settings');
710
-						?>
705
+                }
706
+            } else {
707
+                if ( ! empty( $settings ) ) {
708
+                    if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
709
+                        $link = admin_url('options-general.php?page=wp-font-awesome-settings');
710
+                        ?>
711 711
                         <div class="notice  notice-error is-dismissible">
712 712
                             <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p>
713 713
                         </div>
714 714
 						<?php
715
-					}
716
-				}
717
-			}
718
-		}
719
-
720
-		/**
721
-		 * Handle fontawesome add settings to download fontawesome to store locally.
722
-		 *
723
-		 * @since 1.1.1
724
-		 *
725
-		 * @param string $option The option name.
726
-		 * @param mixed  $value  The option value.
727
-		 */
728
-		public function add_option_wp_font_awesome_settings( $option, $value ) {
729
-			// Do nothing if WordPress is being installed.
730
-			if ( wp_installing() ) {
731
-				return;
732
-			}
733
-
734
-			if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
735
-				$version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
736
-
737
-				if ( ! empty( $version ) ) {
738
-					$response = $this->download_package( $version, $value );
739
-
740
-					if ( is_wp_error( $response ) ) {
741
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
742
-					}
743
-				}
744
-			}
745
-		}
746
-
747
-		/**
748
-		 * Handle fontawesome update settings to download fontawesome to store locally.
749
-		 *
750
-		 * @since 1.1.0
751
-		 *
752
-		 * @param mixed $old_value The old option value.
753
-		 * @param mixed $value     The new option value.
754
-		 */
755
-		public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
756
-			// Do nothing if WordPress is being installed.
757
-			if ( wp_installing() ) {
758
-				return;
759
-			}
760
-
761
-			if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
762
-				// Old values
763
-				$old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
764
-				$old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
765
-
766
-				// New values
767
-				$new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
768
-
769
-				if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
-					$response = $this->download_package( $new_version, $new_value );
771
-
772
-					if ( is_wp_error( $response ) ) {
773
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
774
-					}
775
-				}
776
-			}
777
-		}
778
-
779
-		/**
780
-		 * Get the fonts directory local path.
781
-		 *
782
-		 * @since 1.1.0
783
-		 *
784
-		 * @param string Fonts directory local path.
785
-		 */
786
-		public function get_fonts_dir() {
787
-			$upload_dir = wp_upload_dir( null, false );
788
-
789
-			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
790
-		}
791
-
792
-		/**
793
-		 * Get the fonts directory local url.
794
-		 *
795
-		 * @since 1.1.0
796
-		 *
797
-		 * @param string Fonts directory local url.
798
-		 */
799
-		public function get_fonts_url() {
800
-			$upload_dir = wp_upload_dir( null, false );
801
-
802
-			return $upload_dir['baseurl'] .  '/ayefonts/fa/';
803
-		}
804
-
805
-		/**
806
-		 * Check whether load locally active.
807
-		 *
808
-		 * @since 1.1.0
809
-		 *
810
-		 * @return bool True if active else false.
811
-		 */
812
-		public function has_local() {
813
-			if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
814
-				return true;
815
-			}
816
-
817
-			return false;
818
-		}
819
-
820
-		/**
821
-		 * Get the WP Filesystem access.
822
-		 *
823
-		 * @since 1.1.0
824
-		 *
825
-		 * @return object The WP Filesystem.
826
-		 */
827
-		public function get_wp_filesystem() {
828
-			if ( ! function_exists( 'get_filesystem_method' ) ) {
829
-				require_once( ABSPATH . "/wp-admin/includes/file.php" );
830
-			}
831
-
832
-			$access_type = get_filesystem_method();
833
-
834
-			if ( $access_type === 'direct' ) {
835
-				/* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
836
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
837
-
838
-				/* Initialize the API */
839
-				if ( ! WP_Filesystem( $creds ) ) {
840
-					/* Any problems and we exit */
841
-					return false;
842
-				}
843
-
844
-				global $wp_filesystem;
845
-
846
-				return $wp_filesystem;
847
-				/* Do our file manipulations below */
848
-			} else if ( defined( 'FTP_USER' ) ) {
849
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
850
-
851
-				/* Initialize the API */
852
-				if ( ! WP_Filesystem( $creds ) ) {
853
-					/* Any problems and we exit */
854
-					return false;
855
-				}
856
-
857
-				global $wp_filesystem;
858
-
859
-				return $wp_filesystem;
860
-			} else {
861
-				/* Don't have direct write access. Prompt user with our notice */
862
-				return false;
863
-			}
864
-		}
865
-
866
-		/**
867
-		 * Download the fontawesome package file.
868
-		 *
869
-		 * @since 1.1.0
870
-		 *
871
-		 * @param mixed $version The font awesome.
872
-		 * @param array $option Fontawesome settings.
873
-		 * @return WP_ERROR|bool Error on fail and true on success.
874
-		 */
875
-		public function download_package( $version, $option = array() ) {
876
-			$filename = 'fontawesome-free-' . $version . '-web';
877
-			$url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
878
-
879
-			if ( ! function_exists( 'wp_handle_upload' ) ) {
880
-				require_once ABSPATH . 'wp-admin/includes/file.php';
881
-			}
882
-
883
-			$download_file = download_url( esc_url_raw( $url ) );
884
-
885
-			if ( is_wp_error( $download_file ) ) {
886
-				return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) );
887
-			} else if ( empty( $download_file ) ) {
888
-				return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) );
889
-			}
890
-
891
-			$response = $this->extract_package( $download_file, $filename, true );
892
-
893
-			// Update local version.
894
-			if ( is_wp_error( $response ) ) {
895
-				return $response;
896
-			} else if ( $response ) {
897
-				if ( empty( $option ) ) {
898
-					$option = get_option( 'wp-font-awesome-settings' );
899
-				}
900
-
901
-				$option['local_version'] = $version;
902
-
903
-				// Remove action to prevent looping.
904
-				remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
905
-
906
-				update_option( 'wp-font-awesome-settings', $option );
907
-
908
-				return true;
909
-			}
910
-
911
-			return false;
912
-		}
913
-
914
-		/**
915
-		 * Extract the fontawesome package file.
916
-		 *
917
-		 * @since 1.1.0
918
-		 *
919
-		 * @param string $package The package file path.
920
-		 * @param string $dirname Package file name.
921
-		 * @param bool   $delete_package Delete temp file or not.
922
-		 * @return WP_Error|bool True on success WP_Error on fail.
923
-		 */
924
-		public function extract_package( $package, $dirname = '', $delete_package = false ) {
925
-			global $wp_filesystem;
926
-
927
-			$wp_filesystem = $this->get_wp_filesystem();
928
-
929
-			if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
930
-				return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) );
931
-			} else if ( empty( $wp_filesystem ) ) {
932
-				return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) );
933
-			}
934
-
935
-			$fonts_dir = $this->get_fonts_dir();
936
-			$fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
937
-
938
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
939
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
940
-			}
941
-
942
-			// Unzip package to working directory.
943
-			$result = unzip_file( $package, $fonts_tmp_dir );
944
-
945
-			if ( is_wp_error( $result ) ) {
946
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
947
-
948
-				if ( 'incompatible_archive' === $result->get_error_code() ) {
949
-					return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) );
950
-				}
951
-
952
-				return $result;
953
-			}
954
-
955
-			if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
956
-				$wp_filesystem->delete( $fonts_dir, true );
957
-			}
958
-
959
-			$extract_dir = $fonts_tmp_dir;
960
-
961
-			if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
962
-				$extract_dir .= $dirname . DIRECTORY_SEPARATOR;
963
-			}
964
-
965
-			try {
966
-				$return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
967
-			} catch ( Exception $e ) {
968
-				$return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) );
969
-			}
970
-
971
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
972
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
973
-			}
974
-
975
-			// Once extracted, delete the package if required.
976
-			if ( $delete_package ) {
977
-				unlink( $package );
978
-			}
979
-
980
-			return $return;
981
-		}
982
-
983
-		/**
984
-		 * Output the version in the header.
985
-		 */
986
-		public function add_generator() {
987
-			$file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
988
-			$plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
989
-
990
-			// Find source plugin/theme.
991
-			$source = array();
992
-			if ( strpos( $file, $plugins_dir ) !== false ) {
993
-				$source = explode( "/", plugin_basename( $file ) );
994
-			} else if ( function_exists( 'get_theme_root' ) ) {
995
-				$themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
996
-
997
-				if ( strpos( $file, $themes_dir ) !== false ) {
998
-					$source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
999
-				}
1000
-			}
1001
-
1002
-			echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />';
1003
-		}
1004
-	}
1005
-
1006
-	/**
1007
-	 * Run the class if found.
1008
-	 */
1009
-	WP_Font_Awesome_Settings::instance();
715
+                    }
716
+                }
717
+            }
718
+        }
719
+
720
+        /**
721
+         * Handle fontawesome add settings to download fontawesome to store locally.
722
+         *
723
+         * @since 1.1.1
724
+         *
725
+         * @param string $option The option name.
726
+         * @param mixed  $value  The option value.
727
+         */
728
+        public function add_option_wp_font_awesome_settings( $option, $value ) {
729
+            // Do nothing if WordPress is being installed.
730
+            if ( wp_installing() ) {
731
+                return;
732
+            }
733
+
734
+            if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
735
+                $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
736
+
737
+                if ( ! empty( $version ) ) {
738
+                    $response = $this->download_package( $version, $value );
739
+
740
+                    if ( is_wp_error( $response ) ) {
741
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
742
+                    }
743
+                }
744
+            }
745
+        }
746
+
747
+        /**
748
+         * Handle fontawesome update settings to download fontawesome to store locally.
749
+         *
750
+         * @since 1.1.0
751
+         *
752
+         * @param mixed $old_value The old option value.
753
+         * @param mixed $value     The new option value.
754
+         */
755
+        public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
756
+            // Do nothing if WordPress is being installed.
757
+            if ( wp_installing() ) {
758
+                return;
759
+            }
760
+
761
+            if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
762
+                // Old values
763
+                $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
764
+                $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
765
+
766
+                // New values
767
+                $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
768
+
769
+                if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
+                    $response = $this->download_package( $new_version, $new_value );
771
+
772
+                    if ( is_wp_error( $response ) ) {
773
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
774
+                    }
775
+                }
776
+            }
777
+        }
778
+
779
+        /**
780
+         * Get the fonts directory local path.
781
+         *
782
+         * @since 1.1.0
783
+         *
784
+         * @param string Fonts directory local path.
785
+         */
786
+        public function get_fonts_dir() {
787
+            $upload_dir = wp_upload_dir( null, false );
788
+
789
+            return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
790
+        }
791
+
792
+        /**
793
+         * Get the fonts directory local url.
794
+         *
795
+         * @since 1.1.0
796
+         *
797
+         * @param string Fonts directory local url.
798
+         */
799
+        public function get_fonts_url() {
800
+            $upload_dir = wp_upload_dir( null, false );
801
+
802
+            return $upload_dir['baseurl'] .  '/ayefonts/fa/';
803
+        }
804
+
805
+        /**
806
+         * Check whether load locally active.
807
+         *
808
+         * @since 1.1.0
809
+         *
810
+         * @return bool True if active else false.
811
+         */
812
+        public function has_local() {
813
+            if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
814
+                return true;
815
+            }
816
+
817
+            return false;
818
+        }
819
+
820
+        /**
821
+         * Get the WP Filesystem access.
822
+         *
823
+         * @since 1.1.0
824
+         *
825
+         * @return object The WP Filesystem.
826
+         */
827
+        public function get_wp_filesystem() {
828
+            if ( ! function_exists( 'get_filesystem_method' ) ) {
829
+                require_once( ABSPATH . "/wp-admin/includes/file.php" );
830
+            }
831
+
832
+            $access_type = get_filesystem_method();
833
+
834
+            if ( $access_type === 'direct' ) {
835
+                /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
836
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
837
+
838
+                /* Initialize the API */
839
+                if ( ! WP_Filesystem( $creds ) ) {
840
+                    /* Any problems and we exit */
841
+                    return false;
842
+                }
843
+
844
+                global $wp_filesystem;
845
+
846
+                return $wp_filesystem;
847
+                /* Do our file manipulations below */
848
+            } else if ( defined( 'FTP_USER' ) ) {
849
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
850
+
851
+                /* Initialize the API */
852
+                if ( ! WP_Filesystem( $creds ) ) {
853
+                    /* Any problems and we exit */
854
+                    return false;
855
+                }
856
+
857
+                global $wp_filesystem;
858
+
859
+                return $wp_filesystem;
860
+            } else {
861
+                /* Don't have direct write access. Prompt user with our notice */
862
+                return false;
863
+            }
864
+        }
865
+
866
+        /**
867
+         * Download the fontawesome package file.
868
+         *
869
+         * @since 1.1.0
870
+         *
871
+         * @param mixed $version The font awesome.
872
+         * @param array $option Fontawesome settings.
873
+         * @return WP_ERROR|bool Error on fail and true on success.
874
+         */
875
+        public function download_package( $version, $option = array() ) {
876
+            $filename = 'fontawesome-free-' . $version . '-web';
877
+            $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
878
+
879
+            if ( ! function_exists( 'wp_handle_upload' ) ) {
880
+                require_once ABSPATH . 'wp-admin/includes/file.php';
881
+            }
882
+
883
+            $download_file = download_url( esc_url_raw( $url ) );
884
+
885
+            if ( is_wp_error( $download_file ) ) {
886
+                return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) );
887
+            } else if ( empty( $download_file ) ) {
888
+                return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) );
889
+            }
890
+
891
+            $response = $this->extract_package( $download_file, $filename, true );
892
+
893
+            // Update local version.
894
+            if ( is_wp_error( $response ) ) {
895
+                return $response;
896
+            } else if ( $response ) {
897
+                if ( empty( $option ) ) {
898
+                    $option = get_option( 'wp-font-awesome-settings' );
899
+                }
900
+
901
+                $option['local_version'] = $version;
902
+
903
+                // Remove action to prevent looping.
904
+                remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
905
+
906
+                update_option( 'wp-font-awesome-settings', $option );
907
+
908
+                return true;
909
+            }
910
+
911
+            return false;
912
+        }
913
+
914
+        /**
915
+         * Extract the fontawesome package file.
916
+         *
917
+         * @since 1.1.0
918
+         *
919
+         * @param string $package The package file path.
920
+         * @param string $dirname Package file name.
921
+         * @param bool   $delete_package Delete temp file or not.
922
+         * @return WP_Error|bool True on success WP_Error on fail.
923
+         */
924
+        public function extract_package( $package, $dirname = '', $delete_package = false ) {
925
+            global $wp_filesystem;
926
+
927
+            $wp_filesystem = $this->get_wp_filesystem();
928
+
929
+            if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
930
+                return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) );
931
+            } else if ( empty( $wp_filesystem ) ) {
932
+                return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) );
933
+            }
934
+
935
+            $fonts_dir = $this->get_fonts_dir();
936
+            $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
937
+
938
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
939
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
940
+            }
941
+
942
+            // Unzip package to working directory.
943
+            $result = unzip_file( $package, $fonts_tmp_dir );
944
+
945
+            if ( is_wp_error( $result ) ) {
946
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
947
+
948
+                if ( 'incompatible_archive' === $result->get_error_code() ) {
949
+                    return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) );
950
+                }
951
+
952
+                return $result;
953
+            }
954
+
955
+            if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
956
+                $wp_filesystem->delete( $fonts_dir, true );
957
+            }
958
+
959
+            $extract_dir = $fonts_tmp_dir;
960
+
961
+            if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
962
+                $extract_dir .= $dirname . DIRECTORY_SEPARATOR;
963
+            }
964
+
965
+            try {
966
+                $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
967
+            } catch ( Exception $e ) {
968
+                $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) );
969
+            }
970
+
971
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
972
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
973
+            }
974
+
975
+            // Once extracted, delete the package if required.
976
+            if ( $delete_package ) {
977
+                unlink( $package );
978
+            }
979
+
980
+            return $return;
981
+        }
982
+
983
+        /**
984
+         * Output the version in the header.
985
+         */
986
+        public function add_generator() {
987
+            $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
988
+            $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
989
+
990
+            // Find source plugin/theme.
991
+            $source = array();
992
+            if ( strpos( $file, $plugins_dir ) !== false ) {
993
+                $source = explode( "/", plugin_basename( $file ) );
994
+            } else if ( function_exists( 'get_theme_root' ) ) {
995
+                $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
996
+
997
+                if ( strpos( $file, $themes_dir ) !== false ) {
998
+                    $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
999
+                }
1000
+            }
1001
+
1002
+            echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />';
1003
+        }
1004
+    }
1005
+
1006
+    /**
1007
+     * Run the class if found.
1008
+     */
1009
+    WP_Font_Awesome_Settings::instance();
1010 1010
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-deactivation-survey/wp-deactivation-survey.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -1,99 +1,99 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit;
4
+    exit;
5 5
 }
6 6
 
7 7
 if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) {
8 8
 
9
-	class AyeCode_Deactivation_Survey {
9
+    class AyeCode_Deactivation_Survey {
10 10
 
11
-		/**
12
-		 * AyeCode_Deactivation_Survey instance.
13
-		 *
14
-		 * @access private
15
-		 * @since  1.0.0
16
-		 * @var    AyeCode_Deactivation_Survey There can be only one!
17
-		 */
18
-		private static $instance = null;
11
+        /**
12
+         * AyeCode_Deactivation_Survey instance.
13
+         *
14
+         * @access private
15
+         * @since  1.0.0
16
+         * @var    AyeCode_Deactivation_Survey There can be only one!
17
+         */
18
+        private static $instance = null;
19 19
 
20
-		public static $plugins;
20
+        public static $plugins;
21 21
 
22
-		public $version = "1.0.7";
22
+        public $version = "1.0.7";
23 23
 
24
-		public static function instance( $plugin = array() ) {
25
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) {
26
-				self::$instance = new AyeCode_Deactivation_Survey;
27
-				self::$plugins = array();
24
+        public static function instance( $plugin = array() ) {
25
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) {
26
+                self::$instance = new AyeCode_Deactivation_Survey;
27
+                self::$plugins = array();
28 28
 
29
-				add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) );
29
+                add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) );
30 30
 
31
-				do_action( 'ayecode_deactivation_survey_loaded' );
32
-			}
31
+                do_action( 'ayecode_deactivation_survey_loaded' );
32
+            }
33 33
 
34
-			if(!empty($plugin)){
35
-				self::$plugins[] = (object)$plugin;
36
-			}
34
+            if(!empty($plugin)){
35
+                self::$plugins[] = (object)$plugin;
36
+            }
37 37
 
38
-			return self::$instance;
39
-		}
38
+            return self::$instance;
39
+        }
40 40
 
41
-		public function scripts() {
42
-			global $pagenow;
41
+        public function scripts() {
42
+            global $pagenow;
43 43
 
44
-			// Bail if we are not on the plugins page
45
-			if ( $pagenow != "plugins.php" ) {
46
-				return;
47
-			}
44
+            // Bail if we are not on the plugins page
45
+            if ( $pagenow != "plugins.php" ) {
46
+                return;
47
+            }
48 48
 
49
-			// Enqueue scripts
50
-			add_thickbox();
51
-			wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js');
49
+            // Enqueue scripts
50
+            add_thickbox();
51
+            wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js');
52 52
 
53
-			/*
53
+            /*
54 54
 			 * Localized strings. Strings can be localised by plugins using this class.
55 55
 			 * We deliberately don't add textdomains here so that double textdomain warning is not given in theme review.
56 56
 			 */
57
-			wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array(
58
-				'quick_feedback'			=> __( 'Quick Feedback', 'ayecode-connect' ),
59
-				'foreword'					=> __( 'If you would be kind enough, please tell us why you\'re deactivating?', 'ayecode-connect' ),
60
-				'better_plugins_name'		=> __( 'Please tell us which plugin?', 'ayecode-connect' ),
61
-				'please_tell_us'			=> __( 'Please tell us the reason so we can improve the plugin', 'ayecode-connect' ),
62
-				'do_not_attach_email'		=> __( 'Do not send my e-mail address with this feedback', 'ayecode-connect' ),
63
-				'brief_description'			=> __( 'Please give us any feedback that could help us improve', 'ayecode-connect' ),
64
-				'cancel'					=> __( 'Cancel', 'ayecode-connect' ),
65
-				'skip_and_deactivate'		=> __( 'Skip &amp; Deactivate', 'ayecode-connect' ),
66
-				'submit_and_deactivate'		=> __( 'Submit &amp; Deactivate', 'ayecode-connect' ),
67
-				'please_wait'				=> __( 'Please wait', 'ayecode-connect' ),
68
-				'get_support'				=> __( 'Get Support', 'ayecode-connect' ),
69
-				'documentation'				=> __( 'Documentation', 'ayecode-connect' ),
70
-				'thank_you'					=> __( 'Thank you!', 'ayecode-connect' ),
71
-			));
72
-
73
-			// Plugins
74
-			$plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins);
75
-
76
-			// Reasons
77
-			$defaultReasons = array(
78
-				'suddenly-stopped-working'	=> __( 'The plugin suddenly stopped working', 'ayecode-connect' ),
79
-				'plugin-broke-site'			=> __( 'The plugin broke my site', 'ayecode-connect' ),
80
-				'plugin-setup-difficult'	=> __( 'Too difficult to setup', 'ayecode-connect' ),
81
-				'plugin-design-difficult'	=> __( 'Too difficult to get the design i want', 'ayecode-connect' ),
82
-				'no-longer-needed'			=> __( 'I don\'t need this plugin any more', 'ayecode-connect' ),
83
-				'found-better-plugin'		=> __( 'I found a better plugin', 'ayecode-connect' ),
84
-				'temporary-deactivation'	=> __( 'It\'s a temporary deactivation, I\'m troubleshooting', 'ayecode-connect' ),
85
-				'other'						=> __( 'Other', 'ayecode-connect' ),
86
-			);
87
-
88
-			foreach( $plugins as $plugin ) {
89
-				$plugin->reasons = apply_filters( 'ayecode_deactivation_survey_reasons', $defaultReasons, $plugin );
90
-				$plugin->url = home_url();
91
-				$plugin->activated = 0;
92
-			}
93
-
94
-			// Send plugin data
95
-			wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins);
96
-		}
97
-	}
57
+            wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array(
58
+                'quick_feedback'			=> __( 'Quick Feedback', 'ayecode-connect' ),
59
+                'foreword'					=> __( 'If you would be kind enough, please tell us why you\'re deactivating?', 'ayecode-connect' ),
60
+                'better_plugins_name'		=> __( 'Please tell us which plugin?', 'ayecode-connect' ),
61
+                'please_tell_us'			=> __( 'Please tell us the reason so we can improve the plugin', 'ayecode-connect' ),
62
+                'do_not_attach_email'		=> __( 'Do not send my e-mail address with this feedback', 'ayecode-connect' ),
63
+                'brief_description'			=> __( 'Please give us any feedback that could help us improve', 'ayecode-connect' ),
64
+                'cancel'					=> __( 'Cancel', 'ayecode-connect' ),
65
+                'skip_and_deactivate'		=> __( 'Skip &amp; Deactivate', 'ayecode-connect' ),
66
+                'submit_and_deactivate'		=> __( 'Submit &amp; Deactivate', 'ayecode-connect' ),
67
+                'please_wait'				=> __( 'Please wait', 'ayecode-connect' ),
68
+                'get_support'				=> __( 'Get Support', 'ayecode-connect' ),
69
+                'documentation'				=> __( 'Documentation', 'ayecode-connect' ),
70
+                'thank_you'					=> __( 'Thank you!', 'ayecode-connect' ),
71
+            ));
72
+
73
+            // Plugins
74
+            $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins);
75
+
76
+            // Reasons
77
+            $defaultReasons = array(
78
+                'suddenly-stopped-working'	=> __( 'The plugin suddenly stopped working', 'ayecode-connect' ),
79
+                'plugin-broke-site'			=> __( 'The plugin broke my site', 'ayecode-connect' ),
80
+                'plugin-setup-difficult'	=> __( 'Too difficult to setup', 'ayecode-connect' ),
81
+                'plugin-design-difficult'	=> __( 'Too difficult to get the design i want', 'ayecode-connect' ),
82
+                'no-longer-needed'			=> __( 'I don\'t need this plugin any more', 'ayecode-connect' ),
83
+                'found-better-plugin'		=> __( 'I found a better plugin', 'ayecode-connect' ),
84
+                'temporary-deactivation'	=> __( 'It\'s a temporary deactivation, I\'m troubleshooting', 'ayecode-connect' ),
85
+                'other'						=> __( 'Other', 'ayecode-connect' ),
86
+            );
87
+
88
+            foreach( $plugins as $plugin ) {
89
+                $plugin->reasons = apply_filters( 'ayecode_deactivation_survey_reasons', $defaultReasons, $plugin );
90
+                $plugin->url = home_url();
91
+                $plugin->activated = 0;
92
+            }
93
+
94
+            // Send plugin data
95
+            wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins);
96
+        }
97
+    }
98 98
 
99 99
 }
100 100
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/map.php 1 patch
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -3,241 +3,241 @@
 block discarded – undo
3 3
 class SD_Map extends WP_Super_Duper {
4 4
 
5 5
 
6
-	public $arguments;
7
-
8
-	/**
9
-	 * Sets up the widgets name etc
10
-	 */
11
-	public function __construct() {
12
-
13
-		$options = array(
14
-			'textdomain'     => 'super-duper',
15
-			// textdomain of the plugin/theme (used to prefix the Gutenberg block)
16
-			'block-icon'     => 'admin-site',
17
-			// Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right
18
-			'block-category' => 'widgets',
19
-			// the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'.
20
-			'block-keywords' => "['map','super','google']",
21
-			// used in the block search, MAX 3
22
-			'block-output'   => array( // the block visual output elements as an array
23
-				array(
24
-					'element' => 'p',
25
-					'content' => __('A Google API key is required to use this block, we recommend installing our plugin which makes it easy and sets it globally, or you can set a key in the block settings sidebar: ', 'ayecode-connect' ),
26
-					//'element_require' => '"1"=='.get_option( 'rgmk_google_map_api_key', '"0"') ? '"0"' : '"1"',
27
-					'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1 && [%api_key%]==""',
28
-				),
29
-				array(
30
-					'element' => 'a',
31
-					'content' => __('API KEY for Google Maps', 'ayecode-connect' ),
32
-					'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1 && [%api_key%]==""',
33
-					'href' => 'https://wordpress.org/plugins/api-key-for-google-maps/',
34
-				),
35
-				array(
36
-					'element' => 'img',
37
-					'class'   => '[%className%]',
38
-					//'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%]
39
-					'element_require' => '[%type%]=="image"',
40
-					'src'     => get_option( 'rgmk_google_map_api_key', false) ? "https://maps.googleapis.com/maps/api/staticmap?center=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&size=[%static_width%]x[%static_height%]&key=".get_option( 'rgmk_google_map_api_key') : "https://maps.googleapis.com/maps/api/staticmap?center=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&size=[%static_width%]x[%static_height%]&key=[%api_key%]"
41
-				),
42
-				array(
43
-					'element' => 'div',
44
-					'class'   => 'sd-map-iframe-cover',
45
-					'style'   => '{overflow:"hidden", position:"relative"}',
46
-					array(
47
-						'element' => 'iframe',
48
-						'title'   => __( 'Placeholderx', 'ayecode-connect' ),
49
-						'class'   => '[%className%]',
50
-						'width'   => '[%width%]',
51
-						'height'  => '[%height%]',
52
-						'frameborder' => '0',
53
-						'allowfullscreen' => 'true',
54
-						'style' => '{border:0}',
55
-						'element_require' => '[%type%]!="image"',
56
-						'src'     => get_option( 'rgmk_google_map_api_key', false) ? "https://www.google.com/maps/embed/v1/[%type%]?q=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&key=".get_option( 'rgmk_google_map_api_key') : "https://www.google.com/maps/embed/v1/[%type%]?q=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&key=[%api_key%]"
57
-					),
58
-				),
59
-				array(
60
-					'element' => 'style',
61
-					'content' => '.sd-map-iframe-cover:hover:before {background: #4a4a4a88; content: "'.__( 'Click here, Settings are in the block settings sidebar', 'ayecode-connect' ).'";} .sd-map-iframe-cover:before{cursor: pointer; content: ""; width: 100%; height: 100%; position: absolute; top: 0; bottom: 0;padding-top: 33%; text-align: center;  color: #fff; font-size: 20px; font-weight: bold;}',
62
-					'element_require' => '[%type%]!="image"',
63
-				),
64
-			),
65
-			'class_name'     => __CLASS__,
66
-			// The calling class name
67
-			'base_id'        => 'sd_map',
68
-			// this is used as the widget id and the shortcode id.
69
-			'name'           => __( 'Map', 'ayecode-connect' ),
70
-			// the name of the widget/block
71
-			'widget_ops'     => array(
72
-				'classname'   => 'sd-map-class',
73
-				// widget class
74
-				'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ),
75
-				// widget description
76
-			),
77
-			'arguments'      => array( // these are the arguments that will be used in the widget, shortcode and block settings.
78
-				'type'  => array(
79
-					'title' => __('Map Type:', 'ayecode-connect'),
80
-					'desc' => __('Select the map type to use.', 'ayecode-connect'),
81
-					'type' => 'select',
82
-					'options'   =>  array(
83
-						"image" => __('Static Image', 'ayecode-connect'),
84
-						"place" => __('Place', 'ayecode-connect'),
6
+    public $arguments;
7
+
8
+    /**
9
+     * Sets up the widgets name etc
10
+     */
11
+    public function __construct() {
12
+
13
+        $options = array(
14
+            'textdomain'     => 'super-duper',
15
+            // textdomain of the plugin/theme (used to prefix the Gutenberg block)
16
+            'block-icon'     => 'admin-site',
17
+            // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right
18
+            'block-category' => 'widgets',
19
+            // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'.
20
+            'block-keywords' => "['map','super','google']",
21
+            // used in the block search, MAX 3
22
+            'block-output'   => array( // the block visual output elements as an array
23
+                array(
24
+                    'element' => 'p',
25
+                    'content' => __('A Google API key is required to use this block, we recommend installing our plugin which makes it easy and sets it globally, or you can set a key in the block settings sidebar: ', 'ayecode-connect' ),
26
+                    //'element_require' => '"1"=='.get_option( 'rgmk_google_map_api_key', '"0"') ? '"0"' : '"1"',
27
+                    'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1 && [%api_key%]==""',
28
+                ),
29
+                array(
30
+                    'element' => 'a',
31
+                    'content' => __('API KEY for Google Maps', 'ayecode-connect' ),
32
+                    'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1 && [%api_key%]==""',
33
+                    'href' => 'https://wordpress.org/plugins/api-key-for-google-maps/',
34
+                ),
35
+                array(
36
+                    'element' => 'img',
37
+                    'class'   => '[%className%]',
38
+                    //'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%]
39
+                    'element_require' => '[%type%]=="image"',
40
+                    'src'     => get_option( 'rgmk_google_map_api_key', false) ? "https://maps.googleapis.com/maps/api/staticmap?center=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&size=[%static_width%]x[%static_height%]&key=".get_option( 'rgmk_google_map_api_key') : "https://maps.googleapis.com/maps/api/staticmap?center=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&size=[%static_width%]x[%static_height%]&key=[%api_key%]"
41
+                ),
42
+                array(
43
+                    'element' => 'div',
44
+                    'class'   => 'sd-map-iframe-cover',
45
+                    'style'   => '{overflow:"hidden", position:"relative"}',
46
+                    array(
47
+                        'element' => 'iframe',
48
+                        'title'   => __( 'Placeholderx', 'ayecode-connect' ),
49
+                        'class'   => '[%className%]',
50
+                        'width'   => '[%width%]',
51
+                        'height'  => '[%height%]',
52
+                        'frameborder' => '0',
53
+                        'allowfullscreen' => 'true',
54
+                        'style' => '{border:0}',
55
+                        'element_require' => '[%type%]!="image"',
56
+                        'src'     => get_option( 'rgmk_google_map_api_key', false) ? "https://www.google.com/maps/embed/v1/[%type%]?q=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&key=".get_option( 'rgmk_google_map_api_key') : "https://www.google.com/maps/embed/v1/[%type%]?q=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&key=[%api_key%]"
57
+                    ),
58
+                ),
59
+                array(
60
+                    'element' => 'style',
61
+                    'content' => '.sd-map-iframe-cover:hover:before {background: #4a4a4a88; content: "'.__( 'Click here, Settings are in the block settings sidebar', 'ayecode-connect' ).'";} .sd-map-iframe-cover:before{cursor: pointer; content: ""; width: 100%; height: 100%; position: absolute; top: 0; bottom: 0;padding-top: 33%; text-align: center;  color: #fff; font-size: 20px; font-weight: bold;}',
62
+                    'element_require' => '[%type%]!="image"',
63
+                ),
64
+            ),
65
+            'class_name'     => __CLASS__,
66
+            // The calling class name
67
+            'base_id'        => 'sd_map',
68
+            // this is used as the widget id and the shortcode id.
69
+            'name'           => __( 'Map', 'ayecode-connect' ),
70
+            // the name of the widget/block
71
+            'widget_ops'     => array(
72
+                'classname'   => 'sd-map-class',
73
+                // widget class
74
+                'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ),
75
+                // widget description
76
+            ),
77
+            'arguments'      => array( // these are the arguments that will be used in the widget, shortcode and block settings.
78
+                'type'  => array(
79
+                    'title' => __('Map Type:', 'ayecode-connect'),
80
+                    'desc' => __('Select the map type to use.', 'ayecode-connect'),
81
+                    'type' => 'select',
82
+                    'options'   =>  array(
83
+                        "image" => __('Static Image', 'ayecode-connect'),
84
+                        "place" => __('Place', 'ayecode-connect'),
85 85
 //						"directions" => __('Directions', 'ayecode-connect'),
86 86
 //						"search" => __('Search', 'ayecode-connect'),
87 87
 //						"view" => __('View', 'ayecode-connect'),
88 88
 //						"streetview" => __('Streetview', 'ayecode-connect'),
89
-					),
90
-					'default'  => 'image',
91
-					'desc_tip' => true,
92
-					'advanced' => false
93
-				),
94
-				'location'            => array(
95
-					'type'        => 'text',
96
-					'title'       => __( 'Location:', 'ayecode-connect' ),
97
-					'desc'        => __( 'Enter the location to show on the map, place, city, zip code or GPS.', 'ayecode-connect' ),
98
-					'placeholder' => 'Place, city, zip code or GPS',
99
-					'desc_tip'    => true,
100
-					'default'     => 'Ireland',
101
-					'advanced'    => false
102
-				),
103
-				'static_width'            => array(
104
-					'type'        => 'number',
105
-					'title'       => __( 'Width:', 'ayecode-connect' ),
106
-					'desc'        => __( 'This is the width of the map, for static maps you can only use px values.', 'ayecode-connect' ),
107
-					'placeholder' => '600',
108
-					'desc_tip'    => true,
109
-					'default'     => '600',
110
-					'custom_attributes' => array(
111
-						'max'         => '2000',
112
-						'min'         => '100',
113
-					),
114
-					'element_require' => '[%type%]=="image"',
115
-					'advanced'    => false
116
-				),
117
-				'static_height'           => array(
118
-					'type'        => 'number',
119
-					'title'       => __( 'Height:', 'ayecode-connect' ),
120
-					'desc'        => __( 'This is the height of the map, for static maps you can only use px values.', 'ayecode-connect' ),
121
-					'placeholder' => '400',
122
-					'desc_tip'    => true,
123
-					'default'     => '400',
124
-					'custom_attributes' => array(
125
-						'max'         => '2000',
126
-						'min'         => '100',
127
-						'required'         => 'required',
128
-					),
129
-					'element_require' => '[%type%]=="image"',
130
-					'advanced'    => false
131
-				),
132
-				'width'            => array(
133
-					'type'        => 'text',
134
-					'title'       => __( 'Width:', 'ayecode-connect' ),
135
-					'desc'        => __( 'This is the width of the map, you can use % or px here.', 'ayecode-connect' ),
136
-					'placeholder' => '100%',
137
-					'desc_tip'    => true,
138
-					'default'     => '100%',
139
-					'element_require' => '[%type%]!="image"',
140
-					'advanced'    => false
141
-				),
142
-				'height'           => array(
143
-					'type'        => 'text',
144
-					'title'       => __( 'Height:', 'ayecode-connect' ),
145
-					'desc'        => __( 'This is the height of the map, you can use %, px or vh here.', 'ayecode-connect' ),
146
-					'placeholder' => '425px',
147
-					'desc_tip'    => true,
148
-					'default'     => '425px',
149
-					'element_require' => '[%type%]!="image"',
150
-					'advanced'    => false
151
-				),
152
-				'maptype'          => array(
153
-					'type'     => 'select',
154
-					'title'    => __( 'Mapview:', 'ayecode-connect' ),
155
-					'desc'     => __( 'This is the type of map view that will be used by default.', 'ayecode-connect' ),
156
-					'options'  => array(
157
-						"roadmap"   => __( 'Road Map', 'ayecode-connect' ),
158
-						"satellite" => __( 'Satellite Map', 'ayecode-connect' ),
89
+                    ),
90
+                    'default'  => 'image',
91
+                    'desc_tip' => true,
92
+                    'advanced' => false
93
+                ),
94
+                'location'            => array(
95
+                    'type'        => 'text',
96
+                    'title'       => __( 'Location:', 'ayecode-connect' ),
97
+                    'desc'        => __( 'Enter the location to show on the map, place, city, zip code or GPS.', 'ayecode-connect' ),
98
+                    'placeholder' => 'Place, city, zip code or GPS',
99
+                    'desc_tip'    => true,
100
+                    'default'     => 'Ireland',
101
+                    'advanced'    => false
102
+                ),
103
+                'static_width'            => array(
104
+                    'type'        => 'number',
105
+                    'title'       => __( 'Width:', 'ayecode-connect' ),
106
+                    'desc'        => __( 'This is the width of the map, for static maps you can only use px values.', 'ayecode-connect' ),
107
+                    'placeholder' => '600',
108
+                    'desc_tip'    => true,
109
+                    'default'     => '600',
110
+                    'custom_attributes' => array(
111
+                        'max'         => '2000',
112
+                        'min'         => '100',
113
+                    ),
114
+                    'element_require' => '[%type%]=="image"',
115
+                    'advanced'    => false
116
+                ),
117
+                'static_height'           => array(
118
+                    'type'        => 'number',
119
+                    'title'       => __( 'Height:', 'ayecode-connect' ),
120
+                    'desc'        => __( 'This is the height of the map, for static maps you can only use px values.', 'ayecode-connect' ),
121
+                    'placeholder' => '400',
122
+                    'desc_tip'    => true,
123
+                    'default'     => '400',
124
+                    'custom_attributes' => array(
125
+                        'max'         => '2000',
126
+                        'min'         => '100',
127
+                        'required'         => 'required',
128
+                    ),
129
+                    'element_require' => '[%type%]=="image"',
130
+                    'advanced'    => false
131
+                ),
132
+                'width'            => array(
133
+                    'type'        => 'text',
134
+                    'title'       => __( 'Width:', 'ayecode-connect' ),
135
+                    'desc'        => __( 'This is the width of the map, you can use % or px here.', 'ayecode-connect' ),
136
+                    'placeholder' => '100%',
137
+                    'desc_tip'    => true,
138
+                    'default'     => '100%',
139
+                    'element_require' => '[%type%]!="image"',
140
+                    'advanced'    => false
141
+                ),
142
+                'height'           => array(
143
+                    'type'        => 'text',
144
+                    'title'       => __( 'Height:', 'ayecode-connect' ),
145
+                    'desc'        => __( 'This is the height of the map, you can use %, px or vh here.', 'ayecode-connect' ),
146
+                    'placeholder' => '425px',
147
+                    'desc_tip'    => true,
148
+                    'default'     => '425px',
149
+                    'element_require' => '[%type%]!="image"',
150
+                    'advanced'    => false
151
+                ),
152
+                'maptype'          => array(
153
+                    'type'     => 'select',
154
+                    'title'    => __( 'Mapview:', 'ayecode-connect' ),
155
+                    'desc'     => __( 'This is the type of map view that will be used by default.', 'ayecode-connect' ),
156
+                    'options'  => array(
157
+                        "roadmap"   => __( 'Road Map', 'ayecode-connect' ),
158
+                        "satellite" => __( 'Satellite Map', 'ayecode-connect' ),
159 159
 //						"hybrid"    => __( 'Hybrid Map', 'ayecode-connect' ),
160 160
 //						"terrain"   => __( 'Terrain Map', 'ayecode-connect' ),
161
-					),
162
-					'desc_tip' => true,
163
-					'default'  => 'roadmap',
164
-					'advanced' => true
165
-				),
166
-				'zoom'             => array(
167
-					'type'        => 'select',
168
-					'title'       => __( 'Zoom level:', 'ayecode-connect' ),
169
-					'desc'        => __( 'This is the zoom level of the map, `auto` is recommended.', 'ayecode-connect' ),
170
-					'options'     => range( 1, 19 ),
171
-					'placeholder' => '',
172
-					'desc_tip'    => true,
173
-					'default'     => '7',
174
-					'advanced'    => true
175
-				),
176
-				'api_key'           => array(
177
-					'type'        => 'text',
178
-					'title'       => __( 'Api Key:', 'ayecode-connect' ),
179
-					'desc'        => __( 'This is the height of the map, you can use %, px or vh here.', 'ayecode-connect' ),
180
-					'placeholder' => '',
181
-					'desc_tip'    => true,
182
-					'default'     => '',
183
-					'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1',
184
-					'advanced'    => false
185
-				),
186
-			)
187
-		);
188
-
189
-		parent::__construct( $options );
190
-	}
191
-
192
-
193
-	/**
194
-	 * This is the output function for the widget, shortcode and block (front end).
195
-	 *
196
-	 * @param array $args The arguments values.
197
-	 * @param array $widget_args The widget arguments when used.
198
-	 * @param string $content The shortcode content argument
199
-	 *
200
-	 * @return string
201
-	 */
202
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
203
-
204
-		// options
205
-		$defaults = array(
206
-			'type'      => 'image', // image, place
207
-			'location' => 'Ireland',
208
-			'static_width' => '600',
209
-			'static_height' => '400',
210
-			'width'=> '100%',
211
-			'height'=> '425px',
212
-			'maptype'     => 'roadmap',
213
-			'zoom'     => '7',
214
-			'api_key'     => 'AIzaSyBK3ZcmK0ljxl5agNyJNQh_G24Thq1btuE',
215
-		);
216
-
217
-		/**
218
-		 * Parse incoming $args into an array and merge it with $defaults
219
-		 */
220
-		$args = wp_parse_args($args, $defaults );
221
-
222
-		$output = '';
223
-
224
-
225
-		// check if we have a global API key
226
-		$args['api_key'] = get_option( 'rgmk_google_map_api_key', false ) ? get_option( 'rgmk_google_map_api_key' ) : $args['api_key'];
227
-
228
-		if($args['type']=='image'){
229
-			$output .= "<img src='https://maps.googleapis.com/maps/api/staticmap?center=".esc_attr($args['location'])."&maptype=".esc_attr($args['maptype'])."&zoom=".esc_attr($args['zoom'])."&size=".esc_attr($args['static_width'])."x".esc_attr($args['static_height'])."&key=".esc_attr($args['api_key'])."' />";
230
-		}else{
231
-			$output .= "<iframe width='".esc_attr($args['width'])."' height='".esc_attr($args['height'])."' frameborder='0' allowfullscreen style='border:0;' src='https://www.google.com/maps/embed/v1/".esc_attr($args['type'])."?q=".esc_attr($args['location'])."&maptype=".esc_attr($args['maptype'])."&zoom=".esc_attr($args['zoom'])."&key=".esc_attr($args['api_key'])."' ></iframe> ";
232
-		}
233
-
234
-		return $output;
235
-
236
-	}
161
+                    ),
162
+                    'desc_tip' => true,
163
+                    'default'  => 'roadmap',
164
+                    'advanced' => true
165
+                ),
166
+                'zoom'             => array(
167
+                    'type'        => 'select',
168
+                    'title'       => __( 'Zoom level:', 'ayecode-connect' ),
169
+                    'desc'        => __( 'This is the zoom level of the map, `auto` is recommended.', 'ayecode-connect' ),
170
+                    'options'     => range( 1, 19 ),
171
+                    'placeholder' => '',
172
+                    'desc_tip'    => true,
173
+                    'default'     => '7',
174
+                    'advanced'    => true
175
+                ),
176
+                'api_key'           => array(
177
+                    'type'        => 'text',
178
+                    'title'       => __( 'Api Key:', 'ayecode-connect' ),
179
+                    'desc'        => __( 'This is the height of the map, you can use %, px or vh here.', 'ayecode-connect' ),
180
+                    'placeholder' => '',
181
+                    'desc_tip'    => true,
182
+                    'default'     => '',
183
+                    'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1',
184
+                    'advanced'    => false
185
+                ),
186
+            )
187
+        );
188
+
189
+        parent::__construct( $options );
190
+    }
191
+
192
+
193
+    /**
194
+     * This is the output function for the widget, shortcode and block (front end).
195
+     *
196
+     * @param array $args The arguments values.
197
+     * @param array $widget_args The widget arguments when used.
198
+     * @param string $content The shortcode content argument
199
+     *
200
+     * @return string
201
+     */
202
+    public function output( $args = array(), $widget_args = array(), $content = '' ) {
203
+
204
+        // options
205
+        $defaults = array(
206
+            'type'      => 'image', // image, place
207
+            'location' => 'Ireland',
208
+            'static_width' => '600',
209
+            'static_height' => '400',
210
+            'width'=> '100%',
211
+            'height'=> '425px',
212
+            'maptype'     => 'roadmap',
213
+            'zoom'     => '7',
214
+            'api_key'     => 'AIzaSyBK3ZcmK0ljxl5agNyJNQh_G24Thq1btuE',
215
+        );
216
+
217
+        /**
218
+         * Parse incoming $args into an array and merge it with $defaults
219
+         */
220
+        $args = wp_parse_args($args, $defaults );
221
+
222
+        $output = '';
223
+
224
+
225
+        // check if we have a global API key
226
+        $args['api_key'] = get_option( 'rgmk_google_map_api_key', false ) ? get_option( 'rgmk_google_map_api_key' ) : $args['api_key'];
227
+
228
+        if($args['type']=='image'){
229
+            $output .= "<img src='https://maps.googleapis.com/maps/api/staticmap?center=".esc_attr($args['location'])."&maptype=".esc_attr($args['maptype'])."&zoom=".esc_attr($args['zoom'])."&size=".esc_attr($args['static_width'])."x".esc_attr($args['static_height'])."&key=".esc_attr($args['api_key'])."' />";
230
+        }else{
231
+            $output .= "<iframe width='".esc_attr($args['width'])."' height='".esc_attr($args['height'])."' frameborder='0' allowfullscreen style='border:0;' src='https://www.google.com/maps/embed/v1/".esc_attr($args['type'])."?q=".esc_attr($args['location'])."&maptype=".esc_attr($args['maptype'])."&zoom=".esc_attr($args['zoom'])."&key=".esc_attr($args['api_key'])."' ></iframe> ";
232
+        }
233
+
234
+        return $output;
235
+
236
+    }
237 237
 
238 238
 }
239 239
 
240 240
 // register it.
241 241
 add_action( 'widgets_init', function () {
242
-	register_widget( 'SD_Map' );
242
+    register_widget( 'SD_Map' );
243 243
 } );
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -12,185 +12,185 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items    = $this->get_submission_items();
40
-		$invoice  = $this->get_submission_invoice();
41
-		$invoice  = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items    = $this->get_submission_items();
40
+        $invoice  = $this->get_submission_invoice();
41
+        $invoice  = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
133 125
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
138 131
 
139
-		return $invoice;
140
-	}
132
+        $invoice = $submission->get_invoice();
141 133
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
150 138
 
151
-		$submission = $this->payment_form_submission;
139
+        return $invoice;
140
+    }
152 141
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_submission_id( $submission->id );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_submission_id( $submission->id );
157
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158 158
         $invoice->set_items( $items );
159 159
         $invoice->set_fees( $submission->get_fees() );
160 160
         $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
163
-		$invoice->set_currency( $submission->get_currency() );
161
+        $invoice->set_discounts( $submission->get_discounts() );
162
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
163
+        $invoice->set_currency( $submission->get_currency() );
164 164
 
165
-		if ( $submission->has_shipping() ) {
166
-			$invoice->set_shipping( $submission->get_shipping() );
167
-		}
165
+        if ( $submission->has_shipping() ) {
166
+            $invoice->set_shipping( $submission->get_shipping() );
167
+        }
168 168
 
169
-		$address_confirmed = $submission->get_field( 'confirm-address' );
170
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
169
+        $address_confirmed = $submission->get_field( 'confirm-address' );
170
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
171 171
 
172
-		if ( $submission->has_discount_code() ) {
172
+        if ( $submission->has_discount_code() ) {
173 173
             $invoice->set_discount_code( $submission->get_discount_code() );
174
-		}
175
-
176
-		getpaid_maybe_add_default_address( $invoice );
177
-		return $invoice;
178
-	}
179
-
180
-	/**
181
-	 * Retrieves the submission's customer.
182
-	 *
183
-	 * @return int The customer id.
184
-	 */
185
-	protected function get_submission_customer() {
186
-		$submission = $this->payment_form_submission;
187
-
188
-		// If this is an existing invoice...
189
-		if ( $submission->has_invoice() ) {
190
-			return $submission->get_invoice()->get_user_id();
191
-		}
192
-
193
-		// (Maybe) create the user.
174
+        }
175
+
176
+        getpaid_maybe_add_default_address( $invoice );
177
+        return $invoice;
178
+    }
179
+
180
+    /**
181
+     * Retrieves the submission's customer.
182
+     *
183
+     * @return int The customer id.
184
+     */
185
+    protected function get_submission_customer() {
186
+        $submission = $this->payment_form_submission;
187
+
188
+        // If this is an existing invoice...
189
+        if ( $submission->has_invoice() ) {
190
+            return $submission->get_invoice()->get_user_id();
191
+        }
192
+
193
+        // (Maybe) create the user.
194 194
         $user = get_current_user_id();
195 195
 
196 196
         if ( empty( $user ) ) {
@@ -198,16 +198,16 @@  discard block
 block discarded – undo
198 198
         }
199 199
 
200 200
         if ( empty( $user ) ) {
201
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
202
-			$name = implode( '', array_filter( $name ) );
201
+            $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
202
+            $name = implode( '', array_filter( $name ) );
203 203
             $user = wpinv_create_user( $submission->get_billing_email(), $name );
204 204
 
205
-			// (Maybe) send new user notification.
206
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
207
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
208
-				wp_send_new_user_notifications( $user, 'user' );
209
-			}
210
-		}
205
+            // (Maybe) send new user notification.
206
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
207
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
208
+                wp_send_new_user_notifications( $user, 'user' );
209
+            }
210
+        }
211 211
 
212 212
         if ( is_wp_error( $user ) ) {
213 213
             wp_send_json_error( $user->get_error_message() );
@@ -215,49 +215,49 @@  discard block
 block discarded – undo
215 215
 
216 216
         if ( is_numeric( $user ) ) {
217 217
             return $user;
218
-		}
218
+        }
219 219
 
220
-		return $user->ID;
220
+        return $user->ID;
221 221
 
222
-	}
222
+    }
223 223
 
224
-	/**
224
+    /**
225 225
      * Prepares submission data for saving to the database.
226 226
      *
227
-	 * @return array
227
+     * @return array
228 228
      */
229 229
     public function prepare_submission_data_for_saving() {
230 230
 
231
-		$submission = $this->payment_form_submission;
231
+        $submission = $this->payment_form_submission;
232 232
 
233
-		// Prepared submission details.
233
+        // Prepared submission details.
234 234
         $prepared = array(
235
-			'all'  => array(),
236
-			'meta' => array(),
237
-		);
235
+            'all'  => array(),
236
+            'meta' => array(),
237
+        );
238 238
 
239 239
         // Raw submission details.
240
-		$data     = $submission->get_data();
240
+        $data     = $submission->get_data();
241 241
 
242
-		// Loop through the submitted details.
242
+        // Loop through the submitted details.
243 243
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
244 244
 
245
-			// Skip premade fields.
245
+            // Skip premade fields.
246 246
             if ( ! empty( $field['premade'] ) ) {
247 247
                 continue;
248 248
             }
249 249
 
250
-			// Ensure address is provided.
251
-			if ( 'address' === $field['type'] ) {
250
+            // Ensure address is provided.
251
+            if ( 'address' === $field['type'] ) {
252 252
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
253 253
 
254
-				foreach ( $field['fields'] as $address_field ) {
254
+                foreach ( $field['fields'] as $address_field ) {
255 255
 
256
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
257
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
258
-					}
259
-			}
260
-		}
256
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
257
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
258
+                    }
259
+            }
260
+        }
261 261
 
262 262
             // If it is required and not set, abort.
263 263
             if ( ! $submission->is_required_field_set( $field ) ) {
@@ -267,31 +267,31 @@  discard block
 block discarded – undo
267 267
             // Handle misc fields.
268 268
             if ( isset( $data[ $field['id'] ] ) ) {
269 269
 
270
-				// Uploads.
271
-				if ( 'file_upload' === $field['type'] ) {
272
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+                // Uploads.
271
+                if ( 'file_upload' === $field['type'] ) {
272
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
273 273
 
274
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
276
-					}
274
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
276
+                    }
277 277
 
278
-					$value = array();
278
+                    $value = array();
279 279
 
280
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
281
-						$value[] = sprintf(
282
-							'<a href="%s" target="_blank">%s</a>',
283
-							esc_url_raw( $url ),
284
-							esc_html( $name )
285
-						);
286
-					}
280
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
281
+                        $value[] = sprintf(
282
+                            '<a href="%s" target="_blank">%s</a>',
283
+                            esc_url_raw( $url ),
284
+                            esc_html( $name )
285
+                        );
286
+                    }
287 287
 
288
-					$value = implode( ' | ', $value );
288
+                    $value = implode( ' | ', $value );
289 289
 
290
-				} elseif ( 'checkbox' === $field['type'] ) {
291
-					$value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
292
-				} else {
293
-					$value = wp_kses_post( $data[ $field['id'] ] );
294
-				}
290
+                } elseif ( 'checkbox' === $field['type'] ) {
291
+                    $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
292
+                } else {
293
+                    $value = wp_kses_post( $data[ $field['id'] ] );
294
+                }
295 295
 
296 296
                 $label = $field['id'];
297 297
 
@@ -299,192 +299,192 @@  discard block
 block discarded – undo
299 299
                     $label = $field['label'];
300 300
                 }
301 301
 
302
-				if ( ! empty( $field['add_meta'] ) ) {
303
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
-				}
305
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
302
+                if ( ! empty( $field['add_meta'] ) ) {
303
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
+                }
305
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
306 306
 
307 307
             }
308
-		}
308
+        }
309 309
 
310
-		return $prepared;
310
+        return $prepared;
311 311
 
312
-	}
312
+    }
313 313
 
314
-	/**
314
+    /**
315 315
      * Retrieves address details.
316 316
      *
317
-	 * @return array
318
-	 * @param WPInv_Invoice $invoice
319
-	 * @param string $type
317
+     * @return array
318
+     * @param WPInv_Invoice $invoice
319
+     * @param string $type
320 320
      */
321 321
     public function prepare_address_details( $invoice, $type = 'billing' ) {
322 322
 
323
-		$data     = $this->payment_form_submission->get_data();
324
-		$type     = sanitize_key( $type );
325
-		$address  = array();
326
-		$prepared = array();
323
+        $data     = $this->payment_form_submission->get_data();
324
+        $type     = sanitize_key( $type );
325
+        $address  = array();
326
+        $prepared = array();
327 327
 
328
-		if ( ! empty( $data[ $type ] ) ) {
329
-			$address = $data[ $type ];
330
-		}
328
+        if ( ! empty( $data[ $type ] ) ) {
329
+            $address = $data[ $type ];
330
+        }
331 331
 
332
-		// Clean address details.
333
-		foreach ( $address as $key => $value ) {
334
-			$key             = sanitize_key( $key );
335
-			$key             = str_replace( 'wpinv_', '', $key );
336
-			$value           = wpinv_clean( $value );
337
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
338
-		}
332
+        // Clean address details.
333
+        foreach ( $address as $key => $value ) {
334
+            $key             = sanitize_key( $key );
335
+            $key             = str_replace( 'wpinv_', '', $key );
336
+            $value           = wpinv_clean( $value );
337
+            $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
338
+        }
339 339
 
340
-		// Filter address details.
341
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
340
+        // Filter address details.
341
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
342 342
 
343
-		// Remove non-whitelisted values.
344
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
343
+        // Remove non-whitelisted values.
344
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
345 345
 
346
-	}
346
+    }
347 347
 
348
-	/**
348
+    /**
349 349
      * Prepares the billing details.
350 350
      *
351
-	 * @return array
352
-	 * @param WPInv_Invoice $invoice
351
+     * @return array
352
+     * @param WPInv_Invoice $invoice
353 353
      */
354 354
     protected function prepare_billing_info( &$invoice ) {
355 355
 
356
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
356
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
357 357
 
358
-		// Update the invoice with the billing details.
359
-		$invoice->set_props( $billing_address );
358
+        // Update the invoice with the billing details.
359
+        $invoice->set_props( $billing_address );
360 360
 
361
-	}
361
+    }
362 362
 
363
-	/**
363
+    /**
364 364
      * Prepares the shipping details.
365 365
      *
366
-	 * @return array
367
-	 * @param WPInv_Invoice $invoice
366
+     * @return array
367
+     * @param WPInv_Invoice $invoice
368 368
      */
369 369
     protected function prepare_shipping_info( $invoice ) {
370 370
 
371
-		$data = $this->payment_form_submission->get_data();
371
+        $data = $this->payment_form_submission->get_data();
372 372
 
373
-		if ( empty( $data['same-shipping-address'] ) ) {
374
-			return $this->prepare_address_details( $invoice, 'shipping' );
375
-		}
373
+        if ( empty( $data['same-shipping-address'] ) ) {
374
+            return $this->prepare_address_details( $invoice, 'shipping' );
375
+        }
376 376
 
377
-		return $this->prepare_address_details( $invoice, 'billing' );
377
+        return $this->prepare_address_details( $invoice, 'billing' );
378 378
 
379
-	}
379
+    }
380 380
 
381
-	/**
382
-	 * Confirms the submission is valid and send users to the gateway.
383
-	 *
384
-	 * @param WPInv_Invoice $invoice
385
-	 * @param array $prepared_payment_form_data
386
-	 * @param array $shipping
387
-	 */
388
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
381
+    /**
382
+     * Confirms the submission is valid and send users to the gateway.
383
+     *
384
+     * @param WPInv_Invoice $invoice
385
+     * @param array $prepared_payment_form_data
386
+     * @param array $shipping
387
+     */
388
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
389 389
 
390
-		// Ensure the invoice exists.
390
+        // Ensure the invoice exists.
391 391
         if ( ! $invoice->exists() ) {
392 392
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
393 393
         }
394 394
 
395
-		// Save payment form data.
396
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
395
+        // Save payment form data.
396
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
397 397
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
398
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
399
-		if ( ! empty( $prepared_payment_form_data ) ) {
398
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
399
+        if ( ! empty( $prepared_payment_form_data ) ) {
400 400
 
401
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
402
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
403
-			}
401
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
402
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
403
+            }
404 404
 
405
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
406
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
407
-			}
408
-		}
405
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
406
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
407
+            }
408
+        }
409 409
 
410
-		// Save payment form data.
411
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
410
+        // Save payment form data.
411
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
412 412
         if ( ! empty( $shipping ) ) {
413 413
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
414
-		}
414
+        }
415 415
 
416
-		// Backwards compatibility.
416
+        // Backwards compatibility.
417 417
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
418 418
 
419
-		try {
420
-			$this->process_payment( $invoice );
421
-		} catch ( Exception $e ) {
422
-			wpinv_set_error( 'payment_error', $e->getMessage() );
423
-		}
419
+        try {
420
+            $this->process_payment( $invoice );
421
+        } catch ( Exception $e ) {
422
+            wpinv_set_error( 'payment_error', $e->getMessage() );
423
+        }
424 424
 
425 425
         // If we are here, there was an error.
426
-		wpinv_send_back_to_checkout( $invoice );
426
+        wpinv_send_back_to_checkout( $invoice );
427 427
 
428
-	}
428
+    }
429 429
 
430
-	/**
431
-	 * Processes the actual payment.
432
-	 *
433
-	 * @param WPInv_Invoice $invoice
434
-	 */
435
-	protected function process_payment( $invoice ) {
430
+    /**
431
+     * Processes the actual payment.
432
+     *
433
+     * @param WPInv_Invoice $invoice
434
+     */
435
+    protected function process_payment( $invoice ) {
436 436
 
437
-		// Clear any checkout errors.
438
-		wpinv_clear_errors();
437
+        // Clear any checkout errors.
438
+        wpinv_clear_errors();
439 439
 
440
-		// No need to send free invoices to the gateway.
441
-		if ( $invoice->is_free() ) {
442
-			$this->process_free_payment( $invoice );
443
-		}
440
+        // No need to send free invoices to the gateway.
441
+        if ( $invoice->is_free() ) {
442
+            $this->process_free_payment( $invoice );
443
+        }
444 444
 
445
-		$submission = $this->payment_form_submission;
445
+        $submission = $this->payment_form_submission;
446 446
 
447
-		// Fires before sending to the gateway.
448
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
447
+        // Fires before sending to the gateway.
448
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
449 449
 
450
-		// Allow the sumission data to be modified before it is sent to the gateway.
451
-		$submission_data    = $submission->get_data();
452
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
453
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
450
+        // Allow the sumission data to be modified before it is sent to the gateway.
451
+        $submission_data    = $submission->get_data();
452
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
453
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
454 454
 
455
-		// Validate the currency.
456
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
457
-			wpinv_set_error( 'invalid_currency' );
458
-		}
455
+        // Validate the currency.
456
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
457
+            wpinv_set_error( 'invalid_currency' );
458
+        }
459 459
 
460
-		// Check to see if we have any errors.
461
-		if ( wpinv_get_errors() ) {
462
-			wpinv_send_back_to_checkout( $invoice );
463
-		}
460
+        // Check to see if we have any errors.
461
+        if ( wpinv_get_errors() ) {
462
+            wpinv_send_back_to_checkout( $invoice );
463
+        }
464 464
 
465
-		// Send info to the gateway for payment processing
466
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
465
+        // Send info to the gateway for payment processing
466
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
467 467
 
468
-		// Backwards compatibility.
469
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
468
+        // Backwards compatibility.
469
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
470 470
 
471
-	}
471
+    }
472 472
 
473
-	/**
474
-	 * Marks the invoice as paid in case the checkout is free.
475
-	 *
476
-	 * @param WPInv_Invoice $invoice
477
-	 */
478
-	protected function process_free_payment( $invoice ) {
473
+    /**
474
+     * Marks the invoice as paid in case the checkout is free.
475
+     *
476
+     * @param WPInv_Invoice $invoice
477
+     */
478
+    protected function process_free_payment( $invoice ) {
479 479
 
480
-		$invoice->set_gateway( 'none' );
481
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
482
-		$invoice->mark_paid();
483
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
480
+        $invoice->set_gateway( 'none' );
481
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
482
+        $invoice->mark_paid();
483
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
484 484
 
485
-	}
485
+    }
486 486
 
487
-	/**
487
+    /**
488 488
      * Sends a redrect response to payment details.
489 489
      *
490 490
      */
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-date-based-controller.php 1 patch
Indentation   +491 added lines, -491 removed lines patch added patch discarded remove patch
@@ -16,496 +16,496 @@
 block discarded – undo
16 16
  */
17 17
 class GetPaid_REST_Date_Based_Controller extends GetPaid_REST_Controller {
18 18
 
19
-	/**
20
-	 * Group response items by day or month.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	public $groupby = 'day';
25
-
26
-	/**
27
-	 * Returns an array with arguments to request the previous report.
28
-	 *
29
-	 * @var array
30
-	 */
31
-	public $previous_range = array();
32
-
33
-	/**
34
-	 * The period interval.
35
-	 *
36
-	 * @var int
37
-	 */
38
-	public $interval;
39
-
40
-	/**
41
-	 * Retrieves the before and after dates.
42
-	 *
43
-	 * @param WP_REST_Request $request Request object.
44
-	 * @return array The appropriate date range.
45
-	 */
46
-	public function get_date_range( $request ) {
47
-
48
-		// Check if the period is x_days.
49
-		if ( preg_match( '/^(\d+)_days$/', $request['period'], $matches ) ) {
50
-			$date_range = $this->get_x_days_date_range( absint( $matches[1] ) );
51
-		} elseif ( is_callable( array( $this, 'get_' . $request['period'] . '_date_range' ) ) ) {
52
-			$date_range = call_user_func( array( $this, 'get_' . $request['period'] . '_date_range' ), $request );
53
-		} else {
54
-			$request['period'] = '7_days';
55
-			$date_range        = $this->get_x_days_date_range();
56
-		}
57
-
58
-		// 3 months max for day view.
59
-		$before = strtotime( $date_range['before'] );
60
-		$after  = strtotime( $date_range['after'] );
61
-		if ( floor( ( $before - $after ) / MONTH_IN_SECONDS ) > 2 ) {
62
-			$this->groupby = 'month';
63
-		}
64
-
65
-		$this->prepare_interval( $date_range );
66
-
67
-		return $date_range;
68
-
69
-	}
70
-
71
-	/**
72
-	 * Groups by month or days.
73
-	 *
74
-	 * @param array $range Date range.
75
-	 * @return array The appropriate date range.
76
-	 */
77
-	public function prepare_interval( $range ) {
78
-
79
-		$before = strtotime( $range['before'] );
80
-		$after  = strtotime( $range['after'] );
81
-		if ( 'day' === $this->groupby ) {
82
-			$difference     = max( DAY_IN_SECONDS, ( DAY_IN_SECONDS + $before - $after ) ); // Prevent division by 0;
83
-			$this->interval = absint( ceil( max( 1, $difference / DAY_IN_SECONDS ) ) );
84
-			return;
85
-		}
86
-
87
-		$this->interval = 0;
88
-		$min_date       = strtotime( gmdate( 'Y-m-01', $after ) );
89
-
90
-		while ( $min_date <= $before ) {
91
-			$this->interval ++;
92
-			$min_date = strtotime( '+1 MONTH', $min_date );
93
-		}
94
-
95
-		$this->interval = max( 1, $this->interval );
96
-
97
-	}
98
-
99
-	/**
100
-	 * Retrieves a custom date range.
101
-	 *
102
-	 * @param WP_REST_Request $request Request object.
103
-	 * @return array The appropriate date range.
104
-	 */
105
-	public function get_custom_date_range( $request ) {
106
-
107
-		$after  = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( $request['after'] ) ) );
108
-		$before = gmdate( 'Y-m-d' );
19
+    /**
20
+     * Group response items by day or month.
21
+     *
22
+     * @var string
23
+     */
24
+    public $groupby = 'day';
25
+
26
+    /**
27
+     * Returns an array with arguments to request the previous report.
28
+     *
29
+     * @var array
30
+     */
31
+    public $previous_range = array();
32
+
33
+    /**
34
+     * The period interval.
35
+     *
36
+     * @var int
37
+     */
38
+    public $interval;
39
+
40
+    /**
41
+     * Retrieves the before and after dates.
42
+     *
43
+     * @param WP_REST_Request $request Request object.
44
+     * @return array The appropriate date range.
45
+     */
46
+    public function get_date_range( $request ) {
47
+
48
+        // Check if the period is x_days.
49
+        if ( preg_match( '/^(\d+)_days$/', $request['period'], $matches ) ) {
50
+            $date_range = $this->get_x_days_date_range( absint( $matches[1] ) );
51
+        } elseif ( is_callable( array( $this, 'get_' . $request['period'] . '_date_range' ) ) ) {
52
+            $date_range = call_user_func( array( $this, 'get_' . $request['period'] . '_date_range' ), $request );
53
+        } else {
54
+            $request['period'] = '7_days';
55
+            $date_range        = $this->get_x_days_date_range();
56
+        }
57
+
58
+        // 3 months max for day view.
59
+        $before = strtotime( $date_range['before'] );
60
+        $after  = strtotime( $date_range['after'] );
61
+        if ( floor( ( $before - $after ) / MONTH_IN_SECONDS ) > 2 ) {
62
+            $this->groupby = 'month';
63
+        }
64
+
65
+        $this->prepare_interval( $date_range );
66
+
67
+        return $date_range;
68
+
69
+    }
70
+
71
+    /**
72
+     * Groups by month or days.
73
+     *
74
+     * @param array $range Date range.
75
+     * @return array The appropriate date range.
76
+     */
77
+    public function prepare_interval( $range ) {
78
+
79
+        $before = strtotime( $range['before'] );
80
+        $after  = strtotime( $range['after'] );
81
+        if ( 'day' === $this->groupby ) {
82
+            $difference     = max( DAY_IN_SECONDS, ( DAY_IN_SECONDS + $before - $after ) ); // Prevent division by 0;
83
+            $this->interval = absint( ceil( max( 1, $difference / DAY_IN_SECONDS ) ) );
84
+            return;
85
+        }
86
+
87
+        $this->interval = 0;
88
+        $min_date       = strtotime( gmdate( 'Y-m-01', $after ) );
89
+
90
+        while ( $min_date <= $before ) {
91
+            $this->interval ++;
92
+            $min_date = strtotime( '+1 MONTH', $min_date );
93
+        }
94
+
95
+        $this->interval = max( 1, $this->interval );
96
+
97
+    }
98
+
99
+    /**
100
+     * Retrieves a custom date range.
101
+     *
102
+     * @param WP_REST_Request $request Request object.
103
+     * @return array The appropriate date range.
104
+     */
105
+    public function get_custom_date_range( $request ) {
106
+
107
+        $after  = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( $request['after'] ) ) );
108
+        $before = gmdate( 'Y-m-d' );
109 109
 		
110
-		if ( ! empty( $request['before'] ) ) {
111
-			$before  = min( strtotime( $before ), strtotime( sanitize_text_field( $request['before'] ) ) );
112
-		}
113
-
114
-		// Set the previous date range.
115
-		$difference           = $before - $after;
116
-		$this->previous_range = array(
117
-			'period' => 'custom',
118
-			'before' => gmdate( 'Y-m-d', $before - $difference - DAY_IN_SECONDS ),
119
-			'after'  => gmdate( 'Y-m-d', $after - $difference - DAY_IN_SECONDS ),
120
-		);
121
-
122
-		// Generate the report.
123
-		return array(
124
-			'before' => gmdate( 'Y-m-d', $before ),
125
-			'after'  => gmdate( 'Y-m-d', $after ),
126
-		);
127
-
128
-	}
129
-
130
-	/**
131
-	 * Retrieves todays date range.
132
-	 *
133
-	 * @return array The appropriate date range.
134
-	 */
135
-	public function get_today_date_range() {
136
-
137
-		// Set the previous date range.
138
-		$this->previous_range = array(
139
-			'period' => 'yesterday',
140
-		);
141
-
142
-		// Generate the report.
143
-		return array(
144
-			'before' => gmdate( 'Y-m-d' ),
145
-			'after'  => gmdate( 'Y-m-d' ),
146
-		);
147
-
148
-	}
149
-
150
-	/**
151
-	 * Retrieves yesterdays date range.
152
-	 *
153
-	 * @return array The appropriate date range.
154
-	 */
155
-	public function get_yesterday_date_range() {
156
-
157
-		// Set the previous date range.
158
-		$this->previous_range = array(
159
-			'period' => 'custom',
160
-			'before' => gmdate( 'Y-m-d', strtotime( '-2 days' ) ),
161
-			'after'  => gmdate( 'Y-m-d', strtotime( '-2 days' ) ),
162
-		);
163
-
164
-		// Generate the report.
165
-		return array(
166
-			'before' => gmdate( 'Y-m-d', strtotime( '-1 day' ) ),
167
-			'after'  => gmdate( 'Y-m-d', strtotime( '-1 day' ) ),
168
-		);
169
-
170
-	}
171
-
172
-	/**
173
-	 * Retrieves this week's date range.
174
-	 *
175
-	 * @return array The appropriate date range.
176
-	 */
177
-	public function get_week_date_range() {
178
-
179
-		// Set the previous date range.
180
-		$this->previous_range = array(
181
-			'period' => 'last_week',
182
-		);
183
-
184
-		// Generate the report.
185
-		$week_starts = absint( get_option( 'start_of_week' ) );
186
-		return array(
187
-			'before' => gmdate( 'Y-m-d' ),
188
-			'after'  => gmdate( 'Y-m-d', strtotime( 'next Sunday -' . ( 7 - $week_starts ) . ' days' ) ),
189
-		);
190
-	}
191
-
192
-	/**
193
-	 * Retrieves last week's date range.
194
-	 *
195
-	 * @return array The appropriate date range.
196
-	 */
197
-	public function get_last_week_date_range() {
198
-
199
-		$week_starts = absint( get_option( 'start_of_week' ) );
200
-		$week_starts = strtotime( 'last Sunday -' . ( 7 - $week_starts ) . ' days' );
201
-		$date_range  = array(
202
-			'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ),
203
-			'after'  => gmdate( 'Y-m-d', $week_starts ),
204
-		);
205
-
206
-		// Set the previous date range.
207
-		$week_starts          = $week_starts - 7 * DAY_IN_SECONDS;
208
-		$this->previous_range = array(
209
-			'period' => 'custom',
210
-			'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ),
211
-			'after'  => gmdate( 'Y-m-d', $week_starts ),
212
-		);
213
-
214
-		// Generate the report.
215
-		return $date_range;
216
-	}
217
-
218
-	/**
219
-	 * Retrieves last x days date range.
220
-	 *
221
-	 * @return array The appropriate date range.
222
-	 */
223
-	public function get_x_days_date_range( $days = 7 ) {
224
-
225
-		$days--;
226
-
227
-		$date_range  = array(
228
-			'before' => gmdate( 'Y-m-d' ),
229
-			'after'  => gmdate( 'Y-m-d', strtotime( "-$days days" ) ),
230
-		);
231
-
232
-		$days++;
233
-
234
-		// Set the previous date range.
235
-		$this->previous_range = array(
236
-			'period' => 'custom',
237
-			'before' => gmdate( 'Y-m-d', strtotime( $date_range['before'] ) - $days * DAY_IN_SECONDS ),
238
-			'after'  => gmdate( 'Y-m-d', strtotime( $date_range['after'] ) - $days * DAY_IN_SECONDS ),
239
-		);
240
-
241
-		// Generate the report.
242
-		return $date_range;
243
-	}
244
-
245
-	/**
246
-	 * Retrieves this month date range.
247
-	 *
248
-	 * @return array The appropriate date range.
249
-	 */
250
-	public function get_month_date_range() {
251
-
252
-		// Set the previous date range.
253
-		$this->previous_range = array(
254
-			'period' => 'last_month',
255
-		);
256
-
257
-		// Generate the report.
258
-		return array(
259
-			'after'  => gmdate( 'Y-m-01' ),
260
-			'before' => gmdate( 'Y-m-t' ),
261
-		);
262
-
263
-	}
264
-
265
-	/**
266
-	 * Retrieves last month's date range.
267
-	 *
268
-	 * @return array The appropriate date range.
269
-	 */
270
-	public function get_last_month_date_range() {
271
-
272
-		// Set the previous date range.
273
-		$this->previous_range = array(
274
-			'period' => 'custom',
275
-			'after'  => gmdate( 'Y-m-01', strtotime( '-2 months' ) ),
276
-			'before' => gmdate( 'Y-m-t', strtotime( '-2 months' ) ),
277
-		);
278
-
279
-		// Generate the report.
280
-		return array(
281
-			'after'  => gmdate( 'Y-m-01', strtotime( 'last month' ) ),
282
-			'before' => gmdate( 'Y-m-t', strtotime( 'last month' ) ),
283
-		);
284
-
285
-	}
286
-
287
-	/**
288
-	 * Retrieves this quarter date range.
289
-	 *
290
-	 * @return array The available quarters.
291
-	 */
292
-	public function get_quarters() {
293
-
294
-		$year      = (int) gmdate( 'Y' );
295
-		$last_year = (int) $year - 1;
296
-		return array(
297
-
298
-			// Third quarter of previous year: July 1st to September 30th
299
-			array(
300
-				'before' => "{$last_year}-09-30",
301
-				'after'  => "{$last_year}-07-01",
302
-			),
303
-
304
-			// Last quarter of previous year: October 1st to December 31st
305
-			array(
306
-				'before' => "{$last_year}-12-31",
307
-        		'after'  => "{$last_year}-10-01",
308
-			),
309
-
310
-			// First quarter: January 1st to March 31st
311
-			array(
312
-				'before' => "{$year}-03-31",
313
-				'after'  => "{$year}-01-01",
314
-			),
315
-
316
-			// Second quarter: April 1st to June 30th
317
-			array(
318
-				'before' => "{$year}-06-30",
319
-				'after'  => "{$year}-04-01",
320
-			),
321
-
322
-			// Third quarter: July 1st to September 30th
323
-			array(
324
-				'before' => "{$year}-09-30",
325
-				'after'  => "{$year}-07-01",
326
-			),
327
-
328
-			// Fourth quarter: October 1st to December 31st
329
-			array(
330
-				'before' => "{$year}-12-31",
331
-				'after'  => "{$year}-10-01",
332
-			),
333
-		);
334
-	}
335
-
336
-	/**
337
-	 * Retrieves the current quater.
338
-	 *
339
-	 * @return int The current quarter.
340
-	 */
341
-	public function get_quarter() {
342
-
343
-		$month    = (int) gmdate( 'n' );
344
-		$quarters = array( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 );
345
-		return $quarters[ $month - 1 ];
346
-
347
-	}
348
-
349
-	/**
350
-	 * Retrieves this quarter date range.
351
-	 *
352
-	 * @return array The appropriate date range.
353
-	 */
354
-	public function get_quarter_date_range() {
355
-
356
-		// Set the previous date range.
357
-		$this->previous_range = array(
358
-			'period' => 'last_quarter',
359
-		);
360
-
361
-		// Generate the report.
362
-		$quarter  = $this->get_quarter();
363
-		$quarters = $this->get_quarters();
364
-		return $quarters[ $quarter + 1 ];
365
-
366
-	}
367
-
368
-	/**
369
-	 * Retrieves last quarter's date range.
370
-	 *
371
-	 * @return array The appropriate date range.
372
-	 */
373
-	public function get_last_quarter_date_range() {
374
-
375
-		$quarters = $this->get_quarters();
376
-		$quarter  = $this->get_quarter();
377
-
378
-		// Set the previous date range.
379
-		$this->previous_range = array_merge(
380
-			$quarters[ $quarter - 1 ],
381
-			array( 'period' => 'custom' )
382
-		);
383
-
384
-		// Generate the report.
385
-		return $quarters[ $quarter ];
386
-
387
-	}
388
-
389
-	/**
390
-	 * Retrieves this year date range.
391
-	 *
392
-	 * @return array The appropriate date range.
393
-	 */
394
-	public function get_year_date_range() {
395
-
396
-		// Set the previous date range.
397
-		$this->previous_range = array(
398
-			'period' => 'last_year',
399
-		);
400
-
401
-		// Generate the report.
402
-		return array(
403
-			'after'  => gmdate( 'Y-01-01' ),
404
-			'before' => gmdate( 'Y-12-31' ),
405
-		);
406
-
407
-	}
408
-
409
-	/**
410
-	 * Retrieves last year date range.
411
-	 *
412
-	 * @return array The appropriate date range.
413
-	 */
414
-	public function get_last_year_date_range() {
415
-
416
-		// Set the previous date range.
417
-		$this->previous_range = array(
418
-			'period' => 'custom',
419
-			'after'  => gmdate( 'Y-01-01', strtotime( '-2 years' ) ),
420
-			'before' => gmdate( 'Y-12-31', strtotime( '-2 years' ) ),
421
-		);
422
-
423
-		// Generate the report.
424
-		return array(
425
-			'after'  => gmdate( 'Y-01-01', strtotime( 'last year' ) ),
426
-			'before' => gmdate( 'Y-12-31', strtotime( 'last year' ) ),
427
-		);
428
-
429
-	}
430
-
431
-	/**
432
-	 * Prepare a the request date for SQL usage.
433
-	 *
434
-	 * @param WP_REST_Request $request Request object.
435
-	 * @param string $date_field The date field.
436
-	 * @return string The appropriate SQL.
437
-	 */
438
-	public function get_date_range_sql( $request, $date_field ) {
439
-		global $wpdb;
440
-
441
-		$sql = '1=1';
442
-		$range = $this->get_date_range( $request );
443
-
444
-		if ( ! empty( $range['after'] ) ) {
445
-			$sql .= ' AND ' . $wpdb->prepare(
446
-				"$date_field >= %s",
447
-				$range['after']
448
-			);
449
-		}
450
-
451
-		if ( ! empty( $range['before'] ) ) {
452
-			$sql .= ' AND ' . $wpdb->prepare(
453
-				"$date_field <= %s",
454
-				$range['before']
455
-			);
456
-		}
457
-
458
-		return $sql;
459
-
460
-	}
461
-
462
-	/**
463
-	 * Prepares a group by query.
464
-	 *
465
-	 * @param string $date_field The date field.
466
-	 * @return string The appropriate SQL.
467
-	 */
468
-	public function get_group_by_sql( $date_field ) {
469
-
470
-		if ( 'day' === $this->groupby ) {
471
-			return "YEAR($date_field), MONTH($date_field), DAY($date_field)";
472
-		}
473
-
474
-		return "YEAR($date_field), MONTH($date_field)";
475
-	}
476
-
477
-	/**
478
-	 * Get the query params for collections.
479
-	 *
480
-	 * @return array
481
-	 */
482
-	public function get_collection_params() {
483
-		return array(
484
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
485
-			'period'  => array(
486
-				'description'       => __( 'Limit to results of a specific period.', 'invoicing' ),
487
-				'type'              => 'string',
488
-				'enum'              => array( 'custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'quarter', 'last_quarter', 'year', 'last_year', 'quarter', 'last_quarter' ),
489
-				'validate_callback' => 'rest_validate_request_arg',
490
-				'sanitize_callback' => 'sanitize_text_field',
491
-				'default'           => '7_days',
492
-			),
493
-			'after'   => array(
494
-				/* translators: %s: date format */
495
-				'description'       => sprintf( __( 'Limit to results after a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ),
496
-				'type'              => 'string',
497
-				'validate_callback' => 'rest_validate_request_arg',
498
-				'sanitize_callback' => 'sanitize_text_field',
499
-				'default'           => gmdate( 'Y-m-d', strtotime( '-7 days' ) ),
500
-			),
501
-			'before'  => array(
502
-				/* translators: %s: date format */
503
-				'description'       => sprintf( __( 'Limit to results before a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ),
504
-				'type'              => 'string',
505
-				'validate_callback' => 'rest_validate_request_arg',
506
-				'sanitize_callback' => 'sanitize_text_field',
507
-				'default'           => gmdate( 'Y-m-d' ),
508
-			),
509
-		);
510
-	}
110
+        if ( ! empty( $request['before'] ) ) {
111
+            $before  = min( strtotime( $before ), strtotime( sanitize_text_field( $request['before'] ) ) );
112
+        }
113
+
114
+        // Set the previous date range.
115
+        $difference           = $before - $after;
116
+        $this->previous_range = array(
117
+            'period' => 'custom',
118
+            'before' => gmdate( 'Y-m-d', $before - $difference - DAY_IN_SECONDS ),
119
+            'after'  => gmdate( 'Y-m-d', $after - $difference - DAY_IN_SECONDS ),
120
+        );
121
+
122
+        // Generate the report.
123
+        return array(
124
+            'before' => gmdate( 'Y-m-d', $before ),
125
+            'after'  => gmdate( 'Y-m-d', $after ),
126
+        );
127
+
128
+    }
129
+
130
+    /**
131
+     * Retrieves todays date range.
132
+     *
133
+     * @return array The appropriate date range.
134
+     */
135
+    public function get_today_date_range() {
136
+
137
+        // Set the previous date range.
138
+        $this->previous_range = array(
139
+            'period' => 'yesterday',
140
+        );
141
+
142
+        // Generate the report.
143
+        return array(
144
+            'before' => gmdate( 'Y-m-d' ),
145
+            'after'  => gmdate( 'Y-m-d' ),
146
+        );
147
+
148
+    }
149
+
150
+    /**
151
+     * Retrieves yesterdays date range.
152
+     *
153
+     * @return array The appropriate date range.
154
+     */
155
+    public function get_yesterday_date_range() {
156
+
157
+        // Set the previous date range.
158
+        $this->previous_range = array(
159
+            'period' => 'custom',
160
+            'before' => gmdate( 'Y-m-d', strtotime( '-2 days' ) ),
161
+            'after'  => gmdate( 'Y-m-d', strtotime( '-2 days' ) ),
162
+        );
163
+
164
+        // Generate the report.
165
+        return array(
166
+            'before' => gmdate( 'Y-m-d', strtotime( '-1 day' ) ),
167
+            'after'  => gmdate( 'Y-m-d', strtotime( '-1 day' ) ),
168
+        );
169
+
170
+    }
171
+
172
+    /**
173
+     * Retrieves this week's date range.
174
+     *
175
+     * @return array The appropriate date range.
176
+     */
177
+    public function get_week_date_range() {
178
+
179
+        // Set the previous date range.
180
+        $this->previous_range = array(
181
+            'period' => 'last_week',
182
+        );
183
+
184
+        // Generate the report.
185
+        $week_starts = absint( get_option( 'start_of_week' ) );
186
+        return array(
187
+            'before' => gmdate( 'Y-m-d' ),
188
+            'after'  => gmdate( 'Y-m-d', strtotime( 'next Sunday -' . ( 7 - $week_starts ) . ' days' ) ),
189
+        );
190
+    }
191
+
192
+    /**
193
+     * Retrieves last week's date range.
194
+     *
195
+     * @return array The appropriate date range.
196
+     */
197
+    public function get_last_week_date_range() {
198
+
199
+        $week_starts = absint( get_option( 'start_of_week' ) );
200
+        $week_starts = strtotime( 'last Sunday -' . ( 7 - $week_starts ) . ' days' );
201
+        $date_range  = array(
202
+            'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ),
203
+            'after'  => gmdate( 'Y-m-d', $week_starts ),
204
+        );
205
+
206
+        // Set the previous date range.
207
+        $week_starts          = $week_starts - 7 * DAY_IN_SECONDS;
208
+        $this->previous_range = array(
209
+            'period' => 'custom',
210
+            'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ),
211
+            'after'  => gmdate( 'Y-m-d', $week_starts ),
212
+        );
213
+
214
+        // Generate the report.
215
+        return $date_range;
216
+    }
217
+
218
+    /**
219
+     * Retrieves last x days date range.
220
+     *
221
+     * @return array The appropriate date range.
222
+     */
223
+    public function get_x_days_date_range( $days = 7 ) {
224
+
225
+        $days--;
226
+
227
+        $date_range  = array(
228
+            'before' => gmdate( 'Y-m-d' ),
229
+            'after'  => gmdate( 'Y-m-d', strtotime( "-$days days" ) ),
230
+        );
231
+
232
+        $days++;
233
+
234
+        // Set the previous date range.
235
+        $this->previous_range = array(
236
+            'period' => 'custom',
237
+            'before' => gmdate( 'Y-m-d', strtotime( $date_range['before'] ) - $days * DAY_IN_SECONDS ),
238
+            'after'  => gmdate( 'Y-m-d', strtotime( $date_range['after'] ) - $days * DAY_IN_SECONDS ),
239
+        );
240
+
241
+        // Generate the report.
242
+        return $date_range;
243
+    }
244
+
245
+    /**
246
+     * Retrieves this month date range.
247
+     *
248
+     * @return array The appropriate date range.
249
+     */
250
+    public function get_month_date_range() {
251
+
252
+        // Set the previous date range.
253
+        $this->previous_range = array(
254
+            'period' => 'last_month',
255
+        );
256
+
257
+        // Generate the report.
258
+        return array(
259
+            'after'  => gmdate( 'Y-m-01' ),
260
+            'before' => gmdate( 'Y-m-t' ),
261
+        );
262
+
263
+    }
264
+
265
+    /**
266
+     * Retrieves last month's date range.
267
+     *
268
+     * @return array The appropriate date range.
269
+     */
270
+    public function get_last_month_date_range() {
271
+
272
+        // Set the previous date range.
273
+        $this->previous_range = array(
274
+            'period' => 'custom',
275
+            'after'  => gmdate( 'Y-m-01', strtotime( '-2 months' ) ),
276
+            'before' => gmdate( 'Y-m-t', strtotime( '-2 months' ) ),
277
+        );
278
+
279
+        // Generate the report.
280
+        return array(
281
+            'after'  => gmdate( 'Y-m-01', strtotime( 'last month' ) ),
282
+            'before' => gmdate( 'Y-m-t', strtotime( 'last month' ) ),
283
+        );
284
+
285
+    }
286
+
287
+    /**
288
+     * Retrieves this quarter date range.
289
+     *
290
+     * @return array The available quarters.
291
+     */
292
+    public function get_quarters() {
293
+
294
+        $year      = (int) gmdate( 'Y' );
295
+        $last_year = (int) $year - 1;
296
+        return array(
297
+
298
+            // Third quarter of previous year: July 1st to September 30th
299
+            array(
300
+                'before' => "{$last_year}-09-30",
301
+                'after'  => "{$last_year}-07-01",
302
+            ),
303
+
304
+            // Last quarter of previous year: October 1st to December 31st
305
+            array(
306
+                'before' => "{$last_year}-12-31",
307
+                'after'  => "{$last_year}-10-01",
308
+            ),
309
+
310
+            // First quarter: January 1st to March 31st
311
+            array(
312
+                'before' => "{$year}-03-31",
313
+                'after'  => "{$year}-01-01",
314
+            ),
315
+
316
+            // Second quarter: April 1st to June 30th
317
+            array(
318
+                'before' => "{$year}-06-30",
319
+                'after'  => "{$year}-04-01",
320
+            ),
321
+
322
+            // Third quarter: July 1st to September 30th
323
+            array(
324
+                'before' => "{$year}-09-30",
325
+                'after'  => "{$year}-07-01",
326
+            ),
327
+
328
+            // Fourth quarter: October 1st to December 31st
329
+            array(
330
+                'before' => "{$year}-12-31",
331
+                'after'  => "{$year}-10-01",
332
+            ),
333
+        );
334
+    }
335
+
336
+    /**
337
+     * Retrieves the current quater.
338
+     *
339
+     * @return int The current quarter.
340
+     */
341
+    public function get_quarter() {
342
+
343
+        $month    = (int) gmdate( 'n' );
344
+        $quarters = array( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 );
345
+        return $quarters[ $month - 1 ];
346
+
347
+    }
348
+
349
+    /**
350
+     * Retrieves this quarter date range.
351
+     *
352
+     * @return array The appropriate date range.
353
+     */
354
+    public function get_quarter_date_range() {
355
+
356
+        // Set the previous date range.
357
+        $this->previous_range = array(
358
+            'period' => 'last_quarter',
359
+        );
360
+
361
+        // Generate the report.
362
+        $quarter  = $this->get_quarter();
363
+        $quarters = $this->get_quarters();
364
+        return $quarters[ $quarter + 1 ];
365
+
366
+    }
367
+
368
+    /**
369
+     * Retrieves last quarter's date range.
370
+     *
371
+     * @return array The appropriate date range.
372
+     */
373
+    public function get_last_quarter_date_range() {
374
+
375
+        $quarters = $this->get_quarters();
376
+        $quarter  = $this->get_quarter();
377
+
378
+        // Set the previous date range.
379
+        $this->previous_range = array_merge(
380
+            $quarters[ $quarter - 1 ],
381
+            array( 'period' => 'custom' )
382
+        );
383
+
384
+        // Generate the report.
385
+        return $quarters[ $quarter ];
386
+
387
+    }
388
+
389
+    /**
390
+     * Retrieves this year date range.
391
+     *
392
+     * @return array The appropriate date range.
393
+     */
394
+    public function get_year_date_range() {
395
+
396
+        // Set the previous date range.
397
+        $this->previous_range = array(
398
+            'period' => 'last_year',
399
+        );
400
+
401
+        // Generate the report.
402
+        return array(
403
+            'after'  => gmdate( 'Y-01-01' ),
404
+            'before' => gmdate( 'Y-12-31' ),
405
+        );
406
+
407
+    }
408
+
409
+    /**
410
+     * Retrieves last year date range.
411
+     *
412
+     * @return array The appropriate date range.
413
+     */
414
+    public function get_last_year_date_range() {
415
+
416
+        // Set the previous date range.
417
+        $this->previous_range = array(
418
+            'period' => 'custom',
419
+            'after'  => gmdate( 'Y-01-01', strtotime( '-2 years' ) ),
420
+            'before' => gmdate( 'Y-12-31', strtotime( '-2 years' ) ),
421
+        );
422
+
423
+        // Generate the report.
424
+        return array(
425
+            'after'  => gmdate( 'Y-01-01', strtotime( 'last year' ) ),
426
+            'before' => gmdate( 'Y-12-31', strtotime( 'last year' ) ),
427
+        );
428
+
429
+    }
430
+
431
+    /**
432
+     * Prepare a the request date for SQL usage.
433
+     *
434
+     * @param WP_REST_Request $request Request object.
435
+     * @param string $date_field The date field.
436
+     * @return string The appropriate SQL.
437
+     */
438
+    public function get_date_range_sql( $request, $date_field ) {
439
+        global $wpdb;
440
+
441
+        $sql = '1=1';
442
+        $range = $this->get_date_range( $request );
443
+
444
+        if ( ! empty( $range['after'] ) ) {
445
+            $sql .= ' AND ' . $wpdb->prepare(
446
+                "$date_field >= %s",
447
+                $range['after']
448
+            );
449
+        }
450
+
451
+        if ( ! empty( $range['before'] ) ) {
452
+            $sql .= ' AND ' . $wpdb->prepare(
453
+                "$date_field <= %s",
454
+                $range['before']
455
+            );
456
+        }
457
+
458
+        return $sql;
459
+
460
+    }
461
+
462
+    /**
463
+     * Prepares a group by query.
464
+     *
465
+     * @param string $date_field The date field.
466
+     * @return string The appropriate SQL.
467
+     */
468
+    public function get_group_by_sql( $date_field ) {
469
+
470
+        if ( 'day' === $this->groupby ) {
471
+            return "YEAR($date_field), MONTH($date_field), DAY($date_field)";
472
+        }
473
+
474
+        return "YEAR($date_field), MONTH($date_field)";
475
+    }
476
+
477
+    /**
478
+     * Get the query params for collections.
479
+     *
480
+     * @return array
481
+     */
482
+    public function get_collection_params() {
483
+        return array(
484
+            'context' => $this->get_context_param( array( 'default' => 'view' ) ),
485
+            'period'  => array(
486
+                'description'       => __( 'Limit to results of a specific period.', 'invoicing' ),
487
+                'type'              => 'string',
488
+                'enum'              => array( 'custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'quarter', 'last_quarter', 'year', 'last_year', 'quarter', 'last_quarter' ),
489
+                'validate_callback' => 'rest_validate_request_arg',
490
+                'sanitize_callback' => 'sanitize_text_field',
491
+                'default'           => '7_days',
492
+            ),
493
+            'after'   => array(
494
+                /* translators: %s: date format */
495
+                'description'       => sprintf( __( 'Limit to results after a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ),
496
+                'type'              => 'string',
497
+                'validate_callback' => 'rest_validate_request_arg',
498
+                'sanitize_callback' => 'sanitize_text_field',
499
+                'default'           => gmdate( 'Y-m-d', strtotime( '-7 days' ) ),
500
+            ),
501
+            'before'  => array(
502
+                /* translators: %s: date format */
503
+                'description'       => sprintf( __( 'Limit to results before a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ),
504
+                'type'              => 'string',
505
+                'validate_callback' => 'rest_validate_request_arg',
506
+                'sanitize_callback' => 'sanitize_text_field',
507
+                'default'           => gmdate( 'Y-m-d' ),
508
+            ),
509
+        );
510
+    }
511 511
 }
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-report-sales-controller.php 1 patch
Indentation   +679 added lines, -679 removed lines patch added patch discarded remove patch
@@ -18,688 +18,688 @@
 block discarded – undo
18 18
  */
19 19
 class GetPaid_REST_Report_Sales_Controller extends GetPaid_REST_Date_Based_Controller {
20 20
 
21
-	/**
22
-	 * Route base.
23
-	 *
24
-	 * @var string
25
-	 */
26
-	protected $rest_base = 'reports/sales';
27
-
28
-	/**
29
-	 * The report data.
30
-	 *
31
-	 * @var stdClass
32
-	 */
33
-	public $report_data;
34
-
35
-	/**
36
-	 * The report range.
37
-	 *
38
-	 * @var array
39
-	 */
40
-	public $report_range;
41
-
42
-	/**
43
-	 * Registers the routes for the objects of the controller.
44
-	 *
45
-	 * @since 2.0.0
46
-	 *
47
-	 * @see register_rest_route()
48
-	 */
49
-	public function register_namespace_routes( $namespace ) {
50
-
51
-		// Get sales report.
52
-		register_rest_route(
53
-			$namespace,
54
-			$this->rest_base,
55
-			array(
56
-				array(
57
-					'methods'             => WP_REST_Server::READABLE,
58
-					'callback'            => array( $this, 'get_items' ),
59
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
60
-					'args'                => $this->get_collection_params(),
61
-				),
62
-				'schema' => array( $this, 'get_public_item_schema' ),
63
-			)
64
-		);
65
-
66
-	}
67
-
68
-	/**
69
-	 * Makes sure the current user has access to READ the report APIs.
70
-	 *
71
-	 * @since  2.0.0
72
-	 * @param WP_REST_Request $request Full data about the request.
73
-	 * @return WP_Error|boolean
74
-	 */
75
-	public function get_items_permissions_check( $request ) {
76
-
77
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
78
-			return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
79
-		}
80
-
81
-		return true;
82
-	}
83
-
84
-	/**
85
-	 * Get sales reports.
86
-	 *
87
-	 * @param WP_REST_Request $request
88
-	 * @return array|WP_Error
89
-	 */
90
-	public function get_items( $request ) {
91
-		$data   = array();
92
-		$item   = $this->prepare_item_for_response( null, $request );
93
-		$data[] = $this->prepare_response_for_collection( $item );
94
-
95
-		return rest_ensure_response( $data );
96
-	}
97
-
98
-	/**
99
-	 * Prepare a report sales object for serialization.
100
-	 *
101
-	 * @param null $_
102
-	 * @param WP_REST_Request $request Request object.
103
-	 * @return WP_REST_Response $response Response data.
104
-	 */
105
-	public function prepare_item_for_response( $_, $request ) {
106
-
107
-		// Set report range.
108
-		$this->report_range = $this->get_date_range( $request );
109
-
110
-		$report_data     = $this->get_report_data();
111
-		$period_totals   = array();
112
-
113
-		// Setup period totals by ensuring each period in the interval has data.
114
-		$start_date      = strtotime( $this->report_range['after'] );
115
-
116
-		if ( 'month' === $this->groupby ) {
117
-			$start_date      = strtotime( gmdate( 'Y-m-01', $start_date ) );
118
-		}
119
-
120
-		for ( $i = 0; $i < $this->interval; $i++ ) {
121
-
122
-			switch ( $this->groupby ) {
123
-				case 'day':
124
-					$time = gmdate( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) );
125
-					break;
126
-				default:
127
-					$time = gmdate( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) );
128
-					break;
129
-			}
130
-
131
-			// Set the defaults for each period.
132
-			$period_totals[ $time ] = array(
133
-				'invoices'          => 0,
134
-				'items'             => 0,
135
-				'refunded_items'    => 0,
136
-				'refunded_tax'      => wpinv_round_amount( 0.00 ),
137
-				'subtotal'          => wpinv_round_amount( 0.00 ),
138
-				'refunded_subtotal' => wpinv_round_amount( 0.00 ),
139
-				'refunded_fees'     => wpinv_round_amount( 0.00 ),
140
-				'discount'          => wpinv_round_amount( 0.00 ),
141
-			);
142
-
143
-			foreach ( array_keys( wpinv_get_report_graphs() ) as $key ) {
144
-				if ( ! isset( $period_totals[ $time ][ $key ] ) ) {
145
-					$period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 );
146
-				}
147
-			}
148
-		}
149
-
150
-		// add total sales, total invoice count, total tax for each period
151
-		$date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m';
152
-		foreach ( $report_data->invoices as $invoice ) {
153
-			$time = gmdate( $date_format, strtotime( $invoice->post_date ) );
154
-
155
-			if ( ! isset( $period_totals[ $time ] ) ) {
156
-				continue;
157
-			}
158
-
159
-			$period_totals[ $time ]['sales']    = wpinv_round_amount( $invoice->total_sales );
160
-			$period_totals[ $time ]['tax']      = wpinv_round_amount( $invoice->total_tax );
161
-			$period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal );
162
-			$period_totals[ $time ]['fees']     = wpinv_round_amount( $invoice->total_fees );
163
-
164
-		}
165
-
166
-		foreach ( $report_data->refunds as $invoice ) {
167
-			$time = gmdate( $date_format, strtotime( $invoice->post_date ) );
168
-
169
-			if ( ! isset( $period_totals[ $time ] ) ) {
170
-				continue;
171
-			}
172
-
173
-			$period_totals[ $time ]['refunds']           = wpinv_round_amount( $invoice->total_sales );
174
-			$period_totals[ $time ]['refunded_tax']      = wpinv_round_amount( $invoice->total_tax );
175
-			$period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal );
176
-			$period_totals[ $time ]['refunded_fees']     = wpinv_round_amount( $invoice->total_fees );
177
-
178
-		}
179
-
180
-		foreach ( $report_data->invoice_counts as $invoice ) {
181
-			$time = gmdate( $date_format, strtotime( $invoice->post_date ) );
182
-
183
-			if ( isset( $period_totals[ $time ] ) ) {
184
-				$period_totals[ $time ]['invoices']   = (int) $invoice->count;
185
-			}
186
-		}
187
-
188
-		// Add total invoice items for each period.
189
-		foreach ( $report_data->invoice_items as $invoice_item ) {
190
-			$time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : gmdate( 'Y-m', strtotime( $invoice_item->post_date ) );
191
-
192
-			if ( isset( $period_totals[ $time ] ) ) {
193
-				$period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count;
194
-			}
195
-		}
196
-
197
-		// Add total discount for each period.
198
-		foreach ( $report_data->coupons as $discount ) {
199
-			$time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $discount->post_date ) ) : gmdate( 'Y-m', strtotime( $discount->post_date ) );
200
-
201
-			if ( isset( $period_totals[ $time ] ) ) {
202
-				$period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount );
203
-			}
204
-		}
205
-
206
-		// Extra fields.
207
-		foreach ( array_keys( wpinv_get_report_graphs() ) as $key ) {
208
-
209
-			// Abort unprepared.
210
-			if ( ! isset( $report_data->$key ) ) {
211
-				continue;
212
-			} 
213
-
214
-			// Abort defaults.
215
-			if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) {
216
-				continue;
217
-			}
218
-
219
-			// Set values.
220
-			foreach ( $report_data->$key as $item ) {
221
-				$time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $item->date ) ) : gmdate( 'Y-m', strtotime( $item->date ) );
222
-
223
-				if ( isset( $period_totals[ $time ] ) ) {
224
-					$period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val );
225
-				}
226
-			}
227
-
228
-			unset( $report_data->$key );
229
-		}
230
-
231
-		$report_data->totals            = $period_totals;
232
-		$report_data->grouped_by        = $this->groupby;
233
-		$report_data->interval          = max( $this->interval, 1 );
234
-		$report_data->currency          = wpinv_get_currency();
235
-		$report_data->currency_symbol   = wpinv_currency_symbol();
236
-		$report_data->currency_position = wpinv_currency_position();
237
-		$report_data->decimal_places    = wpinv_decimals();
238
-		$report_data->thousands_sep     = wpinv_thousands_separator();
239
-		$report_data->decimals_sep      = wpinv_decimal_separator();
240
-		$report_data->start_date        = gmdate( 'Y-m-d', strtotime( $this->report_range['after'] ) );
241
-		$report_data->end_date          = gmdate( 'Y-m-d', strtotime( $this->report_range['before'] ) );
242
-		$report_data->start_date_locale = getpaid_format_date( gmdate( 'Y-m-d', strtotime( $this->report_range['after'] ) ) );
243
-		$report_data->end_date_locale   = getpaid_format_date( gmdate( 'Y-m-d', strtotime( $this->report_range['before'] ) ) );
244
-		$report_data->decimals_sep      = wpinv_decimal_separator();
245
-
246
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
247
-		$data    = $report_data;
248
-		unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items );
249
-		$data    = $this->add_additional_fields_to_object( (array) $data, $request );
250
-		$data    = $this->filter_response_by_context( $data, $context );
251
-
252
-		// Wrap the data in a response object.
253
-		$response = rest_ensure_response( $data );
254
-		$response->add_links(
21
+    /**
22
+     * Route base.
23
+     *
24
+     * @var string
25
+     */
26
+    protected $rest_base = 'reports/sales';
27
+
28
+    /**
29
+     * The report data.
30
+     *
31
+     * @var stdClass
32
+     */
33
+    public $report_data;
34
+
35
+    /**
36
+     * The report range.
37
+     *
38
+     * @var array
39
+     */
40
+    public $report_range;
41
+
42
+    /**
43
+     * Registers the routes for the objects of the controller.
44
+     *
45
+     * @since 2.0.0
46
+     *
47
+     * @see register_rest_route()
48
+     */
49
+    public function register_namespace_routes( $namespace ) {
50
+
51
+        // Get sales report.
52
+        register_rest_route(
53
+            $namespace,
54
+            $this->rest_base,
255 55
             array(
256
-				'about' => array(
257
-					'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ),
258
-				),
56
+                array(
57
+                    'methods'             => WP_REST_Server::READABLE,
58
+                    'callback'            => array( $this, 'get_items' ),
59
+                    'permission_callback' => array( $this, 'get_items_permissions_check' ),
60
+                    'args'                => $this->get_collection_params(),
61
+                ),
62
+                'schema' => array( $this, 'get_public_item_schema' ),
259 63
             )
260 64
         );
261 65
 
262
-		return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request );
263
-	}
264
-
265
-	/**
266
-	 * Get report data.
267
-	 *
268
-	 * @return stdClass
269
-	 */
270
-	public function get_report_data() {
271
-		if ( empty( $this->report_data ) ) {
272
-			$this->query_report_data();
273
-		}
274
-		return $this->report_data;
275
-	}
276
-
277
-	/**
278
-	 * Get all data needed for this report and store in the class.
279
-	 */
280
-	protected function query_report_data() {
281
-
282
-		// Prepare reports.
283
-		$this->report_data = (object) array(
284
-			'invoice_counts' => $this->query_invoice_counts(), //count, post_date
285
-			'coupons'        => $this->query_coupon_counts(), // discount_amount, post_date
286
-			'invoice_items'  => $this->query_item_counts(), // invoice_item_count, post_date
287
-			'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date
288
-			'invoices'       => $this->query_invoice_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date
289
-			'refunds'        => $this->query_refunded_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date
290
-			'previous_range' => $this->previous_range,
291
-		);
292
-
293
-		// Calculated totals.
294
-		$this->report_data->total_tax          = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) );
295
-		$this->report_data->total_sales        = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) );
296
-		$this->report_data->total_discount     = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) );
297
-		$this->report_data->total_fees         = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) );
298
-		$this->report_data->subtotal           = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) );
299
-		$this->report_data->net_sales          = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) );
300
-		$this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) );
301
-		$this->report_data->total_refunds      = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) );
302
-		$this->report_data->refunded_discount  = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) );
303
-		$this->report_data->refunded_fees      = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) );
304
-		$this->report_data->refunded_subtotal  = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) );
305
-		$this->report_data->net_refunds        = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) );
306
-
307
-		// Calculate average based on net.
308
-		$this->report_data->average_sales       = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 );
309
-		$this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 );
310
-
311
-		// Total invoices in this period, even if refunded.
312
-		$this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) );
313
-
314
-		// Items invoiced in this period, even if refunded.
315
-		$this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) );
316
-
317
-		// 3rd party filtering of report data
318
-		$this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this );
319
-	}
320
-
321
-	/**
322
-	 * Prepares invoice counts.
323
-	 *
324
-	 * @return array.
325
-	 */
326
-	protected function query_invoice_counts() {
327
-
328
-		return (array) GetPaid_Reports_Helper::get_invoice_report_data(
329
-			array(
330
-				'data'           => array(
331
-					'ID'        => array(
332
-						'type'     => 'post_data',
333
-						'function' => 'COUNT',
334
-						'name'     => 'count',
335
-						'distinct' => true,
336
-					),
337
-					'post_date' => array(
338
-						'type'     => 'post_data',
339
-						'function' => 'MIN',
340
-						'name'     => 'post_date',
341
-					),
342
-				),
343
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
344
-				'order_by'       => 'post_date ASC',
345
-				'query_type'     => 'get_results',
346
-				'filter_range'   => $this->report_range,
347
-				'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ),
348
-			)
349
-		);
350
-
351
-	}
352
-
353
-	/**
354
-	 * Prepares coupon counts.
355
-	 *
356
-	 * @return array.
357
-	 */
358
-	protected function query_coupon_counts() {
359
-
360
-		return (array) GetPaid_Reports_Helper::get_invoice_report_data(
361
-			array(
362
-				'data'           => array(
363
-					'discount'  => array(
364
-						'type'     => 'invoice_data',
365
-						'function' => 'SUM',
366
-						'name'     => 'discount_amount',
367
-					),
368
-					'post_date' => array(
369
-						'type'     => 'post_data',
370
-						'function' => 'MIN',
371
-						'name'     => 'post_date',
372
-					),
373
-				),
374
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
375
-				'order_by'       => 'post_date ASC',
376
-				'query_type'     => 'get_results',
377
-				'filter_range'   => $this->report_range,
378
-				'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ),
379
-			)
380
-		);
381
-
382
-	}
383
-
384
-	/**
385
-	 * Prepares item counts.
386
-	 *
387
-	 * @return array.
388
-	 */
389
-	protected function query_item_counts() {
390
-
391
-		return (array) GetPaid_Reports_Helper::get_invoice_report_data(
392
-			array(
393
-				'data'           => array(
394
-					'quantity'  => array(
395
-						'type'     => 'invoice_item',
396
-						'function' => 'SUM',
397
-						'name'     => 'invoice_item_count',
398
-					),
399
-					'post_date' => array(
400
-						'type'     => 'post_data',
401
-						'function' => 'MIN',
402
-						'name'     => 'post_date',
403
-					),
404
-				),
405
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
406
-				'order_by'       => 'post_date ASC',
407
-				'query_type'     => 'get_results',
408
-				'filter_range'   => $this->report_range,
409
-				'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ),
410
-			)
411
-		);
412
-
413
-	}
414
-
415
-	/**
416
-	 * Prepares refunded item counts.
417
-	 *
418
-	 * @return array.
419
-	 */
420
-	protected function count_refunded_items() {
421
-
422
-		return (int) GetPaid_Reports_Helper::get_invoice_report_data(
423
-			array(
424
-				'data'           => array(
425
-					'quantity' => array(
426
-						'type'     => 'invoice_item',
427
-						'function' => 'SUM',
428
-						'name'     => 'invoice_item_count',
429
-					),
430
-				),
431
-				'query_type'     => 'get_var',
432
-				'filter_range'   => $this->report_range,
433
-				'invoice_status' => array( 'wpi-refunded' ),
434
-			)
435
-		);
436
-
437
-	}
438
-
439
-	/**
440
-	 * Prepares daily invoice totals.
441
-	 *
442
-	 * @return array.
443
-	 */
444
-	protected function query_invoice_totals() {
445
-
446
-		return (array) GetPaid_Reports_Helper::get_invoice_report_data(
447
-			array(
448
-				'data'           => array(
449
-					'total'      => array(
450
-						'type'     => 'invoice_data',
451
-						'function' => 'SUM',
452
-						'name'     => 'total_sales',
453
-					),
454
-					'tax'        => array(
455
-						'type'     => 'invoice_data',
456
-						'function' => 'SUM',
457
-						'name'     => 'total_tax',
458
-					),
459
-					'discount'   => array(
460
-						'type'     => 'invoice_data',
461
-						'function' => 'SUM',
462
-						'name'     => 'total_discount',
463
-					),
464
-					'fees_total' => array(
465
-						'type'     => 'invoice_data',
466
-						'function' => 'SUM',
467
-						'name'     => 'total_fees',
468
-					),
469
-					'subtotal'   => array(
470
-						'type'     => 'invoice_data',
471
-						'function' => 'SUM',
472
-						'name'     => 'subtotal',
473
-					),
474
-					'post_date'  => array(
475
-						'type'     => 'post_data',
476
-						'function' => '',
477
-						'name'     => 'post_date',
478
-					),
479
-				),
480
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
481
-				'order_by'       => 'post_date ASC',
482
-				'query_type'     => 'get_results',
483
-				'filter_range'   => $this->report_range,
484
-				'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ),
485
-			)
486
-		);
487
-
488
-	}
489
-
490
-	/**
491
-	 * Prepares daily invoice totals.
492
-	 *
493
-	 * @return array.
494
-	 */
495
-	protected function query_refunded_totals() {
496
-
497
-		return (array) GetPaid_Reports_Helper::get_invoice_report_data(
498
-			array(
499
-				'data'           => array(
500
-					'total'      => array(
501
-						'type'     => 'invoice_data',
502
-						'function' => 'SUM',
503
-						'name'     => 'total_sales',
504
-					),
505
-					'tax'        => array(
506
-						'type'     => 'invoice_data',
507
-						'function' => 'SUM',
508
-						'name'     => 'total_tax',
509
-					),
510
-					'discount'   => array(
511
-						'type'     => 'invoice_data',
512
-						'function' => 'SUM',
513
-						'name'     => 'total_discount',
514
-					),
515
-					'fees_total' => array(
516
-						'type'     => 'invoice_data',
517
-						'function' => 'SUM',
518
-						'name'     => 'total_fees',
519
-					),
520
-					'subtotal'   => array(
521
-						'type'     => 'invoice_data',
522
-						'function' => 'SUM',
523
-						'name'     => 'subtotal',
524
-					),
525
-					'post_date'  => array(
526
-						'type'     => 'post_data',
527
-						'function' => '',
528
-						'name'     => 'post_date',
529
-					),
530
-				),
531
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
532
-				'order_by'       => 'post_date ASC',
533
-				'query_type'     => 'get_results',
534
-				'filter_range'   => $this->report_range,
535
-				'invoice_status' => array( 'wpi-refunded' ),
536
-			)
537
-		);
538
-
539
-	}
540
-
541
-	/**
542
-	 * Get the Report's schema, conforming to JSON Schema.
543
-	 *
544
-	 * @return array
545
-	 */
546
-	public function get_item_schema() {
547
-
548
-		$schema = array(
549
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
550
-			'title'      => 'sales_report',
551
-			'type'       => 'object',
552
-			'properties' => array(
553
-				'total_sales'         => array(
554
-					'description' => __( 'Gross sales in the period.', 'invoicing' ),
555
-					'type'        => 'string',
556
-					'context'     => array( 'view' ),
557
-					'readonly'    => true,
558
-				),
559
-				'net_sales'           => array(
560
-					'description' => __( 'Net sales in the period.', 'invoicing' ),
561
-					'type'        => 'string',
562
-					'context'     => array( 'view' ),
563
-					'readonly'    => true,
564
-				),
565
-				'average_sales'       => array(
566
-					'description' => __( 'Average net daily sales.', 'invoicing' ),
567
-					'type'        => 'string',
568
-					'context'     => array( 'view' ),
569
-					'readonly'    => true,
570
-				),
571
-				'average_total_sales' => array(
572
-					'description' => __( 'Average gross daily sales.', 'invoicing' ),
573
-					'type'        => 'string',
574
-					'context'     => array( 'view' ),
575
-					'readonly'    => true,
576
-				),
577
-				'total_invoices'      => array(
578
-					'description' => __( 'Number of paid invoices.', 'invoicing' ),
579
-					'type'        => 'integer',
580
-					'context'     => array( 'view' ),
581
-					'readonly'    => true,
582
-				),
583
-				'total_items'         => array(
584
-					'description' => __( 'Number of items purchased.', 'invoicing' ),
585
-					'type'        => 'integer',
586
-					'context'     => array( 'view' ),
587
-					'readonly'    => true,
588
-				),
589
-				'refunded_items'      => array(
590
-					'description' => __( 'Number of items refunded.', 'invoicing' ),
591
-					'type'        => 'integer',
592
-					'context'     => array( 'view' ),
593
-					'readonly'    => true,
594
-				),
595
-				'total_tax'           => array(
596
-					'description' => __( 'Total charged for taxes.', 'invoicing' ),
597
-					'type'        => 'string',
598
-					'context'     => array( 'view' ),
599
-					'readonly'    => true,
600
-				),
601
-				'total_refunded_tax'  => array(
602
-					'description' => __( 'Total refunded for taxes.', 'invoicing' ),
603
-					'type'        => 'string',
604
-					'context'     => array( 'view' ),
605
-					'readonly'    => true,
606
-				),
607
-				'total_fees'          => array(
608
-					'description' => __( 'Total fees charged.', 'invoicing' ),
609
-					'type'        => 'string',
610
-					'context'     => array( 'view' ),
611
-					'readonly'    => true,
612
-				),
613
-				'total_refunds'       => array(
614
-					'description' => __( 'Total of refunded invoices.', 'invoicing' ),
615
-					'type'        => 'integer',
616
-					'context'     => array( 'view' ),
617
-					'readonly'    => true,
618
-				),
619
-				'net_refunds'         => array(
620
-					'description' => __( 'Net of refunded invoices.', 'invoicing' ),
621
-					'type'        => 'integer',
622
-					'context'     => array( 'view' ),
623
-					'readonly'    => true,
624
-				),
625
-				'total_discount'      => array(
626
-					'description' => __( 'Total of discounts used.', 'invoicing' ),
627
-					'type'        => 'integer',
628
-					'context'     => array( 'view' ),
629
-					'readonly'    => true,
630
-				),
631
-				'totals'              => array(
632
-					'description' => __( 'Totals.', 'invoicing' ),
633
-					'type'        => 'array',
634
-					'items'       => array(
635
-						'type' => 'array',
636
-					),
637
-					'context'     => array( 'view' ),
638
-					'readonly'    => true,
639
-				),
640
-				'interval'            => array(
641
-					'description' => __( 'Number of months/days in the report period.', 'invoicing' ),
642
-					'type'        => 'integer',
643
-					'context'     => array( 'view' ),
644
-					'readonly'    => true,
645
-				),
646
-				'previous_range'      => array(
647
-					'description' => __( 'The previous report period.', 'invoicing' ),
648
-					'type'        => 'array',
649
-					'items'       => array(
650
-						'type' => 'string',
651
-					),
652
-					'context'     => array( 'view' ),
653
-					'readonly'    => true,
654
-				),
655
-				'grouped_by'          => array(
656
-					'description' => __( 'The period used to group the totals.', 'invoicing' ),
657
-					'type'        => 'string',
658
-					'context'     => array( 'view' ),
659
-					'enum'        => array( 'day', 'month' ),
660
-					'readonly'    => true,
661
-				),
662
-				'currency'            => array(
663
-					'description' => __( 'The default store currency.', 'invoicing' ),
664
-					'type'        => 'string',
665
-					'context'     => array( 'view' ),
666
-					'readonly'    => true,
667
-				),
668
-				'currency_symbol'     => array(
669
-					'description' => __( 'The default store currency symbol.', 'invoicing' ),
670
-					'type'        => 'string',
671
-					'context'     => array( 'view' ),
672
-					'readonly'    => true,
673
-				),
674
-				'currency_position'   => array(
675
-					'description' => __( 'The default store currency position.', 'invoicing' ),
676
-					'type'        => 'string',
677
-					'context'     => array( 'view' ),
678
-					'readonly'    => true,
679
-				),
680
-				'decimal_places'      => array(
681
-					'description' => __( 'The default store decimal places.', 'invoicing' ),
682
-					'type'        => 'string',
683
-					'context'     => array( 'view' ),
684
-					'readonly'    => true,
685
-				),
686
-				'thousands_sep'       => array(
687
-					'description' => __( 'The default store thousands separator.', 'invoicing' ),
688
-					'type'        => 'string',
689
-					'context'     => array( 'view' ),
690
-					'readonly'    => true,
691
-				),
692
-				'decimals_sep'        => array(
693
-					'description' => __( 'The default store decimals separator.', 'invoicing' ),
694
-					'type'        => 'string',
695
-					'context'     => array( 'view' ),
696
-					'readonly'    => true,
697
-				),
698
-			),
699
-		);
700
-
701
-		return $this->add_additional_fields_schema( $schema );
702
-
703
-	}
66
+    }
67
+
68
+    /**
69
+     * Makes sure the current user has access to READ the report APIs.
70
+     *
71
+     * @since  2.0.0
72
+     * @param WP_REST_Request $request Full data about the request.
73
+     * @return WP_Error|boolean
74
+     */
75
+    public function get_items_permissions_check( $request ) {
76
+
77
+        if ( ! wpinv_current_user_can_manage_invoicing() ) {
78
+            return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
79
+        }
80
+
81
+        return true;
82
+    }
83
+
84
+    /**
85
+     * Get sales reports.
86
+     *
87
+     * @param WP_REST_Request $request
88
+     * @return array|WP_Error
89
+     */
90
+    public function get_items( $request ) {
91
+        $data   = array();
92
+        $item   = $this->prepare_item_for_response( null, $request );
93
+        $data[] = $this->prepare_response_for_collection( $item );
94
+
95
+        return rest_ensure_response( $data );
96
+    }
97
+
98
+    /**
99
+     * Prepare a report sales object for serialization.
100
+     *
101
+     * @param null $_
102
+     * @param WP_REST_Request $request Request object.
103
+     * @return WP_REST_Response $response Response data.
104
+     */
105
+    public function prepare_item_for_response( $_, $request ) {
106
+
107
+        // Set report range.
108
+        $this->report_range = $this->get_date_range( $request );
109
+
110
+        $report_data     = $this->get_report_data();
111
+        $period_totals   = array();
112
+
113
+        // Setup period totals by ensuring each period in the interval has data.
114
+        $start_date      = strtotime( $this->report_range['after'] );
115
+
116
+        if ( 'month' === $this->groupby ) {
117
+            $start_date      = strtotime( gmdate( 'Y-m-01', $start_date ) );
118
+        }
119
+
120
+        for ( $i = 0; $i < $this->interval; $i++ ) {
121
+
122
+            switch ( $this->groupby ) {
123
+                case 'day':
124
+                    $time = gmdate( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) );
125
+                    break;
126
+                default:
127
+                    $time = gmdate( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) );
128
+                    break;
129
+            }
130
+
131
+            // Set the defaults for each period.
132
+            $period_totals[ $time ] = array(
133
+                'invoices'          => 0,
134
+                'items'             => 0,
135
+                'refunded_items'    => 0,
136
+                'refunded_tax'      => wpinv_round_amount( 0.00 ),
137
+                'subtotal'          => wpinv_round_amount( 0.00 ),
138
+                'refunded_subtotal' => wpinv_round_amount( 0.00 ),
139
+                'refunded_fees'     => wpinv_round_amount( 0.00 ),
140
+                'discount'          => wpinv_round_amount( 0.00 ),
141
+            );
142
+
143
+            foreach ( array_keys( wpinv_get_report_graphs() ) as $key ) {
144
+                if ( ! isset( $period_totals[ $time ][ $key ] ) ) {
145
+                    $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 );
146
+                }
147
+            }
148
+        }
149
+
150
+        // add total sales, total invoice count, total tax for each period
151
+        $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m';
152
+        foreach ( $report_data->invoices as $invoice ) {
153
+            $time = gmdate( $date_format, strtotime( $invoice->post_date ) );
154
+
155
+            if ( ! isset( $period_totals[ $time ] ) ) {
156
+                continue;
157
+            }
158
+
159
+            $period_totals[ $time ]['sales']    = wpinv_round_amount( $invoice->total_sales );
160
+            $period_totals[ $time ]['tax']      = wpinv_round_amount( $invoice->total_tax );
161
+            $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal );
162
+            $period_totals[ $time ]['fees']     = wpinv_round_amount( $invoice->total_fees );
163
+
164
+        }
165
+
166
+        foreach ( $report_data->refunds as $invoice ) {
167
+            $time = gmdate( $date_format, strtotime( $invoice->post_date ) );
168
+
169
+            if ( ! isset( $period_totals[ $time ] ) ) {
170
+                continue;
171
+            }
172
+
173
+            $period_totals[ $time ]['refunds']           = wpinv_round_amount( $invoice->total_sales );
174
+            $period_totals[ $time ]['refunded_tax']      = wpinv_round_amount( $invoice->total_tax );
175
+            $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal );
176
+            $period_totals[ $time ]['refunded_fees']     = wpinv_round_amount( $invoice->total_fees );
177
+
178
+        }
179
+
180
+        foreach ( $report_data->invoice_counts as $invoice ) {
181
+            $time = gmdate( $date_format, strtotime( $invoice->post_date ) );
182
+
183
+            if ( isset( $period_totals[ $time ] ) ) {
184
+                $period_totals[ $time ]['invoices']   = (int) $invoice->count;
185
+            }
186
+        }
187
+
188
+        // Add total invoice items for each period.
189
+        foreach ( $report_data->invoice_items as $invoice_item ) {
190
+            $time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : gmdate( 'Y-m', strtotime( $invoice_item->post_date ) );
191
+
192
+            if ( isset( $period_totals[ $time ] ) ) {
193
+                $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count;
194
+            }
195
+        }
196
+
197
+        // Add total discount for each period.
198
+        foreach ( $report_data->coupons as $discount ) {
199
+            $time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $discount->post_date ) ) : gmdate( 'Y-m', strtotime( $discount->post_date ) );
200
+
201
+            if ( isset( $period_totals[ $time ] ) ) {
202
+                $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount );
203
+            }
204
+        }
205
+
206
+        // Extra fields.
207
+        foreach ( array_keys( wpinv_get_report_graphs() ) as $key ) {
208
+
209
+            // Abort unprepared.
210
+            if ( ! isset( $report_data->$key ) ) {
211
+                continue;
212
+            } 
213
+
214
+            // Abort defaults.
215
+            if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) {
216
+                continue;
217
+            }
218
+
219
+            // Set values.
220
+            foreach ( $report_data->$key as $item ) {
221
+                $time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $item->date ) ) : gmdate( 'Y-m', strtotime( $item->date ) );
222
+
223
+                if ( isset( $period_totals[ $time ] ) ) {
224
+                    $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val );
225
+                }
226
+            }
227
+
228
+            unset( $report_data->$key );
229
+        }
230
+
231
+        $report_data->totals            = $period_totals;
232
+        $report_data->grouped_by        = $this->groupby;
233
+        $report_data->interval          = max( $this->interval, 1 );
234
+        $report_data->currency          = wpinv_get_currency();
235
+        $report_data->currency_symbol   = wpinv_currency_symbol();
236
+        $report_data->currency_position = wpinv_currency_position();
237
+        $report_data->decimal_places    = wpinv_decimals();
238
+        $report_data->thousands_sep     = wpinv_thousands_separator();
239
+        $report_data->decimals_sep      = wpinv_decimal_separator();
240
+        $report_data->start_date        = gmdate( 'Y-m-d', strtotime( $this->report_range['after'] ) );
241
+        $report_data->end_date          = gmdate( 'Y-m-d', strtotime( $this->report_range['before'] ) );
242
+        $report_data->start_date_locale = getpaid_format_date( gmdate( 'Y-m-d', strtotime( $this->report_range['after'] ) ) );
243
+        $report_data->end_date_locale   = getpaid_format_date( gmdate( 'Y-m-d', strtotime( $this->report_range['before'] ) ) );
244
+        $report_data->decimals_sep      = wpinv_decimal_separator();
245
+
246
+        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
247
+        $data    = $report_data;
248
+        unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items );
249
+        $data    = $this->add_additional_fields_to_object( (array) $data, $request );
250
+        $data    = $this->filter_response_by_context( $data, $context );
251
+
252
+        // Wrap the data in a response object.
253
+        $response = rest_ensure_response( $data );
254
+        $response->add_links(
255
+            array(
256
+                'about' => array(
257
+                    'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ),
258
+                ),
259
+            )
260
+        );
261
+
262
+        return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request );
263
+    }
264
+
265
+    /**
266
+     * Get report data.
267
+     *
268
+     * @return stdClass
269
+     */
270
+    public function get_report_data() {
271
+        if ( empty( $this->report_data ) ) {
272
+            $this->query_report_data();
273
+        }
274
+        return $this->report_data;
275
+    }
276
+
277
+    /**
278
+     * Get all data needed for this report and store in the class.
279
+     */
280
+    protected function query_report_data() {
281
+
282
+        // Prepare reports.
283
+        $this->report_data = (object) array(
284
+            'invoice_counts' => $this->query_invoice_counts(), //count, post_date
285
+            'coupons'        => $this->query_coupon_counts(), // discount_amount, post_date
286
+            'invoice_items'  => $this->query_item_counts(), // invoice_item_count, post_date
287
+            'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date
288
+            'invoices'       => $this->query_invoice_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date
289
+            'refunds'        => $this->query_refunded_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date
290
+            'previous_range' => $this->previous_range,
291
+        );
292
+
293
+        // Calculated totals.
294
+        $this->report_data->total_tax          = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) );
295
+        $this->report_data->total_sales        = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) );
296
+        $this->report_data->total_discount     = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) );
297
+        $this->report_data->total_fees         = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) );
298
+        $this->report_data->subtotal           = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) );
299
+        $this->report_data->net_sales          = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) );
300
+        $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) );
301
+        $this->report_data->total_refunds      = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) );
302
+        $this->report_data->refunded_discount  = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) );
303
+        $this->report_data->refunded_fees      = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) );
304
+        $this->report_data->refunded_subtotal  = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) );
305
+        $this->report_data->net_refunds        = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) );
306
+
307
+        // Calculate average based on net.
308
+        $this->report_data->average_sales       = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 );
309
+        $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 );
310
+
311
+        // Total invoices in this period, even if refunded.
312
+        $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) );
313
+
314
+        // Items invoiced in this period, even if refunded.
315
+        $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) );
316
+
317
+        // 3rd party filtering of report data
318
+        $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this );
319
+    }
320
+
321
+    /**
322
+     * Prepares invoice counts.
323
+     *
324
+     * @return array.
325
+     */
326
+    protected function query_invoice_counts() {
327
+
328
+        return (array) GetPaid_Reports_Helper::get_invoice_report_data(
329
+            array(
330
+                'data'           => array(
331
+                    'ID'        => array(
332
+                        'type'     => 'post_data',
333
+                        'function' => 'COUNT',
334
+                        'name'     => 'count',
335
+                        'distinct' => true,
336
+                    ),
337
+                    'post_date' => array(
338
+                        'type'     => 'post_data',
339
+                        'function' => 'MIN',
340
+                        'name'     => 'post_date',
341
+                    ),
342
+                ),
343
+                'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
344
+                'order_by'       => 'post_date ASC',
345
+                'query_type'     => 'get_results',
346
+                'filter_range'   => $this->report_range,
347
+                'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ),
348
+            )
349
+        );
350
+
351
+    }
352
+
353
+    /**
354
+     * Prepares coupon counts.
355
+     *
356
+     * @return array.
357
+     */
358
+    protected function query_coupon_counts() {
359
+
360
+        return (array) GetPaid_Reports_Helper::get_invoice_report_data(
361
+            array(
362
+                'data'           => array(
363
+                    'discount'  => array(
364
+                        'type'     => 'invoice_data',
365
+                        'function' => 'SUM',
366
+                        'name'     => 'discount_amount',
367
+                    ),
368
+                    'post_date' => array(
369
+                        'type'     => 'post_data',
370
+                        'function' => 'MIN',
371
+                        'name'     => 'post_date',
372
+                    ),
373
+                ),
374
+                'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
375
+                'order_by'       => 'post_date ASC',
376
+                'query_type'     => 'get_results',
377
+                'filter_range'   => $this->report_range,
378
+                'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ),
379
+            )
380
+        );
381
+
382
+    }
383
+
384
+    /**
385
+     * Prepares item counts.
386
+     *
387
+     * @return array.
388
+     */
389
+    protected function query_item_counts() {
390
+
391
+        return (array) GetPaid_Reports_Helper::get_invoice_report_data(
392
+            array(
393
+                'data'           => array(
394
+                    'quantity'  => array(
395
+                        'type'     => 'invoice_item',
396
+                        'function' => 'SUM',
397
+                        'name'     => 'invoice_item_count',
398
+                    ),
399
+                    'post_date' => array(
400
+                        'type'     => 'post_data',
401
+                        'function' => 'MIN',
402
+                        'name'     => 'post_date',
403
+                    ),
404
+                ),
405
+                'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
406
+                'order_by'       => 'post_date ASC',
407
+                'query_type'     => 'get_results',
408
+                'filter_range'   => $this->report_range,
409
+                'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ),
410
+            )
411
+        );
412
+
413
+    }
414
+
415
+    /**
416
+     * Prepares refunded item counts.
417
+     *
418
+     * @return array.
419
+     */
420
+    protected function count_refunded_items() {
421
+
422
+        return (int) GetPaid_Reports_Helper::get_invoice_report_data(
423
+            array(
424
+                'data'           => array(
425
+                    'quantity' => array(
426
+                        'type'     => 'invoice_item',
427
+                        'function' => 'SUM',
428
+                        'name'     => 'invoice_item_count',
429
+                    ),
430
+                ),
431
+                'query_type'     => 'get_var',
432
+                'filter_range'   => $this->report_range,
433
+                'invoice_status' => array( 'wpi-refunded' ),
434
+            )
435
+        );
436
+
437
+    }
438
+
439
+    /**
440
+     * Prepares daily invoice totals.
441
+     *
442
+     * @return array.
443
+     */
444
+    protected function query_invoice_totals() {
445
+
446
+        return (array) GetPaid_Reports_Helper::get_invoice_report_data(
447
+            array(
448
+                'data'           => array(
449
+                    'total'      => array(
450
+                        'type'     => 'invoice_data',
451
+                        'function' => 'SUM',
452
+                        'name'     => 'total_sales',
453
+                    ),
454
+                    'tax'        => array(
455
+                        'type'     => 'invoice_data',
456
+                        'function' => 'SUM',
457
+                        'name'     => 'total_tax',
458
+                    ),
459
+                    'discount'   => array(
460
+                        'type'     => 'invoice_data',
461
+                        'function' => 'SUM',
462
+                        'name'     => 'total_discount',
463
+                    ),
464
+                    'fees_total' => array(
465
+                        'type'     => 'invoice_data',
466
+                        'function' => 'SUM',
467
+                        'name'     => 'total_fees',
468
+                    ),
469
+                    'subtotal'   => array(
470
+                        'type'     => 'invoice_data',
471
+                        'function' => 'SUM',
472
+                        'name'     => 'subtotal',
473
+                    ),
474
+                    'post_date'  => array(
475
+                        'type'     => 'post_data',
476
+                        'function' => '',
477
+                        'name'     => 'post_date',
478
+                    ),
479
+                ),
480
+                'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
481
+                'order_by'       => 'post_date ASC',
482
+                'query_type'     => 'get_results',
483
+                'filter_range'   => $this->report_range,
484
+                'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ),
485
+            )
486
+        );
487
+
488
+    }
489
+
490
+    /**
491
+     * Prepares daily invoice totals.
492
+     *
493
+     * @return array.
494
+     */
495
+    protected function query_refunded_totals() {
496
+
497
+        return (array) GetPaid_Reports_Helper::get_invoice_report_data(
498
+            array(
499
+                'data'           => array(
500
+                    'total'      => array(
501
+                        'type'     => 'invoice_data',
502
+                        'function' => 'SUM',
503
+                        'name'     => 'total_sales',
504
+                    ),
505
+                    'tax'        => array(
506
+                        'type'     => 'invoice_data',
507
+                        'function' => 'SUM',
508
+                        'name'     => 'total_tax',
509
+                    ),
510
+                    'discount'   => array(
511
+                        'type'     => 'invoice_data',
512
+                        'function' => 'SUM',
513
+                        'name'     => 'total_discount',
514
+                    ),
515
+                    'fees_total' => array(
516
+                        'type'     => 'invoice_data',
517
+                        'function' => 'SUM',
518
+                        'name'     => 'total_fees',
519
+                    ),
520
+                    'subtotal'   => array(
521
+                        'type'     => 'invoice_data',
522
+                        'function' => 'SUM',
523
+                        'name'     => 'subtotal',
524
+                    ),
525
+                    'post_date'  => array(
526
+                        'type'     => 'post_data',
527
+                        'function' => '',
528
+                        'name'     => 'post_date',
529
+                    ),
530
+                ),
531
+                'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
532
+                'order_by'       => 'post_date ASC',
533
+                'query_type'     => 'get_results',
534
+                'filter_range'   => $this->report_range,
535
+                'invoice_status' => array( 'wpi-refunded' ),
536
+            )
537
+        );
538
+
539
+    }
540
+
541
+    /**
542
+     * Get the Report's schema, conforming to JSON Schema.
543
+     *
544
+     * @return array
545
+     */
546
+    public function get_item_schema() {
547
+
548
+        $schema = array(
549
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
550
+            'title'      => 'sales_report',
551
+            'type'       => 'object',
552
+            'properties' => array(
553
+                'total_sales'         => array(
554
+                    'description' => __( 'Gross sales in the period.', 'invoicing' ),
555
+                    'type'        => 'string',
556
+                    'context'     => array( 'view' ),
557
+                    'readonly'    => true,
558
+                ),
559
+                'net_sales'           => array(
560
+                    'description' => __( 'Net sales in the period.', 'invoicing' ),
561
+                    'type'        => 'string',
562
+                    'context'     => array( 'view' ),
563
+                    'readonly'    => true,
564
+                ),
565
+                'average_sales'       => array(
566
+                    'description' => __( 'Average net daily sales.', 'invoicing' ),
567
+                    'type'        => 'string',
568
+                    'context'     => array( 'view' ),
569
+                    'readonly'    => true,
570
+                ),
571
+                'average_total_sales' => array(
572
+                    'description' => __( 'Average gross daily sales.', 'invoicing' ),
573
+                    'type'        => 'string',
574
+                    'context'     => array( 'view' ),
575
+                    'readonly'    => true,
576
+                ),
577
+                'total_invoices'      => array(
578
+                    'description' => __( 'Number of paid invoices.', 'invoicing' ),
579
+                    'type'        => 'integer',
580
+                    'context'     => array( 'view' ),
581
+                    'readonly'    => true,
582
+                ),
583
+                'total_items'         => array(
584
+                    'description' => __( 'Number of items purchased.', 'invoicing' ),
585
+                    'type'        => 'integer',
586
+                    'context'     => array( 'view' ),
587
+                    'readonly'    => true,
588
+                ),
589
+                'refunded_items'      => array(
590
+                    'description' => __( 'Number of items refunded.', 'invoicing' ),
591
+                    'type'        => 'integer',
592
+                    'context'     => array( 'view' ),
593
+                    'readonly'    => true,
594
+                ),
595
+                'total_tax'           => array(
596
+                    'description' => __( 'Total charged for taxes.', 'invoicing' ),
597
+                    'type'        => 'string',
598
+                    'context'     => array( 'view' ),
599
+                    'readonly'    => true,
600
+                ),
601
+                'total_refunded_tax'  => array(
602
+                    'description' => __( 'Total refunded for taxes.', 'invoicing' ),
603
+                    'type'        => 'string',
604
+                    'context'     => array( 'view' ),
605
+                    'readonly'    => true,
606
+                ),
607
+                'total_fees'          => array(
608
+                    'description' => __( 'Total fees charged.', 'invoicing' ),
609
+                    'type'        => 'string',
610
+                    'context'     => array( 'view' ),
611
+                    'readonly'    => true,
612
+                ),
613
+                'total_refunds'       => array(
614
+                    'description' => __( 'Total of refunded invoices.', 'invoicing' ),
615
+                    'type'        => 'integer',
616
+                    'context'     => array( 'view' ),
617
+                    'readonly'    => true,
618
+                ),
619
+                'net_refunds'         => array(
620
+                    'description' => __( 'Net of refunded invoices.', 'invoicing' ),
621
+                    'type'        => 'integer',
622
+                    'context'     => array( 'view' ),
623
+                    'readonly'    => true,
624
+                ),
625
+                'total_discount'      => array(
626
+                    'description' => __( 'Total of discounts used.', 'invoicing' ),
627
+                    'type'        => 'integer',
628
+                    'context'     => array( 'view' ),
629
+                    'readonly'    => true,
630
+                ),
631
+                'totals'              => array(
632
+                    'description' => __( 'Totals.', 'invoicing' ),
633
+                    'type'        => 'array',
634
+                    'items'       => array(
635
+                        'type' => 'array',
636
+                    ),
637
+                    'context'     => array( 'view' ),
638
+                    'readonly'    => true,
639
+                ),
640
+                'interval'            => array(
641
+                    'description' => __( 'Number of months/days in the report period.', 'invoicing' ),
642
+                    'type'        => 'integer',
643
+                    'context'     => array( 'view' ),
644
+                    'readonly'    => true,
645
+                ),
646
+                'previous_range'      => array(
647
+                    'description' => __( 'The previous report period.', 'invoicing' ),
648
+                    'type'        => 'array',
649
+                    'items'       => array(
650
+                        'type' => 'string',
651
+                    ),
652
+                    'context'     => array( 'view' ),
653
+                    'readonly'    => true,
654
+                ),
655
+                'grouped_by'          => array(
656
+                    'description' => __( 'The period used to group the totals.', 'invoicing' ),
657
+                    'type'        => 'string',
658
+                    'context'     => array( 'view' ),
659
+                    'enum'        => array( 'day', 'month' ),
660
+                    'readonly'    => true,
661
+                ),
662
+                'currency'            => array(
663
+                    'description' => __( 'The default store currency.', 'invoicing' ),
664
+                    'type'        => 'string',
665
+                    'context'     => array( 'view' ),
666
+                    'readonly'    => true,
667
+                ),
668
+                'currency_symbol'     => array(
669
+                    'description' => __( 'The default store currency symbol.', 'invoicing' ),
670
+                    'type'        => 'string',
671
+                    'context'     => array( 'view' ),
672
+                    'readonly'    => true,
673
+                ),
674
+                'currency_position'   => array(
675
+                    'description' => __( 'The default store currency position.', 'invoicing' ),
676
+                    'type'        => 'string',
677
+                    'context'     => array( 'view' ),
678
+                    'readonly'    => true,
679
+                ),
680
+                'decimal_places'      => array(
681
+                    'description' => __( 'The default store decimal places.', 'invoicing' ),
682
+                    'type'        => 'string',
683
+                    'context'     => array( 'view' ),
684
+                    'readonly'    => true,
685
+                ),
686
+                'thousands_sep'       => array(
687
+                    'description' => __( 'The default store thousands separator.', 'invoicing' ),
688
+                    'type'        => 'string',
689
+                    'context'     => array( 'view' ),
690
+                    'readonly'    => true,
691
+                ),
692
+                'decimals_sep'        => array(
693
+                    'description' => __( 'The default store decimals separator.', 'invoicing' ),
694
+                    'type'        => 'string',
695
+                    'context'     => array( 'view' ),
696
+                    'readonly'    => true,
697
+                ),
698
+            ),
699
+        );
700
+
701
+        return $this->add_additional_fields_schema( $schema );
702
+
703
+    }
704 704
 
705 705
 }
Please login to merge, or discard this patch.