PluginProbe
Virtue/Ascend/Pinnacle Toolkit / 3.7
Virtue/Ascend/Pinnacle Toolkit v3.7
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 3.8 All 47 releases
virtue-toolkit / gallery.php

gallery.php in Virtue/Ascend/Pinnacle Toolkit 3.7, at gallery.php

204 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
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;
18
19 $upload_info = wp_upload_dir();
20 $upload_dir = $upload_info['basedir'];
21
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' => isset($image_meta['sizes']['thumbnail']) ? $image_meta['sizes']['thumbnail']['mime-type'] : '',
32 )
33 );
34 $image_meta['sizes'] = array_merge($image_meta['sizes'], $kt_add_imagesize);
35 }
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' => isset($image_meta['sizes']['thumbnail']) ? $image_meta['sizes']['thumbnail']['mime-type'] : '',
45 )
46 );
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 } else {
53 $output = '';
54 }
55 return $output;
56 }
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 /**
67 *
68 * Re-create the [gallery] shortcode and use thumbnails styling from kadencethemes
69 *
70 */
71 function kadence_shortcode_gallery($attr) {
72 $post = get_post();
73 static $instance = 0;
74 $instance++;
75
76 if (!empty($attr['ids'])) {
77 if (empty($attr['orderby'])) {
78 $attr['orderby'] = 'post__in';
79 }
80 $attr['include'] = $attr['ids'];
81 }
82
83 $output = apply_filters('post_gallery', '', $attr);
84
85 if ($output != '') {
86 return $output;
87 }
88
89 if (isset($attr['orderby'])) {
90 $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
91 if (!$attr['orderby']) {
92 unset($attr['orderby']);
93 }
94 }
95
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));
113
114 $id = intval($id);
115
116 if ($order === 'RAND') {
117 $orderby = 'none';
118 }
119
120 $gallery_rn = (rand(10,100));
121
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));
124
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 }
134
135 if (empty($attachments)) {
136 return '';
137 }
138
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 }
146
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 }
164
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">';
166
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, false, $id);
171 if(empty($image[0])) {$image = array($attachment_url,$imgsize,$imgsize);}
172 $img_srcset_output = kt_toolkit_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];
176 }
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 }
187
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>';
192 }
193 $output .= '</div>';
194
195 return $output;
196 }
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 }
204 }