elementor
3 years ago
admin-create-shortcode.php
7 years ago
admin-create-user.php
1 week ago
admin-custom-function.php
1 week ago
admin-rest-api.php
1 week ago
admin-settings.php
2 years ago
admin-social-button.php
1 week ago
admin-social-enque-script.php
5 years ago
counter-widget.php
1 week ago
counter.php
1 week ago
custom-function.php
5 years ago
login-widget.php
3 years ago
login.php
5 years ago
share-widget.php
1 week ago
share.php
1 week ago
admin-rest-api.php
169 lines
| 1 | <?php |
| 2 | |
| 3 | defined('ABSPATH') || exit; |
| 4 | |
| 5 | require_once( WSLU_LOGIN_PLUGIN . 'lib/composer/vendor/autoload.php' ); |
| 6 | require_once( WSLU_LOGIN_PLUGIN . 'helper/helper.php' ); |
| 7 | |
| 8 | use TikTok\Authentication\Authentication; |
| 9 | use WP_Social\Helper\Helper; |
| 10 | |
| 11 | /** |
| 12 | * Function Name : xs_return_call_back_login_function(); |
| 13 | * Function Details : WP Rest API. |
| 14 | * |
| 15 | * @params : void |
| 16 | * |
| 17 | * @return : array() |
| 18 | * |
| 19 | * @since : 1.0 |
| 20 | */ |
| 21 | if(!function_exists('xs_return_call_back_login_function')) { |
| 22 | |
| 23 | function xs_return_call_back_login_function(WP_REST_Request $request) { |
| 24 | |
| 25 | $param = $request['data']; |
| 26 | $code = $request['code']; |
| 27 | if(is_null($param)) { |
| 28 | $typeSocial = ''; |
| 29 | } |
| 30 | |
| 31 | $typeSocial = $param; |
| 32 | $socialType = ''; |
| 33 | $callBackUrl = ''; |
| 34 | |
| 35 | require_once(WSLU_LOGIN_PLUGIN . '/inc/admin-create-user.php'); |
| 36 | die(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * wp rest api add action |
| 42 | */ |
| 43 | add_action('rest_api_init', function() { |
| 44 | |
| 45 | //https://dev.finesttheme.com/social/wp-json/wslu-social-login/type/google |
| 46 | register_rest_route('wslu-social-login', '/type/(?P<data>\w+)/', |
| 47 | array( |
| 48 | 'methods' => 'GET', |
| 49 | 'callback' => 'xs_return_call_back_login_function', |
| 50 | 'permission_callback' => '__return_true', |
| 51 | ) |
| 52 | ); |
| 53 | |
| 54 | |
| 55 | register_rest_route('wslu/v1', '/check_cache/(?P<type>\w+)/', |
| 56 | array( |
| 57 | 'methods' => 'POST', |
| 58 | 'callback' => 'post_check_counter_cache', |
| 59 | 'permission_callback' => '__return_true', |
| 60 | ) |
| 61 | ); |
| 62 | |
| 63 | register_rest_route('wslu/v1', '/save_cache/(?P<type>\w+)/', |
| 64 | array( |
| 65 | 'methods' => 'POST', |
| 66 | 'callback' => 'post_save_instagram_counter_cache', |
| 67 | 'permission_callback' => '__return_true', |
| 68 | ) |
| 69 | ); |
| 70 | |
| 71 | register_rest_route('wslu-social-counter', '/type/(?P<data>\w+)/', |
| 72 | array( |
| 73 | 'methods' => 'GET', |
| 74 | 'callback' => 'xs_return_call_back_counter_function', |
| 75 | 'permission_callback' => '__return_true', |
| 76 | ) |
| 77 | ); |
| 78 | }); |
| 79 | |
| 80 | |
| 81 | if( !function_exists('xs_return_call_back_counter_function') ) { |
| 82 | function xs_return_call_back_counter_function( WP_REST_Request $request ) { |
| 83 | |
| 84 | $data = $request->get_params(); |
| 85 | $client_key = get_option( 'xs_counter_tiktok_app_id' ); |
| 86 | $client_secret = get_option( 'xs_counter_tiktok_app_secret' ); |
| 87 | |
| 88 | $authentication = new Authentication( array( |
| 89 | 'client_key' => $client_key, |
| 90 | 'client_secret' => $client_secret |
| 91 | )); |
| 92 | |
| 93 | $redirect_url = site_url() . '/wp-json/wslu-social-counter/type/tiktok'; |
| 94 | $code = isset( $data['code'] ) ? $data['code'] : ''; |
| 95 | $token_from_code = $authentication->getAccessTokenFromCode( $code, $redirect_url ); |
| 96 | $user_token = isset( $token_from_code['access_token'] ) ? $token_from_code['access_token'] : ''; |
| 97 | |
| 98 | // Set proper content type |
| 99 | header('Content-Type: text/html; charset=UTF-8'); |
| 100 | |
| 101 | if( $user_token ) { |
| 102 | Helper::tiktok_access_token_display_page_success_message( $user_token ); |
| 103 | } else { |
| 104 | Helper::tiktok_access_token_display_page_error_message(); |
| 105 | } |
| 106 | die(); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |
| 111 | function post_save_instagram_counter_cache(WP_REST_Request $request) { |
| 112 | |
| 113 | if (!current_user_can('manage_options')) { |
| 114 | return new \WP_Error('rest_forbidden', esc_html__('You do not have permission to perform this action.', 'wp-social'), array('status' => 401)); |
| 115 | } |
| 116 | |
| 117 | $data = $request->get_params(); |
| 118 | |
| 119 | $ins = new \WP_Social\Lib\Counter\Instagram_Counter(); |
| 120 | |
| 121 | $ins->cache_instagram_return($data['content']['count'], \WP_Social\App\Settings::get_counter_cache_time()); |
| 122 | |
| 123 | return array( |
| 124 | 'success' => true, |
| 125 | 'msg' => 'successfully fetched and cached', |
| 126 | //'result' => $data, |
| 127 | ); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | function post_check_counter_cache(WP_REST_Request $request) { |
| 132 | |
| 133 | if (!current_user_can('manage_options')) { |
| 134 | return new \WP_Error('rest_forbidden', esc_html__('You do not have permission to perform this action.', 'wp-social'), array('status' => 401)); |
| 135 | } |
| 136 | |
| 137 | $data = $request->get_params(); |
| 138 | |
| 139 | if($data['type'] == 'instagram') { |
| 140 | |
| 141 | $ins = new \WP_Social\Lib\Counter\Instagram_Counter(); |
| 142 | |
| 143 | $ins->load(); |
| 144 | |
| 145 | if($ins->cache_expired) { |
| 146 | |
| 147 | return array( |
| 148 | 'msg' => 'Successfull', |
| 149 | 'expired' => true, |
| 150 | 'unm' => $ins->user_id, |
| 151 | 'success' => true, |
| 152 | ); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | return array( |
| 157 | 'msg' => 'Successfull', |
| 158 | 'expired' => false, |
| 159 | 'success' => true, |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | return array( |
| 164 | 'msg' => 'error', |
| 165 | 'success' => false, |
| 166 | ); |
| 167 | } |
| 168 | |
| 169 |