PluginProbe
Redirection / 2.2.13
Redirection v2.2.13
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 / ajax.php

ajax.php in Redirection 2.2.13, at ajax.php

376 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 die();
144 }
145 }
146 }
147
148 function red_module_reset() {
149 $id = intval( $_GET['id'] );
150
151 if ( check_ajax_referer( 'redirection-module_'.$id ) ) {
152 $module = Red_Module::get( $id );
153
154 if ( $module ) {
155 global $redirection;
156 $options = $redirection->get_options();
157
158 $module->reset ();
159 $this->render_admin( 'module_item', array( 'module' => $module, 'token' => $options['token'] ) );
160 }
161
162 die();
163 }
164 }
165
166 function red_module_delete() {
167 $id = intval( $_GET['id'] );
168 if ( check_ajax_referer( 'redirection-module_'.$id ) ) {
169 $module = Red_Module::get( $id );
170 $module->delete();
171 }
172 }
173
174 function red_group_edit() {
175 $id = intval( $_GET['id'] );
176
177 if ( check_ajax_referer( 'redirection-group_'.$id ) ) {
178 $group = Red_Group::get( $id );
179 if ( $group )
180 $this->render_admin( 'group_edit', array( 'group' => $group, 'modules' => Red_Module::get_for_select() ) );
181
182 die();
183 }
184 }
185
186 function red_group_load() {
187 $id = intval( $_GET['id'] );
188
189 if ( check_ajax_referer( 'redirection-group_'.$id ) ) {
190 $group = Red_Group::get( $id );
191 if ( $group )
192 $this->render_admin( 'group_item', array( 'group' => $group ) );
193 die();
194 }
195 }
196
197 function red_group_save() {
198 $id = intval( $this->post['id'] );
199
200 if ( check_ajax_referer( 'redirection-group_save_'.$id ) ) {
201 $group = Red_Group::get( $id );
202 if ( $group ) {
203 $original_module = $group->module_id;
204 $group->update( $this->post );
205
206 $this->render_admin( 'group_item', array( 'group' => $group ) );
207 }
208
209 die();
210 }
211 }
212
213 function red_group_toggle() {
214 if ( check_ajax_referer( 'redirection-items' ) ) {
215 if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
216 foreach ( $items[1] AS $group ) {
217 $group = Red_Group::get( $group );
218 $group->toggle_status();
219 }
220
221 Red_Module::flush( $group->module_id );
222 }
223 }
224 }
225
226 function red_group_delete() {
227 if ( check_ajax_referer( 'redirection-items' ) ) {
228 if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
229 foreach ( $items[1] AS $group ) {
230 Red_Group::delete( intval( $group ) );
231 }
232 }
233 }
234 }
235
236 function red_group_reset() {
237 if ( check_ajax_referer( 'redirection-items' ) ) {
238 if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
239 foreach ( $items[1] AS $group ) {
240 $redirect = Red_Group::get( intval( $group ) );
241 $redirect->reset();
242 }
243 }
244 }
245 }
246
247 function red_group_move() {
248 if ( check_ajax_referer( 'redirection-items' ) ) {
249 $target = intval( $this->post['target'] );
250
251 if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
252 foreach ( $items[1] AS $group ) {
253 $redirect = Red_Group::get( $group );
254 $redirect->move_to( $target );
255 }
256 }
257 }
258 }
259
260 function red_group_saveorder() {
261 if ( check_ajax_referer( 'redirection-items' ) ) {
262 if ( preg_match_all( '/=(\d*)/', $this->post['items'], $items ) > 0) {
263 Red_Group::save_order( $items[1], intval( $this->post['page'] ) );
264 }
265 }
266 }
267
268 function red_redirect_edit() {
269 if ( check_ajax_referer( 'redirection-items' ) ) {
270 $redirect = Red_Item::get_by_id( intval( $_GET['id'] ) );
271 if ( $redirect )
272 $this->render_admin( 'item_edit', array( 'redirect' => $redirect, 'groups' => Red_Group::get_for_select() ) );
273
274 die();
275 }
276 }
277
278 function red_redirect_load() {
279 if ( check_ajax_referer( 'redirection-items' ) ) {
280 $redirect = Red_Item::get_by_id( intval( $_GET['id'] ) );
281 if ( $redirect )
282 $this->render_admin( 'item', array( 'redirect' => $redirect, 'date_format' => get_option( 'date_format' ) ) );
283
284 die();
285 }
286 }
287
288 function red_redirect_save() {
289 $id = intval( $this->post['id'] );
290
291 if ( check_ajax_referer( 'redirection-redirect_save_'.$id ) ) {
292 $redirect = Red_Item::get_by_id( $id );
293 $redirect->update( $this->post );
294
295 $this->render_admin( 'item', array( 'redirect' => $redirect, 'date_format' => get_option( 'date_format' ) ) );
296 die();
297 }
298 }
299
300 function red_redirect_toggle() {
301 if ( check_ajax_referer( 'redirection-items' ) ) {
302 if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
303 foreach ( $items[1] AS $item ) {
304 $redirect = Red_Item::get_by_id( $item );
305 $redirect->toggle_status();
306 }
307 }
308
309 $group = Red_Group::get( $redirect->group_id );
310 Red_Module::flush( $group->module_id );
311 }
312 }
313
314 function red_redirect_delete() {
315 if ( check_ajax_referer( 'redirection-items' ) ) {
316 if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
317 $redirect = Red_Item::get_by_id( $items[0]);
318
319 foreach ( $items[1] AS $item ) {
320 Red_Item::delete( intval( $item ) );
321 }
322
323 $group = Red_Group::get( $redirect->group_id );
324 Red_Module::flush( $group->module_id );
325 }
326 }
327 }
328
329 function red_redirect_reset() {
330 if ( check_ajax_referer( 'redirection-items' ) ) {
331 if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
332 foreach ( $items[1] AS $item ) {
333 $redirect = Red_Item::get_by_id( intval( $item ) );
334 $redirect->reset();
335 }
336 }
337 }
338 }
339
340 function red_redirect_move() {
341 if ( check_ajax_referer( 'redirection-items' ) ) {
342 $target = intval( $this->post['target'] );
343
344 if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
345 foreach ( $items[1] AS $item ) {
346 $redirect = Red_Item::get_by_id( $item );
347 $redirect->move_to( $target );
348 }
349 }
350 }
351 }
352
353 function red_redirect_saveorder() {
354 if ( check_ajax_referer( 'redirection-items' ) ) {
355 if ( preg_match_all( '/=(\d*)/', $this->post['items'], $items ) > 0) {
356 Red_Item::save_order( $items[1], intval( $this->post['page'] ) );
357 }
358 }
359 }
360
361 function red_redirect_add() {
362 if ( check_ajax_referer( 'redirection-redirect_add' ) ) {
363 $item = Red_Item::create( $this->post );
364 if ( $item !== false ) {
365 echo '<li class="type_'.$item->action_type.'" id="item_'.$item->id.'">';
366 $this->render_admin( 'item', array( 'redirect' => $item, 'date_format' => get_option( 'date_format' ) ) );
367 echo '</li>';
368 }
369 else
370 $this->render_error (__ ('Sorry, but your redirection was not created', 'redirection'));
371
372 die();
373 }
374 }
375 }
376