import sys with open('index.php', 'r') as f: lines = f.readlines() start_marker = "" in line and i > 1200: # around there else_line = i break if not else_line: print("Error: Could not find the final else line") sys.exit(1) # Now find the first foreach after this else start_line = 0 for i in range(else_line, len(lines)): if start_marker in lines[i]: start_line = i break if not start_line: print("Error: Could not find start marker after else") sys.exit(1) # Now find the end of this block. It should end with # But I might have multiple ones now. # We want to find the one that is followed by (closing the main if) # and then (closing chat-container or messages-list) end_line = 0 for i in range(start_line, len(lines)): if "" in lines[i]: # Check if next line (or soon after) is is_real_end = False for j in range(i+1, min(i+10, len(lines))): if "" in lines[j]: is_real_end = True end_line = j break if is_real_end: break if not end_line: print("Error: Could not find end marker") sys.exit(1) print(f"Replacing lines {start_line+1} to {end_line+1}") new_block = """
">
"> Épinglé
📊 SONDAGE
$opt): $count = 0; $user_voted = false; if (isset($m['votes_data'])) { foreach($m['votes_data'] as $v) { if ($v['option_index'] == $idx) { $count = (int)$v['vote_count']; $user_ids = explode(',', $v['user_ids'] ?? ''); if (in_array($current_user_id, $user_ids)) { $user_voted = true; } break; } } } $percent = $total_votes > 0 ? round(($count / $total_votes) * 100) : 0; $is_expired = !empty($meta['end_date']) && strtotime($meta['end_date']) < time(); ?>
% ()
prepare("SELECT emoji, COUNT(*) as count, GROUP_CONCAT(user_id) as users FROM message_reactions WHERE message_id = ? GROUP BY emoji"); $stmt_react->execute([$m['id']]); $reactions = $stmt_react->fetchAll(); foreach ($reactions as $r): $reacted = in_array($current_user_id, explode(',', $r['users'])); ?> +
""" # Adjust end_line to be the last endif before the start of next section # The original file has at line 1486 in my previous read. # Let's verify. with open('index.php', 'w') as f: f.writelines(lines[:start_line]) f.write(new_block) f.write("\n") f.writelines(lines[end_line+1:])