Skip to content

Commit

Permalink
Merge pull request #31 from BeycanPress/alpha
Browse files Browse the repository at this point in the history
Alpha
  • Loading branch information
0xBeycan authored Nov 28, 2024
2 parents ba211b9 + a4fb2c3 commit 6642eb4
Show file tree
Hide file tree
Showing 826 changed files with 1,261 additions and 61,233 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
debug.log
node_modules
node_modules
.DS_Store
Binary file modified .wordpress-org/banner-1544x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions app/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function getLangParams(): object
"waitingBlockConfirmations" => esc_html__('Waiting for block confirmations:', 'cryptopay'),
"waitingTransactionConfirmations" => esc_html__('Waiting for transaction confirmation...', 'cryptopay'),
"openInExplorer" => esc_html__('Open in explorer', 'cryptopay'),
"waitingConfirmation" => esc_html__('Waiting confirmation...', 'cryptopay'),
"waitingConfirmation" => esc_html__('Waiting for confirmation...', 'cryptopay'),
"selectWallet" => esc_html__('Select wallet', 'cryptopay'),
"selectPaymentMethod" => esc_html__('Select payment method', 'cryptopay'),
"pleaseTryToConnectAgain" => esc_html__('Please try to connect again by selecting network {networkName} from your wallet!', 'cryptopay'),
Expand All @@ -58,7 +58,7 @@ public static function getLangParams(): object
"payNow" => esc_html__('Pay now', 'cryptopay'),
"payWith" => esc_html__('Pay with {name}', 'cryptopay'),
"loading" => esc_html__('Loading...', 'cryptopay'),
"waitingApproval" => esc_html__('Waiting approval...', 'cryptopay'),
"waitingApproval" => esc_html__('Waiting for approval...', 'cryptopay'),
"paymentRejected" => esc_html__('Payment rejected!', 'cryptopay'),
"transferAmountError" => esc_html__('Transfer amount need to be bigger from zero!', 'cryptopay'),
"transactionCreateFail" => esc_html__('Transaction create fail! Please try again.', 'cryptopay'),
Expand Down Expand Up @@ -125,6 +125,7 @@ public static function getLangParams(): object
"redirecting" => esc_html__('Redirecting...', 'cryptopay'),
"connecting" => esc_html__('Connecting...', 'cryptopay'),
"cannotPaySameAddress" => esc_html__('The payment cannot proceed because the payer and receiver address are the same! Please pay with a different wallet!', 'cryptopay'),
"reownProjectIdRequired" => esc_html__('Reown Project ID is required! Please contact the site administrator.', 'cryptopay'),
]);
}

Expand Down
6 changes: 3 additions & 3 deletions app/Pages/TransactionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ public function page(): void
]
]);
})
->createDataList(function () use ($params) {
->createDataList(function ($entry, $orderQuery, $perPage, $offset) use ($params) {
if (isset($_GET['s']) && !empty($_GET['s'])) {
$s = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : null;
$result = (object) $this->model->search($s, $params);
return [$result->transactions->toArray(false), $result->count];
} else {
$transactions = $this->model->findBy($params, ['id', 'DESC']);
return [$transactions->toArray(false), $transactions->count()];
$transactions = $this->model->findBy($params, $orderQuery, $perPage, $offset);
return [$transactions->toArray(false), $this->model->getCount($params)];
}
});

Expand Down
21 changes: 18 additions & 3 deletions app/PluginHero/BaseAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ abstract class BaseAPI
*/
private array $middlewares = [];

/**
* @var int
*/
protected int $currentUserId;

/**
* @param array<string,array<mixed>> $routeList
* @return void
*/
public function addRoutes(array $routeList): void
{
add_action('init', [$this, 'init']);

if (empty($routeList)) {
return;
}
Expand Down Expand Up @@ -66,6 +73,14 @@ public function addRoutes(array $routeList): void
Helpers::addAPI($this);
}

/**
* @return void
*/
public function init(): void
{
$this->currentUserId = get_current_user_id();
}

/**
* @param string $nameSpace
* @param array<mixed>|\Closure $caller
Expand Down Expand Up @@ -110,9 +125,9 @@ public function middlewareFilter(mixed $result, \WP_REST_Server $server, \WP_RES
public function getUrl(?string $nameSpace = null): string
{
if ('rest' == $this->type) {
$nameSpace = isset($this->nameSpaces[$nameSpace])
? $this->nameSpaces[$nameSpace]
: array_values($this->nameSpaces)[0];
$nameSpace = $nameSpace
? $nameSpace
: array_values($this->nameSpaces)[0];

return home_url('?rest_route=/' . $nameSpace);
} else {
Expand Down
43 changes: 43 additions & 0 deletions app/PluginHero/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ public static function getPHPVersion(): float
return floatval($version[0] . '.' . $version[1]);
}

/**
* Hi, this is a helper function to get the ionCube version.
* But we not use it in the wp.org plugins.
* Only in premium versions for protect license.
* @return int|null
*/
public static function getIoncubeVersion(): ?int
{
if (function_exists('ioncube_loader_iversion')) {
$version = ioncube_loader_iversion();
$version = sprintf('%d', $version / 10000);
return intval($version);
}
return null;
}

/**
* @param array<mixed> $rules
* @param string $pluginFile
Expand Down Expand Up @@ -86,6 +102,33 @@ public static function createRequirementRules(array $rules, string $pluginFile):
}
}

if (isset($rules['ioncubeVersion'])) {
$ionCubeVersion = self::getIoncubeVersion();
$requiredIonCubeVersion = $rules['ioncubeVersion'];
if (!is_int($requiredIonCubeVersion)) {
throw new \Exception('ioncubeVersion must be an integer!');
}
if (!$ionCubeVersion || $ionCubeVersion < $requiredIonCubeVersion) {
$status = false;
// @phpcs:ignore
add_action('admin_notices', function () use ($requiredIonCubeVersion, $ionCubeVersion, $pluginName): void {
$message = $pluginName . ": Is disabled because " . ('cli' == php_sapi_name() ? 'ionCube ' . $requiredIonCubeVersion : '<a href="http://www.ioncube.com">ionCube ' . $requiredIonCubeVersion . '</a>') . " PHP Loader is not installed! In order for " . $pluginName . " to work, you must have ionCube " . $requiredIonCubeVersion . " and above. This is a widely used PHP extension for running ionCube protected PHP code, website security and malware blocking. Please visit " . ('cli' == php_sapi_name() ? 'ioncube.com/loaders.php' : '<a href="https://www.ioncube.com/loaders.php">ioncube.com/loaders.php</a>') . " for install assistance or you can ask your server service provider to install ionCube " . $requiredIonCubeVersion . " or above. Your current installed IonCube version is " . ($ionCubeVersion ? $ionCubeVersion : 'not installed') . "."; // @phpcs:ignore
printf('<div class="notice notice-error"><p>%1$s</p></div>', wp_kses_post($message));
});
}
if (extension_loaded('xdebug') && $status) {
$modes = xdebug_info('mode');
$loaderFile = file_get_contents(dirname(__DIR__) . '/Loader.php', true);
if (isset($modes[0]) && 'off' != $modes[0] && false !== strpos($loaderFile, 'HR+')) {
$status = false;
add_action('admin_notices', function () use ($pluginName): void {
$message = $pluginName . ': xDebug installation was detected and ' . $pluginName . ' was disabled because of it. This is because ' . $pluginName . ' uses IonCube for license protection and the IonCube Loader is incompatible with xDebug, causing the site to crash. xDebug helps developers with debug and profile, but it doesn\'t need to be on the production site. So to turn off xDebug, please set mode to off or uninstall it. If you are not familiar with this process, you can get help from your server service provider.'; // @phpcs:ignore
printf('<div class="notice notice-error"><p>%1$s</p></div>', esc_html($message));
});
}
}
}

if (isset($rules['extensions'])) {
$extensions = $rules['extensions'];
if (!is_array($extensions)) {
Expand Down
26 changes: 20 additions & 6 deletions app/PluginHero/Helpers/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,25 @@ public static function getAddon(string $key): Addon
*/
public static function getPluginData(string $file): object
{
if (!function_exists('get_plugin_data')) {
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
}

$pluginData = (object) get_plugin_data($file);
$pluginData = (object) get_file_data($file, [
'Name' => 'Plugin Name',
'PluginURI' => 'Plugin URI',
'Version' => 'Version',
'Description' => 'Description',
'Author' => 'Author',
'AuthorURI' => 'Author URI',
'TextDomain' => 'Text Domain',
'DomainPath' => 'Domain Path',
'License' => 'License',
'LicenseURI' => 'License URI',
'Network' => 'Network',
'RequiresWP' => 'Requires at least',
'RequiresPHP' => 'Requires PHP',
'UpdateURI' => 'Update URI',
'RequiresPlugins' => 'Requires Plugins',
'Title' => 'Plugin Name',
'AuthorName' => 'Author'
]);

if (!isset($pluginData->Slug)) { // phpcs:ignore
$pluginData->Slug = self::getPluginSlug($file); // phpcs:ignore
Expand Down Expand Up @@ -264,7 +278,7 @@ public static function getUserBy(string $field, mixed $value): ?object
// @phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$result = $wpdb->get_row(
$wpdb->prepare(
"SELECT * FROM $wpdb->users WHERE `%s` = %s",
"SELECT * FROM $wpdb->users WHERE %s = %s",
$field,
$value
)
Expand Down
8 changes: 8 additions & 0 deletions app/PluginHero/Helpers/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public static function feedback(bool $form = true, ?string $wpOrgSlug = null): v
}
});

add_action('rest_api_init', function (): void {
register_rest_route('bp-plugin-check', self::getProp('pluginKey'), [
'callback' => fn() => wp_send_json_success(),
'methods' => ['POST', 'GET'],
'permission_callback' => '__return_true'
]);
});

if ($form) {
global $pagenow, $wp_filesystem;
if ('plugins.php' === $pagenow) {
Expand Down
4 changes: 2 additions & 2 deletions app/PluginHero/Helpers/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

trait General
{
/**
/**
* @return string
*/
public static function getCurrentUrl(): string
Expand Down Expand Up @@ -101,7 +101,7 @@ public static function getIp(): ?string
{
$ip = null;
if (isset($_SERVER['REMOTE_ADDR'])) {
$ip = wp_unslash($_SERVER['REMOTE_ADDR']);
$ip = wp_unslash(esc_url_raw($_SERVER['REMOTE_ADDR']));
$ip = rest_is_ip_address($ip);
if (false === $ip) {
$ip = null;
Expand Down
1 change: 1 addition & 0 deletions app/PluginHero/templates/data-table.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php if (!defined('ABSPATH')) exit; ?>
<table id="<?php echo esc_attr($id); ?>" class="display">
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion app/PluginHero/templates/feedback.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php if (!defined('ABSPATH')) exit; ?>
<div
class="bp-feedback-modal"
id="<?php echo esc_attr($pluginKey); ?>-feedback-modal"
Expand Down
2 changes: 1 addition & 1 deletion app/PluginHero/templates/log.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;
if (!defined('ABSPATH')) exit;

echo "<pre>";
echo "Log date: " . esc_html($date) . "<br>";
Expand Down
2 changes: 1 addition & 1 deletion app/PluginHero/templates/notice.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if (!defined('ABSPATH')) exit;

$dismissible = $dismissible ? ' is-dismissible' : '';
?>
Expand Down
2 changes: 1 addition & 1 deletion app/PluginHero/templates/plugins.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php if (!defined('ABSPATH')) exit; ?>
<div class="wrap">
<h1 class="wp-heading-inline">
<?php echo esc_html__('BeycanPress Plugins'); ?>
Expand Down
8 changes: 6 additions & 2 deletions app/PluginHero/templates/table-search-form.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php
<?php
if (!defined('ABSPATH')) exit;
// @phpcs:disable WordPress.Security.NonceVerification.Missing
// @phpcs:disable WordPress.Security.NonceVerification.Recommended
?>
<form>
<?php if (!empty($_GET)) {
foreach ($_GET as $key => $value) { ?>
foreach ($_GET as $key => $value) {
$key = sanitize_text_field($key);
$value = sanitize_text_field($value);
?>
<input type="hidden" name="<?php echo esc_attr($key); ?>" value="<?php echo esc_attr($value); ?>"/>
<?php }
} ?>
Expand Down
58 changes: 29 additions & 29 deletions app/RestAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RestAPI extends BaseAPI
/**
* @var int
*/
private int $currentUserId;
protected int $currentUserId;

/**
* @var Request
Expand Down Expand Up @@ -64,12 +64,12 @@ public function __construct()
}

// create payment data
add_action('rest_pre_dispatch', [$this, 'middleware'], 10, 3);
$this->addMiddleware('cryptopay-lite', [$this, 'middleware']);

$this->addRoutes([
'cryptopay-lite' => [
'init' => [
'callback' => 'init',
'callback' => 'initPayment',
'methods' => ['GET']
],
'create-transaction' => [
Expand Down Expand Up @@ -120,30 +120,28 @@ public function getObjectParam(string $key): object
public function middleware(mixed $result, \WP_REST_Server $server, \WP_REST_Request $request): mixed
{
// check if request is cryptopay
if ('cryptopay-lite' === (Helpers::getRoutePaths($request->get_route())[0] ?? null)) {
if ($addon = $this->request->getParam('cp_addon')) {
try {
// check addon
Helpers::checkIntegration($this->addon = $addon);
$this->paymentData = new PaymentDataType($addon);
$this->paymentData->setUserId($this->currentUserId);
$this->paymentData->setHash($this->request->getParam('hash'));
$this->paymentData->setOrder(
OrderType::fromObject($this->getObjectParam('order'))
);
$this->paymentData->setParams(
ParamsType::fromObject($this->getObjectParam('params'))
);
$this->paymentData->setNetwork(
NetworkType::fromObject($this->getObjectParam('network'))
);
$this->paymentData->setDynamicData(
DynamicDataType::fromObject($this->getObjectParam('dynamicData'))
);
} catch (\Exception $e) {
Helpers::debug($e->getMessage(), 'ERROR', $e);
Response::error($e->getMessage(), 'INT100');
}
if ($addon = $this->request->getParam('cp_addon')) {
try {
// check addon
Helpers::checkIntegration($this->addon = $addon);
$this->paymentData = new PaymentDataType($addon);
$this->paymentData->setUserId($this->currentUserId);
$this->paymentData->setHash($this->request->getParam('hash'));
$this->paymentData->setOrder(
OrderType::fromObject($this->getObjectParam('order'))
);
$this->paymentData->setParams(
ParamsType::fromObject($this->getObjectParam('params'))
);
$this->paymentData->setNetwork(
NetworkType::fromObject($this->getObjectParam('network'))
);
$this->paymentData->setDynamicData(
DynamicDataType::fromObject($this->getObjectParam('dynamicData'))
);
} catch (\Exception $e) {
Helpers::debug($e->getMessage(), 'ERROR', $e);
Response::error($e->getMessage(), 'INT100');
}
}

Expand All @@ -156,7 +154,7 @@ public function middleware(mixed $result, \WP_REST_Server $server, \WP_REST_Requ
* payment address and parameters that the relevant network may need.
* @return void
*/
public function init(): void
public function initPayment(): void
{
try {
$payment = new Payment($this->paymentData->getAddon());
Expand Down Expand Up @@ -321,7 +319,9 @@ public function setReminderEmail(): void
]);

$this->paymentData->getModel()->update([
'reminderEmail' => $email
'reminderEmail' => $email,
'userId' => $this->currentUserId,
'updatedAt' => current_time('mysql')
], [
'hash' => $this->paymentData->getHash()
]);
Expand Down
11 changes: 6 additions & 5 deletions app/Settings/EvmChains.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,17 @@ public static function initSettings(): void
],
[
'id' => 'walletconnect',
'title' => esc_html('WalletConnect'),
'title' => esc_html('WalletConnect (legacy)'),
'type' => 'switcher',
'default' => true
'default' => true,
'desc' => esc_html__('If you enabled Web3Wallets, please disable it.', 'cryptopay'),
],
[
'id' => 'web3modal',
'title' => esc_html('Web3 Wallets (Web3Modal)'),
'id' => 'web3wallets',
'title' => esc_html('Web3 Wallets (Reown AppKit - formerly Web3Modal)'),
'type' => 'switcher',
'default' => true,
'desc' => esc_html__('It is a module within Web3Modal that supports hundreds of wallets with WalletConnect support. Since all the above wallets are already supported, you can deactivate all other wallets and allow users to make transactions only through Web3Modal.', 'cryptopay'),
'desc' => esc_html__('It is a module within Reown AppKit that supports hundreds of wallets with WalletConnect support. Since all the above wallets are already supported, you can deactivate all other wallets and allow users to make transactions only through Reown AppKit.', 'cryptopay'),
],
]
],
Expand Down
Loading

0 comments on commit 6642eb4

Please sign in to comment.