id ) && false !== strpos( (string) $screen->id, 'bcal-settings' ) ) ) {
return 'settings';
}
if ( BCAL_PT === $screen->post_type && 'post' === $screen->base ) {
return 'event';
}
if ( BCAL_PT === $screen->post_type && 'edit' === $screen->base ) {
return 'list';
}
if ( in_array( $screen->taxonomy, array( 'bcal_venue', 'bcal_city', 'bcal_organizer', 'bcal_category' ), true ) ) {
return 'term';
}
if ( BCAL_PT === $screen->post_type || false !== strpos( (string) $hook, 'bcal' ) ) {
return 'other';
}
return '';
}
/**
* Plural forms of a translated string for the Intl.PluralRules categories
* used by JavaScript (one, few, many, other).
*
* @param array $nooped Result of _n_noop().
* @return array
*/
function bcal_js_plural( $nooped ) {
return array(
'one' => translate_nooped_plural( $nooped, 1, 'bearius-calendar' ),
'few' => translate_nooped_plural( $nooped, 2, 'bearius-calendar' ),
'many' => translate_nooped_plural( $nooped, 5, 'bearius-calendar' ),
'other' => translate_nooped_plural( $nooped, 5, 'bearius-calendar' ),
);
}
add_action(
'admin_enqueue_scripts',
function ( $hook ) {
$screen = bcal_admin_screen( $hook );
if ( '' === $screen ) {
return;
}
wp_enqueue_style( 'bcal-admin', BCAL_URL . 'assets/css/admin.css', array(), BCAL_VERSION );
wp_enqueue_script( 'bcal-admin', BCAL_URL . 'assets/js/admin.js', array(), BCAL_VERSION, true );
if ( 'settings' === $screen ) {
wp_enqueue_media();
}
// The settings preview uses the real front-end stylesheet.
if ( 'settings' === $screen ) {
wp_enqueue_style( 'bcal', BCAL_URL . 'assets/css/calendar.css', array(), BCAL_VERSION );
}
$weekdays = array();
$monday = new DateTimeImmutable( '2024-01-01 12:00:00', wp_timezone() );
for ( $i = 1; $i <= 7; $i++ ) {
$weekdays[ $i ] = wp_date( 'D', $monday->modify( '+' . ( $i - 1 ) . ' days' )->getTimestamp() );
}
$presets = array();
foreach ( bcal_palettes() as $key => $preset ) {
$colors = array();
foreach ( bcal_palette_keys() as $color_key ) {
$colors[ $color_key ] = isset( $preset[ $color_key ] ) ? $preset[ $color_key ] : '';
}
$presets[ $key ] = $colors;
}
$time_format = (string) get_option( 'time_format' );
$theme_colors = array();
if ( 'settings' === $screen ) {
foreach ( bcal_theme_palette() as $slug => $color ) {
$theme_colors[ $slug ] = $color['hex'];
}
}
wp_localize_script(
'bcal-admin',
'bcalAdmin',
array(
'ajax' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'bcal_admin' ),
'screen' => $screen,
'duration' => bcal_default_duration(),
'locale' => str_replace( '_', '-', get_user_locale() ),
'hour12' => (bool) preg_match( '/[aAgh]/', $time_format ),
'weekdays' => $weekdays,
'phrases' => function_exists( 'bcal_weekday_phrases' ) ? bcal_weekday_phrases() : array(),
'presets' => $presets,
'themeColors' => (object) $theme_colors,
'units' => array(
'daily' => bcal_js_plural( _n_noop( 'day', 'days', 'bearius-calendar' ) ),
'weekly' => bcal_js_plural( _n_noop( 'week', 'weeks', 'bearius-calendar' ) ),
'monthly' => bcal_js_plural( _n_noop( 'month', 'months', 'bearius-calendar' ) ),
'yearly' => bcal_js_plural( _n_noop( 'year', 'years', 'bearius-calendar' ) ),
/* translators: %d: number of repetitions */
'times' => bcal_js_plural( _n_noop( '%d time', '%d times', 'bearius-calendar' ) ),
/* translators: %d: number of events */
'events' => bcal_js_plural( _n_noop( '%d event', '%d events', 'bearius-calendar' ) ),
),
'i18n' => array(
'working' => __( 'Rebuilding…', 'bearius-calendar' ),
/* translators: 1: processed events, 2: total events */
'progress' => __( 'Processed %1$d of %2$d events', 'bearius-calendar' ),
'done' => __( 'Done. The index is up to date.', 'bearius-calendar' ),
'error' => __( 'Something went wrong. Try again.', 'bearius-calendar' ),
'unsaved' => __( 'Unsaved changes', 'bearius-calendar' ),
'leave' => __( 'You have unsaved changes. Leave anyway?', 'bearius-calendar' ),
'copied' => __( 'Copied', 'bearius-calendar' ),
'adjusted' => __( 'Adjusted for readability', 'bearius-calendar' ),
'tooWeak' => __( 'Low contrast', 'bearius-calendar' ),
'checkText' => __( 'Text', 'bearius-calendar' ),
'checkMuted' => __( 'Secondary text', 'bearius-calendar' ),
'checkAccent' => __( 'Accent used as text', 'bearius-calendar' ),
'checkButton' => __( 'Text on buttons', 'bearius-calendar' ),
/* translators: 1: time, 2: duration such as "45 min" */
'autoEnd' => __( 'Ends automatically at %1$s (%2$s)', 'bearius-calendar' ),
/* translators: %s: duration such as "45 min" */
'autoEndWait' => __( 'Ends automatically %s after the start', 'bearius-calendar' ),
'minutes' => _x( 'min', 'minutes, short', 'bearius-calendar' ),
'hours' => _x( 'h', 'hours, short', 'bearius-calendar' ),
/* translators: %s: interval such as "week" or "2 weeks" */
'every' => __( 'Every %s', 'bearius-calendar' ),
/* translators: 1: "Every week", 2: list of weekdays */
'onDays' => __( '%1$s (%2$s)', 'bearius-calendar' ),
/* translators: 1: "Every month", 2: day of the month */
'onDay' => __( '%1$s, on day %2$d', 'bearius-calendar' ),
/* translators: %s: date */
'until' => __( 'until %s', 'bearius-calendar' ),
'noRepeat' => __( 'Single date', 'bearius-calendar' ),
'removeDate' => __( 'Remove date', 'bearius-calendar' ),
'searching' => __( 'Searching…', 'bearius-calendar' ),
'noResults' => __( 'Nothing found', 'bearius-calendar' ),
/* translators: %s: typed name */
'create' => __( 'Add "%s"', 'bearius-calendar' ),
'createNew' => __( 'Add new', 'bearius-calendar' ),
'saving' => __( 'Saving…', 'bearius-calendar' ),
'nameNeeded' => __( 'Enter a name.', 'bearius-calendar' ),
'existing' => __( 'Already in the list, selected it.', 'bearius-calendar' ),
/* translators: %d: day of the month */
'dayOfMonth' => __( 'Day %d of the month', 'bearius-calendar' ),
/* translators: 1: "Every month", 2: "on the 3rd Thursday" or a date */
'onDate' => __( '%1$s, %2$s', 'bearius-calendar' ),
/* translators: %d: number of additional dates */
'plusDates' => __( '+ %d additional dates', 'bearius-calendar' ),
'customRule' => __( 'Repeats by a rule from another calendar', 'bearius-calendar' ),
'rightsNeed' => __( 'Confirm that you have the right to publish these images, or turn off image downloads.', 'bearius-calendar' ),
'sourceNeed' => __( 'Enter a calendar address or choose a file.', 'bearius-calendar' ),
),
)
);
}
);
/**
* Admin interface icons (stroke, 20px).
*
* @param string $name Icon name.
* @return string
*/
function bcal_admin_icon( $name ) {
$paths = array(
'general' => '',
'appearance' => '',
'single' => '',
'notice' => '',
'advanced' => '',
'tools' => '',
'when' => '',
'place' => '',
'tickets' => '',
'options' => '',
'check' => '',
'alert' => '',
'close' => '',
'plus' => '',
'external' => '',
'copy' => '',
'repeat' => '',
'star' => '',
'search' => '',
'sun' => '',
'moon' => '',
'city' => '',
'person' => '',
'import' => '',
'feed' => '',
'undo' => '',
'pause' => '',
'play' => '',
'image' => '',
'shield' => '',
'trash' => '',
);
if ( ! isset( $paths[ $name ] ) ) {
return '';
}
return '';
}
/**
* Calendar mark: a small date tile with today's day, used as the logo.
*
* @param string $datetime Optional local date to show.
* @return string
*/
function bcal_admin_mark( $datetime = '' ) {
$ts = $datetime ? bcal_ts( $datetime ) : time();
return '' . esc_html( wp_date( 'M', $ts ) ) . '' . esc_html( wp_date( 'j', $ts ) ) . '';
}