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

Annotation of /fenglin/bbs/post.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Apr 4 03:35:16 2025 UTC (11 months, 1 week ago) by sysadm
Branch: MAIN
Merge add and modify_article to post
Refact with AJAX support
Refine the validation logic of post article

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     const instance = axios.create({
240     withCredentials: true,
241     timeout: 3000,
242     baseURL: document.location.protocol + '//' + document.location.hostname + (document.location.port=='' ? '' : (':' + document.location.port)) + '/bbs/',
243     });
244    
245     window.addEventListener("load", () => {
246     var f = document.getElementById("post_form");
247     f.addEventListener("submit", (e) => {
248     e.preventDefault();
249     post_article(f);
250     });
251     });
252    
253     </script>
254     </head>
255     <body>
256     <center>
257     <table border="0" cellpadding="1" cellspacing="0" width="770">
258     <tr>
259     <td>
260     <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;<?
261     if ($id == 0)
262     {
263     if ($reply_id > 0)
264     {
265     ?><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><?
266     }
267     else
268     {
269     ?><a class="s2" href="#">发表新文章</a><?
270     }
271     }
272     else
273     {
274     ?><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><?
275     }
276     ?>
277     </td>
278     </tr>
279     </table>
280     <form method="POST" ENCTYPE="multipart/form-data" id="post_form" name="post_form" action="#">
281     <table border="0" cellpadding="5" cellspacing="0" width="770">
282     <tr>
283     <td colspan="2" align="center" style="color:red;">别忙着发贴,请先看一下<a class="s0" href="doc/management.xml" target=_blank>《论坛管理章程》</a>吧!<br>
284     (请对您的言论负责,遵守有关法律、法规,尊重网络道德)</td>
285     </tr>
286     <tr height="10">
287     <td colspan="2"><span id="err_msg_prompt" name="err_msg" style="color: red;"></span></td>
288     </tr>
289     <tr>
290     <td width="10%" align="right">标题<span id="err_msg_title" name="err_msg" style="color: red;"></span></td>
291     <td width="90%">
292     <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')); ?>">
293     <?
294     if ($id == 0 && $reply_id == 0)
295     {
296     ?>
297     <input type="checkbox" name="transship">转载
298     <?
299     }
300     ?></td>
301     </tr>
302     <tr>
303     <td align="right">正文<span id="err_msg_content" name="err_msg" style="color: red;"></span></td>
304     <td>
305     <textarea name="content" id="content" cols="80" rows="25"><?
306     if ($reply_id == 0)
307     {
308     echo htmlspecialchars($content, ENT_HTML401, 'UTF-8');
309     }
310     else if ($quote)
311     {
312     ?>
313    
314    
315    
316     【 在 <? echo htmlspecialchars($r_username, ENT_HTML401, 'UTF-8'); ?> (<? echo htmlspecialchars($r_nickname, ENT_HTML401, 'UTF-8'); ?>) 的大作中提到: 】
317     <?
318     echo htmlspecialchars(LMLtagFilter(LML(split_line($content, ": ", 76, 20), false, false, 1024)), ENT_HTML401, 'UTF-8');
319     }
320     ?></textarea>
321     </td>
322     </tr>
323     <tr>
324     <td align="right"><a class="s0" href="doc/lml.htm" target=_blank>LML</a>助手</td>
325     <td>
326     <INPUT type="button" value="B" onclick="b_bold(content)" style="font-weight:bold; width:25px;">
327     <INPUT type="button" value="I" onclick="b_italic(content)" style="font-style:italic; width:25px;">
328     <INPUT type="button" value="U" onclick="b_underline(content)" style="text-decoration:underline; width:25px;">
329     <INPUT type="button" value="[" onclick="b_left(content)" style="width:20px;">
330     <INPUT type="button" value="]" onclick="b_right(content)" style="width:20px;">
331     <INPUT type="button" value="Aa" onclick="b_size(content)" style="width:30px;">
332     <INPUT type="button" value="A" onclick="b_color(content)" style="font-weight:bold; color:red; width:25px;">
333     <INPUT type="button" value="@" onclick="b_email(content)" style="width:25px;">
334     <INPUT type="button" value="Link" onclick="b_link(content)" style="text-decoration:underline; color:blue; width:40px;">
335     <INPUT type="button" value="主题" onclick="b_article(content)" style="text-decoration:underline; color:green; width:40px;">
336     <INPUT type="button" value="图片" onclick="b_image(content)" style="width:40px;">
337     <INPUT type="button" value="字幕" onclick="b_marquee(content)" style="width:40px;">
338     </td>
339     </tr>
340     <tr>
341     <td align="right">上传附件<span id="err_msg_attachment" name="err_msg" style="color: red;"</td>
342     <td>
343     单个文件大小不能超过<? echo $BBS_upload_size_limit; ?>M,
344     单次上传不超过<? echo $BBS_upload_count_limit; ?>个文件<br />
345     文件类型限于BMP,GIF,JPEG,PNG,TIFF,TXT,ZIP,RAR<br />
346     <INPUT TYPE=FILE SIZE=40 name="attachment[]" id="attachment" multiple>
347     <?
348     if ($id != 0) // Modify article
349     {
350     $sql = "SELECT * FROM upload_file WHERE ref_AID = $id
351     AND deleted = 0 AND deny = 0
352     ORDER BY AID";
353    
354     $rs = mysqli_query($db_conn, $sql);
355     if ($rs == false)
356     {
357     echo ("Read attachment error: " . mysqli_error($db_conn));
358     exit();
359     }
360    
361     if (mysqli_num_rows($rs) > 0)
362     {
363     ?>
364     <hr width="80%" align="left" />已上传附件<br />
365     <?
366     }
367    
368     while ($row = mysqli_fetch_array($rs))
369     {
370     $filename = $row["filename"];
371     $ext = strtolower(substr($filename, (strrpos($filename, ".") ? strrpos($filename, ".") + 1 : 0)));
372     ?>
373     <img src="images/closed.gif"><a class="s2" href="dl_file.php?aid=<? echo $row["AID"]; ?>" target="_target"><? echo $filename; ?></a> (<? echo $row["size"]; ?>字节)
374     <?
375     if ($row["check"] == 0)
376     {
377     ?><font color="red">未审核</font><?
378     }
379     ?>
380     <a class="s2" href="upload_del.php?aid=<? echo $row["AID"]; ?>&noecho=1" onclick="return window.confirm('真的要删除吗?');" target=hiddenframe>删除</a>
381     <br />
382     <?
383     }
384    
385     mysqli_free_result($rs);
386     }
387     ?>
388     </td>
389     </tr>
390     <tr>
391     <td align="right">表情<span id="err_msg_emoji" name="err_msg" style="color: red;"></td>
392     <td><?
393     for ($i = 1; $i <= $BBS_emoji_count; $i++)
394     {
395     ?><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"><?
396     if (($i % 12)==0)
397     {
398     ?><br><?
399     }
400     }
401     ?></td>
402     </tr>
403     <?
404     if ($id == 0)
405     {
406     ?>
407     <tr>
408     <td align="right"><span id="err_msg_sign" name="err_msg" style="color: red;"></td>
409     <td>
410     <input type="checkbox" name="use_sign">使用我的个人签名&nbsp;
411     <input type="radio" id="sign_id_1" name="sign_id" value="1" checked>1&nbsp;
412     <input type="radio" id="sign_id_2" name="sign_id" value="2">2&nbsp;
413     <input type="radio" id="sign_id_3" name="sign_id" value="3">3&nbsp;
414     <a class="s0" href="" onclick="return NW_open('preference.php', 'member_service', 500, 550);">设置个人签名</a>
415     </td>
416     </tr>
417     <?
418     }
419     ?>
420     <tr>
421     <td align="right"></td>
422     <td><input type="checkbox" name="reply_note" id="reply_note" <? echo ($reply_note ? "checked":""); ?>>有人回复该主题时通知我</td>
423     </tr>
424     </table>
425     <p><input type="submit" value="提交" name="submit">&nbsp;&nbsp;&nbsp;<input type="reset" value="重填" name="reset"></p>
426     </center>
427     </form>
428     <?
429     mysqli_close($db_conn);
430    
431     include "./foot.inc.php";
432     ?>
433     </body>
434     </html>

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