Flickr
display_flickr_id_helper(); ?>
display_flickr_group_helper(); ?>
Google Photos
display_google_photos_album_helper(); ?>
SmugMug
display_smugmug_album_id_helper(); ?>
Zenfolio
display_zenfolio_category_helper(); ?>
Photonic → Settings → Flickr → Flickr Settings'); } else { echo ''; echo ''; echo '
 
'; } } function display_flickr_group_helper() { global $photonic_flickr_api_key; if (empty($photonic_flickr_api_key)) { echo sprintf(esc_html__('Please set up your Flickr API Key under %s', 'photonic'), 'Photonic → Settings → Flickr → Flickr Settings'); } else { echo ''; echo ''; echo '
 
'; } } function display_google_photos_album_helper() { global $photonic_google_client_id, $photonic_google_client_secret, $photonic_google_refresh_token; //global $photonic_google_use_own_keys; // if (!empty($photonic_google_use_own_keys) && (empty($photonic_google_client_id) || empty($photonic_google_client_secret))) { if (empty($photonic_google_client_id) || empty($photonic_google_client_secret)) { echo sprintf(esc_html__('Please set up your Google Client ID and Client Secret under %s', 'photonic'), 'Photonic → Settings → Google Photos → Google Photos Settings'); } else if (empty($photonic_google_refresh_token)) { echo sprintf(esc_html__('Please obtain your Refresh Token and save it under %s', 'photonic'), 'Photonic → Settings → Google Photos → Google Photos Settings'); } else { echo esc_html__("Clicking on the button below will show all albums for the authenticated user.", 'photonic').'
'; echo ''; echo '
 
'; } } function display_smugmug_album_id_helper() { global $photonic_smug_api_key; if (empty($photonic_smug_api_key)) { echo sprintf(esc_html__('Please set up your SmugMug API Key under %s', 'photonic'), 'Photonic → Settings → SmugMug → SmugMug Settings'); } else { echo ''; echo ''; echo '
 
'; } } function display_zenfolio_category_helper() { echo esc_html__('Click "List" to find all available Zenfolio categories.', 'photonic').'
'; echo ''; echo '
 
'; } function invoke_helper() { if (isset($_POST['helper']) && !empty($_POST['helper'])) { $helper = sanitize_text_field($_POST['helper']); $photonic_options = get_option('photonic_options'); switch ($helper) { case 'photonic-flickr-user-find': $flickr_api_key = $photonic_options['flickr_api_key']; $user = isset($_POST['photonic-flickr-user']) ? sanitize_text_field($_POST['photonic-flickr-user']) : ''; $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key='.$flickr_api_key.'&method=flickr.urls.lookupUser&url='.$user; $this->execute_query('flickr', $url, 'flickr.urls.lookupUser'); break; case 'photonic-flickr-group-find': $flickr_api_key = $photonic_options['flickr_api_key']; $group = isset($_POST['photonic-flickr-group']) ? sanitize_text_field($_POST['photonic-flickr-group']) : ''; $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key='.$flickr_api_key.'&method=flickr.urls.lookupGroup&url='.$group; $this->execute_query('flickr', $url, 'flickr.urls.lookupGroup'); break; case 'photonic-smugmug-user-tree': $smugmug_api_key = $photonic_options['smug_api_key']; $user = isset($_POST['photonic-smugmug-user']) ? sanitize_text_field($_POST['photonic-smugmug-user']) : ''; if (!empty($user)) { require_once(PHOTONIC_PATH.'/Modules/SmugMug.php'); $module = SmugMug::get_instance(); $config = $module->get_config_object(100); $config['expand']['Node'] = []; //$api_call = 'https://api.smugmug.com/api/v2/user/' . $user . '?_expand=Node.ChildNodes.ChildNodes.ChildNodes.ChildNodes.ChildNodes'; $api_call = 'https://api.smugmug.com/api/v2/user/' . $user; $args = [ 'APIKey' => $smugmug_api_key, '_accept' => 'application/json', '_verbosity' => 1, '_expandmethod' => 'inline', 'count' => 20 ]; $response = Photonic::http($api_call, 'GET', $args); if (!is_wp_error($response)) { $body = $response['body']; $body = json_decode($body); if ($body->Code === 200) { $body = $body->Response; if (isset($body->User) && isset($body->User->Uris) && isset($body->User->Uris->Node)) { $node = $body->User->Uris->Node->Uri; $node = explode('/', $node); $node = array_pop($node); $api_call = 'https://api.smugmug.com/api/v2/node/' . $node . '?_config='.json_encode($config); if ($module->oauth_done) { $args = $module->sign_call($api_call, 'GET', $args); } else { echo sprintf(esc_html__("If you have protected albums, you will have to %1sauthenticate%2s to see the protected albums.", 'photonic'), "", ""); } $response = Photonic::http($api_call, 'GET', $args); if (!is_wp_error($response)) { $this->process_smugmug_response($response); } else { echo $this->get_wp_errors($response); } } } } else { echo $this->get_wp_errors($response); } } break; case 'photonic-google-album-find': case 'photonic-google-album-more': $url = 'https://photoslibrary.googleapis.com/v1/albums'; global $photonic_google_refresh_token; require_once(PHOTONIC_PATH.'/Modules/Google_Photos.php'); $module = Google_Photos::get_instance(); $module->authenticate($photonic_google_refresh_token); if (!empty($module->access_token)) { $query_args = [ 'access_token' => $module->access_token, 'pageSize' => 50, ]; if (!empty($_POST['nextPageToken'])) { $query_args['pageToken'] = $_POST['nextPageToken']; } $url = add_query_arg( $query_args, $url); } $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); if (!is_wp_error($response) && $response['response']['code'] == 200) { $response = $response['body']; $this->process_google_response($response, !empty($_POST['nextPageToken'])); } else { echo esc_html__("Encountered error: ")."
"; echo $this->get_wp_errors($response); } break; case 'photonic-zenfolio-categories-find': $url = 'https://api.zenfolio.com/api/1.8/zfapi.asmx/GetCategories'; $this->execute_query('zenfolio', $url, 'GetCategories'); break; } } die(); } function execute_query($where, $url, $method) { $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]); if (!is_wp_error($response)) { if (isset($response['response']) && isset($response['response']['code'])) { if ($response['response']['code'] == 200) { if (isset($response['body'])) { if ($where == 'flickr') { $this->execute_flickr_query($response['body'], $method); } else if ($where == 'zenfolio') { $this->execute_zenfolio_query($response['body'], $method); } } else { echo ''.esc_html__('No response from server!', 'photonic').''; } } else { echo ''.$response['response']['message'].''; } } else { echo ''.esc_html__('No response from server!', 'photonic').''; } } else { echo $this->get_wp_errors($response); } } function execute_flickr_query($body, $method) { $body = json_decode($body); if (isset($body->stat) && $body->stat == 'fail') { echo ''.$body->message.''; } else { if ($method == 'flickr.urls.lookupUser') { if (isset($body->user)) { echo ''.esc_html__('User ID:', 'photonic').' '.$body->user->id.''; } } else if ($method == 'flickr.urls.lookupGroup') { if (isset($body->group)) { echo ''.esc_html__('Group ID:', 'photonic').' '.$body->group->id.''; } } } } function process_smugmug_response($response) { $body = $response['body']; $body = json_decode($body); if ($body->Code === 200) { $body = $body->Response; if (isset($body->Node)) { $node = $body->Node; if ($node->Type == 'Folder') { $ret = $this->process_smugmug_node($node); if (!empty($ret)) { $ret = "\n". "\t\n". "\t\n". "\t\n". "\t\n". "\t\n". "\t\n". "\t\n". $ret. "
NameTypeThumbnailAlbum KeySecurity Level
\n"; echo $ret; } } } } } function process_smugmug_node($node) { $ret = ''; if ($node->Type == 'Folder') { $albums = []; $folders = []; if (isset($node->Uris->ChildNodes->Node)) { $child_nodes = $node->Uris->ChildNodes->Node; foreach ($child_nodes as $child) { if ($child->Type == 'Album') { $albums[] = $child; } else if ($child->Type == 'Folder') { $folders[] = $child; } } foreach ($albums as $album) { $ret .= "\t\n"; $ret .= "\t\t{$album->Name}\n"; $ret .= "\t\tAlbum\n"; $thumb = isset($album->Uris->NodeCoverImage->Image->ThumbnailUrl) ? $album->Uris->NodeCoverImage->Image->ThumbnailUrl : ''; $ret .= "\t\t".(empty($thumb) ? '' : "Album thumbnail")."\n"; $album_key = isset($album->Uris->Album) ? $album->Uris->Album->Uri : ''; $album_key = explode('/', $album_key); $album_key = $album_key[count($album_key) - 1]; $ret .= "\t\t$album_key\n"; $ret .= "\t\t{$album->SecurityType}\n"; $ret .= "\t\n"; } foreach ($folders as $folder) { $ret .= "\t\n"; $ret .= "\t\t{$folder->Name}\n"; $ret .= "\t\tFolder\n"; $thumb = isset($folder->Uris->NodeCoverImage->Image->ThumbnailUrl) ? $folder->Uris->NodeCoverImage->Image->ThumbnailUrl : ''; $ret .= "\t\t".(empty($thumb) ? '' : "Folder thumbnail")."\n"; $ret .= "\t\t{$folder->NodeID}\n"; $ret .= "\t\t{$folder->SecurityType}\n"; $ret .= "\t\n"; $ret .= $this->process_smugmug_node($folder); } } } return $ret; } function process_google_response($response, $more = false) { $response = json_decode($response); if (!empty($response->albums) && is_array($response->albums)) { $albums = $response->albums; if (!$more) { echo "\n"; echo "\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\n"; } foreach ($albums as $album) { echo "\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\n"; } if (!empty($response->nextPageToken)) { echo "\t\n"; echo "\t\t\n"; echo "\t\n"; } if (!$more) { echo "
Album TitleThumbnailAlbum IDMedia Count
".(empty($album->title)? '' : esc_attr($album->title))."Album thumbnail{$album->id}{$album->mediaItemsCount}
\n"; echo ''; echo "\t\t
\n"; } } else { esc_html_e("No albums found", 'photonic'); } } function execute_zenfolio_query($body, $method) { if ($method == 'GetCategories') { $response = simplexml_load_string($body); if (!empty($response->Category)) { $categories = $response->Category; echo "\n"; } } } /** * @param $response WP_Error * @return string */ private function get_wp_errors($response) { $err = ''; if (is_wp_error($response)) { $messages = $response->get_error_messages(); $err = '
'.esc_html(sprintf(_n('%s Message:', '%s Messages:', count($messages), 'photonic'), count($messages)))."
\n"; foreach ($messages as $message) { $err .= $message . "
\n"; } } return $err; } }