<commit_before><?php session_start() ?>
<html>
	<!-- Use constant head file in required/  -->
	<?php include_once("required/head.php") ?>
	<body>
	<!-- import common.php -->
	<!-- Use constant nav in required/ -->
	<?php
		require("required/common.php");
		include_once("required/nav.php");
		require("required/security.php");
	?>

	<center>
		<h1 class="title">
			<?php
				// get array values from login
		    	$arr = array_values($_SESSION['user']);
				$clientid = $arr[0];
				$clientname = $arr[1]; // assign username to variable clientname
				$email = $arr[2]; // assing email to variable email
				echo "Hello " . $clientname;
			?>
		</h1>
		<br>
	</center>
	<div class="columns">
		<div class="column is-half is-offset-one-quarter">

			<form action="<?=$_SERVER['PHP_SELF']?>" method="post">


		    	<div class="control">
		    		<!-- <input class="input" type="text" placeholder="&#x21AA;" name="animal"> -->
		    		<label class="label">Post Text</label>
		    		<p class="control">
    					<textarea class="textarea" type="text" placeholder="&#x21AA; (maximum 255 characters)" name="text"></textarea>
  					</p>
		    	</div>
		    	<br>
		    	<label class="label">Post Tag</label>
		    	<div class="control"><input class="input" type="text" placeholder="&#x21AA; (not required)" name="tags"></div>
					<br>
		    	<input class="button is-primary" type="submit" name="submit">
		    </form>
		</div>
	</div>
	<?php

		// open connection
		$connection = mysqli_connect($host, $username, $password) or die ("Unable to connect!");

		// select database
		mysqli_select_db($connection, $dbname) or die ("Unable to select database!");


		$searchTags = $_POST["tag-lookup"];
		$searchUser = $_POST["user-lookup"];

		// if the person looks up a tag
		if ($searchTags != '') {
			// redirect them to tag.php with the tag name as the query string
			$location = "http://" . $_SERVER['HTTP_HOST'] . "tag.php?".$searchTags;
			echo '<META HTTP-EQUIV="refresh" CONTENT="0;URL='.$location.'">';
		}
		// if the person looks up a user
		elseif ($searchUser != '') {
			// redirect them to user.php with the username as the query string
			$location = "http:/" . $_SERVER['HTTP_HOST'] . "user.php?".$searchUser;
			echo '<META HTTP-EQUIV="refresh" CONTENT="0;URL='.$location.'">';
		}
		// search symbols in from most to least recent
		$query = "SELECT * FROM `symbols` ORDER BY `symbols`.`id` DESC";
		// execute query
		$result = mysqli_query($connection,$query) or die ("Error in query: $query. ".mysql_error());
		// $result = array_reverse($initial);
		// see if any rows were returned

		// if there are rows
		if (mysqli_num_rows($result) > 0) {

    		// print them one after another
    		echo '<div class="columns">"';
    		while($row = mysqli_fetch_row($result)) {
    			$tag = $row[1]; // get tag from 2nd array index
    			$id = $row[0]; // get id from 1st array index
    			$text = $row[2]; // get post text from 3rd array index
    			$usr = $row[3]; // get username from 4th array index
					$fixed_hour = date("h",$row[4]) + 6;
					$date = date("Y-m-d",$row[4]);
					$min = date("i:s",$row[4]);
    			$tagText = "";
					//$sql = mysqli_query($connection,$query) or die ("Error in query: $query. ".mysqli_error());

    			// if there is a tag, create a button for it.
    			if ($tag != "") {
    				$tagText = '<a href="tag.php?'.$tag.'"><span class="tag is-primary is-small">'.$tag.'</span></a><br>';
    			}
				?><div class="column is-half is-offset-one-quarter"><div class="box"><article class="media">
  						<figure class="media-left">
    						<p class="image is-64x64">
						      <img src="img/user.png">
						    </p>
						</figure>
						<div class="media-content">
						 	<div class="content">
						      	<p>
						        <strong><a href="user.php?<?=$usr?>"><?=$usr?></a></strong> <small>ID: <?=$id?></small> <small><?=$date?> <?=$fixed_hour?>:<?=$min?></small>
						        <br>
						       <?=$tagText?><?=$text?>
						      	</p>
						    </div>
								<?php
									if($_POST['like']) {
										//$likeid = $_GET['value'];
										//echo $likeid;

										$like_query = "SELECT postid, userid FROM likes where postid = $id and userid = $clientid";
										$like_result = mysqli_query($connection,$like_query) or die ("Error in query: $like_query. ".mysqli_error());
										$like_count = "SELECT count(userid) FROM likes where postid = $id";
										$like_count_result = mysqli_query($connection,$like_count) or die ("Error in query: $like_count. ".mysqli_error());
										$likes_number = mysqli_fetch_row($like_count_result);
										if (mysqli_num_rows($like_result) > 0) {
											echo "you liked it before";
											$like_query = "DELETE FROM likes WHERE postid = $id and userid = $clientid";
											$like_result = mysqli_query($connection,$like_query) or die ("Error in query: $like_query. ".mysql_error());
										}else{
											echo "you just liked it";
											$like_query = "INSERT INTO likes(userid, postid) VALUES ($clientid,$id)";
											$like_result = mysqli_query($connection,$like_query) or die ("Error in query: $like_query. ".mysql_error());
										}
									}
								?>
						    <nav class="level is-mobile">
						    	<div class="level-left">
						        	<a class="level-item">
												<form action="index.php" method="POST">
													<button type="submit" class="fabutton" value="<?=$id?>" name="like">
													   <i class="fa fa-thumbs-up" aria-hidden="true"></i>
													</button>
													<!-- <input type = "submit" class="button is-primary is-small" value="<?=$id?>" name="like"/> -->
												</form>
						        	</a>
											<a class="level-item">
												<?=$likes_number[0]?>
											</a>

						      	</div>
						    </nav>
						</div>
					</article></div></div></div>
			<?php
    		}
		    echo "</div></div>";
		// if there are no posts
		}
		else {<commit_msg>like alternating icons working<commit_after><?php session_start() ?>
<html>
	<!-- Use constant head file in required/  -->
	<?php include_once("required/head.php") ?>
	<body>
	<!-- import common.php -->
	<!-- Use constant nav in required/ -->
	<?php
		require("required/common.php");
		include_once("required/nav.php");
		require("required/security.php");
	?>

	<center>
		<h1 class="title">
			<?php
				// get array values from login
		    	$arr = array_values($_SESSION['user']);
				$clientid = $arr[0];
				$clientname = $arr[1]; // assign username to variable clientname
				$email = $arr[2]; // assing email to variable email
				echo "Hello " . $clientname;
			?>
		</h1>
		<br>
	</center>
	<div class="columns">
		<div class="column is-half is-offset-one-quarter">

			<form action="<?=$_SERVER['PHP_SELF']?>" method="post">


		    	<div class="control">
		    		<!-- <input class="input" type="text" placeholder="&#x21AA;" name="animal"> -->
		    		<label class="label">Post Text</label>
		    		<p class="control">
    					<textarea class="textarea" type="text" placeholder="&#x21AA; (maximum 255 characters)" name="text"></textarea>
  					</p>
		    	</div>
		    	<br>
		    	<label class="label">Post Tag</label>
		    	<div class="control"><input class="input" type="text" placeholder="&#x21AA; (not required)" name="tags"></div>
					<br>
		    	<input class="button is-primary" type="submit" name="submit">
		    </form>
		</div>
	</div>
	<?php

		// open connection
		$connection = mysqli_connect($host, $username, $password) or die ("Unable to connect!");

		// select database
		mysqli_select_db($connection, $dbname) or die ("Unable to select database!");


		$searchTags = $_POST["tag-lookup"];
		$searchUser = $_POST["user-lookup"];

		// if the person looks up a tag
		if ($searchTags != '') {
			// redirect them to tag.php with the tag name as the query string
			$location = "http://" . $_SERVER['HTTP_HOST'] . "tag.php?".$searchTags;
			echo '<META HTTP-EQUIV="refresh" CONTENT="0;URL='.$location.'">';
		}
		// if the person looks up a user
		elseif ($searchUser != '') {
			// redirect them to user.php with the username as the query string
			$location = "http:/" . $_SERVER['HTTP_HOST'] . "user.php?".$searchUser;
			echo '<META HTTP-EQUIV="refresh" CONTENT="0;URL='.$location.'">';
		}
		// search symbols in from most to least recent
		$query = "SELECT * FROM `symbols` ORDER BY `symbols`.`id` DESC";
		// execute query
		$result = mysqli_query($connection,$query) or die ("Error in query: $query. ".mysql_error());
		// $result = array_reverse($initial);
		// see if any rows were returned

		// if there are rows
		if (mysqli_num_rows($result) > 0) {

    		// print them one after another
    		echo '<div class="columns">"';
    		while($row = mysqli_fetch_row($result)) {
    			$tag = $row[1]; // get tag from 2nd array index
    			$id = $row[0]; // get id from 1st array index
    			$text = $row[2]; // get post text from 3rd array index
    			$usr = $row[3]; // get username from 4th array index
					$fixed_hour = date("h",$row[4]) + 6;
					$date = date("Y-m-d",$row[4]);
					$min = date("i:s",$row[4]);
    			$tagText = "";
					//$sql = mysqli_query($connection,$query) or die ("Error in query: $query. ".mysqli_error());

    			// if there is a tag, create a button for it.
    			if ($tag != "") {
    				$tagText = '<a href="tag.php?'.$tag.'"><span class="tag is-primary is-small">'.$tag.'</span></a><br>';
    			}
				?><div class="column is-half is-offset-one-quarter"><div class="box"><article class="media">
  						<figure class="media-left">
    						<p class="image is-64x64">
						      <img src="img/user.png">
						    </p>
						</figure>
						<div class="media-content">
						 	<div class="content">
						      	<p>
						        <strong><a href="user.php?<?=$usr?>"><?=$usr?></a></strong> <small>ID: <?=$id?></small> <small><?=$date?> <?=$fixed_hour?>:<?=$min?></small>
						        <br>
						       <?=$tagText?><?=$text?>
						      	</p>
						    </div>

						    <nav class="level is-mobile">
						    	<div class="level-left">
						        	<a class="level-item">
												<form action="index.php" method="POST">
													<button type="submit" class="fabutton" value="<?=$id?>" name="like">
														<?php
															if($_POST['like']) {
																//$likeid = $_GET['value'];
																//echo $likeid;

																$like_query = "SELECT postid, userid FROM likes where postid = $id and userid = $clientid";
																$like_result = mysqli_query($connection,$like_query) or die ("Error in query: $like_query. ".mysqli_error());
																$like_count = "SELECT count(userid) FROM likes where postid = $id";
																$like_count_result = mysqli_query($connection,$like_count) or die ("Error in query: $like_count. ".mysqli_error());
																$likes_number = mysqli_fetch_row($like_count_result);
																if (mysqli_num_rows($like_result) > 0) {
																	$like_query = "DELETE FROM likes WHERE postid = $id and userid = $clientid";
																	$like_result = mysqli_query($connection,$like_query) or die ("Error in query: $like_query. ".mysql_error());
																	echo '<i class="fa fa-thumbs-up" aria-hidden="true"></i>';
																}else{
																	$like_query = "INSERT INTO likes(userid, postid) VALUES ($clientid,$id)";
																	$like_result = mysqli_query($connection,$like_query) or die ("Error in query: $like_query. ".mysql_error());
																	echo '<i class="fa fa-thumbs-o-up" aria-hidden="true"></i>';
																}
															}
														?>
													</button>
													<!-- <input type = "submit" class="button is-primary is-small" value="<?=$id?>" name="like"/> -->
												</form>
						        	</a>
											<a class="level-item">
												<p><?=$likes_number[0]?></p>
											</a>

						      	</div>
						    </nav>
						</div>
					</article></div></div></div>
			<?php
    		}
		    echo "</div></div>";
		// if there are no posts
		}
		else {
{'fraction_non_alphanumeric': 0.18815331010452963, 'fraction_numerical': 0.005807200929152149, 'mean_word_length': 2.5013069997095556, 'pattern_counts': {'":': 0, '<': 219, '<?xml version=': 0, '>': 221, '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': '1390552', 'n_tokens_mistral': 5115, 'n_tokens_neox': 3927, 'n_words': 965}