Ejemplo n.º 1
0
        /**
         * Outputs the column fields.
         *
         * @param array $instance Current settings.
         * @param array $columns Array of fields to output.
         * @param object $obj Current Widget Object.
         */
        public static function do_columns($instance, $columns, $obj)
        {
            echo '<div class="thememix-featured-content-widget-body">';
            foreach ($columns as $column => $boxes) {
                if ('col1' == $column) {
                    $col_class = 'thememix-featured-content-left-box';
                } elseif ('col2' == $column) {
                    $col_class = 'thememix-featured-content-right-box';
                } else {
                    $col_class = 'thememix-featured-content-wide-box';
                }
                printf('<div class="%s">', $col_class);
                foreach ($boxes as $box) {
                    $box_style = isset($box['box_requires']) ? ' style="' . ThemeMix_Featured_Content::get_display_option($instance, $box['box_requires']) . '"' : '';
                    // $box_style = isset( $box['box_requires'] ) ? ' style="'. ThemeMix_Featured_Content::get_display_option( $instance, $box['box_requires'][0], $box['box_requires'][1], $box['box_requires'][2] ) .'"' : '';
                    printf('<div class="thememix-featured-content-box"%s>', $box_style);
                    foreach ($box as $field_id => $args) {
                        if ('box_requires' == $field_id) {
                            continue;
                        }
                        $data = isset($args['requires']) ? ThemeMix_Featured_Content::data_implode($args['requires']) : '';
                        $style = '';
                        if (isset($args['requires']) && is_array($args['requires']) && 3 == count($args['requires'])) {
                            $style = ' style="' . ThemeMix_Featured_Content::get_display_option($instance, $args['requires']) . '"';
                            echo '<div ' . $style . ' class="' . $args['type'] . ' ' . $field_id . '" data-requires-key="' . $args['requires'][0] . '" data-requires-value="' . $args['requires'][1] . '" >';
                        } else {
                            echo '<div ' . $style . ' class="' . $args['type'] . ' ' . $field_id . '" >';
                        }
                        switch ($args['type']) {
                            case 'post_type_select':
                                printf('<label for="%1$s">%2$s</label><select onchange="thememix_featured_contentSave(this)" id="%1$s" name="%3$s">', $obj->get_field_id($field_id), $args['label'], $obj->get_field_name($field_id));
                                printf('<option class="gs-pad-left-10" value="any" %s>%s</option>', selected(esc_attr($post_type), $instance['post_type'], false), __('Any', 'thememix-pro-genesis'));
                                $post_types = ThemeMix_Featured_Content::get_post_types();
                                foreach ($post_types as $post_type) {
                                    $pt = get_post_type_object($post_type);
                                    printf('<option class="gs-pad-left-10" value="%s" %s>%s</option>', esc_attr($post_type), selected(esc_attr($post_type), $instance['post_type'], false), esc_attr($pt->label));
                                }
                                echo '</select>';
                                break;
                            case 'page_select':
                                printf('<label for="%1$s">%2$s:</label><select id="%1$s" name="%3$s" onchange="thememix_featured_contentSave(this)"><option value="" %4$s>%5$s</option>', $obj->get_field_id($field_id), $args['label'], $obj->get_field_name($field_id), selected('', $instance['page_id'], false), esc_attr(__('Select page', 'thememix-pro-genesis')));
                                $pages = get_pages();
                                foreach ($pages as $page) {
                                    printf('<option class="gs-pad-left-10" value="%s" %s>%s</option>', esc_attr($page->ID), selected(esc_attr($page->ID), $instance['page_id'], false), esc_attr($page->post_title));
                                }
                                echo '</select>';
                                break;
                            case 'select_taxonomy':
                                $taxonomies = ThemeMix_Featured_Content::get_taxonomies(apply_filters('thememix_featured_content_get_taxonomies_args', array('public' => true), $instance, $obj), 'objects');
                                $taxonomies = array_filter((array) $taxonomies, array('ThemeMix_Featured_Content', 'exclude_taxonomies'));
                                printf('<label for="%1$s">%2$s:</label><select id="%1$s" name="%3$s" onchange="thememix_featured_contentSave(this)"><option value="" class="gs-pad-left-10" %4$s>%5$s</option>', $obj->get_field_id($field_id), $args['label'], $obj->get_field_name($field_id), selected('', $instance['posts_term'], false), __('All Taxonomies and Terms', 'thememix-pro-genesis'));
                                foreach ($taxonomies as $taxonomy) {
                                    $query_label = '';
                                    if (!empty($taxonomy->query_var)) {
                                        $query_label = $taxonomy->query_var;
                                    } else {
                                        $query_label = $taxonomy->name;
                                    }
                                    echo '<optgroup label="' . esc_attr($taxonomy->labels->name) . '">
									<option class="gs-tax-optgroup" value="' . esc_attr($query_label) . '" ' . selected(esc_attr($query_label), $instance['posts_term'], false) . '>' . $taxonomy->labels->all_items . '</option>';
                                    $terms = get_terms($taxonomy->name, 'orderby=name&hide_empty=1');
                                    foreach ($terms as $term) {
                                        printf('<option class="gs-pad-left-10" value="%s" %s>%s</option>', esc_attr($query_label) . ',' . $term->slug, selected(esc_attr($query_label) . ',' . $term->slug, $instance['posts_term'], false), esc_attr($term->name));
                                    }
                                    echo '</optgroup>';
                                }
                                echo '</select>';
                                break;
                            case 'text':
                                echo $args['description'] ? wpautop($args['description']) : '';
                                printf('<label for="%1$s">%2$s:</label>', $obj->get_field_id($field_id), $args['label']);
                                printf('<input type="text" id="%s" name="%s" value="%s" class="gs-widefat" />', $obj->get_field_id($field_id), $obj->get_field_name($field_id), esc_attr($instance[$field_id]));
                                break;
                            case 'text_small':
                                printf('<label for="%1$s">%2$s:</label>', $obj->get_field_id($field_id), $args['label']);
                                printf('<input type="text" class="thememix-featured-content-small" id="%s" name="%s" value="%s" />%s', $obj->get_field_id($field_id), $obj->get_field_name($field_id), esc_attr($instance[$field_id]), $args['description']);
                                break;
                            case 'select':
                                printf('<label for="%1$s">%2$s:</label><select id="%1$s" name="%3$s" onchange="thememix_featured_contentSave(this)">', $obj->get_field_id($field_id), $args['label'], $obj->get_field_name($field_id));
                                foreach ($args['options'] as $value => $label) {
                                    printf('<option class="gs-pad-left-10" value="%s" %s>%s</option>', $value, selected($value, $instance[$field_id], false), $label);
                                }
                                echo '</select>';
                                break;
                            case 'checkbox':
                                printf('<input type="checkbox" id="%1$s" name="%2$s" value="1" class="widget-control-save" %3$s />', $obj->get_field_id($field_id), $obj->get_field_name($field_id), checked(1, $instance[$field_id], false));
                                printf('<label for="%1$s">%2$s</label>', $obj->get_field_id($field_id), $args['label']);
                                echo $args['description'] ? wpautop($args['description']) : '';
                                break;
                            case 'colour_picker':
                                echo '
							<script type="text/javascript">
							//<![CDATA[
								jQuery(document).ready(function()
								{
									// colorpicker field
									jQuery(\'.cw-color-picker\').each(function(){
										var $this = jQuery(this),
											id = $this.attr(\'rel\');

										$this.farbtastic(\'#\' + id);
									});
								});
							//]]>
							</script>

							<p>
								<label for="' . esc_attr(ThemeMix_Featured_Content::$self->get_field_id('background')) . '">' . __('Background Color:') . '</label>
								<input class="widefat" id="' . esc_attr(ThemeMix_Featured_Content::$self->get_field_id('background')) . '" name="' . esc_attr(ThemeMix_Featured_Content::$self->get_field_name('background')) . '" type="text" value="' . esc_attr($instance['background']) . '" />
								<div class="cw-color-picker" rel="' . esc_attr(ThemeMix_Featured_Content::$self->get_field_id('background')) . '"></div>
							</p>';
                                break;
                            case 'fontawesome':
                                echo '<div class="font-awesome">';
                                printf('<input type="textbox" id="%1$s" name="%2$s" class="fontawesome-picker" widget-control-save" value="%3$s" />', ThemeMix_Featured_Content::$self->get_field_id('fontawesome-icon'), ThemeMix_Featured_Content::$self->get_field_name('fontawesome-icon'), $instance['fontawesome-icon']);
                                echo '<input class="button fontawesome-picker" type="button" value="Choose Icon" data-target="' . esc_attr('#' . ThemeMix_Featured_Content::$self->get_field_id('fontawesome-icon')) . '" />';
                                echo '</div>';
                                echo '<div class="font-awesome-location">';
                                echo sprintf(__('To edit the Font Awesome Icon used, please visit the <a href="%s">primary widgets page</a> in WordPress.', 'thememix-pro-genesis'), admin_url() . 'widgets.php');
                                echo '</div>';
                                break;
                            case 'p':
                            case 'description':
                                echo $args['description'] ? wpautop($args['description']) : '';
                                break;
                            default:
                                do_action('thememix_featured_content_custom_field_' . $args['type'], $instance, $obj);
                        }
                        echo '</div>';
                    }
                    echo '</div>';
                }
                echo '</div>';
            }
            echo '</div>';
        }