about-widget.php
4 years ago
accordion-widget.php
4 years ago
accordion.php
4 years ago
attachment-url.php
4 years ago
audio.php
4 years ago
before-after.php
4 years ago
button.php
4 years ago
code.php
4 years ago
contact-box.php
4 years ago
contact-form.php
4 years ago
custom-list.php
4 years ago
divider.php
4 years ago
dropcap.php
4 years ago
facebook.php
4 years ago
flickr.php
4 years ago
gallery.php
4 years ago
general-element-fields.php
4 years ago
gmap.php
4 years ago
highlight.php
4 years ago
image.php
4 years ago
instagram-feed.php
4 years ago
latest-items.php
5 years ago
latest-posts-slider.php
4 years ago
popular-posts-widget.php
4 years ago
products-grid.php
4 years ago
quote.php
4 years ago
recent-posts-grid-carousel.php
4 years ago
recent-posts-land-style.php
4 years ago
recent-posts-masonry.php
4 years ago
recent-posts-tiles-carousel.php
4 years ago
recent-posts-tiles.php
4 years ago
recent-posts-timeline.php
4 years ago
recent-posts-widget.php
4 years ago
recent-products.php
4 years ago
related-posts.php
8 years ago
sample-element.php
4 years ago
search.php
4 years ago
socials-list.php
4 years ago
staff.php
4 years ago
tab-widget.php
4 years ago
tabs.php
4 years ago
testimonial.php
4 years ago
text.php
4 years ago
touch-slider.php
4 years ago
video.php
4 years ago
button.php
405 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Button element |
| 4 | * |
| 5 | * |
| 6 | * @package Auxin |
| 7 | * @license LICENSE.txt |
| 8 | * @author averta |
| 9 | * @link http://phlox.pro/ |
| 10 | * @copyright (c) 2010-2022 averta |
| 11 | */ |
| 12 | |
| 13 | function auxin_get_button_master_array( $master_array ) { |
| 14 | |
| 15 | $master_array['aux_button'] = array( |
| 16 | 'name' => __("Button", 'auxin-elements' ), |
| 17 | 'auxin_output_callback' => 'auxin_widget_button_callback', |
| 18 | 'base' => 'aux_button', |
| 19 | 'description' => __('It adds a button element.', 'auxin-elements' ), |
| 20 | 'class' => 'aux-widget-button', |
| 21 | 'show_settings_on_create' => true, |
| 22 | 'weight' => 1, |
| 23 | 'is_widget' => false, |
| 24 | 'is_shortcode' => true, |
| 25 | 'is_so' => true, |
| 26 | 'is_vc' => true, |
| 27 | 'category' => THEME_NAME, |
| 28 | 'group' => '', |
| 29 | 'admin_enqueue_js' => '', |
| 30 | 'admin_enqueue_css' => '', |
| 31 | 'front_enqueue_js' => '', |
| 32 | 'front_enqueue_css' => '', |
| 33 | 'icon' => 'aux-element aux-pb-icons-button', |
| 34 | 'custom_markup' => '', |
| 35 | 'js_view' => '', |
| 36 | 'html_template' => '', |
| 37 | 'deprecated' => '', |
| 38 | 'content_element' => '', |
| 39 | 'as_parent' => '', |
| 40 | 'as_child' => '', |
| 41 | 'params' => array( |
| 42 | array( |
| 43 | 'heading' => __('Button label','auxin-elements' ), |
| 44 | 'description' => __('The label of button.','auxin-elements' ), |
| 45 | 'param_name' => 'label', |
| 46 | 'type' => 'textfield', |
| 47 | 'value' => __('Button', 'auxin-elements'), |
| 48 | 'holder' => 'textfield', |
| 49 | 'class' => 'label', |
| 50 | 'admin_label' => false, |
| 51 | 'dependency' => '', |
| 52 | 'weight' => '', |
| 53 | 'group' => '' , |
| 54 | 'edit_field_class' => '' |
| 55 | ), |
| 56 | array( |
| 57 | 'heading' => __('Button size','auxin-elements' ), |
| 58 | 'description' => '', |
| 59 | 'param_name' => 'size', |
| 60 | 'type' => 'dropdown', |
| 61 | 'def_value' => 'medium', |
| 62 | 'value' => array( |
| 63 | 'exlarge' => __('Exlarge', 'auxin-elements' ), |
| 64 | 'large' => __('Large' , 'auxin-elements' ), |
| 65 | 'medium' => __('Medium' , 'auxin-elements' ), |
| 66 | 'small' => __('Small' , 'auxin-elements' ), |
| 67 | 'tiny' => __('Tiny' , 'auxin-elements' ) |
| 68 | ), |
| 69 | 'holder' => '', |
| 70 | 'class' => 'round', |
| 71 | 'admin_label' => true, |
| 72 | 'dependency' => '', |
| 73 | 'weight' => '', |
| 74 | 'group' => '' , |
| 75 | 'edit_field_class' => '' |
| 76 | ), |
| 77 | array( |
| 78 | 'heading' => __('Button shape','auxin-elements' ), |
| 79 | 'description' => '', |
| 80 | 'param_name' => 'border', |
| 81 | 'type' => 'aux_visual_select', |
| 82 | 'value' => '', |
| 83 | 'class' => 'border', |
| 84 | 'admin_label' => false, |
| 85 | 'dependency' => '', |
| 86 | 'weight' => '', |
| 87 | 'group' => __('Appearance', 'auxin-elements'), |
| 88 | 'edit_field_class' => '', |
| 89 | 'choices' => array( |
| 90 | '' => array( |
| 91 | 'label' => __('Box', 'auxin-elements' ), |
| 92 | 'image' => AUXIN_URL . 'images/visual-select/button-normal.svg' |
| 93 | ), |
| 94 | 'round' => array( |
| 95 | 'label' => __('Round', 'auxin-elements' ), |
| 96 | 'image' => AUXIN_URL . 'images/visual-select/button-curved.svg' |
| 97 | ), |
| 98 | 'curve' => array( |
| 99 | 'label' => __('Curve', 'auxin-elements' ), |
| 100 | 'image' => AUXIN_URL . 'images/visual-select/button-rounded.svg' |
| 101 | ) |
| 102 | ) |
| 103 | ), |
| 104 | array( |
| 105 | 'heading' => __('Button style','auxin-elements' ), |
| 106 | 'description' => '', |
| 107 | 'param_name' => 'style', |
| 108 | 'type' => 'aux_visual_select', |
| 109 | 'value' => '', |
| 110 | 'class' => 'style', |
| 111 | 'admin_label' => false, |
| 112 | 'dependency' => '', |
| 113 | 'weight' => '', |
| 114 | 'group' => __('Appearance', 'auxin-elements'), |
| 115 | 'edit_field_class' => '', |
| 116 | 'choices' => array( |
| 117 | '' => array( |
| 118 | 'label' => __('Normal', 'auxin-elements' ), |
| 119 | 'image' => AUXIN_URL . 'images/visual-select/button-normal.svg' |
| 120 | ), |
| 121 | '3d' => array( |
| 122 | 'label' => __('3D', 'auxin-elements' ), |
| 123 | 'image' => AUXIN_URL . 'images/visual-select/button-3d.svg' |
| 124 | ), |
| 125 | 'outline' => array( |
| 126 | 'label' => __('Outline', 'auxin-elements' ), |
| 127 | 'image' => AUXIN_URL . 'images/visual-select/button-outline.svg' |
| 128 | ) |
| 129 | ) |
| 130 | ), |
| 131 | array( |
| 132 | 'heading' => __('Uppercase label','auxin-elements' ), |
| 133 | 'description' => '', |
| 134 | 'param_name' => 'uppercase', |
| 135 | 'type' => 'aux_switch', |
| 136 | 'value' => '1', |
| 137 | 'class' => 'uppercase', |
| 138 | 'admin_label' => false, |
| 139 | 'dependency' => '', |
| 140 | 'weight' => '', |
| 141 | 'group' => '' , |
| 142 | 'edit_field_class' => '' |
| 143 | ), |
| 144 | array( |
| 145 | 'heading' => __('Darken the label','auxin-elements' ), |
| 146 | 'description' => __('Darken label of button.','auxin-elements' ), |
| 147 | 'param_name' => 'dark', |
| 148 | 'type' => 'aux_switch', |
| 149 | 'value' => '0', |
| 150 | 'class' => 'dark', |
| 151 | 'admin_label' => false, |
| 152 | 'dependency' => '', |
| 153 | 'weight' => '', |
| 154 | 'group' => '' , |
| 155 | 'edit_field_class' => '' |
| 156 | ), |
| 157 | array( |
| 158 | 'heading' => __('Icon for button','auxin-elements' ), |
| 159 | 'description' => '', |
| 160 | 'param_name' => 'icon', |
| 161 | 'type' => 'aux_iconpicker', |
| 162 | 'value' => '', |
| 163 | 'class' => 'icon-name', |
| 164 | 'admin_label' => false, |
| 165 | 'dependency' => '', |
| 166 | 'weight' => '', |
| 167 | 'group' => '' , |
| 168 | 'edit_field_class' => '' |
| 169 | ), |
| 170 | array( |
| 171 | 'heading' => __('Icon alignment','auxin-elements' ), |
| 172 | 'description' => '', |
| 173 | 'param_name' => 'icon_align', |
| 174 | 'type' => 'aux_visual_select', |
| 175 | 'def_value' => 'default', |
| 176 | 'choices' => array( |
| 177 | // default template |
| 178 | 'default' => array( |
| 179 | 'label' => __('Default' , 'auxin-elements'), |
| 180 | 'image' => AUXELS_ADMIN_URL . '/assets/images/button.png' |
| 181 | ), |
| 182 | 'left' => array( |
| 183 | 'label' => __('Left' , 'auxin-elements'), |
| 184 | 'video_src' => AUXELS_ADMIN_URL . '/assets/images/preview/Button2.webm webm' |
| 185 | ), |
| 186 | 'right' => array( |
| 187 | 'label' => __('Right' , 'auxin-elements'), |
| 188 | 'video_src' => AUXELS_ADMIN_URL . '/assets/images/preview/Button1.webm webm' |
| 189 | ), |
| 190 | 'over' => array( |
| 191 | 'label' => __('Over', 'auxin-elements'), |
| 192 | 'video_src' => AUXELS_ADMIN_URL . '/assets/images/preview/Button5.webm webm' |
| 193 | ), |
| 194 | 'left-animate' => array( |
| 195 | 'label' => __('Animate from Left', 'auxin-elements'), |
| 196 | 'video_src' => AUXELS_ADMIN_URL . '/assets/images/preview/Button4.webm webm' |
| 197 | ), |
| 198 | 'right-animate' => array( |
| 199 | 'label' => __('Animate from Righ', 'auxin-elements'), |
| 200 | 'video_src' => AUXELS_ADMIN_URL . '/assets/images/preview/Button3.webm webm' |
| 201 | ), |
| 202 | ), |
| 203 | 'holder' => '', |
| 204 | 'class' => 'icon-align', |
| 205 | 'admin_label' => false, |
| 206 | 'dependency' => '', |
| 207 | 'weight' => '', |
| 208 | 'group' => '' , |
| 209 | 'edit_field_class' => '' |
| 210 | ), |
| 211 | array( |
| 212 | 'heading' => __('Color of button','auxin-elements' ), |
| 213 | 'description' => '', |
| 214 | 'param_name' => 'color_name', |
| 215 | 'type' => 'aux_visual_select', |
| 216 | 'value' => 'carmine-pink', |
| 217 | 'choices' => auxin_get_famous_colors_list(), |
| 218 | 'holder' => '', |
| 219 | 'class' => 'color', |
| 220 | 'admin_label' => false, |
| 221 | 'dependency' => '', |
| 222 | 'weight' => '', |
| 223 | 'group' => __('Appearance', 'auxin-elements'), |
| 224 | 'edit_field_class' => '' |
| 225 | ), |
| 226 | array( |
| 227 | 'heading' => __('Button Link','auxin-elements' ), |
| 228 | 'description' => '', |
| 229 | 'param_name' => 'link', |
| 230 | 'type' => 'textfield', |
| 231 | 'value' => '', |
| 232 | 'holder' => '', |
| 233 | 'class' => 'link', |
| 234 | 'admin_label' => false, |
| 235 | 'dependency' => '', |
| 236 | 'weight' => '', |
| 237 | 'group' => '' , |
| 238 | 'edit_field_class' => '' |
| 239 | ), |
| 240 | array( |
| 241 | 'heading' => __('Open link in','auxin-elements' ), |
| 242 | 'description' => '', |
| 243 | 'param_name' => 'target', |
| 244 | 'type' => 'dropdown', |
| 245 | 'def_value' => '_self', |
| 246 | 'value' => array( |
| 247 | '_self' => __('Current page' , 'auxin-elements' ), |
| 248 | '_blank' => __('New page', 'auxin-elements' ) |
| 249 | ), |
| 250 | 'holder' => '', |
| 251 | 'class' => 'target', |
| 252 | 'admin_label' => false, |
| 253 | 'dependency' => '', |
| 254 | 'weight' => '', |
| 255 | 'group' => '' , |
| 256 | 'edit_field_class' => '' |
| 257 | ), |
| 258 | array( |
| 259 | 'heading' => __('Extra class name','auxin-elements'), |
| 260 | 'description' => __('If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.', 'auxin-elements'), |
| 261 | 'param_name' => 'extra_classes', |
| 262 | 'type' => 'textfield', |
| 263 | 'value' => '', |
| 264 | 'holder' => '', |
| 265 | 'class' => 'extra_classes', |
| 266 | 'admin_label' => false, |
| 267 | 'dependency' => '', |
| 268 | 'weight' => '', |
| 269 | 'group' => '' , |
| 270 | 'edit_field_class' => '' |
| 271 | ) |
| 272 | ) |
| 273 | ); |
| 274 | |
| 275 | return $master_array; |
| 276 | } |
| 277 | |
| 278 | add_filter( 'auxin_master_array_shortcodes', 'auxin_get_button_master_array', 10, 1 ); |
| 279 | |
| 280 | |
| 281 | function auxin_widget_button_callback( $atts = array(), $shortcode_content = null ){ |
| 282 | |
| 283 | // Defining default attributes |
| 284 | $default_atts = array( |
| 285 | 'label' => '', |
| 286 | 'size' => 'medium', |
| 287 | 'border' => '', |
| 288 | 'style' => '', |
| 289 | 'uppercase' => '1', |
| 290 | 'dark' => '0', |
| 291 | 'icon' => '', |
| 292 | 'icon_align' => 'default', |
| 293 | 'color_name' => 'carmine-pink', |
| 294 | 'link' => '', |
| 295 | 'target' => '_self', |
| 296 | 'nofollow' => false, |
| 297 | 'btn_attrs' => '', // data-attr1{val1};data-attr2{val2} |
| 298 | 'custom_styles' => array(), |
| 299 | 'extra_classes' => '', // custom css class names for this element |
| 300 | 'custom_el_id' => '', |
| 301 | 'base_class' => 'aux-widget-button', |
| 302 | 'open_video_in_lightbox' => false, |
| 303 | ); |
| 304 | |
| 305 | $result = auxin_get_widget_scafold( $atts, $default_atts, $shortcode_content ); |
| 306 | extract( $result['parsed_atts'] ); |
| 307 | |
| 308 | |
| 309 | // -------------------------------------------- |
| 310 | $btn_css_classes = array( 'aux-button' ); |
| 311 | $btn_css_classes[] = 'aux-' . $size; // size |
| 312 | $btn_css_classes[] = 'aux-' . $color_name; // appearance |
| 313 | |
| 314 | if( $border ){ |
| 315 | $btn_css_classes[] = 'aux-' . $border; // border form |
| 316 | } |
| 317 | if( $style ){ |
| 318 | $btn_css_classes[] = 'aux-' . $style; // appearance |
| 319 | } |
| 320 | if( auxin_is_true( $uppercase ) ){ |
| 321 | $btn_css_classes[] = 'aux-uppercase'; // text form |
| 322 | } |
| 323 | if( auxin_is_true( $dark ) ){ |
| 324 | $btn_css_classes[] = 'aux-dark-text'; // text color |
| 325 | } |
| 326 | if( $icon_align !== "default" ){ |
| 327 | $btn_css_classes[] = 'aux-icon-' . $icon_align; // icon align |
| 328 | } |
| 329 | |
| 330 | // add extra attributes to button element if defined |
| 331 | $btn_other_attrs = ''; |
| 332 | |
| 333 | if( $btn_attrs = trim( $btn_attrs, ';' ) ){ |
| 334 | preg_match_all('/([\-|\w]+)(?!{})([\w]+)/s', $btn_attrs, $btn_attr_matches ); |
| 335 | |
| 336 | if( ! empty( $btn_attr_matches[0] ) && is_array( $btn_attr_matches[0] ) ){ |
| 337 | foreach( $btn_attr_matches[0] as $i => $attr_name_value ){ |
| 338 | if( 0 == $i % 2 ){ |
| 339 | $btn_other_attrs .= sprintf(' %s', $attr_name_value); |
| 340 | } else { |
| 341 | $btn_other_attrs .= sprintf('="%s"', esc_attr( trim( $attr_name_value ) ) ); |
| 342 | } |
| 343 | } |
| 344 | $btn_other_attrs = trim( $btn_other_attrs ); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | $extra_styles = ''; |
| 349 | |
| 350 | if ( isset( $custom_styles ) && ! empty( $custom_styles ) ) { |
| 351 | |
| 352 | foreach( $custom_styles as $property => $value ) { |
| 353 | if ( 'custom' === $property ) { |
| 354 | $extra_styles .= $value; |
| 355 | } else { |
| 356 | $extra_styles .= $property . ':' . $value . ';'; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | $extra_styles = 'style="' . $extra_styles . '"'; |
| 361 | |
| 362 | } |
| 363 | |
| 364 | if( ! empty( $extra_classes ) ) { |
| 365 | $btn_css_classes[] = $extra_classes; |
| 366 | } |
| 367 | |
| 368 | if ( auxin_is_true( $open_video_in_lightbox ) ) { |
| 369 | $btn_css_classes[] = 'aux-open-video'; |
| 370 | $btn_other_attrs .= ' data-type="video"'; |
| 371 | } |
| 372 | |
| 373 | // get escaped class attributes |
| 374 | $button_class_attr = auxin_make_html_class_attribute( $btn_css_classes ); |
| 375 | |
| 376 | $label = empty( $label ) ? $shortcode_content : $label; |
| 377 | $label = empty( $label ) ? __( "Button", 'auxin-elements' ) : $label; |
| 378 | |
| 379 | $btn_content = '<span class="aux-overlay"></span>'; |
| 380 | $btn_label = '<span class="aux-text">'. auxin_do_cleanup_shortcode( $label ) .'</span>'; |
| 381 | $btn_icon = $icon ? '<span class="aux-icon '. esc_attr($icon) .'"></span>' : ''; |
| 382 | |
| 383 | // if icon is aligned on left |
| 384 | if( false !== strpos( $icon_align, 'left') ){ |
| 385 | $btn_content .= $btn_icon . $btn_label; |
| 386 | } else { |
| 387 | $btn_content .= $btn_label. $btn_icon; |
| 388 | } |
| 389 | |
| 390 | $btn_tag = empty( $link ) ? 'button' : 'a'; |
| 391 | $btn_rel = auxin_is_true ( $nofollow ) ? ' rel="nofollow"' : ''; |
| 392 | $btn_href = empty( $link ) ? '' : ' href="'. $link .'" target="'. esc_attr( $target ) .'" ' . $btn_rel; |
| 393 | |
| 394 | $output = ''; |
| 395 | |
| 396 | // widget custom output ----------------------- |
| 397 | $output .= "<$btn_tag $btn_href $btn_other_attrs $button_class_attr $extra_styles>"; |
| 398 | $output .= $btn_content; |
| 399 | $output .= "</$btn_tag>"; |
| 400 | |
| 401 | if ( auxin_is_true( $open_video_in_lightbox ) ) { |
| 402 | $output = '<span class="aux-lightbox-video ">' . $output . '</span>'; |
| 403 | } |
| 404 | return $output; |
| 405 | } |