diff options
Diffstat (limited to 'cgi/post.py')
-rw-r--r-- | cgi/post.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/cgi/post.py b/cgi/post.py index 6f7ff03..22d8197 100644 --- a/cgi/post.py +++ b/cgi/post.py @@ -149,10 +149,7 @@ def getThread(postid=0, mobile=False, timestamp=0): thread["message"] = op_post["message"] thread["locked"] = op_post["locked"] thread["size"] = "%d KB" % int(total_bytes / 1000) - - #threads = [thread] else: - raise Exception(postid) return None finally: database_lock.release() @@ -416,7 +413,7 @@ def threadList(mode=0): thread['message'] = thread['message'].replace('<br />', ' ') thread['message'] = thread['message'].split("<hr />")[0] thread['message'] = re.compile(r"<[^>]*?>", re.DOTALL | re.IGNORECASE).sub('', thread['message']) - thread['message'] = thread['message'].decode('utf-8')[:cutFactor].encode('utf-8') + thread['message'] = thread['message'][:cutFactor] thread['message'] = re.compile(r"&(.(?!;))*$", re.DOTALL | re.IGNORECASE).sub('', thread['message']) # Removes incomplete HTML entities thread['timestamp_formatted'] = re.compile(r"\(.{1,3}\)", re.DOTALL | re.IGNORECASE).sub(" ", thread['timestamp_formatted']) @@ -432,7 +429,7 @@ def threadList(mode=0): lastreply['message'] = lastreply['message'].replace('<br />', ' ') lastreply['message'] = lastreply['message'].split("<hr />")[0] lastreply['message'] = re.compile(r"<[^>]*?>", re.DOTALL | re.IGNORECASE).sub('', lastreply['message']) - lastreply['message'] = lastreply['message'].decode('utf-8')[:60].encode('utf-8') + lastreply['message'] = lastreply['message'][:60] lastreply['message'] = re.compile(r"&(.(?!;))*$", re.DOTALL | re.IGNORECASE).sub('', lastreply['message']) # Removes incomplete HTML entities lastreply['timestamp_formatted'] = re.compile(r"\(.{1,3}\)", re.DOTALL | re.IGNORECASE).sub(" ", lastreply['timestamp_formatted']) thread["lastreply"] = lastreply @@ -540,6 +537,7 @@ def dynamicRead(parentid, ranges, mobile=False): if not thread: # Try the archive + import json fname = Settings.ROOT_DIR + board["dir"] + "/kako/" + str(parentid) + ".json" if os.path.isfile(fname): import json @@ -809,6 +807,7 @@ def trimThreads(): logging.debug("Trimming threads") board = Settings._.BOARD archived = False + trimmed = [] # Use limit of the board type if board['board_type'] == 1: @@ -817,21 +816,22 @@ def trimThreads(): limit = Settings.MAX_THREADS # trim expiring threads first - if board['maxage'] != '0': + if board['maxage'] > 0: t = time.time() - alert_time = int(round(int(board['maxage']) * Settings.MAX_AGE_ALERT)) + alert_time = int(round(board['maxage'] * Settings.MAX_AGE_ALERT)) time_limit = t + (alert_time * 86400) old_ops = FetchAll("SELECT `id`, `timestamp`, `expires`, `expires_alert`, `length` FROM `posts` WHERE `boardid` = %s AND `parentid` = 0 AND IS_DELETED = 0 AND `expires` > 0 AND `expires` < %s LIMIT 50", (board['id'], time_limit)) for op in old_ops: - if t >= int(op['expires']): + if t >= op['expires']: # Trim old threads if board['archive'] and op["length"] >= Settings.ARCHIVE_MIN_LENGTH: archiveThread(op["id"]) archived = True deletePost(op["id"], None) + trimmed.append(op["id"]) else: # Add alert to threads approaching deletion UpdateDb("UPDATE `posts` SET expires_alert = 1 WHERE `boardid` = %s AND `id` = %s", (board['id'], op['id'])) @@ -840,7 +840,7 @@ def trimThreads(): if board['maxinactive'] > 0: t = time.time() - oldest_last = t - (int(board['maxinactive']) * 86400) + oldest_last = t - (board['maxinactive'] * 86400) old_ops = FetchAll("SELECT `id`, `length` FROM `posts` WHERE `boardid` = %s AND `parentid` = 0 AND IS_DELETED = 0 AND `last` < %s LIMIT 50", (board['id'], oldest_last)) for op in old_ops: @@ -849,6 +849,7 @@ def trimThreads(): archived = True deletePost(op["id"], None) + trimmed.append(op["id"]) # select trim type by board if board['board_type'] == 1: @@ -874,10 +875,12 @@ def trimThreads(): archived = True deletePost(post["id"], None) - pass + trimmed.append(op["id"]) if archived: regenerateKako() + + return trimmed def autoclose_thread(parentid, t, replies): """ @@ -1099,7 +1102,6 @@ def regenerateAccess(): if not Settings.HTACCESS_GEN: return False - boards = FetchAll('SELECT `dir` FROM `boards`') global_boards = [board['dir'] for board in boards if board['dir'] not in Settings.EXCLUDE_GLOBAL_BANS] @@ -1108,11 +1110,11 @@ def regenerateAccess(): board_bans = {} if Settings.ENABLE_BANS: - bans = FetchAll("SELECT `ipstr`, `boards` FROM `bans` WHERE `blind` = '1' ORDER BY `ipstart` ASC") + bans = FetchAll("SELECT `ipstr`, `boards` FROM `bans` WHERE `blind` = 1 ORDER BY `ipstart` ASC") for ban in bans: if ban["boards"]: - boards = pickle.loads(ban["boards"]) + boards = str2boards(ban["boards"]) for board in boards: board_bans.setdefault(board, []).append(ban["ipstr"]) else: @@ -1233,7 +1235,8 @@ def archiveThread(postid): except: raise UserError("Can't archive: %s" % thread['timestamp']) - UpdateDb("REPLACE INTO archive (id, boardid, timestamp, subject, length) VALUES ('%s', '%s', '%s', '%s', '%s')" % (thread['id'], board['id'], thread['timestamp'], _mysql.escape_string(thread['subject']), thread['length'])) + UpdateDb("REPLACE INTO archive (oldid, boardid, timestamp, subject, length) VALUES (%s, %s, %s, %s, %s)", + (thread['id'], board['id'], thread['timestamp'], thread['subject'], thread['length'])) def throw_dice(dice): qty = int(dice[0][1:]) |