PageRenderTime 27ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/responsive-category-slider/system/shortcode.php

https://gitlab.com/rio.munas/gddc
PHP | 257 lines | 222 code | 23 blank | 12 comment | 123 complexity | 712c7c6d31cb484a8a21e417b9899c8c MD5 | raw file
  1. <?php
  2. /**
  3. * @package Responsive Category Slider
  4. * @author ThemeLead Team <support@themelead.com>
  5. * @copyright Copyright 2014 themelead.com. All Rights Reserved.
  6. * @license GPLv2 or later - http://www.gnu.org/licenses/gpl-2.0.html
  7. * Websites: http://www.themelead.com
  8. * Technical Support: Free Forum Support - http://support.themelead.com
  9. */
  10. include_once('functions.php');
  11. // Create Shortcode Category Slider
  12. global $post;
  13. if(!function_exists('b_create_shortcode_categories_slider')){
  14. function b_create_shortcode_categories_slider($args, $content = null){
  15. $type = (empty($args['cat_type'])) ? null : $args['cat_type'];
  16. $cat_id = (empty($args['cat'])) ? null : $args['cat'];
  17. $custom_post = (empty($args['custom_post'])) ? null : $args['custom_post'];
  18. $tax_name = (empty($args['tax_name'])) ? null : $args['tax_name'];
  19. $per_page = (empty($args['per_page'])) ? null : $args['per_page'];
  20. $list_tags = (empty($args['list_tags'])) ? null : $args['list_tags'];
  21. if($type == null): $type = 'category'; endif;
  22. if($type != 'tag' && $type != 'taxonomy' && $type != 'category'): $type = 'category'; endif;
  23. if($type != "taxonomy"): if($cat_id == null): $cat_id = 'category'; endif; endif;
  24. $style = (empty($args['style'])) ? 3 : $args['style'];
  25. if($style != 'post' && $style != 'events' && $style != 'gallery' && $style != 'product' && $style != 'news'): $style = 'post'; endif;
  26. $columns = (empty($args['columns'])) ? 3 : $args['columns'];
  27. if($columns != 1 && $columns != 2 && $columns != 3 && $columns != 4 && $columns != 6 ): $columns = 3; endif;
  28. if($per_page == null || !is_numeric($per_page)):
  29. if($columns == 1): $per_page = 1; endif;
  30. if($columns == 2): $per_page = 4; endif;
  31. if($columns == 3): $per_page = 6; endif;
  32. if($columns == 4): $per_page = 8; endif;
  33. if($columns == 6): $per_page = 12; endif;
  34. endif;
  35. $pos_menu = (empty($args['pos_menu'])) ? 'horizontal' : $args['pos_menu'];
  36. if($pos_menu != 'horizontal' && $pos_menu != 'vertical' && $pos_menu != 'hide'): $pos_menu = 'horizontal'; endif;
  37. $order_by = (empty($args['order_by'])) ? 'date' : $args['order_by'];
  38. if($order_by != 'view'): $order_by = 'date'; endif;
  39. $order = (empty($args['order'])) ? 'desc' : $args['order'];
  40. if($order != 'asc'): $order = 'desc'; endif;
  41. $auto_slide = (empty($args['auto_slide'])) ? 'false' : $args['auto_slide'];
  42. if($auto_slide != 'true'): $auto_slide = 'false'; endif;
  43. $control_nav = (empty($args['control_nav'])) ? 'on' : $args['control_nav'];
  44. if($control_nav != 'off'): $control_nav = 'on'; endif;
  45. $padding = (empty($args['padding'])) ? 'yes' : $args['padding'];
  46. if($padding != 'no'): $padding = 'yes'; endif;
  47. if($padding == 'no'){ $class_no_padding = 'no_padding'; }else { $class_no_padding = ''; }
  48. $image_size = (empty($args['image_ratio'])) ? 'horizontal_rectangle' : $args['image_ratio'];
  49. if($image_size != 'square' && $image_size != 'vertical_rectangle' && $image_size != 'full_size'): $image_size = 'horizontal_rectangle'; endif;
  50. $linkable = (empty($args['linkable'])) ? 'on' : $args['linkable'];
  51. if($linkable != 'off'): $linkable = 'on'; endif;
  52. $show_parent_menu = (empty($args['show_parent_menu'])) ? 'yes' : $args['show_parent_menu'];
  53. if($show_parent_menu != 'no'): $show_parent_menu = 'yes'; endif;
  54. if($show_parent_menu == 'yes'){ $class_show_parent = 'b-show-parent';} else { $class_show_parent = 'b-not-show-parent';}
  55. $class_check_hide_menu = b_check_to_hide_menu($cat_id, $tax_name, $type);
  56. $class_margin_horizontal = b_check_to_set_class_margin_horizontal($cat_id, $type);
  57. if (!class_exists('Mobile_Detect')):
  58. require_once('mobile-detect.php');
  59. endif;
  60. $b_detect = new Mobile_Detect;
  61. global $_b_device_;
  62. $_b_device_ = $b_detect->isMobile() ? ($b_detect->isTablet() ? 'tablet' : 'mobile') : 'pc';
  63. //Set plugin id to a slider
  64. global $plugin_id;
  65. $plugin_id = rand();
  66. //Get data Auto slide and theme style
  67. global $wpdb;
  68. $table_setting = $wpdb->prefix . 'b_responsive_category_slider';
  69. $data = $wpdb->get_row("SELECT * FROM ".$table_setting." WHERE id=1");
  70. $theme_style = $data->theme_style;
  71. $slideshowSpeed = $data->slideshowSpeed;
  72. if(empty($slideshowSpeed)){ $slideSpeed = 7000;} else { $slideSpeed = $slideshowSpeed; }
  73. $style_theme = '';
  74. if(($theme_style == null) || ($theme_style == 'nile')){ $style_theme = 'b_nile_theme';} else {$style_theme = 'b_'.$theme_style.'theme';}
  75. $html = '';
  76. if($pos_menu == 'vertical'){
  77. $html .= '<div id="b-plugins-category-'.$plugin_id.'" class="b-plugins-category b-vertical '.$style_theme.' b-columns-'.$columns.' '.$class_no_padding.' '.$class_show_parent.' '.$class_margin_horizontal.' '.$class_check_hide_menu.'" data-id="'.$plugin_id.'">';
  78. }
  79. else {
  80. $html .= '<div id="b-plugins-category-'.$plugin_id.'" class="b-plugins-category b-no-vertical '.$style_theme.' b-columns-'.$columns.' '.$class_no_padding.' '.$class_show_parent.' '.$class_margin_horizontal.' '.$class_check_hide_menu.'" data-id="'.$plugin_id.'">';
  81. }
  82. if($pos_menu == 'horizontal'):
  83. $html .= '<div class="b-menu-categories b-menu-horizontal"><div class="b-view-horizontal">';
  84. $html .= b_get_menu_horizontal($type, $cat_id, $tax_name, $list_tags, $plugin_id, $show_parent_menu);
  85. $html .= '</div></div>';
  86. endif;
  87. $html .= '<div id="b-plugins-view"><div class="b-plugins-view-in">';
  88. /*Check menu vertical show and hide */
  89. if($pos_menu == 'vertical'){
  90. $html .= '<div class="b-menu-categories" >';
  91. }
  92. else{
  93. $html .= '<div class="b-menu-categories" style="display: none;">';
  94. }
  95. $html .= '<ul class="b-menu-category">';
  96. $html .= b_get_menu_vertical($type, $cat_id, $tax_name, $custom_post, $style, $list_tags, $plugin_id, $image_size, $linkable, $show_parent_menu);
  97. $html .= '</ul></div>';
  98. $html .= '<div class="b-flexslider-posts">
  99. <div id="b-data-ajax">
  100. <span id="cat_type" alt="'.$type.'"></span>
  101. <span id="tax_name" alt="'.$tax_name.'"></span>
  102. <span id="custom_post" alt="'.$custom_post.'"></span>
  103. <span id="per_page" alt="'.$per_page.'"></span>
  104. <span id="columns" alt="'.$columns.'"></span>
  105. <span id="style" alt="'.$style.'"></span>
  106. <span id="order" alt="'.$order.'"></span>
  107. <span id="order_by" alt="'.$order_by.'"></span>
  108. <span id="auto_slide" alt="'.$auto_slide.'"></span>
  109. <span id="control_nav" alt="'.$control_nav.'"></span>
  110. <span id="image_size" alt="'.$image_size.'"></span>
  111. <span id="linkable" alt="'.$linkable.'"></span>
  112. <span id="b_device" alt="'.$_b_device_.'"></span>
  113. </div>
  114. <div id="b-ajax-loaded-posts"><img src="'.home_url().'/wp-content/plugins/responsive-category-slider/images/ajax-loader.gif" alt="loading..."/></div>
  115. <div id="b-ajax-results-html">
  116. <div class="b-flexslider" data-control-nav="'.$control_nav.'" data-autoslide="'.$auto_slide.'" data-slideshowspeed="'.$slideSpeed.'">
  117. <ul class="slides">
  118. <li class="b-li-child-flex">
  119. <div class="row">';
  120. if($type == "tag"){
  121. if($list_tags != null){
  122. $array_tags = explode(",", trim($list_tags," "));
  123. $args = array(
  124. 'tag' => $array_tags[0]
  125. );
  126. }
  127. else{
  128. $posttags = get_tags('orderby=term_id&order=desc');
  129. if($posttags){
  130. $args = array(
  131. 'tag' => $posttags[0]->slug
  132. );
  133. }
  134. }
  135. }
  136. else if($type == "taxonomy"){
  137. if(!empty($tax_name) && !empty($custom_post)){
  138. if(empty($cat_id)){
  139. $args = array(
  140. 'post_type' => $custom_post
  141. );
  142. }
  143. else{
  144. $cat_id = str_replace(" ", "", $cat_id);
  145. $list_id = explode(",", $cat_id);
  146. $filtered = array_filter($list_id, 'is_numeric');
  147. if($filtered == $list_id){
  148. $args = array(
  149. 'post_type' => $custom_post,
  150. 'tax_query' => array(
  151. array(
  152. 'taxonomy' => $tax_name,
  153. 'field' => 'id',
  154. 'terms' => $list_id,
  155. 'operator' => 'IN'
  156. )
  157. )
  158. );
  159. }
  160. else {
  161. $args = array(
  162. 'post_type' => $custom_post,
  163. 'tax_query' => array(
  164. array(
  165. 'taxonomy' => $tax_name,
  166. 'field' => 'slug',
  167. 'terms' => $list_id,
  168. 'operator' => 'IN'
  169. )
  170. )
  171. );
  172. }
  173. }
  174. }
  175. else {
  176. $args = array();
  177. $html .= '<p class="warring_message">'.__('Warning: You need to fill tax_name and custom_post in your shortcode', 'b_category_slider') . '</p>';
  178. }
  179. }
  180. else {
  181. if(is_numeric($cat_id) || $cat_id == 'category'){
  182. $args = array(
  183. 'post_type' => 'post',
  184. 'cat' => $cat_id
  185. );
  186. }
  187. else {
  188. $cat_obj = get_category_by_slug( $cat_id );
  189. $cate_id = $cat_obj->term_id;
  190. if(!empty($cate_id)){
  191. $args = array(
  192. 'post_type' => 'post',
  193. 'cat' => $cate_id
  194. );
  195. } else {
  196. $args = array();
  197. $html .= '<strong style="display: block;">'.__('"Warning: You have entered incorrect slug "', 'b_category_slider') . '</strong>';
  198. }
  199. }
  200. }
  201. if($order_by == 'date'){
  202. $args['orderby'] = 'date';
  203. $args['order'] = $order;
  204. }
  205. else {
  206. $args['orderby'] = 'meta_value_num';
  207. $args['meta_key'] = 'b_meta_views';
  208. $args['order'] = $order;
  209. }
  210. $args['posts_per_page'] = -1;
  211. $query = new WP_Query($args);
  212. $post_num = $query->post_count;
  213. if($post_num <= $per_page):
  214. echo "<style type='text/css'>#b-plugins-category-".$plugin_id." #b-plugins-view .flex-control-nav{padding: 0;}</style>";
  215. endif;
  216. if($query->have_posts()){
  217. $i = 0;
  218. while ($query->have_posts()): $query->the_post();
  219. if(($i > 0) && ($i%$per_page)== 0):
  220. $html .= "</div></li><li class='b-li-child-flex'><div class='row'>";
  221. endif;
  222. ?>
  223. <?php $html .= b_show_posts_by_style($style, $columns, $plugin_id, $image_size, $linkable, $_b_device_);?>
  224. <?php
  225. $i++;
  226. endwhile; wp_reset_postdata();
  227. }
  228. else {
  229. $html .= '<p align="center">'.__('No Article to display', 'b_category_slider').'</p>';
  230. }
  231. $html .= "</div></li></ul></div></div></div></div></div></div>";
  232. return $html;
  233. }
  234. }