<commit_before><?php

if (!defined("WEBPAGE_CONTEXT")) {
    exit;
}

function logout() {
    if (isset($_SESSION['user'])) {
        foreach ($_SESSION['user'] as &$info) {
            unset($info);
        }
        unset($_SESSION['user']);
    }

    $_SESSION = array();
    unset($_SESSION);
    session_destroy();
    session_start();
}

function get_user_by_handle($handle) {
    global $db;
    $query = "SELECT * FROM `users` WHERE `handle`='".$db->real_escape_string($handle)."'";
    $result = $db->query($query);
    if ($result) {
	return $result->fetch_assoc();
    }
    return null;
}
function get_user_by_email($email) {
    global $db;
    $query = "SELECT * FROM `users` WHERE `email`='".$db->real_escape_string($email)."'";
    $result = $db->query($query);
    if ($result) {
	return $result->fetch_assoc();
    }
    return null;
}
function get_user_by_id($user_id) {
    global $db;
    $query = "SELECT * FROM `users` WHERE `user_id`=".$db->real_escape_string((int)$user_id);
    $result = $db->query($query);
    if ($result) {
	return $result->fetch_assoc();
    }
    return null;
}
function get_this_user() {
    if (!is_logged_in()) {
	return null;
    }
    $user_id = $_SESSION['user']['id'];
    return get_user_by_id($user_id);
}

function get_num_posts($user_id) {
    global $db;
    $query = "SELECT COUNT(*) as `num_posts` FROM `posts`
              WHERE `user_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    if ($results) {
        $row = $results->fetch_assoc();
        if ($row && isset($row['num_posts'])) {
            return (int)$row['num_posts'];
        }
    }
    return 0;
}
function get_num_following($user_id) {
    global $db;
    $query = "SELECT COUNT(*) as `num_following` FROM `follows`
              WHERE `user_source_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    if ($results) {
        $row = $results->fetch_assoc();
        if ($row && isset($row['num_following'])) {
            return (int)$row['num_following'];
        }
    }
    return 0;
}
function get_num_followers($user_id) {
    global $db;
    $query = "SELECT COUNT(*) as `num_followers` FROM `follows`
              WHERE `user_destination_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    if ($results) {
        $row = $results->fetch_assoc();
        if ($row && isset($row['num_followers'])) {
            return (int)$row['num_followers'];
        }
    }
    return 0;
}

function get_posts($user_id) {
    global $db;
    $query = "SELECT * FROM `posts` WHERE `user_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    $post_array = array();
    if ($results) {
        while ($row = $results->fetch_assoc()) {
            $post_array[] = $row;
        }
    }
    return $post_array;
}
function get_following($user_id) {
    global $db;
    $query = "SELECT `user_destination_id` AS `id` FROM `follows`
             WHERE `user_source_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    $following_ids = array();
    if ($results) {
        while ($row = $results->fetch_assoc()) {
            $following_ids[] = (int)$row['id'];
        }
    }
    return $following_ids;
}
function get_followers($user_id) {
    global $db;
    $query = "SELECT `user_source_id` AS `id` FROM `follows`
             WHERE `user_destination_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    $follower_ids = array();
    if ($results) {
        while ($row = $results->fetch_assoc()) {
            $follower_ids[] = (int)$row['id'];
        }
    }
    return $follower_ids;<commit_msg>Displays posts/followers in chronological order in view profile page.<commit_after><?php

if (!defined("WEBPAGE_CONTEXT")) {
    exit;
}

function logout() {
    if (isset($_SESSION['user'])) {
        foreach ($_SESSION['user'] as &$info) {
            unset($info);
        }
        unset($_SESSION['user']);
    }

    $_SESSION = array();
    unset($_SESSION);
    session_destroy();
    session_start();
}

function get_user_by_handle($handle) {
    global $db;
    $query = "SELECT * FROM `users` WHERE `handle`='".$db->real_escape_string($handle)."'";
    $result = $db->query($query);
    if ($result) {
	return $result->fetch_assoc();
    }
    return null;
}
function get_user_by_email($email) {
    global $db;
    $query = "SELECT * FROM `users` WHERE `email`='".$db->real_escape_string($email)."'";
    $result = $db->query($query);
    if ($result) {
	return $result->fetch_assoc();
    }
    return null;
}
function get_user_by_id($user_id) {
    global $db;
    $query = "SELECT * FROM `users` WHERE `user_id`=".$db->real_escape_string((int)$user_id);
    $result = $db->query($query);
    if ($result) {
	return $result->fetch_assoc();
    }
    return null;
}
function get_this_user() {
    if (!is_logged_in()) {
	return null;
    }
    $user_id = $_SESSION['user']['id'];
    return get_user_by_id($user_id);
}

function get_num_posts($user_id) {
    global $db;
    $query = "SELECT COUNT(*) as `num_posts` FROM `posts`
              WHERE `user_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    if ($results) {
        $row = $results->fetch_assoc();
        if ($row && isset($row['num_posts'])) {
            return (int)$row['num_posts'];
        }
    }
    return 0;
}
function get_num_following($user_id) {
    global $db;
    $query = "SELECT COUNT(*) as `num_following` FROM `follows`
              WHERE `user_source_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    if ($results) {
        $row = $results->fetch_assoc();
        if ($row && isset($row['num_following'])) {
            return (int)$row['num_following'];
        }
    }
    return 0;
}
function get_num_followers($user_id) {
    global $db;
    $query = "SELECT COUNT(*) as `num_followers` FROM `follows`
              WHERE `user_destination_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1";
    $results = $db->query($query);
    if ($results) {
        $row = $results->fetch_assoc();
        if ($row && isset($row['num_followers'])) {
            return (int)$row['num_followers'];
        }
    }
    return 0;
}

function get_posts($user_id) {
    global $db;
    $query = "SELECT * FROM `posts`
              WHERE `user_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1
              ORDER BY `date_created` DESC";
    $results = $db->query($query);
    $post_array = array();
    if ($results) {
        while ($row = $results->fetch_assoc()) {
            $post_array[] = $row;
        }
    }
    return $post_array;
}
function get_following($user_id) {
    global $db;
    $query = "SELECT `user_destination_id` AS `id` FROM `follows`
              WHERE `user_source_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1
              ORDER BY `date_created` DESC";
    $results = $db->query($query);
    $following_ids = array();
    if ($results) {
        while ($row = $results->fetch_assoc()) {
            $following_ids[] = (int)$row['id'];
        }
    }
    return $following_ids;
}
function get_followers($user_id) {
    global $db;
    $query = "SELECT `user_source_id` AS `id` FROM `follows`
              WHERE `user_destination_id`=".$db->real_escape_string((int)$user_id)." AND `active`=1
              ORDER BY `date_created` DESC";
    $results = $db->query($query);
    $follower_ids = array();
    if ($results) {
        while ($row = $results->fetch_assoc()) {
            $follower_ids[] = (int)$row['id'];
        }
    }
    return $follower_ids;
{'fraction_non_alphanumeric': 0.18499171869027903, 'fraction_numerical': 0.0022932857688877564, 'mean_word_length': 2.8957816377171217, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2945479', 'n_tokens_mistral': 2717, 'n_tokens_neox': 2673, 'n_words': 515}