functions.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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 = file_get_contents($address."/library/recentlyAdded?X-Plex-Token=".$token);
  121. $api = simplexml_load_string($api);
  122. $i = 0;
  123. $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">';
  124. foreach($api AS $child) {
  125. if($child['type'] == $type){
  126. $i++;
  127. if($i == 1){ $active = "active"; }else{ $active = "";}
  128. $thumb = $child['thumb'];
  129. if($type == "movie"){
  130. $title = $child['title'];
  131. $summary = $child['summary'];
  132. $height = "150";
  133. $width = "100";
  134. }elseif($type == "season"){
  135. $title = $child['parentTitle'];
  136. $summary = $child['parentSummary'];
  137. $height = "150";
  138. $width = "100";
  139. }elseif($type == "album"){
  140. $title = $child['parentTitle'];
  141. $summary = $child['title'];
  142. $height = "150";
  143. $width = "150";
  144. }
  145. $gotPlex .= '<div class="item '.$active.'"><img class="carousel-image '.$type.'" src="image.php?img='.$thumb.'&height='.$height.'&width='.$width.'"><div class="carousel-caption '.$type.'"><h4>'.$title.'</h4><small><em>'.$summary.'</em></small></div></div>';
  146. }
  147. }
  148. $gotPlex .= '</div>';
  149. if ($i > 1){
  150. $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>';
  151. }
  152. $gotPlex .= '</div>';
  153. $gotPlex .= '</div>';
  154. if ($i != 0){ return $gotPlex; }
  155. }
  156. function getPlexStreams($url, $port, $token, $size, $header){
  157. $urlCheck = stripos($url, "http");
  158. if ($urlCheck === false) {
  159. $url = "http://" . $url;
  160. }
  161. if($port !== ""){ $url = $url . ":" . $port; }
  162. $address = $url;
  163. $api = file_get_contents($address."/status/sessions?X-Plex-Token=".$token);
  164. $api = simplexml_load_string($api);
  165. $i = 0;
  166. $gotPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  167. $gotPlex .= '<div id="carousel-streams" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  168. $gotPlex .= '<div class="carousel-inner" role="listbox">';
  169. foreach($api AS $child) {
  170. $type = $child['type'];
  171. $i++;
  172. if($i == 1){ $active = "active"; }else{ $active = "";}
  173. if($type == "movie"){
  174. $title = $child['title'];
  175. $summary = $child['summary'];
  176. $thumb = $child['thumb'];
  177. $image = "movie";
  178. $height = "150";
  179. $width = "100";
  180. }elseif($type == "episode"){
  181. $title = $child['grandparentTitle'];
  182. $summary = htmlspecialchars($child['summary'], ENT_QUOTES);
  183. $thumb = $child['grandparentThumb'];
  184. $image = "season";
  185. $height = "150";
  186. $width = "100";
  187. }elseif($type == "track"){
  188. $title = $child['grandparentTitle'] . " - " . $child['parentTitle'];
  189. $summary = $child['title'];
  190. $thumb = $child['thumb'];
  191. $image = "album";
  192. $height = "150";
  193. $width = "150";
  194. }elseif($type == "clip"){
  195. $title = $child['title'].' - Trailer';
  196. $summary = ($child['summary'] != "" ? $child['summary'] : "<i>No summary loaded.</i>");
  197. $thumb = ($child['thumb'] != "" ? $child['thumb'] : 'images/nadaplaying.jpg');
  198. $image = "movie";
  199. $height = "150";
  200. $width = "100";
  201. }
  202. $gotPlex .= '<div class="item '.$active.'">';
  203. $gotPlex .= "<img class='carousel-image $image' src='image.php?img=$thumb&height=$height&width=$width'>";
  204. $gotPlex .= '<div class="carousel-caption '. $image . '""><h4>'.$title.'</h4><small><em>'.$summary.'</em></small></div></div>';
  205. }
  206. $gotPlex .= '</div>';
  207. if ($i > 1){
  208. $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>';
  209. }
  210. $gotPlex .= '</div></div>';
  211. $noPlex = '<div class="col-lg-'.$size.'"><h5 class="text-center">'.$header.'</h5>';
  212. $noPlex .= '<div id="carousel-streams" class="carousel slide box-shadow white-bg" data-ride="carousel">';
  213. $noPlex .= '<div class="carousel-inner" role="listbox">';
  214. $noPlex .= '<div class="item active">';
  215. $noPlex .= "<img class='carousel-image movie' src='images/nadaplaying.jpg'>";
  216. $noPlex .= '<div class="carousel-caption"><h4>Nothing Playing</h4><small><em>Get to Streaming!</em></small></div></div></div></div></div>';
  217. if ($i != 0){ return $gotPlex; }
  218. if ($i == 0){ return $noPlex; }
  219. }
  220. function getSonarrCalendar($url, $port, $key){
  221. $startDate = date('Y-m-d',strtotime("-30 days"));
  222. $endDate = date('Y-m-d',strtotime("+30 days"));
  223. $urlCheck = stripos($url, "http");
  224. if ($urlCheck === false) {
  225. $url = "http://" . $url;
  226. }
  227. if($port !== ""){ $url = $url . ":" . $port; }
  228. $address = $url;
  229. $api = file_get_contents($address."/api/calendar?apikey=".$key."&start=".$startDate."&end=".$endDate);
  230. $api = json_decode($api, true);
  231. $i = 0;
  232. $gotCalendar = "";
  233. foreach($api AS $child) {
  234. $i++;
  235. $seriesName = $child['series']['title'];
  236. $runtime = $child['series']['runtime'];
  237. $episodeName = htmlspecialchars($child['title'], ENT_QUOTES);
  238. $episodeAirDate = $child['airDateUtc'];
  239. $episodeAirDate = strtotime($episodeAirDate);
  240. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  241. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  242. $downloaded = $child['hasFile'];
  243. if($downloaded == "0" && isset($unaired)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg";}else{ $downloaded = "red-bg"; }
  244. $gotCalendar .= "{ title: \"$seriesName\", start: \"$episodeAirDate\", className: \"$downloaded\", imagetype: \"tv\" }, \n";
  245. }
  246. if ($i != 0){ return $gotCalendar; }
  247. }
  248. function getRadarrCalendar($url, $port, $key){
  249. $startDate = date('Y-m-d',strtotime("-30 days"));
  250. $endDate = date('Y-m-d',strtotime("+30 days"));
  251. $urlCheck = stripos($url, "http");
  252. if ($urlCheck === false) {
  253. $url = "http://" . $url;
  254. }
  255. if($port !== ""){ $url = $url . ":" . $port; }
  256. $address = $url;
  257. $api = file_get_contents($address."/api/calendar?apikey=".$key."&start=".$startDate."&end=".$endDate);
  258. $api = json_decode($api, true);
  259. $i = 0;
  260. $gotCalendar = "";
  261. foreach($api AS $child) {
  262. if(isset($child['physicalRelease'])){
  263. $i++;
  264. $movieName = $child['title'];
  265. $runtime = $child['runtime'];
  266. $physicalRelease = $child['physicalRelease'];
  267. $physicalRelease = strtotime($physicalRelease);
  268. $physicalRelease = date("Y-m-d", $physicalRelease);
  269. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = true; }
  270. $downloaded = $child['hasFile'];
  271. if($downloaded == "0" && isset($notReleased)){ $downloaded = "indigo-bg"; }elseif($downloaded == "1"){ $downloaded = "green-bg"; }else{ $downloaded = "red-bg"; }
  272. $gotCalendar .= "{ title: \"$movieName\", start: \"$physicalRelease\", className: \"$downloaded\", imagetype: \"film\" }, \n";
  273. }
  274. }
  275. if ($i != 0){ return $gotCalendar; }
  276. }
  277. function nzbgetConnect($url, $port, $username, $password, $list){
  278. $urlCheck = stripos($url, "http");
  279. if ($urlCheck === false) {
  280. $url = "http://" . $url;
  281. }
  282. if($port !== ""){ $url = $url . ":" . $port; }
  283. $address = $url;
  284. $api = file_get_contents("$url/$username:$password/jsonrpc/$list");
  285. $api = json_decode($api, true);
  286. $i = 0;
  287. $gotNZB = "";
  288. foreach ($api['result'] AS $child) {
  289. $i++;
  290. //echo '<pre>' . var_export($child, true) . '</pre>';
  291. $downloadName = $child['NZBName'];
  292. $downloadStatus = $child['Status'];
  293. $downloadCategory = $child['Category'];
  294. if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
  295. if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
  296. if($child['Health'] <= "750"){
  297. $downloadHealth = "danger";
  298. }elseif($child['Health'] <= "900"){
  299. $downloadHealth = "warning";
  300. }elseif($child['Health'] <= "1000"){
  301. $downloadHealth = "success";
  302. }
  303. $gotNZB .= '<tr>
  304. <td>'.$downloadName.'</td>
  305. <td>'.$downloadStatus.'</td>
  306. <td>'.$downloadCategory.'</td>
  307. <td>
  308. <div class="progress">
  309. <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  310. <p class="text-center">'.round($downloadPercent).'%</p>
  311. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  312. </div>
  313. </div>
  314. </td>
  315. </tr>';
  316. }
  317. if($i > 0){ return $gotNZB; }
  318. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  319. }
  320. function sabnzbdConnect($url, $port, $key, $list){
  321. $urlCheck = stripos($url, "http");
  322. if ($urlCheck === false) {
  323. $url = "http://" . $url;
  324. }
  325. if($port !== ""){ $url = $url . ":" . $port; }
  326. $address = $url;
  327. $api = file_get_contents("$url/api?mode=$list&output=json&apikey=$key");
  328. $api = json_decode($api, true);
  329. $i = 0;
  330. $gotNZB = "";
  331. foreach ($api[$list]['slots'] AS $child) {
  332. $i++;
  333. if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; }
  334. if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
  335. $downloadStatus = $child['status'];
  336. $gotNZB .= '<tr>
  337. <td>'.$downloadName.'</td>
  338. <td>'.$downloadStatus.'</td>
  339. <td>'.$downloadCategory.'</td>
  340. <td>
  341. <div class="progress">
  342. <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
  343. <p class="text-center">'.round($downloadPercent).'%</p>
  344. <span class="sr-only">'.$downloadPercent.'% Complete</span>
  345. </div>
  346. </div>
  347. </td>
  348. </tr>';
  349. }
  350. if($i > 0){ return $gotNZB; }
  351. if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
  352. }
  353. function getHeadphonesCalendar($url, $port, $key, $list){
  354. $urlCheck = stripos($url, "http");
  355. if ($urlCheck === false) {
  356. $url = "http://" . $url;
  357. }
  358. if($port !== ""){ $url = $url . ":" . $port; }
  359. $address = $url;
  360. $api = file_get_contents($address."/api?apikey=".$key."&cmd=$list");
  361. $api = json_decode($api, true);
  362. $i = 0;
  363. $gotCalendar = "";
  364. foreach($api AS $child) {
  365. if($child['Status'] != "Skipped"){
  366. $i++;
  367. $albumName = $child['AlbumTitle'];
  368. $albumArtist = $child['ArtistName'];
  369. $albumDate = $child['ReleaseDate'];
  370. $albumDate = strtotime($albumDate);
  371. $albumDate = date("Y-m-d", $albumDate);
  372. $albumStatus = $child['Status'];
  373. if (new DateTime() < new DateTime($albumDate)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  374. if($albumStatus == "Wanted" && $notReleased == "true"){ $albumStatusColor = "indigo-bg"; }elseif($albumStatus == "Downloaded"){ $albumStatusColor = "green-bg"; }else{ $albumStatusColor = "red-bg"; }
  375. $gotCalendar .= "{ title: \"$albumArtist - $albumName\", start: \"$albumDate\", className: \"$albumStatusColor\", imagetype: \"music\" }, \n";
  376. }
  377. }
  378. if ($i != 0){ return $gotCalendar; }
  379. }
  380. ?>