| 1 |
<?php |
| 2 |
|
| 3 |
class Apache_Module extends Red_Module { |
| 4 |
const MODULE_ID = 2; |
| 5 |
|
| 6 |
private $location = ''; |
| 7 |
|
| 8 |
public function get_id() { |
| 9 |
return self::MODULE_ID; |
| 10 |
} |
| 11 |
|
| 12 |
public function get_name() { |
| 13 |
return 'Apache'; |
| 14 |
} |
| 15 |
|
| 16 |
public function get_location() { |
| 17 |
return $this->location; |
| 18 |
} |
| 19 |
|
| 20 |
protected function load( $data ) { |
| 21 |
$mine = array( 'location' ); |
| 22 |
|
| 23 |
foreach ( $mine as $key ) { |
| 24 |
if ( isset( $data[ $key ] ) ) { |
| 25 |
$this->$key = $data[ $key ]; |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
protected function flush_module() { |
| 31 |
include_once dirname( dirname( __FILE__ ) ) . '/models/htaccess.php'; |
| 32 |
|
| 33 |
if ( empty( $this->location ) ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
$items = Red_Item::get_all_for_module( $this->get_id() ); |
| 38 |
|
| 39 |
// Produce the .htaccess file |
| 40 |
$htaccess = new Red_Htaccess(); |
| 41 |
if ( is_array( $items ) && count( $items ) > 0 ) { |
| 42 |
foreach ( $items as $item ) { |
| 43 |
if ( $item->is_enabled() ) { |
| 44 |
$htaccess->add( $item ); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
return $htaccess->save( $this->location ); |
| 50 |
} |
| 51 |
|
| 52 |
public function update( array $data ) { |
| 53 |
include_once dirname( dirname( __FILE__ ) ).'/models/htaccess.php'; |
| 54 |
|
| 55 |
$save = array( |
| 56 |
'location' => isset( $data['location'] ) ? trim( $data['location'] ) : '', |
| 57 |
); |
| 58 |
|
| 59 |
if ( ! empty( $this->location ) && $save['location'] !== $this->location ) { |
| 60 |
// Location has moved. Remove from old location |
| 61 |
$htaccess = new Red_Htaccess(); |
| 62 |
$htaccess->save( $this->location, '' ); |
| 63 |
} |
| 64 |
|
| 65 |
$this->load( $save ); |
| 66 |
|
| 67 |
if ( $save['location'] !== '' && $this->flush_module() === false ) { |
| 68 |
$save['location'] = ''; |
| 69 |
} |
| 70 |
|
| 71 |
return $save; |
| 72 |
} |
| 73 |
} |
| 74 |
|