WooCommerce Multilingual – run WooCommerce with WPML - Version 4.2.0.1

Version Description

  • Updated the embedded Installer
Download this release

Release Info

Developer mihaimihai
Plugin Icon 128x128 WooCommerce Multilingual – run WooCommerce with WPML
Version 4.2.0.1
Comparing to
See all releases

Code changes from version 4.2.0 to 4.2.0.1

Files changed (30) hide show
  1. readme.txt +5 -2
  2. vendor/otgs/installer/README.md +1 -1
  3. vendor/otgs/installer/changelog.txt +17 -0
  4. vendor/otgs/installer/includes/class-installer-dependencies.php +291 -291
  5. vendor/otgs/installer/includes/class-installer-theme.php +978 -978
  6. vendor/otgs/installer/includes/class-installer-upgrader-skins.php +37 -37
  7. vendor/otgs/installer/includes/class-translation-service-info.php +39 -39
  8. vendor/otgs/installer/includes/class-wp-installer-api.php +133 -133
  9. vendor/otgs/installer/includes/class-wp-installer-channels.php +270 -290
  10. vendor/otgs/installer/includes/class-wp-installer.php +2768 -2769
  11. vendor/otgs/installer/includes/functions-core.php +9 -9
  12. vendor/otgs/installer/includes/functions-templates.php +6 -6
  13. vendor/otgs/installer/includes/installer-api.php +0 -134
  14. vendor/otgs/installer/includes/installer-upgrader-skins.php +0 -37
  15. vendor/otgs/installer/includes/installer.class.php +0 -2672
  16. vendor/otgs/installer/includes/translation-service-info.class.php +0 -40
  17. vendor/otgs/installer/installer.php +18 -18
  18. vendor/otgs/installer/loader.php +150 -150
  19. vendor/otgs/installer/locale/orig/installer.po +230 -230
  20. vendor/otgs/installer/res/css/admin.css +293 -289
  21. vendor/otgs/installer/res/js/admin.js +460 -460
  22. vendor/otgs/installer/res/js/channels.js +260 -260
  23. vendor/otgs/installer/res/js/iframeResizer.min.js +10 -10
  24. vendor/otgs/installer/res/js/installer_theme_install.js +96 -96
  25. vendor/otgs/installer/templates/channel-selector.php +67 -67
  26. vendor/otgs/installer/templates/downloads-list-compact.php +80 -80
  27. vendor/otgs/installer/templates/downloads-list.php +109 -109
  28. vendor/otgs/installer/templates/products-compact.php +147 -147
  29. vendor/otgs/installer/templates/repository-listing.php +199 -199
  30. wpml-woocommerce.php +3 -3
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: http://wpml.org/documentation/related-projects/woocommerce-multilin
4
  Tags: CMS, woocommerce, commerce, ecommerce, e-commerce, products, WPML, multilingual, e-shop, shop
5
  License: GPLv2
6
  Requires at least: 3.9
7
- Tested up to: 4.8
8
- Stable tag: 4.2.0
9
 
10
  Allows running fully multilingual e-commerce sites using WooCommerce and WPML.
11
 
@@ -142,6 +142,9 @@ WooCommerce Multilingual is compatible with all major WooCommerce extensions. We
142
 
143
  == Changelog ==
144
 
 
 
 
145
  = 4.2.0 =
146
  * Added the ability to translate Sensei question custom post types
147
  * Added the ability to translate serialized custom fields in the Translation Editor
4
  Tags: CMS, woocommerce, commerce, ecommerce, e-commerce, products, WPML, multilingual, e-shop, shop
5
  License: GPLv2
6
  Requires at least: 3.9
7
+ Tested up to: 4.8.1
8
+ Stable tag: 4.2.0.1
9
 
10
  Allows running fully multilingual e-commerce sites using WooCommerce and WPML.
11
 
142
 
143
  == Changelog ==
144
 
145
+ = 4.2.0.1 =
146
+ * Updated the embedded Installer
147
+
148
  = 4.2.0 =
149
  * Added the ability to translate Sensei question custom post types
150
  * Added the ability to translate serialized custom fields in the Translation Editor
vendor/otgs/installer/README.md CHANGED
@@ -38,7 +38,7 @@ WP_Installer_Setup( $wp_installer_instance,
38
  );
39
  ```
40
 
41
- After `init`, configure display the OTGS WP Installer UI like in teh example below:
42
 
43
  ```php
44
  WP_Installer_Show_Products(
38
  );
39
  ```
40
 
41
+ After `init`, configure display the OTGS WP Installer UI like in the example below:
42
 
43
  ```php
44
  WP_Installer_Show_Products(
vendor/otgs/installer/changelog.txt CHANGED
@@ -1,3 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  = 1.7.15 =
2
  * Bug fix: New search, results not visible with WordPress 4.6 when searching from installer page
3
  * Bug fix: A js error was showing on the admin pages: `pagenow` is undefined
1
+ = 1.8.2 =
2
+ * Bug fix: registration warning was shown for free plugins
3
+
4
+ = 1.8.1 =
5
+ * Fixed a bug potentially making the downloads list under the Commercial not display correctly
6
+
7
+ = 1.8 =
8
+ * Added support for update channels (beta, developement and production)
9
+
10
+ = 1.7.17 =
11
+ * Fixed some warnings and notices
12
+
13
+ = 1.7.16 =
14
+ * Fixed a bug with plugins list showing twice for the Toolset repository
15
+ * Replaced get_locale() with get_user_locale()
16
+ * Added WP_Installer_API::get_registering_user_id()
17
+
18
  = 1.7.15 =
19
  * Bug fix: New search, results not visible with WordPress 4.6 when searching from installer page
20
  * Bug fix: A js error was showing on the admin pages: `pagenow` is undefined
vendor/otgs/installer/includes/class-installer-dependencies.php CHANGED
@@ -1,291 +1,291 @@
1
- <?php
2
-
3
- class Installer_Dependencies {
4
-
5
- private $uploading_allowed = null;
6
- private $is_win_paths_exception = array();
7
-
8
-
9
- function __construct() {
10
-
11
- add_action( 'admin_init', array( $this, 'prevent_plugins_update_on_plugins_page' ), 100 );
12
-
13
-
14
- global $pagenow;
15
- if ( $pagenow == 'update.php' ) {
16
- if ( isset( $_GET['action'] ) && $_GET['action'] == 'update-selected' ) {
17
- add_action( 'admin_head', array(
18
- $this,
19
- 'prevent_plugins_update_on_updates_screen'
20
- ) ); //iframe/bulk
21
- } else {
22
- add_action( 'all_admin_notices', array(
23
- $this,
24
- 'prevent_plugins_update_on_updates_screen'
25
- ) ); //regular/singular
26
- }
27
- }
28
- add_action( 'wp_ajax_update-plugin', array(
29
- $this,
30
- 'prevent_plugins_update_on_updates_screen'
31
- ), 0 ); // high priority, before WP
32
-
33
- }
34
-
35
- public function is_win_paths_exception( $repository_id ) {
36
-
37
- if ( ! isset( $this->is_win_paths_exception[ $repository_id ] ) ) {
38
-
39
- $this->is_win_paths_exception[ $repository_id ] = false;
40
-
41
- if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
42
-
43
- $windows_max_path_length = 256;
44
- $longest_path['wpml'] = 109;
45
- $longest_path['toolset'] = 99;
46
-
47
- $margin = 15;
48
-
49
- $upgrade_path_length = strlen( WP_CONTENT_DIR . '/upgrade' );
50
-
51
- $installer_settings = WP_Installer()->settings;
52
-
53
- if ( isset($installer_settings['repositories'][$repository_id]['data']) && is_array( $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'] ) ) {
54
- $a_plugin = current( $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'] );
55
- $url = WP_Installer()->append_site_key_to_download_url( $a_plugin['url'], 'xxxxxx', $repository_id );
56
- $tmpfname = wp_tempnam( $url );
57
-
58
- $tmpname_length = strlen( basename( $tmpfname ) ) - 4; // -.tmp
59
-
60
- if ( $upgrade_path_length + $tmpname_length + $longest_path[ $repository_id ] + $margin > $windows_max_path_length ) {
61
-
62
- $this->is_win_paths_exception[ $repository_id ] = true;
63
-
64
- }
65
-
66
- }
67
-
68
-
69
- }
70
-
71
- }
72
-
73
- return $this->is_win_paths_exception[ $repository_id ];
74
-
75
- }
76
-
77
- public function is_uploading_allowed() {
78
-
79
- if ( ! isset( $this->uploading_allowed ) ) {
80
- require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
81
- require_once WP_Installer()->plugin_path() . '/includes/class-installer-upgrader-skins.php';
82
-
83
- $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
84
- $upgrader = new Plugin_Upgrader( $upgrader_skins );
85
-
86
- ob_start();
87
- $res = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
88
- ob_end_clean();
89
-
90
- if ( ! $res || is_wp_error( $res ) ) {
91
- $this->uploading_allowed = false;
92
- } else {
93
- $this->uploading_allowed = true;
94
- }
95
- }
96
-
97
- return $this->uploading_allowed;
98
-
99
- }
100
-
101
- public function cant_download( $repository_id ) {
102
-
103
- return ! $this->is_uploading_allowed() || $this->is_win_paths_exception( $repository_id );
104
-
105
- }
106
-
107
- public function win_paths_exception_message() {
108
- return __( 'Downloading is not possible. WordPress cannot create required folders because of the
109
- 256 characters limitation of the current Windows environment.', 'installer' );
110
- }
111
-
112
- public function prevent_plugins_update_on_plugins_page() {
113
-
114
- $plugins = get_site_transient( 'update_plugins' );
115
- if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
116
- $plugins_with_updates = array_keys( $plugins->response );
117
- }
118
-
119
- if ( ! empty( $plugins_with_updates ) ) {
120
-
121
- $plugins = get_plugins();
122
-
123
- $installer_settings = WP_Installer()->settings;
124
- if ( isset( $installer_settings['repositories'] ) ) {
125
- foreach ( $installer_settings['repositories'] as $repository_id => $repository ) {
126
-
127
- if ( $this->is_win_paths_exception( $repository_id ) ) {
128
-
129
- $repositories_plugins = array();
130
- foreach ( $repository['data']['packages'] as $package ) {
131
- foreach ( $package['products'] as $product ) {
132
- foreach ( $product['plugins'] as $plugin_slug ) {
133
- $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
134
- if ( empty( $download['free-on-wporg'] ) ) {
135
- $repositories_plugins[ $download['slug'] ] = $download['name'];
136
- }
137
- }
138
- }
139
- }
140
-
141
- foreach ( $plugins as $plugin_id => $plugin ) {
142
-
143
- if ( in_array( $plugin_id, $plugins_with_updates ) ) {
144
-
145
- $wp_plugin_slug = dirname( $plugin_id );
146
- if ( empty( $wp_plugin_slug ) ) {
147
- $wp_plugin_slug = basename( $plugin_id, '.php' );
148
- }
149
-
150
- foreach ( $repositories_plugins as $slug => $name ) {
151
- if ( $wp_plugin_slug == $slug || $name == $plugin['Name'] || $name == $plugin['Title'] ) { //match order: slug, name, title
152
-
153
- remove_action( "after_plugin_row_$plugin_id", 'wp_plugin_update_row', 10, 2 );
154
- add_action( "after_plugin_row_$plugin_id", array(
155
- $this,
156
- 'wp_plugin_update_row_win_exception',
157
- ), 10, 2 );
158
-
159
- }
160
- }
161
-
162
- }
163
-
164
- }
165
-
166
- }
167
-
168
-
169
- }
170
- }
171
-
172
- }
173
-
174
- }
175
-
176
- public function wp_plugin_update_row_win_exception() {
177
- $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
178
- echo '<tr class="plugin-update-tr">';
179
- echo '<td class="plugin-update colspanchange" colspan="' . esc_attr( $wp_list_table->get_column_count() ) .
180
- '"><div class="update-message">' . $this->win_paths_exception_message() . '</div></td>';
181
- echo '</tr>';
182
- }
183
-
184
- public function prevent_plugins_update_on_updates_screen() {
185
-
186
- if ( isset( $_REQUEST['action'] ) ) {
187
-
188
- $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
189
-
190
- $installer_settings = WP_Installer()->settings;
191
-
192
- //bulk mode
193
- if ( 'update-selected' == $action ) {
194
-
195
- global $plugins;
196
-
197
- if ( isset( $plugins ) && is_array( $plugins ) ) {
198
-
199
- foreach ( $plugins as $k => $plugin ) {
200
-
201
- $wp_plugin_slug = dirname( $plugin );
202
-
203
- foreach ( $installer_settings['repositories'] as $repository_id => $repository ) {
204
-
205
- if ( $this->is_win_paths_exception( $repository_id ) ) {
206
-
207
- foreach ( $repository['data']['packages'] as $package ) {
208
-
209
- foreach ( $package['products'] as $product ) {
210
-
211
- foreach ( $product['plugins'] as $plugin_slug ) {
212
-
213
- $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
214
-
215
- if ( $download['slug'] == $wp_plugin_slug && empty( $download['free-on-wporg'] ) ) {
216
-
217
- echo '<div class="updated error"><p>' . $this->win_paths_exception_message() .
218
- ' <strong>(' . $download['name'] . ')</strong>' . '</p></div>';
219
- unset( $plugins[ $k ] );
220
-
221
- break( 3 );
222
-
223
- }
224
-
225
- }
226
-
227
- }
228
-
229
- }
230
-
231
-
232
- }
233
-
234
- }
235
-
236
- }
237
-
238
- }
239
-
240
- }
241
-
242
-
243
- if ( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
244
-
245
- $plugin = isset( $_REQUEST['plugin'] ) ? trim( sanitize_text_field( $_REQUEST['plugin'] ) ) : '';
246
-
247
- $wp_plugin_slug = dirname( $plugin );
248
-
249
- foreach ( $installer_settings['repositories'] as $repository_id => $repository ) {
250
-
251
- if ( $this->is_win_paths_exception( $repository_id ) ) {
252
- foreach ( $repository['data']['packages'] as $package ) {
253
-
254
- foreach ( $package['products'] as $product ) {
255
-
256
- foreach ( $product['plugins'] as $plugin_slug ) {
257
- $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
258
-
259
- //match by folder, will change to match by name and folder
260
- if ( $download['slug'] == $wp_plugin_slug && empty ( $download['free-on-wporg'] ) ) {
261
-
262
- echo '<div class="updated error"><p>' . $this->win_paths_exception_message() . '</p></div>';
263
-
264
- echo '<div class="wrap">';
265
- echo '<h2>' . __( 'Update Plugin' ) . '</h2>';
266
- echo '<a href="' . admin_url( 'update-core.php' ) . '">' . __( 'Return to the updates page', 'installer' ) . '</a>';
267
- echo '</div>';
268
- require_once( ABSPATH . 'wp-admin/admin-footer.php' );
269
- exit;
270
-
271
- }
272
-
273
- }
274
-
275
- }
276
-
277
- }
278
- }
279
-
280
- }
281
-
282
- }
283
- }
284
-
285
- }
286
-
287
-
288
- }
289
-
290
-
291
-
1
+ <?php
2
+
3
+ class Installer_Dependencies {
4
+
5
+ private $uploading_allowed = null;
6
+ private $is_win_paths_exception = array();
7
+
8
+
9
+ function __construct() {
10
+
11
+ add_action( 'admin_init', array( $this, 'prevent_plugins_update_on_plugins_page' ), 100 );
12
+
13
+
14
+ global $pagenow;
15
+ if ( $pagenow == 'update.php' ) {
16
+ if ( isset( $_GET['action'] ) && $_GET['action'] == 'update-selected' ) {
17
+ add_action( 'admin_head', array(
18
+ $this,
19
+ 'prevent_plugins_update_on_updates_screen'
20
+ ) ); //iframe/bulk
21
+ } else {
22
+ add_action( 'all_admin_notices', array(
23
+ $this,
24
+ 'prevent_plugins_update_on_updates_screen'
25
+ ) ); //regular/singular
26
+ }
27
+ }
28
+ add_action( 'wp_ajax_update-plugin', array(
29
+ $this,
30
+ 'prevent_plugins_update_on_updates_screen'
31
+ ), 0 ); // high priority, before WP
32
+
33
+ }
34
+
35
+ public function is_win_paths_exception( $repository_id ) {
36
+
37
+ if ( ! isset( $this->is_win_paths_exception[ $repository_id ] ) ) {
38
+
39
+ $this->is_win_paths_exception[ $repository_id ] = false;
40
+
41
+ if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
42
+
43
+ $windows_max_path_length = 256;
44
+ $longest_path['wpml'] = 109;
45
+ $longest_path['toolset'] = 99;
46
+
47
+ $margin = 15;
48
+
49
+ $upgrade_path_length = strlen( WP_CONTENT_DIR . '/upgrade' );
50
+
51
+ $installer_settings = WP_Installer()->settings;
52
+
53
+ if ( isset($installer_settings['repositories'][$repository_id]['data']) && is_array( $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'] ) ) {
54
+ $a_plugin = current( $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'] );
55
+ $url = WP_Installer()->append_site_key_to_download_url( $a_plugin['url'], 'xxxxxx', $repository_id );
56
+ $tmpfname = wp_tempnam( $url );
57
+
58
+ $tmpname_length = strlen( basename( $tmpfname ) ) - 4; // -.tmp
59
+
60
+ if ( $upgrade_path_length + $tmpname_length + $longest_path[ $repository_id ] + $margin > $windows_max_path_length ) {
61
+
62
+ $this->is_win_paths_exception[ $repository_id ] = true;
63
+
64
+ }
65
+
66
+ }
67
+
68
+
69
+ }
70
+
71
+ }
72
+
73
+ return $this->is_win_paths_exception[ $repository_id ];
74
+
75
+ }
76
+
77
+ public function is_uploading_allowed() {
78
+
79
+ if ( ! isset( $this->uploading_allowed ) ) {
80
+ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
81
+ require_once WP_Installer()->plugin_path() . '/includes/class-installer-upgrader-skins.php';
82
+
83
+ $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
84
+ $upgrader = new Plugin_Upgrader( $upgrader_skins );
85
+
86
+ ob_start();
87
+ $res = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
88
+ ob_end_clean();
89
+
90
+ if ( ! $res || is_wp_error( $res ) ) {
91
+ $this->uploading_allowed = false;
92
+ } else {
93
+ $this->uploading_allowed = true;
94
+ }
95
+ }
96
+
97
+ return $this->uploading_allowed;
98
+
99
+ }
100
+
101
+ public function cant_download( $repository_id ) {
102
+
103
+ return ! $this->is_uploading_allowed() || $this->is_win_paths_exception( $repository_id );
104
+
105
+ }
106
+
107
+ public function win_paths_exception_message() {
108
+ return __( 'Downloading is not possible. WordPress cannot create required folders because of the
109
+ 256 characters limitation of the current Windows environment.', 'installer' );
110
+ }
111
+
112
+ public function prevent_plugins_update_on_plugins_page() {
113
+
114
+ $plugins = get_site_transient( 'update_plugins' );
115
+ if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
116
+ $plugins_with_updates = array_keys( $plugins->response );
117
+ }
118
+
119
+ if ( ! empty( $plugins_with_updates ) ) {
120
+
121
+ $plugins = get_plugins();
122
+
123
+ $installer_settings = WP_Installer()->settings;
124
+ if ( isset( $installer_settings['repositories'] ) ) {
125
+ foreach ( $installer_settings['repositories'] as $repository_id => $repository ) {
126
+
127
+ if ( $this->is_win_paths_exception( $repository_id ) ) {
128
+
129
+ $repositories_plugins = array();
130
+ foreach ( $repository['data']['packages'] as $package ) {
131
+ foreach ( $package['products'] as $product ) {
132
+ foreach ( $product['plugins'] as $plugin_slug ) {
133
+ $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
134
+ if ( empty( $download['free-on-wporg'] ) ) {
135
+ $repositories_plugins[ $download['slug'] ] = $download['name'];
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ foreach ( $plugins as $plugin_id => $plugin ) {
142
+
143
+ if ( in_array( $plugin_id, $plugins_with_updates ) ) {
144
+
145
+ $wp_plugin_slug = dirname( $plugin_id );
146
+ if ( empty( $wp_plugin_slug ) ) {
147
+ $wp_plugin_slug = basename( $plugin_id, '.php' );
148
+ }
149
+
150
+ foreach ( $repositories_plugins as $slug => $name ) {
151
+ if ( $wp_plugin_slug == $slug || $name == $plugin['Name'] || $name == $plugin['Title'] ) { //match order: slug, name, title
152
+
153
+ remove_action( "after_plugin_row_$plugin_id", 'wp_plugin_update_row', 10, 2 );
154
+ add_action( "after_plugin_row_$plugin_id", array(
155
+ $this,
156
+ 'wp_plugin_update_row_win_exception',
157
+ ), 10, 2 );
158
+
159
+ }
160
+ }
161
+
162
+ }
163
+
164
+ }
165
+
166
+ }
167
+
168
+
169
+ }
170
+ }
171
+
172
+ }
173
+
174
+ }
175
+
176
+ public function wp_plugin_update_row_win_exception() {
177
+ $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
178
+ echo '<tr class="plugin-update-tr">';
179
+ echo '<td class="plugin-update colspanchange" colspan="' . esc_attr( $wp_list_table->get_column_count() ) .
180
+ '"><div class="update-message">' . $this->win_paths_exception_message() . '</div></td>';
181
+ echo '</tr>';
182
+ }
183
+
184
+ public function prevent_plugins_update_on_updates_screen() {
185
+
186
+ if ( isset( $_REQUEST['action'] ) ) {
187
+
188
+ $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
189
+
190
+ $installer_settings = WP_Installer()->settings;
191
+
192
+ //bulk mode
193
+ if ( 'update-selected' == $action ) {
194
+
195
+ global $plugins;
196
+
197
+ if ( isset( $plugins ) && is_array( $plugins ) ) {
198
+
199
+ foreach ( $plugins as $k => $plugin ) {
200
+
201
+ $wp_plugin_slug = dirname( $plugin );
202
+
203
+ foreach ( $installer_settings['repositories'] as $repository_id => $repository ) {
204
+
205
+ if ( $this->is_win_paths_exception( $repository_id ) ) {
206
+
207
+ foreach ( $repository['data']['packages'] as $package ) {
208
+
209
+ foreach ( $package['products'] as $product ) {
210
+
211
+ foreach ( $product['plugins'] as $plugin_slug ) {
212
+
213
+ $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
214
+
215
+ if ( $download['slug'] == $wp_plugin_slug && empty( $download['free-on-wporg'] ) ) {
216
+
217
+ echo '<div class="updated error"><p>' . $this->win_paths_exception_message() .
218
+ ' <strong>(' . $download['name'] . ')</strong>' . '</p></div>';
219
+ unset( $plugins[ $k ] );
220
+
221
+ break( 3 );
222
+
223
+ }
224
+
225
+ }
226
+
227
+ }
228
+
229
+ }
230
+
231
+
232
+ }
233
+
234
+ }
235
+
236
+ }
237
+
238
+ }
239
+
240
+ }
241
+
242
+
243
+ if ( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
244
+
245
+ $plugin = isset( $_REQUEST['plugin'] ) ? trim( sanitize_text_field( $_REQUEST['plugin'] ) ) : '';
246
+
247
+ $wp_plugin_slug = dirname( $plugin );
248
+
249
+ foreach ( $installer_settings['repositories'] as $repository_id => $repository ) {
250
+
251
+ if ( $this->is_win_paths_exception( $repository_id ) ) {
252
+ foreach ( $repository['data']['packages'] as $package ) {
253
+
254
+ foreach ( $package['products'] as $product ) {
255
+
256
+ foreach ( $product['plugins'] as $plugin_slug ) {
257
+ $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
258
+
259
+ //match by folder, will change to match by name and folder
260
+ if ( $download['slug'] == $wp_plugin_slug && empty ( $download['free-on-wporg'] ) ) {
261
+
262
+ echo '<div class="updated error"><p>' . $this->win_paths_exception_message() . '</p></div>';
263
+
264
+ echo '<div class="wrap">';
265
+ echo '<h2>' . __( 'Update Plugin' ) . '</h2>';
266
+ echo '<a href="' . admin_url( 'update-core.php' ) . '">' . __( 'Return to the updates page', 'installer' ) . '</a>';
267
+ echo '</div>';
268
+ require_once( ABSPATH . 'wp-admin/admin-footer.php' );
269
+ exit;
270
+
271
+ }
272
+
273
+ }
274
+
275
+ }
276
+
277
+ }
278
+ }
279
+
280
+ }
281
+
282
+ }
283
+ }
284
+
285
+ }
286
+
287
+
288
+ }
289
+
290
+
291
+
vendor/otgs/installer/includes/class-installer-theme.php CHANGED
@@ -1,979 +1,979 @@
1
- <?php
2
- /**
3
- * Installer Class for Theme Support
4
- *
5
- * Supports automatic updates and installation of Toolset/WPML Themes
6
- *
7
- * @class Installer_Theme_Class
8
- * @version 1.6
9
- * @category Class
10
- * @author OnTheGoSystems
11
- */
12
-
13
- if ( !defined( 'ABSPATH' ) ) {
14
- exit;
15
- }
16
-
17
- /**
18
- * Installer_Theme_Class
19
- */
20
- class Installer_Theme_Class {
21
-
22
- /** Theme Repository */
23
- private $theme_repo;
24
-
25
- /** Repository API */
26
- private $repository_api;
27
-
28
- /** Repository Theme Products */
29
- private $repository_theme_products;
30
-
31
- /** Site URL */
32
- private $installer_site_url;
33
-
34
- /** Site Key */
35
- private $installer_site_key;
36
-
37
- /** The Themes Option */
38
- protected $installer_themes_option;
39
-
40
- /** Update settings */
41
- protected $installer_themes_available_updates;
42
-
43
- /** The Themes */
44
- protected $installer_themes = array();
45
-
46
- /** Repository with themes */
47
- protected $installer_repo_with_themes;
48
-
49
- /** Active tab */
50
- protected $installer_theme_active_tab;
51
-
52
- /** Theme user registration */
53
- protected $theme_user_registration;
54
-
55
- /** Client active subscription */
56
- protected $installer_theme_subscription_type;
57
-
58
- public function __construct() {
59
-
60
- /** Properties */
61
-
62
- //Get installer repositories
63
- $installer_repositories = WP_Installer()->get_repositories();
64
-
65
- //Get repos with themes
66
- $repos_with_themes = $this->installer_theme_reposities_that_has_themes( $installer_repositories );
67
-
68
- if ( is_array( $repos_with_themes ) ) {
69
- //Assign to property
70
- $this->installer_repo_with_themes = $repos_with_themes;
71
-
72
- //Let's looped through repos with themes
73
- foreach ( $repos_with_themes as $k => $repo ) {
74
-
75
- //$repo could be 'toolset' or 'wpml'
76
- //Assign each repo with theme to property
77
- $this->theme_repo[] = $repo;
78
-
79
- if ( (isset($installer_repositories[$repo]['api-url'])) && (isset($installer_repositories[$repo]['products'])) ) {
80
-
81
- //Define the rest of the properties based on the given repo
82
- $this->repository_api[$repo] = $installer_repositories[$repo]['api-url'];
83
- $this->repository_theme_products[$repo] = $installer_repositories[$repo]['products'];
84
- $this->installer_site_url[$repo] = WP_Installer()->get_installer_site_url( $repo );
85
- $this->installer_site_key[$repo] = WP_Installer()->get_site_key( $repo );
86
- $this->theme_user_registration[$repo] = false;
87
-
88
- if ( WP_Installer()->repository_has_valid_subscription( $repo ) ) {
89
-
90
- $this->installer_theme_subscription_type = WP_Installer()->get_subscription_type_for_repository( $repo );
91
- $this->installer_themes_option[$repo] = 'wp_installer_' . $repo . '_themes';
92
- $this->installer_themes_available_updates[$repo] = 'wp_installer_' . $repo . '_updated_themes';
93
- $this->installer_theme_active_tab = '';
94
-
95
- //We only set themes available to this validated subscription
96
- $this->installer_theme_available( $repo, $this->installer_theme_subscription_type );
97
-
98
- add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_sets_active_tab_on_init'), 10 );
99
- $this->theme_user_registration[$repo] = true;
100
- }
101
-
102
- /** We are ready.. let's initialize .... */
103
- $this->init();
104
- }
105
- }
106
- add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_loaded_hooks') );
107
- }
108
- }
109
-
110
- /** Init */
111
- public function init() {
112
- add_action( 'admin_enqueue_scripts', array($this, 'installer_theme_enqueue_scripts') );
113
- add_filter( 'themes_api', array($this, 'installer_theme_api_override'), 10, 3 );
114
- add_filter( 'themes_api_result', array($this, 'installer_theme_api_override_response'), 10, 3 );
115
- add_filter( 'site_transient_update_themes', array($this, 'installer_theme_upgrade_check'), 10, 1 );
116
- add_action( 'http_api_debug', array($this, 'installer_theme_sync_native_wp_api'), 10, 5 );
117
- add_filter( 'installer_theme_hook_response_theme', array($this, 'installer_theme_add_num_ratings'), 10, 1 );
118
- add_filter( 'themes_update_check_locales', array($this, 'installer_theme_sync_call_wp_theme_api'), 10, 1 );
119
- add_filter( 'admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 3 );
120
- add_filter( 'network_admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 2 );
121
- add_action( 'wp_ajax_installer_theme_frontend_selected_tab', array($this, 'installer_theme_frontend_selected_tab'), 0 );
122
- add_action( 'wp_loaded', array($this, 'installer_themes_support_set_up_func') );
123
- }
124
-
125
- /** Enqueue scripts */
126
- public function installer_theme_enqueue_scripts() {
127
- $current_screen = $this->installer_theme_current_screen();
128
- $commercial_plugin_screen = $this->installer_theme_is_commercial_plugin_screen( $current_screen );
129
- if ( ('theme-install' == $current_screen) || ($commercial_plugin_screen) || ('theme-install-network' == $current_screen) ) {
130
- $repo_with_themes = $this->installer_repo_with_themes;
131
- $js_array = array();
132
- if ( is_array( $repo_with_themes ) ) {
133
- foreach ( $repo_with_themes as $k => $v ) {
134
-
135
- //Hyperlink text
136
- $theme_repo_name = $this->installer_theme_get_repo_product_name( $v );
137
- $the_hyperlink_text = esc_js( $theme_repo_name );
138
-
139
- if ( is_multisite() ) {
140
- $admin_url_passed = network_admin_url();
141
- } else {
142
- $admin_url_passed = admin_url();
143
- }
144
-
145
- //Define
146
- $js_array[$v] = array(
147
- 'the_hyperlink_text' => $the_hyperlink_text,
148
- 'registration_status' => $this->theme_user_registration[$v],
149
- 'is_commercial_plugin_tab' => $commercial_plugin_screen,
150
- 'registration_url' => $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $v
151
- );
152
-
153
- }
154
- }
155
-
156
- if ( !(empty($js_array)) ) {
157
- wp_enqueue_script( 'installer-theme-install', WP_Installer()->res_url() . '/res/js/installer_theme_install.js', array('jquery', 'installer-admin'), WP_Installer()->version() );
158
- $installer_ajax_url = admin_url( 'admin-ajax.php' );
159
-
160
- if ( is_ssl() ) {
161
- $installer_ajax_url = str_replace( 'http://', 'https://', $installer_ajax_url );
162
- } else {
163
- $installer_ajax_url = str_replace( 'https://', 'http://', $installer_ajax_url );
164
- }
165
-
166
- //Case where user is subscribed to a subscription that does not have themes
167
- $subscription_js_check = $this->installer_theme_subscription_does_not_have_theme( $js_array );
168
-
169
- wp_localize_script( 'installer-theme-install', 'installer_theme_install_localize',
170
- array(
171
- 'js_array_installer' => $js_array,
172
- 'ajaxurl' => $installer_ajax_url,
173
- 'no_associated_themes' => $subscription_js_check,
174
- 'installer_theme_frontend_selected_tab_nonce' => wp_create_nonce( 'installer_theme_frontend_selected_tab' )
175
- )
176
- );
177
- }
178
- }
179
- }
180
-
181
- /** Case where user is subscribed to a subscription that does not have themes */
182
- protected function installer_theme_subscription_does_not_have_theme( $js_array ) {
183
-
184
- $any_subscription_has_theme = array();
185
- $number_of_registrations = array();
186
-
187
- //Step1, we looped through JS array
188
- foreach ( $js_array as $repo_slug => $js_details ) {
189
-
190
- //Step2, checked if user is registered
191
- if ( isset($this->theme_user_registration[$repo_slug]) ) {
192
- $registration_status = $this->theme_user_registration[$repo_slug];
193
- if ( $registration_status ) {
194
-
195
- //Registered
196
- $number_of_registrations[] = $repo_slug;
197
-
198
- //Step3, we checked if the $repo_slug has available theme
199
- $themes_available = false;
200
- if ( isset($this->installer_themes[$repo_slug]) ) {
201
- $themes_available = $this->installer_themes[$repo_slug];
202
- if ( !(empty($themes_available)) ) {
203
- //This subscription has theme
204
- $themes_available = true;
205
- }
206
- }
207
-
208
- if ( $themes_available ) {
209
- $any_subscription_has_theme[] = $repo_slug;
210
- }
211
- }
212
- }
213
-
214
- }
215
-
216
- //Step4, we are done looping, check if there are any repos that have themes
217
- if ( empty($registration_status) ) {
218
-
219
- //No registration on any repos
220
- return FALSE;
221
-
222
- } elseif ( !(empty($registration_status)) ) {
223
-
224
- //Has some registration on some repos
225
- //We then checked if this user has any active subscriptions
226
- if ( empty($any_subscription_has_theme) ) {
227
- //No subscription
228
- return TRUE;
229
- } else {
230
- //Has subscription found
231
- return FALSE;
232
- }
233
- }
234
- }
235
-
236
- /** Check if its the commercial plugin screen */
237
- private function installer_theme_is_commercial_plugin_screen( $current_screen ) {
238
- $commercial = false;
239
- if ( ('plugin-install' == $current_screen) || ('plugin-install-network' == $current_screen) ) {
240
- if ( isset($_GET['tab']) ) {
241
- $tab = sanitize_text_field( $_GET['tab'] );
242
- if ( 'commercial' == $tab ) {
243
- $commercial = true;
244
- }
245
- }
246
- }
247
- return $commercial;
248
- }
249
-
250
- /** Current screen */
251
- private function installer_theme_current_screen() {
252
-
253
- $current_screen_loaded = false;
254
-
255
- if ( function_exists( 'get_current_screen' ) ) {
256
-
257
- $screen_output = get_current_screen();
258
- $current_screen_loaded = $screen_output->id;
259
-
260
- }
261
-
262
- return $current_screen_loaded;
263
-
264
- }
265
-
266
- /** Override WordPress Themes API */
267
- public function installer_theme_api_override( $api_boolean, $action, $args ) {
268
-
269
- //Let's checked if user is browsing our themes
270
- if ( isset($args->browse) ) {
271
- $browse = $args->browse;
272
- if ( in_array( $browse, $this->theme_repo ) ) {
273
- //Uniquely validated for our Themes
274
- if ( 'query_themes' == $action ) {
275
- //User is querying or asking information about our themes, let's override
276
- $api_boolean = true;
277
- }
278
- }
279
- } elseif ( isset($args->slug) ) {
280
- //We are installing our themes
281
- $theme_to_install = $args->slug;
282
-
283
- //Lets uniquely validate if this belongs to us
284
- //Check if this is OTGS theme
285
- $validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
286
- if ( $validate_check ) {
287
- //Belongs to us
288
- if ( !(empty($theme_to_install)) ) {
289
- $api_boolean = true;
290
- }
291
- }
292
- }
293
-
294
- return $api_boolean;
295
- }
296
-
297
- /** Override WordPress Themes API response with our own themes API*/
298
- public function installer_theme_api_override_response( $res, $action, $args ) {
299
-
300
- if ( true === $res ) {
301
- if ( isset($args->browse) ) {
302
- $browse = $args->browse;
303
- if ( in_array( $browse, $this->theme_repo ) ) {
304
- //Uniquely validated for our themes
305
- if ( 'query_themes' == $action ) {
306
- //Client querying OTGS themes
307
- //Check for registration status
308
- if ( isset($this->theme_user_registration[$browse]) ) {
309
- //Set
310
- if ( !($this->theme_user_registration[$browse]) ) {
311
- //Not registered yet
312
- $res = new stdClass();
313
- $res->info = array();
314
- $res->themes = array();
315
- return $res;
316
- } else {
317
- //Registered
318
- $themes = $this->installer_theme_get_themes( '', $browse );
319
- $res = $this->installer_theme_format_response( $themes, $action );
320
- }
321
- }
322
- }
323
- }
324
- } elseif ( isset($args->slug) ) {
325
- //We are installing theme
326
- //Lets uniquely validate if this belongs to our theme
327
- $theme_to_install = $args->slug;
328
-
329
- //Lets uniquely validate if this belongs to us
330
- //Check if this is OTGS theme
331
- $validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
332
- if ( $validate_check ) {
333
- //Belongs to us
334
- if ( ($res) && ('theme_information' == $action) ) {
335
- $themes = $this->installer_theme_get_themes( '', $this->installer_theme_active_tab );
336
- $res = $this->installer_theme_format_response( $themes, $action, $args->slug );
337
- }
338
- }
339
- }
340
- return $res;
341
- } else {
342
- //Default WP Themes here
343
- $client_side_active_tab = get_option( 'wp_installer_clientside_active_tab' );
344
- if ( $client_side_active_tab ) {
345
- if ( !(in_array( $client_side_active_tab, $this->theme_repo )) ) {
346
- //Not OTGS tab
347
- return $res;
348
- }
349
- }
350
-
351
- }
352
- }
353
-
354
- /** Get Themes */
355
- private function installer_theme_get_themes( $product_url = '', $repo_source = '' ) {
356
-
357
- //Query API
358
- if ( empty($product_url) ) {
359
- //Not set
360
- if ( isset($this->repository_theme_products[$this->installer_theme_active_tab]) ) {
361
- $query_remote_url = $this->repository_theme_products[$this->installer_theme_active_tab];
362
- }
363
-
364
- } else {
365
- $query_remote_url = $product_url;
366
- }
367
-
368
- //Let's retrieved current installer settings so we won't be querying all the time
369
- $current_installer_settings = WP_Installer()->get_settings();
370
-
371
- //Set $themes to FALSE by default
372
- $themes = false;
373
-
374
- if ( (is_array( $current_installer_settings )) && (!(empty($current_installer_settings))) ) {
375
-
376
- //Set and already defined, retrieved $products
377
- if ( isset($current_installer_settings['repositories'][$repo_source]['data']) ) {
378
- $products = $current_installer_settings['repositories'][$repo_source]['data'];
379
- if ( isset($products['downloads']['themes']) ) {
380
- $themes = $products['downloads']['themes'];
381
- }
382
- }
383
-
384
- } else {
385
-
386
- //Call API
387
- $response = wp_remote_get( $query_remote_url );
388
-
389
- if ( is_wp_error( $response ) ) {
390
- //Error detected: http fallback
391
- $query_remote_url = preg_replace( "@^https://@", 'http://', $query_remote_url );
392
- $response = wp_remote_get( $query_remote_url );
393
- }
394
-
395
- if ( !(is_wp_error( $response )) ) {
396
- //Not WP error
397
- //Evaluate response
398
- if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
399
- //In this case, response is set and defined, proceed...
400
- $body = wp_remote_retrieve_body( $response );
401
- if ( $body ) {
402
- $products = json_decode( $body, true );
403
- if ( isset($products['downloads']['themes']) ) {
404
- $themes = $products['downloads']['themes'];
405
- }
406
- }
407
-
408
- }
409
- }
410
- }
411
-
412
- //Return themes, can be filtered by user subscription type
413
- return apply_filters( 'installer_theme_get_themes', $themes, $this->installer_theme_active_tab );
414
- }
415
-
416
- /** Format response in compatibility with WordPress Theme API response */
417
- private function installer_theme_format_response( $themes, $action, $slug = '' ) {
418
-
419
- //Let's append download link only when retrieving theme information for installation
420
- if ( ('theme_information' == $action) && (!(empty($slug))) ) {
421
-
422
- //Only return one result -> the theme to be installed
423
- foreach ( $themes as $k => $theme ) {
424
- if ( $slug == $theme['basename'] ) {
425
- $theme['download_link'] = WP_Installer()->append_site_key_to_download_url( $theme['url'], $this->installer_site_key[$this->installer_theme_active_tab], $this->installer_theme_active_tab );
426
- $theme = json_decode( json_encode( $theme ), FALSE );
427
- return $theme;
428
- }
429
- }
430
-
431
- } else {
432
-
433
- $res = new stdClass();
434
- $res->info = array();
435
- $res->themes = array();
436
-
437
- //Define info
438
- $res->info['page'] = 1;
439
- $res->info['pages'] = 10;
440
-
441
- //Let's count available themes ;
442
- $res->info['results'] = count( $themes );
443
-
444
- //Let's saved themes for easy access later on
445
- $this->installer_theme_savethemes_by_slug( $themes );
446
-
447
- //Let's defined available themes
448
- if ( isset($this->installer_theme_subscription_type) ) {
449
- //Has subscription type defined, let's saved what is associated with this subscription
450
- $this->installer_theme_available( $this->installer_theme_active_tab, $this->installer_theme_subscription_type );
451
- } else {
452
- $this->installer_theme_available( $this->installer_theme_active_tab );
453
- }
454
-
455
- //Let's add themes to the overriden WordPress API Theme response
456
- /** Installer 1.7.6: Update to compatible data format response from WP Theme API */
457
- $theme_compatible_array=array();
458
- if ((is_array($themes))) {
459
- foreach ($themes as $k=>$v) {
460
- $theme_compatible_array[]=(object)($v);
461
- }
462
- }
463
- $res->themes = $theme_compatible_array;
464
- $res->themes = apply_filters( 'installer_theme_hook_response_theme', $res->themes );
465
- return $res;
466
- }
467
- }
468
-
469
- /** Let's save all available themes by its slug after any latest API query */
470
- private function installer_theme_savethemes_by_slug( $themes, $doing_query = false ) {
471
-
472
- if ( !($doing_query) ) {
473
- $this->installer_themes[$this->installer_theme_active_tab] = array();
474
- }
475
-
476
- if ( !(empty($themes)) ) {
477
- $themes_for_saving = array();
478
- foreach ( $themes as $k => $theme ) {
479
- if ( !($doing_query) ) {
480
- if ( isset($theme['slug']) ) {
481
- $theme_slug = $theme['slug'];
482
- if ( !(empty($theme_slug)) ) {
483
- $themes_for_saving[] = $theme_slug;
484
- }
485
- }
486
- } else {
487
-
488
- if ( ((isset($theme['slug'])) && (isset($theme['version'])) &&
489
- (isset($theme['theme_page_url']))) && (isset($theme['url']))
490
- ) {
491
- $theme_slug = $theme['slug'];
492
- $theme_version = $theme['version'];
493
- $theme_page_url = $theme['theme_page_url'];
494
- $theme_url = $theme['url'];
495
- if ( (!(empty($theme_slug))) && (!(empty($theme_version))) &&
496
- (!(empty($theme_page_url))) && (!(empty($theme_url)))
497
- ) {
498
- //$theme_slug is unique for every theme
499
- $themes_for_saving[$theme_slug] = array(
500
- 'version' => $theme_version,
501
- 'theme_page_url' => $theme_page_url,
502
- 'url' => $theme_url
503
- );
504
-
505
- }
506
- }
507
- }
508
-
509
- }
510
-
511
- if ( !(empty($themes_for_saving)) ) {
512
- //Has themes for saving
513
- if ( !($doing_query) ) {
514
- //Not doing query
515
- $existing_themes = get_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
516
- if ( !($existing_themes) ) {
517
- //Does not yet exists
518
- delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
519
- update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
520
- } else {
521
- //exists, check if we need to update
522
- if ( $existing_themes == $themes_for_saving ) {
523
- //Equal, no need to update here
524
- } else {
525
- //Update
526
- delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
527
- update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
528
- }
529
- }
530
- } else {
531
- //Used for query purposes only, don't save anything
532
- return $themes_for_saving;
533
- }
534
- }
535
- }
536
- }
537
-
538
- /** Available themes */
539
- private function installer_theme_available( $repo, $subscription_type = '' ) {
540
-
541
- $subscription_type = intval( $subscription_type );
542
- if ( $subscription_type > 0 ) {
543
-
544
- //Here we have a case of validated subscription
545
- //We need to set themes that is available to this subscription
546
- $themes_associated_with_subscription = $this->installer_themes[$repo] = $this->installer_theme_get_themes_by_subscription( $subscription_type, $repo );
547
- if ( !(empty($themes_associated_with_subscription)) ) {
548
- //Has themes
549
- $this->installer_themes[$repo] = $themes_associated_with_subscription;
550
- }
551
- } else {
552
-
553
- //Get themes
554
- $this->installer_themes[$repo] = get_option( $this->installer_themes_option[$repo] );
555
- }
556
- }
557
-
558
- /** Theme upgrade check */
559
- public function installer_theme_upgrade_check( $the_value ) {
560
-
561
- //Step1: Let's looped through repos with themes and check if we have updates available for them.
562
- if ( (is_array( $this->installer_repo_with_themes )) && (!(empty($this->installer_repo_with_themes))) ) {
563
- foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
564
- //Step2: Let's checked if we have update for this theme
565
- $update_available = get_option( $this->installer_themes_available_updates[$repo_slug] );
566
- if ( $update_available ) {
567
- if ( (is_array( $update_available )) && (!(empty($update_available))) ) {
568
- //Has updates available coming from this specific theme repo
569
- //Let's loop through the themes that needs update
570
- foreach ( $update_available as $theme_slug => $v ) {
571
- //Add to response API
572
- $the_value->response [$theme_slug] = array(
573
- 'theme' => $theme_slug,
574
- 'new_version' => $v['new_version'],
575
- 'url' => $v['url'],
576
- 'package' => $v['package']
577
- );
578
- }
579
- }
580
- }
581
- }
582
- }
583
- //Return
584
- return $the_value;
585
- }
586
-
587
- /** Return repositories that has themes */
588
- private function installer_theme_reposities_that_has_themes( $repositories, $ret_value = true, $doing_api_query = false ) {
589
-
590
- $repositories_with_themes = array();
591
-
592
- if ( (is_array( $repositories )) && (!(empty($repositories))) ) {
593
-
594
- //Let's checked if we have something before
595
- $themes = get_option( 'installer_repositories_with_theme' );
596
-
597
- if ( (!($themes)) || ($doing_api_query) ) {
598
- //Not yet defined
599
- //Loop through each repositories and check whether they have themes
600
- foreach ( $repositories as $k => $v ) {
601
- if ( isset($v['products']) ) {
602
- $products_url = $v['products'];
603
- $themes = $this->installer_theme_get_themes( $products_url, $k );
604
- if ( (is_array( $themes )) && (!(empty($themes))) ) {
605
- //Repo has themes
606
- $repositories_with_themes[] = $k;
607
- }
608
- }
609
- }
610
- } else {
611
- //Already set
612
- $repositories_with_themes = $themes;
613
- }
614
-
615
- if ( (((is_array( $repositories_with_themes )) && (!(empty($repositories_with_themes)))) && (!($themes))) || ($doing_api_query) ) {
616
- //Save to db
617
- update_option( 'installer_repositories_with_theme', $repositories_with_themes );
618
- }
619
- }
620
-
621
- if ( $ret_value ) {
622
- return $repositories_with_themes;
623
- }
624
-
625
- }
626
-
627
- /** When WordPress queries its own Themes API, we sync with our own */
628
- public function installer_theme_sync_native_wp_api( $response, $responsetext, $class, $args, $url ) {
629
-
630
- $api_native_string = 'api.wordpress.org/themes/';
631
- if ( (strpos( $url, $api_native_string ) !== false) ) {
632
- //WordPress is querying its own themes API
633
- $installer_repositories = WP_Installer()->get_repositories();
634
-
635
- //Query our own API and update repository values too
636
- $this->installer_theme_reposities_that_has_themes( $installer_repositories, false, true );
637
- }
638
- }
639
-
640
- /** Returns product name by theme repo slug */
641
- private function installer_theme_get_repo_product_name( $theme_repo ) {
642
-
643
- $theme_repo_name = false;
644
-
645
- if ( isset(WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name']) ) {
646
- //Set
647
- $prod_name = WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name'];
648
- if ( !(empty($prod_name)) ) {
649
- $theme_repo_name = $prod_name;
650
- }
651
- } else {
652
- //Not yet
653
- if ( $theme_repo == $this->theme_repo ) {
654
- $result = $this->installer_theme_general_api_query();
655
- if ( isset($result['product-name']) ) {
656
- $product_name = $result['product-name'];
657
- if ( !(empty($product_name)) ) {
658
- $theme_repo_name = $product_name;
659
- }
660
- }
661
- }
662
- }
663
-
664
- return $theme_repo_name;
665
- }
666
-
667
- /** General query API method, returns $products */
668
- private function installer_theme_general_api_query() {
669
- $products = false;
670
- $response = wp_remote_get( $this->repository_theme_products );
671
- if ( !(is_wp_error( $response )) ) {
672
- //Not WP error
673
- //Evaluate response
674
- if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
675
- //In this case, response is set and defined, proceed...
676
- $body = wp_remote_retrieve_body( $response );
677
- if ( $body ) {
678
- $result = json_decode( $body, true );
679
- if ( (is_array( $result )) && (!(empty($result))) ) {
680
- $products = $result;
681
- }
682
- }
683
-
684
- }
685
- }
686
-
687
- return $products;
688
- }
689
-
690
- /** General method to check if themes are OTGS themes based on its slug*/
691
- private function installer_themes_belong_to_us( $theme_slug ) {
692
-
693
- $found = false;
694
- $theme_slug = trim( $theme_slug );
695
-
696
- foreach ( $this->installer_themes as $repo_with_theme => $themes ) {
697
- foreach ( $themes as $k => $otgs_theme_slug ) {
698
- if ( $theme_slug == $otgs_theme_slug ) {
699
- //match found! Theme belongs to otgs
700
- return true;
701
- }
702
- }
703
- }
704
- return $found;
705
-
706
- }
707
-
708
- /** Sets active tab on init */
709
- public function installer_theme_sets_active_tab_on_init() {
710
-
711
- if ( isset ($_SERVER ['REQUEST_URI']) ) {
712
- $request_uri = $_SERVER ['REQUEST_URI'];
713
- if ( isset ($_GET ['browse']) ) {
714
- $active_tab = sanitize_text_field( $_GET['browse'] );
715
- $this->installer_theme_active_tab = $active_tab;
716
- } elseif ( isset ($_POST ['request'] ['browse']) ) {
717
- $active_tab = sanitize_text_field ( $_POST['request']['browse'] );
718
- $this->installer_theme_active_tab = $active_tab;
719
- } elseif ( (isset ($_GET ['theme_repo'])) && (isset ($_GET ['action'])) ) {
720
- $theme_repo = sanitize_text_field( $_GET['theme_repo'] );
721
- $the_action = sanitize_text_field( $_GET['action'] );
722
- if ( ('install-theme' == $the_action) && (!(empty($theme_repo))) ) {
723
- $this->installer_theme_active_tab = $theme_repo;
724
- }
725
- } elseif ( wp_get_referer() ) {
726
- $referer = wp_get_referer();
727
- $parts = parse_url( $referer );
728
- if ( isset($parts['query']) ) {
729
- parse_str( $parts['query'], $query );
730
- if ( isset($query['browse']) ) {
731
- $this->installer_theme_active_tab = $query['browse'];
732
- }
733
- }
734
- }
735
- }
736
- }
737
-
738
- /** WP Theme API compatibility- added num ratings */
739
- /** Installer 1.7.6+ Added updated 'rating' field */
740
- public function installer_theme_add_num_ratings( $themes ) {
741
-
742
- if ( (is_array( $themes )) && (!(empty($themes))) ) {
743
- foreach ( $themes as $k => $v ) {
744
- if ( !(isset($v->num_ratings)) ) {
745
- $themes[$k]->num_ratings = 100;
746
- }
747
- if ( !(isset($v->rating)) ) {
748
- $themes[$k]->rating = 100;
749
- }
750
- }
751
- }
752
-
753
- return $themes;
754
- }
755
-
756
- /** When WordPress.org makes a call to its repository, let's run our own upgrade checks too */
757
- public function installer_theme_sync_call_wp_theme_api( $locales ) {
758
-
759
- $this->installer_theme_upgrade_theme_check();
760
-
761
- return $locales;
762
- }
763
-
764
- /** Upgrade theme check */
765
- private function installer_theme_upgrade_theme_check() {
766
-
767
- // Step1-> we get all installed themes in clients local themes directory
768
- $installed_themes = wp_get_themes();
769
-
770
- // Step2: We need to loop through each repository with themes
771
- foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
772
-
773
- // We then need to retrieved the products URL for each of this repo
774
- $products_url = $this->repository_theme_products [$repo_slug];
775
-
776
- // Step3-> we get all available themes in our repository via API based on this URL
777
- $available_themes = $this->installer_theme_get_themes( $products_url, $repo_slug );
778
-
779
- if ( !($available_themes) ) {
780
-
781
- // API is not available as of the moment, return..
782
- return;
783
- } else {
784
-
785
- // We have available themes here...
786
- // Step4->let's simplify available themes data by slugs
787
- $simplified_available_themes = $this->installer_theme_savethemes_by_slug( $available_themes, true );
788
-
789
- // Step5->Let's loop through installed themes
790
- if ( (is_array( $installed_themes )) && (!(empty ($installed_themes))) ) {
791
- $otgs_theme_updates_available = array();
792
- foreach ( $installed_themes as $theme_slug => $theme_object ) {
793
- if ( array_key_exists( $theme_slug, $simplified_available_themes ) ) {
794
-
795
- // This is our theme
796
- // Step6->Let's get version of the local theme installed
797
- $local_version = $theme_object->get( 'Version' );
798
-
799
- // Step7->Let's get the latest version of this theme, page URL and download URL from our repository
800
- $repository_version = $simplified_available_themes [$theme_slug] ['version'];
801
- $theme_page_url = $simplified_available_themes [$theme_slug] ['theme_page_url'];
802
- $theme_download_url = $simplified_available_themes [$theme_slug] ['url'];
803
-
804
- // Step8->Let's compare the version
805
- if ( version_compare( $repository_version, $local_version, '>' ) ) {
806
-
807
- // Update available for this theme
808
- // Step9-> Define download URL with site key
809
- $package_url = WP_Installer()->append_site_key_to_download_url( $theme_download_url, $this->installer_site_key [$repo_slug], $repo_slug );
810
-
811
- //Step10-> Assign to updates array for later accessing.
812
- $otgs_theme_updates_available[$theme_slug] = array(
813
- 'theme' => $theme_slug,
814
- 'new_version' => $repository_version,
815
- 'url' => $theme_page_url,
816
- 'package' => $package_url
817
- );
818
- }
819
- }
820
- }
821
- //Exited the upgrade loop for this specific theme repository
822
- if ( !(empty($otgs_theme_updates_available)) ) {
823
- //Has updates
824
- update_option( $this->installer_themes_available_updates[$repo_slug], $otgs_theme_updates_available );
825
- } else {
826
- //No updates
827
- delete_option( $this->installer_themes_available_updates[$repo_slug] );
828
- }
829
-
830
- }
831
- }
832
- }
833
- }
834
-
835
- /** When the user is on Themes install page OTG themes repository, let's the currently selected tab */
836
- public function installer_theme_add_query_arg_tab( $url, $path, $blog_id = null ) {
837
-
838
- $wp_install_string = 'update.php?action=install-theme';
839
- if ( $path == $wp_install_string ) {
840
- if ( isset($this->installer_theme_active_tab) ) {
841
- if ( !(empty($this->installer_theme_active_tab)) ) {
842
- $url = add_query_arg( array(
843
- 'theme_repo' => $this->installer_theme_active_tab
844
- ), $url );
845
- }
846
- }
847
- }
848
- return $url;
849
- }
850
-
851
- /** Save frontend theme tab selected */
852
- public function installer_theme_frontend_selected_tab() {
853
- if ( isset($_POST["frontend_tab_selected"]) ) {
854
- check_ajax_referer( 'installer_theme_frontend_selected_tab', 'installer_theme_frontend_selected_tab_nonce' );
855
-
856
- //Client_side_active_tab
857
- $frontend_tab_selected = sanitize_text_field( $_POST['frontend_tab_selected'] );
858
- if ( !(empty($frontend_tab_selected)) ) {
859
- //Front end tab selected
860
- update_option( 'wp_installer_clientside_active_tab', $frontend_tab_selected, false );
861
-
862
- //Check for registration status
863
- if ( isset($this->theme_user_registration[$frontend_tab_selected]) ) {
864
- //Set
865
- if ( !($this->theme_user_registration[$frontend_tab_selected]) ) {
866
- //Not registered yet
867
-
868
- if ( is_multisite() ) {
869
- $admin_url_passed = network_admin_url();
870
- } else {
871
- $admin_url_passed = admin_url();
872
- }
873
-
874
- $registration_url = $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $frontend_tab_selected;
875
-
876
- //Message and link
877
- $theme_repo_name = $this->installer_theme_get_repo_product_name( $frontend_tab_selected );;
878
- $response['unregistered_messages'] = sprintf( __( 'To install and update %s, please %sregister%s %s for this site.', 'installer' ),
879
- $theme_repo_name, '<a href="' . $registration_url . '">', '</a>', $theme_repo_name );
880
-
881
- }
882
- }
883
-
884
- $response['output'] = $frontend_tab_selected;
885
- echo json_encode( $response );
886
- }
887
- die();
888
- }
889
- die();
890
- }
891
-
892
- /** Installer loaded aux hooks */
893
- public function installer_theme_loaded_hooks() {
894
-
895
- if ( isset($this->installer_theme_subscription_type) ) {
896
- $subscription_type = intval( $this->installer_theme_subscription_type );
897
- if ( $subscription_type > 0 ) {
898
- //Client is subscribed
899
- add_filter( 'installer_theme_get_themes', array($this, 'installer_theme_filter_themes_by_subscription'), 10, 2 );
900
- }
901
- }
902
-
903
- }
904
-
905
- /** Get themes by subscription type */
906
- protected function installer_theme_get_themes_by_subscription( $subscription_type, $repo ) {
907
-
908
- $themes_associated_with_subscription = array();
909
- if ( isset(WP_Installer()->settings['repositories'][$repo]['data']['packages']) ) {
910
- //Set
911
- $packages = WP_Installer()->settings['repositories'][$repo]['data']['packages'];
912
- $available_themes_subscription = array();
913
- foreach ( $packages as $package_id => $package_details ) {
914
- if ( isset($package_details['products']) ) {
915
- $the_products = $package_details['products'];
916
- foreach ( $the_products as $product_slug => $product_details ) {
917
- if ( isset($product_details['subscription_type']) ) {
918
- $subscription_type_from_settings = intval( $product_details['subscription_type'] );
919
- if ( $subscription_type_from_settings == $subscription_type ) {
920
- //We found the subscription
921
- if ( isset($product_details['themes']) ) {
922
- $themes_associated_with_subscription = $product_details['themes'];
923
- return $themes_associated_with_subscription;
924
- }
925
- }
926
- }
927
-
928
- }
929
- }
930
- }
931
- }
932
- return $themes_associated_with_subscription;
933
- }
934
-
935
- /** Filter API theme response according to user subscription */
936
- public function installer_theme_filter_themes_by_subscription( $themes, $active_tab ) {
937
-
938
- //Step1, we only filter OTGS themes
939
- $orig = count( $themes );
940
- if ( in_array( $active_tab, $this->theme_repo ) ) {
941
- //OTGS Theme
942
- //Step2, we retrieved the available themes based on client subscription
943
- if ( isset($this->installer_themes[$active_tab]) ) {
944
- $available_themes = $this->installer_themes[$active_tab];
945
- //Step3, we filter $themes based on this info
946
- if ( (is_array( $themes )) && (!(empty($themes))) ) {
947
- foreach ( $themes as $k => $theme ) {
948
- //Step4, get theme slug
949
- if ( isset($theme['slug']) ) {
950
- $theme_slug = $theme['slug'];
951
- if ( !(empty($theme_slug)) ) {
952
- if ( !(in_array( $theme_slug, $available_themes )) ) {
953
- //This theme is not in available themes
954
- unset($themes[$k]);
955
- }
956
- }
957
- }
958
- }
959
- }
960
- }
961
- }
962
- $new = count( $themes );
963
- if ( $orig != $new ) {
964
- //It is filtered
965
- $themes = array_values( $themes );
966
- }
967
-
968
- return $themes;
969
- }
970
-
971
- /** Hook to wp_loaded, fires when all Installer theme class is ready */
972
- public function installer_themes_support_set_up_func() {
973
- do_action( 'installer_themes_support_set_up' );
974
- }
975
-
976
- }
977
-
978
- /** Instantiate Installer Theme Class */
979
  new Installer_Theme_Class;
1
+ <?php
2
+ /**
3
+ * Installer Class for Theme Support
4
+ *
5
+ * Supports automatic updates and installation of Toolset/WPML Themes
6
+ *
7
+ * @class Installer_Theme_Class
8
+ * @version 1.6
9
+ * @category Class
10
+ * @author OnTheGoSystems
11
+ */
12
+
13
+ if ( !defined( 'ABSPATH' ) ) {
14
+ exit;
15
+ }
16
+
17
+ /**
18
+ * Installer_Theme_Class
19
+ */
20
+ class Installer_Theme_Class {
21
+
22
+ /** Theme Repository */
23
+ private $theme_repo;
24
+
25
+ /** Repository API */
26
+ private $repository_api;
27
+
28
+ /** Repository Theme Products */
29
+ private $repository_theme_products;
30
+
31
+ /** Site URL */
32
+ private $installer_site_url;
33
+
34
+ /** Site Key */
35
+ private $installer_site_key;
36
+
37
+ /** The Themes Option */
38
+ protected $installer_themes_option;
39
+
40
+ /** Update settings */
41
+ protected $installer_themes_available_updates;
42
+
43
+ /** The Themes */
44
+ protected $installer_themes = array();
45
+
46
+ /** Repository with themes */
47
+ protected $installer_repo_with_themes;
48
+
49
+ /** Active tab */
50
+ protected $installer_theme_active_tab;
51
+
52
+ /** Theme user registration */
53
+ protected $theme_user_registration;
54
+
55
+ /** Client active subscription */
56
+ protected $installer_theme_subscription_type;
57
+
58
+ public function __construct() {
59
+
60
+ /** Properties */
61
+
62
+ //Get installer repositories
63
+ $installer_repositories = WP_Installer()->get_repositories();
64
+
65
+ //Get repos with themes
66
+ $repos_with_themes = $this->installer_theme_reposities_that_has_themes( $installer_repositories );
67
+
68
+ if ( is_array( $repos_with_themes ) ) {
69
+ //Assign to property
70
+ $this->installer_repo_with_themes = $repos_with_themes;
71
+
72
+ //Let's looped through repos with themes
73
+ foreach ( $repos_with_themes as $k => $repo ) {
74
+
75
+ //$repo could be 'toolset' or 'wpml'
76
+ //Assign each repo with theme to property
77
+ $this->theme_repo[] = $repo;
78
+
79
+ if ( (isset($installer_repositories[$repo]['api-url'])) && (isset($installer_repositories[$repo]['products'])) ) {
80
+
81
+ //Define the rest of the properties based on the given repo
82
+ $this->repository_api[$repo] = $installer_repositories[$repo]['api-url'];
83
+ $this->repository_theme_products[$repo] = $installer_repositories[$repo]['products'];
84
+ $this->installer_site_url[$repo] = WP_Installer()->get_installer_site_url( $repo );
85
+ $this->installer_site_key[$repo] = WP_Installer()->get_site_key( $repo );
86
+ $this->theme_user_registration[$repo] = false;
87
+
88
+ if ( WP_Installer()->repository_has_valid_subscription( $repo ) ) {
89
+
90
+ $this->installer_theme_subscription_type = WP_Installer()->get_subscription_type_for_repository( $repo );
91
+ $this->installer_themes_option[$repo] = 'wp_installer_' . $repo . '_themes';
92
+ $this->installer_themes_available_updates[$repo] = 'wp_installer_' . $repo . '_updated_themes';
93
+ $this->installer_theme_active_tab = '';
94
+
95
+ //We only set themes available to this validated subscription
96
+ $this->installer_theme_available( $repo, $this->installer_theme_subscription_type );
97
+
98
+ add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_sets_active_tab_on_init'), 10 );
99
+ $this->theme_user_registration[$repo] = true;
100
+ }
101
+
102
+ /** We are ready.. let's initialize .... */
103
+ $this->init();
104
+ }
105
+ }
106
+ add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_loaded_hooks') );
107
+ }
108
+ }
109
+
110
+ /** Init */
111
+ public function init() {
112
+ add_action( 'admin_enqueue_scripts', array($this, 'installer_theme_enqueue_scripts') );
113
+ add_filter( 'themes_api', array($this, 'installer_theme_api_override'), 10, 3 );
114
+ add_filter( 'themes_api_result', array($this, 'installer_theme_api_override_response'), 10, 3 );
115
+ add_filter( 'site_transient_update_themes', array($this, 'installer_theme_upgrade_check'), 10, 1 );
116
+ add_action( 'http_api_debug', array($this, 'installer_theme_sync_native_wp_api'), 10, 5 );
117
+ add_filter( 'installer_theme_hook_response_theme', array($this, 'installer_theme_add_num_ratings'), 10, 1 );
118
+ add_filter( 'themes_update_check_locales', array($this, 'installer_theme_sync_call_wp_theme_api'), 10, 1 );
119
+ add_filter( 'admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 3 );
120
+ add_filter( 'network_admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 2 );
121
+ add_action( 'wp_ajax_installer_theme_frontend_selected_tab', array($this, 'installer_theme_frontend_selected_tab'), 0 );
122
+ add_action( 'wp_loaded', array($this, 'installer_themes_support_set_up_func') );
123
+ }
124
+
125
+ /** Enqueue scripts */
126
+ public function installer_theme_enqueue_scripts() {
127
+ $current_screen = $this->installer_theme_current_screen();
128
+ $commercial_plugin_screen = $this->installer_theme_is_commercial_plugin_screen( $current_screen );
129
+ if ( ('theme-install' == $current_screen) || ($commercial_plugin_screen) || ('theme-install-network' == $current_screen) ) {
130
+ $repo_with_themes = $this->installer_repo_with_themes;
131
+ $js_array = array();
132
+ if ( is_array( $repo_with_themes ) ) {
133
+ foreach ( $repo_with_themes as $k => $v ) {
134
+
135
+ //Hyperlink text
136
+ $theme_repo_name = $this->installer_theme_get_repo_product_name( $v );
137
+ $the_hyperlink_text = esc_js( $theme_repo_name );
138
+
139
+ if ( is_multisite() ) {
140
+ $admin_url_passed = network_admin_url();
141
+ } else {
142
+ $admin_url_passed = admin_url();
143
+ }
144
+
145
+ //Define
146
+ $js_array[$v] = array(
147
+ 'the_hyperlink_text' => $the_hyperlink_text,
148
+ 'registration_status' => $this->theme_user_registration[$v],
149
+ 'is_commercial_plugin_tab' => $commercial_plugin_screen,
150
+ 'registration_url' => $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $v
151
+ );
152
+
153
+ }
154
+ }
155
+
156
+ if ( !(empty($js_array)) ) {
157
+ wp_enqueue_script( 'installer-theme-install', WP_Installer()->res_url() . '/res/js/installer_theme_install.js', array('jquery', 'installer-admin'), WP_Installer()->version() );
158
+ $installer_ajax_url = admin_url( 'admin-ajax.php' );
159
+
160
+ if ( is_ssl() ) {
161
+ $installer_ajax_url = str_replace( 'http://', 'https://', $installer_ajax_url );
162
+ } else {
163
+ $installer_ajax_url = str_replace( 'https://', 'http://', $installer_ajax_url );
164
+ }
165
+
166
+ //Case where user is subscribed to a subscription that does not have themes
167
+ $subscription_js_check = $this->installer_theme_subscription_does_not_have_theme( $js_array );
168
+
169
+ wp_localize_script( 'installer-theme-install', 'installer_theme_install_localize',
170
+ array(
171
+ 'js_array_installer' => $js_array,
172
+ 'ajaxurl' => $installer_ajax_url,
173
+ 'no_associated_themes' => $subscription_js_check,
174
+ 'installer_theme_frontend_selected_tab_nonce' => wp_create_nonce( 'installer_theme_frontend_selected_tab' )
175
+ )
176
+ );
177
+ }
178
+ }
179
+ }
180
+
181
+ /** Case where user is subscribed to a subscription that does not have themes */
182
+ protected function installer_theme_subscription_does_not_have_theme( $js_array ) {
183
+
184
+ $any_subscription_has_theme = array();
185
+ $number_of_registrations = array();
186
+
187
+ //Step1, we looped through JS array
188
+ foreach ( $js_array as $repo_slug => $js_details ) {
189
+
190
+ //Step2, checked if user is registered
191
+ if ( isset($this->theme_user_registration[$repo_slug]) ) {
192
+ $registration_status = $this->theme_user_registration[$repo_slug];
193
+ if ( $registration_status ) {
194
+
195
+ //Registered
196
+ $number_of_registrations[] = $repo_slug;
197
+
198
+ //Step3, we checked if the $repo_slug has available theme
199
+ $themes_available = false;
200
+ if ( isset($this->installer_themes[$repo_slug]) ) {
201
+ $themes_available = $this->installer_themes[$repo_slug];
202
+ if ( !(empty($themes_available)) ) {
203
+ //This subscription has theme
204
+ $themes_available = true;
205
+ }
206
+ }
207
+
208
+ if ( $themes_available ) {
209
+ $any_subscription_has_theme[] = $repo_slug;
210
+ }
211
+ }
212
+ }
213
+
214
+ }
215
+
216
+ //Step4, we are done looping, check if there are any repos that have themes
217
+ if ( empty($registration_status) ) {
218
+
219
+ //No registration on any repos
220
+ return FALSE;
221
+
222
+ } elseif ( !(empty($registration_status)) ) {
223
+
224
+ //Has some registration on some repos
225
+ //We then checked if this user has any active subscriptions
226
+ if ( empty($any_subscription_has_theme) ) {
227
+ //No subscription
228
+ return TRUE;
229
+ } else {
230
+ //Has subscription found
231
+ return FALSE;
232
+ }
233
+ }
234
+ }
235
+
236
+ /** Check if its the commercial plugin screen */
237
+ private function installer_theme_is_commercial_plugin_screen( $current_screen ) {
238
+ $commercial = false;
239
+ if ( ('plugin-install' == $current_screen) || ('plugin-install-network' == $current_screen) ) {
240
+ if ( isset($_GET['tab']) ) {
241
+ $tab = sanitize_text_field( $_GET['tab'] );
242
+ if ( 'commercial' == $tab ) {
243
+ $commercial = true;
244
+ }
245
+ }
246
+ }
247
+ return $commercial;
248
+ }
249
+
250
+ /** Current screen */
251
+ private function installer_theme_current_screen() {
252
+
253
+ $current_screen_loaded = false;
254
+
255
+ if ( function_exists( 'get_current_screen' ) ) {
256
+
257
+ $screen_output = get_current_screen();
258
+ $current_screen_loaded = $screen_output->id;
259
+
260
+ }
261
+
262
+ return $current_screen_loaded;
263
+
264
+ }
265
+
266
+ /** Override WordPress Themes API */
267
+ public function installer_theme_api_override( $api_boolean, $action, $args ) {
268
+
269
+ //Let's checked if user is browsing our themes
270
+ if ( isset($args->browse) ) {
271
+ $browse = $args->browse;
272
+ if ( in_array( $browse, $this->theme_repo ) ) {
273
+ //Uniquely validated for our Themes
274
+ if ( 'query_themes' == $action ) {
275
+ //User is querying or asking information about our themes, let's override
276
+ $api_boolean = true;
277
+ }
278
+ }
279
+ } elseif ( isset($args->slug) ) {
280
+ //We are installing our themes
281
+ $theme_to_install = $args->slug;
282
+
283
+ //Lets uniquely validate if this belongs to us
284
+ //Check if this is OTGS theme
285
+ $validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
286
+ if ( $validate_check ) {
287
+ //Belongs to us
288
+ if ( !(empty($theme_to_install)) ) {
289
+ $api_boolean = true;
290
+ }
291
+ }
292
+ }
293
+
294
+ return $api_boolean;
295
+ }
296
+
297
+ /** Override WordPress Themes API response with our own themes API*/
298
+ public function installer_theme_api_override_response( $res, $action, $args ) {
299
+
300
+ if ( true === $res ) {
301
+ if ( isset($args->browse) ) {
302
+ $browse = $args->browse;
303
+ if ( in_array( $browse, $this->theme_repo ) ) {
304
+ //Uniquely validated for our themes
305
+ if ( 'query_themes' == $action ) {
306
+ //Client querying OTGS themes
307
+ //Check for registration status
308
+ if ( isset($this->theme_user_registration[$browse]) ) {
309
+ //Set
310
+ if ( !($this->theme_user_registration[$browse]) ) {
311
+ //Not registered yet
312
+ $res = new stdClass();
313
+ $res->info = array();
314
+ $res->themes = array();
315
+ return $res;
316
+ } else {
317
+ //Registered
318
+ $themes = $this->installer_theme_get_themes( '', $browse );
319
+ $res = $this->installer_theme_format_response( $themes, $action );
320
+ }
321
+ }
322
+ }
323
+ }
324
+ } elseif ( isset($args->slug) ) {
325
+ //We are installing theme
326
+ //Lets uniquely validate if this belongs to our theme
327
+ $theme_to_install = $args->slug;
328
+
329
+ //Lets uniquely validate if this belongs to us
330
+ //Check if this is OTGS theme
331
+ $validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
332
+ if ( $validate_check ) {
333
+ //Belongs to us
334
+ if ( ($res) && ('theme_information' == $action) ) {
335
+ $themes = $this->installer_theme_get_themes( '', $this->installer_theme_active_tab );
336
+ $res = $this->installer_theme_format_response( $themes, $action, $args->slug );
337
+ }
338
+ }
339
+ }
340
+ return $res;
341
+ } else {
342
+ //Default WP Themes here
343
+ $client_side_active_tab = get_option( 'wp_installer_clientside_active_tab' );
344
+ if ( $client_side_active_tab ) {
345
+ if ( !(in_array( $client_side_active_tab, $this->theme_repo )) ) {
346
+ //Not OTGS tab
347
+ return $res;
348
+ }
349
+ }
350
+
351
+ }
352
+ }
353
+
354
+ /** Get Themes */
355
+ private function installer_theme_get_themes( $product_url = '', $repo_source = '' ) {
356
+
357
+ //Query API
358
+ if ( empty($product_url) ) {
359
+ //Not set
360
+ if ( isset($this->repository_theme_products[$this->installer_theme_active_tab]) ) {
361
+ $query_remote_url = $this->repository_theme_products[$this->installer_theme_active_tab];
362
+ }
363
+
364
+ } else {
365
+ $query_remote_url = $product_url;
366
+ }
367
+
368
+ //Let's retrieved current installer settings so we won't be querying all the time
369
+ $current_installer_settings = WP_Installer()->get_settings();
370
+
371
+ //Set $themes to FALSE by default
372
+ $themes = false;
373
+
374
+ if ( (is_array( $current_installer_settings )) && (!(empty($current_installer_settings))) ) {
375
+
376
+ //Set and already defined, retrieved $products
377
+ if ( isset($current_installer_settings['repositories'][$repo_source]['data']) ) {
378
+ $products = $current_installer_settings['repositories'][$repo_source]['data'];
379
+ if ( isset($products['downloads']['themes']) ) {
380
+ $themes = $products['downloads']['themes'];
381
+ }
382
+ }
383
+
384
+ } else {
385
+
386
+ //Call API
387
+ $response = wp_remote_get( $query_remote_url );
388
+
389
+ if ( is_wp_error( $response ) ) {
390
+ //Error detected: http fallback
391
+ $query_remote_url = preg_replace( "@^https://@", 'http://', $query_remote_url );
392
+ $response = wp_remote_get( $query_remote_url );
393
+ }
394
+
395
+ if ( !(is_wp_error( $response )) ) {
396
+ //Not WP error
397
+ //Evaluate response
398
+ if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
399
+ //In this case, response is set and defined, proceed...
400
+ $body = wp_remote_retrieve_body( $response );
401
+ if ( $body ) {
402
+ $products = json_decode( $body, true );
403
+ if ( isset($products['downloads']['themes']) ) {
404
+ $themes = $products['downloads']['themes'];
405
+ }
406
+ }
407
+
408
+ }
409
+ }
410
+ }
411
+
412
+ //Return themes, can be filtered by user subscription type
413
+ return apply_filters( 'installer_theme_get_themes', $themes, $this->installer_theme_active_tab );
414
+ }
415
+
416
+ /** Format response in compatibility with WordPress Theme API response */
417
+ private function installer_theme_format_response( $themes, $action, $slug = '' ) {
418
+
419
+ //Let's append download link only when retrieving theme information for installation
420
+ if ( ('theme_information' == $action) && (!(empty($slug))) ) {
421
+
422
+ //Only return one result -> the theme to be installed
423
+ foreach ( $themes as $k => $theme ) {
424
+ if ( $slug == $theme['basename'] ) {
425
+ $theme['download_link'] = WP_Installer()->append_site_key_to_download_url( $theme['url'], $this->installer_site_key[$this->installer_theme_active_tab], $this->installer_theme_active_tab );
426
+ $theme = json_decode( json_encode( $theme ), FALSE );
427
+ return $theme;
428
+ }
429
+ }
430
+
431
+ } else {
432
+
433
+ $res = new stdClass();
434
+ $res->info = array();
435
+ $res->themes = array();
436
+
437
+ //Define info
438
+ $res->info['page'] = 1;
439
+ $res->info['pages'] = 10;
440
+
441
+ //Let's count available themes ;
442
+ $res->info['results'] = count( $themes );
443
+
444
+ //Let's saved themes for easy access later on
445
+ $this->installer_theme_savethemes_by_slug( $themes );
446
+
447
+ //Let's defined available themes
448
+ if ( isset($this->installer_theme_subscription_type) ) {
449
+ //Has subscription type defined, let's saved what is associated with this subscription
450
+ $this->installer_theme_available( $this->installer_theme_active_tab, $this->installer_theme_subscription_type );
451
+ } else {
452
+ $this->installer_theme_available( $this->installer_theme_active_tab );
453
+ }
454
+
455
+ //Let's add themes to the overriden WordPress API Theme response
456
+ /** Installer 1.7.6: Update to compatible data format response from WP Theme API */
457
+ $theme_compatible_array=array();
458
+ if ((is_array($themes))) {
459
+ foreach ($themes as $k=>$v) {
460
+ $theme_compatible_array[]=(object)($v);
461
+ }
462
+ }
463
+ $res->themes = $theme_compatible_array;
464
+ $res->themes = apply_filters( 'installer_theme_hook_response_theme', $res->themes );
465
+ return $res;
466
+ }
467
+ }
468
+
469
+ /** Let's save all available themes by its slug after any latest API query */
470
+ private function installer_theme_savethemes_by_slug( $themes, $doing_query = false ) {
471
+
472
+ if ( !($doing_query) ) {
473
+ $this->installer_themes[$this->installer_theme_active_tab] = array();
474
+ }
475
+
476
+ if ( !(empty($themes)) ) {
477
+ $themes_for_saving = array();
478
+ foreach ( $themes as $k => $theme ) {
479
+ if ( !($doing_query) ) {
480
+ if ( isset($theme['slug']) ) {
481
+ $theme_slug = $theme['slug'];
482
+ if ( !(empty($theme_slug)) ) {
483
+ $themes_for_saving[] = $theme_slug;
484
+ }
485
+ }
486
+ } else {
487
+
488
+ if ( ((isset($theme['slug'])) && (isset($theme['version'])) &&
489
+ (isset($theme['theme_page_url']))) && (isset($theme['url']))
490
+ ) {
491
+ $theme_slug = $theme['slug'];
492
+ $theme_version = $theme['version'];
493
+ $theme_page_url = $theme['theme_page_url'];
494
+ $theme_url = $theme['url'];
495
+ if ( (!(empty($theme_slug))) && (!(empty($theme_version))) &&
496
+ (!(empty($theme_page_url))) && (!(empty($theme_url)))
497
+ ) {
498
+ //$theme_slug is unique for every theme
499
+ $themes_for_saving[$theme_slug] = array(
500
+ 'version' => $theme_version,
501
+ 'theme_page_url' => $theme_page_url,
502
+ 'url' => $theme_url
503
+ );
504
+
505
+ }
506
+ }
507
+ }
508
+
509
+ }
510
+
511
+ if ( !(empty($themes_for_saving)) ) {
512
+ //Has themes for saving
513
+ if ( !($doing_query) ) {
514
+ //Not doing query
515
+ $existing_themes = get_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
516
+ if ( !($existing_themes) ) {
517
+ //Does not yet exists
518
+ delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
519
+ update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
520
+ } else {
521
+ //exists, check if we need to update
522
+ if ( $existing_themes == $themes_for_saving ) {
523
+ //Equal, no need to update here
524
+ } else {
525
+ //Update
526
+ delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
527
+ update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
528
+ }
529
+ }
530
+ } else {
531
+ //Used for query purposes only, don't save anything
532
+ return $themes_for_saving;
533
+ }
534
+ }
535
+ }
536
+ }
537
+
538
+ /** Available themes */
539
+ private function installer_theme_available( $repo, $subscription_type = '' ) {
540
+
541
+ $subscription_type = intval( $subscription_type );
542
+ if ( $subscription_type > 0 ) {
543
+
544
+ //Here we have a case of validated subscription
545
+ //We need to set themes that is available to this subscription
546
+ $themes_associated_with_subscription = $this->installer_themes[$repo] = $this->installer_theme_get_themes_by_subscription( $subscription_type, $repo );
547
+ if ( !(empty($themes_associated_with_subscription)) ) {
548
+ //Has themes
549
+ $this->installer_themes[$repo] = $themes_associated_with_subscription;
550
+ }
551
+ } else {
552
+
553
+ //Get themes
554
+ $this->installer_themes[$repo] = get_option( $this->installer_themes_option[$repo] );
555
+ }
556
+ }
557
+
558
+ /** Theme upgrade check */
559
+ public function installer_theme_upgrade_check( $the_value ) {
560
+
561
+ //Step1: Let's looped through repos with themes and check if we have updates available for them.
562
+ if ( (is_array( $this->installer_repo_with_themes )) && (!(empty($this->installer_repo_with_themes))) ) {
563
+ foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
564
+ //Step2: Let's checked if we have update for this theme
565
+ $update_available = get_option( $this->installer_themes_available_updates[$repo_slug] );
566
+ if ( $update_available ) {
567
+ if ( (is_array( $update_available )) && (!(empty($update_available))) ) {
568
+ //Has updates available coming from this specific theme repo
569
+ //Let's loop through the themes that needs update
570
+ foreach ( $update_available as $theme_slug => $v ) {
571
+ //Add to response API
572
+ $the_value->response [$theme_slug] = array(
573
+ 'theme' => $theme_slug,
574
+ 'new_version' => $v['new_version'],
575
+ 'url' => $v['url'],
576
+ 'package' => $v['package']
577
+ );
578
+ }
579
+ }
580
+ }
581
+ }
582
+ }
583
+ //Return
584
+ return $the_value;
585
+ }
586
+
587
+ /** Return repositories that has themes */
588
+ private function installer_theme_reposities_that_has_themes( $repositories, $ret_value = true, $doing_api_query = false ) {
589
+
590
+ $repositories_with_themes = array();
591
+
592
+ if ( (is_array( $repositories )) && (!(empty($repositories))) ) {
593
+
594
+ //Let's checked if we have something before
595
+ $themes = get_option( 'installer_repositories_with_theme' );
596
+
597
+ if ( (!($themes)) || ($doing_api_query) ) {
598
+ //Not yet defined
599
+ //Loop through each repositories and check whether they have themes
600
+ foreach ( $repositories as $k => $v ) {
601
+ if ( isset($v['products']) ) {
602
+ $products_url = $v['products'];
603
+ $themes = $this->installer_theme_get_themes( $products_url, $k );
604
+ if ( (is_array( $themes )) && (!(empty($themes))) ) {
605
+ //Repo has themes
606
+ $repositories_with_themes[] = $k;
607
+ }
608
+ }
609
+ }
610
+ } else {
611
+ //Already set
612
+ $repositories_with_themes = $themes;
613
+ }
614
+
615
+ if ( (((is_array( $repositories_with_themes )) && (!(empty($repositories_with_themes)))) && (!($themes))) || ($doing_api_query) ) {
616
+ //Save to db
617
+ update_option( 'installer_repositories_with_theme', $repositories_with_themes );
618
+ }
619
+ }
620
+
621
+ if ( $ret_value ) {
622
+ return $repositories_with_themes;
623
+ }
624
+
625
+ }
626
+
627
+ /** When WordPress queries its own Themes API, we sync with our own */
628
+ public function installer_theme_sync_native_wp_api( $response, $responsetext, $class, $args, $url ) {
629
+
630
+ $api_native_string = 'api.wordpress.org/themes/';
631
+ if ( (strpos( $url, $api_native_string ) !== false) ) {
632
+ //WordPress is querying its own themes API
633
+ $installer_repositories = WP_Installer()->get_repositories();
634
+
635
+ //Query our own API and update repository values too
636
+ $this->installer_theme_reposities_that_has_themes( $installer_repositories, false, true );
637
+ }
638
+ }
639
+
640
+ /** Returns product name by theme repo slug */
641
+ private function installer_theme_get_repo_product_name( $theme_repo ) {
642
+
643
+ $theme_repo_name = false;
644
+
645
+ if ( isset(WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name']) ) {
646
+ //Set
647
+ $prod_name = WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name'];
648
+ if ( !(empty($prod_name)) ) {
649
+ $theme_repo_name = $prod_name;
650
+ }
651
+ } else {
652
+ //Not yet
653
+ if ( $theme_repo == $this->theme_repo ) {
654
+ $result = $this->installer_theme_general_api_query();
655
+ if ( isset($result['product-name']) ) {
656
+ $product_name = $result['product-name'];
657
+ if ( !(empty($product_name)) ) {
658
+ $theme_repo_name = $product_name;
659
+ }
660
+ }
661
+ }
662
+ }
663
+
664
+ return $theme_repo_name;
665
+ }
666
+
667
+ /** General query API method, returns $products */
668
+ private function installer_theme_general_api_query() {
669
+ $products = false;
670
+ $response = wp_remote_get( $this->repository_theme_products );
671
+ if ( !(is_wp_error( $response )) ) {
672
+ //Not WP error
673
+ //Evaluate response
674
+ if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
675
+ //In this case, response is set and defined, proceed...
676
+ $body = wp_remote_retrieve_body( $response );
677
+ if ( $body ) {
678
+ $result = json_decode( $body, true );
679
+ if ( (is_array( $result )) && (!(empty($result))) ) {
680
+ $products = $result;
681
+ }
682
+ }
683
+
684
+ }
685
+ }
686
+
687
+ return $products;
688
+ }
689
+
690
+ /** General method to check if themes are OTGS themes based on its slug*/
691
+ private function installer_themes_belong_to_us( $theme_slug ) {
692
+
693
+ $found = false;
694
+ $theme_slug = trim( $theme_slug );
695
+
696
+ foreach ( $this->installer_themes as $repo_with_theme => $themes ) {
697
+ foreach ( $themes as $k => $otgs_theme_slug ) {
698
+ if ( $theme_slug == $otgs_theme_slug ) {
699
+ //match found! Theme belongs to otgs
700
+ return true;
701
+ }
702
+ }
703
+ }
704
+ return $found;
705
+
706
+ }
707
+
708
+ /** Sets active tab on init */
709
+ public function installer_theme_sets_active_tab_on_init() {
710
+
711
+ if ( isset ($_SERVER ['REQUEST_URI']) ) {
712
+ $request_uri = $_SERVER ['REQUEST_URI'];
713
+ if ( isset ($_GET ['browse']) ) {
714
+ $active_tab = sanitize_text_field( $_GET['browse'] );
715
+ $this->installer_theme_active_tab = $active_tab;
716
+ } elseif ( isset ($_POST ['request'] ['browse']) ) {
717
+ $active_tab = sanitize_text_field ( $_POST['request']['browse'] );
718
+ $this->installer_theme_active_tab = $active_tab;
719
+ } elseif ( (isset ($_GET ['theme_repo'])) && (isset ($_GET ['action'])) ) {
720
+ $theme_repo = sanitize_text_field( $_GET['theme_repo'] );
721
+ $the_action = sanitize_text_field( $_GET['action'] );
722
+ if ( ('install-theme' == $the_action) && (!(empty($theme_repo))) ) {
723
+ $this->installer_theme_active_tab = $theme_repo;
724
+ }
725
+ } elseif ( wp_get_referer() ) {
726
+ $referer = wp_get_referer();
727
+ $parts = parse_url( $referer );
728
+ if ( isset($parts['query']) ) {
729
+ parse_str( $parts['query'], $query );
730
+ if ( isset($query['browse']) ) {
731
+ $this->installer_theme_active_tab = $query['browse'];
732
+ }
733
+ }
734
+ }
735
+ }
736
+ }
737
+
738
+ /** WP Theme API compatibility- added num ratings */
739
+ /** Installer 1.7.6+ Added updated 'rating' field */
740
+ public function installer_theme_add_num_ratings( $themes ) {
741
+
742
+ if ( (is_array( $themes )) && (!(empty($themes))) ) {
743
+ foreach ( $themes as $k => $v ) {
744
+ if ( !(isset($v->num_ratings)) ) {
745
+ $themes[$k]->num_ratings = 100;
746
+ }
747
+ if ( !(isset($v->rating)) ) {
748
+ $themes[$k]->rating = 100;
749
+ }
750
+ }
751
+ }
752
+
753
+ return $themes;
754
+ }
755
+
756
+ /** When WordPress.org makes a call to its repository, let's run our own upgrade checks too */
757
+ public function installer_theme_sync_call_wp_theme_api( $locales ) {
758
+
759
+ $this->installer_theme_upgrade_theme_check();
760
+
761
+ return $locales;
762
+ }
763
+
764
+ /** Upgrade theme check */
765
+ private function installer_theme_upgrade_theme_check() {
766
+
767
+ // Step1-> we get all installed themes in clients local themes directory
768
+ $installed_themes = wp_get_themes();
769
+
770
+ // Step2: We need to loop through each repository with themes
771
+ foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
772
+
773
+ // We then need to retrieved the products URL for each of this repo
774
+ $products_url = $this->repository_theme_products [$repo_slug];
775
+
776
+ // Step3-> we get all available themes in our repository via API based on this URL
777
+ $available_themes = $this->installer_theme_get_themes( $products_url, $repo_slug );
778
+
779
+ if ( !($available_themes) ) {
780
+
781
+ // API is not available as of the moment, return..
782
+ return;
783
+ } else {
784
+
785
+ // We have available themes here...
786
+ // Step4->let's simplify available themes data by slugs
787
+ $simplified_available_themes = $this->installer_theme_savethemes_by_slug( $available_themes, true );
788
+
789
+ // Step5->Let's loop through installed themes
790
+ if ( (is_array( $installed_themes )) && (!(empty ($installed_themes))) ) {
791
+ $otgs_theme_updates_available = array();
792
+ foreach ( $installed_themes as $theme_slug => $theme_object ) {
793
+ if ( array_key_exists( $theme_slug, $simplified_available_themes ) ) {
794
+
795
+ // This is our theme
796
+ // Step6->Let's get version of the local theme installed
797
+ $local_version = $theme_object->get( 'Version' );
798
+
799
+ // Step7->Let's get the latest version of this theme, page URL and download URL from our repository
800
+ $repository_version = $simplified_available_themes [$theme_slug] ['version'];
801
+ $theme_page_url = $simplified_available_themes [$theme_slug] ['theme_page_url'];
802
+ $theme_download_url = $simplified_available_themes [$theme_slug] ['url'];
803
+
804
+ // Step8->Let's compare the version
805
+ if ( version_compare( $repository_version, $local_version, '>' ) ) {
806
+
807
+ // Update available for this theme
808
+ // Step9-> Define download URL with site key
809
+ $package_url = WP_Installer()->append_site_key_to_download_url( $theme_download_url, $this->installer_site_key [$repo_slug], $repo_slug );
810
+
811
+ //Step10-> Assign to updates array for later accessing.
812
+ $otgs_theme_updates_available[$theme_slug] = array(
813
+ 'theme' => $theme_slug,
814
+ 'new_version' => $repository_version,
815
+ 'url' => $theme_page_url,
816
+ 'package' => $package_url
817
+ );
818
+ }
819
+ }
820
+ }
821
+ //Exited the upgrade loop for this specific theme repository
822
+ if ( !(empty($otgs_theme_updates_available)) ) {
823
+ //Has updates
824
+ update_option( $this->installer_themes_available_updates[$repo_slug], $otgs_theme_updates_available );
825
+ } else {
826
+ //No updates
827
+ delete_option( $this->installer_themes_available_updates[$repo_slug] );
828
+ }
829
+
830
+ }
831
+ }
832
+ }
833
+ }
834
+
835
+ /** When the user is on Themes install page OTG themes repository, let's the currently selected tab */
836
+ public function installer_theme_add_query_arg_tab( $url, $path, $blog_id = null ) {
837
+
838
+ $wp_install_string = 'update.php?action=install-theme';
839
+ if ( $path == $wp_install_string ) {
840
+ if ( isset($this->installer_theme_active_tab) ) {
841
+ if ( !(empty($this->installer_theme_active_tab)) ) {
842
+ $url = add_query_arg( array(
843
+ 'theme_repo' => $this->installer_theme_active_tab
844
+ ), $url );
845
+ }
846
+ }
847
+ }
848
+ return $url;
849
+ }
850
+
851
+ /** Save frontend theme tab selected */
852
+ public function installer_theme_frontend_selected_tab() {
853
+ if ( isset($_POST["frontend_tab_selected"]) ) {
854
+ check_ajax_referer( 'installer_theme_frontend_selected_tab', 'installer_theme_frontend_selected_tab_nonce' );
855
+
856
+ //Client_side_active_tab
857
+ $frontend_tab_selected = sanitize_text_field( $_POST['frontend_tab_selected'] );
858
+ if ( !(empty($frontend_tab_selected)) ) {
859
+ //Front end tab selected
860
+ update_option( 'wp_installer_clientside_active_tab', $frontend_tab_selected, false );
861
+
862
+ //Check for registration status
863
+ if ( isset($this->theme_user_registration[$frontend_tab_selected]) ) {
864
+ //Set
865
+ if ( !($this->theme_user_registration[$frontend_tab_selected]) ) {
866
+ //Not registered yet
867
+
868
+ if ( is_multisite() ) {
869
+ $admin_url_passed = network_admin_url();
870
+ } else {
871
+ $admin_url_passed = admin_url();
872
+ }
873
+
874
+ $registration_url = $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $frontend_tab_selected;
875
+
876
+ //Message and link
877
+ $theme_repo_name = $this->installer_theme_get_repo_product_name( $frontend_tab_selected );;
878
+ $response['unregistered_messages'] = sprintf( __( 'To install and update %s, please %sregister%s %s for this site.', 'installer' ),
879
+ $theme_repo_name, '<a href="' . $registration_url . '">', '</a>', $theme_repo_name );
880
+
881
+ }
882
+ }
883
+
884
+ $response['output'] = $frontend_tab_selected;
885
+ echo json_encode( $response );
886
+ }
887
+ die();
888
+ }
889
+ die();
890
+ }
891
+
892
+ /** Installer loaded aux hooks */
893
+ public function installer_theme_loaded_hooks() {
894
+
895
+ if ( isset($this->installer_theme_subscription_type) ) {
896
+ $subscription_type = intval( $this->installer_theme_subscription_type );
897
+ if ( $subscription_type > 0 ) {
898
+ //Client is subscribed
899
+ add_filter( 'installer_theme_get_themes', array($this, 'installer_theme_filter_themes_by_subscription'), 10, 2 );
900
+ }
901
+ }
902
+
903
+ }
904
+
905
+ /** Get themes by subscription type */
906
+ protected function installer_theme_get_themes_by_subscription( $subscription_type, $repo ) {
907
+
908
+ $themes_associated_with_subscription = array();
909
+ if ( isset(WP_Installer()->settings['repositories'][$repo]['data']['packages']) ) {
910
+ //Set
911
+ $packages = WP_Installer()->settings['repositories'][$repo]['data']['packages'];
912
+ $available_themes_subscription = array();
913
+ foreach ( $packages as $package_id => $package_details ) {
914
+ if ( isset($package_details['products']) ) {
915
+ $the_products = $package_details['products'];
916
+ foreach ( $the_products as $product_slug => $product_details ) {
917
+ if ( isset($product_details['subscription_type']) ) {
918
+ $subscription_type_from_settings = intval( $product_details['subscription_type'] );
919
+ if ( $subscription_type_from_settings == $subscription_type ) {
920
+ //We found the subscription
921
+ if ( isset($product_details['themes']) ) {
922
+ $themes_associated_with_subscription = $product_details['themes'];
923
+ return $themes_associated_with_subscription;
924
+ }
925
+ }
926
+ }
927
+
928
+ }
929
+ }
930
+ }
931
+ }
932
+ return $themes_associated_with_subscription;
933
+ }
934
+
935
+ /** Filter API theme response according to user subscription */
936
+ public function installer_theme_filter_themes_by_subscription( $themes, $active_tab ) {
937
+
938
+ //Step1, we only filter OTGS themes
939
+ $orig = count( $themes );
940
+ if ( in_array( $active_tab, $this->theme_repo ) ) {
941
+ //OTGS Theme
942
+ //Step2, we retrieved the available themes based on client subscription
943
+ if ( isset($this->installer_themes[$active_tab]) ) {
944
+ $available_themes = $this->installer_themes[$active_tab];
945
+ //Step3, we filter $themes based on this info
946
+ if ( (is_array( $themes )) && (!(empty($themes))) ) {
947
+ foreach ( $themes as $k => $theme ) {
948
+ //Step4, get theme slug
949
+ if ( isset($theme['slug']) ) {
950
+ $theme_slug = $theme['slug'];
951
+ if ( !(empty($theme_slug)) ) {
952
+ if ( !(in_array( $theme_slug, $available_themes )) ) {
953
+ //This theme is not in available themes
954
+ unset($themes[$k]);
955
+ }
956
+ }
957
+ }
958
+ }
959
+ }
960
+ }
961
+ }
962
+ $new = count( $themes );
963
+ if ( $orig != $new ) {
964
+ //It is filtered
965
+ $themes = array_values( $themes );
966
+ }
967
+
968
+ return $themes;
969
+ }
970
+
971
+ /** Hook to wp_loaded, fires when all Installer theme class is ready */
972
+ public function installer_themes_support_set_up_func() {
973
+ do_action( 'installer_themes_support_set_up' );
974
+ }
975
+
976
+ }
977
+
978
+ /** Instantiate Installer Theme Class */
979
  new Installer_Theme_Class;
vendor/otgs/installer/includes/class-installer-upgrader-skins.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
-
3
- class Installer_Upgrader_Skins extends WP_Upgrader_Skin {
4
-
5
- function __construct( $args = array() ) {
6
- $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
7
- $this->options = wp_parse_args( $args, $defaults );
8
- }
9
-
10
- function header() {
11
-
12
- }
13
-
14
- function footer() {
15
-
16
- }
17
-
18
- function error( $error ) {
19
- $this->installer_error = $error;
20
- }
21
-
22
- function add_strings() {
23
-
24
- }
25
-
26
- function feedback( $string ) {
27
-
28
- }
29
-
30
- function before() {
31
-
32
- }
33
-
34
- function after() {
35
-
36
- }
37
-
38
  }
1
+ <?php
2
+
3
+ class Installer_Upgrader_Skins extends WP_Upgrader_Skin {
4
+
5
+ function __construct( $args = array() ) {
6
+ $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
7
+ $this->options = wp_parse_args( $args, $defaults );
8
+ }
9
+
10
+ function header() {
11
+
12
+ }
13
+
14
+ function footer() {
15
+
16
+ }
17
+
18
+ function error( $error ) {
19
+ $this->installer_error = $error;
20
+ }
21
+
22
+ function add_strings() {
23
+
24
+ }
25
+
26
+ function feedback( $string ) {
27
+
28
+ }
29
+
30
+ function before() {
31
+
32
+ }
33
+
34
+ function after() {
35
+
36
+ }
37
+
38
  }
vendor/otgs/installer/includes/class-translation-service-info.php CHANGED
@@ -1,40 +1,40 @@
1
- <?php
2
-
3
- class Translation_Service_Info {
4
-
5
- function __construct() {
6
-
7
- add_action( 'installer_fetched_subscription_data', array( $this, 'save_info' ), 10, 2 );
8
-
9
- }
10
-
11
- function save_info( $data, $repository_id ) {
12
-
13
- $ts_info = isset( WP_Installer()->settings['repositories'][ $repository_id ]['ts_info'] ) ?
14
- WP_Installer()->settings['repositories'][ $repository_id ]['ts_info'] : false;
15
-
16
- $save_settings = false;
17
- if ( isset( $data->ts_info['preferred'] ) && empty( $ts_info['preferred'] ) ) {
18
- WP_Installer()->settings['repositories'][ $repository_id ]['ts_info']['preferred'] = $data->ts_info['preferred'];
19
- $save_settings = true;
20
- }
21
-
22
- if ( isset( $data->ts_info['referal'] ) && empty( $ts_info['referal'] ) ) {
23
- WP_Installer()->settings['repositories'][ $repository_id ]['ts_info']['referal'] = $data->ts_info['referal'];
24
- $save_settings = true;
25
- }
26
-
27
- if ( ! empty( $data->ts_info['client_id'] ) ) { // can be updated
28
- WP_Installer()->settings['repositories'][ $repository_id ]['ts_info']['client_id'] = $data->ts_info['client_id'];
29
- $save_settings = true;
30
- }
31
-
32
- if ( $save_settings ) {
33
- WP_Installer()->save_settings();
34
- }
35
-
36
- }
37
-
38
- }
39
-
40
  new Translation_Service_Info();
1
+ <?php
2
+
3
+ class Translation_Service_Info {
4
+
5
+ function __construct() {
6
+
7
+ add_action( 'installer_fetched_subscription_data', array( $this, 'save_info' ), 10, 2 );
8
+
9
+ }
10
+
11
+ function save_info( $data, $repository_id ) {
12
+
13
+ $ts_info = isset( WP_Installer()->settings['repositories'][ $repository_id ]['ts_info'] ) ?
14
+ WP_Installer()->settings['repositories'][ $repository_id ]['ts_info'] : false;
15
+
16
+ $save_settings = false;
17
+ if ( isset( $data->ts_info['preferred'] ) && empty( $ts_info['preferred'] ) ) {
18
+ WP_Installer()->settings['repositories'][ $repository_id ]['ts_info']['preferred'] = $data->ts_info['preferred'];
19
+ $save_settings = true;
20
+ }
21
+
22
+ if ( isset( $data->ts_info['referal'] ) && empty( $ts_info['referal'] ) ) {
23
+ WP_Installer()->settings['repositories'][ $repository_id ]['ts_info']['referal'] = $data->ts_info['referal'];
24
+ $save_settings = true;
25
+ }
26
+
27
+ if ( ! empty( $data->ts_info['client_id'] ) ) { // can be updated
28
+ WP_Installer()->settings['repositories'][ $repository_id ]['ts_info']['client_id'] = $data->ts_info['client_id'];
29
+ $save_settings = true;
30
+ }
31
+
32
+ if ( $save_settings ) {
33
+ WP_Installer()->save_settings();
34
+ }
35
+
36
+ }
37
+
38
+ }
39
+
40
  new Translation_Service_Info();
vendor/otgs/installer/includes/class-wp-installer-api.php CHANGED
@@ -1,134 +1,134 @@
1
- <?php
2
-
3
- class WP_Installer_API{
4
-
5
- public static function get_product_installer_link($repository_id, $package_id = false){
6
-
7
- $menu_url = WP_Installer()->menu_url();
8
-
9
- $url = $menu_url . '#' . $repository_id;
10
- if($package_id){
11
- $url .= '/' . $package_id;
12
- }
13
-
14
- return $url;
15
-
16
- }
17
-
18
- public static function get_product_price($repository_id, $package_id, $product_id, $incl_discount = false){
19
-
20
- $price = WP_Installer()->get_product_price($repository_id, $package_id, $product_id, $incl_discount);
21
-
22
- return $price;
23
- }
24
-
25
- /**
26
- * Retrieve the preferred translation service.
27
- *
28
- * @since 1.6.5
29
- *
30
- * @param string The repository id (e.g. wpml)
31
- * @return string The translation service id
32
- */
33
- public static function get_preferred_ts($repository_id = 'wpml'){
34
-
35
- if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'])){
36
- return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'];
37
- }
38
-
39
- return false;
40
-
41
- }
42
-
43
- /**
44
- * Set the preferred translation service.
45
- *
46
- * @since 1.6.5
47
- *
48
- * @param string The translation service id
49
- * @param string The repository id (e.g. wpml)
50
- */
51
- public static function set_preferred_ts( $value, $repository_id = 'wpml' ){
52
-
53
- if( isset( WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] ) ){
54
-
55
- WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] = $value;
56
-
57
- WP_Installer()->save_settings();
58
-
59
- }
60
-
61
- }
62
-
63
- /**
64
- * Retrieve the referring translation service (if any)
65
- *
66
- * @since 1.6.5
67
- *
68
- * @param string The repository id (e.g. wpml)
69
- * @return string The translation service id or false
70
- */
71
- public static function get_ts_referal($repository_id = 'wpml'){
72
-
73
- if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'])){
74
- return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'];
75
- }
76
-
77
- return false;
78
-
79
- }
80
-
81
- /**
82
- * Retrieve the translation services client id for a specific repository (if any)
83
- *
84
- * @since 1.7.9
85
- *
86
- * @param string The repository id (e.g. wpml)
87
- * @return string The client id or false
88
- */
89
- public static function get_ts_client_id( $repository_id = 'wpml' ){
90
-
91
- if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'])){
92
- return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'];
93
- }
94
-
95
- return false;
96
-
97
- }
98
-
99
- /**
100
- * Retrieve the site key corresponding to a repository.
101
- * This is a wrapper of WP_Installer::get_site_key()
102
- * @see WP_Installer::get_site_key()
103
- *
104
- * @since 1.7.9
105
- *
106
- * @param string The repository id (e.g. wpml)
107
- * @return string The site key (or false)
108
- */
109
- public static function get_site_key( $repository_id = 'wpml' ){
110
-
111
- return WP_Installer()->get_site_key( $repository_id );
112
-
113
- }
114
-
115
- /**
116
- * Retrieve the ID of the last user who registered a repository.
117
- *
118
- * @since 1.7.16
119
- *
120
- * @param string The repository id (e.g. wpml)
121
- * @return int The user id (or zero)
122
- */
123
- public static function get_registering_user_id( $repository_id = 'wpml' ){
124
-
125
- $user_id = 0;
126
- if( isset( WP_Installer()->settings['repositories'][$repository_id]['subscription']['registered_by'] ) ){
127
- $user_id = WP_Installer()->settings['repositories'][$repository_id]['subscription']['registered_by'];
128
- }
129
-
130
- return $user_id;
131
- }
132
-
133
-
134
  }
1
+ <?php
2
+
3
+ class WP_Installer_API{
4
+
5
+ public static function get_product_installer_link($repository_id, $package_id = false){
6
+
7
+ $menu_url = WP_Installer()->menu_url();
8
+
9
+ $url = $menu_url . '#' . $repository_id;
10
+ if($package_id){
11
+ $url .= '/' . $package_id;
12
+ }
13
+
14
+ return $url;
15
+
16
+ }
17
+
18
+ public static function get_product_price($repository_id, $package_id, $product_id, $incl_discount = false){
19
+
20
+ $price = WP_Installer()->get_product_price($repository_id, $package_id, $product_id, $incl_discount);
21
+
22
+ return $price;
23
+ }
24
+
25
+ /**
26
+ * Retrieve the preferred translation service.
27
+ *
28
+ * @since 1.6.5
29
+ *
30
+ * @param string The repository id (e.g. wpml)
31
+ * @return string The translation service id
32
+ */
33
+ public static function get_preferred_ts($repository_id = 'wpml'){
34
+
35
+ if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'])){
36
+ return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'];
37
+ }
38
+
39
+ return false;
40
+
41
+ }
42
+
43
+ /**
44
+ * Set the preferred translation service.
45
+ *
46
+ * @since 1.6.5
47
+ *
48
+ * @param string The translation service id
49
+ * @param string The repository id (e.g. wpml)
50
+ */
51
+ public static function set_preferred_ts( $value, $repository_id = 'wpml' ){
52
+
53
+ if( isset( WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] ) ){
54
+
55
+ WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] = $value;
56
+
57
+ WP_Installer()->save_settings();
58
+
59
+ }
60
+
61
+ }
62
+
63
+ /**
64
+ * Retrieve the referring translation service (if any)
65
+ *
66
+ * @since 1.6.5
67
+ *
68
+ * @param string The repository id (e.g. wpml)
69
+ * @return string The translation service id or false
70
+ */
71
+ public static function get_ts_referal($repository_id = 'wpml'){
72
+
73
+ if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'])){
74
+ return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'];
75
+ }
76
+
77
+ return false;
78
+
79
+ }
80
+
81
+ /**
82
+ * Retrieve the translation services client id for a specific repository (if any)
83
+ *
84
+ * @since 1.7.9
85
+ *
86
+ * @param string The repository id (e.g. wpml)
87
+ * @return string The client id or false
88
+ */
89
+ public static function get_ts_client_id( $repository_id = 'wpml' ){
90
+
91
+ if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'])){
92
+ return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'];
93
+ }
94
+
95
+ return false;
96
+
97
+ }
98
+
99
+ /**
100
+ * Retrieve the site key corresponding to a repository.
101
+ * This is a wrapper of WP_Installer::get_site_key()
102
+ * @see WP_Installer::get_site_key()
103
+ *
104
+ * @since 1.7.9
105
+ *
106
+ * @param string The repository id (e.g. wpml)
107
+ * @return string The site key (or false)
108
+ */
109
+ public static function get_site_key( $repository_id = 'wpml' ){
110
+
111
+ return WP_Installer()->get_site_key( $repository_id );
112
+
113
+ }
114
+
115
+ /**
116
+ * Retrieve the ID of the last user who registered a repository.
117
+ *
118
+ * @since 1.7.16
119
+ *
120
+ * @param string The repository id (e.g. wpml)
121
+ * @return int The user id (or zero)
122
+ */
123
+ public static function get_registering_user_id( $repository_id = 'wpml' ){
124
+
125
+ $user_id = 0;
126
+ if( isset( WP_Installer()->settings['repositories'][$repository_id]['subscription']['registered_by'] ) ){
127
+ $user_id = WP_Installer()->settings['repositories'][$repository_id]['subscription']['registered_by'];
128
+ }
129
+
130
+ return $user_id;
131
+ }
132
+
133
+
134
  }
vendor/otgs/installer/includes/class-wp-installer-channels.php CHANGED
@@ -1,291 +1,271 @@
1
- <?php
2
-
3
- /**
4
- * Class WP_Installer_Channels
5
- * @since 1.8
6
- */
7
- class WP_Installer_Channels{
8
-
9
- const CHANNEL_PRODUCTION = 1;
10
- const CHANNEL_BETA = 2;
11
- const CHANNEL_DEVELOPMENT = 3;
12
-
13
- protected static $_instance = null;
14
-
15
- function __construct() {
16
- add_action( 'init', array( $this, 'init' ), 20 ); // after Installer
17
- }
18
-
19
- /**
20
- * @return null|WP_Installer_Channels
21
- */
22
- public static function instance() {
23
-
24
- if ( is_null( self::$_instance ) ) {
25
- self::$_instance = new self();
26
- }
27
-
28
- return self::$_instance;
29
- }
30
-
31
- /**
32
- * Get the channel literal id based on the numeric id
33
- *
34
- * @param int $int
35
- *
36
- * @return string
37
- */
38
- public static function channel_id( $int ) {
39
- if ( self::CHANNEL_DEVELOPMENT === $int ) {
40
- $channel = 'development';
41
- } elseif ( self::CHANNEL_BETA === $int ) {
42
- $channel = 'beta';
43
- } else {
44
- $channel = 'production';
45
- }
46
-
47
- return $channel;
48
- }
49
-
50
- /**
51
- * Get the channel literal id based on the numeric id
52
- *
53
- * @param mixed $id
54
- *
55
- * @return string
56
- */
57
- public static function channel_name_by_id( $id ) {
58
- if ( self::CHANNEL_DEVELOPMENT === $id || self::channel_id( self::CHANNEL_DEVELOPMENT ) === $id ) {
59
- $channel = __( 'Development', 'installer' );
60
- } elseif ( self::CHANNEL_BETA === $id || self::channel_id( self::CHANNEL_BETA ) === $id ) {
61
- $channel = __( 'Beta', 'installer' );
62
- } else {
63
- $channel = __( 'Production', 'installer' );
64
- }
65
-
66
- return $channel;
67
- }
68
-
69
- /**
70
- * Initialization
71
- */
72
- public function init(){
73
- global $pagenow;
74
-
75
- if ( defined( 'DOING_AJAX' ) ) {
76
- add_action( 'wp_ajax_installer_set_channel', array( $this, 'set_channel' ) );
77
- }
78
-
79
- if ( $pagenow === 'plugin-install.php' && isset( $_GET['tab'] ) && $_GET['tab'] === 'commercial' ) {
80
- wp_enqueue_script( 'installer-channels', WP_Installer()->res_url() . '/res/js/channels.js', array( 'jquery' ), WP_Installer()->version() );
81
- }
82
-
83
- }
84
-
85
- /**
86
- * Ajax handler for channel switching
87
- */
88
- public function set_channel(){
89
- $repository_id = sanitize_text_field( $_POST['repository_id'] );
90
- $channel = intval( $_POST['channel'] );
91
-
92
- $response = array();
93
-
94
- if( $_POST['nonce'] === wp_create_nonce( 'installer_set_channel:' . $repository_id ) ){
95
-
96
- if( isset( WP_Installer()->settings['repositories'][$repository_id] ) ){
97
- WP_Installer()->settings['repositories'][$repository_id]['channel'] = $channel;
98
- WP_Installer()->settings['repositories'][$repository_id]['no-prompt'] = $_POST['noprompt'] === 'true';
99
- WP_Installer()->save_settings();
100
- }
101
-
102
- WP_Installer()->refresh_repositories_data();
103
-
104
- $response['status'] = 'OK';
105
- }
106
-
107
- echo json_encode( $response );
108
- exit;
109
- }
110
-
111
- /**
112
- * @param string $repository_id
113
- *
114
- * @return int
115
- */
116
- public function get_channel( $repository_id ){
117
- $channel = 0;
118
- if( isset( WP_Installer()->settings['repositories'][$repository_id]['channel'] ) ){
119
- $channel = WP_Installer()->settings['repositories'][$repository_id]['channel'];
120
- }
121
- return $channel;
122
- }
123
-
124
- /**
125
- * @param string $repository_id
126
- * @param array $downloads
127
- */
128
- public function load_channel_selector( $repository_id, $downloads ) {
129
-
130
- $available_channels = $this->get_available_channels( $repository_id );
131
-
132
- if ( $available_channels ) {
133
- $args = array(
134
- 'can_switch' => $this->can_use_unstable_channels( $downloads ) || $this->get_channel( $repository_id ) > 1,
135
- 'channels' => $available_channels,
136
- 'repository_id' => $repository_id,
137
- 'current_channel' => $this->get_channel( $repository_id ),
138
- 'no_prompt' => !empty( WP_Installer()->settings['repositories'][ $repository_id ]['no-prompt'] ),
139
- 'nonce' => wp_create_nonce( 'installer_set_channel:' . $repository_id )
140
- );
141
-
142
- extract( $args );
143
- include WP_Installer()->plugin_path() . '/templates/channel-selector.php';
144
- }
145
- }
146
-
147
- /**
148
- * The beta and development channels can be used only when already using the most up to date versions
149
- * @param array $downloads
150
- *
151
- * @return bool
152
- */
153
- public function can_use_unstable_channels( $downloads ){
154
-
155
- $can = true;
156
- foreach( $downloads as $download ){
157
- $available_version = $download['version'];
158
- $installed_version = WP_Installer()->plugin_is_installed( $download['name'], $download['slug'] );
159
- if( $installed_version !== false && version_compare( $available_version, $installed_version, '>' ) ){
160
- $can = false;
161
- break;
162
- }
163
- }
164
-
165
- return $can;
166
- }
167
-
168
- /**
169
- * Get available updates channels. Only include channels with actual downloads available.
170
- *
171
- * @param string $repository_id
172
- *
173
- * @return array
174
- */
175
- public function get_available_channels( $repository_id ) {
176
-
177
- $beta = false;
178
- $dev = false;
179
-
180
- $downloads = WP_Installer()->settings['repositories'][ $repository_id ]['data']['downloads'];
181
- foreach ( $downloads as $type => $download_types ) {
182
- foreach ( $download_types as $download ) {
183
- $extra_channels = isset( $download['extra_channels'] ) ? array_keys( $download['extra_channels'] ) : array();
184
- if ( ! $beta && in_array( self::channel_id( self::CHANNEL_BETA ), $extra_channels ) ) {
185
- $beta = true;
186
- }
187
- if ( ! $dev && in_array( self::channel_id( self::CHANNEL_DEVELOPMENT ), $extra_channels ) ) {
188
- $dev = true;
189
- }
190
- if ( $beta && $dev ) {
191
- break;
192
- }
193
- }
194
- }
195
-
196
- $channels = array();
197
- if ( $beta || $dev ) {
198
- $channels[ self::CHANNEL_PRODUCTION ] = self::channel_name_by_id( self::CHANNEL_PRODUCTION );
199
- if ( $beta ) {
200
- $channels[ self::CHANNEL_BETA ] = self::channel_name_by_id( self::CHANNEL_BETA );
201
- }
202
- if ( $dev ) {
203
- $channels[ self::CHANNEL_DEVELOPMENT ] = self::channel_name_by_id( self::CHANNEL_DEVELOPMENT );
204
- }
205
- }
206
-
207
- return $channels;
208
- }
209
-
210
- /**
211
- * @param string $repository_id
212
- * @param array $downloads
213
- *
214
- * @return array
215
- */
216
- public function filter_downloads_by_channel( $repository_id, $downloads ) {
217
-
218
- $current_channel = $this->get_channel( $repository_id );
219
-
220
- foreach ( $downloads as $type => $type_downloads ) {
221
- foreach ( $type_downloads as $slug => $download ) {
222
-
223
- $override_download = false;
224
- if ( $current_channel === self::CHANNEL_DEVELOPMENT ) {
225
- if( ! empty( $download['channels']['development'] ) ){
226
- $override_download = $download['channels']['development'];
227
- $override_download['channel'] = self::channel_id( self::CHANNEL_DEVELOPMENT );
228
- }elseif( ! empty( $download['channels']['beta'] ) ){
229
- $override_download = $download['channels']['beta'];
230
- $override_download['channel'] = self::channel_id( self::CHANNEL_BETA );
231
- }
232
- }elseif ( $current_channel === self::CHANNEL_BETA && ! empty( $download['channels']['beta'] ) ) {
233
- $override_download = $download['channels']['beta'];
234
- $override_download['channel'] = self::channel_id( self::CHANNEL_BETA );
235
- }
236
-
237
- if ( $override_download ) {
238
- foreach ( $override_download as $key => $value ) {
239
- $downloads[ $type ][ $slug ][ $key ] = $value;
240
- }
241
- } else {
242
- $downloads[ $type ][ $slug ]['channel'] = self::channel_id( self::CHANNEL_PRODUCTION );
243
- }
244
- unset ( $downloads[ $type ][ $slug ]['channels'] );
245
-
246
- $downloads[ $type ][ $slug ]['extra_channels'] = array();
247
- if( isset( $download['channels'] ) ) {
248
- foreach( $download['channels'] as $channel_id => $channel ){
249
- $downloads[ $type ][ $slug ]['extra_channels'][$channel_id] = array(
250
- 'version' => $channel['version']
251
- );
252
- }
253
- }
254
-
255
- }
256
- }
257
-
258
- return $downloads;
259
- }
260
-
261
- /**
262
- * Get the source channel for the installed version when on the Beta or Development channel
263
- * @param string $version
264
- * @param string $repository_id
265
- * @param string $download_id
266
- * @param string $download_kind
267
- *
268
- * @return string
269
- */
270
- public function get_download_source_channel( $version, $repository_id, $download_id, $download_kind ) {
271
-
272
- $version_channel = '';
273
- $installer_settings = WP_Installer()->get_settings();
274
- if ( isset( $installer_settings['repositories'][ $repository_id ] ) ) {
275
- $repository_data = $installer_settings['repositories'][ $repository_id ]['data'];
276
- if ( isset( $repository_data['downloads'][ $download_kind ][ $download_id ]['extra_channels'] ) ) {
277
-
278
- foreach ( $repository_data['downloads'][ $download_kind ][ $download_id ]['extra_channels'] as $channel_id => $channel_data ) {
279
- if ( $version === $channel_data['version'] ) {
280
- $version_channel = self::channel_name_by_id( $channel_id );
281
- break;
282
- }
283
-
284
- }
285
- }
286
-
287
- }
288
-
289
- return $version_channel;
290
- }
291
  }
1
+ <?php
2
+
3
+ /**
4
+ * Class WP_Installer_Channels
5
+ * @since 1.8
6
+ */
7
+ class WP_Installer_Channels{
8
+
9
+ const CHANNEL_PRODUCTION = 'production';
10
+ const CHANNEL_BETA = 'beta';
11
+ const CHANNEL_DEVELOPMENT = 'development';
12
+
13
+ protected static $_instance = null;
14
+
15
+ function __construct() {
16
+ add_action( 'init', array( $this, 'init' ), 20 ); // after Installer
17
+ }
18
+
19
+ /**
20
+ * @return null|WP_Installer_Channels
21
+ */
22
+ public static function instance() {
23
+
24
+ if ( is_null( self::$_instance ) ) {
25
+ self::$_instance = new self();
26
+ }
27
+
28
+ return self::$_instance;
29
+ }
30
+
31
+ /**
32
+ * Get the channel literal id based on the numeric id
33
+ *
34
+ * @param mixed $id
35
+ *
36
+ * @return string
37
+ */
38
+ public static function channel_name_by_id( $id ) {
39
+ if ( self::CHANNEL_DEVELOPMENT === $id ) {
40
+ $channel = __( 'Development', 'installer' );
41
+ } elseif ( self::CHANNEL_BETA === $id ) {
42
+ $channel = __( 'Beta', 'installer' );
43
+ } else {
44
+ $channel = __( 'Production', 'installer' );
45
+ }
46
+
47
+ return $channel;
48
+ }
49
+
50
+ /**
51
+ * Initialization
52
+ */
53
+ public function init(){
54
+ global $pagenow;
55
+
56
+ if ( defined( 'DOING_AJAX' ) ) {
57
+ add_action( 'wp_ajax_installer_set_channel', array( $this, 'set_channel' ) );
58
+ }
59
+
60
+ if ( $pagenow === 'plugin-install.php' && isset( $_GET['tab'] ) && $_GET['tab'] === 'commercial' ) {
61
+ wp_enqueue_script( 'installer-channels', WP_Installer()->res_url() . '/res/js/channels.js', array( 'jquery' ), WP_Installer()->version() );
62
+ }
63
+
64
+ }
65
+
66
+ /**
67
+ * Ajax handler for channel switching
68
+ */
69
+ public function set_channel(){
70
+ $repository_id = sanitize_text_field( $_POST['repository_id'] );
71
+ $channel = sanitize_text_field( $_POST['channel'] );
72
+
73
+ $response = array();
74
+
75
+ if( $_POST['nonce'] === wp_create_nonce( 'installer_set_channel:' . $repository_id ) ){
76
+
77
+ if( isset( WP_Installer()->settings['repositories'][$repository_id] ) ){
78
+ WP_Installer()->settings['repositories'][$repository_id]['channel'] = $channel;
79
+ WP_Installer()->settings['repositories'][$repository_id]['no-prompt'] = $_POST['noprompt'] === 'true';
80
+ WP_Installer()->save_settings();
81
+ }
82
+
83
+ WP_Installer()->refresh_repositories_data();
84
+
85
+ $response['status'] = 'OK';
86
+ }
87
+
88
+ echo json_encode( $response );
89
+ exit;
90
+ }
91
+
92
+ /**
93
+ * @param string $repository_id
94
+ *
95
+ * @return int
96
+ */
97
+ public function get_channel( $repository_id ){
98
+ $channel = self::CHANNEL_PRODUCTION;
99
+ if( isset( WP_Installer()->settings['repositories'][$repository_id]['channel'] ) ){
100
+ $channel = WP_Installer()->settings['repositories'][$repository_id]['channel'];
101
+ }
102
+ return $channel;
103
+ }
104
+
105
+ /**
106
+ * @param string $repository_id
107
+ * @param array $downloads
108
+ */
109
+ public function load_channel_selector( $repository_id, $downloads ) {
110
+
111
+ $available_channels = $this->get_available_channels( $repository_id );
112
+
113
+ if ( $available_channels ) {
114
+ $args = array(
115
+ 'can_switch' => $this->can_use_unstable_channels( $downloads ) || $this->get_channel( $repository_id ) > 1,
116
+ 'channels' => $available_channels,
117
+ 'repository_id' => $repository_id,
118
+ 'current_channel' => $this->get_channel( $repository_id ),
119
+ 'no_prompt' => !empty( WP_Installer()->settings['repositories'][ $repository_id ]['no-prompt'] ),
120
+ 'nonce' => wp_create_nonce( 'installer_set_channel:' . $repository_id )
121
+ );
122
+ extract( $args );
123
+ include WP_Installer()->plugin_path() . '/templates/channel-selector.php';
124
+ }
125
+ }
126
+
127
+ /**
128
+ * The beta and development channels can be used only when already using the most up to date versions
129
+ * @param array $downloads
130
+ *
131
+ * @return bool
132
+ */
133
+ public function can_use_unstable_channels( $downloads ){
134
+
135
+ $can = true;
136
+ foreach( $downloads as $download ){
137
+ $available_version = $download['version'];
138
+ $installed_version = WP_Installer()->plugin_is_installed( $download['name'], $download['slug'] );
139
+ if( $installed_version !== false && version_compare( $available_version, $installed_version, '>' ) ){
140
+ $can = false;
141
+ break;
142
+ }
143
+ }
144
+
145
+ return $can;
146
+ }
147
+
148
+ /**
149
+ * Get available updates channels. Only include channels with actual downloads available.
150
+ *
151
+ * @param string $repository_id
152
+ *
153
+ * @return array
154
+ */
155
+ public function get_available_channels( $repository_id ) {
156
+
157
+ $beta = false;
158
+ $dev = false;
159
+
160
+ $downloads = WP_Installer()->settings['repositories'][ $repository_id ]['data']['downloads'];
161
+ foreach ( $downloads as $type => $download_types ) {
162
+ foreach ( $download_types as $download ) {
163
+ $extra_channels = isset( $download['extra_channels'] ) ? array_keys( $download['extra_channels'] ) : array();
164
+ if ( ! $beta && in_array( self::CHANNEL_BETA, $extra_channels ) ) {
165
+ $beta = true;
166
+ }
167
+ if ( ! $dev && in_array( self::CHANNEL_DEVELOPMENT, $extra_channels ) ) {
168
+ $dev = true;
169
+ }
170
+ if ( $beta && $dev ) {
171
+ break;
172
+ }
173
+ }
174
+ }
175
+
176
+ $channels = array();
177
+ if ( $beta || $dev ) {
178
+ $channels[ self::CHANNEL_PRODUCTION ] = self::channel_name_by_id( self::CHANNEL_PRODUCTION );
179
+ if ( $beta ) {
180
+ $channels[ self::CHANNEL_BETA ] = self::channel_name_by_id( self::CHANNEL_BETA );
181
+ }
182
+ if ( $dev ) {
183
+ $channels[ self::CHANNEL_DEVELOPMENT ] = self::channel_name_by_id( self::CHANNEL_DEVELOPMENT );
184
+ }
185
+ }
186
+
187
+ return $channels;
188
+ }
189
+
190
+ /**
191
+ * @param string $repository_id
192
+ * @param array $downloads
193
+ *
194
+ * @return array
195
+ */
196
+ public function filter_downloads_by_channel( $repository_id, $downloads ) {
197
+
198
+ $current_channel = $this->get_channel( $repository_id );
199
+
200
+ foreach ( $downloads as $type => $type_downloads ) {
201
+ foreach ( $type_downloads as $slug => $download ) {
202
+
203
+ $override_download = array();
204
+ if ( $current_channel === self::CHANNEL_DEVELOPMENT ) {
205
+ if( ! empty( $download['channels']['development'] ) ){
206
+ $override_download = $download['channels']['development'];
207
+ $override_download['channel'] = self::CHANNEL_DEVELOPMENT;
208
+ }elseif( ! empty( $download['channels']['beta'] ) ){
209
+ $override_download = $download['channels']['beta'];
210
+ $override_download['channel'] = self::CHANNEL_BETA;
211
+ }
212
+ }elseif ( $current_channel === self::CHANNEL_BETA && ! empty( $download['channels']['beta'] ) ) {
213
+ $override_download = $download['channels']['beta'];
214
+ $override_download['channel'] = self::CHANNEL_BETA;
215
+ }
216
+
217
+ if ( $override_download ) {
218
+ foreach ( $override_download as $key => $value ) {
219
+ $downloads[ $type ][ $slug ][ $key ] = $value;
220
+ }
221
+ } else {
222
+ $downloads[ $type ][ $slug ]['channel'] = self::CHANNEL_PRODUCTION;
223
+ }
224
+ unset ( $downloads[ $type ][ $slug ]['channels'] );
225
+
226
+ $downloads[ $type ][ $slug ]['extra_channels'] = array();
227
+ if( isset( $download['channels'] ) ) {
228
+ foreach( $download['channels'] as $channel_id => $channel ){
229
+ $downloads[ $type ][ $slug ]['extra_channels'][$channel_id] = array(
230
+ 'version' => $channel['version']
231
+ );
232
+ }
233
+ }
234
+
235
+ }
236
+ }
237
+
238
+ return $downloads;
239
+ }
240
+
241
+ /**
242
+ * Get the source channel for the installed version when on the Beta or Development channel
243
+ * @param string $version
244
+ * @param string $repository_id
245
+ * @param string $download_id
246
+ * @param string $download_kind
247
+ *
248
+ * @return string
249
+ */
250
+ public function get_download_source_channel( $version, $repository_id, $download_id, $download_kind ) {
251
+
252
+ $version_channel = '';
253
+ $installer_settings = WP_Installer()->get_settings();
254
+ if ( isset( $installer_settings['repositories'][ $repository_id ] ) ) {
255
+ $repository_data = $installer_settings['repositories'][ $repository_id ]['data'];
256
+ if ( isset( $repository_data['downloads'][ $download_kind ][ $download_id ]['extra_channels'] ) ) {
257
+
258
+ foreach ( $repository_data['downloads'][ $download_kind ][ $download_id ]['extra_channels'] as $channel_id => $channel_data ) {
259
+ if ( $version === $channel_data['version'] ) {
260
+ $version_channel = self::channel_name_by_id( $channel_id );
261
+ break;
262
+ }
263
+
264
+ }
265
+ }
266
+
267
+ }
268
+
269
+ return $version_channel;
270
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  }
vendor/otgs/installer/includes/class-wp-installer.php CHANGED
@@ -1,2769 +1,2768 @@
1
- <?php
2
-
3
- final class WP_Installer {
4
- protected static $_instance = null;
5
-
6
- public $settings = array();
7
-
8
- private $repositories = array();
9
-
10
- protected $api_debug = '';
11
-
12
- private $config = array();
13
-
14
- protected $_plugins_renew_warnings = array();
15
-
16
- protected $_gz_on = false;
17
-
18
- private $admin_messages = array();
19
-
20
- private $_using_icl = false;
21
- private $_wpml_version = false;
22
-
23
- private $package_source = array();
24
-
25
- const SITE_KEY_VALIDATION_SOURCE_OTHER = 0;
26
- const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_SPECIFIC = 1;
27
- const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT = 2;
28
- const SITE_KEY_VALIDATION_SOURCE_REGISTRATION = 3;
29
- const SITE_KEY_VALIDATION_SOURCE_REVALIDATION = 4;
30
- const SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK = 5;
31
-
32
- public $dependencies;
33
-
34
- public static function instance() {
35
-
36
- if ( is_null( self::$_instance ) ) {
37
- self::$_instance = new self();
38
- }
39
-
40
- return self::$_instance;
41
- }
42
-
43
- public function __construct() {
44
-
45
- if ( ! is_admin() || ! is_user_logged_in() ) {
46
- return;
47
- } //Only for admin
48
-
49
- $this->_gz_on = function_exists( 'gzuncompress' ) && function_exists( 'gzcompress' );
50
- $this->settings = $this->get_settings();
51
-
52
- add_action( 'admin_notices', array( $this, 'show_site_key_nags' ) );
53
-
54
- add_action( 'admin_notices', array( $this, 'show_admin_messages' ) );
55
-
56
- add_action( 'admin_init', array( $this, 'load_embedded_plugins' ), 0 );
57
-
58
- add_action( 'admin_menu', array( $this, 'menu_setup' ) );
59
- add_action( 'network_admin_menu', array( $this, 'menu_setup' ) );
60
-
61
- if ( defined( 'DOING_AJAX' ) && isset( $_POST['action'] ) && $_POST['action'] == 'installer_download_plugin' ) {
62
- add_filter( 'site_transient_update_plugins', array( $this, 'plugins_upgrade_check' ) );
63
- }
64
- add_filter( 'plugins_api', array( $this, 'custom_plugins_api_call' ), 10, 3 );
65
- add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'plugins_upgrade_check' ) );
66
-
67
- // register repositories
68
- $this->load_repositories_list();
69
-
70
- // default config
71
- $this->config['plugins_install_tab'] = false;
72
-
73
- add_action( 'init', array( $this, 'init' ) );
74
-
75
- //add_filter('wp_installer_buy_url', array($this, 'append_parameters_to_buy_url'));
76
-
77
- add_action( 'init', array( $this, 'load_locale' ) );
78
-
79
- }
80
-
81
- public function get_repositories() {
82
-
83
- return $this->repositories;
84
-
85
- }
86
-
87
- public function set_config( $key, $value ) {
88
-
89
- $this->config[ $key ] = $value;
90
-
91
- }
92
-
93
- public function init() {
94
- global $pagenow;
95
-
96
- if ( empty( $this->settings['last_repositories_update'] ) || time() - $this->settings['last_repositories_update'] > 86400
97
- || ( isset( $_GET['force-check'] ) && $_GET['force-check'] == 1 )
98
- ) {
99
- $this->refresh_repositories_data();
100
- }
101
-
102
- $this->dependencies = new Installer_Dependencies;
103
-
104
- if ( empty( $this->settings['_pre_1_0_clean_up'] ) ) {
105
- $this->_pre_1_0_clean_up();
106
- }
107
-
108
- $this->settings = $this->_old_products_format_backwards_compatibility( $this->settings );
109
-
110
- if ( ! function_exists( 'get_plugins' ) ) {
111
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
112
- }
113
-
114
- $this->_using_icl = function_exists( 'wpml_site_uses_icl' ) && wpml_site_uses_icl();
115
- $this->_wpml_version = defined( 'ICL_SITEPRESS_VERSION' ) ? ICL_SITEPRESS_VERSION : '';
116
-
117
- wp_enqueue_script( 'installer-admin', $this->res_url() . '/res/js/admin.js', array( 'jquery' ), $this->version() );
118
- wp_enqueue_style( 'installer-admin', $this->res_url() . '/res/css/admin.css', array(), $this->version() );
119
-
120
- $translation_array = array(
121
- 'installing' => __( 'Installing %s', 'installer' ),
122
- 'updating' => __( 'Updating %s', 'installer' ),
123
- 'activating' => __( 'Activating %s', 'installer' )
124
- );
125
-
126
- wp_localize_script( 'installer-admin', 'installer_strings', $translation_array );
127
-
128
- if ( $pagenow == 'plugins.php' ) {
129
- add_action( 'admin_notices', array( $this, 'setup_plugins_page_notices' ) );
130
- add_action( 'admin_notices', array( $this, 'setup_plugins_renew_warnings' ), 10 );
131
- add_action( 'admin_notices', array( $this, 'queue_plugins_renew_warnings' ), 20 );
132
-
133
- add_action( 'admin_init', array( $this, 'setup_plugins_action_links' ) );
134
-
135
- }
136
-
137
- if ( $this->is_repositories_page() ) {
138
- add_action( 'admin_init', array( $this, 'validate_repository_subscription' ) );
139
- }
140
-
141
- if ( defined( 'DOING_AJAX' ) ) {
142
- add_action( 'wp_ajax_save_site_key', array( $this, 'save_site_key' ) );
143
- add_action( 'wp_ajax_remove_site_key', array( $this, 'remove_site_key_ajax' ) );
144
- add_action( 'wp_ajax_update_site_key', array( $this, 'update_site_key' ) );
145
-
146
- add_action( 'wp_ajax_installer_download_plugin', array( $this, 'download_plugin_ajax_handler' ) );
147
- add_action( 'wp_ajax_installer_activate_plugin', array( $this, 'activate_plugin' ) );
148
-
149
- add_action( 'wp_ajax_installer_dismiss_nag', array( $this, 'dismiss_nag' ) );
150
- }
151
-
152
- if ( $pagenow == 'update.php' ) {
153
- if ( isset( $_GET['action'] ) && $_GET['action'] == 'update-selected' ) {
154
- add_action( 'admin_head', array( $this, 'plugin_upgrade_custom_errors' ) ); //iframe/bulk
155
- } else {
156
- add_action( 'all_admin_notices', array( $this, 'plugin_upgrade_custom_errors' ) ); //regular/singular
157
- }
158
- }
159
-
160
- // WP 4.2
161
- if ( defined( 'DOING_AJAX' ) ) {
162
- add_action( 'wp_ajax_update-plugin', array(
163
- $this,
164
- 'plugin_upgrade_custom_errors'
165
- ), 0 ); // high priority, before WP
166
- }
167
-
168
- //Include theme support
169
- include_once $this->plugin_path() . '/includes/class-installer-theme.php';
170
-
171
- // Extra information about the source of Installer
172
- $package_source_file = $this->plugin_path() . '/installer-source.json';
173
- if ( file_exists( $package_source_file ) ) {
174
- WP_Filesystem();
175
- global $wp_filesystem;
176
- $this->package_source = json_decode( $wp_filesystem->get_contents( $package_source_file ) );
177
- }
178
- }
179
-
180
- protected function log( $message ) {
181
- require_once ABSPATH . 'wp-admin/includes/file.php';
182
- WP_Filesystem();
183
- global $wp_filesystem;
184
- if ( defined( 'WPML_INSTALLER_LOGGING' ) && WPML_INSTALLER_LOGGING ) {
185
- $wp_filesystem->put_contents( $this->plugin_path() . '/installer.log', current_time( 'mysql' ) . "\t" . $message . "\n" );
186
- }
187
- }
188
-
189
- public function register_admin_message( $text, $type = 'updated' ) {
190
- $this->admin_messages[] = array( 'text' => $text, 'type' => $type );
191
- }
192
-
193
- public function show_admin_messages() {
194
- if ( ! empty( $this->admin_messages ) ) {
195
- $types = array( 'error', 'updated', 'notice' );
196
- foreach ( $this->admin_messages as $message ) {
197
- $class = in_array( $message['type'], $types ) ? $message['type'] : 'updated';
198
- ?>
199
- <div class="<?php echo $class ?>">
200
- <p>
201
- <?php echo $message['text'] ?>
202
- </p>
203
- </div>
204
- <?php
205
- }
206
- }
207
- }
208
-
209
- public function load_locale() {
210
- if ( function_exists( 'get_user_locale' ) ) {
211
- $locale = get_user_locale();
212
- } else {
213
- $locale = get_locale();
214
- }
215
- $locale = apply_filters( 'plugin_locale', $locale, 'installer' );
216
- $mo_file = $this->plugin_path() . '/locale/installer-' . $locale . '.mo';
217
- if ( file_exists( $mo_file ) ) {
218
- load_textdomain( 'installer', $mo_file );
219
- }
220
- }
221
-
222
- public function load_embedded_plugins() {
223
- if ( file_exists( $this->plugin_path() . '/embedded-plugins' ) ) {
224
- include_once $this->plugin_path() . '/embedded-plugins/embedded-plugins.class.php';
225
- $this->installer_embedded_plugins = new Installer_Embedded_Plugins();
226
- }
227
- }
228
-
229
- public function menu_setup() {
230
- global $pagenow;
231
-
232
- if ( is_multisite() && ! is_network_admin() ) {
233
- $this->menu_multisite_redirect();
234
- add_options_page( __( 'Installer', 'installer' ), __( 'Installer', 'installer' ), 'manage_options', 'installer', array(
235
- $this,
236
- 'show_products'
237
- ) );
238
- } else {
239
- if ( $this->config['plugins_install_tab'] && is_admin() && $pagenow == 'plugin-install.php' ) {
240
- // Default GUI, under Plugins -> Install
241
- add_filter( 'install_plugins_tabs', array( $this, 'add_install_plugins_tab' ) );
242
- add_action( 'install_plugins_commercial', array( $this, 'show_products' ) );
243
- }
244
- }
245
-
246
- }
247
-
248
- public function menu_url() {
249
- if ( is_multisite() ) {
250
- if ( is_network_admin() ) {
251
- $url = network_admin_url( 'plugin-install.php?tab=commercial' );
252
- } else {
253
- $url = admin_url( 'options-general.php?page=installer' );
254
- }
255
- } else {
256
- $url = admin_url( 'plugin-install.php?tab=commercial' );
257
- }
258
-
259
- return $url;
260
- }
261
-
262
- private function menu_multisite_redirect() {
263
- global $pagenow;
264
-
265
- if ( $pagenow == 'plugin-install.php' && isset( $_GET['tab'] ) && $_GET['tab'] == 'commercial' ) {
266
- wp_redirect( $this->menu_url() );
267
- exit;
268
- }
269
-
270
- }
271
-
272
- private function _pre_1_0_clean_up() {
273
- global $wpdb;
274
-
275
- if ( ! defined( 'WPRC_VERSION' ) ) {
276
- $old_tables = array(
277
- $wpdb->prefix . 'wprc_cached_requests',
278
- $wpdb->prefix . 'wprc_extension_types',
279
- $wpdb->prefix . 'wprc_extensions',
280
- $wpdb->prefix . 'wprc_repositories',
281
- $wpdb->prefix . 'wprc_repositories_relationships',
282
- );
283
-
284
- foreach ( $old_tables as $table ) {
285
- $wpdb->query( sprintf( "DROP TABLE IF EXISTS %s", $table ) );
286
- }
287
-
288
- }
289
-
290
- $this->settings['_pre_1_0_clean_up'] = true;
291
- $this->save_settings();
292
- }
293
-
294
- public function setup_plugins_action_links() {
295
-
296
- $plugins = get_plugins();
297
-
298
- $repositories_plugins = array();
299
-
300
- if ( ! empty( $this->settings['repositories'] ) ) {
301
-
302
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
303
-
304
- foreach ( $repository['data']['packages'] as $package ) {
305
-
306
- foreach ( $package['products'] as $product ) {
307
-
308
- foreach ( $product['plugins'] as $plugin_slug ) {
309
-
310
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
311
-
312
- if ( ! isset( $repositories_plugins[ $repository_id ][ $download['slug'] ] ) ) {
313
- $repositories_plugins[ $repository_id ][ $download['slug'] ] = array(
314
- 'name' => $download['name'],
315
- 'registered' => $this->plugin_is_registered( $repository_id, $download['slug'] ) ? 1 : 0
316
- );
317
- }
318
-
319
- }
320
-
321
- }
322
-
323
- }
324
-
325
- foreach ( $plugins as $plugin_id => $plugin ) {
326
-
327
- $wp_plugin_slug = dirname( $plugin_id );
328
- if ( empty( $wp_plugin_slug ) ) {
329
- $wp_plugin_slug = basename( $plugin_id, '.php' );
330
- }
331
-
332
- foreach ( $repositories_plugins as $repository_id => $r_plugins ) {
333
-
334
- foreach ( $r_plugins as $slug => $r_plugin ) {
335
-
336
- if ( $wp_plugin_slug == $slug || $r_plugin['name'] == $plugin['Name'] || $r_plugin['name'] == $plugin['Title'] ) { //match order: slug, name, title
337
-
338
- if ( $r_plugin['registered'] ) {
339
- add_filter( 'plugin_action_links_' . $plugin_id, array(
340
- $this,
341
- 'plugins_action_links_registered'
342
- ) );
343
- } else {
344
- add_filter( 'plugin_action_links_' . $plugin_id, array(
345
- $this,
346
- 'plugins_action_links_not_registered'
347
- ) );
348
- }
349
-
350
- }
351
-
352
- }
353
-
354
- }
355
-
356
-
357
- }
358
-
359
- }
360
- }
361
-
362
- }
363
-
364
- public function plugins_action_links_registered( $links ) {
365
- $links[] = '<a href="' . $this->menu_url() . '">' . __( 'Registered', 'installer' ) . '</a>';
366
-
367
- return $links;
368
- }
369
-
370
- public function plugins_action_links_not_registered( $links ) {
371
- $links[] = '<a href="' . $this->menu_url() . '">' . __( 'Register', 'installer' ) . '</a>';
372
-
373
- return $links;
374
- }
375
-
376
- public function plugin_is_registered( $repository_id, $slug ) {
377
-
378
- $registered = false;
379
-
380
- if ( $this->repository_has_valid_subscription( $repository_id ) ) {
381
-
382
- $subscription_type = $this->get_subscription_type_for_repository( $repository_id );
383
- $r_plugins = array();
384
-
385
- foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package ) {
386
-
387
- foreach ( $package['products'] as $product ) {
388
-
389
- if ( $product['subscription_type'] == $subscription_type || $this->have_superior_subscription( $subscription_type, $product ) ) {
390
-
391
- foreach ( $product['plugins'] as $plugin_slug ) {
392
-
393
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
394
-
395
- if ( ! isset( $rep_plugins[ $download['slug'] ] ) ) {
396
- $r_plugins[ $download['slug'] ] = $download['slug'];
397
- }
398
-
399
- }
400
-
401
- }
402
-
403
- }
404
-
405
- }
406
-
407
- $registered = isset( $r_plugins[ $slug ] );
408
-
409
- }
410
-
411
-
412
- return $registered;
413
-
414
- }
415
-
416
- public function version() {
417
- return WP_INSTALLER_VERSION;
418
- }
419
-
420
- public function plugin_path() {
421
- return untrailingslashit( plugin_dir_path( dirname( __FILE__ ) ) );
422
- }
423
-
424
- public function plugin_url() {
425
- if ( isset( $this->config['in_theme_folder'] ) && ! empty( $this->config['in_theme_folder'] ) ) {
426
- $url = untrailingslashit( get_template_directory_uri() . '/' . $this->config['in_theme_folder'] );
427
- } else {
428
- $url = untrailingslashit( plugins_url( '/', dirname( __FILE__ ) ) );
429
- }
430
-
431
- return $url;
432
- }
433
-
434
- public function is_repositories_page() {
435
- global $pagenow;
436
-
437
- return $pagenow == 'plugin-install.php' && isset( $_GET['tab'] ) && $_GET['tab'] == 'commercial';
438
- }
439
-
440
- public function res_url() {
441
- if ( isset( $this->config['in_theme_folder'] ) && ! empty( $this->config['in_theme_folder'] ) ) {
442
- $url = untrailingslashit( get_template_directory_uri() . '/' . $this->config['in_theme_folder'] );
443
- } else {
444
- $url = $this->plugin_url();
445
- }
446
-
447
- return $url;
448
- }
449
-
450
- public function save_settings() {
451
-
452
- $_settings = serialize( $this->settings );
453
- if ( $this->_gz_on ) {
454
- $_settings = gzcompress( $_settings );
455
- }
456
- $_settings = base64_encode( $_settings );
457
-
458
- update_option( 'wp_installer_settings', $_settings );
459
-
460
- if ( is_multisite() && is_main_site() && isset( $this->settings['repositories'] ) ) {
461
- $network_settings = array();
462
-
463
- foreach ( $this->settings['repositories'] as $rep_id => $repository ) {
464
- if ( isset( $repository['subscription'] ) ) {
465
- $network_settings[ $rep_id ] = $repository['subscription'];
466
- }
467
- }
468
-
469
- update_site_option( 'wp_installer_network', $network_settings );
470
-
471
-
472
- }
473
-
474
- }
475
-
476
- public function get_settings( $refresh = false ) {
477
-
478
- if ( $refresh || empty( $this->settings ) ) {
479
-
480
- $_settings = get_option( 'wp_installer_settings' );
481
-
482
-
483
- if ( is_array( $_settings ) || empty( $_settings ) ) { //backward compatibility 1.1
484
- $this->settings = $_settings;
485
-
486
- } else {
487
- $_settings = base64_decode( $_settings );
488
- if ( $this->_gz_on ) {
489
- $_settings = gzuncompress( $_settings );
490
- }
491
- $this->settings = unserialize( $_settings );
492
- }
493
-
494
- // Initialize
495
- if ( empty( $this->settings ) ) {
496
- $this->settings = array(
497
- 'repositories' => array()
498
- );
499
- }
500
-
501
- if ( is_multisite() ) {
502
- $network_settings = maybe_unserialize( get_site_option( 'wp_installer_network' ) );
503
- if ( $network_settings ) {
504
- foreach ( $this->settings['repositories'] as $rep_id => $repository ) {
505
- if ( isset( $network_settings[ $rep_id ] ) ) {
506
- $this->settings['repositories'][ $rep_id ]['subscription'] = $network_settings[ $rep_id ];
507
- }
508
- }
509
- }
510
- }
511
-
512
- $this->load_hardcoded_site_keys();
513
-
514
- $this->_pre_1_8_backwards_compatibility( $this->settings );
515
-
516
- $this->settings = $this->_old_products_format_backwards_compatibility( $this->settings );
517
-
518
- }
519
-
520
- return $this->settings;
521
- }
522
-
523
- private function load_hardcoded_site_keys() {
524
-
525
- if ( ! empty( $this->settings['repositories'] ) ) {
526
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
527
-
528
- if ( $site_key = self::get_repository_hardcoded_site_key( $repository_id ) ) {
529
-
530
- $site_key_missing = empty( $this->settings['repositories'][ $repository_id ]['subscription']['data'] );
531
- $site_key_changed = ! $site_key_missing &&
532
- $this->settings['repositories'][ $repository_id ]['subscription']['key'] != $site_key;
533
-
534
- if ( $site_key_missing || $site_key_changed ) {
535
-
536
- if ( ! function_exists( 'get_plugins' ) ) {
537
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
538
- }
539
- $this->load_repositories_list();
540
- $response = $this->save_site_key(
541
- array(
542
- 'repository_id' => $repository_id,
543
- 'site_key' => $site_key,
544
- 'return' => true,
545
- 'nonce' => wp_create_nonce( 'save_site_key_' . $repository_id )
546
- )
547
- );
548
-
549
- if ( ! empty( $response['error'] ) ) {
550
- $this->remove_site_key( $repository_id );
551
-
552
- $this->admin_messages[] = array(
553
- 'type' => 'error',
554
- 'text' => sprintf( __( 'You are using an invalid site key defined as the constant %s (most likely in wp-config.php).
555
- Please remove it or use the correct value in order to be able to register correctly.', 'installer' ), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id ) )
556
- );
557
-
558
- }
559
-
560
- }
561
-
562
- }
563
-
564
- }
565
- }
566
-
567
- }
568
-
569
- public static function get_repository_hardcoded_site_key( $repository_id ) {
570
-
571
- $site_key = false;
572
-
573
- $site_key_constant = 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id );
574
- if ( defined( $site_key_constant ) ) {
575
- $site_key = constant( $site_key_constant );
576
- }
577
-
578
- return $site_key;
579
- }
580
-
581
- //backward compatibility, add channel
582
- private function _pre_1_8_backwards_compatibility( &$settings ) {
583
- if ( empty( $settings['_pre_1_8_clean_up'] ) ) {
584
- foreach ( $settings['repositories'] as $repository_id => $repository ) {
585
- foreach ( $repository['data']['downloads']['plugins'] as $slug => $download ) {
586
- if( !isset( $download['channel'] ) ){
587
- $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $slug ]['channel'] = '';
588
- }
589
- }
590
- }
591
- $this->save_settings();
592
- }
593
- }
594
-
595
- //backward compatibility - support old products list format (downloads under products instead of global downloads list)
596
- private function _old_products_format_backwards_compatibility( $settings ) {
597
-
598
- if ( version_compare( $this->version(), '1.8', '<' ) && ! empty( $settings['repositories'] ) && empty( $this->_old_products_format_backwards_compatibility ) ) {
599
-
600
- foreach ( $settings['repositories'] as $repository_id => $repository ) {
601
- $populate_downloads = false;
602
- if ( isset( $repository['data'] ) ) {
603
-
604
- foreach ( $repository['data']['packages'] as $package_id => $package ) {
605
- foreach ( $package['products'] as $product_id => $product ) {
606
- if ( ! isset( $product['plugins'] ) ) {
607
- $populate_downloads = true;
608
- foreach ( $product['downloads'] as $download_id => $download ) {
609
- $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['plugins'][] = $download['slug'];
610
- }
611
- }
612
- }
613
- }
614
-
615
- if ( $populate_downloads ) {
616
- // Add downloads branch
617
- foreach ( $repository['data']['packages'] as $package_id => $package ) {
618
- foreach ( $package['products'] as $product_id => $product ) {
619
- foreach ( $product['downloads'] as $download_id => $download ) {
620
- if ( ! isset( $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $download['slug'] ] ) ) {
621
- $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $download['slug'] ] = $download;
622
- }
623
- $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['plugins'][] = $download['slug'];
624
- }
625
- unset( $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['downloads'] );
626
- }
627
- }
628
- }
629
- }
630
- }
631
-
632
- $this->_old_products_format_backwards_compatibility = true;
633
- }
634
-
635
- return $settings;
636
- }
637
-
638
- public function get_installer_site_url( $repository_id = false ) {
639
- global $current_site;
640
-
641
- $site_url = get_site_url();
642
-
643
- if ( $repository_id && is_multisite() && isset( $this->settings['repositories'] ) ) {
644
- $network_settings = maybe_unserialize( get_site_option( 'wp_installer_network' ) );
645
-
646
- if ( isset( $network_settings[ $repository_id ] ) ) {
647
- $site_url = get_site_url( $current_site->blog_id );
648
- }
649
-
650
- }
651
-
652
- return $site_url;
653
- }
654
-
655
- public function show_site_key_nags() {
656
- $screen = get_current_screen();
657
-
658
- if ( $screen->base == 'settings_page_installer' || ( $screen->base == 'plugin-install' && isset( $_GET['tab'] ) && $_GET['tab'] == 'commercial' ) ) {
659
- return;
660
- }
661
-
662
- if ( ! empty( $this->config['site_key_nags'] ) ) {
663
-
664
- foreach ( $this->config['site_key_nags'] as $nag ) {
665
-
666
- if ( ! $this->repository_has_subscription( $nag['repository_id'] ) ) {
667
- $show = true;
668
- if ( ! empty( $nag['condition_cb'] ) ) {
669
- $show = call_user_func( $nag['condition_cb'] );
670
- }
671
-
672
- if ( empty( $this->settings['dismissed_nags'][ $nag['repository_id'] ] ) && $show ) {
673
- echo '<div class="updated error otgs-is-dismissible"><p>';
674
- printf( __( "To get automatic updates, you need to register %s for this site. %sRegister %s%s", 'sitepress' ),
675
- $nag['product_name'], '<a class="button-primary" href="' . $this->menu_url() . '">', $nag['product_name'], '</a>' );
676
-
677
- echo '</p>';
678
- echo '<span class="installer-dismiss-nag notice-dismiss" data-repository="' . $nag['repository_id'] . '"><span class="screen-reader-text">' . __( 'Dismiss', 'sitepress' ) . '</span></span>';
679
- echo '</div>';
680
- }
681
- }
682
-
683
- }
684
-
685
- }
686
-
687
- }
688
-
689
- public function dismiss_nag() {
690
- $this->settings['dismissed_nags'][ $_POST['repository'] ] = 1;
691
-
692
- $this->save_settings();
693
-
694
- echo json_encode( array() );
695
- exit;
696
- }
697
-
698
- public function add_install_plugins_tab( $tabs ) {
699
-
700
- $tabs['commercial'] = __( 'Commercial', 'installer' );
701
-
702
- return $tabs;
703
- }
704
-
705
- public function load_repositories_list() {
706
- global $wp_installer_instances;
707
-
708
- foreach ( $wp_installer_instances as $instance ) {
709
-
710
- if ( file_exists( dirname( $instance['bootfile'] ) . '/repositories.xml' ) ) {
711
- $config_file = dirname( $instance['bootfile'] ) . '/repositories.xml';
712
-
713
- if ( file_exists( dirname( $instance['bootfile'] ) . '/repositories.sandbox.xml' ) ) {
714
- $config_file = dirname( $instance['bootfile'] ) . '/repositories.sandbox.xml';
715
- add_filter( 'https_ssl_verify', '__return_false' );
716
- }
717
-
718
- $repos = simplexml_load_file( $config_file );
719
-
720
- if ( $repos ) {
721
- foreach ( $repos as $repo ) {
722
- $id = strval( $repo->id );
723
-
724
- $data['api-url'] = strval( $repo->apiurl );
725
- $data['products'] = strval( $repo->products );
726
-
727
- // excludes rule;
728
- if ( isset( $this->config['repositories_exclude'] ) && in_array( $id, $this->config['repositories_exclude'] ) ) {
729
- continue;
730
- }
731
-
732
- // includes rule;
733
- if ( isset( $this->config['repositories_include'] ) && ! in_array( $id, $this->config['repositories_include'] ) ) {
734
- continue;
735
- }
736
-
737
- $this->repositories[ $id ] = $data;
738
-
739
- }
740
- }
741
-
742
- }
743
- }
744
-
745
- }
746
-
747
- public function filter_repositories_list() {
748
-
749
- if ( ! empty( $this->settings['repositories'] ) ) {
750
- foreach ( $this->settings['repositories'] as $id => $repo_data ) {
751
-
752
- // excludes rule;
753
- if ( isset( $this->config['repositories_exclude'] ) && in_array( $id, $this->config['repositories_exclude'] ) ) {
754
- unset( $this->settings['repositories'][ $id ] );
755
- }
756
-
757
- // includes rule;
758
- if ( isset( $this->config['repositories_include'] ) && ! in_array( $id, $this->config['repositories_include'] ) ) {
759
- unset( $this->settings['repositories'][ $id ] );
760
- }
761
-
762
-
763
- }
764
- }
765
-
766
-
767
- }
768
-
769
- public function refresh_repositories_data() {
770
- static $checked = false;
771
-
772
- if ( defined( 'OTGS_DISABLE_AUTO_UPDATES' ) && OTGS_DISABLE_AUTO_UPDATES && empty( $_GET['force-check'] ) || $checked ) {
773
-
774
- if ( empty( $this->settings['repositories'] ) && $this->is_repositories_page() ) {
775
-
776
- foreach ( $this->repositories as $id => $data ) {
777
- $repository_names[] = $id;
778
-
779
- }
780
-
781
- $error = sprintf( __( "Installer cannot display the products information because the automatic updating for %s was explicitly disabled with the configuration below (usually in wp-config.php):", 'installer' ), strtoupper( join( ', ', $repository_names ) ) );
782
- $error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code><br /><br />';
783
- $error .= sprintf( __( "In order to see the products information, please run the %smanual updates check%s to initialize the products list or (temporarily) remove the above code.", 'installer' ), '<a href="' . admin_url( 'update-core.php' ) . '">', '</a>' );
784
-
785
- $this->register_admin_message( $error, 'error' );
786
-
787
-
788
- }
789
-
790
- return;
791
- }
792
-
793
- $checked = true;
794
-
795
- foreach ( $this->repositories as $id => $data ) {
796
-
797
- $response = wp_remote_get( $data['products'] );
798
-
799
- if ( is_wp_error( $response ) ) {
800
- // http fallback
801
- $data['products'] = preg_replace( "@^https://@", 'http://', $data['products'] );
802
- $response = wp_remote_get( $data['products'] );
803
- }
804
-
805
- if ( is_wp_error( $response ) ) {
806
-
807
- $error = sprintf( __( "Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:", 'installer' ), strtoupper( $id ) );
808
- $error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code>';
809
-
810
- $this->register_admin_message( $error, 'error' );
811
-
812
- continue;
813
- }
814
-
815
- if ( $response && isset( $response['response']['code'] ) && $response['response']['code'] == 200 ) {
816
- $body = wp_remote_retrieve_body( $response );
817
- if ( $body ) {
818
- $products = json_decode( $body, true );
819
-
820
- if ( is_array( $products ) ) {
821
- $products['downloads'] = WP_Installer_Channels()->filter_downloads_by_channel( $id, $products['downloads'] );
822
- $this->set_release_notes( $products['downloads'] );
823
-
824
- $this->settings['repositories'][ $id ]['data'] = $products;
825
- $this->_pre_1_8_backwards_compatibility( $this->settings );
826
- }
827
- }
828
-
829
- }
830
-
831
- $this->log( sprintf( "Checked for %s updates: %s", $id, $data['products'] ) );
832
-
833
-
834
- }
835
-
836
- // cleanup
837
- if ( empty( $this->settings['repositories'] ) ) {
838
- $this->settings['repositories'] = array();
839
- }
840
- foreach ( $this->settings['repositories'] as $id => $data ) {
841
- if ( ! in_array( $id, array_keys( $this->repositories ) ) ) {
842
- unset( $this->settings['repositories'][ $id ] );
843
- }
844
- }
845
-
846
- $this->settings['last_repositories_update'] = time();
847
-
848
- $this->save_settings();
849
-
850
- }
851
-
852
- /**
853
- * Gets the release notes for the available version from the changelog
854
- *
855
- * @param array $all_downloads
856
- */
857
- private function set_release_notes( &$all_downloads ) {
858
- foreach ( $all_downloads as $kind => $downloads ) {
859
- foreach ( $downloads as $slug => $download ) {
860
- $start = strpos( $download['changelog'], '<h4>' . $download['version'] . '</h4>' );
861
- if ( $start !== false ) {
862
- $start += strlen( $download['version'] ) + 9;
863
- $end = strpos( $download['changelog'], '<h4>', 4 );
864
- if ( $end ) {
865
- $release_notes = substr( $download['changelog'], $start, $end - $start );
866
- } else {
867
- $release_notes = substr( $download['changelog'], $start );
868
- }
869
- }
870
- $all_downloads[ $kind ][ $slug ]['release-notes'] = ! empty( $release_notes ) ? $release_notes : '';
871
- }
872
- }
873
- }
874
-
875
- public function show_products( $args = array() ) {
876
-
877
- $screen = get_current_screen();
878
-
879
- if ( $screen->base == 'settings_page_installer' ) { // settings page
880
- echo '<div class="wrap">';
881
- echo '<h2>' . __( 'Installer', 'installer' ) . '</h2>';
882
- echo '<br />';
883
- }
884
-
885
- if ( ! is_array( $args ) ) {
886
- $args = array();
887
- }
888
- if ( empty( $args['template'] ) ) {
889
- $args['template'] = 'default';
890
- }
891
-
892
- $this->filter_repositories_list();
893
-
894
- if ( ! empty( $this->settings['repositories'] ) ) {
895
-
896
- $this->localize_strings();
897
- $this->set_filtered_prices( $args );
898
- $this->set_hierarchy_and_order();
899
-
900
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
901
-
902
- if ( $args['template'] == 'compact' ) {
903
-
904
- if ( isset( $args['repository'] ) && $args['repository'] == $repository_id ) {
905
- include $this->plugin_path() . '/templates/products-compact.php';
906
- }
907
-
908
- } else {
909
-
910
- include $this->plugin_path() . '/templates/repository-listing.php';
911
-
912
- }
913
-
914
- unset( $site_key, $subscription_type, $expired, $upgrade_options, $products_avaliable );
915
-
916
- }
917
-
918
- } else {
919
-
920
- echo '<center>' . __( 'No repositories defined.', 'installer' ) . '</center>';
921
-
922
- }
923
-
924
- if ( $screen->base == 'settings_page_installer' ) { // settings page
925
- echo '</div>';
926
- }
927
-
928
-
929
- }
930
-
931
- public function get_product_price( $repository_id, $package_id, $product_id, $incl_discount = false ) {
932
-
933
- $price = false;
934
-
935
- foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package ) {
936
-
937
- if ( $package['id'] == $package_id ) {
938
- if ( isset( $package['products'][ $product_id ] ) ) {
939
- if ( $incl_discount && isset( $package['products'][ $product_id ]['price_disc'] ) ) {
940
- $price = $package['products'][ $product_id ]['price_disc'];
941
- } elseif ( isset( $package['products'][ $product_id ]['price'] ) ) {
942
- $price = $package['products'][ $product_id ]['price'];
943
- }
944
- }
945
- break;
946
- }
947
- }
948
-
949
- return $price;
950
- }
951
-
952
- private function _render_product_packages( $packages, $subscription_type, $expired, $upgrade_options, $repository_id ) {
953
-
954
- $data = array();
955
-
956
- foreach ( $packages as $package_id => $package ) {
957
-
958
- $row = array( 'products' => array(), 'downloads' => array() );
959
- foreach ( $package['products'] as $product ) {
960
-
961
- // filter out free subscriptions from being displayed as buying options
962
- if ( empty( $product['price'] ) && ( empty( $subscription_type ) || $expired ) ) {
963
- continue;
964
- }
965
-
966
- //consider equivalent subscriptions
967
- if ( empty( $product['subscription_type_equivalent'] ) ) {
968
- $product['subscription_type_equivalent'] = '';
969
- }
970
-
971
- // buy base
972
- if ( empty( $subscription_type ) || $expired ) {
973
-
974
- $p['url'] = $this->append_parameters_to_buy_url( $product['url'], $repository_id );
975
- if ( ! empty( $product['price_disc'] ) ) {
976
- $p['label'] = $product['call2action'] . ' - ' . sprintf( '$%s %s$%d%s (USD)', $product['price_disc'], '&nbsp;&nbsp;<del>', $product['price'], '</del>' );
977
- } else {
978
- $p['label'] = $product['call2action'] . ' - ' . sprintf( '$%d (USD)', $product['price'] );
979
- }
980
- $row['products'][] = $p;
981
-
982
- // renew
983
- } elseif ( isset( $subscription_type ) && ( $product['subscription_type'] == $subscription_type || $product['subscription_type_equivalent'] == $subscription_type ) ) {
984
-
985
- if ( $product['renewals'] ) {
986
- foreach ( $product['renewals'] as $renewal ) {
987
- $p['url'] = $this->append_parameters_to_buy_url( $renewal['url'], $repository_id );
988
- $p['label'] = $renewal['call2action'] . ' - ' . sprintf( '$%d (USD)', $renewal['price'] );
989
- }
990
-
991
- $row['products'][] = $p;
992
- }
993
-
994
- }
995
-
996
- // upgrades
997
- if ( ! empty( $upgrade_options[ $product['subscription_type'] ] ) ) {
998
-
999
- foreach ( $upgrade_options[ $product['subscription_type'] ] as $stype => $upgrade ) {
1000
- if ( $stype != $subscription_type ) {
1001
- continue;
1002
- }
1003
-
1004
- $p['url'] = $this->append_parameters_to_buy_url( $upgrade['url'], $repository_id );
1005
- if ( ! empty( $upgrade['price_disc'] ) ) {
1006
- $p['label'] = $upgrade['call2action'] . ' - ' . sprintf( '$%s %s$%d%s (USD)', $upgrade['price_disc'], '&nbsp;&nbsp;<del>', $upgrade['price'], '</del>' );
1007
- } else {
1008
- $p['label'] = $upgrade['call2action'] . ' - ' . sprintf( '$%d (USD)', $upgrade['price'] );
1009
- }
1010
- $row['products'][] = $p;
1011
-
1012
- }
1013
-
1014
- }
1015
-
1016
- // downloads
1017
- if ( isset( $subscription_type ) && ! $expired && ( $product['subscription_type'] == $subscription_type || $product['subscription_type_equivalent'] == $subscription_type ) ) {
1018
-
1019
- foreach ( $product['plugins'] as $plugin_slug ) {
1020
- $row['downloads'][ $plugin_slug ] = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
1021
- }
1022
-
1023
- }
1024
-
1025
- //subpackages
1026
- if ( ! empty( $package['sub-packages'] ) ) {
1027
- $row['sub-packages'] = $package['sub-packages'];
1028
- }
1029
-
1030
- }
1031
-
1032
- $row['id'] = $package['id'];
1033
- $row['image_url'] = $package['image_url'];
1034
- $row['name'] = $package['name'];
1035
- $row['description'] = $package['description'];
1036
-
1037
- if ( ! empty( $row['products'] ) || ! empty( $row['downloads'] ) || ! empty( $row['sub-packages'] ) ) {
1038
- $data[] = $row;
1039
- }
1040
-
1041
-
1042
- }
1043
-
1044
- return $data;
1045
-
1046
- }
1047
-
1048
- public function get_extra_url_parameters() {
1049
-
1050
- $parameters = array();
1051
-
1052
- if ( ! empty( $this->package_source ) ) {
1053
- foreach ( $this->package_source as $key => $val ) {
1054
- $parameters[ $key ] = $val;
1055
- }
1056
- }
1057
-
1058
- $parameters['installer_version'] = WP_INSTALLER_VERSION;
1059
- $parameters['theme'] = wp_get_theme()->get( 'Name' );
1060
- $parameters['site_name'] = get_bloginfo( 'name' );
1061
-
1062
- return $parameters;
1063
- }
1064
-
1065
- public function append_parameters_to_buy_url( $url, $repository_id, $args = array() ) {
1066
-
1067
- $url = add_query_arg( array( 'icl_site_url' => $this->get_installer_site_url( $repository_id ) ), $url );
1068
-
1069
- $affiliate_id = false;
1070
- $affiliate_key = false;
1071
-
1072
- // Add extra parameters for custom Installer packages
1073
- if ( ! empty( $this->package_source ) ) {
1074
- $extra = $this->get_extra_url_parameters();
1075
-
1076
- if ( ! empty( $extra['repository'] ) && $extra['repository'] == $repository_id ) {
1077
-
1078
- if ( ! empty( $extra['affiliate_key'] ) && ! empty( $extra['user_id'] ) ) {
1079
- $this->config[ 'affiliate_id:' . $repository_id ] = $extra['user_id'];
1080
- $this->config[ 'affiliate_key:' . $repository_id ] = $extra['affiliate_key'];
1081
- unset( $extra['affiliate_key'], $extra['user_id'], $extra['repository'] ); // no need to include these ones
1082
- }
1083
-
1084
- $url = add_query_arg( $extra, $url );
1085
- }
1086
-
1087
- }
1088
-
1089
- if ( isset( $this->config[ 'affiliate_id:' . $repository_id ] ) && isset( $this->config[ 'affiliate_key:' . $repository_id ] ) ) {
1090
-
1091
- $affiliate_id = $this->config[ 'affiliate_id:' . $repository_id ];
1092
- $affiliate_key = $this->config[ 'affiliate_key:' . $repository_id ];
1093
-
1094
- } elseif ( isset( $args[ 'affiliate_id:' . $repository_id ] ) && isset( $args[ 'affiliate_key:' . $repository_id ] ) ) {
1095
-
1096
- $affiliate_id = $args[ 'affiliate_id:' . $repository_id ];
1097
- $affiliate_key = $args[ 'affiliate_key:' . $repository_id ];
1098
-
1099
- } elseif ( defined( 'ICL_AFFILIATE_ID' ) && defined( 'ICL_AFFILIATE_KEY' ) ) { //support for 1 repo
1100
-
1101
- $affiliate_id = ICL_AFFILIATE_ID;
1102
- $affiliate_key = ICL_AFFILIATE_KEY;
1103
-
1104
- } elseif ( isset( $this->config['affiliate_id'] ) && isset( $this->config['affiliate_key'] ) ) {
1105
- // BACKWARDS COMPATIBILITY
1106
- $affiliate_id = $this->config['affiliate_id'];
1107
- $affiliate_key = $this->config['affiliate_key'];
1108
- }
1109
-
1110
- if ( $affiliate_id && $affiliate_key ) {
1111
- $url = add_query_arg( array( 'aid' => $affiliate_id, 'affiliate_key' => $affiliate_key ), $url );
1112
- }
1113
-
1114
- if ( $repository_id == 'wpml' ) {
1115
- $url = add_query_arg( array(
1116
- 'using_icl' => $this->_using_icl,
1117
- 'wpml_version' => $this->_wpml_version
1118
- ), $url );
1119
- }
1120
-
1121
- $url = apply_filters( 'wp_installer_buy_url', $url );
1122
-
1123
- $url = esc_url( $url );
1124
-
1125
- return $url;
1126
-
1127
- }
1128
-
1129
- public function save_site_key( $args = array() ) {
1130
-
1131
- $error = '';
1132
-
1133
- if ( isset( $args['repository_id'] ) ) {
1134
- $repository_id = $args['repository_id'];
1135
- } elseif ( isset( $_POST['repository_id'] ) ) {
1136
- $repository_id = sanitize_text_field( $_POST['repository_id'] );
1137
- } else {
1138
- $repository_id = false;
1139
- }
1140
-
1141
- if ( isset( $args['nonce'] ) ) {
1142
- $nonce = $args['nonce'];
1143
- } elseif ( isset( $_POST['nonce'] ) ) {
1144
- $nonce = sanitize_text_field( $_POST['nonce'] );
1145
- } else {
1146
- $nonce = '';
1147
- }
1148
-
1149
- if ( isset( $args['site_key'] ) ) {
1150
- $site_key = $args['site_key'];
1151
- } else {
1152
- $site_key = sanitize_text_field( $_POST[ 'site_key_' . $repository_id ] );
1153
- }
1154
- $site_key = preg_replace( "/[^A-Za-z0-9]/", '', $site_key );
1155
-
1156
- if ( $repository_id && $nonce && wp_create_nonce( 'save_site_key_' . $repository_id ) == $nonce ) {
1157
-
1158
- try {
1159
- $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REGISTRATION );
1160
-
1161
- if ( $subscription_data ) {
1162
- $this->settings['repositories'][ $repository_id ]['subscription'] = array(
1163
- 'key' => $site_key,
1164
- 'data' => $subscription_data,
1165
- 'registered_by' => get_current_user_id()
1166
- );
1167
- $this->save_settings();
1168
- } else {
1169
- $error = __( 'Invalid site key for the current site.', 'installer' )
1170
- . '<br /><div class="installer-footnote">' . __( 'Please note that the site key is case sensitive.', 'installer' ) . '</div>';
1171
- }
1172
-
1173
- } catch ( Exception $e ) {
1174
- $error = $e->getMessage();
1175
- if ( preg_match( '#Could not resolve host: (.*)#', $error, $matches ) || preg_match( '#Couldn\'t resolve host \'(.*)\'#', $error, $matches ) ) {
1176
- $error = sprintf( __( "%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer' ),
1177
- '<strong><i>' . $this->get_generic_product_name( $repository_id ) . '</i></strong>',
1178
- '<strong><i>' . $matches[1] . '</i></strong>'
1179
- );
1180
- }
1181
- }
1182
-
1183
- }
1184
-
1185
- $return = array( 'error' => $error );
1186
-
1187
- if ( $this->api_debug ) {
1188
- $return['debug'] = $this->api_debug;
1189
- }
1190
-
1191
- if ( ! empty( $args['return'] ) ) {
1192
- return $return;
1193
- } else {
1194
- echo json_encode( $return );
1195
- exit;
1196
- }
1197
-
1198
- }
1199
-
1200
- /**
1201
- * Alias for WP_Installer::get_repository_site_key
1202
- * @see WP_Installer::get_repository_site_key()
1203
- *
1204
- * @param string $repository_id
1205
- *
1206
- * @return string (site key) or bool
1207
- */
1208
- public function get_site_key( $repository_id ) {
1209
- return WP_Installer::get_repository_site_key( $repository_id );
1210
- }
1211
-
1212
- public function remove_site_key( $repository_id ) {
1213
- if ( isset( $this->settings['repositories'][ $repository_id ] ) ) {
1214
- unset( $this->settings['repositories'][ $repository_id ]['subscription'] );
1215
- $this->save_settings();
1216
- $this->refresh_repositories_data();
1217
- }
1218
- }
1219
-
1220
- public function remove_site_key_ajax() {
1221
- if ( $_POST['nonce'] == wp_create_nonce( 'remove_site_key_' . $_POST['repository_id'] ) ) {
1222
- $this->remove_site_key( $_POST['repository_id'] );
1223
- }
1224
- exit;
1225
- }
1226
-
1227
- public function validate_repository_subscription() {
1228
- $repository_id = isset( $_GET['validate_repository'] ) ? sanitize_text_field( $_GET['validate_repository'] ) : false;
1229
- if ( $repository_id ) {
1230
-
1231
- $site_key = $this->get_site_key( $repository_id );
1232
- if ( $site_key ) {
1233
- $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
1234
- if ( empty( $subscription_data ) ) {
1235
- unset( $this->settings['repositories'][ $repository_id ]['subscription'] );
1236
- delete_site_transient( 'update_plugins' );
1237
- $this->save_settings();
1238
- }
1239
- }
1240
-
1241
- wp_redirect( $this->menu_url() . '#repository-' . $repository_id );
1242
- exit;
1243
-
1244
- }
1245
-
1246
- }
1247
-
1248
- public function update_site_key() {
1249
-
1250
- $error = '';
1251
-
1252
- $repository_id = sanitize_text_field( $_POST['repository_id'] );
1253
- if ( $_POST['nonce'] == wp_create_nonce( 'update_site_key_' . $repository_id ) ) {
1254
-
1255
- $site_key = $this->get_site_key( $_POST['repository_id'] );
1256
-
1257
- if ( $site_key ) {
1258
- try {
1259
- $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK );
1260
-
1261
- if ( $subscription_data ) {
1262
- $this->settings['repositories'][ $repository_id ]['subscription'] = array(
1263
- 'key' => $site_key,
1264
- 'data' => $subscription_data,
1265
- 'registered_by' => get_current_user_id()
1266
- );
1267
-
1268
- //also refresh products information
1269
- $this->refresh_repositories_data();
1270
-
1271
- $this->save_settings();
1272
-
1273
- } else {
1274
- unset( $this->settings['repositories'][ $repository_id ]['subscription'] );
1275
- $error = __( 'Invalid site key for the current site. If the error persists, try to unregister first and then register again with the same site key.', 'installer' );
1276
- }
1277
-
1278
-
1279
- } catch ( Exception $e ) {
1280
- $error = $e->getMessage();
1281
- if ( preg_match( '#Could not resolve host: (.*)#', $error, $matches ) || preg_match( '#Couldn\'t resolve host \'(.*)\'#', $error, $matches ) ) {
1282
- $error = sprintf( __( "%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer' ),
1283
- '<strong><i>' . $this->get_generic_product_name( $repository_id ) . '</i></strong>',
1284
- '<strong><i>' . $matches[1] . '</i></strong>'
1285
- );
1286
- }
1287
- }
1288
-
1289
- }
1290
-
1291
- }
1292
-
1293
- echo json_encode( array( 'error' => $error ) );
1294
-
1295
- exit;
1296
- }
1297
-
1298
- public function api_debug_log( $text ) {
1299
-
1300
- if ( defined( 'WPML_DEBUG_INSTALLER' ) && WPML_DEBUG_INSTALLER ) {
1301
-
1302
- if ( ! is_scalar( $text ) ) {
1303
- $text = print_r( $text, 1 );
1304
- }
1305
-
1306
- $this->api_debug .= $text . "\n";
1307
-
1308
- }
1309
-
1310
- }
1311
-
1312
- public function fetch_subscription_data( $repository_id, $site_key, $source = self::SITE_KEY_VALIDATION_SOURCE_OTHER ) {
1313
-
1314
- $subscription_data = false;
1315
-
1316
- $args['body'] = array(
1317
- 'action' => 'site_key_validation',
1318
- 'site_key' => $site_key,
1319
- 'site_url' => $this->get_installer_site_url( $repository_id ),
1320
- 'source' => $source
1321
- );
1322
-
1323
- if ( $repository_id == 'wpml' ) {
1324
- $args['body']['using_icl'] = $this->_using_icl;
1325
- $args['body']['wpml_version'] = $this->_wpml_version;
1326
- }
1327
-
1328
- $args['body']['installer_version'] = WP_INSTALLER_VERSION;
1329
- $args['body']['theme'] = wp_get_theme()->get( 'Name' );
1330
- $args['body']['site_name'] = get_bloginfo( 'name' );
1331
-
1332
- $args['body']['versions'] = $this->get_local_product_versions( $repository_id );
1333
-
1334
- $args['timeout'] = 45;
1335
-
1336
- // Add extra parameters for custom Installer packages
1337
- if ( ! empty( $this->package_source ) ) {
1338
- $extra = $this->get_extra_url_parameters();
1339
- if ( ! empty( $extra['repository'] ) && $extra['repository'] == $repository_id ) {
1340
- unset( $extra['repository'] );
1341
- foreach ( $extra as $key => $val ) {
1342
- $args['body'][ $key ] = $val;
1343
- }
1344
- }
1345
- }
1346
-
1347
- $response = wp_remote_post( $this->repositories[ $repository_id ]['api-url'], $args );
1348
-
1349
- $this->api_debug_log( "POST {$this->repositories[$repository_id]['api-url']}" );
1350
- $this->api_debug_log( $args );
1351
-
1352
- $this->log( "POST {$this->repositories[$repository_id]['api-url']} - fetch subscription data" );
1353
-
1354
- if ( ! is_wp_error( $response ) ) {
1355
- $datas = wp_remote_retrieve_body( $response );
1356
-
1357
- if ( is_serialized( $datas ) ) {
1358
- $data = unserialize( $datas );
1359
- $this->api_debug_log( $data );
1360
-
1361
- if ( ! empty( $data->subscription_data ) ) {
1362
- $subscription_data = $data->subscription_data;
1363
- }
1364
-
1365
- do_action( 'installer_fetched_subscription_data', $data, $repository_id );
1366
-
1367
- } else {
1368
- $this->api_debug_log( $datas );
1369
- }
1370
-
1371
- } else {
1372
-
1373
- $this->api_debug_log( $response );
1374
- throw new Exception( $response->get_error_message() );
1375
- }
1376
-
1377
- return $subscription_data;
1378
-
1379
- }
1380
-
1381
- function get_local_product_versions( $repository_id ) {
1382
-
1383
- $versions = array();
1384
-
1385
- foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package_id => $package ) {
1386
-
1387
- foreach ( $package['products'] as $product_id => $product ) {
1388
-
1389
- foreach ( $product['plugins'] as $plugin_slug ) {
1390
-
1391
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
1392
-
1393
- if ( empty( $versions[ $download['slug'] ] ) ) {
1394
- $v = $this->get_plugin_installed_version( $download['name'], $download['slug'] );
1395
- if ( $v ) {
1396
- $versions[ $download['slug'] ] = $v;
1397
- }
1398
- }
1399
-
1400
- }
1401
-
1402
- }
1403
-
1404
- }
1405
-
1406
- return $versions;
1407
- }
1408
-
1409
- public function get_repository_site_key( $repository_id ) {
1410
- $site_key = false;
1411
-
1412
- if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription']['key'] ) ) {
1413
- $site_key = $this->settings['repositories'][ $repository_id ]['subscription']['key'];
1414
- }
1415
-
1416
- return $site_key;
1417
- }
1418
-
1419
- public function repository_has_valid_subscription( $repository_id ) {
1420
-
1421
- $valid = false;
1422
-
1423
- if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription'] ) ) {
1424
-
1425
- $subscription = $this->settings['repositories'][ $repository_id ]['subscription']['data'];
1426
- $valid = ( $subscription->status == 1 && ( strtotime( $subscription->expires ) > time() || empty( $subscription->expires ) ) ) || $subscription->status == 4;
1427
-
1428
- }
1429
-
1430
- return $valid;
1431
-
1432
- }
1433
-
1434
- public function repository_has_subscription( $repository_id ) {
1435
- $key = false;
1436
- if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription']['key'] ) ) {
1437
- $key = $this->settings['repositories'][ $repository_id ]['subscription']['key'];
1438
- }
1439
-
1440
- return $key;
1441
-
1442
- }
1443
-
1444
- public function repository_has_expired_subscription( $repository_id ) {
1445
-
1446
- return $this->repository_has_subscription( $repository_id ) && ! $this->repository_has_valid_subscription( $repository_id );
1447
-
1448
- }
1449
-
1450
- public function get_generic_product_name( $repository_id ) {
1451
-
1452
- return $this->settings['repositories'][ $repository_id ]['data']['product-name'];
1453
-
1454
- }
1455
-
1456
- public function show_subscription_renew_warning( $repository_id, $subscription_id ) {
1457
-
1458
- $show = false;
1459
-
1460
- $data = $this->settings['repositories'][ $repository_id ]['data'];
1461
- if ( ! empty( $data['subscriptions_meta'] ) ) {
1462
- if ( isset( $data['subscriptions_meta']['expiration'] ) ) {
1463
-
1464
- if ( ! empty( $data['subscriptions_meta']['expiration'][ $subscription_id ] ) ) {
1465
-
1466
- $days = $data['subscriptions_meta']['expiration'][ $subscription_id ]['days_warning'];
1467
- $message = $data['subscriptions_meta']['expiration'][ $subscription_id ]['warning_message'];
1468
-
1469
- } else {
1470
-
1471
- //defaults
1472
- $days = 30;
1473
- $message = __( 'You will have to renew your subscription in order to continue getting the updates and support.', 'installer' );
1474
-
1475
- }
1476
-
1477
- if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription'] ) ) {
1478
- $subscription = $this->settings['repositories'][ $repository_id ]['subscription'];
1479
-
1480
- if ( $subscription['data']->subscription_type == $subscription_id && ! empty( $subscription['data']->expires ) ) {
1481
-
1482
- if ( strtotime( $subscription['data']->expires ) < strtotime( sprintf( "+%d day", $days ) ) ) {
1483
-
1484
- $days_to_expiration = ceil( ( strtotime( $subscription['data']->expires ) - time() ) / 86400 );
1485
-
1486
- echo '<div><p class="installer-warn-box">' .
1487
- sprintf( _n( 'Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer' ), $days_to_expiration ) .
1488
- '<br />' . $message .
1489
- '</p></div>';
1490
-
1491
- $show = true;
1492
-
1493
- }
1494
-
1495
- }
1496
-
1497
- }
1498
-
1499
-
1500
- }
1501
- }
1502
-
1503
-
1504
- return $show;
1505
-
1506
- }
1507
-
1508
- public function setup_plugins_renew_warnings() {
1509
-
1510
- $plugins = get_plugins();
1511
-
1512
- $subscriptions_with_warnings = array();
1513
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
1514
-
1515
- if ( $this->repository_has_valid_subscription( $repository_id ) ) {
1516
- $subscription_type = $this->settings['repositories'][ $repository_id ]['subscription']['data']->subscription_type;
1517
- $expires = $this->settings['repositories'][ $repository_id ]['subscription']['data']->expires;
1518
-
1519
- $never_expires = isset( $this->settings['repositories'][ $repository_id ]['subscription'] )
1520
- && empty( $this->settings['repositories'][ $repository_id ]['subscription']['data']->expires )
1521
- && (
1522
- $this->settings['repositories'][ $repository_id ]['subscription']['data']->status == 4 ||
1523
- $this->settings['repositories'][ $repository_id ]['subscription']['data']->status == 1
1524
- );
1525
-
1526
- if ( ! $never_expires ) {
1527
- if ( isset( $this->settings['repositories'][ $repository_id ]['data']['subscriptions_meta']['expiration'][ $subscription_type ] ) ) {
1528
-
1529
- $days_warning = $this->settings['repositories'][ $repository_id ]['data']['subscriptions_meta']['expiration'][ $subscription_type ]['days_warning'];
1530
- $custom_message = $this->settings['repositories'][ $repository_id ]['data']['subscriptions_meta']['expiration'][ $subscription_type ]['warning_message'];
1531
-
1532
- } else {
1533
- //defaults
1534
- $days_warning = 30;
1535
- $custom_message = __( 'You will have to renew your subscription in order to continue getting the updates and support.', 'installer' );
1536
- }
1537
-
1538
- if ( strtotime( $expires ) < strtotime( sprintf( '+%d day', $days_warning ) ) ) {
1539
-
1540
- $days_to_expiration = ceil( ( strtotime( $expires ) - time() ) / 86400 );
1541
-
1542
- $message = sprintf( _n( 'Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer' ), $days_to_expiration );
1543
- $subscriptions_with_warnings[ $subscription_type ] = $message . ' ' . $custom_message;
1544
-
1545
- }
1546
- }
1547
-
1548
- }
1549
-
1550
- }
1551
-
1552
-
1553
- foreach ( $plugins as $plugin_id => $plugin ) {
1554
-
1555
- $slug = dirname( $plugin_id );
1556
- if ( empty( $slug ) ) {
1557
- continue;
1558
- }
1559
-
1560
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
1561
-
1562
- if ( $this->repository_has_valid_subscription( $repository_id ) ) {
1563
-
1564
- foreach ( $repository['data']['packages'] as $package ) {
1565
-
1566
- foreach ( $package['products'] as $product ) {
1567
-
1568
- foreach ( $product['plugins'] as $plugin_slug ) {
1569
-
1570
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
1571
-
1572
- if ( $download['slug'] == $slug || $download['name'] == $plugin['Name'] || $download['name'] == $plugin['Title'] ) { //match order: slug, name, title
1573
-
1574
- if ( isset( $subscriptions_with_warnings[ $product['subscription_type'] ] ) ) {
1575
-
1576
- $this->_plugins_renew_warnings[ $plugin_id ] = $subscriptions_with_warnings[ $product['subscription_type'] ];
1577
-
1578
- }
1579
-
1580
- }
1581
-
1582
- }
1583
-
1584
- }
1585
-
1586
- }
1587
-
1588
- }
1589
-
1590
- }
1591
-
1592
- }
1593
-
1594
- }
1595
-
1596
- public function queue_plugins_renew_warnings() {
1597
-
1598
- if ( ! empty( $this->_plugins_renew_warnings ) ) {
1599
-
1600
- foreach ( $this->_plugins_renew_warnings as $plugin_id => $message ) {
1601
-
1602
- add_action( "after_plugin_row_" . $plugin_id, array( $this, 'plugins_renew_warning' ), 10, 3 );
1603
- }
1604
-
1605
- }
1606
-
1607
- }
1608
-
1609
- public function plugins_renew_warning( $plugin_file, $plugin_data, $status ) {
1610
-
1611
- if ( empty( $this->_plugins_renew_warnings[ $plugin_file ] ) ) {
1612
- return;
1613
- }
1614
-
1615
- $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1616
- ?>
1617
-
1618
- <tr class="plugin-update-tr">
1619
- <td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
1620
- <div class="update-message">
1621
- <?php
1622
- echo $this->_plugins_renew_warnings[ $plugin_file ] . ' ';
1623
- printf( __( '%sRenew here%s.', 'installer' ),
1624
- '<a href="' . $this->menu_url() . '">', '</a>' );
1625
- ?>
1626
- </div>
1627
- </tr>
1628
-
1629
- <?php
1630
-
1631
- }
1632
-
1633
- public function get_subscription_type_for_repository( $repository_id ) {
1634
-
1635
- $subscription_type = false;
1636
-
1637
- if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription'] ) ) {
1638
- $subscription_type = $this->settings['repositories'][ $repository_id ]['subscription']['data']->subscription_type;
1639
- }
1640
-
1641
- return $subscription_type;
1642
-
1643
- }
1644
-
1645
- public function have_superior_subscription( $subscription_type, $product ) {
1646
-
1647
- $have = false;
1648
-
1649
- if ( is_array( $product['upgrades'] ) ) {
1650
- foreach ( $product['upgrades'] as $u ) {
1651
- if ( $u['subscription_type'] == $subscription_type ) {
1652
- $have = true;
1653
- break;
1654
- }
1655
- }
1656
- }
1657
-
1658
- return $have;
1659
- }
1660
-
1661
- public function is_product_available_for_download( $product_name, $repository_id ) {
1662
-
1663
- $available = false;
1664
-
1665
- $subscription_type = $this->get_subscription_type_for_repository( $repository_id );
1666
- $expired = $this->repository_has_expired_subscription( $repository_id );
1667
-
1668
- if ( $this->repository_has_subscription( $repository_id ) && ! $expired ) {
1669
-
1670
- $this->set_hierarchy_and_order();
1671
-
1672
- foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package_id => $package ) {
1673
-
1674
- $has_top_package = false;
1675
-
1676
- foreach ( $package['products'] as $product ) {
1677
-
1678
- if ( $subscription_type == $product['subscription_type'] ) {
1679
- $has_top_package = true;
1680
- if ( $product['name'] == $product_name ) {
1681
- return $available = true;
1682
- }
1683
- }
1684
-
1685
- }
1686
-
1687
- if ( ! empty( $package['sub-packages'] ) ) {
1688
- foreach ( $package['sub-packages'] as $sub_package ) {
1689
- foreach ( $sub_package['products'] as $product ) {
1690
- if ( $product['name'] == $product_name && ( $subscription_type == $product['subscription_type'] || $has_top_package ) ) {
1691
- return $available = true;
1692
- }
1693
- }
1694
- }
1695
- }
1696
-
1697
- }
1698
- }
1699
-
1700
- return $available;
1701
-
1702
- }
1703
-
1704
- public function get_upgrade_options( $repository_id ) {
1705
- $all_upgrades = array();
1706
-
1707
-
1708
- //get all products: packages and subpackages
1709
- $all_products = array();
1710
- foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package ) {
1711
- foreach ( $package['products'] as $product ) {
1712
- $all_products[] = $product;
1713
- }
1714
- if ( ! empty( $package['sub-packages'] ) ) {
1715
- foreach ( $package['sub-packages'] as $subpackage ) {
1716
- foreach ( $subpackage['products'] as $product ) {
1717
- $all_products[] = $product;
1718
- }
1719
-
1720
- }
1721
-
1722
- }
1723
-
1724
- }
1725
-
1726
- foreach ( $all_products as $product ) {
1727
- if ( $product['upgrades'] ) {
1728
- foreach ( $product['upgrades'] as $upgrade ) {
1729
- if ( $this->repository_has_valid_subscription( $repository_id ) || ( $this->repository_has_subscription( $repository_id ) && $upgrade['including_expired'] ) ) {
1730
- $all_upgrades[ $upgrade['subscription_type'] ][ $product['subscription_type'] ] = $upgrade;
1731
- }
1732
- }
1733
- }
1734
- }
1735
-
1736
- return $all_upgrades;
1737
-
1738
- }
1739
-
1740
- public function append_site_key_to_download_url( $url, $key, $repository_id ) {
1741
-
1742
- $url_params['site_key'] = $key;
1743
- $url_params['site_url'] = $this->get_installer_site_url( $repository_id );
1744
-
1745
-
1746
- // Add extra parameters for custom Installer packages
1747
- if ( ! empty( $this->package_source ) ) {
1748
- $extra = $this->get_extra_url_parameters();
1749
- if ( ! empty( $extra['repository'] ) && $extra['repository'] == $repository_id ) {
1750
- unset( $extra['repository'] );
1751
- foreach ( $extra as $key => $val ) {
1752
- $url_params[ $key ] = $val;
1753
- }
1754
- }
1755
- }
1756
-
1757
- $url = add_query_arg( $url_params, $url );
1758
-
1759
- if ( $repository_id == 'wpml' ) {
1760
- $url = add_query_arg( array(
1761
- 'using_icl' => $this->_using_icl,
1762
- 'wpml_version' => $this->_wpml_version
1763
- ), $url );
1764
- }
1765
-
1766
- return $url;
1767
-
1768
- }
1769
-
1770
- public function plugin_is_installed( $name, $slug, $version = null ) {
1771
-
1772
- $is = false;
1773
-
1774
- $plugins = get_plugins();
1775
-
1776
- foreach ( $plugins as $plugin_id => $plugin ) {
1777
-
1778
- $wp_plugin_slug = dirname( $plugin_id );
1779
-
1780
- // Exception: embedded plugins
1781
- if ( $wp_plugin_slug == $slug || $plugin['Name'] == $name || $plugin['Title'] == $name || ( $wp_plugin_slug == $slug . '-embedded' || $plugin['Name'] == $name . ' Embedded' ) ) {
1782
- if ( $version ) {
1783
- if ( version_compare( $plugin['Version'], $version, '>=' ) ) {
1784
- $is = $plugin['Version'];
1785
- }
1786
- } else {
1787
- $is = $plugin['Version'];
1788
- }
1789
-
1790
- break;
1791
- }
1792
-
1793
- }
1794
-
1795
- //exception: Types name difference
1796
- if ( ! $is && $name == 'Types' ) {
1797
- return $this->plugin_is_installed( 'Types - Complete Solution for Custom Fields and Types', $slug, $version );
1798
- }
1799
-
1800
- return $is;
1801
- }
1802
-
1803
- public function plugin_is_embedded_version( $name, $slug ) {
1804
- $is = false;
1805
-
1806
- $plugins = get_plugins();
1807
-
1808
- //false if teh full version is also installed
1809
- $is_full_installed = false;
1810
- foreach ( $plugins as $plugin_id => $plugin ) {
1811
-
1812
- if ( ( $plugin['Name'] == $name && ! preg_match( "#-embedded$#", $slug ) ) ) {
1813
- $is_full_installed = true;
1814
- break;
1815
- }
1816
-
1817
- }
1818
-
1819
- if ( $is_full_installed ) {
1820
- return false;
1821
- }
1822
-
1823
- foreach ( $plugins as $plugin_id => $plugin ) {
1824
-
1825
- // TBD
1826
- $wp_plugin_slug = dirname( $plugin_id );
1827
- if ( $wp_plugin_slug == $slug . '-embedded' && $plugin['Name'] == $name . ' Embedded' ) {
1828
- $is = true;
1829
- break;
1830
- }
1831
-
1832
- }
1833
-
1834
- return $is;
1835
-
1836
- }
1837
-
1838
- //Alias for plugin_is_installed
1839
- public function get_plugin_installed_version( $name, $slug ) {
1840
-
1841
- return $this->plugin_is_installed( $name, $slug );
1842
-
1843
- }
1844
-
1845
- public function get_plugin_repository_version( $repository_id, $slug ) {
1846
- $version = false;
1847
-
1848
- if ( ! empty( $this->settings['repositories'][ $repository_id ]['data']['packages'] ) ) {
1849
- foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package ) {
1850
- foreach ( $package['products'] as $product ) {
1851
-
1852
- foreach ( $product['plugins'] as $plugin_slug ) {
1853
-
1854
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
1855
-
1856
- if ( $download['slug'] == $slug ) {
1857
- $version = $download['version'];
1858
- break ( 3 );
1859
- }
1860
-
1861
- }
1862
-
1863
- }
1864
- }
1865
- }
1866
-
1867
- return $version;
1868
- }
1869
-
1870
- public function is_uploading_allowed() {
1871
-
1872
- //_deprecated_function ( __FUNCTION__, '1.7.3', 'Installer_Dependencies::' . __FUNCTION__ );
1873
- return $this->dependencies->is_uploading_allowed();
1874
-
1875
- }
1876
-
1877
- public function download_plugin_ajax_handler() {
1878
-
1879
- require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1880
- require_once $this->plugin_path() . '/includes/class-installer-upgrader-skins.php';
1881
-
1882
- $data = json_decode( base64_decode( sanitize_text_field( $_POST['data'] ) ), true );
1883
-
1884
- $ret = false;
1885
- $plugin_id = false;
1886
- $message = '';
1887
-
1888
- //validate subscription
1889
- $site_key = $this->get_repository_site_key( $data['repository_id'] );
1890
- $subscription_data = $this->fetch_subscription_data( $data['repository_id'], $site_key, self::SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT );
1891
-
1892
- if ( $subscription_data && ! is_wp_error( $subscription_data ) && $this->repository_has_valid_subscription( $data['repository_id'] ) ) {
1893
-
1894
- if ( $data['nonce'] == wp_create_nonce( 'install_plugin_' . $data['url'] ) ) {
1895
-
1896
- $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
1897
- $upgrader = new Plugin_Upgrader( $upgrader_skins );
1898
-
1899
- remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
1900
-
1901
- $plugins = get_plugins();
1902
-
1903
- //upgrade or install?
1904
- foreach ( $plugins as $id => $plugin ) {
1905
- $wp_plugin_slug = dirname( $id );
1906
- $is_embedded = $this->plugin_is_embedded_version( preg_replace( '/ Embedded$/', '', $plugin['Name'] ), preg_replace( '/-embedded$/', '', $wp_plugin_slug ) );
1907
-
1908
- if ( $wp_plugin_slug == $data['slug'] || $is_embedded && preg_replace( '/-embedded$/', '', $wp_plugin_slug ) == $data['slug'] ) {
1909
- $plugin_id = $id;
1910
- break;
1911
- }
1912
- }
1913
-
1914
- if ( $plugin_id && empty( $is_embedded ) ) { //upgrade
1915
- $response['upgrade'] = 1;
1916
-
1917
- $plugin_is_active = is_plugin_active( $plugin_id );
1918
-
1919
- $ret = $upgrader->upgrade( $plugin_id );
1920
-
1921
- if ( ! $ret && ! empty( $upgrader->skin->installer_error ) ) {
1922
- if ( is_wp_error( $upgrader->skin->installer_error ) ) {
1923
- $message = $upgrader->skin->installer_error->get_error_message() .
1924
- ' (' . $upgrader->skin->installer_error->get_error_data() . ')';
1925
- }
1926
- $plugin_version = 0;
1927
- }else{
1928
- if ( $plugin_is_active ) {
1929
- //prevent redirects
1930
- add_filter( 'wp_redirect', '__return_false' );
1931
- activate_plugin( $plugin_id );
1932
- }
1933
- $plugin_version = $this->get_plugin_repository_version( $data['repository_id'], $data['slug'] );
1934
- }
1935
-
1936
- } else { //install
1937
-
1938
- if ( $is_embedded ) {
1939
- delete_plugins( array( $plugin_id ) );
1940
- }
1941
-
1942
- $response['install'] = 1;
1943
- $ret = $upgrader->install( $data['url'] );
1944
- if ( ! $ret && ! empty( $upgrader->skin->installer_error ) ) {
1945
- if ( is_wp_error( $upgrader->skin->installer_error ) ) {
1946
- $message = $upgrader->skin->installer_error->get_error_message() .
1947
- ' (' . $upgrader->skin->installer_error->get_error_data() . ')';
1948
- }
1949
- }
1950
- }
1951
-
1952
- $plugins = get_plugins(); //read again
1953
-
1954
- if ( $ret ) {
1955
- foreach ( $plugins as $id => $plugin ) {
1956
- $wp_plugin_slug = dirname( $id );
1957
- if ( $wp_plugin_slug == $data['slug'] ) {
1958
- $plugin_version = $plugin['Version'];
1959
- $plugin_id = $id;
1960
- break;
1961
- }
1962
- }
1963
-
1964
- }
1965
-
1966
- if( WP_Installer_Channels()->get_channel( $data['repository_id'] ) !== WP_Installer_Channels::CHANNEL_PRODUCTION ){
1967
- $download = $this->settings['repositories'][$data['repository_id']]['data']['downloads']['plugins'][$data['slug']];
1968
- $non_stable = WP_Installer_Channels()->get_download_source_channel( $plugin_version, $data['repository_id'], $download['slug'], 'plugins' );
1969
- }
1970
-
1971
- }
1972
-
1973
- } else { //subscription not valid
1974
-
1975
- $ret = false;
1976
- $message = __( 'Your subscription appears to no longer be valid. Please try to register again using a valid site key.', 'installer' );
1977
- }
1978
-
1979
- $response['version'] = isset( $plugin_version ) ? $plugin_version : 0;
1980
- $response['non_stable']= isset( $non_stable ) ? $non_stable : '';
1981
- $response['plugin_id'] = $plugin_id;
1982
- $response['nonce'] = wp_create_nonce( 'activate_' . $plugin_id );
1983
- $response['success'] = $ret;
1984
- $response['message'] = $message;
1985
-
1986
- echo json_encode( $response );
1987
- exit;
1988
-
1989
- }
1990
-
1991
- public function download_plugin( $slug, $url ) {
1992
-
1993
- require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1994
- require_once $this->plugin_path() . '/includes/class-installer-upgrader-skins.php';
1995
-
1996
- $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
1997
- $upgrader = new Plugin_Upgrader( $upgrader_skins );
1998
-
1999
- remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
2000
-
2001
- $plugins = get_plugins();
2002
-
2003
- $plugin_id = false;
2004
-
2005
- //upgrade or install?
2006
- foreach ( $plugins as $id => $plugin ) {
2007
- $wp_plugin_slug = dirname( $id );
2008
- if ( $wp_plugin_slug == $slug ) {
2009
- $plugin_id = $id;
2010
- break;
2011
- }
2012
- }
2013
-
2014
- if ( $plugin_id ) { //upgrade
2015
-
2016
- $plugin_is_active = is_plugin_active( $plugin_id );
2017
-
2018
- $ret = $upgrader->upgrade( $plugin_id );
2019
-
2020
- if ( $plugin_is_active ) {
2021
- activate_plugin( $plugin_id );
2022
- }
2023
-
2024
- } else { //install
2025
- $ret = $upgrader->install( $url );
2026
- }
2027
-
2028
- return $ret;
2029
-
2030
- }
2031
-
2032
- public function activate_plugin() {
2033
-
2034
- $error = '';
2035
-
2036
- $plugin_id = sanitize_text_field( $_POST['plugin_id'] );
2037
- if ( isset( $_POST['nonce'] ) && $plugin_id && $_POST['nonce'] == wp_create_nonce( 'activate_' . $plugin_id ) ) {
2038
-
2039
- // Deactivate any embedded version
2040
- $plugin_slug = dirname( $plugin_id );
2041
- $active_plugins = get_option( 'active_plugins' );
2042
- foreach ( $active_plugins as $plugin ) {
2043
- $wp_plugin_slug = dirname( $plugin );
2044
- if ( $wp_plugin_slug == $plugin_slug . '-embedded' ) {
2045
- deactivate_plugins( array( $plugin ) );
2046
- break;
2047
- }
2048
- }
2049
-
2050
- //prevent redirects
2051
- add_filter( 'wp_redirect', '__return_false', 10000 );
2052
-
2053
- $return = activate_plugin( $plugin_id );
2054
-
2055
- if ( is_wp_error( $return ) ) {
2056
- $error = $return->get_error_message();
2057
- }
2058
-
2059
- } else {
2060
- $error = 'error';
2061
- }
2062
-
2063
- $ret = array( 'error' => $error );
2064
-
2065
- echo json_encode( $ret );
2066
- exit;
2067
-
2068
- }
2069
-
2070
- public function custom_plugins_api_call( $false, $action, $args ) {
2071
-
2072
- if ( $action == 'plugin_information' ) {
2073
-
2074
- $plugins = get_plugins();
2075
- $plugin_names = array();
2076
- foreach ( $plugins as $plugin_id => $plugin ) {
2077
- // plugins by WP slug which (plugin folder) which can be different
2078
- // will use this to compare by title
2079
- $plugin_names[ dirname( $plugin_id ) ] = array(
2080
- 'name' => $plugin['Name'],
2081
- 'title' => $plugin['Title'],
2082
- );
2083
- }
2084
-
2085
- $slug = $args->slug;
2086
-
2087
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2088
-
2089
- if ( ! $this->repository_has_valid_subscription( $repository_id ) ) {
2090
- $site_key = false;
2091
- } else {
2092
- $site_key = $repository['subscription']['key'];
2093
- }
2094
-
2095
- foreach ( $repository['data']['packages'] as $package ) {
2096
-
2097
- foreach ( $package['products'] as $product ) {
2098
-
2099
- foreach ( $product['plugins'] as $plugin_slug ) {
2100
-
2101
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2102
-
2103
- if ( $download['slug'] == $slug ||
2104
- isset( $plugin_names[ $slug ] ) && (
2105
- $plugin_names[ $slug ]['name'] == $download['name'] ||
2106
- $plugin_names[ $slug ]['title'] == $download['name']
2107
- )
2108
- ) {
2109
-
2110
- if ( ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION ) {
2111
- return false; // use data from wordpress.org
2112
- }
2113
-
2114
- $res = new stdClass();
2115
- $res->external = true;
2116
-
2117
- $res->name = $download['name'];
2118
- $res->slug = $slug;
2119
- $res->version = $download['version'];
2120
- $res->author = '';
2121
- $res->author_profile = '';
2122
- $res->last_updated = $download['date'];
2123
-
2124
- if ( $site_key ) {
2125
- $res->download_link = $this->append_site_key_to_download_url( $download['url'], $site_key, $repository_id );
2126
- }
2127
-
2128
- $res->homepage = $repository['data']['url'];
2129
- $res->sections = array(
2130
- 'Description' => $download['description'],
2131
- 'Changelog' => $download['changelog']
2132
- );
2133
-
2134
- return $res;
2135
-
2136
- }
2137
-
2138
- }
2139
-
2140
- }
2141
-
2142
- }
2143
-
2144
- }
2145
-
2146
- }
2147
-
2148
- return $false;
2149
-
2150
- }
2151
-
2152
- public function plugins_upgrade_check( $update_plugins ) {
2153
-
2154
- if ( ! empty( $this->settings['repositories'] ) ) {
2155
-
2156
- $plugins = get_plugins();
2157
-
2158
- foreach ( $plugins as $plugin_id => $plugin ) {
2159
-
2160
- $slug = dirname( $plugin_id );
2161
- if ( empty( $slug ) ) {
2162
- continue;
2163
- }
2164
-
2165
- $version = $plugin['Version'];
2166
- $name = $plugin['Name'];
2167
-
2168
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2169
-
2170
-
2171
- if ( ! $this->repository_has_valid_subscription( $repository_id ) ) {
2172
- $site_key = false;
2173
- } else {
2174
- $site_key = $repository['subscription']['key'];
2175
- //$subscription_type = $this->get_subscription_type_for_repository($repository_id);
2176
- }
2177
-
2178
- foreach ( $repository['data']['packages'] as $package ) {
2179
-
2180
- foreach ( $package['products'] as $product ) {
2181
-
2182
- foreach ( $product['plugins'] as $plugin_slug ) {
2183
-
2184
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2185
-
2186
- if ( ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION ) {
2187
- continue;
2188
- }
2189
-
2190
- $needs_version_update = version_compare( $download['version'], $version, '>' ) ||
2191
- ! empty( $_POST['reset_to_channel'] );
2192
-
2193
- if (
2194
- empty( $update_plugins->response[ $plugin_id ] ) &&
2195
- ( $download['slug'] == $slug || $download['name'] == $name ) &&
2196
- $needs_version_update
2197
- ) {
2198
-
2199
- $response = new stdClass();
2200
- $response->id = 0;
2201
- $response->slug = $slug;
2202
- $response->plugin = $plugin_id;
2203
- $response->new_version = $download['version'];
2204
- $response->upgrade_notice = '';
2205
- $response->url = $download['url'];
2206
- if ( $site_key ) {
2207
- $response->package = $this->append_site_key_to_download_url( $download['url'], $site_key, $repository_id );
2208
- }
2209
- $update_plugins->checked[ $plugin_id ] = $version;
2210
- $update_plugins->response[ $plugin_id ] = $response;
2211
-
2212
- }
2213
-
2214
- }
2215
-
2216
- }
2217
-
2218
- }
2219
-
2220
- }
2221
-
2222
- }
2223
-
2224
- }
2225
-
2226
- return $update_plugins;
2227
-
2228
- }
2229
-
2230
- public function setup_plugins_page_notices() {
2231
-
2232
- $plugins = get_plugins();
2233
-
2234
- foreach ( $plugins as $plugin_id => $plugin ) {
2235
-
2236
- $slug = dirname( $plugin_id );
2237
- if ( empty( $slug ) ) {
2238
- continue;
2239
- }
2240
-
2241
- $name = $plugin['Name'];
2242
-
2243
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2244
-
2245
- if ( ! $this->repository_has_valid_subscription( $repository_id ) ) {
2246
- $site_key = false;
2247
- } else {
2248
- $site_key = $repository['subscription']['key'];
2249
- }
2250
-
2251
- foreach ( $repository['data']['packages'] as $package ) {
2252
-
2253
- foreach ( $package['products'] as $product ) {
2254
-
2255
- foreach ( $product['plugins'] as $plugin_slug ) {
2256
-
2257
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2258
-
2259
- if ( ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION ) {
2260
- continue;
2261
- }
2262
-
2263
- if ( $download['slug'] == $slug || $download['name'] == $name ) {
2264
-
2265
- if ( ! $site_key || ! $this->plugin_is_registered( $repository_id, $download['slug'] ) ) {
2266
- add_action( "after_plugin_row_" . $plugin_id, array(
2267
- $this,
2268
- 'show_purchase_notice_under_plugin'
2269
- ), 10, 3 );
2270
- }
2271
-
2272
- }
2273
-
2274
- }
2275
-
2276
- }
2277
-
2278
- }
2279
-
2280
- }
2281
-
2282
- }
2283
-
2284
- }
2285
-
2286
- public function show_purchase_notice_under_plugin( $plugin_file, $plugin_data, $status ) {
2287
-
2288
- $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
2289
- $wp_version = preg_replace( '/-(.+)$/', '', $GLOBALS['wp_version'] );
2290
-
2291
- if ( version_compare( $wp_version, '4.6', '>=' ) ) {
2292
-
2293
- ?>
2294
- <tr class="plugin-update-tr installer-plugin-update-tr">
2295
- <td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
2296
- <div class="notice inline notice-warning notice-alt">
2297
- <p class="installer-q-icon">
2298
- <?php printf( __( 'You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer' ),
2299
- '<a href="' . $this->menu_url() . '">', '</a>' ); ?>
2300
- </p>
2301
- </div>
2302
- </td>
2303
- </tr>
2304
- <?php
2305
-
2306
- } else {
2307
-
2308
- ?>
2309
- <tr class="plugin-update-tr">
2310
- <td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
2311
- <div class="update-message installer-q-icon">
2312
- <?php printf( __( 'You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer' ),
2313
- '<a href="' . $this->menu_url() . '">', '</a>' ); ?>
2314
- </div>
2315
- </td>
2316
- </tr>
2317
- <?php
2318
-
2319
- }
2320
-
2321
- }
2322
-
2323
- public function localize_strings() {
2324
-
2325
- if ( ! empty( $this->settings['repositories'] ) ) {
2326
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2327
- //set name as call2action when don't have any
2328
- //products
2329
- foreach ( $repository['data']['packages'] as $package_id => $package ) {
2330
- foreach ( $package['products'] as $product_id => $product ) {
2331
- if ( empty( $product['call2action'] ) ) {
2332
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['call2action'] = $product['name'];
2333
- }
2334
-
2335
- foreach ( $product['upgrades'] as $idx => $upg ) {
2336
- if ( empty( $upg['call2action'] ) ) {
2337
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['upgrades'][ $idx ]['call2action'] = $upg['name'];
2338
- }
2339
- }
2340
-
2341
- foreach ( $product['renewals'] as $idx => $rnw ) {
2342
- if ( empty( $rnw['call2action'] ) ) {
2343
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['renewals'][ $idx ]['call2action'] = $rnw['name'];
2344
- }
2345
-
2346
- }
2347
-
2348
- }
2349
- }
2350
- }
2351
- }
2352
-
2353
- global $sitepress;
2354
- if ( is_null( $sitepress ) ) {
2355
- return;
2356
- }
2357
-
2358
- // default strings are always in English
2359
- $user_admin_language = $sitepress->get_admin_language();
2360
-
2361
- if ( $user_admin_language != 'en' ) {
2362
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2363
-
2364
- $localization = $repository['data']['localization'];
2365
-
2366
- //packages
2367
- foreach ( $repository['data']['packages'] as $package_id => $package ) {
2368
-
2369
- if ( isset( $localization['packages'][ $package_id ]['name'][ $user_admin_language ] ) ) {
2370
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['name'] = $localization['packages'][ $package_id ]['name'][ $user_admin_language ];
2371
- }
2372
- if ( isset( $localization['packages'][ $package_id ]['description'][ $user_admin_language ] ) ) {
2373
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['description'] = $localization['packages'][ $package_id ]['description'][ $user_admin_language ];
2374
- }
2375
-
2376
- }
2377
-
2378
- //products
2379
- foreach ( $repository['data']['packages'] as $package_id => $package ) {
2380
- foreach ( $package['products'] as $product_id => $product ) {
2381
-
2382
- if ( isset( $localization['products'][ $product_id ]['name'][ $user_admin_language ] ) ) {
2383
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['name']
2384
- = $localization['products'][ $product_id ]['name'][ $user_admin_language ];
2385
- }
2386
- if ( isset( $localization['products'][ $product_id ]['description'][ $user_admin_language ] ) ) {
2387
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['description']
2388
- = $localization['products'][ $product_id ]['description'][ $user_admin_language ];
2389
- }
2390
- if ( isset( $localization['products'][ $product_id ]['call2action'][ $user_admin_language ] ) ) {
2391
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['name']
2392
- = $localization['products'][ $product_id ]['call2action'][ $user_admin_language ];
2393
- }
2394
-
2395
-
2396
- }
2397
- }
2398
-
2399
- //subscription info
2400
- if ( isset( $repository['data']['subscriptions_meta']['expiration'] ) ) {
2401
- foreach ( $repository['data']['subscriptions_meta']['expiration'] as $subscription_id => $note ) {
2402
- if ( isset( $localization['subscriptions-notes'][ $subscription_id ]['expiration-warning'][ $user_admin_language ] ) ) {
2403
- $this->settings['repositories'][ $repository_id ]['data']['subscriptions_meta']['expiration'][ $subscription_id ]['warning_message']
2404
- = $localization['subscriptions-notes'][ $subscription_id ]['expiration-warning'][ $user_admin_language ];
2405
- }
2406
- }
2407
- }
2408
-
2409
- }
2410
- }
2411
-
2412
- }
2413
-
2414
- public function get_matching_cp( $repository, $args = array() ) {
2415
- $match = false;
2416
-
2417
-
2418
- $cp_name = $cp_author = false;
2419
-
2420
- if ( isset( $this->config['src_name'] ) && isset( $this->config['src_author'] ) ) {
2421
-
2422
- $cp_name = $this->config['src_name'];
2423
- $cp_author = $this->config['src_author'];
2424
-
2425
- } elseif ( isset( $args['src_name'] ) && isset( $args['src_author'] ) ) {
2426
-
2427
- $cp_name = $args['src_name'];
2428
- $cp_author = $args['src_author'];
2429
-
2430
- }
2431
-
2432
- if ( isset( $repository['data']['marketing_cp'] ) ) {
2433
-
2434
- foreach ( $repository['data']['marketing_cp'] as $cp ) {
2435
-
2436
- if ( ! empty( $cp['exp'] ) && time() > $cp['exp'] ) {
2437
- continue;
2438
- }
2439
-
2440
- //Use theme_name for plugins too
2441
- if ( ! empty( $cp['theme_name'] ) ) {
2442
- if ( $cp['author_name'] == $cp_author && $cp['theme_name'] == $cp_name ) {
2443
- $match = $cp;
2444
- continue;
2445
- }
2446
- } else {
2447
- if ( $cp['author_name'] == $cp_author ) {
2448
- $match = $cp;
2449
- continue;
2450
- }
2451
- }
2452
-
2453
- }
2454
-
2455
- }
2456
-
2457
- return $match;
2458
- }
2459
-
2460
- public function set_filtered_prices( $args = array() ) {
2461
-
2462
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2463
-
2464
- $match = $this->get_matching_cp( $repository, $args );
2465
-
2466
- if ( empty( $match ) ) {
2467
- continue;
2468
- }
2469
-
2470
- foreach ( $repository['data']['packages'] as $package_id => $package ) {
2471
-
2472
- foreach ( $package['products'] as $product_id => $product ) {
2473
-
2474
- if ( $match['dtp'] == '%' ) {
2475
- $fprice = round( $product['price'] * ( 1 - $match['amt'] / 100 ), 2 );
2476
- $fprice = $fprice != round( $fprice ) ? sprintf( '%.2f', $fprice ) : round( $fprice, 0 );
2477
- } elseif ( $match['dtp'] == '-' ) {
2478
- $fprice = $product['price'] - $match['amt'];
2479
- } else {
2480
- $fprice = $product['price'];
2481
- }
2482
-
2483
- if ( $fprice ) {
2484
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['price_disc'] = $fprice;
2485
-
2486
- $url_glue = false !== strpos( $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['url'], '?' ) ? '&' : '?';
2487
- $cpndata = base64_encode( json_encode( array(
2488
- 'theme_author' => $match['author_name'],
2489
- 'theme_name' => $match['theme_name'],
2490
- 'vlc' => $match['vlc']
2491
- ) ) );
2492
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['url'] .= $url_glue . 'cpn=' . $cpndata;
2493
-
2494
- foreach ( $product['upgrades'] as $upgrade_id => $upgrade ) {
2495
-
2496
- $fprice = false;
2497
- if ( $match['dtp'] == '%' ) {
2498
- $fprice = round( $upgrade['price'] * ( 1 - $match['amt'] / 100 ), 2 );
2499
- $fprice = $fprice != round( $fprice ) ? sprintf( '%.2f', $fprice ) : round( $fprice, 0 );
2500
- } elseif ( $match['dtp'] == '-' ) {
2501
- $fprice = $upgrade['price'] - $match['amt'];
2502
- }
2503
- if ( $fprice ) {
2504
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['upgrades'][ $upgrade_id ]['price_disc'] = $fprice;
2505
- $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['upgrades'][ $upgrade_id ]['url'] .= $url_glue . 'cpn=' . $cpndata;
2506
- }
2507
-
2508
-
2509
- }
2510
-
2511
- }
2512
-
2513
- }
2514
-
2515
- }
2516
-
2517
- }
2518
-
2519
- }
2520
-
2521
- public function set_hierarchy_and_order() {
2522
-
2523
- //2 levels
2524
- if ( ! empty( $this->settings['repositories'] ) ) {
2525
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2526
-
2527
- if ( empty( $repository['data']['packages'] ) ) {
2528
- continue;
2529
- }
2530
-
2531
- $all_packages = $repository['data']['packages'];
2532
- $ordered_packages = array();
2533
-
2534
- //backward compatibility - 'order'
2535
- foreach ( $all_packages as $k => $v ) {
2536
- if ( ! isset( $v['order'] ) ) {
2537
- $all_packages[ $k ]['order'] = 0;
2538
- }
2539
- }
2540
-
2541
- //select parents
2542
- foreach ( $all_packages as $package_id => $package ) {
2543
- if ( empty( $package['parent'] ) ) {
2544
- $ordered_packages[ $package_id ] = $package;
2545
- }
2546
- }
2547
-
2548
- //add sub-packages
2549
- foreach ( $all_packages as $package_id => $package ) {
2550
- if ( ! empty( $package['parent'] ) ) {
2551
- if ( isset( $ordered_packages[ $package['parent'] ] ) ) {
2552
- $ordered_packages[ $package['parent'] ]['sub-packages'][ $package_id ] = $package;
2553
- }
2554
- }
2555
- }
2556
-
2557
- // order parents
2558
- usort( $ordered_packages, array( $this, '_order_packages_callback' ) );
2559
- //order sub-packages
2560
- foreach ( $ordered_packages as $package_id => $package ) {
2561
- if ( ! empty( $package['sub-packages'] ) ) {
2562
- usort( $ordered_packages[ $package_id ]['sub-packages'], create_function( '$a, $b', 'return $a[\'order\'] > $b[\'order\'];' ) );
2563
- }
2564
- }
2565
-
2566
- $this->settings['repositories'][ $repository_id ]['data']['packages'] = $ordered_packages;
2567
-
2568
-
2569
- }
2570
- }
2571
-
2572
-
2573
- }
2574
-
2575
- public function _order_packages_callback( $a, $b ) {
2576
- return $a['order'] > $b['order'];
2577
- }
2578
-
2579
- public function get_support_tag_by_name( $name, $repository ) {
2580
-
2581
- if ( is_array( $this->settings['repositories'][ $repository ]['data']['support_tags'] ) ) {
2582
- foreach ( $this->settings['repositories'][ $repository ]['data']['support_tags'] as $support_tag ) {
2583
- if ( $support_tag['name'] == $name ) {
2584
- return $support_tag['url'];
2585
- }
2586
- }
2587
- }
2588
-
2589
- return false;
2590
- }
2591
-
2592
- public function plugin_upgrade_custom_errors() {
2593
-
2594
- if ( isset( $_REQUEST['action'] ) ) {
2595
-
2596
- $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
2597
-
2598
- //bulk mode
2599
- if ( 'update-selected' == $action ) {
2600
-
2601
- global $plugins;
2602
-
2603
- if ( isset( $plugins ) && is_array( $plugins ) ) {
2604
-
2605
- foreach ( $plugins as $k => $plugin ) {
2606
- $plugin_repository = false;
2607
-
2608
- $wp_plugin_slug = dirname( $plugin );
2609
-
2610
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2611
-
2612
- foreach ( $repository['data']['packages'] as $package ) {
2613
-
2614
- foreach ( $package['products'] as $product ) {
2615
-
2616
- foreach ( $product['plugins'] as $plugin_slug ) {
2617
-
2618
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2619
-
2620
- if ( $download['slug'] == $wp_plugin_slug ) {
2621
- $plugin_repository = $repository_id;
2622
- $product_name = $repository['data']['product-name'];
2623
- $plugin_name = $download['name'];
2624
- $free_on_wporg = ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION;
2625
- break;
2626
- }
2627
-
2628
- }
2629
-
2630
- }
2631
-
2632
- }
2633
-
2634
- }
2635
-
2636
- if ( $plugin_repository ) {
2637
-
2638
- //validate subscription
2639
- static $sub_cache = array();
2640
-
2641
- if ( empty( $sub_cache[ $plugin_repository ] ) ) {
2642
- $site_key = $this->get_repository_site_key( $plugin_repository );
2643
- if ( $site_key ) {
2644
- $subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
2645
- }
2646
-
2647
- $sub_cache[ $plugin_repository ]['site_key'] = $site_key;
2648
- $sub_cache[ $plugin_repository ]['subscription_data'] = isset( $subscription_data ) ? $subscription_data : false;
2649
- } else {
2650
-
2651
- $site_key = $sub_cache[ $plugin_repository ]['site_key'];
2652
- $subscription_data = $sub_cache[ $plugin_repository ]['subscription_data'];
2653
-
2654
- }
2655
-
2656
- if ( ! $site_key && ! empty( $free_on_wporg ) ) { // allow the download from wp.org
2657
- continue;
2658
- }
2659
-
2660
- if ( empty( $site_key ) || empty( $subscription_data ) ) {
2661
-
2662
-
2663
- $error_message = sprintf( __( "%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer' ),
2664
- '<strong>' . $plugin_name . '</strong>', '<a target="_top" href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
2665
- '#repository-' . $plugin_repository . '">', $product_name, '</a>' );
2666
-
2667
- echo '<div class="updated error"><p>' . $error_message . '</p></div>';
2668
-
2669
- unset( $plugins[ $k ] );
2670
-
2671
-
2672
- }
2673
-
2674
- }
2675
-
2676
- }
2677
-
2678
- }
2679
-
2680
- }
2681
-
2682
-
2683
- if ( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
2684
-
2685
- $plugin = isset( $_REQUEST['plugin'] ) ? trim( sanitize_text_field( $_REQUEST['plugin'] ) ) : '';
2686
-
2687
- $wp_plugin_slug = dirname( $plugin );
2688
-
2689
- $plugin_repository = false;
2690
-
2691
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2692
-
2693
- foreach ( $repository['data']['packages'] as $package ) {
2694
-
2695
- foreach ( $package['products'] as $product ) {
2696
-
2697
- foreach ( $product['plugins'] as $plugin_slug ) {
2698
- $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2699
-
2700
- //match by folder, will change to match by name and folder
2701
- if ( $download['slug'] == $wp_plugin_slug ) {
2702
- $plugin_repository = $repository_id;
2703
- $product_name = $repository['data']['product-name'];
2704
- $plugin_name = $download['name'];
2705
- $free_on_wporg = ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION;
2706
- break;
2707
- }
2708
-
2709
- }
2710
-
2711
- }
2712
-
2713
- }
2714
-
2715
- }
2716
-
2717
- if ( $plugin_repository ) {
2718
-
2719
- //validate subscription
2720
- $site_key = $this->get_repository_site_key( $plugin_repository );
2721
- if ( $site_key ) {
2722
- $subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
2723
- }
2724
-
2725
- if ( ( empty( $site_key ) || empty( $subscription_data ) ) && empty( $free_on_wporg ) ) {
2726
-
2727
- $error_message = sprintf( __( "%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer' ),
2728
- '<strong>' . $plugin_name . '</strong>', '<a href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
2729
- '#repository-' . $plugin_repository . '">', $product_name, '</a>' );
2730
-
2731
- if ( defined( 'DOING_AJAX' ) ) { //WP 4.2
2732
-
2733
- $status = array(
2734
- 'update' => 'plugin',
2735
- 'plugin' => $plugin,
2736
- 'slug' => sanitize_key( $_POST['slug'] ),
2737
- 'oldVersion' => '',
2738
- 'newVersion' => '',
2739
- );
2740
-
2741
- $status['errorCode'] = 'wp_installer_invalid_subscription';
2742
- $status['error'] = $error_message;
2743
-
2744
- wp_send_json_error( $status );
2745
-
2746
- } else { // WP 4.1.1
2747
- echo '<div class="updated error"><p>' . $error_message . '</p></div>';
2748
-
2749
-
2750
- echo '<div class="wrap">';
2751
- echo '<h2>' . __( 'Update Plugin', 'installer' ) . '</h2>';
2752
- echo '<a href="' . admin_url( 'plugins.php' ) . '">' . __( 'Return to the plugins page', 'installer' ) . '</a>';
2753
- echo '</div>';
2754
- require_once( ABSPATH . 'wp-admin/admin-footer.php' );
2755
- exit;
2756
-
2757
- }
2758
-
2759
- }
2760
-
2761
-
2762
- }
2763
-
2764
- }
2765
- }
2766
-
2767
- }
2768
-
2769
- }
1
+ <?php
2
+
3
+ final class WP_Installer {
4
+ protected static $_instance = null;
5
+
6
+ public $settings = array();
7
+
8
+ private $repositories = array();
9
+
10
+ protected $api_debug = '';
11
+
12
+ private $config = array();
13
+
14
+ protected $_plugins_renew_warnings = array();
15
+
16
+ protected $_gz_on = false;
17
+
18
+ private $admin_messages = array();
19
+
20
+ private $_using_icl = false;
21
+ private $_wpml_version = false;
22
+
23
+ private $package_source = array();
24
+
25
+ const SITE_KEY_VALIDATION_SOURCE_OTHER = 0;
26
+ const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_SPECIFIC = 1;
27
+ const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT = 2;
28
+ const SITE_KEY_VALIDATION_SOURCE_REGISTRATION = 3;
29
+ const SITE_KEY_VALIDATION_SOURCE_REVALIDATION = 4;
30
+ const SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK = 5;
31
+
32
+ public $dependencies;
33
+
34
+ public static function instance() {
35
+
36
+ if ( is_null( self::$_instance ) ) {
37
+ self::$_instance = new self();
38
+ }
39
+
40
+ return self::$_instance;
41
+ }
42
+
43
+ public function __construct() {
44
+
45
+ if ( ! is_admin() || ! is_user_logged_in() ) {
46
+ return;
47
+ } //Only for admin
48
+
49
+ $this->_gz_on = function_exists( 'gzuncompress' ) && function_exists( 'gzcompress' );
50
+ $this->settings = $this->get_settings();
51
+
52
+ add_action( 'admin_notices', array( $this, 'show_site_key_nags' ) );
53
+
54
+ add_action( 'admin_notices', array( $this, 'show_admin_messages' ) );
55
+
56
+ add_action( 'admin_init', array( $this, 'load_embedded_plugins' ), 0 );
57
+
58
+ add_action( 'admin_menu', array( $this, 'menu_setup' ) );
59
+ add_action( 'network_admin_menu', array( $this, 'menu_setup' ) );
60
+
61
+ if ( defined( 'DOING_AJAX' ) && isset( $_POST['action'] ) && $_POST['action'] == 'installer_download_plugin' ) {
62
+ add_filter( 'site_transient_update_plugins', array( $this, 'plugins_upgrade_check' ) );
63
+ }
64
+ add_filter( 'plugins_api', array( $this, 'custom_plugins_api_call' ), 10, 3 );
65
+ add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'plugins_upgrade_check' ) );
66
+
67
+ // register repositories
68
+ $this->load_repositories_list();
69
+
70
+ // default config
71
+ $this->config['plugins_install_tab'] = false;
72
+
73
+ add_action( 'init', array( $this, 'init' ) );
74
+
75
+ //add_filter('wp_installer_buy_url', array($this, 'append_parameters_to_buy_url'));
76
+
77
+ add_action( 'init', array( $this, 'load_locale' ) );
78
+
79
+ }
80
+
81
+ public function get_repositories() {
82
+
83
+ return $this->repositories;
84
+
85
+ }
86
+
87
+ public function set_config( $key, $value ) {
88
+
89
+ $this->config[ $key ] = $value;
90
+
91
+ }
92
+
93
+ public function init() {
94
+ global $pagenow;
95
+
96
+ if ( empty( $this->settings['last_repositories_update'] ) || time() - $this->settings['last_repositories_update'] > 86400
97
+ || ( isset( $_GET['force-check'] ) && $_GET['force-check'] == 1 )
98
+ ) {
99
+ $this->refresh_repositories_data();
100
+ }
101
+
102
+ $this->dependencies = new Installer_Dependencies;
103
+
104
+ if ( empty( $this->settings['_pre_1_0_clean_up'] ) ) {
105
+ $this->_pre_1_0_clean_up();
106
+ }
107
+
108
+ $this->settings = $this->_old_products_format_backwards_compatibility( $this->settings );
109
+
110
+ if ( ! function_exists( 'get_plugins' ) ) {
111
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
112
+ }
113
+
114
+ $this->_using_icl = function_exists( 'wpml_site_uses_icl' ) && wpml_site_uses_icl();
115
+ $this->_wpml_version = defined( 'ICL_SITEPRESS_VERSION' ) ? ICL_SITEPRESS_VERSION : '';
116
+
117
+ wp_enqueue_script( 'installer-admin', $this->res_url() . '/res/js/admin.js', array( 'jquery' ), $this->version() );
118
+ wp_enqueue_style( 'installer-admin', $this->res_url() . '/res/css/admin.css', array(), $this->version() );
119
+
120
+ $translation_array = array(
121
+ 'installing' => __( 'Installing %s', 'installer' ),
122
+ 'updating' => __( 'Updating %s', 'installer' ),
123
+ 'activating' => __( 'Activating %s', 'installer' )
124
+ );
125
+
126
+ wp_localize_script( 'installer-admin', 'installer_strings', $translation_array );
127
+
128
+ if ( $pagenow == 'plugins.php' ) {
129
+ add_action( 'admin_notices', array( $this, 'setup_plugins_page_notices' ) );
130
+ add_action( 'admin_notices', array( $this, 'setup_plugins_renew_warnings' ), 10 );
131
+ add_action( 'admin_notices', array( $this, 'queue_plugins_renew_warnings' ), 20 );
132
+
133
+ add_action( 'admin_init', array( $this, 'setup_plugins_action_links' ) );
134
+
135
+ }
136
+
137
+ if ( $this->is_repositories_page() ) {
138
+ add_action( 'admin_init', array( $this, 'validate_repository_subscription' ) );
139
+ }
140
+
141
+ if ( defined( 'DOING_AJAX' ) ) {
142
+ add_action( 'wp_ajax_save_site_key', array( $this, 'save_site_key' ) );
143
+ add_action( 'wp_ajax_remove_site_key', array( $this, 'remove_site_key_ajax' ) );
144
+ add_action( 'wp_ajax_update_site_key', array( $this, 'update_site_key' ) );
145
+
146
+ add_action( 'wp_ajax_installer_download_plugin', array( $this, 'download_plugin_ajax_handler' ) );
147
+ add_action( 'wp_ajax_installer_activate_plugin', array( $this, 'activate_plugin' ) );
148
+
149
+ add_action( 'wp_ajax_installer_dismiss_nag', array( $this, 'dismiss_nag' ) );
150
+ }
151
+
152
+ if ( $pagenow == 'update.php' ) {
153
+ if ( isset( $_GET['action'] ) && $_GET['action'] == 'update-selected' ) {
154
+ add_action( 'admin_head', array( $this, 'plugin_upgrade_custom_errors' ) ); //iframe/bulk
155
+ } else {
156
+ add_action( 'all_admin_notices', array( $this, 'plugin_upgrade_custom_errors' ) ); //regular/singular
157
+ }
158
+ }
159
+
160
+ // WP 4.2
161
+ if ( defined( 'DOING_AJAX' ) ) {
162
+ add_action( 'wp_ajax_update-plugin', array(
163
+ $this,
164
+ 'plugin_upgrade_custom_errors'
165
+ ), 0 ); // high priority, before WP
166
+ }
167
+
168
+ //Include theme support
169
+ include_once $this->plugin_path() . '/includes/class-installer-theme.php';
170
+
171
+ // Extra information about the source of Installer
172
+ $package_source_file = $this->plugin_path() . '/installer-source.json';
173
+ if ( file_exists( $package_source_file ) ) {
174
+ WP_Filesystem();
175
+ global $wp_filesystem;
176
+ $this->package_source = json_decode( $wp_filesystem->get_contents( $package_source_file ) );
177
+ }
178
+ }
179
+
180
+ protected function log( $message ) {
181
+ require_once ABSPATH . 'wp-admin/includes/file.php';
182
+ WP_Filesystem();
183
+ global $wp_filesystem;
184
+ if ( defined( 'WPML_INSTALLER_LOGGING' ) && WPML_INSTALLER_LOGGING ) {
185
+ $wp_filesystem->put_contents( $this->plugin_path() . '/installer.log', current_time( 'mysql' ) . "\t" . $message . "\n" );
186
+ }
187
+ }
188
+
189
+ public function register_admin_message( $text, $type = 'updated' ) {
190
+ $this->admin_messages[] = array( 'text' => $text, 'type' => $type );
191
+ }
192
+
193
+ public function show_admin_messages() {
194
+ if ( ! empty( $this->admin_messages ) ) {
195
+ $types = array( 'error', 'updated', 'notice' );
196
+ foreach ( $this->admin_messages as $message ) {
197
+ $class = in_array( $message['type'], $types ) ? $message['type'] : 'updated';
198
+ ?>
199
+ <div class="<?php echo $class ?>">
200
+ <p>
201
+ <?php echo $message['text'] ?>
202
+ </p>
203
+ </div>
204
+ <?php
205
+ }
206
+ }
207
+ }
208
+
209
+ public function load_locale() {
210
+ if ( function_exists( 'get_user_locale' ) ) {
211
+ $locale = get_user_locale();
212
+ } else {
213
+ $locale = get_locale();
214
+ }
215
+ $locale = apply_filters( 'plugin_locale', $locale, 'installer' );
216
+ $mo_file = $this->plugin_path() . '/locale/installer-' . $locale . '.mo';
217
+ if ( file_exists( $mo_file ) ) {
218
+ load_textdomain( 'installer', $mo_file );
219
+ }
220
+ }
221
+
222
+ public function load_embedded_plugins() {
223
+ if ( file_exists( $this->plugin_path() . '/embedded-plugins' ) ) {
224
+ include_once $this->plugin_path() . '/embedded-plugins/embedded-plugins.class.php';
225
+ $this->installer_embedded_plugins = new Installer_Embedded_Plugins();
226
+ }
227
+ }
228
+
229
+ public function menu_setup() {
230
+ global $pagenow;
231
+
232
+ if ( is_multisite() && ! is_network_admin() ) {
233
+ $this->menu_multisite_redirect();
234
+ add_options_page( __( 'Installer', 'installer' ), __( 'Installer', 'installer' ), 'manage_options', 'installer', array(
235
+ $this,
236
+ 'show_products'
237
+ ) );
238
+ } else {
239
+ if ( $this->config['plugins_install_tab'] && is_admin() && $pagenow == 'plugin-install.php' ) {
240
+ // Default GUI, under Plugins -> Install
241
+ add_filter( 'install_plugins_tabs', array( $this, 'add_install_plugins_tab' ) );
242
+ add_action( 'install_plugins_commercial', array( $this, 'show_products' ) );
243
+ }
244
+ }
245
+
246
+ }
247
+
248
+ public function menu_url() {
249
+ if ( is_multisite() ) {
250
+ if ( is_network_admin() ) {
251
+ $url = network_admin_url( 'plugin-install.php?tab=commercial' );
252
+ } else {
253
+ $url = admin_url( 'options-general.php?page=installer' );
254
+ }
255
+ } else {
256
+ $url = admin_url( 'plugin-install.php?tab=commercial' );
257
+ }
258
+
259
+ return $url;
260
+ }
261
+
262
+ private function menu_multisite_redirect() {
263
+ global $pagenow;
264
+
265
+ if ( $pagenow == 'plugin-install.php' && isset( $_GET['tab'] ) && $_GET['tab'] == 'commercial' ) {
266
+ wp_redirect( $this->menu_url() );
267
+ exit;
268
+ }
269
+
270
+ }
271
+
272
+ private function _pre_1_0_clean_up() {
273
+ global $wpdb;
274
+
275
+ if ( ! defined( 'WPRC_VERSION' ) ) {
276
+ $old_tables = array(
277
+ $wpdb->prefix . 'wprc_cached_requests',
278
+ $wpdb->prefix . 'wprc_extension_types',
279
+ $wpdb->prefix . 'wprc_extensions',
280
+ $wpdb->prefix . 'wprc_repositories',
281
+ $wpdb->prefix . 'wprc_repositories_relationships',
282
+ );
283
+
284
+ foreach ( $old_tables as $table ) {
285
+ $wpdb->query( sprintf( "DROP TABLE IF EXISTS %s", $table ) );
286
+ }
287
+
288
+ }
289
+
290
+ $this->settings['_pre_1_0_clean_up'] = true;
291
+ $this->save_settings();
292
+ }
293
+
294
+ public function setup_plugins_action_links() {
295
+
296
+ $plugins = get_plugins();
297
+
298
+ $repositories_plugins = array();
299
+
300
+ if ( ! empty( $this->settings['repositories'] ) ) {
301
+
302
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
303
+
304
+ foreach ( $repository['data']['packages'] as $package ) {
305
+
306
+ foreach ( $package['products'] as $product ) {
307
+
308
+ foreach ( $product['plugins'] as $plugin_slug ) {
309
+
310
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
311
+
312
+ if ( ! isset( $repositories_plugins[ $repository_id ][ $download['slug'] ] ) ) {
313
+ $repositories_plugins[ $repository_id ][ $download['slug'] ] = array(
314
+ 'name' => $download['name'],
315
+ 'registered' => $this->plugin_is_registered( $repository_id, $download['slug'] ) ? 1 : 0
316
+ );
317
+ }
318
+
319
+ }
320
+
321
+ }
322
+
323
+ }
324
+
325
+ foreach ( $plugins as $plugin_id => $plugin ) {
326
+
327
+ $wp_plugin_slug = dirname( $plugin_id );
328
+ if ( empty( $wp_plugin_slug ) ) {
329
+ $wp_plugin_slug = basename( $plugin_id, '.php' );
330
+ }
331
+
332
+ foreach ( $repositories_plugins as $repository_id => $r_plugins ) {
333
+
334
+ foreach ( $r_plugins as $slug => $r_plugin ) {
335
+
336
+ if ( $wp_plugin_slug == $slug || $r_plugin['name'] == $plugin['Name'] || $r_plugin['name'] == $plugin['Title'] ) { //match order: slug, name, title
337
+
338
+ if ( $r_plugin['registered'] ) {
339
+ add_filter( 'plugin_action_links_' . $plugin_id, array(
340
+ $this,
341
+ 'plugins_action_links_registered'
342
+ ) );
343
+ } else {
344
+ add_filter( 'plugin_action_links_' . $plugin_id, array(
345
+ $this,
346
+ 'plugins_action_links_not_registered'
347
+ ) );
348
+ }
349
+
350
+ }
351
+
352
+ }
353
+
354
+ }
355
+
356
+
357
+ }
358
+
359
+ }
360
+ }
361
+
362
+ }
363
+
364
+ public function plugins_action_links_registered( $links ) {
365
+ $links[] = '<a href="' . $this->menu_url() . '">' . __( 'Registered', 'installer' ) . '</a>';
366
+
367
+ return $links;
368
+ }
369
+
370
+ public function plugins_action_links_not_registered( $links ) {
371
+ $links[] = '<a href="' . $this->menu_url() . '">' . __( 'Register', 'installer' ) . '</a>';
372
+
373
+ return $links;
374
+ }
375
+
376
+ public function plugin_is_registered( $repository_id, $slug ) {
377
+
378
+ $registered = false;
379
+
380
+ if ( $this->repository_has_valid_subscription( $repository_id ) ) {
381
+
382
+ $subscription_type = $this->get_subscription_type_for_repository( $repository_id );
383
+ $r_plugins = array();
384
+
385
+ foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package ) {
386
+
387
+ foreach ( $package['products'] as $product ) {
388
+
389
+ if ( $product['subscription_type'] == $subscription_type || $this->have_superior_subscription( $subscription_type, $product ) ) {
390
+
391
+ foreach ( $product['plugins'] as $plugin_slug ) {
392
+
393
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
394
+
395
+ if ( ! isset( $rep_plugins[ $download['slug'] ] ) ) {
396
+ $r_plugins[ $download['slug'] ] = $download['slug'];
397
+ }
398
+
399
+ }
400
+
401
+ }
402
+
403
+ }
404
+
405
+ }
406
+
407
+ $registered = isset( $r_plugins[ $slug ] );
408
+
409
+ }
410
+
411
+
412
+ return $registered;
413
+
414
+ }
415
+
416
+ public function version() {
417
+ return WP_INSTALLER_VERSION;
418
+ }
419
+
420
+ public function plugin_path() {
421
+ return untrailingslashit( plugin_dir_path( dirname( __FILE__ ) ) );
422
+ }
423
+
424
+ public function plugin_url() {
425
+ if ( isset( $this->config['in_theme_folder'] ) && ! empty( $this->config['in_theme_folder'] ) ) {
426
+ $url = untrailingslashit( get_template_directory_uri() . '/' . $this->config['in_theme_folder'] );
427
+ } else {
428
+ $url = untrailingslashit( plugins_url( '/', dirname( __FILE__ ) ) );
429
+ }
430
+
431
+ return $url;
432
+ }
433
+
434
+ public function is_repositories_page() {
435
+ global $pagenow;
436
+
437
+ return $pagenow == 'plugin-install.php' && isset( $_GET['tab'] ) && $_GET['tab'] == 'commercial';
438
+ }
439
+
440
+ public function res_url() {
441
+ if ( isset( $this->config['in_theme_folder'] ) && ! empty( $this->config['in_theme_folder'] ) ) {
442
+ $url = untrailingslashit( get_template_directory_uri() . '/' . $this->config['in_theme_folder'] );
443
+ } else {
444
+ $url = $this->plugin_url();
445
+ }
446
+
447
+ return $url;
448
+ }
449
+
450
+ public function save_settings() {
451
+
452
+ $_settings = serialize( $this->settings );
453
+ if ( $this->_gz_on ) {
454
+ $_settings = gzcompress( $_settings );
455
+ }
456
+ $_settings = base64_encode( $_settings );
457
+
458
+ update_option( 'wp_installer_settings', $_settings );
459
+
460
+ if ( is_multisite() && is_main_site() && isset( $this->settings['repositories'] ) ) {
461
+ $network_settings = array();
462
+
463
+ foreach ( $this->settings['repositories'] as $rep_id => $repository ) {
464
+ if ( isset( $repository['subscription'] ) ) {
465
+ $network_settings[ $rep_id ] = $repository['subscription'];
466
+ }
467
+ }
468
+
469
+ update_site_option( 'wp_installer_network', $network_settings );
470
+
471
+
472
+ }
473
+
474
+ }
475
+
476
+ public function get_settings( $refresh = false ) {
477
+
478
+ if ( $refresh || empty( $this->settings ) ) {
479
+
480
+ $_settings = get_option( 'wp_installer_settings' );
481
+
482
+
483
+ if ( is_array( $_settings ) || empty( $_settings ) ) { //backward compatibility 1.1
484
+ $this->settings = $_settings;
485
+
486
+ } else {
487
+ $_settings = base64_decode( $_settings );
488
+ if ( $this->_gz_on ) {
489
+ $_settings = gzuncompress( $_settings );
490
+ }
491
+ $this->settings = unserialize( $_settings );
492
+ }
493
+
494
+ // Initialize
495
+ if ( empty( $this->settings ) ) {
496
+ $this->settings = array(
497
+ 'repositories' => array()
498
+ );
499
+ }
500
+
501
+ if ( is_multisite() ) {
502
+ $network_settings = maybe_unserialize( get_site_option( 'wp_installer_network' ) );
503
+ if ( $network_settings ) {
504
+ foreach ( $this->settings['repositories'] as $rep_id => $repository ) {
505
+ if ( isset( $network_settings[ $rep_id ] ) ) {
506
+ $this->settings['repositories'][ $rep_id ]['subscription'] = $network_settings[ $rep_id ];
507
+ }
508
+ }
509
+ }
510
+ }
511
+
512
+ $this->load_hardcoded_site_keys();
513
+
514
+ $this->_pre_1_8_backwards_compatibility( $this->settings );
515
+
516
+ $this->settings = $this->_old_products_format_backwards_compatibility( $this->settings );
517
+
518
+ }
519
+
520
+ return $this->settings;
521
+ }
522
+
523
+ private function load_hardcoded_site_keys() {
524
+
525
+ if ( ! empty( $this->settings['repositories'] ) ) {
526
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
527
+
528
+ if ( $site_key = self::get_repository_hardcoded_site_key( $repository_id ) ) {
529
+
530
+ $site_key_missing = empty( $this->settings['repositories'][ $repository_id ]['subscription']['data'] );
531
+ $site_key_changed = ! $site_key_missing &&
532
+ $this->settings['repositories'][ $repository_id ]['subscription']['key'] != $site_key;
533
+
534
+ if ( $site_key_missing || $site_key_changed ) {
535
+
536
+ if ( ! function_exists( 'get_plugins' ) ) {
537
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
538
+ }
539
+ $this->load_repositories_list();
540
+ $response = $this->save_site_key(
541
+ array(
542
+ 'repository_id' => $repository_id,
543
+ 'site_key' => $site_key,
544
+ 'return' => true,
545
+ 'nonce' => wp_create_nonce( 'save_site_key_' . $repository_id )
546
+ )
547
+ );
548
+
549
+ if ( ! empty( $response['error'] ) ) {
550
+ $this->remove_site_key( $repository_id );
551
+
552
+ $this->admin_messages[] = array(
553
+ 'type' => 'error',
554
+ 'text' => sprintf( __( 'You are using an invalid site key defined as the constant %s (most likely in wp-config.php).
555
+ Please remove it or use the correct value in order to be able to register correctly.', 'installer' ), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id ) )
556
+ );
557
+
558
+ }
559
+
560
+ }
561
+
562
+ }
563
+
564
+ }
565
+ }
566
+
567
+ }
568
+
569
+ public static function get_repository_hardcoded_site_key( $repository_id ) {
570
+
571
+ $site_key = false;
572
+
573
+ $site_key_constant = 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id );
574
+ if ( defined( $site_key_constant ) ) {
575
+ $site_key = constant( $site_key_constant );
576
+ }
577
+
578
+ return $site_key;
579
+ }
580
+
581
+ //backward compatibility, add channel
582
+ private function _pre_1_8_backwards_compatibility( &$settings ) {
583
+ if ( empty( $settings['_pre_1_8_clean_up'] ) ) {
584
+ foreach ( $settings['repositories'] as $repository_id => $repository ) {
585
+ foreach ( $repository['data']['downloads']['plugins'] as $slug => $download ) {
586
+ if( !isset( $download['channel'] ) ){
587
+ $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $slug ]['channel'] = '';
588
+ }
589
+ }
590
+ }
591
+ $this->save_settings();
592
+ }
593
+ }
594
+
595
+ //backward compatibility - support old products list format (downloads under products instead of global downloads list)
596
+ private function _old_products_format_backwards_compatibility( $settings ) {
597
+
598
+ if ( version_compare( $this->version(), '1.8', '<' ) && ! empty( $settings['repositories'] ) && empty( $this->_old_products_format_backwards_compatibility ) ) {
599
+
600
+ foreach ( $settings['repositories'] as $repository_id => $repository ) {
601
+ $populate_downloads = false;
602
+ if ( isset( $repository['data'] ) ) {
603
+
604
+ foreach ( $repository['data']['packages'] as $package_id => $package ) {
605
+ foreach ( $package['products'] as $product_id => $product ) {
606
+ if ( ! isset( $product['plugins'] ) ) {
607
+ $populate_downloads = true;
608
+ foreach ( $product['downloads'] as $download_id => $download ) {
609
+ $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['plugins'][] = $download['slug'];
610
+ }
611
+ }
612
+ }
613
+ }
614
+
615
+ if ( $populate_downloads ) {
616
+ // Add downloads branch
617
+ foreach ( $repository['data']['packages'] as $package_id => $package ) {
618
+ foreach ( $package['products'] as $product_id => $product ) {
619
+ foreach ( $product['downloads'] as $download_id => $download ) {
620
+ if ( ! isset( $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $download['slug'] ] ) ) {
621
+ $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $download['slug'] ] = $download;
622
+ }
623
+ $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['plugins'][] = $download['slug'];
624
+ }
625
+ unset( $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['downloads'] );
626
+ }
627
+ }
628
+ }
629
+ }
630
+ }
631
+
632
+ $this->_old_products_format_backwards_compatibility = true;
633
+ }
634
+
635
+ return $settings;
636
+ }
637
+
638
+ public function get_installer_site_url( $repository_id = false ) {
639
+ global $current_site;
640
+
641
+ $site_url = get_site_url();
642
+
643
+ if ( $repository_id && is_multisite() && isset( $this->settings['repositories'] ) ) {
644
+ $network_settings = maybe_unserialize( get_site_option( 'wp_installer_network' ) );
645
+
646
+ if ( isset( $network_settings[ $repository_id ] ) ) {
647
+ $site_url = get_site_url( $current_site->blog_id );
648
+ }
649
+
650
+ }
651
+
652
+ return $site_url;
653
+ }
654
+
655
+ public function show_site_key_nags() {
656
+ $screen = get_current_screen();
657
+
658
+ if ( $screen->base == 'settings_page_installer' || ( $screen->base == 'plugin-install' && isset( $_GET['tab'] ) && $_GET['tab'] == 'commercial' ) ) {
659
+ return;
660
+ }
661
+
662
+ if ( ! empty( $this->config['site_key_nags'] ) ) {
663
+
664
+ foreach ( $this->config['site_key_nags'] as $nag ) {
665
+
666
+ if ( ! $this->repository_has_subscription( $nag['repository_id'] ) ) {
667
+ $show = true;
668
+ if ( ! empty( $nag['condition_cb'] ) ) {
669
+ $show = call_user_func( $nag['condition_cb'] );
670
+ }
671
+
672
+ if ( empty( $this->settings['dismissed_nags'][ $nag['repository_id'] ] ) && $show ) {
673
+ echo '<div class="updated error otgs-is-dismissible"><p>';
674
+ printf( __( "To get automatic updates, you need to register %s for this site. %sRegister %s%s", 'sitepress' ),
675
+ $nag['product_name'], '<a class="button-primary" href="' . $this->menu_url() . '">', $nag['product_name'], '</a>' );
676
+
677
+ echo '</p>';
678
+ echo '<span class="installer-dismiss-nag notice-dismiss" data-repository="' . $nag['repository_id'] . '"><span class="screen-reader-text">' . __( 'Dismiss', 'sitepress' ) . '</span></span>';
679
+ echo '</div>';
680
+ }
681
+ }
682
+
683
+ }
684
+
685
+ }
686
+
687
+ }
688
+
689
+ public function dismiss_nag() {
690
+ $this->settings['dismissed_nags'][ $_POST['repository'] ] = 1;
691
+
692
+ $this->save_settings();
693
+
694
+ echo json_encode( array() );
695
+ exit;
696
+ }
697
+
698
+ public function add_install_plugins_tab( $tabs ) {
699
+
700
+ $tabs['commercial'] = __( 'Commercial', 'installer' );
701
+
702
+ return $tabs;
703
+ }
704
+
705
+ public function load_repositories_list() {
706
+ global $wp_installer_instances;
707
+
708
+ foreach ( $wp_installer_instances as $instance ) {
709
+
710
+ if ( file_exists( dirname( $instance['bootfile'] ) . '/repositories.xml' ) ) {
711
+ $config_file = dirname( $instance['bootfile'] ) . '/repositories.xml';
712
+
713
+ if ( file_exists( dirname( $instance['bootfile'] ) . '/repositories.sandbox.xml' ) ) {
714
+ $config_file = dirname( $instance['bootfile'] ) . '/repositories.sandbox.xml';
715
+ add_filter( 'https_ssl_verify', '__return_false' );
716
+ }
717
+
718
+ $repos = simplexml_load_file( $config_file );
719
+
720
+ if ( $repos ) {
721
+ foreach ( $repos as $repo ) {
722
+ $id = strval( $repo->id );
723
+
724
+ $data['api-url'] = strval( $repo->apiurl );
725
+ $data['products'] = strval( $repo->products );
726
+
727
+ // excludes rule;
728
+ if ( isset( $this->config['repositories_exclude'] ) && in_array( $id, $this->config['repositories_exclude'] ) ) {
729
+ continue;
730
+ }
731
+
732
+ // includes rule;
733
+ if ( isset( $this->config['repositories_include'] ) && ! in_array( $id, $this->config['repositories_include'] ) ) {
734
+ continue;
735
+ }
736
+
737
+ $this->repositories[ $id ] = $data;
738
+
739
+ }
740
+ }
741
+
742
+ }
743
+ }
744
+
745
+ }
746
+
747
+ public function filter_repositories_list() {
748
+
749
+ if ( ! empty( $this->settings['repositories'] ) ) {
750
+ foreach ( $this->settings['repositories'] as $id => $repo_data ) {
751
+
752
+ // excludes rule;
753
+ if ( isset( $this->config['repositories_exclude'] ) && in_array( $id, $this->config['repositories_exclude'] ) ) {
754
+ unset( $this->settings['repositories'][ $id ] );
755
+ }
756
+
757
+ // includes rule;
758
+ if ( isset( $this->config['repositories_include'] ) && ! in_array( $id, $this->config['repositories_include'] ) ) {
759
+ unset( $this->settings['repositories'][ $id ] );
760
+ }
761
+
762
+
763
+ }
764
+ }
765
+
766
+
767
+ }
768
+
769
+ public function refresh_repositories_data() {
770
+ static $checked = false;
771
+
772
+ if ( defined( 'OTGS_DISABLE_AUTO_UPDATES' ) && OTGS_DISABLE_AUTO_UPDATES && empty( $_GET['force-check'] ) || $checked ) {
773
+
774
+ if ( empty( $this->settings['repositories'] ) && $this->is_repositories_page() ) {
775
+
776
+ foreach ( $this->repositories as $id => $data ) {
777
+ $repository_names[] = $id;
778
+
779
+ }
780
+
781
+ $error = sprintf( __( "Installer cannot display the products information because the automatic updating for %s was explicitly disabled with the configuration below (usually in wp-config.php):", 'installer' ), strtoupper( join( ', ', $repository_names ) ) );
782
+ $error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code><br /><br />';
783
+ $error .= sprintf( __( "In order to see the products information, please run the %smanual updates check%s to initialize the products list or (temporarily) remove the above code.", 'installer' ), '<a href="' . admin_url( 'update-core.php' ) . '">', '</a>' );
784
+
785
+ $this->register_admin_message( $error, 'error' );
786
+
787
+
788
+ }
789
+
790
+ return;
791
+ }
792
+
793
+ $checked = true;
794
+
795
+ foreach ( $this->repositories as $id => $data ) {
796
+
797
+ $response = wp_remote_get( $data['products'] );
798
+
799
+ if ( is_wp_error( $response ) ) {
800
+ // http fallback
801
+ $data['products'] = preg_replace( "@^https://@", 'http://', $data['products'] );
802
+ $response = wp_remote_get( $data['products'] );
803
+ }
804
+
805
+ if ( is_wp_error( $response ) ) {
806
+
807
+ $error = sprintf( __( "Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:", 'installer' ), strtoupper( $id ) );
808
+ $error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code>';
809
+
810
+ $this->register_admin_message( $error, 'error' );
811
+
812
+ continue;
813
+ }
814
+
815
+ if ( $response && isset( $response['response']['code'] ) && $response['response']['code'] == 200 ) {
816
+ $body = wp_remote_retrieve_body( $response );
817
+ if ( $body ) {
818
+ $products = json_decode( $body, true );
819
+
820
+ if ( is_array( $products ) ) {
821
+ $products['downloads'] = WP_Installer_Channels()->filter_downloads_by_channel( $id, $products['downloads'] );
822
+ $this->set_release_notes( $products['downloads'] );
823
+
824
+ $this->settings['repositories'][ $id ]['data'] = $products;
825
+ $this->_pre_1_8_backwards_compatibility( $this->settings );
826
+ }
827
+ }
828
+
829
+ }
830
+
831
+ $this->log( sprintf( "Checked for %s updates: %s", $id, $data['products'] ) );
832
+
833
+
834
+ }
835
+
836
+ // cleanup
837
+ if ( empty( $this->settings['repositories'] ) ) {
838
+ $this->settings['repositories'] = array();
839
+ }
840
+ foreach ( $this->settings['repositories'] as $id => $data ) {
841
+ if ( ! in_array( $id, array_keys( $this->repositories ) ) ) {
842
+ unset( $this->settings['repositories'][ $id ] );
843
+ }
844
+ }
845
+
846
+ $this->settings['last_repositories_update'] = time();
847
+
848
+ $this->save_settings();
849
+
850
+ }
851
+
852
+ /**
853
+ * Gets the release notes for the available version from the changelog
854
+ *
855
+ * @param array $all_downloads
856
+ */
857
+ private function set_release_notes( &$all_downloads ) {
858
+ foreach ( $all_downloads as $kind => $downloads ) {
859
+ foreach ( $downloads as $slug => $download ) {
860
+ $start = strpos( $download['changelog'], '<h4>' . $download['version'] . '</h4>' );
861
+ if ( $start !== false ) {
862
+ $start += strlen( $download['version'] ) + 9;
863
+ $end = strpos( $download['changelog'], '<h4>', 4 );
864
+ if ( $end ) {
865
+ $release_notes = substr( $download['changelog'], $start, $end - $start );
866
+ } else {
867
+ $release_notes = substr( $download['changelog'], $start );
868
+ }
869
+ }
870
+ $all_downloads[ $kind ][ $slug ]['release-notes'] = ! empty( $release_notes ) ? $release_notes : '';
871
+ }
872
+ }
873
+ }
874
+
875
+ public function show_products( $args = array() ) {
876
+
877
+ $screen = get_current_screen();
878
+
879
+ if ( $screen->base == 'settings_page_installer' ) { // settings page
880
+ echo '<div class="wrap">';
881
+ echo '<h2>' . __( 'Installer', 'installer' ) . '</h2>';
882
+ echo '<br />';
883
+ }
884
+
885
+ if ( ! is_array( $args ) ) {
886
+ $args = array();
887
+ }
888
+ if ( empty( $args['template'] ) ) {
889
+ $args['template'] = 'default';
890
+ }
891
+
892
+ $this->filter_repositories_list();
893
+
894
+ if ( ! empty( $this->settings['repositories'] ) ) {
895
+
896
+ $this->localize_strings();
897
+ $this->set_filtered_prices( $args );
898
+ $this->set_hierarchy_and_order();
899
+
900
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
901
+
902
+ if ( $args['template'] == 'compact' ) {
903
+
904
+ if ( isset( $args['repository'] ) && $args['repository'] == $repository_id ) {
905
+ include $this->plugin_path() . '/templates/products-compact.php';
906
+ }
907
+
908
+ } else {
909
+
910
+ include $this->plugin_path() . '/templates/repository-listing.php';
911
+
912
+ }
913
+
914
+ unset( $site_key, $subscription_type, $expired, $upgrade_options, $products_avaliable );
915
+
916
+ }
917
+
918
+ } else {
919
+
920
+ echo '<center>' . __( 'No repositories defined.', 'installer' ) . '</center>';
921
+
922
+ }
923
+
924
+ if ( $screen->base == 'settings_page_installer' ) { // settings page
925
+ echo '</div>';
926
+ }
927
+
928
+
929
+ }
930
+
931
+ public function get_product_price( $repository_id, $package_id, $product_id, $incl_discount = false ) {
932
+
933
+ $price = false;
934
+
935
+ foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package ) {
936
+
937
+ if ( $package['id'] == $package_id ) {
938
+ if ( isset( $package['products'][ $product_id ] ) ) {
939
+ if ( $incl_discount && isset( $package['products'][ $product_id ]['price_disc'] ) ) {
940
+ $price = $package['products'][ $product_id ]['price_disc'];
941
+ } elseif ( isset( $package['products'][ $product_id ]['price'] ) ) {
942
+ $price = $package['products'][ $product_id ]['price'];
943
+ }
944
+ }
945
+ break;
946
+ }
947
+ }
948
+
949
+ return $price;
950
+ }
951
+
952
+ private function _render_product_packages( $packages, $subscription_type, $expired, $upgrade_options, $repository_id ) {
953
+
954
+ $data = array();
955
+
956
+ foreach ( $packages as $package_id => $package ) {
957
+
958
+ $row = array( 'products' => array(), 'downloads' => array() );
959
+ foreach ( $package['products'] as $product ) {
960
+
961
+ // filter out free subscriptions from being displayed as buying options
962
+ if ( empty( $product['price'] ) && ( empty( $subscription_type ) || $expired ) ) {
963
+ continue;
964
+ }
965
+
966
+ //consider equivalent subscriptions
967
+ if ( empty( $product['subscription_type_equivalent'] ) ) {
968
+ $product['subscription_type_equivalent'] = '';
969
+ }
970
+
971
+ // buy base
972
+ if ( empty( $subscription_type ) || $expired ) {
973
+
974
+ $p['url'] = $this->append_parameters_to_buy_url( $product['url'], $repository_id );
975
+ if ( ! empty( $product['price_disc'] ) ) {
976
+ $p['label'] = $product['call2action'] . ' - ' . sprintf( '$%s %s$%d%s (USD)', $product['price_disc'], '&nbsp;&nbsp;<del>', $product['price'], '</del>' );
977
+ } else {
978
+ $p['label'] = $product['call2action'] . ' - ' . sprintf( '$%d (USD)', $product['price'] );
979
+ }
980
+ $row['products'][] = $p;
981
+
982
+ // renew
983
+ } elseif ( isset( $subscription_type ) && ( $product['subscription_type'] == $subscription_type || $product['subscription_type_equivalent'] == $subscription_type ) ) {
984
+
985
+ if ( $product['renewals'] ) {
986
+ foreach ( $product['renewals'] as $renewal ) {
987
+ $p['url'] = $this->append_parameters_to_buy_url( $renewal['url'], $repository_id );
988
+ $p['label'] = $renewal['call2action'] . ' - ' . sprintf( '$%d (USD)', $renewal['price'] );
989
+ }
990
+
991
+ $row['products'][] = $p;
992
+ }
993
+
994
+ }
995
+
996
+ // upgrades
997
+ if ( ! empty( $upgrade_options[ $product['subscription_type'] ] ) ) {
998
+
999
+ foreach ( $upgrade_options[ $product['subscription_type'] ] as $stype => $upgrade ) {
1000
+ if ( $stype != $subscription_type ) {
1001
+ continue;
1002
+ }
1003
+
1004
+ $p['url'] = $this->append_parameters_to_buy_url( $upgrade['url'], $repository_id );
1005
+ if ( ! empty( $upgrade['price_disc'] ) ) {
1006
+ $p['label'] = $upgrade['call2action'] . ' - ' . sprintf( '$%s %s$%d%s (USD)', $upgrade['price_disc'], '&nbsp;&nbsp;<del>', $upgrade['price'], '</del>' );
1007
+ } else {
1008
+ $p['label'] = $upgrade['call2action'] . ' - ' . sprintf( '$%d (USD)', $upgrade['price'] );
1009
+ }
1010
+ $row['products'][] = $p;
1011
+
1012
+ }
1013
+
1014
+ }
1015
+
1016
+ // downloads
1017
+ if ( isset( $subscription_type ) && ! $expired && ( $product['subscription_type'] == $subscription_type || $product['subscription_type_equivalent'] == $subscription_type ) ) {
1018
+
1019
+ foreach ( $product['plugins'] as $plugin_slug ) {
1020
+ $row['downloads'][ $plugin_slug ] = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
1021
+ }
1022
+
1023
+ }
1024
+
1025
+ //subpackages
1026
+ if ( ! empty( $package['sub-packages'] ) ) {
1027
+ $row['sub-packages'] = $package['sub-packages'];
1028
+ }
1029
+
1030
+ }
1031
+
1032
+ $row['id'] = $package['id'];
1033
+ $row['image_url'] = $package['image_url'];
1034
+ $row['name'] = $package['name'];
1035
+ $row['description'] = $package['description'];
1036
+
1037
+ if ( ! empty( $row['products'] ) || ! empty( $row['downloads'] ) || ! empty( $row['sub-packages'] ) ) {
1038
+ $data[] = $row;
1039
+ }
1040
+
1041
+
1042
+ }
1043
+
1044
+ return $data;
1045
+
1046
+ }
1047
+
1048
+ public function get_extra_url_parameters() {
1049
+
1050
+ $parameters = array();
1051
+
1052
+ if ( ! empty( $this->package_source ) ) {
1053
+ foreach ( $this->package_source as $key => $val ) {
1054
+ $parameters[ $key ] = $val;
1055
+ }
1056
+ }
1057
+
1058
+ $parameters['installer_version'] = WP_INSTALLER_VERSION;
1059
+ $parameters['theme'] = wp_get_theme()->get( 'Name' );
1060
+ $parameters['site_name'] = get_bloginfo( 'name' );
1061
+
1062
+ return $parameters;
1063
+ }
1064
+
1065
+ public function append_parameters_to_buy_url( $url, $repository_id, $args = array() ) {
1066
+
1067
+ $url = add_query_arg( array( 'icl_site_url' => $this->get_installer_site_url( $repository_id ) ), $url );
1068
+
1069
+ $affiliate_id = false;
1070
+ $affiliate_key = false;
1071
+
1072
+ // Add extra parameters for custom Installer packages
1073
+ if ( ! empty( $this->package_source ) ) {
1074
+ $extra = $this->get_extra_url_parameters();
1075
+
1076
+ if ( ! empty( $extra['repository'] ) && $extra['repository'] == $repository_id ) {
1077
+
1078
+ if ( ! empty( $extra['affiliate_key'] ) && ! empty( $extra['user_id'] ) ) {
1079
+ $this->config[ 'affiliate_id:' . $repository_id ] = $extra['user_id'];
1080
+ $this->config[ 'affiliate_key:' . $repository_id ] = $extra['affiliate_key'];
1081
+ unset( $extra['affiliate_key'], $extra['user_id'], $extra['repository'] ); // no need to include these ones
1082
+ }
1083
+
1084
+ $url = add_query_arg( $extra, $url );
1085
+ }
1086
+
1087
+ }
1088
+
1089
+ if ( isset( $this->config[ 'affiliate_id:' . $repository_id ] ) && isset( $this->config[ 'affiliate_key:' . $repository_id ] ) ) {
1090
+
1091
+ $affiliate_id = $this->config[ 'affiliate_id:' . $repository_id ];
1092
+ $affiliate_key = $this->config[ 'affiliate_key:' . $repository_id ];
1093
+
1094
+ } elseif ( isset( $args[ 'affiliate_id:' . $repository_id ] ) && isset( $args[ 'affiliate_key:' . $repository_id ] ) ) {
1095
+
1096
+ $affiliate_id = $args[ 'affiliate_id:' . $repository_id ];
1097
+ $affiliate_key = $args[ 'affiliate_key:' . $repository_id ];
1098
+
1099
+ } elseif ( defined( 'ICL_AFFILIATE_ID' ) && defined( 'ICL_AFFILIATE_KEY' ) ) { //support for 1 repo
1100
+
1101
+ $affiliate_id = ICL_AFFILIATE_ID;
1102
+ $affiliate_key = ICL_AFFILIATE_KEY;
1103
+
1104
+ } elseif ( isset( $this->config['affiliate_id'] ) && isset( $this->config['affiliate_key'] ) ) {
1105
+ // BACKWARDS COMPATIBILITY
1106
+ $affiliate_id = $this->config['affiliate_id'];
1107
+ $affiliate_key = $this->config['affiliate_key'];
1108
+ }
1109
+
1110
+ if ( $affiliate_id && $affiliate_key ) {
1111
+ $url = add_query_arg( array( 'aid' => $affiliate_id, 'affiliate_key' => $affiliate_key ), $url );
1112
+ }
1113
+
1114
+ if ( $repository_id == 'wpml' ) {
1115
+ $url = add_query_arg( array(
1116
+ 'using_icl' => $this->_using_icl,
1117
+ 'wpml_version' => $this->_wpml_version
1118
+ ), $url );
1119
+ }
1120
+
1121
+ $url = apply_filters( 'wp_installer_buy_url', $url );
1122
+
1123
+ $url = esc_url( $url );
1124
+
1125
+ return $url;
1126
+
1127
+ }
1128
+
1129
+ public function save_site_key( $args = array() ) {
1130
+
1131
+ $error = '';
1132
+
1133
+ if ( isset( $args['repository_id'] ) ) {
1134
+ $repository_id = $args['repository_id'];
1135
+ } elseif ( isset( $_POST['repository_id'] ) ) {
1136
+ $repository_id = sanitize_text_field( $_POST['repository_id'] );
1137
+ } else {
1138
+ $repository_id = false;
1139
+ }
1140
+
1141
+ if ( isset( $args['nonce'] ) ) {
1142
+ $nonce = $args['nonce'];
1143
+ } elseif ( isset( $_POST['nonce'] ) ) {
1144
+ $nonce = sanitize_text_field( $_POST['nonce'] );
1145
+ } else {
1146
+ $nonce = '';
1147
+ }
1148
+
1149
+ if ( isset( $args['site_key'] ) ) {
1150
+ $site_key = $args['site_key'];
1151
+ } else {
1152
+ $site_key = sanitize_text_field( $_POST[ 'site_key_' . $repository_id ] );
1153
+ }
1154
+ $site_key = preg_replace( "/[^A-Za-z0-9]/", '', $site_key );
1155
+
1156
+ if ( $repository_id && $nonce && wp_create_nonce( 'save_site_key_' . $repository_id ) == $nonce ) {
1157
+
1158
+ try {
1159
+ $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REGISTRATION );
1160
+
1161
+ if ( $subscription_data ) {
1162
+ $this->settings['repositories'][ $repository_id ]['subscription'] = array(
1163
+ 'key' => $site_key,
1164
+ 'data' => $subscription_data,
1165
+ 'registered_by' => get_current_user_id()
1166
+ );
1167
+ $this->save_settings();
1168
+ } else {
1169
+ $error = __( 'Invalid site key for the current site.', 'installer' )
1170
+ . '<br /><div class="installer-footnote">' . __( 'Please note that the site key is case sensitive.', 'installer' ) . '</div>';
1171
+ }
1172
+
1173
+ } catch ( Exception $e ) {
1174
+ $error = $e->getMessage();
1175
+ if ( preg_match( '#Could not resolve host: (.*)#', $error, $matches ) || preg_match( '#Couldn\'t resolve host \'(.*)\'#', $error, $matches ) ) {
1176
+ $error = sprintf( __( "%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer' ),
1177
+ '<strong><i>' . $this->get_generic_product_name( $repository_id ) . '</i></strong>',
1178
+ '<strong><i>' . $matches[1] . '</i></strong>'
1179
+ );
1180
+ }
1181
+ }
1182
+
1183
+ }
1184
+
1185
+ $return = array( 'error' => $error );
1186
+
1187
+ if ( $this->api_debug ) {
1188
+ $return['debug'] = $this->api_debug;
1189
+ }
1190
+
1191
+ if ( ! empty( $args['return'] ) ) {
1192
+ return $return;
1193
+ } else {
1194
+ echo json_encode( $return );
1195
+ exit;
1196
+ }
1197
+
1198
+ }
1199
+
1200
+ /**
1201
+ * Alias for WP_Installer::get_repository_site_key
1202
+ * @see WP_Installer::get_repository_site_key()
1203
+ *
1204
+ * @param string $repository_id
1205
+ *
1206
+ * @return string (site key) or bool
1207
+ */
1208
+ public function get_site_key( $repository_id ) {
1209
+ return WP_Installer::get_repository_site_key( $repository_id );
1210
+ }
1211
+
1212
+ public function remove_site_key( $repository_id ) {
1213
+ if ( isset( $this->settings['repositories'][ $repository_id ] ) ) {
1214
+ unset( $this->settings['repositories'][ $repository_id ]['subscription'] );
1215
+ $this->save_settings();
1216
+ $this->refresh_repositories_data();
1217
+ }
1218
+ }
1219
+
1220
+ public function remove_site_key_ajax() {
1221
+ if ( $_POST['nonce'] == wp_create_nonce( 'remove_site_key_' . $_POST['repository_id'] ) ) {
1222
+ $this->remove_site_key( $_POST['repository_id'] );
1223
+ }
1224
+ exit;
1225
+ }
1226
+
1227
+ public function validate_repository_subscription() {
1228
+ $repository_id = isset( $_GET['validate_repository'] ) ? sanitize_text_field( $_GET['validate_repository'] ) : false;
1229
+ if ( $repository_id ) {
1230
+
1231
+ $site_key = $this->get_site_key( $repository_id );
1232
+ if ( $site_key ) {
1233
+ $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
1234
+ if ( empty( $subscription_data ) ) {
1235
+ unset( $this->settings['repositories'][ $repository_id ]['subscription'] );
1236
+ delete_site_transient( 'update_plugins' );
1237
+ $this->save_settings();
1238
+ }
1239
+ }
1240
+
1241
+ wp_redirect( $this->menu_url() . '#repository-' . $repository_id );
1242
+ exit;
1243
+
1244
+ }
1245
+
1246
+ }
1247
+
1248
+ public function update_site_key() {
1249
+
1250
+ $error = '';
1251
+
1252
+ $repository_id = sanitize_text_field( $_POST['repository_id'] );
1253
+ if ( $_POST['nonce'] == wp_create_nonce( 'update_site_key_' . $repository_id ) ) {
1254
+
1255
+ $site_key = $this->get_site_key( $_POST['repository_id'] );
1256
+
1257
+ if ( $site_key ) {
1258
+ try {
1259
+ $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK );
1260
+
1261
+ if ( $subscription_data ) {
1262
+ $this->settings['repositories'][ $repository_id ]['subscription'] = array(
1263
+ 'key' => $site_key,
1264
+ 'data' => $subscription_data,
1265
+ 'registered_by' => get_current_user_id()
1266
+ );
1267
+
1268
+ //also refresh products information
1269
+ $this->refresh_repositories_data();
1270
+
1271
+ $this->save_settings();
1272
+
1273
+ } else {
1274
+ unset( $this->settings['repositories'][ $repository_id ]['subscription'] );
1275
+ $error = __( 'Invalid site key for the current site. If the error persists, try to unregister first and then register again with the same site key.', 'installer' );
1276
+ }
1277
+
1278
+
1279
+ } catch ( Exception $e ) {
1280
+ $error = $e->getMessage();
1281
+ if ( preg_match( '#Could not resolve host: (.*)#', $error, $matches ) || preg_match( '#Couldn\'t resolve host \'(.*)\'#', $error, $matches ) ) {
1282
+ $error = sprintf( __( "%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer' ),
1283
+ '<strong><i>' . $this->get_generic_product_name( $repository_id ) . '</i></strong>',
1284
+ '<strong><i>' . $matches[1] . '</i></strong>'
1285
+ );
1286
+ }
1287
+ }
1288
+
1289
+ }
1290
+
1291
+ }
1292
+
1293
+ echo json_encode( array( 'error' => $error ) );
1294
+
1295
+ exit;
1296
+ }
1297
+
1298
+ public function api_debug_log( $text ) {
1299
+
1300
+ if ( defined( 'WPML_DEBUG_INSTALLER' ) && WPML_DEBUG_INSTALLER ) {
1301
+
1302
+ if ( ! is_scalar( $text ) ) {
1303
+ $text = print_r( $text, 1 );
1304
+ }
1305
+
1306
+ $this->api_debug .= $text . "\n";
1307
+
1308
+ }
1309
+
1310
+ }
1311
+
1312
+ public function fetch_subscription_data( $repository_id, $site_key, $source = self::SITE_KEY_VALIDATION_SOURCE_OTHER ) {
1313
+
1314
+ $subscription_data = false;
1315
+
1316
+ $args['body'] = array(
1317
+ 'action' => 'site_key_validation',
1318
+ 'site_key' => $site_key,
1319
+ 'site_url' => $this->get_installer_site_url( $repository_id ),
1320
+ 'source' => $source
1321
+ );
1322
+
1323
+ if ( $repository_id == 'wpml' ) {
1324
+ $args['body']['using_icl'] = $this->_using_icl;
1325
+ $args['body']['wpml_version'] = $this->_wpml_version;
1326
+ }
1327
+
1328
+ $args['body']['installer_version'] = WP_INSTALLER_VERSION;
1329
+ $args['body']['theme'] = wp_get_theme()->get( 'Name' );
1330
+ $args['body']['site_name'] = get_bloginfo( 'name' );
1331
+
1332
+ $args['body']['versions'] = $this->get_local_product_versions( $repository_id );
1333
+
1334
+ $args['timeout'] = 45;
1335
+
1336
+ // Add extra parameters for custom Installer packages
1337
+ if ( ! empty( $this->package_source ) ) {
1338
+ $extra = $this->get_extra_url_parameters();
1339
+ if ( ! empty( $extra['repository'] ) && $extra['repository'] == $repository_id ) {
1340
+ unset( $extra['repository'] );
1341
+ foreach ( $extra as $key => $val ) {
1342
+ $args['body'][ $key ] = $val;
1343
+ }
1344
+ }
1345
+ }
1346
+
1347
+ $response = wp_remote_post( $this->repositories[ $repository_id ]['api-url'], $args );
1348
+
1349
+ $this->api_debug_log( "POST {$this->repositories[$repository_id]['api-url']}" );
1350
+ $this->api_debug_log( $args );
1351
+
1352
+ $this->log( "POST {$this->repositories[$repository_id]['api-url']} - fetch subscription data" );
1353
+
1354
+ if ( ! is_wp_error( $response ) ) {
1355
+ $datas = wp_remote_retrieve_body( $response );
1356
+
1357
+ if ( is_serialized( $datas ) ) {
1358
+ $data = unserialize( $datas );
1359
+ $this->api_debug_log( $data );
1360
+
1361
+ if ( ! empty( $data->subscription_data ) ) {
1362
+ $subscription_data = $data->subscription_data;
1363
+ }
1364
+
1365
+ do_action( 'installer_fetched_subscription_data', $data, $repository_id );
1366
+
1367
+ } else {
1368
+ $this->api_debug_log( $datas );
1369
+ }
1370
+
1371
+ } else {
1372
+
1373
+ $this->api_debug_log( $response );
1374
+ throw new Exception( $response->get_error_message() );
1375
+ }
1376
+
1377
+ return $subscription_data;
1378
+
1379
+ }
1380
+
1381
+ function get_local_product_versions( $repository_id ) {
1382
+
1383
+ $versions = array();
1384
+
1385
+ foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package_id => $package ) {
1386
+
1387
+ foreach ( $package['products'] as $product_id => $product ) {
1388
+
1389
+ foreach ( $product['plugins'] as $plugin_slug ) {
1390
+
1391
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
1392
+
1393
+ if ( empty( $versions[ $download['slug'] ] ) ) {
1394
+ $v = $this->get_plugin_installed_version( $download['name'], $download['slug'] );
1395
+ if ( $v ) {
1396
+ $versions[ $download['slug'] ] = $v;
1397
+ }
1398
+ }
1399
+
1400
+ }
1401
+
1402
+ }
1403
+
1404
+ }
1405
+
1406
+ return $versions;
1407
+ }
1408
+
1409
+ public function get_repository_site_key( $repository_id ) {
1410
+ $site_key = false;
1411
+
1412
+ if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription']['key'] ) ) {
1413
+ $site_key = $this->settings['repositories'][ $repository_id ]['subscription']['key'];
1414
+ }
1415
+
1416
+ return $site_key;
1417
+ }
1418
+
1419
+ public function repository_has_valid_subscription( $repository_id ) {
1420
+
1421
+ $valid = false;
1422
+
1423
+ if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription'] ) ) {
1424
+
1425
+ $subscription = $this->settings['repositories'][ $repository_id ]['subscription']['data'];
1426
+ $valid = ( $subscription->status == 1 && ( strtotime( $subscription->expires ) > time() || empty( $subscription->expires ) ) ) || $subscription->status == 4;
1427
+
1428
+ }
1429
+
1430
+ return $valid;
1431
+
1432
+ }
1433
+
1434
+ public function repository_has_subscription( $repository_id ) {
1435
+ $key = false;
1436
+ if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription']['key'] ) ) {
1437
+ $key = $this->settings['repositories'][ $repository_id ]['subscription']['key'];
1438
+ }
1439
+
1440
+ return $key;
1441
+
1442
+ }
1443
+
1444
+ public function repository_has_expired_subscription( $repository_id ) {
1445
+
1446
+ return $this->repository_has_subscription( $repository_id ) && ! $this->repository_has_valid_subscription( $repository_id );
1447
+
1448
+ }
1449
+
1450
+ public function get_generic_product_name( $repository_id ) {
1451
+
1452
+ return $this->settings['repositories'][ $repository_id ]['data']['product-name'];
1453
+
1454
+ }
1455
+
1456
+ public function show_subscription_renew_warning( $repository_id, $subscription_id ) {
1457
+
1458
+ $show = false;
1459
+
1460
+ $data = $this->settings['repositories'][ $repository_id ]['data'];
1461
+ if ( ! empty( $data['subscriptions_meta'] ) ) {
1462
+ if ( isset( $data['subscriptions_meta']['expiration'] ) ) {
1463
+
1464
+ if ( ! empty( $data['subscriptions_meta']['expiration'][ $subscription_id ] ) ) {
1465
+
1466
+ $days = $data['subscriptions_meta']['expiration'][ $subscription_id ]['days_warning'];
1467
+ $message = $data['subscriptions_meta']['expiration'][ $subscription_id ]['warning_message'];
1468
+
1469
+ } else {
1470
+
1471
+ //defaults
1472
+ $days = 30;
1473
+ $message = __( 'You will have to renew your subscription in order to continue getting the updates and support.', 'installer' );
1474
+
1475
+ }
1476
+
1477
+ if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription'] ) ) {
1478
+ $subscription = $this->settings['repositories'][ $repository_id ]['subscription'];
1479
+
1480
+ if ( $subscription['data']->subscription_type == $subscription_id && ! empty( $subscription['data']->expires ) ) {
1481
+
1482
+ if ( strtotime( $subscription['data']->expires ) < strtotime( sprintf( "+%d day", $days ) ) ) {
1483
+
1484
+ $days_to_expiration = ceil( ( strtotime( $subscription['data']->expires ) - time() ) / 86400 );
1485
+
1486
+ echo '<div><p class="installer-warn-box">' .
1487
+ sprintf( _n( 'Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer' ), $days_to_expiration ) .
1488
+ '<br />' . $message .
1489
+ '</p></div>';
1490
+
1491
+ $show = true;
1492
+
1493
+ }
1494
+
1495
+ }
1496
+
1497
+ }
1498
+
1499
+
1500
+ }
1501
+ }
1502
+
1503
+
1504
+ return $show;
1505
+
1506
+ }
1507
+
1508
+ public function setup_plugins_renew_warnings() {
1509
+
1510
+ $plugins = get_plugins();
1511
+
1512
+ $subscriptions_with_warnings = array();
1513
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
1514
+
1515
+ if ( $this->repository_has_valid_subscription( $repository_id ) ) {
1516
+ $subscription_type = $this->settings['repositories'][ $repository_id ]['subscription']['data']->subscription_type;
1517
+ $expires = $this->settings['repositories'][ $repository_id ]['subscription']['data']->expires;
1518
+
1519
+ $never_expires = isset( $this->settings['repositories'][ $repository_id ]['subscription'] )
1520
+ && empty( $this->settings['repositories'][ $repository_id ]['subscription']['data']->expires )
1521
+ && (
1522
+ $this->settings['repositories'][ $repository_id ]['subscription']['data']->status == 4 ||
1523
+ $this->settings['repositories'][ $repository_id ]['subscription']['data']->status == 1
1524
+ );
1525
+
1526
+ if ( ! $never_expires ) {
1527
+ if ( isset( $this->settings['repositories'][ $repository_id ]['data']['subscriptions_meta']['expiration'][ $subscription_type ] ) ) {
1528
+
1529
+ $days_warning = $this->settings['repositories'][ $repository_id ]['data']['subscriptions_meta']['expiration'][ $subscription_type ]['days_warning'];
1530
+ $custom_message = $this->settings['repositories'][ $repository_id ]['data']['subscriptions_meta']['expiration'][ $subscription_type ]['warning_message'];
1531
+
1532
+ } else {
1533
+ //defaults
1534
+ $days_warning = 30;
1535
+ $custom_message = __( 'You will have to renew your subscription in order to continue getting the updates and support.', 'installer' );
1536
+ }
1537
+
1538
+ if ( strtotime( $expires ) < strtotime( sprintf( '+%d day', $days_warning ) ) ) {
1539
+
1540
+ $days_to_expiration = ceil( ( strtotime( $expires ) - time() ) / 86400 );
1541
+
1542
+ $message = sprintf( _n( 'Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer' ), $days_to_expiration );
1543
+ $subscriptions_with_warnings[ $subscription_type ] = $message . ' ' . $custom_message;
1544
+
1545
+ }
1546
+ }
1547
+
1548
+ }
1549
+
1550
+ }
1551
+
1552
+
1553
+ foreach ( $plugins as $plugin_id => $plugin ) {
1554
+
1555
+ $slug = dirname( $plugin_id );
1556
+ if ( empty( $slug ) ) {
1557
+ continue;
1558
+ }
1559
+
1560
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
1561
+
1562
+ if ( $this->repository_has_valid_subscription( $repository_id ) ) {
1563
+
1564
+ foreach ( $repository['data']['packages'] as $package ) {
1565
+
1566
+ foreach ( $package['products'] as $product ) {
1567
+
1568
+ foreach ( $product['plugins'] as $plugin_slug ) {
1569
+
1570
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
1571
+
1572
+ if ( $download['slug'] == $slug || $download['name'] == $plugin['Name'] || $download['name'] == $plugin['Title'] ) { //match order: slug, name, title
1573
+
1574
+ if ( isset( $subscriptions_with_warnings[ $product['subscription_type'] ] ) ) {
1575
+
1576
+ $this->_plugins_renew_warnings[ $plugin_id ] = $subscriptions_with_warnings[ $product['subscription_type'] ];
1577
+
1578
+ }
1579
+
1580
+ }
1581
+
1582
+ }
1583
+
1584
+ }
1585
+
1586
+ }
1587
+
1588
+ }
1589
+
1590
+ }
1591
+
1592
+ }
1593
+
1594
+ }
1595
+
1596
+ public function queue_plugins_renew_warnings() {
1597
+
1598
+ if ( ! empty( $this->_plugins_renew_warnings ) ) {
1599
+
1600
+ foreach ( $this->_plugins_renew_warnings as $plugin_id => $message ) {
1601
+
1602
+ add_action( "after_plugin_row_" . $plugin_id, array( $this, 'plugins_renew_warning' ), 10, 3 );
1603
+ }
1604
+
1605
+ }
1606
+
1607
+ }
1608
+
1609
+ public function plugins_renew_warning( $plugin_file, $plugin_data, $status ) {
1610
+
1611
+ if ( empty( $this->_plugins_renew_warnings[ $plugin_file ] ) ) {
1612
+ return;
1613
+ }
1614
+
1615
+ $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1616
+ ?>
1617
+
1618
+ <tr class="plugin-update-tr">
1619
+ <td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
1620
+ <div class="update-message">
1621
+ <?php
1622
+ echo $this->_plugins_renew_warnings[ $plugin_file ] . ' ';
1623
+ printf( __( '%sRenew here%s.', 'installer' ),
1624
+ '<a href="' . $this->menu_url() . '">', '</a>' );
1625
+ ?>
1626
+ </div>
1627
+ </tr>
1628
+
1629
+ <?php
1630
+
1631
+ }
1632
+
1633
+ public function get_subscription_type_for_repository( $repository_id ) {
1634
+
1635
+ $subscription_type = false;
1636
+
1637
+ if ( ! empty( $this->settings['repositories'][ $repository_id ]['subscription'] ) ) {
1638
+ $subscription_type = $this->settings['repositories'][ $repository_id ]['subscription']['data']->subscription_type;
1639
+ }
1640
+
1641
+ return $subscription_type;
1642
+
1643
+ }
1644
+
1645
+ public function have_superior_subscription( $subscription_type, $product ) {
1646
+
1647
+ $have = false;
1648
+
1649
+ if ( is_array( $product['upgrades'] ) ) {
1650
+ foreach ( $product['upgrades'] as $u ) {
1651
+ if ( $u['subscription_type'] == $subscription_type ) {
1652
+ $have = true;
1653
+ break;
1654
+ }
1655
+ }
1656
+ }
1657
+
1658
+ return $have;
1659
+ }
1660
+
1661
+ public function is_product_available_for_download( $product_name, $repository_id ) {
1662
+
1663
+ $available = false;
1664
+
1665
+ $subscription_type = $this->get_subscription_type_for_repository( $repository_id );
1666
+ $expired = $this->repository_has_expired_subscription( $repository_id );
1667
+
1668
+ if ( $this->repository_has_subscription( $repository_id ) && ! $expired ) {
1669
+
1670
+ $this->set_hierarchy_and_order();
1671
+
1672
+ foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package_id => $package ) {
1673
+
1674
+ $has_top_package = false;
1675
+
1676
+ foreach ( $package['products'] as $product ) {
1677
+
1678
+ if ( $subscription_type == $product['subscription_type'] ) {
1679
+ $has_top_package = true;
1680
+ if ( $product['name'] == $product_name ) {
1681
+ return $available = true;
1682
+ }
1683
+ }
1684
+
1685
+ }
1686
+
1687
+ if ( ! empty( $package['sub-packages'] ) ) {
1688
+ foreach ( $package['sub-packages'] as $sub_package ) {
1689
+ foreach ( $sub_package['products'] as $product ) {
1690
+ if ( $product['name'] == $product_name && ( $subscription_type == $product['subscription_type'] || $has_top_package ) ) {
1691
+ return $available = true;
1692
+ }
1693
+ }
1694
+ }
1695
+ }
1696
+
1697
+ }
1698
+ }
1699
+
1700
+ return $available;
1701
+
1702
+ }
1703
+
1704
+ public function get_upgrade_options( $repository_id ) {
1705
+ $all_upgrades = array();
1706
+
1707
+
1708
+ //get all products: packages and subpackages
1709
+ $all_products = array();
1710
+ foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package ) {
1711
+ foreach ( $package['products'] as $product ) {
1712
+ $all_products[] = $product;
1713
+ }
1714
+ if ( ! empty( $package['sub-packages'] ) ) {
1715
+ foreach ( $package['sub-packages'] as $subpackage ) {
1716
+ foreach ( $subpackage['products'] as $product ) {
1717
+ $all_products[] = $product;
1718
+ }
1719
+
1720
+ }
1721
+
1722
+ }
1723
+
1724
+ }
1725
+
1726
+ foreach ( $all_products as $product ) {
1727
+ if ( $product['upgrades'] ) {
1728
+ foreach ( $product['upgrades'] as $upgrade ) {
1729
+ if ( $this->repository_has_valid_subscription( $repository_id ) || ( $this->repository_has_subscription( $repository_id ) && $upgrade['including_expired'] ) ) {
1730
+ $all_upgrades[ $upgrade['subscription_type'] ][ $product['subscription_type'] ] = $upgrade;
1731
+ }
1732
+ }
1733
+ }
1734
+ }
1735
+
1736
+ return $all_upgrades;
1737
+
1738
+ }
1739
+
1740
+ public function append_site_key_to_download_url( $url, $key, $repository_id ) {
1741
+
1742
+ $url_params['site_key'] = $key;
1743
+ $url_params['site_url'] = $this->get_installer_site_url( $repository_id );
1744
+
1745
+
1746
+ // Add extra parameters for custom Installer packages
1747
+ if ( ! empty( $this->package_source ) ) {
1748
+ $extra = $this->get_extra_url_parameters();
1749
+ if ( ! empty( $extra['repository'] ) && $extra['repository'] == $repository_id ) {
1750
+ unset( $extra['repository'] );
1751
+ foreach ( $extra as $key => $val ) {
1752
+ $url_params[ $key ] = $val;
1753
+ }
1754
+ }
1755
+ }
1756
+
1757
+ $url = add_query_arg( $url_params, $url );
1758
+
1759
+ if ( $repository_id == 'wpml' ) {
1760
+ $url = add_query_arg( array(
1761
+ 'using_icl' => $this->_using_icl,
1762
+ 'wpml_version' => $this->_wpml_version
1763
+ ), $url );
1764
+ }
1765
+
1766
+ return $url;
1767
+
1768
+ }
1769
+
1770
+ public function plugin_is_installed( $name, $slug, $version = null ) {
1771
+
1772
+ $is = false;
1773
+
1774
+ $plugins = get_plugins();
1775
+
1776
+ foreach ( $plugins as $plugin_id => $plugin ) {
1777
+
1778
+ $wp_plugin_slug = dirname( $plugin_id );
1779
+
1780
+ // Exception: embedded plugins
1781
+ if ( $wp_plugin_slug == $slug || $plugin['Name'] == $name || $plugin['Title'] == $name || ( $wp_plugin_slug == $slug . '-embedded' || $plugin['Name'] == $name . ' Embedded' ) ) {
1782
+ if ( $version ) {
1783
+ if ( version_compare( $plugin['Version'], $version, '>=' ) ) {
1784
+ $is = $plugin['Version'];
1785
+ }
1786
+ } else {
1787
+ $is = $plugin['Version'];
1788
+ }
1789
+
1790
+ break;
1791
+ }
1792
+
1793
+ }
1794
+
1795
+ //exception: Types name difference
1796
+ if ( ! $is && $name == 'Types' ) {
1797
+ return $this->plugin_is_installed( 'Types - Complete Solution for Custom Fields and Types', $slug, $version );
1798
+ }
1799
+
1800
+ return $is;
1801
+ }
1802
+
1803
+ public function plugin_is_embedded_version( $name, $slug ) {
1804
+ $is = false;
1805
+
1806
+ $plugins = get_plugins();
1807
+
1808
+ //false if teh full version is also installed
1809
+ $is_full_installed = false;
1810
+ foreach ( $plugins as $plugin_id => $plugin ) {
1811
+
1812
+ if ( ( $plugin['Name'] == $name && ! preg_match( "#-embedded$#", $slug ) ) ) {
1813
+ $is_full_installed = true;
1814
+ break;
1815
+ }
1816
+
1817
+ }
1818
+
1819
+ if ( $is_full_installed ) {
1820
+ return false;
1821
+ }
1822
+
1823
+ foreach ( $plugins as $plugin_id => $plugin ) {
1824
+
1825
+ // TBD
1826
+ $wp_plugin_slug = dirname( $plugin_id );
1827
+ if ( $wp_plugin_slug == $slug . '-embedded' && $plugin['Name'] == $name . ' Embedded' ) {
1828
+ $is = true;
1829
+ break;
1830
+ }
1831
+
1832
+ }
1833
+
1834
+ return $is;
1835
+
1836
+ }
1837
+
1838
+ //Alias for plugin_is_installed
1839
+ public function get_plugin_installed_version( $name, $slug ) {
1840
+
1841
+ return $this->plugin_is_installed( $name, $slug );
1842
+
1843
+ }
1844
+
1845
+ public function get_plugin_repository_version( $repository_id, $slug ) {
1846
+ $version = false;
1847
+
1848
+ if ( ! empty( $this->settings['repositories'][ $repository_id ]['data']['packages'] ) ) {
1849
+ foreach ( $this->settings['repositories'][ $repository_id ]['data']['packages'] as $package ) {
1850
+ foreach ( $package['products'] as $product ) {
1851
+
1852
+ foreach ( $product['plugins'] as $plugin_slug ) {
1853
+
1854
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
1855
+
1856
+ if ( $download['slug'] == $slug ) {
1857
+ $version = $download['version'];
1858
+ break ( 3 );
1859
+ }
1860
+
1861
+ }
1862
+
1863
+ }
1864
+ }
1865
+ }
1866
+
1867
+ return $version;
1868
+ }
1869
+
1870
+ public function is_uploading_allowed() {
1871
+
1872
+ //_deprecated_function ( __FUNCTION__, '1.7.3', 'Installer_Dependencies::' . __FUNCTION__ );
1873
+ return $this->dependencies->is_uploading_allowed();
1874
+
1875
+ }
1876
+
1877
+ public function download_plugin_ajax_handler() {
1878
+
1879
+ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1880
+ require_once $this->plugin_path() . '/includes/class-installer-upgrader-skins.php';
1881
+
1882
+ $data = json_decode( base64_decode( sanitize_text_field( $_POST['data'] ) ), true );
1883
+
1884
+ $ret = false;
1885
+ $plugin_id = false;
1886
+ $message = '';
1887
+
1888
+ //validate subscription
1889
+ $site_key = $this->get_repository_site_key( $data['repository_id'] );
1890
+ $subscription_data = $this->fetch_subscription_data( $data['repository_id'], $site_key, self::SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT );
1891
+
1892
+ if ( $subscription_data && ! is_wp_error( $subscription_data ) && $this->repository_has_valid_subscription( $data['repository_id'] ) ) {
1893
+
1894
+ if ( $data['nonce'] == wp_create_nonce( 'install_plugin_' . $data['url'] ) ) {
1895
+
1896
+ $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
1897
+ $upgrader = new Plugin_Upgrader( $upgrader_skins );
1898
+
1899
+ remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
1900
+
1901
+ $plugins = get_plugins();
1902
+
1903
+ //upgrade or install?
1904
+ foreach ( $plugins as $id => $plugin ) {
1905
+ $wp_plugin_slug = dirname( $id );
1906
+ $is_embedded = $this->plugin_is_embedded_version( preg_replace( '/ Embedded$/', '', $plugin['Name'] ), preg_replace( '/-embedded$/', '', $wp_plugin_slug ) );
1907
+
1908
+ if ( $wp_plugin_slug == $data['slug'] || $is_embedded && preg_replace( '/-embedded$/', '', $wp_plugin_slug ) == $data['slug'] ) {
1909
+ $plugin_id = $id;
1910
+ break;
1911
+ }
1912
+ }
1913
+
1914
+ if ( $plugin_id && empty( $is_embedded ) ) { //upgrade
1915
+ $response['upgrade'] = 1;
1916
+
1917
+ $plugin_is_active = is_plugin_active( $plugin_id );
1918
+
1919
+ $ret = $upgrader->upgrade( $plugin_id );
1920
+
1921
+ if ( ! $ret && ! empty( $upgrader->skin->installer_error ) ) {
1922
+ if ( is_wp_error( $upgrader->skin->installer_error ) ) {
1923
+ $message = $upgrader->skin->installer_error->get_error_message() .
1924
+ ' (' . $upgrader->skin->installer_error->get_error_data() . ')';
1925
+ }
1926
+ $plugin_version = 0;
1927
+ }else{
1928
+ if ( $plugin_is_active ) {
1929
+ //prevent redirects
1930
+ add_filter( 'wp_redirect', '__return_false' );
1931
+ activate_plugin( $plugin_id );
1932
+ }
1933
+ $plugin_version = $this->get_plugin_repository_version( $data['repository_id'], $data['slug'] );
1934
+ }
1935
+
1936
+ } else { //install
1937
+
1938
+ if ( $is_embedded ) {
1939
+ delete_plugins( array( $plugin_id ) );
1940
+ }
1941
+
1942
+ $response['install'] = 1;
1943
+ $ret = $upgrader->install( $data['url'] );
1944
+ if ( ! $ret && ! empty( $upgrader->skin->installer_error ) ) {
1945
+ if ( is_wp_error( $upgrader->skin->installer_error ) ) {
1946
+ $message = $upgrader->skin->installer_error->get_error_message() .
1947
+ ' (' . $upgrader->skin->installer_error->get_error_data() . ')';
1948
+ }
1949
+ }
1950
+ }
1951
+
1952
+ $plugins = get_plugins(); //read again
1953
+
1954
+ if ( $ret ) {
1955
+ foreach ( $plugins as $id => $plugin ) {
1956
+ $wp_plugin_slug = dirname( $id );
1957
+ if ( $wp_plugin_slug == $data['slug'] ) {
1958
+ $plugin_version = $plugin['Version'];
1959
+ $plugin_id = $id;
1960
+ break;
1961
+ }
1962
+ }
1963
+
1964
+ }
1965
+
1966
+ if( WP_Installer_Channels()->get_channel( $data['repository_id'] ) !== WP_Installer_Channels::CHANNEL_PRODUCTION ){
1967
+ $download = $this->settings['repositories'][$data['repository_id']]['data']['downloads']['plugins'][$data['slug']];
1968
+ $non_stable = WP_Installer_Channels()->get_download_source_channel( $plugin_version, $data['repository_id'], $download['slug'], 'plugins' );
1969
+ }
1970
+
1971
+ }
1972
+
1973
+ } else { //subscription not valid
1974
+
1975
+ $ret = false;
1976
+ $message = __( 'Your subscription appears to no longer be valid. Please try to register again using a valid site key.', 'installer' );
1977
+ }
1978
+
1979
+ $response['version'] = isset( $plugin_version ) ? $plugin_version : 0;
1980
+ $response['non_stable']= isset( $non_stable ) ? $non_stable : '';
1981
+ $response['plugin_id'] = $plugin_id;
1982
+ $response['nonce'] = wp_create_nonce( 'activate_' . $plugin_id );
1983
+ $response['success'] = $ret;
1984
+ $response['message'] = $message;
1985
+
1986
+ echo json_encode( $response );
1987
+ exit;
1988
+
1989
+ }
1990
+
1991
+ public function download_plugin( $slug, $url ) {
1992
+
1993
+ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1994
+ require_once $this->plugin_path() . '/includes/class-installer-upgrader-skins.php';
1995
+
1996
+ $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
1997
+ $upgrader = new Plugin_Upgrader( $upgrader_skins );
1998
+
1999
+ remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
2000
+
2001
+ $plugins = get_plugins();
2002
+
2003
+ $plugin_id = false;
2004
+
2005
+ //upgrade or install?
2006
+ foreach ( $plugins as $id => $plugin ) {
2007
+ $wp_plugin_slug = dirname( $id );
2008
+ if ( $wp_plugin_slug == $slug ) {
2009
+ $plugin_id = $id;
2010
+ break;
2011
+ }
2012
+ }
2013
+
2014
+ if ( $plugin_id ) { //upgrade
2015
+
2016
+ $plugin_is_active = is_plugin_active( $plugin_id );
2017
+
2018
+ $ret = $upgrader->upgrade( $plugin_id );
2019
+
2020
+ if ( $plugin_is_active ) {
2021
+ activate_plugin( $plugin_id );
2022
+ }
2023
+
2024
+ } else { //install
2025
+ $ret = $upgrader->install( $url );
2026
+ }
2027
+
2028
+ return $ret;
2029
+
2030
+ }
2031
+
2032
+ public function activate_plugin() {
2033
+
2034
+ $error = '';
2035
+
2036
+ $plugin_id = sanitize_text_field( $_POST['plugin_id'] );
2037
+ if ( isset( $_POST['nonce'] ) && $plugin_id && $_POST['nonce'] == wp_create_nonce( 'activate_' . $plugin_id ) ) {
2038
+
2039
+ // Deactivate any embedded version
2040
+ $plugin_slug = dirname( $plugin_id );
2041
+ $active_plugins = get_option( 'active_plugins' );
2042
+ foreach ( $active_plugins as $plugin ) {
2043
+ $wp_plugin_slug = dirname( $plugin );
2044
+ if ( $wp_plugin_slug == $plugin_slug . '-embedded' ) {
2045
+ deactivate_plugins( array( $plugin ) );
2046
+ break;
2047
+ }
2048
+ }
2049
+
2050
+ //prevent redirects
2051
+ add_filter( 'wp_redirect', '__return_false', 10000 );
2052
+
2053
+ $return = activate_plugin( $plugin_id );
2054
+
2055
+ if ( is_wp_error( $return ) ) {
2056
+ $error = $return->get_error_message();
2057
+ }
2058
+
2059
+ } else {
2060
+ $error = 'error';
2061
+ }
2062
+
2063
+ $ret = array( 'error' => $error );
2064
+
2065
+ echo json_encode( $ret );
2066
+ exit;
2067
+
2068
+ }
2069
+
2070
+ public function custom_plugins_api_call( $false, $action, $args ) {
2071
+
2072
+ if ( $action == 'plugin_information' ) {
2073
+
2074
+ $plugins = get_plugins();
2075
+ $plugin_names = array();
2076
+ foreach ( $plugins as $plugin_id => $plugin ) {
2077
+ // plugins by WP slug which (plugin folder) which can be different
2078
+ // will use this to compare by title
2079
+ $plugin_names[ dirname( $plugin_id ) ] = array(
2080
+ 'name' => $plugin['Name'],
2081
+ 'title' => $plugin['Title'],
2082
+ );
2083
+ }
2084
+
2085
+ $slug = $args->slug;
2086
+
2087
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2088
+
2089
+ if ( ! $this->repository_has_valid_subscription( $repository_id ) ) {
2090
+ $site_key = false;
2091
+ } else {
2092
+ $site_key = $repository['subscription']['key'];
2093
+ }
2094
+
2095
+ foreach ( $repository['data']['packages'] as $package ) {
2096
+
2097
+ foreach ( $package['products'] as $product ) {
2098
+
2099
+ foreach ( $product['plugins'] as $plugin_slug ) {
2100
+
2101
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2102
+
2103
+ if ( $download['slug'] == $slug ||
2104
+ isset( $plugin_names[ $slug ] ) && (
2105
+ $plugin_names[ $slug ]['name'] == $download['name'] ||
2106
+ $plugin_names[ $slug ]['title'] == $download['name']
2107
+ )
2108
+ ) {
2109
+
2110
+ if ( ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION ) {
2111
+ return false; // use data from wordpress.org
2112
+ }
2113
+
2114
+ $res = new stdClass();
2115
+ $res->external = true;
2116
+
2117
+ $res->name = $download['name'];
2118
+ $res->slug = $slug;
2119
+ $res->version = $download['version'];
2120
+ $res->author = '';
2121
+ $res->author_profile = '';
2122
+ $res->last_updated = $download['date'];
2123
+
2124
+ if ( $site_key ) {
2125
+ $res->download_link = $this->append_site_key_to_download_url( $download['url'], $site_key, $repository_id );
2126
+ }
2127
+
2128
+ $res->homepage = $repository['data']['url'];
2129
+ $res->sections = array(
2130
+ 'Description' => $download['description'],
2131
+ 'Changelog' => $download['changelog']
2132
+ );
2133
+
2134
+ return $res;
2135
+
2136
+ }
2137
+
2138
+ }
2139
+
2140
+ }
2141
+
2142
+ }
2143
+
2144
+ }
2145
+
2146
+ }
2147
+
2148
+ return $false;
2149
+
2150
+ }
2151
+
2152
+ public function plugins_upgrade_check( $update_plugins ) {
2153
+
2154
+ if ( ! empty( $this->settings['repositories'] ) ) {
2155
+
2156
+ $plugins = get_plugins();
2157
+
2158
+ foreach ( $plugins as $plugin_id => $plugin ) {
2159
+
2160
+ $slug = dirname( $plugin_id );
2161
+ if ( empty( $slug ) ) {
2162
+ continue;
2163
+ }
2164
+
2165
+ $version = $plugin['Version'];
2166
+ $name = $plugin['Name'];
2167
+
2168
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2169
+
2170
+
2171
+ if ( ! $this->repository_has_valid_subscription( $repository_id ) ) {
2172
+ $site_key = false;
2173
+ } else {
2174
+ $site_key = $repository['subscription']['key'];
2175
+ //$subscription_type = $this->get_subscription_type_for_repository($repository_id);
2176
+ }
2177
+
2178
+ foreach ( $repository['data']['packages'] as $package ) {
2179
+
2180
+ foreach ( $package['products'] as $product ) {
2181
+
2182
+ foreach ( $product['plugins'] as $plugin_slug ) {
2183
+
2184
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2185
+
2186
+ if ( ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION ) {
2187
+ continue;
2188
+ }
2189
+
2190
+ $needs_version_update = version_compare( $download['version'], $version, '>' ) ||
2191
+ ! empty( $_POST['reset_to_channel'] );
2192
+
2193
+ if (
2194
+ empty( $update_plugins->response[ $plugin_id ] ) &&
2195
+ ( $download['slug'] == $slug || $download['name'] == $name ) &&
2196
+ $needs_version_update
2197
+ ) {
2198
+
2199
+ $response = new stdClass();
2200
+ $response->id = 0;
2201
+ $response->slug = $slug;
2202
+ $response->plugin = $plugin_id;
2203
+ $response->new_version = $download['version'];
2204
+ $response->upgrade_notice = '';
2205
+ $response->url = $download['url'];
2206
+ if ( $site_key ) {
2207
+ $response->package = $this->append_site_key_to_download_url( $download['url'], $site_key, $repository_id );
2208
+ }
2209
+ $update_plugins->checked[ $plugin_id ] = $version;
2210
+ $update_plugins->response[ $plugin_id ] = $response;
2211
+
2212
+ }
2213
+
2214
+ }
2215
+
2216
+ }
2217
+
2218
+ }
2219
+
2220
+ }
2221
+
2222
+ }
2223
+
2224
+ }
2225
+
2226
+ return $update_plugins;
2227
+
2228
+ }
2229
+
2230
+ public function setup_plugins_page_notices() {
2231
+
2232
+ $plugins = get_plugins();
2233
+
2234
+ foreach ( $plugins as $plugin_id => $plugin ) {
2235
+
2236
+ $slug = dirname( $plugin_id );
2237
+ if ( empty( $slug ) ) {
2238
+ continue;
2239
+ }
2240
+
2241
+ $name = $plugin['Name'];
2242
+
2243
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2244
+
2245
+ if ( ! $this->repository_has_valid_subscription( $repository_id ) ) {
2246
+ $site_key = false;
2247
+ } else {
2248
+ $site_key = $repository['subscription']['key'];
2249
+ }
2250
+
2251
+ foreach ( $repository['data']['packages'] as $package ) {
2252
+
2253
+ foreach ( $package['products'] as $product ) {
2254
+
2255
+ foreach ( $product['plugins'] as $plugin_slug ) {
2256
+
2257
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2258
+ if ( ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION ) {
2259
+ continue;
2260
+ }
2261
+
2262
+ if ( $download['slug'] == $slug || $download['name'] == $name ) {
2263
+
2264
+ if ( ! $site_key || ! $this->plugin_is_registered( $repository_id, $download['slug'] ) ) {
2265
+ add_action( "after_plugin_row_" . $plugin_id, array(
2266
+ $this,
2267
+ 'show_purchase_notice_under_plugin'
2268
+ ), 10, 3 );
2269
+ }
2270
+
2271
+ }
2272
+
2273
+ }
2274
+
2275
+ }
2276
+
2277
+ }
2278
+
2279
+ }
2280
+
2281
+ }
2282
+
2283
+ }
2284
+
2285
+ public function show_purchase_notice_under_plugin( $plugin_file, $plugin_data, $status ) {
2286
+
2287
+ $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
2288
+ $wp_version = preg_replace( '/-(.+)$/', '', $GLOBALS['wp_version'] );
2289
+
2290
+ if ( version_compare( $wp_version, '4.6', '>=' ) ) {
2291
+
2292
+ ?>
2293
+ <tr class="plugin-update-tr installer-plugin-update-tr">
2294
+ <td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
2295
+ <div class="notice inline notice-warning notice-alt">
2296
+ <p class="installer-q-icon">
2297
+ <?php printf( __( 'You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer' ),
2298
+ '<a href="' . $this->menu_url() . '">', '</a>' ); ?>
2299
+ </p>
2300
+ </div>
2301
+ </td>
2302
+ </tr>
2303
+ <?php
2304
+
2305
+ } else {
2306
+
2307
+ ?>
2308
+ <tr class="plugin-update-tr">
2309
+ <td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
2310
+ <div class="update-message installer-q-icon">
2311
+ <?php printf( __( 'You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer' ),
2312
+ '<a href="' . $this->menu_url() . '">', '</a>' ); ?>
2313
+ </div>
2314
+ </td>
2315
+ </tr>
2316
+ <?php
2317
+
2318
+ }
2319
+
2320
+ }
2321
+
2322
+ public function localize_strings() {
2323
+
2324
+ if ( ! empty( $this->settings['repositories'] ) ) {
2325
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2326
+ //set name as call2action when don't have any
2327
+ //products
2328
+ foreach ( $repository['data']['packages'] as $package_id => $package ) {
2329
+ foreach ( $package['products'] as $product_id => $product ) {
2330
+ if ( empty( $product['call2action'] ) ) {
2331
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['call2action'] = $product['name'];
2332
+ }
2333
+
2334
+ foreach ( $product['upgrades'] as $idx => $upg ) {
2335
+ if ( empty( $upg['call2action'] ) ) {
2336
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['upgrades'][ $idx ]['call2action'] = $upg['name'];
2337
+ }
2338
+ }
2339
+
2340
+ foreach ( $product['renewals'] as $idx => $rnw ) {
2341
+ if ( empty( $rnw['call2action'] ) ) {
2342
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['renewals'][ $idx ]['call2action'] = $rnw['name'];
2343
+ }
2344
+
2345
+ }
2346
+
2347
+ }
2348
+ }
2349
+ }
2350
+ }
2351
+
2352
+ global $sitepress;
2353
+ if ( is_null( $sitepress ) ) {
2354
+ return;
2355
+ }
2356
+
2357
+ // default strings are always in English
2358
+ $user_admin_language = $sitepress->get_admin_language();
2359
+
2360
+ if ( $user_admin_language != 'en' ) {
2361
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2362
+
2363
+ $localization = $repository['data']['localization'];
2364
+
2365
+ //packages
2366
+ foreach ( $repository['data']['packages'] as $package_id => $package ) {
2367
+
2368
+ if ( isset( $localization['packages'][ $package_id ]['name'][ $user_admin_language ] ) ) {
2369
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['name'] = $localization['packages'][ $package_id ]['name'][ $user_admin_language ];
2370
+ }
2371
+ if ( isset( $localization['packages'][ $package_id ]['description'][ $user_admin_language ] ) ) {
2372
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['description'] = $localization['packages'][ $package_id ]['description'][ $user_admin_language ];
2373
+ }
2374
+
2375
+ }
2376
+
2377
+ //products
2378
+ foreach ( $repository['data']['packages'] as $package_id => $package ) {
2379
+ foreach ( $package['products'] as $product_id => $product ) {
2380
+
2381
+ if ( isset( $localization['products'][ $product_id ]['name'][ $user_admin_language ] ) ) {
2382
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['name']
2383
+ = $localization['products'][ $product_id ]['name'][ $user_admin_language ];
2384
+ }
2385
+ if ( isset( $localization['products'][ $product_id ]['description'][ $user_admin_language ] ) ) {
2386
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['description']
2387
+ = $localization['products'][ $product_id ]['description'][ $user_admin_language ];
2388
+ }
2389
+ if ( isset( $localization['products'][ $product_id ]['call2action'][ $user_admin_language ] ) ) {
2390
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['name']
2391
+ = $localization['products'][ $product_id ]['call2action'][ $user_admin_language ];
2392
+ }
2393
+
2394
+
2395
+ }
2396
+ }
2397
+
2398
+ //subscription info
2399
+ if ( isset( $repository['data']['subscriptions_meta']['expiration'] ) ) {
2400
+ foreach ( $repository['data']['subscriptions_meta']['expiration'] as $subscription_id => $note ) {
2401
+ if ( isset( $localization['subscriptions-notes'][ $subscription_id ]['expiration-warning'][ $user_admin_language ] ) ) {
2402
+ $this->settings['repositories'][ $repository_id ]['data']['subscriptions_meta']['expiration'][ $subscription_id ]['warning_message']
2403
+ = $localization['subscriptions-notes'][ $subscription_id ]['expiration-warning'][ $user_admin_language ];
2404
+ }
2405
+ }
2406
+ }
2407
+
2408
+ }
2409
+ }
2410
+
2411
+ }
2412
+
2413
+ public function get_matching_cp( $repository, $args = array() ) {
2414
+ $match = false;
2415
+
2416
+
2417
+ $cp_name = $cp_author = false;
2418
+
2419
+ if ( isset( $this->config['src_name'] ) && isset( $this->config['src_author'] ) ) {
2420
+
2421
+ $cp_name = $this->config['src_name'];
2422
+ $cp_author = $this->config['src_author'];
2423
+
2424
+ } elseif ( isset( $args['src_name'] ) && isset( $args['src_author'] ) ) {
2425
+
2426
+ $cp_name = $args['src_name'];
2427
+ $cp_author = $args['src_author'];
2428
+
2429
+ }
2430
+
2431
+ if ( isset( $repository['data']['marketing_cp'] ) ) {
2432
+
2433
+ foreach ( $repository['data']['marketing_cp'] as $cp ) {
2434
+
2435
+ if ( ! empty( $cp['exp'] ) && time() > $cp['exp'] ) {
2436
+ continue;
2437
+ }
2438
+
2439
+ //Use theme_name for plugins too
2440
+ if ( ! empty( $cp['theme_name'] ) ) {
2441
+ if ( $cp['author_name'] == $cp_author && $cp['theme_name'] == $cp_name ) {
2442
+ $match = $cp;
2443
+ continue;
2444
+ }
2445
+ } else {
2446
+ if ( $cp['author_name'] == $cp_author ) {
2447
+ $match = $cp;
2448
+ continue;
2449
+ }
2450
+ }
2451
+
2452
+ }
2453
+
2454
+ }
2455
+
2456
+ return $match;
2457
+ }
2458
+
2459
+ public function set_filtered_prices( $args = array() ) {
2460
+
2461
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2462
+
2463
+ $match = $this->get_matching_cp( $repository, $args );
2464
+
2465
+ if ( empty( $match ) ) {
2466
+ continue;
2467
+ }
2468
+
2469
+ foreach ( $repository['data']['packages'] as $package_id => $package ) {
2470
+
2471
+ foreach ( $package['products'] as $product_id => $product ) {
2472
+
2473
+ if ( $match['dtp'] == '%' ) {
2474
+ $fprice = round( $product['price'] * ( 1 - $match['amt'] / 100 ), 2 );
2475
+ $fprice = $fprice != round( $fprice ) ? sprintf( '%.2f', $fprice ) : round( $fprice, 0 );
2476
+ } elseif ( $match['dtp'] == '-' ) {
2477
+ $fprice = $product['price'] - $match['amt'];
2478
+ } else {
2479
+ $fprice = $product['price'];
2480
+ }
2481
+
2482
+ if ( $fprice ) {
2483
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['price_disc'] = $fprice;
2484
+
2485
+ $url_glue = false !== strpos( $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['url'], '?' ) ? '&' : '?';
2486
+ $cpndata = base64_encode( json_encode( array(
2487
+ 'theme_author' => $match['author_name'],
2488
+ 'theme_name' => $match['theme_name'],
2489
+ 'vlc' => $match['vlc']
2490
+ ) ) );
2491
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['url'] .= $url_glue . 'cpn=' . $cpndata;
2492
+
2493
+ foreach ( $product['upgrades'] as $upgrade_id => $upgrade ) {
2494
+
2495
+ $fprice = false;
2496
+ if ( $match['dtp'] == '%' ) {
2497
+ $fprice = round( $upgrade['price'] * ( 1 - $match['amt'] / 100 ), 2 );
2498
+ $fprice = $fprice != round( $fprice ) ? sprintf( '%.2f', $fprice ) : round( $fprice, 0 );
2499
+ } elseif ( $match['dtp'] == '-' ) {
2500
+ $fprice = $upgrade['price'] - $match['amt'];
2501
+ }
2502
+ if ( $fprice ) {
2503
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['upgrades'][ $upgrade_id ]['price_disc'] = $fprice;
2504
+ $this->settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['upgrades'][ $upgrade_id ]['url'] .= $url_glue . 'cpn=' . $cpndata;
2505
+ }
2506
+
2507
+
2508
+ }
2509
+
2510
+ }
2511
+
2512
+ }
2513
+
2514
+ }
2515
+
2516
+ }
2517
+
2518
+ }
2519
+
2520
+ public function set_hierarchy_and_order() {
2521
+
2522
+ //2 levels
2523
+ if ( ! empty( $this->settings['repositories'] ) ) {
2524
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2525
+
2526
+ if ( empty( $repository['data']['packages'] ) ) {
2527
+ continue;
2528
+ }
2529
+
2530
+ $all_packages = $repository['data']['packages'];
2531
+ $ordered_packages = array();
2532
+
2533
+ //backward compatibility - 'order'
2534
+ foreach ( $all_packages as $k => $v ) {
2535
+ if ( ! isset( $v['order'] ) ) {
2536
+ $all_packages[ $k ]['order'] = 0;
2537
+ }
2538
+ }
2539
+
2540
+ //select parents
2541
+ foreach ( $all_packages as $package_id => $package ) {
2542
+ if ( empty( $package['parent'] ) ) {
2543
+ $ordered_packages[ $package_id ] = $package;
2544
+ }
2545
+ }
2546
+
2547
+ //add sub-packages
2548
+ foreach ( $all_packages as $package_id => $package ) {
2549
+ if ( ! empty( $package['parent'] ) ) {
2550
+ if ( isset( $ordered_packages[ $package['parent'] ] ) ) {
2551
+ $ordered_packages[ $package['parent'] ]['sub-packages'][ $package_id ] = $package;
2552
+ }
2553
+ }
2554
+ }
2555
+
2556
+ // order parents
2557
+ usort( $ordered_packages, array( $this, '_order_packages_callback' ) );
2558
+ //order sub-packages
2559
+ foreach ( $ordered_packages as $package_id => $package ) {
2560
+ if ( ! empty( $package['sub-packages'] ) ) {
2561
+ usort( $ordered_packages[ $package_id ]['sub-packages'], create_function( '$a, $b', 'return $a[\'order\'] > $b[\'order\'];' ) );
2562
+ }
2563
+ }
2564
+
2565
+ $this->settings['repositories'][ $repository_id ]['data']['packages'] = $ordered_packages;
2566
+
2567
+
2568
+ }
2569
+ }
2570
+
2571
+
2572
+ }
2573
+
2574
+ public function _order_packages_callback( $a, $b ) {
2575
+ return $a['order'] > $b['order'];
2576
+ }
2577
+
2578
+ public function get_support_tag_by_name( $name, $repository ) {
2579
+
2580
+ if ( is_array( $this->settings['repositories'][ $repository ]['data']['support_tags'] ) ) {
2581
+ foreach ( $this->settings['repositories'][ $repository ]['data']['support_tags'] as $support_tag ) {
2582
+ if ( $support_tag['name'] == $name ) {
2583
+ return $support_tag['url'];
2584
+ }
2585
+ }
2586
+ }
2587
+
2588
+ return false;
2589
+ }
2590
+
2591
+ public function plugin_upgrade_custom_errors() {
2592
+
2593
+ if ( isset( $_REQUEST['action'] ) ) {
2594
+
2595
+ $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
2596
+
2597
+ //bulk mode
2598
+ if ( 'update-selected' == $action ) {
2599
+
2600
+ global $plugins;
2601
+
2602
+ if ( isset( $plugins ) && is_array( $plugins ) ) {
2603
+
2604
+ foreach ( $plugins as $k => $plugin ) {
2605
+ $plugin_repository = false;
2606
+
2607
+ $wp_plugin_slug = dirname( $plugin );
2608
+
2609
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2610
+
2611
+ foreach ( $repository['data']['packages'] as $package ) {
2612
+
2613
+ foreach ( $package['products'] as $product ) {
2614
+
2615
+ foreach ( $product['plugins'] as $plugin_slug ) {
2616
+
2617
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2618
+
2619
+ if ( $download['slug'] == $wp_plugin_slug ) {
2620
+ $plugin_repository = $repository_id;
2621
+ $product_name = $repository['data']['product-name'];
2622
+ $plugin_name = $download['name'];
2623
+ $free_on_wporg = ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION;
2624
+ break;
2625
+ }
2626
+
2627
+ }
2628
+
2629
+ }
2630
+
2631
+ }
2632
+
2633
+ }
2634
+
2635
+ if ( $plugin_repository ) {
2636
+
2637
+ //validate subscription
2638
+ static $sub_cache = array();
2639
+
2640
+ if ( empty( $sub_cache[ $plugin_repository ] ) ) {
2641
+ $site_key = $this->get_repository_site_key( $plugin_repository );
2642
+ if ( $site_key ) {
2643
+ $subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
2644
+ }
2645
+
2646
+ $sub_cache[ $plugin_repository ]['site_key'] = $site_key;
2647
+ $sub_cache[ $plugin_repository ]['subscription_data'] = isset( $subscription_data ) ? $subscription_data : false;
2648
+ } else {
2649
+
2650
+ $site_key = $sub_cache[ $plugin_repository ]['site_key'];
2651
+ $subscription_data = $sub_cache[ $plugin_repository ]['subscription_data'];
2652
+
2653
+ }
2654
+
2655
+ if ( ! $site_key && ! empty( $free_on_wporg ) ) { // allow the download from wp.org
2656
+ continue;
2657
+ }
2658
+
2659
+ if ( empty( $site_key ) || empty( $subscription_data ) ) {
2660
+
2661
+
2662
+ $error_message = sprintf( __( "%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer' ),
2663
+ '<strong>' . $plugin_name . '</strong>', '<a target="_top" href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
2664
+ '#repository-' . $plugin_repository . '">', $product_name, '</a>' );
2665
+
2666
+ echo '<div class="updated error"><p>' . $error_message . '</p></div>';
2667
+
2668
+ unset( $plugins[ $k ] );
2669
+
2670
+
2671
+ }
2672
+
2673
+ }
2674
+
2675
+ }
2676
+
2677
+ }
2678
+
2679
+ }
2680
+
2681
+
2682
+ if ( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
2683
+
2684
+ $plugin = isset( $_REQUEST['plugin'] ) ? trim( sanitize_text_field( $_REQUEST['plugin'] ) ) : '';
2685
+
2686
+ $wp_plugin_slug = dirname( $plugin );
2687
+
2688
+ $plugin_repository = false;
2689
+
2690
+ foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
2691
+
2692
+ foreach ( $repository['data']['packages'] as $package ) {
2693
+
2694
+ foreach ( $package['products'] as $product ) {
2695
+
2696
+ foreach ( $product['plugins'] as $plugin_slug ) {
2697
+ $download = $this->settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ];
2698
+
2699
+ //match by folder, will change to match by name and folder
2700
+ if ( $download['slug'] == $wp_plugin_slug ) {
2701
+ $plugin_repository = $repository_id;
2702
+ $product_name = $repository['data']['product-name'];
2703
+ $plugin_name = $download['name'];
2704
+ $free_on_wporg = ! empty( $download['free-on-wporg'] ) && $download['channel'] == WP_Installer_Channels::CHANNEL_PRODUCTION;
2705
+ break;
2706
+ }
2707
+
2708
+ }
2709
+
2710
+ }
2711
+
2712
+ }
2713
+
2714
+ }
2715
+
2716
+ if ( $plugin_repository ) {
2717
+
2718
+ //validate subscription
2719
+ $site_key = $this->get_repository_site_key( $plugin_repository );
2720
+ if ( $site_key ) {
2721
+ $subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
2722
+ }
2723
+
2724
+ if ( ( empty( $site_key ) || empty( $subscription_data ) ) && empty( $free_on_wporg ) ) {
2725
+
2726
+ $error_message = sprintf( __( "%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer' ),
2727
+ '<strong>' . $plugin_name . '</strong>', '<a href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
2728
+ '#repository-' . $plugin_repository . '">', $product_name, '</a>' );
2729
+
2730
+ if ( defined( 'DOING_AJAX' ) ) { //WP 4.2
2731
+
2732
+ $status = array(
2733
+ 'update' => 'plugin',
2734
+ 'plugin' => $plugin,
2735
+ 'slug' => sanitize_key( $_POST['slug'] ),
2736
+ 'oldVersion' => '',
2737
+ 'newVersion' => '',
2738
+ );
2739
+
2740
+ $status['errorCode'] = 'wp_installer_invalid_subscription';
2741
+ $status['error'] = $error_message;
2742
+
2743
+ wp_send_json_error( $status );
2744
+
2745
+ } else { // WP 4.1.1
2746
+ echo '<div class="updated error"><p>' . $error_message . '</p></div>';
2747
+
2748
+
2749
+ echo '<div class="wrap">';
2750
+ echo '<h2>' . __( 'Update Plugin', 'installer' ) . '</h2>';
2751
+ echo '<a href="' . admin_url( 'plugins.php' ) . '">' . __( 'Return to the plugins page', 'installer' ) . '</a>';
2752
+ echo '</div>';
2753
+ require_once( ABSPATH . 'wp-admin/admin-footer.php' );
2754
+ exit;
2755
+
2756
+ }
2757
+
2758
+ }
2759
+
2760
+
2761
+ }
2762
+
2763
+ }
2764
+ }
2765
+
2766
+ }
2767
+
2768
+ }
 
vendor/otgs/installer/includes/functions-core.php CHANGED
@@ -1,9 +1,9 @@
1
- <?php
2
-
3
- function WP_Installer(){
4
- return WP_Installer::instance();
5
- }
6
-
7
- function WP_Installer_Channels(){
8
- return WP_Installer_Channels::instance();
9
- }
1
+ <?php
2
+
3
+ function WP_Installer(){
4
+ return WP_Installer::instance();
5
+ }
6
+
7
+ function WP_Installer_Channels(){
8
+ return WP_Installer_Channels::instance();
9
+ }
vendor/otgs/installer/includes/functions-templates.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
-
3
- // Ext function
4
- function WP_Installer_Show_Products($args = array()){
5
- WP_Installer()->show_products($args);
6
- }
1
+ <?php
2
+
3
+ // Ext function
4
+ function WP_Installer_Show_Products($args = array()){
5
+ WP_Installer()->show_products($args);
6
+ }
vendor/otgs/installer/includes/installer-api.php DELETED
@@ -1,134 +0,0 @@
1
- <?php
2
-
3
- class WP_Installer_API{
4
-
5
- public static function get_product_installer_link($repository_id, $package_id = false){
6
-
7
- $menu_url = WP_Installer()->menu_url();
8
-
9
- $url = $menu_url . '#' . $repository_id;
10
- if($package_id){
11
- $url .= '/' . $package_id;
12
- }
13
-
14
- return $url;
15
-
16
- }
17
-
18
- public static function get_product_price($repository_id, $package_id, $product_id, $incl_discount = false){
19
-
20
- $price = WP_Installer()->get_product_price($repository_id, $package_id, $product_id, $incl_discount);
21
-
22
- return $price;
23
- }
24
-
25
- /**
26
- * Retrieve the preferred translation service.
27
- *
28
- * @since 1.6.5
29
- *
30
- * @param string The repository id (e.g. wpml)
31
- * @return string The translation service id
32
- */
33
- public static function get_preferred_ts($repository_id = 'wpml'){
34
-
35
- if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'])){
36
- return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'];
37
- }
38
-
39
- return false;
40
-
41
- }
42
-
43
- /**
44
- * Set the preferred translation service.
45
- *
46
- * @since 1.6.5
47
- *
48
- * @param string The translation service id
49
- * @param string The repository id (e.g. wpml)
50
- */
51
- public static function set_preferred_ts( $value, $repository_id = 'wpml' ){
52
-
53
- if( isset( WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] ) ){
54
-
55
- WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] = $value;
56
-
57
- WP_Installer()->save_settings();
58
-
59
- }
60
-
61
- }
62
-
63
- /**
64
- * Retrieve the referring translation service (if any)
65
- *
66
- * @since 1.6.5
67
- *
68
- * @param string The repository id (e.g. wpml)
69
- * @return string The translation service id or false
70
- */
71
- public static function get_ts_referal($repository_id = 'wpml'){
72
-
73
- if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'])){
74
- return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'];
75
- }
76
-
77
- return false;
78
-
79
- }
80
-
81
- /**
82
- * Retrieve the translation services client id for a specific repository (if any)
83
- *
84
- * @since 1.7.9
85
- *
86
- * @param string The repository id (e.g. wpml)
87
- * @return string The client id or false
88
- */
89
- public static function get_ts_client_id( $repository_id = 'wpml' ){
90
-
91
- if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'])){
92
- return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'];
93
- }
94
-
95
- return false;
96
-
97
- }
98
-
99
- /**
100
- * Retrieve the site key corresponding to a repository.
101
- * This is a wrapper of WP_Installer::get_site_key()
102
- * @see WP_Installer::get_site_key()
103
- *
104
- * @since 1.7.9
105
- *
106
- * @param string The repository id (e.g. wpml)
107
- * @return string The site key (or false)
108
- */
109
- public static function get_site_key( $repository_id = 'wpml' ){
110
-
111
- return WP_Installer()->get_site_key( $repository_id );
112
-
113
- }
114
-
115
- /**
116
- * Retrieve the ID of the last user who registered a repository.
117
- *
118
- * @since 1.7.16
119
- *
120
- * @param string The repository id (e.g. wpml)
121
- * @return int The user id (or zero)
122
- */
123
- public static function get_registering_user_id( $repository_id = 'wpml' ){
124
-
125
- $user_id = 0;
126
- if( isset( WP_Installer()->settings['repositories'][$repository_id]['subscription']['registered_by'] ) ){
127
- $user_id = WP_Installer()->settings['repositories'][$repository_id]['subscription']['registered_by'];
128
- }
129
-
130
- return $user_id;
131
- }
132
-
133
-
134
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/otgs/installer/includes/installer-upgrader-skins.php DELETED
@@ -1,37 +0,0 @@
1
- <?php
2
- class Installer_Upgrader_Skins extends WP_Upgrader_Skin{
3
-
4
- function __construct($args = array()){
5
- $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
6
- $this->options = wp_parse_args($args, $defaults);
7
- }
8
-
9
- function header(){
10
-
11
- }
12
-
13
- function footer(){
14
-
15
- }
16
-
17
- function error($error){
18
- $this->installer_error = $error;
19
- }
20
-
21
- function add_strings(){
22
-
23
- }
24
-
25
- function feedback($string){
26
-
27
- }
28
-
29
- function before(){
30
-
31
- }
32
-
33
- function after(){
34
-
35
- }
36
-
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/otgs/installer/includes/installer.class.php DELETED
@@ -1,2672 +0,0 @@
1
- <?php
2
-
3
- final class WP_Installer{
4
- protected static $_instance = null;
5
-
6
- public $settings = array();
7
-
8
- private $repositories = array();
9
-
10
- protected $api_debug = '';
11
-
12
- private $config = array();
13
-
14
- protected $_plugins_renew_warnings = array();
15
-
16
- protected $_gz_on = false;
17
-
18
- private $admin_messages = array();
19
-
20
- private $_using_icl = false;
21
- private $_wpml_version = false;
22
-
23
- private $package_source = array();
24
-
25
- const SITE_KEY_VALIDATION_SOURCE_OTHER = 0;
26
- const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_SPECIFIC = 1;
27
- const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT = 2;
28
- const SITE_KEY_VALIDATION_SOURCE_REGISTRATION = 3;
29
- const SITE_KEY_VALIDATION_SOURCE_REVALIDATION = 4;
30
- const SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK = 5;
31
-
32
- public $dependencies;
33
-
34
- public static function instance() {
35
-
36
- if ( is_null( self::$_instance ) ) {
37
- self::$_instance = new self();
38
- }
39
-
40
- return self::$_instance;
41
- }
42
-
43
- public function __construct(){
44
-
45
- if(!is_admin() || !is_user_logged_in()) return; //Only for admin
46
-
47
- $this->_gz_on = function_exists('gzuncompress') && function_exists('gzcompress');
48
- $this->settings = $this->get_settings();
49
-
50
- add_action('admin_notices', array($this, 'show_site_key_nags'));
51
-
52
- add_action('admin_notices', array($this, 'show_admin_messages'));
53
-
54
- add_action('admin_init', array($this, 'load_embedded_plugins'), 0);
55
-
56
- add_action('admin_menu', array($this, 'menu_setup'));
57
- add_action('network_admin_menu', array($this, 'menu_setup'));
58
-
59
- if(defined('DOING_AJAX') && isset($_POST['action']) && $_POST['action'] == 'installer_download_plugin'){
60
- add_filter( 'site_transient_update_plugins', array( $this, 'plugins_upgrade_check') );
61
- }
62
- add_filter('plugins_api', array( $this, 'custom_plugins_api_call'), 10, 3);
63
- add_filter('pre_set_site_transient_update_plugins', array( $this, 'plugins_upgrade_check'));
64
-
65
- // register repositories
66
- $this->load_repositories_list();
67
-
68
- if( empty($this->settings['last_repositories_update']) || time() - $this->settings['last_repositories_update'] > 86400
69
- || ( isset($_GET['force-check']) && $_GET['force-check'] == 1 ) ){
70
- $this->refresh_repositories_data();
71
- }
72
-
73
- // default config
74
- $this->config['plugins_install_tab'] = false;
75
-
76
- add_action('init', array($this, 'init'));
77
-
78
- //add_filter('wp_installer_buy_url', array($this, 'append_parameters_to_buy_url'));
79
-
80
- add_action('init', array($this,'load_locale'));
81
-
82
- }
83
-
84
- public function get_repositories() {
85
-
86
- return $this->repositories;
87
-
88
- }
89
-
90
- public function set_config($key, $value){
91
-
92
- $this->config[$key] = $value;
93
-
94
- }
95
-
96
- public function init(){
97
- global $pagenow;
98
-
99
- $this->dependencies = new Installer_Dependencies;
100
-
101
- if(empty($this->settings['_pre_1_0_clean_up'])) {
102
- $this->_pre_1_0_clean_up();
103
- }
104
-
105
- $this->settings = $this->_old_products_format_backwards_compatibility($this->settings);
106
-
107
- if ( !function_exists( 'get_plugins' ) ) {
108
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
109
- }
110
-
111
- $this->_using_icl = function_exists('wpml_site_uses_icl') && wpml_site_uses_icl();
112
- $this->_wpml_version = defined('ICL_SITEPRESS_VERSION') ? ICL_SITEPRESS_VERSION : '';
113
-
114
- wp_enqueue_script('installer-admin', $this->res_url() . '/res/js/admin.js', array('jquery'), $this->version());
115
- wp_enqueue_style('installer-admin', $this->res_url() . '/res/css/admin.css', array(), $this->version());
116
-
117
- $translation_array = array(
118
- 'installing' => __( 'Installing %s', 'installer' ),
119
- 'updating' => __( 'Updating %s', 'installer' ),
120
- 'activating' => __( 'Activating %s', 'installer' )
121
- );
122
-
123
- wp_localize_script( 'installer-admin', 'installer_strings', $translation_array );
124
-
125
- if($pagenow == 'plugins.php'){
126
- add_action('admin_notices', array($this, 'setup_plugins_page_notices'));
127
- add_action('admin_notices', array($this, 'setup_plugins_renew_warnings'), 10);
128
- add_action('admin_notices', array($this, 'queue_plugins_renew_warnings'), 20);
129
-
130
- add_action('admin_init', array($this, 'setup_plugins_action_links'));
131
-
132
- }
133
-
134
- if($this->is_repositories_page()){
135
- add_action('admin_init', array($this, 'validate_repository_subscription'));
136
- }
137
-
138
- if(defined('DOING_AJAX')){
139
- add_action('wp_ajax_save_site_key', array($this, 'save_site_key'));
140
- add_action('wp_ajax_remove_site_key', array($this, 'remove_site_key_ajax'));
141
- add_action('wp_ajax_update_site_key', array($this, 'update_site_key'));
142
-
143
- add_action('wp_ajax_installer_download_plugin', array($this, 'download_plugin_ajax_handler'));
144
- add_action('wp_ajax_installer_activate_plugin', array($this, 'activate_plugin'));
145
-
146
- add_action('wp_ajax_installer_dismiss_nag', array($this, 'dismiss_nag'));
147
- }
148
-
149
- if($pagenow == 'update.php'){
150
- if(isset($_GET['action']) && $_GET['action'] == 'update-selected'){
151
- add_action('admin_head', array($this, 'plugin_upgrade_custom_errors')); //iframe/bulk
152
- }else{
153
- add_action('all_admin_notices', array($this, 'plugin_upgrade_custom_errors')); //regular/singular
154
- }
155
- }
156
-
157
- // WP 4.2
158
- if(defined('DOING_AJAX')){
159
- add_action('wp_ajax_update-plugin', array($this, 'plugin_upgrade_custom_errors'), 0); // high priority, before WP
160
- }
161
-
162
- //Include theme support
163
- include_once $this->plugin_path() . '/includes/class-installer-theme.php';
164
-
165
- // Extra information about the source of Installer
166
- $package_source_file = $this->plugin_path() . '/installer-source.json';
167
- if( file_exists( $package_source_file ) ){
168
- WP_Filesystem();
169
- global $wp_filesystem;
170
- $this->package_source = json_decode( $wp_filesystem->get_contents( $package_source_file ) );
171
- }
172
- }
173
-
174
- protected function log($message){
175
- require_once ABSPATH . 'wp-admin/includes/file.php';
176
- WP_Filesystem();
177
- global $wp_filesystem;
178
- if( defined('WPML_INSTALLER_LOGGING') && WPML_INSTALLER_LOGGING ){
179
- $wp_filesystem->put_contents( $this->plugin_path() . '/installer.log', current_time( 'mysql' ) . "\t" . $message . "\n" );
180
- }
181
- }
182
-
183
- public function register_admin_message($text, $type = 'updated'){
184
- $this->admin_messages[] = array('text' => $text, 'type' => $type);
185
- }
186
-
187
- public function show_admin_messages(){
188
- if(!empty($this->admin_messages)){
189
- $types = array( 'error', 'updated', 'notice' );
190
- foreach($this->admin_messages as $message){
191
- $class = in_array( $message['type'], $types ) ? $message['type'] : 'updated';
192
- ?>
193
- <div class="<?php echo $class ?>">
194
- <p>
195
- <?php echo $message['text'] ?>
196
- </p>
197
- </div>
198
- <?php
199
- }
200
- }
201
- }
202
-
203
- public function load_locale(){
204
- if( function_exists('get_user_locale') ){
205
- $locale = get_user_locale();
206
- }else{
207
- $locale = get_locale();
208
- }
209
- $locale = apply_filters( 'plugin_locale', $locale, 'installer' );
210
- $mo_file = $this->plugin_path() . '/locale/installer-' . $locale . '.mo';
211
- if(file_exists($mo_file)){
212
- load_textdomain( 'installer', $mo_file );
213
- }
214
- }
215
-
216
- public function load_embedded_plugins(){
217
- if(file_exists($this->plugin_path() . '/embedded-plugins' )) {
218
- include_once $this->plugin_path() . '/embedded-plugins/embedded-plugins.class.php';
219
- $this->installer_embedded_plugins = new Installer_Embedded_Plugins();
220
- }
221
- }
222
-
223
- public function menu_setup(){
224
- global $pagenow;
225
-
226
- if(is_multisite() && !is_network_admin()){
227
- $this->menu_multisite_redirect();
228
- add_options_page(__('Installer', 'installer'), __('Installer', 'installer'), 'manage_options', 'installer', array($this, 'show_products')) ;
229
- }else{
230
- if($this->config['plugins_install_tab'] && is_admin() && $pagenow == 'plugin-install.php'){
231
- // Default GUI, under Plugins -> Install
232
- add_filter('install_plugins_tabs', array($this, 'add_install_plugins_tab'));
233
- add_action('install_plugins_commercial', array($this, 'show_products'));
234
- }
235
- }
236
-
237
- }
238
-
239
- public function menu_url(){
240
- if(is_multisite()){
241
- if(is_network_admin()){
242
- $url = network_admin_url('plugin-install.php?tab=commercial');
243
- }else{
244
- $url = admin_url('options-general.php?page=installer');
245
- }
246
- }else{
247
- $url = admin_url('plugin-install.php?tab=commercial');
248
- }
249
- return $url;
250
- }
251
-
252
- private function menu_multisite_redirect(){
253
- global $pagenow;
254
-
255
- if($pagenow == 'plugin-install.php' && isset($_GET['tab']) && $_GET['tab'] == 'commercial'){
256
- wp_redirect($this->menu_url());
257
- exit;
258
- }
259
-
260
- }
261
-
262
- private function _pre_1_0_clean_up(){
263
- global $wpdb;
264
-
265
- if(!defined('WPRC_VERSION')){
266
- $old_tables = array(
267
- $wpdb->prefix . 'wprc_cached_requests',
268
- $wpdb->prefix . 'wprc_extension_types',
269
- $wpdb->prefix . 'wprc_extensions',
270
- $wpdb->prefix . 'wprc_repositories',
271
- $wpdb->prefix . 'wprc_repositories_relationships',
272
- );
273
-
274
- foreach($old_tables as $table){
275
- $wpdb->query(sprintf("DROP TABLE IF EXISTS %s", $table));
276
- }
277
-
278
- }
279
-
280
- $this->settings['_pre_1_0_clean_up'] = true;
281
- $this->save_settings();
282
- }
283
-
284
- public function setup_plugins_action_links(){
285
-
286
- $plugins = get_plugins();
287
-
288
- $repositories_plugins = array();
289
-
290
- if( !empty($this->settings['repositories']) ) {
291
-
292
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
293
-
294
- foreach ( $repository['data']['packages'] as $package ) {
295
-
296
- foreach ( $package['products'] as $product ) {
297
-
298
- foreach ( $product['plugins'] as $plugin_slug ) {
299
-
300
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
301
-
302
- if ( !isset($repositories_plugins[$repository_id][$download['slug']]) ) {
303
- $repositories_plugins[$repository_id][$download['slug']] = array(
304
- 'name' => $download['name'],
305
- 'registered' => $this->plugin_is_registered( $repository_id, $download['slug'] ) ? 1 : 0
306
- );
307
- }
308
-
309
- }
310
-
311
- }
312
-
313
- }
314
-
315
- foreach ( $plugins as $plugin_id => $plugin ) {
316
-
317
- $wp_plugin_slug = dirname( $plugin_id );
318
- if ( empty($wp_plugin_slug) ) {
319
- $wp_plugin_slug = basename( $plugin_id, '.php' );
320
- }
321
-
322
- foreach ( $repositories_plugins as $repository_id => $r_plugins ) {
323
-
324
- foreach ( $r_plugins as $slug => $r_plugin ) {
325
-
326
- if ( $wp_plugin_slug == $slug || $r_plugin['name'] == $plugin['Name'] || $r_plugin['name'] == $plugin['Title'] ) { //match order: slug, name, title
327
-
328
- if ( $r_plugin['registered'] ) {
329
- add_filter( 'plugin_action_links_' . $plugin_id, array($this, 'plugins_action_links_registered') );
330
- } else {
331
- add_filter( 'plugin_action_links_' . $plugin_id, array($this, 'plugins_action_links_not_registered') );
332
- }
333
-
334
- }
335
-
336
- }
337
-
338
- }
339
-
340
-
341
- }
342
-
343
- }
344
- }
345
-
346
- }
347
-
348
- public function plugins_action_links_registered($links){
349
- $links[] = '<a href="' . $this->menu_url() . '">' . __('Registered', 'installer') . '</a>';
350
- return $links;
351
- }
352
-
353
- public function plugins_action_links_not_registered($links){
354
- $links[] = '<a href="' . $this->menu_url() . '">' . __('Register', 'installer') . '</a>';
355
- return $links;
356
- }
357
-
358
- public function plugin_is_registered($repository_id, $slug){
359
-
360
- $registered = false;
361
-
362
- if( $this->repository_has_valid_subscription($repository_id) ){
363
-
364
- $subscription_type = $this->get_subscription_type_for_repository($repository_id);
365
- $r_plugins = array();
366
-
367
- foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
368
-
369
- foreach($package['products'] as $product){
370
-
371
- if( $product['subscription_type'] == $subscription_type || $this->have_superior_subscription($subscription_type, $product) ) {
372
-
373
- foreach ($product['plugins'] as $plugin_slug) {
374
-
375
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
376
-
377
- if (!isset($rep_plugins[$download['slug']])) {
378
- $r_plugins[$download['slug']] = $download['slug'];
379
- }
380
-
381
- }
382
-
383
- }
384
-
385
- }
386
-
387
- }
388
-
389
- $registered = isset($r_plugins[$slug]);
390
-
391
- }
392
-
393
-
394
- return $registered;
395
-
396
- }
397
-
398
- public function version(){
399
- return WP_INSTALLER_VERSION;
400
- }
401
-
402
- public function plugin_path() {
403
- return untrailingslashit( plugin_dir_path( dirname(__FILE__) ) );
404
- }
405
-
406
- public function plugin_url() {
407
- if(isset($this->config['in_theme_folder']) && !empty($this->config['in_theme_folder'])){
408
- $url = untrailingslashit(get_template_directory_uri() . '/' . $this->config['in_theme_folder']);
409
- }else{
410
- $url = untrailingslashit( plugins_url( '/', dirname(__FILE__) ) );
411
- }
412
-
413
- return $url;
414
- }
415
-
416
- public function is_repositories_page(){
417
- global $pagenow;
418
-
419
- return $pagenow == 'plugin-install.php' && isset($_GET['tab']) && $_GET['tab'] == 'commercial';
420
- }
421
-
422
- public function res_url(){
423
- if(isset($this->config['in_theme_folder']) && !empty($this->config['in_theme_folder'])){
424
- $url = untrailingslashit(get_template_directory_uri() . '/' . $this->config['in_theme_folder']);
425
- }else{
426
- $url = $this->plugin_url();
427
- }
428
- return $url;
429
- }
430
-
431
- public function save_settings(){
432
-
433
- $_settings = serialize($this->settings);
434
- if($this->_gz_on){
435
- $_settings = gzcompress($_settings);
436
- }
437
- $_settings = base64_encode($_settings);
438
-
439
- update_option( 'wp_installer_settings', $_settings );
440
-
441
- if( is_multisite() && is_main_site() && isset($this->settings['repositories']) ){
442
- $network_settings = array();
443
-
444
- foreach( $this->settings['repositories'] as $rep_id => $repository ){
445
- if( isset($repository['subscription']) )
446
- $network_settings[$rep_id] = $repository['subscription'];
447
- }
448
-
449
- update_site_option( 'wp_installer_network', $network_settings );
450
-
451
-
452
- }
453
-
454
- }
455
-
456
- public function get_settings($refresh = false){
457
-
458
- if($refresh || empty($this->settings)){
459
-
460
- $_settings = get_option('wp_installer_settings');
461
-
462
-
463
- if (is_array($_settings) || empty($_settings)) { //backward compatibility 1.1
464
- $this->settings = $_settings;
465
-
466
- } else {
467
- $_settings = base64_decode($_settings);
468
- if ($this->_gz_on) {
469
- $_settings = gzuncompress($_settings);
470
- }
471
- $this->settings = unserialize($_settings);
472
- }
473
-
474
- // Initialize
475
- if( empty( $this->settings ) ){
476
- $this->settings = array(
477
- 'repositories' => array()
478
- );
479
- }
480
-
481
- if ( is_multisite() ) {
482
- $network_settings = maybe_unserialize(get_site_option('wp_installer_network'));
483
- if ($network_settings) {
484
- foreach ($this->settings['repositories'] as $rep_id => $repository) {
485
- if (isset($network_settings[$rep_id])) {
486
- $this->settings['repositories'][$rep_id]['subscription'] = $network_settings[$rep_id];
487
- }
488
- }
489
- }
490
- }
491
-
492
- $this->load_hardcoded_site_keys();
493
-
494
- $this->settings = $this->_pre_1_6_backwards_compatibility($this->settings);
495
-
496
- $this->settings = $this->_old_products_format_backwards_compatibility($this->settings);
497
-
498
- }
499
-
500
- return $this->settings;
501
- }
502
-
503
- private function load_hardcoded_site_keys(){
504
-
505
- if( !empty( $this->settings['repositories'] ) ) {
506
- foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
507
-
508
- if ( $site_key = self::get_repository_hardcoded_site_key( $repository_id ) ) {
509
-
510
- $site_key_missing = empty($this->settings['repositories'][$repository_id]['subscription']['data']);
511
- $site_key_changed = !$site_key_missing &&
512
- $this->settings['repositories'][$repository_id]['subscription']['key'] != $site_key;
513
-
514
- if ( $site_key_missing || $site_key_changed ) {
515
-
516
- if ( !function_exists( 'get_plugins' ) ) {
517
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
518
- }
519
- $this->load_repositories_list();
520
- $response = $this->save_site_key(
521
- array(
522
- 'repository_id' => $repository_id,
523
- 'site_key' => $site_key,
524
- 'return' => true,
525
- 'nonce' => wp_create_nonce( 'save_site_key_' . $repository_id )
526
- )
527
- );
528
-
529
- if ( !empty($response['error']) ) {
530
- $this->remove_site_key( $repository_id );
531
-
532
- $this->admin_messages[] = array(
533
- 'type' => 'error',
534
- 'text' => sprintf( __( 'You are using an invalid site key defined as the constant %s (most likely in wp-config.php).
535
- Please remove it or use the correct value in order to be able to register correctly.', 'installer' ), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id ) )
536
- );
537
-
538
- }
539
-
540
- }
541
-
542
- }
543
-
544
- }
545
- }
546
-
547
- }
548
-
549
- public static function get_repository_hardcoded_site_key( $repository_id ){
550
-
551
- $site_key = false;
552
-
553
- $site_key_constant = 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id );
554
- if( defined( $site_key_constant ) ){
555
- $site_key = constant( $site_key_constant );
556
- }
557
-
558
- return $site_key;
559
- }
560
-
561
- //backward compatibility, will remove 'basename' in version 1.8
562
- private function _pre_1_6_backwards_compatibility($settings){
563
-
564
- if( version_compare($this->version(), '1.8', '<') && !empty($settings['repositories']) ){
565
- foreach ($settings['repositories'] as $repository_id => $repository) {
566
- if( isset( $repository['data'] ) ) {
567
- foreach ( $repository['data']['downloads']['plugins'] as $slug => $download ) {
568
- $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $slug ]['slug'] = $download['basename'];
569
- }
570
- }
571
- }
572
- }
573
-
574
- return $settings;
575
- }
576
-
577
- //backward compatibility - support old products list format (downloads under products instead of global downloads list)
578
- private function _old_products_format_backwards_compatibility($settings){
579
-
580
- if( version_compare($this->version(), '1.8', '<') && !empty($settings['repositories']) && empty($this->_old_products_format_backwards_compatibility) ) {
581
-
582
- foreach ($settings['repositories'] as $repository_id => $repository) {
583
- $populate_downloads = false;
584
- if( isset( $repository['data'] ) ) {
585
-
586
- foreach ( $repository['data']['packages'] as $package_id => $package ) {
587
- foreach ( $package['products'] as $product_id => $product ) {
588
- if ( ! isset( $product['plugins'] ) ) {
589
- $populate_downloads = true;
590
- foreach ( $product['downloads'] as $download_id => $download ) {
591
- $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['plugins'][] = $download['slug'];
592
- }
593
- }
594
- }
595
- }
596
-
597
- if ( $populate_downloads ) {
598
- // Add downloads branch
599
- foreach ( $repository['data']['packages'] as $package_id => $package ) {
600
- foreach ( $package['products'] as $product_id => $product ) {
601
- foreach ( $product['downloads'] as $download_id => $download ) {
602
- if ( ! isset( $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $download['slug'] ] ) ) {
603
- $settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $download['slug'] ] = $download;
604
- }
605
- $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['plugins'][] = $download['slug'];
606
- }
607
- unset( $settings['repositories'][ $repository_id ]['data']['packages'][ $package_id ]['products'][ $product_id ]['downloads'] );
608
- }
609
- }
610
- }
611
- }
612
- }
613
-
614
- $this->_old_products_format_backwards_compatibility = true;
615
- }
616
-
617
- return $settings;
618
- }
619
-
620
- public function get_installer_site_url( $repository_id = false ){
621
- global $current_site;
622
-
623
- $site_url = get_site_url();
624
-
625
- if( $repository_id && is_multisite() && isset( $this->settings['repositories'] ) ){
626
- $network_settings = maybe_unserialize( get_site_option('wp_installer_network') );
627
-
628
- if ( isset( $network_settings[$repository_id] ) ) {
629
- $site_url = get_site_url( $current_site->blog_id );
630
- }
631
-
632
- }
633
-
634
- return $site_url;
635
- }
636
-
637
- public function show_site_key_nags(){
638
- $screen = get_current_screen();
639
-
640
- if($screen->base == 'settings_page_installer' || ($screen->base == 'plugin-install' && isset($_GET['tab']) && $_GET['tab'] == 'commercial')){
641
- return;
642
- }
643
-
644
- if(!empty($this->config['site_key_nags'])){
645
-
646
- foreach($this->config['site_key_nags'] as $nag){
647
-
648
- if(!$this->repository_has_subscription($nag['repository_id'] )){
649
- $show = true;
650
- if(!empty($nag['condition_cb'])){
651
- $show = call_user_func($nag['condition_cb']);
652
- }
653
-
654
- if(empty($this->settings['dismissed_nags'][$nag['repository_id']]) && $show){
655
- echo '<div class="updated error otgs-is-dismissible"><p>';
656
- printf(__("To get automatic updates, you need to register %s for this site. %sRegister %s%s", 'sitepress'),
657
- $nag['product_name'], '<a class="button-primary" href="' . $this->menu_url() . '">', $nag['product_name'], '</a>');
658
-
659
- echo '</p>';
660
- echo '<span class="installer-dismiss-nag notice-dismiss" data-repository="' . $nag['repository_id'] . '"><span class="screen-reader-text">' . __('Dismiss', 'sitepress') . '</span></span>';
661
- echo '</div>';
662
- }
663
- }
664
-
665
- }
666
-
667
- }
668
-
669
- }
670
-
671
- public function dismiss_nag(){
672
- $this->settings['dismissed_nags'][$_POST['repository']] = 1;
673
-
674
- $this->save_settings();
675
-
676
- echo json_encode(array());
677
- exit;
678
- }
679
-
680
- public function add_install_plugins_tab($tabs){
681
-
682
- $tabs['commercial'] = __('Commercial', 'installer');
683
-
684
- return $tabs;
685
- }
686
-
687
- public function load_repositories_list(){
688
- global $wp_installer_instances;
689
-
690
- foreach ($wp_installer_instances as $instance) {
691
-
692
- if (file_exists(dirname($instance['bootfile']) . '/repositories.xml')) {
693
- $config_file = dirname($instance['bootfile']) . '/repositories.xml';
694
-
695
- if (file_exists(dirname($instance['bootfile']) . '/repositories.sandbox.xml')) {
696
- $config_file = dirname($instance['bootfile']) . '/repositories.sandbox.xml';
697
- add_filter('https_ssl_verify', '__return_false');
698
- }
699
-
700
- $repos = simplexml_load_file($config_file);
701
-
702
- if($repos) {
703
- foreach ($repos as $repo) {
704
- $id = strval($repo->id);
705
-
706
- $data['api-url'] = strval($repo->apiurl);
707
- $data['products'] = strval($repo->products);
708
-
709
- // excludes rule;
710
- if (isset($this->config['repositories_exclude']) && in_array($id, $this->config['repositories_exclude'])) {
711
- continue;
712
- }
713
-
714
- // includes rule;
715
- if (isset($this->config['repositories_include']) && !in_array($id, $this->config['repositories_include'])) {
716
- continue;
717
- }
718
-
719
- $this->repositories[$id] = $data;
720
-
721
- }
722
- }
723
-
724
- }
725
- }
726
-
727
- }
728
-
729
- public function filter_repositories_list(){
730
-
731
- if(!empty($this->settings['repositories'])) {
732
- foreach ($this->settings['repositories'] as $id => $repo_data) {
733
-
734
- // excludes rule;
735
- if (isset($this->config['repositories_exclude']) && in_array($id, $this->config['repositories_exclude'])) {
736
- unset($this->settings['repositories'][$id]);
737
- }
738
-
739
- // includes rule;
740
- if (isset($this->config['repositories_include']) && !in_array($id, $this->config['repositories_include'])) {
741
- unset($this->settings['repositories'][$id]);
742
- }
743
-
744
-
745
- }
746
- }
747
-
748
-
749
- }
750
-
751
- public function refresh_repositories_data(){
752
- static $checked = false;
753
-
754
- if( defined('OTGS_DISABLE_AUTO_UPDATES') && OTGS_DISABLE_AUTO_UPDATES && empty($_GET['force-check']) || $checked ){
755
-
756
- if(empty($this->settings['repositories']) && $this->is_repositories_page()){
757
-
758
- foreach($this->repositories as $id => $data) {
759
- $repository_names[] = $id;
760
-
761
- }
762
-
763
- $error = sprintf(__("Installer cannot display the products information because the automatic updating for %s was explicitly disabled with the configuration below (usually in wp-config.php):", 'installer'), strtoupper( join(', ', $repository_names) ));
764
- $error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code><br /><br />';
765
- $error .= sprintf(__("In order to see the products information, please run the %smanual updates check%s to initialize the products list or (temporarily) remove the above code.", 'installer'), '<a href="' . admin_url('update-core.php') . '">', '</a>');
766
-
767
- $this->register_admin_message($error, 'error');
768
-
769
-
770
- }
771
-
772
- return;
773
- }
774
-
775
- $checked = true;
776
-
777
- foreach($this->repositories as $id => $data){
778
-
779
- $response = wp_remote_get($data['products']);
780
-
781
- if(is_wp_error($response)){
782
- // http fallback
783
- $data['products'] = preg_replace("@^https://@", 'http://', $data['products']);
784
- $response = wp_remote_get($data['products']);
785
- }
786
-
787
- if(is_wp_error($response)){
788
-
789
- $error = sprintf(__("Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:", 'installer'), strtoupper($id));
790
- $error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code>';
791
-
792
- $this->register_admin_message($error, 'error');
793
-
794
- continue;
795
- }
796
-
797
- if($response && isset($response['response']['code']) && $response['response']['code'] == 200){
798
- $body = wp_remote_retrieve_body($response);
799
- if($body){
800
- $products = json_decode($body, true);
801
-
802
- if(is_array($products)){
803
- $this->settings['repositories'][$id]['data'] = $products;
804
- $this->settings = $this->_pre_1_6_backwards_compatibility($this->settings);
805
- }
806
- }
807
-
808
- }
809
-
810
- $this->log( sprintf("Checked for %s updates: %s", $id, $data['products']) );
811
-
812
-
813
- }
814
-
815
- // cleanup
816
- if(empty($this->settings['repositories'])){
817
- $this->settings['repositories'] = array();
818
- }
819
- foreach($this->settings['repositories'] as $id => $data){
820
- if(!in_array($id, array_keys($this->repositories))){
821
- unset($this->settings['repositories'][$id]);
822
- }
823
- }
824
-
825
- $this->settings['last_repositories_update']= time();
826
-
827
- $this->save_settings();
828
-
829
- }
830
-
831
- public function show_products($args = array()){
832
-
833
- $screen = get_current_screen();
834
-
835
- if($screen->base == 'settings_page_installer'){ // settings page
836
- echo '<div class="wrap">';
837
- echo '<h2>' . __('Installer', 'installer') . '</h2>';
838
- echo '<br />';
839
- }
840
-
841
- if(!is_array($args)) $args = array();
842
- if(empty($args['template'])) $args['template'] = 'default';
843
-
844
- $this->filter_repositories_list();
845
-
846
- if(!empty($this->settings['repositories'])){
847
-
848
- $this->localize_strings();
849
- $this->set_filtered_prices($args);
850
- $this->set_hierarchy_and_order();
851
-
852
- foreach($this->settings['repositories'] as $repository_id => $repository){
853
-
854
- if($args['template'] == 'compact'){
855
-
856
- if(isset($args['repository']) && $args['repository'] == $repository_id){
857
- include $this->plugin_path() . '/templates/products-compact.php';
858
- }
859
-
860
- }else{
861
-
862
- include $this->plugin_path() . '/templates/repository-listing.php';
863
-
864
- }
865
-
866
- unset($site_key, $subscription_type, $expired, $upgrade_options, $products_avaliable);
867
-
868
- }
869
-
870
- }else{
871
-
872
- echo '<center>' . __('No repositories defined.', 'installer') . '</center>';
873
-
874
- }
875
-
876
- if($screen->base == 'settings_page_installer'){ // settings page
877
- echo '</div>';
878
- }
879
-
880
-
881
- }
882
-
883
- public function get_product_price($repository_id, $package_id, $product_id, $incl_discount = false){
884
-
885
- $price = false;
886
-
887
- foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package ){
888
-
889
- if($package['id'] == $package_id){
890
- if(isset($package['products'][$product_id])){
891
- if($incl_discount && isset($package['products'][$product_id]['price_disc'])){
892
- $price = $package['products'][$product_id]['price_disc'];
893
- }elseif(isset($package['products'][$product_id]['price'])){
894
- $price = $package['products'][$product_id]['price'];
895
- }
896
- }
897
- break;
898
- }
899
- }
900
-
901
- return $price;
902
- }
903
-
904
- private function _render_product_packages($packages, $subscription_type, $expired, $upgrade_options, $repository_id){
905
-
906
- $data = array();
907
-
908
- foreach($packages as $package_id => $package){
909
-
910
- $row = array('products' => array(), 'downloads' => array());
911
- foreach($package['products'] as $product){
912
-
913
- // filter out free subscriptions from being displayed as buying options
914
- if( empty($product['price']) && (empty($subscription_type) || $expired) ){
915
- continue;
916
- }
917
-
918
- //consider equivalent subscriptions
919
- if( empty($product['subscription_type_equivalent'])){
920
- $product['subscription_type_equivalent'] = '';
921
- }
922
-
923
- // buy base
924
- if(empty($subscription_type) || $expired) {
925
-
926
- $p['url'] = $this->append_parameters_to_buy_url($product['url'], $repository_id);
927
- if (!empty($product['price_disc'])) {
928
- $p['label'] = $product['call2action'] . ' - ' . sprintf('$%s %s$%d%s (USD)', $product['price_disc'], '&nbsp;&nbsp;<del>', $product['price'], '</del>');
929
- } else {
930
- $p['label'] = $product['call2action'] . ' - ' . sprintf('$%d (USD)', $product['price']);
931
- }
932
- $row['products'][] = $p;
933
-
934
- // renew
935
- } elseif(isset($subscription_type) && ($product['subscription_type'] == $subscription_type || $product['subscription_type_equivalent'] == $subscription_type)){
936
-
937
- if($product['renewals']) {
938
- foreach ($product['renewals'] as $renewal) {
939
- $p['url'] = $this->append_parameters_to_buy_url($renewal['url'], $repository_id);
940
- $p['label'] = $renewal['call2action'] . ' - ' . sprintf('$%d (USD)', $renewal['price']);
941
- }
942
-
943
- $row['products'][] = $p;
944
- }
945
-
946
- }
947
-
948
- // upgrades
949
- if(!empty($upgrade_options[$product['subscription_type']])){
950
-
951
- foreach($upgrade_options[$product['subscription_type']] as $stype => $upgrade){
952
- if($stype != $subscription_type) continue;
953
-
954
- $p['url'] = $this->append_parameters_to_buy_url($upgrade['url'], $repository_id);
955
- if (!empty($upgrade['price_disc'])) {
956
- $p['label'] = $upgrade['call2action'] . ' - ' . sprintf('$%s %s$%d%s (USD)', $upgrade['price_disc'], '&nbsp;&nbsp;<del>', $upgrade['price'], '</del>');
957
- } else {
958
- $p['label'] = $upgrade['call2action'] . ' - ' . sprintf('$%d (USD)', $upgrade['price']);
959
- }
960
- $row['products'][] = $p;
961
-
962
- }
963
-
964
- }
965
-
966
- // downloads
967
- if(isset($subscription_type) && !$expired && ($product['subscription_type'] == $subscription_type || $product['subscription_type_equivalent'] == $subscription_type)){
968
- foreach($product['plugins'] as $plugin_slug){
969
- $row['downloads'][ $plugin_slug ] = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
970
- }
971
- }
972
-
973
- //subpackages
974
- if(!empty($package['sub-packages'])){
975
- $row['sub-packages'] = $package['sub-packages'];
976
- }
977
-
978
- }
979
-
980
- $row['id'] = $package['id'];
981
- $row['image_url'] = $package['image_url'];
982
- $row['name'] = $package['name'];
983
- $row['description'] = $package['description'];
984
-
985
- if(!empty($row['products']) || !empty($row['downloads']) || !empty($row['sub-packages'])){
986
- $data[] = $row;
987
- }
988
-
989
-
990
- }
991
-
992
- return $data;
993
-
994
- }
995
-
996
- public function get_extra_url_parameters(){
997
-
998
- $parameters = array();
999
-
1000
- if(!empty($this->package_source)){
1001
- foreach($this->package_source as $key => $val){
1002
- $parameters[$key] = $val;
1003
- }
1004
- }
1005
-
1006
- $parameters['installer_version'] = WP_INSTALLER_VERSION;
1007
- $parameters['theme'] = wp_get_theme()->get( 'Name' );
1008
- $parameters['site_name'] = get_bloginfo( 'name' );
1009
-
1010
- return $parameters;
1011
- }
1012
-
1013
- public function append_parameters_to_buy_url($url, $repository_id, $args = array()){
1014
-
1015
- $url = add_query_arg( array('icl_site_url' => $this->get_installer_site_url( $repository_id ) ), $url );
1016
-
1017
- $affiliate_id = false;
1018
- $affiliate_key = false;
1019
-
1020
- // Add extra parameters for custom Installer packages
1021
- if( !empty($this->package_source) ){
1022
- $extra = $this->get_extra_url_parameters();
1023
-
1024
- if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
1025
-
1026
- if( !empty($extra['affiliate_key']) && !empty($extra['user_id']) ){
1027
- $this->config['affiliate_id:' . $repository_id] = $extra['user_id'];
1028
- $this->config['affiliate_key:' . $repository_id] = $extra['affiliate_key'];
1029
- unset($extra['affiliate_key'], $extra['user_id'], $extra['repository']); // no need to include these ones
1030
- }
1031
-
1032
- $url = add_query_arg($extra, $url);
1033
- }
1034
-
1035
- }
1036
-
1037
- if(isset($this->config['affiliate_id:' . $repository_id]) && isset($this->config['affiliate_key:' . $repository_id])){
1038
-
1039
- $affiliate_id = $this->config['affiliate_id:' . $repository_id];
1040
- $affiliate_key = $this->config['affiliate_key:' . $repository_id];
1041
-
1042
- }elseif(isset($args['affiliate_id:' . $repository_id]) && isset($args['affiliate_key:' . $repository_id])){
1043
-
1044
- $affiliate_id = $args['affiliate_id:' . $repository_id];
1045
- $affiliate_key = $args['affiliate_key:' . $repository_id];
1046
-
1047
- }elseif(defined('ICL_AFFILIATE_ID') && defined('ICL_AFFILIATE_KEY')){ //support for 1 repo
1048
-
1049
- $affiliate_id = ICL_AFFILIATE_ID;
1050
- $affiliate_key = ICL_AFFILIATE_KEY;
1051
-
1052
- }elseif(isset($this->config['affiliate_id']) && isset($this->config['affiliate_key'])) {
1053
- // BACKWARDS COMPATIBILITY
1054
- $affiliate_id = $this->config['affiliate_id'];
1055
- $affiliate_key = $this->config['affiliate_key'];
1056
- }
1057
-
1058
- if($affiliate_id && $affiliate_key){
1059
- $url = add_query_arg(array('aid' => $affiliate_id, 'affiliate_key' => $affiliate_key), $url);
1060
- }
1061
-
1062
- if($repository_id == 'wpml'){
1063
- $url = add_query_arg(array('using_icl' => $this->_using_icl, 'wpml_version' => $this->_wpml_version), $url);
1064
- }
1065
-
1066
- $url = apply_filters('wp_installer_buy_url', $url);
1067
-
1068
- $url = esc_url($url);
1069
-
1070
- return $url;
1071
-
1072
- }
1073
-
1074
- public function save_site_key($args = array()){
1075
-
1076
- $error = '';
1077
-
1078
- if( isset( $args['repository_id'] ) ){
1079
- $repository_id = $args['repository_id'];
1080
- }elseif( isset( $_POST['repository_id'] ) ){
1081
- $repository_id = sanitize_text_field( $_POST['repository_id'] );
1082
- }else{
1083
- $repository_id = false;
1084
- }
1085
-
1086
- if( isset( $args['nonce'] ) ){
1087
- $nonce = $args['nonce'];
1088
- }elseif( isset($_POST['nonce'] ) ){
1089
- $nonce = sanitize_text_field( $_POST['nonce'] );
1090
- }else{
1091
- $nonce = '';
1092
- }
1093
-
1094
- if( isset( $args['site_key'] ) ){
1095
- $site_key = $args['site_key'];
1096
- } else {
1097
- $site_key = sanitize_text_field( $_POST[ 'site_key_' . $repository_id] );
1098
- }
1099
- $site_key = preg_replace("/[^A-Za-z0-9]/", '', $site_key);
1100
-
1101
- if($repository_id && $nonce && wp_create_nonce('save_site_key_' . $repository_id) == $nonce){
1102
-
1103
- try {
1104
- $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REGISTRATION );
1105
-
1106
- if ( $subscription_data ) {
1107
- $this->settings['repositories'][$repository_id]['subscription'] = array(
1108
- 'key' => $site_key,
1109
- 'data' => $subscription_data,
1110
- 'registered_by' => get_current_user_id()
1111
- );
1112
- $this->save_settings();
1113
- } else {
1114
- $error = __( 'Invalid site key for the current site.', 'installer' )
1115
- . '<br /><div class="installer-footnote">' . __('Please note that the site key is case sensitive.', 'installer') . '</div>';
1116
- }
1117
-
1118
- } catch (Exception $e ){
1119
- $error = $e->getMessage();
1120
- if( preg_match('#Could not resolve host: (.*)#', $error, $matches) || preg_match('#Couldn\'t resolve host \'(.*)\'#', $error, $matches) ){
1121
- $error = sprintf(__("%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer'),
1122
- '<strong><i>' . $this->get_generic_product_name($repository_id) . '</i></strong>',
1123
- '<strong><i>' . $matches[1]. '</i></strong>'
1124
- ) ;
1125
- }
1126
- }
1127
-
1128
- }
1129
-
1130
- $return = array('error' => $error);
1131
-
1132
- if($this->api_debug){
1133
- $return['debug'] = $this->api_debug;
1134
- }
1135
-
1136
- if(!empty($args['return'])){
1137
- return $return;
1138
- }else{
1139
- echo json_encode($return);
1140
- exit;
1141
- }
1142
-
1143
- }
1144
-
1145
- /**
1146
- * Alias for WP_Installer::get_repository_site_key
1147
- * @see WP_Installer::get_repository_site_key()
1148
- *
1149
- * @param string $repository_id
1150
- * @return string (site key) or bool
1151
- */
1152
- public function get_site_key($repository_id){
1153
- return WP_Installer::get_repository_site_key( $repository_id );
1154
- }
1155
-
1156
- public function remove_site_key( $repository_id ){
1157
- if( isset( $this->settings['repositories'][$repository_id] ) ){
1158
- unset($this->settings['repositories'][$repository_id]['subscription']);
1159
- $this->save_settings();
1160
- $this->refresh_repositories_data();
1161
- }
1162
- }
1163
-
1164
- public function remove_site_key_ajax(){
1165
- if($_POST['nonce'] == wp_create_nonce('remove_site_key_' . $_POST['repository_id'])){
1166
- $this->remove_site_key( $_POST['repository_id'] );
1167
- }
1168
- exit;
1169
- }
1170
-
1171
- public function validate_repository_subscription(){
1172
- $repository_id = isset($_GET['validate_repository']) ? sanitize_text_field( $_GET['validate_repository'] ) : false;
1173
- if($repository_id){
1174
-
1175
- $site_key = $this->get_site_key($repository_id);
1176
- if($site_key) {
1177
- $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION);
1178
- if(empty($subscription_data)){
1179
- unset($this->settings['repositories'][$repository_id]['subscription']);
1180
- delete_site_transient('update_plugins');
1181
- $this->save_settings();
1182
- }
1183
- }
1184
-
1185
- wp_redirect($this->menu_url() . '#repository-' . $repository_id);
1186
- exit;
1187
-
1188
- }
1189
-
1190
- }
1191
-
1192
- public function update_site_key(){
1193
-
1194
- $error = '';
1195
-
1196
- $repository_id = sanitize_text_field ( $_POST['repository_id'] );
1197
- if($_POST['nonce'] == wp_create_nonce('update_site_key_' . $repository_id )){
1198
-
1199
- $site_key = $this->get_site_key($_POST['repository_id']);
1200
-
1201
- if($site_key){
1202
- try {
1203
- $subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK );
1204
-
1205
- if ( $subscription_data ) {
1206
- $this->settings['repositories'][$repository_id]['subscription'] = array(
1207
- 'key' => $site_key,
1208
- 'data' => $subscription_data,
1209
- 'registered_by' => get_current_user_id()
1210
- );
1211
-
1212
- //also refresh products information
1213
- $this->refresh_repositories_data();
1214
-
1215
- $this->save_settings();
1216
-
1217
- } else {
1218
- unset($this->settings['repositories'][$repository_id]['subscription']);
1219
- $error = __( 'Invalid site key for the current site. If the error persists, try to unregister first and then register again with the same site key.', 'installer' );
1220
- }
1221
-
1222
-
1223
- } catch (Exception $e ){
1224
- $error = $e->getMessage();
1225
- if( preg_match('#Could not resolve host: (.*)#', $error, $matches) || preg_match('#Couldn\'t resolve host \'(.*)\'#', $error, $matches) ){
1226
- $error = sprintf(__("%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer'),
1227
- '<strong><i>' . $this->get_generic_product_name($repository_id) . '</i></strong>',
1228
- '<strong><i>' . $matches[1]. '</i></strong>'
1229
- ) ;
1230
- }
1231
- }
1232
-
1233
- }
1234
-
1235
- }
1236
-
1237
- echo json_encode(array('error' => $error));
1238
-
1239
- exit;
1240
- }
1241
-
1242
- public function api_debug_log($text){
1243
-
1244
- if(defined('WPML_DEBUG_INSTALLER') && WPML_DEBUG_INSTALLER){
1245
-
1246
- if(!is_scalar($text)){
1247
- $text = print_r($text, 1);
1248
- }
1249
-
1250
- $this->api_debug .= $text . "\n";
1251
-
1252
- }
1253
-
1254
- }
1255
-
1256
- public function fetch_subscription_data( $repository_id, $site_key, $source = self::SITE_KEY_VALIDATION_SOURCE_OTHER ){
1257
-
1258
- $subscription_data = false;
1259
-
1260
- $args['body'] = array(
1261
- 'action' => 'site_key_validation',
1262
- 'site_key' => $site_key,
1263
- 'site_url' => $this->get_installer_site_url( $repository_id ),
1264
- 'source' => $source
1265
- );
1266
-
1267
- if($repository_id == 'wpml'){
1268
- $args['body']['using_icl'] = $this->_using_icl;
1269
- $args['body']['wpml_version'] = $this->_wpml_version;
1270
- }
1271
-
1272
- $args['body']['installer_version'] = WP_INSTALLER_VERSION;
1273
- $args['body']['theme'] = wp_get_theme()->get( 'Name' );
1274
- $args['body']['site_name'] = get_bloginfo( 'name' );
1275
-
1276
- $args['body']['versions'] = $this->get_local_product_versions( $repository_id );
1277
-
1278
- $args['timeout'] = 45;
1279
-
1280
- // Add extra parameters for custom Installer packages
1281
- if( !empty($this->package_source) ){
1282
- $extra = $this->get_extra_url_parameters();
1283
- if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
1284
- unset($extra['repository']);
1285
- foreach($extra as $key => $val){
1286
- $args['body'][$key] = $val;
1287
- }
1288
- }
1289
- }
1290
-
1291
- $response = wp_remote_post($this->repositories[$repository_id]['api-url'], $args);
1292
-
1293
- $this->api_debug_log("POST {$this->repositories[$repository_id]['api-url']}");
1294
- $this->api_debug_log($args);
1295
-
1296
- $this->log("POST {$this->repositories[$repository_id]['api-url']} - fetch subscription data");
1297
-
1298
- if( !is_wp_error($response) ){
1299
- $datas = wp_remote_retrieve_body($response);
1300
-
1301
- if(is_serialized($datas)){
1302
- $data = unserialize($datas);
1303
- $this->api_debug_log($data);
1304
-
1305
- if( !empty( $data->subscription_data ) ){
1306
- $subscription_data = $data->subscription_data;
1307
- }
1308
-
1309
- do_action( 'installer_fetched_subscription_data', $data, $repository_id);
1310
-
1311
- }else{
1312
- $this->api_debug_log($datas);
1313
- }
1314
-
1315
- }else{
1316
-
1317
- $this->api_debug_log($response);
1318
- throw new Exception( $response->get_error_message() );
1319
- }
1320
-
1321
- return $subscription_data;
1322
-
1323
- }
1324
-
1325
- function get_local_product_versions( $repository_id ){
1326
-
1327
- $versions = array();
1328
-
1329
- foreach( $this->settings['repositories'][$repository_id]['data']['packages'] as $package_id => $package ){
1330
-
1331
- foreach( $package['products'] as $product_id => $product ){
1332
-
1333
- foreach( $product['plugins'] as $plugin_slug ){
1334
-
1335
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
1336
-
1337
- if( empty( $versions[$download['slug']] ) ) {
1338
- $v = $this->get_plugin_installed_version($download['name'], $download['slug']);
1339
- if($v){
1340
- $versions[$download['slug']] = $v;
1341
- }
1342
- }
1343
-
1344
- }
1345
-
1346
- }
1347
-
1348
- }
1349
-
1350
- return $versions;
1351
- }
1352
-
1353
- public function get_repository_site_key($repository_id){
1354
- $site_key = false;
1355
-
1356
- if(!empty($this->settings['repositories'][$repository_id]['subscription']['key'])){
1357
- $site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
1358
- }
1359
-
1360
- return $site_key;
1361
- }
1362
-
1363
- public function repository_has_valid_subscription($repository_id){
1364
-
1365
- $valid = false;
1366
-
1367
- if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
1368
-
1369
- $subscription = $this->settings['repositories'][$repository_id]['subscription']['data'];
1370
- $valid = ( $subscription->status == 1 && (strtotime($subscription->expires) > time() || empty($subscription->expires)) ) || $subscription->status == 4;
1371
-
1372
- }
1373
- return $valid;
1374
-
1375
- }
1376
-
1377
- public function repository_has_subscription($repository_id){
1378
- $key = false;
1379
- if(!empty($this->settings['repositories'][$repository_id]['subscription']['key'])){
1380
- $key = $this->settings['repositories'][$repository_id]['subscription']['key'];
1381
- }
1382
-
1383
- return $key;
1384
-
1385
- }
1386
-
1387
- public function repository_has_expired_subscription($repository_id){
1388
-
1389
- return $this->repository_has_subscription($repository_id) && !$this->repository_has_valid_subscription($repository_id);
1390
-
1391
- }
1392
-
1393
- public function get_generic_product_name($repository_id){
1394
-
1395
- return $this->settings['repositories'][$repository_id]['data']['product-name'];
1396
-
1397
- }
1398
-
1399
- public function show_subscription_renew_warning($repository_id, $subscription_id){
1400
-
1401
- $show = false;
1402
-
1403
- $data = $this->settings['repositories'][$repository_id]['data'];
1404
- if(!empty($data['subscriptions_meta'])){
1405
- if(isset($data['subscriptions_meta']['expiration'])){
1406
-
1407
- if(!empty($data['subscriptions_meta']['expiration'][$subscription_id])){
1408
-
1409
- $days = $data['subscriptions_meta']['expiration'][$subscription_id]['days_warning'];
1410
- $message = $data['subscriptions_meta']['expiration'][$subscription_id]['warning_message'];
1411
-
1412
- }else{
1413
-
1414
- //defaults
1415
- $days = 30;
1416
- $message = __('You will have to renew your subscription in order to continue getting the updates and support.', 'installer');
1417
-
1418
- }
1419
-
1420
- if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
1421
- $subscription = $this->settings['repositories'][$repository_id]['subscription'];
1422
-
1423
- if($subscription['data']->subscription_type == $subscription_id && !empty($subscription['data']->expires)){
1424
-
1425
- if(strtotime($subscription['data']->expires) < strtotime(sprintf("+%d day", $days))){
1426
-
1427
- $days_to_expiration = ceil((strtotime($subscription['data']->expires) - time()) / 86400);
1428
-
1429
- echo '<div><p class="installer-warn-box">' .
1430
- sprintf(_n('Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer'), $days_to_expiration) .
1431
- '<br />' . $message .
1432
- '</p></div>';
1433
-
1434
- $show = true;
1435
-
1436
- }
1437
-
1438
- }
1439
-
1440
- }
1441
-
1442
-
1443
- }
1444
- }
1445
-
1446
-
1447
- return $show;
1448
-
1449
- }
1450
-
1451
- public function setup_plugins_renew_warnings(){
1452
-
1453
- $plugins = get_plugins();
1454
-
1455
- $subscriptions_with_warnings = array();
1456
- foreach($this->settings['repositories'] as $repository_id => $repository){
1457
-
1458
- if($this->repository_has_valid_subscription($repository_id)){
1459
- $subscription_type = $this->settings['repositories'][$repository_id]['subscription']['data']->subscription_type;
1460
- $expires = $this->settings['repositories'][$repository_id]['subscription']['data']->expires;
1461
-
1462
- $never_expires = isset($this->settings['repositories'][$repository_id]['subscription'])
1463
- && empty($this->settings['repositories'][$repository_id]['subscription']['data']->expires)
1464
- && (
1465
- $this->settings['repositories'][$repository_id]['subscription']['data']->status == 4 ||
1466
- $this->settings['repositories'][$repository_id]['subscription']['data']->status == 1
1467
- );
1468
-
1469
- if(!$never_expires){
1470
- if(isset($this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type])){
1471
-
1472
- $days_warning = $this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type]['days_warning'];
1473
- $custom_message = $this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type]['warning_message'];
1474
-
1475
- }else{
1476
- //defaults
1477
- $days_warning = 30;
1478
- $custom_message = __('You will have to renew your subscription in order to continue getting the updates and support.', 'installer');
1479
- }
1480
-
1481
- if(strtotime($expires) < strtotime(sprintf('+%d day', $days_warning)) ){
1482
-
1483
- $days_to_expiration = ceil((strtotime($expires) - time()) / 86400);
1484
-
1485
- $message = sprintf(_n('Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer'), $days_to_expiration);
1486
- $subscriptions_with_warnings[$subscription_type] = $message . ' ' . $custom_message;
1487
-
1488
- }
1489
- }
1490
-
1491
- }
1492
-
1493
- }
1494
-
1495
-
1496
-
1497
- foreach($plugins as $plugin_id => $plugin){
1498
-
1499
- $slug = dirname($plugin_id);
1500
- if(empty($slug)) continue;
1501
-
1502
- foreach($this->settings['repositories'] as $repository_id => $repository){
1503
-
1504
- if($this->repository_has_valid_subscription($repository_id)){
1505
-
1506
- foreach($repository['data']['packages'] as $package){
1507
-
1508
- foreach($package['products'] as $product){
1509
-
1510
- foreach($product['plugins'] as $plugin_slug){
1511
-
1512
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
1513
-
1514
- if($download['slug'] == $slug || $download['name'] == $plugin['Name'] || $download['name'] == $plugin['Title']){ //match order: slug, name, title
1515
-
1516
- if(isset($subscriptions_with_warnings[$product['subscription_type']])){
1517
-
1518
- $this->_plugins_renew_warnings[$plugin_id] = $subscriptions_with_warnings[$product['subscription_type']];
1519
-
1520
- }
1521
-
1522
- }
1523
-
1524
- }
1525
-
1526
- }
1527
-
1528
- }
1529
-
1530
- }
1531
-
1532
- }
1533
-
1534
- }
1535
-
1536
- }
1537
-
1538
- public function queue_plugins_renew_warnings() {
1539
-
1540
- if(!empty($this->_plugins_renew_warnings)){
1541
-
1542
- foreach($this->_plugins_renew_warnings as $plugin_id => $message){
1543
-
1544
- add_action( "after_plugin_row_" . $plugin_id, array($this, 'plugins_renew_warning'), 10, 3 );
1545
- }
1546
-
1547
- }
1548
-
1549
- }
1550
-
1551
- public function plugins_renew_warning($plugin_file, $plugin_data, $status){
1552
-
1553
- if(empty($this->_plugins_renew_warnings[$plugin_file])) return;
1554
-
1555
- $wp_list_table = _get_list_table('WP_Plugins_List_Table');
1556
- ?>
1557
-
1558
- <tr class="plugin-update-tr"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
1559
- <div class="update-message">
1560
- <?php
1561
- echo $this->_plugins_renew_warnings[$plugin_file]. ' ';
1562
- printf(__('%sRenew here%s.', 'installer'),
1563
- '<a href="' . $this->menu_url() . '">', '</a>');
1564
- ?>
1565
- </div>
1566
- </tr>
1567
-
1568
- <?php
1569
-
1570
- }
1571
-
1572
- public function get_subscription_type_for_repository($repository_id){
1573
-
1574
- $subscription_type = false;
1575
-
1576
- if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
1577
- $subscription_type = $this->settings['repositories'][$repository_id]['subscription']['data']->subscription_type;
1578
- }
1579
-
1580
- return $subscription_type;
1581
-
1582
- }
1583
-
1584
- public function have_superior_subscription($subscription_type, $product){
1585
-
1586
- $have = false;
1587
-
1588
- if(is_array($product['upgrades'])){
1589
- foreach($product['upgrades'] as $u){
1590
- if($u['subscription_type'] == $subscription_type){
1591
- $have = true;
1592
- break;
1593
- }
1594
- }
1595
- }
1596
-
1597
- return $have;
1598
- }
1599
-
1600
- public function is_product_available_for_download($product_name, $repository_id){
1601
-
1602
- $available = false;
1603
-
1604
- $subscription_type = $this->get_subscription_type_for_repository($repository_id);
1605
- $expired = $this->repository_has_expired_subscription($repository_id);
1606
-
1607
- if($this->repository_has_subscription($repository_id) && !$expired){
1608
-
1609
- $this->set_hierarchy_and_order();
1610
-
1611
- foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package_id => $package){
1612
-
1613
- $has_top_package = false;
1614
-
1615
- foreach($package['products'] as $product){
1616
-
1617
- if($subscription_type == $product['subscription_type']){
1618
- $has_top_package = true;
1619
- if($product['name'] == $product_name){
1620
- return $available = true;
1621
- }
1622
- }
1623
-
1624
- }
1625
-
1626
- if(!empty($package['sub-packages'])){
1627
- foreach($package['sub-packages'] as $sub_package){
1628
- foreach($sub_package['products'] as $product){
1629
- if($product['name'] == $product_name && ($subscription_type == $product['subscription_type'] || $has_top_package)){
1630
- return $available = true;
1631
- }
1632
- }
1633
- }
1634
- }
1635
-
1636
- }
1637
- }
1638
-
1639
- return $available;
1640
-
1641
- }
1642
-
1643
- public function get_upgrade_options($repository_id){
1644
- $all_upgrades = array();
1645
-
1646
-
1647
- //get all products: packages and subpackages
1648
- $all_products = array();
1649
- foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
1650
- foreach($package['products'] as $product) {
1651
- $all_products[] = $product;
1652
- }
1653
- if(!empty($package['sub-packages'])){
1654
- foreach($package['sub-packages'] as $subpackage){
1655
- foreach($subpackage['products'] as $product) {
1656
- $all_products[] = $product;
1657
- }
1658
-
1659
- }
1660
-
1661
- }
1662
-
1663
- }
1664
-
1665
- foreach( $all_products as $product ) {
1666
- if ($product['upgrades']) {
1667
- foreach ($product['upgrades'] as $upgrade) {
1668
- if ($this->repository_has_valid_subscription($repository_id) || ($this->repository_has_subscription($repository_id) && $upgrade['including_expired'])) {
1669
- $all_upgrades[$upgrade['subscription_type']][$product['subscription_type']] = $upgrade;
1670
- }
1671
- }
1672
- }
1673
- }
1674
-
1675
- return $all_upgrades;
1676
-
1677
- }
1678
-
1679
- public function append_site_key_to_download_url($url, $key, $repository_id){
1680
-
1681
- $url_params['site_key'] = $key;
1682
- $url_params['site_url'] = $this->get_installer_site_url( $repository_id );
1683
-
1684
-
1685
- // Add extra parameters for custom Installer packages
1686
- if( !empty($this->package_source) ){
1687
- $extra = $this->get_extra_url_parameters();
1688
- if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
1689
- unset($extra['repository']);
1690
- foreach($extra as $key => $val){
1691
- $url_params[$key] = $val;
1692
- }
1693
- }
1694
- }
1695
-
1696
- $url = add_query_arg($url_params, $url);
1697
-
1698
- if($repository_id == 'wpml'){
1699
- $url = add_query_arg(array('using_icl' => $this->_using_icl, 'wpml_version' => $this->_wpml_version), $url);
1700
- }
1701
-
1702
- return $url;
1703
-
1704
- }
1705
-
1706
- public function plugin_is_installed($name, $slug, $version = null){
1707
-
1708
- $is = false;
1709
-
1710
- $plugins = get_plugins();
1711
-
1712
- foreach($plugins as $plugin_id => $plugin){
1713
-
1714
- $wp_plugin_slug = dirname($plugin_id);
1715
-
1716
- // Exception: embedded plugins
1717
- if( $wp_plugin_slug == $slug || $plugin['Name'] == $name || $plugin['Title'] == $name || ( $wp_plugin_slug == $slug . '-embedded' || $plugin['Name'] == $name . ' Embedded' ) ){
1718
- if($version){
1719
- if(version_compare($plugin['Version'], $version, '>=')){
1720
- $is = $plugin['Version'];
1721
- }
1722
- }else{
1723
- $is = $plugin['Version'];
1724
- }
1725
-
1726
- break;
1727
- }
1728
-
1729
- }
1730
-
1731
- //exception: Types name difference
1732
- if(!$is && $name == 'Types'){
1733
- return $this->plugin_is_installed('Types - Complete Solution for Custom Fields and Types', $slug, $version);
1734
- }
1735
-
1736
- return $is;
1737
- }
1738
-
1739
- public function plugin_is_embedded_version($name, $slug){
1740
- $is = false;
1741
-
1742
- $plugins = get_plugins();
1743
-
1744
- //false if teh full version is also installed
1745
- $is_full_installed = false;
1746
- foreach($plugins as $plugin_id => $plugin){
1747
-
1748
- if(($plugin['Name'] == $name && !preg_match("#-embedded$#", $slug)) ){
1749
- $is_full_installed = true;
1750
- break;
1751
- }
1752
-
1753
- }
1754
-
1755
- if($is_full_installed){
1756
- return false;
1757
- }
1758
-
1759
- foreach($plugins as $plugin_id => $plugin){
1760
-
1761
- // TBD
1762
- $wp_plugin_slug = dirname($plugin_id);
1763
- if( $wp_plugin_slug == $slug . '-embedded' && $plugin['Name'] == $name . ' Embedded'){
1764
- $is = true;
1765
- break;
1766
- }
1767
-
1768
- }
1769
-
1770
- return $is;
1771
-
1772
- }
1773
-
1774
- //Alias for plugin_is_installed
1775
- public function get_plugin_installed_version($name, $slug){
1776
-
1777
- return $this->plugin_is_installed($name, $slug);
1778
-
1779
- }
1780
-
1781
- public function get_plugin_repository_version($repository_id, $slug){
1782
- $version = false;
1783
-
1784
- if(!empty($this->settings['repositories'][$repository_id]['data']['packages'])){
1785
- foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
1786
- foreach($package['products'] as $product) {
1787
-
1788
- foreach($product['plugins'] as $plugin_slug){
1789
-
1790
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
1791
-
1792
- if($download['slug'] == $slug){
1793
- $version = $download['version'];
1794
- break (3);
1795
- }
1796
-
1797
- }
1798
-
1799
- }
1800
- }
1801
- }
1802
-
1803
- return $version;
1804
- }
1805
-
1806
- public function is_uploading_allowed(){
1807
-
1808
- //_deprecated_function ( __FUNCTION__, '1.7.3', 'Installer_Dependencies::' . __FUNCTION__ );
1809
- return $this->dependencies->is_uploading_allowed();
1810
-
1811
- }
1812
-
1813
- public function download_plugin_ajax_handler(){
1814
-
1815
- require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1816
- require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php';
1817
-
1818
- $data = json_decode( base64_decode( sanitize_text_field ( $_POST['data'] ) ), true );
1819
-
1820
- $ret = false;
1821
- $plugin_id = false;
1822
- $message = '';
1823
-
1824
- //validate subscription
1825
- $site_key = $this->get_repository_site_key($data['repository_id']);
1826
- $subscription_data = $this->fetch_subscription_data( $data['repository_id'], $site_key , self::SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT);
1827
-
1828
- if($subscription_data && !is_wp_error($subscription_data) && $this->repository_has_valid_subscription($data['repository_id'])){
1829
-
1830
- if($data['nonce'] == wp_create_nonce('install_plugin_' . $data['url'])){
1831
-
1832
- $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
1833
- $upgrader = new Plugin_Upgrader($upgrader_skins);
1834
-
1835
- remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
1836
-
1837
- $plugins = get_plugins();
1838
-
1839
- //upgrade or install?
1840
- foreach($plugins as $id => $plugin){
1841
- $wp_plugin_slug = dirname($id);
1842
- $is_embedded = $this->plugin_is_embedded_version(preg_replace('/ Embedded$/', '', $plugin['Name']), preg_replace('/-embedded$/', '', $wp_plugin_slug));
1843
-
1844
- if($wp_plugin_slug == $data['slug'] || $is_embedded && preg_replace('/-embedded$/', '', $wp_plugin_slug) == $data['slug']){
1845
- $plugin_id = $id;
1846
- break;
1847
- }
1848
- }
1849
-
1850
- if($plugin_id && empty($is_embedded)){ //upgrade
1851
- $response['upgrade'] = 1;
1852
-
1853
- $plugin_is_active = is_plugin_active($plugin_id);
1854
-
1855
- $ret = $upgrader->upgrade($plugin_id);
1856
-
1857
- if(!$ret && !empty($upgrader->skin->installer_error)){
1858
- if(is_wp_error($upgrader->skin->installer_error)){
1859
- $message = $upgrader->skin->installer_error->get_error_message() .
1860
- ' (' . $upgrader->skin->installer_error->get_error_data() . ')';
1861
- }
1862
- }
1863
-
1864
- if($plugin_is_active){
1865
- //prevent redirects
1866
- add_filter('wp_redirect', '__return_false');
1867
- activate_plugin($plugin_id);
1868
- }
1869
-
1870
- }else{ //install
1871
-
1872
- if($is_embedded){
1873
- delete_plugins(array($plugin_id));
1874
- }
1875
-
1876
- $response['install'] = 1;
1877
- $ret = $upgrader->install($data['url']);
1878
- if(!$ret && !empty($upgrader->skin->installer_error)){
1879
- if(is_wp_error($upgrader->skin->installer_error)){
1880
- $message = $upgrader->skin->installer_error->get_error_message() .
1881
- ' (' . $upgrader->skin->installer_error->get_error_data() . ')';
1882
- }
1883
- }
1884
- }
1885
-
1886
- $plugins = get_plugins(); //read again
1887
-
1888
- if($ret && !empty($_POST['activate'])){
1889
- foreach($plugins as $id => $plugin){
1890
- $wp_plugin_slug = dirname($id);
1891
- if($wp_plugin_slug == $data['slug']){
1892
- $plugin_version = $plugin['Version'];
1893
- $plugin_id = $id;
1894
- break;
1895
- }
1896
- }
1897
-
1898
- }
1899
-
1900
- }
1901
-
1902
- } else { //subscription not valid
1903
-
1904
- $ret = false;
1905
- $message = __('Your subscription appears to no longer be valid. Please try to register again using a valid site key.', 'installer');
1906
- }
1907
-
1908
- $response['version'] = isset($plugin_version) ? $plugin_version : 0;
1909
- $response['plugin_id'] = $plugin_id;
1910
- $response['nonce'] = wp_create_nonce('activate_' . $plugin_id);
1911
- $response['success'] = $ret;
1912
- $response['message'] = $message;
1913
-
1914
- echo json_encode( $response );
1915
- exit;
1916
-
1917
- }
1918
-
1919
- public function download_plugin($slug, $url){
1920
-
1921
- require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1922
- require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php';
1923
-
1924
- $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
1925
- $upgrader = new Plugin_Upgrader($upgrader_skins);
1926
-
1927
- remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
1928
-
1929
- $plugins = get_plugins();
1930
-
1931
- $plugin_id = false;
1932
-
1933
- //upgrade or install?
1934
- foreach($plugins as $id => $plugin){
1935
- $wp_plugin_slug = dirname($id);
1936
- if($wp_plugin_slug == $slug){
1937
- $plugin_id = $id;
1938
- break;
1939
- }
1940
- }
1941
-
1942
- if($plugin_id){ //upgrade
1943
-
1944
- $plugin_is_active = is_plugin_active($plugin_id);
1945
-
1946
- $ret = $upgrader->upgrade($plugin_id);
1947
-
1948
- if($plugin_is_active){
1949
- activate_plugin($plugin_id);
1950
- }
1951
-
1952
- }else{ //install
1953
- $ret = $upgrader->install($url);
1954
- }
1955
-
1956
- return $ret;
1957
-
1958
- }
1959
-
1960
- public function activate_plugin(){
1961
-
1962
- $error = '';
1963
-
1964
- $plugin_id = sanitize_text_field ( $_POST['plugin_id'] );
1965
- if(isset($_POST['nonce']) && $plugin_id && $_POST['nonce'] == wp_create_nonce('activate_' . $plugin_id )){
1966
-
1967
- // Deactivate any embedded version
1968
- $plugin_slug = dirname($plugin_id);
1969
- $active_plugins = get_option('active_plugins');
1970
- foreach($active_plugins as $plugin){
1971
- $wp_plugin_slug = dirname($plugin);
1972
- if($wp_plugin_slug == $plugin_slug . '-embedded'){
1973
- deactivate_plugins(array($plugin));
1974
- break;
1975
- }
1976
- }
1977
-
1978
- //prevent redirects
1979
- add_filter('wp_redirect', '__return_false', 10000);
1980
-
1981
- $return = activate_plugin($plugin_id);
1982
-
1983
- if(is_wp_error($return)){
1984
- $error = $return->get_error_message();
1985
- }
1986
-
1987
- }else{
1988
- $error = 'error';
1989
- }
1990
-
1991
- $ret = array('error' => $error);
1992
-
1993
- echo json_encode($ret);
1994
- exit;
1995
-
1996
- }
1997
-
1998
- public function custom_plugins_api_call($false, $action, $args){
1999
-
2000
- if($action == 'plugin_information'){
2001
-
2002
- $plugins = get_plugins();
2003
- $plugin_names = array();
2004
- foreach( $plugins as $plugin_id => $plugin ) {
2005
- // plugins by WP slug which (plugin folder) which can be different
2006
- // will use this to compare by title
2007
- $plugin_names[ dirname( $plugin_id ) ] = array(
2008
- 'name' => $plugin['Name'],
2009
- 'title' => $plugin['Title'],
2010
- );
2011
- }
2012
-
2013
- $slug = $args->slug;
2014
-
2015
- foreach($this->settings['repositories'] as $repository_id => $repository){
2016
-
2017
- if(!$this->repository_has_valid_subscription($repository_id)){
2018
- $site_key = false;
2019
- }else{
2020
- $site_key = $repository['subscription']['key'];
2021
- }
2022
-
2023
- foreach($repository['data']['packages'] as $package){
2024
-
2025
- foreach($package['products'] as $product){
2026
-
2027
- foreach($product['plugins'] as $plugin_slug){
2028
-
2029
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
2030
-
2031
- if( $download['slug'] == $slug ||
2032
- isset( $plugin_names[$slug] ) && (
2033
- $plugin_names[$slug]['name'] == $download['name'] ||
2034
- $plugin_names[$slug]['title'] == $download['name']
2035
- )
2036
- ){
2037
-
2038
- if( !empty( $download['free-on-wporg'] ) ){
2039
- return false; // use data from wordpress.org
2040
- }
2041
-
2042
- $res = new stdClass();
2043
- $res->external = true;
2044
-
2045
- $res->name = $download['name'];
2046
- $res->slug = $slug;
2047
- $res->version = $download['version'];
2048
- $res->author = '';
2049
- $res->author_profile = '';
2050
- $res->last_updated = $download['date'];
2051
-
2052
- if($site_key){
2053
- $res->download_link = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
2054
- }
2055
-
2056
- $res->homepage = $repository['data']['url'];
2057
- $res->sections = array('Description' => $download['description'], 'Changelog' => $download['changelog']);
2058
-
2059
- return $res;
2060
-
2061
- }
2062
-
2063
- }
2064
-
2065
- }
2066
-
2067
- }
2068
-
2069
- }
2070
-
2071
- }
2072
-
2073
- return $false;
2074
-
2075
- }
2076
-
2077
- public function plugins_upgrade_check($update_plugins){
2078
-
2079
- if(!empty($this->settings['repositories'])){
2080
-
2081
- $plugins = get_plugins();
2082
-
2083
- foreach($plugins as $plugin_id => $plugin){
2084
-
2085
- $slug = dirname($plugin_id);
2086
- if(empty($slug)) continue;
2087
-
2088
- $version = $plugin['Version'];
2089
- $name = $plugin['Name'];
2090
-
2091
- foreach($this->settings['repositories'] as $repository_id => $repository){
2092
-
2093
-
2094
- if(!$this->repository_has_valid_subscription($repository_id)){
2095
- $site_key = false;
2096
- }else{
2097
- $site_key = $repository['subscription']['key'];
2098
- //$subscription_type = $this->get_subscription_type_for_repository($repository_id);
2099
- }
2100
-
2101
- foreach($repository['data']['packages'] as $package){
2102
-
2103
- foreach($package['products'] as $product){
2104
-
2105
- foreach($product['plugins'] as $plugin_slug){
2106
-
2107
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
2108
-
2109
- if(!empty($download['free-on-wporg'])) {
2110
- continue;
2111
- }
2112
-
2113
- if(empty($update_plugins->response[$plugin_id]) && ($download['slug'] == $slug || $download['name'] == $name ) && version_compare($download['version'], $version, '>')){
2114
-
2115
- $response = new stdClass();
2116
- $response->id = 0;
2117
- $response->slug = $slug;
2118
- $response->plugin = $plugin_id;
2119
- $response->new_version = $download['version'];
2120
- $response->upgrade_notice = '';
2121
- $response->url = $download['url'];
2122
- if($site_key){
2123
- $response->package = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
2124
- }
2125
- $update_plugins->checked[$plugin_id] = $version;
2126
- $update_plugins->response[$plugin_id] = $response;
2127
-
2128
- }
2129
-
2130
- }
2131
-
2132
- }
2133
-
2134
- }
2135
-
2136
- }
2137
-
2138
- }
2139
-
2140
- }
2141
-
2142
- return $update_plugins;
2143
-
2144
- }
2145
-
2146
- public function setup_plugins_page_notices(){
2147
-
2148
- $plugins = get_plugins();
2149
-
2150
- foreach($plugins as $plugin_id => $plugin){
2151
-
2152
- $slug = dirname($plugin_id);
2153
- if(empty($slug)) continue;
2154
-
2155
- $name = $plugin['Name'];
2156
-
2157
- foreach($this->settings['repositories'] as $repository_id => $repository){
2158
-
2159
- if(!$this->repository_has_valid_subscription($repository_id)){
2160
- $site_key = false;
2161
- }else{
2162
- $site_key = $repository['subscription']['key'];
2163
- }
2164
-
2165
- foreach($repository['data']['packages'] as $package){
2166
-
2167
- foreach($package['products'] as $product){
2168
-
2169
- foreach($product['plugins'] as $plugin_slug){
2170
-
2171
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
2172
-
2173
- if(!empty($download['free-on-wporg'])) {
2174
- continue;
2175
- }
2176
-
2177
- if( $download['slug'] == $slug || $download['name'] == $name ){
2178
-
2179
- if( !$site_key || !$this->plugin_is_registered($repository_id, $download['slug']) ){
2180
- add_action( "after_plugin_row_" . $plugin_id, array($this, 'show_purchase_notice_under_plugin'), 10, 3 );
2181
- }
2182
-
2183
- }
2184
-
2185
- }
2186
-
2187
- }
2188
-
2189
- }
2190
-
2191
- }
2192
-
2193
- }
2194
-
2195
- }
2196
-
2197
- public function show_purchase_notice_under_plugin($plugin_file, $plugin_data, $status){
2198
-
2199
- $wp_list_table = _get_list_table('WP_Plugins_List_Table');
2200
- $wp_version = preg_replace( '/-(.+)$/', '', $GLOBALS['wp_version'] );
2201
-
2202
- if( version_compare( $wp_version, '4.6', '>=' ) ){
2203
-
2204
- ?>
2205
- <tr class="plugin-update-tr installer-plugin-update-tr">
2206
- <td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
2207
- <div class="notice inline notice-warning notice-alt">
2208
- <p class="installer-q-icon">
2209
- <?php printf( __('You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer'),
2210
- '<a href="' . $this->menu_url() . '">', '</a>'); ?>
2211
- </p>
2212
- </div>
2213
- </td>
2214
- </tr>
2215
- <?php
2216
-
2217
- } else {
2218
-
2219
- ?>
2220
- <tr class="plugin-update-tr">
2221
- <td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
2222
- <div class="update-message installer-q-icon">
2223
- <?php printf( __('You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer'),
2224
- '<a href="' . $this->menu_url() . '">', '</a>'); ?>
2225
- </div>
2226
- </td>
2227
- </tr>
2228
- <?php
2229
-
2230
- }
2231
-
2232
- }
2233
-
2234
- public function localize_strings(){
2235
-
2236
- if(!empty($this->settings['repositories'])){
2237
- foreach($this->settings['repositories'] as $repository_id => $repository){
2238
- //set name as call2action when don't have any
2239
- //products
2240
- foreach($repository['data']['packages'] as $package_id => $package){
2241
- foreach($package['products'] as $product_id => $product){
2242
- if(empty($product['call2action'])){
2243
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['call2action'] = $product['name'];
2244
- }
2245
-
2246
- foreach($product['upgrades'] as $idx => $upg){
2247
- if(empty($upg['call2action'])){
2248
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$idx]['call2action'] = $upg['name'];
2249
- }
2250
- }
2251
-
2252
- foreach($product['renewals'] as $idx => $rnw){
2253
- if(empty($rnw['call2action'])){
2254
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['renewals'][$idx]['call2action'] = $rnw['name'];
2255
- }
2256
-
2257
- }
2258
-
2259
- }
2260
- }
2261
- }
2262
- }
2263
-
2264
- global $sitepress;
2265
- if(is_null($sitepress)){
2266
- return;
2267
- }
2268
-
2269
- // default strings are always in English
2270
- $user_admin_language = $sitepress->get_admin_language();
2271
-
2272
- if($user_admin_language != 'en'){
2273
- foreach($this->settings['repositories'] as $repository_id => $repository){
2274
-
2275
- $localization = $repository['data']['localization'];
2276
-
2277
- //packages
2278
- foreach($repository['data']['packages'] as $package_id => $package){
2279
-
2280
- if( isset($localization['packages'][$package_id]['name'][$user_admin_language]) ){
2281
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['name'] = $localization['packages'][$package_id]['name'][$user_admin_language];
2282
- }
2283
- if( isset($localization['packages'][$package_id]['description'][$user_admin_language]) ){
2284
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['description'] = $localization['packages'][$package_id]['description'][$user_admin_language];
2285
- }
2286
-
2287
- }
2288
-
2289
- //products
2290
- foreach($repository['data']['packages'] as $package_id => $package){
2291
- foreach($package['products'] as $product_id => $product){
2292
-
2293
- if( isset($localization['products'][$product_id]['name'][$user_admin_language]) ){
2294
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['name']
2295
- = $localization['products'][$product_id]['name'][$user_admin_language];
2296
- }
2297
- if( isset($localization['products'][$product_id]['description'][$user_admin_language]) ){
2298
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['description']
2299
- = $localization['products'][$product_id]['description'][$user_admin_language];
2300
- }
2301
- if( isset($localization['products'][$product_id]['call2action'][$user_admin_language]) ){
2302
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['name']
2303
- = $localization['products'][$product_id]['call2action'][$user_admin_language];
2304
- }
2305
-
2306
-
2307
- }
2308
- }
2309
-
2310
- //subscription info
2311
- if(isset($repository['data']['subscriptions_meta']['expiration'])){
2312
- foreach($repository['data']['subscriptions_meta']['expiration'] as $subscription_id => $note){
2313
- if(isset($localization['subscriptions-notes'][$subscription_id]['expiration-warning'][$user_admin_language])){
2314
- $this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_id]['warning_message']
2315
- = $localization['subscriptions-notes'][$subscription_id]['expiration-warning'][$user_admin_language];
2316
- }
2317
- }
2318
- }
2319
-
2320
- }
2321
- }
2322
-
2323
- }
2324
-
2325
- public function get_matching_cp($repository, $args = array()){
2326
- $match = false;
2327
-
2328
-
2329
- $cp_name = $cp_author = false;
2330
-
2331
- if(isset($this->config['src_name']) && isset($this->config['src_author'])){
2332
-
2333
- $cp_name = $this->config['src_name'];
2334
- $cp_author = $this->config['src_author'];
2335
-
2336
- }elseif(isset($args['src_name']) && isset($args['src_author'])){
2337
-
2338
- $cp_name = $args['src_name'];
2339
- $cp_author = $args['src_author'];
2340
-
2341
- }
2342
-
2343
- if(isset($repository['data']['marketing_cp'])){
2344
-
2345
- foreach($repository['data']['marketing_cp'] as $cp){
2346
-
2347
- if(!empty($cp['exp']) && time() > $cp['exp']){
2348
- continue;
2349
- }
2350
-
2351
- //Use theme_name for plugins too
2352
- if(!empty($cp['theme_name'])){
2353
- if($cp['author_name'] == $cp_author && $cp['theme_name'] == $cp_name){
2354
- $match = $cp;
2355
- continue;
2356
- }
2357
- }else{
2358
- if($cp['author_name'] == $cp_author){
2359
- $match = $cp;
2360
- continue;
2361
- }
2362
- }
2363
-
2364
- }
2365
-
2366
- }
2367
-
2368
- return $match;
2369
- }
2370
-
2371
- public function set_filtered_prices($args = array()){
2372
-
2373
- foreach($this->settings['repositories'] as $repository_id => $repository){
2374
-
2375
- $match = $this->get_matching_cp($repository, $args);
2376
-
2377
- if(empty($match)) continue;
2378
-
2379
- foreach($repository['data']['packages'] as $package_id => $package){
2380
-
2381
- foreach($package['products'] as $product_id => $product){
2382
-
2383
- if($match['dtp'] == '%'){
2384
- $fprice = round( $product['price'] * (1 - $match['amt']/100), 2 );
2385
- $fprice = $fprice != round($fprice) ? sprintf('%.2f', $fprice) : round($fprice, 0);
2386
- }elseif($match['dtp'] == '-'){
2387
- $fprice = $product['price'] - $match['amt'];
2388
- }else{
2389
- $fprice = $product['price'];
2390
- }
2391
-
2392
- if($fprice){
2393
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['price_disc'] = $fprice;
2394
-
2395
- $url_glue = false !== strpos($this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['url'], '?') ? '&' : '?';
2396
- $cpndata = base64_encode(json_encode(array('theme_author' => $match['author_name'], 'theme_name' => $match['theme_name'], 'vlc' => $match['vlc'])));
2397
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['url'] .= $url_glue . 'cpn=' . $cpndata;
2398
-
2399
- foreach($product['upgrades'] as $upgrade_id => $upgrade){
2400
-
2401
- $fprice = false;
2402
- if($match['dtp'] == '%'){
2403
- $fprice = round( $upgrade['price'] * (1 - $match['amt']/100), 2 );
2404
- $fprice = $fprice != round($fprice) ? sprintf('%.2f', $fprice) : round($fprice, 0);
2405
- }elseif($match['dtp'] == '-'){
2406
- $fprice = $upgrade['price'] - $match['amt'];
2407
- }
2408
- if($fprice){
2409
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$upgrade_id]['price_disc'] = $fprice;
2410
- $this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$upgrade_id]['url'] .= $url_glue . 'cpn=' . $cpndata;
2411
- }
2412
-
2413
-
2414
- }
2415
-
2416
- }
2417
-
2418
- }
2419
-
2420
- }
2421
-
2422
- }
2423
-
2424
- }
2425
-
2426
- public function set_hierarchy_and_order(){
2427
-
2428
- //2 levels
2429
- if(!empty($this->settings['repositories'])) {
2430
- foreach ($this->settings['repositories'] as $repository_id => $repository) {
2431
-
2432
- if( empty( $repository['data']['packages'] ) ) continue;
2433
-
2434
- $all_packages = $repository['data']['packages'];
2435
- $ordered_packages = array();
2436
-
2437
- //backward compatibility - 'order'
2438
- foreach($all_packages as $k => $v){
2439
- if(!isset($v['order'])){
2440
- $all_packages[$k]['order'] = 0;
2441
- }
2442
- }
2443
-
2444
- //select parents
2445
- foreach ($all_packages as $package_id => $package) {
2446
- if(empty($package['parent'])){
2447
- $ordered_packages[$package_id] = $package;
2448
- }
2449
- }
2450
-
2451
- //add sub-packages
2452
- foreach($all_packages as $package_id => $package){
2453
- if(!empty($package['parent'])) {
2454
- if(isset($ordered_packages[$package['parent']])){
2455
- $ordered_packages[$package['parent']]['sub-packages'][$package_id] = $package;
2456
- }
2457
- }
2458
- }
2459
-
2460
- // order parents
2461
- usort($ordered_packages, array($this, '_order_packages_callback'));
2462
- //order sub-packages
2463
- foreach($ordered_packages as $package_id => $package){
2464
- if(!empty($package['sub-packages'])) {
2465
- usort($ordered_packages[$package_id]['sub-packages'], create_function('$a, $b', 'return $a[\'order\'] > $b[\'order\'];'));
2466
- }
2467
- }
2468
-
2469
- $this->settings['repositories'][$repository_id]['data']['packages'] = $ordered_packages;
2470
-
2471
-
2472
- }
2473
- }
2474
-
2475
-
2476
- }
2477
-
2478
- public function _order_packages_callback($a, $b){
2479
- return $a['order'] > $b['order'];
2480
- }
2481
-
2482
- public function get_support_tag_by_name( $name, $repository ){
2483
-
2484
- if( is_array($this->settings['repositories'][$repository]['data']['support_tags'] )){
2485
- foreach( $this->settings['repositories'][$repository]['data']['support_tags'] as $support_tag){
2486
- if( $support_tag['name'] == $name ){
2487
- return $support_tag['url'];
2488
- }
2489
- }
2490
- }
2491
-
2492
- return false;
2493
- }
2494
-
2495
- public function plugin_upgrade_custom_errors(){
2496
-
2497
- if ( isset($_REQUEST['action']) ) {
2498
-
2499
- $action = isset($_REQUEST['action']) ? sanitize_text_field ( $_REQUEST['action'] ) : '';
2500
-
2501
- //bulk mode
2502
- if('update-selected' == $action) {
2503
-
2504
- global $plugins;
2505
-
2506
- if(isset($plugins) && is_array($plugins)) {
2507
-
2508
- foreach ($plugins as $k => $plugin) {
2509
- $plugin_repository = false;
2510
-
2511
- $wp_plugin_slug = dirname($plugin);
2512
-
2513
- foreach ($this->settings['repositories'] as $repository_id => $repository) {
2514
-
2515
- foreach ($repository['data']['packages'] as $package) {
2516
-
2517
- foreach ($package['products'] as $product) {
2518
-
2519
- foreach ($product['plugins'] as $plugin_slug) {
2520
-
2521
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
2522
-
2523
- if ($download['slug'] == $wp_plugin_slug) {
2524
- $plugin_repository = $repository_id;
2525
- $product_name = $repository['data']['product-name'];
2526
- $plugin_name = $download['name'];
2527
- $free_on_wporg = !empty($download['free-on-wporg']);
2528
- break;
2529
- }
2530
-
2531
- }
2532
-
2533
- }
2534
-
2535
- }
2536
-
2537
- }
2538
-
2539
- if ($plugin_repository) {
2540
-
2541
- //validate subscription
2542
- static $sub_cache = array();
2543
-
2544
- if(empty($sub_cache[$plugin_repository])){
2545
- $site_key = $this->get_repository_site_key($plugin_repository);
2546
- if ($site_key) {
2547
- $subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
2548
- }
2549
-
2550
- $sub_cache[$plugin_repository]['site_key'] = $site_key;
2551
- $sub_cache[$plugin_repository]['subscription_data'] = isset($subscription_data) ? $subscription_data : false;
2552
- }else{
2553
-
2554
- $site_key = $sub_cache[$plugin_repository]['site_key'];
2555
- $subscription_data = $sub_cache[$plugin_repository]['subscription_data'];
2556
-
2557
- }
2558
-
2559
- if(!$site_key && !empty($free_on_wporg)){ // allow the download from wp.org
2560
- continue;
2561
- }
2562
-
2563
- if (empty($site_key) || empty($subscription_data)) {
2564
-
2565
-
2566
- $error_message = sprintf(__("%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer'),
2567
- '<strong>' . $plugin_name . '</strong>', '<a target="_top" href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
2568
- '#repository-' . $plugin_repository . '">', $product_name, '</a>');
2569
-
2570
- echo '<div class="updated error"><p>' . $error_message . '</p></div>';
2571
-
2572
- unset($plugins[$k]);
2573
-
2574
-
2575
- }
2576
-
2577
- }
2578
-
2579
- }
2580
-
2581
- }
2582
-
2583
- }
2584
-
2585
-
2586
- if( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
2587
-
2588
- $plugin = isset($_REQUEST['plugin']) ? trim( sanitize_text_field ( $_REQUEST['plugin'] ) ) : '';
2589
-
2590
- $wp_plugin_slug = dirname($plugin);
2591
-
2592
- $plugin_repository = false;
2593
-
2594
- foreach($this->settings['repositories'] as $repository_id => $repository){
2595
-
2596
- foreach($repository['data']['packages'] as $package){
2597
-
2598
- foreach($package['products'] as $product){
2599
-
2600
- foreach($product['plugins'] as $plugin_slug){
2601
- $download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
2602
-
2603
- //match by folder, will change to match by name and folder
2604
- if($download['slug'] == $wp_plugin_slug) {
2605
- $plugin_repository = $repository_id;
2606
- $product_name = $repository['data']['product-name'];
2607
- $plugin_name = $download['name'];
2608
- $free_on_wporg = !empty($download['free-on-wporg']);
2609
- break;
2610
- }
2611
-
2612
- }
2613
-
2614
- }
2615
-
2616
- }
2617
-
2618
- }
2619
-
2620
- if($plugin_repository) {
2621
-
2622
- //validate subscription
2623
- $site_key = $this->get_repository_site_key($plugin_repository);
2624
- if ($site_key) {
2625
- $subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
2626
- }
2627
-
2628
- if ( (empty($site_key) || empty($subscription_data)) && empty($free_on_wporg)) {
2629
-
2630
- $error_message = sprintf(__("%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer'),
2631
- '<strong>'.$plugin_name . '</strong>', '<a href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
2632
- '#repository-' . $plugin_repository . '">', $product_name, '</a>');
2633
-
2634
- if(defined('DOING_AJAX')){ //WP 4.2
2635
-
2636
- $status = array(
2637
- 'update' => 'plugin',
2638
- 'plugin' => $plugin,
2639
- 'slug' => sanitize_key( $_POST['slug'] ),
2640
- 'oldVersion' => '',
2641
- 'newVersion' => '',
2642
- );
2643
-
2644
- $status['errorCode'] = 'wp_installer_invalid_subscription';
2645
- $status['error'] = $error_message;
2646
-
2647
- wp_send_json_error( $status );
2648
-
2649
- } else { // WP 4.1.1
2650
- echo '<div class="updated error"><p>' . $error_message . '</p></div>';
2651
-
2652
-
2653
- echo '<div class="wrap">';
2654
- echo '<h2>' . __( 'Update Plugin', 'installer' ) . '</h2>';
2655
- echo '<a href="' . admin_url('plugins.php') . '">' . __( 'Return to the plugins page', 'installer' ) . '</a>';
2656
- echo '</div>';
2657
- require_once(ABSPATH . 'wp-admin/admin-footer.php');
2658
- exit;
2659
-
2660
- }
2661
-
2662
- }
2663
-
2664
-
2665
- }
2666
-
2667
- }
2668
- }
2669
-
2670
- }
2671
-
2672
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/otgs/installer/includes/translation-service-info.class.php DELETED
@@ -1,40 +0,0 @@
1
- <?php
2
-
3
- class TranslationServiceInfo{
4
-
5
- function __construct(){
6
-
7
- add_action('installer_fetched_subscription_data',array($this, 'save_info'), 10, 2);
8
-
9
- }
10
-
11
- function save_info($data, $repository_id) {
12
-
13
- $ts_info = isset( WP_Installer()->settings['repositories'][$repository_id]['ts_info'] ) ?
14
- WP_Installer()->settings['repositories'][$repository_id]['ts_info'] : false;
15
-
16
- $save_settings = false;
17
- if(isset($data->ts_info['preferred']) && empty($ts_info['preferred'])){
18
- WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] = $data->ts_info['preferred'];
19
- $save_settings = true;
20
- }
21
-
22
- if(isset($data->ts_info['referal']) && empty($ts_info['referal'])){
23
- WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'] = $data->ts_info['referal'];
24
- $save_settings = true;
25
- }
26
-
27
- if ( !empty( $data->ts_info['client_id'] ) ) { // can be updated
28
- WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'] = $data->ts_info['client_id'];
29
- $save_settings = true;
30
- }
31
-
32
- if($save_settings){
33
- WP_Installer()->save_settings();
34
- }
35
-
36
- }
37
-
38
- }
39
-
40
- new TranslationServiceInfo();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/otgs/installer/installer.php CHANGED
@@ -1,18 +1,18 @@
1
- <?php
2
- define( 'WP_INSTALLER_VERSION', '1.8' );
3
-
4
- include_once dirname( __FILE__ ) . '/includes/functions-core.php';
5
- include_once dirname( __FILE__ ) . '/includes/class-wp-installer.php';
6
-
7
- include_once WP_Installer()->plugin_path() . '/includes/class-wp-installer-api.php';
8
- include_once WP_Installer()->plugin_path() . '/includes/class-translation-service-info.php';
9
- include_once WP_Installer()->plugin_path() . '/includes/class-installer-dependencies.php';
10
- include_once WP_Installer()->plugin_path() . '/includes/class-wp-installer-channels.php';
11
-
12
- include_once WP_Installer()->plugin_path() . '/includes/functions-templates.php';
13
-
14
- // Initialization
15
- WP_Installer();
16
- WP_Installer_Channels();
17
-
18
-
1
+ <?php
2
+ define( 'WP_INSTALLER_VERSION', '1.8.2' );
3
+
4
+ include_once dirname( __FILE__ ) . '/includes/functions-core.php';
5
+ include_once dirname( __FILE__ ) . '/includes/class-wp-installer.php';
6
+
7
+ include_once WP_Installer()->plugin_path() . '/includes/class-wp-installer-api.php';
8
+ include_once WP_Installer()->plugin_path() . '/includes/class-translation-service-info.php';
9
+ include_once WP_Installer()->plugin_path() . '/includes/class-installer-dependencies.php';
10
+ include_once WP_Installer()->plugin_path() . '/includes/class-wp-installer-channels.php';
11
+
12
+ include_once WP_Installer()->plugin_path() . '/includes/functions-templates.php';
13
+
14
+ // Initialization
15
+ WP_Installer();
16
+ WP_Installer_Channels();
17
+
18
+
vendor/otgs/installer/loader.php CHANGED
@@ -1,151 +1,151 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly
5
- }
6
-
7
- //It should only be loaded on the admin side
8
- if( !is_admin() ){
9
- if(!function_exists('WP_Installer_Setup')){ function WP_Installer_Setup(){} }
10
- $wp_installer_instance = null;
11
- return;
12
- }
13
-
14
-
15
- $wp_installer_instance = dirname(__FILE__) . '/installer.php';
16
-
17
-
18
- // Global stack of instances
19
- global $wp_installer_instances;
20
- $wp_installer_instances[$wp_installer_instance] = array(
21
- 'bootfile' => $wp_installer_instance,
22
- 'version' => '1.8'
23
- );
24
-
25
-
26
- /* EXCEPTIONS ********************************************************************************************/
27
- // Exception: When WPML prior 3.2 is used, that instance must be used regardless of another newer instance
28
- // Case 1: WPML loaded before Types - eliminate other instances
29
- if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<') ) {
30
- foreach($wp_installer_instances as $key => $instance) {
31
- if(isset($instance['args']['site_key_nags'])){
32
- $wp_installer_instances[$key]['version'] = '9.9';
33
- }else{
34
- $wp_installer_instances[$key]['version'] = '0';
35
- }
36
- }
37
- }
38
-
39
- // Exception: Types 1.8.9 (Installer 1.7.0) with WPML before 3.3 (Installer before 1.7.0)
40
- // New products file http://d2salfytceyqoe.cloudfront.net/wpml-products33.json overrides the old one
41
- // while the WPML's instance is being used
42
- // => Force using the new Installer Instance
43
- if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.3.1', '<') ) {
44
-
45
- // if Installer 1.7.0+ is present, unregister Installer from old WPML
46
- // Force Installer 1.7.0+ being used over older Installer versions
47
- $installer_171_plus_on = false;
48
- foreach($wp_installer_instances as $key => $instance) {
49
- if( version_compare( $instance['version'], '1.7.1', '>=' ) ){
50
- $installer_171_plus_on = true;
51
- break;
52
- }
53
- }
54
-
55
- if( $installer_171_plus_on ){
56
- foreach($wp_installer_instances as $key => $instance) {
57
-
58
- if( version_compare( $instance['version'], '1.7.0', '<' ) ){
59
- unset( $wp_installer_instances[$key] );
60
- }
61
-
62
- }
63
- }
64
-
65
- }
66
-
67
- // Exception: When using the embedded plugins module allow the set up to run completely with the
68
- // Installer instance that triggers it
69
- if( isset( $_POST['installer_instance'] ) && isset( $wp_installer_instances[$_POST['installer_instance']] ) ){
70
- $wp_installer_instances[$_POST['installer_instance']]['version'] = '999';
71
- }
72
- /* EXCEPTIONS ********************************************************************************************/
73
-
74
-
75
- // Only one of these in the end
76
- remove_action('after_setup_theme', 'wpml_installer_instance_delegator', 1);
77
- add_action('after_setup_theme', 'wpml_installer_instance_delegator', 1);
78
-
79
- // When all plugins load pick the newest version
80
- if(!function_exists('wpml_installer_instance_delegator')){
81
- function wpml_installer_instance_delegator(){
82
- global $wp_installer_instances;
83
-
84
- // version based election
85
- foreach($wp_installer_instances as $instance){
86
-
87
- if(!isset($delegate)){
88
- $delegate = $instance;
89
- continue;
90
- }
91
-
92
- if(version_compare($instance['version'], $delegate['version'], '>')){
93
- $delegate = $instance;
94
- }
95
- }
96
-
97
- // priority based election
98
- $highest_priority = null;
99
- foreach($wp_installer_instances as $instance) {
100
- if(isset($instance['args']['high_priority'])){
101
- if(is_null($highest_priority) || $instance['args']['high_priority'] <= $highest_priority){
102
- $highest_priority = $instance['args']['high_priority'];
103
- $delegate = $instance;
104
- }
105
- }
106
- }
107
-
108
- // Exception: When WPML prior 3.2 is used, that instance must be used regardless of another newer instance
109
- // Case 2: WPML loaded after Types
110
- if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<') ) {
111
- foreach($wp_installer_instances as $key => $instance) {
112
- if(isset($instance['args']['site_key_nags'])){
113
- $delegate = $instance;
114
- $wp_installer_instances = array($key => $delegate); //Eliminate other instances
115
- break;
116
- }
117
- }
118
- }
119
-
120
- include_once $delegate['bootfile'];
121
-
122
- // set configuration
123
- if(strpos(realpath($delegate['bootfile']), realpath(TEMPLATEPATH)) === 0){
124
- $delegate['args']['in_theme_folder'] = dirname(ltrim(str_replace(realpath(TEMPLATEPATH), '', realpath($delegate['bootfile'])), '\\/'));
125
- }
126
- if(isset($delegate['args']) && is_array($delegate['args'])){
127
- foreach($delegate['args'] as $key => $value){
128
- WP_Installer()->set_config($key, $value);
129
- }
130
- }
131
-
132
- }
133
- }
134
-
135
- if(!function_exists('WP_Installer_Setup')){
136
-
137
- // $args:
138
- // plugins_install_tab = true|false (default: true)
139
- // repositories_include = array() (default: all)
140
- // repositories_exclude = array() (default: none)
141
- // template = name (default: default)
142
- //
143
- // Ext function
144
- function WP_Installer_Setup($wp_installer_instance, $args = array()){
145
- global $wp_installer_instances;
146
-
147
- $wp_installer_instances[$wp_installer_instance]['args'] = $args;
148
-
149
- }
150
-
151
  }
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly
5
+ }
6
+
7
+ //It should only be loaded on the admin side
8
+ if( !is_admin() ){
9
+ if(!function_exists('WP_Installer_Setup')){ function WP_Installer_Setup(){} }
10
+ $wp_installer_instance = null;
11
+ return;
12
+ }
13
+
14
+
15
+ $wp_installer_instance = dirname(__FILE__) . '/installer.php';
16
+
17
+
18
+ // Global stack of instances
19
+ global $wp_installer_instances;
20
+ $wp_installer_instances[$wp_installer_instance] = array(
21
+ 'bootfile' => $wp_installer_instance,
22
+ 'version' => '1.8.2'
23
+ );
24
+
25
+
26
+ /* EXCEPTIONS ********************************************************************************************/
27
+ // Exception: When WPML prior 3.2 is used, that instance must be used regardless of another newer instance
28
+ // Case 1: WPML loaded before Types - eliminate other instances
29
+ if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<') ) {
30
+ foreach($wp_installer_instances as $key => $instance) {
31
+ if(isset($instance['args']['site_key_nags'])){
32
+ $wp_installer_instances[$key]['version'] = '9.9';
33
+ }else{
34
+ $wp_installer_instances[$key]['version'] = '0';
35
+ }
36
+ }
37
+ }
38
+
39
+ // Exception: Types 1.8.9 (Installer 1.7.0) with WPML before 3.3 (Installer before 1.7.0)
40
+ // New products file http://d2salfytceyqoe.cloudfront.net/wpml-products33.json overrides the old one
41
+ // while the WPML's instance is being used
42
+ // => Force using the new Installer Instance
43
+ if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.3.1', '<') ) {
44
+
45
+ // if Installer 1.7.0+ is present, unregister Installer from old WPML
46
+ // Force Installer 1.7.0+ being used over older Installer versions
47
+ $installer_171_plus_on = false;
48
+ foreach($wp_installer_instances as $key => $instance) {
49
+ if( version_compare( $instance['version'], '1.7.1', '>=' ) ){
50
+ $installer_171_plus_on = true;
51
+ break;
52
+ }
53
+ }
54
+
55
+ if( $installer_171_plus_on ){
56
+ foreach($wp_installer_instances as $key => $instance) {
57
+
58
+ if( version_compare( $instance['version'], '1.7.0', '<' ) ){
59
+ unset( $wp_installer_instances[$key] );
60
+ }
61
+
62
+ }
63
+ }
64
+
65
+ }
66
+
67
+ // Exception: When using the embedded plugins module allow the set up to run completely with the
68
+ // Installer instance that triggers it
69
+ if( isset( $_POST['installer_instance'] ) && isset( $wp_installer_instances[$_POST['installer_instance']] ) ){
70
+ $wp_installer_instances[$_POST['installer_instance']]['version'] = '999';
71
+ }
72
+ /* EXCEPTIONS ********************************************************************************************/
73
+
74
+
75
+ // Only one of these in the end
76
+ remove_action('after_setup_theme', 'wpml_installer_instance_delegator', 1);
77
+ add_action('after_setup_theme', 'wpml_installer_instance_delegator', 1);
78
+
79
+ // When all plugins load pick the newest version
80
+ if(!function_exists('wpml_installer_instance_delegator')){
81
+ function wpml_installer_instance_delegator(){
82
+ global $wp_installer_instances;
83
+
84
+ // version based election
85
+ foreach($wp_installer_instances as $instance){
86
+
87
+ if(!isset($delegate)){
88
+ $delegate = $instance;
89
+ continue;
90
+ }
91
+
92
+ if(version_compare($instance['version'], $delegate['version'], '>')){
93
+ $delegate = $instance;
94
+ }
95
+ }
96
+
97
+ // priority based election
98
+ $highest_priority = null;
99
+ foreach($wp_installer_instances as $instance) {
100
+ if(isset($instance['args']['high_priority'])){
101
+ if(is_null($highest_priority) || $instance['args']['high_priority'] <= $highest_priority){
102
+ $highest_priority = $instance['args']['high_priority'];
103
+ $delegate = $instance;
104
+ }
105
+ }
106
+ }
107
+
108
+ // Exception: When WPML prior 3.2 is used, that instance must be used regardless of another newer instance
109
+ // Case 2: WPML loaded after Types
110
+ if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<') ) {
111
+ foreach($wp_installer_instances as $key => $instance) {
112
+ if(isset($instance['args']['site_key_nags'])){
113
+ $delegate = $instance;
114
+ $wp_installer_instances = array($key => $delegate); //Eliminate other instances
115
+ break;
116
+ }
117
+ }
118
+ }
119
+
120
+ include_once $delegate['bootfile'];
121
+
122
+ // set configuration
123
+ if(strpos(realpath($delegate['bootfile']), realpath(TEMPLATEPATH)) === 0){
124
+ $delegate['args']['in_theme_folder'] = dirname(ltrim(str_replace(realpath(TEMPLATEPATH), '', realpath($delegate['bootfile'])), '\\/'));
125
+ }
126
+ if(isset($delegate['args']) && is_array($delegate['args'])){
127
+ foreach($delegate['args'] as $key => $value){
128
+ WP_Installer()->set_config($key, $value);
129
+ }
130
+ }
131
+
132
+ }
133
+ }
134
+
135
+ if(!function_exists('WP_Installer_Setup')){
136
+
137
+ // $args:
138
+ // plugins_install_tab = true|false (default: true)
139
+ // repositories_include = array() (default: all)
140
+ // repositories_exclude = array() (default: none)
141
+ // template = name (default: default)
142
+ //
143
+ // Ext function
144
+ function WP_Installer_Setup($wp_installer_instance, $args = array()){
145
+ global $wp_installer_instances;
146
+
147
+ $wp_installer_instances[$wp_installer_instance]['args'] = $args;
148
+
149
+ }
150
+
151
  }
vendor/otgs/installer/locale/orig/installer.po CHANGED
@@ -1,230 +1,230 @@
1
- # This file was generated by WPML
2
- # WPML is a WordPress plugin that can turn any WordPress site into a full featured multilingual content management system.
3
- # https://wpml.org
4
- msgid ""
5
- msgstr ""
6
- "Content-Type: text/plain; charset=utf-8\n"
7
- "Content-Transfer-Encoding: 8bit\n"
8
- "Project-Id-Version:WPML_EXPORT\n"
9
- "POT-Creation-Date: \n"
10
- "PO-Revision-Date: \n"
11
- "Last-Translator: \n"
12
- "Language-Team: \n"
13
- "Language:en\n"
14
- "MIME-Version: 1.0\n"
15
-
16
- msgid "Installer"
17
- msgstr ""
18
-
19
- msgid "Registered"
20
- msgstr ""
21
-
22
- msgid "Register"
23
- msgstr ""
24
-
25
- msgid "To get automatic updates, you need to register %s for this site. %sRegister %s%s"
26
- msgstr ""
27
-
28
- msgid "Dismiss"
29
- msgstr ""
30
-
31
- msgid "Commercial"
32
- msgstr ""
33
-
34
- msgid "Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:"
35
- msgstr ""
36
-
37
- msgid "No repositories defined."
38
- msgstr ""
39
-
40
- msgid "%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates."
41
- msgstr ""
42
-
43
- msgid "Invalid site key for the current site."
44
- msgstr ""
45
-
46
- msgid "You will have to renew your subscription in order to continue getting the updates and support."
47
- msgstr ""
48
-
49
- msgid "%sRenew here%s."
50
- msgstr ""
51
-
52
- msgid "Your subscription appears to no longer be valid. Please try to register again using a valid site key."
53
- msgstr ""
54
-
55
- msgid "You need to have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s."
56
- msgstr ""
57
-
58
- msgid "%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first."
59
- msgstr ""
60
-
61
- msgid "Update Plugin"
62
- msgstr ""
63
-
64
- msgid "Return to the plugins page"
65
- msgstr ""
66
-
67
- msgid "Your subscription expires in %d day."
68
- msgstr ""
69
-
70
- msgid "Your subscription expires in %d days."
71
- msgstr ""
72
-
73
- msgid "Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s."
74
- msgstr ""
75
-
76
- msgid "Plugin"
77
- msgstr ""
78
-
79
- msgid "downloading..."
80
- msgstr ""
81
-
82
- msgid "failed!"
83
- msgstr ""
84
-
85
- msgid "downloaded"
86
- msgstr ""
87
-
88
- msgid "activating"
89
- msgstr ""
90
-
91
- msgid "activated"
92
- msgstr ""
93
-
94
- msgid "Activate after download"
95
- msgstr ""
96
-
97
- msgid "Operation complete!"
98
- msgstr ""
99
-
100
- msgid "Download failed!\n\nClick OK to revalidate your subscription or CANCEL to try again."
101
- msgstr ""
102
-
103
- msgid "Available"
104
- msgstr ""
105
-
106
- msgid "Installed"
107
- msgstr ""
108
-
109
- msgid "Downloading"
110
- msgstr ""
111
-
112
- msgid "Activate"
113
- msgstr ""
114
-
115
- msgid "Download"
116
- msgstr ""
117
-
118
- msgid "Downloads:"
119
- msgstr ""
120
-
121
- msgid "Current version"
122
- msgstr ""
123
-
124
- msgid "Released"
125
- msgstr ""
126
-
127
- msgid "Installed version"
128
- msgstr ""
129
-
130
- msgid "(embedded)"
131
- msgstr ""
132
-
133
- msgid "installing..."
134
- msgstr ""
135
-
136
- msgid "updating..."
137
- msgstr ""
138
-
139
- msgid "installed"
140
- msgstr ""
141
-
142
- msgid "updated"
143
- msgstr ""
144
-
145
- msgid "Download failed!\n\nPlease refresh the page and try again."
146
- msgstr ""
147
-
148
- msgid "Incorrect setup"
149
- msgstr ""
150
-
151
- msgid "Invalid product"
152
- msgstr ""
153
-
154
- msgid "Unknown repository"
155
- msgstr ""
156
-
157
- msgid " Your current site key (%s) does not match the selected product (%s)."
158
- msgstr ""
159
-
160
- msgid "Buy %s"
161
- msgstr ""
162
-
163
- msgid "Already bought %s?"
164
- msgstr ""
165
-
166
- msgid "Renew %s"
167
- msgstr ""
168
-
169
- msgid "Remove current site key (%s)"
170
- msgstr ""
171
-
172
- msgid "%s support on wpml.org"
173
- msgstr ""
174
-
175
- msgid "Enter site key"
176
- msgstr ""
177
-
178
- msgid "Subscription is expired."
179
- msgstr ""
180
-
181
- msgid "Add"
182
- msgstr ""
183
-
184
- msgid "Are you sure you want to remove this site key?"
185
- msgstr ""
186
-
187
- msgid "Register %s"
188
- msgstr ""
189
-
190
- msgid "1. Go to your %s%s account%s and add this site URL: %s"
191
- msgstr ""
192
-
193
- msgid "Unregister %s from this site"
194
- msgstr ""
195
-
196
- msgid "%s is registered on this site. You will receive automatic updates until %s"
197
- msgstr ""
198
-
199
- msgid "%s is registered on this site. Your Lifetime account gives you updates for life."
200
- msgstr ""
201
-
202
- msgid "This page lets you install plugins and update existing plugins. To remove any of these plugins, go to the %splugins%s page and if you have the permission to remove plugins you should be able to do this."
203
- msgstr ""
204
-
205
- msgid "Already bought?"
206
- msgstr ""
207
-
208
- msgid "2. Enter your site key"
209
- msgstr ""
210
-
211
- msgid "Subscription is expired. You need to either purchase a new subscription or upgrade if available."
212
- msgstr ""
213
-
214
- msgid "Check for updates"
215
- msgstr ""
216
-
217
- msgid "Individual components"
218
- msgstr ""
219
-
220
- msgid "OK"
221
- msgstr ""
222
-
223
- msgid "Cancel"
224
- msgstr ""
225
-
226
- msgid "Are you sure you want to unregister?"
227
- msgstr ""
228
-
229
- msgid "Click to see individual components options."
230
- msgstr ""
1
+ # This file was generated by WPML
2
+ # WPML is a WordPress plugin that can turn any WordPress site into a full featured multilingual content management system.
3
+ # https://wpml.org
4
+ msgid ""
5
+ msgstr ""
6
+ "Content-Type: text/plain; charset=utf-8\n"
7
+ "Content-Transfer-Encoding: 8bit\n"
8
+ "Project-Id-Version:WPML_EXPORT\n"
9
+ "POT-Creation-Date: \n"
10
+ "PO-Revision-Date: \n"
11
+ "Last-Translator: \n"
12
+ "Language-Team: \n"
13
+ "Language:en\n"
14
+ "MIME-Version: 1.0\n"
15
+
16
+ msgid "Installer"
17
+ msgstr ""
18
+
19
+ msgid "Registered"
20
+ msgstr ""
21
+
22
+ msgid "Register"
23
+ msgstr ""
24
+
25
+ msgid "To get automatic updates, you need to register %s for this site. %sRegister %s%s"
26
+ msgstr ""
27
+
28
+ msgid "Dismiss"
29
+ msgstr ""
30
+
31
+ msgid "Commercial"
32
+ msgstr ""
33
+
34
+ msgid "Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:"
35
+ msgstr ""
36
+
37
+ msgid "No repositories defined."
38
+ msgstr ""
39
+
40
+ msgid "%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates."
41
+ msgstr ""
42
+
43
+ msgid "Invalid site key for the current site."
44
+ msgstr ""
45
+
46
+ msgid "You will have to renew your subscription in order to continue getting the updates and support."
47
+ msgstr ""
48
+
49
+ msgid "%sRenew here%s."
50
+ msgstr ""
51
+
52
+ msgid "Your subscription appears to no longer be valid. Please try to register again using a valid site key."
53
+ msgstr ""
54
+
55
+ msgid "You need to have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s."
56
+ msgstr ""
57
+
58
+ msgid "%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first."
59
+ msgstr ""
60
+
61
+ msgid "Update Plugin"
62
+ msgstr ""
63
+
64
+ msgid "Return to the plugins page"
65
+ msgstr ""
66
+
67
+ msgid "Your subscription expires in %d day."
68
+ msgstr ""
69
+
70
+ msgid "Your subscription expires in %d days."
71
+ msgstr ""
72
+
73
+ msgid "Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s."
74
+ msgstr ""
75
+
76
+ msgid "Plugin"
77
+ msgstr ""
78
+
79
+ msgid "downloading..."
80
+ msgstr ""
81
+
82
+ msgid "failed!"
83
+ msgstr ""
84
+
85
+ msgid "downloaded"
86
+ msgstr ""
87
+
88
+ msgid "activating"
89
+ msgstr ""
90
+
91
+ msgid "activated"
92
+ msgstr ""
93
+
94
+ msgid "Activate after download"
95
+ msgstr ""
96
+
97
+ msgid "Operation complete!"
98
+ msgstr ""
99
+
100
+ msgid "Download failed!\n\nClick OK to revalidate your subscription or CANCEL to try again."
101
+ msgstr ""
102
+
103
+ msgid "Available"
104
+ msgstr ""
105
+
106
+ msgid "Installed"
107
+ msgstr ""
108
+
109
+ msgid "Downloading"
110
+ msgstr ""
111
+
112
+ msgid "Activate"
113
+ msgstr ""
114
+
115
+ msgid "Download"
116
+ msgstr ""
117
+
118
+ msgid "Downloads:"
119
+ msgstr ""
120
+
121
+ msgid "Current version"
122
+ msgstr ""
123
+
124
+ msgid "Released"
125
+ msgstr ""
126
+
127
+ msgid "Installed version"
128
+ msgstr ""
129
+
130
+ msgid "(embedded)"
131
+ msgstr ""
132
+
133
+ msgid "installing..."
134
+ msgstr ""
135
+
136
+ msgid "updating..."
137
+ msgstr ""
138
+
139
+ msgid "installed"
140
+ msgstr ""
141
+
142
+ msgid "updated"
143
+ msgstr ""
144
+
145
+ msgid "Download failed!\n\nPlease refresh the page and try again."
146
+ msgstr ""
147
+
148
+ msgid "Incorrect setup"
149
+ msgstr ""
150
+
151
+ msgid "Invalid product"
152
+ msgstr ""
153
+
154
+ msgid "Unknown repository"
155
+ msgstr ""
156
+
157
+ msgid " Your current site key (%s) does not match the selected product (%s)."
158
+ msgstr ""
159
+
160
+ msgid "Buy %s"
161
+ msgstr ""
162
+
163
+ msgid "Already bought %s?"
164
+ msgstr ""
165
+
166
+ msgid "Renew %s"
167
+ msgstr ""
168
+
169
+ msgid "Remove current site key (%s)"
170
+ msgstr ""
171
+
172
+ msgid "%s support on wpml.org"
173
+ msgstr ""
174
+
175
+ msgid "Enter site key"
176
+ msgstr ""
177
+
178
+ msgid "Subscription is expired."
179
+ msgstr ""
180
+
181
+ msgid "Add"
182
+ msgstr ""
183
+
184
+ msgid "Are you sure you want to remove this site key?"
185
+ msgstr ""
186
+
187
+ msgid "Register %s"
188
+ msgstr ""
189
+
190
+ msgid "1. Go to your %s%s account%s and add this site URL: %s"
191
+ msgstr ""
192
+
193
+ msgid "Unregister %s from this site"
194
+ msgstr ""
195
+
196
+ msgid "%s is registered on this site. You will receive automatic updates until %s"
197
+ msgstr ""
198
+
199
+ msgid "%s is registered on this site. Your Lifetime account gives you updates for life."
200
+ msgstr ""
201
+
202
+ msgid "This page lets you install plugins and update existing plugins. To remove any of these plugins, go to the %splugins%s page and if you have the permission to remove plugins you should be able to do this."
203
+ msgstr ""
204
+
205
+ msgid "Already bought?"
206
+ msgstr ""
207
+
208
+ msgid "2. Enter your site key"
209
+ msgstr ""
210
+
211
+ msgid "Subscription is expired. You need to either purchase a new subscription or upgrade if available."
212
+ msgstr ""
213
+
214
+ msgid "Check for updates"
215
+ msgstr ""
216
+
217
+ msgid "Individual components"
218
+ msgstr ""
219
+
220
+ msgid "OK"
221
+ msgstr ""
222
+
223
+ msgid "Cancel"
224
+ msgstr ""
225
+
226
+ msgid "Are you sure you want to unregister?"
227
+ msgstr ""
228
+
229
+ msgid "Click to see individual components options."
230
+ msgstr ""
vendor/otgs/installer/res/css/admin.css CHANGED
@@ -1,289 +1,293 @@
1
- .otgsi_site_key_form{
2
- display:none;
3
- /*display:inline;*/
4
- }
5
-
6
- .installer-status-installing, .installer-status-installed, .installer-status-updating, .installer-status-updated, .installer-status-activating, .installer-status-activated, .installer-status-success{
7
- display: none;
8
- }
9
- .installer-status-installing{color: #FF9900; }
10
- .installer-status-installed{color: #003300; font-weight: bold; }
11
- .installer-status-updating{color: #FF9900; }
12
- .installer-status-updated{color: #003300; font-weight: bold; }
13
-
14
- .installer-status-installed .error-details:before,
15
- .installer-status-updated .error-details:before{
16
- content: "\f534";
17
- font: 200 16px/1 dashicons;
18
- vertical-align: text-bottom;
19
- margin-left: 5px;
20
- color: red;
21
- cursor: help;
22
- }
23
-
24
- .installer-status-activating{color: #996666 }
25
- .installer-status-activated{color: #333366; font-weight: bold; }
26
-
27
- .js-status-success p{
28
- color: #FF9900;
29
- padding: 4px;
30
- }
31
-
32
- .installer-green-text{
33
- color:#006600;
34
- font-weight:bold;
35
- }
36
-
37
- .installer-red-text{
38
- color:#b22121;
39
- font-weight:bold;
40
- }
41
-
42
- .installer-footnote{
43
- color:#3d5e69;
44
- display:block;
45
- float: left;
46
- font-style: italic;
47
- font-size: 90%;
48
- }
49
-
50
- .installer-products-list li{
51
- display: inline;
52
- margin-right: 20px;
53
- }
54
-
55
- .otgs_wp_installer_table a.disabled{
56
- color:#888;
57
- }
58
-
59
- .otgs_wp_installer_subtable{
60
- clear: both;
61
- margin-left:-20px;
62
- }
63
- .otgs_wp_installer_subtable td p{
64
- font-size: 92%;
65
- }
66
-
67
- .installer-status-error{
68
- color: #f00;
69
- }
70
-
71
- .installer-status-note{
72
- color: #6F6E6D;
73
- font-style: italic;
74
- }
75
-
76
- .installer-warn-text{
77
- color: #FF6400;
78
- }
79
-
80
- .installer-warn-box{
81
- -webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;border:1px solid #FF6400;background-color:#df8a48;
82
- color: #333;
83
- padding: 5px;
84
- }
85
- .installer-warn-box span.details{
86
- font-style: italic;
87
- color:#777;
88
- }
89
-
90
- .installer-error-box{
91
- color:#962722;
92
- margin-top: 10px;
93
- }
94
- .installer-error-box p{
95
- margin: 10px 0 10px 0;
96
- -webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;border:1px solid #962722;background-color:#F5C8C6;
97
- color: #333;
98
- padding: 5px;
99
- text-align: center;
100
- }
101
-
102
- .spinner-inline{
103
- float: none;
104
- display: inline-block;
105
- visibility: visible;
106
- }
107
-
108
- .installer-q-icon:before{
109
- content: '\f223' !important;
110
- font-family: dashicons !important;
111
- color: #f56e28;
112
- font: 20px/1 "dashicons";
113
- }
114
-
115
- .installer-plugin-update-tr td{
116
- padding-left:3px !important;
117
- }
118
-
119
- .otgsi_yellow_bg{
120
- background-color: #f2f46b;
121
- }
122
-
123
- .otgs_wp_installer_table_compact{
124
- width:480px;
125
- border: solid 1px #999;
126
- padding:10px;
127
- border-radius: 5px;
128
- }
129
-
130
- .installer-plugins-list-compact{
131
- background-color: #fff;
132
- border-collapse: collapse;
133
- border:solid 1px #C1DAD7;
134
- width:100%;
135
- }
136
-
137
- .installer-plugins-list-compact tr th{
138
- padding-top:3px;
139
- background-color: #ccc;
140
- }
141
-
142
- .installer-plugins-list-compact tr{
143
- background-color: #ddd;
144
- }
145
-
146
- .installer-plugins-list-compact tr.even{
147
- background-color: #eee;
148
- }
149
-
150
- .installer-plugins-list-compact td{
151
- padding:2px 5px 2px 5px;
152
- border-right: 1px solid #C1DAD7;
153
- border-bottom: 1px solid #C1DAD7;
154
- }
155
-
156
- .installer-plugins-list-compact td.twelve{
157
- width:16px;
158
- }
159
-
160
- .otgs_wp_installer_table_compact .installer-status-downloading,
161
- .otgs_wp_installer_table_compact .installer-status-downloaded,
162
- .otgs_wp_installer_table_compact .installer-status-activating,
163
- .otgs_wp_installer_table_compact .installer-status-activated{
164
- display: none;
165
- color:transparent; width: 12px; padding:2px;
166
- }
167
-
168
- .otgs_wp_installer_table_compact .installer-status-success,
169
- .otgs_wp_installer_table_compact .installer-status-fail{
170
- display: none;
171
- }
172
-
173
- .installer-status-success{
174
- float: right;
175
- color: #006600;
176
- }
177
-
178
- .otgs_wp_installer_table_compact .installer-status-downloading{background: url(../img/dn.gif) no-repeat center; }
179
- .otgs_wp_installer_table_compact .installer-status-downloaded{background: url(../img/complete.png) no-repeat center;}
180
- .otgs_wp_installer_table_compact .installer-status-activating{background: url(../img/dn.gif) no-repeat center; }
181
- .otgs_wp_installer_table_compact .installer-status-activated{background: url(../img/complete.png) no-repeat center; }
182
- .otgs_wp_installer_table_compact .installer-status-error{background: url(../img/icon_error.gif) no-repeat center; }
183
-
184
- .installer_highlight{
185
- color:#c5510b;
186
- }
187
-
188
- .installer_highlight_package{
189
- background-color: #fff9c0;
190
- }
191
-
192
- .plugin_progress{
193
- font-style: italic;
194
- color: #777
195
- }
196
-
197
- .installer-download-progress-status{
198
- display: none;
199
- float:right;
200
- color: #006600;
201
- font-style: italic;
202
- background: url('../img/spinner.gif') no-repeat;
203
- padding-left:24px;
204
- }
205
-
206
- .installer-release-notes{
207
- display: none;
208
- }
209
-
210
- .handle.extended:after{
211
- content: "▾";
212
- font-size: 24px;
213
- vertical-align:bottom;
214
- }
215
- .installer-table-wrap a.handle:active,
216
- .installer-table-wrap a.handle:focus{
217
- outline:0;
218
- border:none;
219
- -moz-outline-style: none;
220
- -webkit-box-shadow: none;
221
- box-shadow: none;
222
- }
223
-
224
- .installer-release-notes .arrow_box {
225
- position: relative;
226
- background: #eee;
227
- border: 1px solid #ccc;
228
- }
229
- .installer-release-notes .arrow_box:after, .installer-release-notes .arrow_box:before {
230
- bottom: 100%;
231
- left: 50%;
232
- border: solid transparent;
233
- content: " ";
234
- height: 0;
235
- width: 0;
236
- position: absolute;
237
- pointer-events: none;
238
- }
239
-
240
- .installer-release-notes .arrow_box:after {
241
- border-color: rgba(238, 238, 238, 0);
242
- border-bottom-color: #eee;
243
- border-width: 16px;
244
- margin-left: -16px;
245
- }
246
- .installer-release-notes .arrow_box:before {
247
- border-color: rgba(204, 204, 204, 0);
248
- border-bottom-color: #ccc;
249
- border-width: 17px;
250
- margin-left: -17px;
251
- }
252
-
253
- .installer-release-notes .arrow_box div{
254
- margin-top:5px;
255
- padding: 10px;
256
- overflow-y: auto;
257
- max-height: 400px;
258
- }
259
-
260
- .otgs-is-dismissible {
261
- position: relative;
262
- padding-right: 38px;
263
- }
264
- .otgs-is-dismissible .notice-dismiss {
265
- text-decoration: none;
266
- }
267
- .otgs-is-dismissible p [class*="button-"] {
268
- margin: -5px 5px;
269
- }
270
-
271
- .otgsi_downloads_form{
272
- margin-top: 15px;
273
- }
274
-
275
- .spinner-with-text{
276
- padding-left: 25px;
277
- float:none;
278
- width: auto;
279
- }
280
- .installer-channel-update-ok{
281
- padding-left: 10px;
282
- display: none;
283
- color: #006600;
284
- }
285
- .installer-channel-update-fail{
286
- padding-left: 10px;
287
- display: none;
288
- color: #962722;
289
- }
 
 
 
 
1
+ .otgsi_site_key_form{
2
+ display:none;
3
+ /*display:inline;*/
4
+ }
5
+
6
+ .installer-status-installing, .installer-status-installed, .installer-status-updating, .installer-status-updated, .installer-status-activating, .installer-status-activated, .installer-status-success{
7
+ display: none;
8
+ }
9
+ .installer-status-installing{color: #FF9900; }
10
+ .installer-status-installed{color: #003300; font-weight: bold; }
11
+ .installer-status-updating{color: #FF9900; }
12
+ .installer-status-updated{color: #003300; font-weight: bold; }
13
+
14
+ .installer-status-installed .error-details:before,
15
+ .installer-status-updated .error-details:before{
16
+ content: "\f534";
17
+ font: 200 16px/1 dashicons;
18
+ vertical-align: text-bottom;
19
+ margin-left: 5px;
20
+ color: red;
21
+ cursor: help;
22
+ }
23
+
24
+ .installer-status-activating{color: #996666 }
25
+ .installer-status-activated{color: #333366; font-weight: bold; }
26
+
27
+ .js-status-success p{
28
+ color: #FF9900;
29
+ padding: 4px;
30
+ }
31
+
32
+ .installer-green-text{
33
+ color:#006600;
34
+ font-weight:bold;
35
+ }
36
+
37
+ .installer-red-text{
38
+ color:#b22121;
39
+ font-weight:bold;
40
+ }
41
+
42
+ .installer-footnote{
43
+ color:#3d5e69;
44
+ display:block;
45
+ float: left;
46
+ font-style: italic;
47
+ font-size: 90%;
48
+ }
49
+
50
+ .installer-products-list li{
51
+ display: inline;
52
+ margin-right: 20px;
53
+ }
54
+
55
+ .otgs_wp_installer_table a.disabled{
56
+ color:#888;
57
+ }
58
+
59
+ .otgs_wp_installer_subtable{
60
+ clear: both;
61
+ margin-left:-20px;
62
+ }
63
+ .otgs_wp_installer_subtable td p{
64
+ font-size: 92%;
65
+ }
66
+
67
+ .installer-status-error{
68
+ color: #f00;
69
+ }
70
+
71
+ .installer-status-note{
72
+ color: #6F6E6D;
73
+ font-style: italic;
74
+ }
75
+
76
+ .installer-warn-text{
77
+ color: #FF6400;
78
+ }
79
+
80
+ .installer-warn-box{
81
+ -webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;border:1px solid #FF6400;background-color:#df8a48;
82
+ color: #333;
83
+ padding: 5px;
84
+ }
85
+ .installer-warn-box span.details{
86
+ font-style: italic;
87
+ color:#777;
88
+ }
89
+
90
+ .installer-error-box{
91
+ color:#962722;
92
+ margin-top: 10px;
93
+ }
94
+ .installer-error-box p{
95
+ margin: 10px 0 10px 0;
96
+ -webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;border:1px solid #962722;background-color:#F5C8C6;
97
+ color: #333;
98
+ padding: 5px;
99
+ text-align: center;
100
+ }
101
+
102
+ .spinner-inline{
103
+ float: none;
104
+ display: inline-block;
105
+ visibility: visible;
106
+ }
107
+
108
+ .installer-q-icon:before{
109
+ content: '\f223' !important;
110
+ font-family: dashicons !important;
111
+ color: #f56e28;
112
+ font: 20px/1 "dashicons";
113
+ }
114
+
115
+ .installer-plugin-update-tr td{
116
+ padding-left:3px !important;
117
+ }
118
+
119
+ .otgsi_yellow_bg{
120
+ background-color: #f2f46b;
121
+ }
122
+
123
+ .otgs_wp_installer_table_compact{
124
+ width:480px;
125
+ border: solid 1px #999;
126
+ padding:10px;
127
+ border-radius: 5px;
128
+ }
129
+
130
+ .installer-plugins-list-compact{
131
+ background-color: #fff;
132
+ border-collapse: collapse;
133
+ border:solid 1px #C1DAD7;
134
+ width:100%;
135
+ }
136
+
137
+ .installer-plugins-list-compact tr th{
138
+ padding-top:3px;
139
+ background-color: #ccc;
140
+ }
141
+
142
+ .installer-plugins-list-compact tr{
143
+ background-color: #ddd;
144
+ }
145
+
146
+ .installer-plugins-list-compact tr.even{
147
+ background-color: #eee;
148
+ }
149
+
150
+ .installer-plugins-list-compact td{
151
+ padding:2px 5px 2px 5px;
152
+ border-right: 1px solid #C1DAD7;
153
+ border-bottom: 1px solid #C1DAD7;
154
+ }
155
+
156
+ .installer-plugins-list-compact td.twelve{
157
+ width:16px;
158
+ }
159
+
160
+ .otgs_wp_installer_table_compact .installer-status-downloading,
161
+ .otgs_wp_installer_table_compact .installer-status-downloaded,
162
+ .otgs_wp_installer_table_compact .installer-status-activating,
163
+ .otgs_wp_installer_table_compact .installer-status-activated{
164
+ display: none;
165
+ color:transparent; width: 12px; padding:2px;
166
+ }
167
+
168
+ .otgs_wp_installer_table_compact .installer-status-success,
169
+ .otgs_wp_installer_table_compact .installer-status-fail{
170
+ display: none;
171
+ }
172
+
173
+ .installer-status-success{
174
+ float: right;
175
+ color: #006600;
176
+ }
177
+
178
+ .otgs_wp_installer_table_compact .installer-status-downloading{background: url(../img/dn.gif) no-repeat center; }
179
+ .otgs_wp_installer_table_compact .installer-status-downloaded{background: url(../img/complete.png) no-repeat center;}
180
+ .otgs_wp_installer_table_compact .installer-status-activating{background: url(../img/dn.gif) no-repeat center; }
181
+ .otgs_wp_installer_table_compact .installer-status-activated{background: url(../img/complete.png) no-repeat center; }
182
+ .otgs_wp_installer_table_compact .installer-status-error{background: url(../img/icon_error.gif) no-repeat center; }
183
+
184
+ .installer_highlight{
185
+ color:#c5510b;
186
+ }
187
+
188
+ .installer_highlight_package{
189
+ background-color: #fff9c0;
190
+ }
191
+
192
+ .plugin_progress{
193
+ font-style: italic;
194
+ color: #777
195
+ }
196
+
197
+ .installer-download-progress-status{
198
+ display: none;
199
+ float:right;
200
+ color: #006600;
201
+ font-style: italic;
202
+ background: url('../img/spinner.gif') no-repeat;
203
+ padding-left:24px;
204
+ }
205
+
206
+ .installer-release-notes{
207
+ display: none;
208
+ }
209
+
210
+ .handle.extended:after{
211
+ content: "▾";
212
+ font-size: 24px;
213
+ vertical-align:bottom;
214
+ }
215
+ .installer-table-wrap a.handle:active,
216
+ .installer-table-wrap a.handle:focus{
217
+ outline:0;
218
+ border:none;
219
+ -moz-outline-style: none;
220
+ -webkit-box-shadow: none;
221
+ box-shadow: none;
222
+ }
223
+
224
+ .installer-release-notes .arrow_box {
225
+ position: relative;
226
+ background: #eee;
227
+ border: 1px solid #ccc;
228
+ }
229
+ .installer-release-notes .arrow_box:after, .installer-release-notes .arrow_box:before {
230
+ bottom: 100%;
231
+ left: 50%;
232
+ border: solid transparent;
233
+ content: " ";
234
+ height: 0;
235
+ width: 0;
236
+ position: absolute;
237
+ pointer-events: none;
238
+ }
239
+
240
+ .installer-release-notes .arrow_box:after {
241
+ border-color: rgba(238, 238, 238, 0);
242
+ border-bottom-color: #eee;
243
+ border-width: 16px;
244
+ margin-left: -16px;
245
+ }
246
+ .installer-release-notes .arrow_box:before {
247
+ border-color: rgba(204, 204, 204, 0);
248
+ border-bottom-color: #ccc;
249
+ border-width: 17px;
250
+ margin-left: -17px;
251
+ }
252
+
253
+ .installer-release-notes .arrow_box div{
254
+ margin-top:5px;
255
+ padding: 10px;
256
+ overflow-y: auto;
257
+ max-height: 400px;
258
+ }
259
+
260
+ .otgs-is-dismissible {
261
+ position: relative;
262
+ padding-right: 38px;
263
+ }
264
+ .otgs-is-dismissible .notice-dismiss {
265
+ text-decoration: none;
266
+ }
267
+ .otgs-is-dismissible p [class*="button-"] {
268
+ margin: -5px 5px;
269
+ }
270
+
271
+ .otgsi_downloads_form{
272
+ margin-top: 15px;
273
+ }
274
+
275
+ .spinner-with-text{
276
+ padding-left: 25px;
277
+ float:none;
278
+ width: auto;
279
+ }
280
+ .installer-channel-update-ok{
281
+ padding-left: 10px;
282
+ display: none;
283
+ color: #006600;
284
+ }
285
+ .installer-channel-update-fail{
286
+ padding-left: 10px;
287
+ display: none;
288
+ color: #962722;
289
+ }
290
+
291
+ .otgs_wp_installer_table .installer-repository-image {
292
+ padding: 8px 20px;
293
+ }
vendor/otgs/installer/res/js/admin.js CHANGED
@@ -1,461 +1,461 @@
1
-
2
-
3
- var otgs_wp_installer = {
4
-
5
- plugins_update_XHR :{},
6
-
7
- init: function(){
8
-
9
- jQuery('.otgs_wp_installer_table').on('click', '.enter_site_key_js', otgs_wp_installer.show_site_key_form);
10
- jQuery('.otgs_wp_installer_table').on('click', '.cancel_site_key_js', otgs_wp_installer.hide_site_key_form);
11
-
12
- jQuery('.otgs_wp_installer_table').on('click', '.remove_site_key_js', otgs_wp_installer.remove_site_key);
13
- jQuery('.otgs_wp_installer_table').on('click', '.update_site_key_js', otgs_wp_installer.update_site_key);
14
-
15
- jQuery('.otgs_wp_installer_table').on('submit', '.otgsi_site_key_form', otgs_wp_installer.save_site_key);
16
- jQuery('.otgs_wp_installer_table').on('submit', '.otgsi_downloads_form', otgs_wp_installer.download_downloads);
17
- jQuery('.otgs_wp_installer_table').on('change', '.otgsi_downloads_form :checkbox[name="downloads[]"]', otgs_wp_installer.update_downloads_form);
18
-
19
- jQuery('.installer-dismiss-nag').click(otgs_wp_installer.dismiss_nag);
20
-
21
- jQuery('.otgs_wp_installer_table').on('click', '.installer_expand_button', otgs_wp_installer.toggle_subpackages);
22
-
23
- otgs_wp_installer.scroll_to_repository();
24
-
25
- if( typeof pagenow != 'undefined' && pagenow == 'plugins'){
26
-
27
- jQuery(document).ajaxSuccess(function(event, xhr, settings) {
28
- var data = otgs_wp_installer.getQueryParameters(settings.data);
29
- if(typeof data.action != 'undefined' && data.action == 'update-plugin'){
30
- response = xhr.responseJSON.data;
31
- if(typeof response.error != 'undefined'){
32
- var default_error = jQuery('#' + response.slug + '-update .update-message').html();
33
- jQuery('#' + response.slug + '-update .update-message').html(default_error + ' &raquo;<span class="installer-red-text"> ' + response.error + '</span>');
34
- }
35
- }
36
- return false;
37
- });
38
-
39
- }
40
-
41
- if( typeof pagenow != 'undefined' && pagenow == 'plugin-install' ){
42
- jQuery( '.plugin-install-tab-commercial .search-plugins' ).remove();
43
- }
44
-
45
- jQuery('.installer-table-wrap').on('click', '.js-release-notes', otgs_wp_installer.toggle_release_notes);
46
- },
47
-
48
- getQueryParameters : function(str) {
49
- return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
50
- },
51
-
52
- reset_errors: function(){
53
- jQuery('.installer-error-box').html('').hide();
54
- },
55
-
56
- show_error: function(repo, text){
57
- jQuery('#installer_repo_' + repo).find('.installer-error-box').html(text).show();
58
- },
59
-
60
- show_site_key_form: function(){
61
-
62
- if( jQuery(this).hasClass('disabled') ) {
63
- alert( jQuery(this).attr('title') );
64
- return false;
65
- }
66
-
67
- otgs_wp_installer.reset_errors();
68
-
69
- var form = jQuery(this).parent().find('form.otgsi_site_key_form');
70
- jQuery(this).prev().hide();
71
- jQuery(this).hide();
72
- form.css('display', 'inline');
73
- form.find('input[name^=site_key_]').focus().val('');
74
- form.find('input').removeAttr('disabled');
75
-
76
- form.closest('.otgsi_register_product_wrap').addClass('otgsi_yellow_bg');
77
-
78
- return false;
79
- },
80
-
81
- hide_site_key_form: function(){
82
- var form = jQuery(this).closest('form');
83
- form.hide();
84
- form.parent().find('.enter_site_key_js').show();
85
- form.parent().find('.enter_site_key_js').prev().show();
86
-
87
- form.closest('.otgsi_register_product_wrap').removeClass('otgsi_yellow_bg');
88
- otgs_wp_installer.reset_errors();
89
- return false;
90
- },
91
-
92
- save_site_key: function(){
93
-
94
- var thisf = jQuery(this);
95
- var data = jQuery(this).serialize();
96
- jQuery(this).find('input').attr('disabled', 'disabled');
97
-
98
- var spinner = jQuery('<span class="spinner"></span>');
99
- spinner.css({display: 'inline-block', float: 'none'}).prependTo(jQuery(this));
100
-
101
- otgs_wp_installer.reset_errors();
102
-
103
- jQuery.ajax({url: ajaxurl, type: 'POST', dataType:'json', data: data, success:
104
- function(ret){
105
- if(!ret.error){
106
- otgs_wp_installer.saved_site_key();
107
- }else{
108
- otgs_wp_installer.show_error(thisf.find('[name=repository_id]').val(), ret.error);
109
- thisf.find('input').removeAttr('disabled');
110
- }
111
-
112
- if(typeof ret.debug != 'undefined'){
113
- thisf.append('<textarea style="width:100%" rows="20">' + ret.debug + '</textarea>');
114
- }
115
-
116
- spinner.remove();
117
- }
118
- });
119
-
120
- return false;
121
-
122
- },
123
-
124
- saved_site_key: function(){
125
- location.reload();
126
- },
127
-
128
- remove_site_key: function(){
129
-
130
- if( jQuery(this).attr('disabled') == 'disabled' ){
131
-
132
- alert( jQuery(this).attr('title') );
133
- return false;
134
-
135
- } else {
136
-
137
- if(confirm(jQuery(this).data('confirmation'))){
138
-
139
- jQuery('<span class="spinner"></span>').css({visibility: 'visible', float: 'none'}).prependTo(jQuery(this).parent());
140
- data = {action: 'remove_site_key', repository_id: jQuery(this).data('repository'), nonce: jQuery(this).data('nonce')}
141
- jQuery.ajax({url: ajaxurl, type: 'POST', data: data, success: otgs_wp_installer.removed_site_key});
142
- }
143
-
144
- }
145
-
146
- return false;
147
- },
148
-
149
- removed_site_key: function(){
150
- location.reload();
151
- },
152
-
153
- update_site_key: function(){
154
- var error_wrap = jQuery(this).closest('.otgsi_register_product_wrap').find('.installer-error-box');
155
- error_wrap.html('');
156
-
157
- var spinner = jQuery('<span class="spinner"></span>');
158
-
159
- spinner.css({visibility: 'visible', float: 'none'}).prependTo(jQuery(this).parent());
160
- data = {action: 'update_site_key', repository_id: jQuery(this).data('repository'), nonce: jQuery(this).data('nonce')}
161
- jQuery.ajax({
162
- url: ajaxurl,
163
- type: 'POST',
164
- data: data,
165
- dataType: 'json',
166
- complete: function( event, xhr, settings ){
167
- var error = '';
168
- if(xhr == 'success') {
169
- var ret = event.responseJSON;
170
- if(ret.error){
171
- error = ret.error;
172
- }else{
173
- otgs_wp_installer.updated_site_key(ret);
174
- }
175
- }else{
176
- error = 'Error processing request (' + xhr + '). Please try again!';
177
- }
178
-
179
- if( error ){
180
- error_wrap.html('<p>' + error + '</p>').show();
181
- spinner.remove();
182
- }
183
-
184
- }
185
- });
186
-
187
- return false;
188
-
189
- },
190
-
191
- updated_site_key: function(ret){
192
- location.reload();
193
- },
194
-
195
- update_downloads_form: function(){
196
-
197
- var checked = jQuery('.otgsi_downloads_form :checkbox:checked[name="downloads[]"]').length;
198
-
199
- if(checked){
200
- jQuery(this).closest('form').find(':submit, :checkbox[name=activate]').removeAttr('disabled');
201
- }else{
202
- jQuery(this).closest('form').find(':submit, :checkbox[name=activate]').attr('disabled', 'disabled');
203
- }
204
-
205
-
206
- },
207
-
208
- download_downloads: function(){
209
-
210
- var activate = jQuery(this).find(":checkbox:checked[name=activate]").val(),
211
- action_button = jQuery(this).find('input[type="submit"]');
212
- downloads_form = jQuery(this),
213
- idx = 0,
214
- checkboxes = [];
215
-
216
- jQuery(this).find(':checkbox:checked[name="downloads[]"]').each(function(){
217
- if(jQuery(this).attr('disabled')) return;
218
- checkboxes[idx] = jQuery(this);
219
- idx++;
220
- jQuery(this).attr('disabled', 'disabled');
221
- });
222
-
223
- idx = 0;
224
-
225
- if( typeof checkboxes[idx] != 'undefined' ){
226
- download_and_activate( checkboxes[idx] );
227
- action_button.attr('disabled', 'disabled');
228
- }
229
-
230
- function download_and_activate( elem ){
231
-
232
- var this_tr = elem.closest('tr');
233
- var is_update = this_tr.find('.installer-red-text').length;
234
- if(is_update){
235
- var installing = this_tr.find('.installer-status-updating');
236
- var installed = this_tr.find('.installer-status-updated');
237
- }else{
238
- var installing = this_tr.find('.installer-status-installing');
239
- var installed = this_tr.find('.installer-status-installed');
240
-
241
- }
242
- if(activate){
243
- var activating = this_tr.find('.installer-status-activating');
244
- var activated = this_tr.find('.installer-status-activated');
245
- }
246
-
247
- if( this_tr.find('.for_spinner_js .spinner').length > 0 ){
248
- var spinner = this_tr.find('.for_spinner_js .spinner');
249
- }else{
250
- var spinner = this_tr.find('.installer-status-downloading');
251
- }
252
-
253
- otgs_wp_installer.reset_errors();
254
- downloads_form.find('div.installer-status-success').hide();
255
- spinner.css('visibility', 'visible');
256
- installing.show();
257
-
258
- var plugin_name = this_tr.find('.installer_plugin_name').html();
259
- if(is_update){
260
- otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.updating.replace('%s', plugin_name));
261
- }else{
262
- otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.installing.replace('%s', plugin_name));
263
- }
264
-
265
-
266
- data = {
267
- action: 'installer_download_plugin',
268
- data: elem.val(),
269
- activate: activate,
270
- reset_to_channel: downloads_form.find('input[name="reset-to-channel"]').val()
271
- }
272
-
273
- otgs_wp_installer.plugins_update_XHR = jQuery.ajax({
274
- url: ajaxurl,
275
- type: 'POST',
276
- dataType: 'json',
277
- data: data,
278
- success: function(ret){
279
- installing.hide();
280
-
281
- if(!ret.success){
282
- installed.addClass('installer-status-error');
283
- installed.html(
284
- installed.data('fail') +
285
- '<a class="error-details" href="#" title="' + ret.message + '"></a>'
286
- );
287
-
288
- if(ret.message){
289
- installed.closest('.otgs_wp_installer_table')
290
- .find('.installer-error-box')
291
- .html('<p>' + ret.message + '</p>')
292
- .show();
293
- }else{
294
- installed.closest('.otgs_wp_installer_table')
295
- .find('.installer-error-box')
296
- .html('<p>' + downloads_form.find('.installer-revalidate-message').html() + '</p>')
297
- .show();
298
- }
299
-
300
- downloads_form.trigger('installer-update-fail');
301
- }
302
-
303
- installed.show();
304
- spinner.fadeOut();
305
-
306
- if(ret.version){
307
- var updated_version = '<span class="installer-green-text">' + ret.version + '</span>';
308
- if( ret.non_stable ){
309
- updated_version += ' (' + ret.non_stable + ')';
310
- }
311
- this_tr.find('.installer_version_installed').html(updated_version);
312
- }
313
-
314
- if(ret.success && activate){
315
-
316
- otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.activating.replace('%s', plugin_name));
317
- activating.show();
318
- spinner.show();
319
- this_tr.find('.installer-red-text').removeClass('installer-red-text').addClass('installer-green-text').html(ret.version);
320
-
321
- jQuery.ajax({
322
- url: ajaxurl,
323
- type: 'POST',
324
- dataType: 'json',
325
- data: {action: 'installer_activate_plugin', plugin_id: ret.plugin_id, nonce: ret.nonce},
326
- success: function(ret){
327
- activating.hide();
328
- if(!ret.error ){
329
- activated.show();
330
- }
331
-
332
- spinner.fadeOut();
333
-
334
- idx++;
335
- if( typeof checkboxes[idx] != 'undefined' ){
336
- download_and_activate( checkboxes[idx] );
337
- }else{
338
- otgs_wp_installer.hide_download_progress_status(downloads_form);
339
- downloads_form.find('div.installer-status-success').show();
340
- action_button.removeAttr('disabled');
341
-
342
- downloads_form.trigger('installer-update-complete');
343
- }
344
- }
345
- });
346
- }else{
347
- idx++;
348
- if( typeof checkboxes[idx] != 'undefined' ){
349
- download_and_activate( checkboxes[idx] );
350
- }else{
351
- otgs_wp_installer.hide_download_progress_status(downloads_form);
352
- downloads_form.find('div.installer-status-success').show();
353
- action_button.removeAttr('disabled');
354
-
355
- downloads_form.trigger('installer-update-complete');
356
-
357
- }
358
- }
359
- }
360
-
361
- });
362
-
363
- };
364
-
365
- return false;
366
- },
367
-
368
- show_download_progress_status: function(downloads_form, text){
369
-
370
- downloads_form.find('.installer-download-progress-status').html(text).fadeIn();
371
-
372
- },
373
-
374
- hide_download_progress_status: function(downloads_form){
375
-
376
- downloads_form.find('.installer-download-progress-status').html('').fadeOut();
377
-
378
- },
379
-
380
- dismiss_nag: function(){
381
-
382
- var thisa = jQuery(this);
383
-
384
- data = {action: 'installer_dismiss_nag', repository: jQuery(this).data('repository')}
385
-
386
- jQuery.ajax({url: ajaxurl, type: 'POST', dataType:'json', data: data, success:
387
- function(ret){
388
- thisa.closest('.otgs-is-dismissible').remove();
389
- }
390
- });
391
-
392
- return false;
393
- },
394
-
395
- toggle_subpackages: function(){
396
- var list = jQuery(this).closest('td').find('.otgs_wp_installer_subtable');
397
-
398
- if(list.is(':visible')){
399
- list.slideUp('fast');
400
- }else{
401
- list.slideDown('fast');
402
- }
403
-
404
-
405
- return false;
406
-
407
- },
408
-
409
- scroll_to_repository: function(){
410
-
411
- var ref = window.location.hash.replace('#', '');
412
-
413
- if(ref) {
414
- var split = ref.split('/');
415
- var repo = split[0];
416
-
417
- if(typeof split[1] != 'undefined'){
418
- var package = split[1];
419
- var repo_element = jQuery('#repository-' + repo);
420
-
421
-
422
-
423
- if(repo_element.length){
424
-
425
- jQuery('html, body').animate({
426
- scrollTop: repo_element.offset().top
427
- }, 1000);
428
-
429
- var package_element = jQuery('#repository-' + repo +'_' + package);
430
-
431
- if(package_element.length && !package_element.is(':visible')){
432
- package_element.parents('.otgs_wp_installer_subtable').slideDown();
433
- package_element.addClass('installer_highlight_package');
434
- }
435
-
436
- package_element.find('.button-secondary').removeClass('button-secondary').addClass('button-primary');
437
- }
438
- }
439
-
440
- }
441
-
442
- },
443
-
444
- toggle_release_notes: function(){
445
- var handle = jQuery(this);
446
- var tr = handle.closest('tr');
447
- if( tr.next('.installer-release-notes').is(':visible') ){
448
- handle.removeClass('extended');
449
- }else{
450
- handle.addClass('extended');
451
- }
452
- tr.next('.installer-release-notes').fadeToggle();
453
-
454
- return false;
455
- }
456
-
457
-
458
- }
459
-
460
-
461
  jQuery(document).ready(otgs_wp_installer.init);
1
+
2
+
3
+ var otgs_wp_installer = {
4
+
5
+ plugins_update_XHR :{},
6
+
7
+ init: function(){
8
+
9
+ jQuery('.otgs_wp_installer_table').on('click', '.enter_site_key_js', otgs_wp_installer.show_site_key_form);
10
+ jQuery('.otgs_wp_installer_table').on('click', '.cancel_site_key_js', otgs_wp_installer.hide_site_key_form);
11
+
12
+ jQuery('.otgs_wp_installer_table').on('click', '.remove_site_key_js', otgs_wp_installer.remove_site_key);
13
+ jQuery('.otgs_wp_installer_table').on('click', '.update_site_key_js', otgs_wp_installer.update_site_key);
14
+
15
+ jQuery('.otgs_wp_installer_table').on('submit', '.otgsi_site_key_form', otgs_wp_installer.save_site_key);
16
+ jQuery('.otgs_wp_installer_table').on('submit', '.otgsi_downloads_form', otgs_wp_installer.download_downloads);
17
+ jQuery('.otgs_wp_installer_table').on('change', '.otgsi_downloads_form :checkbox[name="downloads[]"]', otgs_wp_installer.update_downloads_form);
18
+
19
+ jQuery('.installer-dismiss-nag').click(otgs_wp_installer.dismiss_nag);
20
+
21
+ jQuery('.otgs_wp_installer_table').on('click', '.installer_expand_button', otgs_wp_installer.toggle_subpackages);
22
+
23
+ otgs_wp_installer.scroll_to_repository();
24
+
25
+ if( typeof pagenow != 'undefined' && pagenow == 'plugins'){
26
+
27
+ jQuery(document).ajaxSuccess(function(event, xhr, settings) {
28
+ var data = otgs_wp_installer.getQueryParameters(settings.data);
29
+ if(typeof data.action != 'undefined' && data.action == 'update-plugin'){
30
+ response = xhr.responseJSON.data;
31
+ if(typeof response.error != 'undefined'){
32
+ var default_error = jQuery('#' + response.slug + '-update .update-message').html();
33
+ jQuery('#' + response.slug + '-update .update-message').html(default_error + ' &raquo;<span class="installer-red-text"> ' + response.error + '</span>');
34
+ }
35
+ }
36
+ return false;
37
+ });
38
+
39
+ }
40
+
41
+ if( typeof pagenow != 'undefined' && pagenow == 'plugin-install' ){
42
+ jQuery( '.plugin-install-tab-commercial .search-plugins' ).remove();
43
+ }
44
+
45
+ jQuery('.installer-table-wrap').on('click', '.js-release-notes', otgs_wp_installer.toggle_release_notes);
46
+ },
47
+
48
+ getQueryParameters : function(str) {
49
+ return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
50
+ },
51
+
52
+ reset_errors: function(){
53
+ jQuery('.installer-error-box').html('').hide();
54
+ },
55
+
56
+ show_error: function(repo, text){
57
+ jQuery('#installer_repo_' + repo).find('.installer-error-box').html(text).show();
58
+ },
59
+
60
+ show_site_key_form: function(){
61
+
62
+ if( jQuery(this).hasClass('disabled') ) {
63
+ alert( jQuery(this).attr('title') );
64
+ return false;
65
+ }
66
+
67
+ otgs_wp_installer.reset_errors();
68
+
69
+ var form = jQuery(this).parent().find('form.otgsi_site_key_form');
70
+ jQuery(this).prev().hide();
71
+ jQuery(this).hide();
72
+ form.css('display', 'inline');
73
+ form.find('input[name^=site_key_]').focus().val('');
74
+ form.find('input').removeAttr('disabled');
75
+
76
+ form.closest('.otgsi_register_product_wrap').addClass('otgsi_yellow_bg');
77
+
78
+ return false;
79
+ },
80
+
81
+ hide_site_key_form: function(){
82
+ var form = jQuery(this).closest('form');
83
+ form.hide();
84
+ form.parent().find('.enter_site_key_js').show();
85
+ form.parent().find('.enter_site_key_js').prev().show();
86
+
87
+ form.closest('.otgsi_register_product_wrap').removeClass('otgsi_yellow_bg');
88
+ otgs_wp_installer.reset_errors();
89
+ return false;
90
+ },
91
+
92
+ save_site_key: function(){
93
+
94
+ var thisf = jQuery(this);
95
+ var data = jQuery(this).serialize();
96
+ jQuery(this).find('input').attr('disabled', 'disabled');
97
+
98
+ var spinner = jQuery('<span class="spinner"></span>');
99
+ spinner.css({display: 'inline-block', float: 'none'}).prependTo(jQuery(this));
100
+
101
+ otgs_wp_installer.reset_errors();
102
+
103
+ jQuery.ajax({url: ajaxurl, type: 'POST', dataType:'json', data: data, success:
104
+ function(ret){
105
+ if(!ret.error){
106
+ otgs_wp_installer.saved_site_key();
107
+ }else{
108
+ otgs_wp_installer.show_error(thisf.find('[name=repository_id]').val(), ret.error);
109
+ thisf.find('input').removeAttr('disabled');
110
+ }
111
+
112
+ if(typeof ret.debug != 'undefined'){
113
+ thisf.append('<textarea style="width:100%" rows="20">' + ret.debug + '</textarea>');
114
+ }
115
+
116
+ spinner.remove();
117
+ }
118
+ });
119
+
120
+ return false;
121
+
122
+ },
123
+
124
+ saved_site_key: function(){
125
+ location.reload();
126
+ },
127
+
128
+ remove_site_key: function(){
129
+
130
+ if( jQuery(this).attr('disabled') == 'disabled' ){
131
+
132
+ alert( jQuery(this).attr('title') );
133
+ return false;
134
+
135
+ } else {
136
+
137
+ if(confirm(jQuery(this).data('confirmation'))){
138
+
139
+ jQuery('<span class="spinner"></span>').css({visibility: 'visible', float: 'none'}).prependTo(jQuery(this).parent());
140
+ data = {action: 'remove_site_key', repository_id: jQuery(this).data('repository'), nonce: jQuery(this).data('nonce')}
141
+ jQuery.ajax({url: ajaxurl, type: 'POST', data: data, success: otgs_wp_installer.removed_site_key});
142
+ }
143
+
144
+ }
145
+
146
+ return false;
147
+ },
148
+
149
+ removed_site_key: function(){
150
+ location.reload();
151
+ },
152
+
153
+ update_site_key: function(){
154
+ var error_wrap = jQuery(this).closest('.otgsi_register_product_wrap').find('.installer-error-box');
155
+ error_wrap.html('');
156
+
157
+ var spinner = jQuery('<span class="spinner"></span>');
158
+
159
+ spinner.css({visibility: 'visible', float: 'none'}).prependTo(jQuery(this).parent());
160
+ data = {action: 'update_site_key', repository_id: jQuery(this).data('repository'), nonce: jQuery(this).data('nonce')}
161
+ jQuery.ajax({
162
+ url: ajaxurl,
163
+ type: 'POST',
164
+ data: data,
165
+ dataType: 'json',
166
+ complete: function( event, xhr, settings ){
167
+ var error = '';
168
+ if(xhr == 'success') {
169
+ var ret = event.responseJSON;
170
+ if(ret.error){
171
+ error = ret.error;
172
+ }else{
173
+ otgs_wp_installer.updated_site_key(ret);
174
+ }
175
+ }else{
176
+ error = 'Error processing request (' + xhr + '). Please try again!';
177
+ }
178
+
179
+ if( error ){
180
+ error_wrap.html('<p>' + error + '</p>').show();
181
+ spinner.remove();
182
+ }
183
+
184
+ }
185
+ });
186
+
187
+ return false;
188
+
189
+ },
190
+
191
+ updated_site_key: function(ret){
192
+ location.reload();
193
+ },
194
+
195
+ update_downloads_form: function(){
196
+
197
+ var checked = jQuery('.otgsi_downloads_form :checkbox:checked[name="downloads[]"]').length;
198
+
199
+ if(checked){
200
+ jQuery(this).closest('form').find(':submit, :checkbox[name=activate]').removeAttr('disabled');
201
+ }else{
202
+ jQuery(this).closest('form').find(':submit, :checkbox[name=activate]').attr('disabled', 'disabled');
203
+ }
204
+
205
+
206
+ },
207
+
208
+ download_downloads: function(){
209
+
210
+ var activate = jQuery(this).find(":checkbox:checked[name=activate]").val(),
211
+ action_button = jQuery(this).find('input[type="submit"]');
212
+ downloads_form = jQuery(this),
213
+ idx = 0,
214
+ checkboxes = [];
215
+
216
+ jQuery(this).find(':checkbox:checked[name="downloads[]"]').each(function(){
217
+ if(jQuery(this).attr('disabled')) return;
218
+ checkboxes[idx] = jQuery(this);
219
+ idx++;
220
+ jQuery(this).attr('disabled', 'disabled');
221
+ });
222
+
223
+ idx = 0;
224
+
225
+ if( typeof checkboxes[idx] != 'undefined' ){
226
+ download_and_activate( checkboxes[idx] );
227
+ action_button.attr('disabled', 'disabled');
228
+ }
229
+
230
+ function download_and_activate( elem ){
231
+
232
+ var this_tr = elem.closest('tr');
233
+ var is_update = this_tr.find('.installer-red-text').length;
234
+ if(is_update){
235
+ var installing = this_tr.find('.installer-status-updating');
236
+ var installed = this_tr.find('.installer-status-updated');
237
+ }else{
238
+ var installing = this_tr.find('.installer-status-installing');
239
+ var installed = this_tr.find('.installer-status-installed');
240
+
241
+ }
242
+ if(activate){
243
+ var activating = this_tr.find('.installer-status-activating');
244
+ var activated = this_tr.find('.installer-status-activated');
245
+ }
246
+
247
+ if( this_tr.find('.for_spinner_js .spinner').length > 0 ){
248
+ var spinner = this_tr.find('.for_spinner_js .spinner');
249
+ }else{
250
+ var spinner = this_tr.find('.installer-status-downloading');
251
+ }
252
+
253
+ otgs_wp_installer.reset_errors();
254
+ downloads_form.find('div.installer-status-success').hide();
255
+ spinner.css('visibility', 'visible');
256
+ installing.show();
257
+
258
+ var plugin_name = this_tr.find('.installer_plugin_name').html();
259
+ if(is_update){
260
+ otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.updating.replace('%s', plugin_name));
261
+ }else{
262
+ otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.installing.replace('%s', plugin_name));
263
+ }
264
+
265
+
266
+ data = {
267
+ action: 'installer_download_plugin',
268
+ data: elem.val(),
269
+ activate: activate,
270
+ reset_to_channel: downloads_form.find('input[name="reset-to-channel"]').val()
271
+ }
272
+
273
+ otgs_wp_installer.plugins_update_XHR = jQuery.ajax({
274
+ url: ajaxurl,
275
+ type: 'POST',
276
+ dataType: 'json',
277
+ data: data,
278
+ success: function(ret){
279
+ installing.hide();
280
+
281
+ if(!ret.success){
282
+ installed.addClass('installer-status-error');
283
+ installed.html(
284
+ installed.data('fail') +
285
+ '<a class="error-details" href="#" title="' + ret.message + '"></a>'
286
+ );
287
+
288
+ if(ret.message){
289
+ installed.closest('.otgs_wp_installer_table')
290
+ .find('.installer-error-box')
291
+ .html('<p>' + ret.message + '</p>')
292
+ .show();
293
+ }else{
294
+ installed.closest('.otgs_wp_installer_table')
295
+ .find('.installer-error-box')
296
+ .html('<p>' + downloads_form.find('.installer-revalidate-message').html() + '</p>')
297
+ .show();
298
+ }
299
+
300
+ downloads_form.trigger('installer-update-fail');
301
+ }
302
+
303
+ installed.show();
304
+ spinner.fadeOut();
305
+
306
+ if(ret.version){
307
+ var updated_version = '<span class="installer-green-text">' + ret.version + '</span>';
308
+ if( ret.non_stable ){
309
+ updated_version += ' (' + ret.non_stable + ')';
310
+ }
311
+ this_tr.find('.installer_version_installed').html(updated_version);
312
+ }
313
+
314
+ if(ret.success && activate){
315
+
316
+ otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.activating.replace('%s', plugin_name));
317
+ activating.show();
318
+ spinner.show();
319
+ this_tr.find('.installer-red-text').removeClass('installer-red-text').addClass('installer-green-text').html(ret.version);
320
+
321
+ jQuery.ajax({
322
+ url: ajaxurl,
323
+ type: 'POST',
324
+ dataType: 'json',
325
+ data: {action: 'installer_activate_plugin', plugin_id: ret.plugin_id, nonce: ret.nonce},
326
+ success: function(ret){
327
+ activating.hide();
328
+ if(!ret.error ){
329
+ activated.show();
330
+ }
331
+
332
+ spinner.fadeOut();
333
+
334
+ idx++;
335
+ if( typeof checkboxes[idx] != 'undefined' ){
336
+ download_and_activate( checkboxes[idx] );
337
+ }else{
338
+ otgs_wp_installer.hide_download_progress_status(downloads_form);
339
+ downloads_form.find('div.installer-status-success').show();
340
+ action_button.removeAttr('disabled');
341
+
342
+ downloads_form.trigger('installer-update-complete');
343
+ }
344
+ }
345
+ });
346
+ }else{
347
+ idx++;
348
+ if( typeof checkboxes[idx] != 'undefined' ){
349
+ download_and_activate( checkboxes[idx] );
350
+ }else{
351
+ otgs_wp_installer.hide_download_progress_status(downloads_form);
352
+ downloads_form.find('div.installer-status-success').show();
353
+ action_button.removeAttr('disabled');
354
+
355
+ downloads_form.trigger('installer-update-complete');
356
+
357
+ }
358
+ }
359
+ }
360
+
361
+ });
362
+
363
+ };
364
+
365
+ return false;
366
+ },
367
+
368
+ show_download_progress_status: function(downloads_form, text){
369
+
370
+ downloads_form.find('.installer-download-progress-status').html(text).fadeIn();
371
+
372
+ },
373
+
374
+ hide_download_progress_status: function(downloads_form){
375
+
376
+ downloads_form.find('.installer-download-progress-status').html('').fadeOut();
377
+
378
+ },
379
+
380
+ dismiss_nag: function(){
381
+
382
+ var thisa = jQuery(this);
383
+
384
+ data = {action: 'installer_dismiss_nag', repository: jQuery(this).data('repository')}
385
+
386
+ jQuery.ajax({url: ajaxurl, type: 'POST', dataType:'json', data: data, success:
387
+ function(ret){
388
+ thisa.closest('.otgs-is-dismissible').remove();
389
+ }
390
+ });
391
+
392
+ return false;
393
+ },
394
+
395
+ toggle_subpackages: function(){
396
+ var list = jQuery(this).closest('td').find('.otgs_wp_installer_subtable');
397
+
398
+ if(list.is(':visible')){
399
+ list.slideUp('fast');
400
+ }else{
401
+ list.slideDown('fast');
402
+ }
403
+
404
+
405
+ return false;
406
+
407
+ },
408
+
409
+ scroll_to_repository: function(){
410
+
411
+ var ref = window.location.hash.replace('#', '');
412
+
413
+ if(ref) {
414
+ var split = ref.split('/');
415
+ var repo = split[0];
416
+
417
+ if(typeof split[1] != 'undefined'){
418
+ var package = split[1];
419
+ var repo_element = jQuery('#repository-' + repo);
420
+
421
+
422
+
423
+ if(repo_element.length){
424
+
425
+ jQuery('html, body').animate({
426
+ scrollTop: repo_element.offset().top
427
+ }, 1000);
428
+
429
+ var package_element = jQuery('#repository-' + repo +'_' + package);
430
+
431
+ if(package_element.length && !package_element.is(':visible')){
432
+ package_element.parents('.otgs_wp_installer_subtable').slideDown();
433
+ package_element.addClass('installer_highlight_package');
434
+ }
435
+
436
+ package_element.find('.button-secondary').removeClass('button-secondary').addClass('button-primary');
437
+ }
438
+ }
439
+
440
+ }
441
+
442
+ },
443
+
444
+ toggle_release_notes: function(){
445
+ var handle = jQuery(this);
446
+ var tr = handle.closest('tr');
447
+ if( tr.next('.installer-release-notes').is(':visible') ){
448
+ handle.removeClass('extended');
449
+ }else{
450
+ handle.addClass('extended');
451
+ }
452
+ tr.next('.installer-release-notes').fadeToggle();
453
+
454
+ return false;
455
+ }
456
+
457
+
458
+ }
459
+
460
+
461
  jQuery(document).ready(otgs_wp_installer.init);
vendor/otgs/installer/res/js/channels.js CHANGED
@@ -1,261 +1,261 @@
1
- (function($){
2
-
3
- var updateErrors = [];
4
- var channelUpdateInProgress = false;
5
-
6
- function channelSelectorInit(){
7
-
8
- $('.otgs_wp_installer_table')
9
- .on('focus', '.installer-channel-selector', saveCurrentValue)
10
- .on('change', '.installer-channel-selector', maybeShowPrompt);
11
-
12
- $('.otgs_wp_installer_table')
13
- .on('click', '.installer-channel-retry', retryChannelSwitch)
14
-
15
- $('.installer-switch-confirmation')
16
- .on('click', '.js-cancel', cancelSwitch)
17
- .on('click', '.js-proceed', changeChannel);
18
-
19
- $('.otgsi_downloads_form').on('installer-update-complete', maybeShowWarn);
20
- $('.otgsi_downloads_form').on('installer-update-complete', hideUpdateProgress);
21
-
22
- $('.otgsi_downloads_form').on('installer-update-complete', showConfirmationMessage);
23
-
24
- $('.otgsi_downloads_form').on('installer-update-fail', logUpdateError);
25
-
26
- }
27
-
28
- function saveCurrentValue(){
29
- $(this).data('previous-value', $(this).val());
30
- }
31
-
32
- function maybeShowPrompt(){
33
- var selectorContainer = $(this).closest('.installer-channel-selector-wrap');
34
- var prompt = selectorContainer.find('.installer-switch-confirmation:hidden');
35
-
36
- if(prompt.length){
37
- prompt.show();
38
- selectorContainer.find('select').prop('disabled', true);
39
- var warnText = selectorContainer.find('.installer-warn-text');
40
- warnText.hide();
41
- }else{
42
- changeChannel(selectorContainer);
43
- }
44
-
45
- }
46
-
47
- function changeChannel(selectorContainer){
48
-
49
- if(selectorContainer.type == 'click'){
50
- var selectorContainer = $(this).closest('.installer-channel-selector-wrap');
51
- }
52
-
53
- var select = selectorContainer.find('select');
54
- select.prop('disabled', true);
55
-
56
- hideConfirmationMessage(select);
57
- showUpdateProgress(select);
58
-
59
- selectorContainer.find('.installer-switch-confirmation').hide();
60
-
61
- var data = {
62
- action: 'installer_set_channel',
63
- repository_id: select.data('repository-id'),
64
- channel: select.val(),
65
- nonce: select.parent().find('.nonce').val(),
66
- noprompt: selectorContainer.find('.js-remember').length ?
67
- selectorContainer.find('.js-remember').attr('checked') == 'checked' : 0
68
- }
69
-
70
- resetUpdateErrors();
71
- otgs_wp_installer.reset_errors();
72
- channelUpdateInProgress = true;
73
-
74
- // save selection
75
- jQuery.ajax({
76
- url: ajaxurl,
77
- type: 'POST',
78
- dataType: 'json',
79
- data: data,
80
- success: function (ret) {
81
- if( ret.status == 'OK'){
82
- var tableSelector = '#installer_repo_' + select.data('repository-id') + ' .installer-table-wrap';
83
- $(tableSelector).load( location.href + ' ' + tableSelector + ' table.widefat', function(){
84
-
85
- var upgradesCount = $(tableSelector).find('tr .installer-red-text').length
86
- || select.val() == 1 && $(tableSelector).find('td.installer_version_installed .unstable').length;
87
- if( upgradesCount > 0){
88
- automaticUpgrade(tableSelector);
89
- }else{
90
- $('#installer_repo_' + select.data('repository-id') + ' .otgsi_downloads_form')
91
- .trigger('installer-update-complete');
92
- }
93
-
94
- select.prop('disabled', false);
95
- } );
96
- }
97
-
98
- }
99
-
100
- });
101
-
102
- }
103
-
104
- function retryChannelSwitch(){
105
- var selectorContainer = $(this).closest('.installer-channel-selector-wrap');
106
- changeChannel(selectorContainer);
107
- return false;
108
- }
109
-
110
- function cancelSwitch(){
111
- $(this).closest('.installer-switch-confirmation').hide();
112
- var select = $(this).closest('.installer-switch-confirmation').prev().find('.installer-channel-selector');
113
- var previousValue = select.data('previous-value');
114
-
115
- select.val(previousValue).prop('disabled', false);
116
-
117
- if( select.val() > 1){
118
- var selectorContainer = $(this).closest('.installer-channel-selector-wrap');
119
- var warnText = selectorContainer.find('.installer-warn-text');
120
- warnText.show();
121
- }
122
-
123
- }
124
-
125
- function automaticUpgrade(downloadsTable){
126
- $(downloadsTable + ' tr').each(
127
- function () {
128
- var needsUpgrade = $(this).find(
129
- 'td.installer_version_installed .installer-red-text, ' +
130
- 'td.installer_version_installed .unstable'
131
- ).length > 0;
132
- if (needsUpgrade) {
133
- $(this).find('td :checkbox').prop('disabled', false).prop('checked', true);
134
- }
135
- }
136
- );
137
-
138
- $(downloadsTable)
139
- .closest('form')
140
- .append('<input type="hidden" name="reset-to-channel" value="1">')
141
- .submit();
142
-
143
- }
144
-
145
- function maybeShowWarn(){
146
-
147
- var select = $(this)
148
- .closest('.otgs_wp_installer_table')
149
- .find('.installer-channel-selector')
150
-
151
- if(select.val() > 1 && !hasUpdateErrors()){
152
-
153
- var warnText = select
154
- .closest('.installer-channel-selector-wrap')
155
- .find('.installer-warn-text');
156
- warnText.show();
157
-
158
- }
159
-
160
-
161
- }
162
-
163
- function showUpdateProgress(select){
164
-
165
- var spinner = select
166
- .closest('.installer-channel-selector-wrap')
167
- .find('.spinner-with-text');
168
-
169
- spinner.addClass('is-active').show();
170
-
171
- }
172
-
173
- function hideUpdateProgress(){
174
-
175
- var spinner = $(this)
176
- .closest('.otgs_wp_installer_table')
177
- .find('.installer-channel-selector-wrap')
178
- .find('.spinner-with-text');
179
-
180
- spinner.removeClass('is-active').hide();
181
-
182
- }
183
-
184
- function showConfirmationMessage(){
185
-
186
- if( ! channelUpdateInProgress ) return false;
187
-
188
- var selectWrap = $(this)
189
- .closest('.otgs_wp_installer_table')
190
- .find('.installer-channel-selector-wrap');
191
-
192
- var select = $(this)
193
- .closest('.otgs_wp_installer_table')
194
- .find('.installer-channel-selector');
195
-
196
- var channelName = select.find('option:selected').text();
197
-
198
- if( hasUpdateErrors() ) {
199
-
200
- var message = selectWrap.find('.installer-channel-update-fail');
201
- // suppress default errors
202
- $(this).closest('.otgs_wp_installer_table').find('.installer-error-box').hide();
203
-
204
- var channelType = select.val() == 1 ? 'stable' : 'unstable';
205
- message.html(message.data('text-' + channelType).replace(/%CHANNEL%/, channelName));
206
-
207
- }else{
208
-
209
- var message = selectWrap.find('.installer-channel-update-ok');
210
- message.html(message.data('text').replace(/%CHANNEL%/, channelName));
211
- }
212
-
213
- message.show();
214
-
215
- channelUpdateInProgress = false;
216
- }
217
-
218
- function hideConfirmationMessage(select){
219
-
220
- var selectWrap = select.closest('.installer-channel-selector-wrap');
221
- if( hasUpdateErrors() ){
222
- var message = selectWrap.find('.installer-channel-update-fail');
223
- }else{
224
- var message = selectWrap.find('.installer-channel-update-ok');
225
- }
226
-
227
- message.hide();
228
- }
229
-
230
- /*
231
- function showFailureMessage(download_form){
232
- var message = download_form
233
- .closest('.otgs_wp_installer_table')
234
- .find('.installer-channel-selector-wrap')
235
- .find('.installer-channel-update-fail');
236
-
237
- var channelName = $(this)
238
- .closest('.otgs_wp_installer_table')
239
- .find('.installer-channel-selector option:selected')
240
- .text();
241
-
242
- message.html( message.data('text').replace(/%CHANNEL%/, channelName) );
243
- message.show();
244
- }
245
- */
246
-
247
- function logUpdateError(){
248
- updateErrors.push(1);
249
- }
250
-
251
- function resetUpdateErrors(){
252
- updateErrors = [];
253
- }
254
-
255
- function hasUpdateErrors() {
256
- return updateErrors.length;
257
- }
258
-
259
- $(document).ready( channelSelectorInit );
260
-
261
  })(jQuery)
1
+ (function($){
2
+
3
+ var updateErrors = [];
4
+ var channelUpdateInProgress = false;
5
+
6
+ function channelSelectorInit(){
7
+
8
+ $('.otgs_wp_installer_table')
9
+ .on('focus', '.installer-channel-selector', saveCurrentValue)
10
+ .on('change', '.installer-channel-selector', maybeShowPrompt);
11
+
12
+ $('.otgs_wp_installer_table')
13
+ .on('click', '.installer-channel-retry', retryChannelSwitch)
14
+
15
+ $('.installer-switch-confirmation')
16
+ .on('click', '.js-cancel', cancelSwitch)
17
+ .on('click', '.js-proceed', changeChannel);
18
+
19
+ $('.otgsi_downloads_form').on('installer-update-complete', maybeShowWarn);
20
+ $('.otgsi_downloads_form').on('installer-update-complete', hideUpdateProgress);
21
+
22
+ $('.otgsi_downloads_form').on('installer-update-complete', showConfirmationMessage);
23
+
24
+ $('.otgsi_downloads_form').on('installer-update-fail', logUpdateError);
25
+
26
+ }
27
+
28
+ function saveCurrentValue(){
29
+ $(this).data('previous-value', $(this).val());
30
+ }
31
+
32
+ function maybeShowPrompt(){
33
+ var selectorContainer = $(this).closest('.installer-channel-selector-wrap');
34
+ var prompt = selectorContainer.find('.installer-switch-confirmation:hidden');
35
+
36
+ if(prompt.length){
37
+ prompt.show();
38
+ selectorContainer.find('select').prop('disabled', true);
39
+ var warnText = selectorContainer.find('.installer-warn-text');
40
+ warnText.hide();
41
+ }else{
42
+ changeChannel(selectorContainer);
43
+ }
44
+
45
+ }
46
+
47
+ function changeChannel(selectorContainer){
48
+
49
+ if(selectorContainer.type == 'click'){
50
+ var selectorContainer = $(this).closest('.installer-channel-selector-wrap');
51
+ }
52
+
53
+ var select = selectorContainer.find('select');
54
+ select.prop('disabled', true);
55
+
56
+ hideConfirmationMessage(select);
57
+ showUpdateProgress(select);
58
+
59
+ selectorContainer.find('.installer-switch-confirmation').hide();
60
+
61
+ var data = {
62
+ action: 'installer_set_channel',
63
+ repository_id: select.data('repository-id'),
64
+ channel: select.val(),
65
+ nonce: select.parent().find('.nonce').val(),
66
+ noprompt: selectorContainer.find('.js-remember').length ?
67
+ selectorContainer.find('.js-remember').attr('checked') == 'checked' : 0
68
+ }
69
+
70
+ resetUpdateErrors();
71
+ otgs_wp_installer.reset_errors();
72
+ channelUpdateInProgress = true;
73
+
74
+ // save selection
75
+ jQuery.ajax({
76
+ url: ajaxurl,
77
+ type: 'POST',
78
+ dataType: 'json',
79
+ data: data,
80
+ success: function (ret) {
81
+ if( ret.status == 'OK'){
82
+ var tableSelector = '#installer_repo_' + select.data('repository-id') + ' .installer-table-wrap';
83
+ $(tableSelector).load( location.href + ' ' + tableSelector + ' table.widefat', function(){
84
+
85
+ var upgradesCount = $(tableSelector).find('tr .installer-red-text').length
86
+ || select.val() == 1 && $(tableSelector).find('td.installer_version_installed .unstable').length;
87
+ if( upgradesCount > 0){
88
+ automaticUpgrade(tableSelector);
89
+ }else{
90
+ $('#installer_repo_' + select.data('repository-id') + ' .otgsi_downloads_form')
91
+ .trigger('installer-update-complete');
92
+ }
93
+
94
+ select.prop('disabled', false);
95
+ } );
96
+ }
97
+
98
+ }
99
+
100
+ });
101
+
102
+ }
103
+
104
+ function retryChannelSwitch(){
105
+ var selectorContainer = $(this).closest('.installer-channel-selector-wrap');
106
+ changeChannel(selectorContainer);
107
+ return false;
108
+ }
109
+
110
+ function cancelSwitch(){
111
+ $(this).closest('.installer-switch-confirmation').hide();
112
+ var select = $(this).closest('.installer-switch-confirmation').prev().find('.installer-channel-selector');
113
+ var previousValue = select.data('previous-value');
114
+
115
+ select.val(previousValue).prop('disabled', false);
116
+
117
+ if( select.val() > 1){
118
+ var selectorContainer = $(this).closest('.installer-channel-selector-wrap');
119
+ var warnText = selectorContainer.find('.installer-warn-text');
120
+ warnText.show();
121
+ }
122
+
123
+ }
124
+
125
+ function automaticUpgrade(downloadsTable){
126
+ $(downloadsTable + ' tr').each(
127
+ function () {
128
+ var needsUpgrade = $(this).find(
129
+ 'td.installer_version_installed .installer-red-text, ' +
130
+ 'td.installer_version_installed .unstable'
131
+ ).length > 0;
132
+ if (needsUpgrade) {
133
+ $(this).find('td :checkbox').prop('disabled', false).prop('checked', true);
134
+ }
135
+ }
136
+ );
137
+
138
+ $(downloadsTable)
139
+ .closest('form')
140
+ .append('<input type="hidden" name="reset-to-channel" value="1">')
141
+ .submit();
142
+
143
+ }
144
+
145
+ function maybeShowWarn(){
146
+
147
+ var select = $(this)
148
+ .closest('.otgs_wp_installer_table')
149
+ .find('.installer-channel-selector')
150
+
151
+ if(select.val() > 1 && !hasUpdateErrors()){
152
+
153
+ var warnText = select
154
+ .closest('.installer-channel-selector-wrap')
155
+ .find('.installer-warn-text');
156
+ warnText.show();
157
+
158
+ }
159
+
160
+
161
+ }
162
+
163
+ function showUpdateProgress(select){
164
+
165
+ var spinner = select
166
+ .closest('.installer-channel-selector-wrap')
167
+ .find('.spinner-with-text');
168
+
169
+ spinner.addClass('is-active').show();
170
+
171
+ }
172
+
173
+ function hideUpdateProgress(){
174
+
175
+ var spinner = $(this)
176
+ .closest('.otgs_wp_installer_table')
177
+ .find('.installer-channel-selector-wrap')
178
+ .find('.spinner-with-text');
179
+
180
+ spinner.removeClass('is-active').hide();
181
+
182
+ }
183
+
184
+ function showConfirmationMessage(){
185
+
186
+ if( ! channelUpdateInProgress ) return false;
187
+
188
+ var selectWrap = $(this)
189
+ .closest('.otgs_wp_installer_table')
190
+ .find('.installer-channel-selector-wrap');
191
+
192
+ var select = $(this)
193
+ .closest('.otgs_wp_installer_table')
194
+ .find('.installer-channel-selector');
195
+
196
+ var channelName = select.find('option:selected').text();
197
+
198
+ if( hasUpdateErrors() ) {
199
+
200
+ var message = selectWrap.find('.installer-channel-update-fail');
201
+ // suppress default errors
202
+ $(this).closest('.otgs_wp_installer_table').find('.installer-error-box').hide();
203
+
204
+ var channelType = select.val() == 1 ? 'stable' : 'unstable';
205
+ message.html(message.data('text-' + channelType).replace(/%CHANNEL%/, channelName));
206
+
207
+ }else{
208
+
209
+ var message = selectWrap.find('.installer-channel-update-ok');
210
+ message.html(message.data('text').replace(/%CHANNEL%/, channelName));
211
+ }
212
+
213
+ message.show();
214
+
215
+ channelUpdateInProgress = false;
216
+ }
217
+
218
+ function hideConfirmationMessage(select){
219
+
220
+ var selectWrap = select.closest('.installer-channel-selector-wrap');
221
+ if( hasUpdateErrors() ){
222
+ var message = selectWrap.find('.installer-channel-update-fail');
223
+ }else{
224
+ var message = selectWrap.find('.installer-channel-update-ok');
225
+ }
226
+
227
+ message.hide();
228
+ }
229
+
230
+ /*
231
+ function showFailureMessage(download_form){
232
+ var message = download_form
233
+ .closest('.otgs_wp_installer_table')
234
+ .find('.installer-channel-selector-wrap')
235
+ .find('.installer-channel-update-fail');
236
+
237
+ var channelName = $(this)
238
+ .closest('.otgs_wp_installer_table')
239
+ .find('.installer-channel-selector option:selected')
240
+ .text();
241
+
242
+ message.html( message.data('text').replace(/%CHANNEL%/, channelName) );
243
+ message.show();
244
+ }
245
+ */
246
+
247
+ function logUpdateError(){
248
+ updateErrors.push(1);
249
+ }
250
+
251
+ function resetUpdateErrors(){
252
+ updateErrors = [];
253
+ }
254
+
255
+ function hasUpdateErrors() {
256
+ return updateErrors.length;
257
+ }
258
+
259
+ $(document).ready( channelSelectorInit );
260
+
261
  })(jQuery)
vendor/otgs/installer/res/js/iframeResizer.min.js CHANGED
@@ -1,10 +1,10 @@
1
- /*! iFrame Resizer (iframeSizer.min.js ) - v2.6.1 - 2014-09-03
2
- * Desc: Force cross domain iframes to size to content.
3
- * Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame.
4
- * Copyright: (c) 2014 David J. Bradshaw - dave@bradshaw.net
5
- * License: MIT
6
- */
7
-
8
- !function(){"use strict";function a(a,b,c){"addEventListener"in window?a.addEventListener(b,c,!1):"attachEvent"in window&&a.attachEvent("on"+b,c)}function b(){var a,b=["moz","webkit","o","ms"];for(a=0;a<b.length&&!w;a+=1)w=window[b[a]+"RequestAnimationFrame"];w||c(" RequestAnimationFrame not supported")}function c(a){y.log&&"object"==typeof console&&console.log(s+"[Host page"+u+"]"+a)}function d(a){function b(){function a(){h(z),f(),y.resizedCallback(z)}i(a,z,"resetPage")}function d(a){var b=a.id;c(" Removing iFrame: "+b),a.parentNode.removeChild(a),y.closedCallback(b),c(" --")}function e(){var a=x.substr(t).split(":");return{iframe:document.getElementById(a[0]),id:a[0],height:a[1],width:a[2],type:a[3]}}function j(a){var b=Number(y["max"+a]),d=Number(y["min"+a]),e=a.toLowerCase(),f=Number(z[e]);if(d>b)throw new Error("Value for min"+a+" can not be greater than max"+a);c(" Checking "+e+" is in range "+d+"-"+b),d>f&&(f=d,c(" Set "+e+" to min value")),f>b&&(f=b,c(" Set "+e+" to max value")),z[e]=""+f}function k(){var b=a.origin,d=z.iframe.src.split("/").slice(0,3).join("/");if(y.checkOrigin&&(c(" Checking connection is from: "+d),""+b!="null"&&b!==d))throw new Error("Unexpected message received from: "+b+" for "+z.iframe.id+". Message was: "+a.data+". This error can be disabled by adding the checkOrigin: false option.");return!0}function l(){return s===(""+x).substr(0,t)}function m(){var a=z.type in{"true":1,"false":1};return a&&c(" Ignoring init message from meta parent page"),a}function n(){var a=x.substr(x.indexOf(":")+r+6);c(" MessageCallback passed: {iframe: "+z.iframe.id+", message: "+a+"}"),y.messageCallback({iframe:z.iframe,message:a}),c(" --")}function o(){if(null===z.iframe)throw new Error("iFrame ("+z.id+") does not exist on "+u);return!0}function q(){c(" Reposition requested from iFrame"),v={x:z.width,y:z.height},f()}function w(){switch(z.type){case"close":d(z.iframe),y.resizedCallback(z);break;case"message":n();break;case"scrollTo":q();break;case"reset":g(z);break;case"init":b(),y.initCallback(z.iframe);break;default:b()}}var x=a.data,z={};l()&&(c(" Received: "+x),z=e(),j("Height"),j("Width"),!m()&&o()&&k()&&(w(),p=!1))}function e(){null===v&&(v={x:void 0!==window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft,y:void 0!==window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},c(" Get position: "+v.x+","+v.y))}function f(){null!==v&&(window.scrollTo(v.x,v.y),c(" Set position: "+v.x+","+v.y),v=null)}function g(a){function b(){h(a),j("reset","reset",a.iframe)}c(" Size reset requested by "+("init"===a.type?"host page":"iFrame")),e(),i(b,a,"init")}function h(a){function b(b){a.iframe.style[b]=a[b]+"px",c(" IFrame ("+a.iframe.id+") "+b+" set to "+a[b]+"px")}y.sizeHeight&&b("height"),y.sizeWidth&&b("width")}function i(a,b,d){d!==b.type&&w?(c(" Requesting animation frame"),w(a)):a()}function j(a,b,d){c("["+a+"] Sending msg to iframe ("+b+")"),d.contentWindow.postMessage(s+b,"*")}function k(){function b(){function a(a){1/0!==y[a]&&0!==y[a]&&(k.style[a]=y[a]+"px",c(" Set "+a+" = "+y[a]+"px"))}a("maxHeight"),a("minHeight"),a("maxWidth"),a("minWidth")}function d(a){return""===a&&(k.id=a="iFrameResizer"+o++,c(" Added missing iframe ID: "+a+" ("+k.src+")")),a}function e(){c(" IFrame scrolling "+(y.scrolling?"enabled":"disabled")+" for "+l),k.style.overflow=!1===y.scrolling?"hidden":"auto",k.scrolling=!1===y.scrolling?"no":"yes"}function f(){("number"==typeof y.bodyMargin||"0"===y.bodyMargin)&&(y.bodyMarginV1=y.bodyMargin,y.bodyMargin=""+y.bodyMargin+"px")}function h(){return l+":"+y.bodyMarginV1+":"+y.sizeWidth+":"+y.log+":"+y.interval+":"+y.enablePublicMethods+":"+y.autoResize+":"+y.bodyMargin+":"+y.heightCalculationMethod+":"+y.bodyBackground+":"+y.bodyPadding+":"+y.tolerance}function i(b){a(k,"load",function(){var a=p;j("iFrame.onload",b,k),!a&&y.heightCalculationMethod in x&&g({iframe:k,height:0,width:0,type:"init"})}),j("init",b,k)}var k=this,l=d(k.id);e(),b(),f(),i(h())}function l(a){if("object"!=typeof a)throw new TypeError("Options is not an object.")}function m(){function a(a){if("IFRAME"!==a.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+a.tagName+">.");k.call(a)}function b(a){a=a||{},l(a);for(var b in z)z.hasOwnProperty(b)&&(y[b]=a.hasOwnProperty(b)?a[b]:z[b])}return function(c,d){b(c),Array.prototype.forEach.call(document.querySelectorAll(d||"iframe"),a)}}function n(a){a.fn.iFrameResize=function(b){return b=b||{},l(b),y=a.extend({},z,b),this.filter("iframe").each(k).end()}}var o=0,p=!0,q="message",r=q.length,s="[iFrameSizer]",t=s.length,u="",v=null,w=window.requestAnimationFrame,x={max:1,scroll:1,bodyScroll:1,documentElementScroll:1},y={},z={autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,enablePublicMethods:!1,heightCalculationMethod:"offset",interval:32,log:!1,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,closedCallback:function(){},initCallback:function(){},messageCallback:function(){},resizedCallback:function(){}};b(),a(window,"message",d),"jQuery"in window&&n(jQuery),"function"==typeof define&&define.amd?define(function(){return m()}):window.iFrameResize=m()}();
9
- //# sourceMappingURL=../src/iframeResizer.map
10
-
1
+ /*! iFrame Resizer (iframeSizer.min.js ) - v2.6.1 - 2014-09-03
2
+ * Desc: Force cross domain iframes to size to content.
3
+ * Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame.
4
+ * Copyright: (c) 2014 David J. Bradshaw - dave@bradshaw.net
5
+ * License: MIT
6
+ */
7
+
8
+ !function(){"use strict";function a(a,b,c){"addEventListener"in window?a.addEventListener(b,c,!1):"attachEvent"in window&&a.attachEvent("on"+b,c)}function b(){var a,b=["moz","webkit","o","ms"];for(a=0;a<b.length&&!w;a+=1)w=window[b[a]+"RequestAnimationFrame"];w||c(" RequestAnimationFrame not supported")}function c(a){y.log&&"object"==typeof console&&console.log(s+"[Host page"+u+"]"+a)}function d(a){function b(){function a(){h(z),f(),y.resizedCallback(z)}i(a,z,"resetPage")}function d(a){var b=a.id;c(" Removing iFrame: "+b),a.parentNode.removeChild(a),y.closedCallback(b),c(" --")}function e(){var a=x.substr(t).split(":");return{iframe:document.getElementById(a[0]),id:a[0],height:a[1],width:a[2],type:a[3]}}function j(a){var b=Number(y["max"+a]),d=Number(y["min"+a]),e=a.toLowerCase(),f=Number(z[e]);if(d>b)throw new Error("Value for min"+a+" can not be greater than max"+a);c(" Checking "+e+" is in range "+d+"-"+b),d>f&&(f=d,c(" Set "+e+" to min value")),f>b&&(f=b,c(" Set "+e+" to max value")),z[e]=""+f}function k(){var b=a.origin,d=z.iframe.src.split("/").slice(0,3).join("/");if(y.checkOrigin&&(c(" Checking connection is from: "+d),""+b!="null"&&b!==d))throw new Error("Unexpected message received from: "+b+" for "+z.iframe.id+". Message was: "+a.data+". This error can be disabled by adding the checkOrigin: false option.");return!0}function l(){return s===(""+x).substr(0,t)}function m(){var a=z.type in{"true":1,"false":1};return a&&c(" Ignoring init message from meta parent page"),a}function n(){var a=x.substr(x.indexOf(":")+r+6);c(" MessageCallback passed: {iframe: "+z.iframe.id+", message: "+a+"}"),y.messageCallback({iframe:z.iframe,message:a}),c(" --")}function o(){if(null===z.iframe)throw new Error("iFrame ("+z.id+") does not exist on "+u);return!0}function q(){c(" Reposition requested from iFrame"),v={x:z.width,y:z.height},f()}function w(){switch(z.type){case"close":d(z.iframe),y.resizedCallback(z);break;case"message":n();break;case"scrollTo":q();break;case"reset":g(z);break;case"init":b(),y.initCallback(z.iframe);break;default:b()}}var x=a.data,z={};l()&&(c(" Received: "+x),z=e(),j("Height"),j("Width"),!m()&&o()&&k()&&(w(),p=!1))}function e(){null===v&&(v={x:void 0!==window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft,y:void 0!==window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},c(" Get position: "+v.x+","+v.y))}function f(){null!==v&&(window.scrollTo(v.x,v.y),c(" Set position: "+v.x+","+v.y),v=null)}function g(a){function b(){h(a),j("reset","reset",a.iframe)}c(" Size reset requested by "+("init"===a.type?"host page":"iFrame")),e(),i(b,a,"init")}function h(a){function b(b){a.iframe.style[b]=a[b]+"px",c(" IFrame ("+a.iframe.id+") "+b+" set to "+a[b]+"px")}y.sizeHeight&&b("height"),y.sizeWidth&&b("width")}function i(a,b,d){d!==b.type&&w?(c(" Requesting animation frame"),w(a)):a()}function j(a,b,d){c("["+a+"] Sending msg to iframe ("+b+")"),d.contentWindow.postMessage(s+b,"*")}function k(){function b(){function a(a){1/0!==y[a]&&0!==y[a]&&(k.style[a]=y[a]+"px",c(" Set "+a+" = "+y[a]+"px"))}a("maxHeight"),a("minHeight"),a("maxWidth"),a("minWidth")}function d(a){return""===a&&(k.id=a="iFrameResizer"+o++,c(" Added missing iframe ID: "+a+" ("+k.src+")")),a}function e(){c(" IFrame scrolling "+(y.scrolling?"enabled":"disabled")+" for "+l),k.style.overflow=!1===y.scrolling?"hidden":"auto",k.scrolling=!1===y.scrolling?"no":"yes"}function f(){("number"==typeof y.bodyMargin||"0"===y.bodyMargin)&&(y.bodyMarginV1=y.bodyMargin,y.bodyMargin=""+y.bodyMargin+"px")}function h(){return l+":"+y.bodyMarginV1+":"+y.sizeWidth+":"+y.log+":"+y.interval+":"+y.enablePublicMethods+":"+y.autoResize+":"+y.bodyMargin+":"+y.heightCalculationMethod+":"+y.bodyBackground+":"+y.bodyPadding+":"+y.tolerance}function i(b){a(k,"load",function(){var a=p;j("iFrame.onload",b,k),!a&&y.heightCalculationMethod in x&&g({iframe:k,height:0,width:0,type:"init"})}),j("init",b,k)}var k=this,l=d(k.id);e(),b(),f(),i(h())}function l(a){if("object"!=typeof a)throw new TypeError("Options is not an object.")}function m(){function a(a){if("IFRAME"!==a.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+a.tagName+">.");k.call(a)}function b(a){a=a||{},l(a);for(var b in z)z.hasOwnProperty(b)&&(y[b]=a.hasOwnProperty(b)?a[b]:z[b])}return function(c,d){b(c),Array.prototype.forEach.call(document.querySelectorAll(d||"iframe"),a)}}function n(a){a.fn.iFrameResize=function(b){return b=b||{},l(b),y=a.extend({},z,b),this.filter("iframe").each(k).end()}}var o=0,p=!0,q="message",r=q.length,s="[iFrameSizer]",t=s.length,u="",v=null,w=window.requestAnimationFrame,x={max:1,scroll:1,bodyScroll:1,documentElementScroll:1},y={},z={autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,enablePublicMethods:!1,heightCalculationMethod:"offset",interval:32,log:!1,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,closedCallback:function(){},initCallback:function(){},messageCallback:function(){},resizedCallback:function(){}};b(),a(window,"message",d),"jQuery"in window&&n(jQuery),"function"==typeof define&&define.amd?define(function(){return m()}):window.iFrameResize=m()}();
9
+ //# sourceMappingURL=../src/iframeResizer.map
10
+
vendor/otgs/installer/res/js/installer_theme_install.js CHANGED
@@ -1,97 +1,97 @@
1
- jQuery( document ).ready( function( $ ) {
2
-
3
- /** Append OTGS Theme tab */
4
- var js_array= installer_theme_install_localize.js_array_installer;
5
-
6
- if (!($.isEmptyObject(js_array))) {
7
- //Unempty
8
- for(var key in js_array) {
9
- //Dont append if we are on commercial plugins tab page and if there are no themes
10
- if ((!(js_array[key]['is_commercial_plugin_tab'])) && (!(installer_theme_install_localize.no_associated_themes))) {
11
- $('div.wp-filter ul.filter-links').append('<li><a data-sort="'+key+'" href="#">'+ js_array[key]['the_hyperlink_text'] +'</a></li>');
12
- }
13
- }
14
- }
15
-
16
- /** Page load event tab selected identifier */
17
- var loaded_browsing_tab=installer_theme_extended_object.getParameterByName('browse');
18
- if (loaded_browsing_tab.length > 0) {
19
-
20
- var frontend_tab_selected_tab = loaded_browsing_tab;
21
-
22
- } else if (0 == loaded_browsing_tab.length){
23
-
24
- //WordPress defaults to 'Featured' when theme install is loaded without the browse parameter
25
- var frontend_tab_selected_tab = 'featured';
26
- }
27
-
28
- /** Prepare data on page load event for AJAX */
29
- var data = {
30
- action: 'installer_theme_frontend_selected_tab',
31
- installer_theme_frontend_selected_tab_nonce: installer_theme_install_localize.installer_theme_frontend_selected_tab_nonce,
32
- frontend_tab_selected :frontend_tab_selected_tab
33
- };
34
-
35
- //Call AJAX
36
- installer_theme_extended_object.doAJAX(data,frontend_tab_selected_tab,js_array);
37
-
38
- /** When user clicks on any tab */
39
- $(document).on('click','.filter-links li > a',function () {
40
-
41
- //Get data_sort
42
- var data_sort =$(this).attr('data-sort');
43
-
44
- if (data_sort) {
45
- //data_sort is set, prepare data
46
- var data = {
47
- action: 'installer_theme_frontend_selected_tab',
48
- installer_theme_frontend_selected_tab_nonce: installer_theme_install_localize.installer_theme_frontend_selected_tab_nonce,
49
- frontend_tab_selected : data_sort
50
- };
51
-
52
- //Call AJAX
53
- installer_theme_extended_object.doAJAX(data,data_sort,js_array);
54
-
55
- }
56
- });
57
-
58
- var fullhash = window.location.hash;
59
- if (fullhash.length > 0) {
60
- var product_selector=fullhash+' '+'.enter_site_key_js';
61
- if ($(product_selector).length ) {
62
- $(product_selector).click();
63
- }
64
- }
65
- });
66
-
67
- //Installer theme extended JS object for methods
68
- var installer_theme_extended_object = {
69
-
70
- getParameterByName: function(name) {
71
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
72
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
73
- results = regex.exec(location.search);
74
- return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
75
- },
76
-
77
- doAJAX: function(data,data_sort,js_array) {
78
-
79
- //We only want to post to AJAX if its an OTGS tab
80
- jQuery.post(installer_theme_install_localize.ajaxurl, data, function(response) {
81
- //AJAX response
82
- var myObject = jQuery.parseJSON(response);
83
- if (typeof myObject != "undefined") {
84
- if(myObject.hasOwnProperty("output")){
85
- var tab_selected= myObject.output;
86
- if (data_sort in js_array) {
87
- if (!(installer_theme_install_localize.js_array_installer[tab_selected]['registration_status'])) {
88
- //Not registered, no theme response
89
- var unregistered_message= myObject.unregistered_messages;
90
- jQuery('.no-themes').html(unregistered_message);
91
- }
92
- }
93
- }
94
- }
95
- });
96
- }
97
  };
1
+ jQuery( document ).ready( function( $ ) {
2
+
3
+ /** Append OTGS Theme tab */
4
+ var js_array= installer_theme_install_localize.js_array_installer;
5
+
6
+ if (!($.isEmptyObject(js_array))) {
7
+ //Unempty
8
+ for(var key in js_array) {
9
+ //Dont append if we are on commercial plugins tab page and if there are no themes
10
+ if ((!(js_array[key]['is_commercial_plugin_tab'])) && (!(installer_theme_install_localize.no_associated_themes))) {
11
+ $('div.wp-filter ul.filter-links').append('<li><a data-sort="'+key+'" href="#">'+ js_array[key]['the_hyperlink_text'] +'</a></li>');
12
+ }
13
+ }
14
+ }
15
+
16
+ /** Page load event tab selected identifier */
17
+ var loaded_browsing_tab=installer_theme_extended_object.getParameterByName('browse');
18
+ if (loaded_browsing_tab.length > 0) {
19
+
20
+ var frontend_tab_selected_tab = loaded_browsing_tab;
21
+
22
+ } else if (0 == loaded_browsing_tab.length){
23
+
24
+ //WordPress defaults to 'Featured' when theme install is loaded without the browse parameter
25
+ var frontend_tab_selected_tab = 'featured';
26
+ }
27
+
28
+ /** Prepare data on page load event for AJAX */
29
+ var data = {
30
+ action: 'installer_theme_frontend_selected_tab',
31
+ installer_theme_frontend_selected_tab_nonce: installer_theme_install_localize.installer_theme_frontend_selected_tab_nonce,
32
+ frontend_tab_selected :frontend_tab_selected_tab
33
+ };
34
+
35
+ //Call AJAX
36
+ installer_theme_extended_object.doAJAX(data,frontend_tab_selected_tab,js_array);
37
+
38
+ /** When user clicks on any tab */
39
+ $(document).on('click','.filter-links li > a',function () {
40
+
41
+ //Get data_sort
42
+ var data_sort =$(this).attr('data-sort');
43
+
44
+ if (data_sort) {
45
+ //data_sort is set, prepare data
46
+ var data = {
47
+ action: 'installer_theme_frontend_selected_tab',
48
+ installer_theme_frontend_selected_tab_nonce: installer_theme_install_localize.installer_theme_frontend_selected_tab_nonce,
49
+ frontend_tab_selected : data_sort
50
+ };
51
+
52
+ //Call AJAX
53
+ installer_theme_extended_object.doAJAX(data,data_sort,js_array);
54
+
55
+ }
56
+ });
57
+
58
+ var fullhash = window.location.hash;
59
+ if (fullhash.length > 0) {
60
+ var product_selector=fullhash+' '+'.enter_site_key_js';
61
+ if ($(product_selector).length ) {
62
+ $(product_selector).click();
63
+ }
64
+ }
65
+ });
66
+
67
+ //Installer theme extended JS object for methods
68
+ var installer_theme_extended_object = {
69
+
70
+ getParameterByName: function(name) {
71
+ name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
72
+ var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
73
+ results = regex.exec(location.search);
74
+ return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
75
+ },
76
+
77
+ doAJAX: function(data,data_sort,js_array) {
78
+
79
+ //We only want to post to AJAX if its an OTGS tab
80
+ jQuery.post(installer_theme_install_localize.ajaxurl, data, function(response) {
81
+ //AJAX response
82
+ var myObject = jQuery.parseJSON(response);
83
+ if (typeof myObject != "undefined") {
84
+ if(myObject.hasOwnProperty("output")){
85
+ var tab_selected= myObject.output;
86
+ if (data_sort in js_array) {
87
+ if (!(installer_theme_install_localize.js_array_installer[tab_selected]['registration_status'])) {
88
+ //Not registered, no theme response
89
+ var unregistered_message= myObject.unregistered_messages;
90
+ jQuery('.no-themes').html(unregistered_message);
91
+ }
92
+ }
93
+ }
94
+ }
95
+ });
96
+ }
97
  };
vendor/otgs/installer/templates/channel-selector.php CHANGED
@@ -1,68 +1,68 @@
1
- <div class="installer-channel-selector-wrap">
2
- <label>
3
- <?php esc_html_e('Updates channel:', 'installer'); ?>
4
- <select class="installer-channel-selector" data-repository-id="<?php echo $repository_id ?>"<?php if( !$can_switch ): ?> disabled<?php endif ?>>
5
- <?php foreach( $channels as $channel_id => $channel_name ): ?>
6
- <option value="<?php echo $channel_id ?>" <?php
7
- if( $channel_id == $current_channel ): ?>selected="selected"<?php
8
- endif; ?>><?php echo $channel_name ?></option>
9
- <?php endforeach ?>
10
- </select>
11
- <span class="installer-status-note" <?php if( $can_switch ): ?>style="display:none" <?php endif; ?>>
12
- <?php _e("To select different update channels (beta, development) you must update your existing products to their most recent stable versions.", 'installer') ?>
13
- </span>
14
- <span class="spinner spinner-with-text">
15
- <?php _e( "Updating the plugins on your site. Please don't close this page or navigate away.", 'installer' ); ?>
16
- </span>
17
- <span class="installer-channel-update-ok" data-text="<?php
18
- esc_attr_e( sprintf("Update completed. You are now using the %s channel of %s.",
19
- '%CHANNEL%', WP_Installer()->get_generic_product_name( $repository_id ) ) ) ?>">
20
- </span>
21
- <span class="installer-channel-update-fail" data-text-unstable="<?php
22
- $support_url = $repository_id ==='toolset' ? 'https://wp-types.com/forums/forum/support-2/' : 'https://wpml.org/forums/forum/english-support/';
23
- $download_url = $repository_id ==='toolset' ? 'https://wp-types.com/account/downloads/' : 'https://wpml.org/account/downloads/';
24
- echo esc_attr( sprintf(
25
- __( "Something went wrong and we could not install all updates from the %s channel. Click here to %stry again%s. If the errors persist, please switch back to the Production channel and contact the %s%s support%s.", 'installer' ),
26
- '%CHANNEL%',
27
- '<a href="#" class="installer-channel-retry"><strong>',
28
- '</strong></a>',
29
- '<a href="' . $support_url . '">', WP_Installer()->get_generic_product_name( $repository_id ), '</a>'
30
- ) );
31
- ?>" data-text-stable="<?php
32
- echo esc_attr( sprintf(
33
- esc_attr__( "There was a problem switching to the %s channel. You can %sretry%s. If the problem continues, please %sdownload %s%s and install again manually", 'installer' ),
34
- '%CHANNEL%',
35
- '<a href="#" class="installer-channel-retry"><strong>',
36
- '</strong></a>',
37
- '<a href="' . $download_url . '">', WP_Installer()->get_generic_product_name( $repository_id ), '</a>'
38
- ) );
39
- ?>">
40
- </span>
41
- <input type="hidden" class="nonce" value="<?php echo $nonce ?>" />
42
- </label>
43
-
44
- <?php if( !$no_prompt ): ?>
45
- <div class="installer-warn-box installer-switch-confirmation" style="margin-top: 10px; display: none">
46
- <p class="alignright">
47
- <button class="button-secondary js-cancel"><?php _e("Cancel", 'installer') ?></button>
48
- <button class="button-primary js-proceed"><?php _e("Switch", 'installer') ?></button>
49
- </p>
50
- <p>
51
- <?php _e("Plugins will be updated to their most advanced version in the channel that you selected.", 'installer') ?>
52
- </p>
53
- <label>
54
- <input type="checkbox" value="1" class="js-remember"/>
55
- &nbsp;<?php _e("Remember my preference.", 'installer') ?><br />
56
- </label>
57
- </div>
58
- <?php endif; ?>
59
-
60
- <div class="installer-warn-text" <?php if( WP_Installer_Channels()->get_channel( $repository_id ) <= 1 ): ?>style="display:none" <?php endif; ?>>
61
- <?php printf(
62
- __("You are using a potentially less stable channel for %s. If you didn't enable this on purpose, you should switch to the 'Production' channel.", 'installer'),
63
- WP_Installer()->get_generic_product_name( $repository_id )
64
- );
65
- ?>
66
- </div>
67
-
68
  </div>
1
+ <div class="installer-channel-selector-wrap">
2
+ <label>
3
+ <?php esc_html_e('Updates channel:', 'installer'); ?>
4
+ <select class="installer-channel-selector" data-repository-id="<?php echo $repository_id ?>"<?php if( !$can_switch ): ?> disabled<?php endif ?>>
5
+ <?php foreach( $channels as $channel_id => $channel_name ): ?>
6
+ <option value="<?php echo $channel_id ?>" <?php
7
+ if( $channel_id == $current_channel ): ?>selected="selected"<?php
8
+ endif; ?>><?php echo $channel_name ?></option>
9
+ <?php endforeach ?>
10
+ </select>
11
+ <span class="installer-status-note" <?php if( $can_switch ): ?>style="display:none" <?php endif; ?>>
12
+ <?php _e("To select different update channels (beta, development) you must update your existing products to their most recent stable versions.", 'installer') ?>
13
+ </span>
14
+ <span class="spinner spinner-with-text">
15
+ <?php _e( "Updating the plugins on your site. Please don't close this page or navigate away.", 'installer' ); ?>
16
+ </span>
17
+ <span class="installer-channel-update-ok" data-text="<?php
18
+ esc_attr_e( sprintf("Update completed. You are now using the %s channel of %s.",
19
+ '%CHANNEL%', WP_Installer()->get_generic_product_name( $repository_id ) ) ) ?>">
20
+ </span>
21
+ <span class="installer-channel-update-fail" data-text-unstable="<?php
22
+ $support_url = $repository_id ==='toolset' ? 'https://wp-types.com/forums/forum/support-2/' : 'https://wpml.org/forums/forum/english-support/';
23
+ $download_url = $repository_id ==='toolset' ? 'https://wp-types.com/account/downloads/' : 'https://wpml.org/account/downloads/';
24
+ echo esc_attr( sprintf(
25
+ __( "Something went wrong and we could not install all updates from the %s channel. Click here to %stry again%s. If the errors persist, please switch back to the Production channel and contact the %s%s support%s.", 'installer' ),
26
+ '%CHANNEL%',
27
+ '<a href="#" class="installer-channel-retry"><strong>',
28
+ '</strong></a>',
29
+ '<a href="' . $support_url . '">', WP_Installer()->get_generic_product_name( $repository_id ), '</a>'
30
+ ) );
31
+ ?>" data-text-stable="<?php
32
+ echo esc_attr( sprintf(
33
+ esc_attr__( "There was a problem switching to the %s channel. You can %sretry%s. If the problem continues, please %sdownload %s%s and install again manually", 'installer' ),
34
+ '%CHANNEL%',
35
+ '<a href="#" class="installer-channel-retry"><strong>',
36
+ '</strong></a>',
37
+ '<a href="' . $download_url . '">', WP_Installer()->get_generic_product_name( $repository_id ), '</a>'
38
+ ) );
39
+ ?>">
40
+ </span>
41
+ <input type="hidden" class="nonce" value="<?php echo $nonce ?>" />
42
+ </label>
43
+
44
+ <?php if( !$no_prompt ): ?>
45
+ <div class="installer-warn-box installer-switch-confirmation" style="margin-top: 10px; display: none">
46
+ <p class="alignright">
47
+ <button class="button-secondary js-cancel"><?php _e("Cancel", 'installer') ?></button>
48
+ <button class="button-primary js-proceed"><?php _e("Switch", 'installer') ?></button>
49
+ </p>
50
+ <p>
51
+ <?php _e("Plugins will be updated to their most advanced version in the channel that you selected.", 'installer') ?>
52
+ </p>
53
+ <label>
54
+ <input type="checkbox" value="1" class="js-remember"/>
55
+ &nbsp;<?php _e("Remember my preference.", 'installer') ?><br />
56
+ </label>
57
+ </div>
58
+ <?php endif; ?>
59
+
60
+ <div class="installer-warn-text" <?php if( WP_Installer_Channels()->get_channel( $repository_id ) <= 1 ): ?>style="display:none" <?php endif; ?>>
61
+ <?php printf(
62
+ __("You are using a potentially less stable channel for %s. If you didn't enable this on purpose, you should switch to the 'Production' channel.", 'installer'),
63
+ WP_Installer()->get_generic_product_name( $repository_id )
64
+ );
65
+ ?>
66
+ </div>
67
+
68
  </div>
vendor/otgs/installer/templates/downloads-list-compact.php CHANGED
@@ -1,80 +1,80 @@
1
-
2
- <form method="post" class="otgsi_downloads_form">
3
-
4
- <table class="installer-plugins-list-compact">
5
- <thead>
6
- <tr>
7
- <th>&nbsp;</th>
8
- <th><?php _e('Plugin', 'installer') ?></th>
9
- <th><img src="<?php echo $this->plugin_url() ?>/res/img/globe.png" alt="<?php esc_attr_e('Available', 'installer') ?>" width="16" height="16"></th>
10
- <th><img src="<?php echo $this->plugin_url() ?>/res/img/computer.png" alt="<?php esc_attr_e('Installed', 'installer') ?>" width="16" height="16"></th>
11
- <th><img src="<?php echo $this->plugin_url() ?>/res/img/dn2.gif" alt="<?php esc_attr_e('Downloading', 'installer') ?>" width="16" height="16"></th>
12
- <th><img src="<?php echo $this->plugin_url() ?>/res/img/on.png" alt="<?php esc_attr_e('Activate', 'installer') ?>" width="16" height="16"></th>
13
- </tr>
14
- </thead>
15
- <tbody>
16
- <?php foreach($product['downloads'] as $download): ?>
17
- <?php if(empty($tr_oddeven) || $tr_oddeven == 'even') $tr_oddeven = 'odd'; else $tr_oddeven = 'even'; ?>
18
- <tr class="<?php echo $tr_oddeven ?>">
19
- <td>
20
- <label>
21
- <?php
22
- $url = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id );
23
-
24
- $download_data = array(
25
- 'url' => $url,
26
- 'slug' => $download['slug'],
27
- 'nonce' => wp_create_nonce('install_plugin_' . $url),
28
- 'repository_id' => $repository_id
29
- );
30
-
31
- $disabled = $expired ||
32
- (
33
- $this->plugin_is_installed($download['name'], $download['slug'], $download['version']) &&
34
- !$this->plugin_is_embedded_version($download['name'], $download['slug'])
35
- ) || WP_Installer()->dependencies->cant_download( $repository_id );
36
-
37
- ?>
38
- <input type="checkbox" name="downloads[]" value="<?php echo base64_encode(json_encode($download_data)); ?>" <?php
39
- if($disabled): ?>disabled="disabled"<?php endif; ?> />&nbsp;
40
-
41
- </label>
42
- </td>
43
- <td class="installer_plugin_name"><?php echo $download['name'] ?></td>
44
- <td><?php echo $download['version'] ?></td>
45
- <td class="installer_version_installed">
46
- <?php if($v = $this->plugin_is_installed($download['name'], $download['slug'])):
47
- $class = version_compare($v, $download['version'], '>=') ? 'installer-green-text' : 'installer-red-text'; ?>
48
- <span class="<?php echo $class ?>"><?php echo $v; ?></span>
49
- <?php endif; ?>
50
- </td>
51
- <td class="twelve">
52
- <div class="installer-status-downloading"><?php _e('downloading...', 'installer') ?></div>
53
- <div class="installer-status-downloaded" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('downloaded', 'installer') ?></div>
54
- </td>
55
- <td class="twelve">
56
- <div class="installer-status-activating"><?php _e('activating', 'installer') ?></div>
57
- <div class="installer-status-activated"><?php _e('activated', 'installer') ?></div>
58
- </td>
59
- </tr>
60
- <?php endforeach; ?>
61
- </tbody>
62
- </table>
63
-
64
- <?php if( !WP_Installer()->dependencies->is_uploading_allowed() ): ?>
65
- <p class="installer-error-box"><?php printf(__('Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s.', 'installer'),
66
- '<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') ?></p>
67
- <?php elseif( WP_Installer()->dependencies->is_win_paths_exception($repository_id) ): ?>
68
- <p><?php echo WP_Installer()->dependencies->win_paths_exception_message() ?></p>
69
- <?php endif;?>
70
-
71
- <br />
72
- <input type="submit" class="button-secondary" value="<?php esc_attr_e('Download', 'installer') ?>" disabled="disabled" />
73
- &nbsp;
74
- <label><input name="activate" type="checkbox" value="1" disabled="disabled" />&nbsp;<?php _e('Activate after download', 'installer') ?></label>
75
-
76
- <div class="installer-download-progress-status"></div>
77
- <div class="installer-status-success"><?php _e('Operation complete!', 'installer') ?></div>
78
-
79
- <span class="installer-revalidate-message hidden"><?php _e("Download failed!\n\nClick OK to revalidate your subscription or CANCEL to try again.", 'installer') ?></span>
80
- </form>
1
+
2
+ <form method="post" class="otgsi_downloads_form">
3
+
4
+ <table class="installer-plugins-list-compact">
5
+ <thead>
6
+ <tr>
7
+ <th>&nbsp;</th>
8
+ <th><?php _e('Plugin', 'installer') ?></th>
9
+ <th><img src="<?php echo $this->plugin_url() ?>/res/img/globe.png" alt="<?php esc_attr_e('Available', 'installer') ?>" width="16" height="16"></th>
10
+ <th><img src="<?php echo $this->plugin_url() ?>/res/img/computer.png" alt="<?php esc_attr_e('Installed', 'installer') ?>" width="16" height="16"></th>
11
+ <th><img src="<?php echo $this->plugin_url() ?>/res/img/dn2.gif" alt="<?php esc_attr_e('Downloading', 'installer') ?>" width="16" height="16"></th>
12
+ <th><img src="<?php echo $this->plugin_url() ?>/res/img/on.png" alt="<?php esc_attr_e('Activate', 'installer') ?>" width="16" height="16"></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <?php foreach($product['downloads'] as $download): ?>
17
+ <?php if(empty($tr_oddeven) || $tr_oddeven == 'even') $tr_oddeven = 'odd'; else $tr_oddeven = 'even'; ?>
18
+ <tr class="<?php echo $tr_oddeven ?>">
19
+ <td>
20
+ <label>
21
+ <?php
22
+ $url = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id );
23
+
24
+ $download_data = array(
25
+ 'url' => $url,
26
+ 'slug' => $download['slug'],
27
+ 'nonce' => wp_create_nonce('install_plugin_' . $url),
28
+ 'repository_id' => $repository_id
29
+ );
30
+
31
+ $disabled = $expired ||
32
+ (
33
+ $this->plugin_is_installed($download['name'], $download['slug'], $download['version']) &&
34
+ !$this->plugin_is_embedded_version($download['name'], $download['slug'])
35
+ ) || WP_Installer()->dependencies->cant_download( $repository_id );
36
+
37
+ ?>
38
+ <input type="checkbox" name="downloads[]" value="<?php echo base64_encode(json_encode($download_data)); ?>" <?php
39
+ if($disabled): ?>disabled="disabled"<?php endif; ?> />&nbsp;
40
+
41
+ </label>
42
+ </td>
43
+ <td class="installer_plugin_name"><?php echo $download['name'] ?></td>
44
+ <td><?php echo $download['version'] ?></td>
45
+ <td class="installer_version_installed">
46
+ <?php if($v = $this->plugin_is_installed($download['name'], $download['slug'])):
47
+ $class = version_compare($v, $download['version'], '>=') ? 'installer-green-text' : 'installer-red-text'; ?>
48
+ <span class="<?php echo $class ?>"><?php echo $v; ?></span>
49
+ <?php endif; ?>
50
+ </td>
51
+ <td class="twelve">
52
+ <div class="installer-status-downloading"><?php _e('downloading...', 'installer') ?></div>
53
+ <div class="installer-status-downloaded" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('downloaded', 'installer') ?></div>
54
+ </td>
55
+ <td class="twelve">
56
+ <div class="installer-status-activating"><?php _e('activating', 'installer') ?></div>
57
+ <div class="installer-status-activated"><?php _e('activated', 'installer') ?></div>
58
+ </td>
59
+ </tr>
60
+ <?php endforeach; ?>
61
+ </tbody>
62
+ </table>
63
+
64
+ <?php if( !WP_Installer()->dependencies->is_uploading_allowed() ): ?>
65
+ <p class="installer-error-box"><?php printf(__('Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s.', 'installer'),
66
+ '<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') ?></p>
67
+ <?php elseif( WP_Installer()->dependencies->is_win_paths_exception($repository_id) ): ?>
68
+ <p><?php echo WP_Installer()->dependencies->win_paths_exception_message() ?></p>
69
+ <?php endif;?>
70
+
71
+ <br />
72
+ <input type="submit" class="button-secondary" value="<?php esc_attr_e('Download', 'installer') ?>" disabled="disabled" />
73
+ &nbsp;
74
+ <label><input name="activate" type="checkbox" value="1" disabled="disabled" />&nbsp;<?php _e('Activate after download', 'installer') ?></label>
75
+
76
+ <div class="installer-download-progress-status"></div>
77
+ <div class="installer-status-success"><?php _e('Operation complete!', 'installer') ?></div>
78
+
79
+ <span class="installer-revalidate-message hidden"><?php _e("Download failed!\n\nClick OK to revalidate your subscription or CANCEL to try again.", 'installer') ?></span>
80
+ </form>
vendor/otgs/installer/templates/downloads-list.php CHANGED
@@ -1,109 +1,109 @@
1
-
2
- <form method="post" class="otgsi_downloads_form">
3
-
4
- <div class="installer-table-wrap">
5
- <table class="widefat">
6
- <thead>
7
- <tr>
8
- <th>&nbsp;</th>
9
- <th><?php _e('Plugin', 'installer') ?></th>
10
- <th><?php _e('Installed', 'installer') ?></th>
11
- <th><?php _e('Current', 'installer') ?></th>
12
- <th><?php _e('Released', 'installer') ?></th>
13
- <th>&nbsp;</th>
14
- <th>&nbsp;</th>
15
- <th>&nbsp;</th>
16
- <th>&nbsp;</th>
17
- </tr>
18
- </thead>
19
- <tbody>
20
- <?php
21
- foreach($package['downloads'] as $download_id => $download): ?>
22
- <tr>
23
- <td>
24
- <label>
25
- <?php
26
- $url = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
27
-
28
- $download_data = array(
29
- 'url' => $url,
30
- 'slug' => $download['slug'],
31
- 'nonce' => wp_create_nonce('install_plugin_' . $url),
32
- 'repository_id' => $repository_id
33
- );
34
- ?>
35
- <input type="checkbox" name="downloads[]" value="<?php echo base64_encode(json_encode($download_data)); ?>" <?php
36
- if( $this->plugin_is_installed($download['name'], $download['slug'], $download['version'] )
37
- && ! $this->plugin_is_embedded_version( $download['name'], $download['slug'] )
38
- || WP_Installer()->dependencies->cant_download( $repository_id ) ): ?>disabled="disabled"<?php endif; ?> />&nbsp;
39
- </label>
40
- </td>
41
- <td class="installer_plugin_name"><?php echo $download['name'] ?></td>
42
- <td class="installer_version_installed">
43
- <?php if ( $v = $this->plugin_is_installed( $download['name'], $download['slug'] ) ): ?>
44
- <?php
45
- $class = version_compare( $v, $download['version'], '>=' ) ? 'installer-green-text' : 'installer-red-text';
46
- $class .= version_compare( $v, $download['version'], '>' ) ? ' unstable' : '';
47
- ?>
48
- <span class="<?php echo $class ?>"><?php echo $v; ?></span>
49
- <?php if ( $this->plugin_is_embedded_version( $download['name'], $download['slug'] ) ): ?>&nbsp;<?php _e( '(embedded)', 'installer' ); ?><?php endif; ?>
50
- <?php if(
51
- WP_Installer_Channels()->get_channel( $repository_id ) !== WP_Installer_Channels::CHANNEL_PRODUCTION &&
52
- $non_stable = WP_Installer_Channels()->get_download_source_channel( $v, $repository_id, $download_id, 'plugins')
53
- ) : ?>
54
- (<?php echo $non_stable ?>)
55
- <?php endif; ?>
56
- <?php endif; ?>
57
- </td>
58
- <td><?php echo $download['version'] ?></td>
59
- <td><?php echo date_i18n('F j, Y', strtotime($download['date'])) ?></td>
60
- <td>
61
- <?php if ( !empty( $download['release-notes'] ) ): ?>
62
- <a class="js-release-notes handle" href="#">Release notes</a></td>
63
- <?php endif; ?>
64
- <td>
65
- <span class="installer-status-installing"><?php _e('installing...', 'installer') ?></span>
66
- <span class="installer-status-updating"><?php _e('updating...', 'installer') ?></span>
67
- <span class="installer-status-installed" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('installed', 'installer') ?></span>
68
- <span class="installer-status-updated" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('updated', 'installer') ?></span>
69
- </td>
70
- <td>
71
- <span class="installer-status-activating"><?php _e('activating', 'installer') ?></span>
72
- <span class="installer-status-activated"><?php _e('activated', 'installer') ?></span>
73
- </td>
74
- <td class="for_spinner_js"><span class="spinner"></span></td>
75
- </tr>
76
- <?php if ( !empty( $download['release-notes'] ) ): ?>
77
- <tr class="installer-release-notes">
78
- <td colspan="9">
79
- <div class="arrow_box">
80
- <div><?php echo force_balance_tags( $download['release-notes'] ) ?></div>
81
- </div>
82
- </td>
83
- </tr>
84
- <?php endif; ?>
85
- <?php endforeach; ?>
86
- </tbody>
87
- </table>
88
- </div>
89
- <br />
90
-
91
- <div class="installer-error-box">
92
- <?php if( !WP_Installer()->dependencies->is_uploading_allowed() ): ?>
93
- <p><?php printf(__('Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s.', 'installer'),
94
- '<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') ?></p>
95
- <?php elseif( WP_Installer()->dependencies->is_win_paths_exception($repository_id) ): ?>
96
- <p><?php echo WP_Installer()->dependencies->win_paths_exception_message() ?></p>
97
- <?php endif; ?>
98
- </div>
99
-
100
- <input type="submit" class="button-secondary" value="<?php esc_attr_e('Download', 'installer') ?>" disabled="disabled" />
101
- &nbsp;
102
- <label><input name="activate" type="checkbox" value="1" disabled="disabled" />&nbsp;<?php _e('Activate after download', 'installer') ?></label>
103
-
104
- <div class="installer-download-progress-status"></div>
105
-
106
- <div class="installer-status-success"><?php _e('Operation complete!', 'installer') ?></div>
107
-
108
- <span class="installer-revalidate-message hidden"><?php _e("Download failed!\n\nPlease refresh the page and try again.", 'installer') ?></span>
109
- </form>
1
+
2
+ <form method="post" class="otgsi_downloads_form">
3
+
4
+ <div class="installer-table-wrap">
5
+ <table class="widefat">
6
+ <thead>
7
+ <tr>
8
+ <th>&nbsp;</th>
9
+ <th><?php _e('Plugin', 'installer') ?></th>
10
+ <th><?php _e('Installed', 'installer') ?></th>
11
+ <th><?php _e('Current', 'installer') ?></th>
12
+ <th><?php _e('Released', 'installer') ?></th>
13
+ <th>&nbsp;</th>
14
+ <th>&nbsp;</th>
15
+ <th>&nbsp;</th>
16
+ <th>&nbsp;</th>
17
+ </tr>
18
+ </thead>
19
+ <tbody>
20
+ <?php
21
+ foreach($package['downloads'] as $download_id => $download): ?>
22
+ <tr>
23
+ <td>
24
+ <label>
25
+ <?php
26
+ $url = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
27
+
28
+ $download_data = array(
29
+ 'url' => $url,
30
+ 'slug' => $download['slug'],
31
+ 'nonce' => wp_create_nonce('install_plugin_' . $url),
32
+ 'repository_id' => $repository_id
33
+ );
34
+ ?>
35
+ <input type="checkbox" name="downloads[]" value="<?php echo base64_encode(json_encode($download_data)); ?>" <?php
36
+ if( $this->plugin_is_installed($download['name'], $download['slug'], $download['version'] )
37
+ && ! $this->plugin_is_embedded_version( $download['name'], $download['slug'] )
38
+ || WP_Installer()->dependencies->cant_download( $repository_id ) ): ?>disabled="disabled"<?php endif; ?> />&nbsp;
39
+ </label>
40
+ </td>
41
+ <td class="installer_plugin_name"><?php echo $download['name'] ?></td>
42
+ <td class="installer_version_installed">
43
+ <?php if ( $v = $this->plugin_is_installed( $download['name'], $download['slug'] ) ): ?>
44
+ <?php
45
+ $class = version_compare( $v, $download['version'], '>=' ) ? 'installer-green-text' : 'installer-red-text';
46
+ $class .= version_compare( $v, $download['version'], '>' ) ? ' unstable' : '';
47
+ ?>
48
+ <span class="<?php echo $class ?>"><?php echo $v; ?></span>
49
+ <?php if ( $this->plugin_is_embedded_version( $download['name'], $download['slug'] ) ): ?>&nbsp;<?php _e( '(embedded)', 'installer' ); ?><?php endif; ?>
50
+ <?php if(
51
+ WP_Installer_Channels()->get_channel( $repository_id ) !== WP_Installer_Channels::CHANNEL_PRODUCTION &&
52
+ $non_stable = WP_Installer_Channels()->get_download_source_channel( $v, $repository_id, $download_id, 'plugins')
53
+ ) : ?>
54
+ (<?php echo $non_stable ?>)
55
+ <?php endif; ?>
56
+ <?php endif; ?>
57
+ </td>
58
+ <td><?php echo $download['version'] ?></td>
59
+ <td><?php echo date_i18n('F j, Y', strtotime($download['date'])) ?></td>
60
+ <td>
61
+ <?php if ( !empty( $download['release-notes'] ) ): ?>
62
+ <a class="js-release-notes handle" href="#"><?php esc_html_e( 'Release notes', 'installer' ) ?></a></td>
63
+ <?php endif; ?>
64
+ <td>
65
+ <span class="installer-status-installing"><?php _e('installing...', 'installer') ?></span>
66
+ <span class="installer-status-updating"><?php _e('updating...', 'installer') ?></span>
67
+ <span class="installer-status-installed" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('installed', 'installer') ?></span>
68
+ <span class="installer-status-updated" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('updated', 'installer') ?></span>
69
+ </td>
70
+ <td>
71
+ <span class="installer-status-activating"><?php _e('activating', 'installer') ?></span>
72
+ <span class="installer-status-activated"><?php _e('activated', 'installer') ?></span>
73
+ </td>
74
+ <td class="for_spinner_js"><span class="spinner"></span></td>
75
+ </tr>
76
+ <?php if ( !empty( $download['release-notes'] ) ): ?>
77
+ <tr class="installer-release-notes">
78
+ <td colspan="9">
79
+ <div class="arrow_box">
80
+ <div><?php echo force_balance_tags( $download['release-notes'] ) ?></div>
81
+ </div>
82
+ </td>
83
+ </tr>
84
+ <?php endif; ?>
85
+ <?php endforeach; ?>
86
+ </tbody>
87
+ </table>
88
+ </div>
89
+ <br />
90
+
91
+ <div class="installer-error-box">
92
+ <?php if( !WP_Installer()->dependencies->is_uploading_allowed() ): ?>
93
+ <p><?php printf(__('Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s.', 'installer'),
94
+ '<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') ?></p>
95
+ <?php elseif( WP_Installer()->dependencies->is_win_paths_exception($repository_id) ): ?>
96
+ <p><?php echo WP_Installer()->dependencies->win_paths_exception_message() ?></p>
97
+ <?php endif; ?>
98
+ </div>
99
+
100
+ <input type="submit" class="button-secondary" value="<?php esc_attr_e('Download', 'installer') ?>" disabled="disabled" />
101
+ &nbsp;
102
+ <label><input name="activate" type="checkbox" value="1" disabled="disabled" />&nbsp;<?php _e('Activate after download', 'installer') ?></label>
103
+
104
+ <div class="installer-download-progress-status"></div>
105
+
106
+ <div class="installer-status-success"><?php _e('Operation complete!', 'installer') ?></div>
107
+
108
+ <span class="installer-revalidate-message hidden"><?php _e("Download failed!\n\nPlease refresh the page and try again.", 'installer') ?></span>
109
+ </form>
vendor/otgs/installer/templates/products-compact.php CHANGED
@@ -1,147 +1,147 @@
1
- <h3><?php echo $args['box_title'] ?></h3>
2
-
3
- <?php
4
- if(empty($args['repository']) || empty($args['package']) || empty($args['product'])){
5
- echo __('Incorrect setup', 'installer');
6
- return;
7
- }
8
-
9
- $product = false;
10
- foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package_idx => $package){
11
-
12
- //pre 1.3 backwardds compatibility
13
- if(!isset($package['id'])){
14
- $package['id'] = sanitize_title_with_dashes($package['name']);
15
- }
16
-
17
- if($package['id'] == $args['package']){
18
- $product = $this->settings['repositories'][$repository_id]['data']['packages'][$package_idx]['products'][$args['product']];
19
- break;
20
- }
21
- }
22
-
23
-
24
- if(!$product){
25
- echo __('Invalid product', 'installer');
26
- return;
27
- }
28
-
29
- if(isset($this->settings['repositories'][$repository_id])){
30
- if(isset($this->settings['repositories'][$repository_id]['subscription']['key'])){
31
- $site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
32
- }else{
33
- $site_key = false;
34
- }
35
- }else{
36
- echo __('Unknown repository', 'installer');
37
- return;
38
- }
39
-
40
- $subscription_type = $this->get_subscription_type_for_repository($repository_id);
41
- $expired = false;
42
-
43
- if($subscription_type != $product['subscription_type'] && !$this->have_superior_subscription($subscription_type, $product) && $site_key){
44
- $subscription_no_match = sprintf(__(' Your current site key (%s) does not match the selected product (%s).', 'installer'), $site_key, $product['name']);
45
- }
46
-
47
- if(!isset($args['product_name'])) $args['product_name'] = $product['name'];
48
-
49
- ?>
50
-
51
- <div class="otgs_wp_installer_table otgs_wp_installer_table_compact">
52
-
53
- <p><?php echo $args['box_description'] ?></p>
54
-
55
-
56
- <?php if(!$this->repository_has_subscription($repository_id) || !empty($subscription_no_match)): ?>
57
-
58
- <?php if(!empty($subscription_no_match)): ?>
59
- <div class="installer-warn-box">
60
- <?php echo $subscription_no_match; ?>
61
- </div>
62
- <br />
63
- <?php endif; ?>
64
-
65
- <a class="button-primary" href="<?php echo $this->append_parameters_to_buy_url($product['url'], $repository_id, $args) ?>"><?php printf(__('Buy %s', 'installer'), $args['product_name']) ?></a>
66
-
67
- <div>
68
- <br />
69
- <?php printf(__('Already bought %s?', 'installer'), $args['product_name']) ?>
70
- <a class="enter_site_key_js<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?> disabled<?php endif ?>" href="#"
71
- <?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
72
- style="cursor: help"
73
- disabled="disabled"
74
- title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
75
- <?php endif; ?>
76
- >
77
- <?php _e('Enter site key', 'installer') ?>
78
- </a>&nbsp;&nbsp;
79
-
80
- <form class="otgsi_site_key_form" method="post">
81
- <input type="hidden" name="action" value="save_site_key" />
82
- <input type="hidden" name="nonce" value="<?php echo wp_create_nonce('save_site_key_' . $repository_id) ?>" />
83
- <input type="hidden" name="repository_id" value="<?php echo $repository_id ?>">
84
- <input type="text" size="10" name="site_key_<?php echo $repository_id ?>" />
85
- <input class="button-secondary" type="submit" value="<?php esc_attr_e('Add', 'installer') ?>" />
86
- </form>
87
- <div class="installer-error-box hidden" style="margin-top:10px;"></div>
88
- </div>
89
-
90
- <?php else: ?>
91
-
92
- <?php if($this->repository_has_expired_subscription($repository_id)): $expired = true; ?>
93
-
94
- <div><p class="installer-warn-box"><?php _e('Subscription is expired.', 'installer') ?></p></div>
95
-
96
- <?php else: ?>
97
-
98
- <?php if($this->show_subscription_renew_warning($repository_id, $subscription_type)): ?>
99
-
100
- <ul class="installer-products-list">
101
- <?php foreach($product['renewals'] as $renewal): ?>
102
- <li>
103
- <a href="<?php echo $this->append_parameters_to_buy_url($renewal['url'], $repository_id, $args) ?>"><?php printf(__('Renew %s', 'installer'), $args['product_name']) ?></a>
104
- </li>
105
- <?php endforeach; ?>
106
- </ul>
107
-
108
- <?php endif; ?>
109
-
110
- <?php endif; ?>
111
-
112
- <center>
113
- <a class="remove_site_key_js" href="#" data-repository=<?php echo $repository_id ?>
114
- data-confirmation="<?php esc_attr_e('Are you sure you want to remove this site key?', 'installer') ?>"
115
- data-nonce="<?php echo wp_create_nonce('remove_site_key_' . $repository_id) ?>"
116
- <?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
117
- style="cursor: help;color:#999999"
118
- disabled="disabled"
119
- title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to unregister.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
120
- <?php endif; ?>
121
- >
122
- <?php printf(__("Remove current site key (%s)", 'installer'), $site_key) ?>
123
- </a>
124
- </center>
125
- <br />
126
-
127
- <?php include $this->plugin_path() . '/templates/downloads-list-compact.php'; ?>
128
-
129
-
130
-
131
- <?php endif; ?>
132
-
133
- <?php
134
- if( isset( $args[ 'name' ] ) ):
135
- $support_link = $this->get_support_tag_by_name($args['name'], $args['repository']); ?>
136
-
137
- <?php if($support_link): ?>
138
- <p><a href="<?php echo $support_link ?>" target="_blank"><?php printf(__('%s support on wpml.org', 'installer'), $args['name'] ) ?></a></p>
139
-
140
- <?php endif; ?>
141
- <?php
142
- // compatibility for installer 1.1
143
- elseif( isset( $args[ 'support_link' ] ) ): ?>
144
- <p><?php echo $args[ 'support_link' ]; ?></p>
145
- <?php endif; ?>
146
-
147
- </div>
1
+ <h3><?php echo $args['box_title'] ?></h3>
2
+
3
+ <?php
4
+ if(empty($args['repository']) || empty($args['package']) || empty($args['product'])){
5
+ echo __('Incorrect setup', 'installer');
6
+ return;
7
+ }
8
+
9
+ $product = false;
10
+ foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package_idx => $package){
11
+
12
+ //pre 1.3 backwardds compatibility
13
+ if(!isset($package['id'])){
14
+ $package['id'] = sanitize_title_with_dashes($package['name']);
15
+ }
16
+
17
+ if($package['id'] == $args['package']){
18
+ $product = $this->settings['repositories'][$repository_id]['data']['packages'][$package_idx]['products'][$args['product']];
19
+ break;
20
+ }
21
+ }
22
+
23
+
24
+ if(!$product){
25
+ echo __('Invalid product', 'installer');
26
+ return;
27
+ }
28
+
29
+ if(isset($this->settings['repositories'][$repository_id])){
30
+ if(isset($this->settings['repositories'][$repository_id]['subscription']['key'])){
31
+ $site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
32
+ }else{
33
+ $site_key = false;
34
+ }
35
+ }else{
36
+ echo __('Unknown repository', 'installer');
37
+ return;
38
+ }
39
+
40
+ $subscription_type = $this->get_subscription_type_for_repository($repository_id);
41
+ $expired = false;
42
+
43
+ if($subscription_type != $product['subscription_type'] && !$this->have_superior_subscription($subscription_type, $product) && $site_key){
44
+ $subscription_no_match = sprintf(__(' Your current site key (%s) does not match the selected product (%s).', 'installer'), $site_key, $product['name']);
45
+ }
46
+
47
+ if(!isset($args['product_name'])) $args['product_name'] = $product['name'];
48
+
49
+ ?>
50
+
51
+ <div class="otgs_wp_installer_table otgs_wp_installer_table_compact">
52
+
53
+ <p><?php echo $args['box_description'] ?></p>
54
+
55
+
56
+ <?php if(!$this->repository_has_subscription($repository_id) || !empty($subscription_no_match)): ?>
57
+
58
+ <?php if(!empty($subscription_no_match)): ?>
59
+ <div class="installer-warn-box">
60
+ <?php echo $subscription_no_match; ?>
61
+ </div>
62
+ <br />
63
+ <?php endif; ?>
64
+
65
+ <a class="button-primary" href="<?php echo $this->append_parameters_to_buy_url($product['url'], $repository_id, $args) ?>"><?php printf(__('Buy %s', 'installer'), $args['product_name']) ?></a>
66
+
67
+ <div>
68
+ <br />
69
+ <?php printf(__('Already bought %s?', 'installer'), $args['product_name']) ?>
70
+ <a class="enter_site_key_js<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?> disabled<?php endif ?>" href="#"
71
+ <?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
72
+ style="cursor: help"
73
+ disabled="disabled"
74
+ title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
75
+ <?php endif; ?>
76
+ >
77
+ <?php _e('Enter site key', 'installer') ?>
78
+ </a>&nbsp;&nbsp;
79
+
80
+ <form class="otgsi_site_key_form" method="post">
81
+ <input type="hidden" name="action" value="save_site_key" />
82
+ <input type="hidden" name="nonce" value="<?php echo wp_create_nonce('save_site_key_' . $repository_id) ?>" />
83
+ <input type="hidden" name="repository_id" value="<?php echo $repository_id ?>">
84
+ <input type="text" size="10" name="site_key_<?php echo $repository_id ?>" />
85
+ <input class="button-secondary" type="submit" value="<?php esc_attr_e('Add', 'installer') ?>" />
86
+ </form>
87
+ <div class="installer-error-box hidden" style="margin-top:10px;"></div>
88
+ </div>
89
+
90
+ <?php else: ?>
91
+
92
+ <?php if($this->repository_has_expired_subscription($repository_id)): $expired = true; ?>
93
+
94
+ <div><p class="installer-warn-box"><?php _e('Subscription is expired.', 'installer') ?></p></div>
95
+
96
+ <?php else: ?>
97
+
98
+ <?php if($this->show_subscription_renew_warning($repository_id, $subscription_type)): ?>
99
+
100
+ <ul class="installer-products-list">
101
+ <?php foreach($product['renewals'] as $renewal): ?>
102
+ <li>
103
+ <a href="<?php echo $this->append_parameters_to_buy_url($renewal['url'], $repository_id, $args) ?>"><?php printf(__('Renew %s', 'installer'), $args['product_name']) ?></a>
104
+ </li>
105
+ <?php endforeach; ?>
106
+ </ul>
107
+
108
+ <?php endif; ?>
109
+
110
+ <?php endif; ?>
111
+
112
+ <center>
113
+ <a class="remove_site_key_js" href="#" data-repository=<?php echo $repository_id ?>
114
+ data-confirmation="<?php esc_attr_e('Are you sure you want to remove this site key?', 'installer') ?>"
115
+ data-nonce="<?php echo wp_create_nonce('remove_site_key_' . $repository_id) ?>"
116
+ <?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
117
+ style="cursor: help;color:#999999"
118
+ disabled="disabled"
119
+ title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to unregister.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
120
+ <?php endif; ?>
121
+ >
122
+ <?php printf(__("Remove current site key (%s)", 'installer'), $site_key) ?>
123
+ </a>
124
+ </center>
125
+ <br />
126
+
127
+ <?php include $this->plugin_path() . '/templates/downloads-list-compact.php'; ?>
128
+
129
+
130
+
131
+ <?php endif; ?>
132
+
133
+ <?php
134
+ if( isset( $args[ 'name' ] ) ):
135
+ $support_link = $this->get_support_tag_by_name($args['name'], $args['repository']); ?>
136
+
137
+ <?php if($support_link): ?>
138
+ <p><a href="<?php echo $support_link ?>" target="_blank"><?php printf(__('%s support on wpml.org', 'installer'), $args['name'] ) ?></a></p>
139
+
140
+ <?php endif; ?>
141
+ <?php
142
+ // compatibility for installer 1.1
143
+ elseif( isset( $args[ 'support_link' ] ) ): ?>
144
+ <p><?php echo $args[ 'support_link' ]; ?></p>
145
+ <?php endif; ?>
146
+
147
+ </div>
vendor/otgs/installer/templates/repository-listing.php CHANGED
@@ -1,199 +1,199 @@
1
- <?php if((!$this->repository_has_subscription($repository_id) && $match = $this->get_matching_cp($repository)) && $match['exp']): ?>
2
- <p class="alignright installer_highlight"><strong><?php printf('Price offers available until %s', date_i18n(get_option( 'date_format' ), $match['exp'])) ?></strong></p>
3
- <?php endif; ?>
4
-
5
- <h3 id="repository-<?php echo $repository_id ?>"><?php echo $repository['data']['name'] ?></h3>
6
- <?php
7
- $generic_product_name = $this->settings['repositories'][$repository_id]['data']['product-name'];
8
- ?>
9
- <table class="widefat otgs_wp_installer_table" id="installer_repo_<?php echo $repository_id ?>">
10
-
11
- <tr>
12
- <td>&nbsp;</td>
13
- <td class="otgsi_register_product_wrap" align="center" valign="top">
14
- <?php // IF NO SUBSCRIPTION ?>
15
- <?php if(!$this->repository_has_subscription($repository_id)): ?>
16
-
17
- <div style="text-align: right;">
18
- <span><?php _e('Already bought?', 'installer'); ?>&nbsp;</span>
19
- <a class="enter_site_key_js button-primary<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?> disabled<?php endif ?>" href="#"
20
- <?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
21
- style="cursor: help"
22
- disabled="disabled"
23
- title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
24
- <?php endif; ?>
25
- >
26
- <?php printf(__('Register %s', 'installer'), $generic_product_name); ?>
27
- </a>&nbsp;&nbsp;
28
- <form class="otgsi_site_key_form" method="post">
29
- <input type="hidden" name="action" value="save_site_key" />
30
- <input type="hidden" name="nonce" value="<?php echo wp_create_nonce('save_site_key_' . $repository_id) ?>" />
31
- <input type="hidden" name="repository_id" value="<?php echo $repository_id ?>">
32
- <?php _e('2. Enter your site key', 'installer'); ?>
33
- <input type="text" size="10" name="site_key_<?php echo $repository_id ?>" placeholder="<?php echo esc_attr('site key') ?>" />
34
- <input class="button-primary" type="submit" value="<?php esc_attr_e('OK', 'installer') ?>" />
35
- <input class="button-secondary cancel_site_key_js" type="button" value="<?php esc_attr_e('Cancel', 'installer') ?>" />
36
-
37
- <div class="alignleft" style="margin-top:6px;"><?php printf(__('1. Go to your %s%s account%s and add this site URL: %s', 'installer'),
38
- '<a href="' . $this->settings['repositories'][$repository_id]['data']['site_keys_management_url'] . '?add='.urlencode($this->get_installer_site_url( $repository_id )).'">',
39
- $generic_product_name, '</a>', $this->get_installer_site_url( $repository_id )); ?></div>
40
- </form>
41
-
42
-
43
- </div>
44
-
45
- <?php
46
- $site_key = false;
47
-
48
- // IF SUBSCRIPTION
49
- else:
50
-
51
- $site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
52
- $subscription_type = $this->get_subscription_type_for_repository($repository_id);
53
- $upgrade_options = $this->get_upgrade_options($repository_id);
54
- $expired = false;
55
-
56
- ?>
57
-
58
- <?php if($this->repository_has_expired_subscription($repository_id)): $expired = true; ?>
59
- <div>
60
- <p class="installer-warn-box">
61
- <?php _e('Subscription expired. You need to either purchase a new subscription or upgrade if available.', 'installer') ?>
62
- <span class="alignright">
63
- <a class="update_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?> data-nonce="<?php echo wp_create_nonce('update_site_key_' . $repository_id) ?>">
64
- <?php _e('Revalidate subscription', 'installer'); ?>
65
- </a>
66
- </span>
67
- <br />
68
- <span class="details"><?php _e("If you have already purchased or renewed your subscription and you can still see this message, please revalidate your subscription", 'installer') ?></span>
69
- </p>
70
- </div>
71
- <?php else: ?>
72
- <?php $this->show_subscription_renew_warning($repository_id, $subscription_type); ?>
73
- <?php endif; ?>
74
-
75
- <div class="alignright">
76
- <a class="remove_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?>
77
- data-confirmation="<?php esc_attr_e('Are you sure you want to unregister?', 'installer') ?>"
78
- data-nonce="<?php echo wp_create_nonce('remove_site_key_' . $repository_id) ?>"
79
- <?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
80
- style="cursor: help"
81
- disabled="disabled"
82
- title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to unregister.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
83
- <?php endif; ?>
84
- >
85
- <?php printf(__("Unregister %s from this site", 'installer'), $generic_product_name) ?></a>&nbsp;
86
- <a class="update_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?>
87
- data-nonce="<?php echo wp_create_nonce('update_site_key_' . $repository_id) ?>">
88
- <?php _e('Check for updates', 'installer'); ?>
89
- </a>
90
- </div>
91
-
92
- <?php if(empty($expired)): ?>
93
- <div class="alignleft">
94
- <?php if($expires = $this->settings['repositories'][$repository_id]['subscription']['data']->expires): ?>
95
- <?php printf(__('%s is registered on this site. You will receive automatic updates until %s', 'installer'), $generic_product_name, date_i18n('F j, Y', strtotime($expires))); ?>
96
- <?php else: ?>
97
- <?php printf(__('%s is registered on this site. Your Lifetime account gives you updates for life.', 'installer'), $generic_product_name); ?>
98
- <?php endif; ?>
99
- </div>
100
- <?php endif; //if(empty($expired)) ?>
101
-
102
- <?php endif; // if(!repository_has_subscription) ?>
103
- <br clear="all" />
104
- <div class="installer-error-box hidden"></div>
105
-
106
- </td>
107
- </tr>
108
-
109
- <?php
110
-
111
- $subscription_type = isset($subscription_type) ? $subscription_type : null;
112
- $expired = isset($expired) ? $expired : null;
113
- $upgrade_options = isset($upgrade_options) ? $upgrade_options : null;
114
- $packages = $this->_render_product_packages($repository['data']['packages'], $subscription_type, $expired, $upgrade_options, $repository_id);
115
- if(empty($subscription_type) || $expired){
116
- $subpackages_expandable = true;
117
- }else{
118
- $subpackages_expandable = false;
119
- }
120
-
121
- ?>
122
-
123
- <?php foreach($packages as $package): ?>
124
- <tr id="repository-<?php echo $repository_id ?>_<?php echo $package['id'] ?>">
125
- <td><img width="140" height="140" src="<?php echo $package['image_url'] ?>" /></td>
126
- <td>
127
- <p><strong><?php echo $package['name'] ?></strong></p>
128
- <p><?php echo $package['description'] ?></p>
129
-
130
- <?php if($package['products']): ?>
131
- <?php foreach($package['products'] as $product): ?>
132
- <ul class="installer-products-list" style="display:inline">
133
- <li>
134
- <a class="button-secondary" href="<?php echo $product['url'] ?>"><?php echo $product['label'] ?></a>
135
- </li>
136
- </ul>
137
- <?php endforeach; ?>
138
- <?php endif; ?>
139
-
140
- <?php
141
- if ( $package['downloads'] ) {
142
- WP_Installer_Channels()->load_channel_selector( $repository_id, $package['downloads'] );
143
- include $this->plugin_path() . '/templates/downloads-list.php';
144
- }
145
- ?>
146
-
147
- <?php if(!empty($package['sub-packages'])): ?>
148
-
149
- <?php $subpackages = $this->_render_product_packages($package['sub-packages'], $subscription_type, $expired, $upgrade_options, $repository_id); ?>
150
-
151
- <?php if($subpackages): ?>
152
-
153
- <?php if($subpackages_expandable): ?>
154
- <h5><a class="installer_expand_button" href="#" title="<?php esc_attr_e('Click to see individual components options.', 'installer') ?>"><?php _e('Individual components', 'installer') ?></a></h5>
155
- <?php endif; ?>
156
-
157
- <table class="otgs_wp_installer_subtable" style="<?php if($subpackages_expandable) echo 'display:none' ?>">
158
- <?php foreach($subpackages as $package): ?>
159
- <tr id="repository-<?php echo $repository_id ?>_<?php echo $package['id'] ?>">
160
- <td><img width="70" height="70" src="<?php echo $package['image_url'] ?>" /></td>
161
- <td>
162
- <p><strong><?php echo $package['name'] ?></strong></p>
163
- <p><?php echo $package['description'] ?></p>
164
-
165
- <?php if($package['products']): ?>
166
- <?php foreach($package['products'] as $product): ?>
167
- <ul class="installer-products-list" style="display:inline">
168
- <li>
169
- <a class="button-secondary" href="<?php echo $product['url'] ?>"><?php echo $product['label'] ?></a>
170
- </li>
171
- </ul>
172
- <?php endforeach; ?>
173
- <?php endif; ?>
174
-
175
- <?php if($package['downloads']): ?>
176
- <?php include $this->plugin_path() . '/templates/downloads-list.php'; ?>
177
- <?php endif; ?>
178
- </td>
179
- </tr>
180
- <?php endforeach; ?>
181
- </table>
182
- <?php endif; ?>
183
-
184
- <?php endif; ?>
185
-
186
-
187
- </td>
188
- </tr>
189
-
190
- <?php endforeach; ?>
191
-
192
- </table>
193
-
194
-
195
- <p><i><?php printf(__('This page lets you install plugins and update existing plugins. To remove any of these plugins, go to the %splugins%s page and if you have the permission to remove plugins you should be able to do this.', 'installer'), '<a href="' . admin_url('plugins.php') . '">' , '</a>'); ?></i></p>
196
-
197
-
198
-
199
- <br />
1
+ <?php if((!$this->repository_has_subscription($repository_id) && $match = $this->get_matching_cp($repository)) && $match['exp']): ?>
2
+ <p class="alignright installer_highlight"><strong><?php printf('Price offers available until %s', date_i18n(get_option( 'date_format' ), $match['exp'])) ?></strong></p>
3
+ <?php endif; ?>
4
+
5
+ <h3 id="repository-<?php echo $repository_id ?>"><?php echo $repository['data']['name'] ?></h3>
6
+ <?php
7
+ $generic_product_name = $this->settings['repositories'][$repository_id]['data']['product-name'];
8
+ ?>
9
+ <table class="widefat otgs_wp_installer_table" id="installer_repo_<?php echo $repository_id ?>">
10
+
11
+ <tr>
12
+ <td>&nbsp;</td>
13
+ <td class="otgsi_register_product_wrap" align="center" valign="top">
14
+ <?php // IF NO SUBSCRIPTION ?>
15
+ <?php if(!$this->repository_has_subscription($repository_id)): ?>
16
+
17
+ <div style="text-align: right;">
18
+ <span><?php _e('Already bought?', 'installer'); ?>&nbsp;</span>
19
+ <a class="enter_site_key_js button-primary<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?> disabled<?php endif ?>" href="#"
20
+ <?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
21
+ style="cursor: help"
22
+ disabled="disabled"
23
+ title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
24
+ <?php endif; ?>
25
+ >
26
+ <?php printf(__('Register %s', 'installer'), $generic_product_name); ?>
27
+ </a>&nbsp;&nbsp;
28
+ <form class="otgsi_site_key_form" method="post">
29
+ <input type="hidden" name="action" value="save_site_key" />
30
+ <input type="hidden" name="nonce" value="<?php echo wp_create_nonce('save_site_key_' . $repository_id) ?>" />
31
+ <input type="hidden" name="repository_id" value="<?php echo $repository_id ?>">
32
+ <?php _e('2. Enter your site key', 'installer'); ?>
33
+ <input type="text" size="10" name="site_key_<?php echo $repository_id ?>" placeholder="<?php echo esc_attr('site key') ?>" />
34
+ <input class="button-primary" type="submit" value="<?php esc_attr_e('OK', 'installer') ?>" />
35
+ <input class="button-secondary cancel_site_key_js" type="button" value="<?php esc_attr_e('Cancel', 'installer') ?>" />
36
+
37
+ <div class="alignleft" style="margin-top:6px;"><?php printf(__('1. Go to your %s%s account%s and add this site URL: %s', 'installer'),
38
+ '<a href="' . $this->settings['repositories'][$repository_id]['data']['site_keys_management_url'] . '?add='.urlencode($this->get_installer_site_url( $repository_id )).'">',
39
+ $generic_product_name, '</a>', $this->get_installer_site_url( $repository_id )); ?></div>
40
+ </form>
41
+
42
+
43
+ </div>
44
+
45
+ <?php
46
+ $site_key = false;
47
+
48
+ // IF SUBSCRIPTION
49
+ else:
50
+
51
+ $site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
52
+ $subscription_type = $this->get_subscription_type_for_repository($repository_id);
53
+ $upgrade_options = $this->get_upgrade_options($repository_id);
54
+ $expired = false;
55
+
56
+ ?>
57
+
58
+ <?php if($this->repository_has_expired_subscription($repository_id)): $expired = true; ?>
59
+ <div>
60
+ <p class="installer-warn-box">
61
+ <?php _e('Subscription expired. You need to either purchase a new subscription or upgrade if available.', 'installer') ?>
62
+ <span class="alignright">
63
+ <a class="update_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?> data-nonce="<?php echo wp_create_nonce('update_site_key_' . $repository_id) ?>">
64
+ <?php _e('Revalidate subscription', 'installer'); ?>
65
+ </a>
66
+ </span>
67
+ <br />
68
+ <span class="details"><?php _e("If you have already purchased or renewed your subscription and you can still see this message, please revalidate your subscription", 'installer') ?></span>
69
+ </p>
70
+ </div>
71
+ <?php else: ?>
72
+ <?php $this->show_subscription_renew_warning($repository_id, $subscription_type); ?>
73
+ <?php endif; ?>
74
+
75
+ <div class="alignright">
76
+ <a class="remove_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?>
77
+ data-confirmation="<?php esc_attr_e('Are you sure you want to unregister?', 'installer') ?>"
78
+ data-nonce="<?php echo wp_create_nonce('remove_site_key_' . $repository_id) ?>"
79
+ <?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
80
+ style="cursor: help"
81
+ disabled="disabled"
82
+ title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to unregister.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
83
+ <?php endif; ?>
84
+ >
85
+ <?php printf(__("Unregister %s from this site", 'installer'), $generic_product_name) ?></a>&nbsp;
86
+ <a class="update_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?>
87
+ data-nonce="<?php echo wp_create_nonce('update_site_key_' . $repository_id) ?>">
88
+ <?php _e('Check for updates', 'installer'); ?>
89
+ </a>
90
+ </div>
91
+
92
+ <?php if(empty($expired)): ?>
93
+ <div class="alignleft">
94
+ <?php if($expires = $this->settings['repositories'][$repository_id]['subscription']['data']->expires): ?>
95
+ <?php printf(__('%s is registered on this site. You will receive automatic updates until %s', 'installer'), $generic_product_name, date_i18n('F j, Y', strtotime($expires))); ?>
96
+ <?php else: ?>
97
+ <?php printf(__('%s is registered on this site. Your Lifetime account gives you updates for life.', 'installer'), $generic_product_name); ?>
98
+ <?php endif; ?>
99
+ </div>
100
+ <?php endif; //if(empty($expired)) ?>
101
+
102
+ <?php endif; // if(!repository_has_subscription) ?>
103
+ <br clear="all" />
104
+ <div class="installer-error-box hidden"></div>
105
+
106
+ </td>
107
+ </tr>
108
+
109
+ <?php
110
+
111
+ $subscription_type = isset($subscription_type) ? $subscription_type : null;
112
+ $expired = isset($expired) ? $expired : null;
113
+ $upgrade_options = isset($upgrade_options) ? $upgrade_options : null;
114
+ $packages = $this->_render_product_packages($repository['data']['packages'], $subscription_type, $expired, $upgrade_options, $repository_id);
115
+ if(empty($subscription_type) || $expired){
116
+ $subpackages_expandable = true;
117
+ }else{
118
+ $subpackages_expandable = false;
119
+ }
120
+
121
+ ?>
122
+
123
+ <?php foreach($packages as $package): ?>
124
+ <tr id="repository-<?php echo $repository_id ?>_<?php echo $package['id'] ?>">
125
+ <td class="installer-repository-image"><img width="140" src="<?php echo $package['image_url'] ?>" /></td>
126
+ <td>
127
+ <p><strong><?php echo $package['name'] ?></strong></p>
128
+ <p><?php echo $package['description'] ?></p>
129
+
130
+ <?php if($package['products']): ?>
131
+ <?php foreach($package['products'] as $product): ?>
132
+ <ul class="installer-products-list" style="display:inline">
133
+ <li>
134
+ <a class="button-secondary" href="<?php echo $product['url'] ?>"><?php echo $product['label'] ?></a>
135
+ </li>
136
+ </ul>
137
+ <?php endforeach; ?>
138
+ <?php endif; ?>
139
+
140
+ <?php
141
+ if ( $package['downloads'] ) {
142
+ WP_Installer_Channels()->load_channel_selector( $repository_id, $package['downloads'] );
143
+ include $this->plugin_path() . '/templates/downloads-list.php';
144
+ }
145
+ ?>
146
+
147
+ <?php if(!empty($package['sub-packages'])): ?>
148
+
149
+ <?php $subpackages = $this->_render_product_packages($package['sub-packages'], $subscription_type, $expired, $upgrade_options, $repository_id); ?>
150
+
151
+ <?php if($subpackages): ?>
152
+
153
+ <?php if($subpackages_expandable): ?>
154
+ <h5><a class="installer_expand_button" href="#" title="<?php esc_attr_e('Click to see individual components options.', 'installer') ?>"><?php _e('Individual components', 'installer') ?></a></h5>
155
+ <?php endif; ?>
156
+
157
+ <table class="otgs_wp_installer_subtable" style="<?php if($subpackages_expandable) echo 'display:none' ?>">
158
+ <?php foreach($subpackages as $package): ?>
159
+ <tr id="repository-<?php echo $repository_id ?>_<?php echo $package['id'] ?>">
160
+ <td><img width="70" height="70" src="<?php echo $package['image_url'] ?>" /></td>
161
+ <td>
162
+ <p><strong><?php echo $package['name'] ?></strong></p>
163
+ <p><?php echo $package['description'] ?></p>
164
+
165
+ <?php if($package['products']): ?>
166
+ <?php foreach($package['products'] as $product): ?>
167
+ <ul class="installer-products-list" style="display:inline">
168
+ <li>
169
+ <a class="button-secondary" href="<?php echo $product['url'] ?>"><?php echo $product['label'] ?></a>
170
+ </li>
171
+ </ul>
172
+ <?php endforeach; ?>
173
+ <?php endif; ?>
174
+
175
+ <?php if($package['downloads']): ?>
176
+ <?php include $this->plugin_path() . '/templates/downloads-list.php'; ?>
177
+ <?php endif; ?>
178
+ </td>
179
+ </tr>
180
+ <?php endforeach; ?>
181
+ </table>
182
+ <?php endif; ?>
183
+
184
+ <?php endif; ?>
185
+
186
+
187
+ </td>
188
+ </tr>
189
+
190
+ <?php endforeach; ?>
191
+
192
+ </table>
193
+
194
+
195
+ <p><i><?php printf(__('This page lets you install plugins and update existing plugins. To remove any of these plugins, go to the %splugins%s page and if you have the permission to remove plugins you should be able to do this.', 'installer'), '<a href="' . admin_url('plugins.php') . '">' , '</a>'); ?></i></p>
196
+
197
+
198
+
199
+ <br />
wpml-woocommerce.php CHANGED
@@ -7,15 +7,15 @@
7
  Author URI: http://www.onthegosystems.com/
8
  Text Domain: woocommerce-multilingual
9
  Requires at least: 3.9
10
- Tested up to: 4.8
11
- Version: 4.2.0
12
  */
13
 
14
  if ( defined( 'WCML_VERSION' ) ) {
15
  return;
16
  }
17
 
18
- define( 'WCML_VERSION', '4.2.0' );
19
  define( 'WCML_PLUGIN_PATH', dirname( __FILE__ ) );
20
  define( 'WCML_PLUGIN_FOLDER', basename( WCML_PLUGIN_PATH ) );
21
  define( 'WCML_LOCALE_PATH', WCML_PLUGIN_PATH . '/locale' );
7
  Author URI: http://www.onthegosystems.com/
8
  Text Domain: woocommerce-multilingual
9
  Requires at least: 3.9
10
+ Tested up to: 4.8.1
11
+ Version: 4.2.0.1
12
  */
13
 
14
  if ( defined( 'WCML_VERSION' ) ) {
15
  return;
16
  }
17
 
18
+ define( 'WCML_VERSION', '4.2.0.1' );
19
  define( 'WCML_PLUGIN_PATH', dirname( __FILE__ ) );
20
  define( 'WCML_PLUGIN_FOLDER', basename( WCML_PLUGIN_PATH ) );
21
  define( 'WCML_LOCALE_PATH', WCML_PLUGIN_PATH . '/locale' );