causefx преди 7 години
родител
ревизия
0054db5e0d
променени са 2 файла, в които са добавени 42 реда и са изтрити 9 реда
  1. 36 5
      api/functions/organizr-functions.php
  2. 6 4
      api/plugins/php-mailer.php

+ 36 - 5
api/functions/organizr-functions.php

@@ -1524,7 +1524,7 @@ function getOrgUsers()
 
 function convertPlexName($user, $type)
 {
-	$array = libraryList('plex');
+	$array = userList('plex');
 	switch ($type) {
 		case "username":
 		case "u":
@@ -1541,7 +1541,7 @@ function convertPlexName($user, $type)
 	return (!empty($plexUser) ? $plexUser : null);
 }
 
-function libraryList($type = null)
+function userList($type = null)
 {
 	switch ($type) {
 		case 'plex':
@@ -1557,9 +1557,6 @@ function libraryList($type = null)
 					if ($response->success) {
 						$libraryList = array();
 						$plex = simplexml_load_string($response->body);
-						foreach ($plex->SharedServer->Section as $child) {
-							$libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
-						}
 						foreach ($plex->SharedServer as $child) {
 							if (!empty($child['username'])) {
 								$username = (string)strtolower($child['username']);
@@ -1584,6 +1581,40 @@ function libraryList($type = null)
 	return false;
 }
 
+function libraryList($type = null)
+{
+	switch ($type) {
+		case 'plex':
+			if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
+				$url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'];
+				try {
+					$headers = array(
+						"Accept" => "application/json",
+						"X-Plex-Token" => $GLOBALS['plexToken']
+					);
+					$response = Requests::get($url, $headers, array());
+					libxml_use_internal_errors(true);
+					if ($response->success) {
+						$libraryList = array();
+						$plex = simplexml_load_string($response->body);
+						foreach ($plex->Server->Section as $child) {
+							$libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
+						}
+						$libraryList = array_change_key_case($libraryList, CASE_LOWER);
+						return $libraryList;
+					}
+				} catch (Requests_Exception $e) {
+					writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+				};
+			}
+			break;
+		default:
+			# code...
+			break;
+	}
+	return false;
+}
+
 function plexJoinAPI($array)
 {
 	return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);

+ 6 - 4
api/plugins/php-mailer.php

@@ -1,4 +1,5 @@
 <?php
+/** @noinspection PhpUnusedLocalVariableInspection */
 // PLUGIN INFORMATION
 $GLOBALS['plugins'][]['PHP Mailer'] = array( // Plugin Name
 	'name' => 'PHP Mailer', // Plugin Name
@@ -10,7 +11,7 @@ $GLOBALS['plugins'][]['PHP Mailer'] = array( // Plugin Name
 	//'configFile'=>'php-mailer.php',
 	//'apiFile'=>'php-mailer.php',
 	'idPrefix' => 'PHPMAILER', // html element id prefix
-	'configPrefix' => 'PHPMAILER', // config file prefix for array items without the hypen
+	'configPrefix' => 'PHPMAILER', // config file prefix for array items without the hyphen
 	'version' => '1.0.0', // SemVer of plugin
 	'image' => 'plugins/images/php-mailer.png', // 1:1 non transparent image for plugin
 	'settings' => true, // does plugin need a settings page? true or false
@@ -28,7 +29,7 @@ function getEmails()
 		$type = 'none';
 	}
 	if ($type == 'plex') {
-		$emails = array_merge(libraryList('plex')['both'], getOrgUsers());
+		$emails = array_merge(userList('plex')['both'], getOrgUsers());
 	} elseif ($type == 'emby') {
 		$emails = getOrgUsers();
 	} else {
@@ -65,8 +66,9 @@ function phpmEmailTemplate($emailTemplate)
 
 function phpmBuildEmail($email)
 {
+	/** @noinspection PhpUnusedLocalVariableInspection */
 	$subject = (isset($email['subject'])) ? $email['subject'] : 'Message from Server';
-	$body = (isset($email['body'])) ? $email['body'] : 'Message Error Occured';
+	$body = (isset($email['body'])) ? $email['body'] : 'Message Error Occurred';
 	$type = (isset($email['type'])) ? $email['type'] : 'No Type';
 	switch ($type) {
 		case 'invite':
@@ -170,7 +172,7 @@ function phpmSendEmail($emailInfo)
 		if ($GLOBALS['PHPMAILER-smtpHostType'] !== 'n/a') {
 			$mail->SMTPSecure = $GLOBALS['PHPMAILER-smtpHostType'];
 		}
-        $mail->SMTPAuth = $GLOBALS['PHPMAILER-smtpHostAuth'];
+		$mail->SMTPAuth = $GLOBALS['PHPMAILER-smtpHostAuth'];
 		$mail->Username = $GLOBALS['PHPMAILER-smtpHostUsername'];
 		$mail->Password = decrypt($GLOBALS['PHPMAILER-smtpHostPassword']);
 		$mail->SMTPOptions = array(