Пример #1
0
 public function handleAjaxAction()
 {
     $post_id = $_POST['post_id'];
     check_ajax_referer("contextly-post-{$post_id}", 'nonce');
     if (!isset($_POST['method'])) {
         $GLOBALS['contextly']->return404();
     }
     $method = $_POST['method'];
     if (isset($_POST['params'])) {
         $params = $_POST['params'];
     } else {
         $params = array();
     }
     $params['custom_id'] = $post_id;
     try {
         $result = $this->handleRequest($method, $params);
     } catch (ContextlyKitApiException $e) {
         if (isset($e->getApiResult()->error_code) && $e->getApiResult()->error_code == 413) {
             // Access token not exists, try to remove it
             $this->kit->newApiSession()->cleanupToken();
         }
         if (CONTEXTLY_MODE !== Urls::MODE_LIVE) {
             $message = (string) $e;
         } else {
             $message = NULL;
         }
         $GLOBALS['contextly']->return500($message);
     } catch (Exception $e) {
         Contextly::fireAPIEvent('handleAjaxAction', print_r($e, true));
         if (CONTEXTLY_MODE !== Urls::MODE_LIVE) {
             $message = (string) $e;
         } else {
             $message = NULL;
         }
         $GLOBALS['contextly']->return500($message);
     }
     @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
     echo json_encode($result);
     exit;
 }
 public function apiKeyInput()
 {
     $options = get_option(self::API_SETTINGS_KEY);
     $input_style = "";
     if (isset($_GET['api_key'])) {
         $get_api_key = urldecode($_GET['api_key']);
         if (!isset($options["api_key"]) || $options["api_key"] != $get_api_key) {
             Contextly::fireAPIEvent('contextlyApiInserted', $get_api_key);
             $options["api_key"] = sanitize_text_field($get_api_key);
             $input_style = " style='background-color: #FFEBE8; border-color: #CC0000;'";
             update_option(self::API_SETTINGS_KEY, $options);
         }
     }
     echo "<label><input name='" . esc_attr(self::API_SETTINGS_KEY) . "[api_key]' type='text' size='40' value='" . esc_attr($options["api_key"]) . "' " . $input_style . "/></label>";
 }