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

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