Jelajahi Sumber

HEAD로 통일

2DU 8 tahun lalu
induk
melakukan
062a769a37
3 mengubah file dengan 98 tambahan dan 151 penghapusan
  1. 87 127
      app.py
  2. 9 19
      func.py
  3. 2 5
      views/acme/index.tpl

+ 87 - 127
app.py

@@ -84,8 +84,7 @@ try:
 
     try:
         curs.execute('select user, ip, today from login')
-        lo_d = curs.fetchall()
-        for m_lo in lo_d:
+        for m_lo in curs.fetchall():
             curs.execute("insert into ua_d (name, ip, ua, today, sub) values (?, ?, '', ?, '')", [m_lo[0], m_lo[1], m_lo[2]])
 
         curs.execute("drop table login")
@@ -95,8 +94,7 @@ try:
 
     try:
         curs.execute('select title, cat from cat')
-        lo_d = curs.fetchall()
-        for m_lo in lo_d:
+        for m_lo in curs.fetchall():
             curs.execute("insert into back (title, link, type) values (?, ?, 'cat')", [m_lo[0], m_lo[1]])
 
         curs.execute("drop table cat")
@@ -104,6 +102,56 @@ try:
     except:
         pass
 
+    try:
+        plus_all_data = ''
+        start_replace = 0
+
+        curs.execute('select data from other where name = "css"')
+        for m_lo in curs.fetchall():
+            plus_all_data += '\r\n<style>' + m_lo[0] + '</style>'
+
+        curs.execute('select data from other where name = "js"')
+        for m_lo in curs.fetchall():
+            plus_all_data += '\r\n<script>' + m_lo[0] + '</script>'
+
+        if(plus_all_data != ''):
+            curs.execute("insert into other (name, data) values ('head', ?)", [plus_all_data])
+            curs.execute("delete from other where name = 'css'")
+            curs.execute("delete from other where name = 'js'")
+            start_replace = 1
+
+        curs.execute('select user from custom')
+        if(curs.fetchall()):
+            curs.execute("select user from custom where user like ?", ['% (head)%'])
+            if(not curs.fetchall()):
+                curs.execute("select user, css from custom")
+                for data_lo in curs.fetchall():
+                    plus_all_data = ''
+                    if(re.search(' \(js\)$', data_lo[0])):
+                        name_data_is = data_lo[0].replace(' (js)', '')
+                        plus_all_data = '\r\n<script>' + data_lo[1] + '</script>'
+                    else:
+                        name_data_is = data_lo[0]
+                        plus_all_data = '\r\n<style>' + data_lo[1] + '</style>'
+
+                    print('plus : ' + plus_all_data)
+                    print('name : ' + data_lo[0])
+
+                    curs.execute("select css from custom where user = ?", [name_data_is + ' (head)'])
+                    data_is_it = curs.fetchall()
+                    if(data_is_it):
+                        curs.execute("update custom set css = ? where user = ?", [data_is_it[0][0] + plus_all_data, name_data_is + ' (head)'])
+                    else:
+                        curs.execute("insert into custom (user, css) values (?, ?)", [name_data_is + ' (head)', plus_all_data])
+                    
+                    curs.execute("delete from custom where user = ?", [data_lo[0]])
+                start_replace = 1
+
+        if(start_replace == 1):
+            print('CSS, JS 데이터 변환')
+    except:
+        pass
+
     conn.commit()
 except:
     pass
@@ -282,7 +330,7 @@ def edit_set(num = 0):
         return(re_error('/ban'))
 
     if(num == 0):
-        li_list = ['기본 설정', '문구 관련', '전역 CSS', '전역 JS']
+        li_list = ['기본 설정', '문구 관련', '전역 HEAD']
         x = 0
         li_data = ''
         for li in li_list:
@@ -464,75 +512,39 @@ def edit_set(num = 0):
                 )
             )
     elif(num == 3):
-        session = request.environ.get('beaker.session')
         if(request.method == 'POST'):
-            curs.execute("select name from other where name = 'css'")
+            curs.execute("select name from other where name = 'head'")
             if(curs.fetchall()):
-                curs.execute("update other set data = ? where name = 'css'", [request.forms.content])
+                curs.execute("update other set data = ? where name = 'head'", [request.forms.content])
             else:
-                curs.execute("insert into other (name, data) values ('css', ?)", [request.forms.content])
+                curs.execute("insert into other (name, data) values ('head', ?)", [request.forms.content])
             conn.commit()
 
             return(redirect('/edit_set/3'))
         else:
-            curs.execute("select data from other where name = 'css'")
-            css = curs.fetchall()
-            if(css):
-                data = css[0][0]
+            curs.execute("select data from other where name = 'head'")
+            head = curs.fetchall()
+            if(head):
+                data = head[0][0]
             else:
                 data = ''
 
-            return(
-                html_minify(
-                    template('index', 
-                        imp = ['전역 CSS', wiki_set(1), custom(), other2([0, 0])],
-                        data =  '<form method="post"> \
-                                    <textarea rows="30" cols="100" name="content">'\
-                                        + html.escape(data) + \
-                                    '</textarea> \
-                                    <br> \
-                                    <br> \
-                                    <div class="form-actions"> \
-                                        <button class="btn btn-primary" type="submit">저장</button> \
-                                    </div> \
-                                </form>',
-                        menu = [['edit_set', '설정 편집']]
-                    )
-                )
-            )
-    elif(num == 4):
-        session = request.environ.get('beaker.session')
-        if(request.method == 'POST'):
-            curs.execute("select name from other where name = 'js'")
-            if(curs.fetchall()):
-                curs.execute("update other set data = ? where name = 'js'", [request.forms.content])
-            else:
-                curs.execute("insert into other (name, data) values ('js', ?)", [request.forms.content])
-            conn.commit()
-
-            return(redirect('/edit_set/4'))
-        else:
-            curs.execute("select data from other where name = 'js'")
-            js = curs.fetchall()
-            if(js):
-                data = js[0][0]
-            else:
-                data = ''
+            start = '<span>&lt;style&gt;CSS 코드&lt;/style&gt;<br>&lt;script&gt;JS 코드&lt;/script&gt;</span><br><br>'
 
             return(
                 html_minify(
                     template('index', 
-                        imp = ['전역 JS', wiki_set(1), custom(), other2([0, 0])],
-                        data =  '<form method="post"> \
-                                    <textarea rows="30" cols="100" name="content">'\
-                                        + html.escape(data) + \
-                                    '</textarea> \
-                                    <br> \
-                                    <br> \
-                                    <div class="form-actions"> \
-                                        <button class="btn btn-primary" type="submit">저장</button> \
-                                    </div> \
-                                </form>',
+                        imp = ['전역 HEAD', wiki_set(1), custom(), other2([0, 0])],
+                        data =  start + '<form method="post"> \
+                                            <textarea rows="30" cols="100" name="content">'\
+                                                + html.escape(data) + \
+                                            '</textarea> \
+                                            <br> \
+                                            <br> \
+                                            <div class="form-actions"> \
+                                                <button class="btn btn-primary" type="submit">저장</button> \
+                                            </div> \
+                                        </form>',
                         menu = [['edit_set', '설정 편집']]
                     )
                 )
@@ -3616,8 +3628,7 @@ def user_info():
                                                         ' * [[wiki:register|회원가입]]\r\n' + \
                                                         '== 사용자 기능 ==\r\n' + \
                                                         ' * [[wiki:user_acl/' + url_pas(raw_ip) + '|사용자 문서 ACL]]\r\n' + \
-                                                        ' * [[wiki:custom_css|사용자 CSS]]\r\n' + \
-                                                        ' * [[wiki:custom_js|사용자 JS]]\r\n' + \
+                                                        ' * [[wiki:custom_head|사용자 HEAD]]\r\n' + \
                                                         '== 기타 ==\r\n' + \
                                                         ' * [[wiki:alarm|알림]]\r\n' + \
                                                         ' * [[wiki:view_log|지나온 문서]]\r\n' + \
@@ -3650,95 +3661,44 @@ def view_log():
         )
     )
 
-@route('/custom_css', method=['GET', 'POST'])
-def custom_css_view():
+@route('/custom_head', method=['GET', 'POST'])
+def custom_head_view():
     session = request.environ.get('beaker.session')
     ip = ip_check()
     if(request.method == 'POST'):
         if(not re.search('(\.|:)', ip)):
-            curs.execute("select * from custom where user = ?", [ip])
-            css_data = curs.fetchall()
-            if(css_data):
-                curs.execute("update custom set css = ? where user = ?", [request.forms.content, ip])
+            curs.execute("select user from custom where user = ?", [ip + ' (head)'])
+            if(curs.fetchall()):
+                curs.execute("update custom set css = ? where user = ?", [request.forms.content, ip + ' (head)'])
             else:
-                curs.execute("insert into custom (user, css) values (?, ?)", [ip, request.forms.content])
+                curs.execute("insert into custom (user, css) values (?, ?)", [ip + ' (head)', request.forms.content])
             conn.commit()
 
-        session['Daydream'] = request.forms.content
+        session['MyMaiToNight'] = request.forms.content
 
         return(redirect('/user'))
     else:
         if(not re.search('(\.|:)', ip)):
             start = ''
-            curs.execute("select css from custom where user = ?", [ip])
-            css_data = curs.fetchall()
-            if(css_data):
-                data = css_data[0][0]
+            curs.execute("select css from custom where user = ?", [ip + ' (head)'])
+            head_data = curs.fetchall()
+            if(head_data):
+                data = head_data[0][0]
             else:
                 data = ''
         else:
             start = '<span>비 로그인의 경우에는 로그인하면 날아갑니다.</span><br><br>'
             try:
-                data = session['Daydream']
+                data = session['MyMaiToNight']
             except:
                 data = ''
 
-        return(
-            html_minify(
-                template('index', 
-                    imp = ['사용자 CSS', wiki_set(1), custom(), other2([0, 0])],
-                    data =  start + ' \
-                            <form method="post"> \
-                                <textarea rows="30" cols="100" name="content">'\
-                                     + data + \
-                                '</textarea> \
-                                <br> \
-                                <br> \
-                                <div class="form-actions"> \
-                                    <button class="btn btn-primary" type="submit">저장</button> \
-                                </div> \
-                            </form>',
-                    menu = [['user', '사용자']]
-                )
-            )
-        )
-
-@route('/custom_js', method=['GET', 'POST'])
-def custom_js_view():
-    session = request.environ.get('beaker.session')
-    ip = ip_check()
-    if(request.method == 'POST'):
-        if(not re.search('(\.|:)', ip)):
-            curs.execute("select * from custom where user = ?", [ip + ' (js)'])
-            js_data = curs.fetchall()
-            if(js_data):
-                curs.execute("update custom set css = ? where user = ?", [request.forms.content, ip + ' (js)'])
-            else:
-                curs.execute("insert into custom (user, css) values (?, ?)", [ip + ' (js)', request.forms.content])
-            conn.commit()
-        session['AQUARIUM'] = request.forms.content
-
-        return(redirect('/user'))
-    else:
-        if(not re.search('(\.|:)', ip)):
-            start = ''
-            curs.execute("select css from custom where user = ?", [ip + ' (js)'])
-            js_data = curs.fetchall()
-            if(js_data):
-                data = js_data[0][0]
-            else:
-                data = ''
-        else:
-            start = '<span>비 로그인의 경우에는 로그인하면 날아갑니다.</span><br><br>'
-            try:
-                data = session['AQUARIUM']
-            except:
-                data = ''
+        start += '<span>&lt;style&gt;CSS 코드&lt;/style&gt;<br>&lt;script&gt;JS 코드&lt;/script&gt;</span><br><br>'
 
         return(
             html_minify(
                 template('index', 
-                    imp = ['사용자 JS', wiki_set(1), custom(), other2([0, 0])],
+                    imp = ['사용자 HEAD', wiki_set(1), custom(), other2([0, 0])],
                     data =  start + ' \
                             <form method="post"> \
                                 <textarea rows="30" cols="100" name="content">'\

+ 9 - 19
func.py

@@ -79,26 +79,21 @@ def wiki_set(num):
         else:
             r += ['CC 0']
 
-        curs.execute("select data from other where name = 'css'")
-        d = curs.fetchall()
-        if(d):
-            r += [d[0][0]]
-        else:
-            r += ['']
+        r += ['', '']
 
-        curs.execute("select data from other where name = 'js'")
+        curs.execute('select data from other where name = "logo"')
         d = curs.fetchall()
         if(d):
             r += [d[0][0]]
         else:
-            r += ['']
-
-        curs.execute('select data from other where name = "logo"')
+            r += [r[0]]
+            
+        curs.execute("select data from other where name = 'head'")
         d = curs.fetchall()
         if(d):
             r += [d[0][0]]
         else:
-            r += [r[0]]
+            r += ['']
 
         return(r)
 
@@ -196,14 +191,9 @@ def ip_pas(raw_ip):
 def custom():
     session = request.environ.get('beaker.session')
     try:
-        d1 = format(session['Daydream'])
-    except:
-        d1 = ''
-
-    try:
-        d2 = format(session['AQUARIUM'])
+        d4 = format(session['MyMaiToNight'])
     except:
-        d2 = ''
+        d4 = ''
 
     if(session.get('Now') == 1):
         curs.execute('select name from alarm limit 1')
@@ -214,7 +204,7 @@ def custom():
     else:
         d3 = 0
 
-    return([d1, d2, d3])
+    return(['', '', d3, d4])
 
 def acl_check(name):
     ip = ip_check()

+ 2 - 5
views/acme/index.tpl

@@ -16,11 +16,8 @@
         <link rel="stylesheet" href="/views/acme/css/font-awesome/css/font-awesome.min.css">
         <script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['[math]', '[/math]']]}});</script>
         <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_CHTML"></script>
-        <script src='https://www.google.com/recaptcha/api.js'></script>
-        <style>{{!imp[1][2]}}</style>
-        <script>{{!imp[1][3]}}</script>
-        <style>{{!imp[2][0]}}</style>
-        <script>{{!imp[2][1]}}</script>
+        {{!imp[1][5]}}
+        {{!imp[2][3]}}
         <meta name="twitter:creator" content="@{{imp[1][0]}}">
         <meta name="twitter:title" content="{{imp[0]}}">
         <meta name="twitter:site" content="@{{imp[1][0]}}">