/**
  * Populates the $this->enabled_metaboxes list
  */
 public function filter_metaboxes()
 {
     if (!is_null($this->enabled_metaboxes)) {
         return;
     }
     $this->enabled_metaboxes = array();
     $template = get_post_meta($_GET['post'], '_wp_page_template', true);
     foreach ($this->metabox_infos as $metabox_info) {
         $template_checker = new TemplateChecker($metabox_info->positions['include'], $metabox_info->positions['exclude']);
         if (($template == 'default' || $template == '') && (get_the_ID() == get_option('page_on_front') || get_option('page_on_front') == $_GET['post'] || get_option('page_on_front') == $_POST['post_ID'])) {
             $template = 'front-page.php';
         }
         if ($template_checker->check($template)) {
             $this->enabled_metaboxes[] = $metabox_info->metabox;
         }
     }
 }
 /**
  * Prints the HTML markup for the metabox
  */
 public static function metabox_html($post)
 {
     if (is_null($post)) {
         global $post;
     }
     $template = self::get_template($post);
     if (count(self::$media_list)) {
         $is_first = true;
         foreach (self::$media_list as $k => $elem) {
             $template_checker = new TemplateChecker($elem['include'], $elem['exclude']);
             if (!$template_checker->check($template)) {
                 continue;
             }
             $name = self::META_KEY_NAME . '-' . $elem['id'];
             wp_nonce_field(__FILE__, $name . '_nonce');
             $value = get_post_meta($post->ID, $name, true);
             // main edit button
             $edit_button = HtmlHelper::anchor('javascript:;', HtmlHelper::span('', array('class' => 'wp-media-buttons-icon')) . __('Manage Media', 'wtu_framework'), array('id' => 'wtu-media-manager-button-' . $elem['id'], 'class' => 'button media-manager-button', 'data-target' => '#wtu-media-manager-element-' . $elem['id'], 'data-target-undo' => '#wtu-media-manager-undo-' . $elem['id'], 'data-target-delete' => '#wtu-media-manager-delete-' . $elem['id'], 'data-counter' => '#wtu-media-manager-counter-' . $elem['id'], 'data-frame-id' => 'wtu-media-manager-' . $elem['id'], 'data-title' => sprintf(__('Manage Media for %s', 'wtu_framework'), $elem['label']), 'data-button-label' => sprintf(__('Add selected media to %s set', 'wtu_framework'), $elem['label']), 'data-multiple' => 'true', 'data-elem-id' => $elem['id'], 'data-shortcode' => $elem['shortcode'], 'title' => sprintf(__('Manage Media for %s', 'wtu_framework'), $elem['label'])));
             // input to store temp values, use text instead of hidden to debug
             $input = HtmlHelper::input($name, 'hidden', array('id' => 'wtu-media-manager-element-' . $elem['id'], 'value' => $value));
             // Counter
             $number = 0;
             if (isset($value) && $value != '') {
                 $number = count(explode(',', $value));
             }
             $counter = ' ' . HtmlHelper::span($number > 0 ? sprintf(_n('1 element', '%s elements', $number, 'wtu_framework'), $number) : __('Empty', 'wtu_framework'), array('id' => 'wtu-media-manager-counter-' . $elem['id'], 'data-label-no-images' => __('Empty', 'wtu_framework'), 'data-label-one-image' => __('1 element', 'wtu_framework'), 'data-label-more-images' => __('%s elements', 'wtu_framework')));
             // delete button
             $delete = HtmlHelper::anchor('javascript:;', __('Delete', 'wtu_framework'), array('id' => 'wtu-media-manager-delete-' . $elem['id'], 'style' => $value ? '' : 'display:none;', 'class' => 'delete-media-manager-gallery submitdelete', 'data-counter' => '#wtu-media-manager-counter-' . $elem['id'], 'data-gallery' => $elem['id'], 'data-target' => '#wtu-media-manager-element-' . $elem['id'], 'data-target-undo' => '#wtu-media-manager-undo-' . $elem['id'], 'data-target-origin' => '#wtu-media-manager-button-' . $elem['id'], 'title' => __('Delete Media Set', 'wtu_framework')));
             // undo button
             $undo = HtmlHelper::anchor('javascript:;', __('Undo', 'wtu_framework'), array('id' => 'wtu-media-manager-undo-' . $elem['id'], 'style' => 'display:none;', 'class' => 'undo-media-manager-gallery', 'data-gallery' => $elem['id'], 'data-target' => '#wtu-media-manager-element-' . $elem['id'], 'data-elem-id' => $elem['id'], 'data-target-origin' => '#wtu-media-manager-button-' . $elem['id'], 'data-target-delete' => '#wtu-media-manager-delete-' . $elem['id'], 'data-counter' => '#wtu-media-manager-counter-' . $elem['id'], 'title' => __('Restore Media Set', 'wtu_framework')));
             $title = HtmlHelper::paragraph(HtmlHelper::strong($elem['label']));
             $inner_html = '';
             if (!$is_first) {
                 $inner_html .= HtmlHelper::br();
             }
             $inner_html .= '<table class="widefat"><thead>';
             $inner_html .= '<td width="33%">' . $title . '</td>';
             $inner_html .= '<td width="33%">&nbsp;</td>';
             $inner_html .= '<td width="33%">' . $edit_button . '</td></thead>';
             $inner_html .= '<tbody><tr style="line-height: 25px;"><td class="submitbox">' . $delete . $undo . '</td>';
             $inner_html .= '<td>&nbsp;</td>';
             $inner_html .= '<td>' . $counter . '</td>';
             $inner_html .= '</tr></tbody></table>';
             $inner_html .= $input;
             echo HtmlHelper::div($inner_html, array('class' => ''));
             $is_first = false;
         }
     }
     //var_dump($value);
 }