2
0
2du 4 жил өмнө
parent
commit
7e0aeb6560
5 өөрчлөгдсөн 187 нэмэгдсэн , 185 устгасан
  1. 2 7
      app.py
  2. 5 1
      route/main_func_setting.py
  3. 132 108
      route/topic.py
  4. 47 68
      route/topic_close_list.py
  5. 1 1
      version.json

+ 2 - 7
app.py

@@ -652,13 +652,8 @@ def topic_change(topic_num = 1):
 def topic_admin(topic_num = 1, num = 1):
     return topic_admin_2(load_db.db_get(), topic_num, num)
 
-@app.route('/thread/<int:topic_num>', methods = ['POST', 'GET'])
-def topic(topic_num = 1):
-    return topic_2(load_db.db_get(), topic_num)
-
-@app.route('/topic/<everything:name>', methods = ['POST', 'GET'])
-def topic_close_list(name = 'test'):
-    return topic_close_list_2(load_db.db_get(), name)
+app.route('/thread/<int:topic_num>', methods = ['POST', 'GET'])(topic)
+app.route('/topic/<everything:name>', methods = ['POST', 'GET'])(topic_close_list)
 
 # Func-user
 @app.route('/change', methods = ['POST', 'GET'])

+ 5 - 1
route/main_func_setting.py

@@ -243,7 +243,8 @@ def main_func_setting(db_set, num = 0):
                 'edit_help',
                 'upload_help',
                 'upload_default',
-                'license'
+                'license',
+                'topic_text'
             ]
             if flask.request.method == 'POST':
                 for i in i_list:
@@ -328,6 +329,9 @@ def main_func_setting(db_set, num = 0):
 
                             <h2>17. ''' + load_lang('bottom_text') + ''' (HTML)</h2>
                             <textarea rows="3" name="''' + i_list[16] + '''">''' + html.escape(d_list[16]) + '''</textarea>
+                            
+                            <h2>18. ''' + load_lang('topic_text') + '''</h2>
+                            <textarea rows="3" name="''' + i_list[17] + '''">''' + html.escape(d_list[17]) + '''</textarea>
 
                             <hr class="main_hr">
                             <button id="save" type="submit">''' + load_lang('save') + '''</button>

+ 132 - 108
route/topic.py

@@ -1,121 +1,145 @@
 from .tool.func import *
 
-def topic_2(conn, topic_num):
-    curs = conn.cursor()
-    topic_num = str(topic_num)
-
-    if flask.request.method == 'POST':
-        name = flask.request.form.get('topic', 'test')
-        sub = flask.request.form.get('title', 'test')
-    else:
-        curs.execute(db_change("select title, sub from rd where code = ?"), [topic_num])
-        name = curs.fetchall()
-        if name:
-            sub = name[0][1]
-            name = name[0][0]
+def topic(topic_num = 0):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+        topic_num = str(topic_num)
+
+        if flask.request.method == 'POST':
+            name = flask.request.form.get('topic', 'Test')
+            sub = flask.request.form.get('title', 'Test')
+            
+            if topic_num == '0':
+                curs.execute(db_change("select code from topic order by code + 0 desc limit 1"))
+                t_data = curs.fetchall()
+                topic_num = str(int(t_data[0][0]) + 1) if t_data else '1'
         else:
-            return redirect('/')
+            if topic_num == '0':
+                name = load_lang('make_new_topic')
+                sub = load_lang('make_new_topic')
+            else:
+                curs.execute(db_change("select title, sub from rd where code = ?"), [topic_num])
+                name = curs.fetchall()
+                if name:
+                    sub = name[0][1]
+                    name = name[0][0]
+                else:
+                    return redirect('/')
 
-    ban = acl_check(name, 'topic', topic_num)
+        ban = acl_check(name, 'topic', topic_num)
 
-    if flask.request.method == 'POST':
-        if flask.request.form.get('content', 'Test') == '':
-            return redirect('/thread/' + topic_num)
+        if flask.request.method == 'POST':
+            if flask.request.form.get('content', 'Test') == '':
+                return redirect('/thread/' + topic_num)
 
-        if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
-            return re_error('/error/13')
-        else:
-            captcha_post('', 0)
-
-        ip = ip_check()
-        today = get_time()
-
-        if ban == 1:
-            return re_error('/ban')
-
-        curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
-        old_num = curs.fetchall()
-        num = str((int(old_num[0][0]) + 1) if old_num else 1)
-
-        match = re.search(r'^user:([^/]+)', name)
-        if match:
-            match = match.group(1)
-            y_check = 0
-            if ip_or_user(match) == 1:
-                curs.execute(db_change("select ip from history where ip = ? limit 1"), [match])
-                u_data = curs.fetchall()
-                if u_data:
-                    y_check = 1
+            if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
+                return re_error('/error/13')
+            else:
+                captcha_post('', 0)
+
+            ip = ip_check()
+            today = get_time()
+
+            if ban == 1:
+                return re_error('/ban')
+
+            curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
+            old_num = curs.fetchall()
+            num = str((int(old_num[0][0]) + 1) if old_num else 1)
+
+            match = re.search(r'^user:([^/]+)', name)
+            if match:
+                match = match.group(1)
+                y_check = 0
+                if ip_or_user(match) == 1:
+                    curs.execute(db_change("select ip from history where ip = ? limit 1"), [match])
+                    u_data = curs.fetchall()
+                    if u_data:
+                        y_check = 1
+                    else:
+                        curs.execute(db_change("select ip from topic where ip = ? limit 1"), [match])
+                        u_data = curs.fetchall()
+                        if u_data:
+                            y_check = 1
                 else:
-                    curs.execute(db_change("select ip from topic where ip = ? limit 1"), [match])
+                    curs.execute(db_change("select id from user_set where id = ?"), [match])
                     u_data = curs.fetchall()
                     if u_data:
                         y_check = 1
-            else:
-                curs.execute(db_change("select id from user_set where id = ?"), [match])
-                u_data = curs.fetchall()
-                if u_data:
-                    y_check = 1
-
-            if y_check == 1:
-                add_alarm(match, ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>')
-
-        cate_re = re.compile(r'\[\[((?:분류|category):(?:(?:(?!\]\]).)*))\]\]', re.I)
-        data = cate_re.sub('[br]', flask.request.form.get('content', 'Test').replace('\r', ''))
-
-        for rd_data in re.findall(r"(?: |\n|^)(#(?:[0-9]+))(?: |\n|$)", data):
-            curs.execute(db_change("select ip from topic where code = ? and id = ?"), [topic_num, rd_data])
-            ip_data = curs.fetchall()
-            if ip_data and ip_or_user(ip_data[0][0]) == 0:
-                add_alarm(ip_data[0][0], ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>')
-
-        for rd_data in re.findall(r"(?: |\n|^)@((?:[^ ]+))(?: |\n|$)", data):
-            curs.execute(db_change("select ip from history where ip = ? limit 1"), [rd_data])
-            ip_data = curs.fetchall()
-            if not ip_data:
-                curs.execute(db_change("select ip from topic where ip = ? limit 1"), [rd_data])
+
+                if y_check == 1:
+                    add_alarm(match, ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>')
+
+            cate_re = re.compile(r'\[\[((?:분류|category):(?:(?:(?!\]\]).)*))\]\]', re.I)
+            data = cate_re.sub('[br]', flask.request.form.get('content', 'Test').replace('\r', ''))
+
+            for rd_data in re.findall(r"(?: |\n|^)(#(?:[0-9]+))(?: |\n|$)", data):
+                curs.execute(db_change("select ip from topic where code = ? and id = ?"), [topic_num, rd_data])
                 ip_data = curs.fetchall()
+                if ip_data and ip_or_user(ip_data[0][0]) == 0:
+                    add_alarm(ip_data[0][0], ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>')
 
-            if ip_data and ip_or_user(ip_data[0][0]) == 0:
-                add_alarm(ip_data[0][0], ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>')
-
-        data = re.sub(r"( |\n|^)(#(?:[0-9]+))( |\n|$)", '\g<1><topic_a>\g<2></topic_a>\g<3>', data)
-        data = re.sub(r"( |\n|^)(@(?:[^ ]+))( |\n|$)", '\g<1><topic_call>\g<2></topic_call>\g<3>', data)
-
-        rd_plus(topic_num, today, name, sub)
-        curs.execute(db_change("insert into topic (id, data, date, ip, code) values (?, ?, ?, ?, ?)"), [
-            num,
-            data,
-            today,
-            ip,
-            topic_num
-        ])
-        conn.commit()
-
-        return redirect('/thread/' + topic_num + '#' + num)
-    else:
-        display = 'display: none;' if ban == 1 else ''
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('discussion') + ')', 0])],
-            data = '''
-                <h2 id="topic_top_title">''' + html.escape(sub) + '''</h2>
-                <div id="top_topic"></div>
-                <div id="main_topic"></div>
-                <div id="plus_topic"></div>
-                <script>new_topic_load("''' + topic_num + '''");</script>
-                <a href="/thread/''' + topic_num + '/tool">(' + load_lang('topic_tool') + ''')</a>
-                <hr class="main_hr">
-                <form style="''' + display + '''" method="post">
-                    <textarea id="textarea_edit_view" class="topic_content" placeholder="''' + load_lang('content') + '''" name="content"></textarea>
+            for rd_data in re.findall(r"(?: |\n|^)@((?:[^ ]+))(?: |\n|$)", data):
+                curs.execute(db_change("select ip from history where ip = ? limit 1"), [rd_data])
+                ip_data = curs.fetchall()
+                if not ip_data:
+                    curs.execute(db_change("select ip from topic where ip = ? limit 1"), [rd_data])
+                    ip_data = curs.fetchall()
+
+                if ip_data and ip_or_user(ip_data[0][0]) == 0:
+                    add_alarm(ip_data[0][0], ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>')
+
+            data = re.sub(r"( |\n|^)(#(?:[0-9]+))( |\n|$)", '\g<1><topic_a>\g<2></topic_a>\g<3>', data)
+            data = re.sub(r"( |\n|^)(@(?:[^ ]+))( |\n|$)", '\g<1><topic_call>\g<2></topic_call>\g<3>', data)
+
+            rd_plus(topic_num, today, name, sub)
+            curs.execute(db_change("insert into topic (id, data, date, ip, code) values (?, ?, ?, ?, ?)"), [
+                num,
+                data,
+                today,
+                ip,
+                topic_num
+            ])
+            conn.commit()
+
+            return redirect('/thread/' + topic_num + '#' + num)
+        else:
+            display = 'display: none;' if ban == 1 else ''
+            data_input_topic_name = ''
+            if topic_num == '0':
+                data_input_topic_name = '' + \
+                    '<input placeholder="' + load_lang('discussion_name') + '" name="title">' + \
+                    '<hr class="main_hr">' + \
+                    '<input placeholder="' + load_lang('document_name') + '" name="topic">' + \
+                    '<hr class="main_hr">' + \
+                ''
+                
+            curs.execute(db_change('select data from other where name = "topic_text"'))
+            sql_d = curs.fetchall()
+            topic_text = html.escape(sql_d[0][0]) if sql_d and sql_d[0][0] != '' else load_lang('content')
+
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('discussion') + ')', 0])],
+                data = '''
+                    <h2 id="topic_top_title">''' + html.escape(sub) + '''</h2>
+                    <div id="top_topic"></div>
+                    <div id="main_topic"></div>
+                    <div id="plus_topic"></div>
+                    <script>new_topic_load("''' + topic_num + '''");</script>
+                    <a href="/thread/''' + topic_num + '/tool">(' + load_lang('topic_tool') + ''')</a>
+                    <hr class="main_hr">
+                    <form style="''' + display + '''" method="post">
+                        ''' + data_input_topic_name + '''
+                        <textarea id="textarea_edit_view" class="topic_content" placeholder="''' + topic_text + '''" name="content"></textarea>
+                        <hr class="main_hr">
+                        ''' + captcha_get() + (ip_warning() if display == '' else '') + '''
+                        <input style="display: none;" name="topic" value="''' + name + '''">
+                        <input style="display: none;" name="title" value="''' + sub + '''">
+                        <button id="save" type="submit">''' + load_lang('send') + '''</button>
+                        <button id="preview" type="button" onclick="load_preview(\'\')">''' + load_lang('preview') + '''</button>
+                    </form>
                     <hr class="main_hr">
-                    ''' + captcha_get() + (ip_warning() if display == '' else '') + '''
-                    <input style="display: none;" name="topic" value="''' + name + '''">
-                    <input style="display: none;" name="title" value="''' + sub + '''">
-                    <button id="save" type="submit">''' + load_lang('send') + '''</button>
-                    <button id="preview" type="button" onclick="load_preview(\'\')">''' + load_lang('preview') + '''</button>
-                </form>
-                <hr class="main_hr">
-                <div id="see_preview"></div>
-            ''',
-            menu = [['topic/' + url_pas(name), load_lang('list')]]
-        ))
+                    <div id="see_preview"></div>
+                ''',
+                menu = [['topic/' + url_pas(name), load_lang('list')]]
+            ))

+ 47 - 68
route/topic_close_list.py

@@ -1,78 +1,57 @@
 from .tool.func import *
 
-def topic_close_list_2(conn, name):
-    curs = conn.cursor()
+def topic_close_list(name = 'Test'):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    div = ''
-    tool = flask.request.args.get('tool', '')
+        div = ''
+        tool = flask.request.args.get('tool', '')
 
-    plus = ''
-    menu = [['topic/' + url_pas(name), load_lang('return')]]
+        plus = ''
+        menu = [['topic/' + url_pas(name), load_lang('return')]]
 
-    if tool == 'close':
-        curs.execute(db_change("select code, sub from rd where title = ? and stop = 'O' order by sub asc"), [name])
+        if tool == 'close':
+            curs.execute(db_change("select code, sub from rd where title = ? and stop = 'O' order by sub asc"), [name])
 
-        sub = load_lang('closed_discussion')
-    elif tool == 'agree':
-        curs.execute(db_change("select code, sub from rd where title = ? and agree = 'O' order by sub asc"), [name])
+            sub = load_lang('closed_discussion')
+        elif tool == 'agree':
+            curs.execute(db_change("select code, sub from rd where title = ? and agree = 'O' order by sub asc"), [name])
 
-        sub = load_lang('agreed_discussion')
-    else:
-        sub = load_lang('discussion_list')
-        menu = [['w/' + url_pas(name), load_lang('document')]]
-
-        if acl_check(name, 'topic', None) == 1:
-            display = 'display: none;'
-        else:
-            display = ''
-
-        curs.execute(db_change("select code from topic order by code + 0 desc limit 1"))
-        t_data = curs.fetchall()
-        if t_data:
-            topic_num = str(int(t_data[0][0]) + 1)
+            sub = load_lang('agreed_discussion')
         else:
-            topic_num = '1'
+            sub = load_lang('discussion_list')
+            menu = [['w/' + url_pas(name), load_lang('document')]]
 
-        plus = '''
-            <a href="/topic/''' + url_pas(name) + '?tool=close">(' + load_lang('closed_discussion') + ')</a> <a href="/topic/' + url_pas(name) + '?tool=agree">(' + load_lang('agreed_discussion') + ''')</a>
-            <hr class="main_hr">
-            <form style="''' + display + '" method="post" action="/thread/' + topic_num + '''">
-                <input placeholder="''' + load_lang('discussion_name') + '''" name="title">
+            plus = '''
+                <a href="/topic/''' + url_pas(name) + '?tool=close">(' + load_lang('closed_discussion') + ''')</a>
+                <a href="/topic/''' + url_pas(name) + '?tool=agree">(' + load_lang('agreed_discussion') + ''')</a>
                 <hr class="main_hr">
-                <textarea rows="10" id="textarea_edit_view" placeholder="''' + load_lang('content') + '''" name="content"></textarea>
-                <hr class="main_hr">
-                ''' + captcha_get() + (ip_warning() if display == '' else '') + '''
-                <input style="display: none;" name="topic" value="''' + name + '''">
-                <button type="submit">''' + load_lang('send') + '''</button>
-                <button id="preview" type="button" onclick="load_preview(\'''' + url_pas(name) + '\')">' + load_lang('preview') + '''</button>
-            </form>
-            <hr class="main_hr">
-            <div id="see_preview"></div>
-        '''
-
-        curs.execute(db_change("select code, sub from rd where title = ? and stop != 'O' order by date desc"), [name])
-
-    for data in curs.fetchall():
-        curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [data[0]])
-        t_data = curs.fetchall()
-
-        div += '''
-            <h2><a href="/thread/''' + data[0] + '">' + data[0] + '. ' + data[1] + '''</a></h2>
-            <div id="topic_pre_''' + data[0] + '''"></div>
-            <div id="topic_back_pre_''' + data[0] + '''"></div>
-            <script>
-                new_topic_load(''' + data[0] + ', "list", "?num=1", "topic_pre_' + data[0] + '''");
-                if(''' + t_data[0][0] + ''' !== 1) {
-                    new_topic_load(''' + data[0] + ', "list", "?num=' + t_data[0][0] + '", "topic_back_pre_' + data[0] + '''");
-                }
-            </script>
-        '''
-
-    if div == '':
-        plus = re.sub(r'^<br>', '', plus)
-
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + sub + ')', 0])],
-        data = div + plus,
-        menu = menu
-    ))
+                <a href="/thread/0">(''' + load_lang('make_new_topic') + ''')</a>
+            '''
+
+            curs.execute(db_change("select code, sub from rd where title = ? and stop != 'O' order by date desc"), [name])
+
+        for data in curs.fetchall():
+            curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [data[0]])
+            t_data = curs.fetchall()
+
+            div += '''
+                <h2><a href="/thread/''' + data[0] + '">' + data[0] + '. ' + data[1] + '''</a></h2>
+                <div id="topic_pre_''' + data[0] + '''"></div>
+                <div id="topic_back_pre_''' + data[0] + '''"></div>
+                <script>
+                    new_topic_load(''' + data[0] + ', "list", "/normal/1", "topic_pre_' + data[0] + '''");
+                    if(''' + t_data[0][0] + ''' !== 1) {
+                        new_topic_load(''' + data[0] + ', "list", "/normal/' + t_data[0][0] + '", "topic_back_pre_' + data[0] + '''");
+                    }
+                </script>
+            '''
+
+        if div == '':
+            plus = re.sub(r'^<br>', '', plus)
+
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + sub + ')', 0])],
+            data = div + plus,
+            menu = menu
+        ))

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.5.0-stable (stable1) (beta12) (dev20)",
+        "r_ver" : "v3.5.0-stable (stable1) (beta12) (dev21)",
         "c_ver" : "3500101",
         "s_ver" : "3500110"
     }