12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403 |
- <?php
- require_once 'Cache.php';
- class Application_Model_Preference
- {
-
- private static function getUserId()
- {
- //pass in true so the check is made with the autoloader
- //we need this check because saas calls this function from outside Zend
- if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
- $userId = null;
- } else {
- $auth = Zend_Auth::getInstance();
- $userId = $auth->getIdentity()->id;
- }
-
- return $userId;
- }
-
- /**
- *
- * @param boolean $isUserValue is true when we are setting a value for the current user
- */
- private static function setValue($key, $value, $isUserValue = false)
- {
- $cache = new Cache();
-
- try {
-
- $con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
- $con->beginTransaction();
- $userId = self::getUserId();
-
- if ($isUserValue && is_null($userId))
- throw new Exception("User id can't be null for a user preference {$key}.");
-
- //Check if key already exists
- $sql = "SELECT COUNT(*) FROM cc_pref"
- ." WHERE keystr = :key";
-
- $paramMap = array();
- $paramMap[':key'] = $key;
-
- //For user specific preference, check if id matches as well
- if ($isUserValue) {
- $sql .= " AND subjid = :id";
- $paramMap[':id'] = $userId;
- }
- $result = Application_Common_Database::prepareAndExecute($sql,
- $paramMap,
- Application_Common_Database::COLUMN,
- PDO::FETCH_ASSOC,
- $con);
- $paramMap = array();
- if ($result > 1) {
- //this case should not happen.
- throw new Exception("Invalid number of results returned. Should be ".
- "0 or 1, but is '$result' instead");
- } else if ($result == 1) {
-
- // result found
- if (!$isUserValue) {
- // system pref
- $sql = "UPDATE cc_pref"
- ." SET subjid = NULL, valstr = :value"
- ." WHERE keystr = :key";
- } else {
- // user pref
- $sql = "UPDATE cc_pref"
- . " SET valstr = :value"
- . " WHERE keystr = :key AND subjid = :id";
-
- $paramMap[':id'] = $userId;
- }
- } else {
-
- // result not found
- if (!$isUserValue) {
- // system pref
- $sql = "INSERT INTO cc_pref (keystr, valstr)"
- ." VALUES (:key, :value)";
- } else {
- // user pref
- $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
- ." VALUES (:id, :key, :value)";
-
- $paramMap[':id'] = $userId;
- }
- }
- $paramMap[':key'] = $key;
- $paramMap[':value'] = $value;
- Application_Common_Database::prepareAndExecute($sql,
- $paramMap,
- 'execute',
- PDO::FETCH_ASSOC,
- $con);
- $con->commit();
- } catch (Exception $e) {
- $con->rollback();
- header('HTTP/1.0 503 Service Unavailable');
- Logging::info("Database error: ".$e->getMessage());
- exit;
- }
- $cache->store($key, $value, $isUserValue, $userId);
- }
- private static function getValue($key, $isUserValue = false)
- {
- $cache = new Cache();
-
- try {
-
- $userId = self::getUserId();
-
- if ($isUserValue && is_null($userId))
- throw new Exception("User id can't be null for a user preference.");
- // If the value is already cached, return it
- $res = $cache->fetch($key, $isUserValue, $userId);
- if ($res !== false) return $res;
-
- //Check if key already exists
- $sql = "SELECT COUNT(*) FROM cc_pref"
- ." WHERE keystr = :key";
-
- $paramMap = array();
- $paramMap[':key'] = $key;
-
- //For user specific preference, check if id matches as well
- if ($isUserValue) {
- $sql .= " AND subjid = :id";
- $paramMap[':id'] = $userId;
- }
-
- $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
-
- //return an empty string if the result doesn't exist.
- if ($result == 0) {
- $res = "";
- } else {
- $sql = "SELECT valstr FROM cc_pref"
- ." WHERE keystr = :key";
-
- $paramMap = array();
- $paramMap[':key'] = $key;
- //For user specific preference, check if id matches as well
- if ($isUserValue) {
- $sql .= " AND subjid = :id";
- $paramMap[':id'] = $userId;
- }
-
- $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
- $res = ($result !== false) ? $result : "";
- }
-
- $cache->store($key, $res, $isUserValue, $userId);
- return $res;
- }
- catch (Exception $e) {
- header('HTTP/1.0 503 Service Unavailable');
- Logging::info("Could not connect to database: ".$e->getMessage());
- exit;
- }
- }
- public static function GetHeadTitle()
- {
- $title = self::getValue("station_name");
- if (strlen($title) > 0)
- $title .= " - ";
- return $title."Airtime";
- }
- public static function SetHeadTitle($title, $view=null)
- {
- self::setValue("station_name", $title);
- // in case this is called from airtime-saas script
- if ($view !== null) {
- //set session variable to new station name so that html title is updated.
- //should probably do this in a view helper to keep this controller as minimal as possible.
- $view->headTitle()->exchangeArray(array()); //clear headTitle ArrayObject
- $view->headTitle(self::GetHeadTitle());
- }
- $eventType = "update_station_name";
- $md = array("station_name"=>$title);
- Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
- }
- /**
- * Set the furthest date that a never-ending show
- * should be populated until.
- *
- * @param DateTime $dateTime
- * A row from cc_show_days table
- */
- public static function SetShowsPopulatedUntil($dateTime)
- {
- $dateTime->setTimezone(new DateTimeZone("UTC"));
- self::setValue("shows_populated_until", $dateTime->format("Y-m-d H:i:s"));
- }
- /**
- * Get the furthest date that a never-ending show
- * should be populated until.
- *
- * Returns null if the value hasn't been set, otherwise returns
- * a DateTime object representing the date.
- *
- * @return DateTime (in UTC Timezone)
- */
- public static function GetShowsPopulatedUntil()
- {
- $date = self::getValue("shows_populated_until");
- if ($date == "") {
- return null;
- } else {
- return new DateTime($date, new DateTimeZone("UTC"));
- }
- }
-
- public static function SetDefaultCrossfadeDuration($duration)
- {
- self::setValue("default_crossfade_duration", $duration);
- }
-
- public static function GetDefaultCrossfadeDuration()
- {
- $duration = self::getValue("default_crossfade_duration");
-
- if ($duration === "") {
- // the default value of the fade is 00.5
- return "0";
- }
-
- return $duration;
- }
-
- public static function SetDefaultFadeIn($fade)
- {
- self::setValue("default_fade_in", $fade);
- }
-
- public static function GetDefaultFadeIn()
- {
- $fade = self::getValue("default_fade_in");
-
- if ($fade === "") {
- // the default value of the fade is 00.5
- return "0.5";
- }
-
- return $fade;
- }
-
- public static function SetDefaultFadeOut($fade)
- {
- self::setValue("default_fade_out", $fade);
- }
-
- public static function GetDefaultFadeOut()
- {
- $fade = self::getValue("default_fade_out");
-
- if ($fade === "") {
- // the default value of the fade is 0.5
- return "0.5";
- }
-
- return $fade;
- }
- public static function SetDefaultFade($fade)
- {
- self::setValue("default_fade", $fade);
- }
- public static function SetDefaultTransitionFade($fade)
- {
- self::setValue("default_transition_fade", $fade);
- $eventType = "update_transition_fade";
- $md = array("transition_fade"=>$fade);
- Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
- }
- public static function GetDefaultTransitionFade()
- {
- $transition_fade = self::getValue("default_transition_fade");
- return ($transition_fade == "") ? "0.000" : $transition_fade;
- }
- public static function SetStreamLabelFormat($type)
- {
- self::setValue("stream_label_format", $type);
- $eventType = "update_stream_format";
- $md = array("stream_format"=>$type);
- Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
- }
- public static function GetStreamLabelFormat()
- {
- return self::getValue("stream_label_format");
- }
- public static function GetStationName()
- {
- return self::getValue("station_name");
- }
- public static function SetAutoUploadRecordedShowToSoundcloud($upload)
- {
- self::setValue("soundcloud_auto_upload_recorded_show", $upload);
- }
- public static function GetAutoUploadRecordedShowToSoundcloud()
- {
- return self::getValue("soundcloud_auto_upload_recorded_show");
- }
- public static function SetSoundCloudUser($user)
- {
- self::setValue("soundcloud_user", $user);
- }
- public static function GetSoundCloudUser()
- {
- return self::getValue("soundcloud_user");
- }
- public static function SetSoundCloudPassword($password)
- {
- if (strlen($password) > 0)
- self::setValue("soundcloud_password", $password);
- }
- public static function GetSoundCloudPassword()
- {
- return self::getValue("soundcloud_password");
- }
- public static function SetSoundCloudTags($tags)
- {
- self::setValue("soundcloud_tags", $tags);
- }
- public static function GetSoundCloudTags()
- {
- return self::getValue("soundcloud_tags");
- }
- public static function SetSoundCloudGenre($genre)
- {
- self::setValue("soundcloud_genre", $genre);
- }
- public static function GetSoundCloudGenre()
- {
- return self::getValue("soundcloud_genre");
- }
- public static function SetSoundCloudTrackType($track_type)
- {
- self::setValue("soundcloud_tracktype", $track_type);
- }
- public static function GetSoundCloudTrackType()
- {
- return self::getValue("soundcloud_tracktype");
- }
- public static function SetSoundCloudLicense($license)
- {
- self::setValue("soundcloud_license", $license);
- }
- public static function GetSoundCloudLicense()
- {
- return self::getValue("soundcloud_license");
- }
- public static function SetAllow3rdPartyApi($bool)
- {
- self::setValue("third_party_api", $bool);
- }
- public static function GetAllow3rdPartyApi()
- {
- $val = self::getValue("third_party_api");
- return (strlen($val) == 0 ) ? "0" : $val;
- }
- public static function SetPhone($phone)
- {
- self::setValue("phone", $phone);
- }
- public static function GetPhone()
- {
- return self::getValue("phone");
- }
- public static function SetEmail($email)
- {
- self::setValue("email", $email);
- }
- public static function GetEmail()
- {
- return self::getValue("email");
- }
- public static function SetStationWebSite($site)
- {
- self::setValue("station_website", $site);
- }
- public static function GetStationWebSite()
- {
- return self::getValue("station_website");
- }
- public static function SetSupportFeedback($feedback)
- {
- self::setValue("support_feedback", $feedback);
- }
- public static function GetSupportFeedback()
- {
- return self::getValue("support_feedback");
- }
- public static function SetPublicise($publicise)
- {
- self::setValue("publicise", $publicise);
- }
- public static function GetPublicise()
- {
- return self::getValue("publicise");
- }
- public static function SetRegistered($registered)
- {
- self::setValue("registered", $registered);
- }
- public static function GetRegistered()
- {
- return self::getValue("registered");
- }
- public static function SetStationCountry($country)
- {
- self::setValue("country", $country);
- }
- public static function GetStationCountry()
- {
- return self::getValue("country");
- }
- public static function SetStationCity($city)
- {
- self::setValue("city", $city);
- }
- public static function GetStationCity()
- {
- return self::getValue("city");
- }
- public static function SetStationDescription($description)
- {
- self::setValue("description", $description);
- }
- public static function GetStationDescription()
- {
- return self::getValue("description");
- }
- // Sets station default timezone (from preferences)
- public static function SetDefaultTimezone($timezone)
- {
- self::setValue("timezone", $timezone);
- }
- // Returns station default timezone (from preferences)
- public static function GetDefaultTimezone()
- {
- $stationTimezone = self::getValue("timezone");
- if (is_null($stationTimezone) || $stationTimezone == "") {
- $stationTimezone = "UTC";
- }
- return $stationTimezone;
- }
- public static function SetUserTimezone($timezone = null)
- {
- // When a new user is created they will get the default timezone
- // setting which the admin sets on preferences page
- if (is_null($timezone))
- $timezone = self::GetDefaultTimezone();
- self::setValue("user_timezone", $timezone, true);
- }
- public static function GetUserTimezone()
- {
- $timezone = self::getValue("user_timezone", true);
- if (!$timezone) {
- return self::GetDefaultTimezone();
- } else {
- return $timezone;
- }
- }
- // Always attempts to returns the current user's personal timezone setting
- public static function GetTimezone()
- {
- $userId = self::getUserId();
-
- if (!is_null($userId)) {
- return self::GetUserTimezone();
- } else {
- return self::GetDefaultTimezone();
- }
- }
- // This is the language setting on preferences page
- public static function SetDefaultLocale($locale)
- {
- self::setValue("locale", $locale);
- }
- public static function GetDefaultLocale()
- {
- return self::getValue("locale");
- }
- public static function GetUserLocale()
- {
- $locale = self::getValue("user_locale", true);
- if (!$locale) {
- return self::GetDefaultLocale();
- }
- else {
- return $locale;
- }
- }
- public static function SetUserLocale($locale = null)
- {
- // When a new user is created they will get the default locale
- // setting which the admin sets on preferences page
- if (is_null($locale))
- $locale = self::GetDefaultLocale();
- self::setValue("user_locale", $locale, true);
- }
- public static function GetLocale()
- {
- $userId = self::getUserId();
-
- if (!is_null($userId)) {
- return self::GetUserLocale();
- } else {
- return self::GetDefaultLocale();
- }
- }
- public static function SetStationLogo($imagePath)
- {
- if (empty($imagePath)) {
- Logging::info("Removed station logo");
- }
- $image = @file_get_contents($imagePath);
- $image = base64_encode($image);
- self::setValue("logoImage", $image);
- }
- public static function GetStationLogo()
- {
- return self::getValue("logoImage");
- }
-
- public static function SetUniqueId($id)
- {
- self::setValue("uniqueId", $id);
- }
- public static function GetUniqueId()
- {
- return self::getValue("uniqueId");
- }
- public static function GetCountryList()
- {
- $sql = "SELECT * FROM cc_country";
-
- $res = Application_Common_Database::prepareAndExecute($sql, array());
- $out = array();
- $out[""] = _("Select Country");
- foreach ($res as $r) {
- $out[$r["isocode"]] = $r["name"];
- }
- return $out;
- }
- public static function GetSystemInfo($returnArray=false, $p_testing=false)
- {
- exec('/usr/bin/airtime-check-system --no-color', $output);
- $output = preg_replace('/\s+/', ' ', $output);
- $systemInfoArray = array();
- foreach ($output as $key => &$out) {
- $info = explode('=', $out);
- if (isset($info[1])) {
- $key = str_replace(' ', '_', trim($info[0]));
- $key = strtoupper($key);
- if ($key == 'WEB_SERVER' || $key == 'CPU' || $key == 'OS' || $key == 'TOTAL_RAM' ||
- $key == 'FREE_RAM' || $key == 'AIRTIME_VERSION' || $key == 'KERNAL_VERSION' ||
- $key == 'MACHINE_ARCHITECTURE' || $key == 'TOTAL_MEMORY_MBYTES' || $key == 'TOTAL_SWAP_MBYTES' ||
- $key == 'PLAYOUT_ENGINE_CPU_PERC') {
- if ($key == 'AIRTIME_VERSION') {
- // remove hash tag on the version string
- $version = explode('+', $info[1]);
- $systemInfoArray[$key] = $version[0];
- } else {
- $systemInfoArray[$key] = $info[1];
- }
- }
- }
- }
- $outputArray = array();
- $outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration($p_testing);
- $outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration($p_testing);
- $outputArray['SOUNDCLOUD_ENABLED'] = self::GetUploadToSoundcloudOption();
- if ($outputArray['SOUNDCLOUD_ENABLED']) {
- $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = Application_Model_StoredFile::getSoundCloudUploads();
- } else {
- $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = NULL;
- }
- $outputArray['STATION_NAME'] = self::GetStationName();
- $outputArray['PHONE'] = self::GetPhone();
- $outputArray['EMAIL'] = self::GetEmail();
- $outputArray['STATION_WEB_SITE'] = self::GetStationWebSite();
- $outputArray['STATION_COUNTRY'] = self::GetStationCountry();
- $outputArray['STATION_CITY'] = self::GetStationCity();
- $outputArray['STATION_DESCRIPTION'] = self::GetStationDescription();
- // get web server info
- if (isset($systemInfoArray["AIRTIME_VERSION_URL"])) {
- $url = $systemInfoArray["AIRTIME_VERSION_URL"];
- $index = strpos($url,'/api/');
- $url = substr($url, 0, $index);
-
- $headerInfo = get_headers(trim($url),1);
- $outputArray['WEB_SERVER'] = $headerInfo['Server'][0];
- }
- $outputArray['NUM_OF_USERS'] = Application_Model_User::getUserCount();
- $outputArray['NUM_OF_SONGS'] = Application_Model_StoredFile::getFileCount();
- $outputArray['NUM_OF_PLAYLISTS'] = Application_Model_Playlist::getPlaylistCount();
- $outputArray['NUM_OF_SCHEDULED_PLAYLISTS'] = Application_Model_Schedule::getSchduledPlaylistCount();
- $outputArray['NUM_OF_PAST_SHOWS'] = Application_Model_ShowInstance::GetShowInstanceCount(gmdate("Y-m-d H:i:s"));
- $outputArray['UNIQUE_ID'] = self::GetUniqueId();
- $outputArray['SAAS'] = self::GetPlanLevel();
- if ($outputArray['SAAS'] != 'disabled') {
- $outputArray['TRIAL_END_DATE'] = self::GetTrialEndingDate();
- } else {
- $outputArray['TRIAL_END_DATE'] = NULL;
- }
- $outputArray['INSTALL_METHOD'] = self::GetInstallMethod();
- $outputArray['NUM_OF_STREAMS'] = self::GetNumOfStreams();
- $outputArray['STREAM_INFO'] = Application_Model_StreamSetting::getStreamInfoForDataCollection();
- $outputArray = array_merge($systemInfoArray, $outputArray);
- $outputString = "\n";
- foreach ($outputArray as $key => $out) {
- if ($key == 'TRIAL_END_DATE' && ($out != '' || $out != 'NULL')) {
- continue;
- }
- if ($key == "STREAM_INFO") {
- $outputString .= $key." :\n";
- foreach ($out as $s_info) {
- foreach ($s_info as $k => $v) {
- $outputString .= "\t".strtoupper($k)." : ".$v."\n";
- }
- }
- } elseif ($key == "SOUNDCLOUD_ENABLED") {
- if ($out) {
- $outputString .= $key." : TRUE\n";
- } elseif (!$out) {
- $outputString .= $key." : FALSE\n";
- }
- } elseif ($key == "SAAS") {
- if (strcmp($out, 'disabled')!=0) {
- $outputString .= $key.' : '.$out."\n";
- }
- } else {
- $outputString .= $key.' : '.$out."\n";
- }
- }
- if ($returnArray) {
- $outputArray['PROMOTE'] = self::GetPublicise();
- $outputArray['LOGOIMG'] = self::GetStationLogo();
- return $outputArray;
- } else {
- return $outputString;
- }
- }
- public static function GetInstallMethod()
- {
- $easy_install = file_exists('/usr/bin/airtime-easy-setup');
- $debian_install = file_exists('/var/lib/dpkg/info/airtime.config');
- if ($debian_install) {
- if ($easy_install) {
- return "easy_install";
- } else {
- return "debian_install";
- }
- } else {
- return "manual_install";
- }
- }
- public static function SetRemindMeDate($p_never = false)
- {
- if ($p_never) {
- self::setValue("remindme", -1);
- } else {
- $weekAfter = mktime(0, 0, 0, gmdate("m"), gmdate("d")+7, gmdate("Y"));
- self::setValue("remindme", $weekAfter);
- }
- }
- public static function GetRemindMeDate()
- {
- return self::getValue("remindme");
- }
- public static function SetImportTimestamp()
- {
- $now = time();
- if (self::GetImportTimestamp()+5 < $now) {
- self::setValue("import_timestamp", $now);
- }
- }
- public static function GetImportTimestamp()
- {
- return self::getValue("import_timestamp");
- }
- public static function GetStreamType()
- {
- $st = self::getValue("stream_type");
- return explode(',', $st);
- }
- public static function GetStreamBitrate()
- {
- $sb = self::getValue("stream_bitrate");
- return explode(',', $sb);
- }
- public static function SetPrivacyPolicyCheck($flag)
- {
- self::setValue("privacy_policy", $flag);
- }
- public static function GetPrivacyPolicyCheck()
- {
- return self::getValue("privacy_policy");
- }
- public static function SetNumOfStreams($num)
- {
- self::setValue("num_of_streams", intval($num));
- }
- public static function GetNumOfStreams()
- {
- return self::getValue("num_of_streams");
- }
- public static function SetMaxBitrate($bitrate)
- {
- self::setValue("max_bitrate", intval($bitrate));
- }
- public static function GetMaxBitrate()
- {
- return self::getValue("max_bitrate");
- }
- public static function SetPlanLevel($plan)
- {
- self::setValue("plan_level", $plan);
- }
- public static function GetPlanLevel()
- {
- $plan = self::getValue("plan_level");
- if (trim($plan) == '') {
- $plan = 'disabled';
- }
- return $plan;
- }
- public static function SetTrialEndingDate($date)
- {
- self::setValue("trial_end_date", $date);
- }
- public static function GetTrialEndingDate()
- {
- return self::getValue("trial_end_date");
- }
- public static function SetEnableStreamConf($bool)
- {
- self::setValue("enable_stream_conf", $bool);
- }
- public static function GetEnableStreamConf()
- {
- if (self::getValue("enable_stream_conf") == Null) {
- return "true";
- }
- return self::getValue("enable_stream_conf");
- }
- public static function GetSchemaVersion()
- {
- $schemaVersion = self::getValue("schema_version");
- //Pre-2.5.2 releases all used this ambiguous "system_version" key to represent both the code and schema versions...
- if (empty($schemaVersion)) {
- $schemaVersion = self::getValue("system_version");
- }
- return $schemaVersion;
- }
- public static function SetSchemaVersion($version)
- {
- self::setValue("schema_version", $version);
- }
- public static function GetAirtimeVersion()
- {
- if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development" && function_exists('exec')) {
- $version = exec("git rev-parse --short HEAD 2>/dev/null", $out, $return_code);
- if ($return_code == 0) {
- return self::getValue("system_version")."+".$version.":".time();
- }
- }
- return self::getValue("system_version");
- }
- public static function GetLatestVersion()
- {
- $latest = self::getValue("latest_version");
- if ($latest == null || strlen($latest) == 0) {
- return self::GetAirtimeVersion();
- } else {
- return $latest;
- }
- }
- public static function SetLatestVersion($version)
- {
- $pattern = "/^[0-9]+\.[0-9]+\.[0-9]+/";
- if (preg_match($pattern, $version)) {
- self::setValue("latest_version", $version);
- }
- }
- public static function GetLatestLink()
- {
- $link = self::getValue("latest_link");
- if ($link == null || strlen($link) == 0) {
- return 'http://airtime.sourcefabric.org';
- } else {
- return $link;
- }
- }
- public static function SetLatestLink($link)
- {
- $pattern = "#^(http|https|ftp)://" .
- "([a-zA-Z0-9]+\.)*[a-zA-Z0-9]+" .
- "(/[a-zA-Z0-9\-\.\_\~\:\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=]+)*/?$#";
- if (preg_match($pattern, $link)) {
- self::setValue("latest_link", $link);
- }
- }
- public static function SetUploadToSoundcloudOption($upload)
- {
- self::setValue("soundcloud_upload_option", $upload);
- }
- public static function GetUploadToSoundcloudOption()
- {
- return self::getValue("soundcloud_upload_option");
- }
- public static function SetSoundCloudDownloadbleOption($upload)
- {
- self::setValue("soundcloud_downloadable", $upload);
- }
- public static function GetSoundCloudDownloadbleOption()
- {
- return self::getValue("soundcloud_downloadable");
- }
- public static function SetWeekStartDay($day)
- {
- self::setValue("week_start_day", $day);
- }
- public static function GetWeekStartDay()
- {
- $val = self::getValue("week_start_day");
- return (strlen($val) == 0) ? "0" : $val;
- }
- /**
- * Stores the last timestamp of user updating stream setting
- */
- public static function SetStreamUpdateTimestamp()
- {
- $now = time();
- self::setValue("stream_update_timestamp", $now);
- }
- /**
- * Gets the last timestamp of user updating stream setting
- */
- public static function GetStreamUpdateTimestemp()
- {
- $update_time = self::getValue("stream_update_timestamp");
- return ($update_time == null) ? 0 : $update_time;
- }
- public static function GetClientId()
- {
- return self::getValue("client_id");
- }
- public static function SetClientId($id)
- {
- if (is_numeric($id)) {
- self::setValue("client_id", $id);
- } else {
- Logging::warn("Attempting to set client_id to invalid value: $id");
- }
- }
- /* User specific preferences start */
- /**
- * Sets the time scale preference (agendaDay/agendaWeek/month) in Calendar.
- *
- * @param $timeScale new time scale
- */
- public static function SetCalendarTimeScale($timeScale)
- {
- self::setValue("calendar_time_scale", $timeScale, true /* user specific */);
- }
- /**
- * Retrieves the time scale preference for the current user.
- * Defaults to month if no entry exists
- */
- public static function GetCalendarTimeScale()
- {
- $val = self::getValue("calendar_time_scale", true /* user specific */);
- if (strlen($val) == 0) {
- $val = "month";
- }
- return $val;
- }
- /**
- * Sets the number of entries to show preference in library under Playlist Builder.
- *
- * @param $numEntries new number of entries to show
- */
- public static function SetLibraryNumEntries($numEntries)
- {
- self::setValue("library_num_entries", $numEntries, true /* user specific */);
- }
- /**
- * Retrieves the number of entries to show preference in library under Playlist Builder.
- * Defaults to 10 if no entry exists
- */
- public static function GetLibraryNumEntries()
- {
- $val = self::getValue("library_num_entries", true /* user specific */);
- if (strlen($val) == 0) {
- $val = "10";
- }
- return $val;
- }
- /**
- * Sets the time interval preference in Calendar.
- *
- * @param $timeInterval new time interval
- */
- public static function SetCalendarTimeInterval($timeInterval)
- {
- self::setValue("calendar_time_interval", $timeInterval, true /* user specific */);
- }
- /**
- * Retrieves the time interval preference for the current user.
- * Defaults to 30 min if no entry exists
- */
- public static function GetCalendarTimeInterval()
- {
- $val = self::getValue("calendar_time_interval", true /* user specific */);
- return (strlen($val) == 0) ? "30" : $val;
- }
- public static function SetDiskQuota($value)
- {
- self::setValue("disk_quota", $value, false);
- }
- public static function GetDiskQuota()
- {
- $val = self::getValue("disk_quota");
- return (strlen($val) == 0) ? 0 : $val;
- }
- public static function SetLiveStreamMasterUsername($value)
- {
- self::setValue("live_stream_master_username", $value, false);
- }
- public static function GetLiveStreamMasterUsername()
- {
- return self::getValue("live_stream_master_username");
- }
- public static function SetLiveStreamMasterPassword($value)
- {
- self::setValue("live_stream_master_password", $value, false);
- }
- public static function GetLiveStreamMasterPassword()
- {
- return self::getValue("live_stream_master_password");
- }
- public static function SetSourceStatus($sourcename, $status)
- {
- self::setValue($sourcename, $status, false);
- }
- public static function GetSourceStatus($sourcename)
- {
- $value = self::getValue($sourcename);
- return !($value == null || $value == "false");
- }
- public static function SetSourceSwitchStatus($sourcename, $status)
- {
- self::setValue($sourcename."_switch", $status, false);
- }
- public static function GetSourceSwitchStatus($sourcename)
- {
- $value = self::getValue($sourcename."_switch");
- return ($value == null || $value == "off") ? 'off' : 'on';
- }
- public static function SetMasterDJSourceConnectionURL($value)
- {
- self::setValue("master_dj_source_connection_url", $value, false);
- }
- public static function GetMasterDJSourceConnectionURL()
- {
- return self::getValue("master_dj_source_connection_url");
- }
- public static function SetLiveDJSourceConnectionURL($value)
- {
- self::setValue("live_dj_source_connection_url", $value, false);
- }
- public static function GetLiveDJSourceConnectionURL()
- {
- return self::getValue("live_dj_source_connection_url");
- }
- /* Source Connection URL override status starts */
- public static function GetLiveDjConnectionUrlOverride()
- {
- return self::getValue("live_dj_connection_url_override");
- }
- public static function SetLiveDjConnectionUrlOverride($value)
- {
- self::setValue("live_dj_connection_url_override", $value, false);
- }
- public static function GetMasterDjConnectionUrlOverride()
- {
- return self::getValue("master_dj_connection_url_override");
- }
- public static function SetMasterDjConnectionUrlOverride($value)
- {
- self::setValue("master_dj_connection_url_override", $value, false);
- }
- /* Source Connection URL override status ends */
- public static function SetAutoTransition($value)
- {
- self::setValue("auto_transition", $value, false);
- }
- public static function GetAutoTransition()
- {
- return self::getValue("auto_transition");
- }
- public static function SetAutoSwitch($value)
- {
- self::setValue("auto_switch", $value, false);
- }
- public static function GetAutoSwitch()
- {
- return self::getValue("auto_switch");
- }
- public static function SetEnableSystemEmail($upload)
- {
- self::setValue("enable_system_email", $upload);
- }
- public static function GetEnableSystemEmail()
- {
- $v = self::getValue("enable_system_email");
- return ($v === "") ? 0 : $v;
- }
- public static function SetSystemEmail($value)
- {
- self::setValue("system_email", $value, false);
- }
- public static function GetSystemEmail()
- {
- return self::getValue("system_email");
- }
- public static function SetMailServerConfigured($value)
- {
- self::setValue("mail_server_configured", $value, false);
- }
- public static function GetMailServerConfigured()
- {
- return self::getValue("mail_server_configured");
- }
- public static function SetMailServer($value)
- {
- self::setValue("mail_server", $value, false);
- }
- public static function GetMailServer()
- {
- return self::getValue("mail_server");
- }
- public static function SetMailServerEmailAddress($value)
- {
- self::setValue("mail_server_email_address", $value, false);
- }
- public static function GetMailServerEmailAddress()
- {
- return self::getValue("mail_server_email_address");
- }
- public static function SetMailServerPassword($value)
- {
- self::setValue("mail_server_password", $value, false);
- }
- public static function GetMailServerPassword()
- {
- return self::getValue("mail_server_password");
- }
- public static function SetMailServerPort($value)
- {
- self::setValue("mail_server_port", $value, false);
- }
- public static function GetMailServerPort()
- {
- return self::getValue("mail_server_port");
- }
- public static function SetMailServerRequiresAuth($value)
- {
- self::setValue("mail_server_requires_auth", $value, false);
- }
- public static function GetMailServerRequiresAuth()
- {
- return self::getValue("mail_server_requires_auth");
- }
- /* User specific preferences end */
- public static function ShouldShowPopUp()
- {
- $today = mktime(0, 0, 0, gmdate("m"), gmdate("d"), gmdate("Y"));
- $remindDate = Application_Model_Preference::GetRemindMeDate();
- $retVal = false;
-
- if (is_null($remindDate) || ($remindDate != -1 && $today >= $remindDate)) {
- $retVal = true;
- }
-
- return $retVal;
- }
- public static function getOrderingMap($pref_param)
- {
- $v = self::getValue($pref_param, true);
- $id = function ($x) { return $x; };
- if ($v === '') {
- return $id;
- }
- $ds = unserialize($v);
-
-
- if (is_null($ds) || !is_array($ds)) {
- return $id;
- }
-
- if (!array_key_exists('ColReorder', $ds)) {
- return $id;
- }
- return function ($x) use ($ds) {
- if (array_key_exists($x, $ds['ColReorder'])) {
- return $ds['ColReorder'][$x];
- } else {
- /*For now we just have this hack for debugging. We should not
- rely on this behaviour in case of failure*/
- Logging::warn("Index $x does not exist preferences");
- Logging::warn("Defaulting to identity and printing preferences");
- Logging::warn($ds);
- return $x;
- }
- };
- }
- public static function getCurrentLibraryTableColumnMap()
- {
- return self::getOrderingMap("library_datatable");
- }
- public static function setCurrentLibraryTableSetting($settings)
- {
- $data = serialize($settings);
- self::setValue("library_datatable", $data, true);
- }
- public static function getCurrentLibraryTableSetting()
- {
- $data = self::getValue("library_datatable", true);
- return ($data != "") ? unserialize($data) : null;
- }
- public static function setTimelineDatatableSetting($settings)
- {
- $data = serialize($settings);
- self::setValue("timeline_datatable", $data, true);
- }
- public static function getTimelineDatatableSetting()
- {
- $data = self::getValue("timeline_datatable", true);
- return ($data != "") ? unserialize($data) : null;
- }
- public static function setNowPlayingScreenSettings($settings)
- {
- $data = serialize($settings);
- self::setValue("nowplaying_screen", $data, true);
- }
- public static function getNowPlayingScreenSettings()
- {
- $data = self::getValue("nowplaying_screen", true);
- return ($data != "") ? unserialize($data) : null;
- }
- public static function setLibraryScreenSettings($settings)
- {
- $data = serialize($settings);
- self::setValue("library_screen", $data, true);
- }
- public static function getLibraryScreenSettings()
- {
- $data = self::getValue("library_screen", true);
- return ($data != "") ? unserialize($data) : null;
- }
- public static function SetEnableReplayGain($value) {
- self::setValue("enable_replay_gain", $value, false);
- }
-
- public static function GetEnableReplayGain() {
- return self::getValue("enable_replay_gain", false);
- }
-
- public static function getReplayGainModifier() {
- $rg_modifier = self::getValue("replay_gain_modifier");
-
- if ($rg_modifier === "")
- return "0";
-
- return $rg_modifier;
- }
-
- public static function setReplayGainModifier($rg_modifier)
- {
- self::setValue("replay_gain_modifier", $rg_modifier, true);
- }
-
- public static function SetHistoryItemTemplate($value) {
- self::setValue("history_item_template", $value);
- }
-
- public static function GetHistoryItemTemplate() {
- return self::getValue("history_item_template");
- }
-
- public static function SetHistoryFileTemplate($value) {
- self::setValue("history_file_template", $value);
- }
-
- public static function GetHistoryFileTemplate() {
- return self::getValue("history_file_template");
- }
- }
|