Ejemplo n.º 1
0
function build_lshowcase($order = "menu_order", $category = "", $activeurl = "new", $style = "normal", $interface = "grid", $tooltip = "false", $limit = -1, $slidersettings = "", $imgwo = 0, $ids = "0")
{
    global $lshowcase_slider_count;
    global $post;
    //will be used to include carousel code before tooltip code.
    $carousel = false;
    //image size override
    $imgwidth = "";
    if ($imgwo != "" && $imgwo != 0 && $imgwo != '0') {
        $imgwidth = explode(',', $imgwo);
    }
    $html = "";
    $thumbsize = "lshowcase-thumb";
    $class = "lshowcase-thumb";
    $divwrap = "lshowcase-wrap-normal";
    $divwrapextra = "";
    $divboxclass = "lshowcase-box-normal";
    $divboxinnerclass = "lshowcase-boxInner-normal";
    if ($order == 'none') {
        $order = 'menu_order';
    }
    if ($interface != "grid" && $interface != "hcarousel" && $interface != "vcarousel") {
        $columncount = substr($interface, 4);
        $divboxclass = "lshowcase-box-" . $columncount;
        $divboxinnerclass = "lshowcase-boxInner";
        $divwrap = "lshowcase-wrap-responsive";
    }
    if ($interface == "hcarousel") {
        $divwrapextra = "style='display:none;' class='lshowcase-wrap-carousel-" . $lshowcase_slider_count . "'";
        $class = "lshowcase-thumb";
        $divwrap = "lshowcase-wrap-normal";
        $divboxclass = "lshowcase-box-normal";
        $divboxinnerclass = "lshowcase-slide";
        $carousel = true;
        lshowcase_add_carousel_js();
    }
    $stylearray = lshowcase_styles_array();
    $class = $stylearray[$style]["class"];
    if ($style == 'jgrayscale') {
        lshowcase_add_grayscale_js();
    }
    //tooltip code
    if ($tooltip == 'true' || $tooltip == 'true-description') {
        $class .= " lshowcase-tooltip";
        lshowcase_add_tooltip_js($carousel);
    }
    $postsperpage = -1;
    $nopaging = true;
    if ($limit >= 1) {
        $postsperpage = $limit;
        $nopaging = false;
    }
    $ascdesc = 'DESC';
    if ($order == 'name' || $order == 'menu_order') {
        $ascdesc = 'ASC';
    }
    $args = array('post_type' => 'lshowcase', 'lshowcase-categories' => $category, 'orderby' => $order, 'order' => $ascdesc, 'posts_per_page' => $postsperpage, 'nopaging' => $nopaging, 'suppress_filters' => true);
    if ($ids != '0' && $ids != '') {
        $postarray = explode(',', $ids);
        if ($postarray[0] != '') {
            $args['post__in'] = $postarray;
        }
    }
    $loop = new WP_Query($args);
    // to force random again - uncomment in case random is not working
    // if($order=='rand' ) {
    // shuffle( $loop->posts );
    // }
    if (!$loop->have_posts()) {
        return "<!-- Empty Logos Showcase Container -->";
    }
    $html .= '<div class="lshowcase-clear-both">&nbsp;</div>';
    $html .= '<div class="lshowcase-logos"><div ' . $divwrapextra . ' >';
    while ($loop->have_posts()) {
        $loop->the_post();
        if (has_post_thumbnail()) {
            //check if there is img overide settings
            if (is_array($imgwidth)) {
                $thumbsize = $imgwidth;
            }
            $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $thumbsize);
            $lshowcase_options = get_option('lshowcase-settings');
            $width = $image[1];
            $height = " height = '" . $image[2] . "' ";
            $dwidth = $lshowcase_options['lshowcase_thumb_width'];
            $desc = get_post_meta(get_the_ID(), 'urldesc', true);
            //to filter the quotes and make them html compatible
            $desc = str_replace("'", '&apos;', $desc);
            if (is_array($imgwidth)) {
                $dwidth = $thumbsize[0];
            }
            if ($interface != "hcarousel") {
                $html .= "<div class='" . $divwrap . "'>";
                $html .= '<div class="' . $divboxclass . '">';
                $height = "";
            }
            if ($interface == "grid") {
                $html .= '<div class="' . $divboxinnerclass . '" style="width:' . $dwidth . 'px; align:center; text-align:center;">';
            } else {
                $html .= '<div class="' . $divboxinnerclass . '">';
            }
            $url = get_post_meta(get_the_ID(), 'urllink', true);
            //set default attributes for tooltip
            if ($tooltip == "true" || $tooltip == "false") {
                $alt = $desc;
                $title = the_title_attribute('echo=0');
            }
            //switch attributes to reflect on toolip
            if ($tooltip == "true-description") {
                $title = $desc;
                $alt = the_title_attribute('echo=0');
            }
            if ($activeurl != "inactive" && $url != "") {
                $target = "";
                if ($activeurl == "new") {
                    $target = "target='_blank'";
                }
                if ($activeurl == "new_nofollow") {
                    $target = "target='_blank' rel='nofollow'";
                }
                $html .= "<a href='" . $url . "' alt='" . $alt . "' " . $target . ">";
                $html .= "<img src='" . $image[0] . "' width='" . $width . "' " . $height . " alt='" . $alt . "' title='" . $title . "' class='" . $class . "' />";
                // $html .= get_the_post_thumbnail($post->ID,$thumbsize,array( 'class' => $class, 'alt'	=> $alt, 'title' => $title));
                $html .= "</a>";
            } else {
                $html .= "<img src='" . $image[0] . "' width='" . $width . "' " . $height . " alt='" . $alt . "' title='" . $title . "' class='" . $class . "' />";
                // $html .= get_the_post_thumbnail($post->ID,$thumbsize,array( 'class' => $class, 'alt'	=> $alt, 'title' => $title));
            }
            //uncomment if you want the description content to display below the images.
            //will not work well on responsive grid layout
            //$html .= "<div class='lshowcase-description'>".$desc."</div>";
            if ($interface != "hcarousel") {
                $html .= "</div></div>";
            }
            $html .= "</div>";
        }
    }
    // Restore original Post Data
    wp_reset_postdata();
    $html .= '</div></div><div class="lshowcase-clear-both">&nbsp;</div>';
    //Add Carousel Code
    if ($interface == 'hcarousel') {
        lshowcase_bxslider_options_js($lshowcase_slider_count, $slidersettings, $dwidth);
        $lshowcase_slider_count++;
    }
    lshowcase_add_main_css();
    return $html;
}
Ejemplo n.º 2
0
function build_lshowcase($order = "menu_order", $category = "", $activeurl = "new", $style = "normal", $interface = "grid", $tooltip = "false", $description = "false", $limit = -1, $slidersettings = "", $imgwo = 0, $ids = "0", $filter = "false", $custom_class = '')
{
    global $lshowcase_slider_count;
    global $post;
    add_action('wp_footer', 'lshowcase_custom_css', 99);
    //will be used to include carousel code before tooltip code.
    $carousel = false;
    //image size override
    $imgwidth = "";
    if ($imgwo != "" && $imgwo != 0 && $imgwo != '0') {
        $imgwidth = explode(',', $imgwo);
    }
    $html = "";
    if ($custom_class != '') {
        $html = '<div class="' . $custom_class . '">';
    }
    //if there's a filter active:
    if ($filter != 'false' && $interface != 'hcarousel') {
        $html .= lshowcase_build_filter($filter, $category);
    }
    $thumbsize = "lshowcase-thumb";
    $class = "lshowcase-thumb";
    $divwrap = "lshowcase-wrap-normal";
    $divwrapextra = "";
    $divboxclass = "lshowcase-box-normal";
    $divboxinnerclass = "lshowcase-boxInner-normal";
    if ($order == 'none') {
        $order = 'menu_order';
    }
    if ($interface != "grid" && $interface != "hcarousel" && $interface != "vcarousel") {
        $columncount = substr($interface, 4);
        $divboxclass = "lshowcase-wrap-responsive";
        $divboxinnerclass = "lshowcase-boxInner";
        $divwrap = "lshowcase-box-" . $columncount;
    }
    if ($interface == "hcarousel") {
        $options = get_option('lshowcase-settings');
        $mode = isset($options['lshowcase_carousel_mode']) ? $options['lshowcase_carousel_mode'] : 'horizontal';
        $divwrapextra = "style='display:none;' class='lshowcase-wrap-carousel-" . $lshowcase_slider_count . "'";
        $class = "lshowcase-thumb";
        $divwrap = "lshowcase-wrap-normal";
        $divboxclass = "lshowcase-box-normal";
        $divboxinnerclass = "lshowcase-slide";
        $carousel = true;
        lshowcase_add_carousel_js();
        //if mode is horizontal we add extra call to control better css
        if ($mode == 'horizontal') {
            $divboxinnerclass = "lshowcase-slide lshowcase-horizontal-slide";
        }
    }
    $stylearray = lshowcase_styles_array();
    $class = $stylearray[$style]["class"];
    if ($style == 'jgrayscale') {
        lshowcase_add_grayscale_js();
    }
    //tooltip code
    if ($tooltip == 'true' || $tooltip == 'true-description') {
        $class .= " lshowcase-tooltip";
        lshowcase_add_tooltip_js($carousel);
    }
    $postsperpage = -1;
    $nopaging = true;
    if ($limit >= 1) {
        $postsperpage = $limit;
        $nopaging = false;
    }
    $ascdesc = 'DESC';
    if ($order == 'name' || $order == 'title' || $order == 'menu_order') {
        $ascdesc = 'ASC';
    }
    $args = array('post_type' => 'lshowcase', 'lshowcase-categories' => $category, 'orderby' => $order, 'order' => $ascdesc, 'posts_per_page' => $postsperpage, 'nopaging' => $nopaging, 'suppress_filters' => true);
    if ($ids != '0' && $ids != '') {
        $postarray = explode(',', $ids);
        if ($postarray[0] != '') {
            $args['post__in'] = $postarray;
        }
    }
    $loop = new WP_Query($args);
    // to force random again - uncomment in case random is not working
    // if($order=='rand' ) {
    // shuffle( $loop->posts );
    // }
    if (!$loop->have_posts()) {
        return "<!-- Empty Logos Showcase Container -->";
    }
    $html .= '<div class="lshowcase-clear-both">&nbsp;</div>';
    $html .= '<div class="lshowcase-logos"><div ' . $divwrapextra . ' >';
    $lshowcase_options = get_option('lshowcase-settings');
    while ($loop->have_posts()) {
        $loop->the_post();
        //asign custom image url to a variable, to use later
        $custom_img_url = get_post_meta(get_the_ID(), '_lscustomimageurl', true);
        if (has_post_thumbnail() || $lshowcase_options['lshowcase_default_image'] != '' || $custom_img_url != '') {
            // if (1==1):
            //check if there is img overide settings
            if (is_array($imgwidth)) {
                $thumbsize = $imgwidth;
            }
            $width = '';
            $height = '';
            $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $thumbsize);
            $dwidth = $lshowcase_options['lshowcase_thumb_width'];
            $desc = get_post_meta(get_the_ID(), 'urldesc', true);
            if ($image != false) {
                $width = $image[1];
                $height = " height = '" . $image[2] . "' ";
            }
            if ($image == false && $custom_img_url != '') {
                $image = array();
                $image[0] = $custom_img_url;
                //url to image
                $image[1] = $lshowcase_options['lshowcase_thumb_width'];
                //image width
                $image[2] = $lshowcase_options['lshowcase_thumb_height'];
                //image height
                $width = $image[1];
                $height = "";
            }
            if ($image == false && $custom_img_url == '' && $lshowcase_options['lshowcase_default_image'] != '') {
                $image = array();
                $image[0] = $lshowcase_options['lshowcase_default_image'];
                //url to image
                $image[1] = $lshowcase_options['lshowcase_thumb_width'];
                //image width
                $image[2] = $lshowcase_options['lshowcase_thumb_height'];
                //image height
                $width = $image[1];
                $height = "";
            }
            //to filter the quotes and make them html compatible
            $desc = str_replace("'", '&apos;', $desc);
            if (is_array($imgwidth)) {
                $dwidth = $thumbsize[0];
            }
            //if it's an SVG
            $file_info = pathinfo($image[0]);
            if (isset($file_info['extension']) && $file_info['extension'] == 'svg') {
                $width = $lshowcase_options['lshowcase_thumb_width'];
                $height = " height = '" . $lshowcase_options['lshowcase_thumb_height'] . "' ";
                if (is_array($imgwidth)) {
                    $width = $thumbsize[0];
                    $height = " height = '" . $thumbsize[1] . "' ";
                }
            }
            //get categories to add as classes
            $cat = $filter != 'false' ? ' lshowcase-filter-active ' : ' ';
            $terms = get_the_terms(get_the_ID(), 'lshowcase-categories');
            if (is_array($terms)) {
                foreach ($terms as $term) {
                    $cat .= 'ls-' . $term->slug . ' ';
                }
            }
            if ($interface != "hcarousel") {
                $html .= "<div class='" . $divwrap . $cat . "'>";
                $html .= '<div class="' . $divboxclass . '">';
                //$height = "";
            }
            if ($interface == "grid") {
                $html .= '<div class="' . $divboxinnerclass . '" style="width:' . $dwidth . 'px; align:center; text-align:center;">';
            } else {
                $html .= '<div class="' . $divboxinnerclass . '">';
            }
            $url = get_post_meta(get_the_ID(), 'urllink', true);
            //set default attributes for tooltip
            if ($tooltip == "true") {
                $alt = $desc;
                $title = the_title_attribute('echo=0');
            }
            //switch attributes to reflect on toolip
            if ($tooltip == "true-description") {
                $title = $desc;
                $alt = the_title_attribute('echo=0');
            }
            //if tooltip is off
            if ($tooltip == "false") {
                $title = '';
                $alt = the_title_attribute('echo=0');
            }
            //try out flex div
            //$html .= '<div class="lshowcase-flexdiv">';
            //to display info above (not in shortcode generator)
            if ($description == "true-above" || $description == "true-description-above" || $description == "true-title-above-description-below") {
                $lsdesc = the_title_attribute('echo=0');
                if ($description == "true-description-above") {
                    $lsdesc = $desc;
                }
                $html .= "<div class='lshowcase-description'>" . nl2br($lsdesc) . "</div>";
            }
            //inline styles form custom spacing options
            $inlinestyle = '';
            //image spacing values
            $percentage = get_post_meta(get_the_ID(), '_lspercentage', true);
            if ($percentage != '') {
                $inlinestyle .= 'height:auto; max-width:' . $percentage . '%;';
            }
            $ptop = get_post_meta(get_the_ID(), '_lsptop', true) != '' ? 'padding-top:' . get_post_meta(get_the_ID(), '_lsptop', true) . ';' : '';
            $pright = get_post_meta(get_the_ID(), '_lspright', true) != '' ? 'padding-right:' . get_post_meta(get_the_ID(), '_lspright', true) . ';' : '';
            $pbottom = get_post_meta(get_the_ID(), '_lspbottom', true) != '' ? 'padding-bottom:' . get_post_meta(get_the_ID(), '_lspbottom', true) . ';' : '';
            $pleft = get_post_meta(get_the_ID(), '_lspleft', true) != '' ? 'padding-left:' . get_post_meta(get_the_ID(), '_lspleft', true) . ';' : '';
            $mtop = get_post_meta(get_the_ID(), '_lsmtop', true) != '' ? 'margin-top:' . get_post_meta(get_the_ID(), '_lsmtop', true) . ';' : '';
            $mright = get_post_meta(get_the_ID(), '_lsmright', true) != '' ? 'margin-right:' . get_post_meta(get_the_ID(), '_lsmright', true) . ';' : '';
            $mbottom = get_post_meta(get_the_ID(), '_lsmbottom', true) != '' ? 'margin-bottom:' . get_post_meta(get_the_ID(), '_lsmbottom', true) . ';' : '';
            $mleft = get_post_meta(get_the_ID(), '_lsmleft', true) != '' ? 'margin-left:' . get_post_meta(get_the_ID(), '_lsmleft', true) . ';' : '';
            $inlinestyle .= $ptop . $pright . $pbottom . $pleft . $mtop . $mright . $mbottom . $mleft;
            $instyle = $inlinestyle != '' ? "style='" . $inlinestyle . "'" : '';
            if ($activeurl != "inactive" && $url != "") {
                $target = "";
                if ($activeurl == "new") {
                    $target = "target='_blank'";
                }
                if ($activeurl == "new_nofollow") {
                    $target = "target='_blank' rel='nofollow'";
                }
                //to make some nofollow
                //include #nofollow in the end of the link
                /*
                if (strpos($url,'#nofollow') !== false) {
                   $target = "target='_blank' rel='nofollow'";
                    $url = str_replace('#nofollow', '', $url);
                }
                */
                $html .= "<a href='" . $url . "' " . $target . ">";
                $html .= "<img src='" . $image[0] . "' width='" . $width . "' " . $height . " alt='" . $alt . "' title='" . $title . "' class='" . $class . "' " . $instyle . " />";
                // $html .= get_the_post_thumbnail($post->ID,$thumbsize,array( 'class' => $class, 'alt'	=> $alt, 'title' => $title));
                $html .= "</a>";
            } else {
                $html .= "<img src='" . $image[0] . "' width='" . $width . "' " . $height . " alt='" . $alt . "' title='" . $title . "' class='" . $class . "' " . $instyle . " />";
                // $html .= get_the_post_thumbnail($post->ID,$thumbsize,array( 'class' => $class, 'alt'	=> $alt, 'title' => $title));
            }
            //to display info below
            if ($description == "true" || $description == "true-description" || $description == "true-title-above-description-below") {
                $lsdesc = the_title_attribute('echo=0');
                if ($description == "true-description" || $description == "true-title-above-description-below") {
                    $lsdesc = $desc;
                }
                //to make it clickable
                if ($activeurl != "inactive" && $url != "") {
                    //$lsdesc = "<a href='" . $url . "' " . $target . ">".$lsdesc."</a>";
                }
                $html .= "<div class='lshowcase-description'>" . nl2br($lsdesc) . "</div>";
            }
            //close flex div (contains image and eventually the description)
            //$html .= '</div>';
            if ($interface != "hcarousel") {
                $html .= "</div></div>";
            }
            $html .= "</div>";
        }
    }
    // Restore original Post Data
    wp_reset_postdata();
    $html .= '</div></div><div class="lshowcase-clear-both">&nbsp;</div>';
    //Add Carousel Code
    if ($interface == 'hcarousel') {
        lshowcase_bxslider_options_js($lshowcase_slider_count, $slidersettings, $dwidth);
        $lshowcase_slider_count++;
    }
    lshowcase_add_main_css();
    /* Display category used before logos grid */
    /* if($category!='') {
    
    		$cat = get_term_by('slug', $category, 'lshowcase-categories');
    
    		if(is_object($cat)) {
    
    			$catname = $cat->name;
    			$html = '<h2>'.$catname.'</h2>'.$html;
    		
    		}
    
    	}
    
    	*/
    if ($custom_class != '') {
        $html .= '</div>';
    }
    return $html;
}