/[LeafOK_CVS]/fenglin/bbs/post.php
ViewVC logotype

Annotation of /fenglin/bbs/post.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Fri Apr 4 07:57:04 2025 UTC (11 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.1: +47 -5 lines
Add support for delete existing related upload

1 sysadm 1.1 <?
2     require_once "../lib/common.inc.php";
3     require_once "../lib/db_open.inc.php";
4     require_once "./common_lib.inc.php";
5     require_once "./session_init.inc.php";
6     require_once "./check_sub.inc.php";
7     require_once "../lib/lml.inc.php";
8     require_once "../lib/str_process.inc.php";
9     ?>
10     <?
11     force_login();
12    
13     $id = (isset($_GET["id"]) ? intval($_GET["id"]) : 0);
14     $reply_id = (isset($_GET["reply_id"]) ? intval($_GET["reply_id"]) : 0);
15     $sid = (isset($_GET["sid"]) ? intval($_GET["sid"]) : $BBS_default_sid);
16     $quote = (isset($_GET["quote"]) && $_GET["quote"] == "0" ? false : true);
17    
18     $title = "";
19     $content = "";
20     $emoji = 1;
21     $reply_note = ($reply_id == 0 ? 1 : 0);
22    
23     if($id == 0) // Post article
24     {
25     if ($reply_id == 0) // Post new thread
26     {
27     $sql = "SELECT title FROM section_config WHERE SID = $sid AND enable";
28    
29     $rs = mysqli_query($db_conn, $sql);
30     if ($rs == false)
31     {
32     echo("Query section error: " . mysqli_error($db_conn));
33     exit();
34     }
35    
36     if ($row = mysqli_fetch_array($rs))
37     {
38     $section_title = $row["title"];
39     }
40     else
41     {
42     error_msg("版块不存在!",true);
43     exit();
44     }
45     mysqli_free_result($rs);
46    
47     if (!$_SESSION["BBS_priv"]->checkpriv($sid, S_POST))
48     {
49     error_msg("您无权发表文章!", true);
50     exit();
51     }
52     }
53     else // Reply article
54     {
55     $sql = "SELECT TID, bbs.SID, bbs.title, `lock`, username, nickname, content,
56     section_config.title AS s_title FROM bbs
57     INNER JOIN bbs_content ON bbs.CID = bbs_content.CID
58     INNER JOIN section_config ON bbs.SID = section_config.SID
59     WHERE bbs.AID = $reply_id AND visible";
60    
61     $rs = mysqli_query($db_conn, $sql);
62     if ($rs == false)
63     {
64     echo("Query article error: " . mysqli_error($db_conn));
65     exit();
66     }
67    
68     if ($row = mysqli_fetch_array($rs))
69     {
70     $tid = $row["TID"];
71     $sid = $row["SID"];
72     $title = $row["title"];
73     $lock = $row["lock"];
74     $r_username = $row["username"];
75     $r_nickname = $row["nickname"];
76     $content = $row["content"];
77     $section_title = $row["s_title"];
78     }
79     else
80     {
81     error_msg("回复的文章不存在!", true);
82     exit();
83     }
84     mysqli_free_result($rs);
85    
86     if ($tid != 0) // Article to be replied is not the head of topic thread
87     {
88     $sql = "SELECT SID, `lock` FROM bbs WHERE AID = $tid AND visible";
89    
90     $rs = mysqli_query($db_conn, $sql);
91     if ($rs == false)
92     {
93     echo("Query article error: " . mysqli_error($db_conn));
94     exit();
95     }
96    
97     if ($row = mysqli_fetch_array($rs))
98     {
99     $sid = $row["SID"]; // In case of inconsistent SID data
100     $lock = $row["lock"];
101     }
102     else
103     {
104     error_msg("回复的主题不存在!", true);
105     exit();
106     }
107     mysqli_free_result($rs);
108     }
109    
110     if (!$_SESSION["BBS_priv"]->checkpriv($sid, S_POST))
111     {
112     error_msg("您无权发表文章!", true);
113     exit();
114     }
115    
116     if ($lock)
117     {
118     error_msg("该主题谢绝回复!", true);
119     exit();
120     }
121     }
122     }
123     else // Modify article
124     {
125     $sql = "select UID, bbs.SID, TID, bbs.title, content, icon, reply_note, excerption,
126     section_config.title AS s_title FROM bbs
127     INNER JOIN bbs_content ON bbs.CID = bbs_content.CID
128     INNER JOIN section_config ON bbs.SID = section_config.SID
129     WHERE bbs.AID = $id AND visible";
130    
131     $rs = mysqli_query($db_conn, $sql);
132     if ($rs == false)
133     {
134     echo("Query article error: " . mysqli_error($db_conn));
135     exit();
136     }
137    
138     if ($row = mysqli_fetch_array($rs))
139     {
140     $uid = $row["UID"];
141     $sid = $row["SID"];
142     $tid = $row["TID"];
143     $title = $row["title"];
144     $content = $row["content"];
145     $emoji = $row["icon"];
146     $reply_note = $row["reply_note"];
147     $excerption = $row["excerption"];
148     $section_title = $row["s_title"];
149     }
150     else
151     {
152     error_msg("修改的文章不存在!", true);
153     exit();
154     }
155     mysqli_free_result($rs);
156    
157     if (!($_SESSION["BBS_priv"]->checkpriv($sid, S_POST) && $_SESSION["BBS_uid"] == $uid && (!$excerption)))
158     {
159     error_msg("您无权修改此文章!",true);
160     exit();
161     }
162     }
163     ?>
164     <html>
165     <head>
166     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
167     <title>发表文章</title>
168     <link rel="stylesheet" href="css/default.css" type="text/css">
169     <script language="JavaScript" src="/js/nw_open.js"></script>
170     <script language="JavaScript" src="/js/lml_assistant.js"></script>
171     <script src="../js/polyfill.min.js"></script>
172     <script src="../js/axios.min.js"></script>
173     <script type="text/javascript">
174     function refresh_err_msg(errorFieldMap)
175     {
176     document.getElementsByName("err_msg").forEach(element => {
177     if (errorFieldMap.has(element.id))
178     {
179     element.innerHTML = errorFieldMap.get(element.id);
180     }
181     else
182     {
183     element.innerHTML = "";
184     }
185     });
186     }
187    
188     function post_article(f)
189     {
190     instance.post('post_service.php', {
191     id: <? echo $id; ?>,
192     reply_id: <? echo $reply_id; ?>,
193     sid: <? echo $sid; ?>,
194     title: f.title.value,
195     transship: (f.transship != null && f.transship.checked ? "1" : "0"),
196     content: f.content.value,
197     emoji: f.emoji.value,
198     sign_id: (f.use_sign != null && f.use_sign.checked ? f.sign_id.value : "0"),
199     reply_note: (f.reply_note.checked ? "1" : "0"),
200     attachment: f.attachment.files,
201     }, {
202     headers: {
203     'Content-Type': 'multipart/form-data',
204     }
205     })
206     .then(function (response) {
207     var ret = response.data;
208     var errorFieldMap = new Map();
209     switch (ret.return.code)
210     {
211     case 0: // OK
212     var returnPath = "view_article.php?id=" + ret.return.tid + "#" + ret.return.aid;
213     document.location = returnPath;
214     refresh_err_msg(errorFieldMap);
215     break;
216     case -1: // Input validation failed
217     ret.return.errorFields.forEach(field => {
218     errorFieldMap.set("err_msg_" + field.id, "<br />" + field.errMsg);
219     });
220     refresh_err_msg(errorFieldMap);
221     break;
222     case -2: // Internal error
223     console.log(ret.return.message);
224     errorFieldMap.set("err_msg_prompt", "内部错误");
225     refresh_err_msg(errorFieldMap);
226     break;
227     default:
228     console.log(ret.return.code);
229     break;
230     }
231     })
232     .catch(function (error) {
233     console.log(error);
234     });
235    
236     return false;
237     }
238    
239 sysadm 1.2 function upload_del(id)
240     {
241     if (window.confirm('真的要删除吗?') == false)
242     {
243     return false;
244     }
245    
246     instance.post('upload_del.php', {
247     aid: id
248     })
249     .then(function (response) {
250     var ret = response.data;
251     var errorFieldMap = new Map();
252     switch (ret.return.code)
253     {
254     case 0: // OK
255     document.getElementById("attachment_" + id).style.display = "none";
256     refresh_err_msg(errorFieldMap);
257     break;
258     case -1: // Input validation failed
259     ret.return.errorFields.forEach(field => {
260     errorFieldMap.set("err_msg_" + field.id, "<br />" + field.errMsg);
261     });
262     refresh_err_msg(errorFieldMap);
263     break;
264     case -2: // Internal error
265     console.log(ret.return.message);
266     errorFieldMap.set("err_msg_prompt", "内部错误");
267     refresh_err_msg(errorFieldMap);
268     break;
269     default:
270     console.log(ret.return.code);
271     break;
272     }
273     })
274     .catch(function (error) {
275     console.log(error);
276     });
277    
278     return false;
279     }
280    
281 sysadm 1.1 const instance = axios.create({
282     withCredentials: true,
283     timeout: 3000,
284     baseURL: document.location.protocol + '//' + document.location.hostname + (document.location.port=='' ? '' : (':' + document.location.port)) + '/bbs/',
285     });
286    
287     window.addEventListener("load", () => {
288     var f = document.getElementById("post_form");
289     f.addEventListener("submit", (e) => {
290     e.preventDefault();
291     post_article(f);
292     });
293     });
294    
295     </script>
296     </head>
297     <body>
298     <center>
299     <table border="0" cellpadding="1" cellspacing="0" width="770">
300     <tr>
301     <td>
302     <a class="s2" href="main.php?sid=<? echo $sid; ?>"><? echo $BBS_name; ?></a>&gt;&gt;<a class="s2" href="bbs.php?sid=<? echo $sid; ?>"><? echo $section_title; ?></a>&gt;&gt;<?
303     if ($id == 0)
304     {
305     if ($reply_id > 0)
306     {
307     ?><a class="s2" href="view_article.php?id=<? echo ($tid ? $tid : $reply_id) . "#$reply_id"; ?>"><? echo split_line(htmlspecialchars($title, ENT_HTML401, 'UTF-8'), "", 65, 2, "<br />"); ?></a>&gt;&gt;<a class="s2" href="#">回复文章</a><?
308     }
309     else
310     {
311     ?><a class="s2" href="#">发表新文章</a><?
312     }
313     }
314     else
315     {
316     ?><a class="s2" href="view_article.php?id=<? echo ($tid ? $tid : $id) . "#$id"; ?>"><? echo split_line(htmlspecialchars($title, ENT_HTML401, 'UTF-8'), "", 65, 2, "<br />"); ?></a>&gt;&gt;<a class="s2" href="#">修改文章</a><?
317     }
318     ?>
319     </td>
320     </tr>
321     </table>
322     <form method="POST" ENCTYPE="multipart/form-data" id="post_form" name="post_form" action="#">
323     <table border="0" cellpadding="5" cellspacing="0" width="770">
324     <tr>
325     <td colspan="2" align="center" style="color:red;">别忙着发贴,请先看一下<a class="s0" href="doc/management.xml" target=_blank>《论坛管理章程》</a>吧!<br>
326     (请对您的言论负责,遵守有关法律、法规,尊重网络道德)</td>
327     </tr>
328     <tr height="10">
329 sysadm 1.2 <td colspan="2" align="center"><span id="err_msg_prompt" name="err_msg" style="color: red;"></span></td>
330 sysadm 1.1 </tr>
331     <tr>
332     <td width="10%" align="right">标题<span id="err_msg_title" name="err_msg" style="color: red;"></span></td>
333     <td width="90%">
334     <input type="text" name="title" id="title" size="80" <? echo ($id != 0 ? "readonly" : ""); ?> value="<? echo ($reply_id > 0 ? split_line(htmlspecialchars($title, ENT_QUOTES | ENT_HTML401, 'UTF-8'), "Re: ", 80, 1) : htmlspecialchars($title, ENT_QUOTES | ENT_HTML401, 'UTF-8')); ?>">
335     <?
336     if ($id == 0 && $reply_id == 0)
337     {
338     ?>
339     <input type="checkbox" name="transship">转载
340     <?
341     }
342     ?></td>
343     </tr>
344     <tr>
345     <td align="right">正文<span id="err_msg_content" name="err_msg" style="color: red;"></span></td>
346     <td>
347     <textarea name="content" id="content" cols="80" rows="25"><?
348     if ($reply_id == 0)
349     {
350     echo htmlspecialchars($content, ENT_HTML401, 'UTF-8');
351     }
352     else if ($quote)
353     {
354     ?>
355    
356    
357    
358     【 在 <? echo htmlspecialchars($r_username, ENT_HTML401, 'UTF-8'); ?> (<? echo htmlspecialchars($r_nickname, ENT_HTML401, 'UTF-8'); ?>) 的大作中提到: 】
359     <?
360     echo htmlspecialchars(LMLtagFilter(LML(split_line($content, ": ", 76, 20), false, false, 1024)), ENT_HTML401, 'UTF-8');
361     }
362     ?></textarea>
363     </td>
364     </tr>
365     <tr>
366     <td align="right"><a class="s0" href="doc/lml.htm" target=_blank>LML</a>助手</td>
367     <td>
368     <INPUT type="button" value="B" onclick="b_bold(content)" style="font-weight:bold; width:25px;">
369     <INPUT type="button" value="I" onclick="b_italic(content)" style="font-style:italic; width:25px;">
370     <INPUT type="button" value="U" onclick="b_underline(content)" style="text-decoration:underline; width:25px;">
371     <INPUT type="button" value="[" onclick="b_left(content)" style="width:20px;">
372     <INPUT type="button" value="]" onclick="b_right(content)" style="width:20px;">
373     <INPUT type="button" value="Aa" onclick="b_size(content)" style="width:30px;">
374     <INPUT type="button" value="A" onclick="b_color(content)" style="font-weight:bold; color:red; width:25px;">
375     <INPUT type="button" value="@" onclick="b_email(content)" style="width:25px;">
376     <INPUT type="button" value="Link" onclick="b_link(content)" style="text-decoration:underline; color:blue; width:40px;">
377     <INPUT type="button" value="主题" onclick="b_article(content)" style="text-decoration:underline; color:green; width:40px;">
378     <INPUT type="button" value="图片" onclick="b_image(content)" style="width:40px;">
379     <INPUT type="button" value="字幕" onclick="b_marquee(content)" style="width:40px;">
380     </td>
381     </tr>
382     <tr>
383 sysadm 1.2 <td align="right">上传附件<span id="err_msg_attachment" name="err_msg" style="color: red;"></span></td>
384 sysadm 1.1 <td>
385     单个文件大小不能超过<? echo $BBS_upload_size_limit; ?>M,
386     单次上传不超过<? echo $BBS_upload_count_limit; ?>个文件<br />
387     文件类型限于BMP,GIF,JPEG,PNG,TIFF,TXT,ZIP,RAR<br />
388     <INPUT TYPE=FILE SIZE=40 name="attachment[]" id="attachment" multiple>
389     <?
390     if ($id != 0) // Modify article
391     {
392     $sql = "SELECT * FROM upload_file WHERE ref_AID = $id
393     AND deleted = 0 AND deny = 0
394     ORDER BY AID";
395    
396     $rs = mysqli_query($db_conn, $sql);
397     if ($rs == false)
398     {
399     echo ("Read attachment error: " . mysqli_error($db_conn));
400     exit();
401     }
402    
403     if (mysqli_num_rows($rs) > 0)
404     {
405     ?>
406     <hr width="80%" align="left" />已上传附件<br />
407     <?
408     }
409    
410     while ($row = mysqli_fetch_array($rs))
411     {
412     $filename = $row["filename"];
413     $ext = strtolower(substr($filename, (strrpos($filename, ".") ? strrpos($filename, ".") + 1 : 0)));
414     ?>
415 sysadm 1.2 <span id="attachment_<? echo $row["AID"]; ?>"><img src="images/closed.gif"><a class="s2" href="dl_file.php?aid=<? echo $row["AID"]; ?>" target="_target"><? echo $filename; ?></a> (<? echo $row["size"]; ?>字节)
416 sysadm 1.1 <?
417     if ($row["check"] == 0)
418     {
419     ?><font color="red">未审核</font><?
420     }
421     ?>
422 sysadm 1.2 <a class="s2" href="#" onclick="return upload_del(<? echo $row["AID"]; ?>);">删除</a>
423     <br /></span>
424 sysadm 1.1 <?
425     }
426    
427     mysqli_free_result($rs);
428     }
429     ?>
430     </td>
431     </tr>
432     <tr>
433     <td align="right">表情<span id="err_msg_emoji" name="err_msg" style="color: red;"></td>
434     <td><?
435     for ($i = 1; $i <= $BBS_emoji_count; $i++)
436     {
437     ?><input type="radio" name="emoji" value="<? echo $i; ?>" <? echo ($i == $emoji ? "checked" : ""); ?>><img src="images/expression/<? echo $i; ?>.gif" width="15" height="15" alt="<? echo $i; ?>.gif"><?
438     if (($i % 12)==0)
439     {
440     ?><br><?
441     }
442     }
443     ?></td>
444     </tr>
445     <?
446     if ($id == 0)
447     {
448     ?>
449     <tr>
450     <td align="right"><span id="err_msg_sign" name="err_msg" style="color: red;"></td>
451     <td>
452     <input type="checkbox" name="use_sign">使用我的个人签名&nbsp;
453     <input type="radio" id="sign_id_1" name="sign_id" value="1" checked>1&nbsp;
454     <input type="radio" id="sign_id_2" name="sign_id" value="2">2&nbsp;
455     <input type="radio" id="sign_id_3" name="sign_id" value="3">3&nbsp;
456     <a class="s0" href="" onclick="return NW_open('preference.php', 'member_service', 500, 550);">设置个人签名</a>
457     </td>
458     </tr>
459     <?
460     }
461     ?>
462     <tr>
463     <td align="right"></td>
464     <td><input type="checkbox" name="reply_note" id="reply_note" <? echo ($reply_note ? "checked":""); ?>>有人回复该主题时通知我</td>
465     </tr>
466     </table>
467     <p><input type="submit" value="提交" name="submit">&nbsp;&nbsp;&nbsp;<input type="reset" value="重填" name="reset"></p>
468     </center>
469     </form>
470     <?
471     mysqli_close($db_conn);
472    
473     include "./foot.inc.php";
474     ?>
475     </body>
476     </html>

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1