| @@ -3,14 +3,16 @@ | ||
| 3 | 3 | class Red_Apache_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' ) ).'.htaccess'; | |
| 8 | + | |
| 7 | 9 | header( 'Content-Type: application/octet-stream' ); |
| 8 | - header( 'Content-Disposition: attachment; filename="' . $this->export_filename( 'htaccess' ) . '"' ); | |
| 10 | + header( 'Content-Disposition: attachment; filename="'.$filename.'"' ); | |
| 9 | 11 | } |
| 10 | 12 | |
| 11 | 13 | public function get_data( array $items, array $groups ) { |
| 12 | - include_once dirname( dirname( __FILE__ ) ) . '/models/htaccess.php'; | |
| 14 | + include_once dirname( dirname( __FILE__ ) ).'/models/htaccess.php'; | |
| 13 | 15 | |
| 14 | 16 | $htaccess = new Red_Htaccess(); |
| 15 | 17 | |
| 16 | 18 | foreach ( $items as $item ) { |
| @@ -16,9 +18,9 @@ | ||
| 16 | 18 | foreach ( $items as $item ) { |
| 17 | 19 | $htaccess->add( $item ); |
| 18 | 20 | } |
| 19 | 21 | |
| 20 | - return $htaccess->get() . PHP_EOL; | |
| 22 | + return $htaccess->get().PHP_EOL; | |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | 25 | public function load( $group, $filename, $data ) { |
| 24 | 26 | // Remove any comments |
| @@ -27,9 +29,9 @@ | ||
| 27 | 29 | // Split it into lines |
| 28 | 30 | $lines = array_filter( explode( "\r", $data ) ); |
| 29 | 31 | $count = 0; |
| 30 | 32 | |
| 31 | - foreach ( (array) $lines as $line ) { | |
| 33 | + foreach ( (array)$lines as $line ) { | |
| 32 | 34 | $item = $this->get_as_item( $line ); |
| 33 | 35 | |
| 34 | 36 | if ( $item ) { |
| 35 | 37 | $item['group_id'] = $group; |
| @@ -34,9 +36,9 @@ | ||
| 34 | 36 | if ( $item ) { |
| 35 | 37 | $item['group_id'] = $group; |
| 36 | 38 | $redirect = Red_Item::create( $item ); |
| 37 | 39 | |
| 38 | - if ( ! is_wp_error( $redirect ) ) { | |
| 40 | + if ( !is_wp_error( $redirect ) ) { | |
| 39 | 41 | $count++; |
| 40 | 42 | } |
| 41 | 43 | } |
| 42 | 44 | } |
| @@ -107,14 +109,9 @@ | ||
| 107 | 109 | } |
| 108 | 110 | |
| 109 | 111 | private function decode_url( $url ) { |
| 110 | 112 | $url = rawurldecode( $url ); |
| 111 | - | |
| 112 | - // Replace quoted slashes | |
| 113 | - $url = preg_replace( '@\\\/@', '/', $url ); | |
| 114 | - | |
| 115 | - // Ensure escaped '.' is still escaped | |
| 116 | - $url = preg_replace( '@\\\\.@', '\\\\.', $url ); | |
| 113 | + $url = str_replace( '\\.', '.', $url ); | |
| 117 | 114 | return $url; |
| 118 | 115 | } |
| 119 | 116 | |
| 120 | 117 | private function is_str_regex( $url ) { |
| @@ -146,26 +143,24 @@ | ||
| 146 | 143 | |
| 147 | 144 | return false; |
| 148 | 145 | } |
| 149 | 146 | |
| 150 | - private function regex_url( $url ) { | |
| 151 | - $url = $this->decode_url( $url ); | |
| 152 | - | |
| 147 | + private function regex_url ($url) { | |
| 153 | 148 | if ( $this->is_str_regex( $url ) ) { |
| 154 | 149 | $tmp = ltrim( $url, '^' ); |
| 155 | 150 | $tmp = rtrim( $tmp, '$' ); |
| 156 | 151 | |
| 157 | - if ( $this->is_str_regex( $tmp ) ) { | |
| 158 | - return '^/' . ltrim( $tmp, '/' ); | |
| 152 | + if ( $this->is_str_regex( $tmp ) === false ) { | |
| 153 | + return '/'.$this->decode_url( $tmp ); | |
| 159 | 154 | } |
| 160 | 155 | |
| 161 | - return '/' . ltrim( $tmp, '/' ); | |
| 156 | + return '/'.$this->decode_url( $url ); | |
| 162 | 157 | } |
| 163 | 158 | |
| 164 | 159 | return $this->decode_url( $url ); |
| 165 | 160 | } |
| 166 | 161 | |
| 167 | - private function get_code( $code ) { | |
| 162 | + private function get_code ($code) { | |
| 168 | 163 | if ( strpos( $code, '301' ) !== false || stripos( $code, 'permanent' ) !== false ) { |
| 169 | 164 | return 301; |
| 170 | 165 | } elseif ( strpos( $code, '302' ) !== false ) { |
| 171 | 166 | return 302; |