Пример #1
0
function enlightenment_logo_dimmensions($args, $echo = true)
{
    $defaults = array('size' => 3);
    $args = wp_parse_args($args, $defaults);
    if (!isset($args['width_name']) || empty($args['width_name'])) {
        _doing_it_wrong(__FUNCTION__, 'Please specify a name attribute for your width field.', '');
        return;
    }
    if (!isset($args['height_name']) || empty($args['height_name'])) {
        _doing_it_wrong(__FUNCTION__, 'Please specify a name attribute for your height field.', '');
        return;
    }
    $output = enlightenment_text_input(array('name' => $args['width_name'], 'size' => $args['size'], 'value' => $args['width'], 'description' => ''), false);
    $output .= ' × ';
    $output .= enlightenment_text_input(array('name' => $args['height_name'], 'size' => $args['size'], 'value' => $args['height'], 'description' => ''), false);
    $output .= ' ';
    $output .= __('pixels', 'enlightenment');
    $output = apply_filters('enlightenment_logo_dimmensions', $output, $args);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
Пример #2
0
function enlightenment_color_picker($args, $echo = true)
{
    $defaults = array('transparent' => false, 'alpha' => false, 'class' => '', 'id' => '', 'description' => '');
    $args = wp_parse_args($args, $defaults);
    if (!isset($args['name']) || empty($args['name'])) {
        _doing_it_wrong(__FUNCTION__, __('Please specify a name attribute for your color picker.', 'enlightenment'), '');
        return;
    }
    $description = $args['description'];
    unset($args['description']);
    $picker_args = $args;
    if ($args['transparent'] || $args['alpha']) {
        $picker_args['name'] .= '[hex]';
        $picker_args['value'] = $args['value']['hex'];
    }
    $picker_args['class'] .= ' wp-color-picker';
    wp_enqueue_style('wp-color-picker');
    wp_enqueue_script('wp-color-picker');
    $output = enlightenment_text_input($picker_args, false);
    if ($args['transparent'] || $args['alpha']) {
        if ($args['alpha']) {
            wp_enqueue_script('jquery-ui-slider');
            $alpha_args = $args;
            $alpha_args['name'] .= '[alpha]';
            $alpha_args['value'] = $args['value']['alpha'];
            $alpha_args['size'] = 3;
            $alpha_args['readonly'] = true;
            $output .= ' <br />';
            $output .= enlightenment_open_tag('div', 'enlightenment-opacity-slider');
            $output .= enlightenment_open_tag('div', 'enlightenment-jquery-ui-slider');
            $output .= enlightenment_close_tag('div');
            $output .= __('Opacity:', 'enlightenment');
            $output .= ' ';
            $output .= enlightenment_text_input($alpha_args, false);
            $output .= enlightenment_close_tag('div');
            $args['name'] = str_replace('[alpha]', '', $args['name']);
        }
        if ($args['transparent']) {
            $transparent_args = $args;
            $transparent_args['name'] .= '[transparent]';
            $transparent_args['checked'] = $transparent_args['value']['transparent'];
            $transparent_args['label'] = __('Transparent', 'enlightenment');
            $transparent_args['value'] = 1;
            $output .= ' <br />';
            $output .= enlightenment_checkbox($transparent_args, false);
        }
        $output .= '<br />';
    }
    $output .= empty($description) ? '' : '<p class="description">' . strip_tags($description, '<a><abbr><img>') . '</p>';
    $output = apply_filters('enlightenment_color_picker', $output, $args);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
function enlightenment_add_dynamic_sidebar($args, $echo = true)
{
    $defaults = array('class' => '', 'id' => '', 'value' => '', 'placeholder' => '', 'size' => '', 'description' => '');
    $args = wp_parse_args($args, $defaults);
    $args = apply_filters('enlightenment_add_dynamic_sidebar_args', $args);
    $description = $args['description'];
    unset($args['description']);
    $args['name'] .= '[name]';
    $output = enlightenment_text_input($args, false);
    if (current_theme_supports('enlightenment-grid-loop')) {
        $output .= ' ';
        $output .= enlightenment_dynamic_sidebar_grid($args, false);
    }
    $output .= ' ';
    $output .= '<input name="' . current_theme_supports('enlightenment-theme-settings', 'option_name') . '[submit-sidebars]" class="button add-sidebar" type="submit" value="Add Sidebar" />';
    $output .= empty($description) ? '' : '<p class="description">' . strip_tags($description, '<a><abbr><img>') . '</p>';
    $output = apply_filters('enlightenment_add_dynamic_sidebar', $output, $args);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
Пример #4
0
function enlightenment_color_picker($args, $echo = true)
{
    $defaults = array('class' => '', 'id' => '', 'description' => '');
    $args = wp_parse_args($args, $defaults);
    if (!isset($args['name']) || empty($args['name'])) {
        _doing_it_wrong(__FUNCTION__, __('Please specify a name attribute for your color picker.', 'enlightenment'), '');
        return;
    }
    wp_enqueue_style('wp-color-picker');
    wp_enqueue_script('wp-color-picker');
    $args['class'] .= ' wp-color-picker';
    $output = enlightenment_text_input($args, false);
    $output = apply_filters('enlightenment_color_picker', $output, $args);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
Пример #5
0
    /**
     * Back-end widget form.
     *
     * @see WP_Widget::form()
     *
     * @param array $instance Previously saved values from database.
     */
    public function form($instance)
    {
        $defaults = array('title' => '', 'tagline' => '', 'type' => 'list', 'grid' => 'onecol', 'query' => 'sticky_posts', 'post_type' => 'post', 'p' => null, 'page_id' => null, 'pages' => array(), 'images' => array(), 'author' => null, 'taxonomy' => 'category', 'term' => null, 'posts_per_page' => 5, 'leading_posts' => 1, 'link_to_archive' => false, 'link_to_archive_label' => __('See all posts &rarr;', 'enlightenment'));
        $instance = wp_parse_args($instance, $defaults);
        echo enlightenment_open_tag('p');
        enlightenment_text_input(array('label' => __('Title:', 'enlightenment'), 'name' => $this->get_field_name('title'), 'class' => 'widefat', 'id' => $this->get_field_id('title'), 'value' => $instance['title']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p');
        enlightenment_textarea(array('label' => __('Tagline:', 'enlightenment'), 'name' => $this->get_field_name('tagline'), 'class' => 'widefat', 'id' => $this->get_field_id('tagline'), 'value' => $instance['tagline']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'type');
        $options = array('list' => __('List', 'enlightenment'), 'gallery' => __('Gallery', 'enlightenment'), 'slider' => __('Slider', 'enlightenment'), 'carousel' => __('Carousel', 'enlightenment'));
        enlightenment_select_box(array('label' => __('Type:', 'enlightenment'), 'name' => $this->get_field_name('type'), 'class' => 'widefat', 'id' => $this->get_field_id('type'), 'options' => $options, 'value' => $instance['type']));
        echo enlightenment_close_tag('p');
        if (current_theme_supports('enlightenment-grid-loop')) {
            echo enlightenment_open_tag('p', 'grid');
            $options = array();
            foreach (enlightenment_grid_columns() as $grid => $atts) {
                $options[$grid] = $atts['name'];
            }
            enlightenment_select_box(array('label' => __('Grid:', 'enlightenment'), 'name' => $this->get_field_name('grid'), 'class' => 'widefat', 'id' => $this->get_field_id('grid'), 'options' => $options, 'value' => $instance['grid']));
            echo enlightenment_close_tag('p');
        }
        echo enlightenment_open_tag('p', 'query');
        $queries = enlightenment_custom_queries();
        $options = array();
        foreach ($queries as $query => $atts) {
            $options[$query] = $atts['name'];
        }
        enlightenment_select_box(array('label' => __('Query:', 'enlightenment'), 'name' => $this->get_field_name('query'), 'class' => 'widefat', 'id' => $this->get_field_id('query'), 'options' => $options, 'value' => $instance['query']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'post-types' . ('post_type_archive' == $instance['query'] || 'post_type' == $instance['query'] ? ' show' : ''));
        $options = array();
        $post_types = enlightenment_custom_post_types();
        foreach ($post_types as $post_type => $atts) {
            $options[$post_type] = $atts['name'];
        }
        enlightenment_select_box(array('label' => __('Post Type:', 'enlightenment'), 'name' => $this->get_field_name('post_type'), 'class' => 'widefat', 'id' => $this->get_field_id('post_type'), 'options' => $options, 'value' => $instance['post_type']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'post-type' . ('post_type' == $instance['query'] ? ' show' : ''));
        $posts = get_posts(array('post_type' => esc_attr($instance['post_type']), 'posts_per_page' => -1));
        $options = array();
        foreach ($posts as $post) {
            $options[$post->ID] = get_the_title($post->ID);
        }
        enlightenment_select_box(array('label' => __('Post:', 'enlightenment'), 'name' => $this->get_field_name('p'), 'class' => 'widefat', 'id' => $this->get_field_id('p'), 'options' => $options, 'value' => $instance['p']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'page' . ('page' == $instance['query'] ? ' show' : ''));
        $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'page'));
        $options = array();
        foreach ($posts as $post) {
            $options[$post->ID] = get_the_title($post->ID);
        }
        enlightenment_select_box(array('label' => __('Page:', 'enlightenment'), 'name' => $this->get_field_name('page_id'), 'class' => 'widefat', 'id' => $this->get_field_id('page_id'), 'options' => $options, 'value' => $instance['page_id']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('div', 'pages' . ('pages' == $instance['query'] ? ' show' : ''));
        $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'page'));
        $boxes = array();
        $i = 0;
        foreach ($posts as $post) {
            $boxes[$i] = array();
            $boxes[$i]['label'] = get_the_title($post->ID);
            $boxes[$i]['name'] = $this->get_field_name('pages') . '[' . $post->ID . ']';
            $boxes[$i]['checked'] = in_array($post->ID, $instance['pages']);
            $i++;
        }
        echo '<label>' . __('Select Pages:', 'enlightenment') . '</label><br />';
        echo enlightenment_open_tag('div', 'pages-inner');
        enlightenment_checkboxes(array('boxes' => $boxes, 'value' => $instance['p']));
        echo enlightenment_close_tag('div');
        echo enlightenment_close_tag('div');
        echo enlightenment_open_tag('p', 'image-gallery' . ('gallery' == $instance['query'] ? ' show' : ''));
        enlightenment_upload_media(array('name' => $this->get_field_name('images'), 'upload_button_text' => __('Choose Images', 'enlightenment'), 'uploader_title' => __('Insert Images', 'enlightenment'), 'uploader_button_text' => __('Select', 'enlightenment'), 'remove_button_text' => '', 'mime_type' => 'image', 'multiple' => true, 'thumbnail' => null, 'value' => implode(',', $instance['images'])));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'author' . ('author' == $instance['query'] ? ' show' : ''));
        $authors = get_users(array('who' => 'authors'));
        $options = array();
        foreach ($authors as $author) {
            $options[$author->ID] = $author->display_name;
        }
        enlightenment_select_box(array('label' => __('Select Author:', 'enlightenment'), 'name' => $this->get_field_name('author'), 'class' => 'widefat', 'id' => $this->get_field_id('author'), 'options' => $options, 'value' => $instance['author']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'taxonomy' . ('taxonomy' == $instance['query'] ? ' show' : ''));
        $taxonomies = get_taxonomies(array('public' => true), 'objects');
        $options = array();
        foreach ($taxonomies as $name => $taxonomy) {
            if ('post_format' == $name) {
                $taxonomy->labels->singular_name = __('Post Format', 'enlightenment');
            }
            $options[$name] = $taxonomy->labels->singular_name;
        }
        enlightenment_select_box(array('label' => __('Taxonomy:', 'enlightenment'), 'name' => $this->get_field_name('taxonomy'), 'class' => 'widefat', 'id' => $this->get_field_id('taxonomy'), 'options' => $options, 'value' => $instance['taxonomy']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'term' . ('taxonomy' == $instance['query'] ? ' show' : ''));
        $terms = get_terms($instance['taxonomy']);
        $options = array();
        foreach ($terms as $term) {
            $options[$term->slug] = $term->name;
        }
        enlightenment_select_box(array('label' => __('Term:', 'enlightenment'), 'name' => $this->get_field_name('term'), 'class' => 'widefat', 'id' => $this->get_field_id('term'), 'options' => $options, 'value' => $instance['term']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'posts-count' . ('post_type_archive' == $instance['query'] || 'author' == $instance['query'] || 'taxonomy' == $instance['query'] ? ' show' : ''));
        enlightenment_text_input(array('label' => __('Total number of entries:', 'enlightenment'), 'name' => $this->get_field_name('posts_per_page'), 'id' => $this->get_field_id('posts_per_page'), 'value' => $instance['posts_per_page'], 'size' => 3));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'lead-posts' . ('slider' != $instance['type'] && 'carousel' != $instance['type'] && ('sticky_posts' == $instance['query'] || 'post_type_archive' == $instance['query'] || 'pages' == $instance['query'] || 'gallery' == $instance['query'] || 'author' == $instance['query'] || 'taxonomy' == $instance['query']) ? ' show' : ''));
        enlightenment_text_input(array('label' => __('Number of leading entries:', 'enlightenment'), 'name' => $this->get_field_name('leading_posts'), 'id' => $this->get_field_id('leading_posts'), 'value' => $instance['leading_posts'], 'size' => 3));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'archive-link' . ('post_type_archive' == $instance['query'] || 'author' == $instance['query'] || 'taxonomy' == $instance['query'] ? ' show' : ''));
        enlightenment_checkbox(array('label' => __('Show Link to Archive', 'enlightenment'), 'name' => $this->get_field_name('link_to_archive'), 'id' => $this->get_field_id('link_to_archive'), 'checked' => $instance['link_to_archive']));
        echo enlightenment_close_tag('p');
        echo enlightenment_open_tag('p', 'archive-link-label' . (('post_type_archive' == $instance['query'] || 'author' == $instance['query'] || 'taxonomy' == $instance['query']) && $instance['link_to_archive'] ? ' show' : ''));
        enlightenment_text_input(array('label' => __('Link to Archive Label:', 'enlightenment'), 'name' => $this->get_field_name('link_to_archive_label'), 'class' => 'widefat', 'id' => $this->get_field_id('link_to_archive_label'), 'value' => $instance['link_to_archive_label']));
        echo enlightenment_close_tag('p');
        ?>
		<script>
			jQuery(document).ready(function($) {
				$('.type select').change(function() {
					var container = $(this).closest('.widget-content');
					var val = $(this).val();
					if(val == 'slider' || val == 'carousel')
						$('.lead-posts', container).hide();
					else {
						var query = $('.query select', container).val();
						if(query == 'post_type' || query == 'page')
							$('.lead-posts', container).hide();
						else
							$('.lead-posts', container).show();
					}
				});
				$('.query select').change(function() {
					var container = $(this).closest('.widget-content');
					var val = $(this).val();
					var type = $('.type select', container).val();
					if(val == 'sticky_posts') {
						$('.post-types', container).hide();
						$('.post-type', container).hide();
						$('.page', container).hide();
						$('.pages', container).hide();
						$('.image-gallery', container).hide();
						$('.author', container).hide();
						$('.taxonomy', container).hide();
						$('.term', container).hide();
						$('.posts-count', container).hide();
						if(type != 'slider' && type != 'carousel')
							$('.lead-posts', container).show();
						$('.archive-link', container).hide();
						$('.archive-link-label', container).hide();
					} else if(val == 'post_type_archive') {
						$('.post-types', container).show();
						$('.post-type', container).hide();
						$('.page', container).hide();
						$('.pages', container).hide();
						$('.image-gallery', container).hide();
						$('.author', container).hide();
						$('.taxonomy', container).hide();
						$('.term', container).hide();
						$('.posts-count', container).show();
						if(type != 'slider' && type != 'carousel')
							$('.lead-posts', container).show();
						$('.archive-link', container).show();
						if($('.archive-link', container).is(':checked'))
							$('.archive-link-label', container).show();
					} else if(val == 'post_type') {
						$('.post-types', container).show();
						$('.post-type', container).show();
						$('.page', container).hide();
						$('.pages', container).hide();
						$('.image-gallery', container).hide();
						$('.author', container).hide();
						$('.taxonomy', container).hide();
						$('.term', container).hide();
						$('.posts-count', container).hide();
						$('.lead-posts', container).hide();
						$('.archive-link', container).hide();
						$('.archive-link-label', container).hide();
					} else if(val == 'page') {
						$('.post-types', container).hide();
						$('.post-type', container).hide();
						$('.page', container).show();
						$('.pages', container).hide();
						$('.image-gallery', container).hide();
						$('.author', container).hide();
						$('.taxonomy', container).hide();
						$('.term', container).hide();
						$('.posts-count', container).hide();
						$('.lead-posts', container).hide();
						$('.archive-link', container).hide();
						$('.archive-link-label', container).hide();
					} else if(val == 'pages') {
						$('.post-types', container).hide();
						$('.post-type', container).hide();
						$('.page', container).hide();
						$('.pages', container).show();
						$('.image-gallery', container).hide();
						$('.author', container).hide();
						$('.taxonomy', container).hide();
						$('.term', container).hide();
						$('.posts-count', container).hide();
						if(type != 'slider' && type != 'carousel')
							$('.lead-posts', container).show();
						$('.archive-link', container).hide();
						$('.archive-link-label', container).hide();
					} else if(val == 'gallery') {
						$('.post-types', container).hide();
						$('.post-type', container).hide();
						$('.page', container).hide();
						$('.pages', container).hide();
						$('.image-gallery', container).show();
						$('.author', container).hide();
						$('.taxonomy', container).hide();
						$('.term', container).hide();
						$('.posts-count', container).hide();
						if(type != 'slider' && type != 'carousel')
							$('.lead-posts', container).show();
						$('.archive-link', container).hide();
						$('.archive-link-label', container).hide();
					} else if(val == 'author') {
						$('.post-types', container).hide();
						$('.post-type', container).hide();
						$('.page', container).hide();
						$('.pages', container).hide();
						$('.image-gallery', container).hide();
						$('.author', container).show();
						$('.taxonomy', container).hide();
						$('.term', container).hide();
						$('.posts-count', container).show();
						if(type != 'slider' && type != 'carousel')
							$('.lead-posts', container).show();
						$('.archive-link', container).show();
						if($('.archive-link', container).is(':checked'))
							$('.archive-link-label', container).show();
					} else if(val == 'taxonomy') {
						$('.post-types', container).hide();
						$('.post-type', container).hide();
						$('.page', container).hide();
						$('.pages', container).hide();
						$('.image-gallery', container).hide();
						$('.author', container).hide();
						$('.taxonomy', container).show();
						$('.term', container).show();
						$('.posts-count', container).show();
						if(type != 'slider' && type != 'carousel')
							$('.lead-posts', container).show();
						$('.archive-link', container).show();
						if($('.archive-link', container).is(':checked'))
							$('.archive-link-label', container).show();
					}
				});
				$('.post-types select').change(function() {
					var container = $(this).closest('.widget-content');
					var data = {
						action: 'enlightenment_ajax_get_post_types',
						post_type: $('.post-types select', container).val(),
						name: '<?php 
        echo $this->get_field_name('p');
        ?>
',
						id: '<?php 
        echo $this->get_field_id('p');
        ?>
',
						value: '<?php 
        echo $instance['p'];
        ?>
',
					}
					$.post(ajaxurl, data, function(r) {
						var html = document.createElement( 'div' );
						$(html).html(r);
						$('.post-type select', container).html($('select', $(html)).html());
					});
				});
				$('.taxonomy select').change(function() {
					var container = $(this).closest('.widget-content');
					var data = {
						action: 'enlightenment_ajax_get_terms',
						taxonomy: $('.taxonomy select', container).val(),
						name: '<?php 
        echo $this->get_field_name('term');
        ?>
',
						id: '<?php 
        echo $this->get_field_id('term');
        ?>
',
						value: '<?php 
        echo $instance['term'];
        ?>
',
					}
					$.post(ajaxurl, data, function(r) {
						var html = document.createElement( 'div' );
						$(html).html(r);
						$('.term', container).remove();
						$('.taxonomy', container).after($(html).html());
					});
				});
				$('.archive-link input').each(function() {
					var container = $(this).closest('.widget-content');
					var query = $('.query select', container).val();
					if( query == 'post_type_archive' || query == 'author' || query == 'taxonomy' ) {
						if($(this).is(':checked'))
							$('.archive-link-label', container).show();
						else
							$('.archive-link-label', container).hide();
					}
				});
				$('.archive-link input').change(function() {
					var container = $(this).closest('.widget-content');
					if($(this).is(':checked'))
						$('.archive-link-label', container).show();
					else
						$('.archive-link-label', container).hide();
				});
			});
		</script>
		<?php 
    }