PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/redirection/ajax.php

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