ID = (int) $symbol_id; $this->post = get_post( $symbol_id ); } /** * Stores symbol types that contain states * * @var string[] */ public static $symbol_with_states = [ 'header' ]; /** * Render the symbol content * * @param array $config * @param bool $do_shortcodes * * @return mixed|string */ public static function render_content( $config = [], $do_shortcodes = false ) { static::enter_symbol_render(); $symbol_id = ( ! empty( $config ) && isset( $config['id'] ) ) ? $config['id'] : get_the_ID(); $content = static::content( $symbol_id ); /* prepare Events configuration */ tve_parse_events( $content ); /** * Filter that allows skipping `do_shortcode` in various cases. Example: when exporting a symbol, do_shortcode should NOT be called, * even though `wp_doing_ajax() === true` * * @param bool $do_shortcodes initial value * @param int $symbol_id current symbol ID * @param array $config configuration object passed to the method * * @return bool whether or not it should execute the shortcode functions */ $do_shortcodes = apply_filters( 'tcb_symbol_do_shortcodes', wp_doing_ajax() || $do_shortcodes, $symbol_id, $config ); if ( $do_shortcodes ) { $content = shortcode_unautop( $content ); $GLOBALS['symbol_id'] = $symbol_id; $content = do_shortcode( $content ); unset( $GLOBALS['symbol_id'] ); //apply thrive shortcodes $keep_config = isset( $config['tve_shortcode_config'] ) ? $config['tve_shortcode_config'] : true; $content = tve_thrive_shortcodes( $content, $keep_config ); /* render the content added through WP Editor (element: "WordPress Content") */ $content = tve_do_wp_shortcodes( $content, is_editor_page() ); } /** * This only needs to be executed on frontend. Do not execute it in the editor page or when ajax-loading the symbols in the editor */ if ( ! is_editor_page() && ! wp_doing_ajax() ) { $content = tve_restore_script_tags( $content ); /** * IF yoast is active do not store the parsed styles in the global cache - it will mess up the post queries */ $yoast_seo_active = is_plugin_active( 'wordpress-seo/wp-seo.php' ); $content = tve_get_shared_styles( $content, '', true, ! $yoast_seo_active ) . $content; //Removes the color palette configuration code from the symbol in frontend $content = tcb_clean_frontend_content( $content ); //if it has custom icons make sure that font family is loaded if ( tve_get_post_meta( $symbol_id, 'thrive_icon_pack' ) ) { TCB_Icon_Manager::enqueue_icon_pack(); } } $content = apply_filters( 'tcb_symbol_template', $content ); $content = preg_replace( '!\s+!', ' ', $content ); static::exit_symbol_render(); return $content; } /** * Include the start of the html content */ public static function body_open() { include TVE_TCB_ROOT_PATH . 'inc/views/symbols/symbol-body-open.php'; } /** * Include the end of the html content */ public static function body_close() { include TVE_TCB_ROOT_PATH . 'inc/views/symbols/symbol-body-close.php'; } /** * Get the content from the symbol * * @param int $symbol_id * * @return mixed|string */ public static function content( $symbol_id ) { $content = get_post_meta( (int) $symbol_id, 'tve_updated_post', true ); return apply_filters( 'tcb_symbol_content', $content ); } /** * Get css for symbol * * @param $config * * @return string */ public static function tcb_symbol_get_css( $config ) { $symbol_id = ( ! empty( $config ) && isset( $config['id'] ) ) ? $config['id'] : 0; $css = "'; $lightspeed = Css::get_instance( $symbol_id ); if ( $lightspeed->should_load_optimized_styles() ) { $css = $lightspeed->get_optimized_styles() . $css; } else { Css::enqueue_flat(); } return $css; } /** * Get the css for a symbol * * @param int $id * * @return mixed|string */ public static function css( $id ) { $css = trim( get_post_meta( (int) $id, 'tve_custom_css', true ) ); $css = TCB\Lightspeed\Fonts::parse_google_fonts( $css ); /* If we want to change the symbol css just before is being inserted in the page */ $css = apply_filters( 'tcb_symbol_css_before', $css, $id ); return tve_prepare_global_variables_for_front( $css ); } /** * @param $symbol_type * * @return string */ public static function symbol_state_class( $symbol_type ) { $cls = ''; if ( in_array( $symbol_type, static::$symbol_with_states, true ) ) { $cls = 'tve-default-state'; } return $cls; } /** * Render symbol shortcode content * * @param array $config * @param boolean $wrap * * @return string */ public static function symbol_render_shortcode( $config, $wrap = false ) { $content = ''; if ( ! empty( $config['id'] ) ) { $symbol_id = $config['id']; $post = get_post( $symbol_id ); if ( $post instanceof WP_Post && $post->post_status === 'publish' ) { $content = static::render_content( $config, $wrap ); $css = static::tcb_symbol_get_css( $config ); $type = substr( TCB_Symbols_Taxonomy::get_symbol_type( $symbol_id ), 0, - 1 ); $js_modules = ''; if ( TCB_Utils::is_rest() || wp_doing_ajax() ) { /* we should return this inline when we retrieve the symbol with ajax */ $js_modules = JS::get_instance( $symbol_id )->load_modules( true ); } else { JS::get_instance( $symbol_id )->enqueue_scripts(); } /** * forcing this type allows knowing better whether is a gutenberg block */ if ( strpos( $type, 'gutenberg' ) !== false ) { $type = 'gutenberg_block'; } $shortcode_class = in_array( $type, static::$symbol_with_states, true ) ? 'tve-default-state' : ''; $name = is_editor_page_raw() ? ' data-name="' . esc_attr( $post->post_title ) . '"' : ''; $content = '