4 'assign' => 'Toegewezen aan',
5 'subject' => 'Onderwerp',
8 function userupload($input, $target = NULL, $filename = NULL)
10 switch ($input['error']) {
13 case UPLOAD_ERR_INI_SIZE:
14 case UPLOAD_ERR_FORM_SIZE:
15 throw new Exception('bestand te groot');
17 case UPLOAD_ERR_NO_FILE:
20 throw new Exception('bestand niet goed ontvangen: '.$input['error']);
24 if (!file_exists($target) and !@mkdir($target, 0777, TRUE)) {
25 throw new Exception("bestand kon niet geplaatst worden in $target");
29 if (isset($filename)) {
33 $target .= $input['name'];
36 if (file_exists($target)) {
37 throw new Exception("bestandsnaam al aanwezig op $target");
39 if (!@move_uploaded_file($input['tmp_name'], $target)) {
40 throw new Exception("bestand kon niet worden opgeslagen in $target");
43 foreach (@glob('thumb/*/') as $thumbres) {
44 # attempt to remove old derivations
45 @unlink($thumbres . '/' . $target);
50 function messagehtml($input)
52 # convert user textarea post to formatted html
57 if ($User and $User->admin and preg_match('/\A<[a-z][^>]*>/', $input)) {
58 return $input; # allow html input as is if privileged
61 '{<((?:\w+:|/).+?)>}' => '<$1>', # unescape link entities
62 '{<(?:https?://)?([^>\s|]+)>}' => '<$1 $1>', # unnamed link
63 '{<([^>\s|]+)[\s|]([^>]+)>}' => '<a href="$1">$2</a>', # hyperlink
64 "/\r\n?/" => "\n", # unix newlines
65 "/ +\n/" => "<br />", # trailing spaces for hard line break
66 "/^[-*] (.*)$\n?/m" => '<li>$1</li>', # list item
67 "/^(.+)$\n?/m" => "<p>$1</p>\n", # paragraph
68 "{^<p>(<li>.*</li>)(?:</p>\n)?}m" => "<ul>$1</ul>\n", # list container
69 '/_(?<!\w_)(.+?)_(?!\w)/' => '<em>$1</em>', # italic
70 '/\*(?<!\w\*)(.+?)\*(?!\w)/' => '<strong>$1</strong>', # bold
71 '/~(?<!\w~)(.+?)~(?!\w)/' => '<s>$1</s>', # stricken
72 '/`(?<!\w`)(.+?)`(?!\w)/' => '<code>$1</code>', # monospace
74 return preg_replace(array_keys($markup), array_values($markup), htmlspecialchars($input));
77 function createcomment($input, &$Issue = NULL)
79 # insert user message as database issue/reply
80 global $User, $Db, $Page, $journalcol;
83 if (isset($input['reply']) and $body = $input['reply']) {
84 $reply['raw'] = $body;
85 $reply['message'] = messagehtml($body);
87 if (isset($input['announce'])) {
88 $reply['announced'] = !!$input['announce'];
90 if ($_FILES and !empty($_FILES['image'])) {
91 $target = 'data/upload';
92 if (!file_exists($target)) {
93 throw new Exception("er is geen uploadmap aanwezig op $target");
95 $target .= '/' . $User->login;
96 if ($result = userupload($_FILES['image'], $target)) {
97 $reply['raw'] = $reply['raw'] ?? '';
98 $reply['raw'] .= "/$result";
99 $reply['message'] = $reply['message'] ?? '';
100 if (preg_match('(^image/)', $_FILES['image']['type'])) {
101 $reply['message'] .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
104 $reply['message'] .= sprintf('<p>Bijgevoegd bestand: <a href="/%s" />%s</a></p>',
105 $result, basename($result)
111 if (isset($input['id'])) {
112 $newcomment = $input['id'];
113 $filter = ['id = ?', $newcomment];
114 $oldcomment = $Db->query("SELECT * FROM comments WHERE $filter[0]", [$filter[1]])->fetch();
115 if (empty($oldcomment)) {
116 throw new Exception('Antwoord niet gevonden');
120 'updated' => ['now()'],
122 $query = $Db->set('comments', $reply, $filter);
123 if (!$query->rowCount()) {
124 throw new Exception('Fout bij aanpassen');
127 if ($updated = $query->fetch()) {
128 foreach (array_keys(get_object_vars($updated)) as $col) {
129 if ($updated->$col === $oldcomment->$col) {
130 continue; # unaltered
132 $Db->set('journal', [
133 'comment_id' => $newcomment,
136 'old_value' => $oldcomment->$col,
137 'value' => $updated->$col,
144 'page' => "{$Page->handler}/{$Issue->id}",
145 'author' => $User->login,
147 $query = $Db->set('comments', $reply);
148 if (!$query->rowCount()) {
149 throw new Exception('Fout bij opslaan');
151 $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
156 foreach (array_keys($journalcol) as $col) {
157 if (!isset($input[$col])) continue;
158 $row[$col] = $input[$col] ?: NULL;
160 if (isset($input['status'])) {
161 $reset = !empty($input['status']);
162 if (isset($Issue->closed) !== $reset) {
163 $row['closed'] = $reset ? ['now()'] : NULL;
166 $derived = ['updated' => ['now()']];
167 $filter = ['id = ?', $Issue->id];
168 $subquery = $Db->set('issues', $row + $derived, $filter);
170 if ($updated = $subquery->fetch()) {
171 foreach (array_keys($row) as $col) {
172 if ($updated->$col === $Issue->$col) {
173 continue; # unaltered
175 $Db->set('journal', [
176 'comment_id' => $newcomment,
177 'property' => 'attr',
179 'old_value' => $Issue->$col,
180 'value' => $updated->$col,