Файловый менеджер - Редактировать - /home/tuudkjt/globeasy/wp-includes/ID3/blueprint.zip
Назад
PK N1]Z8�g blueprint.phpnu ��� <?php /** * Plugin Name: Blueprint * Plugin URI: https://woocommerce.com/ * Description: An empty blueprint definition file to setup wp-env test env. * Version: 0.0.1 * Author: Automattic * Author URI: https://woocommerce.com * Requires at least: 6.4 * Requires PHP: 7.4 */ PK N1] ��Y Y src/ImportSchema.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint; use Automattic\WooCommerce\Blueprint\Schemas\JsonSchema; use Opis\JsonSchema\Errors\ErrorFormatter; use Opis\JsonSchema\Validator; /** * Class ImportSchema * * Handles the import schema functionality for WooCommerce. * * @package Automattic\WooCommerce\Blueprint */ class ImportSchema { use UseWPFunctions; /** * JsonSchema object. * * @var JsonSchema The schema instance. */ private JsonSchema $schema; /** * Validator object. * * @var Validator The JSON schema validator instance. */ private Validator $validator; /** * ImportSchema constructor. * * @param JsonSchema $schema The schema instance. * @param Validator|null $validator The validator instance, optional. */ public function __construct( JsonSchema $schema, ?Validator $validator = null ) { $this->schema = $schema; if ( null === $validator ) { $validator = new Validator(); } $this->validator = $validator; } /** * Get the schema. * * @return JsonSchema The schema. */ public function get_schema() { return $this->schema; } /** * Create an ImportSchema instance from a file. * * @param string $file The file path. * @return ImportSchema The created ImportSchema instance. * * @throws \RuntimeException If the JSON file cannot be read. * @throws \InvalidArgumentException If the JSON is invalid or missing 'steps' field. */ public static function create_from_file( $file ) { return self::create_from_json( $file ); } /** * Create an ImportSchema instance from a JSON file. * * @param string $json_path The JSON file path. * @return ImportSchema The created ImportSchema instance. * * @throws \RuntimeException If the JSON file cannot be read. * @throws \InvalidArgumentException If the JSON is invalid or missing 'steps' field. */ public static function create_from_json( $json_path ) { return new self( new JsonSchema( $json_path ) ); } /** * Import the schema steps. * * @return StepProcessorResult[] */ public function import() { $results = array(); $result = StepProcessorResult::success( 'ImportSchema' ); $results[] = $result; foreach ( $this->schema->get_steps() as $step_schema ) { $step_importer = new ImportStep( $step_schema, $this->validator ); $results[] = $step_importer->import(); } return $results; } } PK N1] �v0 0 src/Cli/ImportCli.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint\Cli; use Automattic\WooCommerce\Blueprint\ImportSchema; use Automattic\WooCommerce\Blueprint\ResultFormatters\CliResultFormatter; /** * Class ImportCli */ class ImportCli { /** * Schema path * * @var string $schema_path The path to the schema file. */ private $schema_path; /** * ImportCli constructor. * * @param string $schema_path The path to the schema file. */ public function __construct( $schema_path ) { $this->schema_path = $schema_path; } /** * Run the import process. * * @param array $optional_args Optional arguments. * * @return void */ public function run( $optional_args ) { try { $blueprint = ImportSchema::create_from_file( $this->schema_path ); } catch ( \Exception $e ) { \WP_CLI::error( $e->getMessage() ); return; } $results = $blueprint->import(); $result_formatter = new CliResultFormatter( $results ); $is_success = $result_formatter->is_success(); if ( isset( $optional_args['show-messages'] ) ) { $result_formatter->format( $optional_args['show-messages'] ); } if ( $is_success ) { \WP_CLI::success( "$this->schema_path imported successfully" ); } else { \WP_CLI::error( "Failed to import $this->schema_path. Run with --show-messages=all to debug" ); } } } PK N1]�C��i i src/Cli/ExportCli.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint\Cli; use Automattic\WooCommerce\Blueprint\ExportSchema; use Automattic\WooCommerce\Blueprint\UseWPFunctions; /** * Class ExportCli * * This class handles the CLI commands for exporting schemas. * * @package Automattic\WooCommerce\Blueprint\Cli */ class ExportCli { use UseWPFunctions; /** * The path where the exported schema will be saved. * * @var string The path where the exported schema will be saved. */ private string $save_to; /** * ExportCli constructor. * * @param string $save_to The path where the exported schema will be saved. */ public function __construct( $save_to ) { $this->save_to = $save_to; } /** * Run the export process. * * @param array $args The arguments for the export process. */ public function run( $args = array() ) { if ( ! isset( $args['steps'] ) ) { $args['steps'] = array(); } $exporter = new ExportSchema(); $result = $exporter->export( $args['steps'] ); if ( is_wp_error( $result ) ) { \WP_CLI::error( $result->get_error_message() ); return; } $is_saved = $this->wp_filesystem_put_contents( $this->save_to, wp_json_encode( $result, JSON_PRETTY_PRINT ) ); if ( false === $is_saved ) { \WP_CLI::error( "Failed to save to {$this->save_to}" ); } else { \WP_CLI::success( "Exported JSON to {$this->save_to}" ); } } } PK N1]�1سA A src/StepProcessorResult.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint; use InvalidArgumentException; /** * A class returned by StepProcessor classes containing result of the process and messages. */ class StepProcessorResult { const MESSAGE_TYPES = array( 'error', 'info', 'debug', 'warn' ); /** * Messages * * @var array $messages */ private array $messages = array(); /** * Indicate whether the process was success or not * * @var bool $success */ private bool $success; /** * Step name * * @var string $step_name */ private string $step_name; /** * Construct. * * @param bool $success Indicate whether the process was success or not. * @param string $step_name The name of the step. */ public function __construct( bool $success, string $step_name ) { $this->success = $success; $this->step_name = $step_name; } /** * Get messages. * * @param string $step_name The name of the step. * * @return void */ public function set_step_name( $step_name ) { $this->step_name = $step_name; } /** * Create a new instance with $success = true. * * @param string $stp_name The name of the step. * * @return StepProcessorResult */ public static function success( string $stp_name ): self { return ( new self( true, $stp_name ) ); } /** * Add a new message. * * @param string $message message. * @param string $type one of error, info. * * @throws InvalidArgumentException When incorrect type is given. * @return void */ public function add_message( string $message, string $type = 'error' ) { if ( ! in_array( $type, self::MESSAGE_TYPES, true ) ) { // phpcs:ignore throw new InvalidArgumentException( "{$type} is not allowed. Type must be one of " . implode( ',', self::MESSAGE_TYPES ) ); } $this->messages[] = compact( 'message', 'type' ); } /** * Merge messages from another StepProcessorResult instance. * * @param StepProcessorResult $other The other StepProcessorResult instance. * * @return void */ public function merge_messages( StepProcessorResult $other ) { $this->messages = array_merge( $this->messages, $other->get_messages() ); } /** * Add a new error message. * * @param string $message message. * * @return void */ public function add_error( string $message ) { $this->add_message( $message ); } /** * Add a new debug message. * * @param string $message message. * * @return void */ public function add_debug( string $message ) { $this->add_message( $message, 'debug' ); } /** * Add a new info message. * * @param string $message message. * * @return void */ public function add_info( string $message ) { $this->add_message( $message, 'info' ); } /** * Add a new warn message. * * @param string $message message. * * @return void */ public function add_warn( string $message ) { $this->add_message( $message, 'warn' ); } /** * Filter messages. * * @param string $type one of all, error, and info. * * @return array */ public function get_messages( string $type = 'all' ): array { if ( 'all' === $type ) { return $this->messages; } return array_filter( $this->messages, function ( $message ) use ( $type ) { return $type === $message['type']; } ); } /** * Check to see if the result was success. * * @return bool */ public function is_success(): bool { return true === $this->success && 0 === count( $this->get_messages( 'error' ) ); } /** * Get the name of the step. * * @return string The name of the step. */ public function get_step_name() { return $this->step_name; } } PK N1]��2} } + src/ResultFormatters/CliResultFormatter.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint\ResultFormatters; use Automattic\WooCommerce\Blueprint\StepProcessorResult; use function WP_CLI\Utils\format_items; /** * Class CliResultFormatter */ class CliResultFormatter { /** * The results to format. * * @var StepProcessorResult[] */ private array $results; /** * CliResultFormatter constructor. * * @param array $results The results to format. */ public function __construct( array $results ) { $this->results = $results; } /** * Format the results. * * @param string $message_type The message type to format. * * @return void * * @throws \Exception If WP CLI Utils is not found. */ public function format( $message_type = 'debug' ) { $header = array( 'Step Processor', 'Type', 'Message' ); $items = array(); foreach ( $this->results as $result ) { $step_name = $result->get_step_name(); foreach ( $result->get_messages( $message_type ) as $message ) { $items[] = array( 'Step Processor' => $step_name, 'Type' => $message['type'], 'Message' => $message['message'], ); } } $format_items_exist = function_exists( '\WP_CLI\Utils\format_items' ); if ( ! $format_items_exist ) { throw new \Exception( 'WP CLI Utils not found' ); } format_items( 'table', $items, $header ); } /** * Check if all results are successful. * * @return bool True if all results are successful, false otherwise. */ public function is_success() { foreach ( $this->results as $result ) { $is_success = $result->is_success(); if ( ! $is_success ) { return false; } } return true; } } PK N1]S0M�� � , src/ResultFormatters/JsonResultFormatter.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint\ResultFormatters; use Automattic\WooCommerce\Blueprint\StepProcessorResult; /** * Class JsonResultFormatter */ class JsonResultFormatter { /** * The results to format. * * @var StepProcessorResult[] */ private array $results; /** * JsonResultFormatter constructor. * * @param array $results The results to format. */ public function __construct( array $results ) { $this->results = $results; } /** * Format the results. * * @param string $message_type The message type to format. * * @return array */ public function format( $message_type = 'all' ) { $data = array( 'is_success' => $this->is_success(), 'messages' => array(), ); foreach ( $this->results as $result ) { $step_name = $result->get_step_name(); foreach ( $result->get_messages( $message_type ) as $message ) { if ( ! isset( $data['messages'][ $message['type'] ] ) ) { $data['messages'][ $message['type'] ] = array(); } $data['messages'][ $message['type'] ][] = array( 'step' => $step_name, 'type' => $message['type'], 'message' => $message['message'], ); } } return $data; } /** * Check if all results are successful. * * @return bool True if all results are successful, false otherwise. */ public function is_success() { foreach ( $this->results as $result ) { $is_success = $result->is_success(); if ( ! $is_success ) { return false; } } return true; } } PK N1]���- - src/Exporters/StepExporter.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint\Exporters; use Automattic\WooCommerce\Blueprint\Steps\Step; /** * Interface StepExporter * * A Step Exporter is responsible collecting data needed for a Step object and exporting it. * Refer to the Step class for the data needed as each step may require different data. */ interface StepExporter { /** * Collect data needed for a Step object and export it. * * @return Step */ public function export(); /** * Returns the name of the step class it exports. * * @return string */ public function get_step_name(); /** * Check if the current user has the required capabilities for this step. * * @return bool True if the user has the required capabilities. False otherwise. */ public function check_step_capabilities(): bool; } PK N1]����� � ) src/Exporters/ExportInstallThemeSteps.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint\Exporters; use Automattic\WooCommerce\Blueprint\Steps\InstallTheme; use Automattic\WooCommerce\Blueprint\UseWPFunctions; /** * Class ExportInstallThemeSteps * * Exporter for the InstallTheme step. * * @package Automattic\WooCommerce\Blueprint\Exporters */ class ExportInstallThemeSteps implements StepExporter { use UseWPFunctions; /** * Filter callback. * * @var callable */ private $filter_callback; /** * Register a filter callback to filter the plugins to export. * * @param callable $callback Filter callback. * * @return void */ public function filter( callable $callback ) { $this->filter_callback = $callback; } /** * Export the steps. * * @return array */ public function export() { $steps = array(); $themes = $this->wp_get_themes(); if ( is_callable( $this->filter_callback ) ) { $themes = call_user_func( $this->filter_callback, $themes ); } $active_theme = $this->wp_get_theme(); foreach ( $themes as $slug => $theme ) { // Check if the theme is active. $is_active = $theme->get( 'Name' ) === $active_theme->get( 'Name' ); $info = $this->wp_themes_api( 'theme_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false, ), ) ); if ( isset( $info->download_link ) ) { $steps[] = new InstallTheme( $slug, 'wordpress.org/themes', array( 'activate' => $is_active, ) ); } } return $steps; } /** * Get the step name. * * @return string */ public function get_step_name() { return InstallTheme::get_step_name(); } /** * Check if the current user has the required capabilities for this step. * * @return bool True if the user has the required capabilities. False otherwise. */ public function check_step_capabilities(): bool { return current_user_can( 'switch_themes' ); } } PK N1]"�3�= = src/Exporters/HasAlias.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint\Exporters; /** * Allows a step to have an alias. * * An alias is useful for selective export. * * Let's say you have three exporters and all of them use `setSiteOptions` step. * * Step A: Exports options from WooCommerce -> Settings * Step B: Exports options for the core profiler selection. * Step C: Exports options for the task list. * * You also have a UI where a client can select which steps to export. In this case, we have three checkboxes. * * [ ] WooCommerce Settings * [ ] WooCommerce Core Profiler * [ ] WooCommerce Task List * * Without alias, the client would see three `setSiteOptions` steps and it's not possible * to distinguish between them from the ExportSchema class. * * With alias, you can give each step a unique alias while keeping the step name the same. * * @todo Link to an example class that uses this interface. * * Interface HasAlias */ interface HasAlias { /** * Get the alias for the step. * * @return string The alias for the step. */ public function get_alias(); } PK N1]Ky�N N * src/Exporters/ExportInstallPluginSteps.phpnu ��� <?php namespace Automattic\WooCommerce\Blueprint\Exporters; use Automattic\WooCommerce\Blueprint\Steps\InstallPlugin; use Automattic\WooCommerce\Blueprint\UseWPFunctions; /** * Class ExportInstallPluginSteps * * @package Automattic\WooCommerce\Blueprint\Exporters */ class ExportInstallPluginSteps implements StepExporter { use UseWPFunctions; /** * Filter callback. * * @var callable */ private $filter_callback; /** * Whether to include private plugins in the export. * * @var bool Whether to include private plugins in the export. */ private bool $include_private_plugins = false; /** * Set whether to include private plugins in the export. * * @param bool $boolean Whether to include private plugins. */ public function include_private_plugins( bool $boolean ) { $this->include_private_plugins = $boolean; } /** * Register a filter callback to filter the plugins to export. * * @param callable $callback Filter callback. * * @return void */ public function filter( callable $callback ) { $this->filter_callback = $callback; } /** * Export the steps required to install plugins. * * @return array The array of InstallPlugin steps. */ public function export() { $plugins = $this->sort_plugins_by_dep( $this->wp_get_plugins() ); if ( is_callable( $this->filter_callback ) ) { $plugins = call_user_func( $this->filter_callback, $plugins ); } // @todo temporary fix for JN site -- it includes WooCommerce as a custom plugin // since JN sites are using a different slug. $exclude = array( 'WooCommerce Beta Tester' ); $steps = array(); foreach ( $plugins as $path => $plugin ) { if ( in_array( $plugin['Name'], $exclude, true ) ) { continue; } $slug = dirname( $path ); // single-file plugin. if ( '.' === $slug ) { $slug = pathinfo( $path )['filename']; } $info = $this->wp_plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false, ), ) ); $has_download_link = isset( $info->download_link ); if ( false === $this->include_private_plugins && ! $has_download_link ) { continue; } $resource = $has_download_link ? 'wordpress.org/plugins' : 'self/plugins'; $steps[] = new InstallPlugin( $slug, $resource, array( 'activate' => true, ) ); } return $steps; } /** * Sort plugins by dependencies -- put the dependencies at the top. * * @param array $plugins List of plugins to sort (from wp_get_plugins function). * * @return array */ public function sort_plugins_by_dep( array $plugins ) { $sorted = array(); $visited = array(); // Create a mapping of lowercase titles to plugin keys for quick lookups. $title_map = array_reduce( array_keys( $plugins ), function ( $carry, $key ) use ( $plugins ) { $title = strtolower( $plugins[ $key ]['Title'] ?? '' ); if ( $title ) { $carry[ $title ] = $key; } return $carry; }, array() ); // Recursive function for topological sort. $visit = function ( $plugin_key ) use ( &$visit, &$sorted, &$visited, $plugins, $title_map ) { if ( isset( $visited[ $plugin_key ] ) ) { return; } $visited[ $plugin_key ] = true; $requires = $plugins[ $plugin_key ]['RequiresPlugins'] ?? array(); foreach ( (array) $requires as $dependency ) { $dependency_key = $title_map[ strtolower( $dependency ) ] ?? null; if ( $dependency_key ) { $visit( $dependency_key ); } } $sorted[ $plugin_key ] = $plugins[ $plugin_key ]; }; // Perform sort for each plugin. foreach ( array_keys( $plugins ) as $plugin_key ) { $visit( $plugin_key ); } return $sorted; } /** * Get the name of the step. * * @return string The step name. */ public function get_step_name() { return InstallPlugin::get_step_name(); } /** * Check if the current user has the required capabilities for this step. * * @return bool True if the user has the required capabilities. False otherwise. */ public function check_step_capabilities(): bool { return current_user_can( 'activate_plugins' ); } } PK N1]����* * &