/**
 * Hook for the crons to fire and send tweets
 * @param  id $post_id
 * @param  string $name
 * @return void
 */
function ppp_share_post($post_id, $name)
{
    global $ppp_options, $ppp_social_settings, $ppp_share_settings, $ppp_twitter_oauth;
    // If we've already started to share this, don't share it again.
    // Compensates for wp-cron's race conditions
    if (get_transient('ppp_sharing' . $name) === 'true') {
        return;
    }
    // For 60 seconds, don't allow another share to go for this post
    set_transient('ppp_sharing' . $name, 'true', 60);
    $share_message = ppp_tw_build_share_message($post_id, $name);
    $name_parts = explode('_', $name);
    $post_meta = get_post_meta($post_id, '_ppp_tweets', true);
    $this_share = $post_meta[$name_parts[1]];
    $attachment_id = isset($this_share['attachment_id']) ? $this_share['attachment_id'] : false;
    if (empty($attachment_id) && !empty($this_share['image'])) {
        $media = $this_share['image'];
    } else {
        $media = ppp_post_has_media($post_id, 'tw', ppp_tw_use_media($post_id, $name_parts[1]), $attachment_id);
    }
    $status['twitter'] = ppp_send_tweet($share_message, $post_id, $media);
    if (!empty($status['twitter']->id_str)) {
        $post = get_post($post_id);
        $author_id = $post->post_author;
        $author_rt = get_user_meta($author_id, '_ppp_share_scheduled', true);
        if ($author_rt) {
            $twitter_user = new PPP_Twitter_User($author_id);
            $twitter_user->retweet($status['twitter']->id_str);
        }
    }
    if (isset($ppp_options['enable_debug']) && $ppp_options['enable_debug'] == '1') {
        update_post_meta($post_id, '_ppp-' . $name . '-status', $status);
    }
}
/**
 * Determines if the post should be shared on publish
 * @param  string $old_status The old post status
 * @param  string $new_status The new post status
 * @param  object $post       The Post Object
 * @return void               Shares the post
 */
function ppp_tw_share_on_publish($new_status, $old_status, $post)
{
    global $ppp_options;
    $from_meta = get_post_meta($post->ID, '_ppp_share_on_publish', true);
    $from_post = isset($_POST['_ppp_share_on_publish']);
    if (empty($from_meta) && empty($from_post)) {
        return;
    }
    // Determine if we're seeing the share on publish in meta or $_POST
    if ($from_meta && !$from_post) {
        $ppp_share_on_publish_text = get_post_meta($post->ID, '_ppp_share_on_publish_text', true);
        $use_media = get_post_meta($post->ID, '_ppp_share_on_publish_include_image', true);
    } else {
        $ppp_share_on_publish_text = isset($_POST['_ppp_share_on_publish_text']) ? $_POST['_ppp_share_on_publish_text'] : '';
        $use_media = isset($_POST['_ppp_share_on_publish_include_image']) ? $_POST['_ppp_share_on_publish_include_image'] : false;
    }
    $share_content = !empty($ppp_share_on_publish_text) ? $ppp_share_on_publish_text : ppp_tw_generate_share_content($post->ID, null, false);
    $share_content = apply_filters('ppp_share_content', $share_content, array('post_id' => $post->ID));
    $name = 'sharedate_0_' . $post->ID;
    $media = ppp_post_has_media($post->ID, 'tw', $use_media);
    $share_link = ppp_generate_link($post->ID, $name, true);
    $status['twitter'] = ppp_send_tweet($share_content . ' ' . $share_link, $post->ID, $media);
    if (!empty($status['twitter']->id_str)) {
        $author_id = $post->post_author;
        $author_rt = get_user_meta($author_id, '_ppp_share_on_publish', true);
        if ($author_rt) {
            $twitter_user = new PPP_Twitter_User($author_id);
            $twitter_user->retweet($status['twitter']->id_str);
        }
    }
    if (isset($ppp_options['enable_debug']) && $ppp_options['enable_debug'] == '1') {
        update_post_meta($post->ID, '_ppp-' . $name . '-status', $status);
    }
}