瀏覽代碼

BBS 댓글 수정 기능

잉여개발기 (SPDV) 2 年之前
父節點
當前提交
25e18d527b
共有 3 個文件被更改,包括 66 次插入32 次删除
  1. 2 0
      app.py
  2. 63 31
      route/bbs_w_edit.py
  3. 1 1
      version.json

+ 2 - 0
app.py

@@ -531,6 +531,8 @@ app.route('/bbs/edit/preview/<int:bbs_num>/<int:post_num>', methods = ['POST', '
 app.route('/bbs/w/preview/<int:bbs_num>/<int:post_num>', methods = ['POST'], defaults = { 'do_type' : 'preview' })(bbs_w_post)
 app.route('/bbs/tool/<int:bbs_num>/<int:post_num>/<comment_num>')(bbs_w_comment_tool)
 app.route('/bbs/raw/<int:bbs_num>/<int:post_num>/<comment_num>')(view_raw_2)
+app.route('/bbs/edit/<int:bbs_num>/<int:post_num>/<comment_num>', methods = ['POST', 'GET'])(bbs_w_edit)
+app.route('/bbs/edit/preview/<int:bbs_num>/<int:post_num>/<comment_num>', methods = ['POST', 'GET'])(bbs_w_edit)
 
 # Func-api
 app.route('/api/w/<everything:name>/doc_tool/<tool>/doc_rev/<int(signed = True):rev>')(api_w)

+ 63 - 31
route/bbs_w_edit.py

@@ -1,9 +1,10 @@
 from .tool.func import *
 
 from .api_bbs_w_post import api_bbs_w_post
+from .api_bbs_w_comment_one import api_bbs_w_comment_one
 from .edit import edit_editor
 
-def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
+def bbs_w_edit(bbs_num = '', post_num = '', comment_num = '', do_type = ''):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
@@ -16,14 +17,20 @@ def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
         if not curs.fetchall():
             return redirect('/bbs/main')
         
-        if post_num != '':
-            curs.execute(db_change('select set_data from bbs_data where set_name = "user_id" and set_id = ? and set_code = ?'), [bbs_num, post_num])
-            db_data = curs.fetchall()
-            if not db_data:
-                return redirect('/bbs/main')
+        if comment_num != '':
+            temp_dict = json.loads(api_bbs_w_comment_one(bbs_num_str + '-' + post_num_str + '-' + comment_num).data)
+            if 'comment_user_id' in temp_dict:
+                if not temp_dict['comment_user_id'] == ip and admin_check() != 1:
+                    return re_error('/ban')
             else:
-                if not db_data[0][0] == ip and admin_check() != 1:
+                return redirect('/bbs/main')
+        elif post_num != '':
+            temp_dict = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
+            if 'user_id' in temp_dict:
+                if not temp_dict['user_id'] == ip and admin_check() != 1:
                     return re_error('/ban')
+            else:
+                return redirect('/bbs/main')
             
         if acl_check(bbs_num_str, 'bbs_edit') == 1:
             return redirect('/bbs/set/' + bbs_num_str)
@@ -52,7 +59,17 @@ def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
             
             date = get_time()
 
-            if post_num == '':
+            if comment_num != '':
+                sub_code = (bbs_num_str + '-' + post_num_str + '-' + comment_num).split('-')
+                sub_code_last = ''
+                if len(sub_code) > 2:
+                    sub_code_last = sub_code[len(sub_code) - 1]
+                    del sub_code[len(sub_code) - 1]
+                    
+                sub_code = '-'.join(sub_code)
+
+                curs.execute(db_change("update bbs_data set set_data = ? where set_name = 'comment' and set_code = ? and set_id = ?"), [data, sub_code_last, sub_code])
+            elif post_num == '':
                 curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('title', ?, ?, ?)"), [id_data, bbs_num_str, title])
                 curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('data', ?, ?, ?)"), [id_data, bbs_num_str, data])
                 curs.execute(db_change("insert into bbs_data (set_name, set_code, set_id, set_data) values ('date', ?, ?, ?)"), [id_data, bbs_num_str, date])
@@ -62,8 +79,13 @@ def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
                 curs.execute(db_change("update bbs_data set set_data = ? where set_name = 'data' and set_code = ? and set_id = ?"), [data, id_data, bbs_num_str])
                 curs.execute(db_change("update bbs_data set set_data = ? where set_name = 'date' and set_code = ? and set_id = ?"), [date, id_data, bbs_num_str])
 
-            return redirect('/bbs/w/' + bbs_num_str + '/' + id_data)
+            if comment_num != '':
+                return redirect('/bbs/w/' + bbs_num_str + '/' + id_data + '#' + url_pas(comment_num))
+            else:
+                return redirect('/bbs/w/' + bbs_num_str + '/' + id_data)
         else:
+            option_display = ''
+
             d_list = ['' for _ in range(0, len(i_list))]
             if do_type == 'preview':
                 title = flask.request.form.get('title', '')
@@ -77,15 +99,18 @@ def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
                 for for_a in range(0, len(i_list)):
                     d_list[for_a] = flask.request.form.get(i_list[for_a], 'normal')
             else:
-                if post_num == '':
+                if comment_num != '':
+                    temp_dict = json.loads(api_bbs_w_comment_one(bbs_num_str + '-' + post_num_str + '-' + comment_num).data)
+
+                    title = ''
+                    data = temp_dict['comment']
+                    data_preview = ''
+                    option_display = 'display: none;'
+                elif post_num == '':
                     title = ''
                     data = ''
                     data_preview = ''
                 else:
-                    curs.execute(db_change('select set_name, set_data, set_code from bbs_data where set_id = ? and set_code = ?'), [bbs_num, post_num])
-                    db_data = curs.fetchall()
-                    db_data = list(db_data) if db_data else []
-
                     temp_dict = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
 
                     title = temp_dict['title']
@@ -103,7 +128,10 @@ def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
 
                     acl_div[for_a] += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
             
-            if post_num == '':
+            if comment_num != '':
+                form_action = 'formaction="/bbs/edit/' + bbs_num_str + '/' + post_num_str + '/' + url_pas(comment_num) + '"'
+                form_action_preview = 'formaction="/bbs/edit/preview/' + bbs_num_str + '/' + post_num_str + '/' + url_pas(comment_num) + '"'
+            elif post_num == '':
                 form_action = 'formaction="/bbs/edit/' + bbs_num_str + '"'
                 form_action_preview = 'formaction="/bbs/edit/preview/' + bbs_num_str + '"'
             else:
@@ -115,7 +143,9 @@ def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
             if editor_top_text != '':
                 editor_top_text += '<hr class="main_hr">'
 
-            if post_num == '':
+            if comment_num != '':
+                bbs_title = load_lang('bbs_comment_edit')
+            elif post_num == '':
                 bbs_title = load_lang('post_add')
             else:
                 bbs_title = load_lang('post_edit')
@@ -124,8 +154,8 @@ def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
                 imp = [bbs_title, wiki_set(), wiki_custom(), wiki_css([0, 0])],
                 data =  editor_top_text + '''
                     <form method="post">                        
-                        <input placeholder="''' + load_lang('title') + '''" name="title" value="''' + html.escape(title) + '''">
-                        <hr class="main_hr">
+                        <input style="''' + option_display + '''" placeholder="''' + load_lang('title') + '''" name="title" value="''' + html.escape(title) + '''">
+                        <hr style="''' + option_display + '''" class="main_hr">
 
                         ''' + edit_editor(curs, ip, data, 'bbs') + '''
                         <hr class="main_hr">
@@ -138,19 +168,21 @@ def bbs_w_edit(bbs_num = '', post_num = '', do_type = ''):
                         <hr class="main_hr">
                         <div id="opennamu_preview_area">''' + data_preview + '''</div>
 
-                        ''' + render_simple_set('''
-                            <hr class="main_hr">
-                            <a href="/acl/TEST#exp">(''' + load_lang('reference') + ''')</a>
-                            <h2>''' + load_lang('acl') + '''</h2>
-                            <h3>''' + load_lang('post_view_acl') + '''</h3>
-                            <select name="post_view_acl">''' + acl_div[0] + '''</select>
-
-                            <h4>''' + load_lang('post_comment_acl') + '''</h4>
-                            <select name="post_comment_acl">''' + acl_div[1] + '''</select>
-
-                            <h2>''' + load_lang('markup') + '''</h2>
-                            ''' + load_lang('not_working') + '''
-                        ''') + '''
+                        <div style="''' + option_display + '''">
+                            ''' + render_simple_set('''
+                                <hr class="main_hr">
+                                <a href="/acl/TEST#exp">(''' + load_lang('reference') + ''')</a>
+                                <h2>''' + load_lang('acl') + '''</h2>
+                                <h3>''' + load_lang('post_view_acl') + '''</h3>
+                                <select name="post_view_acl">''' + acl_div[0] + '''</select>
+
+                                <h4>''' + load_lang('post_comment_acl') + '''</h4>
+                                <select name="post_comment_acl">''' + acl_div[1] + '''</select>
+
+                                <h2>''' + load_lang('markup') + '''</h2>
+                                ''' + load_lang('not_working') + '''
+                            ''') + '''
+                        </div>
                     </form>
                 ''',
                 menu = [['bbs/w/' + bbs_num_str, load_lang('return')]]

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.6-RC3-dev217",
+        "r_ver" : "v3.4.6-RC3-dev218",
         "c_ver" : "3500361",
         "s_ver" : "3500111"
     }