';
}
}
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
Name
\n".
"\t
Type
\n".
"\t
Thumbnail
\n".
"\t
Album Key
\n".
"\t
Security Level
\n".
"\t
\n".
$ret.
"
\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