PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.19
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.19
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.19, at extensions/Photonic_Native_Processor.php

216 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 = array(
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 * @return array|bool
28 */
29 function get_gallery_images($attr = array()) {
30 global $post, $photonic_wp_title_caption;
31
32 $this->gallery_index++;
33 $this->push_to_stack('Get Gallery Images');
34 // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
35 if (isset($attr['orderby'])) {
36 $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
37 if (!$attr['orderby'])
38 unset($attr['orderby']);
39 }
40
41 if (!empty($attr['ids'])) {
42 // 'ids' is explicitly ordered, unless you specify otherwise.
43 if (empty($attr['orderby'])) {
44 $attr['orderby'] = 'post__in';
45 }
46 $attr['include'] = $attr['ids'];
47 }
48
49 $html5 = current_theme_supports( 'html5', 'gallery' );
50 $attr = array_merge(
51 $this->common_parameters,
52 array(
53 'caption' => $photonic_wp_title_caption,
54
55 'order' => 'ASC',
56 'orderby' => 'menu_order ID',
57 'id' => $post->ID,
58 'itemtag' => $html5 ? 'figure' : 'dl',
59 'icontag' => $html5 ? 'div' : 'dt',
60 'captiontag' => $html5 ? 'figcaption' : 'dd',
61 'size' => 'thumbnail',
62 'include' => '',
63 'exclude' => '',
64
65 'page' => 1,
66 'count' => -1,
67
68 'thumb_width' => 75,
69 'thumb_height' => 75,
70 'thumb_size' => 'thumbnail',
71 'slide_size' => 'large',
72 'slideshow_height' => 500,
73
74 'controls' => 'hide',
75 ), $attr);
76
77 $attr['layout'] = $attr['style'];
78 $attr['main_size'] = !empty($attr['main_size']) ? $attr['main_size'] : $attr['slide_size'];
79
80 $attr = array_map('trim', $attr);
81 extract($attr);
82
83 $id = intval($attr['id']);
84 if ('RAND' == $attr['order'])
85 $attr['orderby'] = 'none';
86
87 // All arguments can be overridden by the standard pre_get_posts filter ...
88 $args = array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => array('image'), 'order' => $attr['order'], 'orderby' => $attr['orderby'], 'paged' => $attr['page']);
89
90 if (!empty($attr['include'])) {
91 $include = preg_replace('/[^0-9,]+/', '', $attr['include']);
92 $args['include'] = $include;
93 $attr['count'] = -1; // 'include' always ignores the 'posts_per_page'. Having the original value here shows the "More" button even when not required.
94 $_attachments = get_posts($args);
95 $total_posts = count($_attachments);
96
97 $attachments = array();
98 foreach ($_attachments as $key => $val) {
99 $attachments[$val->ID] = $_attachments[$key];
100 }
101 }
102 else {
103 $args['post_parent'] = $id;
104 if (!empty($attr['exclude'])) {
105 $exclude = preg_replace('/[^0-9,]+/', '', $attr['exclude']);
106 $args['exclude'] = $exclude;
107 }
108 // First get the total
109 $attachments = get_children($args);
110 $total_posts = count($attachments);
111
112 $args['posts_per_page'] = $attr['count'];
113 $attachments = get_children($args);
114 }
115
116 $ret = $this->process_gallery($attachments, $attr, $total_posts);
117 $this->pop_from_stack();
118 if (empty($ret)) {
119 return $ret;
120 }
121 return $ret.$this->get_stack_markup();
122 }
123
124 function build_level_1_objects($images, $shortcode_attr) {
125 $photo_objects = array();
126 $thumb_size = $shortcode_attr['thumb_size'];
127 $main_size = $shortcode_attr['main_size'];
128 $tile_size = !empty($shortcode_attr['tile_size']) ? $shortcode_attr['tile_size'] : $main_size;
129 $sources = array();
130 $tiles = array();
131 $thumbs = array();
132 foreach ( $images as $id => $attachment ) {
133 $wp_details = wp_prepare_attachment_for_js($id);
134 $sources[$id] = wp_get_attachment_image_src($id, $main_size, false);
135 $tiles[$id] = wp_get_attachment_image_src($id, $tile_size, false);
136 $thumbs[$id] = wp_get_attachment_image_src($id, $thumb_size);
137
138 if (isset($attachment->post_title)) {
139 $title = wptexturize($attachment->post_title);
140 }
141 else {
142 $title = '';
143 }
144 $title = apply_filters('photonic_modify_title', $title, $attachment);
145
146 if (is_array($wp_details)) {
147 $photo_object = array();
148 $photo_object['thumbnail'] = $thumbs[$id][0];
149 $photo_object['main_image'] = $sources[$id][0];
150 $photo_object['tile_image'] = $tiles[$id][0];
151 $photo_object['title'] = esc_attr($title);
152 $photo_object['alt_title'] = $photo_object['title'];
153 $photo_object['description'] = esc_attr($wp_details['caption']);
154 $photo_object['main_page'] = $wp_details['link'];
155 $photo_object['id'] = $wp_details['id'];
156
157 if ($wp_details['type'] == 'video') {
158 $photo_object['video'] = $wp_details['url'];
159 }
160
161 $photo_object['provider'] = $this->provider;
162 $photo_object['gallery_index'] = $this->gallery_index;
163
164 $photo_objects[] = $photo_object;
165 }
166 }
167 return $photo_objects;
168 }
169
170 /**
171 * Builds the markup for a gallery when you choose to use a specific gallery style. The following styles are allowed:
172 * 1. strip-below: Shows thumbnails for the gallery below a larger image
173 * 2. strip-above: Shows thumbnails for the gallery above a larger image
174 * 3. no-strip: Doesn't show thumbnails. Useful if you are making it behave like an automatic slideshow.
175 * 4. launch: Shows a thumbnail for the gallery, which you can click to launch a slideshow.
176 * 5. random: Shows a random justified gallery.
177 *
178 * @param $attachments
179 * @param $shortcode_attr
180 * @param int $total_posts
181 * @return string
182 */
183 function process_gallery($attachments, $shortcode_attr, $total_posts = -1) {
184 global $photonic_wp_thumbnail_title_display;
185 if ($shortcode_attr['style'] == 'default') {
186 return '';
187 }
188 $photos = $this->build_level_1_objects($attachments, $shortcode_attr);
189
190 $row_constraints = array(
191 'constraint-type' => $shortcode_attr['columns'] == 'auto' ? 'padding' : 'count',
192 'padding' => 0,
193 'count' => absint($shortcode_attr['columns']) ? absint($shortcode_attr['columns']) : 3
194 );
195 $ret = $this->display_level_1_gallery($photos,
196 array(
197 'title_position' => $photonic_wp_thumbnail_title_display,
198 'row_constraints' => $row_constraints,
199 'parent' => 'stream',
200 'level_2_meta' => array(
201 'total' => $total_posts,
202 'start' => $shortcode_attr['count'] < 0 ? 1 : ($shortcode_attr['page'] - 1) * $shortcode_attr['count'] + 1,
203 'end' => ($shortcode_attr['count'] < 0 || $shortcode_attr['page'] * $shortcode_attr['count'] > $total_posts) ? $total_posts : $shortcode_attr['page'] * $shortcode_attr['count'],
204 'per-page' => $shortcode_attr['count'],
205 ),
206 ),
207 $shortcode_attr);
208 $ret = $this->finalize_markup($ret, $shortcode_attr);
209 return $ret;
210 }
211
212 function parse_token($response) {
213 return array();
214 }
215 }
216