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

188 lines 6.0 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 (
58 'location' => $data['location'],
59 'canonical' => $data['canonical'],
60 'strip_index' => $data['strip_index'],
61 'memory_limit' => $data['memory_limit'],
62 'error_level' => $data['error_level'],
63 'ban_ip' => $data['ban_ip'],
64 'allow_ip' => $data['allow_ip'],
65 'raw' => $data['raw'],
66 'site' => preg_replace ('@https?://@', '', $data['site'])
67 );
68
69 $this->load ($save);
70 return $save;
71 }
72
73 function config ()
74 {
75 ?>
76 <tr>
77 <th valign="top"><?php _e ('Location', 'redirection'); ?>:</th>
78 <td>
79 <input type="text" name="location" value="<?php echo htmlspecialchars ($this->location) ?>" style="width: 95%"/>
80 <?php if ($this->location == '') : ?>
81 <br/>
82 <span class="sub"><?php printf (__ ('WordPress is installed in: <code>%s</code>', 'redirection'), ABSPATH); ?></span>
83 <?php endif; ?>
84 </td>
85 </tr>
86 <tr>
87 <th><?php _e ('Canonical', 'redirection'); ?>:</th>
88 <td>
89 <select name="canonical">
90 <?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); ?>
91 </select>
92
93 <br/>
94 <strong><?php _e ('Strip Index', 'redirection'); ?>:</strong>
95 <select name="strip_index">
96 <?php echo $this->select (array ('default' => __ ('Leave as is', 'redirection'), 'yes' => __ ('Strip index files (html,php)', 'redirection')), $this->strip_index); ?>
97 </select>
98 </td>
99 </tr>
100 <tr>
101 <th><?php _e ('Memory Limit', 'redirection'); ?>:</th>
102 <td>
103 <select name="memory_limit">
104 <?php echo $this->select (array ('0' => __ ('Server default', 'redirection'), '8' => '8MB', '16' => '16MB', '32' => '32MB', '64' => '64MB', '128' => '128MB'), $this->memory_limit); ?>
105 </select>
106
107 <strong><?php _e ('Error Level', 'redirection'); ?>:</strong>
108 <select name="error_level">
109 <?php echo $this->select (array ('default' => __ ('Server default', 'redirection'), 'none' => __ ('No errors', 'redirection'), 'error' => __ ('Show errors', 'redirection')), $this->error_level); ?>
110 </select>
111 </td>
112 </tr>
113 <tr>
114 <th><?php _e ('Ban IPs', 'redirection'); ?>:</th>
115 <td>
116 <input type="text" name="ban_ip" value="<?php echo htmlspecialchars ($this->ban_ip) ?>" style="width: 95%"/>
117 </td>
118 </tr>
119 <tr>
120 <th><?php _e ('Allow IPs', 'redirection'); ?>:</th>
121 <td>
122 <input type="text" name="allow_ip" value="<?php echo htmlspecialchars ($this->allow_ip) ?>" style="width: 95%"/>
123 </td>
124 </tr>
125 <tr>
126 <th valign="top"><?php _e ('Raw .htaccess', 'redirection'); ?>:</th>
127 <td>
128 <textarea style="width: 95%" name="raw"><?php echo htmlspecialchars ($this->raw)?></textarea>
129 </td>
130 </tr>
131 <tr>
132 <th><?php _e ('Site URL', 'redirection'); ?>:</th>
133 <td>
134 <input type="text" size="40" name="site" value="<?php echo htmlspecialchars ($this->site) ?>"/>
135 <span class="sub"><?php _e ('Advanced: For management of external sites', 'redirection'); ?></span>
136 </td>
137 </tr>
138
139 <?php
140 }
141
142 function options ()
143 {
144 echo '<p>';
145 if ($this->location)
146 {
147 if (!file_exists (dirname ($this->location)))
148 {
149 echo '<code>'.$this->location.'</code></p>';
150 echo __ ('<strong>Location is invalid - check that path exists</strong>', 'redirection');
151 return;
152 }
153 else if ((file_exists ($this->location) && !is_writable ($this->location)) || (!file_exists ($this->location) && !is_writable (dirname ($this->location))))
154 {
155 echo '<code>'.$this->location.'</code></p>';
156 echo __ ('<strong>Could not write to configured <code>.htaccess</code> file - check file permissions</strong>', 'redirection');
157 return;
158 }
159 else
160 echo '<code>'.$this->location.'</code>';
161 }
162 else
163 echo __ ('<strong>Disabled: enter the location of an <code>.htaccess</code> file for this to be valid</strong>', 'redirection');
164 echo '</p>';
165
166 $options = array ();
167 if ($this->canonical != 'default' && !empty ($this->canonical))
168 $options[] = ($this->canonical == 'nowww') ? __ ('strip WWW', 'redirection') : __ ('force WWW', 'redirection');
169
170 if ($this->strip_index != 'default' && !empty ($this->strip_index))
171 $options[] = __ ('strip index', 'redirection');
172
173 if ($this->memory_limit > 0 && !empty ($this->memory_limit))
174 $options[] = sprintf (__ ('memory limit at %dMB', 'redirection'), $this->memory_limit);
175
176 if ($this->error_level != 'default' && !empty ($this->error_level))
177 $options[] = ($this->error_level == 'none') ? __ ('no errors', 'redirection') : __ ('show errors', 'redirection');
178
179 if (!empty ($this->ban_ip))
180 $options[] = __ ('IPs are banned', 'redirection');
181
182 if (!empty ($this->allow_ip))
183 $options[] = __ ('IPs are allowed', 'redirection');
184
185 echo '<small>'.ucfirst (implode (', ', $options)).'</small>';
186 }
187 }
188