Passed
Push — v1 ( 9d33f6...ef500b )
by Benjamin
02:28
created
providers/login/Google.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -12,56 +12,56 @@
 block discarded – undo
12 12
 
13 13
 class Google extends BaseProvider
14 14
 {
15
-	/**
16
-	 * Get the provider name.
17
-	 *
18
-	 * @return string
19
-	 */
20
-	public function getName()
21
-	{
22
-		return 'Google';
23
-	}
15
+    /**
16
+     * Get the provider name.
17
+     *
18
+     * @return string
19
+     */
20
+    public function getName()
21
+    {
22
+        return 'Google';
23
+    }
24 24
 
25
-	/**
26
-	 * Get the provider handle.
27
-	 *
28
-	 * @return string
29
-	 */
30
-	public function getOauthProviderHandle()
31
-	{
32
-		return 'google';
33
-	}
25
+    /**
26
+     * Get the provider handle.
27
+     *
28
+     * @return string
29
+     */
30
+    public function getOauthProviderHandle()
31
+    {
32
+        return 'google';
33
+    }
34 34
 
35
-	/**
36
-	 * @inheritDoc
37
-	 */
38
-	public function getDefaultScope()
39
-	{
40
-		return [
41
-			'https://www.googleapis.com/auth/userinfo.profile',
42
-			'https://www.googleapis.com/auth/userinfo.email'
43
-		];
44
-	}
35
+    /**
36
+     * @inheritDoc
37
+     */
38
+    public function getDefaultScope()
39
+    {
40
+        return [
41
+            'https://www.googleapis.com/auth/userinfo.profile',
42
+            'https://www.googleapis.com/auth/userinfo.email'
43
+        ];
44
+    }
45 45
 
46
-	public function getProfile(Oauth_TokenModel $token)
47
-	{
48
-		$remoteProfile = $this->getRemoteProfile($token);
46
+    public function getProfile(Oauth_TokenModel $token)
47
+    {
48
+        $remoteProfile = $this->getRemoteProfile($token);
49 49
 
50
-		$photoUrl = $remoteProfile->getAvatar();
50
+        $photoUrl = $remoteProfile->getAvatar();
51 51
 
52
-		if(strpos($photoUrl, '?') !== false)
53
-		{
54
-			$photoUrl = substr($photoUrl, 0, strpos($photoUrl, "?"));
55
-		}
52
+        if(strpos($photoUrl, '?') !== false)
53
+        {
54
+            $photoUrl = substr($photoUrl, 0, strpos($photoUrl, "?"));
55
+        }
56 56
 
57
-		return [
58
-			'id' => $remoteProfile->getId(),
59
-			'email' => $remoteProfile->getEmail(),
60
-			'firstName' => $remoteProfile->getFirstName(),
61
-			'lastName' => $remoteProfile->getLastName(),
62
-			'photoUrl' => $photoUrl,
57
+        return [
58
+            'id' => $remoteProfile->getId(),
59
+            'email' => $remoteProfile->getEmail(),
60
+            'firstName' => $remoteProfile->getFirstName(),
61
+            'lastName' => $remoteProfile->getLastName(),
62
+            'photoUrl' => $photoUrl,
63 63
 
64
-			'name' => $remoteProfile->getName(),
65
-		];
66
-	}
64
+            'name' => $remoteProfile->getName(),
65
+        ];
66
+    }
67 67
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
 
50 50
 		$photoUrl = $remoteProfile->getAvatar();
51 51
 
52
-		if(strpos($photoUrl, '?') !== false)
52
+		if (strpos($photoUrl, '?') !== false)
53 53
 		{
54 54
 			$photoUrl = substr($photoUrl, 0, strpos($photoUrl, "?"));
55 55
 		}
Please login to merge, or discard this patch.
providers/login/Twitter.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -12,42 +12,42 @@
 block discarded – undo
12 12
 
13 13
 class Twitter extends BaseProvider
14 14
 {
15
-	/**
16
-	 * Get the provider name.
17
-	 *
18
-	 * @return string
19
-	 */
20
-	public function getName()
21
-	{
22
-		return 'Twitter';
23
-	}
24
-
25
-	/**
26
-	 * Get the provider handle.
27
-	 *
28
-	 * @return string
29
-	 */
30
-	public function getOauthProviderHandle()
31
-	{
32
-		return 'twitter';
33
-	}
34
-
35
-	public function getProfile(Oauth_TokenModel $token)
36
-	{
37
-		$remoteProfile = $this->getRemoteProfile($token);
38
-
39
-		$photoUrl = $remoteProfile->imageUrl;
40
-		$photoUrl = str_replace("_normal.", ".", $photoUrl);
41
-
42
-		return [
43
-			'id' => $remoteProfile->uid,
44
-			'email' => $remoteProfile->email,
45
-			'photoUrl' => $photoUrl,
46
-
47
-			'nickname' => $remoteProfile->nickname,
48
-			'name' => $remoteProfile->name,
49
-			'location' => $remoteProfile->location,
50
-			'description' => $remoteProfile->description,
51
-		];
52
-	}
15
+    /**
16
+     * Get the provider name.
17
+     *
18
+     * @return string
19
+     */
20
+    public function getName()
21
+    {
22
+        return 'Twitter';
23
+    }
24
+
25
+    /**
26
+     * Get the provider handle.
27
+     *
28
+     * @return string
29
+     */
30
+    public function getOauthProviderHandle()
31
+    {
32
+        return 'twitter';
33
+    }
34
+
35
+    public function getProfile(Oauth_TokenModel $token)
36
+    {
37
+        $remoteProfile = $this->getRemoteProfile($token);
38
+
39
+        $photoUrl = $remoteProfile->imageUrl;
40
+        $photoUrl = str_replace("_normal.", ".", $photoUrl);
41
+
42
+        return [
43
+            'id' => $remoteProfile->uid,
44
+            'email' => $remoteProfile->email,
45
+            'photoUrl' => $photoUrl,
46
+
47
+            'nickname' => $remoteProfile->nickname,
48
+            'name' => $remoteProfile->name,
49
+            'location' => $remoteProfile->location,
50
+            'description' => $remoteProfile->description,
51
+        ];
52
+    }
53 53
 }
Please login to merge, or discard this patch.
providers/login/BaseProvider.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -13,142 +13,142 @@
 block discarded – undo
13 13
 
14 14
 abstract class BaseProvider implements ISocial_Provider
15 15
 {
16
-	/**
17
-	 * Get the provider handle.
18
-	 *
19
-	 * @return string
20
-	 */
21
-	public function getHandle()
22
-	{
23
-		$class = $this->getClass();
24
-
25
-		$handle = strtolower($class);
26
-
27
-		return $handle;
28
-	}
29
-
30
-	/**
31
-	 * Get the class name, stripping all the namespaces.
32
-	 *
33
-	 * For example, "Dukt\Social\LoginProviders\Dribbble" becomes "Dribbble"
34
-	 *
35
-	 * @return string
36
-	 */
37
-	public function getClass()
38
-	{
39
-		$nsClass = get_class($this);
40
-
41
-		$class = substr($nsClass, strrpos($nsClass, "\\") + 1);
42
-
43
-		return $class;
44
-	}
45
-
46
-	/**
47
-	 * Get the icon URL.
48
-	 *
49
-	 * @return mixed
50
-	 */
51
-	public function getIconUrl()
52
-	{
53
-		return $this->getOauthProvider()->getIconUrl();
54
-	}
55
-
56
-	/**
57
-	 * Get the OAuth provider.
58
-	 *
59
-	 * @return mixed
60
-	 */
61
-	public function getOauthProvider()
62
-	{
16
+    /**
17
+     * Get the provider handle.
18
+     *
19
+     * @return string
20
+     */
21
+    public function getHandle()
22
+    {
23
+        $class = $this->getClass();
24
+
25
+        $handle = strtolower($class);
26
+
27
+        return $handle;
28
+    }
29
+
30
+    /**
31
+     * Get the class name, stripping all the namespaces.
32
+     *
33
+     * For example, "Dukt\Social\LoginProviders\Dribbble" becomes "Dribbble"
34
+     *
35
+     * @return string
36
+     */
37
+    public function getClass()
38
+    {
39
+        $nsClass = get_class($this);
40
+
41
+        $class = substr($nsClass, strrpos($nsClass, "\\") + 1);
42
+
43
+        return $class;
44
+    }
45
+
46
+    /**
47
+     * Get the icon URL.
48
+     *
49
+     * @return mixed
50
+     */
51
+    public function getIconUrl()
52
+    {
53
+        return $this->getOauthProvider()->getIconUrl();
54
+    }
55
+
56
+    /**
57
+     * Get the OAuth provider.
58
+     *
59
+     * @return mixed
60
+     */
61
+    public function getOauthProvider()
62
+    {
63 63
         Craft::app()->social->checkPluginRequirements();
64 64
 
65
-		return Craft::app()->oauth->getProvider($this->getHandle(), false);
66
-	}
67
-
68
-	/**
69
-	 * Get the default scope.
70
-	 *
71
-	 * @return mixed
72
-	 */
73
-	public function getDefaultScope()
74
-	{
75
-	}
76
-
77
-	/**
78
-	 * Get the defaul authorization options.
79
-	 *
80
-	 * @return mixed
81
-	 */
82
-	public function getDefaultAuthorizationOptions()
83
-	{
84
-	}
85
-
86
-	/**
87
-	 * Returns the `scope` from login provider class by default, or the `scope` overridden by the config
88
-	 *
89
-	 * @return mixed
90
-	 */
91
-	public function getScope()
92
-	{
93
-		$providerConfig = Craft::app()->config->get($this->getHandle(), 'social');
94
-
95
-		if ($providerConfig && isset($providerConfig['scope']))
96
-		{
97
-			return $providerConfig['scope'];
98
-		}
99
-		else
100
-		{
101
-			return $this->getDefaultScope();
102
-		}
103
-	}
104
-
105
-	/**
106
-	 * Returns the `authorizationOptions` from login provider class by default, or `authorizationOptions` overridden by the config
107
-	 *
108
-	 * @return mixed
109
-	 */
110
-	public function getAuthorizationOptions()
111
-	{
112
-		$providerConfig = Craft::app()->config->get($this->getHandle(), 'social');
113
-
114
-		if ($providerConfig && isset($providerConfig['authorizationOptions']))
115
-		{
116
-			return $providerConfig['authorizationOptions'];
117
-		}
118
-		else
119
-		{
120
-			return $this->getDefaultAuthorizationOptions();
121
-		}
122
-	}
123
-
124
-	/**
125
-	 * Returns the `enabled` setting from login provider class by default, or `enabled` overridden by the config.
126
-	 *
127
-	 * @return bool
128
-	 */
129
-	public function getIsEnabled()
130
-	{
131
-		// get plugin settings
132
-		$pluginSettings = \Craft\Craft::app()->plugins->getPlugin('social')->getSettings();
133
-		$loginProviders = $pluginSettings->loginProviders;
134
-
135
-		if (isset($loginProviders[$this->getHandle()]['enabled']) && $loginProviders[$this->getHandle()]['enabled'])
136
-		{
137
-			return true;
138
-		}
139
-
140
-		return false;
141
-	}
142
-
143
-	/**
144
-	 * Returns the remote profile
145
-	 *
146
-	 * @param $token
147
-	 *
148
-	 * @return mixed
149
-	 */
150
-	public function getRemoteProfile(Oauth_TokenModel $token)
151
-	{
152
-		return $this->getOauthProvider()->getRemoteResourceOwner($token);
153
-	}
65
+        return Craft::app()->oauth->getProvider($this->getHandle(), false);
66
+    }
67
+
68
+    /**
69
+     * Get the default scope.
70
+     *
71
+     * @return mixed
72
+     */
73
+    public function getDefaultScope()
74
+    {
75
+    }
76
+
77
+    /**
78
+     * Get the defaul authorization options.
79
+     *
80
+     * @return mixed
81
+     */
82
+    public function getDefaultAuthorizationOptions()
83
+    {
84
+    }
85
+
86
+    /**
87
+     * Returns the `scope` from login provider class by default, or the `scope` overridden by the config
88
+     *
89
+     * @return mixed
90
+     */
91
+    public function getScope()
92
+    {
93
+        $providerConfig = Craft::app()->config->get($this->getHandle(), 'social');
94
+
95
+        if ($providerConfig && isset($providerConfig['scope']))
96
+        {
97
+            return $providerConfig['scope'];
98
+        }
99
+        else
100
+        {
101
+            return $this->getDefaultScope();
102
+        }
103
+    }
104
+
105
+    /**
106
+     * Returns the `authorizationOptions` from login provider class by default, or `authorizationOptions` overridden by the config
107
+     *
108
+     * @return mixed
109
+     */
110
+    public function getAuthorizationOptions()
111
+    {
112
+        $providerConfig = Craft::app()->config->get($this->getHandle(), 'social');
113
+
114
+        if ($providerConfig && isset($providerConfig['authorizationOptions']))
115
+        {
116
+            return $providerConfig['authorizationOptions'];
117
+        }
118
+        else
119
+        {
120
+            return $this->getDefaultAuthorizationOptions();
121
+        }
122
+    }
123
+
124
+    /**
125
+     * Returns the `enabled` setting from login provider class by default, or `enabled` overridden by the config.
126
+     *
127
+     * @return bool
128
+     */
129
+    public function getIsEnabled()
130
+    {
131
+        // get plugin settings
132
+        $pluginSettings = \Craft\Craft::app()->plugins->getPlugin('social')->getSettings();
133
+        $loginProviders = $pluginSettings->loginProviders;
134
+
135
+        if (isset($loginProviders[$this->getHandle()]['enabled']) && $loginProviders[$this->getHandle()]['enabled'])
136
+        {
137
+            return true;
138
+        }
139
+
140
+        return false;
141
+    }
142
+
143
+    /**
144
+     * Returns the remote profile
145
+     *
146
+     * @param $token
147
+     *
148
+     * @return mixed
149
+     */
150
+    public function getRemoteProfile(Oauth_TokenModel $token)
151
+    {
152
+        return $this->getOauthProvider()->getRemoteResourceOwner($token);
153
+    }
154 154
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -95,8 +95,7 @@  discard block
 block discarded – undo
95 95
 		if ($providerConfig && isset($providerConfig['scope']))
96 96
 		{
97 97
 			return $providerConfig['scope'];
98
-		}
99
-		else
98
+		} else
100 99
 		{
101 100
 			return $this->getDefaultScope();
102 101
 		}
@@ -114,8 +113,7 @@  discard block
 block discarded – undo
114 113
 		if ($providerConfig && isset($providerConfig['authorizationOptions']))
115 114
 		{
116 115
 			return $providerConfig['authorizationOptions'];
117
-		}
118
-		else
116
+		} else
119 117
 		{
120 118
 			return $this->getDefaultAuthorizationOptions();
121 119
 		}
Please login to merge, or discard this patch.
providers/login/Facebook.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -13,39 +13,39 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Facebook extends BaseProvider
15 15
 {
16
-	/**
17
-	 * Get the provider name.
18
-	 *
19
-	 * @return string
20
-	 */
21
-	public function getName()
22
-	{
23
-		return 'Facebook';
24
-	}
25
-
26
-	/**
27
-	 * Get the provider handle.
28
-	 *
29
-	 * @return string
30
-	 */
31
-	public function getOauthProviderHandle()
32
-	{
33
-		return 'facebook';
34
-	}
35
-
36
-	/**
37
-	 * @inheritDoc
38
-	 */
39
-	public function getDefaultScope()
40
-	{
41
-		return [
42
-			'email',
43
-		];
44
-	}
45
-
46
-	public function getRemoteProfile(Oauth_TokenModel $token)
47
-	{
48
-		$oauthProvider = $this->getOauthProvider();
16
+    /**
17
+     * Get the provider name.
18
+     *
19
+     * @return string
20
+     */
21
+    public function getName()
22
+    {
23
+        return 'Facebook';
24
+    }
25
+
26
+    /**
27
+     * Get the provider handle.
28
+     *
29
+     * @return string
30
+     */
31
+    public function getOauthProviderHandle()
32
+    {
33
+        return 'facebook';
34
+    }
35
+
36
+    /**
37
+     * @inheritDoc
38
+     */
39
+    public function getDefaultScope()
40
+    {
41
+        return [
42
+            'email',
43
+        ];
44
+    }
45
+
46
+    public function getRemoteProfile(Oauth_TokenModel $token)
47
+    {
48
+        $oauthProvider = $this->getOauthProvider();
49 49
         $providerConfig = \Craft\craft()->config->get($this->getHandle(), 'social');
50 50
 
51 51
         $apiVersion = 'v2.12';
@@ -54,41 +54,41 @@  discard block
 block discarded – undo
54 54
             $apiVersion = $providerConfig['apiVersion'];
55 55
         }
56 56
 
57
-		$client = new Client('https://graph.facebook.com/'.$apiVersion);
58
-		$client->addSubscriber($oauthProvider->getSubscriber($token));
59
-
60
-		$fields = implode(',', [
61
-			'id', 'name', 'first_name', 'last_name',
62
-			'email', 'hometown', 'picture.type(large){url,is_silhouette}',
63
-			'cover{source}', 'gender', 'locale', 'link',
64
-		]);
65
-
66
-		$request = $client->get('/me?fields='.$fields);
67
-
68
-		$response = $request->send();
69
-		$json = $response->json();
70
-
71
-		return $json;
72
-	}
73
-
74
-	public function getProfile(Oauth_TokenModel $token)
75
-	{
76
-		$remoteProfile = $this->getRemoteProfile($token);
77
-
78
-		return [
79
-			'id' => (isset($remoteProfile['id']) ? $remoteProfile['id'] : null ),
80
-			'email' => (isset($remoteProfile['email']) ? $remoteProfile['email'] : null ),
81
-			'firstName' => (isset($remoteProfile['first_name']) ? $remoteProfile['first_name'] : null ),
82
-			'lastName' => (isset($remoteProfile['last_name']) ? $remoteProfile['last_name'] : null ),
83
-			'photoUrl' => (isset($remoteProfile['picture']['data']['url']) ? $remoteProfile['picture']['data']['url'] : null ),
84
-
85
-			'name' => (isset($remoteProfile['name']) ? $remoteProfile['name'] : null ),
86
-			'hometown' => (isset($remoteProfile['hometown']) ? $remoteProfile['hometown'] : null ),
87
-			'isDefaultPicture' => (isset($remoteProfile['picture']['data']['is_silhouette']) ? $remoteProfile['picture']['data']['is_silhouette'] : null ),
88
-			'coverPhotoUrl' => (isset($remoteProfile['cover']['source']) ? $remoteProfile['cover']['source'] : null ),
89
-			'gender' => (isset($remoteProfile['gender']) ? $remoteProfile['gender'] : null ),
90
-			'locale' => (isset($remoteProfile['locale']) ? $remoteProfile['locale'] : null ),
91
-			'link' => (isset($remoteProfile['link']) ? $remoteProfile['link'] : null ),
92
-		];
93
-	}
57
+        $client = new Client('https://graph.facebook.com/'.$apiVersion);
58
+        $client->addSubscriber($oauthProvider->getSubscriber($token));
59
+
60
+        $fields = implode(',', [
61
+            'id', 'name', 'first_name', 'last_name',
62
+            'email', 'hometown', 'picture.type(large){url,is_silhouette}',
63
+            'cover{source}', 'gender', 'locale', 'link',
64
+        ]);
65
+
66
+        $request = $client->get('/me?fields='.$fields);
67
+
68
+        $response = $request->send();
69
+        $json = $response->json();
70
+
71
+        return $json;
72
+    }
73
+
74
+    public function getProfile(Oauth_TokenModel $token)
75
+    {
76
+        $remoteProfile = $this->getRemoteProfile($token);
77
+
78
+        return [
79
+            'id' => (isset($remoteProfile['id']) ? $remoteProfile['id'] : null ),
80
+            'email' => (isset($remoteProfile['email']) ? $remoteProfile['email'] : null ),
81
+            'firstName' => (isset($remoteProfile['first_name']) ? $remoteProfile['first_name'] : null ),
82
+            'lastName' => (isset($remoteProfile['last_name']) ? $remoteProfile['last_name'] : null ),
83
+            'photoUrl' => (isset($remoteProfile['picture']['data']['url']) ? $remoteProfile['picture']['data']['url'] : null ),
84
+
85
+            'name' => (isset($remoteProfile['name']) ? $remoteProfile['name'] : null ),
86
+            'hometown' => (isset($remoteProfile['hometown']) ? $remoteProfile['hometown'] : null ),
87
+            'isDefaultPicture' => (isset($remoteProfile['picture']['data']['is_silhouette']) ? $remoteProfile['picture']['data']['is_silhouette'] : null ),
88
+            'coverPhotoUrl' => (isset($remoteProfile['cover']['source']) ? $remoteProfile['cover']['source'] : null ),
89
+            'gender' => (isset($remoteProfile['gender']) ? $remoteProfile['gender'] : null ),
90
+            'locale' => (isset($remoteProfile['locale']) ? $remoteProfile['locale'] : null ),
91
+            'link' => (isset($remoteProfile['link']) ? $remoteProfile['link'] : null ),
92
+        ];
93
+    }
94 94
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
         $apiVersion = 'v2.12';
52 52
 
53
-        if(!empty($providerConfig['apiVersion'])) {
53
+        if (!empty($providerConfig['apiVersion'])) {
54 54
             $apiVersion = $providerConfig['apiVersion'];
55 55
         }
56 56
 
@@ -76,19 +76,19 @@  discard block
 block discarded – undo
76 76
 		$remoteProfile = $this->getRemoteProfile($token);
77 77
 
78 78
 		return [
79
-			'id' => (isset($remoteProfile['id']) ? $remoteProfile['id'] : null ),
80
-			'email' => (isset($remoteProfile['email']) ? $remoteProfile['email'] : null ),
81
-			'firstName' => (isset($remoteProfile['first_name']) ? $remoteProfile['first_name'] : null ),
82
-			'lastName' => (isset($remoteProfile['last_name']) ? $remoteProfile['last_name'] : null ),
83
-			'photoUrl' => (isset($remoteProfile['picture']['data']['url']) ? $remoteProfile['picture']['data']['url'] : null ),
84
-
85
-			'name' => (isset($remoteProfile['name']) ? $remoteProfile['name'] : null ),
86
-			'hometown' => (isset($remoteProfile['hometown']) ? $remoteProfile['hometown'] : null ),
87
-			'isDefaultPicture' => (isset($remoteProfile['picture']['data']['is_silhouette']) ? $remoteProfile['picture']['data']['is_silhouette'] : null ),
88
-			'coverPhotoUrl' => (isset($remoteProfile['cover']['source']) ? $remoteProfile['cover']['source'] : null ),
89
-			'gender' => (isset($remoteProfile['gender']) ? $remoteProfile['gender'] : null ),
90
-			'locale' => (isset($remoteProfile['locale']) ? $remoteProfile['locale'] : null ),
91
-			'link' => (isset($remoteProfile['link']) ? $remoteProfile['link'] : null ),
79
+			'id' => (isset($remoteProfile['id']) ? $remoteProfile['id'] : null),
80
+			'email' => (isset($remoteProfile['email']) ? $remoteProfile['email'] : null),
81
+			'firstName' => (isset($remoteProfile['first_name']) ? $remoteProfile['first_name'] : null),
82
+			'lastName' => (isset($remoteProfile['last_name']) ? $remoteProfile['last_name'] : null),
83
+			'photoUrl' => (isset($remoteProfile['picture']['data']['url']) ? $remoteProfile['picture']['data']['url'] : null),
84
+
85
+			'name' => (isset($remoteProfile['name']) ? $remoteProfile['name'] : null),
86
+			'hometown' => (isset($remoteProfile['hometown']) ? $remoteProfile['hometown'] : null),
87
+			'isDefaultPicture' => (isset($remoteProfile['picture']['data']['is_silhouette']) ? $remoteProfile['picture']['data']['is_silhouette'] : null),
88
+			'coverPhotoUrl' => (isset($remoteProfile['cover']['source']) ? $remoteProfile['cover']['source'] : null),
89
+			'gender' => (isset($remoteProfile['gender']) ? $remoteProfile['gender'] : null),
90
+			'locale' => (isset($remoteProfile['locale']) ? $remoteProfile['locale'] : null),
91
+			'link' => (isset($remoteProfile['link']) ? $remoteProfile['link'] : null),
92 92
 		];
93 93
 	}
94 94
 }
Please login to merge, or discard this patch.
config.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -2,41 +2,41 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-	/**
6
-	 * Allow Email Match
7
-	 */
8
-	'allowEmailMatch' => false,
5
+    /**
6
+     * Allow Email Match
7
+     */
8
+    'allowEmailMatch' => false,
9 9
 
10 10
 
11
-	/**
12
-	 * Lock social registration to specific domains
13
-	 */
14
-	'lockDomains' => [],
11
+    /**
12
+     * Lock social registration to specific domains
13
+     */
14
+    'lockDomains' => [],
15 15
 
16 16
 
17
-	/**
18
-	 * Twitter Configuration
19
-	 */
17
+    /**
18
+     * Twitter Configuration
19
+     */
20 20
 
21
-	//'twitter' => [
22
-	//    'userMapping' => [
23
-	//        'location' => '{{ location }}',
24
-	//        'profileUrl' => '{{ nickname }}',
25
-	//    ],
26
-	//],
21
+    //'twitter' => [
22
+    //    'userMapping' => [
23
+    //        'location' => '{{ location }}',
24
+    //        'profileUrl' => '{{ nickname }}',
25
+    //    ],
26
+    //],
27 27
 
28 28
 
29
-	/**
30
-	 * Facebook Configuration
31
-	 */
29
+    /**
30
+     * Facebook Configuration
31
+     */
32 32
 
33
-	//'facebook' => [
34
-	//    'userMapping' => [
35
-	//        'firstName' => '{{ firstName }}',
36
-	//        'lastName' => '{{ lastName }}',
37
-	//        'gender' => '{{ gender }}',
38
-	//        'profileUrl' => '{{ link }}',
39
-	//    ],
33
+    //'facebook' => [
34
+    //    'userMapping' => [
35
+    //        'firstName' => '{{ firstName }}',
36
+    //        'lastName' => '{{ lastName }}',
37
+    //        'gender' => '{{ gender }}',
38
+    //        'profileUrl' => '{{ link }}',
39
+    //    ],
40 40
     //    'apiVersion' => 'v2.12',
41
-	//],
41
+    //],
42 42
 ];
Please login to merge, or discard this patch.
models/Social_ProviderModel.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -9,116 +9,116 @@
 block discarded – undo
9 9
 
10 10
 class Social_ProviderModel extends BaseModel
11 11
 {
12
-	// Public Methods
13
-	// =========================================================================
14
-
15
-	/**
16
-	 * Define Attributes
17
-	 */
18
-	public function defineAttributes()
19
-	{
20
-		return array(
21
-			'oauthProviderHandle' => AttributeType::Number,
22
-			'customScope' => AttributeType::Mixed,
23
-		);
24
-	}
25
-
26
-	/**
27
-	 * Get authorization options for the provider.
28
-	 *
29
-	 * @return mixed
30
-	 */
31
-	public function getAuthorizationOptions()
32
-	{
33
-		$providerConfig = craft()->config->get($this->oauthProviderHandle, 'social');
34
-
35
-		if ($providerConfig && isset($providerConfig['authorizationOptions'])) {
36
-			return $providerConfig['authorizationOptions'];
37
-		}
38
-	}
39
-
40
-	/**
41
-	 * Get scope for the provider.
42
-	 *
43
-	 * @return array
44
-	 */
45
-	public function getScope()
46
-	{
47
-		$scope = [];
48
-		$defaultScope = $this->getDefaultScope();
49
-
50
-		if (is_array($defaultScope))
51
-		{
52
-			$scope = array_merge($scope, $defaultScope);
53
-		}
54
-
55
-		if (is_array($this->customScope))
56
-		{
57
-			$scope = array_merge($scope, $this->customScope);
58
-		}
59
-
60
-		return $scope;
61
-	}
62
-
63
-	/**
64
-	 * Return the default scope for the provider.
65
-	 *
66
-	 * @return mixed
67
-	 */
68
-	public function getDefaultScope()
69
-	{
70
-		return $this->getOauthProvider()->getDefaultScope();
71
-	}
72
-
73
-	/**
74
-	 * Get the provider's name.
75
-	 *
76
-	 * @return mixed
77
-	 */
78
-	public function getName()
79
-	{
80
-		return $this->getOauthProvider()->getName();
81
-	}
82
-
83
-	/**
84
-	 * Get the provider's handle.
85
-	 *
86
-	 * @return mixed
87
-	 */
88
-	public function getHandle()
89
-	{
90
-		return $this->getOauthProvider()->getHandle();
91
-	}
92
-
93
-	/**
94
-	 * Get the provider itself.
95
-	 *
96
-	 * @return mixed
97
-	 */
98
-	public function getOauthProvider()
99
-	{
12
+    // Public Methods
13
+    // =========================================================================
14
+
15
+    /**
16
+     * Define Attributes
17
+     */
18
+    public function defineAttributes()
19
+    {
20
+        return array(
21
+            'oauthProviderHandle' => AttributeType::Number,
22
+            'customScope' => AttributeType::Mixed,
23
+        );
24
+    }
25
+
26
+    /**
27
+     * Get authorization options for the provider.
28
+     *
29
+     * @return mixed
30
+     */
31
+    public function getAuthorizationOptions()
32
+    {
33
+        $providerConfig = craft()->config->get($this->oauthProviderHandle, 'social');
34
+
35
+        if ($providerConfig && isset($providerConfig['authorizationOptions'])) {
36
+            return $providerConfig['authorizationOptions'];
37
+        }
38
+    }
39
+
40
+    /**
41
+     * Get scope for the provider.
42
+     *
43
+     * @return array
44
+     */
45
+    public function getScope()
46
+    {
47
+        $scope = [];
48
+        $defaultScope = $this->getDefaultScope();
49
+
50
+        if (is_array($defaultScope))
51
+        {
52
+            $scope = array_merge($scope, $defaultScope);
53
+        }
54
+
55
+        if (is_array($this->customScope))
56
+        {
57
+            $scope = array_merge($scope, $this->customScope);
58
+        }
59
+
60
+        return $scope;
61
+    }
62
+
63
+    /**
64
+     * Return the default scope for the provider.
65
+     *
66
+     * @return mixed
67
+     */
68
+    public function getDefaultScope()
69
+    {
70
+        return $this->getOauthProvider()->getDefaultScope();
71
+    }
72
+
73
+    /**
74
+     * Get the provider's name.
75
+     *
76
+     * @return mixed
77
+     */
78
+    public function getName()
79
+    {
80
+        return $this->getOauthProvider()->getName();
81
+    }
82
+
83
+    /**
84
+     * Get the provider's handle.
85
+     *
86
+     * @return mixed
87
+     */
88
+    public function getHandle()
89
+    {
90
+        return $this->getOauthProvider()->getHandle();
91
+    }
92
+
93
+    /**
94
+     * Get the provider itself.
95
+     *
96
+     * @return mixed
97
+     */
98
+    public function getOauthProvider()
99
+    {
100 100
         Craft::app()->social->checkPluginRequirements();
101 101
 
102
-		return craft()->oauth->getProvider($this->oauthProviderHandle, false);
103
-	}
104
-
105
-	/**
106
-	 * Get the URL to the icon.
107
-	 *
108
-	 * @return mixed
109
-	 */
110
-	public function getIconUrl()
111
-	{
112
-		return $this->getOauthProvider()->getIconUrl();
113
-	}
114
-
115
-	/**
116
-	 * Get the documentation URL for provider scopes.
117
-	 *
118
-	 * @return mixed
119
-	 */
120
-	public function getScopeDocsUrl()
121
-	{
122
-		return $this->getOauthProvider()->getScopeDocsUrl();
123
-	}
102
+        return craft()->oauth->getProvider($this->oauthProviderHandle, false);
103
+    }
104
+
105
+    /**
106
+     * Get the URL to the icon.
107
+     *
108
+     * @return mixed
109
+     */
110
+    public function getIconUrl()
111
+    {
112
+        return $this->getOauthProvider()->getIconUrl();
113
+    }
114
+
115
+    /**
116
+     * Get the documentation URL for provider scopes.
117
+     *
118
+     * @return mixed
119
+     */
120
+    public function getScopeDocsUrl()
121
+    {
122
+        return $this->getOauthProvider()->getScopeDocsUrl();
123
+    }
124 124
 }
Please login to merge, or discard this patch.
models/Social_LoginAccountModel.php 2 patches
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -9,126 +9,126 @@
 block discarded – undo
9 9
 
10 10
 class Social_LoginAccountModel extends BaseElementModel
11 11
 {
12
-	protected $elementType = 'Social_LoginAccount';
13
-
14
-	private $_user;
15
-
16
-	// Public Methods
17
-	// =========================================================================
18
-
19
-	/**
20
-	 * Use the login account's email as its string representation.
21
-	 *
22
-	 * @return string
23
-	 */
24
-	public function __toString()
25
-	{
26
-		if (craft()->config->get('useEmailAsUsername'))
27
-		{
28
-			return $this->email;
29
-		}
30
-		else
31
-		{
32
-			return $this->username;
33
-		}
34
-	}
35
-
36
-	/**
37
-	 * Returns whether the current user can edit the element.
38
-	 *
39
-	 * @return bool
40
-	 */
41
-	public function isEditable()
42
-	{
43
-		return true;
44
-	}
45
-
46
-	/**
47
-	 * Returns the element's CP edit URL.
48
-	 *
49
-	 * @return string|false
50
-	 */
51
-	public function getCpEditUrl()
52
-	{
53
-		return UrlHelper::getCpUrl('social/loginaccounts/'.$this->userId);
54
-	}
55
-
56
-	/**
57
-	 * Returns the URL to the element's thumbnail, if there is one.
58
-	 *
59
-	 * @param int|null $size
60
-	 *
61
-	 * @return string|null
62
-	 */
63
-	public function getThumbUrl($size = 100)
64
-	{
65
-		$url = $this->getUser()->getPhotoUrl($size);
66
-
67
-		if (!$url)
68
-		{
69
-			$url = UrlHelper::getResourceUrl('defaultuserphoto');
70
-		}
71
-
72
-		return $url;
73
-	}
74
-
75
-	/**
76
-	 * Define Attributes
77
-	 */
78
-	public function defineAttributes()
79
-	{
80
-		return array_merge(parent::defineAttributes(), array(
81
-			'id' => AttributeType::Number,
82
-			'userId' => AttributeType::Number,
83
-			'providerHandle' => array(AttributeType::String, 'required' => true),
84
-			'socialUid' => array(AttributeType::String, 'required' => true),
85
-
86
-			'username' => AttributeType::String,
87
-			'email' => AttributeType::String,
88
-			'firstName' => AttributeType::String,
89
-			'lastName' => AttributeType::String,
90
-			'lastLoginDate' => AttributeType::DateTime,
91
-		));
92
-	}
93
-
94
-	/**
95
-	 * Get the OAuth provider for the social account.
96
-	 */
97
-	public function getOauthProvider()
98
-	{
99
-		if ($this->providerHandle)
100
-		{
12
+    protected $elementType = 'Social_LoginAccount';
13
+
14
+    private $_user;
15
+
16
+    // Public Methods
17
+    // =========================================================================
18
+
19
+    /**
20
+     * Use the login account's email as its string representation.
21
+     *
22
+     * @return string
23
+     */
24
+    public function __toString()
25
+    {
26
+        if (craft()->config->get('useEmailAsUsername'))
27
+        {
28
+            return $this->email;
29
+        }
30
+        else
31
+        {
32
+            return $this->username;
33
+        }
34
+    }
35
+
36
+    /**
37
+     * Returns whether the current user can edit the element.
38
+     *
39
+     * @return bool
40
+     */
41
+    public function isEditable()
42
+    {
43
+        return true;
44
+    }
45
+
46
+    /**
47
+     * Returns the element's CP edit URL.
48
+     *
49
+     * @return string|false
50
+     */
51
+    public function getCpEditUrl()
52
+    {
53
+        return UrlHelper::getCpUrl('social/loginaccounts/'.$this->userId);
54
+    }
55
+
56
+    /**
57
+     * Returns the URL to the element's thumbnail, if there is one.
58
+     *
59
+     * @param int|null $size
60
+     *
61
+     * @return string|null
62
+     */
63
+    public function getThumbUrl($size = 100)
64
+    {
65
+        $url = $this->getUser()->getPhotoUrl($size);
66
+
67
+        if (!$url)
68
+        {
69
+            $url = UrlHelper::getResourceUrl('defaultuserphoto');
70
+        }
71
+
72
+        return $url;
73
+    }
74
+
75
+    /**
76
+     * Define Attributes
77
+     */
78
+    public function defineAttributes()
79
+    {
80
+        return array_merge(parent::defineAttributes(), array(
81
+            'id' => AttributeType::Number,
82
+            'userId' => AttributeType::Number,
83
+            'providerHandle' => array(AttributeType::String, 'required' => true),
84
+            'socialUid' => array(AttributeType::String, 'required' => true),
85
+
86
+            'username' => AttributeType::String,
87
+            'email' => AttributeType::String,
88
+            'firstName' => AttributeType::String,
89
+            'lastName' => AttributeType::String,
90
+            'lastLoginDate' => AttributeType::DateTime,
91
+        ));
92
+    }
93
+
94
+    /**
95
+     * Get the OAuth provider for the social account.
96
+     */
97
+    public function getOauthProvider()
98
+    {
99
+        if ($this->providerHandle)
100
+        {
101 101
             Craft::app()->social->checkPluginRequirements();
102
-			return craft()->oauth->getProvider($this->providerHandle);
103
-		}
104
-	}
105
-
106
-	/**
107
-	 * Get the associated Craft user for this social account.
108
-	 */
109
-	public function getUser()
110
-	{
111
-		if (!isset($this->_user))
112
-		{
113
-			if ($this->userId)
114
-			{
115
-				$this->_user = craft()->users->getUserById($this->userId);
116
-			}
117
-		}
118
-
119
-		return $this->_user;
120
-	}
121
-
122
-	/**
123
-	 * Gets the user's full name.
124
-	 *
125
-	 * @return string|null
126
-	 */
127
-	public function getFullName()
128
-	{
129
-		$firstName = trim($this->firstName);
130
-		$lastName = trim($this->lastName);
131
-
132
-		return $firstName.($firstName && $lastName ? ' ' : '').$lastName;
133
-	}
102
+            return craft()->oauth->getProvider($this->providerHandle);
103
+        }
104
+    }
105
+
106
+    /**
107
+     * Get the associated Craft user for this social account.
108
+     */
109
+    public function getUser()
110
+    {
111
+        if (!isset($this->_user))
112
+        {
113
+            if ($this->userId)
114
+            {
115
+                $this->_user = craft()->users->getUserById($this->userId);
116
+            }
117
+        }
118
+
119
+        return $this->_user;
120
+    }
121
+
122
+    /**
123
+     * Gets the user's full name.
124
+     *
125
+     * @return string|null
126
+     */
127
+    public function getFullName()
128
+    {
129
+        $firstName = trim($this->firstName);
130
+        $lastName = trim($this->lastName);
131
+
132
+        return $firstName.($firstName && $lastName ? ' ' : '').$lastName;
133
+    }
134 134
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@
 block discarded – undo
26 26
 		if (craft()->config->get('useEmailAsUsername'))
27 27
 		{
28 28
 			return $this->email;
29
-		}
30
-		else
29
+		} else
31 30
 		{
32 31
 			return $this->username;
33 32
 		}
Please login to merge, or discard this patch.
elementtypes/Social_LoginAccountElementType.php 3 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -3,290 +3,290 @@  discard block
 block discarded – undo
3 3
 
4 4
 class Social_LoginAccountElementType extends BaseElementType
5 5
 {
6
-	/**
7
-	 * Returns the element type name.
8
-	 *
9
-	 * @return string
10
-	 */
11
-	public function getName()
12
-	{
13
-		return Craft::t('Login Accounts');
14
-	}
15
-
16
-	/**
17
-	 * Returns the element index HTML.
18
-	 *
19
-	 * @param ElementCriteriaModel $criteria
20
-	 * @param array                $disabledElementIds
21
-	 * @param array                $viewState
22
-	 * @param string|null          $sourceKey
23
-	 * @param string|null          $context
24
-	 * @param bool                 $includeContainer
25
-	 * @param bool                 $showCheckboxes
26
-	 *
27
-	 * @return string
28
-	 */
29
-	public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes)
30
-	{
31
-		craft()->templates->includeJsResource('social/js/social.js');
32
-
33
-		return parent::getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes);
34
-	}
35
-
36
-	/**
37
-	 * Returns this element type's sources.
38
-	 *
39
-	 * @param string|null $context
40
-	 *
41
-	 * @return array|false
42
-	 */
43
-	public function getSources($context = null)
44
-	{
45
-		$sources = array(
46
-			'*' => array(
47
-				'label' => Craft::t('All login providers'),
48
-				'hasThumbs' => false
49
-			)
50
-		);
51
-
52
-		$loginProviders = craft()->social_loginProviders->getLoginProviders();
53
-
54
-		if ($loginProviders)
55
-		{
56
-			$sources[] = array('heading' => Craft::t('Login Providers'));
57
-
58
-			foreach ($loginProviders as $loginProvider)
59
-			{
60
-				$providerHandle = $loginProvider->getHandle();
61
-				$key = 'group:'.$providerHandle;
62
-
63
-				$sources[$key] = array(
64
-					'label'     => Craft::t($loginProvider->getName()),
65
-					'criteria'  => array('providerHandle' => $providerHandle),
66
-					'hasThumbs' => false
67
-				);
68
-			}
69
-		}
70
-
71
-		// Allow plugins to modify the sources
72
-		craft()->plugins->call('modifyLoginAccountSources', array(&$sources, $context));
73
-
74
-		return $sources;
75
-	}
76
-
77
-	/**
78
-	 * Returns the available element actions for a given source (if one is provided).
79
-	 *
80
-	 * @param string|null $source
81
-	 *
82
-	 * @return array|null
83
-	 */
84
-	public function getAvailableActions($source = null)
85
-	{
86
-		$actions = array();
87
-
88
-		$deleteAction = craft()->elements->getAction('Delete');
89
-		$deleteAction->setParams(array(
90
-			'confirmationMessage' => Craft::t('Are you sure you want to delete the selected login accounts?'),
91
-			'successMessage'      => Craft::t('Login accounts deleted.'),
92
-		));
93
-		$actions[] = $deleteAction;
94
-
95
-		// Allow plugins to add additional actions
96
-		$allPluginActions = craft()->plugins->call('addLoginAccountActions', array($source), true);
97
-
98
-		foreach ($allPluginActions as $pluginActions)
99
-		{
100
-			$actions = array_merge($actions, $pluginActions);
101
-		}
102
-
103
-		return $actions;
104
-	}
105
-
106
-	/**
107
-	 * Defines which element model attributes should be searchable.
108
-	 *
109
-	 * @return array
110
-	 */
111
-	public function defineSearchableAttributes()
112
-	{
113
-		return array('username', 'email', 'firstName', 'lastName', 'fullName', 'providerHandle', 'socialUid', 'userId');
114
-	}
115
-
116
-	/**
117
-	 * Defines the attributes that elements can be sorted by.
118
-	 *
119
-	 * @return array
120
-	 */
121
-	public function defineSortableAttributes()
122
-	{
123
-		if (craft()->config->get('useEmailAsUsername'))
124
-		{
125
-			// Start with Email and don't even give Username as an option
126
-			$attributes = array(
127
-				'email' => Craft::t('Email'),
128
-			);
129
-		}
130
-		else
131
-		{
132
-			$attributes = array(
133
-				'username' => Craft::t('Username'),
134
-				'email'    => Craft::t('Email'),
135
-			);
136
-		}
137
-
138
-		$attributes['firstName']     = Craft::t('First Name');
139
-		$attributes['lastName']      = Craft::t('Last Name');
140
-
141
-		$attributes['providerHandle'] = Craft::t('Login Provider');
142
-		$attributes['socialUid']     = Craft::t('Social User ID');
143
-
144
-		$attributes['userId']        = Craft::t('User ID');
145
-		$attributes['lastLoginDate'] = Craft::t('Last Login');
146
-		$attributes['dateCreated']   = Craft::t('Date Created');
147
-		$attributes['dateUpdated']   = Craft::t('Date Updated');
148
-
149
-		// Allow plugins to modify the attributes
150
-		craft()->plugins->call('modifyLoginAccountSortableAttributes', array(&$attributes));
151
-
152
-		return $attributes;
153
-	}
154
-
155
-	/**
156
-	 * Defines all of the available columns that can be shown in table views.
157
-	 *
158
-	 * @return array
159
-	 */
160
-	public function defineAvailableTableAttributes()
161
-	{
162
-		if (craft()->config->get('useEmailAsUsername'))
163
-		{
164
-			// Start with Email and don't even give Username as an option
165
-			$attributes = array(
166
-				'email' => array('label' => Craft::t('Email')),
167
-			);
168
-		}
169
-		else
170
-		{
171
-			$attributes = array(
172
-				'username' => array('label' => Craft::t('Username')),
173
-				'email'    => array('label' => Craft::t('Email')),
174
-			);
175
-		}
176
-
177
-		$attributes['fullName'] = array('label' => Craft::t('Full Name'));
178
-		$attributes['firstName'] = array('label' => Craft::t('First Name'));
179
-		$attributes['lastName'] = array('label' => Craft::t('Last Name'));
180
-
181
-		$attributes['providerHandle'] = array('label' => Craft::t('Login Provider'));
182
-		$attributes['socialUid']     = array('label' => Craft::t('Social User ID'));
183
-
184
-		$attributes['userId']        = array('label' => Craft::t('User ID'));
185
-		$attributes['lastLoginDate'] = array('label' => Craft::t('Last Login'));
186
-		$attributes['dateCreated']   = array('label' => Craft::t('Date Created'));
187
-		$attributes['dateUpdated']   = array('label' => Craft::t('Date Updated'));
188
-
189
-		// Allow plugins to modify the attributes
190
-		$pluginAttributes = craft()->plugins->call('defineAdditionalLoginAccountTableAttributes', array(), true);
191
-
192
-		foreach ($pluginAttributes as $thisPluginAttributes)
193
-		{
194
-			$attributes = array_merge($attributes, $thisPluginAttributes);
195
-		}
196
-
197
-		return $attributes;
198
-	}
199
-
200
-	/**
201
-	 * Returns the list of table attribute keys that should be shown by default.
202
-	 *
203
-	 * @param string|null $source
204
-	 *
205
-	 * @return array
206
-	 */
207
-	public function getDefaultTableAttributes($source = null)
208
-	{
209
-		return array('username', 'fullName', 'providerHandle', 'socialUid', 'lastLoginDate');
210
-	}
211
-
212
-	/**
213
-	 * Returns the HTML that should be shown for a given element’s attribute in Table View.
214
-	 *
215
-	 * @param BaseElementModel $element
216
-	 * @param string           $attribute
217
-	 *
218
-	 * @return string
219
-	 */
220
-	public function getTableAttributeHtml(BaseElementModel $element, $attribute)
221
-	{
222
-		// First give plugins a chance to set this
223
-		$pluginAttributeHtml = craft()->plugins->callFirst('getLoginAccountTableAttributeHtml', array($element, $attribute), true);
224
-
225
-		if ($pluginAttributeHtml !== null)
226
-		{
227
-			return $pluginAttributeHtml;
228
-		}
229
-
230
-		switch ($attribute)
231
-		{
232
-			case 'providerHandle':
233
-			{
234
-				// TODO:consider eager loading the provider
235
-				$provider = craft()->oauth->getProvider($element->providerHandle);
236
-
237
-				if ($provider)
238
-				{
239
-					$html = '<div class="provider">' .
240
-						'<div class="thumb"><img src="'.$provider->getIconUrl().'" width="32" height="32" /></div>' .
241
-						'<div class="label">'.$provider->getName().'</div>' .
242
-						'</div>';
243
-
244
-					return $html;
245
-				}
246
-				else
247
-				{
248
-					return '';
249
-				}
250
-			}
251
-
252
-			default:
253
-			{
254
-				return parent::getTableAttributeHtml($element, $attribute);
255
-			}
256
-		}
257
-	}
258
-
259
-	/**
260
-	 * Defines any custom element criteria attributes for this element type.
261
-	 *
262
-	 * @return array
263
-	 */
264
-	public function defineCriteriaAttributes()
265
-	{
266
-		return array(
267
-			'userId' => AttributeType::Number,
268
-			'providerHandle' => AttributeType::String,
269
-			'socialUid' => AttributeType::String,
270
-
271
-			'username' => AttributeType::String,
272
-			'email' => AttributeType::String,
273
-			'firstName' => AttributeType::String,
274
-			'lastName' => AttributeType::String,
275
-			'lastLoginDate' => AttributeType::DateTime,
276
-		);
277
-	}
278
-
279
-	/**
280
-	 * Modifies an element query targeting elements of this type.
281
-	 *
282
-	 * @param DbCommand            $query
283
-	 * @param ElementCriteriaModel $criteria
284
-	 *
285
-	 * @return null|false
286
-	 */
287
-	public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria)
288
-	{
289
-		$query->addSelect('
6
+    /**
7
+     * Returns the element type name.
8
+     *
9
+     * @return string
10
+     */
11
+    public function getName()
12
+    {
13
+        return Craft::t('Login Accounts');
14
+    }
15
+
16
+    /**
17
+     * Returns the element index HTML.
18
+     *
19
+     * @param ElementCriteriaModel $criteria
20
+     * @param array                $disabledElementIds
21
+     * @param array                $viewState
22
+     * @param string|null          $sourceKey
23
+     * @param string|null          $context
24
+     * @param bool                 $includeContainer
25
+     * @param bool                 $showCheckboxes
26
+     *
27
+     * @return string
28
+     */
29
+    public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes)
30
+    {
31
+        craft()->templates->includeJsResource('social/js/social.js');
32
+
33
+        return parent::getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes);
34
+    }
35
+
36
+    /**
37
+     * Returns this element type's sources.
38
+     *
39
+     * @param string|null $context
40
+     *
41
+     * @return array|false
42
+     */
43
+    public function getSources($context = null)
44
+    {
45
+        $sources = array(
46
+            '*' => array(
47
+                'label' => Craft::t('All login providers'),
48
+                'hasThumbs' => false
49
+            )
50
+        );
51
+
52
+        $loginProviders = craft()->social_loginProviders->getLoginProviders();
53
+
54
+        if ($loginProviders)
55
+        {
56
+            $sources[] = array('heading' => Craft::t('Login Providers'));
57
+
58
+            foreach ($loginProviders as $loginProvider)
59
+            {
60
+                $providerHandle = $loginProvider->getHandle();
61
+                $key = 'group:'.$providerHandle;
62
+
63
+                $sources[$key] = array(
64
+                    'label'     => Craft::t($loginProvider->getName()),
65
+                    'criteria'  => array('providerHandle' => $providerHandle),
66
+                    'hasThumbs' => false
67
+                );
68
+            }
69
+        }
70
+
71
+        // Allow plugins to modify the sources
72
+        craft()->plugins->call('modifyLoginAccountSources', array(&$sources, $context));
73
+
74
+        return $sources;
75
+    }
76
+
77
+    /**
78
+     * Returns the available element actions for a given source (if one is provided).
79
+     *
80
+     * @param string|null $source
81
+     *
82
+     * @return array|null
83
+     */
84
+    public function getAvailableActions($source = null)
85
+    {
86
+        $actions = array();
87
+
88
+        $deleteAction = craft()->elements->getAction('Delete');
89
+        $deleteAction->setParams(array(
90
+            'confirmationMessage' => Craft::t('Are you sure you want to delete the selected login accounts?'),
91
+            'successMessage'      => Craft::t('Login accounts deleted.'),
92
+        ));
93
+        $actions[] = $deleteAction;
94
+
95
+        // Allow plugins to add additional actions
96
+        $allPluginActions = craft()->plugins->call('addLoginAccountActions', array($source), true);
97
+
98
+        foreach ($allPluginActions as $pluginActions)
99
+        {
100
+            $actions = array_merge($actions, $pluginActions);
101
+        }
102
+
103
+        return $actions;
104
+    }
105
+
106
+    /**
107
+     * Defines which element model attributes should be searchable.
108
+     *
109
+     * @return array
110
+     */
111
+    public function defineSearchableAttributes()
112
+    {
113
+        return array('username', 'email', 'firstName', 'lastName', 'fullName', 'providerHandle', 'socialUid', 'userId');
114
+    }
115
+
116
+    /**
117
+     * Defines the attributes that elements can be sorted by.
118
+     *
119
+     * @return array
120
+     */
121
+    public function defineSortableAttributes()
122
+    {
123
+        if (craft()->config->get('useEmailAsUsername'))
124
+        {
125
+            // Start with Email and don't even give Username as an option
126
+            $attributes = array(
127
+                'email' => Craft::t('Email'),
128
+            );
129
+        }
130
+        else
131
+        {
132
+            $attributes = array(
133
+                'username' => Craft::t('Username'),
134
+                'email'    => Craft::t('Email'),
135
+            );
136
+        }
137
+
138
+        $attributes['firstName']     = Craft::t('First Name');
139
+        $attributes['lastName']      = Craft::t('Last Name');
140
+
141
+        $attributes['providerHandle'] = Craft::t('Login Provider');
142
+        $attributes['socialUid']     = Craft::t('Social User ID');
143
+
144
+        $attributes['userId']        = Craft::t('User ID');
145
+        $attributes['lastLoginDate'] = Craft::t('Last Login');
146
+        $attributes['dateCreated']   = Craft::t('Date Created');
147
+        $attributes['dateUpdated']   = Craft::t('Date Updated');
148
+
149
+        // Allow plugins to modify the attributes
150
+        craft()->plugins->call('modifyLoginAccountSortableAttributes', array(&$attributes));
151
+
152
+        return $attributes;
153
+    }
154
+
155
+    /**
156
+     * Defines all of the available columns that can be shown in table views.
157
+     *
158
+     * @return array
159
+     */
160
+    public function defineAvailableTableAttributes()
161
+    {
162
+        if (craft()->config->get('useEmailAsUsername'))
163
+        {
164
+            // Start with Email and don't even give Username as an option
165
+            $attributes = array(
166
+                'email' => array('label' => Craft::t('Email')),
167
+            );
168
+        }
169
+        else
170
+        {
171
+            $attributes = array(
172
+                'username' => array('label' => Craft::t('Username')),
173
+                'email'    => array('label' => Craft::t('Email')),
174
+            );
175
+        }
176
+
177
+        $attributes['fullName'] = array('label' => Craft::t('Full Name'));
178
+        $attributes['firstName'] = array('label' => Craft::t('First Name'));
179
+        $attributes['lastName'] = array('label' => Craft::t('Last Name'));
180
+
181
+        $attributes['providerHandle'] = array('label' => Craft::t('Login Provider'));
182
+        $attributes['socialUid']     = array('label' => Craft::t('Social User ID'));
183
+
184
+        $attributes['userId']        = array('label' => Craft::t('User ID'));
185
+        $attributes['lastLoginDate'] = array('label' => Craft::t('Last Login'));
186
+        $attributes['dateCreated']   = array('label' => Craft::t('Date Created'));
187
+        $attributes['dateUpdated']   = array('label' => Craft::t('Date Updated'));
188
+
189
+        // Allow plugins to modify the attributes
190
+        $pluginAttributes = craft()->plugins->call('defineAdditionalLoginAccountTableAttributes', array(), true);
191
+
192
+        foreach ($pluginAttributes as $thisPluginAttributes)
193
+        {
194
+            $attributes = array_merge($attributes, $thisPluginAttributes);
195
+        }
196
+
197
+        return $attributes;
198
+    }
199
+
200
+    /**
201
+     * Returns the list of table attribute keys that should be shown by default.
202
+     *
203
+     * @param string|null $source
204
+     *
205
+     * @return array
206
+     */
207
+    public function getDefaultTableAttributes($source = null)
208
+    {
209
+        return array('username', 'fullName', 'providerHandle', 'socialUid', 'lastLoginDate');
210
+    }
211
+
212
+    /**
213
+     * Returns the HTML that should be shown for a given element’s attribute in Table View.
214
+     *
215
+     * @param BaseElementModel $element
216
+     * @param string           $attribute
217
+     *
218
+     * @return string
219
+     */
220
+    public function getTableAttributeHtml(BaseElementModel $element, $attribute)
221
+    {
222
+        // First give plugins a chance to set this
223
+        $pluginAttributeHtml = craft()->plugins->callFirst('getLoginAccountTableAttributeHtml', array($element, $attribute), true);
224
+
225
+        if ($pluginAttributeHtml !== null)
226
+        {
227
+            return $pluginAttributeHtml;
228
+        }
229
+
230
+        switch ($attribute)
231
+        {
232
+            case 'providerHandle':
233
+            {
234
+                // TODO:consider eager loading the provider
235
+                $provider = craft()->oauth->getProvider($element->providerHandle);
236
+
237
+                if ($provider)
238
+                {
239
+                    $html = '<div class="provider">' .
240
+                        '<div class="thumb"><img src="'.$provider->getIconUrl().'" width="32" height="32" /></div>' .
241
+                        '<div class="label">'.$provider->getName().'</div>' .
242
+                        '</div>';
243
+
244
+                    return $html;
245
+                }
246
+                else
247
+                {
248
+                    return '';
249
+                }
250
+            }
251
+
252
+            default:
253
+            {
254
+                return parent::getTableAttributeHtml($element, $attribute);
255
+            }
256
+        }
257
+    }
258
+
259
+    /**
260
+     * Defines any custom element criteria attributes for this element type.
261
+     *
262
+     * @return array
263
+     */
264
+    public function defineCriteriaAttributes()
265
+    {
266
+        return array(
267
+            'userId' => AttributeType::Number,
268
+            'providerHandle' => AttributeType::String,
269
+            'socialUid' => AttributeType::String,
270
+
271
+            'username' => AttributeType::String,
272
+            'email' => AttributeType::String,
273
+            'firstName' => AttributeType::String,
274
+            'lastName' => AttributeType::String,
275
+            'lastLoginDate' => AttributeType::DateTime,
276
+        );
277
+    }
278
+
279
+    /**
280
+     * Modifies an element query targeting elements of this type.
281
+     *
282
+     * @param DbCommand            $query
283
+     * @param ElementCriteriaModel $criteria
284
+     *
285
+     * @return null|false
286
+     */
287
+    public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria)
288
+    {
289
+        $query->addSelect('
290 290
 			login_accounts.id,
291 291
 			login_accounts.userId,
292 292
 			login_accounts.providerHandle,
@@ -299,59 +299,59 @@  discard block
 block discarded – undo
299 299
 			users.lastLoginDate,
300 300
 		');
301 301
 
302
-		$query->join('social_login_accounts login_accounts', 'login_accounts.id = elements.id');
303
-		$query->leftJoin('users users', 'login_accounts.userId = users.id');
304
-
305
-		if ($criteria->userId)
306
-		{
307
-			$query->andWhere(DbHelper::parseParam('login_accounts.userId', $criteria->userId, $query->params));
308
-		}
309
-
310
-		if ($criteria->providerHandle)
311
-		{
312
-			$query->andWhere(DbHelper::parseParam('login_accounts.providerHandle', $criteria->providerHandle, $query->params));
313
-		}
314
-
315
-		if ($criteria->socialUid)
316
-		{
317
-			$query->andWhere(DbHelper::parseParam('login_accounts.socialUid', $criteria->socialUid, $query->params));
318
-		}
319
-
320
-		if ($criteria->username)
321
-		{
322
-			$query->andWhere(DbHelper::parseParam('users.username', $criteria->username, $query->params));
323
-		}
324
-
325
-		if ($criteria->firstName)
326
-		{
327
-			$query->andWhere(DbHelper::parseParam('users.firstName', $criteria->firstName, $query->params));
328
-		}
329
-
330
-		if ($criteria->lastName)
331
-		{
332
-			$query->andWhere(DbHelper::parseParam('users.lastName', $criteria->lastName, $query->params));
333
-		}
334
-
335
-		if ($criteria->email)
336
-		{
337
-			$query->andWhere(DbHelper::parseParam('users.email', $criteria->email, $query->params));
338
-		}
339
-
340
-		if ($criteria->lastLoginDate)
341
-		{
342
-			$query->andWhere(DbHelper::parseDateParam('users.lastLoginDate', $criteria->lastLoginDate, $query->params));
343
-		}
344
-	}
345
-
346
-	/**
347
-	 * Populates an element model based on a query result.
348
-	 *
349
-	 * @param array $row
350
-	 *
351
-	 * @return Social_LoginAccountModel
352
-	 */
353
-	public function populateElementModel($row)
354
-	{
355
-		return Social_LoginAccountModel::populateModel($row);
356
-	}
302
+        $query->join('social_login_accounts login_accounts', 'login_accounts.id = elements.id');
303
+        $query->leftJoin('users users', 'login_accounts.userId = users.id');
304
+
305
+        if ($criteria->userId)
306
+        {
307
+            $query->andWhere(DbHelper::parseParam('login_accounts.userId', $criteria->userId, $query->params));
308
+        }
309
+
310
+        if ($criteria->providerHandle)
311
+        {
312
+            $query->andWhere(DbHelper::parseParam('login_accounts.providerHandle', $criteria->providerHandle, $query->params));
313
+        }
314
+
315
+        if ($criteria->socialUid)
316
+        {
317
+            $query->andWhere(DbHelper::parseParam('login_accounts.socialUid', $criteria->socialUid, $query->params));
318
+        }
319
+
320
+        if ($criteria->username)
321
+        {
322
+            $query->andWhere(DbHelper::parseParam('users.username', $criteria->username, $query->params));
323
+        }
324
+
325
+        if ($criteria->firstName)
326
+        {
327
+            $query->andWhere(DbHelper::parseParam('users.firstName', $criteria->firstName, $query->params));
328
+        }
329
+
330
+        if ($criteria->lastName)
331
+        {
332
+            $query->andWhere(DbHelper::parseParam('users.lastName', $criteria->lastName, $query->params));
333
+        }
334
+
335
+        if ($criteria->email)
336
+        {
337
+            $query->andWhere(DbHelper::parseParam('users.email', $criteria->email, $query->params));
338
+        }
339
+
340
+        if ($criteria->lastLoginDate)
341
+        {
342
+            $query->andWhere(DbHelper::parseDateParam('users.lastLoginDate', $criteria->lastLoginDate, $query->params));
343
+        }
344
+    }
345
+
346
+    /**
347
+     * Populates an element model based on a query result.
348
+     *
349
+     * @param array $row
350
+     *
351
+     * @return Social_LoginAccountModel
352
+     */
353
+    public function populateElementModel($row)
354
+    {
355
+        return Social_LoginAccountModel::populateModel($row);
356
+    }
357 357
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -236,9 +236,9 @@
 block discarded – undo
236 236
 
237 237
 				if ($provider)
238 238
 				{
239
-					$html = '<div class="provider">' .
240
-						'<div class="thumb"><img src="'.$provider->getIconUrl().'" width="32" height="32" /></div>' .
241
-						'<div class="label">'.$provider->getName().'</div>' .
239
+					$html = '<div class="provider">'.
240
+						'<div class="thumb"><img src="'.$provider->getIconUrl().'" width="32" height="32" /></div>'.
241
+						'<div class="label">'.$provider->getName().'</div>'.
242 242
 						'</div>';
243 243
 
244 244
 					return $html;
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -126,8 +126,7 @@  discard block
 block discarded – undo
126 126
 			$attributes = array(
127 127
 				'email' => Craft::t('Email'),
128 128
 			);
129
-		}
130
-		else
129
+		} else
131 130
 		{
132 131
 			$attributes = array(
133 132
 				'username' => Craft::t('Username'),
@@ -165,8 +164,7 @@  discard block
 block discarded – undo
165 164
 			$attributes = array(
166 165
 				'email' => array('label' => Craft::t('Email')),
167 166
 			);
168
-		}
169
-		else
167
+		} else
170 168
 		{
171 169
 			$attributes = array(
172 170
 				'username' => array('label' => Craft::t('Username')),
@@ -242,8 +240,7 @@  discard block
 block discarded – undo
242 240
 						'</div>';
243 241
 
244 242
 					return $html;
245
-				}
246
-				else
243
+				} else
247 244
 				{
248 245
 					return '';
249 246
 				}
Please login to merge, or discard this patch.
base/SocialTrait.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
      */
20 20
     public function checkPluginRequirements()
21 21
     {
22
-        if($this->areDependenciesMissing())
22
+        if ($this->areDependenciesMissing())
23 23
         {
24 24
             throw new Exception("Social is not configured properly. Check Social settings for more informations.");
25 25
         }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     {
67 67
         $missingDependencies = $this->getMissingDependencies();
68 68
 
69
-        if(count($missingDependencies) > 0)
69
+        if (count($missingDependencies) > 0)
70 70
         {
71 71
             return true;
72 72
         }
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
         $plugin = craft()->plugins->getPlugin('social');
87 87
         $plugins = $plugin->getRequiredPlugins();
88 88
 
89
-        foreach($plugins as $key => $plugin)
89
+        foreach ($plugins as $key => $plugin)
90 90
         {
91 91
             $dependency = $this->getPluginDependency($plugin);
92 92
 
93
-            if($missingOnly)
93
+            if ($missingOnly)
94 94
             {
95
-                if($dependency['isMissing'])
95
+                if ($dependency['isMissing'])
96 96
                 {
97 97
                     $dependencies[] = $dependency;
98 98
                 }
@@ -118,16 +118,16 @@  discard block
 block discarded – undo
118 118
 
119 119
         $plugin = craft()->plugins->getPlugin($dependency['handle'], false);
120 120
 
121
-        if($plugin)
121
+        if ($plugin)
122 122
         {
123 123
             $currentVersion = $plugin->version;
124 124
 
125 125
 
126 126
             // requires update ?
127 127
 
128
-            if(version_compare($currentVersion, $dependency['version']) >= 0)
128
+            if (version_compare($currentVersion, $dependency['version']) >= 0)
129 129
             {
130
-                if($plugin->isInstalled && $plugin->isEnabled)
130
+                if ($plugin->isInstalled && $plugin->isEnabled)
131 131
                 {
132 132
                     $isMissing = false;
133 133
                 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -37,8 +37,7 @@  discard block
 block discarded – undo
37 37
             $url = UrlHelper::getUrl('social/install');
38 38
             craft()->request->redirect($url);
39 39
             return false;
40
-        }
41
-        else
40
+        } else
42 41
         {
43 42
             return true;
44 43
         }
@@ -96,8 +95,7 @@  discard block
 block discarded – undo
96 95
                 {
97 96
                     $dependencies[] = $dependency;
98 97
                 }
99
-            }
100
-            else
98
+            } else
101 99
             {
102 100
                 $dependencies[] = $dependency;
103 101
             }
Please login to merge, or discard this patch.