Neuron-PHP

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
example

gravatar_url('[email protected]', 128, 'identicon')

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
example

gravatar('[email protected]', 32, 'mp', 'rounded-circle')

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
example

route_path('blog_post', ['slug' => 'my-post']) // Returns: /blog/post/my-post route_path('admin_dashboard') // Returns: /admin/dashboard

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
example

route_url('blog_post', ['slug' => 'my-post']) // Returns: https://example.com/blog/post/my-post route_url('admin_dashboard') // Returns: https://example.com/admin/dashboard

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
example

format_user_datetime($post->getCreatedAt()) // Returns: 2024-11-10 15:30 format_user_datetime($post->getCreatedAt(), 'F j, Y g:i A') // Returns: November 10, 2024 3:30 PM

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
example

format_user_date($post->getCreatedAt()) // Returns: 2024-11-10 format_user_date($post->getCreatedAt(), 'F j, Y') // Returns: November 10, 2024

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
example

$timezones = get_timezones(); // Returns: ['America' => ['America/New_York', 'America/Chicago', ...], ...]

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
example

$grouped = group_timezones_for_select($timezones, 'America/New_York'); // Returns: // [ // 'America' => [ // ['value' => 'America/New_York', 'label' => 'America/New_York', 'selected' => true], // ['value' => 'America/Chicago', 'label' => 'America/Chicago', 'selected' => false], // ], // 'Other' => [...] // ]

Return values
array<string, array<string|int, array{value: string, label: string, selected: bool}>>

Grouped timezones


        
On this page

Search results