Stop User Enumeration - Version 1.3.17

Version Description

  • changed settings page to stop random metaboxes
Download this release

Release Info

Developer fullworks
Plugin Icon 128x128 Stop User Enumeration
Version 1.3.17
Comparing to
See all releases

Code changes from version 1.3.16 to 1.3.17

Files changed (77) hide show
  1. readme.txt +5 -1
  2. trunk/admin/class-admin-pages.php +263 -0
  3. trunk/admin/class-admin-settings.php +210 -0
  4. trunk/admin/class-admin.php +60 -0
  5. trunk/admin/class-settings.php +137 -0
  6. trunk/admin/index.php +1 -0
  7. trunk/bootstrap.php +43 -0
  8. trunk/composer.json +32 -0
  9. trunk/fail2ban/filter.d/wordpress-userenum.conf +26 -0
  10. trunk/fail2ban/index.php +1 -0
  11. trunk/fail2ban/jail.local +12 -0
  12. trunk/frontend/class-frontend.php +98 -0
  13. trunk/frontend/index.php +1 -0
  14. trunk/frontend/js/frontend.js +10 -0
  15. trunk/gnugeneralpubliclicence.txt +87 -0
  16. trunk/includes/autoloader.php +63 -0
  17. trunk/includes/class-activator.php +39 -0
  18. trunk/includes/class-core.php +205 -0
  19. trunk/includes/class-freemius-config.php +43 -0
  20. trunk/includes/class-i18n.php +45 -0
  21. trunk/includes/class-loader.php +97 -0
  22. trunk/includes/class-uninstall.php +26 -0
  23. trunk/includes/index.php +1 -0
  24. trunk/includes/vendor/freemius/wordpress-sdk/LICENSE.txt +674 -0
  25. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/account.css +1 -0
  26. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/add-ons.css +2 -0
  27. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/affiliation.css +1 -0
  28. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/checkout.css +1 -0
  29. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/common.css +2 -0
  30. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/connect.css +1 -0
  31. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/deactivation-feedback.css +1 -0
  32. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/debug.css +1 -0
  33. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/dialog-boxes.css +2 -0
  34. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/gdpr-optin-notice.css +1 -0
  35. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/index.php +3 -0
  36. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/license-activation.css +1 -0
  37. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/customizer.css +1 -0
  38. trunk/includes/vendor/freemius/wordpress-sdk/assets/css/index.php +3 -0
  39. trunk/includes/vendor/freemius/wordpress-sdk/assets/img/index.php +3 -0
  40. trunk/includes/vendor/freemius/wordpress-sdk/assets/img/plugin-icon.png +0 -0
  41. trunk/includes/vendor/freemius/wordpress-sdk/assets/img/theme-icon.png +0 -0
  42. trunk/includes/vendor/freemius/wordpress-sdk/assets/index.php +3 -0
  43. trunk/includes/vendor/freemius/wordpress-sdk/assets/js/index.php +3 -0
  44. trunk/includes/vendor/freemius/wordpress-sdk/assets/js/nojquery.ba-postmessage.js +140 -0
  45. trunk/includes/vendor/freemius/wordpress-sdk/assets/js/nojquery.ba-postmessage.min.js +12 -0
  46. trunk/includes/vendor/freemius/wordpress-sdk/assets/js/postmessage.js +135 -0
  47. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_colors.scss +68 -0
  48. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_functions.scss +0 -0
  49. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_load.scss +4 -0
  50. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_mixins.scss +270 -0
  51. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_start.scss +4 -0
  52. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_vars.scss +6 -0
  53. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_ajax-loader.scss +49 -0
  54. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_auto-install.scss +33 -0
  55. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_deactivation-feedback.scss +55 -0
  56. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_gdpr-consent.scss +81 -0
  57. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_license-activation.scss +47 -0
  58. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_license-key-resend.scss +68 -0
  59. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_modal-common.scss +194 -0
  60. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_multisite-options.scss +40 -0
  61. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_themes.scss +21 -0
  62. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_tooltip.scss +66 -0
  63. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/account.scss +302 -0
  64. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/add-ons.scss +449 -0
  65. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/affiliation.scss +97 -0
  66. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/checkout.scss +5 -0
  67. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/common.scss +218 -0
  68. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/connect.scss +548 -0
  69. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/debug.scss +135 -0
  70. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/dialog-boxes.scss +8 -0
  71. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/gdpr-optin-notice.scss +17 -0
  72. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/index.php +3 -0
  73. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/customizer.scss +125 -0
  74. trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/index.php +3 -0
  75. trunk/includes/vendor/freemius/wordpress-sdk/config.php +388 -0
  76. trunk/includes/vendor/freemius/wordpress-sdk/includes/class-freemius-abstract.php +597 -0
  77. trunk/includes/vendor/freemius/wordpress-sdk/includes/class-freemius.php +20158 -0
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: User Enumeration, Security, WPSCAN, fail2ban,
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4EMTVFMKXRRYY
5
  Requires at least: 3.4
6
  Requires PHP: 5.3
7
- Tested up to: 4.8.3
8
  Stable tag: 1.3.16
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -24,6 +24,8 @@ If you don't have access to install fail2ban ( e.g. on a Shared Host ) you can s
24
  Since WordPress 4.5 user data can also be obtained by API calls without logging in, this is a WordPress feature, but if you don't need it to get user data, this
25
  plugin will restrict and log that too.
26
 
 
 
27
 
28
  == Installation ==
29
 
@@ -120,3 +122,5 @@ Fix PHP error
120
  * Added code to remove numbers from comment authors, and setting to turn that off
121
 
122
 
 
 
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4EMTVFMKXRRYY
5
  Requires at least: 3.4
6
  Requires PHP: 5.3
7
+ Tested up to: 4.9.8
8
  Stable tag: 1.3.16
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
24
  Since WordPress 4.5 user data can also be obtained by API calls without logging in, this is a WordPress feature, but if you don't need it to get user data, this
25
  plugin will restrict and log that too.
26
 
27
+ [](http://coderisk.com/wp/plugin/stop-user-enumeration/RIPS-1o0cni0Kbq)
28
+
29
 
30
  == Installation ==
31
 
122
  * Added code to remove numbers from comment authors, and setting to turn that off
123
 
124
 
125
+
126
+
trunk/admin/class-admin-pages.php ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ namespace Stop_User_Enumeration\Admin;
5
+
6
+
7
+ /**
8
+ * Class Settings
9
+ * @package Stop_User_Enumeration\Admin
10
+ */
11
+ class Admin_Pages {
12
+
13
+ public $block_table_obj;
14
+ protected $settings_page; // toplevel appearance etc followed by slug
15
+
16
+
17
+ // for the block report
18
+ protected $settings_page_id = 'settings_page_stop-user-enumeration';
19
+
20
+ //
21
+ protected $settings_title;
22
+
23
+ protected $plugin_name;
24
+ protected $version;
25
+ protected $freemius;
26
+
27
+
28
+ public function __construct() {
29
+
30
+
31
+ }
32
+
33
+
34
+ public static function set_screen( $status, $option, $value ) {
35
+ return $value;
36
+ }
37
+
38
+ public function settings_setup() {
39
+
40
+ /* top level
41
+ add_menu_page(
42
+ $this->settings_title, // Page Title
43
+ $this->settings_title, // Menu Title
44
+ 'manage_options', // Capability
45
+ 'stop-user-enumeration', // Page Slug
46
+ array( $this, 'settings_page' ), // Settings Page Function Callback
47
+ 'dashicons-shield', // Menu Icon
48
+ 70 // Menu Position
49
+ );
50
+ */
51
+ /* Add settings menu page */
52
+ add_submenu_page(
53
+ 'options-general.php',
54
+ $this->settings_title, /* Page Title */
55
+ $this->settings_title, /* Menu Title */
56
+ 'manage_options', /* Capability */
57
+ 'stop-user-enumeration', /* Page Slug */
58
+ array( $this, 'settings_page' ) /* Settings Page Function Callback */
59
+ );
60
+
61
+ $this->register_settings();
62
+
63
+
64
+ /* Vars */
65
+ $page_hook_id = $this->settings_page_id;
66
+
67
+ /* Do stuff in settings page, such as adding scripts, etc. */
68
+ if ( ! empty( $this->settings_page ) ) {
69
+ /* Load the JavaScript needed for the settings screen. */
70
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
71
+ add_action( "admin_footer-{$page_hook_id}", array( $this, 'footer_scripts' ) );
72
+ /* Set number of column available. */
73
+ add_filter( 'screen_layout_columns', array( $this, 'screen_layout_column' ), 10, 2 );
74
+ add_action( $this->settings_page_id . '_settings_page_boxes', array( $this, 'add_required_meta_boxes' ) );
75
+ }
76
+ }
77
+
78
+ public function register_settings() {
79
+ // overide in extended class
80
+ }
81
+
82
+ public function enqueue_scripts( $hook_suffix ) {
83
+ $page_hook_id = $this->settings_page_id;
84
+ if ( $hook_suffix == $page_hook_id ) {
85
+ wp_enqueue_script( 'common' );
86
+ wp_enqueue_script( 'wp-lists' );
87
+ wp_enqueue_script( 'postbox' );
88
+ }
89
+ }
90
+
91
+ public function footer_scripts() {
92
+ $page_hook_id = $this->settings_page_id;
93
+ //@ TODO think about localize and enqueue
94
+ ?>
95
+ <script type="text/javascript">
96
+ //<![CDATA[
97
+ jQuery(document).ready(function ($) {
98
+ // toggle
99
+ $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
100
+ postboxes.add_postbox_toggles('<?php echo $page_hook_id; ?>');
101
+ // display spinner
102
+ $('#fx-smb-form').submit(function () {
103
+ $('#publishing-action .spinner').css('visibility', 'visible');
104
+ });
105
+ // confirm before reset
106
+ $('#delete-action input').on('click', function () {
107
+ return confirm('Are you sure want to do this?');
108
+ });
109
+ });
110
+ //]]>
111
+ </script>
112
+ <?php
113
+ }
114
+
115
+ public function screen_layout_column( $columns, $screen ) {
116
+ $page_hook_id = $this->settings_page_id;
117
+ if ( $screen == $page_hook_id ) {
118
+ $columns[ $page_hook_id ] = 2;
119
+ }
120
+
121
+ return $columns;
122
+ }
123
+
124
+ /**
125
+ *
126
+ */
127
+ public function settings_page() {
128
+
129
+ /* global vars */
130
+ global $hook_suffix;
131
+ if ( $this->settings_page_id == $hook_suffix ) {
132
+
133
+
134
+ /* enable add_meta_boxes function in this page. */
135
+ do_action( $this->settings_page_id . '_settings_page_boxes', $hook_suffix );
136
+ ?>
137
+
138
+ <div class="wrap">
139
+
140
+ <h2><?php echo $this->settings_title; ?></h2>
141
+
142
+ <?php
143
+ global $pagenow;
144
+ if ( $pagenow !== "options-general.php" ) {
145
+ settings_errors();
146
+ } ?>
147
+
148
+ <div class="fs-settings-meta-box-wrap">
149
+
150
+ <form id="fs-smb-form" method="post" action="options.php">
151
+
152
+ <?php settings_fields( $this->option_group ); // options group
153
+ ?>
154
+ <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
155
+ <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
156
+
157
+ <div id="poststuff">
158
+
159
+ <div id="post-body"
160
+ class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
161
+
162
+ <div id="postbox-container-1" class="postbox-container">
163
+
164
+ <?php do_meta_boxes( $hook_suffix, 'side', null ); ?>
165
+ <!-- #side-sortables -->
166
+
167
+ </div><!-- #postbox-container-1 -->
168
+
169
+ <div id="postbox-container-2" class="postbox-container">
170
+
171
+ <?php do_meta_boxes( $hook_suffix, 'normal', null ); ?>
172
+ <!-- #normal-sortables -->
173
+
174
+ <?php do_meta_boxes( $hook_suffix, 'advanced', null ); ?>
175
+ <!-- #advanced-sortables -->
176
+
177
+ </div><!-- #postbox-container-2 -->
178
+
179
+ </div><!-- #post-body -->
180
+
181
+ <br class="clear">
182
+
183
+ </div><!-- #poststuff -->
184
+
185
+ </form>
186
+
187
+ </div><!-- .fs-settings-meta-box-wrap -->
188
+
189
+ </div><!-- .wrap -->
190
+ <?php
191
+ }
192
+
193
+ }
194
+
195
+ public function add_required_meta_boxes() {
196
+ global $hook_suffix;
197
+
198
+ if ( $this->settings_page_id == $hook_suffix ) {
199
+
200
+ $this->add_meta_boxes();
201
+
202
+ add_meta_box(
203
+ 'submitdiv', /* Meta Box ID */
204
+ __( 'Save Options', 'stop-user-enumeration' ), /* Title */
205
+ array( $this, 'submit_meta_box' ), /* Function Callback */
206
+ $this->settings_page_id, /* Screen: Our Settings Page */
207
+ 'side', /* Context */
208
+ 'high' /* Priority */
209
+ );
210
+ }
211
+ }
212
+
213
+ public function add_meta_boxes() {
214
+ // in extended class
215
+ }
216
+
217
+ public function submit_meta_box() {
218
+
219
+ ?>
220
+ <div id="submitpost" class="submitbox">
221
+
222
+ <div id="major-publishing-actions">
223
+
224
+ <div id="delete-action">
225
+ <input type="submit" name="<?php echo "{$this->option_group}-reset"; ?>"
226
+ id="<?php echo "{$this->option_group}-reset"; ?>"
227
+ class="button"
228
+ value="Reset Settings">
229
+ </div><!-- #delete-action -->
230
+
231
+ <div id="publishing-action">
232
+ <span class="spinner"></span>
233
+ <?php submit_button( esc_attr__( 'Save', 'stop-user-enumeration' ), 'primary', 'submit', false ); ?>
234
+ </div>
235
+
236
+ <div class="clear"></div>
237
+
238
+ </div><!-- #major-publishing-actions -->
239
+
240
+ </div><!-- #submitpost -->
241
+
242
+ <?php
243
+ }
244
+
245
+ public function reset_sanitize( $settings ) {
246
+ /* Add Update Notice */
247
+
248
+ if ( ! empty( $settings ) ) {
249
+ add_settings_error( $this->option_group, '', esc_html__( 'Settings reset to defaults.', 'stop-user-enumeration' ), 'updated' );
250
+ /* Delete Option */
251
+ $this->delete_options();
252
+
253
+ }
254
+
255
+ return $settings;
256
+ }
257
+
258
+ public function delete_options() {
259
+ // for extended class to manage
260
+ }
261
+
262
+
263
+ }
trunk/admin/class-admin-settings.php ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created
4
+ * User: alan
5
+ * Date: 04/04/18
6
+ * Time: 13:45
7
+ */
8
+
9
+ namespace Stop_User_Enumeration\Admin;
10
+
11
+
12
+ class Admin_Settings extends Admin_Pages {
13
+
14
+ protected $settings_page;
15
+ // protected $settings_page_id = 'toplevel_page_stop-user-enumeration'; // top level
16
+ protected $settings_page_id = 'settings_page_stop-user-enumeration';
17
+ protected $option_group = 'stop-user-enumeration';
18
+ protected $settings_title;
19
+
20
+ /**
21
+ * Settings constructor.
22
+ *
23
+ * @param string $plugin_name
24
+ * @param string $version plugin version.
25
+ * @param \Freemius $freemius Freemius SDK.
26
+ */
27
+
28
+ public function __construct( $plugin_name, $version, $freemius ) {
29
+ $this->plugin_name = $plugin_name;
30
+ $this->version = $version;
31
+ $this->freemius = $freemius;
32
+
33
+
34
+ $this->settings_title = esc_html__( 'Stop User Enumeration Settings', 'stop-user-enumeration' );
35
+ parent::__construct();
36
+ }
37
+
38
+ public function register_settings() {
39
+ /* Register our setting. */
40
+ register_setting(
41
+ $this->option_group, /* Option Group */
42
+ 'stop-user-enumeration', /* Option Name */
43
+ array( $this, 'sanitize_settings' ) /* Sanitize Callback */
44
+ );
45
+
46
+
47
+ /* Add settings menu page */
48
+ $this->settings_page = add_submenu_page(
49
+ 'stop-user-enumeration',
50
+ 'Settings', /* Page Title */
51
+ 'Settings', /* Menu Title */
52
+ 'manage_options', /* Capability */
53
+ 'stop-user-enumeration', /* Page Slug */
54
+ array( $this, 'settings_page' ) /* Settings Page Function Callback */
55
+ );
56
+
57
+ register_setting(
58
+ $this->option_group, /* Option Group */
59
+ "{$this->option_group}-reset", /* Option Name */
60
+ array( $this, 'reset_sanitize' ) /* Sanitize Callback */
61
+ );
62
+
63
+ }
64
+
65
+
66
+ public function delete_options() {
67
+ update_option( 'stop-user-enumeration', self::option_defaults( 'stop-user-enumeration' ) );
68
+
69
+ }
70
+
71
+ public static function option_defaults( $option ) {
72
+ switch ( $option ) {
73
+ case 'stop-user-enumeration':
74
+ return array(
75
+ // set defaults
76
+ 'stop_rest_user' => 'on',
77
+ 'log_auth' => 'on',
78
+ 'comment_jquery' => 'on',
79
+ );
80
+ default:
81
+ return false;
82
+ }
83
+ }
84
+
85
+ public function add_meta_boxes() {
86
+ add_meta_box(
87
+ 'settings-1', /* Meta Box ID */
88
+ esc_html__( 'Information', 'stop-user-enumeration' ), /* Title */
89
+ array( $this, 'meta_box_information' ), /* Function Callback */
90
+ $this->settings_page_id, /* Screen: Our Settings Page */
91
+ 'normal', /* Context */
92
+ 'default' /* Priority */
93
+ );
94
+ add_meta_box(
95
+ 'settings-2', /* Meta Box ID */
96
+ __( 'Options', 'stop-user-enumeration' ), /* Title */
97
+ array( $this, 'meta_box_options' ), /* Function Callback */
98
+ $this->settings_page_id, /* Screen: Our Settings Page */
99
+ 'normal', /* Context */
100
+ 'default' /* Priority */
101
+ );
102
+
103
+
104
+ }
105
+
106
+ public function meta_box_information() {
107
+ ?>
108
+ <table class="form-table">
109
+ <tbody>
110
+ <tr valign="top" class="alternate">
111
+ <th scope="row"><?php _e( 'About this Plugin', 'stop-user-enumeration' ); ?></th>
112
+ <td>
113
+ <?php _e( '<p>Stop User Enumeration detects attempts by malicious scanners to identify your users</p>
114
+ <p>If a bot or user is caught scanning for user names they are denied access and their IP is
115
+ logged</p>
116
+ <p>When you are viewing an admin page, the plugin does nothing, this is designed this way as it is
117
+ assumed admin user have authority, bear this in mind when testing.</p><br>
118
+ <p>This plugin is best used in conjunction with a blocking tool to exclude the IP for longer. If you
119
+ are on a VPS or dedicated server where you have root access you can install and configure <a
120
+ href="https://www.fail2ban.org" target="_blank">fail2ban</a> or if you are on a shared
121
+ host you can install
122
+ <a href="https://wordpress.org/plugins/fullworks-firewall/" target="_blank">Fullworks
123
+ Firewall</a> which does a very similar job, but requires no configuration to work
124
+ automatically with Stop User Enumeration</a></p>', 'stop-user-enumeration' ); ?>
125
+ </td>
126
+ </tr>
127
+ </tbody>
128
+ </table>
129
+ <?php
130
+ }
131
+
132
+ public function sanitize_settings( $settings ) {
133
+ if ( ! isset( $settings['stop_rest_user'] ) ) {
134
+ $settings['stop_rest_user'] = 'off'; // always set checkboxes if they dont exist
135
+ }
136
+ if ( ! isset( $settings['log_auth'] ) ) {
137
+ $settings['log_auth'] = 'off'; // always set checkboxes if they dont exist
138
+ }
139
+ if ( ! isset( $settings['comment_jquery'] ) ) {
140
+ $settings['comment_jquery'] = 'off'; // always set checkboxes if they dont exist
141
+ }
142
+
143
+ return $settings;
144
+ }
145
+
146
+
147
+ public function meta_box_options() {
148
+ ?>
149
+ <?php
150
+ $options = get_option( 'stop-user-enumeration' );
151
+ if ( ! isset( $options['stop_rest_user'] ) ) {
152
+ $options['stop_rest_user'] = 'off';
153
+ }
154
+ if ( ! isset( $options['log_auth'] ) ) {
155
+ $options['log_auth'] = 'off';
156
+ }
157
+ if ( ! isset( $options['comment_jquery'] ) ) {
158
+ $options['comment_jquery'] = 'off';
159
+ }
160
+ ?>
161
+ <table class="form-table">
162
+ <tbody>
163
+ <tr valign="top">
164
+ <th scope="row"><?php esc_html_e( 'Stop REST API User calls', 'stop-user-enumeration' ); ?></th>
165
+ <td>
166
+ <label for="stop-user-enumeration[stop_rest_user]"><input type="checkbox"
167
+ name="stop-user-enumeration[stop_rest_user]]"
168
+ id="stop-user-enumeration[stop_rest_user]"
169
+ value="on"
170
+ <?php checked( 'on', $options['stop_rest_user'] ); ?>>
171
+ <?php _e( 'WordPress allows anyone to find users by API call, by checking this box the calls will be restricted to logged in users only. Only untick this box if you need to allow unfettered API access to users', 'stop-user-enumeration' ); ?>
172
+ </label>
173
+ </td>
174
+ </tr>
175
+ <tr valign="top" class="alternate">
176
+ <th scope="row"><?php esc_html_e( 'log attempts to AUTH LOG', 'stop-user-enumeration' ); ?></th>
177
+ <td>
178
+ <label for="stop-user-enumeration[log_auth]"><input type="checkbox"
179
+ name="stop-user-enumeration[log_auth]]"
180
+ id="stop-user-enumeration[log_auth]"
181
+ value="on"
182
+ <?php checked( 'on', $options['log_auth'] ); ?>>
183
+ <?php printf( esc_html__( 'Leave this ticked if you are using %1$sFail2Ban%2$s on your VPS to block attempts at enumeration.%3$s If you are not running Fail2Ban or on a shared host this does not need to be ticked, however it normally will not cause a problem being ticked.'
184
+ , 'stop-user-enumeration' ),
185
+ '<a href="http://www.fail2ban.org/wiki/index.php/Main_Page" target="_blank">', '</a>', '<br>' ); ?>
186
+ </label>
187
+ </td>
188
+ </tr>
189
+ <tr valign="top">
190
+ <th scope="row"><?php esc_html_e( 'Remove numbers from comment authors', 'stop-user-enumeration' ); ?></th>
191
+ <td>
192
+ <label for="stop-user-enumeration[comment_jquery]"><input type="checkbox"
193
+ name="stop-user-enumeration[comment_jquery]]"
194
+ id="stop-user-enumeration[comment_jquery]"
195
+ value="on"
196
+ <?php checked( 'on', $options['comment_jquery'] ); ?>>
197
+ <?php esc_html_e( 'This plugin uses jQuery to remove any numbers from a comment author name, this is because numbers trigger enumeration checking. You can untick this if you do not use comments on your site or you use a different comment method than standard',
198
+ 'stop-user-enumeration' ); ?></label>
199
+ </td>
200
+ </tr>
201
+
202
+
203
+ </tbody>
204
+ </table>
205
+ <?php
206
+ }
207
+
208
+
209
+ }
210
+
trunk/admin/class-admin.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * The admin-specific functionality of the plugin.
6
+ *
7
+ * Defines the plugin name, version, and two examples hooks for how to
8
+ * enqueue the admin-specific stylesheet and JavaScript.
9
+ *
10
+ */
11
+
12
+ namespace Stop_User_Enumeration\Admin;
13
+
14
+
15
+ class Admin {
16
+
17
+ /**
18
+ * The ID of this plugin.
19
+ *
20
+ */
21
+ private $plugin_name;
22
+
23
+ /**
24
+ * The version of this plugin.
25
+ *
26
+ */
27
+ private $version;
28
+
29
+ /**
30
+ * Initialize the class and set its properties.
31
+ *
32
+ */
33
+ public function __construct( $plugin_name, $version ) {
34
+
35
+ $this->plugin_name = $plugin_name;
36
+ $this->version = $version;
37
+
38
+ }
39
+
40
+
41
+ public function connect_message(
42
+ $message,
43
+ $user_first_name,
44
+ $plugin_title,
45
+ $user_login,
46
+ $site_link,
47
+ $freemius_link
48
+ ) {
49
+ return sprintf(
50
+ __( 'Hi %1$s' ) . ',<br>' .
51
+ __( 'Never miss an important update -- opt-in to our security and feature updates notifications related to %2$s, and non-sensitive diagnostic tracking to help me improve %2$s sent via %5$s', 'plugin-name' ),
52
+ $user_first_name,
53
+ '<b>' . $plugin_title . '</b>',
54
+ '<b>' . $user_login . '</b>',
55
+ $site_link,
56
+ $freemius_link
57
+ );
58
+ }
59
+
60
+ }
trunk/admin/class-settings.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created
4
+ * User: alan
5
+ * Date: 09/11/17
6
+ * Time: 15:12
7
+ */
8
+
9
+ namespace Stop_User_Enumeration\Admin;
10
+
11
+
12
+ use CMB2_Tabs;
13
+
14
+
15
+ class Settings {
16
+
17
+ private $options_key = 'stop-user-enumeration';
18
+ private $msg;
19
+
20
+ public function __construct( $plugin_name, $version, $freemiusSDK ) {
21
+
22
+
23
+ $this->plugin_name = $plugin_name;
24
+ $this->version = $version;
25
+ $this->freemiusSDK = $freemiusSDK;
26
+ // Init CMB2 ( consider if needed elsewhere )
27
+ require_once( STOP_USER_ENUMERATION_PLUGIN_DIR . 'includes/vendor/cmb2/init.php' );
28
+ require_once( STOP_USER_ENUMERATION_PLUGIN_DIR . 'includes/vendor/cmb2-extensions/cmb2-tabs/cmb2-tabs.php' );
29
+
30
+
31
+ }
32
+
33
+ public function register_settings() {
34
+
35
+ /**
36
+ * Registers options page menu item and form.
37
+ */
38
+
39
+
40
+ $options = array(
41
+ 'id' => 'stop-user-enumeration_option_metabox',
42
+ 'title' => esc_html__( 'Stop User Enumeration', 'stop-user-enumeration' ),
43
+ 'tabs' => array(
44
+ 'info' => array(
45
+ 'label' => __( 'info', 'stop-user-enumeration' ),
46
+ 'icon' => 'dashicons-info',
47
+ ),
48
+ 'settings' => array(
49
+ 'label' => __( 'Settings', 'stop-user-enumeration' ),
50
+ 'icon' => 'dashicons-admin-generic',
51
+ ),
52
+ ),
53
+ "tab_style" => "default",
54
+ 'object_types' => array( 'options-page' ),
55
+ /*
56
+ * The following parameters are specific to the options-page box
57
+ * Several of these parameters are passed along to add_menu_page()/add_submenu_page().
58
+ */
59
+ 'option_key' => $this->options_key,
60
+ // The option key and admin menu page slug.
61
+ // 'icon_url' => 'dashicons-shield',
62
+ // Menu icon. Only applicable if 'parent_slug' is left empty.
63
+ // 'menu_title' => esc_html__( 'Options', 'myprefix' ), // Falls back to 'title' (above).
64
+ 'parent_slug' => 'options-general.php',
65
+ // Make options page a submenu item of the themes menu.
66
+ // 'capability' => 'manage_options', // Cap required to view options-page.
67
+ // 'position' => 1, // Menu position. Only applicable if 'parent_slug' is left empty.
68
+ // 'admin_menu_hook' => 'network_admin_menu', // 'network_admin_menu' to add network-level options page.
69
+ // 'display_cb' => false, // Override the options-page form output (CMB2_Hookup::options_page_output()).
70
+ // 'save_button' => esc_html__( 'Save Theme Options', 'myprefix' ), // The text for the options-page save button. Defaults to 'Save'.
71
+
72
+ );
73
+
74
+
75
+ $cmb_options = new_cmb2_box( $options );
76
+ /*
77
+ * Options fields ids only need
78
+ * to be unique within this box.
79
+ * Prefix is not needed.
80
+ */
81
+
82
+
83
+ $cmb_options->add_field( array(
84
+
85
+ 'before' => '<h2>Information</h2>',
86
+ 'after_field' => __( '<p>Stop User Enumeration detects attempts by malicious scanners to identify your users</p>
87
+ <p>If a bot or user is caught scanning for user names they are denied access and their IP is logged</p>
88
+ <p>When you are viewing an admin page, the plugin does nothing, this is designed this way as it is assumed admin user have authority, bear this in mind when testing.</p><br>
89
+ <p>This plugin is best used in conjunction with a blocking tool to exclude the IP for longer. If you are on a VPS or dedicated server where you have root access you can install and configure <a href="https://www.fail2ban.org" target="_blank">fail2ban</a> or if you are on a shared host you can install <a href="https://wordpress.org/plugins/fullworks-firewall/" target="_blank">Fullworks Firewall</a> which does a very similar job, but requires no configuration to work automatically with Stop User Enumeration</a></p>', 'stop-user-enumeration' ),
90
+ 'id' => 'info_text',
91
+ 'type' => 'title',
92
+ 'tab' => 'info',
93
+ 'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
94
+ ) );
95
+
96
+ $cmb_options->add_field( array(
97
+ 'name' => esc_html__( 'Stop REST API User calls', 'stop-user-enumeration' ),
98
+ 'desc' => esc_html__( 'WordPress allows anyone to find users by API call, by checking this box the calls will be restricted to logged in users only. Only untick this box if you need to allow unfettered API access to users', 'stop-user-enumeration' ),
99
+ 'id' => 'stop_rest_user',
100
+ 'type' => 'checkbox',
101
+ 'default' => $this->set_default_checkbox( true ),
102
+ 'tab' => 'settings',
103
+ 'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
104
+ ) );
105
+
106
+ $cmb_options->add_field( array(
107
+ 'name' => esc_html__( 'log attempts to AUTH LOG', 'stop-user-enumeration' ),
108
+ 'desc' => sprintf( esc_html__( 'Leave this ticked if you are using %1$sFail2Ban%2$s on your VPS to block attempts at enumeration.%3$s If you are not running Fail2Ban or on a shared host this does not need to be ticked, however it normally will not cause a problem being ticked.'
109
+ , 'stop-user-enumeration' ),
110
+ '<a href="http://www.fail2ban.org/wiki/index.php/Main_Page" target="_blank">', '</a>', '<br>' ),
111
+ 'id' => 'log_auth',
112
+ 'type' => 'checkbox',
113
+ 'default' => $this->set_default_checkbox( true ),
114
+ 'tab' => 'settings',
115
+ 'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
116
+ ) );
117
+
118
+ $cmb_options->add_field( array(
119
+ 'name' => esc_html__( 'Remove numbers from comment authors', 'stop-user-enumeration' ),
120
+ 'desc' => esc_html__( 'This plugin uses jQuery to remove any numbers from a comment author name, this is because numbers trigger enumeration checking. You can untick this if you do not use comments on your site or you use a different comment method than standard',
121
+ 'stop-user-enumeration' ),
122
+ 'id' => 'comment_jquery',
123
+ 'type' => 'checkbox',
124
+ 'default' => $this->set_default_checkbox( true ),
125
+ 'tab' => 'settings',
126
+ 'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
127
+ ) );
128
+
129
+ }
130
+
131
+ private function set_default_checkbox( $default ) {
132
+ // only return true if the option has never been set
133
+ return get_option( $this->options_key, false ) ? '' : ( $default ? (string) $default : '' );
134
+ }
135
+
136
+
137
+ }
trunk/admin/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
trunk/bootstrap.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ namespace Stop_User_Enumeration;
5
+ // @TODO options for xforwarded
6
+
7
+ // If this file is called directly, abort.
8
+ if ( ! defined( 'WPINC' ) ) {
9
+ die;
10
+ }
11
+ define( 'STOP_USER_ENUMERATION_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
12
+ define( 'STOP_USER_ENUMERATION_PLUGIN_VERSION', '1.3.15' );
13
+
14
+ // Include the autoloader so we can dynamically include the classes.
15
+ require_once( STOP_USER_ENUMERATION_PLUGIN_DIR . 'includes/autoloader.php' );
16
+
17
+
18
+ function run_stop_user_enumeration() {
19
+ /**
20
+ * Load freemius SDK
21
+ */
22
+ $freemius = new \Stop_User_Enumeration\Includes\Freemius_Config();
23
+ $freemiusSDK = $freemius->init();
24
+ // Signal that SDK was initiated.
25
+ do_action( 'sue_fs_loaded' );
26
+
27
+
28
+ $freemiusSDK->add_action( 'after_uninstall', array( '\Stop_User_Enumeration\Includes\Uninstall', 'uninstall' ) );
29
+
30
+ /**
31
+ * The core plugin class that is used to define internationalization,
32
+ * admin-specific hooks, and public-facing site hooks.
33
+ */
34
+
35
+ $plugin = new \Stop_User_Enumeration\Includes\Core( $freemiusSDK );
36
+ $plugin->run();
37
+
38
+ }
39
+
40
+ run_stop_user_enumeration();
41
+
42
+
43
+ ?>
trunk/composer.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "fullworks/stop-user-enumeration",
3
+ "description": "Wordpress plugin to detect user enumeration attempts",
4
+ "type": "wordpress-plugin",
5
+ "license": "GPL",
6
+ "authors": [
7
+ {
8
+ "name": "alan",
9
+ "email": "alan@fullworks.net"
10
+ }
11
+ ],
12
+ "minimum-stability": "stable",
13
+ "config": {
14
+ "vendor-dir": "includes/vendor"
15
+ },
16
+
17
+ "require": {
18
+ "php": ">=5.3.0",
19
+ "composer/installers": "v1.0.12",
20
+ "webdevstudios/cmb2": "*",
21
+ "stackadroit/cmb2-extensions": "dev-master",
22
+ "freemius/wordpress-sdk": "dev-master"
23
+ },
24
+ "extra": {
25
+ "installer-paths": {
26
+ "includes/vendor/{$name}/": [
27
+ "webdevstudios/cmb2",
28
+ "stackadroit/cmb2-extensions"
29
+ ]
30
+ }
31
+ }
32
+ }
trunk/fail2ban/filter.d/wordpress-userenum.conf ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [INCLUDES]
2
+
3
+ # Read common prefixes. If any customizations available -- read them from
4
+ # common.local
5
+ before = common.conf
6
+
7
+
8
+ [Definition]
9
+
10
+ _daemon = wordpress
11
+
12
+ # Option: failregex
13
+ # Notes.: regex to match the password failures messages in the logfile. The
14
+ # host must be matched by a group named "host". The tag "<HOST>" can
15
+ # be used for standard IP/hostname matching and is only an alias for
16
+ # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
17
+ # Values: TEXT
18
+ #
19
+ failregex = ^%(__prefix_line)sAttempted user enumeration from <HOST>$
20
+
21
+ # Option: ignoreregex
22
+ # Notes.: regex to ignore. If this regex matches, the line is ignored.
23
+ # Values: TEXT
24
+ #
25
+ ignoreregex =
26
+
trunk/fail2ban/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
trunk/fail2ban/jail.local ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # this is an example snippet for jail.local
2
+ # your setting need to betailored depending on your operating system
3
+ # use this only as an example
4
+ #
5
+ [wordpress-userenum]
6
+ enabled = true
7
+ filter = wordpress-userenum
8
+ action = iptables-allports[name=WORDPRESS-USERENUM]
9
+ logpath = /var/log/auth.log
10
+ maxretry = 1
11
+ findtime = 600
12
+ bantime = 604800
trunk/frontend/class-frontend.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * The public-facing functionality of the plugin.
6
+ *
7
+ * Defines the plugin name, version, hooks & filters
8
+ *
9
+ */
10
+
11
+ namespace Stop_User_Enumeration\FrontEnd;
12
+
13
+ use Stop_User_Enumeration\Includes\Core;
14
+
15
+ use WP_Error;
16
+
17
+ class FrontEnd {
18
+
19
+ /**
20
+ * The ID of this plugin.
21
+ *
22
+ */
23
+ private $plugin_name;
24
+
25
+ /**
26
+ * The version of this plugin.
27
+ *
28
+ */
29
+ private $version;
30
+
31
+ private $option_key = 'stop-user-enumeration';
32
+
33
+ /**
34
+ * Initialize the class and set its properties.
35
+ *
36
+ */
37
+ public function __construct( $plugin_name, $version ) {
38
+
39
+ $this->plugin_name = $plugin_name;
40
+ $this->version = $version;
41
+
42
+ }
43
+
44
+ /**
45
+ * Register the JavaScript for the public-facing side of the site.
46
+ *
47
+ */
48
+ public function enqueue_scripts() {
49
+
50
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/frontend.js', array( 'jquery' ), $this->version, false );
51
+
52
+ }
53
+
54
+
55
+ public function check_request() {
56
+ /*
57
+ * Validate incoming request
58
+ *
59
+ */
60
+ if ( ! is_user_logged_in() && isset( $_REQUEST['author'] ) ) {
61
+ if ( $this->ContainsNumbers( $_REQUEST['author'] ) ) {
62
+ $this->sue_log();
63
+ wp_die( esc_html__( 'forbidden - number in author name not allowed = ', 'stop-user-enumeration' ) . esc_html( $_REQUEST['author'] ) );
64
+ }
65
+ }
66
+ }
67
+
68
+ public function only_allow_logged_in_rest_access_to_users( $access ) {
69
+ if ( 'on' === Core::sue_get_option( 'stop_rest_user', 'off' ) ) {
70
+ if ( ( preg_match( '/users/', $_SERVER['REQUEST_URI'] ) !== 0 ) || ( isset( $_REQUEST['rest_route'] ) && ( preg_match( '/users/', $_REQUEST['rest_route'] ) !== 0 ) ) ) {
71
+ if ( ! is_user_logged_in() ) {
72
+ $this->sue_log();
73
+
74
+ return new WP_Error( 'rest_cannot_access', esc_html__( 'Only authenticated users can access the User endpoint REST API.', 'stop-user-enumeration' ), array( 'status' => rest_authorization_required_code() ) );
75
+ }
76
+ }
77
+ }
78
+
79
+ return $access;
80
+ }
81
+
82
+ private function ContainsNumbers( $String ) {
83
+ return preg_match( '/\\d/', $String ) > 0;
84
+ }
85
+
86
+ private function sue_log() {
87
+ $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
88
+ if ( is_plugin_active( 'fullworks-firewall/fullworks-firewall.php' ) ) {
89
+ do_action( 'fullworks_security_block_ip', $ip, 1, 'stop-user-enumeration' );
90
+ }
91
+ if ( 'on' === Core::sue_get_option( 'log_auth', 'off' ) ) {
92
+ openlog( 'wordpress(' . sanitize_text_field( $_SERVER['HTTP_HOST'] ) . ')', LOG_NDELAY | LOG_PID, LOG_AUTH );
93
+ syslog( LOG_INFO, "Attempted user enumeration from " . $ip );
94
+ closelog();
95
+ }
96
+ }
97
+
98
+ }
trunk/frontend/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
trunk/frontend/js/frontend.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ (function ($) {
2
+ 'use strict';
3
+
4
+ $(document).ready(function ($) {
5
+ $(".comment-form input[name='author']").blur(function () {
6
+ $(this).val($(this).val().replace(/\d+/g, ''));
7
+ });
8
+ });
9
+
10
+ })(jQuery);
trunk/gnugeneralpubliclicence.txt ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+
3
+ Version 2, June 1991
4
+
5
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
6
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
7
+
8
+ Everyone is permitted to copy and distribute verbatim copies
9
+ of this license document, but changing it is not allowed.
10
+ Preamble
11
+
12
+ The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
13
+
14
+ When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
15
+
16
+ To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
17
+
18
+ For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
19
+
20
+ We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
21
+
22
+ Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
23
+
24
+ Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
25
+
26
+ The precise terms and conditions for copying, distribution and modification follow.
27
+
28
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
29
+
30
+ 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
31
+
32
+ Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
33
+
34
+ 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
35
+
36
+ You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
37
+
38
+ 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
39
+
40
+ a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
41
+ b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
42
+ c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
43
+ These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
44
+
45
+ Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
46
+
47
+ In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
48
+
49
+ 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
50
+
51
+ a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
52
+ b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
53
+ c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
54
+ The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
55
+
56
+ If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
57
+
58
+ 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
59
+
60
+ 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
61
+
62
+ 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
63
+
64
+ 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
65
+
66
+ If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
67
+
68
+ It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
69
+
70
+ This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
71
+
72
+ 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
73
+
74
+ 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
75
+
76
+ Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
77
+
78
+ 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
79
+
80
+ NO WARRANTY
81
+
82
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
83
+
84
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
85
+
86
+ END OF TERMS AND CONDITIONS
87
+
trunk/includes/autoloader.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Autoloader based on tutorial by
4
+ * Tom McFarlin https://tommcfarlin.com/ Licensed GPL-2.0+
5
+ */
6
+
7
+ spl_autoload_register( 'fullworks_Stop_User_Enumeration_autoload' );
8
+
9
+ function fullworks_Stop_User_Enumeration_autoload( $class_name ) {
10
+
11
+
12
+ // If the specified $class_name does not include our namespace, duck out.
13
+ if ( false === strpos( $class_name, 'Stop_User_Enumeration' ) ) {
14
+ return;
15
+ }
16
+
17
+ // Split the class name into an array to read the namespace and class.
18
+ $file_parts = explode( '\\', $class_name );
19
+
20
+ // Do a reverse loop through $file_parts to build the path to the file.
21
+ $namespace = '';
22
+ for ( $i = count( $file_parts ) - 1; $i > 0; $i -- ) {
23
+
24
+ // Read the current component of the file part.
25
+ $current = strtolower( $file_parts[ $i ] );
26
+ $current = str_ireplace( '_', '-', $current );
27
+
28
+ // If we're at the first entry, then we're at the filename.
29
+ if ( count( $file_parts ) - 1 === $i ) {
30
+
31
+ /* If 'interface' is contained in the parts of the file name, then
32
+ * define the $file_name differently so that it's properly loaded.
33
+ * Otherwise, just set the $file_name equal to that of the class
34
+ * filename structure.
35
+ */
36
+ if ( strpos( strtolower( $file_parts[ count( $file_parts ) - 1 ] ), 'interface' ) ) {
37
+
38
+ // Grab the name of the interface from its qualified name.
39
+ $interface_name = explode( '_', $file_parts[ count( $file_parts ) - 1 ] );
40
+ $interface_name = $interface_name[0];
41
+
42
+ $file_name = "interface-$interface_name.php";
43
+
44
+ } else {
45
+ $file_name = "class-$current.php";
46
+ }
47
+ } else {
48
+ $namespace = '/' . $current . $namespace;
49
+ }
50
+ }
51
+
52
+ // Now build a path to the file using mapping to the file location.
53
+ $filepath = trailingslashit( dirname( dirname( __FILE__ ) ) . $namespace );
54
+ $filepath .= $file_name;
55
+
56
+ // If the file exists in the specified path, then include it.
57
+ if ( file_exists( $filepath ) ) {
58
+ include_once( $filepath );
59
+ } else {
60
+ // changed to be translatable
61
+ wp_die( sprintf( __( 'The system file attempting to be loaded at %1$s does not exist.', 'stop-user-enumeration' ), esc_html( $filepath ) ) );
62
+ }
63
+ }
trunk/includes/class-activator.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Fired during plugin activation
5
+ *
6
+ * @link http://example.com
7
+ * @since 1.0.0
8
+ *
9
+ * @package PluginName
10
+ * @subpackage PluginName/includes
11
+ */
12
+
13
+ /**
14
+ * Fired during plugin activation.
15
+ */
16
+
17
+ namespace Stop_User_Enumeration\Includes;
18
+
19
+ use Stop_User_Enumeration\Admin\Admin_Settings;
20
+
21
+ class Activator {
22
+
23
+ /**
24
+ * Short Description. (use period)
25
+ *
26
+ * Long Description.
27
+ *
28
+ * @since 1.0.0
29
+ */
30
+ public static function activate() {
31
+
32
+ // options set up
33
+ if ( ! get_option( 'stop-user-enumeration' ) ) {
34
+ update_option( 'stop-user-enumeration', Admin_Settings::option_defaults( 'stop-user-enumeration' ) );
35
+ }
36
+
37
+ }
38
+
39
+ }
trunk/includes/class-core.php ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * The core plugin class.
6
+ *
7
+ * This is used to define internationalization, admin-specific hooks, and
8
+ * public-facing site hooks.
9
+ *
10
+ * Also maintains the unique identifier of this plugin as well as the current
11
+ * version of the plugin.
12
+ *
13
+ */
14
+
15
+ namespace Stop_User_Enumeration\Includes;
16
+
17
+ use Stop_User_Enumeration\Admin\Admin_Settings;
18
+ use Stop_User_Enumeration\FrontEnd\FrontEnd;
19
+
20
+
21
+
22
+ class Core {
23
+
24
+ /**
25
+ * The loader that's responsible for maintaining and registering all hooks that power
26
+ * the plugin.
27
+ *
28
+ */
29
+ protected $loader;
30
+
31
+ /**
32
+ * The unique identifier of this plugin.
33
+ *
34
+ */
35
+ protected $plugin_name;
36
+
37
+ /**
38
+ * The current version of the plugin.
39
+ *
40
+ */
41
+ protected $version;
42
+
43
+
44
+ /**
45
+ * Define the core functionality of the plugin.
46
+ *
47
+ * Set the plugin name and the plugin version that can be used throughout the plugin.
48
+ * Load the dependencies, define the locale, and set the hooks for the admin area and
49
+ * the public-facing side of the site.
50
+ *
51
+ */
52
+ public function __construct( $freemius ) {
53
+ $this->plugin_name = 'stop-user-enumeration';
54
+ $this->version = STOP_USER_ENUMERATION_PLUGIN_VERSION;
55
+ $this->freemius = $freemius;
56
+
57
+ // convert settings from legacy settings
58
+ if ( $opts = get_option( 'sue_settings_settings' ) ) {
59
+ $newopts = array(
60
+ 'stop_rest_user' => ( $opts['general_stop_rest_user'] == 1 ) ? 'on' : '',
61
+ 'log_auth' => ( $opts['general_log_auth'] == 1 ) ? 'on' : '',
62
+ 'comment_jquery' => ( $opts['general_comment_jquery'] == 1 ) ? 'on' : '',
63
+ );
64
+ update_option( 'stop-user-enumeration', $newopts );
65
+ delete_option( 'sue_settings_settings' );
66
+ }
67
+
68
+
69
+ $this->load_dependencies();
70
+ $this->set_locale();
71
+ $this->settings_pages();
72
+ $this->define_public_hooks();
73
+
74
+
75
+ }
76
+
77
+ /**
78
+ * Run the loader to execute all of the hooks with WordPress.
79
+ *
80
+ */
81
+ public function run() {
82
+
83
+
84
+ $this->loader->run();
85
+ }
86
+
87
+ /**
88
+ *
89
+ * Loader. Orchestrates the hooks of the plugin.
90
+ *
91
+ * Create an instance of the loader which will be used to register the hooks
92
+ * with WordPress.
93
+ *
94
+ */
95
+ private function load_dependencies() {
96
+
97
+ /**
98
+ * The class responsible for orchestrating the actions and filters of the
99
+ * core plugin.
100
+ */
101
+
102
+ $this->loader = new Loader();
103
+
104
+ }
105
+
106
+ /**
107
+ * Define the locale for this plugin for internationalization.
108
+ *
109
+ * Uses the i18n class in order to set the domain and to register the hook
110
+ * with WordPress.
111
+ *
112
+
113
+ */
114
+ private function set_locale() {
115
+
116
+ /**
117
+ * The class responsible for defining internationalization functionality
118
+ * of the plugin.
119
+ */
120
+
121
+ $plugin_i18n = new i18n();
122
+
123
+ $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
124
+
125
+ }
126
+
127
+ /**
128
+ * Register all of the hooks related to the admin area functionality
129
+ * of the plugin./home/alan/Google/Projects/WordPressPlugins/get-directions-orig
130
+ *
131
+ */
132
+
133
+ private function settings_pages() {
134
+ $settings = new Admin_Settings( $this->get_plugin_name(), $this->get_version(), $this->freemius );
135
+ $this->loader->add_action( 'admin_menu', $settings, 'settings_setup' );
136
+ }
137
+
138
+ /**
139
+ * The name of the plugin used to uniquely identify it within the context of
140
+ * WordPress and to define internationalization functionality.
141
+ *
142
+ * @since 1.0.0
143
+ * @return string The name of the plugin.
144
+ */
145
+ public function get_plugin_name() {
146
+ return $this->plugin_name;
147
+ }
148
+
149
+ /**
150
+ * Retrieve the version number of the plugin.
151
+ *
152
+ * @since 1.0.0
153
+ * @return string The version number of the plugin.
154
+ */
155
+ public function get_version() {
156
+ return $this->version;
157
+ }
158
+
159
+ /**
160
+ * Register all of the hooks related to the public-facing functionality
161
+ * of the plugin.
162
+ *
163
+ * @since 1.0.0
164
+ * @access private
165
+ */
166
+ private function define_public_hooks() {
167
+
168
+ /**
169
+ * The class responsible for defining all actions that occur in the public-facing
170
+ * side of the site.
171
+ */
172
+ $plugin_public = new FrontEnd( $this->get_plugin_name(), $this->get_version() );
173
+ if ( 'on' === $this->sue_get_option( 'comment_jquery', 'off' ) ) {
174
+ $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
175
+ }
176
+
177
+ $this->loader->add_action( 'plugins_loaded', $plugin_public, 'check_request' );
178
+ $this->loader->add_action( 'rest_authentication_errors', $plugin_public, 'only_allow_logged_in_rest_access_to_users' );
179
+
180
+
181
+ }
182
+
183
+
184
+ public static function sue_get_option( $key = '', $default = false ) {
185
+
186
+ $opts = get_option( 'stop-user-enumeration', $default );
187
+ $val = $default;
188
+ if ( 'all' == $key ) {
189
+ $val = $opts;
190
+ } elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) {
191
+ $val = $opts[ $key ];
192
+ }
193
+
194
+ return $val;
195
+ }
196
+
197
+ /**
198
+ * The reference to the class that orchestrates the hooks with the plugin.
199
+ *
200
+ */
201
+ public function get_loader() {
202
+ return $this->loader;
203
+ }
204
+
205
+ }
trunk/includes/class-freemius-config.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class to load freemius configuration
4
+ */
5
+
6
+ namespace Stop_User_Enumeration\Includes;
7
+
8
+
9
+ class Freemius_Config {
10
+
11
+ public function init() {
12
+
13
+ global $sue_fs;
14
+
15
+ if ( ! isset( $sue_fs ) ) {
16
+ // Include Freemius SDK.
17
+ require_once dirname( __FILE__ ) . '/vendor/freemius/wordpress-sdk/start.php';
18
+
19
+ $sue_fs = fs_dynamic_init( array(
20
+ 'id' => '1318',
21
+ 'slug' => 'stop-user-enumeration',
22
+ 'type' => 'plugin',
23
+ 'public_key' => 'pk_bbbd29c5de1662b6753871351b01f',
24
+ 'is_premium' => false,
25
+ 'has_addons' => false,
26
+ 'has_paid_plans' => false,
27
+ 'menu' => array(
28
+ 'slug' => 'stop-user-enumeration',
29
+ 'account' => false,
30
+ 'contact' => false,
31
+ 'parent' => array(
32
+ 'slug' => 'options-general.php',
33
+ ),
34
+ ),
35
+ ) );
36
+ }
37
+
38
+ return $sue_fs;
39
+ }
40
+
41
+
42
+ }
43
+
trunk/includes/class-i18n.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Define the internationalization functionality
5
+ *
6
+ * Loads and defines the internationalization files for this plugin
7
+ * so that it is ready for translation.
8
+ *
9
+ * @link http://example.com
10
+ * @since 1.0.0
11
+ *
12
+ * @package Fullworks_Firewall
13
+ * @subpackage Fullworks_Firewall/includes
14
+ */
15
+
16
+ /**
17
+ * Define the internationalization functionality.
18
+ *
19
+ * Loads and defines the internationalization files for this plugin
20
+ * so that it is ready for translation.
21
+ *
22
+ */
23
+
24
+ namespace Stop_User_Enumeration\Includes;
25
+
26
+ class i18n {
27
+
28
+
29
+ /**
30
+ * Load the plugin text domain for translation.
31
+ *
32
+ * @since 1.0.0
33
+ */
34
+ public function load_plugin_textdomain() {
35
+
36
+ load_plugin_textdomain(
37
+ 'stop-user-enumeration',
38
+ false,
39
+ dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
40
+ );
41
+
42
+ }
43
+
44
+
45
+ }
trunk/includes/class-loader.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * Register all actions and filters for the plugin.
6
+ *
7
+ * Maintain a list of all hooks that are registered throughout
8
+ * the plugin, and register them with the WordPress API. Call the
9
+ * run function to execute the list of actions and filters.
10
+ *
11
+ */
12
+
13
+ namespace Stop_User_Enumeration\Includes;
14
+
15
+ class Loader {
16
+
17
+ /**
18
+ * The array of actions registered with WordPress.
19
+ *
20
+ */
21
+ protected $actions;
22
+
23
+ /**
24
+ * The array of filters registered with WordPress.
25
+ *
26
+ */
27
+ protected $filters;
28
+
29
+ /**
30
+ * Initialize the collections used to maintain the actions and filters.
31
+ *
32
+ */
33
+ public function __construct() {
34
+
35
+ $this->actions = array();
36
+ $this->filters = array();
37
+
38
+ }
39
+
40
+ /**
41
+ * Add a new action to the collection to be registered with WordPress.
42
+ *
43
+ */
44
+ public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
45
+ $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
46
+ }
47
+
48
+ /**
49
+ * Add a new filter to the collection to be registered with WordPress.
50
+ *
51
+ */
52
+ public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
53
+ $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
54
+ }
55
+
56
+ /**
57
+ * A utility function that is used to register the actions and hooks into a single
58
+ * collection.
59
+ *
60
+ */
61
+ private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
62
+
63
+ $hooks[] = array(
64
+ 'hook' => $hook,
65
+ 'component' => $component,
66
+ 'callback' => $callback,
67
+ 'priority' => $priority,
68
+ 'accepted_args' => $accepted_args
69
+ );
70
+
71
+ return $hooks;
72
+
73
+ }
74
+
75
+ /**
76
+ * Register the filters and actions with WordPress.
77
+ *
78
+ */
79
+ public function run() {
80
+
81
+ foreach ( $this->filters as $hook ) {
82
+ add_filter( $hook['hook'], array(
83
+ $hook['component'],
84
+ $hook['callback']
85
+ ), $hook['priority'], $hook['accepted_args'] );
86
+ }
87
+
88
+ foreach ( $this->actions as $hook ) {
89
+ add_action( $hook['hook'], array(
90
+ $hook['component'],
91
+ $hook['callback']
92
+ ), $hook['priority'], $hook['accepted_args'] );
93
+ }
94
+
95
+ }
96
+
97
+ }
trunk/includes/class-uninstall.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * Fired during plugin uninstall.
6
+ *
7
+ * This class defines all code necessary to run during the plugin's deactivation.
8
+ *
9
+ *
10
+ */
11
+
12
+ namespace Stop_User_Enumeration\Includes;
13
+
14
+ class Uninstall {
15
+
16
+ /**
17
+ * Uninstall specific code
18
+ */
19
+ public static function uninstall() {
20
+
21
+ // @TODO check
22
+ delete_option( 'stop-user-enumeration' );
23
+
24
+ }
25
+
26
+ }
trunk/includes/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
trunk/includes/vendor/freemius/wordpress-sdk/LICENSE.txt ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ {one line to give the program's name and a brief idea of what it does.}
635
+ Copyright (C) {year} {name of author}
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ {project} Copyright (C) {year} {fullname}
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/account.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_account .postbox,#fs_account .widefat{max-width:700px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #F1F1F1}#fs_account h3 .dashicons{width:26px;height:26px;font-size:1.3em}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .dashicons{vertical-align:middle}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:0.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type="text"]{color:#0073AA;font-size:16px;background:none}.fs-key-value-table input[type="text"]{width:100%;font-weight:bold}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_sites .fs-scrollable-table .fs-table-body{max-height:200px;overflow:auto;border:1px solid #e5e5e5}#fs_sites .fs-scrollable-table .fs-table-body>table.widefat{border:none !important}#fs_sites .fs-scrollable-table .fs-main-column{width:100%}#fs_sites .fs-scrollable-table .fs-site-details td:first-of-type{text-align:right;color:grey;width:1px}#fs_sites .fs-scrollable-table .fs-site-details td:last-of-type{text-align:right}#fs_sites .fs-scrollable-table .fs-install-details table tr td{width:1px;white-space:nowrap}#fs_sites .fs-scrollable-table .fs-install-details table tr td:last-of-type{width:auto}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons thead{white-space:nowrap}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}#fs_billing_address{width:100%}#fs_billing_address tr td{width:50%;padding:5px}#fs_billing_address tr:first-of-type td{padding-top:0}#fs_billing_address span{font-weight:bold}#fs_billing_address input,#fs_billing_address select{display:block;width:100%;margin-top:5px}#fs_billing_address input::-moz-placeholder,#fs_billing_address select::-moz-placeholder{color:transparent;opacity:1}#fs_billing_address input:-ms-input-placeholder,#fs_billing_address select:-ms-input-placeholder{color:transparent}#fs_billing_address input::-webkit-input-placeholder,#fs_billing_address select::-webkit-input-placeholder{color:transparent}#fs_billing_address input.fs-read-mode,#fs_billing_address select.fs-read-mode{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode td span{display:none}#fs_billing_address.fs-read-mode input,#fs_billing_address.fs-read-mode select{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode input::-moz-placeholder,#fs_billing_address.fs-read-mode select::-moz-placeholder{color:#ccc;opacity:1}#fs_billing_address.fs-read-mode input:-ms-input-placeholder,#fs_billing_address.fs-read-mode select:-ms-input-placeholder{color:#ccc}#fs_billing_address.fs-read-mode input::-webkit-input-placeholder,#fs_billing_address.fs-read-mode select::-webkit-input-placeholder{color:#ccc}#fs_billing_address button{display:block;width:100%}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/add-ons.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ #fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner ul{-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;background-size:100% 100%;-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:0.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:greenyellow;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.3);box-shadow:1px 1px 1px rgba(0,0,0,0.3);text-transform:uppercase;font-size:0.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{position:absolute;top:112px;right:10px}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}
2
+ #TB_window,#TB_window iframe{width:772px !important}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin:1em 30px !important}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:greenyellow;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid darkgreen;padding:2px;text-align:center;font-size:0.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#F3F3F3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:greenyellow}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/affiliation.css ADDED
@@ -0,0 +1 @@
 
1
+ @charset "UTF-8";#fs_affiliation_content_wrapper #messages{margin-top:25px}#fs_affiliation_content_wrapper h3{font-size:24px;padding:0;margin-left:0}#fs_affiliation_content_wrapper ul li{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;list-style-type:none}#fs_affiliation_content_wrapper ul li:before{content:'✓';margin-right:10px;font-weight:bold}#fs_affiliation_content_wrapper p:not(.description),#fs_affiliation_content_wrapper li,#fs_affiliation_content_wrapper label{font-size:16px !important;line-height:26px !important}#fs_affiliation_content_wrapper .button{margin-top:20px;margin-bottom:7px;line-height:35px;height:40px;font-size:16px}#fs_affiliation_content_wrapper .button#cancel_button{margin-right:5px}#fs_affiliation_content_wrapper form .input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form .input-container .input-label{font-weight:bold;display:block;width:100%}#fs_affiliation_content_wrapper form .input-container.input-container-text label,#fs_affiliation_content_wrapper form .input-container.input-container-text input,#fs_affiliation_content_wrapper form .input-container.input-container-text textarea{display:block}#fs_affiliation_content_wrapper form .input-container #add_domain,#fs_affiliation_content_wrapper form .input-container .remove-domain{text-decoration:none;display:inline-block;margin-top:3px}#fs_affiliation_content_wrapper form .input-container #add_domain:focus,#fs_affiliation_content_wrapper form .input-container .remove-domain:focus{box-shadow:none}#fs_affiliation_content_wrapper form .input-container #add_domain.disabled,#fs_affiliation_content_wrapper form .input-container .remove-domain.disabled{color:#aaa;cursor:default}#fs_affiliation_content_wrapper form #extra_domains_container .description{margin-top:0;position:relative;top:-4px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain{display:inline-block;margin-right:5px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain:last-of-type{margin-bottom:0}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/checkout.css ADDED
@@ -0,0 +1 @@
 
1
+ @media screen and (max-width: 782px){#wpbody-content{padding-bottom:0 !important}}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/common.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .theme-browser .theme .fs-premium-theme-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);font-size:1.1em}#iframe{line-height:0;font-size:0}.fs-full-size-wrapper{margin:40px 0 -65px -20px}@media (max-width: 600px){.fs-full-size-wrapper{margin:0 0 -65px -10px}}
2
+ .fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,0.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}div.fs-notice.updated,div.fs-notice.success,div.fs-notice.promotion{display:block !important}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;-moz-box-shadow:0 2px 2px rgba(6,113,6,0.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,0.3);box-shadow:0 2px 2px rgba(6,113,6,0.3);opacity:0.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}.fs-secure-notice a.fs-security-proof{color:green;text-decoration:none}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 600px){.fs-secure-notice{display:none}}@media screen and (max-width: 500px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}.fs-submenu-item.pricing.upgrade-mode{color:greenyellow}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}.fs-ajax-spinner{border:0;width:20px;height:20px;margin-right:5px;vertical-align:sub;display:inline-block;background:url("../../../../../../../wp-admin/images/wpspin_light-2x.gif");background-size:contain}.wrap.fs-section h2{text-align:left}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/connect.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,0,0,0.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect.require-license-key #sites_list_container td{cursor:pointer}#fs_connect #delegate_to_site_admins{margin-right:15px;float:right;height:26px;vertical-align:middle;line-height:37px;font-weight:bold;border-bottom:1px dashed;text-decoration:none}#fs_connect #delegate_to_site_admins.rtl{margin-left:15px;margin-right:0}#fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:' \279C'}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#FEFEFE;-moz-transition:background 0.5s ease;-o-transition:background 0.5s ease;-ms-transition:background 0.5s ease;-webkit-transition:background 0.5s ease;transition:background 0.5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions .fs-trigger{font-size:0.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions ul{height:0;overflow:hidden;margin:0}#fs_connect .fs-permissions ul li{margin-bottom:12px}#fs_connect .fs-permissions ul li:last-child{margin-bottom:0}#fs_connect .fs-permissions ul li i.dashicons{float:left;font-size:40px;width:40px;height:40px}#fs_connect .fs-permissions ul li div{margin-left:55px}#fs_connect .fs-permissions ul li div span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li div p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{height:auto;margin:20px 20px 10px 20px}@media screen and (max-width: 479px){#fs_connect .fs-permissions{background:#fff}#fs_connect .fs-permissions .fs-trigger{display:none}#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:#C2EEFF;text-decoration:underline}#fs_connect .fs-visual{padding:12px;line-height:0;background:#fafafa;height:80px;position:relative}#fs_connect .fs-visual .fs-site-icon{position:absolute;left:20px;top:10px}#fs_connect .fs-visual .fs-connect-logo{position:absolute;right:20px;top:10px}#fs_connect .fs-visual .fs-plugin-icon{position:absolute;top:10px;left:50%;margin-left:-40px}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-site-icon,#fs_connect .fs-visual img,#fs_connect .fs-visual object{width:80px;height:80px}#fs_connect .fs-visual .dashicons-wordpress{font-size:64px;background:#01749a;color:#fff;width:64px;height:64px;padding:8px}#fs_connect .fs-visual .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-visual .dashicons-plus.fs-first{left:28%}#fs_connect .fs-visual .dashicons-plus.fs-second{left:65%}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-connect-logo,#fs_connect .fs-visual .fs-site-icon{border:1px solid #ccc;padding:1px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:0.85em;padding:5px;background:rgba(0,0,0,0.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}#multisite_options_container{margin-top:10px;border:1px solid #ccc;padding:5px}#multisite_options_container a{text-decoration:none}#multisite_options_container a:focus{box-shadow:none}#multisite_options_container a.selected{font-weight:bold}#multisite_options_container.apply-on-all-sites{border:0 none;padding:0}#multisite_options_container.apply-on-all-sites #all_sites_options{border-spacing:0}#multisite_options_container.apply-on-all-sites #all_sites_options td:not(:first-child){display:none}#multisite_options_container #sites_list_container{display:none;overflow:auto}#multisite_options_container #sites_list_container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-tooltip-trigger{position:relative}.fs-tooltip-trigger:not(a){cursor:help}.fs-tooltip-trigger .fs-tooltip{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:rgba(0,0,0,0.8);color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl .fs-tooltip-trigger .fs-tooltip{text-align:right}.fs-tooltip-trigger .fs-tooltip::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:rgba(0,0,0,0.8) transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl .fs-tooltip-trigger .fs-tooltip::after{right:21px;left:auto}.fs-tooltip-trigger:hover .fs-tooltip{visibility:visible;opacity:1}#fs_marketing_optin{display:none;margin-top:10px;border:1px solid #ccc;padding:10px;line-height:1.5em}#fs_marketing_optin .fs-message{display:block;margin-bottom:5px;font-size:1.05em;font-weight:600}#fs_marketing_optin.error{border:1px solid #d3135a;background:#fee}#fs_marketing_optin.error .fs-message{color:#d3135a}#fs_marketing_optin .fs-input-container{margin-top:5px}#fs_marketing_optin .fs-input-container label{margin-top:5px;display:block}#fs_marketing_optin .fs-input-container label input{float:left;margin:1px 0 0 0}#fs_marketing_optin .fs-input-container label:first-child{display:block;margin-bottom:2px}#fs_marketing_optin .fs-input-label{display:block;margin-left:20px}#fs_marketing_optin .fs-input-label .underlined{text-decoration:underline}.rtl #fs_marketing_optin .fs-input-container label input{float:right}.rtl #fs_marketing_optin .fs-input-label{margin-left:0;margin-right:20px}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:' \000bb'}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li div{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}#fs_theme_connect_wrapper{position:fixed;top:0;height:100%;width:100%;z-index:99990;background:rgba(0,0,0,0.75);text-align:center;overflow-y:auto}#fs_theme_connect_wrapper:before{content:"";display:inline-block;vertical-align:middle;height:100%}#fs_theme_connect_wrapper>button.close{color:white;cursor:pointer;height:40px;width:40px;position:absolute;right:0;border:0;background-color:transparent;top:32px}#fs_theme_connect_wrapper #fs_connect{top:0;text-align:left;display:inline-block;vertical-align:middle;margin-top:52px;margin-bottom:20px}#fs_theme_connect_wrapper #fs_connect .fs-terms{background:rgba(140,140,140,0.64)}#fs_theme_connect_wrapper #fs_connect .fs-terms,#fs_theme_connect_wrapper #fs_connect .fs-terms a{color:#c5c5c5}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/deactivation-feedback.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}.fs-modal .fs-modal-dialog li.reason{margin-bottom:10px}.fs-modal .fs-modal-dialog li.reason .reason-input,.fs-modal .fs-modal-dialog li.reason .internal-message{margin-left:29px}.fs-modal .fs-modal-dialog li.reason label{display:table}.fs-modal .fs-modal-dialog li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}.fs-modal .reason-input,.fs-modal .internal-message{margin:3px 0 3px 22px}.fs-modal .reason-input input,.fs-modal .reason-input textarea,.fs-modal .internal-message input,.fs-modal .internal-message textarea{width:100%}.fs-modal li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}body.has-fs-modal{overflow:hidden}#the-list .deactivate>.fs-slug{display:none}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/debug.css ADDED
@@ -0,0 +1 @@
 
1
+ .switch{position:relative;display:inline-block;font-size:1.6em;font-weight:bold;color:#ccc;text-shadow:0px 1px 1px rgba(255,255,255,0.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:4px;background:#ececec;box-shadow:0px 0px 4px rgba(0,0,0,0.1),inset 0px 1px 3px 0px rgba(0,0,0,0.1);cursor:pointer}.switch span{display:inline-block;width:35px;text-transform:uppercase}.switch span.on{color:#6bc406}.switch .toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.3);border-radius:4px;background:#fff;background:-moz-linear-gradient(top, #ececec 0%, #fff 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));background:-webkit-linear-gradient(top, #ececec 0%, #fff 100%);background:-o-linear-gradient(top, #ececec 0%, #fff 100%);background:-ms-linear-gradient(top, #ececec 0%, #fff 100%);background:linear-gradient(top, #ececec 0%, #fff 100%);box-shadow:inset 0px 1px 0px 0px rgba(255,255,255,0.5);z-index:999;-moz-transition:all 0.15s ease-in-out;-o-transition:all 0.15s ease-in-out;-ms-transition:all 0.15s ease-in-out;-webkit-transition:all 0.15s ease-in-out;transition:all 0.15s ease-in-out}.switch.on .toggle{left:2%}.switch.off .toggle{left:54%}.switch.round{padding:0px 20px;border-radius:40px}.switch.round .toggle{border-radius:40px;width:14px;height:14px}.switch.round.on .toggle{left:3%;background:#6bc406}.switch.round.off .toggle{left:58%}.switch-label{font-size:20px;line-height:31px;margin:0 5px}#fs_log_book table{font-family:Consolas,Monaco,monospace;font-size:12px}#fs_log_book table th{color:#ccc}#fs_log_book table tr{background:#232525}#fs_log_book table tr.alternate{background:#2b2b2b}#fs_log_book table tr td.fs-col--logger{color:#5a7435}#fs_log_book table tr td.fs-col--type{color:#ffc861}#fs_log_book table tr td.fs-col--function{color:#a7b7b1;font-weight:bold}#fs_log_book table tr td.fs-col--message,#fs_log_book table tr td.fs-col--message a{color:#9a73ac !important}#fs_log_book table tr td.fs-col--file{color:#d07922}#fs_log_book table tr td.fs-col--timestamp{color:#6596be}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/dialog-boxes.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal.fs-success .fs-modal-header{border-bottom-color:#46b450}.fs-modal.fs-success .fs-modal-body{background-color:#f7fff7}.fs-modal.fs-warn .fs-modal-header{border-bottom-color:#ffb900}.fs-modal.fs-warn .fs-modal-body{background-color:#fff8e5}.fs-modal.fs-error .fs-modal-header{border-bottom-color:#dc3232}.fs-modal.fs-error .fs-modal-body{background-color:#ffeaea}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eeeeee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:0.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-header .fs-close .dashicons,.fs-modal .fs-modal-header .fs-close:hover .dashicons{text-decoration:none}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px;line-height:1.5em}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media (max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label{float:left}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-license-activation .fs-modal-body input.license_key{width:100%}#license_options_container table,#license_options_container table select,#license_options_container table #available_license_key{width:100%}#license_options_container table td:first-child{width:1%}#license_options_container table #other_license_key_container label{position:relative;top:6px;float:left;margin-right:5px}#license_options_container table #other_license_key_container div{overflow:hidden;width:auto;height:30px;display:block;top:2px;position:relative}#license_options_container table #other_license_key_container div input{margin:0}#sites_list_container td{cursor:pointer}#multisite_options_container{margin-top:10px;border:1px solid #ccc;padding:5px}#multisite_options_container a{text-decoration:none}#multisite_options_container a:focus{box-shadow:none}#multisite_options_container a.selected{font-weight:bold}#multisite_options_container.apply-on-all-sites{border:0 none;padding:0}#multisite_options_container.apply-on-all-sites #all_sites_options{border-spacing:0}#multisite_options_container.apply-on-all-sites #all_sites_options td:not(:first-child){display:none}#multisite_options_container #sites_list_container{display:none;overflow:auto}#multisite_options_container #sites_list_container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-modal.fs-modal-license-key-resend .email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend.fs-freemium input.email-address{width:300px}.fs-modal.fs-modal-license-key-resend.fs-freemium label{display:block;margin-bottom:10px}.fs-modal.fs-modal-license-key-resend.fs-premium input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{margin-top:2px}}
2
+ .rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}.fs-ajax-loader{position:relative;width:170px;height:20px;margin:auto}.fs-ajax-loader .fs-ajax-loader-bar{position:absolute;top:0;background-color:#0074a3;width:20px;height:20px;-webkit-animation-name:bounce_ajaxLoader;-moz-animation-name:bounce_ajaxLoader;-ms-animation-name:bounce_ajaxLoader;-o-animation-name:bounce_ajaxLoader;animation-name:bounce_ajaxLoader;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;-ms-animation-duration:1.5s;-o-animation-duration:1.5s;animation-duration:1.5s;animation-iteration-count:infinite;-o-animation-iteration-count:infinite;-ms-animation-iteration-count:infinite;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;-webkit-animation-direction:normal;-moz-animation-direction:normal;-ms-animation-direction:normal;-o-animation-direction:normal;animation-direction:normal;-moz-transform:0.3;-o-transform:0.3;-ms-transform:0.3;-webkit-transform:0.3;transform:0.3}.fs-ajax-loader .fs-ajax-loader-bar-1{left:0px;animation-delay:0.6s;-o-animation-delay:0.6s;-ms-animation-delay:0.6s;-webkit-animation-delay:0.6s;-moz-animation-delay:0.6s}.fs-ajax-loader .fs-ajax-loader-bar-2{left:19px;animation-delay:0.75s;-o-animation-delay:0.75s;-ms-animation-delay:0.75s;-webkit-animation-delay:0.75s;-moz-animation-delay:0.75s}.fs-ajax-loader .fs-ajax-loader-bar-3{left:38px;animation-delay:0.9s;-o-animation-delay:0.9s;-ms-animation-delay:0.9s;-webkit-animation-delay:0.9s;-moz-animation-delay:0.9s}.fs-ajax-loader .fs-ajax-loader-bar-4{left:57px;animation-delay:1.05s;-o-animation-delay:1.05s;-ms-animation-delay:1.05s;-webkit-animation-delay:1.05s;-moz-animation-delay:1.05s}.fs-ajax-loader .fs-ajax-loader-bar-5{left:76px;animation-delay:1.2s;-o-animation-delay:1.2s;-ms-animation-delay:1.2s;-webkit-animation-delay:1.2s;-moz-animation-delay:1.2s}.fs-ajax-loader .fs-ajax-loader-bar-6{left:95px;animation-delay:1.35s;-o-animation-delay:1.35s;-ms-animation-delay:1.35s;-webkit-animation-delay:1.35s;-moz-animation-delay:1.35s}.fs-ajax-loader .fs-ajax-loader-bar-7{left:114px;animation-delay:1.5s;-o-animation-delay:1.5s;-ms-animation-delay:1.5s;-webkit-animation-delay:1.5s;-moz-animation-delay:1.5s}.fs-ajax-loader .fs-ajax-loader-bar-8{left:133px;animation-delay:1.65s;-o-animation-delay:1.65s;-ms-animation-delay:1.65s;-webkit-animation-delay:1.65s;-moz-animation-delay:1.65s}@-moz-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-ms-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-o-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-webkit-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}.fs-modal-auto-install #request-filesystem-credentials-form h2,.fs-modal-auto-install #request-filesystem-credentials-form .request-filesystem-credentials-action-buttons{display:none}.fs-modal-auto-install #request-filesystem-credentials-form input[type=password],.fs-modal-auto-install #request-filesystem-credentials-form input[type=email],.fs-modal-auto-install #request-filesystem-credentials-form input[type=text]{-webkit-appearance:none;padding:10px 10px 5px 10px;width:300px;max-width:100%}.fs-modal-auto-install #request-filesystem-credentials-form>div,.fs-modal-auto-install #request-filesystem-credentials-form label,.fs-modal-auto-install #request-filesystem-credentials-form fieldset{width:300px;max-width:100%;margin:0 auto;display:block}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/gdpr-optin-notice.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice[data-id^="gdpr_optin_actions"] .underlined{text-decoration:underline}.fs-notice[data-id^="gdpr_optin_actions"] ul .button,.fs-notice[data-id^="gdpr_optin_actions"] ul .action-description{vertical-align:middle}.fs-notice[data-id^="gdpr_optin_actions"] ul .action-description{display:inline-block;margin-left:3px}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/admin/license-activation.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body .license-activation-message{margin:0;display:none}.fs-modal .fs-modal-body input.license_key{width:100%}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}body.has-fs-modal{overflow:hidden}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/customizer.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_customizer_upsell .fs-customizer-plan{padding:10px 20px 20px 20px;border-radius:3px;background:#fff}#fs_customizer_upsell .fs-customizer-plan h2{position:relative;margin:0;line-height:2em;text-transform:uppercase}#fs_customizer_upsell .fs-customizer-plan h2 .button-link{top:-2px}#fs_customizer_upsell .fs-feature{position:relative}#fs_customizer_upsell .dashicons-yes{color:#0085ba;font-size:2em;vertical-align:bottom;margin-left:-7px;margin-right:10px}.rtl #fs_customizer_upsell .dashicons-yes{margin-left:10px;margin-right:-7px}#fs_customizer_upsell .dashicons-editor-help{color:#bbb;cursor:help}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:#000;color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{text-align:right}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:#000 transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{right:21px;left:auto}#fs_customizer_upsell .dashicons-editor-help:hover .fs-feature-desc{visibility:visible;opacity:1}#fs_customizer_upsell .button-primary{display:block;text-align:center;margin-top:10px}#fs_customizer_support{display:block !important}#fs_customizer_support .button{float:right}#fs_customizer_support .button-group{width:100%;display:block;margin-top:10px}#fs_customizer_support .button-group .button{float:none;width:50%;text-align:center}
trunk/includes/vendor/freemius/wordpress-sdk/assets/css/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
trunk/includes/vendor/freemius/wordpress-sdk/assets/img/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
trunk/includes/vendor/freemius/wordpress-sdk/assets/img/plugin-icon.png ADDED
Binary file
trunk/includes/vendor/freemius/wordpress-sdk/assets/img/theme-icon.png ADDED
Binary file
trunk/includes/vendor/freemius/wordpress-sdk/assets/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
trunk/includes/vendor/freemius/wordpress-sdk/assets/js/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
trunk/includes/vendor/freemius/wordpress-sdk/assets/js/nojquery.ba-postmessage.js ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ *
9
+ * Non-jQuery fork by Jeff Lee
10
+ *
11
+ * This fork consists of the following changes:
12
+ * 1. Basic code cleanup and restructuring, for legibility.
13
+ * 2. The `postMessage` and `receiveMessage` functions can be bound arbitrarily,
14
+ * in terms of both function names and object scope. Scope is specified by
15
+ * the the "this" context of NoJQueryPostMessageMixin();
16
+ * 3. I've removed the check for Opera 9.64, which used `$.browser`. There were
17
+ * at least three different GitHub users requesting the removal of this
18
+ * "Opera sniff" on the original project's Issues page, so I figured this
19
+ * would be a relatively safe change.
20
+ * 4. `postMessage` no longer uses `$.param` to serialize messages that are not
21
+ * strings. I actually prefer this structure anyway. `receiveMessage` does
22
+ * not implement a corresponding deserialization step, and as such it seems
23
+ * cleaner and more symmetric to leave both data serialization and
24
+ * deserialization to the client.
25
+ * 5. The use of `$.isFunction` is replaced by a functionally-identical check.
26
+ * 6. The `$:nomunge` YUI option is no longer necessary.
27
+ */
28
+
29
+ function NoJQueryPostMessageMixin(postBinding, receiveBinding) {
30
+
31
+ var setMessageCallback, unsetMessageCallback, currentMsgCallback,
32
+ intervalId, lastHash, cacheBust = 1;
33
+
34
+ if (window.postMessage) {
35
+
36
+ if (window.addEventListener) {
37
+ setMessageCallback = function(callback) {
38
+ window.addEventListener('message', callback, false);
39
+ }
40
+
41
+ unsetMessageCallback = function(callback) {
42
+ window.removeEventListener('message', callback, false);
43
+ }
44
+ } else {
45
+ setMessageCallback = function(callback) {
46
+ window.attachEvent('onmessage', callback);
47
+ }
48
+
49
+ unsetMessageCallback = function(callback) {
50
+ window.detachEvent('onmessage', callback);
51
+ }
52
+ }
53
+
54
+ this[postBinding] = function(message, targetUrl, target) {
55
+ if (!targetUrl) {
56
+ return;
57
+ }
58
+
59
+ // The browser supports window.postMessage, so call it with a targetOrigin
60
+ // set appropriately, based on the targetUrl parameter.
61
+ target.postMessage( message, targetUrl.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
62
+ }
63
+
64
+ // Since the browser supports window.postMessage, the callback will be
65
+ // bound to the actual event associated with window.postMessage.
66
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
67
+ // Unbind an existing callback if it exists.
68
+ if (currentMsgCallback) {
69
+ unsetMessageCallback(currentMsgCallback);
70
+ currentMsgCallback = null;
71
+ }
72
+
73
+ if (!callback) {
74
+ return false;
75
+ }
76
+
77
+ // Bind the callback. A reference to the callback is stored for ease of
78
+ // unbinding.
79
+ currentMsgCallback = setMessageCallback(function(e) {
80
+ switch(Object.prototype.toString.call(sourceOrigin)) {
81
+ case '[object String]':
82
+ if (sourceOrigin !== e.origin) {
83
+ return false;
84
+ }
85
+ break;
86
+ case '[object Function]':
87
+ if (sourceOrigin(e.origin)) {
88
+ return false;
89
+ }
90
+ break;
91
+ }
92
+
93
+ callback(e);
94
+ });
95
+ };
96
+
97
+ } else {
98
+
99
+ this[postBinding] = function(message, targetUrl, target) {
100
+ if (!targetUrl) {
101
+ return;
102
+ }
103
+
104
+ // The browser does not support window.postMessage, so set the location
105
+ // of the target to targetUrl#message. A bit ugly, but it works! A cache
106
+ // bust parameter is added to ensure that repeat messages trigger the
107
+ // callback.
108
+ target.location = targetUrl.replace( /#.*$/, '' ) + '#' + (+new Date) + (cacheBust++) + '&' + message;
109
+ }
110
+
111
+ // Since the browser sucks, a polling loop will be started, and the
112
+ // callback will be called whenever the location.hash changes.
113
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
114
+ if (intervalId) {
115
+ clearInterval(intervalId);
116
+ intervalId = null;
117
+ }
118
+
119
+ if (callback) {
120
+ delay = typeof sourceOrigin === 'number'
121
+ ? sourceOrigin
122
+ : typeof delay === 'number'
123
+ ? delay
124
+ : 100;
125
+
126
+ intervalId = setInterval(function(){
127
+ var hash = document.location.hash,
128
+ re = /^#?\d+&/;
129
+ if ( hash !== lastHash && re.test( hash ) ) {
130
+ lastHash = hash;
131
+ callback({ data: hash.replace( re, '' ) });
132
+ }
133
+ }, delay );
134
+ }
135
+ };
136
+
137
+ }
138
+
139
+ return this;
140
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/js/nojquery.ba-postmessage.min.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * nojquery-postmessage by Jeff Lee
3
+ * a non-jQuery fork of:
4
+ *
5
+ * jQuery postMessage - v0.5 - 9/11/2009
6
+ * http://benalman.com/projects/jquery-postmessage-plugin/
7
+ *
8
+ * Copyright (c) 2009 "Cowboy" Ben Alman
9
+ * Dual licensed under the MIT and GPL licenses.
10
+ * http://benalman.com/about/license/
11
+ */
12
+ function NoJQueryPostMessageMixin(g,a){var b,h,e,d,f,c=1;if(window.postMessage){if(window.addEventListener){b=function(i){window.addEventListener("message",i,false)};h=function(i){window.removeEventListener("message",i,false)}}else{b=function(i){window.attachEvent("onmessage",i)};h=function(i){window.detachEvent("onmessage",i)}}this[g]=function(i,k,j){if(!k){return}j.postMessage(i,k.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[a]=function(k,j,i){if(e){h(e);e=null}if(!k){return false}e=b(function(l){switch(Object.prototype.toString.call(j)){case"[object String]":if(j!==l.origin){return false}break;case"[object Function]":if(j(l.origin)){return false}break}k(l)})}}else{this[g]=function(i,k,j){if(!k){return}j.location=k.replace(/#.*$/,"")+"#"+(+new Date)+(c++)+"&"+i};this[a]=function(k,j,i){if(d){clearInterval(d);d=null}if(k){i=typeof j==="number"?j:typeof i==="number"?i:100;d=setInterval(function(){var m=document.location.hash,l=/^#?\d+&/;if(m!==f&&l.test(m)){f=m;k({data:m.replace(l,"")})}},i)}}}return this};
trunk/includes/vendor/freemius/wordpress-sdk/assets/js/postmessage.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($, undef) {
2
+ var global = this;
3
+
4
+ // Namespace.
5
+ global.FS = global.FS || {};
6
+
7
+ global.FS.PostMessage = function ()
8
+ {
9
+ var
10
+ _is_child = false,
11
+ _postman = new NoJQueryPostMessageMixin('postMessage', 'receiveMessage'),
12
+ _callbacks = {},
13
+ _base_url,
14
+ _parent_url = decodeURIComponent(document.location.hash.replace(/^#/, '')),
15
+ _parent_subdomain = _parent_url.substring(0, _parent_url.indexOf('/', ('https://' === _parent_url.substring(0, ('https://').length)) ? 8 : 7)),
16
+ _init = function () {
17
+ _postman.receiveMessage(function (e) {
18
+ var data = JSON.parse(e.data);
19
+
20
+ if (_callbacks[data.type]) {
21
+ for (var i = 0; i < _callbacks[data.type].length; i++) {
22
+ // Execute type callbacks.
23
+ _callbacks[data.type][i](data.data);
24
+ }
25
+ }
26
+ }, _base_url);
27
+ },
28
+ _hasParent = ('' !== _parent_url),
29
+ $window = $(window),
30
+ $html = $('html');
31
+
32
+ return {
33
+ init : function (url, iframes)
34
+ {
35
+ _base_url = url;
36
+ _init();
37
+
38
+ // Automatically receive forward messages.
39
+ FS.PostMessage.receiveOnce('forward', function (data){
40
+ window.location = data.url;
41
+ });
42
+
43
+ iframes = iframes || [];
44
+
45
+ if (iframes.length > 0) {
46
+ $window.on('scroll', function () {
47
+ for (var i = 0; i < iframes.length; i++) {
48
+ FS.PostMessage.postScroll(iframes[i]);
49
+ }
50
+ });
51
+ }
52
+ },
53
+ init_child : function ()
54
+ {
55
+ this.init(_parent_subdomain);
56
+
57
+ _is_child = true;
58
+
59
+ // Post height of a child right after window is loaded.
60
+ $(window).bind('load', function () {
61
+ FS.PostMessage.postHeight();
62
+
63
+ // Post message that window was loaded.
64
+ FS.PostMessage.post('loaded');
65
+ });
66
+ },
67
+ hasParent : function ()
68
+ {
69
+ return _hasParent;
70
+ },
71
+ postHeight : function (diff, wrapper) {
72
+ diff = diff || 0;
73
+ wrapper = wrapper || '#wrap_section';
74
+ this.post('height', {
75
+ height: diff + $(wrapper).outerHeight(true)
76
+ });
77
+ },
78
+ postScroll : function (iframe) {
79
+ this.post('scroll', {
80
+ top: $window.scrollTop(),
81
+ height: ($window.height() - parseFloat($html.css('paddingTop')) - parseFloat($html.css('marginTop')))
82
+ }, iframe);
83
+ },
84
+ post : function (type, data, iframe)
85
+ {
86
+ console.debug('PostMessage.post', type);
87
+
88
+ if (iframe)
89
+ {
90
+ // Post to iframe.
91
+ _postman.postMessage(JSON.stringify({
92
+ type: type,
93
+ data: data
94
+ }), iframe.src, iframe.contentWindow);
95
+ }
96
+ else {
97
+ // Post to parent.
98
+ _postman.postMessage(JSON.stringify({
99
+ type: type,
100
+ data: data
101
+ }), _parent_url, window.parent);
102
+ }
103
+ },
104
+ receive: function (type, callback)
105
+ {
106
+ console.debug('PostMessage.receive', type);
107
+
108
+ if (undef === _callbacks[type])
109
+ _callbacks[type] = [];
110
+
111
+ _callbacks[type].push(callback);
112
+ },
113
+ receiveOnce: function (type, callback)
114
+ {
115
+ if (this.is_set(type))
116
+ return;
117
+
118
+ this.receive(type, callback);
119
+ },
120
+ // Check if any callbacks assigned to a specified message type.
121
+ is_set: function (type)
122
+ {
123
+ return (undef != _callbacks[type]);
124
+ },
125
+ parent_url: function ()
126
+ {
127
+ return _parent_url;
128
+ },
129
+ parent_subdomain: function ()
130
+ {
131
+ return _parent_subdomain;
132
+ }
133
+ };
134
+ }();
135
+ })(jQuery);
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_colors.scss ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $menu-hover-color: #333;
2
+ $darkest-color: #000;
3
+ $fms-live-color: #71ae00;
4
+ $fms-test-color: #f7941d;
5
+ $fms-link-color: #29abe1;
6
+ $fms-link-hover-color: darken(#29abe1, 10%);
7
+ $body-bkg: #111;
8
+ $special-color: #d3135a;
9
+ $body-color: #f1f1f1;
10
+ $fms-white: #f1f1f1;
11
+ $container-bkg: #222;
12
+ $container-bkg-odd: #262626;
13
+ $container-border-color: #333;
14
+ $table-head-bkg: #333;
15
+ $table-head-color: #999;
16
+ $info-color: #999;
17
+ $error-color: #ff0000;
18
+
19
+ $fs-logo-blue-color: #29abe1;
20
+ $fs-logo-green-color: #71ae00;
21
+ $fs-logo-magenta-color: #d3135a;
22
+
23
+ // WordPress colors.
24
+ $page-header-bkg: #333;
25
+ $page-header-color: $fms-white;
26
+ $text-dark-color: #333;
27
+ $text-light-color: #666;
28
+ $text-lightest-color: #999;
29
+
30
+ // Notices.
31
+ $wp-notice-success-color: #f7fff7;
32
+ $wp-notice-success-dark-color: #46b450;
33
+ $wp-notice-error-color: #ffeaea;
34
+ $wp-notice-error-dark-color: #dc3232;
35
+ $wp-notice-warn-color: #fff8e5;
36
+ $wp-notice-warn-dark-color: #ffb900;
37
+ $fs-notice-promotion-border-color: #00a0d2;
38
+ $fs-notice-promotion-bkg: #f2fcff;
39
+
40
+ // WP Buttons.
41
+ $button-primary-bkg: #6bc406;
42
+ $button-primary-color: $fms-white;
43
+ $button-secondary-bkg: #333;
44
+ $button-secondary-color: $fms-white;
45
+ $featured-color: #6bc406;
46
+ $wp-selected-color: #0074a3;
47
+
48
+ $wordpress_color: #01749A;
49
+ $blogger_color: #ff8100;
50
+ $wix_color: #fac102;
51
+ $shopify_color: #80d100;
52
+ $addthis_color: #fe6d4e;
53
+ $tumblr_color: #34506b;
54
+ $zepo_color: #00baf2;
55
+ $jquery_color: #000919;
56
+ $javascript_color: #00baf2;
57
+ $squarespace_color: #000;
58
+
59
+ $blog_color: #ff6600;
60
+ $facebook_color: #3b5998;
61
+ $twitter_color: #4099ff;
62
+ $linkedin_color: #4875b4;
63
+ $youtube_color: #ff3333;
64
+ $gplus_color: #c63d2d;
65
+
66
+ // Tooltip
67
+ $tooltip-color: #fff;
68
+ $tooltip-bkg-color: rgba(0,0,0,0.8);
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_functions.scss ADDED
File without changes
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_load.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_mixins.scss ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ---- CSS3 SASS MIXINS ----
2
+ // https://github.com/madr/css3-sass-mixins
3
+ //
4
+ // Copyright (C) 2011 by Anders Ytterström
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in
14
+ // all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ // THE SOFTWARE.
23
+ //
24
+
25
+ // ---- LEGACY IE SUPPORT USING FILTERS ----
26
+ // Should IE filters be used or not?
27
+ // PROS: gradients, drop shadows etc will be handled by css.
28
+ // CONS: will harm the site performance badly,
29
+ // especially on sites with heavy rendering and scripting.
30
+ $useIEFilters: 0;
31
+ // might be 0 or 1. disabled by default.
32
+ // ---- /LEGACY IE SUPPORT USING FILTERS ----
33
+
34
+
35
+ @mixin background-size ($value) {
36
+ -webkit-background-size: $value;
37
+ background-size: $value;
38
+ }
39
+
40
+ @mixin border-image ($path, $offsets, $repeats) {
41
+ -moz-border-image: $path $offsets $repeats;
42
+ -o-border-image: $path $offsets $repeats;
43
+ -webkit-border-image: $path $offsets $repeats;
44
+ border-image: $path $offsets $repeats;
45
+ }
46
+
47
+ @mixin border-radius ($values...) {
48
+ -moz-border-radius: $values;
49
+ -webkit-border-radius: $values;
50
+ border-radius: $values;
51
+ /*-moz-background-clip: padding;
52
+ -webkit-background-clip: padding-box;
53
+ background-clip: padding-box;*/
54
+ }
55
+
56
+ @mixin box-shadow ($values...) {
57
+ -moz-box-shadow: $values;
58
+ -webkit-box-shadow: $values;
59
+ box-shadow: $values;
60
+ }
61
+
62
+ //@mixin box-shadow ($x, $y, $offset, $hex, $ie: $useIEFilters, $inset: null, $spread:null) {
63
+ // -moz-box-shadow: $x $y $offset $spread $hex $inset;
64
+ // -webkit-box-shadow: $x $y $offset $spread $hex $inset;
65
+ // box-shadow: $x $y $offset $spread $hex $inset;
66
+ //
67
+ // @if $ie == 1 {
68
+ // $iecolor: '#' + red($hex) + green($hex) + blue($hex);
69
+ // filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}');
70
+ // -ms-filter: quote(progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}'));
71
+ // }
72
+ //}
73
+
74
+ @mixin box-sizing($value) {
75
+ -moz-box-sizing: $value;
76
+ -webkit-box-sizing: $value;
77
+ box-sizing: $value;
78
+ }
79
+
80
+ // requires sass 3.2
81
+ @mixin keyframes($name){
82
+ @-moz-keyframes #{$name} { @content; }
83
+ @-ms-keyframes #{$name} { @content; }
84
+ @-o-keyframes #{$name} { @content; }
85
+ @-webkit-keyframes #{$name} { @content; }
86
+ @keyframes #{$name} { @content; }
87
+ }
88
+
89
+ @mixin linear-gradient($from, $to, $ie: $useIEFilters) {
90
+ @if $ie != 1 { background-color: $to; }
91
+
92
+ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, $from),color-stop(1, $to));
93
+ background-image: -webkit-linear-gradient(top, $from, $to);
94
+ background-image: -moz-linear-gradient(top, $from, $to);
95
+ background-image: -ms-linear-gradient(top, $from, $to);
96
+ background-image: -o-linear-gradient(top, $from, $to);
97
+ background-image: linear-gradient(top, bottom, $from, $to);
98
+
99
+ @if $ie == 1 {
100
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
101
+ }
102
+ }
103
+
104
+ @mixin horizontal-gradient($startColor: #555, $endColor: #333, $ie: $useIEFilters) {
105
+ @if $ie != 1 { background-color: $endColor; }
106
+
107
+ background-color: $endColor;
108
+ background-image: -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
109
+ background-image: -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
110
+ background-image: -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
111
+ background-image: -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
112
+ background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
113
+ background-repeat: repeat-x;
114
+ @if $ie == 1 {
115
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$startColor}', endColorstr='#{$endColor}', GradientType=1);
116
+ }
117
+ }
118
+
119
+ @mixin radial-gradient($from, $to, $ie: $useIEFilters) {
120
+ @if $ie != 1 { background-color: $to; }
121
+
122
+ background: -moz-radial-gradient(center, circle cover, $from 0%, $to 100%);
123
+ background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, $from), color-stop(100%, $to));
124
+ background: -webkit-radial-gradient(center, circle cover, $from 0%, $to 100%);
125
+ background: -o-radial-gradient(center, circle cover, $from 0%, $to 100%);
126
+ background: -ms-radial-gradient(center, circle cover, $from 0%, $to 100%);
127
+ background: radial-gradient(center, circle cover, $from 0%, $to 100%);
128
+ background-color: $from;
129
+
130
+ @if $ie == 1 {
131
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}', GradientType=1); /* IE6-9 fallback on horizontal gradient */
132
+ }
133
+ }
134
+
135
+ @mixin perspective($perspective) {
136
+ -moz-perspective: $perspective;
137
+ -ms-perspective: $perspective;
138
+ -webkit-perspective: $perspective;
139
+ perspective: $perspective;
140
+ -moz-transform-style: preserve-3d;
141
+ -ms-transform-style: preserve-3d;
142
+ -webkit-transform-style: preserve-3d;
143
+ transform-style: preserve-3d;
144
+ }
145
+
146
+ @mixin transform ($transforms) {
147
+ -moz-transform: $transforms;
148
+ -o-transform: $transforms;
149
+ -ms-transform: $transforms;
150
+ -webkit-transform: $transforms;
151
+ transform: $transforms;
152
+ }
153
+
154
+ @mixin matrix ($a, $b, $c, $d, $e, $f) {
155
+ -moz-transform: matrix($a, $b, $c, $d, #{$e}px, #{$f}px);
156
+ -o-transform: matrix($a, $b, $c, $d, $e, $f);
157
+ -ms-transform: matrix($a, $b, $c, $d, $e, $f);
158
+ -webkit-transform: matrix($a, $b, $c, $d, $e, $f);
159
+ transform: matrix($a, $b, $c, $d, $e, $f);
160
+ }
161
+
162
+ @mixin rotate ($deg) {
163
+ @include transform(rotate(#{$deg}deg));
164
+ }
165
+
166
+ @mixin scale ($size) {
167
+ @include transform(scale(#{$size}));
168
+ }
169
+
170
+ @mixin translate ($x, $y) {
171
+ @include transform(translate($x, $y));
172
+ }
173
+
174
+ @mixin transition ($value...) {
175
+ -moz-transition: $value;
176
+ -o-transition: $value;
177
+ -ms-transition: $value;
178
+ -webkit-transition: $value;
179
+ transition: $value;
180
+ }
181
+
182
+ @mixin animation($str) {
183
+ -webkit-animation: #{$str};
184
+ -moz-animation: #{$str};
185
+ -ms-animation: #{$str};
186
+ -o-animation: #{$str};
187
+ animation: #{$str};
188
+ }
189
+
190
+ @mixin animation-name($str) {
191
+ -webkit-animation-name: #{$str};
192
+ -moz-animation-name: #{$str};
193
+ -ms-animation-name: #{$str};
194
+ -o-animation-name: #{$str};
195
+ animation-name: #{$str};
196
+ }
197
+
198
+ @mixin animation-duration($str) {
199
+ -webkit-animation-duration: #{$str};
200
+ -moz-animation-duration: #{$str};
201
+ -ms-animation-duration: #{$str};
202
+ -o-animation-duration: #{$str};
203
+ animation-duration: #{$str};
204
+ }
205
+
206
+ @mixin animation-direction($str) {
207
+ -webkit-animation-direction: #{$str};
208
+ -moz-animation-direction: #{$str};
209
+ -ms-animation-direction: #{$str};
210
+ -o-animation-direction: #{$str};
211
+ animation-direction: #{$str};
212
+ }
213
+
214
+ @mixin animation-delay($str) {
215
+ animation-delay:#{$str};
216
+ -o-animation-delay:#{$str};
217
+ -ms-animation-delay:#{$str};
218
+ -webkit-animation-delay:#{$str};
219
+ -moz-animation-delay:#{$str};
220
+ }
221
+
222
+ @mixin animation-iteration-count($str) {
223
+ animation-iteration-count:#{$str};
224
+ -o-animation-iteration-count:#{$str};
225
+ -ms-animation-iteration-count:#{$str};
226
+ -webkit-animation-iteration-count:#{$str};
227
+ -moz-animation-iteration-count:#{$str};
228
+ }
229
+
230
+ @mixin animation-timing-function($str) {
231
+ -webkit-animation-timing-function: #{$str};
232
+ -moz-animation-timing-function: #{$str};
233
+ -ms-animation-timing-function: #{$str};
234
+ -o-animation-timing-function: #{$str};
235
+ animation-timing-function: #{$str};
236
+ }
237
+
238
+ // ==== /CSS3 SASS MIXINS ====
239
+
240
+ @mixin opacity($opacity) {
241
+ opacity: $opacity;
242
+ $opacity-ie: $opacity * 100;
243
+ filter: alpha(opacity=$opacity-ie); //IE8
244
+ }
245
+
246
+ @mixin size($width, $height: $width)
247
+ {
248
+ width: $width;
249
+ height: $height;
250
+ }
251
+
252
+ @mixin clearfix
253
+ {
254
+ &:after {
255
+ content: "";
256
+ display: table;
257
+ clear: both;
258
+ }
259
+ }
260
+
261
+ // Placeholder text
262
+ @mixin placeholder($color: $input-color-placeholder) {
263
+ // Firefox
264
+ &::-moz-placeholder {
265
+ color: $color;
266
+ opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
267
+ }
268
+ &:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
269
+ &::-webkit-input-placeholder { color: $color; } // Safari and Chrome
270
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_start.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
+ @import "functions";
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/_vars.scss ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
+ $layout_width: 960px;
6
+ $admin_mobile_max_width: 782px;
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_ajax-loader.scss ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $color: $wp-selected-color;
2
+ $bkg-color: #fff;
3
+ $size: 20;
4
+
5
+ .fs-ajax-loader
6
+ {
7
+ position: relative;
8
+ width: #{8*$size + 10}px;
9
+ height: #{$size}px;
10
+ margin: auto;
11
+
12
+ .fs-ajax-loader-bar
13
+ {
14
+ position: absolute;
15
+ top: 0;
16
+ background-color: $color;
17
+ width: #{$size}px;
18
+ height: #{$size}px;
19
+ @include animation-name(bounce_ajaxLoader);
20
+ @include animation-duration(1.5s);
21
+ @include animation-iteration-count(infinite);
22
+ @include animation-direction(normal);
23
+ @include transform(.3);
24
+ }
25
+
26
+ @for $i from 0 through 7
27
+ {
28
+ .fs-ajax-loader-bar-#{$i + 1}
29
+ {
30
+ left: #{$i*($size - 1)}px;
31
+ @include animation-delay(#{0.6 + $i*0.15}s);
32
+ }
33
+ }
34
+ }
35
+
36
+ @include keyframes(bounce_ajaxLoader)
37
+ {
38
+ 0%
39
+ {
40
+ @include transform(scale(1));
41
+ background-color: $color;
42
+ }
43
+
44
+ 100%
45
+ {
46
+ @include transform(scale(.3));
47
+ background-color: $bkg-color;
48
+ }
49
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_auto-install.scss ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal-auto-install
2
+ {
3
+ $max-width: 300px;
4
+
5
+ #request-filesystem-credentials-form
6
+ {
7
+ h2,
8
+ .request-filesystem-credentials-action-buttons
9
+ {
10
+ display: none;
11
+ }
12
+
13
+ input[type=password],
14
+ input[type=email],
15
+ input[type=text]
16
+ {
17
+ -webkit-appearance: none;
18
+ padding: 10px 10px 5px 10px;
19
+ width: $max-width;
20
+ max-width: 100%;
21
+ }
22
+
23
+ > div,
24
+ label,
25
+ fieldset
26
+ {
27
+ width: $max-width;
28
+ max-width: 100%;
29
+ margin: 0 auto;
30
+ display: block;
31
+ }
32
+ }
33
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_deactivation-feedback.scss ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+
3
+ .fs-modal.fs-modal-deactivation-feedback {
4
+ .reason-input, .internal-message {
5
+ margin: 3px 0 3px 22px;
6
+
7
+ input, textarea {
8
+ width: 100%;
9
+ }
10
+ }
11
+
12
+ li.reason {
13
+ &.has-internal-message .internal-message {
14
+ border: 1px solid lighten($darkest-color, 80%);
15
+ padding: 7px;
16
+ display: none;
17
+ }
18
+
19
+ @media (max-width: 650px) {
20
+ li.reason {
21
+ margin-bottom: 10px;
22
+
23
+ .reason-input, .internal-message {
24
+ margin-left: 29px;
25
+ }
26
+
27
+ label {
28
+ display: table;
29
+
30
+ > span {
31
+ display: table-cell;
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ .anonymous-feedback-label {
40
+ float: left;
41
+ }
42
+
43
+ .fs-modal-panel {
44
+ margin-top: 0 !important;
45
+
46
+ h3 {
47
+ margin-top: 0;
48
+ line-height: 1.5em;
49
+ }
50
+ }
51
+ }
52
+
53
+ #the-list .deactivate > .fs-slug {
54
+ display: none;
55
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_gdpr-consent.scss ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #fs_marketing_optin
2
+ {
3
+ display: none;
4
+ margin-top: 10px;
5
+ border: 1px solid #ccc;
6
+ padding: 10px;
7
+ line-height: 1.5em;
8
+
9
+ .fs-message
10
+ {
11
+ display: block;
12
+ margin-bottom: 5px;
13
+ font-size: 1.05em;
14
+ font-weight: 600;
15
+ }
16
+
17
+ &.error
18
+ {
19
+ border: 1px solid $fs-logo-magenta-color;
20
+ background: #fee;
21
+
22
+ .fs-message
23
+ {
24
+ color: $fs-logo-magenta-color;
25
+ }
26
+ }
27
+
28
+ .fs-input-container
29
+ {
30
+ margin-top: 5px;
31
+
32
+ label
33
+ {
34
+ margin-top: 5px;
35
+ display: block;
36
+
37
+ input
38
+ {
39
+ float: left;
40
+ margin: 1px 0 0 0;
41
+ }
42
+
43
+ &:first-child
44
+ {
45
+ display: block;
46
+ margin-bottom: 2px;
47
+ }
48
+ }
49
+ }
50
+
51
+ .fs-input-label
52
+ {
53
+ display: block;
54
+ margin-left: 20px;
55
+
56
+ .underlined
57
+ {
58
+ text-decoration: underline;
59
+ }
60
+ }
61
+ }
62
+
63
+ .rtl
64
+ {
65
+ #fs_marketing_optin
66
+ {
67
+ .fs-input-container
68
+ {
69
+ label input
70
+ {
71
+ float: right;
72
+ }
73
+ }
74
+
75
+ .fs-input-label
76
+ {
77
+ margin-left: 0;
78
+ margin-right: 20px;
79
+ }
80
+ }
81
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_license-activation.scss ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-activation {
2
+ .fs-modal-body {
3
+ input.license_key {
4
+ width: 100%;
5
+ }
6
+ }
7
+ }
8
+
9
+ #license_options_container {
10
+ table {
11
+ &, select, #available_license_key {
12
+ width: 100%;
13
+ }
14
+
15
+ td:first-child {
16
+ width: 1%;
17
+ }
18
+
19
+ #other_license_key_container {
20
+ label {
21
+ position: relative;
22
+ top: 6px;
23
+ float: left;
24
+ margin-right: 5px;
25
+ }
26
+
27
+ div {
28
+ overflow: hidden;
29
+ width: auto;
30
+ height: 30px;
31
+ display: block;
32
+ top: 2px;
33
+ position: relative;
34
+
35
+ input {
36
+ margin: 0;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ #sites_list_container {
44
+ td {
45
+ cursor: pointer;
46
+ }
47
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_license-key-resend.scss ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-key-resend
2
+ {
3
+ .email-address-container
4
+ {
5
+ overflow: hidden;
6
+ padding-right: 2px;
7
+ }
8
+
9
+ &.fs-freemium
10
+ {
11
+ input.email-address
12
+ {
13
+ width: 300px;
14
+ }
15
+
16
+ label
17
+ {
18
+ display: block;
19
+ margin-bottom: 10px;
20
+ }
21
+ }
22
+
23
+ &.fs-premium
24
+ {
25
+ input.email-address
26
+ {
27
+ width: 100%;
28
+ }
29
+
30
+ .button-container
31
+ {
32
+ float: right;
33
+ margin-left: 7px;
34
+
35
+ @media (max-width: 650px) {
36
+ margin-top: 2px;
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ .rtl
43
+ {
44
+ .fs-modal.fs-modal-license-key-resend
45
+ {
46
+ .fs-modal-body
47
+ {
48
+ .input-container > .email-address-container
49
+ {
50
+ padding-left: 2px;
51
+ padding-right: 0;
52
+ }
53
+
54
+ .button-container
55
+ {
56
+ float: left;
57
+ margin-right: 7px;
58
+ margin-left: 0;
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ a.show-license-resend-modal
65
+ {
66
+ margin-top: 4px;
67
+ display: inline-block;
68
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_modal-common.scss ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+ @import "../mixins";
3
+
4
+ .fs-modal {
5
+ position: fixed;
6
+ overflow: auto;
7
+ height: 100%;
8
+ width: 100%;
9
+ top: 0;
10
+ z-index: 100000;
11
+ display: none;
12
+ background: rgba(0, 0, 0, 0.6);
13
+
14
+ .fs-modal-dialog {
15
+ background: transparent;
16
+ position: absolute;
17
+ left: 50%;
18
+ margin-left: -298px;
19
+ padding-bottom: 30px;
20
+ top: -100%;
21
+ z-index: 100001;
22
+ width: 596px;
23
+
24
+ @media (max-width: 650px) {
25
+ margin-left: -50%;
26
+ box-sizing: border-box;
27
+ padding-left: 10px;
28
+ padding-right: 10px;
29
+ width: 100%;
30
+
31
+ .fs-modal-panel > h3 > strong {
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+
37
+ &.active {
38
+ display: block;
39
+
40
+ &:before {
41
+ display: block;
42
+ }
43
+
44
+ .fs-modal-dialog {
45
+ top: 10%;
46
+ }
47
+ }
48
+
49
+ &.fs-success {
50
+ .fs-modal-header {
51
+ border-bottom-color: $wp-notice-success-dark-color;
52
+ }
53
+
54
+ .fs-modal-body {
55
+ background-color: $wp-notice-success-color;
56
+ }
57
+ }
58
+
59
+ &.fs-warn {
60
+ .fs-modal-header {
61
+ border-bottom-color: $wp-notice-warn-dark-color;
62
+ }
63
+
64
+ .fs-modal-body {
65
+ background-color: $wp-notice-warn-color;
66
+ }
67
+ }
68
+
69
+ &.fs-error {
70
+ .fs-modal-header {
71
+ border-bottom-color: $wp-notice-error-dark-color;
72
+ }
73
+
74
+ .fs-modal-body {
75
+ background-color: $wp-notice-error-color;
76
+ }
77
+ }
78
+
79
+
80
+ .fs-modal-body,
81
+ .fs-modal-footer {
82
+ border: 0;
83
+ background: #fefefe;
84
+ padding: 20px;
85
+ }
86
+
87
+ .fs-modal-header {
88
+ border-bottom: #eeeeee solid 1px;
89
+ background: #fbfbfb;
90
+ padding: 15px 20px;
91
+ position: relative;
92
+ margin-bottom: -10px;
93
+ // z-index: 2;
94
+
95
+ h4 {
96
+ margin: 0;
97
+ padding: 0;
98
+ text-transform: uppercase;
99
+ font-size: 1.2em;
100
+ font-weight: bold;
101
+ color: #cacaca;
102
+ text-shadow: 1px 1px 1px #fff;
103
+ letter-spacing: 0.6px;
104
+ -webkit-font-smoothing: antialiased;
105
+ }
106
+
107
+ .fs-close {
108
+ position: absolute;
109
+ right: 10px;
110
+ top: 12px;
111
+ cursor: pointer;
112
+ color: #bbb;
113
+ @include border-radius(20px);
114
+ padding: 3px;
115
+ @include transition(all 0.2s ease-in-out);
116
+
117
+ &:hover {
118
+ color: #fff;
119
+ background: #aaa;
120
+ }
121
+
122
+ &, &:hover
123
+ {
124
+ .dashicons
125
+ {
126
+ text-decoration: none;
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ .fs-modal-body {
133
+ border-bottom: 0;
134
+
135
+ p {
136
+ font-size: 14px;
137
+ }
138
+
139
+ h2 {
140
+ font-size: 20px;
141
+ line-height: 1.5em;
142
+ }
143
+
144
+ > div {
145
+ margin-top: 10px;
146
+
147
+ h2 {
148
+ font-weight: bold;
149
+ font-size: 20px;
150
+ margin-top: 0;
151
+ }
152
+ }
153
+ }
154
+
155
+ .fs-modal-footer {
156
+ border-top: #eeeeee solid 1px;
157
+ text-align: right;
158
+
159
+ > .button {
160
+ margin: 0 7px;
161
+
162
+ &:first-child {
163
+ margin: 0;
164
+ }
165
+ }
166
+ }
167
+
168
+ .fs-modal-panel {
169
+ > .notice.inline {
170
+ margin: 0;
171
+ display: none;
172
+ }
173
+
174
+ &:not(.active) {
175
+ display: none;
176
+ }
177
+ }
178
+ }
179
+
180
+ .rtl
181
+ {
182
+ .fs-modal {
183
+ .fs-modal-header {
184
+ .fs-close {
185
+ right: auto;
186
+ left: 20px;
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ body.has-fs-modal {
193
+ overflow: hidden;
194
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_multisite-options.scss ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #multisite_options_container {
2
+ margin-top: 10px;
3
+ border: 1px solid #ccc;
4
+ padding: 5px;
5
+
6
+ a {
7
+ text-decoration: none;
8
+
9
+ &:focus {
10
+ box-shadow: none;
11
+ }
12
+
13
+ &.selected {
14
+ font-weight: bold;
15
+ }
16
+ }
17
+
18
+ &.apply-on-all-sites {
19
+ border: 0 none;
20
+ padding: 0;
21
+
22
+ #all_sites_options {
23
+ border-spacing: 0;
24
+
25
+ td:not(:first-child) {
26
+ display: none;
27
+ }
28
+ }
29
+ }
30
+
31
+ #sites_list_container {
32
+ display: none;
33
+ overflow: auto;
34
+
35
+ table td {
36
+ border-top: 1px solid #ccc;
37
+ padding: 4px 2px;
38
+ }
39
+ }
40
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_themes.scss ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .theme-browser
2
+ {
3
+ .theme
4
+ {
5
+ .fs-premium-theme-badge
6
+ {
7
+ position: absolute;
8
+ top: 10px;
9
+ right: 0;
10
+ background: $fs-logo-green-color;
11
+ color: #fff;
12
+ text-transform: uppercase;
13
+ padding: 5px 10px;
14
+ @include border-radius(3px 0 0 3px);
15
+ font-weight: bold;
16
+ border-right: 0;
17
+ @include box-shadow(0 2px 1px -1px rgba(0, 0, 0, .3));
18
+ font-size: 1.1em;
19
+ }
20
+ }
21
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/_tooltip.scss ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-tooltip-trigger
2
+ {
3
+ &:not(a)
4
+ {
5
+ cursor: help;
6
+ }
7
+
8
+ position: relative;
9
+
10
+ .fs-tooltip
11
+ {
12
+ opacity: 0;
13
+ visibility: hidden;
14
+ @include transition(opacity 0.3s ease-in-out);
15
+ position: absolute;
16
+ background: $tooltip-bkg-color;
17
+ color: $tooltip-color;
18
+ font-family: 'arial', serif;
19
+ font-size: 12px;
20
+ padding: 10px;
21
+ z-index: 999999;
22
+ bottom: 100%;
23
+ margin-bottom: 5px;
24
+ left: 0;
25
+ right: 0;
26
+ @include border-radius(5px);
27
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
28
+ line-height: 1.3em;
29
+ font-weight: bold;
30
+ text-align: left;
31
+
32
+ .rtl &
33
+ {
34
+ text-align: right;
35
+ }
36
+
37
+ &::after
38
+ {
39
+ content: ' ';
40
+ display: block;
41
+ width: 0;
42
+ height: 0;
43
+ border-style: solid;
44
+ border-width: 5px 5px 0 5px;
45
+ border-color: $tooltip-bkg-color transparent transparent transparent;
46
+ position: absolute;
47
+ top: 100%;
48
+ left: 21px;
49
+
50
+ .rtl &
51
+ {
52
+ right: 21px;
53
+ left: auto;
54
+ }
55
+ }
56
+ }
57
+
58
+ &:hover
59
+ {
60
+ .fs-tooltip
61
+ {
62
+ visibility: visible;
63
+ opacity: 1;
64
+ }
65
+ }
66
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/account.scss ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_account
4
+ {
5
+ .postbox,
6
+ .widefat
7
+ {
8
+ max-width: 700px;
9
+ }
10
+
11
+ h3
12
+ {
13
+ font-size: 1.3em;
14
+ padding: 12px 15px;
15
+ margin: 0 0 12px 0;
16
+ line-height: 1.4;
17
+ border-bottom: 1px solid #F1F1F1;
18
+
19
+ .dashicons {
20
+ width: 26px;
21
+ height: 26px;
22
+ font-size: 1.3em;
23
+ }
24
+ }
25
+
26
+ i.dashicons
27
+ {
28
+ font-size: 1.2em;
29
+ height: 1.2em;
30
+ width: 1.2em;
31
+ }
32
+
33
+ .dashicons
34
+ {
35
+ vertical-align: middle;
36
+ }
37
+
38
+ .fs-header-actions
39
+ {
40
+ position: absolute;
41
+ top: 17px;
42
+ right: 15px;
43
+ font-size: 0.9em;
44
+
45
+ ul
46
+ {
47
+ margin: 0;
48
+ }
49
+
50
+ li
51
+ {
52
+ form
53
+ {
54
+ display: inline-block;
55
+ }
56
+
57
+ float: left;
58
+ a
59
+ {
60
+ text-decoration: none;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ #fs_account_details .button-group {
67
+ float: right;
68
+ }
69
+
70
+ .rtl #fs_account .fs-header-actions
71
+ {
72
+ left: 15px;
73
+ right: auto;
74
+ }
75
+
76
+ .fs-key-value-table
77
+ {
78
+ width: 100%;
79
+
80
+ form
81
+ {
82
+ display: inline-block;
83
+ }
84
+
85
+ tr
86
+ {
87
+ td:first-child
88
+ {
89
+ nobr
90
+ {
91
+ font-weight: bold;
92
+ }
93
+
94
+ text-align: right;
95
+
96
+ form
97
+ {
98
+ display: block;
99
+ }
100
+ }
101
+
102
+ td.fs-right
103
+ {
104
+ text-align: right;
105
+ }
106
+
107
+ &.fs-odd
108
+ {
109
+ background: #ebebeb;
110
+ }
111
+ }
112
+
113
+ td, th
114
+ {
115
+ padding: 10px;
116
+ }
117
+
118
+ code {
119
+ line-height: 28px;
120
+ }
121
+
122
+ var, code, input[type="text"]
123
+ {
124
+ color: #0073AA;
125
+ font-size: 16px;
126
+ background: none;
127
+ }
128
+
129
+ input[type="text"] {
130
+ width: 100%;
131
+ font-weight: bold;
132
+ }
133
+ }
134
+
135
+ label.fs-tag
136
+ {
137
+ background: #ffba00;
138
+ color: #fff;
139
+ display: inline-block;
140
+ border-radius: 3px;
141
+ padding: 5px;
142
+ font-size: 11px;
143
+ line-height: 11px;
144
+ vertical-align: baseline;
145
+
146
+ &.fs-warn
147
+ {
148
+ background: #ffba00;
149
+ }
150
+ &.fs-success
151
+ {
152
+ background: #46b450;
153
+ }
154
+ &.fs-error
155
+ {
156
+ background: #dc3232;
157
+ }
158
+ }
159
+
160
+ #fs_sites
161
+ {
162
+ .fs-scrollable-table
163
+ {
164
+ .fs-table-body {
165
+ max-height: 200px;
166
+ overflow: auto;
167
+ border: 1px solid #e5e5e5;
168
+
169
+ & > table.widefat {
170
+ border: none !important;
171
+ }
172
+ }
173
+
174
+ .fs-main-column {
175
+ width: 100%;
176
+ }
177
+
178
+ .fs-site-details
179
+ {
180
+ td:first-of-type
181
+ {
182
+ text-align: right;
183
+ color: grey;
184
+ width: 1px;
185
+ }
186
+
187
+ td:last-of-type
188
+ {
189
+ text-align: right;
190
+ }
191
+ }
192
+
193
+ .fs-install-details table
194
+ {
195
+ tr td
196
+ {
197
+ width: 1px;
198
+ white-space: nowrap;
199
+
200
+ &:last-of-type
201
+ {
202
+ width: auto;
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+
209
+ #fs_addons
210
+ {
211
+ h3
212
+ {
213
+ border: none;
214
+ margin-bottom: 0;
215
+ padding: 4px 5px;
216
+ }
217
+
218
+ td
219
+ {
220
+ vertical-align: middle;
221
+ }
222
+
223
+ thead {
224
+ white-space: nowrap;
225
+ }
226
+
227
+ td:first-child,
228
+ th:first-child
229
+ {
230
+ text-align: left;
231
+ font-weight: bold;
232
+ }
233
+ td:last-child,
234
+ th:last-child
235
+ {
236
+ text-align: right;
237
+ }
238
+ th
239
+ {
240
+ font-weight: bold;
241
+ }
242
+ }
243
+
244
+ #fs_billing_address {
245
+ width: 100%;
246
+
247
+ tr {
248
+ td {
249
+ width: 50%;
250
+ padding: 5px;
251
+ }
252
+
253
+ &:first-of-type {
254
+ td {
255
+ padding-top: 0;
256
+ }
257
+ }
258
+ }
259
+
260
+ @mixin read-mode {
261
+ border-color: transparent;
262
+ color: #777;
263
+ border-bottom: 1px dashed #ccc;
264
+ padding-left: 0;
265
+ background: none;
266
+ }
267
+
268
+ span {
269
+ font-weight: bold;
270
+ }
271
+
272
+ input, select {
273
+ @include placeholder(transparent);
274
+
275
+ display: block;
276
+ width: 100%;
277
+ margin-top: 5px;
278
+
279
+ &.fs-read-mode {
280
+ @include read-mode();
281
+ }
282
+ }
283
+
284
+
285
+ &.fs-read-mode {
286
+ td span {
287
+ display: none;
288
+ }
289
+
290
+ input, select
291
+ {
292
+ @include read-mode();
293
+ @include placeholder(#ccc);
294
+ }
295
+ }
296
+
297
+
298
+ button {
299
+ display: block;
300
+ width: 100%;
301
+ }
302
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/add-ons.scss ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_addons
4
+ {
5
+ .fs-cards-list
6
+ {
7
+ list-style: none;
8
+
9
+ .fs-card
10
+ {
11
+ float: left;
12
+ // height: 185px; // With reviews/ratings
13
+ height: 152px;
14
+ width: 310px;
15
+ padding: 0;
16
+ margin: 0 0 30px 30px;
17
+ font-size: 14px;
18
+ list-style: none;
19
+ border: 1px solid #ddd;
20
+ cursor: pointer;
21
+ position: relative;
22
+
23
+ .fs-overlay
24
+ {
25
+ position: absolute;
26
+ left: 0;
27
+ right: 0;
28
+ bottom: 0;
29
+ top: 0;
30
+ z-index: 9;
31
+ }
32
+
33
+ .fs-inner
34
+ {
35
+ background-color: #fff;
36
+ overflow: hidden;
37
+ height: 100%;
38
+ position: relative;
39
+
40
+ ul
41
+ {
42
+ @include transition(all, 0.15s);
43
+ left: 0;
44
+ right: 0;
45
+ top: 0;
46
+ position: absolute;
47
+ }
48
+
49
+ li
50
+ {
51
+ list-style: none;
52
+ line-height: 18px;
53
+ padding: 0 15px;
54
+ width: 100%;
55
+ display: block;
56
+ @include box-sizing(border-box);
57
+ }
58
+
59
+ .fs-card-banner
60
+ {
61
+ padding: 0;
62
+ margin: 0;
63
+ line-height: 0;
64
+ display: block;
65
+ height: 100px;
66
+ background-repeat: repeat-x;
67
+ background-size: 100% 100%;
68
+ @include transition(all, 0.15s);
69
+ }
70
+
71
+ .fs-title
72
+ {
73
+ margin: 10px 0 0 0;
74
+ height: 18px;
75
+ overflow: hidden;
76
+ color: #000;
77
+ white-space: nowrap;
78
+ text-overflow: ellipsis;
79
+ font-weight: bold;
80
+ }
81
+
82
+ .fs-offer
83
+ {
84
+ font-size: 0.9em;
85
+ }
86
+
87
+ .fs-description
88
+ {
89
+ background-color: #f9f9f9;
90
+ padding: 10px 15px 100px 15px;
91
+ border-top: 1px solid #eee;
92
+ margin: 0 0 10px 0;
93
+ color: #777;
94
+ }
95
+
96
+ .fs-tag
97
+ {
98
+ position: absolute;
99
+ top: 10px;
100
+ right: 0px;
101
+ background: greenyellow;
102
+ display: block;
103
+ padding: 2px 10px;
104
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.3));
105
+ text-transform: uppercase;
106
+ font-size: 0.9em;
107
+ font-weight: bold;
108
+ }
109
+
110
+ .fs-cta
111
+ {
112
+ .button
113
+ {
114
+ position: absolute;
115
+ top: 112px;
116
+ right: 10px;
117
+ }
118
+ }
119
+ }
120
+
121
+ @media screen and (min-width: 960px) {
122
+ &:hover
123
+ {
124
+ .fs-overlay
125
+ {
126
+ border: 2px solid $fms-link-color;
127
+ margin-left: -1px;
128
+ margin-top: -1px;
129
+ }
130
+
131
+ .fs-inner
132
+ {
133
+ ul
134
+ {
135
+ top: -100px;
136
+ }
137
+
138
+ .fs-card-banner
139
+ {
140
+ // background-position: 50% -100px;
141
+ }
142
+
143
+ .fs-title,
144
+ .fs-offer
145
+ {
146
+ color: $fms-link-color;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ #TB_window
156
+ {
157
+ &, iframe
158
+ {
159
+ width: 772px !important;
160
+ }
161
+ }
162
+
163
+ #plugin-information
164
+ {
165
+ #section-description
166
+ {
167
+ h2, h3, p, b, i, blockquote, li, ul, ol
168
+ {
169
+ clear: none;
170
+ }
171
+
172
+ .fs-selling-points
173
+ {
174
+ padding-bottom: 10px;
175
+ border-bottom: 1px solid #ddd;
176
+
177
+ ul
178
+ {
179
+ margin: 0;
180
+
181
+ li
182
+ {
183
+ padding: 0;
184
+ list-style: none outside none;
185
+
186
+ i.dashicons
187
+ {
188
+ color: $fs-logo-green-color;
189
+ font-size: 3em;
190
+ vertical-align: middle;
191
+ line-height: 30px;
192
+ float: left;
193
+ margin: 0 0 0 -15px;
194
+ }
195
+
196
+ h3
197
+ {
198
+ margin: 1em 30px !important;
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ .fs-screenshots
205
+ {
206
+ @include clearfix();
207
+ ul
208
+ {
209
+ list-style: none;
210
+ margin: 0;
211
+
212
+ li
213
+ {
214
+ width: 225px;
215
+ height: 225px;
216
+ float: left;
217
+ margin-bottom: 20px;
218
+ @include box-sizing(content-box);
219
+
220
+ a
221
+ {
222
+ display: block;
223
+ width: 100%;
224
+ height: 100%;
225
+ border: 1px solid;
226
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
227
+ background-size: cover;
228
+ }
229
+
230
+ &.odd
231
+ {
232
+ margin-right: 20px;
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ .plugin-information-pricing
240
+ {
241
+ $pricing_color: #FFFEEC;
242
+ $borders_color: #DDD;
243
+ margin: -16px;
244
+ // padding: 20px;
245
+ border-bottom: 1px solid $borders_color;
246
+
247
+ .fs-plan
248
+ {
249
+
250
+ h3
251
+ {
252
+ margin-top: 0;
253
+ padding: 20px;
254
+ font-size: 16px;
255
+ }
256
+
257
+ .nav-tab-wrapper
258
+ {
259
+ border-bottom: 1px solid $borders_color;
260
+
261
+ .nav-tab
262
+ {
263
+ cursor: pointer;
264
+ position: relative;
265
+ padding: 0 10px;
266
+ font-size: 0.9em;
267
+
268
+ label
269
+ {
270
+ text-transform: uppercase;
271
+ color: green;
272
+ background: greenyellow;
273
+ position: absolute;
274
+ left: -1px;
275
+ right: -1px;
276
+ bottom: 100%;
277
+ border: 1px solid darkgreen;
278
+ padding: 2px;
279
+ text-align: center;
280
+ font-size: 0.9em;
281
+ line-height: 1em;
282
+ }
283
+
284
+ &.nav-tab-active
285
+ {
286
+ cursor: default;
287
+ background: $pricing_color;
288
+ border-bottom-color: $pricing_color;
289
+ }
290
+ }
291
+ }
292
+
293
+ &.fs-single-cycle
294
+ {
295
+ h3
296
+ {
297
+ background: $pricing_color;
298
+ margin: 0;
299
+ padding-bottom: 0;
300
+ color: #0073aa;
301
+ }
302
+
303
+ .nav-tab-wrapper,
304
+ .fs-billing-frequency
305
+ {
306
+ display: none;
307
+ }
308
+ }
309
+
310
+ .fs-pricing-body
311
+ {
312
+ background: $pricing_color;
313
+ padding: 20px;
314
+ }
315
+
316
+ .button
317
+ {
318
+ width: 100%;
319
+ text-align: center;
320
+ font-weight: bold;
321
+ text-transform: uppercase;
322
+ font-size: 1.1em;
323
+ }
324
+
325
+ label
326
+ {
327
+ white-space: nowrap;
328
+ }
329
+
330
+ var {
331
+ font-style: normal;
332
+ }
333
+
334
+ .fs-billing-frequency,
335
+ .fs-annual-discount
336
+ {
337
+ text-align: center;
338
+ display: block;
339
+ font-weight: bold;
340
+ margin-bottom: 10px;
341
+ text-transform: uppercase;
342
+ background: #F3F3F3;
343
+ padding: 2px;
344
+ border: 1px solid #ccc;
345
+ }
346
+
347
+ .fs-annual-discount
348
+ {
349
+ text-transform: none;
350
+ color: green;
351
+ background: greenyellow;
352
+ }
353
+
354
+ ul.fs-trial-terms
355
+ {
356
+ font-size: 0.9em;
357
+
358
+ i
359
+ {
360
+ float: left;
361
+ margin: 0 0 0 -15px;
362
+ }
363
+
364
+ li
365
+ {
366
+ margin: 10px 0 0 0;
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ #section-features
373
+ {
374
+ .fs-features
375
+ {
376
+ margin: -20px -26px;
377
+ }
378
+
379
+ table
380
+ {
381
+ width: 100%;
382
+ border-spacing: 0;
383
+ border-collapse: separate;
384
+
385
+ thead
386
+ {
387
+ th
388
+ {
389
+ padding: 10px 0;
390
+ }
391
+
392
+ .fs-price
393
+ {
394
+ color: $fs-logo-green-color;
395
+ font-weight: normal;
396
+ display: block;
397
+ text-align: center;
398
+ }
399
+ }
400
+
401
+ tbody
402
+ {
403
+ td
404
+ {
405
+ border-top: 1px solid #ccc;
406
+ padding: 10px 0;
407
+ text-align: center;
408
+ width: 100px;
409
+ color: $fs-logo-green-color;
410
+
411
+ &:first-child
412
+ {
413
+ text-align: left;
414
+ width: auto;
415
+ color: inherit;
416
+ padding-left: 26px;
417
+ }
418
+ }
419
+ tr.fs-odd
420
+ {
421
+ td
422
+ {
423
+ background: #fefefe;
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ .dashicons-yes
430
+ {
431
+ width: 30px;
432
+ height: 30px;
433
+ font-size: 30px;
434
+ }
435
+ }
436
+ }
437
+
438
+ @media screen and (max-width: 961px) {
439
+ #fs_addons
440
+ {
441
+ .fs-cards-list
442
+ {
443
+ .fs-card
444
+ {
445
+ height: 265px;
446
+ }
447
+ }
448
+ }
449
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/affiliation.scss ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_affiliation_content_wrapper {
4
+ #messages {
5
+ margin-top: 25px;
6
+ }
7
+
8
+ h3 {
9
+ font-size: 24px;
10
+ padding: 0;
11
+ margin-left: 0;
12
+ }
13
+
14
+ ul {
15
+ li {
16
+ @include box-sizing(border-box);
17
+ list-style-type: none;
18
+
19
+ &:before {
20
+ content: '✓';
21
+ margin-right: 10px;
22
+ font-weight: bold;
23
+ }
24
+ }
25
+ }
26
+
27
+ p:not(.description), li, label {
28
+ font-size: 16px !important;
29
+ line-height: 26px !important;
30
+ }
31
+
32
+ .button {
33
+ margin-top: 20px;
34
+ margin-bottom: 7px;
35
+ line-height: 35px;
36
+ height: 40px;
37
+ font-size: 16px;
38
+
39
+ &#cancel_button {
40
+ margin-right: 5px;
41
+ }
42
+ }
43
+
44
+ form {
45
+ .input-container {
46
+ .input-label {
47
+ font-weight: bold;
48
+ display: block;
49
+ width: 100%;
50
+ }
51
+
52
+ &.input-container-text {
53
+ label, input, textarea {
54
+ display: block;
55
+ }
56
+ }
57
+
58
+ margin-bottom: 15px;
59
+
60
+ #add_domain, .remove-domain {
61
+ text-decoration: none;
62
+ display: inline-block;
63
+ margin-top: 3px;
64
+
65
+ &:focus {
66
+ box-shadow: none;
67
+ }
68
+
69
+ &.disabled {
70
+ color: #aaa;
71
+ cursor: default;
72
+ }
73
+ }
74
+ }
75
+
76
+ #extra_domains_container {
77
+ .description {
78
+ margin-top: 0;
79
+ position: relative;
80
+ top: -4px;
81
+ }
82
+
83
+ .extra-domain-input-container {
84
+ margin-bottom: 15px;
85
+
86
+ .domain {
87
+ display: inline-block;
88
+ margin-right: 5px;
89
+
90
+ &:last-of-type {
91
+ margin-bottom: 0;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/checkout.scss ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ @media screen and (max-width: 782px) {
2
+ #wpbody-content {
3
+ padding-bottom: 0 !important;
4
+ }
5
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/common.scss ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "themes";
3
+
4
+ #iframe
5
+ {
6
+ line-height: 0;
7
+ font-size: 0;
8
+ }
9
+
10
+ .fs-full-size-wrapper
11
+ {
12
+ margin: 40px 0 -65px -20px;
13
+
14
+ @media (max-width: 600px) {
15
+ margin: 0 0 -65px -10px;
16
+ }
17
+ }
18
+
19
+ .fs-notice
20
+ {
21
+ position: relative;
22
+
23
+ &.fs-has-title
24
+ {
25
+ margin-bottom: 30px !important;
26
+ }
27
+
28
+ &.success
29
+ {
30
+ color: green;
31
+ // font-weight: normal;
32
+ }
33
+
34
+ &.promotion
35
+ {
36
+ border-color: $fs-notice-promotion-border-color !important;
37
+ background-color: $fs-notice-promotion-bkg !important;
38
+ }
39
+
40
+ .fs-notice-body
41
+ {
42
+ margin: .5em 0;
43
+ padding: 2px;
44
+ }
45
+
46
+ .fs-close
47
+ {
48
+ // position: absolute;
49
+ // top: 2px;
50
+ // bottom: 2px;
51
+ // right: 2px;
52
+ // min-width: 100px;
53
+ // text-align: center;
54
+ // padding-right: 2px;
55
+ cursor: pointer;
56
+ color: #aaa;
57
+ float: right;
58
+
59
+ &:hover
60
+ {
61
+ color: #666;
62
+ // background: #A9A9A9;
63
+ }
64
+
65
+ > *
66
+ {
67
+ margin-top: 7px;
68
+ display: inline-block;
69
+ }
70
+ }
71
+
72
+ label.fs-plugin-title
73
+ {
74
+ background: rgba(0, 0, 0, 0.3);
75
+ color: #fff;
76
+ padding: 2px 10px;
77
+ position: absolute;
78
+ top: 100%;
79
+ bottom: auto;
80
+ right: auto;
81
+ @include border-radius(0 0 3px 3px);
82
+ left: 10px;
83
+ font-size: 12px;
84
+ font-weight: bold;
85
+ cursor: auto;
86
+ }
87
+ }
88
+
89
+ div.fs-notice
90
+ {
91
+ &.updated,
92
+ &.success,
93
+ &.promotion
94
+ {
95
+ display: block !important;
96
+ }
97
+ }
98
+
99
+ .rtl .fs-notice
100
+ {
101
+ .fs-close
102
+ {
103
+ // left: 2px;
104
+ // right: auto;
105
+ // padding-right: 0;
106
+ // padding-left: 2px;
107
+ float: left;
108
+ }
109
+ }
110
+
111
+ .fs-secure-notice
112
+ {
113
+ position: fixed;
114
+ top: 32px;
115
+ left: 160px;
116
+ right: 0;
117
+ background: rgb(235, 253, 235);
118
+ padding: 10px 20px;
119
+ color: green;
120
+ z-index: 9999;
121
+ @include box-shadow(0 2px 2px rgba(6, 113, 6, 0.3));
122
+ @include opacity(0.95);
123
+
124
+ &:hover
125
+ {
126
+ @include opacity(1);
127
+ }
128
+
129
+ a.fs-security-proof
130
+ {
131
+ color: green;
132
+ text-decoration: none;
133
+ }
134
+ }
135
+
136
+ @media screen and (max-width: 960px) {
137
+ .fs-secure-notice
138
+ {
139
+ left: 36px;
140
+ }
141
+ }
142
+
143
+ @media screen and (max-width: 600px) {
144
+ .fs-secure-notice
145
+ {
146
+ display: none;
147
+ }
148
+ }
149
+
150
+ @media screen and (max-width: 500px) {
151
+ #fs_promo_tab
152
+ {
153
+ display: none;
154
+ }
155
+ }
156
+
157
+ @media screen and (max-width: 782px) {
158
+ .fs-secure-notice
159
+ {
160
+ left: 0;
161
+ top: 46px;
162
+ text-align: center;
163
+ }
164
+ }
165
+
166
+ span.fs-submenu-item.fs-sub:before
167
+ {
168
+ // Add small arrow.
169
+ content: '\21B3';
170
+ padding: 0 5px;
171
+ }
172
+
173
+ .rtl
174
+ {
175
+ span.fs-submenu-item.fs-sub:before
176
+ {
177
+ // Add small RTL arrow.
178
+ content: '\21B2';
179
+ }
180
+ }
181
+
182
+ .fs-submenu-item
183
+ {
184
+ &.pricing
185
+ {
186
+ &.upgrade-mode
187
+ {
188
+ color: greenyellow;
189
+ }
190
+
191
+ &.trial-mode
192
+ {
193
+ color: #83e2ff;
194
+ }
195
+ }
196
+ }
197
+
198
+ #adminmenu .update-plugins.fs-trial
199
+ {
200
+ background-color: #00b9eb;
201
+ }
202
+ .fs-ajax-spinner
203
+ {
204
+ border: 0;
205
+ width: 20px;
206
+ height: 20px;
207
+ margin-right: 5px;
208
+ vertical-align: sub;
209
+ display: inline-block;
210
+ background: url('../../../../../../../wp-admin/images/wpspin_light-2x.gif');
211
+ background-size: contain;
212
+ }
213
+
214
+ .wrap.fs-section {
215
+ h2 {
216
+ text-align: left;
217
+ }
218
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/connect.scss ADDED
@@ -0,0 +1,548 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ $form_width: 480px;
4
+
5
+ #fs_connect
6
+ {
7
+ width: $form_width;
8
+ @include box-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
9
+ margin: 20px 0;
10
+
11
+ @media screen and (max-width: ($form_width - 1)) {
12
+ @include box-shadow(none);
13
+ width: auto;
14
+ margin: 0 0 0 -10px;
15
+ }
16
+
17
+ .fs-content
18
+ {
19
+ background: #fff;
20
+ padding: 15px 20px;
21
+
22
+ .fs-error {
23
+ background: snow;
24
+ color: $fs-logo-magenta-color;
25
+ border: 1px solid $fs-logo-magenta-color;
26
+ @include box-shadow(0 1px 1px 0 rgba(0,0,0,.1));
27
+ text-align: center;
28
+ padding: 5px;
29
+ margin-bottom: 10px;
30
+ }
31
+
32
+ p
33
+ {
34
+ margin: 0;
35
+ padding: 0;
36
+ font-size: 1.2em;
37
+ }
38
+ }
39
+
40
+ .fs-license-key-container {
41
+ position: relative;
42
+ width: 280px;
43
+ margin: 10px auto 0 auto;
44
+
45
+ input {
46
+ width: 100%;
47
+ }
48
+
49
+ .dashicons {
50
+ position: absolute;
51
+ top: 5px;
52
+ right: 5px;
53
+ }
54
+ }
55
+
56
+ &.require-license-key {
57
+ #sites_list_container {
58
+ td {
59
+ cursor: pointer;
60
+ }
61
+ }
62
+ }
63
+
64
+ #delegate_to_site_admins {
65
+ margin-right: 15px;
66
+ float: right;
67
+ height: 26px;
68
+ vertical-align: middle;
69
+ line-height: 37px;
70
+ font-weight: bold;
71
+ border-bottom: 1px dashed;
72
+ text-decoration: none;
73
+
74
+ &.rtl {
75
+ margin-left: 15px;
76
+ margin-right: 0;
77
+ }
78
+ }
79
+
80
+ .fs-actions
81
+ {
82
+ padding: 10px 20px;
83
+ background: #C0C7CA;
84
+
85
+ .button
86
+ {
87
+ padding: 0 10px 1px;
88
+ line-height: 35px;
89
+ height: 37px;
90
+ font-size: 16px;
91
+ margin-bottom: 0;
92
+
93
+ .dashicons
94
+ {
95
+ font-size: 37px;
96
+ margin-left: -8px;
97
+ margin-right: 12px;
98
+ }
99
+
100
+ &.button-primary
101
+ {
102
+ padding-right: 15px;
103
+ padding-left: 15px;
104
+
105
+ &:after
106
+ {
107
+ content: ' \279C';
108
+ }
109
+
110
+ &.fs-loading
111
+ {
112
+ &:after
113
+ {
114
+ content: '';
115
+ }
116
+ }
117
+ }
118
+
119
+ &.button-secondary
120
+ {
121
+ float: right;
122
+ }
123
+ }
124
+
125
+ // .fs-skip
126
+ // {
127
+ // line-height: 38px;
128
+ // vertical-align: middle;
129
+ // text-decoration: none;
130
+ // margin-left: 10px;
131
+ // }
132
+ }
133
+
134
+ &.fs-anonymous-disabled
135
+ {
136
+ .fs-actions
137
+ {
138
+ .button.button-primary
139
+ {
140
+ width: 100%;
141
+ }
142
+ }
143
+ }
144
+
145
+ .fs-permissions
146
+ {
147
+ padding: 10px 20px;
148
+ background: #FEFEFE;
149
+ // background: #F1F1F1;
150
+ @include transition(background 0.5s ease);
151
+
152
+ .fs-license-sync-disclaimer {
153
+ text-align: center;
154
+ margin-top: 0;
155
+ }
156
+
157
+ .fs-trigger
158
+ {
159
+ font-size: 0.9em;
160
+ text-decoration: none;
161
+ text-align: center;
162
+ display: block;
163
+ }
164
+
165
+ ul
166
+ {
167
+ height: 0;
168
+ overflow: hidden;
169
+ margin: 0;
170
+
171
+ li
172
+ {
173
+ margin-bottom: 12px;
174
+
175
+ &:last-child
176
+ {
177
+ margin-bottom: 0;
178
+ }
179
+
180
+ i.dashicons
181
+ {
182
+ float: left;
183
+ font-size: 40px;
184
+ width: 40px;
185
+ height: 40px;
186
+ }
187
+
188
+ div
189
+ {
190
+ margin-left: 55px;
191
+
192
+ span
193
+ {
194
+ font-weight: bold;
195
+ text-transform: uppercase;
196
+ color: #23282d;
197
+ }
198
+
199
+ p
200
+ {
201
+ margin: 2px 0 0 0;
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ &.fs-open
208
+ {
209
+ background: #fff;
210
+
211
+ ul
212
+ {
213
+ height: auto;
214
+ margin: 20px 20px 10px 20px;
215
+ }
216
+ }
217
+
218
+ @media screen and (max-width: ($form_width - 1)) {
219
+ background: #fff;
220
+
221
+ .fs-trigger
222
+ {
223
+ display: none;
224
+ }
225
+
226
+ ul
227
+ {
228
+ height: auto;
229
+ margin: 20px;
230
+ }
231
+ }
232
+ }
233
+
234
+ .fs-freemium-licensing {
235
+ padding: 8px;
236
+ // background: #0085BA;
237
+ background: #777;
238
+ color: #fff;
239
+
240
+ p {
241
+ text-align: center;
242
+ display: block;
243
+ margin: 0;
244
+ padding: 0;
245
+ }
246
+
247
+ a {
248
+ color: #C2EEFF;
249
+ text-decoration: underline;
250
+ }
251
+ }
252
+
253
+ $icon_size: 80px;
254
+ $wp_logo_padding: $icon_size / 10;
255
+ $icons_top: 10px;
256
+
257
+ .fs-visual
258
+ {
259
+ padding: 12px;
260
+ line-height: 0;
261
+ background: #fafafa;
262
+ height: $icon_size;
263
+ position: relative;
264
+
265
+ .fs-site-icon
266
+ {
267
+ position: absolute;
268
+ left: 20px;
269
+ top: $icons_top;
270
+ }
271
+
272
+ .fs-connect-logo
273
+ {
274
+ position: absolute;
275
+ right: 20px;
276
+ top: $icons_top;
277
+ }
278
+
279
+ .fs-plugin-icon
280
+ {
281
+ position: absolute;
282
+ top: $icons_top;
283
+ left: 50%;
284
+ margin-left: - ($icon_size / 2);
285
+ }
286
+
287
+ .fs-plugin-icon,
288
+ .fs-site-icon,
289
+ img,
290
+ object
291
+ {
292
+ width: $icon_size;
293
+ height: $icon_size;
294
+ }
295
+
296
+ .dashicons-wordpress
297
+ {
298
+ font-size: $icon_size - ($wp_logo_padding * 2);
299
+ background: $wordpress_color;
300
+ color: #fff;
301
+ width: $icon_size - ($wp_logo_padding * 2);
302
+ height: $icon_size - ($wp_logo_padding * 2);
303
+ padding: $wp_logo_padding;
304
+ }
305
+
306
+ .dashicons-plus
307
+ {
308
+ position: absolute;
309
+ top: 50%;
310
+ font-size: 30px;
311
+ margin-top: -10px;
312
+ color: #bbb;
313
+
314
+ &.fs-first
315
+ {
316
+ left: 28%;
317
+ }
318
+ &.fs-second
319
+ {
320
+ left: 65%;
321
+ }
322
+ }
323
+
324
+ .fs-plugin-icon,
325
+ .fs-connect-logo,
326
+ .fs-site-icon
327
+ {
328
+ border: 1px solid #ccc;
329
+ padding: 1px;
330
+ background: #fff;
331
+ }
332
+ }
333
+
334
+ .fs-terms
335
+ {
336
+ text-align: center;
337
+ font-size: 0.85em;
338
+ padding: 5px;
339
+ background: rgba(0, 0, 0, 0.05);
340
+
341
+ &, a
342
+ {
343
+ color: #999;
344
+ }
345
+
346
+ a
347
+ {
348
+ text-decoration: none;
349
+ }
350
+ }
351
+ }
352
+
353
+ @import "multisite-options";
354
+ @import "tooltip";
355
+ @import "gdpr-consent";
356
+
357
+ .rtl
358
+ {
359
+ #fs_connect
360
+ {
361
+ .fs-actions
362
+ {
363
+ padding: 10px 20px;
364
+ background: #C0C7CA;
365
+
366
+ .button
367
+ {
368
+ .dashicons
369
+ {
370
+ font-size: 37px;
371
+ margin-left: -8px;
372
+ margin-right: 12px;
373
+ }
374
+
375
+ &.button-primary
376
+ {
377
+ &:after
378
+ {
379
+ content: ' \000bb';
380
+ }
381
+
382
+ &.fs-loading
383
+ {
384
+ &:after
385
+ {
386
+ content: '';
387
+ }
388
+ }
389
+ }
390
+
391
+ &.button-secondary
392
+ {
393
+ float: left;
394
+ }
395
+ }
396
+ }
397
+
398
+ .fs-permissions
399
+ {
400
+ ul
401
+ {
402
+ li
403
+ {
404
+ div
405
+ {
406
+ margin-right: 55px;
407
+ margin-left: 0;
408
+ }
409
+
410
+ i.dashicons
411
+ {
412
+ float: right;
413
+ }
414
+
415
+ }
416
+ }
417
+ }
418
+
419
+ .fs-visual
420
+ {
421
+ .fs-site-icon
422
+ {
423
+ right: 20px;
424
+ left: auto;
425
+ }
426
+
427
+ .fs-connect-logo
428
+ {
429
+ right: auto;
430
+ left: 20px;
431
+ }
432
+ }
433
+ }
434
+ }
435
+
436
+ #fs_theme_connect_wrapper {
437
+ position: fixed;
438
+ top: 0;
439
+ height: 100%;
440
+ width: 100%;
441
+ z-index: 99990;
442
+ background: rgba(0, 0, 0, 0.75);
443
+ text-align: center;
444
+ overflow-y: auto;
445
+
446
+ &:before {
447
+ content: "";
448
+ display: inline-block;
449
+ vertical-align: middle;
450
+ height: 100%;
451
+ }
452
+
453
+ > button.close {
454
+ color: white;
455
+ cursor: pointer;
456
+ height: 40px;
457
+ width: 40px;
458
+ position: absolute;
459
+ right: 0;
460
+ border: 0;
461
+ background-color: transparent;
462
+ top: 32px;
463
+ }
464
+
465
+ #fs_connect {
466
+ top: 0;
467
+ text-align: left;
468
+ display: inline-block;
469
+ vertical-align: middle;
470
+ margin-top: 52px;
471
+ margin-bottom: 20px;
472
+
473
+ .fs-terms
474
+ {
475
+ background: rgba(140, 140, 140, 0.64);
476
+
477
+ &, a
478
+ {
479
+ color: #c5c5c5;
480
+ }
481
+ }
482
+ }
483
+ }
484
+
485
+ .wp-pointer-content
486
+ {
487
+ #fs_connect
488
+ {
489
+ margin: 0;
490
+ @include box-shadow(none);
491
+ }
492
+ }
493
+
494
+ .fs-opt-in-pointer
495
+ {
496
+ .wp-pointer-content
497
+ {
498
+ padding: 0;
499
+ }
500
+
501
+ &.wp-pointer-top
502
+ {
503
+ .wp-pointer-arrow
504
+ {
505
+ border-bottom-color: #dfdfdf;
506
+ }
507
+ .wp-pointer-arrow-inner
508
+ {
509
+ border-bottom-color: #fafafa;
510
+ }
511
+ }
512
+
513
+ &.wp-pointer-bottom
514
+ {
515
+ .wp-pointer-arrow
516
+ {
517
+ border-top-color: #dfdfdf;
518
+ }
519
+ .wp-pointer-arrow-inner
520
+ {
521
+ border-top-color: #fafafa;
522
+ }
523
+ }
524
+
525
+ &.wp-pointer-left
526
+ {
527
+ .wp-pointer-arrow
528
+ {
529
+ border-right-color: #dfdfdf;
530
+ }
531
+ .wp-pointer-arrow-inner
532
+ {
533
+ border-right-color: #fafafa;
534
+ }
535
+ }
536
+
537
+ &.wp-pointer-right
538
+ {
539
+ .wp-pointer-arrow
540
+ {
541
+ border-left-color: #dfdfdf;
542
+ }
543
+ .wp-pointer-arrow-inner
544
+ {
545
+ border-left-color: #fafafa;
546
+ }
547
+ }
548
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/debug.scss ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .switch
4
+ {
5
+ position: relative;
6
+ display: inline-block;
7
+ font-size: 1.6em;
8
+ font-weight: bold;
9
+ color: #ccc;
10
+ text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8);
11
+ height: 18px;
12
+ padding: 6px 6px 5px 6px;
13
+ border: 1px solid #ccc;
14
+ border: 1px solid rgba(0, 0, 0, 0.2);
15
+ border-radius: 4px;
16
+ background: #ececec;
17
+ box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
18
+ cursor: pointer;
19
+
20
+ span
21
+ {
22
+ display: inline-block; width: 35px;
23
+ text-transform: uppercase;
24
+
25
+ &.on
26
+ {
27
+ color: $button-primary-bkg;
28
+ }
29
+ }
30
+
31
+ .toggle
32
+ {
33
+ position: absolute;
34
+ top: 1px;
35
+ width: 37px;
36
+ height: 25px;
37
+ border: 1px solid #ccc;
38
+ border: 1px solid rgba(0, 0, 0, 0.3);
39
+ border-radius: 4px;
40
+ background: #fff;
41
+ background: -moz-linear-gradient(top, #ececec 0%, #fff 100%);
42
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));
43
+ background: -webkit-linear-gradient(top, #ececec 0%, #fff 100%);
44
+ background: -o-linear-gradient(top, #ececec 0%, #fff 100%);
45
+ background: -ms-linear-gradient(top, #ececec 0%, #fff 100%);
46
+ background: linear-gradient(top, #ececec 0%, #fff 100%);
47
+ box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, 0.5);
48
+ z-index: 999;
49
+ @include transition(all 0.15s ease-in-out);
50
+ }
51
+
52
+ &.on .toggle
53
+ {
54
+ left: 2%;
55
+ }
56
+ &.off .toggle
57
+ {
58
+ left: 54%;
59
+ }
60
+
61
+ /* Round switch */
62
+ &.round
63
+ {
64
+ padding: 0px 20px;
65
+ border-radius: 40px;
66
+
67
+ .toggle
68
+ {
69
+ border-radius: 40px;
70
+ width: 14px;
71
+ height: 14px;
72
+ }
73
+
74
+ &.on .toggle
75
+ {
76
+ left: 3%;
77
+ background: $button-primary-bkg;
78
+ }
79
+ &.off .toggle
80
+ {
81
+ left: 58%;
82
+ }
83
+ }
84
+ }
85
+
86
+ .switch-label
87
+ {
88
+ font-size: 20px;
89
+ line-height: 31px;
90
+ margin: 0 5px;
91
+ }
92
+
93
+ #fs_log_book {
94
+ table {
95
+ font-family: Consolas,Monaco,monospace;
96
+ font-size: 12px;
97
+
98
+ th {
99
+ color: #ccc;
100
+ }
101
+
102
+ tr {
103
+ background: #232525;
104
+
105
+ &.alternate {
106
+ background: #2b2b2b;
107
+ }
108
+
109
+ td {
110
+ &.fs-col--logger {
111
+ color: #5a7435;
112
+ }
113
+ &.fs-col--type {
114
+ color: #ffc861;
115
+ }
116
+ &.fs-col--function {
117
+ color: #a7b7b1;
118
+ font-weight: bold;
119
+ }
120
+ &.fs-col--message {
121
+ &, a
122
+ {
123
+ color: #9a73ac !important;
124
+ }
125
+ }
126
+ &.fs-col--file {
127
+ color: #d07922;
128
+ }
129
+ &.fs-col--timestamp {
130
+ color: #6596be;
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/dialog-boxes.scss ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "modal-common";
3
+ @import "deactivation-feedback";
4
+ @import "license-activation";
5
+ @import "multisite-options";
6
+ @import "license-key-resend";
7
+ @import "ajax-loader";
8
+ @import "auto-install";
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/gdpr-optin-notice.scss ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-notice[data-id^="gdpr_optin_actions"]
2
+ {
3
+ .underlined {
4
+ text-decoration: underline;
5
+ }
6
+
7
+ ul {
8
+ .button, .action-description {
9
+ vertical-align: middle;
10
+ }
11
+
12
+ .action-description {
13
+ display: inline-block;
14
+ margin-left: 3px;
15
+ }
16
+ }
17
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/customizer.scss ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "start";
2
+
3
+ #fs_customizer_upsell {
4
+ .fs-customizer-plan {
5
+ padding: 10px 20px 20px 20px;
6
+ border-radius: 3px;
7
+ background: #fff;
8
+
9
+ h2 {
10
+ position: relative;
11
+ margin: 0;
12
+ line-height: 2em;
13
+ text-transform: uppercase;
14
+
15
+ .button-link {
16
+ top: -2px;
17
+ }
18
+ }
19
+ }
20
+
21
+ .fs-feature {
22
+ position: relative;
23
+ }
24
+
25
+ .dashicons-yes {
26
+ color: #0085ba;
27
+ font-size: 2em;
28
+ vertical-align: bottom;
29
+ margin-left: -7px;
30
+ margin-right: 10px;
31
+
32
+ .rtl & {
33
+ margin-left: 10px;
34
+ margin-right: -7px;
35
+ }
36
+ }
37
+
38
+ .dashicons-editor-help
39
+ {
40
+ color: #bbb;
41
+ cursor: help;
42
+
43
+ $tooltip-color: #000;
44
+
45
+ .fs-feature-desc {
46
+ opacity: 0;
47
+ visibility: hidden;
48
+ @include transition(opacity 0.3s ease-in-out);
49
+
50
+ position: absolute;
51
+ background: $tooltip-color;
52
+ color: #fff;
53
+ font-family: 'arial', serif;
54
+ font-size: 12px;
55
+ padding: 10px;
56
+ z-index: 999999;
57
+ bottom: 100%;
58
+ margin-bottom: 5px;
59
+ left: 0;
60
+ right: 0;
61
+ @include border-radius(5px);
62
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.2));
63
+ line-height: 1.3em;
64
+ font-weight: bold;
65
+ text-align: left;
66
+
67
+ .rtl &
68
+ {
69
+ text-align: right;
70
+ }
71
+
72
+ &::after {
73
+ content: ' ';
74
+ display: block;
75
+ width: 0;
76
+ height: 0;
77
+ border-style: solid;
78
+ border-width: 5px 5px 0 5px;
79
+ border-color: $tooltip-color transparent transparent transparent;
80
+ position: absolute;
81
+ top: 100%;
82
+ left: 21px;
83
+
84
+ .rtl & {
85
+ right: 21px;
86
+ left: auto;
87
+ }
88
+ }
89
+ }
90
+
91
+ &:hover {
92
+ .fs-feature-desc {
93
+ visibility: visible;
94
+ opacity: 1;
95
+ }
96
+ }
97
+ }
98
+
99
+ .button-primary {
100
+ display: block;
101
+ text-align: center;
102
+ margin-top: 10px;
103
+ }
104
+ }
105
+
106
+ #fs_customizer_support
107
+ {
108
+ display: block !important;
109
+
110
+ .button {
111
+ float: right;
112
+ }
113
+
114
+ .button-group {
115
+ width: 100%;
116
+ display: block;
117
+ margin-top: 10px;
118
+
119
+ .button {
120
+ float: none;
121
+ width: 50%;
122
+ text-align: center;
123
+ }
124
+ }
125
+ }
trunk/includes/vendor/freemius/wordpress-sdk/assets/scss/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
trunk/includes/vendor/freemius/wordpress-sdk/config.php ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! defined( 'WP_FS__SLUG' ) ) {
14
+ define( 'WP_FS__SLUG', 'freemius' );
15
+ }
16
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
+ define( 'WP_FS__DEV_MODE', false );
18
+ }
19
+
20
+ #--------------------------------------------------------------------------------
21
+ #region API Connectivity Issues Simulation
22
+ #--------------------------------------------------------------------------------
23
+
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
+ }
33
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_CURL ) {
37
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
+ }
42
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
+ }
45
+
46
+ #endregion
47
+
48
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
+ }
51
+
52
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
+ /**
54
+ * @since 1.1.7.3
55
+ * @author Vova Feldman (@svovaf)
56
+ *
57
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
59
+ * between domains on a daily basis. Therefore, to eliminate the risk of
60
+ * multiple unwanted connectivity test pings, temporary ignore domain or
61
+ * server IP changes.
62
+ */
63
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
+ }
65
+
66
+ /**
67
+ * If your dev environment supports custom public network IP setup
68
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
+ * and uncomment it during dev.
70
+ */
71
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
+ // VVV default public network IP.
73
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
+
75
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
+ }
77
+
78
+ /**
79
+ * If true and running with secret key, the opt-in process
80
+ * will skip the email activation process which is invoked
81
+ * when the email of the context user already exist in Freemius
82
+ * database (as a security precaution, to prevent sharing user
83
+ * secret with unauthorized entity).
84
+ *
85
+ * IMPORTANT:
86
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
+ * CLOCK IS SYNCED.
89
+ */
90
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
+ }
93
+
94
+
95
+ #--------------------------------------------------------------------------------
96
+ #region Directories
97
+ #--------------------------------------------------------------------------------
98
+
99
+ if ( ! defined( 'WP_FS__DIR' ) ) {
100
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
+ }
102
+ if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
+ }
105
+ if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
+ }
108
+ if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
+ }
111
+ if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
+ }
114
+ if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
+ }
117
+ if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
+ }
120
+ if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
+ }
123
+
124
+ #endregion
125
+
126
+ /**
127
+ * Domain / URL / Address
128
+ */
129
+ define( 'WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com' );
130
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
131
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
132
+
133
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
134
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
135
+ }
136
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
137
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
138
+ }
139
+
140
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
141
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
142
+ }
143
+
144
+ #--------------------------------------------------------------------------------
145
+ #region HTTP
146
+ #--------------------------------------------------------------------------------
147
+
148
+ if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
149
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
150
+ }
151
+
152
+ if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
153
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
154
+ // Checks if CloudFlare's HTTPS (Flexible SSL support).
155
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
156
+ 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
157
+ ) ||
158
+ // Check if HTTPS request.
159
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
160
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
161
+ );
162
+ }
163
+
164
+ if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
165
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
166
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
167
+ }
168
+
169
+ if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
170
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
171
+ }
172
+
173
+ if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
174
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
175
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
176
+ } else {
177
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
178
+ is_string( WP_FS__REMOTE_ADDR ) &&
179
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
180
+ WP_FS__REMOTE_ADDR === '::1' )
181
+ );
182
+ }
183
+ }
184
+
185
+ if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
186
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
187
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
188
+ }
189
+
190
+ #endregion
191
+
192
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
193
+ // By default, run with Freemius production servers.
194
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
195
+ }
196
+
197
+ if ( ! defined( 'WP_FS__ADDRESS' ) ) {
198
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
199
+ }
200
+
201
+
202
+ #--------------------------------------------------------------------------------
203
+ #region API
204
+ #--------------------------------------------------------------------------------
205
+
206
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
207
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
208
+ }
209
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
210
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
211
+ }
212
+
213
+ // Set API address for local testing.
214
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
215
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
216
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
217
+ }
218
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
219
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
220
+ }
221
+ }
222
+
223
+ #endregion
224
+
225
+ #--------------------------------------------------------------------------------
226
+ #region Checkout
227
+ #--------------------------------------------------------------------------------
228
+
229
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_PRODUCTION' ) ) {
230
+ define( 'FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com' );
231
+ }
232
+
233
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_LOCALHOST' ) ) {
234
+ define( 'FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius-local.com:8080' );
235
+ }
236
+
237
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS' ) ) {
238
+ define( 'FS_CHECKOUT__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST ) );
239
+ }
240
+
241
+ #endregion
242
+
243
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
244
+
245
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
246
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
247
+ }
248
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
249
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
250
+ }
251
+ if ( ! defined( 'WP_FS__GDPR_OPTION_NAME' ) ) {
252
+ define( 'WP_FS__GDPR_OPTION_NAME', WP_FS___OPTION_PREFIX . 'gdpr' );
253
+ }
254
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
255
+
256
+ /**
257
+ * Module types
258
+ *
259
+ * @since 1.2.2
260
+ */
261
+ define( 'WP_FS__MODULE_TYPE_PLUGIN', 'plugin' );
262
+ define( 'WP_FS__MODULE_TYPE_THEME', 'theme' );
263
+
264
+ /**
265
+ * Billing Frequencies
266
+ */
267
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
268
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
269
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
270
+
271
+ /**
272
+ * Plans
273
+ */
274
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
275
+ define( 'WP_FS__PLAN_FREE', 'free' );
276
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
277
+
278
+ /**
279
+ * Times in seconds
280
+ */
281
+ if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
282
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
283
+ }
284
+ if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
285
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
286
+ }
287
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
288
+ if ( ! defined( 'WP_FS__TIME_12_HOURS_IN_SEC' ) ) {
289
+ define( 'WP_FS__TIME_12_HOURS_IN_SEC', 43200 );
290
+ }
291
+ if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
292
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', WP_FS__TIME_12_HOURS_IN_SEC * 2 );
293
+ }
294
+ if ( ! defined( 'WP_FS__TIME_WEEK_IN_SEC' ) ) {
295
+ define( 'WP_FS__TIME_WEEK_IN_SEC', 7 * WP_FS__TIME_24_HOURS_IN_SEC );
296
+ }
297
+
298
+ #--------------------------------------------------------------------------------
299
+ #region Debugging
300
+ #--------------------------------------------------------------------------------
301
+
302
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
303
+ $debug_mode = get_option( 'fs_debug_mode', null );
304
+
305
+ if ( $debug_mode === null ) {
306
+ $debug_mode = false;
307
+ add_option( 'fs_debug_mode', $debug_mode );
308
+ }
309
+
310
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
311
+ }
312
+
313
+ if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
314
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
315
+ }
316
+ if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
317
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
318
+ }
319
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
320
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
321
+ }
322
+
323
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
324
+ error_reporting( E_ALL );
325
+ }
326
+
327
+ #endregion
328
+
329
+ if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
330
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
331
+ }
332
+ if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
333
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
334
+ }
335
+ if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
336
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
337
+ }
338
+
339
+ #--------------------------------------------------------------------------------
340
+ #region Multisite Network
341
+ #--------------------------------------------------------------------------------
342
+
343
+ /**
344
+ * Do not use this define directly, it will have the wrong value
345
+ * during plugin uninstall/deletion when the inclusion of the plugin
346
+ * is triggered due to registration with register_uninstall_hook().
347
+ *
348
+ * Instead, use fs_is_network_admin().
349
+ *
350
+ * @author Vova Feldman (@svovaf)
351
+ */
352
+ if ( ! defined( 'WP_FS__IS_NETWORK_ADMIN' ) ) {
353
+ define( 'WP_FS__IS_NETWORK_ADMIN',
354
+ is_network_admin() ||
355
+ ( is_multisite() &&
356
+ ( ( defined( 'DOING_AJAX' ) && DOING_AJAX &&
357
+ ( isset( $_REQUEST['_fs_network_admin'] ) /*||
358
+ ( ! empty( $_REQUEST['action'] ) && 'delete-plugin' === $_REQUEST['action'] )*/ )
359
+ ) ||
360
+ // Plugin uninstall.
361
+ defined( 'WP_UNINSTALL_PLUGIN' ) )
362
+ )
363
+ );
364
+ }
365
+
366
+ /**
367
+ * Do not use this define directly, it will have the wrong value
368
+ * during plugin uninstall/deletion when the inclusion of the plugin
369
+ * is triggered due to registration with register_uninstall_hook().
370
+ *
371
+ * Instead, use fs_is_blog_admin().
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ */
375
+ if ( ! defined( 'WP_FS__IS_BLOG_ADMIN' ) ) {
376
+ define( 'WP_FS__IS_BLOG_ADMIN', is_blog_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['_fs_blog_admin'] ) ) );
377
+ }
378
+
379
+ if ( ! defined( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED' ) ) {
380
+ // Set to true to show network level settings even if delegated to site admins.
381
+ define( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED', false );
382
+ }
383
+
384
+ #endregion
385
+
386
+ if ( ! defined( 'WP_FS__DEMO_MODE' ) ) {
387
+ define( 'WP_FS__DEMO_MODE', false );
388
+ }
trunk/includes/vendor/freemius/wordpress-sdk/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+
14
+ /**
15
+ * - Each instance of Freemius class represents a single plugin
16
+ * install by a single user (the installer of the plugin).
17
+ *
18
+ * - Each website can only have one install of the same plugin.
19
+ *
20
+ * - Install entity is only created after a user connects his account with Freemius.
21
+ *
22
+ * Class Freemius_Abstract
23
+ */
24
+ abstract class Freemius_Abstract {
25
+
26
+ #----------------------------------------------------------------------------------
27
+ #region Identity
28
+ #----------------------------------------------------------------------------------
29
+
30
+ /**
31
+ * Check if user has connected his account (opted-in).
32
+ *
33
+ * Note:
34
+ * If the user opted-in and opted-out on a later stage,
35
+ * this will still return true. If you want to check if the
36
+ * user is currently opted-in, use:
37
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
38
+ *
39
+ * @since 1.0.1
40
+ * @return bool
41
+ */
42
+ abstract function is_registered();
43
+
44
+ /**
45
+ * Check if the user skipped connecting the account with Freemius.
46
+ *
47
+ * @since 1.0.7
48
+ *
49
+ * @return bool
50
+ */
51
+ abstract function is_anonymous();
52
+
53
+ /**
54
+ * Check if the user currently in activation mode.
55
+ *
56
+ * @since 1.0.7
57
+ *
58
+ * @return bool
59
+ */
60
+ abstract function is_activation_mode();
61
+
62
+ #endregion
63
+
64
+ #----------------------------------------------------------------------------------
65
+ #region Usage Tracking
66
+ #----------------------------------------------------------------------------------
67
+
68
+ /**
69
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
70
+ *
71
+ * @author Leo Fajardo (@leorw)
72
+ * @since 1.2.1.5
73
+ *
74
+ * @return bool
75
+ */
76
+ abstract function is_tracking_allowed();
77
+
78
+ /**
79
+ * Returns TRUE if the user never opted-in or manually opted-out.
80
+ *
81
+ * @author Vova Feldman (@svovaf)
82
+ * @since 1.2.1.5
83
+ *
84
+ * @return bool
85
+ */
86
+ function is_tracking_prohibited() {
87
+ return ! $this->is_registered() || ! $this->is_tracking_allowed();
88
+ }
89
+
90
+ /**
91
+ * Opt-out from usage tracking.
92
+ *
93
+ * Note: This will not delete the account information but will stop all tracking.
94
+ *
95
+ * Returns:
96
+ * 1. FALSE - If the user never opted-in.
97
+ * 2. TRUE - If successfully opted-out.
98
+ * 3. object - API Result on failure.
99
+ *
100
+ * @author Leo Fajardo (@leorw)
101
+ * @since 1.2.1.5
102
+ *
103
+ * @return bool|object
104
+ */
105
+ abstract function stop_tracking();
106
+
107
+ /**
108
+ * Opt-in back into usage tracking.
109
+ *
110
+ * Note: This will only work if the user opted-in previously.
111
+ *
112
+ * Returns:
113
+ * 1. FALSE - If the user never opted-in.
114
+ * 2. TRUE - If successfully opted-in back to usage tracking.
115
+ * 3. object - API result on failure.
116
+ *
117
+ * @author Leo Fajardo (@leorw)
118
+ * @since 1.2.1.5
119
+ *
120
+ * @return bool|object
121
+ */
122
+ abstract function allow_tracking();
123
+
124
+ #endregion
125
+
126
+ #----------------------------------------------------------------------------------
127
+ #region Module Type
128
+ #----------------------------------------------------------------------------------
129
+
130
+ /**
131
+ * Checks if the plugin's type is "plugin". The other type is "theme".
132
+ *
133
+ * @author Leo Fajardo (@leorw)
134
+ * @since 1.2.2
135
+ *
136
+ * @return bool
137
+ */
138
+ abstract function is_plugin();
139
+
140
+ /**
141
+ * Checks if the module type is "theme". The other type is "plugin".
142
+ *
143
+ * @author Leo Fajardo (@leorw)
144
+ * @since 1.2.2
145
+ *
146
+ * @return bool
147
+ */
148
+ function is_theme() {
149
+ return ( ! $this->is_plugin() );
150
+ }
151
+
152
+ #endregion
153
+
154
+ #----------------------------------------------------------------------------------
155
+ #region Permissions
156
+ #----------------------------------------------------------------------------------
157
+
158
+ /**
159
+ * Check if plugin must be WordPress.org compliant.
160
+ *
161
+ * @since 1.0.7
162
+ *
163
+ * @return bool
164
+ */
165
+ abstract function is_org_repo_compliant();
166
+
167
+ /**
168
+ * Check if plugin is allowed to install executable files.
169
+ *
170
+ * @author Vova Feldman (@svovaf)
171
+ * @since 1.0.5
172
+ *
173
+ * @return bool
174
+ */
175
+ function is_allowed_to_install() {
176
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
177
+ }
178
+
179
+ #endregion
180
+
181
+ /**
182
+ * Check if user in trial or in free plan (not paying).
183
+ *
184
+ * @author Vova Feldman (@svovaf)
185
+ * @since 1.0.4
186
+ *
187
+ * @return bool
188
+ */
189
+ function is_not_paying() {
190
+ return ( $this->is_trial() || $this->is_free_plan() );
191
+ }
192
+
193
+ /**
194
+ * Check if the user has an activated and valid paid license on current plugin's install.
195
+ *
196
+ * @since 1.0.9
197
+ *
198
+ * @return bool
199
+ */
200
+ abstract function is_paying();
201
+
202
+ /**
203
+ * Check if the user is paying or in trial.
204
+ *
205
+ * @since 1.0.9
206
+ *
207
+ * @return bool
208
+ */
209
+ function is_paying_or_trial() {
210
+ return ( $this->is_paying() || $this->is_trial() );
211
+ }
212
+
213
+ /**
214
+ * Check if user in a trial or have feature enabled license.
215
+ *
216
+ * @author Vova Feldman (@svovaf)
217
+ * @since 1.1.7
218
+ *
219
+ * @return bool
220
+ */
221
+ abstract function can_use_premium_code();
222
+
223
+ #----------------------------------------------------------------------------------
224
+ #region Premium Only
225
+ #----------------------------------------------------------------------------------
226
+
227
+ /**
228
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
229
+ * included in the premium code.
230
+ *
231
+ * Example:
232
+ * if ( freemius()->is__premium_only() ) {
233
+ * ...
234
+ * }
235
+ */
236
+
237
+ /**
238
+ * Returns true when running premium plugin code.
239
+ *
240
+ * @since 1.0.9
241
+ *
242
+ * @return bool
243
+ */
244
+ function is__premium_only() {
245
+ return $this->is_premium();
246
+ }
247
+
248
+ /**
249
+ * Check if the user has an activated and valid paid license on current plugin's install.
250
+ *
251
+ * @since 1.0.9
252
+ *
253
+ * @return bool
254
+ *
255
+ */
256
+ function is_paying__premium_only() {
257
+ return ( $this->is__premium_only() && $this->is_paying() );
258
+ }
259
+
260
+ /**
261
+ * All code wrapped in this statement will be only included in the premium code.
262
+ *
263
+ * @since 1.0.9
264
+ *
265
+ * @param string $plan Plan name.
266
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
267
+ *
268
+ * @return bool
269
+ */
270
+ function is_plan__premium_only( $plan, $exact = false ) {
271
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
272
+ }
273
+
274
+ /**
275
+ * Check if plan matches active license' plan or active trial license' plan.
276
+ *
277
+ * All code wrapped in this statement will be only included in the premium code.
278
+ *
279
+ * @since 1.0.9
280
+ *
281
+ * @param string $plan Plan name.
282
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
283
+ *
284
+ * @return bool
285
+ */
286
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
287
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
288
+ }
289
+
290
+ /**
291
+ * Check if the user is paying or in trial.
292
+ *
293
+ * All code wrapped in this statement will be only included in the premium code.
294
+ *
295
+ * @since 1.0.9
296
+ *
297
+ * @return bool
298
+ */
299
+ function is_paying_or_trial__premium_only() {
300
+ return $this->is_premium() && $this->is_paying_or_trial();
301
+ }
302
+
303
+ /**
304
+ * Check if the user has an activated and valid paid license on current plugin's install.
305
+ *
306
+ * @since 1.0.4
307
+ *
308
+ * @return bool
309
+ *
310
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
311
+ * @using Alias to is_paying__premium_only()
312
+ */
313
+ function is_paying__fs__() {
314
+ return $this->is_paying__premium_only();
315
+ }
316
+
317
+ /**
318
+ * Check if user in a trial or have feature enabled license.
319
+ *
320
+ * All code wrapped in this statement will be only included in the premium code.
321
+ *
322
+ * @author Vova Feldman (@svovaf)
323
+ * @since 1.1.9
324
+ *
325
+ * @return bool
326
+ */
327
+ function can_use_premium_code__premium_only() {
328
+ return $this->is_premium() && $this->can_use_premium_code();
329
+ }
330
+
331
+ #endregion
332
+
333
+ #----------------------------------------------------------------------------------
334
+ #region Trial
335
+ #----------------------------------------------------------------------------------
336
+
337
+ /**
338
+ * Check if the user in a trial.
339
+ *
340
+ * @since 1.0.3
341
+ *
342
+ * @return bool
343
+ */
344
+ abstract function is_trial();
345
+
346
+ /**
347
+ * Check if trial already utilized.
348
+ *
349
+ * @since 1.0.9
350
+ *
351
+ * @return bool
352
+ */
353
+ abstract function is_trial_utilized();
354
+
355
+ #endregion
356
+
357
+ #----------------------------------------------------------------------------------
358
+ #region Plans
359
+ #----------------------------------------------------------------------------------
360
+
361
+ /**
362
+ * Check if the user is on the free plan of the product.
363
+ *
364
+ * @since 1.0.4
365
+ *
366
+ * @return bool
367
+ */
368
+ abstract function is_free_plan();
369
+
370
+ /**
371
+ * @since 1.0.2
372
+ *
373
+ * @param string $plan Plan name.
374
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
375
+ *
376
+ * @return bool
377
+ */
378
+ abstract function is_plan( $plan, $exact = false );
379
+
380
+ /**
381
+ * Check if plan based on trial. If not in trial mode, should return false.
382
+ *
383
+ * @since 1.0.9
384
+ *
385
+ * @param string $plan Plan name.
386
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
387
+ *
388
+ * @return bool
389
+ */
390
+ abstract function is_trial_plan( $plan, $exact = false );
391
+
392
+ /**
393
+ * Check if plan matches active license' plan or active trial license' plan.
394
+ *
395
+ * @since 1.0.9
396
+ *
397
+ * @param string $plan Plan name.
398
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
399
+ *
400
+ * @return bool
401
+ */
402
+ function is_plan_or_trial( $plan, $exact = false ) {
403
+ return $this->is_plan( $plan, $exact ) ||
404
+ $this->is_trial_plan( $plan, $exact );
405
+ }
406
+
407
+ /**
408
+ * Check if plugin has any paid plans.
409
+ *
410
+ * @author Vova Feldman (@svovaf)
411
+ * @since 1.0.7
412
+ *
413
+ * @return bool
414
+ */
415
+ abstract function has_paid_plan();
416
+
417
+ /**
418
+ * Check if plugin has any free plan, or is it premium only.
419
+ *
420
+ * Note: If no plans configured, assume plugin is free.
421
+ *
422
+ * @author Vova Feldman (@svovaf)
423
+ * @since 1.0.7
424
+ *
425
+ * @return bool
426
+ */
427
+ abstract function has_free_plan();
428
+
429
+ /**
430
+ * Check if plugin is premium only (no free plans).
431
+ *
432
+ * NOTE: is__premium_only() is very different method, don't get confused.
433
+ *
434
+ * @author Vova Feldman (@svovaf)
435
+ * @since 1.1.9
436
+ *
437
+ * @return bool
438
+ */
439
+ abstract function is_only_premium();
440
+
441
+ /**
442
+ * Check if module has a premium code version.
443
+ *
444
+ * Serviceware module might be freemium without any
445
+ * premium code version, where the paid features
446
+ * are all part of the service.
447
+ *
448
+ * @author Vova Feldman (@svovaf)
449
+ * @since 1.2.1.6
450
+ *
451
+ * @return bool
452
+ */
453
+ abstract function has_premium_version();
454
+
455
+ /**
456
+ * Check if module has any release on Freemius,
457
+ * or all plugin's code is on WordPress.org (Serviceware).
458
+ *
459
+ * @return bool
460
+ */
461
+ function has_release_on_freemius() {
462
+ return ! $this->is_org_repo_compliant() ||
463
+ $this->has_premium_version();
464
+ }
465
+
466
+ /**
467
+ * Checks if it's a freemium plugin.
468
+ *
469
+ * @author Vova Feldman (@svovaf)
470
+ * @since 1.1.9
471
+ *
472
+ * @return bool
473
+ */
474
+ function is_freemium() {
475
+ return $this->has_paid_plan() &&
476
+ $this->has_free_plan();
477
+ }
478
+
479
+ /**
480
+ * Check if module has only one plan.
481
+ *
482
+ * @author Vova Feldman (@svovaf)
483
+ * @since 1.2.1.7
484
+ *
485
+ * @return bool
486
+ */
487
+ abstract function is_single_plan();
488
+
489
+ #endregion
490
+
491
+ /**
492
+ * Check if running payments in sandbox mode.
493
+ *
494
+ * @since 1.0.4
495
+ *
496
+ * @return bool
497
+ */
498
+ abstract function is_payments_sandbox();
499
+
500
+ /**
501
+ * Check if running test vs. live plugin.
502
+ *
503
+ * @since 1.0.5
504
+ *
505
+ * @return bool
506
+ */
507
+ abstract function is_live();
508
+
509
+ /**
510
+ * Check if running premium plugin code.
511
+ *
512
+ * @since 1.0.5
513
+ *
514
+ * @return bool
515
+ */
516
+ abstract function is_premium();
517
+
518
+ /**
519
+ * Get upgrade URL.
520
+ *
521
+ * @author Vova Feldman (@svovaf)
522
+ * @since 1.0.2
523
+ *
524
+ * @param string $period Billing cycle.
525
+ *
526
+ * @return string
527
+ */
528
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
529
+
530
+ /**
531
+ * Check if Freemius was first added in a plugin update.
532
+ *
533
+ * @author Vova Feldman (@svovaf)
534
+ * @since 1.1.5
535
+ *
536
+ * @return bool
537
+ */
538
+ function is_plugin_update() {
539
+ return ! $this->is_plugin_new_install();
540
+ }
541
+
542
+ /**
543
+ * Check if Freemius was part of the plugin when the user installed it first.
544
+ *
545
+ * @author Vova Feldman (@svovaf)
546
+ * @since 1.1.5
547
+ *
548
+ * @return bool
549
+ */
550
+ abstract function is_plugin_new_install();
551
+
552
+ #----------------------------------------------------------------------------------
553
+ #region Marketing
554
+ #----------------------------------------------------------------------------------
555
+
556
+ /**
557
+ * Check if current user purchased any other plugins before.
558
+ *
559
+ * @author Vova Feldman (@svovaf)
560
+ * @since 1.0.9
561
+ *
562
+ * @return bool
563
+ */
564
+ abstract function has_purchased_before();
565
+
566
+ /**
567
+ * Check if current user classified as an agency.
568
+ *
569
+ * @author Vova Feldman (@svovaf)
570
+ * @since 1.0.9
571
+ *
572
+ * @return bool
573
+ */
574
+ abstract function is_agency();
575
+
576
+ /**
577
+ * Check if current user classified as a developer.
578
+ *
579
+ * @author Vova Feldman (@svovaf)
580
+ * @since 1.0.9
581
+ *
582
+ * @return bool
583
+ */
584
+ abstract function is_developer();
585
+
586
+ /**
587
+ * Check if current user classified as a business.
588
+ *
589
+ * @author Vova Feldman (@svovaf)
590
+ * @since 1.0.9
591
+ *
592
+ * @return bool
593
+ */
594
+ abstract function is_business();
595
+
596
+ #endregion
597
+ }
trunk/includes/vendor/freemius/wordpress-sdk/includes/class-freemius.php ADDED
@@ -0,0 +1,20822 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ // "final class"
13
+ class Freemius extends Freemius_Abstract {
14
+ /**
15
+ * SDK Version
16
+ *
17
+ * @var string
18
+ */
19
+ public $version = WP_FS__SDK_VERSION;
20
+
21
+ #region Plugin Info
22
+
23
+ /**
24
+ * @since 1.0.1
25
+ *
26
+ * @var string
27
+ */
28
+ private $_slug;
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ private $_plugin_basename;
36
+ /**
37
+ * @since 1.0.0
38
+ *
39
+ * @var string
40
+ */
41
+ private $_free_plugin_basename;
42
+ /**
43
+ * @since 1.0.0
44
+ *
45
+ * @var string
46
+ */
47
+ private $_plugin_dir_path;
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * @var string
52
+ */
53
+ private $_plugin_dir_name;
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * @var string
58
+ */
59
+ private $_plugin_main_file_path;
60
+ /**
61
+ * @var string[]
62
+ */
63
+ private $_plugin_data;
64
+ /**
65
+ * @since 1.0.9
66
+ *
67
+ * @var string
68
+ */
69
+ private $_plugin_name;
70
+ /**
71
+ * @since 1.2.2
72
+ *
73
+ * @var string
74
+ */
75
+ private $_module_type;
76
+
77
+ #endregion Plugin Info
78
+
79
+ /**
80
+ * @since 1.0.9
81
+ *
82
+ * @var bool If false, don't turn Freemius on.
83
+ */
84
+ private $_is_on;
85
+
86
+ /**
87
+ * @since 1.1.3
88
+ *
89
+ * @var bool If false, don't turn Freemius on.
90
+ */
91
+ private $_is_anonymous;
92
+
93
+ /**
94
+ * @since 1.0.9
95
+ * @var bool If false, issues with connectivity to Freemius API.
96
+ */
97
+ private $_has_api_connection;
98
+
99
+ /**
100
+ * @since 1.0.9
101
+ * @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
102
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
103
+ */
104
+ private $_enable_anonymous = true;
105
+
106
+ /**
107
+ * @since 1.1.7.5
108
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
109
+ */
110
+ private $_anonymous_mode;
111
+
112
+ /**
113
+ * @since 1.1.9
114
+ * @var bool Hints the SDK if plugin have any free plans.
115
+ */
116
+ private $_is_premium_only;
117
+
118
+ /**
119
+ * @since 1.2.1.6
120
+ * @var bool Hints the SDK if plugin have premium code version at all.
121
+ */
122
+ private $_has_premium_version;
123
+
124
+ /**
125
+ * @since 1.2.1.6
126
+ * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
127
+ */
128
+ private $_ignore_pending_mode;
129
+
130
+ /**
131
+ * @since 1.0.8
132
+ * @var bool Hints the SDK if the plugin has any paid plans.
133
+ */
134
+ private $_has_paid_plans;
135
+
136
+ /**
137
+ * @since 1.2.1.5
138
+ * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
139
+ * without a specified period, if positive - the number of trial days.
140
+ */
141
+ private $_trial_days = - 1;
142
+
143
+ /**
144
+ * @since 1.2.1.5
145
+ * @var bool Hints the SDK if the trial requires a payment method or not.
146
+ */
147
+ private $_is_trial_require_payment = false;
148
+
149
+ /**
150
+ * @since 1.0.7
151
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
152
+ */
153
+ private $_is_org_compliant;
154
+
155
+ /**
156
+ * @since 1.0.7
157
+ * @var bool Hints the SDK if the plugin is has add-ons.
158
+ */
159
+ private $_has_addons;
160
+
161
+ /**
162
+ * @since 1.1.6
163
+ * @var string[]bool.
164
+ */
165
+ private $_permissions;
166
+
167
+ /**
168
+ * @var FS_Storage
169
+ */
170
+ private $_storage;
171
+
172
+ /**
173
+ * @since 1.2.2.7
174
+ * @var FS_Cache_Manager
175
+ */
176
+ private $_cache;
177
+
178
+ /**
179
+ * @since 1.0.0
180
+ *
181
+ * @var FS_Logger
182
+ */
183
+ private $_logger;
184
+ /**
185
+ * @since 1.0.4
186
+ *
187
+ * @var FS_Plugin
188
+ */
189
+ private $_plugin = false;
190
+ /**
191
+ * @since 1.0.4
192
+ *
193
+ * @var FS_Plugin|false
194
+ */
195
+ private $_parent_plugin = false;
196
+ /**
197
+ * @since 1.1.1
198
+ *
199
+ * @var Freemius
200
+ */
201
+ private $_parent = false;
202
+ /**
203
+ * @since 1.0.1
204
+ *
205
+ * @var FS_User
206
+ */
207
+ private $_user = false;
208
+ /**
209
+ * @since 1.0.1
210
+ *
211
+ * @var FS_Site
212
+ */
213
+ private $_site = false;
214
+ /**
215
+ * @since 1.0.1
216
+ *
217
+ * @var FS_Plugin_License
218
+ */
219
+ private $_license;
220
+ /**
221
+ * @since 1.0.2
222
+ *
223
+ * @var FS_Plugin_Plan[]
224
+ */
225
+ private $_plans = false;
226
+ /**
227
+ * @var FS_Plugin_License[]
228
+ * @since 1.0.5
229
+ */
230
+ private $_licenses = false;
231
+
232
+ /**
233
+ * @since 1.0.1
234
+ *
235
+ * @var FS_Admin_Menu_Manager
236
+ */
237
+ private $_menu;
238
+
239
+ /**
240
+ * @var FS_Admin_Notices
241
+ */
242
+ private $_admin_notices;
243
+
244
+ /**
245
+ * @since 1.1.6
246
+ *
247
+ * @var FS_Admin_Notices
248
+ */
249
+ private static $_global_admin_notices;
250
+
251
+ /**
252
+ * @var FS_Logger
253
+ * @since 1.0.0
254
+ */
255
+ private static $_static_logger;
256
+
257
+ /**
258
+ * @var FS_Options
259
+ * @since 1.0.2
260
+ */
261
+ private static $_accounts;
262
+
263
+ /**
264
+ * @since 1.2.2
265
+ *
266
+ * @var number
267
+ */
268
+ private $_module_id;
269
+
270
+ /**
271
+ * @var Freemius[]
272
+ */
273
+ private static $_instances = array();
274
+
275
+ /**
276
+ * @since 1.2.3
277
+ *
278
+ * @var FS_Affiliate
279
+ */
280
+ private $affiliate = null;
281
+
282
+ /**
283
+ * @since 1.2.3
284
+ *
285
+ * @var FS_AffiliateTerms
286
+ */
287
+ private $plugin_affiliate_terms = null;
288
+
289
+ /**
290
+ * @since 1.2.3
291
+ *
292
+ * @var FS_AffiliateTerms
293
+ */
294
+ private $custom_affiliate_terms = null;
295
+
296
+ /**
297
+ * @since 2.0.0
298
+ *
299
+ * @var bool
300
+ */
301
+ private $_is_multisite_integrated;
302
+
303
+ /**
304
+ * @since 2.0.0
305
+ *
306
+ * @var bool True if the current request is for a network admin screen and the plugin is network active.
307
+ */
308
+ private $_is_network_active;
309
+
310
+ /**
311
+ * @since 2.0.0
312
+ *
313
+ * @var int|null The original blog ID the plugin was loaded with.
314
+ */
315
+ private $_blog_id = null;
316
+
317
+ /**
318
+ * @since 2.0.0
319
+ *
320
+ * @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
321
+ */
322
+ private $_context_is_network_or_blog_id = null;
323
+
324
+ /**
325
+ * @since 2.0.0
326
+ *
327
+ * @var string
328
+ */
329
+ private $_dynamically_added_top_level_page_hook_name = '';
330
+
331
+ #region Uninstall Reasons IDs
332
+
333
+ const REASON_NO_LONGER_NEEDED = 1;
334
+ const REASON_FOUND_A_BETTER_PLUGIN = 2;
335
+ const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
336
+ const REASON_BROKE_MY_SITE = 4;
337
+ const REASON_SUDDENLY_STOPPED_WORKING = 5;
338
+ const REASON_CANT_PAY_ANYMORE = 6;
339
+ const REASON_OTHER = 7;
340
+ const REASON_DIDNT_WORK = 8;
341
+ const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
342
+ const REASON_COULDNT_MAKE_IT_WORK = 10;
343
+ const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
344
+ const REASON_NOT_WORKING = 12;
345
+ const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
346
+ const REASON_DIDNT_WORK_AS_EXPECTED = 14;
347
+ const REASON_TEMPORARY_DEACTIVATION = 15;
348
+
349
+ #endregion
350
+
351
+ /* Ctor
352
+ ------------------------------------------------------------------------------------------------------------------*/
353
+
354
+ /**
355
+ * Main singleton instance.
356
+ *
357
+ * @author Vova Feldman (@svovaf)
358
+ * @since 1.0.0
359
+ *
360
+ * @param number $module_id
361
+ * @param string|bool $slug
362
+ * @param bool $is_init Since 1.2.1 Is initiation sequence.
363
+ */
364
+ private function __construct( $module_id, $slug = false, $is_init = false ) {
365
+ if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
366
+ $this->store_id_slug_type_path_map( $module_id, $slug );
367
+ }
368
+
369
+ $this->_module_id = $module_id;
370
+ $this->_slug = $this->get_slug();
371
+ $this->_module_type = $this->get_module_type();
372
+
373
+ $this->_blog_id = is_multisite() ? get_current_blog_id() : null;
374
+
375
+ $this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
376
+
377
+ $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
378
+
379
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
380
+
381
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
382
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
383
+ $this->_plugin_basename = $this->get_plugin_basename();
384
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
385
+
386
+ $this->_is_multisite_integrated = (
387
+ defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
388
+ ( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
389
+ );
390
+
391
+ $this->_is_network_active = (
392
+ is_multisite() &&
393
+ $this->_is_multisite_integrated &&
394
+ // Themes are always network activated, but the ACTUAL activation is per site.
395
+ $this->is_plugin() &&
396
+ ( is_plugin_active_for_network( $this->_plugin_basename ) ||
397
+ // Plugin network level activation or uninstall.
398
+ is_plugin_inactive( $this->_plugin_basename ) )
399
+ );
400
+
401
+ $this->_storage->set_network_active(
402
+ $this->_is_network_active,
403
+ $this->is_delegated_connection()
404
+ );
405
+
406
+ #region Migration
407
+
408
+ if ( is_multisite() ) {
409
+ /**
410
+ * If the install_timestamp exists on the site level but doesn't exist on the
411
+ * network level storage, it means that we need to process the storage with migration.
412
+ *
413
+ * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, install_timestamp will be already set in the network level storage.
414
+ *
415
+ * @author Vova Feldman (@svovaf)
416
+ * @since 2.0.0
417
+ */
418
+ if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
419
+ false !== $this->_storage->get( 'install_timestamp', false, false )
420
+ ) {
421
+ // Initiate storage migration.
422
+ $this->_storage->migrate_to_network();
423
+
424
+ // Migrate module cache to network level storage.
425
+ $this->_cache->migrate_to_network();
426
+ }
427
+ }
428
+
429
+ #endregion
430
+
431
+ $base_name_split = explode( '/', $this->_plugin_basename );
432
+ $this->_plugin_dir_name = $base_name_split[0];
433
+
434
+ if ( $this->_logger->is_on() ) {
435
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
436
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
437
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
438
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
439
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
440
+ }
441
+
442
+ // Remember link between file to slug.
443
+ $this->store_file_slug_map();
444
+
445
+ // Store plugin's initial install timestamp.
446
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
447
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
448
+ }
449
+
450
+ if ( ! is_object( $this->_plugin ) ) {
451
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
452
+ }
453
+
454
+ $this->_admin_notices = FS_Admin_Notices::instance(
455
+ $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
456
+ /**
457
+ * Ensure that the admin notice will always have a title by using the stored plugin title if available and
458
+ * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
459
+ *
460
+ * @author Leo Fajardo (@leorw)
461
+ * @since 1.2.2
462
+ */
463
+ ( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
464
+ $this->get_unique_affix()
465
+ );
466
+
467
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
468
+ 'true' === fs_request_is_action( 'restart_freemius' )
469
+ ) {
470
+ FS_Api::clear_cache();
471
+ $this->_cache->clear();
472
+ }
473
+
474
+ $this->_register_hooks();
475
+
476
+ /**
477
+ * Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
478
+ * instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
479
+ * loaded in `_load_account` for versions of SDK starting from 2.0.0.
480
+ *
481
+ * @author Leo Fajardo (@leorw)
482
+ */
483
+ self::migrate_install_plan_to_plan_id( $this->_storage );
484
+
485
+ $this->_load_account();
486
+
487
+ $this->_version_updates_handler();
488
+ }
489
+
490
+ /**
491
+ * Checks whether this module has a settings menu.
492
+ *
493
+ * @author Leo Fajardo (@leorw)
494
+ * @since 1.2.2
495
+ *
496
+ * @return bool
497
+ */
498
+ function has_settings_menu() {
499
+ return ( $this->_is_network_active && fs_is_network_admin() ) ?
500
+ $this->_menu->has_network_menu() :
501
+ $this->_menu->has_menu();
502
+ }
503
+
504
+ /**
505
+ * Check if the context module is free wp.org theme.
506
+ *
507
+ * This method is helpful because:
508
+ * 1. wp.org themes are limited to a single submenu item,
509
+ * and sub-submenu items are most likely not allowed (never verified).
510
+ * 2. wp.org themes are not allowed to redirect the user
511
+ * after the theme activation, therefore, the agreed UX
512
+ * is showing the opt-in as a modal dialog box after
513
+ * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
514
+ *
515
+ * @author Vova Feldman (@svovaf)
516
+ * @since 1.2.2.7
517
+ *
518
+ * @return bool
519
+ */
520
+ function is_free_wp_org_theme() {
521
+ return (
522
+ $this->is_theme() &&
523
+ $this->is_org_repo_compliant() &&
524
+ ! $this->is_premium()
525
+ );
526
+ }
527
+
528
+ /**
529
+ * Checks whether this a submenu item is visible.
530
+ *
531
+ * @author Vova Feldman (@svovaf)
532
+ * @since 1.2.2.6
533
+ * @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
534
+ *
535
+ * @param string $slug
536
+ * @param bool $ignore_free_wp_org_theme_context This is used to decide if the associated tab should be shown
537
+ * or hidden.
538
+ *
539
+ * @return bool
540
+ */
541
+ function is_submenu_item_visible( $slug, $ignore_free_wp_org_theme_context = false ) {
542
+ if ( $this->is_admin_page( $slug ) ) {
543
+ /**
544
+ * It is the current context page, so show the submenu item
545
+ * so the user will have the right context page, even if it
546
+ * was set to hidden.
547
+ */
548
+ return true;
549
+ }
550
+
551
+ if ( ! $this->has_settings_menu() ) {
552
+ // No menu settings at all.
553
+ return false;
554
+ }
555
+
556
+ if ( ! $ignore_free_wp_org_theme_context && $this->is_free_wp_org_theme() ) {
557
+ /**
558
+ * wp.org themes are limited to a single submenu item, and
559
+ * sub-submenu items are most likely not allowed (never verified).
560
+ */
561
+ return false;
562
+ }
563
+
564
+ return $this->_menu->is_submenu_item_visible( $slug );
565
+ }
566
+
567
+ /**
568
+ * Check if a Freemius page should be accessible via the UI.
569
+ *
570
+ * @author Vova Feldman (@svovaf)
571
+ * @since 1.2.2.7
572
+ *
573
+ * @param string $slug
574
+ *
575
+ * @return bool
576
+ */
577
+ function is_page_visible( $slug ) {
578
+ if ( $this->is_admin_page( $slug ) ) {
579
+ return true;
580
+ }
581
+
582
+ return $this->_menu->is_submenu_item_visible( $slug, true, true );
583
+ }
584
+
585
+ /**
586
+ * @author Vova Feldman (@svovaf)
587
+ * @since 1.0.9
588
+ */
589
+ private function _version_updates_handler() {
590
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
591
+ // Freemius version upgrade mode.
592
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
593
+ $this->_storage->sdk_version = $this->version;
594
+
595
+ if ( empty( $this->_storage->sdk_last_version ) ||
596
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
597
+ ) {
598
+ $this->_storage->sdk_upgrade_mode = true;
599
+ $this->_storage->sdk_downgrade_mode = false;
600
+ } else {
601
+ $this->_storage->sdk_downgrade_mode = true;
602
+ $this->_storage->sdk_upgrade_mode = false;
603
+
604
+ }
605
+
606
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
607
+ }
608
+
609
+ $plugin_version = $this->get_plugin_version();
610
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
611
+ // Plugin version upgrade mode.
612
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
613
+ $this->_storage->plugin_version = $plugin_version;
614
+
615
+ if ( empty( $this->_storage->plugin_last_version ) ||
616
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
617
+ ) {
618
+ $this->_storage->plugin_upgrade_mode = true;
619
+ $this->_storage->plugin_downgrade_mode = false;
620
+ } else {
621
+ $this->_storage->plugin_downgrade_mode = true;
622
+ $this->_storage->plugin_upgrade_mode = false;
623
+ }
624
+
625
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
626
+ // Different version of the plugin was installed before, therefore it's an update.
627
+ $this->_storage->is_plugin_new_install = false;
628
+ }
629
+
630
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
631
+ }
632
+ }
633
+
634
+ #--------------------------------------------------------------------------------
635
+ #region Data Migration on SDK Update
636
+ #--------------------------------------------------------------------------------
637
+
638
+ /**
639
+ * @author Vova Feldman (@svovaf)
640
+ * @since 1.1.5
641
+ *
642
+ * @param string $sdk_prev_version
643
+ * @param string $sdk_version
644
+ */
645
+ function _sdk_version_update( $sdk_prev_version, $sdk_version ) {
646
+ /**
647
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
648
+ */
649
+ if ( empty( $sdk_prev_version ) ) {
650
+ return;
651
+ }
652
+
653
+ if ( version_compare( $sdk_prev_version, '2.1.0', '<' ) &&
654
+ version_compare( $sdk_version, '2.1.0', '>=' )
655
+ ) {
656
+ $this->_storage->handle_gdpr_admin_notice = true;
657
+ }
658
+
659
+ if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
660
+ version_compare( $sdk_version, '2.0.0', '>=' )
661
+ ) {
662
+ $this->migrate_to_subscriptions_collection();
663
+
664
+ $this->consolidate_licenses();
665
+
666
+ // Clear trial_plan since it's now loaded from the plans collection when needed.
667
+ $this->_storage->remove( 'trial_plan', true, false );
668
+ }
669
+
670
+ if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
671
+ version_compare( $sdk_version, '1.2.3', '>=' )
672
+ ) {
673
+ /**
674
+ * Starting from version 1.2.3, paths are stored as relative paths and not absolute paths; so when upgrading to 1.2.3, make paths relative.
675
+ *
676
+ * @author Leo Fajardo (@leorw)
677
+ */
678
+ $this->make_paths_relative();
679
+ }
680
+
681
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
682
+ version_compare( $sdk_version, '1.1.5', '>=' )
683
+ ) {
684
+ // On version 1.1.5 merged connectivity and is_on data.
685
+ if ( isset( $this->_storage->connectivity_test ) ) {
686
+ if ( ! isset( $this->_storage->is_on ) ) {
687
+ unset( $this->_storage->connectivity_test );
688
+ } else {
689
+ $connectivity_data = $this->_storage->connectivity_test;
690
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
691
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
692
+
693
+ // Override.
694
+ $this->_storage->connectivity_test = $connectivity_data;
695
+
696
+ // Remove previous structure.
697
+ unset( $this->_storage->is_on );
698
+ }
699
+
700
+ }
701
+ }
702
+ }
703
+
704
+ /**
705
+ * @author Leo Fajardo (@leorw)
706
+ * @since 2.0.0
707
+ *
708
+ * @param \FS_Storage $storage
709
+ * @param bool|int|null $blog_id
710
+ */
711
+ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
712
+ if ( empty( $storage->sdk_version ) ) {
713
+ // New installation of the plugin, no need to upgrade.
714
+ return;
715
+ }
716
+
717
+ if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
718
+ // Previous version is >= 2.0.0, so no need to migrate.
719
+ return;
720
+ }
721
+
722
+ // Alias.
723
+ $module_type = $storage->get_module_type();
724
+ $module_slug = $storage->get_module_slug();
725
+
726
+ $installs = self::get_all_sites( $module_type, $blog_id );
727
+ $install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
728
+
729
+ if ( ! is_object( $install ) ) {
730
+ return;
731
+ }
732
+
733
+ if ( isset( $install->plan ) && is_object( $install->plan ) ) {
734
+ if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
735
+ $install->plan_id = self::_decrypt( $install->plan->id );
736
+ }
737
+
738
+ unset( $install->plan );
739
+
740
+ $installs[ $module_slug ] = clone $install;
741
+
742
+ self::set_account_option_by_module(
743
+ $module_type,
744
+ 'sites',
745
+ $installs,
746
+ true,
747
+ $blog_id
748
+ );
749
+ }
750
+ }
751
+
752
+ /**
753
+ * @author Leo Fajardo (@leorw)
754
+ * @since 2.0.0
755
+ */
756
+ private function migrate_to_subscriptions_collection() {
757
+ if ( ! is_object( $this->_site ) ) {
758
+ return;
759
+ }
760
+
761
+ if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
762
+ $this->_storage->subscriptions = array( $this->_storage->subscription );
763
+ }
764
+ }
765
+
766
+ /**
767
+ * @author Leo Fajardo (@leorw)
768
+ * @since 2.0.0
769
+ */
770
+ private function consolidate_licenses() {
771
+ $plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
772
+ if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
773
+ $plugin_licenses = $plugin_licenses[ $this->_slug ];
774
+ } else {
775
+ $plugin_licenses = array();
776
+ }
777
+
778
+ $theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
779
+ if ( isset( $theme_licenses[ $this->_slug ] ) ) {
780
+ $theme_licenses = $theme_licenses[ $this->_slug ];
781
+ } else {
782
+ $theme_licenses = array();
783
+ }
784
+
785
+ if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
786
+ return;
787
+ }
788
+
789
+ $all_licenses = array();
790
+ $user_id_license_ids_map = array();
791
+
792
+ foreach ( $plugin_licenses as $user_id => $user_licenses ) {
793
+ if ( is_array( $user_licenses ) ) {
794
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
795
+ $user_id_license_ids_map[ $user_id ] = array();
796
+ }
797
+
798
+ foreach ( $user_licenses as $user_license ) {
799
+ $all_licenses[] = $user_license;
800
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
801
+ }
802
+ }
803
+ }
804
+
805
+ foreach ( $theme_licenses as $user_id => $user_licenses ) {
806
+ if ( is_array( $user_licenses ) ) {
807
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
808
+ $user_id_license_ids_map[ $user_id ] = array();
809
+ }
810
+
811
+ foreach ( $user_licenses as $user_license ) {
812
+ $all_licenses[] = $user_license;
813
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
814
+ }
815
+ }
816
+ }
817
+
818
+ self::store_user_id_license_ids_map(
819
+ $user_id_license_ids_map,
820
+ $this->_module_id
821
+ );
822
+
823
+ $this->_store_licenses( true, $this->_module_id, $all_licenses );
824
+ }
825
+
826
+ /**
827
+ * Makes paths relative.
828
+ *
829
+ * @author Leo Fajardo (@leorw)
830
+ * @since 1.2.3
831
+ */
832
+ private function make_paths_relative() {
833
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
834
+
835
+ if ( isset( $id_slug_type_path_map[ $this->_module_id ]['path'] ) ) {
836
+ $id_slug_type_path_map[ $this->_module_id ]['path'] = $this->get_relative_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
837
+
838
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
839
+ }
840
+
841
+ if ( isset( $this->_storage->plugin_main_file ) ) {
842
+ $plugin_main_file = $this->_storage->plugin_main_file;
843
+
844
+ if ( isset( $plugin_main_file->path ) ) {
845
+ $this->_storage->plugin_main_file->path = $this->get_relative_path( $this->_storage->plugin_main_file->path );
846
+ } else if ( isset( $plugin_main_file->prev_path ) ) {
847
+ $this->_storage->plugin_main_file->prev_path = $this->get_relative_path( $this->_storage->plugin_main_file->prev_path );
848
+ }
849
+ }
850
+
851
+ // Remove invalid path that is still associated with the current slug if there's any.
852
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
853
+ foreach ( $file_slug_map as $plugin_basename => $slug ) {
854
+ if ( $slug === $this->_slug &&
855
+ $plugin_basename !== $this->_plugin_basename &&
856
+ ! file_exists( $this->get_absolute_path( $plugin_basename ) )
857
+ ) {
858
+ unset( $file_slug_map[ $plugin_basename ] );
859
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
860
+
861
+ break;
862
+ }
863
+ }
864
+ }
865
+
866
+ /**
867
+ * @author Vova Feldman (@svovaf)
868
+ * @since 1.2.2.7
869
+ *
870
+ * @param string $plugin_prev_version
871
+ * @param string $plugin_version
872
+ */
873
+ function _after_version_update( $plugin_prev_version, $plugin_version ) {
874
+ if ( $this->is_theme() ) {
875
+ // Expire the cache of the previous tabs since the theme may
876
+ // have setting updates.
877
+ $this->_cache->expire( 'tabs' );
878
+ $this->_cache->expire( 'tabs_stylesheets' );
879
+ }
880
+ }
881
+
882
+ /**
883
+ * A special migration logic for the $_accounts, executed for all the plugins in the system:
884
+ * - Moves some data to the network level storage.
885
+ * - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
886
+ * - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
887
+ * - If the plugin was connected to all sites by the same super-admin, set the plugin as if was network opted-in for all sites.
888
+ * - If there's at least one site that was connected by a super-admin, find the "main super-admin" (the one that installed the majority of the plugin installs) and set the plugin as if was network activated with the main super-admin, set all the sites that were skipped or opted-in with a different user to delegated mode. Then, prompt the currently logged super-admin to choose what to do with the ignored sites.
889
+ * - If there are any sites in the network which the connection decision was not yet taken for, set this plugin into network activation mode so a super-admin can choose what to do with the rest of the sites.
890
+ *
891
+ * @author Vova Feldman (@svovaf)
892
+ * @since 2.0.0
893
+ */
894
+ private static function migrate_accounts_to_network() {
895
+ $sites = self::get_sites();
896
+ $sites_count = count( $sites );
897
+ $connection_status = array();
898
+ $plugin_slugs = array();
899
+ foreach ( $sites as $site ) {
900
+ $blog_id = self::get_site_blog_id( $site );
901
+
902
+ self::$_accounts->migrate_to_network( $blog_id );
903
+
904
+ /**
905
+ * Build a list of all Freemius powered plugins slugs.
906
+ */
907
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
908
+ foreach ( $id_slug_type_path_map as $module_id => $data ) {
909
+ if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
910
+ $plugin_slugs[ $data['slug'] ] = true;
911
+ }
912
+ }
913
+
914
+ $installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
915
+
916
+ if ( is_array( $installs ) ) {
917
+ foreach ( $installs as $slug => $install ) {
918
+ if ( ! isset( $connection_status[ $slug ] ) ) {
919
+ $connection_status[ $slug ] = array();
920
+ }
921
+
922
+ if ( is_object( $install ) &&
923
+ FS_Site::is_valid_id( $install->id ) &&
924
+ FS_User::is_valid_id( $install->user_id )
925
+ ) {
926
+ $connection_status[ $slug ][ $blog_id ] = $install->user_id;
927
+ }
928
+ }
929
+ }
930
+ }
931
+
932
+ foreach ( $plugin_slugs as $slug => $true ) {
933
+ if ( ! isset( $connection_status[ $slug ] ) ) {
934
+ $connection_status[ $slug ] = array();
935
+ }
936
+
937
+ foreach ( $sites as $site ) {
938
+ $blog_id = self::get_site_blog_id( $site );
939
+
940
+ if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
941
+ continue;
942
+ }
943
+
944
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
945
+
946
+ $is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
947
+
948
+ if ( ! is_null( $is_anonymous ) ) {
949
+ // Since 1.1.3 is_anonymous is an array.
950
+ if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
951
+ $is_anonymous = $is_anonymous['is'];
952
+ }
953
+
954
+ if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
955
+ $connection_status[ $slug ][ $blog_id ] = 'skipped';
956
+ }
957
+ }
958
+
959
+ if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
960
+ $connection_status[ $slug ][ $blog_id ] = 'ignored';
961
+ }
962
+ }
963
+ }
964
+
965
+ $super_admins = array();
966
+
967
+ foreach ( $connection_status as $slug => $blogs_status ) {
968
+ $skips = 0;
969
+ $ignores = 0;
970
+ $connections = 0;
971
+ $opted_in_users = array();
972
+ $opted_in_super_admins = array();
973
+
974
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
975
+
976
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
977
+ if ( 'skipped' === $status_or_user_id ) {
978
+ $skips ++;
979
+ } else if ( 'ignored' === $status_or_user_id ) {
980
+ $ignores ++;
981
+ } else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
982
+ $connections ++;
983
+
984
+ if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
985
+ $opted_in_users[ $status_or_user_id ] = array();
986
+ }
987
+
988
+ $opted_in_users[ $status_or_user_id ][] = $blog_id;
989
+
990
+ if ( isset( $super_admins[ $status_or_user_id ] ) ||
991
+ self::is_super_admin( $status_or_user_id )
992
+ ) {
993
+ // Cache super-admin data.
994
+ $super_admins[ $status_or_user_id ] = true;
995
+
996
+ // Remember opted-in super-admins for the plugin.
997
+ $opted_in_super_admins[ $status_or_user_id ] = true;
998
+ }
999
+ }
1000
+ }
1001
+
1002
+ $main_super_admin_user_id = null;
1003
+ $all_migrated = false;
1004
+ if ( $sites_count == $skips ) {
1005
+ // All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
1006
+ $storage->is_anonymous_ms = $storage->is_anonymous;
1007
+
1008
+ $all_migrated = true;
1009
+ } else if ( $sites_count == $ignores ) {
1010
+ // Don't do anything, still in activation mode.
1011
+
1012
+ $all_migrated = true;
1013
+ } else if ( 0 < count( $opted_in_super_admins ) ) {
1014
+ // Find the super-admin with the majority of installs.
1015
+ $max_installs_by_super_admin = 0;
1016
+ foreach ( $opted_in_super_admins as $user_id => $true ) {
1017
+ $installs_count = count( $opted_in_users[ $user_id ] );
1018
+
1019
+ if ( $installs_count > $max_installs_by_super_admin ) {
1020
+ $max_installs_by_super_admin = $installs_count;
1021
+ $main_super_admin_user_id = $user_id;
1022
+ }
1023
+ }
1024
+
1025
+ if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
1026
+ // Super-admin opted-in for all sites in the network.
1027
+ $storage->is_network_connected = true;
1028
+
1029
+ $all_migrated = true;
1030
+ }
1031
+
1032
+ // Store network user.
1033
+ $storage->network_user_id = $main_super_admin_user_id;
1034
+
1035
+ $storage->network_install_blog_id = ( $sites_count == $connections ) ?
1036
+ // Since all sites are opted-in, associating with the main site.
1037
+ get_current_blog_id() :
1038
+ // Associating with the 1st found opted-in site.
1039
+ $opted_in_users[ $main_super_admin_user_id ][0];
1040
+
1041
+ /**
1042
+ * Make sure we migrate the plan ID of the network install, otherwise, if after the migration
1043
+ * the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
1044
+ * is different than the main site of the network, the $this->_site will not be set since the plan_id
1045
+ * will be empty.
1046
+ */
1047
+ $storage->migrate_to_network();
1048
+ self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
1049
+ } else {
1050
+ // At least one opt-in. All the opt-in were created by a non-super-admin.
1051
+ if ( 0 == $ignores ) {
1052
+ // All sites were opted-in or skipped, all by non-super-admin. So delegate all.
1053
+ $storage->store( 'is_delegated_connection', true, true );
1054
+
1055
+ $all_migrated = true;
1056
+ }
1057
+ }
1058
+
1059
+ if ( ! $all_migrated ) {
1060
+ /**
1061
+ * Delegate all sites that were:
1062
+ * 1) Opted-in by a user that is NOT the main-super-admin.
1063
+ * 2) Skipped and non of the sites was opted-in by a super-admin. If any site was opted-in by a super-admin, there will be a main-super-admin, and we consider the skip as if it was done by that user.
1064
+ */
1065
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1066
+ if ( $status_or_user_id == $main_super_admin_user_id ) {
1067
+ continue;
1068
+ }
1069
+
1070
+ if ( FS_User::is_valid_id( $status_or_user_id ) ||
1071
+ ( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
1072
+ ) {
1073
+ $storage->store( 'is_delegated_connection', true, $blog_id );
1074
+ }
1075
+ }
1076
+ }
1077
+
1078
+
1079
+ if ( ( $connections + $skips > 0 ) ) {
1080
+ if ( $ignores > 0 ) {
1081
+ /**
1082
+ * If admin already opted-in or skipped in any of the network sites, and also
1083
+ * have sites which the connection decision was not yet taken, set this plugin
1084
+ * into network activation mode so the super-admin can choose what to do with
1085
+ * the rest of the sites.
1086
+ */
1087
+ self::set_network_upgrade_mode( $storage );
1088
+ }
1089
+ }
1090
+ }
1091
+ }
1092
+
1093
+ /**
1094
+ * Set a module into network upgrade mode.
1095
+ *
1096
+ * @author Vova Feldman (@svovaf)
1097
+ * @since 2.0.0
1098
+ *
1099
+ * @param \FS_Storage $storage
1100
+ *
1101
+ * @return bool
1102
+ */
1103
+ private static function set_network_upgrade_mode( FS_Storage $storage ) {
1104
+ return $storage->is_network_activation = true;
1105
+ }
1106
+
1107
+ /**
1108
+ * Will return true after upgrading to the SDK with the network level integration,
1109
+ * when the super-admin involvement is required regarding the rest of the sites.
1110
+ *
1111
+ * @author Vova Feldman (@svovaf)
1112
+ * @since 2.0.0
1113
+ *
1114
+ * @return bool
1115
+ */
1116
+ function is_network_upgrade_mode() {
1117
+ return $this->_storage->get( 'is_network_activation' );
1118
+ }
1119
+
1120
+ /**
1121
+ * Clear flag after the upgrade mode completion.
1122
+ *
1123
+ * @author Vova Feldman (@svovaf)
1124
+ * @since 2.0.0
1125
+ *
1126
+ * @return bool True if network activation was on and now completed.
1127
+ */
1128
+ private function network_upgrade_mode_completed() {
1129
+ if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
1130
+ $this->_storage->remove( 'is_network_activation' );
1131
+
1132
+ return true;
1133
+ }
1134
+
1135
+ return false;
1136
+ }
1137
+
1138
+ #endregion
1139
+
1140
+ /**
1141
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
1142
+ * if this is a new plugin installation or a plugin update.
1143
+ *
1144
+ * There are 3 different use-cases:
1145
+ * 1) New plugin installation right with Freemius:
1146
+ * 1.1 _activate_plugin_event_hook() will be executed first
1147
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
1148
+ * and $this->_storage->plugin_last_version is not set,
1149
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
1150
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1151
+ * be already set to TRUE.
1152
+ *
1153
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
1154
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
1155
+ * the activation hook do NOT fires on updates since WP 3.1.
1156
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1157
+ * be empty, therefore, it will be set to FALSE.
1158
+ *
1159
+ * 3) Plugin update, had Freemius in prev version as well:
1160
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
1161
+ * before, $this->_storage->plugin_last_version will NOT be empty,
1162
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
1163
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
1164
+ * already set, therefore, it will not be modified.
1165
+ *
1166
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
1167
+ *
1168
+ * NOTE:
1169
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
1170
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
1171
+ * show the opt-in right away. The reason it will happen is because Freemius execution
1172
+ * will be turned off till the plugin is fully loaded at least once
1173
+ * (till $this->_storage->was_plugin_loaded is TRUE).
1174
+ *
1175
+ * @author Vova Feldman (@svovaf)
1176
+ * @since 1.1.9
1177
+ *
1178
+ */
1179
+ function _plugins_loaded() {
1180
+ // Update flag that plugin was loaded with Freemius at least once.
1181
+ $this->_storage->was_plugin_loaded = true;
1182
+
1183
+ /**
1184
+ * Bug fix - only set to false when it's a plugin, due to the
1185
+ * execution sequence of the theme hooks and our methods, if
1186
+ * this will be set for themes, Freemius will always assume
1187
+ * it's a theme update.
1188
+ *
1189
+ * @author Vova Feldman (@svovaf)
1190
+ * @since 1.2.2.2
1191
+ */
1192
+ if ( $this->is_plugin() &&
1193
+ ! isset( $this->_storage->is_plugin_new_install )
1194
+ ) {
1195
+ $this->_storage->is_plugin_new_install = false;
1196
+ }
1197
+ }
1198
+
1199
+ /**
1200
+ * Add special parameter to WP admin AJAX calls so when we
1201
+ * process AJAX calls we can identify its source properly.
1202
+ *
1203
+ * @author Leo Fajardo (@leorw)
1204
+ * @since 2.0.0
1205
+ */
1206
+ static function _enrich_ajax_url() {
1207
+ $admin_param = is_network_admin() ?
1208
+ '_fs_network_admin' :
1209
+ '_fs_blog_admin';
1210
+ ?>
1211
+ <script type="text/javascript">
1212
+ (function ($) {
1213
+ $(document).ajaxSend(function (event, jqxhr, settings) {
1214
+ if (settings.url &&
1215
+ -1 < settings.url.indexOf('admin-ajax.php') &&
1216
+ ! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
1217
+ ) {
1218
+ if (settings.url.indexOf('?') > 0) {
1219
+ settings.url += '&';
1220
+ } else {
1221
+ settings.url += '?';
1222
+ }
1223
+
1224
+ settings.url += '<?php echo $admin_param ?>=true';
1225
+
1226
+ }
1227
+ });
1228
+ })(jQuery);
1229
+ </script>
1230
+ <?php
1231
+ }
1232
+
1233
+ /**
1234
+ * @author Vova Feldman (@svovaf)
1235
+ * @since 1.0.9
1236
+ */
1237
+ private function _register_hooks() {
1238
+ $this->_logger->entrance();
1239
+
1240
+ if ( is_admin() ) {
1241
+ add_action( 'plugins_loaded', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
1242
+
1243
+ if ( $this->is_plugin() ) {
1244
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
1245
+
1246
+ /**
1247
+ * @since 1.2.2
1248
+ *
1249
+ * Hook to both free and premium version activations to support
1250
+ * auto deactivation on the other version activation.
1251
+ */
1252
+ register_activation_hook(
1253
+ $plugin_dir . $this->_free_plugin_basename,
1254
+ array( &$this, '_activate_plugin_event_hook' )
1255
+ );
1256
+
1257
+ register_activation_hook(
1258
+ $plugin_dir . $this->premium_plugin_basename(),
1259
+ array( &$this, '_activate_plugin_event_hook' )
1260
+ );
1261
+ } else {
1262
+ add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
1263
+
1264
+ /**
1265
+ * Include the required hooks to capture the theme settings' page tabs
1266
+ * and cache them.
1267
+ *
1268
+ * @author Vova Feldman (@svovaf)
1269
+ * @since 1.2.2.7
1270
+ */
1271
+ if ( ! $this->_cache->has_valid( 'tabs' ) ) {
1272
+ add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
1273
+ // Add license activation AJAX callback.
1274
+ $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
1275
+
1276
+ add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
1277
+ }
1278
+
1279
+ add_action(
1280
+ 'admin_footer',
1281
+ array( &$this, '_add_freemius_tabs' ),
1282
+ /**
1283
+ * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
1284
+ * That's why the priority is 11 while the tabs capture logic is added
1285
+ * with priority 10.
1286
+ *
1287
+ * @author Vova Feldman (@svovaf)
1288
+ */
1289
+ 11
1290
+ );
1291
+
1292
+ add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
1293
+ }
1294
+
1295
+ /**
1296
+ * Part of the mechanism to identify new plugin install vs. plugin update.
1297
+ *
1298
+ * @author Vova Feldman (@svovaf)
1299
+ * @since 1.1.9
1300
+ */
1301
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
1302
+ /**
1303
+ * During the plugin activation (not theme), 'plugins_loaded' will be already executed
1304
+ * when the logic gets here since the activation logic first add the activate plugins,
1305
+ * then triggers 'plugins_loaded', and only then include the code of the plugin that
1306
+ * is activated. Which means that _plugins_loaded() will NOT be executed during the
1307
+ * plugin activation, and that IS intentional.
1308
+ *
1309
+ * @author Vova Feldman (@svovaf)
1310
+ */
1311
+ if ( $this->is_plugin() && $this->is_activation_mode( false ) ) {
1312
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
1313
+ } else {
1314
+ // If was activated before, then it was already loaded before.
1315
+ $this->_plugins_loaded();
1316
+ }
1317
+ }
1318
+
1319
+ if ( ! self::is_ajax() ) {
1320
+ if ( ! $this->is_addon() ) {
1321
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
1322
+ }
1323
+ }
1324
+
1325
+ if ( $this->_storage->handle_gdpr_admin_notice ) {
1326
+ add_action( 'init', array( &$this, '_maybe_show_gdpr_admin_notice' ) );
1327
+ }
1328
+
1329
+ add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
1330
+ }
1331
+
1332
+ if ( $this->is_plugin() ) {
1333
+ if ( $this->_is_network_active ) {
1334
+ add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
1335
+ }
1336
+
1337
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
1338
+ }
1339
+
1340
+ if ( is_multisite() ) {
1341
+ add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
1342
+ add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
1343
+ add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
1344
+ add_action( 'deleted_blog', array( &$this, '_after_site_deleted_callback' ), 10, 2 );
1345
+
1346
+ add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
1347
+ add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
1348
+ add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
1349
+ }
1350
+
1351
+ if ( $this->is_theme() && self::is_customizer() ) {
1352
+ // Register customizer upsell.
1353
+ add_action( 'customize_register', array( &$this, '_customizer_register' ) );
1354
+ }
1355
+
1356
+ add_action( 'admin_init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
1357
+
1358
+ if ( $this->is_theme() ) {
1359
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1360
+ }
1361
+
1362
+ add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
1363
+ add_action( 'admin_init', array( &$this, '_add_premium_version_upgrade_selection' ) );
1364
+
1365
+ $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
1366
+ $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
1367
+
1368
+ if ( $this->_is_network_active && fs_is_network_admin() ) {
1369
+ $this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
1370
+ }
1371
+
1372
+ $this->add_ajax_action( 'install_premium_version', array(
1373
+ &$this,
1374
+ '_install_premium_version_ajax_action'
1375
+ ) );
1376
+
1377
+ $this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
1378
+
1379
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
1380
+
1381
+ $this->add_action( 'sdk_version_update', array( &$this, '_sdk_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
1382
+
1383
+ $this->add_action(
1384
+ 'plugin_version_update',
1385
+ array( &$this, '_after_version_update' ),
1386
+ WP_FS__DEFAULT_PRIORITY,
1387
+ 2
1388
+ );
1389
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
1390
+
1391
+ add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1392
+ add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
1393
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
1394
+
1395
+ /**
1396
+ * Handle request to reset anonymous mode for `get_reconnect_url()`.
1397
+ *
1398
+ * @author Vova Feldman (@svovaf)
1399
+ * @since 1.2.1.5
1400
+ */
1401
+ if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
1402
+ $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1403
+ ) {
1404
+ add_action( 'admin_init', array( &$this, 'connect_again' ) );
1405
+ }
1406
+ }
1407
+
1408
+ /**
1409
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
1410
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
1411
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
1412
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
1413
+ *
1414
+ * @author Leo Fajardo (@leorw)
1415
+ *
1416
+ * @since 1.2.0
1417
+ */
1418
+ private function unregister_uninstall_hook() {
1419
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
1420
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
1421
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
1422
+
1423
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
1424
+ }
1425
+
1426
+ /**
1427
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
1428
+ */
1429
+ private function clear_module_main_file_cache() {
1430
+ if ( ! isset( $this->_storage->plugin_main_file ) ||
1431
+ empty( $this->_storage->plugin_main_file->path )
1432
+ ) {
1433
+ return;
1434
+ }
1435
+
1436
+ $plugin_main_file = clone $this->_storage->plugin_main_file;
1437
+
1438
+ // Store cached path (2nd layer cache).
1439
+ $plugin_main_file->prev_path = $plugin_main_file->path;
1440
+
1441
+ // Clear cached path.
1442
+ unset( $plugin_main_file->path );
1443
+
1444
+ $this->_storage->plugin_main_file = $plugin_main_file;
1445
+
1446
+ /**
1447
+ * Clear global cached path.
1448
+ *
1449
+ * @author Leo Fajardo (@leorw)
1450
+ * @since 1.2.2
1451
+ */
1452
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
1453
+ unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1454
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1455
+ }
1456
+
1457
+ /**
1458
+ * @author Leo Fajardo (@leorw)
1459
+ * @since 2.0.0
1460
+ */
1461
+ function _hook_action_links_and_register_account_hooks() {
1462
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1463
+
1464
+ if ( self::is_plugins_page() && $this->is_plugin() ) {
1465
+ $this->hook_plugin_action_links();
1466
+ }
1467
+
1468
+ $this->_register_account_hooks();
1469
+ }
1470
+
1471
+ /**
1472
+ * @author Vova Feldman (@svovaf)
1473
+ * @since 1.0.9
1474
+ */
1475
+ private function _register_account_hooks() {
1476
+ if ( ! is_admin() ) {
1477
+ return;
1478
+ }
1479
+
1480
+ /**
1481
+ * Always show the deactivation feedback form since we added
1482
+ * automatic free version deactivation upon premium code activation.
1483
+ *
1484
+ * @since 1.2.1.6
1485
+ */
1486
+ $this->add_ajax_action(
1487
+ 'submit_uninstall_reason',
1488
+ array( &$this, '_submit_uninstall_reason_action' )
1489
+ );
1490
+
1491
+ if ( $this->is_theme() && $this->is_premium() && ! $this->has_active_valid_license() ) {
1492
+ $this->add_ajax_action(
1493
+ 'delete_theme_update_data',
1494
+ array( &$this, '_delete_theme_update_data_action' )
1495
+ );
1496
+ }
1497
+
1498
+ if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
1499
+ if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
1500
+ ( $this->is_theme() && self::is_themes_page() )
1501
+ ) {
1502
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
1503
+ }
1504
+ }
1505
+ }
1506
+
1507
+ /**
1508
+ * Leverage backtrace to find caller plugin file path.
1509
+ *
1510
+ * @author Vova Feldman (@svovaf)
1511
+ * @since 1.0.6
1512
+ *
1513
+ * @param bool $is_init Is initiation sequence.
1514
+ *
1515
+ * @return string
1516
+ */
1517
+ private function _find_caller_plugin_file( $is_init = false ) {
1518
+ // Try to load the cached value of the file path.
1519
+ if ( isset( $this->_storage->plugin_main_file ) ) {
1520
+ $plugin_main_file = $this->_storage->plugin_main_file;
1521
+ if ( isset( $plugin_main_file->path ) ) {
1522
+ $absolute_path = $this->get_absolute_path( $plugin_main_file->path );
1523
+ if ( file_exists( $absolute_path ) ) {
1524
+ return $absolute_path;
1525
+ }
1526
+ }
1527
+ }
1528
+
1529
+ /**
1530
+ * @since 1.2.1
1531
+ *
1532
+ * `clear_module_main_file_cache()` is clearing the plugin's cached path on
1533
+ * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
1534
+ * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
1535
+ *
1536
+ * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
1537
+ * when the class instantiator isn't the module.
1538
+ */
1539
+ if ( ! $is_init ) {
1540
+ // Fetch prev path cache.
1541
+ if ( isset( $this->_storage->plugin_main_file ) &&
1542
+ isset( $this->_storage->plugin_main_file->prev_path )
1543
+ ) {
1544
+ $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
1545
+ if ( file_exists( $absolute_path ) ) {
1546
+ return $absolute_path;
1547
+ }
1548
+ }
1549
+
1550
+ wp_die(
1551
+ $this->get_text_inline( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'failed-finding-main-path' ) .
1552
+ " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
1553
+ $this->get_text_inline( 'Error', 'error' ),
1554
+ array( 'back_link' => true )
1555
+ );
1556
+ }
1557
+
1558
+ /**
1559
+ * @since 1.2.1
1560
+ *
1561
+ * Only the original instantiator that calls dynamic_init can modify the module's path.
1562
+ */
1563
+ // Find caller module.
1564
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
1565
+ $this->_storage->plugin_main_file = (object) array(
1566
+ 'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
1567
+ );
1568
+
1569
+ return $this->get_absolute_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1570
+ }
1571
+
1572
+ /**
1573
+ * @author Leo Fajardo (@leorw)
1574
+ * @since 1.2.3
1575
+ *
1576
+ * @param string $path
1577
+ *
1578
+ * @return string
1579
+ */
1580
+ private function get_relative_path( $path ) {
1581
+ $module_root_dir = $this->get_module_root_dir_path();
1582
+ if ( 0 === strpos( $path, $module_root_dir ) ) {
1583
+ $path = substr( $path, strlen( $module_root_dir ) );
1584
+ }
1585
+
1586
+ return $path;
1587
+ }
1588
+
1589
+ /**
1590
+ * @author Leo Fajardo (@leorw)
1591
+ * @since 1.2.3
1592
+ *
1593
+ * @param string $path
1594
+ * @param string|bool $module_type
1595
+ *
1596
+ * @return string
1597
+ */
1598
+ private function get_absolute_path( $path, $module_type = false ) {
1599
+ $module_root_dir = $this->get_module_root_dir_path( $module_type );
1600
+ if ( 0 !== strpos( $path, $module_root_dir ) ) {
1601
+ $path = fs_normalize_path( $module_root_dir . $path );
1602
+ }
1603
+
1604
+ return $path;
1605
+ }
1606
+
1607
+ /**
1608
+ * @author Leo Fajardo (@leorw)
1609
+ * @since 1.2.3
1610
+ *
1611
+ * @param string|bool $module_type
1612
+ *
1613
+ * @return string
1614
+ */
1615
+ private function get_module_root_dir_path( $module_type = false ) {
1616
+ $is_plugin = empty( $module_type ) ?
1617
+ $this->is_plugin() :
1618
+ ( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
1619
+
1620
+ return fs_normalize_path( trailingslashit( $is_plugin ?
1621
+ WP_PLUGIN_DIR :
1622
+ get_theme_root() ) );
1623
+ }
1624
+
1625
+ /**
1626
+ * @author Leo Fajardo (@leorw)
1627
+ *
1628
+ * @param number $module_id
1629
+ * @param string $slug
1630
+ *
1631
+ * @since 1.2.2
1632
+ */
1633
+ private function store_id_slug_type_path_map( $module_id, $slug ) {
1634
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
1635
+
1636
+ $store_option = false;
1637
+
1638
+ if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
1639
+ $id_slug_type_path_map[ $module_id ] = array(
1640
+ 'slug' => $slug
1641
+ );
1642
+
1643
+ $store_option = true;
1644
+ }
1645
+
1646
+ if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ||
1647
+ /**
1648
+ * This verification is for cases when suddenly the same module
1649
+ * is installed but with a different folder name.
1650
+ *
1651
+ * @author Vova Feldman (@svovaf)
1652
+ * @since 1.2.3
1653
+ */
1654
+ ! file_exists( $this->get_absolute_path(
1655
+ $id_slug_type_path_map[ $module_id ]['path'],
1656
+ $id_slug_type_path_map[ $module_id ]['type']
1657
+ ) )
1658
+ ) {
1659
+ $caller_main_file_and_type = $this->get_caller_main_file_and_type();
1660
+
1661
+ $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
1662
+ $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
1663
+
1664
+ $store_option = true;
1665
+ }
1666
+
1667
+ if ( $store_option ) {
1668
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1669
+ }
1670
+ }
1671
+
1672
+ /**
1673
+ * Identifies the caller type: plugin or theme.
1674
+ *
1675
+ * @author Leo Fajardo (@leorw)
1676
+ * @since 1.2.2
1677
+ *
1678
+ * @author Vova Feldman (@svovaf)
1679
+ * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
1680
+ * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
1681
+ * SDK an internal file instead of directly from functions.php.
1682
+ * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
1683
+ */
1684
+ private function get_caller_main_file_and_type() {
1685
+ self::require_plugin_essentials();
1686
+
1687
+ $all_plugins = get_plugins();
1688
+ $all_plugins_paths = array();
1689
+
1690
+ // Get active plugin's main files real full names (might be symlinks).
1691
+ foreach ( $all_plugins as $relative_path => &$data ) {
1692
+ if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
1693
+ /**
1694
+ * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
1695
+ * can't really include the SDK.
1696
+ *
1697
+ * @author Vova Feldman
1698
+ * @since 1.2.1.7
1699
+ */
1700
+ continue;
1701
+ }
1702
+
1703
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
1704
+ }
1705
+
1706
+ $caller_file_candidate = false;
1707
+ $caller_map = array();
1708
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1709
+ $themes_dir = fs_normalize_path( get_theme_root() );
1710
+
1711
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
1712
+ if ( empty( $bt[ $i ]['file'] ) ) {
1713
+ continue;
1714
+ }
1715
+
1716
+ if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
1717
+ // If file same as the prev file in the stack, skip it.
1718
+ continue;
1719
+ }
1720
+
1721
+ if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
1722
+ 'do_action',
1723
+ 'apply_filter',
1724
+ // The string split is stupid, but otherwise, theme check
1725
+ // throws info notices.
1726
+ 'requir' . 'e_once',
1727
+ 'requir' . 'e',
1728
+ 'includ' . 'e_once',
1729
+ 'includ' . 'e'
1730
+ ) )
1731
+ ) {
1732
+ // Ignore call stack hooks and files inclusion.
1733
+ continue;
1734
+ }
1735
+
1736
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
1737
+
1738
+ if ( 'functions.php' === basename( $caller_file_path ) ) {
1739
+ /**
1740
+ * 1. Assumes that theme's starting execution file is functions.php.
1741
+ * 2. This complex logic fixes symlink issues (e.g. with Vargant).
1742
+ *
1743
+ * @author Vova Feldman (@svovaf)
1744
+ * @since 1.2.2.5
1745
+ */
1746
+
1747
+ if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
1748
+ $module_type = WP_FS__MODULE_TYPE_THEME;
1749
+
1750
+ /**
1751
+ * Relative path of the theme, e.g.:
1752
+ * `my-theme/functions.php`
1753
+ *
1754
+ * @author Leo Fajardo (@leorw)
1755
+ */
1756
+ $caller_file_candidate = basename( dirname( $caller_file_path ) ) .
1757
+ '/' .
1758
+ basename( $caller_file_path );
1759
+
1760
+ continue;
1761
+ }
1762
+ }
1763
+
1764
+ $caller_file_hash = md5( $caller_file_path );
1765
+
1766
+ if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
1767
+ foreach ( $all_plugins_paths as $plugin_path ) {
1768
+ if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
1769
+ $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
1770
+ break;
1771
+ }
1772
+ }
1773
+ }
1774
+
1775
+ if ( isset( $caller_map[ $caller_file_hash ] ) ) {
1776
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1777
+ $caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
1778
+ }
1779
+ }
1780
+
1781
+ return (object) array(
1782
+ 'module_type' => $module_type,
1783
+ 'path' => $caller_file_candidate
1784
+ );
1785
+ }
1786
+
1787
+ #----------------------------------------------------------------------------------
1788
+ #region Deactivation Feedback Form
1789
+ #----------------------------------------------------------------------------------
1790
+
1791
+ /**
1792
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
1793
+ * page.
1794
+ *
1795
+ * @author Vova Feldman (@svovaf)
1796
+ * @author Leo Fajardo (@leorw)
1797
+ * @since 1.1.2
1798
+ */
1799
+ function _add_deactivation_feedback_dialog_box() {
1800
+ /* Check the type of user:
1801
+ * 1. Long-term (long-term)
1802
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
1803
+ * 3. Short-term (short-term)
1804
+ */
1805
+ $is_long_term_user = true;
1806
+
1807
+ // Check if the site is at least 2 days old.
1808
+ $time_installed = $this->_storage->install_timestamp;
1809
+
1810
+ // Difference in seconds.
1811
+ $date_diff = time() - $time_installed;
1812
+
1813
+ // Convert seconds to days.
1814
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
1815
+
1816
+ if ( $date_diff_days < 2 ) {
1817
+ $is_long_term_user = false;
1818
+ }
1819
+
1820
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
1821
+
1822
+ if ( $is_long_term_user ) {
1823
+ $user_type = 'long-term';
1824
+ } else {
1825
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
1826
+ $user_type = 'non-registered-and-non-anonymous-short-term';
1827
+ } else {
1828
+ $user_type = 'short-term';
1829
+ }
1830
+ }
1831
+
1832
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
1833
+
1834
+ // Load the HTML template for the deactivation feedback dialog box.
1835
+ $vars = array(
1836
+ 'reasons' => $uninstall_reasons,
1837
+ 'id' => $this->_module_id
1838
+ );
1839
+
1840
+ /**
1841
+ * @todo Deactivation form core functions should be loaded only once! Otherwise, when there are multiple Freemius powered plugins the same code is loaded multiple times. The only thing that should be loaded differently is the various deactivation reasons object based on the state of the plugin.
1842
+ */
1843
+ fs_require_template( 'forms/deactivation/form.php', $vars );
1844
+ }
1845
+
1846
+ /**
1847
+ * @author Leo Fajardo (@leorw)
1848
+ * @since 1.1.2
1849
+ *
1850
+ * @param string $user_type
1851
+ *
1852
+ * @return array The uninstall reasons for the specified user type.
1853
+ */
1854
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
1855
+ $module_type = $this->_module_type;
1856
+
1857
+ $internal_message_template_var = array(
1858
+ 'id' => $this->_module_id
1859
+ );
1860
+
1861
+ $plan = $this->get_plan();
1862
+
1863
+ if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
1864
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
1865
+ } else {
1866
+ $contact_support_template = '';
1867
+ }
1868
+
1869
+ $reason_found_better_plugin = array(
1870
+ 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
1871
+ 'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
1872
+ 'input_type' => 'textfield',
1873
+ 'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
1874
+ );
1875
+
1876
+ $reason_temporary_deactivation = array(
1877
+ 'id' => self::REASON_TEMPORARY_DEACTIVATION,
1878
+ 'text' => sprintf(
1879
+ $this->get_text_inline( "It's a temporary %s. I'm just debugging an issue.", 'reason-temporary-x' ),
1880
+ strtolower( $this->is_plugin() ?
1881
+ $this->get_text_inline( 'Deactivation', 'deactivation' ) :
1882
+ $this->get_text_inline( 'Theme Switch', 'theme-switch' )
1883
+ )
1884
+ ),
1885
+ 'input_type' => '',
1886
+ 'input_placeholder' => ''
1887
+ );
1888
+
1889
+ $reason_other = array(
1890
+ 'id' => self::REASON_OTHER,
1891
+ 'text' => $this->get_text_inline( 'Other', 'reason-other' ),
1892
+ 'input_type' => 'textfield',
1893
+ 'input_placeholder' => ''
1894
+ );
1895
+
1896
+ $long_term_user_reasons = array(
1897
+ array(
1898
+ 'id' => self::REASON_NO_LONGER_NEEDED,
1899
+ 'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
1900
+ 'input_type' => '',
1901
+ 'input_placeholder' => ''
1902
+ ),
1903
+ $reason_found_better_plugin,
1904
+ array(
1905
+ 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
1906
+ 'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
1907
+ 'input_type' => '',
1908
+ 'input_placeholder' => ''
1909
+ ),
1910
+ array(
1911
+ 'id' => self::REASON_BROKE_MY_SITE,
1912
+ 'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
1913
+ 'input_type' => '',
1914
+ 'input_placeholder' => '',
1915
+ 'internal_message' => $contact_support_template
1916
+ ),
1917
+ array(
1918
+ 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
1919
+ 'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
1920
+ 'input_type' => '',
1921
+ 'input_placeholder' => '',
1922
+ 'internal_message' => $contact_support_template
1923
+ )
1924
+ );
1925
+
1926
+ if ( $this->is_paying() ) {
1927
+ $long_term_user_reasons[] = array(
1928
+ 'id' => self::REASON_CANT_PAY_ANYMORE,
1929
+ 'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
1930
+ 'input_type' => 'textfield',
1931
+ 'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
1932
+ );
1933
+ }
1934
+
1935
+ $reason_dont_share_info = array(
1936
+ 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
1937
+ 'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
1938
+ 'input_type' => '',
1939
+ 'input_placeholder' => ''
1940
+ );
1941
+
1942
+ /**
1943
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
1944
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
1945
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
1946
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
1947
+ * button in the opt-in form is shown/hidden).
1948
+ */
1949
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
1950
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
1951
+ }
1952
+
1953
+ $uninstall_reasons = array(
1954
+ 'long-term' => $long_term_user_reasons,
1955
+ 'non-registered-and-non-anonymous-short-term' => array(
1956
+ array(
1957
+ 'id' => self::REASON_DIDNT_WORK,
1958
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
1959
+ 'input_type' => '',
1960
+ 'input_placeholder' => ''
1961
+ ),
1962
+ $reason_dont_share_info,
1963
+ $reason_found_better_plugin
1964
+ ),
1965
+ 'short-term' => array(
1966
+ array(
1967
+ 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
1968
+ 'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
1969
+ 'input_type' => '',
1970
+ 'input_placeholder' => '',
1971
+ 'internal_message' => $contact_support_template
1972
+ ),
1973
+ $reason_found_better_plugin,
1974
+ array(
1975
+ 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
1976
+ 'text' => sprintf( $this->get_text_inline( "The %s is great, but I need specific feature that you don't support", 'reason-great-but-need-specific-feature' ), $module_type ),
1977
+ 'input_type' => 'textarea',
1978
+ 'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
1979
+ ),
1980
+ array(
1981
+ 'id' => self::REASON_NOT_WORKING,
1982
+ 'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
1983
+ 'input_type' => 'textarea',
1984
+ 'input_placeholder' => $this->get_text_inline( "Kindly share what didn't work so we can fix it for future users...", 'placeholder-share-what-didnt-work' )
1985
+ ),
1986
+ array(
1987
+ 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
1988
+ 'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
1989
+ 'input_type' => 'textarea',
1990
+ 'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
1991
+ ),
1992
+ array(
1993
+ 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
1994
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
1995
+ 'input_type' => 'textarea',
1996
+ 'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
1997
+ )
1998
+ )
1999
+ );
2000
+
2001
+ // Randomize the reasons for the current user type.
2002
+ shuffle( $uninstall_reasons[ $user_type ] );
2003
+
2004
+ // Keep the following reasons as the last items in the list.
2005
+ $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
2006
+ $uninstall_reasons[ $user_type ][] = $reason_other;
2007
+
2008
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
2009
+
2010
+ return $uninstall_reasons[ $user_type ];
2011
+ }
2012
+
2013
+ /**
2014
+ * Called after the user has submitted his reason for deactivating the plugin.
2015
+ *
2016
+ * @author Leo Fajardo (@leorw)
2017
+ * @since 1.1.2
2018
+ */
2019
+ function _submit_uninstall_reason_action() {
2020
+ $this->_logger->entrance();
2021
+
2022
+ $this->check_ajax_referer( 'submit_uninstall_reason' );
2023
+
2024
+ $reason_id = fs_request_get( 'reason_id' );
2025
+
2026
+ // Check if the given reason ID is an unsigned integer.
2027
+ if ( ! ctype_digit( $reason_id ) ) {
2028
+ exit;
2029
+ }
2030
+
2031
+ $reason_info = trim( fs_request_get( 'reason_info', '' ) );
2032
+ if ( ! empty( $reason_info ) ) {
2033
+ $reason_info = substr( $reason_info, 0, 128 );
2034
+ }
2035
+
2036
+ $reason = (object) array(
2037
+ 'id' => $reason_id,
2038
+ 'info' => $reason_info,
2039
+ 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
2040
+ );
2041
+
2042
+ $this->_storage->store( 'uninstall_reason', $reason );
2043
+
2044
+ /**
2045
+ * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
2046
+ * not support uninstall hook.
2047
+ *
2048
+ * @author Leo Fajardo (@leorw)
2049
+ * @since 1.2.2
2050
+ */
2051
+ if ( $this->is_theme() ) {
2052
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
2053
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2054
+ }
2055
+
2056
+ $this->_uninstall_plugin_event( false );
2057
+ $this->remove_sdk_reference();
2058
+ }
2059
+
2060
+ // Print '1' for successful operation.
2061
+ echo 1;
2062
+ exit;
2063
+ }
2064
+
2065
+ /**
2066
+ * @author Leo Fajardo (@leorw)
2067
+ * @since 2.0.2
2068
+ */
2069
+ function _delete_theme_update_data_action() {
2070
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2071
+ }
2072
+
2073
+ #endregion
2074
+
2075
+ #----------------------------------------------------------------------------------
2076
+ #region Instance
2077
+ #----------------------------------------------------------------------------------
2078
+
2079
+ /**
2080
+ * Main singleton instance.
2081
+ *
2082
+ * @author Vova Feldman (@svovaf)
2083
+ * @since 1.0.0
2084
+ *
2085
+ * @param number $module_id
2086
+ * @param string|bool $slug
2087
+ * @param bool $is_init Is initiation sequence.
2088
+ *
2089
+ * @return Freemius|false
2090
+ */
2091
+ static function instance( $module_id, $slug = false, $is_init = false ) {
2092
+ if ( empty( $module_id ) ) {
2093
+ return false;
2094
+ }
2095
+
2096
+ /**
2097
+ * Load the essential static data prior to initiating FS_Plugin_Manager since there's an essential MS network migration logic that needs to be executed prior to the initiation.
2098
+ */
2099
+ self::_load_required_static();
2100
+
2101
+ if ( ! is_numeric( $module_id ) ) {
2102
+ if ( ! $is_init && true === $slug ) {
2103
+ $is_init = true;
2104
+ }
2105
+
2106
+ $slug = $module_id;
2107
+
2108
+ $module = FS_Plugin_Manager::instance( $slug )->get();
2109
+
2110
+ if ( is_object( $module ) ) {
2111
+ $module_id = $module->id;
2112
+ }
2113
+ }
2114
+
2115
+ $key = 'm_' . $module_id;
2116
+
2117
+ if ( ! isset( self::$_instances[ $key ] ) ) {
2118
+ self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
2119
+ }
2120
+
2121
+ return self::$_instances[ $key ];
2122
+ }
2123
+
2124
+ /**
2125
+ * @author Vova Feldman (@svovaf)
2126
+ * @since 1.0.6
2127
+ *
2128
+ * @param number $addon_id
2129
+ *
2130
+ * @return bool
2131
+ */
2132
+ private static function has_instance( $addon_id ) {
2133
+ return isset( self::$_instances[ 'm_' . $addon_id ] );
2134
+ }
2135
+
2136
+ /**
2137
+ * @author Leo Fajardo (@leorw)
2138
+ * @since 1.2.2
2139
+ *
2140
+ * @param string|number $id_or_slug
2141
+ *
2142
+ * @return number|false
2143
+ */
2144
+ private static function get_module_id( $id_or_slug ) {
2145
+ if ( is_numeric( $id_or_slug ) ) {
2146
+ return $id_or_slug;
2147
+ }
2148
+
2149
+ foreach ( self::$_instances as $instance ) {
2150
+ if ( $instance->is_plugin() && ( $id_or_slug === $instance->get_slug() ) ) {
2151
+ return $instance->get_id();
2152
+ }
2153
+ }
2154
+
2155
+ return false;
2156
+ }
2157
+
2158
+ /**
2159
+ * @author Vova Feldman (@svovaf)
2160
+ * @since 1.0.6
2161
+ *
2162
+ * @param number $id
2163
+ *
2164
+ * @return false|Freemius
2165
+ */
2166
+ static function get_instance_by_id( $id ) {
2167
+ return isset ( self::$_instances[ 'm_' . $id ] ) ?
2168
+ self::$_instances[ 'm_' . $id ] :
2169
+ false;
2170
+ }
2171
+
2172
+ /**
2173
+ *
2174
+ * @author Vova Feldman (@svovaf)
2175
+ * @since 1.0.1
2176
+ *
2177
+ * @param $plugin_file
2178
+ *
2179
+ * @return false|Freemius
2180
+ */
2181
+ static function get_instance_by_file( $plugin_file ) {
2182
+ $slug = self::find_slug_by_basename( $plugin_file );
2183
+
2184
+ return ( false !== $slug ) ?
2185
+ self::instance( self::get_module_id( $slug ) ) :
2186
+ false;
2187
+ }
2188
+
2189
+ /**
2190
+ * @author Vova Feldman (@svovaf)
2191
+ * @since 1.0.6
2192
+ *
2193
+ * @return false|Freemius
2194
+ */
2195
+ function get_parent_instance() {
2196
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2197
+ }
2198
+
2199
+ /**
2200
+ * @author Vova Feldman (@svovaf)
2201
+ * @since 1.0.6
2202
+ *
2203
+ * @param string|number $id_or_slug
2204
+ *
2205
+ * @return false|Freemius
2206
+ */
2207
+ function get_addon_instance( $id_or_slug ) {
2208
+ $addon_id = self::get_module_id( $id_or_slug );
2209
+
2210
+ return self::instance( $addon_id );
2211
+ }
2212
+
2213
+ #endregion ------------------------------------------------------------------
2214
+
2215
+ /**
2216
+ * @author Vova Feldman (@svovaf)
2217
+ * @since 1.0.6
2218
+ *
2219
+ * @return bool
2220
+ */
2221
+ function is_parent_plugin_installed() {
2222
+ $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
2223
+
2224
+ if ( $is_active ) {
2225
+ return true;
2226
+ }
2227
+
2228
+ /**
2229
+ * Parent module might be a theme. If that's the case, the add-on's FS
2230
+ * instance will be loaded prior to the theme's FS instance, therefore,
2231
+ * we need to check if it's active with a "look ahead".
2232
+ *
2233
+ * @author Vova Feldman
2234
+ * @since 1.2.2.3
2235
+ */
2236
+ global $fs_active_plugins;
2237
+ if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
2238
+ $active_theme = wp_get_theme();
2239
+
2240
+ foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
2241
+ if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
2242
+ if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
2243
+ // Parent module is a theme and it's currently active.
2244
+ return true;
2245
+ }
2246
+ }
2247
+ }
2248
+ }
2249
+
2250
+ return false;
2251
+ }
2252
+
2253
+ /**
2254
+ * Check if add-on parent plugin in activation mode.
2255
+ *
2256
+ * @author Vova Feldman (@svovaf)
2257
+ * @since 1.0.7
2258
+ *
2259
+ * @return bool
2260
+ */
2261
+ function is_parent_in_activation() {
2262
+ $parent_fs = $this->get_parent_instance();
2263
+ if ( ! is_object( $parent_fs ) ) {
2264
+ return false;
2265
+ }
2266
+
2267
+ return ( $parent_fs->is_activation_mode() );
2268
+ }
2269
+
2270
+ /**
2271
+ * Is plugin in activation mode.
2272
+ *
2273
+ * @author Vova Feldman (@svovaf)
2274
+ * @since 1.0.7
2275
+ *
2276
+ * @param bool $and_on
2277
+ *
2278
+ * @return bool
2279
+ */
2280
+ function is_activation_mode( $and_on = true ) {
2281
+ return fs_is_network_admin() ?
2282
+ $this->is_network_activation_mode( $and_on ) :
2283
+ $this->is_site_activation_mode( $and_on );
2284
+ }
2285
+
2286
+ /**
2287
+ * Is plugin in activation mode.
2288
+ *
2289
+ * @author Vova Feldman (@svovaf)
2290
+ * @since 1.0.7
2291
+ *
2292
+ * @param bool $and_on
2293
+ *
2294
+ * @return bool
2295
+ */
2296
+ function is_site_activation_mode( $and_on = true ) {
2297
+ return (
2298
+ ( $this->is_on() || ! $and_on ) &&
2299
+ ( ! $this->is_registered() ||
2300
+ ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
2301
+ ( ! $this->is_enable_anonymous() ||
2302
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
2303
+ );
2304
+ }
2305
+
2306
+ /**
2307
+ * Checks if the SDK in network activation mode.
2308
+ *
2309
+ * @author Leo Fajardo (@leorw)
2310
+ * @since 2.0.0
2311
+ *
2312
+ * @param bool $and_on
2313
+ *
2314
+ * @return bool
2315
+ */
2316
+ private function is_network_activation_mode( $and_on = true ) {
2317
+ if ( ! $this->_is_network_active ) {
2318
+ // Not network activated.
2319
+ return false;
2320
+ }
2321
+
2322
+ if ( $this->is_network_upgrade_mode() ) {
2323
+ // Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
2324
+ return true;
2325
+ }
2326
+
2327
+ if ( ! $this->is_site_activation_mode( $and_on ) ) {
2328
+ // Whether the context is single site or the network, if the plugin is no longer in activation mode then it is not in network activation mode as well.
2329
+ return false;
2330
+ }
2331
+
2332
+ if ( $this->is_network_delegated_connection() ) {
2333
+ // Super-admin delegated the connection to the site admins -> not activation mode.
2334
+ return false;
2335
+ }
2336
+
2337
+ if ( $this->is_network_anonymous() ) {
2338
+ // Super-admin skipped the connection network wide -> not activation mode.
2339
+ return false;
2340
+ }
2341
+
2342
+ if ( $this->is_network_registered() ) {
2343
+ // Super-admin connected at least one site -> not activation mode.
2344
+ return false;
2345
+ }
2346
+
2347
+ return true;
2348
+ }
2349
+
2350
+ /**
2351
+ * Check if current page is the opt-in/pending-activation page.
2352
+ *
2353
+ * @author Vova Feldman (@svovaf)
2354
+ * @since 1.2.1.7
2355
+ *
2356
+ * @return bool
2357
+ */
2358
+ function is_activation_page() {
2359
+ if ( $this->_menu->is_main_settings_page() ) {
2360
+ return true;
2361
+ }
2362
+
2363
+ if ( ! $this->is_activation_mode() ) {
2364
+ return false;
2365
+ }
2366
+
2367
+ // Check if current page is matching the activation page.
2368
+ return $this->is_matching_url( $this->get_activation_url() );
2369
+ }
2370
+
2371
+ /**
2372
+ * Check if URL path's are matching and that all querystring
2373
+ * arguments of the $sub_url exist in the $url with the same values.
2374
+ *
2375
+ * WARNING:
2376
+ * 1. This method doesn't check if the sub/domain are matching.
2377
+ * 2. Ignore case sensitivity.
2378
+ *
2379
+ * @author Vova Feldman (@svovaf)
2380
+ * @since 1.2.1.7
2381
+ *
2382
+ * @param string $sub_url
2383
+ * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
2384
+ *
2385
+ * @return bool
2386
+ */
2387
+ private function is_matching_url( $sub_url, $url = '' ) {
2388
+ if ( empty( $url ) ) {
2389
+ $url = $_SERVER['REQUEST_URI'];
2390
+ }
2391
+
2392
+ $url = strtolower( $url );
2393
+ $sub_url = strtolower( $sub_url );
2394
+
2395
+ if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
2396
+ // Different path - DO NOT OVERRIDE PAGE.
2397
+ return false;
2398
+ }
2399
+
2400
+ $url_params = array();
2401
+ parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
2402
+
2403
+ $sub_url_params = array();
2404
+ parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
2405
+
2406
+ foreach ( $sub_url_params as $key => $val ) {
2407
+ if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
2408
+ // Not matching query string - DO NOT OVERRIDE PAGE.
2409
+ return false;
2410
+ }
2411
+ }
2412
+
2413
+ return true;
2414
+ }
2415
+
2416
+ /**
2417
+ * Get the basenames of all active plugins for specific blog. Including network activated plugins.
2418
+ *
2419
+ * @author Vova Feldman (@svovaf)
2420
+ * @since 2.0.0
2421
+ *
2422
+ * @param int $blog_id
2423
+ *
2424
+ * @return string[]
2425
+ */
2426
+ private static function get_active_plugins_basenames( $blog_id = 0 ) {
2427
+ if ( is_multisite() && $blog_id > 0 ) {
2428
+ $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
2429
+ } else {
2430
+ $active_basenames = get_option( 'active_plugins' );
2431
+ }
2432
+
2433
+ if ( is_multisite() ) {
2434
+ $network_active_basenames = get_site_option( 'active_sitewide_plugins' );
2435
+
2436
+ if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
2437
+ $active_basenames = array_merge( $active_basenames, $network_active_basenames );
2438
+ }
2439
+ }
2440
+
2441
+ return $active_basenames;
2442
+ }
2443
+
2444
+ /**
2445
+ * Get collection of all active plugins. Including network activated plugins.
2446
+ *
2447
+ * @author Vova Feldman (@svovaf)
2448
+ * @since 1.0.9
2449
+ *
2450
+ * @param int $blog_id Since 2.0.0
2451
+ *
2452
+ * @return array[string]array
2453
+ */
2454
+ private static function get_active_plugins( $blog_id = 0 ) {
2455
+ self::require_plugin_essentials();
2456
+
2457
+ $active_plugin = array();
2458
+ $all_plugins = get_plugins();
2459
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
2460
+
2461
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
2462
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
2463
+ }
2464
+
2465
+ return $active_plugin;
2466
+ }
2467
+
2468
+ /**
2469
+ * Get collection of all site active plugins for a specified blog.
2470
+ *
2471
+ * @author Vova Feldman (@svovaf)
2472
+ * @since 2.0.0
2473
+ *
2474
+ * @param int $blog_id
2475
+ *
2476
+ * @return array[string]array
2477
+ */
2478
+ private static function get_site_active_plugins( $blog_id = 0 ) {
2479
+ $active_basenames = ( is_multisite() && $blog_id > 0 ) ?
2480
+ get_blog_option( $blog_id, 'active_plugins' ) :
2481
+ get_option( 'active_plugins' );
2482
+
2483
+ $active = array();
2484
+ foreach ( $active_basenames as $basename ) {
2485
+ $active[ $basename ] = array(
2486
+ 'is_active' => true,
2487
+ 'Version' => '1.0', // Dummy version.
2488
+ 'slug' => self::get_plugin_slug( $basename ),
2489
+ );
2490
+ }
2491
+
2492
+ return $active;
2493
+ }
2494
+
2495
+ /**
2496
+ * Get collection of all plugins with their activation status for a specified blog.
2497
+ *
2498
+ * @author Vova Feldman (@svovaf)
2499
+ * @since 1.1.8
2500
+ *
2501
+ * @param int $blog_id Since 2.0.0
2502
+ *
2503
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
2504
+ */
2505
+ private static function get_all_plugins( $blog_id = 0 ) {
2506
+ self::require_plugin_essentials();
2507
+
2508
+ $all_plugins = get_plugins();
2509
+
2510
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
2511
+
2512
+ foreach ( $all_plugins as $basename => &$data ) {
2513
+ // By default set to inactive (next foreach update the active plugins).
2514
+ $data['is_active'] = false;
2515
+ // Enrich with plugin slug.
2516
+ $data['slug'] = self::get_plugin_slug( $basename );
2517
+ }
2518
+
2519
+ // Flag active plugins.
2520
+ foreach ( $active_plugins_basenames as $basename ) {
2521
+ if ( isset( $all_plugins[ $basename ] ) ) {
2522
+ $all_plugins[ $basename ]['is_active'] = true;
2523
+ }
2524
+ }
2525
+
2526
+ return $all_plugins;
2527
+ }
2528
+
2529
+ /**
2530
+ * Get collection of all plugins and if they are network level activated.
2531
+ *
2532
+ * @author Vova Feldman (@svovaf)
2533
+ * @since 2.0.0
2534
+ *
2535
+ * @return array Key is the plugin basename and the value is an array of the plugin data.
2536
+ */
2537
+ private static function get_network_plugins() {
2538
+ self::require_plugin_essentials();
2539
+
2540
+ $all_plugins = get_plugins();
2541
+
2542
+ $network_active_basenames = is_multisite() ?
2543
+ get_site_option( 'active_sitewide_plugins' ) :
2544
+ array();
2545
+
2546
+ foreach ( $all_plugins as $basename => &$data ) {
2547
+ // By default set to inactive (next foreach update the active plugins).
2548
+ $data['is_active'] = false;
2549
+ // Enrich with plugin slug.
2550
+ $data['slug'] = self::get_plugin_slug( $basename );
2551
+ }
2552
+
2553
+ // Flag active plugins.
2554
+ foreach ( $network_active_basenames as $basename ) {
2555
+ if ( isset( $all_plugins[ $basename ] ) ) {
2556
+ $all_plugins[ $basename ]['is_active'] = true;
2557
+ }
2558
+ }
2559
+
2560
+ return $all_plugins;
2561
+ }
2562
+
2563
+ /**
2564
+ * Cached result of get_site_transient( 'update_plugins' )
2565
+ *
2566
+ * @author Vova Feldman (@svovaf)
2567
+ * @since 1.1.8
2568
+ *
2569
+ * @var object
2570
+ */
2571
+ private static $_plugins_info;
2572
+
2573
+ /**
2574
+ * Helper function to get specified plugin's slug.
2575
+ *
2576
+ * @author Vova Feldman (@svovaf)
2577
+ * @since 1.1.8
2578
+ *
2579
+ * @param $basename
2580
+ *
2581
+ * @return string
2582
+ */
2583
+ private static function get_plugin_slug( $basename ) {
2584
+ if ( ! isset( self::$_plugins_info ) ) {
2585
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
2586
+ }
2587
+
2588
+ $slug = '';
2589
+
2590
+ if ( is_object( self::$_plugins_info ) ) {
2591
+ if ( isset( self::$_plugins_info->no_update ) &&
2592
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
2593
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
2594
+ ) {
2595
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
2596
+ } else if ( isset( self::$_plugins_info->response ) &&
2597
+ isset( self::$_plugins_info->response[ $basename ] ) &&
2598
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
2599
+ ) {
2600
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
2601
+ }
2602
+ }
2603
+
2604
+ if ( empty( $slug ) ) {
2605
+ // Try to find slug from FS data.
2606
+ $slug = self::find_slug_by_basename( $basename );
2607
+ }
2608
+
2609
+ if ( empty( $slug ) ) {
2610
+ // Fallback to plugin's folder name.
2611
+ $slug = dirname( $basename );
2612
+ }
2613
+
2614
+ return $slug;
2615
+ }
2616
+
2617
+ private static $_statics_loaded = false;
2618
+
2619
+ /**
2620
+ * Load static resources.
2621
+ *
2622
+ * @author Vova Feldman (@svovaf)
2623
+ * @since 1.0.1
2624
+ */
2625
+ private static function _load_required_static() {
2626
+ if ( self::$_statics_loaded ) {
2627
+ return;
2628
+ }
2629
+
2630
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
2631
+
2632
+ self::$_static_logger->entrance();
2633
+
2634
+ self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
2635
+
2636
+ if ( is_multisite() ) {
2637
+ /**
2638
+ * If the id_slug_type_path_map exists on the site level but doesn't exist on the
2639
+ * network level storage, it means that we need to process the storage with migration.
2640
+ *
2641
+ * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, id_slug_type_path_map will be already set in the network level storage.
2642
+ *
2643
+ * @author Vova Feldman (@svovaf)
2644
+ * @since 2.0.0
2645
+ */
2646
+ if ( null === self::$_accounts->get_option( 'id_slug_type_path_map', null, true ) &&
2647
+ null !== self::$_accounts->get_option( 'id_slug_type_path_map', null, false )
2648
+ ) {
2649
+ self::migrate_accounts_to_network();
2650
+
2651
+ // Migrate API options from site level to network level.
2652
+ $api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
2653
+ $api_network_options->migrate_to_network();
2654
+
2655
+ // Migrate API cache to network level storage.
2656
+ FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
2657
+ }
2658
+ }
2659
+
2660
+ self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
2661
+
2662
+ if ( ! WP_FS__DEMO_MODE ) {
2663
+ add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
2664
+ 'Freemius',
2665
+ '_add_debug_section'
2666
+ ) );
2667
+ }
2668
+
2669
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
2670
+
2671
+ self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
2672
+
2673
+ self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
2674
+
2675
+ self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
2676
+
2677
+ if ( 0 == did_action( 'plugins_loaded' ) ) {
2678
+ add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
2679
+ }
2680
+
2681
+ add_action( 'admin_footer', array( 'Freemius', '_enrich_ajax_url' ) );
2682
+
2683
+ self::$_statics_loaded = true;
2684
+ }
2685
+
2686
+ #----------------------------------------------------------------------------------
2687
+ #region Localization
2688
+ #----------------------------------------------------------------------------------
2689
+
2690
+ /**
2691
+ * Load framework's text domain.
2692
+ *
2693
+ * @author Vova Feldman (@svovaf)
2694
+ * @since 1.2.1
2695
+ */
2696
+ static function _load_textdomain() {
2697
+ if ( ! is_admin() ) {
2698
+ return;
2699
+ }
2700
+
2701
+ global $fs_active_plugins;
2702
+
2703
+ // Works both for plugins and themes.
2704
+ load_plugin_textdomain(
2705
+ 'freemius',
2706
+ false,
2707
+ $fs_active_plugins->newest->sdk_path . '/languages/'
2708
+ );
2709
+ }
2710
+
2711
+ #endregion
2712
+
2713
+ #----------------------------------------------------------------------------------
2714
+ #region Debugging
2715
+ #----------------------------------------------------------------------------------
2716
+
2717
+ /**
2718
+ * @author Vova Feldman (@svovaf)
2719
+ * @since 1.0.8
2720
+ */
2721
+ static function _add_debug_section() {
2722
+ if ( ! is_super_admin() ) {
2723
+ // Add debug page only for super-admins.
2724
+ return;
2725
+ }
2726
+
2727
+ self::$_static_logger->entrance();
2728
+
2729
+ $title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
2730
+
2731
+ if ( WP_FS__DEV_MODE ) {
2732
+ // Add top-level debug menu item.
2733
+ $hook = FS_Admin_Menu_Manager::add_page(
2734
+ $title,
2735
+ $title,
2736
+ 'manage_options',
2737
+ 'freemius',
2738
+ array( 'Freemius', '_debug_page_render' )
2739
+ );
2740
+ } else {
2741
+ // Add hidden debug page.
2742
+ $hook = FS_Admin_Menu_Manager::add_subpage(
2743
+ null,
2744
+ $title,
2745
+ $title,
2746
+ 'manage_options',
2747
+ 'freemius',
2748
+ array( 'Freemius', '_debug_page_render' )
2749
+ );
2750
+ }
2751
+
2752
+ if ( ! empty( $hook ) ) {
2753
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
2754
+ }
2755
+ }
2756
+
2757
+ /**
2758
+ * @author Vova Feldman (@svovaf)
2759
+ * @since 1.1.7.3
2760
+ */
2761
+ static function _toggle_debug_mode() {
2762
+ $is_on = fs_request_get( 'is_on', false, 'post' );
2763
+
2764
+ if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
2765
+ update_option( 'fs_debug_mode', $is_on );
2766
+
2767
+ // Turn on/off storage logging.
2768
+ FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
2769
+ }
2770
+
2771
+ exit;
2772
+ }
2773
+
2774
+ /**
2775
+ * @author Vova Feldman (@svovaf)
2776
+ * @since 1.2.1.6
2777
+ */
2778
+ static function _get_debug_log() {
2779
+ $logs = FS_Logger::load_db_logs(
2780
+ fs_request_get( 'filters', false, 'post' ),
2781
+ ! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
2782
+ ! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
2783
+ );
2784
+
2785
+ self::shoot_ajax_success( $logs );
2786
+ }
2787
+
2788
+ /**
2789
+ * @author Vova Feldman (@svovaf)
2790
+ * @since 1.2.1.7
2791
+ */
2792
+ static function _get_db_option() {
2793
+ $option_name = fs_request_get( 'option_name' );
2794
+
2795
+ $value = get_option( $option_name );
2796
+
2797
+ $result = array(
2798
+ 'name' => $option_name,
2799
+ );
2800
+
2801
+ if ( false !== $value ) {
2802
+ if ( ! is_string( $value ) ) {
2803
+ $value = json_encode( $value );
2804
+ }
2805
+
2806
+ $result['value'] = $value;
2807
+ }
2808
+
2809
+ self::shoot_ajax_success( $result );
2810
+ }
2811
+
2812
+ /**
2813
+ * @author Vova Feldman (@svovaf)
2814
+ * @since 1.2.1.7
2815
+ */
2816
+ static function _set_db_option() {
2817
+ $option_name = fs_request_get( 'option_name' );
2818
+ $option_value = fs_request_get( 'option_value' );
2819
+
2820
+ if ( ! empty( $option_value ) ) {
2821
+ update_option( $option_name, $option_value );
2822
+ }
2823
+
2824
+ self::shoot_ajax_success();
2825
+ }
2826
+
2827
+ /**
2828
+ * @author Vova Feldman (@svovaf)
2829
+ * @since 1.0.8
2830
+ */
2831
+ static function _debug_page_actions() {
2832
+ self::_clean_admin_content_section();
2833
+
2834
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
2835
+ check_admin_referer( 'restart_freemius' );
2836
+
2837
+ if ( ! is_multisite() ) {
2838
+ // Clear accounts data.
2839
+ self::$_accounts->clear( null, true );
2840
+ } else {
2841
+ $sites = self::get_sites();
2842
+ foreach ( $sites as $site ) {
2843
+ $blog_id = self::get_site_blog_id( $site );
2844
+ self::$_accounts->clear( $blog_id, true );
2845
+ }
2846
+
2847
+ // Clear network level storage.
2848
+ self::$_accounts->clear( true, true );
2849
+ }
2850
+
2851
+ // Clear SDK reference cache.
2852
+ delete_option( 'fs_active_plugins' );
2853
+ } else if ( fs_request_is_action( 'clear_updates_data' ) ) {
2854
+ check_admin_referer( 'clear_updates_data' );
2855
+
2856
+ if ( ! is_multisite() ) {
2857
+ set_site_transient( 'update_plugins', null );
2858
+ set_site_transient( 'update_themes', null );
2859
+ } else {
2860
+ $current_blog_id = get_current_blog_id();
2861
+
2862
+ $sites = self::get_sites();
2863
+ foreach ( $sites as $site ) {
2864
+ switch_to_blog( self::get_site_blog_id( $site ) );
2865
+
2866
+ set_site_transient( 'update_plugins', null );
2867
+ set_site_transient( 'update_themes', null );
2868
+ }
2869
+
2870
+ switch_to_blog( $current_blog_id );
2871
+ }
2872
+ } else if ( fs_request_is_action( 'simulate_trial' ) ) {
2873
+ check_admin_referer( 'simulate_trial' );
2874
+
2875
+ $fs = freemius( fs_request_get( 'module_id' ) );
2876
+
2877
+ // Update SDK install to at least 24 hours before.
2878
+ $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
2879
+ // Unset the trial shown timestamp.
2880
+ unset( $fs->_storage->trial_promotion_shown );
2881
+ } else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
2882
+ check_admin_referer( 'simulate_network_upgrade' );
2883
+
2884
+ $fs = freemius( fs_request_get( 'module_id' ) );
2885
+
2886
+ self::set_network_upgrade_mode( $fs->_storage );
2887
+ } else if ( fs_request_is_action( 'delete_install' ) ) {
2888
+ check_admin_referer( 'delete_install' );
2889
+
2890
+ self::_delete_site_by_slug(
2891
+ fs_request_get( 'slug' ),
2892
+ fs_request_get( 'module_type' ),
2893
+ true,
2894
+ fs_request_get( 'blog_id', null )
2895
+ );
2896
+ } else if ( fs_request_is_action( 'delete_user' ) ) {
2897
+ check_admin_referer( 'delete_user' );
2898
+
2899
+ self::delete_user( fs_request_get( 'user_id' ) );
2900
+ } else if ( fs_request_is_action( 'download_logs' ) ) {
2901
+ check_admin_referer( 'download_logs' );
2902
+
2903
+ $download_url = FS_Logger::download_db_logs(
2904
+ fs_request_get( 'filters', false, 'post' )
2905
+ );
2906
+
2907
+ if ( false === $download_url ) {
2908
+ wp_die( 'Oops... there was an error while generating the logs download file. Please try again and if it doesn\'t work contact support@freemius.com.' );
2909
+ }
2910
+
2911
+ fs_redirect( $download_url );
2912
+ }
2913
+ }
2914
+
2915
+ /**
2916
+ * @author Vova Feldman (@svovaf)
2917
+ * @since 1.0.8
2918
+ */
2919
+ static function _debug_page_render() {
2920
+ self::$_static_logger->entrance();
2921
+
2922
+ if ( ! is_multisite() ) {
2923
+ $all_plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
2924
+ $all_themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME );
2925
+ } else {
2926
+ $sites = self::get_sites();
2927
+
2928
+ $all_plugins_installs = array();
2929
+ $all_themes_installs = array();
2930
+
2931
+ foreach ( $sites as $site ) {
2932
+ $blog_id = self::get_site_blog_id( $site );
2933
+
2934
+ $plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
2935
+
2936
+ foreach ( $plugins_installs as $slug => $install ) {
2937
+ if ( ! isset( $all_plugins_installs[ $slug ] ) ) {
2938
+ $all_plugins_installs[ $slug ] = array();
2939
+ }
2940
+
2941
+ $install->blog_id = $blog_id;
2942
+
2943
+ $all_plugins_installs[ $slug ][] = $install;
2944
+ }
2945
+
2946
+ $themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id );
2947
+
2948
+ foreach ( $themes_installs as $slug => $install ) {
2949
+ if ( ! isset( $all_themes_installs[ $slug ] ) ) {
2950
+ $all_themes_installs[ $slug ] = array();
2951
+ }
2952
+
2953
+ $install->blog_id = $blog_id;
2954
+
2955
+ $all_themes_installs[ $slug ][] = $install;
2956
+ }
2957
+ }
2958
+ }
2959
+
2960
+ $licenses_by_module_type = self::get_all_licenses_by_module_type();
2961
+
2962
+ $vars = array(
2963
+ 'plugin_sites' => $all_plugins_installs,
2964
+ 'theme_sites' => $all_themes_installs,
2965
+ 'users' => self::get_all_users(),
2966
+ 'addons' => self::get_all_addons(),
2967
+ 'account_addons' => self::get_all_account_addons(),
2968
+ 'plugin_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_PLUGIN ],
2969
+ 'theme_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_THEME ]
2970
+ );
2971
+
2972
+ fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
2973
+ fs_require_once_template( 'debug.php', $vars );
2974
+ }
2975
+
2976
+ #endregion
2977
+
2978
+ #----------------------------------------------------------------------------------
2979
+ #region Connectivity Issues
2980
+ #----------------------------------------------------------------------------------
2981
+
2982
+ /**
2983
+ * Check if Freemius should be turned on for the current plugin install.
2984
+ *
2985
+ * Note:
2986
+ * $this->_is_on is updated in has_api_connectivity()
2987
+ *
2988
+ * @author Vova Feldman (@svovaf)
2989
+ * @since 1.0.9
2990
+ *
2991
+ * @return bool
2992
+ */
2993
+ function is_on() {
2994
+ self::$_static_logger->entrance();
2995
+
2996
+ if ( isset( $this->_is_on ) ) {
2997
+ return $this->_is_on;
2998
+ }
2999
+
3000
+ // If already installed or pending then sure it's on :)
3001
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
3002
+ $this->_is_on = true;
3003
+
3004
+ return true;
3005
+ }
3006
+
3007
+ return false;
3008
+ }
3009
+
3010
+ /**
3011
+ * @author Vova Feldman (@svovaf)
3012
+ * @since 1.1.7.3
3013
+ *
3014
+ * @param bool $flush_if_no_connectivity
3015
+ *
3016
+ * @return bool
3017
+ */
3018
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
3019
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
3020
+ // Connectivity test was never executed, or cache was cleared.
3021
+ return true;
3022
+ }
3023
+
3024
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
3025
+ if ( WP_FS__IS_HTTP_REQUEST ) {
3026
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
3027
+ // Domain changed.
3028
+ return true;
3029
+ }
3030
+
3031
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
3032
+ // Server IP changed.
3033
+ return true;
3034
+ }
3035
+ }
3036
+ }
3037
+
3038
+ if ( $this->_storage->connectivity_test['is_connected'] &&
3039
+ $this->_storage->connectivity_test['is_active']
3040
+ ) {
3041
+ // API connected and Freemius is active - no need to run connectivity check.
3042
+ return false;
3043
+ }
3044
+
3045
+ if ( $flush_if_no_connectivity ) {
3046
+ /**
3047
+ * If explicitly asked to flush when no connectivity - do it only
3048
+ * if at least 10 sec passed from the last API connectivity test.
3049
+ */
3050
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
3051
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
3052
+ }
3053
+
3054
+ /**
3055
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
3056
+ */
3057
+ $version = $this->get_plugin_version();
3058
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
3059
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
3060
+ return true;
3061
+ }
3062
+
3063
+ return false;
3064
+ }
3065
+
3066
+ /**
3067
+ * @author Vova Feldman (@svovaf)
3068
+ * @since 1.1.7.4
3069
+ *
3070
+ * @param int|null $blog_id Since 2.0.0.
3071
+ * @param bool $is_gdpr_test Since 2.0.2. Perform only the GDPR test.
3072
+ *
3073
+ * @return object|false
3074
+ */
3075
+ private function ping( $blog_id = null, $is_gdpr_test = false ) {
3076
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
3077
+ return false;
3078
+ }
3079
+
3080
+ $version = $this->get_plugin_version();
3081
+
3082
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
3083
+
3084
+ return $this->get_api_plugin_scope()->ping(
3085
+ $this->get_anonymous_id( $blog_id ),
3086
+ array(
3087
+ 'is_update' => json_encode( $is_update ),
3088
+ 'version' => $version,
3089
+ 'sdk' => $this->version,
3090
+ 'is_admin' => json_encode( is_admin() ),
3091
+ 'is_ajax' => json_encode( self::is_ajax() ),
3092
+ 'is_cron' => json_encode( self::is_cron() ),
3093
+ 'is_gdpr_test' => $is_gdpr_test,
3094
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
3095
+ )
3096
+ );
3097
+ }
3098
+
3099
+ /**
3100
+ * Check if there's any connectivity issue to Freemius API.
3101
+ *
3102
+ * @author Vova Feldman (@svovaf)
3103
+ * @since 1.0.9
3104
+ *
3105
+ * @param bool $flush_if_no_connectivity
3106
+ *
3107
+ * @return bool
3108
+ */
3109
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
3110
+ $this->_logger->entrance();
3111
+
3112
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
3113
+ return $this->_has_api_connection;
3114
+ }
3115
+
3116
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
3117
+ isset( $this->_storage->connectivity_test ) &&
3118
+ true === $this->_storage->connectivity_test['is_connected']
3119
+ ) {
3120
+ unset( $this->_storage->connectivity_test );
3121
+ }
3122
+
3123
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
3124
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
3125
+ /**
3126
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
3127
+ *
3128
+ * @since 1.2.1.5 If the user running the premium version then ignore the 'is_active' flag and turn Freemius on to enable license key activation.
3129
+ */
3130
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
3131
+ $this->is_premium() ||
3132
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3133
+
3134
+ return $this->_has_api_connection;
3135
+ }
3136
+
3137
+ $pong = $this->ping();
3138
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3139
+
3140
+ if ( ! $is_connected ) {
3141
+ // API failure.
3142
+ $this->_add_connectivity_issue_message( $pong );
3143
+ }
3144
+
3145
+ if ( $is_connected ) {
3146
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3147
+ }
3148
+
3149
+ $this->store_connectivity_info( $pong, $is_connected );
3150
+
3151
+ return $this->_has_api_connection;
3152
+ }
3153
+
3154
+ /**
3155
+ * @author Vova Feldman (@svovaf)
3156
+ * @since 1.1.7.4
3157
+ *
3158
+ * @param object $pong
3159
+ * @param bool $is_connected
3160
+ */
3161
+ private function store_connectivity_info( $pong, $is_connected ) {
3162
+ $this->_logger->entrance();
3163
+
3164
+ $version = $this->get_plugin_version();
3165
+
3166
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
3167
+ $is_active = false;
3168
+ } else {
3169
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
3170
+ }
3171
+
3172
+ $is_active = $this->apply_filters(
3173
+ 'is_on',
3174
+ $is_active,
3175
+ $this->is_plugin_update(),
3176
+ $version
3177
+ );
3178
+
3179
+ $this->_storage->connectivity_test = array(
3180
+ 'is_connected' => $is_connected,
3181
+ 'host' => $_SERVER['HTTP_HOST'],
3182
+ 'server_ip' => WP_FS__REMOTE_ADDR,
3183
+ 'is_active' => $is_active,
3184
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3185
+ // Last version with connectivity attempt.
3186
+ 'version' => $version,
3187
+ );
3188
+
3189
+ $this->_has_api_connection = $is_connected;
3190
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3191
+ }
3192
+
3193
+ /**
3194
+ * Force turning Freemius on.
3195
+ *
3196
+ * @author Vova Feldman (@svovaf)
3197
+ * @since 1.1.8.1
3198
+ *
3199
+ * @return bool TRUE if successfully turned on.
3200
+ */
3201
+ private function turn_on() {
3202
+ $this->_logger->entrance();
3203
+
3204
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
3205
+ return false;
3206
+ }
3207
+
3208
+ $updated_connectivity = $this->_storage->connectivity_test;
3209
+ $updated_connectivity['is_active'] = true;
3210
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
3211
+ $this->_storage->connectivity_test = $updated_connectivity;
3212
+
3213
+ $this->_is_on = true;
3214
+
3215
+ return true;
3216
+ }
3217
+
3218
+ /**
3219
+ * Anonymous and unique site identifier (Hash).
3220
+ *
3221
+ * @author Vova Feldman (@svovaf)
3222
+ * @since 1.1.0
3223
+ *
3224
+ * @param null|int $blog_id Since 2.0.0
3225
+ *
3226
+ * @return string
3227
+ */
3228
+ function get_anonymous_id( $blog_id = null ) {
3229
+ $unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
3230
+
3231
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
3232
+ $key = fs_strip_url_protocol( get_site_url( $blog_id ) );
3233
+
3234
+ $secure_auth = SECURE_AUTH_KEY;
3235
+ if ( empty( $secure_auth ) || false !== strpos( $secure_auth, ' ' ) ) {
3236
+ // Protect against default auth key.
3237
+ $secure_auth = md5( microtime() );
3238
+ }
3239
+
3240
+ /**
3241
+ * Base the unique identifier on the WP secure authentication key. Which
3242
+ * turns the key into a secret anonymous identifier. This will help us
3243
+ * to avoid duplicate installs generation on the backend upon opt-in.
3244
+ *
3245
+ * @author Vova Feldman (@svovaf)
3246
+ * @since 1.2.3
3247
+ */
3248
+ $unique_id = md5( $key . $secure_auth );
3249
+
3250
+ self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
3251
+ }
3252
+
3253
+ $this->_logger->departure( $unique_id );
3254
+
3255
+ return $unique_id;
3256
+ }
3257
+
3258
+ /**
3259
+ * @author Vova Feldman (@svovaf)
3260
+ * @since 1.1.7.4
3261
+ *
3262
+ * @return \WP_User
3263
+ */
3264
+ static function _get_current_wp_user() {
3265
+ self::require_pluggable_essentials();
3266
+ self::wp_cookie_constants();
3267
+
3268
+ return wp_get_current_user();
3269
+ }
3270
+
3271
+ /**
3272
+ * Define cookie constants which are required by Freemius::_get_current_wp_user() since
3273
+ * it uses wp_get_current_user() which needs the cookie constants set. When a plugin
3274
+ * is network activated the cookie constants are only configured after the network
3275
+ * plugins activation, therefore, if we don't define those constants WP will throw
3276
+ * PHP warnings/notices.
3277
+ *
3278
+ * @author Vova Feldman (@svovaf)
3279
+ * @since 2.1.1
3280
+ */
3281
+ private static function wp_cookie_constants() {
3282
+ if ( defined( 'LOGGED_IN_COOKIE' ) &&
3283
+ ( defined( 'AUTH_COOKIE' ) || defined( 'SECURE_AUTH_COOKIE' ) )
3284
+ ) {
3285
+ return;
3286
+ }
3287
+
3288
+ /**
3289
+ * Used to guarantee unique hash cookies
3290
+ *
3291
+ * @since 1.5.0
3292
+ */
3293
+ if ( ! defined( 'COOKIEHASH' ) ) {
3294
+ $siteurl = get_site_option( 'siteurl' );
3295
+ if ( $siteurl ) {
3296
+ define( 'COOKIEHASH', md5( $siteurl ) );
3297
+ } else {
3298
+ define( 'COOKIEHASH', '' );
3299
+ }
3300
+ }
3301
+
3302
+ if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
3303
+ define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
3304
+ }
3305
+
3306
+ /**
3307
+ * @since 2.5.0
3308
+ */
3309
+ if ( ! defined( 'AUTH_COOKIE' ) ) {
3310
+ define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
3311
+ }
3312
+
3313
+ /**
3314
+ * @since 2.6.0
3315
+ */
3316
+ if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) {
3317
+ define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
3318
+ }
3319
+ }
3320
+
3321
+ /**
3322
+ * @author Vova Feldman (@svovaf)
3323
+ * @since 2.1.0
3324
+ *
3325
+ * @return int
3326
+ */
3327
+ static function get_current_wp_user_id() {
3328
+ $wp_user = self::_get_current_wp_user();
3329
+
3330
+ return $wp_user->ID;
3331
+ }
3332
+
3333
+ /**
3334
+ * @author Vova Feldman (@svovaf)
3335
+ * @since 1.2.1.7
3336
+ *
3337
+ * @param string $email
3338
+ *
3339
+ * @return bool
3340
+ */
3341
+ static function is_valid_email( $email ) {
3342
+ if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
3343
+ return false;
3344
+ }
3345
+
3346
+ $parts = explode( '@', $email );
3347
+
3348
+ if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
3349
+ return false;
3350
+ }
3351
+
3352
+ $blacklist = array(
3353
+ 'admin.',
3354
+ 'webmaster.',
3355
+ 'localhost.',
3356
+ 'dev.',
3357
+ 'development.',
3358
+ 'test.',
3359
+ 'stage.',
3360
+ 'staging.',
3361
+ );
3362
+
3363
+ // Make sure domain is not one of the blacklisted.
3364
+ foreach ( $blacklist as $invalid ) {
3365
+ if ( 0 === strpos( $parts[1], $invalid ) ) {
3366
+ return false;
3367
+ }
3368
+ }
3369
+
3370
+ // Get the UTF encoded domain name.
3371
+ $domain = idn_to_ascii( $parts[1] ) . '.';
3372
+
3373
+ return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
3374
+ }
3375
+
3376
+ /**
3377
+ * Generate API connectivity issue message.
3378
+ *
3379
+ * @author Vova Feldman (@svovaf)
3380
+ * @since 1.0.9
3381
+ *
3382
+ * @param mixed $api_result
3383
+ * @param bool $is_first_failure
3384
+ */
3385
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
3386
+ if ( ! $this->is_premium() && $this->_enable_anonymous ) {
3387
+ // Don't add message if it's the free version and can run anonymously.
3388
+ return;
3389
+ }
3390
+
3391
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
3392
+ require_once ABSPATH . 'wp-includes/functions.php';
3393
+ }
3394
+
3395
+ $current_user = self::_get_current_wp_user();
3396
+ // $admin_email = get_option( 'admin_email' );
3397
+ $admin_email = $current_user->user_email;
3398
+
3399
+ // Aliases.
3400
+ $deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
3401
+ $deactivate_plugin_desc = $this->esc_html_inline( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'deactivate-plugin-desc' );
3402
+ $install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
3403
+ $install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
3404
+ $fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
3405
+ $fix_issue_desc = $this->esc_html_inline( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'fix-issue-desc' );
3406
+ /* translators: %s: product title (e.g. "Awesome Plugin" requires an access to...) */
3407
+ $x_requires_access_to_api = $this->esc_html_inline( '%s requires an access to our API.', 'x-requires-access-to-api' );
3408
+ $sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
3409
+ $happy_to_resolve_issue_asap = $this->esc_html_inline( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'happy-to-resolve-issue-asap' );
3410
+
3411
+ $message = false;
3412
+ if ( is_object( $api_result ) &&
3413
+ isset( $api_result->error ) &&
3414
+ isset( $api_result->error->code )
3415
+ ) {
3416
+ switch ( $api_result->error->code ) {
3417
+ case 'curl_missing':
3418
+ $missing_methods = '';
3419
+ if ( is_array( $api_result->missing_methods ) &&
3420
+ ! empty( $api_result->missing_methods )
3421
+ ) {
3422
+ foreach ( $api_result->missing_methods as $m ) {
3423
+ if ( 'curl_version' === $m ) {
3424
+ continue;
3425
+ }
3426
+
3427
+ if ( ! empty( $missing_methods ) ) {
3428
+ $missing_methods .= ', ';
3429
+ }
3430
+
3431
+ $missing_methods .= sprintf( '<code>%s</code>', $m );
3432
+ }
3433
+
3434
+ if ( ! empty( $missing_methods ) ) {
3435
+ $missing_methods = sprintf(
3436
+ '<br><br><b>%s</b> %s',
3437
+ $this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
3438
+ $missing_methods
3439
+ );
3440
+ }
3441
+ }
3442
+
3443
+ $message = sprintf(
3444
+ $x_requires_access_to_api . ' ' .
3445
+ $this->esc_html_inline( 'We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server.', 'curl-missing-message' ) . ' ' .
3446
+ $missing_methods .
3447
+ ' %s',
3448
+ '<b>' . $this->get_plugin_name() . '</b>',
3449
+ sprintf(
3450
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3451
+ sprintf(
3452
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
3453
+ $this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
3454
+ ' - ' . sprintf(
3455
+ $this->get_text_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'curl-missing-no-clue-desc' ),
3456
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3457
+ )
3458
+ ),
3459
+ sprintf(
3460
+ '<b>%s</b> - %s',
3461
+ $sysadmin_title,
3462
+ esc_html( sprintf( $this->get_text_inline( 'Great, please install cURL and enable it in your php.ini file. In addition, search for the \'disable_functions\' directive in your php.ini file and remove any disabled methods starting with \'curl_\'. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the %s and reactivate it back again.', 'curl-missing-sysadmin-desc' ), $this->get_module_label( true ) ) )
3463
+ ),
3464
+ sprintf(
3465
+ '<a href="%s"><b>%s</b></a> - %s',
3466
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
3467
+ $deactivate_plugin_title,
3468
+ $deactivate_plugin_desc
3469
+ )
3470
+ )
3471
+ );
3472
+ break;
3473
+ case 'cloudflare_ddos_protection':
3474
+ $message = sprintf(
3475
+ $x_requires_access_to_api . ' ' .
3476
+ $this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
3477
+ $happy_to_resolve_issue_asap .
3478
+ ' %s',
3479
+ '<b>' . $this->get_plugin_name() . '</b>',
3480
+ sprintf(
3481
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3482
+ sprintf(
3483
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
3484
+ $fix_issue_title,
3485
+ ' - ' . sprintf(
3486
+ $fix_issue_desc,
3487
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3488
+ )
3489
+ ),
3490
+ sprintf(
3491
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
3492
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
3493
+ $install_previous_title,
3494
+ $install_previous_desc
3495
+ ),
3496
+ sprintf(
3497
+ '<a href="%s"><b>%s</b></a> - %s',
3498
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
3499
+ $deactivate_plugin_title,
3500
+ $deactivate_plugin_desc
3501
+ )
3502
+ )
3503
+ );
3504
+ break;
3505
+ case 'squid_cache_block':
3506
+ $message = sprintf(
3507
+ $x_requires_access_to_api . ' ' .
3508
+ $this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
3509
+ ' %s',
3510
+ '<b>' . $this->get_plugin_name() . '</b>',
3511
+ sprintf(
3512
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3513
+ sprintf(
3514
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
3515
+ $this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
3516
+ sprintf(
3517
+ $this->esc_html_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'squid-no-clue-desc' ),
3518
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3519
+ )
3520
+ ),
3521
+ sprintf(
3522
+ '<b>%s</b> - %s',
3523
+ $sysadmin_title,
3524
+ sprintf(
3525
+ $this->esc_html_inline( 'Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again.', 'squid-sysadmin-desc' ),
3526
+ // We use a filter since the plugin might require additional API connectivity.
3527
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
3528
+ 'api.freemius.com',
3529
+ 'wp.freemius.com'
3530
+ ) ) ) . '</b>',
3531
+ $this->_module_type
3532
+ )
3533
+ ),
3534
+ sprintf(
3535
+ '<a href="%s"><b>%s</b></a> - %s',
3536
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
3537
+ $deactivate_plugin_title,
3538
+ $deactivate_plugin_desc
3539
+ )
3540
+ )
3541
+ );
3542
+ break;
3543
+ // default:
3544
+ // $message = $this->get_text_inline( 'connectivity-test-fails-message' );
3545
+ // break;
3546
+ }
3547
+ }
3548
+
3549
+ $message_id = 'failed_connect_api';
3550
+ $type = 'error';
3551
+
3552
+ $connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
3553
+
3554
+ if ( false === $message ) {
3555
+ if ( $is_first_failure ) {
3556
+ // First attempt failed.
3557
+ $message = sprintf(
3558
+ $x_requires_access_to_api . ' ' .
3559
+ $connectivity_test_fails_message . ' ' .
3560
+ $this->esc_html_inline( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'connectivity-test-maybe-temporary' ) . '<br><br>' .
3561
+ '%s',
3562
+ '<b>' . $this->get_plugin_name() . '</b>',
3563
+ sprintf(
3564
+ '<div id="fs_firewall_issue_options">%s %s</div>',
3565
+ sprintf(
3566
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
3567
+ $this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
3568
+ ),
3569
+ sprintf(
3570
+ '<a href="%s" class="button">%s</a>',
3571
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
3572
+ $this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
3573
+ )
3574
+ )
3575
+ );
3576
+
3577
+ $message_id = 'failed_connect_api_first';
3578
+ $type = 'promotion';
3579
+ } else {
3580
+ // Second connectivity attempt failed.
3581
+ $message = sprintf(
3582
+ $x_requires_access_to_api . ' ' .
3583
+ $connectivity_test_fails_message . ' ' .
3584
+ $happy_to_resolve_issue_asap .
3585
+ ' %s',
3586
+ '<b>' . $this->get_plugin_name() . '</b>',
3587
+ sprintf(
3588
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3589
+ sprintf(
3590
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
3591
+ $fix_issue_title,
3592
+ ' - ' . sprintf(
3593
+ $fix_issue_desc,
3594
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3595
+ )
3596
+ ),
3597
+ sprintf(
3598
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
3599
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
3600
+ $install_previous_title,
3601
+ $install_previous_desc
3602
+ ),
3603
+ sprintf(
3604
+ '<a href="%s"><b>%s</b></a> - %s',
3605
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
3606
+ $deactivate_plugin_title,
3607
+ $deactivate_plugin_desc
3608
+ )
3609
+ )
3610
+ );
3611
+ }
3612
+ }
3613
+
3614
+ $this->_admin_notices->add_sticky(
3615
+ $message,
3616
+ $message_id,
3617
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
3618
+ $type
3619
+ );
3620
+ }
3621
+
3622
+ /**
3623
+ * Handle user request to resolve connectivity issue.
3624
+ * This method will send an email to Freemius API technical staff for resolution.
3625
+ * The email will contain server's info and installed plugins (might be caching issue).
3626
+ *
3627
+ * @author Vova Feldman (@svovaf)
3628
+ * @since 1.0.9
3629
+ */
3630
+ function _email_about_firewall_issue() {
3631
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
3632
+
3633
+ $pong = $this->ping();
3634
+
3635
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3636
+
3637
+ if ( $is_connected ) {
3638
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3639
+
3640
+ $this->store_connectivity_info( $pong, $is_connected );
3641
+
3642
+ echo $this->get_after_plugin_activation_redirect_url();
3643
+ exit;
3644
+ }
3645
+
3646
+ $current_user = self::_get_current_wp_user();
3647
+ $admin_email = $current_user->user_email;
3648
+
3649
+ $error_type = fs_request_get( 'error_type', 'general' );
3650
+
3651
+ switch ( $error_type ) {
3652
+ case 'squid':
3653
+ $title = 'Squid ACL Blocking Issue';
3654
+ break;
3655
+ case 'cloudflare':
3656
+ $title = 'CloudFlare Blocking Issue';
3657
+ break;
3658
+ default:
3659
+ $title = 'API Connectivity Issue';
3660
+ break;
3661
+ }
3662
+
3663
+ $custom_email_sections = array();
3664
+
3665
+ // Add 'API Error' custom email section.
3666
+ $custom_email_sections['api_error'] = array(
3667
+ 'title' => 'API Error',
3668
+ 'rows' => array(
3669
+ 'ping' => array(
3670
+ 'API Error',
3671
+ is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
3672
+ ),
3673
+ )
3674
+ );
3675
+
3676
+ // Send email with technical details to resolve API connectivity issues.
3677
+ $this->send_email(
3678
+ 'api@freemius.com', // recipient
3679
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
3680
+ $custom_email_sections,
3681
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
3682
+ );
3683
+
3684
+ $this->_admin_notices->add_sticky(
3685
+ sprintf(
3686
+ $this->get_text_inline( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'fix-request-sent-message' ),
3687
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3688
+ ),
3689
+ 'server_details_sent'
3690
+ );
3691
+
3692
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
3693
+
3694
+ echo "1";
3695
+ exit;
3696
+ }
3697
+
3698
+ /**
3699
+ * Handle connectivity test retry approved by the user.
3700
+ *
3701
+ * @author Vova Feldman (@svovaf)
3702
+ * @since 1.1.7.4
3703
+ */
3704
+ function _retry_connectivity_test() {
3705
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
3706
+
3707
+ $pong = $this->ping();
3708
+
3709
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3710
+
3711
+ if ( $is_connected ) {
3712
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3713
+
3714
+ $this->store_connectivity_info( $pong, $is_connected );
3715
+
3716
+ echo $this->get_after_plugin_activation_redirect_url();
3717
+ } else {
3718
+ // Add connectivity issue message after 2nd failed attempt.
3719
+ $this->_add_connectivity_issue_message( $pong, false );
3720
+
3721
+ echo "1";
3722
+ }
3723
+
3724
+ exit;
3725
+ }
3726
+
3727
+ static function _add_firewall_issues_javascript() {
3728
+ $params = array();
3729
+ fs_require_once_template( 'firewall-issues-js.php', $params );
3730
+ }
3731
+
3732
+ #endregion
3733
+
3734
+ #----------------------------------------------------------------------------------
3735
+ #region Email
3736
+ #----------------------------------------------------------------------------------
3737
+
3738
+ /**
3739
+ * Generates and sends an HTML email with customizable sections.
3740
+ *
3741
+ * @author Leo Fajardo (@leorw)
3742
+ * @since 1.1.2
3743
+ *
3744
+ * @param string $to_address
3745
+ * @param string $subject
3746
+ * @param array $sections
3747
+ * @param array $headers
3748
+ *
3749
+ * @return bool Whether the email contents were sent successfully.
3750
+ */
3751
+ private function send_email(
3752
+ $to_address,
3753
+ $subject,
3754
+ $sections = array(),
3755
+ $headers = array()
3756
+ ) {
3757
+ $default_sections = $this->get_email_sections();
3758
+
3759
+ // Insert new sections or replace the default email sections.
3760
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
3761
+ foreach ( $sections as $section_id => $custom_section ) {
3762
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
3763
+ // If the section does not exist, add it.
3764
+ $default_sections[ $section_id ] = $custom_section;
3765
+ } else {
3766
+ // If the section already exists, override it.
3767
+ $current_section = $default_sections[ $section_id ];
3768
+
3769
+ // Replace the current section's title if a custom section title exists.
3770
+ if ( isset( $custom_section['title'] ) ) {
3771
+ $current_section['title'] = $custom_section['title'];
3772
+ }
3773
+
3774
+ // Insert new rows under the current section or replace the default rows.
3775
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
3776
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
3777
+ $current_section['rows'][ $row_id ] = $row;
3778
+ }
3779
+ }
3780
+
3781
+ $default_sections[ $section_id ] = $current_section;
3782
+ }
3783
+ }
3784
+ }
3785
+
3786
+ $vars = array( 'sections' => $default_sections );
3787
+ $message = fs_get_template( 'email.php', $vars );
3788
+
3789
+ // Set the type of email to HTML.
3790
+ $headers[] = 'Content-type: text/html; charset=UTF-8';
3791
+
3792
+ $header_string = implode( "\r\n", $headers );
3793
+
3794
+ return wp_mail(
3795
+ $to_address,
3796
+ $subject,
3797
+ $message,
3798
+ $header_string
3799
+ );
3800
+ }
3801
+
3802
+ /**
3803
+ * Generates the data for the sections of the email content.
3804
+ *
3805
+ * @author Leo Fajardo (@leorw)
3806
+ * @since 1.1.2
3807
+ *
3808
+ * @return array
3809
+ */
3810
+ private function get_email_sections() {
3811
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
3812
+ $current_user = self::_get_current_wp_user();
3813
+
3814
+ // Retrieve the cURL version information so that we can get the version number below.
3815
+ $curl_version_information = curl_version();
3816
+
3817
+ $active_plugin = self::get_active_plugins();
3818
+
3819
+ // Generate the list of active plugins separated by new line.
3820
+ $active_plugin_string = '';
3821
+ foreach ( $active_plugin as $plugin ) {
3822
+ $active_plugin_string .= sprintf(
3823
+ '<a href="%s">%s</a> [v%s]<br>',
3824
+ $plugin['PluginURI'],
3825
+ $plugin['Name'],
3826
+ $plugin['Version']
3827
+ );
3828
+ }
3829
+
3830
+ $server_ip = WP_FS__REMOTE_ADDR;
3831
+
3832
+ // Add PHP info for deeper investigation.
3833
+ ob_start();
3834
+ phpinfo();
3835
+ $php_info = ob_get_clean();
3836
+
3837
+ $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
3838
+
3839
+ // Generate the default email sections.
3840
+ $sections = array(
3841
+ 'sdk' => array(
3842
+ 'title' => 'SDK',
3843
+ 'rows' => array(
3844
+ 'fs_version' => array( 'FS Version', $this->version ),
3845
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
3846
+ )
3847
+ ),
3848
+ 'plugin' => array(
3849
+ 'title' => ucfirst( $this->get_module_type() ),
3850
+ 'rows' => array(
3851
+ 'name' => array( 'Name', $this->get_plugin_name() ),
3852
+ 'version' => array( 'Version', $this->get_plugin_version() )
3853
+ )
3854
+ ),
3855
+ 'api' => array(
3856
+ 'title' => 'API Subdomain',
3857
+ 'rows' => array(
3858
+ 'dns' => array(
3859
+ 'DNS_CNAME',
3860
+ function_exists( 'dns_get_record' ) ?
3861
+ var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
3862
+ 'dns_get_record() disabled/blocked'
3863
+ ),
3864
+ 'ip' => array(
3865
+ 'IP',
3866
+ function_exists( 'gethostbyname' ) ?
3867
+ gethostbyname( $api_domain ) :
3868
+ 'gethostbyname() disabled/blocked'
3869
+ ),
3870
+ ),
3871
+ ),
3872
+ 'site' => array(
3873
+ 'title' => 'Site',
3874
+ 'rows' => array(
3875
+ 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
3876
+ 'address' => array( 'Address', site_url() ),
3877
+ 'host' => array(
3878
+ 'HTTP_HOST',
3879
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
3880
+ ),
3881
+ 'hosting' => array(
3882
+ 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
3883
+ fs_request_get( 'hosting_company' ) :
3884
+ 'Unknown',
3885
+ ),
3886
+ 'server_addr' => array(
3887
+ 'SERVER_ADDR',
3888
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
3889
+ )
3890
+ )
3891
+ ),
3892
+ 'user' => array(
3893
+ 'title' => 'User',
3894
+ 'rows' => array(
3895
+ 'email' => array( 'Email', $current_user->user_email ),
3896
+ 'first' => array( 'First', $current_user->user_firstname ),
3897
+ 'last' => array( 'Last', $current_user->user_lastname )
3898
+ )
3899
+ ),
3900
+ 'plugins' => array(
3901
+ 'title' => 'Plugins',
3902
+ 'rows' => array(
3903
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
3904
+ )
3905
+ ),
3906
+ 'php_info' => array(
3907
+ 'title' => 'PHP Info',
3908
+ 'rows' => array(
3909
+ 'info' => array( $php_info )
3910
+ ),
3911
+ )
3912
+ );
3913
+
3914
+ // Allow the sections to be modified by other code.
3915
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
3916
+
3917
+ return $sections;
3918
+ }
3919
+
3920
+ #endregion
3921
+
3922
+ #----------------------------------------------------------------------------------
3923
+ #region Initialization
3924
+ #----------------------------------------------------------------------------------
3925
+
3926
+ /**
3927
+ * Init plugin's Freemius instance.
3928
+ *
3929
+ * @author Vova Feldman (@svovaf)
3930
+ * @since 1.0.1
3931
+ *
3932
+ * @param number $id
3933
+ * @param string $public_key
3934
+ * @param bool $is_live
3935
+ * @param bool $is_premium
3936
+ */
3937
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
3938
+ $this->_logger->entrance();
3939
+
3940
+ $this->dynamic_init( array(
3941
+ 'id' => $id,
3942
+ 'public_key' => $public_key,
3943
+ 'is_live' => $is_live,
3944
+ 'is_premium' => $is_premium,
3945
+ ) );
3946
+ }
3947
+
3948
+ /**
3949
+ * Dynamic initiator, originally created to support initiation
3950
+ * with parent_id for add-ons.
3951
+ *
3952
+ * @author Vova Feldman (@svovaf)
3953
+ * @since 1.0.6
3954
+ *
3955
+ * @param array $plugin_info
3956
+ *
3957
+ * @throws Freemius_Exception
3958
+ */
3959
+ function dynamic_init( array $plugin_info ) {
3960
+ $this->_logger->entrance();
3961
+
3962
+ $this->parse_settings( $plugin_info );
3963
+
3964
+ if ( ! self::is_ajax() ) {
3965
+ if ( ! $this->is_addon() || $this->is_only_premium() ) {
3966
+ add_action(
3967
+ ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
3968
+ array( &$this, '_prepare_admin_menu' ),
3969
+ WP_FS__LOWEST_PRIORITY
3970
+ );
3971
+ }
3972
+ }
3973
+
3974
+ if ( $this->should_stop_execution() ) {
3975
+ return;
3976
+ }
3977
+
3978
+ if ( ! $this->is_registered() ) {
3979
+ if ( $this->is_anonymous() ) {
3980
+ // If user skipped, no need to test connectivity.
3981
+ $this->_has_api_connection = true;
3982
+ $this->_is_on = true;
3983
+ } else {
3984
+ if ( ! $this->has_api_connectivity() ) {
3985
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
3986
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
3987
+ ) {
3988
+ if ( ! $this->_enable_anonymous || $this->is_premium() ) {
3989
+ // If anonymous mode is disabled, add firewall admin-notice message.
3990
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
3991
+
3992
+ $ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
3993
+ add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
3994
+ &$this,
3995
+ '_email_about_firewall_issue'
3996
+ ) );
3997
+
3998
+ add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
3999
+ &$this,
4000
+ '_retry_connectivity_test'
4001
+ ) );
4002
+
4003
+ /**
4004
+ * Currently the admin notice manager relies on the module's type and slug. The new AJAX actions manager uses module IDs, hence, consider to replace the if block above with the commented code below after adjusting the admin notices manager to work with module IDs.
4005
+ *
4006
+ * @author Vova Feldman (@svovaf)
4007
+ * @since 2.0.0
4008
+ */
4009
+ /*$this->add_ajax_action( 'resolve_firewall_issues', array(
4010
+ &$this,
4011
+ '_email_about_firewall_issue'
4012
+ ) );
4013
+
4014
+ $this->add_ajax_action( 'retry_connectivity_test', array(
4015
+ &$this,
4016
+ '_retry_connectivity_test'
4017
+ ) );*/
4018
+ }
4019
+ }
4020
+
4021
+ return;
4022
+ } else {
4023
+ $this->_admin_notices->remove_sticky( array(
4024
+ 'failed_connect_api_first',
4025
+ 'failed_connect_api',
4026
+ ) );
4027
+
4028
+ if ( $this->_anonymous_mode ) {
4029
+ // Simulate anonymous mode.
4030
+ $this->_is_anonymous = true;
4031
+ }
4032
+ }
4033
+ }
4034
+ }
4035
+
4036
+ /**
4037
+ * This should be executed even if Freemius is off for the core module,
4038
+ * otherwise, the add-ons dialogbox won't work properly. This is esepcially
4039
+ * relevant when the developer decided to turn FS off for existing users.
4040
+ *
4041
+ * @author Vova Feldman (@svovaf)
4042
+ */
4043
+ if ( $this->is_user_in_admin() &&
4044
+ ! $this->is_addon() &&
4045
+ $this->has_addons() &&
4046
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
4047
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
4048
+ ) {
4049
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
4050
+
4051
+ new FS_Plugin_Info_Dialog( $this );
4052
+ }
4053
+
4054
+ // Check if Freemius is on for the current plugin.
4055
+ // This MUST be executed after all the plugin variables has been loaded.
4056
+ if ( ! $this->is_registered() && ! $this->is_on() ) {
4057
+ return;
4058
+ }
4059
+
4060
+ if ( $this->has_api_connectivity() ) {
4061
+ if ( self::is_cron() ) {
4062
+ $this->hook_callback_to_sync_cron();
4063
+ } else if ( $this->is_user_in_admin() ) {
4064
+ /**
4065
+ * Schedule daily data sync cron if:
4066
+ *
4067
+ * 1. User opted-in (for tracking).
4068
+ * 2. If skipped, but later upgraded (opted-in via upgrade).
4069
+ *
4070
+ * @author Vova Feldman (@svovaf)
4071
+ * @since 1.1.7.3
4072
+ *
4073
+ */
4074
+ if ( $this->is_registered() ) {
4075
+ if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
4076
+ $this->schedule_sync_cron();
4077
+ }
4078
+ }
4079
+
4080
+ /**
4081
+ * Check if requested for manual blocking background sync.
4082
+ */
4083
+ if ( fs_request_has( 'background_sync' ) ) {
4084
+ $this->run_manual_sync();
4085
+ }
4086
+ }
4087
+ }
4088
+
4089
+ if ( $this->is_registered() ) {
4090
+ $this->hook_callback_to_install_sync();
4091
+ }
4092
+
4093
+ if ( $this->is_addon() ) {
4094
+ if ( $this->is_parent_plugin_installed() ) {
4095
+ // Link to parent FS.
4096
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
4097
+
4098
+ // Get parent plugin reference.
4099
+ $this->_parent_plugin = $this->_parent->get_plugin();
4100
+ }
4101
+ }
4102
+
4103
+ if ( $this->is_user_in_admin() ) {
4104
+ if ( $this->is_addon() ) {
4105
+ if ( ! $this->is_parent_plugin_installed() ) {
4106
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4107
+
4108
+ if ( isset( $plugin_info['parent'] ) ) {
4109
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4110
+ }
4111
+
4112
+ $this->_admin_notices->add(
4113
+ ( ! empty( $parent_name ) ?
4114
+ sprintf( $this->get_text_x_inline( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
4115
+ sprintf( $this->get_text_x_inline( '%s cannot run without the plugin.', 'addonX cannot run...', 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
4116
+ ),
4117
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
4118
+ 'error'
4119
+ );
4120
+
4121
+ return;
4122
+ } else {
4123
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
4124
+ // If parent plugin activated, automatically install add-on for the user.
4125
+ $this->_activate_addon_account( $this->_parent );
4126
+ } else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
4127
+ // If add-on activated and parent not, automatically install parent for the user.
4128
+ $this->activate_parent_account( $this->_parent );
4129
+ }
4130
+
4131
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
4132
+ if ( $this->is_premium() ) {
4133
+ // Remove add-on download admin-notice.
4134
+ $this->_parent->_admin_notices->remove_sticky( array(
4135
+ 'addon_plan_upgraded_' . $this->_slug,
4136
+ 'no_addon_license_' . $this->_slug,
4137
+ ) );
4138
+ }
4139
+
4140
+ // $this->deactivate_premium_only_addon_without_license();
4141
+ }
4142
+ }
4143
+
4144
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
4145
+
4146
+ // if ( $this->is_registered() ||
4147
+ // $this->is_anonymous() ||
4148
+ // $this->is_pending_activation()
4149
+ // ) {
4150
+ // $this->_init_admin();
4151
+ // }
4152
+ }
4153
+
4154
+ /**
4155
+ * Should be called outside `$this->is_user_in_admin()` scope
4156
+ * because the updater has some logic that needs to be executed
4157
+ * during AJAX calls.
4158
+ *
4159
+ * Currently we need to hook to the `http_request_host_is_external` filter.
4160
+ * In the future, there might be additional logic added.
4161
+ *
4162
+ * @author Vova Feldman
4163
+ * @since 1.2.1.6
4164
+ */
4165
+ if ( $this->is_premium() && $this->has_release_on_freemius() ) {
4166
+ FS_Plugin_Updater::instance( $this );
4167
+ }
4168
+
4169
+ $this->do_action( 'initiated' );
4170
+
4171
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
4172
+ if ( isset( $this->_storage->prev_is_premium ) ) {
4173
+ $this->apply_filters(
4174
+ 'after_code_type_change',
4175
+ // New code type.
4176
+ $this->_plugin->is_premium
4177
+ );
4178
+ } else {
4179
+ // Set for code type for the first time.
4180
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
4181
+ }
4182
+ }
4183
+
4184
+ if ( ! $this->is_addon() ) {
4185
+ if ( $this->is_registered() ) {
4186
+ // Fix for upgrade from versions < 1.0.9.
4187
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
4188
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
4189
+ }
4190
+
4191
+ $this->do_action( 'after_init_plugin_registered' );
4192
+ } else if ( $this->is_anonymous() ) {
4193
+ $this->do_action( 'after_init_plugin_anonymous' );
4194
+ } else if ( $this->is_pending_activation() ) {
4195
+ $this->do_action( 'after_init_plugin_pending_activations' );
4196
+ }
4197
+ } else {
4198
+ if ( $this->is_registered() ) {
4199
+ $this->do_action( 'after_init_addon_registered' );
4200
+ } else if ( $this->is_anonymous() ) {
4201
+ $this->do_action( 'after_init_addon_anonymous' );
4202
+ } else if ( $this->is_pending_activation() ) {
4203
+ $this->do_action( 'after_init_addon_pending_activations' );
4204
+ }
4205
+ }
4206
+ }
4207
+
4208
+ /**
4209
+ * @author Leo Fajardo (@leorw)
4210
+ *
4211
+ * @since 1.2.1.5
4212
+ */
4213
+ function _stop_tracking_callback() {
4214
+ $this->_logger->entrance();
4215
+
4216
+ $this->check_ajax_referer( 'stop_tracking' );
4217
+
4218
+ $result = $this->stop_tracking( fs_is_network_admin() );
4219
+
4220
+ if ( true === $result ) {
4221
+ self::shoot_ajax_success();
4222
+ }
4223
+
4224
+ $this->_logger->api_error( $result );
4225
+
4226
+ self::shoot_ajax_failure(
4227
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
4228
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
4229
+ $result->error->message :
4230
+ var_export( $result, true ) )
4231
+ );
4232
+ }
4233
+
4234
+ /**
4235
+ * @author Leo Fajardo (@leorw)
4236
+ * @since 1.2.1.5
4237
+ */
4238
+ function _allow_tracking_callback() {
4239
+ $this->_logger->entrance();
4240
+
4241
+ $this->check_ajax_referer( 'allow_tracking' );
4242
+
4243
+ $result = $this->allow_tracking( fs_is_network_admin() );
4244
+
4245
+ if ( true === $result ) {
4246
+ self::shoot_ajax_success();
4247
+ }
4248
+
4249
+ $this->_logger->api_error( $result );
4250
+
4251
+ self::shoot_ajax_failure(
4252
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
4253
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
4254
+ $result->error->message :
4255
+ var_export( $result, true ) )
4256
+ );
4257
+ }
4258
+
4259
+ /**
4260
+ * Opt-out from usage tracking.
4261
+ *
4262
+ * Note: This will not delete the account information but will stop all tracking.
4263
+ *
4264
+ * Returns:
4265
+ * 1. FALSE - If the user never opted-in.
4266
+ * 2. TRUE - If successfully opted-out.
4267
+ * 3. object - API result on failure.
4268
+ *
4269
+ * @author Leo Fajardo (@leorw)
4270
+ * @since 1.2.1.5
4271
+ *
4272
+ * @return bool|object
4273
+ */
4274
+ function stop_site_tracking() {
4275
+ $this->_logger->entrance();
4276
+
4277
+ if ( ! $this->is_registered() ) {
4278
+ // User never opted-in.
4279
+ return false;
4280
+ }
4281
+
4282
+ if ( $this->is_tracking_prohibited() ) {
4283
+ // Already disconnected.
4284
+ return true;
4285
+ }
4286
+
4287
+ // Send update to FS.
4288
+ $result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
4289
+ 'is_disconnected' => true
4290
+ ) );
4291
+
4292
+ if ( ! $this->is_api_result_entity( $result ) ||
4293
+ ! isset( $result->is_disconnected ) ||
4294
+ ! $result->is_disconnected
4295
+ ) {
4296
+ $this->_logger->api_error( $result );
4297
+
4298
+ return $result;
4299
+ }
4300
+
4301
+ $this->_site->is_disconnected = $result->is_disconnected;
4302
+ $this->_store_site();
4303
+
4304
+ $this->clear_sync_cron();
4305
+
4306
+ // Successfully disconnected.
4307
+ return true;
4308
+ }
4309
+
4310
+ /**
4311
+ * Opt-out network from usage tracking.
4312
+ *
4313
+ * Note: This will not delete the account information but will stop all tracking.
4314
+ *
4315
+ * Returns:
4316
+ * 1. FALSE - If the user never opted-in.
4317
+ * 2. TRUE - If successfully opted-out.
4318
+ * 3. object - API result on failure.
4319
+ *
4320
+ * @author Leo Fajardo (@leorw)
4321
+ * @since 1.2.1.5
4322
+ *
4323
+ * @return bool|object
4324
+ */
4325
+ function stop_network_tracking() {
4326
+ $this->_logger->entrance();
4327
+
4328
+ if ( ! $this->is_registered() ) {
4329
+ // User never opted-in.
4330
+ return false;
4331
+ }
4332
+
4333
+ $install_id_2_blog_id = array();
4334
+ $installs_map = $this->get_blog_install_map();
4335
+
4336
+ $opt_out_all = true;
4337
+
4338
+ $params = array();
4339
+ foreach ( $installs_map as $blog_id => $install ) {
4340
+ if ( $install->is_tracking_prohibited() ) {
4341
+ // Already opted-out.
4342
+ continue;
4343
+ }
4344
+
4345
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
4346
+ // Opt-out only from non-delegated installs.
4347
+ $opt_out_all = false;
4348
+ continue;
4349
+ }
4350
+
4351
+ $params[] = array( 'id' => $install->id );
4352
+
4353
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
4354
+ }
4355
+
4356
+ if ( empty( $install_id_2_blog_id ) ) {
4357
+ return true;
4358
+ }
4359
+
4360
+ $params[] = array( 'is_disconnected' => true );
4361
+
4362
+ // Send update to FS.
4363
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
4364
+
4365
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
4366
+ $this->_logger->api_error( $result );
4367
+
4368
+ return $result;
4369
+ }
4370
+
4371
+ foreach ( $result->installs as $r_install ) {
4372
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
4373
+ $install = $installs_map[ $blog_id ];
4374
+ $install->is_disconnected = $r_install->is_disconnected;
4375
+ $this->_store_site( true, $blog_id, $install );
4376
+ }
4377
+
4378
+ $this->clear_sync_cron( $opt_out_all );
4379
+
4380
+ // Successfully disconnected.
4381
+ return true;
4382
+ }
4383
+
4384
+ /**
4385
+ * Opt-out from usage tracking.
4386
+ *
4387
+ * Note: This will not delete the account information but will stop all tracking.
4388
+ *
4389
+ * Returns:
4390
+ * 1. FALSE - If the user never opted-in.
4391
+ * 2. TRUE - If successfully opted-out.
4392
+ * 3. object - API result on failure.
4393
+ *
4394
+ * @author Leo Fajardo (@leorw)
4395
+ * @since 1.2.1.5
4396
+ *
4397
+ * @param bool $is_network_action
4398
+ *
4399
+ * @return bool|object
4400
+ */
4401
+ function stop_tracking( $is_network_action = false ) {
4402
+ $this->_logger->entrance();
4403
+
4404
+ return $is_network_action ?
4405
+ $this->stop_network_tracking() :
4406
+ $this->stop_site_tracking();
4407
+ }
4408
+
4409
+ /**
4410
+ * Opt-in back into usage tracking.
4411
+ *
4412
+ * Note: This will only work if the user opted-in previously.
4413
+ *
4414
+ * Returns:
4415
+ * 1. FALSE - If the user never opted-in.
4416
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4417
+ * 3. object - API result on failure.
4418
+ *
4419
+ * @author Leo Fajardo (@leorw)
4420
+ * @since 1.2.1.5
4421
+ *
4422
+ * @return bool|object
4423
+ */
4424
+ function allow_site_tracking() {
4425
+ $this->_logger->entrance();
4426
+
4427
+ if ( ! $this->is_registered() ) {
4428
+ // User never opted-in.
4429
+ return false;
4430
+ }
4431
+
4432
+ if ( $this->is_tracking_allowed() ) {
4433
+ // Tracking already allowed.
4434
+ return true;
4435
+ }
4436
+
4437
+ $result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
4438
+ 'is_disconnected' => false
4439
+ ) );
4440
+
4441
+ if ( ! $this->is_api_result_entity( $result ) ||
4442
+ ! isset( $result->is_disconnected ) ||
4443
+ $result->is_disconnected
4444
+ ) {
4445
+ $this->_logger->api_error( $result );
4446
+
4447
+ return $result;
4448
+ }
4449
+
4450
+ $this->_site->is_disconnected = $result->is_disconnected;
4451
+ $this->_store_site();
4452
+
4453
+ $this->schedule_sync_cron();
4454
+
4455
+ // Successfully reconnected.
4456
+ return true;
4457
+ }
4458
+
4459
+ /**
4460
+ * Opt-in network back into usage tracking.
4461
+ *
4462
+ * Note: This will only work if the user opted-in previously.
4463
+ *
4464
+ * Returns:
4465
+ * 1. FALSE - If the user never opted-in.
4466
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4467
+ * 3. object - API result on failure.
4468
+ *
4469
+ * @author Leo Fajardo (@leorw)
4470
+ * @since 1.2.1.5
4471
+ *
4472
+ * @return bool|object
4473
+ */
4474
+ function allow_network_tracking() {
4475
+ $this->_logger->entrance();
4476
+
4477
+ if ( ! $this->is_registered() ) {
4478
+ // User never opted-in.
4479
+ return false;
4480
+ }
4481
+
4482
+ $install_id_2_blog_id = array();
4483
+ $installs_map = $this->get_blog_install_map();
4484
+
4485
+ $params = array();
4486
+ foreach ( $installs_map as $blog_id => $install ) {
4487
+ if ( $install->is_tracking_allowed() ) {
4488
+ continue;
4489
+ }
4490
+
4491
+ $params[] = array( 'id' => $install->id );
4492
+
4493
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
4494
+ }
4495
+
4496
+ if ( empty( $install_id_2_blog_id ) ) {
4497
+ return true;
4498
+ }
4499
+
4500
+ $params[] = array( 'is_disconnected' => false );
4501
+
4502
+ // Send update to FS.
4503
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
4504
+
4505
+
4506
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
4507
+ $this->_logger->api_error( $result );
4508
+
4509
+ return $result;
4510
+ }
4511
+
4512
+ foreach ( $result->installs as $r_install ) {
4513
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
4514
+ $install = $installs_map[ $blog_id ];
4515
+ $install->is_disconnected = $r_install->is_disconnected;
4516
+ $this->_store_site( true, $blog_id, $install );
4517
+ }
4518
+
4519
+ $this->schedule_sync_cron();
4520
+
4521
+ // Successfully reconnected.
4522
+ return true;
4523
+ }
4524
+
4525
+ /**
4526
+ * Opt-in back into usage tracking.
4527
+ *
4528
+ * Note: This will only work if the user opted-in previously.
4529
+ *
4530
+ * Returns:
4531
+ * 1. FALSE - If the user never opted-in.
4532
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4533
+ * 3. object - API result on failure.
4534
+ *
4535
+ * @author Leo Fajardo (@leorw)
4536
+ * @since 1.2.1.5
4537
+ *
4538
+ * @param bool $is_network_action
4539
+ *
4540
+ * @return bool|object
4541
+ */
4542
+ function allow_tracking( $is_network_action = false ) {
4543
+ $this->_logger->entrance();
4544
+
4545
+ return $is_network_action ?
4546
+ $this->allow_network_tracking() :
4547
+ $this->allow_site_tracking();
4548
+ }
4549
+
4550
+ /**
4551
+ * If user opted-in and later disabled usage-tracking,
4552
+ * re-allow tracking for licensing and updates.
4553
+ *
4554
+ * @author Leo Fajardo (@leorw)
4555
+ * @since 1.2.1.5
4556
+ *
4557
+ * @param bool $is_context_single_site
4558
+ */
4559
+ private function reconnect_locally( $is_context_single_site = false ) {
4560
+ $this->_logger->entrance();
4561
+
4562
+ if ( ! $this->is_registered() ) {
4563
+ return;
4564
+ }
4565
+
4566
+ if ( ! fs_is_network_admin() || $is_context_single_site ) {
4567
+ if ( $this->is_tracking_prohibited() ) {
4568
+ $this->_site->is_disconnected = false;
4569
+ $this->_store_site();
4570
+ }
4571
+ } else {
4572
+ $installs_map = $this->get_blog_install_map();
4573
+ foreach ( $installs_map as $blog_id => $install ) {
4574
+ /**
4575
+ * @var FS_Site $install
4576
+ */
4577
+ if ( $install->is_tracking_prohibited() ) {
4578
+ $install->is_disconnected = false;
4579
+ $this->_store_site( true, $blog_id, $install );
4580
+ }
4581
+ }
4582
+ }
4583
+ }
4584
+
4585
+ /**
4586
+ * Parse plugin's settings (as defined by the plugin dev).
4587
+ *
4588
+ * @author Vova Feldman (@svovaf)
4589
+ * @since 1.1.7.3
4590
+ *
4591
+ * @param array $plugin_info
4592
+ *
4593
+ * @throws \Freemius_Exception
4594
+ */
4595
+ private function parse_settings( &$plugin_info ) {
4596
+ $this->_logger->entrance();
4597
+
4598
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
4599
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
4600
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
4601
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
4602
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4603
+
4604
+ /**
4605
+ * @author Vova Feldman (@svovaf)
4606
+ * @since 1.1.9 Try to pull secret key from external config.
4607
+ */
4608
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
4609
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
4610
+ }
4611
+
4612
+ if ( isset( $plugin_info['parent'] ) ) {
4613
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
4614
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
4615
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
4616
+ // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4617
+ }
4618
+
4619
+ if ( false === $id ) {
4620
+ throw new Freemius_Exception( array(
4621
+ 'error' => array(
4622
+ 'type' => 'ParameterNotSet',
4623
+ 'message' => 'Plugin id parameter is not set.',
4624
+ 'code' => 'plugin_id_not_set',
4625
+ 'http' => 500,
4626
+ )
4627
+ ) );
4628
+ }
4629
+ if ( false === $public_key ) {
4630
+ throw new Freemius_Exception( array(
4631
+ 'error' => array(
4632
+ 'type' => 'ParameterNotSet',
4633
+ 'message' => 'Plugin public_key parameter is not set.',
4634
+ 'code' => 'plugin_public_key_not_set',
4635
+ 'http' => 500,
4636
+ )
4637
+ ) );
4638
+ }
4639
+
4640
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
4641
+ $this->_plugin :
4642
+ new FS_Plugin();
4643
+
4644
+ $plugin->update( array(
4645
+ 'id' => $id,
4646
+ 'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
4647
+ 'public_key' => $public_key,
4648
+ 'slug' => $this->_slug,
4649
+ 'parent_plugin_id' => $parent_id,
4650
+ 'version' => $this->get_plugin_version(),
4651
+ 'title' => $this->get_plugin_name(),
4652
+ 'file' => $this->_plugin_basename,
4653
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
4654
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
4655
+ 'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
4656
+ ) );
4657
+
4658
+ if ( $plugin->is_updated() ) {
4659
+ // Update plugin details.
4660
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
4661
+ }
4662
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
4663
+ $this->_plugin->secret_key = $secret_key;
4664
+
4665
+ if ( ! isset( $plugin_info['menu'] ) ) {
4666
+ $plugin_info['menu'] = array();
4667
+
4668
+ if ( ! empty( $this->_storage->sdk_last_version ) &&
4669
+ version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
4670
+ ) {
4671
+ // Backward compatibility to 1.1.2
4672
+ $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
4673
+ $plugin_info['menu_slug'] :
4674
+ $this->_slug;
4675
+ }
4676
+ }
4677
+
4678
+ $this->_menu = FS_Admin_Menu_Manager::instance(
4679
+ $this->_module_id,
4680
+ $this->_module_type,
4681
+ $this->get_unique_affix()
4682
+ );
4683
+
4684
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
4685
+
4686
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
4687
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
4688
+ $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
4689
+ $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
4690
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
4691
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
4692
+ if ( $this->_is_premium_only ) {
4693
+ // If premium only plugin, disable anonymous mode.
4694
+ $this->_enable_anonymous = false;
4695
+ $this->_anonymous_mode = false;
4696
+ } else {
4697
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
4698
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
4699
+ }
4700
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
4701
+
4702
+ if ( ! empty( $plugin_info['trial'] ) ) {
4703
+ $this->_trial_days = $this->get_numeric_option(
4704
+ $plugin_info['trial'],
4705
+ 'days',
4706
+ // Default to 0 - trial without days specification.
4707
+ 0
4708
+ );
4709
+
4710
+ $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
4711
+ }
4712
+ }
4713
+
4714
+ /**
4715
+ * @param string[] $options
4716
+ * @param string $key
4717
+ * @param mixed $default
4718
+ *
4719
+ * @return bool
4720
+ */
4721
+ private function get_option( &$options, $key, $default = false ) {
4722
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
4723
+ }
4724
+
4725
+ private function get_bool_option( &$options, $key, $default = false ) {
4726
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
4727
+ }
4728
+
4729
+ private function get_numeric_option( &$options, $key, $default = false ) {
4730
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
4731
+ }
4732
+
4733
+ /**
4734
+ * Gate keeper.
4735
+ *
4736
+ * @author Vova Feldman (@svovaf)
4737
+ * @since 1.1.7.3
4738
+ *
4739
+ * @return bool
4740
+ */
4741
+ private function should_stop_execution() {
4742
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
4743
+ /**
4744
+ * Don't execute Freemius until plugin was fully loaded at least once,
4745
+ * to give the opportunity for the activation hook to run before pinging
4746
+ * the API for connectivity test. This logic is relevant for the
4747
+ * identification of new plugin install vs. plugin update.
4748
+ *
4749
+ * @author Vova Feldman (@svovaf)
4750
+ * @since 1.1.9
4751
+ */
4752
+ return true;
4753
+ }
4754
+
4755
+ if ( $this->is_activation_mode() ) {
4756
+ if ( ! is_admin() ) {
4757
+ /**
4758
+ * If in activation mode, don't execute Freemius outside of the
4759
+ * admin dashboard.
4760
+ *
4761
+ * @author Vova Feldman (@svovaf)
4762
+ * @since 1.1.7.3
4763
+ */
4764
+ return true;
4765
+ }
4766
+
4767
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
4768
+ /**
4769
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
4770
+ * then don't start Freemius.
4771
+ *
4772
+ * @author Vova Feldman (@svovaf)
4773
+ * @since 1.1.6.3
4774
+ *
4775
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
4776
+ */
4777
+ return true;
4778
+ }
4779
+
4780
+ if ( self::is_cron() ) {
4781
+ /**
4782
+ * If in activation mode, don't execute Freemius during wp crons
4783
+ * (wp crons have HTTP context - called as HTTP request).
4784
+ *
4785
+ * @author Vova Feldman (@svovaf)
4786
+ * @since 1.1.7.3
4787
+ */
4788
+ return true;
4789
+ }
4790
+
4791
+ if ( self::is_ajax() &&
4792
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
4793
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
4794
+ ) {
4795
+ /**
4796
+ * During activation, if running in AJAX mode, unless there's a sticky
4797
+ * connectivity issue notice, don't run Freemius.
4798
+ *
4799
+ * @author Vova Feldman (@svovaf)
4800
+ * @since 1.1.7.3
4801
+ */
4802
+ return true;
4803
+ }
4804
+ }
4805
+
4806
+ return false;
4807
+ }
4808
+
4809
+ /**
4810
+ * Triggered after code type has changed.
4811
+ *
4812
+ * @author Vova Feldman (@svovaf)
4813
+ * @since 1.1.9.1
4814
+ */
4815
+ function _after_code_type_change() {
4816
+ $this->_logger->entrance();
4817
+
4818
+ if ( $this->is_theme() ) {
4819
+ // Expire the cache of the previous tabs since the theme may
4820
+ // have setting updates after code type has changed.
4821
+ $this->_cache->expire( 'tabs' );
4822
+ $this->_cache->expire( 'tabs_stylesheets' );
4823
+ }
4824
+
4825
+ if ( $this->is_registered() ) {
4826
+ if ( ! $this->is_addon() ) {
4827
+ add_action(
4828
+ is_admin() ? 'admin_init' : 'init',
4829
+ array( &$this, '_plugin_code_type_changed' )
4830
+ );
4831
+ }
4832
+
4833
+ if ( $this->is_premium() ) {
4834
+ // Purge cached payments after switching to the premium version.
4835
+ // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
4836
+ $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
4837
+ }
4838
+ }
4839
+ }
4840
+
4841
+ /**
4842
+ * Handles plugin's code type change (free <--> premium).
4843
+ *
4844
+ * @author Vova Feldman (@svovaf)
4845
+ * @since 1.0.9
4846
+ */
4847
+ function _plugin_code_type_changed() {
4848
+ $this->_logger->entrance();
4849
+
4850
+ if ( $this->is_premium() ) {
4851
+ $this->reconnect_locally();
4852
+
4853
+ // Activated premium code.
4854
+ $this->do_action( 'after_premium_version_activation' );
4855
+
4856
+ // Remove all sticky messages related to download of the premium version.
4857
+ $this->_admin_notices->remove_sticky( array(
4858
+ 'trial_started',
4859
+ 'plan_upgraded',
4860
+ 'plan_changed',
4861
+ 'license_activated',
4862
+ ) );
4863
+
4864
+ $notice = '';
4865
+ if ( ! $this->is_only_premium() ) {
4866
+ $notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
4867
+ }
4868
+
4869
+ $license_notice = $this->get_license_network_activation_notice();
4870
+ if ( ! empty( $license_notice ) ) {
4871
+ $notice .= ' ' . $license_notice;
4872
+ }
4873
+
4874
+ if ( ! empty( $notice ) ) {
4875
+ $this->_admin_notices->add_sticky(
4876
+ trim( $notice ),
4877
+ 'premium_activated',
4878
+ $this->get_text_x_inline( 'W00t',
4879
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
4880
+ );
4881
+ }
4882
+ } else {
4883
+ // Remove sticky message related to premium code activation.
4884
+ $this->_admin_notices->remove_sticky( 'premium_activated' );
4885
+
4886
+ // Activated free code (after had the premium before).
4887
+ $this->do_action( 'after_free_version_reactivation' );
4888
+
4889
+ if ( $this->is_paying() && ! $this->is_premium() ) {
4890
+ $this->_admin_notices->add_sticky(
4891
+ sprintf(
4892
+ /* translators: %s: License type (e.g. you have a professional license) */
4893
+ $this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
4894
+ $this->get_plan_title()
4895
+ ) . $this->get_complete_upgrade_instructions(),
4896
+ 'plan_upgraded',
4897
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
4898
+ );
4899
+ }
4900
+ }
4901
+
4902
+ // Schedule code type changes event.
4903
+ $this->schedule_install_sync();
4904
+
4905
+ /**
4906
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
4907
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
4908
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
4909
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
4910
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
4911
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
4912
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
4913
+ */
4914
+ $this->unregister_uninstall_hook();
4915
+
4916
+ $this->clear_module_main_file_cache();
4917
+
4918
+ // Update is_premium of latest version.
4919
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
4920
+ }
4921
+
4922
+ #endregion
4923
+
4924
+ #----------------------------------------------------------------------------------
4925
+ #region Add-ons
4926
+ #----------------------------------------------------------------------------------
4927
+
4928
+ /**
4929
+ * Check if add-on installed and activated on site.
4930
+ *
4931
+ * @author Vova Feldman (@svovaf)
4932
+ * @since 1.0.6
4933
+ *
4934
+ * @param string|number $id_or_slug
4935
+ * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
4936
+ *
4937
+ * @return bool
4938
+ */
4939
+ function is_addon_activated( $id_or_slug, $is_premium = null ) {
4940
+ $this->_logger->entrance();
4941
+
4942
+ $addon_id = self::get_module_id( $id_or_slug );
4943
+ $is_activated = self::has_instance( $addon_id );
4944
+
4945
+ if ( ! $is_activated ) {
4946
+ return false;
4947
+ }
4948
+
4949
+ if ( is_bool( $is_premium ) ) {
4950
+ // Check if the specified code version is activate.
4951
+ $addon = $this->get_addon_instance( $addon_id );
4952
+ $is_activated = ( $is_premium === $addon->is_premium() );
4953
+ }
4954
+
4955
+ return $is_activated;
4956
+ }
4957
+
4958
+ /**
4959
+ * Check if add-on was connected to install
4960
+ *
4961
+ * @author Vova Feldman (@svovaf)
4962
+ * @since 1.1.7
4963
+ *
4964
+ * @param string|number $id_or_slug
4965
+ *
4966
+ * @return bool
4967
+ */
4968
+ function is_addon_connected( $id_or_slug ) {
4969
+ $this->_logger->entrance();
4970
+
4971
+ $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
4972
+
4973
+ $addon_id = self::get_module_id( $id_or_slug );
4974
+ $addon = $this->get_addon( $addon_id );
4975
+ $slug = $addon->slug;
4976
+ if ( ! isset( $sites[ $slug ] ) ) {
4977
+ return false;
4978
+ }
4979
+
4980
+ $site = $sites[ $slug ];
4981
+
4982
+ $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
4983
+
4984
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
4985
+ // The given slug do NOT belong to any of the plugin's add-ons.
4986
+ return false;
4987
+ }
4988
+
4989
+ return ( is_object( $site ) &&
4990
+ is_numeric( $site->id ) &&
4991
+ is_numeric( $site->user_id ) &&
4992
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
4993
+ );
4994
+ }
4995
+
4996
+ /**
4997
+ * Determines if add-on installed.
4998
+ *
4999
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
5000
+ *
5001
+ * @author Vova Feldman (@svovaf)
5002
+ * @since 1.0.6
5003
+ *
5004
+ * @param string|number $id_or_slug
5005
+ *
5006
+ * @return bool
5007
+ */
5008
+ function is_addon_installed( $id_or_slug ) {
5009
+ $this->_logger->entrance();
5010
+
5011
+ $addon_id = self::get_module_id( $id_or_slug );
5012
+
5013
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
5014
+ }
5015
+
5016
+ /**
5017
+ * Get add-on basename.
5018
+ *
5019
+ * @author Vova Feldman (@svovaf)
5020
+ * @since 1.0.6
5021
+ *
5022
+ * @param string|number $id_or_slug
5023
+ *
5024
+ * @return string
5025
+ */
5026
+ function get_addon_basename( $id_or_slug ) {
5027
+ $addon_id = self::get_module_id( $id_or_slug );
5028
+
5029
+ if ( $this->is_addon_activated( $addon_id ) ) {
5030
+ return self::instance( $addon_id )->get_plugin_basename();
5031
+ }
5032
+
5033
+ $addon = $this->get_addon( $addon_id );
5034
+ $premium_basename = "{$addon->slug}-premium/{$addon->slug}.php";
5035
+
5036
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
5037
+ return $premium_basename;
5038
+ }
5039
+
5040
+ $all_plugins = $this->get_all_plugins();
5041
+
5042
+ foreach ( $all_plugins as $basename => &$data ) {
5043
+ if ( $addon->slug === $data['slug'] ||
5044
+ $addon->slug . '-premium' === $data['slug']
5045
+ ) {
5046
+ return $basename;
5047
+ }
5048
+ }
5049
+
5050
+ $free_basename = "{$addon->slug}/{$addon->slug}.php";
5051
+
5052
+ return $free_basename;
5053
+ }
5054
+
5055
+ /**
5056
+ * Get installed add-ons instances.
5057
+ *
5058
+ * @author Vova Feldman (@svovaf)
5059
+ * @since 1.0.6
5060
+ *
5061
+ * @return Freemius[]
5062
+ */
5063
+ function get_installed_addons() {
5064
+ $installed_addons = array();
5065
+ foreach ( self::$_instances as $instance ) {
5066
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
5067
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
5068
+ $installed_addons[] = $instance;
5069
+ }
5070
+ }
5071
+ }
5072
+
5073
+ return $installed_addons;
5074
+ }
5075
+
5076
+ /**
5077
+ * Check if any add-ons of the plugin are installed.
5078
+ *
5079
+ * @author Leo Fajardo (@leorw)
5080
+ * @since 1.1.1
5081
+ *
5082
+ * @return bool
5083
+ */
5084
+ function has_installed_addons() {
5085
+ if ( ! $this->has_addons() ) {
5086
+ return false;
5087
+ }
5088
+
5089
+ foreach ( self::$_instances as $instance ) {
5090
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
5091
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
5092
+ return true;
5093
+ }
5094
+ }
5095
+ }
5096
+
5097
+ return false;
5098
+ }
5099
+
5100
+ /**
5101
+ * Tell Freemius that the current plugin is an add-on.
5102
+ *
5103
+ * @author Vova Feldman (@svovaf)
5104
+ * @since 1.0.6
5105
+ *
5106
+ * @param number $parent_plugin_id The parent plugin ID
5107
+ */
5108
+ function init_addon( $parent_plugin_id ) {
5109
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
5110
+ }
5111
+
5112
+ /**
5113
+ * @author Vova Feldman (@svovaf)
5114
+ * @since 1.0.6
5115
+ *
5116
+ * @return bool
5117
+ */
5118
+ function is_addon() {
5119
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
5120
+ }
5121
+
5122
+ /**
5123
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
5124
+ *
5125
+ * @param bool $is_after_trial_cancel
5126
+ *
5127
+ * @return bool If add-on was deactivated.
5128
+ */
5129
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
5130
+ if ( ! $this->has_free_plan() &&
5131
+ ! $this->has_features_enabled_license() &&
5132
+ ! $this->_has_premium_license()
5133
+ ) {
5134
+ if ( $this->is_registered() ) {
5135
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
5136
+ // if (empty($this->_storage->activation_timestamp) ||
5137
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
5138
+ // ) {
5139
+ /**
5140
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
5141
+ *
5142
+ * Retry syncing the user add-on licenses.
5143
+ */
5144
+ // Sync licenses.
5145
+ $this->_sync_licenses();
5146
+ // }
5147
+
5148
+ // Try to activate premium license.
5149
+ $this->_activate_license( true );
5150
+ }
5151
+
5152
+ if ( ! $this->has_free_plan() &&
5153
+ ! $this->has_features_enabled_license() &&
5154
+ ! $this->_has_premium_license()
5155
+ ) {
5156
+ // @todo Check if deactivate plugins also call the deactivation hook.
5157
+
5158
+ $this->_parent->_admin_notices->add_sticky(
5159
+ sprintf(
5160
+ ( $is_after_trial_cancel ?
5161
+ $this->_parent->get_text_inline(
5162
+ '%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.',
5163
+ 'addon-trial-cancelled-message'
5164
+ ) :
5165
+ $this->_parent->get_text_inline(
5166
+ '%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
5167
+ 'addon-no-license-message'
5168
+ )
5169
+ ),
5170
+ '<b>' . $this->_plugin->title . '</b>'
5171
+ ) . ' ' . sprintf(
5172
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
5173
+ $this->_parent->addon_url( $this->_slug ),
5174
+ esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
5175
+ $this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
5176
+ ),
5177
+ 'no_addon_license_' . $this->_slug,
5178
+ ( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
5179
+ ( $is_after_trial_cancel ? 'success' : 'error' )
5180
+ );
5181
+
5182
+ deactivate_plugins( array( $this->_plugin_basename ), true );
5183
+
5184
+ return true;
5185
+ }
5186
+ }
5187
+
5188
+ return false;
5189
+ }
5190
+
5191
+ #endregion
5192
+
5193
+ #----------------------------------------------------------------------------------
5194
+ #region Sandbox
5195
+ #----------------------------------------------------------------------------------
5196
+
5197
+ /**
5198
+ * Set Freemius into sandbox mode for debugging.
5199
+ *
5200
+ * @author Vova Feldman (@svovaf)
5201
+ * @since 1.0.4
5202
+ *
5203
+ * @param string $secret_key
5204
+ */
5205
+ function init_sandbox( $secret_key ) {
5206
+ $this->_plugin->secret_key = $secret_key;
5207
+
5208
+ // Update plugin details.
5209
+ FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
5210
+ }
5211
+
5212
+ /**
5213
+ * Check if running payments in sandbox mode.
5214
+ *
5215
+ * @author Vova Feldman (@svovaf)
5216
+ * @since 1.0.4
5217
+ *
5218
+ * @return bool
5219
+ */
5220
+ function is_payments_sandbox() {
5221
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
5222
+ }
5223
+
5224
+ #endregion
5225
+
5226
+ /**
5227
+ * Check if running test vs. live plugin.
5228
+ *
5229
+ * @author Vova Feldman (@svovaf)
5230
+ * @since 1.0.5
5231
+ *
5232
+ * @return bool
5233
+ */
5234
+ function is_live() {
5235
+ return $this->_plugin->is_live;
5236
+ }
5237
+
5238
+ /**
5239
+ * Check if super-admin skipped connection for all sites in the network.
5240
+ *
5241
+ * @author Vova Feldman (@svovaf)
5242
+ * @since 2.0.0
5243
+ */
5244
+ function is_network_anonymous() {
5245
+ if ( ! $this->_is_network_active ) {
5246
+ return false;
5247
+ }
5248
+
5249
+ $is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
5250
+
5251
+ if ( empty( $is_anonymous_ms ) ) {
5252
+ return false;
5253
+ }
5254
+
5255
+ return $is_anonymous_ms['is'];
5256
+ }
5257
+
5258
+ /**
5259
+ * Check if super-admin opted-in for all sites in the network.
5260
+ *
5261
+ * @author Vova Feldman (@svovaf)
5262
+ * @since 2.0.0
5263
+ */
5264
+ function is_network_connected() {
5265
+ if ( ! $this->_is_network_active ) {
5266
+ return false;
5267
+ }
5268
+
5269
+ return $this->_storage->get( 'is_network_connected' );
5270
+ }
5271
+
5272
+ /**
5273
+ * Check if the user skipped connecting the account with Freemius.
5274
+ *
5275
+ * @author Vova Feldman (@svovaf)
5276
+ * @since 1.0.7
5277
+ *
5278
+ * @return bool
5279
+ */
5280
+ function is_anonymous() {
5281
+ if ( ! isset( $this->_is_anonymous ) ) {
5282
+ if ( $this->is_network_anonymous() ) {
5283
+ $this->_is_anonymous = true;
5284
+ } else {
5285
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
5286
+ // Not skipped.
5287
+ $this->_is_anonymous = false;
5288
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
5289
+ // For back compatibility, since the variable was boolean before.
5290
+ $this->_is_anonymous = $this->_storage->is_anonymous;
5291
+
5292
+ // Upgrade stored data format to 1.1.3 format.
5293
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
5294
+ } else {
5295
+ // Version 1.1.3 and later.
5296
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
5297
+ }
5298
+ }
5299
+ }
5300
+
5301
+ return $this->_is_anonymous;
5302
+ }
5303
+
5304
+ /**
5305
+ * Check if the user skipped the connection of a specified site.
5306
+ *
5307
+ * @author Vova Feldman (@svovaf)
5308
+ * @since 2.0.0
5309
+ *
5310
+ * @param int $blog_id
5311
+ *
5312
+ * @return bool
5313
+ */
5314
+ function is_anonymous_site( $blog_id = 0 ) {
5315
+ if ( $this->is_network_anonymous() ) {
5316
+ return true;
5317
+ }
5318
+
5319
+ $is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
5320
+
5321
+ if ( empty( $is_anonymous ) ) {
5322
+ return false;
5323
+ }
5324
+
5325
+ return $is_anonymous['is'];
5326
+ }
5327
+
5328
+ /**
5329
+ * Check if user connected his account and install pending email activation.
5330
+ *
5331
+ * @author Vova Feldman (@svovaf)
5332
+ * @since 1.0.7
5333
+ *
5334
+ * @return bool
5335
+ */
5336
+ function is_pending_activation() {
5337
+ return $this->_storage->get( 'is_pending_activation', false );
5338
+ }
5339
+
5340
+ /**
5341
+ * Check if plugin must be WordPress.org compliant.
5342
+ *
5343
+ * @since 1.0.7
5344
+ *
5345
+ * @return bool
5346
+ */
5347
+ function is_org_repo_compliant() {
5348
+ return $this->_is_org_compliant;
5349
+ }
5350
+
5351
+ #--------------------------------------------------------------------------------
5352
+ #region WP Cron Common
5353
+ #--------------------------------------------------------------------------------
5354
+
5355
+ /**
5356
+ * @author Vova Feldman (@svovaf)
5357
+ * @since 2.0.0
5358
+ *
5359
+ * @param string $name Cron name.
5360
+ *
5361
+ * @return object
5362
+ */
5363
+ private function get_cron_data( $name ) {
5364
+ $this->_logger->entrance( $name );
5365
+
5366
+ /**
5367
+ * @var object $cron_data
5368
+ */
5369
+ return $this->_storage->get( "{$name}_cron", null );
5370
+ }
5371
+
5372
+ /**
5373
+ * @author Vova Feldman (@svovaf)
5374
+ * @since 2.0.0
5375
+ *
5376
+ * @param string $name Cron name.
5377
+ */
5378
+ private function clear_cron_data( $name ) {
5379
+ $this->_logger->entrance( $name );
5380
+
5381
+ $this->_storage->remove( "{$name}_cron" );
5382
+ }
5383
+
5384
+ /**
5385
+ * @author Vova Feldman (@svovaf)
5386
+ * @since 2.0.0
5387
+ *
5388
+ * @param string $name Cron name.
5389
+ * @param int $cron_blog_id The cron executing blog ID.
5390
+ */
5391
+ private function set_cron_data( $name, $cron_blog_id = 0 ) {
5392
+ $this->_logger->entrance( $name );
5393
+
5394
+ $this->_storage->store( "{$name}_cron", (object) array(
5395
+ 'version' => $this->get_plugin_version(),
5396
+ 'blog_id' => $cron_blog_id,
5397
+ 'sdk_version' => $this->version,
5398
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
5399
+ 'on' => true,
5400
+ ) );
5401
+ }
5402
+
5403
+ /**
5404
+ * Get the cron's executing blog ID.
5405
+ *
5406
+ * @author Vova Feldman (@svovaf)
5407
+ * @since 2.0.0
5408
+ *
5409
+ * @param string $name Cron name.
5410
+ *
5411
+ * @return int
5412
+ */
5413
+ private function get_cron_blog_id( $name ) {
5414
+ $this->_logger->entrance( $name );
5415
+
5416
+ /**
5417
+ * @var object $cron_data
5418
+ */
5419
+ $cron_data = $this->get_cron_data( $name );
5420
+
5421
+ return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
5422
+ $cron_data->blog_id :
5423
+ 0;
5424
+ }
5425
+
5426
+ /**
5427
+ * @author Vova Feldman (@svovaf)
5428
+ * @since 2.0.0
5429
+ *
5430
+ * @param string $name Cron name.
5431
+ *
5432
+ * @return bool
5433
+ */
5434
+ private function is_cron_on( $name ) {
5435
+ $this->_logger->entrance( $name );
5436
+
5437
+ /**
5438
+ * @var object $cron_data
5439
+ */
5440
+ $cron_data = $this->get_cron_data( $name );
5441
+
5442
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
5443
+ }
5444
+
5445
+ /**
5446
+ * Unix timestamp for previous cron execution or false if never executed.
5447
+ *
5448
+ * @author Vova Feldman (@svovaf)
5449
+ * @since 2.0.0
5450
+ *
5451
+ * @param string $name Cron name.
5452
+ *
5453
+ * @return int|false
5454
+ */
5455
+ private function cron_last_execution( $name ) {
5456
+ $this->_logger->entrance( $name );
5457
+
5458
+ return $this->_storage->get( "{$name}_timestamp" );
5459
+ }
5460
+
5461
+ /**
5462
+ * Set cron execution time to now.
5463
+ *
5464
+ * @author Vova Feldman (@svovaf)
5465
+ * @since 2.0.0
5466
+ *
5467
+ * @param string $name Cron name.
5468
+ */
5469
+ private function set_cron_execution_timestamp( $name ) {
5470
+ $this->_logger->entrance( $name );
5471
+
5472
+ $this->_storage->store( "{$name}_timestamp", time() );
5473
+ }
5474
+
5475
+ /**
5476
+ * Check if cron was executed in the last $period of seconds.
5477
+ *
5478
+ * @author Vova Feldman (@svovaf)
5479
+ * @since 2.0.0
5480
+ *
5481
+ * @param string $name Cron name.
5482
+ * @param int $period In seconds
5483
+ *
5484
+ * @return bool
5485
+ */
5486
+ private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
5487
+ $this->_logger->entrance( $name );
5488
+
5489
+ $last_execution = $this->set_cron_execution_timestamp( $name );
5490
+
5491
+ if ( ! is_numeric( $last_execution ) ) {
5492
+ return false;
5493
+ }
5494
+
5495
+ return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
5496
+ }
5497
+
5498
+ /**
5499
+ * WP Cron is executed on a site level. When running in a multisite network environment
5500
+ * with the network integration activated, for optimization reasons, we are consolidating
5501
+ * the installs data sync cron to be executed only from a single site.
5502
+ *
5503
+ * @author Vova Feldman (@svovaf)
5504
+ * @since 2.0.0
5505
+ *
5506
+ * @param int $except_blog_id Target any except the excluded blog ID.
5507
+ *
5508
+ * @return int
5509
+ */
5510
+ private function get_cron_target_blog_id( $except_blog_id = 0 ) {
5511
+ if ( ! is_multisite() ) {
5512
+ return 0;
5513
+ }
5514
+
5515
+ if ( $this->_is_network_active &&
5516
+ is_numeric( $this->_storage->network_install_blog_id ) &&
5517
+ $except_blog_id != $this->_storage->network_install_blog_id &&
5518
+ self::is_site_active( $this->_storage->network_install_blog_id )
5519
+ ) {
5520
+ // Try to run cron from the main network blog.
5521
+ $install = $this->get_install_by_blog_id( $this->_storage->network_install_blog_id );
5522
+
5523
+ if ( is_object( $install ) &&
5524
+ ( $this->is_premium() || $install->is_tracking_allowed() )
5525
+ ) {
5526
+ return $this->_storage->network_install_blog_id;
5527
+ }
5528
+ }
5529
+
5530
+ // Get first opted-in blog ID with active tracking.
5531
+ $installs = $this->get_blog_install_map();
5532
+ foreach ( $installs as $blog_id => $install ) {
5533
+ if ( $except_blog_id != $blog_id &&
5534
+ self::is_site_active( $blog_id ) &&
5535
+ ( $this->is_premium() || $install->is_tracking_allowed() )
5536
+ ) {
5537
+ return $blog_id;
5538
+ }
5539
+ }
5540
+
5541
+ return 0;
5542
+ }
5543
+
5544
+ /**
5545
+ * @author Vova Feldman (@svovaf)
5546
+ * @since 2.0.0
5547
+ *
5548
+ * @param string $name Cron name.
5549
+ * @param string $action_tag Callback action tag.
5550
+ * @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
5551
+ */
5552
+ private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
5553
+ $this->_logger->entrance( $name );
5554
+
5555
+ if ( ! $this->is_cron_on( $name ) ) {
5556
+ return;
5557
+ }
5558
+
5559
+ $clear_cron = true;
5560
+ if ( ! $is_network_clear && $this->_is_network_active ) {
5561
+ $installs = $this->get_blog_install_map();
5562
+
5563
+ foreach ( $installs as $blog_id => $install ) {
5564
+ /**
5565
+ * @var FS_Site $install
5566
+ */
5567
+ if ( $install->is_tracking_allowed() ) {
5568
+ $clear_cron = false;
5569
+ break;
5570
+ }
5571
+ }
5572
+ }
5573
+
5574
+ if ( ! $clear_cron ) {
5575
+ return;
5576
+ }
5577
+
5578
+ /**
5579
+ * @var object $cron_data
5580
+ */
5581
+ $cron_data = $this->get_cron_data( $name );
5582
+
5583
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
5584
+ $cron_data->blog_id :
5585
+ 0;
5586
+
5587
+ $this->clear_cron_data( $name );
5588
+
5589
+ if ( 0 < $cron_blog_id ) {
5590
+ switch_to_blog( $cron_blog_id );
5591
+ }
5592
+
5593
+ if ( empty( $action_tag ) ) {
5594
+ $action_tag = $name;
5595
+ }
5596
+
5597
+ wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
5598
+
5599
+ if ( 0 < $cron_blog_id ) {
5600
+ restore_current_blog();
5601
+ }
5602
+ }
5603
+
5604
+ /**
5605
+ * Unix timestamp for next cron execution or false if not scheduled.
5606
+ *
5607
+ * @author Vova Feldman (@svovaf)
5608
+ * @since 2.0.0
5609
+ *
5610
+ * @param string $name Cron name.
5611
+ * @param string $action_tag Callback action tag.
5612
+ *
5613
+ * @return int|false
5614
+ */
5615
+ private function get_next_scheduled_cron( $name, $action_tag = '' ) {
5616
+ $this->_logger->entrance( $name );
5617
+
5618
+ if ( ! $this->is_cron_on( $name ) ) {
5619
+ return false;
5620
+ }
5621
+
5622
+ /**
5623
+ * @var object $cron_data
5624
+ */
5625
+ $cron_data = $this->get_cron_data( $name );
5626
+
5627
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
5628
+ $cron_data->blog_id :
5629
+ 0;
5630
+
5631
+ if ( 0 < $cron_blog_id ) {
5632
+ switch_to_blog( $cron_blog_id );
5633
+ }
5634
+
5635
+ if ( empty( $action_tag ) ) {
5636
+ $action_tag = $name;
5637
+ }
5638
+
5639
+ $next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
5640
+
5641
+ if ( 0 < $cron_blog_id ) {
5642
+ restore_current_blog();
5643
+ }
5644
+
5645
+ return $next_scheduled;
5646
+ }
5647
+
5648
+ /**
5649
+ * @author Vova Feldman (@svovaf)
5650
+ * @since 2.0.0
5651
+ *
5652
+ * @param string $name Cron name.
5653
+ * @param string $action_tag Callback action tag.
5654
+ * @param string $recurrence 'single' or 'daily'.
5655
+ * @param int $start_at Defaults to now.
5656
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
5657
+ * @param int $except_blog_id Target any except the excluded blog ID.
5658
+ */
5659
+ private function schedule_cron(
5660
+ $name,
5661
+ $action_tag = '',
5662
+ $recurrence = 'single',
5663
+ $start_at = WP_FS__SCRIPT_START_TIME,
5664
+ $randomize_start = true,
5665
+ $except_blog_id = 0
5666
+ ) {
5667
+ $this->_logger->entrance( $name );
5668
+
5669
+ $this->clear_cron( $name, $action_tag, true );
5670
+
5671
+ $cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
5672
+
5673
+ if ( is_multisite() && 0 == $cron_blog_id ) {
5674
+ // Don't schedule cron since couldn't find a target blog.
5675
+ return;
5676
+ }
5677
+
5678
+ if ( 0 < $cron_blog_id ) {
5679
+ switch_to_blog( $cron_blog_id );
5680
+ }
5681
+
5682
+ if ( 'daily' === $recurrence ) {
5683
+ if ( $randomize_start ) {
5684
+ // Schedule first sync with a random 12 hour time range from now.
5685
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
5686
+ }
5687
+
5688
+ // Schedule daily WP cron.
5689
+ wp_schedule_event(
5690
+ $start_at,
5691
+ 'daily',
5692
+ $this->get_action_tag( $action_tag )
5693
+ );
5694
+ } else if ( 'single' === $recurrence ) {
5695
+ // Schedule single cron.
5696
+ wp_schedule_single_event(
5697
+ $start_at,
5698
+ $this->get_action_tag( $action_tag )
5699
+ );
5700
+ }
5701
+
5702
+ $this->set_cron_data( $name, $cron_blog_id );
5703
+
5704
+ if ( 0 < $cron_blog_id ) {
5705
+ restore_current_blog();
5706
+ }
5707
+ }
5708
+
5709
+ /**
5710
+ * Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
5711
+ * that doesn't halt page loading.
5712
+ *
5713
+ * @author Vova Feldman (@svovaf)
5714
+ * @since 2.0.0
5715
+ *
5716
+ * @param string $name Cron name.
5717
+ * @param callable $callable The function that should be executed.
5718
+ */
5719
+ private function execute_cron( $name, $callable ) {
5720
+ $this->_logger->entrance( $name );
5721
+
5722
+ // Store the last time data sync was executed.
5723
+ $this->set_cron_execution_timestamp( $name );
5724
+
5725
+ // Check if API is temporary down.
5726
+ if ( FS_Api::is_temporary_down() ) {
5727
+ return;
5728
+ }
5729
+
5730
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
5731
+
5732
+ $users_2_blog_ids = array();
5733
+
5734
+ if ( ! is_multisite() ) {
5735
+ // Add dummy blog.
5736
+ $users_2_blog_ids[0] = array( 0 );
5737
+ } else {
5738
+ $installs = $this->get_blog_install_map();
5739
+ foreach ( $installs as $blog_id => $install ) {
5740
+ if ( $this->is_premium() || $install->is_tracking_allowed() ) {
5741
+ if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
5742
+ $users_2_blog_ids[ $install->user_id ] = array();
5743
+ }
5744
+
5745
+ $users_2_blog_ids[ $install->user_id ][] = $blog_id;
5746
+ }
5747
+ }
5748
+ }
5749
+
5750
+ foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
5751
+ if ( 0 < $blog_ids[0] ) {
5752
+ $this->switch_to_blog( $blog_ids[0] );
5753
+ }
5754
+
5755
+ call_user_func_array( $callable, array( $blog_ids ) );
5756
+
5757
+ foreach ( $blog_ids as $blog_id ) {
5758
+ $this->do_action( "after_{$name}_cron", $blog_id );
5759
+ }
5760
+ }
5761
+
5762
+ if ( is_multisite() ) {
5763
+ $this->do_action( "after_{$name}_cron_multisite" );
5764
+ }
5765
+ }
5766
+
5767
+ #endregion
5768
+
5769
+ #----------------------------------------------------------------------------------
5770
+ #region Daily Sync Cron
5771
+ #----------------------------------------------------------------------------------
5772
+
5773
+
5774
+ /**
5775
+ * @author Vova Feldman (@svovaf)
5776
+ * @since 2.0.0
5777
+ *
5778
+ * @return bool
5779
+ */
5780
+ private function is_sync_cron_scheduled() {
5781
+ return $this->is_cron_on( 'sync' );
5782
+ }
5783
+
5784
+ /**
5785
+ * Get the sync cron's executing blog ID.
5786
+ *
5787
+ * @author Vova Feldman (@svovaf)
5788
+ * @since 2.0.0
5789
+ *
5790
+ * @return int
5791
+ */
5792
+ private function get_sync_cron_blog_id() {
5793
+ return $this->get_cron_blog_id( 'sync' );
5794
+ }
5795
+
5796
+ /**
5797
+ * @author Vova Feldman (@svovaf)
5798
+ * @since 1.1.7.3
5799
+ */
5800
+ private function run_manual_sync() {
5801
+ self::require_pluggable_essentials();
5802
+
5803
+ if ( ! $this->is_user_admin() ) {
5804
+ return;
5805
+ }
5806
+
5807
+ // Run manual sync.
5808
+ $this->_sync_cron();
5809
+
5810
+ // Reschedule next cron to run 24 hours from now (performance optimization).
5811
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
5812
+ }
5813
+
5814
+ /**
5815
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
5816
+ * that doesn't halt page loading.
5817
+ *
5818
+ * @author Vova Feldman (@svovaf)
5819
+ * @since 1.1.7.3
5820
+ * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
5821
+ */
5822
+ function _sync_cron() {
5823
+ $this->_logger->entrance();
5824
+
5825
+ $this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
5826
+ }
5827
+
5828
+ /**
5829
+ * The actual data sync cron logic.
5830
+ *
5831
+ * @author Vova Feldman (@svovaf)
5832
+ * @since 2.0.0
5833
+ *
5834
+ * @param int[] $blog_ids
5835
+ */
5836
+ function _sync_cron_method( array $blog_ids ) {
5837
+ if ( $this->is_registered() ) {
5838
+ if ( $this->has_paid_plan() ) {
5839
+ // Initiate background plan sync.
5840
+ $this->_sync_license( true );
5841
+
5842
+ if ( $this->is_paying() ) {
5843
+ // Check for premium plugin updates.
5844
+ $this->check_updates( true );
5845
+ }
5846
+ } else {
5847
+ // Sync install(s) (only if something changed locally).
5848
+ if ( 1 < count( $blog_ids ) ) {
5849
+ $this->sync_installs();
5850
+ } else {
5851
+ $this->sync_install();
5852
+ }
5853
+ }
5854
+ }
5855
+ }
5856
+
5857
+ /**
5858
+ * Check if sync was executed in the last $period of seconds.
5859
+ *
5860
+ * @author Vova Feldman (@svovaf)
5861
+ * @since 1.1.7.3
5862
+ *
5863
+ * @param int $period In seconds
5864
+ *
5865
+ * @return bool
5866
+ */
5867
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
5868
+ return $this->is_cron_executed( 'sync', $period );
5869
+ }
5870
+
5871
+ /**
5872
+ * @author Vova Feldman (@svovaf)
5873
+ * @since 1.1.7.3
5874
+ *
5875
+ * @return bool
5876
+ */
5877
+ private function is_sync_cron_on() {
5878
+ return $this->is_cron_on( 'sync' );
5879
+ }
5880
+
5881
+ /**
5882
+ * @author Vova Feldman (@svovaf)
5883
+ * @since 1.1.7.3
5884
+ *
5885
+ * @param int $start_at Defaults to now.
5886
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
5887
+ * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
5888
+ */
5889
+ private function schedule_sync_cron(
5890
+ $start_at = WP_FS__SCRIPT_START_TIME,
5891
+ $randomize_start = true,
5892
+ $except_blog_id = 0
5893
+ ) {
5894
+ $this->schedule_cron(
5895
+ 'sync',
5896
+ 'data_sync',
5897
+ 'daily',
5898
+ $start_at,
5899
+ $randomize_start,
5900
+ $except_blog_id
5901
+ );
5902
+ }
5903
+
5904
+ /**
5905
+ * Add the actual sync function to the cron job hook.
5906
+ *
5907
+ * @author Vova Feldman (@svovaf)
5908
+ * @since 1.1.7.3
5909
+ */
5910
+ private function hook_callback_to_sync_cron() {
5911
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
5912
+ }
5913
+
5914
+ /**
5915
+ * @author Vova Feldman (@svovaf)
5916
+ * @since 1.1.7.3
5917
+ *
5918
+ * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
5919
+ */
5920
+ private function clear_sync_cron( $is_network_clear = false ) {
5921
+ $this->_logger->entrance();
5922
+
5923
+ $this->clear_cron( 'sync', 'data_sync', $is_network_clear );
5924
+ }
5925
+
5926
+ /**
5927
+ * Unix timestamp for next sync cron execution or false if not scheduled.
5928
+ *
5929
+ * @author Vova Feldman (@svovaf)
5930
+ * @since 1.1.7.3
5931
+ *
5932
+ * @return int|false
5933
+ */
5934
+ function next_sync_cron() {
5935
+ return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
5936
+ }
5937
+
5938
+ /**
5939
+ * Unix timestamp for previous sync cron execution or false if never executed.
5940
+ *
5941
+ * @author Vova Feldman (@svovaf)
5942
+ * @since 1.1.7.3
5943
+ *
5944
+ * @return int|false
5945
+ */
5946
+ function last_sync_cron() {
5947
+ return $this->cron_last_execution( 'sync' );
5948
+ }
5949
+
5950
+ #endregion Daily Sync Cron ------------------------------------------------------------------
5951
+
5952
+ #----------------------------------------------------------------------------------
5953
+ #region Async Install Sync
5954
+ #----------------------------------------------------------------------------------
5955
+
5956
+ /**
5957
+ * @author Vova Feldman (@svovaf)
5958
+ * @since 1.1.7.3
5959
+ *
5960
+ * @return bool
5961
+ */
5962
+ private function is_install_sync_scheduled() {
5963
+ return $this->is_cron_on( 'install_sync' );
5964
+ }
5965
+
5966
+ /**
5967
+ * Get the sync cron's executing blog ID.
5968
+ *
5969
+ * @author Vova Feldman (@svovaf)
5970
+ * @since 2.0.0
5971
+ *
5972
+ * @return int
5973
+ */
5974
+ private function get_install_sync_cron_blog_id() {
5975
+ return $this->get_cron_blog_id( 'install_sync' );
5976
+ }
5977
+
5978
+ /**
5979
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
5980
+ *
5981
+ * @author Vova Feldman (@svovaf)
5982
+ * @since 1.1.7.3
5983
+ *
5984
+ * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
5985
+ */
5986
+ private function schedule_install_sync( $except_blog_id = 0 ) {
5987
+ $this->schedule_cron( 'install_sync', 'install_sync', 'single', 0, false, $except_blog_id );
5988
+ }
5989
+
5990
+ /**
5991
+ * Unix timestamp for previous install sync cron execution or false if never executed.
5992
+ *
5993
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being updated. But for sure the sync event is working.
5994
+ *
5995
+ * @author Vova Feldman (@svovaf)
5996
+ * @since 1.1.7.3
5997
+ *
5998
+ * @return int|false
5999
+ */
6000
+ function last_install_sync() {
6001
+ return $this->cron_last_execution( 'install_sync' );
6002
+ }
6003
+
6004
+ /**
6005
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
6006
+ *
6007
+ * @author Vova Feldman (@svovaf)
6008
+ * @since 1.1.7.3
6009
+ *
6010
+ * @return int|false
6011
+ */
6012
+ function next_install_sync() {
6013
+ return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
6014
+ }
6015
+
6016
+ /**
6017
+ * Add the actual install sync function to the cron job hook.
6018
+ *
6019
+ * @author Vova Feldman (@svovaf)
6020
+ * @since 1.1.7.3
6021
+ */
6022
+ private function hook_callback_to_install_sync() {
6023
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
6024
+ }
6025
+
6026
+ /**
6027
+ * @author Vova Feldman (@svovaf)
6028
+ * @since 1.1.7.3
6029
+ *
6030
+ * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
6031
+ */
6032
+ private function clear_install_sync_cron( $is_network_clear = false ) {
6033
+ $this->_logger->entrance();
6034
+
6035
+ $this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
6036
+ }
6037
+
6038
+ /**
6039
+ * @author Vova Feldman (@svovaf)
6040
+ * @since 1.1.7.3
6041
+ * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
6042
+ */
6043
+ public function _run_sync_install() {
6044
+ $this->_logger->entrance();
6045
+
6046
+ $this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
6047
+ }
6048
+
6049
+ /**
6050
+ * The actual install(s) sync cron logic.
6051
+ *
6052
+ * @author Vova Feldman (@svovaf)
6053
+ * @since 2.0.0
6054
+ *
6055
+ * @param int[] $blog_ids
6056
+ */
6057
+ function _sync_install_cron_method( array $blog_ids ) {
6058
+ if ( $this->is_registered() ) {
6059
+ if ( 1 < count( $blog_ids ) ) {
6060
+ $this->sync_installs( array(), true );
6061
+ } else {
6062
+ $this->sync_install( array(), true );
6063
+ }
6064
+ }
6065
+ }
6066
+
6067
+ #endregion Async Install Sync ------------------------------------------------------------------
6068
+
6069
+ /**
6070
+ * Show a notice that activation is currently pending.
6071
+ *
6072
+ * @author Vova Feldman (@svovaf)
6073
+ * @since 1.0.7
6074
+ *
6075
+ * @param bool|string $email
6076
+ * @param bool $is_pending_trial Since 1.2.1.5
6077
+ */
6078
+ function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
6079
+ if ( ! is_string( $email ) ) {
6080
+ $current_user = self::_get_current_wp_user();
6081
+ $email = $current_user->user_email;
6082
+ }
6083
+
6084
+ $this->_admin_notices->add_sticky(
6085
+ sprintf(
6086
+ $this->get_text_inline( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s.', 'pending-activation-message' ),
6087
+ '<b>' . $this->get_plugin_name() . '</b>',
6088
+ '<b>' . $email . '</b>',
6089
+ ( $is_pending_trial ?
6090
+ $this->get_text_inline( 'start the trial', 'start-the-trial' ) :
6091
+ $this->get_text_inline( 'complete the install', 'complete-the-install' ) )
6092
+ ),
6093
+ 'activation_pending',
6094
+ 'Thanks!'
6095
+ );
6096
+ }
6097
+
6098
+ /**
6099
+ * Check if currently in plugin activation.
6100
+ *
6101
+ * @author Vova Feldman (@svovaf)
6102
+ * @since 1.1.4
6103
+ *
6104
+ * @return bool
6105
+ */
6106
+ function is_plugin_activation() {
6107
+ $result = get_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
6108
+
6109
+ return !empty($result);
6110
+ }
6111
+
6112
+ /**
6113
+ *
6114
+ * NOTE: admin_menu action executed before admin_init.
6115
+ *
6116
+ * @author Vova Feldman (@svovaf)
6117
+ * @since 1.0.7
6118
+ */
6119
+ function _admin_init_action() {
6120
+ /**
6121
+ * Automatically redirect to connect/activation page after plugin activation.
6122
+ *
6123
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
6124
+ */
6125
+ if ( $this->is_plugin_activation() ) {
6126
+ delete_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
6127
+
6128
+ if ( isset( $_GET['activate-multi'] ) ) {
6129
+ /**
6130
+ * Don't redirect if activating multiple plugins at once (bulk activation).
6131
+ */
6132
+ } else {
6133
+ $this->_redirect_on_activation_hook();
6134
+ return;
6135
+ }
6136
+ }
6137
+
6138
+ if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
6139
+ check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
6140
+
6141
+ $this->skip_connection( null, fs_is_network_admin() );
6142
+
6143
+ fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
6144
+ }
6145
+
6146
+ if ( $this->is_network_activation_mode() &&
6147
+ fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
6148
+ ) {
6149
+ check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
6150
+
6151
+ $this->delegate_connection();
6152
+
6153
+ fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
6154
+ }
6155
+
6156
+ $this->_add_upgrade_action_link();
6157
+
6158
+ if ( ! $this->is_addon() &&
6159
+ ! ( ! $this->_is_network_active && fs_is_network_admin() ) &&
6160
+ (
6161
+ // Not registered nor anonymous.
6162
+ ( ! $this->is_registered() && ! $this->is_anonymous() ) ||
6163
+ // OR, network level and in network upgrade mode.
6164
+ ( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
6165
+ )
6166
+ ) {
6167
+ if ( ! $this->is_pending_activation() ) {
6168
+ if ( ! $this->_menu->is_main_settings_page() ) {
6169
+ /**
6170
+ * If a user visits any other admin page before activating the premium-only theme with a valid
6171
+ * license, reactivate the previous theme.
6172
+ *
6173
+ * @author Leo Fajardo (@leorw)
6174
+ * @since 1.2.2
6175
+ */
6176
+ if ( $this->is_theme()
6177
+ && $this->is_only_premium()
6178
+ && ! $this->has_settings_menu()
6179
+ && ! isset( $_REQUEST['fs_action'] )
6180
+ && $this->can_activate_previous_theme()
6181
+ ) {
6182
+ $this->activate_previous_theme();
6183
+
6184
+ return;
6185
+ }
6186
+
6187
+ if ( ! fs_is_network_admin() &&
6188
+ $this->is_network_activation_mode() &&
6189
+ ! $this->is_delegated_connection()
6190
+ ) {
6191
+ return;
6192
+ }
6193
+
6194
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
6195
+ // Show notice for new plugin installations.
6196
+ $this->_admin_notices->add(
6197
+ sprintf(
6198
+ $this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
6199
+ sprintf( '<b><a href="%s">%s</a></b>',
6200
+ $this->get_activation_url( array(), ! $this->is_delegated_connection() ),
6201
+ sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
6202
+ '%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
6203
+ )
6204
+ ),
6205
+ '',
6206
+ 'update-nag'
6207
+ );
6208
+ } else {
6209
+ if ( $this->should_add_sticky_optin_notice() ) {
6210
+ $this->add_sticky_optin_admin_notice();
6211
+ }
6212
+
6213
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
6214
+ // Don't show admin nag if plugin update.
6215
+ wp_enqueue_script( 'wp-pointer' );
6216
+ wp_enqueue_style( 'wp-pointer' );
6217
+
6218
+ $this->_enqueue_connect_essentials();
6219
+
6220
+ add_action( 'admin_print_footer_scripts', array(
6221
+ $this,
6222
+ '_add_connect_pointer_script'
6223
+ ) );
6224
+ }
6225
+ }
6226
+ }
6227
+ }
6228
+
6229
+ if ( $this->is_theme() &&
6230
+ $this->_menu->is_main_settings_page()
6231
+ ) {
6232
+ $this->_show_theme_activation_optin_dialog();
6233
+ }
6234
+ }
6235
+ }
6236
+
6237
+ /**
6238
+ * @author Vova Feldman (@svovaf)
6239
+ * @since 2.0.0
6240
+ *
6241
+ * @return bool
6242
+ */
6243
+ private function should_add_sticky_optin_notice() {
6244
+ if ( fs_is_network_admin() ) {
6245
+ if ( ! $this->_is_network_active ) {
6246
+ return false;
6247
+ }
6248
+
6249
+ if ( ! $this->is_network_activation_mode() ) {
6250
+ return false;
6251
+ }
6252
+
6253
+ return ! isset( $this->_storage->sticky_optin_added_ms );
6254
+ }
6255
+
6256
+ if ( ! $this->is_activation_mode() ) {
6257
+ return false;
6258
+ }
6259
+
6260
+ // If running from a blog admin and delegated the connection.
6261
+ return ! isset( $this->_storage->sticky_optin_added );
6262
+ }
6263
+
6264
+ /**
6265
+ * @author Leo Fajardo (@leorw)
6266
+ * @since 2.0.0
6267
+ */
6268
+ private function add_sticky_optin_admin_notice() {
6269
+ if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
6270
+ $this->_storage->sticky_optin_added = true;
6271
+ } else {
6272
+ $this->_storage->sticky_optin_added_ms = true;
6273
+ }
6274
+
6275
+ // Show notice for new plugin installations.
6276
+ $this->_admin_notices->add_sticky(
6277
+ sprintf(
6278
+ $this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
6279
+ $this->_module_type,
6280
+ sprintf( '<b><a href="%s">%s</a></b>',
6281
+ $this->get_activation_url(),
6282
+ sprintf( $this->get_text_inline( 'Opt in to make "%s" Better!', 'optin-x-now' ), $this->get_plugin_name() )
6283
+ )
6284
+ ),
6285
+ 'connect_account',
6286
+ '',
6287
+ 'update-nag'
6288
+ );
6289
+ }
6290
+
6291
+ /**
6292
+ * Enqueue connect requires scripts and styles.
6293
+ *
6294
+ * @author Vova Feldman (@svovaf)
6295
+ * @since 1.1.4
6296
+ */
6297
+ function _enqueue_connect_essentials() {
6298
+ wp_enqueue_script( 'jquery' );
6299
+ wp_enqueue_script( 'json2' );
6300
+
6301
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
6302
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
6303
+
6304
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
6305
+ }
6306
+
6307
+ /**
6308
+ * Add connect / opt-in pointer.
6309
+ *
6310
+ * @author Vova Feldman (@svovaf)
6311
+ * @since 1.1.4
6312
+ */
6313
+ function _add_connect_pointer_script() {
6314
+ $vars = array( 'id' => $this->_module_id );
6315
+ $pointer_content = fs_get_template( 'connect.php', $vars );
6316
+ ?>
6317
+ <script type="text/javascript">// <![CDATA[
6318
+ jQuery(document).ready(function ($) {
6319
+ if ('undefined' !== typeof(jQuery().pointer)) {
6320
+
6321
+ var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
6322
+
6323
+ if (element.length > 0) {
6324
+ var optin = $(element).pointer($.extend(true, {}, {
6325
+ content : <?php echo json_encode( $pointer_content ) ?>,
6326
+ position : {
6327
+ edge : 'left',
6328
+ align: 'center'
6329
+ },
6330
+ buttons : function () {
6331
+ // Don't show pointer buttons.
6332
+ return '';
6333
+ },
6334
+ pointerWidth: 482
6335
+ }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
6336
+
6337
+ <?php
6338
+ echo $this->apply_filters( 'optin_pointer_execute', "
6339
+
6340
+ optin.pointer('open');
6341
+
6342
+ // Tag the opt-in pointer with custom class.
6343
+ $('.wp-pointer #fs_connect')
6344
+ .parents('.wp-pointer.wp-pointer-top')
6345
+ .addClass('fs-opt-in-pointer');
6346
+
6347
+ ", 'element', 'optin' ) ?>
6348
+ }
6349
+ }
6350
+ });
6351
+ // ]]></script>
6352
+ <?php
6353
+ }
6354
+
6355
+ /**
6356
+ * Return current page's URL.
6357
+ *
6358
+ * @author Vova Feldman (@svovaf)
6359
+ * @since 1.0.7
6360
+ *
6361
+ * @return string
6362
+ */
6363
+ function current_page_url() {
6364
+ $url = 'http';
6365
+
6366
+ if ( isset( $_SERVER["HTTPS"] ) ) {
6367
+ if ( $_SERVER["HTTPS"] == "on" ) {
6368
+ $url .= "s";
6369
+ }
6370
+ }
6371
+ $url .= "://";
6372
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
6373
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
6374
+ } else {
6375
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
6376
+ }
6377
+
6378
+ return esc_url( $url );
6379
+ }
6380
+
6381
+ /**
6382
+ * Check if the current page is the plugin's main admin settings page.
6383
+ *
6384
+ * @author Vova Feldman (@svovaf)
6385
+ * @since 1.0.7
6386
+ *
6387
+ * @return bool
6388
+ */
6389
+ function _is_plugin_page() {
6390
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
6391
+ fs_is_plugin_page( $this->_slug );
6392
+ }
6393
+
6394
+ /* Events
6395
+ ------------------------------------------------------------------------------------------------------------------*/
6396
+ /**
6397
+ * Delete site install from Database.
6398
+ *
6399
+ * @author Vova Feldman (@svovaf)
6400
+ * @since 1.0.1
6401
+ *
6402
+ * @param bool $store
6403
+ * @param int|null $blog_id Since 2.0.0
6404
+ *
6405
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
6406
+ */
6407
+ function _delete_site( $store = true, $blog_id = null ) {
6408
+ return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
6409
+ }
6410
+
6411
+ /**
6412
+ * Delete site install from Database.
6413
+ *
6414
+ * @author Vova Feldman (@svovaf)
6415
+ * @since 1.2.2.7
6416
+ *
6417
+ * @param string $slug
6418
+ * @param string $module_type
6419
+ * @param bool $store
6420
+ * @param int|null $blog_id Since 2.0.0
6421
+ *
6422
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
6423
+ */
6424
+ static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
6425
+ $sites = self::get_all_sites( $module_type, $blog_id );
6426
+
6427
+ $install_id = false;
6428
+
6429
+ if ( isset( $sites[ $slug ] ) ) {
6430
+ if ( is_object( $sites[ $slug ] ) ) {
6431
+ $install_id = $sites[ $slug ]->id;
6432
+ }
6433
+
6434
+ unset( $sites[ $slug ] );
6435
+
6436
+ self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
6437
+ }
6438
+
6439
+ return $install_id;
6440
+ }
6441
+
6442
+ /**
6443
+ * Delete user.
6444
+ *
6445
+ * @author Vova Feldman (@svovaf)
6446
+ * @since 2.0.0
6447
+ *
6448
+ * @param number $user_id
6449
+ * @param bool $store
6450
+ *
6451
+ * @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
6452
+ */
6453
+ private static function delete_user( $user_id, $store = true ) {
6454
+ $users = self::get_all_users();
6455
+
6456
+ if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
6457
+ return false;
6458
+ }
6459
+
6460
+ unset( $users[ $user_id ] );
6461
+
6462
+ self::$_accounts->set_option( 'users', $users, $store );
6463
+
6464
+ return $user_id;
6465
+ }
6466
+
6467
+ /**
6468
+ * Delete plugin's plans information.
6469
+ *
6470
+ * @param bool $store Flush to Database if true.
6471
+ * @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
6472
+ *
6473
+ * @author Vova Feldman (@svovaf)
6474
+ * @since 1.0.9
6475
+ */
6476
+ private function _delete_plans( $store = true, $keep_associated_plans = true ) {
6477
+ $this->_logger->entrance();
6478
+
6479
+ $plans = self::get_all_plans( $this->_module_type );
6480
+
6481
+ $plans_to_keep = array();
6482
+
6483
+ if ( $keep_associated_plans ) {
6484
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
6485
+ foreach ( $plans_ids_to_keep as $plan_id ) {
6486
+ $plan = self::_get_plan_by_id( $plan_id );
6487
+ if ( is_object( $plan ) ) {
6488
+ $plans_to_keep[] = $plan;
6489
+ }
6490
+ }
6491
+ }
6492
+
6493
+ if ( ! empty( $plans_to_keep ) ) {
6494
+ $plans[ $this->_slug ] = $plans_to_keep;
6495
+ } else {
6496
+ unset( $plans[ $this->_slug ] );
6497
+ }
6498
+
6499
+ $this->set_account_option( 'plans', $plans, $store );
6500
+ }
6501
+
6502
+ /**
6503
+ * Delete all plugin licenses.
6504
+ *
6505
+ * @author Vova Feldman (@svovaf)
6506
+ * @since 1.0.9
6507
+ *
6508
+ * @param bool $store
6509
+ */
6510
+ private function _delete_licenses( $store = true ) {
6511
+ $this->_logger->entrance();
6512
+
6513
+ $all_licenses = self::get_all_licenses();
6514
+
6515
+ unset( $all_licenses[ $this->_module_id ] );
6516
+
6517
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
6518
+ }
6519
+
6520
+ /**
6521
+ * Check if Freemius was added on new plugin installation.
6522
+ *
6523
+ * @author Vova Feldman (@svovaf)
6524
+ * @since 1.1.5
6525
+ *
6526
+ * @return bool
6527
+ */
6528
+ function is_plugin_new_install() {
6529
+ return isset( $this->_storage->is_plugin_new_install ) &&
6530
+ $this->_storage->is_plugin_new_install;
6531
+ }
6532
+
6533
+ /**
6534
+ * Check if it's the first plugin release that is running Freemius.
6535
+ *
6536
+ * @author Vova Feldman (@svovaf)
6537
+ * @since 1.2.1.5
6538
+ *
6539
+ * @return bool
6540
+ */
6541
+ function is_first_freemius_powered_version() {
6542
+ return empty( $this->_storage->plugin_last_version );
6543
+ }
6544
+
6545
+ /**
6546
+ * @author Leo Fajardo (@leorw)
6547
+ * @since 1.2.2
6548
+ *
6549
+ * @return bool|string
6550
+ */
6551
+ private function get_previous_theme_slug() {
6552
+ return isset( $this->_storage->previous_theme ) ?
6553
+ $this->_storage->previous_theme :
6554
+ false;
6555
+ }
6556
+
6557
+ /**
6558
+ * @author Leo Fajardo (@leorw)
6559
+ * @since 1.2.2
6560
+ *
6561
+ * @return string
6562
+ */
6563
+ private function can_activate_previous_theme() {
6564
+ $slug = $this->get_previous_theme_slug();
6565
+ if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
6566
+ $theme_instance = wp_get_theme( $slug );
6567
+
6568
+ return $theme_instance->exists();
6569
+ }
6570
+
6571
+ return false;
6572
+ }
6573
+
6574
+ /**
6575
+ * @author Leo Fajardo (@leorw)
6576
+ * @since 1.2.2
6577
+ */
6578
+ private function activate_previous_theme() {
6579
+ switch_theme( $this->get_previous_theme_slug() );
6580
+ unset( $this->_storage->previous_theme );
6581
+
6582
+ global $pagenow;
6583
+ if ( 'themes.php' === $pagenow ) {
6584
+ /**
6585
+ * Refresh the active theme information.
6586
+ *
6587
+ * @author Leo Fajardo (@leorw)
6588
+ * @since 1.2.2
6589
+ */
6590
+ fs_redirect( $this->admin_url( $pagenow ) );
6591
+ }
6592
+ }
6593
+
6594
+ /**
6595
+ * @author Leo Fajardo (@leorw)
6596
+ * @since 1.2.2
6597
+ *
6598
+ * @return string
6599
+ */
6600
+ function get_previous_theme_activation_url() {
6601
+ if ( ! $this->can_activate_previous_theme() ) {
6602
+ return '';
6603
+ }
6604
+
6605
+ /**
6606
+ * Activation URL
6607
+ *
6608
+ * @author Leo Fajardo (@leorw)
6609
+ * @since 1.2.2
6610
+ */
6611
+ return wp_nonce_url(
6612
+ $this->admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
6613
+ 'switch-theme_' . $this->get_previous_theme_slug()
6614
+ );
6615
+ }
6616
+
6617
+ /**
6618
+ * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
6619
+ * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
6620
+ * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
6621
+ * theme doesn't exist, then there will be no close button.
6622
+ *
6623
+ * @author Leo Fajardo (@leorw)
6624
+ * @since 1.2.2
6625
+ *
6626
+ * @param string $slug_or_name Old theme's slug or name.
6627
+ * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
6628
+ */
6629
+ function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
6630
+ $this->_storage->previous_theme = ( false !== $old_theme ) ?
6631
+ $old_theme->get_stylesheet() :
6632
+ $slug_or_name;
6633
+
6634
+ $this->_activate_plugin_event_hook();
6635
+ }
6636
+
6637
+ /**
6638
+ * Plugin activated hook.
6639
+ *
6640
+ * @author Vova Feldman (@svovaf)
6641
+ * @since 1.0.1
6642
+ *
6643
+ * @uses FS_Api
6644
+ */
6645
+ function _activate_plugin_event_hook() {
6646
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6647
+
6648
+ if ( ! $this->is_user_admin() ) {
6649
+ return;
6650
+ }
6651
+
6652
+ $this->unregister_uninstall_hook();
6653
+
6654
+ // Clear API cache on activation.
6655
+ FS_Api::clear_cache();
6656
+
6657
+ $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );
6658
+
6659
+ $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
6660
+
6661
+ // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
6662
+ // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
6663
+ $other_version_basename = $is_premium_version_activation ?
6664
+ $this->_free_plugin_basename :
6665
+ $this->premium_plugin_basename();
6666
+
6667
+ if ( ! $this->_is_network_active ) {
6668
+ /**
6669
+ * During the activation, the plugin isn't yet active, therefore,
6670
+ * _is_network_active will be set to false even if it's a network level
6671
+ * activation. So we need to fix that by looking at the is_network_admin() value.
6672
+ *
6673
+ * @author Vova Feldman
6674
+ */
6675
+ $this->_is_network_active = (
6676
+ $this->_is_multisite_integrated &&
6677
+ // Themes are always network activated, but the ACTUAL activation is per site.
6678
+ $this->is_plugin() &&
6679
+ fs_is_network_admin()
6680
+ );
6681
+ }
6682
+
6683
+ /**
6684
+ * If the other module version is activate, deactivate it.
6685
+ *
6686
+ * is_plugin_active() checks if the plugin active on the site or the network level
6687
+ * and deactivate_plugins() deactivates the plugin whether its activated on the site
6688
+ * or network level.
6689
+ *
6690
+ * @author Leo Fajardo (@leorw)
6691
+ * @since 1.2.2
6692
+ */
6693
+ if ( is_plugin_active( $other_version_basename ) ) {
6694
+ deactivate_plugins( $other_version_basename );
6695
+ }
6696
+
6697
+ if ( $this->is_registered() ) {
6698
+ if ( $is_premium_version_activation ) {
6699
+ $this->reconnect_locally();
6700
+ }
6701
+
6702
+
6703
+ // Schedule re-activation event and sync.
6704
+ // $this->sync_install( array(), true );
6705
+ $this->schedule_install_sync();
6706
+
6707
+ // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
6708
+ if ( $is_premium_version_activation ) {
6709
+ $this->_admin_notices->add(
6710
+ sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
6711
+ $this->get_text_x_inline( 'W00t',
6712
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
6713
+ );
6714
+ }
6715
+ } else if ( $this->is_anonymous() ) {
6716
+ if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
6717
+ $plugin_version = $this->_storage->is_anonymous_ms['version'];
6718
+ $network = true;
6719
+ } else {
6720
+ $plugin_version = $this->_storage->is_anonymous['version'];
6721
+ $network = false;
6722
+ }
6723
+
6724
+ /**
6725
+ * Reset "skipped" click cache on the following:
6726
+ * 1. Freemius DEV mode.
6727
+ * 2. WordPress DEBUG mode.
6728
+ * 3. If a plugin and the user skipped the exact same version before.
6729
+ *
6730
+ * @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
6731
+ *
6732
+ * @todo 4. If explicitly asked to retry after every activation.
6733
+ */
6734
+ if ( WP_FS__DEV_MODE ||
6735
+ (
6736
+ ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
6737
+ $this->get_plugin_version() == $plugin_version
6738
+ )
6739
+ ) {
6740
+ $this->reset_anonymous_mode( $network );
6741
+ }
6742
+ }
6743
+
6744
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
6745
+ /**
6746
+ * If no previous version of plugin's version exist, it means that it's either
6747
+ * the first time that the plugin installed on the site, or the plugin was installed
6748
+ * before but didn't have Freemius integrated.
6749
+ *
6750
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
6751
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
6752
+ * only after immediate activation.
6753
+ *
6754
+ * @since 1.1.4
6755
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
6756
+ */
6757
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
6758
+ }
6759
+
6760
+ if ( ! $this->_anonymous_mode &&
6761
+ $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
6762
+ ! $this->_isAutoInstall
6763
+ ) {
6764
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
6765
+ set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
6766
+ }
6767
+
6768
+ /**
6769
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
6770
+ * after the plugin was loaded. The logic is located at activate_plugin()
6771
+ * ./wp-admin/includes/plugin.php.
6772
+ *
6773
+ * @author Vova Feldman (@svovaf)
6774
+ * @since 1.1.9
6775
+ */
6776
+ $this->_storage->was_plugin_loaded = true;
6777
+ }
6778
+
6779
+ /**
6780
+ * Delete account.
6781
+ *
6782
+ * @author Vova Feldman (@svovaf)
6783
+ * @since 1.0.3
6784
+ *
6785
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
6786
+ */
6787
+ function delete_account_event( $check_user = true ) {
6788
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6789
+
6790
+ if ( $check_user && ! $this->is_user_admin() ) {
6791
+ return;
6792
+ }
6793
+
6794
+ $this->do_action( 'before_account_delete' );
6795
+
6796
+ // Clear all admin notices.
6797
+ $this->_admin_notices->clear_all_sticky( false );
6798
+
6799
+ $this->_delete_site( false );
6800
+
6801
+ $delete_network_common_data = true;
6802
+
6803
+ if ( $this->_is_network_active ) {
6804
+ $installs = $this->get_blog_install_map();
6805
+
6806
+ // Don't delete common network data unless no other installs left.
6807
+ $delete_network_common_data = empty( $installs );
6808
+ }
6809
+
6810
+ if ( $delete_network_common_data ) {
6811
+ $this->_delete_plans( false );
6812
+
6813
+ $this->_delete_licenses( false );
6814
+
6815
+ // Delete add-ons related to plugin's account.
6816
+ $this->_delete_account_addons( false );
6817
+ }
6818
+
6819
+ // @todo Delete plans and licenses of add-ons.
6820
+
6821
+ self::$_accounts->store();
6822
+
6823
+ /**
6824
+ * IMPORTANT:
6825
+ * Clear crons must be executed before clearing all storage.
6826
+ * Otherwise, the cron will not be cleared.
6827
+ */
6828
+ if ( $delete_network_common_data ) {
6829
+ $this->clear_sync_cron();
6830
+ }
6831
+
6832
+ $this->clear_install_sync_cron();
6833
+
6834
+ // Clear all storage data.
6835
+ $this->_storage->clear_all( true, array(
6836
+ 'connectivity_test',
6837
+ 'is_on',
6838
+ ), false );
6839
+
6840
+ // Send delete event.
6841
+ $this->get_api_site_scope()->call( '/', 'delete' );
6842
+
6843
+ $this->do_action( 'after_account_delete' );
6844
+ }
6845
+
6846
+ /**
6847
+ * Delete network level account.
6848
+ *
6849
+ * @author Vova Feldman (@svovaf)
6850
+ * @since 2.0.0
6851
+ *
6852
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
6853
+ */
6854
+ function delete_network_account_event( $check_user = true ) {
6855
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6856
+
6857
+ if ( $check_user && ! $this->is_user_admin() ) {
6858
+ return;
6859
+ }
6860
+
6861
+ $this->do_action( 'before_network_account_delete' );
6862
+
6863
+ // Clear all admin notices.
6864
+ $this->_admin_notices->clear_all_sticky();
6865
+
6866
+ $this->_delete_plans( false, false );
6867
+
6868
+ $this->_delete_licenses( false );
6869
+
6870
+ // Delete add-ons related to plugin's account.
6871
+ $this->_delete_account_addons( false );
6872
+
6873
+ // @todo Delete plans and licenses of add-ons.
6874
+
6875
+ self::$_accounts->store( true );
6876
+
6877
+ /**
6878
+ * IMPORTANT:
6879
+ * Clear crons must be executed before clearing all storage.
6880
+ * Otherwise, the cron will not be cleared.
6881
+ */
6882
+ $this->clear_sync_cron( true );
6883
+ $this->clear_install_sync_cron( true );
6884
+
6885
+ $sites = self::get_sites();
6886
+
6887
+ $install_ids = array();
6888
+ foreach ( $sites as $site ) {
6889
+ $blog_id = self::get_site_blog_id( $site );
6890
+
6891
+ $install_id = $this->_delete_site( true, $blog_id );
6892
+
6893
+ // Clear all storage data.
6894
+ $this->_storage->clear_all( true, array( 'connectivity_test' ), $blog_id );
6895
+
6896
+ if ( FS_Site::is_valid_id( $install_id ) ) {
6897
+ $install_ids[] = $install_id;
6898
+ }
6899
+
6900
+ switch_to_blog( $blog_id );
6901
+
6902
+ $this->do_action( 'after_account_delete' );
6903
+
6904
+ restore_current_blog();
6905
+ }
6906
+
6907
+ $this->_storage->clear_all( true, array(
6908
+ 'connectivity_test',
6909
+ 'is_on',
6910
+ ), true );
6911
+
6912
+ // Send delete event.
6913
+ if ( ! empty( $install_ids ) ) {
6914
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', $install_ids ), 'delete' );
6915
+ }
6916
+
6917
+ $this->do_action( 'after_network_account_delete' );
6918
+ }
6919
+
6920
+ /**
6921
+ * Plugin deactivation hook.
6922
+ *
6923
+ * @author Vova Feldman (@svovaf)
6924
+ * @since 1.0.1
6925
+ */
6926
+ function _deactivate_plugin_hook() {
6927
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6928
+
6929
+ if ( ! $this->is_user_admin() ) {
6930
+ return;
6931
+ }
6932
+
6933
+ $is_network_deactivation = fs_is_network_admin();
6934
+ $storage_keys_for_removal = array();
6935
+
6936
+ $this->_admin_notices->clear_all_sticky();
6937
+
6938
+ $storage_keys_for_removal[] = 'sticky_optin_added';
6939
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
6940
+ unset( $this->_storage->sticky_optin_added );
6941
+ }
6942
+
6943
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
6944
+ // Remember that plugin was already installed.
6945
+ $this->_storage->is_plugin_new_install = false;
6946
+ }
6947
+
6948
+ // Hook to plugin uninstall.
6949
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
6950
+
6951
+ $this->clear_module_main_file_cache();
6952
+ $this->clear_sync_cron( $this->_is_network_active );
6953
+ $this->clear_install_sync_cron();
6954
+
6955
+ if ( $this->is_registered() ) {
6956
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
6957
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
6958
+ }
6959
+
6960
+ if ( $is_network_deactivation ) {
6961
+ // Send deactivation event.
6962
+ $this->sync_installs( array(
6963
+ 'is_active' => false,
6964
+ ) );
6965
+ } else {
6966
+ // Send deactivation event.
6967
+ $this->sync_install( array(
6968
+ 'is_active' => false,
6969
+ ) );
6970
+ }
6971
+ } else {
6972
+ if ( ! $this->has_api_connectivity() ) {
6973
+ // Reset connectivity test cache.
6974
+ unset( $this->_storage->connectivity_test );
6975
+
6976
+ $storage_keys_for_removal[] = 'connectivity_test';
6977
+ }
6978
+ }
6979
+
6980
+ if ( $is_network_deactivation ) {
6981
+ if ( isset( $this->_storage->sticky_optin_added_ms ) ) {
6982
+ unset( $this->_storage->sticky_optin_added_ms );
6983
+ }
6984
+
6985
+ if ( ! empty( $storage_keys_for_removal ) ) {
6986
+ $sites = self::get_sites();
6987
+
6988
+ foreach ( $sites as $site ) {
6989
+ $blog_id = self::get_site_blog_id( $site );
6990
+
6991
+ foreach ( $storage_keys_for_removal as $key ) {
6992
+ $this->_storage->remove( $key, false, $blog_id );
6993
+ }
6994
+
6995
+ $this->_storage->save( $blog_id );
6996
+ }
6997
+ }
6998
+ }
6999
+
7000
+ // Clear API cache on deactivation.
7001
+ FS_Api::clear_cache();
7002
+
7003
+ $this->remove_sdk_reference();
7004
+ }
7005
+
7006
+ /**
7007
+ * @author Vova Feldman (@svovaf)
7008
+ * @since 1.1.6
7009
+ */
7010
+ private function remove_sdk_reference() {
7011
+ global $fs_active_plugins;
7012
+
7013
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
7014
+ if ( $this->_plugin_basename == $data->plugin_path ) {
7015
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
7016
+ break;
7017
+ }
7018
+ }
7019
+
7020
+ fs_fallback_to_newest_active_sdk();
7021
+ }
7022
+
7023
+ /**
7024
+ * @author Vova Feldman (@svovaf)
7025
+ * @since 1.1.3
7026
+ *
7027
+ * @param bool $is_anonymous
7028
+ * @param bool|int $network_or_blog_id Since 2.0.0
7029
+ */
7030
+ private function set_anonymous_mode( $is_anonymous = true, $network_or_blog_id = 0 ) {
7031
+ // Store information regarding skip to try and opt-in the user
7032
+ // again in the future.
7033
+ $skip_info = array(
7034
+ 'is' => $is_anonymous,
7035
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
7036
+ 'version' => $this->get_plugin_version(),
7037
+ );
7038
+
7039
+ if ( true === $network_or_blog_id ) {
7040
+ $this->_storage->is_anonymous_ms = $skip_info;
7041
+ } else {
7042
+ $this->_storage->store( 'is_anonymous', $skip_info, $network_or_blog_id );
7043
+ }
7044
+
7045
+ $this->network_upgrade_mode_completed();
7046
+
7047
+ // Update anonymous mode cache.
7048
+ $this->_is_anonymous = $is_anonymous;
7049
+ }
7050
+
7051
+ /**
7052
+ * @author Vova Feldman (@svovaf)
7053
+ * @since 2.0.0
7054
+ *
7055
+ * @param int $blog_id Site ID.
7056
+ * @param int $user_id User ID.
7057
+ * @param string $domain Site domain.
7058
+ * @param string $path Site path.
7059
+ * @param int $network_id Network ID. Only relevant on multi-network installations.
7060
+ * @param array $meta Metadata. Used to set initial site options.
7061
+ *
7062
+ * @uses Freemius::is_license_network_active() to check if the context license was network activated by the super-admin.
7063
+ * @uses Freemius::is_network_connected() to check if the super-admin network opted-in.
7064
+ * @uses Freemius::is_network_anonymous() to check if the super-admin network skipped.
7065
+ * @uses Freemius::is_network_delegated_connection() to check if the super-admin network delegated the connection to the site admins.
7066
+ */
7067
+ function _after_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
7068
+ $this->_logger->entrance();
7069
+
7070
+ if ( $this->is_premium() &&
7071
+ $this->is_network_connected() &&
7072
+ is_object( $this->_license ) &&
7073
+ $this->_license->can_activate( FS_Site::is_localhost_by_address( $domain ) ) &&
7074
+ $this->is_license_network_active( $blog_id )
7075
+ ) {
7076
+ /**
7077
+ * Running the premium version, the license was network activated, and the license can also be activated on the current site -> so try to opt-in with the license key.
7078
+ */
7079
+ $current_blog_id = get_current_blog_id();
7080
+ $license = clone $this->_license;
7081
+
7082
+ $this->switch_to_blog( $blog_id );
7083
+
7084
+ // Opt-in with network user.
7085
+ $this->install_with_user(
7086
+ $this->get_network_user(),
7087
+ $license->secret_key,
7088
+ false,
7089
+ false,
7090
+ false
7091
+ );
7092
+
7093
+ if ( is_object( $this->_site ) ) {
7094
+ if ( $this->_site->license_id == $license->id ) {
7095
+ /**
7096
+ * If the license was activated successfully, sync the license data from the remote server.
7097
+ */
7098
+ $this->_license = $license;
7099
+ $this->sync_site_license();
7100
+ }
7101
+ }
7102
+
7103
+ $this->switch_to_blog( $current_blog_id );
7104
+
7105
+ if ( is_object( $this->_site ) ) {
7106
+ // Already connected (with or without a license), so no need to continue.
7107
+ return;
7108
+ }
7109
+ }
7110
+
7111
+ if ( $this->is_network_anonymous() ) {
7112
+ /**
7113
+ * Opt-in was network skipped so automatically skip the opt-in for the new site.
7114
+ */
7115
+ $this->skip_site_connection( $blog_id );
7116
+ } else if ( $this->is_network_delegated_connection() ) {
7117
+ /**
7118
+ * Opt-in was network delegated so automatically delegate the opt-in for the new site's admin.
7119
+ */
7120
+ $this->delegate_site_connection( $blog_id );
7121
+ } else if ( $this->is_network_connected() ) {
7122
+ /**
7123
+ * Opt-in was network activated so automatically opt-in with the network user and new site admin.
7124
+ */
7125
+ $current_blog_id = get_current_blog_id();
7126
+
7127
+ $this->switch_to_blog( $blog_id );
7128
+
7129
+ // Opt-in with network user.
7130
+ $this->install_with_user(
7131
+ $this->get_network_user(),
7132
+ false,
7133
+ false,
7134
+ false,
7135
+ false
7136
+ );
7137
+
7138
+ $this->switch_to_blog( $current_blog_id );
7139
+ } else {
7140
+ /**
7141
+ * If the super-admin mixed different options (connect, skip, delegated):
7142
+ * a) If at least one site connection was delegated, then automatically delegate connection.
7143
+ * b) Otherwise, it means that at least one site was skipped and at least one site was connected. For a simplified UX in the initial release of the multisite network integration, skip the connection for the newly created site. If the super-admin will want to opt-in they can still do that from the network level Account page.
7144
+ */
7145
+ $has_delegated_site = false;
7146
+
7147
+ $sites = self::get_sites();
7148
+ foreach ( $sites as $site ) {
7149
+ $blog_id = self::get_site_blog_id( $site );
7150
+
7151
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
7152
+ $has_delegated_site = true;
7153
+ break;
7154
+ }
7155
+ }
7156
+
7157
+ if ( $has_delegated_site ) {
7158
+ $this->delegate_site_connection( $blog_id );
7159
+ } else {
7160
+ $this->skip_site_connection( $blog_id );
7161
+ }
7162
+ }
7163
+ }
7164
+
7165
+ /**
7166
+ * @author Vova Feldman (@svovaf)
7167
+ * @since 1.1.3
7168
+ *
7169
+ * @param bool|int $network_or_blog_id Since 2.0.0.
7170
+ */
7171
+ private function reset_anonymous_mode( $network_or_blog_id = 0 ) {
7172
+ if ( true === $network_or_blog_id ) {
7173
+ unset( $this->_storage->is_anonymous_ms );
7174
+ } else {
7175
+ $this->_storage->remove( 'is_anonymous', true, $network_or_blog_id );
7176
+ }
7177
+
7178
+ /**
7179
+ * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
7180
+ * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
7181
+ * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
7182
+ *
7183
+ * @author Leo Fajardo (@leorw)
7184
+ * @since 1.2.2
7185
+ */
7186
+ if ( ! $this->_is_network_active ||
7187
+ 0 === $network_or_blog_id ||
7188
+ get_current_blog_id() == $network_or_blog_id ||
7189
+ ( true === $network_or_blog_id && fs_is_network_admin() )
7190
+ ) {
7191
+ unset( $this->_is_anonymous );
7192
+ }
7193
+ }
7194
+
7195
+ /**
7196
+ * Clears the anonymous mode and redirects to the opt-in screen.
7197
+ *
7198
+ * @author Vova Feldman (@svovaf)
7199
+ * @since 1.1.7
7200
+ */
7201
+ function connect_again() {
7202
+ if ( ! $this->is_anonymous() ) {
7203
+ return;
7204
+ }
7205
+
7206
+ $this->reset_anonymous_mode( fs_is_network_admin() );
7207
+
7208
+ fs_redirect( $this->get_activation_url() );
7209
+ }
7210
+
7211
+ /**
7212
+ * Skip account connect, and set anonymous mode.
7213
+ *
7214
+ * @author Vova Feldman (@svovaf)
7215
+ * @since 1.1.1
7216
+ *
7217
+ * @param array|null $sites Since 2.0.0. Specific sites.
7218
+ * @param bool $skip_all_network Since 2.0.0. If true, skip connection for all sites.
7219
+ */
7220
+ function skip_connection( $sites = null, $skip_all_network = false ) {
7221
+ $this->_logger->entrance();
7222
+
7223
+ $this->_admin_notices->remove_sticky( 'connect_account' );
7224
+
7225
+ if ( $skip_all_network ) {
7226
+ $this->set_anonymous_mode( true, true );
7227
+ }
7228
+
7229
+ if ( ! $skip_all_network && empty( $sites ) ) {
7230
+ $this->skip_site_connection();
7231
+ } else {
7232
+ $uids = array();
7233
+
7234
+ if ( $skip_all_network ) {
7235
+ $this->set_anonymous_mode( true, true );
7236
+
7237
+ $sites = self::get_sites();
7238
+ foreach ( $sites as $site ) {
7239
+ $blog_id = self::get_site_blog_id( $site );
7240
+ $this->skip_site_connection( $blog_id, false );
7241
+ $uids[] = $this->get_anonymous_id( $blog_id );
7242
+ }
7243
+ } else if ( ! empty( $sites ) ) {
7244
+ foreach ( $sites as $site ) {
7245
+ $uids[] = $site['uid'];
7246
+ $this->skip_site_connection( $site['blog_id'], false );
7247
+ }
7248
+ }
7249
+
7250
+ // Send anonymous skip event.
7251
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
7252
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
7253
+ 'uids' => $uids,
7254
+ ) );
7255
+ }
7256
+
7257
+ $this->network_upgrade_mode_completed();
7258
+ }
7259
+
7260
+ /**
7261
+ * Skip connection for specific site in the network.
7262
+ *
7263
+ * @author Vova Feldman (@svovaf)
7264
+ * @since 2.0.0
7265
+ *
7266
+ * @param int|null $blog_id
7267
+ * @param bool $send_skip
7268
+ */
7269
+ private function skip_site_connection( $blog_id = null, $send_skip = true ) {
7270
+ $this->_logger->entrance();
7271
+
7272
+ $this->_admin_notices->remove_sticky( 'connect_account', $blog_id );
7273
+
7274
+ $this->set_anonymous_mode( true, $blog_id );
7275
+
7276
+ if ( $send_skip ) {
7277
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
7278
+ 'uids' => array( $this->get_anonymous_id( $blog_id ) ),
7279
+ ) );
7280
+ }
7281
+ }
7282
+
7283
+ /**
7284
+ * Plugin version update hook.
7285
+ *
7286
+ * @author Vova Feldman (@svovaf)
7287
+ * @since 1.0.4
7288
+ */
7289
+ private function update_plugin_version_event() {
7290
+ $this->_logger->entrance();
7291
+
7292
+ if ( ! $this->is_registered() ) {
7293
+ return;
7294
+ }
7295
+
7296
+ $this->schedule_install_sync();
7297
+ // $this->sync_install( array(), true );
7298
+ }
7299
+
7300
+ /**
7301
+ * Generate an MD5 signature of a plugins collection.
7302
+ * This helper methods used to identify changes in a plugins collection.
7303
+ *
7304
+ * @author Vova Feldman (@svovaf)
7305
+ * @since 2.0.0
7306
+ *
7307
+ * @param array [string]array $plugins
7308
+ *
7309
+ * @return string
7310
+ */
7311
+ private function get_plugins_thumbprint( $plugins ) {
7312
+ ksort( $plugins );
7313
+
7314
+ $thumbprint = '';
7315
+ foreach ( $plugins as $basename => $data ) {
7316
+ $thumbprint .= $data['slug'] . ',' .
7317
+ $data['Version'] . ',' .
7318
+ ( $data['is_active'] ? '1' : '0' ) . ';';
7319
+ }
7320
+
7321
+ return md5( $thumbprint );
7322
+ }
7323
+
7324
+ /**
7325
+ * Return a list of modified plugins since the last sync.
7326
+ *
7327
+ * Note:
7328
+ * There's no point to store a plugins counter since even if the number of
7329
+ * plugins didn't change, we still need to check if the versions are all the
7330
+ * same and the activity state is similar.
7331
+ *
7332
+ * @author Vova Feldman (@svovaf)
7333
+ * @since 1.1.8
7334
+ *
7335
+ * @return array|false
7336
+ */
7337
+ private function get_plugins_data_for_api() {
7338
+ // Alias.
7339
+ $site_active_plugins_option_name = 'active_plugins';
7340
+ $network_plugins_option_name = 'all_plugins';
7341
+
7342
+ /**
7343
+ * Collection of all site level active plugins.
7344
+ */
7345
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
7346
+
7347
+ if ( ! is_object( $site_active_plugins_cache ) ) {
7348
+ $site_active_plugins_cache = (object) array(
7349
+ 'timestamp' => '',
7350
+ 'md5' => '',
7351
+ 'plugins' => array(),
7352
+ );
7353
+ }
7354
+
7355
+ $time = time();
7356
+
7357
+ if ( ! empty( $site_active_plugins_cache->timestamp ) &&
7358
+ ( $time - $site_active_plugins_cache->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
7359
+ ) {
7360
+ // Don't send plugin updates if last update was in the past 5 min.
7361
+ return false;
7362
+ }
7363
+
7364
+ // Write timestamp to lock the logic.
7365
+ $site_active_plugins_cache->timestamp = $time;
7366
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
7367
+
7368
+ // Reload options from DB.
7369
+ self::$_accounts->load( true );
7370
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
7371
+
7372
+ if ( $time != $site_active_plugins_cache->timestamp ) {
7373
+ // If timestamp is different, then another thread captured the lock.
7374
+ return false;
7375
+ }
7376
+
7377
+ /**
7378
+ * Collection of all plugins (network level).
7379
+ */
7380
+ $network_plugins_cache = self::$_accounts->get_option( $network_plugins_option_name );
7381
+
7382
+ if ( ! is_object( $network_plugins_cache ) ) {
7383
+ $network_plugins_cache = (object) array(
7384
+ 'timestamp' => '',
7385
+ 'md5' => '',
7386
+ 'plugins' => array(),
7387
+ );
7388
+ }
7389
+
7390
+ // Check if there's a change in plugins.
7391
+ $network_plugins = self::get_network_plugins();
7392
+ $site_active_plugins = self::get_site_active_plugins();
7393
+
7394
+ $network_plugins_thumbprint = $this->get_plugins_thumbprint( $network_plugins );
7395
+ $site_active_plugins_thumbprint = $this->get_plugins_thumbprint( $site_active_plugins );
7396
+
7397
+ // Check if plugins status changed (version or active/inactive).
7398
+ $network_plugins_changed = ( $network_plugins_cache->md5 !== $network_plugins_thumbprint );
7399
+ $site_active_plugins_changed = ( $site_active_plugins_cache->md5 !== $site_active_plugins_thumbprint );
7400
+
7401
+ if ( ! $network_plugins_changed &&
7402
+ ! $site_active_plugins_changed
7403
+ ) {
7404
+ // No changes.
7405
+ return array();
7406
+ }
7407
+
7408
+ $plugins_update_data = array();
7409
+
7410
+ foreach ( $network_plugins_cache->plugins as $basename => $data ) {
7411
+ if ( ! isset( $network_plugins[ $basename ] ) ) {
7412
+ // Plugin uninstalled.
7413
+ $uninstalled_plugin_data = $data;
7414
+ $uninstalled_plugin_data['is_active'] = false;
7415
+ $uninstalled_plugin_data['is_uninstalled'] = true;
7416
+ $plugins_update_data[] = $uninstalled_plugin_data;
7417
+
7418
+ unset( $network_plugins[ $basename ] );
7419
+
7420
+ unset( $network_plugins_cache->plugins[ $basename ] );
7421
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
7422
+
7423
+ continue;
7424
+ }
7425
+
7426
+ $was_active = $data['is_active'] ||
7427
+ ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7428
+ true === $site_active_plugins_cache->plugins[ $basename ]['is_active'] );
7429
+ $is_active = $network_plugins[ $basename ]['is_active'] ||
7430
+ ( isset( $site_active_plugins[ $basename ] ) &&
7431
+ $site_active_plugins[ $basename ]['is_active'] );
7432
+
7433
+ if ( ! isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7434
+ isset( $site_active_plugins[ $basename ] )
7435
+ ) {
7436
+ // Plugin was site level activated.
7437
+ $site_active_plugins_cache->plugins[ $basename ] = $network_plugins[ $basename ];
7438
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
7439
+ } else if ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7440
+ ! isset( $site_active_plugins[ $basename ] )
7441
+ ) {
7442
+ // Plugin was site level deactivated.
7443
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
7444
+ }
7445
+
7446
+ $prev_version = $data['version'];
7447
+ $current_version = $network_plugins[ $basename ]['Version'];
7448
+
7449
+ if ( $was_active !== $is_active || $prev_version !== $current_version ) {
7450
+ // Plugin activated or deactivated, or version changed.
7451
+
7452
+ if ( $was_active !== $is_active ) {
7453
+ if ( $data['is_active'] != $network_plugins[ $basename ]['is_active'] ) {
7454
+ $network_plugins_cache->plugins[ $basename ]['is_active'] = $data['is_active'];
7455
+ }
7456
+ }
7457
+
7458
+ if ( $prev_version !== $current_version ) {
7459
+ $network_plugins_cache->plugins[ $basename ]['Version'] = $current_version;
7460
+ }
7461
+
7462
+ $updated_plugin_data = $data;
7463
+ $updated_plugin_data['is_active'] = $is_active;
7464
+ $updated_plugin_data['version'] = $current_version;
7465
+ $updated_plugin_data['title'] = $network_plugins[ $basename ]['Name'];
7466
+ $plugins_update_data[] = $updated_plugin_data;
7467
+ }
7468
+ }
7469
+
7470
+ // Find new plugins that weren't yet seen before.
7471
+ foreach ( $network_plugins as $basename => $data ) {
7472
+ if ( ! isset( $network_plugins_cache->plugins[ $basename ] ) ) {
7473
+ // New plugin.
7474
+ $new_plugin = array(
7475
+ 'slug' => $data['slug'],
7476
+ 'version' => $data['Version'],
7477
+ 'title' => $data['Name'],
7478
+ 'is_active' => $data['is_active'],
7479
+ 'is_uninstalled' => false,
7480
+ );
7481
+
7482
+ $plugins_update_data[] = $new_plugin;
7483
+ $network_plugins_cache->plugins[ $basename ] = $new_plugin;
7484
+
7485
+ if ( isset( $site_active_plugins[ $basename ] ) ) {
7486
+ $site_active_plugins_cache->plugins[ $basename ] = $new_plugin;
7487
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
7488
+ }
7489
+ }
7490
+ }
7491
+
7492
+ $site_active_plugins_cache->md5 = $site_active_plugins_thumbprint;
7493
+ $site_active_plugins_cache->timestamp = $time;
7494
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
7495
+
7496
+ $network_plugins_cache->md5 = $network_plugins_thumbprint;
7497
+ $network_plugins_cache->timestamp = $time;
7498
+ self::$_accounts->set_option( $network_plugins_option_name, $network_plugins_cache, true );
7499
+
7500
+ return $plugins_update_data;
7501
+ }
7502
+
7503
+ /**
7504
+ * Return a list of modified themes since the last sync.
7505
+ *
7506
+ * Note:
7507
+ * There's no point to store a themes counter since even if the number of
7508
+ * themes didn't change, we still need to check if the versions are all the
7509
+ * same and the activity state is similar.
7510
+ *
7511
+ * @author Vova Feldman (@svovaf)
7512
+ * @since 1.1.8
7513
+ *
7514
+ * @return array|false
7515
+ */
7516
+ private function get_themes_data_for_api() {
7517
+ // Alias.
7518
+ $option_name = 'all_themes';
7519
+
7520
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
7521
+
7522
+ if ( ! is_object( $all_cached_themes ) ) {
7523
+ $all_cached_themes = (object) array(
7524
+ 'timestamp' => '',
7525
+ 'md5' => '',
7526
+ 'themes' => array(),
7527
+ );
7528
+ }
7529
+
7530
+ $time = time();
7531
+
7532
+ if ( ! empty( $all_cached_themes->timestamp ) &&
7533
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
7534
+ ) {
7535
+ // Don't send theme updates if last update was in the past 5 min.
7536
+ return false;
7537
+ }
7538
+
7539
+ // Write timestamp to lock the logic.
7540
+ $all_cached_themes->timestamp = $time;
7541
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
7542
+
7543
+ // Reload options from DB.
7544
+ self::$_accounts->load( true );
7545
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
7546
+
7547
+ if ( $time != $all_cached_themes->timestamp ) {
7548
+ // If timestamp is different, then another thread captured the lock.
7549
+ return false;
7550
+ }
7551
+
7552
+ // Get active theme.
7553
+ $active_theme = wp_get_theme();
7554
+ $active_theme_stylesheet = $active_theme->get_stylesheet();
7555
+
7556
+ // Check if there's a change in themes.
7557
+ $all_themes = wp_get_themes();
7558
+
7559
+ // Check if themes changed.
7560
+ ksort( $all_themes );
7561
+
7562
+ $themes_signature = '';
7563
+ foreach ( $all_themes as $slug => $data ) {
7564
+ $is_active = ( $slug === $active_theme_stylesheet );
7565
+ $themes_signature .= $slug . ',' .
7566
+ $data->version . ',' .
7567
+ ( $is_active ? '1' : '0' ) . ';';
7568
+ }
7569
+
7570
+ // Check if themes status changed (version or active/inactive).
7571
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
7572
+
7573
+ $themes_update_data = array();
7574
+
7575
+ if ( $themes_changed ) {
7576
+ // Change in themes, report changes.
7577
+
7578
+ // Update existing themes info.
7579
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
7580
+ $is_active = ( $slug === $active_theme_stylesheet );
7581
+
7582
+ if ( ! isset( $all_themes[ $slug ] ) ) {
7583
+ // Plugin uninstalled.
7584
+ $uninstalled_theme_data = $data;
7585
+ $uninstalled_theme_data['is_active'] = false;
7586
+ $uninstalled_theme_data['is_uninstalled'] = true;
7587
+ $themes_update_data[] = $uninstalled_theme_data;
7588
+
7589
+ unset( $all_themes[ $slug ] );
7590
+ unset( $all_cached_themes->themes[ $slug ] );
7591
+ } else if ( $data['is_active'] !== $is_active ||
7592
+ $data['version'] !== $all_themes[ $slug ]->version
7593
+ ) {
7594
+ // Plugin activated or deactivated, or version changed.
7595
+
7596
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
7597
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
7598
+
7599
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
7600
+ }
7601
+ }
7602
+
7603
+ // Find new themes that weren't yet seen before.
7604
+ foreach ( $all_themes as $slug => $data ) {
7605
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
7606
+ $is_active = ( $slug === $active_theme_stylesheet );
7607
+
7608
+ // New plugin.
7609
+ $new_plugin = array(
7610
+ 'slug' => $slug,
7611
+ 'version' => $data->version,
7612
+ 'title' => $data->name,
7613
+ 'is_active' => $is_active,
7614
+ 'is_uninstalled' => false,
7615
+ );
7616
+
7617
+ $themes_update_data[] = $new_plugin;
7618
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
7619
+ }
7620
+ }
7621
+
7622
+ $all_cached_themes->md5 = md5( $themes_signature );
7623
+ $all_cached_themes->timestamp = time();
7624
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
7625
+ }
7626
+
7627
+ return $themes_update_data;
7628
+ }
7629
+
7630
+ /**
7631
+ * Get site data for API install request.
7632
+ *
7633
+ * @author Vova Feldman (@svovaf)
7634
+ * @since 1.1.2
7635
+ *
7636
+ * @param string[] string $override
7637
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
7638
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
7639
+ *
7640
+ * @return array
7641
+ */
7642
+ private function get_install_data_for_api(
7643
+ array $override,
7644
+ $include_plugins = true,
7645
+ $include_themes = true
7646
+ ) {
7647
+ /**
7648
+ * @since 1.1.8 Also send plugin updates.
7649
+ */
7650
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
7651
+ $plugins = $this->get_plugins_data_for_api();
7652
+ if ( ! empty( $plugins ) ) {
7653
+ $override['plugins'] = $plugins;
7654
+ }
7655
+ }
7656
+ /**
7657
+ * @since 1.1.8 Also send themes updates.
7658
+ */
7659
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
7660
+ $themes = $this->get_themes_data_for_api();
7661
+ if ( ! empty( $themes ) ) {
7662
+ $override['themes'] = $themes;
7663
+ }
7664
+ }
7665
+
7666
+ return array_merge( array(
7667
+ 'version' => $this->get_plugin_version(),
7668
+ 'is_premium' => $this->is_premium(),
7669
+ 'language' => get_bloginfo( 'language' ),
7670
+ 'charset' => get_bloginfo( 'charset' ),
7671
+ 'platform_version' => get_bloginfo( 'version' ),
7672
+ 'sdk_version' => $this->version,
7673
+ 'programming_language_version' => phpversion(),
7674
+ 'title' => get_bloginfo( 'name' ),
7675
+ 'url' => get_site_url(),
7676
+ // Special params.
7677
+ 'is_active' => true,
7678
+ 'is_disconnected' => $this->is_tracking_prohibited(),
7679
+ 'is_uninstalled' => false,
7680
+ ), $override );
7681
+ }
7682
+
7683
+ /**
7684
+ * Update installs details.
7685
+ *
7686
+ * @todo V1 of multiste network support doesn't support plugin and theme data sending.
7687
+ *
7688
+ * @author Vova Feldman (@svovaf)
7689
+ * @since 2.0.0
7690
+ *
7691
+ * @param string[] string $override
7692
+ * @param bool $only_diff
7693
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
7694
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
7695
+ *
7696
+ * @return array
7697
+ */
7698
+ private function get_installs_data_for_api(
7699
+ array $override,
7700
+ $only_diff = false,
7701
+ $include_plugins = true,
7702
+ $include_themes = true
7703
+ ) {
7704
+ /**
7705
+ * @since 1.1.8 Also send plugin updates.
7706
+ */
7707
+ // if ( $include_plugins && ! isset( $override['plugins'] ) ) {
7708
+ // $plugins = $this->get_plugins_data_for_api();
7709
+ // if ( ! empty( $plugins ) ) {
7710
+ // $override['plugins'] = $plugins;
7711
+ // }
7712
+ // }
7713
+ /**
7714
+ * @since 1.1.8 Also send themes updates.
7715
+ */
7716
+ // if ( $include_themes && ! isset( $override['themes'] ) ) {
7717
+ // $themes = $this->get_themes_data_for_api();
7718
+ // if ( ! empty( $themes ) ) {
7719
+ // $override['themes'] = $themes;
7720
+ // }
7721
+ // }
7722
+
7723
+ // Common properties.
7724
+ $common = array_merge( array(
7725
+ 'version' => $this->get_plugin_version(),
7726
+ 'is_premium' => $this->is_premium(),
7727
+ 'sdk_version' => $this->version,
7728
+ 'programming_language_version' => phpversion(),
7729
+ 'platform_version' => get_bloginfo( 'version' ),
7730
+ ), $override );
7731
+
7732
+
7733
+ $is_common_diff_for_any_site = false;
7734
+ $common_diff_union = array();
7735
+
7736
+ $installs_data = array();
7737
+
7738
+ $sites = self::get_sites();
7739
+
7740
+ foreach ( $sites as $site ) {
7741
+ $blog_id = self::get_site_blog_id( $site );
7742
+
7743
+ $install = $this->get_install_by_blog_id( $blog_id );
7744
+
7745
+ if ( is_object( $install ) ) {
7746
+ if ( $install->user_id != $this->_user->id ) {
7747
+ // Install belongs to a different owner.
7748
+ continue;
7749
+ }
7750
+
7751
+ if ( ! $this->is_premium() && $install->is_tracking_prohibited() ) {
7752
+ // Don't send updates regarding opted-out installs.
7753
+ continue;
7754
+ }
7755
+
7756
+ $install_data = $this->get_site_info( $site );
7757
+
7758
+ $uid = $install_data['uid'];
7759
+
7760
+ unset( $install_data['blog_id'] );
7761
+ unset( $install_data['uid'] );
7762
+
7763
+ $install_data['is_disconnected'] = $install->is_disconnected;
7764
+ $install_data['is_active'] = $this->is_active_for_site( $blog_id );
7765
+ $install_data['is_uninstalled'] = $install->is_uninstalled;
7766
+
7767
+ $common_diff = null;
7768
+ $is_common_diff = false;
7769
+ if ( $only_diff ) {
7770
+ $install_data = $this->get_install_diff_for_api( $install_data, $install, $override );
7771
+ $common_diff = $this->get_install_diff_for_api( $common, $install, $override );
7772
+
7773
+ $is_common_diff = ! empty( $common_diff );
7774
+
7775
+ if ( $is_common_diff ) {
7776
+ foreach ( $common_diff as $k => $v ) {
7777
+ if ( ! isset( $common_diff_union[ $k ] ) ) {
7778
+ $common_diff_union[ $k ] = $v;
7779
+ }
7780
+ }
7781
+ }
7782
+
7783
+ $is_common_diff_for_any_site = $is_common_diff_for_any_site || $is_common_diff;
7784
+ }
7785
+
7786
+ if ( ! empty( $install_data ) || $is_common_diff ) {
7787
+ // Add install ID and site unique ID.
7788
+ $install_data['id'] = $install->id;
7789
+ $install_data['uid'] = $uid;
7790
+
7791
+ $installs_data[] = $install_data;
7792
+ }
7793
+ }
7794
+ }
7795
+
7796
+ restore_current_blog();
7797
+
7798
+ if ( 0 < count( $installs_data ) && ( $is_common_diff_for_any_site || ! $only_diff ) ) {
7799
+ if ( ! $only_diff ) {
7800
+ $installs_data[] = $common;
7801
+ } else if ( ! empty( $common_diff_union ) ) {
7802
+ $installs_data[] = $common_diff_union;
7803
+ }
7804
+ }
7805
+
7806
+ foreach ( $installs_data as &$data ) {
7807
+ $data = (object) $data;
7808
+ }
7809
+
7810
+ return $installs_data;
7811
+ }
7812
+
7813
+ /**
7814
+ * Compare site actual data to the stored install data and return the differences for an API data sync.
7815
+ *
7816
+ * @author Vova Feldman (@svovaf)
7817
+ * @since 2.0.0
7818
+ *
7819
+ * @param array $site
7820
+ * @param FS_Site $install
7821
+ * @param string[] string $override
7822
+ *
7823
+ * @return array
7824
+ */
7825
+ private function get_install_diff_for_api( $site, $install, $override = array() ) {
7826
+ $diff = array();
7827
+ $special = array();
7828
+ $special_override = false;
7829
+
7830
+ foreach ( $site as $p => $v ) {
7831
+ if ( property_exists( $install, $p ) ) {
7832
+ if ( ( is_bool( $install->{$p} ) || ! empty( $install->{$p} ) ) &&
7833
+ $install->{$p} != $v
7834
+ ) {
7835
+ $install->{$p} = $v;
7836
+ $diff[ $p ] = $v;
7837
+ }
7838
+ } else {
7839
+ $special[ $p ] = $v;
7840
+
7841
+ if ( isset( $override[ $p ] ) ||
7842
+ 'plugins' === $p ||
7843
+ 'themes' === $p
7844
+ ) {
7845
+ $special_override = true;
7846
+ }
7847
+ }
7848
+ }
7849
+
7850
+ if ( $special_override || 0 < count( $diff ) ) {
7851
+ // Add special params only if has at least one
7852
+ // standard param, or if explicitly requested to
7853
+ // override a special param or a param which is not exist
7854
+ // in the install object.
7855
+ $diff = array_merge( $diff, $special );
7856
+ }
7857
+
7858
+ return $diff;
7859
+ }
7860
+
7861
+ /**
7862
+ * Update install only if changed.
7863
+ *
7864
+ * @author Vova Feldman (@svovaf)
7865
+ * @since 1.0.9
7866
+ *
7867
+ * @param string[] string $override
7868
+ * @param bool $flush
7869
+ *
7870
+ * @return false|object|string
7871
+ */
7872
+ private function send_install_update( $override = array(), $flush = false ) {
7873
+ $this->_logger->entrance();
7874
+
7875
+ $check_properties = $this->get_install_data_for_api( $override );
7876
+
7877
+ if ( $flush ) {
7878
+ $params = $check_properties;
7879
+ } else {
7880
+ $params = $this->get_install_diff_for_api( $check_properties, $this->_site, $override );
7881
+ }
7882
+
7883
+ if ( 0 < count( $params ) ) {
7884
+ if ( ! is_multisite() ) {
7885
+ // Update last install sync timestamp.
7886
+ $this->set_cron_execution_timestamp( 'install_sync' );
7887
+ }
7888
+
7889
+ $params['uid'] = $this->get_anonymous_id();
7890
+
7891
+ // Send updated values to FS.
7892
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
7893
+
7894
+ if ( $this->is_api_result_entity( $site ) ) {
7895
+ if ( ! is_multisite() ) {
7896
+ // I successfully sent install update, clear scheduled sync if exist.
7897
+ $this->clear_install_sync_cron();
7898
+ }
7899
+ }
7900
+
7901
+ return $site;
7902
+ }
7903
+
7904
+ return false;
7905
+ }
7906
+
7907
+ /**
7908
+ * Update installs only if changed.
7909
+ *
7910
+ * @author Vova Feldman (@svovaf)
7911
+ * @since 2.0.0
7912
+ *
7913
+ * @param string[] string $override
7914
+ * @param bool $flush
7915
+ *
7916
+ * @return false|object|string
7917
+ */
7918
+ private function send_installs_update( $override = array(), $flush = false ) {
7919
+ $this->_logger->entrance();
7920
+
7921
+ $installs_data = $this->get_installs_data_for_api( $override, ! $flush );
7922
+
7923
+ if ( empty( $installs_data ) ) {
7924
+ return false;
7925
+ }
7926
+
7927
+ // Update last install sync timestamp.
7928
+ $this->set_cron_execution_timestamp( 'install_sync' );
7929
+
7930
+ // Send updated values to FS.
7931
+ $result = $this->get_api_user_scope()->call( "/plugins/{$this->_plugin->id}/installs.json", 'put', $installs_data );
7932
+
7933
+ if ( $this->is_api_result_object( $result, 'installs' ) ) {
7934
+ // I successfully sent installs update, clear scheduled sync if exist.
7935
+ $this->clear_install_sync_cron();
7936
+ }
7937
+
7938
+ return $result;
7939
+ }
7940
+
7941
+ /**
7942
+ * Update install only if changed.
7943
+ *
7944
+ * @author Vova Feldman (@svovaf)
7945
+ * @since 1.0.9
7946
+ *
7947
+ * @param string[] string $override
7948
+ * @param bool $flush
7949
+ */
7950
+ private function sync_install( $override = array(), $flush = false ) {
7951
+ $this->_logger->entrance();
7952
+
7953
+ $site = $this->send_install_update( $override, $flush );
7954
+
7955
+ if ( false === $site ) {
7956
+ // No sync required.
7957
+ return;
7958
+ }
7959
+
7960
+ if ( ! $this->is_api_result_entity( $site ) ) {
7961
+ // Failed to sync, don't update locally.
7962
+ return;
7963
+ }
7964
+
7965
+ $this->_site = new FS_Site( $site );
7966
+
7967
+ $this->_store_site( true );
7968
+ }
7969
+
7970
+ /**
7971
+ * Update install only if changed.
7972
+ *
7973
+ * @author Vova Feldman (@svovaf)
7974
+ * @since 1.0.9
7975
+ *
7976
+ * @param string[] string $override
7977
+ * @param bool $flush
7978
+ */
7979
+ private function sync_installs( $override = array(), $flush = false ) {
7980
+ $this->_logger->entrance();
7981
+
7982
+ $result = $this->send_installs_update( $override, $flush );
7983
+
7984
+ if ( false === $result ) {
7985
+ // No sync required.
7986
+ return;
7987
+ }
7988
+
7989
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
7990
+ // Failed to sync, don't update locally.
7991
+ return;
7992
+ }
7993
+
7994
+ $address_to_blog_map = $this->get_address_to_blog_map();
7995
+
7996
+ foreach ( $result->installs as $install ) {
7997
+ $this->_site = new FS_Site( $install );
7998
+
7999
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
8000
+ $blog_id = $address_to_blog_map[ $address ];
8001
+
8002
+ $this->_store_site( true, $blog_id );
8003
+ }
8004
+ }
8005
+
8006
+ /**
8007
+ * Track install's custom event.
8008
+ *
8009
+ * IMPORTANT:
8010
+ * Custom event tracking is currently only supported for specific clients.
8011
+ * If you are not one of them, please don't use this method. If you will,
8012
+ * the API will simply ignore your request based on the plugin ID.
8013
+ *
8014
+ * Need custom tracking for your plugin or theme?
8015
+ * If you are interested in custom event tracking please contact yo@freemius.com
8016
+ * for further details.
8017
+ *
8018
+ * @author Vova Feldman (@svovaf)
8019
+ * @since 1.2.1
8020
+ *
8021
+ * @param string $name Event name.
8022
+ * @param array $properties Associative key/value array with primitive values only
8023
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
8024
+ * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
8025
+ *
8026
+ * @return object|false Event data or FALSE on failure.
8027
+ *
8028
+ * @throws \Freemius_InvalidArgumentException
8029
+ */
8030
+ public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
8031
+ $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
8032
+
8033
+ if ( ! $this->is_registered() ) {
8034
+ return false;
8035
+ }
8036
+
8037
+ $event = array( 'type' => $name );
8038
+
8039
+ if ( is_numeric( $process_at ) && $process_at > time() ) {
8040
+ $event['process_at'] = $process_at;
8041
+ }
8042
+
8043
+ if ( $once ) {
8044
+ $event['once'] = true;
8045
+ }
8046
+
8047
+ if ( ! empty( $properties ) ) {
8048
+ // Verify associative array values are primitive.
8049
+ foreach ( $properties as $k => $v ) {
8050
+ if ( ! is_scalar( $v ) ) {
8051
+ throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
8052
+ }
8053
+ }
8054
+
8055
+ $event['properties'] = $properties;
8056
+ }
8057
+
8058
+ $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
8059
+
8060
+ return $this->is_api_error( $result ) ?
8061
+ false :
8062
+ $result;
8063
+ }
8064
+
8065
+ /**
8066
+ * Track install's custom event only once, but it still triggers the API call.
8067
+ *
8068
+ * IMPORTANT:
8069
+ * Custom event tracking is currently only supported for specific clients.
8070
+ * If you are not one of them, please don't use this method. If you will,
8071
+ * the API will simply ignore your request based on the plugin ID.
8072
+ *
8073
+ * Need custom tracking for your plugin or theme?
8074
+ * If you are interested in custom event tracking please contact yo@freemius.com
8075
+ * for further details.
8076
+ *
8077
+ * @author Vova Feldman (@svovaf)
8078
+ * @since 1.2.1
8079
+ *
8080
+ * @param string $name Event name.
8081
+ * @param array $properties Associative key/value array with primitive values only
8082
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
8083
+ *
8084
+ * @return object|false Event data or FALSE on failure.
8085
+ *
8086
+ * @throws \Freemius_InvalidArgumentException
8087
+ *
8088
+ * @user Freemius::track_event()
8089
+ */
8090
+ public function track_event_once( $name, $properties = array(), $process_at = false ) {
8091
+ return $this->track_event( $name, $properties, $process_at, true );
8092
+ }
8093
+
8094
+ /**
8095
+ * Plugin uninstall hook.
8096
+ *
8097
+ * @author Vova Feldman (@svovaf)
8098
+ * @since 1.0.1
8099
+ *
8100
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
8101
+ */
8102
+ function _uninstall_plugin_event( $check_user = true ) {
8103
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8104
+
8105
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
8106
+ return;
8107
+ }
8108
+
8109
+ $params = array();
8110
+ $uninstall_reason = null;
8111
+ if ( isset( $this->_storage->uninstall_reason ) ) {
8112
+ $uninstall_reason = $this->_storage->uninstall_reason;
8113
+ $params['reason_id'] = $uninstall_reason->id;
8114
+ $params['reason_info'] = $uninstall_reason->info;
8115
+ }
8116
+
8117
+ if ( ! $this->is_registered() ) {
8118
+ // Send anonymous uninstall event only if user submitted a feedback.
8119
+ if ( isset( $uninstall_reason ) ) {
8120
+ if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
8121
+ $this->opt_in( false, false, false, false, true );
8122
+ } else {
8123
+ $params['uid'] = $this->get_anonymous_id();
8124
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
8125
+ }
8126
+ }
8127
+ } else {
8128
+ $params = array_merge( $params, array(
8129
+ 'is_active' => false,
8130
+ 'is_uninstalled' => true,
8131
+ ) );
8132
+
8133
+ if ( $this->_is_network_active ) {
8134
+ // Send uninstall event.
8135
+ $this->send_installs_update( $params );
8136
+ } else {
8137
+ // Send uninstall event.
8138
+ $this->send_install_update( $params );
8139
+ }
8140
+ }
8141
+
8142
+ // @todo Decide if we want to delete plugin information from db.
8143
+ }
8144
+
8145
+ /**
8146
+ * @author Vova Feldman (@svovaf)
8147
+ * @since 1.1.1
8148
+ *
8149
+ * @return string
8150
+ */
8151
+ function premium_plugin_basename() {
8152
+ return "{$this->_slug}-premium/" . basename( $this->_free_plugin_basename );
8153
+ }
8154
+
8155
+ /**
8156
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
8157
+ *
8158
+ * @author Vova Feldman (@svovaf)
8159
+ * @since 1.0.2
8160
+ */
8161
+ public static function _uninstall_plugin_hook() {
8162
+ self::_load_required_static();
8163
+
8164
+ self::$_static_logger->entrance();
8165
+
8166
+ if ( ! current_user_can( 'activate_plugins' ) ) {
8167
+ return;
8168
+ }
8169
+
8170
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
8171
+
8172
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
8173
+
8174
+ define( 'WP_FS__UNINSTALL_MODE', true );
8175
+
8176
+ $fs = self::get_instance_by_file( $plugin_file );
8177
+
8178
+ if ( is_object( $fs ) ) {
8179
+ self::require_plugin_essentials();
8180
+
8181
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
8182
+ is_plugin_active( $fs->premium_plugin_basename() )
8183
+ ) {
8184
+ // Deleting Free or Premium plugin version while the other version still installed.
8185
+ return;
8186
+ }
8187
+
8188
+ $fs->_uninstall_plugin_event();
8189
+
8190
+ $fs->do_action( 'after_uninstall' );
8191
+ }
8192
+ }
8193
+
8194
+ #----------------------------------------------------------------------------------
8195
+ #region Plugin Information
8196
+ #----------------------------------------------------------------------------------
8197
+
8198
+ /**
8199
+ * Load WordPress core plugin.php essential module.
8200
+ *
8201
+ * @author Vova Feldman (@svovaf)
8202
+ * @since 1.1.1
8203
+ */
8204
+ private static function require_plugin_essentials() {
8205
+ if ( ! function_exists( 'get_plugins' ) ) {
8206
+ self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
8207
+
8208
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
8209
+ }
8210
+ }
8211
+
8212
+ /**
8213
+ * Load WordPress core pluggable.php module.
8214
+ *
8215
+ * @author Vova Feldman (@svovaf)
8216
+ * @since 1.1.2
8217
+ */
8218
+ private static function require_pluggable_essentials() {
8219
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
8220
+ require_once ABSPATH . 'wp-includes/pluggable.php';
8221
+ }
8222
+ }
8223
+
8224
+ /**
8225
+ * Return plugin data.
8226
+ *
8227
+ * @author Vova Feldman (@svovaf)
8228
+ * @since 1.0.1
8229
+ *
8230
+ * @return array
8231
+ */
8232
+ function get_plugin_data() {
8233
+ if ( ! isset( $this->_plugin_data ) ) {
8234
+ self::require_plugin_essentials();
8235
+
8236
+ if ( $this->is_plugin() ) {
8237
+ /**
8238
+ * @author Vova Feldman (@svovaf)
8239
+ * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
8240
+ *
8241
+ * @link https://github.com/Freemius/wordpress-sdk/issues/77
8242
+ */
8243
+ $plugin_data = get_plugin_data(
8244
+ $this->_plugin_main_file_path,
8245
+ false,
8246
+ false
8247
+ );
8248
+ } else {
8249
+ $theme_data = wp_get_theme();
8250
+
8251
+ if ( $this->_plugin_basename !== $theme_data->get_stylesheet() && is_child_theme() ) {
8252
+ $parent_theme = $theme_data->parent();
8253
+
8254
+ if ( ( $parent_theme instanceof WP_Theme ) && $this->_plugin_basename === $parent_theme->get_stylesheet() ) {
8255
+ $theme_data = $parent_theme;
8256
+ }
8257
+ }
8258
+
8259
+ $plugin_data = array(
8260
+ 'Name' => $theme_data->get( 'Name' ),
8261
+ 'Version' => $theme_data->get( 'Version' ),
8262
+ 'Author' => $theme_data->get( 'Author' ),
8263
+ 'Description' => $theme_data->get( 'Description' ),
8264
+ 'PluginURI' => $theme_data->get( 'ThemeURI' ),
8265
+ );
8266
+ }
8267
+
8268
+ $this->_plugin_data = $plugin_data;
8269
+ }
8270
+
8271
+ return $this->_plugin_data;
8272
+ }
8273
+
8274
+ /**
8275
+ * @author Vova Feldman (@svovaf)
8276
+ * @since 1.0.1
8277
+ * @since 1.2.2.5 If slug not set load slug by module ID.
8278
+ *
8279
+ * @return string Plugin slug.
8280
+ */
8281
+ function get_slug() {
8282
+ if ( ! isset( $this->_slug ) ) {
8283
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
8284
+ $this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
8285
+ }
8286
+
8287
+ return $this->_slug;
8288
+ }
8289
+
8290
+ /**
8291
+ * @author Vova Feldman (@svovaf)
8292
+ * @since 1.2.1.7
8293
+ *
8294
+ * @return string Plugin slug.
8295
+ */
8296
+ function get_target_folder_name() {
8297
+ return $this->_slug . ( $this->can_use_premium_code() ? '-premium' : '' );
8298
+ }
8299
+
8300
+ /**
8301
+ * @author Vova Feldman (@svovaf)
8302
+ * @since 1.0.1
8303
+ *
8304
+ * @return number Plugin ID.
8305
+ */
8306
+ function get_id() {
8307
+ return $this->_plugin->id;
8308
+ }
8309
+
8310
+ /**
8311
+ * @author Vova Feldman (@svovaf)
8312
+ * @since 1.2.1.5
8313
+ *
8314
+ * @return string Freemius SDK version
8315
+ */
8316
+ function get_sdk_version() {
8317
+ return $this->version;
8318
+ }
8319
+
8320
+ /**
8321
+ * @author Vova Feldman (@svovaf)
8322
+ * @since 1.2.1.5
8323
+ *
8324
+ * @return number Parent plugin ID (if parent exist).
8325
+ */
8326
+ function get_parent_id() {
8327
+ return $this->is_addon() ?
8328
+ $this->get_parent_instance()->get_id() :
8329
+ $this->_plugin->id;
8330
+ }
8331
+
8332
+ /**
8333
+ * @author Vova Feldman (@svovaf)
8334
+ * @since 1.0.1
8335
+ *
8336
+ * @return string Plugin public key.
8337
+ */
8338
+ function get_public_key() {
8339
+ return $this->_plugin->public_key;
8340
+ }
8341
+
8342
+ /**
8343
+ * Will be available only on sandbox mode.
8344
+ *
8345
+ * @author Vova Feldman (@svovaf)
8346
+ * @since 1.0.4
8347
+ *
8348
+ * @return mixed Plugin secret key.
8349
+ */
8350
+ function get_secret_key() {
8351
+ return $this->_plugin->secret_key;
8352
+ }
8353
+
8354
+ /**
8355
+ * @author Vova Feldman (@svovaf)
8356
+ * @since 1.1.1
8357
+ *
8358
+ * @return bool
8359
+ */
8360
+ function has_secret_key() {
8361
+ return ! empty( $this->_plugin->secret_key );
8362
+ }
8363
+
8364
+ /**
8365
+ * @author Vova Feldman (@svovaf)
8366
+ * @since 1.0.9
8367
+ *
8368
+ * @return string
8369
+ */
8370
+ function get_plugin_name() {
8371
+ $this->_logger->entrance();
8372
+
8373
+ if ( ! isset( $this->_plugin_name ) ) {
8374
+ $plugin_data = $this->get_plugin_data();
8375
+
8376
+ // Get name.
8377
+ $this->_plugin_name = $plugin_data['Name'];
8378
+
8379
+ // Check if plugin name contains "(Premium)" suffix and remove it.
8380
+ $suffix = ' (premium)';
8381
+ $suffix_len = strlen( $suffix );
8382
+
8383
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
8384
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
8385
+ ) {
8386
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
8387
+ }
8388
+
8389
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
8390
+ }
8391
+
8392
+ return $this->_plugin_name;
8393
+ }
8394
+
8395
+ /**
8396
+ * @author Vova Feldman (@svovaf)
8397
+ * @since 1.0.0
8398
+ *
8399
+ * @return string
8400
+ */
8401
+ function get_plugin_version() {
8402
+ $this->_logger->entrance();
8403
+
8404
+ $plugin_data = $this->get_plugin_data();
8405
+
8406
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
8407
+
8408
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
8409
+ }
8410
+
8411
+ /**
8412
+ * @author Vova Feldman (@svovaf)
8413
+ * @since 1.2.1.7
8414
+ *
8415
+ * @return string
8416
+ */
8417
+ function get_plugin_title() {
8418
+ $this->_logger->entrance();
8419
+
8420
+ $title = $this->_plugin->title;
8421
+
8422
+ return $this->apply_filters( 'plugin_title', $title );
8423
+ }
8424
+
8425
+ /**
8426
+ * @author Vova Feldman (@svovaf)
8427
+ * @since 1.2.2.7
8428
+ *
8429
+ * @param bool $lowercase
8430
+ *
8431
+ * @return string
8432
+ */
8433
+ function get_module_label( $lowercase = false ) {
8434
+ $label = $this->is_addon() ?
8435
+ $this->get_text_inline( 'Add-On', 'addon' ) :
8436
+ ( $this->is_plugin() ?
8437
+ $this->get_text_inline( 'Plugin', 'plugin' ) :
8438
+ $this->get_text_inline( 'Theme', 'theme' ) );
8439
+
8440
+ if ( $lowercase ) {
8441
+ $label = strtolower( $label );
8442
+ }
8443
+
8444
+ return $label;
8445
+ }
8446
+
8447
+ /**
8448
+ * @author Vova Feldman (@svovaf)
8449
+ * @since 1.0.4
8450
+ *
8451
+ * @return string
8452
+ */
8453
+ function get_plugin_basename() {
8454
+ if ( ! isset( $this->_plugin_basename ) ) {
8455
+ if ( $this->is_plugin() ) {
8456
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
8457
+ } else {
8458
+ $this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
8459
+ }
8460
+ }
8461
+
8462
+ return $this->_plugin_basename;
8463
+ }
8464
+
8465
+ function get_plugin_folder_name() {
8466
+ $this->_logger->entrance();
8467
+
8468
+ $plugin_folder = $this->_plugin_basename;
8469
+
8470
+ while ( '.' !== dirname( $plugin_folder ) ) {
8471
+ $plugin_folder = dirname( $plugin_folder );
8472
+ }
8473
+
8474
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
8475
+
8476
+ return $plugin_folder;
8477
+ }
8478
+
8479
+ #endregion ------------------------------------------------------------------
8480
+
8481
+ /* Account
8482
+ ------------------------------------------------------------------------------------------------------------------*/
8483
+
8484
+ /**
8485
+ * Find plugin's slug by plugin's basename.
8486
+ *
8487
+ * @author Vova Feldman (@svovaf)
8488
+ * @since 1.0.9
8489
+ *
8490
+ * @param string $plugin_base_name
8491
+ *
8492
+ * @return false|string
8493
+ */
8494
+ private static function find_slug_by_basename( $plugin_base_name ) {
8495
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
8496
+
8497
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
8498
+ return false;
8499
+ }
8500
+
8501
+ return $file_slug_map[ $plugin_base_name ];
8502
+ }
8503
+
8504
+ /**
8505
+ * Store the map between the plugin's basename to the slug.
8506
+ *
8507
+ * @author Vova Feldman (@svovaf)
8508
+ * @since 1.0.9
8509
+ */
8510
+ private function store_file_slug_map() {
8511
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
8512
+
8513
+ if ( ! array( $file_slug_map ) ) {
8514
+ $file_slug_map = array();
8515
+ }
8516
+
8517
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
8518
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
8519
+ ) {
8520
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
8521
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
8522
+ }
8523
+ }
8524
+
8525
+ /**
8526
+ * @return array[number]FS_User
8527
+ */
8528
+ static function get_all_users() {
8529
+ $users = self::$_accounts->get_option( 'users', array() );
8530
+
8531
+ if ( ! is_array( $users ) ) {
8532
+ $users = array();
8533
+ }
8534
+
8535
+ return $users;
8536
+ }
8537
+
8538
+ /**
8539
+ * @param string $module_type
8540
+ * @param null|int $blog_id Since 2.0.0
8541
+ *
8542
+ * @return array[string]FS_Site
8543
+ */
8544
+ private static function get_all_sites(
8545
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN,
8546
+ $blog_id = null
8547
+ ) {
8548
+ $sites = self::get_account_option( 'sites', $module_type, $blog_id );
8549
+
8550
+ if ( ! is_array( $sites ) ) {
8551
+ $sites = array();
8552
+ }
8553
+
8554
+ return $sites;
8555
+ }
8556
+
8557
+ /**
8558
+ * @author Leo Fajardo (@leorw)
8559
+ *
8560
+ * @since 1.2.2
8561
+ *
8562
+ * @param string $option_name
8563
+ * @param string $module_type
8564
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8565
+ *
8566
+ * @return mixed
8567
+ */
8568
+ private static function get_account_option( $option_name, $module_type = null, $network_level_or_blog_id = null ) {
8569
+ if ( ! is_null( $module_type ) && WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
8570
+ $option_name = $module_type . '_' . $option_name;
8571
+ }
8572
+
8573
+ return self::$_accounts->get_option( $option_name, array(), $network_level_or_blog_id );
8574
+ }
8575
+
8576
+ /**
8577
+ * @author Leo Fajardo (@leorw)
8578
+ *
8579
+ * @since 1.2.2
8580
+ *
8581
+ * @param string $option_name
8582
+ * @param mixed $option_value
8583
+ * @param bool $store
8584
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8585
+ */
8586
+ private function set_account_option( $option_name, $option_value, $store, $network_level_or_blog_id = null ) {
8587
+ self::set_account_option_by_module(
8588
+ $this->_module_type,
8589
+ $option_name,
8590
+ $option_value,
8591
+ $store,
8592
+ $network_level_or_blog_id
8593
+ );
8594
+ }
8595
+
8596
+ /**
8597
+ * @author Vova Feldman (@svovaf)
8598
+ *
8599
+ * @since 1.2.2.7
8600
+ *
8601
+ * @param string $module_type
8602
+ * @param string $option_name
8603
+ * @param mixed $option_value
8604
+ * @param bool $store
8605
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8606
+ */
8607
+ private static function set_account_option_by_module(
8608
+ $module_type,
8609
+ $option_name,
8610
+ $option_value,
8611
+ $store,
8612
+ $network_level_or_blog_id = null
8613
+ ) {
8614
+ if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
8615
+ $option_name = $module_type . '_' . $option_name;
8616
+ }
8617
+
8618
+ self::$_accounts->set_option( $option_name, $option_value, $store, $network_level_or_blog_id );
8619
+ }
8620
+
8621
+ /**
8622
+ * @author Vova Feldman (@svovaf)
8623
+ * @since 1.0.6
8624
+ *
8625
+ * @param number|null $module_id
8626
+ *
8627
+ * @return FS_Plugin_License[]
8628
+ */
8629
+ private static function get_all_licenses( $module_id = null ) {
8630
+ $licenses = self::get_account_option( 'all_licenses' );
8631
+
8632
+ if ( ! is_array( $licenses ) ) {
8633
+ $licenses = array();
8634
+ }
8635
+
8636
+ if ( is_null( $module_id ) ) {
8637
+ return $licenses;
8638
+ }
8639
+
8640
+ $licenses = isset( $licenses[ $module_id ] ) ?
8641
+ $licenses[ $module_id ] :
8642
+ array();
8643
+
8644
+ return $licenses;
8645
+ }
8646
+
8647
+ /**
8648
+ * @author Leo Fajardo (@leorw)
8649
+ * @since 2.0.0
8650
+ *
8651
+ * @return array
8652
+ */
8653
+ private static function get_all_licenses_by_module_type() {
8654
+ $licenses = self::get_account_option( 'all_licenses' );
8655
+
8656
+ $licenses_by_module_type = array(
8657
+ WP_FS__MODULE_TYPE_PLUGIN => array(),
8658
+ WP_FS__MODULE_TYPE_THEME => array()
8659
+ );
8660
+
8661
+ if ( ! is_array( $licenses ) ) {
8662
+ return $licenses_by_module_type;
8663
+ }
8664
+
8665
+ foreach ( $licenses as $module_id => $module_licenses ) {
8666
+ $fs = self::get_instance_by_id( $module_id );
8667
+ if ( false === $fs ) {
8668
+ continue;
8669
+ }
8670
+
8671
+ $licenses_by_module_type[ $fs->_module_type ] = array_merge( $licenses_by_module_type[ $fs->_module_type ], $module_licenses );
8672
+ }
8673
+
8674
+ return $licenses_by_module_type;
8675
+ }
8676
+
8677
+ /**
8678
+ * @author Leo Fajardo (@leorw)
8679
+ * @since 2.0.0
8680
+ *
8681
+ * @param number $module_id
8682
+ * @param number|null $user_id
8683
+ *
8684
+ * @return array
8685
+ */
8686
+ private static function get_user_id_license_ids_map( $module_id, $user_id = null ) {
8687
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
8688
+
8689
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
8690
+ $all_modules_user_id_license_ids_map = array();
8691
+ }
8692
+
8693
+ $user_id_license_ids_map = isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ?
8694
+ $all_modules_user_id_license_ids_map[ $module_id ] :
8695
+ array();
8696
+
8697
+ if ( FS_User::is_valid_id( $user_id ) ) {
8698
+ $user_id_license_ids_map = isset( $user_id_license_ids_map[ $user_id ] ) ?
8699
+ $user_id_license_ids_map[ $user_id ] :
8700
+ array();
8701
+ }
8702
+
8703
+ return $user_id_license_ids_map;
8704
+ }
8705
+
8706
+ /**
8707
+ * @author Leo Fajardo (@leorw)
8708
+ * @since 2.0.0
8709
+ *
8710
+ * @param array $new_user_id_license_ids_map
8711
+ * @param number $module_id
8712
+ * @param number|null $user_id
8713
+ */
8714
+ private static function store_user_id_license_ids_map( $new_user_id_license_ids_map, $module_id, $user_id = null ) {
8715
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
8716
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
8717
+ $all_modules_user_id_license_ids_map = array();
8718
+ }
8719
+
8720
+ if ( ! isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ) {
8721
+ $all_modules_user_id_license_ids_map[ $module_id ] = array();
8722
+ }
8723
+
8724
+ if ( FS_User::is_valid_id( $user_id ) ) {
8725
+ $all_modules_user_id_license_ids_map[ $module_id ][ $user_id ] = $new_user_id_license_ids_map;
8726
+ } else {
8727
+ $all_modules_user_id_license_ids_map[ $module_id ] = $new_user_id_license_ids_map;
8728
+ }
8729
+
8730
+ self::$_accounts->set_option( 'user_id_license_ids_map', $all_modules_user_id_license_ids_map, true );
8731
+ }
8732
+
8733
+ /**
8734
+ * Get a collection of the user's linked license IDs.
8735
+ *
8736
+ * @author Vova Feldman (@svovaf)
8737
+ * @since 2.0.0
8738
+ *
8739
+ * @param number $user_id
8740
+ *
8741
+ * @return number[]
8742
+ */
8743
+ private function get_user_linked_license_ids( $user_id ) {
8744
+ return self::get_user_id_license_ids_map( $this->_module_id, $user_id );
8745
+ }
8746
+
8747
+ /**
8748
+ * Override the user's linked license IDs with a new IDs collection.
8749
+ *
8750
+ * @author Vova Feldman (@svovaf)
8751
+ * @since 2.0.0
8752
+ *
8753
+ * @param number $user_id
8754
+ * @param number[] $license_ids
8755
+ */
8756
+ private function set_user_linked_license_ids( $user_id, array $license_ids ) {
8757
+ self::store_user_id_license_ids_map( $license_ids, $this->_module_id, $user_id );
8758
+ }
8759
+
8760
+ /**
8761
+ * Link a specified license ID to a given user.
8762
+ *
8763
+ * @author Vova Feldman (@svovaf)
8764
+ * @since 2.0.0
8765
+ *
8766
+ * @param number $license_id
8767
+ * @param number $user_id
8768
+ */
8769
+ private function link_license_2_user( $license_id, $user_id ) {
8770
+ $license_ids = $this->get_user_linked_license_ids( $user_id );
8771
+
8772
+ if ( in_array( $license_id, $license_ids ) ) {
8773
+ // License already linked.
8774
+ return;
8775
+ }
8776
+
8777
+ $license_ids[] = $license_id;
8778
+
8779
+ $this->set_user_linked_license_ids( $user_id, $license_ids );
8780
+ }
8781
+
8782
+ /**
8783
+ * @param string|bool $module_type
8784
+ *
8785
+ * @return FS_Plugin_Plan[]
8786
+ */
8787
+ private static function get_all_plans( $module_type = false ) {
8788
+ $plans = self::get_account_option( 'plans', $module_type );
8789
+
8790
+ if ( ! is_array( $plans ) ) {
8791
+ $plans = array();
8792
+ }
8793
+
8794
+ return $plans;
8795
+ }
8796
+
8797
+ /**
8798
+ * @author Vova Feldman (@svovaf)
8799
+ * @since 1.0.4
8800
+ *
8801
+ * @return FS_Plugin_Tag[]
8802
+ */
8803
+ private static function get_all_updates() {
8804
+ $updates = self::$_accounts->get_option( 'updates', array() );
8805
+
8806
+ if ( ! is_array( $updates ) ) {
8807
+ $updates = array();
8808
+ }
8809
+
8810
+ return $updates;
8811
+ }
8812
+
8813
+ /**
8814
+ * @author Vova Feldman (@svovaf)
8815
+ * @since 1.0.6
8816
+ *
8817
+ * @return array<number,FS_Plugin[]>|false
8818
+ */
8819
+ private static function get_all_addons() {
8820
+ $addons = self::$_accounts->get_option( 'addons', array() );
8821
+
8822
+ if ( ! is_array( $addons ) ) {
8823
+ $addons = array();
8824
+ }
8825
+
8826
+ return $addons;
8827
+ }
8828
+
8829
+ /**
8830
+ * @author Vova Feldman (@svovaf)
8831
+ * @since 1.0.6
8832
+ *
8833
+ * @return FS_Plugin[]|false
8834
+ */
8835
+ private static function get_all_account_addons() {
8836
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
8837
+
8838
+ if ( ! is_array( $addons ) ) {
8839
+ $addons = array();
8840
+ }
8841
+
8842
+ return $addons;
8843
+ }
8844
+
8845
+ /**
8846
+ * Check if user has connected his account (opted-in).
8847
+ *
8848
+ * Note:
8849
+ * If the user opted-in and opted-out on a later stage,
8850
+ * this will still return true. If you want to check if the
8851
+ * user is currently opted-in, use:
8852
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
8853
+ *
8854
+ * @author Vova Feldman (@svovaf)
8855
+ * @since 1.0.1
8856
+ * @return bool
8857
+ */
8858
+ function is_registered() {
8859
+ return is_object( $this->_user );
8860
+ }
8861
+
8862
+ /**
8863
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
8864
+ *
8865
+ * @author Leo Fajardo (@leorw)
8866
+ * @since 1.2.1.5
8867
+ *
8868
+ * @return bool
8869
+ */
8870
+ function is_tracking_allowed() {
8871
+ return ( is_object( $this->_site ) && $this->_site->is_tracking_allowed() );
8872
+ }
8873
+
8874
+ /**
8875
+ * @author Vova Feldman (@svovaf)
8876
+ * @since 1.0.4
8877
+ *
8878
+ * @return FS_Plugin
8879
+ */
8880
+ function get_plugin() {
8881
+ return $this->_plugin;
8882
+ }
8883
+
8884
+ /**
8885
+ * @author Vova Feldman (@svovaf)
8886
+ * @since 1.0.3
8887
+ *
8888
+ * @return FS_User
8889
+ */
8890
+ function get_user() {
8891
+ return $this->_user;
8892
+ }
8893
+
8894
+ /**
8895
+ * @author Vova Feldman (@svovaf)
8896
+ * @since 1.0.3
8897
+ *
8898
+ * @return FS_Site
8899
+ */
8900
+ function get_site() {
8901
+ return $this->_site;
8902
+ }
8903
+
8904
+ /**
8905
+ * Get plugin add-ons.
8906
+ *
8907
+ * @author Vova Feldman (@svovaf)
8908
+ * @since 1.0.6
8909
+ *
8910
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
8911
+ *
8912
+ * @param bool $flush
8913
+ *
8914
+ * @return FS_Plugin[]|false
8915
+ */
8916
+ function get_addons( $flush = false ) {
8917
+ $this->_logger->entrance();
8918
+
8919
+ if ( ! $this->_has_addons ) {
8920
+ return false;
8921
+ }
8922
+
8923
+ $addons = $this->sync_addons( $flush );
8924
+
8925
+ return ( ! is_array( $addons ) || empty( $addons ) ) ?
8926
+ false :
8927
+ $addons;
8928
+ }
8929
+
8930
+ /**
8931
+ * @author Vova Feldman (@svovaf)
8932
+ * @since 1.0.6
8933
+ *
8934
+ * @return FS_Plugin[]|false
8935
+ */
8936
+ function get_account_addons() {
8937
+ $this->_logger->entrance();
8938
+
8939
+ $addons = self::get_all_account_addons();
8940
+
8941
+ if ( ! is_array( $addons ) ||
8942
+ ! isset( $addons[ $this->_plugin->id ] ) ||
8943
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
8944
+ 0 === count( $addons[ $this->_plugin->id ] )
8945
+ ) {
8946
+ return false;
8947
+ }
8948
+
8949
+ return $addons[ $this->_plugin->id ];
8950
+ }
8951
+
8952
+ /**
8953
+ * Check if user has any
8954
+ *
8955
+ * @author Vova Feldman (@svovaf)
8956
+ * @since 1.1.6
8957
+ *
8958
+ * @return bool
8959
+ */
8960
+ function has_account_addons() {
8961
+ $addons = $this->get_account_addons();
8962
+
8963
+ return is_array( $addons ) && ( 0 < count( $addons ) );
8964
+ }
8965
+
8966
+
8967
+ /**
8968
+ * Get add-on by ID (from local data).
8969
+ *
8970
+ * @author Vova Feldman (@svovaf)
8971
+ * @since 1.0.6
8972
+ *
8973
+ * @param number $id
8974
+ *
8975
+ * @return FS_Plugin|false
8976
+ */
8977
+ function get_addon( $id ) {
8978
+ $this->_logger->entrance();
8979
+
8980
+ $addons = $this->get_addons();
8981
+
8982
+ if ( is_array( $addons ) ) {
8983
+ foreach ( $addons as $addon ) {
8984
+ if ( $id == $addon->id ) {
8985
+ return $addon;
8986
+ }
8987
+ }
8988
+ }
8989
+
8990
+ return false;
8991
+ }
8992
+
8993
+ /**
8994
+ * Get add-on by slug (from local data).
8995
+ *
8996
+ * @author Vova Feldman (@svovaf)
8997
+ * @since 1.0.6
8998
+ *
8999
+ * @param string $slug
9000
+ *
9001
+ * @param bool $flush
9002
+ *
9003
+ * @return FS_Plugin|false
9004
+ */
9005
+ function get_addon_by_slug( $slug, $flush = false ) {
9006
+ $this->_logger->entrance();
9007
+
9008
+ $addons = $this->get_addons( $flush );
9009
+
9010
+ if ( is_array( $addons ) ) {
9011
+ foreach ( $addons as $addon ) {
9012
+ if ( $slug === $addon->slug ) {
9013
+ return $addon;
9014
+ }
9015
+ }
9016
+ }
9017
+
9018
+ return false;
9019
+ }
9020
+
9021
+ /**
9022
+ * @author Vova Feldman (@svovaf)
9023
+ * @since 2.0.0
9024
+ *
9025
+ * @param number $user_id
9026
+ *
9027
+ * @return FS_User
9028
+ */
9029
+ static function _get_user_by_id( $user_id ) {
9030
+ self::$_static_logger->entrance( "user_id = {$user_id}" );
9031
+
9032
+ $users = self::get_all_users();
9033
+
9034
+ if ( is_array( $users ) ) {
9035
+ if ( isset( $users[ $user_id ] ) &&
9036
+ $users[ $user_id ] instanceof FS_User &&
9037
+ $user_id == $users[ $user_id ]->id
9038
+ ) {
9039
+ return $users[ $user_id ];
9040
+ }
9041
+
9042
+ // If user wasn't found by the key, iterate over all the users collection.
9043
+ foreach ( $users as $user ) {
9044
+ /**
9045
+ * @var FS_User $user
9046
+ */
9047
+ if ( $user_id == $user->id ) {
9048
+ return $user;
9049
+ }
9050
+ }
9051
+ }
9052
+
9053
+ return null;
9054
+ }
9055
+
9056
+ /**
9057
+ * Checks if a Freemius user_id is associated with a super-admin.
9058
+ *
9059
+ * @author Vova Feldman (@svovaf)
9060
+ * @since 2.0.0
9061
+ *
9062
+ * @param number $user_id
9063
+ *
9064
+ * @return bool
9065
+ */
9066
+ private static function is_super_admin( $user_id ) {
9067
+ $is_super_admin = false;
9068
+
9069
+ $user = self::_get_user_by_id( $user_id );
9070
+
9071
+ if ( $user instanceof FS_User && ! empty( $user->email ) ) {
9072
+ self::require_pluggable_essentials();
9073
+
9074
+ $wp_user = get_user_by( 'email', $user->email );
9075
+
9076
+ if ( $wp_user instanceof WP_User ) {
9077
+ $super_admins = get_super_admins();
9078
+ $is_super_admin = ( is_array( $super_admins ) && in_array( $wp_user->user_login, $super_admins ) );
9079
+ }
9080
+ }
9081
+
9082
+ return $is_super_admin;
9083
+ }
9084
+
9085
+ #----------------------------------------------------------------------------------
9086
+ #region Plans & Licensing
9087
+ #----------------------------------------------------------------------------------
9088
+
9089
+ /**
9090
+ * Check if running premium plugin code.
9091
+ *
9092
+ * @author Vova Feldman (@svovaf)
9093
+ * @since 1.0.5
9094
+ *
9095
+ * @return bool
9096
+ */
9097
+ function is_premium() {
9098
+ return $this->_plugin->is_premium;
9099
+ }
9100
+
9101
+ /**
9102
+ * Get site's plan ID.
9103
+ *
9104
+ * @author Vova Feldman (@svovaf)
9105
+ * @since 1.0.2
9106
+ *
9107
+ * @return number
9108
+ */
9109
+ function get_plan_id() {
9110
+ return $this->_site->plan_id;
9111
+ }
9112
+
9113
+ /**
9114
+ * Get site's plan title.
9115
+ *
9116
+ * @author Vova Feldman (@svovaf)
9117
+ * @since 1.0.2
9118
+ *
9119
+ * @return string
9120
+ */
9121
+ function get_plan_title() {
9122
+ $plan = $this->get_plan();
9123
+
9124
+ return is_object( $plan ) ? $plan->title : 'PLAN_TITLE';
9125
+ }
9126
+
9127
+ /**
9128
+ * Get site's plan name.
9129
+ *
9130
+ * @author Vova Feldman (@svovaf)
9131
+ * @since 2.0.0
9132
+ *
9133
+ * @return string
9134
+ */
9135
+ function get_plan_name() {
9136
+ $plan = $this->get_plan();
9137
+
9138
+ return is_object( $plan ) ? $plan->name : 'PLAN_NAME';
9139
+ }
9140
+
9141
+ /**
9142
+ * @author Vova Feldman (@svovaf)
9143
+ * @since 1.0.9
9144
+ *
9145
+ * @return FS_Plugin_Plan|false
9146
+ */
9147
+ function get_plan() {
9148
+ if ( ! is_object( $this->_site ) ) {
9149
+ return false;
9150
+ }
9151
+
9152
+ return FS_Plugin_Plan::is_valid_id( $this->_site->plan_id ) ?
9153
+ $this->_get_plan_by_id( $this->_site->plan_id ) :
9154
+ false;
9155
+ }
9156
+
9157
+ /**
9158
+ * @author Vova Feldman (@svovaf)
9159
+ * @since 1.0.3
9160
+ *
9161
+ * @return bool
9162
+ */
9163
+ function is_trial() {
9164
+ $this->_logger->entrance();
9165
+
9166
+ if ( ! $this->is_registered() || ! is_object( $this->_site ) ) {
9167
+ return false;
9168
+ }
9169
+
9170
+ return $this->_site->is_trial();
9171
+ }
9172
+
9173
+ /**
9174
+ * Check if currently in a trial with payment method (credit card or paypal).
9175
+ *
9176
+ * @author Vova Feldman (@svovaf)
9177
+ * @since 1.1.7
9178
+ *
9179
+ * @return bool
9180
+ */
9181
+ function is_paid_trial() {
9182
+ $this->_logger->entrance();
9183
+
9184
+ if ( ! $this->is_trial() ) {
9185
+ return false;
9186
+ }
9187
+
9188
+ return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
9189
+ }
9190
+
9191
+ /**
9192
+ * Check if trial already utilized.
9193
+ *
9194
+ * @since 1.0.9
9195
+ *
9196
+ * @return bool
9197
+ */
9198
+ function is_trial_utilized() {
9199
+ $this->_logger->entrance();
9200
+
9201
+ if ( ! $this->is_registered() ) {
9202
+ return false;
9203
+ }
9204
+
9205
+ return $this->_site->is_trial_utilized();
9206
+ }
9207
+
9208
+ /**
9209
+ * Get trial plan information (if in trial).
9210
+ *
9211
+ * @author Vova Feldman (@svovaf)
9212
+ * @since 1.0.9
9213
+ *
9214
+ * @return bool|FS_Plugin_Plan
9215
+ */
9216
+ function get_trial_plan() {
9217
+ $this->_logger->entrance();
9218
+
9219
+ if ( ! $this->is_trial() ) {
9220
+ return false;
9221
+ }
9222
+
9223
+ // Try to load plan from local cache.
9224
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
9225
+
9226
+ if ( ! is_object( $trial_plan ) ) {
9227
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
9228
+
9229
+ /**
9230
+ * If managed to fetch the plan, add it to the plans collection.
9231
+ */
9232
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
9233
+ if ( ! is_array( $this->_plans ) ) {
9234
+ $this->_plans = array();
9235
+ }
9236
+
9237
+ $this->_plans[] = $trial_plan;
9238
+ $this->_store_plans();
9239
+ }
9240
+ }
9241
+
9242
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
9243
+ return $trial_plan;
9244
+ }
9245
+
9246
+ /**
9247
+ * If for some reason failed to get the trial plan, fallback to a dummy name and title.
9248
+ */
9249
+ $trial_plan = new FS_Plugin_Plan();
9250
+ $trial_plan->id = $this->_site->trial_plan_id;
9251
+ $trial_plan->name = 'pro';
9252
+ $trial_plan->title = 'Pro';
9253
+
9254
+ return $trial_plan;
9255
+ }
9256
+
9257
+ /**
9258
+ * Check if the user has an activate, non-expired license on current plugin's install.
9259
+ *
9260
+ * @since 1.0.9
9261
+ *
9262
+ * @return bool
9263
+ */
9264
+ function is_paying() {
9265
+ $this->_logger->entrance();
9266
+
9267
+ if ( ! $this->is_registered() ) {
9268
+ return false;
9269
+ }
9270
+
9271
+ if ( ! $this->has_paid_plan() ) {
9272
+ return false;
9273
+ }
9274
+
9275
+ return (
9276
+ ! $this->is_trial() &&
9277
+ 'free' !== $this->get_plan_name() &&
9278
+ $this->has_active_valid_license()
9279
+ );
9280
+ }
9281
+
9282
+ /**
9283
+ * @author Vova Feldman (@svovaf)
9284
+ * @since 1.0.4
9285
+ *
9286
+ * @return bool
9287
+ */
9288
+ function is_free_plan() {
9289
+ if ( ! $this->is_registered() ) {
9290
+ return true;
9291
+ }
9292
+
9293
+ if ( ! $this->has_paid_plan() ) {
9294
+ return true;
9295
+ }
9296
+
9297
+ return (
9298
+ 'free' === $this->get_plan_name() ||
9299
+ ! $this->has_features_enabled_license()
9300
+ );
9301
+ }
9302
+
9303
+ /**
9304
+ * @author Vova Feldman (@svovaf)
9305
+ * @since 1.0.5
9306
+ *
9307
+ * @return bool
9308
+ */
9309
+ function _has_premium_license() {
9310
+ $this->_logger->entrance();
9311
+
9312
+ $premium_license = $this->_get_available_premium_license();
9313
+
9314
+ return ( false !== $premium_license );
9315
+ }
9316
+
9317
+ /**
9318
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
9319
+ *
9320
+ * @author Vova Feldman (@svovaf)
9321
+ * @since 1.1.7.3
9322
+ *
9323
+ * @return bool
9324
+ */
9325
+ function has_any_license() {
9326
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
9327
+ }
9328
+
9329
+ /**
9330
+ * @author Vova Feldman (@svovaf)
9331
+ * @since 1.0.5
9332
+ *
9333
+ * @param bool|null $is_localhost
9334
+ *
9335
+ * @return FS_Plugin_License|false
9336
+ */
9337
+ function _get_available_premium_license( $is_localhost = null ) {
9338
+ $this->_logger->entrance();
9339
+
9340
+ $licenses = $this->get_available_premium_licenses( $is_localhost );
9341
+ if ( ! empty( $licenses ) ) {
9342
+ return $licenses[0];
9343
+ }
9344
+
9345
+ return false;
9346
+ }
9347
+
9348
+ /**
9349
+ * @author Vova Feldman (@svovaf)
9350
+ * @since 1.0.5
9351
+ *
9352
+ * @param bool|null $is_localhost
9353
+ *
9354
+ * @return FS_Plugin_License[]
9355
+ */
9356
+ function get_available_premium_licenses( $is_localhost = null ) {
9357
+ $this->_logger->entrance();
9358
+
9359
+ $licenses = array();
9360
+ if ( ! $this->has_paid_plan() ) {
9361
+ return $licenses;
9362
+ }
9363
+
9364
+ if ( is_array( $this->_licenses ) ) {
9365
+ foreach ( $this->_licenses as $license ) {
9366
+ if ( ! $license->can_activate( $is_localhost ) ) {
9367
+ continue;
9368
+ }
9369
+
9370
+ $licenses[] = $license;
9371
+ }
9372
+ }
9373
+
9374
+ return $licenses;
9375
+ }
9376
+
9377
+ /**
9378
+ * Sync local plugin plans with remote server.
9379
+ *
9380
+ * IMPORTANT: If for some reason a site is associated with deleted plan, we'll preserve the plan's information and append it as the last plan. This means that if plan is deleted, the is_plan() method will ALWAYS return true for any given argument (it becomes the most inclusive plan).
9381
+ *
9382
+ * @author Vova Feldman (@svovaf)
9383
+ * @since 1.0.5
9384
+ *
9385
+ * @return FS_Plugin_Plan[]|object
9386
+ */
9387
+ function _sync_plans() {
9388
+ $plans = $this->_fetch_plugin_plans();
9389
+
9390
+ if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
9391
+ $plans_map = array();
9392
+ foreach ( $plans as $plan ) {
9393
+ $plans_map[ $plan->id ] = true;
9394
+ }
9395
+
9396
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
9397
+
9398
+ foreach ( $plans_ids_to_keep as $plan_id ) {
9399
+ if ( isset( $plans_map[ $plan_id ] ) ) {
9400
+ continue;
9401
+ }
9402
+
9403
+ $missing_plan = self::_get_plan_by_id( $plan_id );
9404
+
9405
+ if ( is_object( $missing_plan ) ) {
9406
+ $plans[] = $missing_plan;
9407
+ }
9408
+ }
9409
+
9410
+ $this->_plans = $plans;
9411
+ $this->_store_plans();
9412
+ }
9413
+
9414
+ $this->do_action( 'after_plans_sync', $plans );
9415
+
9416
+ return $this->_plans;
9417
+ }
9418
+
9419
+ /**
9420
+ * Check if specified plan exists locally. If not, fetch it and store it.
9421
+ *
9422
+ * @author Vova Feldman (@svovaf)
9423
+ * @since 2.0.0
9424
+ *
9425
+ * @param number $plan_id
9426
+ *
9427
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
9428
+ */
9429
+ private function sync_plan_if_not_exist( $plan_id ) {
9430
+ $plan = self::_get_plan_by_id( $plan_id );
9431
+
9432
+ if ( is_object( $plan ) ) {
9433
+ // Plan already exists.
9434
+ return $plan;
9435
+ }
9436
+
9437
+ $plan = $this->fetch_plan_by_id( $plan_id );
9438
+
9439
+ if ( $plan instanceof FS_Plugin_Plan ) {
9440
+ $this->_plans[] = $plan;
9441
+ $this->_store_plans();
9442
+
9443
+ return $plan;
9444
+ }
9445
+
9446
+ return $plan;
9447
+ }
9448
+
9449
+ /**
9450
+ * Check if specified license exists locally. If not, fetch it and store it.
9451
+ *
9452
+ * @author Vova Feldman (@svovaf)
9453
+ * @since 2.0.0
9454
+ *
9455
+ * @param number $license_id
9456
+ * @param string $license_key
9457
+ *
9458
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
9459
+ */
9460
+ private function sync_license_if_not_exist( $license_id, $license_key ) {
9461
+ $license = $this->_get_license_by_id( $license_id );
9462
+
9463
+ if ( is_object( $license ) ) {
9464
+ // License already exists.
9465
+ return $license;
9466
+ }
9467
+
9468
+ $license = $this->fetch_license_by_key( $license_id, $license_key );
9469
+
9470
+ if ( $license instanceof FS_Plugin_License ) {
9471
+ $this->_licenses[] = $license;
9472
+ $this->_license = $license;
9473
+ $this->_store_licenses();
9474
+
9475
+ return $license;
9476
+ }
9477
+
9478
+ return $license;
9479
+ }
9480
+
9481
+ /**
9482
+ * Get a collection of unique plan IDs that are associated with any installs in the network.
9483
+ *
9484
+ * @author Leo Fajardo (@leorw)
9485
+ * @since 2.0.0
9486
+ *
9487
+ * @return number[]
9488
+ */
9489
+ private function get_plans_ids_associated_with_installs() {
9490
+ if ( ! $this->_is_network_active ) {
9491
+ if ( ! is_object( $this->_site ) ||
9492
+ ! FS_Plugin_Plan::is_valid_id( $this->_site->plan_id )
9493
+ ) {
9494
+ return array();
9495
+ }
9496
+
9497
+ return array( $this->_site->plan_id );
9498
+ }
9499
+
9500
+ $plan_ids = array();
9501
+ $sites = self::get_sites();
9502
+ foreach ( $sites as $site ) {
9503
+ $blog_id = self::get_site_blog_id( $site );
9504
+ $install = $this->get_install_by_blog_id( $blog_id );
9505
+
9506
+ if ( ! is_object( $install ) ||
9507
+ ! FS_Plugin_Plan::is_valid_id( $install->plan_id )
9508
+ ) {
9509
+ continue;
9510
+ }
9511
+
9512
+ $plan_ids[ $install->plan_id ] = true;
9513
+ }
9514
+
9515
+ return array_keys( $plan_ids );
9516
+ }
9517
+
9518
+ /**
9519
+ * Get a collection of unique license IDs that are associated with any installs in the network.
9520
+ *
9521
+ * @author Leo Fajardo (@leorw)
9522
+ * @since 2.0.0
9523
+ *
9524
+ * @return number[]
9525
+ */
9526
+ private function get_license_ids_associated_with_installs() {
9527
+ if ( ! $this->_is_network_active ) {
9528
+ if ( ! is_object( $this->_site ) ||
9529
+ ! FS_Plugin_License::is_valid_id( $this->_site->license_id )
9530
+ ) {
9531
+ return array();
9532
+ }
9533
+
9534
+ return array( $this->_site->license_id );
9535
+ }
9536
+
9537
+ $license_ids = array();
9538
+ $sites = self::get_sites();
9539
+ foreach ( $sites as $site ) {
9540
+ $blog_id = self::get_site_blog_id( $site );
9541
+ $install = $this->get_install_by_blog_id( $blog_id );
9542
+
9543
+ if ( ! is_object( $install ) ||
9544
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
9545
+ ) {
9546
+ continue;
9547
+ }
9548
+
9549
+ $license_ids[ $install->license_id ] = true;
9550
+ }
9551
+
9552
+ return array_keys( $license_ids );
9553
+ }
9554
+
9555
+ /**
9556
+ * @author Vova Feldman (@svovaf)
9557
+ * @since 1.0.5
9558
+ *
9559
+ * @param number $id
9560
+ *
9561
+ * @return FS_Plugin_Plan|false
9562
+ */
9563
+ function _get_plan_by_id( $id ) {
9564
+ $this->_logger->entrance();
9565
+
9566
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
9567
+ $this->_sync_plans();
9568
+ }
9569
+
9570
+ foreach ( $this->_plans as $plan ) {
9571
+ if ( $id == $plan->id ) {
9572
+ return $plan;
9573
+ }
9574
+ }
9575
+
9576
+ return false;
9577
+ }
9578
+
9579
+ /**
9580
+ * @author Vova Feldman (@svovaf)
9581
+ * @since 1.1.8.1
9582
+ *
9583
+ * @param string $name
9584
+ *
9585
+ * @return FS_Plugin_Plan|false
9586
+ */
9587
+ private function get_plan_by_name( $name ) {
9588
+ $this->_logger->entrance();
9589
+
9590
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
9591
+ $this->_sync_plans();
9592
+ }
9593
+
9594
+ foreach ( $this->_plans as $plan ) {
9595
+ if ( $name == $plan->name ) {
9596
+ return $plan;
9597
+ }
9598
+ }
9599
+
9600
+ return false;
9601
+ }
9602
+
9603
+ /**
9604
+ * Sync local licenses with remote server.
9605
+ *
9606
+ * @author Vova Feldman (@svovaf)
9607
+ * @since 1.0.6
9608
+ *
9609
+ * @param number|bool $site_license_id
9610
+ * @param number|null $blog_id
9611
+ *
9612
+ * @return FS_Plugin_License[]|object
9613
+ */
9614
+ function _sync_licenses( $site_license_id = false, $blog_id = null ) {
9615
+ $this->_logger->entrance();
9616
+
9617
+ $is_network_admin = fs_is_network_admin();
9618
+
9619
+ if ( $is_network_admin && is_null( $blog_id ) ) {
9620
+ $all_licenses = self::get_all_licenses( $this->_module_id );
9621
+ } else {
9622
+ $all_licenses = $this->get_user_licenses( $this->_user->id );
9623
+ }
9624
+
9625
+ $foreign_licenses = array(
9626
+ 'ids' => array(),
9627
+ 'license_keys' => array()
9628
+ );
9629
+
9630
+ $all_licenses_map = array();
9631
+ foreach ( $all_licenses as $license ) {
9632
+ $all_licenses_map[ $license->id ] = true;
9633
+ if ( $license->user_id == $this->_user->id || $license->id == $site_license_id ) {
9634
+ continue;
9635
+ }
9636
+
9637
+ $foreign_licenses['ids'][] = $license->id;
9638
+ $foreign_licenses['license_keys'][] = $license->secret_key;
9639
+ }
9640
+
9641
+ if ( empty( $foreign_licenses['ids'] ) ) {
9642
+ $foreign_licenses = array();
9643
+ }
9644
+
9645
+ $licenses = $this->_fetch_licenses( false, $site_license_id, $foreign_licenses, $blog_id );
9646
+
9647
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
9648
+ $licenses_map = array();
9649
+ foreach ( $licenses as $license ) {
9650
+ $licenses_map[ $license->id ] = true;
9651
+ }
9652
+
9653
+ // $license_ids_to_keep = $this->get_license_ids_associated_with_installs();
9654
+ // foreach ( $license_ids_to_keep as $license_id ) {
9655
+ // if ( isset( $licenses_map[ $license_id ] ) ) {
9656
+ // continue;
9657
+ // }
9658
+ //
9659
+ // $missing_license = self::_get_license_by_id( $license_id, false );
9660
+ // if ( is_object( $missing_license ) ) {
9661
+ // $licenses[] = $missing_license;
9662
+ // $licenses_map[ $missing_license->id ] = true;
9663
+ // }
9664
+ // }
9665
+
9666
+ $user_license_ids = $this->get_user_linked_license_ids( $this->_user->id );
9667
+
9668
+ foreach ( $user_license_ids as $key => $license_id ) {
9669
+ if ( ! isset( $licenses_map[ $license_id ] ) ) {
9670
+ // Remove access to licenses that no longer exist.
9671
+ unset( $user_license_ids[ $key ] );
9672
+ }
9673
+ }
9674
+
9675
+ if ( ! empty( $user_license_ids ) ) {
9676
+ foreach ( $licenses_map as $license_id => $value ) {
9677
+ if ( ! isset( $all_licenses_map[ $license_id ] ) ) {
9678
+ // Associate new licenses with the user who triggered the license syncing.
9679
+ $user_license_ids[] = $license_id;
9680
+ }
9681
+ }
9682
+
9683
+ $user_license_ids = array_unique( $user_license_ids );
9684
+ } else {
9685
+ $user_license_ids = array_keys( $licenses_map );
9686
+ }
9687
+
9688
+ if ( ! $is_network_admin || ! is_null( $blog_id ) ) {
9689
+ $user_licenses = array();
9690
+ foreach ( $licenses as $license ) {
9691
+ if ( ! in_array( $license->id, $user_license_ids ) ) {
9692
+ continue;
9693
+ }
9694
+
9695
+ $user_licenses[] = $license;
9696
+ }
9697
+
9698
+ $this->_licenses = $user_licenses;
9699
+ } else {
9700
+ $this->_licenses = $licenses;
9701
+ }
9702
+
9703
+ $this->set_user_linked_license_ids( $this->_user->id, $user_license_ids );
9704
+
9705
+ $this->_store_licenses( true, $this->_module_id, $licenses );
9706
+ }
9707
+
9708
+ // Update current license.
9709
+ if ( is_object( $this->_license ) ) {
9710
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
9711
+ }
9712
+
9713
+ return $this->_licenses;
9714
+ }
9715
+
9716
+ /**
9717
+ * @author Vova Feldman (@svovaf)
9718
+ * @since 1.0.5
9719
+ *
9720
+ * @param number $id
9721
+ * @param bool $sync_licenses
9722
+ *
9723
+ * @return FS_Plugin_License|false
9724
+ */
9725
+ function _get_license_by_id( $id, $sync_licenses = true ) {
9726
+ $this->_logger->entrance();
9727
+
9728
+ if ( ! FS_Plugin_License::is_valid_id( $id ) ) {
9729
+ return false;
9730
+ }
9731
+
9732
+ /**
9733
+ * When running from the network level admin and opted-in from the network,
9734
+ * check if the license exists in the network user licenses collection.
9735
+ *
9736
+ * @author Vova Feldman (@svovaf)
9737
+ * @since 2.0.0
9738
+ */
9739
+ if ( fs_is_network_admin() &&
9740
+ $this->is_network_registered() &&
9741
+ ( ! is_object( $this->_user ) || $this->_storage->network_user_id != $this->_user->id )
9742
+ ) {
9743
+ $licenses = $this->get_user_licenses( $this->_storage->network_user_id );
9744
+
9745
+ foreach ( $licenses as $license ) {
9746
+ if ( $id == $license->id ) {
9747
+ return $license;
9748
+ }
9749
+ }
9750
+ }
9751
+
9752
+ if ( ! $this->has_any_license() && $sync_licenses ) {
9753
+ $this->_sync_licenses( $id );
9754
+ }
9755
+
9756
+ if ( is_array( $this->_licenses ) ) {
9757
+ foreach ( $this->_licenses as $license ) {
9758
+ if ( $id == $license->id ) {
9759
+ return $license;
9760
+ }
9761
+ }
9762
+ }
9763
+
9764
+ return false;
9765
+ }
9766
+
9767
+ /**
9768
+ * Get license by ID. Unlike _get_license_by_id(), this method only checks the local storage and return any license, whether it's associated with the current context user/install or not.
9769
+ *
9770
+ * @author Vova Feldman (@svovaf)
9771
+ * @since 2.0.0
9772
+ *
9773
+ * @param number $id
9774
+ *
9775
+ * @return FS_Plugin_License
9776
+ */
9777
+ private function get_license_by_id( $id ) {
9778
+ $licenses = self::get_all_licenses( $this->_module_id );
9779
+
9780
+ if ( is_array( $licenses ) && ! empty( $licenses ) ) {
9781
+ foreach ( $licenses as $license ) {
9782
+ if ( $id == $license->id ) {
9783
+ return $license;
9784
+ }
9785
+ }
9786
+ }
9787
+
9788
+ return null;
9789
+ }
9790
+
9791
+ /**
9792
+ * Synchronize the site's context license by fetching the license form the API and updating the local data with it.
9793
+ *
9794
+ * @author Vova Feldman (@svovaf)
9795
+ * @since 2.0.0
9796
+ *
9797
+ * @return \FS_Plugin_License|mixed
9798
+ */
9799
+ private function sync_site_license() {
9800
+ $api = $this->get_api_user_scope();
9801
+
9802
+ $result = $api->get( "/licenses/{$this->_license->id}.json?license_key=" . urlencode( $this->_license->secret_key ), true );
9803
+
9804
+ if ( ! $this->is_api_result_entity( $result ) ) {
9805
+ return $result;
9806
+ }
9807
+
9808
+ $license = $this->_update_site_license( new FS_Plugin_License( $result ) );
9809
+ $this->_store_licenses();
9810
+
9811
+ return $license;
9812
+ }
9813
+
9814
+ /**
9815
+ * Get all user's available licenses for the current module.
9816
+ *
9817
+ * @author Vova Feldman (@svovaf)
9818
+ * @since 2.0.0
9819
+ *
9820
+ * @param number $user_id
9821
+ *
9822
+ * @return FS_Plugin_License[]
9823
+ */
9824
+ private function get_user_licenses( $user_id ) {
9825
+ $all_licenses = self::get_all_licenses( $this->_module_id );
9826
+ if ( empty( $all_licenses ) ) {
9827
+ return array();
9828
+ }
9829
+
9830
+ $user_license_ids = $this->get_user_linked_license_ids( $user_id );
9831
+ if ( empty( $user_license_ids ) ) {
9832
+ return array();
9833
+ }
9834
+
9835
+ $licenses = array();
9836
+ foreach ( $all_licenses as $license ) {
9837
+ if ( in_array( $license->id, $user_license_ids ) ) {
9838
+ $licenses[] = $license;
9839
+ }
9840
+ }
9841
+
9842
+ return $licenses;
9843
+ }
9844
+
9845
+ /**
9846
+ * Checks if the context license is network activated except on the given blog ID.
9847
+ *
9848
+ * @author Vova Feldman (@svovaf)
9849
+ * @since 2.0.0
9850
+ *
9851
+ * @param int $except_blog_id
9852
+ *
9853
+ * @return bool
9854
+ */
9855
+ private function is_license_network_active( $except_blog_id = 0 ) {
9856
+ $this->_logger->entrance();
9857
+
9858
+ if ( ! is_object( $this->_license ) ) {
9859
+ return false;
9860
+ }
9861
+
9862
+ $sites = self::get_sites();
9863
+
9864
+ if ( $this->_license->total_activations() < ( count( $sites ) - 1 ) ) {
9865
+ // There are more sites than the number of activations, so license cannot be network activated.
9866
+ return false;
9867
+ }
9868
+
9869
+ foreach ( $sites as $site ) {
9870
+ $blog_id = self::get_site_blog_id( $site );
9871
+
9872
+ if ( $except_blog_id == $blog_id ) {
9873
+ // Skip excluded blog.
9874
+ continue;
9875
+ }
9876
+
9877
+ $install = $this->get_install_by_blog_id( $blog_id );
9878
+
9879
+ if ( is_object( $install ) && $install->license_id != $this->_license->id ) {
9880
+ return false;
9881
+ }
9882
+ }
9883
+
9884
+ return true;
9885
+ }
9886
+
9887
+ /**
9888
+ * Checks if license can be activated on all the network sites (opted-in or skipped) that are not yet associated with a license. If possible, try to make the activation, if not return false.
9889
+ *
9890
+ * Notice: On success, this method will also update the license activations counters (without updating the license in the storage).
9891
+ *
9892
+ * @author Vova Feldman (@svovaf)
9893
+ * @since 2.0.0
9894
+ *
9895
+ * @param \FS_User $user
9896
+ * @param \FS_Plugin_License $license
9897
+ *
9898
+ * @return bool
9899
+ */
9900
+ private function try_activate_license_on_network( FS_User $user, FS_Plugin_License $license ) {
9901
+ $this->_logger->entrance();
9902
+
9903
+ $result = $this->can_activate_license_on_network( $license );
9904
+
9905
+ if ( false === $result ) {
9906
+ return false;
9907
+ }
9908
+
9909
+ $installs_without_license = $result['installs'];
9910
+ if ( ! empty( $installs_without_license ) ) {
9911
+ $this->activate_license_on_many_installs( $user, $license->secret_key, $installs_without_license );
9912
+ }
9913
+
9914
+ $disconnected_site_ids = $result['sites'];
9915
+ if ( ! empty( $disconnected_site_ids ) ) {
9916
+ $this->activate_license_on_many_sites( $user, $license->secret_key, $disconnected_site_ids );
9917
+ }
9918
+
9919
+ $this->link_license_2_user( $license->id, $user->id );
9920
+
9921
+ // Sync license after activations.
9922
+ $license->activated += $result['production_count'];
9923
+ $license->activated_local += $result['localhost_count'];
9924
+
9925
+ // $this->_store_licenses()
9926
+
9927
+ return true;
9928
+ }
9929
+
9930
+ /**
9931
+ * Checks if the given license can be activated on the whole network.
9932
+ *
9933
+ * @author Vova Feldman (@svovaf)
9934
+ * @since 2.0.0
9935
+ *
9936
+ * @param \FS_Plugin_License $license
9937
+ *
9938
+ * @return false|array {
9939
+ * @type array[int]FS_Site $installs Blog ID to install map.
9940
+ * @type int[] $sites Non-connected blog IDs.
9941
+ * @type int $production_count Production sites count.
9942
+ * @type int $localhost_count Production sites count.
9943
+ * }
9944
+ */
9945
+ private function can_activate_license_on_network( FS_Plugin_License $license ) {
9946
+ $sites = self::get_sites();
9947
+
9948
+ $production_count = 0;
9949
+ $localhost_count = 0;
9950
+
9951
+ $installs_without_license = array();
9952
+ $disconnected_site_ids = array();
9953
+
9954
+ foreach ( $sites as $site ) {
9955
+ $blog_id = self::get_site_blog_id( $site );
9956
+ $install = $this->get_install_by_blog_id( $blog_id );
9957
+
9958
+ if ( is_object( $install ) ) {
9959
+ if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
9960
+ // License already activated on the install.
9961
+ continue;
9962
+ }
9963
+
9964
+ $url = $install->url;
9965
+
9966
+ $installs_without_license[ $blog_id ] = $install;
9967
+ } else {
9968
+ $url = is_object( $site ) ?
9969
+ $site->siteurl :
9970
+ get_site_url( $blog_id );
9971
+
9972
+ $disconnected_site_ids[] = $blog_id;
9973
+ }
9974
+
9975
+ if ( FS_Site::is_localhost_by_address( $url ) ) {
9976
+ $localhost_count ++;
9977
+ } else {
9978
+ $production_count ++;
9979
+ }
9980
+ }
9981
+
9982
+ if ( ! $license->can_activate_bulk( $production_count, $localhost_count ) ) {
9983
+ return false;
9984
+ }
9985
+
9986
+ return array(
9987
+ 'installs' => $installs_without_license,
9988
+ 'sites' => $disconnected_site_ids,
9989
+ 'production_count' => $production_count,
9990
+ 'localhost_count' => $localhost_count,
9991
+ );
9992
+ }
9993
+
9994
+ /**
9995
+ * Activate a given license on a collection of installs.
9996
+ *
9997
+ * @author Vova Feldman (@svovaf)
9998
+ * @since 2.0.0
9999
+ *
10000
+ * @param \FS_User $user
10001
+ * @param string $license_key
10002
+ * @param array $blog_2_install_map {
10003
+ * @key int Blog ID.
10004
+ * @value FS_Site Blog's associated install.
10005
+ * }
10006
+ *
10007
+ * @return mixed|true
10008
+ */
10009
+ private function activate_license_on_many_installs(
10010
+ FS_User $user,
10011
+ $license_key,
10012
+ array $blog_2_install_map
10013
+ ) {
10014
+ $params = array(
10015
+ array( 'license_key' => $this->apply_filters( 'license_key', $license_key ) )
10016
+ );
10017
+
10018
+ $install_2_blog_map = array();
10019
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
10020
+ $params[] = array( 'id' => $install->id );
10021
+
10022
+ $install_2_blog_map[ $install->id ] = $blog_id;
10023
+ }
10024
+
10025
+ $result = $this->get_api_user_scope_by_user( $user )->call(
10026
+ "plugins/{$this->_plugin->id}/installs.json",
10027
+ 'PUT',
10028
+ $params
10029
+ );
10030
+
10031
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
10032
+ return $result;
10033
+ }
10034
+
10035
+ foreach ( $result->installs as $r_install ) {
10036
+ $install = new FS_Site( $r_install );
10037
+ $install->is_disconnected = false;
10038
+
10039
+ // Update install.
10040
+ $this->_store_site(
10041
+ true,
10042
+ $install_2_blog_map[ $r_install->id ],
10043
+ $install
10044
+ );
10045
+ }
10046
+
10047
+ return true;
10048
+ }
10049
+
10050
+ /**
10051
+ * Activate a given license on a collection of blogs/sites that are not yet opted-in.
10052
+ *
10053
+ * @author Vova Feldman (@svovaf)
10054
+ * @since 2.0.0
10055
+ *
10056
+ * @param \FS_User $user
10057
+ * @param string $license_key
10058
+ * @param int[] $site_ids
10059
+ *
10060
+ * @return true|mixed True if successful, otherwise, the API result.
10061
+ */
10062
+ private function activate_license_on_many_sites(
10063
+ FS_User $user,
10064
+ $license_key,
10065
+ array $site_ids
10066
+ ) {
10067
+ $sites = array();
10068
+ foreach ( $site_ids as $site_id ) {
10069
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
10070
+ }
10071
+
10072
+ // Install the plugin.
10073
+ $result = $this->create_installs_with_user(
10074
+ $user,
10075
+ $license_key,
10076
+ false,
10077
+ $sites,
10078
+ false,
10079
+ true
10080
+ );
10081
+
10082
+ if ( ! $this->is_api_result_entity( $result ) &&
10083
+ ! $this->is_api_result_object( $result, 'installs' )
10084
+ ) {
10085
+ return $result;
10086
+ }
10087
+
10088
+ $installs = array();
10089
+ foreach ( $result->installs as $install ) {
10090
+ $installs[] = new FS_Site( $install );
10091
+ }
10092
+
10093
+ // Map site addresses to their blog IDs.
10094
+ $address_to_blog_map = $this->get_address_to_blog_map();
10095
+
10096
+ $first_blog_id = null;
10097
+
10098
+ foreach ( $installs as $install ) {
10099
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
10100
+ $blog_id = $address_to_blog_map[ $address ];
10101
+
10102
+ $this->_store_site( true, $blog_id, $install );
10103
+
10104
+ $this->reset_anonymous_mode( $blog_id );
10105
+
10106
+ if ( is_null( $first_blog_id ) ) {
10107
+ $first_blog_id = $blog_id;
10108
+ }
10109
+ }
10110
+
10111
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
10112
+ $this->_storage->network_install_blog_id = $first_blog_id;
10113
+ }
10114
+
10115
+ return true;
10116
+ }
10117
+
10118
+ /**
10119
+ * Sync site's license with user licenses.
10120
+ *
10121
+ * @author Vova Feldman (@svovaf)
10122
+ * @since 1.0.6
10123
+ *
10124
+ * @param FS_Plugin_License|null $new_license
10125
+ *
10126
+ * @return FS_Plugin_License|null
10127
+ */
10128
+ function _update_site_license( $new_license ) {
10129
+ $this->_logger->entrance();
10130
+
10131
+ $this->_license = $new_license;
10132
+
10133
+ if ( ! is_object( $new_license ) ) {
10134
+ $this->_site->license_id = null;
10135
+ $this->_sync_site_subscription( null );
10136
+
10137
+ return $this->_license;
10138
+ }
10139
+
10140
+ $this->_site->license_id = $this->_license->id;
10141
+
10142
+ if ( ! is_array( $this->_licenses ) ) {
10143
+ $this->_licenses = array();
10144
+ }
10145
+
10146
+ $is_license_found = false;
10147
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
10148
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
10149
+ $this->_licenses[ $i ] = $new_license;
10150
+
10151
+ $is_license_found = true;
10152
+ break;
10153
+ }
10154
+ }
10155
+
10156
+ // If new license just append.
10157
+ if ( ! $is_license_found ) {
10158
+ $this->_licenses[] = $new_license;
10159
+ }
10160
+
10161
+ $this->_sync_site_subscription( $new_license );
10162
+
10163
+ return $this->_license;
10164
+ }
10165
+
10166
+ /**
10167
+ * Sync site's subscription.
10168
+ *
10169
+ * @author Vova Feldman (@svovaf)
10170
+ * @since 1.0.9
10171
+ *
10172
+ * @param FS_Plugin_License|null $license
10173
+ *
10174
+ * @return bool|\FS_Subscription
10175
+ */
10176
+ private function _sync_site_subscription( $license ) {
10177
+ if ( ! is_object( $license ) ) {
10178
+ $this->delete_unused_subscriptions();
10179
+
10180
+ return false;
10181
+ }
10182
+
10183
+ // Load subscription details if not lifetime.
10184
+ $subscription = $license->is_lifetime() ?
10185
+ false :
10186
+ $this->_fetch_site_license_subscription();
10187
+
10188
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
10189
+ $this->store_subscription( $subscription );
10190
+ } else {
10191
+ $this->delete_unused_subscriptions();
10192
+ }
10193
+
10194
+ return $subscription;
10195
+ }
10196
+
10197
+ /**
10198
+ * @author Vova Feldman (@svovaf)
10199
+ * @since 1.0.6
10200
+ *
10201
+ * @return bool|\FS_Plugin_License
10202
+ */
10203
+ function _get_license() {
10204
+ if ( ! fs_is_network_admin() || is_object( $this->_license ) ) {
10205
+ return $this->_license;
10206
+ }
10207
+
10208
+ return $this->_get_available_premium_license();
10209
+ }
10210
+
10211
+ /**
10212
+ * @param number $license_id
10213
+ *
10214
+ * @return null|\FS_Subscription
10215
+ */
10216
+ function _get_subscription( $license_id ) {
10217
+ if ( ! isset( $this->_storage->subscriptions ) ||
10218
+ empty( $this->_storage->subscriptions )
10219
+ ) {
10220
+ return null;
10221
+ }
10222
+
10223
+ foreach ( $this->_storage->subscriptions as $subscription ) {
10224
+ if ( $subscription->license_id == $license_id ) {
10225
+ return $subscription;
10226
+ }
10227
+ }
10228
+
10229
+ return null;
10230
+ }
10231
+
10232
+ /**
10233
+ * @author Leo Fajardo (@leorw)
10234
+ * @since 2.0.0
10235
+ *
10236
+ * @param FS_Subscription $subscription
10237
+ */
10238
+ function store_subscription( FS_Subscription $subscription ) {
10239
+ if ( ! isset( $this->_storage->subscriptions ) ) {
10240
+ $this->_storage->subscriptions = array();
10241
+ }
10242
+
10243
+ if ( empty( $this->_storage->subscriptions ) || ! is_multisite() ) {
10244
+ $this->_storage->subscriptions = array( $subscription );
10245
+
10246
+ return;
10247
+ }
10248
+
10249
+ $subscriptions = $this->_storage->subscriptions;
10250
+
10251
+ $updated_subscription = false;
10252
+ foreach ( $subscriptions as $key => $existing_subscription ) {
10253
+ if ( $existing_subscription->id == $subscription->id ) {
10254
+ $subscriptions[ $key ] = $subscription;
10255
+ $updated_subscription = true;
10256
+ break;
10257
+ }
10258
+ }
10259
+
10260
+ if ( ! $updated_subscription ) {
10261
+ $subscriptions[] = $subscription;
10262
+ }
10263
+
10264
+ $this->_storage->subscriptions = $subscriptions;
10265
+ }
10266
+
10267
+ /**
10268
+ * @author Leo Fajardo (@leorw)
10269
+ * @since 2.0.0
10270
+ */
10271
+ function delete_unused_subscriptions() {
10272
+ if ( ! isset( $this->_storage->subscriptions ) ||
10273
+ empty( $this->_storage->subscriptions ) ||
10274
+ // Clean up only if there are already at least 3 subscriptions.
10275
+ ( count( $this->_storage->subscriptions ) < 3 )
10276
+ ) {
10277
+ return;
10278
+ }
10279
+
10280
+ if ( ! is_multisite() ) {
10281
+ // If not multisite, there should only be 1 subscription, so just clear the array.
10282
+ $this->_storage->subscriptions = array();
10283
+
10284
+ return;
10285
+ }
10286
+
10287
+ $subscriptions_to_keep_by_license_id_map = array();
10288
+ $sites = self::get_sites();
10289
+ foreach ( $sites as $site ) {
10290
+ $blog_id = self::get_site_blog_id( $site );
10291
+ $install = $this->get_install_by_blog_id( $blog_id );
10292
+
10293
+ if ( ! is_object( $install ) ||
10294
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
10295
+ ) {
10296
+ continue;
10297
+ }
10298
+
10299
+ $subscriptions_to_keep_by_license_id_map[ $install->license_id ] = true;
10300
+ }
10301
+
10302
+ if ( empty( $subscriptions_to_keep_by_license_id_map ) ) {
10303
+ $this->_storage->subscriptions = array();
10304
+
10305
+ return;
10306
+ }
10307
+
10308
+ foreach ( $this->_storage->subscriptions as $key => $subscription ) {
10309
+ if ( ! isset( $subscriptions_to_keep_by_license_id_map[ $subscription->license_id ] ) ) {
10310
+ unset( $this->_storage->subscriptions[ $key ] );
10311
+ }
10312
+ }
10313
+ }
10314
+
10315
+ /**
10316
+ * @author Vova Feldman (@svovaf)
10317
+ * @since 1.0.2
10318
+ *
10319
+ * @param string $plan Plan name
10320
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
10321
+ *
10322
+ * @return bool
10323
+ */
10324
+ function is_plan( $plan, $exact = false ) {
10325
+ $this->_logger->entrance();
10326
+
10327
+ if ( ! $this->is_registered() ) {
10328
+ return false;
10329
+ }
10330
+
10331
+ $plan = strtolower( $plan );
10332
+
10333
+ $current_plan_name = $this->get_plan_name();
10334
+
10335
+ if ( $current_plan_name === $plan ) {
10336
+ // Exact plan.
10337
+ return true;
10338
+ } else if ( $exact ) {
10339
+ // Required exact, but plans are different.
10340
+ return false;
10341
+ }
10342
+
10343
+ $current_plan_order = - 1;
10344
+ $required_plan_order = - 1;
10345
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
10346
+ if ( $plan === $this->_plans[ $i ]->name ) {
10347
+ $required_plan_order = $i;
10348
+ } else if ( $current_plan_name === $this->_plans[ $i ]->name ) {
10349
+ $current_plan_order = $i;
10350
+ }
10351
+ }
10352
+
10353
+ return ( $current_plan_order > $required_plan_order );
10354
+ }
10355
+
10356
+ /**
10357
+ * Check if module has only one plan.
10358
+ *
10359
+ * @author Vova Feldman (@svovaf)
10360
+ * @since 1.2.1.7
10361
+ *
10362
+ * @return bool
10363
+ */
10364
+ function is_single_plan() {
10365
+ $this->_logger->entrance();
10366
+
10367
+ if ( ! $this->is_registered() ||
10368
+ ! is_array( $this->_plans ) ||
10369
+ 0 === count( $this->_plans )
10370
+ ) {
10371
+ return true;
10372
+ }
10373
+
10374
+ return ( 1 === count( $this->_plans ) );
10375
+ }
10376
+
10377
+ /**
10378
+ * Check if plan based on trial. If not in trial mode, should return false.
10379
+ *
10380
+ * @since 1.0.9
10381
+ *
10382
+ * @param string $plan Plan name
10383
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
10384
+ *
10385
+ * @return bool
10386
+ */
10387
+ function is_trial_plan( $plan, $exact = false ) {
10388
+ $this->_logger->entrance();
10389
+
10390
+ if ( ! $this->is_registered() ) {
10391
+ return false;
10392
+ }
10393
+
10394
+ if ( ! $this->is_trial() ) {
10395
+ return false;
10396
+ }
10397
+
10398
+ $trial_plan = $this->get_trial_plan();
10399
+
10400
+ if ( $trial_plan->name === $plan ) {
10401
+ // Exact plan.
10402
+ return true;
10403
+ } else if ( $exact ) {
10404
+ // Required exact, but plans are different.
10405
+ return false;
10406
+ }
10407
+
10408
+ $current_plan_order = - 1;
10409
+ $required_plan_order = - 1;
10410
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
10411
+ if ( $plan === $this->_plans[ $i ]->name ) {
10412
+ $required_plan_order = $i;
10413
+ } else if ( $trial_plan->name === $this->_plans[ $i ]->name ) {
10414
+ $current_plan_order = $i;
10415
+ }
10416
+ }
10417
+
10418
+ return ( $current_plan_order > $required_plan_order );
10419
+ }
10420
+
10421
+ /**
10422
+ * Check if plugin has any paid plans.
10423
+ *
10424
+ * @author Vova Feldman (@svovaf)
10425
+ * @since 1.0.7
10426
+ *
10427
+ * @return bool
10428
+ */
10429
+ function has_paid_plan() {
10430
+ return $this->_has_paid_plans ||
10431
+ FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
10432
+ }
10433
+
10434
+ /**
10435
+ * Check if plugin has any plan with a trail.
10436
+ *
10437
+ * @author Vova Feldman (@svovaf)
10438
+ * @since 1.0.9
10439
+ *
10440
+ * @return bool
10441
+ */
10442
+ function has_trial_plan() {
10443
+ /**
10444
+ * @author Vova Feldman(@svovaf)
10445
+ * @since 1.2.1.5
10446
+ *
10447
+ * Allow setting a trial from the SDK without calling the API.
10448
+ * But, if the user did opt-in, continue using the real data from the API.
10449
+ */
10450
+ if ( $this->_trial_days >= 0 ) {
10451
+ return true;
10452
+ }
10453
+
10454
+ return $this->_storage->get( 'has_trial_plan', false );
10455
+ }
10456
+
10457
+ /**
10458
+ * Check if plugin has any free plan, or is it premium only.
10459
+ *
10460
+ * Note: If no plans configured, assume plugin is free.
10461
+ *
10462
+ * @author Vova Feldman (@svovaf)
10463
+ * @since 1.0.7
10464
+ *
10465
+ * @return bool
10466
+ */
10467
+ function has_free_plan() {
10468
+ return ! $this->is_only_premium();
10469
+ }
10470
+
10471
+ /**
10472
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
10473
+ * or "Change License" link on the plugins
10474
+ * page.
10475
+ *
10476
+ * @author Leo Fajardo (@leorw)
10477
+ * @since 1.1.9
10478
+ */
10479
+ function _add_license_activation_dialog_box() {
10480
+ $vars = array(
10481
+ 'id' => $this->_module_id,
10482
+ );
10483
+
10484
+ fs_require_template( 'forms/license-activation.php', $vars );
10485
+ fs_require_template( 'forms/resend-key.php', $vars );
10486
+ }
10487
+
10488
+ /**
10489
+ * @author Leo Fajardo (@leorw)
10490
+ * @since 2.0.2
10491
+ */
10492
+ function _add_premium_version_upgrade_selection_dialog_box() {
10493
+ $modules_update = get_site_transient( $this->is_theme() ? 'update_themes' : 'update_plugins' );
10494
+ if ( ! isset( $modules_update->response[ $this->_plugin_basename ] ) ) {
10495
+ return;
10496
+ }
10497
+
10498
+ $vars = array(
10499
+ 'id' => $this->_module_id,
10500
+ 'new_version' => is_object( $modules_update->response[ $this->_plugin_basename ] ) ?
10501
+ $modules_update->response[ $this->_plugin_basename ]->new_version :
10502
+ $modules_update->response[ $this->_plugin_basename ]['new_version']
10503
+ );
10504
+
10505
+ fs_require_template( 'forms/premium-versions-upgrade-metadata.php', $vars );
10506
+ fs_require_once_template( 'forms/premium-versions-upgrade-handler.php', $vars );
10507
+ }
10508
+
10509
+ /**
10510
+ * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
10511
+ * page.
10512
+ *
10513
+ * @author Leo Fajardo (@leorw)
10514
+ * @since 1.2.1.5
10515
+ */
10516
+ function _add_optout_dialog() {
10517
+ if ( $this->is_theme() ) {
10518
+ $vars = null;
10519
+ fs_require_once_template( '/js/jquery.content-change.php', $vars );
10520
+ }
10521
+
10522
+ $vars = array( 'id' => $this->_module_id );
10523
+ fs_require_template( 'forms/optout.php', $vars );
10524
+ }
10525
+
10526
+ /**
10527
+ * Prepare page to include all required UI and logic for the license activation dialog.
10528
+ *
10529
+ * @author Vova Feldman (@svovaf)
10530
+ * @since 1.2.0
10531
+ */
10532
+ function _add_license_activation() {
10533
+ if ( ! $this->is_user_admin() ) {
10534
+ // Only admins can activate a license.
10535
+ return;
10536
+ }
10537
+
10538
+ if ( ! $this->has_paid_plan() ) {
10539
+ // Module doesn't have any paid plans.
10540
+ return;
10541
+ }
10542
+
10543
+ if ( ! $this->is_premium() ) {
10544
+ // Only add license activation logic to the premium version.
10545
+ return;
10546
+ }
10547
+
10548
+ // Add license activation link and AJAX request handler.
10549
+ if ( self::is_plugins_page() ) {
10550
+ /**
10551
+ * @since 1.2.0 Add license action link only on plugins page.
10552
+ */
10553
+ $this->_add_license_action_link();
10554
+ }
10555
+
10556
+ // Add license activation AJAX callback.
10557
+ $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
10558
+
10559
+ // Add resend license AJAX callback.
10560
+ $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
10561
+ }
10562
+
10563
+ /**
10564
+ * @author Leo Fajardo (@leorw)
10565
+ * @since 2.0.2
10566
+ */
10567
+ function _add_premium_version_upgrade_selection() {
10568
+ if ( ! $this->is_user_admin() ) {
10569
+ return;
10570
+ }
10571
+
10572
+ if ( ! $this->is_premium() || $this->has_active_valid_license() ) {
10573
+ // This is relevant only to the free versions and premium versions without an active license.
10574
+ return;
10575
+ }
10576
+
10577
+ if ( self::is_updates_page() || ( $this->is_plugin() && self::is_plugins_page() ) ) {
10578
+ $this->_add_premium_version_upgrade_selection_action();
10579
+ }
10580
+ }
10581
+
10582
+ /**
10583
+ * @author Leo Fajardo (@leorw)
10584
+ *
10585
+ * @since 1.1.9
10586
+ * @since 2.0.0 When a super-admin that hasn't connected before is network activating a license and excluding some of the sites for the license activation, go over the unselected sites in the network and if a site is not connected, skipped, nor delegated, if it's a freemium product then just skip the connection for the site, if it's a premium only product, delegate the connection and license activation to the site admin (Vova Feldman @svovaf).
10587
+ */
10588
+ function _activate_license_ajax_action() {
10589
+ $this->_logger->entrance();
10590
+
10591
+ $this->check_ajax_referer( 'activate_license' );
10592
+
10593
+ $license_key = trim( fs_request_get( 'license_key' ) );
10594
+
10595
+ if ( empty( $license_key ) ) {
10596
+ exit;
10597
+ }
10598
+
10599
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
10600
+ $fs = ( $plugin_id == $this->_module_id ) ?
10601
+ $this :
10602
+ $this->get_addon_instance( $plugin_id );
10603
+
10604
+ $error = false;
10605
+ $next_page = false;
10606
+
10607
+ $sites = fs_is_network_admin() ?
10608
+ fs_request_get( 'sites', array(), 'post' ) :
10609
+ array();
10610
+
10611
+ $blog_id = fs_request_get( 'blog_id' );
10612
+ $has_valid_blog_id = is_numeric( $blog_id );
10613
+
10614
+ if ( $fs->is_registered() ) {
10615
+ if ( fs_is_network_admin() && ! $has_valid_blog_id ) {
10616
+ // If no specific blog ID was provided, activate the license for all sites in the network.
10617
+ $blog_2_install_map = array();
10618
+ $site_ids = array();
10619
+
10620
+ foreach ( $sites as $site ) {
10621
+ if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
10622
+ continue;
10623
+ }
10624
+
10625
+ $install = $this->get_install_by_blog_id( $site['blog_id'] );
10626
+
10627
+ if ( is_object( $install ) ) {
10628
+ $blog_2_install_map[ $site['blog_id'] ] = $install;
10629
+ } else {
10630
+ $site_ids[] = $site['blog_id'];
10631
+ }
10632
+ }
10633
+
10634
+ $user = $this->get_current_or_network_user();
10635
+
10636
+ if ( ! empty( $blog_2_install_map ) ) {
10637
+ $result = $this->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
10638
+
10639
+ if ( true !== $result ) {
10640
+ $error = FS_Api::is_api_error_object( $result ) ?
10641
+ $result->error->message :
10642
+ var_export( $result, true );
10643
+ }
10644
+ }
10645
+
10646
+ if ( empty( $error ) && ! empty( $site_ids ) ) {
10647
+ $result = $this->activate_license_on_many_sites( $user, $license_key, $site_ids );
10648
+
10649
+ if ( true !== $result ) {
10650
+ $error = FS_Api::is_api_error_object( $result ) ?
10651
+ $result->error->message :
10652
+ var_export( $result, true );
10653
+ }
10654
+ }
10655
+ } else {
10656
+ if ( $has_valid_blog_id ) {
10657
+ /**
10658
+ * If a specific blog ID was provided, activate the license only for the install that is
10659
+ * associated with the given blog ID.
10660
+ *
10661
+ * @author Leo Fajardo (@leorw)
10662
+ */
10663
+ $this->switch_to_blog( $blog_id );
10664
+ }
10665
+
10666
+ $api = $fs->get_api_site_scope();
10667
+
10668
+ $params = array(
10669
+ 'license_key' => $fs->apply_filters( 'license_key', $license_key )
10670
+ );
10671
+
10672
+ $install = $api->call( '/', 'put', $params );
10673
+
10674
+ if ( FS_Api::is_api_error( $install ) ) {
10675
+ $error = FS_Api::is_api_error_object( $install ) ?
10676
+ $install->error->message :
10677
+ var_export( $install->error, true );
10678
+ } else {
10679
+ $fs->reconnect_locally( $has_valid_blog_id );
10680
+ }
10681
+ }
10682
+
10683
+ if ( empty( $error ) ) {
10684
+ $this->network_upgrade_mode_completed();
10685
+
10686
+ $fs->_sync_license( true, $has_valid_blog_id );
10687
+
10688
+ $next_page = $fs->is_addon() ?
10689
+ $fs->get_parent_instance()->get_account_url() :
10690
+ $fs->get_account_url();
10691
+ }
10692
+ } else {
10693
+ $next_page = $fs->opt_in(
10694
+ false,
10695
+ false,
10696
+ false,
10697
+ $license_key,
10698
+ false,
10699
+ false,
10700
+ false,
10701
+ fs_request_get_bool( 'is_marketing_allowed', null ),
10702
+ $sites
10703
+ );
10704
+
10705
+ if ( isset( $next_page->error ) ) {
10706
+ $error = $next_page->error;
10707
+ } else {
10708
+ if ( fs_is_network_admin() ) {
10709
+ /**
10710
+ * Get the list of sites that were just opted-in (and license activated).
10711
+ * This is an optimization for the next part below saving some DB queries.
10712
+ */
10713
+ $connected_sites = array();
10714
+ foreach ( $sites as $site ) {
10715
+ if ( isset( $site['blog_id'] ) && is_numeric( $site['blog_id'] ) ) {
10716
+ $connected_sites[ $site['blog_id'] ] = true;
10717
+ }
10718
+ }
10719
+
10720
+ $all_sites = self::get_sites();
10721
+ $pending_sites = array();
10722
+
10723
+ /**
10724
+ * Check if there are any sites that are not connected, skipped, nor delegated. For every site that falls into that category, if the product is freemium, skip the connection. If the product is premium only, delegate the connection to the site administrator.
10725
+ *
10726
+ * @author Vova Feldman (@svovaf)
10727
+ */
10728
+ foreach ( $all_sites as $site ) {
10729
+ $blog_id = self::get_site_blog_id( $site );
10730
+
10731
+ if ( isset( $connected_sites[ $blog_id ] ) ) {
10732
+ // Site was just connected.
10733
+ continue;
10734
+ }
10735
+
10736
+ if ( $this->is_installed_on_site( $blog_id ) ) {
10737
+ // Site was already connected before.
10738
+ continue;
10739
+ }
10740
+
10741
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
10742
+ // Site's connection was delegated.
10743
+ continue;
10744
+ }
10745
+
10746
+ if ( $this->is_anonymous_site( $blog_id ) ) {
10747
+ // Site connection was already skipped.
10748
+ continue;
10749
+ }
10750
+
10751
+ $pending_sites[] = self::get_site_info( $site );
10752
+ }
10753
+
10754
+ if ( ! empty( $pending_sites ) ) {
10755
+ if ( $this->is_freemium() ) {
10756
+ $this->skip_connection( $pending_sites );
10757
+ } else {
10758
+ $this->delegate_connection( $pending_sites );
10759
+ }
10760
+ }
10761
+ }
10762
+ }
10763
+ }
10764
+
10765
+ $result = array(
10766
+ 'success' => ( false === $error )
10767
+ );
10768
+
10769
+ if ( false !== $error ) {
10770
+ $result['error'] = $error;
10771
+ } else {
10772
+ $result['next_page'] = $next_page;
10773
+ }
10774
+
10775
+ echo json_encode( $result );
10776
+
10777
+ exit;
10778
+ }
10779
+
10780
+ /**
10781
+ * @author Leo Fajardo (@leorw)
10782
+ * @since 1.2.3.1
10783
+ */
10784
+ function _network_activate_ajax_action() {
10785
+ $this->_logger->entrance();
10786
+
10787
+ $this->check_ajax_referer( 'network_activate' );
10788
+
10789
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
10790
+ $fs = ( $plugin_id == $this->_module_id ) ?
10791
+ $this :
10792
+ $this->get_addon_instance( $plugin_id );
10793
+
10794
+ $error = false;
10795
+
10796
+ $sites = fs_request_get( 'sites', array(), 'post' );
10797
+ if ( is_array( $sites ) && ! empty( $sites ) ) {
10798
+ $sites_by_action = array(
10799
+ 'allow' => array(),
10800
+ 'delegate' => array(),
10801
+ 'skip' => array()
10802
+ );
10803
+
10804
+ foreach ( $sites as $site ) {
10805
+ $sites_by_action[ $site['action'] ][] = $site;
10806
+ }
10807
+
10808
+ $total_sites = count( $sites );
10809
+ $total_sites_to_delegate = count( $sites_by_action['delegate'] );
10810
+
10811
+ $next_page = '';
10812
+ if ( $total_sites === $total_sites_to_delegate &&
10813
+ ! $this->is_network_upgrade_mode()
10814
+ ) {
10815
+ $this->delegate_connection();
10816
+ } else {
10817
+ if ( ! empty( $sites_by_action['delegate'] ) ) {
10818
+ $this->delegate_connection( $sites_by_action['delegate'] );
10819
+ }
10820
+
10821
+ if ( ! empty( $sites_by_action['skip'] ) ) {
10822
+ $this->skip_connection( $sites_by_action['skip'] );
10823
+ }
10824
+
10825
+ if ( ! empty( $sites_by_action['allow'] ) ) {
10826
+ if ( ! $fs->is_registered() || ! $this->_is_network_active ) {
10827
+ $next_page = $fs->opt_in(
10828
+ false,
10829
+ false,
10830
+ false,
10831
+ false,
10832
+ false,
10833
+ false,
10834
+ false,
10835
+ fs_request_get_bool( 'is_marketing_allowed', null ),
10836
+ $sites_by_action['allow']
10837
+ );
10838
+ } else {
10839
+ $next_page = $fs->install_with_user(
10840
+ $this->get_network_user(),
10841
+ false,
10842
+ false,
10843
+ false,
10844
+ true,
10845
+ $sites_by_action['allow']
10846
+ );
10847
+ }
10848
+
10849
+ if ( is_object( $next_page ) && isset( $next_page->error ) ) {
10850
+ $error = $next_page->error;
10851
+ }
10852
+ }
10853
+ }
10854
+
10855
+ if ( empty( $next_page ) ) {
10856
+ $next_page = $this->get_after_activation_url( 'after_network_activation_url' );
10857
+ }
10858
+ } else {
10859
+ $error = $this->get_text_inline( 'Invalid site details collection.', 'invalid_site_details_collection' );
10860
+ }
10861
+
10862
+ $result = array(
10863
+ 'success' => ( false === $error )
10864
+ );
10865
+
10866
+ if ( false !== $error ) {
10867
+ $result['error'] = $error;
10868
+ } else {
10869
+ $result['next_page'] = $next_page;
10870
+ }
10871
+
10872
+ echo json_encode( $result );
10873
+
10874
+ exit;
10875
+ }
10876
+
10877
+ /**
10878
+ * Billing update AJAX callback.
10879
+ *
10880
+ * @author Vova Feldman (@svovaf)
10881
+ * @since 1.2.1.5
10882
+ */
10883
+ function _update_billing_ajax_action() {
10884
+ $this->_logger->entrance();
10885
+
10886
+ $this->check_ajax_referer( 'update_billing' );
10887
+
10888
+ if ( ! $this->is_user_admin() ) {
10889
+ // Only for admins.
10890
+ self::shoot_ajax_failure();
10891
+ }
10892
+
10893
+ $billing = fs_request_get( 'billing' );
10894
+
10895
+ $api = $this->get_api_user_scope();
10896
+ $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
10897
+ 'plugin_id' => $this->get_parent_id(),
10898
+ ) ) );
10899
+
10900
+ if ( ! $this->is_api_result_entity( $result ) ) {
10901
+ self::shoot_ajax_failure();
10902
+ }
10903
+
10904
+ // Purge cached billing.
10905
+ $this->get_api_user_scope()->purge_cache( 'billing.json' );
10906
+
10907
+ self::shoot_ajax_success();
10908
+ }
10909
+
10910
+ /**
10911
+ * Trial start for anonymous users (AJAX callback).
10912
+ *
10913
+ * @author Vova Feldman (@svovaf)
10914
+ * @since 1.2.1.5
10915
+ */
10916
+ function _start_trial_ajax_action() {
10917
+ $this->_logger->entrance();
10918
+
10919
+ $this->check_ajax_referer( 'start_trial' );
10920
+
10921
+ if ( ! $this->is_user_admin() ) {
10922
+ // Only for admins.
10923
+ self::shoot_ajax_failure();
10924
+ }
10925
+
10926
+ $trial_data = fs_request_get( 'trial' );
10927
+
10928
+ $next_page = $this->opt_in(
10929
+ false,
10930
+ false,
10931
+ false,
10932
+ false,
10933
+ false,
10934
+ $trial_data['plan_id']
10935
+ );
10936
+
10937
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
10938
+ self::shoot_ajax_failure(
10939
+ isset( $next_page->error ) ?
10940
+ $next_page->error->message :
10941
+ var_export( $next_page, true )
10942
+ );
10943
+ }
10944
+
10945
+ $this->shoot_ajax_success( array(
10946
+ 'next_page' => $next_page,
10947
+ ) );
10948
+ }
10949
+
10950
+ /**
10951
+ * @author Leo Fajardo (@leorw)
10952
+ * @since 1.2.0
10953
+ */
10954
+ function _resend_license_key_ajax_action() {
10955
+ $this->_logger->entrance();
10956
+
10957
+ $this->check_ajax_referer( 'resend_license_key' );
10958
+
10959
+ $email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
10960
+
10961
+ if ( empty( $email_address ) ) {
10962
+ exit;
10963
+ }
10964
+
10965
+ $error = false;
10966
+
10967
+ $api = $this->get_api_plugin_scope();
10968
+ $result = $api->call( '/licenses/resend.json', 'post',
10969
+ array(
10970
+ 'email' => $email_address,
10971
+ 'url' => home_url(),
10972
+ )
10973
+ );
10974
+
10975
+ if ( is_object( $result ) && isset( $result->error ) ) {
10976
+ $error = $result->error;
10977
+
10978
+ if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
10979
+ $error = $this->get_text_inline( "We couldn't find your email address in the system, are you sure it's the right address?", 'email-not-found' );
10980
+ } else if ( 'no_license' === $error->code ) {
10981
+ $error = $this->get_text_inline( "We can't see any active licenses associated with that email address, are you sure it's the right address?", 'no-active-licenses' );
10982
+ } else {
10983
+ $error = $error->message;
10984
+ }
10985
+ }
10986
+
10987
+ $licenses = array(
10988
+ 'success' => ( false === $error )
10989
+ );
10990
+
10991
+ if ( false !== $error ) {
10992
+ $licenses['error'] = sprintf( '%s... %s', $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ), strtolower( $error ) );
10993
+ }
10994
+
10995
+ echo json_encode( $licenses );
10996
+
10997
+ exit;
10998
+ }
10999
+
11000
+ /**
11001
+ * @author Vova Feldman (@svovaf)
11002
+ * @since 1.2.1.8
11003
+ *
11004
+ * @var string
11005
+ */
11006
+ private static $_pagenow;
11007
+
11008
+ /**
11009
+ * Get current page or the referer if executing a WP AJAX request.
11010
+ *
11011
+ * @author Vova Feldman (@svovaf)
11012
+ * @since 1.2.1.8
11013
+ *
11014
+ * @return string
11015
+ */
11016
+ static function get_current_page() {
11017
+ if ( ! isset( self::$_pagenow ) ) {
11018
+ global $pagenow;
11019
+
11020
+ self::$_pagenow = $pagenow;
11021
+
11022
+ if ( self::is_ajax() &&
11023
+ 'admin-ajax.php' === $pagenow
11024
+ ) {
11025
+ $referer = fs_get_raw_referer();
11026
+
11027
+ if ( is_string( $referer ) ) {
11028
+ $parts = explode( '?', $referer );
11029
+
11030
+ self::$_pagenow = basename( $parts[0] );
11031
+ }
11032
+ }
11033
+ }
11034
+
11035
+ return self::$_pagenow;
11036
+ }
11037
+
11038
+ /**
11039
+ * Helper method to check if user in the plugins page.
11040
+ *
11041
+ * @author Vova Feldman (@svovaf)
11042
+ * @since 1.2.1.5
11043
+ *
11044
+ * @return bool
11045
+ */
11046
+ static function is_plugins_page() {
11047
+ return ( 'plugins.php' === self::get_current_page() );
11048
+ }
11049
+
11050
+ /**
11051
+ * @author Leo Fajardo (@leorw)
11052
+ * @since 2.0.2
11053
+ *
11054
+ * @return bool
11055
+ */
11056
+ static function is_updates_page() {
11057
+ return ( 'update-core.php' === self::get_current_page() );
11058
+ }
11059
+
11060
+ /**
11061
+ * Helper method to check if user in the themes page.
11062
+ *
11063
+ * @author Vova Feldman (@svovaf)
11064
+ * @since 1.2.2.6
11065
+ *
11066
+ * @return bool
11067
+ */
11068
+ static function is_themes_page() {
11069
+ return ( 'themes.php' === self::get_current_page() );
11070
+ }
11071
+
11072
+ #----------------------------------------------------------------------------------
11073
+ #region Affiliation
11074
+ #----------------------------------------------------------------------------------
11075
+
11076
+ /**
11077
+ * @author Leo Fajardo (@leorw)
11078
+ * @since 1.2.3
11079
+ *
11080
+ * @return bool
11081
+ */
11082
+ function has_affiliate_program() {
11083
+ if ( ! is_object( $this->_plugin ) ) {
11084
+ return false;
11085
+ }
11086
+
11087
+ return $this->_plugin->has_affiliate_program();
11088
+ }
11089
+
11090
+ /**
11091
+ * @author Leo Fajardo (@leorw)
11092
+ * @since 1.2.4
11093
+ */
11094
+ private function fetch_affiliate_terms() {
11095
+ if ( ! is_object( $this->plugin_affiliate_terms ) ) {
11096
+ $plugins_api = $this->get_api_plugin_scope();
11097
+ $affiliate_terms = $plugins_api->get( '/aff.json?type=affiliation', false );
11098
+
11099
+ if ( ! $this->is_api_result_entity( $affiliate_terms ) ) {
11100
+ return;
11101
+ }
11102
+
11103
+ $this->plugin_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
11104
+ }
11105
+ }
11106
+
11107
+ /**
11108
+ * @author Leo Fajardo (@leorw)
11109
+ * @since 1.2.4
11110
+ */
11111
+ private function fetch_affiliate_and_custom_terms() {
11112
+ if ( ! empty( $this->_storage->affiliate_application_data ) ) {
11113
+ $application_data = $this->_storage->affiliate_application_data;
11114
+ $flush = ( ! isset( $application_data['status'] ) || 'pending' === $application_data['status'] );
11115
+
11116
+ $users_api = $this->get_api_user_scope();
11117
+ $result = $users_api->get( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json", $flush );
11118
+ if ( $this->is_api_result_object( $result, 'affiliates' ) ) {
11119
+ if ( ! empty( $result->affiliates ) ) {
11120
+ $affiliate = new FS_Affiliate( $result->affiliates[0] );
11121
+
11122
+ if ( ! isset( $application_data['status'] ) || $application_data['status'] !== $affiliate->status ) {
11123
+ $application_data['status'] = $affiliate->status;
11124
+ $this->_storage->affiliate_application_data = $application_data;
11125
+ }
11126
+
11127
+ if ( $affiliate->is_using_custom_terms ) {
11128
+ $affiliate_terms = $users_api->get( "/plugins/{$this->_plugin->id}/affiliates/{$affiliate->id}/aff/{$affiliate->custom_affiliate_terms_id}.json", $flush );
11129
+ if ( $this->is_api_result_entity( $affiliate_terms ) ) {
11130
+ $this->custom_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
11131
+ }
11132
+ }
11133
+
11134
+ $this->affiliate = $affiliate;
11135
+ }
11136
+ }
11137
+ }
11138
+ }
11139
+
11140
+ /**
11141
+ * @author Leo Fajardo (@leorw)
11142
+ * @since 1.2.3
11143
+ */
11144
+ private function fetch_affiliate_and_terms() {
11145
+ $this->_logger->entrance();
11146
+
11147
+ $this->fetch_affiliate_terms();
11148
+ $this->fetch_affiliate_and_custom_terms();
11149
+ }
11150
+
11151
+ /**
11152
+ * @author Leo Fajardo (@leorw)
11153
+ * @since 1.2.3
11154
+ *
11155
+ * @return FS_Affiliate
11156
+ */
11157
+ function get_affiliate() {
11158
+ return $this->affiliate;
11159
+ }
11160
+
11161
+
11162
+ /**
11163
+ * @author Leo Fajardo (@leorw)
11164
+ * @since 1.2.3
11165
+ *
11166
+ * @return FS_AffiliateTerms
11167
+ */
11168
+ function get_affiliate_terms() {
11169
+ return is_object( $this->custom_affiliate_terms ) ?
11170
+ $this->custom_affiliate_terms :
11171
+ $this->plugin_affiliate_terms;
11172
+ }
11173
+
11174
+ /**
11175
+ * @author Leo Fajardo (@leorw)
11176
+ * @since 1.2.3
11177
+ */
11178
+ function _submit_affiliate_application() {
11179
+ $this->_logger->entrance();
11180
+
11181
+ $this->check_ajax_referer( 'submit_affiliate_application' );
11182
+
11183
+ if ( ! $this->is_user_admin() ) {
11184
+ // Only for admins.
11185
+ self::shoot_ajax_failure();
11186
+ }
11187
+
11188
+ $affiliate = fs_request_get( 'affiliate' );
11189
+
11190
+ if ( empty( $affiliate['promotion_methods'] ) ) {
11191
+ unset( $affiliate['promotion_methods'] );
11192
+ }
11193
+
11194
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
11195
+ $affiliate['additional_domains'] = array_unique( $affiliate['additional_domains'] );
11196
+ }
11197
+
11198
+ if ( ! $this->is_registered() ) {
11199
+ // Opt in but don't track usage.
11200
+ $next_page = $this->opt_in(
11201
+ false,
11202
+ false,
11203
+ false,
11204
+ false,
11205
+ false,
11206
+ false,
11207
+ true
11208
+ );
11209
+
11210
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
11211
+ self::shoot_ajax_failure(
11212
+ isset( $next_page->error ) ?
11213
+ $next_page->error->message :
11214
+ var_export( $next_page, true )
11215
+ );
11216
+ } else if ( $this->is_pending_activation() ) {
11217
+ self::shoot_ajax_failure( $this->get_text_inline( 'Account is pending activation.', 'account-is-pending-activation' ) );
11218
+ }
11219
+ }
11220
+
11221
+ $this->fetch_affiliate_terms();
11222
+
11223
+ $api = $this->get_api_user_scope();
11224
+ $result = $api->call(
11225
+ ( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json" ),
11226
+ 'post',
11227
+ $affiliate
11228
+ );
11229
+
11230
+ if ( $this->is_api_error( $result ) ) {
11231
+ self::shoot_ajax_failure(
11232
+ isset( $result->error ) ?
11233
+ $result->error->message :
11234
+ var_export( $result, true )
11235
+ );
11236
+ } else {
11237
+ if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
11238
+ $this->_admin_notices->remove_sticky( 'affiliate_program' );
11239
+ }
11240
+
11241
+ $affiliate_application_data = array(
11242
+ 'status' => 'pending',
11243
+ 'stats_description' => $affiliate['stats_description'],
11244
+ 'promotion_method_description' => $affiliate['promotion_method_description'],
11245
+ );
11246
+
11247
+ if ( ! empty( $affiliate['promotion_methods'] ) ) {
11248
+ $affiliate_application_data['promotion_methods'] = $affiliate['promotion_methods'];
11249
+ }
11250
+
11251
+ if ( ! empty( $affiliate['domain'] ) ) {
11252
+ $affiliate_application_data['domain'] = $affiliate['domain'];
11253
+ }
11254
+
11255
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
11256
+ $affiliate_application_data['additional_domains'] = $affiliate['additional_domains'];
11257
+ }
11258
+
11259
+ $this->_storage->affiliate_application_data = $affiliate_application_data;
11260
+ }
11261
+
11262
+ // Purge cached affiliate.
11263
+ $api->purge_cache( 'affiliate.json' );
11264
+
11265
+ self::shoot_ajax_success( $result );
11266
+ }
11267
+
11268
+ /**
11269
+ * @author Leo Fajardo (@leorw)
11270
+ * @since 1.2.3
11271
+ *
11272
+ * @return array|null
11273
+ */
11274
+ function get_affiliate_application_data() {
11275
+ if ( empty( $this->_storage->affiliate_application_data ) ) {
11276
+ return null;
11277
+ }
11278
+
11279
+ return $this->_storage->affiliate_application_data;
11280
+ }
11281
+
11282
+ #endregion Affiliation ------------------------------------------------------------
11283
+
11284
+ #----------------------------------------------------------------------------------
11285
+ #region URL Generators
11286
+ #----------------------------------------------------------------------------------
11287
+
11288
+ /**
11289
+ * Alias to pricing_url().
11290
+ *
11291
+ * @author Vova Feldman (@svovaf)
11292
+ * @since 1.0.2
11293
+ *
11294
+ * @uses pricing_url()
11295
+ *
11296
+ * @param string $period Billing cycle
11297
+ * @param bool $is_trial
11298
+ *
11299
+ * @return string
11300
+ */
11301
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
11302
+ return $this->pricing_url( $period, $is_trial );
11303
+ }
11304
+
11305
+ /**
11306
+ * @author Vova Feldman (@svovaf)
11307
+ * @since 1.0.9
11308
+ *
11309
+ * @uses get_upgrade_url()
11310
+ *
11311
+ * @return string
11312
+ */
11313
+ function get_trial_url() {
11314
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
11315
+ }
11316
+
11317
+ /**
11318
+ * Plugin's pricing URL.
11319
+ *
11320
+ * @author Vova Feldman (@svovaf)
11321
+ * @since 1.0.4
11322
+ *
11323
+ * @param string $billing_cycle Billing cycle
11324
+ *
11325
+ * @param bool $is_trial
11326
+ *
11327
+ * @return string
11328
+ */
11329
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
11330
+ $this->_logger->entrance();
11331
+
11332
+ $params = array(
11333
+ 'billing_cycle' => $billing_cycle
11334
+ );
11335
+
11336
+ if ( $is_trial ) {
11337
+ $params['trial'] = 'true';
11338
+ }
11339
+
11340
+ if ( $this->is_addon() ) {
11341
+ return $this->_parent->addon_url( $this->_slug );
11342
+ }
11343
+
11344
+ return $this->_get_admin_page_url( 'pricing', $params );
11345
+ }
11346
+
11347
+ /**
11348
+ * Checkout page URL.
11349
+ *
11350
+ * @author Vova Feldman (@svovaf)
11351
+ * @since 1.0.6
11352
+ *
11353
+ * @param string $billing_cycle Billing cycle
11354
+ * @param bool $is_trial
11355
+ * @param array $extra (optional) Extra parameters, override other query params.
11356
+ *
11357
+ * @return string
11358
+ */
11359
+ function checkout_url(
11360
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
11361
+ $is_trial = false,
11362
+ $extra = array()
11363
+ ) {
11364
+ $this->_logger->entrance();
11365
+
11366
+ $params = array(
11367
+ 'checkout' => 'true',
11368
+ 'billing_cycle' => $billing_cycle,
11369
+ );
11370
+
11371
+ if ( $is_trial ) {
11372
+ $params['trial'] = 'true';
11373
+ }
11374
+
11375
+ /**
11376
+ * Params in extra override other params.
11377
+ */
11378
+ $params = array_merge( $params, $extra );
11379
+
11380
+ return $this->_get_admin_page_url( 'pricing', $params );
11381
+ }
11382
+
11383
+ /**
11384
+ * Add-on checkout URL.
11385
+ *
11386
+ * @author Vova Feldman (@svovaf)
11387
+ * @since 1.1.7
11388
+ *
11389
+ * @param number $addon_id
11390
+ * @param number $pricing_id
11391
+ * @param string $billing_cycle
11392
+ * @param bool $is_trial
11393
+ *
11394
+ * @return string
11395
+ */
11396
+ function addon_checkout_url(
11397
+ $addon_id,
11398
+ $pricing_id,
11399
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
11400
+ $is_trial = false
11401
+ ) {
11402
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
11403
+ 'plugin_id' => $addon_id,
11404
+ 'pricing_id' => $pricing_id,
11405
+ ) );
11406
+ }
11407
+
11408
+ #endregion
11409
+
11410
+ #endregion ------------------------------------------------------------------
11411
+
11412
+ /**
11413
+ * Check if plugin has any add-ons.
11414
+ *
11415
+ * @author Vova Feldman (@svovaf)
11416
+ * @since 1.0.5
11417
+ *
11418
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
11419
+ *
11420
+ * @return bool
11421
+ */
11422
+ function has_addons() {
11423
+ $this->_logger->entrance();
11424
+
11425
+ return $this->_has_addons;
11426
+ }
11427
+
11428
+ /**
11429
+ * Check if plugin can work in anonymous mode.
11430
+ *
11431
+ * @author Vova Feldman (@svovaf)
11432
+ * @since 1.0.9
11433
+ *
11434
+ * @return bool
11435
+ *
11436
+ * @deprecated Please use is_enable_anonymous() instead.
11437
+ */
11438
+ function enable_anonymous() {
11439
+ return $this->_enable_anonymous;
11440
+ }
11441
+
11442
+ /**
11443
+ * Check if plugin can work in anonymous mode.
11444
+ *
11445
+ * @author Vova Feldman (@svovaf)
11446
+ * @since 1.1.9
11447
+ *
11448
+ * @return bool
11449
+ */
11450
+ function is_enable_anonymous() {
11451
+ return $this->_enable_anonymous;
11452
+ }
11453
+
11454
+ /**
11455
+ * Check if plugin is premium only (no free plans).
11456
+ *
11457
+ * @author Vova Feldman (@svovaf)
11458
+ * @since 1.1.9
11459
+ *
11460
+ * @return bool
11461
+ */
11462
+ function is_only_premium() {
11463
+ return $this->_is_premium_only;
11464
+ }
11465
+
11466
+ /**
11467
+ * Checks if the plugin's type is "plugin". The other type is "theme".
11468
+ *
11469
+ * @author Leo Fajardo (@leorw)
11470
+ * @since 1.2.2
11471
+ *
11472
+ * @return bool
11473
+ */
11474
+ function is_plugin() {
11475
+ return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
11476
+ }
11477
+
11478
+ /**
11479
+ * @author Leo Fajardo (@leorw)
11480
+ * @since 1.2.2
11481
+ *
11482
+ * @return string
11483
+ */
11484
+ function get_module_type() {
11485
+ if ( ! isset( $this->_module_type ) ) {
11486
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
11487
+ $this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
11488
+ }
11489
+
11490
+ return $this->_module_type;
11491
+ }
11492
+
11493
+ /**
11494
+ * @author Leo Fajardo (@leorw)
11495
+ * @since 1.2.2
11496
+ *
11497
+ * @return string
11498
+ */
11499
+ function get_plugin_main_file_path() {
11500
+ return $this->_plugin_main_file_path;
11501
+ }
11502
+
11503
+ /**
11504
+ * Check if module has a premium code version.
11505
+ *
11506
+ * Serviceware module might be freemium without any
11507
+ * premium code version, where the paid features
11508
+ * are all part of the service.
11509
+ *
11510
+ * @author Vova Feldman (@svovaf)
11511
+ * @since 1.2.1.6
11512
+ *
11513
+ * @return bool
11514
+ */
11515
+ function has_premium_version() {
11516
+ return $this->_has_premium_version;
11517
+ }
11518
+
11519
+ /**
11520
+ * Check if feature supported with current site's plan.
11521
+ *
11522
+ * @author Vova Feldman (@svovaf)
11523
+ * @since 1.0.1
11524
+ *
11525
+ * @todo IMPLEMENT
11526
+ *
11527
+ * @param number $feature_id
11528
+ *
11529
+ * @throws Exception
11530
+ */
11531
+ function is_feature_supported( $feature_id ) {
11532
+ throw new Exception( 'not implemented' );
11533
+ }
11534
+
11535
+ /**
11536
+ * @author Vova Feldman (@svovaf)
11537
+ * @since 1.0.1
11538
+ *
11539
+ * @return bool Is running in SSL/HTTPS
11540
+ */
11541
+ function is_ssl() {
11542
+ return WP_FS__IS_HTTPS;
11543
+ }
11544
+
11545
+ /**
11546
+ * @author Vova Feldman (@svovaf)
11547
+ * @since 1.0.9
11548
+ *
11549
+ * @return bool Is running in AJAX call.
11550
+ *
11551
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
11552
+ */
11553
+ static function is_ajax() {
11554
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
11555
+ }
11556
+
11557
+ /**
11558
+ * Check if it's an AJAX call targeted for the current module.
11559
+ *
11560
+ * @author Vova Feldman (@svovaf)
11561
+ * @since 1.2.0
11562
+ *
11563
+ * @param array|string $actions Collection of AJAX actions.
11564
+ *
11565
+ * @return bool
11566
+ */
11567
+ function is_ajax_action( $actions ) {
11568
+ // Verify it's an ajax call.
11569
+ if ( ! self::is_ajax() ) {
11570
+ return false;
11571
+ }
11572
+
11573
+ // Verify the call is relevant for the plugin.
11574
+ if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
11575
+ return false;
11576
+ }
11577
+
11578
+ // Verify it's one of the specified actions.
11579
+ if ( is_string( $actions ) ) {
11580
+ $actions = explode( ',', $actions );
11581
+ }
11582
+
11583
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
11584
+ $ajax_action = fs_request_get( 'action' );
11585
+
11586
+ foreach ( $actions as $action ) {
11587
+ if ( $ajax_action === $this->get_action_tag( $action ) ) {
11588
+ return true;
11589
+ }
11590
+ }
11591
+ }
11592
+
11593
+ return false;
11594
+ }
11595
+
11596
+ /**
11597
+ * Check if it's an AJAX call targeted for current request.
11598
+ *
11599
+ * @author Vova Feldman (@svovaf)
11600
+ * @since 1.2.0
11601
+ *
11602
+ * @param array|string $actions Collection of AJAX actions.
11603
+ * @param number|null $module_id
11604
+ *
11605
+ * @return bool
11606
+ */
11607
+ static function is_ajax_action_static( $actions, $module_id = null ) {
11608
+ // Verify it's an ajax call.
11609
+ if ( ! self::is_ajax() ) {
11610
+ return false;
11611
+ }
11612
+
11613
+
11614
+ if ( ! empty( $module_id ) ) {
11615
+ // Verify the call is relevant for the plugin.
11616
+ if ( $module_id != fs_request_get( 'module_id' ) ) {
11617
+ return false;
11618
+ }
11619
+ }
11620
+
11621
+ // Verify it's one of the specified actions.
11622
+ if ( is_string( $actions ) ) {
11623
+ $actions = explode( ',', $actions );
11624
+ }
11625
+
11626
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
11627
+ $ajax_action = fs_request_get( 'action' );
11628
+
11629
+ foreach ( $actions as $action ) {
11630
+ if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
11631
+ return true;
11632
+ }
11633
+ }
11634
+ }
11635
+
11636
+ return false;
11637
+ }
11638
+
11639
+ /**
11640
+ * @author Vova Feldman (@svovaf)
11641
+ * @since 1.1.7
11642
+ *
11643
+ * @return bool
11644
+ */
11645
+ static function is_cron() {
11646
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
11647
+ }
11648
+
11649
+ /**
11650
+ * Check if a real user is visiting the admin dashboard.
11651
+ *
11652
+ * @author Vova Feldman (@svovaf)
11653
+ * @since 1.1.7
11654
+ *
11655
+ * @return bool
11656
+ */
11657
+ function is_user_in_admin() {
11658
+ return is_admin() && ! self::is_ajax() && ! self::is_cron();
11659
+ }
11660
+
11661
+ /**
11662
+ * Check if a real user is in the customizer view.
11663
+ *
11664
+ * @author Vova Feldman (@svovaf)
11665
+ * @since 1.2.2.7
11666
+ *
11667
+ * @return bool
11668
+ */
11669
+ static function is_customizer() {
11670
+ return is_customize_preview();
11671
+ }
11672
+
11673
+ /**
11674
+ * Check if running in HTTPS and if site's plan matching the specified plan.
11675
+ *
11676
+ * @param string $plan
11677
+ * @param bool $exact
11678
+ *
11679
+ * @return bool
11680
+ */
11681
+ function is_ssl_and_plan( $plan, $exact = false ) {
11682
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
11683
+ }
11684
+
11685
+ /**
11686
+ * Construct plugin's settings page URL.
11687
+ *
11688
+ * @author Vova Feldman (@svovaf)
11689
+ * @since 1.0.4
11690
+ *
11691
+ * @param string $page
11692
+ * @param array $params
11693
+ * @param bool|null $network
11694
+ *
11695
+ * @return string
11696
+ */
11697
+ function _get_admin_page_url( $page = '', $params = array(), $network = null ) {
11698
+ if ( is_null( $network ) ) {
11699
+ $network = (
11700
+ $this->_is_network_active &&
11701
+ ( fs_is_network_admin() || ! $this->is_delegated_connection() )
11702
+ );
11703
+ }
11704
+
11705
+ if ( 0 < count( $params ) ) {
11706
+ foreach ( $params as $k => $v ) {
11707
+ $params[ $k ] = urlencode( $v );
11708
+ }
11709
+ }
11710
+
11711
+ $page_param = $this->_menu->get_slug( $page );
11712
+
11713
+ if ( empty( $page ) &&
11714
+ $this->is_theme() &&
11715
+ // Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
11716
+ ( $this->is_free_wp_org_theme() || ! $this->has_settings_menu() )
11717
+ ) {
11718
+ $params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
11719
+
11720
+ return add_query_arg(
11721
+ $params,
11722
+ $this->admin_url( 'themes.php', 'admin', $network )
11723
+ );
11724
+ }
11725
+
11726
+ if ( ! $this->has_settings_menu() ) {
11727
+ if ( ! empty( $page ) ) {
11728
+ // Module doesn't have a setting page, but since the request is for
11729
+ // a specific Freemius page, use the admin.php path.
11730
+ return add_query_arg( array_merge( $params, array(
11731
+ 'page' => $page_param,
11732
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11733
+ } else {
11734
+ if ( $this->is_activation_mode() ) {
11735
+ /**
11736
+ * @author Vova Feldman
11737
+ * @since 1.2.1.6
11738
+ *
11739
+ * If plugin doesn't have a settings page, create one for the opt-in screen.
11740
+ */
11741
+ return add_query_arg( array_merge( $params, array(
11742
+ 'page' => $this->_slug,
11743
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11744
+ } else {
11745
+ // Plugin without a settings page.
11746
+ return add_query_arg(
11747
+ $params,
11748
+ $this->admin_url( 'plugins.php', 'admin', $network )
11749
+ );
11750
+ }
11751
+ }
11752
+ }
11753
+
11754
+ // Module has a submenu settings page.
11755
+ if ( ! $this->_menu->is_top_level() ) {
11756
+ $parent_slug = $this->_menu->get_parent_slug();
11757
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
11758
+ $parent_slug :
11759
+ 'admin.php';
11760
+
11761
+ return add_query_arg( array_merge( $params, array(
11762
+ 'page' => $page_param,
11763
+ ) ), $this->admin_url( $menu_file, 'admin', $network ) );
11764
+ }
11765
+
11766
+ // Module has a top level CPT settings page.
11767
+ if ( $this->_menu->is_cpt() ) {
11768
+ if ( empty( $page ) && $this->is_activation_mode() ) {
11769
+ return add_query_arg( array_merge( $params, array(
11770
+ 'page' => $page_param
11771
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11772
+ } else {
11773
+ if ( ! empty( $page ) ) {
11774
+ $params['page'] = $page_param;
11775
+ }
11776
+
11777
+ return add_query_arg(
11778
+ $params,
11779
+ $this->admin_url( $this->_menu->get_raw_slug(), 'admin', $network )
11780
+ );
11781
+ }
11782
+ }
11783
+
11784
+ // Module has a custom top level settings page.
11785
+ return add_query_arg( array_merge( $params, array(
11786
+ 'page' => $page_param,
11787
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11788
+ }
11789
+
11790
+ #--------------------------------------------------------------------------------
11791
+ #region Multisite
11792
+ #--------------------------------------------------------------------------------
11793
+
11794
+ /**
11795
+ * @author Leo Fajardo (@leorw)
11796
+ * @since 2.0.0
11797
+ *
11798
+ * @return bool
11799
+ */
11800
+ function is_network_active() {
11801
+ return $this->_is_network_active;
11802
+ }
11803
+
11804
+ /**
11805
+ * Delegate activation for the given sites in the network (or all sites if `null`) to site admins.
11806
+ *
11807
+ * @author Leo Fajardo (@leorw)
11808
+ * @since 2.0.0
11809
+ *
11810
+ * @param array|null $sites
11811
+ */
11812
+ private function delegate_connection( $sites = null ) {
11813
+ $this->_logger->entrance();
11814
+
11815
+ $this->_admin_notices->remove_sticky( 'connect_account' );
11816
+
11817
+ if ( is_null( $sites ) ) {
11818
+ // All sites delegation.
11819
+ $this->_storage->store( 'is_delegated_connection', true, true, true );
11820
+ } else {
11821
+ // Specified sites delegation.
11822
+ foreach ( $sites as $site ) {
11823
+ $this->delegate_site_connection( $site['blog_id'] );
11824
+ }
11825
+ }
11826
+
11827
+ $this->network_upgrade_mode_completed();
11828
+ }
11829
+
11830
+ /**
11831
+ * Delegate specific network site conncetion to the site admin.
11832
+ *
11833
+ * @author Vova Feldman (@svovaf)
11834
+ * @since 2.0.0
11835
+ *
11836
+ * @param int $blog_id
11837
+ */
11838
+ private function delegate_site_connection( $blog_id ) {
11839
+ $this->_storage->store( 'is_delegated_connection', true, $blog_id, true );
11840
+ }
11841
+
11842
+ /**
11843
+ * Check if super-admin delegated the connection of ALL sites to the site admins.
11844
+ *
11845
+ * @author Vova Feldman (@svovaf)
11846
+ * @since 2.0.0
11847
+ *
11848
+ * @return bool
11849
+ */
11850
+ function is_network_delegated_connection() {
11851
+ if ( ! $this->_is_network_active ) {
11852
+ return false;
11853
+ }
11854
+
11855
+ return $this->_storage->get( 'is_delegated_connection', false, true );
11856
+ }
11857
+
11858
+ /**
11859
+ * @author Leo Fajardo (@leorw)
11860
+ * @since 2.0.0
11861
+ *
11862
+ * @param int $blog_id
11863
+ *
11864
+ * @return bool
11865
+ */
11866
+ function is_site_delegated_connection( $blog_id = 0 ) {
11867
+ if ( ! $this->_is_network_active ) {
11868
+ return false;
11869
+ }
11870
+
11871
+ if ( 0 == $blog_id ) {
11872
+ $blog_id = get_current_blog_id();
11873
+ }
11874
+
11875
+ return $this->_storage->get( 'is_delegated_connection', false, $blog_id );
11876
+ }
11877
+
11878
+ /**
11879
+ * Check if delegated the connection. When running within the the network admin,
11880
+ * and haven't specified the blog ID, checks if network level delegated. If running
11881
+ * within a site admin or specified a blog ID, check if delegated the connection for
11882
+ * the current context site.
11883
+ *
11884
+ * If executed outside the the admin, check if delegated the connection
11885
+ * for the current context site OR the whole network.
11886
+ *
11887
+ * @author Vova Feldman (@svovaf)
11888
+ * @since 2.0.0
11889
+ *
11890
+ * @param int $blog_id If set, checks if network delegated or blog specific delegated.
11891
+ *
11892
+ * @return bool
11893
+ */
11894
+ function is_delegated_connection( $blog_id = 0 ) {
11895
+ if ( ! $this->_is_network_active ) {
11896
+ return false;
11897
+ }
11898
+
11899
+ if ( fs_is_network_admin() && 0 == $blog_id ) {
11900
+ return $this->is_network_delegated_connection();
11901
+ }
11902
+
11903
+ return (
11904
+ $this->is_network_delegated_connection() ||
11905
+ $this->is_site_delegated_connection( $blog_id )
11906
+ );
11907
+ }
11908
+
11909
+ /**
11910
+ * Check if the current module is active for the site.
11911
+ *
11912
+ * @author Vova Feldman (@svovaf)
11913
+ * @since 2.0.0
11914
+ *
11915
+ * @param int $blog_id
11916
+ *
11917
+ * @return bool
11918
+ */
11919
+ function is_active_for_site( $blog_id ) {
11920
+ if ( ! is_multisite() ) {
11921
+ // Not a multisite and this code is executed, means that the plugin is active.
11922
+ return true;
11923
+ }
11924
+
11925
+ if ( $this->is_theme() ) {
11926
+ // All themes are site level activated.
11927
+ return true;
11928
+ }
11929
+
11930
+ if ( $this->_is_network_active ) {
11931
+ // Plugin was network activated so it's active.
11932
+ return true;
11933
+ }
11934
+
11935
+ return in_array( $this->_plugin_basename, (array) get_blog_option( $blog_id, 'active_plugins', array() ) );
11936
+ }
11937
+
11938
+ /**
11939
+ * @author Leo Fajardo (@leorw)
11940
+ * @since 2.0.0
11941
+ *
11942
+ * @return array Active & public sites collection.
11943
+ */
11944
+ static function get_sites() {
11945
+ /**
11946
+ * For consistency with get_blog_list() which only return active public sites.
11947
+ *
11948
+ * @author Vova Feldman (@svovaf)
11949
+ */
11950
+ $args = array(
11951
+ 'public' => 1,
11952
+ 'archived' => 0,
11953
+ 'mature' => 0,
11954
+ 'spam' => 0,
11955
+ 'deleted' => 0,
11956
+ );
11957
+
11958
+ if ( function_exists( 'get_sites' ) ) {
11959
+ // For WP 4.6 and above.
11960
+ return get_sites( $args );
11961
+ } else if ( function_exists( 'wp_get_sites' ) ) {
11962
+ // For WP 3.7 to WP 4.5.
11963
+ return wp_get_sites( $args );
11964
+ } else {
11965
+ // For WP 3.6 and below.
11966
+ return get_blog_list( 0, 'all' );
11967
+ }
11968
+ }
11969
+
11970
+ /**
11971
+ * Checks if a given blog is active.
11972
+ *
11973
+ * @author Vova Feldman (@svovaf)
11974
+ * @since 2.0.0
11975
+ *
11976
+ * @param $blog_id
11977
+ *
11978
+ * @return bool
11979
+ */
11980
+ private static function is_site_active( $blog_id ) {
11981
+ global $wpdb;
11982
+
11983
+ $blog_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id ) );
11984
+
11985
+ if ( ! is_object( $blog_info ) ) {
11986
+ return false;
11987
+ }
11988
+
11989
+ return (
11990
+ true == $blog_info->public &&
11991
+ false == $blog_info->archived &&
11992
+ false == $blog_info->mature &&
11993
+ false == $blog_info->spam &&
11994
+ false == $blog_info->deleted
11995
+ );
11996
+ }
11997
+
11998
+ /**
11999
+ * Get a mapping between the site addresses to their blog IDs.
12000
+ *
12001
+ * @author Vova Feldman (@svovaf)
12002
+ * @since 2.0.0
12003
+ *
12004
+ * @return array {
12005
+ * @key string Site address without protocol with a trailing slash.
12006
+ * @value int Site's blog ID.
12007
+ * }
12008
+ */
12009
+ private function get_address_to_blog_map() {
12010
+ $sites = self::get_sites();
12011
+
12012
+ // Map site addresses to their blog IDs.
12013
+ $address_to_blog_map = array();
12014
+ foreach ( $sites as $site ) {
12015
+ $blog_id = self::get_site_blog_id( $site );
12016
+ $address = trailingslashit( fs_strip_url_protocol( get_site_url( $blog_id ) ) );
12017
+ $address_to_blog_map[ $address ] = $blog_id;
12018
+ }
12019
+
12020
+ return $address_to_blog_map;
12021
+ }
12022
+
12023
+ /**
12024
+ * Get a mapping between the site addresses to their blog IDs.
12025
+ *
12026
+ * @author Vova Feldman (@svovaf)
12027
+ * @since 2.0.0
12028
+ *
12029
+ * @return array {
12030
+ * @key int Site's blog ID.
12031
+ * @value FS_Site Associated install.
12032
+ * }
12033
+ */
12034
+ function get_blog_install_map() {
12035
+ $sites = self::get_sites();
12036
+
12037
+ // Map site blog ID to its install.
12038
+ $install_map = array();
12039
+
12040
+ foreach ( $sites as $site ) {
12041
+ $blog_id = self::get_site_blog_id( $site );
12042
+ $install = $this->get_install_by_blog_id( $blog_id );
12043
+
12044
+ if ( is_object( $install ) ) {
12045
+ $install_map[ $blog_id ] = $install;
12046
+ }
12047
+ }
12048
+
12049
+ return $install_map;
12050
+ }
12051
+
12052
+ /**
12053
+ * Gets a map of module IDs that the given user has opted-in to.
12054
+ *
12055
+ * @author Leo Fajardo (@leorw)
12056
+ * @since 2.1.0
12057
+ *
12058
+ * @param number $fs_user_id
12059
+ *
12060
+ * @return array {
12061
+ * @key number $plugin_id
12062
+ * @value bool Always true.
12063
+ * }
12064
+ */
12065
+ private static function get_user_opted_in_module_ids_map( $fs_user_id ) {
12066
+ self::$_static_logger->entrance();
12067
+
12068
+ if ( ! is_multisite() ) {
12069
+ $installs = array_merge(
12070
+ self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN ),
12071
+ self::get_all_sites( WP_FS__MODULE_TYPE_THEME )
12072
+ );
12073
+ } else {
12074
+ $sites = self::get_sites();
12075
+
12076
+ $installs = array();
12077
+ foreach ( $sites as $site ) {
12078
+ $blog_id = self::get_site_blog_id( $site );
12079
+
12080
+ $installs = array_merge(
12081
+ $installs,
12082
+ self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id ),
12083
+ self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id )
12084
+ );
12085
+ }
12086
+ }
12087
+
12088
+ $module_ids_map = array();
12089
+ foreach ( $installs as $install ) {
12090
+ if ( is_object( $install ) &&
12091
+ FS_Site::is_valid_id( $install->id ) &&
12092
+ FS_User::is_valid_id( $install->user_id ) &&
12093
+ ( $install->user_id == $fs_user_id )
12094
+ ) {
12095
+ $module_ids_map[ $install->plugin_id ] = true;
12096
+ }
12097
+ }
12098
+
12099
+ return $module_ids_map;
12100
+ }
12101
+
12102
+ /**
12103
+ * @author Leo Fajardo (@leorw)
12104
+ *
12105
+ * @return null|array {
12106
+ * 'install' => FS_Site Module's install,
12107
+ * 'blog_id' => string The associated blog ID.
12108
+ * }
12109
+ */
12110
+ private function find_first_install() {
12111
+ $sites = self::get_sites();
12112
+
12113
+ foreach ( $sites as $site ) {
12114
+ $blog_id = self::get_site_blog_id( $site );
12115
+ $install = $this->get_install_by_blog_id( $blog_id );
12116
+
12117
+ if ( is_object( $install ) ) {
12118
+ return array(
12119
+ 'install' => $install,
12120
+ 'blog_id' => $blog_id
12121
+ );
12122
+ }
12123
+ }
12124
+
12125
+ return null;
12126
+ }
12127
+
12128
+ /**
12129
+ * Switches the Freemius site level context to a specified blog.
12130
+ *
12131
+ * @author Vova Feldman (@svovaf)
12132
+ * @since 2.0.0
12133
+ *
12134
+ * @param int $blog_id
12135
+ * @param FS_Site $install
12136
+ */
12137
+ function switch_to_blog( $blog_id, FS_Site $install = null ) {
12138
+ if ( $blog_id == $this->_context_is_network_or_blog_id ) {
12139
+ return;
12140
+ }
12141
+
12142
+ switch_to_blog( $blog_id );
12143
+ $this->_context_is_network_or_blog_id = $blog_id;
12144
+
12145
+ self::$_accounts->set_site_blog_context( $blog_id );
12146
+ $this->_storage->set_site_blog_context( $blog_id );
12147
+ $this->_storage->set_network_active( true, $this->is_delegated_connection( $blog_id ) );
12148
+
12149
+ $this->_site = is_object( $install ) ?
12150
+ $install :
12151
+ $this->get_install_by_blog_id( $blog_id );
12152
+
12153
+ $this->_user = false;
12154
+ $this->_licenses = false;
12155
+ $this->_license = null;
12156
+
12157
+ if ( is_object( $this->_site ) ) {
12158
+ // Try to fetch user from install.
12159
+ $this->_user = self::_get_user_by_id( $this->_site->user_id );
12160
+
12161
+ if ( ! is_object( $this->_user ) &&
12162
+ FS_User::is_valid_id( $this->_storage->prev_user_id )
12163
+ ) {
12164
+ // Try to fetch previously saved user.
12165
+ $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );
12166
+
12167
+ if ( ! is_object( $this->_user ) ) {
12168
+ // Fallback to network's user.
12169
+ $this->_user = $this->get_network_user();
12170
+ }
12171
+ }
12172
+
12173
+ $all_plugin_licenses = self::get_all_licenses( $this->_module_id );
12174
+
12175
+ if ( ! empty( $all_plugin_licenses ) ) {
12176
+ if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
12177
+ $this->_license = null;
12178
+ } else {
12179
+ $license_found = false;
12180
+ foreach ( $all_plugin_licenses as $license ) {
12181
+ if ( $license->id == $this->_site->license_id ) {
12182
+ // License found.
12183
+ $this->_license = $license;
12184
+ $license_found = true;
12185
+ break;
12186
+ }
12187
+ }
12188
+
12189
+ if ( $license_found ) {
12190
+ $this->link_license_2_user( $this->_license->id, $this->_user->id );
12191
+ }
12192
+ }
12193
+
12194
+ $this->_licenses = $this->get_user_licenses( $this->_user->id );
12195
+ }
12196
+ }
12197
+
12198
+ unset( $this->_site_api );
12199
+ unset( $this->_user_api );
12200
+ }
12201
+
12202
+ /**
12203
+ * Restore the blog context to the blog that originally loaded the module.
12204
+ *
12205
+ * @author Vova Feldman (@svovaf)
12206
+ * @since 2.0.0
12207
+ */
12208
+ function restore_current_blog() {
12209
+ $this->switch_to_blog( $this->_blog_id );
12210
+ }
12211
+
12212
+ /**
12213
+ * @author Vova Feldman (@svovaf)
12214
+ * @since 2.0.0
12215
+ *
12216
+ * @param array|WP_Site $site
12217
+ *
12218
+ * @return int
12219
+ */
12220
+ static function get_site_blog_id( &$site ) {
12221
+ return ( $site instanceof WP_Site ) ?
12222
+ $site->blog_id :
12223
+ ( is_object( $site ) && isset( $site->userblog_id ) ?
12224
+ $site->userblog_id :
12225
+ $site['blog_id'] );
12226
+ }
12227
+
12228
+ /**
12229
+ * @author Leo Fajardo (@leorw)
12230
+ * @since 2.0.0
12231
+ *
12232
+ * @param array|WP_Site|null $site
12233
+ *
12234
+ * @return array
12235
+ */
12236
+ function get_site_info( $site = null ) {
12237
+ $this->_logger->entrance();
12238
+
12239
+ $switched = false;
12240
+
12241
+ if ( is_null( $site ) ) {
12242
+ $url = get_site_url();
12243
+ $name = get_bloginfo( 'name' );
12244
+ $blog_id = null;
12245
+ } else {
12246
+ $blog_id = self::get_site_blog_id( $site );
12247
+
12248
+ if ( get_current_blog_id() != $blog_id ) {
12249
+ switch_to_blog( $blog_id );
12250
+ $switched = true;
12251
+ }
12252
+
12253
+ if ( $site instanceof WP_Site ) {
12254
+ $url = $site->siteurl;
12255
+ $name = $site->blogname;
12256
+ } else {
12257
+ $url = get_site_url( $blog_id );
12258
+ $name = get_bloginfo( 'name' );
12259
+ }
12260
+ }
12261
+
12262
+ $info = array(
12263
+ 'uid' => $this->get_anonymous_id( $blog_id ),
12264
+ 'url' => $url,
12265
+ 'title' => $name,
12266
+ 'language' => get_bloginfo( 'language' ),
12267
+ 'charset' => get_bloginfo( 'charset' ),
12268
+ );
12269
+
12270
+ if ( is_numeric( $blog_id ) ) {
12271
+ $info['blog_id'] = $blog_id;
12272
+ }
12273
+
12274
+ if ( $switched ) {
12275
+ restore_current_blog();
12276
+ }
12277
+
12278
+ return $info;
12279
+ }
12280
+
12281
+ /**
12282
+ * Load the module's install based on the blog ID.
12283
+ *
12284
+ * @author Vova Feldman (@svovaf)
12285
+ * @since 2.0.0
12286
+ *
12287
+ * @param int|null $blog_id
12288
+ *
12289
+ * @return FS_Site
12290
+ */
12291
+ function get_install_by_blog_id( $blog_id = null ) {
12292
+ $installs = self::get_all_sites( $this->_module_type, $blog_id );
12293
+ $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
12294
+
12295
+ if ( is_object( $install ) &&
12296
+ is_numeric( $install->id ) &&
12297
+ is_numeric( $install->user_id ) &&
12298
+ FS_Plugin_Plan::is_valid_id( $install->plan_id )
12299
+ ) {
12300
+ // Load site.
12301
+ $install = clone $install;
12302
+ }
12303
+
12304
+ return $install;
12305
+ }
12306
+
12307
+ /**
12308
+ * Check if module is installed on a specified site.
12309
+ *
12310
+ * @author Vova Feldman (@svovaf)
12311
+ * @since 2.0.0
12312
+ *
12313
+ * @param int|null $blog_id
12314
+ *
12315
+ * @return bool
12316
+ */
12317
+ function is_installed_on_site( $blog_id = null ) {
12318
+ $installs = self::get_all_sites( $this->_module_type, $blog_id );
12319
+ $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
12320
+
12321
+ return (
12322
+ is_object( $install ) &&
12323
+ is_numeric( $install->id ) &&
12324
+ is_numeric( $install->user_id ) &&
12325
+ FS_Plugin_Plan::is_valid_id( $install->plan_id )
12326
+ );
12327
+ }
12328
+
12329
+ /**
12330
+ * Check if super-admin connected at least one site via the network opt-in.
12331
+ *
12332
+ * @author Vova Feldman (@svovaf)
12333
+ * @since 2.0.0
12334
+ *
12335
+ * @return bool
12336
+ */
12337
+ function is_network_registered() {
12338
+ if ( ! $this->_is_network_active ) {
12339
+ return false;
12340
+ }
12341
+
12342
+ return FS_User::is_valid_id( $this->_storage->network_user_id );
12343
+ }
12344
+
12345
+ /**
12346
+ * Returns the main user associated with the network.
12347
+ *
12348
+ * @author Vova Feldman (@svovaf)
12349
+ * @since 2.0.0
12350
+ *
12351
+ * @return FS_User
12352
+ */
12353
+ function get_network_user() {
12354
+ if ( ! $this->_is_network_active ) {
12355
+ return null;
12356
+ }
12357
+
12358
+ return FS_User::is_valid_id( $this->_storage->network_user_id ) ?
12359
+ self::_get_user_by_id( $this->_storage->network_user_id ) :
12360
+ null;
12361
+ }
12362
+
12363
+ /**
12364
+ * Returns the current context user or the network's main user.
12365
+ *
12366
+ * @author Vova Feldman (@svovaf)
12367
+ * @since 2.0.0
12368
+ *
12369
+ * @return FS_User
12370
+ */
12371
+ function get_current_or_network_user() {
12372
+ return ( $this->_user instanceof FS_User ) ?
12373
+ $this->_user :
12374
+ $this->get_network_user();
12375
+ }
12376
+
12377
+ /**
12378
+ * Returns the main install associated with the network.
12379
+ *
12380
+ * @author Vova Feldman (@svovaf)
12381
+ * @since 2.0.0
12382
+ *
12383
+ * @return FS_Site
12384
+ */
12385
+ function get_network_install() {
12386
+ if ( ! $this->_is_network_active ) {
12387
+ return null;
12388
+ }
12389
+
12390
+ return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
12391
+ $this->get_install_by_blog_id( $this->_storage->network_install_blog_id ) :
12392
+ null;
12393
+ }
12394
+
12395
+ /**
12396
+ * Returns the blog ID that is associated with the main install.
12397
+ *
12398
+ * @author Leo Fajardo (@leorw)
12399
+ * @since 2.0.0
12400
+ *
12401
+ * @return int|null
12402
+ */
12403
+ function get_network_install_blog_id() {
12404
+ if ( ! $this->_is_network_active ) {
12405
+ return null;
12406
+ }
12407
+
12408
+ return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
12409
+ $this->_storage->network_install_blog_id :
12410
+ null;
12411
+ }
12412
+
12413
+ /**
12414
+ * Returns the current context install or the network's main install.
12415
+ *
12416
+ * @author Vova Feldman (@svovaf)
12417
+ * @since 2.0.0
12418
+ *
12419
+ * @return FS_Site
12420
+ */
12421
+ function get_current_or_network_install() {
12422
+ return ( $this->_site instanceof FS_Site ) ?
12423
+ $this->_site :
12424
+ $this->get_network_install();
12425
+ }
12426
+
12427
+ /**
12428
+ * Check if executing a site level action from the network level admin.
12429
+ *
12430
+ * @author Vova Feldman (@svovaf)
12431
+ * @since 2.0.0
12432
+ *
12433
+ * @return false|int If yes, return the requested blog ID.
12434
+ */
12435
+ private function is_network_level_site_specific_action() {
12436
+ if ( ! $this->_is_network_active ) {
12437
+ return false;
12438
+ }
12439
+
12440
+ if ( ! fs_is_network_admin() ) {
12441
+ return false;
12442
+ }
12443
+
12444
+ $blog_id = fs_request_get( 'blog_id', '' );
12445
+
12446
+ return is_numeric( $blog_id ) ? $blog_id : false;
12447
+ }
12448
+
12449
+ /**
12450
+ * Check if executing an action from the network level admin.
12451
+ *
12452
+ * @author Vova Feldman (@svovaf)
12453
+ * @since 2.0.0
12454
+ *
12455
+ * @return bool
12456
+ */
12457
+ private function is_network_level_action() {
12458
+ return ( $this->_is_network_active && fs_is_network_admin() );
12459
+ }
12460
+
12461
+ /**
12462
+ * Needs to be executed after site deactivation, archive, deletion, or flag as spam.
12463
+ * The logic updates the network level user and blog, and reschedule the crons if the cron executing site matching the site that is no longer publicly active.
12464
+ *
12465
+ * @author Vova Feldman (@svovaf)
12466
+ * @since 2.0.0
12467
+ *
12468
+ * @param int $context_blog_id
12469
+ */
12470
+ private function update_multisite_data_after_site_deactivation( $context_blog_id = 0 ) {
12471
+ $this->_logger->entrance();
12472
+
12473
+ if ( $this->_is_network_active ) {
12474
+ if ( $context_blog_id == $this->_storage->network_install_blog_id ) {
12475
+ $installs_map = $this->get_blog_install_map();
12476
+
12477
+ foreach ( $installs_map as $blog_id => $install ) {
12478
+ /**
12479
+ * @var FS_Site $install
12480
+ */
12481
+ if ( $context_blog_id == $blog_id ) {
12482
+ continue;
12483
+ }
12484
+
12485
+ if ( $install->user_id != $this->_storage->network_user_id ) {
12486
+ continue;
12487
+ }
12488
+
12489
+ // Switch reference to a blog that is opted-in and belong to the same super-admin.
12490
+ $this->_storage->network_install_blog_id = $blog_id;
12491
+ break;
12492
+ }
12493
+ }
12494
+ }
12495
+
12496
+ if ( $this->is_sync_cron_scheduled() &&
12497
+ $context_blog_id == $this->get_sync_cron_blog_id()
12498
+ ) {
12499
+ $this->schedule_sync_cron( WP_FS__SCRIPT_START_TIME, true, $context_blog_id );
12500
+ }
12501
+
12502
+ if ( $this->is_install_sync_scheduled() &&
12503
+ $context_blog_id == $this->get_install_sync_cron_blog_id()
12504
+ ) {
12505
+ $this->schedule_install_sync( $context_blog_id );
12506
+ }
12507
+ }
12508
+
12509
+ /**
12510
+ * Executed after site deactivation, archive, or flag as spam.
12511
+ *
12512
+ * @author Vova Feldman (@svovaf)
12513
+ * @since 2.0.0
12514
+ *
12515
+ * @param int $context_blog_id
12516
+ */
12517
+ public function _after_site_deactivated_callback( $context_blog_id = 0 ) {
12518
+ $this->_logger->entrance();
12519
+
12520
+ $install = $this->get_install_by_blog_id( $context_blog_id );
12521
+
12522
+ if ( ! is_object( $install ) ) {
12523
+ // Site not connected.
12524
+ return;
12525
+ }
12526
+
12527
+ $this->update_multisite_data_after_site_deactivation( $context_blog_id );
12528
+
12529
+ $current_blog_id = get_current_blog_id();
12530
+
12531
+ $this->switch_to_blog( $context_blog_id );
12532
+
12533
+ // Send deactivation event.
12534
+ $this->sync_install( array(
12535
+ 'is_active' => false,
12536
+ ) );
12537
+
12538
+ $this->switch_to_blog( $current_blog_id );
12539
+ }
12540
+
12541
+ /**
12542
+ * Executed after site deletion.
12543
+ *
12544
+ * @author Vova Feldman (@svovaf)
12545
+ * @since 2.0.0
12546
+ *
12547
+ * @param int $context_blog_id
12548
+ * @param bool $drop True if site's database tables should be dropped. Default is false.
12549
+ */
12550
+ public function _after_site_deleted_callback( $context_blog_id = 0, $drop = false ) {
12551
+ $this->_logger->entrance();
12552
+
12553
+ $install = $this->get_install_by_blog_id( $context_blog_id );
12554
+
12555
+ if ( ! is_object( $install ) ) {
12556
+ // Site not connected.
12557
+ return;
12558
+ }
12559
+
12560
+ $this->update_multisite_data_after_site_deactivation( $context_blog_id );
12561
+
12562
+ $current_blog_id = get_current_blog_id();
12563
+
12564
+ $this->switch_to_blog( $context_blog_id );
12565
+
12566
+ if ( $drop ) {
12567
+ // Delete install if dropping site DB.
12568
+ $this->delete_account_event();
12569
+ } else {
12570
+ // Send deactivation event.
12571
+ $this->sync_install( array(
12572
+ 'is_active' => false,
12573
+ ) );
12574
+ }
12575
+
12576
+ $this->switch_to_blog( $current_blog_id );
12577
+ }
12578
+
12579
+ /**
12580
+ * Executed after site re-activation.
12581
+ *
12582
+ * @author Vova Feldman (@svovaf)
12583
+ * @since 2.0.0
12584
+ *
12585
+ * @param int $context_blog_id
12586
+ */
12587
+ public function _after_site_reactivated_callback( $context_blog_id = 0 ) {
12588
+ $this->_logger->entrance();
12589
+
12590
+ $install = $this->get_install_by_blog_id( $context_blog_id );
12591
+
12592
+ if ( ! is_object( $install ) ) {
12593
+ // Site not connected.
12594
+ return;
12595
+ }
12596
+
12597
+ if ( ! self::is_site_active( $context_blog_id ) ) {
12598
+ // Site not yet active (can be in spam mode, archived, deleted...).
12599
+ return;
12600
+ }
12601
+
12602
+ $current_blog_id = get_current_blog_id();
12603
+
12604
+ $this->switch_to_blog( $context_blog_id );
12605
+
12606
+ // Send re-activation event.
12607
+ $this->sync_install( array(
12608
+ 'is_active' => true,
12609
+ ) );
12610
+
12611
+ $this->switch_to_blog( $current_blog_id );
12612
+ }
12613
+
12614
+ #endregion Multisite
12615
+
12616
+ /**
12617
+ * @author Leo Fajardo (@leorw)
12618
+ *
12619
+ * @param string $path
12620
+ * @param string $scheme
12621
+ * @param bool $network
12622
+ *
12623
+ * @return string
12624
+ */
12625
+ private function admin_url( $path = '', $scheme = 'admin', $network = true ) {
12626
+ return ( $this->_is_network_active && $network ) ?
12627
+ network_admin_url( $path, $scheme ) :
12628
+ admin_url( $path, $scheme );
12629
+ }
12630
+
12631
+ /**
12632
+ * Check if currently in a specified admin page.
12633
+ *
12634
+ * @author Vova Feldman (@svovaf)
12635
+ * @since 1.2.2.7
12636
+ *
12637
+ * @param string $page
12638
+ *
12639
+ * @return bool
12640
+ */
12641
+ function is_admin_page( $page ) {
12642
+ return ( $this->_menu->get_slug( $page ) === fs_request_get( 'page', '', 'get' ) );
12643
+ }
12644
+
12645
+ /**
12646
+ * Get module's main admin setting page URL.
12647
+ *
12648
+ * @author Vova Feldman (@svovaf)
12649
+ * @since 1.2.2.7
12650
+ *
12651
+ * @return string
12652
+ */
12653
+ function main_menu_url() {
12654
+ return $this->_menu->main_menu_url();
12655
+ }
12656
+
12657
+ /**
12658
+ * Check if currently on the theme's setting page or
12659
+ * on any of the Freemius added pages (via tabs).
12660
+ *
12661
+ * @author Vova Feldman (@svovaf)
12662
+ * @since 1.2.2.7
12663
+ *
12664
+ * @return bool
12665
+ */
12666
+ function is_theme_settings_page() {
12667
+ return fs_starts_with(
12668
+ fs_request_get( 'page', '', 'get' ),
12669
+ $this->_menu->get_slug()
12670
+ );
12671
+ }
12672
+
12673
+ /**
12674
+ * Plugin's account page + sync license URL.
12675
+ *
12676
+ * @author Vova Feldman (@svovaf)
12677
+ * @since 1.1.9.1
12678
+ *
12679
+ * @param bool|number $plugin_id
12680
+ * @param bool $add_action_nonce
12681
+ * @param array $params
12682
+ *
12683
+ * @return string
12684
+ */
12685
+ function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
12686
+ if ( is_numeric( $plugin_id ) ) {
12687
+ $params['plugin_id'] = $plugin_id;
12688
+ }
12689
+
12690
+ return $this->get_account_url(
12691
+ $this->get_unique_affix() . '_sync_license',
12692
+ $params,
12693
+ $add_action_nonce
12694
+ );
12695
+ }
12696
+
12697
+ /**
12698
+ * Plugin's account URL.
12699
+ *
12700
+ * @author Vova Feldman (@svovaf)
12701
+ * @since 1.0.4
12702
+ *
12703
+ * @param bool|string $action
12704
+ * @param array $params
12705
+ *
12706
+ * @param bool $add_action_nonce
12707
+ *
12708
+ * @return string
12709
+ */
12710
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
12711
+ if ( is_string( $action ) ) {
12712
+ $params['fs_action'] = $action;
12713
+ }
12714
+
12715
+ self::require_pluggable_essentials();
12716
+
12717
+ return ( $add_action_nonce && is_string( $action ) ) ?
12718
+ fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
12719
+ $this->_get_admin_page_url( 'account', $params );
12720
+ }
12721
+
12722
+ /**
12723
+ * @author Vova Feldman (@svovaf)
12724
+ * @since 1.2.0
12725
+ *
12726
+ * @param string $tab
12727
+ * @param bool $action
12728
+ * @param array $params
12729
+ * @param bool $add_action_nonce
12730
+ *
12731
+ * @return string
12732
+ *
12733
+ * @uses get_account_url()
12734
+ */
12735
+ function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
12736
+ $params['tab'] = $tab;
12737
+
12738
+ return $this->get_account_url( $action, $params, $add_action_nonce );
12739
+ }
12740
+
12741
+ /**
12742
+ * Plugin's account URL.
12743
+ *
12744
+ * @author Vova Feldman (@svovaf)
12745
+ * @since 1.0.4
12746
+ *
12747
+ * @param bool|string $topic
12748
+ * @param bool|string $message
12749
+ *
12750
+ * @return string
12751
+ */
12752
+ function contact_url( $topic = false, $message = false ) {
12753
+ $params = array();
12754
+ if ( is_string( $topic ) ) {
12755
+ $params['topic'] = $topic;
12756
+ }
12757
+ if ( is_string( $message ) ) {
12758
+ $params['message'] = $message;
12759
+ }
12760
+
12761
+ if ( $this->is_addon() ) {
12762
+ $params['addon_id'] = $this->get_id();
12763
+
12764
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
12765
+ } else {
12766
+ return $this->_get_admin_page_url( 'contact', $params );
12767
+ }
12768
+ }
12769
+
12770
+ /**
12771
+ * Add-on direct info URL.
12772
+ *
12773
+ * @author Vova Feldman (@svovaf)
12774
+ * @since 1.1.0
12775
+ *
12776
+ * @param string $slug
12777
+ *
12778
+ * @return string
12779
+ */
12780
+ function addon_url( $slug ) {
12781
+ return $this->_get_admin_page_url( 'addons', array(
12782
+ 'slug' => $slug
12783
+ ) );
12784
+ }
12785
+
12786
+ /* Logger
12787
+ ------------------------------------------------------------------------------------------------------------------*/
12788
+ /**
12789
+ * @param string $id
12790
+ * @param bool $prefix_slug
12791
+ *
12792
+ * @return FS_Logger
12793
+ */
12794
+ function get_logger( $id = '', $prefix_slug = true ) {
12795
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
12796
+ }
12797
+
12798
+ /**
12799
+ * Note: This method is used externally so don't delete it.
12800
+ *
12801
+ * @param $id
12802
+ * @param bool $load_options
12803
+ * @param bool $prefix_slug
12804
+ *
12805
+ * @return FS_Option_Manager
12806
+ */
12807
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
12808
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
12809
+ }
12810
+
12811
+ /* Security
12812
+ ------------------------------------------------------------------------------------------------------------------*/
12813
+ private static function _encrypt( $str ) {
12814
+ if ( is_null( $str ) ) {
12815
+ return null;
12816
+ }
12817
+
12818
+ /**
12819
+ * The encrypt/decrypt functions are used to protect
12820
+ * the user from messing up with some of the sensitive
12821
+ * data stored for the module as a JSON in the database.
12822
+ *
12823
+ * I used the same suggested hack by the theme review team.
12824
+ * For more details, look at the function `Base64UrlDecode()`
12825
+ * in `./sdk/FreemiusBase.php`.
12826
+ *
12827
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
12828
+ *
12829
+ * @author Vova Feldman (@svovaf)
12830
+ * @since 1.2.2
12831
+ */
12832
+ $fn = 'base64' . '_encode';
12833
+
12834
+ return $fn( $str );
12835
+ }
12836
+
12837
+ static function _decrypt( $str ) {
12838
+ if ( is_null( $str ) ) {
12839
+ return null;
12840
+ }
12841
+
12842
+ /**
12843
+ * The encrypt/decrypt functions are used to protect
12844
+ * the user from messing up with some of the sensitive
12845
+ * data stored for the module as a JSON in the database.
12846
+ *
12847
+ * I used the same suggested hack by the theme review team.
12848
+ * For more details, look at the function `Base64UrlDecode()`
12849
+ * in `./sdk/FreemiusBase.php`.
12850
+ *
12851
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
12852
+ *
12853
+ * @author Vova Feldman (@svovaf)
12854
+ * @since 1.2.2
12855
+ */
12856
+ $fn = 'base64' . '_decode';
12857
+
12858
+ return $fn( $str );
12859
+ }
12860
+
12861
+ /**
12862
+ * @author Vova Feldman (@svovaf)
12863
+ * @since 1.0.5
12864
+ *
12865
+ * @param FS_Entity $entity
12866
+ *
12867
+ * @return FS_Entity Return an encrypted clone entity.
12868
+ */
12869
+ private static function _encrypt_entity( FS_Entity $entity ) {
12870
+ $clone = clone $entity;
12871
+ $props = get_object_vars( $entity );
12872
+
12873
+ foreach ( $props as $key => $val ) {
12874
+ $clone->{$key} = self::_encrypt( $val );
12875
+ }
12876
+
12877
+ return $clone;
12878
+ }
12879
+
12880
+ /**
12881
+ * @author Vova Feldman (@svovaf)
12882
+ * @since 1.0.5
12883
+ *
12884
+ * @param FS_Entity $entity
12885
+ *
12886
+ * @return FS_Entity Return an decrypted clone entity.
12887
+ */
12888
+ private static function decrypt_entity( FS_Entity $entity ) {
12889
+ $clone = clone $entity;
12890
+ $props = get_object_vars( $entity );
12891
+
12892
+ foreach ( $props as $key => $val ) {
12893
+ $clone->{$key} = self::_decrypt( $val );
12894
+ }
12895
+
12896
+ return $clone;
12897
+ }
12898
+
12899
+ /**
12900
+ * Tries to activate account based on POST params.
12901
+ *
12902
+ * @author Vova Feldman (@svovaf)
12903
+ * @since 1.0.2
12904
+ *
12905
+ * @deprecated Not in use, outdated.
12906
+ */
12907
+ function _activate_account() {
12908
+ if ( $this->is_registered() ) {
12909
+ // Already activated.
12910
+ return;
12911
+ }
12912
+
12913
+ self::_clean_admin_content_section();
12914
+
12915
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
12916
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
12917
+
12918
+ // Verify matching plugin details.
12919
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
12920
+ return;
12921
+ }
12922
+
12923
+ $user = new FS_User();
12924
+ $user->id = fs_request_get( 'user_id' );
12925
+ $user->public_key = fs_request_get( 'user_public_key' );
12926
+ $user->secret_key = fs_request_get( 'user_secret_key' );
12927
+ $user->email = fs_request_get( 'user_email' );
12928
+ $user->first = fs_request_get( 'user_first' );
12929
+ $user->last = fs_request_get( 'user_last' );
12930
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
12931
+
12932
+ $site = new FS_Site();
12933
+ $site->id = fs_request_get( 'install_id' );
12934
+ $site->public_key = fs_request_get( 'install_public_key' );
12935
+ $site->secret_key = fs_request_get( 'install_secret_key' );
12936
+ $site->plan_id = fs_request_get( 'plan_id' );
12937
+
12938
+ $plans = array();
12939
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
12940
+ foreach ( $plans_data as $p ) {
12941
+ $plan = new FS_Plugin_Plan( $p );
12942
+ if ( $site->plan_id == $plan->id ) {
12943
+ $plan->title = fs_request_get( 'plan_title' );
12944
+ $plan->name = fs_request_get( 'plan_name' );
12945
+ }
12946
+
12947
+ $plans[] = $plan;
12948
+ }
12949
+
12950
+ $this->_set_account( $user, $site, $plans );
12951
+
12952
+ // Reload the page with the keys.
12953
+ fs_redirect( $this->_get_admin_page_url() );
12954
+ }
12955
+ }
12956
+
12957
+ /**
12958
+ * @author Vova Feldman (@svovaf)
12959
+ * @since 1.0.7
12960
+ *
12961
+ * @param string $email
12962
+ *
12963
+ * @return FS_User|false
12964
+ */
12965
+ static function _get_user_by_email( $email ) {
12966
+ self::$_static_logger->entrance();
12967
+
12968
+ $email = trim( strtolower( $email ) );
12969
+
12970
+ $users = self::get_all_users();
12971
+
12972
+ if ( is_array( $users ) ) {
12973
+ foreach ( $users as $user ) {
12974
+ if ( $email === trim( strtolower( $user->email ) ) ) {
12975
+ return $user;
12976
+ }
12977
+ }
12978
+ }
12979
+
12980
+ return false;
12981
+ }
12982
+
12983
+ #----------------------------------------------------------------------------------
12984
+ #region Account (Loading, Updates & Activation)
12985
+ #----------------------------------------------------------------------------------
12986
+
12987
+ /***
12988
+ * Load account information (user + site).
12989
+ *
12990
+ * @author Vova Feldman (@svovaf)
12991
+ * @since 1.0.1
12992
+ */
12993
+ private function _load_account() {
12994
+ $this->_logger->entrance();
12995
+
12996
+ $this->do_action( 'before_account_load' );
12997
+
12998
+ $users = self::get_all_users();
12999
+ $plans = self::get_all_plans( $this->_module_type );
13000
+
13001
+ if ( $this->_logger->is_on() && is_admin() ) {
13002
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
13003
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
13004
+ }
13005
+
13006
+ $site = fs_is_network_admin() ?
13007
+ $this->get_network_install() :
13008
+ $this->get_install_by_blog_id();
13009
+
13010
+ if ( fs_is_network_admin() &&
13011
+ ! is_object( $site ) &&
13012
+ FS_Site::is_valid_id( $this->_storage->network_install_blog_id )
13013
+ ) {
13014
+ $first_install = $this->find_first_install();
13015
+
13016
+ if ( is_null( $first_install ) ) {
13017
+ unset( $this->_storage->network_install_blog_id );
13018
+ } else {
13019
+ $site = $first_install['install'];
13020
+ $this->_storage->network_install_blog_id = $first_install['blog_id'];
13021
+ }
13022
+ }
13023
+
13024
+ if ( is_object( $site ) &&
13025
+ is_numeric( $site->id ) &&
13026
+ is_numeric( $site->user_id ) &&
13027
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
13028
+ ) {
13029
+ // Load site.
13030
+ $this->_site = $site;
13031
+
13032
+ // Load plans.
13033
+ $this->_plans = $plans[ $this->_slug ];
13034
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
13035
+ $this->_sync_plans();
13036
+ } else {
13037
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
13038
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
13039
+ $this->_plans[ $i ] = self::decrypt_entity( $this->_plans[ $i ] );
13040
+ } else {
13041
+ unset( $this->_plans[ $i ] );
13042
+ }
13043
+ }
13044
+ }
13045
+ }
13046
+
13047
+ $user = null;
13048
+ if ( fs_is_network_admin() && $this->_is_network_active ) {
13049
+ $user = $this->get_network_user();
13050
+ }
13051
+
13052
+ if ( is_object( $user ) ) {
13053
+ $this->_user = clone $user;
13054
+ } else if ( $this->_site ) {
13055
+ $user = self::_get_user_by_id( $this->_site->user_id );
13056
+
13057
+ if ( ! is_object( $user ) && FS_User::is_valid_id( $this->_storage->prev_user_id ) ) {
13058
+ /**
13059
+ * Try to load the previous owner. This recovery is used for the following use-case:
13060
+ * 1. Opt-in
13061
+ * 2. Cloning site1 to site2
13062
+ * 3. Ownership switch in site1 (same applies for site2)
13063
+ * 4. Install data sync on site2
13064
+ * 5. Now site2's install is associated with the new owner which does not exists locally.
13065
+ */
13066
+ $user = self::_get_user_by_id( $this->_storage->prev_user_id );
13067
+ }
13068
+
13069
+ if ( ! is_object( $user ) ) {
13070
+ /**
13071
+ * This is a special fault tolerance mechanism to handle a scenario that the user data is missing.
13072
+ */
13073
+ $user = $this->fetch_user_by_install();
13074
+ }
13075
+
13076
+ $this->_user = ( $user instanceof FS_User ) ?
13077
+ clone $user :
13078
+ null;
13079
+ }
13080
+
13081
+ if ( is_object( $this->_user ) ) {
13082
+ // Load licenses.
13083
+ $this->_licenses = $this->get_user_licenses( $this->_user->id );
13084
+ }
13085
+
13086
+ if ( is_object( $this->_site ) ) {
13087
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
13088
+
13089
+ if ( $this->_site->version != $this->get_plugin_version() ) {
13090
+ // If stored install version is different than current installed plugin version,
13091
+ // then update plugin version event.
13092
+ $this->update_plugin_version_event();
13093
+ }
13094
+ }
13095
+
13096
+ if ( $this->is_theme() ) {
13097
+ $this->_register_account_hooks();
13098
+ }
13099
+ }
13100
+
13101
+ /**
13102
+ * Special user recovery mechanism.
13103
+ *
13104
+ * @author Vova Feldman (@svovaf)
13105
+ * @since 2.0.0
13106
+ *
13107
+ * @return \FS_User|mixed
13108
+ */
13109
+ private function fetch_user_by_install() {
13110
+ $api = $this->get_api_site_scope();
13111
+
13112
+ $uid = $this->get_anonymous_id();
13113
+ $request_path = "/users/{$this->_site->user_id}.json?uid={$uid}";
13114
+
13115
+ $result = $api->get( $request_path, false, WP_FS__TIME_10_MIN_IN_SEC );
13116
+
13117
+ if ( $this->is_api_result_entity( $result ) ) {
13118
+ $user = new FS_User( $result );
13119
+ $this->_user = $user;
13120
+ $this->_store_user();
13121
+
13122
+ return $user;
13123
+ }
13124
+
13125
+ $error_code = FS_Api::get_error_code( $result );
13126
+
13127
+ if ( in_array( $error_code, array( 'invalid_unique_id', 'user_cannot_be_recovered' ) ) ) {
13128
+ /**
13129
+ * Those API errors will continue coming and are not recoverable with the
13130
+ * current site's data. Therefore, extend the API call's cached result to 7 days.
13131
+ */
13132
+ $api->update_cache_expiration( $request_path, WP_FS__TIME_WEEK_IN_SEC );
13133
+ }
13134
+
13135
+ return $result;
13136
+ }
13137
+
13138
+ /**
13139
+ * @author Vova Feldman (@svovaf)
13140
+ * @since 1.0.1
13141
+ *
13142
+ * @param FS_User $user
13143
+ * @param FS_Site $site
13144
+ * @param bool|array $plans
13145
+ */
13146
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
13147
+ $site->user_id = $user->id;
13148
+
13149
+ $this->_site = $site;
13150
+ $this->_user = $user;
13151
+ if ( false !== $plans ) {
13152
+ $this->_plans = $plans;
13153
+ }
13154
+
13155
+ $this->send_install_update();
13156
+
13157
+ $this->_store_account();
13158
+
13159
+ }
13160
+
13161
+ /**
13162
+ * @author Vova Feldman (@svovaf)
13163
+ * @since 1.1.7.4
13164
+ *
13165
+ * @param array $override_with
13166
+ * @param bool|int|null $network_level_or_blog_id If true, return params for network level opt-in. If integer, get params for specified blog in the network.
13167
+ *
13168
+ * @return array
13169
+ */
13170
+ function get_opt_in_params( $override_with = array(), $network_level_or_blog_id = null ) {
13171
+ $this->_logger->entrance();
13172
+
13173
+ $current_user = self::_get_current_wp_user();
13174
+
13175
+ $activation_action = $this->get_unique_affix() . '_activate_new';
13176
+ $return_url = $this->is_anonymous() ?
13177
+ // If skipped already, then return to the account page.
13178
+ $this->get_account_url( $activation_action, array(), false ) :
13179
+ // Return to the module's main page.
13180
+ $this->get_after_activation_url( 'after_connect_url', array( 'fs_action' => $activation_action ) );
13181
+
13182
+ $params = array(
13183
+ 'user_firstname' => $current_user->user_firstname,
13184
+ 'user_lastname' => $current_user->user_lastname,
13185
+ 'user_nickname' => $current_user->user_nicename,
13186
+ 'user_email' => $current_user->user_email,
13187
+ 'user_ip' => WP_FS__REMOTE_ADDR,
13188
+ 'plugin_slug' => $this->_slug,
13189
+ 'plugin_id' => $this->get_id(),
13190
+ 'plugin_public_key' => $this->get_public_key(),
13191
+ 'plugin_version' => $this->get_plugin_version(),
13192
+ 'return_url' => fs_nonce_url( $return_url, $activation_action ),
13193
+ 'account_url' => fs_nonce_url( $this->_get_admin_page_url(
13194
+ 'account',
13195
+ array( 'fs_action' => 'sync_user' )
13196
+ ), 'sync_user' ),
13197
+ 'platform_version' => get_bloginfo( 'version' ),
13198
+ 'sdk_version' => $this->version,
13199
+ 'programming_language_version' => phpversion(),
13200
+ 'is_premium' => $this->is_premium(),
13201
+ 'is_active' => true,
13202
+ 'is_uninstalled' => false,
13203
+ );
13204
+
13205
+ if ( true === $network_level_or_blog_id ) {
13206
+ if ( ! isset( $override_with['sites'] ) ) {
13207
+ $params['sites'] = array();
13208
+
13209
+ $sites = self::get_sites();
13210
+
13211
+ foreach ( $sites as $site ) {
13212
+ $blog_id = self::get_site_blog_id( $site );
13213
+ if ( ! $this->is_site_delegated_connection( $blog_id ) &&
13214
+ ! $this->is_installed_on_site( $blog_id )
13215
+ ) {
13216
+ $params['sites'][] = $this->get_site_info( $site );
13217
+ }
13218
+ }
13219
+ }
13220
+ } else {
13221
+ $site = is_numeric( $network_level_or_blog_id ) ?
13222
+ array( 'blog_id' => $network_level_or_blog_id ) :
13223
+ null;
13224
+
13225
+ $site = $this->get_site_info( $site );
13226
+
13227
+ $params = array_merge( $params, array(
13228
+ 'site_uid' => $site['uid'],
13229
+ 'site_url' => $site['url'],
13230
+ 'site_name' => $site['title'],
13231
+ 'language' => $site['language'],
13232
+ 'charset' => $site['charset'],
13233
+ ) );
13234
+ }
13235
+
13236
+ if ( $this->is_pending_activation() &&
13237
+ ! empty( $this->_storage->pending_license_key )
13238
+ ) {
13239
+ $params['license_key'] = $this->_storage->pending_license_key;
13240
+ }
13241
+
13242
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
13243
+ // Even though rand() is known for its security issues,
13244
+ // the timestamp adds another layer of protection.
13245
+ // It would be very hard for an attacker to get the secret key form here.
13246
+ // Plus, this should never run in production since the secret should never
13247
+ // be included in the production version.
13248
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
13249
+ $params['salt'] = md5( uniqid( rand() ) );
13250
+ $params['secure'] = md5(
13251
+ $params['ts'] .
13252
+ $params['salt'] .
13253
+ $this->get_secret_key()
13254
+ );
13255
+ }
13256
+
13257
+ return array_merge( $params, $override_with );
13258
+ }
13259
+
13260
+ /**
13261
+ * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
13262
+ * 2. If there was an API error, return the API result.
13263
+ *
13264
+ * @author Vova Feldman (@svovaf)
13265
+ * @since 1.1.7.4
13266
+ *
13267
+ * @param string|bool $email
13268
+ * @param string|bool $first
13269
+ * @param string|bool $last
13270
+ * @param string|bool $license_key
13271
+ * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
13272
+ * In this case, the user and site info will be sent to the server but no
13273
+ * data will be saved to the WP installation's database.
13274
+ * @param number|bool $trial_plan_id
13275
+ * @param bool $is_disconnected Whether or not to opt in without tracking.
13276
+ * @param null|bool $is_marketing_allowed
13277
+ * @param array $sites If network-level opt-in, an array of containing details of sites.
13278
+ *
13279
+ * @return string|object
13280
+ * @use WP_Error
13281
+ */
13282
+ function opt_in(
13283
+ $email = false,
13284
+ $first = false,
13285
+ $last = false,
13286
+ $license_key = false,
13287
+ $is_uninstall = false,
13288
+ $trial_plan_id = false,
13289
+ $is_disconnected = false,
13290
+ $is_marketing_allowed = null,
13291
+ $sites = array()
13292
+ ) {
13293
+ $this->_logger->entrance();
13294
+
13295
+ if ( false === $email ) {
13296
+ $current_user = self::_get_current_wp_user();
13297
+ $email = $current_user->user_email;
13298
+ }
13299
+
13300
+ /**
13301
+ * @since 1.2.1 If activating with license key, ignore the context-user
13302
+ * since the user will be automatically loaded from the license.
13303
+ */
13304
+ if ( empty( $license_key ) ) {
13305
+ // Clean up pending license if opt-ing in again.
13306
+ $this->_storage->remove( 'pending_license_key' );
13307
+
13308
+ if ( ! $is_uninstall ) {
13309
+ $fs_user = Freemius::_get_user_by_email( $email );
13310
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
13311
+ return $this->install_with_current_user(
13312
+ false,
13313
+ $trial_plan_id,
13314
+ $sites
13315
+ );
13316
+ }
13317
+ }
13318
+ }
13319
+
13320
+ $user_info = array();
13321
+ if ( ! empty( $email ) ) {
13322
+ $user_info['user_email'] = $email;
13323
+ }
13324
+ if ( ! empty( $first ) ) {
13325
+ $user_info['user_firstname'] = $first;
13326
+ }
13327
+ if ( ! empty( $last ) ) {
13328
+ $user_info['user_lastname'] = $last;
13329
+ }
13330
+
13331
+ if ( ! empty( $sites ) ) {
13332
+ $is_network = true;
13333
+
13334
+ $user_info['sites'] = $sites;
13335
+ } else {
13336
+ $is_network = false;
13337
+ }
13338
+
13339
+ $params = $this->get_opt_in_params( $user_info, $is_network );
13340
+
13341
+ $filtered_license_key = false;
13342
+ if ( is_string( $license_key ) ) {
13343
+ $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
13344
+ $params['license_key'] = $filtered_license_key;
13345
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
13346
+ $params['trial_plan_id'] = $trial_plan_id;
13347
+ }
13348
+
13349
+ if ( $is_uninstall ) {
13350
+ $params['uninstall_params'] = array(
13351
+ 'reason_id' => $this->_storage->uninstall_reason->id,
13352
+ 'reason_info' => $this->_storage->uninstall_reason->info
13353
+ );
13354
+ }
13355
+
13356
+ if ( isset( $params['license_key'] ) ) {
13357
+ $fs_user = Freemius::_get_user_by_email( $email );
13358
+
13359
+ if ( is_object( $fs_user ) ) {
13360
+ /**
13361
+ * If opting in with a context license and the context WP Admin user already opted in
13362
+ * before from the current site, add the user context security params to avoid the
13363
+ * unnecessary email activation when the context license is owned by the same context user.
13364
+ *
13365
+ * @author Leo Fajardo (@leorw)
13366
+ * @since 1.2.3
13367
+ */
13368
+ $params = array_merge( $params, FS_Security::instance()->get_context_params(
13369
+ $fs_user,
13370
+ false,
13371
+ 'install_with_existing_user'
13372
+ ) );
13373
+ }
13374
+ }
13375
+
13376
+ if ( is_bool( $is_marketing_allowed ) ) {
13377
+ $params['is_marketing_allowed'] = $is_marketing_allowed;
13378
+ }
13379
+
13380
+ $params['is_disconnected'] = $is_disconnected;
13381
+ $params['format'] = 'json';
13382
+
13383
+ $request = array(
13384
+ 'method' => 'POST',
13385
+ 'body' => $params,
13386
+ 'timeout' => WP_FS__DEBUG_SDK ? 60 : 30,
13387
+ );
13388
+
13389
+ $url = WP_FS__ADDRESS . '/action/service/user/install/';
13390
+ $response = self::safe_remote_post( $url, $request );
13391
+
13392
+ if ( is_wp_error( $response ) ) {
13393
+ /**
13394
+ * @var WP_Error $response
13395
+ */
13396
+ $result = new stdClass();
13397
+
13398
+ $error_code = $response->get_error_code();
13399
+ $error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
13400
+
13401
+ $result->error = (object) array(
13402
+ 'type' => $error_type,
13403
+ 'message' => $response->get_error_message(),
13404
+ 'code' => $error_code,
13405
+ 'http' => 402
13406
+ );
13407
+
13408
+ return $result;
13409
+ }
13410
+
13411
+ // Module is being uninstalled, don't handle the returned data.
13412
+ if ( $is_uninstall ) {
13413
+ return true;
13414
+ }
13415
+
13416
+ /**
13417
+ * When json_decode() executed on PHP 5.2 with an invalid JSON, it will throw a PHP warning. Unfortunately, the new Theme Check doesn't allow PHP silencing and the theme review team isn't open to change that, therefore, instead of using `@json_decode()` we had to use the method without the `@` directive.
13418
+ *
13419
+ * @author Vova Feldman (@svovaf)
13420
+ * @since 1.2.3
13421
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:5
13422
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:9
13423
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:12
13424
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:14
13425
+ */
13426
+ $decoded = is_string( $response['body'] ) ?
13427
+ json_decode( $response['body'] ) :
13428
+ null;
13429
+
13430
+ if ( empty( $decoded ) ) {
13431
+ return false;
13432
+ }
13433
+
13434
+ if ( ! $this->is_api_result_object( $decoded ) ) {
13435
+ if ( ! empty( $params['license_key'] ) ) {
13436
+ // Pass the fully entered license key to the failure handler.
13437
+ $params['license_key'] = $license_key;
13438
+ }
13439
+
13440
+ return $is_uninstall ?
13441
+ $decoded :
13442
+ $this->apply_filters( 'after_install_failure', $decoded, $params );
13443
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
13444
+ if ( $is_network ) {
13445
+ $site_ids = array();
13446
+ foreach ( $sites as $site ) {
13447
+ $site_ids[] = $site['blog_id'];
13448
+ }
13449
+
13450
+ /**
13451
+ * Store the sites so that they can be installed once the user has clicked on the activation link
13452
+ * in the email.
13453
+ *
13454
+ * @author Leo Fajardo (@leorw)
13455
+ */
13456
+ $this->_storage->pending_sites_info = array(
13457
+ 'blog_ids' => $site_ids,
13458
+ 'license_key' => $license_key,
13459
+ 'trial_plan_id' => $trial_plan_id
13460
+ );
13461
+ }
13462
+
13463
+ // Pending activation, add message.
13464
+ return $this->set_pending_confirmation(
13465
+ ( isset( $decoded->email ) ?
13466
+ $decoded->email :
13467
+ true ),
13468
+ false,
13469
+ $filtered_license_key,
13470
+ ! empty( $params['trial_plan_id'] )
13471
+ );
13472
+ } else if ( isset( $decoded->install_secret_key ) ) {
13473
+ return $this->install_with_new_user(
13474
+ $decoded->user_id,
13475
+ $decoded->user_public_key,
13476
+ $decoded->user_secret_key,
13477
+ ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
13478
+ $decoded->is_marketing_allowed :
13479
+ null ),
13480
+ $decoded->install_id,
13481
+ $decoded->install_public_key,
13482
+ $decoded->install_secret_key,
13483
+ false
13484
+ );
13485
+ } else if ( is_array( $decoded->installs ) ) {
13486
+ return $this->install_many_with_new_user(
13487
+ $decoded->user_id,
13488
+ $decoded->user_public_key,
13489
+ $decoded->user_secret_key,
13490
+ ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
13491
+ $decoded->is_marketing_allowed :
13492
+ null ),
13493
+ $decoded->installs,
13494
+ false
13495
+ );
13496
+ }
13497
+
13498
+ return $decoded;
13499
+ }
13500
+
13501
+ /**
13502
+ * Set user and site identities.
13503
+ *
13504
+ * @author Vova Feldman (@svovaf)
13505
+ * @since 1.0.9
13506
+ *
13507
+ * @param FS_User $user
13508
+ * @param FS_Site $site
13509
+ * @param bool $redirect
13510
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
13511
+ * redirect (or return a URL) to the account page with a special parameter to
13512
+ * trigger the auto installation processes.
13513
+ *
13514
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13515
+ */
13516
+ function setup_account(
13517
+ FS_User $user,
13518
+ FS_Site $site,
13519
+ $redirect = true,
13520
+ $auto_install = false
13521
+ ) {
13522
+ return $this->setup_network_account(
13523
+ $user,
13524
+ array( $site ),
13525
+ $redirect,
13526
+ $auto_install,
13527
+ false
13528
+ );
13529
+ }
13530
+
13531
+ /**
13532
+ * Set user and site identities.
13533
+ *
13534
+ * @author Vova Feldman (@svovaf)
13535
+ * @since 2.0.0
13536
+ *
13537
+ * @param FS_User $user
13538
+ * @param FS_Site[] $installs
13539
+ * @param bool $redirect
13540
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
13541
+ * @param bool $is_network_level_opt_in
13542
+ *
13543
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13544
+ */
13545
+ function setup_network_account(
13546
+ FS_User $user,
13547
+ array $installs,
13548
+ $redirect = true,
13549
+ $auto_install = false,
13550
+ $is_network_level_opt_in = true
13551
+ ) {
13552
+ $first_install = $installs[0];
13553
+
13554
+ $this->_user = $user;
13555
+ $this->_site = $first_install;
13556
+
13557
+ $this->_sync_plans();
13558
+
13559
+ if ( $this->_storage->handle_gdpr_admin_notice &&
13560
+ $this->should_handle_gdpr_admin_notice() &&
13561
+ FS_GDPR_Manager::instance()->should_show_opt_in_notice()
13562
+ ) {
13563
+ /**
13564
+ * Clear user lock after an opt-in.
13565
+ */
13566
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-user-lock.php';
13567
+ FS_User_Lock::instance()->unlock();
13568
+ }
13569
+
13570
+ if ( 1 < count( $installs ) ) {
13571
+ // Only network level opt-in can have more than one install.
13572
+ $is_network_level_opt_in = true;
13573
+ }
13574
+ // $is_network_level_opt_in = self::is_ajax_action_static( 'network_activate', $this->_module_id );
13575
+ // If Freemius was OFF before, turn it on.
13576
+ $this->turn_on();
13577
+
13578
+ if ( ! $this->_is_network_active || ! $is_network_level_opt_in ) {
13579
+ $this->_set_account( $user, $first_install );
13580
+
13581
+ $this->do_action( 'after_account_connection', $user, $first_install );
13582
+ } else {
13583
+ $this->_store_user();
13584
+
13585
+ // Map site addresses to their blog IDs.
13586
+ $address_to_blog_map = $this->get_address_to_blog_map();
13587
+
13588
+ $first_blog_id = null;
13589
+ $blog_2_install_map = array();
13590
+ foreach ( $installs as $install ) {
13591
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
13592
+ $blog_id = $address_to_blog_map[ $address ];
13593
+
13594
+ $this->_store_site( true, $blog_id, $install );
13595
+
13596
+ if ( is_null( $first_blog_id ) ) {
13597
+ $first_blog_id = $blog_id;
13598
+ }
13599
+
13600
+ $blog_2_install_map[ $blog_id ] = $install;
13601
+ }
13602
+
13603
+ if ( ! FS_User::is_valid_id( $this->_storage->network_user_id ) ||
13604
+ ! is_object( self::_get_user_by_id( $this->_storage->network_user_id ) )
13605
+ ) {
13606
+ // Store network user.
13607
+ $this->_storage->network_user_id = $this->_user->id;
13608
+ }
13609
+
13610
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
13611
+ $this->_storage->network_install_blog_id = $first_blog_id;
13612
+ }
13613
+
13614
+ if ( count( $installs ) === count( $address_to_blog_map ) ) {
13615
+ // Super-admin opted-in for all sites in the network.
13616
+ $this->_storage->is_network_connected = true;
13617
+ }
13618
+
13619
+ $this->_store_licenses( false );
13620
+
13621
+ self::$_accounts->store();
13622
+
13623
+ // Don't sync the installs data on network upgrade
13624
+ if ( ! $this->network_upgrade_mode_completed() ) {
13625
+ $this->send_installs_update();
13626
+ }
13627
+
13628
+ // Switch install context back to the first install.
13629
+ $this->_site = $first_install;
13630
+
13631
+ $current_blog = get_current_blog_id();
13632
+
13633
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
13634
+ $this->switch_to_blog( $blog_id );
13635
+
13636
+ $this->do_action( 'after_account_connection', $user, $install );
13637
+ }
13638
+
13639
+ $this->switch_to_blog( $current_blog );
13640
+
13641
+ $this->do_action( 'after_network_account_connection', $user, $blog_2_install_map );
13642
+ }
13643
+
13644
+ if ( is_numeric( $first_install->license_id ) ) {
13645
+ $this->_license = $this->_get_license_by_id( $first_install->license_id );
13646
+ }
13647
+
13648
+ $this->_admin_notices->remove_sticky( 'connect_account' );
13649
+
13650
+ if ( $this->is_pending_activation() || ! $this->has_settings_menu() ) {
13651
+ // Remove pending activation sticky notice (if still exist).
13652
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
13653
+
13654
+ // Remove plugin from pending activation mode.
13655
+ unset( $this->_storage->is_pending_activation );
13656
+
13657
+ if ( ! $this->is_paying_or_trial() ) {
13658
+ $this->_admin_notices->add_sticky(
13659
+ sprintf( $this->get_text_inline( '%s activation was successfully completed.', 'plugin-x-activation-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
13660
+ 'activation_complete'
13661
+ );
13662
+ }
13663
+ }
13664
+
13665
+ if ( $this->is_paying_or_trial() ) {
13666
+ if ( ! $this->is_premium() ||
13667
+ ! $this->has_premium_version() ||
13668
+ ! $this->has_settings_menu()
13669
+ ) {
13670
+ if ( $this->is_paying() ) {
13671
+ $this->_admin_notices->add_sticky(
13672
+ sprintf(
13673
+ $this->get_text_inline( 'Your account was successfully activated with the %s plan.', 'activation-with-plan-x-message' ),
13674
+ $this->get_plan_title()
13675
+ ) . $this->get_complete_upgrade_instructions(),
13676
+ 'plan_upgraded',
13677
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
13678
+ );
13679
+ } else {
13680
+ $trial_plan = $this->get_trial_plan();
13681
+
13682
+ $this->_admin_notices->add_sticky(
13683
+ sprintf(
13684
+ $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
13685
+ '<i>' . $this->get_plugin_name() . '</i>'
13686
+ ) . $this->get_complete_upgrade_instructions( $trial_plan->title ),
13687
+ 'trial_started',
13688
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
13689
+ );
13690
+ }
13691
+ }
13692
+
13693
+ $this->_admin_notices->remove_sticky( array(
13694
+ 'trial_promotion',
13695
+ ) );
13696
+ }
13697
+
13698
+ $plugin_id = fs_request_get( 'plugin_id', false );
13699
+
13700
+ // Store activation time ONLY for plugins & themes (not add-ons).
13701
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
13702
+ if ( empty( $this->_storage->activation_timestamp ) ) {
13703
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
13704
+ }
13705
+ }
13706
+
13707
+ $next_page = '';
13708
+
13709
+ $extra = array();
13710
+ if ( $auto_install ) {
13711
+ $extra['auto_install'] = 'true';
13712
+ }
13713
+
13714
+ if ( is_numeric( $plugin_id ) ) {
13715
+ /**
13716
+ * @author Leo Fajardo (@leorw)
13717
+ * @since 1.2.1.6
13718
+ *
13719
+ * Also sync the license after an anonymous user subscribes.
13720
+ */
13721
+ if ( $this->is_anonymous() || $plugin_id != $this->_plugin->id ) {
13722
+ // Add-on was installed - sync license right after install.
13723
+ $next_page = $this->_get_sync_license_url( $plugin_id, true, $extra );
13724
+ }
13725
+ } else {
13726
+ /**
13727
+ * @author Vova Feldman (@svovaf)
13728
+ * @since 1.1.9 If site installed with a valid license, sync license.
13729
+ */
13730
+ if ( $this->is_paying() ) {
13731
+ $this->_sync_plugin_license(
13732
+ true,
13733
+ // Installs data is already synced in the beginning of this method directly or via _set_account().
13734
+ false
13735
+ );
13736
+ }
13737
+
13738
+ // Reload the page with the keys.
13739
+ $next_page = $this->is_anonymous() ?
13740
+ // If user previously skipped, redirect to account page.
13741
+ $this->get_account_url( false, $extra ) :
13742
+ $this->get_after_activation_url( 'after_connect_url', array(), $is_network_level_opt_in );
13743
+ }
13744
+
13745
+ if ( ! empty( $next_page ) && $redirect ) {
13746
+ fs_redirect( $next_page );
13747
+ }
13748
+
13749
+ return $next_page;
13750
+ }
13751
+
13752
+ /**
13753
+ * Install plugin with new user information after approval.
13754
+ *
13755
+ * @author Vova Feldman (@svovaf)
13756
+ * @since 1.0.7
13757
+ */
13758
+ function _install_with_new_user() {
13759
+ $this->_logger->entrance();
13760
+
13761
+ if ( $this->is_registered() ) {
13762
+ return;
13763
+ }
13764
+
13765
+ if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
13766
+ // @todo This logic should be improved because it's executed on every load of a theme.
13767
+ $this->is_theme()
13768
+ ) {
13769
+ // check_admin_referer( $this->_slug . '_activate_new' );
13770
+
13771
+ if ( fs_request_has( 'user_secret_key' ) ) {
13772
+ if ( fs_is_network_admin() && isset( $this->_storage->pending_sites_info ) ) {
13773
+ $pending_sites_info = $this->_storage->pending_sites_info;
13774
+
13775
+ $this->install_many_pending_with_user(
13776
+ fs_request_get( 'user_id' ),
13777
+ fs_request_get( 'user_public_key' ),
13778
+ fs_request_get( 'user_secret_key' ),
13779
+ fs_request_get_bool( 'is_marketing_allowed', null ),
13780
+ $pending_sites_info['blog_ids'],
13781
+ $pending_sites_info['license_key'],
13782
+ $pending_sites_info['trial_plan_id']
13783
+ );
13784
+ } else {
13785
+ $this->install_with_new_user(
13786
+ fs_request_get( 'user_id' ),
13787
+ fs_request_get( 'user_public_key' ),
13788
+ fs_request_get( 'user_secret_key' ),
13789
+ fs_request_get_bool( 'is_marketing_allowed', null ),
13790
+ fs_request_get( 'install_id' ),
13791
+ fs_request_get( 'install_public_key' ),
13792
+ fs_request_get( 'install_secret_key' ),
13793
+ true,
13794
+ fs_request_get_bool( 'auto_install' )
13795
+ );
13796
+ }
13797
+ } else if ( fs_request_has( 'pending_activation' ) ) {
13798
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
13799
+ }
13800
+ }
13801
+ }
13802
+
13803
+ /**
13804
+ * @author Vova Feldman (@svovaf)
13805
+ * @since 2.0.0
13806
+ *
13807
+ * @param number $id
13808
+ * @param string $public_key
13809
+ * @param string $secret_key
13810
+ *
13811
+ * @return \FS_User
13812
+ */
13813
+ private function setup_user( $id, $public_key, $secret_key ) {
13814
+ $user = self::_get_user_by_id( $id );
13815
+
13816
+ if ( is_object( $user ) ) {
13817
+ $this->_user = $user;
13818
+ } else {
13819
+ $user = new FS_User();
13820
+ $user->id = $id;
13821
+ $user->public_key = $public_key;
13822
+ $user->secret_key = $secret_key;
13823
+
13824
+ $this->_user = $user;
13825
+ $user_result = $this->get_api_user_scope()->get();
13826
+ $user = new FS_User( $user_result );
13827
+
13828
+ $this->_user = $user;
13829
+ $this->_store_user();
13830
+ }
13831
+
13832
+ return $user;
13833
+ }
13834
+
13835
+ /**
13836
+ * Install plugin with new user.
13837
+ *
13838
+ * @author Vova Feldman (@svovaf)
13839
+ * @since 1.1.7.4
13840
+ *
13841
+ * @param number $user_id
13842
+ * @param string $user_public_key
13843
+ * @param string $user_secret_key
13844
+ * @param bool|null $is_marketing_allowed
13845
+ * @param number $install_id
13846
+ * @param string $install_public_key
13847
+ * @param string $install_secret_key
13848
+ * @param bool $redirect
13849
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
13850
+ * redirect (or return a URL) to the account page with a special parameter to
13851
+ * trigger the auto installation processes.
13852
+ *
13853
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13854
+ */
13855
+ private function install_with_new_user(
13856
+ $user_id,
13857
+ $user_public_key,
13858
+ $user_secret_key,
13859
+ $is_marketing_allowed,
13860
+ $install_id,
13861
+ $install_public_key,
13862
+ $install_secret_key,
13863
+ $redirect = true,
13864
+ $auto_install = false
13865
+ ) {
13866
+ /**
13867
+ * This method is also executed after opting in with a license key since the
13868
+ * license can be potentially associated with a different owner.
13869
+ *
13870
+ * @since 2.0.0
13871
+ */
13872
+ $user = self::_get_user_by_id( $user_id );
13873
+
13874
+ if ( ! is_object( $user ) ) {
13875
+ $user = new FS_User();
13876
+ $user->id = $user_id;
13877
+ $user->public_key = $user_public_key;
13878
+ $user->secret_key = $user_secret_key;
13879
+
13880
+ $this->_user = $user;
13881
+ $user_result = $this->get_api_user_scope()->get();
13882
+ $user = new FS_User( $user_result );
13883
+ }
13884
+
13885
+ $this->_user = $user;
13886
+
13887
+ $site = new FS_Site();
13888
+ $site->id = $install_id;
13889
+ $site->public_key = $install_public_key;
13890
+ $site->secret_key = $install_secret_key;
13891
+
13892
+ $this->_site = $site;
13893
+ $site_result = $this->get_api_site_scope()->get();
13894
+ $site = new FS_Site( $site_result );
13895
+ $this->_site = $site;
13896
+
13897
+ if ( ! is_null( $is_marketing_allowed ) ) {
13898
+ $this->disable_opt_in_notice_and_lock_user();
13899
+ }
13900
+
13901
+ return $this->setup_account(
13902
+ $this->_user,
13903
+ $this->_site,
13904
+ $redirect,
13905
+ $auto_install
13906
+ );
13907
+ }
13908
+
13909
+ /**
13910
+ * Install plugin with user.
13911
+ *
13912
+ * @author Leo Fajardo (@leorw)
13913
+ * @since 2.0.0
13914
+ *
13915
+ * @param number $user_id
13916
+ * @param string $user_public_key
13917
+ * @param string $user_secret_key
13918
+ * @param bool|null $is_marketing_allowed
13919
+ * @param array $site_ids
13920
+ * @param bool $license_key
13921
+ * @param bool $trial_plan_id
13922
+ * @param bool $redirect
13923
+ *
13924
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13925
+ */
13926
+ private function install_many_pending_with_user(
13927
+ $user_id,
13928
+ $user_public_key,
13929
+ $user_secret_key,
13930
+ $is_marketing_allowed,
13931
+ $site_ids,
13932
+ $license_key = false,
13933
+ $trial_plan_id = false,
13934
+ $redirect = true
13935
+ ) {
13936
+ $user = $this->setup_user( $user_id, $user_public_key, $user_secret_key );
13937
+
13938
+ if ( ! is_null( $is_marketing_allowed ) ) {
13939
+ $this->disable_opt_in_notice_and_lock_user();
13940
+ }
13941
+
13942
+ $sites = array();
13943
+ foreach ( $site_ids as $site_id ) {
13944
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
13945
+ }
13946
+
13947
+ $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
13948
+ }
13949
+
13950
+ /**
13951
+ * Multi-site install with a new user.
13952
+ *
13953
+ * @author Vova Feldman (@svovaf)
13954
+ * @since 2.0.0
13955
+ *
13956
+ * @param number $user_id
13957
+ * @param string $user_public_key
13958
+ * @param string $user_secret_key
13959
+ * @param bool|null $is_marketing_allowed
13960
+ * @param object[] $installs
13961
+ * @param bool $redirect
13962
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
13963
+ * redirect (or return a URL) to the account page with a special parameter to
13964
+ * trigger the auto installation processes.
13965
+ *
13966
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13967
+ */
13968
+ private function install_many_with_new_user(
13969
+ $user_id,
13970
+ $user_public_key,
13971
+ $user_secret_key,
13972
+ $is_marketing_allowed,
13973
+ array $installs,
13974
+ $redirect = true,
13975
+ $auto_install = false
13976
+ ) {
13977
+ $this->setup_user( $user_id, $user_public_key, $user_secret_key );
13978
+
13979
+ if ( ! is_null( $is_marketing_allowed ) ) {
13980
+ $this->disable_opt_in_notice_and_lock_user();
13981
+ }
13982
+
13983
+ $install_ids = array();
13984
+
13985
+ foreach ( $installs as $install ) {
13986
+ $install_ids[] = $install->id;
13987
+ }
13988
+
13989
+ $left = count( $install_ids );
13990
+ $offset = 0;
13991
+
13992
+ $installs = array();
13993
+ while ( $left > 0 ) {
13994
+ $result = $this->get_api_user_scope()->get( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', array_slice( $install_ids, $offset, 25 ) ) );
13995
+
13996
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
13997
+ // @todo Handle API error.
13998
+ }
13999
+
14000
+ $installs = array_merge( $installs, $result->installs );
14001
+
14002
+ $left -= 25;
14003
+ }
14004
+
14005
+ foreach ( $installs as &$install ) {
14006
+ $install = new FS_Site( $install );
14007
+ }
14008
+
14009
+ return $this->setup_network_account(
14010
+ $this->_user,
14011
+ $installs,
14012
+ $redirect,
14013
+ $auto_install
14014
+ );
14015
+ }
14016
+
14017
+ /**
14018
+ * @author Vova Feldman (@svovaf)
14019
+ * @since 1.1.7.4
14020
+ *
14021
+ * @param string|bool $email
14022
+ * @param bool $redirect
14023
+ * @param string|bool $license_key Since 1.2.1.5
14024
+ * @param bool $is_pending_trial Since 1.2.1.5
14025
+ *
14026
+ * @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
14027
+ */
14028
+ private function set_pending_confirmation(
14029
+ $email = false,
14030
+ $redirect = true,
14031
+ $license_key = false,
14032
+ $is_pending_trial = false
14033
+ ) {
14034
+ if ( $this->_ignore_pending_mode ) {
14035
+ /**
14036
+ * If explicitly asked to ignore pending mode, set to anonymous mode
14037
+ * if require confirmation before finalizing the opt-in.
14038
+ *
14039
+ * @author Vova Feldman
14040
+ * @since 1.2.1.6
14041
+ */
14042
+ $this->skip_connection( null, fs_is_network_admin() );
14043
+ } else {
14044
+ // Install must be activated via email since
14045
+ // user with the same email already exist.
14046
+ $this->_storage->is_pending_activation = true;
14047
+ $this->_add_pending_activation_notice( $email, $is_pending_trial );
14048
+ }
14049
+
14050
+ if ( ! empty( $license_key ) ) {
14051
+ $this->_storage->pending_license_key = $license_key;
14052
+ }
14053
+
14054
+ // Remove the opt-in sticky notice.
14055
+ $this->_admin_notices->remove_sticky( array(
14056
+ 'connect_account',
14057
+ 'trial_promotion',
14058
+ ) );
14059
+
14060
+ $next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
14061
+
14062
+ // Reload the page with with pending activation message.
14063
+ if ( $redirect ) {
14064
+ fs_redirect( $next_page );
14065
+ }
14066
+
14067
+ return $next_page;
14068
+ }
14069
+
14070
+ /**
14071
+ * Install plugin with current logged WP user info.
14072
+ *
14073
+ * @author Vova Feldman (@svovaf)
14074
+ * @since 1.0.7
14075
+ */
14076
+ function _install_with_current_user() {
14077
+ $this->_logger->entrance();
14078
+
14079
+ if ( $this->is_registered() ) {
14080
+ return;
14081
+ }
14082
+
14083
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
14084
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
14085
+
14086
+ /**
14087
+ * @author Vova Feldman (@svovaf)
14088
+ * @since 1.1.9 Add license key if given.
14089
+ */
14090
+ $license_key = fs_request_get( 'license_secret_key' );
14091
+
14092
+ $this->install_with_current_user( $license_key );
14093
+ }
14094
+ }
14095
+
14096
+
14097
+ /**
14098
+ * @author Vova Feldman (@svovaf)
14099
+ * @since 1.1.7.4
14100
+ *
14101
+ * @param string|bool $license_key
14102
+ * @param number|bool $trial_plan_id
14103
+ * @param array $sites Since 2.0.0
14104
+ * @param bool $redirect
14105
+ *
14106
+ * @return object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install.
14107
+ */
14108
+ private function install_with_current_user(
14109
+ $license_key = false,
14110
+ $trial_plan_id = false,
14111
+ $sites = array(),
14112
+ $redirect = true
14113
+ ) {
14114
+ // Get current logged WP user.
14115
+ $current_user = self::_get_current_wp_user();
14116
+
14117
+ // Find the relevant FS user by the email.
14118
+ $user = self::_get_user_by_email( $current_user->user_email );
14119
+
14120
+ return $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
14121
+ }
14122
+
14123
+ /**
14124
+ * @author Vova Feldman (@svovaf)
14125
+ * @since 2.0.0
14126
+ *
14127
+ * @param \FS_User $user
14128
+ * @param string|bool $license_key
14129
+ * @param number|bool $trial_plan_id
14130
+ * @param bool $redirect
14131
+ * @param bool $setup_account Since 2.0.0. When set to FALSE, executes a light installation without setting up the account as if it's the first opt-in.
14132
+ * @param array $sites Since 2.0.0. If not empty, should be a collection of site details for the bulk install API request.
14133
+ *
14134
+ * @return \FS_Site|object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install. If $setup_account is set to `false`, return the newly created install.
14135
+ */
14136
+ private function install_with_user(
14137
+ FS_User $user,
14138
+ $license_key = false,
14139
+ $trial_plan_id = false,
14140
+ $redirect = true,
14141
+ $setup_account = true,
14142
+ $sites = array()
14143
+ ) {
14144
+ // We have to set the user before getting user scope API handler.
14145
+ $this->_user = $user;
14146
+
14147
+ // Install the plugin.
14148
+ $result = $this->create_installs_with_user(
14149
+ $user,
14150
+ $license_key,
14151
+ $trial_plan_id,
14152
+ $sites,
14153
+ $redirect
14154
+ );
14155
+
14156
+ if ( ! $this->is_api_result_entity( $result ) &&
14157
+ ! $this->is_api_result_object( $result, 'installs' )
14158
+ ) {
14159
+ // @todo Handler potential API error of the $result
14160
+ }
14161
+
14162
+ if ( empty( $sites ) ) {
14163
+ $site = new FS_Site( $result );
14164
+ $this->_site = $site;
14165
+
14166
+ if ( ! $setup_account ) {
14167
+ $this->_store_site();
14168
+
14169
+ $this->sync_plan_if_not_exist( $site->plan_id );
14170
+
14171
+ if ( ! empty( $license_key ) && FS_Plugin_License::is_valid_id( $site->license_id ) ) {
14172
+ $this->sync_license_if_not_exist( $site->license_id, $license_key );
14173
+ }
14174
+
14175
+ $this->_admin_notices->remove_sticky( 'connect_account', false );
14176
+
14177
+ return $site;
14178
+ }
14179
+
14180
+ return $this->setup_account( $this->_user, $this->_site, $redirect );
14181
+ } else {
14182
+ $installs = array();
14183
+ foreach ( $result->installs as $install ) {
14184
+ $installs[] = new FS_Site( $install );
14185
+ }
14186
+
14187
+ return $this->setup_network_account(
14188
+ $user,
14189
+ $installs,
14190
+ $redirect
14191
+ );
14192
+ }
14193
+ }
14194
+
14195
+ /**
14196
+ * Initiate an API request to create a collection of installs.
14197
+ *
14198
+ * @author Vova Feldman (@svovaf)
14199
+ * @since 2.0.0
14200
+ *
14201
+ * @param \FS_User $user
14202
+ * @param bool $license_key
14203
+ * @param bool $trial_plan_id
14204
+ * @param array $sites
14205
+ * @param bool $redirect
14206
+ * @param bool $silent
14207
+ *
14208
+ * @return object|mixed
14209
+ */
14210
+ private function create_installs_with_user(
14211
+ FS_User $user,
14212
+ $license_key = false,
14213
+ $trial_plan_id = false,
14214
+ $sites = array(),
14215
+ $redirect = false,
14216
+ $silent = false
14217
+ ) {
14218
+ $extra_install_params = array(
14219
+ 'uid' => $this->get_anonymous_id(),
14220
+ 'is_disconnected' => false,
14221
+ );
14222
+
14223
+ if ( ! empty( $license_key ) ) {
14224
+ $extra_install_params['license_key'] = $this->apply_filters( 'license_key', $license_key );
14225
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
14226
+ $extra_install_params['trial_plan_id'] = $trial_plan_id;
14227
+ }
14228
+
14229
+ if ( ! empty( $sites ) ) {
14230
+ $extra_install_params['sites'] = $sites;
14231
+ }
14232
+
14233
+ $args = $this->get_install_data_for_api( $extra_install_params, false, false );
14234
+
14235
+ // Install the plugin.
14236
+ $result = $this->get_api_user_scope_by_user( $user )->call(
14237
+ "/plugins/{$this->get_id()}/installs.json",
14238
+ 'post',
14239
+ $args
14240
+ );
14241
+
14242
+ if ( ! $this->is_api_result_entity( $result ) &&
14243
+ ! $this->is_api_result_object( $result, 'installs' )
14244
+ ) {
14245
+ if ( ! empty( $args['license_key'] ) ) {
14246
+ // Pass full the fully entered license key to the failure handler.
14247
+ $args['license_key'] = $license_key;
14248
+ }
14249
+
14250
+ $result = $this->apply_filters( 'after_install_failure', $result, $args );
14251
+
14252
+ if ( ! $silent ) {
14253
+ $this->_admin_notices->add(
14254
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
14255
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $result->error->message . '</b>',
14256
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
14257
+ 'error'
14258
+ );
14259
+ }
14260
+
14261
+ if ( $redirect ) {
14262
+ /**
14263
+ * We set the user before getting the user scope API handler, so the user became temporarily
14264
+ * registered (`is_registered() = true`). Since the API returned an error and we will redirect,
14265
+ * we have to set the user to `null`, otherwise, the user will be redirected to the wrong
14266
+ * activation page based on the return value of `is_registered()`. In addition, in case the
14267
+ * context plugin doesn't have a settings menu and the default page is the `Plugins` page,
14268
+ * misleading plugin activation errors will be shown on the `Plugins` page.
14269
+ *
14270
+ * @author Leo Fajardo (@leorw)
14271
+ */
14272
+ $this->_user = null;
14273
+
14274
+ fs_redirect( $this->get_activation_url( array( 'error' => $result->error->message ) ) );
14275
+ }
14276
+ }
14277
+
14278
+ return $result;
14279
+ }
14280
+
14281
+ /**
14282
+ * Tries to activate add-on account based on parent plugin info.
14283
+ *
14284
+ * @author Vova Feldman (@svovaf)
14285
+ * @since 1.0.6
14286
+ *
14287
+ * @param Freemius $parent_fs
14288
+ */
14289
+ private function _activate_addon_account( Freemius $parent_fs ) {
14290
+ if ( $this->is_registered() ) {
14291
+ // Already activated.
14292
+ return;
14293
+ }
14294
+
14295
+ // Activate add-on with parent plugin credentials.
14296
+ $addon_install = $parent_fs->get_api_site_scope()->call(
14297
+ "/addons/{$this->_plugin->id}/installs.json",
14298
+ 'post',
14299
+ $this->get_install_data_for_api( array(
14300
+ 'uid' => $this->get_anonymous_id(),
14301
+ ), false, false )
14302
+ );
14303
+
14304
+ if ( isset( $addon_install->error ) ) {
14305
+ $this->_admin_notices->add(
14306
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
14307
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
14308
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
14309
+ 'error'
14310
+ );
14311
+
14312
+ return;
14313
+ }
14314
+
14315
+ // Get user information based on parent's plugin.
14316
+ $user = $parent_fs->get_user();
14317
+
14318
+ // First of all, set site and user info - otherwise we won't
14319
+ // be able to invoke API calls.
14320
+ $this->_site = new FS_Site( $addon_install );
14321
+ $this->_user = $user;
14322
+
14323
+ // Sync add-on plans.
14324
+ $this->_sync_plans();
14325
+
14326
+ // Get site's current plan.
14327
+ //$this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
14328
+
14329
+ $this->_set_account( $user, $this->_site );
14330
+
14331
+ // Sync licenses.
14332
+ $this->_sync_licenses();
14333
+
14334
+ // Try to activate premium license.
14335
+ $this->_activate_license( true );
14336
+ }
14337
+
14338
+ /**
14339
+ * Tries to activate parent account based on add-on's info.
14340
+ *
14341
+ * @author Vova Feldman (@svovaf)
14342
+ * @since 1.2.2.7
14343
+ *
14344
+ * @param Freemius $parent_fs
14345
+ */
14346
+ private function activate_parent_account( Freemius $parent_fs ) {
14347
+ if ( ! $this->is_addon() ) {
14348
+ // This is not an add-on.
14349
+ return;
14350
+ }
14351
+
14352
+ if ( $parent_fs->is_registered() ) {
14353
+ // Already activated.
14354
+ return;
14355
+ }
14356
+
14357
+ // Activate parent with add-on's user credentials.
14358
+ $parent_install = $this->get_api_user_scope()->call(
14359
+ "/plugins/{$parent_fs->_plugin->id}/installs.json",
14360
+ 'post',
14361
+ $parent_fs->get_install_data_for_api( array(
14362
+ 'uid' => $parent_fs->get_anonymous_id(),
14363
+ ), false, false )
14364
+ );
14365
+
14366
+ if ( isset( $parent_install->error ) ) {
14367
+ $this->_admin_notices->add(
14368
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
14369
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $parent_install->error->message . '</b>',
14370
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
14371
+ 'error'
14372
+ );
14373
+
14374
+ return;
14375
+ }
14376
+
14377
+ $parent_fs->_admin_notices->remove_sticky( 'connect_account' );
14378
+
14379
+ if ( $parent_fs->is_pending_activation() ) {
14380
+ $parent_fs->_admin_notices->remove_sticky( 'activation_pending' );
14381
+
14382
+ unset( $parent_fs->_storage->is_pending_activation );
14383
+ }
14384
+
14385
+ // Get user information based on parent's plugin.
14386
+ $user = $this->get_user();
14387
+
14388
+ // First of all, set site info - otherwise we won't
14389
+ // be able to invoke API calls.
14390
+ $parent_fs->_site = new FS_Site( $parent_install );
14391
+ $parent_fs->_user = $user;
14392
+
14393
+ // Sync add-on plans.
14394
+ $parent_fs->_sync_plans();
14395
+
14396
+ $parent_fs->_set_account( $user, $parent_fs->_site );
14397
+ }
14398
+
14399
+ #endregion
14400
+
14401
+ #----------------------------------------------------------------------------------
14402
+ #region Admin Menu Items
14403
+ #----------------------------------------------------------------------------------
14404
+
14405
+ private $_menu_items = array();
14406
+
14407
+ /**
14408
+ * @author Vova Feldman (@svovaf)
14409
+ * @since 1.2.1.8
14410
+ *
14411
+ * @return array
14412
+ */
14413
+ function get_menu_items() {
14414
+ return $this->_menu_items;
14415
+ }
14416
+
14417
+ /**
14418
+ * @author Vova Feldman (@svovaf)
14419
+ * @since 1.0.7
14420
+ *
14421
+ * @return string
14422
+ */
14423
+ function get_menu_slug() {
14424
+ return $this->_menu->get_slug();
14425
+ }
14426
+
14427
+ /**
14428
+ * @author Vova Feldman (@svovaf)
14429
+ * @since 1.0.9
14430
+ */
14431
+ function _prepare_admin_menu() {
14432
+ // if ( ! $this->is_on() ) {
14433
+ // return;
14434
+ // }
14435
+
14436
+ /**
14437
+ * When running from a site admin with a network activated module and the connection
14438
+ * was NOT delegated and the user still haven't skipped or opted-in, then hide the
14439
+ * site level settings.
14440
+ *
14441
+ * @author Vova Feldman (@svovaf)
14442
+ * @since 2.0.0
14443
+ */
14444
+ $should_hide_site_admin_settings = (
14445
+ $this->_is_network_active &&
14446
+ ! fs_is_network_admin() &&
14447
+ ! $this->is_delegated_connection() &&
14448
+ ! $this->is_anonymous() &&
14449
+ ! $this->is_registered()
14450
+ );
14451
+
14452
+ if ( ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) ||
14453
+ $should_hide_site_admin_settings
14454
+ ) {
14455
+ $this->_menu->remove_menu_item( $should_hide_site_admin_settings );
14456
+ } else {
14457
+ $this->do_action( fs_is_network_admin() ?
14458
+ 'before_network_admin_menu_init' :
14459
+ 'before_admin_menu_init'
14460
+ );
14461
+
14462
+ $this->add_menu_action();
14463
+
14464
+ $this->add_network_menu_when_missing();
14465
+
14466
+ $this->add_submenu_items();
14467
+ }
14468
+ }
14469
+
14470
+ /**
14471
+ * Admin dashboard menu items modifications.
14472
+ *
14473
+ * NOTE: admin_menu action executed before admin_init.
14474
+ *
14475
+ * @author Vova Feldman (@svovaf)
14476
+ * @since 1.0.7
14477
+ *
14478
+ */
14479
+ private function add_menu_action() {
14480
+ if ( $this->is_activation_mode() ) {
14481
+ if ( $this->is_plugin() || ( $this->has_settings_menu() && ! $this->is_free_wp_org_theme() ) ) {
14482
+ $this->override_plugin_menu_with_activation();
14483
+ } else {
14484
+ /**
14485
+ * Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
14486
+ */
14487
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
14488
+ add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
14489
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
14490
+ fs_request_get_bool( 'pending_activation' )
14491
+ ) {
14492
+ add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
14493
+ }
14494
+ }
14495
+ } else {
14496
+ if ( ! $this->is_registered() ) {
14497
+ // If not registered try to install user.
14498
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
14499
+ $this->_install_with_new_user();
14500
+ }
14501
+ } else if (
14502
+ fs_request_is_action( 'sync_user' ) &&
14503
+ ( ! $this->has_settings_menu() || $this->is_free_wp_org_theme() )
14504
+ ) {
14505
+ $this->_handle_account_user_sync();
14506
+ }
14507
+ }
14508
+ }
14509
+
14510
+ /**
14511
+ * @author Vova Feldman (@svovaf)
14512
+ * @since 1.0.1
14513
+ */
14514
+ function _redirect_on_clicked_menu_link() {
14515
+ $this->_logger->entrance();
14516
+
14517
+ $page = fs_request_get('page');
14518
+ $page = is_string($page) ? strtolower($page) : '';
14519
+
14520
+ $this->_logger->log( 'page = ' . $page );
14521
+
14522
+ foreach ( $this->_menu_items as $priority => $items ) {
14523
+ foreach ( $items as $item ) {
14524
+ if ( isset( $item['url'] ) ) {
14525
+ if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
14526
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
14527
+
14528
+ fs_redirect( $item['url'] );
14529
+ }
14530
+ }
14531
+ }
14532
+ }
14533
+ }
14534
+
14535
+ /**
14536
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
14537
+ *
14538
+ * @author Vova Feldman (@svovaf)
14539
+ * @since 1.0.1
14540
+ */
14541
+ private function override_plugin_menu_with_activation() {
14542
+ $this->_logger->entrance();
14543
+
14544
+ $hook = false;
14545
+
14546
+ if ( ! $this->_menu->has_menu() ) {
14547
+ // Add the opt-in page without a menu item.
14548
+ $hook = FS_Admin_Menu_Manager::add_subpage(
14549
+ null,
14550
+ $this->get_plugin_name(),
14551
+ $this->get_plugin_name(),
14552
+ 'manage_options',
14553
+ $this->_slug,
14554
+ array( &$this, '_connect_page_render' )
14555
+ );
14556
+ } else if ( $this->_menu->is_top_level() ) {
14557
+ if ( $this->_menu->is_override_exact() ) {
14558
+ // Make sure the current page is matching the activation page.
14559
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
14560
+ return;
14561
+ }
14562
+ }
14563
+
14564
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
14565
+
14566
+ if ( false === $hook ) {
14567
+ // Create new menu item just for the opt-in.
14568
+ $hook = FS_Admin_Menu_Manager::add_page(
14569
+ $this->get_plugin_name(),
14570
+ $this->get_plugin_name(),
14571
+ 'manage_options',
14572
+ $this->_menu->get_slug(),
14573
+ array( &$this, '_connect_page_render' )
14574
+ );
14575
+ }
14576
+ } else {
14577
+ $menus = array( $this->_menu->get_parent_slug() );
14578
+
14579
+ if ( $this->_menu->is_override_exact() ) {
14580
+ // Make sure the current page is matching the activation page.
14581
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
14582
+ return;
14583
+ }
14584
+ }
14585
+
14586
+ foreach ( $menus as $parent_slug ) {
14587
+ $hook = $this->_menu->override_submenu_action(
14588
+ $parent_slug,
14589
+ $this->_menu->get_raw_slug(),
14590
+ array( &$this, '_connect_page_render' )
14591
+ );
14592
+
14593
+ if ( false !== $hook ) {
14594
+ // Found plugin's submenu item.
14595
+ break;
14596
+ }
14597
+ }
14598
+ }
14599
+
14600
+ if ( $this->is_activation_page() ) {
14601
+ // Clean admin page from distracting content.
14602
+ self::_clean_admin_content_section();
14603
+ }
14604
+
14605
+ if ( false !== $hook ) {
14606
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
14607
+ $this->_install_with_current_user();
14608
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
14609
+ $this->_install_with_new_user();
14610
+ }
14611
+ }
14612
+ }
14613
+
14614
+ /**
14615
+ * If a plugin was network activated and connected but don't have a network
14616
+ * level settings, then add an artificial menu item for the Account and other
14617
+ * Freemius settings.
14618
+ *
14619
+ * @author Vova Feldman (@svovaf)
14620
+ * @since 2.0.0
14621
+ */
14622
+ private function add_network_menu_when_missing() {
14623
+ $this->_logger->entrance();
14624
+
14625
+ if ( ! $this->_is_network_active ) {
14626
+ // Plugin wasn't activated on the network level.
14627
+ return;
14628
+ }
14629
+
14630
+ if ( ! fs_is_network_admin() ) {
14631
+ // The context is not the network admin.
14632
+ return;
14633
+ }
14634
+
14635
+ if ( $this->_menu->has_network_menu() ) {
14636
+ // Plugin already has a network level menu.
14637
+ return;
14638
+ }
14639
+
14640
+ if ( $this->is_network_activation_mode() ) {
14641
+ /**
14642
+ * Do not add during activation mode, otherwise, there will be duplicate menus while the opt-in
14643
+ * screen is being shown.
14644
+ *
14645
+ * @author Leo Fajardo (@leorw)
14646
+ */
14647
+ return;
14648
+ }
14649
+
14650
+ if ( ! WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ) {
14651
+ if ( $this->is_network_delegated_connection() ) {
14652
+ // Super-admin delegated the connection to the site admins.
14653
+ return;
14654
+ }
14655
+ }
14656
+
14657
+ if ( ! $this->_menu->has_menu() || $this->_menu->is_top_level() ) {
14658
+ $this->_dynamically_added_top_level_page_hook_name = $this->_menu->add_page_and_update(
14659
+ $this->get_plugin_name(),
14660
+ $this->get_plugin_name(),
14661
+ 'manage_options',
14662
+ $this->_menu->has_menu() ? $this->_menu->get_slug() : $this->_slug
14663
+ );
14664
+ } else {
14665
+ $this->_menu->add_subpage_and_update(
14666
+ $this->_menu->get_parent_slug(),
14667
+ $this->get_plugin_name(),
14668
+ $this->get_plugin_name(),
14669
+ 'manage_options',
14670
+ $this->_menu->get_slug()
14671
+ );
14672
+ }
14673
+ }
14674
+
14675
+ /**
14676
+ * @author Leo Fajardo (@leorw)
14677
+ * @since 1.2.1
14678
+ *
14679
+ * return string
14680
+ */
14681
+ function get_top_level_menu_capability() {
14682
+ global $menu;
14683
+
14684
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
14685
+
14686
+ foreach ( $menu as $menu_info ) {
14687
+ /**
14688
+ * The second element in the menu info array is the capability/role that has access to the menu and the
14689
+ * third element is the menu slug.
14690
+ */
14691
+ if ( $menu_info[2] === $top_level_menu_slug ) {
14692
+ return $menu_info[1];
14693
+ }
14694
+ }
14695
+
14696
+ return 'read';
14697
+ }
14698
+
14699
+ /**
14700
+ * @author Vova Feldman (@svovaf)
14701
+ * @since 1.0.0
14702
+ *
14703
+ * @return string
14704
+ */
14705
+ private function get_top_level_menu_slug() {
14706
+ return ( $this->is_addon() ?
14707
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
14708
+ $this->_menu->get_top_level_menu_slug() );
14709
+ }
14710
+
14711
+ /**
14712
+ * @author Vova Feldman (@svovaf)
14713
+ * @since 1.2.2.7
14714
+ *
14715
+ * @return string
14716
+ */
14717
+ function get_pricing_cta_label() {
14718
+ $label = $this->get_text_inline( 'Upgrade', 'upgrade' );
14719
+
14720
+ if ( $this->is_in_trial_promotion() &&
14721
+ ! $this->is_paying_or_trial()
14722
+ ) {
14723
+ // If running a trial promotion, modify the pricing to load the trial.
14724
+ $label = $this->get_text_inline( 'Start Trial', 'start-trial' );
14725
+ } else if ( $this->is_paying() ) {
14726
+ $label = $this->get_text_inline( 'Pricing', 'pricing' );
14727
+ }
14728
+
14729
+ return $label;
14730
+ }
14731
+
14732
+ /**
14733
+ * @author Vova Feldman (@svovaf)
14734
+ * @since 1.2.2.7
14735
+ *
14736
+ * @return bool
14737
+ */
14738
+ function is_pricing_page_visible() {
14739
+ return (
14740
+ // Has at least one paid plan.
14741
+ $this->has_paid_plan() &&
14742
+ // Didn't ask to hide the pricing page.
14743
+ $this->is_page_visible( 'pricing' ) &&
14744
+ // Don't have a valid active license or has more than one plan.
14745
+ ( ! $this->is_paying() || ! $this->is_single_plan() )
14746
+ );
14747
+ }
14748
+
14749
+ /**
14750
+ * Add default Freemius menu items.
14751
+ *
14752
+ * @author Vova Feldman (@svovaf)
14753
+ * @since 1.0.0
14754
+ * @since 1.2.2.7 Also add submenu items when running in a free .org theme so the tabs will be visible.
14755
+ */
14756
+ private function add_submenu_items() {
14757
+ $this->_logger->entrance();
14758
+
14759
+ if ( $this->is_addon() ) {
14760
+ // No submenu items for add-ons.
14761
+ $add_submenu_items = false;
14762
+ } else if ( $this->is_free_wp_org_theme() && ! fs_is_network_admin() ) {
14763
+ // Also add submenu items when running in a free .org theme so the tabs will be visible.
14764
+ $add_submenu_items = true;
14765
+ } else if ( $this->is_activation_mode() && ! $this->is_free_wp_org_theme() ) {
14766
+ $add_submenu_items = false;
14767
+ } else if ( fs_is_network_admin() ) {
14768
+ /**
14769
+ * Add submenu items to network level when plugin was network
14770
+ * activated and the super-admin did NOT delegated the connection
14771
+ * of all sites to site admins.
14772
+ */
14773
+ $add_submenu_items = (
14774
+ $this->_is_network_active &&
14775
+ ( WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ||
14776
+ ! $this->is_network_delegated_connection() )
14777
+ );
14778
+ } else {
14779
+ $add_submenu_items = ( ! $this->_is_network_active || $this->is_delegated_connection() );
14780
+ }
14781
+
14782
+ if ( $add_submenu_items ) {
14783
+ if ( $this->has_affiliate_program() ) {
14784
+ // Add affiliation page.
14785
+ $this->add_submenu_item(
14786
+ $this->get_text_inline( 'Affiliation', 'affiliation' ),
14787
+ array( &$this, '_affiliation_page_render' ),
14788
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Affiliation', 'affiliation' ),
14789
+ 'manage_options',
14790
+ 'affiliation',
14791
+ 'Freemius::_clean_admin_content_section',
14792
+ WP_FS__DEFAULT_PRIORITY,
14793
+ $this->is_submenu_item_visible( 'affiliation' )
14794
+ );
14795
+ }
14796
+
14797
+ if ( ! WP_FS__DEMO_MODE && $this->is_registered() ) {
14798
+ $show_account = (
14799
+ $this->is_submenu_item_visible( 'account' ) &&
14800
+ /**
14801
+ * @since 1.2.2.7 Don't show the Account for free WP.org themes without any paid plans.
14802
+ */
14803
+ ( ! $this->is_free_wp_org_theme() || $this->has_paid_plan() )
14804
+ );
14805
+
14806
+ // Add user account page.
14807
+ $this->add_submenu_item(
14808
+ $this->get_text_inline( 'Account', 'account' ),
14809
+ array( &$this, '_account_page_render' ),
14810
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Account', 'account' ),
14811
+ 'manage_options',
14812
+ 'account',
14813
+ array( &$this, '_account_page_load' ),
14814
+ WP_FS__DEFAULT_PRIORITY,
14815
+ $show_account
14816
+ );
14817
+ }
14818
+
14819
+ // Add contact page.
14820
+ $this->add_submenu_item(
14821
+ $this->get_text_inline( 'Contact Us', 'contact-us' ),
14822
+ array( &$this, '_contact_page_render' ),
14823
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Contact Us', 'contact-us' ),
14824
+ 'manage_options',
14825
+ 'contact',
14826
+ 'Freemius::_clean_admin_content_section',
14827
+ WP_FS__DEFAULT_PRIORITY,
14828
+ $this->is_submenu_item_visible( 'contact' )
14829
+ );
14830
+
14831
+ if ( $this->has_addons() ) {
14832
+ $this->add_submenu_item(
14833
+ $this->get_text_inline( 'Add-Ons', 'add-ons' ),
14834
+ array( &$this, '_addons_page_render' ),
14835
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Add-Ons', 'add-ons' ),
14836
+ 'manage_options',
14837
+ 'addons',
14838
+ array( &$this, '_addons_page_load' ),
14839
+ WP_FS__LOWEST_PRIORITY - 1,
14840
+ $this->is_submenu_item_visible( 'addons' )
14841
+ );
14842
+ }
14843
+
14844
+ if ( ! WP_FS__DEMO_MODE ) {
14845
+ $show_pricing = (
14846
+ $this->is_submenu_item_visible( 'pricing' ) &&
14847
+ $this->is_pricing_page_visible()
14848
+ );
14849
+
14850
+ $pricing_cta_text = $this->get_pricing_cta_label();
14851
+ $pricing_class = 'upgrade-mode';
14852
+ if ( $show_pricing ) {
14853
+ if ( $this->is_in_trial_promotion() &&
14854
+ ! $this->is_paying_or_trial()
14855
+ ) {
14856
+ // If running a trial promotion, modify the pricing to load the trial.
14857
+ $pricing_class = 'trial-mode';
14858
+ } else if ( $this->is_paying() ) {
14859
+ $pricing_class = '';
14860
+ }
14861
+ }
14862
+
14863
+ // Add upgrade/pricing page.
14864
+ $this->add_submenu_item(
14865
+ $pricing_cta_text . '&nbsp;&nbsp;' . ( is_rtl() ? '&#x2190;' : '&#x27a4;' ),
14866
+ array( &$this, '_pricing_page_render' ),
14867
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_x_inline( 'Pricing', 'noun', 'pricing' ),
14868
+ 'manage_options',
14869
+ 'pricing',
14870
+ 'Freemius::_clean_admin_content_section',
14871
+ WP_FS__LOWEST_PRIORITY,
14872
+ $show_pricing,
14873
+ $pricing_class
14874
+ );
14875
+ }
14876
+ }
14877
+
14878
+ if ( 0 < count( $this->_menu_items ) ) {
14879
+ if ( ! $this->_menu->is_top_level() ) {
14880
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
14881
+
14882
+ // Append submenu items right after the plugin's submenu item.
14883
+ $this->order_sub_submenu_items();
14884
+ } else {
14885
+ // Append submenu items.
14886
+ $this->embed_submenu_items();
14887
+ }
14888
+ }
14889
+ }
14890
+
14891
+ /**
14892
+ * Moved the actual submenu item additions to a separated function,
14893
+ * in order to support sub-submenu items when the plugin's settings
14894
+ * only have a submenu and not top-level menu item.
14895
+ *
14896
+ * @author Vova Feldman (@svovaf)
14897
+ * @since 1.1.4
14898
+ */
14899
+ private function embed_submenu_items() {
14900
+ $item_template = $this->_menu->is_top_level() ?
14901
+ '<span class="fs-submenu-item %s %s %s">%s</span>' :
14902
+ '<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
14903
+
14904
+ $top_level_menu_capability = $this->get_top_level_menu_capability();
14905
+
14906
+ ksort( $this->_menu_items );
14907
+
14908
+ $is_first_submenu_item = true;
14909
+
14910
+ foreach ( $this->_menu_items as $priority => $items ) {
14911
+ foreach ( $items as $item ) {
14912
+ if ( $item['show_submenu'] && $is_first_submenu_item ) {
14913
+ if ( $this->_is_network_active && ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
14914
+ $item['menu_slug'] = '';
14915
+
14916
+ $this->_menu->override_menu_item( $item['render_function'] );
14917
+ }
14918
+
14919
+ $is_first_submenu_item = false;
14920
+ }
14921
+
14922
+ $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
14923
+
14924
+ $menu_item = sprintf(
14925
+ $item_template,
14926
+ $this->get_unique_affix(),
14927
+ $item['menu_slug'],
14928
+ ! empty( $item['class'] ) ? $item['class'] : '',
14929
+ $item['menu_title']
14930
+ );
14931
+
14932
+ $menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
14933
+
14934
+ if ( ! isset( $item['url'] ) ) {
14935
+ $hook = FS_Admin_Menu_Manager::add_subpage(
14936
+ $item['show_submenu'] ?
14937
+ $this->get_top_level_menu_slug() :
14938
+ null,
14939
+ $item['page_title'],
14940
+ $menu_item,
14941
+ $capability,
14942
+ $menu_slug,
14943
+ $item['render_function']
14944
+ );
14945
+
14946
+ if ( false !== $item['before_render_function'] ) {
14947
+ add_action( "load-$hook", $item['before_render_function'] );
14948
+ }
14949
+ } else {
14950
+ FS_Admin_Menu_Manager::add_subpage(
14951
+ $item['show_submenu'] ?
14952
+ $this->get_top_level_menu_slug() :
14953
+ null,
14954
+ $item['page_title'],
14955
+ $menu_item,
14956
+ $capability,
14957
+ $menu_slug,
14958
+ array( $this, '' )
14959
+ );
14960
+ }
14961
+ }
14962
+ }
14963
+ }
14964
+
14965
+ /**
14966
+ * Re-order the submenu items so all Freemius added new submenu items
14967
+ * are added right after the plugin's settings submenu item.
14968
+ *
14969
+ * @author Vova Feldman (@svovaf)
14970
+ * @since 1.1.4
14971
+ */
14972
+ private function order_sub_submenu_items() {
14973
+ global $submenu;
14974
+
14975
+ $menu_slug = $this->_menu->get_top_level_menu_slug();
14976
+
14977
+ /**
14978
+ * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
14979
+ * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
14980
+ * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
14981
+ * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
14982
+ *
14983
+ * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
14984
+ * of another plugin, only users that have the right role can access its sub-submenus since we will use the
14985
+ * capability needed to access the parent menu as the capability for the submenus that we will add.
14986
+ */
14987
+ if ( empty( $submenu[ $menu_slug ] ) ) {
14988
+ return;
14989
+ }
14990
+
14991
+ $top_level_menu = &$submenu[ $menu_slug ];
14992
+
14993
+ $all_submenu_items_after = array();
14994
+
14995
+ $found_submenu_item = false;
14996
+
14997
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
14998
+ if ( $found_submenu_item ) {
14999
+ // Remove all submenu items after the plugin's submenu item.
15000
+ $all_submenu_items_after[] = $meta;
15001
+ unset( $top_level_menu[ $submenu_id ] );
15002
+ }
15003
+
15004
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
15005
+ // Found the submenu item, put all below.
15006
+ $found_submenu_item = true;
15007
+ continue;
15008
+ }
15009
+ }
15010
+
15011
+ // Embed all plugin's new submenu items.
15012
+ $this->embed_submenu_items();
15013
+
15014
+ // Start with specially high number to make sure it's appended.
15015
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
15016
+ foreach ( $all_submenu_items_after as $meta ) {
15017
+ $top_level_menu[ $i ] = $meta;
15018
+ $i ++;
15019
+ }
15020
+
15021
+ // Sort submenu items.
15022
+ ksort( $top_level_menu );
15023
+ }
15024
+
15025
+ /**
15026
+ * Helper method to return the module's support forum URL.
15027
+ *
15028
+ * @author Vova Feldman (@svovaf)
15029
+ * @since 1.2.2.7
15030
+ *
15031
+ * @return string
15032
+ */
15033
+ function get_support_forum_url() {
15034
+ return $this->apply_filters( 'support_forum_url', "https://wordpress.org/support/{$this->_module_type}/{$this->_slug}" );
15035
+ }
15036
+
15037
+ /**
15038
+ * Displays the Support Forum link when enabled.
15039
+ *
15040
+ * Can be filtered like so:
15041
+ *
15042
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
15043
+ * if ( 'support' === $menu_id ) {
15044
+ * return _fs->is_registered();
15045
+ * }
15046
+ * return $is_visible;
15047
+ * }
15048
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
15049
+ *
15050
+ */
15051
+ function _add_default_submenu_items() {
15052
+ if ( ! $this->is_on() ) {
15053
+ return;
15054
+ }
15055
+
15056
+ if ( ! $this->is_activation_mode() &&
15057
+ ( ( $this->_is_network_active && fs_is_network_admin() ) ||
15058
+ ( ! $this->_is_network_active && is_admin() ) )
15059
+ ) {
15060
+ $this->add_submenu_link_item(
15061
+ $this->apply_filters( 'support_forum_submenu', $this->get_text_inline( 'Support Forum', 'support-forum' ) ),
15062
+ $this->get_support_forum_url(),
15063
+ 'wp-support-forum',
15064
+ null,
15065
+ 50,
15066
+ $this->is_submenu_item_visible( 'support' )
15067
+ );
15068
+ }
15069
+ }
15070
+
15071
+ /**
15072
+ * @author Vova Feldman (@svovaf)
15073
+ * @since 1.0.1
15074
+ *
15075
+ * @param string $menu_title
15076
+ * @param callable $render_function
15077
+ * @param bool|string $page_title
15078
+ * @param string $capability
15079
+ * @param bool|string $menu_slug
15080
+ * @param bool|callable $before_render_function
15081
+ * @param int $priority
15082
+ * @param bool $show_submenu
15083
+ * @param string $class Since 1.2.1.5 can add custom classes to menu items.
15084
+ */
15085
+ function add_submenu_item(
15086
+ $menu_title,
15087
+ $render_function,
15088
+ $page_title = false,
15089
+ $capability = 'manage_options',
15090
+ $menu_slug = false,
15091
+ $before_render_function = false,
15092
+ $priority = WP_FS__DEFAULT_PRIORITY,
15093
+ $show_submenu = true,
15094
+ $class = ''
15095
+ ) {
15096
+ $this->_logger->entrance( 'Title = ' . $menu_title );
15097
+
15098
+ if ( $this->is_addon() ) {
15099
+ $parent_fs = $this->get_parent_instance();
15100
+
15101
+ if ( is_object( $parent_fs ) ) {
15102
+ $parent_fs->add_submenu_item(
15103
+ $menu_title,
15104
+ $render_function,
15105
+ $page_title,
15106
+ $capability,
15107
+ $menu_slug,
15108
+ $before_render_function,
15109
+ $priority,
15110
+ $show_submenu,
15111
+ $class
15112
+ );
15113
+
15114
+ return;
15115
+ }
15116
+ }
15117
+
15118
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
15119
+ $this->_menu_items[ $priority ] = array();
15120
+ }
15121
+
15122
+ $this->_menu_items[ $priority ][] = array(
15123
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
15124
+ 'menu_title' => $menu_title,
15125
+ 'capability' => $capability,
15126
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
15127
+ 'render_function' => $render_function,
15128
+ 'before_render_function' => $before_render_function,
15129
+ 'show_submenu' => $show_submenu,
15130
+ 'class' => $class,
15131
+ );
15132
+ }
15133
+
15134
+ /**
15135
+ * @author Vova Feldman (@svovaf)
15136
+ * @since 1.0.1
15137
+ *
15138
+ * @param string $menu_title
15139
+ * @param string $url
15140
+ * @param bool $menu_slug
15141
+ * @param string $capability
15142
+ * @param int $priority
15143
+ * @param bool $show_submenu
15144
+ */
15145
+ function add_submenu_link_item(
15146
+ $menu_title,
15147
+ $url,
15148
+ $menu_slug = false,
15149
+ $capability = 'read',
15150
+ $priority = WP_FS__DEFAULT_PRIORITY,
15151
+ $show_submenu = true
15152
+ ) {
15153
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
15154
+
15155
+ if ( $this->is_addon() ) {
15156
+ $parent_fs = $this->get_parent_instance();
15157
+
15158
+ if ( is_object( $parent_fs ) ) {
15159
+ $parent_fs->add_submenu_link_item(
15160
+ $menu_title,
15161
+ $url,
15162
+ $menu_slug,
15163
+ $capability,
15164
+ $priority,
15165
+ $show_submenu
15166
+ );
15167
+
15168
+ return;
15169
+ }
15170
+ }
15171
+
15172
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
15173
+ $this->_menu_items[ $priority ] = array();
15174
+ }
15175
+
15176
+ $this->_menu_items[ $priority ][] = array(
15177
+ 'menu_title' => $menu_title,
15178
+ 'capability' => $capability,
15179
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
15180
+ 'url' => $url,
15181
+ 'page_title' => $menu_title,
15182
+ 'render_function' => 'fs_dummy',
15183
+ 'before_render_function' => '',
15184
+ 'show_submenu' => $show_submenu,
15185
+ );
15186
+ }
15187
+
15188
+ #endregion ------------------------------------------------------------------
15189
+
15190
+
15191
+ #--------------------------------------------------------------------------------
15192
+ #region Actions / Hooks / Filters
15193
+ #--------------------------------------------------------------------------------
15194
+
15195
+ /**
15196
+ * @author Vova Feldman (@svovaf)
15197
+ * @since 1.1.7
15198
+ *
15199
+ * @param string $tag
15200
+ *
15201
+ * @return string
15202
+ */
15203
+ public function get_action_tag( $tag ) {
15204
+ return self::get_action_tag_static( $tag, $this->_slug, $this->is_plugin() );
15205
+ }
15206
+
15207
+ /**
15208
+ * @author Vova Feldman (@svovaf)
15209
+ * @since 1.2.1.6
15210
+ *
15211
+ * @param string $tag
15212
+ * @param string $slug
15213
+ * @param bool $is_plugin
15214
+ *
15215
+ * @return string
15216
+ */
15217
+ static function get_action_tag_static( $tag, $slug = '', $is_plugin = true ) {
15218
+ $action = "fs_{$tag}";
15219
+
15220
+ if ( ! empty( $slug ) ) {
15221
+ $action .= '_' . self::get_module_unique_affix( $slug, $is_plugin );
15222
+ }
15223
+
15224
+ return $action;
15225
+ }
15226
+
15227
+ /**
15228
+ * Returns a string that can be used to generate a unique action name,
15229
+ * option name, HTML element ID, or HTML element class.
15230
+ *
15231
+ * @author Leo Fajardo (@leorw)
15232
+ * @since 1.2.2
15233
+ *
15234
+ * @return string
15235
+ */
15236
+ public function get_unique_affix() {
15237
+ return self::get_module_unique_affix( $this->_slug, $this->is_plugin() );
15238
+ }
15239
+
15240
+ /**
15241
+ * Returns a string that can be used to generate a unique action name,
15242
+ * option name, HTML element ID, or HTML element class.
15243
+ *
15244
+ * @author Vova Feldman (@svovaf)
15245
+ * @since 1.2.2.5
15246
+ *
15247
+ * @param string $slug
15248
+ * @param bool $is_plugin
15249
+ *
15250
+ * @return string
15251
+ */
15252
+ static function get_module_unique_affix( $slug, $is_plugin = true ) {
15253
+ $affix = $slug;
15254
+
15255
+ if ( ! $is_plugin ) {
15256
+ $affix .= '-' . WP_FS__MODULE_TYPE_THEME;
15257
+ }
15258
+
15259
+ return $affix;
15260
+ }
15261
+
15262
+ /**
15263
+ * @author Vova Feldman (@svovaf)
15264
+ * @since 1.2.1
15265
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
15266
+ * based on the slug for backward compatibility.
15267
+ *
15268
+ * @param string $tag
15269
+ *
15270
+ * @return string
15271
+ */
15272
+ function get_ajax_action( $tag ) {
15273
+ return self::get_ajax_action_static( $tag, $this->_module_id );
15274
+ }
15275
+
15276
+ /**
15277
+ * @author Vova Feldman (@svovaf)
15278
+ * @since 1.2.1.7
15279
+ *
15280
+ * @param string $tag
15281
+ *
15282
+ * @return string
15283
+ */
15284
+ function get_ajax_security( $tag ) {
15285
+ return wp_create_nonce( $this->get_ajax_action( $tag ) );
15286
+ }
15287
+
15288
+ /**
15289
+ * @author Vova Feldman (@svovaf)
15290
+ * @since 1.2.1.7
15291
+ *
15292
+ * @param string $tag
15293
+ */
15294
+ function check_ajax_referer( $tag ) {
15295
+ check_ajax_referer( $this->get_ajax_action( $tag ), 'security' );
15296
+ }
15297
+
15298
+ /**
15299
+ * @author Vova Feldman (@svovaf)
15300
+ * @since 1.2.1.6
15301
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
15302
+ * based on the slug for backward compatibility.
15303
+ *
15304
+ * @param string $tag
15305
+ * @param number|null $module_id
15306
+ *
15307
+ * @return string
15308
+ */
15309
+ private static function get_ajax_action_static( $tag, $module_id = null ) {
15310
+ $action = "fs_{$tag}";
15311
+
15312
+ if ( ! empty( $module_id ) ) {
15313
+ $action .= "_{$module_id}";
15314
+ }
15315
+
15316
+ return $action;
15317
+ }
15318
+
15319
+ /**
15320
+ * Do action, specific for the current context plugin.
15321
+ *
15322
+ * @author Vova Feldman (@svovaf)
15323
+ * @since 1.0.1
15324
+ *
15325
+ * @param string $tag The name of the action to be executed.
15326
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
15327
+ * functions hooked to the action. Default empty.
15328
+ *
15329
+ * @uses do_action()
15330
+ */
15331
+ function do_action( $tag, $arg = '' ) {
15332
+ $this->_logger->entrance( $tag );
15333
+
15334
+ $args = func_get_args();
15335
+
15336
+ call_user_func_array( 'do_action', array_merge(
15337
+ array( $this->get_action_tag( $tag ) ),
15338
+ array_slice( $args, 1 ) )
15339
+ );
15340
+ }
15341
+
15342
+ /**
15343
+ * Add action, specific for the current context plugin.
15344
+ *
15345
+ * @author Vova Feldman (@svovaf)
15346
+ * @since 1.0.1
15347
+ *
15348
+ * @param string $tag
15349
+ * @param callable $function_to_add
15350
+ * @param int $priority
15351
+ * @param int $accepted_args
15352
+ *
15353
+ * @uses add_action()
15354
+ */
15355
+ function add_action(
15356
+ $tag,
15357
+ $function_to_add,
15358
+ $priority = WP_FS__DEFAULT_PRIORITY,
15359
+ $accepted_args = 1
15360
+ ) {
15361
+ $this->_logger->entrance( $tag );
15362
+
15363
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
15364
+ }
15365
+
15366
+ /**
15367
+ * Add AJAX action, specific for the current context plugin.
15368
+ *
15369
+ * @author Vova Feldman (@svovaf)
15370
+ * @since 1.2.1
15371
+ *
15372
+ * @param string $tag
15373
+ * @param callable $function_to_add
15374
+ * @param int $priority
15375
+ *
15376
+ * @uses add_action()
15377
+ *
15378
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
15379
+ */
15380
+ function add_ajax_action(
15381
+ $tag,
15382
+ $function_to_add,
15383
+ $priority = WP_FS__DEFAULT_PRIORITY
15384
+ ) {
15385
+ $this->_logger->entrance( $tag );
15386
+
15387
+ return self::add_ajax_action_static(
15388
+ $tag,
15389
+ $function_to_add,
15390
+ $priority,
15391
+ $this->_module_id
15392
+ );
15393
+ }
15394
+
15395
+ /**
15396
+ * Add AJAX action.
15397
+ *
15398
+ * @author Vova Feldman (@svovaf)
15399
+ * @since 1.2.1.6
15400
+ *
15401
+ * @param string $tag
15402
+ * @param callable $function_to_add
15403
+ * @param int $priority
15404
+ * @param number|null $module_id
15405
+ *
15406
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
15407
+ * @uses add_action()
15408
+ *
15409
+ */
15410
+ static function add_ajax_action_static(
15411
+ $tag,
15412
+ $function_to_add,
15413
+ $priority = WP_FS__DEFAULT_PRIORITY,
15414
+ $module_id = null
15415
+ ) {
15416
+ self::$_static_logger->entrance( $tag );
15417
+
15418
+ if ( ! self::is_ajax_action_static( $tag, $module_id ) ) {
15419
+ return false;
15420
+ }
15421
+
15422
+ add_action(
15423
+ 'wp_ajax_' . self::get_ajax_action_static( $tag, $module_id ),
15424
+ $function_to_add,
15425
+ $priority,
15426
+ 0
15427
+ );
15428
+
15429
+ self::$_static_logger->info( "$tag AJAX callback action added." );
15430
+
15431
+ return true;
15432
+ }
15433
+
15434
+ /**
15435
+ * Send a JSON response back to an Ajax request.
15436
+ *
15437
+ * @author Vova Feldman (@svovaf)
15438
+ * @since 1.2.1.5
15439
+ *
15440
+ * @param mixed $response
15441
+ */
15442
+ static function shoot_ajax_response( $response ) {
15443
+ wp_send_json( $response );
15444
+ }
15445
+
15446
+ /**
15447
+ * Send a JSON response back to an Ajax request, indicating success.
15448
+ *
15449
+ * @author Vova Feldman (@svovaf)
15450
+ * @since 1.2.1.5
15451
+ *
15452
+ * @param mixed $data Data to encode as JSON, then print and exit.
15453
+ */
15454
+ static function shoot_ajax_success( $data = null ) {
15455
+ wp_send_json_success( $data );
15456
+ }
15457
+
15458
+ /**
15459
+ * Send a JSON response back to an Ajax request, indicating failure.
15460
+ *
15461
+ * @author Vova Feldman (@svovaf)
15462
+ * @since 1.2.1.5
15463
+ *
15464
+ * @param mixed $error Optional error message.
15465
+ */
15466
+ static function shoot_ajax_failure( $error = '' ) {
15467
+ $result = array( 'success' => false );
15468
+ if ( ! empty( $error ) ) {
15469
+ $result['error'] = $error;
15470
+ }
15471
+
15472
+ wp_send_json( $result );
15473
+ }
15474
+
15475
+ /**
15476
+ * Apply filter, specific for the current context plugin.
15477
+ *
15478
+ * @author Vova Feldman (@svovaf)
15479
+ * @since 1.0.9
15480
+ *
15481
+ * @param string $tag The name of the filter hook.
15482
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
15483
+ *
15484
+ * @return mixed The filtered value after all hooked functions are applied to it.
15485
+ *
15486
+ * @uses apply_filters()
15487
+ */
15488
+ function apply_filters( $tag, $value ) {
15489
+ $this->_logger->entrance( $tag );
15490
+
15491
+ $args = func_get_args();
15492
+ array_unshift( $args, $this->get_unique_affix() );
15493
+
15494
+ return call_user_func_array( 'fs_apply_filter', $args );
15495
+ }
15496
+
15497
+ /**
15498
+ * Add filter, specific for the current context plugin.
15499
+ *
15500
+ * @author Vova Feldman (@svovaf)
15501
+ * @since 1.0.9
15502
+ *
15503
+ * @param string $tag
15504
+ * @param callable $function_to_add
15505
+ * @param int $priority
15506
+ * @param int $accepted_args
15507
+ *
15508
+ * @uses add_filter()
15509
+ */
15510
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
15511
+ $this->_logger->entrance( $tag );
15512
+
15513
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
15514
+ }
15515
+
15516
+ /**
15517
+ * Check if has filter.
15518
+ *
15519
+ * @author Vova Feldman (@svovaf)
15520
+ * @since 1.1.4
15521
+ *
15522
+ * @param string $tag
15523
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
15524
+ *
15525
+ * @return false|int
15526
+ *
15527
+ * @uses has_filter()
15528
+ */
15529
+ function has_filter( $tag, $function_to_check = false ) {
15530
+ $this->_logger->entrance( $tag );
15531
+
15532
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
15533
+ }
15534
+
15535
+ #endregion
15536
+
15537
+ /**
15538
+ * Override default i18n text phrases.
15539
+ *
15540
+ * @author Vova Feldman (@svovaf)
15541
+ * @since 1.1.6
15542
+ *
15543
+ * @param string[] string $key_value
15544
+ *
15545
+ * @uses fs_override_i18n()
15546
+ */
15547
+ function override_i18n( $key_value ) {
15548
+ fs_override_i18n( $key_value, $this->_slug );
15549
+ }
15550
+
15551
+ /* Account Page
15552
+ ------------------------------------------------------------------------------------------------------------------*/
15553
+ /**
15554
+ * Update site information.
15555
+ *
15556
+ * @author Vova Feldman (@svovaf)
15557
+ * @since 1.0.1
15558
+ *
15559
+ * @param bool $store Flush to Database if true.
15560
+ * @param null|int $network_level_or_blog_id Since 2.0.0
15561
+ * @param \FS_Site $site Since 2.0.0
15562
+ */
15563
+ private function _store_site( $store = true, $network_level_or_blog_id = null, FS_Site $site = null ) {
15564
+ $this->_logger->entrance();
15565
+
15566
+ if ( empty( $this->_site->id ) ) {
15567
+ $this->_logger->error( "Empty install ID, can't store site." );
15568
+
15569
+ return;
15570
+ }
15571
+
15572
+ $encrypted_site = clone ( is_object( $site ) ? $site : $this->_site );
15573
+
15574
+ $sites = self::get_all_sites( $this->_module_type, $network_level_or_blog_id );
15575
+
15576
+ $prev_stored_user_id = $this->_storage->get( 'prev_user_id', false, $network_level_or_blog_id );
15577
+
15578
+ if ( empty( $prev_stored_user_id ) &&
15579
+ $this->_user->id != $this->_site->user_id
15580
+ ) {
15581
+ /**
15582
+ * Store the current user ID as the previous user ID so that the previous user can be used
15583
+ * as the install's owner while the new owner's details are not yet available.
15584
+ *
15585
+ * This will be executed only in the `replica` site. For example, there are 2 sites, namely `original`
15586
+ * and `replica`, then an ownership change was initiated and completed in the `original`, the `replica`
15587
+ * will be using the previous user until it is updated again (e.g.: until the next clone of `original`
15588
+ * into `replica`.
15589
+ *
15590
+ * @author Leo Fajardo (@leorw)
15591
+ */
15592
+ $this->_storage->store( 'prev_user_id', $sites[ $this->_slug ]->user_id, $network_level_or_blog_id );
15593
+ }
15594
+
15595
+ $sites[ $this->_slug ] = $encrypted_site;
15596
+
15597
+ $this->set_account_option( 'sites', $sites, $store, $network_level_or_blog_id );
15598
+ }
15599
+
15600
+ /**
15601
+ * Update plugin's plans information.
15602
+ *
15603
+ * @author Vova Feldman (@svovaf)
15604
+ * @since 1.0.2
15605
+ *
15606
+ * @param bool $store Flush to Database if true.
15607
+ */
15608
+ private function _store_plans( $store = true ) {
15609
+ $this->_logger->entrance();
15610
+
15611
+ $plans = self::get_all_plans( $this->_module_type );
15612
+
15613
+ // Copy plans.
15614
+ $encrypted_plans = array();
15615
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
15616
+ $encrypted_plans[] = self::_encrypt_entity( $this->_plans[ $i ] );
15617
+ }
15618
+
15619
+ $plans[ $this->_slug ] = $encrypted_plans;
15620
+
15621
+ $this->set_account_option( 'plans', $plans, $store );
15622
+ }
15623
+
15624
+ /**
15625
+ * Update user's plugin licenses.
15626
+ *
15627
+ * @author Vova Feldman (@svovaf)
15628
+ * @since 1.0.5
15629
+ *
15630
+ * @param bool $store
15631
+ * @param number|bool $module_id
15632
+ * @param FS_Plugin_License[] $licenses
15633
+ */
15634
+ private function _store_licenses( $store = true, $module_id = false, $licenses = array() ) {
15635
+ $this->_logger->entrance();
15636
+
15637
+ $all_licenses = self::get_all_licenses();
15638
+
15639
+ if ( ! FS_Plugin::is_valid_id( $module_id ) ) {
15640
+ $module_id = $this->_module_id;
15641
+
15642
+ $user_licenses = is_array( $this->_licenses ) ?
15643
+ $this->_licenses :
15644
+ array();
15645
+
15646
+ if ( empty( $user_licenses ) ) {
15647
+ // If the context user doesn't have any license, don't update the licenses collection.
15648
+ return;
15649
+ }
15650
+
15651
+ $new_user_licenses_map = array();
15652
+ foreach ( $user_licenses as $user_license ) {
15653
+ $new_user_licenses_map[ $user_license->id ] = $user_license;
15654
+ }
15655
+
15656
+ self::store_user_id_license_ids_map( array_keys( $new_user_licenses_map ), $this->_module_id, $this->_user->id );
15657
+
15658
+ // Update user licenses.
15659
+ $licenses_to_update_count = count( $new_user_licenses_map );
15660
+ foreach ( $all_licenses[ $module_id ] as $key => $license ) {
15661
+ if ( 0 === $licenses_to_update_count ) {
15662
+ break;
15663
+ }
15664
+
15665
+ if ( isset( $new_user_licenses_map[ $license->id ] ) ) {
15666
+ // Update license.
15667
+ $all_licenses[ $module_id ][ $key ] = $new_user_licenses_map[ $license->id ];
15668
+ unset( $new_user_licenses_map[ $license->id ] );
15669
+
15670
+ $licenses_to_update_count --;
15671
+ }
15672
+ }
15673
+
15674
+ if ( ! empty( $new_user_licenses_map ) ) {
15675
+ // Add new licenses.
15676
+ $all_licenses[ $module_id ] = array_merge( array_values( $new_user_licenses_map ), $all_licenses[ $module_id ] );
15677
+ }
15678
+
15679
+ $licenses = $all_licenses[ $module_id ];
15680
+ }
15681
+
15682
+ if ( ! isset( $all_licenses[ $module_id ] ) ) {
15683
+ $all_licenses[ $module_id ] = array();
15684
+ }
15685
+
15686
+ $all_licenses[ $module_id ] = $licenses;
15687
+
15688
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
15689
+ }
15690
+
15691
+ /**
15692
+ * Update user information.
15693
+ *
15694
+ * @author Vova Feldman (@svovaf)
15695
+ * @since 1.0.1
15696
+ *
15697
+ * @param bool $store Flush to Database if true.
15698
+ */
15699
+ private function _store_user( $store = true ) {
15700
+ $this->_logger->entrance();
15701
+
15702
+ if ( empty( $this->_user->id ) ) {
15703
+ $this->_logger->error( "Empty user ID, can't store user." );
15704
+
15705
+ return;
15706
+ }
15707
+
15708
+ $users = self::get_all_users();
15709
+ $users[ $this->_user->id ] = $this->_user;
15710
+ self::$_accounts->set_option( 'users', $users, $store );
15711
+ }
15712
+
15713
+ /**
15714
+ * Update new updates information.
15715
+ *
15716
+ * @author Vova Feldman (@svovaf)
15717
+ * @since 1.0.4
15718
+ *
15719
+ * @param FS_Plugin_Tag|null $update
15720
+ * @param bool $store Flush to Database if true.
15721
+ * @param bool|number $plugin_id
15722
+ */
15723
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
15724
+ $this->_logger->entrance();
15725
+
15726
+ if ( $update instanceof FS_Plugin_Tag ) {
15727
+ $update->updated = time();
15728
+ }
15729
+
15730
+ if ( ! is_numeric( $plugin_id ) ) {
15731
+ $plugin_id = $this->_plugin->id;
15732
+ }
15733
+
15734
+ $updates = self::get_all_updates();
15735
+ $updates[ $plugin_id ] = $update;
15736
+ self::$_accounts->set_option( 'updates', $updates, $store );
15737
+ }
15738
+
15739
+ /**
15740
+ * Update new updates information.
15741
+ *
15742
+ * @author Vova Feldman (@svovaf)
15743
+ * @since 1.0.6
15744
+ *
15745
+ * @param FS_Plugin[] $plugin_addons
15746
+ * @param bool $store Flush to Database if true.
15747
+ */
15748
+ private function _store_addons( $plugin_addons, $store = true ) {
15749
+ $this->_logger->entrance();
15750
+
15751
+ $addons = self::get_all_addons();
15752
+ $addons[ $this->_plugin->id ] = $plugin_addons;
15753
+ self::$_accounts->set_option( 'addons', $addons, $store );
15754
+ }
15755
+
15756
+ /**
15757
+ * Delete plugin's associated add-ons.
15758
+ *
15759
+ * @author Vova Feldman (@svovaf)
15760
+ * @since 1.0.8
15761
+ *
15762
+ * @param bool $store
15763
+ *
15764
+ * @return bool
15765
+ */
15766
+ private function _delete_account_addons( $store = true ) {
15767
+ $all_addons = self::get_all_account_addons();
15768
+
15769
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
15770
+ return false;
15771
+ }
15772
+
15773
+ unset( $all_addons[ $this->_plugin->id ] );
15774
+
15775
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
15776
+
15777
+ return true;
15778
+ }
15779
+
15780
+ /**
15781
+ * Update account add-ons list.
15782
+ *
15783
+ * @author Vova Feldman (@svovaf)
15784
+ * @since 1.0.6
15785
+ *
15786
+ * @param FS_Plugin[] $addons
15787
+ * @param bool $store Flush to Database if true.
15788
+ */
15789
+ private function _store_account_addons( $addons, $store = true ) {
15790
+ $this->_logger->entrance();
15791
+
15792
+ $all_addons = self::get_all_account_addons();
15793
+ $all_addons[ $this->_plugin->id ] = $addons;
15794
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
15795
+ }
15796
+
15797
+ /**
15798
+ * Store account params in the Database.
15799
+ *
15800
+ * @author Vova Feldman (@svovaf)
15801
+ * @since 1.0.1
15802
+ *
15803
+ * @param null|int $blog_id Since 2.0.0
15804
+ */
15805
+ private function _store_account( $blog_id = null ) {
15806
+ $this->_logger->entrance();
15807
+
15808
+ $this->_store_site( false, $blog_id );
15809
+ $this->_store_user( false );
15810
+ $this->_store_plans( false );
15811
+ $this->_store_licenses( false );
15812
+
15813
+ self::$_accounts->store( $blog_id );
15814
+ }
15815
+
15816
+ /**
15817
+ * Sync user's information.
15818
+ *
15819
+ * @author Vova Feldman (@svovaf)
15820
+ * @since 1.0.3
15821
+ * @uses FS_Api
15822
+ */
15823
+ private function _handle_account_user_sync() {
15824
+ $this->_logger->entrance();
15825
+
15826
+ $api = $this->get_api_user_scope();
15827
+
15828
+ // Get user's information.
15829
+ $user = $api->get( '/', true );
15830
+
15831
+ if ( isset( $user->id ) ) {
15832
+ $this->_user->first = $user->first;
15833
+ $this->_user->last = $user->last;
15834
+ $this->_user->email = $user->email;
15835
+
15836
+ $is_menu_item_account_visible = $this->is_submenu_item_visible( 'account' );
15837
+
15838
+ if ( $user->is_verified &&
15839
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
15840
+ ) {
15841
+ $this->_user->is_verified = true;
15842
+
15843
+ $this->do_action( 'account_email_verified', $user->email );
15844
+
15845
+ $this->_admin_notices->add(
15846
+ $this->get_text_inline( 'Your email has been successfully verified - you are AWESOME!', 'email-verified-message' ),
15847
+ $this->get_text_x_inline( 'Right on', 'a positive response', 'right-on' ) . '!',
15848
+ 'success',
15849
+ // Make admin sticky if account menu item is invisible,
15850
+ // since the page will be auto redirected to the plugin's
15851
+ // main settings page, and the non-sticky message
15852
+ // will disappear.
15853
+ ! $is_menu_item_account_visible,
15854
+ 'email_verified'
15855
+ );
15856
+ }
15857
+
15858
+ // Flush user details to DB.
15859
+ $this->_store_user();
15860
+
15861
+ $this->do_action( 'after_account_user_sync', $user );
15862
+
15863
+ /**
15864
+ * If account menu item is hidden, redirect to plugin's main settings page.
15865
+ *
15866
+ * @author Vova Feldman (@svovaf)
15867
+ * @since 1.1.6
15868
+ *
15869
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
15870
+ */
15871
+ if ( ! $is_menu_item_account_visible ) {
15872
+ fs_redirect( $this->_get_admin_page_url() );
15873
+ }
15874
+ }
15875
+ }
15876
+
15877
+ /**
15878
+ * @author Vova Feldman (@svovaf)
15879
+ * @since 1.0.9
15880
+ * @uses FS_Api
15881
+ *
15882
+ * @param number|bool $license_id
15883
+ *
15884
+ * @return FS_Subscription|object|bool
15885
+ */
15886
+ private function _fetch_site_license_subscription( $license_id = false ) {
15887
+ $this->_logger->entrance();
15888
+ $api = $this->get_api_site_scope();
15889
+
15890
+ if ( ! is_numeric( $license_id ) ) {
15891
+ $license_id = $this->_license->id;
15892
+ }
15893
+
15894
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
15895
+
15896
+ return ! isset( $result->error ) ?
15897
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
15898
+ new FS_Subscription( $result->subscriptions[0] ) :
15899
+ false
15900
+ ) :
15901
+ $result;
15902
+ }
15903
+
15904
+ /**
15905
+ * @author Vova Feldman (@svovaf)
15906
+ * @since 1.0.4
15907
+ * @uses FS_Api
15908
+ *
15909
+ * @param number|bool $plan_id
15910
+ *
15911
+ * @return FS_Plugin_Plan|object
15912
+ */
15913
+ private function _fetch_site_plan( $plan_id = false ) {
15914
+ $this->_logger->entrance();
15915
+ $api = $this->get_api_site_scope();
15916
+
15917
+ if ( ! is_numeric( $plan_id ) ) {
15918
+ $plan_id = $this->_site->plan_id;
15919
+ }
15920
+
15921
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
15922
+
15923
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
15924
+ }
15925
+
15926
+ /**
15927
+ * @author Vova Feldman (@svovaf)
15928
+ * @since 1.0.5
15929
+ * @uses FS_Api
15930
+ *
15931
+ * @return FS_Plugin_Plan[]|object
15932
+ */
15933
+ private function _fetch_plugin_plans() {
15934
+ $this->_logger->entrance();
15935
+ $api = $this->get_current_or_network_user_api_scope();
15936
+
15937
+ /**
15938
+ * @since 1.2.3 When running in DEV mode, retrieve pending plans as well.
15939
+ */
15940
+ $result = $api->get( "/plugins/{$this->_module_id}/plans.json?show_pending=" . ( $this->has_secret_key() ? 'true' : 'false' ), true );
15941
+
15942
+ if ( $this->is_api_result_object( $result, 'plans' ) && is_array( $result->plans ) ) {
15943
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
15944
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
15945
+ }
15946
+
15947
+ $result = $result->plans;
15948
+ }
15949
+
15950
+ return $result;
15951
+ }
15952
+
15953
+ /**
15954
+ * @author Vova Feldman (@svovaf)
15955
+ * @since 2.0.0
15956
+ *
15957
+ * @param number $plan_id
15958
+ *
15959
+ * @return \FS_Plugin_Plan|object
15960
+ */
15961
+ private function fetch_plan_by_id( $plan_id ) {
15962
+ $this->_logger->entrance();
15963
+ $api = $this->get_current_or_network_user_api_scope();
15964
+
15965
+ $result = $api->get( "/plugins/{$this->_module_id}/plans/{$plan_id}.json", true );
15966
+
15967
+ return $this->is_api_result_entity( $result ) ?
15968
+ new FS_Plugin_Plan( $result ) :
15969
+ $result;
15970
+ }
15971
+
15972
+ /**
15973
+ * @author Vova Feldman (@svovaf)
15974
+ * @since 1.0.5
15975
+ * @uses FS_Api
15976
+ *
15977
+ * @param number|bool $plugin_id
15978
+ * @param number|bool $site_license_id
15979
+ * @param array $foreign_licenses @since 2.0.0. This is used by network-activated plugins.
15980
+ * @param number|null $blog_id
15981
+ *
15982
+ * @return FS_Plugin_License[]|object
15983
+ */
15984
+ private function _fetch_licenses(
15985
+ $plugin_id = false,
15986
+ $site_license_id = false,
15987
+ $foreign_licenses = array(),
15988
+ $blog_id = null
15989
+ ) {
15990
+ $this->_logger->entrance();
15991
+
15992
+ $api = $this->get_api_user_scope();
15993
+
15994
+ if ( ! is_numeric( $plugin_id ) ) {
15995
+ $plugin_id = $this->_plugin->id;
15996
+ }
15997
+
15998
+ $user_licenses_endpoint = "/plugins/{$plugin_id}/licenses.json";
15999
+ if ( ! empty ( $foreign_licenses ) ) {
16000
+ $foreign_licenses = array(
16001
+ // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
16002
+ 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
16003
+ 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
16004
+ );
16005
+
16006
+ $user_licenses_endpoint = add_query_arg( $foreign_licenses, $user_licenses_endpoint );
16007
+ }
16008
+
16009
+ $result = $api->get( $user_licenses_endpoint, true );
16010
+
16011
+ $is_site_license_synced = false;
16012
+
16013
+ $api_errors = array();
16014
+
16015
+ if ( $this->is_api_result_object( $result, 'licenses' ) &&
16016
+ is_array( $result->licenses )
16017
+ ) {
16018
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
16019
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
16020
+
16021
+ if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
16022
+ $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
16023
+ }
16024
+ }
16025
+
16026
+ $result = $result->licenses;
16027
+ } else {
16028
+ $api_errors[] = $result;
16029
+ $result = array();
16030
+ }
16031
+
16032
+ if ( ! $is_site_license_synced ) {
16033
+ if ( ! is_null( $blog_id ) ) {
16034
+ /**
16035
+ * If blog ID is not null, the request is for syncing of the license of a single site via the
16036
+ * network-level "Account" page.
16037
+ *
16038
+ * @author Leo Fajardo (@leorw)
16039
+ */
16040
+ $this->switch_to_blog( $blog_id );
16041
+ }
16042
+
16043
+ $api = $this->get_api_site_scope();
16044
+
16045
+ if ( is_numeric( $site_license_id ) ) {
16046
+ // Try to retrieve a foreign license that is linked to the install.
16047
+ $api_result = $api->call( '/licenses.json' );
16048
+
16049
+ if ( $this->is_api_result_object( $api_result, 'licenses' ) &&
16050
+ is_array( $api_result->licenses )
16051
+ ) {
16052
+ $licenses = $api_result->licenses;
16053
+
16054
+ if ( ! empty( $licenses ) ) {
16055
+ $result[] = new FS_Plugin_License( $licenses[0] );
16056
+ }
16057
+ } else {
16058
+ $api_errors[] = $api_result;
16059
+ }
16060
+ } else if ( is_object( $this->_license ) ) {
16061
+ $is_license_in_result = false;
16062
+ if ( ! empty( $result ) ) {
16063
+ foreach ( $result as $license ) {
16064
+ if ( $license->id == $this->_license->id ) {
16065
+ $is_license_in_result = true;
16066
+ break;
16067
+ }
16068
+ }
16069
+ }
16070
+
16071
+ if ( ! $is_license_in_result ) {
16072
+ // Fetch foreign license by ID and license key.
16073
+ $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
16074
+ urlencode( $this->_license->secret_key ) );
16075
+
16076
+ if ( $this->is_api_result_entity( $license ) ) {
16077
+ $result[] = new FS_Plugin_License( $license );
16078
+ } else {
16079
+ $api_errors[] = $license;
16080
+ }
16081
+ }
16082
+ }
16083
+
16084
+ if ( ! is_null( $blog_id ) ) {
16085
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
16086
+ }
16087
+ }
16088
+
16089
+ if ( is_array( $result ) && 0 < count( $result ) ) {
16090
+ // If found at least one license, return license collection even if there are errors.
16091
+ return $result;
16092
+ }
16093
+
16094
+ if ( ! empty( $api_errors ) ) {
16095
+ // If found any errors and no licenses, return first error.
16096
+ return $api_errors[0];
16097
+ }
16098
+
16099
+ // Fallback to empty licenses list.
16100
+ return $result;
16101
+ }
16102
+
16103
+ /**
16104
+ * @author Vova Feldman (@svovaf)
16105
+ * @since 2.0.0
16106
+ *
16107
+ * @param number $license_id
16108
+ * @param string $license_key
16109
+ *
16110
+ * @return \FS_Plugin_License|object
16111
+ */
16112
+ private function fetch_license_by_key( $license_id, $license_key ) {
16113
+ $this->_logger->entrance();
16114
+
16115
+ $api = $this->get_current_or_network_user_api_scope();
16116
+
16117
+ $result = $api->get( "/licenses/{$license_id}.json?license_key=" . urlencode( $license_key ) );
16118
+
16119
+ return $this->is_api_result_entity( $result ) ?
16120
+ new FS_Plugin_License( $result ) :
16121
+ $result;
16122
+ }
16123
+
16124
+ /**
16125
+ * @author Vova Feldman (@svovaf)
16126
+ * @since 1.2.0
16127
+ * @uses FS_Api
16128
+ *
16129
+ * @param number|bool $plugin_id
16130
+ * @param bool $flush
16131
+ *
16132
+ * @return FS_Payment[]|object
16133
+ */
16134
+ function _fetch_payments( $plugin_id = false, $flush = false ) {
16135
+ $this->_logger->entrance();
16136
+
16137
+ $api = $this->get_api_user_scope();
16138
+
16139
+ if ( ! is_numeric( $plugin_id ) ) {
16140
+ $plugin_id = $this->_plugin->id;
16141
+ }
16142
+
16143
+ $result = $api->get( "/plugins/{$plugin_id}/payments.json?include_addons=true", $flush );
16144
+
16145
+ if ( ! isset( $result->error ) ) {
16146
+ for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
16147
+ $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
16148
+ }
16149
+ $result = $result->payments;
16150
+ }
16151
+
16152
+ return $result;
16153
+ }
16154
+
16155
+ /**
16156
+ * @author Vova Feldman (@svovaf)
16157
+ * @since 1.2.1.5
16158
+ * @uses FS_Api
16159
+ *
16160
+ * @param bool $flush
16161
+ *
16162
+ * @return \FS_Billing|mixed
16163
+ */
16164
+ function _fetch_billing( $flush = false ) {
16165
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-billing.php';
16166
+
16167
+ $billing = $this->get_api_user_scope()->get( 'billing.json', $flush );
16168
+
16169
+ if ( $this->is_api_result_entity( $billing ) ) {
16170
+ $billing = new FS_Billing( $billing );
16171
+ }
16172
+
16173
+ return $billing;
16174
+ }
16175
+
16176
+ /**
16177
+ * @author Vova Feldman (@svovaf)
16178
+ * @since 1.0.5
16179
+ *
16180
+ * @param FS_Plugin_License[] $licenses
16181
+ * @param number $module_id
16182
+ */
16183
+ private function _update_licenses( $licenses, $module_id ) {
16184
+ $this->_logger->entrance();
16185
+
16186
+ if ( is_array( $licenses ) ) {
16187
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
16188
+ $licenses[ $i ]->updated = time();
16189
+ }
16190
+ }
16191
+
16192
+ $this->_store_licenses( true, $module_id, $licenses );
16193
+ }
16194
+
16195
+ /**
16196
+ * @author Vova Feldman (@svovaf)
16197
+ * @since 1.0.4
16198
+ *
16199
+ * @param bool|number $plugin_id
16200
+ * @param bool $flush Since 1.1.7.3
16201
+ * @param int $expiration Since 1.2.2.7
16202
+ *
16203
+ * @return object|false New plugin tag info if exist.
16204
+ */
16205
+ private function _fetch_newer_version( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
16206
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush, $expiration );
16207
+
16208
+ if ( ! is_object( $latest_tag ) ) {
16209
+ return false;
16210
+ }
16211
+
16212
+ // Check if version is actually newer.
16213
+ $has_new_version =
16214
+ // If it's an non-installed add-on then always return latest.
16215
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
16216
+ // Compare versions.
16217
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
16218
+
16219
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
16220
+
16221
+ return $has_new_version ? $latest_tag : false;
16222
+ }
16223
+
16224
+ /**
16225
+ * @author Vova Feldman (@svovaf)
16226
+ * @since 1.0.5
16227
+ *
16228
+ * @param bool|number $plugin_id
16229
+ * @param bool $flush Since 1.1.7.3
16230
+ * @param int $expiration Since 1.2.2.7
16231
+ *
16232
+ * @return bool|FS_Plugin_Tag
16233
+ */
16234
+ function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
16235
+ $this->_logger->entrance();
16236
+
16237
+ if ( ! is_numeric( $plugin_id ) ) {
16238
+ $plugin_id = $this->_plugin->id;
16239
+ }
16240
+
16241
+ $this->check_updates( true, $plugin_id, $flush, $expiration );
16242
+ $updates = $this->get_all_updates();
16243
+
16244
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
16245
+ }
16246
+
16247
+ /**
16248
+ * Check if site assigned with active license.
16249
+ *
16250
+ * @author Vova Feldman (@svovaf)
16251
+ * @since 1.0.6
16252
+ *
16253
+ * @deprecated Please use has_active_valid_license() instead because license can be cancelled.
16254
+ */
16255
+ function has_active_license() {
16256
+ return (
16257
+ is_object( $this->_license ) &&
16258
+ is_numeric( $this->_license->id ) &&
16259
+ ! $this->_license->is_expired()
16260
+ );
16261
+ }
16262
+
16263
+ /**
16264
+ * Check if site assigned with active & valid (not expired) license.
16265
+ *
16266
+ * @author Vova Feldman (@svovaf)
16267
+ * @since 1.2.1
16268
+ */
16269
+ function has_active_valid_license() {
16270
+ return (
16271
+ is_object( $this->_license ) &&
16272
+ is_numeric( $this->_license->id ) &&
16273
+ $this->_license->is_active() &&
16274
+ $this->_license->is_valid()
16275
+ );
16276
+ }
16277
+
16278
+ /**
16279
+ * Check if site assigned with license with enabled features.
16280
+ *
16281
+ * @author Vova Feldman (@svovaf)
16282
+ * @since 1.0.6
16283
+ *
16284
+ * @return bool
16285
+ */
16286
+ function has_features_enabled_license() {
16287
+ return (
16288
+ is_object( $this->_license ) &&
16289
+ is_numeric( $this->_license->id ) &&
16290
+ $this->_license->is_features_enabled()
16291
+ );
16292
+ }
16293
+
16294
+ /**
16295
+ * Check if user is a trial or have feature enabled license.
16296
+ *
16297
+ * @author Vova Feldman (@svovaf)
16298
+ * @since 1.1.7
16299
+ *
16300
+ * @return bool
16301
+ */
16302
+ function can_use_premium_code() {
16303
+ return $this->is_trial() || $this->has_features_enabled_license();
16304
+ }
16305
+
16306
+ /**
16307
+ * Checks if the current user can activate plugins or switch themes. Note that this method should only be used
16308
+ * after the `init` action is triggered because it is using `current_user_can()` which is only functional after
16309
+ * the context user is authenticated.
16310
+ *
16311
+ * @author Leo Fajardo (@leorw)
16312
+ * @since 1.2.2
16313
+ *
16314
+ * @return bool
16315
+ */
16316
+ function is_user_admin() {
16317
+ /**
16318
+ * Require a super-admin when network activated, running from the network level OR if
16319
+ * running from the site level but not delegated the opt-in.
16320
+ *
16321
+ * @author Vova Feldman (@svovaf)
16322
+ * @since 2.0.0
16323
+ */
16324
+ if ( $this->_is_network_active &&
16325
+ ( fs_is_network_admin() || ! $this->is_delegated_connection() )
16326
+ ) {
16327
+ return is_super_admin();
16328
+ }
16329
+
16330
+ return ( $this->is_plugin() && current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) )
16331
+ || ( $this->is_theme() && current_user_can( 'switch_themes' ) );
16332
+ }
16333
+
16334
+ /**
16335
+ * Sync site's plan.
16336
+ *
16337
+ * @author Vova Feldman (@svovaf)
16338
+ * @since 1.0.3
16339
+ *
16340
+ * @uses FS_Api
16341
+ *
16342
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
16343
+ * the admin.
16344
+ * @param bool $is_context_single_site @since 2.0.0. This is used when syncing a license for a single install from the
16345
+ * network-level "Account" page.
16346
+ */
16347
+ private function _sync_license( $background = false, $is_context_single_site = false ) {
16348
+ $this->_logger->entrance();
16349
+
16350
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
16351
+
16352
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
16353
+
16354
+ if ( $is_addon_sync ) {
16355
+ $this->_sync_addon_license( $plugin_id, $background );
16356
+ } else {
16357
+ $this->_sync_plugin_license( $background, true, $is_context_single_site );
16358
+ }
16359
+
16360
+ $this->do_action( 'after_account_plan_sync', $this->get_plan_name() );
16361
+ }
16362
+
16363
+ /**
16364
+ * Sync plugin's add-on license.
16365
+ *
16366
+ * @author Vova Feldman (@svovaf)
16367
+ * @since 1.0.6
16368
+ * @uses FS_Api
16369
+ *
16370
+ * @param number $addon_id
16371
+ * @param bool $background
16372
+ */
16373
+ private function _sync_addon_license( $addon_id, $background ) {
16374
+ $this->_logger->entrance();
16375
+
16376
+ if ( $this->is_addon_activated( $addon_id ) ) {
16377
+ // If already installed, use add-on sync.
16378
+ $fs_addon = self::get_instance_by_id( $addon_id );
16379
+ $fs_addon->_sync_license( $background );
16380
+
16381
+ return;
16382
+ }
16383
+
16384
+ // Validate add-on exists.
16385
+ $addon = $this->get_addon( $addon_id );
16386
+
16387
+ if ( ! is_object( $addon ) ) {
16388
+ return;
16389
+ }
16390
+
16391
+ // Add add-on into account add-ons.
16392
+ $account_addons = $this->get_account_addons();
16393
+ if ( ! is_array( $account_addons ) ) {
16394
+ $account_addons = array();
16395
+ }
16396
+ $account_addons[] = $addon->id;
16397
+ $account_addons = array_unique( $account_addons );
16398
+ $this->_store_account_addons( $account_addons );
16399
+
16400
+ // Load add-on licenses.
16401
+ $licenses = $this->_fetch_licenses( $addon->id );
16402
+
16403
+ // Sync add-on licenses.
16404
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
16405
+ $this->_update_licenses( $licenses, $addon->id );
16406
+
16407
+ if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
16408
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
16409
+
16410
+ if ( ! isset( $plans_result->error ) ) {
16411
+ $plans = array();
16412
+ foreach ( $plans_result->plans as $plan ) {
16413
+ $plans[] = new FS_Plugin_Plan( $plan );
16414
+ }
16415
+
16416
+ $this->_admin_notices->add_sticky(
16417
+ sprintf(
16418
+ ( FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
16419
+ $this->get_text_inline( 'Your %s Add-on plan was successfully upgraded.', 'addon-successfully-upgraded-message' ) :
16420
+ /* translators: %s:product name, e.g. Facebook add-on was successfully... */
16421
+ $this->get_text_inline( '%s Add-on was successfully purchased.', 'addon-successfully-purchased-message' ) ),
16422
+ $addon->title
16423
+ ) . ' ' . $this->get_latest_download_link(
16424
+ $this->get_text_inline( 'Download the latest version', 'download-latest-version' ),
16425
+ $addon_id
16426
+ ),
16427
+ 'addon_plan_upgraded_' . $addon->slug,
16428
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
16429
+ );
16430
+ }
16431
+ }
16432
+ }
16433
+ }
16434
+
16435
+ /**
16436
+ * Sync site's plugin plan.
16437
+ *
16438
+ * @author Vova Feldman (@svovaf)
16439
+ * @since 1.0.6
16440
+ * @uses FS_Api
16441
+ *
16442
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by the admin.
16443
+ * @param bool $send_installs_update Since 2.0.0
16444
+ * @param bool $is_context_single_site Since 2.0.0. This is used when sending an update for a single install and
16445
+ * syncing its license from the network-level "Account" page (e.g.: after
16446
+ * activating a license only for the single install).
16447
+ */
16448
+ private function _sync_plugin_license(
16449
+ $background = false,
16450
+ $send_installs_update = true,
16451
+ $is_context_single_site = false
16452
+ ) {
16453
+ $this->_logger->entrance();
16454
+
16455
+ $plan_change = 'none';
16456
+
16457
+ $is_site_level_sync = ( $is_context_single_site || fs_is_blog_admin() || ! $this->_is_network_active );
16458
+
16459
+ if ( ! $send_installs_update ) {
16460
+ $site = $this->_site;
16461
+ } else {
16462
+ /**
16463
+ * Sync site info.
16464
+ *
16465
+ * @todo This line will execute install sync on a daily basis, even if running the free version (for opted-in users). The reason we want to keep it that way is for cases when the user was a paying customer, then there was a failure in subscription payment, and then after some time the payment was successful. This could be heavily optimized. For example, we can skip the $flush if the current install was never associated with a paid version.
16466
+ */
16467
+ if ( $is_site_level_sync ) {
16468
+ $result = $this->send_install_update( array(), true );
16469
+ $is_valid = $this->is_api_result_entity( $result );
16470
+ } else {
16471
+ $result = $this->send_installs_update( array(), true );
16472
+ $is_valid = $this->is_api_result_object( $result, 'installs' );
16473
+ }
16474
+
16475
+ if ( ! $is_valid ) {
16476
+ if ( $is_context_single_site ) {
16477
+ // Switch back to the main blog so that the following logic will have the right entities.
16478
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
16479
+ }
16480
+
16481
+ // Show API messages only if not background sync or if paying customer.
16482
+ if ( ! $background || $this->is_paying() ) {
16483
+ // Try to ping API to see if not blocked.
16484
+ if ( ! FS_Api::test() ) {
16485
+ /**
16486
+ * Failed to ping API - blocked!
16487
+ *
16488
+ * @author Vova Feldman (@svovaf)
16489
+ * @since 1.1.6 Only show message related to one of the Freemius powered plugins. Once it will be resolved it will fix the issue for all plugins anyways. There's no point to scare users with multiple error messages.
16490
+ */
16491
+ $api = $this->get_api_site_scope();
16492
+
16493
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
16494
+ self::$_global_admin_notices->add(
16495
+ sprintf(
16496
+ $this->get_text_x_inline( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s', '%1s - plugin title, %2s - API domain', 'server-blocking-access' ),
16497
+ $this->get_plugin_name(),
16498
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
16499
+ ) . '<br> ' . $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . var_export( $result->error, true ),
16500
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
16501
+ 'error',
16502
+ $background,
16503
+ 'api_blocked'
16504
+ );
16505
+ }
16506
+ } else {
16507
+ // Authentication params are broken.
16508
+ $this->_admin_notices->add(
16509
+ $this->get_text_inline( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'wrong-authentication-param-message' ),
16510
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
16511
+ 'error'
16512
+ );
16513
+ }
16514
+ }
16515
+
16516
+ // No reason to continue with license sync while there are API issues.
16517
+ return;
16518
+ }
16519
+
16520
+ if ( $is_site_level_sync ) {
16521
+ $site = new FS_Site( $result );
16522
+ } else {
16523
+ // Map site addresses to their blog IDs.
16524
+ $address_to_blog_map = $this->get_address_to_blog_map();
16525
+
16526
+ // Find the current context install.
16527
+ $site = null;
16528
+ foreach ( $result->installs as $install ) {
16529
+ if ( $install->id == $this->_site->id ) {
16530
+ $site = new FS_Site( $install );
16531
+ } else {
16532
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
16533
+ $blog_id = $address_to_blog_map[ $address ];
16534
+
16535
+ $this->_store_site( true, $blog_id, new FS_Site( $install ) );
16536
+ }
16537
+ }
16538
+ }
16539
+
16540
+ // Sync plans.
16541
+ $this->_sync_plans();
16542
+ }
16543
+
16544
+ // Remove sticky API connectivity message.
16545
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
16546
+
16547
+ if ( ! $this->has_paid_plan() ) {
16548
+ $this->_site = $site;
16549
+ $this->_store_site(
16550
+ true,
16551
+ $is_site_level_sync ?
16552
+ null :
16553
+ $this->get_network_install_blog_id()
16554
+ );
16555
+ } else {
16556
+ $context_blog_id = 0;
16557
+
16558
+ if ( $is_context_single_site ) {
16559
+ $context_blog_id = get_current_blog_id();
16560
+
16561
+ // Switch back to the main blog in order to properly sync the license.
16562
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
16563
+ }
16564
+
16565
+ /**
16566
+ * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
16567
+ * associated with that ID is not included in the user's licenses collection.
16568
+ */
16569
+ $this->_sync_licenses(
16570
+ $site->license_id,
16571
+ ( $is_context_single_site ?
16572
+ $context_blog_id :
16573
+ null
16574
+ )
16575
+ );
16576
+
16577
+ if ( $is_context_single_site ) {
16578
+ $this->switch_to_blog( $context_blog_id );
16579
+ }
16580
+
16581
+ // Check if plan / license changed.
16582
+ if ( $site->plan_id != $this->_site->plan_id ||
16583
+ // Check if trial started.
16584
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
16585
+ $site->trial_ends != $this->_site->trial_ends ||
16586
+ // Check if license changed.
16587
+ $site->license_id != $this->_site->license_id
16588
+ ) {
16589
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
16590
+ // New trial started.
16591
+ $this->_site = $site;
16592
+ $plan_change = 'trial_started';
16593
+
16594
+ // For trial with subscription use-case.
16595
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
16596
+
16597
+ if ( is_object( $new_license ) && $new_license->is_valid() ) {
16598
+ $this->_site = $site;
16599
+ $this->_update_site_license( $new_license );
16600
+ $this->_store_licenses();
16601
+
16602
+ $this->_sync_site_subscription( $this->_license );
16603
+ }
16604
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
16605
+ // Was in trial, but now trial expired and no license ID.
16606
+ // New trial started.
16607
+ $this->_site = $site;
16608
+ $plan_change = 'trial_expired';
16609
+ } else {
16610
+ $is_free = $this->is_free_plan();
16611
+
16612
+ // Make sure license exist and not expired.
16613
+ $new_license = is_null( $site->license_id ) ?
16614
+ null :
16615
+ $this->_get_license_by_id( $site->license_id );
16616
+
16617
+ if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
16618
+ // License cancelled.
16619
+ $this->_site = $site;
16620
+ $this->_update_site_license( $new_license );
16621
+ $this->_store_licenses();
16622
+
16623
+ $plan_change = 'cancelled';
16624
+ } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
16625
+ // The license is expired, so ignore upgrade method.
16626
+ $this->_site = $site;
16627
+ } else {
16628
+ // License changed.
16629
+ $this->_site = $site;
16630
+
16631
+ /**
16632
+ * IMPORTANT:
16633
+ * The line below should be executed before trying to activate the license on the rest of the network, otherwise, the license' activation counters may be out of sync + there's no need to activate the license on the context site since it's already activated on it.
16634
+ *
16635
+ * @author Vova Feldman (@svovaf)
16636
+ * @since 2.0.0
16637
+ */
16638
+ $this->_update_site_license( $new_license );
16639
+
16640
+ if ( ! $is_context_single_site &&
16641
+ fs_is_network_admin() &&
16642
+ $this->_is_network_active &&
16643
+ $new_license->quota > 1 &&
16644
+ get_blog_count() > 1
16645
+ ) {
16646
+ // See if license can activated on all sites.
16647
+ if ( ! $this->try_activate_license_on_network( $this->_user, $new_license ) ) {
16648
+ if ( ! fs_request_get_bool( 'auto_install' ) ) {
16649
+ // Open the license activation dialog box on the account page.
16650
+ add_action( 'admin_footer', array(
16651
+ &$this,
16652
+ '_open_license_activation_dialog_box'
16653
+ ) );
16654
+ }
16655
+ }
16656
+ }
16657
+
16658
+ $this->_store_licenses();
16659
+
16660
+ $plan_change = $is_free ?
16661
+ 'upgraded' :
16662
+ ( is_object( $new_license ) ?
16663
+ 'changed' :
16664
+ 'downgraded' );
16665
+ }
16666
+ }
16667
+
16668
+ // Store updated site info.
16669
+ $this->_store_site(
16670
+ true,
16671
+ $is_site_level_sync ?
16672
+ null :
16673
+ $this->get_network_install_blog_id()
16674
+ );
16675
+ } else {
16676
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
16677
+ if ( ! $this->has_features_enabled_license() ) {
16678
+ $this->_deactivate_license();
16679
+ $plan_change = 'downgraded';
16680
+ } else {
16681
+ $plan_change = 'expired';
16682
+ }
16683
+ }
16684
+
16685
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
16686
+ $this->_sync_site_subscription( $this->_license );
16687
+ }
16688
+ }
16689
+ }
16690
+
16691
+ $hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
16692
+
16693
+ if ( $this->has_paid_plan() ) {
16694
+ switch ( $plan_change ) {
16695
+ case 'none':
16696
+ if ( ! $background && is_admin() ) {
16697
+ $plan = $this->is_trial() ?
16698
+ $this->get_trial_plan() :
16699
+ $this->get_plan();
16700
+
16701
+ if ( $plan->is_free() ) {
16702
+ $this->_admin_notices->add(
16703
+ sprintf(
16704
+ $this->get_text_inline( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.', 'plan-did-not-change-message' ),
16705
+ '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . $this->get_text_x_inline( 'Trial', 'trial period', 'trial' ) : '' ) . '</b></i>'
16706
+ ) . ' ' . sprintf(
16707
+ '<a href="%s">%s</a>',
16708
+ $this->contact_url(
16709
+ 'bug',
16710
+ sprintf( $this->get_text_inline( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'plan-did-not-change-email-message' ),
16711
+ strtoupper( $plan->name )
16712
+ )
16713
+ ),
16714
+ $this->get_text_inline( 'Please contact us here', 'contact-us-here' )
16715
+ ),
16716
+ $hmm_text
16717
+ );
16718
+ }
16719
+ }
16720
+ break;
16721
+ case 'upgraded':
16722
+ $this->_admin_notices->add_sticky(
16723
+ sprintf(
16724
+ $this->get_text_inline( 'Your plan was successfully upgraded.', 'plan-upgraded-message' ),
16725
+ '<i>' . $this->get_plugin_name() . '</i>'
16726
+ ) . $this->get_complete_upgrade_instructions(),
16727
+ 'plan_upgraded',
16728
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
16729
+ );
16730
+
16731
+ $this->_admin_notices->remove_sticky( array(
16732
+ 'trial_started',
16733
+ 'trial_promotion',
16734
+ 'trial_expired',
16735
+ 'activation_complete',
16736
+ ) );
16737
+ break;
16738
+ case 'changed':
16739
+ $this->_admin_notices->add_sticky(
16740
+ sprintf(
16741
+ $this->get_text_inline( 'Your plan was successfully changed to %s.', 'plan-changed-to-x-message' ),
16742
+ $this->get_plan_title()
16743
+ ),
16744
+ 'plan_changed'
16745
+ );
16746
+
16747
+ $this->_admin_notices->remove_sticky( array(
16748
+ 'trial_started',
16749
+ 'trial_promotion',
16750
+ 'trial_expired',
16751
+ 'activation_complete',
16752
+ ) );
16753
+ break;
16754
+ case 'downgraded':
16755
+ $this->_admin_notices->add_sticky(
16756
+ ($this->has_free_plan() ?
16757
+ sprintf( $this->get_text_inline( 'Your license has expired. You can still continue using the free %s forever.', 'license-expired-blocking-message' ), $this->_module_type ) :
16758
+ /* translators: %1$s: product title; %2$s, %3$s: wrapping HTML anchor element; %4$s: 'plugin', 'theme', or 'add-on'. */
16759
+ sprintf( $this->get_text_inline( 'Your license has expired. %1$sUpgrade now%2$s to continue using the %3$s without interruptions.', 'license-expired-blocking-message_premium-only' ), sprintf('<a href="%s">', $this->pricing_url()), '</a>', $this->get_module_label(true) ) ),
16760
+ 'license_expired',
16761
+ $hmm_text
16762
+ );
16763
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
16764
+ break;
16765
+ case 'cancelled':
16766
+ $this->_admin_notices->add(
16767
+ $this->get_text_inline( 'Your license has been cancelled. If you think it\'s a mistake, please contact support.', 'license-cancelled' ) . ' ' .
16768
+ sprintf(
16769
+ '<a href="%s">%s</a>',
16770
+ $this->contact_url( 'bug' ),
16771
+ $this->get_text_inline( 'Please contact us here', 'contact-us-here' )
16772
+ ),
16773
+ $hmm_text,
16774
+ 'error'
16775
+ );
16776
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
16777
+ break;
16778
+ case 'expired':
16779
+ $this->_admin_notices->add_sticky(
16780
+ sprintf( $this->get_text_inline( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', 'license-expired-non-blocking-message' ), $this->get_plan()->title ),
16781
+ 'license_expired',
16782
+ $hmm_text
16783
+ );
16784
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
16785
+ break;
16786
+ case 'trial_started':
16787
+ $this->_admin_notices->add_sticky(
16788
+ sprintf(
16789
+ $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
16790
+ '<i>' . $this->get_plugin_name() . '</i>'
16791
+ ) . $this->get_complete_upgrade_instructions( $this->get_trial_plan()->title ),
16792
+ 'trial_started',
16793
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
16794
+ );
16795
+
16796
+ $this->_admin_notices->remove_sticky( array(
16797
+ 'trial_promotion',
16798
+ ) );
16799
+ break;
16800
+ case 'trial_expired':
16801
+ $this->_admin_notices->add_sticky(
16802
+ ($this->has_free_plan() ?
16803
+ $this->get_text_inline( 'Your free trial has expired. You can still continue using all our free features.', 'trial-expired-message' ) :
16804
+ /* translators: %1$s: product title; %2$s, %3$s: wrapping HTML anchor element; %4$s: 'plugin', 'theme', or 'add-on'. */
16805
+ sprintf( $this->get_text_inline( 'Your free trial has expired. %1$sUpgrade now%2$s to continue using the %3$s without interruptions.', 'trial-expired-message_premium-only' ), sprintf('<a href="%s">', $this->pricing_url()), '</a>', $this->get_module_label(true))),
16806
+ 'trial_expired',
16807
+ $hmm_text
16808
+ );
16809
+ $this->_admin_notices->remove_sticky( array(
16810
+ 'trial_started',
16811
+ 'trial_promotion',
16812
+ 'plan_upgraded',
16813
+ ) );
16814
+ break;
16815
+ }
16816
+ }
16817
+
16818
+ if ( 'none' !== $plan_change ) {
16819
+ $this->do_action( 'after_license_change', $plan_change, $this->get_plan() );
16820
+ }
16821
+ }
16822
+
16823
+ /**
16824
+ * Include the required JS at the footer of the admin to trigger the license activation dialog box.
16825
+ *
16826
+ * @author Vova Feldman (@svovaf)
16827
+ * @since 2.0.0
16828
+ */
16829
+ public function _open_license_activation_dialog_box() {
16830
+ $vars = array( 'license_id' => $this->_site->license_id );
16831
+ fs_require_once_template( 'js/open-license-activation.php', $vars );
16832
+ }
16833
+
16834
+ /**
16835
+ * @author Vova Feldman (@svovaf)
16836
+ * @since 1.0.5
16837
+ *
16838
+ * @param bool $background
16839
+ */
16840
+ protected function _activate_license( $background = false ) {
16841
+ $this->_logger->entrance();
16842
+
16843
+ $license_id = fs_request_get( 'license_id' );
16844
+
16845
+ if ( is_object( $this->_site ) &&
16846
+ FS_Plugin_License::is_valid_id( $license_id ) &&
16847
+ $license_id == $this->_site->license_id
16848
+ ) {
16849
+ // License is already activated.
16850
+ return;
16851
+ }
16852
+
16853
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
16854
+ $this->_get_license_by_id( $license_id ) :
16855
+ $this->_get_available_premium_license();
16856
+
16857
+ if ( ! is_object( $premium_license ) ) {
16858
+ return;
16859
+ }
16860
+
16861
+ if ( ! is_object( $this->_site ) ) {
16862
+ // Not yet opted-in.
16863
+ $user = $this->get_current_or_network_user();
16864
+ if ( ! is_object( $user ) ) {
16865
+ $user = self::_get_user_by_id( $premium_license->user_id );
16866
+ }
16867
+
16868
+ if ( is_object( $user ) ) {
16869
+ $this->install_with_user( $user, $premium_license->secret_key, false, false, false );
16870
+ } else {
16871
+ $this->opt_in(
16872
+ false,
16873
+ false,
16874
+ false,
16875
+ $premium_license->secret_key
16876
+ );
16877
+
16878
+ return;
16879
+ }
16880
+ }
16881
+
16882
+
16883
+ /**
16884
+ * If the premium license is already associated with the install, just
16885
+ * update the license reference (activation is not required).
16886
+ *
16887
+ * @since 1.1.9
16888
+ */
16889
+ if ( $premium_license->id == $this->_site->license_id ) {
16890
+ // License is already activated.
16891
+ $this->_update_site_license( $premium_license );
16892
+ $this->_store_account();
16893
+
16894
+ return;
16895
+ }
16896
+
16897
+ if ( $this->_site->user_id != $premium_license->user_id ) {
16898
+ $api_request_params = array( 'license_key' => $premium_license->secret_key );
16899
+ } else {
16900
+ $api_request_params = array();
16901
+ }
16902
+
16903
+ $api = $this->get_api_site_scope();
16904
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
16905
+
16906
+ if ( ! $this->is_api_result_entity( $license ) ) {
16907
+ if ( ! $background ) {
16908
+ $this->_admin_notices->add( sprintf(
16909
+ '%s %s',
16910
+ $this->get_text_inline( 'It looks like the license could not be activated.', 'license-activation-failed-message' ),
16911
+ ( is_object( $license ) && isset( $license->error ) ?
16912
+ $license->error->message :
16913
+ sprintf( '%s<br><code>%s</code>',
16914
+ $this->get_text_inline( 'Error received from the server:', 'server-error-message' ),
16915
+ var_export( $license, true )
16916
+ )
16917
+ )
16918
+ ),
16919
+ $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...',
16920
+ 'error'
16921
+ );
16922
+ }
16923
+
16924
+ return;
16925
+ }
16926
+
16927
+ $premium_license = new FS_Plugin_License( $license );
16928
+
16929
+ // Updated site plan.
16930
+ $site = $this->get_api_site_scope()->get( '/', true );
16931
+ if ( $this->is_api_result_entity( $site ) ) {
16932
+ $this->_site = new FS_Site( $site );
16933
+ }
16934
+ $this->_update_site_license( $premium_license );
16935
+
16936
+ $this->_store_account();
16937
+
16938
+ if ( ! $background ) {
16939
+ $this->_admin_notices->add_sticky(
16940
+ $this->get_text_inline( 'Your license was successfully activated.', 'license-activated-message' ) .
16941
+ $this->get_complete_upgrade_instructions(),
16942
+ 'license_activated',
16943
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
16944
+ );
16945
+ }
16946
+
16947
+ $this->_admin_notices->remove_sticky( array(
16948
+ 'trial_promotion',
16949
+ 'license_expired',
16950
+ ) );
16951
+ }
16952
+
16953
+ /**
16954
+ * @author Vova Feldman (@svovaf)
16955
+ * @since 1.0.5
16956
+ *
16957
+ * @param bool $show_notice
16958
+ */
16959
+ protected function _deactivate_license( $show_notice = true ) {
16960
+ $this->_logger->entrance();
16961
+
16962
+ $hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
16963
+
16964
+ if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
16965
+ $this->_admin_notices->add(
16966
+ sprintf( $this->get_text_inline( 'It looks like your site currently doesn\'t have an active license.', 'no-active-license-message' ), $this->get_plan_title() ),
16967
+ $hmm_text
16968
+ );
16969
+
16970
+ return;
16971
+ }
16972
+
16973
+ $api = $this->get_api_site_scope();
16974
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
16975
+
16976
+ if ( isset( $license->error ) ) {
16977
+ $this->_admin_notices->add(
16978
+ $this->get_text_inline( 'It looks like the license deactivation failed.', 'license-deactivation-failed-message' ) . '<br> ' .
16979
+ $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . ' ' . var_export( $license->error, true ),
16980
+ $hmm_text,
16981
+ 'error'
16982
+ );
16983
+
16984
+ return;
16985
+ }
16986
+
16987
+ // Update license cache.
16988
+ if ( is_array( $this->_licenses ) ) {
16989
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
16990
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
16991
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
16992
+ }
16993
+ }
16994
+ }
16995
+
16996
+ // Updated site plan to default.
16997
+ $this->_sync_plans();
16998
+ $this->_site->plan_id = $this->_plans[0]->id;
16999
+ // Unlink license from site.
17000
+ $this->_update_site_license( null );
17001
+
17002
+ $this->_store_account();
17003
+
17004
+ if ( $show_notice ) {
17005
+ $this->_admin_notices->add(
17006
+ sprintf( $this->get_text_inline( 'Your license was successfully deactivated, you are back to the %s plan.', 'license-deactivation-message' ), $this->get_plan_title() ),
17007
+ $this->get_text_inline( 'O.K', 'ok' )
17008
+ );
17009
+ }
17010
+
17011
+ $this->_admin_notices->remove_sticky( array(
17012
+ 'plan_upgraded',
17013
+ 'license_activated',
17014
+ ) );
17015
+ }
17016
+
17017
+ /**
17018
+ * Site plan downgrade.
17019
+ *
17020
+ * @author Vova Feldman (@svovaf)
17021
+ * @since 1.0.4
17022
+ *
17023
+ * @uses FS_Api
17024
+ */
17025
+ private function _downgrade_site() {
17026
+ $this->_logger->entrance();
17027
+
17028
+ $api = $this->get_api_site_scope();
17029
+ $site = $api->call( 'downgrade.json', 'put' );
17030
+
17031
+ $plan_downgraded = false;
17032
+ $plan = false;
17033
+ if ( $this->is_api_result_entity( $site ) ) {
17034
+ $prev_plan_id = $this->_site->plan_id;
17035
+
17036
+ // Update new site plan id.
17037
+ $this->_site->plan_id = $site->plan_id;
17038
+
17039
+ $plan = $this->get_plan();
17040
+ $subscription = $this->_sync_site_subscription( $this->_license );
17041
+
17042
+ // Plan downgraded if plan was changed or subscription was cancelled.
17043
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
17044
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
17045
+ } else {
17046
+ // handle different error cases.
17047
+
17048
+ }
17049
+
17050
+ if ( $plan_downgraded ) {
17051
+ // Remove previous sticky message about upgrade (if exist).
17052
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
17053
+
17054
+ $this->_admin_notices->add(
17055
+ sprintf( $this->get_text_inline( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'plan-x-downgraded-message' ),
17056
+ $plan->title,
17057
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
17058
+ )
17059
+ );
17060
+
17061
+ // Store site updates.
17062
+ $this->_store_site();
17063
+ } else {
17064
+ $this->_admin_notices->add(
17065
+ $this->get_text_inline( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'plan-downgraded-failure-message' ),
17066
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
17067
+ 'error'
17068
+ );
17069
+ }
17070
+ }
17071
+
17072
+ /**
17073
+ * @author Vova Feldman (@svovaf)
17074
+ * @since 1.1.8.1
17075
+ *
17076
+ * @param bool|string $plan_name
17077
+ *
17078
+ * @return bool If trial was successfully started.
17079
+ */
17080
+ function start_trial( $plan_name = false ) {
17081
+ $this->_logger->entrance();
17082
+
17083
+ // Alias.
17084
+ $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
17085
+
17086
+ if ( $this->is_trial() ) {
17087
+ // Already in trial mode.
17088
+ $this->_admin_notices->add(
17089
+ sprintf( $this->get_text_inline( 'You are already running the %s in a trial mode.', 'in-trial-mode' ), $this->_module_type ),
17090
+ $oops_text,
17091
+ 'error'
17092
+ );
17093
+
17094
+ return false;
17095
+ }
17096
+
17097
+ if ( $this->_site->is_trial_utilized() ) {
17098
+ // Trial was already utilized.
17099
+ $this->_admin_notices->add(
17100
+ $this->get_text_inline( 'You already utilized a trial before.', 'trial-utilized' ),
17101
+ $oops_text,
17102
+ 'error'
17103
+ );
17104
+
17105
+ return false;
17106
+ }
17107
+
17108
+ if ( false !== $plan_name ) {
17109
+ $plan = $this->get_plan_by_name( $plan_name );
17110
+
17111
+ if ( false === $plan ) {
17112
+ // Plan doesn't exist.
17113
+ $this->_admin_notices->add(
17114
+ sprintf( $this->get_text_inline( 'Plan %s do not exist, therefore, can\'t start a trial.', 'trial-plan-x-not-exist' ), $plan_name ),
17115
+ $oops_text,
17116
+ 'error'
17117
+ );
17118
+
17119
+ return false;
17120
+ }
17121
+
17122
+ if ( ! $plan->has_trial() ) {
17123
+ // Plan doesn't exist.
17124
+ $this->_admin_notices->add(
17125
+ sprintf( $this->get_text_inline( 'Plan %s does not support a trial period.', 'plan-x-no-trial' ), $plan_name ),
17126
+ $oops_text,
17127
+ 'error'
17128
+ );
17129
+
17130
+ return false;
17131
+ }
17132
+ } else {
17133
+ if ( ! $this->has_trial_plan() ) {
17134
+ // None of the plans have a trial.
17135
+ $this->_admin_notices->add(
17136
+ sprintf( $this->get_text_inline( 'None of the %s\'s plans supports a trial period.', 'no-trials' ), $this->_module_type ),
17137
+ $oops_text,
17138
+ 'error'
17139
+ );
17140
+
17141
+ return false;
17142
+ }
17143
+
17144
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
17145
+
17146
+ $plan = $plans_with_trial[0];
17147
+ }
17148
+
17149
+ $api = $this->get_api_site_scope();
17150
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
17151
+
17152
+ if ( ! $this->is_api_result_entity( $plan ) ) {
17153
+ // Some API error while trying to start the trial.
17154
+ $this->_admin_notices->add(
17155
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type )
17156
+ . ' ' . var_export( $plan, true ),
17157
+ $oops_text,
17158
+ 'error'
17159
+ );
17160
+
17161
+ return false;
17162
+ }
17163
+
17164
+ // Sync license.
17165
+ $this->_sync_license();
17166
+
17167
+ return $this->is_trial();
17168
+ }
17169
+
17170
+ /**
17171
+ * Cancel site trial.
17172
+ *
17173
+ * @author Vova Feldman (@svovaf)
17174
+ * @since 1.0.9
17175
+ *
17176
+ * @uses FS_Api
17177
+ */
17178
+ private function _cancel_trial() {
17179
+ $this->_logger->entrance();
17180
+
17181
+ // Alias.
17182
+ $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
17183
+
17184
+ if ( ! $this->is_trial() ) {
17185
+ $this->_admin_notices->add(
17186
+ $this->get_text_inline( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'trial-cancel-no-trial-message' ),
17187
+ $oops_text,
17188
+ 'error'
17189
+ );
17190
+
17191
+ return;
17192
+ }
17193
+
17194
+ $trial_plan = $this->get_trial_plan();
17195
+
17196
+ $api = $this->get_api_site_scope();
17197
+ $site = $api->call( 'trials.json', 'delete' );
17198
+
17199
+ $trial_cancelled = false;
17200
+
17201
+ if ( $this->is_api_result_entity( $site ) ) {
17202
+ $prev_trial_ends = $this->_site->trial_ends;
17203
+
17204
+ if ( $this->is_paid_trial() ) {
17205
+ $this->_license->expiration = $site->trial_ends;
17206
+ $this->_license->is_cancelled = true;
17207
+ $this->_update_site_license( $this->_license );
17208
+ $this->_store_licenses();
17209
+
17210
+ // Clear subscription reference.
17211
+ $this->_sync_site_subscription( null );
17212
+ }
17213
+
17214
+ // Update site info.
17215
+ $this->_site = new FS_Site( $site );
17216
+
17217
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
17218
+ } else {
17219
+ // @todo handle different error cases.
17220
+ }
17221
+
17222
+ if ( $trial_cancelled ) {
17223
+ // Remove previous sticky messages about upgrade or trial (if exist).
17224
+ $this->_admin_notices->remove_sticky( array(
17225
+ 'trial_started',
17226
+ 'trial_promotion',
17227
+ 'plan_upgraded',
17228
+ ) );
17229
+
17230
+ // Store site updates.
17231
+ $this->_store_site();
17232
+
17233
+ if ( ! $this->is_addon() ||
17234
+ ! $this->deactivate_premium_only_addon_without_license( true )
17235
+ ) {
17236
+ $this->_admin_notices->add(
17237
+ sprintf( $this->get_text_inline( 'Your %s free trial was successfully cancelled.', 'trial-cancel-message' ), $trial_plan->title )
17238
+ );
17239
+ }
17240
+ } else {
17241
+ $this->_admin_notices->add(
17242
+ $this->get_text_inline( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'trial-cancel-failure-message' ),
17243
+ $oops_text,
17244
+ 'error'
17245
+ );
17246
+ }
17247
+ }
17248
+
17249
+ /**
17250
+ * @author Vova Feldman (@svovaf)
17251
+ * @since 1.0.6
17252
+ *
17253
+ * @param bool|number $plugin_id
17254
+ *
17255
+ * @return bool
17256
+ */
17257
+ private function _is_addon_id( $plugin_id ) {
17258
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
17259
+ }
17260
+
17261
+ /**
17262
+ * Check if user eligible to download premium version updates.
17263
+ *
17264
+ * @author Vova Feldman (@svovaf)
17265
+ * @since 1.0.6
17266
+ *
17267
+ * @return bool
17268
+ */
17269
+ private function _can_download_premium() {
17270
+ return $this->has_active_valid_license() ||
17271
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
17272
+ }
17273
+
17274
+ /**
17275
+ *
17276
+ * @author Vova Feldman (@svovaf)
17277
+ * @since 1.0.6
17278
+ *
17279
+ * @param bool|number $addon_id
17280
+ * @param string $type "json" or "zip"
17281
+ *
17282
+ * @return string
17283
+ */
17284
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
17285
+
17286
+ $is_addon = $this->_is_addon_id( $addon_id );
17287
+
17288
+ $is_premium = null;
17289
+ if ( ! $is_addon ) {
17290
+ $is_premium = ( $this->is_premium() || $this->_can_download_premium() );
17291
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
17292
+ $fs_addon = self::get_instance_by_id( $addon_id );
17293
+ $is_premium = ( $fs_addon->is_premium() || $fs_addon->_can_download_premium() );
17294
+ }
17295
+
17296
+ // If add-on, then append add-on ID.
17297
+ $endpoint = ( $is_addon ? "/addons/$addon_id" : '' ) .
17298
+ '/updates/latest.' . $type;
17299
+
17300
+ // If add-on and not yet activated, try to fetch based on server licensing.
17301
+ if ( is_bool( $is_premium ) ) {
17302
+ $endpoint = add_query_arg( 'is_premium', json_encode( $is_premium ), $endpoint );
17303
+ }
17304
+
17305
+ if ( $this->has_secret_key() ) {
17306
+ $endpoint = add_query_arg( 'type', 'all', $endpoint );
17307
+ }
17308
+
17309
+ return $endpoint;
17310
+ }
17311
+
17312
+ /**
17313
+ * @author Vova Feldman (@svovaf)
17314
+ * @since 1.0.4
17315
+ *
17316
+ * @param bool|number $addon_id
17317
+ * @param bool $flush Since 1.1.7.3
17318
+ * @param int $expiration Since 1.2.2.7
17319
+ *
17320
+ * @return object|false Plugin latest tag info.
17321
+ */
17322
+ function _fetch_latest_version(
17323
+ $addon_id = false,
17324
+ $flush = true,
17325
+ $expiration = WP_FS__TIME_24_HOURS_IN_SEC
17326
+ ) {
17327
+ $this->_logger->entrance();
17328
+
17329
+ $switch_to_blog_id = null;
17330
+
17331
+ /**
17332
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
17333
+ * @since 1.1.7.4 Also check updates for add-ons.
17334
+ */
17335
+ if ( ! $this->is_registered() &&
17336
+ ! $this->_is_addon_id( $addon_id )
17337
+ ) {
17338
+ if ( ! is_multisite() ) {
17339
+ return false;
17340
+ }
17341
+
17342
+ $installs_map = $this->get_blog_install_map();
17343
+
17344
+ foreach ( $installs_map as $blog_id => $install ) {
17345
+ /**
17346
+ * @var FS_Site $install
17347
+ */
17348
+ if ( $install->is_trial() ) {
17349
+ $switch_to_blog_id = $blog_id;
17350
+ break;
17351
+ }
17352
+
17353
+ if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
17354
+ $license = $this->get_license_by_id( $install->license_id );
17355
+
17356
+ if ( is_object( $license ) && $license->is_features_enabled() ) {
17357
+ $switch_to_blog_id = $blog_id;
17358
+ break;
17359
+ }
17360
+ }
17361
+ }
17362
+
17363
+ if ( is_null( $switch_to_blog_id ) ) {
17364
+ return false;
17365
+ }
17366
+ }
17367
+
17368
+ $current_blog_id = is_numeric( $switch_to_blog_id ) ?
17369
+ get_current_blog_id() :
17370
+ 0;
17371
+
17372
+ if ( is_numeric( $switch_to_blog_id ) ) {
17373
+ $this->switch_to_blog( $switch_to_blog_id );
17374
+ }
17375
+
17376
+ $tag = $this->get_api_site_or_plugin_scope()->get(
17377
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
17378
+ $flush,
17379
+ $expiration
17380
+ );
17381
+
17382
+ if ( is_numeric( $switch_to_blog_id ) ) {
17383
+ $this->switch_to_blog( $current_blog_id );
17384
+ }
17385
+
17386
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
17387
+
17388
+ $this->_logger->departure( 'Latest version ' . $latest_version );
17389
+
17390
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
17391
+ }
17392
+
17393
+ #----------------------------------------------------------------------------------
17394
+ #region Download Plugin
17395
+ #----------------------------------------------------------------------------------
17396
+
17397
+ /**
17398
+ * Download latest plugin version, based on plan.
17399
+ *
17400
+ * Not like _download_latest(), this will redirect the page
17401
+ * to secure download url to prevent dual download (from FS to WP server,
17402
+ * and then from WP server to the client / browser).
17403
+ *
17404
+ * @author Vova Feldman (@svovaf)
17405
+ * @since 1.0.9
17406
+ *
17407
+ * @param bool|number $plugin_id
17408
+ *
17409
+ * @uses FS_Api
17410
+ * @uses wp_redirect()
17411
+ */
17412
+ private function download_latest_directly( $plugin_id = false ) {
17413
+ $this->_logger->entrance();
17414
+
17415
+ wp_redirect( $this->get_latest_download_api_url( $plugin_id ) );
17416
+ }
17417
+
17418
+ /**
17419
+ * Get latest plugin FS API download URL.
17420
+ *
17421
+ * @author Vova Feldman (@svovaf)
17422
+ * @since 1.0.9
17423
+ *
17424
+ * @param bool|number $plugin_id
17425
+ *
17426
+ * @return string
17427
+ */
17428
+ private function get_latest_download_api_url( $plugin_id = false ) {
17429
+ $this->_logger->entrance();
17430
+
17431
+ return $this->get_api_site_scope()->get_signed_url(
17432
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
17433
+ );
17434
+ }
17435
+
17436
+ /**
17437
+ * Get payment invoice URL.
17438
+ *
17439
+ * @author Vova Feldman (@svovaf)
17440
+ * @since 1.2.0
17441
+ *
17442
+ * @param bool|number $payment_id
17443
+ *
17444
+ * @return string
17445
+ */
17446
+ function _get_invoice_api_url( $payment_id = false ) {
17447
+ $this->_logger->entrance();
17448
+
17449
+ return $this->get_api_user_scope()->get_signed_url(
17450
+ "/payments/{$payment_id}/invoice.pdf"
17451
+ );
17452
+ }
17453
+
17454
+ /**
17455
+ * Get latest plugin download link.
17456
+ *
17457
+ * @author Vova Feldman (@svovaf)
17458
+ * @since 1.0.9
17459
+ *
17460
+ * @param string $label
17461
+ * @param bool|number $plugin_id
17462
+ *
17463
+ * @return string
17464
+ */
17465
+ private function get_latest_download_link( $label, $plugin_id = false ) {
17466
+ return sprintf(
17467
+ '<a target="_blank" href="%s">%s</a>',
17468
+ $this->_get_latest_download_local_url( $plugin_id ),
17469
+ $label
17470
+ );
17471
+ }
17472
+
17473
+ /**
17474
+ * Get latest plugin download local URL.
17475
+ *
17476
+ * @author Vova Feldman (@svovaf)
17477
+ * @since 1.0.9
17478
+ *
17479
+ * @param bool|number $plugin_id
17480
+ *
17481
+ * @return string
17482
+ */
17483
+ function _get_latest_download_local_url( $plugin_id = false ) {
17484
+ // Add timestamp to protect from caching.
17485
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
17486
+
17487
+ if ( ! empty( $plugin_id ) ) {
17488
+ $params['plugin_id'] = $plugin_id;
17489
+ } else if ( $this->is_addon() ) {
17490
+ $params['plugin_id'] = $this->get_id();
17491
+ }
17492
+
17493
+ $fs = $this->is_addon() ?
17494
+ $this->get_parent_instance() :
17495
+ $this;
17496
+
17497
+ return $fs->get_account_url( 'download_latest', $params );
17498
+ }
17499
+
17500
+ #endregion Download Plugin ------------------------------------------------------------------
17501
+
17502
+ /**
17503
+ * @author Vova Feldman (@svovaf)
17504
+ * @since 1.0.4
17505
+ *
17506
+ * @uses FS_Api
17507
+ *
17508
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
17509
+ * was initiated by the admin.
17510
+ * @param bool|number $plugin_id
17511
+ * @param bool $flush Since 1.1.7.3
17512
+ * @param int $expiration Since 1.2.2.7
17513
+ */
17514
+ private function check_updates(
17515
+ $background = false,
17516
+ $plugin_id = false,
17517
+ $flush = true,
17518
+ $expiration = WP_FS__TIME_24_HOURS_IN_SEC
17519
+ ) {
17520
+ $this->_logger->entrance();
17521
+
17522
+ // Check if there's a newer version for download.
17523
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush, $expiration );
17524
+
17525
+ $update = null;
17526
+ if ( is_object( $new_version ) ) {
17527
+ $update = new FS_Plugin_Tag( $new_version );
17528
+
17529
+ if ( ! $background ) {
17530
+ $this->_admin_notices->add(
17531
+ sprintf(
17532
+ /* translators: %s: Numeric version number (e.g. '2.1.9' */
17533
+ $this->get_text_inline( 'Version %s was released.', 'version-x-released' ) . ' ' . $this->get_text_inline( 'Please download %s.', 'please-download-x' ),
17534
+ $update->version,
17535
+ sprintf(
17536
+ '<a href="%s" target="_blank">%s</a>',
17537
+ $this->get_account_url( 'download_latest' ),
17538
+ sprintf(
17539
+ /* translators: %s: plan name (e.g. latest "Professional" version) */
17540
+ $this->get_text_inline( 'the latest %s version here', 'latest-x-version' ),
17541
+ $this->get_plan_title()
17542
+ )
17543
+ )
17544
+ ),
17545
+ $this->get_text_inline( 'New', 'new' ) . '!'
17546
+ );
17547
+ }
17548
+ } else if ( false === $new_version && ! $background ) {
17549
+ $this->_admin_notices->add(
17550
+ $this->get_text_inline( 'Seems like you got the latest release.', 'you-have-latest' ),
17551
+ $this->get_text_inline( 'You are all good!', 'you-are-good' )
17552
+ );
17553
+ }
17554
+
17555
+ $this->_store_update( $update, true, $plugin_id );
17556
+ }
17557
+
17558
+ /**
17559
+ * @author Vova Feldman (@svovaf)
17560
+ * @since 1.0.4
17561
+ *
17562
+ * @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
17563
+ *
17564
+ * @return FS_Plugin[]
17565
+ *
17566
+ * @uses FS_Api
17567
+ */
17568
+ private function sync_addons( $flush = false ) {
17569
+ $this->_logger->entrance();
17570
+
17571
+ $api = $this->get_api_site_or_plugin_scope();
17572
+
17573
+ /**
17574
+ * @since 1.2.1
17575
+ *
17576
+ * If there's a cached version of the add-ons and not asking
17577
+ * for a flush, just use the currently stored add-ons.
17578
+ */
17579
+ if ( ! $flush && $api->is_cached( '/addons.json?enriched=true' ) ) {
17580
+ $addons = self::get_all_addons();
17581
+
17582
+ return $addons[ $this->_plugin->id ];
17583
+ }
17584
+
17585
+ $result = $api->get( '/addons.json?enriched=true', $flush );
17586
+
17587
+ $addons = array();
17588
+ if ( $this->is_api_result_object( $result, 'plugins' ) &&
17589
+ is_array( $result->plugins )
17590
+ ) {
17591
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
17592
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
17593
+ }
17594
+
17595
+ $this->_store_addons( $addons, true );
17596
+ }
17597
+
17598
+ return $addons;
17599
+ }
17600
+
17601
+ /**
17602
+ * Handle user email update.
17603
+ *
17604
+ * @author Vova Feldman (@svovaf)
17605
+ * @since 1.0.3
17606
+ * @uses FS_Api
17607
+ *
17608
+ * @param string $new_email
17609
+ *
17610
+ * @return object
17611
+ */
17612
+ private function update_email( $new_email ) {
17613
+ $this->_logger->entrance();
17614
+
17615
+
17616
+ $api = $this->get_api_user_scope();
17617
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
17618
+ 'email' => $new_email,
17619
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
17620
+ 'account',
17621
+ array( 'fs_action' => 'sync_user' )
17622
+ ),
17623
+ ) );
17624
+
17625
+ if ( ! isset( $user->error ) ) {
17626
+ $this->_user->email = $user->email;
17627
+ $this->_user->is_verified = $user->is_verified;
17628
+ $this->_store_user();
17629
+ } else {
17630
+ // handle different error cases.
17631
+
17632
+ }
17633
+
17634
+ return $user;
17635
+ }
17636
+
17637
+ #----------------------------------------------------------------------------------
17638
+ #region API Error Handling
17639
+ #----------------------------------------------------------------------------------
17640
+
17641
+ /**
17642
+ * @author Vova Feldman (@svovaf)
17643
+ * @since 1.1.1
17644
+ *
17645
+ * @param mixed $result
17646
+ *
17647
+ * @return bool Is API result contains an error.
17648
+ */
17649
+ private function is_api_error( $result ) {
17650
+ return FS_Api::is_api_error( $result );
17651
+ }
17652
+
17653
+ /**
17654
+ * Checks if given API result is a non-empty and not an error object.
17655
+ *
17656
+ * @author Vova Feldman (@svovaf)
17657
+ * @since 1.2.1.5
17658
+ *
17659
+ * @param mixed $result
17660
+ * @param string|null $required_property Optional property we want to verify that is set.
17661
+ *
17662
+ * @return bool
17663
+ */
17664
+ function is_api_result_object( $result, $required_property = null ) {
17665
+ return FS_Api::is_api_result_object( $result, $required_property );
17666
+ }
17667
+
17668
+ /**
17669
+ * Checks if given API result is a non-empty entity object with non-empty ID.
17670
+ *
17671
+ * @author Vova Feldman (@svovaf)
17672
+ * @since 1.2.1.5
17673
+ *
17674
+ * @param mixed $result
17675
+ *
17676
+ * @return bool
17677
+ */
17678
+ private function is_api_result_entity( $result ) {
17679
+ return FS_Api::is_api_result_entity( $result );
17680
+ }
17681
+
17682
+ #endregion
17683
+
17684
+ /**
17685
+ * Make sure a given argument is an array of a specific type.
17686
+ *
17687
+ * @author Vova Feldman (@svovaf)
17688
+ * @since 1.2.1.5
17689
+ *
17690
+ * @param mixed $array
17691
+ * @param string $class
17692
+ *
17693
+ * @return bool
17694
+ */
17695
+ private function is_array_instanceof( $array, $class ) {
17696
+ return ( is_array( $array ) && ( empty( $array ) || $array[0] instanceof $class ) );
17697
+ }
17698
+
17699
+ /**
17700
+ * Start install ownership change.
17701
+ *
17702
+ * @author Vova Feldman (@svovaf)
17703
+ * @since 1.1.1
17704
+ * @uses FS_Api
17705
+ *
17706
+ * @param string $candidate_email
17707
+ *
17708
+ * @return bool Is ownership change successfully initiated.
17709
+ */
17710
+ private function init_change_owner( $candidate_email ) {
17711
+ $this->_logger->entrance();
17712
+
17713
+ $api = $this->get_api_site_scope();
17714
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
17715
+ 'email' => $candidate_email,
17716
+ 'after_confirm_url' => $this->_get_admin_page_url(
17717
+ 'account',
17718
+ array( 'fs_action' => 'change_owner' )
17719
+ ),
17720
+ ) );
17721
+
17722
+ return ! $this->is_api_error( $result );
17723
+ }
17724
+
17725
+ /**
17726
+ * Handle install ownership change.
17727
+ *
17728
+ * @author Vova Feldman (@svovaf)
17729
+ * @since 1.1.1
17730
+ * @uses FS_Api
17731
+ *
17732
+ * @return bool Was ownership change successfully complete.
17733
+ */
17734
+ private function complete_change_owner() {
17735
+ $this->_logger->entrance();
17736
+
17737
+ $site_result = $this->get_api_site_scope( true )->get();
17738
+ $site = new FS_Site( $site_result );
17739
+ $this->_site = $site;
17740
+
17741
+ $user = new FS_User();
17742
+ $user->id = fs_request_get( 'user_id' );
17743
+
17744
+ // Validate install's user and given user.
17745
+ if ( $user->id != $this->_site->user_id ) {
17746
+ return false;
17747
+ }
17748
+
17749
+ $user->public_key = fs_request_get( 'user_public_key' );
17750
+ $user->secret_key = fs_request_get( 'user_secret_key' );
17751
+
17752
+ // Fetch new user information.
17753
+ $this->_user = $user;
17754
+ $user_result = $this->get_api_user_scope( true )->get();
17755
+ $user = new FS_User( $user_result );
17756
+ $this->_user = $user;
17757
+
17758
+ $this->_set_account( $user, $site );
17759
+
17760
+ return true;
17761
+ }
17762
+
17763
+ /**
17764
+ * Handle user name update.
17765
+ *
17766
+ * @author Vova Feldman (@svovaf)
17767
+ * @since 1.0.9
17768
+ * @uses FS_Api
17769
+ *
17770
+ * @return object
17771
+ */
17772
+ private function update_user_name() {
17773
+ $this->_logger->entrance();
17774
+ $name = fs_request_get( 'fs_user_name_' . $this->get_unique_affix(), '' );
17775
+
17776
+ $api = $this->get_api_user_scope();
17777
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
17778
+ 'name' => $name,
17779
+ ) );
17780
+
17781
+ if ( ! isset( $user->error ) ) {
17782
+ $this->_user->first = $user->first;
17783
+ $this->_user->last = $user->last;
17784
+ $this->_store_user();
17785
+ } else {
17786
+ // handle different error cases.
17787
+
17788
+ }
17789
+
17790
+ return $user;
17791
+ }
17792
+
17793
+ /**
17794
+ * Verify user email.
17795
+ *
17796
+ * @author Vova Feldman (@svovaf)
17797
+ * @since 1.0.3
17798
+ * @uses FS_Api
17799
+ */
17800
+ private function verify_email() {
17801
+ $this->_handle_account_user_sync();
17802
+
17803
+ if ( $this->_user->is_verified() ) {
17804
+ return;
17805
+ }
17806
+
17807
+ $api = $this->get_api_site_scope();
17808
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
17809
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
17810
+ 'account',
17811
+ array( 'fs_action' => 'sync_user' )
17812
+ )
17813
+ ) );
17814
+
17815
+ if ( ! isset( $result->error ) ) {
17816
+ $this->_admin_notices->add( sprintf(
17817
+ $this->get_text_inline( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'verification-email-sent-message' ),
17818
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
17819
+ ) );
17820
+ } else {
17821
+ // handle different error cases.
17822
+
17823
+ }
17824
+ }
17825
+
17826
+ /**
17827
+ * @author Vova Feldman (@svovaf)
17828
+ * @since 1.1.2
17829
+ *
17830
+ * @param array $params
17831
+ * @param bool|null $network
17832
+ *
17833
+ * @return string
17834
+ */
17835
+ function get_activation_url( $params = array(), $network = null ) {
17836
+ if ( $this->is_addon() && $this->has_free_plan() ) {
17837
+ /**
17838
+ * @author Vova Feldman (@svovaf)
17839
+ * @since 1.2.1.7 Add-on's activation is the parent's module activation.
17840
+ */
17841
+ return $this->get_parent_instance()->get_activation_url( $params );
17842
+ }
17843
+
17844
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params, $network ) );
17845
+ }
17846
+
17847
+ /**
17848
+ * @author Vova Feldman (@svovaf)
17849
+ * @since 1.2.1.5
17850
+ *
17851
+ * @param array $params
17852
+ *
17853
+ * @return string
17854
+ */
17855
+ function get_reconnect_url( $params = array() ) {
17856
+ $params['fs_action'] = 'reset_anonymous_mode';
17857
+ $params['fs_unique_affix'] = $this->get_unique_affix();
17858
+
17859
+ return $this->get_activation_url( $params );
17860
+ }
17861
+
17862
+ /**
17863
+ * Get the URL of the page that should be loaded after the user connect
17864
+ * or skip in the opt-in screen.
17865
+ *
17866
+ * @author Vova Feldman (@svovaf)
17867
+ * @since 1.1.3
17868
+ *
17869
+ * @param string $filter Filter name.
17870
+ * @param array $params Since 1.2.2.7
17871
+ * @param bool|null $network
17872
+ *
17873
+ * @return string
17874
+ */
17875
+ function get_after_activation_url( $filter, $params = array(), $network = null ) {
17876
+ if ( $this->is_free_wp_org_theme() &&
17877
+ fs_request_has( 'pending_activation' )
17878
+ ) {
17879
+ $first_time_path = '';
17880
+ } else {
17881
+ $first_time_path = $this->_menu->get_first_time_path();
17882
+ }
17883
+
17884
+ if ( $this->_is_network_active &&
17885
+ fs_is_network_admin() &&
17886
+ ! $this->_menu->has_network_menu() &&
17887
+ $this->is_network_registered()
17888
+ ) {
17889
+ $target_url = $this->get_account_url();
17890
+ } else {
17891
+ // Default plugin's page.
17892
+ $target_url = $this->_get_admin_page_url( '', array(), $network );
17893
+ }
17894
+
17895
+ return add_query_arg( $params, $this->apply_filters(
17896
+ $filter,
17897
+ empty( $first_time_path ) ?
17898
+ $target_url :
17899
+ $first_time_path
17900
+ ) );
17901
+ }
17902
+
17903
+ /**
17904
+ * Handle account page updates / edits / actions.
17905
+ *
17906
+ * @author Vova Feldman (@svovaf)
17907
+ * @since 1.0.2
17908
+ *
17909
+ */
17910
+ private function _handle_account_edits() {
17911
+ if ( ! $this->is_user_admin() ) {
17912
+ return;
17913
+ }
17914
+
17915
+ $action = fs_get_action();
17916
+
17917
+ if ( empty( $action ) ) {
17918
+ return;
17919
+ }
17920
+
17921
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
17922
+ $install_id = fs_request_get( 'install_id', '' );
17923
+
17924
+ // Alias.
17925
+ $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
17926
+
17927
+ $is_network_action = $this->is_network_level_action();
17928
+ $blog_id = $this->is_network_level_site_specific_action();
17929
+
17930
+ if ( is_numeric( $blog_id ) ) {
17931
+ $this->switch_to_blog( $blog_id );
17932
+ } else {
17933
+ $blog_id = '';
17934
+ }
17935
+
17936
+ switch ( $action ) {
17937
+ case 'opt_in':
17938
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
17939
+
17940
+ if ( $plugin_id == $this->get_id() ) {
17941
+ if ( $is_network_action && ! empty( $blog_id ) ) {
17942
+ if ( ! $this->is_registered() ) {
17943
+ $this->install_with_user(
17944
+ $this->get_network_user(),
17945
+ false,
17946
+ false,
17947
+ false,
17948
+ false
17949
+ );
17950
+
17951
+ $this->_admin_notices->add(
17952
+ $this->get_text_inline( 'Site successfully opted in.', 'successful-opt-in' ),
17953
+ $this->get_text_inline( 'Awesome', 'awesome' )
17954
+ );
17955
+ }
17956
+ }
17957
+ }
17958
+ break;
17959
+
17960
+ case 'toggle_tracking':
17961
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
17962
+
17963
+ if ( $plugin_id == $this->get_id() ) {
17964
+ if ( $is_network_action && ! empty( $blog_id ) ) {
17965
+ if ( $this->is_registered() ) {
17966
+ if ( $this->is_tracking_prohibited() ) {
17967
+ if ( $this->allow_site_tracking() ) {
17968
+ $this->_admin_notices->add(
17969
+ sprintf( $this->get_text_inline( 'We appreciate your help in making the %s better by letting us track some usage data.', 'opt-out-message-appreciation' ), $this->_module_type ),
17970
+ $this->get_text_inline( 'Thank you!', 'thank-you' )
17971
+ );
17972
+ }
17973
+ } else {
17974
+ if ( $this->stop_site_tracking() ) {
17975
+ $this->_admin_notices->add(
17976
+ sprintf(
17977
+ $this->get_text_inline( 'We will no longer be sending any usage data of %s on %s to %s.', 'opted-out-successfully' ),
17978
+ $this->get_plugin_title(),
17979
+ fs_strip_url_protocol( get_site_url( $blog_id ) ),
17980
+ sprintf(
17981
+ '<a href="%s" target="_blank">%s</a>',
17982
+ 'https://freemius.com',
17983
+ 'freemius.com'
17984
+ )
17985
+ )
17986
+ );
17987
+ }
17988
+ }
17989
+ }
17990
+ }
17991
+ }
17992
+
17993
+ break;
17994
+
17995
+ case 'delete_account':
17996
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
17997
+
17998
+ if ( $plugin_id == $this->get_id() ) {
17999
+ if ( $is_network_action && empty( $blog_id ) ) {
18000
+ $this->delete_network_account_event();
18001
+ } else {
18002
+ $this->delete_account_event();
18003
+ }
18004
+
18005
+ // Clear user and site.
18006
+ $this->_site = null;
18007
+ $this->_user = null;
18008
+
18009
+ fs_redirect( $this->get_activation_url() );
18010
+ } else {
18011
+ if ( $this->is_addon_activated( $plugin_id ) ) {
18012
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18013
+ $fs_addon->delete_account_event();
18014
+
18015
+ fs_redirect( $this->_get_admin_page_url( 'account' ) );
18016
+ }
18017
+ }
18018
+
18019
+ return;
18020
+
18021
+ case 'downgrade_account':
18022
+ if ( is_numeric( $blog_id ) ) {
18023
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18024
+ } else {
18025
+ check_admin_referer( $action );
18026
+ }
18027
+
18028
+ if ( $plugin_id == $this->get_id() ) {
18029
+ $this->_downgrade_site();
18030
+
18031
+ if ( is_numeric( $blog_id ) ) {
18032
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
18033
+ }
18034
+ } else if ( $this->is_addon_activated( $plugin_id ) ) {
18035
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18036
+ $fs_addon->_downgrade_site();
18037
+ }
18038
+
18039
+ return;
18040
+
18041
+ case 'activate_license':
18042
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18043
+
18044
+ $fs = $this;
18045
+ if ( $plugin_id != $this->get_id() ) {
18046
+ $fs = $this->is_addon_activated( $plugin_id ) ?
18047
+ self::get_instance_by_id( $plugin_id ) :
18048
+ null;
18049
+ }
18050
+
18051
+ if ( is_object( $fs ) ) {
18052
+ $fs->_activate_license();
18053
+ }
18054
+
18055
+ return;
18056
+
18057
+ case 'deactivate_license':
18058
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18059
+
18060
+ if ( $plugin_id == $this->get_id() ) {
18061
+ $this->_deactivate_license();
18062
+
18063
+ if ( $this->is_only_premium() ) {
18064
+ // Clear user and site.
18065
+ $this->_site = null;
18066
+ $this->_user = null;
18067
+
18068
+ fs_redirect( $this->get_activation_url() );
18069
+ }
18070
+ } else {
18071
+ if ( $this->is_addon_activated( $plugin_id ) ) {
18072
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18073
+ $fs_addon->_deactivate_license();
18074
+ }
18075
+ }
18076
+
18077
+ return;
18078
+
18079
+ case 'check_updates':
18080
+ check_admin_referer( $action );
18081
+ $this->check_updates();
18082
+
18083
+ return;
18084
+
18085
+ case 'change_owner':
18086
+ $state = fs_request_get( 'state', 'init' );
18087
+ switch ( $state ) {
18088
+ case 'init':
18089
+ $candidate_email = fs_request_get( 'candidate_email', '' );
18090
+
18091
+ if ( $this->init_change_owner( $candidate_email ) ) {
18092
+ $this->_admin_notices->add( sprintf( $this->get_text_inline( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.', 'change-owner-request-sent-x' ), '<b>' . $this->_user->email . '</b>' ) );
18093
+ }
18094
+ break;
18095
+ case 'owner_confirmed':
18096
+ $candidate_email = fs_request_get( 'candidate_email', '' );
18097
+
18098
+ $this->_admin_notices->add( sprintf( $this->get_text_inline( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'change-owner-request_owner-confirmed' ), '<b>' . $candidate_email . '</b>' ) );
18099
+ break;
18100
+ case 'candidate_confirmed':
18101
+ if ( $this->complete_change_owner() ) {
18102
+ $this->_admin_notices->add_sticky(
18103
+ sprintf( $this->get_text_inline( '%s is the new owner of the account.', 'change-owner-request_candidate-confirmed' ), '<b>' . $this->_user->email . '</b>' ),
18104
+ 'ownership_changed',
18105
+ $this->get_text_x_inline( 'Congrats', 'as congratulations', 'congrats' ) . '!'
18106
+ );
18107
+ } else {
18108
+ // @todo Handle failed ownership change message.
18109
+ }
18110
+ break;
18111
+ }
18112
+
18113
+ return;
18114
+
18115
+ case 'update_email':
18116
+ check_admin_referer( 'update_email' );
18117
+
18118
+ $new_email = fs_request_get( 'fs_email_' . $this->get_unique_affix(), '' );
18119
+ $result = $this->update_email( $new_email );
18120
+
18121
+ if ( isset( $result->error ) ) {
18122
+ switch ( $result->error->code ) {
18123
+ case 'user_exist':
18124
+ $this->_admin_notices->add(
18125
+ $this->get_text_inline( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'user-exist-message' ) . ' ' .
18126
+ sprintf( $this->get_text_inline( 'If you would like to give up the ownership of the %s\'s account to %s click the Change Ownership button.', 'user-exist-message_ownership' ), $this->_module_type, '<b>' . $new_email . '</b>' ) .
18127
+ sprintf(
18128
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
18129
+ $this->get_account_url( 'change_owner', array(
18130
+ 'state' => 'init',
18131
+ 'candidate_email' => $new_email
18132
+ ) ),
18133
+ $this->get_text_inline( 'Change Ownership', 'change-ownership' )
18134
+ ),
18135
+ $oops_text,
18136
+ 'error'
18137
+ );
18138
+ break;
18139
+ }
18140
+ } else {
18141
+ $this->_admin_notices->add( $this->get_text_inline( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'email-updated-message' ) );
18142
+ }
18143
+
18144
+ return;
18145
+
18146
+ case 'update_user_name':
18147
+ check_admin_referer( 'update_user_name' );
18148
+
18149
+ $result = $this->update_user_name();
18150
+
18151
+ if ( isset( $result->error ) ) {
18152
+ $this->_admin_notices->add(
18153
+ $this->get_text_inline( 'Please provide your full name.', 'name-update-failed-message' ),
18154
+ $oops_text,
18155
+ 'error'
18156
+ );
18157
+ } else {
18158
+ $this->_admin_notices->add( $this->get_text_inline( 'Your name was successfully updated.', 'name-updated-message' ) );
18159
+ }
18160
+
18161
+ return;
18162
+
18163
+ #region Actions that might be called from external links (e.g. email)
18164
+
18165
+ case 'cancel_trial':
18166
+ if ( $plugin_id == $this->get_id() ) {
18167
+ $this->_cancel_trial();
18168
+ } else {
18169
+ if ( $this->is_addon_activated( $plugin_id ) ) {
18170
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18171
+ $fs_addon->_cancel_trial();
18172
+ }
18173
+ }
18174
+
18175
+ return;
18176
+
18177
+ case 'verify_email':
18178
+ $this->verify_email();
18179
+
18180
+ return;
18181
+
18182
+ case 'sync_user':
18183
+ $this->_handle_account_user_sync();
18184
+
18185
+ return;
18186
+
18187
+ case $this->get_unique_affix() . '_sync_license':
18188
+ $this->_sync_license();
18189
+
18190
+ return;
18191
+
18192
+ case 'download_latest':
18193
+ $this->download_latest_directly( $plugin_id );
18194
+
18195
+ return;
18196
+
18197
+ #endregion
18198
+ }
18199
+
18200
+ if ( WP_FS__IS_POST_REQUEST ) {
18201
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
18202
+ foreach ( $properties as $p ) {
18203
+ if ( 'update_' . $p === $action ) {
18204
+ check_admin_referer( $action );
18205
+
18206
+ $this->_logger->log( $action );
18207
+
18208
+ $site_property = substr( $p, strlen( 'site_' ) );
18209
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->get_unique_affix(), '' );
18210
+ $this->get_site()->{$site_property} = $site_property_value;
18211
+
18212
+ // Store account after modification.
18213
+ $this->_store_site();
18214
+
18215
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
18216
+
18217
+ $this->_admin_notices->add( sprintf(
18218
+ /* translators: %s: User's account property (e.g. email address, name) */
18219
+ $this->get_text_inline( 'You have successfully updated your %s.', 'x-updated' ),
18220
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>'
18221
+ ) );
18222
+
18223
+ return;
18224
+ }
18225
+ }
18226
+ }
18227
+ }
18228
+
18229
+ /**
18230
+ * Account page resources load.
18231
+ *
18232
+ * @author Vova Feldman (@svovaf)
18233
+ * @since 1.0.6
18234
+ */
18235
+ function _account_page_load() {
18236
+ $this->_logger->entrance();
18237
+
18238
+ $this->_logger->info( var_export( $_REQUEST, true ) );
18239
+
18240
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
18241
+
18242
+ if ( $this->has_addons() ) {
18243
+ wp_enqueue_script( 'plugin-install' );
18244
+ add_thickbox();
18245
+
18246
+ function fs_addons_body_class( $classes ) {
18247
+ $classes .= ' plugins-php';
18248
+
18249
+ return $classes;
18250
+ }
18251
+
18252
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
18253
+ }
18254
+
18255
+ if ( $this->has_paid_plan() &&
18256
+ ! $this->has_any_license() &&
18257
+ ! $this->is_sync_executed() &&
18258
+ $this->is_tracking_allowed()
18259
+ ) {
18260
+ /**
18261
+ * If no licenses found and no sync job was executed during the last 24 hours,
18262
+ * just execute the sync job right away (blocking execution).
18263
+ *
18264
+ * @since 1.1.7.3
18265
+ */
18266
+ $this->run_manual_sync();
18267
+ }
18268
+
18269
+ $this->_handle_account_edits();
18270
+
18271
+ $this->do_action( 'account_page_load_before_departure' );
18272
+ }
18273
+
18274
+ /**
18275
+ * Renders the "Affiliation" page.
18276
+ *
18277
+ * @author Leo Fajardo (@leorw)
18278
+ * @since 1.2.3
18279
+ */
18280
+ function _affiliation_page_render() {
18281
+ $this->_logger->entrance();
18282
+
18283
+ $this->fetch_affiliate_and_terms();
18284
+
18285
+ fs_enqueue_local_style( 'fs_affiliation', '/admin/affiliation.css' );
18286
+
18287
+ $vars = array( 'id' => $this->_module_id );
18288
+ echo $this->apply_filters( "/forms/affiliation.php", fs_get_template( '/forms/affiliation.php', $vars ) );
18289
+ }
18290
+
18291
+
18292
+ /**
18293
+ * Render account page.
18294
+ *
18295
+ * @author Vova Feldman (@svovaf)
18296
+ * @since 1.0.0
18297
+ */
18298
+ function _account_page_render() {
18299
+ $this->_logger->entrance();
18300
+
18301
+ $template = 'account.php';
18302
+ $vars = array( 'id' => $this->_module_id );
18303
+
18304
+ /**
18305
+ * Added filter to the template to allow developers wrapping the template
18306
+ * in custom HTML (e.g. within a wizard/tabs).
18307
+ *
18308
+ * @author Vova Feldman (@svovaf)
18309
+ * @since 1.2.1.6
18310
+ */
18311
+ echo $this->apply_filters( "templates/{$template}", fs_get_template( $template, $vars ) );
18312
+ }
18313
+
18314
+ /**
18315
+ * Render account connect page.
18316
+ *
18317
+ * @author Vova Feldman (@svovaf)
18318
+ * @since 1.0.7
18319
+ */
18320
+ function _connect_page_render() {
18321
+ $this->_logger->entrance();
18322
+
18323
+ $vars = array( 'id' => $this->_module_id );
18324
+
18325
+ /**
18326
+ * Added filter to the template to allow developers wrapping the template
18327
+ * in custom HTML (e.g. within a wizard/tabs).
18328
+ *
18329
+ * @author Vova Feldman (@svovaf)
18330
+ * @since 1.2.1.6
18331
+ */
18332
+ echo $this->apply_filters( 'templates/connect.php', fs_get_template( 'connect.php', $vars ) );
18333
+ }
18334
+
18335
+ /**
18336
+ * Load required resources before add-ons page render.
18337
+ *
18338
+ * @author Vova Feldman (@svovaf)
18339
+ * @since 1.0.6
18340
+ */
18341
+ function _addons_page_load() {
18342
+ $this->_logger->entrance();
18343
+
18344
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
18345
+
18346
+ wp_enqueue_script( 'plugin-install' );
18347
+ add_thickbox();
18348
+
18349
+ function fs_addons_body_class( $classes ) {
18350
+ $classes .= ' plugins-php';
18351
+
18352
+ return $classes;
18353
+ }
18354
+
18355
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
18356
+
18357
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
18358
+ $this->_admin_notices->add(
18359
+ sprintf( $this->get_text_inline( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'addons-info-external-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
18360
+ $this->get_text_x_inline( 'Heads up', 'advance notice of something that will need attention.', 'heads-up' ),
18361
+ 'update-nag'
18362
+ );
18363
+ }
18364
+ }
18365
+
18366
+ /**
18367
+ * Render add-ons page.
18368
+ *
18369
+ * @author Vova Feldman (@svovaf)
18370
+ * @since 1.0.6
18371
+ */
18372
+ function _addons_page_render() {
18373
+ $this->_logger->entrance();
18374
+
18375
+ $vars = array( 'id' => $this->_module_id );
18376
+
18377
+ /**
18378
+ * Added filter to the template to allow developers wrapping the template
18379
+ * in custom HTML (e.g. within a wizard/tabs).
18380
+ *
18381
+ * @author Vova Feldman (@svovaf)
18382
+ * @since 1.2.1.6
18383
+ */
18384
+ echo $this->apply_filters( 'templates/add-ons.php', fs_get_template( 'add-ons.php', $vars ) );
18385
+ }
18386
+
18387
+ /* Pricing & Upgrade
18388
+ ------------------------------------------------------------------------------------------------------------------*/
18389
+ /**
18390
+ * Render pricing page.
18391
+ *
18392
+ * @author Vova Feldman (@svovaf)
18393
+ * @since 1.0.0
18394
+ */
18395
+ function _pricing_page_render() {
18396
+ $this->_logger->entrance();
18397
+
18398
+ $vars = array( 'id' => $this->_module_id );
18399
+
18400
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
18401
+ fs_require_once_template( 'checkout.php', $vars );
18402
+ } else {
18403
+ fs_require_once_template( 'pricing.php', $vars );
18404
+ }
18405
+ }
18406
+
18407
+ #----------------------------------------------------------------------------------
18408
+ #region Contact Us
18409
+ #----------------------------------------------------------------------------------
18410
+
18411
+ /**
18412
+ * Render contact-us page.
18413
+ *
18414
+ * @author Vova Feldman (@svovaf)
18415
+ * @since 1.0.3
18416
+ */
18417
+ function _contact_page_render() {
18418
+ $this->_logger->entrance();
18419
+
18420
+ $vars = array( 'id' => $this->_module_id );
18421
+ fs_require_once_template( 'contact.php', $vars );
18422
+ }
18423
+
18424
+ #endregion ------------------------------------------------------------------------
18425
+
18426
+ /**
18427
+ * Hide all admin notices to prevent distractions.
18428
+ *
18429
+ * @author Vova Feldman (@svovaf)
18430
+ * @since 1.0.3
18431
+ *
18432
+ * @uses remove_all_actions()
18433
+ */
18434
+ private static function _hide_admin_notices() {
18435
+ remove_all_actions( 'admin_notices' );
18436
+ remove_all_actions( 'network_admin_notices' );
18437
+ remove_all_actions( 'all_admin_notices' );
18438
+ remove_all_actions( 'user_admin_notices' );
18439
+ }
18440
+
18441
+ static function _clean_admin_content_section_hook() {
18442
+ self::_hide_admin_notices();
18443
+
18444
+ // Hide footer.
18445
+ echo '<style>#wpfooter { display: none !important; }</style>';
18446
+ }
18447
+
18448
+ /**
18449
+ * Attach to admin_head hook to hide all admin notices.
18450
+ *
18451
+ * @author Vova Feldman (@svovaf)
18452
+ * @since 1.0.3
18453
+ */
18454
+ static function _clean_admin_content_section() {
18455
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
18456
+ }
18457
+
18458
+ /* CSS & JavaScript
18459
+ ------------------------------------------------------------------------------------------------------------------*/
18460
+ /* function _enqueue_script($handle, $src) {
18461
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
18462
+
18463
+ $this->_logger->entrance( 'script = ' . $url );
18464
+
18465
+ wp_enqueue_script( $handle, $url );
18466
+ }*/
18467
+
18468
+ /* SDK
18469
+ ------------------------------------------------------------------------------------------------------------------*/
18470
+ private $_user_api;
18471
+
18472
+ /**
18473
+ *
18474
+ * @author Vova Feldman (@svovaf)
18475
+ * @since 1.0.2
18476
+ *
18477
+ * @param bool $flush
18478
+ *
18479
+ * @return FS_Api
18480
+ */
18481
+ private function get_api_user_scope( $flush = false ) {
18482
+ if ( ! isset( $this->_user_api ) || $flush ) {
18483
+ $this->_user_api = $this->get_api_user_scope_by_user( $this->_user );
18484
+ }
18485
+
18486
+ return $this->_user_api;
18487
+ }
18488
+
18489
+ /**
18490
+ * @author Vova Feldman (@svovaf)
18491
+ * @since 2.0.0
18492
+ *
18493
+ * @param \FS_User $user
18494
+ *
18495
+ * @return \FS_Api
18496
+ */
18497
+ private function get_api_user_scope_by_user( FS_User $user ) {
18498
+ return FS_Api::instance(
18499
+ $this->_module_id,
18500
+ 'user',
18501
+ $user->id,
18502
+ $user->public_key,
18503
+ ! $this->is_live(),
18504
+ $user->secret_key
18505
+ );
18506
+ }
18507
+
18508
+ /**
18509
+ *
18510
+ * @author Leo Fajardo (@leorw)
18511
+ * @since 2.0.0
18512
+ *
18513
+ * @param bool $flush
18514
+ *
18515
+ * @return FS_Api
18516
+ */
18517
+ private function get_current_or_network_user_api_scope( $flush = false ) {
18518
+ if ( ! $this->_is_network_active || isset( $this->_user ) ) {
18519
+ return $this->get_api_user_scope( $flush );
18520
+ }
18521
+
18522
+ $user = $this->get_current_or_network_user();
18523
+
18524
+ $this->_user_api = FS_Api::instance(
18525
+ $this->_module_id,
18526
+ 'user',
18527
+ $user->id,
18528
+ $user->public_key,
18529
+ ! $this->is_live(),
18530
+ $user->secret_key
18531
+ );
18532
+
18533
+ return $this->_user_api;
18534
+ }
18535
+
18536
+ private $_site_api;
18537
+
18538
+ /**
18539
+ *
18540
+ * @author Vova Feldman (@svovaf)
18541
+ * @since 1.0.2
18542
+ *
18543
+ * @param bool $flush
18544
+ *
18545
+ * @return FS_Api
18546
+ */
18547
+ private function get_api_site_scope( $flush = false ) {
18548
+ if ( ! isset( $this->_site_api ) || $flush ) {
18549
+ $this->_site_api = FS_Api::instance(
18550
+ $this->_module_id,
18551
+ 'install',
18552
+ $this->_site->id,
18553
+ $this->_site->public_key,
18554
+ ! $this->is_live(),
18555
+ $this->_site->secret_key
18556
+ );
18557
+ }
18558
+
18559
+ return $this->_site_api;
18560
+ }
18561
+
18562
+ private $_plugin_api;
18563
+
18564
+ /**
18565
+ * Get plugin public API scope.
18566
+ *
18567
+ * @author Vova Feldman (@svovaf)
18568
+ * @since 1.0.7
18569
+ *
18570
+ * @return FS_Api
18571
+ */
18572
+ function get_api_plugin_scope() {
18573
+ if ( ! isset( $this->_plugin_api ) ) {
18574
+ $this->_plugin_api = FS_Api::instance(
18575
+ $this->_module_id,
18576
+ 'plugin',
18577
+ $this->_plugin->id,
18578
+ $this->_plugin->public_key,
18579
+ ! $this->is_live()
18580
+ );
18581
+ }
18582
+
18583
+ return $this->_plugin_api;
18584
+ }
18585
+
18586
+ /**
18587
+ * Get site API scope object (fallback to public plugin scope when not registered).
18588
+ *
18589
+ * @author Vova Feldman (@svovaf)
18590
+ * @since 1.0.7
18591
+ *
18592
+ * @return FS_Api
18593
+ */
18594
+ function get_api_site_or_plugin_scope() {
18595
+ return $this->is_registered() ?
18596
+ $this->get_api_site_scope() :
18597
+ $this->get_api_plugin_scope();
18598
+ }
18599
+
18600
+ /**
18601
+ * Show trial promotional notice (if any trial exist).
18602
+ *
18603
+ * @author Vova Feldman (@svovaf)
18604
+ * @since 1.0.9
18605
+ *
18606
+ * @param $plans
18607
+ */
18608
+ function _check_for_trial_plans( $plans ) {
18609
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
18610
+ }
18611
+
18612
+ /**
18613
+ * During trial promotion the "upgrade" submenu item turns to
18614
+ * "start trial" to encourage the trial. Since we want to keep
18615
+ * the same menu item handler and there's no robust way to
18616
+ * add new arguments to the menu item link's querystring,
18617
+ * use JavaScript to find the menu item and update the href of
18618
+ * the link.
18619
+ *
18620
+ * @author Vova Feldman (@svovaf)
18621
+ * @since 1.2.1.5
18622
+ */
18623
+ function _fix_start_trial_menu_item_url() {
18624
+ $template_args = array( 'id' => $this->_module_id );
18625
+ fs_require_template( 'add-trial-to-pricing.php', $template_args );
18626
+ }
18627
+
18628
+ /**
18629
+ * Check if module is currently in a trial promotion mode.
18630
+ *
18631
+ * @author Vova Feldman (@svovaf)
18632
+ * @since 1.2.2.7
18633
+ *
18634
+ * @return bool
18635
+ */
18636
+ function is_in_trial_promotion() {
18637
+ return $this->_admin_notices->has_sticky( 'trial_promotion' );
18638
+ }
18639
+
18640
+ /**
18641
+ * Show trial promotional notice (if any trial exist).
18642
+ *
18643
+ * @author Vova Feldman (@svovaf)
18644
+ * @since 1.0.9
18645
+ *
18646
+ * @return bool If trial notice added.
18647
+ */
18648
+ function _add_trial_notice() {
18649
+ if ( ! $this->is_user_admin() ) {
18650
+ return false;
18651
+ }
18652
+
18653
+ if ( ! $this->is_user_in_admin() ) {
18654
+ return false;
18655
+ }
18656
+
18657
+ if ( $this->_is_network_active ) {
18658
+ if ( fs_is_network_admin() ) {
18659
+ // Network level trial is disabled at the moment.
18660
+ return false;
18661
+ }
18662
+
18663
+ if ( ! $this->is_delegated_connection() ) {
18664
+ // Only delegated sites should support trials.
18665
+ return false;
18666
+ }
18667
+ }
18668
+
18669
+ // Check if trial message is already shown.
18670
+ if ( $this->is_in_trial_promotion() ) {
18671
+ add_action( 'admin_footer', array( &$this, '_fix_start_trial_menu_item_url' ) );
18672
+
18673
+ $this->_menu->add_counter_to_menu_item( 1, 'fs-trial' );
18674
+
18675
+ return false;
18676
+ }
18677
+
18678
+ if ( $this->is_premium() && ! WP_FS__DEV_MODE ) {
18679
+ // Don't show trial if running the premium code, unless running in DEV mode.
18680
+ return false;
18681
+ }
18682
+
18683
+ if ( ! $this->has_trial_plan() ) {
18684
+ // No plans with trial.
18685
+ return false;
18686
+ }
18687
+
18688
+ if ( ! $this->apply_filters( 'show_trial', true ) ) {
18689
+ // Developer explicitly asked not to show the trial promo.
18690
+ return false;
18691
+ }
18692
+
18693
+ if ( $this->is_registered() ) {
18694
+ // Check if trial already utilized.
18695
+ if ( $this->_site->is_trial_utilized() ) {
18696
+ return false;
18697
+ }
18698
+
18699
+ if ( $this->is_paying_or_trial() ) {
18700
+ // Don't show trial if paying or already in trial.
18701
+ return false;
18702
+ }
18703
+ }
18704
+
18705
+ if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
18706
+ // If not yet opted-in/skipped, or pending activation, don't show trial.
18707
+ return false;
18708
+ }
18709
+
18710
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
18711
+ $was_promotion_shown_before = ( false !== $last_time_trial_promotion_shown );
18712
+
18713
+ // Show promotion if never shown before and 24 hours after initial activation with FS.
18714
+ if ( ! $was_promotion_shown_before &&
18715
+ $this->_storage->install_timestamp > ( time() - WP_FS__TIME_24_HOURS_IN_SEC )
18716
+ ) {
18717
+ return false;
18718
+ }
18719
+
18720
+ // OR if promotion was shown before, try showing it every 30 days.
18721
+ if ( $was_promotion_shown_before &&
18722
+ 30 * WP_FS__TIME_24_HOURS_IN_SEC > time() - $last_time_trial_promotion_shown
18723
+ ) {
18724
+ return false;
18725
+ }
18726
+
18727
+ $trial_period = $this->_trial_days;
18728
+ $require_payment = $this->_is_trial_require_payment;
18729
+ $trial_url = $this->get_trial_url();
18730
+ $plans_string = strtolower( $this->get_text_inline( 'Awesome', 'awesome' ) );
18731
+
18732
+ if ( $this->is_registered() ) {
18733
+ // If opted-in, override trial with up to date data from API.
18734
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
18735
+ $trial_plans_count = count( $trial_plans );
18736
+
18737
+ if ( 0 === $trial_plans_count ) {
18738
+ // If there's no plans with a trial just exit.
18739
+ return false;
18740
+ }
18741
+
18742
+ /**
18743
+ * @var FS_Plugin_Plan $paid_plan
18744
+ */
18745
+ $paid_plan = $trial_plans[0];
18746
+ $require_payment = $paid_plan->is_require_subscription;
18747
+ $trial_period = $paid_plan->trial_period;
18748
+
18749
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
18750
+
18751
+ if ( $total_paid_plans !== $trial_plans_count ) {
18752
+ // Not all paid plans have a trial - generate a string of those that have it.
18753
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
18754
+ $plans_string .= sprintf(
18755
+ ' <a href="%s">%s</a>',
18756
+ $trial_url,
18757
+ $trial_plans[ $i ]->title
18758
+ );
18759
+
18760
+ if ( $i < $trial_plans_count - 2 ) {
18761
+ $plans_string .= ', ';
18762
+ } else if ( $i == $trial_plans_count - 2 ) {
18763
+ $plans_string .= ' and ';
18764
+ }
18765
+ }
18766
+ }
18767
+ }
18768
+
18769
+ $message = sprintf(
18770
+ $this->get_text_x_inline( 'Hey', 'exclamation', 'hey' ) . '! ' . $this->get_text_inline( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'trial-x-promotion-message' ),
18771
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
18772
+ $plans_string,
18773
+ $trial_period
18774
+ );
18775
+
18776
+ // "No Credit-Card Required" or "No Commitment for N Days".
18777
+ $cc_string = $require_payment ?
18778
+ sprintf( $this->get_text_inline( 'No commitment for %s days - cancel anytime!', 'no-commitment-for-x-days' ), $trial_period ) :
18779
+ $this->get_text_inline( 'No credit card required', 'no-cc-required' ) . '!';
18780
+
18781
+
18782
+ // Start trial button.
18783
+ $button = ' ' . sprintf(
18784
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
18785
+ $trial_url,
18786
+ $this->get_text_x_inline( 'Start free trial', 'call to action', 'start-free-trial' )
18787
+ );
18788
+
18789
+ $this->_admin_notices->add_sticky(
18790
+ $this->apply_filters( 'trial_promotion_message', "{$message} {$cc_string} {$button}" ),
18791
+ 'trial_promotion',
18792
+ '',
18793
+ 'promotion'
18794
+ );
18795
+
18796
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
18797
+
18798
+ return true;
18799
+ }
18800
+
18801
+ /**
18802
+ * Lets users/customers know that the product has an affiliate program.
18803
+ *
18804
+ * @author Leo Fajardo (@leorw)
18805
+ * @since 1.2.2.11
18806
+ *
18807
+ * @return bool Returns true if the notice has been added.
18808
+ */
18809
+ function _add_affiliate_program_notice() {
18810
+ if ( ! $this->is_user_admin() ) {
18811
+ return false;
18812
+ }
18813
+
18814
+ if ( ! $this->is_user_in_admin() ) {
18815
+ return false;
18816
+ }
18817
+
18818
+ // Check if the notice is already shown.
18819
+ if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
18820
+ return false;
18821
+ }
18822
+
18823
+ if (
18824
+ // Product has no affiliate program.
18825
+ ! $this->has_affiliate_program() ||
18826
+ // User has applied for an affiliate account.
18827
+ ! empty( $this->_storage->affiliate_application_data )
18828
+ ) {
18829
+ return false;
18830
+ }
18831
+
18832
+ if ( ! $this->apply_filters( 'show_affiliate_program_notice', true ) ) {
18833
+ // Developer explicitly asked not to show the notice about the affiliate program.
18834
+ return false;
18835
+ }
18836
+
18837
+ if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
18838
+ // If not yet opted in/skipped, or pending activation, don't show the notice.
18839
+ return false;
18840
+ }
18841
+
18842
+ $last_time_notice_was_shown = $this->_storage->get( 'affiliate_program_notice_shown', false );
18843
+ $was_notice_shown_before = ( false !== $last_time_notice_was_shown );
18844
+
18845
+ /**
18846
+ * Do not show the notice if it was already shown before or less than 30 days have passed since the initial
18847
+ * activation with FS.
18848
+ */
18849
+ if ( $was_notice_shown_before ||
18850
+ $this->_storage->install_timestamp > ( time() - ( WP_FS__TIME_24_HOURS_IN_SEC * 30 ) )
18851
+ ) {
18852
+ return false;
18853
+ }
18854
+
18855
+ if ( ! $this->is_paying() &&
18856
+ FS_Plugin::AFFILIATE_MODERATION_CUSTOMERS == $this->_plugin->affiliate_moderation
18857
+ ) {
18858
+ // If the user is not a customer and the affiliate program is only for customers, don't show the notice.
18859
+ return false;
18860
+ }
18861
+
18862
+ $message = sprintf(
18863
+ $this->get_text_inline( 'Hey there, did you know that %s has an affiliate program? If you like the %s you can become our ambassador and earn some cash!', 'become-an-ambassador-admin-notice' ),
18864
+ sprintf( '<strong>%s</strong>', $this->get_plugin_name() ),
18865
+ $this->get_module_label( true )
18866
+ );
18867
+
18868
+ // HTML code for the "Learn more..." button.
18869
+ $button = ' ' . sprintf(
18870
+ '<a style="display: block; margin-top: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
18871
+ $this->_get_admin_page_url( 'affiliation' ),
18872
+ $this->get_text_inline( 'Learn more', 'learn-more' ) . '...'
18873
+ );
18874
+
18875
+ $this->_admin_notices->add_sticky(
18876
+ $this->apply_filters( 'affiliate_program_notice', "{$message} {$button}" ),
18877
+ 'affiliate_program',
18878
+ '',
18879
+ 'promotion'
18880
+ );
18881
+
18882
+ $this->_storage->affiliate_program_notice_shown = WP_FS__SCRIPT_START_TIME;
18883
+
18884
+ return true;
18885
+ }
18886
+
18887
+ /**
18888
+ * @author Vova Feldman (@svovaf)
18889
+ * @since 1.2.1.5
18890
+ */
18891
+ function _enqueue_common_css() {
18892
+ if ( $this->has_paid_plan() && ! $this->is_paying() ) {
18893
+ // Add basic CSS for admin-notices and menu-item colors.
18894
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
18895
+ }
18896
+ }
18897
+
18898
+ /**
18899
+ * @author Leo Fajardo (@leorw)
18900
+ * @since 1.2.2
18901
+ */
18902
+ function _show_theme_activation_optin_dialog() {
18903
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
18904
+
18905
+ add_action( 'admin_footer-themes.php', array( &$this, '_add_fs_theme_activation_dialog' ) );
18906
+ }
18907
+
18908
+ /**
18909
+ * @author Leo Fajardo (@leorw)
18910
+ * @since 1.2.2
18911
+ */
18912
+ function _add_fs_theme_activation_dialog() {
18913
+ $vars = array( 'id' => $this->_module_id );
18914
+ fs_require_once_template( 'connect.php', $vars );
18915
+ }
18916
+
18917
+ /* Action Links
18918
+ ------------------------------------------------------------------------------------------------------------------*/
18919
+ private $_action_links_hooked = false;
18920
+ private $_action_links = array();
18921
+
18922
+ /**
18923
+ * Hook to plugin action links filter.
18924
+ *
18925
+ * @author Vova Feldman (@svovaf)
18926
+ * @since 1.0.0
18927
+ */
18928
+ private function hook_plugin_action_links() {
18929
+ $this->_logger->entrance();
18930
+
18931
+ $this->_action_links_hooked = true;
18932
+
18933
+ $this->_logger->log( 'Adding action links hooks.' );
18934
+
18935
+ // Add action link to settings page.
18936
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
18937
+ &$this,
18938
+ '_modify_plugin_action_links_hook'
18939
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
18940
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
18941
+ &$this,
18942
+ '_modify_plugin_action_links_hook'
18943
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
18944
+ }
18945
+
18946
+ /**
18947
+ * Add plugin action link.
18948
+ *
18949
+ * @author Vova Feldman (@svovaf)
18950
+ * @since 1.0.0
18951
+ *
18952
+ * @param $label
18953
+ * @param $url
18954
+ * @param bool $external
18955
+ * @param int $priority
18956
+ * @param bool $key
18957
+ */
18958
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
18959
+ $this->_logger->entrance();
18960
+
18961
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
18962
+ $this->_action_links[ $priority ] = array();
18963
+ }
18964
+
18965
+ if ( false === $key ) {
18966
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
18967
+ }
18968
+
18969
+ $this->_action_links[ $priority ][] = array(
18970
+ 'label' => $label,
18971
+ 'href' => $url,
18972
+ 'key' => $key,
18973
+ 'external' => $external
18974
+ );
18975
+ }
18976
+
18977
+ /**
18978
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
18979
+ *
18980
+ * @author Vova Feldman (@svovaf)
18981
+ * @since 1.0.0
18982
+ */
18983
+ function _add_upgrade_action_link() {
18984
+ $this->_logger->entrance();
18985
+
18986
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
18987
+ $this->add_plugin_action_link(
18988
+ $this->get_text_inline( 'Upgrade', 'upgrade' ),
18989
+ $this->get_upgrade_url(),
18990
+ false,
18991
+ 7,
18992
+ 'upgrade'
18993
+ );
18994
+ }
18995
+
18996
+ if ( $this->has_addons() ) {
18997
+ $this->add_plugin_action_link(
18998
+ $this->get_text_inline( 'Add-Ons', 'add-ons' ),
18999
+ $this->_get_admin_page_url( 'addons' ),
19000
+ false,
19001
+ 9,
19002
+ 'addons'
19003
+ );
19004
+ }
19005
+ }
19006
+
19007
+ /**
19008
+ * Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
19009
+ *
19010
+ * @author Leo Fajardo (@leorw)
19011
+ * @since 1.1.9
19012
+ */
19013
+ function _add_license_action_link() {
19014
+ $this->_logger->entrance();
19015
+
19016
+ if ( ! self::is_ajax() ) {
19017
+ // Inject license activation dialog UI and client side code.
19018
+ add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
19019
+ }
19020
+
19021
+ $link_text = $this->is_free_plan() ?
19022
+ $this->get_text_inline( 'Activate License', 'activate-license' ) :
19023
+ $this->get_text_inline( 'Change License', 'change-license' );
19024
+
19025
+ $this->add_plugin_action_link(
19026
+ $link_text,
19027
+ '#',
19028
+ false,
19029
+ 11,
19030
+ ( 'activate-license ' . $this->get_unique_affix() )
19031
+ );
19032
+ }
19033
+
19034
+ /**
19035
+ * @author Leo Fajardo (@leorw)
19036
+ * @since 2.0.2
19037
+ */
19038
+ function _add_premium_version_upgrade_selection_action() {
19039
+ $this->_logger->entrance();
19040
+
19041
+ if ( ! self::is_ajax() ) {
19042
+ add_action( 'admin_footer', array( &$this, '_add_premium_version_upgrade_selection_dialog_box' ) );
19043
+ }
19044
+ }
19045
+
19046
+ /**
19047
+ * Adds "Opt in" or "Opt out" link to the main "Plugins" page link actions collection.
19048
+ *
19049
+ * @author Leo Fajardo (@leorw)
19050
+ * @since 1.2.1.5
19051
+ */
19052
+ function _add_tracking_links() {
19053
+ if ( ! current_user_can( 'manage_options' ) ) {
19054
+ return;
19055
+ }
19056
+
19057
+ $this->_logger->entrance();
19058
+
19059
+ /**
19060
+ * If the activation has been delegated to site admins, no tracking-related actions for now.
19061
+ *
19062
+ * @author Leo Fajardo (@leorw)
19063
+ */
19064
+ if ( $this->_is_network_active && $this->is_network_delegated_connection() ) {
19065
+ return;
19066
+ }
19067
+
19068
+ if ( fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' ) ) {
19069
+ if ( ! $this->is_registered() && $this->is_anonymous() ) {
19070
+ $this->connect_again();
19071
+
19072
+ return;
19073
+ }
19074
+ }
19075
+
19076
+ if ( ( $this->is_plugin() && ! self::is_plugins_page() ) ||
19077
+ ( $this->is_theme() && ! self::is_themes_page() )
19078
+ ) {
19079
+ // Only show tracking links on the plugins and themes pages.
19080
+ return;
19081
+ }
19082
+
19083
+ if ( ! $this->is_enable_anonymous() ) {
19084
+ // Don't allow to opt-out if anonymous mode is disabled.
19085
+ return;
19086
+ }
19087
+
19088
+ if ( ! $this->is_free_plan() ) {
19089
+ // Don't allow to opt-out if running in paid plan.
19090
+ return;
19091
+ }
19092
+
19093
+ if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
19094
+ return;
19095
+ }
19096
+
19097
+ if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
19098
+ return;
19099
+ }
19100
+
19101
+ $url = '#';
19102
+
19103
+ if ( $this->is_registered() ) {
19104
+ if ( $this->is_tracking_allowed() ) {
19105
+ $link_text_id = $this->get_text_inline( 'Opt Out', 'opt-out' );
19106
+ } else {
19107
+ $link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
19108
+ }
19109
+
19110
+ add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
19111
+ } else {
19112
+ $link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
19113
+
19114
+ $params = ! $this->is_anonymous() ?
19115
+ array() :
19116
+ array(
19117
+ 'nonce' => wp_create_nonce( $this->get_unique_affix() . '_reconnect' ),
19118
+ 'fs_action' => ( $this->get_unique_affix() . '_reconnect' ),
19119
+ );
19120
+
19121
+ $url = $this->get_activation_url( $params );
19122
+ }
19123
+
19124
+ if ( $this->is_plugin() && self::is_plugins_page() ) {
19125
+ $this->add_plugin_action_link(
19126
+ $link_text_id,
19127
+ $url,
19128
+ false,
19129
+ 13,
19130
+ "opt-in-or-opt-out {$this->_slug}"
19131
+ );
19132
+ }
19133
+ }
19134
+
19135
+ /**
19136
+ * Get the URL of the page that should be loaded right after the plugin activation.
19137
+ *
19138
+ * @author Vova Feldman (@svovaf)
19139
+ * @since 1.1.7.4
19140
+ *
19141
+ * @return string
19142
+ */
19143
+ function get_after_plugin_activation_redirect_url() {
19144
+ $url = false;
19145
+
19146
+ if ( ! $this->is_addon() || ! $this->has_free_plan() ) {
19147
+ $first_time_path = $this->_menu->get_first_time_path();
19148
+ $url = $this->is_activation_mode() ?
19149
+ $this->get_activation_url() :
19150
+ ( empty( $first_time_path ) ?
19151
+ $this->_get_admin_page_url() :
19152
+ $first_time_path );
19153
+ } else {
19154
+ $plugin_fs = false;
19155
+
19156
+ if ( $this->is_parent_plugin_installed() ) {
19157
+ $plugin_fs = self::get_parent_instance();
19158
+ }
19159
+
19160
+ if ( is_object( $plugin_fs ) ) {
19161
+ if ( ! $plugin_fs->is_registered() ) {
19162
+ // Forward to parent plugin connect when parent not registered.
19163
+ $url = $plugin_fs->get_activation_url();
19164
+ } else {
19165
+ // Forward to account page.
19166
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
19167
+ }
19168
+ }
19169
+ }
19170
+
19171
+ return $url;
19172
+ }
19173
+
19174
+ /**
19175
+ * Forward page to activation page.
19176
+ *
19177
+ * @author Vova Feldman (@svovaf)
19178
+ * @since 1.0.3
19179
+ */
19180
+ function _redirect_on_activation_hook() {
19181
+ $url = $this->get_after_plugin_activation_redirect_url();
19182
+
19183
+ if ( is_string( $url ) ) {
19184
+ fs_redirect( $url );
19185
+ }
19186
+ }
19187
+
19188
+ /**
19189
+ * Modify plugin's page action links collection.
19190
+ *
19191
+ * @author Vova Feldman (@svovaf)
19192
+ * @since 1.0.0
19193
+ *
19194
+ * @param array $links
19195
+ * @param $file
19196
+ *
19197
+ * @return array
19198
+ */
19199
+ function _modify_plugin_action_links_hook( $links, $file ) {
19200
+ $this->_logger->entrance();
19201
+
19202
+ $passed_deactivate = false;
19203
+ $deactivate_link = '';
19204
+ $before_deactivate = array();
19205
+ $after_deactivate = array();
19206
+ foreach ( $links as $key => $link ) {
19207
+ if ( 'deactivate' === $key ) {
19208
+ $deactivate_link = $link;
19209
+ $passed_deactivate = true;
19210
+ continue;
19211
+ }
19212
+
19213
+ if ( ! $passed_deactivate ) {
19214
+ $before_deactivate[ $key ] = $link;
19215
+ } else {
19216
+ $after_deactivate[ $key ] = $link;
19217
+ }
19218
+ }
19219
+
19220
+ ksort( $this->_action_links );
19221
+
19222
+ foreach ( $this->_action_links as $new_links ) {
19223
+ foreach ( $new_links as $link ) {
19224
+ $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
19225
+ }
19226
+ }
19227
+
19228
+ if ( ! empty( $deactivate_link ) ) {
19229
+ /**
19230
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
19231
+ *
19232
+ * @since 1.2.1.6 Always show the deactivation feedback form since we added automatic free version deactivation upon premium code activation.
19233
+ */
19234
+ $deactivate_link .= '<i class="fs-module-id" data-module-id="' . $this->_module_id . '"></i>';
19235
+
19236
+ // Append deactivation link.
19237
+ $before_deactivate['deactivate'] = $deactivate_link;
19238
+ }
19239
+
19240
+ return array_merge( $before_deactivate, $after_deactivate );
19241
+ }
19242
+
19243
+ /**
19244
+ * Adds admin message.
19245
+ *
19246
+ * @author Vova Feldman (@svovaf)
19247
+ * @since 1.0.4
19248
+ *
19249
+ * @param string $message
19250
+ * @param string $title
19251
+ * @param string $type
19252
+ */
19253
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
19254
+ $this->_admin_notices->add( $message, $title, $type );
19255
+ }
19256
+
19257
+ /**
19258
+ * Adds sticky admin message.
19259
+ *
19260
+ * @author Vova Feldman (@svovaf)
19261
+ * @since 1.1.0
19262
+ *
19263
+ * @param string $message
19264
+ * @param string $id
19265
+ * @param string $title
19266
+ * @param string $type
19267
+ */
19268
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
19269
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
19270
+ }
19271
+
19272
+ /**
19273
+ * Helper function that returns the final steps for the upgrade completion.
19274
+ *
19275
+ * If the module is already running the premium code, returns an empty string.
19276
+ *
19277
+ * @author Vova Feldman (@svovaf)
19278
+ * @since 1.2.1
19279
+ *
19280
+ * @param string $plan_title
19281
+ *
19282
+ * @return string
19283
+ */
19284
+ private function get_complete_upgrade_instructions( $plan_title = '' ) {
19285
+ $this->_logger->entrance();
19286
+
19287
+ $activate_license_string = $this->get_license_network_activation_notice();
19288
+
19289
+ if ( ! $this->has_premium_version() || $this->is_premium() ) {
19290
+ return '' . $activate_license_string;
19291
+ }
19292
+
19293
+ if ( empty( $plan_title ) ) {
19294
+ $plan_title = $this->get_plan_title();
19295
+ }
19296
+
19297
+ // @since 1.2.1.5 The free version is auto deactivated.
19298
+ $deactivation_step = version_compare( $this->version, '1.2.1.5', '<' ) ?
19299
+ ( '<li>' . $this->esc_html_inline( 'Deactivate the free version', 'deactivate-free-version' ) . '.</li>' ) :
19300
+ '';
19301
+
19302
+ return sprintf(
19303
+ ' %s: <ol><li>%s.</li>%s<li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
19304
+ $this->get_text_inline( 'Please follow these steps to complete the upgrade', 'follow-steps-to-complete-upgrade' ),
19305
+ ( empty( $activate_license_string ) ? '' : $activate_license_string . '</li><li>' ) .
19306
+ $this->get_latest_download_link( sprintf(
19307
+ /* translators: %s: Plan title */
19308
+ $this->get_text_inline( 'Download the latest %s version', 'download-latest-x-version' ),
19309
+ $plan_title
19310
+ ) ),
19311
+ $deactivation_step,
19312
+ $this->get_text_inline( 'Upload and activate the downloaded version', 'upload-and-activate' ),
19313
+ '//bit.ly/upload-wp-' . $this->_module_type . 's',
19314
+ $this->get_text_inline( 'How to upload and activate?', 'howto-upload-activate' )
19315
+ );
19316
+ }
19317
+
19318
+ /**
19319
+ * @author Leo Fajardo (@leorw)
19320
+ * @since 2.1.0
19321
+ *
19322
+ * @param string $url
19323
+ * @param array $request
19324
+ */
19325
+ private static function enrich_request_for_debug( &$url, &$request ) {
19326
+ if ( WP_FS__DEBUG_SDK || isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
19327
+ $url = add_query_arg( 'XDEBUG_SESSION_START', rand( 0, 9999999 ), $url );
19328
+ $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
19329
+
19330
+ $request['cookies'] = array(
19331
+ new WP_Http_Cookie( array(
19332
+ 'name' => 'XDEBUG_SESSION',
19333
+ 'value' => 'PHPSTORM',
19334
+ ) )
19335
+ );
19336
+ }
19337
+ }
19338
+
19339
+ /**
19340
+ * @author Leo Fajardo (@leorw)
19341
+ * @since 2.1.0
19342
+ *
19343
+ * @param string $url
19344
+ * @param array $request
19345
+ * @param int $success_cache_expiration
19346
+ * @param int $failure_cache_expiration
19347
+ *
19348
+ * @return WP_Error|array
19349
+ */
19350
+ private static function safe_remote_post(
19351
+ &$url,
19352
+ $request,
19353
+ $success_cache_expiration = 0,
19354
+ $failure_cache_expiration = 0
19355
+ ) {
19356
+ $should_cache = ($success_cache_expiration + $failure_cache_expiration > 0);
19357
+
19358
+ $cache_key = $should_cache ? md5( fs_strip_url_protocol($url) . json_encode( $request ) ) : false;
19359
+
19360
+ $response = (!WP_FS__DEBUG_SDK && ( false !== $cache_key )) ?
19361
+ get_transient( $cache_key ) :
19362
+ false;
19363
+
19364
+ if ( false === $response ) {
19365
+ self::enrich_request_for_debug( $url, $request );
19366
+
19367
+ $response = wp_remote_post( $url, $request );
19368
+
19369
+ if ( $response instanceof WP_Error ) {
19370
+ if ( 'https://' === substr( $url, 0, 8 ) &&
19371
+ isset( $response->errors ) &&
19372
+ isset( $response->errors['http_request_failed'] )
19373
+ ) {
19374
+ $http_error = strtolower( $response->errors['http_request_failed'][0] );
19375
+
19376
+ if ( false !== strpos( $http_error, 'ssl' ) ||
19377
+ false !== strpos( $http_error, 'curl error 35' )
19378
+ ) {
19379
+ // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
19380
+ $url = 'http://' . substr( $url, 8 );
19381
+
19382
+ $request['timeout'] = 15;
19383
+ $response = wp_remote_post( $url, $request );
19384
+ }
19385
+ }
19386
+ }
19387
+
19388
+ if ( false !== $cache_key ) {
19389
+ set_transient(
19390
+ $cache_key,
19391
+ $response,
19392
+ ( ( $response instanceof WP_Error ) ?
19393
+ $failure_cache_expiration :
19394
+ $success_cache_expiration )
19395
+ );
19396
+ }
19397
+ }
19398
+
19399
+ return $response;
19400
+ }
19401
+
19402
+ /**
19403
+ * This method is used to enrich the after upgrade notice instructions when the upgraded
19404
+ * license cannot be activated network wide (license quota isn't large enough).
19405
+ *
19406
+ * @author Vova Feldman (@svovaf)
19407
+ * @since 2.0.0
19408
+ *
19409
+ * @return string
19410
+ */
19411
+ private function get_license_network_activation_notice() {
19412
+ if ( ! $this->_is_network_active ) {
19413
+ // Module isn't network level activated.
19414
+ return '';
19415
+ }
19416
+
19417
+ if ( ! fs_is_network_admin() ) {
19418
+ // Not network level admin.
19419
+ return '';
19420
+ }
19421
+
19422
+ if ( get_blog_count() == 1 ) {
19423
+ // There's only a single site in the network so if there's a context license it was already activated.
19424
+ return '';
19425
+ }
19426
+
19427
+ if ( ! is_object( $this->_license ) ) {
19428
+ // No context license.
19429
+ return '';
19430
+ }
19431
+
19432
+ if ( $this->_license->is_single_site() && 0 < $this->_license->activated ) {
19433
+ // License was already utilized (this is not 100% the case if all the network is localhost sites and the license can be utilized on unlimited localhost sites).
19434
+ return '';
19435
+ }
19436
+
19437
+ if ( $this->can_activate_license_on_network( $this->_license ) ) {
19438
+ // License can be activated on all the network, so probably, the license is already activate on all the network (that's how the after upgrade sync works).
19439
+ return '';
19440
+ }
19441
+
19442
+ return sprintf(
19443
+ $this->get_text_inline( '%sClick here%s to choose the sites where you\'d like to activate the license on.', 'network-choose-sites-for-license' ),
19444
+ '<a href="' . $this->get_account_url( false, array( 'activate_license' => 'true' ) ) . '">',
19445
+ '</a>'
19446
+ );
19447
+ }
19448
+
19449
+ /**
19450
+ * @author Vova Feldman (@svovaf)
19451
+ * @since 1.2.1.7
19452
+ *
19453
+ * @param string $key
19454
+ *
19455
+ * @return string
19456
+ */
19457
+ function get_text( $key ) {
19458
+ return fs_text( $key, $this->_slug );
19459
+ }
19460
+
19461
+ /**
19462
+ * @author Vova Feldman (@svovaf)
19463
+ * @since 1.2.3
19464
+ *
19465
+ * @param string $text Translatable string.
19466
+ * @param string $key String key for overrides.
19467
+ *
19468
+ * @return string
19469
+ */
19470
+ function get_text_inline( $text, $key = '' ) {
19471
+ return _fs_text_inline( $text, $key, $this->_slug );
19472
+ }
19473
+
19474
+ /**
19475
+ * @author Vova Feldman (@svovaf)
19476
+ * @since 1.2.3
19477
+ *
19478
+ * @param string $text Translatable string.
19479
+ * @param string $context Context information for the translators.
19480
+ * @param string $key String key for overrides.
19481
+ *
19482
+ * @return string
19483
+ */
19484
+ function get_text_x_inline( $text, $context, $key ) {
19485
+ return _fs_text_x_inline( $text, $context, $key, $this->_slug );
19486
+ }
19487
+
19488
+ /**
19489
+ * @author Vova Feldman (@svovaf)
19490
+ * @since 1.2.3
19491
+ *
19492
+ * @param string $text Translatable string.
19493
+ * @param string $key String key for overrides.
19494
+ *
19495
+ * @return string
19496
+ */
19497
+ function esc_html_inline( $text, $key ) {
19498
+ return esc_html( _fs_text_inline( $text, $key, $this->_slug ) );
19499
+ }
19500
+
19501
+ #----------------------------------------------------------------------------------
19502
+ #region Versioning
19503
+ #----------------------------------------------------------------------------------
19504
+
19505
+ /**
19506
+ * Check if Freemius in SDK upgrade mode.
19507
+ *
19508
+ * @author Vova Feldman (@svovaf)
19509
+ * @since 1.0.9
19510
+ *
19511
+ * @return bool
19512
+ */
19513
+ function is_sdk_upgrade_mode() {
19514
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
19515
+ $this->_storage->sdk_upgrade_mode :
19516
+ false;
19517
+ }
19518
+
19519
+ /**
19520
+ * Turn SDK upgrade mode off.
19521
+ *
19522
+ * @author Vova Feldman (@svovaf)
19523
+ * @since 1.0.9
19524
+ */
19525
+ function set_sdk_upgrade_complete() {
19526
+ $this->_storage->sdk_upgrade_mode = false;
19527
+ }
19528
+
19529
+ /**
19530
+ * Check if plugin upgrade mode.
19531
+ *
19532
+ * @author Vova Feldman (@svovaf)
19533
+ * @since 1.0.9
19534
+ *
19535
+ * @return bool
19536
+ */
19537
+ function is_plugin_upgrade_mode() {
19538
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
19539
+ $this->_storage->plugin_upgrade_mode :
19540
+ false;
19541
+ }
19542
+
19543
+ /**
19544
+ * Turn plugin upgrade mode off.
19545
+ *
19546
+ * @author Vova Feldman (@svovaf)
19547
+ * @since 1.0.9
19548
+ */
19549
+ function set_plugin_upgrade_complete() {
19550
+ $this->_storage->plugin_upgrade_mode = false;
19551
+ }
19552
+
19553
+ #endregion
19554
+
19555
+ #----------------------------------------------------------------------------------
19556
+ #region Permissions
19557
+ #----------------------------------------------------------------------------------
19558
+
19559
+ /**
19560
+ * Check if specific permission requested.
19561
+ *
19562
+ * @author Vova Feldman (@svovaf)
19563
+ * @since 1.1.6
19564
+ *
19565
+ * @param string $permission
19566
+ *
19567
+ * @return bool
19568
+ */
19569
+ function is_permission_requested( $permission ) {
19570
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
19571
+ }
19572
+
19573
+ #endregion
19574
+
19575
+ #----------------------------------------------------------------------------------
19576
+ #region Auto Activation
19577
+ #----------------------------------------------------------------------------------
19578
+
19579
+ /**
19580
+ * Hints the SDK if running an auto-installation.
19581
+ *
19582
+ * @var bool
19583
+ */
19584
+ private $_isAutoInstall = false;
19585
+
19586
+ /**
19587
+ * After upgrade callback to install and auto activate a plugin.
19588
+ * This code will only be executed on explicit request from the user,
19589
+ * following the practice Jetpack are using with their theme installations.
19590
+ *
19591
+ * @link https://make.wordpress.org/plugins/2017/03/16/clarification-of-guideline-8-executable-code-and-installs/
19592
+ *
19593
+ * @author Vova Feldman (@svovaf)
19594
+ * @since 1.2.1.7
19595
+ */
19596
+ function _install_premium_version_ajax_action() {
19597
+ $this->_logger->entrance();
19598
+
19599
+ $this->check_ajax_referer( 'install_premium_version' );
19600
+
19601
+ if ( ! $this->is_registered() ) {
19602
+ // Not registered.
19603
+ self::shoot_ajax_failure( array(
19604
+ 'message' => $this->get_text_inline( 'Auto installation only works for opted-in users.', 'auto-install-error-not-opted-in' ),
19605
+ 'code' => 'premium_installed',
19606
+ ) );
19607
+ }
19608
+
19609
+ $plugin_id = fs_request_get( 'target_module_id', $this->get_id() );
19610
+
19611
+ if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
19612
+ // Invalid ID.
19613
+ self::shoot_ajax_failure( array(
19614
+ 'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
19615
+ 'code' => 'invalid_module_id',
19616
+ ) );
19617
+ }
19618
+
19619
+ if ( $plugin_id == $this->get_id() ) {
19620
+ if ( $this->is_premium() ) {
19621
+ // Already using the premium code version.
19622
+ self::shoot_ajax_failure( array(
19623
+ 'message' => $this->get_text_inline( 'Premium version already active.', 'auto-install-error-premium-activated' ),
19624
+ 'code' => 'premium_installed',
19625
+ ) );
19626
+ }
19627
+ if ( ! $this->can_use_premium_code() ) {
19628
+ // Don't have access to the premium code.
19629
+ self::shoot_ajax_failure( array(
19630
+ 'message' => $this->get_text_inline( 'You do not have a valid license to access the premium version.', 'auto-install-error-invalid-license' ),
19631
+ 'code' => 'invalid_license',
19632
+ ) );
19633
+ }
19634
+ if ( ! $this->has_release_on_freemius() ) {
19635
+ // Plugin is a serviceware, no premium code version.
19636
+ self::shoot_ajax_failure( array(
19637
+ 'message' => $this->get_text_inline( 'Plugin is a "Serviceware" which means it does not have a premium code version.', 'auto-install-error-serviceware' ),
19638
+ 'code' => 'premium_version_missing',
19639
+ ) );
19640
+ }
19641
+ } else {
19642
+ $addon = $this->get_addon( $plugin_id );
19643
+
19644
+ if ( ! is_object( $addon ) ) {
19645
+ // Invalid add-on ID.
19646
+ self::shoot_ajax_failure( array(
19647
+ 'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
19648
+ 'code' => 'invalid_module_id',
19649
+ ) );
19650
+ }
19651
+
19652
+ if ( $this->is_addon_activated( $plugin_id, true ) ) {
19653
+ // Premium add-on version is already activated.
19654
+ self::shoot_ajax_failure( array(
19655
+ 'message' => $this->get_text_inline( 'Premium add-on version already installed.', 'auto-install-error-premium-addon-activated' ),
19656
+ 'code' => 'premium_installed',
19657
+ ) );
19658
+ }
19659
+ }
19660
+
19661
+ $this->_isAutoInstall = true;
19662
+
19663
+ // Try to install and activate.
19664
+ $updater = FS_Plugin_Updater::instance( $this );
19665
+ $result = $updater->install_and_activate_plugin( $plugin_id );
19666
+
19667
+ if ( is_array( $result ) && ! empty( $result['message'] ) ) {
19668
+ self::shoot_ajax_failure( array(
19669
+ 'message' => $result['message'],
19670
+ 'code' => $result['code'],
19671
+ ) );
19672
+ }
19673
+
19674
+ self::shoot_ajax_success( $result );
19675
+ }
19676
+
19677
+ /**
19678
+ * Displays module activation dialog box after a successful upgrade
19679
+ * where the user explicitly requested to auto download and install
19680
+ * the premium version.
19681
+ *
19682
+ * @author Vova Feldman (@svovaf)
19683
+ * @since 1.2.1.7
19684
+ */
19685
+ function _add_auto_installation_dialog_box() {
19686
+ $this->_logger->entrance();
19687
+
19688
+ if ( ! $this->is_registered() ) {
19689
+ // Not registered.
19690
+ return;
19691
+ }
19692
+
19693
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
19694
+
19695
+ if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
19696
+ // Invalid module ID.
19697
+ return;
19698
+ }
19699
+
19700
+ if ( $plugin_id == $this->get_id() ) {
19701
+ if ( $this->is_premium() ) {
19702
+ // Already using the premium code version.
19703
+ return;
19704
+ }
19705
+ if ( ! $this->can_use_premium_code() ) {
19706
+ // Don't have access to the premium code.
19707
+ return;
19708
+ }
19709
+ if ( ! $this->has_release_on_freemius() ) {
19710
+ // Plugin is a serviceware, no premium code version.
19711
+ return;
19712
+ }
19713
+ } else {
19714
+ $addon = $this->get_addon( $plugin_id );
19715
+
19716
+ if ( ! is_object( $addon ) ) {
19717
+ // Invalid add-on ID.
19718
+ return;
19719
+ }
19720
+
19721
+ if ( $this->is_addon_activated( $plugin_id, true ) ) {
19722
+ // Premium add-on version is already activated.
19723
+ return;
19724
+ }
19725
+ }
19726
+
19727
+ $vars = array(
19728
+ 'id' => $this->_module_id,
19729
+ 'target_module_id' => $plugin_id,
19730
+ 'slug' => $this->_slug,
19731
+ );
19732
+
19733
+ fs_require_template( 'auto-installation.php', $vars );
19734
+ }
19735
+
19736
+ #endregion
19737
+
19738
+ #--------------------------------------------------------------------------------
19739
+ #region Tabs Integration
19740
+ #--------------------------------------------------------------------------------
19741
+
19742
+ #region Module's Original Tabs
19743
+
19744
+ /**
19745
+ * Inject a JavaScript logic to capture the theme tabs HTML.
19746
+ *
19747
+ * @author Vova Feldman (@svovaf)
19748
+ * @since 1.2.2.7
19749
+ */
19750
+ function _tabs_capture() {
19751
+ $this->_logger->entrance();
19752
+
19753
+ if ( ! $this->is_theme_settings_page() ||
19754
+ ! $this->is_matching_url( $this->main_menu_url() )
19755
+ ) {
19756
+ return;
19757
+ }
19758
+
19759
+ $params = array(
19760
+ 'id' => $this->_module_id,
19761
+ );
19762
+
19763
+ fs_require_once_template( 'tabs-capture-js.php', $params );
19764
+ }
19765
+
19766
+ /**
19767
+ * Cache theme's tabs HTML for a week. The cache will also be set as expired
19768
+ * after version and type (free/premium) changes, in addition to the week period.
19769
+ *
19770
+ * @author Vova Feldman (@svovaf)
19771
+ * @since 1.2.2.7
19772
+ */
19773
+ function _store_tabs_ajax_action() {
19774
+ $this->_logger->entrance();
19775
+
19776
+ $this->check_ajax_referer( 'store_tabs' );
19777
+
19778
+ // Init filesystem if not yet initiated.
19779
+ WP_Filesystem();
19780
+
19781
+ // Get POST body HTML data.
19782
+ global $wp_filesystem;
19783
+ $tabs_html = $wp_filesystem->get_contents( "php://input" );
19784
+
19785
+ if ( is_string( $tabs_html ) ) {
19786
+ $tabs_html = trim( $tabs_html );
19787
+ }
19788
+
19789
+ if ( ! is_string( $tabs_html ) || empty( $tabs_html ) ) {
19790
+ self::shoot_ajax_failure();
19791
+ }
19792
+
19793
+ $this->_cache->set( 'tabs', $tabs_html, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
19794
+
19795
+ self::shoot_ajax_success();
19796
+ }
19797
+
19798
+ /**
19799
+ * Cache theme's settings page custom styles. The cache will also be set as expired
19800
+ * after version and type (free/premium) changes, in addition to the week period.
19801
+ *
19802
+ * @author Vova Feldman (@svovaf)
19803
+ * @since 1.2.2.7
19804
+ */
19805
+ function _store_tabs_styles() {
19806
+ $this->_logger->entrance();
19807
+
19808
+ if ( ! $this->is_theme_settings_page() ||
19809
+ ! $this->is_matching_url( $this->main_menu_url() )
19810
+ ) {
19811
+ return;
19812
+ }
19813
+
19814
+ $wp_styles = wp_styles();
19815
+
19816
+ $theme_styles_url = get_template_directory_uri();
19817
+
19818
+ $stylesheets = array();
19819
+ foreach ( $wp_styles->queue as $handler ) {
19820
+ if ( fs_starts_with( $handler, 'fs_' ) ) {
19821
+ // Assume that stylesheets that their handler starts with "fs_" belong to the SDK.
19822
+ continue;
19823
+ }
19824
+
19825
+ /**
19826
+ * @var _WP_Dependency $stylesheet
19827
+ */
19828
+ $stylesheet = $wp_styles->registered[ $handler ];
19829
+
19830
+ if ( fs_starts_with( $stylesheet->src, $theme_styles_url ) ) {
19831
+ $stylesheets[] = $stylesheet->src;
19832
+ }
19833
+ }
19834
+
19835
+ if ( ! empty( $stylesheets ) ) {
19836
+ $this->_cache->set( 'tabs_stylesheets', $stylesheets, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
19837
+ }
19838
+ }
19839
+
19840
+ /**
19841
+ * Check if module's original settings page has any tabs.
19842
+ *
19843
+ * @author Vova Feldman (@svovaf)
19844
+ * @since 1.2.2.7
19845
+ *
19846
+ * @return bool
19847
+ */
19848
+ private function has_tabs() {
19849
+ return $this->_cache->has( 'tabs' );
19850
+ }
19851
+
19852
+ /**
19853
+ * Get module's settings page HTML content, starting
19854
+ * from the beginning of the <div class="wrap"> element,
19855
+ * until the tabs HTML (including).
19856
+ *
19857
+ * @author Vova Feldman (@svovaf)
19858
+ * @since 1.2.2.7
19859
+ *
19860
+ * @return string
19861
+ */
19862
+ private function get_tabs_html() {
19863
+ $this->_logger->entrance();
19864
+
19865
+ return $this->_cache->get( 'tabs' );
19866
+ }
19867
+
19868
+ /**
19869
+ * Check if page should include tabs.
19870
+ *
19871
+ * @author Vova Feldman (@svovaf)
19872
+ * @since 1.2.2.7
19873
+ *
19874
+ * @return bool
19875
+ */
19876
+ private function should_page_include_tabs() {
19877
+ if ( ! $this->has_settings_menu() ) {
19878
+ // Don't add tabs if no settings at all.
19879
+ return false;
19880
+ }
19881
+
19882
+ if ( ! $this->is_theme() ) {
19883
+ // Only add tabs to themes for now.
19884
+ return false;
19885
+ }
19886
+
19887
+ if ( ! $this->has_paid_plan() && ! $this->has_addons() ) {
19888
+ // Only add tabs to monetizing themes.
19889
+ return false;
19890
+ }
19891
+
19892
+ if ( ! $this->is_theme_settings_page() ) {
19893
+ // Only add tabs if browsing one of the theme's setting pages.
19894
+ return false;
19895
+ }
19896
+
19897
+ if ( $this->is_admin_page( 'pricing' ) && fs_request_get_bool( 'checkout' ) ) {
19898
+ // Don't add tabs on checkout page, we want to reduce distractions
19899
+ // as much as possible.
19900
+ return false;
19901
+ }
19902
+
19903
+ return true;
19904
+ }
19905
+
19906
+ /**
19907
+ * Add the tabs HTML before the setting's page content and
19908
+ * enqueue any required stylesheets.
19909
+ *
19910
+ * @author Vova Feldman (@svovaf)
19911
+ * @since 1.2.2.7
19912
+ *
19913
+ * @return bool If tabs were included.
19914
+ */
19915
+ function _add_tabs_before_content() {
19916
+ $this->_logger->entrance();
19917
+
19918
+ if ( ! $this->should_page_include_tabs() ) {
19919
+ return false;
19920
+ }
19921
+
19922
+ /**
19923
+ * Enqueue the original stylesheets that are included in the
19924
+ * theme settings page. That way, if the theme settings has
19925
+ * some custom _styled_ content above the tabs UI, this
19926
+ * will make sure that the styling is preserved.
19927
+ */
19928
+ $stylesheets = $this->_cache->get( 'tabs_stylesheets', array() );
19929
+ if ( is_array( $stylesheets ) ) {
19930
+ for ( $i = 0, $len = count( $stylesheets ); $i < $len; $i ++ ) {
19931
+ wp_enqueue_style( "fs_{$this->_module_id}_tabs_{$i}", $stylesheets[ $i ] );
19932
+ }
19933
+ }
19934
+
19935
+ // Cut closing </div> tag.
19936
+ echo substr( trim( $this->get_tabs_html() ), 0, - 6 );
19937
+
19938
+ return true;
19939
+ }
19940
+
19941
+ /**
19942
+ * Add the tabs closing HTML after the setting's page content.
19943
+ *
19944
+ * @author Vova Feldman (@svovaf)
19945
+ * @since 1.2.2.7
19946
+ *
19947
+ * @return bool If tabs closing HTML was included.
19948
+ */
19949
+ function _add_tabs_after_content() {
19950
+ $this->_logger->entrance();
19951
+
19952
+ if ( ! $this->should_page_include_tabs() ) {
19953
+ return false;
19954
+ }
19955
+
19956
+ echo '</div>';
19957
+
19958
+ return true;
19959
+ }
19960
+
19961
+ #endregion
19962
+
19963
+ /**
19964
+ * Add in-page JavaScript to inject the Freemius tabs into
19965
+ * the module's setting tabs section.
19966
+ *
19967
+ * @author Vova Feldman (@svovaf)
19968
+ * @since 1.2.2.7
19969
+ */
19970
+ function _add_freemius_tabs() {
19971
+ $this->_logger->entrance();
19972
+
19973
+ if ( ! $this->should_page_include_tabs() ) {
19974
+ return;
19975
+ }
19976
+
19977
+ $params = array( 'id' => $this->_module_id );
19978
+ fs_require_once_template( 'tabs.php', $params );
19979
+ }
19980
+
19981
+ #endregion
19982
+
19983
+ #--------------------------------------------------------------------------------
19984
+ #region Customizer Integration for Themes
19985
+ #--------------------------------------------------------------------------------
19986
+
19987
+ /**
19988
+ * @author Vova Feldman (@svovaf)
19989
+ * @since 1.2.2.7
19990
+ *
19991
+ * @param WP_Customize_Manager $customizer
19992
+ */
19993
+ function _customizer_register( $customizer ) {
19994
+ $this->_logger->entrance();
19995
+
19996
+ if ( $this->is_pricing_page_visible() ) {
19997
+ require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-upsell-control.php';
19998
+
19999
+ $customizer->add_section( 'freemius_upsell', array(
20000
+ 'title' => '&#9733; ' . $this->get_text_inline( 'View paid features', 'view-paid-features' ),
20001
+ 'priority' => 1,
20002
+ ) );
20003
+ $customizer->add_setting( 'freemius_upsell', array(
20004
+ 'sanitize_callback' => 'esc_html',
20005
+ ) );
20006
+
20007
+ $customizer->add_control( new FS_Customizer_Upsell_Control( $customizer, 'freemius_upsell', array(
20008
+ 'fs' => $this,
20009
+ 'section' => 'freemius_upsell',
20010
+ 'priority' => 100,
20011
+ ) ) );
20012
+ }
20013
+
20014
+ if ( $this->is_page_visible( 'contact' ) || $this->is_page_visible( 'support' ) ) {
20015
+ require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-support-section.php';
20016
+
20017
+ // Main Documentation Link In Customizer Root.
20018
+ $customizer->add_section( new FS_Customizer_Support_Section( $customizer, 'freemius_support', array(
20019
+ 'fs' => $this,
20020
+ 'priority' => 1000,
20021
+ ) ) );
20022
+ }
20023
+ }
20024
+
20025
+ #endregion
20026
+
20027
+ /**
20028
+ * If the theme has a paid version, add some custom
20029
+ * styling to the theme's premium version (if exists)
20030
+ * to highlight that it's the premium version of the
20031
+ * same theme, making it easier for identification
20032
+ * after the user upgrades and upload it to the site.
20033
+ *
20034
+ * @author Vova Feldman (@svovaf)
20035
+ * @since 1.2.2.7
20036
+ */
20037
+ function _style_premium_theme() {
20038
+ $this->_logger->entrance();
20039
+
20040
+ if ( ! self::is_themes_page() ) {
20041
+ // Only include in the themes page.
20042
+ return;
20043
+ }
20044
+
20045
+ if ( ! $this->has_paid_plan() ) {
20046
+ // Only include if has any paid plans.
20047
+ return;
20048
+ }
20049
+
20050
+ $params = null;
20051
+ fs_require_once_template( '/js/jquery.content-change.php', $params );
20052
+
20053
+ $params = array(
20054
+ 'slug' => $this->_slug,
20055
+ 'id' => $this->_module_id,
20056
+ );
20057
+
20058
+ fs_require_template( '/js/style-premium-theme.php', $params );
20059
+ }
20060
+
20061
+ /**
20062
+ * This method will return the absolute URL of the module's local icon.
20063
+ *
20064
+ * When you are running your plugin or theme on a **localhost** environment, if the icon
20065
+ * is not found in the local assets folder, try to fetch the icon URL from Freemius. If not set and
20066
+ * it's a plugin hosted on WordPress.org, try fetching the icon URL from wordpress.org.
20067
+ * If an icon is found, this method will automatically attempt to download the icon and store it
20068
+ * in /freemius/assets/img/{slug}.{png|jpg|gif|svg}.
20069
+ *
20070
+ * It's important to mention that this method is NOT phoning home since the developer will deploy
20071
+ * the product with the local icon in the assets folder. The download process just simplifies
20072
+ * the process for the developer.
20073
+ *
20074
+ * @author Vova Feldman (@svovaf)
20075
+ * @since 2.0.0
20076
+ *
20077
+ * @return string
20078
+ */
20079
+ function get_local_icon_url() {
20080
+ global $fs_active_plugins;
20081
+
20082
+ /**
20083
+ * @since 1.1.7.5
20084
+ */
20085
+ $local_path = $this->apply_filters( 'plugin_icon', false );
20086
+
20087
+ if ( is_string( $local_path ) ) {
20088
+ $icons = array( $local_path );
20089
+ } else {
20090
+ $img_dir = WP_FS__DIR_IMG;
20091
+
20092
+ // Locate the main assets folder.
20093
+ if ( 1 < count( $fs_active_plugins->plugins ) ) {
20094
+ $plugin_or_theme_img_dir = ( $this->is_plugin() ? WP_PLUGIN_DIR : get_theme_root() );
20095
+
20096
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
20097
+ if ( $data->plugin_path == $this->get_plugin_basename() ) {
20098
+ $img_dir = $plugin_or_theme_img_dir
20099
+ . '/'
20100
+ . str_replace( '../themes/', '', $sdk_path )
20101
+ . '/assets/img';
20102
+
20103
+ break;
20104
+ }
20105
+ }
20106
+ }
20107
+
20108
+ // Try to locate the icon in the assets folder.
20109
+ $icons = glob( fs_normalize_path( $img_dir . "/{$this->_slug}.*" ) );
20110
+
20111
+ if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
20112
+ if ( ! WP_FS__IS_LOCALHOST && $this->is_theme() ) {
20113
+ $icons = array(
20114
+ fs_normalize_path( $img_dir . '/theme-icon.png' )
20115
+ );
20116
+ } else {
20117
+ $icon_found = false;
20118
+ $local_path = fs_normalize_path( "{$img_dir}/{$this->_slug}.png" );
20119
+
20120
+ $have_write_permissions = ( 'direct' === get_filesystem_method( array(), fs_normalize_path( $img_dir ) ) );
20121
+
20122
+ /**
20123
+ * IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
20124
+ *
20125
+ * This code will only be executed once during the testing
20126
+ * of the plugin in a local environment. The plugin icon file WILL
20127
+ * already exist in the assets folder when the plugin is deployed to
20128
+ * the repository.
20129
+ */
20130
+ if ( WP_FS__IS_LOCALHOST && $have_write_permissions ) {
20131
+ // Fetch icon from Freemius.
20132
+ $icon = $this->fetch_remote_icon_url();
20133
+
20134
+ // Fetch icon from WordPress.org.
20135
+ if ( empty( $icon ) && $this->is_plugin() && $this->is_org_repo_compliant() ) {
20136
+ if ( ! function_exists( 'plugins_api' ) ) {
20137
+ require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
20138
+ }
20139
+
20140
+ $plugin_information = plugins_api( 'plugin_information', array(
20141
+ 'slug' => $this->_slug,
20142
+ 'fields' => array(
20143
+ 'sections' => false,
20144
+ 'tags' => false,
20145
+ 'icons' => true
20146
+ )
20147
+ ) );
20148
+
20149
+ if (
20150
+ ! is_wp_error( $plugin_information )
20151
+ && isset( $plugin_information->icons )
20152
+ && ! empty( $plugin_information->icons )
20153
+ ) {
20154
+ /**
20155
+ * Get the smallest icon.
20156
+ *
20157
+ * @author Leo Fajardo (@leorw)
20158
+