فهرست منبع

plugin_auth_emby_connect bugfix2

Cerothen 9 سال پیش
والد
کامیت
dee67d5465
1فایلهای تغییر یافته به همراه30 افزوده شده و 30 حذف شده
  1. 30 30
      functions.php

+ 30 - 30
functions.php

@@ -62,35 +62,39 @@ function plugin_auth_emby_connect($username, $password) {
 	// Get A User
 	$connectId = '';
 	$userIds = json_decode(file_get_contents($embyAddress.'/Users?api_key='.EMBYTOKEN),true);
-	foreach ($userIds as $value) { // Scan for this user
-		if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
-			if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
-				$connectId = $value['ConnectUserId'];
+	if (is_array($userIds)) {
+		foreach ($userIds as $key => $value) { // Scan for this user
+			if (isset($value['ConnectUserName']) && isset($value['ConnectUserId'])) { // Qualifty as connect account
+				if ($value['ConnectUserName'] == $username || $value['Name'] == $username) {
+					$connectId = $value['ConnectUserId'];
+					break;
+				}
+				
 			}
-			break;
 		}
-	}
-	
-	if ($connectId) {
-		$connectURL = 'https://connect.emby.media/service/user/authenticate';
-		$headers = array(
-			'Accept'=> 'application/json',
-			'Content-Type' => 'application/x-www-form-urlencoded',
-		);
-		$body = array(
-			'nameOrEmail' => $username,
-			'rawpw' => $password,
-		);
 		
-		$result = curl_post($connectURL, $body, $headers);
-		
-		if (isset($response['content'])) {
-			$json = json_decode($response['content'], true);
-			if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
-				return true;
+		if ($connectId) {
+			$connectURL = 'https://connect.emby.media/service/user/authenticate';
+			$headers = array(
+				'Accept'=> 'application/json',
+				'Content-Type' => 'application/x-www-form-urlencoded',
+			);
+			$body = array(
+				'nameOrEmail' => $username,
+				'rawpw' => $password,
+			);
+			
+			$result = curl_post($connectURL, $body, $headers);
+			
+			if (isset($result['content'])) {
+				$json = json_decode($result['content'], true);
+				if (is_array($json) && isset($json['SessionInfo']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
+					return true;
+				}
 			}
 		}
 	}
+	
 	return false;
 }
 
@@ -346,7 +350,7 @@ function resolvePlexItem($server, $token, $item) {
 	
 	$address = "https://app.plex.tv/web/app#!/server/$server/details?key=/library/metadata/".$item['ratingKey'];
 	
-	switch ($item['Type']) {
+	switch ($item['type']) {
 		case 'season':
 			$title = $item['parentTitle'];
 			$summary = $item['parentSummary'];
@@ -448,9 +452,7 @@ function getPlexStreams($url, $port, $token, $size, $header){
     $getServer = simplexml_load_string($getServer);
     
 	// Identify the local machine
-    foreach($getServer AS $child) {
-       $gotServer = $child['machineIdentifier'];
-    }
+    $gotServer = $getServer['machineIdentifier'];
 	
 	$items = array();
 	foreach($api AS $child) {
@@ -527,9 +529,7 @@ function getPlexRecent($url, $port, $type, $token, $size, $header){
     $getServer = simplexml_load_string($getServer);
 	
 	// Identify the local machine
-    foreach($getServer AS $child) {
-       $gotServer = $child['machineIdentifier'];
-    }
+    $gotServer = $getServer['machineIdentifier'];
 	
 	$items = array();
 	foreach($api AS $child) {