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
namespace DgoraWcas\Admin\Promo;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use DgoraWcas\Helpers;
class FeedbackNotice {
const ACTIVATION_DATE_OPT = 'dgwt_wcas_activation_date';
const HIDE_NOTICE_OPT = 'dgwt_wcas_dismiss_review_notice';
const DISMISS_AJAX_ACTION = 'dgwt_wcas_dismiss_notice';
const REVIEW_URL = 'https://wordpress.org/support/plugin/ajax-search-for-woocommerce/reviews/?filter=5';
/**
* Admin notice offset
* @var int timestamp
*/
private $offset;
function __construct() {
$this->offset = strtotime( '-7 days' );
add_action( 'admin_init', array( $this, 'checkInstallationDate' ) );
add_action( 'wp_ajax_' . self::DISMISS_AJAX_ACTION, array( $this, 'dismissNotice' ) );
add_action( 'admin_head', array( $this, 'loadStyle' ) );
add_action( 'admin_footer', array( $this, 'printDismissJS' ) );
}
/**
* Check if is possible to display admin notice on the current screen
*
* @return bool
*/
private function allowDisplay() {
$currentScreen = get_current_screen();
if (
! empty( $currentScreen )
&& (
in_array( $currentScreen->base, array( 'dashboard', 'post', 'edit' ) )
|| strpos( $currentScreen->base, DGWT_WCAS_SETTINGS_KEY ) !== false
)
) {
return true;
}
return false;
}
/**
* Display feedback notice
*
* @return void
*/
public function displayNotice() {
global $current_user;
if ( $this->allowDisplay() && ! dgoraAsfwFs()->is_premium() ) {
?>
<div class="notice-info notice dgwt-wcas-notice dgwt-wcas-review-notice">
<div class="dgwt-wcas-review-notice-logo"></div>
<?php printf( __( "Hey %s, it's Damian Góra from %s. You have used this free plugin for some time now, and I hope you like it!", 'ajax-search-for-woocommerce' ),
'<strong>' . $current_user->display_name . '</strong>',
'<strong>' . DGWT_WCAS_NAME . '</strong>'
); ?>
<br/>
<?php printf( __( "The FiboSearch team have spent countless hours developing it, and it would mean a lot to me if you %ssupport it with a quick review on WordPress.org.%s", 'ajax-search-for-woocommerce' ),
'<strong><a target="_blank" href="' . self::REVIEW_URL . '">', '</a></strong>'
); ?>
<div class="button-container">
<a href="<?php echo self::REVIEW_URL; ?>" target="_blank" data-link="follow" class="button-secondary dgwt-review-notice-dismiss">
<span class="dashicons dashicons-star-filled"></span>
<?php printf( __( "Review %s", 'ajax-search-for-woocommerce' ), DGWT_WCAS_NAME ); ?>
</a>
<a href="#" class="button-secondary dgwt-review-notice-dismiss">
<span class="dashicons dashicons-no-alt"></span>
<?php _e( "No thanks", 'ajax-search-for-woocommerce' ); ?>
</a>
</div>
</div>
<?php
}
}
/**
* Check instalation date
*
* @return void
*/
public function checkInstallationDate() {
$date = get_option( self::ACTIVATION_DATE_OPT );
if ( empty( $date ) ) {
add_option( self::ACTIVATION_DATE_OPT, time() );
}
$notice_closed = get_option( self::HIDE_NOTICE_OPT );
if ( empty( $notice_closed ) ) {
$install_date = get_option( self::ACTIVATION_DATE_OPT );
if ( $this->offset >= $install_date && current_user_can( 'install_plugins' ) ) {
add_action( 'admin_notices', array( $this, 'displayNotice' ) );
}
}
}
/**
* Hide admin notice
*
* @return void
*/
public function dismissNotice() {
if ( ! current_user_can( Helpers::shopManagerHasAccess() ? 'manage_woocommerce' : 'manage_options' ) ) {
wp_die( - 1, 403 );
}
check_ajax_referer( 'dgwt_wcas_dismiss_feedback_notice' );
update_option( self::HIDE_NOTICE_OPT, true );
wp_send_json_success();
}
/**
* Print JS for close admin notice
*
* @return void
*/
public function printDismissJS() {
if ( ! $this->allowDisplay() ) {
return;
}
?>
<script>
(function ($) {
$(document).on('click', '.dgwt-review-notice-dismiss', function () {
var $box = $(this).closest('.dgwt-wcas-review-notice'),
isLink = $(this).attr('data-link') === 'follow' ? true : false;
$box.fadeOut(700);
$.ajax({
url: ajaxurl,
data: {
_wpnonce: '<?php echo wp_create_nonce( 'dgwt_wcas_dismiss_feedback_notice' ); ?>',
action: '<?php echo self::DISMISS_AJAX_ACTION; ?>',
}
}).done(function (data) {
setTimeout(function () {
$box.remove();
}, 700);
});
if (!isLink) {
return false;
}
});
}(jQuery));
</script>
<?php
}
/**
* Load the necessary CSS
*
* @return void
*/
public function loadStyle() {
if ( $this->allowDisplay() ) {
wp_enqueue_style( 'dgwt-wcas-admin-style' );
}
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace DgoraWcas\Admin\Promo;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Upgrade {
function __construct() {
add_action( 'current_screen', array( $this, 'printScripts' ) );
}
public function printScripts() {
if ( dgoraAsfwFs()->is_premium() ) {
return;
}
$cs = get_current_screen();
if ( ! empty( $cs->base ) && strpos( $cs->base, 'dgwt_wcas' ) !== false ) {
add_thickbox();
add_action( 'admin_footer', array( $this, 'renderUpgradeModal' ), 10 );
add_action( 'admin_footer', array( $this, 'upgradeModalHandler' ), 20 );
}
}
/**
* Render plugin upgrade modal
*
* @return void
*/
public function renderUpgradeModal() {
$utmLink = 'https://fibosearch.com/pro-vs-free/?utm_source=wp-admin&utm_medium=referral&utm_campaign=upgrade-popup&utm_content=features&utm_gen=utmdc';
$features = array(
__( 'Speed up search! (even 10× faster) - users love it!', 'ajax-search-for-woocommerce' ),
__( 'Modern search engine based on an inverted index and advanced matching algorithms', 'ajax-search-for-woocommerce' ),
__( 'Fuzzy search', 'ajax-search-for-woocommerce' ),
__( 'Synonyms', 'ajax-search-for-woocommerce' ),
__( 'Search in attributes and variation products SKUs (option)', 'ajax-search-for-woocommerce' ),
__( 'Individual tips and support from the FiboSearch team', 'ajax-search-for-woocommerce' )
);
echo '<a style="display:none;" class="thickbox js-dgwt-wcas-modal-pro-handler" href="#TB_inline?width=600&height=380&inlineId=dgwt-wcas-modal" title="' . __( 'FiboSearch Pro - Upgrade Now', 'ajax-search-for-woocommerce' ) . '"></a>';
echo '<div id="dgwt-wcas-modal" class="dgwt-wcas-modal-upgrade" style="display:none;">';
echo '<img class="dgwt-wcas-modal-logo" src="' . DGWT_WCAS_URL . 'assets/img/logo-128.png" width="128" height="128" />';
echo '
<h2 class="dgwt-wcas-modal-title">' . __( 'Update now and increase your sales. You will receive a 30-day satisfaction guarantee. A return on investment will come very quickly.', 'ajax-search-for-woocommerce' ) . '</h2>';
echo '<ul>';
foreach ( $features as $feature ) {
echo '<li><strong>+ ' . $feature . '</strong></li>';
}
echo '<li><strong>+ ' . __( 'and more...', 'ajax-search-for-woocommerce' ) . ' <a target="_blank" href="' . $utmLink . '">' . __( 'See a comparison of all free and premium features!', 'ajax-search-for-woocommerce' ) . '</a></strong></li>';
echo '</ul>';
echo '<p><a class="button-primary" target="_blank" href="' . self::getUpgradeUrl() . '">' . __( 'Upgrade Now', 'ajax-search-for-woocommerce' ) . '</a>';
echo '</p>';
echo '</div>';
}
/**
* JS for the upgrade modal
*
* @return void
*/
public function upgradeModalHandler() {
?>
<script>
(function ($) {
$(document).on('click', '.dgwt-wcas-premium-only label, .dgwt-wcas-premium-only input, .dgwt-wcas-premium-only button, .dgwt-wcas-premium-only textarea, .dgwt-wcas-premium-only--trigger', function (e) {
triggerModal(e);
});
$('.dgwt-wcas-premium-only select').on('change', function (e) {
$(this).val($(this).attr('data-default'));
triggerModal(e);
});
function triggerModal(e) {
e.preventDefault();
$('.js-dgwt-wcas-modal-pro-handler').trigger('click');
}
})(jQuery);
</script>
<?php
}
/**
* Ge upgrade URL
*
* @param string $type
*
* @return string
*/
public static function getUpgradeUrl( $type = 'external' ) {
$url = "https://fibosearch.com/pricing/?utm_source=wp-admin&utm_medium=referral&utm_campaign=upgrade-link&utm_content=upgrade-now-btn";
if ( $type === 'internal' ) {
$url = esc_url( dgoraAsfwFs()->get_upgrade_url() );
}
return $url;
}
}