Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function display( $args ) {
- $args = wp_parse_args( $args );
- if ( 'true' == $args['targetBlank'] )
- add_filter( 'widget_twitter_link_attributes', array( $this, 'targetBlank' ) );
- // Validate our options
- $count_memory = (int) $args['items'];
- // Get x out THEN do the count.
- $args['items'] = 20;
- //if ( $args['items'] < 1 || 20 < $args['items'] )
- // $args['items'] = 10;
- if ( !isset( $args['showts'] ) )
- $args['showts'] = 86400;
- $tweets = $this->_getTweets( $args );
- if ( false === $tweets )
- return '';
- $widgetContent = $args['before_widget'] . '<div>';
- if ( empty( $args['title'] ) )
- $args['title'] = sprintf( __( 'Twitter: %s', 'twitter-widget-pro' ), $args['username'] );
- $args['title'] = apply_filters( 'twitter-widget-title', $args['title'], $args );
- $args['title'] = "<span class='twitterwidget twitterwidget-title'>{$args['title']}</span>";
- $widgetContent .= $args['before_title'] . $args['title'] . $args['after_title'];
- if ( !empty( $tweets[0] ) && is_object( $tweets[0] ) && !empty( $args['avatar'] ) ) {
- $widgetContent .= '<div class="twitter-avatar">';
- $widgetContent .= $this->_getProfileImage( $tweets[0]->user, $args );
- $widgetContent .= '</div>';
- }
- $widgetContent .= '<ul>';
- if ( ! is_array( $tweets ) || count( $tweets ) == 0 ) {
- $widgetContent .= '<li class="wpTwitterWidgetEmpty">' . __( 'No Tweets Available', 'twitter-widget-pro' ) . '</li>';
- } else {
- $count = 0;
- foreach ( $tweets as $tweet ) {
- // Set our "ago" string which converts the date to "# ___(s) ago"
- $tweet->ago = $this->_timeSince( strtotime( $tweet->created_at ), $args['showts'], $args['dateFormat'] );
- $entryContent = apply_filters( 'widget_twitter_content', $tweet->text, $tweet );
- $widgetContent .= '<li>';
- $widgetContent .= "<span class='entry-content'>{$entryContent}</span>";
- $widgetContent .= " <span class='entry-meta'>";
- $widgetContent .= "<span class='time-meta'>";
- $linkAttrs = array(
- 'href' => "http://twitter.com/{$tweet->user->screen_name}/statuses/{$tweet->id_str}"
- );
- $widgetContent .= $this->_buildLink( $tweet->ago, $linkAttrs );
- $widgetContent .= '</span>';
- if ( 'true' != $args['hidefrom'] ) {
- $from = sprintf( __( 'from %s', 'twitter-widget-pro' ), str_replace( '&', '&', $tweet->source ) );
- $widgetContent .= " <span class='from-meta'>{$from}</span>";
- }
- if ( !empty( $tweet->in_reply_to_screen_name ) ) {
- $rtLinkText = sprintf( __( 'in reply to %s', 'twitter-widget-pro' ), $tweet->in_reply_to_screen_name );
- $widgetContent .= ' <span class="in-reply-to-meta">';
- $linkAttrs = array(
- 'href' => "http://twitter.com/{$tweet->in_reply_to_screen_name}/statuses/{$tweet->in_reply_to_status_id_str}",
- 'class' => 'reply-to'
- );
- $widgetContent .= $this->_buildLink( $rtLinkText, $linkAttrs );
- $widgetContent .= '</span>';
- }
- $widgetContent .= '</span>';
- if ( 'true' == $args['showintents'] ) {
- $widgetContent .= ' <span class="intent-meta">';
- $lang = $this->_getTwitterLang();
- if ( !empty( $lang ) )
- $linkAttrs['data-lang'] = $lang;
- $linkText = __( 'Reply', 'twitter-widget-pro' );
- $linkAttrs['href'] = "http://twitter.com/intent/tweet?in_reply_to={$tweet->id_str}";
- $linkAttrs['class'] = 'in-reply-to';
- $linkAttrs['title'] = $linkText;
- $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
- $linkText = __( 'Retweet', 'twitter-widget-pro' );
- $linkAttrs['href'] = "http://twitter.com/intent/retweet?tweet_id={$tweet->id_str}";
- $linkAttrs['class'] = 'retweet';
- $linkAttrs['title'] = $linkText;
- $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
- $linkText = __( 'Favorite', 'twitter-widget-pro' );
- $linkAttrs['href'] = "http://twitter.com/intent/favorite?tweet_id={$tweet->id_str}";
- $linkAttrs['class'] = 'favorite';
- $linkAttrs['title'] = $linkText;
- $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
- $widgetContent .= '</span>';
- }
- $widgetContent .= '</li>';
- if ( ++$count >= $count_memory )
- break;
- }
- }
- $widgetContent .= '</ul>';
- if ( 'true' == $args['showfollow'] && ! empty( $args['username'] ) ) {
- $widgetContent .= '<div class="follow-button">';
- $linkText = "@{$args['username']}";
- $linkAttrs = array(
- 'href' => "http://twitter.com/{$args['username']}",
- 'class' => 'twitter-follow-button',
- 'title' => sprintf( __( 'Follow %s', 'twitter-widget-pro' ), "@{$args['username']}" ),
- );
- $lang = $this->_getTwitterLang();
- if ( !empty( $lang ) )
- $linkAttrs['data-lang'] = $lang;
- $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
- $widgetContent .= '</div>';
- }
- $widgetContent .= '</div>' . $args['after_widget'];
- if ( 'true' == $args['showintents'] || 'true' == $args['showfollow'] ) {
- $script = 'http://platform.twitter.com/widgets.js';
- if ( is_ssl() )
- $script = str_replace( 'http://', 'https://', $script );
- wp_enqueue_script( 'twitter-widgets', $script, array(), '1.0.0', true );
- if ( ! function_exists( '_wp_footer_scripts' ) ) {
- // This means we can't just enqueue our script (fixes in WP 3.3)
- add_action( 'wp_footer', array( $this, 'add_twitter_js' ) );
- }
- }
- return $widgetContent;
- }
Advertisement
Add Comment
Please, Sign In to add comment