Beispiel #1
0
    /**
     * Rendering Meta Interface
     * @access public
     * @since 1.0.0
     * @param array $meta_box
     * @return void
     *
     */
    function get_meta_interface($meta_box, $name_trailing = true)
    {
        $defaults = array('type' => '', 'std' => '', 'class' => '', 'title' => '', 'options' => '', 'repeat_num' => '', 'repeat_child' => '');
        $meta_box = wp_parse_args($meta_box, $defaults);
        extract($meta_box);
        $id = $name;
        if ($name_trailing) {
            $name = $name . '[]';
        }
        if (!empty($value)) {
            if (!is_array($value)) {
                $value = empty($value) ? esc_html($std) : esc_html($value);
            }
        } else {
            $value = esc_html($std);
        }
        switch ($meta_box['type']) {
            case "text":
                ?>
				<div class="bon-builder-meta-body">
					<label><?php 
                echo $title;
                ?>
</label>
					<div class="bon-builder-meta-input">
						<input type="text" class="<?php 
                echo $class;
                ?>
" name="<?php 
                echo $name;
                ?>
" value="<?php 
                echo $value;
                ?>
" />
						<?php 
                if (isset($description)) {
                    ?>
							<span class="bon-builder-meta-description"><?php 
                    echo $description;
                    ?>
 </span>
						<?php 
                }
                ?>
					</div>
				</div>
				<?php 
                break;
            case "upload":
                ?>
				<div class="bon-builder-meta-body">
					<label><?php 
                echo $title;
                ?>
</label>
					<div class="bon-builder-meta-input">	
						<input name="<?php 
                echo $name;
                ?>
" type="text" class="upload_media_text_meta <?php 
                echo $class;
                ?>
" value="<?php 
                echo $value;
                ?>
" />
						<a href="#" class="bon-builder-upload-button button"><?php 
                _e('Upload Image', 'bon-toolkit');
                ?>
</a>
						<?php 
                if (isset($description)) {
                    ?>
							<span class="bon-builder-meta-description"><?php 
                    echo $description;
                    ?>
</span>
						<?php 
                }
                ?>
					</div>
				</div>
				<?php 
                break;
            case "textarea":
                ?>
				<div class="bon-builder-meta-body">
					<label><?php 
                echo $title;
                ?>
</label>
					<div class="bon-builder-meta-input">
						<textarea class="<?php 
                echo $class;
                ?>
" name="<?php 
                echo $name;
                ?>
" ><?php 
                echo stripslashes($value);
                ?>
</textarea>
						<?php 
                if (isset($description)) {
                    ?>
							<span class="bon-builder-meta-description"><?php 
                    echo $description;
                    ?>
</span>
						<?php 
                }
                ?>
					</div>
				</div>
				<?php 
                break;
            case "select":
                ?>
				<div class="bon-builder-meta-body">
					<label><?php 
                echo $title;
                ?>
</label>
					<div class="bon-builder-meta-input">	
						<select class="<?php 
                echo $class;
                ?>
" name="<?php 
                echo $name;
                ?>
">
							<?php 
                foreach ($options as $key_option => $option) {
                    ?>
								<option value="<?php 
                    echo $key_option;
                    ?>
" <?php 
                    if ($key_option == esc_html($value)) {
                        echo 'selected';
                    }
                    ?>
 ><?php 
                    echo $option;
                    ?>
</option>
							<?php 
                }
                ?>
						</select>
						<?php 
                if (isset($description)) {
                    ?>
							<span class="bon-builder-meta-description"><?php 
                    echo $description;
                    ?>
</span>
						<?php 
                }
                ?>
					</div>
				</div>
				<?php 
                break;
            case "info":
                ?>
				<div class="bon-builder-meta-body">
					<div class="bon-builder-meta-description">	
						<?php 
                if (isset($description)) {
                    ?>
							<strong><span class="bon-builder-meta-description big-desc"><?php 
                    echo $description;
                    ?>
</span></strong>
						<?php 
                }
                ?>
					</div>
				</div>
				<?php 
                break;
            case "repeatable":
                ?>
				<div class="bon-builder-elements-meta-body">
					
					<div class="bon-builder-meta-repeat">
						<input type="hidden" id="repeat-count" name="<?php 
                echo $repeat_num;
                ?>
[]" value="<?php 
                echo empty($value) ? 1 : count($value);
                ?>
" />
						<div class="bon-builder-added-tab" id="bon-builder-added-tab">
							<ul>
								<?php 
                if (!empty($repeat_child)) {
                    if (!empty($value) && is_array($value)) {
                        foreach ($value as $child_val) {
                            ?>
											<li>	
										<?php 
                            $i = 0;
                            foreach ($repeat_child as $child_key => $child_meta) {
                                $child_meta['value'] = $child_val[$child_key];
                                $child_meta['name'] = $meta_box['name'] . '[' . $child_meta['name'] . '][]';
                                $this->get_meta_interface($child_meta, false);
                            }
                            ?>
												<div class="bon-builder-repeat-action">
													<a id="bon-builder-add-child" title="<?php 
                            _e('Add Field', 'bon-toolkit');
                            ?>
" class="bon-builder-add-child button">+</a>
													<a class="bon-builder-remove-child button" title="<?php 
                            _e('Remove Field', 'bon-toolkit');
                            ?>
" >-</a>
												</div>
											</li>

										<?php 
                            $i++;
                        }
                    } else {
                        ?>
											<li>	
												<?php 
                        $i = 0;
                        foreach ($repeat_child as $child) {
                            $child['name'] = $meta_box['name'] . '[' . $child['name'] . '][]';
                            $this->get_meta_interface($child, false);
                            $i++;
                        }
                        ?>
												<div class="bon-builder-repeat-action">
													<a id="bon-builder-add-child" title="<?php 
                        _e('Add Field', 'bon-toolkit');
                        ?>
" class="bon-builder-add-child button">+</a>
													<a class="bon-builder-remove-child button" title="<?php 
                        _e('Remove Field', 'bon-toolkit');
                        ?>
" >-</a>
												</div>
											</li>
											<?php 
                    }
                }
                ?>
							</ul>
						</div>
					</div>
				</div>
				<?php 
                break;
            case "icon":
                ?>
					<?php 
                if (function_exists('bon_icon_select_field')) {
                    ?>
					<div class="bon-builder-meta-body" id="bon-builder-meta-body-<?php 
                    echo $id;
                    ?>
">
						<label><?php 
                    echo $title;
                    ?>
</label>
						<div class="bon-builder-meta-input">
						<?php 
                    echo bon_icon_select_field($id, $name, '#bon-builder-meta-modal #bon-builder-meta-body-' . $id, esc_attr($value));
                    ?>
						</div>
					</div>
					<?php 
                } else {
                    ?>
					<div class="bon-builder-meta-body">
						<label><?php 
                    echo $title;
                    ?>
</label>
						<div class="bon-builder-meta-input">
							<input type="text" class="<?php 
                    echo $class;
                    ?>
" name="<?php 
                    echo $name;
                    ?>
" value="<?php 
                    echo $value;
                    ?>
" />
							<?php 
                    if (isset($description)) {
                        ?>
								<span class="bon-builder-meta-description"><?php 
                        echo $description;
                        ?>
 </span>
							<?php 
                    }
                    ?>
						</div>
					</div>
					<?php 
                }
                ?>

				<?php 
                break;
        }
    }
    /**
     * Adding option field to options block
     *
     * @since  0.1.0
     * @access public
     * @return void
     */
    function add_option($key, $item, $args)
    {
        $adv_key = BON_ADVANCED_MENU_KEY;
        $defaults = array('level' => '0-plus', 'desc' => '', 'label' => '', 'type' => 'text', 'options' => array(), 'std' => '');
        apply_filters('bon_nav_menu_option_defaults', $defaults);
        $args = wp_parse_args($args, $defaults);
        extract($args);
        $val = $this->get_option($item->ID, $key);
        if ($val == '') {
            $val = $std;
        }
        $desc = $this->get_desc($label, $desc);
        $id = 'edit-menu-item-' . $key . '-' . $item->ID;
        $name = $adv_key . '[' . $key . '][' . $item->ID . ']';
        ?>

		
		<div class="bon-nav-menu-field description description-wide level-<?php 
        echo $level;
        ?>
">
            <label for="<?php 
        echo $id;
        ?>
">

        <?php 
        switch ($type) {
            case 'text':
                echo $desc;
                echo '<input class="widefat bon-edit-menu-item" type="text" value="' . esc_attr($val) . '" id="' . $id . '" name="' . $name . '" />';
                break;
            case 'textarea':
                echo $desc;
                echo '<textarea class="widefat bon-edit-menu-item" id="' . $id . '" name="' . $name . '">' . wp_kses_data($val) . '</textarea>';
                break;
            case 'select':
                echo $desc;
                echo '<select class="widefat bon-edit-menu-item" id="' . $id . '" name="' . $name . '">';
                foreach ($options as $opt_key => $opt_label) {
                    echo '<option value="' . $opt_key . '" ' . selected($val, $opt_key, false) . ' >' . $opt_label . '</option>';
                }
                echo '</select>';
                break;
            case 'checkbox':
                echo '<input type="checkbox" class="bon-edit-menu-item" id="' . $id . '" name="' . $name . '" value="1" ' . checked($val, 1, false) . '/>';
                echo $desc;
                break;
            case 'upload':
                echo $desc;
                $class = '';
                if ($val) {
                    $class = ' has-file';
                }
                echo '<span class="bon-edit-menu-fieldset">';
                echo '<input type="text" class="bon-edit-menu-item bon-edit-menu-upload' . $class . '" value="' . esc_attr($val) . '" id="' . $id . '" placeholder="' . __('No file chosen', 'bon') . '" name="' . $name . '" />';
                if (function_exists('wp_enqueue_media')) {
                    if ($val == '') {
                        echo '<input data-choose="' . __('Choose an image', 'bon') . '" data-update="' . __('Use this image', 'bon') . '" id="upload-' . $id . '" class="upload-button button" type="button" value="' . __('Upload', 'bon') . '" />' . "\n";
                    } else {
                        echo '<input id="remove-edit-menu-item-' . $item->ID . '" class="remove-file button" type="button" value="' . __('Remove', 'bon') . '" />' . "\n";
                    }
                }
                echo '<span class="bon-edit-menu-screenshot" id="edit-menu-item-' . $item->ID . '-image">' . "\n";
                $image = preg_match('/(^.*\\.jpg|jpeg|png|gif|ico*)/i', $val);
                $img_cls = '';
                if ($val == '') {
                    $img_cls = 'no-image';
                }
                $remove = '<a class="remove-image ' . $img_cls . '"><i class="dashicons dashicons-no"></i></a>';
                echo '<img class="' . $img_cls . '" src="' . $val . '" alt="" />' . $remove . '';
                echo '</span>' . "\n";
                echo '</span>';
                break;
            case 'icon':
                echo $desc;
                echo bon_icon_select_field($id, $name, 'li#menu-item-' . $item->ID, esc_attr($val), array('bon-edit-menu-fieldset'), array('bon-edit-menu-item', 'bon-edit-menu-icon'));
                break;
            case 'editor':
                echo $desc;
                echo '<input type="button" class="button bon-menu-open-editor" data-button-submit="' . __('Save Content', 'bon') . '" data-dialog-title="' . __('Edit Custom Content', 'bon') . '" data-id="' . $item->ID . '" value="' . __('Edit Custom Content', 'bon') . '"/>';
                echo '<textarea class="widefat bon-edit-menu-item bon-textarea-editor" id="' . $id . '" name="' . $name . '">' . $val . '</textarea>';
                break;
        }
        ?>

		</label></div>

		<?php 
    }