Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当用户1不是用户2的好友时隐藏用户1的内容_Php_Stream_Pseudocode_Privacy_If Statement - Fatal编程技术网

Php 当用户1不是用户2的好友时隐藏用户1的内容

Php 当用户1不是用户2的好友时隐藏用户1的内容,php,stream,pseudocode,privacy,if-statement,Php,Stream,Pseudocode,Privacy,If Statement,我有一个网站,我正在建设两个用户流。我有“被朋友”的代码,这只是一个使用伪代码的例子,如果在正确的位置使用其他代码。。只不过是在绞尽脑汁 我需要的是,当我的user1_id访问你的user2_id流时,如果我们不是朋友,它会隐藏表单和流,并告诉我在查看之前添加你。显示您已添加此好友,但好友尚未接受…或显示表单和流(如果我们是好友) 这是所有的代码 这是为了确定我的用户及其工作方式 <? $user1_id=$_SESSION['id']; if($_SESSION['id']==$use

我有一个网站,我正在建设两个用户流。我有“被朋友”的代码,这只是一个使用伪代码的例子,如果在正确的位置使用其他代码。。只不过是在绞尽脑汁

我需要的是,当我的user1_id访问你的user2_id流时,如果我们不是朋友,它会隐藏表单和流,并告诉我在查看之前添加你。显示您已添加此好友,但好友尚未接受…或显示表单和流(如果我们是好友)

这是所有的代码

这是为了确定我的用户及其工作方式

<?

$user1_id=$_SESSION['id'];
if($_SESSION['id']==$user1_id){
        define('user_isself','2');
    }else{
        define('user_isself','1');
    }

    $friends = rawfeeds_user_core::check_active_friends($id,$_SESSION['id']);

    define('USER_BEFRIENDED',$friends);

    ?>  

这是我的两个提要的代码第一个表单的提要是user1\u id提要,第二个表单的提要是user2\u id提要

<?php if($user2_id==$_SESSION['id']){ ?>
    <div id="statusholder">
    <div class="divider">
        <h2>Post a status</h2>  
        <form action="insert.php" method="POST" target="ifr1" class="form_statusinput">
        <input type="hidden" name="toid" value="<?php echo $user1_id ?>">
        <input type="text" name="newmsg" id="newmsg" class="homescreen_status_input" placeholder="Say something" autocomplete="off">
        <iframe name="ifr1" id="ifr1" style="display:none;"></iframe>
        <input type="submit" target="ifr1" value="Share" >
    </form>
    </div></div>


    <?php 

    //FRIENDSHIPS
            $following_string       =   $_SESSION['id'];
            $sql_follows="SELECT * FROM friends WHERE user1_id=".$_SESSION['id']." AND status=2 OR user2_id=".$_SESSION['id']." AND status=2";
            $query_follows=mysql_query($sql_follows) or die("Error finding friendships");
            if($query_follows>0){
            $friendlist="(".$_SESSION['id'].",";
            $t=0;
            while ($follow=mysql_fetch_array($query_follows))
            {
                if($follow['user1_id']==$_SESSION['id']){
                    if($t>0){
                    $friendlist=$friendlist.",";
                    }
                    $friendlist =   $friendlist. $follow['user2_id'];
                }else{

                    if($t>0){
                        $friendlist=$friendlist.",";
                    }
                    $friendlist =   $friendlist. $follow['user1_id'];

                }
                $t=$t+1;
            }
            $friendlist=$friendlist.")";
            }
        //STREAMDATA
        $badcall = "(".$_SESSION['id'].",)";

if($friendlist==$badcall){
$friendlist="(".$_SESSION['id'].")";
}

        //FRIENDSHIPS
        $user1_id;
            if(isset($data['id'])){
            $user2_id = $data['id'];
            }else{
            $user1_id = $_SESSION['id'];
            }
            $following_string       =   $_SESSION['id'];
            $sql_follows="SELECT * FROM friends WHERE user1_id=".$user1_id." OR user2_id=".$user2_id;
            $query_follows=mysql_query($sql_follows) or die("Error finding friendships");

            while ($follow=mysql_fetch_array($query_follows))
            {
            if($follow['user2_id']==$_SESSION['id']){
                $following_string   =   $following_string. " OR streamitem_creator =" . $follow['user1_id']." OR streamitem_target=".$follow['user1_id'];
            }else{
                $following_string   =   $following_string. " OR streamitem_creator =" . $follow['user2_id']." OR streamitem_target=".$follow['user2_id'];
            }
            }

        //STREAMDATA

        $call="SELECT * FROM streamdata WHERE streamitem_target = " . $user1_id ." AND streamitem_type_id NOT IN ('2') ORDER BY streamitem_timestamp DESC LIMIT 15";
    $chant= mysql_query($call) or die(mysql_error());
        $num = mysql_num_rows($chant);
        if($num>0){

            while($streamitem_data = mysql_fetch_array($chant)){



                echo'<div id="statusholder"><div class="divider">';
                if($streamitem_data['streamitem_type_id'] == 1||$streamitem_data['streamitem_type_id'] == 3){
                echo "<img class='stream_profileimage' style='border:none;padding:0px;display:inline;' src='";rawfeeds_user_core::output_profile_image_url($streamitem_data['streamitem_creator']);echo "' onerror='this.src=\"/img/no_profile_img.jpeg\";'>
                ";
                    $poster_name = rawfeeds_user_core::getuser($streamitem_data['streamitem_creator']);
                    $target_name = rawfeeds_user_core::getuser($streamitem_data['streamitem_target']);
                    $cont = stripslashes($streamitem_data['streamitem_content']);

                    if(!($streamitem_data['streamitem_type_id']==2)){
                    $cont = htmlentities($cont);
                    $cont = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a class='user_link' href=\"\\0\">\\0</a>", $cont);

                    }

                    if($streamitem_data['streamitem_creator']==$streamitem_data['streamitem_target']){
                        echo "<a href='/sn-profile.php?user1_id=".$poster_name['id']."'>" . $poster_name['fullusersname']."</a><span class='subtleLink'> said </span>";
                    }else{
                        echo "<a href='/sn-profile.php?user1_id=".$poster_name['id']."'>" .$poster_name['fullusersname']."</a>  
                        <span class='subtleLink'>wrote</span>";
                    }
                    echo "<br/><a href='#' class='subtleLink' style='font-weight:normal;'>".Agotime($streamitem_data['streamitem_timestamp'])."</a><hr>";

                    if($streamitem_data['streamitem_type_id']==2){
                    $cont = nl2br($cont);
                    echo "<div style='display:inline;'><span class='subtleLink'>".$cont."</span> </div>";
                    }else{

                        if($streamitem_data['streamitem_creator']==$streamitem_data['streamitem_target']){
                        $cont = nl2br($cont);
                            echo "<div>".$cont."</div>";
                        }else{
                        $cont = nl2br($cont);
                        echo "<div>".$cont."</div>";

                        }
                        echo"</div></div>";
                    }}}

                ?>  
                    <div class="stream_show_posts" onClick="global_streamcount=global_streamcount+10;refreshstream();">Show More Posts</div>
                    <?php                   
}else{
            echo "<div class='global_softerror'>No posts yet!</div>";
        }

    }else{
    ?>
-----------------------------------------START OF USER2_ID'S STREAM-------
<div id="statusholder">
    <div class="divider">
        <h2>Post on <?php echo $data['fullusersname']; ?>'s stream</h2>
        <form action="insert.php" method="POST" target="ifr2" class="form_statusinput">
        <input type="hidden" name="toid" value="<?php echo $user2_id ?>">
        <input type="text" name="newmsg" id="newmsg" class="homescreen_status_input" placeholder="Say something" autocomplete="off">
        <iframe name="ifr2" id="ifr2" style="display:none;"></iframe>
        <input type="submit" target="ifr2" value="Share" >

    </form>
    </div></div>


    <?php 
    //FRIENDSHIPS
            $following_string       =   $_SESSION['id'];
            $sql_follows="SELECT * FROM friends WHERE user2_id=".$_SESSION['id']." AND status=2 OR user1_id=".$_SESSION['id']." AND status=2";
            $query_follows=mysql_query($sql_follows) or die("Error finding friendships");
            if($query_follows>0){
            $friendlist="(".$_SESSION['id'].",";
            $t=0;
            while ($follow=mysql_fetch_array($query_follows))
            {
                if($follow['user2_id']==$_SESSION['id']){
                    if($t>0){
                    $friendlist=$friendlist.",";
                    }
                    $friendlist =   $friendlist. $follow['user1_id'];
                }else{

                    if($t>0){
                        $friendlist=$friendlist.",";
                    }
                    $friendlist =   $friendlist. $follow['user2_id'];

                }
                $t=$t+1;
            }
            $friendlist=$friendlist.")";
            }
        //STREAMDATA
        $badcall = "(".$_SESSION['id'].",)";

if($friendlist==$badcall){
$friendlist="(".$_SESSION['id'].")";
}

  date_default_timezone_set("GMT");


        //FRIENDSHIPS
        $user1_id;
            if(isset($data['id'])){
            $user2_id = $data['id'];
            }else{
            $user1_id = $_SESSION['id'];
            }
            $following_string       =   $_SESSION['id'];
            $sql_follows="SELECT * FROM friends WHERE user2_id=".$user2_id." OR user1_id=".$user1_id;
            $query_follows=mysql_query($sql_follows) or die("Error finding friendships");

            while ($follow=mysql_fetch_array($query_follows))
            {
            if($follow['user1_id']==$_SESSION['id']){
                $following_string   =   $following_string. " OR streamitem_creator =" . $follow['user2_id']." OR streamitem_target=".$follow['user2_id'];
            }else{
                $following_string   =   $following_string. " OR streamitem_creator =" . $follow['user1_id']." OR streamitem_target=".$follow['user1_id'];
            }
            }

        //STREAMDATA

        $call="SELECT * FROM streamdata WHERE streamitem_target = " . $user2_id ." AND streamitem_type_id NOT IN ('2') ORDER BY streamitem_timestamp DESC LIMIT 15";
    $chant= mysql_query($call) or die(mysql_error());
        $num = mysql_num_rows($chant);
        if($num>0){

            while($streamitem_data = mysql_fetch_array($chant)){

                echo'<div id="statusholder">
    <div class="divider">';
                if($streamitem_data['streamitem_type_id'] == 1||$streamitem_data['streamitem_type_id'] == 3){
                echo "<img class='stream_profileimage' style='border:none;padding:0px;display:inline;' src='";rawfeeds_user_core::output_profile_image_url($streamitem_data['streamitem_creator']);echo "' onerror='this.src=\"/img/no_profile_img.jpeg\";'>
                ";
                    $poster_name = rawfeeds_user_core::getuser($streamitem_data['streamitem_creator']);
                    $target_name = rawfeeds_user_core::getuser($streamitem_data['streamitem_target']);
                    $cont = stripslashes($streamitem_data['streamitem_content']);

                    if(!($streamitem_data['streamitem_type_id']==2)){
                    $cont = htmlentities($cont);
                    $cont = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a class='user_link' href=\"\\0\">\\0</a>", $cont);

                    }

                    if($streamitem_data['streamitem_creator']==$streamitem_data['streamitem_target']){
                        echo "<a href='/profile.php?username=".$poster_name['username']."'>" . $poster_name['fullusersname']."</a><span class='subtleLink'> said </span>";
                    }else{
                        echo "<a href='/profile.php?username=".$poster_name['username']."'>" .$poster_name['fullusersname']."</a>  
                        <span class='subtleLink'>wrote</span>";
                    }
                    echo "<br/><a href='#' class='subtleLink' style='font-weight:normal;'>".Agotime($streamitem_data['streamitem_timestamp'])."</a><hr>";

                    if($streamitem_data['streamitem_type_id']==2){
                    $cont = nl2br($cont);
                    echo "<div style='display:inline;'><span class='subtleLink'>".$cont."</span> </div>";
                    }else{

                        if($streamitem_data['streamitem_creator']==$streamitem_data['streamitem_target']){
                        $cont = nl2br($cont);
                            echo "<div>".$cont."</div>";
                        }else{
                        $cont = nl2br($cont);
                        echo "<div>".$cont."</div>";
                        }
                    echo'</div>';
                    }}
            }
                    }else{
            echo "<div class='global_softerror'>No posts yet!</div>";
                    }
                    echo'<div class="stream_show_posts" onClick="global_streamcount=global_streamcount+10;refreshstream();">Show More Posts</div>';
    }
}

            ?>

张贴状态

在不阅读所有代码的情况下,我建议使用一个简单的多维数组:

$friends_of_users["user1"] = array("user3", "user9");
$friends_of_users["user2"] = array("user5", "user6");
$friends_of_users["user3"] = array("user1", "user7");
这是伪代码,您应该使用ID而不是“userX”,当然。
到目前为止,这不是最性感的解决方案,但它会解决您的问题。

查看您的代码,我假设您想从数据库中驱动友谊。我不太明白发布的许多代码的相关性,但我可以提出一些建议:

编写函数返回友谊“状态”

我想你会想在其他地方做类似的事情(内容隐藏/原始隐私),所以这很有希望是有用的。显然,我无法测试这一点,但类似于:

function checkUserFriendship($user1,$user2)
{
  $sql = "SELECT status FROM friends WHERE user1_id = $user1 AND user2_id = $user2 OR user1_id = $user2 AND user2_id = $user1";
  $query = mysql_query($sql);
  $data  = mysql_fetch_array($query);
  return $data['status'];
}
现在,我高度怀疑这是否会立即生效,但它(希望)能够实现的是返回“好友”表中的“状态”字段。然后,您可以在输出时使用它。例如:

$friendshipStatus = checkUserFriendship($user1,$user2);

switch($friendshipStatus){
 case "accepted":
  //Show something
 break;
 case "pending":
  //Show "pending" message
 break;
 case 0:
  //Show nothing (or an error message)
 break;
}
这可能不是你想要的,但这是我解决问题的方法。看起来您可能已经使用包含

rawfeeds_user_core::check_active_friends
但是你发布了很多代码,我不完全确定它们是如何组合在一起的

使用Globals

这是一个旁注,但我要避免使用定义的全局变量。看起来他们在这里没有用

不必要的代码(?)


在您的用户流中(让我们这样称呼它们),您有一大块代码构建SQL的“In(n,n,n,n)”部分,以仅选择某些朋友。我想这在网站的global/public/“News Feed”部分是必要的,但我看不出你在哪里使用它。(这可能是我的疏忽/只是我的愚蠢!)

我计划在这个网站上保留许多会员。我不认为多维数组是解决这个问题的理想方案。我需要尽量减少一个干净的后端代码!嘿,迈克。恕我直言,我没有征求你对我们是否需要另一个社交网站的意见。你甚至不知道我制作网站的目的。我只是需要一个小的编码问题的帮助,这个问题很可能由一个没有编码的外人来解决。我相信这是一个寻求帮助/指导和建议的地方。也许我没有抓住重点。戴夫,你说得对。这是一个寻求帮助/指导的地方,如果我的评论冒犯了你,我向你道歉。每当我看到一个关于朋友关系的问题时,我总是想“布莱,另一个试图创建新facebook的人”。然而,没有人会看穿你的代码墙。如果您希望有人真正正确地回答您的问题,最好提供尽可能少的代码。还有一个相关的问题,请看这里:没问题。你一点也没有冒犯我。如果人们阅读,他们会发现我只是在问我将伪代码放在user1_id表单/流和user2之间的什么位置,这样它就能像我所希望的那样工作。。所有的代码都在那里,只是把它放在正确的地方让我感到困惑谢谢你,西蒙,你的帖子很有建设性,很有帮助,而且切中要害。我已经成功地将你的建议落实到我已经拥有的东西上,并且它100%地发挥了我所需要的作用。非常感谢你的时间和努力。
rawfeeds_user_core::check_active_friends