예제 #1
0
function jd_twit_comment($comment_id, $approved)
{
    $_t = get_comment($comment_id);
    $post_ID = $_t->comment_post_ID;
    $commenter = $_t->comment_author;
    $jd_tweet_this = get_post_meta($post_ID, '_jd_tweet_this', TRUE);
    if ($jd_tweet_this != 'no' && $_t->comment_approved == 1) {
        // comments only tweeted on posts which are tweeted
        $post_info = jd_post_info($post_ID);
        $sentence = '';
        $sentence = stripcslashes(get_option('comment-published-text'));
        if ($post_info['shortUrl'] != '') {
            $shrink = $post_info['shortUrl'];
        } else {
            $shrink = jd_shorten_link($post_info['postLink'], $post_info['postTitle'], $post_ID);
            store_url($post_ID, $shrink);
        }
        $sentence = jd_truncate_tweet($sentence, $post_info, $shrink, $post_ID);
        $sentence = str_replace("#commenter#", $commenter, $sentence);
        if ($sentence != '') {
            $sendToTwitter = jd_doTwitterAPIPost($sentence);
        }
    }
    return $post_ID;
}
예제 #2
0
function jd_twit($post_ID, $type = 'instant')
{
    if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
        wpt_mail("0: jd_twit running #{$post_ID}", "Post ID: {$post_ID} / {$type}");
        // DEBUG
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || wp_is_post_revision($post_ID)) {
        return $post_ID;
    }
    wpt_check_version();
    $jd_tweet_this = get_post_meta($post_ID, '_jd_tweet_this', true);
    $newpost = $oldpost = $is_inline_edit = false;
    $sentence = $template = '';
    if (get_option('wpt_inline_edits') != 1) {
        if (isset($_POST['_inline_edit']) || isset($_REQUEST['bulk_edit'])) {
            return;
        }
    } else {
        if (isset($_POST['_inline_edit']) || isset($_REQUEST['bulk_edit'])) {
            $is_inline_edit = true;
        }
    }
    if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
        wpt_mail("1: JD Tweet This Value: #{$post_ID}", "Tweet this: {$jd_tweet_this} /" . get_option('jd_tweet_default') . " / {$type}");
        // DEBUG
    }
    if (get_option('jd_tweet_default') == 0) {
        $test = $jd_tweet_this != 'no' ? true : false;
    } else {
        $test = $jd_tweet_this == 'yes' ? true : false;
    }
    if ($test) {
        // test switch: depend on default settings.
        $post_info = jd_post_info($post_ID);
        $media = wpt_post_with_media($post_ID, $post_info);
        if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true) {
            $auth = get_option('wpt_cotweet_lock') == 'false' || !get_option('wpt_cotweet_lock') ? $post_info['authId'] : get_option('wpt_cotweet_lock');
        } else {
            $auth = $post_info['authId'];
        }
        /* debug data */
        if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
            wpt_mail("2: POST Debug Data #{$post_ID}", "Post_Info: " . print_r($post_info, 1) . "\n\nPOST: " . print_r($_POST, 1) . " / {$type}");
        }
        if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true && function_exists('wpt_filter_post_info')) {
            $filter = wpt_filter_post_info($post_info);
            if ($filter == true) {
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("3a: Post filtered: #{$post_ID}", print_r($post_info, 1) . " / {$type}");
                }
                return false;
            }
        }
        /* Filter Tweet based on POST data -- allows custom filtering of unknown plug-ins, etc. */
        $filter = apply_filters('wpt_filter_post_data', false, $_POST);
        if ($filter) {
            return false;
        }
        $post_type = $post_info['postType'];
        if ($type == 'future' || get_post_meta($post_ID, 'wpt_publishing') == 'future') {
            $new = 1;
            // if this is a future action, then it should be published regardless of relationship
            if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                wpt_mail("4: Future post: #{$post_ID}", print_r($post_info, 1) . " / {$type}");
            }
            delete_post_meta($post_ID, 'wpt_publishing');
        } else {
            // if the post modified date and the post date are the same, this is new.
            // true if first date before or equal to last date
            $new = wpt_date_compare($post_info['_postModified'], $post_info['_postDate']);
        }
        // post is not previously published but has been backdated:
        // (post date is edited, but save option is 'publish')
        if ($new == 0 && (isset($_POST['edit_date']) && $_POST['edit_date'] == 1 && !isset($_POST['save']))) {
            $new = 1;
        }
        // can't catch posts that were set to a past date as a draft, then published.
        $post_type_settings = get_option('wpt_post_types');
        $post_types = array_keys($post_type_settings);
        if (in_array($post_type, $post_types)) {
            // identify whether limited by category/taxonomy
            $continue = wpt_category_limit($post_type, $post_info, $post_ID);
            if ($continue == false) {
                return;
            }
            // create Tweet and ID whether current action is edit or new
            $cT = get_post_meta($post_ID, '_jd_twitter', true);
            if (isset($_POST['_jd_twitter']) && $_POST['_jd_twitter'] != '') {
                $cT = $_POST['_jd_twitter'];
            }
            $customTweet = $cT != '' ? stripcslashes(trim($cT)) : '';
            // if ops is set and equals 'publish', this is being edited. Otherwise, it's a new post.
            if ($new == 0 || $is_inline_edit == true) {
                // if this is an old post and editing updates are enabled
                if (get_option('jd_tweet_default_edit') == 1) {
                    $jd_tweet_this = apply_filters('wpt_tweet_this_edit', $jd_tweet_this, $_POST);
                    if ($jd_tweet_this != 'yes') {
                        if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                            wpt_mail("3c: Tweet this: not equal to yes", "Exit // Post ID: {$post_ID}");
                            // DEBUG
                        }
                        return;
                    }
                }
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("4a: Edited post #{$post_ID}", "Tweet this: " . print_r($post_info, 1) . " / {$type}");
                    // DEBUG
                }
                if ($post_type_settings[$post_type]['post-edited-update'] == '1') {
                    $nptext = stripcslashes($post_type_settings[$post_type]['post-edited-text']);
                    $oldpost = true;
                }
            } else {
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("4b: New Post #{$post_ID}", "Tweet this: " . print_r($post_info, 1) . " / {$type}");
                    // DEBUG
                }
                if ($post_type_settings[$post_type]['post-published-update'] == '1') {
                    $nptext = stripcslashes($post_type_settings[$post_type]['post-published-text']);
                    $newpost = true;
                }
            }
            if ($newpost || $oldpost) {
                $template = $customTweet != "" ? $customTweet : $nptext;
                $sentence = jd_truncate_tweet($template, $post_info, $post_ID);
                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                    wpt_mail("5: Tweet Truncated #{$post_ID}", "Truncated Tweet: {$sentence} / {$template} / {$type}");
                    // DEBUG
                }
                if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true) {
                    $sentence2 = jd_truncate_tweet($template, $post_info, $post_ID, false, $auth);
                }
            }
            if ($sentence != '') {
                // WPT PRO //
                if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true) {
                    $wpt_selected_users = $post_info['wpt_authorized_users'];
                    /* set up basic author/main account values */
                    $auth_verified = wtt_oauth_test($auth, 'verify');
                    if (empty($wpt_selected_users) && get_option('jd_individual_twitter_users') == 1) {
                        $wpt_selected_users = $auth_verified ? array($auth) : array(false);
                    }
                    if ($post_info['wpt_cotweet'] == 1 || get_option('jd_individual_twitter_users') != 1) {
                        $wpt_selected_users['main'] = false;
                    }
                    // filter selected users before using
                    $wpt_selected_users = apply_filters('wpt_filter_users', $wpt_selected_users, $post_info);
                    if ($post_info['wpt_delay_tweet'] == 0 || $post_info['wpt_delay_tweet'] == '' || $post_info['wpt_no_delay'] == 'on') {
                        foreach ($wpt_selected_users as $acct) {
                            if (wtt_oauth_test($acct, 'verify')) {
                                $tweet = jd_doTwitterAPIPost($sentence2, $acct, $post_ID, $media);
                            }
                        }
                    } else {
                        foreach ($wpt_selected_users as $acct) {
                            if ($auth != $acct) {
                                $offset = rand(60, 480);
                                // offset by 1-8 minutes for additional users
                            } else {
                                $offset = 0;
                            }
                            if (wtt_oauth_test($acct, 'verify')) {
                                $time = apply_filters('wpt_schedule_delay', (int) $post_info['wpt_delay_tweet'] * 60, $acct);
                                $scheduled = wp_schedule_single_event(time() + $time + $offset, 'wpt_schedule_tweet_action', array('id' => $acct, 'sentence' => $sentence, 'rt' => 0, 'post_id' => $post_ID));
                                $tweet = true;
                                // if scheduled, return true.
                                if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                                    if ($acct) {
                                        $author_id = "#{$acct}";
                                    } else {
                                        $author_id = 'Main';
                                    }
                                    wpt_mail("7a: Tweet Scheduled for Auth ID {$author_id} #{$post_ID}", print_r(array('id' => $acct, 'sentence' => $sentence, 'rt' => 0, 'post_id' => $post_ID, 'timestamp' => time() + $time + $offset, 'current_time' => time(), 'timezone' => get_option('gmt_offset'), 'scheduled' => $scheduled, 'timestamp_string' => date('Y-m-d H:i:s', time() + $time + $offset), 'current_time_string' => date('Y-m-d H:i:s', time())), 1));
                                    // DEBUG
                                }
                            }
                        }
                    }
                    /* This cycle handles scheduling the automatic retweets */
                    if ($post_info['wpt_retweet_after'] != 0 && $post_info['wpt_no_repost'] != 'on') {
                        $repeat = $post_info['wpt_retweet_repeat'];
                        $first = true;
                        foreach ($wpt_selected_users as $acct) {
                            if (wtt_oauth_test($acct, 'verify')) {
                                for ($i = 1; $i <= $repeat; $i++) {
                                    switch ($i) {
                                        case 1:
                                            $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt');
                                            $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt');
                                            break;
                                        case 2:
                                            $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt2');
                                            $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt2');
                                            break;
                                        case 3:
                                            $prepend = get_option('wpt_prepend') == 1 ? '' : get_option('wpt_prepend_rt3');
                                            $append = get_option('wpt_prepend') != 1 ? '' : get_option('wpt_prepend_rt3');
                                            break;
                                    }
                                    if (get_option('wpt_custom_type') == 'template') {
                                        $retweet = jd_truncate_tweet(trim($prepend . $append), $post_info, $post_ID, true, $acct);
                                    } else {
                                        $retweet = jd_truncate_tweet(trim($prepend . $template . $append), $post_info, $post_ID, true, $acct);
                                    }
                                    // add original delay to schedule
                                    $delay = isset($post_info['wpt_delay_tweet']) ? (int) $post_info['wpt_delay_tweet'] * 60 : 0;
                                    /* Don't delay the first Tweet of the group */
                                    $offset = $first == true ? 0 : rand(60, 240);
                                    // delay each co-tweet by 1-4 minutes
                                    $time = apply_filters('wpt_schedule_retweet', $post_info['wpt_retweet_after'] * (60 * 60) * $i, $acct, $i, $post_info);
                                    wp_schedule_single_event(time() + $time + $offset + $delay, 'wpt_schedule_tweet_action', array('id' => $acct, 'sentence' => $retweet, 'rt' => $i, 'post_id' => $post_ID));
                                    $tweet = true;
                                    if ($i == 4) {
                                        break;
                                    }
                                }
                            }
                            $first = false;
                        }
                    }
                } else {
                    $tweet = jd_doTwitterAPIPost($sentence, false, $post_ID, $media);
                }
                // END WPT PRO //
                if ($tweet == false) {
                    update_option('wp_twitter_failure', '1');
                }
            }
        } else {
            if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
                wpt_mail("3c: Not a Tweeted post type #{$post_ID}", "Post_Info: " . print_r($post_info, 1) . " / {$type}");
            }
            return $post_ID;
        }
    }
    return $post_ID;
}
예제 #3
0
function wpt_set_comment_tweet($comment_id, $approved)
{
    $_t = get_comment($comment_id);
    $post_ID = $_t->comment_post_ID;
    $commenter = $_t->comment_author;
    $comment = $_t->comment_content;
    $user_id = $_t->user_id;
    $excerpt_length = get_option('jd_post_excerpt');
    $comment_excerpt = @mb_substr(strip_tags(strip_shortcodes($comment)), 0, $excerpt_length);
    $comment_date = $_t->comment_date;
    $dateformat = get_option('jd_date_format') == '' ? get_option('date_format') : get_option('jd_date_format');
    $comment_date = mysql2date($dateformat, $comment_date);
    $jd_tweet_this = get_post_meta($post_ID, '_jd_tweet_this', TRUE);
    $post_info = jd_post_info($post_ID);
    $sentence = '';
    $sentence = stripcslashes(get_option('comment-published-text'));
    $sentence = jd_truncate_tweet($sentence, $post_info, $post_ID);
    $sentence = str_replace("#commenter#", $commenter, $sentence);
    $sentence = str_replace("#comment#", $comment_excerpt, $sentence);
    $sentence = str_replace("#comment_date#", $comment_date, $sentence);
    if ($sentence != '') {
        $comment_tweet = apply_filters('wpt_filter_comment_tweet', $sentence, $_t);
        add_comment_meta($comment_id, 'wpt_comment_tweet', $comment_tweet, true);
    }
    if (user_can($user_id, 'moderate_comments') || $approved == 1) {
        wpt_twit_comment($_t);
    }
    return $post_ID;
}