$template_id, 'title' => '', 'type' => $template_type, 'rows' => array(), 'css' => '', 'last_updated' => '', 'applied_table_ids' => array() ); if ($template_id) { if ($template_type === 'comparison_table') { $applied_ids = get_post_meta($template_id, '_affl_applied_table_ids', true); if (is_array($applied_ids)) { $template_data['applied_table_ids'] = array_map('intval', $applied_ids); } } // Custom fields for single_product will be loaded via AJAX } $navbar = new AffiliLabs_Navbar(); $navbar->load_scripts(); $button = new AffiliLabs_Button(); $modal = new AffiliLabs_Modal(); $modal->load_scripts(); $modal->init(); $spinner = new AffiliLabs_Spinner(); $spinner->load_scripts(); $spinner->init(); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-droppable'); wp_enqueue_style('affililabs-template-editor', AFFILILABS_TEMPLATE_EDITOR_CSS_URL, array(), AFFILILABS_VERSION); wp_add_inline_style('affililabs-template-editor', '.template-editor__module-icon img { width: 30px; height: 30px; }'); wp_enqueue_script('affililabs-template-editor', AFFILILABS_TEMPLATE_EDITOR_JS_URL, array('jquery'), AFFILILABS_VERSION, true); if ($template_type === 'comparison_table') { wp_enqueue_style('affililabs-comparison-table', AFFILILABS_COMPARISON_TABLE_SHORTCODE_CSS_URL, array(), AFFILILABS_VERSION); wp_enqueue_script('affililabs-comparison-table', AFFILILABS_COMPARISON_TABLE_SHORTCODE_JS_URL, array('jquery'), AFFILILABS_VERSION, true); } else if ($template_type === 'single_product') { wp_enqueue_style('affililabs-single-product', AFFILILABS_SINGLE_PRODUCT_TEMPLATE_CSS_URL, array(), AFFILILABS_VERSION); wp_enqueue_style('affililabs-shortcode-seal', AFFILILABS_SHORTCODE_SEAL_CSS_URL, array(), AFFILILABS_VERSION); } $products_options = array(); $products_args = array( 'post_type' => AFFILILABS_CPT_PRODUCT, 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ); $products_query = new WP_Query($products_args); if ($products_query->have_posts()) { while ($products_query->have_posts()) { $products_query->the_post(); $products_options[get_the_ID()] = get_the_title(); } wp_reset_postdata(); } $initial_preview_product_id = null; $comparison_tables_options = array(); $comparison_tables_args = array( 'post_type' => AFFILILABS_CPT_COMPARISON_TABLE, 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ); $comparison_tables_query = new WP_Query($comparison_tables_args); if ($comparison_tables_query->have_posts()) { while ($comparison_tables_query->have_posts()) { $comparison_tables_query->the_post(); $comparison_tables_options[get_the_ID()] = get_the_title(); } wp_reset_postdata(); } $initial_preview_table_id = null; $available_modules = array(); if ($template_type === 'comparison_table') { $available_modules = array( array( 'id' => 'star_rating', 'name' => __('Star Rating', 'affililabs'), 'description' => __('Show product rating with stars', 'affililabs'), 'icon' => AFFILILABS_ASSETS_STAR_SIMPLE_SVG ), array( 'id' => 'marketplace_logo', 'name' => __('Marketplace Logo', 'affililabs'), 'description' => __('Display marketplace logo', 'affililabs'), 'icon' => AFFILILABS_ASSETS_PRICE_TAG_SVG ), array( 'id' => 'price', 'name' => __('Price', 'affililabs'), 'description' => __('Show product price', 'affililabs'), 'icon' => AFFILILABS_ASSETS_DOLLAR_SVG ), array( 'id' => 'buy_button', 'name' => __('Buy Button', 'affililabs'), 'description' => __('Add a buy button with affiliate link', 'affililabs'), 'icon' => AFFILILABS_ASSETS_CART_FAST_SVG ), array( 'id' => 'criterias', 'name' => __('Criterias', 'affililabs'), 'description' => __('Display product criterias', 'affililabs'), 'icon' => AFFILILABS_ASSETS_CHECKLIST_SVG ), array( 'id' => 'rating_badge', 'name' => __('Rating Badge', 'affililabs'), 'description' => __('Show special rating badge (Best Price, etc.)', 'affililabs'), 'icon' => AFFILILABS_ASSETS_BADGE_SVG ) ); } else { $available_modules = array( array( 'id' => 'name', 'name' => __('Name', 'affililabs'), 'description' => __('Product name', 'affililabs'), 'icon' => AFFILILABS_ASSETS_DOCUMENT_SVG ), array( 'id' => 'image', 'name' => __('Image', 'affililabs'), 'description' => __('Product image', 'affililabs'), 'icon' => AFFILILABS_ASSETS_IMAGE_SVG ), array( 'id' => 'price', 'name' => __('Price', 'affililabs'), 'description' => __('Product price', 'affililabs'), 'icon' => AFFILILABS_ASSETS_DOLLAR_SVG ), array( 'id' => 'rating', 'name' => __('Rating', 'affililabs'), 'description' => __('Product rating', 'affililabs'), 'icon' => AFFILILABS_ASSETS_STAR_SIMPLE_SVG ), array( 'id' => 'description', 'name' => __('Description', 'affililabs'), 'description' => __('Product description', 'affililabs'), 'icon' => AFFILILABS_ASSETS_MEMO_SVG ), array( 'id' => 'features', 'name' => __('Features', 'affililabs'), 'description' => __('Product features list', 'affililabs'), 'icon' => AFFILILABS_ASSETS_CHECKLIST_SVG ), array( 'id' => 'pros', 'name' => __('Pros', 'affililabs'), 'description' => __('Product pros list', 'affililabs'), 'icon' => AFFILILABS_ASSETS_PLUS_CIRCLE_SVG ), array( 'id' => 'cons', 'name' => __('Cons', 'affililabs'), 'description' => __('Product cons list', 'affililabs'), 'icon' => AFFILILABS_ASSETS_CLOSE_SQUARE_SVG ), array( 'id' => 'button', 'name' => __('Button', 'affililabs'), 'description' => __('Affiliate link button', 'affililabs'), 'icon' => AFFILILABS_ASSETS_CART_FAST_SVG ), array( 'id' => 'criteria', 'name' => __('Criteria', 'affililabs'), 'description' => __('Product criteria', 'affililabs'), 'icon' => AFFILILABS_ASSETS_PENCIL_RULER_SVG ), array( 'id' => 'seal', 'name' => __('Seal', 'affililabs'), 'description' => __('Product seal', 'affililabs'), 'icon' => AFFILILABS_ASSETS_BADGE_SVG ), ); } wp_localize_script( 'affililabs-template-editor', 'affililabs_template_editor', array( 'template_id' => $template_id, 'template_type' => $template_type, 'modules' => $available_modules, 'applied_table_ids' => $template_data['applied_table_ids'], 'assets_url' => AFFILILABS_ASSETS_URL, 'sample_image_url' => AFFILILABS_ASSETS_IMAGE_SVG, 'nonce' => wp_create_nonce('affl_admin_nonce'), 'ajax_render_action' => $template_type === 'comparison_table' ? 'affl_render_table_preview' : 'affl_render_single_product_preview', 'initial_preview_table_id' => $initial_preview_table_id, 'initial_preview_product_id' => $initial_preview_product_id, 'i18n' => array( 'loading_preview' => __('Loading preview...', 'affililabs'), 'preview_error' => __('Error loading preview.', 'affililabs'), 'no_tables_found' => __('No comparison tables found to preview.', 'affililabs'), 'no_products_found' => __('No products found to preview.', 'affililabs'), 'select_table_preview' => __('Select Table to Preview:', 'affililabs'), 'select_product_preview' => __('Select Product to Preview:', 'affililabs'), 'load_success_title' => __('Success', 'affililabs'), 'load_success_message' => __('Template loaded successfully', 'affililabs'), 'save_success_title' => __('Success', 'affililabs'), 'save_success_message' => __('Template saved successfully', 'affililabs'), 'save_error_title' => __('Error', 'affililabs'), 'save_error_message' => __('Error saving template', 'affililabs'), 'delete_row_confirm' => __('Are you sure you want to delete this row?', 'affililabs'), 'delete_module_confirm' => __('Are you sure you want to remove this module?', 'affililabs'), 'drag_here' => __('Drag elements here to build your template', 'affililabs'), 'preview_updated' => __('Preview updated', 'affililabs'), 'template_name_required' => __('Please enter a template name', 'affililabs'), 'add_row' => __('Add Row', 'affililabs'), 'add_column' => __('Add Column', 'affililabs'), 'delete_row' => __('Delete Row', 'affililabs'), 'delete_column' => __('Delete Column', 'affililabs'), ) ) ); ?>