web/wp-content/themes/selecta/ocmx/widgets/twitter-widget.php
author ymh <ymh.work@gmail.com>
Mon, 22 Mar 2010 16:36:28 +0100
changeset 5 ac511f1ccc8e
parent 1 0d28b7c10758
permissions -rw-r--r--
add hgignore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
0d28b7c10758 First commit
ymh
parents:
diff changeset
     1
<?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
     2
class ocmx_twitter_widget extends WP_Widget {
0d28b7c10758 First commit
ymh
parents:
diff changeset
     3
    /** constructor */
0d28b7c10758 First commit
ymh
parents:
diff changeset
     4
    function ocmx_twitter_widget() {
0d28b7c10758 First commit
ymh
parents:
diff changeset
     5
        parent::WP_Widget(false, $name = 'OCMX Twitter Stream', $widget_options = 'Display your latest Flickr Photos.', $control_options ="TESTTESTETETETETE");	
0d28b7c10758 First commit
ymh
parents:
diff changeset
     6
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
     7
0d28b7c10758 First commit
ymh
parents:
diff changeset
     8
    /** @see WP_Widget::widget */
0d28b7c10758 First commit
ymh
parents:
diff changeset
     9
    function widget($args, $instance) {		
0d28b7c10758 First commit
ymh
parents:
diff changeset
    10
        extract( $args );
0d28b7c10758 First commit
ymh
parents:
diff changeset
    11
        $twitter_key = $instance["twitter_id"];
0d28b7c10758 First commit
ymh
parents:
diff changeset
    12
        $twitter_count = $instance["twitter_count"];
0d28b7c10758 First commit
ymh
parents:
diff changeset
    13
        $twitter_src  = "http://twitter.com/statuses/user_timeline/".$twitter_key.".json?callback=twitterCallback2&amp;count=".$twitter_count;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    14
        ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    15
			<?php echo $before_widget; ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    16
				<?php echo $before_title?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    17
	                <a href="http://twitter.com/<?php echo $twitter_key; ?>" target="_blank" rel="nofollow">
0d28b7c10758 First commit
ymh
parents:
diff changeset
    18
						<?php echo $instance['title']; ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    19
					</a>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    20
				<?php echo $after_title; ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    21
                <ul id="twitter_update_list" class="rc_list">
0d28b7c10758 First commit
ymh
parents:
diff changeset
    22
                	<li>...loading Twitter Stream</li>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    23
                </ul>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    24
                <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    25
                <script type="text/javascript" src="<?php echo $twitter_src ?>"></script>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    26
			<?php echo $after_widget; ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    27
        <?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
    28
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
    29
0d28b7c10758 First commit
ymh
parents:
diff changeset
    30
    /** @see WP_Widget::update */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    31
    function update($new_instance, $old_instance) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
    32
        return $new_instance;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    33
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
    34
0d28b7c10758 First commit
ymh
parents:
diff changeset
    35
    /** @see WP_Widget::form */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    36
    function form($instance) {				
0d28b7c10758 First commit
ymh
parents:
diff changeset
    37
        $title = esc_attr($instance["title"]);
0d28b7c10758 First commit
ymh
parents:
diff changeset
    38
        $twitter_id = esc_attr($instance["twitter_id"]);
0d28b7c10758 First commit
ymh
parents:
diff changeset
    39
        $twitter_count = esc_attr($instance["twitter_count"]);
0d28b7c10758 First commit
ymh
parents:
diff changeset
    40
		
0d28b7c10758 First commit
ymh
parents:
diff changeset
    41
        ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    42
            <p><label for="<?php echo $this->get_field_id('title'); ?>">Title<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    43
            <p><label for="<?php echo $this->get_field_id('twitter_id'); ?>">Twitter ID<input class="widefat" id="<?php echo $this->get_field_id('twitter_id'); ?>" name="<?php echo $this->get_field_name('twitter_id'); ?>" type="text" value="<?php echo $twitter_id; ?>" /></label></p>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    44
			<p>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    45
            	<label for="<?php echo $this->get_field_id('twitter_count'); ?>">Tweet Count
0d28b7c10758 First commit
ymh
parents:
diff changeset
    46
                <select size="1" class="widefat" id="<?php echo $this->get_field_id('twitter_count'); ?>" name="<?php echo $this->get_field_name('twitter_count'); ?>">
0d28b7c10758 First commit
ymh
parents:
diff changeset
    47
                    <option <?php if($twitter_count == "1") : ?>selected="selected"<?php endif; ?> value="1">1</option>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    48
                    <option <?php if($twitter_count == "2") : ?>selected="selected"<?php endif; ?> value="2">2</option>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    49
                    <option <?php if($twitter_count == "4") : ?>selected="selected"<?php endif; ?> value="4">4</option>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    50
                    <option <?php if($twitter_count == "6") : ?>selected="selected"<?php endif; ?> value="6">6</option>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    51
                    <option <?php if($twitter_count == "8") : ?>selected="selected"<?php endif; ?> value="8">8</option>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    52
                    <option <?php if($twitter_count == "10") : ?>selected="selected"<?php endif; ?> value="10">10</option>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    53
                </select>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    54
			</p>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    55
        <?php 
0d28b7c10758 First commit
ymh
parents:
diff changeset
    56
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
    57
0d28b7c10758 First commit
ymh
parents:
diff changeset
    58
} // class FooWidget
0d28b7c10758 First commit
ymh
parents:
diff changeset
    59
0d28b7c10758 First commit
ymh
parents:
diff changeset
    60
//This sample widget can then be registered in the widgets_init hook:
0d28b7c10758 First commit
ymh
parents:
diff changeset
    61
0d28b7c10758 First commit
ymh
parents:
diff changeset
    62
// register FooWidget widget
0d28b7c10758 First commit
ymh
parents:
diff changeset
    63
add_action('widgets_init', create_function('', 'return register_widget("ocmx_twitter_widget");'));
0d28b7c10758 First commit
ymh
parents:
diff changeset
    64
0d28b7c10758 First commit
ymh
parents:
diff changeset
    65
?>