default_params.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * WPBakery WPBakery Page Builder shortcode default attributes functions for rendering.
  7. *
  8. * @package WPBakeryPageBuilder
  9. * @since 4.4
  10. */
  11. /**
  12. * Textfield shortcode attribute type generator.
  13. *
  14. * @param $settings
  15. * @param $value
  16. *
  17. * @return string - html string.
  18. * @since 4.4
  19. */
  20. function vc_textfield_form_field( $settings, $value ) {
  21. $value = htmlspecialchars( $value );
  22. return '<input name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-textinput ' . $settings['param_name'] . ' ' . $settings['type'] . '" type="text" value="' . $value . '"/>';
  23. }
  24. /**
  25. * Dropdown(select with options) shortcode attribute type generator.
  26. *
  27. * @param $settings
  28. * @param $value
  29. *
  30. * @return string - html string.
  31. * @since 4.4
  32. */
  33. function vc_dropdown_form_field( $settings, $value ) {
  34. $output = '';
  35. $css_option = str_replace( '#', 'hash-', vc_get_dropdown_option( $settings, $value ) );
  36. $output .= '<select name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-input wpb-select ' . $settings['param_name'] . ' ' . $settings['type'] . ' ' . $css_option . '" data-option="' . $css_option . '">';
  37. if ( is_array( $value ) ) {
  38. $value = isset( $value['value'] ) ? $value['value'] : array_shift( $value );
  39. }
  40. if ( ! empty( $settings['value'] ) ) {
  41. foreach ( $settings['value'] as $index => $data ) {
  42. if ( is_numeric( $index ) && ( is_string( $data ) || is_numeric( $data ) ) ) {
  43. $option_label = $data;
  44. $option_value = $data;
  45. } elseif ( is_numeric( $index ) && is_array( $data ) ) {
  46. $option_label = isset( $data['label'] ) ? $data['label'] : array_pop( $data );
  47. $option_value = isset( $data['value'] ) ? $data['value'] : array_pop( $data );
  48. } else {
  49. $option_value = $data;
  50. $option_label = $index;
  51. }
  52. $selected = '';
  53. $option_value_string = (string) $option_value;
  54. $value_string = (string) $value;
  55. if ( '' !== $value && $option_value_string === $value_string ) {
  56. $selected = 'selected="selected"';
  57. }
  58. $option_class = str_replace( '#', 'hash-', $option_value );
  59. $output .= '<option class="' . esc_attr( $option_class ) . '" value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . htmlspecialchars( $option_label ) . '</option>';
  60. }
  61. }
  62. $output .= '</select>';
  63. return $output;
  64. }
  65. /**
  66. * Checkbox shortcode attribute type generator.
  67. *
  68. * @param $settings
  69. * @param string $value
  70. *
  71. * @return string - html string.
  72. * @since 4.4
  73. */
  74. function vc_checkbox_form_field( $settings, $value ) {
  75. $output = '';
  76. if ( is_array( $value ) ) {
  77. $value = ''; // fix #1239
  78. }
  79. $current_value = strlen( $value ) > 0 ? explode( ',', $value ) : array();
  80. $values = isset( $settings['value'] ) && is_array( $settings['value'] ) ? $settings['value'] : array( esc_html__( 'Yes', 'js_composer' ) => 'true' );
  81. if ( ! empty( $values ) ) {
  82. foreach ( $values as $label => $v ) {
  83. // NOTE!! Don't use strict compare here for BC!
  84. // @codingStandardsIgnoreLine
  85. $checked = in_array( $v, $current_value ) ? 'checked' : '';
  86. $output .= ' <label class="vc_checkbox-label"><input id="' . $settings['param_name'] . '-' . $v . '" value="' . $v . '" class="wpb_vc_param_value ' . $settings['param_name'] . ' ' . $settings['type'] . '" type="checkbox" name="' . $settings['param_name'] . '" ' . $checked . '>' . $label . '</label>';
  87. }
  88. }
  89. return $output;
  90. }
  91. add_filter( 'vc_map_get_param_defaults', 'vc_checkbox_param_defaults', 10, 2 );
  92. /**
  93. * @param $value
  94. * @param $param
  95. * @return mixed|string
  96. */
  97. function vc_checkbox_param_defaults( $value, $param ) {
  98. if ( 'checkbox' === $param['type'] ) {
  99. $value = '';
  100. if ( isset( $param['std'] ) ) {
  101. $value = $param['std'];
  102. }
  103. }
  104. return $value;
  105. }
  106. /**
  107. * Checkbox shortcode attribute type generator.
  108. *
  109. * @param $settings
  110. * @param $value
  111. *
  112. * @return string - html string.
  113. * @since 4.4
  114. */
  115. function vc_posttypes_form_field( $settings, $value ) {
  116. $output = '';
  117. $args = array(
  118. 'public' => true,
  119. );
  120. $post_types = get_post_types( $args );
  121. foreach ( $post_types as $post_type ) {
  122. $checked = '';
  123. if ( 'attachment' !== $post_type ) {
  124. if ( in_array( $post_type, explode( ',', $value ), true ) ) {
  125. $checked = 'checked="checked"';
  126. }
  127. $output .= '<label class="vc_checkbox-label"><input id="' . $settings['param_name'] . '-' . $post_type . '" value="' . $post_type . '" class="wpb_vc_param_value ' . $settings['param_name'] . ' ' . $settings['type'] . '" type="checkbox" name="' . $settings['param_name'] . '" ' . $checked . '> ' . $post_type . '</label>';
  128. }
  129. }
  130. return $output;
  131. }
  132. /**
  133. * Taxonomies shortcode attribute type generator.
  134. *
  135. * @param $settings
  136. * @param $value
  137. *
  138. * @return string - html string.
  139. * @since 4.4
  140. */
  141. function vc_taxonomies_form_field( $settings, $value ) {
  142. $output = '';
  143. $post_types = get_post_types( array(
  144. 'public' => false,
  145. 'name' => 'attachment',
  146. ), 'names', 'NOT' );
  147. foreach ( $post_types as $type ) {
  148. $taxonomies = get_object_taxonomies( $type, '' );
  149. foreach ( $taxonomies as $tax ) {
  150. $checked = '';
  151. if ( in_array( $tax->name, explode( ',', $value ), true ) ) {
  152. $checked = 'checked';
  153. }
  154. $output .= ' <label class="vc_checkbox-label" data-post-type="' . $type . '"><input id="' . $settings['param_name'] . '-' . $tax->name . '" value="' . $tax->name . '" data-post-type="' . $type . '" class="wpb_vc_param_value ' . $settings['param_name'] . ' ' . $settings['type'] . '" type="checkbox" name="' . $settings['param_name'] . '" ' . $checked . '> ' . $tax->label . '</label>';
  155. }
  156. }
  157. return $output;
  158. }
  159. /**
  160. * Exploded textarea shortcode attribute type generator.
  161. *
  162. * Data saved and coma-separated values are merged with line breaks and returned in a textarea.
  163. *
  164. * @param $settings
  165. * @param $value
  166. *
  167. * @return string - html string.
  168. * @since 4.4
  169. */
  170. function vc_exploded_textarea_form_field( $settings, $value ) {
  171. $value = str_replace( ',', "\n", $value );
  172. return '<textarea name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-textarea ' . $settings['param_name'] . ' ' . $settings['type'] . '">' . $value . '</textarea>';
  173. }
  174. /**
  175. * Safe Textarea shortcode attribute type generator.
  176. *
  177. * @param $settings
  178. * @param $value
  179. *
  180. * @return string - html string.
  181. * @since 4.8.2
  182. */
  183. function vc_exploded_textarea_safe_form_field( $settings, $value ) {
  184. $value = vc_value_from_safe( $value, true );
  185. $value = str_replace( ',', "\n", $value );
  186. return '<textarea name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-textarea ' . $settings['param_name'] . ' ' . $settings['type'] . '">' . $value . '</textarea>';
  187. }
  188. /**
  189. * Textarea raw html shortcode attribute type generator.
  190. *
  191. * This attribute type allows safely add custom html to your post/page.
  192. *
  193. * @param $settings
  194. * @param $value
  195. *
  196. * @return string - html string.
  197. * @since 4.4
  198. */
  199. function vc_textarea_raw_html_form_field( $settings, $value ) {
  200. // @codingStandardsIgnoreLine
  201. return sprintf( '<textarea name="%s" class="wpb_vc_param_value wpb-textarea_raw_html %s %s" rows="16">%s</textarea>', $settings['param_name'], $settings['param_name'], $settings['type'], htmlentities( rawurldecode( base64_decode( $value ) ), ENT_COMPAT, 'UTF-8' ) );
  202. }
  203. /**
  204. * Safe Textarea shortcode attribute type generator.
  205. *
  206. * @param $settings
  207. * @param $value
  208. *
  209. * @return string - html string.
  210. * @since 4.4
  211. */
  212. function vc_textarea_safe_form_field( $settings, $value ) {
  213. return '<textarea name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-textarea_raw_html ' . $settings['param_name'] . ' ' . $settings['type'] . '">' . vc_value_from_safe( $value, true ) . '</textarea>';
  214. }
  215. /**
  216. * Textarea shortcode attribute type generator.
  217. *
  218. * @param $settings
  219. * @param $value
  220. *
  221. * @return string - html string.
  222. * @since 4.4
  223. */
  224. function vc_textarea_form_field( $settings, $value ) {
  225. return '<textarea name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-textarea ' . $settings['param_name'] . ' ' . $settings['type'] . '">' . $value . '</textarea>';
  226. }
  227. /**
  228. * Attach images shortcode attribute type generator.
  229. *
  230. * @param $settings
  231. * @param $value
  232. *
  233. * @param $tag
  234. * @param bool $single
  235. *
  236. * @return string - html string.
  237. * @since 4.4
  238. *
  239. */
  240. function vc_attach_images_form_field( $settings, $value, $tag, $single = false ) {
  241. $output = '';
  242. $param_value = wpb_removeNotExistingImgIDs( $value );
  243. $output .= '<input type="hidden" class="wpb_vc_param_value gallery_widget_attached_images_ids ' . esc_attr( $settings['param_name'] ) . ' ' . esc_attr( $settings['type'] ) . '" name="' . esc_attr( $settings['param_name'] ) . '" value="' . $value . '"/>';
  244. $output .= '<div class="gallery_widget_attached_images">';
  245. $output .= '<ul class="gallery_widget_attached_images_list">';
  246. $output .= ( '' !== $param_value ) ? vc_field_attached_images( explode( ',', $value ) ) : '';
  247. $output .= '</ul>';
  248. $output .= '</div>';
  249. $output .= '<div class="gallery_widget_site_images">';
  250. $output .= '</div>';
  251. if ( true === $single ) {
  252. $output .= '<a class="gallery_widget_add_images" href="javascript:;" use-single="true" title="' . esc_attr__( 'Add image', 'js_composer' ) . '"><i class="vc-composer-icon vc-c-icon-add"></i>' . esc_html__( 'Add image', 'js_composer' ) . '</a>';
  253. } else {
  254. $output .= '<a class="gallery_widget_add_images" href="javascript:;" title="' . esc_attr__( 'Add images', 'js_composer' ) . '"><i class="vc-composer-icon vc-c-icon-add"></i>' . esc_html__( 'Add images', 'js_composer' ) . '</a>';
  255. }
  256. return $output;
  257. }
  258. /**
  259. * Attach image shortcode attribute type generator.
  260. *
  261. * @param $settings
  262. * @param $value
  263. *
  264. * @param $tag
  265. *
  266. * @return string - html string.
  267. * @since 4.4
  268. */
  269. function vc_attach_image_form_field( $settings, $value, $tag ) {
  270. return vc_attach_images_form_field( $settings, $value, $tag, true );
  271. }
  272. /**
  273. * Widgetised sidebars shortcode attribute type generator.
  274. *
  275. * @param $settings
  276. * @param $value
  277. *
  278. * @return string - html string.
  279. * @since 4.4
  280. */
  281. function vc_widgetised_sidebars_form_field( $settings, $value ) {
  282. $output = '';
  283. $sidebars = $GLOBALS['wp_registered_sidebars'];
  284. $output .= '<select name="' . esc_attr( $settings['param_name'] ) . '" class="wpb_vc_param_value dropdown wpb-input wpb-select ' . $settings['param_name'] . ' ' . $settings['type'] . '">';
  285. foreach ( $sidebars as $sidebar ) {
  286. $selected = '';
  287. if ( $sidebar['id'] === $value ) {
  288. $selected = 'selected';
  289. }
  290. $sidebar_name = $sidebar['name'];
  291. $output .= '<option value="' . esc_attr( $sidebar['id'] ) . '" ' . $selected . '>' . $sidebar_name . '</option>';
  292. }
  293. $output .= '</select>';
  294. return $output;
  295. }