Skip to content

Commit

Permalink
Merge pull request #9 from BeycanPress/alpha
Browse files Browse the repository at this point in the history
Alpha
  • Loading branch information
BeycanDeveloper committed Mar 14, 2024
2 parents e0847ef + 141eac8 commit fadaa81
Show file tree
Hide file tree
Showing 38 changed files with 678 additions and 231 deletions.
2 changes: 1 addition & 1 deletion app/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static function prepareCurrencies(array $mainnetCurrencies, array $testne
$currencies = array_merge($currencies, $testnetCurrencies);
} else {
foreach ($mainnetCurrencies as $currency) {
if (isset($currency['active']) && $currency['active'] == '1') {
if (isset($currency['active']) && '1' == $currency['active']) {
$address = trim($currency['address']);
$symbol = trim(strtoupper($currency['symbol']));
$imageUrl = sanitize_text_field($currency['image']);
Expand Down
2 changes: 1 addition & 1 deletion app/Pages/TransactionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function page(): void

$params = [];

if ($code != 'all') {
if ('all' != $code) {
$params['code'] = $code;
}

Expand Down
8 changes: 4 additions & 4 deletions app/PluginHero/BaseAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
abstract class BaseAPI
{
/**
* @var string<rest|ajax>
* @var string rest|ajax
*/
protected string $type = 'rest';

Expand All @@ -26,7 +26,7 @@ public function addRoutes(array $routeList): void
return;
}

if ($this->type == 'rest') {
if ('rest' == $this->type) {
$this->nameSpaces = array_keys($routeList);
add_action('rest_api_init', function () use ($routeList): void {
foreach ($routeList as $nameSpace => $routes) {
Expand All @@ -41,7 +41,7 @@ public function addRoutes(array $routeList): void
}
}
});
} elseif ($this->type == 'ajax') {
} elseif ('ajax' == $this->type) {
foreach ($routeList as $nameSpace => $routes) {
foreach ($routes as $route => $config) {
$callback = is_array($config) ? $config['callback'] : $config;
Expand All @@ -62,7 +62,7 @@ public function addRoutes(array $routeList): void
*/
public function getUrl(?string $nameSpace = null): string
{
if ($this->type == 'rest') {
if ('rest' == $this->type) {
$nameSpace = isset($this->nameSpaces[$nameSpace])
? $this->nameSpaces[$nameSpace]
: array_values($this->nameSpaces)[0];
Expand Down
108 changes: 108 additions & 0 deletions app/PluginHero/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,112 @@ public static function registerUninstall(string $pluginFile, mixed $closureOrMet
{
register_uninstall_hook($pluginFile, $closureOrMethodName);
}

/**
* @return float
*/
public static function getPHPVersion(): float
{
$version = explode('.', PHP_VERSION);
return floatval($version[0] . '.' . $version[1]);
}

/**
* @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 string $pluginName
* @param array<mixed> $rules
* @return bool
*/
public static function createRequirementRules(string $pluginName, array $rules): bool
{
$status = true;

if (isset($rules['phpVersions'])) {
$phpVersions = $rules['phpVersions'];
if (!is_array($phpVersions)) {
throw new \Exception('phpVersions must be an array!');
}
if (!in_array(self::getPHPVersion(), $phpVersions)) {
$status = false;
add_action('admin_notices', function () use ($phpVersions, $pluginName): void {
// @phpcs:ignore
$message = $pluginName . ': Your current PHP version does not support ' . self::getPHPVersion() . '. This means errors may occur due to incompatibility or other reasons. So ' . $pluginName . ' is disabled please use one of the supported versions ' . implode(' or ', $phpVersions) . '. You can ask your server service provider to update your PHP version.';
printf('<div class="notice notice-error"><p>%1$s</p></div>', $message);
});
}
}

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>', $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>', $message);
});
}
}
}

if (isset($rules['extensions'])) {
$extensions = $rules['extensions'];
if (!is_array($extensions)) {
throw new \Exception('extensions must be an array!');
}
if (isset($extensions['curl']) && !extension_loaded('curl')) {
$status = false;
add_action('admin_notices', function () use ($pluginName): void {
$message = $pluginName . ': cURL PHP extension is not installed. So ' . $pluginName . ' has been disabled cURL is a HTTP request library that ' . $pluginName . ' needs and uses to verify blockchain transactions. Please visit "' . ('cli' == php_sapi_name() ? 'https://www.php.net/manual/en/book.curl.php' : '<a href="https://www.php.net/manual/en/book.curl.php">https://www.php.net/manual/en/book.curl.php</a>') . '" for install assistance. You can ask your server service provider to install cURL.'; // @phpcs:ignore
printf('<div class="notice notice-error"><p>%1$s</p></div>', $message);
});
}

if (isset($extensions['file_get_contents']) && !function_exists('file_get_contents')) {
$status = false;
add_action('admin_notices', function () use ($pluginName): void {
$message = $pluginName . ': file_get_contents PHP function is not available. So ' . $pluginName . ' has been disabled file_get_contents is a PHP function that ' . $pluginName . ' needs and uses for some process. Please visit "' . ('cli' == php_sapi_name() ? 'https://www.php.net/manual/en/function.file-get-contents.php' : '<a href="https://www.php.net/manual/en/function.file-get-contents.php">https://www.php.net/manual/en/function.file-get-contents.php</a>') . '" for install assistance. You can ask your server service provider to enable file_get_contents.'; // @phpcs:ignore
printf('<div class="notice notice-error"><p>%1$s</p></div>', $message);
});
}
}

if (!$status && isset($rules['documentation'])) {
if (!filter_var($rules['documentation'], FILTER_VALIDATE_URL)) {
throw new \Exception('documentation must be a valid URL!');
}
add_action('admin_notices', function () use ($pluginName, $rules): void {
$message = sprintf($pluginName . ': Deficiencies in ' . $pluginName . ' requirements have been detected. You can check the <a href="%s" target="_blank">documentation</a> if you wish.', $rules['documentation']); // @phpcs:ignore
printf('<div class="notice notice-error"><p>%1$s</p></div>', $message);
});
}

return $status;
}
}
2 changes: 1 addition & 1 deletion app/PluginHero/Helpers/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function createAssetParams(string $path, string $baseUrl, string $
$key = str_replace('/', '-', $path);
$ver = self::getProp('pluginVersion');
$subAsset = 'assets/' . $subAsset . '/';
$url = $baseUrl . ($f === '/' ? 'assets' : $subAsset) . $path;
$url = $baseUrl . ('/' === $f ? 'assets' : $subAsset) . $path;
$key = self::getProp('pluginKey') . '-' . preg_replace('/\..*$/', '', $key);

return [$key, $url, $ver];
Expand Down
10 changes: 5 additions & 5 deletions app/PluginHero/Helpers/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait Data
private static array $pages = [];

/**
* @var array<string,Closure>
* @var array<string,\Closure>
*/
private static array $funcs = [];

Expand All @@ -48,7 +48,7 @@ public static function getProp(string $property, mixed $default = 'no-default'):
{
if (isset(Plugin::$properties->$property)) {
return Plugin::$properties->$property;
} elseif ($default !== 'no-default') {
} elseif ('no-default' !== $default) {
return $default;
} else {
throw new \Exception('Property not found: ' . $property);
Expand Down Expand Up @@ -150,7 +150,7 @@ public static function getPage(string $name, ?string $slug = null): Page
{
if (isset(self::$pages[$name])) {
if (is_array(self::$pages[$name])) {
if (count(self::$pages[$name]) == 1) {
if (1 == count(self::$pages[$name])) {
return array_values(self::$pages[$name])[0];
}

Expand Down Expand Up @@ -250,10 +250,10 @@ public static function getPluginSlug(string $file): string

/**
* @param string $field
* @param array<mixed> $value
* @param mixed $value
* @return object|null
*/
public static function getUserBy(string $field, array $value): ?object
public static function getUserBy(string $field, mixed $value): ?object
{
global $wpdb;
return $wpdb->get_row("SELECT * FROM $wpdb->users WHERE $field = '$value'");
Expand Down
2 changes: 1 addition & 1 deletion app/PluginHero/Helpers/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function debug(string $message, string $level = 'INFO', array|\Thr
{
if (self::getProp('debugging', false)) {
$debugLevel = self::getProp('debugLevel', 'ALL');
if ($debugLevel !== 'ALL' && $debugLevel !== $level) {
if ('ALL' !== $debugLevel && $debugLevel !== $level) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions app/PluginHero/Helpers/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function feedback(bool $form = true, ?string $wpOrgSlug = null): v

if ($form) {
global $pagenow;
if ($pagenow === 'plugins.php') {
if ('plugins.php' === $pagenow) {
if (!file_exists(self::getProp('pluginDir') . 'assets/css/feedback.css')) {
if (!is_dir(self::getProp('pluginDir') . 'assets')) {
mkdir(self::getProp('pluginDir') . 'assets');
Expand Down Expand Up @@ -139,7 +139,6 @@ public static function sendDeactivationInfoApiReal(): void
]);
} catch (\Exception $e) {
wp_send_json_success($e->getMessage());
return;
}
}

Expand Down
10 changes: 6 additions & 4 deletions app/PluginHero/Helpers/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public static function toString(float|int $amount, int $decimals): string
$pos1 = stripos((string) $amount, 'E-');
$pos2 = stripos((string) $amount, 'E+');

if ($pos1 !== false) {
if (false !== $pos1) {
$amount = number_format($amount, $decimals, '.', ',');
}

if ($pos2 !== false) {
if (false !== $pos2) {
$amount = number_format($amount, $decimals, '.', '');
}

Expand Down Expand Up @@ -155,11 +155,13 @@ public static function parseDomain(?string $address): ?string

$parseUrl = parse_url(trim($address));
if (isset($parseUrl['host'])) {
return trim($parseUrl['host']);
$domain = trim($parseUrl['host']);
} else {
$domain = explode('/', $parseUrl['path'], 2);
return array_shift($domain);
$domain = array_shift($domain);
}

return str_replace(['www.'], '', $domain);
}

/**
Expand Down
26 changes: 19 additions & 7 deletions app/PluginHero/Helpers/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public static function getTemplate(string $templateName, array $args = []): stri
{
extract($args);
ob_start();
// for use in templates
$ksesEcho = fn($html, $allowedHtml = []) => self::ksesEcho($html, $allowedHtml);
include self::getProp('phDir') . 'templates/' . $templateName . '.php';
return ob_get_clean();
}
Expand Down Expand Up @@ -91,11 +93,12 @@ public static function registerPageTemplate(string $templateName, string $templa
if ($post && is_page()) {
$pageTemplate = get_page_template_slug($post->ID);

if (strpos($pageTemplate, elf::getProp('pluginKey')) !== false) {
exit(self::viewEcho(
if (false !== strpos($pageTemplate, self::getProp('pluginKey'))) {
self::viewEcho(
'page-templates/' . str_replace(self::getProp('pluginKey'), '', $pageTemplate),
$params
));
);
exit();
}
}

Expand All @@ -121,11 +124,11 @@ public static function parseJson(string $jsonString, bool $array = false): objec
public static function catchShortcode(string $content): string
{
global $shortcode_tags;
$tagnames = array_keys($shortcode_tags);
$tagregexp = join('|', array_map('preg_quote', $tagnames));
$tagNames = array_keys($shortcode_tags);
$tagRegexp = join('|', array_map('preg_quote', $tagNames));

// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
$pattern = '(.?)\[(' . $tagregexp . ')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
$pattern = '(.?)\[(' . $tagRegexp . ')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';

return preg_replace_callback('/' . $pattern . '/s', 'do_shortcode_tag', $content);
}
Expand Down Expand Up @@ -201,7 +204,16 @@ public static function getImageUrl(string $imageName): string
*/
public static function notice(string $notice, string $type = 'success', bool $dismissible = false): void
{
echo wp_kses_post(self::getTemplate('notice', [
$id = md5($notice . $type . $dismissible);

$dismissed = get_option('bp_dismissed_notices', []);

if (in_array($id, $dismissed)) {
return;
}

self::ksesEcho(self::getTemplate('notice', [
'id' => $id,
'type' => $type,
'notice' => $notice,
'dismissible' => $dismissible
Expand Down
2 changes: 1 addition & 1 deletion app/PluginHero/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function getError(): string
private function ifIsJson(string $string): mixed
{
$json = json_decode($string);
if (json_last_error() === JSON_ERROR_NONE) {
if (JSON_ERROR_NONE === json_last_error()) {
return $json;
} else {
return $string;
Expand Down
Loading

0 comments on commit fadaa81

Please sign in to comment.