| @@ -35,10 +35,8 @@ | ||
| 35 | 35 | * |
| 36 | 36 | * All galleries can be laid out using any of the layout options. |
| 37 | 37 | */ |
| 38 | 38 | class Flickr extends OAuth1 implements Level_One_Module, Level_Two_Module, Pageable { |
| 39 | - private static $instance = null; | |
| 40 | - | |
| 41 | 39 | protected function __construct() { |
| 42 | 40 | parent::__construct(); |
| 43 | 41 | global $photonic_flickr_api_key, $photonic_flickr_api_secret, $photonic_flickr_disable_title_link, $photonic_flickr_access_token, $photonic_flickr_token_secret; |
| 44 | 42 | $this->api_key = trim($photonic_flickr_api_key); |
| @@ -344,9 +342,9 @@ | ||
| 344 | 342 | $params = $signed_args; |
| 345 | 343 | } |
| 346 | 344 | |
| 347 | 345 | $this->push_to_stack("Make call ({$params['method']})"); |
| 348 | - $response = Photonic::http($this->base_url, 'GET', $params, $this->user_agent); | |
| 346 | + $response = Photonic::http($this->base_url, 'GET', $params, $this->user_agent, 90, PHOTONIC_SSL_VERIFY); | |
| 349 | 347 | $this->pop_from_stack(); |
| 350 | 348 | return $response; |
| 351 | 349 | } |
| 352 | 350 | |
| @@ -358,9 +356,9 @@ | ||
| 358 | 356 | * @param string $collection_id |
| 359 | 357 | * @param string $filters |
| 360 | 358 | * @return array |
| 361 | 359 | */ |
| 362 | - private function get_collection_list($user_id, $collection_id = '', $filters = ''): array { | |
| 360 | + private function get_collection_list($user_id, string $collection_id = '', string $filters = ''): array { | |
| 363 | 361 | $this->push_to_stack("Collection list (collection id '$collection_id')"); |
| 364 | 362 | $query = $this->base_url . '?method=flickr.collections.getTree'; |
| 365 | 363 | $flickr_params = []; |
| 366 | 364 | if (!empty($collection_id)) { |
| @@ -428,9 +426,9 @@ | ||
| 428 | 426 | |
| 429 | 427 | $processed[] = $id; |
| 430 | 428 | $id = substr($id, strpos($id, '-') + 1); |
| 431 | 429 | $title = wp_kses_post($collection->title ?? ''); |
| 432 | - $description = wp_kses_post($collection->description ?? ''); | |
| 430 | + $description = wp_kses($collection->description ?? '', Photonic::$safe_description_tags); | |
| 433 | 431 | $thumb = esc_url($collection->iconsmall ?? ($collection->iconlarge ?? '')); |
| 434 | 432 | $thumb = ('/images/collection_default_l.gif' === $thumb || '/images/collection_default_s.gif' === $thumb) ? 'https://www.flickr.com' . $thumb : $thumb; |
| 435 | 433 | |
| 436 | 434 | $ret = []; |
| @@ -442,9 +440,9 @@ | ||
| 442 | 440 | foreach ($inner_sets as $inner_set) { |
| 443 | 441 | $sets[] = [ |
| 444 | 442 | 'id' => wp_kses_post($inner_set->id), |
| 445 | 443 | 'title' => wp_kses_post($inner_set->title), |
| 446 | - 'description' => wp_kses_post($inner_set->description), | |
| 444 | + 'description' => wp_kses($inner_set->description, Photonic::$safe_description_tags), | |
| 447 | 445 | ]; |
| 448 | 446 | } |
| 449 | 447 | } |
| 450 | 448 | |
| @@ -490,9 +488,9 @@ | ||
| 490 | 488 | } |
| 491 | 489 | break; |
| 492 | 490 | |
| 493 | 491 | case 'flickr.photos.search': |
| 494 | - if (isset($body->photos) && isset($body->photos->photo)) { | |
| 492 | + if (isset($body->photos->photo)) { | |
| 495 | 493 | $photos = $body->photos->photo; |
| 496 | 494 | $components[] = $this->get_photo_list($photos, 'stream', $flickr_params, $short_code, $this->get_pagination($body->photos)); |
| 497 | 495 | } |
| 498 | 496 | break; |
| @@ -508,12 +506,9 @@ | ||
| 508 | 506 | if (isset($body->photoset)) { |
| 509 | 507 | $photoset = $body->photoset; |
| 510 | 508 | if (isset($photoset->photo) && isset($photoset->owner)) { |
| 511 | 509 | $photos = $photoset->photo; |
| 512 | - $options = []; | |
| 513 | - if (isset($photoset->owner)) { | |
| 514 | - $options['owner'] = $photoset->owner; | |
| 515 | - } | |
| 510 | + $options = ['owner' => $photoset->owner]; | |
| 516 | 511 | $components[] = $this->get_photo_list($photos, 'set', $flickr_params, $short_code, $this->get_pagination($photoset), $options); |
| 517 | 512 | } |
| 518 | 513 | } |
| 519 | 514 | break; |
| @@ -636,15 +631,15 @@ | ||
| 636 | 631 | * The photos may be printed in a local, modal, lightbox or template location. |
| 637 | 632 | * |
| 638 | 633 | * @param $photos |
| 639 | 634 | * @param string $parent |
| 640 | - * @param $flickr_params | |
| 641 | - * @param $short_code | |
| 635 | + * @param array $flickr_params | |
| 636 | + * @param array $short_code | |
| 642 | 637 | * @param Pagination $pagination |
| 643 | 638 | * @param array $options |
| 644 | 639 | * @return Photo_List |
| 645 | 640 | */ |
| 646 | - private function get_photo_list($photos, $parent, $flickr_params, $short_code, $pagination, $options = []): Photo_List { | |
| 641 | + private function get_photo_list($photos, string $parent, array $flickr_params, array $short_code, Pagination $pagination, array $options = []): Photo_List { | |
| 647 | 642 | global $photonic_flickr_photo_title_display, $photonic_flickr_photo_pop_title_display; |
| 648 | 643 | global $photonic_flickr_photos_per_row_constraint, $photonic_flickr_photos_constrain_by_count; |
| 649 | 644 | |
| 650 | 645 | if ('local' === $short_code['display']) { |
| @@ -683,9 +678,9 @@ | ||
| 683 | 678 | $dimensions['w'] = $photo->{'width_' . $value}; |
| 684 | 679 | $dimensions['h'] = $photo->{'height_' . $value}; |
| 685 | 680 | return esc_url($photo->{'url_' . $value}); |
| 686 | 681 | } |
| 687 | - elseif (isset($photo->primary_photo_extras) && isset($photo->primary_photo_extras->{'url_' . $value})) { | |
| 682 | + elseif (isset($photo->primary_photo_extras->{'url_' . $value})) { | |
| 688 | 683 | $dimensions['w'] = $photo->primary_photo_extras->{'width_' . $value}; |
| 689 | 684 | $dimensions['h'] = $photo->primary_photo_extras->{'height_' . $value}; |
| 690 | 685 | return esc_url($photo->primary_photo_extras->{'url_' . $value}); |
| 691 | 686 | } |
| @@ -698,9 +693,9 @@ | ||
| 698 | 693 | } |
| 699 | 694 | return esc_url('https://farm' . $photo->farm . '.staticflickr.com/' . $photo->server . '/' . (!empty($photo->primary) ? $photo->primary : $photo->id) . '_' . $photo->secret . '_z.jpg'); |
| 700 | 695 | } |
| 701 | 696 | |
| 702 | - private function find_largest_video_thumb(&$photo_struct, $current_sizes, $shortcode_sizes) { | |
| 697 | + private function find_largest_video_thumb($photo_struct, $current_sizes, $shortcode_sizes) { | |
| 703 | 698 | $video_sizes = [ |
| 704 | 699 | 'o' => 'Original', |
| 705 | 700 | 'k' => 'Large 2048', |
| 706 | 701 | 'h' => 'Large 1600', |
| @@ -787,11 +782,8 @@ | ||
| 787 | 782 | |
| 788 | 783 | if (isset($photo->description)) { |
| 789 | 784 | $photonic_photo->description = $photo->description->_content; |
| 790 | 785 | } |
| 791 | - else { | |
| 792 | - $photonic_photo->description = ''; | |
| 793 | - } | |
| 794 | 786 | |
| 795 | 787 | if (isset($photo->datetaken)) { |
| 796 | 788 | $photonic_photo->taken_on = sanitize_text_field($photo->datetaken); |
| 797 | 789 | } |
| @@ -841,9 +833,9 @@ | ||
| 841 | 833 | |
| 842 | 834 | return $photo_objects; |
| 843 | 835 | } |
| 844 | 836 | |
| 845 | - public function build_level_2_objects($objects_or_response, array $short_code, array $filter_list = [], array &$options = [], ?Pagination &$pagination = null): array { | |
| 837 | + public function build_level_2_objects($objects_or_response, array $short_code, array $filter_list = [], array $options = [], ?Pagination &$pagination = null): array { | |
| 846 | 838 | global $photonic_gallery_template_page; |
| 847 | 839 | |
| 848 | 840 | $main_size = sanitize_text_field('none' === $short_code['main_size'] ? '' : $short_code['main_size']); |
| 849 | 841 | $tile_size = sanitize_text_field((empty($short_code['tile_size']) || 'same' === $short_code['tile_size']) ? $main_size : ('none' === $short_code['tile_size'] ? '' : $short_code['tile_size'])); |
| @@ -889,9 +881,9 @@ | ||
| 889 | 881 | $photonic_album->thumbnail = esc_url($flickr_object->primary_photo_extras->{'url_' . $short_code['thumb_size']} ?? ("https://farm" . $flickr_object->farm . ".staticflickr.com/" . $flickr_object->server . "/" . $flickr_object->primary . "_" . $flickr_object->secret . "_" . $short_code['thumb_size'] . ".jpg")); |
| 890 | 882 | $photonic_album->tile_image = esc_url($this->find_largest_image($flickr_object, $tile_size, $photonic_album->tile_size)); |
| 891 | 883 | |
| 892 | 884 | $owner = $flickr_object->owner ?? $short_code['user_id']; |
| 893 | - $photonic_album->main_page = esc_url("https://www.flickr.com/photos/$owner/sets/{$flickr_object->id}"); | |
| 885 | + $photonic_album->main_page = esc_url("https://www.flickr.com/photos/$owner/sets/$flickr_object->id"); | |
| 894 | 886 | $photonic_album->counter = $flickr_object->photos; |
| 895 | 887 | |
| 896 | 888 | $internal_short_code['view'] = 'photoset'; |
| 897 | 889 | $internal_short_code['photoset_id'] = $flickr_object->id; |
| @@ -922,9 +914,9 @@ | ||
| 922 | 914 | * @param $photoset |
| 923 | 915 | * @param array $short_code |
| 924 | 916 | * @return Header |
| 925 | 917 | */ |
| 926 | - private function get_photoset_header($photoset, $short_code = []): Header { | |
| 918 | + private function get_photoset_header($photoset, array $short_code = []): Header { | |
| 927 | 919 | global $photonic_flickr_hide_set_thumbnail, $photonic_flickr_hide_set_title, $photonic_flickr_hide_set_photo_count; |
| 928 | 920 | |
| 929 | 921 | $owner = $photoset->owner; |
| 930 | 922 | $hidden = ['thumbnail' => !empty($photonic_flickr_hide_set_thumbnail), 'title' => !empty($photonic_flickr_hide_set_title), 'counter' => !empty($photonic_flickr_hide_set_photo_count)]; |
| @@ -931,9 +923,9 @@ | ||
| 931 | 923 | |
| 932 | 924 | $header = new Header(); |
| 933 | 925 | $header->title = wp_kses_post($photoset->title->_content); |
| 934 | 926 | $header->description = wp_kses_post($photoset->description->_content); |
| 935 | - $header->thumb_url = esc_url($photoset->primary_photo_extras->{'url_' . $short_code['thumb_size']} ?? "https://farm{$photoset->farm}.staticflickr.com/{$photoset->server}/{$photoset->primary}_{$photoset->secret}_{$short_code['thumb_size']}.jpg"); | |
| 927 | + $header->thumb_url = esc_url($photoset->primary_photo_extras->{'url_' . $short_code['thumb_size']} ?? "https://farm$photoset->farm.staticflickr.com/$photoset->server/{$photoset->primary}_{$photoset->secret}_{$short_code['thumb_size']}.jpg"); | |
| 936 | 928 | $header->page_url = 'https://www.flickr.com/photos/' . $owner . '/sets/' . $photoset->id; |
| 937 | 929 | |
| 938 | 930 | $header->header_for = 'set'; |
| 939 | 931 | $header->hidden_elements = $this->get_hidden_headers($short_code['header_display'], $hidden); |
| @@ -987,9 +979,9 @@ | ||
| 987 | 979 | |
| 988 | 980 | $header = new Header(); |
| 989 | 981 | $header->title = wp_kses_post($gallery->title->_content); |
| 990 | 982 | $header->description = wp_kses_post($gallery->description->_content); |
| 991 | - $header->thumb_url = esc_url($gallery->primary_photo_extras->{'url_' . $short_code['thumb_size']} ?? "https://farm{$gallery->primary_photo_farm}.staticflickr.com/{$gallery->primary_photo_server}/{$gallery->primary_photo_id}_{$gallery->primary_photo_secret}_{$short_code['thumb_size']}.jpg"); | |
| 983 | + $header->thumb_url = esc_url($gallery->primary_photo_extras->{'url_' . $short_code['thumb_size']} ?? "https://farm$gallery->primary_photo_farm.staticflickr.com/$gallery->primary_photo_server/{$gallery->primary_photo_id}_{$gallery->primary_photo_secret}_{$short_code['thumb_size']}.jpg"); | |
| 992 | 984 | $header->page_url = $gallery->url; |
| 993 | 985 | |
| 994 | 986 | $header->header_for = 'gallery'; |
| 995 | 987 | $header->hidden_elements = $this->get_hidden_headers($short_code['header_display'], $hidden); |
| @@ -1007,9 +999,9 @@ | ||
| 1007 | 999 | * @param array $filter_list |
| 1008 | 1000 | * @param array $short_code |
| 1009 | 1001 | * @return Album_List |
| 1010 | 1002 | */ |
| 1011 | - private function get_gallery_list($galleries, $filter_list = [], $short_code = []): Album_List { | |
| 1003 | + private function get_gallery_list($galleries, array $filter_list = [], array $short_code = []): Album_List { | |
| 1012 | 1004 | global $photonic_flickr_galleries_per_row_constraint, $photonic_gallery_template_page, |
| 1013 | 1005 | $photonic_flickr_galleries_constrain_by_count, $photonic_flickr_gallery_title_display, $photonic_flickr_hide_gallery_photos_count_display; |
| 1014 | 1006 | |
| 1015 | 1007 | $options = ['type' => 'gallery']; |
| @@ -1036,12 +1028,12 @@ | ||
| 1036 | 1028 | * @param $collections |
| 1037 | 1029 | * @param array $short_code |
| 1038 | 1030 | * @return Collection |
| 1039 | 1031 | */ |
| 1040 | - private function get_collections($collections, $short_code = []): Collection { | |
| 1032 | + private function get_collections($collections, array $short_code = []): Collection { | |
| 1041 | 1033 | global $photonic_flickr_hide_empty_collection_details, $photonic_flickr_collection_set_per_row_constraint, $photonic_gallery_template_page, |
| 1042 | 1034 | $photonic_flickr_collection_set_constrain_by_count, $photonic_flickr_hide_collection_thumbnail, $photonic_flickr_hide_collection_title, |
| 1043 | - $photonic_flickr_hide_collection_set_count, $photonic_flickr_collection_set_title_display, $photonic_flickr_hide_collection_set_photos_count_display; | |
| 1035 | + $photonic_flickr_hide_collection_set_count, $photonic_flickr_collection_set_title_display, $photonic_flickr_hide_collection_set_photos_count_display; | |
| 1044 | 1036 | $photonic_collections = new Collection(); |
| 1045 | 1037 | if (!empty($short_code['strip_top_level'])) { |
| 1046 | 1038 | $photonic_collections->strip_top_level = true; |
| 1047 | 1039 | } |
| @@ -1091,20 +1083,18 @@ | ||
| 1091 | 1083 | |
| 1092 | 1084 | $photonic_collection->header = $header; |
| 1093 | 1085 | } |
| 1094 | 1086 | |
| 1095 | - if (isset($collection->set) && !empty($collection->set) && $short_code['iterate_level_3']) { | |
| 1087 | + if (!empty($collection->set) && $short_code['iterate_level_3']) { | |
| 1096 | 1088 | $flickr_objects = []; |
| 1097 | 1089 | $photosets = $collection->set; |
| 1098 | 1090 | |
| 1099 | 1091 | $parallel = []; |
| 1100 | 1092 | $psets = []; |
| 1093 | + | |
| 1101 | 1094 | $hooks = new Hooks(); |
| 1095 | + $hooks->register('curl.before_multi_add', [$this, 'ssl_verify_peer'], 100); | |
| 1102 | 1096 | |
| 1103 | - if (isset($hooks)) { | |
| 1104 | - $hooks->register('curl.before_multi_add', [$this, 'ssl_verify_peer'], 100); | |
| 1105 | - } | |
| 1106 | - | |
| 1107 | 1097 | foreach ($photosets as $set) { |
| 1108 | 1098 | $parallel_params = []; |
| 1109 | 1099 | $parallel_params['primary_photo_extras'] = 'url_c,c_dims,url_h,h_dims,url_k,k_dims,url_o,o_dims,url_b,b_dims,url_z,z_dims,url_n,n_dims,url_m,m_dims,url_q,q_dims,url_t,t_dims,url_s,s_dims,media'; |
| 1110 | 1100 | $parallel_params['format'] = 'json'; |
| @@ -1125,9 +1115,9 @@ | ||
| 1125 | 1115 | ]; |
| 1126 | 1116 | $psets[] = $set->id; |
| 1127 | 1117 | } |
| 1128 | 1118 | |
| 1129 | - if (!empty($parallel) && isset($hooks)) { | |
| 1119 | + if (!empty($parallel)) { | |
| 1130 | 1120 | $parallel_responses = Requests::request_multiple($parallel, ['hooks' => $hooks]); // DO NOT import this, since the class does not exist before WP 6.2 |
| 1131 | 1121 | if (!empty($parallel_responses)) { |
| 1132 | 1122 | foreach ($parallel_responses as $ps_response) { |
| 1133 | 1123 | if (is_a($ps_response, 'WpOrg\Requests\Response')) { |
| @@ -1208,12 +1198,12 @@ | ||
| 1208 | 1198 | $end_point = $this->base_url; |
| 1209 | 1199 | $end_point .= '?' . self::build_query($signed_parameters); |
| 1210 | 1200 | $parameters = null; |
| 1211 | 1201 | |
| 1212 | - return Photonic::http($end_point, 'GET', $parameters, $this->user_agent); | |
| 1202 | + return Photonic::http($end_point, 'GET', $parameters, $this->user_agent, 90, PHOTONIC_SSL_VERIFY); | |
| 1213 | 1203 | } |
| 1214 | 1204 | |
| 1215 | - public function execute_helper($args = []): string { | |
| 1205 | + public function execute_helper(array $args = []): string { | |
| 1216 | 1206 | if (!empty($args['user'])) { |
| 1217 | 1207 | $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $this->api_key . '&method=flickr.urls.lookupUser&url=' . rawurlencode('https://www.flickr.com/photos/') . $args['user']; |
| 1218 | 1208 | } |
| 1219 | 1209 | elseif (!empty($args['group'])) { |
| @@ -1224,9 +1214,9 @@ | ||
| 1224 | 1214 | } |
| 1225 | 1215 | |
| 1226 | 1216 | $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); |
| 1227 | 1217 | if (!is_wp_error($response)) { |
| 1228 | - if (isset($response['response']) && isset($response['response']['code'])) { | |
| 1218 | + if (isset($response['response']['code'])) { | |
| 1229 | 1219 | if (200 === $response['response']['code']) { |
| 1230 | 1220 | $body = json_decode(wp_remote_retrieve_body($response)); |
| 1231 | 1221 | if (isset($body->stat) && 'fail' === $body->stat) { |
| 1232 | 1222 | Photonic::log($response); |