. // Functions for reading and writing JSON files class ParseJSON extends CommentFiles { public function __construct (Setup $setup, Thread $thread) { // Construct parent class parent::__construct ($setup, $thread); // Throw exception if the JSON extension isn't loaded $setup->extensionsLoaded (array ('json')); } // Returns an array of comment files public function query () { return $this->loadFiles ('json'); } // Reads a comment file public function read ($file, $thread = 'auto') { // Get comment file path $file = $this->getCommentPath ($file, 'json', $thread); // Read and parse JSON comment file $json = $this->readJSON ($file); return $json; } // Saves a comment file public function save ($file, array $contents, $editing = false, $thread = 'auto') { // Get comment file path $file = $this->getCommentPath ($file, 'json', $thread); // Return false on attempts to override an existing file if (file_exists ($file) and $editing === false) { return false; } // Attempt to write file $saved = $this->saveJSON ($file, $contents); // Change file permission if file saved successfully if ($saved !== false) { @chmod ($file, 0600); } // Return status of file write return $saved; } // Deletes a comment file public function delete ($file, $hard_unlink = false) { // Actually delete the comment file if ($hard_unlink === true) { return unlink ($this->getCommentPath ($file, 'json')); } // Read comment file $json = $this->read ($file); // Check for JSON parse error if ($json !== false) { // Change status to deleted $json['status'] = 'deleted'; // Attempt to save file if ($this->save ($file, $json, true)) { return true; } } return false; } }