2
0
Эх сурвалжийг харах

버그 수정 및 다른 스레드 인용 기

https://github.com/openNAMU/openNAMU/issues/1848
잉여개발기 (SPDV) 2 жил өмнө
parent
commit
4086fb6e7b

+ 107 - 2
route/api_topic.py

@@ -1,5 +1,110 @@
 from .tool.func import *
-from .bbs_w_post import bbs_w_post_make_thread
+
+def api_topic_thread_make(user_id, date, data, code, color = '', blind = '', add_style = ''):
+    if blind != '':
+        if data == '':
+            color_b = 'opennamu_comment_blind'
+        else:
+            color_b = 'opennamu_comment_blind_admin'
+    else:
+        color_b = 'opennamu_comment_blind_not'
+
+    return '''
+        <table class="opennamu_comment" style="''' + add_style + '''">
+            <tr>
+                <td class="opennamu_comment_color_''' + color + '''">
+                    <a href="#thread_shortcut" id="''' + code + '''">#''' + code + '''</a>
+                    ''' + user_id + '''
+                    <span style="float: right;">''' + date + '''</span>
+                </td>
+            </tr>
+            <tr>
+                <td class="''' + color_b + '''" id="opennamu_comment_data_main">
+                    ''' + data + '''
+                </td>
+            </tr>
+        </table>
+    '''
+
+def api_topic_thread_pre_render(curs, data, num, ip, topic_num = '', name = '', sub = '', do_type = 'thread'):
+    call_thread_regex = r"( |\n|^)(?:#([0-9]+)(?:-([0-9]+))?)( |\n|$)"
+    call_thread_count = len(re.findall(call_thread_regex, data)) * 3
+    while 1:
+        rd_data = re.search(call_thread_regex, data)
+        if call_thread_count < 0:
+            break
+        elif not rd_data:
+            break
+        else:
+            rd_data = rd_data.groups()
+
+            view_data = rd_data[1]
+            send_topic_num = topic_num
+            if rd_data[2]:
+                view_data += '-' + rd_data[2]
+                if do_type == 'thread':
+                    send_topic_num = rd_data[2]
+                else:
+                    set_id = topic_num.split('-')
+
+                    send_topic_num = set_id[0] + '-' + rd_data[2]
+                    view_data += '-' + set_id[0]
+
+            print(send_topic_num, rd_data[1])
+            if do_type == 'thread':
+                curs.execute(db_change("select ip from topic where code = ? and id = ?"), [send_topic_num, rd_data[1]])
+            else:
+                if rd_data[1] == '0':
+                    set_id = send_topic_num.split('-')
+                    set_id = ['', ''] if len(set_id) < 2 else set_id
+
+                    curs.execute(db_change('select set_data from bbs_data where set_name = "user_id" and set_id = ? and set_code = ?'), [set_id[0], set_id[1]])
+                else:
+                    curs.execute(db_change('select set_data from bbs_data where set_name = "comment_user_id" and set_id = ? and set_code = ?'), [send_topic_num, rd_data[1]])
+
+            ip_data = curs.fetchall()
+            if ip_data and ip_or_user(ip_data[0][0]) == 0:
+                if do_type == 'thread':
+                    add_alarm(ip_data[0][0], ip, '<a href="/thread/' + topic_num + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
+                else:
+                    set_id = topic_num.split('-')
+                    set_id = ['', ''] if len(set_id) < 2 else set_id
+
+                    add_alarm(ip_data[0][0], ip, 'BBS <a href="/bbs/w/' + set_id[0] + '/' + set_id[1] + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
+
+            data = re.sub(call_thread_regex, rd_data[0] + '<topic_a_' + do_type + '>#' + view_data + '</topic_a_' + do_type + '>' + rd_data[3], data, 1)
+
+        call_thread_count -= 1
+
+    call_user_regex = r"( |\n|^)(?:@([^ \n]+))( |\n|$)"
+    call_user_count = len(re.findall(call_user_regex, data)) * 3
+    while 1:
+        rd_data = re.search(call_user_regex, data)
+        if call_user_count < 0:
+            break
+        elif not rd_data:
+            break
+        else:
+            rd_data = rd_data.groups()
+
+            curs.execute(db_change("select ip from history where ip = ? limit 1"), [rd_data[1]])
+            ip_data = curs.fetchall()
+            if not ip_data:
+                curs.execute(db_change("select ip from topic where ip = ? limit 1"), [rd_data[1]])
+                ip_data = curs.fetchall()
+
+            if ip_data and ip_or_user(ip_data[0][0]) == 0:
+                if do_type == 'thread':
+                    add_alarm(ip_data[0][0], ip, '<a href="/thread/' + topic_num + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
+                else:
+                    set_id = topic_num.split('-')
+                    add_alarm(ip_data[0][0], ip, 'BBS <a href="/bbs/w/' + set_id[0] + '/' + set_id[1] + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
+
+            data = re.sub(call_user_regex, rd_data[0] + '<topic_call>@' + rd_data[1] + '</topic_call>' + rd_data[2], data, 1)
+
+        call_user_count -= 1
+
+    return data
 
 def api_topic(topic_num = 1, tool = 'normal', num = '', render = ''):
     with get_db_connect() as conn:
@@ -77,7 +182,7 @@ def api_topic(topic_num = 1, tool = 'normal', num = '', render = ''):
                                 else:
                                     color = 'default'
 
-                            data_r += bbs_w_post_make_thread(
+                            data_r += api_topic_thread_make(
                                 for_a["ip_pas"],
                                 '<a href="/thread/' + topic_num + '/comment/' + for_a["id"] + '/tool">(' + load_lang('tool') + ')</a> ' + for_a["date"],
                                 for_a["data_pas"][0] + '<script>' + for_a["data_pas"][1] + '</script>',

+ 9 - 33
route/bbs_w_post.py

@@ -2,33 +2,9 @@ from .tool.func import *
 
 from .api_bbs_w_post import api_bbs_w_post
 from .api_bbs_w_comment import api_bbs_w_comment
-from .edit import edit_editor
+from .api_topic import api_topic_thread_make, api_topic_thread_pre_render
 
-def bbs_w_post_make_thread(user_id, date, data, code, color = '', blind = '', add_style = ''):
-    if blind != '':
-        if data == '':
-            color_b = 'opennamu_comment_blind'
-        else:
-            color_b = 'opennamu_comment_blind_admin'
-    else:
-        color_b = 'opennamu_comment_blind_not'
-
-    return '''
-        <table class="opennamu_comment" style="''' + add_style + '''">
-            <tr>
-                <td class="opennamu_comment_color_''' + color + '''">
-                    <a href="#thread_shortcut" id="''' + code + '''">#''' + code + '''</a>
-                    ''' + user_id + '''
-                    <span style="float: right;">''' + date + '''</span>
-                </td>
-            </tr>
-            <tr>
-                <td class="''' + color_b + '''" id="opennamu_comment_data_main">
-                    ''' + data + '''
-                </td>
-            </tr>
-        </table>
-    '''
+from .edit import edit_editor
 
 def bbs_w_post_comment(user_id, sub_code, comment_num, bbs_num_str, post_num_str):
     comment_data = ''
@@ -56,7 +32,7 @@ def bbs_w_post_comment(user_id, sub_code, comment_num, bbs_num_str, post_num_str
         date += temp_dict['comment_date']
 
         comment_data += '<span style="padding-left: 20px;"></span>' * margin_count
-        comment_data += bbs_w_post_make_thread(
+        comment_data += api_topic_thread_make(
             ip_pas(temp_dict['comment_user_id']),
             date,
             render_set(
@@ -129,7 +105,7 @@ def bbs_w_post(bbs_num = '', post_num = '', do_type = ''):
                     return redirect('/bbs/w/' + bbs_num_str + '/' + post_num_str)
                 
                 data = data.replace('\r', '')
-                data = get_thread_pre_render(data, id_data, ip, set_id, bbs_name, temp_dict['title'], 'post')
+                data = api_topic_thread_pre_render(curs, data, id_data, ip, set_id, bbs_name, temp_dict['title'], 'post')
                 
                 date = get_time()
 
@@ -164,7 +140,7 @@ def bbs_w_post(bbs_num = '', post_num = '', do_type = ''):
 
                 data = ''
                 data += '<h2>' + html.escape(temp_dict['title']) + '</h2>'
-                data += bbs_w_post_make_thread(
+                data += api_topic_thread_make(
                     ip_pas(temp_dict['user_id']),
                     date,
                     render_set(
@@ -172,13 +148,13 @@ def bbs_w_post(bbs_num = '', post_num = '', do_type = ''):
                         data_type = 'thread',
                         data_in = 'bbs'
                     ),
-                    '1',
+                    '0',
                     color = 'green'
                 )
                 data += '<hr class="main_hr">'
 
                 user_id = temp_dict['user_id']
-                count = 1
+                count = 0
 
                 thread_data = json.loads(api_bbs_w_comment(bbs_num_str + '-' + post_num_str).data)
                 for temp_dict in thread_data:
@@ -192,7 +168,7 @@ def bbs_w_post(bbs_num = '', post_num = '', do_type = ''):
                     date += '<a href="/bbs/w/' + bbs_num_str + '/' + post_num_str + '/comment/' + str(count) + '/tool">(' + load_lang('tool') + ')</a> '
                     date += temp_dict['comment_date']
 
-                    data += bbs_w_post_make_thread(
+                    data += api_topic_thread_make(
                         ip_pas(temp_dict['comment_user_id']),
                         date,
                         render_set(
@@ -322,7 +298,7 @@ def bbs_w_post(bbs_num = '', post_num = '', do_type = ''):
 
                 data = ''
                 data += '<h2>' + html.escape(temp_dict['title']) + '</h2>'
-                data += bbs_w_post_make_thread(
+                data += api_topic_thread_make(
                     ip_pas(temp_dict['user_id']),
                     date,
                     render_set(

+ 0 - 61
route/tool/func.py

@@ -1468,67 +1468,6 @@ def render_simple_set(data):
 
     return data
 
-def get_thread_pre_render(data, num, ip, topic_num = '', name = '', sub = '', do_type = 'thread'):
-    curs = conn.cursor()
-
-    call_thread_regex = r"( |\n|^)(?:#([0-9]+))( |\n|$)"
-    call_thread_count = len(re.findall(call_thread_regex, data)) * 3
-    while 1:
-        rd_data = re.search(call_thread_regex, data)
-        if call_thread_count < 0:
-            break
-        elif not rd_data:
-            break
-        else:
-            rd_data = rd_data.groups()
-
-            if do_type == 'thread':
-                curs.execute(db_change("select ip from topic where code = ? and id = ?"), [topic_num, rd_data[1]])
-            else:
-                curs.execute(db_change('select set_data from bbs_data where set_name = "comment_user_id" and set_id = ? and set_code = ?'), [topic_num, rd_data[1]])
-
-            ip_data = curs.fetchall()
-            if ip_data and ip_or_user(ip_data[0][0]) == 0:
-                if do_type == 'thread':
-                    add_alarm(ip_data[0][0], ip, '<a href="/thread/' + topic_num + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
-                else:
-                    set_id = topic_num.split('-')
-                    add_alarm(ip_data[0][0], ip, 'BBS <a href="/bbs/w/' + set_id[0] + '/' + set_id[1] + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
-
-            data = re.sub(call_thread_regex, rd_data[0] + '<topic_a>#' + rd_data[1] + '</topic_a>' + rd_data[2], data, 1)
-
-        call_thread_count -= 1
-
-    call_user_regex = r"( |\n|^)(?:@([^ \n]+))( |\n|$)"
-    call_user_count = len(re.findall(call_user_regex, data)) * 3
-    while 1:
-        rd_data = re.search(call_user_regex, data)
-        if call_user_count < 0:
-            break
-        elif not rd_data:
-            break
-        else:
-            rd_data = rd_data.groups()
-
-            curs.execute(db_change("select ip from history where ip = ? limit 1"), [rd_data[1]])
-            ip_data = curs.fetchall()
-            if not ip_data:
-                curs.execute(db_change("select ip from topic where ip = ? limit 1"), [rd_data[1]])
-                ip_data = curs.fetchall()
-
-            if ip_data and ip_or_user(ip_data[0][0]) == 0:
-                if do_type == 'thread':
-                    add_alarm(ip_data[0][0], ip, '<a href="/thread/' + topic_num + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
-                else:
-                    set_id = topic_num.split('-')
-                    add_alarm(ip_data[0][0], ip, 'BBS <a href="/bbs/w/' + set_id[0] + '/' + set_id[1] + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
-
-            data = re.sub(call_user_regex, rd_data[0] + '<topic_call>@' + rd_data[1] + '</topic_call>' + rd_data[2], data, 1)
-
-        call_user_count -= 1
-
-    return data
-
 # Func-request
 def send_email(who, title, data):
     curs = conn.cursor()

+ 14 - 2
route/tool/func_render.py

@@ -61,9 +61,21 @@ class class_do_render:
             ]
 
         if data_type == 'thread' or data_type == 'api_thread':
+            def do_thread_a_change(match):
+                data = match[2].replace('#', '')
+                data_split = data.split('-')
+                if match[1] == 'topic_a' or len(data_split) == 1:
+                    return '<a href="' + match[2] + '">' + match[2] + '</a>'
+                elif match[1] == 'topic_a_post' and len(data_split) == 3:
+                    return '<a href="/bbs/w/' + data_split[2] + '/' + data_split[1] + '#' + data_split[0] + '">#' + data_split[0] + '-' + data_split[1] + '</a>'
+                elif len(data_split) == 2:
+                    return '<a href="/thread/' + data_split[1] + '#' + data_split[0] + '">' + match[2] + '</a>'
+                else:
+                    return ''
+
             data_end[0] = re.sub(
-                r'&lt;topic_a&gt;(?P<in>(?:(?!&lt;\/topic_a&gt;).)+)&lt;\/topic_a&gt;',
-                '<a href="\\g<in>">\\g<in></a>',
+                r'&lt;(topic_a(?:_post|_thread)?)&gt;((?:(?!&lt;\/topic_a(?:_post|_thread)?&gt;).)+)&lt;\/topic_a(?:_post|_thread)?&gt;',
+                do_thread_a_change,
                 data_end[0]
             )
             data_end[0] = re.sub(

+ 3 - 2
route/topic.py

@@ -1,6 +1,7 @@
 from .tool.func import *
 
-from .api_topic import api_topic
+from .api_topic import api_topic, api_topic_thread_pre_render
+
 from .edit import edit_editor
 
 def topic(topic_num = 0, do_type = '', doc_name = 'Test'):
@@ -79,7 +80,7 @@ def topic(topic_num = 0, do_type = '', doc_name = 'Test'):
                 add_alarm(ip_data[0][0], ip, '<a href="/thread/' + topic_num + '#' + num + '">' + html.escape(name) + ' - ' + html.escape(sub) + '#' + num + '</a>')
 
             data = flask.request.form.get('content', 'Test').replace('\r', '')
-            data = get_thread_pre_render(data, num, ip, topic_num, name, sub)
+            data = api_topic_thread_pre_render(curs, data, num, ip, topic_num, name, sub)
 
             do_add_thread(
                 topic_num,

+ 1 - 1
version.json

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