4
0
Эх сурвалжийг харах

Merge pull request #1312 from causefx/v2-develop

V2 develop
causefx 6 жил өмнө
parent
commit
bd4ad9de39

+ 6 - 0
README.md

@@ -86,3 +86,9 @@ The parameters are split into two halves, separated by a colon, the left hand si
 
 <p align="center"><a href="https://www.browserstack.com"><img src="https://avatars2.githubusercontent.com/u/1119453?s=200&v=4g"></a></p>
 <p align="center"><a href="https://www.browserstack.com">BrowserStack</a> for allowing us to use their platform for testing</p>
+<p>This project is supported by:</p>
+<p>
+  <a href="https://www.digitalocean.com/">
+    <img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px">
+  </a>
+</p>

+ 5 - 1
api/config/default.php

@@ -254,5 +254,9 @@ return array(
 	'unifiCookie' => '',
 	'homepageUnifiEnabled' => 'false',
 	'homepageUnifiAuth' => '1',
-	'homepageUnifiRefresh' => '600000'
+	'homepageUnifiRefresh' => '600000',
+	'youtubeAPI' => '',
+	'wanDomain' => '',
+	'localAddress' => '',
+	'enableLocalAddressForward' => false
 );

+ 17 - 0
api/functions/api-functions.php

@@ -1281,3 +1281,20 @@ function getSchema()
 		return 'DB not set yet...';
 	}
 }
+
+function youtubeSearch($query){
+	if(!$query){
+		return 'no query provided!';
+	}
+	$keys = array('AIzaSyBsdt8nLJRMTwOq5PY5A5GLZ2q7scgn01w','AIzaSyD-8SHutB60GCcSM8q_Fle38rJUV7ujd8k','AIzaSyBzOpVBT6VII-b-8gWD0MOEosGg4hyhCsQ');
+	$randomKeyIndex = array_rand($keys);
+	$key = $keys[$randomKeyIndex];
+	$apikey = ($GLOBALS['youtubeAPI'] !== '') ? $GLOBALS['youtubeAPI'] : $key;
+	$results = false;
+	$url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=$query+official+trailer&part=snippet&maxResults=1&type=video&videoDuration=short&key=$apikey";
+	$response = Requests::get($url);
+	if ($response->success) {
+		$results = json_decode($response->body, true);
+	}
+	return ($results) ? $results : false;
+}

+ 23 - 0
api/functions/homepage-functions.php

@@ -2455,6 +2455,29 @@ function getHomepageList()
 					),
 				)
 			)
+		),
+		array(
+			'name' => 'Misc',
+			'enabled' => true,
+			'image' => 'plugins/images/organizr/logo-no-border.png',
+			'category' => 'Custom',
+			'settings' => array(
+				'YouTube' => array(
+					array(
+						'type' => 'input',
+						'name' => 'youtubeAPI',
+						'label' => 'Youtube API Key',
+						'value' => $GLOBALS['youtubeAPI'],
+						'help' => 'Please make sure to input this API key as the organizr one gets limited'
+					),
+					array(
+						'type' => 'html',
+						'override' => 6,
+						'label' => 'Instructions',
+						'html' => '<a href="https://www.slickremix.com/docs/get-api-key-for-youtube/" target="_blank">Click here for instructions</a>'
+					),
+				)
+			)
 		)
 	);
 }

+ 26 - 0
api/functions/organizr-functions.php

@@ -107,6 +107,9 @@ function organizrSpecialSettings()
 		'login' => array(
 			'rememberMe' => $GLOBALS['rememberMe'],
 			'rememberMeDays' => $GLOBALS['rememberMeDays'],
+			'wanDomain' => $GLOBALS['wanDomain'],
+			'localAddress' => $GLOBALS['localAddress'],
+			'enableLocalAddressForward' => $GLOBALS['enableLocalAddressForward'],
 		),
 		'misc' => array(
 			'installedPlugins' => qualifyRequest(1) ? $GLOBALS['installedPlugins'] : '',
@@ -869,6 +872,29 @@ function getSettingsMain()
 				'placeholder' => 'i.e. 123.123.123.123',
 				'help' => 'IPv4 only at the moment - This will set your login as local if your IP falls within the From and To'
 			),
+			array(
+				'type' => 'input',
+				'name' => 'wanDomain',
+				'label' => 'WAN Domain',
+				'value' => $GLOBALS['wanDomain'],
+				'placeholder' => 'only domain and tld - i.e. domain.com',
+				'help' => 'Enter domain if you wish to be forwarded to a local address - Local Address filled out on next item'
+			),
+			array(
+				'type' => 'input',
+				'name' => 'localAddress',
+				'label' => 'Local Address',
+				'value' => $GLOBALS['localAddress'],
+				'placeholder' => 'http://home.local',
+				'help' => 'Full local address of organizr install - i.e. http://home.local or http://192.168.0.100'
+			),
+			array(
+				'type' => 'switch',
+				'name' => 'enableLocalAddressForward',
+				'label' => 'Enable Local Address Forward',
+				'help' => 'Enables the local address forward if on local address and accessed from WAN Domain',
+				'value' => $GLOBALS['enableLocalAddressForward'],
+			),
 		),
 		'Auth Proxy' => array(
 			array(

+ 1 - 1
api/functions/static-globals.php

@@ -1,7 +1,7 @@
 <?php
 // ===================================
 // Organizr Version
-$GLOBALS['installedVersion'] = '2.0.362';
+$GLOBALS['installedVersion'] = '2.0.370';
 // ===================================
 // Quick php Version check
 $GLOBALS['minimumPHP'] = '7.1.3';

+ 14 - 0
api/index.php

@@ -1376,6 +1376,20 @@ switch ($function) {
 				break;
 		}
 		break;
+	case 'v1_youtube_search':
+		switch ($method) {
+			case 'GET':
+				$query = isset($_GET['q']) ? $_GET['q'] : false;
+				$result['status'] = isset($_GET['q']) ? 'success' : 'error';
+				$result['statusText'] = isset($_GET['q']) ? 'success' : 'missing query';
+				$result['data'] = youtubeSearch($query);
+				break;
+			default:
+				$result['status'] = 'error';
+				$result['statusText'] = 'The function requested is not defined for method: ' . $method;
+				break;
+		}
+		break;
 	default:
 		//No Function Available
 		$result['status'] = 'error';

+ 26 - 2
js/functions.js

@@ -6428,13 +6428,14 @@ function humanFileSize(bytes, si) {
 //youtube search
 function youtubeSearch(searchQuery) {
 	return $.ajax({
-		url: "https://www.googleapis.com/youtube/v3/search?part=snippet&q="+searchQuery+"+official+trailer&part=snippet&maxResults=1&type=video&videoDuration=short&key=AIzaSyD-8SHutB60GCcSM8q_Fle38rJUV7ujd8k",
+		url: "api/?v1/youtube/search&q="+searchQuery,
 	});
 }
 function youtubeCheck(title,link){
 	youtubeSearch(title).success(function(data) {
+        var response = JSON.parse(data);
 		inlineLoad();
-		var id = data.items["0"].id.videoId;
+		var id = response.data.items["0"].id.videoId;
 		var div = `
 		<div id="player-`+link+`" data-plyr-provider="youtube" data-plyr-embed-id="`+id+`"></div>
 		<div class="clearfix"></div>
@@ -6591,6 +6592,28 @@ function organizrSpecialSettings(array){
 		$(searchBoxResults).appendTo($('.organizr-area'));
 	}
 }
+function checkLocalForwardStatus(array){
+    if(array.settings.login.enableLocalAddressForward == true && typeof array.settings.login.enableLocalAddressForward !== 'undefined'){
+        if(array.settings.login.wanDomain !== '' && array.settings.login.localAddress !== ''){
+            console.log('Local Login Enabled');
+            console.log('Local Login Testing...');
+            let remoteSite = array.settings.login.wanDomain;
+            let localSite = array.settings.login.localAddress;
+            try {
+                let currentURL = decodeURI(window.location.href)
+                let currentSite = window.location.host;
+                if(activeInfo.settings.user.local && currentSite.indexOf(remoteSite) !== -1 && currentURL.indexOf('override') === -1){
+                    console.log('Local Login Status: Local | Forwarding Now');
+                    window.location = localSite;
+                }
+            } catch(e) {
+                console.error(e);
+            }
+            console.log('Local Login Status: Not Local');
+
+        }
+    }
+}
 function forceSearch(term){
     $.magnificPopup.close();
     var tabName = $("li[data-url^='api/?v1/homepage/page']").find('span').html();
@@ -7421,6 +7444,7 @@ function launch(){
                     accountManager(json);
                     organizrSpecialSettings(json);
                     getPingList(json);
+                    checkLocalForwardStatus(json);
                 }
                 loadCustomJava(json.appearance);
                 if(getCookie('lockout')){

+ 7 - 0
js/version.json

@@ -222,5 +222,12 @@
     "new": "Added Jellyfin support - uses same HP Modal as Emby|Added new tab images for Fritzbox, Kodi, OpenHAB and Calibre-Web|Added nginx auth_request dynamic endpoints to allow permission management on organizr front end|Add email header for Auth Proxy use (#1298)|Add another Variable to PR (#1298)|Update local function to take force variable|Added rtorrent bypass cert check",
     "fixed": "qBittorrent Workaround for v2 API (#1287)|Dependency check fails incorrectly on PHP 7.4 (#1288)|Fix depreciated item on PHP 7.4 (#1288)|7.4 work on array check|XSS Vulnerability (#1291)|Cleaner XSS Vulnerability (#1291)|Closing tabs open up top tab (#1266)|more clean up on unifi homepage item|fix typ-os|Add homepage-element-title class to left-aligned homepage element names|Fix plex show on homepage",
     "notes": "Please report bugs in GitHub issues page|Updated language translations"
+  },
+  "2.0.370": {
+    "date": "2020-02-21 14:55",
+    "title": "YouTube Homepage Fix",
+    "new": "Added option to forward to local instance if detected",
+    "fixed": "Fix for YouTube daily query quota is too low (#1297)",
+    "notes": "Please report bugs in GitHub issues page|Updated language translations"
   }
 }