/
new.php
73 lines (56 loc) · 2.2 KB
/
new.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
include_once('module/config.php');
include_once('module/utilities.php');
include_once('module/items.php');
if (isPost()) {
$title = trim(getParam('title'));
$summary = trim(getParam('summary'));
$body = trim(getParam('body'));
$group = getParam('group');
$parent_id = getParam('parentstory');
if ($group || $parent_id) {
// this could be prettier, but it's enough
// if the password doesn't match up for an existing article, something is wrong
if (!getParam('password') || getParam('password') != sha1($group . '-' . $parent_id . '-' . getConfig('secret_salt'))) die("Something went wrong...");
}
if($group && !isHash($group)) {
die("There was a problem with the group hash. Please try again");
}
if (!$summary && $body) {
$body_lines = explode("\n", trim($body));
$summary = $body_lines[0];
$body_new = '';
$comma = 0;
foreach ($body_lines as $line) {
$line = trim($line);
if ($line) {
if ($comma) {
$body_new .= "\n\n";
} else {
$comma = 1;
}
$body_new .= $line;
}
}
$body = $body_new;
}
if ($title && $summary && $body) {
$oldItemId = getItemIdByHash(sha1($title . $summary . $body));
if ($oldItemId) {
put_ticket(array("An exact copy of this item already exists. Here it is!"), getItemUrl($oldItemId, 'absolute'));
}
$newItemId = createNewItem($title, $summary, $body, $parent_id, $group);
if ($newItemId) {
delete_cache('items/*', 1);
if ($group) {
delete_cache("related/$group", 1);
}
header('Location: ' . getItemUrl($newItemId));
} else {
echo("There was a problem creating this item");
}
} else {
echo ("You forgot something...");
// @todo make this more user-friendly
}
}