TRUE,
'_builtin' => FALSE
);
$post_types = get_post_types($arg_post_types, 'names');
// add post and pages as well.
array_push($post_types, 'post', 'page');
foreach ($post_types as $type) {
add_meta_box('aranalyzer_metabox', 'Atomic Engager', 'aranalyzer_metabox_setup', $type, 'side', 'high');
}
}
add_action('admin_init', 'aranalyzer_metabox_init');
/* oAuth check: this function check if the secret and consumer keys were set.
* This event will happen after doing a click on the Connect to AR button
* in the AR Optimizer section and the modal windows return those values
* after login to Atomic Reach site
*
* */
function aranalyzer_oAuth_check()
{
if (isset($_GET['mode']) && isset($_GET['key']) && isset($_GET['secret'])) {
if ($_GET['mode'] == 'ar_callback' ) {
update_option('aranalyzer_secretkey', '');
update_option('aranalyzer_consumerkey', '');
if (update_option('aranalyzer_secretkey', $_GET['secret']) && update_option('aranalyzer_consumerkey', $_GET['key'])) {
update_option('aranalyzer_state_keys', 'TRUE');
echo '
The secret key and consumer key have being updated.
Close this window to continue
';
} else {
echo '
The secret key and consumer key have not being updated.
Close this window to continue
';
}
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);
// $custom_fields = get_post_custom($post->ID);
// $my_custom_field = $custom_fields['_ar_meta_audience_list'];
// foreach ( $my_custom_field as $key => $value ) {
// echo $key . " => " . $value . " ";
// }
// 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_getsophisticationbandlist($consumerKey, $secretKey);
// Store user selected targetAudience to show the pie image. HZ
/*foreach ($audienceList->sources AS $source) {
foreach ($source->segments AS $v) {
if ($v->id == $ar_audience) {
$targetAud = $v->targetAudience;
}
}
}*/
foreach ($audienceList->sophisticatonBands AS $SophBand) {
if ($SophBand->id == $ar_audience) {
$targetAud = strtoupper(str_replace('* ', '', $SophBand->name));
}
}
$arView = get_option('aranalyzer_view');
// including the metabox php code
if ($arView == 1) {
require_once(MY_PLUGIN_FOLDER . '/custom/new-meta.php');
} else {
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;
}
// get 5 bands.
function aranalyzer_api_getsophisticationbandlist($consumerKey, $secretKey)
{
require_once(MY_PLUGIN_FOLDER . '/includes/ARClient.php');
$host = API_HOST;
$apiClient = New AR_Client($host, $consumerKey, $secretKey);
$apiClient->init();
$result = $apiClient->getSophisticationBandList();
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 ar_analyzer_custom_dictionary()
{
$success = FALSE;
$word = $_GET['word'];
if ($word) {
require_once(MY_PLUGIN_FOLDER . '/includes/ARClient.php');
$host = API_HOST;
$consumerKey = get_option('aranalyzer_consumerkey');
$secretKey = get_option('aranalyzer_secretkey');
$apiClient = New AR_Client($host, $consumerKey, $secretKey);
$apiClient->init();
$result = $apiClient->addDictionary($word);
if ($result->status == AR_Client::STATUS_OK) {
$success = TRUE;
}
}
echo $success ? 'OK' : 'ERROR';
exit();
}
add_action('wp_ajax_ar_analyzer_custom_dictionary', 'ar_analyzer_custom_dictionary');
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 Engager Configuration", "Atomic Engager", "manage_options", "ar-analyzer-admin", "aranalyzer_admin",
plugin_dir_url(__FILE__) . "custom/ar-logo-icon.png");
}
add_action('admin_menu', 'aranalyzer_admin_actions');
function aranalyzer_review($post_ID = 0)
{
if ($post_ID == 0) {
$post_ID = intval($_POST['postID']);
$arajax = 1;
}
// code by Sergio
global $wp_version;
if (version_compare($wp_version, '3.8', '<')) {
global $flag;
if ($flag != 1) {
$flag = 1;
return;
}
}
// End Sergio Code
// if (!session_id()) {
// session_start();
// }
// Get post information
$post_info = get_post($post_ID);
$title = $post_info->post_title;
/**
* We are removing the wptexturize before creating the content value to be send to api because it is changing single quotes
* with #8217 char and if makes the analysis fail.
*
* check
* http://codex.wordpress.org/Function_Reference/wptexturize
*/
remove_filter('the_content', 'wptexturize');
$content = apply_filters('the_content', $post_info->post_content);
add_filter('the_content', 'wptexturize');
$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);
if ($arajax == 1) {
echo $scoringObj;
}
// 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 (isset($value->suggestions->option)) {
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',
'scoring' => $scoring,
);
}
return $aColorText;
}
/*********************/
/* TinyMCE custom functions */
/*********************/
function tiny_mce_custom_plugins()
{
global $wp_version;
if (version_compare($wp_version, '3.9', '<')) {
return array('customdictionarycontextmenu' => MY_PLUGIN_PATH . '/customDictionaryContextMenu/editor_plugin.js');
} else {
return array('customdictionarycontextmenu' => MY_PLUGIN_PATH . '/customDictionaryContextMenu/plugin.js');
}
}
add_filter('mce_external_plugins', 'tiny_mce_custom_plugins');
/** plugin Tour * */
/**
* Adds a simple WordPress pointer to Settings menu
*/
function ar_enqueue_pointer_script_style($hook_suffix)
{
// Assume pointer shouldn't be shown
$enqueue_pointer_script_style = FALSE;
// Get array list of dismissed pointers for current user and convert it to array
$dismissed_pointers = explode(',', get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', TRUE));
// Check if our pointer is not among dismissed ones
if (!in_array('ar_settings_pointer', $dismissed_pointers)) {
$enqueue_pointer_script_style = TRUE;
// Add footer scripts using callback function
add_action('admin_print_footer_scripts', 'ar_pointer_print_scripts');
}
// Enqueue pointer CSS and JS files, if needed
if ($enqueue_pointer_script_style) {
wp_enqueue_style('wp-pointer');
wp_enqueue_script('wp-pointer');
}
}
add_action('admin_enqueue_scripts', 'ar_enqueue_pointer_script_style');
function ar_pointer_print_scripts()
{
$pointer_content = "
Atomic Engager!
";
$pointer_content .= "
Click here to connect your plugin to the Atomic Reach Scoring Engine.
";
?>
'' . __('Settings', 'atomicreach') . ''
), $links
);
}
add_action('wp_ajax_aranalyzer_ajax', 'aranalyzer_ajax_callback');
function aranalyzer_ajax_callback()
{
/*$postID = intval($_POST['postID']);
$post_info = get_post($postID);
$title = $post_info->post_title;*/
$_title = $_POST['arTitle'];
$_content = $_POST['arContent'];
/**
* We are removing the wptexturize before creating the content value to be send to api because it is changing single quotes
* with #8217 char and if makes the analysis fail.
*
* check
* http://codex.wordpress.org/Function_Reference/wptexturize
*/
/*remove_filter('the_content', 'wptexturize');
$content = apply_filters('the_content', $post_info->post_content);
add_filter('the_content', 'wptexturize');*/
// $ar_audience = get_post_meta($postID, '_ar_meta_audience_list', TRUE);
$ar_api_status = TRUE;
$ar_api_error = "";
// 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');
$segmentId = intval($_POST['segmentId']);
$audienceList = aranalyzer_api_getsophisticationbandlist($consumerKey, $secretKey);
// Store user selected targetAudience to show the pie image. HZ
foreach ($audienceList->sophisticatonBands AS $SophBand) {
if ($SophBand->id == $segmentId) {
$targetAud = strtoupper(str_replace('* ', '', $SophBand->name));
}
}
$host = API_HOST;
require_once(MY_PLUGIN_FOLDER . '/includes/ARClient.php');
$apiClient = New AR_Client($host, $consumerKey, $secretKey);
$apiClient->init();
$scoring = $apiClient->analyzePost($content, $title, $segmentId);
$isAjax = 1;
$audienceList = aranalyzer_api_getsophisticationbandlist($consumerKey, $secretKey);
ob_start();
require_once(MY_PLUGIN_FOLDER . '/custom/new-meta.php');
$data = ob_get_clean();
echo $data;
die(); // this is required to return a proper result
}
// Add admin bar menu
add_action('wp_before_admin_bar_render', 'aranalyzer_admin_bar_render');
function aranalyzer_admin_bar_render()
{
global $wp_admin_bar;
// we can add a submenu item too
$wp_admin_bar->add_menu(array(
'parent' => '',
'id' => 'atomicreach',
'title' => __('Atomic Engager'),
'href' => 'http://www.atomicreach.com?utm_source=WP%20Plugin&utm_medium=' . get_option('home') . '&utm_campaign=WP%20PLUGIN%20ADMINBAR'
));
$wp_admin_bar->add_menu(array(
'parent' => 'atomicreach',
'id' => 'atomicreach1',
'title' => __('Signup'),
'href' => 'http://score.atomicreach.com?utm_source=WP%20Plugin&utm_medium=' . get_option('home') .
'&utm_campaign=WP%20PLUGIN%20ADMINBAR',
'meta' => array(
'title' => __('Signup'),
'target' => '_blank',
'class' => 'ar_score'
),
));
$wp_admin_bar->add_menu(array(
'parent' => 'atomicreach',
'id' => 'atomicreach3',
'title' => __('Contact us'),
'href' => 'http://www.atomicreach.com/about-us/#contact?utm_source=WP%20Plugin&utm_medium=' . get_option('home') . '&utm_campaign=WP%20PLUGIN%20ADMINBAR',
'meta' => array(
'title' => __('Contact us'),
'target' => '_blank',
'class' => 'ar_contact_us'
),
));
}
/*** EXTRA FEED ***/
add_action('init', 'arfeed');
function arfeed()
{
$arRSS = get_option('aranalyzer_RSS');
if ($arRSS == 1)
add_feed('arfeed', 'arcustomRSS');
}
function arcustomRSS()
{
$arRSS = get_option('aranalyzer_RSS');
// get_template_part('feed', 'two');
// if ($arRSS == 1) {
global $more;
$more = -1;
$postCount = 150; // The number of posts to show in the feed
$posts = query_posts('showposts=' . $postCount);
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), TRUE);
echo '' . PHP_EOL;
echo '' . PHP_EOL;
echo '' . PHP_EOL;
echo '';
bloginfo_rss('name');
echo ' - Feed' . PHP_EOL;
echo '' . PHP_EOL;
echo '';
bloginfo_rss('url');
echo '' . PHP_EOL;
echo '';
bloginfo_rss('description');
echo '' . PHP_EOL;
echo '' . mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), FALSE) . '' . PHP_EOL;
echo '' . get_option('rss_language') . '' . PHP_EOL;
echo '' . apply_filters('rss_update_period', 'hourly') . '' . PHP_EOL;
echo '' . apply_filters('rss_update_frequency', '1') . '' . PHP_EOL;
do_action('rss2_head');
while (have_posts()) : the_post();
echo '';
echo '';
the_title_rss();
echo '' . PHP_EOL;
echo '';
the_permalink_rss();
echo '' . PHP_EOL;
echo '' . mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', TRUE), FALSE) . '' . PHP_EOL;
echo '';
the_author();
echo '' . PHP_EOL;
echo '';
the_guid();
echo '' . PHP_EOL;
echo '' . PHP_EOL;
echo '' . PHP_EOL;
rss_enclosure();
do_action('rss2_item');
echo '' . PHP_EOL;
endwhile;
echo '' . PHP_EOL;
echo '' . PHP_EOL;
// }
}
// TOP banner
function aranalyzer_admin_user_area_notice()
{
$screen = get_current_screen();
if (current_user_can('manage_options')) {
$consumerkey = get_option('aranalyzer_consumerkey');
$secretkey = get_option('aranalyzer_secretkey');
$aranalyzer_state_keys = get_option('aranalyzer_state_keys');
if ($screen->id !== 'toplevel_page_ar-analyzer-admin') {
if ((empty($consumerkey) || empty($secretkey)) || ($aranalyzer_state_keys === 'FALSE' || empty($aranalyzer_state_keys))) {
echo '
Almost Done!Click Here to setup the Atomic Engager plugin.