64 linhas
1,8 KiB
PHP
64 linhas
1,8 KiB
PHP
<?php
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Short activity log (the last 50 events), shown in the settings page.
|
|
* Addresses and numbers are masked, and the key never enters here.
|
|
*/
|
|
class MOZOUT_AI_Log
|
|
{
|
|
const OPTION = 'mozout_ai_activity_log';
|
|
const MAX = 50;
|
|
|
|
public static function add($area, $ok, $text, $extra = array())
|
|
{
|
|
$log = get_option(self::OPTION, array());
|
|
if (!is_array($log)) {
|
|
$log = array();
|
|
}
|
|
array_unshift($log, array(
|
|
't' => time(),
|
|
'area' => (string) $area,
|
|
'ok' => $ok ? 1 : 0,
|
|
'text' => wp_strip_all_tags((string) $text),
|
|
'extra' => is_array($extra) ? $extra : array(),
|
|
));
|
|
update_option(self::OPTION, array_slice($log, 0, self::MAX), false);
|
|
}
|
|
|
|
public static function all($area = null)
|
|
{
|
|
$log = get_option(self::OPTION, array());
|
|
if (!is_array($log)) {
|
|
return array();
|
|
}
|
|
if ($area === null) {
|
|
return $log;
|
|
}
|
|
return array_values(array_filter($log, function ($e) use ($area) {
|
|
return isset($e['area']) && $e['area'] === $area;
|
|
}));
|
|
}
|
|
|
|
public static function mask_email($email)
|
|
{
|
|
$email = (string) $email;
|
|
$at = strpos($email, '@');
|
|
if ($at === false) {
|
|
return '***';
|
|
}
|
|
$user = substr($email, 0, $at);
|
|
return substr($user, 0, 2) . str_repeat('*', max(1, strlen($user) - 2)) . substr($email, $at);
|
|
}
|
|
|
|
public static function mask_phone($phone)
|
|
{
|
|
$d = preg_replace('/\D+/', '', (string) $phone);
|
|
if (strlen($d) < 6) {
|
|
return '***';
|
|
}
|
|
return substr($d, 0, 4) . str_repeat('*', strlen($d) - 7) . substr($d, -3);
|
|
}
|
|
}
|