Profile like/dislike with simple way to do

اضغط هنا لمعاينة كودي شات( Enter Codychat )

admin

Administrator
طاقم الإدارة
PHP:
hey guys, i hope you all fine.

to make a profile like system, with simple way, follow the next steps.

- create a new column in "boom_users" to store the users likes count.

ALTER TABLE boom_users ADD profile_like int(11) NOT NULL DEFAULT (0);
then we need to create a new table to store who will like who, user1 liked user2.

i will upload a .sql file to make it for you, just import this file in your database.

then open js/function_logged.php and at the end of file add this codes.

proLike = function(id){
    $.ajax({
        url: "system/action_profile.php",
        type: "post",
        cache: false,
        dataType: 'json',
        data: {
            user_like: id,
            token: utk
        },
        success: function(response){
            if(response == 1) {
                callSaved('You liked this profile', 1);
                getProfile(id);
            }
        },
    });
}
proUnLike = function(id){
    $.ajax({
        url: "system/action_profile.php",
        type: "post",
        cache: false,
        dataType: 'json',
        data: {
            user_unlike: id,
            token: utk
        },
        success: function(response){
            if(response == 1) {
                callSaved('Profile Unliked', 1);
                getProfile(id);
            }
        },
    });
}
then open system/action_profile.php and go to the end of file before this mark ?> and add this codes,

if(isset($_POST['user_like'])){
    $target = escape($_POST['user_like']);
    $user = userDetails($target);
    if(!boomAllow(1)){
        die();
    }
    $result = $mysqli->query("SELECT * FROM boom_profile_like WHERE target = '$target' AND hunter = '{$data['user_id']}'");
    if($result->num_rows == 0) {
        $mysqli->query("UPDATE boom_users SET profile_like = profile_like +1 WHERE user_id = '$target'");
        $mysqli->query("INSERT INTO `boom_profile_like` (hunter, target) VALUES ('{$data['user_id']}', '$target')");
        boomNotify($target, 'send_like', array('hunter'=> $data['user_id']));
        echo 1;
        die();
    } else {
        die();
    }
}
if(isset($_POST['user_unlike'])){
    $target = escape($_POST['user_unlike']);
    if(!boomAllow(1)){
        die();
    }
    $result = $mysqli->query("SELECT * FROM boom_profile_like WHERE target = '$target' AND hunter = '{$data['user_id']}'");
    if($result->num_rows == 0) {
        die();
    } else {
        $mysqli->query("UPDATE boom_users SET profile_like = profile_like - 1 WHERE user_id = '$target'");
        $mysqli->query("DELETE FROM boom_profile_like WHERE hunter = '{$data['user_id']}' AND target = '$target'");
        echo 1;
        die();
    }
}
then open system/function.php, and at the end add this functions.

function canLike($user){
    global $mysqli, $data;
    $result = $mysqli->query("SELECT * FROM boom_profile_like WHERE target = '{$user['user_id']}' AND hunter = '{$data['user_id']}'");
    if($result->num_rows == 0) {
        return true;
    }
    else {
        return false;
    }
}
function canUnLike($user){
    global $mysqli, $data;
    $result = $mysqli->query("SELECT * FROM boom_profile_like WHERE target = '{$user['user_id']}' AND hunter = '{$data['user_id']}'");
    if($result->num_rows == 0) {
        return false;
    }
    else {
        return true;
    }
}
then open system/box/profile.php and after this code,

<?php if(notMe($user['user_id']) && !isBot($user)){ ?>
                <button onclick="getActions(<?php echo $user['user_id']; ?>);" class="tiny_button ok_btn "><i class="fa fa-bolt"></i> <span class="hide_phone"><?php echo $lang['do_action']; ?></span></button>
                <?php } ?>
add this codes,

<?php if(!isBot($user) && boomAllow(1) && canLike($user)){ ?>
                <button style="background:#ff295b;color:white;" onclick="proLike(<?php echo $user['user_id']; ?>);" class="tiny_button ok_btn "><i class="fa fa-thumbs-up"></i> <?php echo $user['profile_like']; ?></button>
                <?php } ?>

<?php if(!isBot($user) && boomAllow(1) && canUnLike($user)){ ?>
                <button style="background:#737373;color:white;" onclick="proUnLike(<?php echo $user['user_id']; ?>);" class="tiny_button ok_btn "><i class="fa fa-thumbs-down"></i> <?php echo $user['profile_like']; ?></button>
                <?php } ?>
at the end open system/language .. choose which language you are using, then open notification.php and add this.

$nlang['send_like'] = 'I have liked your profile';
you can make a notification for unlike too but it will make some problems for you, so i suggest to keep it without notification. 😄

and now make a /clearcache command in your chat, and have fun. 😛

download the .sql file to make a likes table in database from attachments.
 

المرفقات

أعلى