PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Site/wp-content/plugins/js_composer/include/params/default_params.php

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