summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@tinyboard.org>2011-12-03 15:11:15 +1100
committerSavetheinternet <savetheinternet@tinyboard.org>2011-12-03 15:11:15 +1100
commit95920a6972fe8cae55539280342c120b8653e8e3 (patch)
tree7a2b0be38f5e2f22e479cff2e63bd63628c19253
parentdbe330298729cdaa9c07e72e8778daad0a87e1c3 (diff)
generate_tripcode() rewrite
-rw-r--r--inc/functions.php61
1 files changed, 29 insertions, 32 deletions
diff --git a/inc/functions.php b/inc/functions.php
index db1b930a..3f2a56c6 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -1384,42 +1384,39 @@
return substr(sha1(sha1($ip . $config['secure_trip_salt'] . $thread) . $config['secure_trip_salt']), 0, $config['poster_id_length']);
}
- function generate_tripcode($name, $length = 10){
+ function generate_tripcode($name) {
global $config;
- $t = explode('#', $name);
- $nameo = $t[0];
- if ( isset ( $t[1] ) || isset ( $t[2] ) ) {
- $trip = ( ( strlen ( $t[1] ) > 0 ) ? $t[1] : $t[2] );
- if ( ( function_exists ( 'mb_convert_encoding' ) ) ) {
- // multi-byte encoding is necessary to produce standard tripcode output, but only use it if available
- mb_substitute_character('none');
- $recoded_cap = mb_convert_encoding ( $trip, 'Shift_JIS', 'UTF-8' );
- }
- $trip = ( ( ! empty ( $recoded_cap ) ) ? $recoded_cap : $trip );
- $salt = substr ( $trip.'H.', 1, 2 );
- $salt = preg_replace ( '/[^\.-z]/', '.', $salt );
- $salt = strtr ( $salt, ':;<=>?@[\]^_`', 'ABCDEFGabcdef' );
- if ( isset ( $t[2] ) ) {
- // secure
- if(isset($config['custom_tripcode']["##{$trip}"]))
- $trip = $config['custom_tripcode']["##{$trip}"];
- else
- $trip = '!!' . substr ( crypt ( $trip, $config['secure_trip_salt'] ), ( -1 * $length ) );
- } else {
- // insecure
- if(isset($config['custom_tripcode']["#{$trip}"]))
- $trip = $config['custom_tripcode']["#{$trip}"];
- else
- $trip = '!' . substr ( crypt ( $trip, $salt ), ( -1 * $length ) );
- }
- }
- if ( isset ( $trip ) ) {
- return array ( $nameo, $trip );
+
+ if(!preg_match('/^([^#]+)?(##|#)(.+)$/', $name, $match))
+ return Array($name);
+
+ $name = $match[1];
+ $secure = $match[2] == '##';
+ $trip = $match[3];
+
+ // convert to SHIT_JIS encoding
+ $trip = mb_convert_encoding($trip, 'Shift_JIS', 'UTF-8');
+
+ // generate salt
+ $salt = substr($trip . 'H..', 1, 2);
+ $salt = preg_replace('/[^\.-z]/', '.', $salt);
+ $salt = strtr($salt, ':;<=>?@[\]^_`', 'ABCDEFGabcdef');
+
+ if($secure) {
+ if(isset($config['custom_tripcode']["##{$trip}"]))
+ $trip = $config['custom_tripcode']["##{$trip}"];
+ else
+ $trip = '!!' . substr(crypt($trip, $config['secure_trip_salt']), -10);
} else {
- return array ( $nameo );
+ if(isset($config['custom_tripcode']["#{$trip}"]))
+ $trip = $config['custom_tripcode']["#{$trip}"];
+ else
+ $trip = '!' . substr(crypt($trip, $salt), -10);
}
+
+ return Array($name, $trip);
}
-
+
// Highest common factor
function hcf($a, $b){
$gcd = 1;