PluginProbe
Redirection / 2.4.4
Redirection v2.4.4
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.4.4, at modules/apache.php

115 lines 3.5 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 can_edit_config() {
14 return true;
15 }
16
17 protected function load( $data ) {
18 $mine = array( 'location', 'canonical' );
19
20 foreach ( $mine AS $key ) {
21 if ( isset( $data[$key] ) )
22 $this->$key = $data[$key];
23 }
24 }
25
26 protected function flush_module() {
27 include_once dirname( dirname( __FILE__ ) ).'/models/htaccess.php';
28
29 if ( empty( $this->location ) )
30 return;
31
32 $items = Red_Item::get_by_module( $this->get_id() );
33
34 // Produce the .htaccess file
35 $htaccess = new Red_Htaccess();
36 if ( is_array( $items ) && count( $items ) > 0 ) {
37 foreach ( $items AS $item ) {
38 if ( $item->is_enabled() )
39 $htaccess->add( $item );
40 }
41 }
42
43 return $htaccess->save( $this->location );
44 }
45
46 public function update( $data ) {
47 include_once dirname( dirname( __FILE__ ) ).'/models/htaccess.php';
48
49 $save = array(
50 'location' => isset( $data['location'] ) ? $data['location'] : false,
51 'canonical' => isset( $data['canonical'] ) ? $data['canonical'] : false,
52 );
53
54 if ( !empty( $this->location ) && $save['location'] !== $this->location ) {
55 // Location has moved. Remove from old location
56 $htaccess = new Red_Htaccess();
57 $htaccess->save( $this->location, '' );
58 }
59
60 $this->load( $save );
61
62 if ( $save['location'] && $this->flush_module() === false )
63 return __( 'Cannot write to chosen location - check path and permissions.', 'redirection' );
64
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' );
113 }
114 }
115