calendar.php 5.8 KB

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