<?php
	header("Cache-Control: no-cache, must-revalidate");
	require('config.include.php');
	$_POST['q']=rawurldecode($_POST['q']);
	if(is_numeric($_POST['uid']) && strlen($_POST['key'])==32 && ($_POST['type']=='post'||$_POST['type']=='page')) {
		$is_post=$_POST['type']=='post';
		$_POST['uid']=(int) $_POST['uid'];
		if($_p->log_in_hash($_POST['uid'],$_POST['key'])) {
			if(isset($_POST['recent']) && is_numeric($_POST['recent']))
				$data=$_p->recent_attachments('../'.UPLOAD_PATH);
			else {
				$searchstring=$_POST['q'];
				$userID=$_POST['uid'];
				$userKey=$_POST['key'];
				$data=$_p->search_attachments($_POST['q'],'../'.UPLOAD_PATH);
			}
			echo('Search results for "'.htmlentities($_POST['q'],ENT_QUOTES,'UTF-8').'":<br />'.$_p->render_attachment_search($is_post,$data));
		}
		else
			echo('Authentication failed using ('.$_POST['uid'].', '.$_POST['key'].')');
	}
	else {
		echo('Error in request (Invalid user identification number or corrupted key)');
	}
?>