Skip to content

Commit 1d8d711

Browse files
authored
Formatting fixes
1 parent 500045d commit 1d8d711

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

plugin.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
*/
1010

1111
// No direct call
12-
if( !defined( 'YOURLS_ABSPATH' ) ) die();
12+
if (!defined('YOURLS_ABSPATH')) {
13+
die();
14+
}
1315

1416
/* Assumes that you have already downloaded and installed the
1517
* Google APIs Client Library for PHP and it's in the same directory.
1618
* See https://github.com/google/google-api-php-client for install instructions.
1719
* Include your composer dependencies:
1820
*/
19-
require_once __DIR__.'/vendor/autoload.php';
21+
require_once __DIR__ . '/vendor/autoload.php';
2022

2123
/* The function yourls_is_valid_user() in includes/functions-auth.php checks for a valid user via the login
2224
* form or stored cookie. The 'shunt_is_valid_user' filter allows plugins such as this one, to short-circuit
@@ -26,7 +28,7 @@
2628
/* This says: when filter 'shunt_is_valid_user' is triggered, execute function 'atomarch_google_auth'
2729
* and send back it's return value. Filters should always have a return value.
2830
*/
29-
yourls_add_filter( 'shunt_is_valid_user' , 'atomarch_google_auth' );
31+
yourls_add_filter('shunt_is_valid_user', 'atomarch_google_auth');
3032

3133
function atomarch_google_auth() {
3234

@@ -39,64 +41,62 @@ function atomarch_google_auth() {
3941
// See https://developers.google.com/api-client-library/php/auth/web-app to create
4042
// an OAuth 2.0 client ID, and download the resulting JSON file
4143
// This assumes that client_secrets.json file resides in the same directory as plugin.php
42-
$client->setAuthConfig( dirname(__FILE__) .'/client_secrets.json');
44+
$client->setAuthConfig(dirname(__FILE__) . '/client_secrets.json');
4345

44-
$client->setRedirectUri( yourls_admin_url() );
46+
$client->setRedirectUri(yourls_admin_url());
4547

4648
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
4749
// User has already authenticated against google with an approved domain, nothing to do
4850
return true;
4951

5052
} else {
5153

52-
if (! isset($_GET['code'])) {
54+
if (!isset($_GET['code'])) {
5355

54-
// Generate a URL to request access from Google's OAuth 2.0 server
55-
$auth_url = $client->createAuthUrl();
56-
// Redirect the user to $auth_url so they can enter their Google credentials
57-
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
56+
// Generate a URL to request access from Google's OAuth 2.0 server
57+
$auth_url = $client->createAuthUrl();
58+
// Redirect the user to $auth_url so they can enter their Google credentials
59+
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
5860

59-
} else {
60-
// Exchange an authorization code for an access token
61+
} else {
62+
// Exchange an authorization code for an access token
6163
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
6264
//Store Access Token in a session variable
6365
$_SESSION['access_token'] = $token;
6466

65-
if ( atomarch_check_domain($client) === false ) {
67+
if (atomarch_check_domain($client) === false) {
6668
$client->revokeToken();
6769
unset($_SESSION['access_token']);
68-
yourls_e( "User from Unauthorized Domain." );
70+
yourls_e("User from Unauthorized Domain.");
6971
die();
7072
}
7173

72-
$redirect_uri = yourls_admin_url();
73-
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
74-
}
74+
$redirect_uri = yourls_admin_url();
75+
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
76+
}
7577
}
7678
}
7779

78-
function atomarch_check_domain( $google_client ) {
80+
function atomarch_check_domain($google_client) {
7981

8082
// List of domains that have permission to login. Use "*"" to allow access from any google account
8183
//$APPROVED_DOMAINS = array("domain1.com", "domain2.com");
8284
$APPROVED_DOMAINS = array("*");
8385

84-
if ( in_array("*", $APPROVED_DOMAINS) ) {
85-
return true;
86+
if (in_array("*", $APPROVED_DOMAINS)) {
87+
return true;
8688
}
8789

8890
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
8991

9092
$google_oauthV2 = new Google_Service_Oauth2($google_client);
9193
$user_info = $google_oauthV2->userinfo->get();
92-
$user_domain = substr(strrchr($user_info['email'], "@"), 1);
94+
$user_domain = substr(strrchr($user_info['email'], "@"), 1);
9395

94-
if ( in_array($user_domain, $APPROVED_DOMAINS) ) {
95-
return true;
96-
} else {
97-
return false;
98-
}
96+
if (in_array($user_domain, $APPROVED_DOMAINS)) {
97+
return true;
98+
} else {
99+
return false;
100+
}
99101
}
100102
}
101-
102-
?>

0 commit comments

Comments
 (0)