0

2 つのユーザー ストリームを使用して構築している Web サイトがあります。私は友人のためのコードを持っています。それは疑似コードelse ifステートメントを適切な場所で使用する単なるケースです..私の頭脳を悩ませているだけです。

私が必要としているのは、user1_id が user2_ids ストリームにアクセスしたときに、フォームとストリームの両方を非表示にして、表示する前に追加するように指示することです。この友達を追加したことを示していますが、友達が承認していません...または、友達である場合はフォームとストリームを表示します。

ここにすべてのコードがあります

これは、ユーザーとその動作を決定するためのものです..

<?

$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);

    ?>  

ここに私の 2 つのフィードのコードがあります。最初のフィードは frist フォームから user1_ids フィードで、2 番目の user2_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>';
    }
}

            ?>

そして、これが挿入する必要があるコードです。

<?php if(USER_BEFRIENDED==0){ ?>
    Add <?php echo $data['fullusersname']; ?> as a friend to see posts and information.
    <?php } 
    if(USER_BEFRIENDED==1){
    ?>
    You've added <?php echo $data['fullusersname']; ?> as a friend, but he hasn't accepted yet. Check back later!
    <?php } }?>

考えてみれば..user2_idのストリームをコーディングする前にこれをコードに入れていただろう..そして、私は今そのようなピクルスにはいないだろう.

誰かが助けてくれることを願っています。

ありがとうございました。

4

2 に答える 2

1

あなたのコードを見ると、データベースから友情を推進したいと思います。投稿された多くのコードの関連性はよくわかりませんが、いくつかの推奨事項を作成できます。

友情の「ステータス」を返す関数を書く

他の場所でも同様のこと (コンテンツ非表示/プリミティブ プライバシー) を行いたいと思うので、これが役立つことを願っています。明らかに、これをテストすることはできませんが、次のようなものです。

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

しかし、あなたは多くのコードを投稿しましたが、それがどのように組み合わされているのか完全にはわかりません.

グローバルの使用

これは補足ですが、定義されたグローバルの使用は避けたいと思います。彼らがここで目的を果たしているようには見えません。

不要なコード (?)

ユーザー ストリーム (そのように呼びましょう) には、SQL の "IN (n,n,n,n)" 部分を構成する巨大なコード ブロックがあり、特定のフレンドのみを選択します。これはサイトのグローバル/パブリック/「ニュースフィード」部分で必要だと思いますが、どこで使用しているのかわかりません. (これは見落としかもしれません/私の愚かさです!)

于 2012-07-04T08:02:13.400 に答える
0

コードをすべて読まずに、単純な多次元配列をお勧めします。

$friends_of_users["user1"] = array("user3", "user9");
$friends_of_users["user2"] = array("user5", "user6");
$friends_of_users["user3"] = array("user1", "user7");

これは疑似コードです。「userX」の代わりに ID を使用する必要があります。これは最も魅力的な解決策ではありませんが、問題は解決します。

于 2012-07-03T23:03:32.750 に答える