Re-merge changes from a2hosting dev
authorDan
Sat, 12 Dec 2009 15:44:36 -0500
changeset 1160 c0e0a1787a63
parent 1157 e154e8176700 (current diff)
parent 1159 a1cca4472a58 (diff)
child 1161 9c0c519066ac
Re-merge changes from a2hosting dev
includes/sessions.php
--- a/includes/functions.php	Fri Dec 11 17:11:47 2009 -0500
+++ b/includes/functions.php	Sat Dec 12 15:44:36 2009 -0500
@@ -348,10 +348,34 @@
   
   // are we in DST?
   global $dst_params;
+  $dst_offset = 0;
   if ( check_timestamp_dst($timestamp, $dst_params[0], $dst_params[1], $dst_params[2], $dst_params[3]) )
   {
     // offset for DST
     $timestamp += ( $dst_params[4] * 60 );
+    $dst_offset = $dst_params[4];
+  }
+  
+  // Does this date string include a timezone? If so, gmdate() will report UTC, which is wrong
+  // FIXME This is kind of a halfass replacement...
+  foreach ( array('e', 'T', 'O', 'P') as $char )
+  {
+    if ( ($pos = strpos($string, $char)) !== false )
+    {
+      if ( $string{ $pos - 1 } != '\\' )
+      {
+        // add in our own timezone string
+        // FIXME: l10n? (do we need to? does anyone really not know what "GMT" means? even uglier escaping?)
+        $tzi = '\\G\\M\\T';
+        $tzo = $timezone + $dst_offset;
+        $sign = $tzo > 0 ? '+' : '-';
+        $tzi .= $sign . (intval(abs($tzo / 60)));
+        if ( $tzo % 60 )
+          $tzi .= sprintf(":%02d", abs($tzo) % 60);
+        
+        $string = substr($string, 0, $pos) . $tzi . substr($string, $pos + 1);
+      }
+    }
   }
   
   // Let PHP do the work for us =)
--- a/includes/sessions.php	Fri Dec 11 17:11:47 2009 -0500
+++ b/includes/sessions.php	Sat Dec 12 15:44:36 2009 -0500
@@ -3488,10 +3488,11 @@
   /**
    * For the given code ID, returns the correct CAPTCHA code, or false on failure
    * @param string $hash The unique ID assigned to the code
+   * @param bool If true, the code is NOT deleted from the database. Use with caution!
    * @return string The correct confirmation code
    */
   
-  function get_captcha($hash)
+  function get_captcha($hash, $nodelete = false)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     
@@ -3517,7 +3518,10 @@
     list($code_id, $code) = $db->fetchrow_num();
     
     $db->free_result();
-    $this->sql('DELETE FROM ' . table_prefix . "captcha WHERE code_id = $code_id;");
+    
+    // delete it
+    if ( !$nodelete )
+      $this->sql('DELETE FROM ' . table_prefix . "captcha WHERE code_id = $code_id;");
     
     return $code;
   }
--- a/install/schemas/mysql_stage2.sql	Fri Dec 11 17:11:47 2009 -0500
+++ b/install/schemas/mysql_stage2.sql	Sat Dec 12 15:44:36 2009 -0500
@@ -116,7 +116,7 @@
   user_registration_ip varchar(39),
   user_rank int(12) UNSIGNED DEFAULT NULL,
   user_rank_userset tinyint(1) NOT NULL DEFAULT 0,
-  user_timezone int(12) UNSIGNED NOT NULL DEFAULT 0,
+  user_timezone int(12) UNSIGNED NOT NULL DEFAULT 1440,
   user_title varchar(64) DEFAULT NULL,
   user_group mediumint(5) NOT NULL DEFAULT 1,
   user_dst varchar(11) NOT NULL DEFAULT '0;0;0;0;60',
--- a/install/schemas/postgresql_stage2.sql	Fri Dec 11 17:11:47 2009 -0500
+++ b/install/schemas/postgresql_stage2.sql	Sat Dec 12 15:44:36 2009 -0500
@@ -116,7 +116,7 @@
   user_registration_ip varchar(39),
   user_rank int DEFAULT NULL,
   user_rank_userset smallint NOT NULL DEFAULT 0,
-  user_timezone int NOT NULL DEFAULT 0,
+  user_timezone int NOT NULL DEFAULT 1440,
   user_title varchar(64) DEFAULT NULL,
   user_group int NOT NULL DEFAULT 1,
   user_dst varchar(11) NOT NULL DEFAULT '0;0;0;0;60',
--- a/install/schemas/upgrade/1.1.1-1.1.2-mysql.sql	Fri Dec 11 17:11:47 2009 -0500
+++ b/install/schemas/upgrade/1.1.1-1.1.2-mysql.sql	Sat Dec 12 15:44:36 2009 -0500
@@ -5,7 +5,7 @@
 ALTER TABLE {{TABLE_PREFIX}}logs ADD COLUMN is_draft tinyint(1) NOT NULL DEFAULT 0;
 
 ALTER TABLE {{TABLE_PREFIX}}users ADD COLUMN user_rank int(12) UNSIGNED NOT NULL DEFAULT 1;
-ALTER TABLE {{TABLE_PREFIX}}users ADD COLUMN user_timezone int(12) UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE {{TABLE_PREFIX}}users ADD COLUMN user_timezone int(12) UNSIGNED NOT NULL DEFAULT 1440;
 
 @ALTER TABLE {{TABLE_PREFIX}}tags CHANGE user user_id mediumint(8) NOT NULL DEFAULT 1;
 ALTER TABLE {{TABLE_PREFIX}}themes
--- a/install/schemas/upgrade/1.1.1-1.1.2-postgresql.sql	Fri Dec 11 17:11:47 2009 -0500
+++ b/install/schemas/upgrade/1.1.1-1.1.2-postgresql.sql	Sat Dec 12 15:44:36 2009 -0500
@@ -6,7 +6,7 @@
 
 ALTER TABLE {{TABLE_PREFIX}}users ADD COLUMN user_rank int NOT NULL DEFAULT 1;
 @ALTER TABLE {{TABLE_PREFIX}}users DROP user_timezone;
-ALTER TABLE {{TABLE_PREFIX}}users ADD COLUMN user_timezone int NOT NULL DEFAULT 0;
+ALTER TABLE {{TABLE_PREFIX}}users ADD COLUMN user_timezone int NOT NULL DEFAULT 1440;
 
 ALTER TABLE {{TABLE_PREFIX}}themes
   ADD COLUMN group_list text DEFAULT NULL,
--- a/plugins/SpecialUserFuncs.php	Fri Dec 11 17:11:47 2009 -0500
+++ b/plugins/SpecialUserFuncs.php	Sat Dec 12 15:44:36 2009 -0500
@@ -817,10 +817,10 @@
                 </small>
               </td>
               <td class="row1">
-                <img id="captchaimg" alt="CAPTCHA image" src="<?php echo makeUrlNS('Special', 'Captcha/'.$captchacode); ?>" /><br />
-                <span id="b_username"></span>
+                <img id="captchaimg" alt="CAPTCHA image" src="<?php echo makeUrlNS('Special', 'Captcha/'.$captchacode); ?>" style="cursor: pointer;" onclick="regenCaptcha(); return false;" />
               </td>
               <td class="row1">
+                <img alt="Good/bad icon" src="<?php echo scriptPath; ?>/images/checkbad.png" id="s_captcha" />
               </td>
             </tr>
             
@@ -828,7 +828,8 @@
             <tr>
               <td class="row1" colspan="2">
                 <?php echo $lang->get('user_reg_lbl_field_captcha_code'); ?>
-                <input tabindex="6" name="captchacode" type="text" size="10" />
+                <input tabindex="6" name="captchacode" type="text" size="10" onkeyup="validateCaptcha(this);" />
+                <img id="captchaajax" width="16" height="16" src="<?php echo cdnPath; ?>/images/spacer.gif" />
                 <input type="hidden" name="captchahash" value="<?php echo $captchacode; ?>" />
               </td>
             </tr>
@@ -1060,8 +1061,49 @@
           {
             var frm = document.forms.regform;
             document.getElementById('captchaimg').src = '<?php echo makeUrlNS("Special", "Captcha/$captchacode"); ?>/'+Math.floor(Math.random() * 100000);
+            frm.captchacode.value = '';
             return false;
           }
+          function validateCaptcha(input)
+          {
+            var frm = document.forms.regform;
+            if ( input.value.length < 7 )
+            {
+              return false;
+            }
+            var valid_field = document.getElementById('s_captcha');
+            var loader_img = document.getElementById('captchaajax');
+            loader_img.src = cdnPath + '/images/loading.gif';
+            ajaxGet(makeUrlNS('Special', 'Captcha/' + frm.captchahash.value + '/validate=' + input.value), function(ajax)
+              {
+                if ( ajax.readyState == 4 && ajax.status == 200 )
+                {
+                  var response = String(ajax.responseText + '');
+                  if ( !check_json_response(response) )
+                  {
+                    handle_invalid_json(response);
+                    return false;
+                  }
+                  response = parseJSON(response);
+                  if ( response.valid )
+                  {
+                    loader_img.src = cdnPath + '/images/spacer.gif';
+                    valid_field.src = cdnPath + '/images/check.png';
+                  }
+                  else
+                  {
+                    valid_field.src = cdnPath + '/images/checkbad.png';
+                    regenCaptcha();
+                    document.getElementById('captchaimg').onload = function()
+                    {
+                      document.getElementById('captchaajax').src = cdnPath + '/images/spacer.gif';
+                      input.focus();
+                    };
+                    input.value = '';
+                  }
+                }
+              });
+          }
           addOnloadHook(function()
             {
               <?php if ( getConfig('pw_strength_enable') == '1' ): ?>
@@ -1282,6 +1324,24 @@
   {
     $paths->main_page();
   }
+  
+  if ( $validate_code = $paths->getParam(1) )
+  {
+    if ( preg_match('/^validate=(.+)$/', $validate_code, $match) )
+    {
+      header('Content-type: text/javascript');
+      $code = $session->get_captcha($hash, true);
+      $valid = strtolower($code) === strtolower($match[1]);
+      if ( !$valid )
+      {
+        $session->make_captcha(7, $hash);
+      }
+      echo enano_json_encode(array(
+        'valid' => $valid
+        ));
+      exit;
+    }
+  }
 
   $session->make_captcha(7, $hash);
   $code = $session->generate_captcha_code();
@@ -1292,6 +1352,8 @@
     if ( stristr($code, $word) )
     {
       // but don't put too much effort into this (will only correct this once)
+      // I mean, face it. If it generates one of those words twice in a row, either the local root has had
+      // way too much fun with his /dev/random, or this server is just plain gutter-minded.
       $code = $session->generate_captcha_code();
       break;
     }