Flickr

display_flickr(); ?>

SmugMug

display_smugmug();?>

Google Photos

display_google(); ?> display_google_bundled_token_getter(); */?>

Instagram

display_instagram(); ?>

Zenfolio

display_zenfolio(); ?>
trim($photonic_flickr_api_key), 'api_secret' => trim($photonic_flickr_api_secret), 'token' => trim($photonic_flickr_access_token), ]; $this->show_token_section($auth, 'flickr', 'Flickr'); } function display_smugmug() { global $photonic_smug_api_key, $photonic_smug_api_secret, $photonic_smug_access_token; $auth = [ 'api_key' => !empty($photonic_smug_api_key) ? trim($photonic_smug_api_key) : '86MZ8N8TqJf5x2fQ4FRWXRtJ3C6Jm7XV', 'api_secret' => trim($photonic_smug_api_secret), 'token' => trim($photonic_smug_access_token), ]; $this->show_token_section($auth, 'smug', 'SmugMug'); } function display_google() { global $photonic_google_client_id, $photonic_google_client_secret, $photonic_google_refresh_token; echo "
\n"; 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 { $parameters = Core::parse_parameters($_SERVER['QUERY_STRING']); if (!empty($photonic_google_refresh_token)) { $this->print_auth_done_all_good(); } echo "
\n"; echo "
\n"; esc_html_e("You first have to authorize Photonic to connect to your Google account.", 'photonic'); echo "
\n"; if (!isset($parameters['code']) || !isset($parameters['source']) || $parameters['source'] != 'google') { $url = add_query_arg('test', 'test'); $url = remove_query_arg('test', $url); $parameters = [ 'response_type' => 'code', 'redirect_uri' => admin_url('admin.php?page=photonic-auth&source=google'), 'client_id' => $photonic_google_client_id, 'scope' => 'https://www.googleapis.com/auth/photoslibrary.readonly', 'access_type' => 'offline', 'state' => md5($photonic_google_client_secret.'google').'::'.urlencode($url), 'prompt' => 'consent', ]; $url = 'https://accounts.google.com/o/oauth2/auth?'.Authenticator::build_query($parameters); echo "".esc_html__('Step 1: Authenticate', 'photonic').""; // echo " admin_url('admin.php?page=photonic-auth&source=google'), 'prompt' => 'consent'])."' class='button button-primary'>". // esc_html__('Step 1: Authenticate', 'photonic').""; echo "
\n"; echo "
\n"; echo esc_html__("Next, you have to obtain the token.", 'photonic').'
'; echo "". esc_html__('Step 2: Obtain Token', 'photonic').""; } else { echo "". esc_html__('Step 1: Authenticate', 'photonic').""; echo "
\n"; echo "
\n"; echo esc_html__("Next, you have to obtain the token.", 'photonic').'
'; echo "". esc_html__('Step 2: Obtain Token', 'photonic').""; echo ''; echo ''; } } echo "
\n"; echo '
 
'; echo sprintf(esc_html__('If you are facing issues with the authentication please follow the workaround %1$shere%2$s', 'photonic'), '', ''); } function display_google_bundled() { global $photonic_google_refresh_token; echo "
\n"; require_once(PHOTONIC_PATH."/Modules/Google_Photos.php"); $module = Google_Photos::get_instance(); $parameters = Core::parse_parameters($_SERVER['QUERY_STRING']); if (!empty($photonic_google_refresh_token) && $module->refresh_token_valid) { $this->print_auth_done_all_good(); } echo "
\n"; echo "
\n"; esc_html_e("You first have to authorize Photonic to connect to your Google account.", 'photonic'); echo "
\n"; if (!isset($parameters['code']) || !isset($parameters['source']) || $parameters['source'] != 'google') { echo " 'https://aquoid.com/photonic-router/google.php', 'state' => admin_url('admin.php?page=photonic-auth&source=google'), 'prompt' => 'consent', ])."' class='button button-primary'>". esc_html__('Step 1: Authenticate', 'photonic').""; echo "
\n"; echo "
\n"; echo esc_html__("Next, you have to obtain the token.", 'photonic').'
'; echo "". esc_html__('Step 2: Obtain Token', 'photonic').""; } else { echo "". esc_html__('Step 1: Authenticate', 'photonic').""; echo "
\n"; echo "
\n"; echo esc_html__("Next, you have to obtain the token.", 'photonic').'
'; echo "". esc_html__('Step 2: Obtain Token', 'photonic').""; echo ''; } echo "
\n"; echo '
 
'; echo "
\n"; echo esc_html__("If the above method is not working due to conflicts with your site's security setup try an alternative method where the authentication happens on a different site.", 'photonic').'
'; echo " 'https://aquoid.com/photonic-router/google.php', 'prompt' => 'consent', 'state' => '', ])."' class='button button-primary' target='_blank'>". esc_html__("Authenticate using Photonic's website", 'photonic').""; echo "
\n"; } function display_instagram() { global $photonic_instagram_access_token; $auth = [ 'api_key' => 'not-required-but-not-empty', 'api_secret' => 'not-required-but-not-empty', 'token' => trim($photonic_instagram_access_token), ]; $this->show_token_section_header($auth, 'Instagram'); $response = Core::parse_parameters($_SERVER['QUERY_STRING']); if (empty($response['access_token'])) { echo "" . $this->get_login_button('Instagram'). ""; } else if (!empty($response['access_token'])) { echo "" . $this->get_login_button('Instagram') . ""; echo '
'. (!empty($response['access_token']) ? 'Access token: '.$response['access_token'].'
' : ' '). (!empty($response['expires_in']) ? '' : ''). (!empty($response['user_id']) ? '' : ''). (!empty($response['user']) ? 'User name: '.$response['user'].'
' : ''). '
'; echo "" . esc_html__('Save Token', 'photonic') . ""; } } function display_zenfolio() { global $photonic_zenfolio_default_user; $gallery = Zenfolio::get_instance(); echo "
\n"; if (empty($photonic_zenfolio_default_user)) { echo sprintf(esc_html__('Please set up the default user for Zenfolio under %s', 'photonic'), 'Photonic → Settings → Zenfolio → Zenfolio Photo Settings → Default User')."\n"; } else if (!empty($gallery->token)) { $this->print_auth_done_all_good(); } echo "
\n"; $response = Core::parse_parameters($_SERVER['QUERY_STRING']); if (!empty($photonic_zenfolio_default_user) && (empty($response['provider']) || 'zenfolio' !== $response['provider'])) { echo ""; } echo "
\n"; if (!empty($photonic_zenfolio_default_user) && (empty($response['provider']) || 'zenfolio' !== $response['provider'])) { echo "" . esc_html__('Login and Authenticate', 'photonic') . ""; } if (!empty($gallery->token)) { echo "".esc_html__('Delete current Zenfolio authentication data', 'photonic').""; } echo "
\n"; echo '
 
'; } private function show_token_section($auth, $provider_slug, $provider_text) { $this->show_token_section_header($auth, $provider_text); if (!empty($auth['api_key']) && !empty($auth['api_secret'])) { $this->show_token_section_body($provider_slug, $provider_text); } else { echo '
 
'; } } /** * @param $auth array * @param $provider string */ private function show_token_section_header($auth, $provider) { echo "
\n"; if (empty($auth['api_key']) || empty($auth['api_secret'])) { echo sprintf(esc_html__('Please set up your %1$s API key under %2$s.', 'photonic'), $provider, sprintf('Photonic → Settings → %1$s → %1$s Settings', $provider)); } else if ($provider == 'Instagram' && !empty($auth['token'])) { require_once(PHOTONIC_PATH."/Modules/Instagram.php"); $module = Instagram::get_instance(); $expiring_soon = $module->is_token_expiring_soon(30); if (is_null($expiring_soon)) { // Not yet authenticated with the new API. echo '

'.esc_html__('Your authentication credentials are for the old Instagram API. Please reauthenticate to keep Photonic working.', 'photonic').'


'; } else if ($expiring_soon === 1) { echo '

'.esc_html__('Your authentication credentials are expiring soon. Please reauthenticate to keep Photonic working.', 'photonic').'


'; } else if ($expiring_soon === -1) { echo '

'.esc_html__('Your authentication credentials have expired! Please reauthenticate to keep Photonic working.', 'photonic').'


'; } else { $cached_token = $module->get_cached_token(); if (!empty($cached_token) && !empty($cached_token['user'])) { $this->print_auth_done_all_good(sprintf(esc_html__('You are logged in as %1$s.', 'photonic'), ''.$cached_token['user'].'')); } else { $this->print_auth_done_all_good(); } } } else if (!empty($auth['token'])) { $this->print_auth_done_all_good(); } echo "
\n"; } /** * @param $provider * @param $provider_text */ public function show_token_section_body($provider, $provider_text) { $photonic_authentication = get_option('photonic_authentication'); $response = Core::parse_parameters($_SERVER['QUERY_STRING']); if (empty($response['provider']) || (!empty($response['provider']) && $provider !== $response['provider'])) { echo "" . $this->get_login_button($provider_text) . ""; } else if (!empty($response['oauth_token']) && !empty($response['oauth_verifier'])) { if (in_array($provider, ['flickr', 'smug', 'smugmug'])) { if ($provider == 'flickr') { require_once(PHOTONIC_PATH."/Modules/Flickr.php"); $module = Flickr::get_instance(); } else { require_once(PHOTONIC_PATH."/Modules/SmugMug.php"); $module = SmugMug::get_instance(); } echo "" . $this->get_login_button($provider_text) . ""; $authorization = ['oauth_token' => $response['oauth_token'], 'oauth_verifier' => $response['oauth_verifier']]; if (isset($photonic_authentication) && isset($photonic_authentication[$provider]) && isset($photonic_authentication[$provider]['oauth_token_secret'])) { $authorization['oauth_token_secret'] = $photonic_authentication[$provider]['oauth_token_secret']; } $access_token = $module->get_access_token($authorization); if (isset($access_token['oauth_token'])) { echo '
Access Token: ' . $access_token['oauth_token'] . '
Access Token Secret: ' . $access_token['oauth_token_secret'] . '
'."\n"; echo "" . esc_html__('Save Token', 'photonic') . ""; } } } } private function print_auth_done_all_good($additional_msg = null) { echo '

'; esc_html_e('You have already set up your authentication. Unless you wish to regenerate the token this step is not required. ', 'photonic'); if (!empty($additional_msg)) { echo $additional_msg; } echo '

'; } private function get_login_button($provider) { return sprintf(esc_html__('Login and get Access Token from %s', 'photonic'), $provider); } function obtain_token() { $provider = sanitize_text_field($_POST['provider']); if ($provider == 'google') { $code = esc_attr($_POST['code']); require_once(PHOTONIC_PATH."/Modules/Google_Photos.php"); $module = Google_Photos::get_instance(); global $photonic_google_use_own_keys, $photonic_google_client_id, $photonic_google_client_secret; // if (!empty($photonic_google_use_own_keys) || (!empty($photonic_google_client_id) && !empty($photonic_google_client_secret))) { $response = Photonic::http($module->access_token_URL(), 'POST', [ 'code' => $code, 'grant_type' => 'authorization_code', 'client_id' => $module->client_id, 'client_secret' => $module->client_secret, 'redirect_uri' => admin_url('admin.php?page=photonic-auth&source=google'), ]); /* } else { $response = Photonic::http($module->access_token_URL(), 'POST', [ 'code' => $code, 'grant_type' => 'authorization_code', 'client_id' => $module->client_id, 'client_secret' => $module->client_secret, 'redirect_uri' => 'https://aquoid.com/photonic-router/google.php', 'state' => admin_url('admin.php?page=photonic-auth&source=google'), ]); }*/ if (!is_wp_error($response) && is_array($response)) { echo($response['body']); } else { } } else if ($provider == 'flickr') { require_once(PHOTONIC_PATH."/Modules/Flickr.php"); $module = Flickr::get_instance(); if (empty($_POST['oauth_token']) && empty($_POST['oauth_verifier'])) { $request_token = $module->get_request_token(admin_url('admin.php?page=photonic-auth&provider=flickr')); $authorize_url = $module->get_authorize_URL($request_token); $authorize_url .= '&perms=read'; $module->save_token($request_token); echo $authorize_url; } } else if ($provider == 'smug') { require_once(PHOTONIC_PATH."/Modules/SmugMug.php"); $module = SmugMug::get_instance(); if (empty($_POST['oauth_token']) && empty($_POST['oauth_verifier'])) { $request_token = $module->get_request_token(admin_url('admin.php?page=photonic-auth&provider=smug')); $authorize_url = $module->get_authorize_URL($request_token); $authorize_url .= '&Access=Full&Permissions=Read'; $module->save_token($request_token); echo $authorize_url; } } else if ($provider == 'zenfolio') { $module = Zenfolio::get_instance(); if (!empty($_POST['password'])) { $response = $module->authenticate($_POST['password']); if (!empty($response['error'])) { echo $response['error']; } else if (!empty($response['success'])) { esc_html_e('Authentication successful! All your galleries will be displayed with Authentication in place.', 'photonic'); } } } } }