Sfoglia il codice sorgente

add Sonarr and calendar

causefx 8 anni fa
parent
commit
2f2b6dd371

+ 11 - 1
api/config/default.php

@@ -31,6 +31,8 @@ return array(
     'ssoPlex' => false,
     'ssoOmbi' => false,
     'ssoTautulli' => false,
+	'sonarrURL' => '',
+	'sonarrToken' => '',
 	'sabnzbdURL' => '',
     'sabnzbdToken' => '',
     'nzbgetURL' => '',
@@ -48,6 +50,8 @@ return array(
     'qBittorrentHideCompleted' => false,
     'homepageSabnzbdEnabled' => false,
     'homepageSabnzbdAuth' => '1',
+	'homepageSonarrEnabled' => false,
+    'homepageSonarrAuth' => '1',
     'homepageTransmissionEnabled' => false,
     'homepageTransmissionAuth' => '1',
     'homepageqBittorrentEnabled' => false,
@@ -86,5 +90,11 @@ return array(
     'homepageEmbyStreams' => false,
     'homepageEmbyStreamsAuth' => '1',
     'homepageEmbyRecent' => false,
-    'homepageEmbyRecentAuth' => '1'
+    'homepageEmbyRecentAuth' => '1',
+    'calendarDefault' => 'month',
+    'calendarFirstDay' => '1',
+    'calendarStart' => '14',
+    'calendarEnd' => '14',
+    'calendarRefresh' => '60000',
+    'calendarTimeFormat' => 'h(:mm)t'
 );

+ 61 - 5
api/functions/homepage-connect-functions.php

@@ -32,6 +32,9 @@ function homepageConnect($array){
         case 'getqBittorrent':
             return qBittorrentConnect();
             break;
+        case 'getCalendar':
+            return getCalendar();
+            break;
         default:
             # code...
             break;
@@ -659,9 +662,62 @@ function qBittorrentConnect() {
         return $api;
     }
 }
-function accessProtected($obj, $prop) {
-  $reflection = new ReflectionClass($obj);
-  $property = $reflection->getProperty($prop);
-  $property->setAccessible(true);
-  return $property->getValue($obj);
+function getCalendar(){
+	$startDate = date('Y-m-d',strtotime("-".$GLOBALS['calendarStart']." days"));
+	$endDate = date('Y-m-d',strtotime("+".$GLOBALS['calendarEnd']." days"));
+	$calendarItems = array();
+    // SONARR CONNECT
+    if($GLOBALS['homepageSonarrEnabled'] && qualifyRequest($GLOBALS['homepageSonarrAuth']) && !empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])){
+        $sonarrs = array();
+        $sonarrURLList = explode(',', $GLOBALS['sonarrURL']);
+        $sonarrTokenList = explode(',', $GLOBALS['sonarrToken']);
+        if(count($sonarrURLList) == count($sonarrTokenList)){
+            foreach ($sonarrURLList as $key => $value) {
+                $sonarrs[$key] = array(
+                    'url' => $value,
+                    'token' => $sonarrTokenList[$key]
+                );
+            }
+            foreach ($sonarrs as $key => $value) {
+                try {
+                    $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
+                    $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate),$key);
+
+                } catch (Exception $e) {
+                    writeLog('error', 'Sonarr Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+                }
+                if(!empty($sonarrCalendar)) { $calendarItems = array_merge($calendarItems, $sonarrCalendar); }
+            }
+        }
+    }
+
+
+	return ($calendarItems) ? $calendarItems : false;
+}
+function getSonarrCalendar($array,$number){
+    $array = json_decode($array, true);
+    $gotCalendar = array();
+    $i = 0;
+    foreach($array AS $child) {
+        $i++;
+        $seriesName = $child['series']['title'];
+        $episodeID = $child['series']['tvdbId'];
+        if(!isset($episodeID)){ $episodeID = ""; }
+        $episodeName = htmlentities($child['title'], ENT_QUOTES);
+        if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
+        $episodeAirDate = $child['airDateUtc'];
+        $episodeAirDate = strtotime($episodeAirDate);
+        $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
+        if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
+        $downloaded = $child['hasFile'];
+        if($downloaded == "0" && isset($unaired) && $episodePremier == "true"){ $downloaded = "bg-primary"; }elseif($downloaded == "0" && isset($unaired)){ $downloaded = "bg-info"; }elseif($downloaded == "1"){ $downloaded = "bg-success"; }else{ $downloaded = "bg-danger"; }
+		array_push($gotCalendar, array(
+			"id" => "Sonarr-".$number."-".$i,
+			"title" => $seriesName,
+			"start" => $child['airDateUtc'],
+			"className" => $downloaded." tvID--".$episodeID,
+			"imagetype" => "tv",
+		));
+    }
+    if ($i != 0){ return $gotCalendar; }
 }

+ 161 - 3
api/functions/homepage-functions.php

@@ -31,7 +31,7 @@ function buildHomepage(){
 	return $homepageBuilt;
 }
 function buildHomepageItem($homepageItem){
-	$item = '<div id="'.$homepageItem.'"></div>';
+	$item = '<div id="'.$homepageItem.'">';
 	switch ($homepageItem) {
 		case 'homepageOrderplexsearch':
 
@@ -167,13 +167,23 @@ function buildHomepageItem($homepageItem){
 
 			break;
 		case 'homepageOrdercalendar':
-
+			$item .= '
+			<div id="calendar" class="fc fc-ltr"></div>
+			<script>
+			// Calendar
+			homepageCalendar();
+			setInterval(function() {
+				homepageCalendar();
+			}, '.$GLOBALS['calendarRefresh'].');
+			// End Calendar
+			</script>
+			';
 			break;
 		default:
 			# code...
 			break;
 	}
-	return $item;
+	return $item.'</div>';
 }
 function getHomepageList(){
     $groups = groupSelect();
@@ -215,6 +225,72 @@ function getHomepageList(){
             'value' => '3600000'
         ),
     );
+	$day = array(
+		array(
+			'name' => 'Sunday',
+			'value' => '0'
+		),
+		array(
+			'name' => 'Monday',
+			'value' => '1'
+		),
+		array(
+			'name' => 'Tueday',
+			'value' => '2'
+		),
+		array(
+			'name' => 'Wednesday',
+			'value' => '3'
+		),
+		array(
+			'name' => 'Thursday',
+			'value' => '4'
+		),
+		array(
+			'name' => 'Friday',
+			'value' => '5'
+		),
+		array(
+			'name' => 'Saturday',
+			'value' => '6'
+		)
+	);
+	$calendarDefault = array(
+		array(
+			'name' => 'Month',
+			'value' => 'month'
+		),
+		array(
+			'name' => 'Day',
+			'value' => 'basicDay'
+		),
+		array(
+			'name' => 'Week',
+			'value' => 'basicWeek'
+		)
+	);
+	$timeFormat = array(
+		array(
+			'name' => '6p',
+			'value' => 'h(:mm)t'
+		),
+		array(
+			'name' => '6:00p',
+			'value' => 'h:mmt'
+		),
+		array(
+			'name' => '6:00',
+			'value' => 'h:mm'
+		),
+		array(
+			'name' => '18',
+			'value' => 'H(:mm)'
+		),
+		array(
+			'name' => '18:00',
+			'value' => 'H:mm'
+		)
+	);
     return array(
         array(
             'name' => 'Plex',
@@ -671,6 +747,88 @@ function getHomepageList(){
                     )
                 )
             )
+        ),
+        array(
+            'name' => 'Sonarr',
+            'enabled' => false,
+            'image' => 'plugins/images/tabs/sonarr.png',
+            'category' => 'PVR',
+            'settings' => array(
+                'Enable' => array(
+                    array(
+                        'type' => 'switch',
+                        'name' => 'homepageSonarrEnabled',
+                        'label' => 'Enable',
+                        'value' => $GLOBALS['homepageSonarrEnabled']
+                    ),
+                    array(
+                        'type' => 'select',
+                        'name' => 'homepageSonarrAuth',
+                        'label' => 'Minimum Authentication',
+                        'value' => $GLOBALS['homepageSonarrAuth'],
+                        'options' => $groups
+                    )
+                ),
+                'Connection' => array(
+                    array(
+                        'type' => 'input',
+                        'name' => 'sonarrURL',
+                        'label' => 'URL',
+                        'value' => $GLOBALS['sonarrURL'],
+                        'placeholder' => 'http(s)://hostname:port'
+                    ),
+                    array(
+                        'type' => 'input',
+                        'name' => 'sonarrToken',
+                        'label' => 'Token',
+                        'value' => $GLOBALS['sonarrToken']
+                    )
+                ),
+                'Misc Options' => array(
+					array(
+						'type' => 'input',
+						'name' => 'calendarStart',
+						'label' => '# of Days Before',
+						'value' => $GLOBALS['calendarStart'],
+						'placeholder' => ''
+					),
+					array(
+						'type' => 'input',
+						'name' => 'calendarEnd',
+						'label' => '# of Days After',
+						'value' => $GLOBALS['calendarEnd'],
+						'placeholder' => ''
+					),
+					array(
+                        'type' => 'select',
+                        'name' => 'calendarFirstDay',
+                        'label' => 'Start Day',
+                        'value' => $GLOBALS['calendarFirstDay'],
+                        'options' => $day
+                    ),
+					array(
+                        'type' => 'select',
+                        'name' => 'calendarDefault',
+                        'label' => 'Default View',
+                        'value' => $GLOBALS['calendarDefault'],
+                        'options' => $calendarDefault
+                    ),
+					array(
+                        'type' => 'select',
+                        'name' => 'calendarTimeFormat',
+                        'label' => 'Time Format',
+                        'value' => $GLOBALS['calendarTimeFormat'],
+                        'options' => $timeFormat
+                    ),
+                    array(
+                        'type' => 'select',
+                        'name' => 'calendarRefresh',
+                        'label' => 'Refresh Seconds',
+                        'value' => $GLOBALS['calendarRefresh'],
+                        'options' => $time
+                    )
+                )
+            )
         )
     );
 }

+ 48 - 0
api/pages/homepage.php

@@ -2,6 +2,54 @@
 if(file_exists('config'.DIRECTORY_SEPARATOR.'config.php')){
 $pageHomepage = '
 <script>
+!function($) {
+    "use strict";
+    var CalendarApp = function() {
+        this.$body = $("body")
+        this.$calendar = $("#calendar"),
+        this.$event = ("#calendar-events div.calendar-events"),
+        this.$categoryForm = $("#add-new-event form"),
+        this.$extEvents = $("#calendar-events"),
+        this.$modal = $("#my-event"),
+        this.$saveCategoryBtn = $(".save-category"),
+        this.$calendarObj = null
+    };
+    /* Initializing */
+    CalendarApp.prototype.init = function() {
+        /*  Initialize the calendar  */
+        var date = new Date();
+        var d = date.getDate();
+        var m = date.getMonth();
+        var y = date.getFullYear();
+        var form = "";
+        var today = new Date($.now());
+        var $this = this;
+        $this.$calendarObj = $this.$calendar.fullCalendar({
+            defaultView: "'.$GLOBALS['calendarDefault'].'",
+            firstDay: "'.$GLOBALS['calendarFirstDay'].'",
+            timeFormat: "'.$GLOBALS['calendarTimeFormat'].'",
+            handleWindowResize: true,
+            header: {
+                left: "prev,next today",
+                center: "title",
+                right: "month,basicDay,basicWeek"
+            },
+            timezone: "local",
+            editable: false,
+            droppable: false, // this allows things to be dropped onto the calendar !!!
+            eventLimit: false, // allow "more" link when too many events
+            selectable: false,
+            height: "auto",
+        });
+    },
+   //init CalendarApp
+    $.CalendarApp = new CalendarApp, $.CalendarApp.Constructor = CalendarApp
+}(window.jQuery),
+//initializing CalendarApp
+function($) {
+    "use strict";
+    $.CalendarApp.init()
+}(window.jQuery);
 </script>
 <link href="plugins/bower_components/owl.carousel/owl.carousel.min.css" rel="stylesheet" type="text/css" />
 <link href="plugins/bower_components/owl.carousel/owl.theme.default.css" rel="stylesheet" type="text/css" />

File diff suppressed because it is too large
+ 0 - 0
css/horizontal.css


File diff suppressed because it is too large
+ 0 - 0
css/light.css


+ 10 - 0
css/organizr.css

@@ -236,3 +236,13 @@ td span.label.label-info {
 max-height: 300px;
 overflow-y: auto;
 }
+.fc-event {
+border-radius: 0;
+border: none;
+cursor: pointer;
+font-size: 13px;
+margin: 1px -1px 0;
+padding: 5px;
+text-align: left;
+background: #2cabe3;
+}

+ 2 - 0
index.php

@@ -22,6 +22,7 @@
 	<link href="plugins/bower_components/jquery-asColorPicker-master/css/asColorPicker.css" rel="stylesheet">
 	<link href="plugins/bower_components/dropzone-master/dist/dropzone.css" rel="stylesheet" type="text/css" />
 	<link href="plugins/bower_components/css-chart/css-chart.css" rel="stylesheet">
+	<link href="plugins/bower_components/calendar/dist/fullcalendar.css" rel="stylesheet" />
 	<link id="style" href="css/dark.css?v=<?php echo $GLOBALS['installedVersion']; ?>" rel="stylesheet">
 	<link href="css/organizr.css?v=<?php echo $GLOBALS['installedVersion']; ?>" rel="stylesheet">
 	<?php echo pluginFiles('css'); ?>
@@ -131,6 +132,7 @@
     <script src="plugins/bower_components/jquery-asColorPicker-master/dist/jquery-asColorPicker.min.js"></script>
 	<script src="plugins/bower_components/dropzone-master/dist/dropzone.js"></script>
 	<script src="plugins/bower_components/owl.carousel/owl.carousel.min.js"></script>
+	<script src='plugins/bower_components/calendar/dist/fullcalendar.js'></script>
 	<script src="js/functions.js?v=<?php echo $GLOBALS['installedVersion']; ?>"></script>
 	<script src="js/custom.js?v=<?php echo $GLOBALS['installedVersion']; ?>"></script>
 	<?php echo pluginFiles('js'); ?>

+ 14 - 0
js/functions.js

@@ -2424,6 +2424,20 @@ function homepageRecent(type){
 	});
 	ajaxloader();
 }
+function homepageCalendar(){
+	ajaxloader(".content-wrap","in");
+	organizrAPI('POST','api/?v1/homepage/connect',{action:'getCalendar'}).success(function(data) {
+		var response = JSON.parse(data);
+		console.log(response);
+        $('#calendar').fullCalendar('removeEvents');
+        $('#calendar').fullCalendar('addEventSource', response.data);
+        console.log('Calendar Entries Added');
+		//$('#homepageOrder'+type+'recent').html(buildRecent(response.data, type));
+	}).fail(function(xhr) {
+		console.error("Organizr Function: API Connection Failed");
+	});
+	ajaxloader();
+}
 //Generate API
 function generateCode() {
     var code = "";

File diff suppressed because it is too large
+ 479 - 448
plugins/bower_components/calendar/dist/fullcalendar.js


Some files were not shown because too many files changed in this diff