CDTClient
4 weeks ago
admin-notices
4 weeks ago
buy-url
4 weeks ago
debug
4 weeks ago
exceptions
5 years ago
instances
4 weeks ago
loader
5 years ago
products
4 weeks ago
repository
4 weeks ago
rest
4 weeks ago
site-key
4 weeks ago
support
4 weeks ago
template-service
4 weeks ago
upgrade
4 weeks ago
utilities
4 weeks ago
wpml-content-stats
4 weeks ago
class-installer-dependencies.php
4 weeks ago
class-installer-theme.php
4 weeks ago
class-installer-upgrader-skins.php
4 weeks ago
class-otgs-installer-autoloader.php
5 years ago
class-otgs-installer-cloned-sites-handler.php
4 weeks ago
class-otgs-installer-debug-info.php
4 weeks ago
class-otgs-installer-factory.php
4 weeks ago
class-otgs-installer-filename-hooks.php
4 weeks ago
class-otgs-installer-icons.php
4 weeks ago
class-otgs-installer-loader.php
10 months ago
class-otgs-installer-package-product-finder.php
4 weeks ago
class-otgs-installer-package-product.php
4 weeks ago
class-otgs-installer-package.php
5 years ago
class-otgs-installer-php-functions.php
4 weeks ago
class-otgs-installer-plugin-factory.php
4 weeks ago
class-otgs-installer-plugin-finder.php
4 weeks ago
class-otgs-installer-plugin.php
4 weeks ago
class-otgs-installer-plugins-page-notice.php
4 weeks ago
class-otgs-installer-plugins-update-cache-cleaner.php
5 years ago
class-otgs-installer-settings.php
4 weeks ago
class-otgs-installer-source-factory.php
5 years ago
class-otgs-installer-source.php
4 weeks ago
class-otgs-installer-subscription-factory.php
5 years ago
class-otgs-installer-subscription-warning-message.php
4 weeks ago
class-otgs-installer-subscription.php
4 weeks ago
class-otgs-installer-wp-components-hooks.php
4 weeks ago
class-otgs-installer-wp-components-sender.php
4 weeks ago
class-otgs-installer-wp-components-setting-ajax.php
4 weeks ago
class-otgs-installer-wp-components-setting-resources.php
4 weeks ago
class-otgs-installer-wp-components-storage.php
4 weeks ago
class-otgs-installer-wp-share-local-components-setting-hooks.php
4 weeks ago
class-otgs-installer-wp-share-local-components-setting.php
4 weeks ago
class-translation-service-info.php
4 weeks ago
class-wp-installer-api.php
4 weeks ago
class-wp-installer-channels.php
4 weeks ago
class-wp-installer.php
4 weeks ago
functions-core.php
4 weeks ago
functions-templates.php
4 weeks ago
otgs-installer-autoload-classmap.php
10 months ago
class-installer-dependencies.php
316 lines
| 1 | <?php |
| 2 | |
| 3 | use OTGS\Installer\Settings; |
| 4 | |
| 5 | class Installer_Dependencies { |
| 6 | |
| 7 | private $uploading_allowed = null; |
| 8 | private $is_win_paths_exception = array(); |
| 9 | |
| 10 | private $missing_php_libraries = array(); |
| 11 | |
| 12 | function __construct() { |
| 13 | |
| 14 | add_action( 'admin_init', array( $this, 'prevent_plugins_update_on_plugins_page' ), 100 ); |
| 15 | |
| 16 | |
| 17 | global $pagenow; |
| 18 | if ( $pagenow == 'update.php' ) { |
| 19 | if ( isset( $_GET['action'] ) && $_GET['action'] == 'update-selected' ) { |
| 20 | add_action( 'admin_head', array( |
| 21 | $this, |
| 22 | 'prevent_plugins_update_on_updates_screen' |
| 23 | ) ); |
| 24 | } else { |
| 25 | add_action( 'all_admin_notices', array( |
| 26 | $this, |
| 27 | 'prevent_plugins_update_on_updates_screen' |
| 28 | ) ); |
| 29 | } |
| 30 | } |
| 31 | add_action( 'wp_ajax_update-plugin', array( |
| 32 | $this, |
| 33 | 'prevent_plugins_update_on_updates_screen' |
| 34 | ), 0 ); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | public function is_win_paths_exception( $repository_id ) { |
| 39 | if ( ! isset( $this->is_win_paths_exception[ $repository_id ] ) ) { |
| 40 | $this->is_win_paths_exception[ $repository_id ] = false; |
| 41 | if ( strtoupper( substr( constant('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 | $a_plugin = 'https://' . $repository_id . '.org/?download=637370&version=5.5.2'; |
| 52 | |
| 53 | $url = OTGS_Installer()->append_site_key_to_download_url( $a_plugin, 'xxxxxx', $repository_id ); |
| 54 | $tmpfname = wp_tempnam( $url ); |
| 55 | $tmpname_length = strlen( basename( $tmpfname ) ) - 4; |
| 56 | wp_delete_file( $tmpfname ); |
| 57 | |
| 58 | if ( $upgrade_path_length + $tmpname_length + $longest_path[ $repository_id ] + $margin > $windows_max_path_length ) { |
| 59 | $this->is_win_paths_exception[ $repository_id ] = true; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return $this->is_win_paths_exception[ $repository_id ]; |
| 65 | } |
| 66 | |
| 67 | public function is_uploading_allowed() { |
| 68 | |
| 69 | if ( ! isset( $this->uploading_allowed ) ) { |
| 70 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 71 | require_once WP_Installer()->plugin_path() . '/includes/class-installer-upgrader-skins.php'; |
| 72 | |
| 73 | $upgrader_skins = new Installer_Upgrader_Skins(); |
| 74 | $upgrader = new Plugin_Upgrader( $upgrader_skins ); |
| 75 | |
| 76 | ob_start(); |
| 77 | $res = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) ); |
| 78 | ob_end_clean(); |
| 79 | |
| 80 | if ( ! $res || is_wp_error( $res ) ) { |
| 81 | $this->uploading_allowed = false; |
| 82 | } else { |
| 83 | $this->uploading_allowed = true; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return $this->uploading_allowed; |
| 88 | |
| 89 | } |
| 90 | |
| 91 | public function cant_download( $repository_id ) { |
| 92 | |
| 93 | return ! $this->is_uploading_allowed() || $this->is_win_paths_exception( $repository_id ); |
| 94 | |
| 95 | } |
| 96 | |
| 97 | public function win_paths_exception_message() { |
| 98 | return __( 'Downloading is not possible. WordPress cannot create required folders because of the |
| 99 | 256 characters limitation of the current Windows environment.', 'installer' ); |
| 100 | } |
| 101 | |
| 102 | public function prevent_plugins_update_on_plugins_page() { |
| 103 | if ( strtoupper( substr( constant('PHP_OS'), 0, 3 ) ) !== 'WIN' ) { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | $plugins = get_site_transient( 'update_plugins' ); |
| 108 | if ( isset( $plugins->response ) && is_array( $plugins->response ) ) { |
| 109 | $plugins_with_updates = array_keys( $plugins->response ); |
| 110 | } |
| 111 | |
| 112 | if ( ! empty( $plugins_with_updates ) ) { |
| 113 | |
| 114 | $plugins = get_plugins(); |
| 115 | |
| 116 | $installer_settings = Settings::load_subscriptions(); |
| 117 | if ( isset( $installer_settings['repositories'] ) ) { |
| 118 | foreach ( $installer_settings['repositories'] as $repository_id => $subscription ) { |
| 119 | |
| 120 | if ( $this->is_win_paths_exception( $repository_id ) ) { |
| 121 | $settings = Settings::load(); |
| 122 | $repository = $settings['repositories'][ $repository_id ]; |
| 123 | |
| 124 | $repositories_plugins = array(); |
| 125 | foreach ( $repository['data']['packages'] as $package ) { |
| 126 | foreach ( $package['products'] as $product ) { |
| 127 | foreach ( $product['plugins'] as $plugin_slug ) { |
| 128 | $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ]; |
| 129 | if ( empty( $download['free-on-wporg'] ) ) { |
| 130 | $repositories_plugins[ $download['slug'] ] = $download['name']; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | foreach ( $plugins as $plugin_id => $plugin ) { |
| 137 | |
| 138 | if ( in_array( $plugin_id, $plugins_with_updates ) ) { |
| 139 | |
| 140 | $wp_plugin_slug = dirname( $plugin_id ); |
| 141 | if ( empty( $wp_plugin_slug ) ) { |
| 142 | $wp_plugin_slug = basename( $plugin_id, '.php' ); |
| 143 | } |
| 144 | |
| 145 | foreach ( $repositories_plugins as $slug => $name ) { |
| 146 | if ( $wp_plugin_slug == $slug || $name == $plugin['Name'] || $name == $plugin['Title'] ) { |
| 147 | |
| 148 | remove_action( "after_plugin_row_$plugin_id", 'wp_plugin_update_row', 10 ); |
| 149 | add_action( "after_plugin_row_$plugin_id", array( |
| 150 | $this, |
| 151 | 'wp_plugin_update_row_win_exception', |
| 152 | ), 10, 0 ); |
| 153 | |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | } |
| 160 | |
| 161 | } |
| 162 | |
| 163 | |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | } |
| 168 | |
| 169 | } |
| 170 | |
| 171 | public function wp_plugin_update_row_win_exception() { |
| 172 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
| 173 | echo '<tr class="plugin-update-tr">'; |
| 174 | echo '<td class="plugin-update colspanchange" colspan="' . esc_attr( (string) $wp_list_table->get_column_count() ) . |
| 175 | '"><div class="update-message">' . $this->win_paths_exception_message() . '</div></td>'; |
| 176 | echo '</tr>'; |
| 177 | } |
| 178 | |
| 179 | public function prevent_plugins_update_on_updates_screen() { |
| 180 | |
| 181 | if ( isset( $_REQUEST['action'] ) ) { |
| 182 | |
| 183 | $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : ''; |
| 184 | |
| 185 | $installer_settings = WP_Installer()->settings; |
| 186 | |
| 187 | if ( 'update-selected' == $action ) { |
| 188 | |
| 189 | global $plugins; |
| 190 | |
| 191 | if ( isset( $plugins ) && is_array( $plugins ) ) { |
| 192 | |
| 193 | foreach ( $plugins as $k => $plugin ) { |
| 194 | |
| 195 | $wp_plugin_slug = dirname( $plugin ); |
| 196 | |
| 197 | foreach ( $installer_settings['repositories'] as $repository_id => $repository ) { |
| 198 | |
| 199 | if ( $this->is_win_paths_exception( $repository_id ) ) { |
| 200 | |
| 201 | foreach ( $repository['data']['packages'] as $package ) { |
| 202 | |
| 203 | foreach ( $package['products'] as $product ) { |
| 204 | |
| 205 | foreach ( $product['plugins'] as $plugin_slug ) { |
| 206 | |
| 207 | $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ]; |
| 208 | |
| 209 | if ( $download['slug'] == $wp_plugin_slug && empty( $download['free-on-wporg'] ) ) { |
| 210 | |
| 211 | echo '<div class="updated error"><p>' . $this->win_paths_exception_message() . |
| 212 | ' <strong>(' . $download['name'] . ')</strong>' . '</p></div>'; |
| 213 | unset( $plugins[ $k ] ); |
| 214 | |
| 215 | break( 3 ); |
| 216 | |
| 217 | } |
| 218 | |
| 219 | } |
| 220 | |
| 221 | } |
| 222 | |
| 223 | } |
| 224 | |
| 225 | |
| 226 | } |
| 227 | |
| 228 | } |
| 229 | |
| 230 | } |
| 231 | |
| 232 | } |
| 233 | |
| 234 | } |
| 235 | |
| 236 | |
| 237 | if ( 'upgrade-plugin' == $action || 'update-plugin' == $action ) { |
| 238 | |
| 239 | $plugin = isset( $_REQUEST['plugin'] ) ? trim( sanitize_text_field( $_REQUEST['plugin'] ) ) : ''; |
| 240 | |
| 241 | $wp_plugin_slug = dirname( $plugin ); |
| 242 | |
| 243 | foreach ( $installer_settings['repositories'] as $repository_id => $repository ) { |
| 244 | |
| 245 | if ( $this->is_win_paths_exception( $repository_id ) ) { |
| 246 | foreach ( $repository['data']['packages'] as $package ) { |
| 247 | |
| 248 | foreach ( $package['products'] as $product ) { |
| 249 | |
| 250 | foreach ( $product['plugins'] as $plugin_slug ) { |
| 251 | $download = $installer_settings['repositories'][ $repository_id ]['data']['downloads']['plugins'][ $plugin_slug ]; |
| 252 | |
| 253 | if ( $download['slug'] == $wp_plugin_slug && empty ( $download['free-on-wporg'] ) ) { |
| 254 | |
| 255 | echo '<div class="updated error"><p>' . $this->win_paths_exception_message() . '</p></div>'; |
| 256 | |
| 257 | echo '<div class="wrap">'; |
| 258 | echo '<h2>' . __( 'Update Plugin' ) . '</h2>'; |
| 259 | echo '<a href="' . admin_url( 'update-core.php' ) . '">' . __( 'Return to the updates page', 'installer' ) . '</a>'; |
| 260 | echo '</div>'; |
| 261 | require_once( ABSPATH . 'wp-admin/admin-footer.php' ); |
| 262 | exit; |
| 263 | |
| 264 | } |
| 265 | |
| 266 | } |
| 267 | |
| 268 | } |
| 269 | |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | } |
| 274 | |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | } |
| 279 | |
| 280 | public function php_libraries_missing() { |
| 281 | $requirements = new OTGS_Installer_Requirements(); |
| 282 | |
| 283 | foreach ( $requirements->get() as $requirement ) { |
| 284 | if ( ! $requirement['active'] ) { |
| 285 | $this->missing_php_libraries[] = $requirement['name']; |
| 286 | } |
| 287 | } |
| 288 | if ( $this->missing_php_libraries ) { |
| 289 | add_action( 'admin_notices', array( $this, 'missing_php_functions_notice' ) ); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | public function missing_php_functions_notice() { |
| 294 | $installer_doc_url = 'https://wpml.org/?p=72674#automated-updates'; |
| 295 | $installer_doc_link = '<a href="' . $installer_doc_url . '">' . __( 'OTGS Installer', 'installer' ) . '</a>'; |
| 296 | |
| 297 | echo '<div class="updated error">'; |
| 298 | echo '<p>'; |
| 299 | echo sprintf( |
| 300 | __( '%s, responsible for receiving automated updates for WPML and Toolset, requires the following PHP component(s) in order to function:', 'installer' ), |
| 301 | $installer_doc_link |
| 302 | ); |
| 303 | echo '<code>' . join( ', ', $this->missing_php_libraries ) . '</code>'; |
| 304 | echo '</p>'; |
| 305 | |
| 306 | $minimum_requirements_link = '<a href="https://wpml.org/?page_id=716">' . __( 'Minimum WPML requirements' ) . '</a>'; |
| 307 | echo '<p>' . sprintf( __( 'Learn more: %s', 'installer' ), $minimum_requirements_link ) . '</p>'; |
| 308 | |
| 309 | echo '</div>'; |
| 310 | } |
| 311 | |
| 312 | } |
| 313 | |
| 314 | |
| 315 | |
| 316 |