PageRenderTime 27ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/js_composer/include/classes/core/class-vc-base.php

https://gitlab.com/juanito.abelo/nlmobile
PHP | 873 lines | 414 code | 61 blank | 398 comment | 41 complexity | 629feb44cf1380d84bd9d8b5a591a1da MD5 | raw file
  1. <?php
  2. /**
  3. * WPBakery Visual Composer main class.
  4. *
  5. * @package WPBakeryVisualComposer
  6. * @since 4.2
  7. */
  8. /**
  9. * Visual Composer basic class.
  10. * @since 4.2
  11. */
  12. class Vc_Base {
  13. /**
  14. * Shortcode's edit form.
  15. *
  16. * @since 4.2
  17. * @access protected
  18. * @var bool|Vc_Shortcode_Edit_Form
  19. */
  20. protected $shortcode_edit_form = false;
  21. /**
  22. * Templates management panel.
  23. * @deprecated since 4.4 updated to $templates_panel_editor, use Vc_Base::setTemplatesPanelEditor
  24. * @since 4.2
  25. * @access protected
  26. * @var bool|Vc_Templates_Editor
  27. */
  28. protected $templates_editor = false;
  29. /**
  30. * Templates management panel editor.
  31. * @since 4.4
  32. * @access protected
  33. * @var bool|Vc_Templates_Panel_Editor
  34. */
  35. protected $templates_panel_editor = false;
  36. /**
  37. * Post object for VC in Admin.
  38. *
  39. * @since 4.4
  40. * @access protected
  41. * @var bool|Vc_Post_Admin
  42. */
  43. protected $post_admin = false;
  44. /**
  45. * Post object for VC.
  46. *
  47. * @since 4.4.3
  48. * @access protected
  49. * @var bool|Vc_Post_Admin
  50. */
  51. protected $post = false;
  52. /**
  53. * List of shortcodes map to VC.
  54. *
  55. * @since 4.2
  56. * @access public
  57. * @var array WPBakeryShortCodeFishBones
  58. */
  59. protected $shortcodes = array();
  60. /**
  61. * @deprecated since 4.4 due to autoload logic
  62. * @var Vc_Vendors_Manager $vendor_manager
  63. */
  64. protected $vendor_manager;
  65. /**
  66. * Load default object like shortcode parsing.
  67. *
  68. * @since 4.2
  69. * @access public
  70. */
  71. public function init() {
  72. do_action( 'vc_before_init_base' );
  73. if(is_admin()) {
  74. $this->postAdmin()->init();
  75. }
  76. add_filter( 'body_class', array( &$this, 'bodyClass' ) );
  77. add_filter( 'the_excerpt', array( &$this, 'excerptFilter' ) );
  78. add_action( 'wp_head', array( &$this, 'addMetaData' ) );
  79. if ( is_admin() ) {
  80. $this->initAdmin();
  81. } else {
  82. $this->initPage();
  83. }
  84. do_action( 'vc_after_init_base' );
  85. }
  86. /**
  87. * Post object for interacting with Current post data.
  88. * @since 4.4
  89. * @return Vc_Post_Admin
  90. */
  91. public function postAdmin() {
  92. if ( $this->post_admin === false ) {
  93. require_once vc_path_dir( 'CORE_DIR', 'class-vc-post-admin.php' );
  94. $this->post_admin = new Vc_Post_Admin();
  95. }
  96. return $this->post_admin;
  97. }
  98. /**
  99. * Build VC for frontend pages.
  100. *
  101. * @since 4.2
  102. * @access public
  103. */
  104. public function initPage() {
  105. do_action( 'vc_build_page' );
  106. add_action( 'template_redirect', array( &$this, 'frontCss' ) );
  107. add_action( 'wp_head', array( &$this, 'addFrontCss' ), 1000 );
  108. add_action( 'wp_head', array( &$this, 'addNoScript' ), 1000 );
  109. add_action( 'template_redirect', array( &$this, 'frontJsRegister' ) );
  110. add_filter( 'the_content', array( &$this, 'fixPContent' ), 11 );
  111. }
  112. /**
  113. * Load admin required modules and elements
  114. *
  115. * @since 4.2
  116. * @access public
  117. */
  118. public function initAdmin() {
  119. do_action( 'vc_build_admin_page' );
  120. // Build settings for admin page;
  121. $this->registerAdminJavascript();
  122. $this->registerAdminCss();
  123. $this->editForm()->init();
  124. $this->templatesEditor()->init(); // @deprecated and will be removed
  125. $this->templatesPanelEditor()->init(); // new Templates editor @since 4.4
  126. add_action( 'edit_post', array( &$this, 'save' ) );
  127. add_action( 'wp_ajax_wpb_single_image_src', array( &$this, 'singleImageSrc' ) );
  128. add_action( 'wp_ajax_wpb_gallery_html', array( &$this, 'galleryHTML' ) );
  129. add_action( 'admin_init', array( &$this, 'composerRedirect' ) );
  130. add_filter( 'plugin_action_links', array( &$this, 'pluginActionLinks' ), 10, 2 );
  131. }
  132. /**
  133. * Setter for edit form.
  134. * @since 4.2
  135. *
  136. * @param Vc_Shortcode_Edit_Form $form
  137. */
  138. public function setEditForm( Vc_Shortcode_Edit_Form $form ) {
  139. $this->shortcode_edit_form = $form;
  140. }
  141. /**
  142. * Get Shortcodes Edit form object.
  143. *
  144. * @see Vc_Shortcode_Edit_Form::__construct
  145. * @since 4.2
  146. * @access public
  147. * @return Vc_Shortcode_Edit_Form
  148. */
  149. public function editForm() {
  150. return $this->shortcode_edit_form;
  151. }
  152. /**
  153. * Setter for Templates editor.
  154. * @deprecated since 4.4 updated to panel editor see Vc_Templates_Panel_Editor::__construct
  155. * @use setTemplatesPanelEditor
  156. * @since 4.2
  157. *
  158. * @param Vc_Templates_Editor $editor
  159. */
  160. public function setTemplatesEditor( Vc_Templates_Editor $editor ) {
  161. $this->templates_editor = $editor;
  162. }
  163. /**
  164. * Setter for Templates editor.
  165. * @since 4.4
  166. *
  167. * @param Vc_Templates_Panel_Editor $editor
  168. */
  169. public function setTemplatesPanelEditor( Vc_Templates_Panel_Editor $editor ) {
  170. $this->templates_panel_editor = $editor;
  171. }
  172. /**
  173. * Get templates manager.
  174. * @deprecated updated to panel editor see Vc_Templates_Panel_Editor::__construct
  175. * @see Vc_Templates_Editor::__construct
  176. * @since 4.2
  177. * @access public
  178. * @return bool|Vc_Templates_Editor
  179. */
  180. public function templatesEditor() {
  181. return $this->templates_editor;
  182. }
  183. /**
  184. * Get templates manager.
  185. * @see Vc_Templates_Panel_Editor::__construct
  186. * @since 4.4
  187. * @access public
  188. * @return bool|Vc_Templates_Panel_Editor
  189. */
  190. public function templatesPanelEditor() {
  191. return $this->templates_panel_editor;
  192. }
  193. /**
  194. * Save method for edit_post action.
  195. *
  196. * @since 4.2
  197. * @access public
  198. *
  199. * @param null $post_id
  200. */
  201. public function save( $post_id = null ) {
  202. /**
  203. * vc_filter: vc_base_save_post_custom_css
  204. * @since 4.4
  205. */
  206. $post_custom_css = apply_filters( 'vc_base_save_post_custom_css',
  207. vc_post_param( 'vc_post_custom_css' ) );
  208. if ( $post_custom_css !== null && empty( $post_custom_css ) ) {
  209. delete_post_meta( $post_id, '_wpb_post_custom_css' );
  210. } elseif ( $post_custom_css !== null ) {
  211. update_post_meta( $post_id, '_wpb_post_custom_css', $post_custom_css );
  212. }
  213. visual_composer()->buildShortcodesCustomCss( $post_id );
  214. }
  215. /**
  216. * @todo check for usage
  217. *
  218. * @param $args
  219. *
  220. * @since 4.2
  221. * @return array
  222. */
  223. public function jsForceSend( $args ) {
  224. $args['send'] = true;
  225. return $args;
  226. }
  227. /**
  228. * Add new shortcode to Visual composer.
  229. *
  230. * @see WPBMap::map
  231. * @since 4.2
  232. * @access public
  233. *
  234. * @param array $shortcode - array of options.
  235. */
  236. public function addShortCode( array $shortcode ) {
  237. require_once vc_path_dir( 'SHORTCODES_DIR', 'shortcodes.php' );
  238. $this->shortcodes[$shortcode['base']] = new WPBakeryShortCodeFishBones( $shortcode );
  239. }
  240. /**
  241. * Get shortcode class instance.
  242. *
  243. * @see WPBakeryShortCodeFishBones
  244. * @since 4.2
  245. * @access public
  246. *
  247. * @param string $tag
  248. *
  249. * @return WPBakeryShortCodeFishBones|null
  250. */
  251. public function getShortCode( $tag ) {
  252. return isset( $this->shortcodes[ $tag ] ) ? $this->shortcodes[ $tag ] : null;
  253. }
  254. /**
  255. * Remove shortcode from shortcodes list of VC.
  256. *
  257. * @since 4.2
  258. * @access public
  259. *
  260. * @param $tag - shortcode tag
  261. */
  262. public function removeShortCode( $tag ) {
  263. remove_shortcode( $tag );
  264. }
  265. /**
  266. * Todo: move it
  267. * @since 4.2
  268. */
  269. public function singleImageSrc() {
  270. $image_id = (int) vc_post_param( 'content' );
  271. $size = vc_post_param( 'size' );
  272. if ( empty( $image_id ) ) {
  273. die( '' );
  274. }
  275. if ( empty( $size ) ) {
  276. $size = 'thumbnail';
  277. }
  278. $thumb_src = wp_get_attachment_image_src( $image_id, $size );
  279. echo $thumb_src ? $thumb_src[0] : '';
  280. die();
  281. }
  282. /**
  283. * Todo: move it
  284. * @since 4.2
  285. */
  286. public function galleryHTML() {
  287. $images = vc_post_param( 'content' );
  288. if ( !empty( $images ) ) {
  289. echo fieldAttachedImages( explode( ",", $images ) );
  290. }
  291. die();
  292. }
  293. /**
  294. * Rewrite code or name
  295. * @since 4.2
  296. */
  297. public function createShortCodes() {
  298. remove_all_shortcodes();
  299. foreach ( WPBMap::getShortCodes() as $sc_base => $el ) {
  300. $this->shortcodes[$sc_base] = new WPBakeryShortCodeFishBones( $el );
  301. }
  302. }
  303. /**
  304. * Set or modify new settings for shortcode.
  305. *
  306. * This function widely used by WPBMap class methods to modify shortcodes mapping
  307. *
  308. * @since 4.3
  309. *
  310. * @param $tag
  311. * @param $name
  312. * @param $value
  313. */
  314. public function updateShortcodeSetting( $tag, $name, $value ) {
  315. $this->shortcodes[$tag]->setSettings( $name, $value );
  316. }
  317. /**
  318. * Build custom css styles for page from shortcodes attributes created by VC editors.
  319. *
  320. * Called by save method, which is hooked by edit_post action.
  321. * Function creates meta data for post with the key '_wpb_shortcodes_custom_css'
  322. * and value as css string, which will be added to the footer of the page.
  323. *
  324. * @since 4.2
  325. * @access public
  326. *
  327. * @param $post_id
  328. */
  329. public function buildShortcodesCustomCss( $post_id ) {
  330. $post = get_post( $post_id );
  331. // $this->createShortCodes();
  332. /**
  333. * vc_filter: vc_base_build_shortcodes_custom_css
  334. * @since 4.4
  335. */
  336. $css = apply_filters( 'vc_base_build_shortcodes_custom_css',
  337. $this->parseShortcodesCustomCss( $post->post_content ) );
  338. if ( empty( $css ) ) {
  339. delete_post_meta( $post_id, '_wpb_shortcodes_custom_css' );
  340. } else {
  341. update_post_meta( $post_id, '_wpb_shortcodes_custom_css', $css );
  342. }
  343. }
  344. /**
  345. * Parse shortcodes custom css string.
  346. *
  347. * This function is used by self::buildShortcodesCustomCss and creates css string from shortcodes attributes
  348. * like 'css_editor'.
  349. *
  350. * @see WPBakeryVisualComposerCssEditor
  351. * @since 4.2
  352. * @access public
  353. *
  354. * @param $content
  355. *
  356. * @return string
  357. */
  358. public function parseShortcodesCustomCss( $content ) {
  359. $css = '';
  360. if ( !preg_match( '/\s*(\.[^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', $content ) ) {
  361. return $css;
  362. }
  363. preg_match_all( '/' . get_shortcode_regex() . '/', $content, $shortcodes );
  364. foreach ( $shortcodes[2] as $index => $tag ) {
  365. $shortcode = WPBMap::getShortCode( $tag );
  366. $attr_array = shortcode_parse_atts( trim( $shortcodes[3][$index] ) );
  367. if ( isset( $shortcode['params'] ) && !empty( $shortcode['params'] ) ) {
  368. foreach ( $shortcode['params'] as $param ) {
  369. if ( $param['type'] == 'css_editor' && isset( $attr_array[$param['param_name']] ) ) {
  370. $css .= $attr_array[$param['param_name']];
  371. }
  372. }
  373. }
  374. }
  375. foreach ( $shortcodes[5] as $shortcode_content ) {
  376. $css .= $this->parseShortcodesCustomCss( $shortcode_content );
  377. }
  378. return $css;
  379. }
  380. /**
  381. * Hooked class method by wp_head WP action to output post custom css.
  382. *
  383. * Method gets post meta value for page by key '_wpb_post_custom_css' and if it is not empty
  384. * outputs css string wrapped into style tag.
  385. *
  386. * @since 4.2
  387. * @access public
  388. *
  389. * @param integer $id
  390. */
  391. public function addPageCustomCss( $id = null ) {
  392. if ( !is_singular() ) {
  393. return;
  394. }
  395. if ( !$id ) {
  396. $id = get_the_ID();
  397. }
  398. if ( $id ) {
  399. $post_custom_css = get_post_meta( $id, '_wpb_post_custom_css', true );
  400. if ( !empty( $post_custom_css ) ) {
  401. echo '<style type="text/css" data-type="vc_custom-css">';
  402. echo $post_custom_css;
  403. echo '</style>';
  404. }
  405. }
  406. }
  407. /**
  408. * Hooked class method by wp_footer WP action to output shortcodes css editor settings from page meta data.
  409. *
  410. * Method gets post meta value for page by key '_wpb_shortcodes_custom_css' and if it is not empty
  411. * outputs css string wrapped into style tag.
  412. *
  413. * @since 4.2
  414. * @access public
  415. *
  416. * @param integer $id
  417. *
  418. */
  419. public function addShortcodesCustomCss( $id = null ) {
  420. if ( !is_singular() ) {
  421. return;
  422. }
  423. if ( !$id ) {
  424. $id = get_the_ID();
  425. }
  426. if ( $id ) {
  427. $shortcodes_custom_css = get_post_meta( $id, '_wpb_shortcodes_custom_css', true );
  428. if ( !empty( $shortcodes_custom_css ) ) {
  429. echo '<style type="text/css" data-type="vc_shortcodes-custom-css">';
  430. echo $shortcodes_custom_css;
  431. echo '</style>';
  432. }
  433. }
  434. }
  435. /**
  436. * Add css styles for current page and elements design options added w\ editor.
  437. */
  438. public function addFrontCss() {
  439. get_post();
  440. $this->addPageCustomCss();
  441. $this->addShortcodesCustomCss();
  442. }
  443. public function addNoScript() {
  444. echo '<noscript>';
  445. echo '<style>';
  446. echo ' .wpb_animate_when_almost_visible { opacity: 1; }';
  447. echo '</style>';
  448. echo '</noscript>';
  449. }
  450. /**
  451. * @todo remove or refactor.
  452. */
  453. public function composerRedirect() {
  454. if ( get_option( 'wpb_js_composer_do_activation_redirect', false ) ) {
  455. delete_option( 'wpb_js_composer_do_activation_redirect' );
  456. wp_redirect( admin_url( 'options-general.php?page=vc_settings&build_css=1' ) );
  457. }
  458. }
  459. /**
  460. * Register front css styles.
  461. *
  462. * Calls wp_register_style for required css libraries files.
  463. *
  464. * @since 3.1
  465. * @access public
  466. */
  467. public function frontCss() {
  468. wp_register_style( 'flexslider', vc_asset_url( 'lib/flexslider/flexslider.css' ), false, WPB_VC_VERSION, 'screen' );
  469. wp_register_style( 'nivo-slider-css', vc_asset_url( 'lib/nivoslider/nivo-slider.css' ), false, WPB_VC_VERSION, 'screen' );
  470. wp_register_style( 'nivo-slider-theme', vc_asset_url( 'lib/nivoslider/themes/default/default.css' ), array( 'nivo-slider-css' ), WPB_VC_VERSION, 'screen' );
  471. wp_register_style( 'prettyphoto', vc_asset_url( 'lib/prettyphoto/css/prettyPhoto.css' ), false, WPB_VC_VERSION, 'screen' );
  472. wp_register_style( 'isotope-css', vc_asset_url( 'css/lib/isotope.css' ), false, WPB_VC_VERSION, 'all' );
  473. wp_register_style( 'font-awesome', vc_asset_url( 'lib/font-awesome/css/font-awesome.min.css' ), false, WPB_VC_VERSION, 'screen' );
  474. $front_css_file = vc_asset_url( 'css/js_composer.css' );
  475. $upload_dir = wp_upload_dir();
  476. if ( vc_settings()->get( 'use_custom' ) == '1' && is_file( $upload_dir['basedir'] . '/' . vc_upload_dir() . '/js_composer_front_custom.css' ) ) {
  477. $front_css_file = $upload_dir['baseurl'] . '/' . vc_upload_dir() . '/js_composer_front_custom.css';
  478. // fix @since 4.4, todo review it.
  479. $front_css_file = str_replace( array(
  480. 'http://',
  481. 'https://'
  482. ), '//', $front_css_file );
  483. }
  484. wp_register_style( 'js_composer_front', $front_css_file, false, WPB_VC_VERSION, 'all' );
  485. $custom_css_path = $upload_dir['basedir'] . '/' . vc_upload_dir() . '/custom.css';
  486. if ( is_file( $upload_dir['basedir'] . '/' . vc_upload_dir() . '/custom.css' ) ) {
  487. $custom_css_url = $upload_dir['baseurl'] . '/' . vc_upload_dir() . '/custom.css';
  488. // @todo fix file_get_content()
  489. if ( strlen( trim( vc_file_get_contents( $custom_css_path ) ) ) > 0 ) {
  490. $custom_css_url = str_replace( array(
  491. 'http://',
  492. 'https://'
  493. ), '//', $custom_css_url );
  494. wp_register_style( 'js_composer_custom_css', $custom_css_url, array(), WPB_VC_VERSION, 'screen' );
  495. }
  496. }
  497. add_action( 'wp_enqueue_scripts', array( &$this, 'enqueueStyle' ) );
  498. /**
  499. * @since 4.4
  500. */
  501. do_action( 'vc_base_register_front_css' );
  502. // add_action( 'wp_head', array( &$this, 'addShortcodesCustomCss' ), 1000 );
  503. }
  504. /**
  505. * Enqueue base css class for VC elements and enqueue custom css if exists.
  506. */
  507. public function enqueueStyle() {
  508. $post = get_post();
  509. if ( $post && preg_match( '/vc_row/', $post->post_content ) ) {
  510. wp_enqueue_style( 'js_composer_front' );
  511. }
  512. wp_enqueue_style( 'js_composer_custom_css' );
  513. }
  514. /**
  515. * Register front javascript libs.
  516. *
  517. * Calls wp_register_script for required css libraries files.
  518. *
  519. * @since 3.1
  520. * @access public
  521. */
  522. public function frontJsRegister() {
  523. wp_register_script( 'jquery_ui_tabs_rotate', vc_asset_url( 'lib/jquery-ui-tabs-rotate/jquery-ui-tabs-rotate.js' ), array(
  524. 'jquery',
  525. 'jquery-ui-tabs'
  526. ), WPB_VC_VERSION, true );
  527. wp_register_script( 'wpb_composer_front_js', vc_asset_url( 'js/js_composer_front.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  528. wp_register_script( 'tweet', vc_asset_url( 'lib/jquery.tweet/jquery.tweet.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  529. wp_register_script( 'isotope', vc_asset_url( 'lib/isotope/dist/isotope.pkgd.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  530. wp_register_script( 'jcarousellite', vc_asset_url( 'lib/jcarousellite/jcarousellite_1.0.1.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  531. wp_register_script( 'twbs-pagination', vc_asset_url( 'lib/twbs-pagination/jquery.twbsPagination.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  532. wp_register_script( 'nivo-slider', vc_asset_url( 'lib/nivoslider/jquery.nivo.slider.pack.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  533. wp_register_script( 'flexslider', vc_asset_url( 'lib/flexslider/jquery.flexslider-min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  534. wp_register_script( 'prettyphoto', vc_asset_url( 'lib/prettyphoto/js/jquery.prettyPhoto.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  535. wp_register_script( 'waypoints', vc_asset_url( 'lib/waypoints/waypoints.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  536. //wp_register_script( 'jcarousellite', vc_asset_url( 'js/jcarousellite_1.0.1.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true);
  537. //wp_register_script( 'anythingslider', vc_asset_url( 'js/jquery.anythingslider.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true);
  538. /**
  539. * @since 4.4
  540. */
  541. do_action( 'vc_base_register_front_js' );
  542. }
  543. /**
  544. * Register admin javascript libs.
  545. *
  546. * Calls wp_register_script for required css libraries files for Admin dashboard.
  547. *
  548. * @since 3.1
  549. * vc_filter: vc_i18n_locale_composer_js_view, since 4.4 - override localization for js
  550. * @access public
  551. */
  552. public function registerAdminJavascript() {
  553. /**
  554. * TODO: REFACTOR
  555. * Save register only core js files and check for backend or front
  556. */
  557. // $this->frontJsRegister();
  558. wp_register_script( 'isotope', vc_asset_url( 'lib/isotope/dist/isotope.pkgd.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  559. wp_register_script( 'wpb_scrollTo_js', vc_asset_url( 'lib/scrollTo/jquery.scrollTo.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  560. wp_register_script( 'wpb_php_js', vc_asset_url( 'lib/php.default/php.default.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  561. wp_register_script( 'wpb_json-js', vc_asset_url( 'lib/json-js/json2.js' ), false, WPB_VC_VERSION, true );
  562. wp_register_script( 'wpb_js_composer_js_tools', vc_asset_url( 'js/backend/composer-tools.js' ), array(
  563. 'jquery',
  564. 'backbone',
  565. 'wpb_json-js'
  566. ), WPB_VC_VERSION, true );
  567. wp_register_script( 'wpb_js_composer_settings', vc_asset_url( 'js/backend/composer-settings-page.js' ), array(
  568. 'jquery',
  569. 'wpb_js_composer_js_tools'
  570. ), WPB_VC_VERSION, true );
  571. wp_register_script( 'wpb_jscomposer_media_editor_js', vc_asset_url( 'js/backend/media-editor.js' ), array(
  572. 'media-views',
  573. 'media-editor',
  574. 'mce-view',
  575. 'wpb_js_composer_js_view'
  576. ), WPB_VC_VERSION, true );
  577. wp_register_script( 'wpb_js_composer_js_atts', vc_asset_url( 'js/params/composer-atts.js' ), array( 'wp-color-picker', 'wpb_js_composer_js_tools' ), WPB_VC_VERSION, true );
  578. wp_register_script( 'wpb_js_composer_js_storage', vc_asset_url( 'js/backend/composer-storage.js' ), array( 'wpb_js_composer_js_atts' ), WPB_VC_VERSION, true );
  579. wp_register_script( 'wpb_js_composer_js_models', vc_asset_url( 'js/backend/composer-models.js' ), array( 'wpb_js_composer_js_storage' ), WPB_VC_VERSION, true );
  580. wp_register_script( 'wpb_js_composer_editor_panels', vc_asset_url( 'js/editors/panels.js' ), array( 'wpb_js_composer_js_models' ), WPB_VC_VERSION, true );
  581. wp_register_script( 'wpb_js_composer_js_view', vc_asset_url( 'js/backend/composer-view.js' ), array( 'wpb_js_composer_editor_panels' ), WPB_VC_VERSION, true );
  582. wp_register_script( 'wpb_js_composer_js_custom_views', vc_asset_url( 'js/backend/composer-custom-views.js' ), array( 'wpb_js_composer_js_view' ), WPB_VC_VERSION, true );
  583. wp_register_script( 'wpb_jscomposer_autosuggest_js', vc_asset_url( 'lib/autosuggest/jquery.autoSuggest.js' ), array( 'wpb_js_composer_js_view' ), WPB_VC_VERSION, true );
  584. wp_register_script( 'wpb_jscomposer_teaser_js', vc_asset_url( 'js/backend/composer-teaser.js' ), array(), WPB_VC_VERSION, true );
  585. if ( !vc_is_as_theme() || ( vc_is_as_theme() && 'admin_settings_page' !== vc_mode() ) ) {
  586. wp_register_script( 'ace-editor', vc_asset_url( 'lib/ace-builds/src-min-noconflict/ace.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  587. }
  588. /**
  589. * vc_filter: vc_i18n_locale_composer_js_view - @since 4.4
  590. */
  591. wp_localize_script( 'wpb_js_composer_js_view', 'i18nLocale', apply_filters( 'vc_i18n_locale_composer_js_view', array(
  592. 'add_remove_picture' => __( 'Add/remove picture', 'js_composer' ),
  593. 'finish_adding_text' => __( 'Finish Adding Images', 'js_composer' ),
  594. 'add_image' => __( 'Add Image', 'js_composer' ),
  595. 'add_images' => __( 'Add Images', 'js_composer' ),
  596. 'settings' => __( 'Settings', 'js_composer' ),
  597. 'main_button_title' => __( 'Visual Composer', 'js_composer' ),
  598. 'main_button_title_backend_editor' => __( 'BACKEND EDITOR', 'js_composer' ),
  599. 'main_button_title_frontend_editor' => __( 'FRONTEND EDITOR', 'js_composer' ),
  600. 'main_button_title_revert' => __( 'CLASSIC MODE', 'js_composer' ),
  601. 'please_enter_templates_name' => __( 'Please enter template name', 'js_composer' ),
  602. 'confirm_deleting_template' => __( 'Confirm deleting "{template_name}" template, press Cancel to leave. This action cannot be undone.', 'js_composer' ),
  603. 'press_ok_to_delete_section' => __( 'Press OK to delete section, Cancel to leave', 'js_composer' ),
  604. 'drag_drop_me_in_column' => __( 'Drag and drop me in the column', 'js_composer' ),
  605. 'press_ok_to_delete_tab' => __( 'Press OK to delete "{tab_name}" tab, Cancel to leave', 'js_composer' ),
  606. 'slide' => __( 'Slide', 'js_composer' ),
  607. 'tab' => __( 'Tab', 'js_composer' ),
  608. 'section' => __( 'Section', 'js_composer' ),
  609. 'please_enter_new_tab_title' => __( 'Please enter new tab title', 'js_composer' ),
  610. 'press_ok_delete_section' => __( 'Press OK to delete "{tab_name}" section, Cancel to leave', 'js_composer' ),
  611. 'section_default_title' => __( 'Section', 'js_composer' ),
  612. 'please_enter_section_title' => __( 'Please enter new section title', 'js_composer' ),
  613. 'error_please_try_again' => __( 'Error. Please try again.', 'js_composer' ),
  614. 'if_close_data_lost' => __( 'If you close this window all shortcode settings will be lost. Close this window?', 'js_composer' ),
  615. 'header_select_element_type' => __( 'Select element type', 'js_composer' ),
  616. 'header_media_gallery' => __( 'Media gallery', 'js_composer' ),
  617. 'header_element_settings' => __( 'Element settings', 'js_composer' ),
  618. 'add_tab' => __( 'Add tab', 'js_composer' ),
  619. 'are_you_sure_convert_to_new_version' => __( 'Are you sure you want to convert to new version?', 'js_composer' ),
  620. 'loading' => __( 'Loading...', 'js_composer' ),
  621. // Media editor
  622. 'set_image' => __( 'Set Image', 'js_composer' ),
  623. 'are_you_sure_reset_css_classes' => __( 'Are you sure that you want to remove all your data?', 'js_composer' ),
  624. 'loop_frame_title' => __( 'Loop settings' ),
  625. 'enter_custom_layout' => __( 'Enter custom layout for your row:', 'js_composer' ),
  626. 'wrong_cells_layout' => __( 'Wrong row layout format! Example: 1/2 + 1/2 or span6 + span6.', 'js_composer' ),
  627. 'row_background_color' => __( 'Row background color', 'js_composer' ),
  628. 'row_background_image' => __( 'Row background image', 'js_composer' ),
  629. 'column_background_color' => __( 'Column background color', 'js_composer' ),
  630. 'column_background_image' => __( 'Column background image', 'js_composer' ),
  631. 'guides_on' => __( 'Guides ON', 'js_composer' ),
  632. 'guides_off' => __( 'Guides OFF', 'js_composer' ),
  633. 'template_save' => __( 'New template successfully saved!', 'js_composer' ),
  634. 'template_added' => __( 'Template added to the page.', 'js_composer' ),
  635. 'template_removed' => __( 'Template successfully removed.', 'js_composer' ),
  636. 'template_is_empty' => __( 'Nothing to save. Template is empty.', 'js_composer' ),
  637. 'css_updated' => __( 'Page settings updated!', 'js_composer' ),
  638. 'update_all' => __( 'Update all', 'js_composer' ),
  639. 'confirm_to_leave' => __( 'The changes you made will be lost if you navigate away from this page.', 'js_composer' ),
  640. 'inline_element_saved' => __( '%s saved!', 'js_composer' ),
  641. 'inline_element_deleted' => __( '%s deleted!', 'js_composer' ),
  642. 'inline_element_cloned' => __( '%s cloned. <a href="#" class="vc_edit-cloned" data-model-id="%s">Edit now?</a>', 'js_composer' ),
  643. 'gfonts_loading_google_font_failed' => __( 'Loading Google Font failed', 'js_composer' ),
  644. 'gfonts_loading_google_font' => __( 'Loading Font...', 'js_composer' ),
  645. 'gfonts_unable_to_load_google_fonts' => __( 'Unable to load Google Fonts', 'js_composer' ),
  646. //'gfonts_font_loaded' => __( 'Google Font loaded successfully', 'js_composer' ),
  647. ) ) );
  648. /**
  649. * @since 4.4
  650. */
  651. do_action( 'vc_base_register_admin_js' );
  652. }
  653. /**
  654. * Register admin css styles.
  655. *
  656. * Calls wp_register_style for required css libraries files for admin dashboard.
  657. *
  658. * @since 3.1
  659. * @access public
  660. */
  661. public function registerAdminCss() {
  662. // $this->frontCss();
  663. wp_register_style( 'ui-custom-theme', vc_asset_url( 'css/ui-custom-theme/jquery-ui-less.custom.css' ), false, WPB_VC_VERSION, false );
  664. wp_register_style( 'isotope-css', vc_asset_url( 'css/lib/isotope.css' ), false, WPB_VC_VERSION, 'screen' );
  665. wp_register_style( 'animate-css', vc_asset_url( 'lib/animate-css/animate.css' ), false, WPB_VC_VERSION, 'screen' );
  666. wp_register_style( 'font-awesome', vc_asset_url( 'lib/font-awesome/css/font-awesome.min.css' ), false, WPB_VC_VERSION, 'screen' );
  667. $backend_default_css = 'css/js_composer_backend_editor.css';
  668. wp_register_style( 'js_composer', vc_asset_url( $backend_default_css ), array(
  669. 'isotope-css',
  670. 'animate-css'
  671. ), WPB_VC_VERSION, false );
  672. wp_register_style( 'wpb_jscomposer_autosuggest', vc_asset_url( 'lib/autosuggest/jquery.autoSuggest.css' ), false, WPB_VC_VERSION, false );
  673. /**
  674. * @since 4.4
  675. */
  676. do_action( 'vc_base_register_admin_css' );
  677. }
  678. /**
  679. * Add Settings link in plugin's page
  680. * @since 4.2
  681. *
  682. * @param $links
  683. * @param $file
  684. *
  685. * @return array
  686. */
  687. public function pluginActionLinks( $links, $file ) {
  688. if ( $file == plugin_basename( vc_path_dir( 'APP_DIR', '/js_composer.php' ) ) ) {
  689. $link = '<a title="' . __( 'Visual Composer Settings', 'js_composer' ) . '" href="' . esc_url( $this->getSettingsPageLink() ) . '">' . esc_html__( 'Settings', 'js_composer' ) . '</a>';
  690. array_unshift( $links, $link ); // Add to top
  691. }
  692. return $links;
  693. }
  694. /**
  695. * Get settings page link
  696. * @since 4.2
  697. * @return string url to settings page
  698. */
  699. public function getSettingsPageLink() {
  700. return add_query_arg( array( 'page' => 'vc_settings' ), admin_url( 'options-general.php' ) );
  701. }
  702. /**
  703. * Hooked class method by wp_head WP action.
  704. * Also add fix for IE8 bootstrap styles from WPExplorer
  705. * @since 4.2
  706. * @access public
  707. */
  708. public function addMetaData() {
  709. echo '<meta name="generator" content="Powered by Visual Composer - drag and drop page builder for WordPress."/>' . "\n";
  710. // Add IE8 compatibility from WPExplorer: https://github.com/wpexplorer/visual-composer-ie8
  711. echo '<!--[if IE 8]><link rel="stylesheet" type="text/css" href="' . vc_asset_url( 'css/vc-ie8.css' ) . '" media="screen"><![endif]-->';
  712. }
  713. /**
  714. * Method adds css class to body tag.
  715. *
  716. * Hooked class method by body_class WP filter. Method adds custom css class to body tag of the page to help
  717. * identify and build design specially for VC shortcodes.
  718. *
  719. * @since 4.2
  720. * @access public
  721. *
  722. * @param $classes
  723. *
  724. * @return array
  725. */
  726. public function bodyClass( $classes ) {
  727. return js_composer_body_class( $classes );
  728. }
  729. /**
  730. * Builds excerpt for post from content.
  731. *
  732. * Hooked class method by the_excerpt WP filter. When user creates content with VC all content is always wrapped by shortcodes.
  733. * This methods calls do_shortcode for post's content and then creates a new excerpt.
  734. *
  735. * @since 4.2
  736. * @access public
  737. *
  738. * @param $output
  739. *
  740. * @return string
  741. */
  742. public function excerptFilter( $output ) {
  743. global $post;
  744. if ( empty( $output ) && !empty( $post->post_content ) ) {
  745. $text = strip_tags( do_shortcode( $post->post_content ) );
  746. $excerpt_length = apply_filters( 'excerpt_length', 55 );
  747. $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[...]' );
  748. $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
  749. return $text;
  750. }
  751. return $output;
  752. }
  753. /**
  754. * Remove unwanted wraping with p for content.
  755. *
  756. * Hooked by 'the_content' filter.
  757. * @since 4.2
  758. *
  759. * @param null $content
  760. *
  761. * @return string|null
  762. */
  763. public function fixPContent( $content = null ) {
  764. //$content = preg_replace( '#^<\/p>|^<br \/>|<p>$#', '', $content );
  765. if ( $content ) {
  766. $s = array(
  767. '/' . preg_quote( '</div>', '/' ) . '[\s\n\f]*' . preg_quote( '</p>', '/' ) . '/i',
  768. '/' . preg_quote( '<p>', '/' ) . '[\s\n\f]*' . preg_quote( '<div ', '/' ) . '/i',
  769. '/' . preg_quote( '<p>', '/' ) . '[\s\n\f]*' . preg_quote( '<section ', '/' ) . '/i',
  770. '/' . preg_quote( '</section>', '/' ) . '[\s\n\f]*' . preg_quote( '</p>', '/' ) . '/i'
  771. );
  772. $r = array( "</div>", "<div ", "<section ", "</section>" );
  773. $content = preg_replace( $s, $r, $content );
  774. return $content;
  775. }
  776. return null;
  777. }
  778. /**
  779. * Set manger for custom third-party plugins.
  780. * @deprecated due to autoload logic
  781. * @since 4.3
  782. *
  783. * @param Vc_Vendors_Manager $vendor_manager
  784. */
  785. public function setVendorsManager( Vc_Vendors_Manager $vendor_manager ) {
  786. $this->vendor_manager = $vendor_manager;
  787. }
  788. /**
  789. * Get vendors manager.
  790. * @deprecated due to autoload logic from 4.4
  791. * @since 4.3
  792. * @return bool|Vc_Vendors_Manager
  793. */
  794. public function vendorsManager() {
  795. return $this->vendor_manager;
  796. }
  797. }
  798. /**
  799. * VC backward capability.
  800. * @deprecated @since 4.3
  801. */
  802. class WPBakeryVisualComposer extends Vc_Base {
  803. /**
  804. * @param $template
  805. *
  806. * @deprecated
  807. * @return string
  808. */
  809. public static function getUserTemplate( $template ) {
  810. return vc_manager()->getShortcodesTemplateDir( $template );
  811. }
  812. }