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

/wp-content/plugins/js_composer/include/helpers/helpers.php

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