PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.10.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.10.0
4.12.0 4.10.0 4.9.0 4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / Helpers / PluginSilentUpgrader.php
custom-facebook-feed / inc / Helpers Last commit date
PluginSilentUpgrader.php 3 weeks ago PluginSilentUpgraderSkin.php 3 weeks ago Util.php 3 weeks ago index.php 3 weeks ago
PluginSilentUpgrader.php
584 lines
1 <?php
2
3 namespace CustomFacebookFeed\Helpers;
4
5 if (! defined('ABSPATH')) {
6 exit;
7 }
8 use WP_Error;
9 use WP_Upgrader;
10 use WP_Filesystem_Base;
11
12 /** \WP_Upgrader class */
13 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
14
15 /** \Plugin_Upgrader class */
16 require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
17
18 /**
19 * In WP 5.3 a PHP 5.6 splat operator (...$args) was added to \WP_Upgrader_Skin::feedback().
20 * We need to remove all calls to *Skin::feedback() method, as we can't override it in own Skins
21 * without breaking support for PHP 5.3-5.5.
22 *
23 * @internal Please do not use this class outside of core WPForms development. May be removed at any time.
24 *
25 * @since 1.5.6.1
26 */
27 class PluginSilentUpgrader extends \Plugin_Upgrader
28 {
29 /**
30 * Run an upgrade/installation.
31 *
32 * Attempts to download the package (if it is not a local file), unpack it, and
33 * install it in the destination folder.
34 *
35 * @since 1.5.6.1
36 *
37 * @param array $options {
38 * Array or string of arguments for upgrading/installing a package.
39 *
40 * @type string $package The full path or URI of the package to install.
41 * Default empty.
42 * @type string $destination The full path to the destination folder.
43 * Default empty.
44 * @type bool $clear_destination Whether to delete any files already in the
45 * destination folder. Default false.
46 * @type bool $clear_working Whether to delete the files form the working
47 * directory after copying to the destination.
48 * Default false.
49 * @type bool $abort_if_destination_exists Whether to abort the installation if the destination
50 * folder already exists. When true, `$clear_destination`
51 * should be false. Default true.
52 * @type bool $is_multi Whether this run is one of multiple upgrade/installation
53 * actions being performed in bulk. When true, the skin
54 * WP_Upgrader::header() and WP_Upgrader::footer()
55 * aren't called. Default false.
56 * @type array $hook_extra Extra arguments to pass to the filter hooks called by
57 * WP_Upgrader::run().
58 * }
59 * @return array|false|WP_error The result from self::install_package() on success, otherwise a WP_Error,
60 * or false if unable to connect to the filesystem.
61 */
62 public function run($options)
63 {
64
65 $defaults = array(
66 'package' => '', // Please always pass this.
67 'destination' => '', // And this
68 'clear_destination' => false,
69 'abort_if_destination_exists' => false, // Abort if the Destination directory exists, Pass clear_destination as false please
70 'clear_working' => true,
71 'is_multi' => false,
72 'hook_extra' => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
73 );
74
75 $options = wp_parse_args($options, $defaults);
76
77 /**
78 * Filters the package options before running an update.
79 *
80 * See also {@see 'upgrader_process_complete'}.
81 *
82 * @since 4.3.0
83 *
84 * @param array $options {
85 * Options used by the upgrader.
86 *
87 * @type string $package Package for update.
88 * @type string $destination Update location.
89 * @type bool $clear_destination Clear the destination resource.
90 * @type bool $clear_working Clear the working resource.
91 * @type bool $abort_if_destination_exists Abort if the Destination directory exists.
92 * @type bool $is_multi Whether the upgrader is running multiple times.
93 * @type array $hook_extra {
94 * Extra hook arguments.
95 *
96 * @type string $action Type of action. Default 'update'.
97 * @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'.
98 * @type bool $bulk Whether the update process is a bulk update. Default true.
99 * @type string $plugin Path to the plugin file relative to the plugins directory.
100 * @type string $theme The stylesheet or template name of the theme.
101 * @type string $language_update_type The language pack update type. Accepts 'plugin', 'theme',
102 * or 'core'.
103 * @type object $language_update The language pack update offer.
104 * }
105 * }
106 */
107 $options = apply_filters('upgrader_package_options', $options);
108
109 if (! $options['is_multi']) { // call $this->header separately if running multiple times
110 $this->skin->header();
111 }
112
113 // Connect to the Filesystem first.
114 $res = $this->fs_connect(array( WP_CONTENT_DIR, $options['destination'] ));
115 // Mainly for non-connected filesystem.
116 if (! $res) {
117 if (! $options['is_multi']) {
118 $this->skin->footer();
119 }
120 return false;
121 }
122
123 $this->skin->before();
124
125 if (is_wp_error($res)) {
126 $this->skin->error($res);
127 $this->skin->after();
128 if (! $options['is_multi']) {
129 $this->skin->footer();
130 }
131 return $res;
132 }
133
134 /*
135 * Download the package (Note, This just returns the filename
136 * of the file if the package is a local file)
137 */
138 $download = $this->download_package($options['package'], true);
139
140 // Allow for signature soft-fail.
141 // WARNING: This may be removed in the future.
142 if (is_wp_error($download) && $download->get_error_data('softfail-filename')) {
143 // Don't output the 'no signature could be found' failure message for now.
144 if ('signature_verification_no_signature' != $download->get_error_code() || WP_DEBUG) {
145 // Outout the failure error as a normal feedback, and not as an error:
146 // $this->skin->feedback( $download->get_error_message() );
147
148 // Report this failure back to WordPress.org for debugging purposes.
149 wp_version_check(
150 array(
151 'signature_failure_code' => $download->get_error_code(),
152 'signature_failure_data' => $download->get_error_data(),
153 )
154 );
155 }
156
157 // Pretend this error didn't happen.
158 $download = $download->get_error_data('softfail-filename');
159 }
160
161 if (is_wp_error($download)) {
162 $this->skin->error($download);
163 $this->skin->after();
164 if (! $options['is_multi']) {
165 $this->skin->footer();
166 }
167 return $download;
168 }
169
170 $delete_package = ( $download != $options['package'] ); // Do not delete a "local" file
171
172 // Unzips the file into a temporary directory.
173 $working_dir = $this->unpack_package($download, $delete_package);
174 if (is_wp_error($working_dir)) {
175 $this->skin->error($working_dir);
176 $this->skin->after();
177 if (! $options['is_multi']) {
178 $this->skin->footer();
179 }
180 return $working_dir;
181 }
182
183 // With the given options, this installs it to the destination directory.
184 $result = $this->install_package(
185 array(
186 'source' => $working_dir,
187 'destination' => $options['destination'],
188 'clear_destination' => $options['clear_destination'],
189 'abort_if_destination_exists' => $options['abort_if_destination_exists'],
190 'clear_working' => $options['clear_working'],
191 'hook_extra' => $options['hook_extra'],
192 )
193 );
194
195 $this->skin->set_result($result);
196 if (is_wp_error($result)) {
197 $this->skin->error($result);
198 // $this->skin->feedback( 'process_failed' );
199 } else {
200 // Installation succeeded.
201 // $this->skin->feedback( 'process_success' );
202 }
203
204 $this->skin->after();
205
206 if (! $options['is_multi']) {
207
208 /**
209 * Fires when the upgrader process is complete.
210 *
211 * See also {@see 'upgrader_package_options'}.
212 *
213 * @since 3.6.0
214 * @since 3.7.0 Added to WP_Upgrader::run().
215 * @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`.
216 *
217 * @param WP_Upgrader $this WP_Upgrader instance. In other contexts, $this, might be a
218 * Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
219 * @param array $hook_extra {
220 * Array of bulk item update data.
221 *
222 * @type string $action Type of action. Default 'update'.
223 * @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'.
224 * @type bool $bulk Whether the update process is a bulk update. Default true.
225 * @type array $plugins Array of the basename paths of the plugins' main files.
226 * @type array $themes The theme slugs.
227 * @type array $translations {
228 * Array of translations update data.
229 *
230 * @type string $language The locale the translation is for.
231 * @type string $type Type of translation. Accepts 'plugin', 'theme', or 'core'.
232 * @type string $slug Text domain the translation is for. The slug of a theme/plugin or
233 * 'default' for core translations.
234 * @type string $version The version of a theme, plugin, or core.
235 * }
236 * }
237 */
238 do_action('upgrader_process_complete', $this, $options['hook_extra']);
239
240 $this->skin->footer();
241 }
242
243 return $result;
244 }
245
246 /**
247 * Toggle maintenance mode for the site.
248 *
249 * Create/delete the maintenance file to enable/disable maintenance mode.
250 *
251 * @since 2.8.0
252 *
253 * @global WP_Filesystem_Base $wp_filesystem Subclass
254 *
255 * @param bool $enable True to enable maintenance mode, false to disable.
256 */
257 public function maintenance_mode($enable = false)
258 {
259 global $wp_filesystem;
260 $file = $wp_filesystem->abspath() . '.maintenance';
261 if ($enable) {
262 // $this->skin->feedback( 'maintenance_start' );
263 // Create maintenance file to signal that we are upgrading
264 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
265 $wp_filesystem->delete($file);
266 $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
267 } elseif (! $enable && $wp_filesystem->exists($file)) {
268 // $this->skin->feedback( 'maintenance_end' );
269 $wp_filesystem->delete($file);
270 }
271 }
272
273 /**
274 * Download a package.
275 *
276 * @since 2.8.0
277 *
278 * @param string $package The URI of the package. If this is the full path to an
279 * existing local file, it will be returned untouched.
280 * @param bool $check_signatures Whether to validate file signatures. Default false.
281 * @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
282 */
283 public function download_package($package, $check_signatures = false, $hook_extra = array())
284 {
285
286 /**
287 * Filters whether to return the package.
288 *
289 * @since 3.7.0
290 *
291 * @param bool $reply Whether to bail without returning the package.
292 * Default false.
293 * @param string $package The package file name.
294 * @param WP_Upgrader $this The WP_Upgrader instance.
295 */
296 $reply = apply_filters('upgrader_pre_download', false, $package, $this);
297 if (false !== $reply) {
298 return $reply;
299 }
300
301 if (! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package)) { // Local file or remote?
302 return $package; // must be a local file..
303 }
304
305 if (empty($package)) {
306 return new WP_Error('no_package', $this->strings['no_package']);
307 }
308
309 // $this->skin->feedback( 'downloading_package', $package );
310
311 $download_file = download_url($package, 300, $check_signatures);
312
313 if (is_wp_error($download_file) && ! $download_file->get_error_data('softfail-filename')) {
314 return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
315 }
316
317 return $download_file;
318 }
319
320 /**
321 * Unpack a compressed package file.
322 *
323 * @since 2.8.0
324 *
325 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
326 *
327 * @param string $package Full path to the package file.
328 * @param bool $delete_package Optional. Whether to delete the package file after attempting
329 * to unpack it. Default true.
330 * @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure.
331 */
332 public function unpack_package($package, $delete_package = true)
333 {
334 global $wp_filesystem;
335
336 // $this->skin->feedback( 'unpack_package' );
337
338 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
339
340 // Clean up contents of upgrade directory beforehand.
341 $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
342 if (! empty($upgrade_files)) {
343 foreach ($upgrade_files as $file) {
344 $wp_filesystem->delete($upgrade_folder . $file['name'], true);
345 }
346 }
347
348 // We need a working directory - Strip off any .tmp or .zip suffixes
349 $working_dir = $upgrade_folder . basename(basename($package, '.tmp'), '.zip');
350
351 // Clean up working directory
352 if ($wp_filesystem->is_dir($working_dir)) {
353 $wp_filesystem->delete($working_dir, true);
354 }
355
356 // Unzip package to working directory
357 $result = unzip_file($package, $working_dir);
358
359 // Once extracted, delete the package if required.
360 if ($delete_package) {
361 unlink($package);
362 }
363
364 if (is_wp_error($result)) {
365 $wp_filesystem->delete($working_dir, true);
366 if ('incompatible_archive' == $result->get_error_code()) {
367 return new WP_Error('incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data());
368 }
369 return $result;
370 }
371
372 return $working_dir;
373 }
374
375 /**
376 * Install a package.
377 *
378 * Copies the contents of a package form a source directory, and installs them in
379 * a destination directory. Optionally removes the source. It can also optionally
380 * clear out the destination folder if it already exists.
381 *
382 * @since 2.8.0
383 *
384 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
385 * @global array $wp_theme_directories
386 *
387 * @param array|string $args {
388 * Optional. Array or string of arguments for installing a package. Default empty array.
389 *
390 * @type string $source Required path to the package source. Default empty.
391 * @type string $destination Required path to a folder to install the package in.
392 * Default empty.
393 * @type bool $clear_destination Whether to delete any files already in the destination
394 * folder. Default false.
395 * @type bool $clear_working Whether to delete the files form the working directory
396 * after copying to the destination. Default false.
397 * @type bool $abort_if_destination_exists Whether to abort the installation if
398 * the destination folder already exists. Default true.
399 * @type array $hook_extra Extra arguments to pass to the filter hooks called by
400 * WP_Upgrader::install_package(). Default empty array.
401 * }
402 *
403 * @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.
404 */
405 public function install_package($args = array())
406 {
407 global $wp_filesystem, $wp_theme_directories;
408
409 $defaults = array(
410 'source' => '', // Please always pass this
411 'destination' => '', // and this
412 'clear_destination' => false,
413 'clear_working' => false,
414 'abort_if_destination_exists' => true,
415 'hook_extra' => array(),
416 );
417
418 $args = wp_parse_args($args, $defaults);
419
420 // These were previously extract()'d.
421 $source = $args['source'];
422 $destination = $args['destination'];
423 $clear_destination = $args['clear_destination'];
424
425 set_time_limit(300);
426
427 if (empty($source) || empty($destination)) {
428 return new WP_Error('bad_request', $this->strings['bad_request']);
429 }
430 // $this->skin->feedback( 'installing_package' );
431
432 /**
433 * Filters the install response before the installation has started.
434 *
435 * Returning a truthy value, or one that could be evaluated as a WP_Error
436 * will effectively short-circuit the installation, returning that value
437 * instead.
438 *
439 * @since 2.8.0
440 *
441 * @param bool|WP_Error $response Response.
442 * @param array $hook_extra Extra arguments passed to hooked filters.
443 */
444 $res = apply_filters('upgrader_pre_install', true, $args['hook_extra']);
445
446 if (is_wp_error($res)) {
447 return $res;
448 }
449
450 // Retain the Original source and destinations
451 $remote_source = $args['source'];
452 $local_destination = $destination;
453
454 $source_files = array_keys($wp_filesystem->dirlist($remote_source));
455 $remote_destination = $wp_filesystem->find_folder($local_destination);
456
457 // Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
458 if (1 == count($source_files) && $wp_filesystem->is_dir(trailingslashit($args['source']) . $source_files[0] . '/')) { // Only one folder? Then we want its contents.
459 $source = trailingslashit($args['source']) . trailingslashit($source_files[0]);
460 } elseif (count($source_files) == 0) {
461 return new WP_Error('incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files']); // There are no files?
462 } else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename.
463 $source = trailingslashit($args['source']);
464 }
465
466 /**
467 * Filters the source file location for the upgrade package.
468 *
469 * @since 2.8.0
470 * @since 4.4.0 The $hook_extra parameter became available.
471 *
472 * @param string $source File source location.
473 * @param string $remote_source Remote file source location.
474 * @param WP_Upgrader $this WP_Upgrader instance.
475 * @param array $hook_extra Extra arguments passed to hooked filters.
476 */
477 $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra']);
478
479 if (is_wp_error($source)) {
480 return $source;
481 }
482
483 // Has the source location changed? If so, we need a new source_files list.
484 if ($source !== $remote_source) {
485 $source_files = array_keys($wp_filesystem->dirlist($source));
486 }
487
488 /*
489 * Protection against deleting files in any important base directories.
490 * Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the
491 * destination directory (WP_PLUGIN_DIR / wp-content/themes) intending
492 * to copy the directory into the directory, whilst they pass the source
493 * as the actual files to copy.
494 */
495 $protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
496
497 if (is_array($wp_theme_directories)) {
498 $protected_directories = array_merge($protected_directories, $wp_theme_directories);
499 }
500
501 if (in_array($destination, $protected_directories)) {
502 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
503 $destination = trailingslashit($destination) . trailingslashit(basename($source));
504 }
505
506 if ($clear_destination) {
507 // We're going to clear the destination if there's something there.
508 // $this->skin->feedback( 'remove_old' );
509
510 $removed = $this->clear_destination($remote_destination);
511
512 /**
513 * Filters whether the upgrader cleared the destination.
514 *
515 * @since 2.8.0
516 *
517 * @param mixed $removed Whether the destination was cleared. true on success, WP_Error on failure
518 * @param string $local_destination The local package destination.
519 * @param string $remote_destination The remote package destination.
520 * @param array $hook_extra Extra arguments passed to hooked filters.
521 */
522 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra']);
523
524 if (is_wp_error($removed)) {
525 return $removed;
526 }
527 } elseif ($args['abort_if_destination_exists'] && $wp_filesystem->exists($remote_destination)) {
528 // If we're not clearing the destination folder and something exists there already, Bail.
529 // But first check to see if there are actually any files in the folder.
530 $_files = $wp_filesystem->dirlist($remote_destination);
531 if (! empty($_files)) {
532 $wp_filesystem->delete($remote_source, true); // Clear out the source files.
533 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination);
534 }
535 }
536
537 // Create destination if needed
538 if (! $wp_filesystem->exists($remote_destination)) {
539 if (! $wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR)) {
540 return new WP_Error('mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination);
541 }
542 }
543 // Copy new version of item into place.
544 $result = copy_dir($source, $remote_destination);
545 if (is_wp_error($result)) {
546 if ($args['clear_working']) {
547 $wp_filesystem->delete($remote_source, true);
548 }
549 return $result;
550 }
551
552 // Clear the Working folder?
553 if ($args['clear_working']) {
554 $wp_filesystem->delete($remote_source, true);
555 }
556
557 $destination_name = basename(str_replace($local_destination, '', $destination));
558 if ('.' == $destination_name) {
559 $destination_name = '';
560 }
561
562 $this->result = compact('source', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination');
563
564 /**
565 * Filters the installation response after the installation has finished.
566 *
567 * @since 2.8.0
568 *
569 * @param bool $response Installation response.
570 * @param array $hook_extra Extra arguments passed to hooked filters.
571 * @param array $result Installation result data.
572 */
573 $res = apply_filters('upgrader_post_install', true, $args['hook_extra'], $this->result);
574
575 if (is_wp_error($res)) {
576 $this->result = $res;
577 return $res;
578 }
579
580 // Bombard the calling function will all the info which we've just used.
581 return $this->result;
582 }
583 }
584