Advertisement
Kaluschar

Twitch_php_2

Jun 15th, 2018
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.19 KB | None | 0 0
  1. <?php
  2.  
  3. include(plugin_dir_path( __FILE__ ) . '/inc/Twitch.php');
  4. include(plugin_dir_path( __FILE__ ) . '/inc/Panel.php');
  5.  
  6. //Register CSS
  7. wp_register_style( 'streamsCSS', plugins_url('styles/streams.css', __FILE__) );
  8. wp_enqueue_style( 'streamsCSS' );
  9. wp_add_inline_style( 'streamsCSS', get_option('twitchwp_css_code') );
  10.  
  11. //Build Shortcodes
  12. add_shortcode("twitch-streaming-site", "streamsPage");
  13. add_shortcode("twitch-streams-list", "streamsList");
  14. add_shortcode("twitch-users", "streamUserList");
  15. add_shortcode("twitch-feature", "getFeatured");
  16. add_shortcode("twitch-status", "isLive");
  17. add_shortcode("twitch-channel", "showChannel");
  18.  
  19. //Make sure Sidebars can Read Shortcode
  20. add_filter('widget_text', 'do_shortcode');
  21.  
  22. function cacheData($data, $query, $time) {
  23. if(intval(get_option('twitchwp_do_caching')) > 0) {
  24. $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  25. $salt = get_option('twitchwp_cache_salt');
  26. $identifier = md5($actual_link."-".$query).$salt;
  27. if ( false === ( get_transient( $identifier ) ) ) {
  28. set_transient( $identifier, $data, $time);
  29. return $data;
  30. } else {
  31. return get_transient( $identifier );
  32. }
  33. }
  34. return $data;
  35. }
  36.  
  37. function isLive($atts) {
  38. $twitch = new Twitch;
  39. extract(shortcode_atts( array(
  40. 'channel' => 'twitchplayspokemon'
  41. ), $atts ));
  42.  
  43. $final = "";
  44. if($twitch->isLive($channel)) {
  45. $cdata = $twitch->getChannelStream($channel);
  46. $cdata = $cdata["stream"];
  47. $final .= "<div class='stream-status'>";
  48. $final .= "<div class='stream-icon'><img src='".$cdata["channel"]["logo"]."'></div>";
  49. $final .= "<div class='stream-data'><a href='https://twitch.tv/".$channel."'>".$cdata["channel"]["display_name"]."</a><div class='stream-info'><span class='live-icon'></span> Streaming Live<br><span class='playing-stream'>Playing ".$cdata["game"]."</span></div></div>";
  50. $final .= "</div>";
  51. } else {
  52. $cdata = $twitch->getChannel($channel);
  53. $final .= "<div class='stream-status'>";
  54. $final .= "<div class='stream-icon'><img src='".$cdata["logo"]."'></div>";
  55. $final .= "<div class='stream-data'><a href='https://twitch.tv/".$channel."'>".$cdata["display_name"]."</a><div class='stream-info'><span class='offline-icon'></span> Stream Offline<br><span class='playing-stream'>Last Playing ".$cdata["game"]."</span></div></div>";
  56. $final .= "</div>";
  57. }
  58. return $final;
  59. }
  60.  
  61. function getFeatured($atts) {
  62. $twitch = new Twitch;
  63. $final = "";
  64. extract(shortcode_atts( array(
  65. 'game' => 'League of Legends',
  66. 'user' => null
  67. ), $atts ));
  68. if(is_null($user)) {
  69. $user = $twitch->getFeatured($game);
  70. }
  71. $final .= "<div class=\"featured-home\">";
  72. $final .= "<object type=\"application/x-shockwave-flash\" height=\"645\" width=\"620\" id=\"live_embed_player_flash\" data=\"https://www.twitch.tv/widgets/live_embed_player.swf?channel=$user\" bgcolor=\"#000000\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowScriptAccess\" value=\"always\"><param name=\"allowNetworking\" value=\"all\"><param name=\"movie\" value=\"https://www.twitch.tv/widgets/live_embed_player.swf\"><param name=\"flashvars\" value=\"hostname=www.twitch.tv&amp;channel={$user}&amp;auto_play=true&amp;start_volume=25\"></object>";
  73. $final .= "</div>";
  74. return $final;
  75. }
  76.  
  77. function showChannel($atts) {
  78. $twitch = new Twitch;
  79. extract(shortcode_atts( array(
  80. 'chat' => '',
  81. 'video' => '',
  82. 'channel' => "gamebeyond"
  83. ), $atts ));
  84. $final = "";
  85. if($video!="hide") {
  86. $final .="<div class=\"stream\">";
  87. $final .="<object type=\"application/x-shockwave-flash\" height=\"245\" width=\"100%\" id=\"live_embed_player_flash\" data=\"https://www.twitch.tv/widgets/live_embed_player.swf?channel=".$channel." bgcolor=\"#000000\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowScriptAccess\" value=\"always\"><param name=\"wmode\" value=\"transparent\"><param name=\"allowNetworking\" value=\"all\"><param name=\"movie\" value=\"https://www.twitch.tv/widgets/live_embed_player.swf\"><param name=\"flashvars\" value=\"hostname=www.twitch.tv&amp;channel=".$channel."&amp;auto_play=true&amp;start_volume=25\"></object>";
  88. $final .="</div>";
  89. }
  90. if($chat!="hide") {
  91. $final .="<div class=\"stream-chat\">";
  92. $final .="<iframe style=\"width:100%; height: 245px;\" frameborder=\"0\" scrolling=\"no\" id=\"chat_embed\" src=\"https://twitch.tv/".$channel."/chat?popout=\"></iframe>";
  93. $final .="</div>";
  94. }
  95. return $final;
  96. }
  97.  
  98. function streamsList($atts) {
  99. $twitch = new Twitch;
  100. $final = "";
  101. $cachetime = 1 * HOUR_IN_SECONDS;
  102. extract(shortcode_atts( array(
  103. 'count' => '12',
  104. 'paginate' => true,
  105. 'game' => 'League of Legends'
  106. ), $atts ));
  107. if($paginate=="false") {
  108. $paginate = false;
  109. }
  110. $page = isset($_GET["pg"]) ? $_GET["pg"] : 1;
  111. $final.= "<div class=\"streams-container\">".cacheData($twitch->getStreams($game,$page,intval($count),$paginate), "streamList", $cacheTime)."</div>";
  112. if(isset($_GET['channel'])) {
  113. $channel = $_GET['channel'];
  114. $final = streamVideo($channel);
  115. $final .= streamChat($channel);
  116. }
  117. return $final;
  118. }
  119.  
  120. function streamUserList($atts) {
  121. $twitch = new Twitch;
  122. $final = "";
  123. $cachetime = 1 * HOUR_IN_SECONDS;
  124. extract(shortcode_atts( array(
  125. 'channels' => 'the_aaron,mega64podcast',
  126. 'showoffline' => 'true'
  127. ), $atts ));
  128. $final.= "<div class=\"streams-container\">".cacheData($twitch->getUserStreams2($channels, $showoffline), "streamersList", $cachetime)."</div>";
  129. if(isset($_GET['channel'])) {
  130. $channel = $_GET['channel'];
  131. $final = streamVideo($channel);
  132. $final .= streamChat($channel);
  133. }
  134. return $final;
  135. }
  136. function streamsPage() {
  137. $twitch = new Twitch;
  138. $final = "";
  139. $cachetime = 1 * HOUR_IN_SECONDS;
  140. if(isset($_GET["game"])) {
  141. $final.="<h1 style='margin-bottom:20px;'>".urldecode($_GET["game"])." Live Streams</h1>";
  142. if(isset($_GET["pg"])) {
  143. $page = $_GET["pg"];
  144. } else {
  145. $page = 1;
  146. }
  147. $streamList = cacheData($twitch->getStreams($_GET["game"],$page,12,true), "streamsPageGame", $cachetime);
  148. $final.= "<div class=\"streams-container\">".$streamList."</div>";
  149. } else if(isset($_GET["channel"])) {
  150. $channel = urldecode($_GET["channel"]);
  151. $final .= streamVideo($channel);
  152. $final .= streamChat($channel);
  153. } else {
  154. $final .="<div class=\"game-wrapper\">";
  155.  
  156. $games = cacheData($twitch->getGames(98), "streamsPage", $cachetime);
  157. foreach ($games as $game) {
  158. $gName = $game["game"]["name"];
  159. $gLink = "?game=".urlencode($game["game"]["name"]);
  160. $gArt = $game["game"]["box"]["medium"];
  161. $final.="<div class=\"game\"><a href='".$gLink."'><img src='".$gArt."''></a></div>";
  162. }
  163. $final.="</div>";
  164. }
  165. return $final;
  166. }
  167.  
  168. function streamVideo($channel) {
  169. $final = "";
  170. $final .="<div class=\"stream\">";
  171. $final .="<iframe src=\"https://www.twitch.tv/".$channel."/embed\" frameborder=\"0\" scrolling=\"no\" height=\"606\" width=\"100%\"allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>";
  172. //$final .="<object type=\"application/x-shockwave-flash\" height=\"600\" width=\"100%\" id=\"live_embed_player_flash\" data=\"https://www.twitch.tv/widgets/live_embed_player.swf?channel=".$channel." bgcolor=\"#000000\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowScriptAccess\" value=\"always\"><param name=\"wmode\" value=\"transparent\"><param name=\"allowNetworking\" value=\"all\"><param name=\"movie\" value=\"https://www.twitch.tv/widgets/live_embed_player.swf\"><param name=\"flashvars\" value=\"hostname=www.twitch.tv&amp;channel=".$channel."&amp;auto_play=true&amp;start_volume=25\"></object>";
  173. $final .="</div>";
  174. return $final;
  175. }
  176.  
  177. function streamChat($channel) {
  178. $final .="<div class=\"stream-chat\">";
  179. $final .="<iframe style=\"width:100%; height: 660px;\" frameborder=\"0\" scrolling=\"no\" id=\"chat_embed\" src=\"https://twitch.tv/embed/".$channel."/chat?popout=\"></iframe>";
  180. $final .="</div>";
  181. return $final;
  182. }
  183.  
  184. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement