| @@ -1,16 +1,26 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace Photonic_Plugin\Admin; |
| 3 | 4 | |
| 5 | +if (!current_user_can('edit_posts')) { | |
| 6 | + wp_die(esc_html__('You are not authorized to use this capability.', 'photonic')); | |
| 7 | +} | |
| 8 | + | |
| 4 | 9 | use Photonic_Plugin\Core\Photonic; |
| 5 | -use Photonic_Plugin\Modules\Google_Photos; | |
| 6 | -use Photonic_Plugin\Modules\SmugMug; | |
| 10 | +use Photonic_Plugin\Platforms\Google_Photos; | |
| 11 | +use Photonic_Plugin\Platforms\SmugMug; | |
| 7 | 12 | use WP_Error; |
| 8 | 13 | |
| 9 | -require_once('Admin_Page.php'); | |
| 14 | +require_once 'Admin_Page.php'; | |
| 10 | 15 | |
| 11 | 16 | class Helper extends Admin_Page { |
| 12 | - function render_content() { | |
| 17 | + public function render_content() { | |
| 18 | + $user = get_current_user_id(); | |
| 19 | + if (0 === $user) { | |
| 20 | + $user = wp_rand(1); | |
| 21 | + } | |
| 22 | + | |
| 13 | 23 | ?> |
| 14 | 24 | <form method="post" id="photonic-helper-form"> |
| 15 | 25 | <table class="photonic-helper"> |
| 16 | 26 | <thead> |
| @@ -19,14 +29,16 @@ | ||
| 19 | 29 | </tr> |
| 20 | 30 | </thead> |
| 21 | 31 | <tbody> |
| 22 | 32 | <tr> |
| 23 | - <th class="photonic-helper-row-header" scope="row"><?php esc_html_e('Find your User ID', 'photonic'); ?></th> | |
| 24 | - <td><?php $this->display_flickr_id_helper(); ?></td> | |
| 33 | + <th class="photonic-helper-row-header" | |
| 34 | + scope="row"><?php esc_html_e('Find your User ID', 'photonic'); ?></th> | |
| 35 | + <td class="photonic-helper-area"><?php $this->display_flickr_id_helper(); ?></td> | |
| 25 | 36 | </tr> |
| 26 | 37 | <tr> |
| 27 | - <th class="photonic-helper-row-header" scope="row"><?php esc_html_e('Find your Group ID', 'photonic'); ?></th> | |
| 28 | - <td><?php $this->display_flickr_group_helper(); ?></td> | |
| 38 | + <th class="photonic-helper-row-header" | |
| 39 | + scope="row"><?php esc_html_e('Find your Group ID', 'photonic'); ?></th> | |
| 40 | + <td class="photonic-helper-area"><?php $this->display_flickr_group_helper(); ?></td> | |
| 29 | 41 | </tr> |
| 30 | 42 | </tbody> |
| 31 | 43 | </table> |
| 32 | 44 | |
| @@ -32,29 +44,16 @@ | ||
| 32 | 44 | |
| 33 | 45 | <table class="photonic-helper"> |
| 34 | 46 | <thead> |
| 35 | 47 | <tr> |
| 36 | - <th class="photonic-helper-header" colspan="2">Google Photos</th> | |
| 37 | - </tr> | |
| 38 | - </thead> | |
| 39 | - <tbody> | |
| 40 | - <tr> | |
| 41 | - <th class="photonic-helper-row-header" scope="row"><?php esc_html_e('Find your Album IDs', 'photonic'); ?></th> | |
| 42 | - <td><?php $this->display_google_photos_album_helper(); ?></td> | |
| 43 | - </tr> | |
| 44 | - </tbody> | |
| 45 | - </table> | |
| 46 | - | |
| 47 | - <table class="photonic-helper"> | |
| 48 | - <thead> | |
| 49 | - <tr> | |
| 50 | 48 | <th class="photonic-helper-header" colspan="2">SmugMug</th> |
| 51 | 49 | </tr> |
| 52 | 50 | </thead> |
| 53 | 51 | <tbody> |
| 54 | 52 | <tr> |
| 55 | - <th class="photonic-helper-row-header" scope="row"><?php esc_html_e('Find your Album and Folder IDs', 'photonic'); ?></th> | |
| 56 | - <td><?php $this->display_smugmug_album_id_helper(); ?></td> | |
| 53 | + <th class="photonic-helper-row-header" | |
| 54 | + scope="row"><?php esc_html_e('Find your Album and Folder IDs', 'photonic'); ?></th> | |
| 55 | + <td class="photonic-helper-area"><?php $this->display_smugmug_album_id_helper(); ?></td> | |
| 57 | 56 | </tr> |
| 58 | 57 | </tbody> |
| 59 | 58 | </table> |
| 60 | 59 | |
| @@ -65,272 +64,242 @@ | ||
| 65 | 64 | </tr> |
| 66 | 65 | </thead> |
| 67 | 66 | <tbody> |
| 68 | 67 | <tr> |
| 69 | - <th class="photonic-helper-row-header" scope="row"><?php esc_html_e('Categories', 'photonic'); ?></th> | |
| 70 | - <td><?php $this->display_zenfolio_category_helper(); ?></td> | |
| 68 | + <th class="photonic-helper-row-header" | |
| 69 | + scope="row"><?php esc_html_e('Categories', 'photonic'); ?></th> | |
| 70 | + <td class="photonic-helper-area"><?php $this->display_zenfolio_category_helper(); ?></td> | |
| 71 | 71 | </tr> |
| 72 | 72 | </tbody> |
| 73 | 73 | </table> |
| 74 | + <?php | |
| 75 | + wp_nonce_field('photonic-helper-' . $user, 'photonic_helper_nonce'); | |
| 76 | + ?> | |
| 74 | 77 | </form> |
| 75 | 78 | <?php |
| 76 | 79 | } |
| 77 | 80 | |
| 78 | - function display_flickr_id_helper() { | |
| 81 | + private function display_flickr_id_helper() { | |
| 79 | 82 | global $photonic_flickr_api_key; |
| 80 | 83 | if (empty($photonic_flickr_api_key)) { |
| 81 | 84 | echo sprintf(esc_html__('Please set up your Flickr API Key under %s', 'photonic'), '<em>Photonic → Settings → Flickr → Flickr Settings</em>'); |
| 82 | 85 | } |
| 83 | 86 | else { |
| 84 | - echo '<label>'.esc_html__('Enter your Flickr photostream URL and click "Find"', 'photonic'); | |
| 87 | + echo '<label>' . esc_html__('Enter your Flickr photostream URL and click "Find"', 'photonic'); | |
| 85 | 88 | echo '<input type="text" value="https://www.flickr.com/photos/username/" id="photonic-flickr-user" name="photonic-flickr-user"/>'; |
| 86 | 89 | echo '</label>'; |
| 87 | - echo '<input type="button" value="'.esc_attr__('Find', 'photonic').'" id="photonic-flickr-user-find" class="button button-primary"/>'; | |
| 90 | + echo '<input type="button" value="' . esc_attr__('Find', 'photonic') . '" id="photonic-flickr-user-find" class="button button-primary"/>'; | |
| 88 | 91 | echo '<div class="result"> </div>'; |
| 89 | 92 | } |
| 90 | 93 | } |
| 91 | 94 | |
| 92 | - function display_flickr_group_helper() { | |
| 95 | + private function display_flickr_group_helper() { | |
| 93 | 96 | global $photonic_flickr_api_key; |
| 94 | 97 | if (empty($photonic_flickr_api_key)) { |
| 95 | 98 | echo sprintf(esc_html__('Please set up your Flickr API Key under %s', 'photonic'), '<em>Photonic → Settings → Flickr → Flickr Settings</em>'); |
| 96 | 99 | } |
| 97 | 100 | else { |
| 98 | - echo '<label>'.esc_html__('Enter your Flickr group URL and click "Find"', 'photonic'); | |
| 101 | + echo '<label>' . esc_html__('Enter your Flickr group URL and click "Find"', 'photonic'); | |
| 99 | 102 | echo '<input type="text" value="https://www.flickr.com/groups/groupname/" id="photonic-flickr-group" name="photonic-flickr-group"/>'; |
| 100 | 103 | echo '</label>'; |
| 101 | - echo '<input type="button" value="'.esc_attr__('Find', 'photonic').'" id="photonic-flickr-group-find" class="button button-primary"/>'; | |
| 104 | + echo '<input type="button" value="' . esc_attr__('Find', 'photonic') . '" id="photonic-flickr-group-find" class="button button-primary"/>'; | |
| 102 | 105 | echo '<div class="result"> </div>'; |
| 103 | 106 | } |
| 104 | 107 | } |
| 105 | 108 | |
| 106 | - function display_google_photos_album_helper() { | |
| 109 | + private function display_google_photos_album_helper() { | |
| 107 | 110 | global $photonic_google_client_id, $photonic_google_client_secret, $photonic_google_refresh_token; |
| 108 | - //global $photonic_google_use_own_keys; | |
| 109 | -// if (!empty($photonic_google_use_own_keys) && (empty($photonic_google_client_id) || empty($photonic_google_client_secret))) { | |
| 111 | + // global $photonic_google_use_own_keys; | |
| 112 | + // if (!empty($photonic_google_use_own_keys) && (empty($photonic_google_client_id) || empty($photonic_google_client_secret))) { | |
| 110 | 113 | if (empty($photonic_google_client_id) || empty($photonic_google_client_secret)) { |
| 111 | - echo sprintf(esc_html__('Please set up your Google Client ID and Client Secret under %s', 'photonic'), | |
| 112 | - '<em>Photonic → Settings → Google Photos → Google Photos Settings</em>'); | |
| 114 | + echo sprintf(esc_html__('Please set up your Google Client ID and Client Secret under %s', 'photonic'), '<em>Photonic → Settings → Google Photos → Google Photos Settings</em>'); | |
| 113 | 115 | } |
| 114 | - else if (empty($photonic_google_refresh_token)) { | |
| 115 | - echo sprintf(esc_html__('Please obtain your Refresh Token and save it under %s', 'photonic'), | |
| 116 | - '<em>Photonic → Settings → Google Photos → Google Photos Settings</em>'); | |
| 116 | + elseif (empty($photonic_google_refresh_token)) { | |
| 117 | + echo sprintf(esc_html__('Please obtain your Refresh Token and save it under %s', 'photonic'), '<em>Photonic → Settings → Google Photos → Google Photos Settings</em>'); | |
| 117 | 118 | } |
| 118 | 119 | else { |
| 119 | - echo esc_html__("Clicking on the button below will show all albums for the authenticated user.", 'photonic').'<br/>'; | |
| 120 | - echo '<input type="button" value="'.esc_attr__('Find my albums', 'photonic').'" id="photonic-google-album-find" class="button button-primary"/>'; | |
| 120 | + echo esc_html__("Clicking on the button below will show all albums for the authenticated user.", 'photonic') . '<br/>'; | |
| 121 | + echo '<input type="button" value="' . esc_attr__('Find my albums', 'photonic') . '" id="photonic-google-album-find" class="button button-primary"/>'; | |
| 121 | 122 | echo '<div class="result"> </div>'; |
| 122 | 123 | } |
| 123 | 124 | } |
| 124 | 125 | |
| 125 | - function display_smugmug_album_id_helper() { | |
| 126 | + private function display_smugmug_album_id_helper() { | |
| 126 | 127 | global $photonic_smug_api_key; |
| 127 | 128 | if (empty($photonic_smug_api_key)) { |
| 128 | 129 | echo sprintf(esc_html__('Please set up your SmugMug API Key under %s', 'photonic'), '<em>Photonic → Settings → SmugMug → SmugMug Settings</em>'); |
| 129 | 130 | } |
| 130 | 131 | else { |
| 131 | - echo '<label>'.esc_html__('Enter your SmugMug username and click "Find"', 'photonic'); | |
| 132 | + echo '<label>' . esc_html__('Enter your SmugMug username and click "Find"', 'photonic'); | |
| 132 | 133 | echo '<input type="text" value="username" id="photonic-smugmug-user" name="photonic-smugmug-user"/>'; |
| 133 | 134 | echo '</label>'; |
| 134 | - echo '<input type="button" value="'.esc_attr__('Find', 'photonic').'" id="photonic-smugmug-user-tree" class="button button-primary"/>'; | |
| 135 | + echo '<input type="button" value="' . esc_attr__('Find', 'photonic') . '" id="photonic-smugmug-user-tree" class="button button-primary"/>'; | |
| 135 | 136 | echo '<div class="result"> </div>'; |
| 136 | 137 | } |
| 137 | 138 | } |
| 138 | 139 | |
| 139 | - function display_zenfolio_category_helper() { | |
| 140 | - echo esc_html__('Click "List" to find all available Zenfolio categories.', 'photonic').'<br/>'; | |
| 141 | - echo '<input type="button" value="'.esc_attr__('List', 'photonic').'" id="photonic-zenfolio-categories-find" class="button button-primary"/>'; | |
| 140 | + private function display_zenfolio_category_helper() { | |
| 141 | + echo esc_html__('Click "List" to find all available Zenfolio categories.', 'photonic') . '<br/>'; | |
| 142 | + echo '<input type="button" value="' . esc_attr__('List', 'photonic') . '" id="photonic-zenfolio-categories-find" class="button button-primary"/>'; | |
| 142 | 143 | echo '<div class="result"> </div>'; |
| 143 | 144 | } |
| 144 | 145 | |
| 145 | - function invoke_helper() { | |
| 146 | - if (isset($_POST['helper']) && !empty($_POST['helper'])) { | |
| 147 | - $helper = sanitize_text_field($_POST['helper']); | |
| 148 | - $photonic_options = get_option('photonic_options'); | |
| 149 | - switch ($helper) { | |
| 150 | - case 'photonic-flickr-user-find': | |
| 151 | - $flickr_api_key = $photonic_options['flickr_api_key']; | |
| 152 | - $user = isset($_POST['photonic-flickr-user']) ? sanitize_text_field($_POST['photonic-flickr-user']) : ''; | |
| 153 | - $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key='.$flickr_api_key.'&method=flickr.urls.lookupUser&url='.$user; | |
| 154 | - $this->execute_query('flickr', $url, 'flickr.urls.lookupUser'); | |
| 155 | - break; | |
| 146 | + public function invoke_helper() { | |
| 147 | + if (current_user_can('edit_posts') && check_admin_referer('photonic-helper-' . get_current_user_id(), 'photonic_helper_nonce')) { | |
| 148 | + if (!empty($_POST['helper'])) { | |
| 149 | + $helper = sanitize_text_field($_POST['helper']); | |
| 150 | + $photonic_options = get_option('photonic_options'); | |
| 151 | + switch ($helper) { | |
| 152 | + case 'photonic-flickr-user-find': | |
| 153 | + $flickr_api_key = $photonic_options['flickr_api_key']; | |
| 154 | + $user = sanitize_text_field($_POST['photonic-flickr-user'] ?? ''); | |
| 155 | + $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $flickr_api_key . '&method=flickr.urls.lookupUser&url=' . $user; | |
| 156 | + $this->execute_query('flickr', $url, 'flickr.urls.lookupUser'); | |
| 157 | + break; | |
| 156 | 158 | |
| 157 | - case 'photonic-flickr-group-find': | |
| 158 | - $flickr_api_key = $photonic_options['flickr_api_key']; | |
| 159 | - $group = isset($_POST['photonic-flickr-group']) ? sanitize_text_field($_POST['photonic-flickr-group']) : ''; | |
| 160 | - $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key='.$flickr_api_key.'&method=flickr.urls.lookupGroup&url='.$group; | |
| 161 | - $this->execute_query('flickr', $url, 'flickr.urls.lookupGroup'); | |
| 162 | - break; | |
| 159 | + case 'photonic-flickr-group-find': | |
| 160 | + $flickr_api_key = $photonic_options['flickr_api_key']; | |
| 161 | + $group = sanitize_text_field($_POST['photonic-flickr-group'] ?? ''); | |
| 162 | + $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $flickr_api_key . '&method=flickr.urls.lookupGroup&url=' . $group; | |
| 163 | + $this->execute_query('flickr', $url, 'flickr.urls.lookupGroup'); | |
| 164 | + break; | |
| 163 | 165 | |
| 164 | - case 'photonic-smugmug-user-tree': | |
| 165 | - $smugmug_api_key = $photonic_options['smug_api_key']; | |
| 166 | - $user = isset($_POST['photonic-smugmug-user']) ? sanitize_text_field($_POST['photonic-smugmug-user']) : ''; | |
| 167 | - if (!empty($user)) { | |
| 168 | - require_once(PHOTONIC_PATH.'/Modules/SmugMug.php'); | |
| 169 | - $module = SmugMug::get_instance(); | |
| 166 | + case 'photonic-smugmug-user-tree': | |
| 167 | + $smugmug_api_key = $photonic_options['smug_api_key']; | |
| 168 | + $user = sanitize_text_field($_POST['photonic-smugmug-user'] ?? ''); | |
| 169 | + if (!empty($user)) { | |
| 170 | + require_once PHOTONIC_PATH . '/Platforms/SmugMug.php'; | |
| 171 | + $module = SmugMug::get_instance(); | |
| 170 | 172 | |
| 171 | - $config = $module->get_config_object(100); | |
| 172 | - $config['expand']['Node'] = []; | |
| 173 | + global $photonic_smug_nesting_levels; | |
| 174 | + $config = $module->get_config_object(100, $photonic_smug_nesting_levels); | |
| 175 | + $config['expand']['Node'] = []; | |
| 173 | 176 | |
| 174 | - //$api_call = 'https://api.smugmug.com/api/v2/user/' . $user . '?_expand=Node.ChildNodes.ChildNodes.ChildNodes.ChildNodes.ChildNodes'; | |
| 175 | - $api_call = 'https://api.smugmug.com/api/v2/user/' . $user; | |
| 176 | - $args = [ | |
| 177 | - 'APIKey' => $smugmug_api_key, | |
| 178 | - '_accept' => 'application/json', | |
| 179 | - '_verbosity' => 1, | |
| 180 | - '_expandmethod' => 'inline', | |
| 181 | - 'count' => 20 | |
| 182 | - ]; | |
| 177 | + // $api_call = 'https://api.smugmug.com/api/v2/user/' . $user . '?_expand=Node.ChildNodes.ChildNodes.ChildNodes.ChildNodes.ChildNodes'; | |
| 178 | + $api_call = 'https://api.smugmug.com/api/v2/user/' . $user; | |
| 179 | + $args = [ | |
| 180 | + 'APIKey' => $smugmug_api_key, | |
| 181 | + '_accept' => 'application/json', | |
| 182 | + '_verbosity' => 1, | |
| 183 | + '_expandmethod' => 'inline', | |
| 184 | + 'count' => 20 | |
| 185 | + ]; | |
| 183 | 186 | |
| 184 | - $response = Photonic::http($api_call, 'GET', $args); | |
| 185 | - if (!is_wp_error($response)) { | |
| 186 | - $body = $response['body']; | |
| 187 | - $body = json_decode($body); | |
| 188 | - if ($body->Code === 200) { | |
| 189 | - $body = $body->Response; | |
| 190 | - if (isset($body->User) && isset($body->User->Uris) && isset($body->User->Uris->Node)) { | |
| 191 | - $node = $body->User->Uris->Node->Uri; | |
| 192 | - $node = explode('/', $node); | |
| 193 | - $node = array_pop($node); | |
| 194 | - $api_call = 'https://api.smugmug.com/api/v2/node/' . $node . '?_config='.json_encode($config); | |
| 187 | + $response = Photonic::http($api_call, 'GET', $args); | |
| 188 | + if (!is_wp_error($response)) { | |
| 189 | + $body = $response['body']; | |
| 190 | + $body = json_decode($body); | |
| 191 | + if (200 === $body->Code) { | |
| 192 | + $body = $body->Response; | |
| 193 | + if (isset($body->User) && isset($body->User->Uris) && isset($body->User->Uris->Node)) { | |
| 194 | + $node = $body->User->Uris->Node->Uri; | |
| 195 | + $node = explode('/', $node); | |
| 196 | + $node = array_pop($node); | |
| 197 | + $api_call = 'https://api.smugmug.com/api/v2/node/' . $node . '?_config=' . wp_json_encode($config); | |
| 195 | 198 | |
| 196 | - if ($module->oauth_done) { | |
| 197 | - $args = $module->sign_call($api_call, 'GET', $args); | |
| 199 | + if ($module->oauth_done) { | |
| 200 | + $args = $module->sign_call($api_call, 'GET', $args); | |
| 201 | + } | |
| 202 | + else { | |
| 203 | + echo sprintf(esc_html__('If you have protected albums, you will have to %1$sauthenticate%2$s to see the protected albums.', 'photonic'), "<a href='" . esc_url(admin_url('admin.php?page=photonic-auth')) . "'>", "</a>"); | |
| 204 | + } | |
| 205 | + $response = Photonic::http($api_call, 'GET', $args); | |
| 206 | + if (!is_wp_error($response)) { | |
| 207 | + $this->process_smugmug_response($response); | |
| 208 | + } | |
| 209 | + else { | |
| 210 | + $this->get_wp_errors($response); | |
| 211 | + } | |
| 198 | 212 | } |
| 199 | - else { | |
| 200 | - echo sprintf(esc_html__("If you have protected albums, you will have to %1sauthenticate%2s to see the protected albums.", 'photonic'), "<a href='".admin_url('admin.php?page=photonic-auth')."'>", "</a>"); | |
| 201 | - } | |
| 202 | - $response = Photonic::http($api_call, 'GET', $args); | |
| 203 | - if (!is_wp_error($response)) { | |
| 204 | - $this->process_smugmug_response($response); | |
| 205 | - } | |
| 206 | - else { | |
| 207 | - echo $this->get_wp_errors($response); | |
| 208 | - } | |
| 209 | 213 | } |
| 210 | 214 | } |
| 215 | + else { | |
| 216 | + $this->get_wp_errors($response); | |
| 217 | + } | |
| 211 | 218 | } |
| 212 | - else { | |
| 213 | - echo $this->get_wp_errors($response); | |
| 214 | - } | |
| 219 | + break; | |
| 215 | 220 | |
| 216 | - } | |
| 217 | - break; | |
| 218 | - | |
| 219 | - case 'photonic-google-album-find': | |
| 220 | - case 'photonic-google-album-more': | |
| 221 | - $url = 'https://photoslibrary.googleapis.com/v1/albums'; | |
| 222 | - | |
| 223 | - global $photonic_google_refresh_token; | |
| 224 | - require_once(PHOTONIC_PATH.'/Modules/Google_Photos.php'); | |
| 225 | - $module = Google_Photos::get_instance(); | |
| 226 | - $module->authenticate($photonic_google_refresh_token); | |
| 227 | - if (!empty($module->access_token)) { | |
| 228 | - $query_args = [ | |
| 229 | - 'access_token' => $module->access_token, | |
| 230 | - 'pageSize' => 50, | |
| 231 | - ]; | |
| 232 | - if (!empty($_POST['nextPageToken'])) { | |
| 233 | - $query_args['pageToken'] = $_POST['nextPageToken']; | |
| 234 | - } | |
| 235 | - | |
| 236 | - $url = add_query_arg( | |
| 237 | - $query_args, | |
| 238 | - $url); | |
| 239 | - } | |
| 240 | - | |
| 241 | - $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); | |
| 242 | - if (!is_wp_error($response) && $response['response']['code'] == 200) { | |
| 243 | - $response = $response['body']; | |
| 244 | - $this->process_google_response($response, !empty($_POST['nextPageToken'])); | |
| 245 | - } | |
| 246 | - else { | |
| 247 | - echo esc_html__("Encountered error: ")."<br/>"; | |
| 248 | - echo $this->get_wp_errors($response); | |
| 249 | - } | |
| 250 | - | |
| 251 | - break; | |
| 252 | - | |
| 253 | - case 'photonic-zenfolio-categories-find': | |
| 254 | - $url = 'https://api.zenfolio.com/api/1.8/zfapi.asmx/GetCategories'; | |
| 255 | - $this->execute_query('zenfolio', $url, 'GetCategories'); | |
| 256 | - break; | |
| 221 | + case 'photonic-zenfolio-categories-find': | |
| 222 | + $url = 'https://api.zenfolio.com/api/1.8/zfapi.asmx/GetCategories'; | |
| 223 | + $this->execute_query('zenfolio', $url, 'GetCategories'); | |
| 224 | + break; | |
| 225 | + } | |
| 257 | 226 | } |
| 258 | 227 | } |
| 259 | 228 | die(); |
| 260 | 229 | } |
| 261 | 230 | |
| 262 | - function execute_query($where, $url, $method) { | |
| 231 | + private function execute_query($where, $url, $method) { | |
| 263 | 232 | $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); |
| 264 | 233 | if (!is_wp_error($response)) { |
| 265 | - if (isset($response['response']) && isset($response['response']['code'])) { | |
| 266 | - if ($response['response']['code'] == 200) { | |
| 234 | + if (isset($response['response']['code'])) { | |
| 235 | + if (200 === $response['response']['code']) { | |
| 267 | 236 | if (isset($response['body'])) { |
| 268 | - if ($where == 'flickr') { | |
| 237 | + if ('flickr' === $where) { | |
| 269 | 238 | $this->execute_flickr_query($response['body'], $method); |
| 270 | 239 | } |
| 271 | - else if ($where == 'zenfolio') { | |
| 240 | + elseif ('zenfolio' === $where) { | |
| 272 | 241 | $this->execute_zenfolio_query($response['body'], $method); |
| 273 | 242 | } |
| 274 | 243 | } |
| 275 | 244 | else { |
| 276 | - echo '<span class="found-id-text">'.esc_html__('No response from server!', 'photonic').'</span>'; | |
| 245 | + echo '<span class="found-id-text">' . esc_html__('No response from server!', 'photonic') . '</span>'; | |
| 277 | 246 | } |
| 278 | 247 | } |
| 279 | 248 | else { |
| 280 | - echo '<span class="found-id-text">'.$response['response']['message'].'</span>'; | |
| 249 | + echo '<span class="found-id-text">' . esc_html($response['response']['message']) . '</span>'; | |
| 281 | 250 | } |
| 282 | 251 | } |
| 283 | 252 | else { |
| 284 | - echo '<span class="found-id-text">'.esc_html__('No response from server!', 'photonic').'</span>'; | |
| 253 | + echo '<span class="found-id-text">' . esc_html__('No response from server!', 'photonic') . '</span>'; | |
| 285 | 254 | } |
| 286 | 255 | } |
| 287 | 256 | else { |
| 288 | - echo $this->get_wp_errors($response); | |
| 257 | + $this->get_wp_errors($response); | |
| 289 | 258 | } |
| 290 | 259 | } |
| 291 | 260 | |
| 292 | - function execute_flickr_query($body, $method) { | |
| 261 | + private function execute_flickr_query($body, $method) { | |
| 293 | 262 | $body = json_decode($body); |
| 294 | - if (isset($body->stat) && $body->stat == 'fail') { | |
| 295 | - echo '<span class="found-id-text">'.$body->message.'</span>'; | |
| 263 | + if (isset($body->stat) && 'fail' === $body->stat) { | |
| 264 | + echo '<span class="found-id-text">' . esc_html($body->message) . '</span>'; | |
| 296 | 265 | } |
| 297 | 266 | else { |
| 298 | - if ($method == 'flickr.urls.lookupUser') { | |
| 267 | + if ('flickr.urls.lookupUser' === $method) { | |
| 299 | 268 | if (isset($body->user)) { |
| 300 | - echo '<span class="found-id-text">'.esc_html__('User ID:', 'photonic').'</span> <span class="found-id"><code>'.$body->user->id.'</code></span>'; | |
| 269 | + echo '<span class="found-id-text">' . esc_html__('User ID:', 'photonic') . '</span> <span class="found-id"><code>' . esc_html($body->user->id) . '</code></span>'; | |
| 301 | 270 | } |
| 302 | 271 | } |
| 303 | - else if ($method == 'flickr.urls.lookupGroup') { | |
| 272 | + elseif ('flickr.urls.lookupGroup' === $method) { | |
| 304 | 273 | if (isset($body->group)) { |
| 305 | - echo '<span class="found-id-text">'.esc_html__('Group ID:', 'photonic').'</span> <span class="found-id"><code>'.$body->group->id.'</code></span>'; | |
| 274 | + echo '<span class="found-id-text">' . esc_html__('Group ID:', 'photonic') . '</span> <span class="found-id"><code>' . esc_html($body->group->id) . '</code></span>'; | |
| 306 | 275 | } |
| 307 | 276 | } |
| 308 | 277 | } |
| 309 | 278 | } |
| 310 | 279 | |
| 311 | - function process_smugmug_response($response) { | |
| 280 | + private function process_smugmug_response($response) { | |
| 312 | 281 | $body = $response['body']; |
| 313 | 282 | $body = json_decode($body); |
| 314 | 283 | |
| 315 | - if ($body->Code === 200) { | |
| 284 | + if (200 === $body->Code) { | |
| 316 | 285 | $body = $body->Response; |
| 317 | 286 | if (isset($body->Node)) { |
| 318 | 287 | $node = $body->Node; |
| 319 | - if ($node->Type == 'Folder') { | |
| 288 | + if ('Folder' === $node->Type) { | |
| 320 | 289 | $ret = $this->process_smugmug_node($node); |
| 321 | 290 | if (!empty($ret)) { |
| 322 | - $ret = "<table class='photonic-helper-table'>\n". | |
| 323 | - "\t<tr>\n". | |
| 324 | - "\t<th>Name</th>\n". | |
| 325 | - "\t<th>Type</th>\n". | |
| 326 | - "\t<th>Thumbnail</th>\n". | |
| 327 | - "\t<th>Album Key</th>\n". | |
| 328 | - "\t<th>Security Level</th>\n". | |
| 329 | - "\t</tr>\n". | |
| 330 | - $ret. | |
| 291 | + $ret = "<table class='photonic-helper-table'>\n" . | |
| 292 | + "\t<tr>\n" . | |
| 293 | + "\t<th>Name</th>\n" . | |
| 294 | + "\t<th>Type</th>\n" . | |
| 295 | + "\t<th>Thumbnail</th>\n" . | |
| 296 | + "\t<th>Album Key</th>\n" . | |
| 297 | + "\t<th>Security Level</th>\n" . | |
| 298 | + "\t</tr>\n" . | |
| 299 | + $ret . | |
| 331 | 300 | "</table>\n"; |
| 332 | - echo $ret; | |
| 301 | + echo wp_kses_post($ret); | |
| 333 | 302 | } |
| 334 | 303 | } |
| 335 | 304 | } |
| 336 | 305 | } |
| @@ -335,20 +304,20 @@ | ||
| 335 | 304 | } |
| 336 | 305 | } |
| 337 | 306 | } |
| 338 | 307 | |
| 339 | - function process_smugmug_node($node) { | |
| 308 | + private function process_smugmug_node($node): string { | |
| 340 | 309 | $ret = ''; |
| 341 | - if ($node->Type == 'Folder') { | |
| 310 | + if ('Folder' === $node->Type) { | |
| 342 | 311 | $albums = []; |
| 343 | 312 | $folders = []; |
| 344 | 313 | if (isset($node->Uris->ChildNodes->Node)) { |
| 345 | 314 | $child_nodes = $node->Uris->ChildNodes->Node; |
| 346 | 315 | foreach ($child_nodes as $child) { |
| 347 | - if ($child->Type == 'Album') { | |
| 316 | + if ('Album' === $child->Type) { | |
| 348 | 317 | $albums[] = $child; |
| 349 | 318 | } |
| 350 | - else if ($child->Type == 'Folder') { | |
| 319 | + elseif ('Folder' === $child->Type) { | |
| 351 | 320 | $folders[] = $child; |
| 352 | 321 | } |
| 353 | 322 | } |
| 354 | 323 | |
| @@ -355,10 +324,10 @@ | ||
| 355 | 324 | foreach ($albums as $album) { |
| 356 | 325 | $ret .= "\t<tr>\n"; |
| 357 | 326 | $ret .= "\t\t<td>{$album->Name}</td>\n"; |
| 358 | 327 | $ret .= "\t\t<td>Album</td>\n"; |
| 359 | - $thumb = isset($album->Uris->NodeCoverImage->Image->ThumbnailUrl) ? $album->Uris->NodeCoverImage->Image->ThumbnailUrl : ''; | |
| 360 | - $ret .= "\t\t<td>".(empty($thumb) ? '' : "<img src='$thumb' alt='Album thumbnail'/>")."</td>\n"; | |
| 328 | + $thumb = $album->Uris->NodeCoverImage->Image->ThumbnailUrl ?? ''; | |
| 329 | + $ret .= "\t\t<td>" . (empty($thumb) ? '' : "<img src='$thumb' alt='Album thumbnail'/>") . "</td>\n"; | |
| 361 | 330 | $album_key = isset($album->Uris->Album) ? $album->Uris->Album->Uri : ''; |
| 362 | 331 | $album_key = explode('/', $album_key); |
| 363 | 332 | $album_key = $album_key[count($album_key) - 1]; |
| 364 | 333 | $ret .= "\t\t<td>$album_key</td>\n"; |
| @@ -369,10 +338,10 @@ | ||
| 369 | 338 | foreach ($folders as $folder) { |
| 370 | 339 | $ret .= "\t<tr>\n"; |
| 371 | 340 | $ret .= "\t\t<td>{$folder->Name}</td>\n"; |
| 372 | 341 | $ret .= "\t\t<td>Folder</td>\n"; |
| 373 | - $thumb = isset($folder->Uris->NodeCoverImage->Image->ThumbnailUrl) ? $folder->Uris->NodeCoverImage->Image->ThumbnailUrl : ''; | |
| 374 | - $ret .= "\t\t<td>".(empty($thumb) ? '' : "<img src='$thumb' alt='Folder thumbnail'/>")."</td>\n"; | |
| 342 | + $thumb = $folder->Uris->NodeCoverImage->Image->ThumbnailUrl ?? ''; | |
| 343 | + $ret .= "\t\t<td>" . (empty($thumb) ? '' : "<img src='$thumb' alt='Folder thumbnail'/>") . "</td>\n"; | |
| 375 | 344 | $ret .= "\t\t<td>{$folder->NodeID}</td>\n"; |
| 376 | 345 | $ret .= "\t\t<td>{$folder->SecurityType}</td>\n"; |
| 377 | 346 | $ret .= "\t</tr>\n"; |
| 378 | 347 | |
| @@ -382,9 +351,9 @@ | ||
| 382 | 351 | } |
| 383 | 352 | return $ret; |
| 384 | 353 | } |
| 385 | 354 | |
| 386 | - function process_google_response($response, $more = false) { | |
| 355 | + private function process_google_response($response, $more = false) { | |
| 387 | 356 | $response = json_decode($response); |
| 388 | 357 | if (!empty($response->albums) && is_array($response->albums)) { |
| 389 | 358 | $albums = $response->albums; |
| 390 | 359 | if (!$more) { |
| @@ -398,12 +367,12 @@ | ||
| 398 | 367 | } |
| 399 | 368 | |
| 400 | 369 | foreach ($albums as $album) { |
| 401 | 370 | echo "\t<tr>\n"; |
| 402 | - echo "\t\t<td>".(empty($album->title)? '' : esc_attr($album->title))."</td>\n"; | |
| 403 | - echo "\t\t<td><img src='{$album->coverPhotoBaseUrl}=w75-h75-c' alt='Album thumbnail'/></td>\n"; | |
| 404 | - echo "\t\t<td>{$album->id}</td>\n"; | |
| 405 | - echo "\t\t<td>{$album->mediaItemsCount}</td>\n"; | |
| 371 | + echo "\t\t<td>" . (empty($album->title) ? '' : esc_html($album->title)) . "</td>\n"; | |
| 372 | + echo "\t\t<td><img src='" . esc_attr($album->coverPhotoBaseUrl . '=w75-h75-c') . "' alt='Album thumbnail'/></td>\n"; | |
| 373 | + echo "\t\t<td>" . esc_html($album->id) . "</td>\n"; | |
| 374 | + echo "\t\t<td>" . esc_html($album->mediaItemsCount) . "</td>\n"; | |
| 406 | 375 | echo "\t</tr>\n"; |
| 407 | 376 | } |
| 408 | 377 | |
| 409 | 378 | if (!empty($response->nextPageToken)) { |
| @@ -408,9 +377,9 @@ | ||
| 408 | 377 | |
| 409 | 378 | if (!empty($response->nextPageToken)) { |
| 410 | 379 | echo "\t<tr>\n"; |
| 411 | 380 | echo "\t\t<td colspan='4'>\n"; |
| 412 | - echo '<input type="button" value="'.esc_attr__('Load More', 'photonic').'" id="photonic-google-album-more" class="button button-primary" data-photonic-token="'.$response->nextPageToken.'"/>'; | |
| 381 | + echo '<input type="button" value="' . esc_attr__('Load More', 'photonic') . '" id="photonic-google-album-more" class="button button-primary" data-photonic-token="' . esc_attr($response->nextPageToken) . '"/>'; | |
| 413 | 382 | echo "\t\t</td>\n"; |
| 414 | 383 | echo "\t</tr>\n"; |
| 415 | 384 | } |
| 416 | 385 | |
| @@ -422,16 +391,16 @@ | ||
| 422 | 391 | esc_html_e("No albums found", 'photonic'); |
| 423 | 392 | } |
| 424 | 393 | } |
| 425 | 394 | |
| 426 | - function execute_zenfolio_query($body, $method) { | |
| 427 | - if ($method == 'GetCategories') { | |
| 395 | + private function execute_zenfolio_query($body, $method) { | |
| 396 | + if ('GetCategories' === $method) { | |
| 428 | 397 | $response = simplexml_load_string($body); |
| 429 | 398 | if (!empty($response->Category)) { |
| 430 | 399 | $categories = $response->Category; |
| 431 | 400 | echo "<ul class='photonic-scroll-panel'>\n"; |
| 432 | 401 | foreach ($categories as $category) { |
| 433 | - echo "<li>{$category->DisplayName} – {$category->Code}</li>\n"; | |
| 402 | + echo "<li>" . esc_html($category->DisplayName . ' – ' . $category->Code) . "</li>\n"; | |
| 434 | 403 | } |
| 435 | 404 | echo "</ul>\n"; |
| 436 | 405 | } |
| 437 | 406 | } |
| @@ -438,19 +407,16 @@ | ||
| 438 | 407 | } |
| 439 | 408 | |
| 440 | 409 | /** |
| 441 | 410 | * @param $response WP_Error |
| 442 | - * @return string | |
| 411 | + * @return void | |
| 443 | 412 | */ |
| 444 | 413 | private function get_wp_errors($response) { |
| 445 | - $err = ''; | |
| 446 | 414 | if (is_wp_error($response)) { |
| 447 | 415 | $messages = $response->get_error_messages(); |
| 448 | - $err = '<br/><strong>'.esc_html(sprintf(_n('%s Message:', '%s Messages:', count($messages), 'photonic'), | |
| 449 | - count($messages)))."</strong><br/>\n"; | |
| 416 | + echo '<br/><strong>' . esc_html(sprintf(_n('%s Message:', '%s Messages:', count($messages), 'photonic'), count($messages))) . "</strong><br/>\n"; | |
| 450 | 417 | foreach ($messages as $message) { |
| 451 | - $err .= $message . "<br>\n"; | |
| 418 | + echo wp_kses_post($message) . "<br>\n"; | |
| 452 | 419 | } |
| 453 | 420 | } |
| 454 | - return $err; | |
| 455 | 421 | } |
| 456 | 422 | } |