@@ -249,5 +249,48 @@ public function get_matching_dns_record($domain, $match) {
249
249
}
250
250
return '' ;
251
251
}
252
+
253
+ /**
254
+ * Gets the selector suffix
255
+ * @param string $domain check specific domain
256
+ * @return string suffix
257
+ */
258
+ public function get_selector_suffix ($ domain = '' ) {
259
+ GLOBAL $ CFG ;
260
+
261
+ if (empty ($ domain )) {
262
+ $ url = new \moodle_url ($ CFG ->wwwroot );
263
+ $ domain = $ url ->get_host ();
264
+ }
265
+
266
+ // Determine the suffix based on the LMS domain and noreply domain.
267
+ $ primarydomain = $ this ->get_primary_domain ($ domain );
268
+ $ noreplydomain = $ this ->get_noreply_domain ();
269
+ if ($ primarydomain == $ noreplydomain ) {
270
+ // Noreply domain is same as primary domain, add all LMS subdomains.
271
+ $ suffix = $ this ->get_subdomains ($ domain );
272
+ } else if (str_contains ($ domain , '. ' . $ noreplydomain )) {
273
+ // Noreply domain includes part of the LMS subdomain, only add different subdomains.
274
+ $ suffix = str_replace ('. ' . $ noreplydomain , '' , $ domain );
275
+ } else if (str_contains ($ noreplydomain , '. ' . $ domain )) {
276
+ // Noreply domain is a subdomain of LMS, domain already has all info.
277
+ $ suffix = '' ;
278
+ } else if (str_contains ($ noreplydomain , '. ' . $ primarydomain )) {
279
+ // Noreply domain is a different subdomain of primary domain, add all LMS subdomains.
280
+ $ suffix = $ this ->get_subdomains ($ domain );
281
+ } else {
282
+ // Noreply domain shares nothing in common with LMS, add entire LMS domain.
283
+ $ suffix = $ domain ;
284
+ }
285
+
286
+ // Clean the suffix to remove www and foreign language chars, and convert '.' to '-'.
287
+ // Email filter is enough because domains don't contain the other allowed chars.
288
+ $ suffix = ltrim ($ suffix , 'www. ' );
289
+ $ suffix = trim (filter_var ($ suffix , FILTER_SANITIZE_EMAIL ), '. ' );
290
+ $ suffix = str_replace ('. ' , '- ' , $ suffix );
291
+
292
+ return $ suffix ;
293
+ }
294
+
252
295
}
253
296
0 commit comments