457 lines
23 KiB
PHP
457 lines
23 KiB
PHP
<?php
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* What every settings screen of the plugin shares: messages after saving, form fields, the styled select box,
|
|
* and the Connection tab, where a new key is checked with the API (GET /v1/token) before it is saved.
|
|
*/
|
|
abstract class INTERWEB_MZ_RESELLER_Admin_Base
|
|
{
|
|
/* ---- To be defined by the plugin screen ---- */
|
|
|
|
/** Permissions the plugin can use: scope => what it is for. */
|
|
abstract public static function needed_scopes();
|
|
|
|
/** Permissions needed by what is turned on now (subset of needed_scopes). */
|
|
abstract public static function scopes_in_use();
|
|
|
|
/** Slug of the settings screen. */
|
|
abstract public static function page_slug();
|
|
|
|
/** URL of the settings screen. */
|
|
abstract public static function url($tab = 'connection', $args = array());
|
|
|
|
/* ---- Images of the brand edition ---- */
|
|
|
|
/** URL of an image in assets/, or '' when the edition has none. */
|
|
public static function image_url($file)
|
|
{
|
|
return is_readable(INTERWEB_MZ_RESELLER_DIR . 'assets/' . $file) ? INTERWEB_MZ_RESELLER_URL . 'assets/' . $file : '';
|
|
}
|
|
|
|
/** Menu label with the brand icon, when the edition has one. */
|
|
public static function menu_label($title)
|
|
{
|
|
$menu = esc_html($title);
|
|
$icon = self::image_url('menu-icon.png');
|
|
if ($icon !== '') {
|
|
$menu = '<img src="' . esc_url($icon) . '" alt="" width="16" height="16" style="vertical-align:text-bottom;margin-right:5px;border-radius:3px">' . $menu;
|
|
}
|
|
return $menu;
|
|
}
|
|
|
|
public static function header($title)
|
|
{
|
|
$logo = self::image_url('logo.png');
|
|
if ($logo !== '') {
|
|
echo '<div class="interweb-mz-reseller-header"><img class="interweb-mz-reseller-logo" src="' . esc_url($logo) . '" alt="' . esc_attr(INTERWEB_MZ_RESELLER_Brands::name()) . '" width="200" height="38"></div>';
|
|
}
|
|
echo '<h1>' . esc_html($title) . ' <span class="interweb-mz-reseller-brand">' . esc_html(INTERWEB_MZ_RESELLER_Brands::name()) . '</span></h1>';
|
|
self::notices();
|
|
}
|
|
|
|
/* ---- Messages ---- */
|
|
|
|
/**
|
|
* Back to a screen with messages. $ok: true (success), false (error) or 'warning'.
|
|
* $more: extra messages, as array(type, text).
|
|
*/
|
|
public static function redirect($tab, $ok, $text, array $more = array(), $url = '')
|
|
{
|
|
$type = $ok === true ? 'success' : ($ok === false ? 'error' : (string) $ok);
|
|
$list = array(array($type, $text));
|
|
foreach ($more as $m) {
|
|
$list[] = $m;
|
|
}
|
|
$key = strtolower(wp_generate_password(8, false, false));
|
|
set_transient('interweb_mz_reseller_notice_' . get_current_user_id(), array('key' => $key, 'list' => $list), 120);
|
|
wp_safe_redirect(add_query_arg('interweb_mz_reseller_msg', $key, $url !== '' ? $url : static::url($tab)));
|
|
exit;
|
|
}
|
|
|
|
public static function notices()
|
|
{
|
|
if (empty($_GET['interweb_mz_reseller_msg'])) {
|
|
return;
|
|
}
|
|
$key = sanitize_key(wp_unslash($_GET['interweb_mz_reseller_msg']));
|
|
$n = get_transient('interweb_mz_reseller_notice_' . get_current_user_id());
|
|
delete_transient('interweb_mz_reseller_notice_' . get_current_user_id());
|
|
if (!is_array($n) || $n['key'] !== $key) {
|
|
return;
|
|
}
|
|
foreach ($n['list'] as $m) {
|
|
$class = in_array($m[0], array('success', 'error', 'warning', 'info'), true) ? $m[0] : 'info';
|
|
echo '<div class="notice notice-' . esc_attr($class) . ' is-dismissible"><p>' . esc_html($m[1]) . '</p></div>';
|
|
}
|
|
}
|
|
|
|
public static function check($action, $cap = 'manage_options')
|
|
{
|
|
if (!current_user_can($cap)) {
|
|
wp_die(esc_html__('You do not have permission to do this.', 'interweb-mz-reseller'), 403);
|
|
}
|
|
check_admin_referer($action);
|
|
}
|
|
|
|
/* ---- Form fields ---- */
|
|
|
|
public static function form_open($tab, $action = 'interweb_mz_reseller_save')
|
|
{
|
|
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" class="interweb-mz-reseller-form" autocomplete="off">';
|
|
echo '<input type="hidden" name="action" value="' . esc_attr($action) . '"><input type="hidden" name="tab" value="' . esc_attr($tab) . '">';
|
|
wp_nonce_field($action === 'interweb_mz_reseller_save' ? 'interweb_mz_reseller_save_' . $tab : $action);
|
|
echo '<table class="form-table" role="presentation">';
|
|
}
|
|
|
|
public static function form_close($button = null)
|
|
{
|
|
echo '</table>';
|
|
submit_button($button === null ? __('Save changes', 'interweb-mz-reseller') : $button);
|
|
echo '</form>';
|
|
}
|
|
|
|
public static function row($label, $html, $help = '', $for = '')
|
|
{
|
|
echo '<tr><th scope="row">' . ($for ? '<label for="' . esc_attr($for) . '">' . esc_html($label) . '</label>' : esc_html($label)) . '</th><td>' . $html;
|
|
if ($help !== '') {
|
|
echo '<p class="description">' . wp_kses($help, array('a' => array('href' => array(), 'target' => array(), 'rel' => array()), 'code' => array(), 'strong' => array())) . '</p>';
|
|
}
|
|
echo '</td></tr>';
|
|
}
|
|
|
|
public static function checkbox($name, $label)
|
|
{
|
|
return '<label><input type="checkbox" name="' . esc_attr($name) . '" value="1" ' . checked((int) INTERWEB_MZ_RESELLER_Settings::get($name), 1, false) . '> ' . esc_html($label) . '</label>';
|
|
}
|
|
|
|
public static function input($name, $type = 'text', $attrs = '', $value = null)
|
|
{
|
|
$v = $value === null ? (string) INTERWEB_MZ_RESELLER_Settings::get($name) : (string) $value;
|
|
return '<input type="' . esc_attr($type) . '" id="interweb-mz-reseller-' . esc_attr($name) . '" name="' . esc_attr($name) . '" value="' . esc_attr($v) . '" class="regular-text" ' . $attrs . '>';
|
|
}
|
|
|
|
public static function textarea($name, $rows = 3, $value = null, $placeholder = '')
|
|
{
|
|
$v = $value === null ? (string) INTERWEB_MZ_RESELLER_Settings::get($name) : $value;
|
|
return '<textarea id="interweb-mz-reseller-' . esc_attr($name) . '" name="' . esc_attr($name) . '" rows="' . (int) $rows . '" class="large-text" placeholder="' . esc_attr($placeholder) . '">' . esc_textarea($v) . '</textarea>';
|
|
}
|
|
|
|
/** A select box with the plugin style (select.js turns it into a button with a list). Never the native look. */
|
|
public static function select($name, array $options, $current, $id = '', $attrs = '')
|
|
{
|
|
$id = $id !== '' ? $id : 'interweb-mz-reseller-' . $name;
|
|
$html = '<select name="' . esc_attr($name) . '" id="' . esc_attr($id) . '" data-interweb-mz-reseller-select ' . $attrs . '>';
|
|
foreach ($options as $k => $v) {
|
|
$html .= '<option value="' . esc_attr($k) . '" ' . selected((string) $current, (string) $k, false) . '>' . esc_html($v) . '</option>';
|
|
}
|
|
return $html . '</select>';
|
|
}
|
|
|
|
public static function need_key_notice()
|
|
{
|
|
if (INTERWEB_MZ_RESELLER_Settings::api_key() === '') {
|
|
echo '<div class="notice notice-warning inline"><p>' . esc_html__('Save the API key in the Connection tab first.', 'interweb-mz-reseller') . '</p></div>';
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/* ---- Connection tab ---- */
|
|
|
|
public static function tab_connection()
|
|
{
|
|
$hint = INTERWEB_MZ_RESELLER_Settings::key_hint();
|
|
self::form_open('connection');
|
|
|
|
if (!INTERWEB_MZ_RESELLER_Brands::is_fixed()) {
|
|
$opts = array();
|
|
foreach (INTERWEB_MZ_RESELLER_Brands::all() as $id => $b) {
|
|
$opts[$id] = INTERWEB_MZ_RESELLER_Brands::label($b);
|
|
}
|
|
self::row(__('Brand', 'interweb-mz-reseller'), self::select('brand', $opts, INTERWEB_MZ_RESELLER_Brands::current_id()), __('The company where you have your account. The API address and links follow this choice.', 'interweb-mz-reseller'), 'interweb-mz-reseller-brand');
|
|
}
|
|
|
|
if (INTERWEB_MZ_RESELLER_Settings::key_from_constant()) {
|
|
$key_html = '<p><strong>' . esc_html__('The key is defined in wp-config.php (INTERWEB_MZ_RESELLER_API_KEY) and cannot be changed here.', 'interweb-mz-reseller') . '</strong></p>';
|
|
} else {
|
|
$key_html = '<input type="password" name="api_key" id="interweb-mz-reseller-api_key" class="regular-text" value="" autocomplete="new-password" spellcheck="false" placeholder="'
|
|
. esc_attr(!empty($hint['suffix']) ? __('Saved. Write a new key only to replace it.', 'interweb-mz-reseller') : 'prod_... / sandbox_...') . '">';
|
|
if (!empty($hint['suffix'])) {
|
|
$key_html .= '<p class="interweb-mz-reseller-keyhint">' . esc_html(sprintf(
|
|
/* translators: 1: Sandbox or Production, 2: last 4 characters */
|
|
__('Saved key: %1$s, ending in %2$s.', 'interweb-mz-reseller'),
|
|
$hint['mode'] === 'sandbox' ? 'Sandbox' : __('Production', 'interweb-mz-reseller'),
|
|
$hint['suffix']
|
|
)) . '</p>';
|
|
$key_html .= '<label><input type="checkbox" name="delete_key" value="1"> ' . esc_html__('Delete the saved key', 'interweb-mz-reseller') . '</label>';
|
|
}
|
|
if (INTERWEB_MZ_RESELLER_Settings::key_unreadable()) {
|
|
$key_html .= '<p class="interweb-mz-reseller-error">' . esc_html__('The saved API key can no longer be read (the WordPress security keys changed). Save the key again.', 'interweb-mz-reseller') . '</p>';
|
|
}
|
|
}
|
|
$scopes = array_keys(static::needed_scopes());
|
|
$help = sprintf(
|
|
/* translators: 1: link to the API page, 2: name of the customer area, 3: list of permissions */
|
|
__('Create the key in %2$s, on the <a href="%1$s" target="_blank" rel="noopener">API page</a>, with these permissions: %3$s. When you save, the key is checked with the API. It is stored encrypted and is never shown again.', 'interweb-mz-reseller'),
|
|
esc_url(INTERWEB_MZ_RESELLER_Brands::portal_link('api-center.php')),
|
|
esc_html(INTERWEB_MZ_RESELLER_Brands::portal_name()),
|
|
'<code>' . implode('</code>, <code>', array_map('esc_html', $scopes)) . '</code>'
|
|
);
|
|
self::row(__('API key', 'interweb-mz-reseller'), $key_html, $help, 'interweb-mz-reseller-api_key');
|
|
|
|
$lang_opts = array('auto' => __('Same as WordPress', 'interweb-mz-reseller'), 'pt' => 'Português', 'en' => 'English');
|
|
self::row(__('Language', 'interweb-mz-reseller'), self::select('ui_lang', $lang_opts, INTERWEB_MZ_RESELLER_Settings::get('ui_lang')), __('Language of these screens and of the texts shown to visitors.', 'interweb-mz-reseller'), 'interweb-mz-reseller-ui_lang');
|
|
self::form_close();
|
|
|
|
echo '<h2>' . esc_html__('Connection test', 'interweb-mz-reseller') . '</h2>';
|
|
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
|
echo '<input type="hidden" name="action" value="interweb_mz_reseller_test">';
|
|
wp_nonce_field('interweb_mz_reseller_test');
|
|
submit_button(__('Test the connection', 'interweb-mz-reseller'), 'secondary', 'submit', false);
|
|
echo '</form>';
|
|
$info = get_transient('interweb_mz_reseller_token_info');
|
|
if (is_array($info)) {
|
|
echo '<table class="widefat striped interweb-mz-reseller-info"><tbody>';
|
|
echo '<tr><th>' . esc_html__('Mode', 'interweb-mz-reseller') . '</th><td>' . esc_html(self::mode_label($info)) . '</td></tr>';
|
|
echo '<tr><th>' . esc_html__('Key name', 'interweb-mz-reseller') . '</th><td>' . esc_html($info['name']) . '</td></tr>';
|
|
echo '<tr><th>' . esc_html__('Expires', 'interweb-mz-reseller') . '</th><td>' . esc_html($info['expires_at'] ? $info['expires_at'] : __('Never', 'interweb-mz-reseller')) . '</td></tr>';
|
|
echo '<tr><th>' . esc_html__('Permissions', 'interweb-mz-reseller') . '</th><td>';
|
|
foreach (static::needed_scopes() as $scope => $what) {
|
|
$has = in_array($scope, $info['permissions'], true) || in_array('*', $info['permissions'], true);
|
|
echo '<span class="interweb-mz-reseller-scope ' . ($has ? 'is-ok' : 'is-missing') . '">' . esc_html(($has ? '✓ ' : '✗ ') . $scope) . '</span> <span class="description">' . esc_html($what) . '</span><br>';
|
|
}
|
|
echo '</td></tr></tbody></table>';
|
|
}
|
|
}
|
|
|
|
/** Saves the Connection tab. @return array (ok, message, more messages) */
|
|
public static function save_connection(array $p)
|
|
{
|
|
$v = array();
|
|
$brands = INTERWEB_MZ_RESELLER_Brands::all();
|
|
$old_brand = INTERWEB_MZ_RESELLER_Brands::current_id();
|
|
if (!INTERWEB_MZ_RESELLER_Brands::is_fixed() && isset($p['brand'], $brands[$p['brand']])) {
|
|
$v['brand'] = $p['brand'];
|
|
}
|
|
$v['ui_lang'] = in_array(isset($p['ui_lang']) ? $p['ui_lang'] : '', array('auto', 'pt', 'en'), true) ? $p['ui_lang'] : 'auto';
|
|
INTERWEB_MZ_RESELLER_Settings::update($v);
|
|
if (isset($v['brand']) && $v['brand'] !== $old_brand) {
|
|
delete_transient('interweb_mz_reseller_token_info');
|
|
}
|
|
if (!INTERWEB_MZ_RESELLER_Settings::key_from_constant() && !empty($p['delete_key'])) {
|
|
INTERWEB_MZ_RESELLER_Settings::delete_api_key();
|
|
return array(true, __('Settings saved. The key was deleted.', 'interweb-mz-reseller'), array());
|
|
}
|
|
if (!INTERWEB_MZ_RESELLER_Settings::key_from_constant() && !empty($p['api_key'])) {
|
|
return self::save_new_key(trim((string) $p['api_key']));
|
|
}
|
|
if (INTERWEB_MZ_RESELLER_Settings::api_key() !== '') {
|
|
return self::recheck_saved_key();
|
|
}
|
|
return array(true, __('Settings saved.', 'interweb-mz-reseller'), array());
|
|
}
|
|
|
|
/** Asks the API about a key (GET /v1/token). Null checks the saved key and keeps the answer for an hour. @return array|WP_Error */
|
|
public static function token_info($key = null)
|
|
{
|
|
$opts = array('timeout' => 10);
|
|
if ($key !== null) {
|
|
$opts['key'] = $key;
|
|
}
|
|
$res = INTERWEB_MZ_RESELLER_Api::request('GET', '/v1/token', null, $opts);
|
|
if (is_wp_error($res)) {
|
|
return $res;
|
|
}
|
|
$d = is_array($res['data']) ? $res['data'] : array();
|
|
$info = array(
|
|
'mode' => isset($d['mode']) ? (string) $d['mode'] : (isset($d['type']) ? (string) $d['type'] : ''),
|
|
'simulated' => !empty($d['writes_simulated']),
|
|
'name' => isset($d['name']) ? (string) $d['name'] : '',
|
|
'expires_at' => isset($d['expires_at']) ? (string) $d['expires_at'] : '',
|
|
'permissions' => isset($d['permissions']) && is_array($d['permissions']) ? $d['permissions'] : array(),
|
|
);
|
|
if ($key === null) {
|
|
set_transient('interweb_mz_reseller_token_info', $info, HOUR_IN_SECONDS);
|
|
}
|
|
return $info;
|
|
}
|
|
|
|
public static function mode_label(array $info)
|
|
{
|
|
if ($info['mode'] === 'sandbox') {
|
|
return __('Sandbox (writes are simulated)', 'interweb-mz-reseller');
|
|
}
|
|
return !empty($info['simulated']) ? __('Production (writes are still simulated)', 'interweb-mz-reseller') : __('Production', 'interweb-mz-reseller');
|
|
}
|
|
|
|
/** Missing permissions for what is turned on, and a mode that does not fit. @return array of array(type, text) */
|
|
public static function key_warnings($info = null)
|
|
{
|
|
if ($info === null) {
|
|
if (INTERWEB_MZ_RESELLER_Settings::api_key() === '') {
|
|
return array();
|
|
}
|
|
$info = get_transient('interweb_mz_reseller_token_info');
|
|
if (!is_array($info)) {
|
|
$info = self::token_info();
|
|
}
|
|
if (is_wp_error($info)) {
|
|
return array();
|
|
}
|
|
}
|
|
$out = array();
|
|
$perms = $info['permissions'];
|
|
if (!in_array('*', $perms, true)) {
|
|
$missing = array();
|
|
foreach (static::scopes_in_use() as $scope => $what) {
|
|
if (!in_array($scope, $perms, true)) {
|
|
$missing[] = $scope . ' (' . $what . ')';
|
|
}
|
|
}
|
|
if ($missing) {
|
|
$out[] = array('warning', sprintf(
|
|
/* translators: 1: list of permissions, 2: name of the customer area */
|
|
__('The key is missing permissions: %1$s. Those features will fail until you create a key with these permissions in %2$s and save it here.', 'interweb-mz-reseller'),
|
|
implode(', ', $missing),
|
|
INTERWEB_MZ_RESELLER_Brands::portal_name()
|
|
));
|
|
}
|
|
}
|
|
foreach (static::mode_warnings($info) as $w) {
|
|
$out[] = $w;
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
/** Warnings about the key mode. Plugins with purchases override it. @return array of array(type, text) */
|
|
public static function mode_warnings(array $info)
|
|
{
|
|
return array();
|
|
}
|
|
|
|
/** Checks a new key with the API before saving it. A key the API refuses (401) is not saved. */
|
|
public static function save_new_key($key)
|
|
{
|
|
$format = INTERWEB_MZ_RESELLER_Settings::check_key_format($key);
|
|
if (is_wp_error($format)) {
|
|
return array(false, $format->get_error_message(), array());
|
|
}
|
|
$had_key = INTERWEB_MZ_RESELLER_Settings::has_stored_key();
|
|
$info = self::token_info($key);
|
|
$status = is_wp_error($info) ? (int) self::error_status($info) : 200;
|
|
if ($status === 401) {
|
|
$msg = __('The API did not accept this key: it is wrong, was revoked or has expired. It was not saved.', 'interweb-mz-reseller');
|
|
if ($had_key) {
|
|
$msg .= ' ' . __('The key you had before is still in use.', 'interweb-mz-reseller');
|
|
}
|
|
return array(false, $msg, array());
|
|
}
|
|
$saved = INTERWEB_MZ_RESELLER_Settings::save_api_key($key, is_wp_error($info) ? '' : $info['mode']);
|
|
if (is_wp_error($saved)) {
|
|
return array(false, $saved->get_error_message(), array());
|
|
}
|
|
if (is_wp_error($info)) {
|
|
if ($status === 403) {
|
|
return array('warning', sprintf(
|
|
/* translators: %s: reason given by the API */
|
|
__('Key saved, but the API refused it for this site: %s', 'interweb-mz-reseller'),
|
|
$info->get_error_message()
|
|
), array());
|
|
}
|
|
return array('warning', sprintf(
|
|
/* translators: %s: technical reason */
|
|
__('Key saved, but it could not be checked now: %s Use the connection test later.', 'interweb-mz-reseller'),
|
|
$info->get_error_message()
|
|
), array());
|
|
}
|
|
set_transient('interweb_mz_reseller_token_info', $info, HOUR_IN_SECONDS);
|
|
static::after_key_change();
|
|
return array(true, sprintf(
|
|
/* translators: %s: mode of the key, for example "Sandbox (writes are simulated)" */
|
|
__('Key checked and saved. Mode: %s. It is stored encrypted and will not be shown again.', 'interweb-mz-reseller'),
|
|
self::mode_label($info)
|
|
), self::key_warnings($info));
|
|
}
|
|
|
|
/** Saving the Connection tab without a new key checks the saved one again. */
|
|
public static function recheck_saved_key()
|
|
{
|
|
$info = self::token_info();
|
|
if (!is_wp_error($info)) {
|
|
return array(true, __('Settings saved.', 'interweb-mz-reseller'), self::key_warnings($info));
|
|
}
|
|
if ((int) self::error_status($info) === 401) {
|
|
return array('warning', __('Settings saved, but the API no longer accepts the saved key: it was revoked or has expired. Write a new key.', 'interweb-mz-reseller'), array());
|
|
}
|
|
return array('warning', sprintf(
|
|
/* translators: %s: technical reason */
|
|
__('Settings saved, but the key could not be checked now: %s', 'interweb-mz-reseller'),
|
|
$info->get_error_message()
|
|
), array());
|
|
}
|
|
|
|
/** Caches to forget when the key changes. */
|
|
public static function after_key_change()
|
|
{
|
|
}
|
|
|
|
public static function error_status(WP_Error $e)
|
|
{
|
|
$data = $e->get_error_data();
|
|
return is_array($data) && isset($data['status']) ? $data['status'] : 0;
|
|
}
|
|
|
|
public static function test_connection()
|
|
{
|
|
self::check('interweb_mz_reseller_test');
|
|
delete_transient('interweb_mz_reseller_token_info');
|
|
static::after_key_change();
|
|
$info = self::token_info();
|
|
if (is_wp_error($info)) {
|
|
self::redirect('connection', false, $info->get_error_message());
|
|
}
|
|
self::redirect('connection', true, sprintf(
|
|
/* translators: %s: brand name */
|
|
__('Connection to %s working.', 'interweb-mz-reseller'),
|
|
INTERWEB_MZ_RESELLER_Brands::name()
|
|
), self::key_warnings($info));
|
|
}
|
|
|
|
/* ---- Activity ---- */
|
|
|
|
public static function log_table($area, $n = 10, array $areas = array())
|
|
{
|
|
$log = array_slice(INTERWEB_MZ_RESELLER_Log::all($area), 0, $n);
|
|
if (!$log) {
|
|
if ($area === null) {
|
|
echo '<p>' . esc_html__('No activity yet.', 'interweb-mz-reseller') . '</p>';
|
|
}
|
|
return;
|
|
}
|
|
echo '<h2>' . esc_html__('Recent activity', 'interweb-mz-reseller') . '</h2><table class="widefat striped interweb-mz-reseller-log"><thead><tr><th>' . esc_html__('Date', 'interweb-mz-reseller') . '</th><th>' . esc_html__('Area', 'interweb-mz-reseller') . '</th><th>' . esc_html__('Result', 'interweb-mz-reseller') . '</th><th>' . esc_html__('Details', 'interweb-mz-reseller') . '</th></tr></thead><tbody>';
|
|
foreach ($log as $e) {
|
|
$extra = array();
|
|
foreach ((array) $e['extra'] as $k => $v) {
|
|
$extra[] = $k . ': ' . (is_scalar($v) ? $v : wp_json_encode($v));
|
|
}
|
|
$area_name = isset($areas[$e['area']]) ? $areas[$e['area']] : $e['area'];
|
|
echo '<tr><td>' . esc_html(wp_date('d/m/Y H:i', $e['t'])) . '</td><td>' . esc_html($area_name) . '</td><td class="' . ($e['ok'] ? 'interweb-mz-reseller-ok' : 'interweb-mz-reseller-error') . '">' . esc_html($e['text']) . '</td><td>' . esc_html(implode(' · ', $extra)) . '</td></tr>';
|
|
}
|
|
echo '</tbody></table>';
|
|
}
|
|
|
|
/* ---- Money ---- */
|
|
|
|
/** Amount with 2 decimal places in the format of the currency, as the brands show it. */
|
|
public static function money($value, $currency, $lang = null)
|
|
{
|
|
$lang = $lang ? $lang : INTERWEB_MZ_RESELLER_I18n::lang();
|
|
$n = $lang === 'pt' ? number_format((float) $value, 2, ',', '.') : number_format((float) $value, 2, '.', ',');
|
|
$sym = array('MZN' => 'MT', 'AOA' => 'Kz', 'USD' => 'USD', 'EUR' => '€', 'ZAR' => 'R');
|
|
$s = isset($sym[$currency]) ? $sym[$currency] : $currency;
|
|
return trim($n . ' ' . $s);
|
|
}
|
|
}
|