Browse Source

Emby recent user matching and only unplayed if matches

Cerothen 9 years ago
parent
commit
3b2d766f40
4 changed files with 22 additions and 5 deletions
  1. 3 1
      ajax.php
  2. 13 2
      functions.php
  3. 3 1
      settings.php
  4. 3 1
      user.php

+ 3 - 1
ajax.php

@@ -1,6 +1,8 @@
 <?php
-// Include functions if not already included
+// Include functions and user
 require_once('functions.php');
+require_once("user.php");
+$GLOBALS['USER'] = new User('registration_callback');
 
 // Upgrade environment
 upgradeCheck();

+ 13 - 2
functions.php

@@ -611,6 +611,12 @@ function getPlexStreams($size){
 function getEmbyRecent($type, $size) {
     $address = qualifyURL(EMBYURL);
 	
+	// Currently Logged In User
+	$username = false;
+	if (isset($GLOBALS['USER'])) {
+		$username = strtolower($GLOBALS['USER']->username);
+	}
+	
 	// Resolve Types
 	switch ($type) {
 		case 'movie':
@@ -632,15 +638,20 @@ function getEmbyRecent($type, $size) {
 	
 	// Get A User
 	$userIds = json_decode(file_get_contents($address.'/Users?api_key='.EMBYTOKEN),true);
+	$showPlayed = true;
 	foreach ($userIds as $value) { // Scan for admin user
-		$userId = $value['Id'];
 		if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
+			$userId = $value['Id'];
+		}
+		if ($username && strtolower($value['Name']) == $username) {
+			$userId = $value['Id'];
+			$showPlayed = false;
 			break;
 		}
 	}
 	
 	// Get the latest Items
-	$latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?'.$embyTypeQuery.'EnableImages=false&api_key='.EMBYTOKEN),true);
+	$latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?'.$embyTypeQuery.'EnableImages=false&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
 	
 	// For Each Item In Category
 	$items = array();

+ 3 - 1
settings.php

@@ -878,6 +878,7 @@ echo buildSettings(
 						'value' => HOMEPAGEAUTHNEEDED,
 						'options' => $userTypes,
 					),
+					/*
 					array(
 						'type' => 'custom',
 						'labelTranslate' => 'SHOW_HOMEPAGE',
@@ -885,6 +886,7 @@ echo buildSettings(
 						'name' => 'homePagelayout',
 						'value' => '',
 					),
+					*/
 				),
 			),
 			array(
@@ -969,7 +971,7 @@ echo buildSettings(
 						'type' => 'text',
 						'placeholder' => randString(32),
 						'labelTranslate' => 'EMBY_TOKEN',
-						'name' => 'plexToken',
+						'name' => 'embyToken',
 						'pattern' => '[a-zA-Z0-9]{32}',
 						'value' => EMBYTOKEN,
 					),

+ 3 - 1
user.php

@@ -504,6 +504,7 @@ EOT;
 		 */
 		function register_user($username, $email, $sha1, &$registration_callback = false, $settings)
 		{
+			$username = strtolower($username);
 			$dbpassword = $this->token_hash_password($username, $sha1, "");
 			if($dbpassword==$sha1) die("password hashing is not implemented.");
             $newRole = "admin"; 
@@ -566,7 +567,8 @@ EOT;
 		 * Log a user in
 		 */
 		function login_user($username, $sha1, $remember, $password, $surface = true) {
-
+			$username = strtolower($username);
+			
             $buildLog = function($username, $authType) {
                 if(file_exists(FAIL_LOG)) {
                     $getFailLog = str_replace("\r\ndate", "date", file_get_contents(FAIL_LOG));