| @@ -1,133 +1,113 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Ajax requests handler | |
| 4 | - * @author Webcraftic <[email protected]> | |
| 5 | - * @copyright (c) 2018 Webraftic Ltd | |
| 6 | - * @version 1.0 | |
| 7 | - */ | |
| 8 | - | |
| 9 | -// Exit if accessed directly | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | - exit; | |
| 12 | -} | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * Get snippet library table content | |
| 16 | - */ | |
| 17 | -function wbcr_inp_ajax_get_snippet_library() { | |
| 18 | - check_ajax_referer( 'winp-snippet-library', 'winp_nonce' ); | |
| 19 | - ?> | |
| 20 | - <div class="wrap"> | |
| 21 | - <form id="winp-snippet-library-list" method="get"> | |
| 22 | - <input type="hidden" name="page" value="<?php echo WINP_Plugin::app()->request->request( 'page', 1, true ); ?>"/> | |
| 23 | - <input type="hidden" name="order" value="<?php echo WINP_Plugin::app()->request->request( 'order', 'asc', true ); ?>"/> | |
| 24 | - <input type="hidden" name="orderby" value="<?php echo WINP_Plugin::app()->request->request( 'orderby', 'title', true ); ?>"/> | |
| 25 | - | |
| 26 | - <div id="winp-snippet-library-table" style=""> | |
| 27 | - <p><?php _e( 'Loading...', 'insert-php' ); ?></p> | |
| 28 | - <?php | |
| 29 | - wp_nonce_field( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' ); | |
| 30 | - ?> | |
| 31 | - </div> | |
| 32 | - </form> | |
| 33 | - </div> | |
| 34 | - <?php | |
| 35 | - wp_die(); | |
| 36 | -} | |
| 37 | -add_action( 'wp_ajax_winp_get_snippet_library', 'wbcr_inp_ajax_get_snippet_library' ); | |
| 38 | - | |
| 39 | -/** | |
| 40 | - * Snippet synchronization | |
| 41 | - */ | |
| 42 | -function wbcr_inp_ajax_snippet_synchronization() { | |
| 43 | - if ( ! WINP_Helper::winp_check_user_admin() ) { | |
| 44 | - wp_die( -1, 403 ); | |
| 45 | - } | |
| 46 | - | |
| 47 | - check_ajax_referer( 'winp-snippet-library', 'winp_nonce' ); | |
| 48 | - | |
| 49 | - $result = WINP_Plugin::app()->get_api_object()->synchronization( | |
| 50 | - WINP_Plugin::app()->request->post( 'snippet_id', 0, true ), | |
| 51 | - WINP_Plugin::app()->request->post( 'snippet_name', '', true ) | |
| 52 | - ); | |
| 53 | - | |
| 54 | - exit( $result ); | |
| 55 | -} | |
| 56 | -add_action( 'wp_ajax_winp_snippet_synchronization', 'wbcr_inp_ajax_snippet_synchronization' ); | |
| 57 | - | |
| 58 | -/** | |
| 59 | - * Snippet create from library | |
| 60 | - */ | |
| 61 | -function wbcr_inp_ajax_snippet_create() { | |
| 62 | - if ( ! WINP_Helper::winp_check_user_admin() ) { | |
| 63 | - wp_die( -1, 403 ); | |
| 64 | - } | |
| 65 | - | |
| 66 | - check_ajax_referer( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' ); | |
| 67 | - | |
| 68 | - $snippet_id = WINP_Plugin::app()->request->post( 'snippet_id', 0, true ); | |
| 69 | - $post_id = WINP_Plugin::app()->request->post( 'post_id', 0, true ); | |
| 70 | - $common = WINP_Plugin::app()->request->post( 'common', 0 ); | |
| 71 | - $result = WINP_Plugin::app()->get_api_object()->create_from_library( $snippet_id, $post_id, $common ); | |
| 72 | - | |
| 73 | - echo( $result ); | |
| 74 | - exit(); | |
| 75 | -} | |
| 76 | -add_action( 'wp_ajax_winp_snippet_create', 'wbcr_inp_ajax_snippet_create' ); | |
| 77 | - | |
| 78 | -/** | |
| 79 | - * Snippet delete from library | |
| 80 | - */ | |
| 81 | -function wbcr_inp_ajax_snippet_delete() { | |
| 82 | - if ( ! WINP_Helper::winp_check_user_admin() ) { | |
| 83 | - wp_die( -1, 403 ); | |
| 84 | - } | |
| 85 | - | |
| 86 | - $snippet_id = WINP_Plugin::app()->request->post( 'snippet_id', 0, true ); | |
| 87 | - | |
| 88 | - check_ajax_referer( 'winp-ajax-snippet-delete-' . $snippet_id, 'winp_ajax_snippet_delete_nonce' ); | |
| 89 | - | |
| 90 | - $result = WINP_Plugin::app()->get_api_object()->delete_snippet( $snippet_id ); | |
| 91 | - | |
| 92 | - echo( $result ); | |
| 93 | - exit(); | |
| 94 | -} | |
| 95 | -add_action( 'wp_ajax_winp_snippet_delete', 'wbcr_inp_ajax_snippet_delete' ); | |
| 96 | - | |
| 97 | -/** | |
| 98 | - * Action wp_ajax for fetching the first time table structure | |
| 99 | - */ | |
| 100 | -function wbcr_inp_ajax_sts_display_callback() { | |
| 101 | - check_ajax_referer( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' ); | |
| 102 | - | |
| 103 | - require_once( WINP_PLUGIN_DIR . '/admin/includes/class.snippets.table.php' ); | |
| 104 | - | |
| 105 | - // Create an instance of our package class... | |
| 106 | - $snippet_list_table = new WINP_Snippet_Library_Table( true ); | |
| 107 | - // Fetch, prepare, sort, and filter our data... | |
| 108 | - $snippet_list_table->prepare_items(); | |
| 109 | - ob_start(); | |
| 110 | - $snippet_list_table->display(); | |
| 111 | - $display = ob_get_clean(); | |
| 112 | - die( | |
| 113 | - json_encode( | |
| 114 | - array( | |
| 115 | - 'display' => $display, | |
| 116 | - ) | |
| 117 | - ) | |
| 118 | - ); | |
| 119 | -} | |
| 120 | -add_action( 'wp_ajax_winp_sts_display', 'wbcr_inp_ajax_sts_display_callback' ); | |
| 121 | - | |
| 122 | -/** | |
| 123 | - * Action wp_ajax for fetching ajax_response | |
| 124 | - */ | |
| 125 | -function wbcr_inp_ajax_sts_history_callback() { | |
| 126 | - check_ajax_referer( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' ); | |
| 127 | - | |
| 128 | - require_once( WINP_PLUGIN_DIR . '/admin/includes/class.snippets.table.php' ); | |
| 129 | - | |
| 130 | - $snippet_list_table = new WINP_Snippet_Library_Table( true ); | |
| 131 | - $snippet_list_table->ajax_response(); | |
| 132 | -} | |
| 133 | -add_action( 'wp_ajax_winp_fetch_sts_history', array( $this, 'wbcr_inp_ajax_sts_history_callback' ) ); | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Ajax requests handler | |
| 4 | + * | |
| 5 | + * @package Woody_Code_Snippets | |
| 6 | + */ | |
| 7 | + | |
| 8 | +// Exit if accessed directly | |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | + exit; | |
| 11 | +} | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * Get snippet library table content | |
| 15 | + */ | |
| 16 | +function wbcr_inp_ajax_get_snippet_library() { | |
| 17 | + if ( ! WINP_Plugin::app()->current_user_car() ) { | |
| 18 | + wp_die( - 1, 403 ); | |
| 19 | + } | |
| 20 | + | |
| 21 | + check_ajax_referer( 'winp-snippet-library', 'winp_nonce' ); | |
| 22 | + ?> | |
| 23 | + <div class="wrap"> | |
| 24 | + <form id="winp-snippet-library-list" method="get"> | |
| 25 | + <input type="hidden" name="page" value="<?php echo WINP_HTTP::request( 'page', 1, true ); ?>"/> | |
| 26 | + <input type="hidden" name="order" value="<?php echo WINP_HTTP::request( 'order', 'asc', true ); ?>"/> | |
| 27 | + <input type="hidden" name="orderby" value="<?php echo WINP_HTTP::request( 'orderby', 'title', true ); ?>"/> | |
| 28 | + <div id="winp-snippet-library-table" style=""> | |
| 29 | + <p><?php _e( 'Loading snippets...', 'insert-php' ); ?></p> | |
| 30 | + <?php | |
| 31 | + wp_nonce_field( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' ); | |
| 32 | + ?> | |
| 33 | + </div> | |
| 34 | + </form> | |
| 35 | + </div> | |
| 36 | + <?php | |
| 37 | + wp_die(); | |
| 38 | +} | |
| 39 | + | |
| 40 | +add_action( 'wp_ajax_winp_get_snippet_library', 'wbcr_inp_ajax_get_snippet_library' ); | |
| 41 | + | |
| 42 | +/** | |
| 43 | + * Snippet create from library | |
| 44 | + */ | |
| 45 | +function wbcr_inp_ajax_snippet_create() { | |
| 46 | + if ( ! WINP_Plugin::app()->current_user_car() ) { | |
| 47 | + wp_die( - 1, 403 ); | |
| 48 | + } | |
| 49 | + | |
| 50 | + check_ajax_referer( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' ); | |
| 51 | + | |
| 52 | + $snippet_id = WINP_HTTP::post( 'snippet_id', 0, true ); | |
| 53 | + $post_id = WINP_HTTP::post( 'post_id', 0, true ); | |
| 54 | + $common = WINP_HTTP::post( 'common', 0 ); | |
| 55 | + $result = WINP_Plugin::app()->get_api_object()->create_from_library( $snippet_id, $post_id, $common ); | |
| 56 | + | |
| 57 | + echo( $result ); | |
| 58 | + exit(); | |
| 59 | +} | |
| 60 | + | |
| 61 | +add_action( 'wp_ajax_winp_snippet_create', 'wbcr_inp_ajax_snippet_create' ); | |
| 62 | + | |
| 63 | +/** | |
| 64 | + * Snippet delete from library | |
| 65 | + */ | |
| 66 | +function wbcr_inp_ajax_snippet_delete() { | |
| 67 | + if ( ! WINP_Plugin::app()->current_user_car() ) { | |
| 68 | + wp_die( - 1, 403 ); | |
| 69 | + } | |
| 70 | + | |
| 71 | + $snippet_id = WINP_HTTP::post( 'snippet_id', 0, true ); | |
| 72 | + | |
| 73 | + check_ajax_referer( 'winp-ajax-snippet-delete-' . $snippet_id, 'winp_ajax_snippet_delete_nonce' ); | |
| 74 | + | |
| 75 | + $result = WINP_Plugin::app()->get_api_object()->delete_snippet( $snippet_id ); | |
| 76 | + | |
| 77 | + echo( $result ); | |
| 78 | + exit(); | |
| 79 | +} | |
| 80 | + | |
| 81 | +add_action( 'wp_ajax_winp_snippet_delete', 'wbcr_inp_ajax_snippet_delete' ); | |
| 82 | + | |
| 83 | +/** | |
| 84 | + * Action wp_ajax for fetching the first time table structure | |
| 85 | + */ | |
| 86 | +function wbcr_inp_ajax_sts_display_callback() { | |
| 87 | + if ( ! WINP_Plugin::app()->current_user_car() ) { | |
| 88 | + wp_die( - 1, 403 ); | |
| 89 | + } | |
| 90 | + | |
| 91 | + check_ajax_referer( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' ); | |
| 92 | + | |
| 93 | + require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.table.php'; | |
| 94 | + | |
| 95 | + // Create an instance of our package class... | |
| 96 | + $snippet_list_table = new WINP_Snippet_Library_Table( true ); | |
| 97 | + // Fetch, prepare, sort, and filter our data... | |
| 98 | + $snippet_list_table->prepare_items(); | |
| 99 | + ob_start(); | |
| 100 | + $snippet_list_table->display(); | |
| 101 | + $display = ob_get_clean(); | |
| 102 | + die( | |
| 103 | + json_encode( | |
| 104 | + [ | |
| 105 | + 'display' => $display, | |
| 106 | + ] | |
| 107 | + ) | |
| 108 | + ); | |
| 109 | +} | |
| 110 | + | |
| 111 | +add_action( 'wp_ajax_winp_sts_display', 'wbcr_inp_ajax_sts_display_callback' ); | |
| 112 | + | |
| 113 | + | |