Guest User

Untitled

a guest
Oct 7th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.15 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by ra.
  4. * Date: 4/14/2016
  5. */
  6. // Ready to load the shortcodes
  7. require_once('tdc_util.php');
  8. require_once('tdc_state.php');
  9. require_once('tdc_ajax.php');
  10. require_once('tdc_guttenberg.php');
  11. add_action( 'enqueue_block_editor_assets', function() {
  12. if (TDC_DEPLOY_MODE == 'deploy' ) {
  13. wp_enqueue_script('js_files_for_gutenberg_style', TDC_URL . '/assets/js/js_files_for_gutenberg_style.min.js', array('jquery', 'wp-blocks', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-data'
  14. ), TD_COMPOSER, true);
  15. }else {
  16. wp_enqueue_script('tdcGutenbergStyle', TDC_URL . '/assets/js/tdcGutenbergStyle.js', array('jquery', 'wp-blocks', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-data'
  17. ), TD_COMPOSER, true);
  18. }
  19. });
  20. if ( tdc_guttenberg::is_gutenberg() or substr( get_bloginfo('version'), 0, 1) > 4 )
  21. new tdc_guttenberg();
  22. // shortcodes
  23. require_once('tdc_composer_block.php' );
  24. require_once('shortcodes/tdc_zone.php' );
  25. require_once('shortcodes/vc_row.php' );
  26. require_once('shortcodes/vc_row_inner.php' );
  27. require_once('shortcodes/vc_column.php' );
  28. require_once('shortcodes/vc_column_inner.php' );
  29. require_once('shortcodes/vc_column_text.php' );
  30. require_once('shortcodes/vc_raw_html.php' );
  31. require_once('shortcodes/vc_empty_space.php' );
  32. require_once('shortcodes/vc_widget_sidebar.php' );
  33. require_once('shortcodes/vc_single_image.php' );
  34. require_once('shortcodes/vc_separator.php' );
  35. require_once('shortcodes/vc_wp_recentcomments.php' );
  36. // mapper and internal map
  37. require_once('tdc_mapper.php');
  38. require_once('tdc_map.php');
  39. /**
  40. * WP-admin - Edit page with tagDiv composer
  41. */
  42. add_action('admin_bar_menu', 'tdc_on_admin_bar_menu', 100);
  43. function tdc_on_admin_bar_menu() {
  44. global $wp_admin_bar, $post;
  45. $is_bbpress = $is_buddypress = false;
  46. // bbpress
  47. if ( is_plugin_active( 'bbpress/bbpress.php') ) {
  48. if ( function_exists( 'is_bbpress' ) && is_bbpress() ) {
  49. $is_bbpress = true;
  50. }
  51. }
  52. // buddypress
  53. if ( is_plugin_active( 'buddypress/bp-loader.php') ) {
  54. if ( function_exists( 'is_buddypress' ) && is_buddypress() ) {
  55. $is_buddypress = true;
  56. }
  57. }
  58. if (
  59. is_user_logged_in() &&
  60. current_user_can('publish_pages') &&
  61. is_admin_bar_showing() &&
  62. is_page() &&
  63. ! $is_bbpress &&
  64. ! $is_buddypress &&
  65. ! td_util::is_mobile_theme()
  66. ) {
  67. $wp_admin_bar->add_menu( array(
  68. 'id' => 'tdc_edit',
  69. 'meta' => array(
  70. 'title' => 'Edit with TD Composer'
  71. ),
  72. 'title' => 'Edit with TD Composer',
  73. 'href' => admin_url( 'post.php?post_id=' . $post->ID . '&td_action=tdc&tdbTemplateType=page&prev_url=' . rawurlencode( tdc_util::get_current_url() ) )
  74. ) );
  75. }
  76. }
  77. // Set the tdc_state
  78. $tdcPageSettings = tdc_util::get_get_val( 'tdc-page-settings' );
  79. if ( 'post' === basename($_SERVER["SCRIPT_FILENAME"], '.php') && false !== $tdcPageSettings ) {
  80. add_action('admin_head', 'on_admin_head_add_page_settings');
  81. function on_admin_head_add_page_settings() {
  82. ?>
  83. <style>
  84. #wpcontent {
  85. margin-left: 0;
  86. margin-top: -30px;
  87. }
  88. #nav-menus-frame {
  89. margin-top: 0;
  90. }
  91. #wpadminbar,
  92. #screen-meta,
  93. #screen-meta-links,
  94. #adminmenumain,
  95. #wpfooter,
  96. .wrap > h1,
  97. .wrap > h2,
  98. .wrap > .manage-menus,
  99. .menu-save,
  100. .delete-action,
  101. .error,
  102. .update-nag,
  103. .major-publishing-actions,
  104. .page-title-action,
  105. .notice,
  106. #submitdiv,
  107. #postimagediv,
  108. #post-body-content,
  109. #td_mobile_wp_editor_content_meta_box,
  110. .edit-post-visual-editor,
  111. .edit-post-header,
  112. .edit-post-layout .components-notice-list,
  113. .edit-post-layout .components-panel__header,
  114. .edit-post-layout .components-panel__body.edit-post-post-status,
  115. .edit-post-layout .components-panel__body.edit-post-last-revision__panel {
  116. display: none !important;
  117. }
  118. #wpbody-content {
  119. padding-bottom: 0;
  120. }
  121. .edit-post-layout {
  122. padding-top: 0 !important;
  123. }
  124. .edit-post-sidebar {
  125. top: 0;
  126. }
  127. </style>
  128.  
  129. <script>
  130. (function(){
  131. jQuery(window).load(function() {
  132. var $wpbodyContent = jQuery( '#wpbody-content' ),
  133. $wrap = $wpbodyContent.children( '.wrap' ),
  134. $normalSortables = $wpbodyContent.find( '#normal-sortables' );
  135. $wrap.siblings().hide();
  136. $wrap.children( 'form' ).siblings().hide();
  137. $normalSortables.children().each(function(index, el) {
  138. var $el = jQuery(el),
  139. elId = $el.attr( 'id' );
  140. if ( 'td_homepage_loop_metabox' !== elId && 'td_page_metabox' !== elId ) {
  141. $el.hide();
  142. }
  143. });
  144. });
  145. })();
  146. </script>
  147. <?php
  148. // // Disables all the updates notifications regarding plugins, themes & WordPress completely.
  149. // tdc_disable_notification();
  150. }
  151. }
  152. // Set the tdc_state
  153. $tdcMenuSettings = tdc_util::get_get_val( 'tdc-menu-settings' );
  154. if ( 'nav-menus' === basename($_SERVER["SCRIPT_FILENAME"], '.php') && false !== $tdcMenuSettings ) {
  155. add_action('admin_head', 'on_admin_head_add_menu_settings');
  156. function on_admin_head_add_menu_settings() {
  157. ?>
  158. <style>
  159. #wpcontent {
  160. margin-left: 0;
  161. margin-top: -30px;
  162. }
  163. #nav-menus-frame {
  164. margin-top: 0;
  165. }
  166. #wpadminbar,
  167. #screen-meta,
  168. #screen-meta-links,
  169. #screen-options-link-wrap,
  170. #adminmenumain,
  171. #wpfooter,
  172. .wrap > h1,
  173. .wrap > h2,
  174. .wrap > .manage-menus,
  175. .menu-save,
  176. .delete-action,
  177. .error,
  178. .update-nag,
  179. .major-publishing-actions,
  180. .menu-settings {
  181. display: none !important;
  182. }
  183. #wpbody-content {
  184. padding-bottom: 0;
  185. }
  186. </style>
  187.  
  188. <script>
  189. (function(){
  190. jQuery(window).load(function() {
  191. var $wpbodyContent = jQuery( '#wpbody-content' );
  192. $wrap = $wpbodyContent.children( '.wrap' );
  193. $wrap.siblings().hide();
  194. $wrap.children().each(function(index, el) {
  195. var $el = jQuery(el),
  196. elId = $el.attr( 'id' );
  197. if ( 'nav-menus-frame' !== elId ) {
  198. $el.hide();
  199. }
  200. });
  201. });
  202. })();
  203. </script>
  204. <?php
  205. // Disables all the updates notifications regarding plugins, themes & WordPress completely.
  206. tdc_disable_notification();
  207. }
  208. }
  209. /**
  210. * edit with td composer
  211. */
  212. if ( is_user_logged_in() && current_user_can('publish_pages') && 'page' === tdc_util::get_get_val('post_type') ) {
  213. add_filter( 'page_row_actions', 'tdc_on_page_row_actions', 10, 2 );
  214. function tdc_on_page_row_actions( $actions, $post ) {
  215. if ( $post->ID === (int) get_option( 'page_for_posts' ) ) {
  216. $actions['edit_tdc_composer'] = '<a href="#">TD Composer is disabled on Posts Page</a>';
  217. } else {
  218. $actions['edit_tdc_composer'] = '<a href="' . admin_url( 'post.php?post_id=' . $post->ID . '&td_action=tdc&tdbTemplateType=page&prev_url=' . rawurlencode(tdc_util::get_current_url()) ) . '">Edit with TD Composer</a>';
  219. }
  220. return $actions;
  221. }
  222. }
  223. /**
  224. * Disables all the updates notifications regarding plugins, themes & WordPress completely.
  225. */
  226. function tdc_disable_notification() {
  227. add_filter( 'pre_site_transient_update_core','tdc_on_remove_core_updates' );
  228. add_filter( 'pre_site_transient_update_plugins','tdc_on_remove_core_updates' );
  229. add_filter( 'pre_site_transient_update_themes','tdc_on_remove_core_updates' );
  230. function tdc_on_remove_core_updates(){
  231. global $wp_version;
  232. return (object) array('last_checked'=> time(),'version_checked'=> $wp_version);
  233. }
  234. }
  235. // Remove the auto added paragraphs - as VC does
  236. // Important! Remove from 'page' and from 'tdb_templates' (custom post type used by template builder)
  237. add_filter( 'the_content', 'tdc_on_remove_wpautop', 9 );
  238. function tdc_on_remove_wpautop($content) {
  239. global $post;
  240. if ( ( 'page' === get_post_type() || 'tdb_templates' === get_post_type() ) && td_util::is_pagebuilder_content( $post ) ) {
  241. remove_filter( 'the_content', 'wpautop' );
  242. }
  243. return $content;
  244. }
  245. /**
  246. * load font icons
  247. */
  248. add_action( 'wp_enqueue_scripts', 'tdc_on_load_font_icon' ); // load them last
  249. function tdc_on_load_font_icon() {
  250. $icon_fonts = array();
  251. // Filter used to modify the post checked for icon fonts
  252. $post_id = apply_filters( 'tdc_filter_icon_fonts_post_id', get_the_ID() );
  253. $post_icon_fonts = get_post_meta( $post_id, 'tdc_icon_fonts', true );
  254. // echo '<pre>';
  255. // var_dump($tdc_icon_fonts);
  256. // echo '</pre>';
  257. if ( ! empty( $post_icon_fonts ) && is_array( $post_icon_fonts ) ) {
  258. foreach ( $post_icon_fonts as $font_id => $font_settings ) {
  259. $icon_fonts[ $font_id ] = $font_settings;
  260. }
  261. }
  262. // Get font icons for footer
  263. $tds_footer_page = td_util::get_option('tds_footer_page');
  264. if ( intval($tds_footer_page) !== $post_id ) {
  265. $footer_icon_fonts = get_post_meta( $tds_footer_page, 'tdc_icon_fonts', true );
  266. if ( ! empty( $footer_icon_fonts ) && is_array( $footer_icon_fonts ) ) {
  267. foreach ( $footer_icon_fonts as $font_id => $font_settings ) {
  268. if ( ! isset( $icon_fonts[ $font_id ] ) ) {
  269. $icon_fonts[ $font_id ] = $font_settings;
  270. }
  271. }
  272. }
  273. }
  274. foreach ( $icon_fonts as $font_id => $font_settings ) {
  275. if ( isset( $font_settings['theme_font'] ) ) {
  276. continue;
  277. }
  278. wp_enqueue_style( $font_id, TDC_URL . $font_settings['css_file'], false, TD_COMPOSER );
  279. }
  280. }
  281. // Set the tdc_state
  282. $td_action = tdc_util::get_get_val( 'td_action' );
  283. if ( false === $td_action ) {
  284. tdc_state::set_is_live_editor_iframe( false );
  285. } else {
  286. tdc_state::set_is_live_editor_iframe( true );
  287. }
  288. $tmpJobId = tdc_util::get_get_val( 'uuid' );
  289. if ( false === $tmpJobId ) {
  290. tdc_state::set_is_live_editor_ajax( false );
  291. } else {
  292. tdc_state::set_is_live_editor_ajax( true );
  293. }
  294. if ( ! tdc_state::is_live_editor_iframe() && ! tdc_state::is_live_editor_ajax() ) {
  295. // All hooks necessary for tdb
  296. add_action( 'admin_head', 'tdc_on_admin_head_for_tbm' );
  297. function tdc_on_admin_head_for_tbm() {
  298. $is_page_for_posts = false;
  299. global $post;
  300. if ( ! is_null( $post )) {
  301. $is_page_for_posts = $post->ID == get_option( 'page_for_posts' );
  302. }
  303. $tdc_admin_settings = array(
  304. 'adminUrl' => admin_url(),
  305. 'hasUserRights' => is_user_logged_in() && current_user_can('publish_pages'),
  306. 'isPageForPosts' => $is_page_for_posts,
  307. );
  308. ob_start();
  309. ?>
  310. <script>
  311. window.tdcAdminSettings = <?php echo json_encode( $tdc_admin_settings );?>;
  312. //console.log(window.tdcAdminSettings);
  313. </script>
  314. <?php
  315. $buffer = ob_get_clean();
  316. echo $buffer;
  317. }
  318. add_action( 'admin_enqueue_scripts', 'tdc_on_admin_enqueue_scripts_for_tbm' );
  319. function tdc_on_admin_enqueue_scripts_for_tbm() {
  320. // load the css
  321. if ( true === TDC_USE_LESS ) {
  322. wp_enqueue_style('tdc_wp_admin_main', TDC_URL . '/td_less_style.css.php?part=tdc_wp_admin_main', false, TD_COMPOSER );
  323. } else {
  324. wp_enqueue_style('tdc_wp_admin_main', TDC_URL . '/assets/css/tdc_wp_admin_main.css', false, TD_COMPOSER);
  325. }
  326. // load the js
  327. if (TDC_DEPLOY_MODE == 'deploy') {
  328. wp_enqueue_script('js_files_for_wp_admin', TDC_URL . '/assets/js/js_files_for_wp_admin.min.js', array('jquery', 'underscore'), TD_COMPOSER, true);
  329. } else {
  330. tdc_util::enqueue_js_files_array(tdc_config::$js_files_for_wp_admin, array('jquery', 'underscore'));
  331. }
  332. }
  333. return;
  334. }
  335. // DO NOT CONTINUE IF COMPOSER IS NOT LIVE OR IN AJAX
  336. /**
  337. * WP-admin - add js in header on all the admin pages (wp-admin and the iframe Wrapper. Does not run in the iframe)
  338. * It's on general, and not only for 'td-action=tdc' because it's also used on widgets' page.
  339. */
  340. add_action( 'admin_head', 'tdc_on_admin_head' );
  341. function tdc_on_admin_head() {
  342. //map_not_registered_shortcodes();
  343. $mappedShortcodes = tdc_mapper::get_mapped_shortcodes();
  344. $mappedBlockTemplates = tdc_mapper::get_mapped_block_templates();
  345. global $wp_registered_sidebars;
  346. foreach ( $mappedShortcodes as &$mappedShortcode ) {
  347. if ( 'vc_widget_sidebar' === $mappedShortcode[ 'base' ] ) {
  348. foreach ( $mappedShortcode[ 'params' ] as &$param ) {
  349. if ( 'sidebar_id' === $param[ 'param_name' ] ) {
  350. $param[ 'value' ][ __( '- Please select a sidebar -', 'td_composer' ) ] = '';
  351. foreach ( $wp_registered_sidebars as $key => $val ) {
  352. $param[ 'value' ][ $val[ 'name' ] ] = $key;
  353. }
  354. break;
  355. }
  356. }
  357. continue;
  358. }
  359. // Replace the 'dropdown' params values with values of the 'tdc_value' index (because VC does not render well default values of dropdown params)
  360. if ( 'td_block_instagram' === $mappedShortcode[ 'base' ] ||
  361. 'td_block_exchange' === $mappedShortcode[ 'base' ] ) {
  362. foreach ( $mappedShortcode[ 'params' ] as &$param ) {
  363. if ( 'dropdown' === $param[ 'type' ] && isset($param['tdc_value'] ) ) {
  364. $param['value'] = $param['tdc_value'];
  365. }
  366. }
  367. continue;
  368. }
  369. }
  370. $globalStyle = array();
  371. $settingsStyle = array();
  372. $groups = array();
  373. foreach ( td_api_style::get_all() as $style_id => $style ) {
  374. $group_style = $style['group'];
  375. if ( ! in_array( $group_style, $groups ) ) {
  376. $groups[] = $group_style;
  377. $settingsStyle[ $group_style ] = td_api_style::get_styles_by_group( $group_style );
  378. $globalStyle[ $group_style ] = td_options::get( $group_style, $style_id );
  379. }
  380. }
  381. // the settings that we load in wp-admin and wrapper. We need json to be sure we don't get surprises with the encoding/escaping
  382. // save the previous url - used when the X in composer is pressed to close it down.
  383. if (tdc_util::get_get_val('prev_url') != '') {
  384. $previous_url = htmlspecialchars_decode ( tdc_util::get_get_val('prev_url') );
  385. } else {
  386. $previous_url = get_edit_post_link(get_the_ID(), '');
  387. }
  388. $mappedFontFamily = array();
  389. $mappedFontWeight = array();
  390. $mappedFontTransform = array();
  391. $mappedFontStyle = array();
  392. foreach ( $mappedShortcodes as &$element ) {
  393. foreach ( $element['params'] as &$param ) {
  394. if ( strpos( $param['param_name'], 'font_family' ) > 0 ) {
  395. if ( empty( $mappedFontFamily ) ) {
  396. $mappedFontFamily = $param['value'];
  397. }
  398. $param['value'] = '';
  399. } else if ( strpos( $param['param_name'], 'font_weight' ) > 0 ) {
  400. if ( empty( $mappedFontWeight ) ) {
  401. $mappedFontWeight = $param['value'];
  402. }
  403. $param['value'] = '';
  404. } else if ( strpos( $param['param_name'], 'font_transform' ) > 0 ) {
  405. if ( empty( $mappedFontTransform ) ) {
  406. $mappedFontTransform = $param['value'];
  407. }
  408. $param['value'] = '';
  409. } else if ( strpos( $param['param_name'], 'font_style' ) > 0 ) {
  410. if ( empty( $mappedFontStyle ) ) {
  411. $mappedFontStyle = $param['value'];
  412. }
  413. $param['value'] = '';
  414. }
  415. }
  416. }
  417. foreach ( $settingsStyle as &$group ) {
  418. foreach ( $group as &$element ) {
  419. foreach ( $element['params'] as &$param ) {
  420. if ( strpos( $param['param_name'], 'font_family' ) > 0 ) {
  421. if ( empty( $mappedFontFamily ) ) {
  422. $mappedFontFamily = $param['value'];
  423. }
  424. $param['value'] = '';
  425. } else if ( strpos( $param['param_name'], 'font_weight' ) > 0 ) {
  426. if ( empty( $mappedFontWeight ) ) {
  427. $mappedFontWeight = $param['value'];
  428. }
  429. $param['value'] = '';
  430. } else if ( strpos( $param['param_name'], 'font_transform' ) > 0 ) {
  431. if ( empty( $mappedFontTransform ) ) {
  432. $mappedFontTransform = $param['value'];
  433. }
  434. $param['value'] = '';
  435. } else if ( strpos( $param['param_name'], 'font_style' ) > 0 ) {
  436. if ( empty( $mappedFontStyle ) ) {
  437. $mappedFontStyle = $param['value'];
  438. }
  439. $param['value'] = '';
  440. }
  441. }
  442. }
  443. }
  444. $tdb_header_templates = array();
  445. // read the tdb category templates
  446. $wp_query_templates = new WP_Query( array(
  447. 'post_type' => 'tdb_templates',
  448. 'posts_per_page' => -1,
  449. 'meta_key' => 'tdb_template_type',
  450. 'meta_value' => 'header'
  451. )
  452. );
  453. if ( !empty( $wp_query_templates->posts ) ) {
  454. foreach ( $wp_query_templates->posts as $post ) {
  455. $tdb_header_templates[] = array(
  456. 'text' => $post->post_title,
  457. 'val' => 'tdb_template_' . $post->ID
  458. );
  459. }
  460. }
  461. $global_header_template_id = td_api_header_style::get_header_template_id();
  462. $global_header_template_content = '';
  463. if ( ! empty( $global_header_template_id ) && td_global::is_tdb_template( $global_header_template_id, true ) ) {
  464. $global_header_template_id = td_global::tdb_get_template_id( $global_header_template_id );
  465. $global_header_template_content = get_post_field('post_content', $global_header_template_id );
  466. }
  467. $tdc_admin_settings = array(
  468. 'adminUrl' => admin_url(),
  469. 'ABSPATH' => ABSPATH,
  470. 'editPostUrl' => get_edit_post_link( get_the_ID(), '' ),
  471. 'previousUrl' => $previous_url, //this is uesd to redirect to the previous url when the composer is closed
  472. 'wpRestNonce' => wp_create_nonce('wp_rest'),
  473. 'wpRestUrl' => rest_url(),
  474. 'permalinkStructure' => get_option('permalink_structure'),
  475. 'pluginUrl' => TDC_URL,
  476. 'themeName' => TD_THEME_NAME,
  477. 'mappedShortcodes' => $mappedShortcodes, // get ALL the mapped shortcodes / we should turn off pretty print
  478. 'mappedFontFamily' => $mappedFontFamily,
  479. 'mappedFontWeight' => $mappedFontWeight,
  480. 'mappedFontTransform' => $mappedFontTransform,
  481. 'mappedFontStyle' => $mappedFontStyle,
  482. 'mappedBlockTemplates' => $mappedBlockTemplates, // get ALL the mapped block templates / we should turn off pretty print
  483. 'customized' => array(
  484. 'menus' => new stdClass()
  485. ),
  486. 'globalBlockTemplate' => td_options::get('tds_global_block_template', 'td_block_template_1'),
  487. 'globalStyle' => $globalStyle,
  488. 'settingsStyle' => $settingsStyle,
  489. 'registeredSidebars' => $GLOBALS['wp_registered_sidebars'],
  490. 'hasUserRights' => is_user_logged_in() && current_user_can('publish_pages'),
  491. 'tdcSavings' => td_util::get_option( 'tdc_savings' ),
  492. 'deployMode' => TDC_DEPLOY_MODE,
  493. 'tdbHeaderTemplates' => $tdb_header_templates,
  494. 'headerTemplateId' => $global_header_template_id,
  495. 'headerTemplateContent' => $global_header_template_content
  496. );
  497. echo '<script>window.tdcAdminSettings = ' . json_encode( $tdc_admin_settings ) . '</script>';
  498. ob_start();
  499. ?>
  500. <script>
  501. for ( var shortcode in window.tdcAdminSettings.mappedShortcodes ) {
  502. var params = window.tdcAdminSettings.mappedShortcodes[shortcode].params;
  503. for ( var param in params ) {
  504. if ( params[param].param_name.indexOf( 'font_family' ) > 0 && '' === params[param]['value'] ) {
  505. params[param]['value'] = window.tdcAdminSettings.mappedFontFamily;
  506. } else if ( params[param].param_name.indexOf( 'font_weight' ) > 0 && '' === params[param]['value'] ) {
  507. params[param]['value'] = window.tdcAdminSettings.mappedFontWeight;
  508. } else if ( params[param].param_name.indexOf( 'font_transform' ) > 0 && '' === params[param]['value'] ) {
  509. params[param]['value'] = window.tdcAdminSettings.mappedFontTransform;
  510. } else if ( params[param].param_name.indexOf( 'font_style' ) > 0 && '' === params[param]['value'] ) {
  511. params[param]['value'] = window.tdcAdminSettings.mappedFontStyle;
  512. }
  513. }
  514. }
  515. for ( var group in window.tdcAdminSettings.settingsStyle ) {
  516. for ( var style in window.tdcAdminSettings.settingsStyle[group] ) {
  517. var params = window.tdcAdminSettings.settingsStyle[group][style].params;
  518. for (var param in params) {
  519. if (params[param].param_name.indexOf('font_family') > 0 && '' === params[param]['value']) {
  520. params[param]['value'] = window.tdcAdminSettings.mappedFontFamily;
  521. } else if (params[param].param_name.indexOf('font_weight') > 0 && '' === params[param]['value']) {
  522. params[param]['value'] = window.tdcAdminSettings.mappedFontWeight;
  523. } else if (params[param].param_name.indexOf('font_transform') > 0 && '' === params[param]['value']) {
  524. params[param]['value'] = window.tdcAdminSettings.mappedFontTransform;
  525. } else if (params[param].param_name.indexOf('font_style') > 0 && '' === params[param]['value']) {
  526. params[param]['value'] = window.tdcAdminSettings.mappedFontStyle;
  527. }
  528. }
  529. }
  530. }
  531. // Code necessary to supply some vc functionality that VC does not register when tagDiv composer runs as frontend editor
  532. window.vc_user_access = function() {
  533. return {
  534. editor: function ( editor ) {
  535. return false;
  536. },
  537. partAccess: function ( editor ) {
  538. return false;
  539. },
  540. check: function ( part, rule, custom, not_check_state ) {
  541. return false;
  542. },
  543. getState: function ( part ) {
  544. return false;
  545. },
  546. shortcodeAll: function ( shortcode ) {
  547. return false;
  548. },
  549. shortcodeEdit: function ( shortcode ) {
  550. return false;
  551. },
  552. shortcodeValidateOldMethod: function ( shortcode ) {
  553. return false;
  554. },
  555. updateMergedCaps: function ( rule ) {
  556. return false;
  557. }
  558. };
  559. };
  560. //console.log(window.tdcAdminSettings);
  561. </script>
  562. <?php
  563. $buffer = ob_get_clean();
  564. echo $buffer;
  565. }
  566. // Code necessary to remove some vc functionality that interfere with tagDiv composer
  567. if ( class_exists( 'Vc_Manager' ) && method_exists( 'Vc_Manager', 'getInstance' ) ) {
  568. $vc_instance = Vc_Manager::getInstance();
  569. remove_action( 'init', array(
  570. $vc_instance,
  571. 'init',
  572. ), 9 );
  573. }
  574. add_action( 'after_setup_theme', 'tdc_on_register_external_shortcodes' );
  575. function tdc_on_register_external_shortcodes() {
  576. if ( tdc_state::is_live_editor_iframe() || tdc_state::is_live_editor_ajax() ) {
  577. register_external_shortcodes();
  578. } else {
  579. wrap_external_shortcodes();
  580. }
  581. }
  582. /**
  583. * Registers the js script:
  584. */
  585. add_action( 'admin_enqueue_scripts', 'tdc_on_admin_enqueue_scripts' );
  586. function tdc_on_admin_enqueue_scripts() {
  587. // load the css
  588. if ( true === TDC_USE_LESS ) {
  589. wp_enqueue_style('tdc_wp_admin_main', TDC_URL . '/td_less_style.css.php?part=tdc_wp_admin_main', false, TD_COMPOSER );
  590. } else {
  591. wp_enqueue_style('tdc_wp_admin_main', TDC_URL . '/assets/css/tdc_wp_admin_main.css', false, TD_COMPOSER);
  592. }
  593. // load the js
  594. if (TDC_DEPLOY_MODE == 'deploy') {
  595. wp_enqueue_script('js_files_for_wp_admin', TDC_URL . '/assets/js/js_files_for_wp_admin.min.js', array('jquery', 'underscore'), TD_COMPOSER, true);
  596. } else {
  597. tdc_util::enqueue_js_files_array(tdc_config::$js_files_for_wp_admin, array('jquery', 'underscore'));
  598. }
  599. // Disable the confirmation messages at leaving pages
  600. if ( tdc_state::is_live_editor_iframe() || tdc_state::is_live_editor_ajax() ) {
  601. wp_dequeue_script( 'autosave' );
  602. wp_deregister_script( 'ace-editor' );
  603. }
  604. //remove_action( 'vc-settings-render-tab-vc-custom_css', 'vc_page_settings_custom_css_load' );
  605. }
  606. if (!empty($td_action)) {
  607. // $_GET['post_id'] is requiered from now on
  608. $post_id = tdc_util::get_get_val( 'post_id' );
  609. if (empty($post_id)) {
  610. echo 'No post_id received via GET';
  611. die;
  612. }
  613. switch ($td_action) {
  614. case 'tdc':
  615. // Wrapper edit page
  616. $current_post = get_post($post_id);
  617. do_action_ref_array( 'the_post', array( &$current_post ) );
  618. tdc_state::set_post($current_post);
  619. /**
  620. * on wrap body class
  621. */
  622. add_filter( 'admin_body_class', 'on_admin_body_class_wrap');
  623. function on_admin_body_class_wrap( $classes ) {
  624. $classes .= ' tdc';
  625. global $post;
  626. $current_post_type = get_post_type( $post );
  627. $tdbTemplateType = tdc_util::get_get_val('tdbTemplateType');
  628. if ( false !== $tdbTemplateType ) {
  629. $current_post_type = $tdbTemplateType;
  630. }
  631. $classes .= ' tdb-template-type-' . $current_post_type;
  632. return $classes;
  633. }
  634. /**
  635. * on wrapper current_screen
  636. */
  637. add_action( 'current_screen', 'on_current_screen_load_wrap');
  638. function on_current_screen_load_wrap() {
  639. // @todo The 'tiny_mce' doesn't work as dependency. That's why it was independently loaded
  640. wp_enqueue_script( 'tiny_mce', includes_url( '/js/tinymce/tinymce.min.js' ) );
  641. //wp_enqueue_script( 'tiny_mce', '//tinymce.cachefly.net/4.1/tinymce.min.js' );
  642. if (TDC_DEPLOY_MODE == 'deploy') {
  643. wp_enqueue_script('js_files_for_wrapper', TDC_URL . '/assets/js/js_files_for_wrapper.min.js', array(
  644. 'jquery',
  645. 'backbone',
  646. 'underscore',
  647. 'shortcode' // the parser depends of wp.shortcode (shortcode.js wp file)
  648. ), TD_COMPOSER, true);
  649. } else {
  650. tdc_util::enqueue_js_files_array(tdc_config::$js_files_for_wrapper, array(
  651. 'jquery',
  652. 'backbone',
  653. 'underscore',
  654. 'shortcode' // the parser depends of wp.shortcode (shortcode.js wp file)
  655. ));
  656. }
  657. if ( true === TDC_USE_LESS ) {
  658. wp_enqueue_style('td_composer_edit', TDC_URL . '/td_less_style.css.php?part=wrap_main', false, TD_COMPOSER);
  659. } else {
  660. wp_enqueue_style('td_composer_edit', TDC_URL . '/assets/css/wrap_main.css', false, TD_COMPOSER);
  661. }
  662. remove_all_actions('admin_notices');
  663. remove_all_actions('network_admin_notices');
  664. // Disables all the updates notifications regarding plugins, themes & WordPress completely.
  665. tdc_disable_notification();
  666. require_once('templates/frontend.tpl.php');
  667. die;
  668. }
  669. /**
  670. * admin enqueue scripts
  671. */
  672. add_action( 'admin_enqueue_scripts', 'on_admin_enqueue_scripts'); // load them last
  673. function on_admin_enqueue_scripts() {
  674. foreach ( tdc_config::$font_settings as $font_id => $font_settings ) {
  675. if ( $font_id === 'font_newspaper' && 'Newsmag' === TD_THEME_NAME ) {
  676. continue;
  677. }
  678. if ( isset( $font_settings['theme_font'] ) ) {
  679. wp_enqueue_style( $font_id, get_stylesheet_directory_uri() . $font_settings['css_file'], false, TD_THEME_VERSION );
  680. continue;
  681. }
  682. wp_enqueue_style( $font_id, TDC_URL . $font_settings['css_file'], false, TD_COMPOSER );
  683. $file_path = plugin_dir_path( __FILE__ ) . 'templates/' . $font_settings['template_file'];
  684. if ( ! file_exists( $file_path ) ) {
  685. $handle_file = fopen( $file_path, 'w+');
  686. //check response
  687. if ( $handle_file !== false ) {
  688. switch ( $font_settings[ 'name' ] ) {
  689. case 'Font Awesome':
  690. case 'Typicons':
  691. case 'Open Iconic':
  692. case 'tagDiv Multi-purpose':
  693. $json_font_response = td_remote_http::get_page( TDC_URL . $font_settings[ 'css_file' ], __CLASS__ );
  694. if ( false === $json_font_response ) {
  695. td_log::log( __FILE__, __FUNCTION__, 'Failed to get font icons', $json_font_response );
  696. } else {
  697. preg_match_all( "/\.tdc-font-" . $font_settings[ 'family_class' ] . "-(.*)\:before/", $json_font_response, $output_array );
  698. if ( is_array( $output_array ) && count( $output_array ) ) {
  699. $response[ $font_id ][ 'classes' ] = $output_array[ 1 ];
  700. $span_icons = '';
  701. foreach ( $response[ $font_id ][ 'classes' ] as $font_class ) {
  702. $css_class = 'tdc-font-' . $font_settings[ 'family_class' ] . ' tdc-font-' . $font_settings[ 'family_class' ] . '-' . $font_class;
  703. $span_icons .= '<span data-font_class="' . $css_class . '"><i class="' . $css_class . '"></i></span>' . PHP_EOL;
  704. }
  705. fwrite( $handle_file, $span_icons );
  706. clearstatcache();
  707. }
  708. }
  709. break;
  710. }
  711. fclose( $handle_file );
  712. }
  713. }
  714. }
  715. }
  716. break;
  717. case 'tdc_edit':
  718. // Iframe content post
  719. add_filter( 'show_admin_bar', '__return_false' );
  720. add_filter( 'body_class', 'tdc_on_body_class' );
  721. function tdc_on_body_class( $classes ) {
  722. $classes[] = 'tdc-theme-' . TD_THEME_NAME;
  723. return $classes;
  724. }
  725. add_filter( 'the_content', function($content) {
  726. if ( ! function_exists( 'td_replace_vc_column_text' ) ) {
  727. function td_replace_vc_column_text( $matches ) {
  728. return '[vc_column_text' . $matches[ 1 ] . ']' . base64_encode( $matches[ 2 ] ) . '[/vc_column_text]';
  729. }
  730. }
  731. if ( shortcode_exists( 'vc_column_text' ) && has_shortcode( $content, 'vc_column_text' ) ) {
  732. // Double regex instead of one regex (preg_match and preg_replace_callback) - with one regex we need to parse content for replacing text, to supply what does the second regex
  733. // This first regex check is to allow second regex replacement to apply only when 'vc_column_text' has content
  734. preg_match("/\[vc_column_text(.*)\](.*)\[\/vc_column_text\]/sU", $content, $matches);
  735. if ( is_array( $matches ) && count( $matches ) ) {
  736. $content = preg_replace_callback( "/\[vc_column_text(.*)\](.*)\[\/vc_column_text\]/sU", 'td_replace_vc_column_text', $content );
  737. }
  738. }
  739. if ( ! function_exists( 'td_replace_td_block_text_with_title' ) ) {
  740. function td_replace_td_block_text_with_title( $matches ) {
  741. return '[td_block_text_with_title' . $matches[ 1 ] . ']' . base64_encode( $matches[ 2 ] ) . '[/td_block_text_with_title]';
  742. }
  743. }
  744. if ( shortcode_exists( 'td_block_text_with_title' ) && has_shortcode( $content, 'td_block_text_with_title' ) ) {
  745. // Double regex instead of one regex (preg_match and preg_replace_callback) - with one regex we need to parse content for replacing text, to supply what does the second regex
  746. // This first regex check is to allow second regex replacement to apply only when 'td_block_text_with_title' has content
  747. preg_match("/\[td_block_text_with_title(.*)\](.*)\[\/td_block_text_with_title\]/sU", $content, $matches);
  748. if ( is_array( $matches ) && count( $matches ) ) {
  749. $content = preg_replace_callback("/\[td_block_text_with_title(.*)\](.*)\[\/td_block_text_with_title\]/sU", 'td_replace_td_block_text_with_title', $content);
  750. }
  751. }
  752. return $content;
  753. }, 10, 1 );
  754. add_filter( 'the_content', 'tdc_on_the_content', 10000, 1 );
  755. function tdc_on_the_content( $content ) {
  756. if ( isset( $_POST['tdc_content'] ) ) {
  757. //echo $_POST['tdc_content'];die;
  758. //return $_POST['tdc_content'];
  759. return do_shortcode( stripslashes ( $_POST['tdc_content'] ) );
  760. }
  761. return $content;
  762. }
  763. add_filter( 'get_post_metadata', 'tdc_on_get_post_metadata', 10, 4 );
  764. function tdc_on_get_post_metadata( $value, $object_id, $meta_key, $single ) {
  765. tdc_state::set_customized_settings();
  766. if ( 'td_mega_menu_cat' === $meta_key || 'td_mega_menu_page_id' === $meta_key ) {
  767. // Look inside of the customized menu settings
  768. $customized_menu_settings = tdc_state::get_customized_menu_settings();
  769. if ( false !== $customized_menu_settings ) {
  770. foreach ( $customized_menu_settings as $key_menu_settings => $value_menu_settings ) {
  771. if ( isset($value_menu_settings[ $meta_key .'[' . $object_id . ']' ] ) ) {
  772. return $value_menu_settings[ $meta_key .'[' . $object_id . ']' ];
  773. }
  774. }
  775. }
  776. } else if ( 'td_homepage_loop' === $meta_key || 'td_page' === $meta_key ) {
  777. // Look inside of the customized page settings
  778. $customized_page_settings = tdc_state::get_customized_page_settings();
  779. if ( false !== $customized_page_settings ) {
  780. return array( $customized_page_settings[ $meta_key ] );
  781. }
  782. } else if ( '_wp_page_template' === $meta_key ) {
  783. $customized_page_settings = tdc_state::get_customized_page_settings();
  784. if ( false !== $customized_page_settings ) {
  785. return array( $customized_page_settings[ 'page_template' ] );
  786. }
  787. }
  788. return $value;
  789. }
  790. add_filter( 'wp_get_nav_menu_items', 'tdc_on_wp_get_nav_menu_items', 10, 3 );
  791. function tdc_on_wp_get_nav_menu_items( $items, $menu, $args ) {
  792. //var_dump($menu);
  793. tdc_state::set_customized_settings();
  794. $menu_settings = tdc_state::get_customized_menu_settings( $menu->term_id );
  795. if ( false !== $menu_settings ) {
  796. //var_dump($menu_settings);
  797. //return $items;
  798. $new_items = array();
  799. foreach ( $menu_settings as $key => $value) {
  800. if ( 0 === strpos( $key, 'menu-item-db-id' ) ) {
  801. $item = new stdClass();
  802. $item->ID = $value;
  803. $item->post_type = 'nav_menu_item';
  804. if ( isset($menu_settings[ "menu-item-object-id[$value]" ] ) ) {
  805. $item->object_id = $menu_settings[ "menu-item-object-id[$value]" ];
  806. }
  807. if ( isset($menu_settings[ "menu-item-object[$value]" ] ) ) {
  808. $item->object = $menu_settings[ "menu-item-object[$value]" ];
  809. }
  810. if ( isset($menu_settings[ "menu-item-parent-id[$value]" ] ) ) {
  811. $item->menu_item_parent = $menu_settings[ "menu-item-parent-id[$value]" ];
  812. }
  813. if ( isset($menu_settings[ "menu-item-type[$value]" ] ) ) {
  814. $item->type = $menu_settings[ "menu-item-type[$value]" ];
  815. }
  816. if ( isset($menu_settings[ "menu-item-title[$value]" ] ) ) {
  817. $item->title = $menu_settings[ "menu-item-title[$value]" ];
  818. }
  819. if ( isset($menu_settings[ "menu-item-url[$value]" ] ) ) {
  820. $item->url = $menu_settings[ "menu-item-url[$value]" ];
  821. }
  822. if ( isset($menu_settings[ "menu-item-title[$value]" ] ) ) {
  823. $item->title = $menu_settings[ "menu-item-title[$value]" ];
  824. $item->post_title = $item->title;
  825. }
  826. if ( isset($menu_settings[ "menu-item-attr-title[$value]" ] ) ) {
  827. $item->attr_title = $menu_settings[ "menu-item-attr-title[$value]" ];
  828. }
  829. if ( isset($menu_settings[ "menu-item-description[$value]" ] ) ) {
  830. $item->description = $menu_settings[ "menu-item-description[$value]" ];
  831. }
  832. if ( isset($menu_settings[ "menu-item-classes[$value]" ] ) ) {
  833. $item->classes = $menu_settings[ "menu-item-classes[$value]" ];
  834. }
  835. if ( isset($menu_settings[ "menu-item-xfn[$value]" ] ) ) {
  836. $item->xfn = $menu_settings[ "menu-item-xfn[$value]" ];
  837. }
  838. if ( isset($menu_settings[ "menu-item-position[$value]" ] ) ) {
  839. $item->menu_order = $menu_settings[ "menu-item-position[$value]" ];
  840. }
  841. if ( isset($menu_settings[ "menu-item-db-id[$value]" ] ) ) {
  842. $item->db_id = $menu_settings[ "menu-item-db-id[$value]" ];
  843. }
  844. if ( isset($menu_settings[ "td_mega_menu_cat[$value]" ] ) ) {
  845. $item->td_mega_menu_cat = $menu_settings[ "td_mega_menu_cat[$value]" ];
  846. }
  847. if ( isset($menu_settings[ "td_mega_menu_page_id[$value]" ] ) ) {
  848. $item->td_mega_menu_page_id = $menu_settings[ "td_mega_menu_page_id[$value]" ];
  849. }
  850. // CODE SECTION FROM wp customizer >>>
  851. $post = new WP_Post( (object) $item );
  852. if ( empty( $post->post_author ) ) {
  853. $post->post_author = get_current_user_id();
  854. }
  855. if ( ! isset( $post->type_label ) ) {
  856. if ( 'post_type' === $post->type ) {
  857. $object = get_post_type_object( $post->object );
  858. if ( $object ) {
  859. $post->type_label = $object->labels->singular_name;
  860. } else {
  861. $post->type_label = $post->object;
  862. }
  863. } elseif ( 'taxonomy' == $post->type ) {
  864. $object = get_taxonomy( $post->object );
  865. if ( $object ) {
  866. $post->type_label = $object->labels->singular_name;
  867. } else {
  868. $post->type_label = $post->object;
  869. }
  870. } else {
  871. $post->type_label = __( 'Custom Link' );
  872. }
  873. }
  874. /** This filter is documented in wp-includes/nav-menu.php */
  875. $post->attr_title = apply_filters( 'nav_menu_attr_title', $post->attr_title );
  876. /** This filter is documented in wp-includes/nav-menu.php */
  877. $post->description = apply_filters( 'nav_menu_description', wp_trim_words( $post->description, 200 ) );
  878. /** This filter is documented in wp-includes/nav-menu.php */
  879. $post = apply_filters( 'wp_setup_nav_menu_item', $post );
  880. // <<< CODE SECTION FROM wp customizer
  881. $new_items[] = $post;
  882. }
  883. }
  884. // CODE SECTION FROM wp customizer >>>
  885. foreach ( $new_items as $item ) {
  886. foreach ( get_object_vars( $item ) as $key => $value ) {
  887. $item->$key = $value;
  888. }
  889. }
  890. // <<< CODE SECTION FROM wp customizer
  891. //print_r($new_items);
  892. return $new_items;
  893. }
  894. return $items;
  895. }
  896. /**
  897. * iframe enqueue scripts
  898. */
  899. add_action( 'wp_enqueue_scripts', 'on_wp_enqueue_scripts_iframe', 1010); // load them last
  900. function on_wp_enqueue_scripts_iframe() {
  901. if (TDC_DEPLOY_MODE == 'deploy') {
  902. wp_enqueue_script('js_files_for_iframe', TDC_URL . '/assets/js/js_files_for_iframe.min.js', array(
  903. 'jquery',
  904. 'underscore'
  905. ), TD_COMPOSER, true);
  906. } else {
  907. tdc_util::enqueue_js_files_array(tdc_config::$js_files_for_iframe, array(
  908. 'jquery',
  909. 'underscore'
  910. ));
  911. }
  912. if ( true === TDC_USE_LESS ) {
  913. wp_enqueue_style('td_composer_iframe_main', TDC_URL . '/td_less_style.css.php?part=iframe_main', false, TD_COMPOSER);
  914. } else {
  915. wp_enqueue_style('td_composer_iframe_main', TDC_URL . '/assets/css/iframe_main.css', false, TD_COMPOSER);
  916. }
  917. }
  918. /**
  919. * Load all fonts in iframe, to be sure we have all fonts when a do_job callback finishes
  920. */
  921. add_action( 'get_footer', 'on_get_footer_load_all_fonts' );
  922. function on_get_footer_load_all_fonts() {
  923. foreach ( tdc_config::$font_settings as $font_id => $font_settings ) {
  924. if ( isset( $font_settings['theme_font'] ) ) {
  925. continue;
  926. }
  927. wp_enqueue_style( $font_id, TDC_URL . $font_settings['css_file'], false, TD_COMPOSER );
  928. }
  929. if ( td_util::get_check_installed_plugins() ) {
  930. ob_start();
  931. ?>
  932. <script>
  933. setTimeout(function() {
  934. window.top.tdConfirm.modal({
  935. caption: 'Did you disable any TagDiv plugins?',
  936. htmlInfoContent: "We've got some errors at loading API files. It could happen because of a disabled TagDiv plugin!",
  937. textYes: 'Ok',
  938. callbackYes: function () {
  939. window.top.tb_remove();
  940. },
  941. hideNoButton: true
  942. });
  943. }, 3000);
  944. </script>
  945. <?php
  946. echo ob_get_clean();
  947. }
  948. }
  949. break;
  950.  
  951. default:
  952. // Unknown td_action - kill execution
  953. echo 'Unknown td_action received: ' . $td_action;
  954. die;
  955. }
  956. }
  957. add_action('admin_head', 'on_admin_head_add_tdc_loader');
  958. function on_admin_head_add_tdc_loader() {
  959. if (!tdc_state::is_live_editor_iframe()) {
  960. return;
  961. }
  962. ?>
  963. <style>
  964. .tdc-fullscreen-loader-wrap {
  965. opacity: 1 !important;
  966. }
  967. </style>
  968.  
  969.  
  970. <div class="tdc-fullscreen-loader-wrap" style=""></div>
  971.  
  972. <?php
  973. }
  974. // Add the necessary scripts for css tab on widgets
  975. add_action( 'load-widgets.php', 'tdc_load_widget' );
  976. function tdc_load_widget() {
  977. if (td_util::tdc_is_installed()) {
  978. if (TDC_DEPLOY_MODE === 'deploy') {
  979. wp_enqueue_script('js_files_for_widget', TDC_URL . '/assets/js/js_files_for_widget.min.js', array(
  980. 'jquery',
  981. 'underscore',
  982. 'backbone'
  983. ), TD_COMPOSER, true);
  984. } else {
  985. // Load tdc js scripts needed for the css tab in the widget panel of the theme
  986. tdc_util::enqueue_js_files_array(tdc_config::$js_files_for_widget, array('jquery', 'underscore', 'backbone'));
  987. // wp_enqueue_script( 'tdcAdminIFrameUI', TDC_URL . '/assets/js/tdcAdminIFrameUI.js', array( 'underscore', 'backbone' ) );
  988. // wp_enqueue_script( 'tdcCssEditor', TDC_URL . '/assets/js/tdcCssEditor.js', array( 'underscore' ) );
  989. // wp_enqueue_script( 'tdcSidebarPanel', TDC_URL . '/assets/js/tdcSidebarPanel.js' );
  990. // wp_enqueue_script( 'tdcUtil', TDC_URL . '/assets/js/tdcUtil.js' );
  991. // wp_enqueue_script( 'tdcJobManager', TDC_URL . '/assets/js/tdcJobManager.js' );
  992. }
  993. // Add viewport intervals
  994. td_js_buffer::add_variable('td_viewport_interval_list', td_global::$td_viewport_intervals);
  995. // Load media
  996. add_action( 'admin_enqueue_scripts', 'on_load_widget_admin_enqueue_scripts' );
  997. function on_load_widget_admin_enqueue_scripts() {
  998. wp_enqueue_media();
  999. }
  1000. }
  1001. }
Add Comment
Please, Sign In to add comment