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

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

https://gitlab.com/juanito.abelo/nlmobile
PHP | 1160 lines | 693 code | 112 blank | 355 comment | 137 complexity | b6d797fcedca6fccbae4eed118ff07e7 MD5 | raw file
  1. <?php
  2. /**
  3. * WPBakery Visual Composer helpers functions
  4. *
  5. * @package WPBakeryVisualComposer
  6. *
  7. */
  8. if ( ! defined( 'WPB_VC_VERSION' ) ) {
  9. die( '-1' );
  10. } // Check if this file is loaded in js_composer
  11. /**
  12. * @param array $params
  13. *
  14. * @since 4.2
  15. * vc_filter: vc_wpb_getimagesize - to override output of this function
  16. * @return array|bool
  17. */
  18. function wpb_getImageBySize(
  19. $params = array(
  20. 'post_id' => null,
  21. 'attach_id' => null,
  22. 'thumb_size' => 'thumbnail',
  23. 'class' => ''
  24. )
  25. ) {
  26. //array( 'post_id' => $post_id, 'thumb_size' => $grid_thumb_size )
  27. if ( ( ! isset( $params['attach_id'] ) || $params['attach_id'] == null ) && ( ! isset( $params['post_id'] ) || $params['post_id'] == null ) ) {
  28. return false;
  29. }
  30. $post_id = isset( $params['post_id'] ) ? $params['post_id'] : 0;
  31. if ( $post_id ) {
  32. $attach_id = get_post_thumbnail_id( $post_id );
  33. } else {
  34. $attach_id = $params['attach_id'];
  35. }
  36. $thumb_size = $params['thumb_size'];
  37. $thumb_class = ( isset( $params['class'] ) && $params['class'] != '' ) ? $params['class'] . ' ' : '';
  38. global $_wp_additional_image_sizes;
  39. $thumbnail = '';
  40. 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(
  41. 'thumbnail',
  42. 'thumb',
  43. 'medium',
  44. 'large',
  45. 'full'
  46. ) ) )
  47. ) {
  48. $thumbnail = wp_get_attachment_image( $attach_id, $thumb_size, false, array( 'class' => $thumb_class . 'attachment-' . $thumb_size ) );
  49. } elseif ( $attach_id ) {
  50. if ( is_string( $thumb_size ) ) {
  51. preg_match_all( '/\d+/', $thumb_size, $thumb_matches );
  52. if ( isset( $thumb_matches[0] ) ) {
  53. $thumb_size = array();
  54. if ( count( $thumb_matches[0] ) > 1 ) {
  55. $thumb_size[] = $thumb_matches[0][0]; // width
  56. $thumb_size[] = $thumb_matches[0][1]; // height
  57. } elseif ( count( $thumb_matches[0] ) > 0 && count( $thumb_matches[0] ) < 2 ) {
  58. $thumb_size[] = $thumb_matches[0][0]; // width
  59. $thumb_size[] = $thumb_matches[0][0]; // height
  60. } else {
  61. $thumb_size = false;
  62. }
  63. }
  64. }
  65. if ( is_array( $thumb_size ) ) {
  66. // Resize image to custom size
  67. $p_img = wpb_resize( $attach_id, null, $thumb_size[0], $thumb_size[1], true );
  68. $alt = trim( strip_tags( get_post_meta( $attach_id, '_wp_attachment_image_alt', true ) ) );
  69. $attachment = get_post( $attach_id );
  70. if(!empty($attachment)) {
  71. $title = trim( strip_tags( $attachment->post_title ) );
  72. if ( empty( $alt ) ) {
  73. $alt = trim( strip_tags( $attachment->post_excerpt ) ); // If not, Use the Caption
  74. }
  75. if ( empty( $alt ) ) {
  76. $alt = $title;
  77. } // Finally, use the title
  78. if ( $p_img ) {
  79. $img_class = '';
  80. //if ( $grid_layout == 'thumbnail' ) $img_class = ' no_bottom_margin'; class="'.$img_class.'"
  81. $thumbnail = '<img class="' . esc_attr( $thumb_class ) . '" src="' . esc_attr( $p_img['url'] ) . '" width="' . esc_attr( $p_img['width'] ) . '" height="' . esc_attr( $p_img['height'] ) . '" alt="' . esc_attr( $alt ) . '" title="' . esc_attr( $title ) . '" />';
  82. }
  83. }
  84. }
  85. }
  86. $p_img_large = wp_get_attachment_image_src( $attach_id, 'large' );
  87. return apply_filters( 'vc_wpb_getimagesize', array(
  88. 'thumbnail' => $thumbnail,
  89. 'p_img_large' => $p_img_large
  90. ), $attach_id, $params );
  91. }
  92. /**
  93. * @param $width
  94. *
  95. * @since 4.2
  96. * @return string
  97. */
  98. function wpb_getColumnControls( $width ) {
  99. switch ( $width ) {
  100. case "vc_col-md-2" :
  101. $w = "1/6";
  102. break;
  103. case "vc_col-sm-3" :
  104. $w = "1/4";
  105. break;
  106. case "vc_col-sm-4" :
  107. $w = "1/3";
  108. break;
  109. case "vc_col-sm-6" :
  110. $w = "1/2";
  111. break;
  112. case "vc_col-sm-8" :
  113. $w = "2/3";
  114. break;
  115. case "vc_col-sm-9" :
  116. $w = "3/4";
  117. break;
  118. case "vc_col-sm-12" :
  119. $w = "1/1";
  120. break;
  121. default :
  122. $w = $width;
  123. }
  124. return $w;
  125. }
  126. /* Convert vc_col-sm-3 to 1/4
  127. ---------------------------------------------------------- */
  128. /**
  129. * @param $width
  130. *
  131. * @since 4.2
  132. * @return string
  133. */
  134. function wpb_translateColumnWidthToFractional( $width ) {
  135. switch ( $width ) {
  136. case "vc_col-sm-2" :
  137. $w = "1/6";
  138. break;
  139. case "vc_col-sm-3" :
  140. $w = "1/4";
  141. break;
  142. case "vc_col-sm-4" :
  143. $w = "1/3";
  144. break;
  145. case "vc_col-sm-6" :
  146. $w = "1/2";
  147. break;
  148. case "vc_col-sm-8" :
  149. $w = "2/3";
  150. break;
  151. case "vc_col-sm-9" :
  152. $w = "3/4";
  153. break;
  154. case "vc_col-sm-12" :
  155. $w = "1/1";
  156. break;
  157. default :
  158. $w = $width;
  159. }
  160. return $w;
  161. }
  162. /* Convert 2 to
  163. ---------------------------------------------------------- */
  164. /**
  165. * @param $grid_columns_count
  166. *
  167. * @since 4.2
  168. * @return string
  169. */
  170. function wpb_translateColumnsCountToSpanClass( $grid_columns_count ) {
  171. $teaser_width = '';
  172. switch ( $grid_columns_count ) {
  173. case '1' :
  174. $teaser_width = 'vc_col-sm-12';
  175. break;
  176. case '2' :
  177. $teaser_width = 'vc_col-sm-6';
  178. break;
  179. case '3' :
  180. $teaser_width = 'vc_col-sm-4';
  181. break;
  182. case '4' :
  183. $teaser_width = 'vc_col-sm-3';
  184. break;
  185. case '5':
  186. $teaser_width = 'vc_col-sm-10';
  187. break;
  188. case '6' :
  189. $teaser_width = 'vc_col-sm-2';
  190. break;
  191. }
  192. //return $teaser_width;
  193. $custom = get_custom_column_class( $teaser_width );
  194. return $custom ? $custom : $teaser_width;
  195. }
  196. /**
  197. * @param $width
  198. * @param bool $front
  199. *
  200. * @since 4.2
  201. * @return bool|string
  202. */
  203. function wpb_translateColumnWidthToSpan( $width, $front = true ) {
  204. preg_match( '/(\d+)\/(\d+)/', $width, $matches );
  205. $w = $width;
  206. if ( ! empty( $matches ) ) {
  207. $part_x = (int) $matches[1];
  208. $part_y = (int) $matches[2];
  209. if ( $part_x > 0 && $part_y > 0 ) {
  210. $value = ceil( $part_x / $part_y * 12 );
  211. if ( $value > 0 && $value <= 12 ) {
  212. $w = 'vc_col-sm-' . $value;
  213. }
  214. }
  215. }
  216. $custom = $front ? get_custom_column_class( $w ) : false;
  217. return $custom ? $custom : $w;
  218. }
  219. /**
  220. * @param $content
  221. * @param bool $autop
  222. *
  223. * @since 4.2
  224. * @return string
  225. */
  226. function wpb_js_remove_wpautop( $content, $autop = false ) {
  227. if ( $autop ) { // Possible to use !preg_match('('.WPBMap::getTagsRegexp().')', $content)
  228. $content = wpautop( preg_replace( '/<\/?p\>/', "\n", $content ) . "\n" );
  229. }
  230. return do_shortcode( shortcode_unautop( $content ) );
  231. }
  232. if ( ! function_exists( 'shortcode_exists' ) ) {
  233. /**
  234. * Check if a shortcode is registered in WordPress.
  235. *
  236. * Examples: shortcode_exists( 'caption' ) - will return true.
  237. * shortcode_exists( 'blah' ) - will return false.
  238. *
  239. * @param bool $shortcode
  240. *
  241. * @since 4.2
  242. * @return bool
  243. */
  244. function shortcode_exists( $shortcode = false ) {
  245. global $shortcode_tags;
  246. if ( ! $shortcode ) {
  247. return false;
  248. }
  249. if ( array_key_exists( $shortcode, $shortcode_tags ) ) {
  250. return true;
  251. }
  252. return false;
  253. }
  254. }
  255. /* Helper function which returs list of site attached images,
  256. and if image is attached to the current post it adds class
  257. 'added'
  258. ---------------------------------------------------------- */
  259. if ( ! function_exists( 'siteAttachedImages' ) ) {
  260. /**
  261. * @param array $att_ids
  262. *
  263. * @since 4.2
  264. * @return string
  265. */
  266. function siteAttachedImages( $att_ids = array() ) {
  267. $output = '';
  268. global $wpdb;
  269. $media_images = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' order by ID desc" );
  270. foreach ( $media_images as $image_post ) {
  271. $thumb_src = wp_get_attachment_image_src( $image_post->ID, 'thumbnail' );
  272. $thumb_src = $thumb_src[0];
  273. $class = ( in_array( $image_post->ID, $att_ids ) ) ? ' class="added"' : '';
  274. $output .= '<li' . $class . '>
  275. <img rel="' . $image_post->ID . '" src="' . $thumb_src . '" />
  276. <span class="img-added">' . __( 'Added', "js_composer" ) . '</span>
  277. </li>';
  278. }
  279. if ( $output != '' ) {
  280. $output = '<ul class="gallery_widget_img_select">' . $output . '</ul>';
  281. }
  282. return $output;
  283. } // end siteAttachedImages()
  284. }
  285. /**
  286. * @param array $att_ids
  287. *
  288. * @since 4.2
  289. * @return string
  290. */
  291. function fieldAttachedImages( $att_ids = array() ) {
  292. $output = '';
  293. foreach ( $att_ids as $th_id ) {
  294. $thumb_src = wp_get_attachment_image_src( $th_id, 'thumbnail' );
  295. if ( $thumb_src ) {
  296. $thumb_src = $thumb_src[0];
  297. $output .= '
  298. <li class="added">
  299. <img rel="' . $th_id . '" src="' . $thumb_src . '" />
  300. <a href="#" class="icon-remove"></a>
  301. </li>';
  302. }
  303. }
  304. return $output;
  305. }
  306. /**
  307. * @param $param_value
  308. *
  309. * @since 4.2
  310. * @return array
  311. */
  312. function wpb_removeNotExistingImgIDs( $param_value ) {
  313. $tmp = explode( ",", $param_value );
  314. $return_ar = array();
  315. foreach ( $tmp as $id ) {
  316. if ( wp_get_attachment_image( $id ) ) {
  317. $return_ar[] = $id;
  318. }
  319. }
  320. $tmp = implode( ",", $return_ar );
  321. return $tmp;
  322. }
  323. /*
  324. * Resize images dynamically using wp built in functions
  325. * Victor Teixeira
  326. *
  327. * php 5.2+
  328. *
  329. * Exemplo de uso:
  330. *
  331. * <?php
  332. * $thumb = get_post_thumbnail_id();
  333. * $image = vt_resize( $thumb, '', 140, 110, true );
  334. * ?>
  335. * <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" />
  336. *
  337. */
  338. if ( ! function_exists( 'wpb_resize' ) ) {
  339. /**
  340. * @param int $attach_id
  341. * @param string $img_url
  342. * @param int $width
  343. * @param int $height
  344. * @param bool $crop
  345. *
  346. * @since 4.2
  347. * @return array
  348. */
  349. function wpb_resize( $attach_id = null, $img_url = null, $width, $height, $crop = false ) {
  350. // this is an attachment, so we have the ID
  351. $image_src = array();
  352. if ( $attach_id ) {
  353. $image_src = wp_get_attachment_image_src( $attach_id, 'full' );
  354. $actual_file_path = get_attached_file( $attach_id );
  355. // this is not an attachment, let's use the image url
  356. } else if ( $img_url ) {
  357. $file_path = parse_url( $img_url );
  358. $actual_file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
  359. $actual_file_path = ltrim( $file_path['path'], '/' );
  360. $actual_file_path = rtrim( ABSPATH, '/' ) . $file_path['path'];
  361. $orig_size = getimagesize( $actual_file_path );
  362. $image_src[0] = $img_url;
  363. $image_src[1] = $orig_size[0];
  364. $image_src[2] = $orig_size[1];
  365. }
  366. if(!empty($actual_file_path)) {
  367. $file_info = pathinfo( $actual_file_path );
  368. $extension = '.' . $file_info['extension'];
  369. // the image path without the extension
  370. $no_ext_path = $file_info['dirname'] . '/' . $file_info['filename'];
  371. $cropped_img_path = $no_ext_path . '-' . $width . 'x' . $height . $extension;
  372. // checking if the file size is larger than the target size
  373. // if it is smaller or the same size, stop right here and return
  374. if ( $image_src[1] > $width || $image_src[2] > $height ) {
  375. // 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)
  376. if ( file_exists( $cropped_img_path ) ) {
  377. $cropped_img_url = str_replace( basename( $image_src[0] ), basename( $cropped_img_path ), $image_src[0] );
  378. $vt_image = array(
  379. 'url' => $cropped_img_url,
  380. 'width' => $width,
  381. 'height' => $height
  382. );
  383. return $vt_image;
  384. }
  385. // $crop = false
  386. if ( $crop == false ) {
  387. // calculate the size proportionaly
  388. $proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height );
  389. $resized_img_path = $no_ext_path . '-' . $proportional_size[0] . 'x' . $proportional_size[1] . $extension;
  390. // checking if the file already exists
  391. if ( file_exists( $resized_img_path ) ) {
  392. $resized_img_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] );
  393. $vt_image = array(
  394. 'url' => $resized_img_url,
  395. 'width' => $proportional_size[0],
  396. 'height' => $proportional_size[1]
  397. );
  398. return $vt_image;
  399. }
  400. }
  401. // no cache files - let's finally resize it
  402. $img_editor = wp_get_image_editor( $actual_file_path );
  403. if ( is_wp_error( $img_editor ) || is_wp_error( $img_editor->resize( $width, $height, $crop ) ) ) {
  404. return array(
  405. 'url' => '',
  406. 'width' => '',
  407. 'height' => ''
  408. );
  409. }
  410. $new_img_path = $img_editor->generate_filename();
  411. if ( is_wp_error( $img_editor->save( $new_img_path ) ) ) {
  412. return array(
  413. 'url' => '',
  414. 'width' => '',
  415. 'height' => ''
  416. );
  417. }
  418. if ( ! is_string( $new_img_path ) ) {
  419. return array(
  420. 'url' => '',
  421. 'width' => '',
  422. 'height' => ''
  423. );
  424. }
  425. $new_img_size = getimagesize( $new_img_path );
  426. $new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
  427. // resized output
  428. $vt_image = array(
  429. 'url' => $new_img,
  430. 'width' => $new_img_size[0],
  431. 'height' => $new_img_size[1]
  432. );
  433. return $vt_image;
  434. }
  435. // default output - without resizing
  436. $vt_image = array(
  437. 'url' => $image_src[0],
  438. 'width' => $image_src[1],
  439. 'height' => $image_src[2]
  440. );
  441. return $vt_image;
  442. }
  443. return false;
  444. }
  445. }
  446. if ( ! function_exists( 'wpb_debug' ) ) {
  447. /**
  448. * Returns bool if wpb_debug is provided in url - set visual composer debug mode.
  449. * Used for example in shortcodes (end block comment for example)
  450. * @since 4.2
  451. * @return bool
  452. */
  453. function wpb_debug() {
  454. if ( isset( $_GET['wpb_debug'] ) && $_GET['wpb_debug'] == 'true' ) {
  455. return true;
  456. } else {
  457. return false;
  458. }
  459. }
  460. }
  461. /**
  462. * Method adds css class to body tag.
  463. *
  464. * Hooked class method by body_class WP filter. Method adds custom css class to body tag of the page to help
  465. * identify and build design specially for VC shortcodes.
  466. * Used in wp-content/plugins/js_composer/include/classes/core/class-vc-base.php\Vc_Base\bodyClass
  467. *
  468. * @param $classes
  469. *
  470. * @since 4.2
  471. * @return array
  472. */
  473. function js_composer_body_class( $classes ) {
  474. $classes[] = 'wpb-js-composer js-comp-ver-' . WPB_VC_VERSION;
  475. $disable_responsive = vc_settings()->get( 'not_responsive_css' );
  476. if ( $disable_responsive !== '1' ) {
  477. $classes[] = 'vc_responsive';
  478. } else {
  479. $classes[] = 'vc_non_responsive';
  480. }
  481. return $classes;
  482. }
  483. /**
  484. * @todo check for usage, \Vc_Base::jsForceSend
  485. *
  486. * @param $args
  487. *
  488. * @since 4.2
  489. * @return array
  490. */
  491. function wpb_js_force_send( $args ) {
  492. $args['send'] = true;
  493. return $args;
  494. }
  495. /**
  496. * @deprecated and will be removed
  497. * @since 4.2
  498. * @return int
  499. */
  500. function vc_get_interface_version() {
  501. return 2;
  502. }
  503. /**
  504. * @deprecated and will be removed.
  505. * @since 4.2
  506. * @return int
  507. */
  508. function vc_get_initerface_version() {
  509. return vc_get_interface_version();
  510. }
  511. /**
  512. * @param $m
  513. *
  514. * @since 4.2
  515. * @return string
  516. */
  517. function vc_convert_shortcode( $m ) {
  518. list( $output, $m_one, $tag, $attr_string, $m_four, $content ) = $m;
  519. $result = $width = $el_position = '';
  520. $shortcode_attr = shortcode_parse_atts( $attr_string );
  521. extract( shortcode_atts( array(
  522. 'width' => '1/1',
  523. 'el_class' => '',
  524. 'el_position' => ''
  525. ), $shortcode_attr ) );
  526. if ( $tag == 'vc_row' ) {
  527. return $output;
  528. }
  529. // Start
  530. if ( preg_match( '/first/', $el_position ) || empty( $shortcode_attr['width'] ) || $shortcode_attr['width'] === '1/1' ) {
  531. $result = '[vc_row]';
  532. }
  533. if ( $tag != 'vc_column' ) {
  534. $result .= "\n" . '[vc_column width="' . $width . '"]';
  535. }
  536. // Tag
  537. $pattern = get_shortcode_regex();
  538. if ( $tag == 'vc_column' ) {
  539. $result .= "[{$m_one}{$tag} {$attr_string}]" . preg_replace_callback( "/{$pattern}/s", 'vc_convert_inner_shortcode', $content ) . "[/{$tag}{$m_four}]";
  540. } elseif ( $tag == 'vc_tabs' || $tag == 'vc_accordion' || $tag == 'vc_tour' ) {
  541. $result .= "[{$m_one}{$tag} {$attr_string}]" . preg_replace_callback( "/{$pattern}/s", 'vc_convert_tab_inner_shortcode', $content ) . "[/{$tag}{$m_four}]";
  542. } else {
  543. $result .= preg_replace( '/(\"\d\/\d\")/', '"1/1"', $output );
  544. }
  545. // $content = preg_replace_callback( "/{$pattern}/s", 'vc_convert_inner_shortcode', $content );
  546. // End
  547. if ( $tag != 'vc_column' ) {
  548. $result .= '[/vc_column]';
  549. }
  550. if ( preg_match( '/last/', $el_position ) || empty( $shortcode_attr['width'] ) || $shortcode_attr['width'] === '1/1' ) {
  551. $result .= '[/vc_row]' . "\n";
  552. }
  553. return $result;
  554. }
  555. /**
  556. * @param $m
  557. *
  558. * @since 4.2
  559. * @return string
  560. */
  561. function vc_convert_tab_inner_shortcode( $m ) {
  562. list( $output, $m_one, $tag, $attr_string, $m_four, $content ) = $m;
  563. $result = $width = $el_position = '';
  564. extract( shortcode_atts( array(
  565. 'width' => '1/1',
  566. 'el_class' => '',
  567. 'el_position' => ''
  568. ), shortcode_parse_atts( $attr_string ) ) );
  569. $pattern = get_shortcode_regex();
  570. $result .= "[{$m_one}{$tag} {$attr_string}]" . preg_replace_callback( "/{$pattern}/s", 'vc_convert_inner_shortcode', $content ) . "[/{$tag}{$m_four}]";
  571. return $result;
  572. }
  573. /**
  574. * @param $m
  575. *
  576. * @since 4.2
  577. * @return string
  578. */
  579. function vc_convert_inner_shortcode( $m ) {
  580. list( $output, $m_one, $tag, $attr_string, $m_four, $content ) = $m;
  581. $result = $width = $el_position = '';
  582. extract( shortcode_atts( array(
  583. 'width' => '1/1',
  584. 'el_class' => '',
  585. 'el_position' => ''
  586. ), shortcode_parse_atts( $attr_string ) ) );
  587. if ( $width != '1/1' ) {
  588. if ( preg_match( '/first/', $el_position ) ) {
  589. $result .= '[vc_row_inner]';
  590. }
  591. $result .= "\n" . '[vc_column_inner width="' . $width . '" el_position="' . $el_position . '"]';
  592. $attr = '';
  593. foreach ( shortcode_parse_atts( $attr_string ) as $key => $value ) {
  594. if ( $key == 'width' ) {
  595. $value = '1/1';
  596. } elseif ( $key == 'el_position' ) {
  597. $value = 'first last';
  598. }
  599. $attr .= ' ' . $key . '="' . $value . '"';
  600. }
  601. $result .= "[{$m_one}{$tag} {$attr}]" . $content . "[/{$tag}{$m_four}]";
  602. $result .= '[/vc_column_inner]';
  603. if ( preg_match( '/last/', $el_position ) ) {
  604. $result .= '[/vc_row_inner]' . "\n";
  605. }
  606. } else {
  607. $result = $output;
  608. }
  609. return $result;
  610. }
  611. global $vc_row_layouts;
  612. $vc_row_layouts = array(
  613. /*
  614. * How to count mask?
  615. * mask = column_count . sum of all numbers. Example layout 12_12 mask = (column count=2)(1+2+1+2=6)= 26
  616. */
  617. array( 'cells' => '11', 'mask' => '12', 'title' => '1/1', 'icon_class' => 'l_11' ),
  618. array( 'cells' => '12_12', 'mask' => '26', 'title' => '1/2 + 1/2', 'icon_class' => 'l_12_12' ),
  619. array( 'cells' => '23_13', 'mask' => '29', 'title' => '2/3 + 1/3', 'icon_class' => 'l_23_13' ),
  620. array( 'cells' => '13_13_13', 'mask' => '312', 'title' => '1/3 + 1/3 + 1/3', 'icon_class' => 'l_13_13_13' ),
  621. array(
  622. 'cells' => '14_14_14_14',
  623. 'mask' => '420',
  624. 'title' => '1/4 + 1/4 + 1/4 + 1/4',
  625. 'icon_class' => 'l_14_14_14_14'
  626. ),
  627. array( 'cells' => '14_34', 'mask' => '212', 'title' => '1/4 + 3/4', 'icon_class' => 'l_14_34' ),
  628. array( 'cells' => '14_12_14', 'mask' => '313', 'title' => '1/4 + 1/2 + 1/4', 'icon_class' => 'l_14_12_14' ),
  629. array( 'cells' => '56_16', 'mask' => '218', 'title' => '5/6 + 1/6', 'icon_class' => 'l_56_16' ),
  630. array(
  631. 'cells' => '16_16_16_16_16_16',
  632. 'mask' => '642',
  633. 'title' => '1/6 + 1/6 + 1/6 + 1/6 + 1/6 + 1/6',
  634. 'icon_class' => 'l_16_16_16_16_16_16'
  635. ),
  636. array( 'cells' => '16_23_16', 'mask' => '319', 'title' => '1/6 + 4/6 + 1/6', 'icon_class' => 'l_16_46_16' ),
  637. array(
  638. 'cells' => '16_16_16_12',
  639. 'mask' => '424',
  640. 'title' => '1/6 + 1/6 + 1/6 + 1/2',
  641. 'icon_class' => 'l_16_16_16_12'
  642. )
  643. );
  644. /**
  645. * @param $width
  646. *
  647. * @since 4.2
  648. * @return string
  649. */
  650. function wpb_vc_get_column_width_indent( $width ) {
  651. $identy = '11';
  652. if ( $width == 'vc_col-sm-6' ) {
  653. $identy = '12';
  654. } elseif ( $width == 'vc_col-sm-3' ) {
  655. $identy = '14';
  656. } elseif ( $width == 'vc_col-sm-4' ) {
  657. $identy = '13';
  658. } elseif ( $width == 'vc_col-sm-8' ) {
  659. $identy = '23';
  660. } elseif ( $width == 'vc_col-sm-2' ) {
  661. $identy = '16';
  662. } elseif ( $width == 'vc_col-sm-9' ) {
  663. $identy = '34';
  664. } elseif ( $width == 'vc_col-sm-2' ) {
  665. $identy = '16';
  666. } elseif ( $width == 'vc_col-sm-10' ) {
  667. $identy = '56';
  668. }
  669. return $identy;
  670. }
  671. /**
  672. * @since 4.2
  673. * @return mixed|string|void
  674. */
  675. function get_row_css_class() {
  676. $custom = vc_settings()->get( 'row_css_class' );
  677. return ! empty( $custom ) ? $custom : 'vc_row-fluid';
  678. }
  679. /**
  680. * @param $class
  681. *
  682. * @since 4.2
  683. * @return string
  684. */
  685. function get_custom_column_class( $class ) {
  686. $custom_array = (array) vc_settings()->get( 'column_css_classes' );
  687. return ! empty( $custom_array[ $class ] ) ? $custom_array[ $class ] : '';
  688. }
  689. /* Make any HEX color lighter or darker
  690. ---------------------------------------------------------- */
  691. /**
  692. * @param $colour
  693. * @param $per
  694. *
  695. * @since 4.2
  696. * @return string
  697. */
  698. function vc_colorCreator( $colour, $per ) {
  699. $colour = substr( $colour, 1 ); // Removes first character of hex string (#)
  700. $rgb = ''; // Empty variable
  701. $per = $per / 100 * 255; // Creates a percentage to work with. Change the middle figure to control colour temperature
  702. if ( $per < 0 ) // Check to see if the percentage is a negative number
  703. {
  704. // DARKER
  705. $per = abs( $per ); // Turns Neg Number to Pos Number
  706. for ( $x = 0; $x < 3; $x ++ ) {
  707. $c = hexdec( substr( $colour, ( 2 * $x ), 2 ) ) - $per;
  708. $c = ( $c < 0 ) ? 0 : dechex( $c );
  709. $rgb .= ( strlen( $c ) < 2 ) ? '0' . $c : $c;
  710. }
  711. } else {
  712. // LIGHTER
  713. for ( $x = 0; $x < 3; $x ++ ) {
  714. $c = hexdec( substr( $colour, ( 2 * $x ), 2 ) ) + $per;
  715. $c = ( $c > 255 ) ? 'ff' : dechex( $c );
  716. $rgb .= ( strlen( $c ) < 2 ) ? '0' . $c : $c;
  717. }
  718. }
  719. return '#' . $rgb;
  720. }
  721. /* HEX to RGB converter
  722. ---------------------------------------------------------- */
  723. /**
  724. * @param $color
  725. *
  726. * @since 4.2
  727. * @return array|bool
  728. */
  729. function vc_hex2rgb( $color ) {
  730. if ( ! empty( $color ) && $color[0] == '#' ) {
  731. $color = substr( $color, 1 );
  732. }
  733. if ( strlen( $color ) == 6 ) {
  734. list( $r, $g, $b ) = array(
  735. $color[0] . $color[1],
  736. $color[2] . $color[3],
  737. $color[4] . $color[5]
  738. );
  739. } elseif ( strlen( $color ) == 3 ) {
  740. list( $r, $g, $b ) = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
  741. } else {
  742. return false;
  743. }
  744. $r = hexdec( $r );
  745. $g = hexdec( $g );
  746. $b = hexdec( $b );
  747. return array( $r, $g, $b );
  748. }
  749. /**
  750. * Parse string like "title:Hello world|weekday:Monday" to array('title' => 'Hello World', 'weekday' => 'Monday')
  751. *
  752. * @param $value
  753. * @param array $default
  754. *
  755. * @since 4.2
  756. * @return array
  757. */
  758. function vc_parse_multi_attribute( $value, $default = array() ) {
  759. $result = $default;
  760. $params_pairs = explode( '|', $value );
  761. foreach ( $params_pairs as $pair ) {
  762. $param = preg_split( '/\:/', $pair );
  763. if ( ! empty( $param[0] ) && isset( $param[1] ) ) {
  764. $result[ $param[0] ] = rawurldecode( $param[1] );
  765. }
  766. }
  767. return $result;
  768. }
  769. /**
  770. * @param $string
  771. *
  772. * @since 4.2
  773. * @return string
  774. */
  775. function wpb_stripslashes_if_gpc_magic_quotes( $string ) {
  776. if ( get_magic_quotes_gpc() ) {
  777. return stripslashes( $string );
  778. } else {
  779. return $string;
  780. }
  781. }
  782. /**
  783. * @param $v
  784. *
  785. * @since 4.2
  786. * @return string
  787. */
  788. function vc_param_options_parse_values( $v ) {
  789. return rawurldecode( $v );
  790. }
  791. /**
  792. * @param $name
  793. * @param $settings
  794. *
  795. * @since 4.2
  796. * @return bool
  797. */
  798. function vc_param_options_get_settings( $name, $settings ) {
  799. foreach ( $settings as $params ) {
  800. if ( isset( $params['name'] ) && $params['name'] === $name && isset( $params['type'] ) ) {
  801. return $params;
  802. }
  803. }
  804. return false;
  805. }
  806. /**
  807. * @param $atts
  808. *
  809. * @since 4.2
  810. * @return string
  811. */
  812. function vc_convert_atts_to_string( $atts ) {
  813. $output = '';
  814. foreach ( $atts as $key => $value ) {
  815. $output .= ' ' . $key . '="' . $value . '"';
  816. }
  817. return $output;
  818. }
  819. /**
  820. * @param $string
  821. * @param $tag
  822. * @param $param
  823. *
  824. * @since 4.2
  825. * @return array
  826. */
  827. function vc_parse_options_string( $string, $tag, $param ) {
  828. $options = $option_settings_list = array();
  829. $settings = WPBMap::getParam( $tag, $param );
  830. foreach ( preg_split( '/\|/', $string ) as $value ) {
  831. if ( preg_match( '/\:/', $value ) ) {
  832. $split = preg_split( '/\:/', $value );
  833. $option_name = $split[0];
  834. $option_settings = $option_settings_list[ $option_name ] = vc_param_options_get_settings( $option_name, $settings['options'] );
  835. if ( isset( $option_settings['type'] ) && $option_settings['type'] === 'checkbox' ) {
  836. $option_value = array_map( 'vc_param_options_parse_values', preg_split( '/\,/', $split[1] ) );
  837. } else {
  838. $option_value = rawurldecode( $split[1] );
  839. }
  840. $options[ $option_name ] = $option_value;
  841. }
  842. }
  843. if ( isset( $settings['options'] ) ) {
  844. foreach ( $settings['options'] as $setting_option ) {
  845. if ( $setting_option['type'] !== 'separator' && isset( $setting_option['value'] ) && empty( $options[ $setting_option['name'] ] ) ) {
  846. $options[ $setting_option['name'] ] = $setting_option['type'] === 'checkbox' ? preg_split( '/\,/', $setting_option['value'] ) : $setting_option['value'];
  847. }
  848. if ( isset( $setting_option['name'] ) && isset( $options[ $setting_option['name'] ] ) && isset( $setting_option['value_type'] ) ) {
  849. if ( $setting_option['value_type'] === 'integer' ) {
  850. $options[ $setting_option['name'] ] = (int) $options[ $setting_option['name'] ];
  851. } elseif ( $setting_option['value_type'] === 'float' ) {
  852. $options[ $setting_option['name'] ] = (float) $options[ $setting_option['name'] ];
  853. } elseif ( $setting_option['value_type'] === 'boolean' ) {
  854. $options[ $setting_option['name'] ] = (boolean) $options[ $setting_option['name'] ];
  855. }
  856. }
  857. }
  858. }
  859. return $options;
  860. }
  861. /**
  862. * @since 4.2
  863. */
  864. function wpb_js_composer_check_version_schedule_deactivation() {
  865. wp_clear_scheduled_hook( 'wpb_check_for_update' );
  866. delete_option( 'wpb_js_composer_show_new_version_message' );
  867. }
  868. /**
  869. * Helper function to add new third-party adaptation class.
  870. *
  871. * @since 4.3
  872. *
  873. * @param Vc_Vendor_Interface $vendor - instance of class.
  874. */
  875. function vc_add_vendor( Vc_Vendor_Interface $vendor ) {
  876. visual_composer()->vendorsManager()->add( $vendor );
  877. }
  878. /**
  879. * Convert string to a valid css class name.
  880. *
  881. * @since 4.3
  882. *
  883. * @param string $class
  884. *
  885. * @return string
  886. */
  887. function vc_build_safe_css_class( $class ) {
  888. return preg_replace( '/\W+/', '', strtolower( str_replace( " ", "_", strip_tags( $class ) ) ) );
  889. }
  890. /**
  891. * Include template from templates dir.
  892. *
  893. * @since 4.3
  894. *
  895. * @param $template
  896. * @param array $variables - passed variables to the template.
  897. *
  898. * @param bool $once
  899. *
  900. * @return mixed
  901. */
  902. function vc_include_template( $template, $variables = array(), $once = false ) {
  903. is_array( $variables ) && extract( $variables );
  904. if ( $once ) {
  905. return require_once vc_template( $template );
  906. } else {
  907. return require vc_template( $template );
  908. }
  909. }
  910. /**
  911. * Output template from templates dir.
  912. *
  913. * @since 4.4
  914. *
  915. * @param $template
  916. * @param array $variables - passed variables to the template.
  917. *
  918. * @param bool $once
  919. *
  920. * @return string
  921. */
  922. function vc_get_template( $template, $variables = array(), $once = false ) {
  923. ob_start();
  924. vc_include_template( $template, $variables, $once );
  925. return ob_get_clean();
  926. }
  927. /**
  928. * if php version < 5.3 this function is required.
  929. */
  930. if ( function_exists( 'lcfirst' ) === false ) {
  931. /**
  932. * @param $str
  933. *
  934. * @since 4.3, fix #1093
  935. * @return mixed
  936. */
  937. function lcfirst( $str ) {
  938. $str[0] = mb_strtolower( $str[0] );
  939. return $str;
  940. }
  941. }
  942. /**
  943. * VC Convert a value to studly caps case.
  944. *
  945. * @since 4.3
  946. *
  947. * @param string $value
  948. *
  949. * @return string
  950. */
  951. function vc_studly( $value ) {
  952. $value = ucwords( str_replace( array( '-', '_' ), ' ', $value ) );
  953. return str_replace( ' ', '', $value );
  954. }
  955. /**
  956. * VC Convert a value to camel case.
  957. *
  958. * @since 4.3
  959. *
  960. * @param string $value
  961. *
  962. * @return string
  963. */
  964. function vc_camel_case( $value ) {
  965. return lcfirst( vc_studly( $value ) );
  966. }
  967. /**
  968. * Enqueue icon element font
  969. * @todo move to separate folder
  970. * @since 4.4
  971. *
  972. * @param $font
  973. */
  974. function vc_icon_element_fonts_enqueue( $font ) {
  975. switch ( $font ) {
  976. case 'fontawesome':
  977. wp_enqueue_style( 'font-awesome' );
  978. break;
  979. case 'openiconic':
  980. wp_enqueue_style( 'vc_openiconic' );
  981. break;
  982. case 'typicons':
  983. wp_enqueue_style( 'vc_typicons' );
  984. break;
  985. case 'entypo':
  986. wp_enqueue_style( 'vc_entypo' );
  987. break;
  988. case 'linecons':
  989. wp_enqueue_style( 'vc_linecons' );
  990. break;
  991. default:
  992. do_action( 'vc_enqueue_font_icon_element', $font ); // hook to custom do enqueue style
  993. }
  994. }
  995. /**
  996. * Function merges defaults attributes in attributes by keeping it values
  997. *
  998. * Example
  999. * array defaults | array attributes | result array
  1000. * 'color'=>'black', - 'color'=>'black',
  1001. * 'target'=>'_self', 'target'=>'_blank', 'target'=>'_blank',
  1002. * - 'link'=>'google.com' 'link'=>'google.com'
  1003. *
  1004. * @since 4.4
  1005. *
  1006. * @param array $defaults
  1007. * @param array $attributes
  1008. *
  1009. * @return array - merged attributes
  1010. */
  1011. function vc_shortcode_attribute_parse( $defaults = array(), $attributes = array() ) {
  1012. $atts = $attributes + shortcode_atts( $defaults, $attributes );
  1013. return $atts;
  1014. }
  1015. function vc_get_shortcode_regex($tagregexp = '') {
  1016. if( 0 === strlen($tagregexp) ) {
  1017. return get_shortcode_regex();
  1018. }
  1019. return
  1020. '\\[' // Opening bracket
  1021. . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
  1022. . "($tagregexp)" // 2: Shortcode name
  1023. . '(?![\\w-])' // Not followed by word character or hyphen
  1024. . '(' // 3: Unroll the loop: Inside the opening shortcode tag
  1025. . '[^\\]\\/]*' // Not a closing bracket or forward slash
  1026. . '(?:'
  1027. . '\\/(?!\\])' // A forward slash not followed by a closing bracket
  1028. . '[^\\]\\/]*' // Not a closing bracket or forward slash
  1029. . ')*?'
  1030. . ')'
  1031. . '(?:'
  1032. . '(\\/)' // 4: Self closing tag ...
  1033. . '\\]' // ... and closing bracket
  1034. . '|'
  1035. . '\\]' // Closing bracket
  1036. . '(?:'
  1037. . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
  1038. . '[^\\[]*+' // Not an opening bracket
  1039. . '(?:'
  1040. . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
  1041. . '[^\\[]*+' // Not an opening bracket
  1042. . ')*+'
  1043. . ')'
  1044. . '\\[\\/\\2\\]' // Closing shortcode tag
  1045. . ')?'
  1046. . ')'
  1047. . '(\\]?)';
  1048. }