PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.40
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.40
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 / Admin / Wizard / Instagram.php

Instagram.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.40, at Admin/Wizard/Instagram.php

219 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Photonic_Plugin\Admin\Wizard;
3
4 use Photonic_Plugin\Core\Utilities;
5
6 class Instagram extends Source {
7 private static $instance;
8
9 protected function __construct() {
10 parent::__construct();
11 $this->provider = 'instagram';
12 }
13
14 public static function get_instance() {
15 if (self::$instance == null) {
16 self::$instance = new Instagram();
17 }
18 return self::$instance;
19 }
20
21 function get_screen_2() {
22 return [
23 'header' => esc_html__('Choose Type of Gallery', 'photonic'),
24 'display' => [
25 'display_type' => [
26 'desc' => esc_html__('What do you want to show?', 'photonic'),
27 'type' => 'select',
28 'options' => [
29 '' => '',
30 'single-photo' => esc_html__('Single Photo', 'photonic'),
31 'album-photo' => esc_html__('Photos in a Post', 'photonic'),
32 'multi-photo' => esc_html__('Multiple Photos', 'photonic'),
33 ],
34 'req' => 1,
35 ],
36 ],
37 ];
38 }
39
40 function get_screen_3() {
41 return [
42 'header' => esc_html__('Build your gallery', 'photonic'),
43 'single-photo' => [
44 'header' => esc_html__('Pick a photo', 'photonic'),
45 'desc' => esc_html__('From the list below pick the single photo you wish to display.', 'photonic'),
46 'display' => [
47 'embed_type' => [
48 'desc' => esc_html__('How do you want to display your photo?', 'photonic'),
49 'type' => 'select',
50 'options' => [
51 '' => '',
52 'embed' => esc_html__('Show as an "Instagram embed"', 'photonic'),
53 'integrate' => esc_html__('Show similar to other photos, without embedding Instagram', 'photonic'),
54 ],
55 'std' => '',
56 ],
57 'container' => [
58 'type' => 'thumbnail-selector',
59 'mode' => 'single',
60 'for' => 'selected_data',
61 ],
62 ],
63 ],
64 'album-photo' => [
65 'header' => esc_html__('Pick a post (a.k.a. Carousel)', 'photonic'),
66 'desc' => esc_html__('From the list below pick the post whose photos you wish to display.', 'photonic'),
67 'display' => [
68 'container' => [
69 'type' => 'thumbnail-selector',
70 'mode' => 'single',
71 'for' => 'selected_data',
72 ],
73 ],
74 ],
75 'multi-photo' => [
76 'header' => esc_html__('All your photos', 'photonic'),
77 'desc' => esc_html__('You can only show all your photos without filtering. In the following only the latest 25 photos are displayed. You can change this in subsequent screens.', 'photonic'),
78 'display' => [
79 'carousel_handling' => [
80 'desc' => esc_html__('How do you want to show photos in a carousel?', 'photonic'),
81 'type' => 'select',
82 'options' => [
83 '' => '',
84 'single' => esc_html__('Show first photo', 'photonic'),
85 'expand' => esc_html__('Show all photos', 'photonic'),
86 ],
87 'std' => '',
88 ],
89 'container' => [
90 'type' => 'thumbnail-selector',
91 'mode' => 'none',
92 'for' => 'selected_data',
93 ],
94 ],
95 ],
96 ];
97 }
98
99 function get_screen_4() {
100 return [];
101 }
102
103 function get_screen_5() {
104 global $photonic_instagram_media;
105 return [
106 'instagram' => [
107 'media' => [
108 'desc' => esc_html__('Media to Show', 'photonic'),
109 'type' => 'select',
110 'options' => Utilities::media_options(true, $photonic_instagram_media),
111 'std' => '',
112 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Instagram &rarr; Instagram Settings &rarr; Media to show</em>'),
113 ],
114 ]
115 ];
116 }
117
118 function get_square_size_options() {
119 return [];
120 }
121
122 function get_random_size_options() {
123 return [];
124 }
125
126 function make_request($display_type, $for, $flattened_fields) {
127 require_once(PHOTONIC_PATH.'/Modules/Instagram.php');
128 $module = \Photonic_Plugin\Modules\Instagram::get_instance();
129 $base_url = 'https://graph.instagram.com/me/media?fields='.$module->field_list.'&access_token='.$module->access_token;
130 $response = wp_remote_request($base_url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
131
132 return [$response, [], $base_url];
133 }
134
135 /**
136 * Processes a response from Instagram to build it out into a gallery of thumbnails. Instagram only has L1 displays.
137 *
138 * @param $response
139 * @param $display_type
140 * @param $url
141 * @param array $pagination
142 * @return array
143 */
144 function process_response($response, $display_type, $url = null, &$pagination = []) {
145 $objects = [];
146 $body = json_decode($response['body']);
147 if (isset($body->data)) {
148 $data = $body->data;
149 foreach ($data as $photo) {
150 if (isset($photo->media_type) && (strtolower($photo->media_type) == 'image' || strtolower($photo->media_type) == 'carousel_album' || strtolower($photo->media_type) == 'video')) {
151 if (($display_type == 'album-photo' && strtolower($photo->media_type) == 'carousel_album') || $display_type != 'album-photo') {
152 $object = [];
153 $link = $photo->permalink;
154 $link = explode('/', $link);
155 if (empty($link[count($link) - 1])) {
156 $link = $link[count($link) - 2];
157 }
158 else {
159 $link = $link[count($link) - 1];
160 }
161 $object['alt_id'] = $link;
162 $object['id'] = $photo->id;
163 if (isset($photo->caption)) {
164 $object['title'] = esc_attr($photo->caption);
165 }
166 else {
167 $object['title'] = '';
168 }
169 $object['thumbnail'] = empty($photo->thumbnail_url) ? $photo->media_url : $photo->thumbnail_url;
170 $objects[] = $object;
171 }
172 }
173 }
174 if (isset($body->pagination) && isset($body->pagination->next_max_id) && $display_type == 'single-photo') {
175 $pagination['url'] = add_query_arg(['max_id' => $body->pagination->next_max_id], remove_query_arg(['max_id'], $url));
176 }
177 }
178 return $objects;
179 }
180
181 /**
182 * @param $display_type
183 * @return array|mixed
184 */
185 function construct_shortcode_from_screen_selections($display_type) {
186 $short_code = [];
187
188 if ($display_type == 'single-photo') {
189 $short_code['media_id'] = sanitize_text_field($_POST['selected_data']);
190 }
191 else if ($display_type == 'album-photo') {
192 $short_code['carousel'] = sanitize_text_field($_POST['selected_data']);
193 }
194
195 return $short_code;
196 }
197
198 /**
199 * @param $input
200 * @return array|mixed
201 */
202 function deconstruct_shortcode_to_screen_selections($input) {
203 $deconstructed = [];
204
205 if (!empty($input->media_id)) {
206 $deconstructed['display_type'] = 'single-photo';
207 $deconstructed['selected_data'] = $input->media_id;
208 }
209 else if (!empty($input->carousel)) {
210 $deconstructed['display_type'] = 'album-photo';
211 $deconstructed['selected_data'] = $input->carousel;
212 }
213 else {
214 $deconstructed['display_type'] = 'multi-photo';
215 }
216
217 return $deconstructed;
218 }
219 }