. // Check if request is for JSONP if (isset ($_GET['jsonp'])) { // If so, setup HashOver for JavaScript require ('javascript-setup.php'); } else { // If not, setup HashOver for JSON require ('json-setup.php'); } // Returns comment data or authentication error function get_json_response ($hashover) { // Initial JSON data $data = array (); // Get comment from POST/GET data $key = $hashover->setup->getRequest ('comment', null); // Return error if we're missing necessary post data if ($key === null) { return array ('error' => 'Missing comment file.'); } // Sanitize file path $file = str_replace ('../', '', $key); // Store references to some long variables $thread = $hashover->setup->threadName; // Read comment $comment = $hashover->thread->data->read ($file, $thread); // Return error message if failed to read comment if ($comment === false) { return array ('error' => 'Failed to read file: "' . $file . '"'); } // User is not authorized by default $authorized = false; // Check if user is logged in if ($hashover->login->userIsLoggedIn === true) { // If so, user is authorized if they own the comment if (!empty ($comment['login_id'])) { if ($hashover->login->loginHash === $comment['login_id']) { $authorized = true; } } // Or, user is authorized if they are Admin if ($hashover->login->isAdmin () === true) { $authorized = true; } } // Check if user is authorized to receive comment data if ($authorized === true) { // If so, instantiate Crypto class $crypto = new Crypto (); // Specific comment data to return $data = array ( // Commenter name 'name' => Misc::getArrayItem ($comment, 'name') ?: '', // Commenter website URL 'website' => Misc::getArrayItem ($comment, 'website') ?: '', // Commenter's comment 'body' => Misc::getArrayItem ($comment, 'body') ?: '' ); // Add decrypted email address to data if an email exists if (!empty ($comment['email']) and !empty ($comment['encryption'])) { $data ['email'] = $crypto->decrypt ($comment['email'], $comment['encryption']); } // And return comment data return $data; } // Otherwise, wait 5 seconds sleep (5); // And return authentication error return array ( 'error' => $hashover->locale->text['post-fail'] ); } try { // Instanciate HashOver class $hashover = new \HashOver ('json'); // Throw exception if requested by remote server $hashover->setup->refererCheck (); // Set page URL from POST/GET data $hashover->setup->setPageURL ('request'); // Initiate comment processing $hashover->initiate (); // Get JSON response $data = get_json_response ($hashover); // Return JSON or JSONP function call echo Misc::jsonData ($data); } catch (\Exception $error) { echo Misc::displayException ($error, 'json'); }