Files
xxx/publish/write.inc.php
T
tim bf36ec25fd Load a saved story into the form for editors only.
Visitors could post an id to /publish and read the author's email address.
2026-09-26 15:27:51 +02:00

159 lines
6.1 KiB
PHP

<?php
$id = get_id();
$search = get_search_args();
if ($action == 'preview')
$result = get_post_data(TRUE);
// Only editors load a saved story; it holds the author's email address
else if ($is_admin && $action && is_numeric($id))
$result = get_query($id);
if (isset($result) && is_array($result))
extract($result[0], EXTR_OVERWRITE);
// Print any validation error messages
if (count($validate) !== 0) {
echo '<ul class="error-box">Please correct the following errors:';
foreach ($validate as $validate_key=>$validate_value) {
echo '<li>'.$validate_value.'</li>';
}
echo '</ul>';
}
?>
<form id="write" method="post" enctype="multipart/form-data" onsubmit="return review()" action="">
<?= csrf_field() ?>
<div class="grid">
<label<?= isset($validate['title']) ? ' class="red"' : '' ?> for="title">Title:</label>
<div class="rightcolumn">
<input type="text" id="title" name="title" maxlength="150" value="<?= isset($title) ? form_value($title) : '' ?>" />
<span class="required">&nbsp;*</span>
</div>
<label<?= isset($validate['author']) ? ' class="red"' : '' ?> for="author">Author:</label>
<div class="rightcolumn">
<input type="text" name="author" id="author" value="<?= isset($author) ? form_value($author) : '' ?>" maxlength="150" />
<span class="required">&nbsp;*</span>
</div>
<label<?= isset($validate['email']) ? ' class="red"' : '' ?> for="email">Email address:</label>
<div class="rightcolumn">
<input type="text" name="email" id="email" maxlength="150" value="<?= isset($email) ? form_value($email) : '' ?>" />
</div>
<div class="leftcolumn"></div>
<div class="note">(An email address where editors can reach the author.)</div>
<div class="tabs">
<span id="texttab" class="tab active<?= isset($validate['story']) ? ' red' : '' ?>" onclick="showHide('text');">Text:</span>
<span id="uploadtab" class="tab<?= isset($validate['upload']) ? ' red' : '' ?>" onclick="showHide('upload');">Image:</span>
<span id="wordcounter" class="counter" hidden>0 words</span>
</div>
<?php $line_break_note = '(To get line-breaks&mdash;as in poetry&mdash;instead of paragraph breaks, hit shift-enter instead of enter.)'; ?>
<div class="textarea rightcolumn">
<div id="textparent">
<textarea name="story" id="story" rows="20" cols="50"><?php
echo (isset($story) ? form_value($story) : '')
?></textarea>
<div class="note"><?= $line_break_note ?></div>
</div>
<div id="uploadparent" hidden>
<div class="upload"><div>
<?php
if (isset($file_src) || isset($img)) {
if (isset($file_src)) {
echo ' <input type="hidden" id="uploaded" name="uploaded" value="pending" />';
} else {
echo ' <input type="hidden" id="uploaded" name="uploaded" value="'.(int)$id.'" />';
}
echo ' <div class="in-note">If you are happy with the image above, click Submit. Otherwise, upload a new image:</div>';
} else {
echo ' <div class="in-note">You may upload an image of 100,000 pixels instead of text:</div>';
}
?>
<input type="file" name="upload" id="upload" />
<?php
if (isset($file_src) || isset($img)) {
echo ' <div>';
echo ' <div class="remove">';
echo ' <input id="remove_img" name="remove_img" type="hidden" value="0" />';
echo ' <a href="javascript:toggle_remove()">';
echo ' <img id="remove_img_icon" src="/graphics/trashcan.png" border="0" title="Mark photo for deletion." /></a>';
echo ' </div>';
echo ' <div class="in-note">If you wish to remove the image altogether, and replace it with text, click the bin icon: <br />';
echo ' (Click it again to restore the image.)</div>';
echo ' </div>';
}
?>
</div></div>
<!-- An invisible copy of the note under the story keeps the page height -->
<div class="note spacer" aria-hidden="true"><?= $line_break_note ?></div>
</div>
</div>
<?php if ($is_admin) { ?>
<label<?= isset($validate['comments']) ? ' class="red"' : '' ?> for="comments">Comments:</label>
<div class="rightcolumn">
<input type="text" name="comments" id="comments" maxlength="150" value="<?= isset($comments) ? form_value($comments) : '' ?>" />
</div>
<input type="hidden" id="editor" name="editor" value="<?= form_value($username) ?>" />
<?php } else { ?>
<input type="hidden" id="editor" name="editor" value="original author" />
<?php } ?>
<div hidden>
<input type="hidden" id="date" name="date" value="<?= isset($date) ? form_value($date) : '' ?>" />
<input type="hidden" id="id" name="id" value="<?= isset($id) ? form_value($id) : '' ?>" />
</div>
<?php
// Visitors solve the captcha once; the session remembers it until the story is saved
if (!$is_admin && !captcha_passed()) {
echo captcha_widget();
}
if ($is_admin) {
$checked = isset($hidden) && !empty($hidden) ? ' checked' : '';
echo '<label'.(isset($validate['hidden']) ? ' class="red"' : '').' for="hidden">Hidden:</label>';
echo '<div class="rightcolumn">';
echo '<input type="checkbox" name="hidden" id="hidden"'.$checked.' />';
echo '</div>';
}
?>
<div class="leftcolumn"></div>
<div class="submission rightcolumn">
<?php
if (isset($queue) && $is_admin) {
echo '<button type="submit" id="preview" name="action" value="save">Save in queue</button>';
} else {
echo '<button type="submit" id="preview" name="action" value="preview">Preview</button>';
}
if ((count($validate) === 0 && $action == "preview") || ($is_admin && !$action)){
$submit_text = $is_admin ? "Submit to queue" : "Submit";
echo '<button type="submit" id="submit" name="action" value="submit">'.$submit_text.'</button>';
}
if (($id || $action == "edit") || $is_admin) {
echo '<button type="submit" id="post" name="action" value="post">Post!</button>';
if ($id && $is_admin)
echo '<button type="submit" onclick="javascript:return do_delete();" id="delete" name="action" value="delete">Delete</button>';
}
?>
</div>
</div><!-- .grid -->
</form>
<?php
echo '<script type="text/javascript">'."\n";
if (isset($file_src) || isset($img) || isset($validate['upload'])) {
echo " showHide('upload')\n";
} else {
echo " var wordcounter = document.getElementById('wordcounter');\n";
echo " wordcounter.hidden = false;\n";
}
echo "</script>\n";
?>