@@ -27,46 +27,46 @@ |
||
| 27 | 27 | |
| 28 | 28 | class MailApi { |
| 29 | 29 | |
| 30 | - public static function sendPlainMail ($to, string $subject, string $message, array $options = array(), string $from = "", string $reply_to = "") : bool { |
|
| 31 | - if (!Settings::get("send_mails_enabled", true)) { |
|
| 32 | - //send mails is not enabled |
|
| 33 | - return false; |
|
| 34 | - } |
|
| 30 | + public static function sendPlainMail ($to, string $subject, string $message, array $options = array(), string $from = "", string $reply_to = "") : bool { |
|
| 31 | + if (!Settings::get("send_mails_enabled", true)) { |
|
| 32 | + //send mails is not enabled |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - return self::getClass()->sendPlainMail($to, $subject, $message, $options, $from, $reply_to); |
|
| 37 | - } |
|
| 36 | + return self::getClass()->sendPlainMail($to, $subject, $message, $options, $from, $reply_to); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public static function sendHTMLMail ($to, string $subject, string $message, array $options = array(), string $from = "", string $reply_to = "") : bool { |
|
| 40 | - if (!Settings::get("send_mails_enabled", true)) { |
|
| 41 | - //send mails is not enabled |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 39 | + public static function sendHTMLMail ($to, string $subject, string $message, array $options = array(), string $from = "", string $reply_to = "") : bool { |
|
| 40 | + if (!Settings::get("send_mails_enabled", true)) { |
|
| 41 | + //send mails is not enabled |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return self::getClass()->sendHTMLMail($to, $subject, $message, $options, $from, $reply_to); |
|
| 46 | - } |
|
| 45 | + return self::getClass()->sendHTMLMail($to, $subject, $message, $options, $from, $reply_to); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - protected static function getClass () : MailSender { |
|
| 49 | - //get setting |
|
| 50 | - $class_name = Settings::get("sendmail_method", "PHPMail"); |
|
| 48 | + protected static function getClass () : MailSender { |
|
| 49 | + //get setting |
|
| 50 | + $class_name = Settings::get("sendmail_method", "PHPMail"); |
|
| 51 | 51 | |
| 52 | - $obj = new $class_name(); |
|
| 52 | + $obj = new $class_name(); |
|
| 53 | 53 | |
| 54 | - if (!($obj instanceof MailSender)) { |
|
| 55 | - throw new IllegalStateException("setting sendmail_method isnt a valide class which implements interface 'MailSender'."); |
|
| 56 | - } |
|
| 54 | + if (!($obj instanceof MailSender)) { |
|
| 55 | + throw new IllegalStateException("setting sendmail_method isnt a valide class which implements interface 'MailSender'."); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return $obj; |
|
| 59 | - } |
|
| 58 | + return $obj; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public static function getSignature () : string { |
|
| 62 | - $signature = Settings::get("mail_signature", ""); |
|
| 61 | + public static function getSignature () : string { |
|
| 62 | + $signature = Settings::get("mail_signature", ""); |
|
| 63 | 63 | |
| 64 | - Events::throwEvent("get_mail_signature", array( |
|
| 65 | - 'signature' => &$signature |
|
| 66 | - )); |
|
| 64 | + Events::throwEvent("get_mail_signature", array( |
|
| 65 | + 'signature' => &$signature |
|
| 66 | + )); |
|
| 67 | 67 | |
| 68 | - return $signature; |
|
| 69 | - } |
|
| 68 | + return $signature; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
@@ -27,296 +27,296 @@ |
||
| 27 | 27 | |
| 28 | 28 | class RegisterPage extends PageType { |
| 29 | 29 | |
| 30 | - public function getAdditionalHeaderCode(): string { |
|
| 31 | - //check, if captcha is enabled |
|
| 32 | - if (!Captcha::isEnabled()) { |
|
| 33 | - return ""; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - //get code between <head> and </head> |
|
| 37 | - return Captcha::getInstance()->getHeader(); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function getContent(): string { |
|
| 41 | - $template = new DwooTemplate("pages/register"); |
|
| 42 | - |
|
| 43 | - $registration_enabled = Settings::get("registration_enabled", false); |
|
| 44 | - |
|
| 45 | - if (!$registration_enabled) { |
|
| 46 | - //registration is not enabled |
|
| 47 | - $template->assign("registration_enabled", false); |
|
| 48 | - } else { |
|
| 49 | - $template->assign("registration_enabled", true); |
|
| 50 | - $template->assign("action_url", DomainUtils::generateURL($this->getPage()->getAlias())); |
|
| 51 | - |
|
| 52 | - $fields = array(); |
|
| 53 | - |
|
| 54 | - //add fields |
|
| 55 | - $fields[] = array( |
|
| 56 | - 'name' => "username", |
|
| 57 | - 'title' => "Username", |
|
| 58 | - 'type' => "text", |
|
| 59 | - 'placeholder' => "Username", |
|
| 60 | - 'required' => true, |
|
| 61 | - 'value' => (isset($_REQUEST['username']) && !empty($_REQUEST['username']) ? str_replace("\"", "", $_REQUEST['username']) : ""), |
|
| 62 | - 'custom_html' => false, |
|
| 63 | - 'text_behind', |
|
| 64 | - 'text_behind' => "", |
|
| 65 | - 'validator' => "Validator_Username" |
|
| 66 | - ); |
|
| 67 | - |
|
| 68 | - $fields[] = array( |
|
| 69 | - 'name' => "mail", |
|
| 70 | - 'title' => "E-Mail", |
|
| 71 | - 'type' => "email", |
|
| 72 | - 'placeholder' => "[email protected]", |
|
| 73 | - 'required' => true, |
|
| 74 | - 'value' => (isset($_REQUEST['mail']) && !empty($_REQUEST['mail']) ? str_replace("\"", "", $_REQUEST['mail']) : ""), |
|
| 75 | - 'custom_html' => false, |
|
| 76 | - 'text_behind' => "", |
|
| 77 | - 'validator' => "Validator_Mail" |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - $fields[] = array( |
|
| 81 | - 'name' => "password", |
|
| 82 | - 'title' => "Password", |
|
| 83 | - 'type' => "password", |
|
| 84 | - 'placeholder' => "Password", |
|
| 85 | - 'required' => true, |
|
| 86 | - 'value' => "", |
|
| 87 | - 'custom_html' => false, |
|
| 88 | - 'text_behind' => "", |
|
| 89 | - 'validator' => "Validator_Password", |
|
| 90 | - 'hints' => "All characters are allowed, min length: 8, max length: 64" |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - $fields[] = array( |
|
| 94 | - 'name' => "password_repeat", |
|
| 95 | - 'title' => "Repeat password", |
|
| 96 | - 'type' => "password", |
|
| 97 | - 'placeholder' => "Password", |
|
| 98 | - 'required' => true, |
|
| 99 | - 'value' => "", |
|
| 100 | - 'custom_html' => false, |
|
| 101 | - 'text_behind' => "", |
|
| 102 | - 'validator' => "Validator_Password", |
|
| 103 | - 'hints' => "All characters are allowed, min length: 8, max length: 64" |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - $fields[] = array( |
|
| 107 | - 'name' => "agb", |
|
| 108 | - 'title' => "Terms of use", |
|
| 109 | - 'type' => "checkbox", |
|
| 110 | - 'placeholder' => "", |
|
| 111 | - 'required' => true, |
|
| 112 | - 'value' => "checked", |
|
| 113 | - 'custom_html' => false, |
|
| 114 | - 'text_behind' => "<br />I have read and agree with the <a href=\"" . DomainUtils::generateURL(Settings::get("agb_page", "agb")) . "\" target=\"_blank\">terms of use</a>", |
|
| 115 | - 'validator' => null |
|
| 116 | - ); |
|
| 117 | - |
|
| 118 | - Events::throwEvent("register_fields", array( |
|
| 119 | - 'fields' => &$fields, |
|
| 120 | - 'template' => &$template |
|
| 121 | - )); |
|
| 122 | - |
|
| 123 | - //array with all validated values of fields |
|
| 124 | - $field_values = array(); |
|
| 125 | - |
|
| 126 | - //add captcha field, if captcha enabled |
|
| 127 | - if (Captcha::isEnabled()) { |
|
| 128 | - $fields[] = array( |
|
| 129 | - 'name' => "captcha", |
|
| 130 | - 'title' => "Captcha", |
|
| 131 | - 'type' => "", |
|
| 132 | - 'placeholder' => "", |
|
| 133 | - 'required' => true, |
|
| 134 | - 'value' => "captcha", |
|
| 135 | - 'custom_html' => "<input type=\"hidden\" name=\"captcha\" value=\"captcha\" />" . Captcha::getInstance()->getFormCode(), |
|
| 136 | - 'validator' => null |
|
| 137 | - ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if (isset($_REQUEST['submit']) && !empty($_REQUEST['submit'])) { |
|
| 141 | - $validate = true; |
|
| 142 | - $error_msg_array = array(); |
|
| 143 | - |
|
| 144 | - //check CSRF token |
|
| 145 | - if (!Security::checkCSRFToken()) { |
|
| 146 | - $validate = false; |
|
| 147 | - $error_msg_array[] = "Wrong CSRF token!"; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - //check fields |
|
| 151 | - foreach ($fields as $field) { |
|
| 152 | - //check, if field is required |
|
| 153 | - if ($field['required']) { |
|
| 154 | - if (!isset($_POST[$field['name']]) || empty($_POST[$field['name']])) { |
|
| 155 | - $validate = false; |
|
| 156 | - $error_msg_array[] = "Field '" . $field['title'] . "' wasnt filled!"; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - //validate fields |
|
| 161 | - if (isset($_POST[$field['name']])) { |
|
| 162 | - $validator = $field['validator']; |
|
| 163 | - |
|
| 164 | - if (!is_null($validator) && !empty($validator)) { |
|
| 165 | - $obj = new $validator; |
|
| 166 | - |
|
| 167 | - if (!$obj->isValide($_POST[$field['name']])) { |
|
| 168 | - $validate = false; |
|
| 169 | - $error_msg_array[] = "Field '" . $field['title'] . "' is not valide! " . (isset($field['hints']) ? $field['hints'] : ""); |
|
| 170 | - } else { |
|
| 171 | - //set validated value |
|
| 172 | - $field_values[$field['name']] = $obj->validate($_POST[$field['name']]); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - //check, if username already exists |
|
| 179 | - if (isset($_POST['username']) && !empty($_POST['username'])) { |
|
| 180 | - $username = $_POST['username']; |
|
| 181 | - |
|
| 182 | - if (User::existsUsername($username)) { |
|
| 183 | - $validate = false; |
|
| 184 | - $error_msg_array[] = "Username '" . htmlentities($_POST['username']) . "' already exists! Choose another username!"; |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - //check, if mail already exists |
|
| 189 | - if (isset($_POST['mail']) && !empty($_POST['mail'])) { |
|
| 190 | - $mail = $_POST['mail']; |
|
| 191 | - |
|
| 192 | - if (User::existsMail($mail)) { |
|
| 193 | - $validate = false; |
|
| 194 | - $error_msg_array[] = "Mail '" . htmlentities($_POST['mail']) . "' already exists in system! Maybe you are already registered? Choose another mail address or login!"; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - //check, if passwords are equals |
|
| 199 | - if (isset($_POST['password']) && isset($_POST['password_repeat']) && !PHPUtils::strEqs($_POST['password'], $_POST['password_repeat'])) { |
|
| 200 | - $validate = false; |
|
| 201 | - $error_msg_array[] = "Repeated password isnt the same!"; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - //check, if agb is checked |
|
| 205 | - if (!isset($_POST['agb']) || $_POST['agb'] !== "checked") { |
|
| 206 | - $validate = false; |
|
| 207 | - $error_msg_array[] = "Please agree to AGB and fillout checkbox!"; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - //check captcha, if enabled |
|
| 211 | - if (Captcha::isEnabled()) { |
|
| 212 | - if (!Captcha::getInstance()->verify()) { |
|
| 213 | - $validate = false; |
|
| 214 | - $error_msg_array[] = "Wrong captcha!"; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - Events::throwEvent("register_validate", array( |
|
| 219 | - 'valide' => &$validate, |
|
| 220 | - 'fields' => &$fields, |
|
| 221 | - 'field_values' => &$field_values, |
|
| 222 | - 'error_msg_array' => &$error_msg_array |
|
| 223 | - )); |
|
| 224 | - |
|
| 225 | - if ($validate) { |
|
| 226 | - $text = ""; |
|
| 227 | - |
|
| 228 | - //get activation method |
|
| 229 | - $activation_method = Settings::get("register_activation_method", "auto"); |
|
| 230 | - |
|
| 231 | - $activated = 2; |
|
| 232 | - |
|
| 233 | - if ($activation_method === "auto") { |
|
| 234 | - $activated = 1; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - //get fields |
|
| 238 | - $username = $field_values['username']; |
|
| 239 | - $password = $_POST['password']; |
|
| 240 | - $mail = $field_values['mail']; |
|
| 241 | - |
|
| 242 | - //get IP address of user |
|
| 243 | - $ip = PHPUtils::getClientIP(); |
|
| 244 | - |
|
| 245 | - $main_group = 2; |
|
| 246 | - |
|
| 247 | - //create new user |
|
| 248 | - $res = User::create($username, $password, $mail, $ip, $main_group, "", $activated); |
|
| 249 | - |
|
| 250 | - if ($res === true || $res['success'] === true) { |
|
| 251 | - //throw event for custom registration fields |
|
| 252 | - Events::throwEvent("register_execute", array( |
|
| 253 | - 'field_values' => $field_values, |
|
| 254 | - 'text' => &$text |
|
| 255 | - )); |
|
| 256 | - |
|
| 257 | - switch ($activation_method) { |
|
| 258 | - case "auto": |
|
| 259 | - //login user automatically |
|
| 260 | - User::current()->loginByID($res['userID']); |
|
| 261 | - |
|
| 262 | - //redirect user to home page |
|
| 263 | - //header("Location: " . DomainUtils::generateURL(Domain::getCurrent()->getHomePage())); |
|
| 264 | - //exit; |
|
| 265 | - |
|
| 266 | - $text .= "You are automatically logged-in now. <a href=\"" . DomainUtils::generateURL(Domain::getCurrent()->getHomePage()) . "\">Homepage</a>"; |
|
| 267 | - |
|
| 268 | - break; |
|
| 269 | - |
|
| 270 | - case "mail_verification": |
|
| 271 | - //send verification mail |
|
| 272 | - Mail_Verification::sendMail($res['userID'], $res['username'], $res['mail']); |
|
| 273 | - |
|
| 274 | - $text .= "Before you can login you have to verify your mail address! For this we have send you a mail with a link, please click on this link!"; |
|
| 275 | - |
|
| 276 | - break; |
|
| 277 | - |
|
| 278 | - case "manual_verification": |
|
| 279 | - |
|
| 280 | - //TODO: inform administrator |
|
| 281 | - |
|
| 282 | - $text .= "An Administrator has to activate your account manually now."; |
|
| 283 | - |
|
| 284 | - break; |
|
| 285 | - |
|
| 286 | - default: |
|
| 287 | - throw new IllegalStateException("Unknown activation method: " . $activation_method); |
|
| 288 | - break; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - $template->assign("error", !$validate); |
|
| 292 | - $template->assign("error_msg_array", $error_msg_array); |
|
| 293 | - $template->assign("success", $validate); |
|
| 294 | - $template->assign("additional_success_text", $text); |
|
| 295 | - } else { |
|
| 296 | - $template->assign("error", true); |
|
| 297 | - $template->assign("error_msg_array", array("Couldnt create user. Please contact the administrator of this website!")); |
|
| 298 | - $template->assign("success", false); |
|
| 299 | - } |
|
| 300 | - } else { |
|
| 301 | - $template->assign("error", !$validate); |
|
| 302 | - $template->assign("error_msg_array", $error_msg_array); |
|
| 303 | - $template->assign("success", $validate); |
|
| 304 | - } |
|
| 305 | - } else { |
|
| 306 | - $template->assign("error", false); |
|
| 307 | - } |
|
| 30 | + public function getAdditionalHeaderCode(): string { |
|
| 31 | + //check, if captcha is enabled |
|
| 32 | + if (!Captcha::isEnabled()) { |
|
| 33 | + return ""; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + //get code between <head> and </head> |
|
| 37 | + return Captcha::getInstance()->getHeader(); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function getContent(): string { |
|
| 41 | + $template = new DwooTemplate("pages/register"); |
|
| 42 | + |
|
| 43 | + $registration_enabled = Settings::get("registration_enabled", false); |
|
| 44 | + |
|
| 45 | + if (!$registration_enabled) { |
|
| 46 | + //registration is not enabled |
|
| 47 | + $template->assign("registration_enabled", false); |
|
| 48 | + } else { |
|
| 49 | + $template->assign("registration_enabled", true); |
|
| 50 | + $template->assign("action_url", DomainUtils::generateURL($this->getPage()->getAlias())); |
|
| 51 | + |
|
| 52 | + $fields = array(); |
|
| 53 | + |
|
| 54 | + //add fields |
|
| 55 | + $fields[] = array( |
|
| 56 | + 'name' => "username", |
|
| 57 | + 'title' => "Username", |
|
| 58 | + 'type' => "text", |
|
| 59 | + 'placeholder' => "Username", |
|
| 60 | + 'required' => true, |
|
| 61 | + 'value' => (isset($_REQUEST['username']) && !empty($_REQUEST['username']) ? str_replace("\"", "", $_REQUEST['username']) : ""), |
|
| 62 | + 'custom_html' => false, |
|
| 63 | + 'text_behind', |
|
| 64 | + 'text_behind' => "", |
|
| 65 | + 'validator' => "Validator_Username" |
|
| 66 | + ); |
|
| 67 | + |
|
| 68 | + $fields[] = array( |
|
| 69 | + 'name' => "mail", |
|
| 70 | + 'title' => "E-Mail", |
|
| 71 | + 'type' => "email", |
|
| 72 | + 'placeholder' => "[email protected]", |
|
| 73 | + 'required' => true, |
|
| 74 | + 'value' => (isset($_REQUEST['mail']) && !empty($_REQUEST['mail']) ? str_replace("\"", "", $_REQUEST['mail']) : ""), |
|
| 75 | + 'custom_html' => false, |
|
| 76 | + 'text_behind' => "", |
|
| 77 | + 'validator' => "Validator_Mail" |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + $fields[] = array( |
|
| 81 | + 'name' => "password", |
|
| 82 | + 'title' => "Password", |
|
| 83 | + 'type' => "password", |
|
| 84 | + 'placeholder' => "Password", |
|
| 85 | + 'required' => true, |
|
| 86 | + 'value' => "", |
|
| 87 | + 'custom_html' => false, |
|
| 88 | + 'text_behind' => "", |
|
| 89 | + 'validator' => "Validator_Password", |
|
| 90 | + 'hints' => "All characters are allowed, min length: 8, max length: 64" |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + $fields[] = array( |
|
| 94 | + 'name' => "password_repeat", |
|
| 95 | + 'title' => "Repeat password", |
|
| 96 | + 'type' => "password", |
|
| 97 | + 'placeholder' => "Password", |
|
| 98 | + 'required' => true, |
|
| 99 | + 'value' => "", |
|
| 100 | + 'custom_html' => false, |
|
| 101 | + 'text_behind' => "", |
|
| 102 | + 'validator' => "Validator_Password", |
|
| 103 | + 'hints' => "All characters are allowed, min length: 8, max length: 64" |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + $fields[] = array( |
|
| 107 | + 'name' => "agb", |
|
| 108 | + 'title' => "Terms of use", |
|
| 109 | + 'type' => "checkbox", |
|
| 110 | + 'placeholder' => "", |
|
| 111 | + 'required' => true, |
|
| 112 | + 'value' => "checked", |
|
| 113 | + 'custom_html' => false, |
|
| 114 | + 'text_behind' => "<br />I have read and agree with the <a href=\"" . DomainUtils::generateURL(Settings::get("agb_page", "agb")) . "\" target=\"_blank\">terms of use</a>", |
|
| 115 | + 'validator' => null |
|
| 116 | + ); |
|
| 117 | + |
|
| 118 | + Events::throwEvent("register_fields", array( |
|
| 119 | + 'fields' => &$fields, |
|
| 120 | + 'template' => &$template |
|
| 121 | + )); |
|
| 122 | + |
|
| 123 | + //array with all validated values of fields |
|
| 124 | + $field_values = array(); |
|
| 125 | + |
|
| 126 | + //add captcha field, if captcha enabled |
|
| 127 | + if (Captcha::isEnabled()) { |
|
| 128 | + $fields[] = array( |
|
| 129 | + 'name' => "captcha", |
|
| 130 | + 'title' => "Captcha", |
|
| 131 | + 'type' => "", |
|
| 132 | + 'placeholder' => "", |
|
| 133 | + 'required' => true, |
|
| 134 | + 'value' => "captcha", |
|
| 135 | + 'custom_html' => "<input type=\"hidden\" name=\"captcha\" value=\"captcha\" />" . Captcha::getInstance()->getFormCode(), |
|
| 136 | + 'validator' => null |
|
| 137 | + ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if (isset($_REQUEST['submit']) && !empty($_REQUEST['submit'])) { |
|
| 141 | + $validate = true; |
|
| 142 | + $error_msg_array = array(); |
|
| 143 | + |
|
| 144 | + //check CSRF token |
|
| 145 | + if (!Security::checkCSRFToken()) { |
|
| 146 | + $validate = false; |
|
| 147 | + $error_msg_array[] = "Wrong CSRF token!"; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + //check fields |
|
| 151 | + foreach ($fields as $field) { |
|
| 152 | + //check, if field is required |
|
| 153 | + if ($field['required']) { |
|
| 154 | + if (!isset($_POST[$field['name']]) || empty($_POST[$field['name']])) { |
|
| 155 | + $validate = false; |
|
| 156 | + $error_msg_array[] = "Field '" . $field['title'] . "' wasnt filled!"; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + //validate fields |
|
| 161 | + if (isset($_POST[$field['name']])) { |
|
| 162 | + $validator = $field['validator']; |
|
| 163 | + |
|
| 164 | + if (!is_null($validator) && !empty($validator)) { |
|
| 165 | + $obj = new $validator; |
|
| 166 | + |
|
| 167 | + if (!$obj->isValide($_POST[$field['name']])) { |
|
| 168 | + $validate = false; |
|
| 169 | + $error_msg_array[] = "Field '" . $field['title'] . "' is not valide! " . (isset($field['hints']) ? $field['hints'] : ""); |
|
| 170 | + } else { |
|
| 171 | + //set validated value |
|
| 172 | + $field_values[$field['name']] = $obj->validate($_POST[$field['name']]); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + //check, if username already exists |
|
| 179 | + if (isset($_POST['username']) && !empty($_POST['username'])) { |
|
| 180 | + $username = $_POST['username']; |
|
| 181 | + |
|
| 182 | + if (User::existsUsername($username)) { |
|
| 183 | + $validate = false; |
|
| 184 | + $error_msg_array[] = "Username '" . htmlentities($_POST['username']) . "' already exists! Choose another username!"; |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + //check, if mail already exists |
|
| 189 | + if (isset($_POST['mail']) && !empty($_POST['mail'])) { |
|
| 190 | + $mail = $_POST['mail']; |
|
| 191 | + |
|
| 192 | + if (User::existsMail($mail)) { |
|
| 193 | + $validate = false; |
|
| 194 | + $error_msg_array[] = "Mail '" . htmlentities($_POST['mail']) . "' already exists in system! Maybe you are already registered? Choose another mail address or login!"; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + //check, if passwords are equals |
|
| 199 | + if (isset($_POST['password']) && isset($_POST['password_repeat']) && !PHPUtils::strEqs($_POST['password'], $_POST['password_repeat'])) { |
|
| 200 | + $validate = false; |
|
| 201 | + $error_msg_array[] = "Repeated password isnt the same!"; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + //check, if agb is checked |
|
| 205 | + if (!isset($_POST['agb']) || $_POST['agb'] !== "checked") { |
|
| 206 | + $validate = false; |
|
| 207 | + $error_msg_array[] = "Please agree to AGB and fillout checkbox!"; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + //check captcha, if enabled |
|
| 211 | + if (Captcha::isEnabled()) { |
|
| 212 | + if (!Captcha::getInstance()->verify()) { |
|
| 213 | + $validate = false; |
|
| 214 | + $error_msg_array[] = "Wrong captcha!"; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + Events::throwEvent("register_validate", array( |
|
| 219 | + 'valide' => &$validate, |
|
| 220 | + 'fields' => &$fields, |
|
| 221 | + 'field_values' => &$field_values, |
|
| 222 | + 'error_msg_array' => &$error_msg_array |
|
| 223 | + )); |
|
| 224 | + |
|
| 225 | + if ($validate) { |
|
| 226 | + $text = ""; |
|
| 227 | + |
|
| 228 | + //get activation method |
|
| 229 | + $activation_method = Settings::get("register_activation_method", "auto"); |
|
| 230 | + |
|
| 231 | + $activated = 2; |
|
| 232 | + |
|
| 233 | + if ($activation_method === "auto") { |
|
| 234 | + $activated = 1; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + //get fields |
|
| 238 | + $username = $field_values['username']; |
|
| 239 | + $password = $_POST['password']; |
|
| 240 | + $mail = $field_values['mail']; |
|
| 241 | + |
|
| 242 | + //get IP address of user |
|
| 243 | + $ip = PHPUtils::getClientIP(); |
|
| 244 | + |
|
| 245 | + $main_group = 2; |
|
| 246 | + |
|
| 247 | + //create new user |
|
| 248 | + $res = User::create($username, $password, $mail, $ip, $main_group, "", $activated); |
|
| 249 | + |
|
| 250 | + if ($res === true || $res['success'] === true) { |
|
| 251 | + //throw event for custom registration fields |
|
| 252 | + Events::throwEvent("register_execute", array( |
|
| 253 | + 'field_values' => $field_values, |
|
| 254 | + 'text' => &$text |
|
| 255 | + )); |
|
| 256 | + |
|
| 257 | + switch ($activation_method) { |
|
| 258 | + case "auto": |
|
| 259 | + //login user automatically |
|
| 260 | + User::current()->loginByID($res['userID']); |
|
| 261 | + |
|
| 262 | + //redirect user to home page |
|
| 263 | + //header("Location: " . DomainUtils::generateURL(Domain::getCurrent()->getHomePage())); |
|
| 264 | + //exit; |
|
| 265 | + |
|
| 266 | + $text .= "You are automatically logged-in now. <a href=\"" . DomainUtils::generateURL(Domain::getCurrent()->getHomePage()) . "\">Homepage</a>"; |
|
| 267 | + |
|
| 268 | + break; |
|
| 269 | + |
|
| 270 | + case "mail_verification": |
|
| 271 | + //send verification mail |
|
| 272 | + Mail_Verification::sendMail($res['userID'], $res['username'], $res['mail']); |
|
| 273 | + |
|
| 274 | + $text .= "Before you can login you have to verify your mail address! For this we have send you a mail with a link, please click on this link!"; |
|
| 275 | + |
|
| 276 | + break; |
|
| 277 | + |
|
| 278 | + case "manual_verification": |
|
| 279 | + |
|
| 280 | + //TODO: inform administrator |
|
| 281 | + |
|
| 282 | + $text .= "An Administrator has to activate your account manually now."; |
|
| 283 | + |
|
| 284 | + break; |
|
| 285 | + |
|
| 286 | + default: |
|
| 287 | + throw new IllegalStateException("Unknown activation method: " . $activation_method); |
|
| 288 | + break; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + $template->assign("error", !$validate); |
|
| 292 | + $template->assign("error_msg_array", $error_msg_array); |
|
| 293 | + $template->assign("success", $validate); |
|
| 294 | + $template->assign("additional_success_text", $text); |
|
| 295 | + } else { |
|
| 296 | + $template->assign("error", true); |
|
| 297 | + $template->assign("error_msg_array", array("Couldnt create user. Please contact the administrator of this website!")); |
|
| 298 | + $template->assign("success", false); |
|
| 299 | + } |
|
| 300 | + } else { |
|
| 301 | + $template->assign("error", !$validate); |
|
| 302 | + $template->assign("error_msg_array", $error_msg_array); |
|
| 303 | + $template->assign("success", $validate); |
|
| 304 | + } |
|
| 305 | + } else { |
|
| 306 | + $template->assign("error", false); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - $template->assign("fields", $fields); |
|
| 309 | + $template->assign("fields", $fields); |
|
| 310 | 310 | |
| 311 | - //TODO: add code here |
|
| 312 | - } |
|
| 311 | + //TODO: add code here |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - return $template->getCode(); |
|
| 315 | - } |
|
| 314 | + return $template->getCode(); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - public function listRequiredPermissions(): array { |
|
| 318 | - return array("not_logged_in"); |
|
| 319 | - } |
|
| 317 | + public function listRequiredPermissions(): array { |
|
| 318 | + return array("not_logged_in"); |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | 321 | } |
| 322 | 322 | |
@@ -27,24 +27,24 @@ |
||
| 27 | 27 | |
| 28 | 28 | class MailVerifyPage extends PageType { |
| 29 | 29 | |
| 30 | - public function getContent(): string { |
|
| 31 | - $template = new DwooTemplate("pages/verifymail"); |
|
| 32 | - |
|
| 33 | - if (isset($_REQUEST['token']) && !empty($_REQUEST['token'])) { |
|
| 34 | - $template->assign("no_token", false); |
|
| 35 | - |
|
| 36 | - //check token |
|
| 37 | - if (!Mail_Verification::checkToken($_REQUEST['token'])) { |
|
| 38 | - $template->assign("invalide_token", true); |
|
| 39 | - } else { |
|
| 40 | - $template->assign("invalide_token", false); |
|
| 41 | - } |
|
| 42 | - } else { |
|
| 43 | - $template->assign("no_token", true); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return $template->getCode(); |
|
| 47 | - } |
|
| 30 | + public function getContent(): string { |
|
| 31 | + $template = new DwooTemplate("pages/verifymail"); |
|
| 32 | + |
|
| 33 | + if (isset($_REQUEST['token']) && !empty($_REQUEST['token'])) { |
|
| 34 | + $template->assign("no_token", false); |
|
| 35 | + |
|
| 36 | + //check token |
|
| 37 | + if (!Mail_Verification::checkToken($_REQUEST['token'])) { |
|
| 38 | + $template->assign("invalide_token", true); |
|
| 39 | + } else { |
|
| 40 | + $template->assign("invalide_token", false); |
|
| 41 | + } |
|
| 42 | + } else { |
|
| 43 | + $template->assign("no_token", true); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return $template->getCode(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
@@ -27,55 +27,55 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Mail_Verification { |
| 29 | 29 | |
| 30 | - public static function sendMail (int $userID, string $username, string $mail) { |
|
| 31 | - //generate token |
|
| 32 | - $token = PHPUtils::randomString(64); |
|
| 30 | + public static function sendMail (int $userID, string $username, string $mail) { |
|
| 31 | + //generate token |
|
| 32 | + $token = PHPUtils::randomString(64); |
|
| 33 | 33 | |
| 34 | - Database::getInstance()->execute("INSERT INTO `{praefix}register_mail_verification` ( |
|
| 34 | + Database::getInstance()->execute("INSERT INTO `{praefix}register_mail_verification` ( |
|
| 35 | 35 | `userID`, `token` |
| 36 | 36 | ) VALUES ( |
| 37 | 37 | :userID, :token |
| 38 | 38 | ) ON DUPLICATE KEY UPDATE `token` = :token; ", array( |
| 39 | - 'userID' => $userID, |
|
| 40 | - 'token' => $token |
|
| 41 | - )); |
|
| 42 | - |
|
| 43 | - //send mail |
|
| 44 | - $template = new DwooTemplate(STORE_PATH . "templates/mail/verify_mail.tpl"); |
|
| 45 | - |
|
| 46 | - //assign variables |
|
| 47 | - $template->assign("token", $token); |
|
| 48 | - $template->assign("userID", $userID); |
|
| 49 | - $template->assign("username", $username); |
|
| 50 | - $template->assign("verify_url", DomainUtils::generateURL("user/verify_mail", array('token' => $token, 'username' => $username))); |
|
| 51 | - $template->assign("base_url", DomainUtils::getBaseURL()); |
|
| 52 | - $template->assign("mail", $mail); |
|
| 53 | - |
|
| 54 | - $message = $template->getCode(); |
|
| 55 | - |
|
| 56 | - //send mail |
|
| 57 | - MailApi::sendHTMLMail($mail, "Mail Verification " . Settings::get("website_name", ""), $message); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public static function checkToken (string $token) : bool { |
|
| 61 | - $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}register_mail_verification` WHERE `token` = :token; ", array('token' => $token)); |
|
| 62 | - |
|
| 63 | - if ($row === false) { |
|
| 64 | - return false; |
|
| 65 | - } else { |
|
| 66 | - //activate user |
|
| 67 | - Database::getInstance()->execute("UPDATE `{praefix}user` SET `activated` = '1' WHERE `userID` = :userID AND `activated` = '2'; ", array('userID' => $row['userID'])); |
|
| 68 | - |
|
| 69 | - //remove token |
|
| 70 | - self::removeToken($token); |
|
| 71 | - |
|
| 72 | - return true; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public static function removeToken (string $token) { |
|
| 77 | - Database::getInstance()->execute("DELETE FROM `{praefix}register_mail_verification` WHERE `token` = :token; ", array('token' => $token)); |
|
| 78 | - } |
|
| 39 | + 'userID' => $userID, |
|
| 40 | + 'token' => $token |
|
| 41 | + )); |
|
| 42 | + |
|
| 43 | + //send mail |
|
| 44 | + $template = new DwooTemplate(STORE_PATH . "templates/mail/verify_mail.tpl"); |
|
| 45 | + |
|
| 46 | + //assign variables |
|
| 47 | + $template->assign("token", $token); |
|
| 48 | + $template->assign("userID", $userID); |
|
| 49 | + $template->assign("username", $username); |
|
| 50 | + $template->assign("verify_url", DomainUtils::generateURL("user/verify_mail", array('token' => $token, 'username' => $username))); |
|
| 51 | + $template->assign("base_url", DomainUtils::getBaseURL()); |
|
| 52 | + $template->assign("mail", $mail); |
|
| 53 | + |
|
| 54 | + $message = $template->getCode(); |
|
| 55 | + |
|
| 56 | + //send mail |
|
| 57 | + MailApi::sendHTMLMail($mail, "Mail Verification " . Settings::get("website_name", ""), $message); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public static function checkToken (string $token) : bool { |
|
| 61 | + $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}register_mail_verification` WHERE `token` = :token; ", array('token' => $token)); |
|
| 62 | + |
|
| 63 | + if ($row === false) { |
|
| 64 | + return false; |
|
| 65 | + } else { |
|
| 66 | + //activate user |
|
| 67 | + Database::getInstance()->execute("UPDATE `{praefix}user` SET `activated` = '1' WHERE `userID` = :userID AND `activated` = '2'; ", array('userID' => $row['userID'])); |
|
| 68 | + |
|
| 69 | + //remove token |
|
| 70 | + self::removeToken($token); |
|
| 71 | + |
|
| 72 | + return true; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public static function removeToken (string $token) { |
|
| 77 | + Database::getInstance()->execute("DELETE FROM `{praefix}register_mail_verification` WHERE `token` = :token; ", array('token' => $token)); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
@@ -33,16 +33,16 @@ |
||
| 33 | 33 | |
| 34 | 34 | class PluginPLang extends Plugin implements ICompilable { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param Compiler $compiler |
|
| 38 | - * @param mixed $value |
|
| 39 | - * @param mixed $var |
|
| 40 | - * |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public static function compile(Compiler $compiler, $msg1, $msg2, $n, $domain = "") { |
|
| 44 | - return 'Translator::n_translate(' . $msg1 . ', ' . $msg2 . ', ' . $n . ', ' . $domain . ')'; |
|
| 45 | - } |
|
| 36 | + /** |
|
| 37 | + * @param Compiler $compiler |
|
| 38 | + * @param mixed $value |
|
| 39 | + * @param mixed $var |
|
| 40 | + * |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public static function compile(Compiler $compiler, $msg1, $msg2, $n, $domain = "") { |
|
| 44 | + return 'Translator::n_translate(' . $msg1 . ', ' . $msg2 . ', ' . $n . ', ' . $domain . ')'; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
@@ -27,41 +27,41 @@ |
||
| 27 | 27 | |
| 28 | 28 | interface Translator_Backend { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * initialize translator backend |
|
| 32 | - * |
|
| 33 | - * @param $lang_token $lang_token contains language & country, e.q. de_DE |
|
| 34 | - */ |
|
| 35 | - public function init (string $lang_token); |
|
| 30 | + /** |
|
| 31 | + * initialize translator backend |
|
| 32 | + * |
|
| 33 | + * @param $lang_token $lang_token contains language & country, e.q. de_DE |
|
| 34 | + */ |
|
| 35 | + public function init (string $lang_token); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * translate a string |
|
| 39 | - * |
|
| 40 | - * @param string $key message to translate |
|
| 41 | - * @param string $domain domain where to search key (optional) |
|
| 42 | - * @param array $params array with params to replace in translated message |
|
| 43 | - * |
|
| 44 | - * @return string translated message |
|
| 45 | - */ |
|
| 46 | - public function translate (string $key, string $domain = "", $params = null) : string; |
|
| 37 | + /** |
|
| 38 | + * translate a string |
|
| 39 | + * |
|
| 40 | + * @param string $key message to translate |
|
| 41 | + * @param string $domain domain where to search key (optional) |
|
| 42 | + * @param array $params array with params to replace in translated message |
|
| 43 | + * |
|
| 44 | + * @return string translated message |
|
| 45 | + */ |
|
| 46 | + public function translate (string $key, string $domain = "", $params = null) : string; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * translate a string, plural version of translate() |
|
| 50 | - * |
|
| 51 | - * @see Translator_Backend::translate() |
|
| 52 | - * @since 0.1.0 |
|
| 53 | - * |
|
| 54 | - * @param string $key message to translate |
|
| 55 | - * @param string $domain domain where to search key (optional) |
|
| 56 | - * @param array $params array with params to replace in translated message |
|
| 57 | - * |
|
| 58 | - * @return string translated message |
|
| 59 | - */ |
|
| 60 | - public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string; |
|
| 48 | + /** |
|
| 49 | + * translate a string, plural version of translate() |
|
| 50 | + * |
|
| 51 | + * @see Translator_Backend::translate() |
|
| 52 | + * @since 0.1.0 |
|
| 53 | + * |
|
| 54 | + * @param string $key message to translate |
|
| 55 | + * @param string $domain domain where to search key (optional) |
|
| 56 | + * @param array $params array with params to replace in translated message |
|
| 57 | + * |
|
| 58 | + * @return string translated message |
|
| 59 | + */ |
|
| 60 | + public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string; |
|
| 61 | 61 | |
| 62 | - public function bindLangPack (string $domain, string $path); |
|
| 62 | + public function bindLangPack (string $domain, string $path); |
|
| 63 | 63 | |
| 64 | - public function setDefaultDomain (string $domain); |
|
| 64 | + public function setDefaultDomain (string $domain); |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | |
@@ -27,73 +27,73 @@ |
||
| 27 | 27 | |
| 28 | 28 | class GetTextBackend implements Translator_Backend { |
| 29 | 29 | |
| 30 | - //current language token |
|
| 31 | - protected $lang_token = ""; |
|
| 32 | - |
|
| 33 | - //current domain |
|
| 34 | - protected $domain = ""; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * initialize translator backend |
|
| 38 | - * |
|
| 39 | - * @param $lang_token $lang_token contains language & country, e.q. de_DE |
|
| 40 | - */ |
|
| 41 | - public function init(string $lang_token) { |
|
| 42 | - //check, if gettext is available |
|
| 43 | - if (!PHPUtils::isGettextAvailable()) { |
|
| 44 | - throw new IllegalStateException("PHP extension 'gettext' is not available."); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - putenv("LANG=" . $lang_token); |
|
| 48 | - setlocale(LC_ALL, $lang_token); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function translate(string $key, string $domain = "", $params = null): string { |
|
| 52 | - $text = ""; |
|
| 53 | - |
|
| 54 | - if (empty($domain)) { |
|
| 55 | - $text = gettext($key); |
|
| 56 | - } else { |
|
| 57 | - $text = dgettext($domain, $key); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if ($params != null && !empty($params)) { |
|
| 61 | - foreach ($params as $key=>$value) { |
|
| 62 | - //replace variables |
|
| 63 | - $text = str_replace("{" . $key . "}", $value, $text); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $text; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 71 | - $text = ""; |
|
| 72 | - |
|
| 73 | - if (empty($domain)) { |
|
| 74 | - $text = ngettext($key, $plural_key, $n); |
|
| 75 | - } else { |
|
| 76 | - $text = dngettext($domain, $key, $plural_key, $n); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ($params != null && !empty($params)) { |
|
| 80 | - foreach ($params as $key=>$value) { |
|
| 81 | - //replace variables |
|
| 82 | - $text = str_replace("{" . $key . "}", $value, $text); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return $text; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function bindLangPack(string $domain, string $path) { |
|
| 90 | - bindtextdomain($domain, $path); |
|
| 91 | - bind_textdomain_codeset($domain, 'UTF-8'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function setDefaultDomain(string $domain) { |
|
| 95 | - textdomain($domain); |
|
| 96 | - } |
|
| 30 | + //current language token |
|
| 31 | + protected $lang_token = ""; |
|
| 32 | + |
|
| 33 | + //current domain |
|
| 34 | + protected $domain = ""; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * initialize translator backend |
|
| 38 | + * |
|
| 39 | + * @param $lang_token $lang_token contains language & country, e.q. de_DE |
|
| 40 | + */ |
|
| 41 | + public function init(string $lang_token) { |
|
| 42 | + //check, if gettext is available |
|
| 43 | + if (!PHPUtils::isGettextAvailable()) { |
|
| 44 | + throw new IllegalStateException("PHP extension 'gettext' is not available."); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + putenv("LANG=" . $lang_token); |
|
| 48 | + setlocale(LC_ALL, $lang_token); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function translate(string $key, string $domain = "", $params = null): string { |
|
| 52 | + $text = ""; |
|
| 53 | + |
|
| 54 | + if (empty($domain)) { |
|
| 55 | + $text = gettext($key); |
|
| 56 | + } else { |
|
| 57 | + $text = dgettext($domain, $key); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if ($params != null && !empty($params)) { |
|
| 61 | + foreach ($params as $key=>$value) { |
|
| 62 | + //replace variables |
|
| 63 | + $text = str_replace("{" . $key . "}", $value, $text); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $text; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 71 | + $text = ""; |
|
| 72 | + |
|
| 73 | + if (empty($domain)) { |
|
| 74 | + $text = ngettext($key, $plural_key, $n); |
|
| 75 | + } else { |
|
| 76 | + $text = dngettext($domain, $key, $plural_key, $n); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ($params != null && !empty($params)) { |
|
| 80 | + foreach ($params as $key=>$value) { |
|
| 81 | + //replace variables |
|
| 82 | + $text = str_replace("{" . $key . "}", $value, $text); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $text; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function bindLangPack(string $domain, string $path) { |
|
| 90 | + bindtextdomain($domain, $path); |
|
| 91 | + bind_textdomain_codeset($domain, 'UTF-8'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function setDefaultDomain(string $domain) { |
|
| 95 | + textdomain($domain); |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | ?> |
@@ -27,12 +27,12 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | class PHPInfoPage extends PageType { |
| 29 | 29 | |
| 30 | - public function getContent(): string { |
|
| 31 | - if (isset($_REQUEST['no_design'])) { |
|
| 32 | - phpinfo(); |
|
| 33 | - exit; |
|
| 34 | - } else { |
|
| 35 | - /*$content = ""; |
|
| 30 | + public function getContent(): string { |
|
| 31 | + if (isset($_REQUEST['no_design'])) { |
|
| 32 | + phpinfo(); |
|
| 33 | + exit; |
|
| 34 | + } else { |
|
| 35 | + /*$content = ""; |
|
| 36 | 36 | |
| 37 | 37 | ob_start(); |
| 38 | 38 | phpinfo(); |
@@ -41,25 +41,25 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | return $content;*/ |
| 43 | 43 | |
| 44 | - //https://github.com/Froxlor/Froxlor/blob/5437fcdc898cb505348b89c5a3d09a16e29f67d2/admin_settings.php |
|
| 44 | + //https://github.com/Froxlor/Froxlor/blob/5437fcdc898cb505348b89c5a3d09a16e29f67d2/admin_settings.php |
|
| 45 | 45 | |
| 46 | - //show iframe |
|
| 47 | - return $this->generateNormalPage(" <iframe src=\"" . DomainUtils::generateURL("admin/phpinfo") . "?no_design=true\" style=\"width: 100%; min-height: 800px; \"></iframe> "); |
|
| 48 | - } |
|
| 49 | - } |
|
| 46 | + //show iframe |
|
| 47 | + return $this->generateNormalPage(" <iframe src=\"" . DomainUtils::generateURL("admin/phpinfo") . "?no_design=true\" style=\"width: 100%; min-height: 800px; \"></iframe> "); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function setCustomHeader() { |
|
| 52 | - //allow iframe |
|
| 53 | - header('X-Frame-Options: SAMEORIGIN'); |
|
| 54 | - } |
|
| 51 | + public function setCustomHeader() { |
|
| 52 | + //allow iframe |
|
| 53 | + header('X-Frame-Options: SAMEORIGIN'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function showDesign() { |
|
| 57 | - return !isset($_REQUEST['no_design']); |
|
| 58 | - } |
|
| 56 | + public function showDesign() { |
|
| 57 | + return !isset($_REQUEST['no_design']); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function listRequiredPermissions(): array { |
|
| 61 | - return array("can_see_phpinfo"); |
|
| 62 | - } |
|
| 60 | + public function listRequiredPermissions(): array { |
|
| 61 | + return array("can_see_phpinfo"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
@@ -29,15 +29,15 @@ |
||
| 29 | 29 | |
| 30 | 30 | class DwooAutoloader { |
| 31 | 31 | |
| 32 | - public static function loadClass (string $class_name) { |
|
| 33 | - $class_name = str_replace("\\", "/", $class_name); |
|
| 34 | - |
|
| 35 | - if (file_exists(DWOO_PATH . $class_name . ".php")) { |
|
| 36 | - require(DWOO_PATH . $class_name . ".php"); |
|
| 37 | - } else { |
|
| 38 | - //echo "Cannot load Dwoo Template Engine class '" . $class_name . "' (search path: " . DWOO_PATH . $class_name . ".php)!"; |
|
| 39 | - } |
|
| 40 | - } |
|
| 32 | + public static function loadClass (string $class_name) { |
|
| 33 | + $class_name = str_replace("\\", "/", $class_name); |
|
| 34 | + |
|
| 35 | + if (file_exists(DWOO_PATH . $class_name . ".php")) { |
|
| 36 | + require(DWOO_PATH . $class_name . ".php"); |
|
| 37 | + } else { |
|
| 38 | + //echo "Cannot load Dwoo Template Engine class '" . $class_name . "' (search path: " . DWOO_PATH . $class_name . ".php)!"; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | |