Advertisement
Guest User

Untitled

a guest
Jun 25th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.30 KB | None | 0 0
  1. <?php
  2.  
  3. class WPBakeryShortCode_posts_carousel extends WPBakeryShortCode {
  4.  
  5. protected function content($atts, $content = null) {
  6.  
  7. $options = get_option('sf_supreme_options');
  8. $use_disqus = $options['use_disqus'];
  9.  
  10. $title = $category = $item_class = $excerpt_length = $width = $exclude_categories = $el_class = $output = $filter = $items = $el_position = '';
  11.  
  12. extract(shortcode_atts(array(
  13. 'title' => '',
  14. 'show_title' => 'yes',
  15. 'show_excerpt' => 'yes',
  16. "excerpt_length" => '20',
  17. "item_count" => '12',
  18. "show_details" => 'yes',
  19. "category" => 'all',
  20. "exclude_categories" => '',
  21. 'shadow' => 'yes',
  22. 'el_position' => '',
  23. 'width' => '1/1',
  24. 'el_class' => ''
  25. ), $atts));
  26.  
  27. // CATEGORY SLUG MODIFICATION
  28. if ($category == "All") {$category = "all";}
  29. if ($category == "all") {$category = '';}
  30. $category_slug = str_replace('_', '-', $category);
  31.  
  32. global $post, $wp_query;
  33.  
  34. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  35. $args=array(
  36. 'post_type' => 'post',
  37. 'post_status' => 'publish',
  38. 'paged' => $paged,
  39. 'category_name' => $category_slug,
  40. 'posts_per_page' => $item_count,
  41. 'ignore_sticky_posts' => 0,
  42. 'cat' => '"'.$exclude_categories.'"'
  43. );
  44. $blog_items = query_posts($args);
  45. $count = 0;
  46.  
  47. if( have_posts() ) {
  48.  
  49. $items .= '<ul class="blog-items carousel-items clearfix">';
  50.  
  51. while ( have_posts() ) {
  52.  
  53. the_post();
  54.  
  55. $item_title = get_the_title();
  56. $post_author = get_the_author_link();
  57. $post_date = get_the_date();
  58. $post_comments = get_comments_number();
  59. $post_categories = sf_get_custom_post_cat_list($post->ID);
  60.  
  61. $thumb_type = get_post_meta($post->ID, 'sf_thumbnail_type', true);
  62. $thumb_image = rwmb_meta('sf_thumbnail_image', 'type=image&size=full');
  63. $thumb_video = get_post_meta($post->ID, 'sf_thumbnail_video_url', true);
  64. $thumb_gallery = rwmb_meta( 'sf_thumbnail_gallery', 'type=image&size=thumb-image' );
  65. $thumb_link_type = get_post_meta($post->ID, 'sf_thumbnail_link_type', true);
  66. $thumb_link_url = get_post_meta($post->ID, 'sf_thumbnail_link_url', true);
  67. $thumb_lightbox_thumb = rwmb_meta( 'sf_thumbnail_image', 'type=image&size=large' );
  68. $thumb_lightbox_image = rwmb_meta( 'sf_thumbnail_link_image', 'type=image&size=large' );
  69. $thumb_lightbox_video_url = get_post_meta($post->ID, 'sf_thumbnail_link_video_url', true);
  70.  
  71. foreach ($thumb_image as $detail_image) {
  72. $thumb_img_url = $detail_image['url'];
  73. break;
  74. }
  75.  
  76. if (!$thumb_image) {
  77. $thumb_image = get_post_thumbnail_id();
  78. $thumb_img_url = wp_get_attachment_url( $thumb_image, 'full' );
  79. }
  80.  
  81. $item_title = get_the_title();
  82. $permalink = get_permalink();
  83. $custom_excerpt = get_post_meta($post->ID, 'sf_custom_excerpt', true);
  84. $post_excerpt = '';
  85. if ($custom_excerpt != '') {
  86. $post_excerpt = custom_excerpt($custom_excerpt, $excerpt_length);
  87. } else {
  88. $post_excerpt = excerpt($excerpt_length);
  89. }
  90.  
  91. $thumb_lightbox_img_url = wp_get_attachment_url( $thumb_lightbox_image, 'full' );
  92.  
  93. if ($thumb_link_type == "link_to_url") {
  94. $link_config = 'href="'.$thumb_link_url.'" class="link-to-url"';
  95. $item_icon = "link";
  96. } else if ($thumb_link_type == "link_to_url_nw") {
  97. $link_config = 'href="'.$thumb_link_url.'" class="link-to-url" target="_blank"';
  98. $item_icon = "link";
  99. } else if ($thumb_link_type == "lightbox_thumb") {
  100. $link_config = 'href="'.$thumb_img_url.'" class="view"';
  101. $item_icon = "search";
  102. } else if ($thumb_link_type == "lightbox_image") {
  103. $lightbox_image_url = '';
  104. foreach ($thumb_lightbox_image as $image) {
  105. $lightbox_image_url = $image['full_url'];
  106. }
  107. $link_config = 'href="'.$lightbox_image_url.'" class="view"';
  108. $item_icon = "search";
  109. } else if ($thumb_link_type == "lightbox_video") {
  110. $link_config = 'href="'.$thumb_lightbox_video_url.'" class="fancybox-media"';
  111. $item_icon = "facetime-video";
  112. } else {
  113. $link_config = 'href="'.$permalink.'" class="link-to-post"';
  114. $item_icon = "file-alt";
  115. }
  116.  
  117. if ($thumb_type == "image") {
  118. $item_class .= "image-item";
  119. }
  120.  
  121. $items .= '<li data-id="id-'. $count .'" class="clearfix recent-post four columns '.$item_class.'">';
  122.  
  123. $items .= '<figure>';
  124.  
  125. // THUMBNAIL MEDIA TYPE SETUP
  126.  
  127. if ($thumb_type == "video") {
  128.  
  129. $video = video_embed($thumb_video, 220, 165);
  130.  
  131. $items .= $video;
  132.  
  133. } else if ($thumb_type == "slider") {
  134.  
  135. $items .= '<div class="flexslider thumb-slider"><ul class="slides">';
  136.  
  137. foreach ( $thumb_gallery as $image )
  138. {
  139. $alt = $image['alt'];
  140. if (!$alt) {
  141. $alt = $image['title'];
  142. }
  143. $items .= "<li><img src='{$image['url']}' width='{$image['width']}' height='{$image['height']}' alt='{$alt}' /></li>";
  144. }
  145.  
  146. $items .= '</ul><div class="open-item"><a '.$link_config.'><i class="icon-plus"></i></a></div></div>';
  147.  
  148. } else {
  149.  
  150. $image = aq_resize( $thumb_img_url, 274, 205, true, false);
  151.  
  152. $items .= '<a '.$link_config.'>';
  153.  
  154. $items .= '<div class="overlay"><div class="thumb-info">';
  155. if (function_exists( 'lip_love_it_nolink' )) {
  156. $items .= lip_love_it_nolink(get_the_ID(), '<i class="icon-heart"></i>', '<i class="icon-heart"></i>', false);
  157. }
  158. $items .= '</div></div>';
  159.  
  160. if ($image) {
  161. $items .= '<img src="'.$image[0].'" width="'.$image[1].'" height="'.$image[2].'" alt="'.$item_title.'" />';
  162. }
  163.  
  164. $items .= '</a>';
  165. }
  166.  
  167. $items .= '</figure>';
  168.  
  169.  
  170. if ($show_title == "yes") {
  171. $items .= '<h4 class="blog-item-title"><a href="'.$permalink.'">'. $item_title .'</a></h4>';
  172. }
  173. if ($show_details == "yes") {
  174. $items .= '<div class="post-item-details">'. sprintf(__('By %1$s on %2$s', 'swiftframework'), $post_author, $post_date) .'</div>';
  175. }
  176. if ($show_details == "yes") {
  177. $items .= '<div class="item-cats">'. $post_categories .'</div>';
  178. }
  179. if ($show_excerpt == "yes") {
  180. $items .= '<div class="blog-item-excerpt">'. $post_excerpt .'</div>';
  181. }
  182. $items .= '</li>';
  183. $count++;
  184. $item_class = "";
  185. }
  186.  
  187. wp_reset_query();
  188.  
  189. $items .= '</ul>';
  190.  
  191. }
  192.  
  193. $el_class = $this->getExtraClass($el_class);
  194. $width = wpb_translateColumnWidthToSpan($width);
  195.  
  196. $output .= "\n\t".'<div class="wpb_posts_carousel_widget wpb_content_element '.$width.$el_class.'">';
  197. if ($shadow == "yes") {
  198. $output .= "\n\t\t".'<div class="wpb_wrapper carousel-wrap shadow">';
  199. } else {
  200. $output .= "\n\t\t".'<div class="wpb_wrapper carousel-wrap">';
  201. }
  202. if ($title != '') {
  203. $output .= "\n\t\t\t".'<div class="heading-wrap"><h3 class="wpb_heading"><span>'.$title.'</span></h3><div class="carousel-nav"><a href="#" class="carousel-prev"><i class="icon-chevron-left"></i></a><a href="#" class="carousel-next"><i class="icon-chevron-right"></i></a></div></div>';
  204. } else {
  205. $output .= "\n\t\t\t".'<div class="heading-wrap"><div class="carousel-nav"><a href="#" class="carousel-prev"><i class="icon-chevron-left"></i></a><a href="#" class="carousel-next"><i class="icon-chevron-right"></i></a></div></div>';
  206. }
  207. $output .= "\n\t\t\t\t".$items;
  208. $output .= "\n\t\t".'</div> '.$this->endBlockComment('.wpb_wrapper');
  209. $output .= "\n\t".'</div> '.$this->endBlockComment($width);
  210.  
  211. $output = $this->startRow($el_position) . $output . $this->endRow($el_position);
  212.  
  213. global $include_carousel;
  214. $include_carousel = true;
  215.  
  216. return $output;
  217.  
  218. }
  219. }
  220.  
  221. WPBMap::map( 'posts_carousel', array(
  222. "name" => __("Posts Carousel", "js_composer"),
  223. "base" => "posts_carousel",
  224. "class" => "wpb_posts_carousel wpb_carousel",
  225. "icon" => "icon-wpb-posts-carousel",
  226. "params" => array(
  227. array(
  228. "type" => "textfield",
  229. "heading" => __("Widget title", "js_composer"),
  230. "param_name" => "title",
  231. "value" => "",
  232. "description" => __("Heading text. Leave it empty if not needed.", "js_composer")
  233. ),
  234. array(
  235. "type" => "textfield",
  236. "class" => "",
  237. "heading" => __("Number of items", "js_composer"),
  238. "param_name" => "item_count",
  239. "value" => "12",
  240. "description" => __("The number of blog items to show in the carousel.", "js_composer")
  241. ),
  242. array(
  243. "type" => "dropdown",
  244. "heading" => __("Posts category", "js_composer"),
  245. "param_name" => "category",
  246. "value" => get_category_list('category'),
  247. "description" => __("Choose the category for the blog items.", "js_composer")
  248. ),
  249. array(
  250. "type" => "textfield",
  251. "heading" => __("Exclude categories", "js_composer"),
  252. "param_name" => "exclude_categories",
  253. "value" => "",
  254. "description" => __('If you would like to exclude categories from the blog list, then enter the category IDs here with a "-" infront of them, seperated by a comma (no spaces or quotes). E.g. "-1,-7,-23".', "js_composer")
  255. ),
  256. array(
  257. "type" => "dropdown",
  258. "heading" => __("Show title text", "js_composer"),
  259. "param_name" => "show_title",
  260. "value" => array(__("Yes", "js_composer") => "yes", __("No", "js_composer") => "no"),
  261. "description" => __("Show the item title text.", "js_composer")
  262. ),
  263. array(
  264. "type" => "dropdown",
  265. "heading" => __("Show item excerpt", "js_composer"),
  266. "param_name" => "show_excerpt",
  267. "value" => array(__("Yes", "js_composer") => "yes", __("No", "js_composer") => "no"),
  268. "description" => __("Show the item excerpt text.", "js_composer")
  269. ),
  270. array(
  271. "type" => "dropdown",
  272. "heading" => __("Show item details", "js_composer"),
  273. "param_name" => "show_details",
  274. "value" => array(__("Yes", "js_composer") => "yes", __("No", "js_composer") => "no"),
  275. "description" => __("Show the item details.", "js_composer")
  276. ),
  277. array(
  278. "type" => "dropdown",
  279. "heading" => __("Show bottom shadow", "js_composer"),
  280. "param_name" => "shadow",
  281. "value" => array(__("Yes", "js_composer") => "yes", __("No", "js_composer") => "no"),
  282. "description" => __("Show a shadow below the asset.", "js_composer")
  283. ),
  284. array(
  285. "type" => "textfield",
  286. "heading" => __("Excerpt Length", "js_composer"),
  287. "param_name" => "excerpt_length",
  288. "value" => "20",
  289. "description" => __("The length of the excerpt for the posts.", "js_composer")
  290. ),
  291. array(
  292. "type" => "textfield",
  293. "heading" => __("Extra class name", "js_composer"),
  294. "param_name" => "el_class",
  295. "value" => "",
  296. "description" => __("If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.", "js_composer")
  297. )
  298. )
  299. ) );
  300.  
  301. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement