Photonic → Settings → Flickr → Flickr Settings');
}
else {
echo '' . esc_html__('Enter your Flickr photostream URL and click "Find"', 'photonic');
echo ' ';
echo ' ';
echo ' ';
echo '
';
}
}
private 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 '' . esc_html__('Enter your Flickr group URL and click "Find"', 'photonic');
echo ' ';
echo ' ';
echo ' ';
echo '
';
}
}
private 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 ');
}
elseif (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 '
';
}
}
private 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 '' . esc_html__('Enter your SmugMug username and click "Find"', 'photonic');
echo ' ';
echo ' ';
echo ' ';
echo '
';
}
}
private function display_zenfolio_category_helper() {
echo esc_html__('Click "List" to find all available Zenfolio categories.', 'photonic') . ' ';
echo ' ';
echo '
';
}
public function invoke_helper() {
if (current_user_can('edit_posts') && check_admin_referer('photonic-helper-' . get_current_user_id(), 'photonic_helper_nonce')) {
if (!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 = 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 = 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 = sanitize_text_field($_POST['photonic-smugmug-user'] ?? '');
if (!empty($user)) {
require_once PHOTONIC_PATH . '/Platforms/SmugMug.php';
$module = SmugMug::get_instance();
global $photonic_smug_nesting_levels;
$config = $module->get_config_object(100, $photonic_smug_nesting_levels);
$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 (200 === $body->Code) {
$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=' . wp_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 %1$sauthenticate%2$s to see the protected albums.', 'photonic'), "", " ");
}
$response = Photonic::http($api_call, 'GET', $args);
if (!is_wp_error($response)) {
$this->process_smugmug_response($response);
}
else {
$this->get_wp_errors($response);
}
}
}
}
else {
$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();
}
private function execute_query($where, $url, $method) {
$response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
if (!is_wp_error($response)) {
if (isset($response['response']['code'])) {
if (200 === $response['response']['code']) {
if (isset($response['body'])) {
if ('flickr' === $where) {
$this->execute_flickr_query($response['body'], $method);
}
elseif ('zenfolio' === $where) {
$this->execute_zenfolio_query($response['body'], $method);
}
}
else {
echo '' . esc_html__('No response from server!', 'photonic') . ' ';
}
}
else {
echo '' . esc_html($response['response']['message']) . ' ';
}
}
else {
echo '' . esc_html__('No response from server!', 'photonic') . ' ';
}
}
else {
$this->get_wp_errors($response);
}
}
private function execute_flickr_query($body, $method) {
$body = json_decode($body);
if (isset($body->stat) && 'fail' === $body->stat) {
echo '' . esc_html($body->message) . ' ';
}
else {
if ('flickr.urls.lookupUser' === $method) {
if (isset($body->user)) {
echo '' . esc_html__('User ID:', 'photonic') . ' ' . esc_html($body->user->id) . ' ';
}
}
elseif ('flickr.urls.lookupGroup' === $method) {
if (isset($body->group)) {
echo '' . esc_html__('Group ID:', 'photonic') . ' ' . esc_html($body->group->id) . ' ';
}
}
}
}
private function process_smugmug_response($response) {
$body = $response['body'];
$body = json_decode($body);
if (200 === $body->Code) {
$body = $body->Response;
if (isset($body->Node)) {
$node = $body->Node;
if ('Folder' === $node->Type) {
$ret = $this->process_smugmug_node($node);
if (!empty($ret)) {
$ret = "\n" .
"\t\n" .
"\tName \n" .
"\tType \n" .
"\tThumbnail \n" .
"\tAlbum Key \n" .
"\tSecurity Level \n" .
"\t \n" .
$ret .
"
\n";
echo wp_kses_post($ret);
}
}
}
}
}
private function process_smugmug_node($node): string {
$ret = '';
if ('Folder' === $node->Type) {
$albums = [];
$folders = [];
if (isset($node->Uris->ChildNodes->Node)) {
$child_nodes = $node->Uris->ChildNodes->Node;
foreach ($child_nodes as $child) {
if ('Album' === $child->Type) {
$albums[] = $child;
}
elseif ('Folder' === $child->Type) {
$folders[] = $child;
}
}
foreach ($albums as $album) {
$ret .= "\t\n";
$ret .= "\t\t{$album->Name} \n";
$ret .= "\t\tAlbum \n";
$thumb = $album->Uris->NodeCoverImage->Image->ThumbnailUrl ?? '';
$ret .= "\t\t" . (empty($thumb) ? '' : " ") . " \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 = $folder->Uris->NodeCoverImage->Image->ThumbnailUrl ?? '';
$ret .= "\t\t" . (empty($thumb) ? '' : " ") . " \n";
$ret .= "\t\t{$folder->NodeID} \n";
$ret .= "\t\t{$folder->SecurityType} \n";
$ret .= "\t \n";
$ret .= $this->process_smugmug_node($folder);
}
}
}
return $ret;
}
private 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";
}
}
else {
esc_html_e("No albums found", 'photonic');
}
}
private function execute_zenfolio_query($body, $method) {
if ('GetCategories' === $method) {
$response = simplexml_load_string($body);
if (!empty($response->Category)) {
$categories = $response->Category;
echo "\n";
}
}
}
/**
* @param $response WP_Error
* @return void
*/
private function get_wp_errors($response) {
if (is_wp_error($response)) {
$messages = $response->get_error_messages();
echo '' . esc_html(sprintf(_n('%s Message:', '%s Messages:', count($messages), 'photonic'), count($messages))) . " \n";
foreach ($messages as $message) {
echo wp_kses_post($message) . " \n";
}
}
}
}