<commit_before><?php

require_once __DIR__.'/../lib/functions.php';
require_once __DIR__.'/../views/head.php';

$uid = $_SESSION['loginUser']['uid'];

$user = executeGetQuery($db, "SELECT * FROM users WHERE id = '$uid'", true);
$posts = executeGetQuery($db, "SELECT * FROM posts WHERE uid = '$uid'");

 ?>

<div class="profile-info">
  <h3>Profile</h3>
  <div class="profile-username">
    <?php echo $user['username']; ?>
  </div>
  <div class="profile-name">
    <?php echo $user['name']; ?>
  </div>
  <div class="profile-bio">
    <?php echo $user['bio']; ?>
  </div>
</div>
<br>
  <?php

  foreach ($posts as $post):
    $date = strtotime($post['published']);
    $date = date("l jS \of F Y", $date);
    if ($post['uid'] === $uid && sizeof($post) != 0):?>
      <div class="profile-posts">
        <a href="<?php echo $post['link']; ?>">
        <div class="post-title"><?php echo $post['title']; ?></div>
        </a>
        <div class="post-content"><?php echo $post['content']; ?></div>
        <div class="post-published"><?php echo 'Published ' . $date; ?></div>
      </div>
  <?php endif;
    endforeach;

      if (sizeof($posts) == 0): ?>
        <div class="profile-empty-posts">
          <p>No posts yet! What are you waiting for?</p>
        </div>
<?php die();
        endif;
?>

<?php  require_once __DIR__.'/../views/footer.php';  ?><commit_msg>changed structure, and comment<commit_after><?php

require_once __DIR__.'/../lib/functions.php';
require_once __DIR__.'/../views/head.php';

$uid = $_SESSION['loginUser']['uid'];

//Fetch data from the logged in user
$user = executeGetQuery($db, "SELECT * FROM users WHERE id = '$uid'", true);
//Fetch all posts from the logged in user
$posts = executeGetQuery($db, "SELECT * FROM posts WHERE uid = '$uid'");

?>

<div class="profile-intro">
  <h3>Profile info</h3>
</div>
<div class="profile-info">
  <p>Username: <?php echo $user['username']; ?> </p>
  <p>Fullname: <?php echo $user['name']; ?> </p>
  <p>Bio: <?php echo $user['bio']; ?> </p>
  <p style="font-style: italic">If you want to change your settings please visit your account page to update them.</p>
</div>
<br>
<div class="profile-posts-intro">
  <h3>Your posts</h3>
</div>
<?php
foreach ($posts as $post):
  $date = strtotime($post['published']);
  $date = date("l jS \of F Y", $date);
  //Checks if the user have any posts, if there are some print all of them
  if ($post['uid'] === $uid && sizeof($post) != 0):?>
  <div class="profile-posts">
    <a href="<?php echo $post['link']; ?>">
      <div class="profile-post-title"><?php echo $post['title']; ?></div>
    </a>
    <div class="profile-post-content"><?php echo $post['content']; ?></div>
    <div class="profile-post-published"><?php echo 'Published ' . $date; ?></div>
  </div>
<?php endif;
endforeach;
//If the user have not made any posts, show message
if (sizeof($posts) == 0): ?>
<div class="profile-empty-posts">
  <p>No posts yet! What are you waiting for?</p>
</div>
<?php die();
endif;
?>

<?php  require_once __DIR__.'/../views/footer.php';  ?>
{'fraction_non_alphanumeric': 0.2263779527559055, 'fraction_numerical': 0.0032808398950131233, 'mean_word_length': 3.683563748079877, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 85, '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': '2711155', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1049, 'n_words': 292}