Changeset 12620


Ignore:
Timestamp:
Nov 13, 2011, 8:33:09 PM (9 years ago)
Author:
mistic100
Message:

fix key generation function when mcrypt is disabled, fix display on some themes

Location:
extensions/Subscribe_to_comments/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/Subscribe_to_comments/include/functions.inc.php

    r12609 r12620  
    371371
    372372/**
    373  * crypt a string using mcrypt extension or a binary method
     373 * crypt a string using mcrypt extension or
     374 * http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php/802957#802957
    374375 * @param string value to crypt
    375376 * @param string key
     
    382383    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    383384    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    384     $value = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
     385    $result = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
    385386  }
    386387  else
    387388  {
    388     $value = $value ^ $key; // binary XOR operation
    389   }
    390  
    391   $value = base64url_encode($value);
    392   return trim($value);
     389    $result = null;
     390    for($i = 0; $i < strlen($value); $i++)
     391    {
     392      $char = substr($value, $i, 1);
     393      $keychar = substr($key, ($i % strlen($key))-1, 1);
     394      $char = chr(ord($char) + ord($keychar));
     395      $result .= $char;
     396    }
     397  }
     398 
     399  $result = base64url_encode($result);
     400  return trim($result);
    393401}
    394402
     
    407415    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    408416    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    409     $value = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
     417    $result = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
    410418  }
    411419  else
    412420  {
    413     $value = $value ^ $key; // binary XOR operation
    414   }
    415  
    416   return trim($value);
    417 }
    418 
     421    $result = null;
     422    for($i = 0; $i < strlen($value); $i++)
     423    {
     424      $char = substr($value, $i, 1);
     425      $keychar = substr($key, ($i % strlen($key))-1, 1);
     426      $char = chr(ord($char) - ord($keychar));
     427      $result .= $char;
     428    }
     429  }
     430 
     431  return trim($result);
     432}
    419433
    420434/**
  • extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php

    r12609 r12620  
    233233
    234234  ## subscribe while add a comment ##
    235   $search = '<input type="submit" value="{\'Submit\'|@translate}">';
    236   $replace = null;
     235  $search = '#<input type="hidden" name="key" value="{\$comment_add\.KEY}"([ /]*)>#';
     236  $replace = '<input type="hidden" name="key" value="{$comment_add.KEY}"$1>';
    237237 
    238238  if (!$subscribed)
     
    254254    {/literal}{/footer_script}';
    255255  }
    256   $replace.= $search;
    257  
    258   $content = str_replace($search, $replace, $content);
     256 
     257  $content = preg_replace($search, $replace, $content);
    259258 
    260259  return $content;
     
    390389
    391390  ## subscribe while add a comment ##
    392   $search = '<input type="submit" value="{\'Submit\'|@translate}">';
    393   $replace = null;
     391  $search = '<input type="hidden" name="key" value="{$comment_add.KEY}">';
     392  $replace = $search;
    394393 
    395394  if (!$subscribed)
     
    411410    {/literal}{/footer_script}';
    412411  }
    413   $replace.= $search;
    414412
    415413  $content = str_replace($search, $replace, $content);
Note: See TracChangeset for help on using the changeset viewer.