コード例 #1
0
function dg_tw_publish_mega_tweet($tweets)
{
    global $dg_tw_queryes, $dg_tw_publish, $dg_tw_tags, $dg_tw_cats, $dg_tw_ft, $wpdb;
    $content = '<ul id="dg_tw_list_tweets">';
    foreach ($tweets as $tweet) {
        if (!dg_tw_iswhite($tweet)) {
            continue;
        }
        $str = dg_tw_regexText($tweet['text']);
        $str = preg_replace("/(?<!a href=\")(?<!src=\")((http|ftp)+(s)?:\\/\\/[^<>\\s]+)/i", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $str);
        $str = preg_replace('|@(\\w+)|', '<a href="http://twitter.com/$1" target="_blank">@$1</a>', $str);
        $str = preg_replace('|#(\\w+)|', '<a href="http://twitter.com/search?q=%23$1" target="_blank">#$1</a>', $str);
        $time_tweet = !empty($dg_tw_ft['tweettime']) ? ' - ' . date('Y-m-d H:i:s', strtotime($tweet['created_at'])) : '';
        $content .= '<li class="single_tweet">' . $str . $time_tweet . '</li>';
    }
    $content .= '</ul>';
    $tweet_title = empty($dg_tw_ft['title_format']) ? "Periodically tweets" : $dg_tw_ft['title_format'];
    $post = array('post_author' => $dg_tw_ft['author'], 'post_content' => $content, 'post_name' => dg_tw_slug($tweet_title), 'post_status' => strval($dg_tw_publish), 'post_title' => $tweet_title, 'tags_input' => $dg_tw_tags, 'post_type' => 'post', 'post_status' => strval($dg_tw_publish));
    $dg_tw_this_post = wp_insert_post($post, true);
    $tags = wp_get_post_tags($dg_tw_this_post);
    foreach ($tags as $tag) {
        switch ($tag->name) {
            case "SafetyDataGov":
                $category_id = get_cat_ID("safety");
                break;
            case "usdatagov":
                $category_id = get_cat_ID("developers");
                break;
            case "HealthDataGov":
                $category_id = get_cat_ID("health");
                break;
            case "energydatagov":
                $category_id = get_cat_ID("energy");
                break;
            default:
                $category_id = "";
        }
    }
    wp_set_post_categories($dg_tw_this_post, array($category_id));
    if ($dg_tw_this_post) {
        // adding acf values
        $username = dg_tw_tweet_user($tweet);
        $tweet_url = 'https://twitter.com/' . $username . '/status/' . $tweet->id_str;
        update_field("field_5176000e6c97e", $username, $dg_tw_this_post);
        update_field("field_517600256c97f", $username, $dg_tw_this_post);
        update_field("field_517600346c980", $tweet->user->profile_image_url_https, $dg_tw_this_post);
        update_field("field_517600586c981", $tweet_url, $dg_tw_this_post);
    }
    return 'true';
}
コード例 #2
0
function dg_tw_publish_tweet($tweet, $query = false)
{
    global $dg_tw_queryes, $dg_tw_publish, $dg_tw_tags, $dg_tw_cats, $dg_tw_ft, $wpdb;
    $post_type = isset($dg_tw_ft['post_type']) ? $dg_tw_ft['post_type'] : 'post';
    $dg_tw_start_post = get_default_post_to_edit($post_type, true);
    $username = dg_tw_tweet_user($tweet);
    $current_query = $query != false ? $query : array('tag' => '', 'value' => '');
    $querystr = "SELECT *\r\n\t\t\t\t\tFROM {$wpdb->postmeta}\r\n\t\t\t\t\tWHERE (meta_key = 'dg_tw_id' AND meta_value = '" . (int) $tweet->id_str . "')\r\n\t\t\t\t\tGROUP BY post_id";
    $postid = $wpdb->get_results($querystr);
    $author_tag = !empty($dg_tw_ft['authortag']) ? ',' . $username : '';
    $post_tags = htmlspecialchars($dg_tw_tags . ',' . $current_query['tag'] . $author_tag);
    if (!count($postid)) {
        $tweet_content = dg_tw_regexText($tweet->text);
        $post_title = filter_text($tweet, $dg_tw_ft['title_format'], "", $dg_tw_ft['maxtitle'], $dg_tw_ft['title_remove_url']);
        $post_content = filter_text($tweet, $dg_tw_ft['body_format'], $tweet_content);
        do_action('dg_tw_before_images_placed');
        if (strstr($post_content, '%tweet_images%') || $dg_tw_ft['featured_image']) {
            $images_list = dg_tw_put_attachments($dg_tw_start_post->ID, $tweet);
            if ($dg_tw_ft['featured_image']) {
                set_post_thumbnail($dg_tw_start_post->ID, end($images_list['ids']));
            }
            $post_content = str_replace('%tweet_images%', $images_list['html'], $post_content);
            do_action('dg_tw_images_placed');
        }
        $post = array('ID' => $dg_tw_start_post->ID, 'post_author' => $dg_tw_ft['author'], 'post_content' => $post_content, 'post_name' => dg_tw_slug($post_title), 'post_status' => strval($dg_tw_publish), 'post_title' => $post_title, 'post_category' => $dg_tw_cats, 'tags_input' => $post_tags, 'post_type' => $post_type, 'post_status' => strval($dg_tw_publish));
        $post = apply_filters('dg_tw_before_post_tweet', $post);
        $dg_tw_this_post = wp_insert_post($post, true);
        do_action('dg_tw_after_post_published', $dg_tw_this_post);
        if ($dg_tw_this_post) {
            //Set the format of a post
            $format = isset($dg_tw_ft['format']) ? $dg_tw_ft['format'] : 'standard';
            set_post_format($dg_tw_this_post, $format);
            /* POST METAS */
            $query_string = urlencode($current_query['value']);
            $query_string = $query != false ? $query['value'] : $query_string;
            add_post_meta($dg_tw_this_post, 'dg_tw_query', $query_string);
            add_post_meta($dg_tw_this_post, 'dg_tw_id', $tweet->id_str);
            add_post_meta($dg_tw_this_post, 'dg_tw_author', $username);
            add_post_meta($dg_tw_this_post, 'dg_tw_author_avatar', $tweet->user->profile_image_url);
            /* END POST METAS */
        }
    } else {
        return "already";
    }
    return "true";
}
コード例 #3
0
function filter_text($tweet, $format = "", $content = "", $limit = -1, $remove_url = false)
{
    global $dg_tw_queryes, $dg_tw_publish, $dg_tw_tags, $dg_tw_cats, $dg_tw_ft, $wpdb;
    $text = $content == "" ? $tweet->text : $content;
    $result = $format == "" ? $text : $format;
    $tweet_time = strtotime($tweet->created_at);
    $username = dg_tw_tweet_user($tweet);
    $tweet_url = 'https://twitter.com/' . $username . '/status/' . $tweet->id_str;
    $tweet_date = date($dg_tw_ft['date_format'], $tweet_time);
    $result = str_replace('%tweet%', $text, $result);
    $result = str_replace('%author%', $username, $result);
    $result = str_replace('%avatar_url%', $tweet->user->profile_image_url, $result);
    $result = str_replace('%tweet_url%', $tweet_url, $result);
    $result = str_replace('%tweet_date%', $tweet_date, $result);
    if ($remove_url) {
        $result = preg_replace("/(?<!a href=\")(?<!src=\")((http|ftp)+(s)?:\\/\\/[^<>\\s]+)/i", "", $result);
    }
    if ($limit != -1) {
        $result = substr($result, 0, $limit);
    }
    return $result;
}