PluginProbe
Slider Ultimate / 2.2.1
Slider Ultimate v2.2.1
2.2.10 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 All 54 releases
ultimate-slider / includes / template-functions.php
template-functions.php
161 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 wp_mkdir_p( $plugin_upload_path );
54
55 $path_parts = pathinfo( $image_url );
56
57 $image_file_path = $plugin_upload_path . $path_parts['filename'] . '_watermarked.png';
58
59 $aspect_ratio_fraction = ewd_us_get_aspect_ratio_fraction();
60
61 $image_string = file_get_contents( $image_url );
62
63 $stamp = imagecreatefrompng( EWD_US_PLUGIN_URL . '/assets/img/star-watermark.png' );
64 $image = imagecreatefromstring( $image_string );
65
66 $height = imagesy( $image );
67 $width = imagesx( $image );
68
69 if ( $width < 2500 ) {
70 $stamp_width = round( $width / 10 );
71 $stamp_height = $stamp_width;
72 $scaled_stamp = imagescale( $stamp, $stamp_width, $stamp_height );
73 }
74 else {
75 $scaled_stamp = $stamp;
76 }
77
78 $margin_right = 10;
79 $margin_bottom = $height - ( $width * $aspect_ratio_fraction ) + 10;
80 $sx = imagesx( $scaled_stamp );
81 $sy = imagesy( $scaled_stamp );
82
83 imagecopy( $image, $scaled_stamp, imagesx( $image ) - $sx - $margin_right, imagesy( $image ) - $sy - $margin_bottom, 0, 0, imagesx( $scaled_stamp ), imagesy( $scaled_stamp ) );
84
85 imagepng( $image, $image_file_path );
86
87 imagedestroy( $image );
88 }
89
90 function ewd_us_get_aspect_ratio_fraction() {
91 global $ewd_us_controller;
92
93 $aspect_ratio = $ewd_us_controller->settings->get_setting( 'aspect-ratio' );
94
95 if ($aspect_ratio == "3_1") {$aspect_ratio_fraction = .333333333;}
96 elseif ($aspect_ratio == "2_1") {$aspect_ratio_fraction = .5;}
97 elseif ($aspect_ratio == "16_9") {$aspect_ratio_fraction = .5625;}
98 elseif ($aspect_ratio == "3_2") {$aspect_ratio_fraction = .666666666;}
99 elseif ($aspect_ratio == "4_3") {$aspect_ratio_fraction = .75;}
100 elseif ($aspect_ratio == "1_1") {$aspect_ratio_fraction = 1;}
101 else {$aspect_ratio_fraction = .444444444;}
102
103 return $aspect_ratio_fraction;
104 }
105
106 if ( ! function_exists( 'ewd_us_get_aspect_fraction' ) ) {
107 function ewd_us_get_aspect_fraction( $aspect_ratio ) {
108
109 if ($aspect_ratio == "3_1") {$aspect_fraction = .333333333;}
110 if ($aspect_ratio == "16_7") {$aspect_fraction = .4375;}
111 if ($aspect_ratio == "2_1") {$aspect_fraction = .5;}
112 if ($aspect_ratio == "16_9") {$aspect_fraction = .5625;}
113 if ($aspect_ratio == "3_2") {$aspect_fraction = .666666667;}
114 if ($aspect_ratio == "4_3") {$aspect_fraction = .75;}
115 if ($aspect_ratio == "1_1") {$aspect_fraction = 1;}
116
117 return $aspect_fraction;
118 }
119 }
120
121 if ( ! function_exists( 'ewd_hex_to_rgb' ) ) {
122 function ewd_hex_to_rgb( $hex ) {
123
124 $hex = str_replace("#", "", $hex);
125
126 // return if the string isn't a color code
127 if ( strlen( $hex ) !== 3 and strlen( $hex ) !== 6 ) { return '0,0,0'; }
128
129 if(strlen($hex) == 3) {
130 $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) );
131 $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) );
132 $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) );
133 } else {
134 $r = hexdec( substr( $hex, 0, 2 ) );
135 $g = hexdec( substr( $hex, 2, 2 ) );
136 $b = hexdec( substr( $hex, 4, 2 ) );
137 }
138
139 $rgb = $r . ", " . $g . ", " . $b;
140
141 return $rgb;
142 }
143 }
144
145 if ( ! function_exists( 'ewd_format_classes' ) ) {
146 function ewd_format_classes( $classes ) {
147
148 if ( count( $classes ) ) {
149 return ' class="' . join( ' ', $classes ) . '"';
150 }
151 }
152 }
153
154 if ( ! function_exists( 'ewd_add_frontend_ajax_url' ) ) {
155 function ewd_add_frontend_ajax_url() { ?>
156
157 <script type="text/javascript">
158 var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
159 </script>
160 <?php }
161 }