sintonia/legacy/application/forms/GeneralPreferences.php

265 lines
13 KiB
PHP
Raw Permalink Normal View History

Vendorize ZF1, fix PHPUnit and configure travis This a a rather large commit due to the nature of the stuff it is touching. To get PHPUnit up and running again I had to update some deps and I did so by vendorizing them. The vendorizing of zf1 makes sense since distros are already considering to drop it from their repos. * [x] install vendorized zf1 with composer * [x] load composer autoloader before zf1 * [x] Implement headAction for all Zend_Rest_Controller based controllers * [x] switch to yml dataset to get around string only limitations of xml sets (also removed warning in readme) * [x] use year 2044 as hardcoded date for tests since it is in the future and has the same days like previously used 2016 * [x] make tests easier to run when accessing phpunit directly * [x] clean up test helper to always use airtime.conf * [x] switch test dbname to libretime_test * [x] test db username password switched to libretime/libretime * [x] install phpunit with composer in a clear version (make tests easier to reproduce on other platforms) * [x] remove local libs from airtime repo (most of airtime_mvc/library was not needed of in vendor already) * [x] configure composer autoloading and use it (also removed requires that are not needed anymore) * [x] add LibreTime prefix for FileNotFoundException (phing had a similar class and these are all pre-namespace style) * [x] add .travis.yml file * [x] make etc and logdir configurable with LIBRETIME_CONF_DIR and LIBRETIME_LOG_DIR env (so travis can change it) * [x] slight cleanup in config for travis not to fail * [x] add cloud_storage.conf for during test runs * [x] rewrite mvc testing docs and move them to docs/ folder * [x] don't use `static::class` in a class that does not have a parent class, use `__CLASS__` instead. * [x] don't use `<ClassName>::class`, since we already know what class we want `"<ClassName>"` ist just fine. * [x] fix "can't use method in write context" errors on 5.4 (also helps the optimizer) * [x] add build status badge on main README.md Fixes https://github.com/LibreTime/libretime/issues/4 The PHP parts of https://github.com/LibreTime/libretime/pull/10 get obsoleted by this change and it will need rebasing. This also contains https://github.com/LibreTime/libretime/pull/8, the late static binding compat code was broken for no reason and until CentOS drops php 5.4 there is no reason I'm aware of not to support it. I inlined #8 since the test would be failing on php 5.4 without the change. If you want to run tests you need to run `composer install` in the root directory and then `cd airtime_mvc/tests && ../../vendor/bin/phpunit`. For the tests to run the user `libretime` needs to be allowed to create the `libretime_test` database. See `docs/TESTING.md` for more info on getting set up.
2017-02-20 21:47:53 +01:00
<?php
// this is not getting loaded by autloading since it has a classname
// that makes it clash with how zf1 expects to load plugins.
require_once 'customfilters/ImageSize.php';
class Application_Form_GeneralPreferences extends Zend_Form_SubForm
{
public function init()
{
$maxLens = Application_Model_Show::getMaxLengths();
$this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
$rangeValidator = Application_Form_Helper_ValidationTypes::overrideBetweenValidator(0, 59.9);
2021-10-11 16:10:47 +02:00
$this->setDecorators([
['ViewScript', ['viewScript' => 'form/preferences_general.phtml']],
]);
$defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn();
$defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut();
// Station name
2021-10-11 16:10:47 +02:00
$this->addElement('text', 'stationName', [
'class' => 'input_text',
'label' => _('Station Name'),
'required' => false,
2021-10-11 16:10:47 +02:00
'filters' => ['StringTrim'],
'value' => Application_Model_Preference::GetStationName(),
2021-10-11 16:10:47 +02:00
]);
// Station description
2021-10-11 16:10:47 +02:00
$stationDescription = new Zend_Form_Element_Textarea('stationDescription');
$stationDescription->setLabel(_('Station Description'));
$stationDescription->setValue(Application_Model_Preference::GetStationDescription());
$stationDescription->setRequired(false);
2021-10-11 16:10:47 +02:00
$stationDescription->setValidators([['StringLength', false, [0, $maxLens['description']]]]);
$stationDescription->setAttrib('rows', 4);
$this->addElement($stationDescription);
// Station Logo
$stationLogoUpload = new Zend_Form_Element_File('stationLogo');
$stationLogoUpload->setLabel(_('Station Logo:'))
2021-10-11 16:10:47 +02:00
->setDescription(_('Note: Anything larger than 600x600 will be resized.'))
->setRequired(false)
->addValidator('Count', false, 1)
->addValidator('Extension', false, 'jpg,jpeg,png,gif')
->setMaxFileSize(1000000)
->addFilter('ImageSize');
$stationLogoUpload->setAttrib('accept', 'image/*');
$this->addElement($stationLogoUpload);
$stationLogoRemove = new Zend_Form_Element_Button('stationLogoRemove');
$stationLogoRemove->setLabel(_('Remove'));
$stationLogoRemove->setAttrib('class', 'btn');
$stationLogoRemove->setAttrib('id', 'logo-remove-btn');
$stationLogoRemove->setAttrib('onclick', 'removeLogo();');
$this->addElement($stationLogoRemove);
// Default station crossfade duration
2021-10-11 16:10:47 +02:00
$this->addElement('text', 'stationDefaultCrossfadeDuration', [
'class' => 'input_text',
'label' => _('Default Crossfade Duration (s):'),
'required' => true,
2021-10-11 16:10:47 +02:00
'filters' => ['StringTrim'],
'validators' => [
$rangeValidator,
$notEmptyValidator,
['regex', false, ['/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)')]],
],
'value' => Application_Model_Preference::GetDefaultCrossfadeDuration(),
2021-10-11 16:10:47 +02:00
]);
// Default station fade in
2021-10-11 16:10:47 +02:00
$this->addElement('text', 'stationDefaultFadeIn', [
'class' => 'input_text',
'label' => _('Default Fade In (s):'),
'required' => true,
2021-10-11 16:10:47 +02:00
'filters' => ['StringTrim'],
'validators' => [
$rangeValidator,
$notEmptyValidator,
2021-10-11 16:10:47 +02:00
['regex', false, ['/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)')]],
],
'value' => $defaultFadeIn,
2021-10-11 16:10:47 +02:00
]);
// Default station fade out
2021-10-11 16:10:47 +02:00
$this->addElement('text', 'stationDefaultFadeOut', [
'class' => 'input_text',
'label' => _('Default Fade Out (s):'),
'required' => true,
2021-10-11 16:10:47 +02:00
'filters' => ['StringTrim'],
'validators' => [
$rangeValidator,
$notEmptyValidator,
2021-10-11 16:10:47 +02:00
['regex', false, ['/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)')]],
],
'value' => $defaultFadeOut,
2021-10-11 16:10:47 +02:00
]);
2021-10-11 16:10:47 +02:00
$tracktypeDefault = new Zend_Form_Element_Select('tracktypeDefault');
$tracktypeDefault->setLabel(_('Track Type Upload Default'));
2020-05-04 06:32:52 +02:00
$tracktypeDefault->setMultiOptions(Application_Model_Library::getTracktypes());
$tracktypeDefault->setValue(Application_Model_Preference::GetTrackTypeDefault());
$this->addElement($tracktypeDefault);
2019-01-15 14:45:21 +01:00
// add intro playlist select here
2021-10-11 16:10:47 +02:00
$introPlaylistSelect = new Zend_Form_Element_Select('introPlaylistSelect');
$introPlaylistSelect->setLabel(_('Intro Autoloading Playlist'));
2019-01-15 14:45:21 +01:00
$introPlaylistSelect->setMultiOptions(Application_Model_Library::getPlaylistNames(true));
$introPlaylistSelect->setValue(Application_Model_Preference::GetIntroPlaylist());
2019-01-15 14:45:21 +01:00
$this->addElement($introPlaylistSelect);
2021-10-11 16:10:47 +02:00
$outroPlaylistSelect = new Zend_Form_Element_Select('outroPlaylistSelect');
$outroPlaylistSelect->setLabel(_('Outro Autoloading Playlist'));
2019-01-15 14:45:21 +01:00
$outroPlaylistSelect->setMultiOptions(Application_Model_Library::getPlaylistNames(true));
$outroPlaylistSelect->setValue(Application_Model_Preference::GetOutroPlaylist());
2019-01-15 14:45:21 +01:00
$this->addElement($outroPlaylistSelect);
$podcast_album_override = new Zend_Form_Element_Radio('podcastAlbumOverride');
2019-01-23 02:54:34 +01:00
$podcast_album_override->setLabel(_('Overwrite Podcast Episode Metatags'));
2021-10-11 16:10:47 +02:00
$podcast_album_override->setMultiOptions([
_('Disabled'),
_('Enabled'),
]);
$podcast_album_override->setValue(Application_Model_Preference::GetPodcastAlbumOverride());
2019-01-23 02:54:34 +01:00
$podcast_album_override->setDescription(_('Enabling this feature will cause podcast episode tracks to have their Artist, Title, and Album metatags set from podcast feed values. Note that enabling this feature is recommended in order to ensure reliable scheduling of episodes via smartblocks.'));
$podcast_album_override->setSeparator(' '); // No <br> between radio buttons
2022-07-07 20:01:15 +02:00
$podcast_album_override->addDecorator('HtmlTag', [
'tag' => 'dd',
2021-10-11 16:10:47 +02:00
'id' => 'podcastAlbumOverride-element',
'class' => 'radio-inline-list',
2021-10-11 16:10:47 +02:00
]);
$this->addElement($podcast_album_override);
$podcast_auto_smartblock = new Zend_Form_Element_Radio('podcastAutoSmartblock');
2019-01-23 02:54:34 +01:00
$podcast_auto_smartblock->setLabel(_('Generate a smartblock and a playlist upon creation of a new podcast'));
2021-10-11 16:10:47 +02:00
$podcast_auto_smartblock->setMultiOptions([
_('Disabled'),
_('Enabled'),
]);
$podcast_auto_smartblock->setValue(Application_Model_Preference::GetPodcastAutoSmartblock());
2019-01-23 02:54:34 +01:00
$podcast_auto_smartblock->setDescription(_('If this option is enabled, a new smartblock and playlist matching the newest track of a podcast will be generated immediately upon creation of a new podcast. Note that the "Overwrite Podcast Episode Metatags" feature must also be enabled in order for smartblocks to reliably find episodes.'));
$podcast_auto_smartblock->setSeparator(' '); // No <br> between radio buttons
2022-07-07 20:01:15 +02:00
$podcast_auto_smartblock->addDecorator('HtmlTag', [
'tag' => 'dd',
2021-10-11 16:10:47 +02:00
'id' => 'podcastAutoSmartblock-element',
'class' => 'radio-inline-list',
2021-10-11 16:10:47 +02:00
]);
$this->addElement($podcast_auto_smartblock);
$scheduleTrimOverbooked = new Zend_Form_Element_Checkbox('scheduleTrimOverbooked');
$scheduleTrimOverbooked->setDecorators([
'ViewHelper',
'Errors',
'Label',
]);
$displayScheduleTrimOverbookedValue = Application_Model_Preference::getScheduleTrimOverbooked();
$scheduleTrimOverbooked->addDecorator('Label');
$scheduleTrimOverbooked->setLabel(_('Trim overbooked shows after autoloading?'));
$scheduleTrimOverbooked->setValue($displayScheduleTrimOverbookedValue);
$this->addElement($scheduleTrimOverbooked);
// TODO add and insert Podcast Smartblock and Playlist autogenerate options
$third_party_api = new Zend_Form_Element_Radio('thirdPartyApi');
2019-01-23 02:54:34 +01:00
$third_party_api->setLabel(_('Public LibreTime API'));
$third_party_api->setDescription(_('Required for embeddable schedule widget.'));
2021-10-11 16:10:47 +02:00
$third_party_api->setMultiOptions([
_('Disabled'),
_('Enabled'),
]);
$third_party_api->setValue(Application_Model_Preference::GetAllow3rdPartyApi());
2019-01-23 02:54:34 +01:00
$third_party_api->setDescription(_('Enabling this feature will allow LibreTime to provide schedule data
to external widgets that can be embedded in your website.'));
$third_party_api->setSeparator(' '); // No <br> between radio buttons
// $third_party_api->addDecorator(new Zend_Form_Decorator_Label(array('tag' => 'dd', 'class' => 'radio-inline-list')));
2022-07-07 20:01:15 +02:00
$third_party_api->addDecorator('HtmlTag', [
'tag' => 'dd',
2021-10-11 16:10:47 +02:00
'id' => 'thirdPartyApi-element',
'class' => 'radio-inline-list',
]);
$this->addElement($third_party_api);
2021-10-11 16:10:47 +02:00
$locale = new Zend_Form_Element_Select('locale');
$locale->setLabel(_('Default Language'));
$locale->setMultiOptions(Application_Model_Locale::getLocales());
$locale->setValue(Application_Model_Preference::GetDefaultLocale());
$this->addElement($locale);
2021-10-11 16:10:47 +02:00
// Form Element for setting the Timezone
$timezone = new Zend_Form_Element_Select('timezone');
$timezone->setLabel(_('Station Timezone'));
$timezone->setAttrib('disabled', 'true');
$timezone->setMultiOptions(Application_Common_Timezone::getTimezones());
$timezone->setValue(Application_Model_Preference::GetDefaultTimezone());
$this->addElement($timezone);
2021-10-11 16:10:47 +02:00
// Form Element for setting which day is the start of the week
$week_start_day = new Zend_Form_Element_Select('weekStartDay');
$week_start_day->setLabel(_('Week Starts On'));
$week_start_day->setMultiOptions($this->getWeekStartDays());
$week_start_day->setValue(Application_Model_Preference::GetWeekStartDay());
$this->addElement($week_start_day);
2021-10-11 16:10:47 +02:00
$radioPageLoginButton = new Zend_Form_Element_Checkbox('radioPageLoginButton');
$radioPageLoginButton->setDecorators([
'ViewHelper',
'Errors',
2021-10-11 16:10:47 +02:00
'Label',
]);
$displayRadioPageLoginButtonValue = Application_Model_Preference::getRadioPageDisplayLoginButton();
2021-10-11 16:10:47 +02:00
if ($displayRadioPageLoginButtonValue == '') {
$displayRadioPageLoginButtonValue = true;
}
$radioPageLoginButton->addDecorator('Label');
2021-10-11 16:10:47 +02:00
$radioPageLoginButton->setLabel(_('Display login button on your Radio Page?'));
$radioPageLoginButton->setValue($displayRadioPageLoginButtonValue);
$this->addElement($radioPageLoginButton);
2021-01-03 12:40:06 +01:00
// add a checkbox for completely disabling the radio page
$radioPageDisabled = new Zend_Form_Element_Checkbox('radioPageDisabled');
$radioPageDisabled->setDecorators([
'ViewHelper',
'Errors',
'Label',
]);
$radioPageDisabledValue = Application_Model_Preference::getRadioPageDisabled();
$radioPageDisabled->addDecorator('Label');
$radioPageDisabled->setLabel(_('Disable the public radio page and redirect to the login page?'));
$radioPageDisabled->setValue($radioPageDisabledValue);
$this->addElement($radioPageDisabled);
2021-01-03 12:40:06 +01:00
$feature_preview_mode = new Zend_Form_Element_Radio('featurePreviewMode');
$feature_preview_mode->setLabel(_('Feature Previews'));
2021-10-11 16:10:47 +02:00
$feature_preview_mode->setMultiOptions([
_('Disabled'),
_('Enabled'),
]);
2021-01-03 12:40:06 +01:00
$feature_preview_mode->setValue(Application_Model_Preference::GetFeaturePreviewMode());
$feature_preview_mode->setDescription(_('Enable this to opt-in to test new features.'));
$feature_preview_mode->setSeparator(' '); // No <br> between radio buttons
2022-07-07 20:01:15 +02:00
$feature_preview_mode->addDecorator('HtmlTag', [
'tag' => 'dd',
2021-10-11 16:10:47 +02:00
'id' => 'featurePreviewMode-element',
2021-01-03 12:40:06 +01:00
'class' => 'radio-inline-list',
2021-10-11 16:10:47 +02:00
]);
2021-01-03 12:40:06 +01:00
$this->addElement($feature_preview_mode);
}
private function getWeekStartDays()
{
2021-10-11 16:10:47 +02:00
return [
_('Sunday'),
_('Monday'),
_('Tuesday'),
_('Wednesday'),
_('Thursday'),
_('Friday'),
2021-10-11 16:10:47 +02:00
_('Saturday'),
];
}
}