Преглед изворни кода

Ajax Rewrite
Fix Ombi Images

causefx пре 8 година
родитељ
комит
66b19744c9
3 измењених фајлова са 92 додато и 44 уклоњено
  1. 73 36
      functions.php
  2. 18 7
      homepage.php
  3. 1 1
      lang/en.ini

+ 73 - 36
functions.php

@@ -998,9 +998,9 @@ function outputRecentAdded($header, $items, $script = false, $array, $type) {
 function outputNowPlaying($header, $size, $type, $items, $script = false) {
 	// If None Populate Empty Item
 	if (!count($items)) {
-		return '<div id='.$type.'></div>'.($script?'<script>'.$script.'</script>':'');
+		return '<div id="'.$type.'"></div>'.($script?'<script>'.$script.'</script>':'');
 	}else{
-	   return '<div id='.$type.'><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
+	   return '<div id="'.$type.'"><h5 class="zero-m big-box"><strong>'.$header.'</strong></h5>'.implode('',$items).'</div>'.($script?'<script>'.$script.'</script>':'');
  }
 
 }
@@ -1021,11 +1021,19 @@ function getEmbyStreams($size, $showNames, $role) {
 
 	return outputNowPlaying(translate('PLAYING_NOW_ON_EMBY')." ( ".count($playingItems)." Streams )", $size, 'streams-emby', $playingItems, "
 		setInterval(function() {
-			$('<div></div>').load('ajax.php?a=emby-streams',function() {
-				var element = $(this).find('[id]');
-				var loadedID = 	element.attr('id');
-				$('#'+loadedID).replaceWith(element);
-				console.log('Loaded updated: '+loadedID);
+			$.ajax({
+				url: 'ajax.php?a=emby-streams',
+				timeout: 10000,
+				type: 'GET',
+				success: function(response) {
+					var getDiv = response;
+					var loadedID = 	$(getDiv).attr('id');
+					$('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
+					console.log(loadedID+' has been updated');
+				},
+				error: function(jqXHR, textStatus, errorThrown) {
+					console.error(loadedID+' could not be updated');
+				}
 			});
 		}, ".NOWPLAYINGREFRESH.");
 	");
@@ -1054,11 +1062,19 @@ function getPlexStreams($size, $showNames, $role){
 
 			return outputNowPlaying(translate('PLAYING_NOW_ON_PLEX')." ( ".count($items)." Streams )", $size, 'streams-plex', $items, "
 				setInterval(function() {
-					$('<div></div>').load('ajax.php?a=plex-streams',function() {
-						var element = $(this).find('[id]');
-						var loadedID = 	element.attr('id');
-						$('#'+loadedID).replaceWith(element);
-						console.log('Loaded updated: '+loadedID);
+					$.ajax({
+						url: 'ajax.php?a=plex-streams',
+						timeout: 10000,
+						type: 'GET',
+						success: function(response) {
+							var getDiv = response;
+							var loadedID = 	$(getDiv).attr('id');
+							$('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
+							console.log(loadedID+' has been updated');
+						},
+						error: function(jqXHR, textStatus, errorThrown) {
+							console.error(loadedID+' could not be updated');
+						}
 					});
 				}, ".NOWPLAYINGREFRESH.");
 			");
@@ -1118,14 +1134,21 @@ function getEmbyRecent($array) {
 
     return outputRecentAdded($header, $items, "
 	setInterval(function() {
-		$('<div></div>').load('ajax.php?a=emby-recent',function() {
-			var element = $(this).find('#recentMediaEmby');
-			var loadedID = 	element.attr('id');
-			$('#recentMediaEmby').replaceWith(element);
-			console.log('Loaded recent: '+loadedID);
-			loadSlick();
+		$.ajax({
+			url: 'ajax.php?a=emby-recent',
+			timeout: 10000,
+			type: 'GET',
+			success: function(response) {
+				var getDiv = response;
+				var loadedID = 	$(getDiv).attr('id');
+				$('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
+				loadSlick();
+				console.log(loadedID+' has been updated');
+			},
+			error: function(jqXHR, textStatus, errorThrown) {
+				console.error(loadedID+' could not be updated');
+			}
 		});
-
 	}, ".RECENTREFRESH.");
 	", $array, 'Emby');
 }
@@ -1157,14 +1180,21 @@ function getPlexRecent($array){
 
 			return outputRecentAdded($header, $items, "
 			setInterval(function() {
-				$('<div></div>').load('ajax.php?a=plex-recent',function() {
-					var element = $(this).find('#recentMediaPlex');
-					var loadedID = 	element.attr('id');
-					$('#recentMediaPlex').replaceWith(element);
-					console.log('Loaded recent: '+loadedID);
-					loadSlick();
+				$.ajax({
+					url: 'ajax.php?a=plex-recent',
+					timeout: 10000,
+					type: 'GET',
+					success: function(response) {
+						var getDiv = response;
+						var loadedID = 	$(getDiv).attr('id');
+						$('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
+						loadSlick();
+						console.log(loadedID+' has been updated');
+					},
+					error: function(jqXHR, textStatus, errorThrown) {
+						console.error(loadedID+' could not be updated');
+					}
 				});
-
 			}, ".RECENTREFRESH.");
 			", $array, 'Plex');
 		}else{
@@ -4867,7 +4897,7 @@ function getOmbiRequests($type = "both"){
 			$requests[] = array(
 				'id' => $value['theMovieDbId'],
 				'title' => $value['title'],
-				'poster' => (strpos($value['posterPath'], "http") !== false) ? $value['posterPath'] : 'https://image.tmdb.org/t/p/w300/'.$value['posterPath'],
+				'poster' => (strpos($value['posterPath'], "/") !== false) ? 'https://image.tmdb.org/t/p/w300/'.end(explode('/',$value['posterPath'])) : 'https://image.tmdb.org/t/p/w300/'.$value['posterPath'],
 				'approved' => $value['approved'],
 				'available' => $value['available'],
 				'denied' => $value['denied'],
@@ -4878,7 +4908,7 @@ function getOmbiRequests($type = "both"){
 				'release_date' => $value['releaseDate'],
 				'type' => 'movie',
 				'icon' => 'mdi mdi-filmstrip',
-				'color' => 'palette-Purple-900 bg white',
+				'color' => 'palette-Deep-Purple-900 bg white',
 			);
 		}
 	}
@@ -5047,15 +5077,22 @@ function buildOmbiList($group, $user){
 	}
 	return outputOmbiRequests("Requested Content", $requests, "
 	setInterval(function() {
-		$('<div></div>').load('ajax.php?a=ombi-requests',function() {
-			var element = $(this).find('#recentRequests');
-			var loadedID = 	element.attr('id');
-			$('#recentRequests').replaceWith(element);
-			console.log('Loaded updated: '+loadedID);
-			loadSlick();
+		$.ajax({
+			url: 'ajax.php?a=ombi-requests',
+			timeout: 10000,
+			type: 'GET',
+			success: function(response) {
+				var getDiv = response;
+				var loadedID = 	$(getDiv).attr('id');
+				$('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
+				loadSlick();
+				console.log(loadedID+' has been updated');
+			},
+			error: function(jqXHR, textStatus, errorThrown) {
+				console.error(loadedID+' could not be updated');
+			}
 		});
-
-	}, ".RECENTREFRESH.");
+	}, ".REQUESTREFRESH.");
 	", false);
 }
 

+ 18 - 7
homepage.php

@@ -75,6 +75,9 @@ foreach(loadAppearance() as $key => $value) {
         <![endif]-->
         <style>
 			<?php if($USER->role !== "admin"){ echo '.refreshImage { display: none; }';}?>
+            .dropdown-menu {
+                max-width: 160px;
+            }
 			.requestHeader {
 				padding: 5px;
 				margin-top: -10px;
@@ -690,13 +693,21 @@ foreach(loadAppearance() as $key => $value) {
 					action_type: action,
 					type: type,
                 }).done(function(data){
-					$('<div></div>').load('ajax.php?a=ombi-requests',function() {
-						var element = $(this).find('[id]');
-						var loadedID = 	element.attr('id');
-						$('#'+loadedID).replaceWith(element);
-						console.log('OMBI ACTION Submited and reloaded: '+loadedID);
-						loadSlick();
-					});
+                    $.ajax({
+        				url: 'ajax.php?a=ombi-requests',
+        				timeout: 10000,
+        				type: 'GET',
+        				success: function(response) {
+        					var getDiv = response;
+        					var loadedID = 	$(getDiv).attr('id');
+        					$('#'+loadedID).replaceWith($(getDiv).prop('outerHTML'));
+        					console.log('OMBI ACTION Submited and reloaded: '+loadedID);
+                            loadSlick();
+        				},
+        				error: function(jqXHR, textStatus, errorThrown) {
+        					console.error(loadedID+' could not be updated');
+        				}
+        			});
 				});
 			});
             $('.repeat-btn').click(function(){

+ 1 - 1
lang/en.ini

@@ -206,7 +206,7 @@ SABNZBD_KEY = "SABnzbd API Key"
 HEADPHONES_URL = "Headphones URL"
 HEADPHONES_PORT = "Headphones Port"
 HEADPHONES_KEY = "Headphones API Key"
-COOKIE_DOMAIN = "Domain Name for Cookie"
+COOKIE_DOMAIN = "Domain Name for Cookie & Auth Request i.e. domain.com"
 DAYS = "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday"
 CALENDAR_START_DAY = "First Day"
 CALENDAR_START_DATE = "# of Days Before"