Localized registration errors and activation/COPPA e-mails
authorDan
Tue, 22 Jan 2008 01:08:15 -0500
changeset 370 b251818286b1
parent 369 d0825e599853
child 371 dc6026376919
Localized registration errors and activation/COPPA e-mails
includes/sessions.php
includes/template.php
language/english/core.json
language/english/user.json
--- a/includes/sessions.php	Tue Jan 22 00:38:19 2008 -0500
+++ b/includes/sessions.php	Tue Jan 22 01:08:15 2008 -0500
@@ -1688,6 +1688,7 @@
   function create_user($username, $password, $email, $real_name = '', $coppa = false)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
+    global $lang;
     
     // Initialize AES
     $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE);
@@ -1698,7 +1699,7 @@
       return 'Invalid IP';
     
     if ( !preg_match('#^'.$this->valid_username.'$#', $username) )
-      return 'The username you chose contains invalid characters.';
+      return $lang->get('user_reg_err_username_banned_chars');
     
     $username = str_replace('_', ' ', $username);
     $user_orig = $username;
@@ -1710,31 +1711,23 @@
     $q = $this->sql('SELECT * FROM '.table_prefix.'users WHERE ' . ENANO_SQLFUNC_LOWERCASE . '(username)=\''.strtolower($username).'\' OR email=\''.$email.'\''.$nameclause.';');
     if($db->numrows() > 0)
     {
-      $r = 'The ';
-      $i=0;
       $row = $db->fetchrow();
-      // Wow! An error checker that actually speaks English with the properest grammar! :-P
+      $str = 'user_reg_err_dupe';
+      
       if ( $row['username'] == $username )
       {
-        $r .= 'username';
-        $i++;
+        $str .= '_username';
       }
       if ( $row['email'] == $email )
       {
-        if($i) $r.=', ';
-        $r .= 'e-mail address';
-        $i++;
+        $str .= '_email';
       }
       if ( $row['real_name'] == $real_name && $real_name != '' )
       {
-        if($i) $r.=', and ';
-        $r .= 'real name';
-        $i++;
+        $str .= '_realname';
       }
-      $r .= ' that you entered ';
-      $r .= ( $i == 1 ) ? 'is' : 'are';
-      $r .= ' already in use by another user.';
-      return $r;
+      
+      return $lang->get($r);
     }
     
     // Is the password strong enough?
@@ -1744,7 +1737,7 @@
       $pass_score = password_score($password);
       if ( $pass_score < $min_score )
       {
-        return 'The password you entered did not meet the complexity requirements for this site. Please choose a stronger password.';
+        return $lang->get('user_reg_err_password_too_weak');
       }
     }
     
@@ -1828,7 +1821,7 @@
           if(!$a)
           {
             $this->admin_activation_request($username);
-            return 'The activation e-mail could not be sent due to an internal error. This could possibly be due to an incorrect SMTP configuration. A request has been sent to the administrator to activate your account for you. ' . $a;
+            return $lang->get('user_reg_err_actmail_failed') . ' ' . $a;
           }
           break;
         case 'admin':
@@ -1857,6 +1850,7 @@
   function send_activation_mail($u, $actkey = false)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
+    global $lang;
     $q = $this->sql('SELECT username,email FROM '.table_prefix.'users WHERE user_id=2 OR user_level=' . USER_LEVEL_ADMIN . ' ORDER BY user_id ASC;');
     $un = $db->fetchrow();
     $admin_user = $un['username'];
@@ -1864,32 +1858,22 @@
     $r = $db->fetchrow();
     if ( empty($r['email']) )
       $db->_die('BUG: $session->send_activation_mail(): no e-mail address in row');
-    $message = 'Dear '.$u.',
-Thank you for registering on '.getConfig('site_name').'. Your account creation is almost complete. To complete the registration process, please click the following link or paste it into your web browser:
     
-';
-    if(isset($_SERVER['HTTPS'])) $prot = 'https';
-    else $prot = 'http';                                                                           
-    if($_SERVER['SERVER_PORT'] == '80') $p = '';
-    else $p = ':'.$_SERVER['SERVER_PORT'];
-    $sidbak = false;
-    if($this->sid_super)
-      $sidbak = $this->sid_super;
-    $this->sid_super = false;
-    $aklink = makeUrlNS('Special', 'ActivateAccount/'.str_replace(' ', '_', $u).'/'. ( ( is_string($actkey) ) ? $actkey : $r['activation_key'] ) );
-    if($sidbak)
-      $this->sid_super = $sidbak;
-    unset($sidbak);
-    $message .= "$prot://".$_SERVER['HTTP_HOST'].$p.$aklink;
-      $message .= "\n\nSincerely yours, \n$admin_user and the ".$_SERVER['HTTP_HOST']." administration team";
+    $aklink = makeUrlComplete('Special', 'ActivateAccount/'.str_replace(' ', '_', $u).'/'. ( ( is_string($actkey) ) ? $actkey : $r['activation_key'] ) );
+    $message = $lang->get('user_reg_activation_email', array(
+        'activation_link' => $aklink,
+        'admin_user' => $admin_user,
+        'username' => $u
+      ));
+      
     error_reporting(E_ALL);
     if(getConfig('smtp_enabled') == '1')
     {
-      $result = smtp_send_email($r['email'], getConfig('site_name').' website account activation', preg_replace("#(?<!\r)\n#s", "\n", $message), getConfig('contact_email'));
+      $result = smtp_send_email($r['email'], $lang->get('user_reg_activation_email_subject'), preg_replace("#(?<!\r)\n#s", "\n", $message), getConfig('contact_email'));
       if($result == 'success') $result = true;
       else { echo $result; $result = false; }
     } else {
-      $result = mail($r['email'], getConfig('site_name').' website account activation', preg_replace("#(?<!\r)\n#s", "\n", $message), 'From: '.getConfig('contact_email'));
+      $result = mail($r['email'], $lang->get('user_reg_activation_email_subject'), preg_replace("#(?<!\r)\n#s", "\n", $message), 'From: '.getConfig('contact_email'));
     }
     return $result;
   }
@@ -1902,8 +1886,8 @@
    
   function send_coppa_mail($u, $actkey = false)
   {
-    
     global $db, $session, $paths, $template, $plugins; // Common objects
+    global $lang;
     
     $q = $this->sql('SELECT username,email FROM '.table_prefix.'users WHERE user_id=2 OR user_level=' . USER_LEVEL_ADMIN . ' ORDER BY user_id ASC;');
     $un = $db->fetchrow();
@@ -1927,33 +1911,14 @@
     unset($sidbak);
     $link = "$prot://".$_SERVER['HTTP_HOST'].scriptPath;
     
-    $message = 'Dear parent or legal guardian,
-A child under the username ' . $u . ' recently registered on our website. The child provided your e-mail address as the one of his or her authorized parent or legal guardian, and to comply with the United States Childrens\' Online Privacy Protection act, we ask that all parents of children ages 13 or under please mail us a written form authorizing their child\'s use of our website.
-
-If you wish for your child to be allowed access to our website, please print and fill out the form below, and mail it to this address:
-
-' . getConfig('coppa_address') . '
-
-If you do NOT wish for your child to be allowed access to our site, you do not need to do anything - your child will not be able to access our site as a registered user unless you authorize their account activation.
-
-Authorization form:
--------------------------------- Cut here --------------------------------
-
-I, _______________________________________, the legal parent or guardian of the child registered on the website "' . getConfig('site_name') . '" as ' . $u . ', hereby give my authorization for the child\'s e-mail address, instant messaging information, location, and real name, to be collected and stored in a database owned and maintained by ' . getConfig('site_name') . ' at the child\'s option, and for the administrators of this website to use this information according to the privacy policy displayed on their website <' . $link . '>.
-
-Child\'s name:               _____________________________________
-
-Child\'s e-mail address:     _____________________________________
-(optional - if you don\'t provide this, we\'ll just send site-related e-mails to your e-mail address)
-
-Signature of parent or guardian:
-
-____________________________________________________
-
-Date (YYYY-MM-DD): ______ / _____ / _____
-
--------------------------------- Cut here --------------------------------';
-    $message .= "\n\nSincerely yours, \n$admin_user and the ".$_SERVER['HTTP_HOST']." administration team";
+    $message = $lang->get(
+        'user_reg_activation_email_coppa',
+        array(
+          'username' => $u,
+          'admin_user' => $admin_user,
+          'site_link' => $link
+        )
+      );
     
     error_reporting(E_ALL);
     
--- a/includes/template.php	Tue Jan 22 00:38:19 2008 -0500
+++ b/includes/template.php	Tue Jan 22 01:08:15 2008 -0500
@@ -1576,25 +1576,28 @@
   
   function tinymce_textarea($name, $content = '', $rows = 20, $cols = 60)
   {
+    global $lang;
     $randomid = md5(microtime() . mt_rand());
     $html = '';
     $html .= '<textarea name="' . $name . '" rows="'.$rows.'" cols="'.$cols.'" style="width: 100%;" id="toggleMCEroot_'.$randomid.'">' . $content . '</textarea>';
-    $html .= '<div style="float: right; display: table;" id="mceSwitchAgent_' . $randomid . '">text editor&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" onclick="if ( !KILL_SWITCH ) { toggleMCE_'.$randomid.'(); return false; }">graphical editor</a></div>';
+    $html .= '<div style="float: right; display: table;" id="mceSwitchAgent_' . $randomid . '">' . $lang->get('etc_tinymce_btn_text') . '&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" onclick="if ( !KILL_SWITCH ) { toggleMCE_'.$randomid.'(); return false; }">' . $lang->get('etc_tinymce_btn_graphical') . '</a></div>';
     $html .= '<script type="text/javascript">
                 // <![CDATA[
                 function toggleMCE_'.$randomid.'()
                 {
                   var the_obj = document.getElementById(\'toggleMCEroot_' . $randomid . '\');
                   var panel = document.getElementById(\'mceSwitchAgent_' . $randomid . '\');
+                  var text_editor = $lang.get("etc_tinymce_btn_text");
+                  var graphical_editor = $lang.get("etc_tinymce_btn_graphical");
                   if ( the_obj.dnIsMCE == "yes" )
                   {
                     $dynano(the_obj).destroyMCE();
-                    panel.innerHTML = \'text editor&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" onclick="if ( !KILL_SWITCH ) { toggleMCE_'.$randomid.'(); return false; }">graphical editor</a>\';
+                    panel.innerHTML = text_editor + \'&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" onclick="if ( !KILL_SWITCH ) { toggleMCE_'.$randomid.'(); return false; }">\' + graphical_editor + \'</a>\';
                   }
                   else
                   {
                     $dynano(the_obj).switchToMCE();
-                    panel.innerHTML = \'<a href="#" onclick="if ( !KILL_SWITCH ) { toggleMCE_'.$randomid.'(); return false; }">text editor</a>&nbsp;&nbsp;|&nbsp;&nbsp;graphical editor\';
+                    panel.innerHTML = \'<a href="#" onclick="if ( !KILL_SWITCH ) { toggleMCE_'.$randomid.'(); return false; }">\' + text_editor + \'</a>&nbsp;&nbsp;|&nbsp;&nbsp;\' + graphical_editor;
                   }
                 }
                 // ]]>
--- a/language/english/core.json	Tue Jan 22 00:38:19 2008 -0500
+++ b/language/english/core.json	Tue Jan 22 01:08:15 2008 -0500
@@ -509,6 +509,9 @@
       wizard_next: 'Next >',
       wizard_back: '< Back',
       wizard_previous: '< Previous',
+      // Generic switchable editor buttons
+      tinymce_btn_text: 'text editor',
+      tinymce_btn_graphical: 'graphical editor',
       // Generic "Notice:" label
       lbl_notice: 'Notice:',
       // Generic "Access denied"
--- a/language/english/user.json	Tue Jan 22 00:38:19 2008 -0500
+++ b/language/english/user.json	Tue Jan 22 01:08:15 2008 -0500
@@ -95,6 +95,15 @@
       reg_err_alert_password_nomatch: 'The passwords you entered do not match.',
       reg_err_missing_key: 'Couldn\'t look up public encryption key',
       reg_err_accept_tou: 'Please read and accept the Terms of Use before creating your account.',
+      reg_err_username_banned_chars: 'The username you chose contains invalid characters.',
+      reg_err_dupe_username: 'The username you selected is already in use by another user.',
+      reg_err_dupe_username_email: 'The username and e-mail address you selected are already in use by another user.',
+      reg_err_dupe_username_email_realname: 'The username, e-mail address, and real name you selected are already in use by another user.',
+      reg_err_dupe_email: 'The e-mail address you selected is already in use by another user.',
+      reg_err_dupe_email_realname: 'The e-mail address and real name you selected are already in use by another user.',
+      reg_err_dupe_realname: 'The real name you selected is already in use by another user.',
+      reg_err_password_too_weak: 'The password you entered did not meet the complexity requirements for this site. Please choose a stronger password.',
+      reg_err_actmail_failed: 'The activation e-mail could not be sent due to an internal error. This could possibly be due to an incorrect SMTP configuration. A request has been sent to the administrator to activate your account for you.',
       
       reg_msg_greatercontrol: 'A user account enables you to have greater control over your browsing experience.',
       reg_msg_table_title: 'Create a user account',
@@ -133,6 +142,45 @@
       reg_coppa_link_atleast13: 'I was born <b>on or before</b> %yo13_date% and am <b>at least</b> 13 years of age',
       reg_coppa_link_not13: 'I was born <b>after</b> %yo13_date% and am <b>less than</b> 13 years of age',
       
+      reg_activation_email_subject: '%config.site_name% website account activation',
+      reg_activation_email: 'Dear %username%,
+Thank you for registering on %config.site_name%. Your account creation is almost complete. To complete the registration process, please click the following link or paste it into your web browser:
+
+  %activation_link%
+  
+Sincerely yours,
+%admin_user% and the %config.site_name% administration team',
+
+      reg_activation_email_coppa: 'Dear parent or legal guardian,
+A child under the username %username% recently registered on our website. The child provided your e-mail address as the one of his or her authorized parent or legal guardian, and to comply with the United States Childrens\' Online Privacy Protection act, we ask that all parents of children ages 13 or under please mail us a written form authorizing their child\'s use of our website.
+
+If you wish for your child to be allowed access to our website, please print and fill out the form below, and mail it to this address:
+
+%config.coppa_address%
+
+If you do NOT wish for your child to be allowed access to our site, you do not need to do anything - your child will not be able to access our site as a registered user unless you authorize their account activation.
+
+Authorization form:
+-------------------------------- Cut here --------------------------------
+
+I, _______________________________________, the legal parent or guardian of the child registered on the website "%config.site_name%" as %username%, hereby give my authorization for the child\'s e-mail address, instant messaging information, location, and real name, to be collected and stored in a database owned and maintained by %config.site_name% at the child\'s option, and for the administrators of this website to use this information according to the privacy policy displayed on their website <%site_link%>.
+
+Child\'s name:               _____________________________________
+
+Child\'s e-mail address:     _____________________________________
+(optional - if you don\'t provide this, we\'ll just send site-related e-mails to your e-mail address)
+
+Signature of parent or guardian:
+
+____________________________________________________
+
+Date (YYYY-MM-DD): ______ / _____ / _____
+
+-------------------------------- Cut here --------------------------------
+
+Sincerely yours,
+%admin_user% and the %config.site_name% administration team',
+      
       autofill_heading_suggestions: 'Username suggestions',
       autofill_msg_no_suggestions: 'No suggestions',
     },