calendar.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. trait CalendarHomepageItem
  3. {
  4. public function calendarSettingsArray($infoOnly = false)
  5. {
  6. $homepageInformation = [
  7. 'name' => 'iCal',
  8. 'enabled' => strpos('personal', $this->config['license']) !== false,
  9. 'image' => 'plugins/images/tabs/calendar.png',
  10. 'category' => 'HOMEPAGE',
  11. 'settingsArray' => __FUNCTION__
  12. ];
  13. if ($infoOnly) {
  14. return $homepageInformation;
  15. }
  16. $homepageSettings = array(
  17. 'settings' => array(
  18. 'Enable' => array(
  19. array(
  20. 'type' => 'switch',
  21. 'name' => 'homepageCalendarEnabled',
  22. 'label' => 'Enable iCal',
  23. 'value' => $this->config['homepageCalendarEnabled']
  24. ),
  25. array(
  26. 'type' => 'select',
  27. 'name' => 'homepageCalendarAuth',
  28. 'label' => 'Minimum Authentication',
  29. 'value' => $this->config['homepageCalendarAuth'],
  30. 'options' => $this->groupOptions
  31. ),
  32. array(
  33. 'type' => 'input',
  34. 'name' => 'calendariCal',
  35. 'label' => 'iCal URL\'s',
  36. 'value' => $this->config['calendariCal'],
  37. 'placeholder' => 'separate by comma\'s'
  38. ),
  39. ),
  40. 'Misc Options' => array(
  41. array(
  42. 'type' => 'number',
  43. 'name' => 'calendarStart',
  44. 'label' => '# of Days Before',
  45. 'value' => $this->config['calendarStart'],
  46. 'placeholder' => ''
  47. ),
  48. array(
  49. 'type' => 'number',
  50. 'name' => 'calendarEnd',
  51. 'label' => '# of Days After',
  52. 'value' => $this->config['calendarEnd'],
  53. 'placeholder' => ''
  54. ),
  55. array(
  56. 'type' => 'select',
  57. 'name' => 'calendarFirstDay',
  58. 'label' => 'Start Day',
  59. 'value' => $this->config['calendarFirstDay'],
  60. 'options' => $this->daysOptions()
  61. ),
  62. array(
  63. 'type' => 'select',
  64. 'name' => 'calendarDefault',
  65. 'label' => 'Default View',
  66. 'value' => $this->config['calendarDefault'],
  67. 'options' => $this->calendarDefaultOptions()
  68. ),
  69. array(
  70. 'type' => 'select',
  71. 'name' => 'calendarTimeFormat',
  72. 'label' => 'Time Format',
  73. 'value' => $this->config['calendarTimeFormat'],
  74. 'options' => $this->timeFormatOptions()
  75. ),
  76. array(
  77. 'type' => 'select',
  78. 'name' => 'calendarLocale',
  79. 'label' => 'Locale',
  80. 'value' => $this->config['calendarLocale'],
  81. 'options' => $this->calendarLocaleOptions()
  82. ),
  83. array(
  84. 'type' => 'select',
  85. 'name' => 'calendarLimit',
  86. 'label' => 'Items Per Day',
  87. 'value' => $this->config['calendarLimit'],
  88. 'options' => $this->limitOptions()
  89. ),
  90. array(
  91. 'type' => 'select',
  92. 'name' => 'calendarRefresh',
  93. 'label' => 'Refresh Seconds',
  94. 'value' => $this->config['calendarRefresh'],
  95. 'options' => $this->timeOptions()
  96. )
  97. ),
  98. )
  99. );
  100. return array_merge($homepageInformation, $homepageSettings);
  101. }
  102. public function calendarHomepagePermissions($key = null)
  103. {
  104. $permissions = [
  105. 'main' => [
  106. 'enabled' => [
  107. 'homepageCalendarEnabled'
  108. ],
  109. 'auth' => [
  110. 'homepageCalendarAuth'
  111. ],
  112. 'not_empty' => [
  113. 'calendariCal'
  114. ]
  115. ]
  116. ];
  117. if (array_key_exists($key, $permissions)) {
  118. return $permissions[$key];
  119. } elseif ($key == 'all') {
  120. return $permissions;
  121. } else {
  122. return [];
  123. }
  124. }
  125. public function homepageOrdercalendar()
  126. {
  127. if (
  128. $this->homepageItemPermissions($this->sonarrHomepagePermissions('calendar')) ||
  129. $this->homepageItemPermissions($this->radarrHomepagePermissions('calendar')) ||
  130. $this->homepageItemPermissions($this->lidarrHomepagePermissions('calendar')) ||
  131. $this->homepageItemPermissions($this->sickrageHomepagePermissions('calendar')) ||
  132. $this->homepageItemPermissions($this->couchPotatoHomepagePermissions('calendar')) ||
  133. $this->homepageItemPermissions($this->traktHomepagePermissions('calendar')) ||
  134. $this->homepageItemPermissions($this->calendarHomepagePermissions('main'))
  135. ) {
  136. return '
  137. <div id="' . __FUNCTION__ . '">
  138. <div id="calendar" class="fc fc-ltr m-b-30"></div>
  139. <script>
  140. // Calendar
  141. homepageCalendar("' . $this->config['calendarRefresh'] . '");
  142. // End Calendar
  143. </script>
  144. </div>
  145. ';
  146. }
  147. }
  148. public function loadCalendarJS()
  149. {
  150. $locale = ($this->config['calendarLocale'] !== 'en') ?? false;
  151. return ($locale) ? '<script src="plugins/bower_components/calendar/dist/lang-all.js"></script>' : '';
  152. }
  153. public function getCalendar()
  154. {
  155. $startDate = date('Y-m-d', strtotime("-" . $this->config['calendarStart'] . " days"));
  156. $endDate = date('Y-m-d', strtotime("+" . $this->config['calendarEnd'] . " days"));
  157. $icalCalendarSources = array();
  158. $calendarItems = array();
  159. // SONARR CONNECT
  160. $items = $this->getSonarrCalendar($startDate, $endDate);
  161. $calendarItems = is_array($items) ? array_merge($calendarItems, $items) : $calendarItems;
  162. unset($items);
  163. // LIDARR CONNECT
  164. $items = $this->getLidarrCalendar($startDate, $endDate);
  165. $calendarItems = is_array($items) ? array_merge($calendarItems, $items) : $calendarItems;
  166. unset($items);
  167. // RADARR CONNECT
  168. $items = $this->getRadarrCalendar($startDate, $endDate);
  169. $calendarItems = is_array($items) ? array_merge($calendarItems, $items) : $calendarItems;
  170. unset($items);
  171. // SICKRAGE/BEARD/MEDUSA CONNECT
  172. $items = $this->getSickRageCalendar();
  173. $calendarItems = is_array($items) ? array_merge($calendarItems, $items) : $calendarItems;
  174. unset($items);
  175. // COUCHPOTATO CONNECT
  176. $items = $this->getCouchPotatoCalendar();
  177. $calendarItems = is_array($items) ? array_merge($calendarItems, $items) : $calendarItems;
  178. unset($items);
  179. // TRAKT CONNECT
  180. $items = $this->getTraktCalendar();
  181. $calendarItems = is_array($items) ? array_merge($calendarItems, $items) : $calendarItems;
  182. unset($items);
  183. // iCal URL
  184. $calendarSources['ical'] = $this->getICalendar();
  185. unset($items);
  186. // Finish
  187. $calendarSources['events'] = $calendarItems;
  188. $this->setAPIResponse('success', null, 200, $calendarSources);
  189. return $calendarSources;
  190. }
  191. }