Пример #1
0
 public function register_hook()
 {
     $hook = hook();
     $hook->add('UserRegister_Register_before', function ($code) {
         if ($code === 0 && !allowed_register()) {
             return -11;
         }
         return $code;
     });
     switch (site_mode()) {
         case "https":
             if (!is_ssl()) {
                 header("Cache-Control: no-cache, must-revalidate");
                 header("Pragma: no-cache");
                 redirect("https://" . substr(URL_NOW, 6), "header", 301);
             }
             $hook->add('get_url', function () {
                 return site_url_ssl();
             });
             $hook->add("get_file_url", function () {
                 return site_static_url_ssl();
             });
             break;
         case "all":
             if (is_ssl()) {
                 $hook->add('get_url', function () {
                     return site_url_ssl();
                 });
                 $hook->add("get_file_url", function () {
                     return site_static_url_ssl();
                 });
             } else {
                 $hook->add('get_url', function () {
                     return site_url();
                 });
                 $hook->add("get_file_url", function () {
                     return site_static_url();
                 });
             }
             break;
         default:
             if (is_ssl()) {
                 header("Cache-Control: no-cache, must-revalidate");
                 header("Pragma: no-cache");
                 redirect("http://" . substr(URL_NOW, 7), "header", 301);
             }
             $hook->add('get_url', function () {
                 return site_url();
             });
             $hook->add("get_file_url", function () {
                 return site_static_url();
             });
     }
     $hook->add("UserRegister_CodeMsg", function ($msg, $code) {
         if ($code == -11) {
             return _("User register already closed.");
         }
         return $msg;
     });
     if (!login_captcha()) {
         //将验证码检测返回TRUE
         $hook->add("UserLogin_Captcha", function () {
             return true;
         });
     }
     if (email_notice()) {
         $hook->add('UserRegister_Register_success', function ($user_id) {
             lib()->load('MailTemplate');
             $user = User::getUser($user_id);
             $mt = new MailTemplate("new_user_registered.html");
             $mt->setUserInfo($user->getInfo());
             $mt->mailSend(site_title() . " Manager", admin_email());
         });
     }
     if (strtolower(default_avatar_config()) == "gravatar") {
         $hook->add("Avatar_convert", function ($avatar) {
             if (strtolower($avatar) == "{default}") {
                 return "{gravatar}";
             }
             return $avatar;
         });
     }
 }