functions.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <?php
  2. function registration_callback($username, $email, $userdir){
  3. global $data;
  4. $data = array($username, $email, $userdir);
  5. }
  6. function printArray($arrayName){
  7. $messageCount = count($arrayName);
  8. $i = 0;
  9. foreach ( $arrayName as $item ) :
  10. $i++;
  11. if($i < $messageCount) :
  12. echo "<small class='text-uppercase'>" . $item . "</small> & ";
  13. elseif($i = $messageCount) :
  14. echo "<small class='text-uppercase'>" . $item . "</small>";
  15. endif;
  16. endforeach;
  17. }
  18. function write_ini_file($content, $path) {
  19. if (!$handle = fopen($path, 'w')) {
  20. return false;
  21. }
  22. $success = fwrite($handle, trim($content));
  23. fclose($handle);
  24. return $success;
  25. }
  26. function gotTimezone(){
  27. $regions = array(
  28. 'Africa' => DateTimeZone::AFRICA,
  29. 'America' => DateTimeZone::AMERICA,
  30. 'Antarctica' => DateTimeZone::ANTARCTICA,
  31. 'Arctic' => DateTimeZone::ARCTIC,
  32. 'Asia' => DateTimeZone::ASIA,
  33. 'Atlantic' => DateTimeZone::ATLANTIC,
  34. 'Australia' => DateTimeZone::AUSTRALIA,
  35. 'Europe' => DateTimeZone::EUROPE,
  36. 'Indian' => DateTimeZone::INDIAN,
  37. 'Pacific' => DateTimeZone::PACIFIC
  38. );
  39. $timezones = array();
  40. foreach ($regions as $name => $mask) {
  41. $zones = DateTimeZone::listIdentifiers($mask);
  42. foreach($zones as $timezone) {
  43. $time = new DateTime(NULL, new DateTimeZone($timezone));
  44. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  45. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  46. }
  47. }
  48. print '<select name="timezone" id="timezone" class="form-control material input-sm" required>';
  49. foreach($timezones as $region => $list) {
  50. print '<optgroup label="' . $region . '">' . "\n";
  51. foreach($list as $timezone => $name) {
  52. if($timezone == TIMEZONE) : $selected = " selected"; else : $selected = ""; endif;
  53. print '<option value="' . $timezone . '"' . $selected . '>' . $name . '</option>' . "\n";
  54. }
  55. print '</optgroup>' . "\n";
  56. }
  57. print '</select>';
  58. }
  59. function getTimezone(){
  60. $regions = array(
  61. 'Africa' => DateTimeZone::AFRICA,
  62. 'America' => DateTimeZone::AMERICA,
  63. 'Antarctica' => DateTimeZone::ANTARCTICA,
  64. 'Arctic' => DateTimeZone::ARCTIC,
  65. 'Asia' => DateTimeZone::ASIA,
  66. 'Atlantic' => DateTimeZone::ATLANTIC,
  67. 'Australia' => DateTimeZone::AUSTRALIA,
  68. 'Europe' => DateTimeZone::EUROPE,
  69. 'Indian' => DateTimeZone::INDIAN,
  70. 'Pacific' => DateTimeZone::PACIFIC
  71. );
  72. $timezones = array();
  73. foreach ($regions as $name => $mask) {
  74. $zones = DateTimeZone::listIdentifiers($mask);
  75. foreach($zones as $timezone) {
  76. $time = new DateTime(NULL, new DateTimeZone($timezone));
  77. $ampm = $time->format('H') > 12 ? ' ('. $time->format('g:i a'). ')' : '';
  78. $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' - ' . $time->format('H:i') . $ampm;
  79. }
  80. }
  81. print '<select name="timezone" id="timezone" class="form-control material" required>';
  82. foreach($timezones as $region => $list) {
  83. print '<optgroup label="' . $region . '">' . "\n";
  84. foreach($list as $timezone => $name) {
  85. print '<option value="' . $timezone . '">' . $name . '</option>' . "\n";
  86. }
  87. print '</optgroup>' . "\n";
  88. }
  89. print '</select>';
  90. }
  91. function explosion($string, $position){
  92. $getWord = explode("|", $string);
  93. return $getWord[$position];
  94. }
  95. function getServerPath() {
  96. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
  97. $protocol = "https://";
  98. } else {
  99. $protocol = "http://";
  100. }
  101. return $protocol . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
  102. }
  103. function get_browser_name() {
  104. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  105. if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
  106. elseif (strpos($user_agent, 'Edge')) return 'Edge';
  107. elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
  108. elseif (strpos($user_agent, 'Safari')) return 'Safari';
  109. elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
  110. elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
  111. return 'Other';
  112. }
  113. function getPlexRecent($url, $port, $type, $token, $size, $header){
  114. $urlCheck = stripos($url, "http");
  115. if ($urlCheck === false) {
  116. $url = "http://" . $url;
  117. }
  118. if($port !== ""){ $url = $url . ":" . $port; }
  119. $address = $url;
  120. $api = simplexml_load_file($address."/library/recentlyAdded?X-Plex-Token=".$token);
  121. $i = 0;
  122. $gotPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5><div id="carousel-'.$type.'" class="carousel slide box-shadow white-bg" data-ride="carousel"><div class="carousel-inner" role="listbox">';
  123. foreach($api AS $child) {
  124. if($child['type'] == $type){
  125. $i++;
  126. if($i == 1){ $active = "active"; }else{ $active = "";}
  127. $thumb = $child['thumb'];
  128. if($type == "movie"){
  129. $title = $child['title'];
  130. $summary = $child['summary'];
  131. $height = "150";
  132. $width = "100";
  133. }elseif($type == "season"){
  134. $title = $child['parentTitle'];
  135. $summary = $child['parentSummary'];
  136. $height = "150";
  137. $width = "100";
  138. }elseif($type == "album"){
  139. $title = $child['parentTitle'];
  140. $summary = $child['title'];
  141. $height = "150";
  142. $width = "150";
  143. }
  144. $gotPlex .= '<div class="item '.$active.'"><img class="carousel-image '.$type.'" src="image.php?img='.$address.$thumb.'&height='.$height.'&width='.$width.'"><div class="carousel-caption '.$type.'" style="overflow:auto"><h4>'.$title.'</h4><small><em>'.$summary.'</em></small></div></div>';
  145. }
  146. }
  147. $gotPlex .= '</div>';
  148. if ($i > 1){
  149. $gotPlex .= '<a class="left carousel-control '.$type.'" href="#carousel-'.$type.'" role="button" data-slide="prev"><span class="fa fa-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a><a class="right carousel-control '.$type.'" href="#carousel-'.$type.'" role="button" data-slide="next"><span class="fa fa-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>';
  150. }
  151. $gotPlex .= '</div>';
  152. $gotPlex .= '</div>';
  153. if ($i != 0){ return $gotPlex; }
  154. }
  155. function getPlexStreams($url, $port, $token, $size, $header){
  156. $urlCheck = stripos($url, "http");
  157. if ($urlCheck === false) {
  158. $url = "http://" . $url;
  159. }
  160. if($port !== ""){ $url = $url . ":" . $port; }
  161. $address = $url;
  162. $api = simplexml_load_file($address."/status/sessions?X-Plex-Token=".$token);
  163. $i = 0;
  164. $gotPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  165. $gotPlex .= '<div id="carousel-streams" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  166. $gotPlex .= '<div class="carousel-inner" role="listbox">';
  167. foreach($api AS $child) {
  168. $type = $child['type'];
  169. $i++;
  170. if($i == 1){ $active = "active"; }else{ $active = "";}
  171. if($type == "movie"){
  172. $title = $child['title'];
  173. $summary = $child['summary'];
  174. $thumb = $child['thumb'];
  175. $image = "movie";
  176. $height = "150";
  177. $width = "100";
  178. }elseif($type == "episode"){
  179. $title = $child['grandparentTitle'];
  180. $summary = htmlspecialchars($child['summary'], ENT_QUOTES);
  181. $thumb = $child['grandparentThumb'];
  182. $image = "season";
  183. $height = "150";
  184. $width = "100";
  185. }elseif($type == "track"){
  186. $title = $child['grandparentTitle'] . " - " . $child['parentTitle'];
  187. $summary = $child['title'];
  188. $thumb = $child['thumb'];
  189. $image = "album";
  190. $height = "150";
  191. $width = "150";
  192. }
  193. $gotPlex .= '<div class="item '.$active.'">';
  194. $gotPlex .= "<img class='carousel-image $image' src='image.php?img=$address$thumb&height=$height&width=$width'>";
  195. $gotPlex .= '<div class="carousel-caption '. $image . '" style="overflow:auto"><h4>'.$title.'</h4><small><em>'.$summary.'</em></small></div></div>';
  196. }
  197. $gotPlex .= '</div>';
  198. if ($i > 1){
  199. $gotPlex .= '<a class="left carousel-control streams" href="#carousel-streams" role="button" data-slide="prev"><span class="fa fa-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a><a class="right carousel-control streams" href="#carousel-streams" role="button" data-slide="next"><span class="fa fa-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>';
  200. }
  201. $gotPlex .= '</div></div>';
  202. $noPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  203. $noPlex .= '<div id="carousel-streams" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  204. $noPlex .= '<div class="carousel-inner" role="listbox">';
  205. $noPlex .= '<div class="item active">';
  206. $noPlex .= "<img class='carousel-image movie' src='images/nadaplaying.jpg'>";
  207. $noPlex .= '<div class="carousel-caption" style="overflow:auto"><h4>Nothing Playing</h4><small><em>Get to Streaming!</em></small></div></div></div></div></div>';
  208. if ($i != 0){ return $gotPlex; }
  209. if ($i == 0){ return $noPlex; }
  210. }
  211. function getSonarrCalendar($url, $port, $key){
  212. $startDate = date('Y-m-d',strtotime("-30 days"));
  213. $endDate = date('Y-m-d',strtotime("+30 days"));
  214. $urlCheck = stripos($url, "http");
  215. if ($urlCheck === false) {
  216. $url = "http://" . $url;
  217. }
  218. if($port !== ""){ $url = $url . ":" . $port; }
  219. $address = $url;
  220. $api = file_get_contents($address."/api/calendar?apikey=".$key."&start=".$startDate."&end=".$endDate);
  221. $api = json_decode($api, true);
  222. $i = 0;
  223. $gotCalendar = "";
  224. foreach($api AS $child) {
  225. $i++;
  226. $seriesName = $child['series']['title'];
  227. $runtime = $child['series']['runtime'];
  228. $episodeName = htmlspecialchars($child['title'], ENT_QUOTES);
  229. $episodeAirDate = $child['airDateUtc'];
  230. $episodeAirDate = strtotime($episodeAirDate);
  231. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  232. $downloaded = $child['hasFile'];
  233. if($downloaded == "0"){ $downloaded = "red-bg";}elseif($downloaded == "1"){ $downloaded = "green-bg";}
  234. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\" }, \n";
  235. }
  236. if ($i != 0){ return $gotCalendar; }
  237. }
  238. function getRadarrCalendar($url, $port, $key){
  239. $startDate = date('Y-m-d',strtotime("-30 days"));
  240. $endDate = date('Y-m-d',strtotime("+30 days"));
  241. $urlCheck = stripos($url, "http");
  242. if ($urlCheck === false) {
  243. $url = "http://" . $url;
  244. }
  245. if($port !== ""){ $url = $url . ":" . $port; }
  246. $address = $url;
  247. $api = file_get_contents($address."/api/calendar?apikey=".$key."&start=".$startDate."&end=".$endDate);
  248. $api = json_decode($api, true);
  249. $i = 0;
  250. $gotCalendar = "";
  251. foreach($api AS $child) {
  252. if(isset($child['physicalRelease'])){
  253. $i++;
  254. $movieName = $child['title'];
  255. $runtime = $child['runtime'];
  256. $physicalRelease = $child['physicalRelease'];
  257. $physicalRelease = strtotime($physicalRelease);
  258. $physicalRelease = date("Y-m-d", $physicalRelease);
  259. $downloaded = $child['hasFile'];
  260. if($downloaded == "0"){ $downloaded = "progress-bar-danger progress-bar-striped";}elseif($downloaded == "1"){ $downloaded = "progress-bar-success progress-bar-striped";}
  261. $gotCalendar .= "{ title: \"$movieName\", start: \"$physicalRelease\", className: \"$downloaded\", imagetype: \"film\" }, \n";
  262. }
  263. }
  264. if ($i != 0){ return $gotCalendar; }
  265. }
  266. ?>