2du 2 роки тому
батько
коміт
33a2e10524
5 змінених файлів з 67 додано та 54 видалено
  1. 54 46
      route/edit.py
  2. 5 1
      route/main_setting_phrase.py
  3. 6 6
      route/topic.py
  4. 1 0
      route/topic_list.py
  5. 1 1
      version.json

+ 54 - 46
route/edit.py

@@ -19,6 +19,57 @@ def edit_timeout(func, args = (), timeout = 3):
         pool.close()
         pool.join()
         return 0
+        
+def edit_editor(curs, ip, data_main = '', do_type = 'edit'):
+    monaco_editor_top = ''
+    editor_display = ''
+    add_get_file = ''
+    monaco_display = ''
+    
+    monaco_on = get_main_skin_set(curs, flask.session, 'main_css_monaco', ip)
+    if monaco_on == 'use':
+        editor_display = 'style="display: none;"'
+        add_get_file = '''
+            <link   rel="stylesheet"
+                    data-name="vs/editor/editor.main" 
+                    href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.37.1/min/vs/editor/editor.main.min.css">
+            <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.37.1/min/vs/loader.min.js"></script>
+        '''
+
+        monaco_editor_top = '<a href="javascript:opennamu_edit_turn_off_monaco();">(' + load_lang('turn_off_monaco') + ')</a>'
+        
+        if flask.request.cookies.get('main_css_darkmode', '0') == '1':
+            monaco_thema = 'vs-dark'
+        else:
+            monaco_thema = ''
+        
+        add_script = 'do_monaco_init("' + monaco_thema + '");'
+    else:
+        monaco_display = 'style="display: none;"'
+        add_script = 'opennamu_edit_turn_off_monaco();'
+
+    curs.execute(db_change('select data from other where name = "edit_help"'))
+    sql_d = curs.fetchall()
+    p_text = html.escape(sql_d[0][0]) if sql_d and sql_d[0][0] != '' else load_lang('default_edit_help')
+
+    if do_type == 'edit':
+        textarea_size = 'opennamu_textarea_500'
+    else:
+        textarea_size = 'opennamu_textarea_100'
+
+    return add_get_file + '''
+        <textarea style="display: none;" id="opennamu_edit_origin" name="doc_data_org">''' + html.escape(data_main) + '''</textarea>
+        <div>''' + monaco_editor_top + ' ' + edit_button('opennamu_edit_textarea', 'opennamu_monaco_editor') + '''</div>
+        
+        <div id="opennamu_monaco_editor" class="''' + textarea_size + '''" ''' + monaco_display + '''></div>
+        <textarea id="opennamu_edit_textarea" ''' + editor_display + ''' class="''' + textarea_size + '''" name="content" placeholder="''' + p_text + '''">''' + html.escape(data_main) + '''</textarea>
+        <hr class="main_hr">
+        <script>
+            do_stop_exit();
+            do_paste_image('opennamu_edit_textarea', 'opennamu_monaco_editor');
+            ''' + add_script + '''
+        </script>
+    '''
 
 def edit(name = 'Test', section = 0, do_type = ''):
     with get_db_connect() as conn:
@@ -256,58 +307,21 @@ def edit(name = 'Test', section = 0, do_type = ''):
     
             editor_top_text += '<a href="/edit_filter">(' + load_lang('edit_filter_rule') + ')</a>'
     
-            curs.execute(db_change('select data from other where name = "edit_help"'))
-            sql_d = curs.fetchall()
-            p_text = html.escape(sql_d[0][0]) if sql_d and sql_d[0][0] != '' else load_lang('default_edit_help')
-            
-            monaco_on = get_main_skin_set(curs, flask.session, 'main_css_monaco', ip)
-            if monaco_on == 'use':
-                editor_display = 'style="display: none;"'
-                monaco_display = ''
-                add_get_file = '''
-                    <link   rel="stylesheet"
-                            data-name="vs/editor/editor.main" 
-                            href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.37.1/min/vs/editor/editor.main.min.css">
-                    <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.37.1/min/vs/loader.min.js"></script>
-                '''
-
-                editor_top_text += ' <a href="javascript:opennamu_edit_turn_off_monaco();">(' + load_lang('turn_off_monaco') + ')</a>'
-                
-                if flask.request.cookies.get('main_css_darkmode', '0') == '1':
-                    monaco_thema = 'vs-dark'
-                else:
-                    monaco_thema = ''
-                
-                add_script = 'do_monaco_init("' + monaco_thema + '");'
-            else:
-                editor_display = ''
-                monaco_display = 'style="display: none;"'
-                add_get_file = ''
-                add_script = 'opennamu_edit_turn_off_monaco();'
-
             if editor_top_text != '':
                 editor_top_text += '<hr class="main_hr">'
 
             sub_menu = ' (' + str(section) + ')' if section != '' else ''
-    
+
             return easy_minify(flask.render_template(skin_check(), 
                 imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('edit') + ')' + sub_menu, 0])],
-                data =  editor_top_text + add_get_file + '''
-                    <script>
-                        
-                    </script>
+                data = editor_top_text + '''
                     <form method="post">
-                        <textarea style="display: none;" id="opennamu_edit_origin" name="doc_data_org">''' + html.escape(data_section) + '''</textarea>
                         <textarea style="display: none;" name="doc_section_data_where">''' + data_section_where + '''</textarea>
                         <input style="display: none;" name="doc_section_edit_apply" value="''' + doc_section_edit_apply + '''">
 
                         <input style="display: none;" name="ver" value="''' + doc_ver + '''">
                         
-                        <div>''' + edit_button('opennamu_edit_textarea', 'opennamu_monaco_editor') + '''</div>
-                        
-                        <div id="opennamu_monaco_editor" class="opennamu_textarea_500" ''' + monaco_display + '''></div>
-                        <textarea id="opennamu_edit_textarea" ''' + editor_display + ''' class="opennamu_textarea_500" name="content" placeholder="''' + p_text + '''">''' + html.escape(data_section) + '''</textarea>
-                        <hr class="main_hr">
+                        ''' + edit_editor(curs, ip, data_section) + '''
 
                         <input placeholder="''' + load_lang('why') + '''" name="send">
                         <hr class="main_hr">
@@ -320,12 +334,6 @@ def edit(name = 'Test', section = 0, do_type = ''):
                     
                     <hr class="main_hr">
                     <div id="opennamu_preview_area">''' + data_preview + '''</div>
-                    
-                    <script>
-                        do_stop_exit();
-                        do_paste_image('opennamu_edit_textarea', 'opennamu_monaco_editor');
-                        ''' + add_script + '''
-                    </script>
                 ''',
                 menu = [
                     ['w/' + url_pas(name), load_lang('return')],

+ 5 - 1
route/main_setting_phrase.py

@@ -28,7 +28,8 @@ def main_setting_phrase():
             'topic_text',
             'phrase_user_page_admin',
             'phrase_user_page_owner',
-            'phrase_old_page_warring'
+            'phrase_old_page_warring',
+            'bbs_help'
         ]
         if flask.request.method == 'POST':
             for i in i_list:
@@ -124,6 +125,9 @@ def main_setting_phrase():
 
                         <h2>''' + load_lang('phrase_old_page_warring') + ''' (''' + load_lang('beta') + ''') (HTML)</h2>
                         <textarea class="opennamu_textarea_100" name="''' + i_list[20] + '''">''' + html.escape(d_list[20]) + '''</textarea>
+                        
+                        <h2>''' + load_lang('bbs_help') + '''</h2>
+                        <textarea class="opennamu_textarea_100" name="''' + i_list[13] + '''">''' + html.escape(d_list[22]) + '''</textarea>
 
                         <hr class="main_hr">
                         <button id="opennamu_save_button" type="submit">''' + load_lang('save') + '''</button>

+ 6 - 6
route/topic.py

@@ -1,6 +1,7 @@
 from .tool.func import *
 
 from .api_topic import api_topic
+from .edit import edit_editor
 
 def topic(topic_num = 0, do_type = '', doc_name = 'Test'):
     with get_db_connect() as conn:
@@ -12,6 +13,8 @@ def topic(topic_num = 0, do_type = '', doc_name = 'Test'):
         if topic_view_acl == 1:
             return re_error('/ban')
 
+        ip = ip_check()
+
         if flask.request.method == 'POST' and do_type == '':
             if do_edit_slow_check('thread') == 1:
                 return re_error('/error/42')
@@ -38,7 +41,6 @@ def topic(topic_num = 0, do_type = '', doc_name = 'Test'):
             else:
                 captcha_post('', 0)
 
-            ip = ip_check()
             today = get_time()
 
             if topic_acl == 1:
@@ -175,15 +177,13 @@ def topic(topic_num = 0, do_type = '', doc_name = 'Test'):
                             <hr class="main_hr">
                         </div>
                         
-                        <div>''' + edit_button('opennamu_edit_textarea') + '''</div>
-
-                        <textarea id="opennamu_edit_textarea" class="opennamu_textarea_100" placeholder="''' + topic_text + '''" name="content">''' + html.escape(thread_data) + '''</textarea>
+                        ''' + edit_editor(curs, ip, thread_data, 'thread') + '''
                         <hr class="main_hr">
                         
                         ''' + captcha_get() + ip_warning() + '''
                         
-                        <button id="opennamu_save_button" formaction="/thread/''' + topic_num + '''" type="submit">''' + load_lang('send') + '''</button>
-                        <button id="opennamu_preview_button" formaction="/thread_preview/''' + topic_num + '''#opennamu_edit_textarea" type="submit">''' + load_lang('preview') + '''</button>
+                        <button id="opennamu_save_button" formaction="/thread/''' + topic_num + '''" type="submit" onclick="do_monaco_to_textarea(); do_stop_exit_release();">''' + load_lang('send') + '''</button>
+                        <button id="opennamu_preview_button" formaction="/thread_preview/''' + topic_num + '''#opennamu_edit_textarea" type="submit" onclick="do_monaco_to_textarea(); do_stop_exit_release();">''' + load_lang('preview') + '''</button>
                     </form>
                     <hr class="main_hr">
                     

+ 1 - 0
route/topic_list.py

@@ -1,4 +1,5 @@
 from .tool.func import *
+
 from .api_topic import api_topic
 
 def topic_list(name = 'Test'):

+ 1 - 1
version.json

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