PageRenderTime 60ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/fusion-core/admin/page-builder/includes/engine/class-helper.php

https://gitlab.com/webkod3r/tripolis
PHP | 422 lines | 275 code | 43 blank | 104 comment | 38 complexity | 68c92b4e5feee95646760280c4976311 MD5 | raw file
  1. <?php
  2. /**
  3. * FusionHelper class with static methods
  4. */
  5. class FusionHelper {
  6. /**
  7. * Convert object sent using Ajax into array.
  8. * @param type $object data object
  9. * @return type data array
  10. */
  11. public static function OBJECT_TO_ARRAY( $object ) {
  12. if ( is_object($object) ) {
  13. // Gets the properties of the given object
  14. // with get_object_vars function
  15. $object = get_object_vars($object);
  16. }
  17. if ( is_array($object) ) {
  18. /*
  19. * Return array converted to object
  20. * Using recursive call
  21. */
  22. return array_map("FusionHelper::OBJECT_TO_ARRAY", $object);
  23. }
  24. else {
  25. // Return array
  26. return $object;
  27. }
  28. }
  29. /**
  30. * Create drop down data of wordpress existing categories
  31. * @params: null
  32. * @return: data array
  33. */
  34. public static function get_wp_categories_list () {
  35. $args = array(
  36. 'type' => 'post', // tye of categor
  37. 'child_of' => 0, // child of some specific
  38. 'parent' => '', // should get parents?
  39. 'orderby' => 'name', // sorty by name
  40. 'order' => 'ASC', // in ascending order
  41. 'hide_empty' => 0, // hide empty categories
  42. 'hierarchical' => 1, // get in hirearchical order
  43. 'exclude' => '', // no categories to exclude
  44. 'include' => '', // include all categories
  45. 'number' => '', // number of categories to retun. Empty for ALL.
  46. 'taxonomy' => 'category', // taxonomy to return
  47. 'pad_counts' => true // get number of posts for each category
  48. );
  49. $categories = get_categories( $args );
  50. $categories_list = array();
  51. foreach ( $categories as $category ) {
  52. $data = array (
  53. $category->slug => $category->name." (".$category->category_count.")" //category name and post count
  54. );
  55. $categories_list += $data;
  56. }
  57. return $categories_list;
  58. }
  59. /**
  60. * Get taxonomy categories
  61. * @params: $taxonomy, $empty_choice
  62. * @return: data array
  63. */
  64. public static function fusion_shortcodes_categories ( $taxonomy, $empty_choice = false, $empty_choice_label = 'Default' ) {
  65. if( taxonomy_exists( $taxonomy ) ) {
  66. if( $empty_choice == true ) {
  67. $post_categories[''] = $empty_choice_label;
  68. }
  69. $get_categories = get_categories('hide_empty=0&taxonomy=' . $taxonomy);
  70. if( ! array_key_exists('errors', $get_categories) ) {
  71. if( $get_categories && is_array($get_categories) ) {
  72. foreach ( $get_categories as $cat ) {
  73. $post_categories[$cat->slug] = $cat->name;
  74. }
  75. }
  76. if( isset( $post_categories ) && count( $post_categories ) > 0 ) {
  77. return $post_categories;
  78. } else {
  79. return array();
  80. }
  81. }
  82. } else {
  83. return array();
  84. }
  85. }
  86. /**
  87. * Create drop down data in form of array
  88. * @params: $array, $start, $end
  89. * @return: data array
  90. */
  91. public static function fusion_create_dropdown_data ( $start, $end, $dataArray = array() ) {
  92. for ($i = $start; $i <= $end; $i++ ) {
  93. $array['fusion_' . $i] = $i;
  94. }
  95. $dataArray = $dataArray + $array;
  96. return $dataArray;
  97. }
  98. /**
  99. * Generate icons list
  100. * you can get more icons names from http://fontawesome.io/icons/
  101. * @return array icons array
  102. */
  103. public static function GET_ICONS_LIST() {
  104. $icons = new FAIterator(FUSION_BUILDER_FA_PATH);
  105. $iconssArray = array();
  106. $output = '';
  107. foreach ($icons as $icon) {
  108. $output .= '<span class="icon_preview"><i class="fa ' . $icon->class . '" data-name="' . $icon->class . '"></i></span>';
  109. }
  110. return $output;
  111. }
  112. /**
  113. * Returns array of layerslider slide groups
  114. * @param NULL
  115. * @return array slide keys array
  116. */
  117. public static function get_layerslider_slides () {
  118. global $wpdb;
  119. $slides_array['fusion_0'] = 'Select a slider';
  120. // Table name
  121. $table_name = $wpdb->prefix . "layerslider";
  122. //check if table exists
  123. if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
  124. //table not exists
  125. } else {
  126. // Get sliders
  127. $sliders = $wpdb->get_results( "SELECT * FROM $table_name
  128. WHERE flag_hidden = '0' AND flag_deleted = '0'
  129. ORDER BY date_c ASC" );
  130. if(!empty($sliders)) {
  131. foreach($sliders as $key => $item) {
  132. $slides[$item->id] = '';
  133. }
  134. }
  135. if(isset($slides) && $slides){
  136. foreach($slides as $key => $val){
  137. $slides_array['fusion_'.$key] = 'LayerSlider #'.($key);
  138. }
  139. }
  140. }
  141. return $slides_array;
  142. }
  143. /**
  144. * Returns array of rev slider slide groups
  145. * @param NULL
  146. * @return array slide keys array
  147. */
  148. public static function get_revslider_slides () {
  149. global $wpdb;
  150. $revsliders['fusion_0'] = 'Select a slider';
  151. $table_name = $wpdb->prefix.'revslider_sliders';
  152. //check if table exists
  153. if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
  154. //table not exists
  155. } else {
  156. if(function_exists('rev_slider_shortcode')) {
  157. $get_sliders = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'revslider_sliders');
  158. if($get_sliders) {
  159. foreach($get_sliders as $slider) {
  160. $revsliders['fusion_'.$slider->alias] = $slider->title;
  161. }
  162. }
  163. }
  164. }
  165. return $revsliders;
  166. }
  167. /**
  168. * Returns array of elastic slider slide groups
  169. * @param NULL
  170. * @return array slide keys array
  171. */
  172. public static function get_elasticslider_slides () {
  173. $slides_array = array();
  174. $slides_array[0] = 'Select a slider';
  175. $slides = get_terms('themefusion_es_groups');
  176. if($slides && !isset($slides->errors)){
  177. $slides = is_array($slides) ? $slides : unserialize($slides);
  178. foreach($slides as $key => $val){
  179. $slides_array[$val->slug] = $val->name;
  180. }
  181. }
  182. return $slides_array;
  183. }
  184. /**
  185. * Returns array of theme fusion slider slide groups
  186. * @param NULL
  187. * @return array slide keys array
  188. */
  189. public static function get_tfslider_slides () {
  190. global $data;
  191. $slides_array = array();
  192. $slides_array[0] = 'Select a slider';
  193. $counter = 1;
  194. if ( isset ( $data['flexsliders_number'] ) ) {
  195. while($counter <= $data['flexsliders_number']){
  196. $slides_array['flexslider_'.$counter] = 'TFSlider'.$counter;
  197. $counter ++;
  198. }
  199. }
  200. return $slides_array;
  201. }
  202. /**
  203. * Returns array of animation speed data
  204. * @param NULL
  205. * @return array
  206. */
  207. public static function get_animation_speed_data ( $defaults = false ) {
  208. if( $defaults ) {
  209. $dec_numbers = array(
  210. '' => 'Default',
  211. '0.1' => '0.1',
  212. '0.2' => '0.2',
  213. '0.3' => '0.3',
  214. '0.4' => '0.4',
  215. '0.5' => '0.5',
  216. '0.6' => '0.6',
  217. '0.7' => '0.7',
  218. '0.8' => '0.8',
  219. '0.9' => '0.9',
  220. '1' => '1'
  221. );
  222. } else {
  223. $dec_numbers = array(
  224. '0.1' => '0.1',
  225. '0.2' => '0.2',
  226. '0.3' => '0.3',
  227. '0.4' => '0.4',
  228. '0.5' => '0.5',
  229. '0.6' => '0.6',
  230. '0.7' => '0.7',
  231. '0.8' => '0.8',
  232. '0.9' => '0.9',
  233. '1' => '1'
  234. );
  235. }
  236. return $dec_numbers;
  237. }
  238. /**
  239. * Returns array of choices data
  240. * @param NULL
  241. * @return array
  242. */
  243. public static function get_shortcode_choices () {
  244. $choices = array(
  245. 'yes' => 'Yes',
  246. 'no' => 'No'
  247. );
  248. return $choices;
  249. }
  250. /**
  251. * Returns array of choices data with default
  252. * @param NULL
  253. * @return array
  254. */
  255. public static function get_shortcode_choices_with_default () {
  256. $choices = array(
  257. '' => 'Default',
  258. 'yes' => 'Yes',
  259. 'no' => 'No'
  260. );
  261. return $choices;
  262. }
  263. /**
  264. * Returns array of animation direction data
  265. * @param NULL
  266. * @return array
  267. */
  268. public static function get_animation_direction_data ( $defaults = false ) {
  269. if( $defaults ) {
  270. $directions = array(
  271. '' => 'Default',
  272. 'down' => 'Down',
  273. 'left' => 'Left',
  274. 'right' => 'Right',
  275. 'up' => 'Up',
  276. 'static' => 'Static'
  277. );
  278. } else {
  279. $directions = array(
  280. 'down' => 'Down',
  281. 'left' => 'Left',
  282. 'right' => 'Right',
  283. 'up' => 'Up',
  284. 'static' => 'Static'
  285. );
  286. }
  287. return $directions;
  288. }
  289. /**
  290. * Returns array of animation type data
  291. * @param NULL
  292. * @return array
  293. */
  294. public static function get_animation_type_data ( $defaults = false ) {
  295. if( $defaults ) {
  296. $types = array(
  297. '' => 'Default',
  298. '0' => 'None',
  299. 'bounce' => 'Bounce',
  300. 'fade' => 'Fade',
  301. 'flash' => 'Flash',
  302. 'rubberBand' => 'Rubberband',
  303. 'shake' => 'Shake',
  304. 'slide' => 'Slide',
  305. 'zoom' => 'Zoom'
  306. );
  307. } else {
  308. $types = array(
  309. '0' => 'None',
  310. 'bounce' => 'Bounce',
  311. 'fade' => 'Fade',
  312. 'flash' => 'Flash',
  313. 'rubberBand' => 'Rubberband',
  314. 'shake' => 'Shake',
  315. 'slide' => 'Slide',
  316. 'zoom' => 'Zoom'
  317. );
  318. }
  319. return $types;
  320. }
  321. /**
  322. * Returns array of left-right data
  323. * @param NULL
  324. * @return array
  325. */
  326. public static function get_left_right_data () {
  327. $leftright = array(
  328. 'left' => 'Left',
  329. 'right' => 'Right'
  330. );
  331. return $leftright;
  332. }
  333. /**
  334. * Returns array of no-yes data
  335. * @param NULL
  336. * @return array
  337. */
  338. public static function get_reversed_choice_data () {
  339. $reverse_choices = array(
  340. 'no' => 'No',
  341. 'yes' => 'Yes'
  342. );
  343. return $reverse_choices;
  344. }
  345. /**
  346. * Function to generate combinations for number of elements in each column
  347. *
  348. * @since 2.0.0
  349. *
  350. * @return Array Array of $columns index where each index has a number value
  351. */
  352. public static function generate_column_combinations( $total, $columns ) {
  353. $combinations = array();
  354. $per_col = floor( $total / $columns );
  355. $per_col_increment = $total % $columns;
  356. //if not divided equally
  357. if( $per_col_increment > 0 ) {
  358. $per_col++;
  359. }
  360. for( $i = 0; $i < $columns; $i++ ) {
  361. if( $total > $per_col ) {
  362. $combinations[$i] = $per_col;
  363. $total = $total-$per_col;
  364. } else {
  365. $combinations[$i] = $total;
  366. $total = 0;
  367. }
  368. }
  369. return $combinations;
  370. }
  371. public static function get_sidebars() {
  372. global $wp_registered_sidebars;
  373. $sidebars = array();
  374. foreach( $wp_registered_sidebars as $sidebar_id => $sidebar ) {
  375. $sidebars[$sidebar_id] = $sidebar['name'];
  376. }
  377. return $sidebars;
  378. }
  379. }