Procházet zdrojové kódy

되돌리기와 토론

2DU před 9 roky
rodič
revize
73e6edb32d
2 změnil soubory, kde provedl 193 přidání a 6 odebrání
  1. 120 4
      app.py
  2. 73 2
      templates/index.html

+ 120 - 4
app.py

@@ -15,7 +15,7 @@ curs = conn.cursor(pymysql.cursors.DictCursor)
 
 def namumark(data):
     data = '\n' + data + '\n'
-    
+
     data = re.sub('<', '&lt;', data)
     data = re.sub('>', '&gt;', data)
 
@@ -25,7 +25,7 @@ def namumark(data):
     data = re.sub("===\s?(?P<in>[^=]*)\s?===(?:\s+)?\n", '<h3>\g<in></h3>', data)
     data = re.sub("==\s?(?P<in>[^=]*)\s?==(?:\s+)?\n", '<h2>\g<in></h2>', data)
     data = re.sub("=\s?(?P<in>[^=]*)\s?=(?:\s+)?\n", '<h1>\g<in></h1>', data)
-    
+
     data = re.sub("'''(?P<in>.+?)'''(?!')", '<strong>\g<in></strong>', data)
     data = re.sub("''(?P<in>.+?)''(?!')", '<i>\g<in></i>', data)
     data = re.sub('~~(?P<in>.+?)~~(?!~)', '<s>\g<in></s>', data)
@@ -53,6 +53,10 @@ def recent(title, ip, today, send, leng):
     curs.execute("insert into rc (title, date, ip, send, leng, back) value ('" + pymysql.escape_string(title) + "', '" + today + "', '" + ip + "', '" + pymysql.escape_string(send) + "', '" + leng + "', '')")
     conn.commit()
 
+def discuss(title, sub, ip, date):
+    curs.execute("insert into rd (title, sub, ip, date) value ('" + pymysql.escape_string(title) + "', '" + pymysql.escape_string(sub) + "', '" + ip + "', '" + date + "')")
+    conn.commit()
+
 def history(title, data, date, ip, send, leng):
     curs.execute("select * from history where title = '" + pymysql.escape_string(title) + "' order by id+0 desc limit 1")
     rows = curs.fetchall()
@@ -106,6 +110,25 @@ def recentchanges():
     else:
          return render_template('index.html', logo = data['name'], rows = '', tn = 3, title = '최근 변경내역')
 
+@app.route('/recentdiscuss')
+def recentdiscuss():
+    i = 0
+    div = '<div>'
+    curs.execute("select * from rd order by date desc limit 50")
+    rows = curs.fetchall()
+    if(rows):
+        while True:
+            try:
+                a = rows[i]
+            except:
+                div = div + '</div>'
+                break
+            div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;"><a href="/topic/' + parse.quote(rows[i]['title']) + '/sub/' + parse.quote(rows[i]['sub']) + '">' + rows[i]['title'] + '</a> (' + rows[i]['sub'] + ')</td><td style="text-align: center;width:33.33%;">' + rows[i]['ip'] + '</td><td style="text-align: center;width:33.33%;">' + rows[i]['date'] + '</td></tr></tbody></table>'
+            i = i + 1
+        return render_template('index.html', logo = data['name'], rows = div, tn = 12, title = '최근 토론내역')
+    else:
+         return render_template('index.html', logo = data['name'], rows = '', tn = 12, title = '최근 토론내역')
+
 @app.route('/history/<name>')
 def gethistory(name = None):
     i = 0
@@ -126,7 +149,7 @@ def gethistory(name = None):
                 send = re.sub('&lt;a href="\/w\/(?P<in>[^"]*)"&gt;(?P<out>[^&]*)&lt;\/a&gt;', '<a href="/w/\g<in>">\g<out></a>', send)
             else:
                 send = '<br>'
-            div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;">r' + rows[i]['id'] + '</a> <a href="/w/' + parse.quote(rows[i]['title']) + '/r/' + rows[i]['id'] + '">(w)</a> <a href="/w/' + parse.quote(rows[i]['title']) + '/raw/' + rows[i]['id'] + '">(raw)</a> (' + rows[i]['leng'] + ')</td><td style="text-align: center;width:33.33%;">' + rows[i]['ip'] + '</td><td style="text-align: center;width:33.33%;">' + rows[i]['date'] + '</td></tr><tr><td colspan="3" style="text-align: center;width:100%;">' + send + '</td></tr></tbody></table>'
+            div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;">r' + rows[i]['id'] + '</a> <a href="/w/' + parse.quote(rows[i]['title']) + '/r/' + rows[i]['id'] + '">(w)</a> <a href="/w/' + parse.quote(rows[i]['title']) + '/raw/' + rows[i]['id'] + '">(raw)</a> <a href="/revert/' + parse.quote(rows[i]['title']) + '/r/' + rows[i]['id'] + '">(되돌리기)</a> (' + rows[i]['leng'] + ')</td><td style="text-align: center;width:33.33%;">' + rows[i]['ip'] + '</td><td style="text-align: center;width:33.33%;">' + rows[i]['date'] + '</td></tr><tr><td colspan="3" style="text-align: center;width:100%;">' + send + '</td></tr></tbody></table>'
             i = i + 1
         return render_template('index.html', logo = data['name'], rows = div, tn = 5, title = name, page = parse.quote(name))
     else:
@@ -179,6 +202,37 @@ def raw(name = None):
     else:
         return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name), data = '문서 없음', license = data['license'], tn = 7)
 
+@app.route('/revert/<name>/r/<number>', methods=['POST', 'GET'])
+def revert(name = None, number = None):
+    if(request.method == 'POST'):
+        curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
+        rows = curs.fetchall()
+        if(rows):
+            ip = getip(request)
+            today = getnow()
+            curs.execute("select * from data where title = '" + pymysql.escape_string(name) + "'")
+            row = curs.fetchall()
+            if(row):
+                leng = getleng(len(row[0]['data']), len(rows[0]['data']))
+                curs.execute("update data set data = '" + pymysql.escape_string(rows[0]['data']) + "' where title = '" + pymysql.escape_string(name) + "'")
+                conn.commit()
+            else:
+                leng = '+' + str(len(rows[0]['data']))
+                curs.execute("insert into data (title, data, acl) value ('" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(rows[0]['data']) + "', '')")
+                conn.commit()
+            recent(name, ip, today, '문서를 ' + number + '판으로 되돌렸습니다.', leng)
+            history(name, rows[0]['data'], today, ip, '문서를 ' + number + '판으로 되돌렸습니다.', leng)
+            return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name) + '" />'
+        else:
+            return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name) + '" />'
+    else:
+        curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' and id = '" + number + "'")
+        rows = curs.fetchall()
+        if(rows):
+            return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name), r = parse.quote(number), tn = 13, plus = '정말 되돌리시겠습니까?')
+        else:
+            return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name) + '" />'
+
 @app.route('/edit/<name>', methods=['POST', 'GET'])
 def edit(name = None):
     if(request.method == 'POST'):
@@ -304,6 +358,68 @@ def titleindex():
     else:
         return render_template('index.html', logo = data['name'], rows = '', tn = 4, title = '모든 문서')
 
+@app.route('/topic/<name>', methods=['POST', 'GET'])
+def topic(name = None):
+    if(request.method == 'POST'):
+        return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name) + '/sub/' + parse.quote(request.form["topic"]) + '" />'
+    else:
+        div = '<div>'
+        i = 0
+        curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "'")
+        rows = curs.fetchall()
+        while True:
+            try:
+                a = rows[i]
+            except:
+                div = div + '</div>'
+                break
+            if(i == 0):
+                sub = rows[i]['sub']
+                div = div + '<li><a href="/topic/' + parse.quote(name) + '/sub/' + parse.quote(rows[i]['sub']) + '">' + rows[i]['sub'] + '</a></li>'
+            else:
+                if(not sub == rows[i]['sub']):
+                    sub = rows[i]['sub']
+                    div = div + '<li><a href="/topic/' + parse.quote(name) + '/sub/' + parse.quote(rows[i]['sub']) + '">' + rows[i]['sub'] + '</a></li>'
+            i = i + 1
+        return render_template('index.html', title = name, page = parse.quote(name), logo = data['name'], plus = div, tn = 10)
+
+@app.route('/topic/<name>/sub/<sub>', methods=['POST', 'GET'])
+def sub(name = None, sub = None):
+    if(request.method == 'POST'):
+        curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 desc limit 1")
+        rows = curs.fetchall()
+        if(rows):
+            number = int(rows[0]['id']) + 1
+        else:
+            number = 1
+        ip = getip(request)
+        today = getnow()
+        discuss(name, sub, ip, today)
+        curs.execute("insert into topic (id, title, sub, data, date, ip, block) value ('" + str(number) + "', '" + pymysql.escape_string(name) + "', '" + pymysql.escape_string(sub) + "', '" + pymysql.escape_string(request.form["content"]) + "', '" + today + "', '" + ip + "', '')")
+        conn.commit()
+        return '<meta http-equiv="refresh" content="0;url=/topic/' + parse.quote(name) + '/sub/' + parse.quote(sub) + '" />'
+    else:
+        div = '<div>'
+        i = 0
+        curs.execute("select * from topic where title = '" + pymysql.escape_string(name) + "' and sub = '" + pymysql.escape_string(sub) + "' order by id+0 asc")
+        rows = curs.fetchall()
+        while True:
+            try:
+                a = rows[i]
+            except:
+                div = div + '</div>'
+                break
+            if(i == 0):
+                start = rows[i]['ip']
+            if(rows[i]['ip'] == start):
+                j = i + 1
+                div = div + '<table id="toron"><tbody><tr><td id="toroncolorgreen"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + rows[i]['ip'] + ' <span style="float:right;">' + rows[i]['date'] + '</span></td></tr><tr><td>' + rows[i]['data'] + '</td></tr></tbody></table><br>'
+            else:
+                j = i + 1
+                div = div + '<table id="toron"><tbody><tr><td id="toroncolor"><a href="javascript:void(0);" id="' + str(j) + '">#' + str(j) + '</a> ' + rows[i]['ip'] + ' <span style="float:right;">' + rows[i]['date'] + '</span></td></tr><tr><td>' + rows[i]['data'] + '</td></tr></tbody></table><br>'
+            i = i + 1
+        return render_template('index.html', title = name, page = parse.quote(name), suburl = parse.quote(sub), sub = sub, logo = data['name'], rows = div, tn = 11)
+
 @app.route('/grammar')
 def grammar():
     return render_template('index.html', title = '문법 설명', logo = data['name'], data = '아직 없음')
@@ -314,7 +430,7 @@ def version():
 
 @app.route('/random')
 def random():
-    curs.execute("select * from data order by rand() limit 1;")
+    curs.execute("select * from data order by rand() limit 1")
     rows = curs.fetchall()
     if(rows):
         return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(rows[0]['title']) + '" />'

+ 73 - 2
templates/index.html

@@ -129,7 +129,7 @@
 				</nav>
 			</div>
 			<h1 class="titlee">{{title}}</h1>
-			<h2 class="titlee"><span style="margin-left:5px"></span></h2>
+			<h2 class="titlee"><span style="margin-left:5px"></span>(old)</h2>
 			<div>
 				{% autoescape false %}
 				{{data}}
@@ -143,7 +143,7 @@
 				</nav>
 			</div>
 			<h1 class="title">{{title}}</h1>
-			<h2 class="title"><span style="margin-left:5px"></span></h2>
+			<h2 class="title"><span style="margin-left:5px"></span>(raw)</h2>
 			<div>
 				{% autoescape false %}
 				{{data}}
@@ -151,6 +151,13 @@
 			</div>
 			{% elif tn == 8 %}
 			<h1 class="title">{{title}}</h1>
+			<h2 class="title"><span style="margin-left:5px"></span>(삭제)</h2>
+			<div id="tool">
+				<nav class="menu">
+					<a class="menu-item selected" href="#" onclick="return false">삭제</a>
+					<a class="menu-item" href="/w/{{page}}">문서</a>
+				</nav>
+			</div>
 			<form id="usrform" method="POST" action="/delete/{{page}}">
 				{{plus}}
 				<br>
@@ -159,6 +166,13 @@
 			</form>
 			{% elif tn == 9 %}
 			<h1 class="title">{{title}}</h1>
+			<h2 class="title"><span style="margin-left:5px"></span>(이동)</h2>
+			<div id="tool">
+				<nav class="menu">
+					<a class="menu-item selected" href="#" onclick="return false">이동</a>
+					<a class="menu-item" href="/w/{{page}}">문서</a>
+				</nav>
+			</div>
 			<form id="usrform" method="POST" action="/move/{{page}}">
 				{{plus}}
 				<br>
@@ -168,6 +182,63 @@
 				<br>
 				<button class="btn btn-primary" type="submit">이동</button>
 			</form>
+			{% elif tn == 10 %}
+			<h1 class="title">{{title}}</h1>
+			<h2 class="title"><span style="margin-left:5px"></span>(토론 목록)</h2>
+			<form id="usrform" method="POST" action="/topic/{{page}}">
+				{% autoescape false %}
+				{{plus}}
+				{% endautoescape %}
+				<br>
+				<input class="form-control" name="topic" style="width: 100%">
+				<br>
+				<br>
+				<button class="btn btn-primary" type="submit">새토론</button>
+			</form>
+			{% elif tn == 11 %}
+			<h1 class="titlee">{{title}}</h1>
+			<h2 class="titlee"><span style="margin-left:5px"></span>(토론)</h2>
+			<h2>{{sub}}</h2>
+			<br>
+			{% autoescape false %}
+			{{rows}}
+			{% endautoescape %}
+			<form id="usrform" method="POST" action="/topic/{{page}}/sub/{{suburl}}">
+				<br>
+				<textarea rows="10" cols="100" name="content" form="usrform"></textarea>
+				<br>
+				<br>
+				<button class="btn btn-primary" type="submit">전송</button>
+			</form>
+			{% elif tn == 12 %}
+			<h1 class="title">{{title}}</h1>
+			<table style="width: 100%;">
+				<tbody>
+					<tr>
+						<td style="text-align: center;width:33.33%;">토론명</td>
+						<td style="text-align: center;width:33.33%;">토론자</td>
+						<td style="text-align: center;width:33.33%;">시간</td>
+					</tr>
+				</tbody>
+			</table>
+			{% autoescape false %}
+			{{rows}}
+			{% endautoescape %}
+			{% elif tn == 13 %}
+			<h1 class="title">{{title}}</h1>
+			<h2 class="title"><span style="margin-left:5px"></span>(되돌리기)</h2>
+			<div id="tool">
+				<nav class="menu">
+					<a class="menu-item selected" href="#" onclick="return false">되돌리기</a>
+					<a class="menu-item" href="/w/{{page}}">문서</a>
+				</nav>
+			</div>
+			<form id="usrform" method="POST" action="/revert/{{page}}/r/{{r}}">
+				{{plus}}
+				<br>
+				<br>
+				<button class="btn btn-primary" type="submit">되돌리기</button>
+			</form>
 			{% else %}
 			<h1 class="title">{{title}}</h1>
 			<h2 class="title"><span style="margin-left:5px"></span></h2>