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

https://gitlab.com/juanito.abelo/nlmobile · PHP · 389 lines · 179 code · 16 blank · 194 comment · 37 complexity · 296af1052d60c4c022fc5712c34a10ad MD5 · raw file

  1. <?php
  2. /**
  3. * WPBakery Visual Composer Main manager.
  4. *
  5. * @package WPBakeryVisualComposer
  6. * @since 4.2
  7. */
  8. if ( ! function_exists( 'vc_manager' ) ) {
  9. /**
  10. * Visual Composer manager.
  11. * @since 4.2
  12. * @return Vc_Manager
  13. */
  14. function vc_manager() {
  15. global $vc_manager;
  16. return $vc_manager;
  17. }
  18. }
  19. if ( ! function_exists( 'visual_composer' ) ) {
  20. /**
  21. * Visual Composer instance.
  22. * @since 4.2
  23. * @return Vc_Base
  24. */
  25. function visual_composer() {
  26. return vc_manager()->vc();
  27. }
  28. }
  29. if ( ! function_exists( 'vc_mapper' ) ) {
  30. /**
  31. * Shorthand for Vc Mapper.
  32. * @since 4.2
  33. * @return Vc_Mapper
  34. */
  35. function vc_mapper() {
  36. return vc_manager()->mapper();
  37. }
  38. }
  39. if ( ! function_exists( 'vc_settings' ) ) {
  40. /**
  41. * Shorthand for Visual composer settings.
  42. * @since 4.2
  43. * @return Vc_Settings
  44. */
  45. function vc_settings() {
  46. return vc_manager()->settings();
  47. }
  48. }
  49. if ( ! function_exists( 'vc_license' ) ) {
  50. /**
  51. * Get License manager
  52. * @since 4.2
  53. * @return Vc_License
  54. */
  55. function vc_license() {
  56. return vc_manager()->license();
  57. }
  58. }
  59. if ( ! function_exists( 'vc_automapper' ) ) {
  60. /**
  61. * @since 4.2
  62. * @return Vc_Automapper
  63. */
  64. function vc_automapper() {
  65. return vc_manager()->automapper();
  66. }
  67. }
  68. if ( ! function_exists( 'vc_frontend_editor' ) ) {
  69. /**
  70. * Shorthand for VC frontend editor
  71. * @since 4.2
  72. * @return Vc_Frontend_Editor
  73. */
  74. function vc_frontend_editor() {
  75. return vc_manager()->frontendEditor();
  76. }
  77. }
  78. if ( ! function_exists( 'vc_backend_editor' ) ) {
  79. /**
  80. * Shorthand for VC frontend editor
  81. * @since 4.2
  82. * @return Vc_Backend_Editor
  83. */
  84. function vc_backend_editor() {
  85. return vc_manager()->backendEditor();
  86. }
  87. }
  88. if ( ! function_exists( 'vc_updater' ) ) {
  89. /**
  90. * @since 4.2
  91. * @return Vc_Updater
  92. */
  93. function vc_updater() {
  94. return vc_manager()->updater();
  95. }
  96. }
  97. if ( ! function_exists( 'vc_is_network_plugin' ) ) {
  98. /**
  99. * Vc is network plugin or not.
  100. * @since 4.2
  101. * @return bool
  102. */
  103. function vc_is_network_plugin() {
  104. return vc_manager()->isNetworkPlugin();
  105. }
  106. }
  107. if ( ! function_exists( 'vc_path_dir' ) ) {
  108. /**
  109. * Get file/directory path in Vc.
  110. *
  111. * @param string $name - path name
  112. * @param string $file
  113. *
  114. * @since 4.2
  115. * @return string
  116. */
  117. function vc_path_dir( $name, $file = '' ) {
  118. return vc_manager()->path( $name, $file );
  119. }
  120. }
  121. if ( ! function_exists( 'vc_asset_url' ) ) {
  122. /**
  123. * Get full url for assets.
  124. *
  125. * @param string $file
  126. *
  127. * @since 4.2
  128. * @return string
  129. */
  130. function vc_asset_url( $file ) {
  131. return vc_manager()->assetUrl( $file );
  132. }
  133. }
  134. if ( ! function_exists( 'vc_upload_dir' ) ) {
  135. /**
  136. * Temporary files upload dir;
  137. * @since 4.2
  138. * @return string
  139. */
  140. function vc_upload_dir() {
  141. return vc_manager()->uploadDir();
  142. }
  143. }
  144. if ( ! function_exists( 'vc_template' ) ) {
  145. /**
  146. * @param $file
  147. *
  148. * @since 4.2
  149. * @return string
  150. */
  151. function vc_template( $file ) {
  152. return vc_path_dir( 'TEMPLATES_DIR', $file );
  153. }
  154. }
  155. if ( ! function_exists( 'vc_post_param' ) ) {
  156. /**
  157. * Get param value from $_POST if exists.
  158. *
  159. * @param $param
  160. * @param $default
  161. *
  162. * @since 4.2
  163. * @return null|string - null for undefined param.
  164. */
  165. function vc_post_param( $param, $default = null ) {
  166. return isset( $_POST[ $param ] ) ? $_POST[ $param ] : $default;
  167. }
  168. }
  169. if ( ! function_exists( 'vc_get_param' ) ) {
  170. /**
  171. * Get param value from $_GET if exists.
  172. *
  173. * @param $param
  174. * @param $default
  175. *
  176. * @since 4.2
  177. * @return null|string - null for undefined param.
  178. */
  179. function vc_get_param( $param, $default = null ) {
  180. return isset( $_GET[ $param ] ) ? $_GET[ $param ] : $default;
  181. }
  182. }
  183. if ( ! function_exists( 'vc_request_param' ) ) {
  184. /**
  185. * Get param value from $_REQUEST if exists.
  186. *
  187. * @param $param
  188. * @param $default
  189. *
  190. * @since 4.4
  191. * @return null|string - null for undefined param.
  192. */
  193. function vc_request_param( $param, $default = null ) {
  194. return isset( $_REQUEST[ $param ] ) ? $_REQUEST[ $param ] : $default;
  195. }
  196. }
  197. if ( ! function_exists( 'vc_is_frontend_editor' ) ) {
  198. /**
  199. * @since 4.2
  200. * @return bool
  201. */
  202. function vc_is_frontend_editor() {
  203. return vc_mode() === 'admin_frontend_editor';
  204. }
  205. }
  206. if ( ! function_exists( 'vc_is_page_editable' ) ) {
  207. /**
  208. * @since 4.2
  209. * @return bool
  210. */
  211. function vc_is_page_editable() {
  212. return vc_mode() == 'page_editable';
  213. }
  214. }
  215. if ( ! function_exists( 'vc_action' ) ) {
  216. /**
  217. * Get VC special action param.
  218. * @since 4.2
  219. * @return string|null
  220. */
  221. function vc_action() {
  222. $vc_action = null;
  223. if ( isset( $_GET['vc_action'] ) ) {
  224. $vc_action = $_GET['vc_action'];
  225. } elseif ( isset( $_POST['vc_action'] ) ) {
  226. $vc_action = $_POST['vc_action'];
  227. }
  228. return $vc_action;
  229. }
  230. }
  231. if ( ! function_exists( 'vc_is_inline' ) ) {
  232. /**
  233. * Get is inline or not.
  234. * @since 4.2
  235. * @return bool
  236. */
  237. function vc_is_inline() {
  238. global $vc_is_inline;
  239. if ( is_null( $vc_is_inline ) ) {
  240. $vc_is_inline = vc_action() === 'vc_inline' || !is_null(vc_request_param('vc_inline')) || vc_request_param('vc_editable') === 'true';
  241. }
  242. return $vc_is_inline;
  243. }
  244. }
  245. if ( ! function_exists( 'vc_is_frontend_ajax' ) ) {
  246. /**
  247. * @since 4.2
  248. * @return bool
  249. */
  250. function vc_is_frontend_ajax() {
  251. return vc_post_param( 'vc_inline' ) == 'true' || vc_get_param( 'vc_inline' );
  252. }
  253. }
  254. /**
  255. * @since 4.2
  256. * @return bool
  257. */
  258. function vc_is_editor() {
  259. return vc_is_frontend_editor();
  260. }
  261. /**
  262. * @param $value
  263. * @param bool $encode
  264. *
  265. * @since 4.2
  266. * @return string
  267. */
  268. function vc_value_from_safe( $value, $encode = false ) {
  269. $value = preg_match( '/^#E\-8_/', $value ) ? rawurldecode( base64_decode( preg_replace( '/^#E\-8_/', '', $value ) ) ) : $value;
  270. if ( $encode ) {
  271. $value = htmlentities( $value, ENT_COMPAT, 'UTF-8' );
  272. }
  273. return $value;
  274. }
  275. /**
  276. * @since 4.2
  277. *
  278. * @param bool $disable
  279. */
  280. function vc_disable_automapper( $disable = true ) {
  281. vc_automapper()->setDisabled( $disable );
  282. }
  283. /**
  284. * @since 4.2
  285. * @return bool
  286. */
  287. function vc_automapper_is_disabled() {
  288. return vc_automapper()->disabled();
  289. }
  290. /**
  291. * @param $param
  292. * @param $value
  293. *
  294. * @since 4.2
  295. * @return mixed|string
  296. */
  297. function vc_get_dropdown_option( $param, $value ) {
  298. if ( $value === '' && is_array( $param['value'] ) ) {
  299. $value = array_shift( $param['value'] );
  300. }
  301. if ( is_array( $value ) ) {
  302. reset( $value );
  303. $value = isset( $value['value'] ) ? $value['value'] :
  304. current( $value );
  305. }
  306. $value = preg_replace( '/\s/', '_', $value );
  307. return ( $value !== '' ? $value : '' );
  308. }
  309. /**
  310. * @param $prefix
  311. * @param $color
  312. *
  313. * @since 4.2
  314. * @return string
  315. */
  316. function vc_get_css_color( $prefix, $color ) {
  317. $rgb_color = preg_match( '/rgba/', $color ) ? preg_replace( array(
  318. '/\s+/',
  319. '/^rgba\((\d+)\,(\d+)\,(\d+)\,([\d\.]+)\)$/'
  320. ), array( '', 'rgb($1,$2,$3)' ), $color ) : $color;
  321. $string = $prefix . ':' . $rgb_color . ';';
  322. if ( $rgb_color !== $color ) {
  323. $string .= $prefix . ':' . $color . ';';
  324. }
  325. return $string;
  326. }
  327. /**
  328. * @param $param_value
  329. * @param string $prefix
  330. *
  331. * @since 4.2
  332. * @return string
  333. */
  334. function vc_shortcode_custom_css_class( $param_value, $prefix = '' ) {
  335. $css_class = preg_match( '/\s*\.([^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', $param_value ) ? $prefix . preg_replace( '/\s*\.([^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', '$1', $param_value ) : '';
  336. return $css_class;
  337. }
  338. /**
  339. * Plugin name for VC.
  340. *
  341. * @since 4.2
  342. * @return string
  343. */
  344. function vc_plugin_name() {
  345. return vc_manager()->pluginName();
  346. }
  347. /**
  348. * @since 4.4.3 used in vc_base when getting an custom css output
  349. * @param $filename
  350. *
  351. * @return bool|mixed|string
  352. */
  353. function vc_file_get_contents( $filename ) {
  354. global $wp_filesystem;
  355. if ( empty( $wp_filesystem ) ) {
  356. require_once( ABSPATH . '/wp-admin/includes/file.php' );
  357. WP_Filesystem();
  358. }
  359. /** @var $wp_filesystem WP_Filesystem_Base */
  360. if ( ! is_object( $wp_filesystem ) || ! $output = $wp_filesystem->get_contents( $filename ) ) {
  361. /*if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
  362. } elseif ( ! $wp_filesystem->connect() ) {
  363. } elseif ( ! $wp_filesystem->is_writable( $filename ) ) {
  364. } else {
  365. }*/
  366. $output = file_get_contents( $filename );
  367. }
  368. return $output;
  369. }