PluginProbe
Virtue/Ascend/Pinnacle Toolkit / 4.9.12.2
Virtue/Ascend/Pinnacle Toolkit v4.9.12.2
4.9.12.2 trunk 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.7 All 48 releases
← All changes | gallery.php +464 -167 3.3 → 4.9.12.2 View file →
@@ -1,204 +1,501 @@
1 1 <?php
2 +if ( ! class_exists( 'Kadence_Toolkit_Get_Image' ) ) {
3 + class Kadence_Toolkit_Get_Image {
4 + /**
5 + * The singleton instance
6 + */
7 + static private $instance = null;
8 + /**
9 + * No initialization allowed
10 + */
11 + private function __construct() {}
2 12
3 -function kt_toolkit_get_srcset($width,$height,$url,$id) {
4 - if(empty($id) || empty($url)) {
5 - return;
6 - }
7 -
8 - $image_meta = get_post_meta( $id, '_wp_attachment_metadata', true );
9 - if(empty($image_meta['file'])){
10 - return;
11 - }
12 - // If possible add in our images on the fly sizes
13 - $ext = substr($image_meta['file'], strrpos($image_meta['file'], "."));
14 - $pathflyfilename = str_replace($ext,'-'.$width.'x'.$height.'' . $ext, $image_meta['file']);
15 - $pathretinaflyfilename = str_replace($ext, '-'.$width.'x'.$height.'@2x' . $ext, $image_meta['file']);
16 - $flyfilename = basename($image_meta['file'], $ext) . '-'.$width.'x'.$height.'' . $ext;
17 - $retinaflyfilename = basename($image_meta['file'], $ext) . '-'.$width.'x'.$height.'@2x' . $ext;
13 + /**
14 + * No cloning allowed
15 + */
16 + private function __clone() {}
18 17
19 - $upload_info = wp_upload_dir();
20 - $upload_dir = $upload_info['basedir'];
18 + static public function getInstance() {
19 + if(self::$instance == null) {
20 + self::$instance = new self;
21 + }
21 22
22 - $flyfile = trailingslashit($upload_dir).$pathflyfilename;
23 - $retinafile = trailingslashit($upload_dir).$pathretinaflyfilename;
24 - if(empty($image_meta['sizes']) ){ $image_meta['sizes'] = array();}
25 - if (file_exists($flyfile)) {
26 - $kt_add_imagesize = array(
27 - 'kt_on_fly' => array(
28 - 'file'=> $flyfilename,
29 - 'width' => $width,
30 - 'height' => $height,
31 - 'mime-type' => $image_meta['sizes']['thumbnail']['mime-type']
32 - )
33 - );
34 - $image_meta['sizes'] = array_merge($image_meta['sizes'], $kt_add_imagesize);
23 + return self::$instance;
24 + }
25 +
26 + public function process($id = null, $width = null, $height = null) {
27 + // return if no ID
28 + if(empty($id)) {
29 + return false;
30 + }
31 + // return with orginal if no width or height set.
32 + if(empty($width) && empty($height) ) {
33 + return self::toolkit_get_full_image($id);
34 + }
35 + // Find width or height if one or the other is not set.
36 + $org_height = true;
37 + if(empty($height) ) {
38 + $org_height = false;
39 + $image_attributes = wp_get_attachment_image_src( $id, 'full' );
40 + $sizes = image_resize_dimensions($image_attributes[1], $image_attributes[2], $width, null, false );
41 + $height = ( isset( $sizes[5] ) ? $sizes[5] : '' );
42 + } else if(empty($width) ) {
43 + $image_attributes = wp_get_attachment_image_src( $id, 'full' );
44 + $sizes = image_resize_dimensions($image_attributes[1], $image_attributes[2], null, $height, false );
45 + $width = ( isset( $sizes[4] ) ? $sizes[4] : '' );
46 + }
47 + // Now we checked for an ID, made sure the width and height have values lets check if we can make the size at all
48 + if ( self::toolkit_image_size_larger_than_original( $id, $width, $height ) ) {
49 + return self::toolkit_get_full_image($id);
50 + }
51 + //Check for jetpack
52 + if( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
53 + $args = array( 'resize' => $width . ',' . $height );
54 + $image_url = wp_get_attachment_image_url($id, 'full');
55 + return array (
56 + 0 => jetpack_photon_url( $image_url, $args ),
57 + 1 => $width,
58 + 2 => $height,
59 + 3 => self::toolkit_get_srcset_output($id, $image_url, $width, $height),
60 + 4 => $image_url,
61 + 5 => $id
62 + );
63 + } else if( self::toolkit_image_size_already_exists( $id, $width, $height ) ) {
64 +
65 + return self::toolkit_get_image_at_size($id, $width, $height );
66 +
67 + } else if(class_exists( 'Kadence_Image_Processing' )) {
68 + // lets process the image
69 + $Kadence_Image_Processing = Kadence_Image_Processing::getInstance();
70 + $created = $Kadence_Image_Processing->process($id, $width, $height);
71 + if($created) {
72 + return self::toolkit_get_image_at_size($id, $width, $height );
73 + } else {
74 + return self::toolkit_get_full_image($id);
75 + }
76 + } else {
77 + return self::toolkit_get_full_image($id);
78 + }
79 + }
80 + public static function toolkit_get_image_srcset($id = null, $url = null, $width = null, $height = null) {
81 + if(empty($id) || empty($url) || empty($width) || empty($height)) {
82 + return false;
83 + }
84 +
85 + $image_meta = self::toolkit_get_image_meta($id);
86 + if ( ! $image_meta ) {
87 + return false;
88 + }
89 +
90 + if(function_exists ( 'wp_calculate_image_srcset') ){
91 + $output = wp_calculate_image_srcset(array( $width, $height), $url, $image_meta, $id);
92 + } else {
93 + $output = '';
94 + }
95 +
96 + return $output;
97 + }
98 + public static function toolkit_get_srcset_output($id = null, $url = null, $width = null, $height = null) {
99 + $img_srcset = self::toolkit_get_image_srcset($id, $url, $width, $height);
100 + if(!empty($img_srcset) ) {
101 + $output = 'srcset="'.esc_attr($img_srcset).'" sizes="(max-width: '.esc_attr($width).'px) 100vw, '.esc_attr($width).'px"';
102 + } else {
103 + $output = '';
104 + }
105 + return $output;
106 + }
107 + public static function toolkit_image_size_larger_than_original($id, $width, $height) {
108 + $image_meta = self::toolkit_get_image_meta( $id );
109 +
110 + if ( ! isset( $image_meta['width'] ) || ! isset( $image_meta['height'] ) ) {
111 + return true;
112 + }
113 + if ( $width > $image_meta['width'] || $height > $image_meta['height'] ) {
114 + return true;
115 + }
116 +
117 + return false;
118 + }
119 + public static function toolkit_get_full_image($id) {
120 + $src = wp_get_attachment_image_src($id, 'full' );
121 + // array return.
122 + $image = array (
123 + 0 => $src[0],
124 + 1 => $src[1],
125 + 2 => $src[2],
126 + 3 => self::toolkit_get_srcset_output($id, $src[0], $src[1], $src[2]),
127 + 4 => $src[0],
128 + 5 => $id
129 + );
130 + return $image;
131 + }
132 + public static function toolkit_get_image_at_size($id, $width, $height) {
133 + $size = array(
134 + 0 => $width,
135 + 1 => $height
136 + );
137 + $src = wp_get_attachment_image_src($id, $size );
138 + $full = wp_get_attachment_image_url($id, 'full' );
139 + // array return.
140 + $image = array (
141 + 0 => $src[0],
142 + 1 => $src[1],
143 + 2 => $src[2],
144 + 3 => self::toolkit_get_srcset_output($id, $src[0], $src[1], $src[2]),
145 + 4 => $full,
146 + 5 => $id
147 + );
148 + return $image;
149 + }
150 + public static function toolkit_get_image_meta( $id ) {
151 + return wp_get_attachment_metadata( $id );
152 + }
153 + public static function toolkit_image_size_already_exists( $id, $width, $height ) {
154 + $image_meta = self::toolkit_get_image_meta( $id );
155 + $kip_size_name = self::kip_get_size_name( array( $width, $height ));
156 + if(isset( $image_meta['sizes'][ $kip_size_name ] ) ) {
157 + return true;
158 + } else {
159 + return false;
160 + }
161 + }
162 + public static function kip_get_size_name( $size ) {
163 + return 'kip-' . $size[0] . 'x' . $size[1];
164 + }
165 + }
166 +}
167 +
168 +function kadence_toolkit_get_image_array($width = null, $height = null, $crop = true, $class = null, $alt = null, $id = null) {
169 + if(empty($id)) {
170 + $id = get_post_thumbnail_id();
35 171 }
36 - if (file_exists($retinafile)) {
37 - $size = getimagesize( $retinafile );
38 - if(($size[0] == 2 * $width) && ($size[1] == 2 * $height) ) {
39 - $kt_add_imagesize_retina = array(
40 - 'kt_on_fly_retina' => array(
41 - 'file'=> $retinaflyfilename,
42 - 'width' => 2 * $width,
43 - 'height' => 2 * $height,
44 - 'mime-type' => $image_meta['sizes']['thumbnail']['mime-type']
45 - )
172 + if(!empty($id)) {
173 + $Kadence_Toolkit_Get_Image = Kadence_Toolkit_Get_Image::getInstance();
174 + $image = $Kadence_Toolkit_Get_Image->process( $id, $width, $height);
175 + if(empty($alt)) {
176 + $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
177 + }
178 + $return_array = array(
179 + 'src' => $image[0],
180 + 'width' => $image[1],
181 + 'height' => $image[2],
182 + 'srcset' => $image[3],
183 + 'class' => $class,
184 + 'alt' => $alt,
185 + 'full' => $image[4],
46 186 );
47 - $image_meta['sizes'] = array_merge($image_meta['sizes'], $kt_add_imagesize_retina);
48 - }
49 - }
50 - if(function_exists ( 'wp_calculate_image_srcset') ){
51 - $output = wp_calculate_image_srcset(array( $width, $height), $url, $image_meta, $id);
52 187 } else {
53 - $output = '';
188 + $return_array = array(
189 + 'src' => '',
190 + 'width' => '',
191 + 'height' => '',
192 + 'srcset' => '',
193 + 'class' => '',
194 + 'alt' => '',
195 + 'full' => '',
196 + );
54 197 }
55 - return $output;
198 +
199 + return $return_array;
56 200 }
57 -function kt_toolkit_get_srcset_output($width,$height,$url,$id) {
58 - $img_srcset = kt_toolkit_get_srcset( $width, $height, $url, $id);
59 - if(!empty($img_srcset) ) {
60 - $output = 'srcset="'.esc_attr($img_srcset).'" sizes="(max-width: '.esc_attr($width).'px) 100vw, '.esc_attr($width).'px"';
61 - } else {
62 - $output = '';
63 - }
64 - return $output;
65 -}
66 201 /**
67 202 *
68 203 * Re-create the [gallery] shortcode and use thumbnails styling from kadencethemes
69 204 *
70 205 */
71 -function kadence_shortcode_gallery($attr) {
72 - $post = get_post();
73 - static $instance = 0;
74 - $instance++;
206 +function kadence_toolkit_shortcode_gallery($attr) {
207 + $post = get_post();
208 + static $instance = 0;
209 + $instance++;
75 210
76 - if (!empty($attr['ids'])) {
77 - if (empty($attr['orderby'])) {
78 - $attr['orderby'] = 'post__in';
79 - }
80 - $attr['include'] = $attr['ids'];
81 - }
211 + if (!empty($attr['ids'])) {
212 + if (empty($attr['orderby'])) {
213 + $attr['orderby'] = 'post__in';
214 + }
215 + $attr['include'] = $attr['ids'];
216 + }
82 217
83 - $output = apply_filters('post_gallery', '', $attr);
218 + $output = apply_filters('post_gallery', '', $attr);
84 219
85 - if ($output != '') {
86 - return $output;
87 - }
220 + if ($output != '') {
221 + return $output;
222 + }
88 223
89 - if (isset($attr['orderby'])) {
90 - $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
91 - if (!$attr['orderby']) {
92 - unset($attr['orderby']);
93 - }
94 - }
224 + if (isset($attr['orderby'])) {
225 + $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
226 + if (!$attr['orderby']) {
227 + unset($attr['orderby']);
228 + }
229 + }
230 + if(!isset($post)) {
231 + $post_id = null;
232 + } else {
233 + $post_id = $post->ID;
234 + }
95 235
96 - extract(shortcode_atts(array(
97 - 'order' => 'ASC',
98 - 'orderby' => 'menu_order ID',
99 - 'id' => $post->ID,
100 - 'itemtag' => '',
101 - 'icontag' => '',
102 - 'captiontag' => '',
103 - 'columns' => 3,
104 - 'link' => 'file',
105 - 'size' => 'full',
106 - 'include' => '',
107 - 'attachment_page' => 'false',
108 - 'use_image_alt' => 'false',
109 - 'gallery_id' => (rand(10,100)),
110 - 'lightboxsize' => 'full',
111 - 'exclude' => ''
112 - ), $attr));
236 + extract(shortcode_atts(array(
237 + 'order' => 'ASC',
238 + 'orderby' => 'menu_order ID',
239 + 'id' => $post_id,
240 + 'itemtag' => '',
241 + 'icontag' => '',
242 + 'captiontag' => '',
243 + 'columns' => 3,
244 + 'link' => 'file',
245 + 'size' => 'full',
246 + 'include' => '',
247 + 'attachment_page' => 'false',
248 + 'use_image_alt' => 'false',
249 + 'gallery_id' => ( rand( 10, 100 ) ),
250 + 'lightboxsize' => 'full',
251 + 'exclude' => ''
252 + ), $attr));
113 253
114 - $id = intval($id);
254 + $id = intval($id);
115 255
116 - if ($order === 'RAND') {
117 - $orderby = 'none';
118 - }
256 + if ($order === 'RAND') {
257 + $orderby = 'none';
258 + }
119 259
120 - $gallery_rn = (rand(10,100));
260 + $gallery_rn = (rand(10,100));
121 261
122 - if (!empty($include)) {
123 - $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
262 + if (!empty($include)) {
263 + $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
124 264
125 - $attachments = array();
126 - foreach ($_attachments as $key => $val) {
127 - $attachments[$val->ID] = $_attachments[$key];
128 - }
129 - } elseif (!empty($exclude)) {
130 - $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
131 - } else {
132 - $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
133 - }
265 + $attachments = array();
266 + foreach ($_attachments as $key => $val) {
267 + $attachments[$val->ID] = $_attachments[$key];
268 + }
269 + } elseif (!empty($exclude)) {
270 + $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
271 + } else {
272 + $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
273 + }
134 274
135 - if (empty($attachments)) {
136 - return '';
137 - }
275 + if (empty($attachments)) {
276 + return '';
277 + }
138 278
139 - if (is_feed()) {
140 - $output = "\n";
141 - foreach ($attachments as $att_id => $attachment) {
142 - $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
143 - }
144 - return $output;
145 - }
279 + if (is_feed()) {
280 + $output = "\n";
281 + foreach ($attachments as $att_id => $attachment) {
282 + $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
283 + }
284 + return $output;
285 + }
146 286
147 - if ($columns == '2') {
148 - $itemsize = 'tcol-lg-6 tcol-md-6 tcol-sm-6 tcol-xs-12 tcol-ss-12'; $imgsize = 600;
149 - } else if ($columns == '1') {
150 - $itemsize = 'tcol-lg-12 tcol-md-12 tcol-sm-12 tcol-xs-12 tcol-ss-12'; $imgsize = 1200;
151 - } else if ($columns == '3'){
152 - $itemsize = 'tcol-lg-4 tcol-md-4 tcol-sm-4 tcol-xs-6 tcol-ss-12'; $imgsize = 400;
153 - } else if ($columns == '6'){
154 - $itemsize = 'tcol-lg-2 tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-6'; $imgsize = 300;
155 - } else if ($columns == '8' || $columns == '9' || $columns == '7'){
156 - $itemsize = 'tcol-lg-2 tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-4'; $imgsize = 260;
157 - } else if ($columns == '12' || $columns == '11'){
158 - $itemsize = 'tcol-lg-1 tcol-md-1 tcol-sm-2 tcol-xs-2 tcol-ss-3'; $imgsize = 240;
159 - } else if ($columns == '5'){
160 - $itemsize = 'tcol-lg-25 tcol-md-25 tcol-sm-3 tcol-xs-4 tcol-ss-6'; $imgsize = 300;
161 - } else {
162 - $itemsize = 'tcol-lg-3 tcol-md-3 tcol-sm-4 tcol-xs-6 tcol-ss-12'; $imgsize = 300;
163 - }
287 + if ($columns == '2') {
288 + $itemsize = 'tcol-lg-6 tcol-md-6 tcol-sm-6 tcol-xs-12 tcol-ss-12'; $imgsize = 600;
289 + } else if ($columns == '1') {
290 + $itemsize = 'tcol-lg-12 tcol-md-12 tcol-sm-12 tcol-xs-12 tcol-ss-12'; $imgsize = 1200;
291 + } else if ($columns == '3'){
292 + $itemsize = 'tcol-lg-4 tcol-md-4 tcol-sm-4 tcol-xs-6 tcol-ss-12'; $imgsize = 400;
293 + } else if ($columns == '6'){
294 + $itemsize = 'tcol-lg-2 tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-6'; $imgsize = 300;
295 + } else if ($columns == '8' || $columns == '9' || $columns == '7'){
296 + $itemsize = 'tcol-lg-2 tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-4'; $imgsize = 260;
297 + } else if ($columns == '12' || $columns == '11'){
298 + $itemsize = 'tcol-lg-1 tcol-md-1 tcol-sm-2 tcol-xs-2 tcol-ss-3'; $imgsize = 240;
299 + } else if ($columns == '5'){
300 + $itemsize = 'tcol-lg-25 tcol-md-25 tcol-sm-3 tcol-xs-4 tcol-ss-6'; $imgsize = 300;
301 + } else {
302 + $itemsize = 'tcol-lg-3 tcol-md-3 tcol-sm-4 tcol-xs-6 tcol-ss-12'; $imgsize = 300;
303 + }
164 304
165 - $output .= '<div id="kad-wp-gallery'.esc_attr($gallery_rn).'" class="kad-wp-gallery kad-light-wp-gallery clearfix kt-gallery-column-'.esc_attr($columns).' rowtight">';
305 + $output .= '<div id="kad-wp-gallery'.esc_attr($gallery_rn).'" class="kad-wp-gallery kad-light-wp-gallery clearfix kt-gallery-column-'.esc_attr($columns).' rowtight">';
166 306
167 - $i = 0;
168 - foreach ($attachments as $id => $attachment) {
169 - $attachment_url = wp_get_attachment_url($id);
170 - $image = aq_resize($attachment_url, $imgsize, $imgsize, true, false);
171 - if(empty($image[0])) {$image = array($attachment_url,$imgsize,$imgsize);}
172 - $img_srcset_output = kt_get_srcset_output( $image[1], $image[2], $attachment_url, $id);
173 - if($lightboxsize != 'full') {
174 - $attachment_url = wp_get_attachment_image_src( $id, $lightboxsize);
175 - $attachment_url = $attachment_url[0];
307 + foreach ($attachments as $id => $attachment) {
308 + if($use_image_alt == 'true') {
309 + $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
310 + } else {
311 + $alt = $attachment->post_excerpt;
312 + }
313 +
314 + $img = kadence_toolkit_get_image_array($imgsize, $imgsize, true, 'light-dropshaddow', $alt, $id);
315 + $attachment_url = $img['full'];
316 +
317 + if($lightboxsize != 'full') {
318 + $attachment_url = wp_get_attachment_image_src( $id, $lightboxsize);
319 + $attachment_url = $attachment_url[0];
320 + }
321 + $lightbox_data = 'data-rel="lightbox"';
322 + if($link == 'attachment_page' || $attachment_page == 'true') {
323 + $attachment_url = get_permalink($id);
324 + $lightbox_data = '';
325 + }
326 +
327 + $output .= '<div class="'.esc_attr($itemsize).' g_item"><div class="grid_item kad_gallery_fade_in gallery_item">';
328 + $output .= '<a href="'.esc_url($attachment_url).'" '.$lightbox_data.' class="lightboxhover">';
329 + $output .= '<img src="'.esc_url($img['src']).'" width="'.esc_attr($img['width']).'" height="'.esc_attr($img['height']).'" alt="'.esc_attr($img['alt']).'" '.$img['srcset'].' class="'.$img['class'].'"/>';
330 + $output .= '</a>';
331 + $output .= '</div></div>';
332 + }
333 + $output .= '</div>';
334 +
335 + return $output;
336 +}
337 +add_action('init', 'kt_tool_gallery_setup_init');
338 +function kt_tool_gallery_setup_init() {
339 + $pinnacle = get_option( 'pinnacle' );
340 + $virtue = get_option( 'virtue' );
341 + if(! function_exists( 'kadence_gallery' ) ) {
342 + if( (isset($pinnacle['pinnacle_gallery']) && $pinnacle['pinnacle_gallery'] == '1') || (isset($virtue['virtue_gallery']) && $virtue['virtue_gallery'] == '1') ) {
343 + remove_shortcode('gallery');
344 + add_shortcode('gallery', 'kadence_toolkit_shortcode_gallery');
345 + }
346 + }
347 +}
348 +function kt_toolkit_shortcode_gallery($attr) {
349 + $post = get_post();
350 + static $instance = 0;
351 + $instance++;
352 +
353 + if (!empty($attr['ids'])) {
354 + if (empty($attr['orderby'])) {
355 + $attr['orderby'] = 'post__in';
356 + }
357 + $attr['include'] = $attr['ids'];
358 + }
359 +
360 + $output = apply_filters('post_gallery', '', $attr);
361 +
362 + if ($output != '') {
363 + return $output;
364 + }
365 +
366 + if (isset($attr['orderby'])) {
367 + $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
368 + if (!$attr['orderby']) {
369 + unset($attr['orderby']);
370 + }
371 + }
372 + if(!isset($post)) {
373 + $post_id = null;
374 + } else {
375 + $post_id = $post->ID;
376 + }
377 +
378 + extract(shortcode_atts(array(
379 + 'order' => 'ASC',
380 + 'orderby' => 'menu_order ID',
381 + 'id' => $post_id,
382 + 'columns' => 3,
383 + 'link' => 'file',
384 + 'size' => 'full',
385 + 'include' => '',
386 + 'use_image_alt' => 'true',
387 + 'gallery_id' => (rand(10,100)),
388 + 'lightboxsize' => 'full',
389 + 'exclude' => ''
390 + ), $attr));
391 +
392 + $id = intval($id);
393 +
394 + if ($order === 'RAND') {
395 + $orderby = 'none';
396 + }
397 + $caption = 'false';
398 + if (!empty($include)) {
399 + $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
400 + $attachments = array();
401 + foreach ($_attachments as $key => $val) {
402 + $attachments[$val->ID] = $_attachments[$key];
403 + }
404 + } elseif (!empty($exclude)) {
405 + $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
406 + } else {
407 + $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
408 + }
409 + if (empty($attachments)) {
410 + return '';
411 + }
412 + if (is_feed()) {
413 + $output = "\n";
414 + foreach ($attachments as $att_id => $attachment) {
415 + $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
416 + }
417 + return $output;
418 + }
419 + $output .= '<div id="kad-wp-gallery'.esc_attr($gallery_id).'" class="kad-wp-gallery kt-gallery-column-'.esc_attr($columns).' kad-light-gallery clearfix row-margin-small">';
420 + if ($columns == '1') {
421 + $itemsize = 'col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12 col-ss-12';
422 + $imgsize = 1140;
423 + } else if ($columns == '2') {
424 + $itemsize = 'col-xxl-3 col-xl-4 col-lg-6 col-md-6 col-sm-6 col-xs-12 col-ss-12';
425 + $imgsize = 600;
426 + } else if ($columns == '3'){
427 + $itemsize = 'col-xxl-25 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-xs-6 col-ss-12';
428 + $imgsize = 400;
429 + } else if ($columns == '4'){
430 + $itemsize = 'col-xxl-2 col-xl-25 col-lg-3 col-md-3 col-sm-4 col-xs-6 col-ss-12';
431 + $imgsize = 300;
432 + } else if ($columns == '5'){
433 + $itemsize = 'col-xxl-2 col-xl-2 col-lg-25 col-md-25 col-sm-3 col-xs-4 col-ss-6';
434 + $imgsize = 240;
435 + } else if ($columns == '6'){
436 + $itemsize = 'col-xxl-15 col-xl-2 col-lg-2 col-md-2 col-sm-3 col-xs-4 col-ss-6';
437 + $imgsize = 240;
438 + } else {
439 + $itemsize = 'col-xxl-1 col-xl-15 col-lg-2 col-md-2 col-sm-3 col-xs-4 col-ss-4';
440 + $imgsize = 240;
176 441 }
177 - $lightbox_data = 'data-rel="lightbox"';
178 - if($link == 'attachment_page' || $attachment_page == 'true') {
179 - $attachment_url = get_permalink($id);
180 - $lightbox_data = '';
181 - }
182 - if($use_image_alt == 'true') {
183 - $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
184 - } else {
185 - $alt = $attachment->post_excerpt;
186 - }
442 +
443 + $i = 0;
444 + foreach ($attachments as $id => $attachment) {
445 + // Get alt or caption for alt
446 + if($use_image_alt == 'true') {
447 + $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
448 + } else {
449 + $alt = $attachment->post_excerpt;
450 + }
187 451
188 - $output .= '<div class="'.esc_attr($itemsize).' g_item"><div class="grid_item kad_gallery_fade_in gallery_item"><a href="'.esc_url($attachment_url).'" '.$lightbox_data.' class="lightboxhover">';
189 - $output .= '<img src="'.esc_url($image[0]).'" width="'.esc_attr($image[1]).'" height="'.esc_attr($image[2]).'" alt="'.esc_attr($alt).'" '.$img_srcset_output.' class="light-dropshaddow"/>';
190 - $output .= '</a>';
191 - $output .= '</div></div>';
452 + $img = kadence_toolkit_get_image_array($imgsize, $imgsize, true, 'kt-gallery-img', $alt, $id);
453 + $attachment_url = $img['full'];
454 +
455 + if($lightboxsize != 'full') {
456 + $attachment_lb = wp_get_attachment_image_src( $id, $lightboxsize);
457 + $attachment_url = $attachment_lb[0];
458 + }
459 + $lightbox_data = 'data-rel="lightbox"';
460 + if($link == 'attachment_page') {
461 + $attachment_url = get_permalink($id);
462 + $lightbox_data = '';
463 + }
464 +
465 + $paddingbtn = ($img['height']/$img['width']) * 100;
466 + $output .= '<div class="'.esc_attr($itemsize).' g_item"><div class="grid_item gallery_item">';
467 + if($link != 'none') {
468 + $output .='<a href="'.esc_url($attachment_url).'" '.$lightbox_data.' class="gallery-link">';
469 + }
470 + $output .= '<div class="kt-intrinsic" style="padding-bottom:'.esc_attr($paddingbtn).'%;" itemprop="image" itemscope itemtype="http://schema.org/ImageObject">';
471 + $output .= '<img src="'.esc_url($img['src']).'" width="'.esc_attr($img['width']).'" height="'.esc_attr($img['height']).'" alt="'.esc_attr($img['alt']).'" '.$img['srcset'].' class="'.$img['class'].'" itemprop="contentUrl" />';
472 + $output .= '<meta itemprop="url" content="'.esc_url($img['src']).'">';
473 + $output .= '<meta itemprop="width" content="'.esc_attr($img['width']).'">';
474 + $output .= '<meta itemprop="height" content="'.esc_attr($img['height']).'>">';
475 + $output .= '</div>';
476 + if (trim($attachment->post_excerpt) && $caption == 'true') {
477 + $output .= '<div class="photo-caption-bg"></div>';
478 + $output .= '<div class="caption kad_caption">';
479 + $output .= '<div class="kad_caption_inner">' . wptexturize($attachment->post_excerpt) . '</div>';
480 + $output .= '</div>';
481 + }
482 + if($link != 'none') {
483 + $output .= '</a>';
484 + }
485 + $output .= '</div></div>';
192 486 }
193 487 $output .= '</div>';
194 488
195 489 return $output;
196 490 }
197 -$pinnacle = get_option( 'pinnacle' );
198 -$virtue = get_option( 'virtue' );
199 -if(! function_exists( 'kadence_gallery' ) ) {
200 -if( (isset($pinnacle['pinnacle_gallery']) && $pinnacle['pinnacle_gallery'] == '1') || (isset($virtue['virtue_gallery']) && $virtue['virtue_gallery'] == '1') ) {
201 - remove_shortcode('gallery');
202 - add_shortcode('gallery', 'kadence_shortcode_gallery');
203 -}
491 +add_action('init', 'kt_tool_ascend_gallery_setup_init');
492 +function kt_tool_ascend_gallery_setup_init() {
493 + $the_theme = wp_get_theme();
494 + if($the_theme->get( 'Name' ) == 'Ascend' || ($the_theme->get( 'Template') == 'ascend') ) {
495 + $ascend = get_option( 'ascend' );
496 + if(isset($ascend['kadence_gallery']) && $ascend['kadence_gallery'] == '1') {
497 + remove_shortcode('gallery');
498 + add_shortcode('gallery', 'kt_toolkit_shortcode_gallery');
499 + }
500 + }
204 501 }