<commit_before><?php

require_once dirname(dirname(__DIR__)) . "/classes/autoload.php";
require_once dirname(dirname(__DIR__)) . "/lib/xsrf.php";
require_once("/etc/apache2/capstone-mysql/encrypted-config.php");

/**
 * controller/api for the listing class
 *
 * @author <NAME> <<EMAIL>>
 */

// verify the xsrf challenge
if(session_status() !== PHP_SESSION_ACTIVE) {
	session_start();
}

// prepare an empty reply
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;

$ipAddress = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];

try {
	// grab the mySQL connection
	$pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/open-trails.ini");

	//determine which HTTP method was used
	$method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];

	// sanitize the commentId
	$commentId = filter_input(INPUT_GET, "commentId", FILTER_VALIDATE_INT);
	if(($method === "DELETE" || $method === "PUT") && (empty($commentId) === true || $commentId < 0)) {
		throw(new InvalidArgumentException("comment ID cannot be empty or negative", 405));
	}

	// sanitize and trim the other fields
	// trailId, userId, browser, createDate, ipAddress, commentPhoto, commentPhotoType, commentText			// only fields are commentPhoto, commentPhotoType, & commentText?!?!?!!?!?!?
	$commentPhoto = filter_input;
	$commentPhotoType = filter_input;																							// HOW DO YOU FILTER THESE??????????????? 4 gets!
	$commentText = filter_input(INPUT_GET, "commentText", FILTER_SANITIZE_STRING);

	// handle all RESTful calls to listing
	//get some or all Comments
	if($method === "GET") {
		// set an XSRF cookie on get requests
		setXsrfCookie("/");
		if(empty($commentId) === false) {
			$reply->data = Comment::getCommentByCommentId($pdo, $commentId);
		} elseif(empty($trailId) === false) {
			$reply->data = Comment::getCommentByUserId($pdo, $userId)->toArray();
		} elseif(empty($commentText) === false) {
			$reply->data = Comment::getCommentByCommentText($pdo, $commentText)->toArray();
		} else {
			$reply->data = Comment::getCommentByTrailId($pdo, $trailId)->toArray();
		}
	}

	// verify admin and verify object not empty
	// if the session belongs to an admin, allow post, put, and delete methods
	if(empty($_SESSION["user"]) === false && $_SESSION["user"]->getUserAccountType() !== "X") {
		if($method === "PUT" || $method === "POST") {
			verifyXsrf();
			$requestContent = file_get_contents("php://input");<commit_msg>added filters for userId & trailId<commit_after><?php

require_once dirname(dirname(__DIR__)) . "/classes/autoload.php";
require_once dirname(dirname(__DIR__)) . "/lib/xsrf.php";
require_once("/etc/apache2/capstone-mysql/encrypted-config.php");

/**
 * controller/api for the listing class
 *
 * @author <NAME> <<EMAIL>>
 */

// verify the xsrf challenge
if(session_status() !== PHP_SESSION_ACTIVE) {
	session_start();
}

// prepare an empty reply
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;

$ipAddress = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];

try {
	// grab the mySQL connection
	$pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/open-trails.ini");

	//determine which HTTP method was used
	$method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];

	// sanitize the commentId
	$commentId = filter_input(INPUT_GET, "commentId", FILTER_VALIDATE_INT);
	if(($method === "DELETE" || $method === "PUT") && (empty($commentId) === true || $commentId < 0)) {
		throw(new InvalidArgumentException("comment ID cannot be empty or negative", 405));
	}

	// sanitize and trim the other fields
	// trailId, userId, browser, createDate, ipAddress, commentPhoto, commentPhotoType, commentText			// only fields are commentPhoto, commentPhotoType, & commentText?!?!?!!?!?!?
	$commentText = filter_input(INPUT_GET, "commentText", FILTER_SANITIZE_STRING);
	$userId = filter_input(INPUT_GET, "userId", FILTER_VALIDATE_INT);
	$trailId = filter_input(INPUT_GET, "trailId", FILTER_VALIDATE_INT);

	// handle all RESTful calls to listing
	//get some or all Comments
	if($method === "GET") {
		// set an XSRF cookie on get requests
		setXsrfCookie("/");
		if(empty($commentId) === false) {
			$reply->data = Comment::getCommentByCommentId($pdo, $commentId);
		} elseif(empty($trailId) === false) {
			$reply->data = Comment::getCommentByUserId($pdo, $userId)->toArray();
		} elseif(empty($commentText) === false) {
			$reply->data = Comment::getCommentByCommentText($pdo, $commentText)->toArray();
		} else {
			$reply->data = Comment::getCommentByTrailId($pdo, $trailId)->toArray();
		}
	}

	// verify admin and verify object not empty
	// if the session belongs to an admin, allow post, put, and delete methods
	if(empty($_SESSION["user"]) === false && $_SESSION["user"]->getUserAccountType() !== "X") {
		if($method === "PUT" || $method === "POST") {
			verifyXsrf();
			$requestContent = file_get_contents("php://input");
{'fraction_non_alphanumeric': 0.17226306377905823, 'fraction_numerical': 0.003775084442678323, 'mean_word_length': 5.154034229828851, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, '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': '806169', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1627, 'n_words': 374}