PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.34
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.34
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
photonic / extensions / Photonic_Native_Processor.php

Photonic_Native_Processor.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.34, at extensions/Photonic_Native_Processor.php

206 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Processor for native WP galleries. This extends the Photonic_Processor class and defines methods local to WP.
4 *
5 * @package Photonic
6 * @subpackage Extensions
7 */
8
9 class Photonic_Native_Processor extends Photonic_Processor {
10 function __construct() {
11 parent::__construct();
12 global $photonic_wp_disable_title_link;
13 $this->provider = 'wp';
14 $this->link_lightbox_title = empty($photonic_wp_disable_title_link);
15 $this->doc_links = [
16 'general' => 'https://aquoid.com/plugins/photonic/wp-galleries/',
17 ];
18 }
19
20 /**
21 * Gets all images associated with the gallery. This method is lifted almost verbatim from the gallery short-code function provided by WP.
22 * We will take the gallery images and do some fun stuff with styling them in other methods. We cannot use the WP function because
23 * this code is nested within the gallery_shortcode function and we want to tweak that (there is no hook that executes after
24 * the gallery has been retrieved.)
25 *
26 * @param array $attr
27 * @param array $gallery_meta
28 * @return array|bool
29 */
30 function get_gallery_images($attr = [], &$gallery_meta = []) {
31 global $post, $photonic_wp_title_caption, $photonic_alternative_shortcode;
32
33 $this->gallery_index++;
34 $this->push_to_stack('Get Gallery Images');
35
36 // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
37 if (isset($attr['orderby'])) {
38 $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
39 if (!$attr['orderby'])
40 unset($attr['orderby']);
41 }
42
43 if (!empty($attr['ids'])) {
44 // 'ids' is explicitly ordered, unless you specify otherwise.
45 if (empty($attr['orderby'])) {
46 $attr['orderby'] = 'post__in';
47 }
48 $attr['include'] = $attr['ids'];
49 }
50
51 $html5 = current_theme_supports( 'html5', 'gallery' );
52 $attr = shortcode_atts([
53 'order' => 'ASC',
54 'orderby' => 'menu_order ID',
55 'id' => $post ? $post->ID : 0,
56 'itemtag' => $html5 ? 'figure' : 'dl',
57 'icontag' => $html5 ? 'div' : 'dt',
58 'captiontag' => $html5 ? 'figcaption' : 'dd',
59 'columns' => 3,
60 'size' => 'thumbnail',
61 'include' => '',
62 'exclude' => '',
63 'link' => ''
64 ], $attr, !empty($photonic_alternative_shortcode) ? $photonic_alternative_shortcode: 'gallery' );
65
66 $attr['layout'] = $attr['style'];
67 $attr['main_size'] = !empty($attr['main_size']) ? $attr['main_size'] : $attr['slide_size'];
68 $attr['caption'] = !empty($attr['caption']) ? $attr['caption'] : $photonic_wp_title_caption;
69
70 $attr = array_map('trim', $attr);
71 extract($attr);
72
73 $id = intval($attr['id']);
74 if ('RAND' == $attr['order'])
75 $attr['orderby'] = 'none';
76
77 // All arguments can be overridden by the standard pre_get_posts filter ...
78 $args = ['post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => ['image'], 'order' => $attr['order'], 'orderby' => $attr['orderby'], 'paged' => $attr['page']];
79
80 if (!empty($attr['include'])) {
81 $include = preg_replace('/[^0-9,]+/', '', $attr['include']);
82 $args['include'] = $include;
83 $attr['count'] = -1; // 'include' always ignores the 'posts_per_page'. Having the original value here shows the "More" button even when not required.
84 $_attachments = get_posts($args);
85 $total_posts = count($_attachments);
86
87 $attachments = [];
88 foreach ($_attachments as $key => $val) {
89 $attachments[$val->ID] = $_attachments[$key];
90 }
91 }
92 else {
93 $args['post_parent'] = $id;
94 if (!empty($attr['exclude'])) {
95 $exclude = preg_replace('/[^0-9,]+/', '', $attr['exclude']);
96 $args['exclude'] = $exclude;
97 }
98 // First get the total
99 $attachments = get_children($args);
100 $total_posts = count($attachments);
101
102 $args['posts_per_page'] = $attr['count'];
103 $attachments = get_children($args);
104 }
105
106 $ret = $this->process_gallery($attachments, $attr, $total_posts);
107 $this->pop_from_stack();
108 if (empty($ret)) {
109 return $ret;
110 }
111 return $ret.$this->get_stack_markup();
112 }
113
114 function build_level_1_objects($images, $shortcode_attr) {
115 $photo_objects = [];
116 $thumb_size = $shortcode_attr['thumb_size'];
117 $main_size = $shortcode_attr['main_size'];
118 $tile_size = !empty($shortcode_attr['tile_size']) ? $shortcode_attr['tile_size'] : $main_size;
119 $sources = [];
120 $tiles = [];
121 $thumbs = [];
122 foreach ( $images as $id => $attachment ) {
123 $wp_details = wp_prepare_attachment_for_js($id);
124 $sources[$id] = wp_get_attachment_image_src($id, $main_size, false);
125 $tiles[$id] = wp_get_attachment_image_src($id, $tile_size, false);
126 $thumbs[$id] = wp_get_attachment_image_src($id, $thumb_size);
127
128 if (isset($attachment->post_title)) {
129 $title = wptexturize($attachment->post_title);
130 }
131 else {
132 $title = '';
133 }
134 $title = apply_filters('photonic_modify_title', $title, $attachment);
135
136 if (is_array($wp_details)) {
137 $photo_object = [];
138 $photo_object['thumbnail'] = $thumbs[$id][0];
139 $photo_object['main_image'] = $sources[$id][0];
140 $photo_object['tile_image'] = $tiles[$id][0];
141 $photo_object['title'] = esc_attr($title);
142 $photo_object['alt_title'] = $photo_object['title'];
143 $photo_object['description'] = esc_attr($wp_details['caption']);
144 $photo_object['main_page'] = $wp_details['link'];
145 $photo_object['id'] = $wp_details['id'];
146
147 if ($wp_details['type'] == 'video') {
148 $photo_object['video'] = $wp_details['url'];
149 }
150
151 $photo_object['provider'] = $this->provider;
152 $photo_object['gallery_index'] = $this->gallery_index;
153
154 $photo_objects[] = $photo_object;
155 }
156 }
157 return $photo_objects;
158 }
159
160 /**
161 * Builds the markup for a gallery when you choose to use a specific gallery style. The following styles are allowed:
162 * 1. strip-below: Shows thumbnails for the gallery below a larger image
163 * 2. strip-above: Shows thumbnails for the gallery above a larger image
164 * 3. no-strip: Doesn't show thumbnails. Useful if you are making it behave like an automatic slideshow.
165 * 4. launch: Shows a thumbnail for the gallery, which you can click to launch a slideshow.
166 * 5. random: Shows a random justified gallery.
167 *
168 * @param $attachments
169 * @param $shortcode_attr
170 * @param int $total_posts
171 * @return string
172 */
173 function process_gallery($attachments, $shortcode_attr, $total_posts = -1) {
174 global $photonic_wp_thumbnail_title_display;
175 if ($shortcode_attr['style'] == 'default') {
176 return '';
177 }
178 $photos = $this->build_level_1_objects($attachments, $shortcode_attr);
179
180 $row_constraints = [
181 'constraint-type' => $shortcode_attr['columns'] == 'auto' ? 'padding' : 'count',
182 'padding' => 0,
183 'count' => absint($shortcode_attr['columns']) ? absint($shortcode_attr['columns']) : 3
184 ];
185 $ret = $this->display_level_1_gallery($photos,
186 [
187 'title_position' => $photonic_wp_thumbnail_title_display,
188 'row_constraints' => $row_constraints,
189 'parent' => 'stream',
190 'level_2_meta' => [
191 'total' => $total_posts,
192 'start' => $shortcode_attr['count'] < 0 ? 1 : ($shortcode_attr['page'] - 1) * $shortcode_attr['count'] + 1,
193 'end' => ($shortcode_attr['count'] < 0 || $shortcode_attr['page'] * $shortcode_attr['count'] > $total_posts) ? $total_posts : $shortcode_attr['page'] * $shortcode_attr['count'],
194 'per-page' => $shortcode_attr['count'],
195 ],
196 ],
197 $shortcode_attr);
198 $ret = $this->finalize_markup($ret, $shortcode_attr);
199 return $ret;
200 }
201
202 function add_hooks() {
203 // add_filter('use_default_gallery_style', '__return_false');
204 }
205 }
206