itemId = (int)$itemId; $this->ip = $_SERVER['REMOTE_ADDR']; $this->ratingFile = realpath(__DIR__.'/..').'/ratings/rating_'.$this->itemId.'.json'; if (!is_dir(dirname($this->ratingFile))) { if (!mkdir(dirname($this->ratingFile), 0755, true)) { error_log("Failed to create ratings directory"); } } } public function canRate() { $ratings = $this->getRatings(); $recent = array_filter($ratings, function($r) { return $r['ip'] === $this->ip && strtotime($r['date']) > strtotime('-1 hour'); }); return count($recent) < 3; // Max 3 ratings per hour per IP } public function addRating($ratingValue, $csrfToken) { if (!$this->validateCsrfToken($csrfToken)) { throw new Exception("Invalid CSRF token"); } if (!$this->canRate()) { throw new Exception("Rating limit exceeded"); } $ratings = $this->getRatings(); $ratings[] = [ 'value' => min(5, max(1, (int)$ratingValue)), 'date' => date('Y-m-d H:i:s'), 'ip' => $this->ip ]; $json = json_encode($ratings); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception("JSON encoding error: ".json_last_error_msg()); } if (file_put_contents($this->ratingFile, $json) === false) { throw new Exception("Failed to save rating"); } } private function validateCsrfToken($token) { if (empty($_SESSION['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $token)) { return false; } return true; } public function generateCsrfToken() { if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } return $_SESSION['csrf_token']; } public function getRatings() { if (!file_exists($this->ratingFile)) { return []; } $data = file_get_contents($this->ratingFile); if ($data === false) { return []; } $ratings = json_decode($data, true); if (json_last_error() !== JSON_ERROR_NONE) { error_log("JSON error: ".json_last_error_msg()); return []; } return is_array($ratings) ? $ratings : []; } public function getAverage() { $ratings = $this->getRatings(); return count($ratings) ? round(array_sum(array_column($ratings, 'value')) / count($ratings), 1) : 0; } public function getCount() { return count($this->getRatings()); } } // Start session for CSRF if (session_status() === PHP_SESSION_NONE) { session_start(); } // Initialize with sanitized input $itemId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT, ['options' => ['default' => 0]]); $ratingSystem = new ProductRating($itemId); // Handle submission $error = null; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rating_submit'])) { try { $ratingValue = filter_input(INPUT_POST, 'rating_value', FILTER_VALIDATE_INT, [ 'options' => ['min_range' => 1, 'max_range' => 5] ]); if ($ratingValue) { $ratingSystem->addRating($ratingValue, $_POST['csrf_token'] ?? ''); } } catch (Exception $e) { $error = $e->getMessage(); } } ?>
{{serverconnect1.data.query1[0].Description1}}
[contact for info.]
: {{serverconnect1.data.query1[0].ID_NUM}}:
Note: Photos may vary and each handmade artwork may vary.
|
|
|
|
You've reached the maximum number of ratings allowed per hour.
From mountaintop to tabletop! Wildlife Sculpture editions hand made and custom painted American artist studio statues and paintings professionally made in USA since 1976. This quality American craftsmanship is available as custom made artworks at very reasonable costs that maintain heirloom value. Experience and attention to quality of materials and detail is evident in all these pleasing artworks.
{{serverconnect1.data.query1[0].Gallery}}{{serverconnect1.data.query1[0].ArtistInfo}}
[contact for info.]