|
1 <?php |
|
2 |
|
3 class AKTT_Widget extends WP_Widget { |
|
4 function __construct() { |
|
5 $title = __('Twitter Tools', 'twitter-tools'); |
|
6 $desc = __('Show recent tweets for a Twitter account.', 'twitter-tools'); |
|
7 // widget actual processes |
|
8 parent::__construct( |
|
9 'aktt-widget', |
|
10 $title, |
|
11 array( |
|
12 'classname' => 'aktt-widget', |
|
13 'description' => $desc |
|
14 ) |
|
15 ); |
|
16 } |
|
17 |
|
18 function form($instance) { |
|
19 if (!AKTT::$enabled) { |
|
20 return ''; |
|
21 } |
|
22 $account_options = array(); |
|
23 AKTT::get_social_accounts(); |
|
24 foreach (AKTT::$accounts as $account) { |
|
25 if ($account->option('enabled')) { |
|
26 $account_options[] = $account->social_acct->name(); |
|
27 } |
|
28 } |
|
29 $defaults = array( |
|
30 'title' => __('Recent Tweets', 'twitter-tools'), |
|
31 'account' => '', |
|
32 'count' => 5, |
|
33 'include_rts' => 0, |
|
34 'include_replies' => 0, |
|
35 ); |
|
36 foreach ($defaults as $k => $v) { |
|
37 if (!isset($instance[$k])) { |
|
38 $instance[$k] = $v; |
|
39 } |
|
40 } |
|
41 ?> |
|
42 <p> |
|
43 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'twitter-tools'); ?></label> |
|
44 <input type="text" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" class="widefat" /> |
|
45 </p> |
|
46 <p> |
|
47 <label for="<?php echo $this->get_field_id('account'); ?>"><?php _e('Account', 'twitter-tools'); ?></label> |
|
48 <select name="<?php echo $this->get_field_name('account'); ?>" id="<?php echo $this->get_field_id('account'); ?>"> |
|
49 <?php |
|
50 foreach ($account_options as $account_option) { |
|
51 ?> |
|
52 <option value="<?php echo esc_attr($account_option); ?>" <?php selected($instance['account'], $account_option); ?>><?php echo esc_html($account_option); ?></option> |
|
53 <?php |
|
54 } |
|
55 ?> |
|
56 </select> |
|
57 </p> |
|
58 <p> |
|
59 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('How Many Tweets?', 'twitter-tools'); ?></label> |
|
60 <input type="text" size="3" name="<?php echo $this->get_field_name('count'); ?>" id="<?php echo $this->get_field_id('count'); ?>" value="<?php echo esc_attr($instance['count']); ?>" /> |
|
61 </p> |
|
62 <p> |
|
63 <?php _e('Include Retweets?', 'twitter-tools'); ?> |
|
64 |
|
65 <input type="radio" name="<?php echo $this->get_field_name('include_rts'); ?>" id="<?php echo $this->get_field_id('include_rts_1'); ?>" value="1" <?php checked($instance['include_rts'], 1); ?> /> |
|
66 <label for="<?php echo $this->get_field_id('include_rts_1'); ?>"><?php _e('Yes', 'twitter-tools'); ?></label> |
|
67 |
|
68 <input type="radio" name="<?php echo $this->get_field_name('include_rts'); ?>" id="<?php echo $this->get_field_id('include_rts_0'); ?>" value="0" <?php checked($instance['include_rts'], 0); ?> /> |
|
69 <label for="<?php echo $this->get_field_id('include_rts_0'); ?>"><?php _e('No', 'twitter-tools'); ?></label> |
|
70 </p> |
|
71 <p> |
|
72 <?php _e('Include Replies?', 'twitter-tools'); ?> |
|
73 |
|
74 <input type="radio" name="<?php echo $this->get_field_name('include_replies'); ?>" id="<?php echo $this->get_field_id('include_replies_1'); ?>" value="1" <?php checked($instance['include_replies'], 1); ?> /> |
|
75 <label for="<?php echo $this->get_field_id('include_replies_1'); ?>"><?php _e('Yes', 'twitter-tools'); ?></label> |
|
76 |
|
77 <input type="radio" name="<?php echo $this->get_field_name('include_replies'); ?>" id="<?php echo $this->get_field_id('include_replies_0'); ?>" value="0" <?php checked($instance['include_replies'], 0); ?> /> |
|
78 <label for="<?php echo $this->get_field_id('include_replies_0'); ?>"><?php _e('No', 'twitter-tools'); ?></label> |
|
79 </p> |
|
80 <?php |
|
81 } |
|
82 |
|
83 function update($new_instance, $old_instance) { |
|
84 // processes widget options to be saved |
|
85 $instance = $old_instance; |
|
86 $instance['title'] = strip_tags($new_instance['title']); |
|
87 $instance['account'] = strip_tags($new_instance['account']); |
|
88 if (!($count = intval($new_instance['count']))) { |
|
89 $count = 1; |
|
90 } |
|
91 $instance['count'] = $count; |
|
92 $instance['include_rts'] = (int) $new_instance['include_rts']; |
|
93 $instance['include_replies'] = (int) $new_instance['include_replies']; |
|
94 return $instance; |
|
95 } |
|
96 |
|
97 function widget($args, $instance) { |
|
98 extract($args); |
|
99 $username = $instance['account']; |
|
100 $tweets = AKTT::get_tweets($instance); |
|
101 echo $before_widget.$before_title.$instance['title'].$after_title; |
|
102 include(AKTT_PATH.'views/widget.php'); |
|
103 echo $after_widget; |
|
104 } |
|
105 |
|
106 static function register() { |
|
107 register_widget('AKTT_Widget'); |
|
108 } |
|
109 } |
|
110 add_action('widgets_init', array('AKTT_Widget', 'register')); |