Skip to content

Commit 81368c4

Browse files
authored
Merge pull request #39 from RRZE-Webteam/dev
Dev
2 parents c270c86 + 30133e3 commit 81368c4

File tree

3 files changed

+136
-121
lines changed

3 files changed

+136
-121
lines changed

includes/Authenticate.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ public function authenticate($user, $userLogin)
103103
// The entityID of the IdP the user is authenticated against.
104104
$samlSpIdp = $this->authSimple->getAuthData('saml:sp:IdP');
105105

106-
// Get the IdP Metadata.
107-
$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
108-
$idpMetadata = $metadata->getMetaData($samlSpIdp, 'saml20-idp-remote');
109-
$locale = get_locale();
110-
$lang = substr($locale, 0, 2);
111-
$idpName = $idpMetadata['name'][$lang] ?? $idpMetadata['name']['en'] ?? '';
112-
113106
// Retrieve the attributes of the current user.
114107
// If the user isn't authenticated, an empty array will be returned.
115108
if (empty($_atts = $this->authSimple->getAttributes())) {
@@ -167,11 +160,11 @@ public function authenticate($user, $userLogin)
167160
$userLogin = $userLogin ?: explode('@', $subjectId)[0];
168161

169162
$found = false;
170-
foreach (array_keys($identityProviders) as $key) {
171-
$key = sanitize_title($key);
172-
$domainScope = $this->options->domain_scope[$key] ?? '';
163+
foreach (array_keys($identityProviders) as $idpName) {
164+
$idpName = sanitize_title($idpName);
165+
$domainScope = $this->options->domain_scope[$idpName] ?? '';
173166
$domainScope = $domainScope ? '@' . $domainScope : $domainScope;
174-
if (sanitize_title($samlSpIdp) == $key) {
167+
if (sanitize_title($samlSpIdp) == $idpName) {
175168
$found = true;
176169
$userLogin = $userLogin . $domainScope;
177170
break;

includes/Plugin.php

+50-40
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ class Plugin
3131
protected $url;
3232

3333
/**
34-
* The version of the plugin.
35-
* @var string
34+
* The data of the plugin.
35+
* @var array
3636
*/
37-
protected $version;
37+
protected $data;
3838

3939
/**
40-
* __construct method
40+
* Constructor.
4141
* @param string $pluginFile The full path and filename of the plugin.
4242
*/
4343
public function __construct(string $pluginFile)
4444
{
4545
$this->pluginFile = $pluginFile;
46+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
4647
}
4748

4849
/**
@@ -53,11 +54,10 @@ public function loaded()
5354
$this->setBasename()
5455
->setDirectory()
5556
->setUrl()
56-
->setVersion();
57+
->setData();
5758
}
5859

5960
/**
60-
* getFile method
6161
* Get the full path and filename of the plugin.
6262
* @return string The full path and filename.
6363
*/
@@ -67,7 +67,6 @@ public function getFile(): string
6767
}
6868

6969
/**
70-
* getBasename method
7170
* Get the basename of the plugin.
7271
* @return string The basename.
7372
*/
@@ -77,7 +76,6 @@ public function getBasename(): string
7776
}
7877

7978
/**
80-
* setBasename method
8179
* Set the basename of the plugin.
8280
* @return object This Plugin object.
8381
*/
@@ -88,7 +86,6 @@ public function setBasename(): object
8886
}
8987

9088
/**
91-
* getDirectory method
9289
* Get the filesystem directory path (with trailing slash) for the plugin.
9390
* @return string The filesystem directory path.
9491
*/
@@ -98,29 +95,26 @@ public function getDirectory(): string
9895
}
9996

10097
/**
101-
* setDirectory method
10298
* Set the filesystem directory path (with trailing slash) for the plugin.
10399
* @return object This Plugin object.
104100
*/
105101
public function setDirectory(): object
106102
{
107-
$this->directory = rtrim(plugin_dir_path($this->pluginFile), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
103+
$this->directory = rtrim(plugin_dir_path($this->pluginFile), '/') . '/';
108104
return $this;
109105
}
110106

111107
/**
112-
* getPath method
113108
* Get the filesystem directory path (with trailing slash) for the plugin.
114109
* @param string $path The path name.
115110
* @return string The filesystem directory path.
116111
*/
117112
public function getPath(string $path = ''): string
118113
{
119-
return $this->directory . ($path ? trim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : '');
114+
return $this->directory . ($path ? trim($path, '/') . '/' : '');
120115
}
121116

122117
/**
123-
* getUrl method
124118
* Get the URL directory path (with trailing slash) for the plugin.
125119
* @param string $path The path name.
126120
* @return string The URL directory path.
@@ -131,7 +125,6 @@ public function getUrl(string $path = ''): string
131125
}
132126

133127
/**
134-
* setUrl method
135128
* Set the URL directory path (with trailing slash) for the plugin.
136129
* @return object This Plugin object.
137130
*/
@@ -142,7 +135,6 @@ public function setUrl(): object
142135
}
143136

144137
/**
145-
* getSlug method
146138
* Get the slug of the plugin.
147139
* @return string The slug.
148140
*/
@@ -152,31 +144,58 @@ public function getSlug(): string
152144
}
153145

154146
/**
155-
* getVersion method
147+
* Set the data of the plugin.
148+
* @return object This Plugin object.
149+
*/
150+
public function setData(): object
151+
{
152+
$this->data = get_plugin_data($this->pluginFile, false, false);
153+
return $this;
154+
}
155+
156+
/**
157+
* Get the data of the plugin.
158+
* @return array The data.
159+
*/
160+
public function getData(): array
161+
{
162+
return $this->data;
163+
}
164+
165+
/**
166+
* Get the name of the plugin.
167+
* @return string The name.
168+
*/
169+
public function getName(): string
170+
{
171+
return $this->data['Name'];
172+
}
173+
174+
/**
156175
* Get the version of the plugin.
157176
* @return string The version.
158177
*/
159178
public function getVersion(): string
160179
{
161-
if (defined('WP_DEBUG') && WP_DEBUG) {
162-
return bin2hex(random_bytes(4));
163-
}
164-
return $this->version;
180+
return $this->data['Version'];
165181
}
166182

167183
/**
168-
* getVersion method
169-
* Set the version of the plugin.
170-
* @return object This Plugin object.
184+
* Get the required WordPress version of the plugin.
185+
* @return string The required WordPress version.
171186
*/
172-
public function setVersion(): object
187+
public function getRequiresWP(): string
173188
{
174-
$headers = ['Version' => 'Version'];
175-
$fileData = get_file_data($this->pluginFile, $headers, 'plugin');
176-
if (isset($fileData['Version'])) {
177-
$this->version = $fileData['Version'];
178-
};
179-
return $this;
189+
return $this->data['RequiresWP'];
190+
}
191+
192+
/**
193+
* Get the required PHP version of the plugin.
194+
* @return string The required PHP version.
195+
*/
196+
public function getRequiresPHP(): string
197+
{
198+
return $this->data['RequiresPHP'];
180199
}
181200

182201
/**
@@ -187,15 +206,6 @@ public function __call(string $name, array $arguments)
187206
{
188207
if (!method_exists($this, $name)) {
189208
$message = sprintf('Call to undefined method %1$s::%2$s', __CLASS__, $name);
190-
do_action(
191-
'rrze.log.error',
192-
$message,
193-
[
194-
'class' => __CLASS__,
195-
'method' => $name,
196-
'arguments' => $arguments
197-
]
198-
);
199209
if (defined('WP_DEBUG') && WP_DEBUG) {
200210
throw new \Exception($message);
201211
}

0 commit comments

Comments
 (0)