PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.34
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.34
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
photonic / admin / Photonic_Authentication_Page.php

Photonic_Authentication_Page.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.34, at admin/Photonic_Authentication_Page.php

296 lines 14.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Photonic_Authentication_Page {
4 function __construct() {
5 }
6
7 function render() {
8 ?>
9 <div class="photonic-waiting"><img src="<?php echo PHOTONIC_URL.'/include/images/downloading-dots.gif'; ?>" alt='waiting'/></div>
10 <h1>Photonic - Authentication</h1>
11 <form method="post" id="photonic-auth-form">
12 <h2 id="#photonic-flickr-auth-section">Flickr</h2>
13 <?php $this->display_flickr(); ?>
14
15 <h2 id="#photonic-smugmug-auth-section">SmugMug</h2>
16 <?php $this->display_smugmug();?>
17
18 <h2 id="#photonic-google-auth-section">Google Photos</h2>
19 <?php $this->display_google(); ?>
20
21 <!-- <h3 id="#photonic-google-auth-section-bundled">Google Photos</h3>
22 --><?php /*$this->display_google_bundled_token_getter(); */?>
23
24 <h2 id="#photonic-instagram-auth-section">Instagram</h2>
25 <?php $this->display_instagram(); ?>
26
27 <h2 id="#photonic-zenfolio-auth-section">Zenfolio</h2>
28 <?php $this->display_zenfolio(); ?>
29 </form>
30 <?php
31 }
32
33 function display_flickr() {
34 global $photonic_flickr_gallery;
35 if (!isset($photonic_flickr_gallery)) {
36 $photonic_flickr_gallery = new Photonic_Flickr_Processor();
37 }
38
39 $this->show_token_section($photonic_flickr_gallery, 'flickr', 'Flickr');
40 }
41
42 function display_smugmug() {
43 global $photonic_smugmug_gallery;
44 if (!isset($photonic_smugmug_gallery)) {
45 $photonic_smugmug_gallery = new Photonic_SmugMug_Processor();
46 }
47
48 $this->show_token_section($photonic_smugmug_gallery, 'smug', 'SmugMug');
49 }
50
51 function display_google() {
52 global $photonic_google_client_id, $photonic_google_client_secret, $photonic_google_gallery, $photonic_google_refresh_token;
53 echo "<div class=\"photonic-token-header\">\n";
54 if (empty($photonic_google_client_id) || empty($photonic_google_client_secret)) {
55 echo sprintf(esc_html__('Please set up your Google Client ID and Client Secret under %s', 'photonic'),
56 '<em>Photonic &rarr; Settings &rarr; Google Photos &rarr; Google Photos Settings</em>');
57 }
58 else {
59 if (!isset($photonic_google_gallery)) {
60 $photonic_google_gallery = new Photonic_Google_Photos_Processor();
61 }
62 $parameters = Photonic_Processor::parse_parameters($_SERVER['QUERY_STRING']);
63
64 if (!empty($photonic_google_refresh_token)) {
65 $this->print_auth_done_all_good();
66 }
67
68 echo "</div>\n";
69 echo "<div class=\"photonic-token-header\">\n";
70 esc_html_e("You first have to authorize Photonic to connect to your Google account.", 'photonic');
71 echo "<br/>\n";
72 if (!isset($parameters['code']) || !isset($parameters['source']) || $parameters['source'] != 'google') {
73 echo "<a href='".$photonic_google_gallery->get_authorization_url(['redirect_uri' => admin_url('admin.php?page=photonic-auth&source=google'), 'prompt' => 'consent'])."' class='button button-primary'>".
74 esc_html__('Step 1: Authenticate', 'photonic')."</a>";
75 echo "</div>\n";
76 echo "<div class=\"photonic-token-header\">\n";
77 echo esc_html__("Next, you have to obtain the token.", 'photonic').'<br/>';
78 echo "<span class='button photonic-helper-button-disabled'>".
79 esc_html__('Step 2: Obtain Token', 'photonic')."</span>";
80 }
81 else {
82 echo "<span class='button photonic-helper-button-disabled'>".
83 esc_html__('Step 1: Authenticate', 'photonic')."</span>";
84 echo "</div>\n";
85 echo "<div class=\"photonic-token-header\">\n";
86 echo esc_html__("Next, you have to obtain the token.", 'photonic').'<br/>';
87 echo "<a href='#' class='button button-primary photonic-google-refresh'>".
88 esc_html__('Step 2: Obtain Token', 'photonic')."</a>";
89 echo '<input type="hidden" value="'.$parameters['code'].'" id="photonic-google-oauth-code"/>';
90 echo '<input type="hidden" value="'.$parameters['state'].'" id="photonic-google-oauth-state"/>';
91 }
92 }
93 echo "</div>\n";
94 echo '<div class="result" id="google-result">&nbsp;</div>';
95 echo sprintf(esc_html__('If you are facing issues with the authentication please follow the workaround %1$shere%2$s', 'photonic'),
96 '<a href="https://aquoid.com/plugins/photonic/google-photos/#auth-workaround" target="_blank">',
97 '</a>');
98 }
99
100 function display_google_bundled() {
101 global $photonic_google_gallery, $photonic_google_refresh_token;
102 echo "<div class=\"photonic-token-header\">\n";
103 if (!isset($photonic_google_gallery)) {
104 $photonic_google_gallery = new Photonic_Google_Photos_Processor();
105 }
106 $parameters = Photonic_Processor::parse_parameters($_SERVER['QUERY_STRING']);
107
108 if (!empty($photonic_google_refresh_token) && $photonic_google_gallery->refresh_token_valid) {
109 $this->print_auth_done_all_good();
110 }
111
112 echo "</div>\n";
113 echo "<div class=\"photonic-token-header\">\n";
114 esc_html_e("You first have to authorize Photonic to connect to your Google account.", 'photonic');
115 echo "<br/>\n";
116 if (!isset($parameters['code']) || !isset($parameters['source']) || $parameters['source'] != 'google') {
117 echo "<a href='".$photonic_google_gallery->get_authorization_url([
118 'redirect_uri' => 'https://aquoid.com/photonic-router/google.php',
119 'state' => admin_url('admin.php?page=photonic-auth&source=google'),
120 'prompt' => 'consent',
121 ])."' class='button button-primary'>".
122 esc_html__('Step 1: Authenticate', 'photonic')."</a>";
123 echo "</div>\n";
124 echo "<div class=\"photonic-token-header\">\n";
125 echo esc_html__("Next, you have to obtain the token.", 'photonic').'<br/>';
126 echo "<span class='button photonic-helper-button-disabled'>".
127 esc_html__('Step 2: Obtain Token', 'photonic')."</span>";
128 }
129 else {
130 echo "<span class='button photonic-helper-button-disabled'>".
131 esc_html__('Step 1: Authenticate', 'photonic')."</span>";
132 echo "</div>\n";
133 echo "<div class=\"photonic-token-header\">\n";
134 echo esc_html__("Next, you have to obtain the token.", 'photonic').'<br/>';
135 echo "<a href='#' class='button button-primary photonic-google-refresh'>".
136 esc_html__('Step 2: Obtain Token', 'photonic')."</a>";
137 echo '<input type="hidden" value="'.$parameters['code'].'" id="photonic-google-oauth-code"/>';
138 }
139 echo "</div>\n";
140 echo '<div class="result" id="google-result">&nbsp;</div>';
141
142 echo "<div class=\"photonic-token-header\">\n";
143 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').'<br/>';
144 echo "<a href='".$photonic_google_gallery->get_authorization_url([
145 'redirect_uri' => 'https://aquoid.com/photonic-router/google.php',
146 'prompt' => 'consent',
147 'state' => '',
148 ])."' class='button button-primary' target='_blank'>".
149 esc_html__("Authenticate using Photonic's website", 'photonic')."</a>";
150 echo "</div>\n";
151 }
152
153 function display_instagram() {
154 global $photonic_instagram_gallery;
155 if (!isset($photonic_instagram_gallery)) {
156 $photonic_instagram_gallery = new Photonic_Instagram_Processor();
157 }
158 $this->show_token_section_header($photonic_instagram_gallery, 'Instagram');
159 $response = Photonic_Processor::parse_parameters($_SERVER['QUERY_STRING']);
160 if (empty($response['access_token'])) {
161 echo "<a href='https://api.instagram.com/oauth/authorize/?client_id=1089620424711320&scope=user_profile,user_media&redirect_uri=https://aquoid.com/photonic-router/instagram/&state=" .
162 admin_url('admin.php?page=photonic-auth') . "&response_type=code' class='button button-primary'>" .
163 $this->get_login_button('Instagram'). "</a>";
164 }
165 else if (!empty($response['access_token'])) {
166 echo "<span class='button photonic-helper-button-disabled'>" . $this->get_login_button('Instagram') . "</span>";
167 echo '<div class="result">'.
168 (!empty($response['access_token']) ? 'Access token: <code id="instagram-token">'.$response['access_token'].'</code><br/>' : '&nbsp;').
169 (!empty($response['expires_in']) ? '<input type="hidden" id="instagram-token-expires-in" value="'.$response['expires_in'].'" />' : '').
170 (!empty($response['user_id']) ? '<input type="hidden" id="instagram-token-client-id" value="'.$response['user_id'].'" />' : '').
171 (!empty($response['user']) ? 'User name: <code id="instagram-token-user">'.$response['user'].'</code><br/>' : '').
172 '</div>';
173
174 echo "<a href='#' class='button button-primary photonic-save-token' data-photonic-provider='instagram'>" . esc_html__('Save Token', 'photonic') . "</a>";
175 }
176 }
177
178 function display_zenfolio() {
179 global $photonic_zenfolio_gallery, $photonic_zenfolio_default_user;
180 if (!isset($photonic_zenfolio_gallery)) {
181 $photonic_zenfolio_gallery = new Photonic_Zenfolio_Processor();
182 }
183 $gallery = $photonic_zenfolio_gallery;
184
185 echo "<div class=\"photonic-token-header\">\n";
186 if (empty($photonic_zenfolio_default_user)) {
187 echo sprintf(esc_html__('Please set up the default user for Zenfolio under %s', 'photonic'),
188 '<em>Photonic &rarr; Settings &rarr; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Default User</em>')."\n";
189 }
190 else if (!empty($gallery->token)) {
191 $this->print_auth_done_all_good();
192 }
193 echo "</div>\n";
194
195 $response = Photonic_Processor::parse_parameters($_SERVER['QUERY_STRING']);
196 if (!empty($photonic_zenfolio_default_user) && (empty($response['provider']) || 'zenfolio' !== $response['provider'])) {
197 echo "<label>".esc_html__('Password:', 'photonic')."<input type='password' name='zenfolio-password' id='zenfolio-password'></label>";
198 echo "<a href='#' class='button button-primary' data-photonic-provider='zenfolio'>" . esc_html__('Login and Authenticate', 'photonic') . "</a>";
199 }
200 if (!empty($gallery->token)) {
201 echo "<div style='display: block; width: 100%;'>\n";
202 echo "<a href='#' class='button button-primary photonic-zenfolio-delete'>".esc_html__('Delete current Zenfolio authentication data', 'photonic')."</a>";
203 echo "</div>\n";
204 }
205 echo '<div class="result" id="zenfolio-result">&nbsp;</div>';
206 }
207
208 private function show_token_section($gallery, $provider_slug, $provider_text) {
209 $this->show_token_section_header($gallery, $provider_text);
210 if (!empty($gallery->api_key) && !empty($gallery->api_secret)) {
211 $this->show_token_section_body($gallery, $provider_slug, $provider_text);
212 }
213 else {
214 echo '<div class="result" id="'.$provider_slug.'-result">&nbsp;</div>';
215 }
216 }
217
218 /**
219 * @param $gallery Photonic_Processor
220 * @param $provider string
221 */
222 private function show_token_section_header($gallery, $provider) {
223 echo "<div class=\"photonic-token-header\">\n";
224
225 if (empty($gallery->api_key) || empty($gallery->api_secret)) {
226 echo sprintf(esc_html__('Please set up your %1$s API key under %2$s.', 'photonic'), $provider, sprintf('<em>Photonic &rarr; Settings &rarr; %1$s &rarr; %1$s Settings</em>', $provider));
227 }
228 else if ($provider == 'Instagram' && !empty($gallery->token)) {
229 $expiring_soon = $gallery->is_token_expiring_soon(30);
230 if (is_null($expiring_soon)) {
231 // Not yet authenticated with the new API.
232 echo '<p class="notice notice-error">'.esc_html__('Your authentication credentials are for the old Instagram API. Please reauthenticate to keep Photonic working.', 'photonic').'</p><br/>';
233 }
234 else if ($expiring_soon === 1) {
235 echo '<p class="notice notice-warning">'.esc_html__('Your authentication credentials are expiring soon. Please reauthenticate to keep Photonic working.', 'photonic').'</p><br/>';
236 }
237 else if ($expiring_soon === -1) {
238 echo '<p class="notice notice-error">'.esc_html__('Your authentication credentials have expired! Please reauthenticate to keep Photonic working.', 'photonic').'</p><br/>';
239 }
240 else {
241 $cached_token = $gallery->get_cached_token();
242
243 if (!empty($cached_token) && !empty($cached_token['user'])) {
244 $this->print_auth_done_all_good(sprintf(esc_html__('You are logged in as %1$s.', 'photonic'), '<code>'.$cached_token['user'].'</code>'));
245 }
246 else {
247 $this->print_auth_done_all_good();
248 }
249 }
250 }
251 else if (!empty($gallery->token)) {
252 $this->print_auth_done_all_good();
253 }
254 echo "</div>\n";
255 }
256
257 /**
258 * @param $gallery Photonic_OAuth1_Processor | Photonic_OAuth2_Processor
259 * @param $provider
260 * @param $provider_text
261 */
262 public function show_token_section_body($gallery, $provider, $provider_text) {
263 $photonic_authentication = get_option('photonic_authentication');
264 $response = Photonic_Processor::parse_parameters($_SERVER['QUERY_STRING']);
265
266 if (empty($response['provider']) || (!empty($response['provider']) && $provider !== $response['provider'])) {
267 echo "<a href='#' class='button button-primary photonic-token-request' data-photonic-provider='$provider'>" . $this->get_login_button($provider_text) . "</a>";
268 }
269 else if (!empty($response['oauth_token']) && !empty($response['oauth_verifier'])) {
270 echo "<span class='button photonic-helper-button-disabled'>" . $this->get_login_button($provider_text) . "</span>";
271 $authorization = ['oauth_token' => $response['oauth_token'], 'oauth_verifier' => $response['oauth_verifier']];
272 if (isset($photonic_authentication) && isset($photonic_authentication[$provider]) && isset($photonic_authentication[$provider]['oauth_token_secret'])) {
273 $authorization['oauth_token_secret'] = $photonic_authentication[$provider]['oauth_token_secret'];
274 }
275 $access_token = $gallery->get_access_token($authorization, false);
276 if (isset($access_token['oauth_token'])) {
277 echo '<div class="result">Access Token: <code id="'.$provider.'-token">' . $access_token['oauth_token'] . '</code><br/>Access Token Secret: <code id="'.$provider.'-token-secret">' . $access_token['oauth_token_secret'] . '</code></div>'."\n";
278 echo "<a href='#' class='button button-primary photonic-save-token' data-photonic-provider='$provider'>" . esc_html__('Save Token', 'photonic') . "</a>";
279 }
280 }
281 }
282
283 private function print_auth_done_all_good($additional_msg = null) {
284 echo '<p class="notice notice-success">';
285 esc_html_e('You have already set up your authentication. Unless you wish to regenerate the token this step is not required. ', 'photonic');
286 if (!empty($additional_msg)) {
287 echo $additional_msg;
288 }
289 echo '</p>';
290 }
291
292 private function get_login_button($provider) {
293 return sprintf(esc_html__('Login and get Access Token from %s', 'photonic'), $provider);
294 }
295 }
296