Ejemplo n.º 1
0
function showBlog($dbh, $user, $user2)
{
    printPageTop('Blog');
    print <<<EOT
\t\t<div class="blog-masthead">
       \t\t<div class="container">
         \t\t\t<nav class="blog-nav">
           \t\t\t\t<ul class="nav navbar-nav">
             \t\t\t\t\t<li><a class="blog-nav-item active" href="toBlog.php?user={$user}">Blog</a></li>
                  \t\t\t\t<li><a class="blog-nav-item" href ="userprofile.php?user={$user}">Profile</a></li>
             \t\t\t\t\t<li><a class="blog-nav-item" href = "toHomePage.php">Home</a></li>
             \t\t\t\t\t<li><a class="blog-nav-item" href = "logoutPage.php">Logout</a></li>
           \t\t\t\t</ul>
EOT;
    printSearchForm();
    print <<<EOT
      \t\t\t</div>
    \t\t</div>

EOT;
    $result = 0;
    // get all of the users the currently logged-in user is following, to print the
    // follow/un-follow buttons on the page
    $preparedquery = "SELECT following FROM follows where user = ?";
    $resultset = prepared_query($dbh, $preparedquery, $user2);
    // the current user may be following many users; go through them and if you find that they are following the one that
    // corresponds to this blog, break from the loop
    while ($row = $resultset->fetchRow(MDB2_FETCHMODE_ASSOC)) {
        $following = $row['following'];
        $result = $following == $user;
        if ($result == 1) {
            break;
        }
    }
    if ($result == 1) {
        // the user is currently following this blog; print an un-follow button
        print <<<EOT
\t<div class="container">
      \t\t\t\t<div class="blog-header">
      \t\t\t\t</div>

\t\t\t\t<form class="navbar-form navbar-left" method = 'post' action = "toBlog.php" role="form">
            \t\t\t\t<div class="form-group">
              \t\t\t\t<a href="" class="btn btn-default btn-med disabled" role="button"><span class="glyphicon glyphicon-ok"></span> Following</a>
            \t\t\t\t</div>
            \t\t\t\t<div class="form-group">
\t\t\t\t\t\t<input type="hidden" value={$user} name = "unfollowfollowing" id="unfollowfollowing" class="form-control">
\t\t\t\t\t\t<input type="hidden" value={$user2} name = "unfollowfollower" id="unfollowfollower" class="form-control">
            \t\t\t\t</div>
            \t\t\t\t<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Un-Follow</button>
          \t\t\t</form>
EOT;
    } else {
        // the user is not currently following this blog; print a follow button
        print <<<EOT
\t<div class="container">
\t\t\t\t<div class="blog-header">
      \t\t\t\t</div>
\t\t\t<form class="navbar-form navbar-left" method = 'post' action = "toBlog.php" role="form">
            \t\t\t<div class="form-group">
              \t\t\t<a href="" class="btn btn-default btn-med disabled" role="button"><span class="glyphicon glyphicon-minus"></span> Not Following</a>
            \t\t\t</div>
            \t\t\t<div class="form-group">
\t\t\t\t\t<input type="hidden" value={$user} name = "followfollowing" id="followfollowing" class="form-control">
\t\t\t\t\t<input type="hidden" value={$user2} name = "followfollower" id="followfollower" class="form-control">
            \t\t\t</div>
            \t\t\t<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Follow</button>
          \t\t</form>
EOT;
    }
    printBlogTop($user);
    // get all of the blog posts from this user
    $postsQuery = "SELECT * from blog_entry where user = ?  order by date(entered) desc, time(entered) desc";
    $postsResults = prepared_query($dbh, $postsQuery, $user);
    displayBlog($dbh, $postsResults, "toBlog.php", 0);
    printUserProfile($dbh, $user);
    printBlogFooter();
}
?>
  
        <?php 
include_once 'menu.php';
?>
        <div id="main">
        	<div class="container">
            	<div class="news">
                    <div class="box"> 
                        <?php 
if (isset($_GET['id'])) {
    ?>

                        <h1>User profile</h1>
                        <?php 
    printUserProfile($_GET['id']);
}
?>
                    </div>
                </div>
                <div class="sidebar">
                    <?php 
include_once 'userbox.php';
?>
  
                    <?php 
include_once 'commentsbox.php';
?>
 
                </div>
            </div>