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'); var formDom = $('form.edit-post');
if (formDom.find('.tagit').length == 0) if (formDom.find('.tagit').length == 0)
{ {
attachTagIt($('.tags input')); attachTagIt($('input[name=tags]'));
aDom.removeClass('inactive'); aDom.removeClass('inactive');
formDom.find('input[type=text]:visible:eq(0)').focus(); formDom.find('input[type=text]:visible:eq(0)').focus();

View file

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

View file

@ -12,10 +12,10 @@ class View extends \Chibi\View
$view->render(); $view->render();
} }
protected function renderExternal($viewName) protected function renderExternal($viewName, $context = null)
{ {
$view = new View($viewName); $view = new View($viewName);
$view->context = $this->context; $view->context = $context !== null ? $context : $this->context;
$view->assets = $this->assets; $view->assets = $this->assets;
$view->render(); $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. <a href="<?= \Chibi\Router::linkTo(['UserController', 'registrationView']); ?>">click here</a> to create a new one.
</p> </p>
<div class="form-row"> <?php
<label for="name">User name:</label> $context = new StdClass;
<div class="input-wrapper"><input type="text" id="name" name="name"/></div> $context->name = 'name';
</div> $context->label = 'User name';
$this->renderExternal('input-text', $context);
<div class="form-row"> $context = new StdClass;
<label for="password">Password:</label> $context->name = 'password';
<div class="input-wrapper"><input type="password" id="password" name="password"/></div> $context->label = 'Password';
</div> $this->renderExternal('input-password', $context);
?>
<div class="form-row"> <div class="form-row">
<label></label> <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" id="edit-token"
value="<?= htmlspecialchars($this->context->transport->post->getEditToken()) ?>"/> value="<?= htmlspecialchars($this->context->transport->post->getEditToken()) ?>"/>
<?php if (Access::check(new Privilege( <?php
Privilege::EditPostSafety, if (Access::check(new Privilege(
Access::getIdentity($this->context->transport->post->getUploader())))): ?> Privilege::EditPostSafety,
Access::getIdentity($this->context->transport->post->getUploader()))))
{
$safety = PostSafety::getAll();
<div class="form-row safety"> $context = new StdClass;
<label>Safety:</label> $context->label = 'Safety';
<div class="input-wrapper"> $context->name = 'safety';
<?php foreach (PostSafety::getAll() as $safety): ?> $context->optionValues = array_map(function($s) { return $s->toInteger(); }, $safety);
<label> $context->optionLabels = array_map(function($s) { return ucfirst($s->toDisplayString()); }, $safety);
<input type="radio" $context->activeOptionValue = $this->context->transport->post->getSafety()->toInteger();
name="safety" $this->renderExternal('input-radioboxes', $context);
<?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 ?>
<?php if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditPostTags, Privilege::EditPostTags,
Access::getIdentity($this->context->transport->post->getUploader())))): ?> 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"> if (Access::check(new Privilege(
<label for="tags">Tags:</label> Privilege::EditPostSource,
<div class="input-wrapper"> Access::getIdentity($this->context->transport->post->getUploader()))))
<input type="text" {
name="tags" $context = new StdClass;
id="tags" $context->label = 'Source';
placeholder="enter some tags&hellip;" $context->name = 'source';
value="<?= join(',', array_map(function($tag) { $context->value = htmlspecialchars($this->context->transport->post->getSource());
return htmlspecialchars($tag->getName()); $this->renderExternal('input-text', $context);
}, $this->context->transport->post->getTags())) ?>"/> }
</div>
</div>
<?php endif ?>
<?php if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditPostSource, Privilege::EditPostRelations,
Access::getIdentity($this->context->transport->post->getUploader())))): ?> 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"> if (Access::check(new Privilege(
<label for="source">Source:</label> Privilege::EditPostContent,
<div class="input-wrapper"> Access::getIdentity($this->context->transport->post->getUploader()))))
<input type="text" {
name="source" $context = new StdClass;
id="source" $context->label = 'File';
value="<?= htmlspecialchars($this->context->transport->post->getSource()) ?>"/> $context->name = 'url';
</div> $context->placeholder = 'Some URL&hellip;';
</div> $this->renderExternal('input-text', $context);
<?php endif ?>
<?php if (Access::check(new Privilege( $context = new StdClass;
Privilege::EditPostRelations, $context->name = 'file';
Access::getIdentity($this->context->transport->post->getUploader())))): ?> $this->renderExternal('input-file', $context);
}
<div class="form-row thumb"> if (Access::check(new Privilege(
<label for="relations">Relations:</label> Privilege::EditPostThumb,
<div class="input-wrapper"> Access::getIdentity($this->context->transport->post->getUploader()))))
<input type="text" {
name="relations" $context = new StdClass;
id="relations" $context->name = 'thumb';
placeholder="id1,id2,&hellip;" $context->label = 'Thumb';
value="<?= join(',', array_map(function($post) { if ($this->context->transport->post->hasCustomThumb())
return $post->getId(); $context->additionalInfo = '(Currently using custom thumb)';
}, $this->context->transport->post->getRelations())) ?>"/> $this->renderExternal('input-file', $context);
</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 ?>
<div class="form-row"> <div class="form-row">
<label></label> <label></label>

View file

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

View file

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

View file

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

View file

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

View file

@ -6,108 +6,83 @@
class="edit" class="edit"
autocomplete="off"> autocomplete="off">
<?php if (Auth::getCurrentUser()->getId() == $this->context->transport->user->getId()): ?> <?php
<div class="form-row current-password"> if (Auth::getCurrentUser()->getId() == $this->context->transport->user->getId())
<label for="current-password">Current password:</label> {
<div class="input-wrapper"> $context = new StdClass;
<input $context->label = 'Current password';
type="password" $context->name = 'current-password';
name="current-password" $context->placeholder = 'Current password';
id="current-password" $this->renderExternal('input-password', $context);
placeholder="Current password"/> echo '<hr/>';
</div> }
</div>
<hr>
<?php endif ?>
<?php if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditUserName, Privilege::EditUserName,
Access::getIdentity($this->context->transport->user)))): ?> 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"> if (Access::check(new Privilege(
<label for="name">Name:</label> Privilege::EditUserEmail,
<div class="input-wrapper"> Access::getIdentity($this->context->transport->user))))
<input {
type="text" $context = new StdClass;
name="name" $context->label = 'E-mail';
id="name" $context->name = 'email';
placeholder="New name&hellip;" $context->placeholder = 'New e-mail&hellip;';
value="<?= htmlspecialchars(InputHelper::get('name')) ?>"> $context->value = htmlspecialchars(InputHelper::get('email'));
</div> $this->renderExternal('input-text', $context);
</div> }
<?php endif ?>
<?php if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditUserEmail, Privilege::EditUserPassword,
Access::getIdentity($this->context->transport->user)))): ?> 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"> $context = new StdClass;
<label for="name">E-mail:</label> $context->name = 'password2';
<div class="input-wrapper"> $context->placeholder = 'New password&hellip; (repeat)';
<input $context->value = htmlspecialchars(InputHelper::get('password2'));
type="text" $this->renderExternal('input-password', $context);
name="email" }
id="email"
placeholder="New e-mail&hellip;"
value="<?= htmlspecialchars(InputHelper::get('email')) ?>"/>
</div>
</div>
<?php endif ?>
<?php if (Access::check(new Privilege( if (Access::check(new Privilege(
Privilege::EditUserPassword, Privilege::EditUserAccessRank,
Access::getIdentity($this->context->transport->user)))): ?> Access::getIdentity($this->context->transport->user))))
{
$accessRanks = array_filter(
AccessRank::getAll(),
function($ar)
{
return $ar->toInteger() != AccessRank::Nobody;
});
<div class="form-row password1"> $context = new StdClass;
<label for="password1">New password:</label> $context->name = 'access-rank';
<div class="input-wrapper"> $context->label = 'Access rank';
<input $context->placeholder = 'New password&hellip; (repeat)';
type="password" $context->optionValues = array_map(function($ar) { return $ar->toInteger(); }, $accessRanks);
name="password1" $context->optionLabels = array_map(function($ar) { return $ar->toDisplayString(); }, $accessRanks);
id="password1" $context->activeOptionValue = InputHelper::get('access-rank')
placeholder="New password&hellip;" ?: $this->context->transport->user->getAccessRank()->toInteger();
value="<?= htmlspecialchars(InputHelper::get('password1')) ?>"/> $this->renderExternal('input-select', $context);
</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 ?>
<?php if (Access::check(new Privilege( $this->renderExternal('message');
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') ?>
<div class="form-row"> <div class="form-row">
<label></label> <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> <p>Registered users can view more content,<br/>upload files and add posts to favorites.</p>
<div class="form-row"> <?php
<label for="name">User name:</label> $context = new StdClass;
<div class="input-wrapper"> $context->name = 'name';
<input $context->label = 'User name';
type="text" $context->value = htmlspecialchars(InputHelper::get('name'));
id="name" $context->placeholder = 'e.g. darth_vader';
name="name" $context->noAutocomplete = true;
value="<?= htmlspecialchars(InputHelper::get('name')) ?>" $this->renderExternal('input-text', $context);
placeholder="e.g. darth_vader"
autocomplete="off"/>
</div>
</div>
<div class="form-row"> $context = new StdClass;
<label for="password1">Password:</label> $context->name = 'password1';
<div class="input-wrapper"> $context->label = 'Password';
<input $context->value = htmlspecialchars(InputHelper::get('password1'));
type="password" $context->placeholder = 'e.g. ' . str_repeat('&#x25cf;', 8);
id="password1" $context->noAutocomplete = true;
name="password1" $this->renderExternal('input-password', $context);
value="<?= htmlspecialchars(InputHelper::get('password1')) ?>"
placeholder="e.g. <?= str_repeat('&#x25cf;', 8) ?>"
autocomplete="off"/>
</div>
</div>
<div class="form-row"> $context->name = 'password2';
<label for="password2">Password (repeat):</label> $context->label = 'Password (repeat)';
<div class="input-wrapper"> $context->value = htmlspecialchars(InputHelper::get('password2'));
<input $this->renderExternal('input-password', $context);
type="password"
id="password2"
name="password2"
value="<?= htmlspecialchars(InputHelper::get('password2')) ?>"
placeholder="e.g. <?= str_repeat('&#x25cf;', 8) ?>"
autocomplete="off"/>
</div>
</div>
<div class="form-row"> $context = new StdClass;
<label for="email">E-mail address:</label> $context->name = 'email';
<div class="input-wrapper"> $context->label = 'E-mail address';
<input $context->value = htmlspecialchars(InputHelper::get('email'));
type="text" $context->placeholder = 'e.g. vader@empire.gov';
id="email" $context->noAutocomplete = true;
name="email" $this->renderExternal('input-text', $context);
value="<?= htmlspecialchars(InputHelper::get('email')) ?>" ?>
placeholder="e.g. vader@empire.gov" autocomplete="off"/>
</div>
</div>
<p id="email-info"> <p id="email-info">
Your e-mail will be used to show your <a href="http://gravatar.com/">Gravatar</a>.<br/> 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" method="post"
class="settings"> class="settings">
<div class="form-row safety"> <?php
<label>Safety:</label> $safety = array_filter(
<div class="input-wrapper"> PostSafety::getAll(),
<?php foreach (PostSafety::getAll() as $safety): ?> function($s)
<?php if (Access::check(new Privilege( {
Privilege::ListPosts, return Access::check(new Privilege(Privilege::ListPosts, $s->toString()));
$safety->toString()))): ?> });
<label>
<?php
$attrs = [];
$attrs['type'] = 'checkbox';
$attrs['name'] = 'safety[]';
$attrs['value'] = $safety->toInteger();
if ($settings->hasEnabledSafety($safety))
$attrs['checked'] = 'checked';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs); $context = new StdClass;
?> $context->label = 'Safety';
<?= ucfirst($safety->toDisplayString()) ?> $context->optionValuesDisabled = array_map(function($s) { return null; }, $safety);
</label> $context->optionValuesEnabled = array_map(function($s) { return $s->toInteger(); }, $safety);
<?php endif ?> $context->optionLabels = array_map(function($s) { return ucfirst($s->toDisplayString()); }, $safety);
<?php endforeach ?> $context->optionNames = array_map(function($s) { return 'safety[]'; }, $safety);
</div> $context->optionStates = array_map(function($s) use ($settings) { return $settings->hasEnabledSafety($s); }, $safety);
</div> $this->renderExternal('input-checkboxes', $context);
<div class="form-row endless-scrolling"> $context = new StdClass;
<label for="endless-scrolling">Endless scrolling:</label> $context->optionValuesDisabled = ['0'];
<div class="input-wrapper"> $context->optionValuesEnabled = ['1'];
<?php $context->optionLabels = ['Enabled'];
$attrs = [];
$attrs['name'] = 'endless-scrolling';
$attrs['type'] = 'hidden';
$attrs['value'] = '0';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
<label>
<?php
$attrs['type'] = 'checkbox'; $context->label = 'Endless scrolling';
$attrs['value'] = '1'; $context->optionNames = ['endless-scrolling'];
$attrs['id'] = 'endless-scrolling'; $context->optionStates = [$settings->hasEnabledEndlessScrolling()];
if ($settings->hasEnabledEndlessScrolling()) $this->renderExternal('input-checkboxes', $context);
$attrs['checked'] = 'checked';
echo TextHelper::htmlTag('input', TextHelper::HTML_LEAF, $attrs);
?>
Enabled
</label>
</div>
</div>
<div class="form-row post-tag-titles"> $context->label = 'Tags in thumbs';
<label for="post-tag-titles">Tags in thumbs:</label> $context->optionNames = ['post-tag-titles'];
<div class="input-wrapper"> $context->optionStates = [$settings->hasEnabledPostTagTitles()];
<?php $this->renderExternal('input-checkboxes', $context);
$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>
<div class="form-row hide-disliked-posts"> $context->label = 'Hide down-voted';
<label for="hide-disliked-posts">Hide down-voted:</label> $context->optionNames = ['hide-disliked-posts'];
<div class="input-wrapper"> $context->optionStates = [$settings->hasEnabledHidingDislikedPosts()];
<?php $this->renderExternal('input-checkboxes', $context);
$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>
<?php $this->renderExternal('message') ?> <?php $this->renderExternal('message') ?>