helpers.php
View helper functions for Neuron CMS.
Provides convenient view-related functionality including Gravatar support.
Table of Contents
Functions
- gravatar_url() : string
- Generate a Gravatar URL for the given email address
- gravatar() : string
- Generate a complete Gravatar image tag
- route_path() : string
- Generate a relative URL path for a named route
- route_url() : string
- Generate an absolute URL for a named route
- format_user_datetime() : string
- Format a DateTimeImmutable object in the authenticated user's timezone
- format_user_date() : string
- Format a DateTimeImmutable object as a date (no time) in the authenticated user's timezone
- get_timezones() : array<string, array<string|int, string>>
- Get a list of all available timezones grouped by region
- group_timezones_for_select() : array<string, array<string|int, array{value: string, label: string, selected: bool}>>
- Prepare timezones for select dropdown with selection state
Functions
gravatar_url()
Generate a Gravatar URL for the given email address
gravatar_url(string $email[, int $size = 80 ][, string $default = 'mp' ]) : string
Parameters
- $email : string
-
Email address
- $size : int = 80
-
Image size in pixels (default: 80)
- $default : string = 'mp'
-
Default image type (mp, identicon, monsterid, wavatar, retro, robohash, blank)
Tags
Return values
string —Gravatar URL
gravatar()
Generate a complete Gravatar image tag
gravatar(string $email[, int $size = 80 ][, string $default = 'mp' ][, string $class = '' ]) : string
Parameters
- $email : string
-
Email address
- $size : int = 80
-
Image size in pixels (default: 80)
- $default : string = 'mp'
-
Default image type (mp, identicon, monsterid, wavatar, retro, robohash, blank)
- $class : string = ''
-
Additional CSS classes to add to the img tag
Tags
Return values
string —Complete HTML img tag
route_path()
Generate a relative URL path for a named route
route_path(string $routeName[, array<string, mixed> $parameters = [] ]) : string
Parameters
- $routeName : string
-
The name of the route
- $parameters : array<string, mixed> = []
-
Route parameters
Tags
Return values
string —Relative URL path
route_url()
Generate an absolute URL for a named route
route_url(string $routeName[, array<string, mixed> $parameters = [] ]) : string
Parameters
- $routeName : string
-
The name of the route
- $parameters : array<string, mixed> = []
-
Route parameters
Tags
Return values
string —Absolute URL
format_user_datetime()
Format a DateTimeImmutable object in the authenticated user's timezone
format_user_datetime(DateTimeImmutable|null $dateTime[, string $format = 'Y-m-d H:i' ]) : string
Converts a DateTime from UTC to the user's preferred timezone and formats it. Falls back to system timezone if no user is authenticated or user has no timezone set.
Parameters
- $dateTime : DateTimeImmutable|null
-
DateTime to format (assumed to be in UTC)
- $format : string = 'Y-m-d H:i'
-
Date format string (default: 'Y-m-d H:i')
Tags
Return values
string —Formatted date/time string, or 'N/A' if dateTime is null
format_user_date()
Format a DateTimeImmutable object as a date (no time) in the authenticated user's timezone
format_user_date(DateTimeImmutable|null $dateTime[, string $format = 'Y-m-d' ]) : string
Convenience wrapper around format_user_datetime for date-only display.
Parameters
- $dateTime : DateTimeImmutable|null
-
DateTime to format (assumed to be in UTC)
- $format : string = 'Y-m-d'
-
Date format string (default: 'Y-m-d')
Tags
Return values
string —Formatted date string, or 'N/A' if dateTime is null
get_timezones()
Get a list of all available timezones grouped by region
get_timezones() : array<string, array<string|int, string>>
Returns an associative array with regions as keys and arrays of timezones as values. Useful for populating timezone dropdown selects.
Tags
Return values
array<string, array<string|int, string>> —Grouped timezones
group_timezones_for_select()
Prepare timezones for select dropdown with selection state
group_timezones_for_select(array<int, string> $timezones[, string|null $currentTimezone = null ]) : array<string, array<string|int, array{value: string, label: string, selected: bool}>>
Groups timezones by region and returns a structured array ready for rendering in a select dropdown. Each timezone includes value, label, and selected state.
Parameters
- $timezones : array<int, string>
-
List of timezone identifiers
- $currentTimezone : string|null = null
-
Currently selected timezone
Tags
Return values
array<string, array<string|int, array{value: string, label: string, selected: bool}>> —Grouped timezones