0, 'current' => 0, 'allow' => false, ]; public function get_id() { return 'custom'; } public function get_title() { return __( 'Custom', 'ele-custom-skin' ); } private function admin_bar_menu(){ foreach($this->used_templates as $post_id){ \ECS_Admin_Bar_Menu::add_document($post_id); } } protected function _register_controls_actions() { parent::_register_controls_actions(); add_action( 'elementor/element/posts/'.$this->get_id().'_section_design_layout/after_section_end', [ $this, 'register_navigation_design_controls' ] ); add_action( 'elementor/element/posts/section_pagination/after_section_end', [ $this, 'register_navigation_controls' ] ); } public function register_navigation_controls() { do_action( 'ECS_after_pagination_controls', $this ); } public function register_navigation_design_controls() { do_action( 'ECS_after_style_controls', $this ); } public function register_controls( Widget_Base $widget ) { $this->parent = $widget; $this->add_control( 'skin_template', [ 'label' => __( 'Select a default template', 'ele-custom-skin' ), 'description' => '
', 'type' => Controls_Manager::SELECT2, 'label_block' => true, 'default' => [], 'options' => $this->get_skin_template(), ] ); $this->add_control(//this would make use of 100% if width 'view', [ 'label' => __( 'View', 'ele-custom-skin' ), 'type' => \Elementor\Controls_Manager::HIDDEN, 'default' => 'top', 'prefix_class' => 'elementor-posts--thumbnail-', ] ); $this->add_control( 'use_custom_grid', [ 'label' => __( 'Use custom grid?', 'ele-custom-skin' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_off' => __( 'No', 'ele-custom-skin' ), 'label_on' => __( 'Yes', 'ele-custom-skin' ), 'return_value' => 'yes', 'separator' => 'before', 'default' =>'', ] ); $this->add_control( 'custom_grid', [ 'label' => __( 'Select a default template', 'ele-custom-skin' ), 'description' => '', 'type' => Controls_Manager::SELECT2, 'label_block' => true, 'default' => [], 'options' => $this->get_custom_grid(), 'condition' => [ $this->get_id().'_use_custom_grid' => 'yes' ], ] ); do_action( 'ECS_after_control', $this ); $this->add_control( 'hr2', [ 'type' => \Elementor\Controls_Manager::DIVIDER, ] ); parent::register_controls($widget); $this->remove_control( 'img_border_radius' ); $this->remove_control( 'meta_data' ); $this->remove_control( 'item_ratio' ); $this->remove_control( 'image_width' ); $this->remove_control( 'show_title' ); $this->remove_control( 'title_tag' ); $this->remove_control( 'masonry' ); $this->remove_control( 'thumbnail' ); $this->remove_control( 'thumbnail_size' ); $this->remove_control( 'show_read_more' ); $this->remove_control( 'read_more_text' ); $this->remove_control( 'show_excerpt' ); $this->remove_control( 'excerpt_length' ); $this->remove_control( 'open_new_tab' ); } private function get_post_id(){ return $this->pid; } public function get_skin_template(){ global $wpdb; $templates = $wpdb->get_results( "SELECT $wpdb->term_relationships.object_id as ID, $wpdb->posts.post_title as post_title FROM $wpdb->term_relationships INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_relationships.term_taxonomy_id=$wpdb->term_taxonomy.term_taxonomy_id INNER JOIN $wpdb->terms ON $wpdb->term_taxonomy.term_id=$wpdb->terms.term_id AND $wpdb->terms.slug='loop' INNER JOIN $wpdb->posts ON $wpdb->term_relationships.object_id=$wpdb->posts.ID WHERE $wpdb->posts.post_status='publish'" ); $options = [ 0 => 'Select a template' ]; foreach ( $templates as $template ) { $options[ $template->ID ] = $template->post_title; } return $options; } public function get_custom_grid(){ global $wpdb; $templates = $wpdb->get_results( "SELECT $wpdb->term_relationships.object_id as ID, $wpdb->posts.post_title as post_title FROM $wpdb->term_relationships INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_relationships.term_taxonomy_id=$wpdb->term_taxonomy.term_taxonomy_id INNER JOIN $wpdb->terms ON $wpdb->term_taxonomy.term_id=$wpdb->terms.term_id AND $wpdb->terms.slug='custom_grid' INNER JOIN $wpdb->posts ON $wpdb->term_relationships.object_id=$wpdb->posts.ID WHERE $wpdb->posts.post_status='publish'" ); $options = [ 0 => 'Select a template' ]; foreach ( $templates as $template ) { $options[ $template->ID ] = $template->post_title; } return $options; } public function render_amp() { } /*protected function set_template($skin){// this is for terms we don't need passid so we can actually add them in cache if (!$skin) return; if (isset($this->template_cache[$skin])) return $this->template_cache[$skin]; $return = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $skin ); $this->template_cache[$skin] = $return; }*/ protected function set_used_template($skin){// this is for terms we don't need passid so we can actually add them in cache if (!$skin) return; $this->used_templates[$skin]=$skin; } protected function set_custom_grid($grid){// this is for terms we don't need passid so we can actually add them in cache if (!$grid) return; $custom_grid = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $grid ); $this->set_used_template($grid); $this->grid = explode('{{ecs-article}}',$custom_grid); $this->grid_settings['length'] = count($this->grid); } public function get_grid(){ $grid=""; if($this->grid_settings['current'] >= $this->grid_settings['length']-1){ $grid.=$this->grid[$this->grid_settings['current']]; $this->grid_settings['current']=0; } // print_r($this->grid_settings); $grid.=$this->grid[$this->grid_settings['current']]; $grid.=""; $this->grid_settings['current']++; return $grid; } public function end_grid(){ if($this->grid_settings['current']) for($i = $this->grid_settings['current']; $i < $this->grid_settings['length'];$i++){ echo ""; echo $this->grid[$i]; echo ""; } $this->grid_settings['current'] = 0; } protected function get_template(){ global $ecs_render_loop, $wp_query,$ecs_index; $ecs_index++; $old_query=$wp_query; //\Elementor\Plugin::$instance->documents->switch_to_document( get_the_ID() ); //\Elementor\Plugin::$instance->db->switch_to_post( get_the_ID() ); $new_query=new \WP_Query( array( 'p' => get_the_ID(), 'post_type' => get_post_type() ) ); $wp_query = $new_query; $settings = $this->parent->get_settings(); $this->pid=get_the_ID();//set the current id in private var usefull to passid $default_template = $this->get_instance_value( 'skin_template' ) ; $template = $default_template; /* move to pro */ //print_r(ThemeBuilderModule::instance()->get_conditions_manager()->get_documents_for_location( 'loop' )); //print_r($this->conditions->get_template());echo "aici";print_r($template); $template = apply_filters( 'ECS_action_template', $template,$this,$ecs_index ); $template = $this->get_current_ID($template); $ecs_render_loop=get_the_ID().",".$template; //echo $ecs_render_loop; /* end pro */ if (!$template) return; $this->set_used_template($template); $return = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template ); $ecs_render_loop=false; //\Elementor\Plugin::$instance->documents->restore_document(); $wp_query = $old_query; return $return; } //this is for multilang porpouses... curently WPML private function get_current_ID($id){ $newid = apply_filters( 'wpml_object_id', $id, 'elementor_library', TRUE ); return $newid ? $newid : $id; } protected function render_post_header() { $classes = 'elementor-post elementor-grid-item ecs-post-loop'; $parent_settings = $this->parent->get_settings(); $parent_settings[$this->get_id().'_post_slider'] = isset($parent_settings[$this->get_id().'_post_slider'])? $parent_settings[$this->get_id().'_post_slider'] : ""; if($parent_settings[$this->get_id().'_post_slider'] == "yes") $classes .= ' swiper-slide'; if ($this->grid_settings['allow']) { echo $this->get_grid(); ?>