track type default

This commit is contained in:
Codenift 2020-05-04 00:32:52 -04:00
parent f87dc5cbbc
commit 5ef67836cf
7 changed files with 93 additions and 64 deletions

View file

@ -442,7 +442,7 @@ class FileDataHelper {
$tt = $_COOKIE['tt_upload']; $tt = $_COOKIE['tt_upload'];
} else { } else {
// Use default track type // Use default track type
$tt = "MUS"; $tt = Application_Model_Preference::GetTrackTypeDefault();
} }
return $tt; return $tt;
} }

View file

@ -25,7 +25,7 @@ class PreferenceController extends Zend_Controller_Action
$request = $this->getRequest(); $request = $this->getRequest();
Zend_Layout::getMvcInstance()->assign('parent_page', 'Settings'); Zend_Layout::getMvcInstance()->assign('parent_page', 'Settings');
$baseUrl = Application_Common_OsPath::getBaseDir(); $baseUrl = Application_Common_OsPath::getBaseDir();
$this->view->headScript()->appendFile($baseUrl.'js/airtime/preferences/preferences.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/preferences/preferences.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
@ -42,6 +42,7 @@ class PreferenceController extends Zend_Controller_Action
{ {
Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view); Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view);
Application_Model_Preference::SetStationDescription($values["stationDescription"]); Application_Model_Preference::SetStationDescription($values["stationDescription"]);
Application_Model_Preference::SetTrackTypeDefault($values["tracktypeDefault"]);
Application_Model_Preference::SetDefaultCrossfadeDuration($values["stationDefaultCrossfadeDuration"]); Application_Model_Preference::SetDefaultCrossfadeDuration($values["stationDefaultCrossfadeDuration"]);
Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]); Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]);
Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]); Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]);
@ -502,7 +503,7 @@ class PreferenceController extends Zend_Controller_Action
{ {
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
if (!SecurityHelper::verifyCSRFToken($this->_getParam('csrf_token'))) { if (!SecurityHelper::verifyCSRFToken($this->_getParam('csrf_token'))) {
Logging::error(__FILE__ . ': Invalid CSRF token'); Logging::error(__FILE__ . ': Invalid CSRF token');
$this->_helper->json->sendJson(array("jsonrpc" => "2.0", "valid" => false, "error" => "CSRF token did not match.")); $this->_helper->json->sendJson(array("jsonrpc" => "2.0", "valid" => false, "error" => "CSRF token did not match."));

View file

@ -100,6 +100,11 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
'value' => $defaultFadeOut, 'value' => $defaultFadeOut,
)); ));
$tracktypeDefault = new Zend_Form_Element_Select("tracktypeDefault");
$tracktypeDefault->setLabel(_("Track Type Upload Default"));
$tracktypeDefault->setMultiOptions(Application_Model_Library::getTracktypes());
$tracktypeDefault->setValue(Application_Model_Preference::GetTrackTypeDefault());
$this->addElement($tracktypeDefault);
// add intro playlist select here // add intro playlist select here
$introPlaylistSelect = new Zend_Form_Element_Select("introPlaylistSelect"); $introPlaylistSelect = new Zend_Form_Element_Select("introPlaylistSelect");
@ -114,8 +119,6 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
$outroPlaylistSelect->setValue(Application_Model_Preference::GetOutroPlaylist()); $outroPlaylistSelect->setValue(Application_Model_Preference::GetOutroPlaylist());
$this->addElement($outroPlaylistSelect); $this->addElement($outroPlaylistSelect);
$podcast_album_override = new Zend_Form_Element_Radio('podcastAlbumOverride'); $podcast_album_override = new Zend_Form_Element_Radio('podcastAlbumOverride');
$podcast_album_override->setLabel(_('Overwrite Podcast Episode Metatags')); $podcast_album_override->setLabel(_('Overwrite Podcast Episode Metatags'));
$podcast_album_override->setMultiOptions(array( $podcast_album_override->setMultiOptions(array(

View file

@ -56,4 +56,15 @@ class Application_Model_Library
return $playlistNames; return $playlistNames;
} }
public static function getTracktypes()
{
$track_type_options = array(NULL => _("None"));
$track_types = Application_Model_Tracktype::getTracktypes();
foreach ($track_types as $key => $tt) {
$track_type_options[$tt['code']] = $tt['type_name'];
}
return $track_type_options;
}
} }

View file

@ -2,7 +2,7 @@
class Application_Model_Preference class Application_Model_Preference
{ {
private static function getUserId() private static function getUserId()
{ {
//pass in true so the check is made with the autoloader //pass in true so the check is made with the autoloader
@ -13,10 +13,10 @@ class Application_Model_Preference
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
$userId = $auth->getIdentity()->id; $userId = $auth->getIdentity()->id;
} }
return $userId; return $userId;
} }
/** /**
* *
* @param boolean $isUserValue is true when we are setting a value for the current user * @param boolean $isUserValue is true when we are setting a value for the current user
@ -32,7 +32,7 @@ class Application_Model_Preference
/* Comment this out while we reevaluate it in favor of a unique constraint /* Comment this out while we reevaluate it in favor of a unique constraint
static::_lock($con); */ static::_lock($con); */
$userId = self::getUserId(); $userId = self::getUserId();
if ($isUserValue && is_null($userId)) { if ($isUserValue && is_null($userId)) {
throw new Exception("User id can't be null for a user preference {$key}."); throw new Exception("User id can't be null for a user preference {$key}.");
} }
@ -40,10 +40,10 @@ class Application_Model_Preference
//Check if key already exists //Check if key already exists
$sql = "SELECT valstr FROM cc_pref" $sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = :key"; ." WHERE keystr = :key";
$paramMap = array(); $paramMap = array();
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue) { if ($isUserValue) {
$sql .= " AND subjid = :id"; $sql .= " AND subjid = :id";
@ -52,8 +52,8 @@ class Application_Model_Preference
$sql .= " FOR UPDATE"; $sql .= " FOR UPDATE";
$result = Application_Common_Database::prepareAndExecute($sql, $result = Application_Common_Database::prepareAndExecute($sql,
$paramMap, $paramMap,
Application_Common_Database::ROW_COUNT, Application_Common_Database::ROW_COUNT,
PDO::FETCH_ASSOC, PDO::FETCH_ASSOC,
$con); $con);
@ -64,7 +64,7 @@ class Application_Model_Preference
throw new Exception("Invalid number of results returned. Should be ". throw new Exception("Invalid number of results returned. Should be ".
"0 or 1, but is '$result' instead"); "0 or 1, but is '$result' instead");
} else if ($result == 1) { } else if ($result == 1) {
// result found // result found
if (!$isUserValue) { if (!$isUserValue) {
// system pref // system pref
@ -76,11 +76,11 @@ class Application_Model_Preference
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
. " SET valstr = :value" . " SET valstr = :value"
. " WHERE keystr = :key AND subjid = :id"; . " WHERE keystr = :key AND subjid = :id";
$paramMap[':id'] = $userId; $paramMap[':id'] = $userId;
} }
} else { } else {
// result not found // result not found
if (!$isUserValue) { if (!$isUserValue) {
// system pref // system pref
@ -90,17 +90,17 @@ class Application_Model_Preference
// user pref // user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES (:id, :key, :value)"; ." VALUES (:id, :key, :value)";
$paramMap[':id'] = $userId; $paramMap[':id'] = $userId;
} }
} }
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
$paramMap[':value'] = $value; $paramMap[':value'] = $value;
Application_Common_Database::prepareAndExecute($sql, Application_Common_Database::prepareAndExecute($sql,
$paramMap, $paramMap,
Application_Common_Database::EXECUTE, Application_Common_Database::EXECUTE,
PDO::FETCH_ASSOC, PDO::FETCH_ASSOC,
$con); $con);
} catch (Exception $e) { } catch (Exception $e) {
@ -141,7 +141,7 @@ class Application_Model_Preference
private static function getValue($key, $isUserValue = false, $forceDefault = false) private static function getValue($key, $isUserValue = false, $forceDefault = false)
{ {
try { try {
$userId = null; $userId = null;
if ($isUserValue) { if ($isUserValue) {
//This is nested in here because so we can still use getValue() when the session hasn't started yet. //This is nested in here because so we can still use getValue() when the session hasn't started yet.
@ -154,10 +154,10 @@ class Application_Model_Preference
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = :key"; ." WHERE keystr = :key";
$paramMap = array(); $paramMap = array();
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue) { if ($isUserValue) {
$sql .= " AND subjid = :id"; $sql .= " AND subjid = :id";
@ -174,7 +174,7 @@ class Application_Model_Preference
} else { } else {
$sql = "SELECT valstr FROM cc_pref" $sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = :key"; ." WHERE keystr = :key";
$paramMap = array(); $paramMap = array();
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
@ -183,14 +183,14 @@ class Application_Model_Preference
$sql .= " AND subjid = :id"; $sql .= " AND subjid = :id";
$paramMap[':id'] = $userId; $paramMap[':id'] = $userId;
} }
$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN); $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
$res = ($result !== false) ? $result : ""; $res = ($result !== false) ? $result : "";
} }
return $res; return $res;
} }
catch (Exception $e) { catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
Logging::info("Could not connect to database: ".$e); Logging::info("Could not connect to database: ".$e);
@ -258,55 +258,55 @@ class Application_Model_Preference
return new DateTime($date, new DateTimeZone("UTC")); return new DateTime($date, new DateTimeZone("UTC"));
} }
} }
public static function SetDefaultCrossfadeDuration($duration) public static function SetDefaultCrossfadeDuration($duration)
{ {
self::setValue("default_crossfade_duration", $duration); self::setValue("default_crossfade_duration", $duration);
} }
public static function GetDefaultCrossfadeDuration() public static function GetDefaultCrossfadeDuration()
{ {
$duration = self::getValue("default_crossfade_duration"); $duration = self::getValue("default_crossfade_duration");
if ($duration === "") { if ($duration === "") {
// the default value of the fade is 00.5 // the default value of the fade is 00.5
return "0"; return "0";
} }
return $duration; return $duration;
} }
public static function SetDefaultFadeIn($fade) public static function SetDefaultFadeIn($fade)
{ {
self::setValue("default_fade_in", $fade); self::setValue("default_fade_in", $fade);
} }
public static function GetDefaultFadeIn() public static function GetDefaultFadeIn()
{ {
$fade = self::getValue("default_fade_in"); $fade = self::getValue("default_fade_in");
if ($fade === "") { if ($fade === "") {
// the default value of the fade is 00.5 // the default value of the fade is 00.5
return "0.5"; return "0.5";
} }
return $fade; return $fade;
} }
public static function SetDefaultFadeOut($fade) public static function SetDefaultFadeOut($fade)
{ {
self::setValue("default_fade_out", $fade); self::setValue("default_fade_out", $fade);
} }
public static function GetDefaultFadeOut() public static function GetDefaultFadeOut()
{ {
$fade = self::getValue("default_fade_out"); $fade = self::getValue("default_fade_out");
if ($fade === "") { if ($fade === "") {
// the default value of the fade is 0.5 // the default value of the fade is 0.5
return "0.5"; return "0.5";
} }
return $fade; return $fade;
} }
@ -370,7 +370,7 @@ class Application_Model_Preference
{ {
self::setValue("podcast_album_override", $bool); self::setValue("podcast_album_override", $bool);
} }
public static function GetPodcastAlbumOverride() public static function GetPodcastAlbumOverride()
{ {
$val = self::getValue("podcast_album_override"); $val = self::getValue("podcast_album_override");
@ -388,6 +388,16 @@ class Application_Model_Preference
return $val === '1' ? true : false; return $val === '1' ? true : false;
} }
public static function SetTrackTypeDefault($tracktype)
{
self::setValue("tracktype_default", $tracktype);
}
public static function GetTrackTypeDefault()
{
return self::getValue("tracktype_default");
}
public static function GetIntroPlaylist() public static function GetIntroPlaylist()
{ {
return self::getValue("intro_playlist"); return self::getValue("intro_playlist");
@ -527,7 +537,7 @@ class Application_Model_Preference
public static function GetUserTimezone() public static function GetUserTimezone()
{ {
$timezone = self::getValue("user_timezone", true); $timezone = self::getValue("user_timezone", true);
if (!$timezone) { if (!$timezone) {
return self::GetDefaultTimezone(); return self::GetDefaultTimezone();
} else { } else {
@ -539,7 +549,7 @@ class Application_Model_Preference
public static function GetTimezone() public static function GetTimezone()
{ {
$userId = self::getUserId(); $userId = self::getUserId();
if (!is_null($userId)) { if (!is_null($userId)) {
return self::GetUserTimezone(); return self::GetUserTimezone();
} else { } else {
@ -581,7 +591,7 @@ class Application_Model_Preference
public static function GetLocale() public static function GetLocale()
{ {
$userId = self::getUserId(); $userId = self::getUserId();
if (!is_null($userId)) { if (!is_null($userId)) {
return self::GetUserLocale(); return self::GetUserLocale();
} else { } else {
@ -612,7 +622,7 @@ class Application_Model_Preference
return $image; return $image;
} }
} }
public static function SetUniqueId($id) public static function SetUniqueId($id)
{ {
self::setValue("uniqueId", $id); self::setValue("uniqueId", $id);
@ -626,7 +636,7 @@ class Application_Model_Preference
public static function GetCountryList() public static function GetCountryList()
{ {
$sql = "SELECT * FROM cc_country"; $sql = "SELECT * FROM cc_country";
$res = Application_Common_Database::prepareAndExecute($sql, array()); $res = Application_Common_Database::prepareAndExecute($sql, array());
$out = array(); $out = array();
@ -682,7 +692,7 @@ class Application_Model_Preference
$url = $systemInfoArray["AIRTIME_VERSION_URL"]; $url = $systemInfoArray["AIRTIME_VERSION_URL"];
$index = strpos($url,'/api/'); $index = strpos($url,'/api/');
$url = substr($url, 0, $index); $url = substr($url, 0, $index);
$headerInfo = get_headers(trim($url),1); $headerInfo = get_headers(trim($url),1);
$outputArray['WEB_SERVER'] = $headerInfo['Server'][0]; $outputArray['WEB_SERVER'] = $headerInfo['Server'][0];
} }
@ -961,7 +971,7 @@ class Application_Model_Preference
Logging::warn("Attempting to set client_id to invalid value: $id"); Logging::warn("Attempting to set client_id to invalid value: $id");
} }
} }
/* User specific preferences start */ /* User specific preferences start */
/** /**
@ -1170,11 +1180,11 @@ class Application_Model_Preference
$today = mktime(0, 0, 0, gmdate("m"), gmdate("d"), gmdate("Y")); $today = mktime(0, 0, 0, gmdate("m"), gmdate("d"), gmdate("Y"));
$remindDate = Application_Model_Preference::GetRemindMeDate(); $remindDate = Application_Model_Preference::GetRemindMeDate();
$retVal = false; $retVal = false;
if (is_null($remindDate) || ($remindDate != -1 && $today >= $remindDate)) { if (is_null($remindDate) || ($remindDate != -1 && $today >= $remindDate)) {
$retVal = true; $retVal = true;
} }
return $retVal; return $retVal;
} }
@ -1191,12 +1201,12 @@ class Application_Model_Preference
} }
$ds = unserialize($v); $ds = unserialize($v);
if (is_null($ds) || !is_array($ds)) { if (is_null($ds) || !is_array($ds)) {
return $id; return $id;
} }
if (!array_key_exists('ColReorder', $ds)) { if (!array_key_exists('ColReorder', $ds)) {
return $id; return $id;
} }
@ -1273,37 +1283,37 @@ class Application_Model_Preference
public static function SetEnableReplayGain($value) { public static function SetEnableReplayGain($value) {
self::setValue("enable_replay_gain", $value, false); self::setValue("enable_replay_gain", $value, false);
} }
public static function GetEnableReplayGain() { public static function GetEnableReplayGain() {
return self::getValue("enable_replay_gain", false); return self::getValue("enable_replay_gain", false);
} }
public static function getReplayGainModifier() { public static function getReplayGainModifier() {
$rg_modifier = self::getValue("replay_gain_modifier"); $rg_modifier = self::getValue("replay_gain_modifier");
if ($rg_modifier === "") if ($rg_modifier === "")
return "0"; return "0";
return $rg_modifier; return $rg_modifier;
} }
public static function setReplayGainModifier($rg_modifier) public static function setReplayGainModifier($rg_modifier)
{ {
self::setValue("replay_gain_modifier", $rg_modifier, true); self::setValue("replay_gain_modifier", $rg_modifier, true);
} }
public static function SetHistoryItemTemplate($value) { public static function SetHistoryItemTemplate($value) {
self::setValue("history_item_template", $value); self::setValue("history_item_template", $value);
} }
public static function GetHistoryItemTemplate() { public static function GetHistoryItemTemplate() {
return self::getValue("history_item_template"); return self::getValue("history_item_template");
} }
public static function SetHistoryFileTemplate($value) { public static function SetHistoryFileTemplate($value) {
self::setValue("history_file_template", $value); self::setValue("history_file_template", $value);
} }
public static function GetHistoryFileTemplate() { public static function GetHistoryFileTemplate() {
return self::getValue("history_file_template"); return self::getValue("history_file_template");
} }
@ -1479,7 +1489,7 @@ class Application_Model_Preference
{ {
self::setValue("whats_new_dialog_viewed", $value, true); self::setValue("whats_new_dialog_viewed", $value, true);
} }
public static function getAutoPlaylistPollLock() { public static function getAutoPlaylistPollLock() {
return self::getValue("autoplaylist_poll_lock"); return self::getValue("autoplaylist_poll_lock");
} }

View file

@ -25,6 +25,8 @@
<?php echo $this->element->getElement('weekStartDay')->render() ?> <?php echo $this->element->getElement('weekStartDay')->render() ?>
<?php echo $this->element->getElement('tracktypeDefault')->render() ?>
<?php echo $this->element->getElement('stationDefaultFadeIn')->render() ?> <?php echo $this->element->getElement('stationDefaultFadeIn')->render() ?>
<?php echo $this->element->getElement('stationDefaultFadeOut')->render() ?> <?php echo $this->element->getElement('stationDefaultFadeOut')->render() ?>

View file

@ -25,9 +25,11 @@
<?php <?php
if (isset($_COOKIE['tt_upload'])) { if (isset($_COOKIE['tt_upload'])) {
$ttsaved = $_COOKIE['tt_upload']; $ttsaved = $_COOKIE['tt_upload'];
$timer_icon = '<i class="icon-time icon-white"></i>';
} else { } else {
// Use default track type // Use default track type
$ttsaved = "MUS"; $ttsaved = Application_Model_Preference::GetTrackTypeDefault();
$timer_icon = '';
} }
?> ?>
@ -66,7 +68,7 @@
} }
?> ?>
<H2><?php echo _("Upload")?> <span id="upload_type" <?php echo ($showTracktypesDropdown && $ttTitle!="") ? 'style="color:#ff611f"' : "" ?>> <H2><?php echo _("Upload")?> <span id="upload_type" <?php echo ($showTracktypesDropdown && $ttTitle!="") ? 'style="color:#ff611f"' : "" ?>>
<?php echo ($showTracktypesDropdown && $ttTitle!="") ? $ttTitle : "Tracks"; ?></span></H2> <?php echo ($showTracktypesDropdown && $ttTitle!="") ? $ttTitle : "Tracks"; ?></span> <?php echo $timer_icon; ?></H2>
<form action="/rest/media" method="post" id="add-media-dropzone" class="dropzone dz-clickable"> <form action="/rest/media" method="post" id="add-media-dropzone" class="dropzone dz-clickable">
<?php echo $this->form->getElement('csrf') ?> <?php echo $this->form->getElement('csrf') ?>
<div class="dz-message"> <div class="dz-message">