Exemple #1
0
function custom_body_class($classes)
{
    global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome;
    // Top level
    if (is_handheld()) {
        $classes[] = "handheld";
    }
    if (is_mobile()) {
        $classes[] = "mobile";
    }
    if (is_ios()) {
        $classes[] = "ios";
    }
    if (is_tablet()) {
        $classes[] = "tablet";
    }
    // Specific
    if (is_iphone()) {
        $classes[] = "iphone";
    }
    if (is_ipad()) {
        $classes[] = "ipad";
    }
    if (is_ipod()) {
        $classes[] = "ipod";
    }
    if (is_android()) {
        $classes[] = "android";
    }
    if (is_blackberry()) {
        $classes[] = "blackberry";
    }
    if (is_opera_mobile()) {
        $classes[] = "opera-mobile";
    }
    if (is_palm()) {
        $classes[] = "palm";
    }
    if (is_symbian()) {
        $classes[] = "symbian";
    }
    if (is_windows_mobile()) {
        $classes[] = "windows-mobile";
    }
    if (is_lg()) {
        $classes[] = "lg";
    }
    if (is_motorola()) {
        $classes[] = "motorola";
    }
    if (is_nokia()) {
        $classes[] = "nokia";
    }
    if (is_samsung()) {
        $classes[] = "samsung";
    }
    if (is_samsung_galaxy_tab()) {
        $classes[] = "samsung-galaxy-tab";
    }
    if (is_sony_ericsson()) {
        $classes[] = "sony-ericsson";
    }
    if (is_nintendo()) {
        $classes[] = "nintendo";
    }
    // Computer browser
    if (!is_handheld()) {
        $classes[] = "desktop";
    }
    if ($is_lynx) {
        $classes[] = "lynx";
    }
    if ($is_gecko) {
        $classes[] = "gecko";
    }
    if ($is_opera) {
        $classes[] = "opera";
    }
    if ($is_NS4) {
        $classes[] = "ns4";
    }
    if ($is_safari) {
        $classes[] = "safari";
    }
    if ($is_chrome) {
        $classes[] = "chrome";
    }
    if ($is_IE) {
        $classes[] = "ie";
    }
    // IE Version check
    $ie_check = array();
    $ie_classes = array('ie7', 'ie8', 'ie9', 'ie10');
    $version = 7;
    while ($version < 11) {
        $ie_check[] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ' . $version . '.') !== FALSE;
        ++$version;
    }
    $ie = '';
    foreach ($ie_check as $key => $value) {
        if ($value == 1) {
            $ie = $ie_classes[$key] . ' oldie';
        }
    }
    $classes[] = $ie;
    // Check user logged in?
    if (!is_user_logged_in()) {
        $classes[] = 'not-login';
    }
    return $classes;
}
    function widget($args, $instance)
    {
        $cache = wp_cache_get('widget_dw_focus_recent_posts', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (!isset($args['widget_id'])) {
            $args['widget_id'] = $this->id;
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', 'dw_focus') : $instance['title'], $instance, $this->id_base);
        if (empty($instance['number']) || !($number = absint($instance['number']))) {
            $number = 10;
        }
        $interval = isset($instance['interval']) ? $instance['interval'] : 0;
        $tax_query = array();
        if (!empty($instance['post-format'])) {
            $tax_query = array(array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-' . $instance['post-format']), 'operator' => 'IN'));
        }
        $r = new WP_Query(apply_filters('widget_posts_args', array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category__in' => $instance['category'], 'tax_query' => $tax_query)));
        if (is_mobile() || is_kindle() || is_samsung_galaxy_tab() || is_nexus()) {
            $col = 1;
            $row = 1;
            $size = 'large';
        } else {
            $col = 4;
            $row = 4;
            $size = 'medium';
        }
        if ($r->have_posts()) {
            $i = 0;
            //Dectect first post
            ?>
        
        <?php 
            echo $before_widget;
            ?>
        <?php 
            echo $before_title . $title . $after_title;
            ?>
        <div id="dwqa-news-carousel-<?php 
            echo $this->id;
            ?>
" class="carousel slide" data-pause="hover" data-interval="<?php 
            echo $interval > 0 ? $interval * 1000 : 'false';
            ?>
">
            <div class="carousel-inner">
                <div class="active item">
                    <div class="row-fluid">
            <?php 
            $i = 0;
            while ($r->have_posts()) {
                $r->the_post();
                ?>
                <?php 
                if ($i != 0 && $i % $col == 0) {
                    ?>
                    </div>
                </div>
                <div class="item">
                    <div class="row-fluid">
                <?php 
                }
                ?>
                    <?php 
                $class = 'span3';
                if (has_post_thumbnail(get_the_ID())) {
                    $class .= ' has-thumbnail';
                }
                ?>
                    <article <?php 
                post_class($class);
                ?>
>
                        <?php 
                if (has_post_thumbnail(get_the_ID())) {
                    ?>
                        <div class="entry-thumbnail">
                            <a href="<?php 
                    the_permalink();
                    ?>
" title="<?php 
                    echo esc_attr(get_the_title() ? get_the_title() : get_the_ID());
                    ?>
">
                                <?php 
                    echo dw_focus_post_format_icons($this);
                    ?>
                                <?php 
                    the_post_thumbnail($size);
                    ?>
                            </a>
                        </div>
                        <?php 
                }
                ?>
                        <h2 class="entry-title"><a href="<?php 
                the_permalink();
                ?>
" title="<?php 
                echo esc_attr(get_the_title() ? get_the_title() : get_the_ID());
                ?>
"><?php 
                the_title();
                ?>
</a></h2>
                        <div class="entry-meta">
                            <time datetime="<?php 
                echo get_post_time('c');
                ?>
" class="entry-date"><?php 
                echo get_post_time('d.m.Y');
                ?>
</time>
                        </div>
                    </article>
            <?php 
                $i++;
            }
            ?>
                    </div>
                </div>
            </div>

            <a class="carousel-control left" href="#dwqa-news-carousel-<?php 
            echo $this->id;
            ?>
" data-slide="prev"><i class="icon-chevron-left"></i></a>
            <a class="carousel-control right" href="#dwqa-news-carousel-<?php 
            echo $this->id;
            ?>
" data-slide="next"><i class="icon-chevron-right"></i></a>
            <div class="carousel-nav"><ul></ul></div>
        </div>
        <?php 
            echo $after_widget;
            // Reset the global $the_post as this query will have stomped on it
            wp_reset_postdata();
        }
        $cache[$args['widget_id']] = ob_get_flush();
        wp_cache_set('widget_recent_posts', $cache, 'widget');
    }