|
@@ 14-28 (lines=15) @@
|
| 11 |
|
* @param string $path The path we want to process. |
| 12 |
|
* @return string The tokenized path. |
| 13 |
|
*/ |
| 14 |
|
public function tokenize_path_constants( $path ) { |
| 15 |
|
$path = wp_normalize_path( $path ); |
| 16 |
|
|
| 17 |
|
$constants = $this->get_normalized_constants(); |
| 18 |
|
foreach ( $constants as $constant => $constant_path ) { |
| 19 |
|
$len = strlen( $constant_path ); |
| 20 |
|
if ( substr( $path, 0, $len ) !== $constant_path ) { |
| 21 |
|
continue; |
| 22 |
|
} |
| 23 |
|
|
| 24 |
|
return substr_replace( $path, '{{' . $constant . '}}', 0, $len ); |
| 25 |
|
} |
| 26 |
|
|
| 27 |
|
return $path; |
| 28 |
|
} |
| 29 |
|
|
| 30 |
|
/** |
| 31 |
|
* Given a path this will replace any of the path constant tokens with the expanded path. |
|
@@ 36-52 (lines=17) @@
|
| 33 |
|
* @param string $tokenized_path The path we want to process. |
| 34 |
|
* @return string The expanded path. |
| 35 |
|
*/ |
| 36 |
|
public function untokenize_path_constants( $tokenized_path ) { |
| 37 |
|
$tokenized_path = wp_normalize_path( $tokenized_path ); |
| 38 |
|
|
| 39 |
|
$constants = $this->get_normalized_constants(); |
| 40 |
|
foreach ( $constants as $constant => $constant_path ) { |
| 41 |
|
$constant = '{{' . $constant . '}}'; |
| 42 |
|
|
| 43 |
|
$len = strlen( $constant ); |
| 44 |
|
if ( substr( $tokenized_path, 0, $len ) !== $constant ) { |
| 45 |
|
continue; |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) ); |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
return $tokenized_path; |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
/** |
| 55 |
|
* Given a file and an array of places it might be, this will find the absolute path and return it. |