コード例 #1
0
ファイル: logo.php プロジェクト: thano/cfpi-theme-2016
function enlightenment_upload_logo($args, $echo = true)
{
    $defaults = array('class' => 'site-logo', 'id' => 'site-logo', 'upload_button_text' => __('Choose Logo', 'enlightenment'), 'uploader_title' => __('Select Logo', 'enlightenment'), 'uploader_button_text' => __('Use as Logo', 'enlightenment'), 'remove_button_text' => __('Remove Logo', 'enlightenment'), 'mime_type' => 'image', 'thumbnail' => 'enlightenment-logo');
    $args = wp_parse_args($args, $defaults);
    if (!isset($args['name']) || empty($args['name'])) {
        _doing_it_wrong(__FUNCTION__, 'Please specify a name attribute for your logo uploader.', '');
        return;
    }
    $output = enlightenment_upload_media($args, false);
    $output = apply_filters('enlightenment_upload_logo', $output, $args);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
コード例 #2
0
function enlightenment_background_options($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 background options.', 'enlightenment'), '1.1.0');
        return;
    }
    $description = $args['description'];
    unset($args['description']);
    $option = enlightenment_theme_option($args['name']);
    $color_picker_args = array('name' => $args['name'] . '[color]', 'value' => isset($args['value']['color']) ? $args['value']['color'] : $option['color'], 'transparent' => true, 'alpha' => true, 'class' => 'background_color' . (!empty($args['class']) ? ' ' . $args['class'] . '_background_color' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_background_color' : '');
    $image_uploader_args = array('name' => $args['name'] . '[image]', 'value' => isset($args['value']['image']) ? $args['value']['image'] : $option['image'], 'class' => 'background_image' . (!empty($args['class']) ? ' ' . $args['class'] . '_background_image' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_background_image' : '', 'upload_button_text' => __('Choose Image', 'enlightenment'), 'uploader_title' => __('Select Image', 'enlightenment'), 'uploader_button_text' => __('Use Image', 'enlightenment'), 'remove_button_text' => __('Remove Image', 'enlightenment'), 'mime_type' => 'image', 'thumbnail' => 'thumbnail');
    $position_args = array('name' => $args['name'] . '[position]', 'value' => isset($args['value']['position']) ? $args['value']['position'] : $option['position'], 'class' => 'background_position' . (!empty($args['class']) ? ' ' . $args['class'] . '_background_position' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_background_position' : '', 'options' => array('center' => __('Center', 'enlightenment'), 'center-top' => __('Center Top', 'enlightenment'), 'center-bottom' => __('Center Bottom', 'enlightenment'), 'left-top' => __('Left Top', 'enlightenment'), 'left-center' => __('Left Center', 'enlightenment'), 'left-bottm' => __('Left Bottom', 'enlightenment'), 'right-top' => __('Right Top', 'enlightenment'), 'right-center' => __('Right Center', 'enlightenment'), 'right-bottom' => __('Right Bottom', 'enlightenment')));
    $repeat_args = array('name' => $args['name'] . '[repeat]', 'value' => isset($args['value']['repeat']) ? $args['value']['repeat'] : $option['repeat'], 'class' => 'background_repeat' . (!empty($args['class']) ? ' ' . $args['class'] . '_background_repeat' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_background_repeat' : '', 'options' => array('no-repeat' => __('No Repeat', 'enlightenment'), 'repeat' => __('Tiled', 'enlightenment'), 'repeat-x' => __('Tiled Horizontally', 'enlightenment'), 'repeat-y' => __('Tiled Vertically', 'enlightenment')));
    $size_args = array('name' => $args['name'] . '[size]', 'value' => isset($args['value']['size']) ? $args['value']['size'] : $option['size'], 'class' => 'background_size' . (!empty($args['class']) ? ' ' . $args['class'] . '_background_size' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_background_size' : '', 'options' => array('auto' => __('Scaled', 'enlightenment'), 'cover' => __('Cover', 'enlightenment'), 'contain' => __('Contained', 'enlightenment')));
    $scroll_args = array('name' => $args['name'] . '[scroll]', 'value' => isset($args['value']['scroll']) ? $args['value']['scroll'] : $option['scroll'], 'class' => 'background_scroll' . (!empty($args['class']) ? ' ' . $args['class'] . '_background_scroll' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_background_scroll' : '', 'options' => array('scroll' => __('Scroll', 'enlightenment'), 'fixed' => __('Fixed', 'enlightenment'), 'parallax' => __('Parallax', 'enlightenment')));
    $output = enlightenment_open_tag('fieldset', 'background-options');
    $output .= enlightenment_color_picker($color_picker_args, false);
    $output .= enlightenment_upload_media($image_uploader_args, false);
    $output .= enlightenment_select_box($position_args, false);
    $output .= enlightenment_select_box($repeat_args, false);
    $output .= enlightenment_select_box($size_args, false);
    $output .= enlightenment_select_box($scroll_args, false);
    $output .= enlightenment_close_tag('fieldset');
    $output .= empty($description) ? '' : '<p class="description">' . strip_tags($description, '<a><abbr><img>') . '</p>';
    $output = apply_filters('enlightenment_background_options', $output, $args);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
コード例 #3
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 
    }