Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require_once "abstract_signup_class.php";
class SignupMethods {
private $signup_methods = [];
function __construct() {
$this->signup_methods = $this->loadSignupMethods();
}
public function getSignupMethods() {
return $this->signup_methods;
}
/**
* @return array of assoc_arrays with name, desc and contribs
*/
public function getSignupMethodsBaseInfo() {
$tmp = [];
foreach($this->signup_methods as $method) {
array_push($tmp, [
"name" => $method["class"]::getName(),
"description" => $method["class"]::getAltText(),
"contributors" => $method["class"]::getMetaInfo()
]);
}
return $tmp;
}
/**
* @return class (instantiated) of the active signup method
* @throws ErrorException when $_GET["method"] is missing or not available in the list
*/
public function getActiveMethod() {
if(!isset($_GET["method"])) throw new ErrorException("No signup-method selected!");
$mode = $_GET["method"];
if(!isset($this->signup_methods[$mode])) throw new ErrorException("Signup-method does not exist!");
return new $this->signup_methods->$mode->class();
}
private function getMethodDirs() {
return glob(__DIR__ . '/*' , GLOB_ONLYDIR);
}
private function loadSignupMethod($folder_name) {
$tmp_file_name = __DIR__ . '/' . $folder_name . '/index.php';
try {
if (file_exists($tmp_file_name)) {
require_once $tmp_file_name;
$tmp_class_name = ucfirst($folder_name . 'SignupMethod');
if (class_exists($tmp_class_name)) {
return [
'class' => $tmp_class_name,
'classFile' => $tmp_file_name
];
}
}
} catch (Exception $e) { /* do nothing */ }
return false;
}
private function loadSignupMethods() {
$tmp_method_dirs = $this->getMethodDirs();
$tmp_methods = [];
foreach ($tmp_method_dirs as $method_dir) {
$tmp_method = $this->loadSignupMethod($method_dir);
if ($tmp_method) $tmp_methods[$method_dir] = $tmp_method;
}
return $tmp_methods;
}
}