PageRenderTime 67ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/web/app/plugins/js_composer_salient/include/helpers/helpers.php

https://bitbucket.org/mikestivala/vinciarchitects
PHP | 1437 lines | 851 code | 168 blank | 418 comment | 247 complexity | 0f28b8084ff6cb64afa449628d662680 MD5 | raw file
Possible License(s): MIT, Apache-2.0
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * WPBakery WPBakery Page Builder helpers functions
  7. *
  8. * @package WPBakeryPageBuilder
  9. *
  10. */
  11. // Check if this file is loaded in js_composer
  12. if ( ! defined( 'WPB_VC_VERSION' ) ) {
  13. die( '-1' );
  14. }
  15. /**
  16. * @param array $params
  17. *
  18. * @since 4.2
  19. * vc_filter: vc_wpb_getimagesize - to override output of this function
  20. * @return array|bool
  21. */
  22. function wpb_getImageBySize( $params = array() ) {
  23. $params = array_merge( array(
  24. 'post_id' => null,
  25. 'attach_id' => null,
  26. 'thumb_size' => 'thumbnail',
  27. 'class' => '',
  28. ), $params );
  29. if ( ! $params['thumb_size'] ) {
  30. $params['thumb_size'] = 'thumbnail';
  31. }
  32. if ( ! $params['attach_id'] && ! $params['post_id'] ) {
  33. return false;
  34. }
  35. $post_id = $params['post_id'];
  36. $attach_id = $post_id ? get_post_thumbnail_id( $post_id ) : $params['attach_id'];
  37. $attach_id = apply_filters( 'vc_object_id', $attach_id );
  38. $thumb_size = $params['thumb_size'];
  39. $thumb_class = ( isset( $params['class'] ) && '' !== $params['class'] ) ? $params['class'] . ' ' : '';
  40. global $_wp_additional_image_sizes;
  41. $thumbnail = '';
  42. if ( is_string( $thumb_size ) && ( ( ! empty( $_wp_additional_image_sizes[ $thumb_size ] ) && is_array( $_wp_additional_image_sizes[ $thumb_size ] ) ) || in_array( $thumb_size, array(
  43. 'thumbnail',
  44. 'thumb',
  45. 'medium',
  46. 'large',
  47. 'full',
  48. ) ) )
  49. ) {
  50. $attributes = array( 'class' => $thumb_class . 'attachment-' . $thumb_size );
  51. $thumbnail = wp_get_attachment_image( $attach_id, $thumb_size, false, $attributes );
  52. } elseif ( $attach_id ) {
  53. if ( is_string( $thumb_size ) ) {
  54. preg_match_all( '/\d+/', $thumb_size, $thumb_matches );
  55. if ( isset( $thumb_matches[0] ) ) {
  56. $thumb_size = array();
  57. $count = count( $thumb_matches[0] );
  58. if ( $count > 1 ) {
  59. $thumb_size[] = $thumb_matches[0][0]; // width
  60. $thumb_size[] = $thumb_matches[0][1]; // height
  61. } elseif ( 1 === $count ) {
  62. $thumb_size[] = $thumb_matches[0][0]; // width
  63. $thumb_size[] = $thumb_matches[0][0]; // height
  64. } else {
  65. $thumb_size = false;
  66. }
  67. }
  68. }
  69. if ( is_array( $thumb_size ) ) {
  70. // Resize image to custom size
  71. $p_img = wpb_resize( $attach_id, null, $thumb_size[0], $thumb_size[1], true );
  72. $alt = trim( strip_tags( get_post_meta( $attach_id, '_wp_attachment_image_alt', true ) ) );
  73. $attachment = get_post( $attach_id );
  74. if ( ! empty( $attachment ) ) {
  75. $title = trim( strip_tags( $attachment->post_title ) );
  76. if ( empty( $alt ) ) {
  77. $alt = trim( strip_tags( $attachment->post_excerpt ) ); // If not, Use the Caption
  78. }
  79. if ( empty( $alt ) ) {
  80. $alt = $title;
  81. } // Finally, use the title
  82. if ( $p_img ) {
  83. $attributes = vc_stringify_attributes( array(
  84. 'class' => $thumb_class,
  85. 'src' => $p_img['url'],
  86. 'width' => $p_img['width'],
  87. 'height' => $p_img['height'],
  88. 'alt' => $alt,
  89. 'title' => $title,
  90. ) );
  91. $thumbnail = '<img ' . $attributes . ' />';
  92. }
  93. }
  94. }
  95. }
  96. $p_img_large = wp_get_attachment_image_src( $attach_id, 'large' );
  97. return apply_filters( 'vc_wpb_getimagesize', array(
  98. 'thumbnail' => $thumbnail,
  99. 'p_img_large' => $p_img_large,
  100. ), $attach_id, $params );
  101. }
  102. function vc_get_image_by_size( $id, $size ) {
  103. global $_wp_additional_image_sizes;
  104. if ( is_string( $size ) && ( ( ! empty( $_wp_additional_image_sizes[ $size ] ) && is_array( $_wp_additional_image_sizes[ $size ] ) ) || in_array( $size, array(
  105. 'thumbnail',
  106. 'thumb',
  107. 'medium',
  108. 'large',
  109. 'full',
  110. ) ) )
  111. ) {
  112. return wp_get_attachment_image_src( $id, $size );
  113. } else {
  114. if ( is_string( $size ) ) {
  115. preg_match_all( '/\d+/', $size, $thumb_matches );
  116. if ( isset( $thumb_matches[0] ) ) {
  117. $size = array();
  118. $count = count( $thumb_matches[0] );
  119. if ( $count > 1 ) {
  120. $size[] = $thumb_matches[0][0]; // width
  121. $size[] = $thumb_matches[0][1]; // height
  122. } elseif ( 1 === $count ) {
  123. $size[] = $thumb_matches[0][0]; // width
  124. $size[] = $thumb_matches[0][0]; // height
  125. } else {
  126. $size = false;
  127. }
  128. }
  129. }
  130. if ( is_array( $size ) ) {
  131. // Resize image to custom size
  132. $p_img = wpb_resize( $id, null, $size[0], $size[1], true );
  133. return $p_img['url'];
  134. }
  135. }
  136. return '';
  137. }
  138. /* Convert vc_col-sm-3 to 1/4
  139. ---------------------------------------------------------- */
  140. /**
  141. * @param $width
  142. *
  143. * @since 4.2
  144. * @return string
  145. */
  146. function wpb_translateColumnWidthToFractional( $width ) {
  147. switch ( $width ) {
  148. case 'vc_col-sm-2' :
  149. $w = '1/6';
  150. break;
  151. case 'vc_col-sm-3' :
  152. $w = '1/4';
  153. break;
  154. case 'vc_col-sm-4' :
  155. $w = '1/3';
  156. break;
  157. case 'vc_col-sm-6' :
  158. $w = '1/2';
  159. break;
  160. case 'vc_col-sm-8' :
  161. $w = '2/3';
  162. break;
  163. case 'vc_col-sm-9' :
  164. $w = '3/4';
  165. break;
  166. case 'vc_col-sm-12' :
  167. $w = '1/1';
  168. break;
  169. default :
  170. $w = is_string( $width ) ? $width : '1/1';
  171. }
  172. return $w;
  173. }
  174. /**
  175. * @param $width
  176. *
  177. * @since 4.2
  178. * @return bool|string
  179. */
  180. function wpb_translateColumnWidthToSpan( $width ) {
  181. preg_match( '/(\d+)\/(\d+)/', $width, $matches );
  182. if ( ! empty( $matches ) ) {
  183. $part_x = (int) $matches[1];
  184. $part_y = (int) $matches[2];
  185. if ( $part_x > 0 && $part_y > 0 ) {
  186. $value = ceil( $part_x / $part_y * 12 );
  187. if ( $value > 0 && $value <= 12 ) {
  188. $width = 'vc_col-sm-' . $value;
  189. }
  190. }
  191. }
  192. return $width;
  193. }
  194. /**
  195. * @param $content
  196. * @param bool $autop
  197. *
  198. * @since 4.2
  199. * @return string
  200. */
  201. function wpb_js_remove_wpautop( $content, $autop = false ) {
  202. if ( $autop ) { // Possible to use !preg_match('('.WPBMap::getTagsRegexp().')', $content)
  203. $content = wpautop( preg_replace( '/<\/?p\>/', "\n", $content ) . "\n" );
  204. }
  205. return do_shortcode( shortcode_unautop( $content ) );
  206. }
  207. if ( ! function_exists( 'shortcode_exists' ) ) {
  208. /**
  209. * Check if a shortcode is registered in WordPress.
  210. *
  211. * Examples: shortcode_exists( 'caption' ) - will return true.
  212. * shortcode_exists( 'blah' ) - will return false.
  213. *
  214. * @param bool $shortcode
  215. *
  216. * @since 4.2
  217. * @return bool
  218. */
  219. function shortcode_exists( $shortcode = false ) {
  220. global $shortcode_tags;
  221. if ( ! $shortcode ) {
  222. return false;
  223. }
  224. if ( array_key_exists( $shortcode, $shortcode_tags ) ) {
  225. return true;
  226. }
  227. return false;
  228. }
  229. }
  230. /* Helper function which returns list of site attached images,
  231. and if image is attached to the current post it adds class
  232. 'added'
  233. ---------------------------------------------------------- */
  234. if ( ! function_exists( 'vc_siteAttachedImages' ) ) {
  235. /**
  236. * @param array $att_ids
  237. *
  238. * @since 4.11
  239. * @return string
  240. */
  241. function vc_siteAttachedImages( $att_ids = array() ) {
  242. $output = '';
  243. $limit = (int) apply_filters( 'vc_site_attached_images_query_limit', - 1 );
  244. $media_images = get_posts( 'post_type=attachment&orderby=ID&numberposts=' . $limit );
  245. foreach ( $media_images as $image_post ) {
  246. $thumb_src = wp_get_attachment_image_src( $image_post->ID, 'thumbnail' );
  247. $thumb_src = $thumb_src[0];
  248. $class = ( in_array( $image_post->ID, $att_ids ) ) ? ' class="added"' : '';
  249. $output .= '<li' . $class . '>
  250. <img rel="' . esc_attr( $image_post->ID ) . '" src="' . esc_url( $thumb_src ) . '" />
  251. <span class="img-added">' . __( 'Added', 'js_composer' ) . '</span>
  252. </li>';
  253. }
  254. if ( '' !== $output ) {
  255. $output = '<ul class="gallery_widget_img_select">' . $output . '</ul>';
  256. }
  257. return $output;
  258. }
  259. }
  260. /**
  261. * @param array $images IDs or srcs of images
  262. *
  263. * @since 4.2
  264. * @return string
  265. */
  266. function fieldAttachedImages( $images = array() ) {
  267. $output = '';
  268. foreach ( $images as $image ) {
  269. if ( is_numeric( $image ) ) {
  270. $thumb_src = wp_get_attachment_image_src( $image, 'thumbnail' );
  271. $thumb_src = isset( $thumb_src[0] ) ? $thumb_src[0] : '';
  272. } else {
  273. $thumb_src = $image;
  274. }
  275. if ( $thumb_src ) {
  276. $output .= '
  277. <li class="added">
  278. <img rel="' . esc_attr( $image ) . '" src="' . esc_url( $thumb_src ) . '" />
  279. <a href="#" class="vc_icon-remove"><i class="vc-composer-icon vc-c-icon-close"></i></a>
  280. </li>';
  281. }
  282. }
  283. return $output;
  284. }
  285. /* nectar addition */
  286. function fjarrett_get_attachment_id_by_url( $url ) {
  287. // Split the $url into two parts with the wp-content directory as the separator.
  288. $parse_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
  289. // Get the host of the current site and the host of the $url, ignoring www.
  290. $this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
  291. $file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
  292. // Return nothing if there aren't any $url parts or if the current host and $url host do not match.
  293. if ( ! isset( $parse_url[1] ) || empty( $parse_url[1] ) || ( $this_host != $file_host ) )
  294. return;
  295. global $wpdb;
  296. $prefix = $wpdb->prefix;
  297. $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $prefix . "posts WHERE guid RLIKE %s;", $parse_url[1] ) );
  298. // Returns null if no attachment is found.
  299. return $attachment[0];
  300. }
  301. /* nectar addition end */
  302. /**
  303. * @param $param_value
  304. *
  305. * @since 4.2
  306. * @return array
  307. */
  308. function wpb_removeNotExistingImgIDs( $param_value ) {
  309. $tmp = explode( ',', $param_value );
  310. $return_ar = array();
  311. foreach ( $tmp as $id ) {
  312. if ( wp_get_attachment_image( $id ) ) {
  313. $return_ar[] = $id;
  314. }
  315. }
  316. $tmp = implode( ',', $return_ar );
  317. return $tmp;
  318. }
  319. /*
  320. * Resize images dynamically using wp built in functions
  321. * Victor Teixeira
  322. *
  323. * php 5.2+
  324. *
  325. * Exemplo de uso:
  326. *
  327. * <?php
  328. * $thumb = get_post_thumbnail_id();
  329. * $image = vt_resize( $thumb, '', 140, 110, true );
  330. * ?>
  331. * <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" />
  332. *
  333. */
  334. if ( ! function_exists( 'wpb_resize' ) ) {
  335. /**
  336. * @param int $attach_id
  337. * @param string $img_url
  338. * @param int $width
  339. * @param int $height
  340. * @param bool $crop
  341. *
  342. * @since 4.2
  343. * @return array
  344. */
  345. function wpb_resize( $attach_id = null, $img_url = null, $width, $height, $crop = false ) {
  346. // this is an attachment, so we have the ID
  347. $image_src = array();
  348. if ( $attach_id ) {
  349. $image_src = wp_get_attachment_image_src( $attach_id, 'full' );
  350. $actual_file_path = get_attached_file( $attach_id );
  351. // this is not an attachment, let's use the image url
  352. } elseif ( $img_url ) {
  353. $file_path = parse_url( $img_url );
  354. $actual_file_path = rtrim( ABSPATH, '/' ) . $file_path['path'];
  355. $orig_size = getimagesize( $actual_file_path );
  356. $image_src[0] = $img_url;
  357. $image_src[1] = $orig_size[0];
  358. $image_src[2] = $orig_size[1];
  359. }
  360. if ( ! empty( $actual_file_path ) ) {
  361. $file_info = pathinfo( $actual_file_path );
  362. $extension = '.' . $file_info['extension'];
  363. // the image path without the extension
  364. $no_ext_path = $file_info['dirname'] . '/' . $file_info['filename'];
  365. $cropped_img_path = $no_ext_path . '-' . $width . 'x' . $height . $extension;
  366. // checking if the file size is larger than the target size
  367. // if it is smaller or the same size, stop right here and return
  368. if ( $image_src[1] > $width || $image_src[2] > $height ) {
  369. // the file is larger, check if the resized version already exists (for $crop = true but will also work for $crop = false if the sizes match)
  370. if ( file_exists( $cropped_img_path ) ) {
  371. $cropped_img_url = str_replace( basename( $image_src[0] ), basename( $cropped_img_path ), $image_src[0] );
  372. $vt_image = array(
  373. 'url' => $cropped_img_url,
  374. 'width' => $width,
  375. 'height' => $height,
  376. );
  377. return $vt_image;
  378. }
  379. if ( false == $crop ) {
  380. // calculate the size proportionaly
  381. $proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height );
  382. $resized_img_path = $no_ext_path . '-' . $proportional_size[0] . 'x' . $proportional_size[1] . $extension;
  383. // checking if the file already exists
  384. if ( file_exists( $resized_img_path ) ) {
  385. $resized_img_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] );
  386. $vt_image = array(
  387. 'url' => $resized_img_url,
  388. 'width' => $proportional_size[0],
  389. 'height' => $proportional_size[1],
  390. );
  391. return $vt_image;
  392. }
  393. }
  394. // no cache files - let's finally resize it
  395. $img_editor = wp_get_image_editor( $actual_file_path );
  396. if ( is_wp_error( $img_editor ) || is_wp_error( $img_editor->resize( $width, $height, $crop ) ) ) {
  397. return array(
  398. 'url' => '',
  399. 'width' => '',
  400. 'height' => '',
  401. );
  402. }
  403. $new_img_path = $img_editor->generate_filename();
  404. if ( is_wp_error( $img_editor->save( $new_img_path ) ) ) {
  405. return array(
  406. 'url' => '',
  407. 'width' => '',
  408. 'height' => '',
  409. );
  410. }
  411. if ( ! is_string( $new_img_path ) ) {
  412. return array(
  413. 'url' => '',
  414. 'width' => '',
  415. 'height' => '',
  416. );
  417. }
  418. $new_img_size = getimagesize( $new_img_path );
  419. $new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
  420. // resized output
  421. $vt_image = array(
  422. 'url' => $new_img,
  423. 'width' => $new_img_size[0],
  424. 'height' => $new_img_size[1],
  425. );
  426. return $vt_image;
  427. }
  428. // default output - without resizing
  429. $vt_image = array(
  430. 'url' => $image_src[0],
  431. 'width' => $image_src[1],
  432. 'height' => $image_src[2],
  433. );
  434. return $vt_image;
  435. }
  436. return false;
  437. }
  438. }
  439. if ( ! function_exists( 'wpb_debug' ) ) {
  440. /**
  441. * Returns bool if wpb_debug is provided in url - set WPBakery Page Builder debug mode.
  442. * Used for example in shortcodes (end block comment for example)
  443. * @since 4.2
  444. * @return bool
  445. */
  446. function wpb_debug() {
  447. if ( ( isset( $_GET['wpb_debug'] ) && 'true' === $_GET['wpb_debug'] ) || ( isset( $_GET['vc_debug'] ) && 'true' === $_GET['vc_debug'] ) ) {
  448. return true;
  449. } else {
  450. return false;
  451. }
  452. }
  453. }
  454. /**
  455. * Method adds css class to body tag.
  456. *
  457. * Hooked class method by body_class WP filter. Method adds custom css class to body tag of the page to help
  458. * identify and build design specially for VC shortcodes.
  459. * Used in wp-content/plugins/js_composer/include/classes/core/class-vc-base.php\Vc_Base\bodyClass
  460. *
  461. * @param $classes
  462. *
  463. * @since 4.2
  464. * @return array
  465. */
  466. function js_composer_body_class( $classes ) {
  467. $classes[] = 'wpb-js-composer js-comp-ver-' . WPB_VC_VERSION;
  468. $disable_responsive = vc_settings()->get( 'not_responsive_css' );
  469. if ( '1' !== $disable_responsive ) {
  470. $classes[] = 'vc_responsive';
  471. } else {
  472. $classes[] = 'vc_non_responsive';
  473. }
  474. return $classes;
  475. }
  476. /**
  477. * @param $m
  478. *
  479. * @since 4.2
  480. * @return string
  481. */
  482. /* nectar addition */
  483. function vc_convert_shortcode( $m ) {
  484. list($output, $m_one, $tag, $attr_string, $m_four, $content) = $m;
  485. $result = $width = $el_position = '';
  486. $shortcode_attr = shortcode_parse_atts( $attr_string );
  487. extract(shortcode_atts(array(
  488. 'width' => '1/1',
  489. 'el_class' => '',
  490. 'el_position' => ''
  491. ), $shortcode_attr));
  492. if($tag == 'vc_row' || $tag == 'full_width_section') return $output;
  493. // Start
  494. if(preg_match('/first/', $el_position) || empty($shortcode_attr['width']) || $shortcode_attr['width']==='1/1') {
  495. if(!empty($output)) $result = '[vc_row]';
  496. }
  497. /*if($tag == 'one_half' || $tag == 'one_third' || $tag == 'one_fourth'
  498. || $tag == 'one_sixth' || $tag == 'two_thirds' || $tag == 'three_fourths' || $tag == 'fixth_sixths' || $tag == 'one_whole') {
  499. if($rowStart == 0) {
  500. $rowStart = 1;
  501. $result = '[vc_row]';
  502. }
  503. }*/
  504. if($tag!='vc_column' && $tag != 'one_half' && $tag != 'one_half_last' && $tag != 'one_third' && $tag != 'one_third_last' && $tag != 'one_fourth' && $tag != 'one_fourth_last' && $tag != 'one_sixth' && $tag != 'one_sixth_last' && $tag != 'two_thirds' && $tag != 'two_thirds_last' && $tag != 'three_fourths' && $tag != 'three_fourtsh_last' && $tag != 'fixth_sixths' && $tag != 'five_sixths_last' && $tag != 'one_whole') $result .= "\n".'[vc_column width="'.$width.'"]';
  505. // Tag
  506. $pattern = get_shortcode_regex();
  507. if($tag == 'vc_column' || $tag == 'one_half' || $tag == 'one_half_last' || $tag == 'one_third' || $tag == 'one_third_last' || $tag == 'one_fourth' || $tag == 'one_fourth_last'
  508. || $tag == 'one_sixth' || $tag == 'one_sixth_last' || $tag == 'two_thirds' || $tag == 'two_thirds_last' || $tag == 'three_fourths' || $tag == 'three_fourtsh_last' || $tag == 'fixth_sixths'
  509. || $tag == 'five_sixths_last' || $tag == 'one_whole') {
  510. $result .= "[{$m_one}{$tag} {$attr_string}]".preg_replace_callback( "/{$pattern}/s", 'vc_convert_inner_shortcode', $content)."[/{$tag}{$m_four}]";
  511. } elseif( $tag == 'vc_tabs' || $tag == 'vc_accordion' || $tag == 'vc_tour' || $tag == 'toggle' || $tag == 'tabbed_section' || $tag == 'testimonial_slider' || $tag == 'clients' || $tag == 'pricing_table' ) {
  512. $result .= "[{$m_one}{$tag} {$attr_string}]".preg_replace_callback( "/{$pattern}/s", 'vc_convert_tab_inner_shortcode', $content)."[/{$tag}{$m_four}]";
  513. } else {
  514. $result .= preg_replace('/(\"\d\/\d\")/', '"1/1"', $output);
  515. }
  516. // $content = preg_replace_callback( "/{$pattern}/s", 'vc_convert_inner_shortcode', $content );
  517. // End
  518. if($tag!='vc_column' && $tag != 'one_half' && $tag != 'one_half_last' && $tag != 'one_third' && $tag != 'one_third_last' && $tag != 'one_fourth' && $tag != 'one_fourth_last' && $tag != 'one_sixth' && $tag != 'one_sixth_last' && $tag != 'two_thirds' && $tag != 'two_thirds_last' && $tag != 'three_fourths' && $tag != 'three_fourtsh_last' && $tag != 'fixth_sixths' && $tag != 'five_sixths_last' && $tag != 'one_whole') $result .= '[/vc_column]';
  519. if(preg_match('/last/', $el_position) || empty($shortcode_attr['width']) || $shortcode_attr['width']==='1/1') {
  520. /*if($tag != 'one_half' && $tag != 'one_half_last' && $tag != 'one_third' && $tag != 'one_third_last' && $tag != 'one_fourth' && $tag != 'one_fourth_last'
  521. && $tag != 'one_sixth' && $tag != 'one_sixth_last' && $tag != 'two_thirds' && $tag != 'two_thirds_last' && $tag != 'three_fourths' && $tag != 'three_fourtsh_last' && $tag != 'fixth_sixths'
  522. && $tag != 'five_sixths_last' && $tag != 'one_whole') {*/
  523. if(!empty($output)) $result .= '[/vc_row]'."\n";
  524. /*}*/
  525. }
  526. /*if($tag == 'one_half_last' || $tag == 'one_third_last' || $tag == 'one_fourth_last'
  527. || $tag == 'one_sixth_last' || $tag == 'two_thirds_last' || $tag == 'three_fourtsh_last' || $tag !== 'five_sixths_last') {
  528. $result .= '[/vc_row]'."\n";
  529. $rowStart = 0;
  530. }*/
  531. return $result;
  532. }
  533. /* nectar addition end */
  534. /**
  535. * @param $m
  536. *
  537. * @since 4.2
  538. * @return string
  539. */
  540. function vc_convert_tab_inner_shortcode( $m ) {
  541. list( $output, $m_one, $tag, $attr_string, $m_four, $content ) = $m;
  542. $result = $width = $el_position = '';
  543. extract( shortcode_atts( array(
  544. 'width' => '1/1',
  545. 'el_class' => '',
  546. 'el_position' => '',
  547. ), shortcode_parse_atts( $attr_string ) ) );
  548. $pattern = get_shortcode_regex();
  549. $result .= "[{$m_one}{$tag} {$attr_string}]" . preg_replace_callback( "/{$pattern}/s", 'vc_convert_inner_shortcode', $content ) . "[/{$tag}{$m_four}]";
  550. return $result;
  551. }
  552. /**
  553. * @param $m
  554. *
  555. * @since 4.2
  556. * @return string
  557. */
  558. function vc_convert_inner_shortcode( $m ) {
  559. list( $output, $m_one, $tag, $attr_string, $m_four, $content ) = $m;
  560. $result = $width = $el_position = '';
  561. extract( shortcode_atts( array(
  562. 'width' => '1/1',
  563. 'el_class' => '',
  564. 'el_position' => '',
  565. ), shortcode_parse_atts( $attr_string ) ) );
  566. if ( '1/1' !== $width ) {
  567. if ( preg_match( '/first/', $el_position ) ) {
  568. $result .= '[vc_row_inner]';
  569. }
  570. $result .= "\n" . '[vc_column_inner width="' . esc_attr( $width ) . '" el_position="' . esc_attr( $el_position ) . '"]';
  571. $attr = '';
  572. foreach ( shortcode_parse_atts( $attr_string ) as $key => $value ) {
  573. if ( 'width' === $key ) {
  574. $value = '1/1';
  575. } elseif ( 'el_position' === $key ) {
  576. $value = 'first last';
  577. }
  578. $attr .= ' ' . $key . '="' . $value . '"';
  579. }
  580. $result .= "[{$m_one}{$tag} {$attr}]" . $content . "[/{$tag}{$m_four}]";
  581. $result .= '[/vc_column_inner]';
  582. if ( preg_match( '/last/', $el_position ) ) {
  583. $result .= '[/vc_row_inner]' . "\n";
  584. }
  585. } else {
  586. $result = $output;
  587. }
  588. return $result;
  589. }
  590. global $vc_row_layouts;
  591. $vc_row_layouts = array(
  592. /*
  593. * How to count mask?
  594. * mask = column_count . sum of all numbers. Example layout 12_12 mask = (column count=2)(1+2+1+2=6)= 26
  595. */
  596. array(
  597. 'cells' => '11',
  598. 'mask' => '12',
  599. 'title' => '1/1',
  600. 'icon_class' => '1-1',
  601. ),
  602. array(
  603. 'cells' => '12_12',
  604. 'mask' => '26',
  605. 'title' => '1/2 + 1/2',
  606. 'icon_class' => '1-2_1-2',
  607. ),
  608. array(
  609. 'cells' => '23_13',
  610. 'mask' => '29',
  611. 'title' => '2/3 + 1/3',
  612. 'icon_class' => '2-3_1-3',
  613. ),
  614. array(
  615. 'cells' => '13_13_13',
  616. 'mask' => '312',
  617. 'title' => '1/3 + 1/3 + 1/3',
  618. 'icon_class' => '1-3_1-3_1-3',
  619. ),
  620. array(
  621. 'cells' => '14_14_14_14',
  622. 'mask' => '420',
  623. 'title' => '1/4 + 1/4 + 1/4 + 1/4',
  624. 'icon_class' => '1-4_1-4_1-4_1-4',
  625. ),
  626. array(
  627. 'cells' => '14_34',
  628. 'mask' => '212',
  629. 'title' => '1/4 + 3/4',
  630. 'icon_class' => '1-4_3-4',
  631. ),
  632. array(
  633. 'cells' => '14_12_14',
  634. 'mask' => '313',
  635. 'title' => '1/4 + 1/2 + 1/4',
  636. 'icon_class' => '1-4_1-2_1-4',
  637. ),
  638. array(
  639. 'cells' => '56_16',
  640. 'mask' => '218',
  641. 'title' => '5/6 + 1/6',
  642. 'icon_class' => '5-6_1-6',
  643. ),
  644. array(
  645. 'cells' => '16_16_16_16_16_16',
  646. 'mask' => '642',
  647. 'title' => '1/6 + 1/6 + 1/6 + 1/6 + 1/6 + 1/6',
  648. 'icon_class' => '1-6_1-6_1-6_1-6_1-6_1-6',
  649. ),
  650. array(
  651. 'cells' => '16_23_16',
  652. 'mask' => '319',
  653. 'title' => '1/6 + 4/6 + 1/6',
  654. 'icon_class' => '1-6_2-3_1-6',
  655. ),
  656. array(
  657. 'cells' => '16_16_16_12',
  658. 'mask' => '424',
  659. 'title' => '1/6 + 1/6 + 1/6 + 1/2',
  660. 'icon_class' => '1-6_1-6_1-6_1-2',
  661. ),
  662. );
  663. /**
  664. * @param $width
  665. *
  666. * @since 4.2
  667. * @return string
  668. */
  669. function wpb_vc_get_column_width_indent( $width ) {
  670. $identy = '11';
  671. if ( 'vc_col-sm-6' === $width ) {
  672. $identy = '12';
  673. } elseif ( 'vc_col-sm-3' === $width ) {
  674. $identy = '14';
  675. } elseif ( 'vc_col-sm-4' === $width ) {
  676. $identy = '13';
  677. } elseif ( 'vc_col-sm-8' === $width ) {
  678. $identy = '23';
  679. } elseif ( 'vc_col-sm-9' === $width ) {
  680. $identy = '34';
  681. } elseif ( 'vc_col-sm-2' === $width ) {
  682. $identy = '16'; // TODO: check why there is no "vc_col-sm-1, -5, -6, -7, -11, -12.
  683. } elseif ( 'vc_col-sm-10' === $width ) {
  684. $identy = '56';
  685. }
  686. return $identy;
  687. }
  688. /* Make any HEX color lighter or darker
  689. ---------------------------------------------------------- */
  690. /**
  691. * @param $colour
  692. * @param $per
  693. *
  694. * @since 4.2
  695. * @return string
  696. */
  697. function vc_colorCreator( $colour, $per = 10 ) {
  698. require_once 'class-vc-color-helper.php';
  699. $color = $colour;
  700. if ( stripos( $colour, 'rgba(' ) !== false ) {
  701. $rgb = str_replace( array(
  702. 'rgba',
  703. 'rgb',
  704. '(',
  705. ')',
  706. ), '', $colour );
  707. $rgb = explode( ',', $rgb );
  708. $rgb_array = array(
  709. 'R' => $rgb[0],
  710. 'G' => $rgb[1],
  711. 'B' => $rgb[2],
  712. );
  713. $alpha = $rgb[3];
  714. try {
  715. $color = Vc_Color_Helper::rgbToHex( $rgb_array );
  716. $color_obj = new Vc_Color_Helper( $color );
  717. if ( $per >= 0 ) {
  718. $color = $color_obj->lighten( $per );
  719. } else {
  720. $color = $color_obj->darken( abs( $per ) );
  721. }
  722. $rgba = $color_obj->hexToRgb( $color );
  723. $rgba[] = $alpha;
  724. $css_rgba_color = 'rgba(' . implode( ', ', $rgba ) . ')';
  725. return $css_rgba_color;
  726. } catch ( Exception $e ) {
  727. // In case of error return same as given
  728. return $colour;
  729. }
  730. } else if ( stripos( $colour, 'rgb(' ) !== false ) {
  731. $rgb = str_replace( array(
  732. 'rgba',
  733. 'rgb',
  734. '(',
  735. ')',
  736. ), '', $colour );
  737. $rgb = explode( ',', $rgb );
  738. $rgb_array = array(
  739. 'R' => $rgb[0],
  740. 'G' => $rgb[1],
  741. 'B' => $rgb[2],
  742. );
  743. try {
  744. $color = Vc_Color_Helper::rgbToHex( $rgb_array );
  745. } catch ( Exception $e ) {
  746. // In case of error return same as given
  747. return $colour;
  748. }
  749. }
  750. try {
  751. $color_obj = new Vc_Color_Helper( $color );
  752. if ( $per >= 0 ) {
  753. $color = $color_obj->lighten( $per );
  754. } else {
  755. $color = $color_obj->darken( abs( $per ) );
  756. }
  757. return '#' . $color;
  758. } catch ( Exception $e ) {
  759. return $colour;
  760. }
  761. }
  762. /* nectar addition */
  763. function hex2rgba($color, $opacity = false) {
  764. $default = 'rgb(0,0,0)';
  765. //Return default if no color provided
  766. if(empty($color))
  767. return $default;
  768. //Sanitize $color if "#" is provided
  769. if ($color[0] == '#' ) {
  770. $color = substr( $color, 1 );
  771. }
  772. //Check if color has 6 or 3 characters and get values
  773. if (strlen($color) == 6) {
  774. $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
  775. } elseif ( strlen( $color ) == 3 ) {
  776. $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
  777. } else {
  778. return $default;
  779. }
  780. //Convert hexadec to rgb
  781. $rgb = array_map('hexdec', $hex);
  782. //Check if opacity is set(rgba or rgb)
  783. if($opacity){
  784. if(abs($opacity) > 1)
  785. $opacity = 1.0;
  786. $output = 'rgba('.implode(",",$rgb).','.$opacity.')';
  787. } else {
  788. $output = 'rgb('.implode(",",$rgb).')';
  789. }
  790. //Return rgb(a) color string
  791. return $output;
  792. }
  793. /* nectar addition end */
  794. /* HEX to RGB converter
  795. ---------------------------------------------------------- */
  796. /**
  797. * @param $color
  798. *
  799. * @since 4.2
  800. * @return array|bool
  801. */
  802. function vc_hex2rgb( $color ) {
  803. $color = str_replace( '#', '', $color );
  804. if ( strlen( $color ) === 6 ) {
  805. list( $r, $g, $b ) = array(
  806. $color[0] . $color[1],
  807. $color[2] . $color[3],
  808. $color[4] . $color[5],
  809. );
  810. } elseif ( strlen( $color ) === 3 ) {
  811. list( $r, $g, $b ) = array(
  812. $color[0] . $color[0],
  813. $color[1] . $color[1],
  814. $color[2] . $color[2],
  815. );
  816. } else {
  817. return false;
  818. }
  819. $r = hexdec( $r );
  820. $g = hexdec( $g );
  821. $b = hexdec( $b );
  822. return array(
  823. $r,
  824. $g,
  825. $b,
  826. );
  827. }
  828. /**
  829. * Parse string like "title:Hello world|weekday:Monday" to array('title' => 'Hello World', 'weekday' => 'Monday')
  830. *
  831. * @param $value
  832. * @param array $default
  833. *
  834. * @since 4.2
  835. * @return array
  836. */
  837. function vc_parse_multi_attribute( $value, $default = array() ) {
  838. $result = $default;
  839. $params_pairs = explode( '|', $value );
  840. if ( ! empty( $params_pairs ) ) {
  841. foreach ( $params_pairs as $pair ) {
  842. $param = preg_split( '/\:/', $pair );
  843. if ( ! empty( $param[0] ) && isset( $param[1] ) ) {
  844. $result[ $param[0] ] = rawurldecode( $param[1] );
  845. }
  846. }
  847. }
  848. return $result;
  849. }
  850. /**
  851. * @param $v
  852. *
  853. * @since 4.2
  854. * @return string
  855. */
  856. function vc_param_options_parse_values( $v ) {
  857. return rawurldecode( $v );
  858. }
  859. /**
  860. * @param $name
  861. * @param $settings
  862. *
  863. * @since 4.2
  864. * @return bool
  865. */
  866. function vc_param_options_get_settings( $name, $settings ) {
  867. if ( is_array( $settings ) ) {
  868. foreach ( $settings as $params ) {
  869. if ( isset( $params['name'] ) && $params['name'] === $name && isset( $params['type'] ) ) {
  870. return $params;
  871. }
  872. }
  873. }
  874. return false;
  875. }
  876. /**
  877. * @param $atts
  878. *
  879. * @since 4.2
  880. * @return string
  881. */
  882. function vc_convert_atts_to_string( $atts ) {
  883. $output = '';
  884. foreach ( $atts as $key => $value ) {
  885. $output .= ' ' . $key . '="' . $value . '"';
  886. }
  887. return $output;
  888. }
  889. /**
  890. * @param $string
  891. * @param $tag
  892. * @param $param
  893. *
  894. * @since 4.2
  895. * @return array
  896. */
  897. function vc_parse_options_string( $string, $tag, $param ) {
  898. $options = $option_settings_list = array();
  899. $settings = WPBMap::getParam( $tag, $param );
  900. foreach ( preg_split( '/\|/', $string ) as $value ) {
  901. if ( preg_match( '/\:/', $value ) ) {
  902. $split = preg_split( '/\:/', $value );
  903. $option_name = $split[0];
  904. $option_settings = $option_settings_list[ $option_name ] = vc_param_options_get_settings( $option_name, $settings['options'] );
  905. if ( isset( $option_settings['type'] ) && 'checkbox' === $option_settings['type'] ) {
  906. $option_value = array_map( 'vc_param_options_parse_values', preg_split( '/\,/', $split[1] ) );
  907. } else {
  908. $option_value = rawurldecode( $split[1] );
  909. }
  910. $options[ $option_name ] = $option_value;
  911. }
  912. }
  913. if ( isset( $settings['options'] ) ) {
  914. foreach ( $settings['options'] as $setting_option ) {
  915. if ( 'separator' !== $setting_option['type'] && isset( $setting_option['value'] ) && empty( $options[ $setting_option['name'] ] ) ) {
  916. $options[ $setting_option['name'] ] = 'checkbox' === $setting_option['type'] ? preg_split( '/\,/', $setting_option['value'] ) : $setting_option['value'];
  917. }
  918. if ( isset( $setting_option['name'] ) && isset( $options[ $setting_option['name'] ] ) && isset( $setting_option['value_type'] ) ) {
  919. if ( 'integer' === $setting_option['value_type'] ) {
  920. $options[ $setting_option['name'] ] = (int) $options[ $setting_option['name'] ];
  921. } elseif ( 'float' === $setting_option['value_type'] ) {
  922. $options[ $setting_option['name'] ] = (float) $options[ $setting_option['name'] ];
  923. } elseif ( 'boolean' === $setting_option['value_type'] ) {
  924. $options[ $setting_option['name'] ] = (boolean) $options[ $setting_option['name'] ];
  925. }
  926. }
  927. }
  928. }
  929. return $options;
  930. }
  931. /**
  932. * Convert string to a valid css class name.
  933. *
  934. * @since 4.3
  935. *
  936. * @param string $class
  937. *
  938. * @return string
  939. */
  940. function vc_build_safe_css_class( $class ) {
  941. return preg_replace( '/\W+/', '', strtolower( str_replace( ' ', '_', strip_tags( $class ) ) ) );
  942. }
  943. /**
  944. * Include template from templates dir.
  945. *
  946. * @since 4.3
  947. *
  948. * @param $template
  949. * @param array $variables - passed variables to the template.
  950. *
  951. * @param bool $once
  952. *
  953. * @return mixed
  954. */
  955. function vc_include_template( $template, $variables = array(), $once = false ) {
  956. is_array( $variables ) && extract( $variables );
  957. if ( $once ) {
  958. return require_once vc_template( $template );
  959. } else {
  960. return require vc_template( $template );
  961. }
  962. }
  963. /**
  964. * Output template from templates dir.
  965. *
  966. * @since 4.4
  967. *
  968. * @param $template
  969. * @param array $variables - passed variables to the template.
  970. *
  971. * @param bool $once
  972. *
  973. * @return string
  974. */
  975. function vc_get_template( $template, $variables = array(), $once = false ) {
  976. ob_start();
  977. vc_include_template( $template, $variables, $once );
  978. return ob_get_clean();
  979. }
  980. /**
  981. * if php version < 5.3 this function is required.
  982. */
  983. if ( ! function_exists( 'lcfirst' ) ) {
  984. /**
  985. * @param $str
  986. *
  987. * @since 4.3, fix #1093
  988. * @return mixed
  989. */
  990. function lcfirst( $str ) {
  991. $str[0] = function_exists( 'mb_strtolower' ) ? mb_strtolower( $str[0] ) : strtolower( $str[0] );
  992. return $str;
  993. }
  994. }
  995. /**
  996. * VC Convert a value to studly caps case.
  997. *
  998. * @since 4.3
  999. *
  1000. * @param string $value
  1001. *
  1002. * @return string
  1003. */
  1004. function vc_studly( $value ) {
  1005. $value = ucwords( str_replace( array(
  1006. '-',
  1007. '_',
  1008. ), ' ', $value ) );
  1009. return str_replace( ' ', '', $value );
  1010. }
  1011. /**
  1012. * VC Convert a value to camel case.
  1013. *
  1014. * @since 4.3
  1015. *
  1016. * @param string $value
  1017. *
  1018. * @return string
  1019. */
  1020. function vc_camel_case( $value ) {
  1021. return lcfirst( vc_studly( $value ) );
  1022. }
  1023. /**
  1024. * Enqueue icon element font
  1025. * @todo move to separate folder
  1026. * @since 4.4
  1027. *
  1028. * @param $font
  1029. */
  1030. function vc_icon_element_fonts_enqueue( $font ) {
  1031. switch ( $font ) {
  1032. case 'fontawesome':
  1033. wp_enqueue_style( 'font-awesome' );
  1034. break;
  1035. case 'openiconic':
  1036. wp_enqueue_style( 'vc_openiconic' );
  1037. break;
  1038. case 'typicons':
  1039. wp_enqueue_style( 'vc_typicons' );
  1040. break;
  1041. case 'entypo':
  1042. wp_enqueue_style( 'vc_entypo' );
  1043. break;
  1044. case 'linecons':
  1045. wp_enqueue_style( 'vc_linecons' );
  1046. break;
  1047. case 'monosocial':
  1048. wp_enqueue_style( 'vc_monosocialiconsfont' );
  1049. break;
  1050. /*nectar addition */
  1051. /*
  1052. case 'material':
  1053. wp_enqueue_style( 'vc_material' );
  1054. break;
  1055. */
  1056. /*nectar addition end */
  1057. default:
  1058. do_action( 'vc_enqueue_font_icon_element', $font ); // hook to custom do enqueue style
  1059. }
  1060. }
  1061. /**
  1062. * Function merges defaults attributes in attributes by keeping it values
  1063. *
  1064. * Example
  1065. * array defaults | array attributes | result array
  1066. * 'color'=>'black', - 'color'=>'black',
  1067. * 'target'=>'_self', 'target'=>'_blank', 'target'=>'_blank',
  1068. * - 'link'=>'google.com' 'link'=>'google.com'
  1069. *
  1070. * @since 4.4
  1071. *
  1072. * @param array $defaults
  1073. * @param array $attributes
  1074. *
  1075. * @return array - merged attributes
  1076. *
  1077. * @see vc_map_get_attributes
  1078. */
  1079. function vc_shortcode_attribute_parse( $defaults = array(), $attributes = array() ) {
  1080. $atts = $attributes + shortcode_atts( $defaults, $attributes );
  1081. return $atts;
  1082. }
  1083. function vc_get_shortcode_regex( $tagregexp = '' ) {
  1084. if ( 0 === strlen( $tagregexp ) ) {
  1085. return get_shortcode_regex();
  1086. }
  1087. return '\\[' // Opening bracket
  1088. . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
  1089. . "($tagregexp)" // 2: Shortcode name
  1090. . '(?![\\w-])' // Not followed by word character or hyphen
  1091. . '(' // 3: Unroll the loop: Inside the opening shortcode tag
  1092. . '[^\\]\\/]*' // Not a closing bracket or forward slash
  1093. . '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket
  1094. . '[^\\]\\/]*' // Not a closing bracket or forward slash
  1095. . ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag ...
  1096. . '\\]' // ... and closing bracket
  1097. . '|' . '\\]' // Closing bracket
  1098. . '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
  1099. . '[^\\[]*+' // Not an opening bracket
  1100. . '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
  1101. . '[^\\[]*+' // Not an opening bracket
  1102. . ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag
  1103. . ')?' . ')' . '(\\]?)';
  1104. }
  1105. /**
  1106. * Used to send warning message
  1107. *
  1108. * @since 4.5
  1109. *
  1110. * @param $message
  1111. *
  1112. * @return string
  1113. */
  1114. function vc_message_warning( $message ) {
  1115. return '<div class="wpb_element_wrapper"><div class="vc_message_box vc_message_box-standard vc_message_box-rounded vc_color-warning">
  1116. <div class="vc_message_box-icon"><i class="fa fa-exclamation-triangle"></i>
  1117. </div><p class="messagebox_text">' . $message . '</p>
  1118. </div></div>';
  1119. }
  1120. /**
  1121. * Extract video ID from youtube url
  1122. *
  1123. * @param string $url Youtube url
  1124. *
  1125. * @return string
  1126. */
  1127. function vc_extract_youtube_id( $url ) {
  1128. parse_str( parse_url( $url, PHP_URL_QUERY ), $vars );
  1129. if ( ! isset( $vars['v'] ) ) {
  1130. return '';
  1131. }
  1132. return $vars['v'];
  1133. }
  1134. function vc_taxonomies_types() {
  1135. global $vc_taxonomies_types;
  1136. if ( is_null( $vc_taxonomies_types ) ) {
  1137. $vc_taxonomies_types = get_taxonomies( array( 'public' => true ), 'objects' );
  1138. }
  1139. return $vc_taxonomies_types;
  1140. }
  1141. /**
  1142. * Since
  1143. *
  1144. * @since 4.5.3
  1145. *
  1146. * @param $term
  1147. *
  1148. * @return array
  1149. */
  1150. function vc_get_term_object( $term ) {
  1151. $vc_taxonomies_types = vc_taxonomies_types();
  1152. return array(
  1153. 'label' => $term->name,
  1154. 'value' => $term->term_id,
  1155. 'group_id' => $term->taxonomy,
  1156. 'group' => isset( $vc_taxonomies_types[ $term->taxonomy ], $vc_taxonomies_types[ $term->taxonomy ]->labels, $vc_taxonomies_types[ $term->taxonomy ]->labels->name ) ? $vc_taxonomies_types[ $term->taxonomy ]->labels->name : __( 'Taxonomies', 'js_composer' ),
  1157. );
  1158. }
  1159. /**
  1160. * Extract width/height from string
  1161. *
  1162. * @param string $dimensions WxH
  1163. *
  1164. * @since 4.7
  1165. *
  1166. * @return mixed array(width, height) or false
  1167. */
  1168. function vcExtractDimensions( $dimensions ) {
  1169. $dimensions = str_replace( ' ', '', $dimensions );
  1170. $matches = null;
  1171. if ( preg_match( '/(\d+)x(\d+)/', $dimensions, $matches ) ) {
  1172. return array(
  1173. $matches[1],
  1174. $matches[2],
  1175. );
  1176. }
  1177. return false;
  1178. }
  1179. /**
  1180. * Check if element has specific class
  1181. *
  1182. * E.g. f('foo', 'foo bar baz') -> true
  1183. *
  1184. * @param string $class Class to check for
  1185. * @param string $classes Classes separated by space(s)
  1186. *
  1187. * @return bool
  1188. */
  1189. function vc_has_class( $class, $classes ) {
  1190. return in_array( $class, explode( ' ', strtolower( $classes ) ) );
  1191. }
  1192. /**
  1193. * Remove specific class from classes string
  1194. *
  1195. * E.g. f('foo', 'foo bar baz') -> 'bar baz'
  1196. *
  1197. * @param string $class Class to remove
  1198. * @param string $classes Classes separated by space(s)
  1199. *
  1200. * @return string
  1201. */
  1202. function vc_remove_class( $class, $classes ) {
  1203. $list_classes = explode( ' ', strtolower( $classes ) );
  1204. $key = array_search( $class, $list_classes, true );
  1205. if ( false === $key ) {
  1206. return $classes;
  1207. }
  1208. unset( $list_classes[ $key ] );
  1209. return implode( ' ', $list_classes );
  1210. }
  1211. /**
  1212. * Convert array of named params to string version
  1213. * All values will be escaped
  1214. *
  1215. * E.g. f(array('name' => 'foo', 'id' => 'bar')) -> 'name="foo" id="bar"'
  1216. *
  1217. * @param $attributes
  1218. *
  1219. * @return string
  1220. */
  1221. function vc_stringify_attributes( $attributes ) {
  1222. $atts = array();
  1223. foreach ( $attributes as $name => $value ) {
  1224. $atts[] = $name . '="' . esc_attr( $value ) . '"';
  1225. }
  1226. return implode( ' ', $atts );
  1227. }
  1228. function vc_is_responsive_disabled() {
  1229. $disable_responsive = vc_settings()->get( 'not_responsive_css' );
  1230. return '1' === $disable_responsive;
  1231. }
  1232. /**
  1233. * Do shortcode single render point
  1234. *
  1235. * @param $atts
  1236. * @param null $content
  1237. * @param null $tag
  1238. *
  1239. * @return string
  1240. */
  1241. function vc_do_shortcode( $atts, $content = null, $tag = null ) {
  1242. return Vc_Shortcodes_Manager::getInstance()->getElementClass( $tag )->output( $atts, $content );
  1243. }
  1244. /**
  1245. * Return random string
  1246. *
  1247. * @param int $length
  1248. *
  1249. * @return string
  1250. */
  1251. function vc_random_string( $length = 10 ) {
  1252. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1253. $len = strlen( $characters );
  1254. $str = '';
  1255. for ( $i = 0; $i < $length; $i ++ ) {
  1256. $str .= $characters[ rand( 0, $len - 1 ) ];
  1257. }
  1258. return $str;
  1259. }
  1260. function vc_slugify( $str ) {
  1261. $str = strtolower( $str );
  1262. $str = html_entity_decode( $str );
  1263. $str = preg_replace( '/[^\w ]+/', '', $str );
  1264. $str = preg_replace( '/ +/', '-', $str );
  1265. return $str;
  1266. }