first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,192 @@
<?php
class Activate extends BSDK{
protected $url = 'https://api.bplugins.com/wp-json/data/v1/accept-data';
protected $status = false;
protected $post_type = '';
protected $nonce = null;
protected $last_check = null;
protected $marketing_allowed = false;
protected static $_instance = null;
public function __construct($config, $__FILE__){
parent::__construct($config, $__FILE__);
$this->register();
}
private function register(){
$this->status = get_option("$this->prefix-opt_in", false);
$this->last_check = get_option("$this->prefix-info-check", time()-1);
$this->marketing_allowed = get_option("$this->prefix-marketing-allowed", false);
add_filter("plugin_action_links_$this->base_name", [$this, 'opt_in_button'] );
add_action("wp_ajax_$this->prefix-opt-in-update", [$this, 'opt_in_update']);
add_action('admin_init', [$this, 'admin_init']);
add_action('admin_enqueue_scripts', [$this, 'enqueue_assets']);
if(!$this->status){
add_action('admin_menu', [$this, 'add_opt_in_menu']);
}
if($this->status == 'agreed'){
register_deactivation_hook( $this->__FILE__, [$this, 'deactivate'] );
}
add_action('admin_footer', [$this, 'opt_in_modal']);
add_action('admin_footer', [$this, 'initialize_opt_in']);
}
function initialize_opt_in(){
?>
<script>
document.addEventListener('DOMContentLoaded', function(){
if(typeof bsdkOptInFormHandler === 'function'){
bsdkOptInFormHandler('<?php echo esc_html($this->prefix) ?>');
}
});
</script>
<?php
}
function admin_init(){
$redirect = get_option("$this->prefix-redirect", false);
if(!$redirect && !str_contains($_SERVER['REQUEST_URI'], 'post.php') && !str_contains( $_SERVER['REQUEST_URI'], 'post-new.php' )){
wp_redirect("admin.php?page=".dirname($this->base_name));
update_option("$this->prefix-redirect", true);
}
}
public function opt_in_update(){
$nonce = $_POST['nonce'] ?? '';
$actionType = $_POST['actionType'] ?? '';
if(!wp_verify_nonce( $nonce, 'wp_ajax' )){
echo wp_json_encode(['success' => false, 'message' => 'invalid nonce']);
wp_die();
}
if($actionType === 'agree'){
update_option("$this->prefix-opt_in", 'agreed');
update_option("$this->prefix-marketing-allowed", true);
}else if($actionType === 'skip'){
update_option("$this->prefix-opt_in", 'skipped');
}else if ($actionType === 'opt_out'){
update_option("$this->prefix-marketing-allowed", false);
}
echo wp_json_encode(new \WP_REST_Response(['success' => true]));
wp_die();
}
public function opt_in_button($links){
$settings_link = '<a href="#" class="optInBtn" id="'.esc_attr($this->prefix).'OptInBtn" data-status="'.esc_attr($this->marketing_allowed ? 'agree': 'not-allowed').'">'.esc_html($this->marketing_allowed ? 'Opt out' : 'Opt In').'</a>';
array_unshift($links, $settings_link);
return $links;
}
// add a temp page to show opt-in form
public function add_opt_in_menu(){
add_submenu_page( '', $this->plugin_name, $this->plugin_name, 'manage_options', dirname($this->base_name), [$this, 'opt_in_form']
);
}
// enqueue assets
public function enqueue_assets($hook){
wp_register_script("bsdk-opt-in", plugin_dir_url(plugin_dir_path( __DIR__ )).'dist/opt-in-form.js', ['react', 'react-dom'], $this->version);
wp_register_style("bsdk-opt-in", plugin_dir_url(plugin_dir_path( __DIR__ )).'dist/opt-in-form.css', [], $this->version);
if($hook === 'plugins.php' || $hook === "admin_page_".dirname($this->base_name)){
wp_enqueue_script("bsdk-opt-in");
wp_enqueue_style("bsdk-opt-in");
}
}
// show the opt-in form
public function opt_in_form(){
update_option("$this->prefix-redirect", true);
?>
<div
data-basename="<?php echo esc_attr(dirname($this->base_name)) ?>"
data-admin_url="<?php echo esc_url(admin_url()) ?>"
data-ajax_url="<?php echo esc_url(admin_url('admin-ajax.php')) ?>"
data-nonce="<?php echo esc_attr(wp_create_nonce( 'wp_ajax' )) ?>"
data-info = "<?php echo esc_attr(wp_json_encode($this->getInfo())) ?>"
id="<?php echo esc_attr($this->prefix); ?>OptInForm">
</div>
<?php
}
// information to send to the server
public function getInfo(){
$user = wp_get_current_user();
global $wp_version;
return [
'website' => site_url(),
'user_email' => $user->user_email,
'user_display_name' => $user->display_name,
'user_nickname' => $user->user_login,
'plugin_version' => $this->version,
'php_version' => phpversion(),
'platform_version' => $wp_version,
'plugin_slug' => dirname($this->base_name),
];
}
// update data to the server
public function data_update($data = []){
global $wp_version;
$user = wp_get_current_user();
$response = wp_remote_post($this->url, array(
'method' => 'POST',
'timeout' => 45,
'headers' => array(),
'body' => wp_parse_args($data, [
'website' => site_url(),
'user_email' => $user->user_email,
'user_nickname' => $user->user_nickname ? $user->user_nickname : $user->user_login,
'php_version' => phpversion(),
'platform_version' => $wp_version,
'plugin_version' => $this->version
] )
)
);
}
// send activation notice to the server if agreed
public function activate(){
if($this->status == 'agreed'){
$this->data_update(['status' => 'activate']);
}
}
// send deactivation notice to the server if agreed
public function deactivate(){
if($this->status == 'agreed'){
$this->data_update(['status' => 'deactivate']);
}
}
// opt-in modal on plugins.php page
public function opt_in_modal($hook){
global $wp_version;
$user = \wp_get_current_user();
$screen = \get_current_screen();
if($screen->base === 'plugins'){
?>
<div id="<?php echo esc_attr($this->prefix) ?>OptInModal"
data-basename="<?php echo esc_attr(dirname($this->base_name)) ?>"
data-path="<?php echo esc_url(plugin_dir_url(plugin_dir_path( __DIR__ ))) ?>"
data-admin_url="<?php echo esc_url(admin_url()) ?>"
data-ajax_url="<?php echo esc_url(admin_url('admin-ajax.php')) ?>"
data-nonce="<?php echo esc_attr(wp_create_nonce( 'wp_ajax' )) ?>"
data-info = "<?php echo esc_attr(wp_json_encode($this->getInfo())) ?>">
</div>
<?php
}
}
}

View File

@@ -0,0 +1,57 @@
<?php
class BSDK{
protected $prefix = '';
protected $config = '';
protected $base_name = null;
protected $plugin_name = '';
protected $product = "";
public $isPipe = false;
protected $key = null;
protected $__FILE__ = null;
protected $_upgraded = false;
protected $version = false;
protected $dir = __DIR__;
protected $test = null;
protected $blockHandler = null;
function __construct($config, $__FILE__){
$this->config = $config;
$this->prefix = $this->config->prefix;
$this->__FILE__ = $__FILE__;
$this->base_name = plugin_basename( $this->__FILE__ );
$this->blockHandler = $this->config->blockHandler;
$license = str_replace('8ysg', true, stripslashes($this->__($this->prefix."_pipe")));
if($license){
$license = json_decode(str_replace('4z5xg', 'false', $license), true);
$this->isPipe = isset($license['zn8mpz8gt']) ? $license['zn8mpz8gt'] : false;
$this->key = isset($license['jga']) ? $license['jga'] : false;
}else {
$o_license = $this->__($this->prefix);
$this->isPipe = isset($o_license['active']) ? $o_license['active'] : false;
$this->key = isset($o_license['key']) ? $o_license['key'] : false;
}
if( ! function_exists('get_plugin_data') ){
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$plugin_data = \get_plugin_data( $this->__FILE__ );
$this->plugin_name = $plugin_data['Name'];
$this->version = $plugin_data['Version'];
}
// function
function __($name){
$data = get_option($name);
$this->_upgraded = (boolean) $data;
return $data;
}
}

View File

@@ -0,0 +1,146 @@
<?php
class BSDKLicense extends BSDK{
protected $permalinks = [];
function __construct($config, $__FILE__){
parent::__construct($config, $__FILE__);
$this->permalinks = $config->permalinks;
$this->register();
}
public function register(){
add_action('admin_footer', [$this, 'form']);
add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']);
add_filter("plugin_action_links_$this->base_name", [$this, 'addButtonInPlugin'] );
add_action("wp_ajax_{$this->prefix}_active_license_key", [$this, 'activeLicense']);
add_action("wp_ajax_{$this->prefix}_sync_license_key", [$this, 'ajaxSyncLicense']);
add_action('admin_footer', [$this, 'admin_footer']);
}
public function activeLicense(){
if(isset($_POST['nonce']) && !wp_verify_nonce( $_POST['nonce'], 'wp_ajax' )){
echo wp_json_encode(['success' => false, 'message' => 'invalid nonce']);
wp_die();
return;
}
$data = isset($_POST['data']) ? stripslashes(sanitize_text_field( $_POST['data'])) : "{}";
if(!$data){
echo wp_json_encode(['success' => false, 'message' => 'invalid data']);
wp_die();
return;
}
$result = \update_option($this->prefix."_pipe", $data);
echo wp_json_encode(['success' => true]);
wp_die();
}
public function addButtonInPlugin($links){
if(get_option($this->prefix."_pipe", false) || !$this->config->isBlock){
$text = ($this->isPipe ? __('Deactivate License', 'bsdk') : __('Active License', 'bsdk'));
}else {
$text = __('Upgrade to pro', 'bsdk');
}
$settings_link = '<a href="#" class="'.$this->prefix.'_modal_opener">'. $text .'</a>';
array_unshift($links, $settings_link);
return $links;
}
public function admin_enqueue_scripts($page){
if($page === 'plugins.php'){
wp_register_script( 'bsdk-license', plugin_dir_url( plugin_dir_path( __DIR__ ) ) . 'dist/license.js', array(), WP_B__VERSION , true );
wp_register_style( 'bsdk-license', plugin_dir_url( plugin_dir_path( __DIR__ ) ) . 'dist/license.css', array(), WP_B__VERSION , 'all' );
wp_localize_script('bsdk-license', 'BSDK', array(
'ajaxURL' => admin_url('admin-ajax.php'),
'website' => site_url(),
'email' => get_option('admin_email'),
'nonce' => wp_create_nonce( 'wp_ajax' ),
));
}
}
public function form(){
$screen = \get_current_screen();
if($screen->base === 'plugins'){
?>
<div class="<?php echo esc_attr($this->prefix) ?>_license_popup">
<div id="bLicensePopup" class="popupWrapper">
<div class="overlay"></div>
<div class="license_form">
<div class="popup_header">
<h2><?php _e("Active License", "bsdk") ?></h2>
<span class="closer">&times;</span>
</div>
<div class="popup_body">
<p><?php _e('Please enter the license key that you received in the email right after the purchase:', 'bsdk') ?></p>
<input type="<?php echo $this->_upgraded ? 'password' : 'text' ?>" value="<?php echo esc_attr($this->key) ?>" class="license_key" name="<?php echo esc_attr($this->prefix) ?>-license-key" />
<div class="license_notice"></div>
<div class="terms">
<input type="checkbox" id="agreeField" class="input agree">
<label for="agreeField"><?php $this->isPipe ? _e("Remove Data", 'bsdk') : _e("I agreed to send the website url, email, and the License key to '$this->plugin_name' plugin server to verify the license key.", "bsdk"); ?></label>
</div>
</div>
<div class="popup_footer">
<span class="bpl_loader"></span>
<?php if($this->isPipe): ?>
<input type="submit" class="button button-primary btn-deactivate" value="<?php _e("Deactive License", "bsdk") ?>" />
<?php else: ?>
<input type="submit" disabled="true" class="button button-primary btn-activate" value="<?php _e("Active License", "bsdk") ?>" />
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
public function admin_footer(){
$screen = (array) get_current_screen();
if(isset($screen['base']) && $screen['base'] === 'plugins'){
wp_enqueue_script('bsdk-license');
wp_enqueue_style('bsdk-license');
?>
<script>
document.addEventListener('DOMContentLoaded', function(){
if(typeof LicenseHandler === 'function'){
const license = new LicenseHandler('<?php echo esc_html($this->prefix); ?>', <?php echo wp_json_encode($this->permalinks) ?>);
license.initialize();
}
})
</script>
<?php
}
if($this->blockHandler){
wp_enqueue_script('bsdk-license');
}
}
function syncLicense(){
$website = $_POST['website'] ?? $_SERVER['HTTP_HOST'];
$response = ['success' => false];
if($this->isPipe){
$response = json_decode(wp_remote_retrieve_body( wp_remote_get("https://api.bplugins.com/wp-json/license/v1/sync-license?website=$website&product=$this->prefix&time=".time())), true);
}
if(isset($response['success']) && !$response['success']){
\update_option($this->prefix."_pipe", "{}");
}
return $response;
}
function ajaxSyncLicense(){
$response = $this->syncLicense();
echo wp_json_encode($response);
wp_die();
}
}

View File

@@ -0,0 +1,25 @@
<?php
class Init{
public static function get_services(){
return [
Base\License::class,
Base\Activate::class
];
}
public static function register_services(){
foreach(self::get_services() as $class){
$services = self::instantiate($class);
if(method_exists($services, 'register')){
$services->register();
}
}
}
private static function instantiate($class){
return new $class();
}
}