| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace Photonic_Plugin\Admin\Wizard; |
| 3 | 4 | |
| 4 | 5 | use Photonic_Plugin\Core\Photonic; |
| 5 | 6 | use Photonic_Plugin\Core\Utilities; |
| @@ -4,40 +5,51 @@ | ||
| 4 | 5 | use Photonic_Plugin\Core\Photonic; |
| 5 | 6 | use Photonic_Plugin\Core\Utilities; |
| 6 | 7 | |
| 7 | 8 | class Google_Photos extends Source { |
| 8 | - private static $instance; | |
| 9 | + private static ?Google_Photos $instance = null; | |
| 9 | 10 | |
| 11 | + private $notice; | |
| 12 | + | |
| 10 | 13 | protected function __construct() { |
| 11 | 14 | parent::__construct(); |
| 12 | 15 | $this->provider = 'google'; |
| 16 | + $this->api_base = Wizard::base_apis()['google']; | |
| 17 | + $this->notice = sprintf( | |
| 18 | + esc_html__('%1$sAPI Shutdown%2$s%3$sGoogle is making a change to its APIs, which make them unusable for browsing on the web. This will prevent Photonic from working after %1$s31st March 2025%2$s. Please switch to a different platform to avoid disruption.%4$s', 'photonic'), | |
| 19 | + '<strong>', | |
| 20 | + '</strong>', | |
| 21 | + '<p>', | |
| 22 | + '</p>' | |
| 23 | + ); | |
| 24 | + | |
| 13 | 25 | $this->allowed_image_sizes['google'] = [ |
| 14 | 26 | 'thumb_size' => [ |
| 15 | - '32' => '32', | |
| 16 | - '48' => 48, | |
| 17 | - '64' => 64, | |
| 18 | - '72' => 72, | |
| 27 | + '32' => '32', | |
| 28 | + '48' => 48, | |
| 29 | + '64' => 64, | |
| 30 | + '72' => 72, | |
| 19 | 31 | '104' => 104, |
| 20 | 32 | '144' => 144, |
| 21 | 33 | '150' => 150, |
| 22 | 34 | '160' => 160, |
| 23 | 35 | ], |
| 24 | - 'tile_size' => [ | |
| 36 | + 'tile_size' => [ | |
| 25 | 37 | 'same' => esc_html__('Same as Main image size', 'photonic'), |
| 26 | - '94' => 94, | |
| 27 | - '110' => 110, | |
| 28 | - '128' => 128, | |
| 29 | - '200' => 200, | |
| 30 | - '220' => 220, | |
| 31 | - '288' => 288, | |
| 32 | - '320' => 320, | |
| 33 | - '400' => 400, | |
| 34 | - '512' => 512, | |
| 35 | - '576' => 576, | |
| 36 | - '640' => 640, | |
| 37 | - '720' => 720, | |
| 38 | - '800' => 800, | |
| 39 | - '912' => 912, | |
| 38 | + '94' => 94, | |
| 39 | + '110' => 110, | |
| 40 | + '128' => 128, | |
| 41 | + '200' => 200, | |
| 42 | + '220' => 220, | |
| 43 | + '288' => 288, | |
| 44 | + '320' => 320, | |
| 45 | + '400' => 400, | |
| 46 | + '512' => 512, | |
| 47 | + '576' => 576, | |
| 48 | + '640' => 640, | |
| 49 | + '720' => 720, | |
| 50 | + '800' => 800, | |
| 51 | + '912' => 912, | |
| 40 | 52 | '1024' => 1024, |
| 41 | 53 | '1152' => 1152, |
| 42 | 54 | '1280' => 1280, |
| 43 | 55 | '1440' => 1440, |
| @@ -42,23 +54,23 @@ | ||
| 42 | 54 | '1280' => 1280, |
| 43 | 55 | '1440' => 1440, |
| 44 | 56 | '1600' => 1600, |
| 45 | 57 | ], |
| 46 | - 'main_size' => [ | |
| 47 | - '94' => 94, | |
| 48 | - '110' => 110, | |
| 49 | - '128' => 128, | |
| 50 | - '200' => 200, | |
| 51 | - '220' => 220, | |
| 52 | - '288' => 288, | |
| 53 | - '320' => 320, | |
| 54 | - '400' => 400, | |
| 55 | - '512' => 512, | |
| 56 | - '576' => 576, | |
| 57 | - '640' => 640, | |
| 58 | - '720' => 720, | |
| 59 | - '800' => 800, | |
| 60 | - '912' => 912, | |
| 58 | + 'main_size' => [ | |
| 59 | + '94' => 94, | |
| 60 | + '110' => 110, | |
| 61 | + '128' => 128, | |
| 62 | + '200' => 200, | |
| 63 | + '220' => 220, | |
| 64 | + '288' => 288, | |
| 65 | + '320' => 320, | |
| 66 | + '400' => 400, | |
| 67 | + '512' => 512, | |
| 68 | + '576' => 576, | |
| 69 | + '640' => 640, | |
| 70 | + '720' => 720, | |
| 71 | + '800' => 800, | |
| 72 | + '912' => 912, | |
| 61 | 73 | '1024' => 1024, |
| 62 | 74 | '1152' => 1152, |
| 63 | 75 | '1280' => 1280, |
| 64 | 76 | '1440' => 1440, |
| @@ -66,50 +78,53 @@ | ||
| 66 | 78 | ], |
| 67 | 79 | ]; |
| 68 | 80 | } |
| 69 | 81 | |
| 70 | - public static function get_instance() { | |
| 71 | - if (self::$instance == null) { | |
| 82 | + public static function get_instance(): Google_Photos { | |
| 83 | + if (null === self::$instance) { | |
| 72 | 84 | self::$instance = new Google_Photos(); |
| 73 | 85 | } |
| 74 | 86 | return self::$instance; |
| 75 | 87 | } |
| 76 | 88 | |
| 77 | - function get_screen_2() { | |
| 89 | + public function get_screen_2(): array { | |
| 78 | 90 | return [ |
| 79 | - 'header' => esc_html__('Choose Type of Gallery', 'photonic'), | |
| 91 | + 'header' => esc_html__('Choose Type of Gallery', 'photonic'), | |
| 92 | + 'notice' => $this->notice, | |
| 80 | 93 | 'display' => [ |
| 81 | 94 | 'display_type' => [ |
| 82 | - 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 83 | - 'type' => 'select', | |
| 95 | + 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 96 | + 'type' => 'select', | |
| 84 | 97 | 'options' => [ |
| 85 | - '' => '', | |
| 86 | - 'multi-photo' => esc_html__('Multiple Photos', 'photonic'), | |
| 87 | - 'album-photo' => esc_html__('Photos from an Album', 'photonic'), | |
| 88 | - 'multi-album' => esc_html__('Multiple Albums', 'photonic'), | |
| 98 | + '' => '', | |
| 99 | + 'multi-photo' => esc_html__('Multiple Photos', 'photonic'), | |
| 100 | + 'album-photo' => esc_html__('Photos from an Album Belonging to You', 'photonic'), | |
| 101 | + 'shared-album-photo' => esc_html__('Photos from an Album Shared by or with You', 'photonic'), | |
| 102 | + 'multi-album' => esc_html__('Multiple Albums', 'photonic'), | |
| 89 | 103 | ], |
| 90 | - 'req' => 1, | |
| 104 | + 'req' => 1, | |
| 91 | 105 | ], |
| 92 | 106 | ], |
| 93 | 107 | ]; |
| 94 | 108 | } |
| 95 | 109 | |
| 96 | - function get_screen_3() { | |
| 110 | + public function get_screen_3(): array { | |
| 97 | 111 | return [ |
| 98 | - 'header' => esc_html__('Build your gallery', 'photonic'), | |
| 99 | - 'multi-photo' => [ | |
| 100 | - 'header' => esc_html__('All your photos', 'photonic'), | |
| 101 | - 'desc' => esc_html__('You can show all your photos, or apply filters to show some of them.', 'photonic'), | |
| 112 | + 'header' => esc_html__('Build your gallery', 'photonic'), | |
| 113 | + 'multi-photo' => [ | |
| 114 | + 'header' => esc_html__('All your photos', 'photonic'), | |
| 115 | + 'notice' => $this->notice, | |
| 116 | + 'desc' => esc_html__('You can show all your photos, or apply filters to show some of them.', 'photonic'), | |
| 102 | 117 | 'display' => [ |
| 103 | 118 | 'date_filters' => [ |
| 104 | - 'desc' => esc_html__('Date Filters', 'photonic'), | |
| 105 | - 'type' => 'date-filter', | |
| 119 | + 'desc' => esc_html__('Date Filters', 'photonic'), | |
| 120 | + 'type' => 'date-filter', | |
| 106 | 121 | 'count' => 5 |
| 107 | 122 | ], |
| 108 | 123 | |
| 109 | 124 | 'date_range_filters' => [ |
| 110 | - 'desc' => esc_html__('Date Range Filters', 'photonic'), | |
| 111 | - 'type' => 'date-range-filter', | |
| 125 | + 'desc' => esc_html__('Date Range Filters', 'photonic'), | |
| 126 | + 'type' => 'date-range-filter', | |
| 112 | 127 | 'count' => 5 |
| 113 | 128 | ], |
| 114 | 129 | |
| 115 | 130 | 'content_filters' => [ |
| @@ -114,61 +129,77 @@ | ||
| 114 | 129 | |
| 115 | 130 | 'content_filters' => [ |
| 116 | 131 | 'desc' => esc_html__('Content Filters', 'photonic'), |
| 117 | 132 | 'type' => 'text', |
| 118 | - 'hint' => sprintf(esc_html__('Comma-separated. Pick from: %s. Filters will be applied on the front-end, not on the display below. ', 'photonic'), | |
| 119 | - 'NONE, LANDSCAPES, RECEIPTS, CITYSCAPES, LANDMARKS, SELFIES, PEOPLE, PETS, WEDDINGS, BIRTHDAYS, DOCUMENTS, TRAVEL, ANIMALS, FOOD, SPORT, NIGHT, PERFORMANCES, WHITEBOARDS, SCREENSHOTS, UTILITY'). | |
| 120 | - Photonic::doc_link("https://aquoid.com/plugins/photonic/google-photos/photos/#filtering-photos"), | |
| 133 | + 'hint' => sprintf( | |
| 134 | + esc_html__('Comma-separated. Pick from: %s. Filters will be applied on the front-end, not on the display below. ', 'photonic'), | |
| 135 | + 'NONE, LANDSCAPES, RECEIPTS, CITYSCAPES, LANDMARKS, SELFIES, PEOPLE, PETS, WEDDINGS, BIRTHDAYS, DOCUMENTS, TRAVEL, ANIMALS, FOOD, SPORT, NIGHT, PERFORMANCES, WHITEBOARDS, SCREENSHOTS, UTILITY' | |
| 136 | + ) . | |
| 137 | + Photonic::doc_link("https://aquoid.com/plugins/photonic/google-photos/photos/#filtering-photos"), | |
| 121 | 138 | ], |
| 122 | 139 | |
| 123 | 140 | 'container' => [ |
| 124 | 141 | 'type' => 'thumbnail-selector', |
| 125 | 142 | 'mode' => 'none', |
| 126 | - 'for' => 'selected_data', | |
| 143 | + 'for' => 'selected_data', | |
| 127 | 144 | ], |
| 128 | 145 | ], |
| 129 | 146 | ], |
| 130 | - 'album-photo' => [ | |
| 131 | - 'header' => esc_html__('Pick your album', 'photonic'), | |
| 132 | - 'desc' => esc_html__('From the list below pick the album whose photos you wish to display. Photos from that album will show up as thumbnails.', 'photonic'), | |
| 147 | + 'album-photo' => [ | |
| 148 | + 'header' => esc_html__('Pick your album', 'photonic'), | |
| 149 | + 'notice' => $this->notice, | |
| 150 | + 'desc' => esc_html__('From the list below pick the album whose photos you wish to display. Photos from that album will show up as thumbnails.', 'photonic'), | |
| 133 | 151 | 'display' => [ |
| 134 | 152 | 'container' => [ |
| 135 | 153 | 'type' => 'thumbnail-selector', |
| 136 | 154 | 'mode' => 'single', |
| 137 | - 'for' => 'selected_data', | |
| 155 | + 'for' => 'selected_data', | |
| 138 | 156 | ], |
| 139 | 157 | ], |
| 140 | 158 | ], |
| 141 | - 'multi-album' => [ | |
| 142 | - 'header' => esc_html__('Pick your albums', 'photonic'), | |
| 143 | - 'desc' => esc_html__('From the list below pick the albums you wish to display. Each album will show up as a single thumbnail.', 'photonic'), | |
| 159 | + 'shared-album-photo' => [ | |
| 160 | + 'header' => esc_html__('Pick your album', 'photonic'), | |
| 161 | + 'notice' => $this->notice, | |
| 162 | + 'desc' => esc_html__('From the list below pick the album whose photos you wish to display. Photos from that album will show up as thumbnails.', 'photonic'), | |
| 144 | 163 | 'display' => [ |
| 164 | + 'container' => [ | |
| 165 | + 'type' => 'thumbnail-selector', | |
| 166 | + 'mode' => 'single', | |
| 167 | + 'for' => 'selected_data', | |
| 168 | + ], | |
| 169 | + ], | |
| 170 | + ], | |
| 171 | + 'multi-album' => [ | |
| 172 | + 'header' => esc_html__('Pick your albums', 'photonic'), | |
| 173 | + 'notice' => $this->notice, | |
| 174 | + 'desc' => esc_html__('From the list below pick the albums you wish to display. Each album will show up as a single thumbnail.', 'photonic'), | |
| 175 | + 'display' => [ | |
| 145 | 176 | 'selection' => [ |
| 146 | - 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 147 | - 'type' => 'select', | |
| 177 | + 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 178 | + 'type' => 'select', | |
| 148 | 179 | 'options' => [ |
| 149 | - 'all' => esc_html__('Automatic all (will automatically add new albums)', 'photonic'), | |
| 150 | - 'selected' => esc_html__('Selected albums', 'photonic'), | |
| 180 | + 'all' => esc_html__('Automatic all (will automatically add new albums)', 'photonic'), | |
| 181 | + 'selected' => esc_html__('Selected albums', 'photonic'), | |
| 151 | 182 | 'not-selected' => esc_html__('All except selected albums', 'photonic'), |
| 152 | 183 | ], |
| 153 | - 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'), | |
| 154 | - 'req' => 1, | |
| 184 | + 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'), | |
| 185 | + 'req' => 1, | |
| 155 | 186 | ], |
| 156 | - 'access' => [ | |
| 157 | - 'desc' => esc_html__('What type of album?', 'photonic'), | |
| 158 | - 'type' => 'select', | |
| 187 | + 'access' => [ | |
| 188 | + 'desc' => esc_html__('What type of album?', 'photonic'), | |
| 189 | + 'type' => 'select', | |
| 159 | 190 | 'options' => [ |
| 160 | - '' => '', | |
| 161 | - 'all' => esc_html__('Show both shared and not shared albums', 'photonic'), | |
| 162 | - 'shared' => esc_html__('Only show shared albums', 'photonic'), | |
| 191 | + '' => '', | |
| 192 | + 'all' => esc_html__('Show both shared and not shared albums', 'photonic'), | |
| 193 | + 'shared' => esc_html__('Only show shared albums', 'photonic'), | |
| 163 | 194 | 'not-shared' => esc_html__('Only show albums not shared', 'photonic'), |
| 164 | 195 | ], |
| 165 | - 'std' => '', | |
| 196 | + 'std' => '', | |
| 166 | 197 | ], |
| 167 | 198 | 'container' => [ |
| 168 | 199 | 'type' => 'thumbnail-selector', |
| 169 | 200 | 'mode' => 'multi', |
| 170 | - 'for' => 'selected_data', | |
| 201 | + 'for' => 'selected_data', | |
| 171 | 202 | ], |
| 172 | 203 | ], |
| 173 | 204 | ], |
| 174 | 205 | ]; |
| @@ -173,41 +204,41 @@ | ||
| 173 | 204 | ], |
| 174 | 205 | ]; |
| 175 | 206 | } |
| 176 | 207 | |
| 177 | - function get_screen_4() { | |
| 208 | + public function get_screen_4(): array { | |
| 178 | 209 | return []; |
| 179 | 210 | } |
| 180 | 211 | |
| 181 | - function get_screen_5() { | |
| 212 | + public function get_screen_5(): array { | |
| 182 | 213 | global $photonic_google_media; |
| 183 | 214 | return [ |
| 184 | 215 | 'google' => [ |
| 185 | - 'L1' => [ | |
| 216 | + 'L1' => [ | |
| 186 | 217 | 'media' => [ |
| 187 | - 'desc' => esc_html__('Media to Show', 'photonic'), | |
| 188 | - 'type' => 'select', | |
| 218 | + 'desc' => esc_html__('Media to Show', 'photonic'), | |
| 219 | + 'type' => 'select', | |
| 189 | 220 | 'options' => Utilities::media_options(true, $photonic_google_media), |
| 190 | - 'std' => '', | |
| 191 | - 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Google Photos → Google Photos settings → Media to show</em>'), | |
| 221 | + 'std' => '', | |
| 222 | + 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Google Photos → Google Photos settings → Media to show</em>'), | |
| 192 | 223 | ], |
| 193 | 224 | |
| 194 | 225 | 'caption' => [ |
| 195 | - 'desc' => esc_html__('Photo titles and captions', 'photonic'), | |
| 196 | - 'type' => 'select', | |
| 226 | + 'desc' => esc_html__('Photo titles and captions', 'photonic'), | |
| 227 | + 'type' => 'select', | |
| 197 | 228 | 'options' => [ |
| 198 | - '' => $this->default_from_settings, | |
| 199 | - 'none' => esc_html__('No title / caption / description', 'photonic'), | |
| 229 | + '' => $this->default_from_settings, | |
| 230 | + 'none' => esc_html__('No title / caption / description', 'photonic'), | |
| 200 | 231 | 'title' => esc_html__('Always use the photo title, even if blank', 'photonic'), |
| 201 | 232 | ], |
| 202 | - 'std' => '', | |
| 203 | - 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Google Photos → Google Photos Settings → Photo titles and captions</em>'), | |
| 233 | + 'std' => '', | |
| 234 | + 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Google Photos → Google Photos Settings → Photo titles and captions</em>'), | |
| 204 | 235 | ], |
| 205 | 236 | ], |
| 206 | 237 | 'main_size' => [ |
| 207 | 238 | 'desc' => esc_html__('Main image size', 'photonic'), |
| 208 | 239 | 'type' => 'text', |
| 209 | - 'std' => 1600, | |
| 240 | + 'std' => 1600, | |
| 210 | 241 | 'hint' => esc_html__('Numeric values between 1 and 16383, both inclusive.', 'photonic'), |
| 211 | 242 | ], |
| 212 | 243 | ] |
| 213 | 244 | ]; |
| @@ -212,30 +243,30 @@ | ||
| 212 | 243 | ] |
| 213 | 244 | ]; |
| 214 | 245 | } |
| 215 | 246 | |
| 216 | - function get_square_size_options() { | |
| 247 | + public function get_square_size_options(): array { | |
| 217 | 248 | return [ |
| 218 | 249 | 'thumb_size' => [ |
| 219 | 250 | 'desc' => esc_html__('Thumbnail size', 'photonic'), |
| 220 | 251 | 'type' => 'text', |
| 221 | 252 | 'hint' => esc_html__('Numeric values between 1 and 256, both inclusive.', 'photonic'), |
| 222 | - 'std' => 150, | |
| 253 | + 'std' => 150, | |
| 223 | 254 | ], |
| 224 | 255 | 'crop_thumb' => [ |
| 225 | - 'desc' => esc_html__('Crop Thumbnail', 'photonic'), | |
| 226 | - 'type' => 'select', | |
| 256 | + 'desc' => esc_html__('Crop Thumbnail', 'photonic'), | |
| 257 | + 'type' => 'select', | |
| 227 | 258 | 'options' => [ |
| 228 | - 'crop' => esc_html__('Crop the thumbnail', 'photonic'), | |
| 259 | + 'crop' => esc_html__('Crop the thumbnail', 'photonic'), | |
| 229 | 260 | 'no-crop' => esc_html__('Do not crop the thumbnail', 'photonic'), |
| 230 | 261 | ], |
| 231 | - 'std' => 'crop', | |
| 232 | - 'hint' => esc_html__('Cropping the thumbnail presents you with a square thumbnail.', 'photonic') | |
| 262 | + 'std' => 'crop', | |
| 263 | + 'hint' => esc_html__('Cropping the thumbnail presents you with a square thumbnail.', 'photonic') | |
| 233 | 264 | ], |
| 234 | 265 | ]; |
| 235 | 266 | } |
| 236 | 267 | |
| 237 | - function get_random_size_options() { | |
| 268 | + public function get_random_size_options(): array { | |
| 238 | 269 | return [ |
| 239 | 270 | 'tile_size' => [ |
| 240 | 271 | 'desc' => esc_html__('Tile size', 'photonic'), |
| 241 | 272 | 'type' => 'text', |
| @@ -243,13 +274,13 @@ | ||
| 243 | 274 | ], |
| 244 | 275 | ]; |
| 245 | 276 | } |
| 246 | 277 | |
| 247 | - function make_request($display_type, $for, $flattened_fields) { | |
| 278 | + public function make_request($display_type, $for, $flattened_fields): array { | |
| 248 | 279 | global $photonic_google_refresh_token; |
| 249 | 280 | |
| 250 | - require_once(PHOTONIC_PATH.'/Modules/Google_Photos.php'); | |
| 251 | - $module = \Photonic_Plugin\Modules\Google_Photos::get_instance(); | |
| 281 | + require_once PHOTONIC_PATH . '/Platforms/Google_Photos.php'; | |
| 282 | + $module = \Photonic_Plugin\Platforms\Google_Photos::get_instance(); | |
| 252 | 283 | $module->authenticate($photonic_google_refresh_token); |
| 253 | 284 | |
| 254 | 285 | $parameters = []; |
| 255 | 286 | |
| @@ -256,17 +287,20 @@ | ||
| 256 | 287 | // All OK so far. Let's try to get the data for the next screen |
| 257 | 288 | $parameters['access_token'] = $module->access_token; |
| 258 | 289 | |
| 259 | 290 | $query_url = ''; |
| 260 | - if ($display_type == 'multi-photo') { | |
| 261 | - $query_url = 'https://photoslibrary.googleapis.com/v1/mediaItems:search'; | |
| 291 | + if ('multi-photo' === $display_type) { | |
| 292 | + $query_url = 'https://' . $this->api_base . '/v1/mediaItems:search'; | |
| 262 | 293 | } |
| 263 | - else if ($display_type == 'multi-album' || $display_type == 'album-photo') { | |
| 264 | - $query_url = 'https://photoslibrary.googleapis.com/v1/albums?pageSize=50'; | |
| 294 | + elseif ('multi-album' === $display_type || 'album-photo' === $display_type) { | |
| 295 | + $query_url = 'https://' . $this->api_base . '/v1/albums?pageSize=50'; | |
| 265 | 296 | } |
| 297 | + elseif ('shared-album-photo' === $display_type) { | |
| 298 | + $query_url = 'https://' . $this->api_base . '/v1/sharedAlbums?pageSize=50'; | |
| 299 | + } | |
| 266 | 300 | |
| 267 | 301 | $query_url = add_query_arg($parameters, $query_url); |
| 268 | - $response = wp_remote_request($query_url, ['method' => ($display_type == 'multi-photo' ? 'POST' : 'GET'), 'sslverify' => PHOTONIC_SSL_VERIFY]); | |
| 302 | + $response = wp_remote_request($query_url, ['method' => ('multi-photo' === $display_type ? 'POST' : 'GET'), 'sslverify' => PHOTONIC_SSL_VERIFY]); | |
| 269 | 303 | return [$response, [], $query_url]; |
| 270 | 304 | } |
| 271 | 305 | |
| 272 | 306 | /** |
| @@ -277,13 +311,13 @@ | ||
| 277 | 311 | * @param $url |
| 278 | 312 | * @param array $pagination |
| 279 | 313 | * @return array |
| 280 | 314 | */ |
| 281 | - function process_response($response, $display_type, $url = null, &$pagination = []) { | |
| 315 | + public function process_response($response, $display_type, $url = null, &$pagination = []): array { | |
| 282 | 316 | $objects = []; |
| 283 | 317 | $body = json_decode(wp_remote_retrieve_body($response)); |
| 284 | - if (isset($body->albums)) { | |
| 285 | - $albums = $body->albums; | |
| 318 | + if (isset($body->albums) || isset($body->sharedAlbums)) { | |
| 319 | + $albums = isset($body->albums) ? $body->albums : $body->sharedAlbums; | |
| 286 | 320 | foreach ($albums as $album) { |
| 287 | 321 | $object = []; |
| 288 | 322 | $object['id'] = $album->id; |
| 289 | 323 | $object['title'] = !empty($album->title) ? esc_attr($album->title) : ''; |
| @@ -294,9 +328,9 @@ | ||
| 294 | 328 | if (!empty($body->nextPageToken)) { |
| 295 | 329 | $pagination['url'] = add_query_arg(['pageToken' => $body->nextPageToken], remove_query_arg(['pageToken'], $url)); |
| 296 | 330 | } |
| 297 | 331 | } |
| 298 | - else if (isset($body->mediaItems)) { | |
| 332 | + elseif (isset($body->mediaItems)) { | |
| 299 | 333 | $photos = $body->mediaItems; |
| 300 | 334 | foreach ($photos as $photo) { |
| 301 | 335 | $object = []; |
| 302 | 336 | $object['id'] = $photo->id; |
| @@ -304,9 +338,9 @@ | ||
| 304 | 338 | $object['thumbnail'] = $photo->baseUrl . "=w150-h150-c"; |
| 305 | 339 | $objects[] = $object; |
| 306 | 340 | } |
| 307 | 341 | } |
| 308 | - else if (isset($body->error)) { | |
| 342 | + elseif (isset($body->error)) { | |
| 309 | 343 | $objects['error'] = $body->error->message; |
| 310 | 344 | } |
| 311 | 345 | return $objects; |
| 312 | 346 | } |
| @@ -312,26 +346,32 @@ | ||
| 312 | 346 | } |
| 313 | 347 | |
| 314 | 348 | /** |
| 315 | 349 | * @param $display_type |
| 316 | - * @return array|mixed | |
| 350 | + * @return array | |
| 317 | 351 | */ |
| 318 | - function construct_shortcode_from_screen_selections($display_type) { | |
| 352 | + public function construct_shortcode_from_screen_selections($display_type): array { | |
| 319 | 353 | $short_code = []; |
| 320 | 354 | |
| 321 | - if ($display_type == 'album-photo') { | |
| 322 | - $short_code['view'] = 'photos'; | |
| 323 | - $short_code['album_id'] = sanitize_text_field($_POST['selected_data']); | |
| 355 | + if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) { | |
| 356 | + if ('album-photo' === $display_type) { | |
| 357 | + $short_code['view'] = 'photos'; | |
| 358 | + $short_code['album_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? '')); | |
| 359 | + } | |
| 360 | + elseif ('shared-album-photo' === $display_type) { | |
| 361 | + $short_code['view'] = 'shared-photos'; | |
| 362 | + $short_code['album_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? '')); | |
| 363 | + } | |
| 364 | + elseif ('multi-photo' === $display_type) { | |
| 365 | + $short_code['view'] = 'photos'; | |
| 366 | + $date_filters = !empty($_POST['date_filters']) ? sanitize_text_field(wp_unslash($_POST['date_filters'])) : ''; | |
| 367 | + $date_range_filters = !empty($_POST['date_range_filters']) ? sanitize_text_field(wp_unslash($_POST['date_range_filters'])) : ''; | |
| 368 | + $short_code['date_filters'] = trim($date_filters . ',' . $date_range_filters, ','); | |
| 369 | + } | |
| 370 | + elseif ('multi-album' === $display_type) { | |
| 371 | + $short_code['view'] = 'albums'; | |
| 372 | + } | |
| 324 | 373 | } |
| 325 | - else if ($display_type == 'multi-photo') { | |
| 326 | - $short_code['view'] = 'photos'; | |
| 327 | - $date_filters = !empty($_POST['date_filters']) ? sanitize_text_field($_POST['date_filters']) : ''; | |
| 328 | - $date_range_filters = !empty($_POST['date_range_filters']) ? sanitize_text_field($_POST['date_range_filters']) : ''; | |
| 329 | - $short_code['date_filters'] = trim($date_filters.','.$date_range_filters, ','); | |
| 330 | - } | |
| 331 | - else if ($display_type == 'multi-album') { | |
| 332 | - $short_code['view'] = 'albums'; | |
| 333 | - } | |
| 334 | 374 | |
| 335 | 375 | return $short_code; |
| 336 | 376 | } |
| 337 | 377 | |
| @@ -336,17 +376,17 @@ | ||
| 336 | 376 | } |
| 337 | 377 | |
| 338 | 378 | /** |
| 339 | 379 | * @param $input |
| 340 | - * @return array|mixed | |
| 380 | + * @return array | |
| 341 | 381 | */ |
| 342 | - function deconstruct_shortcode_to_screen_selections($input) { | |
| 382 | + public function deconstruct_shortcode_to_screen_selections($input): array { | |
| 343 | 383 | $deconstructed = []; |
| 344 | 384 | |
| 345 | 385 | if (!empty($input->view)) { |
| 346 | - if ($input->view == 'photos') { | |
| 386 | + if ('photos' === $input->view || 'shared-photos' === $input->view) { | |
| 347 | 387 | if (!empty($input->album_id)) { |
| 348 | - $deconstructed['display_type'] = 'album-photo'; | |
| 388 | + $deconstructed['display_type'] = ('photos' === $input->view) ? 'album-photo' : 'shared-album-photo'; | |
| 349 | 389 | $deconstructed['selected_data'] = sanitize_text_field($input->album_id); |
| 350 | 390 | } |
| 351 | 391 | else { |
| 352 | 392 | $deconstructed['display_type'] = 'multi-photo'; |
| @@ -356,12 +396,12 @@ | ||
| 356 | 396 | $date_filters = []; |
| 357 | 397 | $date_range_filters = []; |
| 358 | 398 | foreach ($filters as $filter) { |
| 359 | 399 | $maybe_range = explode('-', $filter); |
| 360 | - if (count($maybe_range) == 2) { | |
| 400 | + if (count($maybe_range) === 2) { | |
| 361 | 401 | $date_range_filters[] = $filter; |
| 362 | 402 | } |
| 363 | - else if (count($maybe_range) == 1) { | |
| 403 | + elseif (count($maybe_range) === 1) { | |
| 364 | 404 | $date_filters[] = $filter; |
| 365 | 405 | } |
| 366 | 406 | } |
| 367 | 407 | if (count($date_range_filters) > 5) { |
| @@ -380,9 +420,9 @@ | ||
| 380 | 420 | } |
| 381 | 421 | } |
| 382 | 422 | } |
| 383 | 423 | } |
| 384 | - else if ($input->view == 'albums') { | |
| 424 | + elseif ('albums' === $input->view) { | |
| 385 | 425 | $deconstructed['display_type'] = 'multi-album'; |
| 386 | 426 | } |
| 387 | 427 | } |
| 388 | 428 | |
| @@ -387,5 +427,5 @@ | ||
| 387 | 427 | } |
| 388 | 428 | |
| 389 | 429 | return $deconstructed; |
| 390 | 430 | } |
| 391 | -} | |
| 431 | +} | |