BackwardsCompatibility.class.php
4 years ago
Blocks.class.php
4 years ago
CustomPostTypes.class.php
4 years ago
Dashboard.class.php
4 years ago
DeactivationSurvey.class.php
4 years ago
InstallationWalkthrough.class.php
4 years ago
Permissions.class.php
4 years ago
ReviewAsk.class.php
4 years ago
Settings.class.php
4 years ago
Widgets.class.php
4 years ago
WooCommerceIntegration.class.php
4 years ago
template-functions.php
4 years ago
template-functions.php
157 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Create a shortcode to display a slider |
| 5 | * @since 2.0.0 |
| 6 | */ |
| 7 | function ewd_us_slider_shortcode( $atts ) { |
| 8 | |
| 9 | // Define shortcode attributes |
| 10 | $slider_atts = array( |
| 11 | 'slider_type' => null, |
| 12 | 'post__in_string' => '', |
| 13 | 'posts' => -1, |
| 14 | 'category' => false, |
| 15 | 'carousel' => false, |
| 16 | 'slide_indicators' => null, |
| 17 | 'timer_bar' => null |
| 18 | ); |
| 19 | |
| 20 | // Create filter so addons can modify the accepted attributes |
| 21 | $slider_atts = apply_filters( 'ewd_us_slider_shortcode_atts', $slider_atts ); |
| 22 | |
| 23 | // Extract the shortcode attributes |
| 24 | $args = shortcode_atts( $slider_atts, $atts ); |
| 25 | |
| 26 | // Render menu |
| 27 | ewd_us_load_view_files(); |
| 28 | $slider = new ewdusViewSlider( $args ); |
| 29 | |
| 30 | return $slider->render(); |
| 31 | } |
| 32 | add_shortcode( 'ultimate-slider', 'ewd_us_slider_shortcode' ); |
| 33 | |
| 34 | function ewd_us_load_view_files() { |
| 35 | |
| 36 | $files = array( |
| 37 | EWD_US_PLUGIN_DIR . '/views/Base.class.php' // This will load all default classes |
| 38 | ); |
| 39 | |
| 40 | $files = apply_filters( 'ewd_us_load_view_files', $files ); |
| 41 | |
| 42 | foreach( $files as $file ) { |
| 43 | require_once( $file ); |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | |
| 48 | function ewd_us_create_watermarked_image( $image_url ) { |
| 49 | |
| 50 | $upload_dir = wp_upload_dir(); |
| 51 | $plugin_upload_path = $upload_dir['basedir'] . "/ultimate-slider/"; |
| 52 | |
| 53 | $image_file_path = $plugin_upload_path . basename( $image_url ); |
| 54 | |
| 55 | $aspect_ratio_fraction = ewd_us_get_aspect_ratio_fraction(); |
| 56 | |
| 57 | $image_string = file_get_contents( $image_url ); |
| 58 | |
| 59 | $stamp = imagecreatefrompng( EWD_US_PLUGIN_URL . '/assets/img/star-watermark.png' ); |
| 60 | $image = imagecreatefromstring( $image_string ); |
| 61 | |
| 62 | $height = imagesy( $image ); |
| 63 | $width = imagesx( $image ); |
| 64 | |
| 65 | if ( $width < 2500 ) { |
| 66 | $stamp_width = round( $width / 10 ); |
| 67 | $stamp_height = $stamp_width; |
| 68 | $scaled_stamp = imagescale( $stamp, $stamp_width, $stamp_height ); |
| 69 | } |
| 70 | else { |
| 71 | $scaled_stamp = $stamp; |
| 72 | } |
| 73 | |
| 74 | $margin_right = 10; |
| 75 | $margin_bottom = $height - ( $width * $aspect_ratio_fraction ) + 10; |
| 76 | $sx = imagesx( $scaled_stamp ); |
| 77 | $sy = imagesy( $scaled_stamp ); |
| 78 | |
| 79 | imagecopy( $image, $scaled_stamp, imagesx( $image ) - $sx - $margin_right, imagesy( $image ) - $sy - $margin_bottom, 0, 0, imagesx( $scaled_stamp ), imagesy( $scaled_stamp ) ); |
| 80 | |
| 81 | header( 'Content-type: image/png' ); |
| 82 | imagepng( $image, $image_file_path ); |
| 83 | imagedestroy( $image ); |
| 84 | } |
| 85 | |
| 86 | function ewd_us_get_aspect_ratio_fraction() { |
| 87 | global $ewd_us_controller; |
| 88 | |
| 89 | $aspect_ratio = $ewd_us_controller->settings->get_setting( 'aspect-ratio' ); |
| 90 | |
| 91 | if ($aspect_ratio == "3_1") {$aspect_ratio_fraction = .333333333;} |
| 92 | elseif ($aspect_ratio == "2_1") {$aspect_ratio_fraction = .5;} |
| 93 | elseif ($aspect_ratio == "16_9") {$aspect_ratio_fraction = .5625;} |
| 94 | elseif ($aspect_ratio == "3_2") {$aspect_ratio_fraction = .666666666;} |
| 95 | elseif ($aspect_ratio == "4_3") {$aspect_ratio_fraction = .75;} |
| 96 | elseif ($aspect_ratio == "1_1") {$aspect_ratio_fraction = 1;} |
| 97 | else {$aspect_ratio_fraction = .444444444;} |
| 98 | |
| 99 | return $aspect_ratio_fraction; |
| 100 | } |
| 101 | |
| 102 | if ( ! function_exists( 'ewd_us_get_aspect_fraction' ) ) { |
| 103 | function ewd_us_get_aspect_fraction( $aspect_ratio ) { |
| 104 | |
| 105 | if ($aspect_ratio == "3_1") {$aspect_fraction = .333333333;} |
| 106 | if ($aspect_ratio == "16_7") {$aspect_fraction = .4375;} |
| 107 | if ($aspect_ratio == "2_1") {$aspect_fraction = .5;} |
| 108 | if ($aspect_ratio == "16_9") {$aspect_fraction = .5625;} |
| 109 | if ($aspect_ratio == "3_2") {$aspect_fraction = .666666667;} |
| 110 | if ($aspect_ratio == "4_3") {$aspect_fraction = .75;} |
| 111 | if ($aspect_ratio == "1_1") {$aspect_fraction = 1;} |
| 112 | |
| 113 | return $aspect_fraction; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if ( ! function_exists( 'ewd_hex_to_rgb' ) ) { |
| 118 | function ewd_hex_to_rgb( $hex ) { |
| 119 | |
| 120 | $hex = str_replace("#", "", $hex); |
| 121 | |
| 122 | // return if the string isn't a color code |
| 123 | if ( strlen( $hex ) !== 3 and strlen( $hex ) !== 6 ) { return '0,0,0'; } |
| 124 | |
| 125 | if(strlen($hex) == 3) { |
| 126 | $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) ); |
| 127 | $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) ); |
| 128 | $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) ); |
| 129 | } else { |
| 130 | $r = hexdec( substr( $hex, 0, 2 ) ); |
| 131 | $g = hexdec( substr( $hex, 2, 2 ) ); |
| 132 | $b = hexdec( substr( $hex, 4, 2 ) ); |
| 133 | } |
| 134 | |
| 135 | $rgb = $r . ", " . $g . ", " . $b; |
| 136 | |
| 137 | return $rgb; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if ( ! function_exists( 'ewd_format_classes' ) ) { |
| 142 | function ewd_format_classes( $classes ) { |
| 143 | |
| 144 | if ( count( $classes ) ) { |
| 145 | return ' class="' . join( ' ', $classes ) . '"'; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if ( ! function_exists( 'ewd_add_frontend_ajax_url' ) ) { |
| 151 | function ewd_add_frontend_ajax_url() { ?> |
| 152 | |
| 153 | <script type="text/javascript"> |
| 154 | var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; |
| 155 | </script> |
| 156 | <?php } |
| 157 | } |