Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp-matchesmapregex.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WP_MatchesMapRegex helper class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 4.7.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Helper class to remove the need to use eval to replace $matches[] in query strings.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.9.0
[11] Fix | Delete
*/
[12] Fix | Delete
class WP_MatchesMapRegex {
[13] Fix | Delete
/**
[14] Fix | Delete
* store for matches
[15] Fix | Delete
*
[16] Fix | Delete
* @var array
[17] Fix | Delete
*/
[18] Fix | Delete
private $_matches;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* store for mapping result
[22] Fix | Delete
*
[23] Fix | Delete
* @var string
[24] Fix | Delete
*/
[25] Fix | Delete
public $output;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* subject to perform mapping on (query string containing $matches[] references
[29] Fix | Delete
*
[30] Fix | Delete
* @var string
[31] Fix | Delete
*/
[32] Fix | Delete
private $_subject;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* regexp pattern to match $matches[] references
[36] Fix | Delete
*
[37] Fix | Delete
* @var string
[38] Fix | Delete
*/
[39] Fix | Delete
public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // Magic number.
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* constructor
[43] Fix | Delete
*
[44] Fix | Delete
* @param string $subject subject if regex
[45] Fix | Delete
* @param array $matches data to use in map
[46] Fix | Delete
*/
[47] Fix | Delete
public function __construct( $subject, $matches ) {
[48] Fix | Delete
$this->_subject = $subject;
[49] Fix | Delete
$this->_matches = $matches;
[50] Fix | Delete
$this->output = $this->_map();
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Substitute substring matches in subject.
[55] Fix | Delete
*
[56] Fix | Delete
* static helper function to ease use
[57] Fix | Delete
*
[58] Fix | Delete
* @param string $subject subject
[59] Fix | Delete
* @param array $matches data used for substitution
[60] Fix | Delete
* @return string
[61] Fix | Delete
*/
[62] Fix | Delete
public static function apply( $subject, $matches ) {
[63] Fix | Delete
$oSelf = new WP_MatchesMapRegex( $subject, $matches );
[64] Fix | Delete
return $oSelf->output;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* do the actual mapping
[69] Fix | Delete
*
[70] Fix | Delete
* @return string
[71] Fix | Delete
*/
[72] Fix | Delete
private function _map() {
[73] Fix | Delete
$callback = array( $this, 'callback' );
[74] Fix | Delete
return preg_replace_callback( $this->_pattern, $callback, $this->_subject );
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* preg_replace_callback hook
[79] Fix | Delete
*
[80] Fix | Delete
* @param array $matches preg_replace regexp matches
[81] Fix | Delete
* @return string
[82] Fix | Delete
*/
[83] Fix | Delete
public function callback( $matches ) {
[84] Fix | Delete
$index = (int) substr( $matches[0], 9, -1 );
[85] Fix | Delete
return ( isset( $this->_matches[ $index ] ) ? urlencode( $this->_matches[ $index ] ) : '' );
[86] Fix | Delete
}
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function