DB_Twitter_HTML

The DevBuddy Twitter Feed Plugin DB Twitter HTML class.

Defined (1)

The class is defined in the following location(s).

/lib/class.feed-html.php  
  1. class DB_Twitter_HTML { 
  2.  
  3. /** 
  4. * @var array Used to hold an individual tweet's data 
  5. * @since 1.0.0 
  6. */ 
  7. public $tweet; 
  8.  
  9. /** 
  10. * @var array Holds the options for the feed instance 
  11. * @since 1.0.0 
  12. */ 
  13. public $options; 
  14.  
  15. /** 
  16. * @var string Main Twitter URL 
  17. * @since 1.0.0 
  18. */ 
  19. public $tw; 
  20.  
  21. /** 
  22. * @var string Twitter search URL 
  23. * @since 1.0.0 
  24. */ 
  25. public $search; 
  26.  
  27. /** 
  28. * @var string Twitter intent URL 
  29. * @since 1.0.0 
  30. */ 
  31. public $intent; 
  32.  
  33.  
  34. /** 
  35. * Grab and assign data essential for the rendered output 
  36. * @access public 
  37. * @return void 
  38. * @param $options array The feed configuration for a feed instance 
  39. * @param $url_data array The URL that will be necessary within the feed 
  40. */ 
  41. public function __construct( $options, $url_data ) { 
  42. $this->options = $options; 
  43. $this->tw = $url_data['tw']; 
  44. $this->search = $url_data['search']; 
  45. $this->intent = $url_data['intent']; 
  46.  
  47.  
  48. /** 
  49. * Sets the tweet data to be used while rendering 
  50. * @access public 
  51. * @return void 
  52. * @param $tweet array The array of data to be used 
  53. */ 
  54. public function set( $tweet ) { 
  55. $this->tweet = $tweet; 
  56.  
  57.  
  58. /** 
  59. * Returns the opening element for a tweet 
  60. * @access public 
  61. * @return string 
  62. */ 
  63. public function open_tweet() { 
  64. $output = '<article class="tweet">'; 
  65.  
  66. return $output; 
  67.  
  68.  
  69. /** 
  70. * Returns the closing element for a tweet 
  71. * @access public 
  72. * @return string 
  73. */ 
  74. public function close_tweet() { 
  75. $output = '</article>'; 
  76.  
  77. return $output; 
  78.  
  79.  
  80. /** 
  81. * Returns the opening element for a tweet's content 
  82. * @access public 
  83. * @return string 
  84. */ 
  85. public function open_tweet_content() { 
  86. $output = '<div class="tweet_content">'; 
  87.  
  88. return $output; 
  89.  
  90.  
  91. /** 
  92. * Returns the closing element for a tweet's content 
  93. * @access public 
  94. * @return string 
  95. */ 
  96. public function close_tweet_content() { 
  97. $output = '</div>'; 
  98.  
  99. return $output; 
  100.  
  101.  
  102. /** 
  103. * Returns the opening element for a generic div used to wrap around a tweet's meta information 
  104. * @access public 
  105. * @return string 
  106. */ 
  107. public function open_tweet_primary_meta() { 
  108. $output = '<div class="tweet_primary_meta">'; 
  109.  
  110. return $output; 
  111.  
  112.  
  113. /** 
  114. * Returns the closing element for a generic div used to wrap around a tweet's meta information 
  115. * @access public 
  116. * @return string 
  117. */ 
  118. public function close_tweet_primary_meta() { 
  119. $output = '</div>'; 
  120.  
  121. return $output; 
  122.  
  123.  
  124. /** 
  125. * Returns the opening element for a generic div used to wrap around a tweet's meta information 
  126. * @access public 
  127. * @return string 
  128. */ 
  129. public function open_tweet_secondary_meta() { 
  130. $output = '<div class="tweet_secondary_meta">'; 
  131.  
  132. return $output; 
  133.  
  134.  
  135. /** 
  136. * Returns the closing element for a generic div used to wrap around a tweet's meta information 
  137. * @access public 
  138. * @return string 
  139. */ 
  140. public function close_tweet_secondary_meta() { 
  141. $output = '</div>'; 
  142.  
  143. return $output; 
  144.  
  145.  
  146. /** 
  147. * Returns the display name as a link along with the Twitter handle, which is left unlinked 
  148. * @access public 
  149. * @return string 
  150. */ 
  151. public function tweet_display_name_link() { 
  152. $output = '<a href="' . $this->tw . $this->tweet['user_screen_name'] . '" target="_blank" class="tweet_user" title="' . $this->tweet['user_description'] . '">' . $this->tweet['user_display_name'] . '</a>'; 
  153. $output .= ' <span class="tweet_screen_name">@' . $this->tweet['user_screen_name'] . '</span>'; 
  154.  
  155. return $output; 
  156.  
  157.  
  158. /** 
  159. * Returns the display picture 
  160. * @access public 
  161. * @return string 
  162. */ 
  163. public function tweet_display_pic() { 
  164. $output = '<figure class="tweet_profile_img">'; 
  165. $output .= '<a href="' . $this->tw . $this->tweet['user_screen_name'] . '" target="_blank" title="' . $this->tweet['user_display_name'] . '"><img src="' . $this->tweet_media_src( 'profile_img' ) . '" alt="' . $this->tweet['user_display_name'] . '" /></a>'; 
  166. $output .= '</figure>'; 
  167.  
  168. return $output; 
  169.  
  170.  
  171. /** 
  172. * Returns the tweet text 
  173. * @access public 
  174. * @return string 
  175. */ 
  176. public function tweet_text() { 
  177. $output = '<div class="tweet_text">' . $this->tweet['text'] . '</div>'; 
  178.  
  179. return $output; 
  180.  
  181.  
  182. /** 
  183. * Returns the HTML for the media item associated with the tweet 
  184. * @access public 
  185. * @return string 
  186. */ 
  187. public function tweet_media() { 
  188. $output = ''; 
  189.  
  190. if ( isset( $this->tweet['media'] ) ) { 
  191. $output .= '<div class="tweet_media">'; 
  192.  
  193. switch ( $this->tweet['media'][0]['type'] ) { 
  194. case 'photo': 
  195. if ( isset( $this->options['show_images'] ) && $this->options['show_images'] === 'yes' ) { 
  196. $output .= '<a href="' . $this->tweet['media'][0]['expanded_url'] . '" target="_blank">'; 
  197. $output .= '<img src="' . $this->tweet_media_src( 'embedded_img' ) . '" alt="" />'; 
  198. $output .= '</a>'; 
  199. break; 
  200.  
  201. default: 
  202. $output .= ''; 
  203. break; 
  204.  
  205. $output .= '</div>'; 
  206.  
  207. return $output; 
  208.  
  209.  
  210. /** 
  211. * Returns the date at which the tweet was posted as a hyperlink to the post itself 
  212. * @access public 
  213. * @return string 
  214. */ 
  215. public function tweet_date() { 
  216. $output = '<a href="' . $this->url_to_tweet().'" target="_blank" title="View this tweet in Twitter" class="tweet_date">' . $this->tweet['date'] . '</a>'; 
  217.  
  218. return $output; 
  219.  
  220.  
  221. /** 
  222. * Returns the retweet information should the tweet indeed be a retweet 
  223. * @access public 
  224. * @return string 
  225. */ 
  226. public function tweet_retweeted() { 
  227. $output = ''; 
  228.  
  229. if ( $this->tweet['is_retweet'] ) { 
  230. $output .= '<span class="tweet_retweet">'; 
  231. $output .= '<span class="tweet_icon tweet_icon_retweet"></span>'; 
  232. $output .= 'Retweeted by '; 
  233. $output .= '<a href="' . $this->tw . $this->tweet['retweeter_screen_name'] . '" target="_blank" title="' . $this->tweet['retweeter_display_name'] . '">' . $this->tweet['retweeter_display_name'] . '</a>'; 
  234. $output .= '</span>'; 
  235.  
  236. return $output; 
  237.  
  238.  
  239. /** 
  240. * Returns actions that end users can use to interact with the tweet: reply, retweet, and favourite 
  241. * @access public 
  242. * @return string 
  243. */ 
  244. public function tweet_intents() { 
  245. $output = '<div class="tweet_intents">'; 
  246.  
  247. // START Reply intent 
  248. $output .= '<a href="' . $this->intent.'tweet?in_reply_to=' . $this->tweet['id'] . '" title="Reply to this tweet" target="_blank" class="tweet_intent tweet_intent_reply">'; 
  249. $output .= '<span class="tweet_icon tweet_icon_reply"></span>'; 
  250. $output .= '<b class="tweet_intent_txt">Reply</b></a>'; 
  251. // END Reply intent 
  252.  
  253. // START Retweet intent 
  254. $output .= '<a href="' . $this->intent.'retweet?tweet_id=' . $this->tweet['id'] . '" title="Retweet this tweet" target="_blank" class="tweet_intent tweet_intent_retweet">'; 
  255. $output .= '<span class="tweet_icon tweet_icon_retweet"></span>'; 
  256. $output .= '<b class="tweet_intent_txt">Retweet</b></a>'; 
  257. // END Retweet intent 
  258.  
  259. // START Favourite intent 
  260. $output .= '<a href="' . $this->intent.'favorite?tweet_id=' . $this->tweet['id'] . '" title="Favourite this tweet" target="_blank" class="tweet_intent tweet_intent_favourite">'; 
  261. $output .= '<span class="tweet_icon tweet_icon_favourite"></span>'; 
  262. $output .= '<b class="tweet_intent_txt">Favourite</b></a>'; 
  263. // END Favourite intent 
  264.  
  265. $output .= '</div>'; 
  266. // END Tweet intents 
  267.  
  268. return $output; 
  269.  
  270.  
  271. /** 
  272. * Returns the URL to the tweet in Twitter 
  273. * @access public 
  274. * @return string 
  275. */ 
  276. public function url_to_tweet() { 
  277. $output = $this->tw . $this->tweet['user_screen_name'] . '/status/' . $this->tweet['id']; 
  278.  
  279. return $output; 
  280.  
  281.  
  282. /** 
  283. * Returns the URL for the media item given. Checks for HTTPS 
  284. * @access public 
  285. * @return string 
  286. */ 
  287. public function tweet_media_src( $media_item ) { 
  288. $media_item = strtolower($media_item); 
  289.  
  290. $media_src = ''; 
  291. $https = ''; 
  292.  
  293. if ( isset( $this->options['https'] ) && $this->options['https'] === 'yes' ) { 
  294. $https = '_https'; 
  295.  
  296. switch ( $media_item ) { 
  297. case 'profile_img': 
  298. $media_src = $this->tweet['profile_img_url' . $https]; 
  299. break; 
  300.  
  301. case 'embedded_img': 
  302. $media_src = $this->tweet['media'][0]['media_url' . $https]; 
  303. break; 
  304.  
  305. return $media_src; 
  306.  
  307. } // END class