first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,183 @@
<?php
use Elementor\Controls_Manager;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
class Jet_Woo_Builder_Archive_Document_Category extends Jet_Woo_Builder_Document_Base {
/**
* @access public
*/
public function get_name() {
return 'jet-woo-builder-category';
}
/**
* @access public
* @static
*/
public static function get_title() {
return __( 'Jet Woo Category Template', 'jet-woo-builder' );
}
protected function _register_controls() {
parent::_register_controls();
$this->start_controls_section(
'section_template_category_settings',
array(
'label' => esc_html__( 'Template Settings', 'jet-woo-builder' ),
'tab' => Controls_Manager::TAB_SETTINGS,
'show_label' => false,
)
);
$this->add_control(
'use_custom_template_category_columns',
array(
'label' => esc_html__( 'Use custom columns count', 'jet-woo-builder' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'jet-woo-builder' ),
'label_off' => esc_html__( 'No', 'jet-woo-builder' ),
'return_value' => 'yes',
'default' => '',
)
);
$this->add_responsive_control(
'template_category_columns_count',
array(
'label' => esc_html__( 'Template Columns', 'jet-woo-builder' ),
'type' => Controls_Manager::NUMBER,
'min' => 1,
'max' => 6,
'step' => 1,
'condition' => array(
'use_custom_template_category_columns' => 'yes'
)
)
);
$this->add_responsive_control(
'template_category_columns_horizontal_gutter',
array(
'label' => esc_html__( 'Template Columns Horizontal Gutter (px)', 'jet-woo-builder' ),
'type' => Controls_Manager::SLIDER,
'size_units' => array(
'px',
),
'range' => array(
'px' => array(
'min' => 0,
'max' => 100,
),
),
'default' => array(
'size' => 10,
'unit' => 'px',
),
'selectors' => array(
'.woocommerce {{WRAPPER}} ' . '.products.jet-woo-builder-categories--columns .product.product-category' => 'padding-left: calc({{SIZE}}{{UNIT}}/2); padding-right: calc({{SIZE}}{{UNIT}}/2);',
'.woocommerce {{WRAPPER}} ' . '.products.jet-woo-builder-categories--columns' => 'margin-left: calc(-{{SIZE}}{{UNIT}}/2); margin-right: calc(-{{SIZE}}{{UNIT}}/2);',
),
'condition' => array(
'use_custom_template_category_columns' => 'yes'
)
)
);
$this->add_responsive_control(
'template_category_columns_vertical_gutter',
array(
'label' => esc_html__( 'Template Columns Vertical Gutter (px)', 'jet-woo-builder' ),
'type' => Controls_Manager::SLIDER,
'size_units' => array(
'px',
),
'range' => array(
'px' => array(
'min' => 0,
'max' => 100,
),
),
'default' => array(
'size' => 10,
'unit' => 'px',
),
'selectors' => array(
'.woocommerce ' . '.products.jet-woo-builder-categories--columns .product.product-category' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
),
'condition' => array(
'use_custom_template_category_columns' => 'yes'
)
)
);
$this->end_controls_section();
}
/**
* @since 2.0.0
* @access public
*
* @param $data
*
* @return bool
*/
public function save( $data = [] ) {
return $this->save_archive_templates( $data );
}
/**
* @access public
*/
public function get_wp_preview_url() {
$main_post_id = $this->get_main_id();
$product_category = $this->query_first_category();
return add_query_arg(
array(
'preview_nonce' => wp_create_nonce( 'post_preview_' . $main_post_id ),
'jet_woo_template' => $main_post_id,
),
esc_url( get_category_link( $product_category ) )
);
}
public function get_preview_as_query_args() {
jet_woo_builder()->documents->set_current_type( $this->get_name() );
$args = array();
$product_category = $this->query_first_category();
if ( ! empty( $product_category ) ) {
$args = array(
'posts_per_page' => - 1,
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $product_category
)
)
);
}
return $args;
}
}

View File

@@ -0,0 +1,197 @@
<?php
use Elementor\Controls_Manager;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
class Jet_Woo_Builder_Archive_Document_Product extends Jet_Woo_Builder_Document_Base {
/**
* @access public
*/
public function get_name() {
return 'jet-woo-builder-archive';
}
/**
* @access public
* @static
*/
public static function get_title() {
return __( 'Jet Woo Archive Template', 'jet-woo-builder' );
}
/**
* @since 2.0.0
* @access protected
*/
protected function _register_controls() {
parent::_register_controls();
$this->start_controls_section(
'section_template_settings',
array(
'label' => esc_html__( 'Template Settings', 'jet-woo-builder' ),
'tab' => Controls_Manager::TAB_SETTINGS,
'show_label' => false,
)
);
$this->add_control(
'use_custom_template_columns',
array(
'label' => esc_html__( 'Use custom columns count', 'jet-woo-builder' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'jet-woo-builder' ),
'label_off' => esc_html__( 'No', 'jet-woo-builder' ),
'return_value' => 'yes',
'default' => '',
)
);
$this->add_responsive_control(
'template_columns_count',
array(
'label' => esc_html__( 'Template Columns', 'jet-woo-builder' ),
'type' => Controls_Manager::NUMBER,
'min' => 1,
'max' => 6,
'step' => 1,
'condition' => array(
'use_custom_template_columns' => 'yes'
)
)
);
$this->add_responsive_control(
'template_columns_horizontal_gutter',
array(
'label' => esc_html__( 'Template Columns Horizontal Gutter (px)', 'jet-woo-builder' ),
'type' => Controls_Manager::SLIDER,
'size_units' => array(
'px',
),
'range' => array(
'px' => array(
'min' => 0,
'max' => 100,
),
),
'default' => array(
'size' => 10,
'unit' => 'px',
),
'selectors' => array(
'.woocommerce {{WRAPPER}} ' . '.products.jet-woo-builder-products--columns .product:not(.product-category)' => 'padding-left: calc({{SIZE}}{{UNIT}}/2); padding-right: calc({{SIZE}}{{UNIT}}/2);',
'.woocommerce {{WRAPPER}} ' . '.products.jet-woo-builder-products--columns' => 'margin-left: calc(-{{SIZE}}{{UNIT}}/2); margin-right: calc(-{{SIZE}}{{UNIT}}/2);',
),
'condition' => array(
'use_custom_template_columns' => 'yes'
)
)
);
$this->add_responsive_control(
'template_columns_vertical_gutter',
array(
'label' => esc_html__( 'Template Columns Vertical Gutter (px)', 'jet-woo-builder' ),
'type' => Controls_Manager::SLIDER,
'size_units' => array(
'px',
),
'range' => array(
'px' => array(
'min' => 0,
'max' => 100,
),
),
'default' => array(
'size' => 10,
'unit' => 'px',
),
'selectors' => array(
'.woocommerce {{WRAPPER}} ' . '.products.jet-woo-builder-products--columns .product:not(.product-category)' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
),
'condition' => array(
'use_custom_template_columns' => 'yes'
)
)
);
$this->end_controls_section();
}
/**
* @since 2.0.0
* @access public
*
* @param $data
*
* @return bool
*/
public function save( $data = [] ) {
return $this->save_archive_templates( $data );
}
/**
* @since 2.0.0
* @access public
*
* @param $data
*
* @return bool
*/
/**
* @access public
*/
public function get_wp_preview_url() {
$main_post_id = $this->get_main_id();
$sample_product = get_post_meta( $main_post_id, '_sample_product', true );
if ( ! $sample_product ) {
$sample_product = $this->query_first_product();
}
$product_id = $sample_product;
return add_query_arg(
array(
'preview_nonce' => wp_create_nonce( 'post_preview_' . $main_post_id ),
'jet_woo_template' => $main_post_id,
),
get_permalink( $product_id )
);
}
/**
* Return preview query args
* @return array
*/
public function get_preview_as_query_args() {
jet_woo_builder()->documents->set_current_type( $this->get_name() );
$args = array();
$product = $this->query_first_product();
if ( ! empty( $product ) ) {
$args = array(
'post_type' => 'product',
'p' => $product,
);
}
return $args;
}
}

View File

@@ -0,0 +1,54 @@
<?php
use Elementor\Controls_Manager;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
class Jet_Woo_Builder_Shop_Document extends Jet_Woo_Builder_Document_Base {
/**
* @access public
*/
public function get_name() {
return 'jet-woo-builder-shop';
}
/**
* @access public
* @static
*/
public static function get_title() {
return __( 'Jet Woo Shop Template', 'jet-woo-builder' );
}
public function get_preview_as_query_args() {
jet_woo_builder()->documents->set_current_type( $this->get_name() );
$args = array();
$products = get_posts( array(
'post_type' => 'product',
'posts_per_page' => 5,
) );
if ( ! empty( $products ) ) {
$args = array(
'post_type' => 'product',
'p' => $products,
);
}
wc_set_loop_prop( 'total', 20 );
wc_set_loop_prop( 'total_pages', 3 );
return $args;
}
}

View File

@@ -0,0 +1,228 @@
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
class Jet_Woo_Builder_Document_Base extends Elementor\Core\Base\Document {
public $first_product = null;
public $first_category = null;
/**
* @access public
*/
public function get_name() {
return 'jet-woo-builder-archive-document';
}
public static function get_properties() {
$properties = parent::get_properties();
$properties['admin_tab_group'] = '';
return $properties;
}
/**
* Query for first product ID.
*
* @return int|bool
*/
public function query_first_product() {
if ( null !== $this->first_product ) {
return $this->first_product;
}
$args = array(
'post_type' => 'product',
'post_status' => array( 'publish', 'pending', 'draft', 'future' ),
'posts_per_page' => 1,
);
$sample_product = get_post_meta( $this->get_main_id(), '_sample_product', true );
if ( $sample_product ) {
$args['p'] = $sample_product;
}
$wp_query = new WP_Query( $args );
if ( ! $wp_query->have_posts() ) {
return false;
}
$post = $wp_query->posts;
return $this->first_product = $post[0]->ID;
}
/**
* Query for first product ID.
*
* @return int|bool
*/
public function query_first_category() {
if ( null !== $this->first_category ) {
return $this->first_category;
}
$product_categories = get_categories( array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'pad_counts' => false,
'hierarchical' => 1,
'hide_empty' => false
) );
if ( ! empty( $product_categories ) ) {
$product_category = $product_categories[0];
}
return $this->first_category = $product_category->term_id;
}
/**
* Save meta for current post
* @param $post_id
*/
public function save_template_item_to_meta( $post_id ) {
$content = Elementor\Plugin::instance()->frontend->get_builder_content( $post_id, false );
$content = preg_replace( '/<style>.*?<\/style>/', '', $content );
update_post_meta( $post_id, '_jet_woo_builder_content', $content );
}
public function enqueue_custom_fonts_epro( $post_css ){
if( class_exists( 'ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\Custom_Fonts' ) ){
$custom_fonts_manager = new ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\Custom_Fonts();
$fonts = $custom_fonts_manager->get_fonts();
if( !empty( $fonts ) ){
foreach ( $fonts as $font => $font_data ){
$custom_fonts_manager->enqueue_font( $font, $font_data, $post_css );
}
}
}
}
/**
* Save data for archive document types
*
* @param array $data
*
* @return bool
*/
public function save_archive_templates( $data = [] ){
if ( ! $this->is_editable_by_current_user() || empty( $data ) ) {
return false;
}
if ( ! empty( $data['settings'] ) ) {
if ( Elementor\DB::STATUS_AUTOSAVE === $data['settings']['post_status'] ) {
if ( ! defined( 'DOING_AUTOSAVE' ) ) {
define( 'DOING_AUTOSAVE', true );
}
}
$this->save_settings( $data['settings'] );
//Refresh post after save settings.
$this->post = get_post( $this->post->ID );
}
if ( ! empty( $data['elements'] ) ) {
$this->save_elements( $data['elements'] );
}
$this->save_template_type();
$this->save_version();
$this->save_template_item_to_meta( $this->post->ID );
// Update Post CSS
$post_css = new Elementor\Core\Files\CSS\Post( $this->post->ID );
$this->enqueue_custom_fonts_epro( $post_css );
$post_css->update();
return true;
}
/**
* Get elements data with new query
*
* @param [type] $data [description]
* @param boolean $with_html_content [description]
*
* @return [type] [description]
*/
public function get_elements_raw_data( $data = null, $with_html_content = false ) {
jet_woo_builder()->documents->switch_to_preview_query();
$editor_data = parent::get_elements_raw_data( $data, $with_html_content );
jet_woo_builder()->documents->restore_current_query();
return $editor_data;
}
/**
* Render current element
* @param $data
*
* @return string
* @throws Exception
*/
public function render_element( $data ) {
jet_woo_builder()->documents->switch_to_preview_query();
$render_html = parent::render_element( $data );
jet_woo_builder()->documents->restore_current_query();
return $render_html;
}
/**
* Return elements data
* @param string $status
*
* @return array
*/
public function get_elements_data( $status = 'publish' ) {
if ( ! isset( $_GET[ jet_woo_builder_post_type()->slug() ] ) || ! isset( $_GET['preview'] ) ) {
return parent::get_elements_data( $status );
}
jet_woo_builder()->documents->switch_to_preview_query();
$elements = parent::get_elements_data( $status );
jet_woo_builder()->documents->restore_current_query();
return $elements;
}
}

View File

@@ -0,0 +1,75 @@
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
class Jet_Woo_Builder_Document extends Jet_Woo_Builder_Document_Base {
/**
* @access public
*/
public function get_name() {
return 'jet-woo-builder';
}
/**
* @access public
* @static
*/
public static function get_title() {
return __( 'Jet Woo Template Single', 'jet-woo-builder' );
}
/**
* @access public
*/
public function get_wp_preview_url() {
$main_post_id = $this->get_main_id();
$sample_product = get_post_meta( $main_post_id, '_sample_product', true );
if ( ! $sample_product ) {
$sample_product = $this->query_first_product();
}
$product_id = $sample_product;
return add_query_arg(
array(
'preview_nonce' => wp_create_nonce( 'post_preview_' . $main_post_id ),
'jet_woo_template' => $main_post_id,
),
get_permalink( $product_id )
);
}
/**
* Return preview query args
*
* @return array
*/
public function get_preview_as_query_args() {
jet_woo_builder()->documents->set_current_type( $this->get_name() );
$args = array();
$product = $this->query_first_product();
if ( ! empty( $product ) ) {
$args = array(
'post_type' => 'product',
'p' => $product,
);
}
return $args;
}
}

View File

@@ -0,0 +1,45 @@
<?php
//use Elementor\Controls_Manager;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
class Jet_Woo_Builder_Document_Not_Supported extends Elementor\Modules\Library\Documents\Not_Supported {
/**
* Get document properties.
*
* Retrieve the document properties.
*
* @access public
* @static
*
* @return array Document properties.
*/
public static function get_properties() {
$properties = parent::get_properties();
$properties['cpt'] = [ 'jet-woo-builder' ];
return $properties;
}
/**
* Get document name.
*
* Retrieve the document name.
*
* @access public
*
* @return string Document name.
*/
public function get_name() {
return 'jet-woo-builder-not-supported';
}
public function save_template_type() {
// Do nothing.
}
}