我不确定如何说出来,所以如果你需要更多澄清,我可以尽力解释。
这是代码
$file = "shout.txt";
$filed = file_get_contents($file);
preg_match_all('|<div class=\'date\'>(?P<date>.*?) .*<a.*>(?P<user>.*)</a>|i', $filed, $matches);
$shoutlines = file($shout_file);
$aTemp = array();
foreach($matches['user'] as $user) {
$aTemp[] = "'" . mysql_real_escape_string($user) . "'";
}
$user = implode(",", $aTemp);
$getlevel = $db->query("SELECT * FROM accounts WHERE username IN ( ".$user." )");
$isadmin = $db->query("SELECT * FROM accounts WHERE username = '".$_SESSION['username']."'");
$admin = $isadmin->fetch_assoc();
while($status = $getlevel->fetch_assoc()){
//output the html
for($i = 0; $i < (1000); $i++)
{
if(isset($shoutlines[$i]))
{
if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] != Banned){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='javascript: ban({$status['id']});' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
}
if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] == Banned){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&unban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to unban this user?');\">ø</a>";
}
if ($admin['admin'] == 1 && $status['sblevel'] == Admin){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
}
if ($admin['sblevel'] == Moderator && $status['sblevel'] != Admin && $status['sblevel'] != Moderator){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&ban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
}
if ($status['sblevel'] == Moderator && $status['sblevel'] != Admin){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
}
$shoutline = preg_replace('/<\/div>\n/', ' ', $shoutlines[$i], 1);
echo showSmileys($shoutline) . $delete . "</div>";
}
}
}
问题是它复制了每个发布的用户的所有帖子。我假设这是因为它是一个while循环,但我不知道如何去做,因为我需要检查用户是否为admin / mod,以及是否在帖子旁边放置了删除/禁止按钮以允许他们删除。现在它在所有帖子旁边放置一个删除按钮,然后在它们旁边的删除和禁止按钮复制它们。
答案 0 :(得分:1)
这是避免重复消息的最简单修改。您必须提供一个函数author()
,它从shout_file中取一行并返回作者ID。
while($status = $getlevel->fetch_assoc()){
//output the html
for($i = 0; $i < (1000); $i++)
{
if(isset($shoutlines[$i]))
{
if (author($shoutlines[$i]) != $status['id']) {
continue;
}
if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] != Banned){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='javascript: ban({$status['id']});' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
}
if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] == Banned){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&unban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to unban this user?');\">ø</a>";
}
if ($admin['admin'] == 1 && $status['sblevel'] == Admin){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
}
if ($admin['sblevel'] == Moderator && $status['sblevel'] != Admin && $status['sblevel'] != Moderator){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&ban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
}
if ($status['sblevel'] == Moderator && $status['sblevel'] != Admin){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
}
$shoutline = preg_replace('/<\/div>\n/', ' ', $shoutlines[$i], 1);
echo showSmileys($shoutline) . $delete . "</div>";
unset($shoutlines[$i]);
}
}
}
这可能不是最好的方法,因为它为作者的每条消息重复“禁止此用户”。最好将禁止/取消选项放在每个用户的开头一次,然后在每行上“删除”。