0
|
1 |
<?php |
|
2 |
/* |
|
3 |
Plugin Name: Twitter Widget |
|
4 |
Description: Twitter widget. |
|
5 |
Author: PEGO |
|
6 |
Version: 1.0 |
|
7 |
Author URI: |
|
8 |
*/ |
|
9 |
class twitter_widget extends WP_Widget { |
|
10 |
/*-----------------------------------------------------------------------------------*/ |
|
11 |
/* Widget Setup |
|
12 |
/*-----------------------------------------------------------------------------------*/ |
|
13 |
|
|
14 |
function twitter_Widget() { |
|
15 |
$widget_options = array( |
|
16 |
'classname' => 'twitter_widget', |
|
17 |
'description' => __('Custom twitter widget.','pego_tr') |
|
18 |
); |
|
19 |
|
|
20 |
$control_options = array( //dodama svoje incializirane mere |
|
21 |
'width' => 200, |
|
22 |
'height' => 400, |
|
23 |
'id_base' => 'twitter_widget' |
|
24 |
); |
|
25 |
$this->WP_Widget( 'twitter_widget', __('Twitter Widget','pego_tr'), $widget_options, $control_options ); |
|
26 |
} |
|
27 |
function widget( $args, $instance ) { |
|
28 |
|
|
29 |
extract( $args ); |
|
30 |
$title = apply_filters('widget_title', $instance['title'] ); |
|
31 |
$account = $instance['account']; |
|
32 |
$tweets_number = $instance['tweets_number']; |
|
33 |
|
|
34 |
echo $before_widget; |
|
35 |
// start |
|
36 |
echo '<div id="twitter_div">' |
|
37 |
.$before_title.$title.$after_title; |
|
38 |
echo '<ul id="twitter_update_list"></ul></div> |
|
39 |
<script type="text/javascript" src="'.get_template_directory_uri().'/js/blogger.js"></script>'; |
|
40 |
echo '<script type="text/javascript" src="https://api.twitter.com/1/statuses/user_timeline.json?screen_name='.$account.'&include_rts=true&count='.$tweets_number.'&callback=twitterCallback2"></script>'; |
|
41 |
|
|
42 |
|
|
43 |
echo $after_widget; |
|
44 |
} |
|
45 |
function form( $instance ) { |
|
46 |
/* Set the default values */ |
|
47 |
$defaults = array( |
|
48 |
'title' => __('Twitter','pego_tr'), |
|
49 |
'account' => 'designpego', |
|
50 |
'tweets_number' => '3', |
|
51 |
); |
|
52 |
$instance = wp_parse_args( (array) $instance, $defaults ); |
|
53 |
?> |
|
54 |
|
|
55 |
<label for="<?php echo $this->get_field_id( 'title' ); ?>"> |
|
56 |
Title: |
|
57 |
<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" |
|
58 |
name="<?php echo $this->get_field_name( 'title' ); ?>" |
|
59 |
value="<?php echo $instance['title']; ?>" /> |
|
60 |
</label> |
|
61 |
|
|
62 |
<label for="<?php echo $this->get_field_id( 'account' ); ?>"> |
|
63 |
Account: |
|
64 |
<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'account' ); ?>" |
|
65 |
name="<?php echo $this->get_field_name( 'account' ); ?>" |
|
66 |
value="<?php echo $instance['account']; ?>" /> |
|
67 |
</label> |
|
68 |
|
|
69 |
<label for="<?php echo $this->get_field_id( 'tweets_number' ); ?>"> |
|
70 |
Number of tweets: |
|
71 |
<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'tweets_number' ); ?>" |
|
72 |
name="<?php echo $this->get_field_name( 'tweets_number' ); ?>" |
|
73 |
value="<?php echo $instance['tweets_number']; ?>" /> |
|
74 |
</label> |
|
75 |
|
|
76 |
|
|
77 |
<?php |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
|
|
82 |
/* Adding widget to widgets_init and registering flickr widget */ |
|
83 |
add_action( 'widgets_init', 'twitter_widgets' ); |
|
84 |
|
|
85 |
function twitter_widgets() { |
|
86 |
register_widget( 'twitter_Widget' ); |
|
87 |
} |
|
88 |
?> |