about-widget.php
5 months ago
accordion-widget.php
1 month ago
accordion.php
5 months ago
attachment-url.php
5 months ago
audio.php
5 months ago
before-after.php
5 months ago
button.php
5 months ago
code.php
5 months ago
contact-box.php
5 months ago
contact-form.php
5 months ago
custom-list.php
5 months ago
divider.php
5 months ago
dropcap.php
5 months ago
facebook.php
5 months ago
flickr.php
5 months ago
gallery.php
5 months ago
gmap.php
5 months ago
highlight.php
5 months ago
image.php
5 months ago
instagram-feed.php
5 months ago
latest-posts-slider.php
5 months ago
popular-posts-widget.php
5 months ago
products-grid.php
5 months ago
quote.php
5 months ago
recent-posts-grid-carousel.php
5 months ago
recent-posts-land-style.php
5 months ago
recent-posts-masonry.php
5 months ago
recent-posts-tiles-carousel.php
5 months ago
recent-posts-tiles.php
5 months ago
recent-posts-timeline.php
5 months ago
recent-posts-widget.php
5 months ago
recent-products.php
5 months ago
related-posts.php
8 years ago
sample-element.php
5 months ago
search.php
5 months ago
socials-list.php
5 months ago
staff.php
5 months ago
tab-widget.php
5 months ago
tabs.php
5 months ago
testimonial.php
5 months ago
text.php
5 months ago
touch-slider.php
5 months ago
video.php
5 months ago
dropcap.php
207 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Dropcap element |
| 4 | * |
| 5 | * |
| 6 | * @package Auxin |
| 7 | * @license LICENSE.txt |
| 8 | * @author averta |
| 9 | * @link http://phlox.pro/ |
| 10 | * @copyright (c) 2010-2026 averta |
| 11 | */ |
| 12 | function auxin_get_dropcap_master_array( $master_array ) { |
| 13 | |
| 14 | $master_array['aux_dropcap'] = array( |
| 15 | 'name' => __("Dropcap", 'auxin-elements' ), |
| 16 | 'auxin_output_callback' => 'auxin_widget_dropcap_callback', |
| 17 | 'base' => 'aux_dropcap', |
| 18 | 'description' => __('Big styled character at the beginning of paragraph', 'auxin-elements' ), |
| 19 | 'class' => 'aux-widget-dropcap', |
| 20 | 'show_settings_on_create' => true, |
| 21 | 'weight' => 1, |
| 22 | 'is_widget' => false, |
| 23 | 'is_shortcode' => true, |
| 24 | 'category' => THEME_NAME, |
| 25 | 'group' => '', |
| 26 | 'admin_enqueue_js' => '', |
| 27 | 'admin_enqueue_css' => '', |
| 28 | 'front_enqueue_js' => '', |
| 29 | 'front_enqueue_css' => '', |
| 30 | 'icon' => 'aux-element aux-pb-icons-dropcap', |
| 31 | 'custom_markup' => '', |
| 32 | 'js_view' => '', |
| 33 | 'html_template' => '', |
| 34 | 'deprecated' => '', |
| 35 | 'content_element' => '', |
| 36 | 'as_parent' => '', |
| 37 | 'as_child' => '', |
| 38 | 'params' => array( |
| 39 | array( |
| 40 | 'heading' => __('Dropcap style','auxin-elements' ), |
| 41 | 'description' => '', |
| 42 | 'param_name' => 'style', |
| 43 | 'type' => 'aux_visual_select', |
| 44 | 'def_value' => 'classic', |
| 45 | 'holder' => '', |
| 46 | 'class' => 'style', |
| 47 | 'admin_label' => true, |
| 48 | 'dependency' => '', |
| 49 | 'weight' => '', |
| 50 | 'group' => '' , |
| 51 | 'edit_field_class' => '', |
| 52 | 'choices' => array( |
| 53 | 'classic' => array( |
| 54 | 'label' => __('Classic', 'auxin-elements' ), |
| 55 | 'image' => AUXIN_URL . 'images/visual-select/dropcap-classic.svg' |
| 56 | ), |
| 57 | 'square' => array( |
| 58 | 'label' => __('Square', 'auxin-elements' ), |
| 59 | 'image' => AUXIN_URL . 'images/visual-select/dropcap-square.svg' |
| 60 | ), |
| 61 | 'square-outline' => array( |
| 62 | 'label' => __('Outline Square', 'auxin-elements' ), |
| 63 | 'image' => AUXIN_URL . 'images/visual-select/dropcap-square-outline.svg' |
| 64 | ), |
| 65 | 'square-round' => array( |
| 66 | 'label' => __('Round Square', 'auxin-elements' ), |
| 67 | 'image' => AUXIN_URL . 'images/visual-select/dropcap-square-round.svg' |
| 68 | ), |
| 69 | 'circle' => array( |
| 70 | 'label' => __('Circle', 'auxin-elements' ), |
| 71 | 'image' => AUXIN_URL . 'images/visual-select/dropcap-circle.svg' |
| 72 | ), |
| 73 | 'circle-outline' => array( |
| 74 | 'label' => __('Outline Circle', 'auxin-elements' ), |
| 75 | 'image' => AUXIN_URL . 'images/visual-select/dropcap-circle-outline.svg' |
| 76 | ) |
| 77 | ) |
| 78 | ), |
| 79 | array( |
| 80 | 'heading' => __('Content','auxin-elements' ), |
| 81 | 'description' => __('Enter a text to show as dropcap text.', 'auxin-elements' ), |
| 82 | 'param_name' => 'content', |
| 83 | 'type' => 'textarea_html', |
| 84 | 'value' => '', |
| 85 | 'holder' => '', |
| 86 | 'class' => 'content', |
| 87 | 'admin_label' => false, |
| 88 | 'dependency' => '', |
| 89 | 'weight' => '', |
| 90 | 'group' => '' , |
| 91 | 'edit_field_class' => '' |
| 92 | ), |
| 93 | array( |
| 94 | 'heading' => __('Extra class name','auxin-elements' ), |
| 95 | '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' ), |
| 96 | 'param_name' => 'extra_classes', |
| 97 | 'type' => 'textfield', |
| 98 | 'value' => '', |
| 99 | 'holder' => '', |
| 100 | 'class' => 'extra_classes', |
| 101 | 'admin_label' => false, |
| 102 | 'dependency' => '', |
| 103 | 'weight' => '', |
| 104 | 'group' => '' , |
| 105 | 'edit_field_class' => '' |
| 106 | ) |
| 107 | ) |
| 108 | ); |
| 109 | |
| 110 | return $master_array; |
| 111 | } |
| 112 | |
| 113 | add_filter( 'auxin_master_array_shortcodes', 'auxin_get_dropcap_master_array', 10, 1 ); |
| 114 | |
| 115 | /** |
| 116 | * The front-end output of this element is returned by the following function |
| 117 | * |
| 118 | * @param array $atts The array containing the parsed values from shortcode, it should be same as defined params above. |
| 119 | * @param string $shortcode_content The shorcode content |
| 120 | * @return string The output of element markup |
| 121 | */ |
| 122 | function auxin_widget_dropcap_callback( $atts, $shortcode_content = null ) { |
| 123 | |
| 124 | // Defining default attributes |
| 125 | $default_atts = array( |
| 126 | 'title' => '', // header title |
| 127 | 'style' => 'classic', |
| 128 | 'content' => '', // custom css class names for this element |
| 129 | |
| 130 | 'extra_classes' => '', |
| 131 | 'custom_el_id' => '', |
| 132 | 'base_class' => 'aux-widget-dropcap' |
| 133 | ); |
| 134 | |
| 135 | $result = auxin_get_widget_scafold( $atts, $default_atts, $shortcode_content ); |
| 136 | extract( $result['parsed_atts'] ); |
| 137 | |
| 138 | ob_start(); |
| 139 | |
| 140 | // widget header ------------------------------ |
| 141 | echo wp_kses_post( $result['widget_header'] ); |
| 142 | echo wp_kses_post( $result['widget_title'] ); |
| 143 | |
| 144 | // The output for element here |
| 145 | $class_names = ""; |
| 146 | |
| 147 | switch ($style) { |
| 148 | case 'classic': |
| 149 | $class_names = "dropcap"; |
| 150 | break; |
| 151 | case 'square': |
| 152 | $class_names = "dropcap square"; |
| 153 | |
| 154 | break; |
| 155 | case 'square-outline': |
| 156 | $class_names = "dropcap square outline"; |
| 157 | |
| 158 | break; |
| 159 | case 'square-round': |
| 160 | $class_names = "dropcap square round"; |
| 161 | |
| 162 | break; |
| 163 | case 'square-round-outline': |
| 164 | $class_names = "dropcap square round outline"; |
| 165 | |
| 166 | break; |
| 167 | case 'circle': |
| 168 | $class_names = "dropcap circle"; |
| 169 | |
| 170 | break; |
| 171 | case 'circle-outline': |
| 172 | $class_names = "dropcap circle outline"; |
| 173 | |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | $first_letter = substr( $content, 0, 1); // get the first letter |
| 178 | |
| 179 | if ( $first_letter === "<") { |
| 180 | $tag = auxin_get_string_between($content, '<', '>'); |
| 181 | $content = auxin_str_replace_first( "<" .$tag. ">" ,"" , $content ); |
| 182 | $content = auxin_str_replace_first( "</".$tag. ">" ,"" , $content ); |
| 183 | } |
| 184 | |
| 185 | $first_letter = mb_substr( $content, 0, 1,'utf-8' ); // get the first letter |
| 186 | $rest_of_text = mb_substr( $content, 1, null, 'utf-8' ); // get the rest of text |
| 187 | |
| 188 | echo '<p class="'. esc_attr( $extra_classes ) .'">' . |
| 189 | '<span class="'. esc_attr( $class_names ) .'">'. esc_html( $first_letter ) .'</span>'. wp_kses_post( $rest_of_text ) . |
| 190 | '</p>'; |
| 191 | |
| 192 | // widget footer ------------------------------ |
| 193 | echo wp_kses_post( $result['widget_footer'] ); |
| 194 | |
| 195 | return ob_get_clean(); |
| 196 | } |
| 197 | |
| 198 | |
| 199 | if( ! function_exists( 'auxin_str_replace_first' ) ) { |
| 200 | |
| 201 | function auxin_str_replace_first($from, $to, $subject) { |
| 202 | $from = '/'.preg_quote($from, '/').'/'; |
| 203 | return preg_replace($from, $to, $subject, 1); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 |