Preference.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. <?php
  2. require_once 'Cache.php';
  3. class Application_Model_Preference
  4. {
  5. private static function getUserId()
  6. {
  7. //pass in true so the check is made with the autoloader
  8. //we need this check because saas calls this function from outside Zend
  9. if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
  10. $userId = null;
  11. } else {
  12. $auth = Zend_Auth::getInstance();
  13. $userId = $auth->getIdentity()->id;
  14. }
  15. return $userId;
  16. }
  17. /**
  18. *
  19. * @param boolean $isUserValue is true when we are setting a value for the current user
  20. */
  21. private static function setValue($key, $value, $isUserValue = false)
  22. {
  23. $cache = new Cache();
  24. try {
  25. $con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
  26. $con->beginTransaction();
  27. $userId = self::getUserId();
  28. if ($isUserValue && is_null($userId))
  29. throw new Exception("User id can't be null for a user preference {$key}.");
  30. //Check if key already exists
  31. $sql = "SELECT COUNT(*) FROM cc_pref"
  32. ." WHERE keystr = :key";
  33. $paramMap = array();
  34. $paramMap[':key'] = $key;
  35. //For user specific preference, check if id matches as well
  36. if ($isUserValue) {
  37. $sql .= " AND subjid = :id";
  38. $paramMap[':id'] = $userId;
  39. }
  40. $result = Application_Common_Database::prepareAndExecute($sql,
  41. $paramMap,
  42. Application_Common_Database::COLUMN,
  43. PDO::FETCH_ASSOC,
  44. $con);
  45. $paramMap = array();
  46. if ($result > 1) {
  47. //this case should not happen.
  48. throw new Exception("Invalid number of results returned. Should be ".
  49. "0 or 1, but is '$result' instead");
  50. } else if ($result == 1) {
  51. // result found
  52. if (!$isUserValue) {
  53. // system pref
  54. $sql = "UPDATE cc_pref"
  55. ." SET subjid = NULL, valstr = :value"
  56. ." WHERE keystr = :key";
  57. } else {
  58. // user pref
  59. $sql = "UPDATE cc_pref"
  60. . " SET valstr = :value"
  61. . " WHERE keystr = :key AND subjid = :id";
  62. $paramMap[':id'] = $userId;
  63. }
  64. } else {
  65. // result not found
  66. if (!$isUserValue) {
  67. // system pref
  68. $sql = "INSERT INTO cc_pref (keystr, valstr)"
  69. ." VALUES (:key, :value)";
  70. } else {
  71. // user pref
  72. $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
  73. ." VALUES (:id, :key, :value)";
  74. $paramMap[':id'] = $userId;
  75. }
  76. }
  77. $paramMap[':key'] = $key;
  78. $paramMap[':value'] = $value;
  79. Application_Common_Database::prepareAndExecute($sql,
  80. $paramMap,
  81. 'execute',
  82. PDO::FETCH_ASSOC,
  83. $con);
  84. $con->commit();
  85. } catch (Exception $e) {
  86. $con->rollback();
  87. header('HTTP/1.0 503 Service Unavailable');
  88. Logging::info("Database error: ".$e->getMessage());
  89. exit;
  90. }
  91. $cache->store($key, $value, $isUserValue, $userId);
  92. }
  93. private static function getValue($key, $isUserValue = false)
  94. {
  95. $cache = new Cache();
  96. try {
  97. $userId = self::getUserId();
  98. if ($isUserValue && is_null($userId))
  99. throw new Exception("User id can't be null for a user preference.");
  100. // If the value is already cached, return it
  101. $res = $cache->fetch($key, $isUserValue, $userId);
  102. if ($res !== false) return $res;
  103. //Check if key already exists
  104. $sql = "SELECT COUNT(*) FROM cc_pref"
  105. ." WHERE keystr = :key";
  106. $paramMap = array();
  107. $paramMap[':key'] = $key;
  108. //For user specific preference, check if id matches as well
  109. if ($isUserValue) {
  110. $sql .= " AND subjid = :id";
  111. $paramMap[':id'] = $userId;
  112. }
  113. $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
  114. //return an empty string if the result doesn't exist.
  115. if ($result == 0) {
  116. $res = "";
  117. } else {
  118. $sql = "SELECT valstr FROM cc_pref"
  119. ." WHERE keystr = :key";
  120. $paramMap = array();
  121. $paramMap[':key'] = $key;
  122. //For user specific preference, check if id matches as well
  123. if ($isUserValue) {
  124. $sql .= " AND subjid = :id";
  125. $paramMap[':id'] = $userId;
  126. }
  127. $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
  128. $res = ($result !== false) ? $result : "";
  129. }
  130. $cache->store($key, $res, $isUserValue, $userId);
  131. return $res;
  132. }
  133. catch (Exception $e) {
  134. header('HTTP/1.0 503 Service Unavailable');
  135. Logging::info("Could not connect to database: ".$e->getMessage());
  136. exit;
  137. }
  138. }
  139. public static function GetHeadTitle()
  140. {
  141. $title = self::getValue("station_name");
  142. if (strlen($title) > 0)
  143. $title .= " - ";
  144. return $title."Airtime";
  145. }
  146. public static function SetHeadTitle($title, $view=null)
  147. {
  148. self::setValue("station_name", $title);
  149. // in case this is called from airtime-saas script
  150. if ($view !== null) {
  151. //set session variable to new station name so that html title is updated.
  152. //should probably do this in a view helper to keep this controller as minimal as possible.
  153. $view->headTitle()->exchangeArray(array()); //clear headTitle ArrayObject
  154. $view->headTitle(self::GetHeadTitle());
  155. }
  156. $eventType = "update_station_name";
  157. $md = array("station_name"=>$title);
  158. Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
  159. }
  160. /**
  161. * Set the furthest date that a never-ending show
  162. * should be populated until.
  163. *
  164. * @param DateTime $dateTime
  165. * A row from cc_show_days table
  166. */
  167. public static function SetShowsPopulatedUntil($dateTime)
  168. {
  169. $dateTime->setTimezone(new DateTimeZone("UTC"));
  170. self::setValue("shows_populated_until", $dateTime->format("Y-m-d H:i:s"));
  171. }
  172. /**
  173. * Get the furthest date that a never-ending show
  174. * should be populated until.
  175. *
  176. * Returns null if the value hasn't been set, otherwise returns
  177. * a DateTime object representing the date.
  178. *
  179. * @return DateTime (in UTC Timezone)
  180. */
  181. public static function GetShowsPopulatedUntil()
  182. {
  183. $date = self::getValue("shows_populated_until");
  184. if ($date == "") {
  185. return null;
  186. } else {
  187. return new DateTime($date, new DateTimeZone("UTC"));
  188. }
  189. }
  190. public static function SetDefaultCrossfadeDuration($duration)
  191. {
  192. self::setValue("default_crossfade_duration", $duration);
  193. }
  194. public static function GetDefaultCrossfadeDuration()
  195. {
  196. $duration = self::getValue("default_crossfade_duration");
  197. if ($duration === "") {
  198. // the default value of the fade is 00.5
  199. return "0";
  200. }
  201. return $duration;
  202. }
  203. public static function SetDefaultFadeIn($fade)
  204. {
  205. self::setValue("default_fade_in", $fade);
  206. }
  207. public static function GetDefaultFadeIn()
  208. {
  209. $fade = self::getValue("default_fade_in");
  210. if ($fade === "") {
  211. // the default value of the fade is 00.5
  212. return "0.5";
  213. }
  214. return $fade;
  215. }
  216. public static function SetDefaultFadeOut($fade)
  217. {
  218. self::setValue("default_fade_out", $fade);
  219. }
  220. public static function GetDefaultFadeOut()
  221. {
  222. $fade = self::getValue("default_fade_out");
  223. if ($fade === "") {
  224. // the default value of the fade is 0.5
  225. return "0.5";
  226. }
  227. return $fade;
  228. }
  229. public static function SetDefaultFade($fade)
  230. {
  231. self::setValue("default_fade", $fade);
  232. }
  233. public static function SetDefaultTransitionFade($fade)
  234. {
  235. self::setValue("default_transition_fade", $fade);
  236. $eventType = "update_transition_fade";
  237. $md = array("transition_fade"=>$fade);
  238. Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
  239. }
  240. public static function GetDefaultTransitionFade()
  241. {
  242. $transition_fade = self::getValue("default_transition_fade");
  243. return ($transition_fade == "") ? "0.000" : $transition_fade;
  244. }
  245. public static function SetStreamLabelFormat($type)
  246. {
  247. self::setValue("stream_label_format", $type);
  248. $eventType = "update_stream_format";
  249. $md = array("stream_format"=>$type);
  250. Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
  251. }
  252. public static function GetStreamLabelFormat()
  253. {
  254. return self::getValue("stream_label_format");
  255. }
  256. public static function GetStationName()
  257. {
  258. return self::getValue("station_name");
  259. }
  260. public static function SetAutoUploadRecordedShowToSoundcloud($upload)
  261. {
  262. self::setValue("soundcloud_auto_upload_recorded_show", $upload);
  263. }
  264. public static function GetAutoUploadRecordedShowToSoundcloud()
  265. {
  266. return self::getValue("soundcloud_auto_upload_recorded_show");
  267. }
  268. public static function SetSoundCloudUser($user)
  269. {
  270. self::setValue("soundcloud_user", $user);
  271. }
  272. public static function GetSoundCloudUser()
  273. {
  274. return self::getValue("soundcloud_user");
  275. }
  276. public static function SetSoundCloudPassword($password)
  277. {
  278. if (strlen($password) > 0)
  279. self::setValue("soundcloud_password", $password);
  280. }
  281. public static function GetSoundCloudPassword()
  282. {
  283. return self::getValue("soundcloud_password");
  284. }
  285. public static function SetSoundCloudTags($tags)
  286. {
  287. self::setValue("soundcloud_tags", $tags);
  288. }
  289. public static function GetSoundCloudTags()
  290. {
  291. return self::getValue("soundcloud_tags");
  292. }
  293. public static function SetSoundCloudGenre($genre)
  294. {
  295. self::setValue("soundcloud_genre", $genre);
  296. }
  297. public static function GetSoundCloudGenre()
  298. {
  299. return self::getValue("soundcloud_genre");
  300. }
  301. public static function SetSoundCloudTrackType($track_type)
  302. {
  303. self::setValue("soundcloud_tracktype", $track_type);
  304. }
  305. public static function GetSoundCloudTrackType()
  306. {
  307. return self::getValue("soundcloud_tracktype");
  308. }
  309. public static function SetSoundCloudLicense($license)
  310. {
  311. self::setValue("soundcloud_license", $license);
  312. }
  313. public static function GetSoundCloudLicense()
  314. {
  315. return self::getValue("soundcloud_license");
  316. }
  317. public static function SetAllow3rdPartyApi($bool)
  318. {
  319. self::setValue("third_party_api", $bool);
  320. }
  321. public static function GetAllow3rdPartyApi()
  322. {
  323. $val = self::getValue("third_party_api");
  324. return (strlen($val) == 0 ) ? "0" : $val;
  325. }
  326. public static function SetPhone($phone)
  327. {
  328. self::setValue("phone", $phone);
  329. }
  330. public static function GetPhone()
  331. {
  332. return self::getValue("phone");
  333. }
  334. public static function SetEmail($email)
  335. {
  336. self::setValue("email", $email);
  337. }
  338. public static function GetEmail()
  339. {
  340. return self::getValue("email");
  341. }
  342. public static function SetStationWebSite($site)
  343. {
  344. self::setValue("station_website", $site);
  345. }
  346. public static function GetStationWebSite()
  347. {
  348. return self::getValue("station_website");
  349. }
  350. public static function SetSupportFeedback($feedback)
  351. {
  352. self::setValue("support_feedback", $feedback);
  353. }
  354. public static function GetSupportFeedback()
  355. {
  356. return self::getValue("support_feedback");
  357. }
  358. public static function SetPublicise($publicise)
  359. {
  360. self::setValue("publicise", $publicise);
  361. }
  362. public static function GetPublicise()
  363. {
  364. return self::getValue("publicise");
  365. }
  366. public static function SetRegistered($registered)
  367. {
  368. self::setValue("registered", $registered);
  369. }
  370. public static function GetRegistered()
  371. {
  372. return self::getValue("registered");
  373. }
  374. public static function SetStationCountry($country)
  375. {
  376. self::setValue("country", $country);
  377. }
  378. public static function GetStationCountry()
  379. {
  380. return self::getValue("country");
  381. }
  382. public static function SetStationCity($city)
  383. {
  384. self::setValue("city", $city);
  385. }
  386. public static function GetStationCity()
  387. {
  388. return self::getValue("city");
  389. }
  390. public static function SetStationDescription($description)
  391. {
  392. self::setValue("description", $description);
  393. }
  394. public static function GetStationDescription()
  395. {
  396. return self::getValue("description");
  397. }
  398. // Sets station default timezone (from preferences)
  399. public static function SetDefaultTimezone($timezone)
  400. {
  401. self::setValue("timezone", $timezone);
  402. }
  403. // Returns station default timezone (from preferences)
  404. public static function GetDefaultTimezone()
  405. {
  406. $stationTimezone = self::getValue("timezone");
  407. if (is_null($stationTimezone) || $stationTimezone == "") {
  408. $stationTimezone = "UTC";
  409. }
  410. return $stationTimezone;
  411. }
  412. public static function SetUserTimezone($timezone = null)
  413. {
  414. // When a new user is created they will get the default timezone
  415. // setting which the admin sets on preferences page
  416. if (is_null($timezone))
  417. $timezone = self::GetDefaultTimezone();
  418. self::setValue("user_timezone", $timezone, true);
  419. }
  420. public static function GetUserTimezone()
  421. {
  422. $timezone = self::getValue("user_timezone", true);
  423. if (!$timezone) {
  424. return self::GetDefaultTimezone();
  425. } else {
  426. return $timezone;
  427. }
  428. }
  429. // Always attempts to returns the current user's personal timezone setting
  430. public static function GetTimezone()
  431. {
  432. $userId = self::getUserId();
  433. if (!is_null($userId)) {
  434. return self::GetUserTimezone();
  435. } else {
  436. return self::GetDefaultTimezone();
  437. }
  438. }
  439. // This is the language setting on preferences page
  440. public static function SetDefaultLocale($locale)
  441. {
  442. self::setValue("locale", $locale);
  443. }
  444. public static function GetDefaultLocale()
  445. {
  446. return self::getValue("locale");
  447. }
  448. public static function GetUserLocale()
  449. {
  450. $locale = self::getValue("user_locale", true);
  451. if (!$locale) {
  452. return self::GetDefaultLocale();
  453. }
  454. else {
  455. return $locale;
  456. }
  457. }
  458. public static function SetUserLocale($locale = null)
  459. {
  460. // When a new user is created they will get the default locale
  461. // setting which the admin sets on preferences page
  462. if (is_null($locale))
  463. $locale = self::GetDefaultLocale();
  464. self::setValue("user_locale", $locale, true);
  465. }
  466. public static function GetLocale()
  467. {
  468. $userId = self::getUserId();
  469. if (!is_null($userId)) {
  470. return self::GetUserLocale();
  471. } else {
  472. return self::GetDefaultLocale();
  473. }
  474. }
  475. public static function SetStationLogo($imagePath)
  476. {
  477. if (empty($imagePath)) {
  478. Logging::info("Removed station logo");
  479. }
  480. $image = @file_get_contents($imagePath);
  481. $image = base64_encode($image);
  482. self::setValue("logoImage", $image);
  483. }
  484. public static function GetStationLogo()
  485. {
  486. return self::getValue("logoImage");
  487. }
  488. public static function SetUniqueId($id)
  489. {
  490. self::setValue("uniqueId", $id);
  491. }
  492. public static function GetUniqueId()
  493. {
  494. return self::getValue("uniqueId");
  495. }
  496. public static function GetCountryList()
  497. {
  498. $sql = "SELECT * FROM cc_country";
  499. $res = Application_Common_Database::prepareAndExecute($sql, array());
  500. $out = array();
  501. $out[""] = _("Select Country");
  502. foreach ($res as $r) {
  503. $out[$r["isocode"]] = $r["name"];
  504. }
  505. return $out;
  506. }
  507. public static function GetSystemInfo($returnArray=false, $p_testing=false)
  508. {
  509. exec('/usr/bin/airtime-check-system --no-color', $output);
  510. $output = preg_replace('/\s+/', ' ', $output);
  511. $systemInfoArray = array();
  512. foreach ($output as $key => &$out) {
  513. $info = explode('=', $out);
  514. if (isset($info[1])) {
  515. $key = str_replace(' ', '_', trim($info[0]));
  516. $key = strtoupper($key);
  517. if ($key == 'WEB_SERVER' || $key == 'CPU' || $key == 'OS' || $key == 'TOTAL_RAM' ||
  518. $key == 'FREE_RAM' || $key == 'AIRTIME_VERSION' || $key == 'KERNAL_VERSION' ||
  519. $key == 'MACHINE_ARCHITECTURE' || $key == 'TOTAL_MEMORY_MBYTES' || $key == 'TOTAL_SWAP_MBYTES' ||
  520. $key == 'PLAYOUT_ENGINE_CPU_PERC') {
  521. if ($key == 'AIRTIME_VERSION') {
  522. // remove hash tag on the version string
  523. $version = explode('+', $info[1]);
  524. $systemInfoArray[$key] = $version[0];
  525. } else {
  526. $systemInfoArray[$key] = $info[1];
  527. }
  528. }
  529. }
  530. }
  531. $outputArray = array();
  532. $outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration($p_testing);
  533. $outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration($p_testing);
  534. $outputArray['SOUNDCLOUD_ENABLED'] = self::GetUploadToSoundcloudOption();
  535. if ($outputArray['SOUNDCLOUD_ENABLED']) {
  536. $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = Application_Model_StoredFile::getSoundCloudUploads();
  537. } else {
  538. $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = NULL;
  539. }
  540. $outputArray['STATION_NAME'] = self::GetStationName();
  541. $outputArray['PHONE'] = self::GetPhone();
  542. $outputArray['EMAIL'] = self::GetEmail();
  543. $outputArray['STATION_WEB_SITE'] = self::GetStationWebSite();
  544. $outputArray['STATION_COUNTRY'] = self::GetStationCountry();
  545. $outputArray['STATION_CITY'] = self::GetStationCity();
  546. $outputArray['STATION_DESCRIPTION'] = self::GetStationDescription();
  547. // get web server info
  548. if (isset($systemInfoArray["AIRTIME_VERSION_URL"])) {
  549. $url = $systemInfoArray["AIRTIME_VERSION_URL"];
  550. $index = strpos($url,'/api/');
  551. $url = substr($url, 0, $index);
  552. $headerInfo = get_headers(trim($url),1);
  553. $outputArray['WEB_SERVER'] = $headerInfo['Server'][0];
  554. }
  555. $outputArray['NUM_OF_USERS'] = Application_Model_User::getUserCount();
  556. $outputArray['NUM_OF_SONGS'] = Application_Model_StoredFile::getFileCount();
  557. $outputArray['NUM_OF_PLAYLISTS'] = Application_Model_Playlist::getPlaylistCount();
  558. $outputArray['NUM_OF_SCHEDULED_PLAYLISTS'] = Application_Model_Schedule::getSchduledPlaylistCount();
  559. $outputArray['NUM_OF_PAST_SHOWS'] = Application_Model_ShowInstance::GetShowInstanceCount(gmdate("Y-m-d H:i:s"));
  560. $outputArray['UNIQUE_ID'] = self::GetUniqueId();
  561. $outputArray['SAAS'] = self::GetPlanLevel();
  562. if ($outputArray['SAAS'] != 'disabled') {
  563. $outputArray['TRIAL_END_DATE'] = self::GetTrialEndingDate();
  564. } else {
  565. $outputArray['TRIAL_END_DATE'] = NULL;
  566. }
  567. $outputArray['INSTALL_METHOD'] = self::GetInstallMethod();
  568. $outputArray['NUM_OF_STREAMS'] = self::GetNumOfStreams();
  569. $outputArray['STREAM_INFO'] = Application_Model_StreamSetting::getStreamInfoForDataCollection();
  570. $outputArray = array_merge($systemInfoArray, $outputArray);
  571. $outputString = "\n";
  572. foreach ($outputArray as $key => $out) {
  573. if ($key == 'TRIAL_END_DATE' && ($out != '' || $out != 'NULL')) {
  574. continue;
  575. }
  576. if ($key == "STREAM_INFO") {
  577. $outputString .= $key." :\n";
  578. foreach ($out as $s_info) {
  579. foreach ($s_info as $k => $v) {
  580. $outputString .= "\t".strtoupper($k)." : ".$v."\n";
  581. }
  582. }
  583. } elseif ($key == "SOUNDCLOUD_ENABLED") {
  584. if ($out) {
  585. $outputString .= $key." : TRUE\n";
  586. } elseif (!$out) {
  587. $outputString .= $key." : FALSE\n";
  588. }
  589. } elseif ($key == "SAAS") {
  590. if (strcmp($out, 'disabled')!=0) {
  591. $outputString .= $key.' : '.$out."\n";
  592. }
  593. } else {
  594. $outputString .= $key.' : '.$out."\n";
  595. }
  596. }
  597. if ($returnArray) {
  598. $outputArray['PROMOTE'] = self::GetPublicise();
  599. $outputArray['LOGOIMG'] = self::GetStationLogo();
  600. return $outputArray;
  601. } else {
  602. return $outputString;
  603. }
  604. }
  605. public static function GetInstallMethod()
  606. {
  607. $easy_install = file_exists('/usr/bin/airtime-easy-setup');
  608. $debian_install = file_exists('/var/lib/dpkg/info/airtime.config');
  609. if ($debian_install) {
  610. if ($easy_install) {
  611. return "easy_install";
  612. } else {
  613. return "debian_install";
  614. }
  615. } else {
  616. return "manual_install";
  617. }
  618. }
  619. public static function SetRemindMeDate($p_never = false)
  620. {
  621. if ($p_never) {
  622. self::setValue("remindme", -1);
  623. } else {
  624. $weekAfter = mktime(0, 0, 0, gmdate("m"), gmdate("d")+7, gmdate("Y"));
  625. self::setValue("remindme", $weekAfter);
  626. }
  627. }
  628. public static function GetRemindMeDate()
  629. {
  630. return self::getValue("remindme");
  631. }
  632. public static function SetImportTimestamp()
  633. {
  634. $now = time();
  635. if (self::GetImportTimestamp()+5 < $now) {
  636. self::setValue("import_timestamp", $now);
  637. }
  638. }
  639. public static function GetImportTimestamp()
  640. {
  641. return self::getValue("import_timestamp");
  642. }
  643. public static function GetStreamType()
  644. {
  645. $st = self::getValue("stream_type");
  646. return explode(',', $st);
  647. }
  648. public static function GetStreamBitrate()
  649. {
  650. $sb = self::getValue("stream_bitrate");
  651. return explode(',', $sb);
  652. }
  653. public static function SetPrivacyPolicyCheck($flag)
  654. {
  655. self::setValue("privacy_policy", $flag);
  656. }
  657. public static function GetPrivacyPolicyCheck()
  658. {
  659. return self::getValue("privacy_policy");
  660. }
  661. public static function SetNumOfStreams($num)
  662. {
  663. self::setValue("num_of_streams", intval($num));
  664. }
  665. public static function GetNumOfStreams()
  666. {
  667. return self::getValue("num_of_streams");
  668. }
  669. public static function SetMaxBitrate($bitrate)
  670. {
  671. self::setValue("max_bitrate", intval($bitrate));
  672. }
  673. public static function GetMaxBitrate()
  674. {
  675. return self::getValue("max_bitrate");
  676. }
  677. public static function SetPlanLevel($plan)
  678. {
  679. self::setValue("plan_level", $plan);
  680. }
  681. public static function GetPlanLevel()
  682. {
  683. $plan = self::getValue("plan_level");
  684. if (trim($plan) == '') {
  685. $plan = 'disabled';
  686. }
  687. return $plan;
  688. }
  689. public static function SetTrialEndingDate($date)
  690. {
  691. self::setValue("trial_end_date", $date);
  692. }
  693. public static function GetTrialEndingDate()
  694. {
  695. return self::getValue("trial_end_date");
  696. }
  697. public static function SetEnableStreamConf($bool)
  698. {
  699. self::setValue("enable_stream_conf", $bool);
  700. }
  701. public static function GetEnableStreamConf()
  702. {
  703. if (self::getValue("enable_stream_conf") == Null) {
  704. return "true";
  705. }
  706. return self::getValue("enable_stream_conf");
  707. }
  708. public static function GetSchemaVersion()
  709. {
  710. $schemaVersion = self::getValue("schema_version");
  711. //Pre-2.5.2 releases all used this ambiguous "system_version" key to represent both the code and schema versions...
  712. if (empty($schemaVersion)) {
  713. $schemaVersion = self::getValue("system_version");
  714. }
  715. return $schemaVersion;
  716. }
  717. public static function SetSchemaVersion($version)
  718. {
  719. self::setValue("schema_version", $version);
  720. }
  721. public static function GetAirtimeVersion()
  722. {
  723. if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development" && function_exists('exec')) {
  724. $version = exec("git rev-parse --short HEAD 2>/dev/null", $out, $return_code);
  725. if ($return_code == 0) {
  726. return self::getValue("system_version")."+".$version.":".time();
  727. }
  728. }
  729. return self::getValue("system_version");
  730. }
  731. public static function GetLatestVersion()
  732. {
  733. $latest = self::getValue("latest_version");
  734. if ($latest == null || strlen($latest) == 0) {
  735. return self::GetAirtimeVersion();
  736. } else {
  737. return $latest;
  738. }
  739. }
  740. public static function SetLatestVersion($version)
  741. {
  742. $pattern = "/^[0-9]+\.[0-9]+\.[0-9]+/";
  743. if (preg_match($pattern, $version)) {
  744. self::setValue("latest_version", $version);
  745. }
  746. }
  747. public static function GetLatestLink()
  748. {
  749. $link = self::getValue("latest_link");
  750. if ($link == null || strlen($link) == 0) {
  751. return 'http://airtime.sourcefabric.org';
  752. } else {
  753. return $link;
  754. }
  755. }
  756. public static function SetLatestLink($link)
  757. {
  758. $pattern = "#^(http|https|ftp)://" .
  759. "([a-zA-Z0-9]+\.)*[a-zA-Z0-9]+" .
  760. "(/[a-zA-Z0-9\-\.\_\~\:\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=]+)*/?$#";
  761. if (preg_match($pattern, $link)) {
  762. self::setValue("latest_link", $link);
  763. }
  764. }
  765. public static function SetUploadToSoundcloudOption($upload)
  766. {
  767. self::setValue("soundcloud_upload_option", $upload);
  768. }
  769. public static function GetUploadToSoundcloudOption()
  770. {
  771. return self::getValue("soundcloud_upload_option");
  772. }
  773. public static function SetSoundCloudDownloadbleOption($upload)
  774. {
  775. self::setValue("soundcloud_downloadable", $upload);
  776. }
  777. public static function GetSoundCloudDownloadbleOption()
  778. {
  779. return self::getValue("soundcloud_downloadable");
  780. }
  781. public static function SetWeekStartDay($day)
  782. {
  783. self::setValue("week_start_day", $day);
  784. }
  785. public static function GetWeekStartDay()
  786. {
  787. $val = self::getValue("week_start_day");
  788. return (strlen($val) == 0) ? "0" : $val;
  789. }
  790. /**
  791. * Stores the last timestamp of user updating stream setting
  792. */
  793. public static function SetStreamUpdateTimestamp()
  794. {
  795. $now = time();
  796. self::setValue("stream_update_timestamp", $now);
  797. }
  798. /**
  799. * Gets the last timestamp of user updating stream setting
  800. */
  801. public static function GetStreamUpdateTimestemp()
  802. {
  803. $update_time = self::getValue("stream_update_timestamp");
  804. return ($update_time == null) ? 0 : $update_time;
  805. }
  806. public static function GetClientId()
  807. {
  808. return self::getValue("client_id");
  809. }
  810. public static function SetClientId($id)
  811. {
  812. if (is_numeric($id)) {
  813. self::setValue("client_id", $id);
  814. } else {
  815. Logging::warn("Attempting to set client_id to invalid value: $id");
  816. }
  817. }
  818. /* User specific preferences start */
  819. /**
  820. * Sets the time scale preference (agendaDay/agendaWeek/month) in Calendar.
  821. *
  822. * @param $timeScale new time scale
  823. */
  824. public static function SetCalendarTimeScale($timeScale)
  825. {
  826. self::setValue("calendar_time_scale", $timeScale, true /* user specific */);
  827. }
  828. /**
  829. * Retrieves the time scale preference for the current user.
  830. * Defaults to month if no entry exists
  831. */
  832. public static function GetCalendarTimeScale()
  833. {
  834. $val = self::getValue("calendar_time_scale", true /* user specific */);
  835. if (strlen($val) == 0) {
  836. $val = "month";
  837. }
  838. return $val;
  839. }
  840. /**
  841. * Sets the number of entries to show preference in library under Playlist Builder.
  842. *
  843. * @param $numEntries new number of entries to show
  844. */
  845. public static function SetLibraryNumEntries($numEntries)
  846. {
  847. self::setValue("library_num_entries", $numEntries, true /* user specific */);
  848. }
  849. /**
  850. * Retrieves the number of entries to show preference in library under Playlist Builder.
  851. * Defaults to 10 if no entry exists
  852. */
  853. public static function GetLibraryNumEntries()
  854. {
  855. $val = self::getValue("library_num_entries", true /* user specific */);
  856. if (strlen($val) == 0) {
  857. $val = "10";
  858. }
  859. return $val;
  860. }
  861. /**
  862. * Sets the time interval preference in Calendar.
  863. *
  864. * @param $timeInterval new time interval
  865. */
  866. public static function SetCalendarTimeInterval($timeInterval)
  867. {
  868. self::setValue("calendar_time_interval", $timeInterval, true /* user specific */);
  869. }
  870. /**
  871. * Retrieves the time interval preference for the current user.
  872. * Defaults to 30 min if no entry exists
  873. */
  874. public static function GetCalendarTimeInterval()
  875. {
  876. $val = self::getValue("calendar_time_interval", true /* user specific */);
  877. return (strlen($val) == 0) ? "30" : $val;
  878. }
  879. public static function SetDiskQuota($value)
  880. {
  881. self::setValue("disk_quota", $value, false);
  882. }
  883. public static function GetDiskQuota()
  884. {
  885. $val = self::getValue("disk_quota");
  886. return (strlen($val) == 0) ? 0 : $val;
  887. }
  888. public static function SetLiveStreamMasterUsername($value)
  889. {
  890. self::setValue("live_stream_master_username", $value, false);
  891. }
  892. public static function GetLiveStreamMasterUsername()
  893. {
  894. return self::getValue("live_stream_master_username");
  895. }
  896. public static function SetLiveStreamMasterPassword($value)
  897. {
  898. self::setValue("live_stream_master_password", $value, false);
  899. }
  900. public static function GetLiveStreamMasterPassword()
  901. {
  902. return self::getValue("live_stream_master_password");
  903. }
  904. public static function SetSourceStatus($sourcename, $status)
  905. {
  906. self::setValue($sourcename, $status, false);
  907. }
  908. public static function GetSourceStatus($sourcename)
  909. {
  910. $value = self::getValue($sourcename);
  911. return !($value == null || $value == "false");
  912. }
  913. public static function SetSourceSwitchStatus($sourcename, $status)
  914. {
  915. self::setValue($sourcename."_switch", $status, false);
  916. }
  917. public static function GetSourceSwitchStatus($sourcename)
  918. {
  919. $value = self::getValue($sourcename."_switch");
  920. return ($value == null || $value == "off") ? 'off' : 'on';
  921. }
  922. public static function SetMasterDJSourceConnectionURL($value)
  923. {
  924. self::setValue("master_dj_source_connection_url", $value, false);
  925. }
  926. public static function GetMasterDJSourceConnectionURL()
  927. {
  928. return self::getValue("master_dj_source_connection_url");
  929. }
  930. public static function SetLiveDJSourceConnectionURL($value)
  931. {
  932. self::setValue("live_dj_source_connection_url", $value, false);
  933. }
  934. public static function GetLiveDJSourceConnectionURL()
  935. {
  936. return self::getValue("live_dj_source_connection_url");
  937. }
  938. /* Source Connection URL override status starts */
  939. public static function GetLiveDjConnectionUrlOverride()
  940. {
  941. return self::getValue("live_dj_connection_url_override");
  942. }
  943. public static function SetLiveDjConnectionUrlOverride($value)
  944. {
  945. self::setValue("live_dj_connection_url_override", $value, false);
  946. }
  947. public static function GetMasterDjConnectionUrlOverride()
  948. {
  949. return self::getValue("master_dj_connection_url_override");
  950. }
  951. public static function SetMasterDjConnectionUrlOverride($value)
  952. {
  953. self::setValue("master_dj_connection_url_override", $value, false);
  954. }
  955. /* Source Connection URL override status ends */
  956. public static function SetAutoTransition($value)
  957. {
  958. self::setValue("auto_transition", $value, false);
  959. }
  960. public static function GetAutoTransition()
  961. {
  962. return self::getValue("auto_transition");
  963. }
  964. public static function SetAutoSwitch($value)
  965. {
  966. self::setValue("auto_switch", $value, false);
  967. }
  968. public static function GetAutoSwitch()
  969. {
  970. return self::getValue("auto_switch");
  971. }
  972. public static function SetEnableSystemEmail($upload)
  973. {
  974. self::setValue("enable_system_email", $upload);
  975. }
  976. public static function GetEnableSystemEmail()
  977. {
  978. $v = self::getValue("enable_system_email");
  979. return ($v === "") ? 0 : $v;
  980. }
  981. public static function SetSystemEmail($value)
  982. {
  983. self::setValue("system_email", $value, false);
  984. }
  985. public static function GetSystemEmail()
  986. {
  987. return self::getValue("system_email");
  988. }
  989. public static function SetMailServerConfigured($value)
  990. {
  991. self::setValue("mail_server_configured", $value, false);
  992. }
  993. public static function GetMailServerConfigured()
  994. {
  995. return self::getValue("mail_server_configured");
  996. }
  997. public static function SetMailServer($value)
  998. {
  999. self::setValue("mail_server", $value, false);
  1000. }
  1001. public static function GetMailServer()
  1002. {
  1003. return self::getValue("mail_server");
  1004. }
  1005. public static function SetMailServerEmailAddress($value)
  1006. {
  1007. self::setValue("mail_server_email_address", $value, false);
  1008. }
  1009. public static function GetMailServerEmailAddress()
  1010. {
  1011. return self::getValue("mail_server_email_address");
  1012. }
  1013. public static function SetMailServerPassword($value)
  1014. {
  1015. self::setValue("mail_server_password", $value, false);
  1016. }
  1017. public static function GetMailServerPassword()
  1018. {
  1019. return self::getValue("mail_server_password");
  1020. }
  1021. public static function SetMailServerPort($value)
  1022. {
  1023. self::setValue("mail_server_port", $value, false);
  1024. }
  1025. public static function GetMailServerPort()
  1026. {
  1027. return self::getValue("mail_server_port");
  1028. }
  1029. public static function SetMailServerRequiresAuth($value)
  1030. {
  1031. self::setValue("mail_server_requires_auth", $value, false);
  1032. }
  1033. public static function GetMailServerRequiresAuth()
  1034. {
  1035. return self::getValue("mail_server_requires_auth");
  1036. }
  1037. /* User specific preferences end */
  1038. public static function ShouldShowPopUp()
  1039. {
  1040. $today = mktime(0, 0, 0, gmdate("m"), gmdate("d"), gmdate("Y"));
  1041. $remindDate = Application_Model_Preference::GetRemindMeDate();
  1042. $retVal = false;
  1043. if (is_null($remindDate) || ($remindDate != -1 && $today >= $remindDate)) {
  1044. $retVal = true;
  1045. }
  1046. return $retVal;
  1047. }
  1048. public static function getOrderingMap($pref_param)
  1049. {
  1050. $v = self::getValue($pref_param, true);
  1051. $id = function ($x) { return $x; };
  1052. if ($v === '') {
  1053. return $id;
  1054. }
  1055. $ds = unserialize($v);
  1056. if (is_null($ds) || !is_array($ds)) {
  1057. return $id;
  1058. }
  1059. if (!array_key_exists('ColReorder', $ds)) {
  1060. return $id;
  1061. }
  1062. return function ($x) use ($ds) {
  1063. if (array_key_exists($x, $ds['ColReorder'])) {
  1064. return $ds['ColReorder'][$x];
  1065. } else {
  1066. /*For now we just have this hack for debugging. We should not
  1067. rely on this behaviour in case of failure*/
  1068. Logging::warn("Index $x does not exist preferences");
  1069. Logging::warn("Defaulting to identity and printing preferences");
  1070. Logging::warn($ds);
  1071. return $x;
  1072. }
  1073. };
  1074. }
  1075. public static function getCurrentLibraryTableColumnMap()
  1076. {
  1077. return self::getOrderingMap("library_datatable");
  1078. }
  1079. public static function setCurrentLibraryTableSetting($settings)
  1080. {
  1081. $data = serialize($settings);
  1082. self::setValue("library_datatable", $data, true);
  1083. }
  1084. public static function getCurrentLibraryTableSetting()
  1085. {
  1086. $data = self::getValue("library_datatable", true);
  1087. return ($data != "") ? unserialize($data) : null;
  1088. }
  1089. public static function setTimelineDatatableSetting($settings)
  1090. {
  1091. $data = serialize($settings);
  1092. self::setValue("timeline_datatable", $data, true);
  1093. }
  1094. public static function getTimelineDatatableSetting()
  1095. {
  1096. $data = self::getValue("timeline_datatable", true);
  1097. return ($data != "") ? unserialize($data) : null;
  1098. }
  1099. public static function setNowPlayingScreenSettings($settings)
  1100. {
  1101. $data = serialize($settings);
  1102. self::setValue("nowplaying_screen", $data, true);
  1103. }
  1104. public static function getNowPlayingScreenSettings()
  1105. {
  1106. $data = self::getValue("nowplaying_screen", true);
  1107. return ($data != "") ? unserialize($data) : null;
  1108. }
  1109. public static function setLibraryScreenSettings($settings)
  1110. {
  1111. $data = serialize($settings);
  1112. self::setValue("library_screen", $data, true);
  1113. }
  1114. public static function getLibraryScreenSettings()
  1115. {
  1116. $data = self::getValue("library_screen", true);
  1117. return ($data != "") ? unserialize($data) : null;
  1118. }
  1119. public static function SetEnableReplayGain($value) {
  1120. self::setValue("enable_replay_gain", $value, false);
  1121. }
  1122. public static function GetEnableReplayGain() {
  1123. return self::getValue("enable_replay_gain", false);
  1124. }
  1125. public static function getReplayGainModifier() {
  1126. $rg_modifier = self::getValue("replay_gain_modifier");
  1127. if ($rg_modifier === "")
  1128. return "0";
  1129. return $rg_modifier;
  1130. }
  1131. public static function setReplayGainModifier($rg_modifier)
  1132. {
  1133. self::setValue("replay_gain_modifier", $rg_modifier, true);
  1134. }
  1135. public static function SetHistoryItemTemplate($value) {
  1136. self::setValue("history_item_template", $value);
  1137. }
  1138. public static function GetHistoryItemTemplate() {
  1139. return self::getValue("history_item_template");
  1140. }
  1141. public static function SetHistoryFileTemplate($value) {
  1142. self::setValue("history_file_template", $value);
  1143. }
  1144. public static function GetHistoryFileTemplate() {
  1145. return self::getValue("history_file_template");
  1146. }
  1147. }