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