コード例 #1
0
ファイル: server.php プロジェクト: wp-cli/wp-cli
 /**
  * Launch PHP's built-in web server for this specific WordPress installation.
  *
  * Uses `php -S` to launch a web server serving the WordPress webroot.
  * <http://php.net/manual/en/features.commandline.webserver.php>
  *
  * ## OPTIONS
  *
  * [--host=<host>]
  * : The hostname to bind the server to.
  * ---
  * default: localhost
  * ---
  *
  * [--port=<port>]
  * : The port number to bind the server to.
  * ---
  * default: 8080
  * ---
  *
  * [--docroot=<path>]
  * : The path to use as the document root.
  *
  * [--config=<file>]
  * : Configure the server with a specific .ini file.
  *
  * ## EXAMPLES
  *
  *     # Make the instance available on any address (with port 8080)
  *     $ wp server --host=0.0.0.0
  *     PHP 5.6.9 Development Server started at Tue May 24 01:27:11 2016
  *     Listening on http://0.0.0.0:8080
  *     Document root is /
  *     Press Ctrl-C to quit.
  *
  *     # Run on port 80 (for multisite)
  *     $ sudo wp server --host=localhost.localdomain --port=80
  *     PHP 5.6.9 Development Server started at Tue May 24 01:30:06 2016
  *     Listening on http://localhost1.localdomain1:8080
  *     Document root is /
  *     Press Ctrl-C to quit.
  *
  *     # Configure the server with a specific .ini file
  *     $ wp server --config=development.ini
  *     PHP 7.0.9 Development Server started at Mon Aug 22 12:09:04 2016
  *     Listening on http://localhost:8080
  *     Document root is /
  *     Press Ctrl-C to quit.
  *
  * @when before_wp_load
  */
 function __invoke($_, $assoc_args)
 {
     $min_version = '5.4';
     if (version_compare(PHP_VERSION, $min_version, '<')) {
         WP_CLI::error("The `wp server` command requires PHP {$min_version} or newer.");
     }
     $defaults = array('host' => 'localhost', 'port' => 8080, 'docroot' => false, 'config' => get_cfg_var('cfg_file_path'));
     $assoc_args = array_merge($defaults, $assoc_args);
     $docroot = $assoc_args['docroot'];
     if (!$docroot) {
         $config_path = WP_CLI::get_runner()->project_config_path;
         if (!$config_path) {
             $docroot = ABSPATH;
         } else {
             $docroot = dirname($config_path);
         }
     }
     $cmd = \WP_CLI\Utils\esc_cmd('%s -S %s -t %s -c %s %s', PHP_BINARY, $assoc_args['host'] . ':' . $assoc_args['port'], $docroot, $assoc_args['config'], \WP_CLI\Utils\extract_from_phar(WP_CLI_ROOT . '/php/router.php'));
     $descriptors = array(STDIN, STDOUT, STDERR);
     // https://bugs.php.net/bug.php?id=60181
     $options = array();
     if (\WP_CLI\Utils\is_windows()) {
         $options["bypass_shell"] = TRUE;
     }
     exit(proc_close(proc_open($cmd, $descriptors, $pipes, NULL, NULL, $options)));
 }
コード例 #2
0
ファイル: core.php プロジェクト: staylor/wp-cli
 /**
  * Download core WordPress files.
  *
  * ## OPTIONS
  *
  * [--path=<path>]
  * : Specify the path in which to install WordPress.
  *
  * [--locale=<locale>]
  * : Select which language you want to download.
  *
  * [--version=<version>]
  * : Select which version you want to download.
  *
  * [--force]
  * : Overwrites existing files, if present.
  *
  * ## EXAMPLES
  *
  *     wp core download --locale=nl_NL
  *
  * @when before_wp_load
  */
 public function download($args, $assoc_args)
 {
     if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'force') && is_readable(ABSPATH . 'wp-load.php')) {
         WP_CLI::error('WordPress files seem to already be present here.');
     }
     if (!is_dir(ABSPATH)) {
         WP_CLI::log(sprintf('Creating directory %s', ABSPATH));
         $mkdir = \WP_CLI\Utils\is_windows() ? 'mkdir %s' : 'mkdir -p %s';
         WP_CLI::launch(Utils\esc_cmd($mkdir, ABSPATH));
     }
     $locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', 'en_US');
     if (isset($assoc_args['version'])) {
         $version = $assoc_args['version'];
         $download_url = $this->get_download_url($version, $locale, 'tar.gz');
     } else {
         $offer = $this->get_download_offer($locale);
         if (!$offer) {
             WP_CLI::error("The requested locale ({$locale}) was not found.");
         }
         $version = $offer['current'];
         $download_url = str_replace('.zip', '.tar.gz', $offer['download']);
     }
     WP_CLI::log(sprintf('Downloading WordPress %s (%s)...', $version, $locale));
     $cache = WP_CLI::get_cache();
     $cache_key = "core/wordpress-{$version}-{$locale}.tar.gz";
     $cache_file = $cache->has($cache_key);
     $bad_cache = false;
     if ($cache_file) {
         WP_CLI::log("Using cached file '{$cache_file}'...");
         try {
             self::_extract($cache_file, ABSPATH);
         } catch (Exception $e) {
             WP_CLI::warning("Extraction failed, downloading a new copy...");
             $bad_cache = true;
         }
     }
     if (!$cache_file || $bad_cache) {
         // We need to use a temporary file because piping from cURL to tar is flaky
         // on MinGW (and probably in other environments too).
         $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz';
         $headers = array('Accept' => 'application/json');
         $options = array('timeout' => 600, 'filename' => $temp);
         $response = Utils\http_request('GET', $download_url, null, $headers, $options);
         if (404 == $response->status_code) {
             WP_CLI::error("Release not found. Double-check locale or version.");
         } else {
             if (20 != substr($response->status_code, 0, 2)) {
                 WP_CLI::error("Couldn't access download URL (HTTP code {$response->status_code})");
             }
         }
         try {
             self::_extract($temp, ABSPATH);
         } catch (Exception $e) {
             WP_CLI::error("Couldn't extract WordPress archive. " . $e->getMessage());
         }
         $cache->import($cache_key, $temp);
         unlink($temp);
     }
     WP_CLI::success('WordPress downloaded.');
 }
コード例 #3
0
ファイル: plugin.php プロジェクト: kyeates/wp-cli
 private function _delete($plugin)
 {
     $plugin_dir = dirname($plugin->file);
     if ('.' == $plugin_dir) {
         $plugin_dir = $plugin->file;
     }
     $path = path_join(WP_PLUGIN_DIR, $plugin_dir);
     if (\WP_CLI\Utils\is_windows()) {
         // Handles plugins that are not in own folders
         // e.g. Hello Dolly -> plugins/hello.php
         if (is_file($path)) {
             $command = 'del /f /q ';
         } else {
             $command = 'rd /s /q ';
         }
         $path = str_replace("/", "\\", $path);
     } else {
         $command = 'rm -rf ';
     }
     return !WP_CLI::launch($command . $path);
 }
コード例 #4
0
 /**
  * Download core WordPress files.
  *
  * ## OPTIONS
  *
  * [--path=<path>]
  * : Specify the path in which to install WordPress.
  *
  * [--locale=<locale>]
  * : Select which language you want to download.
  *
  * [--version=<version>]
  * : Select which version you want to download.
  *
  * [--force]
  * : Overwrites existing files, if present.
  *
  * ## EXAMPLES
  *
  *     wp core download --locale=nl_NL
  *
  * @when before_wp_load
  */
 public function download($args, $assoc_args)
 {
     if (!isset($assoc_args['force']) && is_readable(ABSPATH . 'wp-load.php')) {
         WP_CLI::error('WordPress files seem to already be present here.');
     }
     if (!is_dir(ABSPATH)) {
         WP_CLI::log(sprintf('Creating directory %s', ABSPATH));
         $mkdir = \WP_CLI\Utils\is_windows() ? 'mkdir %s' : 'mkdir -p %s';
         WP_CLI::launch(Utils\esc_cmd($mkdir, ABSPATH));
     }
     $locale = isset($assoc_args['locale']) ? $assoc_args['locale'] : 'en_US';
     if (isset($assoc_args['version'])) {
         $version = $assoc_args['version'];
         $download_url = $this->get_download_url($version, $locale, 'tar.gz');
     } else {
         $offer = $this->get_download_offer($locale);
         if (!$offer) {
             WP_CLI::error("The requested locale ({$locale}) was not found.");
         }
         $version = $offer['current'];
         $download_url = str_replace('.zip', '.tar.gz', $offer['download']);
     }
     WP_CLI::log(sprintf('Downloading WordPress %s (%s)...', $version, $locale));
     $cache = WP_CLI::get_cache();
     $cache_key = "core/{$locale}-{$version}.tar.gz";
     $cache_file = $cache->has($cache_key);
     if ($cache_file) {
         WP_CLI::log("Using cached file '{$cache_file}'...");
         self::_extract($cache_file, ABSPATH);
     } else {
         // We need to use a temporary file because piping from cURL to tar is flaky
         // on MinGW (and probably in other environments too).
         $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz';
         $headers = array('Accept' => 'application/json');
         $options = array('timeout' => 600, 'filename' => $temp);
         Utils\http_request('GET', $download_url, null, $headers, $options);
         self::_extract($temp, ABSPATH);
         $cache->import($cache_key, $temp);
         unlink($temp);
     }
     WP_CLI::success('WordPress downloaded.');
 }
コード例 #5
0
ファイル: core.php プロジェクト: anver/wp-cli
 /**
  * Download core WordPress files.
  *
  * ## OPTIONS
  *
  * [--path=<path>]
  * : Specify the path in which to install WordPress.
  *
  * [--locale=<locale>]
  * : Select which language you want to download.
  *
  * [--version=<version>]
  * : Select which version you want to download.
  *
  * [--force]
  * : Overwrites existing files, if present.
  *
  * ## EXAMPLES
  *
  *     wp core download --locale=nl_NL
  *
  * @when before_wp_load
  */
 public function download($args, $assoc_args)
 {
     $download_dir = !empty($assoc_args['path']) ? $assoc_args['path'] : ABSPATH;
     $wordpress_present = is_readable($download_dir . 'wp-load.php');
     if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'force') && $wordpress_present) {
         WP_CLI::error('WordPress files seem to already be present here.');
     }
     if (!is_dir($download_dir)) {
         if (!is_writable(dirname($download_dir))) {
             WP_CLI::error(sprintf("Insufficient permission to create directory %s", $download_dir));
         }
         WP_CLI::log(sprintf('Creating directory %s', $download_dir));
         $mkdir = \WP_CLI\Utils\is_windows() ? 'mkdir %s' : 'mkdir -p %s';
         WP_CLI::launch(Utils\esc_cmd($mkdir, $download_dir));
     }
     if (!is_writable($download_dir)) {
         WP_CLI::error(sprintf("%s is not writable by current user", $download_dir));
     }
     $locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', 'en_US');
     if (isset($assoc_args['version'])) {
         $version = $assoc_args['version'];
         $download_url = $this->get_download_url($version, $locale, 'tar.gz');
     } else {
         $offer = $this->get_download_offer($locale);
         if (!$offer) {
             WP_CLI::error("The requested locale ({$locale}) was not found.");
         }
         $version = $offer['current'];
         $download_url = str_replace('.zip', '.tar.gz', $offer['download']);
     }
     $from_version = '';
     if (file_exists($download_dir . 'wp-includes/version.php')) {
         global $wp_version;
         require_once $download_dir . 'wp-includes/version.php';
         $from_version = $wp_version;
     }
     WP_CLI::log(sprintf('Downloading WordPress %s (%s)...', $version, $locale));
     $cache = WP_CLI::get_cache();
     $cache_key = "core/wordpress-{$version}-{$locale}.tar.gz";
     $cache_file = $cache->has($cache_key);
     $bad_cache = false;
     if ($cache_file) {
         WP_CLI::log("Using cached file '{$cache_file}'...");
         try {
             self::_extract($cache_file, $download_dir);
         } catch (Exception $e) {
             WP_CLI::warning("Extraction failed, downloading a new copy...");
             $bad_cache = true;
         }
     }
     if (!$cache_file || $bad_cache) {
         // We need to use a temporary file because piping from cURL to tar is flaky
         // on MinGW (and probably in other environments too).
         $temp = \WP_CLI\Utils\get_temp_dir() . uniqid('wp_') . '.tar.gz';
         $headers = array('Accept' => 'application/json');
         $options = array('timeout' => 600, 'filename' => $temp);
         $response = Utils\http_request('GET', $download_url, null, $headers, $options);
         if (404 == $response->status_code) {
             WP_CLI::error("Release not found. Double-check locale or version.");
         } else {
             if (20 != substr($response->status_code, 0, 2)) {
                 WP_CLI::error("Couldn't access download URL (HTTP code {$response->status_code})");
             }
         }
         $md5_response = Utils\http_request('GET', $download_url . '.md5');
         if (20 != substr($md5_response->status_code, 0, 2)) {
             WP_CLI::error("Couldn't access md5 hash for release (HTTP code {$response->status_code})");
         }
         $md5_file = md5_file($temp);
         if ($md5_file === $md5_response->body) {
             WP_CLI::log('md5 hash verified: ' . $md5_file);
         } else {
             WP_CLI::error("md5 hash for download ({$md5_file}) is different than the release hash ({$md5_response->body})");
         }
         try {
             self::_extract($temp, $download_dir);
         } catch (Exception $e) {
             WP_CLI::error("Couldn't extract WordPress archive. " . $e->getMessage());
         }
         $cache->import($cache_key, $temp);
         unlink($temp);
     }
     if ($wordpress_present) {
         $this->cleanup_extra_files($from_version, $version, $locale);
     }
     WP_CLI::success('WordPress downloaded.');
 }
コード例 #6
0
 private function _delete($plugin)
 {
     $plugin_dir = dirname($plugin->file);
     if ('.' == $plugin_dir) {
         $plugin_dir = $plugin->file;
     }
     $path = path_join(WP_PLUGIN_DIR, $plugin_dir);
     if (\WP_CLI\Utils\is_windows()) {
         $command = 'rd /s /q ';
         $path = str_replace("/", "\\", $path);
     } else {
         $command = 'rm -rf ';
     }
     return !WP_CLI::launch($command . $path);
 }