Last active
September 6, 2020 07:43
-
-
Save gohumble/eecb0ea2b2277031275dc98c8d19ed39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function event() { | |
global $events; | |
$args = func_get_args(); | |
$event = $args[0]; | |
$args = array_splice($args, 1); | |
if (!isset($events[$event])) | |
return false; | |
foreach ($events[$event] as $callback) { | |
if (!is_callable($callback)) | |
error('Event handler for ' . $event . ' is not callable!'); | |
if ($error = call_user_func_array($callback, $args)) | |
return $error; | |
} | |
return false; | |
} | |
function generate_tripcode($name) { | |
global $config; | |
if ($trip = event('tripcode', $name)) | |
return $trip; | |
if (!preg_match('/^([^#]+)?(###|##|#)(.+)$/', $name, $match)) | |
return array($name); | |
$name = $match[1]; | |
$secure = $match[2] == '##'; | |
$secure2 = $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, str_replace('+', '.', '_..A.' . substr(base64_encode(sha1($trip . $config['secure_trip_salt'], true)), 0, 4))), -10); | |
} | |
} elseif ($secure2) { | |
if (isset($config['custom_tripcode']["###{$trip}"])) | |
$trip = $config['custom_tripcode']["###{$trip}"]; | |
else | |
$trip = '!!!' . substr(base64_encode(hash('sha256', $trip . $config['secure_trip_salt'])), 0,16); | |
} else { | |
if (isset($config['custom_tripcode']["#{$trip}"])) | |
$trip = $config['custom_tripcode']["#{$trip}"]; | |
else | |
$trip = '!' . substr(crypt($trip, $salt), -10); | |
} | |
return array($name, $trip); | |
} | |
print_r(generate_tripcode("##test")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment