0

我不确定如何表达,所以如果您需要更多说明,我可以尽力解释。

这是代码

$file = "shout.txt";
$filed = file_get_contents($file);
preg_match_all('|<div class=\'date\'>(?P<date>.*?)&nbsp;.*<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?');\">&oslash;</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循环中,但我不知道该怎么做,因为我需要检查一个用户是管理员/mod,如果他们在帖子旁边放置了一个删除/禁止按钮以允许他们删除。就目前而言,它会在所有帖子旁边放置一个删除按钮,然后使用它们旁边的删除和禁止按钮将它们全部复制。

4

1 回答 1

1

这是避免重复消息的最简单修改。您必须提供一个函数,该函数author()从 say_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?');\">&oslash;</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]);
        }
    }
}

这可能不是最好的方法,因为它为来自作者的每条消息重复“禁止此用户”。最好在每个用户的开头放置一次禁止/取消禁止选项,然后在每一行上“删除”。

于 2012-12-10T20:50:09.133 回答