connect('post')->connect('taxonomy')->connect('user'); $cached = $cache->get($ID); if ($cached) { return $cached; } if (!$meta) { if (term_exists((int)$ID)) { $type = 'term'; } elseif (get_post_status((int)$ID)) { $type = 'post'; } else { $type = 'user'; } $meta = new JVBase\meta\MetaManager($ID, $type); } $out = ''; $avg = $meta->getValue('average_rating'); $total = $meta->getValue('total_ratings'); if ($avg !== 'none') { $out .= jvbFormatStarRating($avg, (int)$total); } $cache->set($ID, $out); return $out; } function jvbFormatStarRating(string $rating, int $total = 0):string { $out = '

'; $temp = str_contains($rating, '.5'); if ($temp) { $rating = (int)$rating; } $remaining = ($temp) ? $rating + 1 - 5 : $rating - 5; for ($i = 1; $i <= $rating; $i++) { $out .= jvbIcon('star', ['style' => 'fill']); } if ($temp) { $out .= jvbIcon('star-half'); } for ($i = 1; $i <= $remaining; $i++) { $out .= jvbIcon('star'); } $out .= ''; $out .= ($total == 0) ? '' : '( '.$total.' Ratings )'; $out .= '

'; return $out; } /** * gets all the image links together and stores them * @param int $imgID * * @return array */ function jvbImageData(int $imgID):array { $image = new Image(); return $image->getImageData($imgID); } function formatJSONField(mixed $value): string|bool|null { if (empty($value)) { return null; } // If already a JSON string, validate it if (is_string($value)) { json_decode($value); if (json_last_error() === JSON_ERROR_NONE) { return $value; } } // If array or object, encode it if (is_array($value) || is_object($value)) { return json_encode($value); } // If not valid for JSON, return null return null; } function jvbCurrency(string $number) { if ($number === '') { $number = 0; } if (!is_numeric($number)) { return $number; } $number = number_format($number, 2); list($dollars, $cents) = explode('.', $number); return '$'.$dollars.'.'.$cents.''; } function jvbMailToLink(string $emailTo, string $subject = 'Contact from Website', string $message = '', bool $icon = true, ?string $linkText = null ):string { if (!is_email($emailTo)) { return ''; } $link = 'mailto:'.$emailTo.'?subject='.rawurlencode($subject); if ($message !== '') { $link .= '&body='.rawurlencode($message); } return $link; } function jvbTextLink(int $phoneNumber, string $message=''):string { $length =strlen((string)$phoneNumber); if ($length < 10 || $length > 10) { return ''; } $link = 'sms:+1'.$phoneNumber; if ($message !== '') { $link .= '?body='.rawurlencode($message); } return $link; } function jvbPhoneLink(int $phoneNumber):string { $length =strlen((string)$phoneNumber); if ($length < 10 || $length > 10) { return ''; } return 'tel:+1'.$phoneNumber; } function jvbFormatString(string $string):string { return html_entity_decode($string); }