PluginProbe
Redirection / 2.9
Redirection v2.9
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
← All changes | fileio/nginx.php +28 -40 4.02.9 View file →
@@ -3,42 +3,38 @@
3 3 class Red_Nginx_File extends Red_FileIO {
4 4 public function force_download() {
5 5 parent::force_download();
6 6
7 + $filename = 'redirection-'.date_i18n( get_option( 'date_format' ) ).'.nginx';
8 +
7 9 header( 'Content-Type: application/octet-stream' );
8 - header( 'Content-Disposition: attachment; filename="' . $this->export_filename( 'nginx' ) . '"' );
10 + header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
9 11 }
10 12
11 13 public function get_data( array $items, array $groups ) {
12 14 $lines = array();
13 - $version = red_get_plugin_data( dirname( dirname( __FILE__ ) ) . '/redirection.php' );
15 + $version = get_plugin_data( dirname( dirname( __FILE__ ) ).'/redirection.php' );
14 16
15 17 $lines[] = '# Created by Redirection';
16 - $lines[] = '# ' . date( 'r' );
17 - $lines[] = '# Redirection ' . trim( $version['Version'] ) . ' - https://redirection.me';
18 + $lines[] = '# '.date( 'r' );
19 + $lines[] = '# Redirection '.trim( $version['Version'] ).' - http://urbangiraffe.com/plugins/redirection/';
18 20 $lines[] = '';
19 21 $lines[] = 'server {';
20 22
21 - $parts = array();
22 23 foreach ( $items as $item ) {
23 - if ( $item->is_enabled() ) {
24 - $parts[] = $this->get_nginx_item( $item );
25 - }
24 + $lines[] = $this->get_nginx_item( $item );
26 25 }
27 26
28 - $lines = array_merge( $lines, array_filter( $parts ) );
29 -
30 27 $lines[] = '}';
31 28 $lines[] = '';
32 29 $lines[] = '# End of Redirection';
33 30
34 - return implode( PHP_EOL, $lines ) . PHP_EOL;
31 + return implode( PHP_EOL, $lines ).PHP_EOL;
35 32 }
36 33
37 34 private function get_redirect_code( Red_Item $item ) {
38 - if ( $item->get_action_code() === 301 ) {
35 + if ( $item->get_action_code() === 301 )
39 36 return 'permanent';
40 - }
41 37 return 'redirect';
42 38 }
43 39
44 40 function load( $group, $data, $filename = '' ) {
@@ -45,31 +41,29 @@
45 41 return 0;
46 42 }
47 43
48 44 private function get_nginx_item( Red_Item $item ) {
49 - $target = 'add_' . $item->get_match_type();
45 + $target = 'add_'.$item->get_match_type();
50 46
51 - if ( method_exists( $this, $target ) ) {
52 - return ' ' . $this->$target( $item, $item->get_match_data() );
53 - }
54 -
47 + if ( method_exists( $this, $target ) )
48 + return ' '.$this->$target( $item, $item->match );
55 49 return false;
56 50 }
57 51
58 - private function add_url( Red_Item $item, array $match_data ) {
59 - return $this->get_redirect( $item->get_url(), $item->get_action_data(), $this->get_redirect_code( $item ), $match_data['source'] );
52 + private function add_url( Red_Item $item ) {
53 + return $this->add_redirect( $item->get_url(), $item->get_action_data(), $this->get_redirect_code( $item ) );
60 54 }
61 55
62 - private function add_agent( Red_Item $item, array $match_data ) {
56 + private function add_agent( Red_Item $item ) {
63 57 if ( $item->match->url_from ) {
64 - $lines[] = 'if ( $http_user_agent ~* ^' . $item->match->user_agent . '$ ) {';
65 - $lines[] = ' ' . $this->get_redirect( $item->get_url(), $item->match->url_from, $this->get_redirect_code( $item ), $match_data['source'] );
58 + $lines[] = 'if ( $http_user_agent ~* ^'.$item->match->user_agent.'$ ) {';
59 + $lines[] = ' '.$this->add_redirect( $item->get_url(), $item->match->url_from, $this->get_redirect_code( $item ) );
66 60 $lines[] = ' }';
67 61 }
68 62
69 63 if ( $item->match->url_notfrom ) {
70 - $lines[] = 'if ( $http_user_agent !~* ^' . $item->match->user_agent . '$ ) {';
71 - $lines[] = ' ' . $this->get_redirect( $item->get_url(), $item->match->url_notfrom, $this->get_redirect_code( $item ), $match_data['source'] );
64 + $lines[] = 'if ( $http_user_agent !~* ^'.$item->match->user_agent.'$ ) {';
65 + $lines[] = ' '.$this->add_redirect( $item->get_url(), $item->match->url_notfrom, $this->get_redirect_code( $item ) );
72 66 $lines[] = ' }';
73 67 }
74 68
75 69 return implode( "\n", $lines );
@@ -74,18 +68,18 @@
74 68
75 69 return implode( "\n", $lines );
76 70 }
77 71
78 - private function add_referrer( Red_Item $item, array $match_data ) {
72 + private function add_referrer( Red_Item $item ) {
79 73 if ( $item->match->url_from ) {
80 - $lines[] = 'if ( $http_referer ~* ^' . $item->match->referrer . '$ ) {';
81 - $lines[] = ' ' . $this->get_redirect( $item->get_url(), $item->match->url_from, $this->get_redirect_code( $item ), $match_data['source'] );
74 + $lines[] = 'if ( $http_referer ~* ^'.$item->match->referrer.'$ ) {';
75 + $lines[] = ' '.$this->add_redirect( $item->get_url(), $item->match->url_from, $this->get_redirect_code( $item ) );
82 76 $lines[] = ' }';
83 77 }
84 78
85 79 if ( $item->match->url_notfrom ) {
86 - $lines[] = 'if ( $http_referer !~* ^' . $item->match->referrer . '$ ) {';
87 - $lines[] = ' ' . $this->get_redirect( $item->get_url(), $item->match->url_notfrom, $this->get_redirect_code( $item ), $match_data['source'] );
80 + $lines[] = 'if ( $http_referer !~* ^'.$item->match->referrer.'$ ) {';
81 + $lines[] = ' '.$this->add_redirect( $item->get_url(), $item->match->url_notfrom, $this->get_redirect_code( $item ) );
88 82 $lines[] = ' }';
89 83 }
90 84
91 85 return implode( "\n", $lines );
@@ -90,19 +84,13 @@
90 84
91 85 return implode( "\n", $lines );
92 86 }
93 87
94 - private function get_redirect( $line, $target, $code, $source ) {
95 - if ( isset( $source['flag_case'] ) && $source['flag_case'] ) {
96 - $line = '(?i)^' . $line;
97 - } else {
98 - $line = '^' . $line;
99 - }
100 -
101 - $line = preg_replace( "/[\r\n\t].*?$/s", '', $line );
102 - $line = preg_replace( '/[^\PC\s]/u', '', $line );
88 + private function add_redirect( $source, $target, $code ) {
89 + $source = preg_replace( "/[\r\n\t].*?$/s", '', $source );
90 + $source = preg_replace( '/[^\PC\s]/u', '', $source );
103 91 $target = preg_replace( "/[\r\n\t].*?$/s", '', $target );
104 92 $target = preg_replace( '/[^\PC\s]/u', '', $target );
105 93
106 - return 'rewrite ' . $line . '$ ' . $target . ' ' . $code . ';';
94 + return 'rewrite ^'.$source.'$ '.$target.' '.$code.';';
107 95 }
108 96 }