Skip to content

Commit c972ddd

Browse files
committed
Create initial template for packet editor
1 parent dde5e3f commit c972ddd

File tree

4 files changed

+56
-36
lines changed

4 files changed

+56
-36
lines changed

src/controllers/Packet/Edit.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ public function &run(Router &$router, View &$view, array &$args) {
2323

2424
$data = $router->getRequestQueryArray();
2525
$model = new PacketEditModel();
26-
$model->content = null;
2726
$model->csrf_id = mt_rand();
2827
$model->csrf_token = CSRF::generate($model->csrf_id, 900); // 15 mins
29-
$model->packet = null;
30-
$model->packet_id = (isset($data["id"]) ? $data["id"] : null);
3128
$model->error = null;
29+
$model->format = null;
3230
$model->markdown = null;
31+
$model->name = null;
32+
$model->packet = null;
33+
$model->packet_id = (isset($data["id"]) ? $data["id"] : null);
3334
$model->published = null;
34-
$model->title = null;
35+
$model->remarks = null;
3536
$model->user = (
3637
isset($_SESSION['user_id']) ? new User($_SESSION['user_id']) : null
3738
);
@@ -49,10 +50,11 @@ public function &run(Router &$router, View &$view, array &$args) {
4950
} else {
5051
$flags = $model->packet->getOptionsBitmask();
5152

52-
$model->content = $model->packet->getContent(false);
53+
$model->format = $model->packet->getPacketFormat();
54+
$model->name = $model->packet->getPacketName();
55+
$model->remarks = $model->packet->getPacketRemarks(false);
5356
$model->markdown = ($flags & Packet::OPTION_MARKDOWN);
5457
$model->published = ($flags & Packet::OPTION_PUBLISHED);
55-
$model->title = $model->packet->getTitle();
5658

5759
if ($router->getRequestMethod() == "POST") {
5860
$this->handlePost($router, $model);
@@ -82,15 +84,17 @@ protected function handlePost(Router &$router, PacketEditModel &$model) {
8284
$csrf_id = (isset($data["csrf_id" ]) ? $data["csrf_id" ] : null);
8385
$csrf_token = (isset($data["csrf_token"]) ? $data["csrf_token"] : null);
8486
$csrf_valid = CSRF::validate($csrf_id, $csrf_token);
85-
$category = (isset($data["category" ]) ? $data["category" ] : null);
86-
$title = (isset($data["title" ]) ? $data["title" ] : null);
87+
$name = (isset($data["name" ]) ? $data["name" ] : null);
88+
$format = (isset($data["format" ]) ? $data["format" ] : null);
89+
$remarks = (isset($data["remarks" ]) ? $data["remarks" ] : null);
8790
$markdown = (isset($data["markdown" ]) ? $data["markdown" ] : null);
8891
$content = (isset($data["content" ]) ? $data["content" ] : null);
8992
$publish = (isset($data["publish" ]) ? $data["publish" ] : null);
9093
$save = (isset($data["save" ]) ? $data["save" ] : null);
9194

92-
$model->category = $category;
93-
$model->title = $title;
95+
$model->name = $name;
96+
$model->format = $format;
97+
$model->remarks = $remarks;
9498
$model->markdown = $markdown;
9599
$model->content = $content;
96100

@@ -100,19 +104,22 @@ protected function handlePost(Router &$router, PacketEditModel &$model) {
100104
}
101105
CSRF::invalidate($csrf_id);
102106

103-
if (empty($title)) {
104-
$model->error = "EMPTY_TITLE";
105-
} else if (empty($content)) {
106-
$model->error = "EMPTY_CONTENT";
107+
if (empty($name)) {
108+
$model->error = "EMPTY_NAME";
109+
} else if (empty($format)) {
110+
$model->error = "EMPTY_FORMAT";
111+
} else if (empty($remarks)) {
112+
$model->error = "EMPTY_REMARKS";
107113
}
108114

109115
$user_id = $model->user->getId();
110116

111117
try {
112118

113-
$model->packet->setTitle($model->title);
119+
$model->packet->setPacketName($model->name);
120+
$model->packet->setPacketFormat($model->format);
121+
$model->packet->setPacketRemarks($model->remarks);
114122
$model->packet->setMarkdown($model->markdown);
115-
$model->packet->setContent($model->content);
116123
$model->packet->setPublished($publish);
117124

118125
$model->packet->setEditedCount(
@@ -146,10 +153,11 @@ protected function handlePost(Router &$router, PacketEditModel &$model) {
146153
getenv("REMOTE_ADDR"),
147154
json_encode([
148155
"error" => $model->error,
149-
"packet_id" => $model->packet_id,
156+
"packet_id" => $model->packet_id,
150157
"options_bitmask" => $model->packet->getOptionsBitmask(),
151-
"title" => $model->packet->getTitle(),
152-
"content" => $model->packet->getContent(false),
158+
"name" => $model->packet->getPacketName(),
159+
"format" => $model->packet->getPacketFormat(),
160+
"remarks" => $model->packet->getPacketRemarks(false),
153161
])
154162
);
155163
}

src/models/Document/Edit.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class Edit extends Model {
88

99
public $acl_allowed;
10+
public $category;
1011
public $content;
1112
public $csrf_id;
1213
public $csrf_token;

src/models/Packet/Edit.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
class Edit extends Model {
88

99
public $acl_allowed;
10-
public $content;
1110
public $csrf_id;
1211
public $csrf_token;
13-
public $document;
14-
public $document_id;
1512
public $error;
13+
public $format;
1614
public $markdown;
15+
public $name;
16+
public $packet;
17+
public $packet_id;
1718
public $published;
18-
public $title;
19+
public $remarks;
1920
public $user;
2021

2122
}

src/templates/Packet/Edit.phtml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ switch ($this->getContext()->error) {
2323
. "edit packet form expired, or this may have been a malicious attempt"
2424
. "to create a packet.";
2525
break;
26-
case "EMPTY_TITLE":
27-
$message = "The title of the packet is required.";
26+
case "EMPTY_NAME":
27+
$message = "The name of the packet is required.";
2828
break;
29-
case "EMPTY_CONTENT":
30-
$message = "The content of the packet is required.";
29+
case "EMPTY_FORMAT":
30+
$message = "The format of the packet is required.";
31+
break;
32+
case "EMPTY_REMARKS":
33+
$message = "The remarks of the packet is required.";
3134
break;
3235
case "INTERNAL_ERROR":
3336
$message = "An internal error occurred while processing your request. "
@@ -56,30 +59,37 @@ require("./header.inc.phtml");
5659
htmlspecialchars($this->getContext()->csrf_token, ENT_HTML5, "UTF-8");
5760
?>"/>
5861
<section>
59-
<label for="title">Title:</label><br/>
60-
<input type="text" name="title" id="title" tabindex="1" required
62+
<label for="title">Name:</label><br/>
63+
<input type="text" name="name" id="name" tabindex="1" required
6164
autofocus="autofocus" value="<?php echo
62-
filter_var($this->getContext()->title, FILTER_SANITIZE_STRING);
65+
filter_var($this->getContext()->name, FILTER_SANITIZE_STRING);
6366
?>"/>
6467
</section>
6568
<section>
66-
<label for="content">Content:</label>
69+
<label for="format">Remarks:</label>
70+
<textarea name="format" id="format" tabindex="2" required
71+
style="height:200px;"><?php echo
72+
htmlspecialchars($this->getContext()->format, ENT_HTML5, "UTF-8");
73+
?></textarea>
74+
</section>
75+
<section>
76+
<label for="remarks">Remarks:</label>
6777
<span style="float:right;">
6878
<label for="markdown" title="Use markdown or use raw HTML">Markdown</label>
69-
<input type="checkbox" name="markdown" id="markdown" tabindex="3"
79+
<input type="checkbox" name="markdown" id="markdown" tabindex="4"
7080
title="Use markdown or use raw HTML" value="1"<?php
7181
if ($this->getContext()->markdown)
7282
echo " checked=\"checked\"";
7383
?>/>
7484
</span>
75-
<textarea name="content" id="content" tabindex="2" required
85+
<textarea name="remarks" id="remarks" tabindex="3" required
7686
style="height:200px;"><?php echo
77-
htmlspecialchars($this->getContext()->content, ENT_HTML5, "UTF-8");
87+
htmlspecialchars($this->getContext()->remarks, ENT_HTML5, "UTF-8");
7888
?></textarea>
7989
</section>
8090
<section>
81-
<input type="submit" name="publish" value="Publish" tabindex="4"/>
82-
<input type="submit" name="save" value="Unpublish" tabindex="5"/>
91+
<input type="submit" name="publish" value="Publish" tabindex="5"/>
92+
<input type="submit" name="save" value="Unpublish" tabindex="6"/>
8393
</section>
8494
</form>
8595
<?php } ?>

0 commit comments

Comments
 (0)