post_type; $is_settings = str_contains( $hook, 'sg7g-settings' ); $is_statistics = str_contains( $hook, 'sg7g-statistics' ); if ( ! $is_media_screen && ! $is_settings && ! $is_statistics ) { return; } wp_enqueue_style( 'sg7g-admin', SG7G_URL . 'assets/css/admin.css', array(), self::asset_version( 'assets/css/admin.css' ) ); if ( $is_statistics ) { wp_enqueue_script( 'sg7g-statistics', SG7G_URL . 'assets/js/statistics.js', array(), self::asset_version( 'assets/js/statistics.js' ), true ); wp_localize_script( 'sg7g-statistics', 'sg7gStatistics', array( 'endpoint' => rest_url( '7sgaleri/v1/statistics' ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'interval' => 5000, 'refreshing' => __( 'Refreshing interaction data…', '7sgaleri' ), 'updated' => __( 'Interaction data is up to date.', '7sgaleri' ), 'error' => __( 'Live statistics could not be refreshed.', '7sgaleri' ), ) ); return; } if ( $is_settings ) { wp_enqueue_media(); wp_enqueue_script( 'sg7g-settings', SG7G_URL . 'assets/js/settings.js', array( 'jquery', 'jquery-ui-sortable' ), self::asset_version( 'assets/js/settings.js' ), true ); wp_localize_script( 'sg7g-settings', 'sg7gSettings', array( 'slotLead' => __( 'Large card', '7sgaleri' ), 'slotLarge' => /* translators: %d: Large showcase card number. */ __( 'Large card %d', '7sgaleri' ), 'slotSupport' => /* translators: %d: Small showcase card number. */ __( 'Small card %d', '7sgaleri' ), 'slotReserve' => __( 'Reserve queue', '7sgaleri' ), 'slotUnpublished' => __( 'Not displayed on the front end', '7sgaleri' ), 'position' => /* translators: %d: Content position. */ __( 'Position %d', '7sgaleri' ), 'unsaved' => __( 'There are unsaved changes.', '7sgaleri' ), 'saving' => __( 'Saving settings…', '7sgaleri' ), 'desktopPreview' => __( 'Desktop preview', '7sgaleri' ), 'mobilePreview' => __( 'Mobile preview', '7sgaleri' ), 'heroImageTitle' => __( 'Select hero image', '7sgaleri' ), 'heroImageButton' => __( 'Use this image', '7sgaleri' ), ) ); return; } if ( ! $is_media_screen || 'post' !== $screen->base ) { return; } wp_enqueue_media(); wp_enqueue_script( 'sg7g-admin', SG7G_URL . 'assets/js/admin.js', array( 'jquery' ), self::asset_version( 'assets/js/admin.js' ), true ); $source_labels = array(); foreach ( SG7G_Meta_Boxes::sources() as $source_group ) { $source_labels += $source_group; } wp_localize_script( 'sg7g-admin', 'sg7gAdmin', array( 'titleVideo' => __( 'Select video file', '7sgaleri' ), 'titleAudio' => __( 'Select audio file', '7sgaleri' ), 'button' => __( 'Use this file', '7sgaleri' ), 'valid' => __( 'Link recognized:', '7sgaleri' ), 'invalid' => __( 'This link does not appear to belong to a supported platform.', '7sgaleri' ), 'missing' => __( 'Enter a valid link or select a file from the Media Library.', '7sgaleri' ), 'previewBlocked' => __( 'This source does not provide a live preview in the admin screen; the link will be validated when saved.', '7sgaleri' ), 'youtubeNoCookie' => SG7G_Settings::enabled( 'youtube_nocookie' ), 'sourceLabels' => $source_labels, ) ); } public static function public_assets(): void { if ( ! is_singular( 'sg7g_media' ) && ! is_post_type_archive( 'sg7g_media' ) && ! is_tax( array( 'sg7g_category', 'sg7g_tag' ) ) ) { return; } wp_enqueue_style( 'sg7g-public', SG7G_URL . 'assets/css/public.css', array(), self::asset_version( 'assets/css/public.css' ) ); wp_add_inline_style( 'sg7g-public', self::dynamic_css() ); wp_enqueue_script( 'sg7g-public', SG7G_URL . 'assets/js/public.js', array(), self::asset_version( 'assets/js/public.js' ), true ); wp_script_add_data( 'sg7g-public', 'strategy', 'defer' ); $singular_post_id = is_singular( 'sg7g_media' ) ? get_queried_object_id() : 0; $can_track_view = $singular_post_id > 0 && ! post_password_required( $singular_post_id ); wp_localize_script( 'sg7g-public', 'sg7gPublic', array( 'postId' => $can_track_view ? $singular_post_id : 0, 'viewEndpoint' => $can_track_view ? rest_url( '7sgaleri/v1/view/' . $singular_post_id ) : '', 'viewToken' => $can_track_view ? SG7G_Views::token( $singular_post_id ) : '', 'loadError' => __( 'The player could not be loaded.', '7sgaleri' ), 'metricsEndpoint' => rest_url( '7sgaleri/v1/metrics' ), 'searchEndpoint' => rest_url( '7sgaleri/v1/search' ), 'searchLoading' => __( 'Searching…', '7sgaleri' ), 'searchError' => __( 'The search could not be completed right now. Please try again.', '7sgaleri' ), 'searchEmpty' => __( 'No content matched your search.', '7sgaleri' ), 'searchTitle' => __( 'Search results', '7sgaleri' ), 'searchPrevious' => __( 'Previous', '7sgaleri' ), 'searchNext' => __( 'Next', '7sgaleri' ), 'searchPageLabel' => __( 'Search results pages', '7sgaleri' ), 'paginationMode' => (string) SG7G_Settings::get( 'pagination_mode', 'numbers' ), 'loadMore' => __( 'Load More', '7sgaleri' ), 'loadingMore' => __( 'Loading content…', '7sgaleri' ), 'loadMoreError' => __( 'New content could not be loaded. Please try again.', '7sgaleri' ), 'shareCopied' => __( 'Link copied.', '7sgaleri' ), 'shareCopyError' => __( 'The link could not be copied.', '7sgaleri' ), 'likeLabel' => __( 'Like', '7sgaleri' ), 'likedLabel' => __( 'Liked', '7sgaleri' ), 'likeError' => __( 'Your like could not be saved. Please try again.', '7sgaleri' ), 'restNonce' => is_user_logged_in() ? wp_create_nonce( 'wp_rest' ) : '', ) ); } /** * Use each asset's modification time so a prefix or selector migration can never * leave a browser/CDN serving an incompatible cached stylesheet or script. */ private static function asset_version( string $relative_path ): string { $path = SG7G_DIR . ltrim( $relative_path, '/' ); $time = is_file( $path ) ? filemtime( $path ) : false; return SG7G_VERSION . '-' . ( false !== $time ? (string) $time : '0' ); } private static function dynamic_css(): string { $settings = SG7G_Settings::all(); $width = 'custom' === $settings['width_mode'] ? absint( $settings['custom_width'] ) . 'px' : 'var(--ys-site-width, var(--ys-container-width, var(--site-width, var(--container-width, var(--wp--style--global--wide-size, 1440px)))))'; $declarations = array( '--sg7g-width:' . $width, '--sg7g-text:' . ( sanitize_hex_color( $settings['text_color'] ) ?: '#161616' ), '--sg7g-muted:' . ( sanitize_hex_color( $settings['muted_color'] ) ?: '#696969' ), '--sg7g-line:' . ( sanitize_hex_color( $settings['line_color'] ) ?: '#dedede' ), '--sg7g-surface:' . ( sanitize_hex_color( $settings['surface_color'] ) ?: '#f4f4f4' ), '--sg7g-hero-eyebrow-color:' . ( sanitize_hex_color( $settings['hero_eyebrow_color'] ?? '' ) ?: '#ffffff' ), '--sg7g-hero-title-color:' . ( sanitize_hex_color( $settings['hero_title_color'] ?? '' ) ?: '#ffffff' ), '--sg7g-hero-description-color:' . ( sanitize_hex_color( $settings['hero_description_color'] ?? '' ) ?: '#ffffff' ), '--sg7g-hero-quote-color:' . ( sanitize_hex_color( $settings['hero_quote_color'] ?? '' ) ?: '#ffffff' ), '--sg7g-popular-like-color:' . ( sanitize_hex_color( $settings['popular_like_color'] ?? '' ) ?: '#a13b43' ), '--sg7g-featured-area-title-size:' . max( 1, absint( $settings['featured_area_title_size'] ?? 32 ) ) . 'px', '--sg7g-card-title-size:' . absint( $settings['card_title_size'] ) . 'px', '--sg7g-card-title-mobile:' . absint( $settings['card_title_mobile'] ) . 'px', '--sg7g-featured-title-size:' . absint( $settings['featured_title_size'] ) . 'px', '--sg7g-featured-title-mobile:' . absint( $settings['featured_title_mobile'] ) . 'px', '--sg7g-single-title-size:' . absint( $settings['single_title_size'] ) . 'px', '--sg7g-single-title-mobile:' . absint( $settings['single_title_mobile'] ) . 'px', '--sg7g-content-text-size:' . absint( $settings['content_text_size'] ) . 'px', '--sg7g-content-text-mobile:' . absint( $settings['content_text_mobile'] ) . 'px', '--sg7g-hero-eyebrow-size:' . absint( $settings['hero_eyebrow_size'] ?? 12 ) . 'px', '--sg7g-hero-eyebrow-mobile:' . absint( $settings['hero_eyebrow_mobile'] ?? 11 ) . 'px', '--sg7g-hero-title-size:' . absint( $settings['hero_title_size'] ?? 72 ) . 'px', '--sg7g-hero-title-mobile:' . absint( $settings['hero_title_mobile'] ?? 48 ) . 'px', '--sg7g-hero-description-size:' . absint( $settings['hero_description_size'] ?? 18 ) . 'px', '--sg7g-hero-description-mobile:' . absint( $settings['hero_description_mobile'] ?? 15 ) . 'px', '--sg7g-hero-quote-size:' . absint( $settings['hero_quote_size'] ?? 19 ) . 'px', '--sg7g-hero-quote-mobile:' . absint( $settings['hero_quote_mobile'] ?? 15 ) . 'px', ); if ( 'custom' === (string) $settings['typography_mode'] ) { $declarations[] = '--sg7g-hero-title-font:' . self::font_stack( (string) $settings['hero_title_font'] ); $declarations[] = '--sg7g-hero-text-font:' . self::font_stack( (string) $settings['hero_text_font'] ); $declarations[] = '--sg7g-hero-title-weight:' . absint( $settings['hero_title_weight'] ); $declarations[] = '--sg7g-hero-text-weight:' . absint( $settings['hero_text_weight'] ); $declarations[] = '--sg7g-title-font:' . self::font_stack( (string) $settings['title_font'] ); $declarations[] = '--sg7g-featured-font:' . self::font_stack( (string) $settings['featured_font'] ); $declarations[] = '--sg7g-body-font:' . self::font_stack( (string) $settings['body_font'] ); $declarations[] = '--sg7g-single-title-font:' . self::font_stack( (string) $settings['single_title_font'] ); $declarations[] = '--sg7g-title-weight:' . absint( $settings['title_weight'] ); $declarations[] = '--sg7g-featured-weight:' . absint( $settings['featured_weight'] ); $declarations[] = '--sg7g-single-title-weight:' . absint( $settings['single_title_weight'] ); $declarations[] = '--sg7g-body-weight:' . absint( $settings['body_weight'] ); } else { $declarations[] = '--sg7g-hero-title-font:inherit'; $declarations[] = '--sg7g-hero-text-font:inherit'; $declarations[] = '--sg7g-hero-title-weight:inherit'; $declarations[] = '--sg7g-hero-text-weight:inherit'; $declarations[] = '--sg7g-title-font:inherit'; $declarations[] = '--sg7g-featured-font:inherit'; $declarations[] = '--sg7g-body-font:inherit'; $declarations[] = '--sg7g-single-title-font:inherit'; $declarations[] = '--sg7g-title-weight:inherit'; $declarations[] = '--sg7g-featured-weight:inherit'; $declarations[] = '--sg7g-single-title-weight:inherit'; $declarations[] = '--sg7g-body-weight:inherit'; } return '.sg7g-archive,.sg7g-single{' . implode( ';', $declarations ) . ';}'; } private static function font_stack( string $font ): string { $stacks = array( 'theme' => 'inherit', 'system_sans' => 'system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif', 'editorial_serif' => 'Georgia,"Times New Roman",serif', 'classic_serif' => '"Times New Roman",Times,serif', ); return $stacks[ $font ] ?? $stacks['theme']; } }