Refactored form rendering

This commit is contained in:
Marcin Kurczewski 2014-05-20 17:03:47 +02:00
parent 0947858ffc
commit 65e909d053
20 changed files with 443 additions and 420 deletions

View file

@ -14,7 +14,7 @@ $(function()
var formDom = $('form.edit-post');
if (formDom.find('.tagit').length == 0)
{
attachTagIt($('.tags input'));
attachTagIt($('input[name=tags]'));
aDom.removeClass('inactive');
formDom.find('input[type=text]:visible:eq(0)').focus();

View file

@ -85,8 +85,8 @@ class TagController extends AbstractController
Api::run(
new MergeTagsJob(),
[
JobArgs::ARG_SOURCE_TAG_NAME => InputHelper::get('source-tag'),
JobArgs::ARG_TARGET_TAG_NAME => InputHelper::get('target-tag'),
JobArgs::ARG_SOURCE_TAG_NAME => trim(InputHelper::get('source-tag')),
JobArgs::ARG_TARGET_TAG_NAME => trim(InputHelper::get('target-tag')),
]);
Messenger::success('Tags merged successfully.');
@ -111,8 +111,8 @@ class TagController extends AbstractController
Api::run(
new RenameTagsJob(),
[
JobArgs::ARG_SOURCE_TAG_NAME => InputHelper::get('source-tag'),
JobArgs::ARG_TARGET_TAG_NAME => InputHelper::get('target-tag'),
JobArgs::ARG_SOURCE_TAG_NAME => trim(InputHelper::get('source-tag')),
JobArgs::ARG_TARGET_TAG_NAME => trim(InputHelper::get('target-tag')),
]);
Messenger::success('Tag renamed successfully.');

View file

@ -12,10 +12,10 @@ class View extends \Chibi\View
$view->render();
}
protected function renderExternal($viewName)
protected function renderExternal($viewName, $context = null)
{
$view = new View($viewName);
$view->context = $this->context;
$view->context = $context !== null ? $context : $this->context;
$view->assets = $this->assets;
$view->render();
}

View file

@ -14,15 +14,17 @@ $this->assets->addStylesheet('auth.css');
<a href="<?= \Chibi\Router::linkTo(['UserController', 'registrationView']); ?>">click here</a> to create a new one.
</p>
<div class="form-row">
<label for="name">User name:</label>
<div class="input-wrapper"><input type="text" id="name" name="name"/></div>
</div>
<?php
$context = new StdClass;
$context->name = 'name';
$context->label = 'User name';
$this->renderExternal('input-text', $context);
<div class="form-row">
<label for="password">Password:</label>
<div class="input-wrapper"><input type="password" id="password" name="password"/></div>
</div>
$context = new StdClass;
$context->name = 'password';
$context->label = 'Password';
$this->renderExternal('input-password', $context);
?>
<div class="form-row">
<label></label>

View file

@ -0,0 +1,36 @@
<?php
$id = uniqid();
$type = $this->context->type;
$name = $this->context->name;
$label = isset($this->context->label) ? $this->context->label . ':' : '';
$value = isset($this->context->value) ? $this->context->value : '';
$placeholder = isset($this->context->placeholder) ? $this->context->placeholder : '';
$additionalInfo = isset($this->context->additionalInfo) ? $this->context->additionalInfo : '';
$inputClass = isset($this->context->inputClass) ? $this->context->inputClass : '';
$noAutocomplete = isset($this->context->noAutocomplete) ? true : false;
?>
<div class="form-row">
<label for="<?= $id ?>">
<?= $label ?>
</label>
<div class="input-wrapper">
<input
<?php if ($noAutocomplete): ?>
autocomplete="off"
<?php endif ?>
<?php if ($inputClass != ''): ?>
class="<?= $inputClass ?>"
<?php endif ?>
type="<?= $type ?>"
name="<?= $name ?>"
id="<?= $id ?>"
placeholder="<?= $placeholder ?>"
value="<?= $value ?>"/>
<?php if ($additionalInfo): ?>
<small><?= $additionalInfo ?></small>
<?php endif ?>
</div>
</div>

View file

@ -0,0 +1,38 @@
<?php
$id = uniqid();
$label = isset($this->context->label) ? $this->context->label . ':' : '';
$optionValuesDisabled = $this->context->optionValuesDisabled;
$optionValuesEnabled = $this->context->optionValuesEnabled;
$optionLabels = $this->context->optionLabels;
$optionNames = $this->context->optionNames;
$optionStates = $this->context->optionStates;
$keys = array_keys($optionNames);
?>
<div class="form-row">
<label for="<?= $id ?>">
<?= $label ?>
</label>
<div class="input-wrapper">
<?php foreach ($keys as $key): ?>
<input type="hidden"
name="<?= $optionNames[$key] ?>"
value="<?= $optionValuesDisabled[$key] ?>"/>
<label>
<input type="checkbox"
name="<?= $optionNames[$key] ?>"
<?php if (count($keys) == 1): ?>
id="<?= $id ?>"
<?php endif ?>
<?php if ($optionStates[$key]): ?>
checked="checked"
<?php endif ?>
value="<?= $optionValuesEnabled[$key] ?>"/>
<?= $optionLabels[$key] ?>
</label>
<?php endforeach ?>
</div>
</div>

View file

@ -0,0 +1,3 @@
<?php
$this->context->type = 'file';
$this->renderExternal('input-basic', $this->context);

View file

@ -0,0 +1,6 @@
<?php
$name = $this->context->name;
$value = $this->context->value;
?>
<input type="hidden" name="<?= $name ?>" value="<?= $value ?>"/>

View file

@ -0,0 +1,3 @@
<?php
$this->context->type = 'password';
$this->renderExternal('input-basic', $this->context);

View file

@ -0,0 +1,33 @@
<?php
$id = uniqid();
$name = $this->context->name;
$label = isset($this->context->label) ? $this->context->label . ':' : '';
$optionValues = $this->context->optionValues;
$optionLabels = $this->context->optionLabels;
$activeOptionValue = $this->context->activeOptionValue;
$keys = array_keys($optionValues);
?>
<div class="form-row">
<label for="<?= $id ?>">
<?= $label ?>
</label>
<div class="input-wrapper">
<?php foreach ($keys as $key): ?>
<label>
<input type="radio"
name="<?= $name ?>"
<?php if (count($keys) == 1): ?>
id="<?= $id ?>"
<?php endif ?>
<?php if ($optionValues[$key] == $activeOptionValue): ?>
checked="checked"
<?php endif ?>
value="<?= $optionValues[$key] ?>"/>
<?= $optionLabels[$key] ?>
</label>
<?php endforeach ?>
</div>
</div>

View file

@ -0,0 +1,28 @@
<?php
$id = uniqid();
$name = $this->context->name;
$label = isset($this->context->label) ? $this->context->label . ':' : '';
$optionValues = $this->context->optionValues;
$optionLabels = $this->context->optionLabels;
$activeOptionValue = isset($this->context->activeOptionValue) ? $this->context->activeOptionValue : null;
$keys = array_keys($optionValues);
?>
<div class="form-row">
<label for="<?= $id ?>">
<?= $label ?>
</label>
<div class="input-wrapper">
<select name="<?= $name ?>" id="<?= $id ?>">
<?php foreach ($keys as $key): ?>
<?php if ($activeOptionValue == $optionValues[$key]): ?>
<option value="<?= $optionValues[$key] ?>" selected="selected">
<?php else: ?>
<option value="<?= $optionValues[$key] ?>">
<?php endif ?>
<?= $optionLabels[$key] ?>
</option>
<?php endforeach ?>
</select>
</div>
</div>

View file

@ -0,0 +1,3 @@
<?php
$this->context->type = 'text';
$this->renderExternal('input-basic', $this->context);

View file

@ -12,112 +12,94 @@
id="edit-token"
value="<?= htmlspecialchars($this->context->transport->post->getEditToken()) ?>"/>
<?php if (Access::check(new Privilege(
Privilege::EditPostSafety,
Access::getIdentity($this->context->transport->post->getUploader())))): ?>
<?php
if (Access::check(new Privilege(
Privilege::EditPostSafety,
Access::getIdentity($this->context->transport->post->getUploader()))))
{
$safety = PostSafety::getAll();
<div class="form-row safety">
<label>Safety:</label>
<div class="input-wrapper">
<?php foreach (PostSafety::getAll() as $safety): ?>
<label>
<input type="radio"
name="safety"
<?php if ($this->context->transport->post->getSafety() == $safety): ?>
checked="checked"
<?php endif ?>
value="<?= $safety->toInteger() ?>"/>
&nbsp;<?= ucfirst($safety->toDisplayString()) ?>
</label>
<?php endforeach ?>
</div>
</div>
<?php endif ?>
$context = new StdClass;
$context->label = 'Safety';
$context->name = 'safety';
$context->optionValues = array_map(function($s) { return $s->toInteger(); }, $safety);
$context->optionLabels = array_map(function($s) { return ucfirst($s->toDisplayString()); }, $safety);
$context->activeOptionValue = $this->context->transport->post->getSafety()->toInteger();
$this->renderExternal('input-radioboxes', $context);
}
<?php if (Access::check(new Privilege(
Privilege::EditPostTags,
Access::getIdentity($this->context->transport->post->getUploader())))): ?>
if (Access::check(new Privilege(
Privilege::EditPostTags,
Access::getIdentity($this->context->transport->post->getUploader()))))
{
$context = new StdClass;
$context->label = 'Tags';
$context->name = 'tags';
$context->placeholder = 'Enter some tags&hellip;';
$context->value = join(',', array_map(
function($tag)
{
return htmlspecialchars($tag->getName());
},
$this->context->transport->post->getTags()));
$this->renderExternal('input-text', $context);
}
<div class="form-row tags">
<label for="tags">Tags:</label>
<div class="input-wrapper">
<input type="text"
name="tags"
id="tags"
placeholder="enter some tags&hellip;"
value="<?= join(',', array_map(function($tag) {
return htmlspecialchars($tag->getName());
}, $this->context->transport->post->getTags())) ?>"/>
</div>
</div>
<?php endif ?>
if (Access::check(new Privilege(
Privilege::EditPostSource,
Access::getIdentity($this->context->transport->post->getUploader()))))
{
$context = new StdClass;
$context->label = 'Source';
$context->name = 'source';
$context->value = htmlspecialchars($this->context->transport->post->getSource());
$this->renderExternal('input-text', $context);
}
<?php if (Access::check(new Privilege(
Privilege::EditPostSource,
Access::getIdentity($this->context->transport->post->getUploader())))): ?>
if (Access::check(new Privilege(
Privilege::EditPostRelations,
Access::getIdentity($this->context->transport->post->getUploader()))))
{
$context = new StdClass;
$context->label = 'Relations';
$context->name = 'relations';
$context->placeholder = 'id1,id2,&hellip;';
$context->value = join(',', array_map(
function($post)
{
return $post->getId();
},
$this->context->transport->post->getRelations()));
$this->renderExternal('input-text', $context);
}
<div class="form-row source">
<label for="source">Source:</label>
<div class="input-wrapper">
<input type="text"
name="source"
id="source"
value="<?= htmlspecialchars($this->context->transport->post->getSource()) ?>"/>
</div>
</div>
<?php endif ?>
if (Access::check(new Privilege(
Privilege::EditPostContent,
Access::getIdentity($this->context->transport->post->getUploader()))))
{
$context = new StdClass;
$context->label = 'File';
$context->name = 'url';
$context->placeholder = 'Some URL&hellip;';
$this->renderExternal('input-text', $context);
<?php if (Access::check(new Privilege(
Privilege::EditPostRelations,
Access::getIdentity($this->context->transport->post->getUploader())))): ?>
$context = new StdClass;
$context->name = 'file';
$this->renderExternal('input-file', $context);
}
<div class="form-row thumb">
<label for="relations">Relations:</label>
<div class="input-wrapper">
<input type="text"
name="relations"
id="relations"
placeholder="id1,id2,&hellip;"
value="<?= join(',', array_map(function($post) {
return $post->getId();
}, $this->context->transport->post->getRelations())) ?>"/>
</div>
</div>
<?php endif ?>
<?php if (Access::check(new Privilege(
Privilege::EditPostContent,
Access::getIdentity($this->context->transport->post->getUploader())))): ?>
<div class="form-row url">
<label for="url">File:</label>
<div class="input-wrapper">
<input type="text" name="url" id="url" placeholder="Some url&hellip;"/>
</div>
</div>
<div class="form-row file">
<label for="file"></label>
<div class="input-wrapper">
<input type="file" name="file" id="file"/>
</div>
</div>
<?php endif ?>
<?php if (Access::check(new Privilege(
Privilege::EditPostThumb,
Access::getIdentity($this->context->transport->post->getUploader())))): ?>
<div class="form-row thumb">
<label for="thumb">Thumb:</label>
<div class="input-wrapper">
<input type="file" name="thumb" id="thumb"/>
<?php if ($this->context->transport->post->hasCustomThumb()): ?>
<small>(Currently using custom thumb)</small>
<?php endif ?>
</div>
</div>
<?php endif ?>
if (Access::check(new Privilege(
Privilege::EditPostThumb,
Access::getIdentity($this->context->transport->post->getUploader()))))
{
$context = new StdClass;
$context->name = 'thumb';
$context->label = 'Thumb';
if ($this->context->transport->post->hasCustomThumb())
$context->additionalInfo = '(Currently using custom thumb)';
$this->renderExternal('input-file', $context);
}
?>
<div class="form-row">
<label></label>

View file

@ -4,47 +4,41 @@
['source' => 'mass-tag']) ?>">
<h1>mass tag</h1>
<div class="form-row">
<label for="mass-tag-query">Search query:</label>
<div class="input-wrapper">
<input
class="autocomplete"
type="text"
name="query"
id="mass-tag-query"
value="<?= isset($this->context->massTagQuery)
? htmlspecialchars($this->context->massTagQuery)
: '' ?>"/>
</div>
</div>
<?php
$context = new StdClass;
$context->name = 'query';
$context->label = 'Search query';
$context->inputClass = 'autocomplete';
if (isset($this->context->massTagQuery))
$context->value = htmlspecialchars($this->context->massTagQuery);
$this->renderExternal('input-text', $context);
?>
<div class="form-row">
<label for="mass-tag-tag">Tag:</label>
<div class="input-wrapper">
<input
class="autocomplete"
type="text"
name="tag"
id="mass-tag-tag"
value="<?= isset($this->context->massTagTag)
? htmlspecialchars($this->context->massTagTag)
: '' ?>"/>
</div>
</div>
<?php
$context = new StdClass;
$context->name = 'tag';
$context->label = 'Tag';
$context->inputClass = 'autocomplete';
if (isset($this->context->massTagTag))
$context->value = htmlspecialchars($this->context->massTagTag);
$this->renderExternal('input-text', $context);
<input
type="hidden"
name="old-page"
value="<?= isset($this->context->transport->paginator)
? htmlspecialchars($this->context->transport->paginator->page)
: '' ?>"/>
if (isset($this->context->transport->paginator))
{
$context = new StdClass;
$context->name = 'old-page';
$context->value = intval($this->context->transport->paginator->page);
$this->renderExternal('input-hidden', $context);
}
<input
type="hidden"
name="old-query"
value="<?= isset($this->context->massTagQuery)
? htmlspecialchars($this->context->massTagQuery)
: '' ?>"/>
if (isset($this->context->massTagQuery))
{
$context = new StdClass;
$context->name = 'old-query';
$context->value = htmlspecialchars($this->context->massTagQuery);
$this->renderExternal('input-hidden', $context);
}
?>
<div class="form-row">
<label></label>

View file

@ -2,21 +2,20 @@
<form method="post" action="<?= \Chibi\Router::linkTo(['TagController', 'mergeAction']) ?>">
<h1>merge tags</h1>
<div class="form-row">
<label for="merge-source-tag">Source tag:</label>
<div class="input-wrapper">
<input class="autocomplete" type="text" name="source-tag" id="merge-source-tag"/>
</div>
</div>
<?php
$context = new StdClass;
$context->name = 'source-tag';
$context->label = 'Source tag';
$context->inputClass = 'autocomplete';
$this->renderExternal('input-text', $context);
<div class="form-row">
<label for="merge-target-tag">Target tag:</label>
<div class="input-wrapper">
<input class="autocomplete" type="text" name="target-tag" id="merge-target-tag"/>
</div>
</div>
$context = new StdClass;
$context->name = 'target-tag';
$context->label = 'Target tag';
$this->renderExternal('input-text', $context);
<?php $this->renderExternal('message') ?>
$this->renderExternal('message');
?>
<div class="form-row">
<label></label>

View file

@ -2,21 +2,20 @@
<form method="post" action="<?= \Chibi\Router::linkTo(['TagController', 'renameAction']) ?>">
<h1>rename tags</h1>
<div class="form-row">
<label for="rename-source-tag">Source tag:</label>
<div class="input-wrapper">
<input class="autocomplete" type="text" name="source-tag" id="rename-source-tag"/>
</div>
</div>
<?php
$context = new StdClass;
$context->name = 'source-tag';
$context->label = 'Source tag';
$context->inputClass = 'autocomplete';
$this->renderExternal('input-text', $context);
<div class="form-row">
<label for="rename-target-tag">Target tag:</label>
<div class="input-wrapper">
<input type="text" name="target-tag" id="rename-target-tag"/>
</div>
</div>
$context = new StdClass;
$context->name = 'target-tag';
$context->label = 'Target tag';
$this->renderExternal('input-text', $context);
<?php $this->renderExternal('message') ?>
$this->renderExternal('message');
?>
<div class="form-row">
<label></label>

View file

@ -7,14 +7,16 @@
autocomplete="off"
data-confirm-text="Are you sure you want to delete your account?">
<?php if (Auth::getCurrentUser()->getId() == $this->context->transport->user->getId()): ?>
<div class="form-row current-password">
<label for="current-password">Current password:</label>
<div class="input-wrapper">
<input type="password" name="current-password" id="current-password" placeholder="Current password"/>
</div>
</div>
<?php endif ?>
<?php
if (Auth::getCurrentUser()->getId() == $this->context->transport->user->getId())
{
$context = new StdClass;
$context->label = 'Current password';
$context->name = 'current-password';
$context->placeholder = 'Current password';
$this->renderExternal('input-password', $context);
}
?>
<?php $this->renderExternal('message') ?>

View file

@ -6,108 +6,83 @@
class="edit"
autocomplete="off">
<?php if (Auth::getCurrentUser()->getId() == $this->context->transport->user->getId()): ?>
<div class="form-row current-password">
<label for="current-password">Current password:</label>
<div class="input-wrapper">
<input
type="password"
name="current-password"
id="current-password"
placeholder="Current password"/>
</div>
</div>
<hr>
<?php endif ?>
<?php
if (Auth::getCurrentUser()->getId() == $this->context->transport->user->getId())
{
$context = new StdClass;
$context->label = 'Current password';
$context->name = 'current-password';
$context->placeholder = 'Current password';
$this->renderExternal('input-password', $context);
echo '<hr/>';
}
<?php if (Access::check(new Privilege(
Privilege::EditUserName,
Access::getIdentity($this->context->transport->user)))): ?>
if (Access::check(new Privilege(
Privilege::EditUserName,
Access::getIdentity($this->context->transport->user))))
{
$context = new StdClass;
$context->label = 'Name';
$context->name = 'name';
$context->placeholder = 'New name&hellip;';
$context->value = htmlspecialchars(InputHelper::get('name'));
$this->renderExternal('input-text', $context);
}
<div class="form-row nickname">
<label for="name">Name:</label>
<div class="input-wrapper">
<input
type="text"
name="name"
id="name"
placeholder="New name&hellip;"
value="<?= htmlspecialchars(InputHelper::get('name')) ?>">
</div>
</div>
<?php endif ?>
if (Access::check(new Privilege(
Privilege::EditUserEmail,
Access::getIdentity($this->context->transport->user))))
{
$context = new StdClass;
$context->label = 'E-mail';
$context->name = 'email';
$context->placeholder = 'New e-mail&hellip;';
$context->value = htmlspecialchars(InputHelper::get('email'));
$this->renderExternal('input-text', $context);
}
<?php if (Access::check(new Privilege(
Privilege::EditUserEmail,
Access::getIdentity($this->context->transport->user)))): ?>
if (Access::check(new Privilege(
Privilege::EditUserPassword,
Access::getIdentity($this->context->transport->user))))
{
$context = new StdClass;
$context->label = 'New password';
$context->name = 'password1';
$context->placeholder = 'New password&hellip;';
$context->value = htmlspecialchars(InputHelper::get('password1'));
$this->renderExternal('input-password', $context);
<div class="form-row email">
<label for="name">E-mail:</label>
<div class="input-wrapper">
<input
type="text"
name="email"
id="email"
placeholder="New e-mail&hellip;"
value="<?= htmlspecialchars(InputHelper::get('email')) ?>"/>
</div>
</div>
<?php endif ?>
$context = new StdClass;
$context->name = 'password2';
$context->placeholder = 'New password&hellip; (repeat)';
$context->value = htmlspecialchars(InputHelper::get('password2'));
$this->renderExternal('input-password', $context);
}
<?php if (Access::check(new Privilege(
Privilege::EditUserPassword,
Access::getIdentity($this->context->transport->user)))): ?>
if (Access::check(new Privilege(
Privilege::EditUserAccessRank,
Access::getIdentity($this->context->transport->user))))
{
$accessRanks = array_filter(
AccessRank::getAll(),
function($ar)
{
return $ar->toInteger() != AccessRank::Nobody;
});
<div class="form-row password1">
<label for="password1">New password:</label>
<div class="input-wrapper">
<input
type="password"
name="password1"
id="password1"
placeholder="New password&hellip;"
value="<?= htmlspecialchars(InputHelper::get('password1')) ?>"/>
</div>
</div>
<div class="form-row password2">
<label for="password2"></label>
<div class="input-wrapper">
<input
type="password"
name="password2"
id="password2"
placeholder="New password&hellip; (repeat)"
value="<?= htmlspecialchars(InputHelper::get('password2')) ?>"/>
</div>
</div>
<?php endif ?>
$context = new StdClass;
$context->name = 'access-rank';
$context->label = 'Access rank';
$context->placeholder = 'New password&hellip; (repeat)';
$context->optionValues = array_map(function($ar) { return $ar->toInteger(); }, $accessRanks);
$context->optionLabels = array_map(function($ar) { return $ar->toDisplayString(); }, $accessRanks);
$context->activeOptionValue = InputHelper::get('access-rank')
?: $this->context->transport->user->getAccessRank()->toInteger();
$this->renderExternal('input-select', $context);
}
<?php if (Access::check(new Privilege(
Privilege::EditUserAccessRank,
Access::getIdentity($this->context->transport->user)))): ?>
<div class="form-row access-rank">
<label for="access-rank">Access rank:</label>
<div class="input-wrapper">
<select name="access-rank" id="access-rank">
<?php foreach (AccessRank::getAll() as $rank): ?>
<?php if ($rank->toInteger() == AccessRank::Nobody) continue ?>
<?php if ($rank->toInteger() == InputHelper::get('access-rank')
or (!InputHelper::get('access-rank') and
$rank == $this->context->transport->user->getAccessRank())): ?>
<option value="<?= $rank->toInteger() ?>" selected="selected">
<?php else: ?>
<option value="<?= $rank->toInteger() ?>">
<?php endif ?>
<?= $rank->toDisplayString() ?>
</option>
<?php endforeach ?>
</select>
</div>
</div>
<?php endif ?>
<?php $this->renderExternal('message') ?>
$this->renderExternal('message');
?>
<div class="form-row">
<label></label>

View file

@ -16,56 +16,36 @@ $this->assets->setSubTitle('registration form');
<p>Registered users can view more content,<br/>upload files and add posts to favorites.</p>
<div class="form-row">
<label for="name">User name:</label>
<div class="input-wrapper">
<input
type="text"
id="name"
name="name"
value="<?= htmlspecialchars(InputHelper::get('name')) ?>"
placeholder="e.g. darth_vader"
autocomplete="off"/>
</div>
</div>
<?php
$context = new StdClass;
$context->name = 'name';
$context->label = 'User name';
$context->value = htmlspecialchars(InputHelper::get('name'));
$context->placeholder = 'e.g. darth_vader';
$context->noAutocomplete = true;
$this->renderExternal('input-text', $context);
<div class="form-row">
<label for="password1">Password:</label>
<div class="input-wrapper">
<input
type="password"
id="password1"
name="password1"
value="<?= htmlspecialchars(InputHelper::get('password1')) ?>"
placeholder="e.g. <?= str_repeat('&#x25cf;', 8) ?>"
autocomplete="off"/>
</div>
</div>
$context = new StdClass;
$context->name = 'password1';
$context->label = 'Password';
$context->value = htmlspecialchars(InputHelper::get('password1'));
$context->placeholder = 'e.g. ' . str_repeat('&#x25cf;', 8);
$context->noAutocomplete = true;
$this->renderExternal('input-password', $context);
<div class="form-row">
<label for="password2">Password (repeat):</label>
<div class="input-wrapper">
<input
type="password"
id="password2"
name="password2"
value="<?= htmlspecialchars(InputHelper::get('password2')) ?>"
placeholder="e.g. <?= str_repeat('&#x25cf;', 8) ?>"
autocomplete="off"/>
</div>
</div>
$context->name = 'password2';
$context->label = 'Password (repeat)';
$context->value = htmlspecialchars(InputHelper::get('password2'));
$this->renderExternal('input-password', $context);
<div class="form-row">
<label for="email">E-mail address:</label>
<div class="input-wrapper">
<input
type="text"
id="email"
name="email"
value="<?= htmlspecialchars(InputHelper::get('email')) ?>"
placeholder="e.g. vader@empire.gov" autocomplete="off"/>
</div>
</div>
$context = new StdClass;
$context->name = 'email';
$context->label = 'E-mail address';
$context->value = htmlspecialchars(InputHelper::get('email'));
$context->placeholder = 'e.g. vader@empire.gov';
$context->noAutocomplete = true;
$this->renderExternal('input-text', $context);
?>
<p id="email-info">
Your e-mail will be used to show your <a href="http://gravatar.com/">Gravatar</a>.<br/>

View file

@ -9,103 +9,43 @@ $settings = $this->context->transport->user->getSettings();
method="post"
class="settings">
<div class="form-row safety">
<label>Safety:</label>
<div class="input-wrapper">
<?php foreach (PostSafety::getAll() as $safety): ?>
<?php if (Access::check(new Privilege(
Privilege::ListPosts,
$safety->toString()))): ?>
<label>
<?php
$attrs = [];
$attrs['type'] = 'checkbox';
$attrs['name'] = 'safety[]';
$attrs['value'] = $safety->toInteger();
if ($settings->hasEnabledSafety($safety))
$attrs['checked'] = 'checked';
<?php
$safety = array_filter(
PostSafety::getAll(),
function($s)
{
return Access::check(new Privilege(Privilege::ListPosts, $s->toString()));
});
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
<?= ucfirst($safety->toDisplayString()) ?>
</label>
<?php endif ?>
<?php endforeach ?>
</div>
</div>
$context = new StdClass;
$context->label = 'Safety';
$context->optionValuesDisabled = array_map(function($s) { return null; }, $safety);
$context->optionValuesEnabled = array_map(function($s) { return $s->toInteger(); }, $safety);
$context->optionLabels = array_map(function($s) { return ucfirst($s->toDisplayString()); }, $safety);
$context->optionNames = array_map(function($s) { return 'safety[]'; }, $safety);
$context->optionStates = array_map(function($s) use ($settings) { return $settings->hasEnabledSafety($s); }, $safety);
$this->renderExternal('input-checkboxes', $context);
<div class="form-row endless-scrolling">
<label for="endless-scrolling">Endless scrolling:</label>
<div class="input-wrapper">
<?php
$attrs = [];
$attrs['name'] = 'endless-scrolling';
$attrs['type'] = 'hidden';
$attrs['value'] = '0';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
<label>
<?php
$context = new StdClass;
$context->optionValuesDisabled = ['0'];
$context->optionValuesEnabled = ['1'];
$context->optionLabels = ['Enabled'];
$attrs['type'] = 'checkbox';
$attrs['value'] = '1';
$attrs['id'] = 'endless-scrolling';
if ($settings->hasEnabledEndlessScrolling())
$attrs['checked'] = 'checked';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
Enabled
</label>
</div>
</div>
$context->label = 'Endless scrolling';
$context->optionNames = ['endless-scrolling'];
$context->optionStates = [$settings->hasEnabledEndlessScrolling()];
$this->renderExternal('input-checkboxes', $context);
<div class="form-row post-tag-titles">
<label for="post-tag-titles">Tags in thumbs:</label>
<div class="input-wrapper">
<?php
$attrs = [];
$attrs['name'] = 'post-tag-titles';
$attrs['type'] = 'hidden';
$attrs['value'] = '0';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
<label>
<?php
$attrs['type'] = 'checkbox';
$attrs['value'] = '1';
$attrs['id'] = 'post-tag-titles';
if ($settings->hasEnabledPostTagTitles())
$attrs['checked'] = 'checked';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
Enabled
</label>
</div>
</div>
$context->label = 'Tags in thumbs';
$context->optionNames = ['post-tag-titles'];
$context->optionStates = [$settings->hasEnabledPostTagTitles()];
$this->renderExternal('input-checkboxes', $context);
<div class="form-row hide-disliked-posts">
<label for="hide-disliked-posts">Hide down-voted:</label>
<div class="input-wrapper">
<?php
$attrs = [];
$attrs['name'] = 'hide-disliked-posts';
$attrs['type'] = 'hidden';
$attrs['value'] = '0';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
<label>
<?php
$attrs['type'] = 'checkbox';
$attrs['value'] = '1';
$attrs['id'] = 'hide-disliked-posts';
if ($settings->hasEnabledHidingDislikedPosts())
$attrs['checked'] = 'checked';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
Enabled
</label>
</div>
</div>
$context->label = 'Hide down-voted';
$context->optionNames = ['hide-disliked-posts'];
$context->optionStates = [$settings->hasEnabledHidingDislikedPosts()];
$this->renderExternal('input-checkboxes', $context);
?>
<?php $this->renderExternal('message') ?>