Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////
- // multi instance twitter widget
- ///////////////////////////////////////////////////////////////////////////////
- function theme_twitter_js_handler($unique_id,$twitter_username,$twitter_count) {
- ?>
- <script type="text/javascript">
- <!--//--><![CDATA[//><!--
- function twitterCallback2(twitters) {
- var statusHTML = [];
- for (var i=0; i<twitters.length; i++){
- var username = twitters[i].user.screen_name;
- var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
- return '<a href="'+url+'">'+url+'</a>';
- }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
- return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
- });
- statusHTML.push('<li><span class="">'+status+'</span> <a style="font-size:85%" class="time" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'">'+relative_time(twitters[i].created_at)+'</a></li>');
- }
- document.getElementById('twitter_update_list_<?php echo $unique_id; ?>').innerHTML = statusHTML.join('');
- }
- function relative_time(time_value) {
- var values = time_value.split(" ");
- time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
- var parsed_date = Date.parse(time_value);
- var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
- var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
- delta = delta + (relative_to.getTimezoneOffset() * 60);
- if (delta < 60) {
- return 'less than a minute ago';
- } else if(delta < 120) {
- return 'about a minute ago';
- } else if(delta < (60*60)) {
- return (parseInt(delta / 60)).toString() + ' minutes ago';
- } else if(delta < (120*60)) {
- return 'about an hour ago';
- } else if(delta < (24*60*60)) {
- return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
- } else if(delta < (48*60*60)) {
- return '1 day ago';
- } else {
- return (parseInt(delta / 86400)).toString() + ' days ago';
- }
- }
- //-->!]]>
- </script>
- <script type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline/<?php echo $twitter_username; ?>.json?callback=twitterCallback2&count=<?php echo $twitter_count; ?>&include_rts=t"></script>
- <?php
- }
- class My_THEME_Twitter_Widget extends WP_Widget {
- function My_THEME_Twitter_Widget() {
- //Constructor
- parent::WP_Widget(false, $name = TEMPLATE_DOMAIN . ' | Twitter', array(
- 'description' => __('Display your latest twitter.', TEMPLATE_DOMAIN)
- ));
- }
- function widget($args, $instance) {
- // outputs the content of the widget
- extract($args); // Make before_widget, etc available.
- $twitter_username = $instance['twitter_username'];
- $twitter_count = $instance['twitter_count'];
- $twitter_title = empty($instance['title']) ? __('Twitter', TEMPLATE_DOMAIN) : apply_filters('widget_title', $instance['title']);
- $unique_id = $args['widget_id'];
- echo $before_widget;
- echo $before_title . $twitter_title . $after_title; ?>
- <ul class="twitterbox" id="twitter_update_list_<?php echo $unique_id; ?>">
- <?php echo theme_twitter_js_handler($unique_id,$twitter_username,$twitter_count); //Javascript output function ?>
- <li class="followme"><?php echo '<a style="font-weight: normal; letter-spacing: normal; font-size: 11px;" href="http://twitter.com/' . $twitter_username . '">'; ?><?php printf( __( 'Follow %1$s in Twitter', TEMPLATE_DOMAIN ), ucfirst($twitter_username) ); ?><?php echo '</a>'; ?>
- </li>
- </ul>
- <?php echo $after_widget;
- }
- function update($new_instance, $old_instance) {
- //update and save the widget
- return $new_instance;
- }
- function form($instance) {
- // Get the options into variables, escaping html characters on the way
- $twitter_username = $instance['twitter_username'];
- $twitter_title = $instance['title'];
- $twitter_count = $instance['twitter_count'];
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e("Twitter Title:",TEMPLATE_DOMAIN); ?></label>
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $twitter_title; ?>" />
- </p>
- <p><label for="<?php echo $this->get_field_id('twitter_username'); ?>">
- <?php echo __('Twitter ID:', TEMPLATE_DOMAIN)?></label>
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_username'); ?>" name="<?php echo $this->get_field_name('twitter_username'); ?>" value="<?php echo $twitter_username; ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('twitter_count'); ?>"><?php echo __('Number Of Tweets:', TEMPLATE_DOMAIN)?></label>
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('twitter_count'); ?>" name="<?php echo $this->get_field_name('twitter_count'); ?>" value="<?php echo $twitter_count; ?>" />
- </p>
- <?php
- }
- }
- register_widget('My_THEME_Twitter_Widget');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement