array( 'name' => esc_html__( 'Slider', 'mega' ), 'description' => esc_html__( 'Slider block', 'mega' )), 'before' => '
', 'after' => '
', 'class_base' => $class_base ); $this->animations = array( 'fade' => array( 'name' => esc_html__( 'Fade', 'mega' ), 'in' => 'fadeIn', 'out' => false ), 'slidedownflipin' => array( 'name' => esc_html__( 'Slide out down - Flip in', 'mega' ), 'in' => 'flipInX', 'out' => 'slideOutDown' ), 'slideinright' => array( 'name' => esc_html__( 'Slide in right', 'mega' ), 'in' => 'slideInRight', 'out' => 'slideOutLeft' ) ); add_filter( 'mega_form_select_lists', array( $this, 'addList' )); add_filter( 'mega_slider_anim_list', array( $this, 'doList' )); parent::__construct( $class, $args ); } public function settings( $form ) { $form->add_section( 'mega_block_slider_section', array( 'title' => esc_html__( 'Settings', 'mega' ), 'panel' => 'mega_slider' )); $form->add_control( 'Mega_Control_onOff', array( 'label' => esc_html__( 'Show Slider', 'mega' ), 'value' => 1, 'name' => 'show_slider' )); $form->add_sub_control( 'Mega_Control_Checklist', array( 'control' => 'show_slider', 'control_value' => 'true', 'label' => esc_html__( 'Slider Location', 'mega' ), 'value' => array( 'template-home.php' => 1, 'category' => 0, 'archive' => 0, 'post' => 0, 'template-contact.php' => 0, 'page' => 0 ), 'name' => 'location', 'use_list' => 1, 'list' => 'mega_template_2_list' )); $form->add_control( 'Mega_Control_Select', array( 'label' => esc_html__( 'Auto Pull or Custom', 'mega' ), 'value' => 'auto', 'name' => 'source', 'choices' => array( 'auto' => esc_html__( 'Auto Pull', 'mega' ), 'custom' => esc_html__( 'Custom', 'mega' ) ) )); $form->add_control( 'Mega_Control_Select', array( 'label' => esc_html__( 'Slider Animation', 'mega' ), 'value' => 'default', 'pro' => 1, 'name' => 'auto_animation', 'use_list' => 1, 'list' => 'mega_slider_anim_list' )); $form->add_control( 'Mega_Control_onOff', array( 'label' => esc_html__( 'Navigation', 'mega' ), 'value' => 1, 'name' => 'nav' )); $form->add_control( 'Mega_Control_onOff', array( 'label' => esc_html__( 'Auto Play', 'mega' ), 'value' => 1, 'name' => 'auto' )); $form->add_control( 'Mega_Control_onOff', array( 'label' => esc_html__( 'Pause on hover', 'mega' ), 'value' => 1, 'name' => 'pause' )); $form->add_control( 'Mega_Control_onOff', array( 'label' => esc_html__( 'Loop', 'mega' ), 'value' => 1, 'name' => 'loop' )); $form->add_control( 'Mega_Control_Number', array( 'label' => esc_html__( 'Slide Time (miliseconds)', 'mega' ), 'value' => 8000, 'name' => 'time' )); $form->add_sub_control( 'Mega_Control_Select', array( 'control' => 'source', 'control_value' => 'auto', 'label' => esc_html__( 'Pages, Posts or Category Posts', 'mega' ), 'value' => 'posts', 'name' => 'type', 'choices' => array( 'cats' => esc_html__( 'Category Posts', 'mega' ), 'posts' => esc_html__( 'Posts', 'mega' ), 'pages' => esc_html__( 'Pages', 'mega' ) ) )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'type', 'control_value' => 'cats', 'label' => esc_html__( 'Category Posts - Number of Results', 'mega' ), 'value' => 1, 'name' => 'count' )); $form->add_sub_control( 'Mega_Control_Select', array( 'control' => 'type', 'control_value' => 'cats', 'label' => esc_html__( 'Select a Category', 'mega' ), 'name' => 'cat', 'use_list' => 1, 'list' => 'mega_cat_list' )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'type', 'control_value' => 'pages', 'label' => esc_html__( 'Random Page', 'mega' ), 'value' => 1, 'name' => 'rand_pages' )); $form->add_sub_control( 'Mega_Control_Checklist', array( 'control' => 'rand_pages', 'control_value' => 'false', 'label' => esc_html__( 'Select Pages', 'mega' ), 'value' => array( 0 => 1 ), 'name' => 'pages', 'use_list' => 1, 'list' => 'mega_page_list' )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'type', 'control_value' => 'posts', 'label' => esc_html__( 'Random Post', 'mega' ), 'value' => 1, 'name' => 'rand_posts' )); $form->add_sub_control( 'Mega_Control_Checklist', array( 'control' => 'rand_posts', 'control_value' => 'false', 'label' => esc_html__( 'Select Posts', 'mega' ), 'value' => array( 0 => 1 ), 'name' => 'posts', 'use_list' => 1, 'list' => 'mega_post_list' )); $form->add_sub_control( 'Mega_Control_Select', array( 'control' => 'source', 'control_value' => 'auto', 'label' => esc_html__( 'Order By', 'mega' ), 'value' => 'date', 'name' => 'order', 'choices' => array( 'date' => esc_html__( 'Date', 'mega' ), 'rand' => esc_html__( 'Random', 'mega' ), 'comment_count' => esc_html__( 'Comment Count', 'mega' ) ) )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'source', 'control_value' => 'auto', 'label' => esc_html__( 'Title', 'mega' ), 'value' => 1, 'name' => 'show_title' )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'show_title', 'control_value' => 'true', 'label' => esc_html__( 'Title Character Count', 'mega' ), 'value' => 35, 'name' => 'title_count' )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'source', 'control_value' => 'auto', 'label' => esc_html__( 'Excerpt Character Count', 'mega' ), 'value' => 110, 'name' => 'excerpt_count' )); $form->add_sub_control( 'Mega_Control_Select', array( 'control' => 'source', 'control_value' => 'auto', 'label' => esc_html__( 'Alignment', 'mega' ), 'value' => 'center', 'name' => 'auto_alignment', 'choices' => array( 'top' => esc_html__( 'Top Center', 'mega' ), 'center'=> esc_html__( 'Center', 'mega' ), 'left' => esc_html__( 'Left', 'mega' ), 'right' => esc_html__( 'Right', 'mega' ) ) )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'auto_alignment', 'control_value' => 'center', 'label' => esc_html__( 'Cover Effect', 'mega' ), 'value' => 0, 'name' => 'auto_cover' )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'source', 'control_value' => 'auto', 'label' => esc_html__( 'Image', 'mega' ), 'value' => 1, 'name' => 'auto_image' )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'auto_image', 'control_value' => 'true', 'label' => esc_html__( 'Image Width (px)', 'mega' ), 'name' => 'auto_image_width' )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'auto_image', 'control_value' => 'true', 'label' => esc_html__( 'Image Height (px)', 'mega' ), 'name' => 'auto_image_height' )); $form->add_sub_control( 'Mega_Control_Checklist', array( 'control' => 'auto_image', 'control_value' => 'true', 'label' => esc_html__( 'Image Sources', 'mega' ), 'value' => array( 'featured' => 1, 'first' => 1, 'ph' => 1 ), 'name' => 'auto_image_sources', 'choices' => array( 'featured' => esc_html__( 'Featured', 'mega' ), 'first' => esc_html__( 'First', 'mega' ), 'ph' => esc_html__( 'Placeholder', 'mega' ) ) )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'source', 'control_value' => 'auto', 'label' => esc_html__( 'Link', 'mega' ), 'value' => 1, 'name' => 'show_link' )); $range = range( 1, 4 ); foreach ( $range as $n ) : $form->add_section( 'mega_block_slider_custom_' . $n . '_section', array( 'title' => sprintf( esc_html__( 'Custom %s', 'mega' ), $n ), 'panel' => 'mega_slider' )); $form->section = 'mega_block_slider_custom_' . $n . '_section'; $form->add_control( 'Mega_Control_onOff', array( 'label' => sprintf( esc_html__( 'Custom %s', 'mega' ), $n ), 'value' => 0, 'name' => 'custom_' . $n )); $form->add_sub_control( 'Mega_Control_Select', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Alignment', 'mega' ), 'value' => 'center', 'name' => 'custom_' . $n . '_alignment', 'choices' => array( 'top' => esc_html__( 'Top Center', 'mega' ), 'center'=> esc_html__( 'Center', 'mega' ), 'left' => esc_html__( 'Left', 'mega' ), 'right' => esc_html__( 'Right', 'mega' ) ) )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'custom_' . $n . '_alignment', 'control_value' => 'center', 'label' => esc_html__( 'Cover Effect', 'mega' ), 'value' => 0, 'name' => 'custom_' . $n . '_cover' )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Image', 'mega' ), 'value' => 1, 'name' => 'custom_' . $n . '_image' )); $form->add_sub_control( 'Mega_Control_Text', array( 'control' => 'custom_' . $n . '_image', 'control_value' => 'true', 'label' => esc_html__( 'Image URL', 'mega' ), 'name' => 'custom_' . $n . '_image_url' )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'custom_' . $n . '_image', 'control_value' => 'true', 'label' => esc_html__( 'Image Width (px)', 'mega' ), 'name' => 'custom_' . $n . '_width' )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'custom_' . $n . '_image', 'control_value' => 'true', 'label' => esc_html__( 'Image Height (px)', 'mega' ), 'name' => 'custom_' . $n . '_height' )); $form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'custom_' . $n . '_image', 'control_value' => 'true', 'label' => esc_html__( 'Show Placeholder', 'mega' ), 'pro' => 1, 'value' => 1, 'name' => 'custom_' . $n . '_show_placeholder' )); $form->add_sub_control( 'Mega_Control_Text', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Title', 'mega' ), 'name' => 'custom_' . $n . '_title' )); $form->add_sub_control( 'Mega_Control_Text', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Link', 'mega' ), 'value' => '#', 'name' => 'custom_' . $n . '_link' )); $form->add_sub_control( 'Mega_Control_WP_Editor', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Content', 'mega' ), 'tinymce' => 1, 'name' => 'custom_' . $n . '_text' )); $form->add_sub_control( 'Mega_Control_Text', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Button label', 'mega' ), 'name' => 'custom_' . $n . '_button_label' )); $form->add_sub_control( 'Mega_Control_Text', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Background Image URL', 'mega' ), 'name' => 'custom_' . $n . '_bg_image_url' )); $form->add_sub_control( 'Mega_Control_Text', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Background Gradient Top', 'mega' ), 'name' => 'custom_' . $n . '_bg_top' )); $form->add_sub_control( 'Mega_Control_Text', array( 'control' => 'custom_' . $n, 'control_value' => 'true', 'label' => esc_html__( 'Background Gradient Bottom', 'mega' ), 'name' => 'custom_' . $n . '_bg_bottom' )); endforeach; unset( $form->section ); } public function addList( $lists ) { $lists['mega_slider_anim_list'] = esc_html__( 'Slider Animation List', 'mega' ); return $lists; } public function doList() { $data['default'] = esc_html__( 'Default', 'mega' ); $data['random'] = esc_html__( 'Random', 'mega' ); foreach( $this->animations as $key => $value ) $data[$key] = $value['name']; return $data; } public function hookOnce() { add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue' )); } public function enqueue() { if ( !$this->mega['settings']['show_slider'] || !mega_toggle( $this->mega['settings']['location'] )) return; wp_enqueue_script( 'owl.carousel' ); wp_enqueue_style( 'owl.carousel.min' ); wp_enqueue_style( 'mega.animate', MEGA_DIR_URI . '/assets/css/animate.css' ); } public function hook() { add_action( 'wp_footer', array( &$this, 'footer' ), 20 ); add_filter( 'body_class', array( &$this, 'addBodyClass' )); } public function footer() { if ( !$this->mega['settings']['show_slider'] || !mega_toggle( $this->mega['settings']['location'] )) return; $id = $this->mega['args']['id'];//parent_ //$parent_id = strtolower( $this->mega['args']['parent_id_base'] ) . '-' . $this->mega['args']['parent_id']; extract( $this->mega['settings'] ); $args = array(); $args = array_merge( $args, $this->getAnimations() ); $data = json_encode( wp_parse_args( $args, array( //'responsiveBaseElement' => "#{$parent_id} > #{$id} > .owl-carousel", //'responsiveBaseElement' => "#{$id}", 'responsiveClass' => true, 'responsive' => array( 0 => array( 'items' => 1 ), 600 => array( 'items' => 1 ), 1000 => array( 'items' => 1 )), 'nav' => (bool) $nav, 'rtl' => is_rtl(), 'autoplay' => (bool) $auto, 'autoplayHoverPause' => (bool) $pause, 'autoplayTimeout' => (int) $time, 'loop' => (bool) $loop, //'margin' => $margin, 'navRewind' => true, 'autoHeight' => true, 'smartSpeed' => 1000, 'items' => 1, 'navText' => array( 'prev', 'next' ) ))); echo ""; }//#{$parent_id} > public function getAnimations() { extract( $this->mega['settings'] ); if ( $this->mega['settings']['auto_animation'] === 'default' ) return array(); if ( $this->mega['settings']['auto_animation'] == 'random' ) { $code = $this->animations[array_rand( $this->animations )]; if ( $code['in'] ) $r['animateIn'] = $code['in']; if ( $code['out'] ) $r['animateOut'] = $code['out']; return $r; } else { $code = $this->animations[$this->mega['settings']['auto_animation']]; if ( $code['in'] ) $r['animateIn'] = $code['in']; if ( $code['out'] ) $r['animateOut'] = $code['out']; return $r; } } public function addBodyClass( $classes ) { if ( is_admin() ) return $classes; if ( !$this->mega['settings']['show_slider'] || !mega_toggle( $this->mega['settings']['location'] )) return $classes; $classes[] = 'show-slider'; return $classes; } public function callback() { if ( !$this->mega['settings']['show_slider'] || !mega_toggle( $this->mega['settings']['location'] )) return; echo $this->before(); echo ''; echo $this->after(); } public function getSlides() { extract( $this->mega['settings'] ); if ( $source === 'auto' ) { $this->getPostQuery(); } else foreach ( range( 1, 4 ) as $k => $v ) { if ( ${"custom_$v"} ) { $this->block( $v ); } } } public function block( $k = '' ) { extract( $this->mega['settings'] ); if ( $source === 'auto' ) { $this->auto(); return; } echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; $this->h2( ${'custom_' . $k . '_title'}, ${'custom_' . $k . '_link'} ); $this->text( mega_is_mobile() ? mega_clean_words( 90, ${'custom_' . $k . '_text'} ) : ${'custom_' . $k . '_text'} ); if ( !empty( ${'custom_' . $k . '_link'} )) $this->link( ${'custom_' . $k . '_link'}, ${'custom_' . $k . '_button_label'} ); echo '
'; if ( ${'custom_' . $k . '_image'} && ${'custom_' . $k . '_alignment'} !== 'center' ) { $thumb = mega_thumb( array( 'width' => mega_is_mobile() ? '100%' : ${'custom_' . $k . '_width'} . 'px', 'height' => ${'custom_' . $k . '_height'} . 'px', 'custom' => ${'custom_' . $k . '_image_url'}, 'sources' => array( 'custom' => 1, 'ph' => ${'custom_' . $k . '_show_placeholder'} ) ), 1 ); $this->thumb( $thumb, ${'custom_' . $k . '_link'} ); } echo '
'; echo '
'; } public function auto() { extract( $this->mega['settings'] ); echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; $this->h2( $show_title ? mega_clean_words( $title_count, get_the_title() ) : '', $show_link ? get_permalink() : '' ); $this->text( mega_clean_words( mega_is_mobile() && $excerpt_count > 90 ? 90 : $excerpt_count, get_the_excerpt() )); if ( $show_link ) $this->link( get_permalink(), esc_html_x( 'Continue', 'Slider', 'mega' )); echo '
'; if ( $auto_image && $auto_alignment !== 'center' ) { $thumb = mega_thumb( array( 'width' => mega_is_mobile() ? '100%' : $auto_image_width . 'px', 'height' => $auto_image_height . 'px', 'sources' => $auto_image_sources ), 1 ); $this->thumb( $thumb, $show_link ? get_permalink() : '' ); } echo '
'; echo '
'; } public function h2( $text, $link ) { echo mega_auto_tag( 'h2', array( 'text' => mega_auto_tag( 'a', array( 'text' => esc_html( $text ), 'attr' => array( 'href' => $link ) ) ) ) ); } public function text( $text ) { echo '
' . wpautop( $text ) . '
'; } public function link( $link, $label ) { echo mega_auto_tag( 'a', array( 'text' => '' . esc_html( $label ) . '', 'attr' => array( 'href' => $link, 'class' => 'button' ), 'bypass' => false )); } public function thumb( $thumb, $link ) { echo '
' . mega_auto_tag( 'a', array( 'text' => $thumb, 'attr' => array( 'href' => $link ) )) . '
'; } public function bg( $top, $bottom, $image ) { return esc_attr( 'linear-gradient(' . ( empty( $top ) ? 'transparent' : $top ) . ' 0, ' . ( empty( $bottom ) ? 'transparent' : $bottom ) . ' 100%), url(' . $image . ')' ); } public function alignment( $alignment, $cover ) { $class = array(); if ( mega_is_mobile() ) $class[] = 'to-center'; else if ( isset( $alignment )) { if ( $alignment === 'top' ) { $class[] = 'to-top'; $class[] = 'to-center'; } else { $class[] = 'to-' . $alignment; } } if ( isset( $cover ) && $cover && $alignment !== 'top' ) { $class[] = 'cover'; } return implode( ' ', $class ); } }