function atw_posts_style_admin()
{
    // admin for style options...
    ?>
   <h2 style="color:blue;">Custom CSS Rules</h2>
    <form method="post" enctype="multipart/form-data">
        <input type="hidden" name="atw_posts_save_style_opts" value="Filter Options Saved" />
<?php 
    atw_posts_nonce_field('atw_posts_save_style_opts');
    ?>

	<!-- ======== -->
	<span style="color:#6666FF;"><b>Add your own custom CSS Rules</b></span><br/>
	<p>
	This section allows you to add new CSS Rules. The intent is to allow you to add custom CSS that will make
    the plugin's post output more closely match your own theme. These rules apply to all posts generated by this plugin for all filters.
    You can add any standard CSS rule to the text box.
    </p>
	<p>
	The classes used by this plugin to style posts include (you can copy/paste these into the textbox):
    <ul style="padding-left:20px;">
        <li>.atw-post {} - wraps whole post</li>
        <li>.atw-entry-title a {} - the post title</li>
        <li>.atw-entry-meta {} - top meta info line</li>
        <li>.atw-featured-image {} - wraps the Featured Image</li>
        <li>.atw-entry-summary {} - wraps excerpt</li>
        <li>.atw-entry-content {} - wraps full content</li>
        <li>.atw-show-posts .sticky {} - sticky posts</li>
    </ul>
    Note that these .atw- classes won't apply to posts generated by your theme using "Native Theme Support" (see Filters tab).
    For example, you could make the titles of posts green by adding this CSS: <code>.atw-entry-title a {color:green;}</code>
	</p>
<?php 
    if (current_user_can('unfiltered_html')) {
        ?>
<textarea name="atw_custom_css" placeholder=".sample-class { ... } /* enter CSS Rules */" rows=7 style="width: 95%"><?php 
        echo esc_textarea(atw_posts_getopt('custom_css'));
        ?>
</textarea>
<?php 
    } else {
        ?>
<p>Sorry, due to security issues, you must have an Administrator user role to add Custom CSS Rules.</p>
<?php 
    }
    atw_posts_save_style_button();
    ?>
    </form>
<?php 
}
function atw_posts_form_checkbox($id, $desc, $br = '<br />')
{
    ?>
    <div style = "display:inline;padding-left:2.5em;text-indent:-1.7em;"><label><input type="checkbox" name="<?php 
    echo $id;
    ?>
" id="<?php 
    echo $id;
    ?>
"
        <?php 
    checked(atw_posts_getopt($id));
    ?>
 >&nbsp;
<?php 
    echo $desc . '</label></div>' . $br . "\n";
}
    function form($instance)
    {
        $title = isset($instance['title']) ? $instance['title'] : '';
        $post_list = isset($instance['post_list']) ? $instance['post_list'] : 'default';
        $add_class = isset($instance['add_class']) ? $instance['add_class'] : '';
        // Get posts
        $posts = atw_posts_getopt('filters');
        // If no menus exists, direct the user to go and create some.
        if (empty($posts)) {
            echo '<p>' . 'No Post Filters have been created yet. Create some on the <em>Weaver Posts (& Slider Options) -> Filters</em> admin menu.' . '</p>';
            return;
        }
        ?>
	<p>
	<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        echo 'Title (optional):';
        ?>
</label>
	<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" value="<?php 
        echo esc_textarea($title);
        ?>
" />
	</p>

	<p>
	<label for="<?php 
        echo $this->get_field_id('post_list');
        ?>
"><?php 
        echo 'Select a Post';
        ?>
</label><br />
	<select id="<?php 
        echo $this->get_field_id('post_list');
        ?>
" name="<?php 
        echo $this->get_field_name('post_list');
        ?>
">
<?php 
        foreach ($posts as $post) {
            $selected = $post_list == $post['slug'] ? ' selected="selected"' : '';
            echo '<option' . $selected . ' value="' . $post['slug'] . '">' . $post['name'] . '</option>';
        }
        ?>
	</select>
	</p>

	<p>
	<label for="<?php 
        echo $this->get_field_id('add_class');
        ?>
"><?php 
        echo 'Additional Classes to Wrap Posts (optional):';
        ?>
</label>
	<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('add_class');
        ?>
" name="<?php 
        echo $this->get_field_name('add_class');
        ?>
" value="<?php 
        echo esc_textarea($add_class);
        ?>
" />
	</p>
<?php 
    }
function atw_posts_duplicate_filter()
{
    $name = sanitize_text_field(atw_posts_get_POST('filter_name'));
    $slug = sanitize_title_with_dashes($name);
    if ($name == '') {
        atw_posts_error_msg('Please provide a name for the new filter.');
        return true;
    }
    $current_filter = atw_posts_getopt('current_filter');
    global $atw_posts_opts_cache;
    $cur_opts = $atw_posts_opts_cache['filters'][$current_filter];
    atw_posts_setopt('current_filter', $slug);
    $atw_posts_opts_cache['filters'][$slug] = $cur_opts;
    atw_posts_set_filter_opt('name', $name);
    atw_posts_set_filter_opt('slug', $slug);
    $new_opts = $cur_opts = $atw_posts_opts_cache['filters'][$slug];
    atw_posts_save_msg('Filter Duplicated: "' . $name . '" (Slug: <em>' . $slug . '</em>)');
    return true;
}
function weaverii_pwp_atw_show_post_filter()
{
    // use plugin options...
    global $post;
    if (function_exists('atw_showposts_installed')) {
        $filters = atw_posts_getopt('filters');
        $first = true;
        echo '<select id="pp_post_filter" name="pp_post_filter" >';
        foreach ($filters as $filter => $val) {
            // display dropdown of available filters
            if ($first) {
                $first = false;
                echo '<option value="" ' . selected(get_post_meta($post->ID, 'pp_post_filter', true) == '') . '>Don\'t Use Filter</option>';
            } else {
                echo '<option value="' . $filter . '" ' . selected(get_post_meta($post->ID, 'pp_post_filter', true) == $filter) . '>' . $val['name'] . '</option>';
            }
        }
        echo '</select>&nbsp;Use a Filter from <em>ATW Show Posts Plugin</em> <strong>instead</strong> of above post selection options.<br /> ' . '<span style="margin-left:12em;"><span>(Note: ATW Filter Display Options and Use Paging option <em>not</em> used for posts using this filter.)<br />';
    } else {
        ?>
<strong>Want More Post Filtering Options?</strong> Install the <em>Aspen Themeworks Show Posts</em> plugin for more filtering options.<br /><br />
<?php 
    }
}
function wvrx_ts_pwp_atw_show_post_filter()
{
    // use plugin options...
    global $post;
    if (function_exists('atw_showposts_installed')) {
        $filters = atw_posts_getopt('filters');
        $first = true;
        echo '<select id="_pp_post_filter" name="_pp_post_filter" >';
        foreach ($filters as $filter => $val) {
            // display dropdown of available filters
            if ($first) {
                $first = false;
                echo '<option value="" ' . selected(get_post_meta($post->ID, '_pp_post_filter', true) == '') . '>Use above post filtering options</option>';
            } else {
                echo '<option value="' . $filter . '" ' . selected(get_post_meta($post->ID, '_pp_post_filter', true) == $filter) . '>' . $val['name'] . '</option>';
            }
        }
        echo '</select>&nbsp;' . __('Use a Filter from <em>Weaver Show Posts Plugin</em> <strong>instead</strong> of above post selection options.', 'weaverx-theme-support') . '<br /> <span style="margin-left:8em;"><span>' . __('(Note: Weaver Show Posts <em>Post Display</em> options and <em>Use Paging</em> option <strong>not</strong> used for posts when using this filter.)', 'weaverx-theme-support') . '<br />' . '<br />';
    } else {
        _e('<strong>Want More Post Filtering Options?</strong> Install the <em>Aspen Themeworks Show Posts</em> plugin for more filtering options.', 'weaverx-theme-support');
        ?>
<br /><br />
<?php 
    }
}
function atw_posts_define_display()
{
    // define display filter options
    ?>

    <h3><u>Define Post Display Filter Options</u></h3>
    <div class="filter-section">
    <div class="filter-title">&bull; Post Display <span class="filter-title-description">When displaying posts, use these display options. Don't apply to image sliders.</span></div>

    <div class="filter-opts">
<?php 
    $has_templates = atw_posts_theme_has_templates();
    if ($has_templates && atw_posts_is_generic() && atw_posts_getopt('use_native_theme_templates')) {
        ?>
        <span style="display:inline;padding-left:2.5em;text-indent:-1.7em;"></span>
        <em>Post Display Options not available when using your theme's content display as checked in the option above.</em><br /><br />
<?php 
    } else {
        atw_posts_filter_checkbox('hide_title', 'Hide Post Title', '');
        atw_posts_filter_checkbox('show_avatar', 'Show Author Avatar');
        atw_posts_filter_checkbox('hide_top_info', 'Hide Top Post Meta Info (date, author)', '');
        atw_posts_filter_checkbox('hide_bottom_info', 'Hide Bottom Post Meta Info (category, tag, comment link)');
        atw_posts_filter_checkbox('hide_featured_image', 'Hide Featurd Image in post (default: show; or theme defaults)', '');
        echo '<br />';
        atw_posts_filter_textarea('more_msg', '"Continue Reading..." message for excerpts.');
        $cur_show = atw_posts_get_filter_opt('show');
        ?>


    <div style="padding:1em 0 .5em 4em;text-indent:-1.7em;">Display posts as: &nbsp;&nbsp;
	<select name="show">
	<option value="" <?php 
        selected($cur_show == '');
        ?>
></option>
	<option value="full" <?php 
        selected($cur_show == 'full');
        ?>
>Full post</option>
	<option value="excerpt" <?php 
        selected($cur_show == 'excerpt');
        ?>
>Excerpt</option>
	<option value="title" <?php 
        selected($cur_show == 'title');
        ?>
>Title + Top Meta Line</option>
    <option value="titlelist" <?php 
        selected($cur_show == 'titlelist');
        ?>
>Title only as list</option>
    <option value="title_featured" <?php 
        selected($cur_show == 'title_featured');
        ?>
>Title + Featured Image</option>
	</select> &nbsp;How to display posts - (Default: full post; Weaver theme settings)
    </div>


<?php 
    }
    // else not getting from gallery
    ?>
    </div>

    <div style="clear:both;"></div>

        <div class="filter-description">
    <p>
        Use this section to define how each post is to be displayed - title, excerpted, etc. These options apply to how each post is displayed when
        using the plugin's built-in post layout, or when used with native Weaver Xtreme or Weaver II layout. Use the Content Selection Filter to define which posts
        will be displayed. The Slider Image Show options can be used to define how images are used in a image only slide show. (Note: when using the
        Weaver Slider plugin to display an image slider, these Post Display options do not apply.)
    </p>
    </div>
</div>
<?php 
}
function atw_posts_showposts_admin()
{
    // admin for style options...
    ?>
   <h2 style="color:blue;">Weaver Show Posts</h2>
    <form method="post" enctype="multipart/form-data">
        <input type="hidden" name="atw_posts_save_showposts_opts" value="Show Posts Options Saved" />
<?php 
    atw_posts_nonce_field('atw_posts_save_showposts_opts');
    ?>
<label><span style="color:blue;font-weight:bold; font-size: larger;"><b>Show Posts - [show_posts filter=filter-name]</b></span></label>
<br />
<p>
    The Weaver <code>[show_posts]</code> shortcode allows you to display posts on your pages or in a text widget
    in the sidebar. You can specify a large number of filtering options to select a specific set of posts to show.
</p>

<p>
    The recommended way to display posts is to specify all the filter selection options on the <em>Filter</em> tab, and use the
    <strong>[show_posts filter=filter-name]</strong> form of the shortcode. You can also specify the options manually.
</p>
<p><span style="font-size:120%;font-weight:bold;">Shortcodes, using current <em>Filter</em> settings:</span> - You can Copy/Paste these.
<table>
    <tr><td>Shortcode using filter name:&nbsp;&nbsp;</td><td><strong>[show_posts filter=<?php 
    echo atw_posts_getopt('current_filter');
    ?>
]</strong>
    &nbsp;&nbsp;- You can also use the "Add [show_posts]" button on the Page/Post Editor.</td></tr>
    <tr><td>Shortcode using parameters:&nbsp;&nbsp; </td><td><strong>[show_posts
<?php 
    $params = atw_posts_get_filter_params();
    // define in atw-runtime-lib.php
    echo $params;
    ?>
]</strong></td></tr></table>
</p>

<p>
<h3>Summary of all parameters for [show_posts] shortcode, shown with default values:</h3>
<table style="padding-left:25px;">
    <tr><td>cols=1</td><td>display posts in 1 to 3 columns</td></tr>
    <tr><td>filter=''</td><td>use named filter - all other parameters ignored when filter specified </td></tr>
    <tr><td>hide_bottom_info=false</td><td>hide bottom info line </td></tr>
    <tr><td>hide_featured_image=false</td><td>hide featured image - FI is displayed by default </td></tr>
    <tr><td>hide_title=false</td><td>hide the title </td></tr>
    <tr><td>hide_top_info=false</td><td>hide the top info line </td></tr>
    <tr><td>show=full</td><td>show: title | excerpt | full | titlelist | title_featured </td></tr>
    <tr><td>show_avatar=false</td><td>show the author avatar </td></tr>
    <tr><td>more_msg="New More Message"&nbsp;&nbsp;</td><td>replacement for Continue Reading excerpt message </td></tr>
    <tr><td>use_paging=false</td><td>Use paging when displaying multiple posts </td></tr>
	<tr><td>no_top_clear=false</td><td>Prevents "clear:both" at beginning of posts display.</td></tr>
    <tr><td>category_name=list</td><td>list of categories by slug</td></tr>
    <tr><td>post_ids</td><td>list of posts by IDs</td></tr>
    <tr><td>post_slug</td><td>single post by specified post slug name</td></tr>
    <tr><td>WP_Query args</td><td>Any standard <a href="http://codex.wordpress.org/Class_Reference/WP_Query" alt="WP_Query Codex Entry" target="_blank">WP_Query</a> argument (not including those needing array()).
    <br />
    Using these options directly requires fairly advanced technical understanding, and is intended for advanced users.
    </td></tr>
</table>
<br />

You don't need to supply every option when you add the <code>[show_posts]</code> to your own content.
You can wrap the parameter values with double or single quotation marks if you want, but they aren't needed
unless the value has a space (e.g., the more_msg example).</p>

<hr />
<p style = "display:inline;padding-left:2.5em;text-indent:-1.7em;"><label><input type="checkbox" name='textWidgetShortcodes' id='textWidgetShortcodes'
        <?php 
    checked(atw_posts_getopt('textWidgetShortcodes'));
    ?>
 >&nbsp;
        Enable [shortcode] support for the Text Widget. Some themes and plugins already support this, but this allows you
        to add [show_posts] or [show_slider] directly into the standard Text Widget.</label></p>
<br />
<br />

<?php 
    atw_posts_save_showposts_button();
    ?>
    </form>
<?php 
}
function atw_show_content($slider, $filter = '')
{
    $cur_post_id = get_the_ID();
    /* We have to do our own sticky processing because WP is_sticky() will not work because we are in our own WP_Query,
     * and will thus never be on the home page which is one of the tests in the core is_sticky()
     */
    $sticky = is_sticky($cur_post_id);
    do_action('atw_show_sliders_post_pager', $slider);
    $saved_the_content_filter_key = atw_save_the_content_filters();
    if (!atw_posts_getopt('ignore_aspen_weaver') && (atw_posts_is_wvrx() || atw_posts_is_aspen() || atw_posts_is_wii()) || atw_posts_getopt('use_native_theme_templates') && atw_posts_theme_has_templates()) {
        if ($sticky) {
            echo '<div class="sticky">';
        }
        if (atw_posts_is_wvrx()) {
            get_template_part('templates/content', get_post_format());
        } else {
            if (function_exists('twentysixteen_setup')) {
                // custom support for twentysixteen
                get_template_part('template-parts/content', get_post_format());
            } else {
                get_template_part('content', get_post_format());
            }
        }
        if ($sticky) {
            echo '</div>';
        }
        echo "<div style='clear:both;'></div>\n";
        atw_restore_the_content_filters($saved_the_content_filter_key);
        return;
    }
    if (WEAVER_SHOWPOSTS_TEMPLATE) {
        $template = atw_posts_get_filter_opt('post_template', $filter);
        if ($template != '') {
            atw_posts_do_template($slider, $template);
            atw_restore_the_content_filters($saved_the_content_filter_key);
            return;
        }
    }
    $add_class = 'atw-post';
    if ($sticky) {
        $add_class .= ' sticky';
    }
    ?>
    <article id="post-<?php 
    the_ID();
    ?>
" <?php 
    post_class($add_class);
    ?>
>
	<header class="atw-entry-header">
<?php 
    if (!atw_trans_get('hide_title')) {
        // ========== TITLE
        ?>
	    <hgroup class="atw-entry-hdr"><h2 class="atw-entry-title">
	    <a href="<?php 
        the_permalink();
        ?>
" title="<?php 
        printf(esc_attr(__('Permalink to %s', 'show-posts')), the_title_attribute('echo=0'));
        ?>
" rel="bookmark"><?php 
        the_title();
        ?>
</a>
	   </h2></hgroup>

<?php 
    }
    if (!atw_trans_get('hide_top_info')) {
        // ============ TOP META
        ?>
	    <div class="atw-entry-meta">
		<div class="atw-entry-meta-icons">
<?php 
        printf(__('<span class="entry-date"><a href="%1$s" title="%2$s" rel="bookmark"><time datetime="%3$s" pubdate>%4$s</time></a></span> <span class="by-author"><span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'show-posts'), esc_url(get_permalink()), esc_attr(get_the_time()), esc_attr(get_the_date('c')), esc_html(get_the_date()), esc_url(get_author_posts_url(get_the_author_meta('ID'))), sprintf(esc_attr(__('View all posts by %s', 'show-posts')), get_the_author()), esc_html(get_the_author()));
        if (atw_trans_get('show_avatar') != '' && atw_trans_get('show_avatar') != 'no') {
            echo '&nbsp;&nbsp;' . get_avatar(get_the_author_meta('user_email'), 22, null, 'avatar');
        }
        ?>
		</div><!-- .atw-entry-meta-icons -->
	    </div><!-- .atw-entry-meta -->
<?php 
    }
    ?>
	</header><!-- .atw-entry-header -->
<?php 
    if (atw_trans_get('show') == 'title') {
        echo '</article><!-- #post-' . get_the_ID() . '-->';
        atw_restore_the_content_filters($saved_the_content_filter_key);
        return;
    }
    if (atw_trans_get('show') == 'title_featured') {
        if (get_post_thumbnail_id()) {
            $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
            // (url, width, height)
            $href = $image[0];
            ?>
		<p class='atw-featured-image'><a href="<?php 
            echo $href;
            ?>
"><?php 
            esc_url(the_post_thumbnail('thumbnail'));
            ?>
</a></p>
<?php 
        }
        echo '</article><!-- #post-' . get_the_ID() . '-->';
        atw_restore_the_content_filters($saved_the_content_filter_key);
        return;
    }
    if (atw_trans_get('show') == 'excerpt') {
        // =================== EXCERPT
        ?>
	    <div class="atw-entry-summary atw-cf">
<?php 
        atw_show_post_content($slider);
        ?>
	    </div><!-- .atw-entry-summary -->
<?php 
    } else {
        // ================== FULL CONTENT
        ?>
	    <div class="atw-entry-content atw-cf">
<?php 
        atw_show_post_content($slider);
        ?>
	    </div><!-- .atw-entry-content -->
<?php 
    }
    if (!atw_trans_get('hide_bottom_info')) {
        // ================= BOTTOM META
        ?>

	    <footer class="atw-entry-utility">
		<div class="atw-entry-meta-icons">
<?php 
        $categories_list = get_the_category_list(__(', ', 'show-posts'));
        if ($categories_list) {
            ?>
		    <span class="cat-links">
<?php 
            echo $categories_list;
            ?>
		    </span>
<?php 
        }
        // End if categories
        $tags_list = get_the_tag_list('', __(', ', 'show-posts'));
        if ($tags_list) {
            ?>
			<span class="tag-links">
<?php 
            echo $tags_list;
            ?>
			</span>
<?php 
        }
        // End if $tags_list
        if (comments_open()) {
            ?>
		    <span class="comments-link">
<?php 
            comments_popup_link(__('Leave a reply', 'show-posts'), __('<b>1</b> Reply', 'show-posts'), __('<b>%</b> Replies', 'show-posts'), 'leave-reply');
            ?>

		    </span><div style="clear:both;"></div>
<?php 
        }
        // End if comments_open()
        ?>
		</div><!-- .entry-meta-icons -->
	    </footer><!-- .atw-entry-utility -->
<?php 
    }
    edit_post_link(__('Edit', 'show-posts'), '<span class="atw-edit-link">', '</span>');
    ?>
	</article><!-- #post-<?php 
    the_ID();
    ?>
 -->

<?php 
    atw_restore_the_content_filters($saved_the_content_filter_key);
}
function atw_posts_setup_shortcodes()
{
    remove_shortcode('show_posts');
    // alias
    add_shortcode('show_posts', 'atw_show_posts_sc');
    if (function_exists('atw_posts_getopt') && atw_posts_getopt('textWidgetShortcodes')) {
        add_filter('widget_text', 'atw_post_text_widget_shortcode');
    }
}
function atw_posts_set_slider_opt($opt, $val, $current_slider = '', $save = true)
{
    // set a slider value
    global $atw_posts_opts_cache;
    if ($current_slider == '') {
        $current_slider = atw_posts_getopt('current_slider');
    }
    $atw_posts_opts_cache['sliders'][$current_slider][$opt] = $val;
    if ($save) {
        atw_posts_wpupdate_option('atw_posts_settings', $atw_posts_opts_cache);
    }
}