PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/kennethreitz-archive/wordpress-skeleton
PHP | 377 lines | 289 code | 69 blank | 19 comment | 47 complexity | 1b7f4295d4d14a50f2e6cccc59bf71ad 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. var $post;
  24. function RedirectionAjax() {
  25. $this->register_plugin( 'redirection', __FILE__ );
  26. add_action( 'init', array( &$this, 'init' ) );
  27. }
  28. function init() {
  29. if ( current_user_can( 'administrator' ) ) {
  30. $this->post = stripslashes_deep( $_POST );
  31. $this->register_ajax( 'red_log_show' );
  32. $this->register_ajax( 'red_log_hide' );
  33. $this->register_ajax( 'red_log_delete' );
  34. $this->register_ajax( 'red_module_edit' );
  35. $this->register_ajax( 'red_module_load' );
  36. $this->register_ajax( 'red_module_save' );
  37. $this->register_ajax( 'red_module_reset' );
  38. $this->register_ajax( 'red_module_delete' );
  39. $this->register_ajax( 'red_group_edit' );
  40. $this->register_ajax( 'red_group_load' );
  41. $this->register_ajax( 'red_group_save' );
  42. $this->register_ajax( 'red_group_toggle' );
  43. $this->register_ajax( 'red_group_delete' );
  44. $this->register_ajax( 'red_group_reset' );
  45. $this->register_ajax( 'red_group_move' );
  46. $this->register_ajax( 'red_group_saveorder' );
  47. $this->register_ajax( 'red_redirect_edit' );
  48. $this->register_ajax( 'red_redirect_load' );
  49. $this->register_ajax( 'red_redirect_save' );
  50. $this->register_ajax( 'red_redirect_toggle' );
  51. $this->register_ajax( 'red_redirect_delete' );
  52. $this->register_ajax( 'red_redirect_reset' );
  53. $this->register_ajax( 'red_redirect_move' );
  54. $this->register_ajax( 'red_redirect_saveorder' );
  55. $this->register_ajax( 'red_redirect_add' );
  56. }
  57. }
  58. function red_log_show() {
  59. $id = intval( $_GET['id'] );
  60. if ( check_ajax_referer( 'redirection-log_'.$id ) ) {
  61. $log = RE_Log::get_by_id( $id );
  62. $redirect = Red_Item::get_by_id( $log->redirection_id );
  63. $this->render_admin( 'log_item_details', array( 'log' => $log, 'redirect' => $redirect ) );
  64. die();
  65. }
  66. }
  67. function red_log_hide() {
  68. $id = intval( $_GET['id'] );
  69. if ( check_ajax_referer( 'redirection-log_'.$id ) ) {
  70. $log = RE_Log::get_by_id( $id );
  71. echo '<a class="details" href="'.$log->url.'">'.$log->show_url ($log->url).'</a>';
  72. die();
  73. }
  74. }
  75. function red_log_delete() {
  76. if ( check_ajax_referer( 'redirection-items' ) ) {
  77. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  78. foreach ( $items[1] AS $item ) {
  79. RE_Log::delete( intval( $item ) );
  80. }
  81. }
  82. }
  83. }
  84. function red_module_edit() {
  85. $id = intval( $_GET['id'] );
  86. if ( check_ajax_referer( 'redirection-module_'.$id ) ) {
  87. $module = Red_Module::get( $id );
  88. if ( $module )
  89. $this->render_admin( 'module_edit', array( 'module' => $module ) );
  90. die();
  91. }
  92. }
  93. function red_module_load() {
  94. $id = intval( $_GET['id'] );
  95. if ( check_ajax_referer( 'redirection-module_'.$id ) ) {
  96. $module = Red_Module::get ($id);
  97. if ($module) {
  98. global $redirection;
  99. $options = $redirection->get_options();
  100. $this->render_admin( 'module_item', array( 'module' => $module, 'token' => $options['token'] ) );
  101. }
  102. die();
  103. }
  104. }
  105. function red_module_save() {
  106. $id = intval( $this->post['id'] );
  107. if ( check_ajax_referer( 'redirection-module_save_'.$id ) ) {
  108. $module = Red_Module::get( $id );
  109. if ( $module ) {
  110. global $redirection;
  111. $options = $redirection->get_options();
  112. $module->update( $this->post );
  113. $this->render_admin( 'module_item', array( 'module' => $module, 'token' => $options['token'] ) );
  114. }
  115. }
  116. }
  117. function red_module_reset() {
  118. $id = intval( $_GET['id'] );
  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. $module->reset ();
  125. $this->render_admin( 'module_item', array( 'module' => $module, 'token' => $options['token'] ) );
  126. }
  127. die();
  128. }
  129. }
  130. function red_module_delete() {
  131. $id = intval( $_GET['id'] );
  132. if ( check_ajax_referer( 'redirection-module_'.$id ) ) {
  133. $module = Red_Module::get( $id );
  134. $module->delete();
  135. }
  136. }
  137. function red_group_edit() {
  138. $id = intval( $_GET['id'] );
  139. if ( check_ajax_referer( 'redirection-group_'.$id ) ) {
  140. $group = Red_Group::get( $id );
  141. if ( $group )
  142. $this->render_admin( 'group_edit', array( 'group' => $group, 'modules' => Red_Module::get_for_select() ) );
  143. die();
  144. }
  145. }
  146. function red_group_load() {
  147. $id = intval( $_GET['id'] );
  148. if ( check_ajax_referer( 'redirection-group_'.$id ) ) {
  149. $group = Red_Group::get( $id );
  150. if ( $group )
  151. $this->render_admin( 'group_item', array( 'group' => $group ) );
  152. die();
  153. }
  154. }
  155. function red_group_save() {
  156. $id = intval( $this->post['id'] );
  157. if ( check_ajax_referer( 'redirection-group_save_'.$id ) ) {
  158. $group = Red_Group::get( $id );
  159. if ( $group ) {
  160. $original_module = $group->module_id;
  161. $group->update( $this->post );
  162. $this->render_admin( 'group_item', array( 'group' => $group ) );
  163. }
  164. die();
  165. }
  166. }
  167. function red_group_toggle() {
  168. if ( check_ajax_referer( 'redirection-items' ) ) {
  169. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  170. foreach ( $items[1] AS $group ) {
  171. $group = Red_Group::get( $group );
  172. $group->toggle_status();
  173. }
  174. Red_Module::flush( $group->module_id );
  175. }
  176. }
  177. }
  178. function red_group_delete() {
  179. if ( check_ajax_referer( 'redirection-items' ) ) {
  180. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  181. foreach ( $items[1] AS $group ) {
  182. Red_Group::delete( intval( $group ) );
  183. }
  184. $group = Red_Group::get( $group );
  185. Red_Module::flush( $group->module_id );
  186. }
  187. }
  188. }
  189. function red_group_reset() {
  190. if ( check_ajax_referer( 'redirection-items' ) ) {
  191. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  192. foreach ( $items[1] AS $group ) {
  193. $redirect = Red_Group::get( intval( $group ) );
  194. $redirect->reset();
  195. }
  196. }
  197. }
  198. }
  199. function red_group_move() {
  200. if ( check_ajax_referer( 'redirection-items' ) ) {
  201. $target = intval( $this->post['target'] );
  202. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  203. foreach ( $items[1] AS $group ) {
  204. $redirect = Red_Group::get( $group );
  205. $redirect->move_to( $target );
  206. }
  207. }
  208. }
  209. }
  210. function red_group_saveorder() {
  211. if ( check_ajax_referer( 'redirection-items' ) ) {
  212. if ( preg_match_all( '/=(\d*)/', $this->post['items'], $items ) > 0) {
  213. Red_Group::save_order( $items[1], intval( $this->post['page'] ) );
  214. }
  215. }
  216. }
  217. function red_redirect_edit() {
  218. if ( check_ajax_referer( 'redirection-items' ) ) {
  219. $redirect = Red_Item::get_by_id( intval( $_GET['id'] ) );
  220. if ( $redirect )
  221. $this->render_admin( 'item_edit', array( 'redirect' => $redirect, 'groups' => Red_Group::get_for_select() ) );
  222. die();
  223. }
  224. }
  225. function red_redirect_load() {
  226. if ( check_ajax_referer( 'redirection-items' ) ) {
  227. $redirect = Red_Item::get_by_id( intval( $_GET['id'] ) );
  228. if ( $redirect )
  229. $this->render_admin( 'item', array( 'redirect' => $redirect, 'date_format' => get_option( 'date_format' ) ) );
  230. die();
  231. }
  232. }
  233. function red_redirect_save() {
  234. $id = intval( $this->post['id'] );
  235. if ( check_ajax_referer( 'redirection-redirect_save_'.$id ) ) {
  236. $redirect = Red_Item::get_by_id( $id );
  237. $redirect->update( $this->post );
  238. $this->render_admin( 'item', array( 'redirect' => $redirect, 'date_format' => get_option( 'date_format' ) ) );
  239. die();
  240. }
  241. }
  242. function red_redirect_toggle() {
  243. if ( check_ajax_referer( 'redirection-items' ) ) {
  244. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  245. foreach ( $items[1] AS $item ) {
  246. $redirect = Red_Item::get_by_id( $item );
  247. $redirect->toggle_status();
  248. }
  249. }
  250. $group = Red_Group::get( $redirect->group_id );
  251. Red_Module::flush( $group->module_id );
  252. }
  253. }
  254. function red_redirect_delete() {
  255. if ( check_ajax_referer( 'redirection-items' ) ) {
  256. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  257. $redirect = Red_Item::get_by_id( $items[0]);
  258. foreach ( $items[1] AS $item ) {
  259. Red_Item::delete( intval( $item ) );
  260. }
  261. $group = Red_Group::get( $redirect->group_id );
  262. Red_Module::flush( $group->module_id );
  263. }
  264. }
  265. }
  266. function red_redirect_reset() {
  267. if ( check_ajax_referer( 'redirection-items' ) ) {
  268. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  269. foreach ( $items[1] AS $item ) {
  270. $redirect = Red_Item::get_by_id( intval( $item ) );
  271. $redirect->reset();
  272. }
  273. }
  274. }
  275. }
  276. function red_redirect_move() {
  277. if ( check_ajax_referer( 'redirection-items' ) ) {
  278. $target = intval( $this->post['target'] );
  279. if ( preg_match_all( '/=(\d*)/', $this->post['checked'], $items ) > 0) {
  280. foreach ( $items[1] AS $item ) {
  281. $redirect = Red_Item::get_by_id( $item );
  282. $redirect->move_to( $target );
  283. }
  284. }
  285. }
  286. }
  287. function red_redirect_saveorder() {
  288. if ( check_ajax_referer( 'redirection-items' ) ) {
  289. if ( preg_match_all( '/=(\d*)/', $this->post['items'], $items ) > 0) {
  290. Red_Item::save_order( $items[1], intval( $this->post['page'] ) );
  291. }
  292. }
  293. }
  294. function red_redirect_add() {
  295. if ( check_ajax_referer( 'redirection-redirect_add' ) ) {
  296. $item = Red_Item::create( $this->post );
  297. if ( $item !== false ) {
  298. echo '<li class="type_'.$item->action_type.'" id="item_'.$item->id.'">';
  299. $this->render_admin( 'item', array( 'redirect' => $item, 'date_format' => get_option( 'date_format' ) ) );
  300. echo '</li>';
  301. }
  302. else
  303. $this->render_error (__ ('Sorry, but your redirection was not created', 'redirection'));
  304. die();
  305. }
  306. }
  307. }