Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include(plugin_dir_path( __FILE__ ) . '/inc/Twitch.php');
- include(plugin_dir_path( __FILE__ ) . '/inc/Panel.php');
- //Register CSS
- wp_register_style( 'streamsCSS', plugins_url('styles/streams.css', __FILE__) );
- wp_enqueue_style( 'streamsCSS' );
- wp_add_inline_style( 'streamsCSS', get_option('twitchwp_css_code') );
- //Build Shortcodes
- add_shortcode("twitch-streaming-site", "streamsPage");
- add_shortcode("twitch-streams-list", "streamsList");
- add_shortcode("twitch-users", "streamUserList");
- add_shortcode("twitch-feature", "getFeatured");
- add_shortcode("twitch-status", "isLive");
- add_shortcode("twitch-channel", "showChannel");
- //Make sure Sidebars can Read Shortcode
- add_filter('widget_text', 'do_shortcode');
- function cacheData($data, $query, $time) {
- if(intval(get_option('twitchwp_do_caching')) > 0) {
- $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
- $salt = get_option('twitchwp_cache_salt');
- $identifier = md5($actual_link."-".$query).$salt;
- if ( false === ( get_transient( $identifier ) ) ) {
- set_transient( $identifier, $data, $time);
- return $data;
- } else {
- return get_transient( $identifier );
- }
- }
- return $data;
- }
- function isLive($atts) {
- $twitch = new Twitch;
- extract(shortcode_atts( array(
- 'channel' => 'twitchplayspokemon'
- ), $atts ));
- $final = "";
- if($twitch->isLive($channel)) {
- $cdata = $twitch->getChannelStream($channel);
- $cdata = $cdata["stream"];
- $final .= "<div class='stream-status'>";
- $final .= "<div class='stream-icon'><img src='".$cdata["channel"]["logo"]."'></div>";
- $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>";
- $final .= "</div>";
- } else {
- $cdata = $twitch->getChannel($channel);
- $final .= "<div class='stream-status'>";
- $final .= "<div class='stream-icon'><img src='".$cdata["logo"]."'></div>";
- $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>";
- $final .= "</div>";
- }
- return $final;
- }
- function getFeatured($atts) {
- $twitch = new Twitch;
- $final = "";
- extract(shortcode_atts( array(
- 'game' => 'League of Legends',
- 'user' => null
- ), $atts ));
- if(is_null($user)) {
- $user = $twitch->getFeatured($game);
- }
- $final .= "<div class=\"featured-home\">";
- $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&channel={$user}&auto_play=true&start_volume=25\"></object>";
- $final .= "</div>";
- return $final;
- }
- function showChannel($atts) {
- $twitch = new Twitch;
- extract(shortcode_atts( array(
- 'chat' => '',
- 'video' => '',
- 'channel' => "gamebeyond"
- ), $atts ));
- $final = "";
- if($video!="hide") {
- $final .="<div class=\"stream\">";
- $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&channel=".$channel."&auto_play=true&start_volume=25\"></object>";
- $final .="</div>";
- }
- if($chat!="hide") {
- $final .="<div class=\"stream-chat\">";
- $final .="<iframe style=\"width:100%; height: 245px;\" frameborder=\"0\" scrolling=\"no\" id=\"chat_embed\" src=\"https://twitch.tv/".$channel."/chat?popout=\"></iframe>";
- $final .="</div>";
- }
- return $final;
- }
- function streamsList($atts) {
- $twitch = new Twitch;
- $final = "";
- $cachetime = 1 * HOUR_IN_SECONDS;
- extract(shortcode_atts( array(
- 'count' => '12',
- 'paginate' => true,
- 'game' => 'League of Legends'
- ), $atts ));
- if($paginate=="false") {
- $paginate = false;
- }
- $page = isset($_GET["pg"]) ? $_GET["pg"] : 1;
- $final.= "<div class=\"streams-container\">".cacheData($twitch->getStreams($game,$page,intval($count),$paginate), "streamList", $cacheTime)."</div>";
- if(isset($_GET['channel'])) {
- $channel = $_GET['channel'];
- $final = streamVideo($channel);
- $final .= streamChat($channel);
- }
- return $final;
- }
- function streamUserList($atts) {
- $twitch = new Twitch;
- $final = "";
- $cachetime = 1 * HOUR_IN_SECONDS;
- extract(shortcode_atts( array(
- 'channels' => 'the_aaron,mega64podcast',
- 'showoffline' => 'true'
- ), $atts ));
- $final.= "<div class=\"streams-container\">".cacheData($twitch->getUserStreams2($channels, $showoffline), "streamersList", $cachetime)."</div>";
- if(isset($_GET['channel'])) {
- $channel = $_GET['channel'];
- $final = streamVideo($channel);
- $final .= streamChat($channel);
- }
- return $final;
- }
- function streamsPage() {
- $twitch = new Twitch;
- $final = "";
- $cachetime = 1 * HOUR_IN_SECONDS;
- if(isset($_GET["game"])) {
- $final.="<h1 style='margin-bottom:20px;'>".urldecode($_GET["game"])." Live Streams</h1>";
- if(isset($_GET["pg"])) {
- $page = $_GET["pg"];
- } else {
- $page = 1;
- }
- $streamList = cacheData($twitch->getStreams($_GET["game"],$page,12,true), "streamsPageGame", $cachetime);
- $final.= "<div class=\"streams-container\">".$streamList."</div>";
- } else if(isset($_GET["channel"])) {
- $channel = urldecode($_GET["channel"]);
- $final .= streamVideo($channel);
- $final .= streamChat($channel);
- } else {
- $final .="<div class=\"game-wrapper\">";
- $games = cacheData($twitch->getGames(98), "streamsPage", $cachetime);
- foreach ($games as $game) {
- $gName = $game["game"]["name"];
- $gLink = "?game=".urlencode($game["game"]["name"]);
- $gArt = $game["game"]["box"]["medium"];
- $final.="<div class=\"game\"><a href='".$gLink."'><img src='".$gArt."''></a></div>";
- }
- $final.="</div>";
- }
- return $final;
- }
- function streamVideo($channel) {
- $final = "";
- $final .="<div class=\"stream\">";
- $final .="<iframe src=\"https://www.twitch.tv/".$channel."/embed\" frameborder=\"0\" scrolling=\"no\" height=\"606\" width=\"100%\"allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>";
- //$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&channel=".$channel."&auto_play=true&start_volume=25\"></object>";
- $final .="</div>";
- return $final;
- }
- function streamChat($channel) {
- $final .="<div class=\"stream-chat\">";
- $final .="<iframe style=\"width:100%; height: 660px;\" frameborder=\"0\" scrolling=\"no\" id=\"chat_embed\" src=\"https://twitch.tv/embed/".$channel."/chat?popout=\"></iframe>";
- $final .="</div>";
- return $final;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement