Advertisement
Guest User

PHP Tweets

a guest
Jan 16th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 39.12 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: Twitter Widget Pro
  4.  * Plugin URI: http://xavisys.com/wordpress-plugins/wordpress-twitter-widget/
  5.  * Description: A widget that properly handles twitter feeds, including @username, #hashtag, and link parsing.  It can even display profile images for the users.  Requires PHP5.
  6.  * Version: 2.3.3
  7.  * Author: Aaron D. Campbell
  8.  * Author URI: http://xavisys.com/
  9.  * License: GPLv2 or later
  10.  * Text Domain: twitter-widget-pro
  11.  */
  12.  
  13. /*
  14.     Copyright 2006-current  Aaron D. Campbell  ( email : wp_plugins@xavisys.com )
  15.  
  16.     This program is free software; you can redistribute it and/or modify
  17.     it under the terms of the GNU General Public License as published by
  18.     the Free Software Foundation; either version 2 of the License, or
  19.     ( at your option ) any later version.
  20.  
  21.     This program is distributed in the hope that it will be useful,
  22.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24.     GNU General Public License for more details.
  25.  
  26.     You should have received a copy of the GNU General Public License
  27.     along with this program; if not, write to the Free Software
  28.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  29. */
  30.  
  31. require_once( 'tlc-transients.php' );
  32. require_once( 'xavisys-plugin-framework.php' );
  33. define( 'TWP_VERSION', '2.3.3' );
  34.  
  35. /**
  36.  * WP_Widget_Twitter_Pro is the class that handles the main widget.
  37.  */
  38. class WP_Widget_Twitter_Pro extends WP_Widget {
  39.     public function WP_Widget_Twitter_Pro () {
  40.         $this->_slug = 'twitter-widget-pro';
  41.         $wpTwitterWidget = wpTwitterWidget::getInstance();
  42.         $widget_ops = array(
  43.             'classname' => 'widget_twitter',
  44.             'description' => __( 'Follow a Twitter Feed', $wpTwitterWidget->get_slug() )
  45.         );
  46.         $control_ops = array(
  47.             'width' => 400,
  48.             'height' => 350,
  49.             'id_base' => 'twitter'
  50.         );
  51.         $name = __( 'Twitter Widget Pro', $wpTwitterWidget->get_slug() );
  52.  
  53.         $this->WP_Widget( 'twitter', $name, $widget_ops, $control_ops );
  54.     }
  55.  
  56.     private function _getInstanceSettings ( $instance ) {
  57.         $wpTwitterWidget = wpTwitterWidget::getInstance();
  58.         return $wpTwitterWidget->getSettings( $instance );
  59.     }
  60.  
  61.     public function form( $instance ) {
  62.         $instance = $this->_getInstanceSettings( $instance );
  63.         $wpTwitterWidget = wpTwitterWidget::getInstance();
  64. ?>
  65.             <p>
  66.                 <label for="<?php echo $this->get_field_id( 'username' ); ?>"><?php _e( 'Twitter username:', $this->_slug ); ?></label>
  67.                 <input class="widefat" id="<?php echo $this->get_field_id( 'username' ); ?>" name="<?php echo $this->get_field_name( 'username' ); ?>" type="text" value="<?php esc_attr_e( $instance['username'] ); ?>" />
  68.             </p>
  69.             <p>
  70.                 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Give the feed a title ( optional ):', $this->_slug ); ?></label>
  71.                 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php esc_attr_e( $instance['title'] ); ?>" />
  72.             </p>
  73.             <p>
  74.                 <label for="<?php echo $this->get_field_id( 'items' ); ?>"><?php _e( 'How many items would you like to display?', $this->_slug ); ?></label>
  75.                 <select id="<?php echo $this->get_field_id( 'items' ); ?>" name="<?php echo $this->get_field_name( 'items' ); ?>">
  76.                     <?php
  77.                         for ( $i = 1; $i <= 20; ++$i ) {
  78.                             echo "<option value='$i' ". selected( $instance['items'], $i, false ). ">$i</option>";
  79.                         }
  80.                     ?>
  81.                 </select>
  82.             </p>
  83.             <p>
  84.                 <label for="<?php echo $this->get_field_id( 'avatar' ); ?>"><?php _e( 'Display profile image?', $this->_slug ); ?></label>
  85.                 <select id="<?php echo $this->get_field_id( 'avatar' ); ?>" name="<?php echo $this->get_field_name( 'avatar' ); ?>">
  86.                     <option value=""<?php selected( $instance['avatar'], '' ) ?>><?php _e( 'Do not show', $this->_slug ); ?></option>
  87.                     <option value="mini"<?php selected( $instance['avatar'], 'mini' ) ?>><?php _e( 'Mini - 24px by 24px', $this->_slug ); ?></option>
  88.                     <option value="normal"<?php selected( $instance['avatar'], 'normal' ) ?>><?php _e( 'Normal - 48px by 48px', $this->_slug ); ?></option>
  89.                     <option value="bigger"<?php selected( $instance['avatar'], 'bigger' ) ?>><?php _e( 'Bigger - 73px by 73px', $this->_slug ); ?></option>
  90.                     <option value="original"<?php selected( $instance['avatar'], 'original' ) ?>><?php _e( 'Original', $this->_slug ); ?></option>
  91.                 </select>
  92.             </p>
  93.             <p>
  94.                 <input class="checkbox" type="checkbox" value="true" id="<?php echo $this->get_field_id( 'showretweets' ); ?>" name="<?php echo $this->get_field_name( 'showretweets' ); ?>"<?php checked( $instance['showretweets'], 'true' ); ?> />
  95.                 <label for="<?php echo $this->get_field_id( 'showretweets' ); ?>"><?php _e( 'Include retweets', $this->_slug ); ?></label>
  96.             </p>
  97.             <p>
  98.                 <input class="checkbox" type="checkbox" value="true" id="<?php echo $this->get_field_id( 'hidereplies' ); ?>" name="<?php echo $this->get_field_name( 'hidereplies' ); ?>"<?php checked( $instance['hidereplies'], 'true' ); ?> />
  99.                 <label for="<?php echo $this->get_field_id( 'hidereplies' ); ?>"><?php _e( 'Hide @replies', $this->_slug ); ?></label>
  100.             </p>
  101.             <p>
  102.                 <input class="checkbox" type="checkbox" value="true" id="<?php echo $this->get_field_id( 'hidefrom' ); ?>" name="<?php echo $this->get_field_name( 'hidefrom' ); ?>"<?php checked( $instance['hidefrom'], 'true' ); ?> />
  103.                 <label for="<?php echo $this->get_field_id( 'hidefrom' ); ?>"><?php _e( 'Hide sending applications', $this->_slug ); ?></label>
  104.             </p>
  105.             <p>
  106.                 <input type="hidden" value="false" name="<?php echo $this->get_field_name( 'showintents' ); ?>" />
  107.                 <input class="checkbox" type="checkbox" value="true" id="<?php echo $this->get_field_id( 'showintents' ); ?>" name="<?php echo $this->get_field_name( 'showintents' ); ?>"<?php checked( $instance['showintents'], 'true' ); ?> />
  108.                 <label for="<?php echo $this->get_field_id( 'showintents' ); ?>"><?php _e( 'Show Tweet Intents (reply, retweet, favorite)', $this->_slug ); ?></label>
  109.             </p>
  110.             <p>
  111.                 <input type="hidden" value="false" name="<?php echo $this->get_field_name( 'showfollow' ); ?>" />
  112.                 <input class="checkbox" type="checkbox" value="true" id="<?php echo $this->get_field_id( 'showfollow' ); ?>" name="<?php echo $this->get_field_name( 'showfollow' ); ?>"<?php checked( $instance['showfollow'], 'true' ); ?> />
  113.                 <label for="<?php echo $this->get_field_id( 'showfollow' ); ?>"><?php _e( 'Show Follow Link', $this->_slug ); ?></label>
  114.             </p>
  115.             <p>
  116.                 <label for="<?php echo $this->get_field_id( 'errmsg' ); ?>"><?php _e( 'What to display when Twitter is down ( optional ):', $this->_slug ); ?></label>
  117.                 <input class="widefat" id="<?php echo $this->get_field_id( 'errmsg' ); ?>" name="<?php echo $this->get_field_name( 'errmsg' ); ?>" type="text" value="<?php esc_attr_e( $instance['errmsg'] ); ?>" />
  118.             </p>
  119.             <p>
  120.                 <label for="<?php echo $this->get_field_id( 'fetchTimeOut' ); ?>"><?php _e( 'Number of seconds to wait for a response from Twitter ( default 2 ):', $this->_slug ); ?></label>
  121.                 <input class="widefat" id="<?php echo $this->get_field_id( 'fetchTimeOut' ); ?>" name="<?php echo $this->get_field_name( 'fetchTimeOut' ); ?>" type="text" value="<?php esc_attr_e( $instance['fetchTimeOut'] ); ?>" />
  122.             </p>
  123.             <p>
  124.                 <label for="<?php echo $this->get_field_id( 'showts' ); ?>"><?php _e( 'Show date/time of Tweet ( rather than 2 ____ ago ):', $this->_slug ); ?></label>
  125.                 <select id="<?php echo $this->get_field_id( 'showts' ); ?>" name="<?php echo $this->get_field_name( 'showts' ); ?>">
  126.                     <option value="0" <?php selected( $instance['showts'], '0' ); ?>><?php _e( 'Always', $this->_slug );?></option>
  127.                     <option value="3600" <?php selected( $instance['showts'], '3600' ); ?>><?php _e( 'If over an hour old', $this->_slug );?></option>
  128.                     <option value="86400" <?php selected( $instance['showts'], '86400' ); ?>><?php _e( 'If over a day old', $this->_slug );?></option>
  129.                     <option value="604800" <?php selected( $instance['showts'], '604800' ); ?>><?php _e( 'If over a week old', $this->_slug );?></option>
  130.                     <option value="2592000" <?php selected( $instance['showts'], '2592000' ); ?>><?php _e( 'If over a month old', $this->_slug );?></option>
  131.                     <option value="31536000" <?php selected( $instance['showts'], '31536000' ); ?>><?php _e( 'If over a year old', $this->_slug );?></option>
  132.                     <option value="-1" <?php selected( $instance['showts'], '-1' ); ?>><?php _e( 'Never', $this->_slug );?></option>
  133.                 </select>
  134.             </p>
  135.             <p>
  136.                 <label for="<?php echo $this->get_field_id( 'dateFormat' ); ?>"><?php echo sprintf( __( 'Format to dispaly the date in, uses <a href="%s">PHP date()</a> format:', $this->_slug ), 'http://php.net/date' ); ?></label>
  137.                 <input class="widefat" id="<?php echo $this->get_field_id( 'dateFormat' ); ?>" name="<?php echo $this->get_field_name( 'dateFormat' ); ?>" type="text" value="<?php esc_attr_e( $instance['dateFormat'] ); ?>" />
  138.             </p>
  139.             <p>
  140.                 <input class="checkbox" type="checkbox" value="true" id="<?php echo $this->get_field_id( 'targetBlank' ); ?>" name="<?php echo $this->get_field_name( 'targetBlank' ); ?>"<?php checked( $instance['targetBlank'], 'true' ); ?> />
  141.                 <label for="<?php echo $this->get_field_id( 'targetBlank' ); ?>"><?php _e( 'Open links in a new window', $this->_slug ); ?></label>
  142.             </p>
  143.             <p>
  144.                 <input class="checkbox" type="checkbox" value="true" id="<?php echo $this->get_field_id( 'showXavisysLink' ); ?>" name="<?php echo $this->get_field_name( 'showXavisysLink' ); ?>"<?php checked( $instance['showXavisysLink'], 'true' ); ?> />
  145.                 <label for="<?php echo $this->get_field_id( 'showXavisysLink' ); ?>"><?php _e( 'Show Link to Twitter Widget Pro', $this->_slug ); ?></label>
  146.             </p>
  147.             <p><?php echo $wpTwitterWidget->getSupportForumLink(); ?></p>
  148. <?php
  149.         return;
  150.     }
  151.  
  152.     public function update( $new_instance, $old_instance ) {
  153.         $instance = $this->_getInstanceSettings( $new_instance );
  154.  
  155.         // Clean up the free-form areas
  156.         $instance['title'] = stripslashes( $new_instance['title'] );
  157.         $instance['errmsg'] = stripslashes( $new_instance['errmsg'] );
  158.  
  159.         // If the current user isn't allowed to use unfiltered HTML, filter it
  160.         if ( !current_user_can( 'unfiltered_html' ) ) {
  161.             $instance['title'] = strip_tags( $new_instance['title'] );
  162.             $instance['errmsg'] = strip_tags( $new_instance['errmsg'] );
  163.         }
  164.  
  165.         return $instance;
  166.     }
  167.  
  168.     public function flush_widget_cache() {
  169.         wp_cache_delete( 'widget_twitter_widget_pro', 'widget' );
  170.     }
  171.  
  172.     public function widget( $args, $instance ) {
  173.         $instance = $this->_getInstanceSettings( $instance );
  174.         $wpTwitterWidget = wpTwitterWidget::getInstance();
  175.         echo $wpTwitterWidget->display( wp_parse_args( $instance, $args ) );
  176.     }
  177. }
  178.  
  179.  
  180. /**
  181.  * wpTwitterWidget is the class that handles everything outside the widget. This
  182.  * includes filters that modify tweet content for things like linked usernames.
  183.  * It also helps us avoid name collisions.
  184.  */
  185. class wpTwitterWidget extends XavisysPlugin {
  186.     private $_api_url = 'https://api.twitter.com/1/';
  187.  
  188.     /**
  189.      * @var wpTwitterWidget - Static property to hold our singleton instance
  190.      */
  191.     static $instance = false;
  192.  
  193.     protected function _init() {
  194.         $this->_hook = 'twitterWidgetPro';
  195.         $this->_file = plugin_basename( __FILE__ );
  196.         $this->_pageTitle = __( 'Twitter Widget Pro', $this->_slug );
  197.         $this->_menuTitle = __( 'Twitter Widget', $this->_slug );
  198.         $this->_accessLevel = 'manage_options';
  199.         $this->_optionGroup = 'twp-options';
  200.         $this->_optionNames = array( 'twp' );
  201.         $this->_optionCallbacks = array();
  202.         $this->_slug = 'twitter-widget-pro';
  203.         $this->_paypalButtonId = '9993090';
  204.  
  205.         /**
  206.          * Add filters and actions
  207.          */
  208.         add_action( 'widgets_init', array( $this, 'register' ) );
  209.         add_filter( 'widget_twitter_content', array( $this, 'linkTwitterUsers' ) );
  210.         add_filter( 'widget_twitter_content', array( $this, 'linkUrls' ) );
  211.         add_filter( 'widget_twitter_content', array( $this, 'linkHashtags' ) );
  212.         add_filter( 'widget_twitter_content', 'convert_chars' );
  213.         add_filter( $this->_slug .'-opt-twp', array( $this, 'filterSettings' ) );
  214.         add_shortcode( 'twitter-widget', array( $this, 'handleShortcodes' ) );
  215.  
  216.         $twp_version = get_option( 'twp_version' );
  217.         if ( TWP_VERSION != $twp_version )
  218.             update_option( 'twp_version', TWP_VERSION );
  219.     }
  220.  
  221.     /**
  222.      * Function to instantiate our class and make it a singleton
  223.      */
  224.     public static function getInstance() {
  225.         if ( !self::$instance )
  226.             self::$instance = new self;
  227.  
  228.         return self::$instance;
  229.     }
  230.  
  231.     public function get_slug() {
  232.         return $this->_slug;
  233.     }
  234.  
  235.     public function addOptionsMetaBoxes() {
  236.         add_meta_box( $this->_slug . '-general-settings', __( 'General Settings', $this->_slug ), array( $this, 'generalSettingsMetaBox' ), 'xavisys-' . $this->_slug, 'main' );
  237.     }
  238.  
  239.     public function generalSettingsMetaBox() {
  240.         ?>
  241.                 <table class="form-table">
  242.                     <tr valign="top">
  243.                         <th scope="row">
  244.                             <label for="twp_username"><?php _e( 'Twitter username:', $this->_slug ); ?></label>
  245.                         </th>
  246.                         <td>
  247.                             <input id="twp_username" name="twp[username]" type="text" class="regular-text code" value="<?php esc_attr_e( $this->_settings['twp']['username'] ); ?>" size="40" />
  248.                         </td>
  249.                     </tr>
  250.                     <tr valign="top">
  251.                         <th scope="row">
  252.                             <label for="twp_title"><?php _e( 'Give the feed a title ( optional ):', $this->_slug ); ?></label>
  253.                         </th>
  254.                         <td>
  255.                             <input id="twp_title" name="twp[title]" type="text" class="regular-text code" value="<?php esc_attr_e( $this->_settings['twp']['title'] ); ?>" size="40" />
  256.                         </td>
  257.                     </tr>
  258.                     <tr valign="top">
  259.                         <th scope="row">
  260.                             <label for="twp_items"><?php _e( 'How many items would you like to display?', $this->_slug ); ?></label>
  261.                         </th>
  262.                         <td>
  263.                             <select id="twp_items" name="twp[items]">
  264.                                 <?php
  265.                                     for ( $i = 1; $i <= 20; ++$i ) {
  266.                                         echo "<option value='$i' ". selected( $this->_settings['twp']['items'], $i, false ). ">$i</option>";
  267.                                     }
  268.                                 ?>
  269.                             </select>
  270.                         </td>
  271.                     </tr>
  272.                     <tr valign="top">
  273.                         <th scope="row">
  274.                             <label for="twp_avatar"><?php _e( 'Display profile image?', $this->_slug ); ?></label>
  275.                         </th>
  276.                         <td>
  277.                             <select id="twp_avatar" name="twp[avatar]">
  278.                                 <option value=""<?php selected( $this->_settings['twp']['avatar'], '' ) ?>><?php _e( 'Do not show', $this->_slug ); ?></option>
  279.                                 <option value="mini"<?php selected( $this->_settings['twp']['avatar'], 'mini' ) ?>><?php _e( 'Mini - 24px by 24px', $this->_slug ); ?></option>
  280.                                 <option value="normal"<?php selected( $this->_settings['twp']['avatar'], 'normal' ) ?>><?php _e( 'Normal - 48px by 48px', $this->_slug ); ?></option>
  281.                                 <option value="bigger"<?php selected( $this->_settings['twp']['avatar'], 'bigger' ) ?>><?php _e( 'Bigger - 73px by 73px', $this->_slug ); ?></option>
  282.                                 <option value="original"<?php selected( $this->_settings['twp']['avatar'], 'original' ) ?>><?php _e( 'Original', $this->_slug ); ?></option>
  283.                             </select>
  284.                         </td>
  285.                     </tr>
  286.                     <tr valign="top">
  287.                         <th scope="row">
  288.                             <label for="twp_errmsg"><?php _e( 'What to display when Twitter is down ( optional ):', $this->_slug ); ?></label>
  289.                         </th>
  290.                         <td>
  291.                             <input id="twp_errmsg" name="twp[errmsg]" type="text" class="regular-text code" value="<?php esc_attr_e( $this->_settings['twp']['errmsg'] ); ?>" size="40" />
  292.                         </td>
  293.                     </tr>
  294.                     <tr valign="top">
  295.                         <th scope="row">
  296.                             <label for="twp_fetchTimeOut"><?php _e( 'Number of seconds to wait for a response from Twitter ( default 2 ):', $this->_slug ); ?></label>
  297.                         </th>
  298.                         <td>
  299.                             <input id="twp_fetchTimeOut" name="twp[fetchTimeOut]" type="text" class="regular-text code" value="<?php esc_attr_e( $this->_settings['twp']['fetchTimeOut'] ); ?>" size="40" />
  300.                         </td>
  301.                     </tr>
  302.                     <tr valign="top">
  303.                         <th scope="row">
  304.                             <label for="twp_showts"><?php _e( 'Show date/time of Tweet ( rather than 2 ____ ago ):', $this->_slug ); ?></label>
  305.                         </th>
  306.                         <td>
  307.                             <select id="twp_showts" name="twp[showts]">
  308.                                 <option value="0" <?php selected( $this->_settings['twp']['showts'], '0' ); ?>><?php _e( 'Always', $this->_slug );?></option>
  309.                                 <option value="3600" <?php selected( $this->_settings['twp']['showts'], '3600' ); ?>><?php _e( 'If over an hour old', $this->_slug );?></option>
  310.                                 <option value="86400" <?php selected( $this->_settings['twp']['showts'], '86400' ); ?>><?php _e( 'If over a day old', $this->_slug );?></option>
  311.                                 <option value="604800" <?php selected( $this->_settings['twp']['showts'], '604800' ); ?>><?php _e( 'If over a week old', $this->_slug );?></option>
  312.                                 <option value="2592000" <?php selected( $this->_settings['twp']['showts'], '2592000' ); ?>><?php _e( 'If over a month old', $this->_slug );?></option>
  313.                                 <option value="31536000" <?php selected( $this->_settings['twp']['showts'], '31536000' ); ?>><?php _e( 'If over a year old', $this->_slug );?></option>
  314.                                 <option value="-1" <?php selected( $this->_settings['twp']['showts'], '-1' ); ?>><?php _e( 'Never', $this->_slug );?></option>
  315.                             </select>
  316.                         </td>
  317.                     </tr>
  318.                     <tr valign="top">
  319.                         <th scope="row">
  320.                             <label for="twp_dateFormat"><?php echo sprintf( __( 'Format to dispaly the date in, uses <a href="%s">PHP date()</a> format:', $this->_slug ), 'http://php.net/date' ); ?></label>
  321.                         </th>
  322.                         <td>
  323.                             <input id="twp_dateFormat" name="twp[dateFormat]" type="text" class="regular-text code" value="<?php esc_attr_e( $this->_settings['twp']['dateFormat'] ); ?>" size="40" />
  324.                         </td>
  325.                     </tr>
  326.                     <tr valign="top">
  327.                         <th scope="row">
  328.                             <?php _e( "Other Setting:", $this->_slug );?>
  329.                         </th>
  330.                         <td>
  331.                             <input class="checkbox" type="checkbox" value="true" id="twp_showretweets" name="twp[showretweets]"<?php checked( $this->_settings['twp']['showretweets'], 'true' ); ?> />
  332.                             <label for="twp_showretweets"><?php _e( 'Include retweets', $this->_slug ); ?></label>
  333.                             <br />
  334.                             <input class="checkbox" type="checkbox" value="true" id="twp_hidereplies" name="twp[hidereplies]"<?php checked( $this->_settings['twp']['hidereplies'], 'true' ); ?> />
  335.                             <label for="twp_hidereplies"><?php _e( 'Hide @replies', $this->_slug ); ?></label>
  336.                             <br />
  337.                             <input class="checkbox" type="checkbox" value="true" id="twp_hidefrom" name="twp[hidefrom]"<?php checked( $this->_settings['twp']['hidefrom'], 'true' ); ?> />
  338.                             <label for="twp_hidefrom"><?php _e( 'Hide sending applications', $this->_slug ); ?></label>
  339.                             <br />
  340.                             <input type="hidden" value="false" name="twp[showintents]" />
  341.                             <input class="checkbox" type="checkbox" value="true" id="twp_showintents" name="twp[showintents]"<?php checked( $this->_settings['twp']['showintents'], 'true' ); ?> />
  342.                             <label for="twp_showintents"><?php _e( 'Show Tweet Intents (reply, retweet, favorite)', $this->_slug ); ?></label>
  343.                             <br />
  344.                             <input type="hidden" value="false" name="twp[showfollow]" />
  345.                             <input class="checkbox" type="checkbox" value="true" id="twp_showfollow" name="twp[showfollow]"<?php checked( $this->_settings['twp']['showfollow'], 'true' ); ?> />
  346.                             <label for="twp_showfollow"><?php _e( 'Show Follow Link', $this->_slug ); ?></label>
  347.                             <br />
  348.                             <input class="checkbox" type="checkbox" value="true" id="twp_targetBlank" name="twp[targetBlank]"<?php checked( $this->_settings['twp']['targetBlank'], 'true' ); ?> />
  349.                             <label for="twp_targetBlank"><?php _e( 'Open links in a new window', $this->_slug ); ?></label>
  350.                             <br />
  351.                             <input class="checkbox" type="checkbox" value="true" id="twp_showXavisysLink" name="twp[showXavisysLink]"<?php checked( $this->_settings['twp']['showXavisysLink'], 'true' ); ?> />
  352.                             <label for="twp_showXavisysLink"><?php _e( 'Show Link to Twitter Widget Pro', $this->_slug ); ?></label>
  353.                         </td>
  354.                     </tr>
  355.                 </table>
  356.         <?php
  357.     }
  358.  
  359.     /**
  360.      * Replace @username with a link to that twitter user
  361.      *
  362.      * @param string $text - Tweet text
  363.      * @return string - Tweet text with @replies linked
  364.      */
  365.     public function linkTwitterUsers( $text ) {
  366.         $text = preg_replace_callback('/(^|\s)@(\w+)/i', array($this, '_linkTwitterUsersCallback'), $text);
  367.         return $text;
  368.     }
  369.  
  370.     private function _linkTwitterUsersCallback( $matches ) {
  371.         $linkAttrs = array(
  372.             'href'  => 'http://twitter.com/' . urlencode( $matches[2] ),
  373.             'class' => 'twitter-user'
  374.         );
  375.         return $matches[1] . $this->_buildLink( '@'.$matches[2], $linkAttrs );
  376.     }
  377.  
  378.     /**
  379.      * Replace #hashtag with a link to search.twitter.com for that hashtag
  380.      *
  381.      * @param string $text - Tweet text
  382.      * @return string - Tweet text with #hashtags linked
  383.      */
  384.     public function linkHashtags( $text ) {
  385.         $text = preg_replace_callback('/(^|\s)(#\w*)/i', array($this, '_linkHashtagsCallback'), $text);
  386.         return $text;
  387.     }
  388.  
  389.     /**
  390.      * Replace #hashtag with a link to search.twitter.com for that hashtag
  391.      *
  392.      * @param array $matches - Tweet text
  393.      * @return string - Tweet text with #hashtags linked
  394.      */
  395.     private function _linkHashtagsCallback( $matches ) {
  396.         $linkAttrs = array(
  397.             'href'  => 'http://search.twitter.com/search?q=' . urlencode( $matches[2] ),
  398.             'class' => 'twitter-hashtag'
  399.         );
  400.         return $matches[1] . $this->_buildLink( $matches[2], $linkAttrs );
  401.     }
  402.  
  403.     /**
  404.      * Turn URLs into links
  405.      *
  406.      * @param string $text - Tweet text
  407.      * @return string - Tweet text with URLs repalced with links
  408.      */
  409.     public function linkUrls( $text ) {
  410.         /**
  411.          * match protocol://address/path/file.extension?some=variable&another=asf%
  412.          * $1 is a possible space, this keeps us from linking href="[link]" etc
  413.          * $2 is the whole URL
  414.          * $3 is protocol://
  415.          * $4 is the URL without the protocol://
  416.          * $5 is the URL parameters
  417.          */
  418.         $text = preg_replace_callback("/(^|\s)(([a-zA-Z]+:\/\/)([a-z][a-z0-9_\..-]*[a-z]{2,6})([a-zA-Z0-9~\/*-?&%]*))/i", array($this, '_linkUrlsCallback'), $text);
  419.  
  420.         /**
  421.          * match www.something.domain/path/file.extension?some=variable&another=asf%
  422.          * $1 is a possible space, this keeps us from linking href="[link]" etc
  423.          * $2 is the whole URL that was matched.  The protocol is missing, so we assume http://
  424.          * $3 is www.
  425.          * $4 is the URL matched without the www.
  426.          * $5 is the URL parameters
  427.          */
  428.         $text = preg_replace_callback("/(^|\s)(www\.([a-z][a-z0-9_\..-]*[a-z]{2,6})([a-zA-Z0-9~\/*-?&%]*))/i", array($this, '_linkUrlsCallback'), $text);
  429.  
  430.         return $text;
  431.     }
  432.  
  433.     private function _linkUrlsCallback ( $matches ) {
  434.         $linkAttrs = array(
  435.             'href'  => $matches[2]
  436.         );
  437.         return $matches[1] . $this->_buildLink( $matches[2], $linkAttrs );
  438.     }
  439.  
  440.     private function _notEmpty( $v ) {
  441.         return !( empty( $v ) );
  442.     }
  443.  
  444.     private function _buildLink( $text, $attributes = array(), $noFilter = false ) {
  445.         $attributes = array_filter( wp_parse_args( $attributes ), array( $this, '_notEmpty' ) );
  446.         $attributes = apply_filters( 'widget_twitter_link_attributes', $attributes );
  447.         $attributes = wp_parse_args( $attributes );
  448.         if ( strtolower( 'www' == substr( $attributes['href'], 0, 3 ) ) )
  449.             $attributes['href'] = 'http://' . $attributes['href'];
  450.  
  451.         $text = apply_filters( 'widget_twitter_link_text', $text );
  452.         $link = '<a';
  453.         foreach ( $attributes as $name => $value ) {
  454.             $link .= ' ' . esc_attr( $name ) . '="' . esc_attr( $value ) . '"';
  455.         }
  456.         $link .= '>';
  457.         if ( $noFilter )
  458.             $link .= $text;
  459.         else
  460.             $link .= esc_html( $text );
  461.  
  462.         $link .= '</a>';
  463.         return $link;
  464.     }
  465.  
  466.     public function register() {
  467.         register_widget( 'WP_Widget_Twitter_Pro' );
  468.     }
  469.  
  470.     public function targetBlank( $attributes ) {
  471.         $attributes['target'] = '_blank';
  472.         return $attributes;
  473.     }
  474.  
  475.     public function display( $args ) {
  476.         $args = wp_parse_args( $args );
  477.  
  478.         if ( 'true' == $args['targetBlank'] )
  479.             add_filter( 'widget_twitter_link_attributes', array( $this, 'targetBlank' ) );
  480.  
  481.         // Validate our options
  482.         $args['items'] = (int) $args['items'];
  483.         if ( $args['items'] < 1 || 20 < $args['items'] )
  484.             $args['items'] = 10;
  485.  
  486.         if ( !isset( $args['showts'] ) )
  487.             $args['showts'] = 86400;
  488.  
  489.         $tweets = $this->_getTweets( $args );
  490.         if ( false === $tweets )
  491.             return '';
  492.  
  493.         $widgetContent = $args['before_widget'] . '<div>';
  494.  
  495.         if ( empty( $args['title'] ) )
  496.             $args['title'] = "Twitter: {$args['username']}";
  497.  
  498.         $args['title'] = apply_filters( 'twitter-widget-title', $args['title'], $args );
  499.         $args['title'] = "<span class='twitterwidget twitterwidget-title'>{$args['title']}</span>";
  500.         $widgetContent .= $args['before_title'] . $args['title'] . $args['after_title'];
  501.         if ( !empty( $tweets[0] ) && !empty( $args['avatar'] ) ) {
  502.             $widgetContent .= '<div class="twitter-avatar">';
  503.             $widgetContent .= $this->_getProfileImage( $tweets[0]->user, $args );
  504.             $widgetContent .= '</div>';
  505.         }
  506.         $widgetContent .= '<ul>';
  507.         if ( count( $tweets ) == 0 ) {
  508.             $widgetContent .= '<li class="wpTwitterWidgetEmpty">' . __( 'No Tweets Available', $this->_slug ) . '</li>';
  509.         } else {
  510.             $count = 0;
  511.             foreach ( $tweets as $tweet ) {
  512.                 // Set our "ago" string which converts the date to "# ___(s) ago"
  513.                 $tweet->ago = $this->_timeSince( strtotime( $tweet->created_at ), $args['showts'], $args['dateFormat'] );
  514.                 $entryContent = apply_filters( 'widget_twitter_content', $tweet->text );
  515.                 $widgetContent .= '<li>';
  516.                 $widgetContent .= "<span class='entry-content'>{$entryContent}</span>";
  517.                 $widgetContent .= " <span class='entry-meta'>";
  518.                 $widgetContent .= "<span class='time-meta'>";
  519.                 $linkAttrs = array(
  520.                     'href'  => "http://twitter.com/{$tweet->user->screen_name}/statuses/{$tweet->id_str}"
  521.                 );
  522.                 $widgetContent .= $this->_buildLink( $tweet->ago, $linkAttrs );
  523.                 $widgetContent .= '</span>';
  524.  
  525.                 if ( 'true' != $args['hidefrom'] ) {
  526.                     $from = sprintf( __( 'from %s', $this->_slug ), str_replace( '&', '&amp;', $tweet->source ) );
  527.                     $widgetContent .= " <span class='from-meta'>{$from}</span>";
  528.                 }
  529.                 if ( !empty( $tweet->in_reply_to_screen_name ) ) {
  530.                     $rtLinkText = sprintf( __( 'in reply to %s', $this->_slug ), $tweet->in_reply_to_screen_name );
  531.                     $widgetContent .=  ' <span class="in-reply-to-meta">';
  532.                     $linkAttrs = array(
  533.                         'href'  => "http://twitter.com/{$tweet->in_reply_to_screen_name}/statuses/{$tweet->in_reply_to_status_id_str}",
  534.                         'class' => 'reply-to'
  535.                     );
  536.                     $widgetContent .= $this->_buildLink( $rtLinkText, $linkAttrs );
  537.                     $widgetContent .= '</span>';
  538.                 }
  539.                 $widgetContent .= '</span>';
  540.  
  541.                 if ( 'true' == $args['showintents'] ) {
  542.                     $widgetContent .= ' <span class="intent-meta">';
  543.                     $lang = $this->_getTwitterLang();
  544.                     if ( !empty( $lang ) )
  545.                         $linkAttrs['data-lang'] = $lang;
  546.  
  547.                     $linkText = __( 'Reply', $this->_slug );
  548.                     $linkAttrs['href'] = "http://twitter.com/intent/tweet?in_reply_to={$tweet->id_str}";
  549.                     $linkAttrs['class'] = 'in-reply-to';
  550.                     $linkAttrs['title'] = $linkText;
  551.                     $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
  552.  
  553.                     $linkText = __( 'Retweet', $this->_slug );
  554.                     $linkAttrs['href'] = "http://twitter.com/intent/retweet?tweet_id={$tweet->id_str}";
  555.                     $linkAttrs['class'] = 'retweet';
  556.                     $linkAttrs['title'] = $linkText;
  557.                     $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
  558.  
  559.                     $linkText = __( 'Favorite', $this->_slug );
  560.                     $linkAttrs['href'] = "http://twitter.com/intent/favorite?tweet_id={$tweet->id_str}";
  561.                     $linkAttrs['class'] = 'favorite';
  562.                     $linkAttrs['title'] = $linkText;
  563.                     $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
  564.                     $widgetContent .= '</span>';
  565.                 }
  566.                 $widgetContent .= '</li>';
  567.  
  568.                 if ( ++$count >= $args['items'] )
  569.                     break;
  570.             }
  571.         }
  572.  
  573.         $widgetContent .= '</ul>';
  574.         if ( 'true' == $args['showfollow'] ) {
  575.             $widgetContent .= '<div class="follow-button">';
  576.             $linkText = "@{$args['username']}";
  577.             $linkAttrs = array(
  578.                 'href'  => "http://twitter.com/{$args['username']}",
  579.                 'class' => 'twitter-follow-button',
  580.                 'title' => sprintf( __( 'Follow %s', $this->_slug ), "@{$args['username']}" ),
  581.             );
  582.             $lang = $this->_getTwitterLang();
  583.             if ( !empty( $lang ) )
  584.                 $linkAttrs['data-lang'] = $lang;
  585.  
  586.             $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
  587.             $widgetContent .= '</div>';
  588.         }
  589.  
  590.         if ( 'true' == $args['showXavisysLink'] ) {
  591.             $widgetContent .= '<div class="xavisys-link"><span class="xavisys-link-text">';
  592.             $linkAttrs = array(
  593.                 'href'  => 'http://xavisys.com/wordpress-plugins/wordpress-twitter-widget/',
  594.                 'title' => __( 'Brought to you by Xavisys - A WordPress development company', $this->_slug )
  595.             );
  596.             $widgetContent .= __( 'Powered by', $this->_slug );
  597.             $widgetContent .= $this->_buildLink( 'WordPress Twitter Widget Pro', $linkAttrs );
  598.             $widgetContent .= '</span></div>';
  599.         }
  600.         $widgetContent .= '</div>' . $args['after_widget'];
  601.  
  602.         if ( 'true' == $args['showintents'] || 'true' == $args['showfollow'] ) {
  603.             wp_enqueue_script( 'twitter-widgets', 'http://platform.twitter.com/widgets.js', array(), '1.0.0', true );
  604.  
  605.             if ( ! function_exists( '_wp_footer_scripts' ) ) {
  606.                 // This means we can't just enqueue our script (fixes in WP 3.3)
  607.                 add_action( 'wp_footer', array( $this, 'add_twitter_js' ) );
  608.             }
  609.         }
  610.         return $widgetContent;
  611.     }
  612.  
  613.     private function _getTwitterLang() {
  614.         $valid_langs = array(
  615.             'en', // English
  616.             'it', // Italian
  617.             'es', // Spanish
  618.             'fr', // French
  619.             'ko', // Korean
  620.             'ja', // Japanese
  621.         );
  622.         $locale = get_locale();
  623.         $lang = strtolower( substr( get_locale(), 0, 2 ) );
  624.         if ( in_array( $lang, $valid_langs ) )
  625.             return $lang;
  626.  
  627.         return false;
  628.     }
  629.  
  630.     public function add_twitter_js() {
  631.         wp_print_scripts( 'twitter-widgets' );
  632.     }
  633.  
  634.     /**
  635.      * Gets tweets, from cache if possible
  636.      *
  637.      * @param array $widgetOptions - options needed to get feeds
  638.      * @return array - Array of objects
  639.      */
  640.     private function _getTweets( $widgetOptions ) {
  641.         $key = 'twp_' . md5( $this->_getFeedUrl( $widgetOptions ) );
  642.         return tlc_transient( $key )
  643.             ->expires_in( 300 ) // cache for 5 minutes
  644.             ->updates_with( array( $this, 'parseFeed' ), array( $widgetOptions ) )
  645.             ->get();
  646.     }
  647.  
  648.     /**
  649.      * Pulls the JSON feed from Twitter and returns an array of objects
  650.      *
  651.      * @param array $widgetOptions - settings needed to get feed url, etc
  652.      * @return array
  653.      */
  654.     public function parseFeed( $widgetOptions ) {
  655.         $feedUrl = $this->_getFeedUrl( $widgetOptions );
  656.         $resp = wp_remote_request( $feedUrl, array( 'timeout' => $widgetOptions['fetchTimeOut'] ) );
  657.  
  658.         if ( !is_wp_error( $resp ) && $resp['response']['code'] >= 200 && $resp['response']['code'] < 300 ) {
  659.             $decodedResponse = json_decode( $resp['body'] );
  660.             if ( empty( $decodedResponse ) ) {
  661.                 if ( empty( $widgetOptions['errmsg'] ) )
  662.                     $widgetOptions['errmsg'] = __( 'Invalid Twitter Response.', $this->_slug );
  663.             } elseif( !empty( $decodedResponse->error ) ) {
  664.                 if ( empty( $widgetOptions['errmsg'] ) )
  665.                     $widgetOptions['errmsg'] = $decodedResponse->error;
  666.             } else {
  667.                 return $decodedResponse;
  668.             }
  669.         } else {
  670.             // Failed to fetch url;
  671.             if ( empty( $widgetOptions['errmsg'] ) )
  672.                 $widgetOptions['errmsg'] = __( 'Could not connect to Twitter', $this->_slug );
  673.         }
  674.         do_action( 'widget_twitter_parsefeed_error', $resp, $feedUrl, $widgetOptions );
  675.         throw new Exception( $widgetOptions['errmsg'] );
  676.     }
  677.  
  678.     /**
  679.      * Gets the URL for the desired feed.
  680.      *
  681.      * @param array $widgetOptions - settings needed such as username, feet type, etc
  682.      * @param string[optional] $type - 'rss' or 'json'
  683.      * @param bool[optional] $count - If true, it adds the count parameter to the URL
  684.      * @return string - Twitter feed URL
  685.      */
  686.     private function _getFeedUrl( $widgetOptions, $type = 'json', $count = true ) {
  687.         if ( !in_array( $type, array( 'rss', 'json' ) ) )
  688.             $type = 'json';
  689.  
  690.         $req = $this->_api_url . "statuses/user_timeline.{$type}";
  691.  
  692.         /**
  693.          * user_id
  694.          * screen_name *
  695.          * since_id
  696.          * count
  697.          * max_id
  698.          * page
  699.          * trim_user
  700.          * include_rts *
  701.          * include_entities
  702.          * exclude_replies *
  703.          * contributor_details
  704.          */
  705.  
  706.         $req = add_query_arg( array( 'screen_name' => $widgetOptions['username'] ), $req );
  707.         if ( $count )
  708.             $req = add_query_arg( array( 'count' => $widgetOptions['items'] ), $req );
  709.  
  710.         if ( 'true' == $widgetOptions['hidereplies'] )
  711.             $req = add_query_arg( array( 'exclude_replies' => 'true' ), $req );
  712.  
  713.         if ( 'true' == $widgetOptions['showretweets'] )
  714.             $req = add_query_arg( array( 'include_rts' => 'true' ), $req );
  715.  
  716.         return $req;
  717.     }
  718.  
  719.     /**
  720.      * Twitter displays all tweets that are less than 24 hours old with
  721.      * something like "about 4 hours ago" and ones older than 24 hours with a
  722.      * time and date. This function allows us to simulate that functionality,
  723.      * but lets us choose where the dividing line is.
  724.      *
  725.      * @param int $startTimestamp - The timestamp used to calculate time passed
  726.      * @param int $max - Max number of seconds to conver to "ago" messages.  0 for all, -1 for none
  727.      * @return string
  728.      */
  729.     private function _timeSince( $startTimestamp, $max, $dateFormat ) {
  730.         // array of time period chunks
  731.         $chunks = array(
  732.             'year'   => 60 * 60 * 24 * 365, // 31,536,000 seconds
  733.             'month'  => 60 * 60 * 24 * 30,  // 2,592,000 seconds
  734.             'week'   => 60 * 60 * 24 * 7,   // 604,800 seconds
  735.             'day'    => 60 * 60 * 24,       // 86,400 seconds
  736.             'hour'   => 60 * 60,            // 3600 seconds
  737.             'minute' => 60,                 // 60 seconds
  738.             'second' => 1                   // 1 second
  739.         );
  740.  
  741.         $since = time() - $startTimestamp;
  742.  
  743.         if ( $max != '-1' && $since >= $max )
  744.             return date_i18n( $dateFormat, $startTimestamp );
  745.  
  746.  
  747.         foreach ( $chunks as $key => $seconds ) {
  748.             // finding the biggest chunk ( if the chunk fits, break )
  749.             if ( ( $count = floor( $since / $seconds ) ) != 0 )
  750.                 break;
  751.         }
  752.  
  753.         $messages = array(
  754.             'year'   => _n( 'about %s year ago',   'about %s years ago',   $count, $this->_slug ),
  755.             'month'  => _n( 'about %s month ago',  'about %s months ago',  $count, $this->_slug ),
  756.             'week'   => _n( 'about %s week ago',   'about %s weeks ago',   $count, $this->_slug ),
  757.             'day'    => _n( 'about %s day ago',    'about %s days ago',    $count, $this->_slug ),
  758.             'hour'   => _n( 'about %s hour ago',   'about %s hours ago',   $count, $this->_slug ),
  759.             'minute' => _n( 'about %s minute ago', 'about %s minutes ago', $count, $this->_slug ),
  760.             'second' => _n( 'about %s second ago', 'about %s seconds ago', $count, $this->_slug ),
  761.         );
  762.  
  763.         return sprintf( $messages[$key], $count );
  764.     }
  765.  
  766.     /**
  767.      * Returns the Twitter user's profile image, linked to that user's profile
  768.      *
  769.      * @param object $user - Twitter User
  770.      * @param array $args - Widget Arguments
  771.      * @return string - Linked image ( XHTML )
  772.      */
  773.     private function _getProfileImage( $user, $args = array() ) {
  774.         $linkAttrs = array(
  775.             'href'  => "http://twitter.com/{$user->screen_name}",
  776.             'title' => $user->name
  777.         );
  778.         $img = $this->_api_url . 'users/profile_image';
  779.         $img = add_query_arg( array( 'screen_name' => $user->screen_name ), $img );
  780.         $img = add_query_arg( array( 'size' => $args['avatar'] ), $img );
  781.  
  782.         return $this->_buildLink( "<img alt='{$user->name}' src='{$img}' />", $linkAttrs, true );
  783.     }
  784.  
  785.     /**
  786.      * Replace our shortCode with the "widget"
  787.      *
  788.      * @param array $attr - array of attributes from the shortCode
  789.      * @param string $content - Content of the shortCode
  790.      * @return string - formatted XHTML replacement for the shortCode
  791.      */
  792.     public function handleShortcodes( $attr, $content = '' ) {
  793.         $defaults = array(
  794.             'before_widget'   => '',
  795.             'after_widget'    => '',
  796.             'before_title'    => '<h2>',
  797.             'after_title'     => '</h2>',
  798.             'title'           => '',
  799.             'errmsg'          => '',
  800.             'fetchTimeOut'    => '2',
  801.             'username'        => '',
  802.             'hidereplies'     => 'false',
  803.             'showretweets'    => 'true',
  804.             'hidefrom'        => 'false',
  805.             'showintents'     => 'true',
  806.             'showfollow'      => 'true',
  807.             'avatar'          => '',
  808.             'showXavisysLink' => 'false',
  809.             'targetBlank'     => 'false',
  810.             'items'           => 10,
  811.             'showts'          => 60 * 60 * 24,
  812.             'dateFormat'      => __( 'h:i:s A F d, Y', $this->_slug ),
  813.         );
  814.  
  815.         /**
  816.          * Attribute names are strtolower'd, so we need to fix them to match
  817.          * the names used through the rest of the plugin
  818.          */
  819.         if ( array_key_exists( 'fetchtimeout', $attr ) ) {
  820.             $attr['fetchTimeOut'] = $attr['fetchtimeout'];
  821.             unset( $attr['fetchtimeout'] );
  822.         }
  823.         if ( array_key_exists( 'showxavisyslink', $attr ) ) {
  824.             $attr['showXavisysLink'] = $attr['showxavisyslink'];
  825.             unset( $attr['showxavisyslink'] );
  826.         }
  827.         if ( array_key_exists( 'targetblank', $attr ) ) {
  828.             $attr['targetBlank'] = $attr['targetblank'];
  829.             unset( $attr['targetblank'] );
  830.         }
  831.         if ( array_key_exists( 'dateformat', $attr ) ) {
  832.             $attr['dateFormat'] = $attr['dateformat'];
  833.             unset( $attr['dateformat'] );
  834.         }
  835.  
  836.         if ( !empty( $content ) && empty( $attr['title'] ) )
  837.             $attr['title'] = $content;
  838.  
  839.  
  840.         $attr = shortcode_atts( $defaults, $attr );
  841.  
  842.         if ( $attr['hidereplies'] && $attr['hidereplies'] != 'false' && $attr['hidereplies'] != '0' )
  843.             $attr['hidereplies'] = 'true';
  844.  
  845.         if ( $attr['showretweets'] && $attr['showretweets'] != 'false' && $attr['showretweets'] != '0' )
  846.             $attr['showretweets'] = 'true';
  847.  
  848.         if ( $attr['hidefrom'] && $attr['hidefrom'] != 'false' && $attr['hidefrom'] != '0' )
  849.             $attr['hidefrom'] = 'true';
  850.  
  851.         if ( $attr['showintents'] && $attr['showintents'] != 'true' && $attr['showintents'] != '1' )
  852.             $attr['showintents'] = 'false';
  853.  
  854.         if ( $attr['showfollow'] && $attr['showfollow'] != 'true' && $attr['showfollow'] != '1' )
  855.             $attr['showfollow'] = 'false';
  856.  
  857.         if ( !in_array( $attr['avatar'], array( 'bigger', 'normal', 'mini', 'original', '' ) ) )
  858.             $attr['avatar'] = 'normal';
  859.  
  860.         if ( $attr['showXavisysLink'] && $attr['showXavisysLink'] != 'false' && $attr['showXavisysLink'] != '0' )
  861.             $attr['showXavisysLink'] = 'true';
  862.  
  863.         if ( $attr['targetBlank'] && $attr['targetBlank'] != 'false' && $attr['targetBlank'] != '0' )
  864.             $attr['targetBlank'] = 'true';
  865.  
  866.         return $this->display( $attr );
  867.     }
  868.  
  869.     public function filterSettings( $settings ) {
  870.         $defaultArgs = array(
  871.             'title'           => '',
  872.             'errmsg'          => '',
  873.             'fetchTimeOut'    => '2',
  874.             'username'        => '',
  875.             'hidereplies'     => 'false',
  876.             'showretweets'    => 'true',
  877.             'hidefrom'        => 'false',
  878.             'showintents'     => 'true',
  879.             'showfollow'      => 'true',
  880.             'avatar'          => '',
  881.             'showXavisysLink' => 'false',
  882.             'targetBlank'     => 'false',
  883.             'items'           => 10,
  884.             'showts'          => 60 * 60 * 24,
  885.             'dateFormat'      => __( 'h:i:s A F d, Y', $this->_slug ),
  886.         );
  887.  
  888.         return $this->fixAvatar( wp_parse_args( $settings, $defaultArgs ) );
  889.     }
  890.  
  891.     /**
  892.      * Now that we support all the profile image sizes we need to convert
  893.      * the old true/false to a size string
  894.      */
  895.     private function fixAvatar( $settings ) {
  896.         if ( false === $settings['avatar'] )
  897.             $settings['avatar'] = '';
  898.         elseif ( !in_array( $settings['avatar'], array( 'bigger', 'normal', 'mini', 'original', false ) ) )
  899.             $settings['avatar'] = 'normal';
  900.  
  901.         return $settings;
  902.     }
  903.  
  904.     public function getSettings( $settings ) {
  905.         return $this->fixAvatar( wp_parse_args( $settings, $this->_settings['twp'] ) );
  906.     }
  907. }
  908. // Instantiate our class
  909. $wpTwitterWidget = wpTwitterWidget::getInstance();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement