Exemplo n.º 1
0
 static function download_tweet($status_id, $username = null)
 {
     if (empty(AKTT::$accounts)) {
         return false;
     }
     $account_found = $tweet = false;
     if (!empty($username)) {
         AKTT::get_social_accounts();
         foreach (AKTT::$accounts as $id => $account) {
             if ($username == $account->social_acct->name()) {
                 // proper account stored as $account
                 $account_found = true;
                 break;
             }
         }
         if (!$account_found) {
             $account = AKTT::$accounts[0];
             // use any account
         }
         $response = Social::instance()->service('twitter')->request($account->social_acct, '1.1/statuses/show/' . urlencode($t->id) . '.json', array('include_entities' => 1, 'include_rts' => 1));
         $content = $response->body();
         if ($content->result == 'success') {
             $tweets = $content->response;
             if (!$tweets || !is_array($tweets) || count($tweets) != 1) {
                 $tweet = $tweet[0];
             }
         }
     }
     return $tweet;
 }
Exemplo n.º 2
0
    function form($instance)
    {
        if (!AKTT::$enabled) {
            return '';
        }
        $account_options = array();
        AKTT::get_social_accounts();
        foreach (AKTT::$accounts as $account) {
            if ($account->option('enabled')) {
                $account_options[] = $account->social_acct->name();
            }
        }
        $defaults = array('title' => __('Recent Tweets', 'twitter-tools'), 'account' => '', 'count' => 5, 'include_rts' => 0, 'include_replies' => 0);
        foreach ($defaults as $k => $v) {
            if (!isset($instance[$k])) {
                $instance[$k] = $v;
            }
        }
        ?>
<p>
	<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title', 'twitter-tools');
        ?>
</label>
	<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" />
</p>
<p>
	<label for="<?php 
        echo $this->get_field_id('account');
        ?>
"><?php 
        _e('Account', 'twitter-tools');
        ?>
</label>
	<select name="<?php 
        echo $this->get_field_name('account');
        ?>
" id="<?php 
        echo $this->get_field_id('account');
        ?>
">
<?php 
        foreach ($account_options as $account_option) {
            ?>
		<option value="<?php 
            echo esc_attr($account_option);
            ?>
" <?php 
            selected($instance['account'], $account_option);
            ?>
><?php 
            echo esc_html($account_option);
            ?>
</option>
<?php 
        }
        ?>
	</select>
</p>
<p>
	<label for="<?php 
        echo $this->get_field_id('count');
        ?>
"><?php 
        _e('How Many Tweets?', 'twitter-tools');
        ?>
</label>
	<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']);
        ?>
" />
</p>
<p>
	<?php 
        _e('Include Retweets?', 'twitter-tools');
        ?>
	&nbsp;
	<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);
        ?>
 />
	<label for="<?php 
        echo $this->get_field_id('include_rts_1');
        ?>
"><?php 
        _e('Yes', 'twitter-tools');
        ?>
</label>
	&nbsp;
	<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);
        ?>
 />
	<label for="<?php 
        echo $this->get_field_id('include_rts_0');
        ?>
"><?php 
        _e('No', 'twitter-tools');
        ?>
</label>
</p>
<p>
	<?php 
        _e('Include Replies?', 'twitter-tools');
        ?>
	&nbsp;
	<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);
        ?>
 />
	<label for="<?php 
        echo $this->get_field_id('include_replies_1');
        ?>
"><?php 
        _e('Yes', 'twitter-tools');
        ?>
</label>
	&nbsp;
	<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);
        ?>
 />
	<label for="<?php 
        echo $this->get_field_id('include_replies_0');
        ?>
"><?php 
        _e('No', 'twitter-tools');
        ?>
</label>
</p>
<?php 
    }