PluginProbe
Redirection / 2.8
Redirection v2.8
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
redirection / modules / apache.php

apache.php in Redirection 2.8, at modules/apache.php

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