<?php
    class TiguThemeIncludesMetaboxes {
    public function __construct()
  {
    add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
    add_action('save_post', array($this, 'save_meta_boxes'));
  }
    public function add_meta_boxes()
  {
    add_meta_box( 'flash_game_meta_box', 'Game file details', 'display_gamecode', 'post', 'advanced', 'high' );
  }
    public function add_meta_box($id, $label, $post_type)
  {
    add_meta_box(
    'tigu_' . $id,
    array($this, $id),
    $post_type
);
}
    public function save_meta_boxes($post_id)
  {
    if(defined( 'DOING_AUTOSAVE') && DOING_AUTOSAVE) {
    return;
  }
    foreach($_POST as $key => $value) {
    if(strstr($key, 'tigu_')) {
    update_post_meta($post_id, $key, $value);
  }
  }
  }
    public function text($id, $label, $desc = '')
  {
    global $post;
    $html .= '<div class="tigu_metabox_field">';
    $html .= '<label for="tigu_' . $id . '">';
    $html .= $label;
    $html .= '</label>';
    $html .= '<div class="field">';
    $html .= '<input type="text" id="tigu_' . $id . '" name="tigu_' . $id . '" value="' . get_post_meta($post->ID, 'tigu_' . $id, true) . '" />';
    if($desc) {
    $html .= '<p>' . $desc . '</p>';
  }
    $html .= '</div>';
    $html .= '</div>';
    echo $html;
  }
    public function select($id, $label, $options, $desc = '')
  {
    global $post;
    $html .= '<div class="tigu_metabox_field">';
    $html .= '<label for="tigu_' . $id . '">';
    $html .= $label;
    $html .= '</label>';
    $html .= '<div class="field">';
    $html .= '<select id="tigu_' . $id . '" name="tigu_' . $id . '">';
    foreach($options as $key => $option) {
    if(get_post_meta($post->ID, 'tigu_' . $id, true) == $key) {
    $selected = 'selected="selected"';
  } else {
    $selected = '';
  }
    $html .= '<option ' . $selected . 'value="' . $key . '">' . $option . '</option>';
  }
    $html .= '</select>';
    if($desc) {
    $html .= '<p>' . $desc . '</p>';
  }
  $html .= '</div>';
  $html .= '</div>';
  echo $html;
  }
  }
  if ( !defined('MYARCADE_VERSION') && get_option('tigu_template_type') == 'Games Template') {
  $metaboxes = new TiguThemeIncludesMetaboxes;
}