Guest User

Untitled

a guest
Oct 7th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. public function display( $args ) {
  2.  
  3.  
  4.  
  5. $args = wp_parse_args( $args );
  6.  
  7. if ( 'true' == $args['targetBlank'] )
  8. add_filter( 'widget_twitter_link_attributes', array( $this, 'targetBlank' ) );
  9.  
  10. // Validate our options
  11. $count_memory = (int) $args['items'];
  12. // Get x out THEN do the count.
  13. $args['items'] = 20;
  14.  
  15.  
  16. //if ( $args['items'] < 1 || 20 < $args['items'] )
  17. // $args['items'] = 10;
  18.  
  19.  
  20. if ( !isset( $args['showts'] ) )
  21. $args['showts'] = 86400;
  22.  
  23. $tweets = $this->_getTweets( $args );
  24. if ( false === $tweets )
  25. return '';
  26.  
  27. $widgetContent = $args['before_widget'] . '<div>';
  28.  
  29. if ( empty( $args['title'] ) )
  30. $args['title'] = sprintf( __( 'Twitter: %s', 'twitter-widget-pro' ), $args['username'] );
  31.  
  32. $args['title'] = apply_filters( 'twitter-widget-title', $args['title'], $args );
  33. $args['title'] = "<span class='twitterwidget twitterwidget-title'>{$args['title']}</span>";
  34. $widgetContent .= $args['before_title'] . $args['title'] . $args['after_title'];
  35. if ( !empty( $tweets[0] ) && is_object( $tweets[0] ) && !empty( $args['avatar'] ) ) {
  36. $widgetContent .= '<div class="twitter-avatar">';
  37. $widgetContent .= $this->_getProfileImage( $tweets[0]->user, $args );
  38. $widgetContent .= '</div>';
  39. }
  40. $widgetContent .= '<ul>';
  41. if ( ! is_array( $tweets ) || count( $tweets ) == 0 ) {
  42. $widgetContent .= '<li class="wpTwitterWidgetEmpty">' . __( 'No Tweets Available', 'twitter-widget-pro' ) . '</li>';
  43. } else {
  44. $count = 0;
  45. foreach ( $tweets as $tweet ) {
  46. // Set our "ago" string which converts the date to "# ___(s) ago"
  47. $tweet->ago = $this->_timeSince( strtotime( $tweet->created_at ), $args['showts'], $args['dateFormat'] );
  48. $entryContent = apply_filters( 'widget_twitter_content', $tweet->text, $tweet );
  49. $widgetContent .= '<li>';
  50. $widgetContent .= "<span class='entry-content'>{$entryContent}</span>";
  51. $widgetContent .= " <span class='entry-meta'>";
  52. $widgetContent .= "<span class='time-meta'>";
  53. $linkAttrs = array(
  54. 'href' => "http://twitter.com/{$tweet->user->screen_name}/statuses/{$tweet->id_str}"
  55. );
  56. $widgetContent .= $this->_buildLink( $tweet->ago, $linkAttrs );
  57. $widgetContent .= '</span>';
  58.  
  59. if ( 'true' != $args['hidefrom'] ) {
  60. $from = sprintf( __( 'from %s', 'twitter-widget-pro' ), str_replace( '&', '&amp;', $tweet->source ) );
  61. $widgetContent .= " <span class='from-meta'>{$from}</span>";
  62. }
  63. if ( !empty( $tweet->in_reply_to_screen_name ) ) {
  64. $rtLinkText = sprintf( __( 'in reply to %s', 'twitter-widget-pro' ), $tweet->in_reply_to_screen_name );
  65. $widgetContent .= ' <span class="in-reply-to-meta">';
  66. $linkAttrs = array(
  67. 'href' => "http://twitter.com/{$tweet->in_reply_to_screen_name}/statuses/{$tweet->in_reply_to_status_id_str}",
  68. 'class' => 'reply-to'
  69. );
  70. $widgetContent .= $this->_buildLink( $rtLinkText, $linkAttrs );
  71. $widgetContent .= '</span>';
  72. }
  73. $widgetContent .= '</span>';
  74.  
  75. if ( 'true' == $args['showintents'] ) {
  76. $widgetContent .= ' <span class="intent-meta">';
  77. $lang = $this->_getTwitterLang();
  78. if ( !empty( $lang ) )
  79. $linkAttrs['data-lang'] = $lang;
  80.  
  81. $linkText = __( 'Reply', 'twitter-widget-pro' );
  82. $linkAttrs['href'] = "http://twitter.com/intent/tweet?in_reply_to={$tweet->id_str}";
  83. $linkAttrs['class'] = 'in-reply-to';
  84. $linkAttrs['title'] = $linkText;
  85. $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
  86.  
  87. $linkText = __( 'Retweet', 'twitter-widget-pro' );
  88. $linkAttrs['href'] = "http://twitter.com/intent/retweet?tweet_id={$tweet->id_str}";
  89. $linkAttrs['class'] = 'retweet';
  90. $linkAttrs['title'] = $linkText;
  91. $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
  92.  
  93. $linkText = __( 'Favorite', 'twitter-widget-pro' );
  94. $linkAttrs['href'] = "http://twitter.com/intent/favorite?tweet_id={$tweet->id_str}";
  95. $linkAttrs['class'] = 'favorite';
  96. $linkAttrs['title'] = $linkText;
  97. $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
  98. $widgetContent .= '</span>';
  99. }
  100. $widgetContent .= '</li>';
  101.  
  102. if ( ++$count >= $count_memory )
  103. break;
  104. }
  105. }
  106.  
  107. $widgetContent .= '</ul>';
  108. if ( 'true' == $args['showfollow'] && ! empty( $args['username'] ) ) {
  109. $widgetContent .= '<div class="follow-button">';
  110. $linkText = "@{$args['username']}";
  111. $linkAttrs = array(
  112. 'href' => "http://twitter.com/{$args['username']}",
  113. 'class' => 'twitter-follow-button',
  114. 'title' => sprintf( __( 'Follow %s', 'twitter-widget-pro' ), "@{$args['username']}" ),
  115. );
  116. $lang = $this->_getTwitterLang();
  117. if ( !empty( $lang ) )
  118. $linkAttrs['data-lang'] = $lang;
  119.  
  120. $widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
  121. $widgetContent .= '</div>';
  122. }
  123.  
  124. $widgetContent .= '</div>' . $args['after_widget'];
  125.  
  126. if ( 'true' == $args['showintents'] || 'true' == $args['showfollow'] ) {
  127. $script = 'http://platform.twitter.com/widgets.js';
  128. if ( is_ssl() )
  129. $script = str_replace( 'http://', 'https://', $script );
  130. wp_enqueue_script( 'twitter-widgets', $script, array(), '1.0.0', true );
  131.  
  132. if ( ! function_exists( '_wp_footer_scripts' ) ) {
  133. // This means we can't just enqueue our script (fixes in WP 3.3)
  134. add_action( 'wp_footer', array( $this, 'add_twitter_js' ) );
  135. }
  136. }
  137. return $widgetContent;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment