コード例 #1
0
    /**
     * Renders option
     *
     * @access public
     * @param array $option
     * @return string
     */
    public static function renderOption($option)
    {
        /*var_dump($option);*/
        global $post, $wp_registered_sidebars, $wp_locale;
        $out = '';
        //option wrapper
        if (!isset($option['wrap']) || $option['wrap']) {
            $parent = '';
            if (isset($option['parent'])) {
                $parent = 'data-parent="' . MTHEME_PREFIX . $option['parent']['id'] . '" ';
                $parent .= 'data-value="' . $option['parent']['value'] . '"';
            }
            if (isset($option['group']) && $option['group'] == 'multiple') {
                $out .= '<div class="mtheme-multiple-option mtheme-' . str_replace('_', '-', $option['type']) . '" ' . $parent . '>';
            } else {
                $out .= '<div class="mtheme-option mtheme-' . str_replace('_', '-', $option['type']) . '" ' . $parent . '>';
            }
            if (isset($option['name']) && $option['type'] != 'checkbox') {
                $out .= '<h3 class="mtheme-option-title">' . $option['name'] . '</h3>';
            }
        }
        //option before
        if (isset($option['before'])) {
            $out .= $option['before'];
        }
        //option description
        if (isset($option['description'])) {
            $out .= '<div class="mtheme-tooltip"><div class="mtheme-tooltip-icon"></div><div class="mtheme-tooltip-text">' . $option['description'] . '</div></div>';
        }
        //option attributes
        $attributes = '';
        if (isset($option['attributes'])) {
            foreach ($option['attributes'] as $name => $value) {
                $attributes .= $name . '="' . $value . '" ';
            }
        }
        //option value
        if (!isset($option['value'])) {
            $option['value'] = '';
            if (isset($option['id'])) {
                $option['value'] = mtheme_stripslashes(get_option($option['id']));
                if (($option['value'] === false || $option['value'] == '') && isset($option['default'])) {
                    $option['value'] = mtheme_stripslashes($option['default']);
                }
            } else {
                if (isset($option['default'])) {
                    $option['value'] = mtheme_stripslashes($option['default']);
                }
            }
        }
        switch ($option['type']) {
            //text field
            case 'text':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $out .= '<input type="text" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />';
                break;
                //number field
            //number field
            case 'number':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $out .= '<input type="text" maxlength="12" onkeypress="return isNumberKey(event)" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />';
                break;
                //date field
            //date field
            case 'date':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $out .= '<input type="text" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" class="date-field" ' . $attributes . ' />';
                break;
                //hidden field
            //hidden field
            case 'hidden':
                $out .= '<input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />';
                break;
                //icon_picker field
            //icon_picker field
            case 'icon_picker':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $v = "";
                if (isset($option['value']) && !empty($option['value'])) {
                    $v = explode('|', $option['value']);
                    $v = $v[0] . ' ' . $v[1];
                }
                $out .= '<input class="regular-text" type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '"/>';
                $out .= '<div id="mtheme_icon_picker_' . $option['id'] . '" data-target="#' . $option['id'] . '" class="button icon-picker ' . $v . '" ' . $attributes . ' ></div>';
                break;
                //message field
            //message field
            case 'textarea':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $out .= '<textarea id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . '>' . $option['value'] . '</textarea>';
                break;
                //checkbox
            //checkbox
            case 'checkbox':
                if (isset($option['default']) && empty($option['value'])) {
                    $option['value'] = $option['default'];
                }
                /*var_dump($option);*/
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                if (isset($option['defendency-set'])) {
                    $attributes .= ' data-defendency="' . $option['defendency-set'] . '" ';
                }
                $checked = '';
                if ($option['value'] == 'true') {
                    $checked = 'checked="checked"';
                }
                $out .= '<input type="checkbox" id="' . $option['id'] . '" name="' . $option['id'] . '" value="true" ' . $checked . ' ' . $attributes . ' />';
                if (isset($option['name'])) {
                    $out .= '<label for="' . $option['id'] . '">' . $option['name'] . '</label>';
                }
                break;
                //colorpicker
            //colorpicker
            case 'color':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $out .= '<input name="' . $option['id'] . '" id="' . $option['id'] . '" type="text" value="' . $option['value'] . '" class="mtheme-colorpicker" ' . $attributes . ' />';
                break;
                //uploader
            //uploader
            case 'uploader':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $out .= '<input name="' . $option['id'] . '" id="' . $option['id'] . '" type="text" value="' . $option['value'] . '" ' . $attributes . ' />';
                $out .= '<a class="button mtheme-upload-button">' . __('Browse', 'mtheme') . '</a>';
                break;
                //multiple uploader
            //multiple uploader
            case 'attachments':
                if (empty($option['value']) || !is_array($option['value'])) {
                    $option['value'] = array('a' . uniqid() => array('title' => '', 'url' => '', 'type' => ''));
                }
                $out .= '<div class="mtheme-clone-pane"><input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="" />';
                foreach ($option['value'] as $key => $field) {
                    $out .= '<div class="mtheme-clone-item" id="' . $option['id'] . '_' . $key . '">';
                    $out .= '<a href="#" class="mtheme-button mtheme-remove-button mtheme-trigger" data-element="' . $option['id'] . '_' . $key . '" title="' . __('Remove', 'mtheme') . '"></a>';
                    $out .= '<a href="#" class="mtheme-button mtheme-clone-button mtheme-trigger" data-element="' . $option['id'] . '_' . $key . '" data-value="' . $key . '" title="' . __('Add', 'mtheme') . '"></a>';
                    $out .= MthemeInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][title]', 'type' => 'text', 'value' => mtheme_value($field, 'title'), 'wrap' => false, 'attributes' => array('placeholder' => __('Title', 'mtheme'))));
                    $out .= MthemeInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][type]', 'type' => 'select', 'value' => mtheme_value($field, 'type'), 'wrap' => false, 'options' => array('document' => __('Document', 'mtheme'), 'audio' => __('Audio', 'mtheme'), 'video' => __('Video', 'mtheme'))));
                    $out .= MthemeInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][status]', 'type' => 'select', 'value' => mtheme_value($field, 'status'), 'wrap' => false, 'options' => array('file' => __('File', 'mtheme'), 'link' => __('Link', 'mtheme'))));
                    $out .= MthemeInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][url]', 'type' => 'uploader', 'value' => mtheme_value($field, 'url'), 'attributes' => array('placeholder' => 'URL')));
                    $out .= '</div>';
                }
                $out .= '</div>';
                break;
                //images selector
            //images selector
            case 'select_image':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                foreach ($option['options'] as $name => $src) {
                    $out .= '<image src="' . $src . '" ';
                    if ($name == $option['value']) {
                        $out .= 'class="current"';
                    }
                    $out .= ' data-value="' . $name . '" />';
                }
                $out .= '<input type="hidden" name="' . $option['id'] . '" id="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />';
                break;
                //custom dropdown
            //custom dropdown
            case 'select':
                if (isset($option['default']) && empty($option['value'])) {
                    $option['value'] = $option['default'];
                }
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                if (isset($option['defendency-set'])) {
                    $attributes .= ' data-defendency="' . $option['defendency-set'] . '" ';
                }
                $out .= '<select id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . ' autocomplete="off">';
                if (isset($option['options'])) {
                    foreach ($option['options'] as $name => $title) {
                        $selected = '';
                        if ($option['value'] != '' && ($name == $option['value'] || is_array($option['value']) && in_array($name, $option['value']))) {
                            $selected = 'selected="selected"';
                        }
                        $out .= '<option value="' . $name . '" ' . $selected . '>' . $title . '</option>';
                    }
                }
                $out .= '</select>';
                break;
                //fonts dropdown
            //fonts dropdown
            case 'select_font':
                $options = MthemeCore::$components['fonts'];
                asort($options);
                $out .= self::renderOption(array('id' => $option['id'], 'type' => 'select', 'wrap' => false, 'default' => $option['value'], 'options' => $options));
                break;
                //pages dropdown
            //pages dropdown
            case 'select_page':
                $args = array('selected' => $option['value'], 'echo' => 0, 'name' => $option['id'], 'id' => $option['id']);
                $out .= wp_dropdown_pages($args);
                break;
                //posts dropdown
            //posts dropdown
            case 'select_post':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $atts = array('numberposts' => -1, 'post_type' => $option['post_type'], 'post_status' => array('publish', 'future', 'pending', 'draft'), 'orderby' => 'title', 'order' => 'ASC');
                if ($option['post_type'] != 'product' && !current_user_can('manage_options')) {
                    $atts['author'] = get_current_user_id();
                }
                $items = get_posts($atts);
                $out .= '<select id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . '>';
                $out .= '<option value="0">' . __('None', 'mtheme') . '</option>';
                foreach ($items as $item) {
                    $selected = '';
                    if ($item->ID == $option['value']) {
                        $selected = 'selected="selected"';
                    }
                    $out .= '<option value="' . $item->ID . '" ' . $selected . '>' . $item->post_title . '</option>';
                }
                $out .= '</select>';
                break;
                //multiple posts dropdown
            //multiple posts dropdown
            case 'select_multiple_post':
                global $post;
                $data = get_post_meta($post->ID, $option['input_id'], false);
                echo '<div class="custom-mtheme-option">';
                echo '<ul id="' . $option['input_id'] . '_items">';
                $c = 0;
                if (!empty($data)) {
                    foreach ((array) $data as $p) {
                        echo ajax_show_multiple_select($c, $option, $p);
                        $c++;
                    }
                }
                echo '</ul>';
                ?>
				<span class="add_<?php 
                echo esc_attr($option['input_id']);
                ?>
 button"><?php 
                echo __('Add', 'mtheme');
                ?>
</span>
				<script>
					var $ =jQuery.noConflict();
					$(document).ready(function() {
						var count = <?php 
                echo esc_attr($c - 1);
                ?>
; 
						$(".add_<?php 
                echo esc_attr($option['input_id']);
                ?>
").click(function() {
						count = count + 1;
						$('#<?php 
                echo esc_attr($option['input_id'] . '_items');
                ?>
').append('<?php 
                echo ajax_show_multiple_select('count', $option);
                ?>
'.replace(/count/g, count));
						return false;
						});
						$(".remove_<?php 
                echo esc_attr($option['input_id']);
                ?>
").live('click', function() {
							$(this).parent().remove();
						});
					});
				</script>
				<style>#<?php 
                echo esc_attr($option['input_id'] . '_items');
                ?>
 {list-style: none;}</style>
				<?php 
                echo '</div>';
                break;
                //sidebars dropdown
            //sidebars dropdown
            case 'select_sidebar':
                $sidebars = array();
                foreach ($wp_registered_sidebars as $sidebar) {
                    $sidebars[$sidebar['name']] = $sidebar['name'];
                }
                $out .= self::renderOption(array('id' => $option['id'], 'type' => 'select', 'wrap' => false, 'options' => $sidebars));
                break;
                //categories dropdown
            //categories dropdown
            case 'select_category':
                if (isset($option['defendency'])) {
                    $attributes .= ' data-defendency-show="' . $option['defendency']['show'] . '" data-defendency-set="' . $option['defendency']['base'] . '_' . $option['defendency']['id'] . '_' . $option['defendency']['value'] . '" data-parent="' . $option['defendency']['parent'] . '" ';
                }
                $args = array('hide_empty' => 0, 'echo' => 0, 'selected' => $option['value'], 'show_option_all' => __('None', 'mtheme'), 'hierarchical' => 0, 'name' => $option['id'], 'id' => $option['id'], 'depth' => 0, 'tab_index' => 0, 'taxonomy' => $option['taxonomy'], 'hide_if_empty' => false);
                if (isset($option['attributes'])) {
                    $args['class'] = $option['attributes']['class'];
                }
                $out .= '<div' . $attributes . '>';
                $out .= wp_dropdown_categories($args);
                $out .= '</div>';
                break;
                //range slider
            //range slider
            case 'slider':
                $out .= '<div class="mtheme-slider-controls"></div><div class="mtheme-slider-value"></div>';
                $out .= '<input type="hidden" class="slider-max" value="' . $option['max_value'] . '" />';
                $out .= '<input type="hidden" class="slider-min" value="' . $option['min_value'] . '" />';
                $out .= '<input type="hidden" class="slider-unit" value="' . $option['unit'] . '" />';
                $out .= '<input type="hidden" class="slider-value" name="' . $option['id'] . '" id="' . $option['id'] . '"  value="' . $option['value'] . '" />';
                break;
                /*section_menu*/
            /*section_menu*/
            case 'section_menu':
                if (empty($option['value']) || !is_array($option['value'])) {
                    $option['value'] = array('s' . uniqid() => array('title' => '', 'type' => ''));
                }
                $out .= '<div class="mtheme-clone-pane"><input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="" />';
                foreach ($option['value'] as $key => $field) {
                    $out .= '<div class="mtheme-clone-item" id="' . $option['id'] . '_' . $key . '">';
                    $out .= '<a href="#" class="mtheme-button mtheme-remove-button mtheme-trigger" data-element="' . $option['id'] . '_' . $key . '" title="' . __('Remove', 'mtheme') . '"></a>';
                    $out .= '<a href="#" class="mtheme-button mtheme-clone-button mtheme-trigger" data-value="' . $key . '" title="' . __('Add', 'mtheme') . '"></a>';
                    $out .= MthemeInterface::renderOption(array('name' => __('Menu link type', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][name]', 'type' => 'select', 'options' => array('internal' => __('Menu Link - Internal', 'mtheme'), 'external' => __('Menu Link - External', 'mtheme')), 'attributes' => array('placeholder' => __('Section link type', 'mtheme')), 'value' => htmlspecialchars(mtheme_value($field, 'name')), 'wrap' => true, 'group' => 'multiple', 'default' => 'internal'));
                    $out .= MthemeInterface::renderOption(array('name' => __('Menu Heading', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][menu_heading]', 'type' => 'text', 'attributes' => array('placeholder' => __('Menu Heading', 'mtheme')), 'value' => htmlspecialchars(mtheme_value($field, 'menu_heading')), 'wrap' => true, 'group' => 'multiple', 'description' => 'If Menu heading is empty, only section has to added in the page'));
                    $out .= MthemeInterface::renderOption(array('name' => __('External menu link', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][external_link]', 'type' => 'text', 'attributes' => array('placeholder' => __('External menu link', 'mtheme')), 'value' => htmlspecialchars(mtheme_value($field, 'external_link')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Please enter external link. Only menu link has get display'));
                    $out .= MthemeInterface::renderOption(array('name' => __('Internal Section Content', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][content]', 'type' => 'textarea', 'attributes' => array('placeholder' => __('Section Content', 'mtheme')), 'value' => htmlspecialchars(mtheme_value($field, 'content')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Please enter section shortcodes.'));
                    $out .= '</div>';
                }
                $out .= '</div>';
                break;
                /*schedule*/
            /*schedule*/
            case 'schedule':
                if (empty($option['value']) || !is_array($option['value'])) {
                    $option['value'] = array('s' . uniqid() => array('title' => '', 'type' => ''));
                }
                $out .= '<div class="mtheme-clone-pane"><input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="" />';
                foreach ($option['value'] as $key => $field) {
                    $out .= '<div class="mtheme-clone-item" id="' . $option['id'] . '_' . $key . '">';
                    $out .= '<a href="#" class="mtheme-button mtheme-remove-button mtheme-trigger" data-element="' . $option['id'] . '_' . $key . '" title="' . __('Remove', 'mtheme') . '"></a>';
                    $out .= '<a href="#" class="mtheme-button mtheme-clone-button mtheme-trigger" data-value="' . $key . '" title="' . __('Add', 'mtheme') . '"></a>';
                    $out .= MthemeInterface::renderOption(array('name' => __('Accordion Active', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][active]', 'type' => 'select', 'value' => htmlspecialchars(mtheme_value($field, 'active')), 'options' => array('no' => __('Accordion Active - NO', 'mtheme'), 'yes' => __('Accordion Active - Yes', 'mtheme')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Is Accordion Active?', 'default' => 'no'));
                    $out .= MthemeInterface::renderOption(array('name' => __('Event Title', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][title]', 'type' => 'text', 'value' => htmlspecialchars(mtheme_value($field, 'title')), 'wrap' => false, 'attributes' => array('placeholder' => __('Event Title', 'mtheme')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Please enter Event Title.'));
                    $out .= MthemeInterface::renderOption(array('name' => __('Event Time', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][time]', 'type' => 'text', 'value' => htmlspecialchars(mtheme_value($field, 'time')), 'wrap' => false, 'attributes' => array('placeholder' => __('Event Time', 'mtheme')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Please enter Event Time.'));
                    $out .= MthemeInterface::renderOption(array('name' => __('Speaker Name', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][speaker]', 'type' => 'text', 'value' => htmlspecialchars(mtheme_value($field, 'speaker')), 'wrap' => false, 'attributes' => array('placeholder' => __('Event Speaker Name', 'mtheme')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Please enter Event Speaker Name.'));
                    $out .= MthemeInterface::renderOption(array('name' => __('Speaker Designation', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][designation]', 'type' => 'text', 'value' => htmlspecialchars(mtheme_value($field, 'designation')), 'wrap' => false, 'attributes' => array('placeholder' => __('Event Speaker Designation', 'mtheme')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Please enter Event Speaker Name.'));
                    $out .= MthemeInterface::renderOption(array('name' => __('Event Venue', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][venue]', 'type' => 'text', 'value' => htmlspecialchars(mtheme_value($field, 'venue')), 'wrap' => false, 'attributes' => array('placeholder' => __('Event Venue', 'mtheme')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Please enter Event Venue.'));
                    $out .= MthemeInterface::renderOption(array('name' => __('Description', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][description]', 'type' => 'textarea', 'value' => htmlspecialchars(mtheme_value($field, 'description')), 'wrap' => false, 'attributes' => array('placeholder' => __('Event Description', 'mtheme')), 'wrap' => true, 'group' => 'multiple', 'description' => 'Please enter Event Description.'));
                    $out .= '</div>';
                }
                $out .= '</div>';
                break;
                /*external_link*/
            /*external_link*/
            case 'external_link':
                if (empty($option['value']) || !is_array($option['value'])) {
                    $option['value'] = array('el' . uniqid() => array('title' => '', 'type' => ''));
                }
                $out .= '<div class="mtheme-clone-pane"><input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="" />';
                foreach ($option['value'] as $key => $field) {
                    $out .= '<div class="mtheme-clone-item" id="' . $option['id'] . '_' . $key . '">';
                    $out .= '<a href="#" class="mtheme-button mtheme-remove-button mtheme-trigger" data-element="' . $option['id'] . '_' . $key . '" title="' . __('Remove', 'mtheme') . '"></a>';
                    $out .= '<a href="#" class="mtheme-button mtheme-clone-button mtheme-trigger" data-value="' . $key . '" title="' . __('Add', 'mtheme') . '"></a>';
                    $out .= MthemeInterface::renderOption(array('name' => __('External Link Title', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][el_link_title]', 'type' => 'text', 'value' => htmlspecialchars(mtheme_value($field, 'el_link_title')), 'wrap' => true, 'attributes' => array('placeholder' => __('External Link Title', 'mtheme')), 'group' => 'multiple', 'description' => 'External Link Title'));
                    $out .= MthemeInterface::renderOption(array('name' => __('External Link URL', 'mtheme'), 'id' => $option['id'] . '[' . $key . '][el_link_url]', 'type' => 'text', 'value' => htmlspecialchars(mtheme_value($field, 'el_link_url')), 'wrap' => true, 'attributes' => array('placeholder' => __('External Link URL', 'mtheme')), 'group' => 'multiple', 'description' => 'External Link URL'));
                    $out .= '</div>';
                }
                $out .= '</div>';
                break;
                //users manager
            //users manager
            case 'users':
                $users = MthemeCore::getUserRelations(0, $post->ID, $post->post_type);
                $out .= '<div class="mtheme-row clearfix">';
                $out .= wp_dropdown_users(array('echo' => false, 'exclude' => $users, 'name' => 'add_user_id', 'id' => 'add_user_id'));
                $out .= '<input type="submit" name="add_user" class="button" value="' . __('Add', 'mtheme') . '" /></div>';
                if (!empty($users)) {
                    $out .= '<div class="mtheme-row clearfix">';
                    $out .= wp_dropdown_users(array('echo' => false, 'include' => $users, 'name' => 'remove_user_id', 'id' => 'remove_user_id'));
                    $out .= '<input type="submit" name="remove_user" class="button" value="' . __('Remove', 'mtheme') . '" /></div>';
                }
                break;
                //module settings
            //module settings
            case 'module':
                $out .= '<div class="' . substr(strtolower(implode('-', preg_split('/(?=[A-Z])/', str_replace(MTHEME_PREFIX, '', $option['id'])))), 1) . '">';
                if (isset($option['slug'])) {
                    $out .= call_user_func(array(str_replace(MTHEME_PREFIX, '', $option['id']), 'renderSettings'), $option['slug']);
                } else {
                    $out .= call_user_func(array(str_replace(MTHEME_PREFIX, '', $option['id']), 'renderSettings'));
                }
                $out .= '</div>';
                break;
        }
        //option after
        if (isset($option['after'])) {
            $out .= $option['after'];
        }
        //wrap option
        if (!isset($option['wrap']) || $option['wrap']) {
            $out .= '</div>';
        }
        return $out;
    }
コード例 #2
0
ファイル: mtheme.form.php プロジェクト: jaychow/sdmardigras
 /**
  * Renders contact form data
  *
  * @access public
  * @param string $slug
  * @param array $optionst
  * @param array $values
  * @return void
  */
 public static function renderContactForm($slug, $btitle, $secondary_color, $options = array(), $values = array())
 {
     $options = wp_parse_args($options, array('edit' => true, 'before_title' => '', 'after_title' => '', 'before_content' => '', 'after_content' => ''));
     $out = '';
     if (self::isActive($slug)) {
         foreach (self::$data[$slug]['fields'] as $field) {
             $ID = mtheme_sanitize_key($field['name']);
             $field['name'] = mtheme_get_string($ID, 'name', $field['name']);
             $field['options'] = mtheme_get_string($ID, 'options', $field['options']);
             $option = array('id' => $ID, 'name' => $field['name'], 'type' => $field['type'], 'label' => $field['label'], 'value' => mtheme_value($values, $ID), 'options' => $field['options']);
             /*var_dump($option);*/
             switch ($option['type']) {
                 //text field
                 case 'text':
                     $out .= $option['label'] . " ";
                     $out .= '<input type="text" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" placeholder="' . $option['options'] . '" data-subline="' . $option['options'] . '"/>';
                     break;
                     //email field
                 //email field
                 case 'email':
                     $out .= $option['label'] . " ";
                     $out .= '<input type="text" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" placeholder="' . $option['options'] . '" data-subline="' . $option['options'] . '" onkeypress="return isNumberKey(event)" />';
                     break;
                     //number field
                 //number field
                 case 'number':
                     $out .= $option['label'] . " ";
                     $out .= '<input type="text" maxlength="12" placeholder="' . $option['options'] . '" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" data-subline="' . $option['options'] . '" onkeypress="return isNumberKey(event)" />';
                     break;
                     //message field
                 //message field
                 case 'textarea':
                     if (empty($option['value'])) {
                         $option['value'] = " " . $option['options'];
                     }
                     $out .= $option['label'];
                     $out .= '<textarea id="' . $option['id'] . '" name="' . $option['id'] . '">' . $option['value'] . '</textarea>';
                     break;
                     /*custom dropdown*/
                 /*custom dropdown*/
                 case 'select':
                     $option['options'] = explode(',', $option['options']);
                     $out .= $option['label'] . " ";
                     $out .= '<select id="' . $option['id'] . '" name="' . $option['id'] . '">';
                     if (isset($option['options'])) {
                         foreach ($option['options'] as $name => $title) {
                             $selected = '';
                             if ($option['value'] != '' && ($name == $option['value'] || is_array($option['value']) && in_array($name, $option['value']))) {
                                 $selected = 'selected="selected"';
                             }
                             $out .= '<option value="' . $name . '" ' . $selected . '>' . $title . '</option>';
                         }
                     }
                     $out .= '</select>';
                     break;
             }
         }
         if ($options['edit'] && isset(self::$data[$slug]['captcha'])) {
             $out .= '<div class="clear"></div>';
             $out .= '<div class="form-captcha clearfix">';
             $out .= '<div class="captcha-left"><img src="' . MTHEME_URI . 'assets/images/captcha/captcha.php" alt="" /></div>';
             $out .= '<div class="captcha-right"><input type="text" name="captcha" id="captcha" size="6" value="" placeholder="' . __(' Code', 'mtheme') . '" /></div></div>';
         }
         $out .= '<div class="clear"></div>';
         if (isset($btitle) && !empty($btitle)) {
             $out .= '<div class="nl-submit-wrap"><button class="nl-submit submit-button btn-effect" type="submit" style="background: none repeat scroll 0 0 ' . esc_attr($secondary_color) . ';">' . esc_attr($btitle) . '</button></div>';
         } else {
             if (isset(self::$data[$slug]['btitle']) && !empty(self::$data[$slug]['btitle'])) {
                 $out .= '<div class="nl-submit-wrap"><button class="nl-submit submit-button btn-effect" type="submit" style="background: none repeat scroll 0 0 ' . esc_attr($secondary_color) . ';">' . esc_attr(self::$data[$slug]['btitle']) . '</button></div>';
             } else {
                 $out .= '<div class="nl-submit-wrap"><button class="nl-submit submit-button btn-effect" type="submit" style="background: none repeat scroll 0 0 ' . esc_attr($secondary_color) . ';">Submit</button></div>';
             }
         }
     }
     echo mtheme_html($out);
 }