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

191 lines 6.3 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 {
5 var $name;
6 var $allow_ip = false;
7 var $raw;
8 var $ban_ip = false;
9
10 var $site = '';
11 var $location = '';
12 var $canonical = '';
13 var $strip_index = '';
14 var $memory_limit = '';
15 var $error_level = '';
16
17 function is_valid ()
18 {
19 if (!$this->location || !file_exists (dirname ($this->location)) && !is_writable (dirname ($this->location)))
20 return false;
21 return true;
22 }
23
24 function load ($data)
25 {
26 $mine = array ('location', 'canonical', 'strip_index', 'memory_limit', 'error_level', 'ban_ip', 'allow_ip', 'raw', 'site');
27 foreach ($mine AS $key)
28 {
29 if (isset ($data[$key]))
30 $this->$key = $data[$key];
31 }
32 }
33
34 function module_flush_delete ()
35 {
36 @unlink ($this->location);
37 }
38
39 function module_flush ($items)
40 {
41 // Produce the .htaccess file
42 include_once (dirname (__FILE__).'/../models/htaccess.php');
43
44 $htaccess = new Red_Htaccess ($this);
45 if (is_array ($items) && count ($items) > 0)
46 {
47 foreach ($items AS $item)
48 $htaccess->add ($item);
49 }
50
51 $htaccess->save ($this->location, $this->name);
52 }
53
54 function save ($data)
55 {
56 $save = array (
57 'location' => isset( $data['location'] ) ? $data['location'] : false,
58 'canonical' => isset( $data['canonical'] ) ? $data['canonical'] : false,
59 'strip_index' => isset( $data['strip_index'] ) ? $data['strip_index'] : false,
60 'memory_limit' => isset( $data['memory_limit'] ) ? $data['memory_limit'] : false,
61 'error_level' => isset( $data['error_level'] ) ? $data['error_level'] : false,
62 'ban_ip' => isset( $data['ban_ip'] ) ? $data['ban_ip'] : false,
63 'allow_ip' => isset( $data['allow_ip'] ) ? $data['allow_ip'] : false,
64 'raw' => isset( $data['raw'] ) ? $data['raw'] : false,
65 'site' => preg_replace ('@https?://@', '', $data['site'])
66 );
67
68 $this->load ($save);
69 return $save;
70 }
71
72 function config ()
73 {
74 ?>
75 <tr>
76 <th valign="top"><?php _e ('Location', 'redirection'); ?>:</th>
77 <td>
78 <input type="text" name="location" value="<?php echo htmlspecialchars ($this->location) ?>" style="width: 95%"/>
79 <?php if ($this->location == '') : ?>
80 <br/>
81 <span class="sub"><?php printf (__ ('WordPress is installed in: <code>%s</code>', 'redirection'), ABSPATH); ?></span>
82 <?php endif; ?>
83 </td>
84 </tr>
85 <tr>
86 <th><?php _e ('Canonical', 'redirection'); ?>:</th>
87 <td>
88 <select name="canonical">
89 <?php echo $this->select (array ('default' => __ ('Leave as is', 'redirection'), 'nowww' => sprintf (__ ('Strip WWW (%s)', 'redirection'), preg_replace ('@https?://(www)?@', '', get_bloginfo ('url'))), 'www' => sprintf (__ ('Force WWW (www.%s)', 'redirection'), preg_replace ('@https?://(www)?@', '', get_bloginfo ('url')))), $this->canonical); ?>
90 </select>
91
92 <br/>
93 <strong><?php _e ('Strip Index', 'redirection'); ?>:</strong>
94 <select name="strip_index">
95 <?php echo $this->select (array ('default' => __ ('Leave as is', 'redirection'), 'yes' => __ ('Strip index files (html,php)', 'redirection')), $this->strip_index); ?>
96 </select>
97 </td>
98 </tr>
99 <tr>
100 <th><?php _e ('Memory Limit', 'redirection'); ?>:</th>
101 <td>
102 <select name="memory_limit">
103 <?php echo $this->select (array ('0' => __ ('Server default', 'redirection'), '8' => '8MB', '16' => '16MB', '32' => '32MB', '64' => '64MB', '128' => '128MB'), $this->memory_limit); ?>
104 </select>
105
106 <strong><?php _e ('Error Level', 'redirection'); ?>:</strong>
107 <select name="error_level">
108 <?php echo $this->select (array ('default' => __ ('Server default', 'redirection'), 'none' => __ ('No errors', 'redirection'), 'error' => __ ('Show errors', 'redirection')), $this->error_level); ?>
109 </select>
110 </td>
111 </tr>
112 <tr>
113 <th><?php _e ('Ban IPs', 'redirection'); ?>:</th>
114 <td>
115 <input type="text" name="ban_ip" value="<?php echo htmlspecialchars ($this->ban_ip) ?>" style="width: 95%"/>
116 </td>
117 </tr>
118 <tr>
119 <th><?php _e ('Allow IPs', 'redirection'); ?>:</th>
120 <td>
121 <input type="text" name="allow_ip" value="<?php echo htmlspecialchars ($this->allow_ip) ?>" style="width: 95%"/>
122 </td>
123 </tr>
124 <tr>
125 <th valign="top"><?php _e ('Raw .htaccess', 'redirection'); ?>:</th>
126 <td>
127 <textarea style="width: 95%" name="raw"><?php echo htmlspecialchars ($this->raw)?></textarea>
128 </td>
129 </tr>
130 <tr>
131 <th><?php _e ('Site URL', 'redirection'); ?>:</th>
132 <td>
133 <input type="text" size="40" name="site" value="<?php echo htmlspecialchars ($this->site) ?>"/>
134 <span class="sub"><?php _e ('Advanced: For management of external sites', 'redirection'); ?></span>
135 </td>
136 </tr>
137
138 <?php
139 }
140
141 function options ()
142 {
143 echo '<p>';
144 if ($this->location)
145 {
146 if (!file_exists (dirname ($this->location)))
147 {
148 echo '<code>'.$this->location.'</code></p>';
149 echo __ ('<strong>Location is invalid - check that path exists</strong>', 'redirection');
150 return;
151 }
152 else if ((file_exists ($this->location) && !is_writable ($this->location)) || (!file_exists ($this->location) && !is_writable (dirname ($this->location))))
153 {
154 echo '<code>'.$this->location.'</code></p>';
155 echo __ ('<strong>Could not write to configured <code>.htaccess</code> file - check file permissions</strong>', 'redirection');
156 return;
157 }
158 else
159 echo '<code>'.$this->location.'</code>';
160 }
161 else
162 echo __ ('<strong>Disabled: enter the location of an <code>.htaccess</code> file for this to be valid</strong>', 'redirection');
163 echo '</p>';
164
165 $options = array ();
166 if ($this->canonical != 'default' && !empty ($this->canonical))
167 $options[] = ($this->canonical == 'nowww') ? __ ('strip WWW', 'redirection') : __ ('force WWW', 'redirection');
168
169 if ($this->strip_index != 'default' && !empty ($this->strip_index))
170 $options[] = __ ('strip index', 'redirection');
171
172 if ($this->memory_limit > 0 && !empty ($this->memory_limit))
173 $options[] = sprintf (__ ('memory limit at %dMB', 'redirection'), $this->memory_limit);
174
175 if ($this->error_level != 'default' && !empty ($this->error_level))
176 $options[] = ($this->error_level == 'none') ? __ ('no errors', 'redirection') : __ ('show errors', 'redirection');
177
178 if (!empty ($this->ban_ip))
179 $options[] = __ ('IPs are banned', 'redirection');
180
181 if (!empty ($this->allow_ip))
182 $options[] = __ ('IPs are allowed', 'redirection');
183
184 echo '<small>'.ucfirst (implode (', ', $options)).'</small>';
185 }
186
187 public function get_type_string() {
188 return __( 'Apache', 'redirection' );
189 }
190 }
191