| @@ -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,18 +5,19 @@ | ||
| 4 | 5 | use Photonic_Plugin\Core\Photonic; |
| 5 | 6 | use Photonic_Plugin\Core\Utilities; |
| 6 | 7 | |
| 7 | 8 | class Flickr extends Source { |
| 8 | - private static $instance; | |
| 9 | + private static ?Flickr $instance = null; | |
| 9 | 10 | |
| 10 | 11 | protected function __construct() { |
| 11 | 12 | parent::__construct(); |
| 12 | 13 | $this->provider = 'flickr'; |
| 14 | + $this->api_base = Wizard::base_apis()['flickr']; | |
| 13 | 15 | |
| 14 | 16 | global $photonic_flickr_thumb_size, $photonic_flickr_tile_size, $photonic_flickr_main_size, $photonic_flickr_video_size; |
| 15 | 17 | $this->allowed_image_sizes['flickr'] = [ |
| 16 | 18 | 'thumb_size' => [ |
| 17 | - '' => $this->default_from_settings, | |
| 19 | + '' => $this->default_from_settings, | |
| 18 | 20 | 's' => esc_html__('Small square, 75x75px', 'photonic'), |
| 19 | 21 | 'q' => esc_html__('Large square, 150x150px', 'photonic'), |
| 20 | 22 | 't' => esc_html__('Thumbnail, 100px on longest side', 'photonic'), |
| 21 | 23 | 'm' => esc_html__('Small, 240px on longest side', 'photonic'), |
| @@ -20,104 +22,109 @@ | ||
| 20 | 22 | 't' => esc_html__('Thumbnail, 100px on longest side', 'photonic'), |
| 21 | 23 | 'm' => esc_html__('Small, 240px on longest side', 'photonic'), |
| 22 | 24 | 'n' => esc_html__('Small, 320px on longest side', 'photonic'), |
| 23 | 25 | ], |
| 24 | - 'tile_size' => [ | |
| 25 | - '' => $this->default_from_settings, | |
| 26 | + 'tile_size' => [ | |
| 27 | + '' => $this->default_from_settings, | |
| 26 | 28 | 'same' => esc_html__('Same as Main image size', 'photonic'), |
| 27 | - 'n' => esc_html__('Small, 320px on longest side', 'photonic'), | |
| 29 | + 'n' => esc_html__('Small, 320px on longest side', 'photonic'), | |
| 28 | 30 | 'none' => esc_html__('Medium, 500px on the longest side', 'photonic'), |
| 29 | - 'z' => esc_html__('Medium, 640px on longest side', 'photonic'), | |
| 30 | - 'c' => esc_html__('Medium, 800px on longest side', 'photonic'), | |
| 31 | - 'b' => esc_html__('Large, 1024px on longest side', 'photonic'), | |
| 32 | - 'h' => esc_html__('Large, 1600px on longest side', 'photonic'), | |
| 33 | - 'k' => esc_html__('Large, 2048px on longest side', 'photonic'), | |
| 34 | - 'o' => esc_html__('Original', 'photonic'), | |
| 31 | + 'z' => esc_html__('Medium, 640px on longest side', 'photonic'), | |
| 32 | + 'c' => esc_html__('Medium, 800px on longest side', 'photonic'), | |
| 33 | + 'b' => esc_html__('Large, 1024px on longest side', 'photonic'), | |
| 34 | + 'h' => esc_html__('Large, 1600px on longest side', 'photonic'), | |
| 35 | + 'k' => esc_html__('Large, 2048px on longest side', 'photonic'), | |
| 36 | + 'o' => esc_html__('Original', 'photonic'), | |
| 35 | 37 | ], |
| 36 | - 'main_size' => [ | |
| 37 | - '' => $this->default_from_settings, | |
| 38 | + 'main_size' => [ | |
| 39 | + '' => $this->default_from_settings, | |
| 38 | 40 | 'none' => esc_html__('Medium, 500px on the longest side', 'photonic'), |
| 39 | - 'z' => esc_html__('Medium, 640px on longest side', 'photonic'), | |
| 40 | - 'c' => esc_html__('Medium, 800px on longest side', 'photonic'), | |
| 41 | - 'b' => esc_html__('Large, 1024px on longest side', 'photonic'), | |
| 42 | - 'h' => esc_html__('Large, 1600px on longest side', 'photonic'), | |
| 43 | - 'k' => esc_html__('Large, 2048px on longest side', 'photonic'), | |
| 44 | - 'o' => esc_html__('Original', 'photonic'), | |
| 41 | + 'z' => esc_html__('Medium, 640px on longest side', 'photonic'), | |
| 42 | + 'c' => esc_html__('Medium, 800px on longest side', 'photonic'), | |
| 43 | + 'b' => esc_html__('Large, 1024px on longest side', 'photonic'), | |
| 44 | + 'h' => esc_html__('Large, 1600px on longest side', 'photonic'), | |
| 45 | + 'k' => esc_html__('Large, 2048px on longest side', 'photonic'), | |
| 46 | + 'o' => esc_html__('Original', 'photonic'), | |
| 45 | 47 | ], |
| 46 | 48 | 'video_size' => [ |
| 47 | - '' => $this->default_from_settings, | |
| 48 | - 'Site MP4' => esc_html__('Site MP4', 'photonic'), | |
| 49 | - 'Mobile MP4' => esc_html__('Mobile MP4', 'photonic'), | |
| 50 | - 'HD MP4' => esc_html__('HD MP4', 'photonic'), | |
| 49 | + '' => $this->default_from_settings, | |
| 50 | + 'Site MP4' => esc_html__('Site MP4', 'photonic'), | |
| 51 | + 'Mobile MP4' => esc_html__('Mobile MP4', 'photonic'), | |
| 52 | + 'HD MP4' => esc_html__('HD MP4', 'photonic'), | |
| 51 | 53 | 'Video Original' => esc_html__('Video Original', 'photonic'), |
| 54 | + 'Video Player' => esc_html__('Video Player', 'photonic'), | |
| 55 | + '1080p' => '1080p', | |
| 56 | + '720p' => '720p', | |
| 57 | + '360p' => '360p', | |
| 58 | + '288p' => '288p', | |
| 52 | 59 | ], |
| 53 | 60 | ]; |
| 54 | - $this->allowed_image_sizes['flickr']['thumb_size'][''] .= ' - '.$this->allowed_image_sizes['flickr']['thumb_size'][$photonic_flickr_thumb_size]; | |
| 55 | - $this->allowed_image_sizes['flickr']['tile_size'][''] .= ' - '.$this->allowed_image_sizes['flickr']['tile_size'][$photonic_flickr_tile_size]; | |
| 56 | - $this->allowed_image_sizes['flickr']['main_size'][''] .= ' - '.$this->allowed_image_sizes['flickr']['main_size'][$photonic_flickr_main_size]; | |
| 57 | - $this->allowed_image_sizes['flickr']['video_size'][''] .= ' - '.$this->allowed_image_sizes['flickr']['video_size'][$photonic_flickr_video_size]; | |
| 61 | + $this->allowed_image_sizes['flickr']['thumb_size'][''] .= ' - ' . $this->allowed_image_sizes['flickr']['thumb_size'][$photonic_flickr_thumb_size]; | |
| 62 | + $this->allowed_image_sizes['flickr']['tile_size'][''] .= ' - ' . $this->allowed_image_sizes['flickr']['tile_size'][$photonic_flickr_tile_size]; | |
| 63 | + $this->allowed_image_sizes['flickr']['main_size'][''] .= ' - ' . $this->allowed_image_sizes['flickr']['main_size'][$photonic_flickr_main_size]; | |
| 64 | + $this->allowed_image_sizes['flickr']['video_size'][''] .= ' - ' . $this->allowed_image_sizes['flickr']['video_size'][$photonic_flickr_video_size]; | |
| 58 | 65 | |
| 59 | 66 | } |
| 60 | 67 | |
| 61 | - public static function get_instance() { | |
| 62 | - if (self::$instance == null) { | |
| 68 | + public static function get_instance(): Flickr { | |
| 69 | + if (null === self::$instance) { | |
| 63 | 70 | self::$instance = new Flickr(); |
| 64 | 71 | } |
| 65 | 72 | return self::$instance; |
| 66 | 73 | } |
| 67 | 74 | |
| 68 | - function get_screen_2() { | |
| 75 | + public function get_screen_2(): array { | |
| 69 | 76 | return [ |
| 70 | - 'header' => esc_html__('Choose Type of Gallery', 'photonic'), | |
| 77 | + 'header' => esc_html__('Choose Type of Gallery', 'photonic'), | |
| 71 | 78 | 'display' => [ |
| 72 | 79 | 'kind' => [ |
| 73 | - 'type' => 'field_list', | |
| 80 | + 'type' => 'field_list', | |
| 74 | 81 | 'list_type' => 'sequence', |
| 75 | - 'list' => [ | |
| 82 | + 'list' => [ | |
| 76 | 83 | 'display_type' => [ |
| 77 | - 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 78 | - 'type' => 'select', | |
| 84 | + 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 85 | + 'type' => 'select', | |
| 79 | 86 | 'options' => [ |
| 80 | - '' => '', | |
| 81 | - 'single-photo' => esc_html__('A Single Photo', 'photonic'), | |
| 82 | - 'multi-photo' => esc_html__('Multiple Photos', 'photonic'), | |
| 83 | - 'album-photo' => esc_html__('Photos from an Album / Photoset', 'photonic'), | |
| 87 | + '' => '', | |
| 88 | + 'single-photo' => esc_html__('A Single Photo', 'photonic'), | |
| 89 | + 'multi-photo' => esc_html__('Multiple Photos', 'photonic'), | |
| 90 | + 'album-photo' => esc_html__('Photos from an Album / Photoset', 'photonic'), | |
| 84 | 91 | 'gallery-photo' => esc_html__('Photos from a Gallery', 'photonic'), |
| 85 | - 'multi-album' => esc_html__('Multiple Albums', 'photonic'), | |
| 92 | + 'multi-album' => esc_html__('Multiple Albums', 'photonic'), | |
| 86 | 93 | 'multi-gallery' => esc_html__('Multiple Galleries', 'photonic'), |
| 87 | - 'collection' => esc_html__('Albums from a single collection', 'photonic'), | |
| 88 | - 'collections' => esc_html__('Multiple collections', 'photonic'), | |
| 94 | + 'collection' => esc_html__('Albums from a single collection', 'photonic'), | |
| 95 | + 'collections' => esc_html__('Multiple collections', 'photonic'), | |
| 89 | 96 | ], |
| 90 | - 'req' => 1, | |
| 97 | + 'req' => 1, | |
| 91 | 98 | ], |
| 92 | - 'for' => [ | |
| 93 | - 'desc' => esc_html__('For whom?', 'photonic'), | |
| 94 | - 'type' => 'radio', | |
| 95 | - 'options' => [ | |
| 99 | + 'for' => [ | |
| 100 | + 'desc' => esc_html__('For whom?', 'photonic'), | |
| 101 | + 'type' => 'radio', | |
| 102 | + 'options' => [ | |
| 96 | 103 | 'current' => sprintf(esc_html__('Current user (Defined under %s)', 'photonic'), '<em>Photonic → Settings → Flickr → Flickr Settings → Default user</em>'), |
| 97 | - 'other' => esc_html__('Another user', 'photonic'), | |
| 98 | - 'group' => esc_html__('Group', 'photonic'), | |
| 99 | - 'any' => esc_html__('All users', 'photonic'), | |
| 104 | + 'other' => esc_html__('Another user', 'photonic'), | |
| 105 | + 'group' => esc_html__('Group', 'photonic'), | |
| 106 | + 'any' => esc_html__('All users', 'photonic'), | |
| 100 | 107 | ], |
| 101 | 108 | 'option-conditions' => [ |
| 102 | 109 | 'group' => ['display_type' => ['multi-photo']], |
| 103 | - 'any' => ['display_type' => ['multi-photo']], | |
| 110 | + 'any' => ['display_type' => ['multi-photo']], | |
| 104 | 111 | ], |
| 105 | - 'req' => 1, | |
| 112 | + 'req' => 1, | |
| 106 | 113 | ], |
| 107 | - 'login' => [ | |
| 108 | - 'desc' => sprintf(esc_html__('User name, e.g. %s', 'photonic'), 'https://www.flickr.com/photos/<span style="text-decoration: underline">username</span>/'), | |
| 109 | - 'type' => 'text', | |
| 110 | - 'std' => '', | |
| 114 | + 'login' => [ | |
| 115 | + 'desc' => sprintf(esc_html__('User name, e.g. %s', 'photonic'), 'https://www.flickr.com/photos/<span style="text-decoration: underline">username</span>/'), | |
| 116 | + 'type' => 'text', | |
| 117 | + 'std' => '', | |
| 111 | 118 | 'conditions' => ['for' => ['other']], |
| 112 | - 'req' => 1, | |
| 119 | + 'req' => 1, | |
| 113 | 120 | ], |
| 114 | - 'group' => [ | |
| 115 | - 'desc' => sprintf(esc_html__('Group name, e.g. %s', 'photonic'), 'https://www.flickr.com/groups/<span style="text-decoration: underline">groupname</span>/'), | |
| 116 | - 'type' => 'text', | |
| 117 | - 'std' => '', | |
| 121 | + 'group' => [ | |
| 122 | + 'desc' => sprintf(esc_html__('Group name, e.g. %s', 'photonic'), 'https://www.flickr.com/groups/<span style="text-decoration: underline">groupname</span>/'), | |
| 123 | + 'type' => 'text', | |
| 124 | + 'std' => '', | |
| 118 | 125 | 'conditions' => ['for' => ['group']], |
| 119 | - 'req' => 1, | |
| 126 | + 'req' => 1, | |
| 120 | 127 | ], |
| 121 | 128 | ], |
| 122 | 129 | ], |
| 123 | 130 | ], |
| @@ -123,25 +130,25 @@ | ||
| 123 | 130 | ], |
| 124 | 131 | ]; |
| 125 | 132 | } |
| 126 | 133 | |
| 127 | - function get_screen_3() { | |
| 134 | + public function get_screen_3(): array { | |
| 128 | 135 | return [ |
| 129 | - 'header' => esc_html__('Build your gallery', 'photonic'), | |
| 130 | - 'single-photo' => [ | |
| 131 | - 'header' => esc_html__('Pick a photo', 'photonic'), | |
| 132 | - 'desc' => esc_html__('From the list below pick the single photo you wish to display.', 'photonic'), | |
| 136 | + 'header' => esc_html__('Build your gallery', 'photonic'), | |
| 137 | + 'single-photo' => [ | |
| 138 | + 'header' => esc_html__('Pick a photo', 'photonic'), | |
| 139 | + 'desc' => esc_html__('From the list below pick the single photo you wish to display.', 'photonic'), | |
| 133 | 140 | 'display' => [ |
| 134 | 141 | 'container' => [ |
| 135 | 142 | 'type' => 'thumbnail-selector', |
| 136 | 143 | 'mode' => 'single', |
| 137 | - 'for' => 'selected_data', | |
| 144 | + 'for' => 'selected_data', | |
| 138 | 145 | ], |
| 139 | 146 | ], |
| 140 | 147 | ], |
| 141 | - 'multi-photo' => [ | |
| 142 | - 'header' => esc_html__('All your photos', 'photonic'), | |
| 143 | - 'desc' => esc_html__('You can show all your photos, or apply tags to show some of them.', 'photonic'), | |
| 148 | + 'multi-photo' => [ | |
| 149 | + 'header' => esc_html__('All your photos', 'photonic'), | |
| 150 | + 'desc' => esc_html__('You can show all your photos, or apply tags to show some of them.', 'photonic'), | |
| 144 | 151 | 'display' => [ |
| 145 | 152 | 'tags' => [ |
| 146 | 153 | 'desc' => esc_html__('Tags', 'photonic'), |
| 147 | 154 | 'type' => 'text', |
| @@ -148,10 +155,10 @@ | ||
| 148 | 155 | 'hint' => esc_html__('Comma-separated list of tags', 'photonic') |
| 149 | 156 | ], |
| 150 | 157 | |
| 151 | 158 | 'tag_mode' => [ |
| 152 | - 'desc' => esc_html__('Tag mode', 'photonic'), | |
| 153 | - 'type' => 'select', | |
| 159 | + 'desc' => esc_html__('Tag mode', 'photonic'), | |
| 160 | + 'type' => 'select', | |
| 154 | 161 | 'options' => [ |
| 155 | 162 | 'any' => esc_html__('Any tag', 'photonic'), |
| 156 | 163 | 'all' => esc_html__('All tags', 'photonic'), |
| 157 | 164 | ], |
| @@ -162,12 +169,12 @@ | ||
| 162 | 169 | 'type' => 'text', |
| 163 | 170 | ], |
| 164 | 171 | |
| 165 | 172 | 'privacy_filter' => [ |
| 166 | - 'desc' => esc_html__('Privacy filter', 'photonic'), | |
| 167 | - 'type' => 'select', | |
| 173 | + 'desc' => esc_html__('Privacy filter', 'photonic'), | |
| 174 | + 'type' => 'select', | |
| 168 | 175 | 'options' => [ |
| 169 | - '' => esc_html__('None', 'photonic'), | |
| 176 | + '' => esc_html__('None', 'photonic'), | |
| 170 | 177 | '1' => esc_html__('Public photos', 'photonic'), |
| 171 | 178 | '2' => esc_html__('Private photos visible to friends', 'photonic'), |
| 172 | 179 | '3' => esc_html__('Private photos visible to family', 'photonic'), |
| 173 | 180 | '4' => esc_html__('Private photos visible to friends & family', 'photonic'), |
| @@ -172,27 +179,27 @@ | ||
| 172 | 179 | '3' => esc_html__('Private photos visible to family', 'photonic'), |
| 173 | 180 | '4' => esc_html__('Private photos visible to friends & family', 'photonic'), |
| 174 | 181 | '5' => esc_html__('Completely private photos', 'photonic'), |
| 175 | 182 | ], |
| 176 | - 'hint' => sprintf(esc_html__('Applicable only if Flickr private photos are turned on (%1$s) and Back-end authentication is off (%2$s)', 'photonic'), '<em>Photonic → Settings → Flickr → Flickr Settings → Allow User Login</em>', '<em>Photonic → Settings → Flickr → Flickr Settings → Access Token</em>'), | |
| 183 | + 'hint' => sprintf(esc_html__('Applicable only if Flickr private photos are turned on (%1$s) and Back-end authentication is off (%2$s)', 'photonic'), '<em>Photonic → Settings → Flickr → Flickr Settings → Allow User Login</em>', '<em>Photonic → Settings → Flickr → Flickr Settings → Access Token</em>'), | |
| 177 | 184 | ], |
| 178 | 185 | |
| 179 | 186 | 'container' => [ |
| 180 | 187 | 'type' => 'thumbnail-selector', |
| 181 | 188 | 'mode' => 'none', |
| 182 | - 'for' => 'selected_data', | |
| 189 | + 'for' => 'selected_data', | |
| 183 | 190 | ], |
| 184 | 191 | ], |
| 185 | 192 | ], |
| 186 | - 'album-photo' => [ | |
| 187 | - 'header' => esc_html__('Pick your album', 'photonic'), | |
| 188 | - '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'), | |
| 193 | + 'album-photo' => [ | |
| 194 | + 'header' => esc_html__('Pick your album', 'photonic'), | |
| 195 | + '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'), | |
| 189 | 196 | 'display' => [ |
| 190 | 197 | 'privacy_filter' => [ |
| 191 | - 'desc' => esc_html__('Privacy filter', 'photonic'), | |
| 192 | - 'type' => 'select', | |
| 198 | + 'desc' => esc_html__('Privacy filter', 'photonic'), | |
| 199 | + 'type' => 'select', | |
| 193 | 200 | 'options' => [ |
| 194 | - '' => esc_html__('None', 'photonic'), | |
| 201 | + '' => esc_html__('None', 'photonic'), | |
| 195 | 202 | '1' => esc_html__('Public photos', 'photonic'), |
| 196 | 203 | '2' => esc_html__('Private photos visible to friends', 'photonic'), |
| 197 | 204 | '3' => esc_html__('Private photos visible to family', 'photonic'), |
| 198 | 205 | '4' => esc_html__('Private photos visible to friends & family', 'photonic'), |
| @@ -197,103 +204,103 @@ | ||
| 197 | 204 | '3' => esc_html__('Private photos visible to family', 'photonic'), |
| 198 | 205 | '4' => esc_html__('Private photos visible to friends & family', 'photonic'), |
| 199 | 206 | '5' => esc_html__('Completely private photos', 'photonic'), |
| 200 | 207 | ], |
| 201 | - 'hint' => sprintf(esc_html__('Applicable only if Flickr private photos are turned on (%1$s) and Back-end authentication is off (%2$s)', 'photonic'), '<em>Photonic → Settings → Flickr → Flickr Settings → Allow User Login</em>', '<em>Photonic → Settings → Flickr → Flickr Settings → Access Token</em>'), | |
| 208 | + 'hint' => sprintf(esc_html__('Applicable only if Flickr private photos are turned on (%1$s) and Back-end authentication is off (%2$s)', 'photonic'), '<em>Photonic → Settings → Flickr → Flickr Settings → Allow User Login</em>', '<em>Photonic → Settings → Flickr → Flickr Settings → Access Token</em>'), | |
| 202 | 209 | ], |
| 203 | 210 | |
| 204 | 211 | 'container' => [ |
| 205 | 212 | 'type' => 'thumbnail-selector', |
| 206 | 213 | 'mode' => 'single', |
| 207 | - 'for' => 'selected_data', | |
| 214 | + 'for' => 'selected_data', | |
| 208 | 215 | ], |
| 209 | 216 | ], |
| 210 | 217 | ], |
| 211 | 218 | 'gallery-photo' => [ |
| 212 | - 'header' => esc_html__('Pick your gallery', 'photonic'), | |
| 213 | - 'desc' => esc_html__('From the list below pick the gallery whose photos you wish to display. Photos from that gallery will show up as thumbnails.', 'photonic'), | |
| 219 | + 'header' => esc_html__('Pick your gallery', 'photonic'), | |
| 220 | + 'desc' => esc_html__('From the list below pick the gallery whose photos you wish to display. Photos from that gallery will show up as thumbnails.', 'photonic'), | |
| 214 | 221 | 'display' => [ |
| 215 | 222 | 'container' => [ |
| 216 | 223 | 'type' => 'thumbnail-selector', |
| 217 | 224 | 'mode' => 'single', |
| 218 | - 'for' => 'selected_data', | |
| 225 | + 'for' => 'selected_data', | |
| 219 | 226 | ], |
| 220 | 227 | ], |
| 221 | 228 | ], |
| 222 | - 'multi-album' => [ | |
| 223 | - 'header' => esc_html__('Pick your albums / photosets', 'photonic'), | |
| 224 | - 'desc' => esc_html__('From the list below pick the albums / photosets you wish to display. Each album will show up as a single thumbnail.', 'photonic'), | |
| 229 | + 'multi-album' => [ | |
| 230 | + 'header' => esc_html__('Pick your albums / photosets', 'photonic'), | |
| 231 | + 'desc' => esc_html__('From the list below pick the albums / photosets you wish to display. Each album will show up as a single thumbnail.', 'photonic'), | |
| 225 | 232 | 'display' => [ |
| 226 | 233 | 'selection' => [ |
| 227 | - 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 228 | - 'type' => 'select', | |
| 234 | + 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 235 | + 'type' => 'select', | |
| 229 | 236 | 'options' => [ |
| 230 | - 'all' => esc_html__('Automatic all (will automatically add new albums)', 'photonic'), | |
| 231 | - 'selected' => esc_html__('Selected albums / photosets', 'photonic'), | |
| 237 | + 'all' => esc_html__('Automatic all (will automatically add new albums)', 'photonic'), | |
| 238 | + 'selected' => esc_html__('Selected albums / photosets', 'photonic'), | |
| 232 | 239 | 'not-selected' => esc_html__('All except selected albums / photosets', 'photonic'), |
| 233 | 240 | ], |
| 234 | - 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'), | |
| 235 | - 'req' => 1, | |
| 241 | + 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'), | |
| 242 | + 'req' => 1, | |
| 236 | 243 | ], |
| 237 | 244 | 'container' => [ |
| 238 | 245 | 'type' => 'thumbnail-selector', |
| 239 | 246 | 'mode' => 'multi', |
| 240 | - 'for' => 'selected_data', | |
| 247 | + 'for' => 'selected_data', | |
| 241 | 248 | ], |
| 242 | 249 | ], |
| 243 | 250 | ], |
| 244 | 251 | 'multi-gallery' => [ |
| 245 | - 'header' => esc_html__('Pick your galleries', 'photonic'), | |
| 246 | - 'desc' => esc_html__('From the list below pick the galleries you wish to display. Each album will show up as a single thumbnail.', 'photonic'), | |
| 252 | + 'header' => esc_html__('Pick your galleries', 'photonic'), | |
| 253 | + 'desc' => esc_html__('From the list below pick the galleries you wish to display. Each album will show up as a single thumbnail.', 'photonic'), | |
| 247 | 254 | 'display' => [ |
| 248 | 255 | 'selection' => [ |
| 249 | - 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 250 | - 'type' => 'select', | |
| 256 | + 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 257 | + 'type' => 'select', | |
| 251 | 258 | 'options' => [ |
| 252 | - 'all' => esc_html__('Automatic all (will automatically add new galleries)', 'photonic'), | |
| 253 | - 'selected' => esc_html__('Selected galleries', 'photonic'), | |
| 259 | + 'all' => esc_html__('Automatic all (will automatically add new galleries)', 'photonic'), | |
| 260 | + 'selected' => esc_html__('Selected galleries', 'photonic'), | |
| 254 | 261 | 'not-selected' => esc_html__('All except selected galleries', 'photonic'), |
| 255 | 262 | ], |
| 256 | - 'req' => 1, | |
| 257 | - 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'), | |
| 263 | + 'req' => 1, | |
| 264 | + 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'), | |
| 258 | 265 | ], |
| 259 | 266 | 'container' => [ |
| 260 | 267 | 'type' => 'thumbnail-selector', |
| 261 | 268 | 'mode' => 'multi', |
| 262 | - 'for' => 'selected_data', | |
| 269 | + 'for' => 'selected_data', | |
| 263 | 270 | ], |
| 264 | 271 | ], |
| 265 | 272 | ], |
| 266 | - 'collection' => [ | |
| 267 | - 'header' => esc_html__('Pick your collection', 'photonic'), | |
| 268 | - 'desc' => esc_html__('From the list below pick the collection you wish to display. The albums within the collections will show up as single thumbnails.', 'photonic'), | |
| 273 | + 'collection' => [ | |
| 274 | + 'header' => esc_html__('Pick your collection', 'photonic'), | |
| 275 | + 'desc' => esc_html__('From the list below pick the collection you wish to display. The albums within the collections will show up as single thumbnails.', 'photonic'), | |
| 269 | 276 | 'display' => [ |
| 270 | 277 | 'container' => [ |
| 271 | 278 | 'type' => 'thumbnail-selector', |
| 272 | 279 | 'mode' => 'single', |
| 273 | - 'for' => 'selected_data', | |
| 280 | + 'for' => 'selected_data', | |
| 274 | 281 | ], |
| 275 | 282 | ], |
| 276 | 283 | ], |
| 277 | - 'collections' => [ | |
| 278 | - 'header' => esc_html__('Pick your collections', 'photonic'), | |
| 279 | - 'desc' => esc_html__('From the list below pick the collections you wish to display. The albums within the collections will show up as single thumbnails.', 'photonic'), | |
| 284 | + 'collections' => [ | |
| 285 | + 'header' => esc_html__('Pick your collections', 'photonic'), | |
| 286 | + 'desc' => esc_html__('From the list below pick the collections you wish to display. The albums within the collections will show up as single thumbnails.', 'photonic'), | |
| 280 | 287 | 'display' => [ |
| 281 | 288 | 'selection' => [ |
| 282 | - 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 283 | - 'type' => 'select', | |
| 289 | + 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 290 | + 'type' => 'select', | |
| 284 | 291 | 'options' => [ |
| 285 | - 'all' => esc_html__('Automatic all (will automatically add new collections)', 'photonic'), | |
| 286 | - 'selected' => esc_html__('Selected collections', 'photonic'), | |
| 292 | + 'all' => esc_html__('Automatic all (will automatically add new collections)', 'photonic'), | |
| 293 | + 'selected' => esc_html__('Selected collections', 'photonic'), | |
| 287 | 294 | 'not-selected' => esc_html__('All except selected collections', 'photonic'), |
| 288 | 295 | ], |
| 289 | - 'req' => 1, | |
| 290 | - 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'), | |
| 296 | + 'req' => 1, | |
| 297 | + 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'), | |
| 291 | 298 | ], |
| 292 | 299 | 'container' => [ |
| 293 | 300 | 'type' => 'thumbnail-selector', |
| 294 | 301 | 'mode' => 'multi', |
| 295 | - 'for' => 'selected_data', | |
| 302 | + 'for' => 'selected_data', | |
| 296 | 303 | ], |
| 297 | 304 | ], |
| 298 | 305 | ], |
| 299 | 306 | ]; |
| @@ -298,137 +305,111 @@ | ||
| 298 | 305 | ], |
| 299 | 306 | ]; |
| 300 | 307 | } |
| 301 | 308 | |
| 302 | - function get_screen_4() { | |
| 309 | + public function get_screen_4(): array { | |
| 303 | 310 | return []; |
| 304 | 311 | } |
| 305 | 312 | |
| 306 | - function get_screen_5() { | |
| 313 | + public function get_screen_5(): array { | |
| 307 | 314 | global $photonic_flickr_media, $photonic_flickr_title_caption; |
| 308 | - $output = [ | |
| 315 | + // $output['slideshow'] = $this->get_slideshow_options(); | |
| 316 | + return [ | |
| 309 | 317 | 'flickr' => [ |
| 310 | - 'L1' => [ | |
| 311 | - 'sort' => [ | |
| 312 | - 'desc' => esc_html__('Sort by', 'photonic'), | |
| 313 | - 'type' => 'select', | |
| 318 | + 'L1' => [ | |
| 319 | + 'sort' => [ | |
| 320 | + 'desc' => esc_html__('Sort by', 'photonic'), | |
| 321 | + 'type' => 'select', | |
| 314 | 322 | 'options' => [ |
| 315 | - '' => '', | |
| 316 | - 'date-posted-desc' => esc_html__('Date posted, descending', 'photonic'), | |
| 317 | - 'date-posted-asc' => esc_html__('Date posted, ascending', 'photonic'), | |
| 318 | - 'date-taken-asc' => esc_html__('Date taken, ascending', 'photonic'), | |
| 319 | - 'date-taken-desc' => esc_html__('Date taken, descending', 'photonic'), | |
| 323 | + '' => '', | |
| 324 | + 'date-posted-desc' => esc_html__('Date posted, descending', 'photonic'), | |
| 325 | + 'date-posted-asc' => esc_html__('Date posted, ascending', 'photonic'), | |
| 326 | + 'date-taken-asc' => esc_html__('Date taken, ascending', 'photonic'), | |
| 327 | + 'date-taken-desc' => esc_html__('Date taken, descending', 'photonic'), | |
| 320 | 328 | 'interestingness-desc' => esc_html__('Interestingness, descending', 'photonic'), |
| 321 | - 'interestingness-asc' => esc_html__('Interestingness, ascending', 'photonic'), | |
| 322 | - 'relevance' => esc_html__('Relevance', 'photonic'), | |
| 329 | + 'interestingness-asc' => esc_html__('Interestingness, ascending', 'photonic'), | |
| 330 | + 'relevance' => esc_html__('Relevance', 'photonic'), | |
| 323 | 331 | ], |
| 332 | + 'conditions' => ['display_type' => ['multi-photo']], | |
| 324 | 333 | ], |
| 325 | - 'media' => [ | |
| 326 | - 'desc' => esc_html__('Media to Show', 'photonic'), | |
| 327 | - 'type' => 'select', | |
| 334 | + 'media' => [ | |
| 335 | + 'desc' => esc_html__('Media to Show', 'photonic'), | |
| 336 | + 'type' => 'select', | |
| 328 | 337 | 'options' => Utilities::media_options(true, $photonic_flickr_media), |
| 329 | - 'std' => '', | |
| 330 | - 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Media to show</em>'), | |
| 338 | + 'std' => '', | |
| 339 | + 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Media to show</em>'), | |
| 331 | 340 | ], |
| 332 | 341 | 'caption' => [ |
| 333 | - 'desc' => esc_html__('Photo titles and captions', 'photonic'), | |
| 334 | - 'type' => 'select', | |
| 342 | + 'desc' => esc_html__('Photo titles and captions', 'photonic'), | |
| 343 | + 'type' => 'select', | |
| 335 | 344 | 'options' => Utilities::title_caption_options(true, $photonic_flickr_title_caption), |
| 336 | - 'std' => '', | |
| 337 | - 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Photo titles and captions</em>'), | |
| 345 | + 'std' => '', | |
| 346 | + 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Photo titles and captions</em>'), | |
| 338 | 347 | ], |
| 339 | - 'headers' => [ | |
| 340 | - 'desc' => esc_html__('Show Header', 'photonic'), | |
| 341 | - 'type' => 'select', | |
| 342 | - 'options' => [ | |
| 343 | - '' => $this->default_from_settings, | |
| 344 | - 'none' => esc_html__('No header', 'photonic'), | |
| 345 | - 'title' => esc_html__('Title only', 'photonic'), | |
| 346 | - 'thumbnail' => esc_html__('Thumbnail only', 'photonic'), | |
| 347 | - 'counter' => esc_html__('Counts only', 'photonic'), | |
| 348 | - 'title,counter' => esc_html__('Title and counts', 'photonic'), | |
| 349 | - 'thumbnail,counter' => esc_html__('Thumbnail and counts', 'photonic'), | |
| 350 | - 'thumbnail,title' => esc_html__('Thumbnail and title', 'photonic'), | |
| 351 | - 'thumbnail,title,counter' => esc_html__('Thumbnail, title and counts', 'photonic'), | |
| 352 | - ], | |
| 353 | - 'conditions' => ['display_type' => ['album-photo', 'gallery-photo']], | |
| 354 | - ], | |
| 348 | + 'headers' => $this->get_header_options(['display_type' => ['album-photo', 'gallery-photo']]), | |
| 355 | 349 | ], |
| 356 | - 'L2' => [], | |
| 357 | - 'L3' => [ | |
| 350 | + 'L2' => [], | |
| 351 | + 'L3' => [ | |
| 358 | 352 | 'collections_display' => [ |
| 359 | - 'desc' => esc_html__('Expand Collections', 'photonic'), | |
| 360 | - 'type' => 'select', | |
| 353 | + 'desc' => esc_html__('Expand Collections', 'photonic'), | |
| 354 | + 'type' => 'select', | |
| 361 | 355 | 'options' => [ |
| 362 | - '' => '', | |
| 363 | - 'lazy' => esc_html__('Lazy loading', 'photonic'), | |
| 356 | + '' => '', | |
| 357 | + 'lazy' => esc_html__('Lazy loading', 'photonic'), | |
| 364 | 358 | 'expanded' => esc_html__('Expanded upfront', 'photonic'), |
| 365 | 359 | ], |
| 366 | - 'hint' => sprintf(esc_html__('The Collections API is slow, so, if you are displaying collections, pick %1$slazy loading%2$s if your collections have many albums / photosets.', 'photonic'), | |
| 367 | - '<a href="https://aquoid.com/plugins/photonic/flickr/flickr-collections/" target="_blank">', '</a>'), | |
| 360 | + 'hint' => sprintf( | |
| 361 | + esc_html__('The Collections API is slow, so, if you are displaying collections, pick %1$slazy loading%2$s if your collections have many albums / photosets.', 'photonic'), | |
| 362 | + '<a href="https://aquoid.com/plugins/photonic/flickr/flickr-collections/" target="_blank">', | |
| 363 | + '</a>' | |
| 364 | + ), | |
| 368 | 365 | ], |
| 369 | - 'headers' => [ | |
| 370 | - 'desc' => esc_html__('Show Header', 'photonic'), | |
| 371 | - 'type' => 'select', | |
| 372 | - 'options' => [ | |
| 373 | - '' => $this->default_from_settings, | |
| 374 | - 'none' => esc_html__('No header', 'photonic'), | |
| 375 | - 'title' => esc_html__('Title only', 'photonic'), | |
| 376 | - 'thumbnail' => esc_html__('Thumbnail only', 'photonic'), | |
| 377 | - 'counter' => esc_html__('Counts only', 'photonic'), | |
| 378 | - 'title,counter' => esc_html__('Title and counts', 'photonic'), | |
| 379 | - 'thumbnail,counter' => esc_html__('Thumbnail and counts', 'photonic'), | |
| 380 | - 'thumbnail,title' => esc_html__('Thumbnail and title', 'photonic'), | |
| 381 | - 'thumbnail,title,counter' => esc_html__('Thumbnail, title and counts', 'photonic'), | |
| 382 | - ], | |
| 383 | - ], | |
| 366 | + 'headers' => $this->get_header_options(), | |
| 384 | 367 | ], |
| 385 | - 'main_size' => [ | |
| 386 | - 'desc' => esc_html__('Main image size', 'photonic'), | |
| 387 | - 'type' => 'select', | |
| 368 | + 'main_size' => [ | |
| 369 | + 'desc' => esc_html__('Main image size', 'photonic'), | |
| 370 | + 'type' => 'select', | |
| 388 | 371 | 'options' => $this->allowed_image_sizes['flickr']['main_size'], |
| 389 | - 'std' => '', | |
| 390 | - 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Main image size</em>'), | |
| 372 | + 'std' => '', | |
| 373 | + 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Main image size</em>'), | |
| 391 | 374 | ], |
| 392 | 375 | 'video_size' => [ |
| 393 | - 'desc' => esc_html__('Main video size', 'photonic'), | |
| 394 | - 'type' => 'select', | |
| 376 | + 'desc' => esc_html__('Main video size', 'photonic'), | |
| 377 | + 'type' => 'select', | |
| 395 | 378 | 'options' => $this->allowed_image_sizes['flickr']['video_size'], |
| 396 | - 'std' => '', | |
| 397 | - 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Video size</em>'), | |
| 379 | + 'std' => '', | |
| 380 | + 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Video size</em>'), | |
| 398 | 381 | ], |
| 399 | 382 | ] |
| 400 | 383 | ]; |
| 401 | -// $output['slideshow'] = $this->get_slideshow_options(); | |
| 402 | - return $output; | |
| 403 | 384 | } |
| 404 | 385 | |
| 405 | - function get_square_size_options() { | |
| 386 | + public function get_square_size_options(): array { | |
| 406 | 387 | return [ |
| 407 | 388 | 'thumb_size' => [ |
| 408 | - 'desc' => esc_html__('Thumbnail size', 'photonic'), | |
| 409 | - 'type' => 'select', | |
| 389 | + 'desc' => esc_html__('Thumbnail size', 'photonic'), | |
| 390 | + 'type' => 'select', | |
| 410 | 391 | 'options' => $this->allowed_image_sizes['flickr']['thumb_size'], |
| 411 | - 'std' => '', | |
| 412 | - 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Thumbnail size</em>'), | |
| 392 | + 'std' => '', | |
| 393 | + 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Thumbnail size</em>'), | |
| 413 | 394 | ], |
| 414 | 395 | ]; |
| 415 | 396 | } |
| 416 | 397 | |
| 417 | - function get_random_size_options() { | |
| 398 | + public function get_random_size_options(): array { | |
| 418 | 399 | return [ |
| 419 | 400 | 'tile_size' => [ |
| 420 | - 'desc' => esc_html__('Tile size', 'photonic'), | |
| 421 | - 'type' => 'select', | |
| 401 | + 'desc' => esc_html__('Tile size', 'photonic'), | |
| 402 | + 'type' => 'select', | |
| 422 | 403 | 'options' => $this->allowed_image_sizes['flickr']['tile_size'], |
| 423 | - 'std' => '', | |
| 424 | - 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Tile image size</em>'), | |
| 404 | + 'std' => '', | |
| 405 | + 'hint' => sprintf($this->default_under, '<em>Photonic → Settings → Flickr → Flickr Settings → Tile image size</em>'), | |
| 425 | 406 | ], |
| 426 | 407 | ]; |
| 427 | 408 | } |
| 428 | 409 | |
| 429 | - function make_request($display_type, $for, $flattened_fields) { | |
| 430 | - if ($display_type != 'multi-photo' && in_array($for, ['group', 'any'])) { | |
| 410 | + public function make_request($display_type, $for, $flattened_fields): array { | |
| 411 | + if ('multi-photo' !== $display_type && in_array($for, ['group', 'any'], true)) { | |
| 431 | 412 | $err = esc_html__('Incompatible selections:', 'photonic') . "<br/>\n"; |
| 432 | 413 | $err .= $flattened_fields['display_type']['desc'] . ": " . $flattened_fields['display_type']['options'][$display_type] . "<br/>\n"; |
| 433 | 414 | $err .= $flattened_fields['for']['desc'] . ": " . $flattened_fields['for']['options'][$for] . "<br/>\n"; |
| 434 | 415 | return ['error' => $err]; |
| @@ -433,29 +414,40 @@ | ||
| 433 | 414 | $err .= $flattened_fields['for']['desc'] . ": " . $flattened_fields['for']['options'][$for] . "<br/>\n"; |
| 434 | 415 | return ['error' => $err]; |
| 435 | 416 | } |
| 436 | 417 | |
| 437 | - $group = sanitize_text_field($_POST['group']); | |
| 438 | - $login = sanitize_text_field($_POST['login']); | |
| 418 | + $group = ''; | |
| 419 | + $login = ''; | |
| 420 | + | |
| 421 | + if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) { | |
| 422 | + $group = sanitize_text_field(wp_unslash($_POST['group'] ?? '')); | |
| 423 | + $login = sanitize_text_field(wp_unslash($_POST['login'] ?? '')); | |
| 424 | + } | |
| 425 | + | |
| 439 | 426 | global $photonic_flickr_default_user, $photonic_flickr_api_key; |
| 440 | - if ($for == 'current' && empty($photonic_flickr_default_user)) { | |
| 441 | - return ['error' => sprintf(esc_html__('Default user not defined under %1$s. %2$sSelect "Another user" and put in your user id.', 'photonic'), | |
| 442 | - '<em>Photonic → Settings → Flickr → Flickr Settings → Default User</em>', '<br/>')]; | |
| 427 | + if ('current' === $for && empty($photonic_flickr_default_user)) { | |
| 428 | + return [ | |
| 429 | + 'error' => sprintf( | |
| 430 | + esc_html__('Default user not defined under %1$s. %2$sSelect "Another user" and put in your user id.', 'photonic'), | |
| 431 | + '<em>Photonic → Settings → Flickr → Flickr Settings → Default User</em>', | |
| 432 | + '<br/>' | |
| 433 | + ) | |
| 434 | + ]; | |
| 443 | 435 | } |
| 444 | 436 | |
| 445 | - if (($for == 'group' && empty($group)) || ($for == 'other' && empty($login))) { | |
| 437 | + if (('group' === $for && empty($group)) || ('other' === $for && empty($login))) { | |
| 446 | 438 | return ['error' => $this->error_mandatory]; |
| 447 | 439 | } |
| 448 | 440 | |
| 449 | 441 | $parameters = []; |
| 450 | - $user = $for == 'current' ? $photonic_flickr_default_user : ($for == 'other' ? $login : ''); | |
| 451 | - if (($for == 'other' || $for == 'current') && !empty($user)) { | |
| 452 | - $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupUser&url=' . urlencode('https://www.flickr.com/photos/') . $user; | |
| 442 | + $user = 'current' === $for ? $photonic_flickr_default_user : ('other' === $for ? $login : ''); | |
| 443 | + if (('other' === $for || 'current' === $for) && !empty($user)) { | |
| 444 | + $url = 'https://' . $this->api_base . '/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupUser&url=' . rawurlencode('https://www.flickr.com/photos/') . $user; | |
| 453 | 445 | $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); |
| 454 | 446 | $response = $this->process_response($response, 'flickr', 'user'); |
| 455 | 447 | if (!empty($response['error'])) { |
| 456 | 448 | // Maybe the user provided the full URL instead of just the user name? |
| 457 | - $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupUser&url=' . urlencode($user); | |
| 449 | + $url = 'https://' . $this->api_base . '/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupUser&url=' . rawurlencode($user); | |
| 458 | 450 | $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); |
| 459 | 451 | $response = $this->process_response($response, 'flickr', 'user'); |
| 460 | 452 | if (!empty($response['error'])) { |
| 461 | 453 | return $response; |
| @@ -466,15 +458,15 @@ | ||
| 466 | 458 | $parameters = array_merge($response['success'], $parameters); |
| 467 | 459 | } |
| 468 | 460 | } |
| 469 | 461 | |
| 470 | - if ($for == 'group' && !empty($group)) { | |
| 471 | - $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupGroup&url=' . urlencode('https://www.flickr.com/groups/') . $group; | |
| 462 | + if ('group' === $for && !empty($group)) { | |
| 463 | + $url = 'https://' . $this->api_base . '/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupGroup&url=' . rawurlencode('https://www.flickr.com/groups/') . $group; | |
| 472 | 464 | $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); |
| 473 | 465 | $response = $this->process_response($response, 'flickr', 'group'); |
| 474 | 466 | if (!empty($response['error'])) { |
| 475 | 467 | // Maybe the user provided the full URL instead of just the group name? |
| 476 | - $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupGroup&url=' . urlencode($user); | |
| 468 | + $url = 'https://' . $this->api_base . '/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupGroup&url=' . rawurlencode($user); | |
| 477 | 469 | $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); |
| 478 | 470 | $response = $this->process_response($response, 'flickr', 'group'); |
| 479 | 471 | if (!empty($response['error'])) { |
| 480 | 472 | return $response; |
| @@ -490,44 +482,53 @@ | ||
| 490 | 482 | $parameters['api_key'] = $photonic_flickr_api_key; |
| 491 | 483 | $parameters['format'] = 'json'; |
| 492 | 484 | $parameters['nojsoncallback'] = 1; |
| 493 | 485 | |
| 494 | - if ($display_type == 'single-photo') { | |
| 486 | + if ('single-photo' === $display_type) { | |
| 495 | 487 | $parameters['view'] = 'photo'; |
| 496 | 488 | $parameters['method'] = 'flickr.photos.search'; |
| 489 | + $parameters['extras'] = 'url_q'; | |
| 497 | 490 | $parameters['per_page'] = 500; |
| 498 | 491 | } |
| 499 | - else if ($display_type == 'multi-photo') { | |
| 492 | + elseif ('multi-photo' === $display_type) { | |
| 500 | 493 | $parameters['view'] = 'photos'; |
| 501 | 494 | $parameters['method'] = 'flickr.photos.search'; |
| 495 | + $parameters['extras'] = 'url_q'; | |
| 502 | 496 | } |
| 503 | - else if ($display_type == 'multi-album' || $display_type == 'album-photo') { | |
| 497 | + elseif ('multi-album' === $display_type || 'album-photo' === $display_type) { | |
| 504 | 498 | $parameters['view'] = 'photosets'; |
| 505 | 499 | $parameters['method'] = 'flickr.photosets.getList'; |
| 500 | + $parameters['primary_photo_extras'] = 'url_q'; | |
| 501 | + $parameters['per_page'] = 500; | |
| 506 | 502 | } |
| 507 | - else if ($display_type == 'multi-gallery' || $display_type == 'gallery-photo') { | |
| 503 | + elseif ('multi-gallery' === $display_type || 'gallery-photo' === $display_type) { | |
| 508 | 504 | $parameters['view'] = 'galleries'; |
| 509 | 505 | $parameters['method'] = 'flickr.galleries.getList'; |
| 506 | + $parameters['primary_photo_extras'] = 'url_q'; | |
| 510 | 507 | $parameters['per_page'] = 500; |
| 511 | 508 | } |
| 512 | - else if ($display_type == 'collection' || $display_type == 'collections') { | |
| 509 | + elseif ('collection' === $display_type || 'collections' === $display_type) { | |
| 513 | 510 | $parameters['view'] = 'collections'; |
| 514 | 511 | $parameters['method'] = 'flickr.collections.getTree'; |
| 515 | 512 | } |
| 516 | 513 | |
| 517 | 514 | global $photonic_flickr_access_token; |
| 518 | - require_once(PHOTONIC_PATH.'/Modules/Flickr.php'); | |
| 519 | - $module = \Photonic_Plugin\Modules\Flickr::get_instance(); | |
| 515 | + require_once PHOTONIC_PATH . '/Platforms/Flickr.php'; | |
| 516 | + $module = \Photonic_Plugin\Platforms\Flickr::get_instance(); | |
| 520 | 517 | if (!empty($photonic_flickr_access_token)) { |
| 521 | - $parameters = $module->sign_call('https://api.flickr.com/services/rest/', 'GET', $parameters); | |
| 518 | + $parameters = $module->sign_call('https://' . $this->api_base . '/services/rest/', 'GET', $parameters); | |
| 522 | 519 | } |
| 523 | 520 | |
| 524 | - $url = add_query_arg($parameters, 'https://api.flickr.com/services/rest/'); | |
| 521 | + $url = add_query_arg($parameters, 'https://' . $this->api_base . '/services/rest/'); | |
| 525 | 522 | $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); |
| 526 | 523 | |
| 527 | 524 | $hidden = []; |
| 528 | - if (isset($parameters['user_id'])) $hidden['user_id'] = $parameters['user_id']; | |
| 529 | - if (isset($parameters['group_id'])) $hidden['group_id'] = $parameters['group_id']; | |
| 525 | + if (isset($parameters['user_id'])) { | |
| 526 | + $hidden['user_id'] = $parameters['user_id']; | |
| 527 | + } | |
| 528 | + if (isset($parameters['group_id'])) { | |
| 529 | + $hidden['group_id'] = $parameters['group_id']; | |
| 530 | + } | |
| 530 | 531 | |
| 531 | 532 | return [$response, $hidden, $url]; |
| 532 | 533 | } |
| 533 | 534 | |
| @@ -537,22 +538,22 @@ | ||
| 537 | 538 | * @param $response |
| 538 | 539 | * @param $display_type |
| 539 | 540 | * @param null $url |
| 540 | 541 | * @param array $pagination |
| 541 | - * @return mixed|void | |
| 542 | + * @return array | |
| 542 | 543 | */ |
| 543 | - function process_response($response, $display_type, $url = null, &$pagination = []) { | |
| 544 | + public function process_response($response, $display_type, $url = null, &$pagination = []): array { | |
| 544 | 545 | $objects = []; |
| 545 | 546 | $body = json_decode(wp_remote_retrieve_body($response)); |
| 546 | 547 | |
| 547 | - if (isset($body->stat) && $body->stat == 'fail') { | |
| 548 | + if (isset($body->stat) && 'fail' === $body->stat) { | |
| 548 | 549 | Photonic::log($response); |
| 549 | 550 | return ['error' => $body->message]; |
| 550 | 551 | } |
| 551 | 552 | |
| 552 | 553 | if (isset($body->photosets) && isset($body->photosets->photoset)) { |
| 553 | -// $page = (int)($body->photosets->page); // Not needed because apparently the photosets.getList call returns all photosets for now | |
| 554 | -// $pages = (int)($body->photosets->pages); // Not needed because apparently the photosets.getList call returns all photosets for now | |
| 554 | + $page = (int) ($body->photosets->page); // 22-ug-2022: Needed now, because photosets.getList caps per_page at 500 | |
| 555 | + $pages = (int) ($body->photosets->pages); // 22-ug-2022: Needed now, because photosets.getList caps per_page at 500 | |
| 555 | 556 | $photosets = $body->photosets->photoset; |
| 556 | 557 | foreach ($photosets as $flickr_object) { |
| 557 | 558 | $object = []; |
| 558 | 559 | $object['id'] = $flickr_object->id; |
| @@ -557,33 +558,41 @@ | ||
| 557 | 558 | $object = []; |
| 558 | 559 | $object['id'] = $flickr_object->id; |
| 559 | 560 | $object['title'] = esc_attr($flickr_object->title->_content); |
| 560 | 561 | $object['counters'] = []; |
| 561 | - if (!empty($flickr_object->photos)) $object['counters'][] = esc_html(sprintf(_n('%s photo', '%s photos', $flickr_object->photos, 'photonic'), $flickr_object->photos)); | |
| 562 | - if (!empty($flickr_object->videos)) $object['counters'][] = esc_html(sprintf(_n('%s video', '%s videos', $flickr_object->videos, 'photonic'), $flickr_object->videos)); | |
| 563 | - $object['thumbnail'] = "https://farm" . $flickr_object->farm . ".staticflickr.com/" . $flickr_object->server . "/" . $flickr_object->primary . "_" . $flickr_object->secret . "_q.jpg"; | |
| 562 | + if (!empty($flickr_object->photos)) { | |
| 563 | + $object['counters'][] = esc_html(sprintf(_n('%s photo', '%s photos', $flickr_object->photos, 'photonic'), $flickr_object->photos)); | |
| 564 | + } | |
| 565 | + if (!empty($flickr_object->videos)) { | |
| 566 | + $object['counters'][] = esc_html(sprintf(_n('%s video', '%s videos', $flickr_object->videos, 'photonic'), $flickr_object->videos)); | |
| 567 | + } | |
| 568 | + $object['thumbnail'] = esc_url($flickr_object->primary_photo_extras->url_q ?? "https://farm" . $flickr_object->farm . ".staticflickr.com/" . $flickr_object->server . "/" . $flickr_object->primary . "_" . $flickr_object->secret . "_q.jpg"); | |
| 564 | 569 | $objects[] = $object; |
| 565 | 570 | } |
| 566 | 571 | } |
| 567 | - else if (isset($body->galleries) && isset($body->galleries->gallery)) { | |
| 568 | - $page = (int)($body->galleries->page); | |
| 569 | - $pages = (int)($body->galleries->pages); | |
| 572 | + elseif (isset($body->galleries) && isset($body->galleries->gallery)) { | |
| 573 | + $page = (int) ($body->galleries->page); | |
| 574 | + $pages = (int) ($body->galleries->pages); | |
| 570 | 575 | $galleries = $body->galleries->gallery; |
| 571 | 576 | foreach ($galleries as $flickr_object) { |
| 572 | 577 | $object = []; |
| 573 | - $object['id'] = substr($flickr_object->id, strpos($flickr_object->id, '-') + 1); //$flickr_object->id; | |
| 578 | + $object['id'] = substr($flickr_object->id, strpos($flickr_object->id, '-') + 1); // $flickr_object->id; | |
| 574 | 579 | $object['title'] = esc_attr($flickr_object->title->_content); |
| 575 | 580 | $object['counters'] = []; |
| 576 | - if (!empty($flickr_object->count_photos)) $object['counters'][] = esc_html(sprintf(_n('%s photo', '%s photos', $flickr_object->count_photos, 'photonic'), $flickr_object->count_photos)); | |
| 577 | - if (!empty($flickr_object->count_videos)) $object['counters'][] = esc_html(sprintf(_n('%s video', '%s videos', $flickr_object->count_videos, 'photonic'), $flickr_object->count_videos)); | |
| 578 | - $object['thumbnail'] = "https://farm" . $flickr_object->primary_photo_farm . ".staticflickr.com/" . $flickr_object->primary_photo_server . "/" . $flickr_object->primary_photo_id . "_" . $flickr_object->primary_photo_secret . "_q.jpg"; | |
| 581 | + if (!empty($flickr_object->count_photos)) { | |
| 582 | + $object['counters'][] = esc_html(sprintf(_n('%s photo', '%s photos', $flickr_object->count_photos, 'photonic'), $flickr_object->count_photos)); | |
| 583 | + } | |
| 584 | + if (!empty($flickr_object->count_videos)) { | |
| 585 | + $object['counters'][] = esc_html(sprintf(_n('%s video', '%s videos', $flickr_object->count_videos, 'photonic'), $flickr_object->count_videos)); | |
| 586 | + } | |
| 587 | + $object['thumbnail'] = esc_url($flickr_object->primary_photo_extras->url_q ?? "https://farm" . $flickr_object->primary_photo_farm . ".staticflickr.com/" . $flickr_object->primary_photo_server . "/" . $flickr_object->primary_photo_id . "_" . $flickr_object->primary_photo_secret . "_q.jpg"); | |
| 579 | 588 | $objects[] = $object; |
| 580 | 589 | } |
| 581 | 590 | } |
| 582 | - else if (isset($body->photos) && isset($body->photos->photo)) { | |
| 583 | - if ($display_type == 'single-photo') { | |
| 584 | - $page = (int)($body->photos->page); | |
| 585 | - $pages = (int)($body->photos->pages); | |
| 591 | + elseif (isset($body->photos) && isset($body->photos->photo)) { | |
| 592 | + if ('single-photo' === $display_type) { | |
| 593 | + $page = (int) ($body->photos->page); | |
| 594 | + $pages = (int) ($body->photos->pages); | |
| 586 | 595 | if ($page < $pages && !empty($url)) { |
| 587 | 596 | $url = remove_query_arg('page', $url); |
| 588 | 597 | $pagination['url'] = add_query_arg(['page' => $page + 1], $url); |
| 589 | 598 | } |
| @@ -592,28 +601,30 @@ | ||
| 592 | 601 | foreach ($photos as $flickr_object) { |
| 593 | 602 | $object = []; |
| 594 | 603 | $object['id'] = $flickr_object->id; |
| 595 | 604 | $object['title'] = esc_attr($flickr_object->title); |
| 596 | - $object['thumbnail'] = 'https://farm' . $flickr_object->farm . '.staticflickr.com/' . $flickr_object->server . '/' . $flickr_object->id . '_' . $flickr_object->secret . '_q.jpg'; | |
| 605 | + $object['thumbnail'] = esc_url($flickr_object->url_q ?? 'https://farm' . $flickr_object->farm . '.staticflickr.com/' . $flickr_object->server . '/' . $flickr_object->id . '_' . $flickr_object->secret . '_q.jpg'); | |
| 597 | 606 | $objects[] = $object; |
| 598 | 607 | } |
| 599 | 608 | } |
| 600 | - else if (isset($body->collections) && isset($body->collections->collection)) { | |
| 609 | + elseif (isset($body->collections) && isset($body->collections->collection)) { | |
| 601 | 610 | $collections = $body->collections->collection; |
| 602 | 611 | foreach ($collections as $flickr_object) { |
| 603 | 612 | $object = []; |
| 604 | - $object['id'] = substr($flickr_object->id, strpos($flickr_object->id, '-') + 1); | |
| 613 | + $object['id'] = substr($flickr_object->id, strpos($flickr_object->id, '-') + 1); | |
| 605 | 614 | $object['title'] = esc_attr($flickr_object->title); |
| 606 | 615 | $object['counters'] = []; |
| 607 | - if (!empty($flickr_object->set)) $object['counters'][] = esc_html(sprintf(_n('%s album', '%s albums', count($flickr_object->set), 'photonic'), count($flickr_object->set))); | |
| 616 | + if (!empty($flickr_object->set)) { | |
| 617 | + $object['counters'][] = esc_html(sprintf(_n('%s album', '%s albums', count($flickr_object->set), 'photonic'), count($flickr_object->set))); | |
| 618 | + } | |
| 608 | 619 | $object['thumbnail'] = $flickr_object->iconlarge; |
| 609 | 620 | $objects[] = $object; |
| 610 | 621 | } |
| 611 | 622 | } |
| 612 | - else if (isset($body->user)) { | |
| 623 | + elseif (isset($body->user)) { | |
| 613 | 624 | return ['success' => ['user_id' => $body->user->id]]; |
| 614 | 625 | } |
| 615 | - else if (isset($body->group)) { | |
| 626 | + elseif (isset($body->group)) { | |
| 616 | 627 | return ['success' => ['group_id' => $body->group->id]]; |
| 617 | 628 | } |
| 618 | 629 | |
| 619 | 630 | if (!empty($page) && !empty($pages) && $page < $pages && !empty($url)) { |
| @@ -624,41 +635,46 @@ | ||
| 624 | 635 | } |
| 625 | 636 | |
| 626 | 637 | /** |
| 627 | 638 | * @param $display_type |
| 628 | - * @return array|mixed | |
| 639 | + * @return array | |
| 629 | 640 | */ |
| 630 | - function construct_shortcode_from_screen_selections($display_type) { | |
| 641 | + public function construct_shortcode_from_screen_selections($display_type): array { | |
| 631 | 642 | $short_code = []; |
| 632 | 643 | |
| 633 | - if ($display_type == 'single-photo') { | |
| 634 | - $short_code['view'] = 'photo'; | |
| 635 | - $short_code['photo_id'] = sanitize_text_field($_POST['selected_data']); | |
| 644 | + if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) { | |
| 645 | + if ('single-photo' === $display_type) { | |
| 646 | + $short_code['view'] = 'photo'; | |
| 647 | + $short_code['photo_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? '')); | |
| 648 | + } | |
| 649 | + elseif ('multi-photo' === $display_type) { | |
| 650 | + $short_code['view'] = 'photos'; | |
| 651 | + } | |
| 652 | + elseif ('album-photo' === $display_type) { | |
| 653 | + $short_code['view'] = 'photosets'; | |
| 654 | + $short_code['photoset_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? '')); | |
| 655 | + } | |
| 656 | + elseif ('gallery-photo' === $display_type) { | |
| 657 | + $short_code['view'] = 'galleries'; | |
| 658 | + $short_code['gallery_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? '')); | |
| 659 | + } | |
| 660 | + elseif ('multi-album' === $display_type) { | |
| 661 | + $short_code['view'] = 'photosets'; | |
| 662 | + unset($short_code['photoset_id']); | |
| 663 | + unset($short_code['gallery_id']); | |
| 664 | + unset($short_code['collection_id']); | |
| 665 | + } | |
| 666 | + elseif ('multi-gallery' === $display_type) { | |
| 667 | + $short_code['view'] = 'galleries'; | |
| 668 | + } | |
| 669 | + elseif ('collection' === $display_type) { | |
| 670 | + $short_code['view'] = 'collections'; | |
| 671 | + $short_code['collection_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? '')); | |
| 672 | + } | |
| 673 | + elseif ('collections' === $display_type) { | |
| 674 | + $short_code['view'] = 'collections'; | |
| 675 | + } | |
| 636 | 676 | } |
| 637 | - else if ($display_type == 'multi-photo') { | |
| 638 | - $short_code['view'] = 'photos'; | |
| 639 | - } | |
| 640 | - else if ($display_type == 'album-photo') { | |
| 641 | - $short_code['view'] = 'photosets'; | |
| 642 | - $short_code['photoset_id'] = sanitize_text_field($_POST['selected_data']); | |
| 643 | - } | |
| 644 | - else if ($display_type == 'gallery-photo') { | |
| 645 | - $short_code['view'] = 'galleries'; | |
| 646 | - $short_code['gallery_id'] = sanitize_text_field($_POST['selected_data']); | |
| 647 | - } | |
| 648 | - else if ($display_type == 'multi-album') { | |
| 649 | - $short_code['view'] = 'photosets'; | |
| 650 | - } | |
| 651 | - else if ($display_type == 'multi-gallery') { | |
| 652 | - $short_code['view'] = 'galleries'; | |
| 653 | - } | |
| 654 | - else if ($display_type == 'collection') { | |
| 655 | - $short_code['view'] = 'collections'; | |
| 656 | - $short_code['collection_id'] = sanitize_text_field($_POST['selected_data']); | |
| 657 | - } | |
| 658 | - else if ($display_type == 'collections') { | |
| 659 | - $short_code['view'] = 'collections'; | |
| 660 | - } | |
| 661 | 677 | |
| 662 | 678 | return $short_code; |
| 663 | 679 | } |
| 664 | 680 | |
| @@ -663,11 +679,11 @@ | ||
| 663 | 679 | } |
| 664 | 680 | |
| 665 | 681 | /** |
| 666 | 682 | * @param $input |
| 667 | - * @return array|mixed | |
| 683 | + * @return array | |
| 668 | 684 | */ |
| 669 | - function deconstruct_shortcode_to_screen_selections($input) { | |
| 685 | + public function deconstruct_shortcode_to_screen_selections($input): array { | |
| 670 | 686 | $deconstructed = []; |
| 671 | 687 | |
| 672 | 688 | // Potential for an existing (old) shortcode to not have a user_id. E.g. Just defining photoset_id. |
| 673 | 689 | // Rather than defaulting to the default user, we will make the user put it in this time. |
| @@ -674,24 +690,24 @@ | ||
| 674 | 690 | if (!empty($input->user_id)) { |
| 675 | 691 | $deconstructed['for'] = 'other'; |
| 676 | 692 | $deconstructed['login'] = $input->user_id; |
| 677 | 693 | } |
| 678 | - else if (!empty($input->group_id)) { | |
| 694 | + elseif (!empty($input->group_id)) { | |
| 679 | 695 | $deconstructed['for'] = 'group'; |
| 680 | 696 | $deconstructed['group'] = $input->group_id; |
| 681 | 697 | } |
| 682 | 698 | |
| 683 | 699 | if (!empty($input->view)) { |
| 684 | - if ($input->view == 'collections' && empty($input->collection_id)) { | |
| 700 | + if ('collections' === $input->view && empty($input->collection_id)) { | |
| 685 | 701 | $deconstructed['display_type'] = 'collections'; |
| 686 | 702 | } |
| 687 | - else if ($input->view == 'galleries' && empty($input->gallery_id)) { | |
| 703 | + elseif ('galleries' === $input->view && empty($input->gallery_id)) { | |
| 688 | 704 | $deconstructed['display_type'] = 'multi-gallery'; |
| 689 | 705 | } |
| 690 | - else if ($input->view == 'photosets' && empty($input->photoset_id)) { | |
| 706 | + elseif ('photosets' === $input->view && empty($input->photoset_id)) { | |
| 691 | 707 | $deconstructed['display_type'] = 'multi-album'; |
| 692 | 708 | } |
| 693 | - else if ($input->view == 'photos') { | |
| 709 | + elseif ('photos' === $input->view) { | |
| 694 | 710 | $deconstructed['display_type'] = 'multi-photo'; |
| 695 | 711 | } |
| 696 | 712 | } |
| 697 | 713 | |
| @@ -698,17 +714,17 @@ | ||
| 698 | 714 | if (!empty($input->collection_id)) { |
| 699 | 715 | $deconstructed['display_type'] = 'collection'; |
| 700 | 716 | $deconstructed['selected_data'] = $input->collection_id; |
| 701 | 717 | } |
| 702 | - else if (!empty($input->gallery_id)) { | |
| 718 | + elseif (!empty($input->gallery_id)) { | |
| 703 | 719 | $deconstructed['display_type'] = 'gallery-photo'; |
| 704 | 720 | $deconstructed['selected_data'] = $input->gallery_id; |
| 705 | 721 | } |
| 706 | - else if (!empty($input->photoset_id)) { | |
| 722 | + elseif (!empty($input->photoset_id)) { | |
| 707 | 723 | $deconstructed['display_type'] = 'album-photo'; |
| 708 | 724 | $deconstructed['selected_data'] = $input->photoset_id; |
| 709 | 725 | } |
| 710 | - else if (!empty($input->photo_id)) { | |
| 726 | + elseif (!empty($input->photo_id)) { | |
| 711 | 727 | $deconstructed['display_type'] = 'single-photo'; |
| 712 | 728 | $deconstructed['selected_data'] = $input->photo_id; |
| 713 | 729 | } |
| 714 | 730 | |
| @@ -713,5 +729,5 @@ | ||
| 713 | 729 | } |
| 714 | 730 | |
| 715 | 731 | return $deconstructed; |
| 716 | 732 | } |
| 717 | -} | |
| 733 | +} | |