'EasyCoins',
'symbol' => 'EC',
'plural' => 'EasyCoins',
'description' => 'Platform currency for tips and donations',
'icon' => '/f_templates/tpl_frontend/img/default-token.png',
'color_primary' => '#FFD700',
'color_secondary' => '#FFA500',
'exchange_rate' => 1.00,
'min_purchase' => 1.00,
'max_purchase' => 1000.00,
'enabled' => true
];
try {
$sql = "SELECT setting_key, setting_value FROM db_settings WHERE setting_key LIKE 'token_%'";
$result = $class_database->execute($sql);
$settings = $defaults;
while (!$result->EOF) {
$key = str_replace('token_', '', $result->fields['setting_key']);
$value = $result->fields['setting_value'];
// Convert numeric values
if (in_array($key, ['exchange_rate', 'min_purchase', 'max_purchase'])) {
$value = floatval($value);
} elseif ($key === 'enabled') {
$value = $value === '1';
}
$settings[$key] = $value;
$result->MoveNext();
}
self::$settings = $settings;
return $settings;
} catch (Exception $e) {
self::$settings = $defaults;
return $defaults;
}
}
/**
* Get token display HTML
*/
public static function getTokenDisplay($amount, $size = 'normal', $show_icon = true) {
$settings = self::getSettings();
if (!$settings['enabled']) {
return '$' . number_format($amount, 2);
}
$sizes = [
'small' => ['icon' => '16px', 'font' => '0.875rem'],
'normal' => ['icon' => '20px', 'font' => '1rem'],
'large' => ['icon' => '24px', 'font' => '1.25rem'],
'xlarge' => ['icon' => '32px', 'font' => '1.5rem']
];
$size_config = $sizes[$size] ?? $sizes['normal'];
$icon_html = '';
if ($show_icon) {
$icon_html = sprintf(
'',
htmlspecialchars($settings['icon']),
htmlspecialchars($settings['symbol']),
$size_config['icon'],
$size_config['icon']
);
}
$token_name = $amount == 1 ? $settings['name'] : $settings['plural'];
return sprintf(
'%s%s %s',
$settings['color_primary'],
$size_config['font'],
$icon_html,
number_format($amount, 0),
htmlspecialchars($token_name)
);
}
/**
* Get token symbol only
*/
public static function getSymbol() {
$settings = self::getSettings();
return $settings['symbol'];
}
/**
* Get token name
*/
public static function getName($plural = false) {
$settings = self::getSettings();
return $plural ? $settings['plural'] : $settings['name'];
}
/**
* Get token icon HTML
*/
public static function getIcon($size = '20px') {
$settings = self::getSettings();
return sprintf(
'
',
htmlspecialchars($settings['icon']),
htmlspecialchars($settings['symbol']),
$size,
$size
);
}
/**
* Convert USD to tokens
*/
public static function usdToTokens($usd_amount) {
$settings = self::getSettings();
return round($usd_amount / $settings['exchange_rate']);
}
/**
* Convert tokens to USD
*/
public static function tokensToUsd($token_amount) {
$settings = self::getSettings();
return $token_amount * $settings['exchange_rate'];
}
/**
* Get purchase limits
*/
public static function getPurchaseLimits() {
$settings = self::getSettings();
return [
'min' => $settings['min_purchase'],
'max' => $settings['max_purchase'],
'min_tokens' => self::usdToTokens($settings['min_purchase']),
'max_tokens' => self::usdToTokens($settings['max_purchase'])
];
}
/**
* Validate token amount
*/
public static function validateAmount($amount, $type = 'usd') {
$limits = self::getPurchaseLimits();
if ($type === 'tokens') {
$min = $limits['min_tokens'];
$max = $limits['max_tokens'];
} else {
$min = $limits['min'];
$max = $limits['max'];
}
if ($amount < $min) {
return ['valid' => false, 'message' => "Minimum amount is $min"];
}
if ($amount > $max) {
return ['valid' => false, 'message' => "Maximum amount is $max"];
}
return ['valid' => true];
}
/**
* Get token CSS for styling
*/
public static function getTokenCSS() {
$settings = self::getSettings();
return sprintf('
', $settings['color_primary'], $settings['color_secondary']);
}
/**
* Get donation button HTML
*/
public static function getDonationButton($streamer_id, $suggested_amount = null) {
$settings = self::getSettings();
if (!$settings['enabled']) {
return '';
}
$suggested_tokens = $suggested_amount ? self::usdToTokens($suggested_amount) : 10;
return sprintf('
',
$streamer_id,
$suggested_tokens,
self::getIcon('16px'),
number_format($suggested_tokens),
$settings['name']
);
}
/**
* Get token purchase form HTML
*/
public static function getPurchaseForm($user_id) {
$settings = self::getSettings();
$limits = self::getPurchaseLimits();
if (!$settings['enabled']) {
return '
Token system is currently disabled.
'; } ob_start(); ?>