first commit

This commit is contained in:
2024-11-10 21:08:49 +01:00
commit 0d932ce5ee
14455 changed files with 2567501 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
<?php
namespace WPDesk\FCF\Free\Notice;
use FcfVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin;
/**
* Notice about new plugin - Flexible Wishlist.
*/
class FlexibleWishlistReview implements Notice {
const ACTIVATION_OPTION_NAME = 'plugin_activation_%s';
const NOTICE_OPTION_NAME = 'notice_flexible_wishlist_%s';
const NOTICE_NAME = 'notice_flexible_wishlist';
/**
* @var AbstractPlugin
*/
private $plugin;
public function __construct( AbstractPlugin $plugin ) {
$this->plugin = $plugin;
}
/**
* {@inheritdoc}
*/
public function get_notice_name(): string {
return self::NOTICE_NAME;
}
/**
* {@inheritdoc}
*/
public function is_active(): bool {
if ( basename( $_SERVER['PHP_SELF'] ) !== 'index.php' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
return false;
}
$plugins = [
$this->plugin->get_plugin_file_path(),
'flexible-product-fields/flexible-product-fields.php',
];
foreach ( $plugins as $plugin_filename ) {
$option_notice = sprintf( self::NOTICE_OPTION_NAME, $plugin_filename );
$notice_date = strtotime( get_option( $option_notice, false ) );
$min_date = strtotime( current_time( 'mysql' ) );
if ( ( $notice_date !== false ) && ( $notice_date > $min_date ) ) {
return false;
}
}
$option_activation = sprintf( self::ACTIVATION_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$activation_date = strtotime( get_option( $option_activation, current_time( 'mysql' ) ) );
$min_date = strtotime( current_time( 'mysql' ) . ' -1 day' );
if ( $activation_date > $min_date ) {
return false;
}
$installed_plugins = get_plugins();
return ! isset( $installed_plugins['flexible-wishlist/flexible-wishlist.php'] );
}
/**
* {@inheritdoc}
*/
public function get_template_path(): string {
return 'notices/flexible-wishlist';
}
/**
* {@inheritdoc}
*/
public function get_vars_for_view(): array {
return [
'image_url' => untrailingslashit( $this->plugin->get_plugin_assets_url() ) . '/img/flexible-wishlist.png',
'install_url' => wp_nonce_url(
add_query_arg(
[
'action' => 'install-plugin',
'plugin' => 'flexible-wishlist',
],
admin_url( 'update.php' )
),
'install-plugin_flexible-wishlist'
),
];
}
/**
* {@inheritdoc}
*/
public function set_notice_as_hidden( bool $is_permanently ) {
$option_name = sprintf( self::NOTICE_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$notice_time = strtotime( current_time( 'mysql' ) . ( ( $is_permanently ) ? ' +10 years' : ' +1 month' ) );
$notice_date = gmdate( 'Y-m-d H:i:s', $notice_time );
update_option( $option_name, $notice_date, true );
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WPDesk\FCF\Free\Notice;
/**
* Interface for class that supports notice displayed in admin panel.
*/
interface Notice {
/**
* Returns unique key of notice.
*
* @return string
*/
public function get_notice_name(): string;
/**
* Returns status if notice is active.
*
* @return bool Do show notice?
*/
public function is_active(): bool;
/**
* Returns server path for view template.
*
* @return string Server path relative to plugin /templates directory.
*/
public function get_template_path(): string;
/**
* Returns variables with values using in view template.
*
* @return string[] Args extract in view template.
*/
public function get_vars_for_view(): array;
/**
* Disables visible notice.
*
* @param bool $is_permanently .
*
* @return void
* @internal
*/
public function set_notice_as_hidden( bool $is_permanently );
}

View File

@@ -0,0 +1,116 @@
<?php
namespace WPDesk\FCF\Free\Notice;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use FcfVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant;
use FcfVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
use FcfVendor\WPDesk\View\Renderer\SimplePhpRenderer;
use FcfVendor\WPDesk\View\Resolver\DirResolver;
/**
* Supports ability to display notice and its management.
*/
class NoticeIntegration implements Hookable, HookablePluginDependant {
use PluginAccess;
/**
* @var Notice
*/
private $notice;
/**
* @var SimplePhpRenderer
*/
private $renderer;
/**
* Class constructor.
*/
public function __construct( Notice $notice ) {
$this->notice = $notice;
$this->renderer = new SimplePhpRenderer( new DirResolver( dirname( dirname( __DIR__ ) ) . '/templates' ) );
}
/**
* {@inheritdoc}
*/
public function hooks() {
add_filter( 'admin_init', [ $this, 'init_admin_notice' ] );
add_action( 'wp_ajax_fcf_close_' . $this->notice->get_notice_name(), [ $this, 'hide_admin_notice' ] );
}
/**
* @return void
* @internal
*/
public function init_admin_notice() {
if ( ! $this->notice->is_active() ) {
return;
}
add_filter( 'admin_notices', [ $this, 'load_admin_notice_template' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'load_styles_for_notice' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'load_scripts_for_notice' ] );
}
/**
* @return void
* @internal
*/
public function load_admin_notice_template() {
echo $this->renderer->render( // phpcs:ignore
$this->notice->get_template_path(),
array_merge( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[
'ajax_url' => esc_attr( admin_url( 'admin-ajax.php' ) ),
'ajax_action' => esc_attr( 'fcf_close_' . $this->notice->get_notice_name() ),
],
$this->notice->get_vars_for_view()
)
);
}
/**
* @return void
* @internal
*/
public function load_styles_for_notice() {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.css' : '.min.css';
wp_register_style(
'fcf-notice',
trailingslashit( $this->plugin->get_plugin_assets_url() ) . 'css/admin-notice' . $suffix,
[],
( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : $this->plugin->get_script_version()
);
wp_enqueue_style( 'fcf-notice' );
}
/**
* @return void
* @internal
*/
public function load_scripts_for_notice() {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.js' : '.min.js';
wp_register_script(
'fcf-notice',
trailingslashit( $this->plugin->get_plugin_assets_url() ) . 'js/admin-notice' . $suffix,
[],
( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : $this->plugin->get_script_version(),
true
);
wp_enqueue_script( 'fcf-notice' );
}
/**
* @return void
* @internal
*/
public function hide_admin_notice() {
$is_permanently = ( isset( $_POST['is_permanently'] ) && $_POST['is_permanently'] ); // phpcs:ignore
$this->notice->set_notice_as_hidden( $is_permanently );
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace WPDesk\FCF\Free\Notice;
use FcfVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin;
/**
* Notice about review.
*/
class ReviewNotice implements Notice {
const ACTIVATION_OPTION_NAME = 'plugin_activation_%s';
const NOTICE_OPTION_NAME = 'notice_review_%s';
const NOTICE_NAME = 'notice_review';
/**
* @var AbstractPlugin
*/
private $plugin;
public function __construct( AbstractPlugin $plugin ) {
$this->plugin = $plugin;
}
/**
* {@inheritdoc}
*/
public function get_notice_name(): string {
return self::NOTICE_NAME;
}
/**
* {@inheritdoc}
*/
public function is_active(): bool {
$option_notice = sprintf( self::NOTICE_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$notice_date = strtotime( get_option( $option_notice, false ) );
$min_date = strtotime( current_time( 'mysql' ) );
if ( ( basename( $_SERVER['PHP_SELF'] ) !== 'index.php' ) // phpcs:ignore
|| ( ( $notice_date !== false ) && ( $notice_date > $min_date ) ) ) {
return false;
}
$option_activation = sprintf( self::ACTIVATION_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$activation_date = strtotime( get_option( $option_activation, current_time( 'mysql' ) ) );
$min_date = strtotime( current_time( 'mysql' ) . ' -7 days' );
return ( $activation_date <= $min_date );
}
/**
* {@inheritdoc}
*/
public function get_template_path(): string {
return 'notices/review';
}
/**
* {@inheritdoc}
*/
public function get_vars_for_view(): array {
return [];
}
/**
* {@inheritdoc}
*/
public function set_notice_as_hidden( bool $is_permanently ) {
$option_name = sprintf( self::NOTICE_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$notice_time = strtotime( current_time( 'mysql' ) . ( ( $is_permanently ) ? ' +10 years' : ' +1 month' ) );
$notice_date = gmdate( 'Y-m-d H:i:s', $notice_time );
update_option( $option_name, $notice_date, true );
}
}