コード例 #1
0
ファイル: tag.php プロジェクト: jonbeckett/wetheusers
function render_tag_page($tag_name, $page)
{
    $start = (intval($page) - 1) * 20;
    $html = render_header($tag_name, "", true);
    $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 class=\"selected\"><a href=\"/explore/tags\" title=\"Tags\">Tags</a></li>\n" . "<li><a href=\"/explore/directory\" title=\"Directory\">Directory</a></li>\n" . "<li><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();
    $sql = "";
    $sql_count = "";
    if (isset($_SESSION["user_id"])) {
        $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,Likes.Id AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " INNER JOIN PostTags ON Posts.Id=PostTags.PostId" . " INNER JOIN Tags ON PostTags.TagId=Tags.Id" . " LEFT OUTER JOIN Likes ON Likes.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Likes.PostId=Posts.Id" . " LEFT OUTER JOIN Friends FriendsA ON Posts.UserId=FriendsA.UserId" . " WHERE" . " ((FriendsA.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Tags.Name='" . $mysqli->real_escape_string($tag_name) . "'" . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
        $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " INNER JOIN PostTags ON Posts.Id=PostTags.PostId" . " INNER JOIN Tags ON PostTags.TagId=Tags.Id" . " LEFT OUTER JOIN Friends FriendsA ON Posts.UserId=FriendsA.UserId" . " WHERE" . " ((FriendsA.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Tags.Name='" . $mysqli->real_escape_string($tag_name) . "'";
    } else {
        $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " INNER JOIN PostTags ON Posts.Id=PostTags.PostId" . " INNER JOIN Tags ON PostTags.TagId=Tags.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Tags.Name='" . $mysqli->real_escape_string($tag_name) . "'" . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
        $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " INNER JOIN PostTags ON Posts.Id=PostTags.PostId" . " INNER JOIN Tags ON PostTags.TagId=Tags.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Tags.Name='" . $mysqli->real_escape_string($tag_name) . "'";
    }
    // fetch count for pagination
    $count_result = $mysqli->query($sql_count);
    $count_row = $count_result->fetch_assoc();
    $count = $count_row["NumPosts"];
    $post_result = $mysqli->query($sql);
    $html .= "<div id=\"header\"><h1>Posts tagged &#8216;<span>" . $tag_name . "</span>&#8217;</h1></div>\n";
    $html .= render_posts($mysqli, $post_result);
    $html .= render_pagination("explore/tag/" . $tag_name, $page, $count, 20);
    $html .= render_display_controls();
    $html .= render_footer();
    return $html;
}
コード例 #2
0
ファイル: firehose.php プロジェクト: jonbeckett/wetheusers
function render_firehose_page($numposts = 20, $page = 1)
{
    $start = (intval($page) - 1) * $numposts;
    $html = render_header("The Firehose");
    $html .= "<div class=\"bg_menu_wrapper\">\n" . "<ul class=\"bg_menu\">\n" . "<li class=\"selected\"><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><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();
    $sql = "";
    $count_sql = "";
    if (isset($_SESSION["user_id"])) {
        $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,Likes.Id AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Likes ON Likes.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Likes.PostId=Posts.Id" . " LEFT OUTER JOIN Friends FriendsOfAuthor ON Posts.UserId=FriendsOfAuthor.UserId AND FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " WHERE" . " ((FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . "," . $mysqli->real_escape_string($numposts);
        $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Friends FriendsOfAuthor ON Posts.UserId=FriendsOfAuthor.UserId AND FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " WHERE" . " ((FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED;
    } else {
        $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar, null AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . "," . $mysqli->real_escape_string($numposts);
        $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED;
    }
    // fetch count for pagination
    $count_result = $mysqli->query($sql_count);
    $count_row = $count_result->fetch_assoc();
    $count = $count_row["NumPosts"];
    $post_result = $mysqli->query($sql);
    $html .= "<div id=\"header\">\n" . "<h1>The Firehose</h1>\n" . "<p>Everything posted by everybody, across the entire site (well... everything they are choosing to let you see...)</p>\n" . "</div>";
    $html .= render_posts($mysqli, $post_result);
    /*
    $html .= "<div class=\"tiles\">\n";
    while ($post_row =@ $post_result->fetch_assoc()){
    	$html .= render_tile($mysqli,$post_row,false);
    }
    $html .= "</div> <!-- .tiles -->\n";
    */
    // Pagination
    $html .= render_pagination("explore/firehose/" . $numposts, $page, $count, $numposts);
    $html .= render_display_controls();
    $html .= render_footer();
    return $html;
}
コード例 #3
0
ファイル: popular.php プロジェクト: jonbeckett/wetheusers
function render_popular_page($page)
{
    $start = (intval($page) - 1) * 20;
    $html = render_header("Popular Posts");
    $html .= "<div class=\"bg_menu_wrapper\">\n" . "<ul class=\"bg_menu\">\n" . "<li><a href=\"/explore/firehose\" title=\"Firehose\">Firehose</a></li>\n" . "<li class=\"selected\"><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><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();
    if (isset($_SESSION["user_id"])) {
        $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,Likes.Id AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Likes ON Likes.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Likes.PostId=Posts.Id" . " LEFT OUTER JOIN Friends FriendsA ON Posts.UserId=FriendsA.UserId" . " WHERE" . " ((FriendsA.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '1' DAY))" . " ORDER BY (Posts.Likes + Posts.Comments) DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
        $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Friends FriendsA ON Posts.UserId=FriendsA.UserId" . " WHERE" . " ((FriendsA.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '1' DAY))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED;
    } else {
        $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar, null AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '1' DAY))" . " ORDER BY (Posts.Likes + Posts.Comments) DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
        $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '1' DAY))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED;
    }
    // fetch count for pagination
    $count_result = $mysqli->query($sql_count);
    $count_row = $count_result->fetch_assoc();
    $count = $count_row["NumPosts"];
    $post_result = $mysqli->query($sql);
    $html .= "<div id=\"header\">\n" . "<h1>Popular Posts</h1>\n" . "<p>The most popular content available to you of the last 24 hours, judged by comments and likes...</p>\n" . "</div>";
    $html .= render_posts($mysqli, $post_result);
    $html .= render_pagination("explore/popular", $page, $count, 20);
    $html .= render_display_controls();
    $html .= render_footer();
    return $html;
}
コード例 #4
0
ファイル: search.php プロジェクト: jonbeckett/wetheusers
function render_search_page($search_terms = "", $page = 1)
{
    $start = (intval($page) - 1) * 20;
    $html = render_header("Search");
    $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><a href=\"/explore/suggested\" title=\"Suggested Users\">Suggested</a></li>\n" . "<li class=\"selected\"><a href=\"/explore/search\" title=\"Search\">Search</a></li>\n" . "</ul>\n" . "<div class=\"clear\"></div>\n" . "</div>\n";
    $html .= "<div id=\"header\">\n" . "<h1>Search</h1>\n" . "<p>Search the title and body of posts.</p>\n" . "<table id=\"search_form\" cellspacing=\"0\" cellpadding=\"5\"><tr>\n" . "<td><input type=\"text\" name=\"s\" id=\"search_text\" value=\"" . addslashes(urldecode($search_terms)) . "\" size=\"20\" onKeyPress=\"return checkSubmit(event)\"/></td>\n" . "<td><button id='search_submit_button' onClick=\"document.location.href = '/explore/search/' + \$('#search_text').val();\">Go</button></td>\n" . "</tr></table>";
    $html .= "<script>\n" . "\$(\"#search_text\").focus();\n" . "</script>\n";
    if ($search_terms != "") {
        $mysqli = db_connect();
        $sql = "";
        $count_sql = "";
        if (isset($_SESSION["user_id"])) {
            $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,Likes.Id AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Likes ON Likes.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Likes.PostId=Posts.Id" . " LEFT OUTER JOIN Friends FriendsA ON Posts.UserId=FriendsA.UserId" . " WHERE" . " ((FriendsA.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND MATCH(Posts.Title, Posts.Body) AGAINST ('" . $mysqli->real_escape_string($search_terms) . "')" . " ORDER BY MATCH(Posts.Title, Posts.Body) AGAINST ('" . $mysqli->real_escape_string($search_terms) . "') DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
            $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Friends FriendsA ON Posts.UserId=FriendsA.UserId" . " WHERE" . " ((FriendsA.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND MATCH(Posts.Title, Posts.Body) AGAINST ('" . $mysqli->real_escape_string($search_terms) . "')";
        } else {
            $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar, null AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND MATCH(Posts.Title, Posts.Body) AGAINST ('" . $mysqli->real_escape_string($search_terms) . "')" . " ORDER BY MATCH(Posts.Title, Posts.Body) AGAINST ('" . $mysqli->real_escape_string($search_terms) . "') DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
            $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND MATCH(Posts.Title, Posts.Body) AGAINST ('" . $mysqli->real_escape_string($search_terms) . "')";
        }
        // fetch count for pagination
        $count_result = $mysqli->query($sql_count);
        $count_row = $count_result->fetch_assoc();
        $count = $count_row["NumPosts"];
        $post_result = $mysqli->query($sql);
        $html .= "<p>" . $count . " posts found with '" . $search_terms . "' in the title, or body...</p>\n" . "</div> <!-- #header -->\n";
        $html .= render_posts($mysqli, $post_result);
        // Pagination
        $html .= render_pagination("explore/search/" . $search_terms, $page, $count, 20);
        $html .= render_display_controls();
    } else {
        $html .= "</div> <!-- #header -->\n";
    }
    $html .= render_footer();
    return $html;
}
コード例 #5
0
ファイル: home.php プロジェクト: jonbeckett/wetheusers
function render_home_page($numposts = 20, $page = 1)
{
    $start = (intval($page) - 1) * $numposts;
    $html = render_header("Home");
    $mysqli = db_connect();
    if (isset($_SESSION["user_id"])) {
        // does the logged in user have any friends yet ?
        $friends_sql = "SELECT COUNT(*) AS NumFriends FROM Friends WHERE UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]);
        $friends_result = $mysqli->query($friends_sql);
        $friends_row = $friends_result->fetch_assoc();
        $friends_count = $friends_row["NumFriends"];
        if ($friends_count > 0) {
            // get the friends only posts by people who call you a friend
            // also get friends public posts
            // also get your own posts
            $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,Likes.Id AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Friends FriendsOfMe ON FriendsOfMe.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND FriendsOfMe.FriendId=Posts.UserId" . " LEFT OUTER JOIN Friends FriendsOfAuthor ON Posts.UserId=FriendsOfAuthor.UserId AND FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " LEFT OUTER JOIN Likes ON Likes.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Likes.PostId=Posts.Id" . " WHERE" . " ((FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . " AND FriendsOfMe.FriendId=Posts.UserId)" . " OR" . " (FriendsOfMe.FriendId=Posts.UserId AND Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . "," . $mysqli->real_escape_string($numposts);
            $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Friends FriendsOfMe ON FriendsOfMe.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND FriendsOfMe.FriendId=Posts.UserId" . " LEFT OUTER JOIN Friends FriendsOfAuthor ON Posts.UserId=FriendsOfAuthor.UserId AND FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " LEFT OUTER JOIN Likes ON Likes.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Likes.PostId=Posts.Id" . " WHERE" . " ((FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . " AND FriendsOfMe.FriendId=Posts.UserId)" . " OR" . " (FriendsOfMe.FriendId=Posts.UserId AND Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED;
        } else {
            // no friends - fetch popular content from the last 7 days
            $html .= "<div id=\"header\">\n" . "<h1>Welcome to " . SITE_NAME . " - No Friends Yet?</h1>\n" . "<p>Here is some popular content from the last 7 days. You might also like to check out the <a href=\"/explore/firehose\">Firehose</a>.</p>\n" . "</div>\n";
            $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,null AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Posts.Privacy=" . POST_PRIVACY_PUBLIC . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . "," . $mysqli->real_escape_string($numposts);
            $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Posts.Privacy=" . POST_PRIVACY_PUBLIC;
        }
    } else {
        // not logged in - fetch popular content from the last 7 days
        $html .= "<div id=\"header\">\n" . "<h1>Post, Friend, Follow, Like, Comment</h1>\n" . "<p>Welcome to a new social experience on the internet - <strong><a href=\"/register\">register</a></strong> now, and begin posting!</p>\n" . "</div>\n";
        $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,null AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Posts.Privacy=" . POST_PRIVACY_PUBLIC . " ORDER BY Posts.Likes DESC LIMIT " . $mysqli->real_escape_string($start) . "," . $mysqli->real_escape_string($numposts);
        $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE (Posts.Created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Posts.Privacy=" . POST_PRIVACY_PUBLIC;
        //print "<p>".$sql;
        //print "<p>".$sql_count;
    }
    // fetch count for pagination
    $count_result = $mysqli->query($sql_count);
    $count_row = $count_result->fetch_assoc();
    $count = $count_row["NumPosts"];
    $post_result = $mysqli->query($sql);
    if (isset($_GET["debug"])) {
        print "<p><br /><br /><code>" . $sql . "</code></p>";
    }
    $html .= render_posts($mysqli, $post_result);
    $html .= render_pagination("home/" . $numposts, $page, $count, $numposts);
    $html .= render_display_controls();
    $html .= render_footer();
    // $html .= "<pre>".$sql."</pre>\n";
    return $html;
}
コード例 #6
0
ファイル: posts.php プロジェクト: jonbeckett/wetheusers
function render_post_drafts_page($page)
{
    if (isset($_SESSION["user_id"])) {
        $start = (intval($page) - 1) * 20;
        $html = render_header("Draft Posts");
        $mysqli = db_connect();
        $html .= "<div class=\"bg_menu_wrapper\">\n" . "<ul class=\"bg_menu\">\n" . "<li><a href=\"/post/add\" title=\"Compose\">Compose</a></li>\n" . "<li class=\"selected\"><a href=\"/post/drafts\" title=\"Draft Posts\">Draft Posts</a></li>\n" . "</ul>\n" . "<div class=\"clear\"></div>\n" . "</div>\n";
        $sql = "";
        $count_sql = "";
        $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,Likes.Id AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Likes ON Likes.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Likes.PostId=Posts.Id" . " LEFT OUTER JOIN Friends FriendsA ON Posts.UserId=FriendsA.UserId" . " WHERE Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Status=" . POST_STATUS_DRAFT . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
        $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Friends FriendsA ON Posts.UserId=FriendsA.UserId" . " WHERE Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Status=" . POST_STATUS_DRAFT;
        // fetch count for pagination
        $count_result = $mysqli->query($sql_count);
        $count_row = $count_result->fetch_assoc();
        $count = $count_row["NumPosts"];
        $post_result = $mysqli->query($sql);
        $html .= "<div id=\"header\">\n" . "<h1>You have " . $count . " draft posts</h1>\n" . "<p>All of your draft posts.</p>\n" . "</div>";
        $html .= render_posts($mysqli, $post_result);
        // Pagination
        $html .= render_pagination("account/drafts", $page, $count, 20);
        $html .= render_display_controls();
        $html .= render_footer();
        return $html;
    } else {
        header("Location: /401");
    }
}
コード例 #7
0
ファイル: users.php プロジェクト: jonbeckett/wetheusers
function render_profile_page_posts($username, $page)
{
    $start = (intval($page) - 1) * 20;
    $mysqli = db_connect();
    $html = "";
    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();
        $html .= "<div class=\"profile_menu_wrapper\">\n" . "<ul class=\"profile_menu\">\n" . "<li class=\"selected\"><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><a href=\"/" . $username . "/followers\" title=\"Followers\">Followers</a></li>\n" : "") . "</ul>\n" . "<div class=\"clear\"></div>\n" . "</div>\n";
        $sql = "";
        $sql_count = "";
        if (isset($_SESSION["user_id"])) {
            $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar,Likes.Id AS LikeId FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Likes ON Likes.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Likes.PostId=Posts.Id" . " LEFT OUTER JOIN Friends FriendsOfAuthor ON Posts.UserId=FriendsOfAuthor.UserId" . " WHERE" . " ((FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Users.Username='******'" . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
            $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " LEFT OUTER JOIN Friends FriendsOfAuthor ON Posts.UserId=FriendsOfAuthor.UserId" . " WHERE" . " ((FriendsOfAuthor.FriendId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . " AND Posts.Privacy=" . POST_PRIVACY_FRIENDS_ONLY . " AND Posts.Status=" . POST_STATUS_PUBLISHED . ")" . " OR" . " (Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . ")" . " OR" . " (Posts.UserId=" . $mysqli->real_escape_string($_SESSION["user_id"]) . "))" . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Users.Username='******'";
        } else {
            $sql = "SELECT DISTINCT Posts.*,Users.Username,Users.Avatar FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Users.Username='******'" . " ORDER BY Created DESC LIMIT " . $mysqli->real_escape_string($start) . ",20";
            $sql_count = "SELECT COUNT(DISTINCT Posts.Id) AS NumPosts FROM Posts" . " INNER JOIN Users ON Posts.UserId=Users.Id" . " WHERE" . " Posts.Privacy=" . POST_PRIVACY_PUBLIC . " AND Posts.Status=" . POST_STATUS_PUBLISHED . " AND Users.Username='******'";
        }
        // fetch count for pagination
        $count_result = $mysqli->query($sql_count);
        $count_row = $count_result->fetch_assoc();
        $count = $count_row["NumPosts"];
        // posts
        $post_result = $mysqli->query($sql);
        $html .= render_posts($mysqli, $post_result);
        $html .= render_pagination($username, $page, $count, 20);
        $html .= render_display_controls();
        $html .= render_footer();
    }
    return $html;
}