| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | class Apache_Module extends Red_Module { |
| 4 | 4 | const MODULE_ID = 2; |
| 5 | 5 | |
| 6 | 6 | private $location = ''; |
| 7 | + private $canonical = ''; | |
| 7 | 8 | |
| 8 | 9 | public function get_id() { |
| 9 | 10 | return self::MODULE_ID; |
| 10 | 11 | } |
| @@ -16,10 +17,14 @@ | ||
| 16 | 17 | public function get_location() { |
| 17 | 18 | return $this->location; |
| 18 | 19 | } |
| 19 | 20 | |
| 21 | + public function get_canonical() { | |
| 22 | + return $this->canonical; | |
| 23 | + } | |
| 24 | + | |
| 20 | 25 | protected function load( $data ) { |
| 21 | - $mine = array( 'location' ); | |
| 26 | + $mine = array( 'location', 'canonical' ); | |
| 22 | 27 | |
| 23 | 28 | foreach ( $mine as $key ) { |
| 24 | 29 | if ( isset( $data[ $key ] ) ) { |
| 25 | 30 | $this->$key = $data[ $key ]; |
| @@ -27,9 +32,9 @@ | ||
| 27 | 32 | } |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | 35 | protected function flush_module() { |
| 31 | - include_once dirname( dirname( __FILE__ ) ) . '/models/htaccess.php'; | |
| 36 | + include_once dirname( dirname( __FILE__ ) ).'/models/htaccess.php'; | |
| 32 | 37 | |
| 33 | 38 | if ( empty( $this->location ) ) { |
| 34 | 39 | return; |
| 35 | 40 | } |
| @@ -49,13 +54,18 @@ | ||
| 49 | 54 | return $htaccess->save( $this->location ); |
| 50 | 55 | } |
| 51 | 56 | |
| 52 | 57 | public function update( array $data ) { |
| 53 | - include_once dirname( dirname( __FILE__ ) ) . '/models/htaccess.php'; | |
| 58 | + include_once dirname( dirname( __FILE__ ) ).'/models/htaccess.php'; | |
| 54 | 59 | |
| 55 | 60 | $save = array( |
| 56 | - 'location' => isset( $data['location'] ) ? trim( $data['location'] ) : '', | |
| 61 | + 'location' => isset( $data['location'] ) ? trim( $data['location'] ) : '', | |
| 62 | + 'canonical' => isset( $data['canonical'] ) ? trim( $data['canonical'] ) : '', | |
| 57 | 63 | ); |
| 64 | + | |
| 65 | + if ( ! in_array( $save['canonical'], array( 'www', 'nowww' ), true ) ) { | |
| 66 | + $save['canonical'] = ''; | |
| 67 | + } | |
| 58 | 68 | |
| 59 | 69 | if ( ! empty( $this->location ) && $save['location'] !== $this->location ) { |
| 60 | 70 | // Location has moved. Remove from old location |
| 61 | 71 | $htaccess = new Red_Htaccess(); |