| 1 |
<?php |
| 2 |
|
| 3 |
class Page_Match extends Red_Match { |
| 4 |
use FromUrl_Match; |
| 5 |
|
| 6 |
public $page; |
| 7 |
|
| 8 |
public function name() { |
| 9 |
return __( 'URL and WordPress page type', 'redirection' ); |
| 10 |
} |
| 11 |
|
| 12 |
public function save( array $details, $no_target_url = false ) { |
| 13 |
$data = array( 'page' => isset( $details['page'] ) ? $this->sanitize_page( $details['page'] ) : '404' ); |
| 14 |
|
| 15 |
return $this->save_data( $details, $no_target_url, $data ); |
| 16 |
} |
| 17 |
|
| 18 |
private function sanitize_page( $page ) { |
| 19 |
return '404'; |
| 20 |
} |
| 21 |
|
| 22 |
public function get_target( $requested_url, $source_url, Red_Source_Flags $flags ) { |
| 23 |
if ( ! is_404() ) { |
| 24 |
return false; |
| 25 |
} |
| 26 |
|
| 27 |
$target = $this->get_matched_target( true ); |
| 28 |
|
| 29 |
if ( $flags->is_regex() && $target ) { |
| 30 |
return $this->get_target_regex_url( $source_url, $target, $requested_url, $flags ); |
| 31 |
} |
| 32 |
|
| 33 |
return $target; |
| 34 |
} |
| 35 |
|
| 36 |
public function get_data() { |
| 37 |
return array_merge( array( |
| 38 |
'page' => $this->page, |
| 39 |
), $this->get_from_data() ); |
| 40 |
} |
| 41 |
|
| 42 |
public function load( $values ) { |
| 43 |
$values = $this->load_data( $values ); |
| 44 |
$this->page = $values['page']; |
| 45 |
} |
| 46 |
} |
| 47 |
|