calendar.php 5.4 KB

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