first commit

This commit is contained in:
CHIEFSOFT\ameye
2023-11-30 13:20:54 -05:00
commit e9e5c0546c
5833 changed files with 1801865 additions and 0 deletions
@@ -0,0 +1,35 @@
<?php
/**
* Define the internationalization functionality
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package ADP
* @subpackage ADP/includes
*/
/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @package ADP
* @subpackage ADP/includes
*/
class ADP_i18n {
/**
* Load the plugin text domain for translation.
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'advanced-popups', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
}
}
@@ -0,0 +1,115 @@
<?php
/**
* Register all actions and filters for the plugin
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package ADP
* @subpackage ADP/includes
*/
/**
* Register all actions and filters for the plugin.
*
* Maintain a list of all hooks that are registered throughout
* the plugin, and register them with the WordPress API. Call the
* run function to execute the list of actions and filters.
*
* @package ADP
* @subpackage ADP/includes
*/
class ADP_Loader {
/**
* The array of actions registered with WordPress.
*
* @access protected
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
*/
protected $actions;
/**
* The array of filters registered with WordPress.
*
* @access protected
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
*/
protected $filters;
/**
* Initialize the collections used to maintain the actions and filters.
*/
public function __construct() {
$this->actions = array();
$this->filters = array();
}
/**
* Add a new action to the collection to be registered with WordPress.
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
* @access private
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args,
);
return $hooks;
}
/**
* Register the filters and actions with WordPress.
*/
public function run() {
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}
@@ -0,0 +1,251 @@
<?php
/**
* Class Advanced Popups Rules.
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package ADP
* @subpackage ADP/includes
*/
/**
* Class Rules
*/
class ADP_Popup_Rules {
/**
* The instance.
*
* @var mixed $instance The instance.
*/
public static $instance;
/**
* The rules.
*
* @var array $instance The rules.
*/
public $rules;
/**
* The rule sort order.
*
* @var array $rule_sort_order The rule sort order.
*/
public $rule_sort_order = array();
/**
* Init.
*/
public static function init() {
self::instance();
}
/**
* Return instance.
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Get List rules
*/
public function get_list() {
$list = array(
'general' => array(),
'post_types' => array(),
'taxonomies' => array(),
);
$types = array();
// General.
$list['general'] = array(
'none' => esc_html__( 'None', 'advanced-popups' ),
'is_front_page' => esc_html__( 'Front Page', 'advanced-popups' ),
'is_home' => esc_html__( 'Home Page', 'advanced-popups' ),
'is_archive' => esc_html__( 'Archive Page', 'advanced-popups' ),
'is_author' => esc_html__( 'Author Page', 'advanced-popups' ),
'is_search' => esc_html__( 'Search Result Page', 'advanced-popups' ),
'is_404' => esc_html__( '404 Error Page', 'advanced-popups' ),
'url' => esc_html__( 'URL (slug)', 'advanced-popups' ),
);
// Post types.
$post_types = get_post_types( array(
'public' => true,
), 'objects' );
foreach ( $post_types as $name => $post_type ) {
if ( 'adp-popup' === $name ) {
continue;
}
if ( 'attachment' === $name ) {
continue;
}
$types[] = $name;
$list['post_types'][ 'post_type_' . $name ] = $post_type->labels->name;
}
// Taxonomies.
foreach ( $types as $name ) {
$post_type = get_post_type_object( $name );
$taxonomies = get_object_taxonomies( $name, 'object' );
foreach ( $taxonomies as $tax_name => $taxonomy ) {
$list['taxonomies'][ 'taxonomy_' . $tax_name ] = esc_html__( 'Taxonomy of ', 'advanced-popups' ) . $post_type->labels->name . ': ' . $taxonomy->labels->name;
}
}
return $list;
}
/**
* Get type from rule value
*
* @param string $val The value.
*/
public function get_type( $val ) {
if ( 'url' === $val ) {
return 'url';
}
if ( 0 === strpos( $val, 'is_' ) ) {
return 'is';
}
if ( 0 === strpos( $val, 'post_type' ) ) {
return 'post';
}
if ( 0 === strpos( $val, 'taxonomy' ) ) {
return 'taxonomy';
}
}
/**
* Get object from rule value
*
* @param string $val The value.
*/
public function get_object( $val ) {
$val = str_replace( array( 'post_type', 'taxonomy' ), '', $val );
return ltrim( $val, '_' );
}
/**
* Checking all the rules on the front end
*
* @param string $rules The rules.
*/
public function is_check( $rules ) {
if ( ! $rules ) {
return true;
}
$check = array();
foreach ( $rules as $i => $row ) {
$check[ $i ] = true;
foreach ( $row as $t => $tools ) {
if ( ! isset( $tools['rule'] ) ) {
continue;
}
if ( 'none' === $tools['rule'] ) {
continue;
}
$rule = $tools['rule'];
// Get type from rule value.
$type_rule = self::instance()->get_type( $rule );
// Get type object from rule value.
$type_object = self::instance()->get_object( $rule );
$check_or = true;
// Check rules.
switch ( $type_rule ) {
case 'url':
if ( isset( $tools['url'] ) && $tools['url'] ) {
$object_uri = ltrim( rtrim( $tools['url'], '/' ), '/' );
$current_uri = ltrim( rtrim( $_SERVER['REQUEST_URI'], '/' ), '/' );
if ( $object_uri !== $current_uri ) {
$check_or = false;
}
}
break;
case 'is':
if ( ! function_exists( $rule ) || ! call_user_func( $rule ) ) {
$check_or = false;
}
break;
case 'post':
if ( ! is_singular( $type_object ) ) {
$check_or = false;
}
$post_id = get_the_ID();
if ( isset( $tools['object'] ) && is_array( $tools['object'] ) ) {
foreach ( $tools['object'] as $object ) {
$check_or = (int) $post_id === (int) $object ? true : false;
}
}
break;
case 'taxonomy':
if ( ! is_tax( $type_object ) ) {
$check_or = false;
}
$term_id = get_queried_object_id();
if ( isset( $tools['object'] ) && is_array( $tools['object'] ) ) {
foreach ( $tools['object'] as $object ) {
$check_or = (int) $term_id === (int) $object ? true : false;
}
}
break;
}
$check[ $i ] = $check_or;
if ( $check_or ) {
break;
}
}
}
$is_check = true;
foreach ( $check as $item ) {
if ( ! $item ) {
$is_check = false;
break;
}
}
return $is_check;
}
}
@@ -0,0 +1,210 @@
<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package ADP
* @subpackage ADP/includes
*/
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since 1.0.0
* @package ADP
* @subpackage ADP/includes
*/
class ADP {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @access protected
* @var ADP_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @access protected
* @var string $adp The string used to uniquely identify this plugin.
*/
protected $adp;
/**
* The current version of the plugin.
*
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*/
public function __construct() {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Get plugin data.
$plugin_data = get_plugin_data( ADP_PATH . '/advanced-popups.php' );
$this->version = $plugin_data['Version'];
$this->adp = 'advanced-popups';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - ADP_Loader. Orchestrates the hooks of the plugin.
* - ADP_i18n. Defines internationalization functionality.
* - ADP_Admin. Defines all hooks for the admin area.
* - ADP_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @access private
*/
private function load_dependencies() {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/helpers-advanced-popups.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-advanced-popups-rules.php';
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-advanced-popups-loader.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-advanced-popups-i18n.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-advanced-popups-admin.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-advanced-popups-public.php';
$this->loader = new ADP_Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the ADP_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @access private
*/
private function set_locale() {
$plugin_i18n = new ADP_i18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @access private
*/
private function define_admin_hooks() {
$plugin_admin = new ADP_Admin( $this->get_adp(), $this->get_version() );
$this->loader->add_action( 'init', $plugin_admin, 'register_post_type' );
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'metabox_popup_register' );
$this->loader->add_action( 'save_post', $plugin_admin, 'metabox_popup_save', 10, 2 );
$this->loader->add_action( 'wp_ajax_nopriv_adp_popup_rules_objects', $plugin_admin, 'ajax_rules_objects' );
$this->loader->add_action( 'wp_ajax_adp_popup_rules_objects', $plugin_admin, 'ajax_rules_objects' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'admin_enqueue_scripts' );
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @access private
*/
private function define_public_hooks() {
$plugin_public = new ADP_Public( $this->get_adp(), $this->get_version() );
$this->loader->add_action( 'wp_head', $plugin_public, 'wp_head' );
$this->loader->add_action( 'wp_footer', $plugin_public, 'wp_footer' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'wp_enqueue_scripts' );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @return string The name of the plugin.
*/
public function get_adp() {
return $this->adp;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @return ADP_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}
@@ -0,0 +1,87 @@
<?php
/**
* Helpers Advanced Popups
*
* @package ADP
* @subpackage ADP/includes
*/
/**
* Processing path of style.
*
* @param string $path URL to the stylesheet.
*/
function adp_style( $path ) {
// Check RTL.
if ( is_rtl() ) {
return $path;
}
// Check Dev.
$dev = ADP_PATH . 'public/css/advanced-popups-public-dev.css';
if ( file_exists( $dev ) ) {
return str_replace( '.css', '-dev.css', $path );
}
return $path;
}
/**
* Retrieves a post meta field for the given post ID.
*
* @param int $post_id Post ID.
* @param string $key Optional. The meta key to retrieve. By default, returns
* data for all keys. Default empty.
* @param bool $single Optional. If true, returns only the first value for the specified meta key.
* This parameter has no effect if $key is not specified. Default false.
* @param mixed $default Default value.
* @return mixed Will be an array if $single is false. Will be value of the meta
* field if $single is true.
*/
function adp_get_post_meta( $post_id, $key = '', $single = false, $default = null ) {
if ( ! metadata_exists( 'post', $post_id, $key ) && $default ) {
return $default;
}
return get_metadata( 'post', $post_id, $key, $single );
}
/**
* Checks whether a popup should be displayed or not
*
* @param int $popup_id The popup Id.
*/
function adp_is_popup_visible( $popup_id ) {
$visible = true;
// Verify rules.
$popup_rules_mode = adp_get_post_meta( $popup_id, '_adp_popup_rules_mode', true, 'all' );
if ( true === $visible && 'specific' === $popup_rules_mode ) {
$popup_rules = adp_get_post_meta( $popup_id, '_adp_popup_rules', true, array() );
$visible = ADP_Popup_Rules::instance()->is_check( $popup_rules );
}
// Has user seen this popup before?
$popup_limit_display = adp_get_post_meta( $popup_id, '_adp_popup_limit_display', true, 1 );
if ( true === $visible && $popup_limit_display && isset( $_COOKIE[ "adp-popup-{$popup_id}" ] ) && $_COOKIE[ "adp-popup-{$popup_id}" ] >= $popup_limit_display ) {
$visible = false;
}
// Guests or Logged-in.
if ( true === $visible ) {
$popup_show_to = adp_get_post_meta( $popup_id, '_adp_popup_show_to', true, 'both' );
$visible = ! ( ( 'guest' === $popup_show_to && is_user_logged_in() ) || ( 'user' === $popup_show_to && ! is_user_logged_in() ) );
}
// Apply a final filter to determine visibility.
$visible = apply_filters( 'advanced_popups_is_popup_visible', $visible, $popup_id );
return $visible;
}
@@ -0,0 +1 @@
<?php // Silence is golden