Browse Source

update post format method

main
ghost 10 months ago
parent
commit
eb19f62c46
  1. 49
      src/controller/room.php

49
src/controller/room.php

@ -508,12 +508,37 @@ class Room
?int &$time = 0 ?int &$time = 0
): ?string ): ?string
{ {
// Validate required data
if (empty($data['txid']))
{
return null;
}
if (empty($data['key']))
{
return null;
}
if (empty($data['value']))
{
return null;
}
// Skip values with meta keys // Skip values with meta keys
if (str_starts_with($data['key'], '_')) if (str_starts_with($data['key'], '_'))
{ {
return null; return null;
} }
// Legacy key format support (protocol v1 contain timestamp in prefix)
if (preg_match('/^([\d]+)@([A-z0-9\.\:\[\]]+)/', $data['key'], $matches))
{
if (!empty($matches[2]))
{
$data['key'] = $matches[2];
}
}
// Validate value format allowed in settings // Validate value format allowed in settings
if (!preg_match((string) $this->_config->kevachat->post->value->regex, $data['value'])) if (!preg_match((string) $this->_config->kevachat->post->value->regex, $data['value']))
{ {
@ -521,40 +546,32 @@ class Room
} }
// Validate key format allowed in settings // Validate key format allowed in settings
if (!preg_match($this->_config->kevachat->post->key->regex, $data['key'], $matches)) if (!preg_match($this->_config->kevachat->post->key->regex, $data['key']))
{ {
return null; return null;
} }
// Timestamp required in key // Get time from raw transaction
if (empty($matches[1])) if (!$transaction = $this->_kevacoin->getRawTransaction($data['txid']))
{ {
return null; return null;
} }
// Username required in key // Make sure time available
if (empty($matches[2])) if (empty($transaction['time']))
{ {
return null; return null;
} }
// Return timestamp
$time = $matches[1];
// Is raw field request // Is raw field request
if ($field) if ($field)
{ {
return isset($data[$field]) ? $data[$field] : null; return isset($data[$field]) ? $data[$field] : null;
} }
// Legacy usernames backport
if (!preg_match((string) $this->_config->kevachat->user->name->regex, $matches[2]))
{
$matches[2] = 'anon';
}
// Try to find related quote value // Try to find related quote value
$quote = null; $quote = null;
if (preg_match(self::PARENT_REGEX, $data['value'], $mention)) if (preg_match(self::PARENT_REGEX, $data['value'], $mention))
{ {
// Message starts with mention // Message starts with mention
@ -665,11 +682,11 @@ class Room
[ [
// time // time
$this->_ago( $this->_ago(
$matches[1] $transaction['time']
), ),
// author // author
$matches[2], $data['key'],
// quote // quote
$quote, $quote,

Loading…
Cancel
Save