<?php
function myarcadetheme_init_actions() {
  /** Add WPSeoContentManager Compatibility **/
  if ( function_exists('get_WPSEOContent') ) {
    add_action('myarcadetheme_after_404_content', 'get_WPSEOContent');
    add_action('myarcadetheme_after_archive_content', 'get_WPSEOContent');
    add_action('myarcadetheme_after_index_content', 'get_WPSEOContent');
  }
}
add_action( 'init', 'myarcadetheme_init_actions' );

function myarcadetheme_action_after_404_content() {
  do_action('myarcadetheme_after_404_content');
}

function myarcadetheme_action_after_archive_content() {
  do_action('myarcadetheme_after_archive_content');
}

function myarcadetheme_action_after_index_content() {
  do_action('myarcadetheme_after_index_content');
}

function myarcadetheme_before_boxes() {

  $option = myarcadetheme_get_option( 'box_design' );

  if( $option == 'half') {
    echo '<ul class="cntcls-n6">';
  }
  elseif( $option == 'vertical' ) {
    echo'<!--<vertical>--><ul class="cntcls-n4">';
  }
}
add_action( 'myarcadetheme_before_boxes', 'myarcadetheme_before_boxes' );

/**
 * [myarcadetheme_after_boxes description]
 *
 * @version 1.0.0
 * @since   1.0.0
 * @access  public
 * @return  [type] [description]
 */
function myarcadetheme_after_boxes() {

  $option = myarcadetheme_get_option( 'box_design' );

  if( $option == 'half' ) {
   echo '</ul>';
  }
  elseif( $option == 'vertical' ) {
    echo'</ul><!--</vertical>-->';
  }
}
add_action( 'myarcadetheme_after_boxes', 'myarcadetheme_after_boxes' );

/**
 * Display an alert message if there is an active contest for this game
 * and if the user doesn't participate in the contest.
 *
 * @version 1.0.0
 * @since   1.0.0
 * @access  public
 * @return  void
 */
function myarcadetheme_contest_alert() {

  // Check if MyArcadeContest is installed
  if ( ! function_exists( 'myarcadecontest_get_contest_id_for_this_game' ) || ! function_exists( 'myarcadecontest_check_user_is_in_contest' ) ) {
    return;
  }

  $contest_id = myarcadecontest_get_contest_id_for_this_game();
  $user_id    = get_current_user_id();

  // Check if user has already joined this contest
  if ( ! $contest_id || myarcadecontest_check_user_is_in_contest( $contest_id, $user_id ) ) {
    return;
  }

  ob_start();
  ?>
  <div id="message" class="info">
    <p>
      <strong><?php _e('Howdy!', 'myarcadetheme' ); ?></strong> <?php printf( __('There is an active contest available for this game. Click %shere%s to join the contest!', 'myarcadetheme' ), '<a href="'.get_permalink( $contest_id ).'" title="'.the_title_attribute( array( 'echo' => false, 'post' => $contest_id ) ).'">' , '</a>' ); ?>
    </p>
  </div>
  <?php
  ob_end_flush();
}
add_action('myarcadetheme_before_game', 'myarcadetheme_contest_alert' );