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 Writer', 'aranalyzer_metabox_setup', $type, 'side', 'high' ); } } add_action( 'admin_init', 'aranalyzer_metabox_init' ); /** * Registers an editor stylesheet for the theme. */ function wpdocs_theme_add_editor_styles() { add_editor_style( MY_PLUGIN_PATH . 'custom/style/inEditor.css' ); add_editor_style( MY_PLUGIN_PATH . 'custom/style/ionicons.min.css' ); } add_action( 'admin_init', 'wpdocs_theme_add_editor_styles' ); /* 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 ( isset( $_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' ); // } if ( empty( $consumerKey ) && empty( $secretKey ) ) { // grabs the HTML file to display the form. $doc = new DOMDocument(); $doc->loadHTMLFile( plugin_dir_path( __FILE__ ) . "custom/html/ftu.html" ); echo $doc->saveHTML(); } else { $doc = new DOMDocument(); $doc->loadHTMLFile( plugin_dir_path( __FILE__ ) . "custom/html/audSlider-score.html" ); echo $doc->saveHTML(); } } /*************************/ /* 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 Writer Configuration", "Atomic Writer", "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 ( isset( $analyzer_active ) ) { 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 * */ add_action( 'wp_ajax_aranalyzer_ajax', 'aranalyzer_ajax_callback' ); add_action( 'wp_ajax_awSignUpEmail_ajax', 'awSignUpEmail_ajax_callback' ); add_action( 'wp_ajax_awSignInEmail_ajax', 'awSignInEmail_ajax_callback' ); add_action( 'wp_ajax_awCheckScoreFreq_ajax', 'awCheckScoreFreq_ajax_callback' ); function awSignInEmail_ajax_callback() { if ( isset( $_POST['email'] ) ) { $email = $_POST['email']; } if ( isset( $_POST['pass'] ) ) { $pass = $_POST['pass']; } if ( isset( $email ) && isset( $pass ) ) { $host = API_HOST; require_once( MY_PLUGIN_FOLDER . '/includes/ARClient.php' ); $apiClient = New AR_Client( $host, '', '', $email, $pass ); if ( $apiClient->key != "" && $apiClient->secret != "" ) { update_option( 'aranalyzer_consumerkey', $apiClient->key ); update_option( 'aranalyzer_secretkey', $apiClient->secret ); aranalyzer_hatchbuckIntegration( $email ); echo "ok"; die(); } else { echo $apiClient->errorMessage; } } else { die( "error" ); } } function awSignUpEmail_ajax_callback() { if ( isset( $_POST['email'] ) ) { $email = $_POST['email']; } if ( isset( $_POST['pass'] ) ) { $pass = $_POST['pass']; } if ( isset( $email ) && isset( $pass ) ) { require_once( MY_PLUGIN_FOLDER . '/includes/ARClient.php' ); $apiClient = New AR_Client( API_HOST, "", "", "", "" ); $res = $apiClient->createAccount( $email, $pass ); if ( $res->status == 10 ) { update_option( 'aranalyzer_consumerkey', $res->data->consumerKey ); update_option( 'aranalyzer_secretkey', $res->data->consumerSecret ); update_option( 'aranalyzer_accountId', $res->data->accountId ); echo "ok-" . $res->data->accountId; aranalyzer_hatchbuckIntegration( $email ); die(); } else { echo json_encode( $res ); die(); } } else { die( "error" ); } } function aranalyzer_hatchbuckIntegration( $email ) { require_once( MY_PLUGIN_FOLDER . '/custom/class/Hatchbuck.php' ); $hb = new Hatchbuck(); $r = $hb->search( $email ); if ( ! $r ) { $data = '{ "emails": [ { "address": "' . $email . '" , "type": "Work"}], "status":{"id": "R000dFZxWHdUSDhFT3d5TGp4UXUzSmg3cEVuS2Iwa1ZyMFpIOHktNm1WbzE1"} }'; $addUser = $hb->addNewUser( $data ); if ( $addUser ) { $tag = '{"id": "RkNBVkhGcWtoTUt1a1RXM1lzVXlyTG9hNlNIY0FDOUIzWWVscWVRb1RMWTE1"}'; $hb->addTag( $email, $tag ); } } else { $tag = '{"id": "RkNBVkhGcWtoTUt1a1RXM1lzVXlyTG9hNlNIY0FDOUIzWWVscWVRb1RMWTE1"}'; $hb->addTag( $email, $tag ); } } function aranalyzer_ajax_callback() { update_user_option( get_current_user_id(), 'arLastScoreDate', date( 'Y-m-d' ) );// saves the latest date of when user scores. /*$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 = $_POST['segmentId']; $host = API_HOST; require_once( MY_PLUGIN_FOLDER . '/includes/ARClient.php' ); $apiClient = New AR_Client( $host, $consumerKey, $secretKey ); $apiClient->init(); $apiClient->setAppName("WP"); $scoring = $apiClient->analyzePost( $content, $title, NULL, NULL, $segmentId ); $atomicScore = $apiClient->getAtomicScore(); $output = get_score( $scoring, $segmentId, $atomicScore->atomicScore ); //call get_score // Return the String die( $output ); } function get_score( $result, $segmentId, $atomicScore ) { if ( $result->status == AR_Client::STATUS_OK ) { include( MY_PLUGIN_FOLDER . '/custom/class/meta.php' ); include( MY_PLUGIN_FOLDER . '/custom/html/popups.php' ); $Output = NEW meta( $result, $segmentId, $atomicScore ); $score = ''; // Display Score card. // $score .= '
'; $score .= $Output->displayScore(); // $score .= '
'; $score .= '
'; $score .= '
ADVANCED EDITS
'; $score .= '

Use the toggles to highlight content and make changes to improve your article score.

'; $score .= ''; $score .= '
'; $score .= '
'; $score .= '
'; $score .= $Output->titleOptimization(); $score .= '
'; $score .= '
'; $score .= '
'; $score .= $Output->contentSophistication(); $score .= '
'; $score .= '
'; $score .= '
'; $score .= $Output->readability(); $score .= '
'; // $score .= ''; $score .= '
'; $score .= '
'; $score .= ''; $score .= ''; return $score; } else { return "Error Message: " . $result->error . " Status Code: [" . $result->status . "]"; } } function awCheckScoreFreq_ajax_callback() { $screen = get_current_screen(); $numDaysLastScore = getDays(); $numDaysSinceActivation = getDays( TRUE ); $consumerkey = get_option( 'aranalyzer_consumerkey' ); $secretkey = get_option( 'aranalyzer_secretkey' ); // If user is signed in - check how active they are. if ( ! empty( $consumerkey ) || ! empty( $secretkey ) ) { if ( $numDaysSinceActivation >= 1 ) { // activated for more than a day but never scored any post. if (!$numDaysLastScore) { echo 20; } // activated the plugin more than a day but haven't score a post in last 3 days. elseif ( $numDaysLastScore > 3 ) { echo 22; } else{ echo 0;// see writer.js:6 } }else{ echo 0; } } die(); } // 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 ReachAtomic Writer' ), '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(); $numDaysLastScore = getDays(); $numDaysSinceActivation = getDays( TRUE ); $consumerkey = get_option( 'aranalyzer_consumerkey' ); $secretkey = get_option( 'aranalyzer_secretkey' ); $aranalyzer_state_keys = get_option( 'aranalyzer_state_keys' ); if ( current_user_can( 'manage_options' ) ) { // if user is not logged in - Walk them through to the sign up screen. if ( ! $consumerkey && ! $secretkey ) { if ( $screen->id != "edit-post" && $screen->id != 'post' ) { echo '

Let\'s go use AtomicWriter! Edit some articles now.

'; } elseif ( $screen->id == "edit-post" ) { echo '

Almost there! Click on any post title to setup AtomicWriter.

'; } elseif ( $screen->id == 'post' ) { echo '

One last step! Sign up to analyze this article.

'; } } } } add_action( 'admin_notices', 'aranalyzer_admin_user_area_notice' ); function atomic_engager_activate() { // custom feed update_option( 'aranalyzer_RSS', 1 ); update_option( 'aranalyzer_view', 1 ); update_option( 'arActivatedDate', date( 'Y-m-d' ) ); arfeed(); flush_rewrite_rules(); } register_activation_hook( __FILE__, 'atomic_engager_activate' ); function atomic_engager_deactivation() { flush_rewrite_rules(); delete_option( 'aranalyzer_tracking' ); delete_option( 'aranalyzer_view' ); delete_option( 'aranalyzer_RSS' ); delete_option( 'aranalyzer_consumerkey' ); delete_option( 'aranalyzer_secretkey' ); delete_option( 'aranalyzer_state_keys' ); delete_option( 'arActivatedDate' ); delete_user_option( get_current_user_id(), 'arLastScoreDate' ); } register_deactivation_hook( __FILE__, 'atomic_engager_deactivation' ); // Return number of days since user last score. function getDays( $activation = FALSE ) { $today = date( 'Y-m-d' ); // Today's date $lastScoreDate = get_user_option( 'arLastScoreDate' ); $activationDate = get_option( 'arActivatedDate' ); if ( $activation ) { if ( ! $activationDate ) { return FALSE; } $requestedDate = $activationDate; } else { if ( ! $lastScoreDate ) { return FALSE; } // return 0 if user never scored before. $requestedDate = $lastScoreDate; } $sec = strtotime( $today ) - strtotime( $requestedDate ); return secondsToTime( $sec ); } /** * Convert number of seconds into hours, minutes and seconds * and return an array containing those values * * @param integer $inputSeconds Number of seconds to parse * * @return array */ function secondsToTime( $inputSeconds ) { $secondsInAMinute = 60; $secondsInAnHour = 60 * $secondsInAMinute; $secondsInADay = 24 * $secondsInAnHour; // extract days $days = floor( $inputSeconds / $secondsInADay ); // extract hours $hourSeconds = $inputSeconds % $secondsInADay; $hours = floor( $hourSeconds / $secondsInAnHour ); // extract minutes $minuteSeconds = $hourSeconds % $secondsInAnHour; $minutes = floor( $minuteSeconds / $secondsInAMinute ); // extract the remaining seconds $remainingSeconds = $minuteSeconds % $secondsInAMinute; $seconds = ceil( $remainingSeconds ); // return the final array // $obj = array( // 'd' => (int) $days, // 'h' => (int) $hours, // 'm' => (int) $minutes, // 's' => (int) $seconds, // ); // return $obj; return $days; } ?>