Forráskód Böngészése

Added twitch support

Janco Kock 9 éve
szülő
commit
b34c28339a
9 módosított fájl, 177 hozzáadás és 29 törlés
  1. 20 16
      alarmen/toevoegen.php
  2. 1 8
      alarmen/wijzigen.php
  3. 30 0
      getTwitch.php
  4. 1 1
      includes/footer.php
  5. 9 1
      includes/nav.php
  6. 3 3
      register.php
  7. 24 0
      twitch.php
  8. 38 0
      twitch/configuration.php
  9. 51 0
      twitch/overzicht.php

+ 20 - 16
alarmen/toevoegen.php

@@ -7,17 +7,25 @@
 	    $streamport = safeString($_POST["StreamPort"]);
 	    $snoozetijd = safeString($_POST["snoozetijd"]);
 
-		$streamdomain = $streamurl;
-		$streamsplit = parse_url($streamurl);
-		$streamip = gethostbyname($streamsplit["host"]);
-		$streamurl = $streamsplit["path"];
-		
-	    if($stmt = $mysqli -> prepare("INSERT INTO alarm(message,name,streamip, streamurl, streamport, tijd, snoozetijd, streamdomain, uid) VALUES(?,?,?,?,?,?,?,?,?)")){
-	    	$stmt ->bind_param("ssssisisi", $message, $alarmname, $streamip,  $streamurl, $streamport, $tijd, $snoozetijd, $streamdomain, $userid);
-	    	$stmt ->execute();
-	    	$stmt ->close();
-	    }
-	    reDirect("alarmen.php?i=overzicht");
+		if (filter_var($streamurl, FILTER_VALIDATE_URL) === FALSE) {
+			 print('
+		    <div class="alert alert-danger alert-dismissable">
+	            <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>Stream url ongeldig
+	        </div>
+		    ');
+		}else{
+			$streamdomain = $streamurl;
+			$streamsplit = parse_url($streamurl);
+			$streamip = gethostbyname($streamsplit["host"]);
+			$streamurl = $streamsplit["path"];
+			
+		    if($stmt = $mysqli -> prepare("INSERT INTO alarm(message,name,streamip, streamurl, streamport, tijd, snoozetijd, streamdomain, uid) VALUES(?,?,?,?,?,?,?,?,?)")){
+		    	$stmt ->bind_param("ssssisisi", $message, $alarmname, $streamip,  $streamurl, $streamport, $tijd, $snoozetijd, $streamdomain, $userid);
+		    	$stmt ->execute();
+		    	$stmt ->close();
+		    }
+		    reDirect("alarmen.php?i=overzicht");			
+		}
 	}
 ?>
 
@@ -32,10 +40,6 @@
 				<a class="dropdown-toggle" data-toggle="dropdown" href="#">
 					<i class="fa fa-wrench"></i>
 				</a>
-				<ul class="dropdown-menu dropdown-user">
-					<li><a href="#">Alarm toevoegen</a></li>
-					<li><a href="#">Alle alarmen verwijderen</a></li>
-				</ul>
 			</div>
 		</div>
 		<div class="ibox-content">
@@ -77,7 +81,7 @@
 				<div class="form-group">
 					<label class="col-sm-2 control-label">Streamurl</label>
 					<div class="col-sm-8">
-						<input type="text" maxlength="48" required name = "StreamUrl" class="form-control">
+						<input type="url" maxlength="48" required name = "StreamUrl" class="form-control">
 					</div>
 					<div class="col-sm-2">
 						<input type="number" min"0" max="9999" value="80" required name = "StreamPort" class="form-control">

+ 1 - 8
alarmen/wijzigen.php

@@ -48,18 +48,11 @@
 <div class="col-lg-12">
     <div class="ibox float-e-margins">
         <div class="ibox-title">
-            <h5>Alarmen overzicht</h5>
+            <h5>Alarm wijzigen</h5>
             <div class="ibox-tools">
                 <a class="collapse-link">
                     <i class="fa fa-chevron-up"></i>
                 </a>
-                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
-                    <i class="fa fa-wrench"></i>
-                </a>
-                <ul class="dropdown-menu dropdown-user">
-                    <li><a href="#">Alarm toevoegen</a></li>
-                    <li><a href="#">Alle alarmen verwijderen</a></li>
-                </ul>
             </div>
         </div>
         <div class="ibox-content">

+ 30 - 0
getTwitch.php

@@ -0,0 +1,30 @@
+<?php
+	include_once('includes/db_connect.php');
+	include_once('includes/global_functions.php');
+    $radioid = $_GET['radioid'];
+    $radiomac = $_GET['radiomac'];
+        
+    if($radioid == "" && $radiomac == ""){
+        print(json_encode([error => "Not a valid radioid"]));
+        die();
+    }else{
+        if($radiomac != ""){
+            $radiomac = str_replace(':', '', $radiomac);
+            $radioid = substr($radiomac, 6 , 11);
+        }
+        
+        $array = array();
+       	if($stmt = $mysqli -> prepare("SELECT username FROM Twitch LEFT JOIN users ON Twitch.uid = users.uid WHERE users.radiotoken = ?")){
+        	$stmt -> bind_param("s", $radioid);
+        	$stmt -> execute();
+        	$stmt -> bind_result($TwitchUsername);
+        	while($result = $stmt -> fetch()){
+        	    array_push($array, array(   username =>$TwitchUsername) 
+        	               );
+        	 };
+        	$stmt -> close();
+       	}
+        print(json_encode($array, JSON_UNESCAPED_SLASHES));
+    }
+    
+    

+ 1 - 1
includes/footer.php

@@ -49,7 +49,7 @@
    <script src="includes/js/plugins/jsKnob/jquery.knob.js"></script>
  
      <script>
-    	var pages = ["index.php", "alarmen.php", "streams.php"];
+    	var pages = ["index.php", "alarmen.php", "streams.php", "twitch.php","twitter.php"];
     	var found = false;
     	for(x in pages){
     		if(document.URL.indexOf(pages[x]) > -1){

+ 9 - 1
includes/nav.php

@@ -37,7 +37,15 @@
 				<li id="streams.php">
 					<a href="streams.php?i=overzicht"><i class="fa fa-briefcase"></i> <span class="nav-label">Internet stations</span></a>
 				</li>
-				<li id=
+				<li id="twitch.php">
+					<a href="twitch.php?i=overzicht"><i class="fa fa-twitch"></i> <span class="nav-label">Twitch</span></a>
+				</li>
+				<li id="twitter.php">
+					<a href="twitter.php?i=overzicht"><i class="fa fa-twitter"></i> <span class="nav-label">Twitter</span></a>
+				</li>
+					<li id="getTwitter.php">
+					<a href="getTwitter.php?i=overzicht"><i class="fa fa-twitter"></i> <span class="nav-label">Twitter</span></a>
+				</li>
 			</ul>
 		</div>
 	</nav>

+ 3 - 3
register.php

@@ -52,9 +52,9 @@
             			$stmt1 -> close();
             		}
             		if(!isset($id) || $id != ""){
-            		    print('<div class="alert alert-error">
-                                Uw gebruikersnaam of radiotoken is al in gebruik. 
-                               </div>');
+            		    print('	    <div style="color: red" class="alert alert-danger alert-dismissable">
+                                        <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>Gebruikersnaam of radiotoken al in gebruik.
+                                    </div>');
             		}else{
             			include("includes/crypt.php");
             			$phash = password_hash($password, PASSWORD_DEFAULT);

+ 24 - 0
twitch.php

@@ -0,0 +1,24 @@
+<?php 
+	include_once("includes/header.php");
+	include_once("includes/nav.php");
+	$a = array (
+		'overzicht'	=> 1,
+		'configuration' => 1,
+	); 
+	if(isset($_GET["i"])){
+		if($_GET["i"] == ""){
+			@include('twitch/overzicht.php');
+		}
+		else{
+			if(isset($a[$_GET["i"]])){	
+				@include('twitch/'.$_GET["i"].'.php');
+			}else{
+				echo '<h1>Deze pagina bestaat helaas niet.</h1>';
+			}
+		}
+	}else{
+		@include('twitch/overzicht.php');
+	}
+	
+	include_once("includes/footer.php");
+?>

+ 38 - 0
twitch/configuration.php

@@ -0,0 +1,38 @@
+<?php
+	if($_SERVER['REQUEST_METHOD'] == "POST"){
+		$twitchUsername = safeString($_POST["twitchUsername"]);
+
+	   if($stmt = $mysqli -> prepare("INSERT INTO Twitch(uid,username) VALUES(?,?) ON DUPLICATE KEY UPDATE username=VALUES(username)")){
+        	$stmt -> bind_param("is",$userid,$twitchUsername);
+        	$stmt -> execute();
+        	$stmt -> close();
+        } 
+	}
+?>
+
+<div class="col-lg-12">
+    <div class="ibox float-e-margins">
+        <div class="ibox-title">
+            <h5>Configureer Twitch account</h5>
+            <div class="ibox-tools">
+                <a class="collapse-link">
+                    <i class="fa fa-chevron-up"></i>
+                </a>
+            </div>
+        </div>
+        <div class="ibox-content">
+            <form method="POST" class="form-horizontal">
+                <div class="form-group"><label class="col-sm-2 control-label">Naam</label>
+                    <div class="col-sm-10"><input name="twitchUsername" type="text" class="form-control"></div>
+                </div>
+		        <div class="form-group">
+                        <div class="col-sm-4 col-sm-offset-2">
+                        <button class="btn btn-primary" type="submit">Naam opslaan</button>
+                        <a href="twitch.php?i=overzicht" class="btn btn-primary" role="button">Annuleren</a>
+                    </div>
+                </div>
+            </form>
+        </div>
+    </div>
+</div>
+

+ 51 - 0
twitch/overzicht.php

@@ -0,0 +1,51 @@
+<?php
+error_reporting(-1); ini_set('display_errors', 'On'); 
+error_reporting(E_ALL);
+ini_set("display_errors", 1);
+if($stmt = $mysqli -> prepare("SELECT username FROM Twitch WHERE uid = ?")){
+	$stmt -> bind_param("i", $userid);
+	$stmt -> execute();
+	$stmt -> bind_result($TwitchUsername);
+	$stmt -> fetch();
+	$stmt -> close();
+}
+
+$ch = curl_init(); 
+curl_setopt($ch, CURLOPT_URL, "https://api.twitch.tv/kraken/users/".$TwitchUsername."/follows/channels"); 
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
+$jsonreturn = json_decode(curl_exec($ch), true);
+//$jsonreturn = curl_exec($ch);
+?>
+<div class="col-lg-12">
+    <div class="ibox float-e-margins">
+        <div class="ibox-title">
+            <h5>Twitch Integratie</h5>
+            <div class="ibox-tools">
+                <a class="collapse-link">
+                    <i class="fa fa-chevron-up"></i>
+                </a>
+                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+                    <i class="fa fa-wrench"></i>
+                </a>
+                <ul class="dropdown-menu dropdown-user">
+                    <li><a href="twitch.php?i=configuration">Configure Twitch Account</a></li>
+                </ul>
+                <a class="close-link">
+                    <i class="fa fa-times"></i>
+                </a>
+            </div>
+        </div>
+        <div class="ibox-content">
+            <label>Ingelogd als: <?php print($TwitchUsername); ?> </label>
+            <br />
+            <label>Aan het volgen:</label>
+            <br />
+            <label><?php
+            for($x = 0; $x < count($jsonreturn["follows"]); $x++ )
+            {
+                echo $jsonreturn["follows"][$x]["channel"]["display_name"]."<br />";
+            }
+            ?></label>
+        </div>
+    </div>
+</div>