Ejemplo n.º 1
0
/**
 * woothemes_metabox_create function.
 *
 * @access public
 * @param object $post
 * @param array $callback
 * @return void
 */
function woothemes_metabox_create($post, $callback)
{
    global $post;
    // Allow child themes/plugins to act here.
    do_action('woothemes_metabox_create', $post, $callback);
    $template_to_show = $callback['args'];
    $woo_metaboxes = get_option('woo_custom_template');
    $seo_metaboxes = get_option('woo_custom_seo_template');
    if (empty($seo_metaboxes) && $template_to_show == 'seo') {
        return;
    }
    if (get_option('seo_woo_hide_fields') != 'true' && $template_to_show == 'seo') {
        $woo_metaboxes = $seo_metaboxes;
    }
    // Array sanity check.
    if (!is_array($woo_metaboxes)) {
        return;
    }
    $output = '';
    $output .= '<table class="woo_metaboxes_table">' . "\n";
    foreach ($woo_metaboxes as $k => $woo_metabox) {
        // Setup CSS classes to be added to each table row.
        $row_css_class = 'woo-custom-field';
        if ($k + 1 == count($woo_metaboxes)) {
            $row_css_class .= ' last';
        }
        $woo_id = 'woothemes_' . $woo_metabox['name'];
        $woo_name = $woo_metabox['name'];
        if ($template_to_show == 'seo') {
            $metabox_post_type_restriction = 'undefined';
        } elseif (function_exists('woothemes_content_builder_menu')) {
            $metabox_post_type_restriction = $woo_metabox['cpt'][$post->post_type];
        } else {
            $metabox_post_type_restriction = 'undefined';
        }
        if ($metabox_post_type_restriction != '' && $metabox_post_type_restriction == 'true') {
            $type_selector = true;
        } elseif ($metabox_post_type_restriction == 'undefined') {
            $type_selector = true;
        } else {
            $type_selector = false;
        }
        $woo_metaboxvalue = '';
        if ($type_selector) {
            if (isset($woo_metabox['type']) && in_array($woo_metabox['type'], woothemes_metabox_fieldtypes())) {
                $woo_metaboxvalue = get_post_meta($post->ID, $woo_name, true);
            }
            // Make sure slashes are stripped before output.
            foreach (array('label', 'desc', 'std') as $k) {
                if (isset($woo_metabox[$k]) && $woo_metabox[$k] != '') {
                    $woo_metabox[$k] = stripslashes($woo_metabox[$k]);
                }
            }
            if ($woo_metaboxvalue == '' && isset($woo_metabox['std'])) {
                $woo_metaboxvalue = $woo_metabox['std'];
            }
            // Add a dynamic CSS class to each row in the table.
            $row_css_class .= ' woo-field-type-' . strtolower($woo_metabox['type']);
            if ($woo_metabox['type'] == 'info') {
                $output .= "\t" . '<tr class="' . $row_css_class . '" style="background:#f8f8f8; font-size:11px; line-height:1.5em;">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td style="font-size:11px;">' . $woo_metabox['desc'] . '</td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'text') {
                $add_class = '';
                $add_counter = '';
                if ($template_to_show == 'seo') {
                    $add_class = 'words-count';
                    $add_counter = '<span class="counter">0 characters, 0 words</span>';
                }
                $output .= "\t" . '<tr class="' . $row_css_class . '">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td><input class="woo_input_text ' . $add_class . '" type="' . $woo_metabox['type'] . '" value="' . esc_attr($woo_metaboxvalue) . '" name="' . $woo_name . '" id="' . esc_attr($woo_id) . '"/>';
                $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . ' ' . $add_counter . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'textarea') {
                $add_class = '';
                $add_counter = '';
                if ($template_to_show == 'seo') {
                    $add_class = 'words-count';
                    $add_counter = '<span class="counter">0 characters, 0 words</span>';
                }
                $output .= "\t" . '<tr class="' . $row_css_class . '">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_metabox . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td><textarea class="woo_input_textarea ' . $add_class . '" name="' . $woo_name . '" id="' . esc_attr($woo_id) . '">' . esc_textarea(stripslashes($woo_metaboxvalue)) . '</textarea>';
                $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . ' ' . $add_counter . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'calendar') {
                $output .= "\t" . '<tr class="' . $row_css_class . '">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_metabox . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td><input class="woo_input_calendar" type="text" name="' . $woo_name . '" id="' . esc_attr($woo_id) . '" value="' . esc_attr($woo_metaboxvalue) . '">';
                $output .= "\t\t" . '<input type="hidden" name="datepicker-image" value="' . get_template_directory_uri() . '/functions/images/calendar.gif" />';
                $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'time') {
                $output .= "\t" . '<tr>';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td><input class="woo_input_time" type="' . $woo_metabox['type'] . '" value="' . esc_attr($woo_metaboxvalue) . '" name="' . $woo_name . '" id="' . esc_attr($woo_id) . '"/>';
                $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'select') {
                $output .= "\t" . '<tr class="' . $row_css_class . '">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td><select class="woo_input_select" id="' . esc_attr($woo_id) . '" name="' . esc_attr($woo_name) . '">';
                $output .= '<option value="">Select to return to default</option>';
                $array = $woo_metabox['options'];
                if ($array) {
                    foreach ($array as $id => $option) {
                        $selected = '';
                        if (isset($woo_metabox['default'])) {
                            if ($woo_metabox['default'] == $option && empty($woo_metaboxvalue)) {
                                $selected = 'selected="selected"';
                            } else {
                                $selected = '';
                            }
                        }
                        if ($woo_metaboxvalue == $option) {
                            $selected = 'selected="selected"';
                        } else {
                            $selected = '';
                        }
                        $output .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . $option . '</option>';
                    }
                }
                $output .= '</select><span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'select2') {
                $output .= "\t" . '<tr class="' . $row_css_class . '">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td><select class="woo_input_select" id="' . esc_attr($woo_id) . '" name="' . esc_attr($woo_name) . '">';
                $output .= '<option value="">Select to return to default</option>';
                $array = $woo_metabox['options'];
                if ($array) {
                    foreach ($array as $id => $option) {
                        $selected = '';
                        if (isset($woo_metabox['default'])) {
                            if ($woo_metabox['default'] == $id && empty($woo_metaboxvalue)) {
                                $selected = 'selected="selected"';
                            } else {
                                $selected = '';
                            }
                        }
                        if ($woo_metaboxvalue == $id) {
                            $selected = 'selected="selected"';
                        } else {
                            $selected = '';
                        }
                        $output .= '<option value="' . esc_attr($id) . '" ' . $selected . '>' . $option . '</option>';
                    }
                }
                $output .= '</select><span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'checkbox') {
                if ($woo_metaboxvalue == 'true') {
                    $checked = ' checked="checked"';
                } else {
                    $checked = '';
                }
                $output .= "\t" . '<tr class="' . $row_css_class . '">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td><input type="checkbox" ' . $checked . ' class="woo_input_checkbox" value="true"  id="' . esc_attr($woo_id) . '" name="' . esc_attr($woo_name) . '" />';
                $output .= '<span class="woo_metabox_desc" style="display:inline">' . $woo_metabox['desc'] . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'radio') {
                $array = $woo_metabox['options'];
                if ($array) {
                    $output .= "\t" . '<tr class="' . $row_css_class . '">';
                    $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                    $output .= "\t\t" . '<td>';
                    foreach ($array as $id => $option) {
                        if ($woo_metaboxvalue == $id) {
                            $checked = ' checked';
                        } else {
                            $checked = '';
                        }
                        $output .= '<input type="radio" ' . $checked . ' value="' . $id . '" class="woo_input_radio"  name="' . esc_attr($woo_name) . '" />';
                        $output .= '<span class="woo_input_radio_desc" style="display:inline">' . $option . '</span><div class="woo_spacer"></div>';
                    }
                    $output .= "\t" . '</tr>' . "\n";
                }
            } elseif ($woo_metabox['type'] == 'images') {
                $i = 0;
                $select_value = '';
                $layout = '';
                foreach ($woo_metabox['options'] as $key => $option) {
                    $i++;
                    $checked = '';
                    $selected = '';
                    if ($woo_metaboxvalue != '') {
                        if ($woo_metaboxvalue == $key) {
                            $checked = ' checked';
                            $selected = 'woo-meta-radio-img-selected';
                        }
                    } else {
                        if ($option['std'] == $key) {
                            $checked = ' checked';
                        } elseif ($i == 1) {
                            $checked = ' checked';
                            $selected = 'woo-meta-radio-img-selected';
                        } else {
                            $checked = '';
                        }
                    }
                    $layout .= '<div class="woo-meta-radio-img-label">';
                    $layout .= '<input type="radio" id="woo-meta-radio-img-' . $woo_name . $i . '" class="checkbox woo-meta-radio-img-radio" value="' . esc_attr($key) . '" name="' . $woo_name . '" ' . $checked . ' />';
                    $layout .= '&nbsp;' . esc_html($key) . '<div class="woo_spacer"></div></div>';
                    $layout .= '<img src="' . esc_url($option) . '" alt="" class="woo-meta-radio-img-img ' . $selected . '" onClick="document.getElementById(\'woo-meta-radio-img-' . esc_js($woo_metabox["name"] . $i) . '\').checked = true;" />';
                }
                $output .= "\t" . '<tr class="' . $row_css_class . '">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td class="woo_metabox_fields">';
                $output .= $layout;
                $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            } elseif ($woo_metabox['type'] == 'upload') {
                if (isset($woo_metabox['default'])) {
                    $default = $woo_metabox['default'];
                } else {
                    $default = '';
                }
                // Add support for the WooThemes Media Library-driven Uploader Module // 2010-11-09.
                if (function_exists('woothemes_medialibrary_uploader')) {
                    $_value = $default;
                    $_value = get_post_meta($post->ID, $woo_metabox['name'], true);
                    $output .= "\t" . '<tr class="' . $row_css_class . '">';
                    $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_metabox['name'] . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                    $output .= "\t\t" . '<td class="woo_metabox_fields">' . woothemes_medialibrary_uploader($woo_metabox['name'], $_value, 'postmeta', $woo_metabox['desc'], $post->ID);
                    $output .= '</td>' . "\n";
                    $output .= "\t" . '</tr>' . "\n";
                } else {
                    $output .= "\t" . '<tr class="' . $row_css_class . '">';
                    $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . esc_attr($woo_id) . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                    $output .= "\t\t" . '<td class="woo_metabox_fields">' . woothemes_uploader_custom_fields($post->ID, $woo_name, $default, $woo_metabox['desc']);
                    $output .= '</td>' . "\n";
                    $output .= "\t" . '</tr>' . "\n";
                }
            } elseif ($woo_metabox['type'] == 'timestamp') {
                $woo_metaboxvalue = get_post_meta($post->ID, $woo_name, true);
                // Default to current UNIX timestamp.
                if ($woo_metaboxvalue == '') {
                    $woo_metaboxvalue = time();
                }
                $output .= "\t" . '<tr class="' . $row_css_class . '">';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_metabox . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td><input class="woo_input_calendar" type="text" name="' . $woo_name . '[date]" id="' . esc_attr($woo_id) . '" value="' . esc_attr(date('m/d/Y', $woo_metaboxvalue)) . '">';
                $output .= "\t\t" . '<input type="hidden" name="datepicker-image" value="' . get_template_directory_uri() . '/functions/images/calendar.gif" /><br />';
                $output .= '<select name="' . $woo_name . '[hour]" class="woo-select-timestamp">' . "\n";
                for ($i = 0; $i <= 23; $i++) {
                    $j = $i;
                    if ($i < 10) {
                        $j = '0' . $i;
                    }
                    $output .= '<option value="' . $i . '"' . selected(date('H', $woo_metaboxvalue), $j, false) . '>' . $j . '</option>' . "\n";
                }
                $output .= '</select>' . "\n";
                $output .= '<select name="' . $woo_name . '[minute]" class="woo-select-timestamp">' . "\n";
                for ($i = 0; $i <= 59; $i++) {
                    $j = $i;
                    if ($i < 10) {
                        $j = '0' . $i;
                    }
                    $output .= '<option value="' . $i . '"' . selected(date('i', $woo_metaboxvalue), $j, false) . '>' . $j . '</option>' . "\n";
                }
                $output .= '</select>' . "\n";
                $output .= '<select name="' . $woo_name . '[second]" class="woo-select-timestamp">' . "\n";
                for ($i = 0; $i <= 59; $i++) {
                    $j = $i;
                    if ($i < 10) {
                        $j = '0' . $i;
                    }
                    $output .= '<option value="' . $i . '"' . selected(date('s', $woo_metaboxvalue), $j, false) . '>' . $j . '</option>' . "\n";
                }
                $output .= '</select>' . "\n";
                $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            }
        }
        // End IF Statement
    }
    $output .= '</table>' . "\n\n";
    echo $output;
}
Ejemplo n.º 2
0
function woothemes_meta_box_content()
{
    global $post;
    $woo_metaboxes = get_option('woo_custom_template');
    $output = '';
    $output .= '<table class="woo_metaboxes_table">' . "\n";
    foreach ($woo_metaboxes as $woo_id => $woo_metabox) {
        if ($woo_metabox['type'] == 'text' or $woo_metabox['type'] == 'select' or $woo_metabox['type'] == 'checkbox' or $woo_metabox['type'] == 'textarea' or $woo_metabox['type'] == 'radio') {
            $woo_metaboxvalue = get_post_meta($post->ID, $woo_metabox["name"], true);
        }
        if ($woo_metaboxvalue == "" || !isset($woo_metaboxvalue)) {
            $woo_metaboxvalue = $woo_metabox['std'];
        }
        if ($woo_metabox['type'] == 'text') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><input class="woo_input_text" type="' . $woo_metabox['type'] . '" value="' . $woo_metaboxvalue . '" name="woothemes_' . $woo_metabox["name"] . '" id="' . $woo_id . '"/>';
            $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
            $output .= "\t" . '<td></td></tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'textarea') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_metabox . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><textarea class="woo_input_textarea" name="woothemes_' . $woo_metabox["name"] . '" id="' . $woo_id . '">' . $woo_metaboxvalue . '</textarea>';
            $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
            $output .= "\t" . '<td></td></tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'select') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><select class="woo_input_select" id="' . $woo_id . '" name="woothemes_' . $woo_metabox["name"] . '">';
            $output .= '<option value="">Select to return to default</option>';
            $array = $woo_metabox['options'];
            if ($array) {
                foreach ($array as $id => $option) {
                    $selected = '';
                    if ($woo_metabox['default'] == $option && empty($woo_metaboxvalue)) {
                        $selected = 'selected="selected"';
                    } else {
                        $selected = '';
                    }
                    if ($woo_metaboxvalue == $option) {
                        $selected = 'selected="selected"';
                    } else {
                        $selected = '';
                    }
                    $output .= '<option value="' . $option . '" ' . $selected . '>' . $option . '</option>';
                }
            }
            $output .= '</select><span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td></td><td></td>' . "\n";
            $output .= "\t" . '</tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'checkbox') {
            if ($woo_metaboxvalue == 'true') {
                $checked = ' checked="checked"';
            } else {
                $checked = '';
            }
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><input type="checkbox" ' . $checked . ' class="woo_input_checkbox" value="true"  id="' . $woo_id . '" name="woothemes_' . $woo_metabox["name"] . '" />';
            $output .= '<span class="woo_metabox_desc" style="display:inline">' . $woo_metabox['desc'] . '</span></td></td><td></td>' . "\n";
            $output .= "\t" . '</tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'radio') {
            $array = $woo_metabox['options'];
            if ($array) {
                $output .= "\t" . '<tr>';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td>';
                foreach ($array as $id => $option) {
                    if ($woo_metaboxvalue == $option) {
                        $checked = ' checked';
                    } else {
                        $checked = '';
                    }
                    $output .= '<input type="radio" ' . $checked . ' value="' . $id . '" class="woo_input_radio"  id="' . $woo_id . '" name="woothemes_' . $woo_metabox["name"] . '" />';
                    $output .= '<span class="woo_input_radio_desc" style="display:inline">' . $option . '</span><div class="woo_spacer"></div>';
                }
                $output .= '</td></td><td></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            }
        } elseif ($woo_metabox['type'] == 'upload') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td class="woo_metabox_fields">' . woothemes_uploader_custom_fields($post->ID, $woo_metabox["name"], $woo_metabox["default"], $woo_metabox["desc"]);
            $output .= '</td>' . "\n";
            $output .= "\t" . '</tr>' . "\n";
        }
    }
    $output .= '</table>' . "\n\n";
    echo $output;
}
Ejemplo n.º 3
0
function woothemes_metabox_create()
{
    global $post;
    $woo_metaboxes = get_option('woo_custom_template');
    $seo_metaboxes = get_option('woo_custom_seo_template');
    if (!empty($seo_metaboxes)) {
        $woo_metaboxes = array_merge($woo_metaboxes, $seo_metaboxes);
    }
    $output = '';
    $output .= '<table class="woo_metaboxes_table">' . "\n";
    foreach ($woo_metaboxes as $woo_metabox) {
        $woo_id = "woothemes_" . $woo_metabox["name"];
        $woo_name = $woo_metabox["name"];
        if ($woo_metabox['type'] == 'text' or $woo_metabox['type'] == 'select' or $woo_metabox['type'] == 'checkbox' or $woo_metabox['type'] == 'textarea' or $woo_metabox['type'] == 'calendar' or $woo_metabox['type'] == 'time' or $woo_metabox['type'] == 'radio' or $woo_metabox['type'] == 'images') {
            $woo_metaboxvalue = get_post_meta($post->ID, $woo_name, true);
        }
        if (empty($woo_metaboxvalue) && isset($woo_metabox['std'])) {
            $woo_metaboxvalue = $woo_metabox['std'];
        }
        if ($woo_metabox['type'] == 'text') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><input class="woo_input_text" type="' . $woo_metabox['type'] . '" value="' . $woo_metaboxvalue . '" name="' . $woo_name . '" id="' . $woo_id . '"/>';
            $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
            $output .= "\t" . '<td></td></tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'textarea') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_metabox . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><textarea class="woo_input_textarea" name="' . $woo_name . '" id="' . $woo_id . '">' . $woo_metaboxvalue . '</textarea>';
            $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
            $output .= "\t" . '<td></td></tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'calendar') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_metabox . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><input class="woo_input_calendar" type="text" name="' . $woo_name . '" id="' . $woo_id . '" value="' . $woo_metaboxvalue . '">';
            $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
            $output .= "\t" . '<td></td></tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'time') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><input class="woo_input_time" type="' . $woo_metabox['type'] . '" value="' . $woo_metaboxvalue . '" name="' . $woo_name . '" id="' . $woo_id . '"/>';
            $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td>' . "\n";
            $output .= "\t" . '<td></td></tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'select') {
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><select class="woo_input_select" id="' . $woo_id . '" name="' . $woo_name . '">';
            $output .= '<option value="">Select to return to default</option>';
            $array = $woo_metabox['options'];
            if ($array) {
                foreach ($array as $id => $option) {
                    $selected = '';
                    if (isset($woo_metabox['default'])) {
                        if ($woo_metabox['default'] == $option && empty($woo_metaboxvalue)) {
                            $selected = 'selected="selected"';
                        } else {
                            $selected = '';
                        }
                    }
                    if ($woo_metaboxvalue == $option) {
                        $selected = 'selected="selected"';
                    } else {
                        $selected = '';
                    }
                    $output .= '<option value="' . $option . '" ' . $selected . '>' . $option . '</option>';
                }
            }
            $output .= '</select><span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td></td><td></td>' . "\n";
            $output .= "\t" . '</tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'checkbox') {
            if ($woo_metaboxvalue == 'true') {
                $checked = ' checked="checked"';
            } else {
                $checked = '';
            }
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td><input type="checkbox" ' . $checked . ' class="woo_input_checkbox" value="true"  id="' . $woo_id . '" name="' . $woo_name . '" />';
            $output .= '<span class="woo_metabox_desc" style="display:inline">' . $woo_metabox['desc'] . '</span></td></td><td></td>' . "\n";
            $output .= "\t" . '</tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'radio') {
            $array = $woo_metabox['options'];
            if ($array) {
                $output .= "\t" . '<tr>';
                $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
                $output .= "\t\t" . '<td>';
                foreach ($array as $id => $option) {
                    if ($woo_metaboxvalue == $id) {
                        $checked = ' checked';
                    } else {
                        $checked = '';
                    }
                    $output .= '<input type="radio" ' . $checked . ' value="' . $id . '" class="woo_input_radio"  name="' . $woo_name . '" />';
                    $output .= '<span class="woo_input_radio_desc" style="display:inline">' . $option . '</span><div class="woo_spacer"></div>';
                }
                $output .= '</td></td><td></td>' . "\n";
                $output .= "\t" . '</tr>' . "\n";
            }
        } elseif ($woo_metabox['type'] == 'images') {
            $i = 0;
            $select_value = '';
            $layout = '';
            foreach ($woo_metabox['options'] as $key => $option) {
                $i++;
                $checked = '';
                $selected = '';
                if ($woo_metaboxvalue != '') {
                    if ($woo_metaboxvalue == $key) {
                        $checked = ' checked';
                        $selected = 'woo-meta-radio-img-selected';
                    }
                } else {
                    if ($option['std'] == $key) {
                        $checked = ' checked';
                    } elseif ($i == 1) {
                        $checked = ' checked';
                        $selected = 'woo-meta-radio-img-selected';
                    } else {
                        $checked = '';
                    }
                }
                $layout .= '<div class="woo-meta-radio-img-label">';
                $layout .= '<input type="radio" id="woo-meta-radio-img-' . $woo_name . $i . '" class="checkbox woo-meta-radio-img-radio" value="' . $key . '" name="' . $woo_name . '" ' . $checked . ' />';
                $layout .= '&nbsp;' . $key . '<div class="woo_spacer"></div></div>';
                $layout .= '<img src="' . $option . '" alt="" class="woo-meta-radio-img-img ' . $selected . '" onClick="document.getElementById(\'woo-meta-radio-img-' . $woo_metabox["name"] . $i . '\').checked = true;" />';
            }
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td class="woo_metabox_fields">';
            $output .= $layout;
            $output .= '<span class="woo_metabox_desc">' . $woo_metabox['desc'] . '</span></td></td><td></td>' . "\n";
            $output .= '</td>' . "\n";
            $output .= "\t" . '</tr>' . "\n";
        } elseif ($woo_metabox['type'] == 'upload') {
            if (isset($woo_metabox["default"])) {
                $default = $woo_metabox["default"];
            } else {
                $default = '';
            }
            $output .= "\t" . '<tr>';
            $output .= "\t\t" . '<th class="woo_metabox_names"><label for="' . $woo_id . '">' . $woo_metabox['label'] . '</label></th>' . "\n";
            $output .= "\t\t" . '<td class="woo_metabox_fields">' . woothemes_uploader_custom_fields($post->ID, $woo_name, $default, $woo_metabox["desc"]);
            $output .= '</td>' . "\n";
            $output .= "\t" . '</tr>' . "\n";
        }
    }
    $output .= '</table>' . "\n\n";
    echo $output;
}
Ejemplo n.º 4
0
function woothemes_metabox_create($post,$callback) {
    global $post;

    $template_to_show = $callback['args'];

    $woo_metaboxes = get_option( 'woo_custom_template' );

    $seo_metaboxes = get_option( 'woo_custom_seo_template' );

    if(empty($seo_metaboxes) AND $template_to_show == 'seo'){
    	return;
    }
    if(get_option( 'seo_woo_hide_fields') != 'true' AND $template_to_show == 'seo'){
    	$woo_metaboxes = $seo_metaboxes;
    }

    $output = '';
    $output .= '<table class="woo_metaboxes_table">'."\n";
    foreach ($woo_metaboxes as $woo_metabox) {
    	$woo_id = "woothemes_" . $woo_metabox["name"];
    	$woo_name = $woo_metabox["name"];

    	if ($template_to_show == 'seo') {
    		$metabox_post_type_restriction = 'undefined';
    	} elseif (function_exists( 'woothemes_content_builder_menu')) {
    		$metabox_post_type_restriction = $woo_metabox['cpt'][$post->post_type];
    	} else {
    		$metabox_post_type_restriction = 'undefined';
    	}

    	if ( ($metabox_post_type_restriction != '') && ($metabox_post_type_restriction == 'true') ) {
    		$type_selector = true;
    	} elseif ($metabox_post_type_restriction == 'undefined') {
    		$type_selector = true;
    	} else {
    		$type_selector = false;
    	}

   		$woo_metaboxvalue = '';

    	if ($type_selector) {

    		if(
        	        $woo_metabox['type'] == 'text'
			OR      $woo_metabox['type'] == 'select'
			OR      $woo_metabox['type'] == 'select2'
			OR      $woo_metabox['type'] == 'checkbox'
			OR      $woo_metabox['type'] == 'textarea'
			OR      $woo_metabox['type'] == 'calendar'
			OR      $woo_metabox['type'] == 'time'
			OR      $woo_metabox['type'] == 'radio'
			OR      $woo_metabox['type'] == 'images') {

        	    	$woo_metaboxvalue = get_post_meta($post->ID,$woo_name,true);

				}
				
				// Make sure slashes are stripped before output.
				foreach ( array( 'label', 'desc', 'std' ) as $k ) {
					if ( isset( $woo_metabox[$k] ) && ( $woo_metabox[$k] != '' ) ) {
						$woo_metabox[$k] = stripslashes( $woo_metabox[$k] );
					}
				}
				
        	    if ( $woo_metaboxvalue == '' && isset( $woo_metabox['std'] ) ) {

        	        $woo_metaboxvalue = $woo_metabox['std'];
        	    } 
        	    
				if($woo_metabox['type'] == 'info'){

        	        $output .= "\t".'<tr style="background:#f8f8f8; font-size:11px; line-height:1.5em;">';
        	        $output .= "\t\t".'<th class="woo_metabox_names"><label for="'. esc_attr( $woo_id ) .'">'.$woo_metabox['label'].'</label></th>'."\n";
        	        $output .= "\t\t".'<td style="font-size:11px;">'.$woo_metabox['desc'].'</td>'."\n";
        	        $output .= "\t".'</tr>'."\n";

        	    }
        	    elseif($woo_metabox['type'] == 'text'){

        	    	$add_class = ''; $add_counter = '';
        	    	if($template_to_show == 'seo'){$add_class = 'words-count'; $add_counter = '<span class="counter">0 characters, 0 words</span>';}
        	        $output .= "\t".'<tr>';
        	        $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.esc_attr( $woo_id ).'">'.$woo_metabox['label'].'</label></th>'."\n";
        	        $output .= "\t\t".'<td><input class="woo_input_text '.$add_class.'" type="'.$woo_metabox['type'].'" value="'.esc_attr( $woo_metaboxvalue ).'" name="'.$woo_name.'" id="'.esc_attr( $woo_id ).'"/>';
        	        $output .= '<span class="woo_metabox_desc">'.$woo_metabox['desc'] .' '. $add_counter .'</span></td>'."\n";
        	        $output .= "\t".'</tr>'."\n";

        	    }

        	    elseif ($woo_metabox['type'] == 'textarea'){

        	   		$add_class = ''; $add_counter = '';
        	    	if( $template_to_show == 'seo' ){ $add_class = 'words-count'; $add_counter = '<span class="counter">0 characters, 0 words</span>'; }
        	        $output .= "\t".'<tr>';
        	        $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.$woo_metabox.'">'.$woo_metabox['label'].'</label></th>'."\n";
        	        $output .= "\t\t".'<td><textarea class="woo_input_textarea '.$add_class.'" name="'.$woo_name.'" id="'.esc_attr( $woo_id ).'">' . esc_textarea(stripslashes($woo_metaboxvalue)) . '</textarea>';
        	        $output .= '<span class="woo_metabox_desc">'.$woo_metabox['desc'] .' '. $add_counter.'</span></td>'."\n";
        	        $output .= "\t".'</tr>'."\n";

        	    }

        	    elseif ($woo_metabox['type'] == 'calendar'){

        	        $output .= "\t".'<tr>';
        	        $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.$woo_metabox.'">'.$woo_metabox['label'].'</label></th>'."\n";
        	        $output .= "\t\t".'<td><input class="woo_input_calendar" type="text" name="'.$woo_name.'" id="'.esc_attr( $woo_id ).'" value="'.esc_attr( $woo_metaboxvalue ).'">';
        	        $output .= '<span class="woo_metabox_desc">'.$woo_metabox['desc'].'</span></td>'."\n";
        	        $output .= "\t".'</tr>'."\n";

        	    }

        	    elseif ($woo_metabox['type'] == 'time'){

        	        $output .= "\t".'<tr>';
        	        $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.esc_attr( $woo_id ).'">'.$woo_metabox['label'].'</label></th>'."\n";
        	        $output .= "\t\t".'<td><input class="woo_input_time" type="'.$woo_metabox['type'].'" value="'.esc_attr( $woo_metaboxvalue ).'" name="'.$woo_name.'" id="'.esc_attr( $woo_id ).'"/>';
        	        $output .= '<span class="woo_metabox_desc">'.$woo_metabox['desc'].'</span></td>'."\n";
        	        $output .= "\t".'</tr>'."\n";

        	    }

        	    elseif ($woo_metabox['type'] == 'select'){

        	        $output .= "\t".'<tr>';
        	        $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.esc_attr( $woo_id ).'">'.$woo_metabox['label'].'</label></th>'."\n";
        	        $output .= "\t\t".'<td><select class="woo_input_select" id="'.esc_attr( $woo_id ).'" name="'. esc_attr( $woo_name ) .'">';
        	        $output .= '<option value="">Select to return to default</option>';

        	        $array = $woo_metabox['options'];

        	        if($array){

        	            foreach ( $array as $id => $option ) {
        	                $selected = '';

        	                if(isset($woo_metabox['default']))  {
								if($woo_metabox['default'] == $option && empty($woo_metaboxvalue)){$selected = 'selected="selected"';}
								else  {$selected = '';}
							}

        	                if($woo_metaboxvalue == $option){$selected = 'selected="selected"';}
        	                else  {$selected = '';}

        	                $output .= '<option value="'. esc_attr( $option ) .'" '. $selected .'>' . $option .'</option>';
        	            }
        	        }

        	        $output .= '</select><span class="woo_metabox_desc">'.$woo_metabox['desc'].'</span></td>'."\n";
        	        $output .= "\t".'</tr>'."\n";
        	    }
        	    elseif ($woo_metabox['type'] == 'select2'){

        	        $output .= "\t".'<tr>';
        	        $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.esc_attr( $woo_id ).'">'.$woo_metabox['label'].'</label></th>'."\n";
        	        $output .= "\t\t".'<td><select class="woo_input_select" id="'.esc_attr( $woo_id ).'" name="'. esc_attr( $woo_name ) .'">';
        	        $output .= '<option value="">Select to return to default</option>';

        	        $array = $woo_metabox['options'];

        	        if($array){

        	            foreach ( $array as $id => $option ) {
        	                $selected = '';

        	                if(isset($woo_metabox['default']))  {
								if($woo_metabox['default'] == $id && empty($woo_metaboxvalue)){$selected = 'selected="selected"';}
								else  {$selected = '';}
							}

        	                if($woo_metaboxvalue == $id){$selected = 'selected="selected"';}
        	                else  {$selected = '';}

        	                $output .= '<option value="'. esc_attr( $id ) .'" '. $selected .'>' . $option .'</option>';
        	            }
        	        }

        	        $output .= '</select><span class="woo_metabox_desc">'.$woo_metabox['desc'].'</span></td>'."\n";
        	        $output .= "\t".'</tr>'."\n";
        	    }

        	    elseif ($woo_metabox['type'] == 'checkbox'){

        	        if($woo_metaboxvalue == 'true') { $checked = ' checked="checked"';} else {$checked='';}

        	        $output .= "\t".'<tr>';
        	        $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.esc_attr( $woo_id ).'">'.$woo_metabox['label'].'</label></th>'."\n";
        	        $output .= "\t\t".'<td><input type="checkbox" '.$checked.' class="woo_input_checkbox" value="true"  id="'.esc_attr( $woo_id ).'" name="'. esc_attr( $woo_name ) .'" />';
        	        $output .= '<span class="woo_metabox_desc" style="display:inline">'.$woo_metabox['desc'].'</span></td>'."\n";
        	        $output .= "\t".'</tr>'."\n";
        	    }

        	    elseif ($woo_metabox['type'] == 'radio'){

        	    $array = $woo_metabox['options'];

        	    if($array){

        	    $output .= "\t".'<tr>';
        	    $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.esc_attr( $woo_id ).'">'.$woo_metabox['label'].'</label></th>'."\n";
        	    $output .= "\t\t".'<td>';

        	        foreach ( $array as $id => $option ) {

        	            if($woo_metaboxvalue == $id) { $checked = ' checked';} else {$checked='';}

        	                $output .= '<input type="radio" '.$checked.' value="' . $id . '" class="woo_input_radio"  name="'. esc_attr( $woo_name ) .'" />';
        	                $output .= '<span class="woo_input_radio_desc" style="display:inline">'. $option .'</span><div class="woo_spacer"></div>';
        	            }
        	            $output .= "\t".'</tr>'."\n";
        	         }
        	    }
				elseif ($woo_metabox['type'] == 'images')
				{

				$i = 0;
				$select_value = '';
				$layout = '';

				foreach ($woo_metabox['options'] as $key => $option)
					 {
					 $i++;

					 $checked = '';
					 $selected = '';
					 if($woo_metaboxvalue != '') {
					 	if ($woo_metaboxvalue == $key) { $checked = ' checked'; $selected = 'woo-meta-radio-img-selected'; }
					 }
					 else {
					 	if ($option['std'] == $key) { $checked = ' checked'; }
						elseif ($i == 1) { $checked = ' checked'; $selected = 'woo-meta-radio-img-selected'; }
						else { $checked=''; }

					 }

						$layout .= '<div class="woo-meta-radio-img-label">';
						$layout .= '<input type="radio" id="woo-meta-radio-img-' . $woo_name . $i . '" class="checkbox woo-meta-radio-img-radio" value="'.esc_attr($key).'" name="'. $woo_name.'" '.$checked.' />';
						$layout .= '&nbsp;' . esc_html($key) .'<div class="woo_spacer"></div></div>';
						$layout .= '<img src="'.esc_url( $option ).'" alt="" class="woo-meta-radio-img-img '. $selected .'" onClick="document.getElementById(\'woo-meta-radio-img-'. esc_js($woo_metabox["name"] . $i).'\').checked = true;" />';
					}

				$output .= "\t".'<tr>';
				$output .= "\t\t".'<th class="woo_metabox_names"><label for="'.esc_attr( $woo_id ).'">'.$woo_metabox['label'].'</label></th>'."\n";
				$output .= "\t\t".'<td class="woo_metabox_fields">';
				$output .= $layout;
				$output .= '<span class="woo_metabox_desc">'.$woo_metabox['desc'].'</span></td>'."\n";
        	    $output .= "\t".'</tr>'."\n";

				}

        	    elseif($woo_metabox['type'] == 'upload')
        	    {
					if(isset($woo_metabox["default"])) $default = $woo_metabox["default"];
					else $default = '';

        	    	// Add support for the WooThemes Media Library-driven Uploader Module // 2010-11-09.
        	    	if ( function_exists( 'woothemes_medialibrary_uploader' ) ) {

        	    		$_value = $default;

        	    		$_value = get_post_meta( $post->ID, $woo_metabox["name"], true );

        	    		$output .= "\t".'<tr>';
	    	            $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.$woo_metabox["name"].'">'.$woo_metabox['label'].'</label></th>'."\n";
	    	            $output .= "\t\t".'<td class="woo_metabox_fields">'. woothemes_medialibrary_uploader( $woo_metabox["name"], $_value, 'postmeta', $woo_metabox["desc"], $post->ID );
	    	            $output .= '</td>'."\n";
	    	            $output .= "\t".'</tr>'."\n";

        	    	} else {

	    	            $output .= "\t".'<tr>';
	    	            $output .= "\t\t".'<th class="woo_metabox_names"><label for="'.esc_attr( $woo_id ).'">'.$woo_metabox['label'].'</label></th>'."\n";
	    	            $output .= "\t\t".'<td class="woo_metabox_fields">'. woothemes_uploader_custom_fields($post->ID,$woo_name,$default,$woo_metabox["desc"]);
	    	            $output .= '</td>'."\n";
	    	            $output .= "\t".'</tr>'."\n";

        	        } // End IF Statement

        	    }
        }	// End IF Statement
    }

    $output .= '</table>'."\n\n";
    echo $output;
}