$tag, 'exp' => ! TD_TTW_User_Licenses::get_instance()->has_active_license( $tag ), 'gp' => TD_TTW_User_Licenses::get_instance()->is_in_grace_period( $tag ), 'show_lightbox' => TD_TTW_User_Licenses::get_instance()->show_gp_lightbox( $tag ), 'link' => tvd_get_individual_plugin_license_link( $tag ), 'product' => 'Thrive Ultimatum', ]; } return $attributes; }, 10, 2 ); /** * Ultimatum custom actions * * @param $action_tabs * * @return mixed */ function tve_ult_editor_actions( $action_tabs ) { $classes = tve_ult_load_action_classes( array() ); $post_id = get_the_ID(); if ( tve_ult_is_editable( $post_id ) ) { $action_tabs['custom']['actions']['tve_ult_close'] = array( 'class' => $classes['tve_ult_close'], 'order' => 20, 'available' => true, ); } return $action_tabs; } /** * Post visibility options blacklist * * @param $post_types * * @return array */ function tve_ult_post_visibility_options( $post_types ) { $post_types = array_merge( $post_types, array( TVE_Ult_Const::POST_TYPE_NAME_FOR_CAMPAIGN, TVE_Ult_Const::POST_TYPE_NAME_FOR_SCHEDULE, ) ); return $post_types; } /** * Ultimatum custom actions classes * * @param $actions * * @return mixed */ function tve_ult_load_action_classes( $actions ) { require_once dirname( __FILE__ ) . '/event-manager/actions/Thrive_Ultimatum_Form_Close_Action.php'; $actions['tve_ult_close'] = 'Thrive_Ultimatum_Form_Close_Action'; return $actions; } /** * Ultimatum templates * * @param array $templates * * @return array */ function tve_ult_editor_backbone_templates( $templates = array() ) { $templates = array_merge( $templates, tve_dash_get_backbone_templates( plugin_dir_path( dirname( __FILE__ ) ) . 'inc/backbone', 'backbone' ) ); return $templates; } /** * Check if the post can be edited by checking access and key * * @param $valid * * @return bool */ function tve_ult_user_can_use_plugin( $valid ) { if ( ! empty( $_REQUEST['post_id'] ) && tve_ult_is_editable( $_REQUEST['post_id'] ) ) { $valid = true; } if ( empty( $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ] ) ) { return $valid; } if ( ! TU_Product::has_access() ) { return false; } return true; } /** * Adds TU query string variation to preview link * * @param $preview_link * @param $post * * @return string */ function tve_ult_preview_post_link( $preview_link, $post ) { if ( tve_ult_is_editable( get_post_type( $post ) ) && ! empty( $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ] ) ) { $preview_link = add_query_arg( array( TVE_Ult_Const::DESIGN_QUERY_KEY_NAME => $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ], ), $preview_link ); } return $preview_link; } /** * Adds Ultimatum Product To TCB * * @param array $elements * * @return mixed */ function tve_ult_add_product_to_tcb( $elements = array() ) { $post_type = get_post_type(); if ( empty( $post_type ) || tve_ult_is_editable( $post_type ) ) { require_once TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-elements/class-tcb-ultimatum-shortcode-element.php' ); require_once TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-elements/class-tcb-ultimatum-bar-element.php' ); require_once TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-elements/class-tcb-ultimatum-widget-element.php' ); require_once TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-elements/class-tcb-ultimatum-close-bar-element.php' ); $elements['ultimatum_shortcode'] = new TCB_Ultimatum_Shortcode_Element( 'ultimatum_shortcode' ); $elements['ultimatum_bar'] = new TCB_Ultimatum_Bar_Element( 'ultimatum_bar' ); $elements['ultimatum_widget'] = new TCB_Ultimatum_Widget_Element( 'ultimatum_widget' ); if ( tve_ult_allow_cloud_templates() ) { $elements['ultimatum_close'] = new TCB_Ultimatum_Close_Bar_Element( 'ultimatum_close' ); } } else { require_once TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-elements/class-tcb-ultimatum-countdown-element.php' ); $elements['ultimatum_countdown'] = new TCB_Ultimatum_Countdown_Element( 'ultimatum_countdown' ); } return $elements; } /** * Disable Menu Layout For Some Elements in Ultimatum Editor * * @param string $menu_path * * @return bool|string */ function tve_ult_disable_menu_layouts( $menu_path = '' ) { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { return false; } return $menu_path; } /** * Disables all Countdown controls(except Color) on TU editor * * @param $controls * * @return mixed */ function tve_ult_disable_controls( $controls ) { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { $disabled_controls = array( '.tve-control:not([data-view="CountdownPalette"]):not([data-view="Color"]):not([data-view="Size"]):not([data-view="ShowSep"]):not([data-view="VisibleTiles"])', '.control-grid:not(.color-picker-control):not(.color-picker-input):not([data-view="VisibleTiles"] *):not([data-view="Size"] *):not([data-view="ShowSep"] *):not([data-view="CountdownPalette"] *)', ); if ( ! empty( $controls['countdown'] ) ) { $controls['countdown']['disabled_controls'] = $disabled_controls; } if ( ! empty( $controls['countdown_old'] ) ) { $controls['countdown_old']['disabled_controls'] = $disabled_controls; } } return $controls; } /** * Remove Elements Instances * * @param array $elements * * @return array */ function tve_ult_remove_element_instances( $elements = array() ) { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { /** * Remove Thrive Leads ShortCode */ if ( ! empty( $elements['tl_shortcode'] ) ) { unset( $elements['tl_shortcode'] ); } /** * Remove Quiz Builder ShortCode */ if ( ! empty( $elements['quiz'] ) ) { unset( $elements['quiz'] ); } } return $elements; } /** * Includes the Ultimatum Modal template files * * @param array $files existing modal files * * @return array */ function tve_ult_modal_files( $files = array() ) { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { if ( tve_ult_allow_cloud_templates() ) { $files[] = TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-lightbox/design-cloud-templates.php' ); } else { $files[] = TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-lightbox/design-templates.php' ); $files[] = TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-lightbox/design-reset.php' ); } $files[] = TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-lightbox/design-save.php' ); $files[] = TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-lightbox/add-edit-state.php' ); } else { $files[] = TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-lightbox/campaign-shotcodes.php' ); } return $files; } /** * Modifies Thrive Architect close URL when in Ultimatum Editor * * @param string $close_url * * @return string */ function tve_ult_tcb_close_url( $close_url = '' ) { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { $close_url = 'javascript:window.close();'; } return $close_url; } /** * Add some Ultimatum post types to Architect Post Grid Element Banned Types * * @param $banned_types * * @return array */ function tve_ult_tcb_add_post_grid_banned_types( $banned_types ) { $banned_types[] = TVE_Ult_Const::POST_TYPE_NAME_FOR_CAMPAIGN; $banned_types[] = TVE_Ult_Const::POST_TYPE_NAME_FOR_SCHEDULE; return $banned_types; } /** * Adds Extra Scripts to Main Frame */ function tve_ult_add_script_to_main_frame() { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { global $design; if ( empty( $design ) ) { $design = tve_ult_get_design( $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ] ); } $template_type = tve_ult_get_template_name( $design['post_type'] ); $allow_cloud_tpls = tve_ult_allow_cloud_templates(); $page_data = array( 'design_id' => $design['id'], 'post_id' => $design['post_parent'], 'tpl_action' => TVE_Ult_Const::ACTION_TEMPLATE, 'state_action' => TVE_Ult_Const::ACTION_STATE, 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'has_content' => ! empty( $design['content'] ), 'security' => wp_create_nonce( 'tve-ult-verify-track-sender-672' ), 'L' => array( 'fetching_saved_templates' => __( 'Fetching saved templates...', 'thrive-ult' ), 'tpl_name_required' => __( 'Please enter a template name, it will be easier to reload it after.', 'thrive-ult' ), 'tpl_existing_name' => __( 'That template name already exists, please use another name', 'thrive-ult' ), 'state_name_required' => __( 'Please enter a name for the state so you can easily identify it', 'thrive-ult' ), ), 'design_type' => $template_type, 'with_cloud_tpl' => $allow_cloud_tpls, ); if ( $allow_cloud_tpls ) { if ( empty( $design['content'] ) ) { $page_data['placeholder'] = tcb_template( 'elements/element-placeholder', array( 'icon' => $template_type, 'class' => 'tcb-ct-placeholder tve-ult-cloud-placeholder', 'title' => __( 'Insert template', 'thrive-ult' ), ), true ); } $page_data['saved_tpls'] = TU_Template_Manager::get_saved_templates_data( $template_type ); } tve_ult_enqueue_script( 'tve-ult-internal-editor', TVE_Ult_Const::plugin_url( 'tcb-bridge/assets/js/ult-tcb-internal.min.js' ), array( 'tve-main' ) ); wp_localize_script( 'tve-ult-internal-editor', 'tve_ult_page_data', $page_data ); tve_ult_enqueue_style( 'tve-ult-main-frame-css', TVE_Ult_Const::plugin_url( 'tcb-bridge/assets/css/main-frame.css' ) ); } else { tve_ult_enqueue_script( 'tve-ult-external-editor', TVE_Ult_Const::plugin_url( 'tcb-bridge/assets/js/ult-tcb-external.min.js' ), array( 'tve-main' ) ); $tve_ult_page_data = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'security' => wp_create_nonce( 'tve_ult_external_editor_ajax_request' ), ); $tve_ult_page_data = tve_ult_append_shortcode_campaigns( $tve_ult_page_data ); wp_localize_script( 'tve-ult-external-editor', 'tve_ult_page_data', $tve_ult_page_data ); } } /** * Return The HTML Code for displaying the Countdown Preview Inside TCB Editor */ function tve_ult_fetch_countdown_for_editor() { if ( ! check_ajax_referer( 'tve_ult_external_editor_ajax_request', '_nonce', false ) ) { header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found' ); echo esc_attr( __( 'Invalid request.', 'thrive-ult' ) ); wp_die(); } $design_id = ! empty( $_POST['tve_ult_shortcode'] ) ? intval( $_POST['tve_ult_shortcode'] ) : 0; if ( empty( $design_id ) ) { header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found' ); echo esc_attr( __( 'Invalid parameter: tve_ult_shortcode.', 'thrive-ult' ) ); wp_die(); } $design = tve_ult_get_design( $design_id ); $config = array( 'tve_ult_campaign' => $design['post_parent'], 'tve_ult_shortcode' => $design_id, ); $html = ''; $html .= '
'; $html .= str_replace( array( 'id="tve_editor"', 'tve_editor_main_content', ), '', tve_ult_render_shortcode( $config ) ); wp_send_json( $html ); } /** * Outputs Extra SVG Icons to editor page (Control Panel) */ function tve_ult_output_extra_control_panel_svg() { $post_type = get_post_type(); /** * Include this for all pages besides Ultimatum Pages */ if ( ! tve_ult_is_editable( $post_type ) ) { include TVE_Ult_Const::plugin_path( 'tcb-bridge/assets/css/fonts/ultimatum-main.svg' ); } } /** * Outputs Extra SVG Icons to editor page (Editor) */ function tve_ult_output_extra_iframe_svg() { $post_type = get_post_type(); /** * Include this for all pages besides Ultimatum Pages */ if ( ! tve_ult_is_editable( $post_type ) ) { include TVE_Ult_Const::plugin_path( 'tcb-bridge/assets/css/fonts/ultimatum-editor.svg' ); } } /** * Returns the new Ultimatum Countdown Component Menu path * * @return string */ function tve_ult_include_ultimatum_countdown_menu() { $post_type = get_post_type(); /** * Include this for all pages besides Ultimatum Pages */ if ( ! tve_ult_is_editable( $post_type ) ) { return TVE_Ult_Const::plugin_path( 'tcb-bridge/editor-layouts/menus/ultimatum-countdown.php' ); } } /** * Enables Template Tab in Settings Section * * @param bool $status * * @return bool */ function tve_ult_enable_template_tab( $status ) { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { return true; } return $status; } /** * Disable Revision Manager for Ultimatum Pages * * @param bool $status * * @return bool */ function tve_ult_disable_revision_manager( $status = true ) { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { return ! $status; } return $status; } /** * Disable Page Events for Ultimatum Pages * * @param bool $allow * * @return bool */ function tve_ult_disable_page_events( $allow = true ) { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { return false; } return $allow; } /** * Output the HTML for the Ultimatum form states */ function tve_ult_output_editor_states() { $post_type = get_post_type(); if ( tve_ult_is_editable( $post_type ) ) { $last_edited_state_key = get_post_meta( get_the_ID(), TVE_Ult_Const::META_PREFIX_NAME_FOR_EDIT_STATE . $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ], true ); if ( ! empty( $last_edited_state_key ) ) { $current_design = tve_ult_get_design( $last_edited_state_key ); } include TVE_Ult_Const::plugin_path( 'tcb-bridge/editor/states.php' ); } } //-------------------------------- /** * called when there is no active license for TCB, but it is installed and enabled * the function returns true only for pieces of content that "belong" to Thrive Ultimatum, so only the following: * * @param bool $value * * @return bool whether or not the current piece of content can be edited with TCB core functions */ function tve_ult_tcb_license_override( $value ) { /* this means that the license check should be skipped, possibly from thrive leads */ if ( $value ) { return true; } $post_type = get_post_type(); return tve_ult_is_editable( $post_type ); } /** * Checks if TU license if valid (only if the user is trying to edit a design) * * @param bool $valid * * @return bool */ function tve_ult_editor_check_license( $valid ) { if ( empty( $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ] ) ) { return $valid; } if ( ! tve_ult_license_activated() ) { add_action( 'wp_print_footer_scripts', 'tve_leads_license_warning' ); return false; } return true; } /** * Check if TCB version is valid * * @param bool $valid * * @return bool */ function tve_ult_editor_check_tcb_version( $valid ) { if ( empty( $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ] ) ) { return $valid; } if ( ! $valid ) { return false; } if ( ! tve_ult_check_tcb_version() ) { add_action( 'wp_print_footer_scripts', 'tve_ult_tcb_version_warning' ); return false; } return true; } /** * show a box with a warning message notifying the user to update the TCB plugin to the latest version * this will be shown only when the TCB version is lower than a minimum required version */ function tve_ult_tcb_version_warning() { return include TVE_Ult_Const::plugin_path( 'admin/views/tcb_version_incompatible.php' ); } /** * show a box with a warning message and a link to take the user to the license activation page * this will be called only when no valid / activated license has been found * * @return mixed */ function tve_ult_license_warning() { return include TVE_Ult_Const::plugin_path( 'admin/views/license_inactive.php' ); } /** * Callback for "tcb_custom_post_layouts" filter applied by TCB * * @param $current_templates * @param $post_id * @param $post_type * * @return array of layouts */ function tve_ult_editor_layout( $current_templates, $post_id, $post_type ) { global $design; if ( ! tve_ult_is_editable( $post_type ) ) { return $current_templates; } /* handles the following case: user refreshes the page when editing a child state - the child state should be directly opened after refresh */ if ( is_editor_page() ) { $last_edited_state_key = get_post_meta( $post_id, TVE_Ult_Const::META_PREFIX_NAME_FOR_EDIT_STATE . $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ], true ); if ( ! empty( $last_edited_state_key ) ) { $design = tve_ult_get_design( $last_edited_state_key ); } } if ( empty( $design ) ) { $design = tve_ult_get_design( $_GET[ TVE_Ult_Const::DESIGN_QUERY_KEY_NAME ] ); } if ( empty( $design ) ) { return $current_templates; } $current_templates['campaign_design'] = TVE_Ult_Const::plugin_path() . 'tcb-bridge/editor/campaign/' . TU_Template_Manager::type( $design['post_type'] ) . '.php'; if ( ! empty( $design[ TVE_Ult_Const::FIELD_TEMPLATE ] ) ) { $config = tve_ult_editor_get_template_config( $design[ TVE_Ult_Const::FIELD_TEMPLATE ] ); /* custom fonts for the design */ if ( ! empty( $config['fonts'] ) ) { foreach ( $config['fonts'] as $font ) { wp_enqueue_style( 'tve-ult-font-' . md5( $font ), $font ); } } /* include also the CSS for each design template */ if ( ! empty( $config['css'] ) ) { $css_handle = 'tve-ult-' . TU_Template_Manager::type( $design[ TVE_Ult_Const::FIELD_TEMPLATE ] ) . '-' . str_replace( '.css', '', $config['css'] ); tve_ult_enqueue_style( $css_handle, TVE_Ult_Const::plugin_url( 'tcb-bridge/editor-templates/css/' . TU_Template_Manager::type( $design['post_type'] ) . '/' . $config['css'] ) ); } /** * reset the design html to default */ if ( file_exists( TVE_Ult_Const::plugin_path( '.ui-develop' ) ) ) { $design[ TVE_Ult_Const::FIELD_CONTENT ] = tve_ult_editor_get_template_content( $design ); tve_ult_save_design( $design ); } } tve_ult_enqueue_style( 'tve-ult-design', TVE_Ult_Const::plugin_url( 'tcb-bridge/assets/css/editor.css' ) ); if ( ! is_editor_page() ) { //this is the preview page tve_ult_enqueue_default_scripts(); } $globals = ! empty( $design[ TVE_Ult_Const::FIELD_GLOBALS ] ) ? $design[ TVE_Ult_Const::FIELD_GLOBALS ] : array(); if ( ! empty( $globals['js_sdk'] ) ) { foreach ( $globals['js_sdk'] as $handle ) { $link = tve_social_get_sdk_link( $handle ); $js[ 'tve_js_sdk_' . $handle ] = $link; wp_script_is( 'tve_js_sdk_' . $handle ) || wp_enqueue_script( 'tve_js_sdk_' . $handle, $link, array(), false ); } } add_action( 'wp_enqueue_scripts', 'tve_ult_enqueue_design_scripts' ); return $current_templates; } /** * Check if a Thrive Ultimatum post is editable with TCB * * @param $post_or_type * string post type * int post it * * @return bool */ function tve_ult_is_editable( $post_or_type ) { $post_or_type = is_numeric( $post_or_type ) ? get_post_type( $post_or_type ) : $post_or_type; return in_array( $post_or_type, array( TVE_Ult_Const::POST_TYPE_NAME_FOR_CAMPAIGN, ) ); } /** * This is the main controller for editor and preview page * * @param array $design * @param array $is_editor_or_preview true if we are on the editor / preview page * * @return string */ function tve_ult_editor_custom_content( $design, $is_editor_or_preview = true ) { if ( empty( $design ) ) { return __( 'Design cannot be empty', 'thrive-ult' ); } $tve_saved_content = $design[ TVE_Ult_Const::FIELD_CONTENT ]; /** * if in editor page or preview, replace the data-date attribute for the countdown timers with the current_date + 1 day (just for demo purposes) */ if ( $is_editor_or_preview ) { $tomorrow = tve_ult_current_time( 'timestamp' ) + DAY_IN_SECONDS; $tve_saved_content = preg_replace( '#data-dd="(\d+)"#', '', $tve_saved_content ); $tve_saved_content = preg_replace( '#data-date="(\d+)-(\d+)-(\d+)"#', 'data-dd="2" data-date="' . date( 'Y-m-d', $tomorrow ) . '"', $tve_saved_content ); $tve_saved_content = preg_replace( '#data-hour="(\d+)"#', 'data-hour="' . date( 'H', $tomorrow ) . '"', $tve_saved_content ); $tve_saved_content = preg_replace( '#data-timezone="(.+?)"#', 'data-timezone="' . tve_ult_get_timezone_format() . '"', $tve_saved_content ); $tve_saved_content = preg_replace( '#data-min="(.+?)"#', 'data-min="' . date( 'i' ) . '"', $tve_saved_content ); } /* this will hold the html for the tinymce editor instantiation, only if we're on the editor page */ $tinymce_editor = $page_loader = ''; $is_editor_page = $is_editor_or_preview && tve_ult_is_editor_page(); /** * this means we are getting the content to output it on a targeted page => include also the custom CSS rules */ $custom_css = tve_ult_editor_output_custom_css( $design, true ); /** * style family class should always be Flat */ $style_family_class = 'tve_flt'; $style_family_id = $is_editor_or_preview ? ' id="' . $style_family_class . '" ' : ' '; $wrap = array( 'start' => '