From 6f6263415be7d893e332d6e6c3404c453304e9e4 Mon Sep 17 00:00:00 2001
From: Choom
Date: Wed, 18 Jan 2023 23:06:56 -0300
Subject: Separando ID de timestamp
---
cgi/api.py | 15 ++++++----
cgi/manage.py | 59 +++++++++++++++++++++++++++++----------
cgi/post.py | 7 ++---
cgi/template.py | 13 +++++----
cgi/templates/board.html | 3 ++
cgi/templates/board.jp.html | 3 ++
cgi/templates/txt_archive.html | 7 ++++-
cgi/templates/txt_board.en.html | 7 ++++-
cgi/templates/txt_board.html | 7 ++++-
cgi/templates/txt_thread.html | 3 ++
cgi/templates/txt_threadlist.html | 2 +-
cgi/weabot.py | 9 +++---
12 files changed, 97 insertions(+), 38 deletions(-)
(limited to 'cgi')
diff --git a/cgi/api.py b/cgi/api.py
index 129da97..ffc9e39 100644
--- a/cgi/api.py
+++ b/cgi/api.py
@@ -75,7 +75,7 @@ def api_process(self, path_split):
if limit > 50:
raise APIError("Maximum limit is 50")
- sql = "SELECT posts.id, boards.dir, timestamp, timestamp_formatted, posts.name, tripcode, email, posts.subject, posts.message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, parentid FROM posts INNER JOIN boards ON boardid = boards.id WHERE timestamp > %d AND IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %d" % (
+ sql = "SELECT posts.id, boards.dir, timestamp, timestamp_formatted, posts.name, tripcode, email, posterid, posts.subject, posts.message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, parentid FROM posts INNER JOIN boards ON boardid = boards.id WHERE timestamp > %d AND IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %d" % (
since, limit)
values['posts'] = FetchAll(sql)
@@ -89,6 +89,7 @@ def api_process(self, path_split):
post['thumb_width'] = post['thumb_width']
post['thumb_height'] = post['thumb_height']
post['message'] = post['message']
+
elif method == 'lastage':
data_limit = formdata.get('limit')
data_time = formdata.get('time', 0)
@@ -110,6 +111,7 @@ def api_process(self, path_split):
values['threads'] = threads
else:
values['threads'] = []
+
elif method == 'list':
data_board = formdata.get('dir')
data_offset = formdata.get('offset')
@@ -146,15 +148,14 @@ def api_process(self, path_split):
board = setBoard(data_board)
#sql = "SELECT id, timestamp, bumped, timestamp_formatted, name, tripcode, email, subject, message, file, thumb FROM posts WHERE boardid = %s AND parentid = 0 AND IS_DELETED = 0 ORDER BY bumped DESC LIMIT %d" % (board['id'], limit)
- sql = "SELECT p.id, p.timestamp, p.bumped, p.expires, p.expires_formatted, p.timestamp_formatted, p.name, p.tripcode, p.email, p.subject, p.message, p.file, p.file_size, p.image_width, p.image_height, p.thumb, p.thumb_height, p.thumb_width, p.locked, coalesce(x.count,0) AS total_replies, coalesce(x.files,0) AS total_files FROM `posts` AS p LEFT JOIN (SELECT parentid, count(1) as count, count(nullif(file, '')) as files FROM `posts` WHERE boardid = %(board)s GROUP BY parentid) AS x ON p.id=x.parentid WHERE p.parentid = 0 AND p.boardid = %(board)s AND p.IS_DELETED = 0 ORDER BY `bumped` DESC LIMIT %(limit)d OFFSET %(offset)d" % {
+ sql = "SELECT p.id, p.timestamp, p.bumped, p.expires, p.expires_formatted, p.timestamp_formatted, p.name, p.tripcode, p.email, p.posterid, p.subject, p.message, p.file, p.file_size, p.image_width, p.image_height, p.thumb, p.thumb_height, p.thumb_width, p.locked, coalesce(x.count,0) AS total_replies, coalesce(x.files,0) AS total_files FROM `posts` AS p LEFT JOIN (SELECT parentid, count(1) as count, count(nullif(file, '')) as files FROM `posts` WHERE boardid = %(board)s GROUP BY parentid) AS x ON p.id=x.parentid WHERE p.parentid = 0 AND p.boardid = %(board)s AND p.IS_DELETED = 0 ORDER BY `bumped` DESC LIMIT %(limit)d OFFSET %(offset)d" % {
'board': board["id"], 'limit': limit, 'offset': offset}
threads = FetchAll(sql)
if numreplies:
for thread in threads:
- lastreplies = FetchAll("SELECT id, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, IS_DELETED FROM `posts` WHERE parentid = %s AND boardid = %s ORDER BY `timestamp` DESC LIMIT %s",
- (thread['id'], board['id'], numreplies))
+ lastreplies = FetchAll("SELECT id, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, IS_DELETED FROM `posts` WHERE parentid = %s AND boardid = %s ORDER BY `timestamp` DESC LIMIT %s", (thread['id'], board['id'], numreplies))
lastreplies = lastreplies[::-1]
thread['id'] = thread['id']
thread['timestamp'] = thread['timestamp']
@@ -193,6 +194,7 @@ def api_process(self, path_split):
thread['replies'].append(post)
values['threads'] = threads
+
elif method == 'thread':
data_board = formdata.get('dir')
data_threadid = formdata.get('id')
@@ -257,7 +259,7 @@ def api_process(self, path_split):
values['total_replies'] = total_replies
- sql = "SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE boardid = %s AND (parentid = %s OR id = %s) ORDER BY id ASC LIMIT %s OFFSET %s"
+ sql = "SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE boardid = %s AND (parentid = %s OR id = %s) ORDER BY id ASC LIMIT %s OFFSET %s"
sqlv = (board['id'], values['id'], values['id'], limit, offset)
posts = FetchAll(sql, sqlv)
@@ -288,6 +290,7 @@ def api_process(self, path_split):
post['message'] = re.compile(
r"<[^>]*?>", re.DOTALL | re.IGNORECASE).sub("", post['message'])
values['posts'].append(post)
+
elif method == 'get':
data_board = formdata.get('dir')
data_parentid = formdata.get('thread')
@@ -308,7 +311,7 @@ def api_process(self, path_split):
except ValueError:
raise APIError("Post ID must be numeric")
- post = FetchOne("SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE `id` = %s AND boardid = %s"
+ post = FetchOne("SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE `id` = %s AND boardid = %s"
(postid, board["id"]))
if not post:
diff --git a/cgi/manage.py b/cgi/manage.py
index 79a94de..e3d7704 100644
--- a/cgi/manage.py
+++ b/cgi/manage.py
@@ -527,14 +527,17 @@ def manage(self, path_split):
if post['name'] == oldboardname:
post['name'] = board['anonymous']
- # fix date and (re)add post ID if necessary
+ # fix date
post['timestamp_formatted'] = formatTimestamp(post['timestamp'])
+
+ #(re)add post ID if necessary
if board["useid"] != '0':
if post["parentid"]:
tym = parent_time
else:
tym = post["timestamp"]
- post['timestamp_formatted'] += ' ID:' + iphash(post['ip'], post, tym, board["useid"], False, '', False, False, (board["countrycode"] in [1, 2]))
+
+ post['posterid'] = iphash(post['ip'], post, tym, board["useid"], False, '', False, False, (board["countrycode"] in [1, 2]))
# insert new post and get its new ID
new_id = post.insert()
@@ -1450,27 +1453,55 @@ def manage(self, path_split):
self.output = "done"
return
+ elif path_split[2] == 'sepid':
+ if not administrator:
+ return
+
+ #sql = 'update posts set posterid = \'\''
+ #UpdateDb(sql)
+
+ board = setBoard(path_split[3])
+ #posts = FetchAll('SELECT * FROM `posts` WHERE `boardid` = %s LIMIT 5' % board['id'])
+ #for post in posts:
+ # self.output += str(post)
+
+ #return
+
+ posts = FetchAll('SELECT * FROM `posts` WHERE `boardid` = %s' % board['id'])
+
+ for post in posts:
+ if not post['posterid']:
+ splitted = post['timestamp_formatted'].split(' ID:')
+
+ self.output += splitted[0] + '
'
+
+ idhash = ''
+ if len(splitted) > 1:
+ self.output += splitted[1]
+ idhash = splitted[1]
+
+ self.output += '