Пример #1
0
function render_suggested_users($days = 7, $page = 1)
{
    $start = (intval($page) - 1) * 20;
    $html = render_header("Suggested Users");
    $html .= "<div class=\"bg_menu_wrapper\">\n" . "<ul class=\"bg_menu\">\n" . "<li><a href=\"/explore/firehose\" title=\"Firehose\">Firehose</a></li>\n" . "<li><a href=\"/explore/popular\" title=\"Popular\">Popular</a></li>\n" . "<li><a href=\"/explore/tags\" title=\"Tags\">Tags</a></li>\n" . "<li><a href=\"/explore/directory\" title=\"Directory\">Directory</a></li>\n" . "<li class=\"selected\"><a href=\"/explore/suggested\" title=\"Suggested Users\">Suggested</a></li>\n" . "<li><a href=\"/explore/search\" title=\"Search\">Search</a></li>\n" . "</ul>\n" . "<div class=\"clear\"></div>\n" . "</div>\n";
    $mysqli = db_connect();
    $html .= "<div id=\"header\">\n" . "<h1>Suggested Users</h1>\n" . "<p>Users with the most popular public content over the last " . $days . " days.</p>\n" . "</div>\n";
    $sql = "SELECT Users.*, COUNT(DISTINCT Posts.Id) AS PostCount, COUNT(DISTINCT Comments.Id) AS CommentCount, COUNT(DISTINCT Likes.Id) AS LikesCount, COUNT(DISTINCT Posts.Id) + COUNT(DISTINCT Comments.Id) + COUNT(DISTINCT Likes.Id) AS TotalCount\n" . " FROM Users" . " INNER JOIN Posts ON Posts.UserId=Users.Id AND Posts.Status=1 AND Posts.Privacy=0" . " LEFT OUTER JOIN Comments ON Posts.Id=Comments.PostId AND Comments.UserId<>Users.Id" . " LEFT OUTER JOIN Likes ON Posts.Id=Likes.PostId AND Likes.UserId<>Users.Id" . " WHERE Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '" . $mysqli->real_escape_string($days) . "' DAY)" . " GROUP BY Users.Id" . " ORDER BY TotalCount DESC" . " LIMIT " . $mysqli->real_escape_string($start) . ",20";
    $sql_count = "SELECT COUNT(DISTINCT Users.Id) AS NumUsers" . " FROM Users" . " INNER JOIN Posts ON Posts.UserId=Users.Id AND Posts.Status=1 AND Posts.Privacy=0" . " WHERE (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '" . $mysqli->real_escape_string($days) . "' DAY))";
    $user_result = $mysqli->query($sql);
    if ($user_result->num_rows > 0) {
        $html .= "<div class=\"directory_users\">\n";
        while ($user_row = @$user_result->fetch_assoc()) {
            $html .= render_user($user_row);
        }
        $html .= "<div class=\"clear\"></div>\n" . "</div>\n";
    }
    // fetch count for pagination
    $count_result = $mysqli->query($sql_count);
    $count_row = $count_result->fetch_assoc();
    $count = $count_row["NumUsers"];
    $html .= render_pagination("explore/suggested/" . $days, $page, $count, 20);
    $html .= render_footer();
    return $html;
}
Пример #2
0
function render_user_directory($tag_name = "", $page = 1)
{
    $start = (intval($page) - 1) * 20;
    $html = render_header("User Directory");
    $mysqli = db_connect();
    // check if a tag is passed in
    if ($tag_name == "") {
        // No tag - draw the tags
        $sql = "SELECT Tags.Name AS TagName, COUNT(Tags.Id) AS TagCount" . " FROM Tags" . " INNER JOIN UserTags ON Tags.Id=UserTags.TagId" . " INNER JOIN Users ON UserTags.UserId=Users.Id" . " GROUP BY Tags.Name" . " ORDER BY Tags.Name";
        // ." HAVING COUNT(Tags.Id)>1" - goes above ORDER BY
        $html .= "<div id=\"header\">\n" . "<h1>User Directory</h1>\n" . "<p>Explore the tags users have filed themselves under - edit your <a href=\"/account\">account</a> details to file yourself under some tags.</p>\n" . "</div>\n";
        $tags_result_a = $mysqli->query($sql);
        $tags_result_b = $mysqli->query($sql);
        // find the most tags to do sizing
        $max_tags = 0;
        while ($tags_row = @$tags_result_a->fetch_assoc()) {
            if (intval($tags_row["TagCount"]) > $max_tags) {
                $max_tags = intval($tags_row["TagCount"]);
            }
        }
        $range = 2;
        $html .= "<div id='tags_page'>\n" . "<div class=\"tags\">\n";
        while ($tags_row = @$tags_result_b->fetch_assoc()) {
            // math to work out size of font
            $tag_count = $tags_row["TagCount"];
            $ratio = $tag_count / $max_tags;
            $size = number_format(1 + $ratio * $range, 1);
            $html .= "<div class='tag' style='font-size:" . $size . "em !important;'><a title='" . addslashes($tags_row["TagName"]) . "' href='/directory/" . htmlspecialchars($tags_row["TagName"]) . "'>" . str_replace(" ", "&nbsp;", $tags_row["TagName"]) . "</a><br /><small>" . $tags_row["TagCount"] . " users</small></div>\n";
        }
        $html .= "<div class='clear'></div>\n" . "</div> <!-- .tags -->\n" . "</div> <!-- #tags_page -->\n";
    } else {
        $html .= "<div id=\"header\">\n" . "<h1>User Directory : &#8216;<span>" . $tag_name . "</span>&#8217;</h1>\n" . "<p>Here are the users that have filed themselves under the tag '" . $tag_name . "'</p>\n" . "</div>\n";
        // get all the users with a particular tag
        $sql = "SELECT Users.*, COUNT(DISTINCT Posts.Id) AS PostCount, COUNT(DISTINCT Comments.Id) AS CommentCount, COUNT(DISTINCT Likes.Id) AS LikesCount,COUNT(DISTINCT Posts.Id) + COUNT(DISTINCT Comments.Id) + COUNT(DISTINCT Likes.Id) AS TotalCount\n" . " FROM Users" . " INNER JOIN UserTags ON Users.Id=UserTags.UserId" . " INNER JOIN Tags ON Tags.Id=UserTags.TagId" . " LEFT OUTER JOIN Posts ON Posts.UserId=Users.Id AND Posts.Status=1 AND Posts.Privacy=0" . " LEFT OUTER JOIN Comments ON Posts.Id=Comments.PostId AND Comments.UserId<>Users.Id" . " LEFT OUTER JOIN Likes ON Posts.Id=Likes.PostId AND Likes.UserId<>Users.Id" . " WHERE Tags.Name='" . $mysqli->real_escape_string($tag_name) . "'" . " GROUP BY Users.Id" . " ORDER BY TotalCount DESC" . " LIMIT " . $mysqli->real_escape_string($start) . ",20";
        $sql_count = "SELECT COUNT(DISTINCT Users.Id) AS NumUsers" . " FROM Users" . " INNER JOIN UserTags ON Users.Id=UserTags.UserId" . " INNER JOIN Tags ON Tags.Id=UserTags.TagId" . " INNER JOIN Posts ON Posts.UserId=Users.Id AND Posts.Status=1 AND Posts.Privacy=0" . " LEFT OUTER JOIN Comments ON Posts.Id=Comments.PostId" . " LEFT OUTER JOIN Likes ON Posts.Id=Likes.PostId" . " WHERE Tags.Name='" . $mysqli->real_escape_string($tag_name) . "'" . " GROUP BY Users.Id";
        $user_result = $mysqli->query($sql);
        if ($user_result->num_rows > 0) {
            $html .= "<div class=\"directory_users\">\n";
            while ($user_row = @$user_result->fetch_assoc()) {
                $html .= render_user($user_row);
            }
            $html .= "</div>\n";
        } else {
            $html .= "<p>There are no users filed under the tag '" . $tag_name . "'</p>\n";
        }
        // fetch count for pagination
        $count_result = $mysqli->query($sql_count);
        $count_row = $count_result->fetch_assoc();
        $count = $count_row["NumUsers"];
        $html .= render_pagination("user_directory/" . $tag_name, $page, $count, 20);
    }
    $html .= render_footer();
    return $html;
}
Пример #3
0
function render_profile_page_followers($username, $page)
{
    $html = "";
    $start = (intval($page) - 1) * 20;
    $mysqli = db_connect();
    if (isset($_SESSION["user_id"])) {
        $sql = "SELECT Users.*,Friends.FriendId,FriendsB.FriendId AS FriendBId FROM Users" . " LEFT OUTER JOIN Friends ON Friends.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Friends.FriendId=Users.Id" . " LEFT OUTER JOIN Friends FriendsB ON FriendsB.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND FriendsB.UserId=Users.Id" . " WHERE Username='******'";
    } else {
        $sql = "SELECT * FROM Users WHERE Username='******'";
    }
    $user_result = $mysqli->query($sql);
    if ($user_result->num_rows > 0) {
        $user_row = $user_result->fetch_assoc();
        $user_id = $user_row["Id"];
        $html .= "<div class=\"profile_menu_wrapper\">\n" . "<ul class=\"profile_menu\">\n" . "<li><a href=\"/" . $username . "\" title=\"Posts\">Posts</a></li>\n" . ($user_row["ShowFriends"] == 1 ? "<li><a href=\"/" . $username . "/friends\" title=\"Friends\">Friends</a></li>\n" : "") . ($user_row["ShowFriendOf"] == 1 ? "<li class=\"selected\"><a href=\"/" . $username . "/followers\" title=\"Followers\">Followers</a></li>\n" : "") . "</ul>\n" . "<div class=\"clear\"></div>\n" . "</div>\n";
        $sql = "SELECT Users.*, COUNT(DISTINCT Posts.Id) AS PostCount, COUNT(DISTINCT Comments.Id) AS CommentCount, COUNT(DISTINCT Likes.Id) AS LikesCount,COUNT(DISTINCT Posts.Id) + COUNT(DISTINCT Comments.Id) + COUNT(DISTINCT Likes.Id) AS TotalCount\n" . " FROM Users" . " INNER JOIN Friends ON Users.Id=Friends.UserId" . " LEFT OUTER JOIN Posts ON Posts.UserId=Users.Id AND Posts.Status=1 AND Posts.Privacy=0" . " LEFT OUTER JOIN Comments ON Posts.Id=Comments.PostId AND Comments.UserId<>Users.Id" . " LEFT OUTER JOIN Likes ON Posts.Id=Likes.PostId AND Likes.UserId<>Users.Id" . " WHERE Friends.FriendId=" . $mysqli->real_escape_string($user_id) . " GROUP BY Users.Id" . " ORDER BY TotalCount DESC" . " LIMIT " . $mysqli->real_escape_string($start) . ",20";
        $sql_count = "SELECT COUNT(DISTINCT Users.Id) AS NumUsers" . " FROM Users" . " INNER JOIN Friends ON Users.Id=Friends.UserId" . " WHERE Friends.FriendId=" . $user_id;
        // fetch count for pagination
        $count_result = $mysqli->query($sql_count);
        $count_row = $count_result->fetch_assoc();
        $count = $count_row["NumUsers"];
        $user_result = $mysqli->query($sql);
        if ($user_result->num_rows > 0) {
            $html .= "<div class=\"directory_users\">\n";
            while ($user_row = @$user_result->fetch_assoc()) {
                $html .= render_user($user_row);
            }
            $html .= "</div>\n";
        } else {
            $html .= "<div id=\"header\"><h3>Nobody has added you as a friend yet.</h3><p>Go explore the public posts, and get to know a few people :)</p></div>\n";
        }
        $html .= render_pagination($username . "/followers", $page, $count, 20);
        $html .= "</div> <!-- .page -->\n" . "</div> <!-- .page_wrapper -->\n";
        $html .= render_footer();
        return $html;
    }
}