Ver código fonte

Fix deluge when no results
more edits to cookie function

causefx 8 anos atrás
pai
commit
287aff30bd

+ 8 - 30
api/functions/homepage-connect-functions.php

@@ -1,5 +1,4 @@
 <?php
-
 function homepageConnect($array)
 {
 	switch ($array['data']['action']) {
@@ -96,7 +95,6 @@ function resolveEmbyItem($itemDetails)
 	// Types
 	$embyItem['array-item'] = $item;
 	$embyItem['array-itemdetails'] = $itemDetails;
-	
 	switch (@$item['Type']) {
 		case 'Series':
 			$embyItem['type'] = 'tv';
@@ -247,7 +245,6 @@ function resolveEmbyItem($itemDetails)
 		'genres' => ($item['Genres']) ? $genres : '',
 		'actors' => ($item['People']) ? $actors : ''
 	);
-	
 	if (file_exists($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg')) {
 		$embyItem['nowPlayingImageURL'] = $cacheDirectoryWeb . $embyItem['nowPlayingKey'] . '.jpg';
 	}
@@ -805,7 +802,7 @@ function delugeConnect()
 			} else {
 				$api['content']['queueItems'] = $torrents;
 			}
-			//$api['content']['queueItems'] = $torrents;
+			$api['content']['queueItems'] = (empty($api['content']['queueItems'])) ? [] : $api['content']['queueItems'];
 			$api['content']['historyItems'] = false;
 		} catch (Excecption $e) {
 			writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
@@ -924,7 +921,6 @@ function getCalendar()
 			}
 		}
 	}
-	
 	return ($calendarItems) ? $calendarItems : false;
 }
 
@@ -963,7 +959,6 @@ function getSonarrCalendar($array, $number)
 		} else {
 			$downloaded = "text-danger";
 		}
-		
 		$fanart = "/plugins/images/cache/no-np.png";
 		foreach ($child['series']['images'] as $image) {
 			if ($image['coverType'] == "fanart") {
@@ -1049,12 +1044,10 @@ function getRadarrCalendar($array, $number, $url)
 					$imageUrl = $image['url'];
 					$urlParts = explode("/", $url);
 					$imageParts = explode("/", $image['url']);
-					
 					if ($imageParts[1] == end($urlParts)) {
 						unset($imageParts[1]);
 						$imageUrl = implode("/", $imageParts);
 					}
-					
 					$banner = $url . $imageUrl;
 				}
 			}
@@ -1136,7 +1129,6 @@ function getCouchCalendar($array, $number)
 			} else {
 				$downloaded = "text-danger";
 			}
-			
 			if (!empty($child['info']['images']['backdrop_original'])) {
 				$banner = $child['info']['images']['backdrop_original'][0];
 			} elseif (!empty($child['info']['images']['backdrop'])) {
@@ -1170,7 +1162,6 @@ function getCouchCalendar($array, $number)
 				"videoCodec" => "",
 				"genres" => $child['info']['genres'],
 			);
-			
 			array_push($gotCalendar, array(
 				"id" => "CouchPotato-" . $number . "-" . $i,
 				"title" => $movieName,
@@ -1214,7 +1205,6 @@ function getSickrageCalendarWanted($array, $number)
 			$downloaded = "text-danger";
 		}
 		$bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
-		
 		$cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
 		$cacheFile = $cacheDirectory . $seriesID . '.jpg';
 		$fanart = "/plugins/images/cache/no-np.png";
@@ -1222,7 +1212,6 @@ function getSickrageCalendarWanted($array, $number)
 			$fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
 			unset($cacheFile);
 		}
-		
 		$details = array(
 			"seasonCount" => "",
 			"status" => $child['show_status'],
@@ -1270,7 +1259,6 @@ function getSickrageCalendarWanted($array, $number)
 			$downloaded = "text-danger";
 		}
 		$bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
-		
 		$cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
 		$cacheFile = $cacheDirectory . $seriesID . '.jpg';
 		$fanart = "/plugins/images/cache/no-np.png";
@@ -1278,7 +1266,6 @@ function getSickrageCalendarWanted($array, $number)
 			$fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
 			unset($cacheFile);
 		}
-		
 		$details = array(
 			"seasonCount" => "",
 			"status" => $child['show_status'],
@@ -1326,7 +1313,6 @@ function getSickrageCalendarWanted($array, $number)
 			$downloaded = "text-danger";
 		}
 		$bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
-		
 		$cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
 		$cacheFile = $cacheDirectory . $seriesID . '.jpg';
 		$fanart = "/plugins/images/cache/no-np.png";
@@ -1334,7 +1320,6 @@ function getSickrageCalendarWanted($array, $number)
 			$fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
 			unset($cacheFile);
 		}
-		
 		$details = array(
 			"seasonCount" => "",
 			"status" => $child['show_status'],
@@ -1382,7 +1367,6 @@ function getSickrageCalendarWanted($array, $number)
 			$downloaded = "text-danger";
 		}
 		$bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
-		
 		$cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
 		$cacheFile = $cacheDirectory . $seriesID . '.jpg';
 		$fanart = "/plugins/images/cache/no-np.png";
@@ -1390,7 +1374,6 @@ function getSickrageCalendarWanted($array, $number)
 			$fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
 			unset($cacheFile);
 		}
-		
 		$details = array(
 			"seasonCount" => "",
 			"status" => $child['show_status'],
@@ -1435,7 +1418,6 @@ function getSickrageCalendarHistory($array, $number)
 		$episodeAirDate = $child['date'];
 		$downloaded = "text-success";
 		$bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']);
-		
 		$cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
 		$cacheFile = $cacheDirectory . $seriesID . '.jpg';
 		$fanart = "/plugins/images/cache/no-np.png";
@@ -1443,7 +1425,6 @@ function getSickrageCalendarHistory($array, $number)
 			$fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
 			unset($cacheFile);
 		}
-		
 		$details = array(
 			"seasonCount" => "",
 			"status" => $child['status'],
@@ -1584,7 +1565,6 @@ function getOmbiRequests($type = "both")
 				case 'tv':
 					$tv = Requests::get($url . "/api/v1/Request/tv", $headers, $options);
 					break;
-				
 				default:
 					$movie = Requests::get($url . "/api/v1/Request/movie", $headers, $options);
 					$tv = Requests::get($url . "/api/v1/Request/tv", $headers, $options);
@@ -1675,12 +1655,11 @@ function testAPIConnection($array)
 				} catch (Requests_Exception $e) {
 					return $e->getMessage();
 				};
-			}else{
+			} else {
 				return 'URL and/or Token not setup';
 			}
 			break;
 		case 'emby':
-			
 			break;
 		case 'sonarr':
 			if (!empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])) {
@@ -1704,7 +1683,7 @@ function testAPIConnection($array)
 						}
 					}
 				}
-			}else{
+			} else {
 				return 'URL/s and/or Token/s not setup';
 			}
 			break;
@@ -1730,12 +1709,12 @@ function testAPIConnection($array)
 						}
 					}
 				}
-			}else{
+			} else {
 				return 'URL/s and/or Token/s not setup';
 			}
 			break;
 		case 'sabnzbd':
-			if (!empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) ) {
+			if (!empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken'])) {
 				$url = qualifyURL($GLOBALS['sabnzbdURL']);
 				$url = $url . '/api?mode=queue&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
 				try {
@@ -1747,7 +1726,7 @@ function testAPIConnection($array)
 				} catch (Requests_Exception $e) {
 					return $e->getMessage();
 				};
-			}else{
+			} else {
 				return 'URL and/or Token not setup';
 			}
 			break;
@@ -1764,7 +1743,7 @@ function testAPIConnection($array)
 				} catch (Requests_Exception $e) {
 					return $e->getMessage();
 				};
-			}else{
+			} else {
 				return 'URL and/or Username/Password not setup';
 			}
 			break;
@@ -1778,8 +1757,7 @@ function testAPIConnection($array)
 				} catch (\Excecption $e) {
 					return $e->getMessage();
 				}
-			}
-			else{
+			} else {
 				return 'URL and/or Password not setup';
 			}
 			break;

+ 27 - 17
api/functions/normal-functions.php

@@ -27,25 +27,10 @@ function gravatar($email = '')
 	return $gravurl;
 }
 
-// Cookie Custom Function
-function coookie($type, $name, $value = '', $days = -1, $http = true)
+function parseDomain($value)
 {
 	$badDomains = array('ddns.net', 'ddnsking.com', '3utilities.com', 'bounceme.net', 'duckdns.org', 'freedynamicdns.net', 'freedynamicdns.org', 'gotdns.ch', 'hopto.org', 'myddns.me', 'myds.me', 'myftp.biz', 'myftp.org', 'myvnc.com', 'noip.com', 'onthewifi.com', 'redirectme.net', 'serveblog.net', 'servecounterstrike.com', 'serveftp.com', 'servegame.com', 'servehalflife.com', 'servehttp.com', 'serveirc.com', 'serveminecraft.net', 'servemp3.com', 'servepics.com', 'servequake.com', 'sytes.net', 'viewdns.net', 'webhop.me', 'zapto.org');
-	if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https") {
-		$Secure = true;
-		$HTTPOnly = true;
-	} elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
-		$Secure = true;
-		$HTTPOnly = true;
-	} else {
-		$Secure = false;
-		$HTTPOnly = false;
-	}
-	if (!$http) {
-		$HTTPOnly = false;
-	}
-	$Path = '/';
-	$Domain = $_SERVER['HTTP_HOST'];
+	$Domain = $value;
 	$Port = strpos($Domain, ':');
 	if ($Port !== false) {
 		$Domain = substr($Domain, 0, $Port);
@@ -64,6 +49,10 @@ function coookie($type, $name, $value = '', $days = -1, $http = true)
 	} elseif ($check == 2) {
 		if (in_array(strtolower(explode('.', $Domain)[1] . '.' . explode('.', $Domain)[2]), $badDomains)) {
 			$Domain = '.' . explode('.', $Domain)[0] . '.' . explode('.', $Domain)[1] . '.' . explode('.', $Domain)[2];
+		} elseif (explode('.', $Domain)[0] == 'www') {
+			$Domain = '.' . explode('.', $Domain)[1] . '.' . explode('.', $Domain)[2];
+		} elseif (explode('.', $Domain)[1] == 'co') {
+			$Domain = '.' . explode('.', $Domain)[0] . '.' . explode('.', $Domain)[1] . '.' . explode('.', $Domain)[2];
 		} else {
 			$Domain = '.' . explode('.', $Domain)[1] . '.' . explode('.', $Domain)[2];
 		}
@@ -72,6 +61,27 @@ function coookie($type, $name, $value = '', $days = -1, $http = true)
 	} else {
 		$Domain = '';
 	}
+	return $Domain;
+}
+
+// Cookie Custom Function
+function coookie($type, $name, $value = '', $days = -1, $http = true)
+{
+	if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https") {
+		$Secure = true;
+		$HTTPOnly = true;
+	} elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
+		$Secure = true;
+		$HTTPOnly = true;
+	} else {
+		$Secure = false;
+		$HTTPOnly = false;
+	}
+	if (!$http) {
+		$HTTPOnly = false;
+	}
+	$Path = '/';
+	$Domain = parseDomain($_SERVER['HTTP_HOST']);
 	if ($type == 'set') {
 		$_COOKIE[$name] = $value;
 		header('Set-Cookie: ' . rawurlencode($name) . '=' . rawurlencode($value)