{% extends 'layouts/layout.twig' %}
{% block title %}{{ __('Setup') }}{% endblock %}
{% set startpage = old.settings.startpage ? old.settings.startpage : settings.startpage %}
{% set linebreaks = old.settings.linebreaks ? old.settings.linebreaks : settings.linebreaks %}
{% set year = settings.year ? settings.year : "now"|date("Y") %}
{% set mylang = settings.language ? settings.language : locale %}
{% set mycopy = settings.copyright ? settings.copyright : "@" %}

{% block content %}
	
	<div class="formWrapper">

		<form method="POST" action="{{ path_for('settings.save') }}" enctype="multipart/form-data">
		
			<section id="system" class="settings">

				<header class="headline">
					<h1>{{ __('System') }} <span class="version-number">v. {{settings.version}}</span></h1>
					<p>{{ __('New here? Then watch') }} <a class="link tm-red underline-hover" href="https://www.youtube.com/watch?v=7yvlwXJL9dc" target="_blank">{{ __('the video-tutorial') }}</a> {{ __('about configurations for typemill on YouTube.') }}</p>
				</header>
				
				<div id="typemill" class="fc-system-version update-banner">{{ settings.version ? settings.version : 'Unknown' }}</div>

				<fieldset>
				
					<div class="medium{{ errors.settings.title ? ' error' : '' }}">
						<label for="settings[title]">{{ __('Website Title') }} *</label>
						<input type="text" name="settings[title]" id="title" pattern=".{2,50}" required title="{{ __('Use 2 to 50 characters') }}" value="{{ old.settings.title ? old.settings.title : settings.title }}" />
						{% if errors.settings.title %}
							<span class="error">{{ errors.settings.title | first }}</span>
						{% endif %}
					</div><div class="medium{{ errors.settings.author ? ' error' : '' }}">
						<label for="settings[author]">{{ __('Author') }}</label>
						<input type="text" name="settings[author]" id="author" pattern="[^()/><\]\{\}\?\$@#!*%§=[\\\x22;:|]{2,50}" value="{{ old.settings.author ? old.settings.author : settings.author }}" title="{{ __('Use 2 to 40 characters') }} {{ __('Only the following special characters are allowed') }} a,b a.b a-b a_b a&b a+b" />
						{% if errors.settings.author %}
							<span class="error">{{ errors.settings.author | first }}</span>
						{% endif %}
					</div><div class="medium{{ errors.settings.copyright ? ' error' : '' }}">
						<label for="settings[copyright]">{{ __('Copyright') }}/{{ __('Licence') }}</label>
						<select name="settings[copyright]" id="copyright">
							{% for copy in copyright %}
								<option value="{{ copy }}"{% if copy == old.settings.copyright or copy == mycopy %} selected{% endif %}>{{ __(copy) }}</option>
							{% endfor %}
						</select>
						{% if errors.settings.copyright %}
							<span class="error">{{ errors.settings.copyright | first }}</span>
						{% endif %}
					</div><div class="medium{{ errors.settings.year ? ' error' : '' }}">
						<label for="settings[year]">{{ __('Year') }} *</label>
						<input type="text" name="settings[year]" id="year" value="{{ old.settings.year ? old.settings.year : year }}" pattern="[0-9]{4}" required title="{{ __('Use a valid year') }}, {{ __('e.g.') }} 2017" />
						{% if errors.settings.year %}
							<span class="error">{{ errors.settings.year | first }}</span>
						{% endif %}
					</div><div class="medium{{ errors.settings.language ? ' error' : '' }}">
						<label for="settings[language]">{{ __('Language_admin') }}</label>
						<select name="settings[language]" id="language">
							{% for key,lang in languages %}
								<option value="{{ key }}"{% if (key == old.settings.language or key == mylang) %} selected{% endif %}>{{ __(lang) }}</option>
							{% endfor %}
						</select>
						{% if errors.settings.language %}
							<span class="error">{{ errors.settings.language | first }}</span>
						{% endif %}
					</div><div class="medium{{ errors.settings.langattr ? ' error' : '' }}">
						<label for="langattr">{{ __('Language_attr') }}</label>
						<input type="text" name="settings[langattr]" id="langattr" value="{{ old.settings.langattr ? old.settings.langattr : settings.langattr }}" pattern="[a-z]{2}" title="{{ __('Use a valid language attribute') }}, {{ __('e.g.') }} en" />
						<div class="description">{{ __('Please use codes from') }} <a target="_blank" href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1</a> {{ __('like «en»') }}</div>
						{% if errors.settings.langattr %}
							<span class="error">{{ errors.settings.langattr | first }}</span>
						{% endif %}
					</div><div class="medium">
						<label for="settings[sitemap]">{{ __('Google Sitemap') }} <small>({{ __('Readonly') }})</small></label>
						<input type="text" name="settings[sitemap]" id="sitemap" readonly value="{{ base_url }}/cache/sitemap.xml" />
						<div class="description">{{ __('You can ping the sitemap with the following links to') }} <a target="_blank" href="https://www.google.com/ping?sitemap={{ (base_url ~ '/cache/sitemap.xml')|url_encode }}">google</a> {{ __('and') }} <a target="_blank" href="http://www.bing.com/ping?sitemap={{ (base_url ~ '/cache/sitemap.xml')|url_encode }}">bing</a>.</div>
					</div><div class="medium{{ errors.settings.pingsitemap ? ' error' : '' }}">
						<label for="settings[pingsitemap]">{{ __('Ping sitemap automatically') }}</label>
						<label class="control-group">{{ __('Ping sitemap automatically after publishing a page.') }}
							<input name="settings[pingsitemap]" type="checkbox" {% if (settings.pingsitemap or old.settings.pingsitemap) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<hr>
					<header class="headline">
						<h2>{{ __('Media') }}</h2>
					</header>
					<div class="medium{{ errors.settings.logo ? ' error' : '' }}">
						<label for="settings[logo]">{{ __('Logo') }} <small>(jpg,jpeg,png,svg)</small></label>
						<div class="flex fileinput">
							<button class="deletefilebutton w-10 bg-tm-gray bn hover-bg-tm-red hover-white">x</button>
							<input class="deletefileinput" name="settings[deletelogo]" type="hidden" value="NULL" />
							<input class="visiblefilename w-60" type="text" disabled="disabled" value="{{ old.settings.logo ? old.settings.logo : settings.logo }}" placeholder="{{ __('CHOOSE_FILE') }}" />
							<div class="relative w-30 pv3 tc bg-tm-green white dim pointer">
	    						<span class="f7">{{ __('BROWSE') }}</span>
								<input class="upload hiddenfile" type="file" name="settings[logo]" value="{{ old.settings.logo ? old.settings.logo : settings.logo }}" />
							</div>
						</div>
						{% if errors.settings.logo %}
							<span class="error">{{ errors.settings.logo | first }}</span>
						{% endif %}
					</div><div class="medium{{ errors.settings.favicon ? ' error' : '' }}">
						<label for="settings[favicon]">{{ __('Favicon') }} <small>(png)</small></label>
						<div class="flex fileinput">
							<button class="deletefilebutton w-10 bg-tm-gray bn hover-bg-tm-red hover-white">x</button>
							<input class="deletefileinput" name="settings[deletefav]" type="hidden" value="NULL" />
							<input class="visiblefilename w-60" type="text" disabled="disabled" value="{{ old.settings.favicon ? old.settings.favicon : settings.favicon }}" placeholder="{{ __('CHOOSE_FILE') }}" />
							<div class="relative w-30 pv3 tc bg-tm-green white dim pointer">
	    						<span class="f7">{{ __('BROWSE') }}</span>
								<input class="upload hiddenfile" type="file" name="settings[favicon]" value="{{ old.settings.favicon ? old.settings.favicon : settings.favicon }}" />
							</div>
						</div>
						{% if errors.settings.favicon %}
							<span class="error">{{ errors.settings.favicon | first }}</span>
						{% endif %}
					</div>
					<div class="medium{{ errors.settings.images.live.width ? ' error' : '' }}">
						<label for="imagewidth">{{ __('Standard width for images') }}</label>
						<input type="text" name="settings[images][live][width]" id="imagewidth" value="{{ old.settings.images.live.width ? old.settings.images.live.width : settings.images.live.width }}" title="{{ __('Use a valid number') }}" />
						<div class="description">{{ __('This applies only for future images in the content area.') }}</div>
						{% if errors.settings.images.live.width %}
							<span class="error">{{ errors.settings.images.live.width | first }}</span>
						{% endif %}
					</div>
					<div class="medium{{ errors.settings.images.live.height ? ' error' : '' }}">
						<label for="imageheight">{{ __('Standard height for images') }}</label>
						<input type="text" name="settings[images][live][height]" id="imageheight" value="{{ old.settings.images.live.height ? old.settings.images.live.height : settings.images.live.height }}" title="{{ __('Use a valid number') }}" />
						<div class="description">{{ __('If you add a value for the height, then the image will be cropped.') }}</div>
						{% if errors.settings.images.live.height %}
							<span class="error">{{ errors.settings.images.live.height | first }}</span>
						{% endif %}
					</div>
					<div class="large{{ errors.settings.svg ? ' error' : '' }}">
						<label for="settings[svg]">{{ __('Upload svg images') }}</label>
						<label class="control-group">{{ __('Allow upload of svg images (on your own risk, has security implications)') }}
							<input name="settings[svg]" type="checkbox" {% if (settings.svg or old.settings.svg) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="medium{{ errors.settings.maxuploadsize ? ' error' : '' }}">
						<label for="maxuploadsize">{{ __('Maximum size for file-uploads in MB') }}</label>
						<input type="text" name="settings[maxuploadsize]" id="maxuploadsize" value="{{ old.settings.maxuploadsize ? old.settings.maxuploadsize : settings.maxuploadsize }}" title="{{ __('Use a valid number') }}" />
						<div class="description">{{ __('The maximum file size might be limited by your server settings.') }}</div>
						{% if errors.settings.maxuploadsize %}
							<span class="error">{{ errors.settings.maxuploadsize | first }}</span>
						{% endif %}
					</div>
					<hr>
					<header class="headline">
						<h2>{{ __('Writing') }}</h2>
					</header>
					<div class="medium{{ errors.settings.editor ? ' error' : '' }}">
						<label for="settings[editor]">{{ __('Standard Editor Mode') }} *</label>
						<label class="control-group">{{ __('Visual Markdown Editor') }}
							<input name="settings[editor]" value="visual" type="radio" {% if (old.settings.editor == "visual") or (settings.editor == "visual") %} checked {% endif %}>
							<span class="radiomark"></span>
						</label>
						<label class="control-group">{{ __('Raw Markdown Editor') }}
							<input name="settings[editor]" value="raw" type="radio" {% if (old.settings.editor == "raw") or (settings.editor == "raw") %} checked {% endif %}>
							<span class="radiomark"></span>
						</label>
						{% if errors.settings.editor %}
							<span class="error">{{ errors.settings.editor | first }}</span>
						{% endif %}
					</div>
					<div class="medium{{ errors.settings.editor ? ' error' : '' }}">
						<label>{{ __('Visual Editor') }}: {{ __('The Format Buttons') }}</label>
						{% for format in formats %}

							<label class="control-group">{{ __(format) }}
								<input name="settings[formats][]" value="{{ format }}" type="checkbox" {% if format in settings.formats %} checked {% endif %}>
								<span class="checkmark"></span>
							</label>

						{% endfor %}
					</div><div class="medium{{ errors.settings.headlineanchors ? ' error' : '' }}">
						<label for="settings[headlineanchors]">{{ __('Headline Anchors') }} *</label>
						<label class="control-group">{{ __('Show anchors next to headlines in frontend') }}
							<input name="settings[headlineanchors]" type="checkbox" {% if (settings.headlineanchors or old.settings.headlineanchors) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div><div class="large{{ errors.settings.urlschemes ? ' error' : '' }}">
						<label for="urlschemes">{{ __('Add more url schemes for external links e.g. like dict:// (comma separated list)') }}</label>
						<input type="text" name="settings[urlschemes]" id="urlschemes" placeholder="dict://" value="{{ old.settings.urlschemes ? old.settings.urlschemes : settings.urlschemes }}" title="{{ __('Comma separated list additional schemes') }}" />
						{% if errors.settings.urlschemes %}
							<span class="error">{{ errors.settings.urlschemes | first }}</span>
						{% endif %}
					</div>
					<hr>
					<header class="headline">
						<h2>{{ __('Access Control') }}</h2>
						<p>{{ __('Limit the access for the whole website or for each page individually. If you activate the website restriction or the page restrictions, then sessions will be used in frontend.') }}</p>
						<p>{{ __('New here? Then watch') }} <a class="link tm-red underline-hover" href="https://www.youtube.com/watch?v=7yvlwXJL9dc" target="_blank">{{ __('the video-tutorial') }}</a> {{ __('about configurations for typemill on YouTube.') }}</p>
					</header>
					<div class="large{{ errors.settings.access ? ' error' : '' }}">
						<label for="settings[access]">{{ __('Website Restriction') }}</label>
						<label class="control-group">{{ __('Show the website only to authenticated users and redirect all other users to the login page.') }}
							<input name="settings[access]" type="checkbox" {% if (settings.access or old.settings.access) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="large{{ errors.settings.pageaccess ? ' error' : '' }}">
						<label for="settings[pageaccess]">{{ __('Page Restrictions - Activate') }}</label>
						<label class="control-group">{{ __('Activate individual restrictions for pages in the meta-tab of each page.') }}
							<input name="settings[pageaccess]" type="checkbox" {% if (settings.pageaccess or old.settings.pageaccess) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="large{{ errors.settings.hrdelimiter ? ' error' : '' }}">
						<label for="settings[hrdelimiter]">{{ __('Page Restrictions - Cut Restricted Content') }}</label>
						<label class="control-group">{{ __('Cut restricted content after the first hr-element on a page (per default content will be cut after title).') }}
							<input name="settings[hrdelimiter]" type="checkbox" {% if (settings.hrdelimiter or old.settings.hrdelimiter) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="large{{ errors.settings.restrictionnotice ? ' error' : '' }}">
						<label for="settings[restrictionnotice]">{{ __('Page Restrictions - Notice') }} <small>({{ __('use markdown') }})</small></label>
						<textarea id="restrictionnotice" rows="8" name="settings[restrictionnotice]">{{ old.settings.restrictionnotice ? old.settings.restrictionnotice : settings.restrictionnotice }}</textarea>
						{% if errors.settings.restrictionnotice %}
							<span class="error">{{ errors.settings.restrictionnotice | first }}</span>
						{% endif %}
					</div>
					<div class="large{{ errors.settings.wraprestrictionnotice ? ' error' : '' }}">
						<label for="settings[wraprestrictionnotice]">{{ __('Page Restrictions - Wrap Notice into a Box') }}</label>
						<label class="control-group">{{ __('Wrap the restriction notice above into a notice-4 element (which can be designed as special box)') }}
							<input name="settings[wraprestrictionnotice]" type="checkbox" {% if (settings.wraprestrictionnotice or old.settings.wraprestrictionnotice) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<hr>
					<header class="headline">
						<h2>{{ __('Password Recovery') }}</h2>
						<p>{{ __('Activate the password recovery only if it is really needed. If possible use your password manager instead.') }}</p>
					</header>
					<div class="large{{ errors.settings.recoverpw ? ' error' : '' }}">
						<label for="settings[recoverpw]">{{ __('Recover Passwords') }}</label>
						<label class="control-group">{{ __('Activate the recover password function') }}
							<input name="settings[recoverpw]" type="checkbox" {% if (settings.recoverpw or old.settings.recoverpw) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div><div class="large{{ errors.settings.recoverfrom ? ' error' : '' }}">
						<label for="recoverfrom">{{ __('Sender email') }}</label>
						<input type="text" name="settings[recoverfrom]" id="recoverfrom" placeholder="your@email.com" value="{{ old.settings.recoverfrom ? old.settings.recoverfrom : settings.recoverfrom }}" />
						{% if errors.settings.recoverfrom %}
							<span class="error">{{ errors.settings.recoverfrom | first }}</span>
						{% endif %}
					</div>
					<div class="large{{ errors.settings.recoversubject ? ' error' : '' }}">
						<label for="recoversubject">{{ __('Subject') }}</label>
						<input type="text" name="settings[recoversubject]" id="recoversubject" placeholder="{{ __('Recover your password') }}" value="{{ old.settings.recoversubject ? old.settings.recoversubject : settings.recoversubject }}" />
						{% if errors.settings.recoversubject %}
							<span class="error">{{ errors.settings.recoversubject | first }}</span>
						{% endif %}
					</div>
					<div class="large{{ errors.settings.recovermessage ? ' error' : '' }}">
						<label for="settings[recovermessage]">{{ __('Text before the recover link in the email message') }} <small>({{ __('use markdown') }})</small></label>
						<textarea id="recovermessage" rows="8" name="settings[recovermessage]" placeholder="{{ __('Dear user,') }}&#10;&#10;{{ __('please use the following link to create a new password. The link is valid for 24 hours') }}">{{ old.settings.recovermessage ? old.settings.recovermessage : settings.recovermessage }}</textarea>
						{% if errors.settings.recovermessage %}
							<span class="error">{{ errors.settings.recovermessage | first }}</span>
						{% endif %}
					</div>
					<hr>
					<header class="headline">
						<h2>{{ __('Developer') }}</h2>
						<p>{{ __('The following options are only for developers') }}</p>
					</header>
					<div class="large{{ errors.settings.displayErrorDetails ? ' error' : '' }}">
						<label for="settings[displayErrorDetails]">{{ __('Error Reporting') }}</label>
						<label class="control-group">{{ __('Display Application Errors') }}
							<input name="settings[displayErrorDetails]" type="checkbox" {% if (settings.displayErrorDetails or old.settings.displayErrorDetails) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="large{{ errors.settings.securitylog ? ' error' : '' }}">
						<label for="settings[securitylog]">{{ __('Security Log') }}</label>
						<label class="control-group">{{ __('Create a logfile in the cache folder to track spam and suspicious actions') }}
							<input name="settings[securitylog]" type="checkbox" {% if (settings.securitylog or old.settings.securitylog) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="large{{ errors.settings.oldslug ? ' error' : '' }}">
						<label for="settings[oldslug]">{{ __('Old Slug Logic') }}</label>
						<label class="control-group">{{ __('Use the old logic from versions < 1.5.0 to create the slug') }}
							<input name="settings[oldslug]" type="checkbox" {% if (settings.oldslug or old.settings.oldslug) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="medium{{ errors.settings.twigcache ? ' error' : '' }}">
						<label for="settings[twigcache]">{{ __('Twig Cache') }}</label>
						<label class="control-group">{{ __('Activate Cache for Twig Templates') }}
							<input name="settings[twigcache]" type="checkbox" {% if (settings.twigcache or old.settings.twigcache) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="medium">
						<div class="label">{{ __('Recreate cached files') }}</div>
						<button id="clearcache" class="link bg-tm-green white dim bn br1 ph3 pv2 f6">{{ __('Recreate Cache') }}</button><div id="cacheresult" class="dib ph3 pv2"></div>
					</div>
					<div class="large{{ errors.settings.refreshcache ? ' error' : '' }}">
						<label for="settings[refreshcache]">{{ __('Refresh Cache') }}</label>
						<label class="control-group">{{ __('Refresh the cache after 10 minutes. Use this if you change content files manually e.g. with FTP.') }}
							<input name="settings[refreshcache]" type="checkbox" {% if (settings.refreshcache or old.settings.refreshcache) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="medium{{ errors.settings.proxy ? ' error' : '' }}">
						<label for="settings[proxy]">{{ __('Proxy') }}</label>
						<label class="control-group">{{ __('Use X-Forwarded Headers') }}
							<input name="settings[proxy]" type="checkbox" {% if (settings.proxy or old.settings.proxy) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="medium{{ errors.settings.trustedproxies ? ' error' : '' }}">
						<label for="trustedproxies">{{ __('Trusted IPs for proxy (comma separated)') }}</label>
						<input type="text" name="settings[trustedproxies]" id="trustedproxies" value="{{ old.settings.trustedproxies ? old.settings.trustedproxies : settings.trustedproxies }}" title="{{ __('Comma separated list of IPs') }}" />
						{% if errors.settings.trustedproxies %}
							<span class="error">{{ errors.settings.trustedproxies | first }}</span>
						{% endif %}
					</div>
					<div class="medium{{ errors.settings.headersoff ? ' error' : '' }}">
						<label for="settings[headersoff]">{{ __('Disable Headers') }}</label>
						<label class="control-group">{{ __('Disable Typemill Headers And Send Your Own') }}
							<input name="settings[headersoff]" type="checkbox" {% if (settings.headersoff or old.settings.headersoff) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
					<div class="large{{ errors.settings.schemelessbaseurl ? ' error' : '' }}">
						<label for="settings[schemelessbaseurl]">{{ __('Schemeless Base Url') }}</label>
						<label class="control-group">{{ __('Remove scheme (i.e., HTTP or HTTPS) when addressing resources') }}
							<input name="settings[schemelessbaseurl]" type="checkbox" {% if (settings.schemelessbaseurl or old.settings.schemelessbaseurl) %} checked {% endif %}>
							<span class="checkmark"></span>
						</label>
					</div>
				</fieldset>
			</section>
			<input type="submit" value="{{ __('Save All Settings') }}" />

			{{ csrf_field() | raw }}
			
		</form>
	
	</div>
{% endblock %}
