The secret key and consumer key have being updated.

'; }else{ echo '

The secret key and consumer key have not being updated.

'; } exit(); } } add_action('admin_init','aranalyzer_oAuth_check'); /* End oAuth check */ /* oAuth Callback response from modal windows. This function will prevent reload the WP site inside * the modal windows.(see file modal/js/modal.windows.js) **/ function aranalyzer_check_keys_callback() { if ($_POST['modekeys']){ echo true; exit(); } } add_action('admin_init','aranalyzer_check_keys_callback'); function aranalyzer_metabox_setup() { global $post; // using an underscore, prevents the meta variable // from showing up in the custom fields section $scoring = get_post_meta($post->ID, '_ar_scoring', TRUE); $ar_enabled = get_post_meta($post->ID, '_ar_meta_review_enabled', TRUE); $ar_audience = get_post_meta($post->ID, '_ar_meta_audience_list', TRUE); // will return TRUE if the keys have been set correctly in AR Optimizer (modal windows login to AR) $ar_state_keys = get_option('aranalyzer_state_keys'); // if (!session_id()) { // session_start(); // } $error = $_SESSION['_ar_api_error']; $consumerKey = get_option('aranalyzer_consumerkey'); $secretKey = get_option('aranalyzer_secretkey'); $audienceList = aranalyzer_api_getaudiencelist($consumerKey, $secretKey); // including the metabox php code require_once(MY_PLUGIN_FOLDER . '/custom/meta.php'); } /*************************/ /* Metabox Functions End */ /*************************/ /*************************/ /* API Interaction */ /*************************/ function aranalyzer_api_getmetadata($consumerKey, $secretKey, $title, $content, $segmentId) { require_once(MY_PLUGIN_FOLDER . '/includes/ARClient.php'); $host = API_HOST; $apiClient = New AR_Client($host, $consumerKey, $secretKey); $apiClient->init(); $result = $apiClient->analyzePost($content, $title, $segmentId); return $result; } function aranalyzer_api_getaudiencelist($consumerKey, $secretKey) { require_once(MY_PLUGIN_FOLDER . '/includes/ARClient.php'); $host = API_HOST; $apiClient = New AR_Client($host, $consumerKey, $secretKey); $apiClient->init(); $result = $apiClient->getAudienceList(); return $result; } function aranalyzer_admin() { // this option will have the state of the keys in case of error will set to FALSE $ar_state_keys = get_option('ar_state_keys'); require_once('ar_analyzer_admin.php'); } function aranalyzer_admin_actions() { wp_enqueue_script('ar_simple.modal_js', MY_PLUGIN_PATH . 'modal/js/jquery.simplemodal.js', array( 'jquery')); wp_enqueue_script('ar_modal.windows_js', MY_PLUGIN_PATH . 'modal/js/modal.windows.js', array( 'jquery')); wp_enqueue_style('ar_modal_css', MY_PLUGIN_PATH . '/modal/css/modal-windows.css'); add_menu_page("Atomic Reach Post Optimizer Configuration", "AR Optimizer", 1, "ar-analyzer-admin", "aranalyzer_admin", plugin_dir_url( __FILE__ ) . "custom/ar-logo-icon.gif"); } add_action('admin_menu', 'aranalyzer_admin_actions'); function aranalyzer_review($post_ID) { // if (!session_id()) { // session_start(); // } // Get post information $post_info = get_post($post_ID); $title = $post_info->post_title; $content = apply_filters('the_content', $post_info->post_content); $ar_api_status = true; $ar_api_error = ""; // Save the analizer is active option $meta_key = '_ar_meta_review_enabled'; $value = ( isset( $_POST[$meta_key] ) ? $_POST[$meta_key] : '' ); delete_post_meta( $post_ID, $meta_key); add_post_meta( $post_ID, $meta_key, $value, true ); if($value === "enabled") $analyzer_active = true; // Save the audience list option selected $meta_key = '_ar_meta_audience_list'; $segmentId = $value = ( isset( $_POST[$meta_key] ) ? $_POST[$meta_key] : '' ); delete_post_meta( $post_ID, $meta_key); add_post_meta( $post_ID, $meta_key, $value, true ); if ($analyzer_active) { /* After a long time looking through formatting functions * * I found this combination that left HTML code without encoding and * * all the other text formatted with HTML entities encoding */ $title = htmlspecialchars_decode( htmlentities( $title, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES ); $content = htmlspecialchars_decode( htmlentities( $content, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES ); // Call the API with the post contents. $consumerKey = get_option('aranalyzer_consumerkey'); $secretKey = get_option('aranalyzer_secretkey'); $scoringObj = aranalyzer_api_getmetadata($consumerKey, $secretKey, $title, $content, $segmentId); // delete_post_meta($post_ID, '_ar_api_status'); update_option('aranalyzer_state_keys', 'TRUE'); if(isset($scoringObj->error)){ // delete_post_meta($post_ID, '_ar_api_error'); // add_post_meta($post_ID,'_ar_api_error', $scoringObj->error, TRUE); // add_post_meta($post_ID,'_ar_api_status', 'FALSE', TRUE); update_option('aranalyzer_state_keys', 'FALSE'); $_SESSION['_ar_api_error'] = $scoringObj->error; } else { $_SESSION['_ar_api_error'] = false; // Fix the special case when only one suggestion comes in the spelling options foreach($scoringObj->data->analysis->sm->detail as $key => $value) { if(!is_array($value->suggestions->option)) { $value->suggestions->option = array($value->suggestions->option); } } // Fix the special case when only one suggestion comes in the grammar options foreach($scoringObj->data->analysis->gm->detail as $key => $value) { if(isset($value->suggestions->option)) { if(!is_array($value->suggestions->option)) { $value->suggestions->option = array($value->suggestions->option); } } } delete_post_meta($post_ID, '_ar_scoring'); // Update metadata and recover it again to update the UI. $current_data = get_post_meta($post_ID, '_ar_scoring', TRUE); if ($current_data) { update_post_meta($post_ID,'_ar_scoring',$scoringObj); } elseif (!is_null($scoringObj)) { add_post_meta($post_ID,'_ar_scoring',$scoringObj,TRUE); } } } else { delete_post_meta($post_ID, '_ar_scoring'); } } /* hook when click on update */ add_action('publish_post', 'aranalyzer_review'); /* hook when save draft post */ add_action('save_post', 'aranalyzer_review'); /** * Used to load the required files on the plugins_loaded hook, instead of immediately. * */ function aranalyzer_tracking_admin_init(){ $opt_in = get_option('aranalyzer_tracking'); if ( isset($opt_in) && $opt_in ) { require_once( MY_PLUGIN_FOLDER . '/includes/ARTracking.php'); $ar_tracking = new AR_Tracking(API_HOST); } } /** * checks if the Dashboard or the administration panel is attempting to be displayed * http://codex.wordpress.org/Function_Reference/is_admin */ if ( is_admin() ) { add_action( 'plugins_loaded', 'aranalyzer_tracking_admin_init' ); } /** * Used to get the state to be display in scoring list comparing recommended words against sentences * */ function aranalyzer_get_state($dpObject) { if(!isset($dpObject->scoring)) { $scoring= 40; // add text in case there is not a value }else{ $scoring = $dpObject->scoring; } $dpObject = $dpObject->analysis; $aColorText = array(); if($scoring <= 33){ $aColorText = array( 'arBarColor' => 'red', 'arText' => 'Content edits are needed', 'scoring' => $scoring, ); }elseif($scoring > 33 && $scoring<= 66){ $aColorText = array( 'arBarColor' => 'yellow', 'arText' => 'Content edits are recommended', 'scoring' => $scoring, ); }else{ $aColorText = array( 'arBarColor' => 'green', 'arText' => 'Content refinements are suggested
To update this page analysis, save as draft or update and check this tab again.', 'scoring' => $scoring, ); } return $aColorText; } ?>