Smilia: children's dental clinic website (WordPress theme and plugin)
This commit is contained in:
commit
4f4b5f2c0a
266 files changed
+16459
No files matched your search
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Smilia\Core;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Prices {
|
||||
|
||||
public static function groups( array $groups ): array {
|
||||
$urls = Content::service_urls();
|
||||
$result = array();
|
||||
foreach ( $groups as $group ) {
|
||||
$title = self::plain( (string) ( $group['title'] ?? '' ) );
|
||||
$items = array();
|
||||
foreach ( (array) ( $group['items'] ?? array() ) as $item ) {
|
||||
$name = self::plain( (string) ( $item['name'] ?? '' ) );
|
||||
if ( '' === $name ) {
|
||||
continue;
|
||||
}
|
||||
$raw = self::plain( (string) ( $item['price'] ?? '' ) );
|
||||
$items[] = array(
|
||||
'name' => $name,
|
||||
'price' => self::format( $raw ),
|
||||
'amount' => ctype_digit( preg_replace( '/\s/', '', $raw ) ) && '' !== $raw ? (int) preg_replace( '/\s/', '', $raw ) : null,
|
||||
);
|
||||
}
|
||||
if ( '' === $title || ! $items ) {
|
||||
continue;
|
||||
}
|
||||
$service = sanitize_title( (string) ( $group['service'] ?? '' ) );
|
||||
$result[] = array(
|
||||
'title' => $title,
|
||||
'service' => $service,
|
||||
'url' => $urls[ $service ] ?? '',
|
||||
'items' => $items,
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function plain( string $value ): string {
|
||||
return trim( html_entity_decode( wp_strip_all_tags( $value ), ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
|
||||
}
|
||||
|
||||
public static function format( string $price ): string {
|
||||
$price = self::plain( $price );
|
||||
$digits = preg_replace( '/[^\d]/', '', $price );
|
||||
if ( '' === $price || $digits !== preg_replace( '/\s/', '', $price ) ) {
|
||||
return $price;
|
||||
}
|
||||
return sprintf( __( 'от %s zł', 'smilia-core' ), number_format_i18n( (int) $digits ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user