PluginProbe
Redirection / 2.6
Redirection v2.6
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 | modules/apache.php +63 -22 4.12.6 View file →
@@ -3,47 +3,41 @@
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 }
11 12
12 - public function get_name() {
13 - return 'Apache';
13 + public function can_edit_config() {
14 + return true;
14 15 }
15 16
16 - public function get_location() {
17 - return $this->location;
18 - }
19 -
20 17 protected function load( $data ) {
21 - $mine = array( 'location' );
18 + $mine = array( 'location', 'canonical' );
22 19
23 20 foreach ( $mine as $key ) {
24 - if ( isset( $data[ $key ] ) ) {
21 + if ( isset( $data[ $key ] ) )
25 22 $this->$key = $data[ $key ];
26 - }
27 23 }
28 24 }
29 25
30 26 protected function flush_module() {
31 - include_once dirname( dirname( __FILE__ ) ) . '/models/htaccess.php';
27 + include_once dirname( dirname( __FILE__ ) ).'/models/htaccess.php';
32 28
33 - if ( empty( $this->location ) ) {
29 + if ( empty( $this->location ) )
34 30 return;
35 - }
36 31
37 - $items = Red_Item::get_all_for_module( $this->get_id() );
32 + $items = Red_Item::get_by_module( $this->get_id() );
38 33
39 34 // Produce the .htaccess file
40 35 $htaccess = new Red_Htaccess();
41 36 if ( is_array( $items ) && count( $items ) > 0 ) {
42 37 foreach ( $items as $item ) {
43 - if ( $item->is_enabled() ) {
38 + if ( $item->is_enabled() )
44 39 $htaccess->add( $item );
45 - }
46 40 }
47 41 }
48 42
49 43 return $htaccess->save( $this->location );
@@ -48,13 +42,14 @@
48 42
49 43 return $htaccess->save( $this->location );
50 44 }
51 45
52 - public function update( array $data ) {
53 - include_once dirname( dirname( __FILE__ ) ) . '/models/htaccess.php';
46 + public function update( $data ) {
47 + include_once dirname( dirname( __FILE__ ) ).'/models/htaccess.php';
54 48
55 49 $save = array(
56 - 'location' => isset( $data['location'] ) ? trim( $data['location'] ) : '',
50 + 'location' => isset( $data['location'] ) ? $data['location'] : false,
51 + 'canonical' => isset( $data['canonical'] ) ? $data['canonical'] : false,
57 52 );
58 53
59 54 if ( ! empty( $this->location ) && $save['location'] !== $this->location ) {
60 55 // Location has moved. Remove from old location
@@ -63,11 +58,57 @@
63 58 }
64 59
65 60 $this->load( $save );
66 61
67 - if ( $save['location'] !== '' && $this->flush_module() === false ) {
68 - $save['location'] = '';
69 - }
62 + if ( $save['location'] && $this->flush_module() === false )
63 + return __( 'Cannot write to chosen location - check path and permissions.', 'redirection' );
70 64
71 - return $save;
65 + $options = red_get_options();
66 + $options['modules'][ self::MODULE_ID ] = $save;
67 +
68 + update_option( 'redirection_options', $options );
69 + return true;
70 + }
71 +
72 + public function render_config() {
73 + $without = preg_replace( '@https?://(www)?@', '', get_bloginfo( 'url' ) );
74 + ?>
75 + <tr>
76 + <th valign="top" width="170"><?php _e( '.htaccess Location', 'redirection' ); ?>:</th>
77 + <td>
78 + <input type="text" name="location" value="<?php echo esc_attr( $this->location ) ?>" style="width: 95%"/>
79 +
80 + <p class="sub"><?php _e( 'If you want Redirection to automatically update your <code>.htaccess</code> file then enter the full path and filename here. You can also download the file and update it manually.', 'redirection' ); ?></p>
81 + <p class="sub"><?php printf( __( 'WordPress is installed in: <code>%s</code>', 'redirection' ), ABSPATH ); ?></p>
82 + </td>
83 + </tr>
84 + <tr>
85 + <th valign="top"><?php _e( 'Canonical URL', 'redirection' ); ?>:</th>
86 + <td>
87 + <select name="canonical">
88 + <option <?php selected( $this->canonical, '' ); ?> value=""><?php _e( 'Default server', 'redirection' ); ?></option>
89 + <option <?php selected( $this->canonical, 'nowww' ); ?> value="nowww"><?php printf( __( 'Remove WWW (%s)', 'redirection' ), $without ); ?></option>
90 + <option <?php selected( $this->canonical, 'www' ); ?> value="www"><?php printf( __( 'Add WWW (www.%s)', 'redirection' ), $without ); ?></option>
91 + </select>
92 +
93 + <p class="sub"><?php _e( 'Automatically remove or add www to your site.', 'redirection' ); ?></p>
94 + </td>
95 + </tr>
96 +
97 + <?php
98 + }
99 +
100 + public function get_config() {
101 + if ( ! empty( $this->location ) )
102 + return array( sprintf( __( '<code>.htaccess</code> saved to %s', 'redirection' ), esc_html( $this->location ) ) );
103 +
104 + return array();
105 + }
106 +
107 + public function get_name() {
108 + return __( 'Apache', 'redirection' );
109 + }
110 +
111 + public function get_description() {
112 + return __( 'Uses Apache <code>.htaccess</code> files. Requires further configuration. The redirect happens without loading WordPress. No tracking of hits.', 'redirection' );
72 113 }
73 114 }