Example #1
0
function ts_title_shortcode($atts, $content = null)
{
    $atts = shortcode_atts(array('size' => '3', 'align' => '', 'bold' => '', 'line_style' => '', 'style' => '', 'padding_top' => '0', 'padding_bottom' => '0', 'margin_top' => '0', 'margin_bottom' => '0', 'color' => '', 'border_color' => ''), $atts);
    $hex = $class = $style = $h_atts = $span_class_style = '';
    $size = $font_size = preg_replace("/[^0-9]*/", "", $atts['size']);
    $size = ts_essentials_number_within_range($size, 1, 6) ? $size : 3;
    if ($font_size > 6) {
        $style .= 'font-size:' . $font_size . 'px;';
        $size = 1;
    }
    $default_align = ts_essentials_option_vs_default('rtl', 0) == 1 ? 'right' : 'left';
    $align_options = array('center', 'centered', 'middle', 'right', 'left');
    $align = in_array($atts['align'], $align_options) ? in_array($atts['align'], array('centered', 'middle')) ? 'text-center' : 'text-' . $atts['align'] : 'text-' . $default_align;
    $line_style_options = array('none', 'line', 'single', 'single-line', 'dashed', 'dotted', 'double-line', 'double-dashed', 'double-dotted', 'underline-full', 'underline-text');
    $line_style = $atts['line_style'] ? $atts['line_style'] : $atts['style'];
    $line_style = in_array($line_style, $line_style_options) ? $line_style : 'none';
    $line_style = in_array($line_style, array('single', 'single-line')) ? 'line' : $line_style;
    $padding_top = max(preg_replace("/[^0-9]*/", "", $atts['margin_top']), preg_replace("/[^0-9]*/", "", $atts['padding_top']));
    $padding_top = preg_replace("/[^0-9]*/", "", $padding_top);
    $padding_bottom = max(preg_replace("/[^0-9]*/", "", $atts['margin_bottom']), preg_replace("/[^0-9]*/", "", $atts['padding_bottom']));
    $padding_bottom = preg_replace("/[^0-9]*/", "", $padding_bottom);
    $color = $atts['color'] ? $atts['color'] : '';
    if ($color && $color[0] == '#') {
        $style .= 'color:' . $color . ';';
        $color = '';
    } else {
        $class .= $color ? 'color-shortcode ' . $color : '';
    }
    $no_line_thru = in_array($line_style, array('none', 'underline-text', 'underline-full')) ? true : false;
    $no_table = $no_line_thru ? 'no-table' : '';
    $class .= ts_essentials_attr_is_true($atts['bold']) ? ' bold' : '';
    $class .= ' ' . $align;
    $border_color = $atts['border_color'] ? $atts['border_color'] : '';
    $title_sep_class_style = 'class="title-sep"';
    if (substr($border_color, 0, 1) == '#') {
        $title_sep_class_style = 'class="title-sep" style="border-color:' . esc_attr($border_color) . ' !important;"';
        $span_class_style = 'style="border-color:' . esc_attr($border_color) . ' !important;"';
        $border_color = '';
    }
    $title_sep_class_style = $border_color ? 'class="title-sep border-' . esc_attr($border_color) . '"' : $title_sep_class_style;
    $span_class_style = $border_color ? 'class="border-' . esc_attr($border_color) . '"' : $span_class_style;
    $h_atts .= ' style="' . esc_attr($style) . '"';
    $h_atts .= ' class="title-shortcode-htag ' . esc_attr($class) . '"';
    $html = '<div class="title-shortcode ' . esc_attr($no_table) . ' ' . esc_attr($align) . ' ' . esc_attr($line_style) . '" style="padding-top:' . intval($padding_top) . 'px;padding-bottom:' . intval($padding_bottom) . 'px;">';
    if ($align == 'text-center') {
        $html .= $no_line_thru ? '' : '<div class="title-sep-container"><div ' . $title_sep_class_style . '>&nbsp;</div></div>';
        $html .= '<h' . absint($size) . ' ' . $h_atts . '><span ' . $span_class_style . '>' . do_shortcode($content) . '</span></h' . absint($size) . '>';
        $html .= $no_line_thru ? '' : '<div class="title-sep-container"><div ' . $title_sep_class_style . '>&nbsp;</div></div>';
    } elseif ($align == 'text-right') {
        $rtl = ts_essentials_option_vs_default('rtl', 0) == 1 ? true : false;
        $html .= $no_line_thru ? '' : ($rtl ? '' : '<div class="title-sep-container"><div ' . $title_sep_class_style . '></div></div>');
        $html .= '<h' . absint($size) . ' ' . $h_atts . '><span ' . $span_class_style . '>' . do_shortcode($content) . '</span></h' . absint($size) . '>';
        $html .= $no_line_thru ? '' : ($rtl ? '<div class="title-sep-container"><div ' . $title_sep_class_style . '></div></div>' : '');
    } else {
        $rtl = ts_essentials_option_vs_default('rtl', 0) == 1 ? true : false;
        $html .= $no_line_thru ? '' : ($rtl ? '<div class="title-sep-container"><div ' . $title_sep_class_style . '></div></div>' : '');
        $html .= '<h' . absint($size) . ' ' . $h_atts . '><span ' . $span_class_style . '>' . do_shortcode($content) . '</span></h' . absint($size) . '>';
        $html .= $no_line_thru ? '' : ($rtl ? '' : '<div class="title-sep-container"><div ' . $title_sep_class_style . '></div></div>');
    }
    $html .= '</div>';
    return $html;
}
Example #2
0
    function widget($args, $instance)
    {
        global $wpdb, $post;
        $tab1 = $instance['tab1'];
        $tab2 = $instance['tab2'];
        $tab3 = $instance['tab3'];
        $crop_thumbs = isset($instance['crop_thumbs']) ? $instance['crop_thumbs'] : 1;
        $count = ctype_digit($instance['count']) && ts_essentials_number_within_range($instance['count'], 1, 20) ? $instance['count'] : 5;
        echo ts_essentials_escape($args['before_widget']);
        echo '<div class="ts-tabs-widget tabs-widget shortcode-tabs simple-tabs horizontal-tabs">';
        $tab = array();
        ?>
	
		<div class="tab-widget">

			<ul class="tab-header clearfix">
				<li class="active"><?php 
        echo esc_html($tab1);
        ?>
</li>
				<li><?php 
        echo esc_html($tab2);
        ?>
</li>
				<li class="last"><?php 
        echo esc_html($tab3);
        ?>
</li>
			</ul>

            <div class="tab-contents">
			<div  class="tab-context visible">
                <ul>
				<?php 
        $popular_posts = '';
        $temp = $popular_posts;
        $popular_posts = new WP_Query(array('showposts' => intval($count), 'orderby' => 'comment_count'));
        while ($popular_posts->have_posts()) {
            $popular_posts->the_post();
            ?>
				
                    <li class="post-widget clearfix">
                        <?php 
            $img_url = false;
            $size = 'thumbnail';
            $img_id = get_post_thumbnail_id($popular_posts->post->ID);
            $photo = wp_get_attachment_image_src($img_id, $size);
            $img_url = isset($photo[0]) ? $photo[0] : '';
            $has_img = $img_url ? 'has-img' : '';
            if ($img_url) {
                ?>
                        <div class="widget-thumbnail">
                            <a href="<?php 
                echo get_permalink($popular_posts->post->ID);
                ?>
" class="thumb-link">
                                <img width="60" src="<?php 
                echo esc_url($img_url);
                ?>
" alt="<?php 
                echo esc_attr(get_the_title());
                ?>
"/>
                            </a>
                        </div><!-- / div.widget-thumbnail -->
                        <?php 
            }
            ?>

                        <div class="widget-context <?php 
            echo esc_attr($has_img);
            ?>
">
                            <h4><a href="<?php 
            echo get_permalink($popular_posts->post->ID);
            ?>
"><?php 
            the_title();
            ?>
</a></h4>
                            <small><?php 
            the_time('F j, Y');
            ?>
</small>
                        </div><!-- / div.widget-context -->

                    </li><!-- / div.post-widget -->

                <?php 
        }
        $popular_posts = $temp;
        echo '</ul></div>';
        echo '<div  class="tab-context"><ul>';
        $recentPosts = '';
        $temp = $recentPosts;
        $recentPosts = new WP_Query(array('showposts' => intval($count)));
        while ($recentPosts->have_posts()) {
            $recentPosts->the_post();
            ?>
                    <li class="post-widget clearfix">
                        <?php 
            $img_url = false;
            $size = 'thumbnail';
            $img_id = get_post_thumbnail_id($recentPosts->post->ID);
            $photo = wp_get_attachment_image_src($img_id, $size);
            $img_url = isset($photo[0]) ? $photo[0] : '';
            $has_img = $img_url ? 'has-img' : '';
            if ($img_url) {
                ?>
                        <div class="widget-thumbnail">
                            <a href="<?php 
                echo get_permalink($recentPosts->post->ID);
                ?>
" class="thumb-link">
                                <img width="60" src="<?php 
                echo esc_url($img_url);
                ?>
" alt="<?php 
                echo esc_attr(get_the_title());
                ?>
"/>
                            </a>
                        </div><!-- / div.widget-thumbnail -->
                        <?php 
            }
            ?>

                        <div class="widget-context <?php 
            echo esc_attr($has_img);
            ?>
">
                            <h4><a href="<?php 
            echo get_permalink($recentPosts->post->ID);
            ?>
"><?php 
            the_title();
            ?>
</a></h4>
                            <small><?php 
            the_time('F j, Y');
            ?>
</small>
                        </div><!-- / div.widget-context -->

                    </li><!-- / div.post-widget -->

                <?php 
        }
        $recentPosts = $temp;
        echo '</ul></div>';
        echo '<div class="tab-context"><ul>';
        $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_approved, comment_type, comment_author_url, SUBSTRING(comment_content,1,70) AS com_excerpt FROM {$wpdb->comments} LEFT OUTER JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT " . intval($count);
        $comments = $wpdb->get_results($sql);
        foreach ($comments as $comment) {
            ?>

					<li class="post-widget post-widget-comment clearfix">
						<div class="widget-thumbnail">
							<a href="<?php 
            echo get_permalink($comment->ID);
            ?>
#comment-<?php 
            echo esc_attr($comment->comment_ID);
            ?>
" title="<?php 
            echo esc_attr(strip_tags($comment->comment_author));
            ?>
 <?php 
            _e('on ', 'ThemeStockyard');
            echo esc_attr($comment->post_title);
            ?>
" class="thumb-link"><?php 
            echo get_avatar($comment, '60');
            ?>
</a>
						</div>
						
						<div class="widget-context">
							<a href="<?php 
            echo get_permalink($comment->ID);
            ?>
#comment-<?php 
            echo esc_attr($comment->comment_ID);
            ?>
" class="comm_link">
                                <h4><?php 
            echo esc_html(strip_tags($comment->comment_author));
            ?>
</h4>
                                <p>&#8220;<?php 
            echo ts_essentials_trim_text($comment->com_excerpt, 50);
            ?>
&#8221;</p>
                            </a>
                            <p class="small"><?php 
            _e('on', 'ThemeStockyard');
            ?>
 <a href="<?php 
            echo get_permalink($comment->comment_post_ID);
            ?>
" class="post-link"><?php 
            echo ts_essentials_trim_text(get_the_title($comment->comment_post_ID), 36);
            ?>
</a></p>
						</div>
					</li>
				<?php 
        }
        echo '</ul></div>';
        wp_reset_postdata();
        echo '</div>';
        echo '</div>';
        echo '</div>';
        echo ts_essentials_escape($args['after_widget']);
    }