PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.37
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.37
3.37 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 All 142 releases
← All changes | Platforms/Google_Photos.php +35 -29 3.33 → 3.37 View file →
@@ -2,8 +2,9 @@
2 2
3 3 namespace Photonic_Plugin\Platforms;
4 4
5 5 use Photonic_Plugin\Components\Album_List;
6 +use Photonic_Plugin\Components\Comment;
6 7 use Photonic_Plugin\Components\Error;
7 8 use Photonic_Plugin\Components\Pagination;
8 9 use Photonic_Plugin\Components\Photo_List;
9 10 use Photonic_Plugin\Core\Photonic;
@@ -19,11 +20,10 @@
19 20 * Fetches photos from a user's Google Photos account.
20 21 * Lacks support for dual title / description fields, doesn't provide download URLs, and video support is ambiguous.
21 22 */
22 23 class Google_Photos extends OAuth2 implements Level_One_Module, Level_Two_Module, Pageable {
23 - public $error_date_format;
24 + public string $error_date_format;
24 25 public $refresh_token_valid;
25 - private static $instance = null;
26 26
27 27 private $eol_date;
28 28 private $current_date;
29 29
@@ -75,8 +75,13 @@
75 75 * @param array $attr
76 76 * @return array
77 77 */
78 78 public function get_gallery_images($attr = []): array {
79 + // This block kills the rest of the execution without deleting the rest of the code.
80 + if ('google' === $attr['type']) {
81 + return [new Comment(esc_html__('Google Photos is no longer supported due to an API deprecation by Google.', 'photonic'))];
82 + }
83 +
79 84 global $photonic_google_refresh_token, $photonic_google_media, $photonic_google_title_caption;
80 85
81 86 $out = [];
82 87
@@ -132,9 +137,9 @@
132 137 $query_urls = [];
133 138 if ('albums' === $attr['view']) {
134 139 $additional = [];
135 140 if (!empty($attr['count'])) {
136 - $additional['pageSize'] = intval($attr['count']) > 50 ? 50 : intval($attr['count']);
141 + $additional['pageSize'] = min(intval($attr['count']), 50);
137 142 }
138 143
139 144 if (!empty($attr['next_token'])) {
140 145 $additional['pageToken'] = $attr['next_token'];
@@ -247,9 +252,10 @@
247 252 * The filters are specified as a comma-separated list.
248 253 * A "-" before the filter's name indicates that the filter should be excluded rather than included.
249 254 */
250 255 $content_filters = explode(',', $attr['content_filters']);
251 - $include = $exclude = [];
256 + $include = [];
257 + $exclude = [];
252 258 foreach ($content_filters as $content_filter) {
253 259 $content_filter = strtoupper($content_filter);
254 260 if (stripos($content_filter, '-') === 0 && array_key_exists(substr($content_filter, 1), $valid_filters)) {
255 261 $exclude[] = substr($content_filter, 1);
@@ -293,9 +299,9 @@
293 299 }
294 300
295 301 if (!empty($attr['count']) || !empty($attr['photo_count'])) {
296 302 $additional['pageSize'] = !empty($attr['photo_count']) ? $attr['photo_count'] : $attr['count'];
297 - $additional['pageSize'] = intval($additional['pageSize']) > 100 ? 100 : intval($additional['pageSize']);
303 + $additional['pageSize'] = min(intval($additional['pageSize']), 100);
298 304 }
299 305 if (!empty($attr['next_token'])) {
300 306 $additional['pageToken'] = $attr['next_token'];
301 307 }
@@ -405,13 +411,13 @@
405 411
406 412 /**
407 413 * @param $body
408 414 * @param $short_code
409 - * @param bool|false $deferred
415 + * @param bool $deferred
410 416 * @param array $remove
411 417 * @return mixed
412 418 */
413 - private function process_response($body, $short_code, $deferred = false, $remove = []) {
419 + private function process_response($body, $short_code, bool $deferred = false, array $remove = []) {
414 420 global $photonic_google_photo_title_display, $photonic_google_photos_per_row_constraint, $photonic_gallery_template_page,
415 421 $photonic_google_photos_constrain_by_count, $photonic_google_photo_pop_title_display, $photonic_google_hide_album_photo_count_display;
416 422
417 423 if (!empty($body)) {
@@ -518,9 +524,9 @@
518 524 $photonic_photo->taken_on = sanitize_text_field($photo->mediaMetadata->creationTime);
519 525 }
520 526 }
521 527
522 - $photonic_photo->thumb_size = $photonic_photo->tile_size = $photonic_photo->main_size = [];
528 + $photonic_photo->thumb_size = $photonic_photo->tile_size = $photonic_photo->main_size = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments
523 529
524 530 $media = explode(',', $short_code['media']);
525 531 $videos_ok = in_array('videos', $media, true) || in_array('all', $media, true);
526 532 $photos_ok = in_array('photos', $media, true) || in_array('all', $media, true);
@@ -568,14 +574,14 @@
568 574
569 575 /**
570 576 * @param $objects_or_response
571 577 * @param array $short_code
572 - * @param array $remove
578 + * @param array $filter_list
573 579 * @param array $options
574 580 * @param Pagination|null $pagination
575 581 * @return array
576 582 */
577 - public function build_level_2_objects($objects_or_response, array $short_code, array $remove = [], array &$options = [], ?Pagination &$pagination = null): array {
583 + public function build_level_2_objects($objects_or_response, array $short_code, array $filter_list = [], array $options = [], ?Pagination &$pagination = null): array {
578 584 $filter = $short_code['filter'];
579 585 $filters = empty($filter) ? [] : explode(',', $filter);
580 586 $processed = [];
581 587
@@ -585,9 +591,9 @@
585 591 (in_array($album->id, $filters, true) && strtolower($short_code['filter_type']) === 'exclude'))) {
586 592 continue;
587 593 }
588 594
589 - if (in_array($album->id, $remove, true)) {
595 + if (in_array($album->id, $filter_list, true)) {
590 596 continue;
591 597 }
592 598
593 599 $object = $this->process_album($album, $short_code);
@@ -600,9 +606,9 @@
600 606 global $photonic_google_chain_queries;
601 607 if (!empty($pagination->next_token) && strtolower($short_code['filter_type']) !== 'exclude' && !empty($filters) && count($processed) < count($filters) && !empty($photonic_google_chain_queries)) {
602 608 $additional = [];
603 609 if (!empty($short_code['count'])) {
604 - $additional['pageSize'] = intval($short_code['count']) > 50 ? 50 : intval($short_code['count']);
610 + $additional['pageSize'] = min(intval($short_code['count']), 50);
605 611 }
606 612
607 613 $additional['pageToken'] = $pagination->next_token;
608 614
@@ -639,9 +645,9 @@
639 645 $remaining = array_diff($filters, $processed);
640 646 $remaining = implode(',', $remaining);
641 647 $inner_code = $short_code;
642 648 $inner_code['filter'] = $remaining;
643 - $inner = $this->build_level_2_objects($inner_albums, $inner_code, $remove, $options, $pagination);
649 + $inner = $this->build_level_2_objects($inner_albums, $inner_code, $filter_list, $options, $pagination);
644 650 $objects = array_merge($objects, $inner);
645 651 }
646 652 }
647 653 }
@@ -648,9 +654,9 @@
648 654
649 655 return $objects;
650 656 }
651 657
652 - private function calculate_sizes($photo, &$object, $sizes) {
658 + private function calculate_sizes($photo, $object, $sizes) {
653 659 if (!empty($photo->mediaMetadata->width) && !empty($photo->mediaMetadata->height)) {
654 660 $original_width = $photo->mediaMetadata->width;
655 661 $original_height = $photo->mediaMetadata->height;
656 662 $aspect_ratio = $original_width / $original_height;
@@ -679,12 +685,11 @@
679 685 }
680 686 }
681 687 }
682 688
683 - private function update_thumbnail_information(&$albums, array $short_code) {
689 + private function update_thumbnail_information($albums, array $short_code) {
684 690 $thumbnail_albums = [];
685 691 $thumbnail_ids = [];
686 - $additional = [];
687 692 foreach ($albums as $album) {
688 693 $thumbnail_albums[$album->thumbnail_id] = $album;
689 694 $thumbnail_ids[] = $album->thumbnail_id;
690 695 }
@@ -694,10 +699,8 @@
694 699 if (!empty($photonic_google_refresh_token) && !empty($this->access_token)) {
695 700 $query_url = add_query_arg('access_token', $this->access_token, $query_url);
696 701 }
697 702
698 - $additional['mediaItemIds'] = $thumbnail_ids;
699 -
700 703 $headers = [];
701 704 $headers['Accept'] = 'application/json';
702 705 $headers['Content-Type'] = 'application/json';
703 706
@@ -747,14 +750,15 @@
747 750 * @param $album
748 751 * @param $short_code
749 752 * @return Album
750 753 */
751 - private function process_album($album, $short_code) {
754 + private function process_album($album, $short_code): ?Album {
752 755 if (empty($album->coverPhotoBaseUrl)) {
753 756 return null;
754 757 }
755 758
756 -/* $sizes = [
759 + /*
760 + $sizes = [
757 761 'thumb_size' => [
758 762 'size' => $short_code['thumb_size'],
759 763 'crop' => $short_code['crop_thumb'],
760 764 ],
@@ -760,9 +764,10 @@
760 764 ],
761 765 'tile_size' => [
762 766 'size' => $short_code['tile_size'],
763 767 ],
764 - ];*/
768 + ];
769 + */
765 770
766 771 $photonic_album = new Album();
767 772
768 773 $internal_short_code = $short_code;
@@ -778,10 +783,8 @@
778 783 $photonic_album->thumbnail = esc_url($album->coverPhotoBaseUrl . "=w{$short_code['thumb_size']}-h{$short_code['thumb_size']}" . ('crop' === $short_code['crop_thumb'] ? '-c' : ''));
779 784 $photonic_album->tile_image = esc_url($album->coverPhotoBaseUrl . "=w{$short_code['tile_size']}-h{$short_code['tile_size']}");
780 785 $photonic_album->thumbnail_id = $album->coverPhotoMediaItemId;
781 786
782 -// $this->calculate_sizes($album, $photonic_album, $sizes);
783 -
784 787 $photonic_album->main_page = '';
785 788
786 789 $photonic_album->title = wp_kses_post($album->title);
787 790 $photonic_album->counter = empty($album->totalMediaItems) ? $album->mediaItemsCount : $album->totalMediaItems;
@@ -828,9 +831,9 @@
828 831 protected function set_token_validity($validity) {
829 832 $this->refresh_token_valid = $validity;
830 833 }
831 834
832 - public function execute_helper($args = []): string {
835 + public function execute_helper(array $args = []): string {
833 836 if (empty($args['album_type']) || !in_array($args['album_type'], ['self', 'shared'], true)) {
834 837 $album_type = 'self';
835 838 }
836 839 else {
@@ -842,10 +845,10 @@
842 845 $parameters = [
843 846 'access_token' => $this->access_token,
844 847 'pageSize' => 50,
845 848 ];
846 - if (!empty($args['nextPageToken'])) {
847 - $parameters['pageToken'] = sanitize_text_field($args['nextPageToken']);
849 + if (!empty($args['next_page_token'])) {
850 + $parameters['pageToken'] = sanitize_text_field($args['next_page_token']);
848 851 }
849 852
850 853 $call_args = [];
851 854 $call_args['method'] = 'GET';
@@ -919,9 +922,12 @@
919 922 'client_id' => $this->client_id,
920 923 'client_secret' => $this->client_secret,
921 924 'refresh_token' => $refresh_token,
922 925 'grant_type' => 'refresh_token'
923 - ]
926 + ],
927 + $this->user_agent,
928 + 90,
929 + PHOTONIC_SSL_VERIFY
924 930 );
925 931
926 932 if (!is_wp_error($response)) {
927 933 $token = $this->parse_token($response);
@@ -929,9 +935,9 @@
929 935 $token['client_id'] = $this->client_id;
930 936 }
931 937 set_transient('photonic_' . $this->provider . '_token', $token, $token['oauth_token_expires']);
932 938 if (empty($token)) {
933 - $error = print_r(wp_remote_retrieve_body($response), true);
939 + $error = print_r(wp_remote_retrieve_body($response), true); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
934 940 }
935 941 }
936 942 else {
937 943 $error = $response->get_error_message();
@@ -960,9 +966,9 @@
960 966 if (!empty($body->nextPageToken)) {
961 967 $pagination->total = 10;
962 968 $pagination->start = 0;
963 969 $pagination->end = 1;
964 - $pagination->per_page = $short_code;
970 + $pagination->per_page = $short_code['count'];
965 971 $pagination->next_token = $body->nextPageToken;
966 972 }
967 973 return $pagination;
968 974 }