| 1 |
<?php |
| 2 |
/** |
| 3 |
* Redirection |
| 4 |
* |
| 5 |
* @package Redirection |
| 6 |
* @author John Godley |
| 7 |
* @copyright Copyright (C) John Godley |
| 8 |
**/ |
| 9 |
|
| 10 |
/* |
| 11 |
============================================================================================================ |
| 12 |
This software is provided "as is" and any express or implied warranties, including, but not limited to, the |
| 13 |
implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall |
| 14 |
the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or |
| 15 |
consequential damages (including, but not limited to, procurement of substitute goods or services; loss of |
| 16 |
use, data, or profits; or business interruption) however caused and on any theory of liability, whether in |
| 17 |
contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of |
| 18 |
this software, even if advised of the possibility of such damage. |
| 19 |
|
| 20 |
For full license details see license.txt |
| 21 |
============================================================================================================ */ |
| 22 |
|
| 23 |
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 |
| 24 |
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past |
| 25 |
|
| 26 |
class RedirectionAjax extends Redirection_Plugin { |
| 27 |
var $post; |
| 28 |
|
| 29 |
function RedirectionAjax() { |
| 30 |
$this->register_plugin( 'redirection', __FILE__ ); |
| 31 |
|
| 32 |
add_action( 'init', array( &$this, 'init' ) ); |
| 33 |
} |
| 34 |
|
| 35 |
function init() { |
| 36 |
if ( current_user_can( 'administrator' ) ) { |
| 37 |
$this->post = stripslashes_deep( $_POST ); |
| 38 |
|
| 39 |
$this->register_ajax( 'red_log_show' ); |
| 40 |
$this->register_ajax( 'red_log_hide' ); |
| 41 |
$this->register_ajax( 'red_log_delete' ); |
| 42 |
|
| 43 |
$this->register_ajax( 'red_module_edit' ); |
| 44 |
$this->register_ajax( 'red_module_load' ); |
| 45 |
$this->register_ajax( 'red_module_save' ); |
| 46 |
$this->register_ajax( 'red_module_reset' ); |
| 47 |
$this->register_ajax( 'red_module_delete' ); |
| 48 |
|
| 49 |
$this->register_ajax( 'red_group_edit' ); |
| 50 |
$this->register_ajax( 'red_group_load' ); |
| 51 |
$this->register_ajax( 'red_group_save' ); |
| 52 |
$this->register_ajax( 'red_group_toggle' ); |
| 53 |
$this->register_ajax( 'red_group_delete' ); |
| 54 |
$this->register_ajax( 'red_group_reset' ); |
| 55 |
$this->register_ajax( 'red_group_move' ); |
| 56 |
$this->register_ajax( 'red_group_saveorder' ); |
| 57 |
|
| 58 |
$this->register_ajax( 'red_redirect_edit' ); |
| 59 |
$this->register_ajax( 'red_redirect_load' ); |
| 60 |
$this->register_ajax( 'red_redirect_save' ); |
| 61 |
$this->register_ajax( 'red_redirect_toggle' ); |
| 62 |
$this->register_ajax( 'red_redirect_delete' ); |
| 63 |
$this->register_ajax( 'red_redirect_reset' ); |
| 64 |
$this->register_ajax( 'red_redirect_move' ); |
| 65 |
$this->register_ajax( 'red_redirect_saveorder' ); |
| 66 |
$this->register_ajax( 'red_redirect_add' ); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
function red_log_show() { |
| 71 |
$id = intval( $_GET['id'] ); |
| 72 |
|
| 73 |
if ( check_ajax_referer( 'redirection-log_'.$id ) ) { |
| 74 |
$log = RE_Log::get_by_id( $id ); |
| 75 |
$redirect = Red_Item::get_by_id( $log->redirection_id ); |
| 76 |
|
| 77 |
$this->render_admin( 'log_item_details', array( 'log' => $log, 'redirect' => $redirect ) ); |
| 78 |
die(); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
function red_log_hide() { |
| 83 |
$id = intval( $_GET['id'] ); |
| 84 |
|
| 85 |
if ( check_ajax_referer( 'redirection-log_'.$id ) ) { |
| 86 |
$log = RE_Log::get_by_id( $id ); |
| 87 |
|
| 88 |
echo '<a class="details" href="'.$log->url.'">'.$log->show_url ($log->url).'</a>'; |
| 89 |
die(); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
function red_log_delete() { |
| 94 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 95 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 96 |
foreach ( $items[1] AS $item ) { |
| 97 |
RE_Log::delete( intval( $item ) ); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
function red_module_edit() { |
| 104 |
$id = intval( $_GET['id'] ); |
| 105 |
|
| 106 |
if ( check_ajax_referer( 'redirection-module_'.$id ) ) { |
| 107 |
$module = Red_Module::get( $id ); |
| 108 |
|
| 109 |
if ( $module ) |
| 110 |
$this->render_admin( 'module_edit', array( 'module' => $module ) ); |
| 111 |
|
| 112 |
die(); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
function red_module_load() { |
| 117 |
$id = intval( $_GET['id'] ); |
| 118 |
|
| 119 |
if ( check_ajax_referer( 'redirection-module_'.$id ) ) { |
| 120 |
$module = Red_Module::get ($id); |
| 121 |
if ($module) { |
| 122 |
global $redirection; |
| 123 |
$options = $redirection->get_options(); |
| 124 |
|
| 125 |
$this->render_admin( 'module_item', array( 'module' => $module, 'token' => $options['token'] ) ); |
| 126 |
} |
| 127 |
|
| 128 |
die(); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
function red_module_save() { |
| 133 |
$id = intval( $this->post['id'] ); |
| 134 |
|
| 135 |
if ( check_ajax_referer( 'redirection-module_save_'.$id ) ) { |
| 136 |
$module = Red_Module::get( $id ); |
| 137 |
if ( $module ) { |
| 138 |
global $redirection; |
| 139 |
$options = $redirection->get_options(); |
| 140 |
$module->update( $this->post ); |
| 141 |
|
| 142 |
$this->render_admin( 'module_item', array( 'module' => $module, 'token' => $options['token'] ) ); |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
function red_module_reset() { |
| 148 |
$id = intval( $_GET['id'] ); |
| 149 |
|
| 150 |
if ( check_ajax_referer( 'redirection-module_'.$id ) ) { |
| 151 |
$module = Red_Module::get( $id ); |
| 152 |
|
| 153 |
if ( $module ) { |
| 154 |
global $redirection; |
| 155 |
$options = $redirection->get_options(); |
| 156 |
|
| 157 |
$module->reset (); |
| 158 |
$this->render_admin( 'module_item', array( 'module' => $module, 'token' => $options['token'] ) ); |
| 159 |
} |
| 160 |
|
| 161 |
die(); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
function red_module_delete() { |
| 166 |
$id = intval( $_GET['id'] ); |
| 167 |
if ( check_ajax_referer( 'redirection-module_'.$id ) ) { |
| 168 |
$module = Red_Module::get( $id ); |
| 169 |
$module->delete(); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
function red_group_edit() { |
| 174 |
$id = intval( $_GET['id'] ); |
| 175 |
|
| 176 |
if ( check_ajax_referer( 'redirection-group_'.$id ) ) { |
| 177 |
$group = Red_Group::get( $id ); |
| 178 |
if ( $group ) |
| 179 |
$this->render_admin( 'group_edit', array( 'group' => $group, 'modules' => Red_Module::get_for_select() ) ); |
| 180 |
|
| 181 |
die(); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
function red_group_load() { |
| 186 |
$id = intval( $_GET['id'] ); |
| 187 |
|
| 188 |
if ( check_ajax_referer( 'redirection-group_'.$id ) ) { |
| 189 |
$group = Red_Group::get( $id ); |
| 190 |
if ( $group ) |
| 191 |
$this->render_admin( 'group_item', array( 'group' => $group ) ); |
| 192 |
die(); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
function red_group_save() { |
| 197 |
$id = intval( $this->post['id'] ); |
| 198 |
|
| 199 |
if ( check_ajax_referer( 'redirection-group_save_'.$id ) ) { |
| 200 |
$group = Red_Group::get( $id ); |
| 201 |
if ( $group ) { |
| 202 |
$original_module = $group->module_id; |
| 203 |
$group->update( $this->post ); |
| 204 |
|
| 205 |
$this->render_admin( 'group_item', array( 'group' => $group ) ); |
| 206 |
} |
| 207 |
|
| 208 |
die(); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
function red_group_toggle() { |
| 213 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 214 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 215 |
foreach ( $items[1] AS $group ) { |
| 216 |
$group = Red_Group::get( $group ); |
| 217 |
$group->toggle_status(); |
| 218 |
} |
| 219 |
|
| 220 |
Red_Module::flush( $group->module_id ); |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
function red_group_delete() { |
| 226 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 227 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 228 |
foreach ( $items[1] AS $group ) { |
| 229 |
Red_Group::delete( intval( $group ) ); |
| 230 |
} |
| 231 |
|
| 232 |
$group = Red_Group::get( $group ); |
| 233 |
Red_Module::flush( $group->module_id ); |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
function red_group_reset() { |
| 239 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 240 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 241 |
foreach ( $items[1] AS $group ) { |
| 242 |
$redirect = Red_Group::get( intval( $group ) ); |
| 243 |
$redirect->reset(); |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
function red_group_move() { |
| 250 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 251 |
$target = intval( $this->post['target'] ); |
| 252 |
|
| 253 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 254 |
foreach ( $items[1] AS $group ) { |
| 255 |
$redirect = Red_Group::get( $group ); |
| 256 |
$redirect->move_to( $target ); |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
function red_group_saveorder() { |
| 263 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 264 |
if ( preg_match_all( '/=(\d*)/', $this->post['items'], $items ) > 0) { |
| 265 |
Red_Group::save_order( $items[1], intval( $this->post['page'] ) ); |
| 266 |
} |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
function red_redirect_edit() { |
| 271 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 272 |
$redirect = Red_Item::get_by_id( intval( $_GET['id'] ) ); |
| 273 |
if ( $redirect ) |
| 274 |
$this->render_admin( 'item_edit', array( 'redirect' => $redirect, 'groups' => Red_Group::get_for_select() ) ); |
| 275 |
|
| 276 |
die(); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
function red_redirect_load() { |
| 281 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 282 |
$redirect = Red_Item::get_by_id( intval( $_GET['id'] ) ); |
| 283 |
if ( $redirect ) |
| 284 |
$this->render_admin( 'item', array( 'redirect' => $redirect, 'date_format' => get_option( 'date_format' ) ) ); |
| 285 |
|
| 286 |
die(); |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
function red_redirect_save() { |
| 291 |
$id = intval( $this->post['id'] ); |
| 292 |
|
| 293 |
if ( check_ajax_referer( 'redirection-redirect_save_'.$id ) ) { |
| 294 |
$redirect = Red_Item::get_by_id( $id ); |
| 295 |
$redirect->update( $this->post ); |
| 296 |
|
| 297 |
$this->render_admin( 'item', array( 'redirect' => $redirect, 'date_format' => get_option( 'date_format' ) ) ); |
| 298 |
die(); |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
function red_redirect_toggle() { |
| 303 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 304 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 305 |
foreach ( $items[1] AS $item ) { |
| 306 |
$redirect = Red_Item::get_by_id( $item ); |
| 307 |
$redirect->toggle_status(); |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
$group = Red_Group::get( $redirect->group_id ); |
| 312 |
Red_Module::flush( $group->module_id ); |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
function red_redirect_delete() { |
| 317 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 318 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 319 |
$redirect = Red_Item::get_by_id( $items[0]); |
| 320 |
|
| 321 |
foreach ( $items[1] AS $item ) { |
| 322 |
Red_Item::delete( intval( $item ) ); |
| 323 |
} |
| 324 |
|
| 325 |
$group = Red_Group::get( $redirect->group_id ); |
| 326 |
Red_Module::flush( $group->module_id ); |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
function red_redirect_reset() { |
| 332 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 333 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 334 |
foreach ( $items[1] AS $item ) { |
| 335 |
$redirect = Red_Item::get_by_id( intval( $item ) ); |
| 336 |
$redirect->reset(); |
| 337 |
} |
| 338 |
} |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
function red_redirect_move() { |
| 343 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 344 |
$target = intval( $this->post['target'] ); |
| 345 |
|
| 346 |
if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) { |
| 347 |
foreach ( $items[1] AS $item ) { |
| 348 |
$redirect = Red_Item::get_by_id( $item ); |
| 349 |
$redirect->move_to( $target ); |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
function red_redirect_saveorder() { |
| 356 |
if ( check_ajax_referer( 'redirection-items' ) ) { |
| 357 |
if ( preg_match_all( '/=(\d*)/', $this->post['items'], $items ) > 0) { |
| 358 |
Red_Item::save_order( $items[1], intval( $this->post['page'] ) ); |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
function red_redirect_add() { |
| 364 |
if ( check_ajax_referer( 'redirection-redirect_add' ) ) { |
| 365 |
$item = Red_Item::create( $this->post ); |
| 366 |
if ( $item !== false ) { |
| 367 |
echo '<li class="type_'.$item->action_type.'" id="item_'.$item->id.'">'; |
| 368 |
$this->render_admin( 'item', array( 'redirect' => $item, 'date_format' => get_option( 'date_format' ) ) ); |
| 369 |
echo '</li>'; |
| 370 |
} |
| 371 |
else |
| 372 |
$this->render_error (__ ('Sorry, but your redirection was not created', 'redirection')); |
| 373 |
|
| 374 |
die(); |
| 375 |
} |
| 376 |
} |
| 377 |
} |
| 378 |
|