/**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     if (!$GLOBALS['contextly']->isLoadWidget()) {
         return;
     }
     $classes = array(Contextly::WIDGET_SIDERAIL_CLASS, Contextly::WIDGET_PLACEMENT_CLASS, Contextly::CLEARFIX_CLASS);
     print $args['before_widget'];
     printf('<div class="%s"></div>', Contextly::escapeClasses($classes));
     print $args['after_widget'];
 }
 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>";
 }
/*
Plugin Name: Contextly
Plugin URI: http://contextly.com
Description: Adds the Contextly content recommendation tool to your site. Contextly provides related, trending, evergreen and personalized recommendations to help your readers keep reading. Includes text, video and product recommendations to show off your best content.
Author: Contextly
Version: 3.2
*/
$is_https = is_ssl();
if (!$is_https && strpos(home_url(), 'https://') !== false) {
    $is_https = true;
}
define("CONTEXTLY_MODE", 'live');
define("CONTEXTLY_HTTPS", $is_https);
define("CONTEXTLY_PLUGIN_FILE", __FILE__);
define("CONTEXTLY_PLUGIN_VERSION", '3.2');
define("CONTEXTLY_CDN_VERSION", 'branch');
require_once "kit/server/Kit.php";
ContextlyKit::registerAutoload();
require_once "Kit.php";
require_once "Urls.php";
require_once "Contextly.php";
require_once "ContextlySettings.php";
if (is_admin()) {
    // Init Contextly WP settings
    $contextly_settings = new ContextlySettings();
    $contextly_settings->init();
}
// Init Contextly
global $contextly;
$contextly = new Contextly();
$contextly->init();
 public function ajaxPublishPostCallback()
 {
     $page_id = $_REQUEST['page_id'];
     check_ajax_referer("contextly-post-{$page_id}", 'contextly_nonce');
     $post = get_post($page_id);
     if ($post) {
         $contextly = new Contextly();
         $result = $contextly->publishPost($page_id, $post);
         echo json_encode($result);
     }
     exit;
 }