context['postId'])) { $ctx = (int) $block->context['postId']; if ($ctx > 0 && get_post_type($ctx) === $cpt) { $pid = $ctx; } } if ($pid <= 0 && function_exists('is_singular') && is_singular($cpt)) { $pid = (int) get_queried_object_id(); } if ($pid <= 0 || get_post_type($pid) !== $cpt) { return; } $name = get_the_title($pid); $desc = (string) get_post_meta($pid, '_aieo_comp_short_desc', true); $gf_id = (int) get_post_meta($pid, '_aieo_comp_gf_form_id', true); $img_d = (int) get_post_meta($pid, '_aieo_comp_image_desktop', true); $img_m = (int) get_post_meta($pid, '_aieo_comp_image_mobile', true); $links = class_exists('AIEO_Competition_CPT') ? AIEO_Competition_CPT::share_links($pid) : array(); $state = class_exists('AIEO_Competition_CPT') ? AIEO_Competition_CPT::schedule_state($pid) : 'live'; $is_manager = current_user_can('edit_post', $pid) || current_user_can('manage_options'); $start_disp = class_exists('AIEO_Competition_CPT') ? AIEO_Competition_CPT::fmt_dt(get_post_meta($pid, AIEO_Competition_CPT::META_START, true)) : ''; $end_disp = class_exists('AIEO_Competition_CPT') ? AIEO_Competition_CPT::fmt_dt(get_post_meta($pid, AIEO_Competition_CPT::META_END, true)) : ''; $announce_raw = class_exists('AIEO_Competition_CPT') ? (string) get_post_meta($pid, AIEO_Competition_CPT::META_ANNOUNCE_AT, true) : ''; $announce_disp = ($announce_raw !== '' && class_exists('AIEO_Competition_CPT')) ? AIEO_Competition_CPT::fmt_dt($announce_raw) : ''; $winners_html = class_exists('AIEO_Competition_CPT') ? (string) get_post_meta($pid, AIEO_Competition_CPT::META_WINNERS_ANNOUNCE, true) : ''; $winners = ($state === 'ended' && class_exists('AIEO_Competition_Participants')) ? AIEO_Competition_Participants::get_winners($pid) : array(); $own_page = function_exists('is_singular') && is_singular($cpt) && (int) get_queried_object_id() === $pid; $rooster_zero = function_exists('get_template') && 'rooster' === get_template(); $featured = (int) get_post_thumbnail_id($pid); $twice = $own_page && $featured > 0 && in_array($featured, array($img_d, $img_m), true) && (bool) apply_filters('aieo_competition_template_shows_featured_image', $rooster_zero, $pid); $picture = isset($attributes['picture']) ? (string) $attributes['picture'] : ''; $show_picture = 'show' === $picture || ('hide' !== $picture && !$twice); $hero = ''; if ($show_picture && ($img_d || $img_m)) { $main = $img_d ?: $img_m; $source = ''; if ($img_d && $img_m) { $phone = wp_get_attachment_image_src($img_m, 'large'); if (is_array($phone)) { $srcset = (string) wp_get_attachment_image_srcset($img_m, 'large'); $source = ''; } } $hero = '' . $source . wp_get_attachment_image($main, 'full', false, $own_page ? array('class' => 'aieo-competition__img', 'alt' => $name, 'loading' => 'eager', 'fetchpriority' => 'high') : array('class' => 'aieo-competition__img', 'alt' => $name, 'loading' => 'lazy')) . ''; } $wrapper = get_block_wrapper_attributes(array('class' => 'aieo-competition')); echo '
'; if ($hero !== '') { echo '
' . $hero . '
'; } echo '
'; $title_tag = $own_page && (bool) apply_filters('aieo_competition_template_shows_title', $rooster_zero, $pid) ? 'h2' : 'h1'; echo '<' . $title_tag . ' class="aieo-competition__title">' . esc_html($name) . ''; $confirm_notice = class_exists('AIEO_Competition_Participants') ? AIEO_Competition_Participants::confirmation_notice() : null; if (is_array($confirm_notice)) { echo '
' . esc_html($confirm_notice['text']) . '
'; } if ($desc !== '') { echo '
' . wp_kses_post(wpautop($desc)) . '
'; } if ($start_disp !== '' || $end_disp !== '') { echo '
'; if ($start_disp !== '') { echo '' . esc_html__('Starts:', 'ai-eshop-optimizer') . ' ' . esc_html($start_disp) . ''; } if ($end_disp !== '') { $end_label = ($state === 'ended') ? esc_html__('Ended:', 'ai-eshop-optimizer') : esc_html__('Ends:', 'ai-eshop-optimizer'); echo '' . $end_label . ' ' . esc_html($end_disp) . ''; } echo '
'; } $show_form = ($state === 'live') || $is_manager; if ($is_manager && $state !== 'live') { $note = ($state === 'before') ? __('Preview (shop manager): this competition hasn’t started — visitors see the “coming soon” notice.', 'ai-eshop-optimizer') : __('Preview (shop manager): this competition has ended — visitors see the “ended” message.', 'ai-eshop-optimizer'); echo '

' . esc_html($note) . '

'; } $comp_settings = (array) get_option('aieo_competitions_settings', array()); if (!$is_manager && $state === 'before') { $soon = (isset($comp_settings['msg_soon']) && $comp_settings['msg_soon'] !== '') ? (string) $comp_settings['msg_soon'] : ($start_disp !== '' ? __('This competition opens on %s. Check back soon!', 'ai-eshop-optimizer') : __('This competition hasn’t started yet. Check back soon!', 'ai-eshop-optimizer')); if (strpos($soon, '%s') !== false) { $soon = $start_disp !== '' ? sprintf($soon, $start_disp) : trim(str_replace('%s', '', $soon)); } echo '
' . esc_html($soon) . '
'; } elseif (!$is_manager && $state === 'ended') { $ended = (isset($comp_settings['msg_ended']) && $comp_settings['msg_ended'] !== '') ? (string) $comp_settings['msg_ended'] : __('This competition has ended. Thank you to everyone who entered!', 'ai-eshop-optimizer'); echo '
' . esc_html($ended) . '
'; } if ($show_form) { $form_in_use = class_exists('AIEO_Competition_Entry_Form') ? AIEO_Competition_Entry_Form::form_in_use($pid) : ($gf_id > 0 && class_exists('GFForms') ? 'gravity' : ''); if ('gravity' === $form_in_use) { echo '
' . do_shortcode('[gravityform id="' . $gf_id . '" title="false" description="false" ajax="true"]') . '
'; } elseif ('native' === $form_in_use) { echo '
' . AIEO_Competition_Entry_Form::render($pid) . '
'; } } if (!empty($winners)) { echo '
'; $trophy = function_exists('rooster_icon') ? (string) rooster_icon('trophy', array('class' => 'aieo-competition__trophy')) : ''; echo '

' . $trophy . esc_html__('Winners', 'ai-eshop-optimizer') . '

'; echo '
    '; foreach ($winners as $w) { echo '
  • ' . esc_html(AIEO_Competition_CPT::winner_public_name($w)) . '
  • '; } echo '
'; if ($winners_html !== '') { echo '
' . wp_kses_post(wpautop($winners_html)) . '
'; } echo '
'; } elseif ($announce_disp !== '') { $atext = (isset($comp_settings['msg_announce']) && $comp_settings['msg_announce'] !== '') ? (string) $comp_settings['msg_announce'] : __('The winners will be announced on %s.', 'ai-eshop-optimizer'); $atext = (strpos($atext, '%s') !== false) ? sprintf($atext, $announce_disp) : trim($atext . ' ' . $announce_disp); echo '
' . esc_html($atext) . '
'; } if ($state !== 'ended') { $share = ''; $theme_share = class_exists('WP_Block_Type_Registry') && WP_Block_Type_Registry::get_instance()->is_registered('rooster/share-box'); if ($theme_share && !$own_page) { $share = (string) (new WP_Block( array('blockName' => 'rooster/share-box', 'attrs' => array('channels' => 'facebook,copy', 'display' => 'inline', 'showHeading' => false), 'innerBlocks' => array(), 'innerHTML' => '', 'innerContent' => array()), array('postId' => $pid, 'postType' => $cpt) ))->render(); } elseif (!$theme_share && !empty($links['facebook'])) { $share = ''; } $follow = ''; foreach (class_exists('AIEO_Competition_CPT') ? AIEO_Competition_CPT::follow_links() : array() as $net => $url) { $follow .= ''; } if ('' !== $share . $follow) { echo ''; } } echo '
'; echo '
';