PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/Ultimate_VC_Addons/woocomposer/modules/design-loop-style02.php

https://gitlab.com/mattswann/launch-housing
PHP | 396 lines | 377 code | 18 blank | 1 comment | 101 complexity | f542251dec9644812da3ddad2b9571b2 MD5 | raw file
  1. <?php
  2. function WooComposer_Loop_style02($atts,$element){
  3. $product_style = $display_elements = $quick_view_style = $img_animate = $text_align = $color_heading = $color_categories = $color_price = '';
  4. $color_rating = $color_rating_bg = $color_quick_bg = $color_quick = $color_cart_bg = $color_cart = $color_product_desc = $advanced_opts = '';
  5. $color_product_desc_bg = $size_title = $size_cat = $size_price = $color_on_sale = $color_on_sale_bg = $label_on_sale = $product_animation = '';
  6. $disp_type = $category = $output = $product_style = $border_style = $border_color = $border_size = $border_radius = $lazy_images = $pagination = '';
  7. $sale_price = $shortcode = $on_sale_alignment = $on_sale_style = $product_img_disp = '';
  8. extract(shortcode_atts(array(
  9. "disp_type" => "",
  10. "category" => "",
  11. "shortcode" => "",
  12. "product_style" => "style01",
  13. "display_elements" => "",
  14. "quick_view_style" => "expandable",
  15. "label_on_sale" => "Sale!",
  16. "text_align" => "left",
  17. "img_animate" => "rotate-clock",
  18. "pagination" => "",
  19. "color_heading" => "",
  20. "color_categories" => "",
  21. "color_price" => "",
  22. "color_rating" => "",
  23. "color_rating_bg" => "",
  24. "color_quick_bg" => "",
  25. "color_quick" => "",
  26. "color_cart_bg" => "",
  27. "color_on_sale_bg" => "",
  28. "color_on_sale" => "",
  29. "color_cart" => "",
  30. "color_product_desc" => "",
  31. "color_product_desc_bg" => "",
  32. "size_title" => "",
  33. "size_cat" => "",
  34. "size_price" => "",
  35. "border_style" => "",
  36. "border_color" => "",
  37. "border_size" => "",
  38. "border_radius" => "",
  39. "product_animation" => "",
  40. "lazy_images" => "",
  41. "advanced_opts" => "",
  42. "sale_price" => "",
  43. "on_sale_style" => "wcmp-sale-circle",
  44. "on_sale_alignment" => "wcmp-sale-right",
  45. "product_img_disp" => "single",
  46. ),$atts));
  47. $output = $heading_style = $cat_style = $price_style = $cart_style = $cart_bg_style = $view_style = $view_bg_style = $rating_style = '';
  48. $desc_style = $label_style = $on_sale = $class = $style = $border = $desc_style = $sale_price_size = '';
  49. $infinite = $autoplay = $dots = 'false';
  50. $image_size = apply_filters( 'single_product_large_thumbnail_size', 'shop_single' );
  51. if($sale_price !== ''){
  52. $sale_price_size = 'font-size:'.$sale_price.'px;';
  53. }
  54. if($border_style !== ''){
  55. $border .= 'border:'.$border_size.'px '.$border_style.' '.$border_color.';';
  56. $border .= 'border-radius:'.$border_radius.'px;';
  57. }
  58. if($color_product_desc_bg !== ''){
  59. $desc_style .= 'background:'.$color_product_desc_bg.';';
  60. }
  61. if($color_product_desc !== ''){
  62. $desc_style .= 'color:'.$color_product_desc.';';
  63. }
  64. $img_animate = 'wcmp-img-'.$img_animate;
  65. $advanced_opts = explode(",", $advanced_opts);
  66. if(in_array("infinite",$advanced_opts)){
  67. $infinite = 'true';
  68. }
  69. if(in_array("autoplay",$advanced_opts)){
  70. $autoplay = 'true';
  71. }
  72. if(in_array("dots",$advanced_opts)){
  73. $dots = 'true';
  74. }
  75. $display_type = $disp_type;
  76. $columns = 3;
  77. if($color_heading !== ""){
  78. $heading_style = 'color:'.$color_heading.';';
  79. }
  80. if($size_title !== ""){
  81. $heading_style .= 'font-size:'.$size_title.'px;';
  82. }
  83. if($color_categories !== ""){
  84. $cat_style = 'color:'.$color_categories.';';
  85. }
  86. if($size_cat !== ""){
  87. $cat_style .= 'font-size:'.$size_cat.'px;';
  88. }
  89. if($color_price !== ""){
  90. $price_style = 'color:'.$color_price.';';
  91. }
  92. if($size_price !== ""){
  93. $price_style .= 'font-size:'.$size_price.'px;';
  94. }
  95. if($color_rating !== ""){
  96. $rating_style .= 'color:'.$color_rating.';';
  97. }
  98. if($color_rating_bg !== ""){
  99. $rating_style .= 'background:'.$color_rating_bg.';';
  100. }
  101. if($color_quick_bg !== ""){
  102. $view_bg_style = 'background:'.$color_quick_bg.';';
  103. }
  104. if($color_quick !== ""){
  105. $view_style = 'color:'.$color_quick.';';
  106. }
  107. if($color_cart_bg !== ""){
  108. $cart_bg_style = 'background:'.$color_cart_bg.';';
  109. }
  110. if($color_cart !== ""){
  111. $cart_style = 'color:'.$color_cart.';';
  112. }
  113. if($color_on_sale_bg !== ""){
  114. $label_style = 'background:'.$color_on_sale_bg.';';
  115. }
  116. if($color_on_sale !== ""){
  117. $label_style .= 'color:'.$color_on_sale.';';
  118. }
  119. $elemets = explode(",",$display_elements);
  120. $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  121. $post_count = '12';
  122. /* $output .= do_shortcode($content); */
  123. if($shortcode !== ''){
  124. $new_shortcode = rawurldecode( base64_decode( strip_tags( $shortcode ) ) );
  125. }
  126. $pattern = get_shortcode_regex();
  127. $shortcode_str = $short_atts = $text_align_style = '';
  128. preg_match_all("/".$pattern."/",$new_shortcode,$matches);
  129. $shortcode_str = str_replace('"','',str_replace(" ","&",trim($matches[3][0])));
  130. $short_atts = parse_str($shortcode_str);//explode("&",$shortcode_str);
  131. if(isset($matches[2][0])): $display_type = $matches[2][0]; else: $display_type = ''; endif;
  132. if(!isset($columns)): $columns = '4'; endif;
  133. if(isset($per_page)): $post_count = $per_page; endif;
  134. if(isset($number)): $post_count = $number; endif;
  135. if(!isset($order)): $order = 'asc'; endif;
  136. if(!isset($orderby)): $orderby = 'date'; endif;
  137. if(!isset($category)): $category = ''; endif;
  138. if(!isset($ids)): $ids = ''; endif;
  139. if($ids){
  140. $ids = explode( ',', $ids );
  141. $ids = array_map( 'trim', $ids );
  142. }
  143. $col = $columns;
  144. if($columns == "2") $columns = 6;
  145. elseif($columns == "3") $columns = 4;
  146. elseif($columns == "4") $columns = 3;
  147. $meta_query = '';
  148. if($display_type == "recent_products"){
  149. $meta_query = WC()->query->get_meta_query();
  150. }
  151. if($display_type == "featured_products"){
  152. $meta_query = array(
  153. array(
  154. 'key' => '_visibility',
  155. 'value' => array('catalog', 'visible'),
  156. 'compare' => 'IN'
  157. ),
  158. array(
  159. 'key' => '_featured',
  160. 'value' => 'yes'
  161. )
  162. );
  163. }
  164. if($display_type == "top_rated_products"){
  165. add_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
  166. $meta_query = WC()->query->get_meta_query();
  167. }
  168. $args = array(
  169. 'post_type' => 'product',
  170. 'post_status' => 'publish',
  171. 'ignore_sticky_posts' => 1,
  172. 'posts_per_page' => $post_count,
  173. 'orderby' => $orderby,
  174. 'order' => $order,
  175. 'paged' => $paged,
  176. 'meta_query' => $meta_query
  177. );
  178. if($display_type == "sale_products"){
  179. $product_ids_on_sale = woocommerce_get_product_ids_on_sale();
  180. $meta_query = array();
  181. $meta_query[] = $woocommerce->query->visibility_meta_query();
  182. $meta_query[] = $woocommerce->query->stock_status_meta_query();
  183. $args['meta_query'] = $meta_query;
  184. $args['post__in'] = $product_ids_on_sale;
  185. }
  186. if($display_type == "best_selling_products"){
  187. $args['meta_key'] = 'total_sales';
  188. $args['orderby'] = 'meta_value_num';
  189. $args['meta_query'] = array(
  190. array(
  191. 'key' => '_visibility',
  192. 'value' => array( 'catalog', 'visible' ),
  193. 'compare' => 'IN'
  194. )
  195. );
  196. }
  197. if($display_type == "product_category"){
  198. $args['tax_query'] = array(
  199. array(
  200. 'taxonomy' => 'product_cat',
  201. 'terms' => array( esc_attr( $category ) ),
  202. 'field' => 'slug',
  203. 'operator' => 'IN'
  204. )
  205. );
  206. }
  207. if($display_type == "product_categories"){
  208. $args['tax_query'] = array(
  209. array(
  210. 'taxonomy' => 'product_cat',
  211. 'terms' => $ids,
  212. 'field' => 'term_id',
  213. 'operator' => 'IN'
  214. )
  215. );
  216. }
  217. if($product_animation == ''){
  218. $product_animation = 'no-animation';
  219. }
  220. if($element == "grid"){
  221. $class = 'vc_span'.$columns.' ';
  222. }
  223. $output .= '<div class="woocomposer" data-columns="'.$col.'">';
  224. $query = new WP_Query( $args );
  225. if($query->have_posts()):
  226. while ( $query->have_posts() ) : $query->the_post();
  227. $product_id = get_the_ID();
  228. $uid = uniqid();
  229. $output .= '<div id="product-'.$uid.'" class="'.$class.' wpb_column column_container wooproduct" data-animation="animated '.$product_animation.'">';
  230. if($element == 'carousel'){
  231. $output .= '<div class="wcmp-carousel-item">';
  232. }
  233. $product_title = get_the_title($product_id);
  234. $post = get_post($product_id);
  235. $product_desc = get_post($product_id)->post_excerpt;
  236. $product_img = wp_get_attachment_image_src( get_post_thumbnail_id($product_id),$image_size);
  237. $product = new WC_Product( $product_id );
  238. $attachment_ids = $product->get_gallery_attachment_ids();
  239. $price = $product->get_price_html();
  240. $rating = $product->get_rating_html();
  241. $attributes = $product->get_attributes();
  242. $stock = $product->is_in_stock() ? 'InStock' : 'OutOfStock';
  243. if ( $product->is_on_sale() ) :
  244. $on_sale = apply_filters( 'woocommerce_sale_flash', $label_on_sale , $post, $product );
  245. else:
  246. $on_sale = '';
  247. endif;
  248. $cat_count = sizeof( get_the_terms( $product_id, 'product_cat' ) );
  249. $tag_count = sizeof( get_the_terms( $product_id, 'product_tag' ) );
  250. $categories = $product->get_categories(', ','<span class="posted_in">'._n('','',$cat_count,'woocommerce').' ','.</span>');
  251. $tags = $product->get_tags( ', ','<span class="tagged_as">'._n('', '',$tag_count, 'woocommerce').' ', '.</span>' );
  252. $output .= "\n".'<div class="wcmp-product woocommerce wcmp-'.$product_style.' '.$img_animate.'" style="'.$border.' '.$desc_style.'">';
  253. $output .= "\n\t".'<div class="wcmp-product-image">';
  254. if(empty($attachment_ids) && count($attachment_ids) > 1 && $product_img_disp == "carousel"){
  255. $uniqid = uniqid();
  256. $output .= '<div class="wcmp-single-image-carousel carousel-in-loop">';
  257. $product_img = wp_get_attachment_image_src( get_post_thumbnail_id($product_id),$image_size);
  258. if($lazy_images == "enable"){
  259. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  260. } else {
  261. $src = $product_img[0];
  262. }
  263. $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></div></div>';
  264. foreach($attachment_ids as $attachment_id){
  265. $product_img = wp_get_attachment_image_src( $attachment_id,$image_size);
  266. $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></div></div>';
  267. }
  268. $output .= '</div>';
  269. } else {
  270. $product_img = wp_get_attachment_image_src( get_post_thumbnail_id($product_id),$image_size);
  271. if($lazy_images == "enable"){
  272. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  273. } else {
  274. $src = $product_img[0];
  275. }
  276. $output .= '<a href="'.get_permalink($product_id).'"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></a>';
  277. }
  278. if($quick_view_style == "expandable"){
  279. $quick_view_class = 'quick-view-loop';
  280. } else {
  281. $quick_view_class = 'quick-view-loop-popup';
  282. }
  283. if($on_sale !== ''){
  284. $output .= "\n".'<div class="wcmp-onsale '.$on_sale_alignment.' '.$on_sale_style.'"><span class="onsale" style="'.$label_style.' '.$sale_price_size.'">'.$on_sale.'</span></div>';
  285. }
  286. if($stock == 'OutOfStock'){
  287. $output .= "\n".'<span class="wcmp-out-stock">'.__('Out Of Stock!','woocomposer').'</span>';
  288. }
  289. $output .= '<div class="wcmp-add-to-cart" style="'.$cart_bg_style.'"><a style="'.$cart_style.'" title="Add to Cart" href="?add-to-cart='.$product_id.'" rel="nofollow" data-product_id="'.$product_id.'" data-product_sku="" class="add_to_cart_button product_type_simple"><i class="wooicon-cart4"></i></a></div>';
  290. if(in_array("quick",$elemets)){
  291. $output .= '<div class="wcmp-quick-view '.$quick_view_class.'" style="'.$view_bg_style.'"><a style="'.$view_style.'" title="Quick View" href="'.get_permalink($product_id).'"><i class="wooicon-plus32"></i></a></div>';
  292. }
  293. if(in_array("reviews",$elemets)){
  294. $output .= "\n".'<div class="wcmp-star-ratings" style="'.$rating_style.'">'.$rating.'</div>';
  295. }
  296. $output .= '</div>';
  297. if($text_align !== ''){
  298. $text_align_style = 'text-align:'.$text_align.';';
  299. }
  300. $output .= "\n\t".'<div class="wcmp-product-desc" style="'.$text_align_style.'">';
  301. $output .= '<a href="'.get_permalink($product_id).'">';
  302. $output .= "\n\t\t".'<h2 style="'.$heading_style.'">'.$product_title.'</h2>';
  303. $output .= '</a>';
  304. if(in_array("category",$elemets)){
  305. $output .= '<h5 style="'.$cat_style.'">';
  306. if($categories !== ''){
  307. $output .= $categories;
  308. $output .= $tags;
  309. }
  310. $output .= '</h5>';
  311. }
  312. $output .= "\n\t\t".'<div class="wcmp-price"><span class="price" style="'.$price_style.'">'.$price.'</span></div>';
  313. if(in_array("description",$elemets)){
  314. $output .= "\n\t\t".'<div class="wcmp-product-content" style="'.$desc_style.'">'.$product_desc.'</div>';
  315. }
  316. $output .= "\n\t".'</div>';
  317. $output .= "\n\t".'</div>';
  318. if(in_array("quick",$elemets)){
  319. $output .= '<div class="wcmp-quick-view-wrapper" data-columns="'.$col.'">';
  320. if($quick_view_style !== "expandable"){
  321. $output .= '<div class="wcmp-quick-view-wrapper woocommerce product">';
  322. $output .= '<div class="wcmp-close-single"><i class="wooicon-cross2"></i></div>';
  323. }
  324. if(!empty($attachment_ids) && count($attachment_ids) > 1){
  325. $uniqid = uniqid();
  326. $output .= '<div class="slider wcmp-image-carousel wcmp-carousel-'.$uniqid.'" data-class="wcmp-carousel-'.$uniqid.'">';
  327. foreach($attachment_ids as $attachment_id){
  328. $product_img = wp_get_attachment_image_src( $attachment_id,$image_size);
  329. if($lazy_images == "enable"){
  330. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  331. } else {
  332. $src = $product_img[0];
  333. }
  334. $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></div></div>';
  335. }
  336. $output .= '</div>';
  337. } else {
  338. $product_img = wp_get_attachment_image_src( get_post_thumbnail_id($product_id),$image_size);
  339. if($lazy_images == "enable"){
  340. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  341. } else {
  342. $src = $product_img[0];
  343. }
  344. $output .= '<div class="wcmp-single-image wcmp-quickview-img images"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></div>';
  345. }
  346. if($quick_view_style !== "expandable"){
  347. $output .= '<div class="wcmp-product-content-single">';
  348. } else {
  349. $output .= '<div class="wcmp-product-content">';
  350. }
  351. ob_start();
  352. do_action( 'woocommerce_single_product_summary' );
  353. $output .= ob_get_clean();
  354. $output .= '</div>';
  355. $output .= '<div class="clear"></div>';
  356. if($quick_view_style !== "expandable"){
  357. $output .= '</div>';
  358. }
  359. $output .= '</div>';
  360. }
  361. $output .= "\n".'</div>';
  362. if($element == 'carousel'){
  363. $output .= "\n\t".'</div>';
  364. }
  365. endwhile;
  366. endif;
  367. if($pagination == "enable"){
  368. $output .= '<div class="woocomposer-paginate">';
  369. $output .= woocomposer_pagination($query->max_num_pages);
  370. $output .= '</div>';
  371. }
  372. $output .= '</div>';
  373. if($display_type == "top_rated_products"){
  374. remove_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
  375. }
  376. wp_reset_postdata();
  377. return $output;
  378. }