예제 #1
0
파일: twitget.php 프로젝트: bencet/jetrowp
function show_recent_tweets()
{
    $options = get_option('twitget_settings');
    $get_data = false;
    if (!isset($options['twitter_data'])) {
        $get_data = true;
    }
    if (time() - $options['last_access'] > $options['time_limit'] * 60) {
        $get_data = true;
        $options['last_access'] = time();
        update_option('twitget_settings', $options);
    }
    unset($options);
    $options = get_option('twitget_settings');
    if ($get_data) {
        twitter_status();
    }
    unset($options);
    $options = get_option('twitget_settings');
    if (!is_array($options["twitter_data"])) {
        $tweets = json_decode($options['twitter_data'], true);
    } else {
        $tweets = $options['twitter_data'];
    }
    if (is_array($tweets) && isset($tweets) && isset($tweets[0]['user'])) {
        $limit = $options['number_of_tweets'];
        $image_url = $options['use_https_url'] ? $tweets[0]['user']['profile_image_url_https'] : $tweets[0]['user']['profile_image_url'];
        // {$profile_image}
        $twitter_username = $tweets[0]['user']['screen_name'];
        // {$user_twitter_name}
        $twitter_username_real = $tweets[0]['user']['name'];
        // {$user_real_name}
        $twitter_user_url = $tweets[0]['user']['url'];
        // {$url}
        $twitter_user_description = $tweets[0]['user']['description'];
        // {$user_description}
        $twitter_follower_count = $tweets[0]['user']['followers_count'];
        // {$follower_count}
        $twitter_friends_count = $tweets[0]['user']['friends_count'];
        // {$friends_count}
        $twitter_user_location = $tweets[0]['user']['location'];
        // {$user_location}
        $result = "";
        $custom_string = $options['custom_string'];
        $feed_string = twitget_get_substring($custom_string, "{\$tweets_start}", "{\$tweets_end}");
        $feed_whole_string = "";
        $i = 0;
        $tweet_date_array = array();
        foreach ($tweets as $tweet) {
            $tweet_text = $tweet['text'];
            $tweet_location = $tweet['place']['full_name'];
            $link_processed = "";
            if (isset($tweet['retweeted_status'])) {
                $first = current(explode(":", $tweet_text));
                $whole_tweet = $first . ": ";
                $whole_tweet .= $tweet['retweeted_status']['text'];
                $link_processed = process_links($whole_tweet, $options['links_new_window'], $options['show_full_url'], $tweet);
            } else {
                $link_processed = process_links($tweet['text'], $options['links_new_window'], $options['show_full_url'], $tweet);
            }
            $tweet_date_array[$i] = strtotime($tweet['created_at']);
            $tweet_id = $tweet['id_str'];
            if ($options["truncate_tweet"]) {
                $link_processed = twitget_truncate_tweet($link_processed, $options["truncate_tweet_size"], "...", true, true);
            }
            $feed_string_tmp = str_replace("{\$tweet_text}", $link_processed, $feed_string);
            $feed_string_tmp = str_replace("{\$tweet_time}", '<span class="' . $i . '_tweet_date"></span>', $feed_string_tmp);
            $feed_string_tmp = str_replace("{\$tweet_location}", $tweet_location, $feed_string_tmp);
            $feed_string_tmp = str_replace("{\$retweet}", '<a href="http://twitter.com/intent/retweet?tweet_id=' . $tweet_id . '" target="_blank">Retweet</a>', $feed_string_tmp);
            $feed_string_tmp = str_replace("{\$reply}", '<a href="http://twitter.com/intent/tweet?in_reply_to=' . $tweet_id . '" target="_blank">Reply</a>', $feed_string_tmp);
            $feed_string_tmp = str_replace("{\$favorite}", '<a href="http://twitter.com/intent/favorite?tweet_id=' . $tweet_id . '" target="_blank">Favorite</a>', $feed_string_tmp);
            $feed_string_tmp = str_replace("{\$retweet_link}", "http://twitter.com/intent/retweet?tweet_id=" . $tweet_id, $feed_string_tmp);
            $feed_string_tmp = str_replace("{\$reply_link}", "http://twitter.com/intent/tweet?in_reply_to=" . $tweet_id, $feed_string_tmp);
            $feed_string_tmp = str_replace("{\$favorite_link}", "http://twitter.com/intent/favorite?tweet_id=" . $tweet_id, $feed_string_tmp);
            $feed_string_tmp = str_replace("{\$tweet_link}", "http://twitter.com/" . $options['twitter_username'] . "/statuses/" . $tweet_id, $feed_string_tmp);
            if (isset($tweet['retweeted_status'])) {
                $profile_url = $tweet["retweeted_status"]["user"]["profile_image_url"];
                // 48x48 px
                $profile_73_url = str_replace("_normal", "_bigger", $profile_url);
                // 73x73 px
                $profile_24_url = str_replace("_normal", "_mini", $profile_url);
                // 24x24 px
                $profile_original_url = str_replace("_normal", "", $profile_url);
                // Original size
                $feed_string_tmp = str_replace("{\$profile_image_normal_url}", $profile_url, $feed_string_tmp);
                $feed_string_tmp = str_replace("{\$profile_image_bigger_url}", $profile_73_url, $feed_string_tmp);
                $feed_string_tmp = str_replace("{\$profile_image_mini_url}", $profile_24_url, $feed_string_tmp);
                $feed_string_tmp = str_replace("{\$profile_image_original_url}", $profile_original_url, $feed_string_tmp);
            } else {
                $profile_url = $tweet['user']['profile_image_url'];
                // 48x48 px
                $profile_73_url = str_replace("_normal", "_bigger", $profile_url);
                // 73x73 px
                $profile_24_url = str_replace("_normal", "_mini", $profile_url);
                // 24x24 px
                $profile_original_url = str_replace("_normal", "", $profile_url);
                // Original size
                $feed_string_tmp = str_replace("{\$profile_image_normal_url}", $profile_url, $feed_string_tmp);
                $feed_string_tmp = str_replace("{\$profile_image_bigger_url}", $profile_73_url, $feed_string_tmp);
                $feed_string_tmp = str_replace("{\$profile_image_mini_url}", $profile_24_url, $feed_string_tmp);
                $feed_string_tmp = str_replace("{\$profile_image_original_url}", $profile_original_url, $feed_string_tmp);
            }
            $feed_whole_string .= $feed_string_tmp;
            if ($i == $limit - 1) {
                break;
            }
            $i = $i + 1;
        }
        $feed_start = "{\$tweets_start}";
        $feed_end = "{\$tweets_end}";
        $start_pos = strrpos($custom_string, $feed_start);
        $end_pos = strrpos($custom_string, $feed_end) + strlen($feed_end);
        $tag_length = $end_pos - $start_pos + 1;
        $feed_string = substr_replace($custom_string, $feed_whole_string, $start_pos, $tag_length);
        $feed_string = str_replace("{\$profile_image}", $image_url, $feed_string);
        $feed_string = str_replace("{\$user_twitter_name}", $twitter_username, $feed_string);
        $feed_string = str_replace("{\$user_real_name}", $twitter_username_real, $feed_string);
        $feed_string = str_replace("{\$url}", $twitter_user_url, $feed_string);
        $feed_string = str_replace("{\$user_description}", $twitter_user_description, $feed_string);
        $feed_string = str_replace("{\$follower_count}", $twitter_follower_count, $feed_string);
        $feed_string = str_replace("{\$friends_count}", $twitter_friends_count, $feed_string);
        $feed_string = str_replace("{\$user_location}", $twitter_user_location, $feed_string);
        $feed_string = str_replace("{\$tweet_location}", $tweet_location, $feed_string);
        $profile_url = $image_url;
        $profile_73_url = str_replace("_normal", "_bigger", $profile_url);
        // 73x73 px
        $profile_24_url = str_replace("_normal", "_mini", $profile_url);
        // 24x24 px
        $profile_original_url = str_replace("_normal", "", $profile_url);
        // Original size
        $feed_string = str_replace("{\$profile_image_normal_url}", $profile_url, $feed_string);
        $feed_string = str_replace("{\$profile_image_bigger_url}", $profile_73_url, $feed_string);
        $feed_string = str_replace("{\$profile_image_mini_url}", $profile_24_url, $feed_string);
        $feed_string = str_replace("{\$profile_image_original_url}", $profile_original_url, $feed_string);
        $result = $feed_string;
        if (isset($tweets['errors'][0]['code'])) {
            $result = $options['before_tweets_html'] . '<p>The Twitter feed is currently unavailable or the username does not exist.</p>';
        }
        if ($options['show_powered_by']) {
            $result = $result . '<p>Powered by <a href="http://wpplugz.is-leet.com">wpPlugz</a></p>';
        }
    } else {
        $result = "Twitter outputted an error: <br />";
        $result .= $tweets['errors'][0]['message'] . ".";
    }
    echo $result;
    $time_format = $options['time_format'];
    $moment_js_time = twitget_convert_from_php_to_momentjs($time_format);
    ?>

		<script type="text/javascript">
			jQuery(document).ready(function() { 
				<?php 
    if (strlen($options['language']) > 0) {
        ?>
					moment.lang('<?php 
        echo $options['language'];
        ?>
');
				<?php 
    } else {
        ?>
					moment.lang('en');
				<?php 
    }
    ?>
				<?php 
    if (!empty($tweet_date_array)) {
        foreach ($tweet_date_array as $c => $val) {
            ?>
				var date_val_<?php 
            echo $c;
            ?>
 = <?php 
            echo $val;
            ?>
;
				<?php 
            if ($options["show_relative_time"]) {
                ?>
				var date_<?php 
                echo $c;
                ?>
 = moment.unix(date_val_<?php 
                echo $c;
                ?>
).fromNow();
				<?php 
            } else {
                ?>
				var date_<?php 
                echo $c;
                ?>
 = moment.unix(date_val_<?php 
                echo $c;
                ?>
).format("<?php 
                echo $moment_js_time;
                ?>
");
				<?php 
            }
            ?>
				jQuery(".<?php 
            echo $c;
            ?>
_tweet_date").html(date_<?php 
            echo $c;
            ?>
);
				<?php 
        }
    }
    ?>
			});
		</script>

<?php 
}
예제 #2
0
    echo $tracklist;
    ?>
			</div>
			
			<hr class="small-line special" />
		<?php 
}
?>
				
		<?php 
if (!empty($credits)) {
    ?>
			<div class="credits">
				<p class="title">CREDITS</p>
				<p><?php 
    echo process_links($credits);
    ?>
</p>
			</div>
			
			<hr class="small-line special" />
		<?php 
}
?>
		
		<?php 
if (!empty($links)) {
    ?>
			<div class="links">
				<p class="title">LINKS</p>
				<?php