| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') || exit; |
| 4 |
|
| 5 |
/** |
| 6 |
* Module Name: Slider |
| 7 |
* Description: Display slider content |
| 8 |
*/ |
| 9 |
class TB_Slider_Module extends Themify_Builder_Component_Module { |
| 10 |
const SLUG='slider'; |
| 11 |
public static function init():void { |
| 12 |
if (Themify_Builder_Model::is_cpt_active(self::SLUG)) { |
| 13 |
add_filter('themify_metabox/fields/themify-meta-boxes', array(__CLASS__, 'cpt_meta_boxes'), 100); // requires low priority so that it loads after theme's metaboxes |
| 14 |
if (!shortcode_exists('themify_slider_posts')) { |
| 15 |
add_shortcode('themify_slider_posts', array(__CLASS__, 'do_shortcode')); |
| 16 |
} |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
public static function get_module_name():string { |
| 21 |
add_filter('themify_builder_active_vars',array(__CLASS__,'set_cpt_active')); |
| 22 |
return __('Slider', 'themify'); |
| 23 |
} |
| 24 |
|
| 25 |
public static function get_module_icon():string { |
| 26 |
return 'layout-slider'; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
public static function get_metabox() { |
| 31 |
|
| 32 |
/** Slider Meta Box Options */ |
| 33 |
return array( |
| 34 |
// Featured Image Size |
| 35 |
Themify_Builder_Model::$featured_image_size, |
| 36 |
// Image Width |
| 37 |
Themify_Builder_Model::$image_width, |
| 38 |
// Image Height |
| 39 |
Themify_Builder_Model::$image_height, |
| 40 |
// External Link |
| 41 |
Themify_Builder_Model::$external_link, |
| 42 |
// Lightbox Link |
| 43 |
Themify_Builder_Model::$lightbox_link, |
| 44 |
array( |
| 45 |
'name' => 'video_url', |
| 46 |
'title' => __('Video URL', 'themify'), |
| 47 |
'description' => __('URL to embed a video instead of featured image', 'themify'), |
| 48 |
'type' => 'textbox', |
| 49 |
'meta' => array() |
| 50 |
) |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
public static function do_shortcode($atts) { |
| 55 |
|
| 56 |
$atts = shortcode_atts(array( |
| 57 |
'visible' => '1', |
| 58 |
'scroll' => '1', |
| 59 |
'auto' => 0, |
| 60 |
'pause_hover' => 'no', |
| 61 |
'play_control' => 'no', |
| 62 |
'wrap' => 'yes', |
| 63 |
'excerpt_length' => '20', |
| 64 |
'speed' => 'normal', |
| 65 |
'slider_nav' => 'yes', |
| 66 |
'pager' => 'yes', |
| 67 |
'limit' => 5, |
| 68 |
'category' => 0, |
| 69 |
'image' => 'yes', |
| 70 |
'image_w' => '240px', |
| 71 |
'image_fullwidth' => '', |
| 72 |
'image_h' => '180px', |
| 73 |
'more_text' => __('More...', 'themify'), |
| 74 |
'title' => 'yes', |
| 75 |
'display' => 'none', |
| 76 |
'post_meta' => 'no', |
| 77 |
'post_date' => 'no', |
| 78 |
'width' => '', |
| 79 |
'height' => '', |
| 80 |
'class' => '', |
| 81 |
'unlink_title' => 'no', |
| 82 |
'unlink_image' => 'no', |
| 83 |
'image_size' => 'thumbnail', |
| 84 |
'post_type' => 'post', |
| 85 |
'taxonomy' => 'category', |
| 86 |
'order' => 'DESC', |
| 87 |
'orderby' => 'date', |
| 88 |
'effect' => 'scroll', |
| 89 |
'style' => 'slider-default' |
| 90 |
), $atts); |
| 91 |
|
| 92 |
$module = array( |
| 93 |
'module_ID' => self::SLUG.'-' . rand(0, 10000), |
| 94 |
'mod_name' => self::SLUG, |
| 95 |
'mod_settings' => array( |
| 96 |
'mod_title_slider' => '', |
| 97 |
'layout_display_slider' => 'slider', |
| 98 |
'slider_category_slider' => $atts['category'], |
| 99 |
'posts_per_page_slider' => $atts['limit'], |
| 100 |
'offset_slider' => '', |
| 101 |
'order_slider' => $atts['order'], |
| 102 |
'orderby_slider' => $atts['orderby'], |
| 103 |
'display_slider' => $atts['display'], |
| 104 |
'hide_post_title_slider' => $atts['title'] === 'yes' ? 'no' : 'yes', |
| 105 |
'unlink_post_title_slider' => $atts['unlink_title'], |
| 106 |
'hide_feat_img_slider' => '', |
| 107 |
'unlink_feat_img_slider' => $atts['unlink_image'], |
| 108 |
'layout_slider' => $atts['style'], |
| 109 |
'image_size_slider' => $atts['image_size'], |
| 110 |
'img_w_slider' => $atts['image_w'], |
| 111 |
'img_fullwidth_slider' => $atts['image_fullwidth'], |
| 112 |
'img_h_slider' => $atts['image_h'], |
| 113 |
'visible_opt_slider' => $atts['visible'], |
| 114 |
'auto_scroll_opt_slider' => $atts['auto'], |
| 115 |
'scroll_opt_slider' => $atts['scroll'], |
| 116 |
'speed_opt_slider' => $atts['speed'], |
| 117 |
'effect_slider' => $atts['effect'], |
| 118 |
'pause_on_hover_slider' => $atts['pause_hover'], |
| 119 |
'play_pause_control' => $atts['play_control'], |
| 120 |
'wrap_slider' => $atts['wrap'], |
| 121 |
'show_nav_slider' => $atts['pager'], |
| 122 |
'show_arrow_slider' => $atts['slider_nav'], |
| 123 |
'left_margin_slider' => '', |
| 124 |
'right_margin_slider' => '', |
| 125 |
'css_slider' => themify_sanitize_css_classes( $atts['class'] ) |
| 126 |
) |
| 127 |
); |
| 128 |
|
| 129 |
return self::retrieve_template('template-'.self::SLUG.'.php', $module, THEMIFY_BUILDER_TEMPLATES_DIR, '', false); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Render plain content for static content. |
| 134 |
* |
| 135 |
* @param array $module |
| 136 |
* @return string |
| 137 |
*/ |
| 138 |
public static function get_static_content(array $module):string { |
| 139 |
$mod_settings = $module['mod_settings']+array( |
| 140 |
'layout_display_slider' => 'blog' |
| 141 |
); |
| 142 |
return 'blog' === $mod_settings['layout_display_slider'] ? '' : parent::get_static_content($module); |
| 143 |
} |
| 144 |
|
| 145 |
public static function set_cpt_active(array $arr){ |
| 146 |
if(Themify_Builder_Model::is_cpt_active('slider')){ |
| 147 |
$arr['slider_active']=1; |
| 148 |
} |
| 149 |
if(Themify_Builder_Model::is_cpt_active('portfolio')){ |
| 150 |
$arr['portfolio_active']=1; |
| 151 |
} |
| 152 |
if(Themify_Builder_Model::is_cpt_active('testimonial')){ |
| 153 |
$arr['testimonial_active']=1; |
| 154 |
} |
| 155 |
return $arr; |
| 156 |
} |
| 157 |
|
| 158 |
public static function get_translatable_text_fields( $module ) : array { |
| 159 |
return [ 'mod_title_slider' ]; |
| 160 |
} |
| 161 |
|
| 162 |
public static function get_translatable_repeatable_fields( $module ) { |
| 163 |
return [ |
| 164 |
'img_content_slider' => [ |
| 165 |
'img_url_slider' => 'LINK', |
| 166 |
'img_title_slider' => 'LINE', |
| 167 |
'img_link_slider' => 'LINK', |
| 168 |
'img_caption_slider' => 'TEXTAREA' |
| 169 |
], |
| 170 |
'video_content_slider' => [ |
| 171 |
'video_url_slider' => 'LINK', |
| 172 |
'video_title_slider' => 'LINE', |
| 173 |
'video_title_link_slider' => 'LINK', |
| 174 |
'video_caption_slider' => 'TEXTAREA' |
| 175 |
], |
| 176 |
'text_content_slider' => [ |
| 177 |
'text_caption_slider' => 'TEXTAREA' |
| 178 |
] |
| 179 |
]; |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
TB_Slider_Module::init(); |
| 184 |
|