n0099 应定期执行的删除b站链接tracing参数的php:
$telemetryParamNames = ['spm_id_from', 'seid', 'utm_', 'spm', 'share_source'];
$telemetryParamNamesRegex = join('|', $telemetryParamNames);
$sql = $pdo->prepare('SELECT id, discussion_id, number, content FROM prefix_posts WHERE content REGEXP ?');
$sql->execute([$telemetryParamNamesRegex]);
$posts = $sql->fetchAll();
foreach ($posts as $post) {
['id' => $id, 'discussion_id' => $discussionId, 'number' => $number, 'content' => $content] = $post;
echo "removing following querystrings which contains telemetry params for https://n0099.net/v/d/{$discussionId}/{$number}\n";
$matches = [];
preg_match_all('/\/?\?(.*?)(<|">)/', $content, $matches, PREG_SET_ORDER);
echo ' ' . join("\n ", (array_map(fn($i) => $i[1], array_filter($matches, fn($i) => $i[2] === '">')))) . "\n";
if (count($matches) === 0) continue;
$content = preg_replace_callback('/\/?\?(.*?)(<|">)/', fn($m) =>
preg_match("/{$telemetryParamNamesRegex}/", $content, $_matches) === 1 ? $m[2] : $m[0], $content);
$sql2 = $pdo->prepare('UPDATE prefix_posts SET content = ? WHERE id = ?');
$sql2->execute([$content, $id]);
if ($sql2->rowCount() !== 1) {
echo "update for {$id} https://n0099.net/v/d/{$discussionId}/{$number} failed";
}
}
2022-07-22:清理了23个